prisma-nestjs-graphql 16.0.0 → 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 +95 -107
  3. package/package.json +1 -1
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;
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,18 +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 modelField = model == null ? void 0 : model.fields.find((f) => f.name === name);
683
- const isCustomsApplicable = typeName === (modelField == null ? void 0 : modelField.type);
684
- 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({
685
680
  location,
686
681
  type: typeName
687
682
  }));
@@ -700,11 +695,11 @@ function inputType(args) {
700
695
  importDeclarations.add("Decimal", "@prisma/client/runtime");
701
696
  }
702
697
  let graphqlType;
703
- const shouldHideField = (settings == null ? void 0 : settings.shouldHideField({
698
+ const shouldHideField = settings?.shouldHideField({
704
699
  name: inputType1.name,
705
700
  input: true
706
- })) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType1.name));
707
- 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({
708
703
  name: inputType1.name,
709
704
  input: true
710
705
  });
@@ -750,7 +745,7 @@ function inputType(args) {
750
745
  arguments: [
751
746
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
752
747
  import_json5.default.stringify({
753
- ...settings == null ? void 0 : settings.fieldArguments(),
748
+ ...settings?.fieldArguments(),
754
749
  nullable: !isRequired
755
750
  })
756
751
  ]
@@ -770,20 +765,21 @@ function inputType(args) {
770
765
  "transformToDecimal"
771
766
  ]
772
767
  });
