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