prisma-nestjs-graphql 15.3.2 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +131 -111
  3. package/package.json +21 -21
package/README.md CHANGED
@@ -23,7 +23,7 @@ generator nestgraphql {
23
23
  provider = "node node_modules/prisma-nestjs-graphql"
24
24
  // for yarn monorepos
25
25
  // provider = "prisma-nestjs-graphql"
26
- output = "../src/@generated/prisma-nestjs-graphql"
26
+ output = "../src/@generated"
27
27
  }
28
28
  ```
29
29
 
@@ -97,7 +97,7 @@ Example configuration:
97
97
  ```prisma
98
98
  generator nestgraphql {
99
99
  provider = "node node_modules/prisma-nestjs-graphql"
100
- output = "../src/@generated/prisma-nestjs-graphql"
100
+ output = "../src/@generated"
101
101
  reExport = Directories
102
102
  }
103
103
  ```
@@ -182,7 +182,7 @@ to set `UserWhereInput` need to configure generator the following way:
182
182
  ```prisma
183
183
  generator nestgraphql {
184
184
  provider = "node node_modules/prisma-nestjs-graphql"
185
- output = "../src/@generated/prisma-nestjs-graphql"
185
+ output = "../src/@generated"
186
186
  useInputType_WhereInput_ALL = "WhereInput"
187
187
  }