773
- } else if (location === "inputObjectTypes" && ((modelField == null ? void 0 : modelField.type) === "Decimal" || [
774
- "data",
775
- "where",
776
- "create",
768
+ } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
769
+ "connect",
777
770
  "connectOrCreate",
778
- "upsert",
779
- "set",
780
- "disconnect",
771
+ "create",
772
+ "createMany",
773
+ "data",
781
774
  "delete",
782
- "connect",
775
+ "deleteMany",
776
+ "disconnect",
777
+ "set",
783
778
  "update",
784
779
  "updateMany",
785
- "deleteMany"
786
- ].includes(name))) {
780
+ "upsert",
781
+ "where"
782
+ ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) || ""))) {
787
783
  importDeclarations.add("Type", "class-transformer");
788
784
  property.decorators.push({
789
785
  name: "Type",
@@ -794,7 +790,7 @@ function inputType(args) {
794
790
  }
795
791
  if (isCustomsApplicable) {
796
792
  for (const options of settings || []) {
797
- if ((_b = options.kind === "Decorator" && options.input && ((_a = options.match) == null ? void 0 : _a.call(options, name))) != null ? _b : true) {
793
+ if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
798
794
  property.decorators.push({
799
795
  name: options.name,
800
796
  arguments: options.arguments
@@ -808,7 +804,7 @@ function inputType(args) {
808
804
  if (decorate.isMatchField(name) && decorate.isMatchType(inputType1.name)) {
809
805
  property.decorators.push({
810
806
  name: decorate.name,
811
- arguments: (_c = decorate.arguments) == null ? void 0 : _c.map((x) => (0, import_pupa.default)(x, {
807
+ arguments: decorate.arguments?.map((x) => (0, import_pupa.default)(x, {
812
808
  propertyType
813
809
  }))
814
810
  });
@@ -837,9 +833,8 @@ var import_lodash4 = require("lodash");
837
833
  var import_outmatch2 = __toESM(require("outmatch"));
838
834
  var ObjectSettings = class extends Array {
839
835
  shouldHideField({ name, input = false, output = false }) {
840
- var _a;
841
836
  const hideField = this.find((s) => s.name === "HideField");
842
- 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));
843
838
  }
844
839
  getFieldType({ name, input, output }) {
845
840
  const fieldType = this.find((s) => s.kind === "FieldType");
@@ -931,7 +926,6 @@ function createObjectSettings(args) {
931
926
  }
932
927
  __name(createObjectSettings, "createObjectSettings");
933
928
  function createSettingElement({ line, config, fieldElement, match }) {
934
- var _a, _b, _c, _d, _e;
935
929
  const result = {
936
930
  documentLine: "",
937
931
  element: void 0
@@ -941,7 +935,7 @@ function createSettingElement({ line, config, fieldElement, match }) {
941
935
  result.element = fieldElement;
942
936
  return result;
943
937
  }
944
- const name = (_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.name;
938
+ const name = match?.groups?.name;
945
939
  if (!(match && name)) {
946
940
  result.documentLine = line;
947
941
  return result;
@@ -963,14 +957,14 @@ function createSettingElement({ line, config, fieldElement, match }) {
963
957
  if ([
964
958
  "FieldType",
965
959
  "PropertyType"
966
- ].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
960
+ ].includes(name) && match.groups?.args) {
967
961
  const options2 = customType(match.groups.args);
968
962
  (0, import_lodash4.merge)(element, options2.namespace && config.fields[options2.namespace], options2, {
969
963
  kind: name
970
964
  });
971
965
  return result;
972
966
  }
973
- if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
967
+ if (name === "ObjectType" && match.groups?.args) {
974
968
  element.kind = "ObjectType";
975
969
  const options2 = customType(match.groups.args);
976
970
  if (typeof options2[0] === "string" && options2[0]) {
@@ -985,7 +979,7 @@ function createSettingElement({ line, config, fieldElement, match }) {
985
979
  };
986
980
  return result;
987
981
  }
988
- if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
982
+ if (name === "Directive" && match.groups?.args) {
989
983
  const options2 = customType(match.groups.args);
990
984
  (0, import_lodash4.merge)(element, {
991
985
  model: true,
@@ -1002,14 +996,13 @@ function createSettingElement({ line, config, fieldElement, match }) {
1002
996
  element.namespaceImport = namespace;
1003
997
  const options = {
1004
998
  name,
1005
- 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)
1006
1000
  };
1007
1001
  (0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
1008
1002
  return result;
1009
1003
  }
1010
1004
  __name(createSettingElement, "createSettingElement");
1011
1005
  function customType(args) {
1012
- var _a;
1013
1006
  const result = {};
1014
1007
  let options = parseArgs(args);
1015
1008
  if (typeof options === "string") {
@@ -1020,7 +1013,7 @@ function customType(args) {
1020
1013
  Object.assign(result, options);
1021
1014
  const namespace = getNamespace(options.name);
1022
1015
  result.namespace = namespace;
1023
- if ((_a = options.name) == null ? void 0 : _a.includes(".")) {
1016
+ if (options.name?.includes(".")) {
1024
1017
  result.namespaceImport = namespace;
1025
1018
  }
1026
1019
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -1032,7 +1025,6 @@ function customType(args) {
1032
1025
  }
1033
1026
  __name(customType, "customType");
1034
1027
  function hideFieldDecorator(match) {
1035
- var _a;
1036
1028
  const result = {
1037
1029
  name: "HideField",
1038
1030
  arguments: [],
@@ -1041,7 +1033,7 @@ function hideFieldDecorator(match) {
1041
1033
  namespaceImport: void 0,
1042
1034
  match: void 0
1043
1035
  };
1044
- if (!((_a = match.groups) == null ? void 0 : _a.args)) {
1036
+ if (!match.groups?.args) {
1045
1037
  result.output = true;
1046
1038
  return result;
1047
1039
  }
@@ -1068,10 +1060,10 @@ __name(hideFieldDecorator, "hideFieldDecorator");
1068
1060
  function parseArgs(string) {
1069
1061
  try {
1070
1062
  return import_json52.default.parse(string);
1071
- } catch (e) {
1063
+ } catch {
1072
1064
  try {
1073
1065
  return import_json52.default.parse(`[${string}]`);
1074
- } catch (e2) {
1066
+ } catch {
1075
1067
  throw new Error(`Failed to parse: ${string}`);
1076
1068
  }
1077
1069
  }
@@ -1091,23 +1083,26 @@ __name(getNamespace, "getNamespace");
1091
1083
 
1092
1084
  // src/handlers/model-data.ts
1093
1085
  function modelData(model, args) {
1094
- const { config, modelNames, models, modelFields, fieldSettings } = args;
1086
+ const { config, modelNames, models, modelFields, fieldSettings, classTransformerTypeModels } = args;
1095
1087
  modelNames.push(model.name);
1096
1088
  models.set(model.name, model);
1097
1089
  const modelFieldsValue = /* @__PURE__ */ new Map();
1098
1090
  modelFields.set(model.name, modelFieldsValue);
1099
1091
  const fieldSettingsValue = /* @__PURE__ */ new Map();
1100
1092
  fieldSettings.set(model.name, fieldSettingsValue);
1101
- for (const field of model.fields) {
1102
- if (field.documentation) {
1093
+ for (const field1 of model.fields) {
1094
+ if (field1.documentation) {
1103
1095
  const { documentation, settings } = createObjectSettings({
1104
- text: field.documentation,
1096
+ text: field1.documentation,
1105
1097
  config
1106
1098
  });
1107
- field.documentation = documentation;
1108
- fieldSettingsValue.set(field.name, settings);
1099
+ field1.documentation = documentation;
1100
+ fieldSettingsValue.set(field1.name, settings);
1109
1101
  }
1110
- 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);
1111
1106
  }
1112
1107
  }
1113
1108
  __name(modelData, "modelData");
@@ -1121,7 +1116,6 @@ var import_ts_morph5 = require("ts-morph");
1121
1116
 
1122
1117
  // src/helpers/create-comment.ts
1123
1118
  function createComment(documentation, settings) {
1124
- var _a;
1125
1119
  const documentationLines = documentation.split("\n");
1126
1120
  const commentLines = [
1127
1121
  "/**"
@@ -1129,7 +1123,7 @@ function createComment(documentation, settings) {
1129
1123
  for (const line of documentationLines) {
1130
1124
  commentLines.push(` * ${line}`);
1131
1125
  }
1132
- const deprecationReason = (_a = settings == null ? void 0 : settings.fieldArguments()) == null ? void 0 : _a.deprecationReason;
1126
+ const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1133
1127
  if (deprecationReason) {
1134
1128
  commentLines.push(` * @deprecated ${deprecationReason}`);
1135
1129
  }
@@ -1147,7 +1141,6 @@ __name(getOutputTypeName, "getOutputTypeName");
1147
1141
  // src/handlers/model-output-type.ts
1148
1142
  var nestjsGraphql = "@nestjs/graphql";
1149
1143
  function modelOutputType(outputType2, args) {
1150
- var _a, _b, _c, _d, _e, _f;
1151
1144
  const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
1152
1145
  const model = models.get(outputType2.name);
1153
1146
  (0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
@@ -1200,17 +1193,17 @@ function modelOutputType(outputType2, args) {
1200
1193
  fileType = "output";
1201
1194
  outputTypeName = getOutputTypeName(outputTypeName);
1202
1195
  }
1203
- const modelField = (_a = modelFields.get(model.name)) == null ? void 0 : _a.get(field.name);
1204
- const settings = (_b = fieldSettings.get(model.name)) == null ? void 0 : _b.get(field.name);
1205
- 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({
1206
1199
  name: outputType2.name,
1207
1200
  output: true
1208
1201
  });
1209
- const propertySettings = settings == null ? void 0 : settings.getPropertyType({
1202
+ const propertySettings = settings?.getPropertyType({
1210
1203
  name: outputType2.name,
1211
1204
  output: true
1212
1205
  });
1213
- const propertyType = (0, import_lodash5.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1206
+ const propertyType = (0, import_lodash5.castArray)(propertySettings?.name || getPropertyType({
1214
1207
  location,
1215
1208
  type: outputTypeName
1216
1209
  }));
@@ -1230,7 +1223,7 @@ function modelOutputType(outputType2, args) {
1230
1223
  sourceFile,
1231
1224
  fileType,
1232
1225
  location,
1233
- isId: modelField == null ? void 0 : modelField.isId,
1226
+ isId: modelField?.isId,
1234
1227
  noTypeId: config.noTypeId,
1235
1228
  typeName: outputTypeName,
1236
1229
  getSourceFile
@@ -1248,10 +1241,10 @@ function modelOutputType(outputType2, args) {
1248
1241
  propertyType,
1249
1242
  isList
1250
1243
  });
1251
- if (typeof property.leadingTrivia === "string" && (modelField == null ? void 0 : modelField.documentation)) {
1244
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1252
1245
  property.leadingTrivia += createComment(modelField.documentation, settings);
1253
1246
  }
1254
- (_c = classStructure.properties) == null ? void 0 : _c.push(property);
1247
+ classStructure.properties?.push(property);
1255
1248
  if (propertySettings) {
1256
1249
  importDeclarations.create({
1257
1250
  ...propertySettings
@@ -1260,7 +1253,7 @@ function modelOutputType(outputType2, args) {
1260
1253
  importDeclarations.add("Decimal", "@prisma/client/runtime");
1261
1254
  }
1262
1255
  (0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
1263
- if (settings == null ? void 0 : settings.shouldHideField({
1256
+ if (settings?.shouldHideField({
1264
1257
  name: outputType2.name,
1265
1258
  output: true
1266
1259
  })) {
@@ -1275,19 +1268,19 @@ function modelOutputType(outputType2, args) {
1275
1268
  arguments: [
1276
1269
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1277
1270
  import_json53.default.stringify({
1278
- ...settings == null ? void 0 : settings.fieldArguments(),
1271
+ ...settings?.fieldArguments(),
1279
1272
  nullable: Boolean(field.isNullable),
1280
1273
  defaultValue: [
1281
1274
  "number",
1282
1275
  "string",
1283
1276
  "boolean"
1284
- ].includes(typeof (modelField == null ? void 0 : modelField.default)) ? modelField == null ? void 0 : modelField.default : void 0,
1285
- description: modelField == null ? void 0 : modelField.documentation
1277
+ ].includes(typeof modelField?.default) ? modelField?.default : void 0,
1278
+ description: modelField?.documentation
1286
1279
  })
1287
1280
  ]
1288
1281
  });
1289
1282
  for (const setting of settings || []) {
1290
- 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)) {
1291
1284
  property.decorators.push({
1292
1285
  name: setting.name,
1293
1286
  arguments: setting.arguments
@@ -1300,7 +1293,7 @@ function modelOutputType(outputType2, args) {
1300
1293
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
1301
1294
  property.decorators.push({
1302
1295
  name: decorate.name,
1303
- 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, {
1304
1297
  propertyType
1305
1298
  }))
1306
1299
  });
@@ -1381,10 +1374,9 @@ function beforeInputType2(args) {
1381
1374
  }
1382
1375
  __name(beforeInputType2, "beforeInputType");
1383
1376
  function beforeGenerateFiles(args) {
1384
- var _a;
1385
1377
  const { project } = args;
1386
1378
  for (const sourceFile of project.getSourceFiles()) {
1387
- const className = (_a = sourceFile.getClass(() => true)) == null ? void 0 : _a.getName();
1379
+ const className = sourceFile.getClass(() => true)?.getName();
1388
1380
  if (className && isAtomicOperation(className)) {
1389
1381
  project.removeSourceFile(sourceFile);
1390
1382
  }
@@ -1410,14 +1402,13 @@ var import_lodash6 = require("lodash");
1410
1402
  var import_ts_morph6 = require("ts-morph");
1411
1403
  var nestjsGraphql2 = "@nestjs/graphql";
1412
1404
  function outputType(outputType1, args) {
1413
- var _a, _b, _c, _d, _e;
1414
1405
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2, config } = args;
1415
1406
  const importDeclarations = new ImportDeclarationMap();
1416
1407
  const fileType = "output";
1417
1408
  const modelName = getModelName2(outputType1.name) || "";
1418
1409
  const model = models.get(modelName);
1419
1410
  const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType1.name) && String(outputType1.name).startsWith(model.name);
1420
- const isCountOutput = (model == null ? void 0 : model.name) && outputType1.name === `${model.name}CountOutputType`;
1411
+ const isCountOutput = model?.name && outputType1.name === `${model.name}CountOutputType`;
1421
1412
  outputType1.name = getOutputTypeName(outputType1.name);
1422
1413
  if (isAggregateOutput) {
1423
1414
  eventEmitter.emitSync("AggregateOutput", {
@@ -1446,14 +1437,14 @@ function outputType(outputType1, args) {
1446
1437
  for (const field of outputType1.fields) {
1447
1438
  const { location, isList, type } = field.outputType;
1448
1439
  const outputTypeName = getOutputTypeName(String(type));
1449
- const settings = isCountOutput ? void 0 : model && ((_a = fieldSettings.get(model.name)) == null ? void 0 : _a.get(field.name));
1450
- 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({
1451
1442
  name: outputType1.name,
1452
1443
  output: true
1453
1444
  });
1454
- 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;
1455
1446
  field.outputType.type = outputTypeName;
1456
- const propertyType = (0, import_lodash6.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1447
+ const propertyType = (0, import_lodash6.castArray)(propertySettings?.name || getPropertyType({
1457
1448
  location,
1458
1449
  type: outputTypeName
1459
1450
  }));
@@ -1464,7 +1455,7 @@ function outputType(outputType1, args) {
1464
1455
  propertyType,
1465
1456
  isList
1466
1457
  });
1467
- (_c = classStructure.properties) == null ? void 0 : _c.push(property);
1458
+ classStructure.properties?.push(property);
1468
1459
  if (propertySettings) {
1469
1460
  importDeclarations.create({
1470
1461
  ...propertySettings
@@ -1473,11 +1464,11 @@ function outputType(outputType1, args) {
1473
1464
  importDeclarations.add("Decimal", "@prisma/client/runtime");
1474
1465
  }
1475
1466
  let graphqlType;
1476
- const shouldHideField = (settings == null ? void 0 : settings.shouldHideField({
1467
+ const shouldHideField = settings?.shouldHideField({
1477
1468
  name: outputType1.name,
1478
1469
  output: true
1479
- })) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName));
1480
- 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({
1481
1472
  name: outputType1.name,
1482
1473
  output: true
1483
1474
  });
@@ -1525,14 +1516,14 @@ function outputType(outputType1, args) {
1525
1516
  arguments: [
1526
1517
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1527
1518
  import_json54.default.stringify({
1528
- ...settings == null ? void 0 : settings.fieldArguments(),
1519
+ ...settings?.fieldArguments(),
1529
1520
  nullable: Boolean(field.isNullable)
1530
1521
  })
1531
1522
  ]
1532
1523
  });
1533
1524
  if (isCustomsApplicable) {
1534
1525
  for (const options of settings || []) {
1535
- 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) {
1536
1527
  property.decorators.push({
1537
1528
  name: options.name,
1538
1529
  arguments: options.arguments
@@ -1566,8 +1557,7 @@ function purgeOutput(emitter) {
1566
1557
  }
1567
1558
  __name(purgeOutput, "purgeOutput");
1568
1559
  function begin({ project, output }) {
1569
- var _a;
1570
- const sourceFiles = (_a = project.getDirectory(output)) == null ? void 0 : _a.getDescendantSourceFiles();
1560
+ const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1571
1561
  if (sourceFiles) {
1572
1562
  for (const sourceFile of sourceFiles) {
1573
1563
  sourceFile.delete();
@@ -1576,12 +1566,11 @@ function begin({ project, output }) {
1576
1566
  }
1577
1567
  __name(begin, "begin");
1578
1568
  async function end({ project, output }) {
1579
- var _a;
1580
- 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());
1581
1570
  for (const directory1 of directories || []) {
1582
1571
  try {
1583
1572
  await import_fs.promises.rmdir(directory1);
1584
- } catch (e) {
1573
+ } catch {
1585
1574
  }
1586
1575
  }
1587
1576
  }
@@ -1704,7 +1693,7 @@ function registerEnum(enumType, args) {
1704
1693
  ...importDeclarations.toStatements(),
1705
1694
  enumStructure,
1706
1695
  "\n",
1707
- `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)} })`
1708
1697
  ]
1709
1698
  });
1710
1699
  }
@@ -1751,7 +1740,6 @@ var import_json55 = __toESM(require("json5"));
1751
1740
  var import_lodash7 = require("lodash");
1752
1741
  var import_outmatch3 = __toESM(require("outmatch"));
1753
1742
  function createConfig(data) {
1754
- var _a;
1755
1743
  const config = (0, import_lodash7.merge)({}, (0, import_flat.unflatten)(data, {
1756
1744
  delimiter: "_"
1757
1745
  }));
@@ -1770,7 +1758,7 @@ function createConfig(data) {
1770
1758
  config.reExport = "All";
1771
1759
  }
1772
1760
  }
1773
- 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]) => {
1774
1762
  const fieldSetting = {
1775
1763
  arguments: [],
1776
1764
  output: toBoolean(value.output),
@@ -2084,9 +2072,8 @@ var middleKeywords = [
2084
2072
 
2085
2073
  // src/generate.ts
2086
2074
  async function generate(args) {
2087
- var _a;
2088
2075
  const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
2089
- const generatorOutputValue = (_a = generator.output) == null ? void 0 : _a.value;
2076
+ const generatorOutputValue = generator.output?.value;
2090
2077
  (0, import_assert6.ok)(generatorOutputValue, "Missing generator configuration: output");
2091
2078
  const eventEmitter = new import_await_event_emitter.default();
2092
2079
  eventEmitter.on("Warning", warning);
@@ -2149,7 +2136,8 @@ async function generate(args) {
2149
2136
  typeNames: /* @__PURE__ */ new Set(),
2150
2137
  enums: (0, import_lodash10.mapKeys)(datamodel.enums, (x) => x.name),
2151
2138
  getModelName: getModelName2,
2152
- removeTypes
2139
+ removeTypes,
2140
+ classTransformerTypeModels: /* @__PURE__ */ new Set()
2153
2141
  };
2154
2142
  if (connectCallback) {
2155
2143
  await connectCallback(eventEmitter, eventArguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "16.0.0",
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",