@stryke/prisma-trpc-generator 0.3.3 → 0.4.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 +1338 -137
- package/dist/generator.js +1338 -137
- package/dist/index.cjs +1338 -137
- package/dist/index.js +1338 -137
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -2480,11 +2480,11 @@ var exists = /* @__PURE__ */ __name(async (filePath) => {
|
|
|
2480
2480
|
|
|
2481
2481
|
// ../fs/src/helpers.ts
|
|
2482
2482
|
var import_promises2 = require("node:fs/promises");
|
|
2483
|
-
async function createDirectory(
|
|
2484
|
-
if (await exists(
|
|
2483
|
+
async function createDirectory(path7) {
|
|
2484
|
+
if (await exists(path7)) {
|
|
2485
2485
|
return;
|
|
2486
2486
|
}
|
|
2487
|
-
return (0, import_promises2.mkdir)(
|
|
2487
|
+
return (0, import_promises2.mkdir)(path7, {
|
|
2488
2488
|
recursive: true
|
|
2489
2489
|
});
|
|
2490
2490
|
}
|
|
@@ -2506,65 +2506,65 @@ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
|
2506
2506
|
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
2507
2507
|
return _IS_ABSOLUTE_RE.test(p);
|
|
2508
2508
|
}, "isAbsolute");
|
|
2509
|
-
var correctPaths = /* @__PURE__ */ __name(function(
|
|
2510
|
-
if (!
|
|
2509
|
+
var correctPaths = /* @__PURE__ */ __name(function(path7) {
|
|
2510
|
+
if (!path7 || path7.length === 0) {
|
|
2511
2511
|
return ".";
|
|
2512
2512
|
}
|
|
2513
|
-
|
|
2514
|
-
const isUNCPath =
|
|
2515
|
-
const isPathAbsolute = isAbsolute(
|
|
2516
|
-
const trailingSeparator =
|
|
2517
|
-
|
|
2518
|
-
if (
|
|
2513
|
+
path7 = normalizeWindowsPath(path7);
|
|
2514
|
+
const isUNCPath = path7.match(_UNC_REGEX);
|
|
2515
|
+
const isPathAbsolute = isAbsolute(path7);
|
|
2516
|
+
const trailingSeparator = path7[path7.length - 1] === "/";
|
|
2517
|
+
path7 = normalizeString(path7, !isPathAbsolute);
|
|
2518
|
+
if (path7.length === 0) {
|
|
2519
2519
|
if (isPathAbsolute) {
|
|
2520
2520
|
return "/";
|
|
2521
2521
|
}
|
|
2522
2522
|
return trailingSeparator ? "./" : ".";
|
|
2523
2523
|
}
|
|
2524
2524
|
if (trailingSeparator) {
|
|
2525
|
-
|
|
2525
|
+
path7 += "/";
|
|
2526
2526
|
}
|
|
2527
|
-
if (_DRIVE_LETTER_RE.test(
|
|
2528
|
-
|
|
2527
|
+
if (_DRIVE_LETTER_RE.test(path7)) {
|
|
2528
|
+
path7 += "/";
|
|
2529
2529
|
}
|
|
2530
2530
|
if (isUNCPath) {
|
|
2531
2531
|
if (!isPathAbsolute) {
|
|
2532
|
-
return `//./${
|
|
2532
|
+
return `//./${path7}`;
|
|
2533
2533
|
}
|
|
2534
|
-
return `//${
|
|
2534
|
+
return `//${path7}`;
|
|
2535
2535
|
}
|
|
2536
|
-
return isPathAbsolute && !isAbsolute(
|
|
2536
|
+
return isPathAbsolute && !isAbsolute(path7) ? `/${path7}` : path7;
|
|
2537
2537
|
}, "correctPaths");
|
|
2538
2538
|
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
2539
|
-
let
|
|
2539
|
+
let path7 = "";
|
|
2540
2540
|
for (const seg of segments) {
|
|
2541
2541
|
if (!seg) {
|
|
2542
2542
|
continue;
|
|
2543
2543
|
}
|
|
2544
|
-
if (
|
|
2545
|
-
const pathTrailing =
|
|
2544
|
+
if (path7.length > 0) {
|
|
2545
|
+
const pathTrailing = path7[path7.length - 1] === "/";
|
|
2546
2546
|
const segLeading = seg[0] === "/";
|
|
2547
2547
|
const both = pathTrailing && segLeading;
|
|
2548
2548
|
if (both) {
|
|
2549
|
-
|
|
2549
|
+
path7 += seg.slice(1);
|
|
2550
2550
|
} else {
|
|
2551
|
-
|
|
2551
|
+
path7 += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
2552
2552
|
}
|
|
2553
2553
|
} else {
|
|
2554
|
-
|
|
2554
|
+
path7 += seg;
|
|
2555
2555
|
}
|
|
2556
2556
|
}
|
|
2557
|
-
return correctPaths(
|
|
2557
|
+
return correctPaths(path7);
|
|
2558
2558
|
}, "joinPaths");
|
|
2559
|
-
function normalizeString(
|
|
2559
|
+
function normalizeString(path7, allowAboveRoot) {
|
|
2560
2560
|
let res = "";
|
|
2561
2561
|
let lastSegmentLength = 0;
|
|
2562
2562
|
let lastSlash = -1;
|
|
2563
2563
|
let dots = 0;
|
|
2564
2564
|
let char = null;
|
|
2565
|
-
for (let index = 0; index <=
|
|
2566
|
-
if (index <
|
|
2567
|
-
char =
|
|
2565
|
+
for (let index = 0; index <= path7.length; ++index) {
|
|
2566
|
+
if (index < path7.length) {
|
|
2567
|
+
char = path7[index];
|
|
2568
2568
|
} else if (char === "/") {
|
|
2569
2569
|
break;
|
|
2570
2570
|
} else {
|
|
@@ -2600,9 +2600,9 @@ function normalizeString(path5, allowAboveRoot) {
|
|
|
2600
2600
|
}
|
|
2601
2601
|
} else {
|
|
2602
2602
|
if (res.length > 0) {
|
|
2603
|
-
res += `/${
|
|
2603
|
+
res += `/${path7.slice(lastSlash + 1, index)}`;
|
|
2604
2604
|
} else {
|
|
2605
|
-
res =
|
|
2605
|
+
res = path7.slice(lastSlash + 1, index);
|
|
2606
2606
|
}
|
|
2607
2607
|
lastSegmentLength = index - lastSlash - 1;
|
|
2608
2608
|
}
|
|
@@ -2619,7 +2619,7 @@ function normalizeString(path5, allowAboveRoot) {
|
|
|
2619
2619
|
__name(normalizeString, "normalizeString");
|
|
2620
2620
|
|
|
2621
2621
|
// src/prisma-generator.ts
|
|
2622
|
-
var
|
|
2622
|
+
var import_node_path7 = __toESM(require("node:path"), 1);
|
|
2623
2623
|
var import_pluralize = __toESM(require_pluralize(), 1);
|
|
2624
2624
|
|
|
2625
2625
|
// src/config.ts
|
|
@@ -2987,8 +2987,8 @@ function getErrorMap() {
|
|
|
2987
2987
|
}
|
|
2988
2988
|
__name(getErrorMap, "getErrorMap");
|
|
2989
2989
|
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
2990
|
-
const { data, path:
|
|
2991
|
-
const fullPath = [...
|
|
2990
|
+
const { data, path: path7, errorMaps, issueData } = params;
|
|
2991
|
+
const fullPath = [...path7, ...issueData.path || []];
|
|
2992
2992
|
const fullIssue = {
|
|
2993
2993
|
...issueData,
|
|
2994
2994
|
path: fullPath
|
|
@@ -3122,11 +3122,11 @@ var ParseInputLazyPath = class {
|
|
|
3122
3122
|
static {
|
|
3123
3123
|
__name(this, "ParseInputLazyPath");
|
|
3124
3124
|
}
|
|
3125
|
-
constructor(parent, value,
|
|
3125
|
+
constructor(parent, value, path7, key) {
|
|
3126
3126
|
this._cachedPath = [];
|
|
3127
3127
|
this.parent = parent;
|
|
3128
3128
|
this.data = value;
|
|
3129
|
-
this._path =
|
|
3129
|
+
this._path = path7;
|
|
3130
3130
|
this._key = key;
|
|
3131
3131
|
}
|
|
3132
3132
|
get path() {
|
|
@@ -7111,34 +7111,34 @@ __name2(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
|
7111
7111
|
var _UNC_REGEX2 = /^[/\\]{2}/;
|
|
7112
7112
|
var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
7113
7113
|
var _DRIVE_LETTER_RE2 = /^[A-Za-z]:$/;
|
|
7114
|
-
var correctPaths2 = /* @__PURE__ */ __name2(function(
|
|
7115
|
-
if (!
|
|
7114
|
+
var correctPaths2 = /* @__PURE__ */ __name2(function(path7) {
|
|
7115
|
+
if (!path7 || path7.length === 0) {
|
|
7116
7116
|
return ".";
|
|
7117
7117
|
}
|
|
7118
|
-
|
|
7119
|
-
const isUNCPath =
|
|
7120
|
-
const isPathAbsolute = isAbsolute2(
|
|
7121
|
-
const trailingSeparator =
|
|
7122
|
-
|
|
7123
|
-
if (
|
|
7118
|
+
path7 = normalizeWindowsPath2(path7);
|
|
7119
|
+
const isUNCPath = path7.match(_UNC_REGEX2);
|
|
7120
|
+
const isPathAbsolute = isAbsolute2(path7);
|
|
7121
|
+
const trailingSeparator = path7[path7.length - 1] === "/";
|
|
7122
|
+
path7 = normalizeString2(path7, !isPathAbsolute);
|
|
7123
|
+
if (path7.length === 0) {
|
|
7124
7124
|
if (isPathAbsolute) {
|
|
7125
7125
|
return "/";
|
|
7126
7126
|
}
|
|
7127
7127
|
return trailingSeparator ? "./" : ".";
|
|
7128
7128
|
}
|
|
7129
7129
|
if (trailingSeparator) {
|
|
7130
|
-
|
|
7130
|
+
path7 += "/";
|
|
7131
7131
|
}
|
|
7132
|
-
if (_DRIVE_LETTER_RE2.test(
|
|
7133
|
-
|
|
7132
|
+
if (_DRIVE_LETTER_RE2.test(path7)) {
|
|
7133
|
+
path7 += "/";
|
|
7134
7134
|
}
|
|
7135
7135
|
if (isUNCPath) {
|
|
7136
7136
|
if (!isPathAbsolute) {
|
|
7137
|
-
return `//./${
|
|
7137
|
+
return `//./${path7}`;
|
|
7138
7138
|
}
|
|
7139
|
-
return `//${
|
|
7139
|
+
return `//${path7}`;
|
|
7140
7140
|
}
|
|
7141
|
-
return isPathAbsolute && !isAbsolute2(
|
|
7141
|
+
return isPathAbsolute && !isAbsolute2(path7) ? `/${path7}` : path7;
|
|
7142
7142
|
}, "correctPaths");
|
|
7143
7143
|
function cwd() {
|
|
7144
7144
|
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
@@ -7148,15 +7148,15 @@ function cwd() {
|
|
|
7148
7148
|
}
|
|
7149
7149
|
__name(cwd, "cwd");
|
|
7150
7150
|
__name2(cwd, "cwd");
|
|
7151
|
-
function normalizeString2(
|
|
7151
|
+
function normalizeString2(path7, allowAboveRoot) {
|
|
7152
7152
|
let res = "";
|
|
7153
7153
|
let lastSegmentLength = 0;
|
|
7154
7154
|
let lastSlash = -1;
|
|
7155
7155
|
let dots = 0;
|
|
7156
7156
|
let char = null;
|
|
7157
|
-
for (let index = 0; index <=
|
|
7158
|
-
if (index <
|
|
7159
|
-
char =
|
|
7157
|
+
for (let index = 0; index <= path7.length; ++index) {
|
|
7158
|
+
if (index < path7.length) {
|
|
7159
|
+
char = path7[index];
|
|
7160
7160
|
} else if (char === "/") {
|
|
7161
7161
|
break;
|
|
7162
7162
|
} else {
|
|
@@ -7192,9 +7192,9 @@ function normalizeString2(path5, allowAboveRoot) {
|
|
|
7192
7192
|
}
|
|
7193
7193
|
} else {
|
|
7194
7194
|
if (res.length > 0) {
|
|
7195
|
-
res += `/${
|
|
7195
|
+
res += `/${path7.slice(lastSlash + 1, index)}`;
|
|
7196
7196
|
} else {
|
|
7197
|
-
res =
|
|
7197
|
+
res = path7.slice(lastSlash + 1, index);
|
|
7198
7198
|
}
|
|
7199
7199
|
lastSegmentLength = index - lastSlash - 1;
|
|
7200
7200
|
}
|
|
@@ -7294,20 +7294,20 @@ init_cjs_shims();
|
|
|
7294
7294
|
// ../path/src/is-file.ts
|
|
7295
7295
|
init_cjs_shims();
|
|
7296
7296
|
var import_node_fs3 = require("node:fs");
|
|
7297
|
-
function isFile(
|
|
7298
|
-
return Boolean((0, import_node_fs3.statSync)(additionalPath ? joinPaths(additionalPath,
|
|
7297
|
+
function isFile(path7, additionalPath) {
|
|
7298
|
+
return Boolean((0, import_node_fs3.statSync)(additionalPath ? joinPaths(additionalPath, path7) : path7, {
|
|
7299
7299
|
throwIfNoEntry: false
|
|
7300
7300
|
})?.isFile());
|
|
7301
7301
|
}
|
|
7302
7302
|
__name(isFile, "isFile");
|
|
7303
|
-
function isDirectory(
|
|
7304
|
-
return Boolean((0, import_node_fs3.statSync)(additionalPath ? joinPaths(additionalPath,
|
|
7303
|
+
function isDirectory(path7, additionalPath) {
|
|
7304
|
+
return Boolean((0, import_node_fs3.statSync)(additionalPath ? joinPaths(additionalPath, path7) : path7, {
|
|
7305
7305
|
throwIfNoEntry: false
|
|
7306
7306
|
})?.isDirectory());
|
|
7307
7307
|
}
|
|
7308
7308
|
__name(isDirectory, "isDirectory");
|
|
7309
|
-
function isAbsolutePath(
|
|
7310
|
-
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(
|
|
7309
|
+
function isAbsolutePath(path7) {
|
|
7310
|
+
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path7);
|
|
7311
7311
|
}
|
|
7312
7312
|
__name(isAbsolutePath, "isAbsolutePath");
|
|
7313
7313
|
|
|
@@ -7322,45 +7322,45 @@ function normalizeWindowsPath3(input = "") {
|
|
|
7322
7322
|
__name(normalizeWindowsPath3, "normalizeWindowsPath");
|
|
7323
7323
|
var _UNC_REGEX3 = /^[/\\]{2}/;
|
|
7324
7324
|
var _DRIVE_LETTER_RE3 = /^[A-Z]:$/i;
|
|
7325
|
-
function correctPath(
|
|
7326
|
-
if (!
|
|
7325
|
+
function correctPath(path7) {
|
|
7326
|
+
if (!path7 || path7.length === 0) {
|
|
7327
7327
|
return ".";
|
|
7328
7328
|
}
|
|
7329
|
-
|
|
7330
|
-
const isUNCPath =
|
|
7331
|
-
const isPathAbsolute = isAbsolutePath(
|
|
7332
|
-
const trailingSeparator =
|
|
7333
|
-
|
|
7334
|
-
if (
|
|
7329
|
+
path7 = normalizeWindowsPath3(path7);
|
|
7330
|
+
const isUNCPath = path7.match(_UNC_REGEX3);
|
|
7331
|
+
const isPathAbsolute = isAbsolutePath(path7);
|
|
7332
|
+
const trailingSeparator = path7[path7.length - 1] === "/";
|
|
7333
|
+
path7 = normalizeString3(path7, !isPathAbsolute);
|
|
7334
|
+
if (path7.length === 0) {
|
|
7335
7335
|
if (isPathAbsolute) {
|
|
7336
7336
|
return "/";
|
|
7337
7337
|
}
|
|
7338
7338
|
return trailingSeparator ? "./" : ".";
|
|
7339
7339
|
}
|
|
7340
7340
|
if (trailingSeparator) {
|
|
7341
|
-
|
|
7341
|
+
path7 += "/";
|
|
7342
7342
|
}
|
|
7343
|
-
if (_DRIVE_LETTER_RE3.test(
|
|
7344
|
-
|
|
7343
|
+
if (_DRIVE_LETTER_RE3.test(path7)) {
|
|
7344
|
+
path7 += "/";
|
|
7345
7345
|
}
|
|
7346
7346
|
if (isUNCPath) {
|
|
7347
7347
|
if (!isPathAbsolute) {
|
|
7348
|
-
return `//./${
|
|
7348
|
+
return `//./${path7}`;
|
|
7349
7349
|
}
|
|
7350
|
-
return `//${
|
|
7350
|
+
return `//${path7}`;
|
|
7351
7351
|
}
|
|
7352
|
-
return isPathAbsolute && !isAbsolutePath(
|
|
7352
|
+
return isPathAbsolute && !isAbsolutePath(path7) ? `/${path7}` : path7;
|
|
7353
7353
|
}
|
|
7354
7354
|
__name(correctPath, "correctPath");
|
|
7355
|
-
function normalizeString3(
|
|
7355
|
+
function normalizeString3(path7, allowAboveRoot) {
|
|
7356
7356
|
let res = "";
|
|
7357
7357
|
let lastSegmentLength = 0;
|
|
7358
7358
|
let lastSlash = -1;
|
|
7359
7359
|
let dots = 0;
|
|
7360
7360
|
let char = null;
|
|
7361
|
-
for (let index = 0; index <=
|
|
7362
|
-
if (index <
|
|
7363
|
-
char =
|
|
7361
|
+
for (let index = 0; index <= path7.length; ++index) {
|
|
7362
|
+
if (index < path7.length) {
|
|
7363
|
+
char = path7[index];
|
|
7364
7364
|
} else if (char === "/") {
|
|
7365
7365
|
break;
|
|
7366
7366
|
} else {
|
|
@@ -7396,9 +7396,9 @@ function normalizeString3(path5, allowAboveRoot) {
|
|
|
7396
7396
|
}
|
|
7397
7397
|
} else {
|
|
7398
7398
|
if (res.length > 0) {
|
|
7399
|
-
res += `/${
|
|
7399
|
+
res += `/${path7.slice(lastSlash + 1, index)}`;
|
|
7400
7400
|
} else {
|
|
7401
|
-
res =
|
|
7401
|
+
res = path7.slice(lastSlash + 1, index);
|
|
7402
7402
|
}
|
|
7403
7403
|
lastSegmentLength = index - lastSlash - 1;
|
|
7404
7404
|
}
|
|
@@ -7433,17 +7433,17 @@ function findFilePath(filePath) {
|
|
|
7433
7433
|
}), "");
|
|
7434
7434
|
}
|
|
7435
7435
|
__name(findFilePath, "findFilePath");
|
|
7436
|
-
function resolvePath(
|
|
7437
|
-
const paths = normalizeWindowsPath3(
|
|
7436
|
+
function resolvePath(path7, cwd2 = getWorkspaceRoot()) {
|
|
7437
|
+
const paths = normalizeWindowsPath3(path7).split("/");
|
|
7438
7438
|
let resolvedPath = "";
|
|
7439
7439
|
let resolvedAbsolute = false;
|
|
7440
7440
|
for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
7441
|
-
const
|
|
7442
|
-
if (!
|
|
7441
|
+
const path8 = index >= 0 ? paths[index] : cwd2;
|
|
7442
|
+
if (!path8 || path8.length === 0) {
|
|
7443
7443
|
continue;
|
|
7444
7444
|
}
|
|
7445
|
-
resolvedPath = joinPaths(
|
|
7446
|
-
resolvedAbsolute = isAbsolutePath(
|
|
7445
|
+
resolvedPath = joinPaths(path8, resolvedPath);
|
|
7446
|
+
resolvedAbsolute = isAbsolutePath(path8);
|
|
7447
7447
|
}
|
|
7448
7448
|
resolvedPath = normalizeString3(resolvedPath, !resolvedAbsolute);
|
|
7449
7449
|
if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
|
|
@@ -7453,13 +7453,13 @@ function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
|
|
|
7453
7453
|
}
|
|
7454
7454
|
__name(resolvePath, "resolvePath");
|
|
7455
7455
|
function resolvePaths(...paths) {
|
|
7456
|
-
return resolvePath(joinPaths(...paths.map((
|
|
7456
|
+
return resolvePath(joinPaths(...paths.map((path7) => normalizeWindowsPath3(path7))));
|
|
7457
7457
|
}
|
|
7458
7458
|
__name(resolvePaths, "resolvePaths");
|
|
7459
7459
|
|
|
7460
7460
|
// ../path/src/get-parent-path.ts
|
|
7461
|
-
var resolveParentPath = /* @__PURE__ */ __name((
|
|
7462
|
-
return resolvePaths(
|
|
7461
|
+
var resolveParentPath = /* @__PURE__ */ __name((path7) => {
|
|
7462
|
+
return resolvePaths(path7, "..");
|
|
7463
7463
|
}, "resolveParentPath");
|
|
7464
7464
|
var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
|
|
7465
7465
|
const ignoreCase = options?.ignoreCase ?? true;
|
|
@@ -7845,15 +7845,15 @@ var getProcedureTypeByOpName = /* @__PURE__ */ __name((opName) => {
|
|
|
7845
7845
|
return procType;
|
|
7846
7846
|
}, "getProcedureTypeByOpName");
|
|
7847
7847
|
function resolveModelsComments(models, hiddenModels) {
|
|
7848
|
-
const
|
|
7849
|
-
const
|
|
7850
|
-
const
|
|
7848
|
+
const modelAttributeRegex2 = /(?:@@Gen\.)+[A-z]+\(.+\)/;
|
|
7849
|
+
const attributeNameRegex2 = /\.+[A-Z]+\(+/i;
|
|
7850
|
+
const attributeArgsRegex2 = /\(+[A-Z]+:.+\)/i;
|
|
7851
7851
|
for (const model of models) {
|
|
7852
7852
|
if (model.documentation) {
|
|
7853
|
-
const attribute = model.documentation?.match(
|
|
7854
|
-
const attributeName = attribute?.match(
|
|
7853
|
+
const attribute = model.documentation?.match(modelAttributeRegex2)?.[0];
|
|
7854
|
+
const attributeName = attribute?.match(attributeNameRegex2)?.[0]?.slice(1, -1);
|
|
7855
7855
|
if (attributeName !== "model") continue;
|
|
7856
|
-
const rawAttributeArgs = attribute?.match(
|
|
7856
|
+
const rawAttributeArgs = attribute?.match(attributeArgsRegex2)?.[0]?.slice(1, -1);
|
|
7857
7857
|
const parsedAttributeArgs = {};
|
|
7858
7858
|
if (rawAttributeArgs) {
|
|
7859
7859
|
const rawAttributeArgsParts = rawAttributeArgs.split(":").map((it) => it.trim()).map((part) => part.startsWith("[") ? part : part.split(",")).flat().map((it) => it.trim());
|
|
@@ -9162,7 +9162,7 @@ var isURL = /* @__PURE__ */ __name((payload) => payload instanceof URL, "isURL")
|
|
|
9162
9162
|
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
|
|
9163
9163
|
init_cjs_shims();
|
|
9164
9164
|
var escapeKey = /* @__PURE__ */ __name((key) => key.replace(/\./g, "\\."), "escapeKey");
|
|
9165
|
-
var stringifyPath = /* @__PURE__ */ __name((
|
|
9165
|
+
var stringifyPath = /* @__PURE__ */ __name((path7) => path7.map(String).map(escapeKey).join("."), "stringifyPath");
|
|
9166
9166
|
var parsePath = /* @__PURE__ */ __name((string) => {
|
|
9167
9167
|
const result = [];
|
|
9168
9168
|
let segment = "";
|
|
@@ -9425,27 +9425,27 @@ var getNthKey = /* @__PURE__ */ __name((value, n) => {
|
|
|
9425
9425
|
}
|
|
9426
9426
|
return keys.next().value;
|
|
9427
9427
|
}, "getNthKey");
|
|
9428
|
-
function validatePath(
|
|
9429
|
-
if (includes(
|
|
9428
|
+
function validatePath(path7) {
|
|
9429
|
+
if (includes(path7, "__proto__")) {
|
|
9430
9430
|
throw new Error("__proto__ is not allowed as a property");
|
|
9431
9431
|
}
|
|
9432
|
-
if (includes(
|
|
9432
|
+
if (includes(path7, "prototype")) {
|
|
9433
9433
|
throw new Error("prototype is not allowed as a property");
|
|
9434
9434
|
}
|
|
9435
|
-
if (includes(
|
|
9435
|
+
if (includes(path7, "constructor")) {
|
|
9436
9436
|
throw new Error("constructor is not allowed as a property");
|
|
9437
9437
|
}
|
|
9438
9438
|
}
|
|
9439
9439
|
__name(validatePath, "validatePath");
|
|
9440
|
-
var getDeep = /* @__PURE__ */ __name((object,
|
|
9441
|
-
validatePath(
|
|
9442
|
-
for (let i = 0; i <
|
|
9443
|
-
const key =
|
|
9440
|
+
var getDeep = /* @__PURE__ */ __name((object, path7) => {
|
|
9441
|
+
validatePath(path7);
|
|
9442
|
+
for (let i = 0; i < path7.length; i++) {
|
|
9443
|
+
const key = path7[i];
|
|
9444
9444
|
if (isSet(object)) {
|
|
9445
9445
|
object = getNthKey(object, +key);
|
|
9446
9446
|
} else if (isMap(object)) {
|
|
9447
9447
|
const row = +key;
|
|
9448
|
-
const type = +
|
|
9448
|
+
const type = +path7[++i] === 0 ? "key" : "value";
|
|
9449
9449
|
const keyOfRow = getNthKey(object, row);
|
|
9450
9450
|
switch (type) {
|
|
9451
9451
|
case "key":
|
|
@@ -9461,14 +9461,14 @@ var getDeep = /* @__PURE__ */ __name((object, path5) => {
|
|
|
9461
9461
|
}
|
|
9462
9462
|
return object;
|
|
9463
9463
|
}, "getDeep");
|
|
9464
|
-
var setDeep = /* @__PURE__ */ __name((object,
|
|
9465
|
-
validatePath(
|
|
9466
|
-
if (
|
|
9464
|
+
var setDeep = /* @__PURE__ */ __name((object, path7, mapper) => {
|
|
9465
|
+
validatePath(path7);
|
|
9466
|
+
if (path7.length === 0) {
|
|
9467
9467
|
return mapper(object);
|
|
9468
9468
|
}
|
|
9469
9469
|
let parent = object;
|
|
9470
|
-
for (let i = 0; i <
|
|
9471
|
-
const key =
|
|
9470
|
+
for (let i = 0; i < path7.length - 1; i++) {
|
|
9471
|
+
const key = path7[i];
|
|
9472
9472
|
if (isArray(parent)) {
|
|
9473
9473
|
const index = +key;
|
|
9474
9474
|
parent = parent[index];
|
|
@@ -9478,12 +9478,12 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
|
9478
9478
|
const row = +key;
|
|
9479
9479
|
parent = getNthKey(parent, row);
|
|
9480
9480
|
} else if (isMap(parent)) {
|
|
9481
|
-
const isEnd = i ===
|
|
9481
|
+
const isEnd = i === path7.length - 2;
|
|
9482
9482
|
if (isEnd) {
|
|
9483
9483
|
break;
|
|
9484
9484
|
}
|
|
9485
9485
|
const row = +key;
|
|
9486
|
-
const type = +
|
|
9486
|
+
const type = +path7[++i] === 0 ? "key" : "value";
|
|
9487
9487
|
const keyOfRow = getNthKey(parent, row);
|
|
9488
9488
|
switch (type) {
|
|
9489
9489
|
case "key":
|
|
@@ -9495,7 +9495,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
|
9495
9495
|
}
|
|
9496
9496
|
}
|
|
9497
9497
|
}
|
|
9498
|
-
const lastKey =
|
|
9498
|
+
const lastKey = path7[path7.length - 1];
|
|
9499
9499
|
if (isArray(parent)) {
|
|
9500
9500
|
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
9501
9501
|
} else if (isPlainObject2(parent)) {
|
|
@@ -9510,7 +9510,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
|
9510
9510
|
}
|
|
9511
9511
|
}
|
|
9512
9512
|
if (isMap(parent)) {
|
|
9513
|
-
const row = +
|
|
9513
|
+
const row = +path7[path7.length - 2];
|
|
9514
9514
|
const keyToRow = getNthKey(parent, row);
|
|
9515
9515
|
const type = +lastKey === 0 ? "key" : "value";
|
|
9516
9516
|
switch (type) {
|
|
@@ -9556,15 +9556,15 @@ function traverse(tree, walker2, origin = []) {
|
|
|
9556
9556
|
}
|
|
9557
9557
|
__name(traverse, "traverse");
|
|
9558
9558
|
function applyValueAnnotations(plain, annotations, superJson) {
|
|
9559
|
-
traverse(annotations, (type,
|
|
9560
|
-
plain = setDeep(plain,
|
|
9559
|
+
traverse(annotations, (type, path7) => {
|
|
9560
|
+
plain = setDeep(plain, path7, (v) => untransformValue(v, type, superJson));
|
|
9561
9561
|
});
|
|
9562
9562
|
return plain;
|
|
9563
9563
|
}
|
|
9564
9564
|
__name(applyValueAnnotations, "applyValueAnnotations");
|
|
9565
9565
|
function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
9566
|
-
function apply(identicalPaths,
|
|
9567
|
-
const object = getDeep(plain, parsePath(
|
|
9566
|
+
function apply(identicalPaths, path7) {
|
|
9567
|
+
const object = getDeep(plain, parsePath(path7));
|
|
9568
9568
|
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
|
9569
9569
|
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
9570
9570
|
});
|
|
@@ -9585,13 +9585,13 @@ function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
|
9585
9585
|
}
|
|
9586
9586
|
__name(applyReferentialEqualityAnnotations, "applyReferentialEqualityAnnotations");
|
|
9587
9587
|
var isDeep = /* @__PURE__ */ __name((object, superJson) => isPlainObject2(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson), "isDeep");
|
|
9588
|
-
function addIdentity(object,
|
|
9588
|
+
function addIdentity(object, path7, identities) {
|
|
9589
9589
|
const existingSet = identities.get(object);
|
|
9590
9590
|
if (existingSet) {
|
|
9591
|
-
existingSet.push(
|
|
9591
|
+
existingSet.push(path7);
|
|
9592
9592
|
} else {
|
|
9593
9593
|
identities.set(object, [
|
|
9594
|
-
|
|
9594
|
+
path7
|
|
9595
9595
|
]);
|
|
9596
9596
|
}
|
|
9597
9597
|
}
|
|
@@ -9604,7 +9604,7 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9604
9604
|
return;
|
|
9605
9605
|
}
|
|
9606
9606
|
if (!dedupe) {
|
|
9607
|
-
paths = paths.map((
|
|
9607
|
+
paths = paths.map((path7) => path7.map(String)).sort((a, b) => a.length - b.length);
|
|
9608
9608
|
}
|
|
9609
9609
|
const [representativePath, ...identicalPaths] = paths;
|
|
9610
9610
|
if (representativePath.length === 0) {
|
|
@@ -9629,10 +9629,10 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9629
9629
|
}
|
|
9630
9630
|
}
|
|
9631
9631
|
__name(generateReferentialEqualityAnnotations, "generateReferentialEqualityAnnotations");
|
|
9632
|
-
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe,
|
|
9632
|
+
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path7 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
9633
9633
|
const primitive = isPrimitive(object);
|
|
9634
9634
|
if (!primitive) {
|
|
9635
|
-
addIdentity(object,
|
|
9635
|
+
addIdentity(object, path7, identities);
|
|
9636
9636
|
const seen = seenObjects.get(object);
|
|
9637
9637
|
if (seen) {
|
|
9638
9638
|
return dedupe ? {
|
|
@@ -9669,7 +9669,7 @@ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path
|
|
|
9669
9669
|
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
9670
9670
|
}
|
|
9671
9671
|
const recursiveResult = walker(value, identities, superJson, dedupe, [
|
|
9672
|
-
...
|
|
9672
|
+
...path7,
|
|
9673
9673
|
index
|
|
9674
9674
|
], [
|
|
9675
9675
|
...objectsInThisPath,
|
|
@@ -10248,6 +10248,9 @@ var writeFile = /* @__PURE__ */ __name(async (filePath, content, options) => {
|
|
|
10248
10248
|
return (0, import_promises3.writeFile)(filePath, content || "", options);
|
|
10249
10249
|
}, "writeFile");
|
|
10250
10250
|
|
|
10251
|
+
// src/utils/write-file-safely.ts
|
|
10252
|
+
var import_node_path5 = __toESM(require("node:path"), 1);
|
|
10253
|
+
|
|
10251
10254
|
// src/utils/format-file.ts
|
|
10252
10255
|
init_cjs_shims();
|
|
10253
10256
|
var import_prettier = __toESM(require("prettier"), 1);
|
|
@@ -10274,13 +10277,1185 @@ async function formatFile(content) {
|
|
|
10274
10277
|
__name(formatFile, "formatFile");
|
|
10275
10278
|
|
|
10276
10279
|
// src/utils/write-file-safely.ts
|
|
10277
|
-
var
|
|
10280
|
+
var indexExports = /* @__PURE__ */ new Set();
|
|
10281
|
+
var addIndexExport = /* @__PURE__ */ __name((filePath) => {
|
|
10282
|
+
indexExports.add(filePath);
|
|
10283
|
+
}, "addIndexExport");
|
|
10284
|
+
var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addToIndex = true) => {
|
|
10278
10285
|
const [fileContent] = await Promise.all([
|
|
10279
10286
|
formatFile(content),
|
|
10280
10287
|
createDirectory(findFilePath(writeLocation))
|
|
10281
10288
|
]);
|
|
10282
10289
|
await writeFile(writeLocation, fileContent);
|
|
10290
|
+
if (addToIndex) {
|
|
10291
|
+
addIndexExport(writeLocation);
|
|
10292
|
+
}
|
|
10283
10293
|
}, "writeFileSafely");
|
|
10294
|
+
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10295
|
+
const rows = Array.from(indexExports).map((filePath) => {
|
|
10296
|
+
let relativePath = import_node_path5.default.relative(import_node_path5.default.dirname(indexPath), filePath);
|
|
10297
|
+
if (relativePath.endsWith(".ts")) {
|
|
10298
|
+
relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
|
|
10299
|
+
}
|
|
10300
|
+
const normalized = correctPath(relativePath);
|
|
10301
|
+
return `export * from './${normalized}'`;
|
|
10302
|
+
});
|
|
10303
|
+
await writeFileSafely(indexPath, rows.join("\n"), false);
|
|
10304
|
+
}, "writeIndexFile");
|
|
10305
|
+
|
|
10306
|
+
// src/zod-helpers/aggregate-helpers.ts
|
|
10307
|
+
init_cjs_shims();
|
|
10308
|
+
var isAggregateOutputType = /* @__PURE__ */ __name((name) => /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(name), "isAggregateOutputType");
|
|
10309
|
+
var isAggregateInputType = /* @__PURE__ */ __name((name) => name.endsWith("CountAggregateInput") || name.endsWith("SumAggregateInput") || name.endsWith("AvgAggregateInput") || name.endsWith("MinAggregateInput") || name.endsWith("MaxAggregateInput"), "isAggregateInputType");
|
|
10310
|
+
function addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes) {
|
|
10311
|
+
const aggregateOutputTypes = outputObjectTypes.filter(({ name }) => isAggregateOutputType(name));
|
|
10312
|
+
for (const aggregateOutputType of aggregateOutputTypes) {
|
|
10313
|
+
const name = aggregateOutputType.name.replace(/(?:OutputType|Output)$/, "");
|
|
10314
|
+
inputObjectTypes.push({
|
|
10315
|
+
constraints: {
|
|
10316
|
+
maxNumFields: null,
|
|
10317
|
+
minNumFields: null
|
|
10318
|
+
},
|
|
10319
|
+
name: `${name}Input`,
|
|
10320
|
+
fields: aggregateOutputType.fields.map((field) => ({
|
|
10321
|
+
name: field.name,
|
|
10322
|
+
isNullable: false,
|
|
10323
|
+
isRequired: false,
|
|
10324
|
+
inputTypes: [
|
|
10325
|
+
{
|
|
10326
|
+
isList: false,
|
|
10327
|
+
type: "True",
|
|
10328
|
+
location: "scalar"
|
|
10329
|
+
}
|
|
10330
|
+
]
|
|
10331
|
+
}))
|
|
10332
|
+
});
|
|
10333
|
+
}
|
|
10334
|
+
}
|
|
10335
|
+
__name(addMissingInputObjectTypesForAggregate, "addMissingInputObjectTypesForAggregate");
|
|
10336
|
+
function resolveZodAggregateOperationSupport(inputObjectTypes) {
|
|
10337
|
+
const aggregateOperationSupport = {};
|
|
10338
|
+
for (const inputType of inputObjectTypes) {
|
|
10339
|
+
if (isAggregateInputType(inputType.name)) {
|
|
10340
|
+
const name = inputType.name.replace("AggregateInput", "");
|
|
10341
|
+
if (name.endsWith("Count")) {
|
|
10342
|
+
const model = name.replace("Count", "");
|
|
10343
|
+
aggregateOperationSupport[model] = {
|
|
10344
|
+
...aggregateOperationSupport[model],
|
|
10345
|
+
count: true
|
|
10346
|
+
};
|
|
10347
|
+
} else if (name.endsWith("Min")) {
|
|
10348
|
+
const model = name.replace("Min", "");
|
|
10349
|
+
aggregateOperationSupport[model] = {
|
|
10350
|
+
...aggregateOperationSupport[model],
|
|
10351
|
+
min: true
|
|
10352
|
+
};
|
|
10353
|
+
} else if (name.endsWith("Max")) {
|
|
10354
|
+
const model = name.replace("Max", "");
|
|
10355
|
+
aggregateOperationSupport[model] = {
|
|
10356
|
+
...aggregateOperationSupport[model],
|
|
10357
|
+
max: true
|
|
10358
|
+
};
|
|
10359
|
+
} else if (name.endsWith("Sum")) {
|
|
10360
|
+
const model = name.replace("Sum", "");
|
|
10361
|
+
aggregateOperationSupport[model] = {
|
|
10362
|
+
...aggregateOperationSupport[model],
|
|
10363
|
+
sum: true
|
|
10364
|
+
};
|
|
10365
|
+
} else if (name.endsWith("Avg")) {
|
|
10366
|
+
const model = name.replace("Avg", "");
|
|
10367
|
+
aggregateOperationSupport[model] = {
|
|
10368
|
+
...aggregateOperationSupport[model],
|
|
10369
|
+
avg: true
|
|
10370
|
+
};
|
|
10371
|
+
}
|
|
10372
|
+
}
|
|
10373
|
+
}
|
|
10374
|
+
return aggregateOperationSupport;
|
|
10375
|
+
}
|
|
10376
|
+
__name(resolveZodAggregateOperationSupport, "resolveZodAggregateOperationSupport");
|
|
10377
|
+
|
|
10378
|
+
// src/zod-helpers/comments-helpers.ts
|
|
10379
|
+
init_cjs_shims();
|
|
10380
|
+
var modelAttributeRegex = /(?:@@Gen\.)+[A-z]+\(.+\)/;
|
|
10381
|
+
var attributeNameRegex = /\.+[A-Z]+\(+/i;
|
|
10382
|
+
var attributeArgsRegex = /\(+[A-Z]+:.+\)/i;
|
|
10383
|
+
function resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields) {
|
|
10384
|
+
models = collectHiddenModels(models, hiddenModels);
|
|
10385
|
+
collectHiddenFields(models, hiddenModels, hiddenFields);
|
|
10386
|
+
hideModelOperations(models, modelOperations);
|
|
10387
|
+
hideEnums(enumTypes, hiddenModels);
|
|
10388
|
+
}
|
|
10389
|
+
__name(resolveZodModelsComments, "resolveZodModelsComments");
|
|
10390
|
+
function collectHiddenModels(models, hiddenModels) {
|
|
10391
|
+
return models.map((model) => {
|
|
10392
|
+
if (model.documentation) {
|
|
10393
|
+
const attribute = model.documentation?.match(modelAttributeRegex)?.[0];
|
|
10394
|
+
const attributeName = attribute?.match(attributeNameRegex)?.[0]?.slice(1, -1);
|
|
10395
|
+
if (attributeName !== "model") {
|
|
10396
|
+
return model;
|
|
10397
|
+
}
|
|
10398
|
+
const rawAttributeArgs = attribute?.match(attributeArgsRegex)?.[0]?.slice(1, -1);
|
|
10399
|
+
const parsedAttributeArgs = {};
|
|
10400
|
+
if (rawAttributeArgs) {
|
|
10401
|
+
const rawAttributeArgsParts = rawAttributeArgs.split(":").map((it) => it.trim()).map((part) => part.startsWith("[") ? part : part.split(",")).flat().map((it) => it.trim());
|
|
10402
|
+
for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {
|
|
10403
|
+
const key = rawAttributeArgsParts[i];
|
|
10404
|
+
const value = rawAttributeArgsParts[i + 1];
|
|
10405
|
+
parsedAttributeArgs[key] = JSON.parse(value);
|
|
10406
|
+
}
|
|
10407
|
+
}
|
|
10408
|
+
if (parsedAttributeArgs.hide) {
|
|
10409
|
+
hiddenModels.push(model.name);
|
|
10410
|
+
return null;
|
|
10411
|
+
}
|
|
10412
|
+
}
|
|
10413
|
+
return model;
|
|
10414
|
+
}).filter(Boolean);
|
|
10415
|
+
}
|
|
10416
|
+
__name(collectHiddenModels, "collectHiddenModels");
|
|
10417
|
+
function collectHiddenFields(models, hiddenModels, hiddenFields) {
|
|
10418
|
+
models.forEach((model) => {
|
|
10419
|
+
model.fields.forEach((field) => {
|
|
10420
|
+
if (hiddenModels.includes(field.type)) {
|
|
10421
|
+
hiddenFields.push(field.name);
|
|
10422
|
+
if (field.relationFromFields) {
|
|
10423
|
+
field.relationFromFields.forEach((item) => hiddenFields.push(item));
|
|
10424
|
+
}
|
|
10425
|
+
}
|
|
10426
|
+
});
|
|
10427
|
+
});
|
|
10428
|
+
}
|
|
10429
|
+
__name(collectHiddenFields, "collectHiddenFields");
|
|
10430
|
+
function hideEnums(enumTypes, hiddenModels) {
|
|
10431
|
+
enumTypes.prisma = enumTypes.prisma.filter((item) => !hiddenModels.find((model) => item.name.startsWith(model)));
|
|
10432
|
+
}
|
|
10433
|
+
__name(hideEnums, "hideEnums");
|
|
10434
|
+
function hideModelOperations(models, modelOperations) {
|
|
10435
|
+
let i = modelOperations.length;
|
|
10436
|
+
while (i >= 0) {
|
|
10437
|
+
--i;
|
|
10438
|
+
const modelOperation = modelOperations[i];
|
|
10439
|
+
if (modelOperation && !models.find((model) => {
|
|
10440
|
+
return model.name === modelOperation.model;
|
|
10441
|
+
})) {
|
|
10442
|
+
modelOperations.splice(i, 1);
|
|
10443
|
+
}
|
|
10444
|
+
}
|
|
10445
|
+
}
|
|
10446
|
+
__name(hideModelOperations, "hideModelOperations");
|
|
10447
|
+
function hideZodInputObjectTypesAndRelatedFields(inputObjectTypes, hiddenModels, hiddenFields) {
|
|
10448
|
+
let j = inputObjectTypes.length;
|
|
10449
|
+
while (j >= 0) {
|
|
10450
|
+
--j;
|
|
10451
|
+
const inputType = inputObjectTypes[j];
|
|
10452
|
+
if (inputType && (hiddenModels.includes(inputType?.meta?.source) || hiddenModels.find((model) => inputType.name.startsWith(model)))) {
|
|
10453
|
+
inputObjectTypes.splice(j, 1);
|
|
10454
|
+
} else {
|
|
10455
|
+
let k = inputType?.fields?.length ?? 0;
|
|
10456
|
+
while (k >= 0) {
|
|
10457
|
+
--k;
|
|
10458
|
+
const field = inputType?.fields?.[k];
|
|
10459
|
+
if (field && hiddenFields.includes(field.name)) {
|
|
10460
|
+
inputObjectTypes[j].fields.slice(k, 1);
|
|
10461
|
+
}
|
|
10462
|
+
}
|
|
10463
|
+
}
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10466
|
+
__name(hideZodInputObjectTypesAndRelatedFields, "hideZodInputObjectTypesAndRelatedFields");
|
|
10467
|
+
|
|
10468
|
+
// src/zod-helpers/generator-helpers.ts
|
|
10469
|
+
init_cjs_shims();
|
|
10470
|
+
|
|
10471
|
+
// src/zod-helpers/transformer.ts
|
|
10472
|
+
init_cjs_shims();
|
|
10473
|
+
var import_node_path6 = __toESM(require("node:path"), 1);
|
|
10474
|
+
|
|
10475
|
+
// src/zod-helpers/model-helpers.ts
|
|
10476
|
+
init_cjs_shims();
|
|
10477
|
+
function checkModelHasModelRelation(model) {
|
|
10478
|
+
const { fields: modelFields } = model;
|
|
10479
|
+
for (const modelField of modelFields) {
|
|
10480
|
+
const isRelationField = checkIsModelRelationField(modelField);
|
|
10481
|
+
if (isRelationField) {
|
|
10482
|
+
return true;
|
|
10483
|
+
}
|
|
10484
|
+
}
|
|
10485
|
+
return false;
|
|
10486
|
+
}
|
|
10487
|
+
__name(checkModelHasModelRelation, "checkModelHasModelRelation");
|
|
10488
|
+
function checkModelHasManyModelRelation(model) {
|
|
10489
|
+
const { fields: modelFields } = model;
|
|
10490
|
+
for (const modelField of modelFields) {
|
|
10491
|
+
const isManyRelationField = checkIsManyModelRelationField(modelField);
|
|
10492
|
+
if (isManyRelationField) {
|
|
10493
|
+
return true;
|
|
10494
|
+
}
|
|
10495
|
+
}
|
|
10496
|
+
return false;
|
|
10497
|
+
}
|
|
10498
|
+
__name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
|
|
10499
|
+
function checkIsModelRelationField(modelField) {
|
|
10500
|
+
const { kind, relationName } = modelField;
|
|
10501
|
+
return kind === "object" && !!relationName;
|
|
10502
|
+
}
|
|
10503
|
+
__name(checkIsModelRelationField, "checkIsModelRelationField");
|
|
10504
|
+
function checkIsManyModelRelationField(modelField) {
|
|
10505
|
+
return checkIsModelRelationField(modelField) && modelField.isList;
|
|
10506
|
+
}
|
|
10507
|
+
__name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
|
|
10508
|
+
function findModelByName(models, modelName) {
|
|
10509
|
+
return models.find(({ name }) => name === modelName);
|
|
10510
|
+
}
|
|
10511
|
+
__name(findModelByName, "findModelByName");
|
|
10512
|
+
|
|
10513
|
+
// src/zod-helpers/mongodb-helpers.ts
|
|
10514
|
+
init_cjs_shims();
|
|
10515
|
+
function addMissingInputObjectTypesForMongoDbRawOpsAndQueries(modelOperations, outputObjectTypes, inputObjectTypes) {
|
|
10516
|
+
const rawOpsMap = resolveMongoDbRawOperations(modelOperations);
|
|
10517
|
+
Transformer.rawOpsMap = rawOpsMap ?? {};
|
|
10518
|
+
const mongoDbRawQueryInputObjectTypes = resolveMongoDbRawQueryInputObjectTypes(outputObjectTypes);
|
|
10519
|
+
for (const mongoDbRawQueryInputType of mongoDbRawQueryInputObjectTypes) {
|
|
10520
|
+
inputObjectTypes.push(mongoDbRawQueryInputType);
|
|
10521
|
+
}
|
|
10522
|
+
}
|
|
10523
|
+
__name(addMissingInputObjectTypesForMongoDbRawOpsAndQueries, "addMissingInputObjectTypesForMongoDbRawOpsAndQueries");
|
|
10524
|
+
function resolveMongoDbRawOperations(modelOperations) {
|
|
10525
|
+
const rawOpsMap = {};
|
|
10526
|
+
const rawOpsNames = [
|
|
10527
|
+
...new Set(modelOperations.reduce((result, current) => {
|
|
10528
|
+
const keys = Object.keys(current);
|
|
10529
|
+
keys?.forEach((key) => {
|
|
10530
|
+
if (key.includes("Raw")) {
|
|
10531
|
+
result.push(key);
|
|
10532
|
+
}
|
|
10533
|
+
});
|
|
10534
|
+
return result;
|
|
10535
|
+
}, []))
|
|
10536
|
+
];
|
|
10537
|
+
const modelNames = modelOperations.map((item) => item.model);
|
|
10538
|
+
rawOpsNames.forEach((opName) => {
|
|
10539
|
+
modelNames.forEach((modelName) => {
|
|
10540
|
+
const isFind = opName === "findRaw";
|
|
10541
|
+
const opWithModel = `${opName.replace("Raw", "")}${modelName}Raw`;
|
|
10542
|
+
rawOpsMap[opWithModel] = isFind ? `${modelName}FindRawArgs` : `${modelName}AggregateRawArgs`;
|
|
10543
|
+
});
|
|
10544
|
+
});
|
|
10545
|
+
return rawOpsMap;
|
|
10546
|
+
}
|
|
10547
|
+
__name(resolveMongoDbRawOperations, "resolveMongoDbRawOperations");
|
|
10548
|
+
function resolveMongoDbRawQueryInputObjectTypes(outputObjectTypes) {
|
|
10549
|
+
const mongoDbRawQueries = getMongoDbRawQueries(outputObjectTypes);
|
|
10550
|
+
const mongoDbRawQueryInputObjectTypes = mongoDbRawQueries.map((item) => ({
|
|
10551
|
+
name: item.name,
|
|
10552
|
+
constraints: {
|
|
10553
|
+
maxNumFields: null,
|
|
10554
|
+
minNumFields: null
|
|
10555
|
+
},
|
|
10556
|
+
fields: item.args.map((arg) => ({
|
|
10557
|
+
name: arg.name,
|
|
10558
|
+
isRequired: arg.isRequired,
|
|
10559
|
+
isNullable: arg.isNullable,
|
|
10560
|
+
inputTypes: arg.inputTypes
|
|
10561
|
+
}))
|
|
10562
|
+
}));
|
|
10563
|
+
return mongoDbRawQueryInputObjectTypes;
|
|
10564
|
+
}
|
|
10565
|
+
__name(resolveMongoDbRawQueryInputObjectTypes, "resolveMongoDbRawQueryInputObjectTypes");
|
|
10566
|
+
function getMongoDbRawQueries(outputObjectTypes) {
|
|
10567
|
+
const queryOutputTypes = outputObjectTypes.filter((item) => item.name === "Query");
|
|
10568
|
+
const mongodbRawQueries = queryOutputTypes?.[0].fields.filter((field) => field.name.includes("Raw")) ?? [];
|
|
10569
|
+
return mongodbRawQueries;
|
|
10570
|
+
}
|
|
10571
|
+
__name(getMongoDbRawQueries, "getMongoDbRawQueries");
|
|
10572
|
+
var isMongodbRawOp = /* @__PURE__ */ __name((name) => /find[\s\S]*?Raw/.test(name) || /aggregate[\s\S]*?Raw/.test(name), "isMongodbRawOp");
|
|
10573
|
+
|
|
10574
|
+
// src/zod-helpers/transformer.ts
|
|
10575
|
+
var Transformer = class _Transformer {
|
|
10576
|
+
static {
|
|
10577
|
+
__name(this, "Transformer");
|
|
10578
|
+
}
|
|
10579
|
+
name;
|
|
10580
|
+
fields;
|
|
10581
|
+
schemaImports = /* @__PURE__ */ new Set();
|
|
10582
|
+
models;
|
|
10583
|
+
modelOperations;
|
|
10584
|
+
aggregateOperationSupport;
|
|
10585
|
+
enumTypes;
|
|
10586
|
+
static enumNames = [];
|
|
10587
|
+
static rawOpsMap = {};
|
|
10588
|
+
static provider;
|
|
10589
|
+
static previewFeatures;
|
|
10590
|
+
static outputPath = "./generated";
|
|
10591
|
+
hasJson = false;
|
|
10592
|
+
static prismaClientOutputPath = "@prisma/client";
|
|
10593
|
+
static isCustomPrismaClientOutputPath = false;
|
|
10594
|
+
static isGenerateSelect = false;
|
|
10595
|
+
static isGenerateInclude = false;
|
|
10596
|
+
constructor(params) {
|
|
10597
|
+
this.name = params.name ?? "";
|
|
10598
|
+
this.fields = params.fields ?? [];
|
|
10599
|
+
this.models = params.models ?? [];
|
|
10600
|
+
this.modelOperations = params.modelOperations ?? [];
|
|
10601
|
+
this.aggregateOperationSupport = params.aggregateOperationSupport ?? {};
|
|
10602
|
+
this.enumTypes = params.enumTypes ?? [];
|
|
10603
|
+
}
|
|
10604
|
+
static setOutputPath(outPath) {
|
|
10605
|
+
this.outputPath = outPath;
|
|
10606
|
+
}
|
|
10607
|
+
static setIsGenerateSelect(isGenerateSelect) {
|
|
10608
|
+
this.isGenerateSelect = isGenerateSelect;
|
|
10609
|
+
}
|
|
10610
|
+
static setIsGenerateInclude(isGenerateInclude) {
|
|
10611
|
+
this.isGenerateInclude = isGenerateInclude;
|
|
10612
|
+
}
|
|
10613
|
+
static getOutputPath() {
|
|
10614
|
+
return this.outputPath;
|
|
10615
|
+
}
|
|
10616
|
+
static setPrismaClientOutputPath(prismaClientCustomPath) {
|
|
10617
|
+
this.prismaClientOutputPath = prismaClientCustomPath;
|
|
10618
|
+
this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
|
|
10619
|
+
}
|
|
10620
|
+
static async generateIndex() {
|
|
10621
|
+
const indexPath = import_node_path6.default.join(_Transformer.outputPath, "schemas/index.ts");
|
|
10622
|
+
await writeIndexFile(indexPath);
|
|
10623
|
+
}
|
|
10624
|
+
async generateEnumSchemas() {
|
|
10625
|
+
for (const enumType2 of this.enumTypes) {
|
|
10626
|
+
const { name, values } = enumType2;
|
|
10627
|
+
await writeFileSafely(import_node_path6.default.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10628
|
+
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10629
|
+
}
|
|
10630
|
+
}
|
|
10631
|
+
generateImportZodStatement() {
|
|
10632
|
+
return "import { z } from 'zod';\n";
|
|
10633
|
+
}
|
|
10634
|
+
generateExportSchemaStatement(name, schema) {
|
|
10635
|
+
return `export const ${name}Schema = ${schema}`;
|
|
10636
|
+
}
|
|
10637
|
+
async generateObjectSchema() {
|
|
10638
|
+
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10639
|
+
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10640
|
+
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10641
|
+
await writeFileSafely(import_node_path6.default.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10642
|
+
}
|
|
10643
|
+
generateObjectSchemaFields() {
|
|
10644
|
+
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
10645
|
+
const [zodStringWithMainType, field, skipValidators] = item;
|
|
10646
|
+
const value = skipValidators ? zodStringWithMainType : this.generateFieldValidators(zodStringWithMainType, field);
|
|
10647
|
+
return value.trim();
|
|
10648
|
+
});
|
|
10649
|
+
return zodObjectSchemaFields;
|
|
10650
|
+
}
|
|
10651
|
+
generateObjectSchemaField(field) {
|
|
10652
|
+
const lines = field.inputTypes;
|
|
10653
|
+
if (lines.length === 0) {
|
|
10654
|
+
return [];
|
|
10655
|
+
}
|
|
10656
|
+
let alternatives = lines.reduce((result, inputType) => {
|
|
10657
|
+
if (inputType.type === "String") {
|
|
10658
|
+
result.push(this.wrapWithZodValidators("z.string()", field));
|
|
10659
|
+
} else if (inputType.type === "Int" || inputType.type === "Float" || inputType.type === "Decimal") {
|
|
10660
|
+
result.push(this.wrapWithZodValidators("z.number()", field));
|
|
10661
|
+
} else if (inputType.type === "BigInt") {
|
|
10662
|
+
result.push(this.wrapWithZodValidators("z.bigint()", field));
|
|
10663
|
+
} else if (inputType.type === "Boolean") {
|
|
10664
|
+
result.push(this.wrapWithZodValidators("z.boolean()", field));
|
|
10665
|
+
} else if (inputType.type === "DateTime") {
|
|
10666
|
+
result.push(this.wrapWithZodValidators("z.coerce.date()", field));
|
|
10667
|
+
} else if (inputType.type === "Json") {
|
|
10668
|
+
this.hasJson = true;
|
|
10669
|
+
result.push(this.wrapWithZodValidators("jsonSchema", field));
|
|
10670
|
+
} else if (inputType.type === "True") {
|
|
10671
|
+
result.push(this.wrapWithZodValidators("z.literal(true)", field));
|
|
10672
|
+
} else if (inputType.type === "Bytes") {
|
|
10673
|
+
result.push(this.wrapWithZodValidators("z.instanceof(Buffer)", field));
|
|
10674
|
+
} else {
|
|
10675
|
+
const isEnum = inputType.location === "enumTypes";
|
|
10676
|
+
if (inputType.namespace === "prisma" || isEnum) {
|
|
10677
|
+
if (inputType.type !== this.name && typeof inputType.type === "string") {
|
|
10678
|
+
this.addSchemaImport(inputType.type);
|
|
10679
|
+
}
|
|
10680
|
+
result.push(this.generatePrismaStringLine(field, lines.length));
|
|
10681
|
+
}
|
|
10682
|
+
}
|
|
10683
|
+
return result;
|
|
10684
|
+
}, []);
|
|
10685
|
+
if (alternatives.length === 0) {
|
|
10686
|
+
return [];
|
|
10687
|
+
}
|
|
10688
|
+
if (alternatives.length > 1) {
|
|
10689
|
+
alternatives = alternatives.map((alter) => alter.replace(".optional()", ""));
|
|
10690
|
+
}
|
|
10691
|
+
const fieldName = alternatives.some((alt) => alt.includes(":")) ? "" : ` ${field.name}:`;
|
|
10692
|
+
const opt = !field.isRequired ? ".optional()" : "";
|
|
10693
|
+
let resString = alternatives.length === 1 ? alternatives.join(",\r\n") : `z.union([${alternatives.join(",\r\n")}])${opt}`;
|
|
10694
|
+
if (field.isNullable) {
|
|
10695
|
+
resString += ".nullable()";
|
|
10696
|
+
}
|
|
10697
|
+
return [
|
|
10698
|
+
[
|
|
10699
|
+
` ${fieldName} ${resString} `,
|
|
10700
|
+
field,
|
|
10701
|
+
true
|
|
10702
|
+
]
|
|
10703
|
+
];
|
|
10704
|
+
}
|
|
10705
|
+
wrapWithZodValidators(mainValidator, field) {
|
|
10706
|
+
let line = "";
|
|
10707
|
+
line = mainValidator;
|
|
10708
|
+
if (field.inputTypes.some((inputType) => inputType.isList)) {
|
|
10709
|
+
line += ".array()";
|
|
10710
|
+
}
|
|
10711
|
+
if (!field.isRequired) {
|
|
10712
|
+
line += ".optional()";
|
|
10713
|
+
}
|
|
10714
|
+
return line;
|
|
10715
|
+
}
|
|
10716
|
+
addSchemaImport(name) {
|
|
10717
|
+
this.schemaImports.add(name);
|
|
10718
|
+
}
|
|
10719
|
+
generatePrismaStringLine(field, inputsLength) {
|
|
10720
|
+
return field.inputTypes.map((inputType) => {
|
|
10721
|
+
const isEnum = inputType.location === "enumTypes";
|
|
10722
|
+
const inputTypeString = inputType.type;
|
|
10723
|
+
const { isModelQueryType, modelName, queryName } = this.checkIsModelQueryType(inputTypeString);
|
|
10724
|
+
const objectSchemaLine = isModelQueryType ? this.resolveModelQuerySchemaName(modelName, queryName) : `${inputTypeString}ObjectSchema`;
|
|
10725
|
+
const enumSchemaLine = `${inputTypeString}Schema`;
|
|
10726
|
+
const schema = inputType.type === this.name ? objectSchemaLine : isEnum ? enumSchemaLine : objectSchemaLine;
|
|
10727
|
+
const arr = inputType.isList ? ".array()" : "";
|
|
10728
|
+
const opt = !field.isRequired ? ".optional()" : "";
|
|
10729
|
+
return inputsLength === 1 ? ` ${field.name}: z.lazy(() => ${schema})${arr}${opt}` : `z.lazy(() => ${schema})${arr}${opt}`;
|
|
10730
|
+
}).join(",\r\n");
|
|
10731
|
+
}
|
|
10732
|
+
generateFieldValidators(zodStringWithMainType, field) {
|
|
10733
|
+
const { isRequired, isNullable } = field;
|
|
10734
|
+
if (!isRequired) {
|
|
10735
|
+
zodStringWithMainType += ".optional()";
|
|
10736
|
+
}
|
|
10737
|
+
if (isNullable) {
|
|
10738
|
+
zodStringWithMainType += ".nullable()";
|
|
10739
|
+
}
|
|
10740
|
+
return zodStringWithMainType;
|
|
10741
|
+
}
|
|
10742
|
+
prepareObjectSchema(zodObjectSchemaFields) {
|
|
10743
|
+
const objectSchema = `${this.generateExportObjectSchemaStatement(this.addFinalWrappers({
|
|
10744
|
+
zodStringFields: zodObjectSchemaFields
|
|
10745
|
+
}))}
|
|
10746
|
+
`;
|
|
10747
|
+
const prismaImportStatement = this.generateImportPrismaStatement();
|
|
10748
|
+
const json = this.generateJsonSchemaImplementation();
|
|
10749
|
+
return `${this.generateObjectSchemaImportStatements()}${prismaImportStatement}${json}${objectSchema}`;
|
|
10750
|
+
}
|
|
10751
|
+
generateExportObjectSchemaStatement(schema) {
|
|
10752
|
+
let name = this.name;
|
|
10753
|
+
let exportName = this.name;
|
|
10754
|
+
if (_Transformer.provider === "mongodb") {
|
|
10755
|
+
if (isMongodbRawOp(name)) {
|
|
10756
|
+
name = _Transformer.rawOpsMap[name];
|
|
10757
|
+
exportName = name.replace("Args", "");
|
|
10758
|
+
}
|
|
10759
|
+
}
|
|
10760
|
+
if (isAggregateInputType(name)) {
|
|
10761
|
+
name = `${name}Type`;
|
|
10762
|
+
}
|
|
10763
|
+
const end = `export const ${exportName}ObjectSchema = Schema`;
|
|
10764
|
+
return `const Schema: z.ZodType<Prisma.${name}> = ${schema};
|
|
10765
|
+
|
|
10766
|
+
${end}`;
|
|
10767
|
+
}
|
|
10768
|
+
addFinalWrappers({ zodStringFields }) {
|
|
10769
|
+
const fields = [
|
|
10770
|
+
...zodStringFields
|
|
10771
|
+
];
|
|
10772
|
+
return `${this.wrapWithZodObject(fields)}.strict()`;
|
|
10773
|
+
}
|
|
10774
|
+
generateImportPrismaStatement() {
|
|
10775
|
+
let prismaClientImportPath;
|
|
10776
|
+
if (_Transformer.isCustomPrismaClientOutputPath) {
|
|
10777
|
+
const fromPath = import_node_path6.default.join(_Transformer.outputPath, "schemas", "objects");
|
|
10778
|
+
const toPath = _Transformer.prismaClientOutputPath;
|
|
10779
|
+
const relativePathFromOutputToPrismaClient = import_node_path6.default.relative(fromPath, toPath).split(import_node_path6.default.sep).join(import_node_path6.default.posix.sep);
|
|
10780
|
+
prismaClientImportPath = relativePathFromOutputToPrismaClient;
|
|
10781
|
+
} else {
|
|
10782
|
+
prismaClientImportPath = _Transformer.prismaClientOutputPath;
|
|
10783
|
+
}
|
|
10784
|
+
return `import type { Prisma } from '${prismaClientImportPath}';
|
|
10785
|
+
|
|
10786
|
+
`;
|
|
10787
|
+
}
|
|
10788
|
+
generateJsonSchemaImplementation() {
|
|
10789
|
+
let jsonSchemaImplementation = "";
|
|
10790
|
+
if (this.hasJson) {
|
|
10791
|
+
jsonSchemaImplementation += `
|
|
10792
|
+
`;
|
|
10793
|
+
jsonSchemaImplementation += `const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
10794
|
+
`;
|
|
10795
|
+
jsonSchemaImplementation += `const jsonSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
|
|
10796
|
+
`;
|
|
10797
|
+
jsonSchemaImplementation += ` z.union([literalSchema, z.array(jsonSchema.nullable()), z.record(jsonSchema.nullable())])
|
|
10798
|
+
`;
|
|
10799
|
+
jsonSchemaImplementation += `);
|
|
10800
|
+
|
|
10801
|
+
`;
|
|
10802
|
+
}
|
|
10803
|
+
return jsonSchemaImplementation;
|
|
10804
|
+
}
|
|
10805
|
+
generateObjectSchemaImportStatements() {
|
|
10806
|
+
let generatedImports = this.generateImportZodStatement();
|
|
10807
|
+
generatedImports += this.generateSchemaImports();
|
|
10808
|
+
generatedImports += "\n\n";
|
|
10809
|
+
return generatedImports;
|
|
10810
|
+
}
|
|
10811
|
+
generateSchemaImports() {
|
|
10812
|
+
return [
|
|
10813
|
+
...this.schemaImports
|
|
10814
|
+
].map((name) => {
|
|
10815
|
+
const { isModelQueryType, modelName, queryName } = this.checkIsModelQueryType(name);
|
|
10816
|
+
if (isModelQueryType) {
|
|
10817
|
+
return `import { ${this.resolveModelQuerySchemaName(modelName, queryName)} } from '../${queryName}${modelName}.schema'`;
|
|
10818
|
+
} else if (_Transformer.enumNames.includes(name)) {
|
|
10819
|
+
return `import { ${name}Schema } from '../enums/${name}.schema'`;
|
|
10820
|
+
} else {
|
|
10821
|
+
return `import { ${name}ObjectSchema } from './${name}.schema'`;
|
|
10822
|
+
}
|
|
10823
|
+
}).join(";\r\n");
|
|
10824
|
+
}
|
|
10825
|
+
checkIsModelQueryType(type) {
|
|
10826
|
+
const modelQueryTypeSuffixToQueryName = {
|
|
10827
|
+
FindManyArgs: "findMany"
|
|
10828
|
+
};
|
|
10829
|
+
for (const modelQueryType of [
|
|
10830
|
+
"FindManyArgs"
|
|
10831
|
+
]) {
|
|
10832
|
+
if (type.includes(modelQueryType)) {
|
|
10833
|
+
const modelQueryTypeSuffixIndex = type.indexOf(modelQueryType);
|
|
10834
|
+
return {
|
|
10835
|
+
isModelQueryType: true,
|
|
10836
|
+
modelName: type.substring(0, modelQueryTypeSuffixIndex),
|
|
10837
|
+
queryName: modelQueryTypeSuffixToQueryName[modelQueryType]
|
|
10838
|
+
};
|
|
10839
|
+
}
|
|
10840
|
+
}
|
|
10841
|
+
return {
|
|
10842
|
+
isModelQueryType: false
|
|
10843
|
+
};
|
|
10844
|
+
}
|
|
10845
|
+
resolveModelQuerySchemaName(modelName, queryName) {
|
|
10846
|
+
const modelNameCapitalized = modelName.charAt(0).toUpperCase() + modelName.slice(1);
|
|
10847
|
+
const queryNameCapitalized = queryName.charAt(0).toUpperCase() + queryName.slice(1);
|
|
10848
|
+
return `${modelNameCapitalized}${queryNameCapitalized}Schema`;
|
|
10849
|
+
}
|
|
10850
|
+
wrapWithZodUnion(zodStringFields) {
|
|
10851
|
+
let wrapped = "";
|
|
10852
|
+
wrapped += "z.union([";
|
|
10853
|
+
wrapped += "\n";
|
|
10854
|
+
wrapped += ` ${zodStringFields.join(",")}`;
|
|
10855
|
+
wrapped += "\n";
|
|
10856
|
+
wrapped += "])";
|
|
10857
|
+
return wrapped;
|
|
10858
|
+
}
|
|
10859
|
+
wrapWithZodObject(zodStringFields) {
|
|
10860
|
+
let wrapped = "";
|
|
10861
|
+
wrapped += "z.object({";
|
|
10862
|
+
wrapped += "\n";
|
|
10863
|
+
wrapped += ` ${typeof zodStringFields === "string" ? zodStringFields : zodStringFields.join(",\n ")}`;
|
|
10864
|
+
wrapped += "\n";
|
|
10865
|
+
wrapped += "})";
|
|
10866
|
+
return wrapped;
|
|
10867
|
+
}
|
|
10868
|
+
resolveObjectSchemaName() {
|
|
10869
|
+
let name = this.name;
|
|
10870
|
+
let exportName = this.name;
|
|
10871
|
+
if (isMongodbRawOp(name)) {
|
|
10872
|
+
name = _Transformer.rawOpsMap[name];
|
|
10873
|
+
exportName = name.replace("Args", "");
|
|
10874
|
+
}
|
|
10875
|
+
return exportName;
|
|
10876
|
+
}
|
|
10877
|
+
async generateModelSchemas() {
|
|
10878
|
+
for (const modelOperation of this.modelOperations) {
|
|
10879
|
+
const {
|
|
10880
|
+
model: modelName,
|
|
10881
|
+
findUnique,
|
|
10882
|
+
findFirst,
|
|
10883
|
+
findMany,
|
|
10884
|
+
// @ts-ignore
|
|
10885
|
+
createOne,
|
|
10886
|
+
createMany,
|
|
10887
|
+
// @ts-ignore
|
|
10888
|
+
deleteOne,
|
|
10889
|
+
// @ts-ignore
|
|
10890
|
+
updateOne,
|
|
10891
|
+
deleteMany,
|
|
10892
|
+
updateMany,
|
|
10893
|
+
// @ts-ignore
|
|
10894
|
+
upsertOne,
|
|
10895
|
+
aggregate,
|
|
10896
|
+
groupBy
|
|
10897
|
+
} = modelOperation;
|
|
10898
|
+
const model = findModelByName(this.models, modelName);
|
|
10899
|
+
const { selectImport, includeImport, selectZodSchemaLine, includeZodSchemaLine, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
10900
|
+
const { orderByImport, orderByZodSchemaLine } = this.resolveOrderByWithRelationImportAndZodSchemaLine(model);
|
|
10901
|
+
if (findUnique) {
|
|
10902
|
+
const imports = [
|
|
10903
|
+
selectImport,
|
|
10904
|
+
includeImport,
|
|
10905
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10906
|
+
];
|
|
10907
|
+
await writeFileSafely(import_node_path6.default.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
10908
|
+
}
|
|
10909
|
+
if (findFirst) {
|
|
10910
|
+
const imports = [
|
|
10911
|
+
selectImport,
|
|
10912
|
+
includeImport,
|
|
10913
|
+
orderByImport,
|
|
10914
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
10915
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10916
|
+
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10917
|
+
];
|
|
10918
|
+
await writeFileSafely(import_node_path6.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() })`)}`);
|
|
10919
|
+
}
|
|
10920
|
+
if (findMany) {
|
|
10921
|
+
const imports = [
|
|
10922
|
+
selectImport,
|
|
10923
|
+
includeImport,
|
|
10924
|
+
orderByImport,
|
|
10925
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
10926
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10927
|
+
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10928
|
+
];
|
|
10929
|
+
await writeFileSafely(import_node_path6.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() })`)}`);
|
|
10930
|
+
}
|
|
10931
|
+
if (createOne) {
|
|
10932
|
+
const imports = [
|
|
10933
|
+
selectImport,
|
|
10934
|
+
includeImport,
|
|
10935
|
+
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
10936
|
+
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
|
|
10937
|
+
];
|
|
10938
|
+
await writeFileSafely(import_node_path6.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]) })`)}`);
|
|
10939
|
+
}
|
|
10940
|
+
if (createMany) {
|
|
10941
|
+
const imports = [
|
|
10942
|
+
`import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`
|
|
10943
|
+
];
|
|
10944
|
+
await writeFileSafely(import_node_path6.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()"} })`)}`);
|
|
10945
|
+
}
|
|
10946
|
+
if (deleteOne) {
|
|
10947
|
+
const imports = [
|
|
10948
|
+
selectImport,
|
|
10949
|
+
includeImport,
|
|
10950
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10951
|
+
];
|
|
10952
|
+
await writeFileSafely(import_node_path6.default.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
10953
|
+
}
|
|
10954
|
+
if (deleteMany) {
|
|
10955
|
+
const imports = [
|
|
10956
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
10957
|
+
];
|
|
10958
|
+
await writeFileSafely(import_node_path6.default.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
10959
|
+
}
|
|
10960
|
+
if (updateOne) {
|
|
10961
|
+
const imports = [
|
|
10962
|
+
selectImport,
|
|
10963
|
+
includeImport,
|
|
10964
|
+
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
10965
|
+
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
|
|
10966
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10967
|
+
];
|
|
10968
|
+
await writeFileSafely(import_node_path6.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 })`)}`);
|
|
10969
|
+
}
|
|
10970
|
+
if (updateMany) {
|
|
10971
|
+
const imports = [
|
|
10972
|
+
`import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`,
|
|
10973
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
10974
|
+
];
|
|
10975
|
+
await writeFileSafely(import_node_path6.default.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
10976
|
+
}
|
|
10977
|
+
if (upsertOne) {
|
|
10978
|
+
const imports = [
|
|
10979
|
+
selectImport,
|
|
10980
|
+
includeImport,
|
|
10981
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10982
|
+
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
10983
|
+
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`,
|
|
10984
|
+
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
10985
|
+
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
|
|
10986
|
+
];
|
|
10987
|
+
await writeFileSafely(import_node_path6.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 ]) })`)}`);
|
|
10988
|
+
}
|
|
10989
|
+
if (aggregate) {
|
|
10990
|
+
const imports = [
|
|
10991
|
+
orderByImport,
|
|
10992
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
10993
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10994
|
+
];
|
|
10995
|
+
const aggregateOperations = [];
|
|
10996
|
+
if (this.aggregateOperationSupport[modelName]) {
|
|
10997
|
+
if (this.aggregateOperationSupport[modelName].count) {
|
|
10998
|
+
imports.push(`import { ${modelName}CountAggregateInputObjectSchema } from './objects/${modelName}CountAggregateInput.schema'`);
|
|
10999
|
+
aggregateOperations.push(`_count: z.union([ z.literal(true), ${modelName}CountAggregateInputObjectSchema ]).optional()`);
|
|
11000
|
+
}
|
|
11001
|
+
if (this.aggregateOperationSupport[modelName].min) {
|
|
11002
|
+
imports.push(`import { ${modelName}MinAggregateInputObjectSchema } from './objects/${modelName}MinAggregateInput.schema'`);
|
|
11003
|
+
aggregateOperations.push(`_min: ${modelName}MinAggregateInputObjectSchema.optional()`);
|
|
11004
|
+
}
|
|
11005
|
+
if (this.aggregateOperationSupport[modelName].max) {
|
|
11006
|
+
imports.push(`import { ${modelName}MaxAggregateInputObjectSchema } from './objects/${modelName}MaxAggregateInput.schema'`);
|
|
11007
|
+
aggregateOperations.push(`_max: ${modelName}MaxAggregateInputObjectSchema.optional()`);
|
|
11008
|
+
}
|
|
11009
|
+
if (this.aggregateOperationSupport[modelName].avg) {
|
|
11010
|
+
imports.push(`import { ${modelName}AvgAggregateInputObjectSchema } from './objects/${modelName}AvgAggregateInput.schema'`);
|
|
11011
|
+
aggregateOperations.push(`_avg: ${modelName}AvgAggregateInputObjectSchema.optional()`);
|
|
11012
|
+
}
|
|
11013
|
+
if (this.aggregateOperationSupport[modelName].sum) {
|
|
11014
|
+
imports.push(`import { ${modelName}SumAggregateInputObjectSchema } from './objects/${modelName}SumAggregateInput.schema'`);
|
|
11015
|
+
aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
|
|
11016
|
+
}
|
|
11017
|
+
}
|
|
11018
|
+
await writeFileSafely(import_node_path6.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(", ")} })`)}`);
|
|
11019
|
+
}
|
|
11020
|
+
if (groupBy) {
|
|
11021
|
+
const imports = [
|
|
11022
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
11023
|
+
`import { ${modelName}OrderByWithAggregationInputObjectSchema } from './objects/${modelName}OrderByWithAggregationInput.schema'`,
|
|
11024
|
+
`import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
|
|
11025
|
+
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
11026
|
+
];
|
|
11027
|
+
await writeFileSafely(import_node_path6.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) })`)}`);
|
|
11028
|
+
}
|
|
11029
|
+
}
|
|
11030
|
+
}
|
|
11031
|
+
generateImportStatements(imports) {
|
|
11032
|
+
let generatedImports = this.generateImportZodStatement();
|
|
11033
|
+
generatedImports += imports?.filter((importItem) => !!importItem).join(";\r\n") ?? "";
|
|
11034
|
+
generatedImports += "\n\n";
|
|
11035
|
+
return generatedImports;
|
|
11036
|
+
}
|
|
11037
|
+
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
11038
|
+
const { name: modelName } = model;
|
|
11039
|
+
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11040
|
+
const selectImport = _Transformer.isGenerateSelect ? `import { ${modelName}SelectObjectSchema } from './objects/${modelName}Select.schema'` : "";
|
|
11041
|
+
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${modelName}IncludeObjectSchema } from './objects/${modelName}Include.schema'` : "";
|
|
11042
|
+
let selectZodSchemaLine = "";
|
|
11043
|
+
let includeZodSchemaLine = "";
|
|
11044
|
+
let selectZodSchemaLineLazy = "";
|
|
11045
|
+
let includeZodSchemaLineLazy = "";
|
|
11046
|
+
if (_Transformer.isGenerateSelect) {
|
|
11047
|
+
const zodSelectObjectSchema = `${modelName}SelectObjectSchema.optional()`;
|
|
11048
|
+
selectZodSchemaLine = `select: ${zodSelectObjectSchema},`;
|
|
11049
|
+
selectZodSchemaLineLazy = `select: z.lazy(() => ${zodSelectObjectSchema}),`;
|
|
11050
|
+
}
|
|
11051
|
+
if (_Transformer.isGenerateInclude && hasRelationToAnotherModel) {
|
|
11052
|
+
const zodIncludeObjectSchema = `${modelName}IncludeObjectSchema.optional()`;
|
|
11053
|
+
includeZodSchemaLine = `include: ${zodIncludeObjectSchema},`;
|
|
11054
|
+
includeZodSchemaLineLazy = `include: z.lazy(() => ${zodIncludeObjectSchema}),`;
|
|
11055
|
+
}
|
|
11056
|
+
return {
|
|
11057
|
+
selectImport,
|
|
11058
|
+
includeImport,
|
|
11059
|
+
selectZodSchemaLine,
|
|
11060
|
+
includeZodSchemaLine,
|
|
11061
|
+
selectZodSchemaLineLazy,
|
|
11062
|
+
includeZodSchemaLineLazy
|
|
11063
|
+
};
|
|
11064
|
+
}
|
|
11065
|
+
resolveOrderByWithRelationImportAndZodSchemaLine(model) {
|
|
11066
|
+
const { name: modelName } = model;
|
|
11067
|
+
let modelOrderBy = "";
|
|
11068
|
+
if ([
|
|
11069
|
+
"postgresql",
|
|
11070
|
+
"mysql"
|
|
11071
|
+
].includes(_Transformer.provider) && _Transformer.previewFeatures?.includes("fullTextSearch")) {
|
|
11072
|
+
modelOrderBy = `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11073
|
+
} else {
|
|
11074
|
+
modelOrderBy = `${modelName}OrderByWithRelationInput`;
|
|
11075
|
+
}
|
|
11076
|
+
const orderByImport = `import { ${modelOrderBy}ObjectSchema } from './objects/${modelOrderBy}.schema'`;
|
|
11077
|
+
const orderByZodSchemaLine = `orderBy: z.union([${modelOrderBy}ObjectSchema, ${modelOrderBy}ObjectSchema.array()]).optional(),`;
|
|
11078
|
+
return {
|
|
11079
|
+
orderByImport,
|
|
11080
|
+
orderByZodSchemaLine
|
|
11081
|
+
};
|
|
11082
|
+
}
|
|
11083
|
+
};
|
|
11084
|
+
|
|
11085
|
+
// src/zod-helpers/generator-helpers.ts
|
|
11086
|
+
async function generateZodEnumSchemas(prismaSchemaEnum, modelSchemaEnum) {
|
|
11087
|
+
const enumTypes = [
|
|
11088
|
+
...prismaSchemaEnum,
|
|
11089
|
+
...modelSchemaEnum
|
|
11090
|
+
];
|
|
11091
|
+
const enumNames = enumTypes.map((enumItem) => enumItem.name);
|
|
11092
|
+
Transformer.enumNames = enumNames ?? [];
|
|
11093
|
+
const transformer = new Transformer({
|
|
11094
|
+
enumTypes
|
|
11095
|
+
});
|
|
11096
|
+
await transformer.generateEnumSchemas();
|
|
11097
|
+
}
|
|
11098
|
+
__name(generateZodEnumSchemas, "generateZodEnumSchemas");
|
|
11099
|
+
async function generateZodObjectSchemas(inputObjectTypes) {
|
|
11100
|
+
for (let i = 0; i < inputObjectTypes.length; i += 1) {
|
|
11101
|
+
const fields = inputObjectTypes[i]?.fields;
|
|
11102
|
+
const name = inputObjectTypes[i]?.name;
|
|
11103
|
+
const transformer = new Transformer({
|
|
11104
|
+
name,
|
|
11105
|
+
fields
|
|
11106
|
+
});
|
|
11107
|
+
await transformer.generateObjectSchema();
|
|
11108
|
+
}
|
|
11109
|
+
}
|
|
11110
|
+
__name(generateZodObjectSchemas, "generateZodObjectSchemas");
|
|
11111
|
+
async function generateZodModelSchemas(models, modelOperations, aggregateOperationSupport) {
|
|
11112
|
+
const transformer = new Transformer({
|
|
11113
|
+
models,
|
|
11114
|
+
modelOperations,
|
|
11115
|
+
aggregateOperationSupport
|
|
11116
|
+
});
|
|
11117
|
+
await transformer.generateModelSchemas();
|
|
11118
|
+
}
|
|
11119
|
+
__name(generateZodModelSchemas, "generateZodModelSchemas");
|
|
11120
|
+
async function generateZodIndex() {
|
|
11121
|
+
await Transformer.generateIndex();
|
|
11122
|
+
}
|
|
11123
|
+
__name(generateZodIndex, "generateZodIndex");
|
|
11124
|
+
|
|
11125
|
+
// src/zod-helpers/helpers.ts
|
|
11126
|
+
init_cjs_shims();
|
|
11127
|
+
|
|
11128
|
+
// src/zod-helpers/include-helpers.ts
|
|
11129
|
+
init_cjs_shims();
|
|
11130
|
+
function addMissingInputObjectTypesForInclude(inputObjectTypes, models, isGenerateSelect) {
|
|
11131
|
+
const generatedIncludeInputObjectTypes = generateModelIncludeInputObjectTypes(models, isGenerateSelect);
|
|
11132
|
+
for (const includeInputObjectType of generatedIncludeInputObjectTypes) {
|
|
11133
|
+
inputObjectTypes.push(includeInputObjectType);
|
|
11134
|
+
}
|
|
11135
|
+
}
|
|
11136
|
+
__name(addMissingInputObjectTypesForInclude, "addMissingInputObjectTypesForInclude");
|
|
11137
|
+
function generateModelIncludeInputObjectTypes(models, isGenerateSelect) {
|
|
11138
|
+
const modelIncludeInputObjectTypes = [];
|
|
11139
|
+
for (const model of models) {
|
|
11140
|
+
const { name: modelName, fields: modelFields } = model;
|
|
11141
|
+
const fields = [];
|
|
11142
|
+
for (const modelField of modelFields) {
|
|
11143
|
+
const { name: modelFieldName, isList, type } = modelField;
|
|
11144
|
+
const isRelationField = checkIsModelRelationField(modelField);
|
|
11145
|
+
if (isRelationField) {
|
|
11146
|
+
const field = {
|
|
11147
|
+
name: modelFieldName,
|
|
11148
|
+
isRequired: false,
|
|
11149
|
+
isNullable: false,
|
|
11150
|
+
inputTypes: [
|
|
11151
|
+
{
|
|
11152
|
+
isList: false,
|
|
11153
|
+
type: "Boolean",
|
|
11154
|
+
location: "scalar"
|
|
11155
|
+
},
|
|
11156
|
+
{
|
|
11157
|
+
isList: false,
|
|
11158
|
+
type: isList ? `${type}FindManyArgs` : `${type}Args`,
|
|
11159
|
+
location: "inputObjectTypes",
|
|
11160
|
+
namespace: "prisma"
|
|
11161
|
+
}
|
|
11162
|
+
]
|
|
11163
|
+
};
|
|
11164
|
+
fields.push(field);
|
|
11165
|
+
}
|
|
11166
|
+
}
|
|
11167
|
+
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11168
|
+
if (!hasRelationToAnotherModel) {
|
|
11169
|
+
continue;
|
|
11170
|
+
}
|
|
11171
|
+
const hasManyRelationToAnotherModel = checkModelHasManyModelRelation(model);
|
|
11172
|
+
const shouldAddCountField = hasManyRelationToAnotherModel;
|
|
11173
|
+
if (shouldAddCountField) {
|
|
11174
|
+
const inputTypes = [
|
|
11175
|
+
{
|
|
11176
|
+
isList: false,
|
|
11177
|
+
type: "Boolean",
|
|
11178
|
+
location: "scalar"
|
|
11179
|
+
}
|
|
11180
|
+
];
|
|
11181
|
+
if (isGenerateSelect) {
|
|
11182
|
+
inputTypes.push({
|
|
11183
|
+
isList: false,
|
|
11184
|
+
type: `${modelName}CountOutputTypeArgs`,
|
|
11185
|
+
location: "inputObjectTypes",
|
|
11186
|
+
namespace: "prisma"
|
|
11187
|
+
});
|
|
11188
|
+
}
|
|
11189
|
+
const _countField = {
|
|
11190
|
+
name: "_count",
|
|
11191
|
+
isRequired: false,
|
|
11192
|
+
isNullable: false,
|
|
11193
|
+
inputTypes
|
|
11194
|
+
};
|
|
11195
|
+
fields.push(_countField);
|
|
11196
|
+
}
|
|
11197
|
+
const modelIncludeInputObjectType = {
|
|
11198
|
+
name: `${modelName}Include`,
|
|
11199
|
+
constraints: {
|
|
11200
|
+
maxNumFields: null,
|
|
11201
|
+
minNumFields: null
|
|
11202
|
+
},
|
|
11203
|
+
fields
|
|
11204
|
+
};
|
|
11205
|
+
modelIncludeInputObjectTypes.push(modelIncludeInputObjectType);
|
|
11206
|
+
}
|
|
11207
|
+
return modelIncludeInputObjectTypes;
|
|
11208
|
+
}
|
|
11209
|
+
__name(generateModelIncludeInputObjectTypes, "generateModelIncludeInputObjectTypes");
|
|
11210
|
+
|
|
11211
|
+
// src/zod-helpers/modelArgs-helpers.ts
|
|
11212
|
+
init_cjs_shims();
|
|
11213
|
+
function addMissingInputObjectTypesForModelArgs(inputObjectTypes, models, isGenerateSelect, isGenerateInclude) {
|
|
11214
|
+
const modelArgsInputObjectTypes = generateModelArgsInputObjectTypes(models, isGenerateSelect, isGenerateInclude);
|
|
11215
|
+
for (const modelArgsInputObjectType of modelArgsInputObjectTypes) {
|
|
11216
|
+
inputObjectTypes.push(modelArgsInputObjectType);
|
|
11217
|
+
}
|
|
11218
|
+
}
|
|
11219
|
+
__name(addMissingInputObjectTypesForModelArgs, "addMissingInputObjectTypesForModelArgs");
|
|
11220
|
+
function generateModelArgsInputObjectTypes(models, isGenerateSelect, isGenerateInclude) {
|
|
11221
|
+
const modelArgsInputObjectTypes = [];
|
|
11222
|
+
for (const model of models) {
|
|
11223
|
+
const { name: modelName } = model;
|
|
11224
|
+
const fields = [];
|
|
11225
|
+
if (isGenerateSelect) {
|
|
11226
|
+
const selectField = {
|
|
11227
|
+
name: "select",
|
|
11228
|
+
isRequired: false,
|
|
11229
|
+
isNullable: false,
|
|
11230
|
+
inputTypes: [
|
|
11231
|
+
{
|
|
11232
|
+
isList: false,
|
|
11233
|
+
type: `${modelName}Select`,
|
|
11234
|
+
location: "inputObjectTypes",
|
|
11235
|
+
namespace: "prisma"
|
|
11236
|
+
}
|
|
11237
|
+
]
|
|
11238
|
+
};
|
|
11239
|
+
fields.push(selectField);
|
|
11240
|
+
}
|
|
11241
|
+
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11242
|
+
if (isGenerateInclude && hasRelationToAnotherModel) {
|
|
11243
|
+
const includeField = {
|
|
11244
|
+
name: "include",
|
|
11245
|
+
isRequired: false,
|
|
11246
|
+
isNullable: false,
|
|
11247
|
+
inputTypes: [
|
|
11248
|
+
{
|
|
11249
|
+
isList: false,
|
|
11250
|
+
type: `${modelName}Include`,
|
|
11251
|
+
location: "inputObjectTypes",
|
|
11252
|
+
namespace: "prisma"
|
|
11253
|
+
}
|
|
11254
|
+
]
|
|
11255
|
+
};
|
|
11256
|
+
fields.push(includeField);
|
|
11257
|
+
}
|
|
11258
|
+
const modelArgsInputObjectType = {
|
|
11259
|
+
name: `${modelName}Args`,
|
|
11260
|
+
constraints: {
|
|
11261
|
+
maxNumFields: null,
|
|
11262
|
+
minNumFields: null
|
|
11263
|
+
},
|
|
11264
|
+
fields
|
|
11265
|
+
};
|
|
11266
|
+
modelArgsInputObjectTypes.push(modelArgsInputObjectType);
|
|
11267
|
+
}
|
|
11268
|
+
return modelArgsInputObjectTypes;
|
|
11269
|
+
}
|
|
11270
|
+
__name(generateModelArgsInputObjectTypes, "generateModelArgsInputObjectTypes");
|
|
11271
|
+
|
|
11272
|
+
// src/zod-helpers/select-helpers.ts
|
|
11273
|
+
init_cjs_shims();
|
|
11274
|
+
function addMissingInputObjectTypesForSelect(inputObjectTypes, outputObjectTypes, models) {
|
|
11275
|
+
const modelCountOutputTypes = getModelCountOutputTypes(outputObjectTypes);
|
|
11276
|
+
const modelCountOutputTypeSelectInputObjectTypes = generateModelCountOutputTypeSelectInputObjectTypes(modelCountOutputTypes);
|
|
11277
|
+
const modelCountOutputTypeArgsInputObjectTypes = generateModelCountOutputTypeArgsInputObjectTypes(modelCountOutputTypes);
|
|
11278
|
+
const modelSelectInputObjectTypes = generateModelSelectInputObjectTypes(models);
|
|
11279
|
+
const generatedInputObjectTypes = [
|
|
11280
|
+
modelCountOutputTypeSelectInputObjectTypes,
|
|
11281
|
+
modelCountOutputTypeArgsInputObjectTypes,
|
|
11282
|
+
modelSelectInputObjectTypes
|
|
11283
|
+
].flat();
|
|
11284
|
+
for (const inputObjectType of generatedInputObjectTypes) {
|
|
11285
|
+
inputObjectTypes.push(inputObjectType);
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
__name(addMissingInputObjectTypesForSelect, "addMissingInputObjectTypesForSelect");
|
|
11289
|
+
function getModelCountOutputTypes(outputObjectTypes) {
|
|
11290
|
+
return outputObjectTypes.filter(({ name }) => name.includes("CountOutputType"));
|
|
11291
|
+
}
|
|
11292
|
+
__name(getModelCountOutputTypes, "getModelCountOutputTypes");
|
|
11293
|
+
function generateModelCountOutputTypeSelectInputObjectTypes(modelCountOutputTypes) {
|
|
11294
|
+
const modelCountOutputTypeSelectInputObjectTypes = [];
|
|
11295
|
+
for (const modelCountOutputType of modelCountOutputTypes) {
|
|
11296
|
+
const { name: modelCountOutputTypeName, fields: modelCountOutputTypeFields } = modelCountOutputType;
|
|
11297
|
+
const modelCountOutputTypeSelectInputObjectType = {
|
|
11298
|
+
name: `${modelCountOutputTypeName}Select`,
|
|
11299
|
+
constraints: {
|
|
11300
|
+
maxNumFields: null,
|
|
11301
|
+
minNumFields: null
|
|
11302
|
+
},
|
|
11303
|
+
fields: modelCountOutputTypeFields.map(({ name }) => ({
|
|
11304
|
+
name,
|
|
11305
|
+
isRequired: false,
|
|
11306
|
+
isNullable: false,
|
|
11307
|
+
inputTypes: [
|
|
11308
|
+
{
|
|
11309
|
+
isList: false,
|
|
11310
|
+
type: `Boolean`,
|
|
11311
|
+
location: "scalar"
|
|
11312
|
+
}
|
|
11313
|
+
]
|
|
11314
|
+
}))
|
|
11315
|
+
};
|
|
11316
|
+
modelCountOutputTypeSelectInputObjectTypes.push(modelCountOutputTypeSelectInputObjectType);
|
|
11317
|
+
}
|
|
11318
|
+
return modelCountOutputTypeSelectInputObjectTypes;
|
|
11319
|
+
}
|
|
11320
|
+
__name(generateModelCountOutputTypeSelectInputObjectTypes, "generateModelCountOutputTypeSelectInputObjectTypes");
|
|
11321
|
+
function generateModelCountOutputTypeArgsInputObjectTypes(modelCountOutputTypes) {
|
|
11322
|
+
const modelCountOutputTypeArgsInputObjectTypes = [];
|
|
11323
|
+
for (const modelCountOutputType of modelCountOutputTypes) {
|
|
11324
|
+
const { name: modelCountOutputTypeName } = modelCountOutputType;
|
|
11325
|
+
const modelCountOutputTypeArgsInputObjectType = {
|
|
11326
|
+
name: `${modelCountOutputTypeName}Args`,
|
|
11327
|
+
constraints: {
|
|
11328
|
+
maxNumFields: null,
|
|
11329
|
+
minNumFields: null
|
|
11330
|
+
},
|
|
11331
|
+
fields: [
|
|
11332
|
+
{
|
|
11333
|
+
name: "select",
|
|
11334
|
+
isRequired: false,
|
|
11335
|
+
isNullable: false,
|
|
11336
|
+
inputTypes: [
|
|
11337
|
+
{
|
|
11338
|
+
isList: false,
|
|
11339
|
+
type: `${modelCountOutputTypeName}Select`,
|
|
11340
|
+
location: "inputObjectTypes",
|
|
11341
|
+
namespace: "prisma"
|
|
11342
|
+
}
|
|
11343
|
+
]
|
|
11344
|
+
}
|
|
11345
|
+
]
|
|
11346
|
+
};
|
|
11347
|
+
modelCountOutputTypeArgsInputObjectTypes.push(modelCountOutputTypeArgsInputObjectType);
|
|
11348
|
+
}
|
|
11349
|
+
return modelCountOutputTypeArgsInputObjectTypes;
|
|
11350
|
+
}
|
|
11351
|
+
__name(generateModelCountOutputTypeArgsInputObjectTypes, "generateModelCountOutputTypeArgsInputObjectTypes");
|
|
11352
|
+
function generateModelSelectInputObjectTypes(models) {
|
|
11353
|
+
const modelSelectInputObjectTypes = [];
|
|
11354
|
+
for (const model of models) {
|
|
11355
|
+
const { name: modelName, fields: modelFields } = model;
|
|
11356
|
+
const fields = [];
|
|
11357
|
+
for (const modelField of modelFields) {
|
|
11358
|
+
const { name: modelFieldName, isList, type } = modelField;
|
|
11359
|
+
const isRelationField = checkIsModelRelationField(modelField);
|
|
11360
|
+
const field = {
|
|
11361
|
+
name: modelFieldName,
|
|
11362
|
+
isRequired: false,
|
|
11363
|
+
isNullable: false,
|
|
11364
|
+
inputTypes: [
|
|
11365
|
+
{
|
|
11366
|
+
isList: false,
|
|
11367
|
+
type: "Boolean",
|
|
11368
|
+
location: "scalar"
|
|
11369
|
+
}
|
|
11370
|
+
]
|
|
11371
|
+
};
|
|
11372
|
+
if (isRelationField) {
|
|
11373
|
+
const schemaArgInputType = {
|
|
11374
|
+
isList: false,
|
|
11375
|
+
type: isList ? `${type}FindManyArgs` : `${type}Args`,
|
|
11376
|
+
location: "inputObjectTypes",
|
|
11377
|
+
namespace: "prisma"
|
|
11378
|
+
};
|
|
11379
|
+
field.inputTypes.push(schemaArgInputType);
|
|
11380
|
+
}
|
|
11381
|
+
fields.push(field);
|
|
11382
|
+
}
|
|
11383
|
+
const hasManyRelationToAnotherModel = checkModelHasManyModelRelation(model);
|
|
11384
|
+
const shouldAddCountField = hasManyRelationToAnotherModel;
|
|
11385
|
+
if (shouldAddCountField) {
|
|
11386
|
+
const _countField = {
|
|
11387
|
+
name: "_count",
|
|
11388
|
+
isRequired: false,
|
|
11389
|
+
isNullable: false,
|
|
11390
|
+
inputTypes: [
|
|
11391
|
+
{
|
|
11392
|
+
isList: false,
|
|
11393
|
+
type: "Boolean",
|
|
11394
|
+
location: "scalar"
|
|
11395
|
+
},
|
|
11396
|
+
{
|
|
11397
|
+
isList: false,
|
|
11398
|
+
type: `${modelName}CountOutputTypeArgs`,
|
|
11399
|
+
location: "inputObjectTypes",
|
|
11400
|
+
namespace: "prisma"
|
|
11401
|
+
}
|
|
11402
|
+
]
|
|
11403
|
+
};
|
|
11404
|
+
fields.push(_countField);
|
|
11405
|
+
}
|
|
11406
|
+
const modelSelectInputObjectType = {
|
|
11407
|
+
name: `${modelName}Select`,
|
|
11408
|
+
constraints: {
|
|
11409
|
+
maxNumFields: null,
|
|
11410
|
+
minNumFields: null
|
|
11411
|
+
},
|
|
11412
|
+
fields
|
|
11413
|
+
};
|
|
11414
|
+
modelSelectInputObjectTypes.push(modelSelectInputObjectType);
|
|
11415
|
+
}
|
|
11416
|
+
return modelSelectInputObjectTypes;
|
|
11417
|
+
}
|
|
11418
|
+
__name(generateModelSelectInputObjectTypes, "generateModelSelectInputObjectTypes");
|
|
11419
|
+
|
|
11420
|
+
// src/zod-helpers/whereUniqueInput-helpers.ts
|
|
11421
|
+
init_cjs_shims();
|
|
11422
|
+
function changeOptionalToRequiredFields(inputObjectTypes) {
|
|
11423
|
+
inputObjectTypes.map((item) => {
|
|
11424
|
+
if (item.name.includes("WhereUniqueInput") && // eslint-disable-next-line ts/no-non-null-asserted-optional-chain
|
|
11425
|
+
item.constraints.fields?.length > 0) {
|
|
11426
|
+
item.fields = item.fields.map((subItem) => {
|
|
11427
|
+
if (item.constraints.fields?.includes(subItem.name)) {
|
|
11428
|
+
subItem.isRequired = true;
|
|
11429
|
+
return subItem;
|
|
11430
|
+
}
|
|
11431
|
+
return subItem;
|
|
11432
|
+
});
|
|
11433
|
+
}
|
|
11434
|
+
return item;
|
|
11435
|
+
});
|
|
11436
|
+
}
|
|
11437
|
+
__name(changeOptionalToRequiredFields, "changeOptionalToRequiredFields");
|
|
11438
|
+
|
|
11439
|
+
// src/zod-helpers/helpers.ts
|
|
11440
|
+
function addMissingZodInputObjectTypes(inputObjectTypes, outputObjectTypes, models, modelOperations, dataSourceProvider, options) {
|
|
11441
|
+
if (dataSourceProvider === "mongodb") {
|
|
11442
|
+
addMissingInputObjectTypesForMongoDbRawOpsAndQueries(modelOperations, outputObjectTypes, inputObjectTypes);
|
|
11443
|
+
}
|
|
11444
|
+
addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes);
|
|
11445
|
+
if (options.isGenerateSelect) {
|
|
11446
|
+
addMissingInputObjectTypesForSelect(inputObjectTypes, outputObjectTypes, models);
|
|
11447
|
+
Transformer.setIsGenerateSelect(true);
|
|
11448
|
+
}
|
|
11449
|
+
if (options.isGenerateSelect || options.isGenerateInclude) {
|
|
11450
|
+
addMissingInputObjectTypesForModelArgs(inputObjectTypes, models, options.isGenerateSelect, options.isGenerateInclude);
|
|
11451
|
+
}
|
|
11452
|
+
if (options.isGenerateInclude) {
|
|
11453
|
+
addMissingInputObjectTypesForInclude(inputObjectTypes, models, options.isGenerateSelect);
|
|
11454
|
+
Transformer.setIsGenerateInclude(true);
|
|
11455
|
+
}
|
|
11456
|
+
changeOptionalToRequiredFields(inputObjectTypes);
|
|
11457
|
+
}
|
|
11458
|
+
__name(addMissingZodInputObjectTypes, "addMissingZodInputObjectTypes");
|
|
10284
11459
|
|
|
10285
11460
|
// src/prisma-generator.ts
|
|
10286
11461
|
async function generate(options) {
|
|
@@ -10302,13 +11477,6 @@ async function generate(options) {
|
|
|
10302
11477
|
consoleLog(`Preparing output directory: ${outputDir}`);
|
|
10303
11478
|
await createDirectory(outputDir);
|
|
10304
11479
|
await removeDir(outputDir, true);
|
|
10305
|
-
if (config.withZod !== false) {
|
|
10306
|
-
consoleLog("Generating Zod schemas");
|
|
10307
|
-
const prismaZodGenerator = await getJiti().import(getJiti().esmResolve("prisma-zod-generator/lib/prisma-generator"));
|
|
10308
|
-
await prismaZodGenerator.generate(options);
|
|
10309
|
-
} else {
|
|
10310
|
-
consoleLog("Skipping Zod schemas generation");
|
|
10311
|
-
}
|
|
10312
11480
|
consoleLog("Finding Prisma Client generator");
|
|
10313
11481
|
const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
|
|
10314
11482
|
if (!prismaClientProvider) {
|
|
@@ -10320,8 +11488,41 @@ async function generate(options) {
|
|
|
10320
11488
|
previewFeatures: prismaClientProvider?.previewFeatures
|
|
10321
11489
|
});
|
|
10322
11490
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
11491
|
+
const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma;
|
|
11492
|
+
const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes.prisma;
|
|
11493
|
+
const enumTypes = prismaClientDmmf.schema.enumTypes;
|
|
10323
11494
|
const models = prismaClientDmmf.datamodel.models;
|
|
10324
11495
|
const hiddenModels = [];
|
|
11496
|
+
const hiddenFields = [];
|
|
11497
|
+
if (config.withZod !== false) {
|
|
11498
|
+
consoleLog("Generating Zod schemas");
|
|
11499
|
+
const zodOutputPath = internals.parseEnvValue(options.generator.output);
|
|
11500
|
+
await createDirectory(zodOutputPath);
|
|
11501
|
+
Transformer.setOutputPath(zodOutputPath);
|
|
11502
|
+
if (prismaClientProvider?.isCustomOutput) {
|
|
11503
|
+
Transformer.setPrismaClientOutputPath(prismaClientProvider.output?.value);
|
|
11504
|
+
}
|
|
11505
|
+
resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
|
|
11506
|
+
await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model);
|
|
11507
|
+
const dataSource = options.datasources?.[0];
|
|
11508
|
+
if (!dataSource) {
|
|
11509
|
+
throw new Error("No datasource found");
|
|
11510
|
+
}
|
|
11511
|
+
const previewFeatures = prismaClientProvider?.previewFeatures;
|
|
11512
|
+
Transformer.provider = dataSource.provider;
|
|
11513
|
+
Transformer.previewFeatures = previewFeatures;
|
|
11514
|
+
addMissingZodInputObjectTypes(inputObjectTypes, outputObjectTypes, models, modelOperations, dataSource.provider, {
|
|
11515
|
+
isGenerateSelect: true,
|
|
11516
|
+
isGenerateInclude: true
|
|
11517
|
+
});
|
|
11518
|
+
const aggregateOperationSupport = resolveZodAggregateOperationSupport(inputObjectTypes);
|
|
11519
|
+
hideZodInputObjectTypesAndRelatedFields(inputObjectTypes, hiddenModels, hiddenFields);
|
|
11520
|
+
await generateZodObjectSchemas(inputObjectTypes);
|
|
11521
|
+
await generateZodModelSchemas(models, modelOperations, aggregateOperationSupport);
|
|
11522
|
+
await generateZodIndex();
|
|
11523
|
+
} else {
|
|
11524
|
+
consoleLog("Skipping Zod schemas generation");
|
|
11525
|
+
}
|
|
10325
11526
|
if (config.withShield !== false) {
|
|
10326
11527
|
consoleLog("Generating tRPC Shield");
|
|
10327
11528
|
const shieldOutputDir = joinPaths(outputDir, "shield");
|
|
@@ -10385,7 +11586,7 @@ async function generate(options) {
|
|
|
10385
11586
|
}
|
|
10386
11587
|
consoleLog(`Generating tRPC source code for ${models.length} models`);
|
|
10387
11588
|
resolveModelsComments(models, hiddenModels);
|
|
10388
|
-
const createRouter = project.createSourceFile(
|
|
11589
|
+
const createRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
|
|
10389
11590
|
overwrite: true
|
|
10390
11591
|
});
|
|
10391
11592
|
consoleLog("Generating tRPC imports");
|
|
@@ -10398,7 +11599,7 @@ async function generate(options) {
|
|
|
10398
11599
|
createRouter.formatText({
|
|
10399
11600
|
indentSize: 2
|
|
10400
11601
|
});
|
|
10401
|
-
const appRouter = project.createSourceFile(
|
|
11602
|
+
const appRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
10402
11603
|
overwrite: true
|
|
10403
11604
|
});
|
|
10404
11605
|
consoleLog("Generating tRPC router imports");
|
|
@@ -10420,7 +11621,7 @@ async function generate(options) {
|
|
|
10420
11621
|
const plural = (0, import_pluralize.default)(model.toLowerCase());
|
|
10421
11622
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
10422
11623
|
generateRouterImport(appRouter, plural, model);
|
|
10423
|
-
const modelRouter = project.createSourceFile(
|
|
11624
|
+
const modelRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
10424
11625
|
overwrite: true
|
|
10425
11626
|
});
|
|
10426
11627
|
generateCreateRouterImport({
|