188
188
  ```
package/index.js CHANGED
@@ -73,7 +73,7 @@ function argsType(field, args) {
73
73
  ];
74
74
  if (`${modelName}GroupByArgs` === inputType1.name) {
75
75
  const byField = inputType1.fields.find((f) => f.name === "by");
76
- if (byField == null ? void 0 : byField.inputTypes) {
76
+ if (byField?.inputTypes) {
77
77
  byField.inputTypes = byField.inputTypes.filter((inputType2) => inputType2.isList);
78
78
  }
79
79
  }
@@ -165,21 +165,18 @@ function createAggregateInput(args) {
165
165
  minNumFields: null
166
166
  },
167
167
  name: className,
168
- fields: outputType2.fields.map((x) => {
169
- var _a;
170
- return {
171
- name: x.name,
172
- isNullable: (_a = x.isNullable) != null ? _a : true,
173
- isRequired: false,
174
- inputTypes: [
175
- {
176
- isList: false,
177
- type: "true",
178
- location: "scalar"
179
- }
180
- ]
181
- };
182
- })
168
+ fields: outputType2.fields.map((x) => ({
169
+ name: x.name,
170
+ isNullable: x.isNullable ?? true,
171
+ isRequired: false,
172
+ inputTypes: [
173
+ {
174
+ isList: false,
175
+ type: "true",
176
+ location: "scalar"
177
+ }
178
+ ]
179
+ }))
183
180
  };
184
181
  eventEmitter.emitSync("InputType", {
185
182
  ...args,
@@ -284,7 +281,6 @@ async function generateFiles(args) {
284
281
  overwrite: true
285
282
  });
286
283
  const statements1 = project.getSourceFiles().flatMap((s) => {
287
- var _a, _b;
288
284
  if (s === sourceFile) {
289
285
  return [];
290
286
  }
@@ -297,7 +293,7 @@ async function generateFiles(args) {
297
293
  }
298
294
  for (const property of statement.properties || []) {
299
295
  for (const decorator of property.decorators || []) {
300
- const fullName = (_b = (_a = classDeclaration == null ? void 0 : classDeclaration.getProperty(property.name)) == null ? void 0 : _a.getDecorator(decorator.name)) == null ? void 0 : _b.getFullName();
296
+ const fullName = classDeclaration?.getProperty(property.name)?.getDecorator(decorator.name)?.getFullName();
301
297
  (0, import_assert.ok)(fullName, `Cannot get full name of decorator of class ${statement.name}`);
302
298
  decorator.name = fullName;
303
299
  }
@@ -613,8 +609,8 @@ function propertyStructure(args) {
613
609
  kind: import_ts_morph3.StructureKind.Property,
614
610
  name,
615
611
  type: type1,
616
- hasQuestionToken: hasQuestionToken != null ? hasQuestionToken : isNullable,
617
- hasExclamationToken: hasExclamationToken != null ? hasExclamationToken : !isNullable,
612
+ hasQuestionToken: hasQuestionToken ?? isNullable,
613
+ hasExclamationToken: hasExclamationToken ?? !isNullable,
618
614
  decorators: [],
619
615
  leadingTrivia: "\n"
620
616
  };
@@ -623,8 +619,7 @@ __name(propertyStructure, "propertyStructure");
623
619
 
624
620
  // src/handlers/input-type.ts
625
621
  function inputType(args) {
626
- var _a, _b, _c, _d;
627
- const { inputType: inputType1, fileType, getSourceFile, config, eventEmitter, classDecoratorName, fieldSettings, getModelName: getModelName2, models, removeTypes, typeNames } = args;
622
+ const { classDecoratorName, classTransformerTypeModels, config, eventEmitter, fieldSettings, fileType, getModelName: getModelName2, getSourceFile, inputType: inputType1, models, removeTypes, typeNames } = args;
628
623
  typeNames.add(inputType1.name);
629
624
  const importDeclarations = new ImportDeclarationMap();
630
625
  const sourceFile = getSourceFile({
@@ -670,17 +665,18 @@ function inputType(args) {
670
665
  if (inputTypes.length === 0) {
671
666
  continue;
672
667
  }
673
- const usePattern = (useInputType == null ? void 0 : useInputType.ALL) || (useInputType == null ? void 0 : useInputType[name]);
668
+ const usePattern = useInputType?.ALL || useInputType?.[name];
674
669
  const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
675
670
  const { isList, location, type } = graphqlInputType;
676
671
  const typeName = String(type);
677
- const settings = modelFieldSettings == null ? void 0 : modelFieldSettings.get(name);
678
- const propertySettings = settings == null ? void 0 : settings.getPropertyType({
672
+ const settings = modelFieldSettings?.get(name);
673
+ const propertySettings = settings?.getPropertyType({
679
674
  name: inputType1.name,
680
675
  input: true
681
676
  });
682
- const isCustomsApplicable = typeName === ((_a = model == null ? void 0 : model.fields.find((f) => f.name === name)) == null ? void 0 : _a.type);
683
- const propertyType = (0, import_lodash3.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
677
+ const modelField = model?.fields.find((f) => f.name === name);
678
+ const isCustomsApplicable = typeName === modelField?.type;
679
+ const propertyType = (0, import_lodash3.castArray)(propertySettings?.name || getPropertyType({
684
680
  location,
685
681
  type: typeName
686
682
  }));
@@ -699,11 +695,11 @@ function inputType(args) {
699
695
  importDeclarations.add("Decimal", "@prisma/client/runtime");
700
696
  }
701
697
  let graphqlType;
702
- const shouldHideField = (settings == null ? void 0 : settings.shouldHideField({
698
+ const shouldHideField = settings?.shouldHideField({
703
699
  name: inputType1.name,
704
700
  input: true
705
- })) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType1.name));
706
- const fieldType = settings == null ? void 0 : settings.getFieldType({
701
+ }) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType1.name));
702
+ const fieldType = settings?.getFieldType({
707
703
  name: inputType1.name,
708
704
  input: true
709
705
  });
@@ -749,14 +745,52 @@ function inputType(args) {
749
745
  arguments: [
750
746
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
751
747
  import_json5.default.stringify({
752
- ...settings == null ? void 0 : settings.fieldArguments(),
748
+ ...settings?.fieldArguments(),
753
749
  nullable: !isRequired
754
750
  })
755
751
  ]
756
752
  });
753
+ if (graphqlType === "GraphQLDecimal") {
754
+ importDeclarations.add("transformToDecimal", "prisma-graphql-type-decimal");
755
+ importDeclarations.add("Transform", "class-transformer");
756
+ importDeclarations.add("Type", "class-transformer");
757
+ property.decorators.push({
758
+ name: "Type",
759
+ arguments: [
760
+ "() => Object"
761
+ ]
762
+ }, {
763
+ name: "Transform",
764
+ arguments: [
765
+ "transformToDecimal"
766
+ ]
767
+ });
768
+ } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
769
+ "connect",
770
+ "connectOrCreate",
771
+ "create",
772
+ "createMany",
773
+ "data",
774
+ "delete",
775
+ "deleteMany",
776
+ "disconnect",
777
+ "set",
778
+ "update",
779
+ "updateMany",
780
+ "upsert",
781
+ "where"
782
+ ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) || ""))) {
783
+ importDeclarations.add("Type", "class-transformer");
784
+ property.decorators.push({
785
+ name: "Type",
786
+ arguments: [
787
+ `() => ${graphqlType}`
788
+ ]
789
+ });
790
+ }
757
791
  if (isCustomsApplicable) {
758
792
  for (const options of settings || []) {
759
- if ((_c = options.kind === "Decorator" && options.input && ((_b = options.match) == null ? void 0 : _b.call(options, name))) != null ? _c : true) {
793
+ if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
760
794
  property.decorators.push({
761
795
  name: options.name,
762
796
  arguments: options.arguments
@@ -770,7 +804,7 @@ function inputType(args) {
770
804
  if (decorate.isMatchField(name) && decorate.isMatchType(inputType1.name)) {
771
805
  property.decorators.push({
772
806
  name: decorate.name,
773
- arguments: (_d = decorate.arguments) == null ? void 0 : _d.map((x) => (0, import_pupa.default)(x, {
807
+ arguments: decorate.arguments?.map((x) => (0, import_pupa.default)(x, {
774
808
  propertyType
775
809
  }))
776
810
  });
@@ -799,9 +833,8 @@ var import_lodash4 = require("lodash");
799
833
  var import_outmatch2 = __toESM(require("outmatch"));
800
834
  var ObjectSettings = class extends Array {
801
835
  shouldHideField({ name, input = false, output = false }) {
802
- var _a;
803
836
  const hideField = this.find((s) => s.name === "HideField");
804
- return Boolean((hideField == null ? void 0 : hideField.input) && input || (hideField == null ? void 0 : hideField.output) && output || ((_a = hideField == null ? void 0 : hideField.match) == null ? void 0 : _a.call(hideField, name)));
837
+ return Boolean(hideField?.input && input || hideField?.output && output || hideField?.match?.(name));
805
838
  }
806
839
  getFieldType({ name, input, output }) {
807
840
  const fieldType = this.find((s) => s.kind === "FieldType");
@@ -893,7 +926,6 @@ function createObjectSettings(args) {
893
926
  }
894
927
  __name(createObjectSettings, "createObjectSettings");
895
928
  function createSettingElement({ line, config, fieldElement, match }) {
896
- var _a, _b, _c, _d, _e;
897
929
  const result = {
898
930
  documentLine: "",
899
931
  element: void 0
@@ -903,7 +935,7 @@ function createSettingElement({ line, config, fieldElement, match }) {
903
935
  result.element = fieldElement;
904
936
  return result;
905
937
  }
906
- const name = (_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.name;
938
+ const name = match?.groups?.name;
907
939
  if (!(match && name)) {
908
940
  result.documentLine = line;
909
941
  return result;
@@ -925,14 +957,14 @@ function createSettingElement({ line, config, fieldElement, match }) {
925
957
  if ([
926
958
  "FieldType",
927
959
  "PropertyType"
928
- ].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
960
+ ].includes(name) && match.groups?.args) {
929
961
  const options2 = customType(match.groups.args);
930
962
  (0, import_lodash4.merge)(element, options2.namespace && config.fields[options2.namespace], options2, {
931
963
  kind: name
932
964
  });
933
965
  return result;
934
966
  }
935
- if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
967
+ if (name === "ObjectType" && match.groups?.args) {
936
968
  element.kind = "ObjectType";
937
969
  const options2 = customType(match.groups.args);
938
970
  if (typeof options2[0] === "string" && options2[0]) {
@@ -947,7 +979,7 @@ function createSettingElement({ line, config, fieldElement, match }) {
947
979
  };
948
980
  return result;
949
981
  }
950
- if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
982
+ if (name === "Directive" && match.groups?.args) {
951
983
  const options2 = customType(match.groups.args);
952
984
  (0, import_lodash4.merge)(element, {
953
985
  model: true,
@@ -964,14 +996,13 @@ function createSettingElement({ line, config, fieldElement, match }) {
964
996
  element.namespaceImport = namespace;
965
997
  const options = {
966
998
  name,
967
- arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
999
+ arguments: (match.groups?.args || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
968
1000
  };
969
1001
  (0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
970
1002
  return result;
971
1003
  }
972
1004
  __name(createSettingElement, "createSettingElement");
973
1005
  function customType(args) {
974
- var _a;
975
1006
  const result = {};
976
1007
  let options = parseArgs(args);
977
1008
  if (typeof options === "string") {
@@ -982,7 +1013,7 @@ function customType(args) {
982
1013
  Object.assign(result, options);
983
1014
  const namespace = getNamespace(options.name);
984
1015
  result.namespace = namespace;
985
- if ((_a = options.name) == null ? void 0 : _a.includes(".")) {
1016
+ if (options.name?.includes(".")) {
986
1017
  result.namespaceImport = namespace;
987
1018
  }
988
1019
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -994,7 +1025,6 @@ function customType(args) {
994
1025
  }
995
1026
  __name(customType, "customType");
996
1027
  function hideFieldDecorator(match) {
997
- var _a;
998
1028
  const result = {
999
1029
  name: "HideField",
1000
1030
  arguments: [],
@@ -1003,7 +1033,7 @@ function hideFieldDecorator(match) {
1003
1033
  namespaceImport: void 0,
1004
1034
  match: void 0
1005
1035
  };
1006
- if (!((_a = match.groups) == null ? void 0 : _a.args)) {
1036
+ if (!match.groups?.args) {
1007
1037
  result.output = true;
1008
1038
  return result;
1009
1039
  }
@@ -1030,10 +1060,10 @@ __name(hideFieldDecorator, "hideFieldDecorator");
1030
1060
  function parseArgs(string) {
1031
1061
  try {
1032
1062
  return import_json52.default.parse(string);
1033
- } catch (e) {
1063
+ } catch {
1034
1064
  try {
1035
1065
  return import_json52.default.parse(`[${string}]`);
1036
- } catch (e2) {
1066
+ } catch {
1037
1067
  throw new Error(`Failed to parse: ${string}`);
1038
1068
  }
1039
1069
  }
@@ -1053,23 +1083,26 @@ __name(getNamespace, "getNamespace");
1053
1083
 
1054
1084
  // src/handlers/model-data.ts
1055
1085
  function modelData(model, args) {
1056
- const { config, modelNames, models, modelFields, fieldSettings } = args;
1086
+ const { config, modelNames, models, modelFields, fieldSettings, classTransformerTypeModels } = args;
1057
1087
  modelNames.push(model.name);
1058
1088
  models.set(model.name, model);
1059
1089
  const modelFieldsValue = /* @__PURE__ */ new Map();
1060
1090
  modelFields.set(model.name, modelFieldsValue);
1061
1091
  const fieldSettingsValue = /* @__PURE__ */ new Map();
1062
1092
  fieldSettings.set(model.name, fieldSettingsValue);
1063
- for (const field of model.fields) {
1064
- if (field.documentation) {
1093
+ for (const field1 of model.fields) {
1094
+ if (field1.documentation) {
1065
1095
  const { documentation, settings } = createObjectSettings({
1066
- text: field.documentation,
1096
+ text: field1.documentation,
1067
1097
  config
1068
1098
  });
1069
- field.documentation = documentation;
1070
- fieldSettingsValue.set(field.name, settings);
1099
+ field1.documentation = documentation;
1100
+ fieldSettingsValue.set(field1.name, settings);
1071
1101
  }
1072
- modelFieldsValue.set(field.name, field);
1102
+ modelFieldsValue.set(field1.name, field1);
1103
+ }
1104
+ if (model.fields.some((field) => field.type === "Decimal")) {
1105
+ classTransformerTypeModels.add(model.name);
1073
1106
  }
1074
1107
  }
1075
1108
  __name(modelData, "modelData");
@@ -1083,7 +1116,6 @@ var import_ts_morph5 = require("ts-morph");
1083
1116
 
1084
1117
  // src/helpers/create-comment.ts
1085
1118
  function createComment(documentation, settings) {
1086
- var _a;
1087
1119
  const documentationLines = documentation.split("\n");
1088
1120
  const commentLines = [
1089
1121
  "/**"
@@ -1091,7 +1123,7 @@ function createComment(documentation, settings) {
1091
1123
  for (const line of documentationLines) {
1092
1124
  commentLines.push(` * ${line}`);
1093
1125
  }
1094
- const deprecationReason = (_a = settings == null ? void 0 : settings.fieldArguments()) == null ? void 0 : _a.deprecationReason;
1126
+ const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1095
1127
  if (deprecationReason) {
1096
1128
  commentLines.push(` * @deprecated ${deprecationReason}`);
1097
1129
  }
@@ -1109,7 +1141,6 @@ __name(getOutputTypeName, "getOutputTypeName");
1109
1141
  // src/handlers/model-output-type.ts
1110
1142
  var nestjsGraphql = "@nestjs/graphql";
1111
1143
  function modelOutputType(outputType2, args) {
1112
- var _a, _b, _c, _d, _e, _f;
1113
1144
  const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
1114
1145
  const model = models.get(outputType2.name);
1115
1146
  (0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
@@ -1162,17 +1193,17 @@ function modelOutputType(outputType2, args) {
1162
1193
  fileType = "output";
1163
1194
  outputTypeName = getOutputTypeName(outputTypeName);
1164
1195
  }
1165
- const modelField = (_a = modelFields.get(model.name)) == null ? void 0 : _a.get(field.name);
1166
- const settings = (_b = fieldSettings.get(model.name)) == null ? void 0 : _b.get(field.name);
1167
- const fieldType = settings == null ? void 0 : settings.getFieldType({
1196
+ const modelField = modelFields.get(model.name)?.get(field.name);
1197
+ const settings = fieldSettings.get(model.name)?.get(field.name);
1198
+ const fieldType = settings?.getFieldType({
1168
1199
  name: outputType2.name,
1169
1200
  output: true
1170
1201
  });
1171
- const propertySettings = settings == null ? void 0 : settings.getPropertyType({
1202
+ const propertySettings = settings?.getPropertyType({
1172
1203
  name: outputType2.name,
1173
1204
  output: true
1174
1205
  });
1175
- const propertyType = (0, import_lodash5.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1206
+ const propertyType = (0, import_lodash5.castArray)(propertySettings?.name || getPropertyType({
1176
1207
  location,
1177
1208
  type: outputTypeName
1178
1209
  }));
@@ -1192,7 +1223,7 @@ function modelOutputType(outputType2, args) {
1192
1223
  sourceFile,
1193
1224
  fileType,
1194
1225
  location,
1195
- isId: modelField == null ? void 0 : modelField.isId,
1226
+ isId: modelField?.isId,
1196
1227
  noTypeId: config.noTypeId,
1197
1228
  typeName: outputTypeName,
1198
1229
  getSourceFile
@@ -1210,10 +1241,10 @@ function modelOutputType(outputType2, args) {
1210
1241
  propertyType,
1211
1242
  isList
1212
1243
  });
1213
- if (typeof property.leadingTrivia === "string" && (modelField == null ? void 0 : modelField.documentation)) {
1244
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1214
1245
  property.leadingTrivia += createComment(modelField.documentation, settings);
1215
1246
  }
1216
- (_c = classStructure.properties) == null ? void 0 : _c.push(property);
1247
+ classStructure.properties?.push(property);
1217
1248
  if (propertySettings) {
1218
1249
  importDeclarations.create({
1219
1250
  ...propertySettings
@@ -1222,7 +1253,7 @@ function modelOutputType(outputType2, args) {
1222
1253
  importDeclarations.add("Decimal", "@prisma/client/runtime");
1223
1254
  }
1224
1255
  (0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
1225
- if (settings == null ? void 0 : settings.shouldHideField({
1256
+ if (settings?.shouldHideField({
1226
1257
  name: outputType2.name,
1227
1258
  output: true
1228
1259
  })) {
@@ -1237,19 +1268,19 @@ function modelOutputType(outputType2, args) {
1237
1268
  arguments: [
1238
1269
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1239
1270
  import_json53.default.stringify({
1240
- ...settings == null ? void 0 : settings.fieldArguments(),
1271
+ ...settings?.fieldArguments(),
1241
1272
  nullable: Boolean(field.isNullable),
1242
1273
  defaultValue: [
1243
1274
  "number",
1244
1275
  "string",
1245
1276
  "boolean"
1246
- ].includes(typeof (modelField == null ? void 0 : modelField.default)) ? modelField == null ? void 0 : modelField.default : void 0,
1247
- description: modelField == null ? void 0 : modelField.documentation
1277
+ ].includes(typeof modelField?.default) ? modelField?.default : void 0,
1278
+ description: modelField?.documentation
1248
1279
  })
1249
1280
  ]
1250
1281
  });
1251
1282
  for (const setting of settings || []) {
1252
- if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ? void 0 : _d.call(setting, field.name)) != null ? _e : true)) {
1283
+ if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
1253
1284
  property.decorators.push({
1254
1285
  name: setting.name,
1255
1286
  arguments: setting.arguments
@@ -1262,7 +1293,7 @@ function modelOutputType(outputType2, args) {
1262
1293
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
1263
1294
  property.decorators.push({
1264
1295
  name: decorate.name,
1265
- arguments: (_f = decorate.arguments) == null ? void 0 : _f.map((x) => (0, import_pupa2.default)(x, {
1296
+ arguments: decorate.arguments?.map((x) => (0, import_pupa2.default)(x, {
1266
1297
  propertyType
1267
1298
  }))
1268
1299
  });
@@ -1321,12 +1352,6 @@ function getExportDeclaration(name, statements) {
1321
1352
  }
1322
1353
  __name(getExportDeclaration, "getExportDeclaration");
1323
1354
 
1324
- // src/helpers/is-list-input.ts
1325
- function isListInput(typeName, model) {
1326
- return typeName.startsWith(`${model}Create`) || typeName.startsWith(`${model}Update`);
1327
- }
1328
- __name(isListInput, "isListInput");
1329
-
1330
1355
  // src/handlers/no-atomic-operations.ts
1331
1356
  function noAtomicOperations(eventEmitter) {
1332
1357
  eventEmitter.on("BeforeInputType", beforeInputType2);
@@ -1336,10 +1361,11 @@ __name(noAtomicOperations, "noAtomicOperations");
1336
1361
  function beforeInputType2(args) {
1337
1362
  const { inputType: inputType1, getModelName: getModelName2 } = args;
1338
1363
  for (const field of inputType1.fields) {
1364
+ const fieldName = field.name;
1339
1365
  field.inputTypes = field.inputTypes.filter((inputType2) => {
1340
1366
  const inputTypeName = String(inputType2.type);
1341
1367
  const modelName = getModelName2(inputTypeName);
1342
- if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName)) {
1368
+ if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName, fieldName)) {
1343
1369
  return false;
1344
1370
  }
1345
1371
  return true;
@@ -1348,10 +1374,9 @@ function beforeInputType2(args) {
1348
1374
  }
1349
1375
  __name(beforeInputType2, "beforeInputType");
1350
1376
  function beforeGenerateFiles(args) {
1351
- var _a;
1352
1377
  const { project } = args;
1353
1378
  for (const sourceFile of project.getSourceFiles()) {
1354
- const className = (_a = sourceFile.getClass(() => true)) == null ? void 0 : _a.getName();
1379
+ const className = sourceFile.getClass(() => true)?.getName();
1355
1380
  if (className && isAtomicOperation(className)) {
1356
1381
  project.removeSourceFile(sourceFile);
1357
1382
  }
@@ -1365,6 +1390,10 @@ function isAtomicOperation(typeName) {
1365
1390
  return false;
1366
1391
  }
1367
1392
  __name(isAtomicOperation, "isAtomicOperation");
1393
+ function isListInput(typeName, model, field) {
1394
+ return typeName === `${model}Create${field}Input` || typeName === `${model}Update${field}Input`;
1395
+ }
1396
+ __name(isListInput, "isListInput");
1368
1397
 
1369
1398
  // src/handlers/output-type.ts
1370
1399
  var import_assert4 = require("assert");
@@ -1373,14 +1402,13 @@ var import_lodash6 = require("lodash");
1373
1402
  var import_ts_morph6 = require("ts-morph");
1374
1403
  var nestjsGraphql2 = "@nestjs/graphql";
1375
1404
  function outputType(outputType1, args) {
1376
- var _a, _b, _c, _d, _e;
1377
1405
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2, config } = args;
1378
1406
  const importDeclarations = new ImportDeclarationMap();
1379
1407
  const fileType = "output";
1380
1408
  const modelName = getModelName2(outputType1.name) || "";
1381
1409
  const model = models.get(modelName);
1382
1410
  const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType1.name) && String(outputType1.name).startsWith(model.name);
1383
- const isCountOutput = (model == null ? void 0 : model.name) && outputType1.name === `${model.name}CountOutputType`;
1411
+ const isCountOutput = model?.name && outputType1.name === `${model.name}CountOutputType`;
1384
1412
  outputType1.name = getOutputTypeName(outputType1.name);
1385
1413
  if (isAggregateOutput) {
1386
1414
  eventEmitter.emitSync("AggregateOutput", {
@@ -1409,14 +1437,14 @@ function outputType(outputType1, args) {
1409
1437
  for (const field of outputType1.fields) {
1410
1438
  const { location, isList, type } = field.outputType;
1411
1439
  const outputTypeName = getOutputTypeName(String(type));
1412
- const settings = isCountOutput ? void 0 : model && ((_a = fieldSettings.get(model.name)) == null ? void 0 : _a.get(field.name));
1413
- const propertySettings = settings == null ? void 0 : settings.getPropertyType({
1440
+ const settings = isCountOutput ? void 0 : model && fieldSettings.get(model.name)?.get(field.name);
1441
+ const propertySettings = settings?.getPropertyType({
1414
1442
  name: outputType1.name,
1415
1443
  output: true
1416
1444
  });
1417
- const isCustomsApplicable = outputTypeName === ((_b = model == null ? void 0 : model.fields.find((f) => f.name === field.name)) == null ? void 0 : _b.type);
1445
+ const isCustomsApplicable = outputTypeName === model?.fields.find((f) => f.name === field.name)?.type;
1418
1446
  field.outputType.type = outputTypeName;
1419
- const propertyType = (0, import_lodash6.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1447
+ const propertyType = (0, import_lodash6.castArray)(propertySettings?.name || getPropertyType({
1420
1448
  location,
1421
1449
  type: outputTypeName
1422
1450
  }));
@@ -1427,7 +1455,7 @@ function outputType(outputType1, args) {
1427
1455
  propertyType,
1428
1456
  isList
1429
1457
  });
1430
- (_c = classStructure.properties) == null ? void 0 : _c.push(property);
1458
+ classStructure.properties?.push(property);
1431
1459
  if (propertySettings) {
1432
1460
  importDeclarations.create({
1433
1461
  ...propertySettings
@@ -1436,11 +1464,11 @@ function outputType(outputType1, args) {
1436
1464
  importDeclarations.add("Decimal", "@prisma/client/runtime");
1437
1465
  }
1438
1466
  let graphqlType;
1439
- const shouldHideField = (settings == null ? void 0 : settings.shouldHideField({
1467
+ const shouldHideField = settings?.shouldHideField({
1440
1468
  name: outputType1.name,
1441
1469
  output: true
1442
- })) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName));
1443
- const fieldType = settings == null ? void 0 : settings.getFieldType({
1470
+ }) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName));
1471
+ const fieldType = settings?.getFieldType({
1444
1472
  name: outputType1.name,
1445
1473
  output: true
1446
1474
  });
@@ -1488,14 +1516,14 @@ function outputType(outputType1, args) {
1488
1516
  arguments: [
1489
1517
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1490
1518
  import_json54.default.stringify({
1491
- ...settings == null ? void 0 : settings.fieldArguments(),
1519
+ ...settings?.fieldArguments(),
1492
1520
  nullable: Boolean(field.isNullable)
1493
1521
  })
1494
1522
  ]
1495
1523
  });
1496
1524
  if (isCustomsApplicable) {
1497
1525
  for (const options of settings || []) {
1498
- if ((_e = options.kind === "Decorator" && options.output && ((_d = options.match) == null ? void 0 : _d.call(options, field.name))) != null ? _e : true) {
1526
+ if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1499
1527
  property.decorators.push({
1500
1528
  name: options.name,
1501
1529
  arguments: options.arguments
@@ -1529,8 +1557,7 @@ function purgeOutput(emitter) {
1529
1557
  }
1530
1558
  __name(purgeOutput, "purgeOutput");
1531
1559
  function begin({ project, output }) {
1532
- var _a;
1533
- const sourceFiles = (_a = project.getDirectory(output)) == null ? void 0 : _a.getDescendantSourceFiles();
1560
+ const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1534
1561
  if (sourceFiles) {
1535
1562
  for (const sourceFile of sourceFiles) {
1536
1563
  sourceFile.delete();
@@ -1539,12 +1566,11 @@ function begin({ project, output }) {
1539
1566
  }
1540
1567
  __name(begin, "begin");
1541
1568
  async function end({ project, output }) {
1542
- var _a;
1543
- const directories = (_a = project.getDirectory(output)) == null ? void 0 : _a.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1569
+ const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1544
1570
  for (const directory1 of directories || []) {
1545
1571
  try {
1546
1572
  await import_fs.promises.rmdir(directory1);
1547
- } catch (e) {
1573
+ } catch {
1548
1574
  }
1549
1575
  }
1550
1576
  }
@@ -1667,7 +1693,7 @@ function registerEnum(enumType, args) {
1667
1693
  ...importDeclarations.toStatements(),
1668
1694
  enumStructure,
1669
1695
  "\n",
1670
- `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum == null ? void 0 : dataModelEnum.documentation)} })`
1696
+ `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum?.documentation)} })`
1671
1697
  ]
1672
1698
  });
1673
1699
  }
@@ -1714,7 +1740,6 @@ var import_json55 = __toESM(require("json5"));
1714
1740
  var import_lodash7 = require("lodash");
1715
1741
  var import_outmatch3 = __toESM(require("outmatch"));
1716
1742
  function createConfig(data) {
1717
- var _a;
1718
1743
  const config = (0, import_lodash7.merge)({}, (0, import_flat.unflatten)(data, {
1719
1744
  delimiter: "_"
1720
1745
  }));
@@ -1733,7 +1758,7 @@ function createConfig(data) {
1733
1758
  config.reExport = "All";
1734
1759
  }
1735
1760
  }
1736
- const fields = Object.fromEntries(Object.entries((_a = config.fields) != null ? _a : {}).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
1761
+ const fields = Object.fromEntries(Object.entries(config.fields ?? {}).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
1737
1762
  const fieldSetting = {
1738
1763
  arguments: [],
1739
1764
  output: toBoolean(value.output),
@@ -1931,13 +1956,6 @@ function getModelName(args) {
1931
1956
  return test;
1932
1957
  }
1933
1958
  }
1934
- if (name.slice(-5) === "Input") {
1935
- for (const model of modelNames) {
1936
- if (isListInput(name, model)) {
1937
- return model;
1938
- }
1939
- }
1940
- }
1941
1959
  return void 0;
1942
1960
  }
1943
1961
  __name(getModelName, "getModelName");
@@ -1980,7 +1998,9 @@ var splitKeywords = [
1980
1998
  "SumOrderBy",
1981
1999
  "MinOrderBy",
1982
2000
  "MaxOrderBy",
1983
- "AvgOrderBy"
2001
+ "AvgOrderBy",
2002
+ "Create",
2003
+ "Update"
1984
2004
  ].sort((a, b) => b.length - a.length);
1985
2005
  var endsWithKeywords = [
1986
2006
  "Aggregate",
@@ -2052,9 +2072,8 @@ var middleKeywords = [
2052
2072
 
2053
2073
  // src/generate.ts
2054
2074
  async function generate(args) {
2055
- var _a;
2056
2075
  const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
2057
- const generatorOutputValue = (_a = generator.output) == null ? void 0 : _a.value;
2076
+ const generatorOutputValue = generator.output?.value;
2058
2077
  (0, import_assert6.ok)(generatorOutputValue, "Missing generator configuration: output");
2059
2078
  const eventEmitter = new import_await_event_emitter.default();
2060
2079
  eventEmitter.on("Warning", warning);
@@ -2117,7 +2136,8 @@ async function generate(args) {
2117
2136
  typeNames: /* @__PURE__ */ new Set(),
2118
2137
  enums: (0, import_lodash10.mapKeys)(datamodel.enums, (x) => x.name),
2119
2138
  getModelName: getModelName2,
2120
- removeTypes
2139
+ removeTypes,
2140
+ classTransformerTypeModels: /* @__PURE__ */ new Set()
2121
2141
  };
2122
2142
  if (connectCallback) {
2123
2143
  await connectCallback(eventEmitter, eventArguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "15.3.2",
3
+ "version": "16.0.1",
4
4
  "license": "MIT",
5
5
  "description": "Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module",
6
6
  "main": "index.js",
@@ -23,9 +23,9 @@
23
23
  "scripts": {
24
24
  "test": "npm run eslint && npm run tscheck && npm run test:cov",
25
25
  "mocha": "node node_modules/mocha/bin/mocha",
26
- "test:r": "npm run mocha -- -r ts-node/register src/**/*.spec.ts",
27
- "test:cov": "c8 --reporter text --exclude \"**/*.spec.ts\" --exclude \"**/test/**\" npm run test:r -- --no-timeouts",
28
- "test:w": "npm run test:r -- --watch-files src --watch --timeout=10s",
26
+ "test:r": "npm run mocha -- -r ts-node/register --no-timeouts src/**/*.spec.ts",
27
+ "test:cov": "c8 --reporter text --exclude \"**/*.spec.ts\" --exclude \"**/test/**\" npm run test:r",
28
+ "test:w": "npm run test:r -- --watch-files src --watch",
29
29
  "test:d": "ndb -r @swc/register node_modules/mocha/bin/_mocha --no-timeouts --watch-files src/**/*.ts --watch src/**/*.spec.ts",
30
30
  "tscheck": "tsc --noEmit",
31
31
  "tscheck:w": "npm run tscheck -- --watch",
@@ -36,7 +36,8 @@
36
36
  "prisma:g": "node node_modules/prisma/build/index.js generate",
37
37
  "format": "npx prettier ./@generated --write",
38
38
  "regen": "rm -rf @generated && npm run prisma:g && npm run format",
39
- "example": "ts-node-dev example/main.ts",
39
+ "rt": "npm run regen && npm test",
40
+ "example": "node-dev example/main.ts",
40
41
  "clean_cache": "rm -rf node_modules/.cache",
41
42
  "compatibilty_check": "sh Taskfile compatibilty_check",
42
43
  "commit": "cz"
@@ -64,35 +65,35 @@
64
65
  "ts-morph": ">=11"
65
66
  },
66
67
  "devDependencies": {
67
- "@nestjs/apollo": "^10.0.11",
68
- "@commitlint/cli": "^16.2.4",
69
- "@commitlint/config-conventional": "^16.2.4",
70
- "@nestjs/common": "^8.4.4",
71
- "@nestjs/core": "^8.4.4",
72
- "@nestjs/graphql": "^10.0.11",
73
- "@nestjs/platform-express": "^8.4.4",
68
+ "@commitlint/cli": "^17.0.0",
69
+ "@commitlint/config-conventional": "^17.0.0",
70
+ "@nestjs/apollo": "^10.0.12",
71
+ "@nestjs/common": "^8.4.5",
72
+ "@nestjs/core": "^8.4.5",
73
+ "@nestjs/graphql": "^10.0.12",
74
+ "@nestjs/platform-express": "^8.4.5",
74
75
  "@paljs/plugins": "^4.1.0",
75
76
  "@prisma/client": "^3.14.0",
76
77
  "@semantic-release/changelog": "^6.0.1",
77
78
  "@semantic-release/git": "^10.0.1",
78
- "@swc/core": "^1.2.181",
79
+ "@swc/core": "^1.2.189",
79
80
  "@swc/helpers": "^0.3.13",
80
81
  "@swc/register": "^0.1.10",
81
82
  "@types/flat": "^5.0.2",
82
83
  "@types/lodash": "^4.14.182",
83
84
  "@types/mocha": "^9.1.1",
84
- "@types/node": "^17.0.31",
85
+ "@types/node": "^17.0.35",
85
86
  "@types/pluralize": "^0.0.29",
86
- "@typescript-eslint/eslint-plugin": "^5.23.0",
87
- "@typescript-eslint/parser": "^5.23.0",
87
+ "@typescript-eslint/eslint-plugin": "^5.25.0",
88
+ "@typescript-eslint/parser": "^5.25.0",
88
89
  "apollo-server-express": "^3.7.0",
89
- "c8": "^7.11.2",
90
+ "c8": "^7.11.3",
90
91
  "class-transformer": "^0.5.1",
91
92
  "class-validator": "^0.13.2",
92
93
  "commitizen": "^4.2.4",
93
94
  "cz-customizable": "^6.3.0",
94
95
  "decimal.js": "^10.3.1",
95
- "eslint": "^8.15.0",
96
+ "eslint": "^8.16.0",
96
97
  "eslint-import-resolver-node": "^0.3.6",
97
98
  "eslint-plugin-etc": "^2.0.2",
98
99
  "eslint-plugin-import": "^2.26.0",
@@ -114,15 +115,14 @@
114
115
  "precise-commits": "^1.0.2",
115
116
  "prettier": "^2.6.2",
116
117
  "prisma": "^3.14.0",
117
- "prisma-graphql-type-decimal": "^2.0.0",
118
+ "prisma-graphql-type-decimal": "^2.0.2",
118
119
  "reflect-metadata": "^0.1.13",
119
120
  "request": "^2.88.2",
120
121
  "rxjs": "^7.5.5",
121
122
  "semantic-release": "^19.0.2",
122
123
  "simplytyped": "^3.3.0",
123
124
  "temp-dir": "^2.0.0",
124
- "ts-node": "^10.7.0",
125
- "ts-node-dev": "^1.1.8",
125
+ "ts-node": "^10.8.0",
126
126
  "tslib": "^2.4.0",
127
127
  "typescript": "^4.6.4",
128
128
  "watchexec-bin": "^1.0.0"