zenstack 1.0.0-beta.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/cli/actions/generate.d.ts +13 -0
- package/cli/actions/generate.js +71 -0
- package/cli/actions/generate.js.map +1 -0
- package/cli/actions/index.d.ts +3 -0
- package/cli/actions/index.js +20 -0
- package/cli/actions/index.js.map +1 -0
- package/cli/actions/info.d.ts +4 -0
- package/cli/actions/info.js +63 -0
- package/cli/actions/info.js.map +1 -0
- package/cli/actions/init.d.ts +12 -0
- package/cli/actions/init.js +83 -0
- package/cli/actions/init.js.map +1 -0
- package/cli/cli-util.d.ts +7 -10
- package/cli/cli-util.js +48 -130
- package/cli/cli-util.js.map +1 -1
- package/cli/config.d.ts +1 -10
- package/cli/config.js +2 -7
- package/cli/config.js.map +1 -1
- package/cli/index.d.ts +3 -12
- package/cli/index.js +12 -30
- package/cli/index.js.map +1 -1
- package/cli/plugin-runner.d.ts +11 -2
- package/cli/plugin-runner.js +66 -41
- package/cli/plugin-runner.js.map +1 -1
- package/language-server/utils.d.ts +1 -10
- package/language-server/utils.js +1 -20
- package/language-server/utils.js.map +1 -1
- package/language-server/validator/attribute-application-validator.d.ts +15 -0
- package/language-server/validator/attribute-application-validator.js +246 -0
- package/language-server/validator/attribute-application-validator.js.map +1 -0
- package/language-server/validator/attribute-validator.d.ts +1 -1
- package/language-server/validator/attribute-validator.js +4 -1
- package/language-server/validator/attribute-validator.js.map +1 -1
- package/language-server/validator/datamodel-validator.js +5 -6
- package/language-server/validator/datamodel-validator.js.map +1 -1
- package/language-server/validator/enum-validator.js +3 -6
- package/language-server/validator/enum-validator.js.map +1 -1
- package/language-server/validator/expression-validator.d.ts +0 -1
- package/language-server/validator/expression-validator.js +48 -7
- package/language-server/validator/expression-validator.js.map +1 -1
- package/language-server/validator/function-decl-validator.js +2 -4
- package/language-server/validator/function-decl-validator.js.map +1 -1
- package/language-server/validator/function-invocation-validator.js +5 -6
- package/language-server/validator/function-invocation-validator.js.map +1 -1
- package/language-server/validator/utils.d.ts +0 -1
- package/language-server/validator/utils.js +3 -119
- package/language-server/validator/utils.js.map +1 -1
- package/language-server/zmodel-linker.js +33 -25
- package/language-server/zmodel-linker.js.map +1 -1
- package/package.json +8 -5
- package/plugins/access-policy/expression-writer.d.ts +5 -0
- package/plugins/access-policy/expression-writer.js +123 -64
- package/plugins/access-policy/expression-writer.js.map +1 -1
- package/plugins/access-policy/index.d.ts +3 -3
- package/plugins/access-policy/index.js +3 -5
- package/plugins/access-policy/index.js.map +1 -1
- package/plugins/access-policy/policy-guard-generator.d.ts +10 -3
- package/plugins/access-policy/policy-guard-generator.js +321 -71
- package/plugins/access-policy/policy-guard-generator.js.map +1 -1
- package/plugins/model-meta/index.d.ts +3 -3
- package/plugins/model-meta/index.js +90 -34
- package/plugins/model-meta/index.js.map +1 -1
- package/plugins/plugin-utils.d.ts +5 -3
- package/plugins/plugin-utils.js +22 -5
- package/plugins/plugin-utils.js.map +1 -1
- package/plugins/prisma/index.d.ts +3 -4
- package/plugins/prisma/index.js +3 -5
- package/plugins/prisma/index.js.map +1 -1
- package/plugins/prisma/prisma-builder.d.ts +4 -14
- package/plugins/prisma/prisma-builder.js +16 -42
- package/plugins/prisma/prisma-builder.js.map +1 -1
- package/plugins/prisma/schema-generator.d.ts +5 -4
- package/plugins/prisma/schema-generator.js +77 -164
- package/plugins/prisma/schema-generator.js.map +1 -1
- package/plugins/prisma/zmodel-code-generator.js +4 -2
- package/plugins/prisma/zmodel-code-generator.js.map +1 -1
- package/plugins/zod/generator.d.ts +2 -2
- package/plugins/zod/generator.js +36 -33
- package/plugins/zod/generator.js.map +1 -1
- package/plugins/zod/index.d.ts +3 -4
- package/plugins/zod/index.js +8 -5
- package/plugins/zod/index.js.map +1 -1
- package/plugins/zod/transformer.d.ts +6 -5
- package/plugins/zod/transformer.js +123 -81
- package/plugins/zod/transformer.js.map +1 -1
- package/plugins/zod/types.d.ts +2 -1
- package/plugins/zod/utils/schema-gen.js +14 -4
- package/plugins/zod/utils/schema-gen.js.map +1 -1
- package/res/stdlib.zmodel +19 -3
- package/telemetry.js +1 -1
- package/telemetry.js.map +1 -1
- package/utils/ast-utils.d.ts +2 -1
- package/utils/ast-utils.js +7 -3
- package/utils/ast-utils.js.map +1 -1
- package/utils/typescript-expression-transformer.d.ts +3 -2
- package/utils/typescript-expression-transformer.js +48 -17
- package/utils/typescript-expression-transformer.js.map +1 -1
- package/utils/version-utils.js +7 -2
- package/utils/version-utils.js.map +1 -1
- package/plugins/access-policy/utils.d.ts +0 -5
- package/plugins/access-policy/utils.js +0 -14
- package/plugins/access-policy/utils.js.map +0 -1
- package/types.d.ts +0 -12
- package/types.js +0 -3
- package/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/plugins/zod/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/plugins/zod/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,yCAcyB;AACzB,6CAAiH;AACjH,+DAA4G;AAC5G,2BAAoC;AACpC,qCAA4C;AAC5C,gDAAwB;AAExB,uDAAkD;AAClD,kDAAyD;AACzD,gEAAwC;AACxC,kEAA0C;AAC1C,mDAAgF;AAEhF,SAAsB,QAAQ,CAC1B,KAAY,EACZ,OAAsB,EACtB,IAAmB,EACnB,aAAmC;;;QAEnC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAgB,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,mBAAmB,GAAG,IAAA,qCAAsB,EAAC,aAAa,CAAC,CAAC;YAClE,IAAI,mBAAmB,EAAE;gBACrB,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;aAClD;iBAAM;gBACH,MAAM,GAAG,iBAAiB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M;UACV,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;OAC7C,CAAC;AACR,CAAC;AAED,SAAS,QAAQ,CAAC,MAAc,EAAE,MAAgB;IAC9C,OAAO,GAAG,MAAM;UACV,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;OAC7C,CAAC;AACR,CAAC"}
|
package/plugins/zod/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PluginOptions } from '@zenstackhq/sdk';
|
|
3
|
-
import { Model } from '@zenstackhq/sdk/ast';
|
|
1
|
+
import { PluginFunction } from '@zenstackhq/sdk';
|
|
4
2
|
export declare const name = "Zod";
|
|
5
|
-
|
|
3
|
+
declare const run: PluginFunction;
|
|
4
|
+
export default run;
|
package/plugins/zod/index.js
CHANGED
|
@@ -8,14 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.name = void 0;
|
|
16
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
13
17
|
const generator_1 = require("./generator");
|
|
14
18
|
exports.name = 'Zod';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
19
|
+
const run = (model, options, dmmf, globalOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
(0, tiny_invariant_1.default)(dmmf);
|
|
21
|
+
return (0, generator_1.generate)(model, options, dmmf, globalOptions);
|
|
22
|
+
});
|
|
20
23
|
exports.default = run;
|
|
21
24
|
//# sourceMappingURL=index.js.map
|
package/plugins/zod/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/zod/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/zod/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,oEAAuC;AACvC,2CAAuC;AAE1B,QAAA,IAAI,GAAG,KAAK,CAAC;AAE1B,MAAM,GAAG,GAAmB,CAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE;IACtE,IAAA,wBAAS,EAAC,IAAI,CAAC,CAAC;IAChB,OAAO,IAAA,oBAAQ,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AACzD,CAAC,CAAA,CAAC;AAEF,kBAAe,GAAG,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { DMMF as PrismaDMMF } from '@prisma/generator-helper';
|
|
|
2
2
|
import { AggregateOperationSupport, TransformerParams } from './types';
|
|
3
3
|
export default class Transformer {
|
|
4
4
|
name: string;
|
|
5
|
+
originalName: string;
|
|
5
6
|
fields: PrismaDMMF.SchemaArg[];
|
|
6
7
|
schemaImports: Set<string>;
|
|
7
8
|
models: PrismaDMMF.Model[];
|
|
@@ -18,15 +19,16 @@ export default class Transformer {
|
|
|
18
19
|
private hasDecimal;
|
|
19
20
|
private project;
|
|
20
21
|
private zmodel;
|
|
22
|
+
private inputObjectTypes;
|
|
21
23
|
constructor(params: TransformerParams);
|
|
22
24
|
static setOutputPath(outPath: string): void;
|
|
23
25
|
static getOutputPath(): string;
|
|
24
26
|
generateEnumSchemas(): Promise<void>;
|
|
25
27
|
generateImportZodStatement(): string;
|
|
26
28
|
generateExportSchemaStatement(name: string, schema: string): string;
|
|
27
|
-
generateObjectSchema(): string;
|
|
28
|
-
generateObjectSchemaFields(): string[];
|
|
29
|
-
generateObjectSchemaField(field: PrismaDMMF.SchemaArg): [string, PrismaDMMF.SchemaArg, boolean][];
|
|
29
|
+
generateObjectSchema(generateUnchecked: boolean): string;
|
|
30
|
+
generateObjectSchemaFields(generateUnchecked: boolean): string[];
|
|
31
|
+
generateObjectSchemaField(field: PrismaDMMF.SchemaArg, generateUnchecked: boolean): [string, PrismaDMMF.SchemaArg, boolean][];
|
|
30
32
|
wrapWithZodValidators(mainValidators: string | string[], field: PrismaDMMF.SchemaArg, inputType: PrismaDMMF.SchemaArgInputType): string;
|
|
31
33
|
addSchemaImport(name: string): void;
|
|
32
34
|
generatePrismaStringLine(field: PrismaDMMF.SchemaArg, inputType: PrismaDMMF.SchemaArgInputType, inputsLength: number): string;
|
|
@@ -53,8 +55,7 @@ export default class Transformer {
|
|
|
53
55
|
resolveModelQuerySchemaName(modelName: string, queryName: string): string;
|
|
54
56
|
wrapWithZodUnion(zodStringFields: string[]): string;
|
|
55
57
|
wrapWithZodObject(zodStringFields: string | string[]): string;
|
|
56
|
-
|
|
57
|
-
generateInputSchemas(): Promise<void>;
|
|
58
|
+
generateInputSchemas(generateUnchecked: boolean): Promise<void>;
|
|
58
59
|
generateImportStatements(imports: (string | undefined)[]): string;
|
|
59
60
|
resolveSelectIncludeImportAndZodSchemaLine(model: PrismaDMMF.Model): {
|
|
60
61
|
selectImport: string;
|
|
@@ -37,17 +37,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const sdk_1 = require("@zenstackhq/sdk");
|
|
39
39
|
const dmmf_helpers_1 = require("@zenstackhq/sdk/dmmf-helpers");
|
|
40
|
-
const utils_1 =
|
|
40
|
+
const utils_1 = require("@zenstackhq/sdk/utils");
|
|
41
41
|
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const upper_case_first_1 = require("upper-case-first");
|
|
43
42
|
const semver = __importStar(require("semver"));
|
|
43
|
+
const upper_case_first_1 = require("upper-case-first");
|
|
44
44
|
class Transformer {
|
|
45
45
|
constructor(params) {
|
|
46
46
|
var _a, _b, _c, _d, _e, _f;
|
|
47
47
|
this.schemaImports = new Set();
|
|
48
48
|
this.hasJson = false;
|
|
49
49
|
this.hasDecimal = false;
|
|
50
|
-
this.
|
|
50
|
+
this.originalName = (_a = params.name) !== null && _a !== void 0 ? _a : '';
|
|
51
|
+
this.name = params.name ? (0, upper_case_first_1.upperCaseFirst)(params.name) : '';
|
|
51
52
|
this.fields = (_b = params.fields) !== null && _b !== void 0 ? _b : [];
|
|
52
53
|
this.models = (_c = params.models) !== null && _c !== void 0 ? _c : [];
|
|
53
54
|
this.modelOperations = (_d = params.modelOperations) !== null && _d !== void 0 ? _d : [];
|
|
@@ -55,6 +56,7 @@ class Transformer {
|
|
|
55
56
|
this.enumTypes = (_f = params.enumTypes) !== null && _f !== void 0 ? _f : [];
|
|
56
57
|
this.project = params.project;
|
|
57
58
|
this.zmodel = params.zmodel;
|
|
59
|
+
this.inputObjectTypes = params.inputObjectTypes;
|
|
58
60
|
}
|
|
59
61
|
static setOutputPath(outPath) {
|
|
60
62
|
this.outputPath = outPath;
|
|
@@ -65,13 +67,12 @@ class Transformer {
|
|
|
65
67
|
generateEnumSchemas() {
|
|
66
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
69
|
for (const enumType of this.enumTypes) {
|
|
68
|
-
const
|
|
69
|
-
const filteredValues = values.filter((v) => !sdk_1.AUXILIARY_FIELDS.includes(v));
|
|
70
|
+
const name = (0, upper_case_first_1.upperCaseFirst)(enumType.name);
|
|
70
71
|
const filePath = path_1.default.join(Transformer.outputPath, `enums/${name}.schema.ts`);
|
|
71
|
-
const content = `/* eslint-disable */\n${this.generateImportZodStatement()}\n${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(
|
|
72
|
+
const content = `/* eslint-disable */\n${this.generateImportZodStatement()}\n${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(enumType.values)})`)}`;
|
|
72
73
|
this.project.createSourceFile(filePath, content, { overwrite: true });
|
|
73
74
|
}
|
|
74
|
-
this.project.createSourceFile(path_1.default.join(Transformer.outputPath, `enums/index.ts`), this.enumTypes.map((enumType) => `export * from './${enumType.name}.schema';`).join('\n'), { overwrite: true });
|
|
75
|
+
this.project.createSourceFile(path_1.default.join(Transformer.outputPath, `enums/index.ts`), this.enumTypes.map((enumType) => `export * from './${(0, upper_case_first_1.upperCaseFirst)(enumType.name)}.schema';`).join('\n'), { overwrite: true });
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
generateImportZodStatement() {
|
|
@@ -80,19 +81,17 @@ class Transformer {
|
|
|
80
81
|
generateExportSchemaStatement(name, schema) {
|
|
81
82
|
return `export const ${name}Schema = ${schema}`;
|
|
82
83
|
}
|
|
83
|
-
generateObjectSchema() {
|
|
84
|
-
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
84
|
+
generateObjectSchema(generateUnchecked) {
|
|
85
|
+
const zodObjectSchemaFields = this.generateObjectSchemaFields(generateUnchecked);
|
|
85
86
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
86
|
-
const
|
|
87
|
-
const filePath = path_1.default.join(Transformer.outputPath, `objects/${objectSchemaName}.schema.ts`);
|
|
87
|
+
const filePath = path_1.default.join(Transformer.outputPath, `objects/${this.name}.schema.ts`);
|
|
88
88
|
const content = '/* eslint-disable */\n' + objectSchema;
|
|
89
89
|
this.project.createSourceFile(filePath, content, { overwrite: true });
|
|
90
|
-
return `${
|
|
90
|
+
return `${this.name}.schema`;
|
|
91
91
|
}
|
|
92
|
-
generateObjectSchemaFields() {
|
|
92
|
+
generateObjectSchemaFields(generateUnchecked) {
|
|
93
93
|
const zodObjectSchemaFields = this.fields
|
|
94
|
-
.
|
|
95
|
-
.map((field) => this.generateObjectSchemaField(field))
|
|
94
|
+
.map((field) => this.generateObjectSchemaField(field, generateUnchecked))
|
|
96
95
|
.flatMap((item) => item)
|
|
97
96
|
.map((item) => {
|
|
98
97
|
const [zodStringWithMainType, field, skipValidators] = item;
|
|
@@ -103,12 +102,15 @@ class Transformer {
|
|
|
103
102
|
});
|
|
104
103
|
return zodObjectSchemaFields;
|
|
105
104
|
}
|
|
106
|
-
generateObjectSchemaField(field) {
|
|
105
|
+
generateObjectSchemaField(field, generateUnchecked) {
|
|
107
106
|
const lines = field.inputTypes;
|
|
108
107
|
if (lines.length === 0) {
|
|
109
108
|
return [];
|
|
110
109
|
}
|
|
111
110
|
let alternatives = lines.reduce((result, inputType) => {
|
|
111
|
+
if (!generateUnchecked && typeof inputType.type === 'string' && inputType.type.includes('Unchecked')) {
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
112
114
|
if (inputType.type === 'String') {
|
|
113
115
|
result.push(this.wrapWithZodValidators('z.string()', field, inputType));
|
|
114
116
|
}
|
|
@@ -148,7 +150,7 @@ class Transformer {
|
|
|
148
150
|
// fieldRefTypes refer to other fields in the model and don't need to be generated as part of schema
|
|
149
151
|
!isFieldRef &&
|
|
150
152
|
('prisma' || isEnum)) {
|
|
151
|
-
if (inputType.type !== this.
|
|
153
|
+
if (inputType.type !== this.originalName && typeof inputType.type === 'string') {
|
|
152
154
|
this.addSchemaImport(inputType.type);
|
|
153
155
|
}
|
|
154
156
|
result.push(this.generatePrismaStringLine(field, inputType, lines.length));
|
|
@@ -191,7 +193,7 @@ class Transformer {
|
|
|
191
193
|
return line;
|
|
192
194
|
}
|
|
193
195
|
addSchemaImport(name) {
|
|
194
|
-
this.schemaImports.add(name);
|
|
196
|
+
this.schemaImports.add((0, upper_case_first_1.upperCaseFirst)(name));
|
|
195
197
|
}
|
|
196
198
|
generatePrismaStringLine(field, inputType, inputsLength) {
|
|
197
199
|
const isEnum = inputType.location === 'enumTypes';
|
|
@@ -199,8 +201,8 @@ class Transformer {
|
|
|
199
201
|
const objectSchemaLine = isModelQueryType
|
|
200
202
|
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
201
203
|
this.resolveModelQuerySchemaName(modelName, queryName)
|
|
202
|
-
: `${inputType.type}ObjectSchema`;
|
|
203
|
-
const enumSchemaLine = `${inputType.type}Schema`;
|
|
204
|
+
: `${(0, upper_case_first_1.upperCaseFirst)(inputType.type.toString())}ObjectSchema`;
|
|
205
|
+
const enumSchemaLine = `${(0, upper_case_first_1.upperCaseFirst)(inputType.type.toString())}Schema`;
|
|
204
206
|
const schema = inputType.type === this.name ? objectSchemaLine : isEnum ? enumSchemaLine : objectSchemaLine;
|
|
205
207
|
const arr = inputType.isList ? '.array()' : '';
|
|
206
208
|
const opt = !field.isRequired ? '.optional()' : '';
|
|
@@ -226,10 +228,12 @@ class Transformer {
|
|
|
226
228
|
}
|
|
227
229
|
generateExportObjectSchemaStatement(schema) {
|
|
228
230
|
let name = this.name;
|
|
231
|
+
let origName = this.originalName;
|
|
229
232
|
if ((0, dmmf_helpers_1.isAggregateInputType)(name)) {
|
|
230
233
|
name = `${name}Type`;
|
|
234
|
+
origName = `${origName}Type`;
|
|
231
235
|
}
|
|
232
|
-
const outType = `z.ZodType<
|
|
236
|
+
const outType = `z.ZodType<Prisma.${origName}>`;
|
|
233
237
|
return `type SchemaType = ${outType};
|
|
234
238
|
export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
235
239
|
}
|
|
@@ -276,11 +280,13 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
276
280
|
.join('\n');
|
|
277
281
|
}
|
|
278
282
|
generateCommonImport() {
|
|
279
|
-
let r =
|
|
283
|
+
let r = '';
|
|
280
284
|
if (this.hasDecimal) {
|
|
281
285
|
r += `import { DecimalSchema } from '../common';\n`;
|
|
282
286
|
}
|
|
283
|
-
r
|
|
287
|
+
if (r) {
|
|
288
|
+
r += '\n';
|
|
289
|
+
}
|
|
284
290
|
return r;
|
|
285
291
|
}
|
|
286
292
|
checkIsModelQueryType(type) {
|
|
@@ -292,7 +298,7 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
292
298
|
const modelQueryTypeSuffixIndex = type.indexOf(modelQueryType);
|
|
293
299
|
return {
|
|
294
300
|
isModelQueryType: true,
|
|
295
|
-
modelName: type.substring(0, modelQueryTypeSuffixIndex),
|
|
301
|
+
modelName: (0, upper_case_first_1.upperCaseFirst)(type.substring(0, modelQueryTypeSuffixIndex)),
|
|
296
302
|
queryName: modelQueryTypeSuffixToQueryName[modelQueryType],
|
|
297
303
|
};
|
|
298
304
|
}
|
|
@@ -300,8 +306,7 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
300
306
|
return { isModelQueryType: false };
|
|
301
307
|
}
|
|
302
308
|
resolveModelQuerySchemaName(modelName, queryName) {
|
|
303
|
-
|
|
304
|
-
return `${modelNameCapitalized}InputSchema.${queryName}`;
|
|
309
|
+
return `${modelName}InputSchema.${queryName}`;
|
|
305
310
|
}
|
|
306
311
|
wrapWithZodUnion(zodStringFields) {
|
|
307
312
|
let wrapped = '';
|
|
@@ -321,15 +326,12 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
321
326
|
wrapped += '})';
|
|
322
327
|
return wrapped;
|
|
323
328
|
}
|
|
324
|
-
|
|
325
|
-
return this.name;
|
|
326
|
-
}
|
|
327
|
-
generateInputSchemas() {
|
|
329
|
+
generateInputSchemas(generateUnchecked) {
|
|
328
330
|
var _a, _b, _c, _d, _e;
|
|
329
331
|
return __awaiter(this, void 0, void 0, function* () {
|
|
330
332
|
const globalExports = [];
|
|
331
333
|
for (const modelOperation of this.modelOperations) {
|
|
332
|
-
const { model:
|
|
334
|
+
const { model: origModelName, findUnique, findFirst, findMany,
|
|
333
335
|
// @ts-expect-error
|
|
334
336
|
createOne, createMany,
|
|
335
337
|
// @ts-expect-error
|
|
@@ -340,9 +342,10 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
340
342
|
upsertOne, aggregate, groupBy,
|
|
341
343
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
342
344
|
} = modelOperation;
|
|
345
|
+
const modelName = (0, upper_case_first_1.upperCaseFirst)(origModelName);
|
|
343
346
|
globalExports.push(`export * from './${modelName}Input.schema'`);
|
|
344
347
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
345
|
-
const model = (0, dmmf_helpers_1.findModelByName)(this.models,
|
|
348
|
+
const model = (0, dmmf_helpers_1.findModelByName)(this.models, origModelName);
|
|
346
349
|
const { selectImport, includeImport, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
347
350
|
let imports = [
|
|
348
351
|
`import { z } from 'zod'`,
|
|
@@ -352,97 +355,135 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
352
355
|
];
|
|
353
356
|
let codeBody = '';
|
|
354
357
|
const operations = [];
|
|
358
|
+
// OrderByWithRelationInput's name is different when "fullTextSearch" is enabled
|
|
359
|
+
const orderByWithRelationInput = this.inputObjectTypes
|
|
360
|
+
.map((o) => (0, upper_case_first_1.upperCaseFirst)(o.name))
|
|
361
|
+
.includes(`${modelName}OrderByWithRelationInput`)
|
|
362
|
+
? `${modelName}OrderByWithRelationInput`
|
|
363
|
+
: `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
|
|
355
364
|
if (findUnique) {
|
|
356
365
|
imports.push(`import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`);
|
|
357
366
|
codeBody += `findUnique: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereUniqueInputObjectSchema }),`;
|
|
358
|
-
operations.push(['findUnique',
|
|
367
|
+
operations.push(['findUnique', origModelName]);
|
|
359
368
|
}
|
|
360
369
|
if (findFirst) {
|
|
361
|
-
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${
|
|
362
|
-
codeBody += `findFirst: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${
|
|
363
|
-
operations.push(['findFirst',
|
|
370
|
+
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${orderByWithRelationInput}ObjectSchema } from '../objects/${orderByWithRelationInput}.schema'`, `import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`, `import { ${modelName}ScalarFieldEnumSchema } from '../enums/${modelName}ScalarFieldEnum.schema'`);
|
|
371
|
+
codeBody += `findFirst: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${orderByWithRelationInput}ObjectSchema, ${orderByWithRelationInput}ObjectSchema.array()]).optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() }),`;
|
|
372
|
+
operations.push(['findFirst', origModelName]);
|
|
364
373
|
}
|
|
365
374
|
if (findMany) {
|
|
366
|
-
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${
|
|
367
|
-
codeBody += `findMany: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${
|
|
368
|
-
operations.push(['findMany',
|
|
375
|
+
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${orderByWithRelationInput}ObjectSchema } from '../objects/${orderByWithRelationInput}.schema'`, `import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`, `import { ${modelName}ScalarFieldEnumSchema } from '../enums/${modelName}ScalarFieldEnum.schema'`);
|
|
376
|
+
codeBody += `findMany: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${orderByWithRelationInput}ObjectSchema, ${orderByWithRelationInput}ObjectSchema.array()]).optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() }),`;
|
|
377
|
+
operations.push(['findMany', origModelName]);
|
|
369
378
|
}
|
|
370
379
|
if (createOne) {
|
|
371
|
-
imports.push(`import { ${modelName}CreateInputObjectSchema } from '../objects/${modelName}CreateInput.schema'
|
|
372
|
-
|
|
373
|
-
|
|
380
|
+
imports.push(`import { ${modelName}CreateInputObjectSchema } from '../objects/${modelName}CreateInput.schema'`);
|
|
381
|
+
if (generateUnchecked) {
|
|
382
|
+
imports.push(`import { ${modelName}UncheckedCreateInputObjectSchema } from '../objects/${modelName}UncheckedCreateInput.schema'`);
|
|
383
|
+
}
|
|
384
|
+
const dataSchema = generateUnchecked
|
|
385
|
+
? `z.union([${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema])`
|
|
386
|
+
: `${modelName}CreateInputObjectSchema`;
|
|
387
|
+
codeBody += `create: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} data: ${dataSchema} }),`;
|
|
388
|
+
operations.push(['create', origModelName]);
|
|
374
389
|
}
|
|
375
390
|
if (createMany) {
|
|
376
391
|
imports.push(`import { ${modelName}CreateManyInputObjectSchema } from '../objects/${modelName}CreateManyInput.schema'`);
|
|
377
392
|
codeBody += `createMany: z.object({ data: z.union([${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema)]) }),`;
|
|
378
|
-
operations.push(['createMany',
|
|
393
|
+
operations.push(['createMany', origModelName]);
|
|
379
394
|
}
|
|
380
395
|
if (deleteOne) {
|
|
381
396
|
imports.push(`import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`);
|
|
382
397
|
codeBody += `'delete': z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereUniqueInputObjectSchema }),`;
|
|
383
|
-
operations.push(['delete',
|
|
398
|
+
operations.push(['delete', origModelName]);
|
|
384
399
|
}
|
|
385
400
|
if (deleteMany) {
|
|
386
401
|
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`);
|
|
387
402
|
codeBody += `deleteMany: z.object({ where: ${modelName}WhereInputObjectSchema.optional() }),`;
|
|
388
|
-
operations.push(['deleteMany',
|
|
403
|
+
operations.push(['deleteMany', origModelName]);
|
|
389
404
|
}
|
|
390
405
|
if (updateOne) {
|
|
391
|
-
imports.push(`import { ${modelName}UpdateInputObjectSchema } from '../objects/${modelName}UpdateInput.schema'`, `import { ${modelName}
|
|
392
|
-
|
|
393
|
-
|
|
406
|
+
imports.push(`import { ${modelName}UpdateInputObjectSchema } from '../objects/${modelName}UpdateInput.schema'`, `import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`);
|
|
407
|
+
if (generateUnchecked) {
|
|
408
|
+
imports.push(`import { ${modelName}UncheckedUpdateInputObjectSchema } from '../objects/${modelName}UncheckedUpdateInput.schema'`);
|
|
409
|
+
}
|
|
410
|
+
const dataSchema = generateUnchecked
|
|
411
|
+
? `z.union([${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema])`
|
|
412
|
+
: `${modelName}UpdateInputObjectSchema`;
|
|
413
|
+
codeBody += `update: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} data: ${dataSchema}, where: ${modelName}WhereUniqueInputObjectSchema }),`;
|
|
414
|
+
operations.push(['update', origModelName]);
|
|
394
415
|
}
|
|
395
416
|
if (updateMany) {
|
|
396
|
-
imports.push(`import { ${modelName}UpdateManyMutationInputObjectSchema } from '../objects/${modelName}UpdateManyMutationInput.schema'`, `import { ${modelName}
|
|
397
|
-
|
|
398
|
-
|
|
417
|
+
imports.push(`import { ${modelName}UpdateManyMutationInputObjectSchema } from '../objects/${modelName}UpdateManyMutationInput.schema'`, `import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`);
|
|
418
|
+
if (generateUnchecked) {
|
|
419
|
+
imports.push(`import { ${modelName}UncheckedUpdateManyInputObjectSchema } from '../objects/${modelName}UncheckedUpdateManyInput.schema'`);
|
|
420
|
+
}
|
|
421
|
+
const dataSchema = generateUnchecked
|
|
422
|
+
? `z.union([${modelName}UpdateManyMutationInputObjectSchema, ${modelName}UncheckedUpdateManyInputObjectSchema])`
|
|
423
|
+
: `${modelName}UpdateManyMutationInputObjectSchema`;
|
|
424
|
+
codeBody += `updateMany: z.object({ data: ${dataSchema}, where: ${modelName}WhereInputObjectSchema.optional() }),`;
|
|
425
|
+
operations.push(['updateMany', origModelName]);
|
|
399
426
|
}
|
|
400
427
|
if (upsertOne) {
|
|
401
|
-
imports.push(`import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`, `import { ${modelName}CreateInputObjectSchema } from '../objects/${modelName}CreateInput.schema'`, `import { ${modelName}
|
|
402
|
-
|
|
403
|
-
|
|
428
|
+
imports.push(`import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`, `import { ${modelName}CreateInputObjectSchema } from '../objects/${modelName}CreateInput.schema'`, `import { ${modelName}UpdateInputObjectSchema } from '../objects/${modelName}UpdateInput.schema'`);
|
|
429
|
+
if (generateUnchecked) {
|
|
430
|
+
imports.push(`import { ${modelName}UncheckedCreateInputObjectSchema } from '../objects/${modelName}UncheckedCreateInput.schema'`, `import { ${modelName}UncheckedUpdateInputObjectSchema } from '../objects/${modelName}UncheckedUpdateInput.schema'`);
|
|
431
|
+
}
|
|
432
|
+
const createSchema = generateUnchecked
|
|
433
|
+
? `z.union([${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema])`
|
|
434
|
+
: `${modelName}CreateInputObjectSchema`;
|
|
435
|
+
const updateSchema = generateUnchecked
|
|
436
|
+
? `z.union([${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema])`
|
|
437
|
+
: `${modelName}UpdateInputObjectSchema`;
|
|
438
|
+
codeBody += `upsert: z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} where: ${modelName}WhereUniqueInputObjectSchema, create: ${createSchema}, update: ${updateSchema} }),`;
|
|
439
|
+
operations.push(['upsert', origModelName]);
|
|
404
440
|
}
|
|
405
441
|
const aggregateOperations = [];
|
|
406
442
|
// DMMF messed up the model name casing used in the aggregate operations,
|
|
407
443
|
// AND the casing behavior varies from version to version -_-||
|
|
408
|
-
const modelNameCap = (0, upper_case_first_1.upperCaseFirst)(modelName);
|
|
409
444
|
const prismaVersion = (0, sdk_1.getPrismaVersion)();
|
|
410
|
-
if ((_a = this.aggregateOperationSupport[
|
|
411
|
-
imports.push(`import { ${
|
|
412
|
-
aggregateOperations.push(`_count: z.union([ z.literal(true), ${
|
|
445
|
+
if ((_a = this.aggregateOperationSupport[modelName]) === null || _a === void 0 ? void 0 : _a.count) {
|
|
446
|
+
imports.push(`import { ${modelName}CountAggregateInputObjectSchema } from '../objects/${modelName}CountAggregateInput.schema'`);
|
|
447
|
+
aggregateOperations.push(`_count: z.union([ z.literal(true), ${modelName}CountAggregateInputObjectSchema ]).optional()`);
|
|
413
448
|
}
|
|
414
|
-
if ((_b = this.aggregateOperationSupport[
|
|
415
|
-
imports.push(`import { ${
|
|
416
|
-
aggregateOperations.push(`_min: ${
|
|
449
|
+
if ((_b = this.aggregateOperationSupport[modelName]) === null || _b === void 0 ? void 0 : _b.min) {
|
|
450
|
+
imports.push(`import { ${modelName}MinAggregateInputObjectSchema } from '../objects/${modelName}MinAggregateInput.schema'`);
|
|
451
|
+
aggregateOperations.push(`_min: ${modelName}MinAggregateInputObjectSchema.optional()`);
|
|
417
452
|
}
|
|
418
|
-
if ((_c = this.aggregateOperationSupport[
|
|
419
|
-
imports.push(`import { ${
|
|
420
|
-
aggregateOperations.push(`_max: ${
|
|
453
|
+
if ((_c = this.aggregateOperationSupport[modelName]) === null || _c === void 0 ? void 0 : _c.max) {
|
|
454
|
+
imports.push(`import { ${modelName}MaxAggregateInputObjectSchema } from '../objects/${modelName}MaxAggregateInput.schema'`);
|
|
455
|
+
aggregateOperations.push(`_max: ${modelName}MaxAggregateInputObjectSchema.optional()`);
|
|
421
456
|
}
|
|
422
|
-
if ((_d = this.aggregateOperationSupport[
|
|
423
|
-
imports.push(`import { ${
|
|
424
|
-
aggregateOperations.push(`_avg: ${
|
|
457
|
+
if ((_d = this.aggregateOperationSupport[modelName]) === null || _d === void 0 ? void 0 : _d.avg) {
|
|
458
|
+
imports.push(`import { ${modelName}AvgAggregateInputObjectSchema } from '../objects/${modelName}AvgAggregateInput.schema'`);
|
|
459
|
+
aggregateOperations.push(`_avg: ${modelName}AvgAggregateInputObjectSchema.optional()`);
|
|
425
460
|
}
|
|
426
|
-
if ((_e = this.aggregateOperationSupport[
|
|
427
|
-
imports.push(`import { ${
|
|
428
|
-
aggregateOperations.push(`_sum: ${
|
|
461
|
+
if ((_e = this.aggregateOperationSupport[modelName]) === null || _e === void 0 ? void 0 : _e.sum) {
|
|
462
|
+
imports.push(`import { ${modelName}SumAggregateInputObjectSchema } from '../objects/${modelName}SumAggregateInput.schema'`);
|
|
463
|
+
aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
|
|
429
464
|
}
|
|
430
465
|
if (aggregate) {
|
|
431
|
-
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${
|
|
432
|
-
codeBody += `aggregate: z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${
|
|
433
|
-
operations.push(['aggregate',
|
|
466
|
+
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${orderByWithRelationInput}ObjectSchema } from '../objects/${orderByWithRelationInput}.schema'`, `import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`);
|
|
467
|
+
codeBody += `aggregate: z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${orderByWithRelationInput}ObjectSchema, ${orderByWithRelationInput}ObjectSchema.array()]).optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${aggregateOperations.join(', ')} }),`;
|
|
468
|
+
operations.push(['aggregate', modelName]);
|
|
434
469
|
}
|
|
435
470
|
if (groupBy) {
|
|
436
|
-
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${modelName}OrderByWithAggregationInputObjectSchema } from '../objects/${modelName}OrderByWithAggregationInput.schema'`, `import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from '../objects/${modelName}ScalarWhereWithAggregatesInput.schema'`, `import { ${
|
|
437
|
-
codeBody += `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(${
|
|
471
|
+
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${modelName}OrderByWithAggregationInputObjectSchema } from '../objects/${modelName}OrderByWithAggregationInput.schema'`, `import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from '../objects/${modelName}ScalarWhereWithAggregatesInput.schema'`, `import { ${modelName}ScalarFieldEnumSchema } from '../enums/${modelName}ScalarFieldEnum.schema'`);
|
|
472
|
+
codeBody += `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), ${aggregateOperations.join(', ')} }),`;
|
|
473
|
+
// prisma 4 and 5 different typing for "groupBy" and we have to deal with it separately
|
|
438
474
|
if (prismaVersion && semver.gte(prismaVersion, '5.0.0')) {
|
|
439
|
-
|
|
440
|
-
operations.push(['groupBy', modelName]);
|
|
475
|
+
operations.push(['groupBy', origModelName]);
|
|
441
476
|
}
|
|
442
477
|
else {
|
|
443
|
-
operations.push(['groupBy',
|
|
478
|
+
operations.push(['groupBy', modelName]);
|
|
444
479
|
}
|
|
445
480
|
}
|
|
481
|
+
// count
|
|
482
|
+
{
|
|
483
|
+
imports.push(`import { ${modelName}WhereInputObjectSchema } from '../objects/${modelName}WhereInput.schema'`, `import { ${orderByWithRelationInput}ObjectSchema } from '../objects/${orderByWithRelationInput}.schema'`, `import { ${modelName}WhereUniqueInputObjectSchema } from '../objects/${modelName}WhereUniqueInput.schema'`, `import { ${modelName}ScalarFieldEnumSchema } from '../enums/${modelName}ScalarFieldEnum.schema'`, `import { ${modelName}CountAggregateInputObjectSchema } from '../objects/${modelName}CountAggregateInput.schema'`);
|
|
484
|
+
codeBody += `count: z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${orderByWithRelationInput}ObjectSchema, ${orderByWithRelationInput}ObjectSchema.array()]).optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional(), select: z.union([ z.literal(true), ${modelName}CountAggregateInputObjectSchema ]).optional() })`;
|
|
485
|
+
operations.push(['count', origModelName]);
|
|
486
|
+
}
|
|
446
487
|
imports = [...new Set(imports)];
|
|
447
488
|
const filePath = path_1.default.join(Transformer.outputPath, `input/${modelName}Input.schema.ts`);
|
|
448
489
|
const content = `
|
|
@@ -451,12 +492,12 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
|
|
|
451
492
|
|
|
452
493
|
type ${modelName}InputSchemaType = {
|
|
453
494
|
${operations
|
|
454
|
-
.map((
|
|
495
|
+
.map(([operation, typeName]) => (0, utils_1.indentString)(`${operation}: z.ZodType<Prisma.${typeName}${(0, upper_case_first_1.upperCaseFirst)(operation)}Args>`, 4))
|
|
455
496
|
.join(',\n')}
|
|
456
497
|
}
|
|
457
498
|
|
|
458
499
|
export const ${modelName}InputSchema = {
|
|
459
|
-
${(0, utils_1.
|
|
500
|
+
${(0, utils_1.indentString)(codeBody, 4)}
|
|
460
501
|
} as ${modelName}InputSchemaType;
|
|
461
502
|
`;
|
|
462
503
|
this.project.createSourceFile(filePath, content, { overwrite: true });
|
|
@@ -477,7 +518,8 @@ ${globalExports.join(';\n')}
|
|
|
477
518
|
return generatedImports;
|
|
478
519
|
}
|
|
479
520
|
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
480
|
-
const { name
|
|
521
|
+
const { name } = model;
|
|
522
|
+
const modelName = (0, upper_case_first_1.upperCaseFirst)(name);
|
|
481
523
|
const hasRelationToAnotherModel = (0, dmmf_helpers_1.checkModelHasModelRelation)(model);
|
|
482
524
|
const selectImport = `import { ${modelName}SelectObjectSchema } from '../objects/${modelName}Select.schema'`;
|
|
483
525
|
const includeImport = hasRelationToAnotherModel
|