prisma-nestjs-graphql 20.0.2 → 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 +110 -100
- package/generate.d.ts +197 -47
- package/package.json +27 -29
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,10 +16,18 @@ 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
|
|
|
23
|
+
function isCreateManyReturn(name) {
|
|
24
|
+
const lowerName = name.toLowerCase();
|
|
25
|
+
if (lowerName.startsWith("createmany") && (lowerName.endsWith("andreturnoutputtype") || lowerName.endsWith("andreturn"))) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
function pascalCase(string) {
|
|
24
32
|
return lodash.startCase(lodash.camelCase(string)).replaceAll(" ", "");
|
|
25
33
|
}
|
|
@@ -28,6 +36,7 @@ function argsType(field, args) {
|
|
|
28
36
|
if (["queryRaw", "executeRaw"].includes(field.name)) {
|
|
29
37
|
return;
|
|
30
38
|
}
|
|
39
|
+
if (isCreateManyReturn(field.name)) return;
|
|
31
40
|
const { eventEmitter, typeNames, getModelName } = args;
|
|
32
41
|
let className = pascalCase(`${field.name}Args`);
|
|
33
42
|
const modelName = getModelName(className) || "";
|
|
@@ -51,7 +60,7 @@ function argsType(field, args) {
|
|
|
51
60
|
const names = ["Count", "Avg", "Sum", "Min", "Max"];
|
|
52
61
|
if (`${modelName}GroupByArgs` === inputType.name) {
|
|
53
62
|
const byField = inputType.fields.find((f) => f.name === "by");
|
|
54
|
-
if (byField == null ?
|
|
63
|
+
if (byField == null ? undefined : byField.inputTypes) {
|
|
55
64
|
byField.inputTypes = byField.inputTypes.filter((inputType2) => inputType2.isList);
|
|
56
65
|
}
|
|
57
66
|
}
|
|
@@ -237,8 +246,8 @@ class ImportDeclarationMap extends Map {
|
|
|
237
246
|
const value = {
|
|
238
247
|
moduleSpecifier: from,
|
|
239
248
|
namedImports: [],
|
|
240
|
-
defaultImport:
|
|
241
|
-
namespaceImport:
|
|
249
|
+
defaultImport: undefined,
|
|
250
|
+
namespaceImport: undefined
|
|
242
251
|
};
|
|
243
252
|
if (namedImport === true && namespaceImport) {
|
|
244
253
|
value.namedImports = [{ name: namespaceImport }];
|
|
@@ -271,7 +280,7 @@ async function generateFiles(args) {
|
|
|
271
280
|
const { project, config, output, eventEmitter } = args;
|
|
272
281
|
if (config.emitSingle) {
|
|
273
282
|
const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
|
|
274
|
-
const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts",
|
|
283
|
+
const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", undefined, { overwrite: true });
|
|
275
284
|
const statements = project.getSourceFiles().flatMap((s) => {
|
|
276
285
|
var _a, _b;
|
|
277
286
|
if (s === sourceFile) {
|
|
@@ -286,7 +295,7 @@ async function generateFiles(args) {
|
|
|
286
295
|
}
|
|
287
296
|
for (const property of statement.properties || []) {
|
|
288
297
|
for (const decorator of property.decorators || []) {
|
|
289
|
-
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();
|
|
290
299
|
assert.ok(
|
|
291
300
|
fullName,
|
|
292
301
|
`Cannot get full name of decorator of class ${statement.name}`
|
|
@@ -425,11 +434,11 @@ function getGraphqlImport(args) {
|
|
|
425
434
|
return { name: typeName, specifier: "@nestjs/graphql" };
|
|
426
435
|
}
|
|
427
436
|
case "DateTime": {
|
|
428
|
-
return { name: "Date", specifier:
|
|
437
|
+
return { name: "Date", specifier: undefined };
|
|
429
438
|
}
|
|
430
439
|
case "true":
|
|
431
440
|
case "Boolean": {
|
|
432
|
-
return { name: "Boolean", specifier:
|
|
441
|
+
return { name: "Boolean", specifier: undefined };
|
|
433
442
|
}
|
|
434
443
|
case "Decimal": {
|
|
435
444
|
return {
|
|
@@ -441,7 +450,7 @@ function getGraphqlImport(args) {
|
|
|
441
450
|
return { name: "GraphQLJSON", specifier: "graphql-type-json" };
|
|
442
451
|
}
|
|
443
452
|
}
|
|
444
|
-
return { name: "String", specifier:
|
|
453
|
+
return { name: "String", specifier: undefined };
|
|
445
454
|
}
|
|
446
455
|
let sourceFileType = fileTypeByLocation(location);
|
|
447
456
|
if (sourceFileType === "output" && fileType === "model") {
|
|
@@ -656,33 +665,33 @@ function inputType(args) {
|
|
|
656
665
|
if (inputTypes.length === 0) {
|
|
657
666
|
continue;
|
|
658
667
|
}
|
|
659
|
-
const usePattern = (useInputType == null ?
|
|
668
|
+
const usePattern = (useInputType == null ? undefined : useInputType.ALL) || (useInputType == null ? undefined : useInputType[name]);
|
|
660
669
|
const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
|
|
661
670
|
const { isList, location, type } = graphqlInputType;
|
|
662
671
|
const typeName = String(type);
|
|
663
|
-
const settings = modelFieldSettings == null ?
|
|
664
|
-
const propertySettings = settings == null ?
|
|
672
|
+
const settings = modelFieldSettings == null ? undefined : modelFieldSettings.get(name);
|
|
673
|
+
const propertySettings = settings == null ? undefined : settings.getPropertyType({
|
|
665
674
|
name: inputType2.name,
|
|
666
675
|
input: true
|
|
667
676
|
});
|
|
668
|
-
const modelField = model == null ?
|
|
669
|
-
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);
|
|
670
679
|
const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
|
|
671
680
|
const whereUniqueInputType = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((name2) => `'${name2}'`).join(" | ")}>`;
|
|
672
681
|
const propertyType = lodash.castArray(
|
|
673
|
-
(propertySettings == null ?
|
|
682
|
+
(propertySettings == null ? undefined : propertySettings.name) || whereUniqueInputType || getPropertyType({
|
|
674
683
|
location,
|
|
675
684
|
type: typeName
|
|
676
685
|
})
|
|
677
686
|
);
|
|
678
687
|
const hasExclamationToken = Boolean(
|
|
679
|
-
isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ?
|
|
688
|
+
isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ? undefined : atLeastKeys.includes(name))
|
|
680
689
|
);
|
|
681
690
|
const property = propertyStructure({
|
|
682
691
|
name,
|
|
683
692
|
isNullable: !isRequired,
|
|
684
|
-
hasExclamationToken: hasExclamationToken ||
|
|
685
|
-
hasQuestionToken: hasExclamationToken ? false :
|
|
693
|
+
hasExclamationToken: hasExclamationToken || undefined,
|
|
694
|
+
hasQuestionToken: hasExclamationToken ? false : undefined,
|
|
686
695
|
propertyType,
|
|
687
696
|
isList
|
|
688
697
|
});
|
|
@@ -695,13 +704,13 @@ function inputType(args) {
|
|
|
695
704
|
importDeclarations.add("Prisma", config.prismaClientImport);
|
|
696
705
|
}
|
|
697
706
|
let graphqlType;
|
|
698
|
-
const shouldHideField = (settings == null ?
|
|
707
|
+
const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
|
|
699
708
|
name: inputType2.name,
|
|
700
709
|
input: true
|
|
701
710
|
})) || config.decorate.some(
|
|
702
711
|
(d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
|
|
703
712
|
);
|
|
704
|
-
const fieldType = settings == null ?
|
|
713
|
+
const fieldType = settings == null ? undefined : settings.getFieldType({
|
|
705
714
|
name: inputType2.name,
|
|
706
715
|
input: true
|
|
707
716
|
});
|
|
@@ -738,7 +747,7 @@ function inputType(args) {
|
|
|
738
747
|
arguments: [
|
|
739
748
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
740
749
|
JSON5.stringify({
|
|
741
|
-
...settings == null ?
|
|
750
|
+
...settings == null ? undefined : settings.fieldArguments(),
|
|
742
751
|
nullable: !isRequired
|
|
743
752
|
})
|
|
744
753
|
]
|
|
@@ -757,7 +766,7 @@ function inputType(args) {
|
|
|
757
766
|
arguments: ["transformToDecimal"]
|
|
758
767
|
}
|
|
759
768
|
);
|
|
760
|
-
} else if (location === "inputObjectTypes" && ((modelField == null ?
|
|
769
|
+
} else if (location === "inputObjectTypes" && ((modelField == null ? undefined : modelField.type) === "Decimal" || [
|
|
761
770
|
"connect",
|
|
762
771
|
"connectOrCreate",
|
|
763
772
|
"create",
|
|
@@ -771,7 +780,7 @@ function inputType(args) {
|
|
|
771
780
|
"updateMany",
|
|
772
781
|
"upsert",
|
|
773
782
|
"where"
|
|
774
|
-
].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(
|
|
775
784
|
(field2) => field2.kind === "object" && classTransformerTypeModels.has(field2.type)
|
|
776
785
|
)))) {
|
|
777
786
|
importDeclarations.add("Type", "class-transformer");
|
|
@@ -779,7 +788,7 @@ function inputType(args) {
|
|
|
779
788
|
}
|
|
780
789
|
if (isCustomsApplicable) {
|
|
781
790
|
for (const options of settings || []) {
|
|
782
|
-
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) {
|
|
783
792
|
property.decorators.push({
|
|
784
793
|
name: options.name,
|
|
785
794
|
arguments: options.arguments
|
|
@@ -793,7 +802,7 @@ function inputType(args) {
|
|
|
793
802
|
if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
|
|
794
803
|
property.decorators.push({
|
|
795
804
|
name: decorate.name,
|
|
796
|
-
arguments: (_d = decorate.arguments) == null ?
|
|
805
|
+
arguments: (_d = decorate.arguments) == null ? undefined : _d.map((x) => pupa(x, { propertyType }))
|
|
797
806
|
});
|
|
798
807
|
importDeclarations.create(decorate);
|
|
799
808
|
}
|
|
@@ -819,7 +828,7 @@ class ObjectSettings extends Array {
|
|
|
819
828
|
var _a;
|
|
820
829
|
const hideField = this.find((s) => s.name === "HideField");
|
|
821
830
|
return Boolean(
|
|
822
|
-
(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))
|
|
823
832
|
);
|
|
824
833
|
}
|
|
825
834
|
getFieldType({
|
|
@@ -829,16 +838,16 @@ class ObjectSettings extends Array {
|
|
|
829
838
|
}) {
|
|
830
839
|
const fieldType = this.find((s) => s.kind === "FieldType");
|
|
831
840
|
if (!fieldType) {
|
|
832
|
-
return
|
|
841
|
+
return undefined;
|
|
833
842
|
}
|
|
834
843
|
if (fieldType.match) {
|
|
835
|
-
return fieldType.match(name) ? fieldType :
|
|
844
|
+
return fieldType.match(name) ? fieldType : undefined;
|
|
836
845
|
}
|
|
837
846
|
if (input && !fieldType.input) {
|
|
838
|
-
return
|
|
847
|
+
return undefined;
|
|
839
848
|
}
|
|
840
849
|
if (output && !fieldType.output) {
|
|
841
|
-
return
|
|
850
|
+
return undefined;
|
|
842
851
|
}
|
|
843
852
|
return fieldType;
|
|
844
853
|
}
|
|
@@ -849,16 +858,16 @@ class ObjectSettings extends Array {
|
|
|
849
858
|
}) {
|
|
850
859
|
const propertyType = this.find((s) => s.kind === "PropertyType");
|
|
851
860
|
if (!propertyType) {
|
|
852
|
-
return
|
|
861
|
+
return undefined;
|
|
853
862
|
}
|
|
854
863
|
if (propertyType.match) {
|
|
855
|
-
return propertyType.match(name) ? propertyType :
|
|
864
|
+
return propertyType.match(name) ? propertyType : undefined;
|
|
856
865
|
}
|
|
857
866
|
if (input && !propertyType.input) {
|
|
858
|
-
return
|
|
867
|
+
return undefined;
|
|
859
868
|
}
|
|
860
869
|
if (output && !propertyType.output) {
|
|
861
|
-
return
|
|
870
|
+
return undefined;
|
|
862
871
|
}
|
|
863
872
|
return propertyType;
|
|
864
873
|
}
|
|
@@ -912,7 +921,7 @@ function createObjectSettings(args) {
|
|
|
912
921
|
}
|
|
913
922
|
return {
|
|
914
923
|
settings: result,
|
|
915
|
-
documentation: documentationLines.filter(Boolean).join("\n") ||
|
|
924
|
+
documentation: documentationLines.filter(Boolean).join("\n") || undefined
|
|
916
925
|
};
|
|
917
926
|
}
|
|
918
927
|
function createSettingElement({
|
|
@@ -924,14 +933,21 @@ function createSettingElement({
|
|
|
924
933
|
var _a, _b, _c, _d, _e;
|
|
925
934
|
const result = {
|
|
926
935
|
documentLine: "",
|
|
927
|
-
element:
|
|
936
|
+
element: undefined
|
|
928
937
|
};
|
|
929
938
|
if (line.startsWith("@deprecated")) {
|
|
930
939
|
fieldElement.arguments["deprecationReason"] = lodash.trim(line.slice(11));
|
|
931
940
|
result.element = fieldElement;
|
|
932
941
|
return result;
|
|
933
942
|
}
|
|
934
|
-
|
|
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;
|
|
935
951
|
if (!(match && name)) {
|
|
936
952
|
result.documentLine = line;
|
|
937
953
|
return result;
|
|
@@ -950,14 +966,14 @@ function createSettingElement({
|
|
|
950
966
|
Object.assign(element, hideFieldDecorator(match));
|
|
951
967
|
return result;
|
|
952
968
|
}
|
|
953
|
-
if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ?
|
|
969
|
+
if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? undefined : _b.args)) {
|
|
954
970
|
const options2 = customType(match.groups.args);
|
|
955
971
|
lodash.merge(element, options2.namespace && config.fields[options2.namespace], options2, {
|
|
956
972
|
kind: name
|
|
957
973
|
});
|
|
958
974
|
return result;
|
|
959
975
|
}
|
|
960
|
-
if (name === "ObjectType" && ((_c = match.groups) == null ?
|
|
976
|
+
if (name === "ObjectType" && ((_c = match.groups) == null ? undefined : _c.args)) {
|
|
961
977
|
element.kind = "ObjectType";
|
|
962
978
|
const options2 = customType(match.groups.args);
|
|
963
979
|
if (typeof options2[0] === "string" && options2[0]) {
|
|
@@ -972,7 +988,7 @@ function createSettingElement({
|
|
|
972
988
|
};
|
|
973
989
|
return result;
|
|
974
990
|
}
|
|
975
|
-
if (name === "Directive" && ((_d = match.groups) == null ?
|
|
991
|
+
if (name === "Directive" && ((_d = match.groups) == null ? undefined : _d.args)) {
|
|
976
992
|
const options2 = customType(match.groups.args);
|
|
977
993
|
lodash.merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
|
|
978
994
|
name,
|
|
@@ -986,7 +1002,7 @@ function createSettingElement({
|
|
|
986
1002
|
element.namespaceImport = namespace;
|
|
987
1003
|
const options = {
|
|
988
1004
|
name,
|
|
989
|
-
arguments: (((_e = match.groups) == null ?
|
|
1005
|
+
arguments: (((_e = match.groups) == null ? undefined : _e.args) || "").split(",").map((s) => lodash.trim(s)).filter(Boolean)
|
|
990
1006
|
};
|
|
991
1007
|
lodash.merge(element, namespace && config.fields[namespace], options);
|
|
992
1008
|
return result;
|
|
@@ -1001,7 +1017,7 @@ function customType(args) {
|
|
|
1001
1017
|
Object.assign(result, options);
|
|
1002
1018
|
const namespace = getNamespace(options.name);
|
|
1003
1019
|
result.namespace = namespace;
|
|
1004
|
-
if ((_a = options.name) == null ?
|
|
1020
|
+
if ((_a = options.name) == null ? undefined : _a.includes(".")) {
|
|
1005
1021
|
result.namespaceImport = namespace;
|
|
1006
1022
|
}
|
|
1007
1023
|
if (typeof options.match === "string" || Array.isArray(options.match)) {
|
|
@@ -1015,11 +1031,11 @@ function hideFieldDecorator(match) {
|
|
|
1015
1031
|
name: "HideField",
|
|
1016
1032
|
arguments: [],
|
|
1017
1033
|
from: "@nestjs/graphql",
|
|
1018
|
-
defaultImport:
|
|
1019
|
-
namespaceImport:
|
|
1020
|
-
match:
|
|
1034
|
+
defaultImport: undefined,
|
|
1035
|
+
namespaceImport: undefined,
|
|
1036
|
+
match: undefined
|
|
1021
1037
|
};
|
|
1022
|
-
if (!((_a = match.groups) == null ?
|
|
1038
|
+
if (!((_a = match.groups) == null ? undefined : _a.args)) {
|
|
1023
1039
|
result.output = true;
|
|
1024
1040
|
return result;
|
|
1025
1041
|
}
|
|
@@ -1052,8 +1068,8 @@ function parseArgs(string) {
|
|
|
1052
1068
|
}
|
|
1053
1069
|
}
|
|
1054
1070
|
function getNamespace(name) {
|
|
1055
|
-
if (name ===
|
|
1056
|
-
return
|
|
1071
|
+
if (name === undefined) {
|
|
1072
|
+
return undefined;
|
|
1057
1073
|
}
|
|
1058
1074
|
let result = String(name);
|
|
1059
1075
|
if (result.includes(".")) {
|
|
@@ -1100,7 +1116,7 @@ function createComment(documentation, settings) {
|
|
|
1100
1116
|
for (const line of documentationLines) {
|
|
1101
1117
|
commentLines.push(` * ${line}`);
|
|
1102
1118
|
}
|
|
1103
|
-
const deprecationReason = (_a = settings == null ?
|
|
1119
|
+
const deprecationReason = (_a = settings == null ? undefined : settings.fieldArguments()) == null ? undefined : _a.deprecationReason;
|
|
1104
1120
|
if (deprecationReason) {
|
|
1105
1121
|
commentLines.push(` * @deprecated ${deprecationReason}`);
|
|
1106
1122
|
}
|
|
@@ -1116,6 +1132,7 @@ const nestjsGraphql$1 = "@nestjs/graphql";
|
|
|
1116
1132
|
function modelOutputType(outputType, args) {
|
|
1117
1133
|
var _a, _b, _c, _d, _e, _f;
|
|
1118
1134
|
const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
|
|
1135
|
+
if (isCreateManyReturn(outputType.name)) return;
|
|
1119
1136
|
const model = models.get(outputType.name);
|
|
1120
1137
|
assert.ok(model, `Cannot find model by name ${outputType.name}`);
|
|
1121
1138
|
const sourceFile = getSourceFile({
|
|
@@ -1163,8 +1180,7 @@ function modelOutputType(outputType, args) {
|
|
|
1163
1180
|
importDeclarations.add("Field", nestjsGraphql$1);
|
|
1164
1181
|
importDeclarations.add("ObjectType", nestjsGraphql$1);
|
|
1165
1182
|
for (const field of outputType.fields) {
|
|
1166
|
-
if (config.omitModelsCount && field.name === "_count")
|
|
1167
|
-
continue;
|
|
1183
|
+
if (config.omitModelsCount && field.name === "_count") continue;
|
|
1168
1184
|
let fileType = "model";
|
|
1169
1185
|
const { location, isList, type, namespace } = field.outputType;
|
|
1170
1186
|
let outputTypeName = String(type);
|
|
@@ -1172,18 +1188,18 @@ function modelOutputType(outputType, args) {
|
|
|
1172
1188
|
fileType = "output";
|
|
1173
1189
|
outputTypeName = getOutputTypeName(outputTypeName);
|
|
1174
1190
|
}
|
|
1175
|
-
const modelField = (_a = modelFields.get(model.name)) == null ?
|
|
1176
|
-
const settings = (_b = fieldSettings.get(model.name)) == null ?
|
|
1177
|
-
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({
|
|
1178
1194
|
name: outputType.name,
|
|
1179
1195
|
output: true
|
|
1180
1196
|
});
|
|
1181
|
-
const propertySettings = settings == null ?
|
|
1197
|
+
const propertySettings = settings == null ? undefined : settings.getPropertyType({
|
|
1182
1198
|
name: outputType.name,
|
|
1183
1199
|
output: true
|
|
1184
1200
|
});
|
|
1185
1201
|
const propertyType = lodash.castArray(
|
|
1186
|
-
(propertySettings == null ?
|
|
1202
|
+
(propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
|
|
1187
1203
|
location,
|
|
1188
1204
|
type: outputTypeName
|
|
1189
1205
|
})
|
|
@@ -1202,7 +1218,7 @@ function modelOutputType(outputType, args) {
|
|
|
1202
1218
|
sourceFile,
|
|
1203
1219
|
fileType,
|
|
1204
1220
|
location,
|
|
1205
|
-
isId: modelField == null ?
|
|
1221
|
+
isId: modelField == null ? undefined : modelField.isId,
|
|
1206
1222
|
noTypeId: config.noTypeId,
|
|
1207
1223
|
typeName: outputTypeName,
|
|
1208
1224
|
getSourceFile
|
|
@@ -1220,17 +1236,17 @@ function modelOutputType(outputType, args) {
|
|
|
1220
1236
|
propertyType,
|
|
1221
1237
|
isList
|
|
1222
1238
|
});
|
|
1223
|
-
if (typeof property.leadingTrivia === "string" && (modelField == null ?
|
|
1239
|
+
if (typeof property.leadingTrivia === "string" && (modelField == null ? undefined : modelField.documentation)) {
|
|
1224
1240
|
property.leadingTrivia += createComment(modelField.documentation, settings);
|
|
1225
1241
|
}
|
|
1226
|
-
(_c = classStructure.properties) == null ?
|
|
1242
|
+
(_c = classStructure.properties) == null ? undefined : _c.push(property);
|
|
1227
1243
|
if (propertySettings) {
|
|
1228
1244
|
importDeclarations.create({ ...propertySettings });
|
|
1229
1245
|
} else if (propertyType.includes("Decimal")) {
|
|
1230
1246
|
importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
|
|
1231
1247
|
}
|
|
1232
1248
|
assert.ok(property.decorators, "property.decorators is undefined");
|
|
1233
|
-
const shouldHideField = (settings == null ?
|
|
1249
|
+
const shouldHideField = (settings == null ? undefined : settings.shouldHideField({ name: outputType.name, output: true })) || config.decorate.some(
|
|
1234
1250
|
(d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
|
|
1235
1251
|
);
|
|
1236
1252
|
if (shouldHideField) {
|
|
@@ -1242,17 +1258,17 @@ function modelOutputType(outputType, args) {
|
|
|
1242
1258
|
arguments: [
|
|
1243
1259
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1244
1260
|
JSON5.stringify({
|
|
1245
|
-
...settings == null ?
|
|
1261
|
+
...settings == null ? undefined : settings.fieldArguments(),
|
|
1246
1262
|
nullable: Boolean(field.isNullable),
|
|
1247
1263
|
defaultValue: ["number", "string", "boolean"].includes(
|
|
1248
|
-
typeof (modelField == null ?
|
|
1249
|
-
) ? modelField == null ?
|
|
1250
|
-
description: modelField == null ?
|
|
1264
|
+
typeof (modelField == null ? undefined : modelField.default)
|
|
1265
|
+
) ? modelField == null ? undefined : modelField.default : undefined,
|
|
1266
|
+
description: modelField == null ? undefined : modelField.documentation
|
|
1251
1267
|
})
|
|
1252
1268
|
]
|
|
1253
1269
|
});
|
|
1254
1270
|
for (const setting of settings || []) {
|
|
1255
|
-
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)) {
|
|
1256
1272
|
property.decorators.push({
|
|
1257
1273
|
name: setting.name,
|
|
1258
1274
|
arguments: setting.arguments
|
|
@@ -1265,7 +1281,7 @@ function modelOutputType(outputType, args) {
|
|
|
1265
1281
|
if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
|
|
1266
1282
|
property.decorators.push({
|
|
1267
1283
|
name: decorate.name,
|
|
1268
|
-
arguments: (_f = decorate.arguments) == null ?
|
|
1284
|
+
arguments: (_f = decorate.arguments) == null ? undefined : _f.map((x) => pupa(x, { propertyType }))
|
|
1269
1285
|
});
|
|
1270
1286
|
importDeclarations.create(decorate);
|
|
1271
1287
|
}
|
|
@@ -1333,7 +1349,7 @@ function beforeGenerateFiles$1(args) {
|
|
|
1333
1349
|
var _a;
|
|
1334
1350
|
const { project } = args;
|
|
1335
1351
|
for (const sourceFile of project.getSourceFiles()) {
|
|
1336
|
-
const className = (_a = sourceFile.getClass(() => true)) == null ?
|
|
1352
|
+
const className = (_a = sourceFile.getClass(() => true)) == null ? undefined : _a.getName();
|
|
1337
1353
|
if (className && isAtomicOperation(className)) {
|
|
1338
1354
|
project.removeSourceFile(sourceFile);
|
|
1339
1355
|
}
|
|
@@ -1358,9 +1374,8 @@ function outputType(outputType2, args) {
|
|
|
1358
1374
|
const modelName = getModelName(outputType2.name) || "";
|
|
1359
1375
|
const model = models.get(modelName);
|
|
1360
1376
|
const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
|
|
1361
|
-
const isCountOutput = (model == null ?
|
|
1362
|
-
if (!config.emitBlocks.outputs && !isCountOutput)
|
|
1363
|
-
return;
|
|
1377
|
+
const isCountOutput = (model == null ? undefined : model.name) && outputType2.name === `${model.name}CountOutputType`;
|
|
1378
|
+
if (!config.emitBlocks.outputs && !isCountOutput) return;
|
|
1364
1379
|
outputType2.name = getOutputTypeName(outputType2.name);
|
|
1365
1380
|
if (isAggregateOutput) {
|
|
1366
1381
|
eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputType2 });
|
|
@@ -1386,15 +1401,15 @@ function outputType(outputType2, args) {
|
|
|
1386
1401
|
for (const field of outputType2.fields) {
|
|
1387
1402
|
const { location, isList, type } = field.outputType;
|
|
1388
1403
|
const outputTypeName = getOutputTypeName(String(type));
|
|
1389
|
-
const settings = isCountOutput ?
|
|
1390
|
-
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({
|
|
1391
1406
|
name: outputType2.name,
|
|
1392
1407
|
output: true
|
|
1393
1408
|
});
|
|
1394
|
-
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);
|
|
1395
1410
|
field.outputType.type = outputTypeName;
|
|
1396
1411
|
const propertyType = lodash.castArray(
|
|
1397
|
-
(propertySettings == null ?
|
|
1412
|
+
(propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
|
|
1398
1413
|
location,
|
|
1399
1414
|
type: outputTypeName
|
|
1400
1415
|
})
|
|
@@ -1402,24 +1417,24 @@ function outputType(outputType2, args) {
|
|
|
1402
1417
|
const property = propertyStructure({
|
|
1403
1418
|
name: field.name,
|
|
1404
1419
|
isNullable: field.isNullable,
|
|
1405
|
-
hasQuestionToken: isCountOutput ? true :
|
|
1420
|
+
hasQuestionToken: isCountOutput ? true : undefined,
|
|
1406
1421
|
propertyType,
|
|
1407
1422
|
isList
|
|
1408
1423
|
});
|
|
1409
|
-
(_c = classStructure.properties) == null ?
|
|
1424
|
+
(_c = classStructure.properties) == null ? undefined : _c.push(property);
|
|
1410
1425
|
if (propertySettings) {
|
|
1411
1426
|
importDeclarations.create({ ...propertySettings });
|
|
1412
1427
|
} else if (propertyType.includes("Decimal")) {
|
|
1413
1428
|
importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
|
|
1414
1429
|
}
|
|
1415
1430
|
let graphqlType;
|
|
1416
|
-
const shouldHideField = (settings == null ?
|
|
1431
|
+
const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
|
|
1417
1432
|
name: outputType2.name,
|
|
1418
1433
|
output: true
|
|
1419
1434
|
})) || config.decorate.some(
|
|
1420
1435
|
(d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
|
|
1421
1436
|
);
|
|
1422
|
-
const fieldType = settings == null ?
|
|
1437
|
+
const fieldType = settings == null ? undefined : settings.getFieldType({
|
|
1423
1438
|
name: outputType2.name,
|
|
1424
1439
|
output: true
|
|
1425
1440
|
});
|
|
@@ -1458,14 +1473,14 @@ function outputType(outputType2, args) {
|
|
|
1458
1473
|
arguments: [
|
|
1459
1474
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1460
1475
|
JSON5.stringify({
|
|
1461
|
-
...settings == null ?
|
|
1476
|
+
...settings == null ? undefined : settings.fieldArguments(),
|
|
1462
1477
|
nullable: Boolean(field.isNullable)
|
|
1463
1478
|
})
|
|
1464
1479
|
]
|
|
1465
1480
|
});
|
|
1466
1481
|
if (isCustomsApplicable) {
|
|
1467
1482
|
for (const options of settings || []) {
|
|
1468
|
-
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) {
|
|
1469
1484
|
property.decorators.push({
|
|
1470
1485
|
name: options.name,
|
|
1471
1486
|
arguments: options.arguments
|
|
@@ -1493,7 +1508,7 @@ function purgeOutput(emitter) {
|
|
|
1493
1508
|
}
|
|
1494
1509
|
function begin({ project, output }) {
|
|
1495
1510
|
var _a;
|
|
1496
|
-
const sourceFiles = (_a = project.getDirectory(output)) == null ?
|
|
1511
|
+
const sourceFiles = (_a = project.getDirectory(output)) == null ? undefined : _a.getDescendantSourceFiles();
|
|
1497
1512
|
if (sourceFiles) {
|
|
1498
1513
|
for (const sourceFile of sourceFiles) {
|
|
1499
1514
|
sourceFile.delete();
|
|
@@ -1502,7 +1517,7 @@ function begin({ project, output }) {
|
|
|
1502
1517
|
}
|
|
1503
1518
|
function end({ project, output }) {
|
|
1504
1519
|
var _a;
|
|
1505
|
-
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());
|
|
1506
1521
|
for (const directory of directories || []) {
|
|
1507
1522
|
try {
|
|
1508
1523
|
gracefulFs.rmdirSync(directory);
|
|
@@ -1575,6 +1590,7 @@ function beforeGenerateFiles(args) {
|
|
|
1575
1590
|
if (config.reExport === "All" /* All */) {
|
|
1576
1591
|
const exportDeclarations = [];
|
|
1577
1592
|
for (const directory of rootDirectory.getDirectories()) {
|
|
1593
|
+
if (directory.getBaseName() === "node_modules") continue;
|
|
1578
1594
|
const sourceFile = directory.getSourceFileOrThrow("index.ts");
|
|
1579
1595
|
exportDeclarations.push(getExportDeclaration(rootDirectory, sourceFile));
|
|
1580
1596
|
}
|
|
@@ -1605,8 +1621,7 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
|
|
|
1605
1621
|
|
|
1606
1622
|
function registerEnum(enumType, args) {
|
|
1607
1623
|
const { getSourceFile, enums, config } = args;
|
|
1608
|
-
if (!config.emitBlocks.prismaEnums && !enums[enumType.name])
|
|
1609
|
-
return;
|
|
1624
|
+
if (!config.emitBlocks.prismaEnums && !enums[enumType.name]) return;
|
|
1610
1625
|
const dataModelEnum = enums[enumType.name];
|
|
1611
1626
|
const sourceFile = getSourceFile({
|
|
1612
1627
|
name: enumType.name,
|
|
@@ -1631,7 +1646,7 @@ function registerEnum(enumType, args) {
|
|
|
1631
1646
|
...importDeclarations.toStatements(),
|
|
1632
1647
|
enumStructure,
|
|
1633
1648
|
"\n",
|
|
1634
|
-
`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)} })`
|
|
1635
1650
|
]
|
|
1636
1651
|
});
|
|
1637
1652
|
}
|
|
@@ -1673,8 +1688,7 @@ function createEmitBlocks(data) {
|
|
|
1673
1688
|
}
|
|
1674
1689
|
let blocksToEmit = {};
|
|
1675
1690
|
for (const block of data) {
|
|
1676
|
-
if (!Object.keys(blocksDependencyMap).includes(block))
|
|
1677
|
-
continue;
|
|
1691
|
+
if (!Object.keys(blocksDependencyMap).includes(block)) continue;
|
|
1678
1692
|
blocksToEmit = {
|
|
1679
1693
|
...blocksToEmit,
|
|
1680
1694
|
...Object.fromEntries(blocksDependencyMap[block].map((block2) => [block2, true]))
|
|
@@ -1726,8 +1740,7 @@ function createConfig(data) {
|
|
|
1726
1740
|
config.decorate || {}
|
|
1727
1741
|
);
|
|
1728
1742
|
for (const element of configDecorate) {
|
|
1729
|
-
if (!element)
|
|
1730
|
-
continue;
|
|
1743
|
+
if (!element) continue;
|
|
1731
1744
|
assert.ok(
|
|
1732
1745
|
element.from && element.name,
|
|
1733
1746
|
`Missed 'from' or 'name' part in configuration for decorate`
|
|
@@ -1740,7 +1753,7 @@ function createConfig(data) {
|
|
|
1740
1753
|
namedImport: toBoolean(element.namedImport),
|
|
1741
1754
|
defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
|
|
1742
1755
|
namespaceImport: element.namespaceImport,
|
|
1743
|
-
arguments: element.arguments ? JSON5.parse(element.arguments) :
|
|
1756
|
+
arguments: element.arguments ? JSON5.parse(element.arguments) : undefined
|
|
1744
1757
|
});
|
|
1745
1758
|
}
|
|
1746
1759
|
return {
|
|
@@ -1773,14 +1786,11 @@ const tsConfigFileExists = lodash.memoize((filePath) => {
|
|
|
1773
1786
|
return gracefulFs.existsSync(filePath);
|
|
1774
1787
|
});
|
|
1775
1788
|
function createTsConfigFilePathValue(value) {
|
|
1776
|
-
if (typeof value === "string")
|
|
1777
|
-
|
|
1778
|
-
if (tsConfigFileExists("tsconfig.json"))
|
|
1779
|
-
return "tsconfig.json";
|
|
1789
|
+
if (typeof value === "string") return value;
|
|
1790
|
+
if (tsConfigFileExists("tsconfig.json")) return "tsconfig.json";
|
|
1780
1791
|
}
|
|
1781
1792
|
function createPrismaImport(value) {
|
|
1782
|
-
if (typeof value === "string")
|
|
1783
|
-
return value;
|
|
1793
|
+
if (typeof value === "string") return value;
|
|
1784
1794
|
return "@prisma/client";
|
|
1785
1795
|
}
|
|
1786
1796
|
function createUseInputType(data) {
|
|
@@ -1791,7 +1801,7 @@ function createUseInputType(data) {
|
|
|
1791
1801
|
for (const [typeName, useInputs] of Object.entries(data)) {
|
|
1792
1802
|
const entry = {
|
|
1793
1803
|
typeName,
|
|
1794
|
-
ALL:
|
|
1804
|
+
ALL: undefined
|
|
1795
1805
|
};
|
|
1796
1806
|
if (useInputs.ALL) {
|
|
1797
1807
|
entry.ALL = useInputs.ALL;
|
|
@@ -1845,7 +1855,7 @@ function factoryGetSourceFile(args) {
|
|
|
1845
1855
|
template: outputFilePattern
|
|
1846
1856
|
});
|
|
1847
1857
|
filePath = `${output}/${filePath}`;
|
|
1848
|
-
return project.getSourceFile(filePath) || project.createSourceFile(filePath,
|
|
1858
|
+
return project.getSourceFile(filePath) || project.createSourceFile(filePath, undefined, { overwrite: true });
|
|
1849
1859
|
};
|
|
1850
1860
|
}
|
|
1851
1861
|
|
|
@@ -1890,7 +1900,7 @@ function getModelName(args) {
|
|
|
1890
1900
|
return test;
|
|
1891
1901
|
}
|
|
1892
1902
|
}
|
|
1893
|
-
return
|
|
1903
|
+
return undefined;
|
|
1894
1904
|
}
|
|
1895
1905
|
const splitKeywords = [
|
|
1896
1906
|
"CreateInput",
|
|
@@ -1973,7 +1983,7 @@ const AwaitEventEmitter = require$1("await-event-emitter").default;
|
|
|
1973
1983
|
async function generate(args) {
|
|
1974
1984
|
var _a;
|
|
1975
1985
|
const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
|
|
1976
|
-
const generatorOutputValue = (_a = generator.output) == null ?
|
|
1986
|
+
const generatorOutputValue = (_a = generator.output) == null ? undefined : _a.value;
|
|
1977
1987
|
assert.ok(generatorOutputValue, "Missing generator configuration: output");
|
|
1978
1988
|
const config = createConfig(generator.config);
|
|
1979
1989
|
const eventEmitter = new AwaitEventEmitter();
|
package/generate.d.ts
CHANGED
|
@@ -3,50 +3,51 @@ import AwaitEventEmitter from 'await-event-emitter';
|
|
|
3
3
|
import { Project, SourceFile } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare namespace DMMF {
|
|
6
|
-
export
|
|
6
|
+
export type Document = ReadonlyDeep_2<{
|
|
7
7
|
datamodel: Datamodel;
|
|
8
8
|
schema: Schema;
|
|
9
9
|
mappings: Mappings;
|
|
10
|
-
}
|
|
11
|
-
export
|
|
10
|
+
}>;
|
|
11
|
+
export type Mappings = ReadonlyDeep_2<{
|
|
12
12
|
modelOperations: ModelMapping[];
|
|
13
13
|
otherOperations: {
|
|
14
14
|
read: string[];
|
|
15
15
|
write: string[];
|
|
16
16
|
};
|
|
17
|
-
}
|
|
18
|
-
export
|
|
17
|
+
}>;
|
|
18
|
+
export type OtherOperationMappings = ReadonlyDeep_2<{
|
|
19
19
|
read: string[];
|
|
20
20
|
write: string[];
|
|
21
|
-
}
|
|
22
|
-
export
|
|
21
|
+
}>;
|
|
22
|
+
export type DatamodelEnum = ReadonlyDeep_2<{
|
|
23
23
|
name: string;
|
|
24
24
|
values: EnumValue[];
|
|
25
25
|
dbName?: string | null;
|
|
26
26
|
documentation?: string;
|
|
27
|
-
}
|
|
28
|
-
export
|
|
27
|
+
}>;
|
|
28
|
+
export type SchemaEnum = ReadonlyDeep_2<{
|
|
29
29
|
name: string;
|
|
30
30
|
values: string[];
|
|
31
|
-
}
|
|
32
|
-
export
|
|
31
|
+
}>;
|
|
32
|
+
export type EnumValue = ReadonlyDeep_2<{
|
|
33
33
|
name: string;
|
|
34
34
|
dbName: string | null;
|
|
35
|
-
}
|
|
36
|
-
export
|
|
35
|
+
}>;
|
|
36
|
+
export type Datamodel = ReadonlyDeep_2<{
|
|
37
37
|
models: Model[];
|
|
38
38
|
enums: DatamodelEnum[];
|
|
39
39
|
types: Model[];
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
indexes: Index[];
|
|
41
|
+
}>;
|
|
42
|
+
export type uniqueIndex = ReadonlyDeep_2<{
|
|
42
43
|
name: string;
|
|
43
44
|
fields: string[];
|
|
44
|
-
}
|
|
45
|
-
export
|
|
45
|
+
}>;
|
|
46
|
+
export type PrimaryKey = ReadonlyDeep_2<{
|
|
46
47
|
name: string | null;
|
|
47
48
|
fields: string[];
|
|
48
|
-
}
|
|
49
|
-
export
|
|
49
|
+
}>;
|
|
50
|
+
export type Model = ReadonlyDeep_2<{
|
|
50
51
|
name: string;
|
|
51
52
|
dbName: string | null;
|
|
52
53
|
fields: Field[];
|
|
@@ -55,11 +56,11 @@ declare namespace DMMF {
|
|
|
55
56
|
documentation?: string;
|
|
56
57
|
primaryKey: PrimaryKey | null;
|
|
57
58
|
isGenerated?: boolean;
|
|
58
|
-
}
|
|
59
|
+
}>;
|
|
59
60
|
export type FieldKind = 'scalar' | 'object' | 'enum' | 'unsupported';
|
|
60
61
|
export type FieldNamespace = 'model' | 'prisma';
|
|
61
62
|
export type FieldLocation = 'scalar' | 'inputObjectTypes' | 'outputObjectTypes' | 'enumTypes' | 'fieldRefTypes';
|
|
62
|
-
export
|
|
63
|
+
export type Field = ReadonlyDeep_2<{
|
|
63
64
|
kind: FieldKind;
|
|
64
65
|
name: string;
|
|
65
66
|
isRequired: boolean;
|
|
@@ -82,13 +83,31 @@ declare namespace DMMF {
|
|
|
82
83
|
relationOnDelete?: string;
|
|
83
84
|
relationName?: string;
|
|
84
85
|
documentation?: string;
|
|
85
|
-
}
|
|
86
|
-
export
|
|
86
|
+
}>;
|
|
87
|
+
export type FieldDefault = ReadonlyDeep_2<{
|
|
87
88
|
name: string;
|
|
88
89
|
args: any[];
|
|
89
|
-
}
|
|
90
|
+
}>;
|
|
90
91
|
export type FieldDefaultScalar = string | boolean | number;
|
|
91
|
-
export
|
|
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';
|
|
110
|
+
export type Schema = ReadonlyDeep_2<{
|
|
92
111
|
rootQueryType?: string;
|
|
93
112
|
rootMutationType?: string;
|
|
94
113
|
inputObjectTypes: {
|
|
@@ -106,17 +125,17 @@ declare namespace DMMF {
|
|
|
106
125
|
fieldRefTypes: {
|
|
107
126
|
prisma?: FieldRefType[];
|
|
108
127
|
};
|
|
109
|
-
}
|
|
110
|
-
export
|
|
128
|
+
}>;
|
|
129
|
+
export type Query = ReadonlyDeep_2<{
|
|
111
130
|
name: string;
|
|
112
131
|
args: SchemaArg[];
|
|
113
132
|
output: QueryOutput;
|
|
114
|
-
}
|
|
115
|
-
export
|
|
133
|
+
}>;
|
|
134
|
+
export type QueryOutput = ReadonlyDeep_2<{
|
|
116
135
|
name: string;
|
|
117
136
|
isRequired: boolean;
|
|
118
137
|
isList: boolean;
|
|
119
|
-
}
|
|
138
|
+
}>;
|
|
120
139
|
export type TypeRef<AllowedLocations extends FieldLocation> = {
|
|
121
140
|
isList: boolean;
|
|
122
141
|
type: string;
|
|
@@ -124,33 +143,33 @@ declare namespace DMMF {
|
|
|
124
143
|
namespace?: FieldNamespace;
|
|
125
144
|
};
|
|
126
145
|
export type InputTypeRef = TypeRef<'scalar' | 'inputObjectTypes' | 'enumTypes' | 'fieldRefTypes'>;
|
|
127
|
-
export
|
|
146
|
+
export type SchemaArg = ReadonlyDeep_2<{
|
|
128
147
|
name: string;
|
|
129
148
|
comment?: string;
|
|
130
149
|
isNullable: boolean;
|
|
131
150
|
isRequired: boolean;
|
|
132
151
|
inputTypes: InputTypeRef[];
|
|
133
152
|
deprecation?: Deprecation;
|
|
134
|
-
}
|
|
135
|
-
export
|
|
153
|
+
}>;
|
|
154
|
+
export type OutputType = ReadonlyDeep_2<{
|
|
136
155
|
name: string;
|
|
137
156
|
fields: SchemaField[];
|
|
138
|
-
}
|
|
139
|
-
export
|
|
157
|
+
}>;
|
|
158
|
+
export type SchemaField = ReadonlyDeep_2<{
|
|
140
159
|
name: string;
|
|
141
160
|
isNullable?: boolean;
|
|
142
161
|
outputType: OutputTypeRef;
|
|
143
162
|
args: SchemaArg[];
|
|
144
163
|
deprecation?: Deprecation;
|
|
145
164
|
documentation?: string;
|
|
146
|
-
}
|
|
165
|
+
}>;
|
|
147
166
|
export type OutputTypeRef = TypeRef<'scalar' | 'outputObjectTypes' | 'enumTypes'>;
|
|
148
|
-
export
|
|
167
|
+
export type Deprecation = ReadonlyDeep_2<{
|
|
149
168
|
sinceVersion: string;
|
|
150
169
|
reason: string;
|
|
151
170
|
plannedRemovalVersion?: string;
|
|
152
|
-
}
|
|
153
|
-
export
|
|
171
|
+
}>;
|
|
172
|
+
export type InputType = ReadonlyDeep_2<{
|
|
154
173
|
name: string;
|
|
155
174
|
constraints: {
|
|
156
175
|
maxNumFields: number | null;
|
|
@@ -161,14 +180,14 @@ declare namespace DMMF {
|
|
|
161
180
|
source?: string;
|
|
162
181
|
};
|
|
163
182
|
fields: SchemaArg[];
|
|
164
|
-
}
|
|
165
|
-
export
|
|
183
|
+
}>;
|
|
184
|
+
export type FieldRefType = ReadonlyDeep_2<{
|
|
166
185
|
name: string;
|
|
167
186
|
allowTypes: FieldRefAllowType[];
|
|
168
187
|
fields: SchemaArg[];
|
|
169
|
-
}
|
|
188
|
+
}>;
|
|
170
189
|
export type FieldRefAllowType = TypeRef<'scalar' | 'enumTypes'>;
|
|
171
|
-
export
|
|
190
|
+
export type ModelMapping = ReadonlyDeep_2<{
|
|
172
191
|
model: string;
|
|
173
192
|
plural: string;
|
|
174
193
|
findUnique?: string | null;
|
|
@@ -178,6 +197,7 @@ declare namespace DMMF {
|
|
|
178
197
|
findMany?: string | null;
|
|
179
198
|
create?: string | null;
|
|
180
199
|
createMany?: string | null;
|
|
200
|
+
createManyAndReturn?: string | null;
|
|
181
201
|
update?: string | null;
|
|
182
202
|
updateMany?: string | null;
|
|
183
203
|
upsert?: string | null;
|
|
@@ -188,7 +208,7 @@ declare namespace DMMF {
|
|
|
188
208
|
count?: string | null;
|
|
189
209
|
findRaw?: string | null;
|
|
190
210
|
aggregateRaw?: string | null;
|
|
191
|
-
}
|
|
211
|
+
}>;
|
|
192
212
|
export enum ModelAction {
|
|
193
213
|
findUnique = "findUnique",
|
|
194
214
|
findUniqueOrThrow = "findUniqueOrThrow",
|
|
@@ -197,19 +217,148 @@ declare namespace DMMF {
|
|
|
197
217
|
findMany = "findMany",
|
|
198
218
|
create = "create",
|
|
199
219
|
createMany = "createMany",
|
|
220
|
+
createManyAndReturn = "createManyAndReturn",
|
|
200
221
|
update = "update",
|
|
201
222
|
updateMany = "updateMany",
|
|
202
223
|
upsert = "upsert",
|
|
203
224
|
delete = "delete",
|
|
204
225
|
deleteMany = "deleteMany",
|
|
205
226
|
groupBy = "groupBy",
|
|
206
|
-
count = "count",
|
|
227
|
+
count = "count",// TODO: count does not actually exist, why?
|
|
207
228
|
aggregate = "aggregate",
|
|
208
229
|
findRaw = "findRaw",
|
|
209
230
|
aggregateRaw = "aggregateRaw"
|
|
210
231
|
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
declare type ReadonlyDeep_2<O> = {
|
|
235
|
+
+readonly [K in keyof O]: ReadonlyDeep_2<O[K]>;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
240
|
+
|
|
241
|
+
@category Type
|
|
242
|
+
*/
|
|
243
|
+
type Primitive =
|
|
244
|
+
| null
|
|
245
|
+
| undefined
|
|
246
|
+
| string
|
|
247
|
+
| number
|
|
248
|
+
| boolean
|
|
249
|
+
| symbol
|
|
250
|
+
| bigint;
|
|
251
|
+
|
|
252
|
+
declare global {
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
254
|
+
interface SymbolConstructor {
|
|
255
|
+
readonly observable: symbol;
|
|
256
|
+
}
|
|
211
257
|
}
|
|
212
258
|
|
|
259
|
+
/**
|
|
260
|
+
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
261
|
+
*/
|
|
262
|
+
type BuiltIns = Primitive | void | Date | RegExp;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
Test if the given function has multiple call signatures.
|
|
266
|
+
|
|
267
|
+
Needed to handle the case of a single call signature with properties.
|
|
268
|
+
|
|
269
|
+
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
270
|
+
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
271
|
+
*/
|
|
272
|
+
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
273
|
+
T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
|
|
274
|
+
? B extends A
|
|
275
|
+
? A extends B
|
|
276
|
+
? false
|
|
277
|
+
: true
|
|
278
|
+
: true
|
|
279
|
+
: false;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type. The inverse of `ReadonlyDeep<T>`. Use `Writable<T>` if you only need one level deep.
|
|
283
|
+
|
|
284
|
+
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
|
|
285
|
+
|
|
286
|
+
@example
|
|
287
|
+
```
|
|
288
|
+
import type {WritableDeep} from 'type-fest';
|
|
289
|
+
|
|
290
|
+
type Foo = {
|
|
291
|
+
readonly a: number;
|
|
292
|
+
readonly b: readonly string[]; // To show that mutability is deeply affected.
|
|
293
|
+
readonly c: boolean;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const writableDeepFoo: WritableDeep<Foo> = {a: 1, b: ['2'], c: true};
|
|
297
|
+
writableDeepFoo.a = 3;
|
|
298
|
+
writableDeepFoo.b[0] = 'new value';
|
|
299
|
+
writableDeepFoo.b = ['something'];
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Note that types containing overloaded functions are not made deeply writable due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
303
|
+
|
|
304
|
+
@see Writable
|
|
305
|
+
@category Object
|
|
306
|
+
@category Array
|
|
307
|
+
@category Set
|
|
308
|
+
@category Map
|
|
309
|
+
*/
|
|
310
|
+
type WritableDeep<T> = T extends BuiltIns
|
|
311
|
+
? T
|
|
312
|
+
: T extends (...arguments_: any[]) => unknown
|
|
313
|
+
? {} extends WritableObjectDeep<T>
|
|
314
|
+
? T
|
|
315
|
+
: HasMultipleCallSignatures<T> extends true
|
|
316
|
+
? T
|
|
317
|
+
: ((...arguments_: Parameters<T>) => ReturnType<T>) & WritableObjectDeep<T>
|
|
318
|
+
: T extends ReadonlyMap<unknown, unknown>
|
|
319
|
+
? WritableMapDeep<T>
|
|
320
|
+
: T extends ReadonlySet<unknown>
|
|
321
|
+
? WritableSetDeep<T>
|
|
322
|
+
: T extends readonly unknown[]
|
|
323
|
+
? WritableArrayDeep<T>
|
|
324
|
+
: T extends object
|
|
325
|
+
? WritableObjectDeep<T>
|
|
326
|
+
: unknown;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
Same as `WritableDeep`, but accepts only `Map`s as inputs. Internal helper for `WritableDeep`.
|
|
330
|
+
*/
|
|
331
|
+
type WritableMapDeep<MapType extends ReadonlyMap<unknown, unknown>> =
|
|
332
|
+
MapType extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
333
|
+
? Map<WritableDeep<KeyType>, WritableDeep<ValueType>>
|
|
334
|
+
: MapType; // Should not heppen
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
Same as `WritableDeep`, but accepts only `Set`s as inputs. Internal helper for `WritableDeep`.
|
|
338
|
+
*/
|
|
339
|
+
type WritableSetDeep<SetType extends ReadonlySet<unknown>> =
|
|
340
|
+
SetType extends ReadonlySet<infer ItemType>
|
|
341
|
+
? Set<WritableDeep<ItemType>>
|
|
342
|
+
: SetType; // Should not heppen
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
Same as `WritableDeep`, but accepts only `object`s as inputs. Internal helper for `WritableDeep`.
|
|
346
|
+
*/
|
|
347
|
+
type WritableObjectDeep<ObjectType extends object> = {
|
|
348
|
+
-readonly [KeyType in keyof ObjectType]: WritableDeep<ObjectType[KeyType]>
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
Same as `WritableDeep`, but accepts only `Array`s as inputs. Internal helper for `WritableDeep`.
|
|
353
|
+
*/
|
|
354
|
+
type WritableArrayDeep<ArrayType extends readonly unknown[]> =
|
|
355
|
+
ArrayType extends readonly [] ? []
|
|
356
|
+
: ArrayType extends readonly [...infer U, infer V] ? [...WritableArrayDeep<U>, WritableDeep<V>]
|
|
357
|
+
: ArrayType extends readonly [infer U, ...infer V] ? [WritableDeep<U>, ...WritableArrayDeep<V>]
|
|
358
|
+
: ArrayType extends ReadonlyArray<infer U> ? Array<WritableDeep<U>>
|
|
359
|
+
: ArrayType extends Array<infer U> ? Array<WritableDeep<U>>
|
|
360
|
+
: ArrayType;
|
|
361
|
+
|
|
213
362
|
declare enum ReExport {
|
|
214
363
|
None = "None",
|
|
215
364
|
Directories = "Directories",
|
|
@@ -284,10 +433,11 @@ declare class ObjectSettings extends Array<ObjectSetting> {
|
|
|
284
433
|
fieldArguments(): Record<string, unknown> | undefined;
|
|
285
434
|
}
|
|
286
435
|
|
|
287
|
-
type Model = DMMF.Model
|
|
436
|
+
type Model = WritableDeep<DMMF.Model>;
|
|
437
|
+
type Schema = WritableDeep<DMMF.Schema>;
|
|
288
438
|
type GeneratorConfiguration = ReturnType<typeof createConfig>;
|
|
289
439
|
type EventArguments = {
|
|
290
|
-
schema:
|
|
440
|
+
schema: Schema;
|
|
291
441
|
models: Map<string, Model>;
|
|
292
442
|
modelNames: string[];
|
|
293
443
|
modelFields: Map<string, Map<string, Field>>;
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-nestjs-graphql",
|
|
3
|
-
"version": "20.0
|
|
3
|
+
"version": "20.1.0",
|
|
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
|
"bin": "bin.js",
|
|
7
|
-
"repository":
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/unlight/nestjs-graphql-prisma.git"
|
|
10
|
-
},
|
|
7
|
+
"repository": "https://github.com/unlight/nestjs-graphql-prisma.git",
|
|
11
8
|
"bugs": {
|
|
12
9
|
"url": "https://github.com/unlight/nestjs-graphql-prisma/issues"
|
|
13
10
|
},
|
|
@@ -72,7 +69,7 @@
|
|
|
72
69
|
}
|
|
73
70
|
},
|
|
74
71
|
"dependencies": {
|
|
75
|
-
"@prisma/generator-helper": "^5.
|
|
72
|
+
"@prisma/generator-helper": "^5.14.0",
|
|
76
73
|
"await-event-emitter": "^2.0.2",
|
|
77
74
|
"filenamify": "4.X",
|
|
78
75
|
"flat": "5.X",
|
|
@@ -88,31 +85,31 @@
|
|
|
88
85
|
"devDependencies": {
|
|
89
86
|
"@commitlint/cli": "^18.4.3",
|
|
90
87
|
"@commitlint/config-conventional": "^18.4.3",
|
|
91
|
-
"@nestjs/apollo": "^12.0
|
|
92
|
-
"@nestjs/common": "^10.
|
|
93
|
-
"@nestjs/core": "^10.
|
|
94
|
-
"@nestjs/graphql": "^12.
|
|
95
|
-
"@nestjs/platform-express": "^10.
|
|
88
|
+
"@nestjs/apollo": "^12.1.0",
|
|
89
|
+
"@nestjs/common": "^10.3.8",
|
|
90
|
+
"@nestjs/core": "^10.3.8",
|
|
91
|
+
"@nestjs/graphql": "^12.1.1",
|
|
92
|
+
"@nestjs/platform-express": "^10.3.8",
|
|
96
93
|
"@paljs/plugins": "^6.0.7",
|
|
97
|
-
"@prisma/client": "^5.
|
|
94
|
+
"@prisma/client": "^5.14.0",
|
|
98
95
|
"@semantic-release/changelog": "^6.0.3",
|
|
99
96
|
"@semantic-release/git": "^10.0.1",
|
|
100
97
|
"@semantic-release/github": "^9.2.5",
|
|
101
|
-
"@swc/core": "^1.
|
|
102
|
-
"@swc/helpers": "^0.5.
|
|
98
|
+
"@swc/core": "^1.5.7",
|
|
99
|
+
"@swc/helpers": "^0.5.11",
|
|
103
100
|
"@swc/register": "^0.1.10",
|
|
104
101
|
"@types/flat": "^5.0.5",
|
|
105
102
|
"@types/graceful-fs": "^4.1.9",
|
|
106
|
-
"@types/lodash": "^4.
|
|
103
|
+
"@types/lodash": "^4.17.4",
|
|
107
104
|
"@types/mocha": "^10.0.6",
|
|
108
|
-
"@types/node": "^20.
|
|
105
|
+
"@types/node": "^20.12.12",
|
|
109
106
|
"@types/pluralize": "^0.0.33",
|
|
110
107
|
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
111
108
|
"@typescript-eslint/parser": "^6.14.0",
|
|
112
109
|
"apollo-server-express": "^3.13.0",
|
|
113
|
-
"c8": "^
|
|
110
|
+
"c8": "^9.1.0",
|
|
114
111
|
"class-transformer": "^0.5.1",
|
|
115
|
-
"class-validator": "^0.14.
|
|
112
|
+
"class-validator": "^0.14.1",
|
|
116
113
|
"commitizen": "^4.3.0",
|
|
117
114
|
"cz-customizable": "^7.0.0",
|
|
118
115
|
"decimal.js": "^10.4.3",
|
|
@@ -121,25 +118,25 @@
|
|
|
121
118
|
"eslint-plugin-etc": "^2.0.3",
|
|
122
119
|
"eslint-plugin-import": "^2.29.1",
|
|
123
120
|
"eslint-plugin-only-warn": "^1.1.0",
|
|
124
|
-
"eslint-plugin-prettier": "^5.
|
|
125
|
-
"eslint-plugin-regexp": "^2.
|
|
121
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
122
|
+
"eslint-plugin-regexp": "^2.5.0",
|
|
126
123
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
127
|
-
"eslint-plugin-sort-class-members": "^1.
|
|
128
|
-
"eslint-plugin-unicorn": "^
|
|
124
|
+
"eslint-plugin-sort-class-members": "^1.20.0",
|
|
125
|
+
"eslint-plugin-unicorn": "^53.0.0",
|
|
129
126
|
"eslint-plugin-wix-editor": "^3.3.0",
|
|
130
127
|
"expect": "^29.7.0",
|
|
131
128
|
"git-branch-is": "^4.0.0",
|
|
132
129
|
"graphql": "^16.8.1",
|
|
133
|
-
"graphql-scalars": "^1.
|
|
130
|
+
"graphql-scalars": "^1.23.0",
|
|
134
131
|
"graphql-type-json": "^0.3.2",
|
|
135
|
-
"mocha": "^10.
|
|
132
|
+
"mocha": "^10.4.0",
|
|
136
133
|
"ololog": "^1.1.175",
|
|
137
|
-
"pkgroll": "^2.0
|
|
134
|
+
"pkgroll": "^2.1.0",
|
|
138
135
|
"precise-commits": "^1.0.2",
|
|
139
|
-
"prettier": "^3.
|
|
140
|
-
"prisma": "^5.
|
|
136
|
+
"prettier": "^3.2.5",
|
|
137
|
+
"prisma": "^5.14.0",
|
|
141
138
|
"prisma-graphql-type-decimal": "^3.0.0",
|
|
142
|
-
"reflect-metadata": "^0.
|
|
139
|
+
"reflect-metadata": "^0.2.2",
|
|
143
140
|
"request": "^2.88.2",
|
|
144
141
|
"rxjs": "^7.8.1",
|
|
145
142
|
"semantic-release": "^22.0.12",
|
|
@@ -147,7 +144,8 @@
|
|
|
147
144
|
"temp-dir": "2.X",
|
|
148
145
|
"ts-node": "^10.9.2",
|
|
149
146
|
"tslib": "^2.6.2",
|
|
150
|
-
"
|
|
147
|
+
"type-fest": "^4.18.2",
|
|
148
|
+
"typescript": "^5.4.5",
|
|
151
149
|
"watchexec-bin": "^1.0.0"
|
|
152
150
|
}
|
|
153
151
|
}
|