prisma-nestjs-graphql 16.0.0 → 17.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 +5 -4
- package/index.js +215 -221
- package/package.json +30 -30
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Generate object types, inputs, args, etc. from prisma schema file for usage with
|
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```
|
|
14
14
|
npm install --save-dev prisma-nestjs-graphql
|
|
15
15
|
```
|
|
16
16
|
|
|
@@ -23,7 +23,7 @@ generator nestgraphql {
|
|
|
23
23
|
provider = "node node_modules/prisma-nestjs-graphql"
|
|
24
24
|
// for yarn monorepos
|
|
25
25
|
// provider = "prisma-nestjs-graphql"
|
|
26
|
-
output = "../src/@generated
|
|
26
|
+
output = "../src/@generated"
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -97,7 +97,7 @@ Example configuration:
|
|
|
97
97
|
```prisma
|
|
98
98
|
generator nestgraphql {
|
|
99
99
|
provider = "node node_modules/prisma-nestjs-graphql"
|
|
100
|
-
output = "../src/@generated
|
|
100
|
+
output = "../src/@generated"
|
|
101
101
|
reExport = Directories
|
|
102
102
|
}
|
|
103
103
|
```
|
|
@@ -182,7 +182,7 @@ to set `UserWhereInput` need to configure generator the following way:
|
|
|
182
182
|
```prisma
|
|
183
183
|
generator nestgraphql {
|
|
184
184
|
provider = "node node_modules/prisma-nestjs-graphql"
|
|
185
|
-
output = "../src/@generated
|
|
185
|
+
output = "../src/@generated"
|
|
186
186
|
useInputType_WhereInput_ALL = "WhereInput"
|
|
187
187
|
}
|
|
188
188
|
```
|
|
@@ -703,6 +703,7 @@ export class User {}
|
|
|
703
703
|
|
|
704
704
|
## Similar Projects
|
|
705
705
|
|
|
706
|
+
- https://github.com/jasonraimondi/prisma-generator-nestjs-graphql
|
|
706
707
|
- https://github.com/omar-dulaimi/prisma-class-validator-generator
|
|
707
708
|
- https://github.com/kimjbstar/prisma-class-generator
|
|
708
709
|
- https://github.com/odroe/nest-gql-mix
|
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -13,7 +14,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
14
|
}
|
|
14
15
|
return to;
|
|
15
16
|
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
19
|
+
mod
|
|
20
|
+
));
|
|
17
21
|
|
|
18
22
|
// src/index.ts
|
|
19
23
|
var import_generator_helper = require("@prisma/generator-helper");
|
|
@@ -50,7 +54,7 @@ function argsType(field, args) {
|
|
|
50
54
|
className = `${modelName}GroupByArgs`;
|
|
51
55
|
break;
|
|
52
56
|
}
|
|
53
|
-
const
|
|
57
|
+
const inputType2 = {
|
|
54
58
|
constraints: {
|
|
55
59
|
maxNumFields: null,
|
|
56
60
|
minNumFields: null
|
|
@@ -71,17 +75,17 @@ function argsType(field, args) {
|
|
|
71
75
|
"Min",
|
|
72
76
|
"Max"
|
|
73
77
|
];
|
|
74
|
-
if (`${modelName}GroupByArgs` ===
|
|
75
|
-
const byField =
|
|
76
|
-
if (byField
|
|
77
|
-
byField.inputTypes = byField.inputTypes.filter((
|
|
78
|
+
if (`${modelName}GroupByArgs` === inputType2.name) {
|
|
79
|
+
const byField = inputType2.fields.find((f) => f.name === "by");
|
|
80
|
+
if (byField?.inputTypes) {
|
|
81
|
+
byField.inputTypes = byField.inputTypes.filter((inputType3) => inputType3.isList);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
for (const name of names) {
|
|
81
85
|
if (!typeNames.has(`${modelName}${name}AggregateInput`)) {
|
|
82
86
|
continue;
|
|
83
87
|
}
|
|
84
|
-
|
|
88
|
+
inputType2.fields.push({
|
|
85
89
|
name: `_${name.toLowerCase()}`,
|
|
86
90
|
isRequired: false,
|
|
87
91
|
isNullable: true,
|
|
@@ -97,7 +101,7 @@ function argsType(field, args) {
|
|
|
97
101
|
}
|
|
98
102
|
eventEmitter.emitSync("InputType", {
|
|
99
103
|
...args,
|
|
100
|
-
inputType:
|
|
104
|
+
inputType: inputType2,
|
|
101
105
|
fileType: "args",
|
|
102
106
|
classDecoratorName: "ArgsType"
|
|
103
107
|
});
|
|
@@ -165,21 +169,18 @@ function createAggregateInput(args) {
|
|
|
165
169
|
minNumFields: null
|
|
166
170
|
},
|
|
167
171
|
name: className,
|
|
168
|
-
fields: outputType2.fields.map((x) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
]
|
|
181
|
-
};
|
|
182
|
-
})
|
|
172
|
+
fields: outputType2.fields.map((x) => ({
|
|
173
|
+
name: x.name,
|
|
174
|
+
isNullable: x.isNullable ?? true,
|
|
175
|
+
isRequired: false,
|
|
176
|
+
inputTypes: [
|
|
177
|
+
{
|
|
178
|
+
isList: false,
|
|
179
|
+
type: "true",
|
|
180
|
+
location: "scalar"
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}))
|
|
183
184
|
};
|
|
184
185
|
eventEmitter.emitSync("InputType", {
|
|
185
186
|
...args,
|
|
@@ -283,21 +284,20 @@ async function generateFiles(args) {
|
|
|
283
284
|
const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", void 0, {
|
|
284
285
|
overwrite: true
|
|
285
286
|
});
|
|
286
|
-
const
|
|
287
|
-
var _a, _b;
|
|
287
|
+
const statements = project.getSourceFiles().flatMap((s) => {
|
|
288
288
|
if (s === sourceFile) {
|
|
289
289
|
return [];
|
|
290
290
|
}
|
|
291
291
|
const classDeclaration = s.getClass(() => true);
|
|
292
|
-
const
|
|
293
|
-
if (Array.isArray(
|
|
294
|
-
for (const statement of
|
|
292
|
+
const statements2 = s.getStructure().statements;
|
|
293
|
+
if (Array.isArray(statements2)) {
|
|
294
|
+
for (const statement of statements2) {
|
|
295
295
|
if (!(typeof statement === "object" && statement.kind === import_ts_morph2.StructureKind.Class)) {
|
|
296
296
|
continue;
|
|
297
297
|
}
|
|
298
298
|
for (const property of statement.properties || []) {
|
|
299
299
|
for (const decorator of property.decorators || []) {
|
|
300
|
-
const fullName =
|
|
300
|
+
const fullName = classDeclaration?.getProperty(property.name)?.getDecorator(decorator.name)?.getFullName();
|
|
301
301
|
(0, import_assert.ok)(fullName, `Cannot get full name of decorator of class ${statement.name}`);
|
|
302
302
|
decorator.name = fullName;
|
|
303
303
|
}
|
|
@@ -305,47 +305,47 @@ async function generateFiles(args) {
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
project.removeSourceFile(s);
|
|
308
|
-
return
|
|
308
|
+
return statements2;
|
|
309
309
|
});
|
|
310
310
|
const imports = new ImportDeclarationMap();
|
|
311
311
|
const enums = [];
|
|
312
312
|
const classes = [];
|
|
313
|
-
for (const
|
|
314
|
-
if (typeof
|
|
315
|
-
if (
|
|
316
|
-
enums.push(
|
|
313
|
+
for (const statement of statements) {
|
|
314
|
+
if (typeof statement === "string") {
|
|
315
|
+
if (statement.startsWith("registerEnumType")) {
|
|
316
|
+
enums.push(statement);
|
|
317
317
|
}
|
|
318
318
|
continue;
|
|
319
319
|
}
|
|
320
|
-
switch (
|
|
320
|
+
switch (statement.kind) {
|
|
321
321
|
case import_ts_morph2.StructureKind.ImportDeclaration:
|
|
322
|
-
if (
|
|
322
|
+
if (statement.moduleSpecifier.startsWith("./") || statement.moduleSpecifier.startsWith("..")) {
|
|
323
323
|
continue;
|
|
324
324
|
}
|
|
325
|
-
for (const namedImport of
|
|
325
|
+
for (const namedImport of statement.namedImports) {
|
|
326
326
|
const name = namedImport.alias || namedImport.name;
|
|
327
|
-
imports.add(name,
|
|
327
|
+
imports.add(name, statement.moduleSpecifier);
|
|
328
328
|
}
|
|
329
|
-
if (
|
|
329
|
+
if (statement.defaultImport) {
|
|
330
330
|
imports.create({
|
|
331
|
-
from:
|
|
332
|
-
name:
|
|
333
|
-
defaultImport:
|
|
331
|
+
from: statement.moduleSpecifier,
|
|
332
|
+
name: statement.defaultImport,
|
|
333
|
+
defaultImport: statement.defaultImport
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
-
if (
|
|
336
|
+
if (statement.namespaceImport) {
|
|
337
337
|
imports.create({
|
|
338
|
-
from:
|
|
339
|
-
name:
|
|
340
|
-
namespaceImport:
|
|
338
|
+
from: statement.moduleSpecifier,
|
|
339
|
+
name: statement.namespaceImport,
|
|
340
|
+
namespaceImport: statement.namespaceImport
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
break;
|
|
344
344
|
case import_ts_morph2.StructureKind.Enum:
|
|
345
|
-
enums.unshift(
|
|
345
|
+
enums.unshift(statement);
|
|
346
346
|
break;
|
|
347
347
|
case import_ts_morph2.StructureKind.Class:
|
|
348
|
-
classes.push(
|
|
348
|
+
classes.push(statement);
|
|
349
349
|
break;
|
|
350
350
|
}
|
|
351
351
|
}
|
|
@@ -532,7 +532,9 @@ function getGraphqlInputType(inputTypes, pattern) {
|
|
|
532
532
|
return result;
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
|
-
throw new TypeError(
|
|
535
|
+
throw new TypeError(
|
|
536
|
+
`Cannot get matching input type from ${inputTypes.map((x) => x.type).join(", ") || "zero length inputTypes"}`
|
|
537
|
+
);
|
|
536
538
|
}
|
|
537
539
|
__name(getGraphqlInputType, "getGraphqlInputType");
|
|
538
540
|
|
|
@@ -608,13 +610,13 @@ __name(getPropertyType, "getPropertyType");
|
|
|
608
610
|
var import_ts_morph3 = require("ts-morph");
|
|
609
611
|
function propertyStructure(args) {
|
|
610
612
|
const { isNullable, propertyType, name, isList, hasQuestionToken, hasExclamationToken } = args;
|
|
611
|
-
const
|
|
613
|
+
const type = propertyType.map((type2) => isList ? `Array<${type2}>` : type2).join(" | ");
|
|
612
614
|
return {
|
|
613
615
|
kind: import_ts_morph3.StructureKind.Property,
|
|
614
616
|
name,
|
|
615
|
-
type
|
|
616
|
-
hasQuestionToken: hasQuestionToken
|
|
617
|
-
hasExclamationToken: hasExclamationToken
|
|
617
|
+
type,
|
|
618
|
+
hasQuestionToken: hasQuestionToken ?? isNullable,
|
|
619
|
+
hasExclamationToken: hasExclamationToken ?? !isNullable,
|
|
618
620
|
decorators: [],
|
|
619
621
|
leadingTrivia: "\n"
|
|
620
622
|
};
|
|
@@ -623,18 +625,17 @@ __name(propertyStructure, "propertyStructure");
|
|
|
623
625
|
|
|
624
626
|
// src/handlers/input-type.ts
|
|
625
627
|
function inputType(args) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
typeNames.add(inputType1.name);
|
|
628
|
+
const { classDecoratorName, classTransformerTypeModels, config, eventEmitter, fieldSettings, fileType, getModelName: getModelName2, getSourceFile, inputType: inputType2, models, removeTypes, typeNames } = args;
|
|
629
|
+
typeNames.add(inputType2.name);
|
|
629
630
|
const importDeclarations = new ImportDeclarationMap();
|
|
630
631
|
const sourceFile = getSourceFile({
|
|
631
|
-
name:
|
|
632
|
+
name: inputType2.name,
|
|
632
633
|
type: fileType
|
|
633
634
|
});
|
|
634
635
|
const classStructure = {
|
|
635
636
|
kind: import_ts_morph4.StructureKind.Class,
|
|
636
637
|
isExported: true,
|
|
637
|
-
name:
|
|
638
|
+
name: inputType2.name,
|
|
638
639
|
decorators: [
|
|
639
640
|
{
|
|
640
641
|
name: classDecoratorName,
|
|
@@ -643,7 +644,7 @@ function inputType(args) {
|
|
|
643
644
|
],
|
|
644
645
|
properties: []
|
|
645
646
|
};
|
|
646
|
-
const modelName = getModelName2(
|
|
647
|
+
const modelName = getModelName2(inputType2.name) || "";
|
|
647
648
|
const model = models.get(modelName);
|
|
648
649
|
const modelFieldSettings = model && fieldSettings.get(model.name);
|
|
649
650
|
const moduleSpecifier = "@nestjs/graphql";
|
|
@@ -662,26 +663,26 @@ function inputType(args) {
|
|
|
662
663
|
],
|
|
663
664
|
moduleSpecifier
|
|
664
665
|
});
|
|
665
|
-
const useInputType = config.useInputType.find((x) =>
|
|
666
|
-
for (const field of
|
|
666
|
+
const useInputType = config.useInputType.find((x) => inputType2.name.includes(x.typeName));
|
|
667
|
+
for (const field of inputType2.fields) {
|
|
667
668
|
field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(String(t.type)));
|
|
668
669
|
eventEmitter.emitSync("BeforeGenerateField", field, args);
|
|
669
670
|
const { inputTypes, isRequired, name } = field;
|
|
670
671
|
if (inputTypes.length === 0) {
|
|
671
672
|
continue;
|
|
672
673
|
}
|
|
673
|
-
const usePattern =
|
|
674
|
+
const usePattern = useInputType?.ALL || useInputType?.[name];
|
|
674
675
|
const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
|
|
675
676
|
const { isList, location, type } = graphqlInputType;
|
|
676
677
|
const typeName = String(type);
|
|
677
|
-
const settings = modelFieldSettings
|
|
678
|
-
const propertySettings = settings
|
|
679
|
-
name:
|
|
678
|
+
const settings = modelFieldSettings?.get(name);
|
|
679
|
+
const propertySettings = settings?.getPropertyType({
|
|
680
|
+
name: inputType2.name,
|
|
680
681
|
input: true
|
|
681
682
|
});
|
|
682
|
-
const modelField = model
|
|
683
|
-
const isCustomsApplicable = typeName ===
|
|
684
|
-
const propertyType = (0, import_lodash3.castArray)(
|
|
683
|
+
const modelField = model?.fields.find((f) => f.name === name);
|
|
684
|
+
const isCustomsApplicable = typeName === modelField?.type;
|
|
685
|
+
const propertyType = (0, import_lodash3.castArray)(propertySettings?.name || getPropertyType({
|
|
685
686
|
location,
|
|
686
687
|
type: typeName
|
|
687
688
|
}));
|
|
@@ -700,12 +701,12 @@ function inputType(args) {
|
|
|
700
701
|
importDeclarations.add("Decimal", "@prisma/client/runtime");
|
|
701
702
|
}
|
|
702
703
|
let graphqlType;
|
|
703
|
-
const shouldHideField =
|
|
704
|
-
name:
|
|
704
|
+
const shouldHideField = settings?.shouldHideField({
|
|
705
|
+
name: inputType2.name,
|
|
705
706
|
input: true
|
|
706
|
-
})
|
|
707
|
-
const fieldType = settings
|
|
708
|
-
name:
|
|
707
|
+
}) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType2.name));
|
|
708
|
+
const fieldType = settings?.getFieldType({
|
|
709
|
+
name: inputType2.name,
|
|
709
710
|
input: true
|
|
710
711
|
});
|
|
711
712
|
if (fieldType && isCustomsApplicable && !shouldHideField) {
|
|
@@ -726,7 +727,7 @@ function inputType(args) {
|
|
|
726
727
|
if (location === "enumTypes") {
|
|
727
728
|
referenceName = (0, import_lodash3.last)(referenceName.split(" "));
|
|
728
729
|
}
|
|
729
|
-
if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !==
|
|
730
|
+
if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputType2.name) {
|
|
730
731
|
importDeclarations.set(graphqlImport.name, {
|
|
731
732
|
namedImports: [
|
|
732
733
|
{
|
|
@@ -750,7 +751,7 @@ function inputType(args) {
|
|
|
750
751
|
arguments: [
|
|
751
752
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
752
753
|
import_json5.default.stringify({
|
|
753
|
-
...settings
|
|
754
|
+
...settings?.fieldArguments(),
|
|
754
755
|
nullable: !isRequired
|
|
755
756
|
})
|
|
756
757
|
]
|
|
@@ -770,20 +771,21 @@ function inputType(args) {
|
|
|
770
771
|
"transformToDecimal"
|
|
771
772
|
]
|
|
772
773
|
});
|
|
773
|
-
} else if (location === "inputObjectTypes" && (
|
|
774
|
-
"
|
|
775
|
-
"where",
|
|
776
|
-
"create",
|
|
774
|
+
} else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
|
|
775
|
+
"connect",
|
|
777
776
|
"connectOrCreate",
|
|
778
|
-
"
|
|
779
|
-
"
|
|
780
|
-
"
|
|
777
|
+
"create",
|
|
778
|
+
"createMany",
|
|
779
|
+
"data",
|
|
781
780
|
"delete",
|
|
782
|
-
"
|
|
781
|
+
"deleteMany",
|
|
782
|
+
"disconnect",
|
|
783
|
+
"set",
|
|
783
784
|
"update",
|
|
784
785
|
"updateMany",
|
|
785
|
-
"
|
|
786
|
-
|
|
786
|
+
"upsert",
|
|
787
|
+
"where"
|
|
788
|
+
].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) || "") || modelField?.kind === "object" && models.get(modelField.type) && models.get(modelField.type)?.fields.some((field2) => field2.kind === "object" && classTransformerTypeModels.has(field2.type)))) {
|
|
787
789
|
importDeclarations.add("Type", "class-transformer");
|
|
788
790
|
property.decorators.push({
|
|
789
791
|
name: "Type",
|
|
@@ -794,7 +796,7 @@ function inputType(args) {
|
|
|
794
796
|
}
|
|
795
797
|
if (isCustomsApplicable) {
|
|
796
798
|
for (const options of settings || []) {
|
|
797
|
-
if ((
|
|
799
|
+
if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
|
|
798
800
|
property.decorators.push({
|
|
799
801
|
name: options.name,
|
|
800
802
|
arguments: options.arguments
|
|
@@ -805,10 +807,10 @@ function inputType(args) {
|
|
|
805
807
|
}
|
|
806
808
|
}
|
|
807
809
|
for (const decorate of config.decorate) {
|
|
808
|
-
if (decorate.isMatchField(name) && decorate.isMatchType(
|
|
810
|
+
if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
|
|
809
811
|
property.decorators.push({
|
|
810
812
|
name: decorate.name,
|
|
811
|
-
arguments:
|
|
813
|
+
arguments: decorate.arguments?.map((x) => (0, import_pupa.default)(x, {
|
|
812
814
|
propertyType
|
|
813
815
|
}))
|
|
814
816
|
});
|
|
@@ -837,9 +839,8 @@ var import_lodash4 = require("lodash");
|
|
|
837
839
|
var import_outmatch2 = __toESM(require("outmatch"));
|
|
838
840
|
var ObjectSettings = class extends Array {
|
|
839
841
|
shouldHideField({ name, input = false, output = false }) {
|
|
840
|
-
var _a;
|
|
841
842
|
const hideField = this.find((s) => s.name === "HideField");
|
|
842
|
-
return Boolean(
|
|
843
|
+
return Boolean(hideField?.input && input || hideField?.output && output || hideField?.match?.(name));
|
|
843
844
|
}
|
|
844
845
|
getFieldType({ name, input, output }) {
|
|
845
846
|
const fieldType = this.find((s) => s.kind === "FieldType");
|
|
@@ -889,9 +890,9 @@ var ObjectSettings = class extends Array {
|
|
|
889
890
|
return resultArguments.map((x) => import_json52.default.stringify(x));
|
|
890
891
|
}
|
|
891
892
|
fieldArguments() {
|
|
892
|
-
const
|
|
893
|
-
if (
|
|
894
|
-
return
|
|
893
|
+
const item = this.find((item2) => item2.kind === "Field");
|
|
894
|
+
if (item) {
|
|
895
|
+
return item.arguments;
|
|
895
896
|
}
|
|
896
897
|
}
|
|
897
898
|
};
|
|
@@ -931,7 +932,6 @@ function createObjectSettings(args) {
|
|
|
931
932
|
}
|
|
932
933
|
__name(createObjectSettings, "createObjectSettings");
|
|
933
934
|
function createSettingElement({ line, config, fieldElement, match }) {
|
|
934
|
-
var _a, _b, _c, _d, _e;
|
|
935
935
|
const result = {
|
|
936
936
|
documentLine: "",
|
|
937
937
|
element: void 0
|
|
@@ -941,7 +941,7 @@ function createSettingElement({ line, config, fieldElement, match }) {
|
|
|
941
941
|
result.element = fieldElement;
|
|
942
942
|
return result;
|
|
943
943
|
}
|
|
944
|
-
const name =
|
|
944
|
+
const name = match?.groups?.name;
|
|
945
945
|
if (!(match && name)) {
|
|
946
946
|
result.documentLine = line;
|
|
947
947
|
return result;
|
|
@@ -963,29 +963,29 @@ function createSettingElement({ line, config, fieldElement, match }) {
|
|
|
963
963
|
if ([
|
|
964
964
|
"FieldType",
|
|
965
965
|
"PropertyType"
|
|
966
|
-
].includes(name) &&
|
|
967
|
-
const
|
|
968
|
-
(0, import_lodash4.merge)(element,
|
|
966
|
+
].includes(name) && match.groups?.args) {
|
|
967
|
+
const options = customType(match.groups.args);
|
|
968
|
+
(0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, {
|
|
969
969
|
kind: name
|
|
970
970
|
});
|
|
971
971
|
return result;
|
|
972
972
|
}
|
|
973
|
-
if (name === "ObjectType" &&
|
|
973
|
+
if (name === "ObjectType" && match.groups?.args) {
|
|
974
974
|
element.kind = "ObjectType";
|
|
975
|
-
const
|
|
976
|
-
if (typeof
|
|
977
|
-
|
|
975
|
+
const options1 = customType(match.groups.args);
|
|
976
|
+
if (typeof options1[0] === "string" && options1[0]) {
|
|
977
|
+
options1.name = options1[0];
|
|
978
978
|
}
|
|
979
|
-
if ((0, import_lodash4.isObject)(
|
|
980
|
-
(0, import_lodash4.merge)(
|
|
979
|
+
if ((0, import_lodash4.isObject)(options1[1])) {
|
|
980
|
+
(0, import_lodash4.merge)(options1, options1[1]);
|
|
981
981
|
}
|
|
982
982
|
element.arguments = {
|
|
983
|
-
name:
|
|
984
|
-
isAbstract:
|
|
983
|
+
name: options1.name,
|
|
984
|
+
isAbstract: options1.isAbstract
|
|
985
985
|
};
|
|
986
986
|
return result;
|
|
987
987
|
}
|
|
988
|
-
if (name === "Directive" &&
|
|
988
|
+
if (name === "Directive" && match.groups?.args) {
|
|
989
989
|
const options2 = customType(match.groups.args);
|
|
990
990
|
(0, import_lodash4.merge)(element, {
|
|
991
991
|
model: true,
|
|
@@ -1000,16 +1000,15 @@ function createSettingElement({ line, config, fieldElement, match }) {
|
|
|
1000
1000
|
}
|
|
1001
1001
|
const namespace = getNamespace(name);
|
|
1002
1002
|
element.namespaceImport = namespace;
|
|
1003
|
-
const
|
|
1003
|
+
const options3 = {
|
|
1004
1004
|
name,
|
|
1005
|
-
arguments: (
|
|
1005
|
+
arguments: (match.groups?.args || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
|
|
1006
1006
|
};
|
|
1007
|
-
(0, import_lodash4.merge)(element, namespace && config.fields[namespace],
|
|
1007
|
+
(0, import_lodash4.merge)(element, namespace && config.fields[namespace], options3);
|
|
1008
1008
|
return result;
|
|
1009
1009
|
}
|
|
1010
1010
|
__name(createSettingElement, "createSettingElement");
|
|
1011
1011
|
function customType(args) {
|
|
1012
|
-
var _a;
|
|
1013
1012
|
const result = {};
|
|
1014
1013
|
let options = parseArgs(args);
|
|
1015
1014
|
if (typeof options === "string") {
|
|
@@ -1020,7 +1019,7 @@ function customType(args) {
|
|
|
1020
1019
|
Object.assign(result, options);
|
|
1021
1020
|
const namespace = getNamespace(options.name);
|
|
1022
1021
|
result.namespace = namespace;
|
|
1023
|
-
if (
|
|
1022
|
+
if (options.name?.includes(".")) {
|
|
1024
1023
|
result.namespaceImport = namespace;
|
|
1025
1024
|
}
|
|
1026
1025
|
if (typeof options.match === "string" || Array.isArray(options.match)) {
|
|
@@ -1032,7 +1031,6 @@ function customType(args) {
|
|
|
1032
1031
|
}
|
|
1033
1032
|
__name(customType, "customType");
|
|
1034
1033
|
function hideFieldDecorator(match) {
|
|
1035
|
-
var _a;
|
|
1036
1034
|
const result = {
|
|
1037
1035
|
name: "HideField",
|
|
1038
1036
|
arguments: [],
|
|
@@ -1041,7 +1039,7 @@ function hideFieldDecorator(match) {
|
|
|
1041
1039
|
namespaceImport: void 0,
|
|
1042
1040
|
match: void 0
|
|
1043
1041
|
};
|
|
1044
|
-
if (!
|
|
1042
|
+
if (!match.groups?.args) {
|
|
1045
1043
|
result.output = true;
|
|
1046
1044
|
return result;
|
|
1047
1045
|
}
|
|
@@ -1068,10 +1066,10 @@ __name(hideFieldDecorator, "hideFieldDecorator");
|
|
|
1068
1066
|
function parseArgs(string) {
|
|
1069
1067
|
try {
|
|
1070
1068
|
return import_json52.default.parse(string);
|
|
1071
|
-
} catch
|
|
1069
|
+
} catch {
|
|
1072
1070
|
try {
|
|
1073
1071
|
return import_json52.default.parse(`[${string}]`);
|
|
1074
|
-
} catch
|
|
1072
|
+
} catch {
|
|
1075
1073
|
throw new Error(`Failed to parse: ${string}`);
|
|
1076
1074
|
}
|
|
1077
1075
|
}
|
|
@@ -1091,7 +1089,7 @@ __name(getNamespace, "getNamespace");
|
|
|
1091
1089
|
|
|
1092
1090
|
// src/handlers/model-data.ts
|
|
1093
1091
|
function modelData(model, args) {
|
|
1094
|
-
const { config, modelNames, models, modelFields, fieldSettings } = args;
|
|
1092
|
+
const { config, modelNames, models, modelFields, fieldSettings, classTransformerTypeModels } = args;
|
|
1095
1093
|
modelNames.push(model.name);
|
|
1096
1094
|
models.set(model.name, model);
|
|
1097
1095
|
const modelFieldsValue = /* @__PURE__ */ new Map();
|
|
@@ -1109,6 +1107,9 @@ function modelData(model, args) {
|
|
|
1109
1107
|
}
|
|
1110
1108
|
modelFieldsValue.set(field.name, field);
|
|
1111
1109
|
}
|
|
1110
|
+
if (model.fields.some((field) => field.type === "Decimal")) {
|
|
1111
|
+
classTransformerTypeModels.add(model.name);
|
|
1112
|
+
}
|
|
1112
1113
|
}
|
|
1113
1114
|
__name(modelData, "modelData");
|
|
1114
1115
|
|
|
@@ -1121,7 +1122,6 @@ var import_ts_morph5 = require("ts-morph");
|
|
|
1121
1122
|
|
|
1122
1123
|
// src/helpers/create-comment.ts
|
|
1123
1124
|
function createComment(documentation, settings) {
|
|
1124
|
-
var _a;
|
|
1125
1125
|
const documentationLines = documentation.split("\n");
|
|
1126
1126
|
const commentLines = [
|
|
1127
1127
|
"/**"
|
|
@@ -1129,7 +1129,7 @@ function createComment(documentation, settings) {
|
|
|
1129
1129
|
for (const line of documentationLines) {
|
|
1130
1130
|
commentLines.push(` * ${line}`);
|
|
1131
1131
|
}
|
|
1132
|
-
const deprecationReason =
|
|
1132
|
+
const deprecationReason = settings?.fieldArguments()?.deprecationReason;
|
|
1133
1133
|
if (deprecationReason) {
|
|
1134
1134
|
commentLines.push(` * @deprecated ${deprecationReason}`);
|
|
1135
1135
|
}
|
|
@@ -1147,7 +1147,6 @@ __name(getOutputTypeName, "getOutputTypeName");
|
|
|
1147
1147
|
// src/handlers/model-output-type.ts
|
|
1148
1148
|
var nestjsGraphql = "@nestjs/graphql";
|
|
1149
1149
|
function modelOutputType(outputType2, args) {
|
|
1150
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1151
1150
|
const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
|
|
1152
1151
|
const model = models.get(outputType2.name);
|
|
1153
1152
|
(0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
|
|
@@ -1200,17 +1199,17 @@ function modelOutputType(outputType2, args) {
|
|
|
1200
1199
|
fileType = "output";
|
|
1201
1200
|
outputTypeName = getOutputTypeName(outputTypeName);
|
|
1202
1201
|
}
|
|
1203
|
-
const modelField =
|
|
1204
|
-
const
|
|
1205
|
-
const fieldType =
|
|
1202
|
+
const modelField = modelFields.get(model.name)?.get(field.name);
|
|
1203
|
+
const settings1 = fieldSettings.get(model.name)?.get(field.name);
|
|
1204
|
+
const fieldType = settings1?.getFieldType({
|
|
1206
1205
|
name: outputType2.name,
|
|
1207
1206
|
output: true
|
|
1208
1207
|
});
|
|
1209
|
-
const propertySettings =
|
|
1208
|
+
const propertySettings = settings1?.getPropertyType({
|
|
1210
1209
|
name: outputType2.name,
|
|
1211
1210
|
output: true
|
|
1212
1211
|
});
|
|
1213
|
-
const propertyType = (0, import_lodash5.castArray)(
|
|
1212
|
+
const propertyType = (0, import_lodash5.castArray)(propertySettings?.name || getPropertyType({
|
|
1214
1213
|
location,
|
|
1215
1214
|
type: outputTypeName
|
|
1216
1215
|
}));
|
|
@@ -1230,7 +1229,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1230
1229
|
sourceFile,
|
|
1231
1230
|
fileType,
|
|
1232
1231
|
location,
|
|
1233
|
-
isId: modelField
|
|
1232
|
+
isId: modelField?.isId,
|
|
1234
1233
|
noTypeId: config.noTypeId,
|
|
1235
1234
|
typeName: outputTypeName,
|
|
1236
1235
|
getSourceFile
|
|
@@ -1248,10 +1247,10 @@ function modelOutputType(outputType2, args) {
|
|
|
1248
1247
|
propertyType,
|
|
1249
1248
|
isList
|
|
1250
1249
|
});
|
|
1251
|
-
if (typeof property.leadingTrivia === "string" &&
|
|
1252
|
-
property.leadingTrivia += createComment(modelField.documentation,
|
|
1250
|
+
if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
|
|
1251
|
+
property.leadingTrivia += createComment(modelField.documentation, settings1);
|
|
1253
1252
|
}
|
|
1254
|
-
|
|
1253
|
+
classStructure.properties?.push(property);
|
|
1255
1254
|
if (propertySettings) {
|
|
1256
1255
|
importDeclarations.create({
|
|
1257
1256
|
...propertySettings
|
|
@@ -1260,7 +1259,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1260
1259
|
importDeclarations.add("Decimal", "@prisma/client/runtime");
|
|
1261
1260
|
}
|
|
1262
1261
|
(0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
|
|
1263
|
-
if (
|
|
1262
|
+
if (settings1?.shouldHideField({
|
|
1264
1263
|
name: outputType2.name,
|
|
1265
1264
|
output: true
|
|
1266
1265
|
})) {
|
|
@@ -1275,19 +1274,19 @@ function modelOutputType(outputType2, args) {
|
|
|
1275
1274
|
arguments: [
|
|
1276
1275
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1277
1276
|
import_json53.default.stringify({
|
|
1278
|
-
...
|
|
1277
|
+
...settings1?.fieldArguments(),
|
|
1279
1278
|
nullable: Boolean(field.isNullable),
|
|
1280
1279
|
defaultValue: [
|
|
1281
1280
|
"number",
|
|
1282
1281
|
"string",
|
|
1283
1282
|
"boolean"
|
|
1284
|
-
].includes(typeof
|
|
1285
|
-
description: modelField
|
|
1283
|
+
].includes(typeof modelField?.default) ? modelField?.default : void 0,
|
|
1284
|
+
description: modelField?.documentation
|
|
1286
1285
|
})
|
|
1287
1286
|
]
|
|
1288
1287
|
});
|
|
1289
|
-
for (const setting of
|
|
1290
|
-
if (shouldBeDecorated(setting) && (
|
|
1288
|
+
for (const setting of settings1 || []) {
|
|
1289
|
+
if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
|
|
1291
1290
|
property.decorators.push({
|
|
1292
1291
|
name: setting.name,
|
|
1293
1292
|
arguments: setting.arguments
|
|
@@ -1300,7 +1299,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1300
1299
|
if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
|
|
1301
1300
|
property.decorators.push({
|
|
1302
1301
|
name: decorate.name,
|
|
1303
|
-
arguments:
|
|
1302
|
+
arguments: decorate.arguments?.map((x) => (0, import_pupa2.default)(x, {
|
|
1304
1303
|
propertyType
|
|
1305
1304
|
}))
|
|
1306
1305
|
});
|
|
@@ -1314,13 +1313,13 @@ function modelOutputType(outputType2, args) {
|
|
|
1314
1313
|
propertyType
|
|
1315
1314
|
});
|
|
1316
1315
|
}
|
|
1317
|
-
for (const
|
|
1318
|
-
if (shouldBeDecorated(
|
|
1316
|
+
for (const setting1 of modelSettings || []) {
|
|
1317
|
+
if (shouldBeDecorated(setting1)) {
|
|
1319
1318
|
classStructure.decorators.push({
|
|
1320
|
-
name:
|
|
1321
|
-
arguments:
|
|
1319
|
+
name: setting1.name,
|
|
1320
|
+
arguments: setting1.arguments
|
|
1322
1321
|
});
|
|
1323
|
-
importDeclarations.create(
|
|
1322
|
+
importDeclarations.create(setting1);
|
|
1324
1323
|
}
|
|
1325
1324
|
}
|
|
1326
1325
|
if (exportDeclaration) {
|
|
@@ -1366,11 +1365,11 @@ function noAtomicOperations(eventEmitter) {
|
|
|
1366
1365
|
}
|
|
1367
1366
|
__name(noAtomicOperations, "noAtomicOperations");
|
|
1368
1367
|
function beforeInputType2(args) {
|
|
1369
|
-
const { inputType:
|
|
1370
|
-
for (const field of
|
|
1368
|
+
const { inputType: inputType2, getModelName: getModelName2 } = args;
|
|
1369
|
+
for (const field of inputType2.fields) {
|
|
1371
1370
|
const fieldName = field.name;
|
|
1372
|
-
field.inputTypes = field.inputTypes.filter((
|
|
1373
|
-
const inputTypeName = String(
|
|
1371
|
+
field.inputTypes = field.inputTypes.filter((inputType3) => {
|
|
1372
|
+
const inputTypeName = String(inputType3.type);
|
|
1374
1373
|
const modelName = getModelName2(inputTypeName);
|
|
1375
1374
|
if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName, fieldName)) {
|
|
1376
1375
|
return false;
|
|
@@ -1381,10 +1380,9 @@ function beforeInputType2(args) {
|
|
|
1381
1380
|
}
|
|
1382
1381
|
__name(beforeInputType2, "beforeInputType");
|
|
1383
1382
|
function beforeGenerateFiles(args) {
|
|
1384
|
-
var _a;
|
|
1385
1383
|
const { project } = args;
|
|
1386
1384
|
for (const sourceFile of project.getSourceFiles()) {
|
|
1387
|
-
const className =
|
|
1385
|
+
const className = sourceFile.getClass(() => true)?.getName();
|
|
1388
1386
|
if (className && isAtomicOperation(className)) {
|
|
1389
1387
|
project.removeSourceFile(sourceFile);
|
|
1390
1388
|
}
|
|
@@ -1409,30 +1407,29 @@ var import_json54 = __toESM(require("json5"));
|
|
|
1409
1407
|
var import_lodash6 = require("lodash");
|
|
1410
1408
|
var import_ts_morph6 = require("ts-morph");
|
|
1411
1409
|
var nestjsGraphql2 = "@nestjs/graphql";
|
|
1412
|
-
function outputType(
|
|
1413
|
-
var _a, _b, _c, _d, _e;
|
|
1410
|
+
function outputType(outputType2, args) {
|
|
1414
1411
|
const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2, config } = args;
|
|
1415
1412
|
const importDeclarations = new ImportDeclarationMap();
|
|
1416
1413
|
const fileType = "output";
|
|
1417
|
-
const modelName = getModelName2(
|
|
1414
|
+
const modelName = getModelName2(outputType2.name) || "";
|
|
1418
1415
|
const model = models.get(modelName);
|
|
1419
|
-
const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(
|
|
1420
|
-
const isCountOutput =
|
|
1421
|
-
|
|
1416
|
+
const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
|
|
1417
|
+
const isCountOutput = model?.name && outputType2.name === `${model.name}CountOutputType`;
|
|
1418
|
+
outputType2.name = getOutputTypeName(outputType2.name);
|
|
1422
1419
|
if (isAggregateOutput) {
|
|
1423
1420
|
eventEmitter.emitSync("AggregateOutput", {
|
|
1424
1421
|
...args,
|
|
1425
|
-
outputType:
|
|
1422
|
+
outputType: outputType2
|
|
1426
1423
|
});
|
|
1427
1424
|
}
|
|
1428
1425
|
const sourceFile = getSourceFile({
|
|
1429
|
-
name:
|
|
1426
|
+
name: outputType2.name,
|
|
1430
1427
|
type: fileType
|
|
1431
1428
|
});
|
|
1432
1429
|
const classStructure = {
|
|
1433
1430
|
kind: import_ts_morph6.StructureKind.Class,
|
|
1434
1431
|
isExported: true,
|
|
1435
|
-
name:
|
|
1432
|
+
name: outputType2.name,
|
|
1436
1433
|
decorators: [
|
|
1437
1434
|
{
|
|
1438
1435
|
name: "ObjectType",
|
|
@@ -1443,17 +1440,17 @@ function outputType(outputType1, args) {
|
|
|
1443
1440
|
};
|
|
1444
1441
|
importDeclarations.add("Field", nestjsGraphql2);
|
|
1445
1442
|
importDeclarations.add("ObjectType", nestjsGraphql2);
|
|
1446
|
-
for (const field of
|
|
1443
|
+
for (const field of outputType2.fields) {
|
|
1447
1444
|
const { location, isList, type } = field.outputType;
|
|
1448
1445
|
const outputTypeName = getOutputTypeName(String(type));
|
|
1449
|
-
const settings = isCountOutput ? void 0 : model &&
|
|
1450
|
-
const propertySettings = settings
|
|
1451
|
-
name:
|
|
1446
|
+
const settings = isCountOutput ? void 0 : model && fieldSettings.get(model.name)?.get(field.name);
|
|
1447
|
+
const propertySettings = settings?.getPropertyType({
|
|
1448
|
+
name: outputType2.name,
|
|
1452
1449
|
output: true
|
|
1453
1450
|
});
|
|
1454
|
-
const isCustomsApplicable = outputTypeName ===
|
|
1451
|
+
const isCustomsApplicable = outputTypeName === model?.fields.find((f) => f.name === field.name)?.type;
|
|
1455
1452
|
field.outputType.type = outputTypeName;
|
|
1456
|
-
const propertyType = (0, import_lodash6.castArray)(
|
|
1453
|
+
const propertyType = (0, import_lodash6.castArray)(propertySettings?.name || getPropertyType({
|
|
1457
1454
|
location,
|
|
1458
1455
|
type: outputTypeName
|
|
1459
1456
|
}));
|
|
@@ -1464,7 +1461,7 @@ function outputType(outputType1, args) {
|
|
|
1464
1461
|
propertyType,
|
|
1465
1462
|
isList
|
|
1466
1463
|
});
|
|
1467
|
-
|
|
1464
|
+
classStructure.properties?.push(property);
|
|
1468
1465
|
if (propertySettings) {
|
|
1469
1466
|
importDeclarations.create({
|
|
1470
1467
|
...propertySettings
|
|
@@ -1473,12 +1470,12 @@ function outputType(outputType1, args) {
|
|
|
1473
1470
|
importDeclarations.add("Decimal", "@prisma/client/runtime");
|
|
1474
1471
|
}
|
|
1475
1472
|
let graphqlType;
|
|
1476
|
-
const shouldHideField =
|
|
1477
|
-
name:
|
|
1473
|
+
const shouldHideField = settings?.shouldHideField({
|
|
1474
|
+
name: outputType2.name,
|
|
1478
1475
|
output: true
|
|
1479
|
-
})
|
|
1480
|
-
const fieldType = settings
|
|
1481
|
-
name:
|
|
1476
|
+
}) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName));
|
|
1477
|
+
const fieldType = settings?.getFieldType({
|
|
1478
|
+
name: outputType2.name,
|
|
1482
1479
|
output: true
|
|
1483
1480
|
});
|
|
1484
1481
|
if (fieldType && isCustomsApplicable && !shouldHideField) {
|
|
@@ -1501,7 +1498,7 @@ function outputType(outputType1, args) {
|
|
|
1501
1498
|
if (location === "enumTypes") {
|
|
1502
1499
|
referenceName = (0, import_lodash6.last)(referenceName.split(" "));
|
|
1503
1500
|
}
|
|
1504
|
-
if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !==
|
|
1501
|
+
if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
|
|
1505
1502
|
importDeclarations.set(graphqlImport.name, {
|
|
1506
1503
|
namedImports: [
|
|
1507
1504
|
{
|
|
@@ -1525,14 +1522,14 @@ function outputType(outputType1, args) {
|
|
|
1525
1522
|
arguments: [
|
|
1526
1523
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1527
1524
|
import_json54.default.stringify({
|
|
1528
|
-
...settings
|
|
1525
|
+
...settings?.fieldArguments(),
|
|
1529
1526
|
nullable: Boolean(field.isNullable)
|
|
1530
1527
|
})
|
|
1531
1528
|
]
|
|
1532
1529
|
});
|
|
1533
1530
|
if (isCustomsApplicable) {
|
|
1534
1531
|
for (const options of settings || []) {
|
|
1535
|
-
if ((
|
|
1532
|
+
if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
|
|
1536
1533
|
property.decorators.push({
|
|
1537
1534
|
name: options.name,
|
|
1538
1535
|
arguments: options.arguments
|
|
@@ -1566,8 +1563,7 @@ function purgeOutput(emitter) {
|
|
|
1566
1563
|
}
|
|
1567
1564
|
__name(purgeOutput, "purgeOutput");
|
|
1568
1565
|
function begin({ project, output }) {
|
|
1569
|
-
|
|
1570
|
-
const sourceFiles = (_a = project.getDirectory(output)) == null ? void 0 : _a.getDescendantSourceFiles();
|
|
1566
|
+
const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
|
|
1571
1567
|
if (sourceFiles) {
|
|
1572
1568
|
for (const sourceFile of sourceFiles) {
|
|
1573
1569
|
sourceFile.delete();
|
|
@@ -1576,12 +1572,11 @@ function begin({ project, output }) {
|
|
|
1576
1572
|
}
|
|
1577
1573
|
__name(begin, "begin");
|
|
1578
1574
|
async function end({ project, output }) {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
for (const directory1 of directories || []) {
|
|
1575
|
+
const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
|
|
1576
|
+
for (const directory of directories || []) {
|
|
1582
1577
|
try {
|
|
1583
|
-
await import_fs.promises.rmdir(
|
|
1584
|
-
} catch
|
|
1578
|
+
await import_fs.promises.rmdir(directory);
|
|
1579
|
+
} catch {
|
|
1585
1580
|
}
|
|
1586
1581
|
}
|
|
1587
1582
|
}
|
|
@@ -1631,23 +1626,23 @@ function beforeGenerateFiles2(args) {
|
|
|
1631
1626
|
}
|
|
1632
1627
|
}
|
|
1633
1628
|
if (config.reExport === ReExport.Single) {
|
|
1634
|
-
const
|
|
1629
|
+
const exportDeclarations1 = project.getSourceFiles().filter((sourceFile) => {
|
|
1635
1630
|
return sourceFile.getBaseName() !== "index.ts";
|
|
1636
1631
|
}).map((sourceFile) => getExportDeclaration2(rootDirectory, sourceFile));
|
|
1637
1632
|
rootDirectory.createSourceFile("index.ts", {
|
|
1638
|
-
statements:
|
|
1633
|
+
statements: exportDeclarations1
|
|
1639
1634
|
}, {
|
|
1640
1635
|
overwrite: true
|
|
1641
1636
|
});
|
|
1642
1637
|
}
|
|
1643
1638
|
if (config.reExport === ReExport.All) {
|
|
1644
|
-
const
|
|
1645
|
-
for (const
|
|
1646
|
-
const sourceFile =
|
|
1647
|
-
|
|
1639
|
+
const exportDeclarations2 = [];
|
|
1640
|
+
for (const directory1 of rootDirectory.getDirectories()) {
|
|
1641
|
+
const sourceFile = directory1.getSourceFileOrThrow("index.ts");
|
|
1642
|
+
exportDeclarations2.push(getExportDeclaration2(rootDirectory, sourceFile));
|
|
1648
1643
|
}
|
|
1649
1644
|
rootDirectory.createSourceFile("index.ts", {
|
|
1650
|
-
statements:
|
|
1645
|
+
statements: exportDeclarations2
|
|
1651
1646
|
}, {
|
|
1652
1647
|
overwrite: true
|
|
1653
1648
|
});
|
|
@@ -1704,7 +1699,7 @@ function registerEnum(enumType, args) {
|
|
|
1704
1699
|
...importDeclarations.toStatements(),
|
|
1705
1700
|
enumStructure,
|
|
1706
1701
|
"\n",
|
|
1707
|
-
`registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum
|
|
1702
|
+
`registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum?.documentation)} })`
|
|
1708
1703
|
]
|
|
1709
1704
|
});
|
|
1710
1705
|
}
|
|
@@ -1751,7 +1746,6 @@ var import_json55 = __toESM(require("json5"));
|
|
|
1751
1746
|
var import_lodash7 = require("lodash");
|
|
1752
1747
|
var import_outmatch3 = __toESM(require("outmatch"));
|
|
1753
1748
|
function createConfig(data) {
|
|
1754
|
-
var _a;
|
|
1755
1749
|
const config = (0, import_lodash7.merge)({}, (0, import_flat.unflatten)(data, {
|
|
1756
1750
|
delimiter: "_"
|
|
1757
1751
|
}));
|
|
@@ -1770,7 +1764,7 @@ function createConfig(data) {
|
|
|
1770
1764
|
config.reExport = "All";
|
|
1771
1765
|
}
|
|
1772
1766
|
}
|
|
1773
|
-
const fields = Object.fromEntries(Object.entries(
|
|
1767
|
+
const fields = Object.fromEntries(Object.entries(config.fields ?? {}).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
|
|
1774
1768
|
const fieldSetting = {
|
|
1775
1769
|
arguments: [],
|
|
1776
1770
|
output: toBoolean(value.output),
|
|
@@ -1879,18 +1873,18 @@ function generateFileName(args) {
|
|
|
1879
1873
|
return (0, import_lodash8.kebabCase)(result);
|
|
1880
1874
|
},
|
|
1881
1875
|
get name() {
|
|
1882
|
-
let
|
|
1876
|
+
let result1 = (0, import_lodash8.kebabCase)(name);
|
|
1883
1877
|
for (const suffix of [
|
|
1884
1878
|
"input",
|
|
1885
1879
|
"args",
|
|
1886
1880
|
"enum"
|
|
1887
1881
|
]) {
|
|
1888
1882
|
const ending = `-${suffix}`;
|
|
1889
|
-
if (type === suffix &&
|
|
1890
|
-
|
|
1883
|
+
if (type === suffix && result1.endsWith(ending)) {
|
|
1884
|
+
result1 = result1.slice(0, -ending.length);
|
|
1891
1885
|
}
|
|
1892
1886
|
}
|
|
1893
|
-
return
|
|
1887
|
+
return result1;
|
|
1894
1888
|
},
|
|
1895
1889
|
plural: {
|
|
1896
1890
|
get type() {
|
|
@@ -1902,10 +1896,10 @@ function generateFileName(args) {
|
|
|
1902
1896
|
__name(generateFileName, "generateFileName");
|
|
1903
1897
|
|
|
1904
1898
|
// src/helpers/factory-get-source-file.ts
|
|
1905
|
-
function factoryGetSourceFile(
|
|
1906
|
-
const { outputFilePattern, output, getModelName: getModelName2, project } =
|
|
1907
|
-
return /* @__PURE__ */ __name(function getSourceFile(
|
|
1908
|
-
const { name, type } =
|
|
1899
|
+
function factoryGetSourceFile(args) {
|
|
1900
|
+
const { outputFilePattern, output, getModelName: getModelName2, project } = args;
|
|
1901
|
+
return /* @__PURE__ */ __name(function getSourceFile(args2) {
|
|
1902
|
+
const { name, type } = args2;
|
|
1909
1903
|
let filePath = generateFileName({
|
|
1910
1904
|
getModelName: getModelName2,
|
|
1911
1905
|
name,
|
|
@@ -1942,30 +1936,30 @@ function getModelName(args) {
|
|
|
1942
1936
|
}
|
|
1943
1937
|
}
|
|
1944
1938
|
for (const keyword1 of endsWithKeywords) {
|
|
1945
|
-
const [
|
|
1946
|
-
if (modelNames.includes(
|
|
1947
|
-
return
|
|
1939
|
+
const [test1] = name.split(keyword1).slice(-1);
|
|
1940
|
+
if (modelNames.includes(test1)) {
|
|
1941
|
+
return test1;
|
|
1948
1942
|
}
|
|
1949
1943
|
}
|
|
1950
1944
|
for (const [start, end2] of middleKeywords) {
|
|
1951
|
-
let
|
|
1952
|
-
if (modelNames.includes(
|
|
1953
|
-
return
|
|
1945
|
+
let test2 = name.slice(start.length).slice(0, -end2.length);
|
|
1946
|
+
if (modelNames.includes(test2)) {
|
|
1947
|
+
return test2;
|
|
1954
1948
|
}
|
|
1955
|
-
|
|
1956
|
-
if (modelNames.includes(
|
|
1957
|
-
return
|
|
1949
|
+
test2 = name.slice(0, -(start + end2).length);
|
|
1950
|
+
if (modelNames.includes(test2)) {
|
|
1951
|
+
return test2;
|
|
1958
1952
|
}
|
|
1959
1953
|
}
|
|
1960
1954
|
if (name.slice(-19) === "CompoundUniqueInput") {
|
|
1961
|
-
const
|
|
1962
|
-
const models = modelNames.filter((x) =>
|
|
1955
|
+
const test3 = name.slice(0, -19);
|
|
1956
|
+
const models = modelNames.filter((x) => test3.startsWith(x)).sort((a, b) => b.length - a.length);
|
|
1963
1957
|
return (0, import_lodash9.first)(models);
|
|
1964
1958
|
}
|
|
1965
1959
|
if (name.slice(-5) === "Count") {
|
|
1966
|
-
const
|
|
1967
|
-
if (modelNames.includes(
|
|
1968
|
-
return
|
|
1960
|
+
const test4 = name.slice(0, -5);
|
|
1961
|
+
if (modelNames.includes(test4)) {
|
|
1962
|
+
return test4;
|
|
1969
1963
|
}
|
|
1970
1964
|
}
|
|
1971
1965
|
return void 0;
|
|
@@ -2084,9 +2078,8 @@ var middleKeywords = [
|
|
|
2084
2078
|
|
|
2085
2079
|
// src/generate.ts
|
|
2086
2080
|
async function generate(args) {
|
|
2087
|
-
var _a;
|
|
2088
2081
|
const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
|
|
2089
|
-
const generatorOutputValue =
|
|
2082
|
+
const generatorOutputValue = generator.output?.value;
|
|
2090
2083
|
(0, import_assert6.ok)(generatorOutputValue, "Missing generator configuration: output");
|
|
2091
2084
|
const eventEmitter = new import_await_event_emitter.default();
|
|
2092
2085
|
eventEmitter.on("Warning", warning);
|
|
@@ -2149,7 +2142,8 @@ async function generate(args) {
|
|
|
2149
2142
|
typeNames: /* @__PURE__ */ new Set(),
|
|
2150
2143
|
enums: (0, import_lodash10.mapKeys)(datamodel.enums, (x) => x.name),
|
|
2151
2144
|
getModelName: getModelName2,
|
|
2152
|
-
removeTypes
|
|
2145
|
+
removeTypes,
|
|
2146
|
+
classTransformerTypeModels: /* @__PURE__ */ new Set()
|
|
2153
2147
|
};
|
|
2154
2148
|
if (connectCallback) {
|
|
2155
2149
|
await connectCallback(eventEmitter, eventArguments);
|
|
@@ -2165,19 +2159,19 @@ async function generate(args) {
|
|
|
2165
2159
|
for (const enumType of enumTypes.prisma.concat(enumTypes.model || [])) {
|
|
2166
2160
|
await eventEmitter.emit("EnumType", enumType, eventArguments);
|
|
2167
2161
|
}
|
|
2168
|
-
for (const
|
|
2169
|
-
await eventEmitter.emit("ModelOutputType",
|
|
2162
|
+
for (const outputType1 of outputObjectTypes.model) {
|
|
2163
|
+
await eventEmitter.emit("ModelOutputType", outputType1, eventArguments);
|
|
2170
2164
|
}
|
|
2171
2165
|
const queryOutputTypes = [];
|
|
2172
|
-
for (const
|
|
2166
|
+
for (const outputType2 of outputObjectTypes.prisma) {
|
|
2173
2167
|
if ([
|
|
2174
2168
|
"Query",
|
|
2175
2169
|
"Mutation"
|
|
2176
|
-
].includes(
|
|
2177
|
-
queryOutputTypes.push(
|
|
2170
|
+
].includes(outputType2.name)) {
|
|
2171
|
+
queryOutputTypes.push(outputType2);
|
|
2178
2172
|
continue;
|
|
2179
2173
|
}
|
|
2180
|
-
await eventEmitter.emit("OutputType",
|
|
2174
|
+
await eventEmitter.emit("OutputType", outputType2, eventArguments);
|
|
2181
2175
|
}
|
|
2182
2176
|
const inputTypes = inputObjectTypes.prisma.concat(inputObjectTypes.model || []);
|
|
2183
2177
|
for (const inputType1 of inputTypes) {
|
|
@@ -2194,8 +2188,8 @@ async function generate(args) {
|
|
|
2194
2188
|
await eventEmitter.emit("BeforeInputType", event);
|
|
2195
2189
|
await eventEmitter.emit("InputType", event);
|
|
2196
2190
|
}
|
|
2197
|
-
for (const
|
|
2198
|
-
for (const field of
|
|
2191
|
+
for (const outputType3 of queryOutputTypes) {
|
|
2192
|
+
for (const field of outputType3.fields) {
|
|
2199
2193
|
await eventEmitter.emit("ArgsType", field, eventArguments);
|
|
2200
2194
|
}
|
|
2201
2195
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-nestjs-graphql",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@prisma/generator-helper": "^
|
|
55
|
+
"@prisma/generator-helper": "^4.1.0",
|
|
56
56
|
"await-event-emitter": "^2.0.2",
|
|
57
57
|
"filenamify": "4.X",
|
|
58
58
|
"flat": "^5.0.2",
|
|
@@ -65,46 +65,46 @@
|
|
|
65
65
|
"ts-morph": ">=11"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@commitlint/cli": "^17.0.
|
|
69
|
-
"@commitlint/config-conventional": "^17.0.
|
|
70
|
-
"@nestjs/apollo": "^10.0.
|
|
71
|
-
"@nestjs/common": "^
|
|
72
|
-
"@nestjs/core": "^
|
|
73
|
-
"@nestjs/graphql": "^10.0.
|
|
74
|
-
"@nestjs/platform-express": "^
|
|
68
|
+
"@commitlint/cli": "^17.0.3",
|
|
69
|
+
"@commitlint/config-conventional": "^17.0.3",
|
|
70
|
+
"@nestjs/apollo": "^10.0.19",
|
|
71
|
+
"@nestjs/common": "^9.0.5",
|
|
72
|
+
"@nestjs/core": "^9.0.5",
|
|
73
|
+
"@nestjs/graphql": "^10.0.21",
|
|
74
|
+
"@nestjs/platform-express": "^9.0.5",
|
|
75
75
|
"@paljs/plugins": "^4.1.0",
|
|
76
|
-
"@prisma/client": "^
|
|
76
|
+
"@prisma/client": "^4.1.0",
|
|
77
77
|
"@semantic-release/changelog": "^6.0.1",
|
|
78
78
|
"@semantic-release/git": "^10.0.1",
|
|
79
|
-
"@swc/core": "^1.2.
|
|
80
|
-
"@swc/helpers": "^0.3
|
|
79
|
+
"@swc/core": "^1.2.218",
|
|
80
|
+
"@swc/helpers": "^0.4.3",
|
|
81
81
|
"@swc/register": "^0.1.10",
|
|
82
82
|
"@types/flat": "^5.0.2",
|
|
83
83
|
"@types/lodash": "^4.14.182",
|
|
84
84
|
"@types/mocha": "^9.1.1",
|
|
85
|
-
"@types/node": "^
|
|
85
|
+
"@types/node": "^18.0.6",
|
|
86
86
|
"@types/pluralize": "^0.0.29",
|
|
87
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
88
|
-
"@typescript-eslint/parser": "^5.
|
|
89
|
-
"apollo-server-express": "^3.
|
|
90
|
-
"c8": "^7.
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
|
88
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
89
|
+
"apollo-server-express": "^3.10.0",
|
|
90
|
+
"c8": "^7.12.0",
|
|
91
91
|
"class-transformer": "^0.5.1",
|
|
92
92
|
"class-validator": "^0.13.2",
|
|
93
|
-
"commitizen": "^4.2.
|
|
94
|
-
"cz-customizable": "^6.
|
|
93
|
+
"commitizen": "^4.2.5",
|
|
94
|
+
"cz-customizable": "^6.9.1",
|
|
95
95
|
"decimal.js": "^10.3.1",
|
|
96
|
-
"eslint": "^8.
|
|
96
|
+
"eslint": "^8.20.0",
|
|
97
97
|
"eslint-import-resolver-node": "^0.3.6",
|
|
98
98
|
"eslint-plugin-etc": "^2.0.2",
|
|
99
99
|
"eslint-plugin-import": "^2.26.0",
|
|
100
100
|
"eslint-plugin-only-warn": "^1.0.3",
|
|
101
|
-
"eslint-plugin-prettier": "^4.
|
|
101
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
102
102
|
"eslint-plugin-regexp": "^1.7.0",
|
|
103
103
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
104
104
|
"eslint-plugin-sort-class-members": "^1.14.1",
|
|
105
|
-
"eslint-plugin-unicorn": "^
|
|
105
|
+
"eslint-plugin-unicorn": "^43.0.2",
|
|
106
106
|
"eslint-plugin-wix-editor": "^3.3.0",
|
|
107
|
-
"expect": "^
|
|
107
|
+
"expect": "^29.0.1",
|
|
108
108
|
"ghooks": "^2.0.4",
|
|
109
109
|
"git-branch-is": "^4.0.0",
|
|
110
110
|
"graphql": "^16.5.0",
|
|
@@ -113,18 +113,18 @@
|
|
|
113
113
|
"mocha": "^10.0.0",
|
|
114
114
|
"ololog": "^1.1.175",
|
|
115
115
|
"precise-commits": "^1.0.2",
|
|
116
|
-
"prettier": "^2.
|
|
117
|
-
"prisma": "^
|
|
118
|
-
"prisma-graphql-type-decimal": "^2.0.
|
|
116
|
+
"prettier": "^2.7.1",
|
|
117
|
+
"prisma": "^4.1.0",
|
|
118
|
+
"prisma-graphql-type-decimal": "^2.0.4",
|
|
119
119
|
"reflect-metadata": "^0.1.13",
|
|
120
120
|
"request": "^2.88.2",
|
|
121
|
-
"rxjs": "^7.5.
|
|
122
|
-
"semantic-release": "^19.0.
|
|
121
|
+
"rxjs": "^7.5.6",
|
|
122
|
+
"semantic-release": "^19.0.3",
|
|
123
123
|
"simplytyped": "^3.3.0",
|
|
124
124
|
"temp-dir": "^2.0.0",
|
|
125
|
-
"ts-node": "^10.
|
|
125
|
+
"ts-node": "^10.9.1",
|
|
126
126
|
"tslib": "^2.4.0",
|
|
127
|
-
"typescript": "^4.
|
|
127
|
+
"typescript": "^4.7.4",
|
|
128
128
|
"watchexec-bin": "^1.0.0"
|
|
129
129
|
}
|
|
130
130
|
}
|