@stryke/prisma-trpc-generator 0.13.49 → 0.13.51

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