prisma-nestjs-graphql 20.0.3 → 20.1.0
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 +3 -1
- package/generate.cjs +102 -106
- package/generate.d.ts +19 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -372,6 +372,7 @@ For example:
|
|
|
372
372
|
model Product {
|
|
373
373
|
/// Old description
|
|
374
374
|
/// @deprecated Use new name instead
|
|
375
|
+
/// @complexity 1
|
|
375
376
|
oldName String
|
|
376
377
|
}
|
|
377
378
|
```
|
|
@@ -388,6 +389,7 @@ export class Product {
|
|
|
388
389
|
@Field(() => String, {
|
|
389
390
|
description: 'Old description',
|
|
390
391
|
deprecationReason: 'Use new name instead',
|
|
392
|
+
complexity: 1
|
|
391
393
|
})
|
|
392
394
|
oldName: string;
|
|
393
395
|
}
|
|
@@ -726,7 +728,7 @@ model User {
|
|
|
726
728
|
export class User {}
|
|
727
729
|
```
|
|
728
730
|
|
|
729
|
-
### Using
|
|
731
|
+
### Using library in other generators
|
|
730
732
|
|
|
731
733
|
```ts
|
|
732
734
|
import { generate } from 'prisma-nestjs-graphql/generate';
|
package/generate.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var pluralize = require('pluralize');
|
|
|
16
16
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
17
17
|
var require$1 = (
|
|
18
18
|
false
|
|
19
|
-
? /* @__PURE__ */ module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('generate.cjs', document.baseURI).href)))
|
|
19
|
+
? /* @__PURE__ */ module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('generate.cjs', document.baseURI).href)))
|
|
20
20
|
: require
|
|
21
21
|
);
|
|
22
22
|
|
|
@@ -36,8 +36,7 @@ function argsType(field, args) {
|
|
|
36
36
|
if (["queryRaw", "executeRaw"].includes(field.name)) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
if (isCreateManyReturn(field.name))
|
|
40
|
-
return;
|
|
39
|
+
if (isCreateManyReturn(field.name)) return;
|
|
41
40
|
const { eventEmitter, typeNames, getModelName } = args;
|
|
42
41
|
let className = pascalCase(`${field.name}Args`);
|
|
43
42
|
const modelName = getModelName(className) || "";
|
|
@@ -61,7 +60,7 @@ function argsType(field, args) {
|
|
|
61
60
|
const names = ["Count", "Avg", "Sum", "Min", "Max"];
|
|
62
61
|
if (`${modelName}GroupByArgs` === inputType.name) {
|
|
63
62
|
const byField = inputType.fields.find((f) => f.name === "by");
|
|
64
|
-
if (byField == null ?
|
|
63
|
+
if (byField == null ? undefined : byField.inputTypes) {
|
|
65
64
|
byField.inputTypes = byField.inputTypes.filter((inputType2) => inputType2.isList);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
@@ -247,8 +246,8 @@ class ImportDeclarationMap extends Map {
|
|
|
247
246
|
const value = {
|
|
248
247
|
moduleSpecifier: from,
|
|
249
248
|
namedImports: [],
|
|
250
|
-
defaultImport:
|
|
251
|
-
namespaceImport:
|
|
249
|
+
defaultImport: undefined,
|
|
250
|
+
namespaceImport: undefined
|
|
252
251
|
};
|
|
253
252
|
if (namedImport === true && namespaceImport) {
|
|
254
253
|
value.namedImports = [{ name: namespaceImport }];
|
|
@@ -281,7 +280,7 @@ async function generateFiles(args) {
|
|
|
281
280
|
const { project, config, output, eventEmitter } = args;
|
|
282
281
|
if (config.emitSingle) {
|
|
283
282
|
const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
|
|
284
|
-
const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts",
|
|
283
|
+
const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", undefined, { overwrite: true });
|
|
285
284
|
const statements = project.getSourceFiles().flatMap((s) => {
|
|
286
285
|
var _a, _b;
|
|
287
286
|
if (s === sourceFile) {
|
|
@@ -296,7 +295,7 @@ async function generateFiles(args) {
|
|
|
296
295
|
}
|
|
297
296
|
for (const property of statement.properties || []) {
|
|
298
297
|
for (const decorator of property.decorators || []) {
|
|
299
|
-
const fullName = (_b = (_a = classDeclaration == null ?
|
|
298
|
+
const fullName = (_b = (_a = classDeclaration == null ? undefined : classDeclaration.getProperty(property.name)) == null ? undefined : _a.getDecorator(decorator.name)) == null ? undefined : _b.getFullName();
|
|
300
299
|
assert.ok(
|
|
301
300
|
fullName,
|
|
302
301
|
`Cannot get full name of decorator of class ${statement.name}`
|
|
@@ -435,11 +434,11 @@ function getGraphqlImport(args) {
|
|
|
435
434
|
return { name: typeName, specifier: "@nestjs/graphql" };
|
|
436
435
|
}
|
|
437
436
|
case "DateTime": {
|
|
438
|
-
return { name: "Date", specifier:
|
|
437
|
+
return { name: "Date", specifier: undefined };
|
|
439
438
|
}
|
|
440
439
|
case "true":
|
|
441
440
|
case "Boolean": {
|
|
442
|
-
return { name: "Boolean", specifier:
|
|
441
|
+
return { name: "Boolean", specifier: undefined };
|
|
443
442
|
}
|
|
444
443
|
case "Decimal": {
|
|
445
444
|
return {
|
|
@@ -451,7 +450,7 @@ function getGraphqlImport(args) {
|
|
|
451
450
|
return { name: "GraphQLJSON", specifier: "graphql-type-json" };
|
|
452
451
|
}
|
|
453
452
|
}
|
|
454
|
-
return { name: "String", specifier:
|
|
453
|
+
return { name: "String", specifier: undefined };
|
|
455
454
|
}
|
|
456
455
|
let sourceFileType = fileTypeByLocation(location);
|
|
457
456
|
if (sourceFileType === "output" && fileType === "model") {
|
|
@@ -666,33 +665,33 @@ function inputType(args) {
|
|
|
666
665
|
if (inputTypes.length === 0) {
|
|
667
666
|
continue;
|
|
668
667
|
}
|
|
669
|
-
const usePattern = (useInputType == null ?
|
|
668
|
+
const usePattern = (useInputType == null ? undefined : useInputType.ALL) || (useInputType == null ? undefined : useInputType[name]);
|
|
670
669
|
const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
|
|
671
670
|
const { isList, location, type } = graphqlInputType;
|
|
672
671
|
const typeName = String(type);
|
|
673
|
-
const settings = modelFieldSettings == null ?
|
|
674
|
-
const propertySettings = settings == null ?
|
|
672
|
+
const settings = modelFieldSettings == null ? undefined : modelFieldSettings.get(name);
|
|
673
|
+
const propertySettings = settings == null ? undefined : settings.getPropertyType({
|
|
675
674
|
name: inputType2.name,
|
|
676
675
|
input: true
|
|
677
676
|
});
|
|
678
|
-
const modelField = model == null ?
|
|
679
|
-
const isCustomsApplicable = typeName === (modelField == null ?
|
|
677
|
+
const modelField = model == null ? undefined : model.fields.find((f) => f.name === name);
|
|
678
|
+
const isCustomsApplicable = typeName === (modelField == null ? undefined : modelField.type);
|
|
680
679
|
const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
|
|
681
680
|
const whereUniqueInputType = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((name2) => `'${name2}'`).join(" | ")}>`;
|
|
682
681
|
const propertyType = lodash.castArray(
|
|
683
|
-
(propertySettings == null ?
|
|
682
|
+
(propertySettings == null ? undefined : propertySettings.name) || whereUniqueInputType || getPropertyType({
|
|
684
683
|
location,
|
|
685
684
|
type: typeName
|
|
686
685
|
})
|
|
687
686
|
);
|
|
688
687
|
const hasExclamationToken = Boolean(
|
|
689
|
-
isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ?
|
|
688
|
+
isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ? undefined : atLeastKeys.includes(name))
|
|
690
689
|
);
|
|
691
690
|
const property = propertyStructure({
|
|
692
691
|
name,
|
|
693
692
|
isNullable: !isRequired,
|
|
694
|
-
hasExclamationToken: hasExclamationToken ||
|
|
695
|
-
hasQuestionToken: hasExclamationToken ? false :
|
|
693
|
+
hasExclamationToken: hasExclamationToken || undefined,
|
|
694
|
+
hasQuestionToken: hasExclamationToken ? false : undefined,
|
|
696
695
|
propertyType,
|
|
697
696
|
isList
|
|
698
697
|
});
|
|
@@ -705,13 +704,13 @@ function inputType(args) {
|
|
|
705
704
|
importDeclarations.add("Prisma", config.prismaClientImport);
|
|
706
705
|
}
|
|
707
706
|
let graphqlType;
|
|
708
|
-
const shouldHideField = (settings == null ?
|
|
707
|
+
const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
|
|
709
708
|
name: inputType2.name,
|
|
710
709
|
input: true
|
|
711
710
|
})) || config.decorate.some(
|
|
712
711
|
(d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
|
|
713
712
|
);
|
|
714
|
-
const fieldType = settings == null ?
|
|
713
|
+
const fieldType = settings == null ? undefined : settings.getFieldType({
|
|
715
714
|
name: inputType2.name,
|
|
716
715
|
input: true
|
|
717
716
|
});
|
|
@@ -748,7 +747,7 @@ function inputType(args) {
|
|
|
748
747
|
arguments: [
|
|
749
748
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
750
749
|
JSON5.stringify({
|
|
751
|
-
...settings == null ?
|
|
750
|
+
...settings == null ? undefined : settings.fieldArguments(),
|
|
752
751
|
nullable: !isRequired
|
|
753
752
|
})
|
|
754
753
|
]
|
|
@@ -767,7 +766,7 @@ function inputType(args) {
|
|
|
767
766
|
arguments: ["transformToDecimal"]
|
|
768
767
|
}
|
|
769
768
|
);
|
|
770
|
-
} else if (location === "inputObjectTypes" && ((modelField == null ?
|
|
769
|
+
} else if (location === "inputObjectTypes" && ((modelField == null ? undefined : modelField.type) === "Decimal" || [
|
|
771
770
|
"connect",
|
|
772
771
|
"connectOrCreate",
|
|
773
772
|
"create",
|
|
@@ -781,7 +780,7 @@ function inputType(args) {
|
|
|
781
780
|
"updateMany",
|
|
782
781
|
"upsert",
|
|
783
782
|
"where"
|
|
784
|
-
].includes(name) || classTransformerTypeModels.has(getModelName(graphqlType) || "") || (modelField == null ?
|
|
783
|
+
].includes(name) || classTransformerTypeModels.has(getModelName(graphqlType) || "") || (modelField == null ? undefined : modelField.kind) === "object" && models.get(modelField.type) && ((_a = models.get(modelField.type)) == null ? undefined : _a.fields.some(
|
|
785
784
|
(field2) => field2.kind === "object" && classTransformerTypeModels.has(field2.type)
|
|
786
785
|
)))) {
|
|
787
786
|
importDeclarations.add("Type", "class-transformer");
|
|
@@ -789,7 +788,7 @@ function inputType(args) {
|
|
|
789
788
|
}
|
|
790
789
|
if (isCustomsApplicable) {
|
|
791
790
|
for (const options of settings || []) {
|
|
792
|
-
if ((_c = options.kind === "Decorator" && options.input && ((_b = options.match) == null ?
|
|
791
|
+
if ((_c = options.kind === "Decorator" && options.input && ((_b = options.match) == null ? undefined : _b.call(options, name))) != null ? _c : true) {
|
|
793
792
|
property.decorators.push({
|
|
794
793
|
name: options.name,
|
|
795
794
|
arguments: options.arguments
|
|
@@ -803,7 +802,7 @@ function inputType(args) {
|
|
|
803
802
|
if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
|
|
804
803
|
property.decorators.push({
|
|
805
804
|
name: decorate.name,
|
|
806
|
-
arguments: (_d = decorate.arguments) == null ?
|
|
805
|
+
arguments: (_d = decorate.arguments) == null ? undefined : _d.map((x) => pupa(x, { propertyType }))
|
|
807
806
|
});
|
|
808
807
|
importDeclarations.create(decorate);
|
|
809
808
|
}
|
|
@@ -829,7 +828,7 @@ class ObjectSettings extends Array {
|
|
|
829
828
|
var _a;
|
|
830
829
|
const hideField = this.find((s) => s.name === "HideField");
|
|
831
830
|
return Boolean(
|
|
832
|
-
(hideField == null ?
|
|
831
|
+
(hideField == null ? undefined : hideField.input) && input || (hideField == null ? undefined : hideField.output) && output || ((_a = hideField == null ? undefined : hideField.match) == null ? undefined : _a.call(hideField, name))
|
|
833
832
|
);
|
|
834
833
|
}
|
|
835
834
|
getFieldType({
|
|
@@ -839,16 +838,16 @@ class ObjectSettings extends Array {
|
|
|
839
838
|
}) {
|
|
840
839
|
const fieldType = this.find((s) => s.kind === "FieldType");
|
|
841
840
|
if (!fieldType) {
|
|
842
|
-
return
|
|
841
|
+
return undefined;
|
|
843
842
|
}
|
|
844
843
|
if (fieldType.match) {
|
|
845
|
-
return fieldType.match(name) ? fieldType :
|
|
844
|
+
return fieldType.match(name) ? fieldType : undefined;
|
|
846
845
|
}
|
|
847
846
|
if (input && !fieldType.input) {
|
|
848
|
-
return
|
|
847
|
+
return undefined;
|
|
849
848
|
}
|
|
850
849
|
if (output && !fieldType.output) {
|
|
851
|
-
return
|
|
850
|
+
return undefined;
|
|
852
851
|
}
|
|
853
852
|
return fieldType;
|
|
854
853
|
}
|
|
@@ -859,16 +858,16 @@ class ObjectSettings extends Array {
|
|
|
859
858
|
}) {
|
|
860
859
|
const propertyType = this.find((s) => s.kind === "PropertyType");
|
|
861
860
|
if (!propertyType) {
|
|
862
|
-
return
|
|
861
|
+
return undefined;
|
|
863
862
|
}
|
|
864
863
|
if (propertyType.match) {
|
|
865
|
-
return propertyType.match(name) ? propertyType :
|
|
864
|
+
return propertyType.match(name) ? propertyType : undefined;
|
|
866
865
|
}
|
|
867
866
|
if (input && !propertyType.input) {
|
|
868
|
-
return
|
|
867
|
+
return undefined;
|
|
869
868
|
}
|
|
870
869
|
if (output && !propertyType.output) {
|
|
871
|
-
return
|
|
870
|
+
return undefined;
|
|
872
871
|
}
|
|
873
872
|
return propertyType;
|
|
874
873
|
}
|
|
@@ -922,7 +921,7 @@ function createObjectSettings(args) {
|
|
|
922
921
|
}
|
|
923
922
|
return {
|
|
924
923
|
settings: result,
|
|
925
|
-
documentation: documentationLines.filter(Boolean).join("\n") ||
|
|
924
|
+
documentation: documentationLines.filter(Boolean).join("\n") || undefined
|
|
926
925
|
};
|
|
927
926
|
}
|
|
928
927
|
function createSettingElement({
|
|
@@ -934,14 +933,21 @@ function createSettingElement({
|
|
|
934
933
|
var _a, _b, _c, _d, _e;
|
|
935
934
|
const result = {
|
|
936
935
|
documentLine: "",
|
|
937
|
-
element:
|
|
936
|
+
element: undefined
|
|
938
937
|
};
|
|
939
938
|
if (line.startsWith("@deprecated")) {
|
|
940
939
|
fieldElement.arguments["deprecationReason"] = lodash.trim(line.slice(11));
|
|
941
940
|
result.element = fieldElement;
|
|
942
941
|
return result;
|
|
943
942
|
}
|
|
944
|
-
|
|
943
|
+
if (line.startsWith("@complexity")) {
|
|
944
|
+
let n = Number.parseInt(lodash.trim(line.slice(11)));
|
|
945
|
+
if (n !== n || n < 1) n = 1;
|
|
946
|
+
fieldElement.arguments["complexity"] = n;
|
|
947
|
+
result.element = fieldElement;
|
|
948
|
+
return result;
|
|
949
|
+
}
|
|
950
|
+
const name = (_a = match == null ? undefined : match.groups) == null ? undefined : _a.name;
|
|
945
951
|
if (!(match && name)) {
|
|
946
952
|
result.documentLine = line;
|
|
947
953
|
return result;
|
|
@@ -960,14 +966,14 @@ function createSettingElement({
|
|
|
960
966
|
Object.assign(element, hideFieldDecorator(match));
|
|
961
967
|
return result;
|
|
962
968
|
}
|
|
963
|
-
if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ?
|
|
969
|
+
if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? undefined : _b.args)) {
|
|
964
970
|
const options2 = customType(match.groups.args);
|
|
965
971
|
lodash.merge(element, options2.namespace && config.fields[options2.namespace], options2, {
|
|
966
972
|
kind: name
|
|
967
973
|
});
|
|
968
974
|
return result;
|
|
969
975
|
}
|
|
970
|
-
if (name === "ObjectType" && ((_c = match.groups) == null ?
|
|
976
|
+
if (name === "ObjectType" && ((_c = match.groups) == null ? undefined : _c.args)) {
|
|
971
977
|
element.kind = "ObjectType";
|
|
972
978
|
const options2 = customType(match.groups.args);
|
|
973
979
|
if (typeof options2[0] === "string" && options2[0]) {
|
|
@@ -982,7 +988,7 @@ function createSettingElement({
|
|
|
982
988
|
};
|
|
983
989
|
return result;
|
|
984
990
|
}
|
|
985
|
-
if (name === "Directive" && ((_d = match.groups) == null ?
|
|
991
|
+
if (name === "Directive" && ((_d = match.groups) == null ? undefined : _d.args)) {
|
|
986
992
|
const options2 = customType(match.groups.args);
|
|
987
993
|
lodash.merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
|
|
988
994
|
name,
|
|
@@ -996,7 +1002,7 @@ function createSettingElement({
|
|
|
996
1002
|
element.namespaceImport = namespace;
|
|
997
1003
|
const options = {
|
|
998
1004
|
name,
|
|
999
|
-
arguments: (((_e = match.groups) == null ?
|
|
1005
|
+
arguments: (((_e = match.groups) == null ? undefined : _e.args) || "").split(",").map((s) => lodash.trim(s)).filter(Boolean)
|
|
1000
1006
|
};
|
|
1001
1007
|
lodash.merge(element, namespace && config.fields[namespace], options);
|
|
1002
1008
|
return result;
|
|
@@ -1011,7 +1017,7 @@ function customType(args) {
|
|
|
1011
1017
|
Object.assign(result, options);
|
|
1012
1018
|
const namespace = getNamespace(options.name);
|
|
1013
1019
|
result.namespace = namespace;
|
|
1014
|
-
if ((_a = options.name) == null ?
|
|
1020
|
+
if ((_a = options.name) == null ? undefined : _a.includes(".")) {
|
|
1015
1021
|
result.namespaceImport = namespace;
|
|
1016
1022
|
}
|
|
1017
1023
|
if (typeof options.match === "string" || Array.isArray(options.match)) {
|
|
@@ -1025,11 +1031,11 @@ function hideFieldDecorator(match) {
|
|
|
1025
1031
|
name: "HideField",
|
|
1026
1032
|
arguments: [],
|
|
1027
1033
|
from: "@nestjs/graphql",
|
|
1028
|
-
defaultImport:
|
|
1029
|
-
namespaceImport:
|
|
1030
|
-
match:
|
|
1034
|
+
defaultImport: undefined,
|
|
1035
|
+
namespaceImport: undefined,
|
|
1036
|
+
match: undefined
|
|
1031
1037
|
};
|
|
1032
|
-
if (!((_a = match.groups) == null ?
|
|
1038
|
+
if (!((_a = match.groups) == null ? undefined : _a.args)) {
|
|
1033
1039
|
result.output = true;
|
|
1034
1040
|
return result;
|
|
1035
1041
|
}
|
|
@@ -1062,8 +1068,8 @@ function parseArgs(string) {
|
|
|
1062
1068
|
}
|
|
1063
1069
|
}
|
|
1064
1070
|
function getNamespace(name) {
|
|
1065
|
-
if (name ===
|
|
1066
|
-
return
|
|
1071
|
+
if (name === undefined) {
|
|
1072
|
+
return undefined;
|
|
1067
1073
|
}
|
|
1068
1074
|
let result = String(name);
|
|
1069
1075
|
if (result.includes(".")) {
|
|
@@ -1110,7 +1116,7 @@ function createComment(documentation, settings) {
|
|
|
1110
1116
|
for (const line of documentationLines) {
|
|
1111
1117
|
commentLines.push(` * ${line}`);
|
|
1112
1118
|
}
|
|
1113
|
-
const deprecationReason = (_a = settings == null ?
|
|
1119
|
+
const deprecationReason = (_a = settings == null ? undefined : settings.fieldArguments()) == null ? undefined : _a.deprecationReason;
|
|
1114
1120
|
if (deprecationReason) {
|
|
1115
1121
|
commentLines.push(` * @deprecated ${deprecationReason}`);
|
|
1116
1122
|
}
|
|
@@ -1126,8 +1132,7 @@ const nestjsGraphql$1 = "@nestjs/graphql";
|
|
|
1126
1132
|
function modelOutputType(outputType, args) {
|
|
1127
1133
|
var _a, _b, _c, _d, _e, _f;
|
|
1128
1134
|
const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
|
|
1129
|
-
if (isCreateManyReturn(outputType.name))
|
|
1130
|
-
return;
|
|
1135
|
+
if (isCreateManyReturn(outputType.name)) return;
|
|
1131
1136
|
const model = models.get(outputType.name);
|
|
1132
1137
|
assert.ok(model, `Cannot find model by name ${outputType.name}`);
|
|
1133
1138
|
const sourceFile = getSourceFile({
|
|
@@ -1175,8 +1180,7 @@ function modelOutputType(outputType, args) {
|
|
|
1175
1180
|
importDeclarations.add("Field", nestjsGraphql$1);
|
|
1176
1181
|
importDeclarations.add("ObjectType", nestjsGraphql$1);
|
|
1177
1182
|
for (const field of outputType.fields) {
|
|
1178
|
-
if (config.omitModelsCount && field.name === "_count")
|
|
1179
|
-
continue;
|
|
1183
|
+
if (config.omitModelsCount && field.name === "_count") continue;
|
|
1180
1184
|
let fileType = "model";
|
|
1181
1185
|
const { location, isList, type, namespace } = field.outputType;
|
|
1182
1186
|
let outputTypeName = String(type);
|
|
@@ -1184,18 +1188,18 @@ function modelOutputType(outputType, args) {
|
|
|
1184
1188
|
fileType = "output";
|
|
1185
1189
|
outputTypeName = getOutputTypeName(outputTypeName);
|
|
1186
1190
|
}
|
|
1187
|
-
const modelField = (_a = modelFields.get(model.name)) == null ?
|
|
1188
|
-
const settings = (_b = fieldSettings.get(model.name)) == null ?
|
|
1189
|
-
const fieldType = settings == null ?
|
|
1191
|
+
const modelField = (_a = modelFields.get(model.name)) == null ? undefined : _a.get(field.name);
|
|
1192
|
+
const settings = (_b = fieldSettings.get(model.name)) == null ? undefined : _b.get(field.name);
|
|
1193
|
+
const fieldType = settings == null ? undefined : settings.getFieldType({
|
|
1190
1194
|
name: outputType.name,
|
|
1191
1195
|
output: true
|
|
1192
1196
|
});
|
|
1193
|
-
const propertySettings = settings == null ?
|
|
1197
|
+
const propertySettings = settings == null ? undefined : settings.getPropertyType({
|
|
1194
1198
|
name: outputType.name,
|
|
1195
1199
|
output: true
|
|
1196
1200
|
});
|
|
1197
1201
|
const propertyType = lodash.castArray(
|
|
1198
|
-
(propertySettings == null ?
|
|
1202
|
+
(propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
|
|
1199
1203
|
location,
|
|
1200
1204
|
type: outputTypeName
|
|
1201
1205
|
})
|
|
@@ -1214,7 +1218,7 @@ function modelOutputType(outputType, args) {
|
|
|
1214
1218
|
sourceFile,
|
|
1215
1219
|
fileType,
|
|
1216
1220
|
location,
|
|
1217
|
-
isId: modelField == null ?
|
|
1221
|
+
isId: modelField == null ? undefined : modelField.isId,
|
|
1218
1222
|
noTypeId: config.noTypeId,
|
|
1219
1223
|
typeName: outputTypeName,
|
|
1220
1224
|
getSourceFile
|
|
@@ -1232,17 +1236,17 @@ function modelOutputType(outputType, args) {
|
|
|
1232
1236
|
propertyType,
|
|
1233
1237
|
isList
|
|
1234
1238
|
});
|
|
1235
|
-
if (typeof property.leadingTrivia === "string" && (modelField == null ?
|
|
1239
|
+
if (typeof property.leadingTrivia === "string" && (modelField == null ? undefined : modelField.documentation)) {
|
|
1236
1240
|
property.leadingTrivia += createComment(modelField.documentation, settings);
|
|
1237
1241
|
}
|
|
1238
|
-
(_c = classStructure.properties) == null ?
|
|
1242
|
+
(_c = classStructure.properties) == null ? undefined : _c.push(property);
|
|
1239
1243
|
if (propertySettings) {
|
|
1240
1244
|
importDeclarations.create({ ...propertySettings });
|
|
1241
1245
|
} else if (propertyType.includes("Decimal")) {
|
|
1242
1246
|
importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
|
|
1243
1247
|
}
|
|
1244
1248
|
assert.ok(property.decorators, "property.decorators is undefined");
|
|
1245
|
-
const shouldHideField = (settings == null ?
|
|
1249
|
+
const shouldHideField = (settings == null ? undefined : settings.shouldHideField({ name: outputType.name, output: true })) || config.decorate.some(
|
|
1246
1250
|
(d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
|
|
1247
1251
|
);
|
|
1248
1252
|
if (shouldHideField) {
|
|
@@ -1254,17 +1258,17 @@ function modelOutputType(outputType, args) {
|
|
|
1254
1258
|
arguments: [
|
|
1255
1259
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1256
1260
|
JSON5.stringify({
|
|
1257
|
-
...settings == null ?
|
|
1261
|
+
...settings == null ? undefined : settings.fieldArguments(),
|
|
1258
1262
|
nullable: Boolean(field.isNullable),
|
|
1259
1263
|
defaultValue: ["number", "string", "boolean"].includes(
|
|
1260
|
-
typeof (modelField == null ?
|
|
1261
|
-
) ? modelField == null ?
|
|
1262
|
-
description: modelField == null ?
|
|
1264
|
+
typeof (modelField == null ? undefined : modelField.default)
|
|
1265
|
+
) ? modelField == null ? undefined : modelField.default : undefined,
|
|
1266
|
+
description: modelField == null ? undefined : modelField.documentation
|
|
1263
1267
|
})
|
|
1264
1268
|
]
|
|
1265
1269
|
});
|
|
1266
1270
|
for (const setting of settings || []) {
|
|
1267
|
-
if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ?
|
|
1271
|
+
if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ? undefined : _d.call(setting, field.name)) != null ? _e : true)) {
|
|
1268
1272
|
property.decorators.push({
|
|
1269
1273
|
name: setting.name,
|
|
1270
1274
|
arguments: setting.arguments
|
|
@@ -1277,7 +1281,7 @@ function modelOutputType(outputType, args) {
|
|
|
1277
1281
|
if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
|
|
1278
1282
|
property.decorators.push({
|
|
1279
1283
|
name: decorate.name,
|
|
1280
|
-
arguments: (_f = decorate.arguments) == null ?
|
|
1284
|
+
arguments: (_f = decorate.arguments) == null ? undefined : _f.map((x) => pupa(x, { propertyType }))
|
|
1281
1285
|
});
|
|
1282
1286
|
importDeclarations.create(decorate);
|
|
1283
1287
|
}
|
|
@@ -1345,7 +1349,7 @@ function beforeGenerateFiles$1(args) {
|
|
|
1345
1349
|
var _a;
|
|
1346
1350
|
const { project } = args;
|
|
1347
1351
|
for (const sourceFile of project.getSourceFiles()) {
|
|
1348
|
-
const className = (_a = sourceFile.getClass(() => true)) == null ?
|
|
1352
|
+
const className = (_a = sourceFile.getClass(() => true)) == null ? undefined : _a.getName();
|
|
1349
1353
|
if (className && isAtomicOperation(className)) {
|
|
1350
1354
|
project.removeSourceFile(sourceFile);
|
|
1351
1355
|
}
|
|
@@ -1370,9 +1374,8 @@ function outputType(outputType2, args) {
|
|
|
1370
1374
|
const modelName = getModelName(outputType2.name) || "";
|
|
1371
1375
|
const model = models.get(modelName);
|
|
1372
1376
|
const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
|
|
1373
|
-
const isCountOutput = (model == null ?
|
|
1374
|
-
if (!config.emitBlocks.outputs && !isCountOutput)
|
|
1375
|
-
return;
|
|
1377
|
+
const isCountOutput = (model == null ? undefined : model.name) && outputType2.name === `${model.name}CountOutputType`;
|
|
1378
|
+
if (!config.emitBlocks.outputs && !isCountOutput) return;
|
|
1376
1379
|
outputType2.name = getOutputTypeName(outputType2.name);
|
|
1377
1380
|
if (isAggregateOutput) {
|
|
1378
1381
|
eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputType2 });
|
|
@@ -1398,15 +1401,15 @@ function outputType(outputType2, args) {
|
|
|
1398
1401
|
for (const field of outputType2.fields) {
|
|
1399
1402
|
const { location, isList, type } = field.outputType;
|
|
1400
1403
|
const outputTypeName = getOutputTypeName(String(type));
|
|
1401
|
-
const settings = isCountOutput ?
|
|
1402
|
-
const propertySettings = settings == null ?
|
|
1404
|
+
const settings = isCountOutput ? undefined : model && ((_a = fieldSettings.get(model.name)) == null ? undefined : _a.get(field.name));
|
|
1405
|
+
const propertySettings = settings == null ? undefined : settings.getPropertyType({
|
|
1403
1406
|
name: outputType2.name,
|
|
1404
1407
|
output: true
|
|
1405
1408
|
});
|
|
1406
|
-
const isCustomsApplicable = outputTypeName === ((_b = model == null ?
|
|
1409
|
+
const isCustomsApplicable = outputTypeName === ((_b = model == null ? undefined : model.fields.find((f) => f.name === field.name)) == null ? undefined : _b.type);
|
|
1407
1410
|
field.outputType.type = outputTypeName;
|
|
1408
1411
|
const propertyType = lodash.castArray(
|
|
1409
|
-
(propertySettings == null ?
|
|
1412
|
+
(propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
|
|
1410
1413
|
location,
|
|
1411
1414
|
type: outputTypeName
|
|
1412
1415
|
})
|
|
@@ -1414,24 +1417,24 @@ function outputType(outputType2, args) {
|
|
|
1414
1417
|
const property = propertyStructure({
|
|
1415
1418
|
name: field.name,
|
|
1416
1419
|
isNullable: field.isNullable,
|
|
1417
|
-
hasQuestionToken: isCountOutput ? true :
|
|
1420
|
+
hasQuestionToken: isCountOutput ? true : undefined,
|
|
1418
1421
|
propertyType,
|
|
1419
1422
|
isList
|
|
1420
1423
|
});
|
|
1421
|
-
(_c = classStructure.properties) == null ?
|
|
1424
|
+
(_c = classStructure.properties) == null ? undefined : _c.push(property);
|
|
1422
1425
|
if (propertySettings) {
|
|
1423
1426
|
importDeclarations.create({ ...propertySettings });
|
|
1424
1427
|
} else if (propertyType.includes("Decimal")) {
|
|
1425
1428
|
importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
|
|
1426
1429
|
}
|
|
1427
1430
|
let graphqlType;
|
|
1428
|
-
const shouldHideField = (settings == null ?
|
|
1431
|
+
const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
|
|
1429
1432
|
name: outputType2.name,
|
|
1430
1433
|
output: true
|
|
1431
1434
|
})) || config.decorate.some(
|
|
1432
1435
|
(d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
|
|
1433
1436
|
);
|
|
1434
|
-
const fieldType = settings == null ?
|
|
1437
|
+
const fieldType = settings == null ? undefined : settings.getFieldType({
|
|
1435
1438
|
name: outputType2.name,
|
|
1436
1439
|
output: true
|
|
1437
1440
|
});
|
|
@@ -1470,14 +1473,14 @@ function outputType(outputType2, args) {
|
|
|
1470
1473
|
arguments: [
|
|
1471
1474
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1472
1475
|
JSON5.stringify({
|
|
1473
|
-
...settings == null ?
|
|
1476
|
+
...settings == null ? undefined : settings.fieldArguments(),
|
|
1474
1477
|
nullable: Boolean(field.isNullable)
|
|
1475
1478
|
})
|
|
1476
1479
|
]
|
|
1477
1480
|
});
|
|
1478
1481
|
if (isCustomsApplicable) {
|
|
1479
1482
|
for (const options of settings || []) {
|
|
1480
|
-
if ((_e = options.kind === "Decorator" && options.output && ((_d = options.match) == null ?
|
|
1483
|
+
if ((_e = options.kind === "Decorator" && options.output && ((_d = options.match) == null ? undefined : _d.call(options, field.name))) != null ? _e : true) {
|
|
1481
1484
|
property.decorators.push({
|
|
1482
1485
|
name: options.name,
|
|
1483
1486
|
arguments: options.arguments
|
|
@@ -1505,7 +1508,7 @@ function purgeOutput(emitter) {
|
|
|
1505
1508
|
}
|
|
1506
1509
|
function begin({ project, output }) {
|
|
1507
1510
|
var _a;
|
|
1508
|
-
const sourceFiles = (_a = project.getDirectory(output)) == null ?
|
|
1511
|
+
const sourceFiles = (_a = project.getDirectory(output)) == null ? undefined : _a.getDescendantSourceFiles();
|
|
1509
1512
|
if (sourceFiles) {
|
|
1510
1513
|
for (const sourceFile of sourceFiles) {
|
|
1511
1514
|
sourceFile.delete();
|
|
@@ -1514,7 +1517,7 @@ function begin({ project, output }) {
|
|
|
1514
1517
|
}
|
|
1515
1518
|
function end({ project, output }) {
|
|
1516
1519
|
var _a;
|
|
1517
|
-
const directories = (_a = project.getDirectory(output)) == null ?
|
|
1520
|
+
const directories = (_a = project.getDirectory(output)) == null ? undefined : _a.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
|
|
1518
1521
|
for (const directory of directories || []) {
|
|
1519
1522
|
try {
|
|
1520
1523
|
gracefulFs.rmdirSync(directory);
|
|
@@ -1587,8 +1590,7 @@ function beforeGenerateFiles(args) {
|
|
|
1587
1590
|
if (config.reExport === "All" /* All */) {
|
|
1588
1591
|
const exportDeclarations = [];
|
|
1589
1592
|
for (const directory of rootDirectory.getDirectories()) {
|
|
1590
|
-
if (directory.getBaseName() === "node_modules")
|
|
1591
|
-
continue;
|
|
1593
|
+
if (directory.getBaseName() === "node_modules") continue;
|
|
1592
1594
|
const sourceFile = directory.getSourceFileOrThrow("index.ts");
|
|
1593
1595
|
exportDeclarations.push(getExportDeclaration(rootDirectory, sourceFile));
|
|
1594
1596
|
}
|
|
@@ -1619,8 +1621,7 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
|
|
|
1619
1621
|
|
|
1620
1622
|
function registerEnum(enumType, args) {
|
|
1621
1623
|
const { getSourceFile, enums, config } = args;
|
|
1622
|
-
if (!config.emitBlocks.prismaEnums && !enums[enumType.name])
|
|
1623
|
-
return;
|
|
1624
|
+
if (!config.emitBlocks.prismaEnums && !enums[enumType.name]) return;
|
|
1624
1625
|
const dataModelEnum = enums[enumType.name];
|
|
1625
1626
|
const sourceFile = getSourceFile({
|
|
1626
1627
|
name: enumType.name,
|
|
@@ -1645,7 +1646,7 @@ function registerEnum(enumType, args) {
|
|
|
1645
1646
|
...importDeclarations.toStatements(),
|
|
1646
1647
|
enumStructure,
|
|
1647
1648
|
"\n",
|
|
1648
|
-
`registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum == null ?
|
|
1649
|
+
`registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum == null ? undefined : dataModelEnum.documentation)} })`
|
|
1649
1650
|
]
|
|
1650
1651
|
});
|
|
1651
1652
|
}
|
|
@@ -1687,8 +1688,7 @@ function createEmitBlocks(data) {
|
|
|
1687
1688
|
}
|
|
1688
1689
|
let blocksToEmit = {};
|
|
1689
1690
|
for (const block of data) {
|
|
1690
|
-
if (!Object.keys(blocksDependencyMap).includes(block))
|
|
1691
|
-
continue;
|
|
1691
|
+
if (!Object.keys(blocksDependencyMap).includes(block)) continue;
|
|
1692
1692
|
blocksToEmit = {
|
|
1693
1693
|
...blocksToEmit,
|
|
1694
1694
|
...Object.fromEntries(blocksDependencyMap[block].map((block2) => [block2, true]))
|
|
@@ -1740,8 +1740,7 @@ function createConfig(data) {
|
|
|
1740
1740
|
config.decorate || {}
|
|
1741
1741
|
);
|
|
1742
1742
|
for (const element of configDecorate) {
|
|
1743
|
-
if (!element)
|
|
1744
|
-
continue;
|
|
1743
|
+
if (!element) continue;
|
|
1745
1744
|
assert.ok(
|
|
1746
1745
|
element.from && element.name,
|
|
1747
1746
|
`Missed 'from' or 'name' part in configuration for decorate`
|
|
@@ -1754,7 +1753,7 @@ function createConfig(data) {
|
|
|
1754
1753
|
namedImport: toBoolean(element.namedImport),
|
|
1755
1754
|
defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
|
|
1756
1755
|
namespaceImport: element.namespaceImport,
|
|
1757
|
-
arguments: element.arguments ? JSON5.parse(element.arguments) :
|
|
1756
|
+
arguments: element.arguments ? JSON5.parse(element.arguments) : undefined
|
|
1758
1757
|
});
|
|
1759
1758
|
}
|
|
1760
1759
|
return {
|
|
@@ -1787,14 +1786,11 @@ const tsConfigFileExists = lodash.memoize((filePath) => {
|
|
|
1787
1786
|
return gracefulFs.existsSync(filePath);
|
|
1788
1787
|
});
|
|
1789
1788
|
function createTsConfigFilePathValue(value) {
|
|
1790
|
-
if (typeof value === "string")
|
|
1791
|
-
|
|
1792
|
-
if (tsConfigFileExists("tsconfig.json"))
|
|
1793
|
-
return "tsconfig.json";
|
|
1789
|
+
if (typeof value === "string") return value;
|
|
1790
|
+
if (tsConfigFileExists("tsconfig.json")) return "tsconfig.json";
|
|
1794
1791
|
}
|
|
1795
1792
|
function createPrismaImport(value) {
|
|
1796
|
-
if (typeof value === "string")
|
|
1797
|
-
return value;
|
|
1793
|
+
if (typeof value === "string") return value;
|
|
1798
1794
|
return "@prisma/client";
|
|
1799
1795
|
}
|
|
1800
1796
|
function createUseInputType(data) {
|
|
@@ -1805,7 +1801,7 @@ function createUseInputType(data) {
|
|
|
1805
1801
|
for (const [typeName, useInputs] of Object.entries(data)) {
|
|
1806
1802
|
const entry = {
|
|
1807
1803
|
typeName,
|
|
1808
|
-
ALL:
|
|
1804
|
+
ALL: undefined
|
|
1809
1805
|
};
|
|
1810
1806
|
if (useInputs.ALL) {
|
|
1811
1807
|
entry.ALL = useInputs.ALL;
|
|
@@ -1859,7 +1855,7 @@ function factoryGetSourceFile(args) {
|
|
|
1859
1855
|
template: outputFilePattern
|
|
1860
1856
|
});
|
|
1861
1857
|
filePath = `${output}/${filePath}`;
|
|
1862
|
-
return project.getSourceFile(filePath) || project.createSourceFile(filePath,
|
|
1858
|
+
return project.getSourceFile(filePath) || project.createSourceFile(filePath, undefined, { overwrite: true });
|
|
1863
1859
|
};
|
|
1864
1860
|
}
|
|
1865
1861
|
|
|
@@ -1904,7 +1900,7 @@ function getModelName(args) {
|
|
|
1904
1900
|
return test;
|
|
1905
1901
|
}
|
|
1906
1902
|
}
|
|
1907
|
-
return
|
|
1903
|
+
return undefined;
|
|
1908
1904
|
}
|
|
1909
1905
|
const splitKeywords = [
|
|
1910
1906
|
"CreateInput",
|
|
@@ -1987,7 +1983,7 @@ const AwaitEventEmitter = require$1("await-event-emitter").default;
|
|
|
1987
1983
|
async function generate(args) {
|
|
1988
1984
|
var _a;
|
|
1989
1985
|
const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
|
|
1990
|
-
const generatorOutputValue = (_a = generator.output) == null ?
|
|
1986
|
+
const generatorOutputValue = (_a = generator.output) == null ? undefined : _a.value;
|
|
1991
1987
|
assert.ok(generatorOutputValue, "Missing generator configuration: output");
|
|
1992
1988
|
const config = createConfig(generator.config);
|
|
1993
1989
|
const eventEmitter = new AwaitEventEmitter();
|
package/generate.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ declare namespace DMMF {
|
|
|
37
37
|
models: Model[];
|
|
38
38
|
enums: DatamodelEnum[];
|
|
39
39
|
types: Model[];
|
|
40
|
+
indexes: Index[];
|
|
40
41
|
}>;
|
|
41
42
|
export type uniqueIndex = ReadonlyDeep_2<{
|
|
42
43
|
name: string;
|
|
@@ -88,6 +89,24 @@ declare namespace DMMF {
|
|
|
88
89
|
args: any[];
|
|
89
90
|
}>;
|
|
90
91
|
export type FieldDefaultScalar = string | boolean | number;
|
|
92
|
+
export type Index = ReadonlyDeep_2<{
|
|
93
|
+
model: string;
|
|
94
|
+
type: IndexType;
|
|
95
|
+
isDefinedOnField: boolean;
|
|
96
|
+
name?: string;
|
|
97
|
+
dbName?: string;
|
|
98
|
+
algorithm?: string;
|
|
99
|
+
clustered?: boolean;
|
|
100
|
+
fields: IndexField[];
|
|
101
|
+
}>;
|
|
102
|
+
export type IndexType = 'id' | 'normal' | 'unique' | 'fulltext';
|
|
103
|
+
export type IndexField = ReadonlyDeep_2<{
|
|
104
|
+
name: string;
|
|
105
|
+
sortOrder?: SortOrder;
|
|
106
|
+
length?: number;
|
|
107
|
+
operatorClass?: string;
|
|
108
|
+
}>;
|
|
109
|
+
export type SortOrder = 'asc' | 'desc';
|
|
91
110
|
export type Schema = ReadonlyDeep_2<{
|
|
92
111
|
rootQueryType?: string;
|
|
93
112
|
rootMutationType?: string;
|
package/package.json
CHANGED