@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.
Files changed (104) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +31 -1
  2. package/dist/_virtual/rolldown_runtime.mjs +32 -1
  3. package/dist/config.cjs +50 -1
  4. package/dist/config.mjs +49 -1
  5. package/dist/config.mjs.map +1 -1
  6. package/dist/generator.cjs +1 -1
  7. package/dist/generator.mjs +3 -1
  8. package/dist/helpers.cjs +281 -32
  9. package/dist/helpers.mjs +271 -32
  10. package/dist/helpers.mjs.map +1 -1
  11. package/dist/index.cjs +26 -1
  12. package/dist/index.mjs +27 -1
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/packages/env/src/get-env-paths.cjs +87 -1
  15. package/dist/packages/env/src/get-env-paths.mjs +84 -1
  16. package/dist/packages/env/src/get-env-paths.mjs.map +1 -1
  17. package/dist/packages/string-format/src/acronyms.cjs +408 -1
  18. package/dist/packages/string-format/src/acronyms.mjs +407 -1
  19. package/dist/packages/string-format/src/acronyms.mjs.map +1 -1
  20. package/dist/packages/string-format/src/articles.cjs +10 -1
  21. package/dist/packages/string-format/src/articles.mjs +9 -1
  22. package/dist/packages/string-format/src/articles.mjs.map +1 -1
  23. package/dist/packages/string-format/src/combine.cjs +15 -1
  24. package/dist/packages/string-format/src/combine.mjs +14 -1
  25. package/dist/packages/string-format/src/combine.mjs.map +1 -1
  26. package/dist/packages/string-format/src/conjunctions.cjs +32 -1
  27. package/dist/packages/string-format/src/conjunctions.mjs +31 -1
  28. package/dist/packages/string-format/src/conjunctions.mjs.map +1 -1
  29. package/dist/packages/string-format/src/decamelize.cjs +14 -1
  30. package/dist/packages/string-format/src/decamelize.mjs +13 -1
  31. package/dist/packages/string-format/src/decamelize.mjs.map +1 -1
  32. package/dist/packages/string-format/src/format-special-cases.cjs +33 -1
  33. package/dist/packages/string-format/src/format-special-cases.mjs +33 -1
  34. package/dist/packages/string-format/src/format-special-cases.mjs.map +1 -1
  35. package/dist/packages/string-format/src/lower-case-first.cjs +17 -1
  36. package/dist/packages/string-format/src/lower-case-first.mjs +16 -1
  37. package/dist/packages/string-format/src/lower-case-first.mjs.map +1 -1
  38. package/dist/packages/string-format/src/prepositions.cjs +68 -1
  39. package/dist/packages/string-format/src/prepositions.mjs +67 -1
  40. package/dist/packages/string-format/src/prepositions.mjs.map +1 -1
  41. package/dist/packages/string-format/src/special-cases.cjs +53 -1
  42. package/dist/packages/string-format/src/special-cases.mjs +52 -1
  43. package/dist/packages/string-format/src/special-cases.mjs.map +1 -1
  44. package/dist/packages/string-format/src/title-case.cjs +19 -1
  45. package/dist/packages/string-format/src/title-case.mjs +19 -1
  46. package/dist/packages/string-format/src/title-case.mjs.map +1 -1
  47. package/dist/packages/string-format/src/upper-case-first.cjs +17 -1
  48. package/dist/packages/string-format/src/upper-case-first.mjs +16 -1
  49. package/dist/packages/string-format/src/upper-case-first.mjs.map +1 -1
  50. package/dist/prisma-generator.cjs +185 -8
  51. package/dist/prisma-generator.mjs +184 -8
  52. package/dist/prisma-generator.mjs.map +1 -1
  53. package/dist/project.cjs +15 -1
  54. package/dist/project.mjs +14 -1
  55. package/dist/project.mjs.map +1 -1
  56. package/dist/utils/format-file.cjs +25 -1
  57. package/dist/utils/format-file.mjs +23 -1
  58. package/dist/utils/format-file.mjs.map +1 -1
  59. package/dist/utils/get-jiti.cjs +21 -1
  60. package/dist/utils/get-jiti.mjs +20 -1
  61. package/dist/utils/get-jiti.mjs.map +1 -1
  62. package/dist/utils/get-prisma-internals.cjs +13 -1
  63. package/dist/utils/get-prisma-internals.mjs +12 -1
  64. package/dist/utils/get-prisma-internals.mjs.map +1 -1
  65. package/dist/utils/write-file-safely.cjs +32 -2
  66. package/dist/utils/write-file-safely.mjs +29 -2
  67. package/dist/utils/write-file-safely.mjs.map +1 -1
  68. package/dist/zod/aggregate-helpers.cjs +70 -1
  69. package/dist/zod/aggregate-helpers.mjs +67 -1
  70. package/dist/zod/aggregate-helpers.mjs.map +1 -1
  71. package/dist/zod/comments-helpers.cjs +77 -1
  72. package/dist/zod/comments-helpers.mjs +75 -1
  73. package/dist/zod/comments-helpers.mjs.map +1 -1
  74. package/dist/zod/docs-helpers.cjs +23 -3
  75. package/dist/zod/docs-helpers.mjs +20 -3
  76. package/dist/zod/docs-helpers.mjs.map +1 -1
  77. package/dist/zod/generator-helpers.cjs +34 -1
  78. package/dist/zod/generator-helpers.mjs +31 -1
  79. package/dist/zod/generator-helpers.mjs.map +1 -1
  80. package/dist/zod/helpers.cjs +26 -1
  81. package/dist/zod/helpers.mjs +26 -1
  82. package/dist/zod/helpers.mjs.map +1 -1
  83. package/dist/zod/include-helpers.cjs +69 -1
  84. package/dist/zod/include-helpers.mjs +69 -1
  85. package/dist/zod/include-helpers.mjs.map +1 -1
  86. package/dist/zod/model-helpers.cjs +244 -1
  87. package/dist/zod/model-helpers.mjs +236 -1
  88. package/dist/zod/model-helpers.mjs.map +1 -1
  89. package/dist/zod/modelArgs-helpers.cjs +56 -1
  90. package/dist/zod/modelArgs-helpers.mjs +56 -1
  91. package/dist/zod/modelArgs-helpers.mjs.map +1 -1
  92. package/dist/zod/mongodb-helpers.cjs +49 -1
  93. package/dist/zod/mongodb-helpers.mjs +48 -1
  94. package/dist/zod/mongodb-helpers.mjs.map +1 -1
  95. package/dist/zod/select-helpers.cjs +128 -1
  96. package/dist/zod/select-helpers.mjs +128 -1
  97. package/dist/zod/select-helpers.mjs.map +1 -1
  98. package/dist/zod/transformer.cjs +434 -19
  99. package/dist/zod/transformer.mjs +432 -19
  100. package/dist/zod/transformer.mjs.map +1 -1
  101. package/dist/zod/whereUniqueInput-helpers.cjs +17 -1
  102. package/dist/zod/whereUniqueInput-helpers.mjs +16 -1
  103. package/dist/zod/whereUniqueInput-helpers.mjs.map +1 -1
  104. package/package.json +4 -4
