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