@stryke/prisma-trpc-generator 0.13.48 → 0.13.50
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/_virtual/rolldown_runtime.cjs +31 -1
- package/dist/_virtual/rolldown_runtime.mjs +32 -1
- package/dist/config.cjs +50 -1
- package/dist/config.mjs +49 -1
- package/dist/config.mjs.map +1 -1
- package/dist/generator.cjs +1 -1
- package/dist/generator.mjs +3 -1
- package/dist/helpers.cjs +281 -32
- package/dist/helpers.mjs +271 -32
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +26 -1
- package/dist/index.mjs +27 -1
- package/dist/index.mjs.map +1 -1
- package/dist/packages/env/src/get-env-paths.cjs +87 -1
- package/dist/packages/env/src/get-env-paths.mjs +84 -1
- package/dist/packages/env/src/get-env-paths.mjs.map +1 -1
- package/dist/packages/string-format/src/acronyms.cjs +408 -1
- package/dist/packages/string-format/src/acronyms.mjs +407 -1
- package/dist/packages/string-format/src/acronyms.mjs.map +1 -1
- package/dist/packages/string-format/src/articles.cjs +10 -1
- package/dist/packages/string-format/src/articles.mjs +9 -1
- package/dist/packages/string-format/src/articles.mjs.map +1 -1
- package/dist/packages/string-format/src/combine.cjs +15 -1
- package/dist/packages/string-format/src/combine.mjs +14 -1
- package/dist/packages/string-format/src/combine.mjs.map +1 -1
- package/dist/packages/string-format/src/conjunctions.cjs +32 -1
- package/dist/packages/string-format/src/conjunctions.mjs +31 -1
- package/dist/packages/string-format/src/conjunctions.mjs.map +1 -1
- package/dist/packages/string-format/src/decamelize.cjs +14 -1
- package/dist/packages/string-format/src/decamelize.mjs +13 -1
- package/dist/packages/string-format/src/decamelize.mjs.map +1 -1
- package/dist/packages/string-format/src/format-special-cases.cjs +33 -1
- package/dist/packages/string-format/src/format-special-cases.mjs +33 -1
- package/dist/packages/string-format/src/format-special-cases.mjs.map +1 -1
- package/dist/packages/string-format/src/lower-case-first.cjs +17 -1
- package/dist/packages/string-format/src/lower-case-first.mjs +16 -1
- package/dist/packages/string-format/src/lower-case-first.mjs.map +1 -1
- package/dist/packages/string-format/src/prepositions.cjs +68 -1
- package/dist/packages/string-format/src/prepositions.mjs +67 -1
- package/dist/packages/string-format/src/prepositions.mjs.map +1 -1
- package/dist/packages/string-format/src/special-cases.cjs +53 -1
- package/dist/packages/string-format/src/special-cases.mjs +52 -1
- package/dist/packages/string-format/src/special-cases.mjs.map +1 -1
- package/dist/packages/string-format/src/title-case.cjs +19 -1
- package/dist/packages/string-format/src/title-case.mjs +19 -1
- package/dist/packages/string-format/src/title-case.mjs.map +1 -1
- package/dist/packages/string-format/src/upper-case-first.cjs +17 -1
- package/dist/packages/string-format/src/upper-case-first.mjs +16 -1
- package/dist/packages/string-format/src/upper-case-first.mjs.map +1 -1
- package/dist/prisma-generator.cjs +185 -8
- package/dist/prisma-generator.mjs +184 -8
- package/dist/prisma-generator.mjs.map +1 -1
- package/dist/project.cjs +15 -1
- package/dist/project.mjs +14 -1
- package/dist/project.mjs.map +1 -1
- package/dist/utils/format-file.cjs +25 -1
- package/dist/utils/format-file.mjs +23 -1
- package/dist/utils/format-file.mjs.map +1 -1
- package/dist/utils/get-jiti.cjs +21 -1
- package/dist/utils/get-jiti.mjs +20 -1
- package/dist/utils/get-jiti.mjs.map +1 -1
- package/dist/utils/get-prisma-internals.cjs +13 -1
- package/dist/utils/get-prisma-internals.mjs +12 -1
- package/dist/utils/get-prisma-internals.mjs.map +1 -1
- package/dist/utils/write-file-safely.cjs +32 -2
- package/dist/utils/write-file-safely.mjs +29 -2
- package/dist/utils/write-file-safely.mjs.map +1 -1
- package/dist/zod/aggregate-helpers.cjs +70 -1
- package/dist/zod/aggregate-helpers.mjs +67 -1
- package/dist/zod/aggregate-helpers.mjs.map +1 -1
- package/dist/zod/comments-helpers.cjs +77 -1
- package/dist/zod/comments-helpers.mjs +75 -1
- package/dist/zod/comments-helpers.mjs.map +1 -1
- package/dist/zod/docs-helpers.cjs +23 -3
- package/dist/zod/docs-helpers.mjs +20 -3
- package/dist/zod/docs-helpers.mjs.map +1 -1
- package/dist/zod/generator-helpers.cjs +34 -1
- package/dist/zod/generator-helpers.mjs +31 -1
- package/dist/zod/generator-helpers.mjs.map +1 -1
- package/dist/zod/helpers.cjs +26 -1
- package/dist/zod/helpers.mjs +26 -1
- package/dist/zod/helpers.mjs.map +1 -1
- package/dist/zod/include-helpers.cjs +69 -1
- package/dist/zod/include-helpers.mjs +69 -1
- package/dist/zod/include-helpers.mjs.map +1 -1
- package/dist/zod/model-helpers.cjs +244 -1
- package/dist/zod/model-helpers.mjs +236 -1
- package/dist/zod/model-helpers.mjs.map +1 -1
- package/dist/zod/modelArgs-helpers.cjs +56 -1
- package/dist/zod/modelArgs-helpers.mjs +56 -1
- package/dist/zod/modelArgs-helpers.mjs.map +1 -1
- package/dist/zod/mongodb-helpers.cjs +49 -1
- package/dist/zod/mongodb-helpers.mjs +48 -1
- package/dist/zod/mongodb-helpers.mjs.map +1 -1
- package/dist/zod/select-helpers.cjs +128 -1
- package/dist/zod/select-helpers.mjs +128 -1
- package/dist/zod/select-helpers.mjs.map +1 -1
- package/dist/zod/transformer.cjs +434 -19
- package/dist/zod/transformer.mjs +432 -19
- package/dist/zod/transformer.mjs.map +1 -1
- package/dist/zod/whereUniqueInput-helpers.cjs +17 -1
- package/dist/zod/whereUniqueInput-helpers.mjs +16 -1
- package/dist/zod/whereUniqueInput-helpers.mjs.map +1 -1
- package/package.json +4 -4
package/dist/zod/transformer.mjs
CHANGED
|
@@ -1,22 +1,435 @@
|
|
|
1
|
-
import{lowerCaseFirst
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`,e+=`);
|
|
1
|
+
import { lowerCaseFirst } from "../packages/string-format/src/lower-case-first.mjs";
|
|
2
|
+
import { upperCaseFirst } from "../packages/string-format/src/upper-case-first.mjs";
|
|
3
|
+
import { checkModelHasModelRelation, findModelByName } from "./model-helpers.mjs";
|
|
4
|
+
import { writeFileSafely, writeIndexFile } from "../utils/write-file-safely.mjs";
|
|
5
|
+
import { isAggregateInputType } from "./aggregate-helpers.mjs";
|
|
6
|
+
import { isMongodbRawOp } from "./mongodb-helpers.mjs";
|
|
7
|
+
import path from "node:path";
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
//#region src/zod/transformer.ts
|
|
10
|
+
var Transformer = class Transformer {
|
|
11
|
+
name;
|
|
12
|
+
fields;
|
|
13
|
+
schemaImports = /* @__PURE__ */ new Set();
|
|
14
|
+
models;
|
|
15
|
+
modelOperations;
|
|
16
|
+
aggregateOperationSupport;
|
|
17
|
+
enumTypes;
|
|
18
|
+
static enumNames = [];
|
|
19
|
+
static rawOpsMap = {};
|
|
20
|
+
static provider;
|
|
21
|
+
static previewFeatures;
|
|
22
|
+
static outputPath = "./generated";
|
|
23
|
+
hasJson = false;
|
|
24
|
+
static prismaClientOutputPath = "@prisma/client";
|
|
25
|
+
static isCustomPrismaClientOutputPath = false;
|
|
26
|
+
static isGenerateSelect = true;
|
|
27
|
+
static isGenerateInclude = true;
|
|
28
|
+
constructor(params) {
|
|
29
|
+
this.name = params.name ?? "";
|
|
30
|
+
this.fields = params.fields ?? [];
|
|
31
|
+
this.models = params.models ?? [];
|
|
32
|
+
this.modelOperations = params.modelOperations ?? [];
|
|
33
|
+
this.aggregateOperationSupport = params.aggregateOperationSupport ?? {};
|
|
34
|
+
this.enumTypes = params.enumTypes ?? [];
|
|
35
|
+
}
|
|
36
|
+
static setOutputPath(outPath) {
|
|
37
|
+
this.outputPath = outPath;
|
|
38
|
+
}
|
|
39
|
+
static setIsGenerateSelect(isGenerateSelect) {
|
|
40
|
+
this.isGenerateSelect = isGenerateSelect;
|
|
41
|
+
}
|
|
42
|
+
static setIsGenerateInclude(isGenerateInclude) {
|
|
43
|
+
this.isGenerateInclude = isGenerateInclude;
|
|
44
|
+
}
|
|
45
|
+
static getOutputPath() {
|
|
46
|
+
return this.outputPath;
|
|
47
|
+
}
|
|
48
|
+
static setPrismaClientOutputPath(prismaClientCustomPath) {
|
|
49
|
+
this.prismaClientOutputPath = prismaClientCustomPath;
|
|
50
|
+
this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
|
|
51
|
+
}
|
|
52
|
+
static async generateIndex() {
|
|
53
|
+
await writeIndexFile(path.join(Transformer.outputPath, "schemas/index.ts"));
|
|
54
|
+
}
|
|
55
|
+
async generateEnumSchemas() {
|
|
56
|
+
for (const enumType of this.enumTypes) {
|
|
57
|
+
const { name, values } = enumType;
|
|
58
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}\n${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
generateImportZodStatement() {
|
|
62
|
+
return "import { z } from 'zod';\n";
|
|
63
|
+
}
|
|
64
|
+
generateExportSchemaStatement(name, schema) {
|
|
65
|
+
return `export const ${lowerCaseFirst(name)}Schema = ${schema}`;
|
|
66
|
+
}
|
|
67
|
+
async generateObjectSchema() {
|
|
68
|
+
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
69
|
+
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
70
|
+
const objectSchemaName = this.resolveObjectSchemaName();
|
|
71
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
|
|
72
|
+
}
|
|
73
|
+
generateObjectSchemaFields() {
|
|
74
|
+
return this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
75
|
+
const [zodStringWithMainType, field, skipValidators] = item;
|
|
76
|
+
return (skipValidators ? zodStringWithMainType : this.generateFieldValidators(zodStringWithMainType, field)).trim();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
generateObjectSchemaField(field) {
|
|
80
|
+
const lines = field.inputTypes;
|
|
81
|
+
if (lines.length === 0) return [];
|
|
82
|
+
let alternatives = lines.reduce((result, inputType) => {
|
|
83
|
+
if (inputType.type === "String") result.push(this.wrapWithZodValidators("z.string()", field));
|
|
84
|
+
else if (inputType.type === "Int" || inputType.type === "Float" || inputType.type === "Decimal") result.push(this.wrapWithZodValidators("z.number()", field));
|
|
85
|
+
else if (inputType.type === "BigInt") result.push(this.wrapWithZodValidators("z.bigint()", field));
|
|
86
|
+
else if (inputType.type === "Boolean") result.push(this.wrapWithZodValidators("z.boolean()", field));
|
|
87
|
+
else if (inputType.type === "DateTime") result.push(this.wrapWithZodValidators("z.coerce.date()", field));
|
|
88
|
+
else if (inputType.type === "Json") {
|
|
89
|
+
this.hasJson = true;
|
|
90
|
+
result.push(this.wrapWithZodValidators("jsonSchema", field));
|
|
91
|
+
} else if (inputType.type === "True") result.push(this.wrapWithZodValidators("z.literal(true)", field));
|
|
92
|
+
else if (inputType.type === "Bytes") result.push(this.wrapWithZodValidators("z.instanceof(Buffer)", field));
|
|
93
|
+
else if (!inputType.type.endsWith("FieldRefInput")) {
|
|
94
|
+
const isEnum = inputType.location === "enumTypes";
|
|
95
|
+
if (inputType.namespace === "prisma" || isEnum) {
|
|
96
|
+
if (inputType.type !== this.name && typeof inputType.type === "string") this.addSchemaImport(inputType.type);
|
|
97
|
+
result.push(this.generatePrismaStringLine(field, inputType, lines.length));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}, []);
|
|
102
|
+
if (alternatives.length === 0) return [];
|
|
103
|
+
if (alternatives.length > 1) alternatives = alternatives.map((alter) => alter.replace(".optional()", ""));
|
|
104
|
+
const fieldName = alternatives.some((alt) => alt.includes(":")) ? "" : ` ${field.name}:`;
|
|
105
|
+
const opt = !field.isRequired ? ".optional()" : "";
|
|
106
|
+
let resString = alternatives.length === 1 ? alternatives.join(",\r\n") : `z.union([${alternatives.join(",\r\n")}])${opt}`;
|
|
107
|
+
if (field.isNullable) resString += ".nullable()";
|
|
108
|
+
return [[
|
|
109
|
+
` ${fieldName} ${resString} `,
|
|
110
|
+
field,
|
|
111
|
+
true
|
|
112
|
+
]];
|
|
113
|
+
}
|
|
114
|
+
wrapWithZodValidators(mainValidator, field) {
|
|
115
|
+
let line = "";
|
|
116
|
+
line = mainValidator;
|
|
117
|
+
if (field.inputTypes.some((inputType) => inputType.isList)) line += ".array()";
|
|
118
|
+
if (!field.isRequired) line += ".optional()";
|
|
119
|
+
return line;
|
|
120
|
+
}
|
|
121
|
+
addSchemaImport(name) {
|
|
122
|
+
this.schemaImports.add(name);
|
|
123
|
+
}
|
|
124
|
+
generatePrismaStringLine(field, inputType, inputsLength) {
|
|
125
|
+
const isEnum = inputType.location === "enumTypes";
|
|
126
|
+
const inputTypeString = inputType.type;
|
|
127
|
+
const { isModelQueryType, modelName, queryName } = this.checkIsModelQueryType(inputTypeString);
|
|
128
|
+
const objectSchemaLine = isModelQueryType ? this.resolveModelQuerySchemaName(modelName, queryName) : `${inputTypeString}ObjectSchema`;
|
|
129
|
+
const enumSchemaLine = `${inputTypeString}Schema`;
|
|
130
|
+
const schema = inputType.type === this.name ? objectSchemaLine : isEnum ? enumSchemaLine : objectSchemaLine;
|
|
131
|
+
const arr = inputType.isList ? ".array()" : "";
|
|
132
|
+
const opt = !field.isRequired ? ".optional()" : "";
|
|
133
|
+
return inputsLength === 1 ? ` ${field.name}: z.lazy(() => ${lowerCaseFirst(schema)})${arr}${opt}` : `z.lazy(() => ${lowerCaseFirst(schema)})${arr}${opt}`;
|
|
134
|
+
}
|
|
135
|
+
generateFieldValidators(zodStringWithMainType, field) {
|
|
136
|
+
const { isRequired, isNullable } = field;
|
|
137
|
+
if (!isRequired) zodStringWithMainType += ".optional()";
|
|
138
|
+
if (isNullable) zodStringWithMainType += ".nullable()";
|
|
139
|
+
return zodStringWithMainType;
|
|
140
|
+
}
|
|
141
|
+
prepareObjectSchema(zodObjectSchemaFields) {
|
|
142
|
+
const objectSchema = `${this.generateExportObjectSchemaStatement(this.addFinalWrappers({ zodStringFields: zodObjectSchemaFields }))}\n`;
|
|
143
|
+
const prismaImportStatement = this.generateImportPrismaStatement();
|
|
144
|
+
const json = this.generateJsonSchemaImplementation();
|
|
145
|
+
return `${this.generateObjectSchemaImportStatements()}${prismaImportStatement}${json}${objectSchema}`;
|
|
146
|
+
}
|
|
147
|
+
generateExportObjectSchemaStatement(schema) {
|
|
148
|
+
let name = this.name;
|
|
149
|
+
let exportName = this.name;
|
|
150
|
+
if (Transformer.provider === "mongodb") {
|
|
151
|
+
if (isMongodbRawOp(name)) {
|
|
152
|
+
name = Transformer.rawOpsMap[name];
|
|
153
|
+
exportName = name.replace("Args", "");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (isAggregateInputType(name)) name = `${name}Type`;
|
|
157
|
+
const end = `export const ${lowerCaseFirst(exportName)}ObjectSchema = schema`;
|
|
158
|
+
return `const schema: z.ZodType<Prisma.${name}> = ${schema};\n\n ${end}`;
|
|
159
|
+
}
|
|
160
|
+
addFinalWrappers({ zodStringFields }) {
|
|
161
|
+
const fields = [...zodStringFields];
|
|
162
|
+
return `${this.wrapWithZodObject(fields)}.strict()`;
|
|
163
|
+
}
|
|
164
|
+
generateImportPrismaStatement() {
|
|
165
|
+
let prismaClientImportPath;
|
|
166
|
+
if (Transformer.isCustomPrismaClientOutputPath) {
|
|
167
|
+
/**
|
|
168
|
+
* If a custom location was designated for the prisma client, we need to figure out the
|
|
169
|
+
* relative path from \{outputPath\}/schemas/objects to \{prismaClientCustomPath\}
|
|
170
|
+
*/
|
|
171
|
+
const fromPath = path.join(Transformer.outputPath, "schemas", "objects");
|
|
172
|
+
const toPath = Transformer.prismaClientOutputPath;
|
|
173
|
+
prismaClientImportPath = path.relative(fromPath, toPath).split(path.sep).join(path.posix.sep);
|
|
174
|
+
} else
|
|
175
|
+
/**
|
|
176
|
+
* If the default output path for prisma client (\@prisma/client) is being used, we can import from it directly
|
|
177
|
+
* without having to resolve a relative path
|
|
178
|
+
*/
|
|
179
|
+
prismaClientImportPath = Transformer.prismaClientOutputPath;
|
|
180
|
+
return `import type { Prisma } from '${prismaClientImportPath}';\n\n`;
|
|
181
|
+
}
|
|
182
|
+
generateJsonSchemaImplementation() {
|
|
183
|
+
let jsonSchemaImplementation = "";
|
|
184
|
+
if (this.hasJson) {
|
|
185
|
+
jsonSchemaImplementation += `\n`;
|
|
186
|
+
jsonSchemaImplementation += `const literalSchema = z.union([z.string(), z.number(), z.boolean()]);\n`;
|
|
187
|
+
jsonSchemaImplementation += `const jsonSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>\n`;
|
|
188
|
+
jsonSchemaImplementation += ` z.union([literalSchema, z.array(jsonSchema.nullable()), z.record(jsonSchema.nullable())])\n`;
|
|
189
|
+
jsonSchemaImplementation += `);\n\n`;
|
|
190
|
+
}
|
|
191
|
+
return jsonSchemaImplementation;
|
|
192
|
+
}
|
|
193
|
+
generateObjectSchemaImportStatements() {
|
|
194
|
+
let generatedImports = this.generateImportZodStatement();
|
|
195
|
+
generatedImports += this.generateSchemaImports();
|
|
196
|
+
generatedImports += "\n\n";
|
|
197
|
+
return generatedImports;
|
|
198
|
+
}
|
|
199
|
+
generateSchemaImports() {
|
|
200
|
+
return [...this.schemaImports].map((name) => {
|
|
201
|
+
const { isModelQueryType, modelName, queryName } = this.checkIsModelQueryType(name);
|
|
202
|
+
if (isModelQueryType) return `import { ${this.resolveModelQuerySchemaName(modelName, queryName)} } from '../${queryName}${modelName}.schema'`;
|
|
203
|
+
else if (Transformer.enumNames.includes(name)) return `import { ${lowerCaseFirst(name)}Schema } from '../enums/${lowerCaseFirst(name)}.schema'`;
|
|
204
|
+
else return `import { ${lowerCaseFirst(name)}ObjectSchema } from './${lowerCaseFirst(name)}.schema'`;
|
|
205
|
+
}).join(";\r\n");
|
|
206
|
+
}
|
|
207
|
+
checkIsModelQueryType(type) {
|
|
208
|
+
const modelQueryTypeSuffixToQueryName = { FindManyArgs: "findMany" };
|
|
209
|
+
for (const modelQueryType of ["FindManyArgs"]) if (type.includes(modelQueryType)) {
|
|
210
|
+
const modelQueryTypeSuffixIndex = type.indexOf(modelQueryType);
|
|
211
|
+
return {
|
|
212
|
+
isModelQueryType: true,
|
|
213
|
+
modelName: type.substring(0, modelQueryTypeSuffixIndex),
|
|
214
|
+
queryName: modelQueryTypeSuffixToQueryName[modelQueryType]
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return { isModelQueryType: false };
|
|
218
|
+
}
|
|
219
|
+
resolveModelQuerySchemaName(modelName, queryName) {
|
|
220
|
+
return `${lowerCaseFirst(modelName)}${upperCaseFirst(queryName)}Schema`;
|
|
221
|
+
}
|
|
222
|
+
wrapWithZodUnion(zodStringFields) {
|
|
223
|
+
let wrapped = "";
|
|
224
|
+
wrapped += "z.union([";
|
|
225
|
+
wrapped += "\n";
|
|
226
|
+
wrapped += ` ${zodStringFields.join(",")}`;
|
|
227
|
+
wrapped += "\n";
|
|
228
|
+
wrapped += "])";
|
|
229
|
+
return wrapped;
|
|
230
|
+
}
|
|
231
|
+
wrapWithZodObject(zodStringFields) {
|
|
232
|
+
let wrapped = "";
|
|
233
|
+
wrapped += "z.object({";
|
|
234
|
+
wrapped += "\n";
|
|
235
|
+
wrapped += ` ${typeof zodStringFields === "string" ? zodStringFields : zodStringFields.join(",\n ")}`;
|
|
236
|
+
wrapped += "\n";
|
|
237
|
+
wrapped += "})";
|
|
238
|
+
return wrapped;
|
|
239
|
+
}
|
|
240
|
+
resolveObjectSchemaName() {
|
|
241
|
+
let name = this.name;
|
|
242
|
+
let exportName = this.name;
|
|
243
|
+
if (isMongodbRawOp(name)) {
|
|
244
|
+
name = Transformer.rawOpsMap[name];
|
|
245
|
+
exportName = name.replace("Args", "");
|
|
246
|
+
}
|
|
247
|
+
return lowerCaseFirst(exportName);
|
|
248
|
+
}
|
|
249
|
+
async generateModelSchemas() {
|
|
250
|
+
for (const modelOperation of this.modelOperations) {
|
|
251
|
+
const { findUnique, findFirst, findMany, createOne, createMany, createManyAndReturn, deleteOne, updateOne, deleteMany, updateMany, updateManyAndReturn, upsertOne, aggregate, groupBy } = modelOperation;
|
|
252
|
+
const model = findModelByName(this.models, modelOperation.model);
|
|
253
|
+
const modelName = lowerCaseFirst(modelOperation.model);
|
|
254
|
+
const { selectImport, includeImport, selectZodSchemaLine, includeZodSchemaLine, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
255
|
+
const { orderByImport, orderByZodSchemaLine } = this.resolveOrderByWithRelationImportAndZodSchemaLine(model);
|
|
256
|
+
if (findUnique) {
|
|
257
|
+
const imports = [
|
|
258
|
+
selectImport,
|
|
259
|
+
includeImport,
|
|
260
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
261
|
+
];
|
|
262
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
263
|
+
}
|
|
264
|
+
if (findFirst) {
|
|
265
|
+
const imports = [
|
|
266
|
+
selectImport,
|
|
267
|
+
includeImport,
|
|
268
|
+
orderByImport,
|
|
269
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
270
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
271
|
+
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
272
|
+
];
|
|
273
|
+
await writeFileSafely(path.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() })`)}`);
|
|
274
|
+
}
|
|
275
|
+
if (findMany) {
|
|
276
|
+
const imports = [
|
|
277
|
+
selectImport,
|
|
278
|
+
includeImport,
|
|
279
|
+
orderByImport,
|
|
280
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
281
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
282
|
+
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
283
|
+
];
|
|
284
|
+
await writeFileSafely(path.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() })`)}`);
|
|
285
|
+
}
|
|
286
|
+
if (createOne) {
|
|
287
|
+
const imports = [
|
|
288
|
+
selectImport,
|
|
289
|
+
includeImport,
|
|
290
|
+
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
291
|
+
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
|
|
292
|
+
];
|
|
293
|
+
await writeFileSafely(path.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]) })`)}`);
|
|
294
|
+
}
|
|
295
|
+
if (createMany) {
|
|
296
|
+
const imports = [`import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`];
|
|
297
|
+
await writeFileSafely(path.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()"} })`)}`);
|
|
298
|
+
}
|
|
299
|
+
if (createManyAndReturn) {
|
|
300
|
+
const imports = [`import { ${modelName}CreateManyAndReturnInputObjectSchema } from './objects/${modelName}CreateManyAndReturnInput.schema'`];
|
|
301
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/${createManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateManyAndReturn`, `z.object({ data: z.union([ ${modelName}CreateManyAndReturnInputObjectSchema, z.array(${modelName}CreateManyAndReturnInputObjectSchema) ]), ${Transformer.provider === "mongodb" || Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
302
|
+
}
|
|
303
|
+
if (deleteOne) {
|
|
304
|
+
const imports = [
|
|
305
|
+
selectImport,
|
|
306
|
+
includeImport,
|
|
307
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
308
|
+
];
|
|
309
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
310
|
+
}
|
|
311
|
+
if (deleteMany) {
|
|
312
|
+
const imports = [`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`];
|
|
313
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
314
|
+
}
|
|
315
|
+
if (updateOne) {
|
|
316
|
+
const imports = [
|
|
317
|
+
selectImport,
|
|
318
|
+
includeImport,
|
|
319
|
+
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
320
|
+
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
|
|
321
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
322
|
+
];
|
|
323
|
+
await writeFileSafely(path.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 })`)}`);
|
|
324
|
+
}
|
|
325
|
+
if (updateMany) {
|
|
326
|
+
const imports = [`import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`, `import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`];
|
|
327
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
328
|
+
}
|
|
329
|
+
if (updateManyAndReturn) {
|
|
330
|
+
const imports = [`import { ${modelName}UpdateManyAndReturnInputObjectSchema } from './objects/${modelName}UpdateManyAndReturnInput.schema'`];
|
|
331
|
+
await writeFileSafely(path.join(Transformer.outputPath, `schemas/${updateManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateManyAndReturn`, `z.object({ data: z.union([ ${modelName}UpdateManyAndReturnInputObjectSchema, z.array(${modelName}UpdateManyAndReturnInputObjectSchema) ]), ${Transformer.provider === "mongodb" || Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
332
|
+
}
|
|
333
|
+
if (upsertOne) {
|
|
334
|
+
const imports = [
|
|
335
|
+
selectImport,
|
|
336
|
+
includeImport,
|
|
337
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
338
|
+
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
339
|
+
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`,
|
|
340
|
+
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
341
|
+
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
|
|
342
|
+
];
|
|
343
|
+
await writeFileSafely(path.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 ]) })`)}`);
|
|
344
|
+
}
|
|
345
|
+
if (aggregate) {
|
|
346
|
+
const imports = [
|
|
347
|
+
orderByImport,
|
|
348
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
349
|
+
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
350
|
+
];
|
|
351
|
+
const aggregateOperations = [];
|
|
352
|
+
if (this.aggregateOperationSupport[modelName]) {
|
|
353
|
+
if (this.aggregateOperationSupport[modelName].count) {
|
|
354
|
+
imports.push(`import { ${modelName}CountAggregateInputObjectSchema } from './objects/${modelName}CountAggregateInput.schema'`);
|
|
355
|
+
aggregateOperations.push(`_count: z.union([ z.literal(true), ${modelName}CountAggregateInputObjectSchema ]).optional()`);
|
|
356
|
+
}
|
|
357
|
+
if (this.aggregateOperationSupport[modelName].min) {
|
|
358
|
+
imports.push(`import { ${modelName}MinAggregateInputObjectSchema } from './objects/${modelName}MinAggregateInput.schema'`);
|
|
359
|
+
aggregateOperations.push(`_min: ${modelName}MinAggregateInputObjectSchema.optional()`);
|
|
360
|
+
}
|
|
361
|
+
if (this.aggregateOperationSupport[modelName].max) {
|
|
362
|
+
imports.push(`import { ${modelName}MaxAggregateInputObjectSchema } from './objects/${modelName}MaxAggregateInput.schema'`);
|
|
363
|
+
aggregateOperations.push(`_max: ${modelName}MaxAggregateInputObjectSchema.optional()`);
|
|
364
|
+
}
|
|
365
|
+
if (this.aggregateOperationSupport[modelName].avg) {
|
|
366
|
+
imports.push(`import { ${modelName}AvgAggregateInputObjectSchema } from './objects/${modelName}AvgAggregateInput.schema'`);
|
|
367
|
+
aggregateOperations.push(`_avg: ${modelName}AvgAggregateInputObjectSchema.optional()`);
|
|
368
|
+
}
|
|
369
|
+
if (this.aggregateOperationSupport[modelName].sum) {
|
|
370
|
+
imports.push(`import { ${modelName}SumAggregateInputObjectSchema } from './objects/${modelName}SumAggregateInput.schema'`);
|
|
371
|
+
aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
await writeFileSafely(path.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(", ")} })`)}`);
|
|
375
|
+
}
|
|
376
|
+
if (groupBy) {
|
|
377
|
+
const imports = [
|
|
378
|
+
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`,
|
|
379
|
+
`import { ${modelName}OrderByWithAggregationInputObjectSchema } from './objects/${modelName}OrderByWithAggregationInput.schema'`,
|
|
380
|
+
`import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
|
|
381
|
+
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
382
|
+
];
|
|
383
|
+
await writeFileSafely(path.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) })`)}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
generateImportStatements(imports) {
|
|
388
|
+
let generatedImports = this.generateImportZodStatement();
|
|
389
|
+
generatedImports += imports?.filter((importItem) => !!importItem).join(";\r\n") ?? "";
|
|
390
|
+
generatedImports += "\n\n";
|
|
391
|
+
return generatedImports;
|
|
392
|
+
}
|
|
393
|
+
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
394
|
+
const { name: modelName } = model;
|
|
395
|
+
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
396
|
+
const selectImport = Transformer.isGenerateSelect ? `import { ${lowerCaseFirst(modelName)}SelectObjectSchema } from './objects/${lowerCaseFirst(modelName)}Select.schema'` : "";
|
|
397
|
+
const includeImport = Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${lowerCaseFirst(modelName)}IncludeObjectSchema } from './objects/${lowerCaseFirst(modelName)}Include.schema'` : "";
|
|
398
|
+
let selectZodSchemaLine = "";
|
|
399
|
+
let includeZodSchemaLine = "";
|
|
400
|
+
let selectZodSchemaLineLazy = "";
|
|
401
|
+
let includeZodSchemaLineLazy = "";
|
|
402
|
+
if (Transformer.isGenerateSelect) {
|
|
403
|
+
const zodSelectObjectSchema = `${lowerCaseFirst(modelName)}SelectObjectSchema.optional()`;
|
|
404
|
+
selectZodSchemaLine = `select: ${zodSelectObjectSchema},`;
|
|
405
|
+
selectZodSchemaLineLazy = `select: z.lazy(() => ${zodSelectObjectSchema}),`;
|
|
406
|
+
}
|
|
407
|
+
if (Transformer.isGenerateInclude && hasRelationToAnotherModel) {
|
|
408
|
+
const zodIncludeObjectSchema = `${lowerCaseFirst(modelName)}IncludeObjectSchema.optional()`;
|
|
409
|
+
includeZodSchemaLine = `include: ${zodIncludeObjectSchema},`;
|
|
410
|
+
includeZodSchemaLineLazy = `include: z.lazy(() => ${zodIncludeObjectSchema}),`;
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
selectImport,
|
|
414
|
+
includeImport,
|
|
415
|
+
selectZodSchemaLine,
|
|
416
|
+
includeZodSchemaLine,
|
|
417
|
+
selectZodSchemaLineLazy,
|
|
418
|
+
includeZodSchemaLineLazy
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
resolveOrderByWithRelationImportAndZodSchemaLine(model) {
|
|
422
|
+
const { name: modelName } = model;
|
|
423
|
+
let modelOrderBy = "";
|
|
424
|
+
if (["postgresql", "mysql"].includes(Transformer.provider) && Transformer.previewFeatures?.includes("fullTextSearch")) modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationAndSearchRelevanceInput`;
|
|
425
|
+
else modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationInput`;
|
|
426
|
+
return {
|
|
427
|
+
orderByImport: `import { ${modelOrderBy}ObjectSchema } from './objects/${modelOrderBy}.schema'`,
|
|
428
|
+
orderByZodSchemaLine: `orderBy: z.union([${modelOrderBy}ObjectSchema, ${modelOrderBy}ObjectSchema.array()]).optional(),`
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
};
|
|
11
432
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
`,t+=` ${e.join(`,`)}`,t+=`
|
|
15
|
-
`,t+=`])`,t}wrapWithZodObject(e){let t=``;return t+=`z.object({`,t+=`
|
|
16
|
-
`,t+=` ${typeof e==`string`?e:e.join(`,
|
|
17
|
-
`)}`,t+=`
|
|
18
|
-
`,t+=`})`,t}resolveObjectSchemaName(){let t=this.name,n=this.name;return s(t)&&(t=l.rawOpsMap[t],n=t.replace(`Args`,``)),e(n)}async generateModelSchemas(){for(let t of this.modelOperations){let{findUnique:n,findFirst:a,findMany:o,createOne:s,createMany:u,createManyAndReturn:d,deleteOne:f,updateOne:p,deleteMany:m,updateMany:h,updateManyAndReturn:g,upsertOne:_,aggregate:v,groupBy:y}=t,b=r(this.models,t.model),x=e(t.model),{selectImport:S,includeImport:C,selectZodSchemaLine:w,includeZodSchemaLine:T,selectZodSchemaLineLazy:E,includeZodSchemaLineLazy:D}=this.resolveSelectIncludeImportAndZodSchemaLine(b),{orderByImport:O,orderByZodSchemaLine:k}=this.resolveOrderByWithRelationImportAndZodSchemaLine(b);if(n){let e=[S,C,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`];await i(c.join(l.outputPath,`schemas/${n}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}FindUnique`,`z.object({ ${w} ${T} where: ${x}WhereUniqueInputObjectSchema })`)}`)}if(a){let e=[S,C,O,`import { ${x}WhereInputObjectSchema } from './objects/${x}WhereInput.schema'`,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`,`import { ${x}ScalarFieldEnumSchema } from './enums/${x}ScalarFieldEnum.schema'`];await i(c.join(l.outputPath,`schemas/${a}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}FindFirst`,`z.object({ ${w} ${T} ${k} where: ${x}WhereInputObjectSchema.optional(), cursor: ${x}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${x}ScalarFieldEnumSchema).optional() })`)}`)}if(o){let e=[S,C,O,`import { ${x}WhereInputObjectSchema } from './objects/${x}WhereInput.schema'`,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`,`import { ${x}ScalarFieldEnumSchema } from './enums/${x}ScalarFieldEnum.schema'`];await i(c.join(l.outputPath,`schemas/${o}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}FindMany`,`z.object({ ${E} ${D} ${k} where: ${x}WhereInputObjectSchema.optional(), cursor: ${x}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${x}ScalarFieldEnumSchema).optional() })`)}`)}if(s){let e=[S,C,`import { ${x}CreateInputObjectSchema } from './objects/${x}CreateInput.schema'`,`import { ${x}UncheckedCreateInputObjectSchema } from './objects/${x}UncheckedCreateInput.schema'`];await i(c.join(l.outputPath,`schemas/${s}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}CreateOne`,`z.object({ ${w} ${T} data: z.union([${x}CreateInputObjectSchema, ${x}UncheckedCreateInputObjectSchema]) })`)}`)}if(u){let e=[`import { ${x}CreateManyInputObjectSchema } from './objects/${x}CreateManyInput.schema'`];await i(c.join(l.outputPath,`schemas/${u}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}CreateMany`,`z.object({ data: z.union([ ${x}CreateManyInputObjectSchema, z.array(${x}CreateManyInputObjectSchema) ]), ${l.provider===`mongodb`||l.provider===`sqlserver`?``:`skipDuplicates: z.boolean().optional()`} })`)}`)}if(d){let e=[`import { ${x}CreateManyAndReturnInputObjectSchema } from './objects/${x}CreateManyAndReturnInput.schema'`];await i(c.join(l.outputPath,`schemas/${d}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}CreateManyAndReturn`,`z.object({ data: z.union([ ${x}CreateManyAndReturnInputObjectSchema, z.array(${x}CreateManyAndReturnInputObjectSchema) ]), ${l.provider===`mongodb`||l.provider===`sqlserver`?``:`skipDuplicates: z.boolean().optional()`} })`)}`)}if(f){let e=[S,C,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`];await i(c.join(l.outputPath,`schemas/${f}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}DeleteOne`,`z.object({ ${w} ${T} where: ${x}WhereUniqueInputObjectSchema })`)}`)}if(m){let e=[`import { ${x}WhereInputObjectSchema } from './objects/${x}WhereInput.schema'`];await i(c.join(l.outputPath,`schemas/${m}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}DeleteMany`,`z.object({ where: ${x}WhereInputObjectSchema.optional() })`)}`)}if(p){let e=[S,C,`import { ${x}UpdateInputObjectSchema } from './objects/${x}UpdateInput.schema'`,`import { ${x}UncheckedUpdateInputObjectSchema } from './objects/${x}UncheckedUpdateInput.schema'`,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`];await i(c.join(l.outputPath,`schemas/${p}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}UpdateOne`,`z.object({ ${w} ${T} data: z.union([${x}UpdateInputObjectSchema, ${x}UncheckedUpdateInputObjectSchema]), where: ${x}WhereUniqueInputObjectSchema })`)}`)}if(h){let e=[`import { ${x}UpdateManyMutationInputObjectSchema } from './objects/${x}UpdateManyMutationInput.schema'`,`import { ${x}WhereInputObjectSchema } from './objects/${x}WhereInput.schema'`];await i(c.join(l.outputPath,`schemas/${h}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}UpdateMany`,`z.object({ data: ${x}UpdateManyMutationInputObjectSchema, where: ${x}WhereInputObjectSchema.optional() })`)}`)}if(g){let e=[`import { ${x}UpdateManyAndReturnInputObjectSchema } from './objects/${x}UpdateManyAndReturnInput.schema'`];await i(c.join(l.outputPath,`schemas/${g}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}UpdateManyAndReturn`,`z.object({ data: z.union([ ${x}UpdateManyAndReturnInputObjectSchema, z.array(${x}UpdateManyAndReturnInputObjectSchema) ]), ${l.provider===`mongodb`||l.provider===`sqlserver`?``:`skipDuplicates: z.boolean().optional()`} })`)}`)}if(_){let e=[S,C,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`,`import { ${x}CreateInputObjectSchema } from './objects/${x}CreateInput.schema'`,`import { ${x}UncheckedCreateInputObjectSchema } from './objects/${x}UncheckedCreateInput.schema'`,`import { ${x}UpdateInputObjectSchema } from './objects/${x}UpdateInput.schema'`,`import { ${x}UncheckedUpdateInputObjectSchema } from './objects/${x}UncheckedUpdateInput.schema'`];await i(c.join(l.outputPath,`schemas/${_}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}Upsert`,`z.object({ ${w} ${T} where: ${x}WhereUniqueInputObjectSchema, create: z.union([ ${x}CreateInputObjectSchema, ${x}UncheckedCreateInputObjectSchema ]), update: z.union([ ${x}UpdateInputObjectSchema, ${x}UncheckedUpdateInputObjectSchema ]) })`)}`)}if(v){let e=[O,`import { ${x}WhereInputObjectSchema } from './objects/${x}WhereInput.schema'`,`import { ${x}WhereUniqueInputObjectSchema } from './objects/${x}WhereUniqueInput.schema'`],t=[];this.aggregateOperationSupport[x]&&(this.aggregateOperationSupport[x].count&&(e.push(`import { ${x}CountAggregateInputObjectSchema } from './objects/${x}CountAggregateInput.schema'`),t.push(`_count: z.union([ z.literal(true), ${x}CountAggregateInputObjectSchema ]).optional()`)),this.aggregateOperationSupport[x].min&&(e.push(`import { ${x}MinAggregateInputObjectSchema } from './objects/${x}MinAggregateInput.schema'`),t.push(`_min: ${x}MinAggregateInputObjectSchema.optional()`)),this.aggregateOperationSupport[x].max&&(e.push(`import { ${x}MaxAggregateInputObjectSchema } from './objects/${x}MaxAggregateInput.schema'`),t.push(`_max: ${x}MaxAggregateInputObjectSchema.optional()`)),this.aggregateOperationSupport[x].avg&&(e.push(`import { ${x}AvgAggregateInputObjectSchema } from './objects/${x}AvgAggregateInput.schema'`),t.push(`_avg: ${x}AvgAggregateInputObjectSchema.optional()`)),this.aggregateOperationSupport[x].sum&&(e.push(`import { ${x}SumAggregateInputObjectSchema } from './objects/${x}SumAggregateInput.schema'`),t.push(`_sum: ${x}SumAggregateInputObjectSchema.optional()`))),await i(c.join(l.outputPath,`schemas/${v}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}Aggregate`,`z.object({ ${k} where: ${x}WhereInputObjectSchema.optional(), cursor: ${x}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${t.join(`, `)} })`)}`)}if(y){let e=[`import { ${x}WhereInputObjectSchema } from './objects/${x}WhereInput.schema'`,`import { ${x}OrderByWithAggregationInputObjectSchema } from './objects/${x}OrderByWithAggregationInput.schema'`,`import { ${x}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${x}ScalarWhereWithAggregatesInput.schema'`,`import { ${x}ScalarFieldEnumSchema } from './enums/${x}ScalarFieldEnum.schema'`];await i(c.join(l.outputPath,`schemas/${y}.schema.ts`),`${this.generateImportStatements(e)}${this.generateExportSchemaStatement(`${x}GroupBy`,`z.object({ where: ${x}WhereInputObjectSchema.optional(), orderBy: z.union([${x}OrderByWithAggregationInputObjectSchema, ${x}OrderByWithAggregationInputObjectSchema.array()]).optional(), having: ${x}ScalarWhereWithAggregatesInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), by: z.array(${x}ScalarFieldEnumSchema) })`)}`)}}}generateImportStatements(e){let t=this.generateImportZodStatement();return t+=e?.filter(e=>!!e).join(`;\r
|
|
19
|
-
`)??``,t+=`
|
|
20
|
-
|
|
21
|
-
`,t}resolveSelectIncludeImportAndZodSchemaLine(t){let{name:r}=t,i=n(t),a=l.isGenerateSelect?`import { ${e(r)}SelectObjectSchema } from './objects/${e(r)}Select.schema'`:``,o=l.isGenerateInclude&&i?`import { ${e(r)}IncludeObjectSchema } from './objects/${e(r)}Include.schema'`:``,s=``,c=``,u=``,d=``;if(l.isGenerateSelect){let t=`${e(r)}SelectObjectSchema.optional()`;s=`select: ${t},`,u=`select: z.lazy(() => ${t}),`}if(l.isGenerateInclude&&i){let t=`${e(r)}IncludeObjectSchema.optional()`;c=`include: ${t},`,d=`include: z.lazy(() => ${t}),`}return{selectImport:a,includeImport:o,selectZodSchemaLine:s,includeZodSchemaLine:c,selectZodSchemaLineLazy:u,includeZodSchemaLineLazy:d}}resolveOrderByWithRelationImportAndZodSchemaLine(t){let{name:n}=t,r=``;return r=[`postgresql`,`mysql`].includes(l.provider)&&l.previewFeatures?.includes(`fullTextSearch`)?`${e(n)}OrderByWithRelationAndSearchRelevanceInput`:`${e(n)}OrderByWithRelationInput`,{orderByImport:`import { ${r}ObjectSchema } from './objects/${r}.schema'`,orderByZodSchemaLine:`orderBy: z.union([${r}ObjectSchema, ${r}ObjectSchema.array()]).optional(),`}}};export{l as default};
|
|
433
|
+
//#endregion
|
|
434
|
+
export { Transformer as default };
|
|
22
435
|
//# sourceMappingURL=transformer.mjs.map
|