@@ -1,22 +1,435 @@
1
- import{lowerCaseFirst as e}from"../packages/string-format/src/lower-case-first.mjs";import{upperCaseFirst as t}from"../packages/string-format/src/upper-case-first.mjs";import{checkModelHasModelRelation as n,findModelByName as r}from"./model-helpers.mjs";import{writeFileSafely as i,writeIndexFile as a}from"../utils/write-file-safely.mjs";import{isAggregateInputType as o}from"./aggregate-helpers.mjs";import{isMongodbRawOp as s}from"./mongodb-helpers.mjs";import c from"node:path";var l=class l{name;fields;schemaImports=new Set;models;modelOperations;aggregateOperationSupport;enumTypes;static enumNames=[];static rawOpsMap={};static provider;static previewFeatures;static outputPath=`./generated`;hasJson=!1;static prismaClientOutputPath=`@prisma/client`;static isCustomPrismaClientOutputPath=!1;static isGenerateSelect=!0;static isGenerateInclude=!0;constructor(e){this.name=e.name??``,this.fields=e.fields??[],this.models=e.models??[],this.modelOperations=e.modelOperations??[],this.aggregateOperationSupport=e.aggregateOperationSupport??{},this.enumTypes=e.enumTypes??[]}static setOutputPath(e){this.outputPath=e}static setIsGenerateSelect(e){this.isGenerateSelect=e}static setIsGenerateInclude(e){this.isGenerateInclude=e}static getOutputPath(){return this.outputPath}static setPrismaClientOutputPath(e){this.prismaClientOutputPath=e,this.isCustomPrismaClientOutputPath=e!==`@prisma/client`}static async generateIndex(){await a(c.join(l.outputPath,`schemas/index.ts`))}async generateEnumSchemas(){for(let t of this.enumTypes){let{name:n,values:r}=t;await i(c.join(l.outputPath,`schemas/enums/${e(n)}.schema.ts`),`${this.generateImportZodStatement()}\n${this.generateExportSchemaStatement(`${e(n)}`,`z.enum(${JSON.stringify(r)})`)}`)}}generateImportZodStatement(){return`import { z } from 'zod';
2
- `}generateExportSchemaStatement(t,n){return`export const ${e(t)}Schema = ${n}`}async generateObjectSchema(){let t=this.generateObjectSchemaFields(),n=this.prepareObjectSchema(t),r=this.resolveObjectSchemaName();await i(c.join(l.outputPath,`schemas/objects/${e(r)}.schema.ts`),n)}generateObjectSchemaFields(){return this.fields.map(e=>this.generateObjectSchemaField(e)).flatMap(e=>e).map(e=>{let[t,n,r]=e;return(r?t:this.generateFieldValidators(t,n)).trim()})}generateObjectSchemaField(e){let t=e.inputTypes;if(t.length===0)return[];let n=t.reduce((n,r)=>{if(r.type===`String`)n.push(this.wrapWithZodValidators(`z.string()`,e));else if(r.type===`Int`||r.type===`Float`||r.type===`Decimal`)n.push(this.wrapWithZodValidators(`z.number()`,e));else if(r.type===`BigInt`)n.push(this.wrapWithZodValidators(`z.bigint()`,e));else if(r.type===`Boolean`)n.push(this.wrapWithZodValidators(`z.boolean()`,e));else if(r.type===`DateTime`)n.push(this.wrapWithZodValidators(`z.coerce.date()`,e));else if(r.type===`Json`)this.hasJson=!0,n.push(this.wrapWithZodValidators(`jsonSchema`,e));else if(r.type===`True`)n.push(this.wrapWithZodValidators(`z.literal(true)`,e));else if(r.type===`Bytes`)n.push(this.wrapWithZodValidators(`z.instanceof(Buffer)`,e));else if(!r.type.endsWith(`FieldRefInput`)){let i=r.location===`enumTypes`;(r.namespace===`prisma`||i)&&(r.type!==this.name&&typeof r.type==`string`&&this.addSchemaImport(r.type),n.push(this.generatePrismaStringLine(e,r,t.length)))}return n},[]);if(n.length===0)return[];n.length>1&&(n=n.map(e=>e.replace(`.optional()`,``)));let r=n.some(e=>e.includes(`:`))?``:` ${e.name}:`,i=e.isRequired?``:`.optional()`,a=n.length===1?n.join(`,\r
3
- `):`z.union([${n.join(`,\r
4
- `)}])${i}`;return e.isNullable&&(a+=`.nullable()`),[[` ${r} ${a} `,e,!0]]}wrapWithZodValidators(e,t){let n=``;return n=e,t.inputTypes.some(e=>e.isList)&&(n+=`.array()`),t.isRequired||(n+=`.optional()`),n}addSchemaImport(e){this.schemaImports.add(e)}generatePrismaStringLine(t,n,r){let i=n.location===`enumTypes`,a=n.type,{isModelQueryType:o,modelName:s,queryName:c}=this.checkIsModelQueryType(a),l=o?this.resolveModelQuerySchemaName(s,c):`${a}ObjectSchema`,u=`${a}Schema`,d=n.type===this.name?l:i?u:l,f=n.isList?`.array()`:``,p=t.isRequired?``:`.optional()`;return r===1?` ${t.name}: z.lazy(() => ${e(d)})${f}${p}`:`z.lazy(() => ${e(d)})${f}${p}`}generateFieldValidators(e,t){let{isRequired:n,isNullable:r}=t;return n||(e+=`.optional()`),r&&(e+=`.nullable()`),e}prepareObjectSchema(e){let t=`${this.generateExportObjectSchemaStatement(this.addFinalWrappers({zodStringFields:e}))}\n`,n=this.generateImportPrismaStatement(),r=this.generateJsonSchemaImplementation();return`${this.generateObjectSchemaImportStatements()}${n}${r}${t}`}generateExportObjectSchemaStatement(t){let n=this.name,r=this.name;l.provider===`mongodb`&&s(n)&&(n=l.rawOpsMap[n],r=n.replace(`Args`,``)),o(n)&&(n=`${n}Type`);let i=`export const ${e(r)}ObjectSchema = schema`;return`const schema: z.ZodType<Prisma.${n}> = ${t};\n\n ${i}`}addFinalWrappers({zodStringFields:e}){let t=[...e];return`${this.wrapWithZodObject(t)}.strict()`}generateImportPrismaStatement(){let e;if(l.isCustomPrismaClientOutputPath){let t=c.join(l.outputPath,`schemas`,`objects`),n=l.prismaClientOutputPath;e=c.relative(t,n).split(c.sep).join(c.posix.sep)}else e=l.prismaClientOutputPath;return`import type { Prisma } from '${e}';\n\n`}generateJsonSchemaImplementation(){let e=``;return this.hasJson&&(e+=`
5
- `,e+=`const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
6
- `,e+=`const jsonSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
7
- `,e+=` z.union([literalSchema, z.array(jsonSchema.nullable()), z.record(jsonSchema.nullable())])
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
- `),e}generateObjectSchemaImportStatements(){let e=this.generateImportZodStatement();return e+=this.generateSchemaImports(),e+=`
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
- `,e}generateSchemaImports(){return[...this.schemaImports].map(t=>{let{isModelQueryType:n,modelName:r,queryName:i}=this.checkIsModelQueryType(t);return n?`import { ${this.resolveModelQuerySchemaName(r,i)} } from '../${i}${r}.schema'`:l.enumNames.includes(t)?`import { ${e(t)}Schema } from '../enums/${e(t)}.schema'`:`import { ${e(t)}ObjectSchema } from './${e(t)}.schema'`}).join(`;\r
13
- `)}checkIsModelQueryType(e){let t={FindManyArgs:`findMany`};for(let n of[`FindManyArgs`])if(e.includes(n)){let r=e.indexOf(n);return{isModelQueryType:!0,modelName:e.substring(0,r),queryName:t[n]}}return{isModelQueryType:!1}}resolveModelQuerySchemaName(n,r){return`${e(n)}${t(r)}Schema`}wrapWithZodUnion(e){let t=``;return t+=`z.union([`,t+=`
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