prisma-nestjs-graphql 16.0.1 → 17.0.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.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/index.js +133 -132
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -10,10 +10,18 @@ Generate object types, inputs, args, etc. from prisma schema file for usage with
10
10
 
11
11
  ## Install
12
12
 
13
+ Prisma v3
14
+
13
15
  ```sh
14
16
  npm install --save-dev prisma-nestjs-graphql
15
17
  ```
16
18
 
19
+ Prisma v4
20
+
21
+ ```
22
+ npm install --save-dev prisma-nestjs-graphql@next
23
+ ```
24
+
17
25
  ## Usage
18
26
 
19
27
  1. Add new generator section to `schema.prisma` file
@@ -703,6 +711,7 @@ export class User {}
703
711
 
704
712
  ## Similar Projects
705
713
 
714
+ - https://github.com/jasonraimondi/prisma-generator-nestjs-graphql
706
715
  - https://github.com/omar-dulaimi/prisma-class-validator-generator
707
716
  - https://github.com/kimjbstar/prisma-class-generator
708
717
  - https://github.com/odroe/nest-gql-mix
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -50,7 +51,7 @@ function argsType(field, args) {
50
51
  className = `${modelName}GroupByArgs`;
51
52
  break;
52
53
  }
53
- const inputType1 = {
54
+ const inputType2 = {
54
55
  constraints: {
55
56
  maxNumFields: null,
56
57
  minNumFields: null
@@ -71,17 +72,17 @@ function argsType(field, args) {
71
72
  "Min",
72
73
  "Max"
73
74
  ];
74
- if (`${modelName}GroupByArgs` === inputType1.name) {
75
- const byField = inputType1.fields.find((f) => f.name === "by");
75
+ if (`${modelName}GroupByArgs` === inputType2.name) {
76
+ const byField = inputType2.fields.find((f) => f.name === "by");
76
77
  if (byField?.inputTypes) {
77
- byField.inputTypes = byField.inputTypes.filter((inputType2) => inputType2.isList);
78
+ byField.inputTypes = byField.inputTypes.filter((inputType3) => inputType3.isList);
78
79
  }
79
80
  }
80
81
  for (const name of names) {
81
82
  if (!typeNames.has(`${modelName}${name}AggregateInput`)) {
82
83
  continue;
83
84
  }
84
- inputType1.fields.push({
85
+ inputType2.fields.push({
85
86
  name: `_${name.toLowerCase()}`,
86
87
  isRequired: false,
87
88
  isNullable: true,
@@ -97,7 +98,7 @@ function argsType(field, args) {
97
98
  }
98
99
  eventEmitter.emitSync("InputType", {
99
100
  ...args,
100
- inputType: inputType1,
101
+ inputType: inputType2,
101
102
  fileType: "args",
102
103
  classDecoratorName: "ArgsType"
103
104
  });
@@ -280,14 +281,14 @@ async function generateFiles(args) {
280
281
  const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", void 0, {
281
282
  overwrite: true
282
283
  });
283
- const statements1 = project.getSourceFiles().flatMap((s) => {
284
+ const statements = project.getSourceFiles().flatMap((s) => {
284
285
  if (s === sourceFile) {
285
286
  return [];
286
287
  }
287
288
  const classDeclaration = s.getClass(() => true);
288
- const statements = s.getStructure().statements;
289
- if (Array.isArray(statements)) {
290
- for (const statement of statements) {
289
+ const statements2 = s.getStructure().statements;
290
+ if (Array.isArray(statements2)) {
291
+ for (const statement of statements2) {
291
292
  if (!(typeof statement === "object" && statement.kind === import_ts_morph2.StructureKind.Class)) {
292
293
  continue;
293
294
  }
@@ -301,47 +302,47 @@ async function generateFiles(args) {
301
302
  }
302
303
  }
303
304
  project.removeSourceFile(s);
304
- return statements;
305
+ return statements2;
305
306
  });
306
307
  const imports = new ImportDeclarationMap();
307
308
  const enums = [];
308
309
  const classes = [];
309
- for (const statement1 of statements1) {
310
- if (typeof statement1 === "string") {
311
- if (statement1.startsWith("registerEnumType")) {
312
- enums.push(statement1);
310
+ for (const statement of statements) {
311
+ if (typeof statement === "string") {
312
+ if (statement.startsWith("registerEnumType")) {
313
+ enums.push(statement);
313
314
  }
314
315
  continue;
315
316
  }
316
- switch (statement1.kind) {
317
+ switch (statement.kind) {
317
318
  case import_ts_morph2.StructureKind.ImportDeclaration:
318
- if (statement1.moduleSpecifier.startsWith("./") || statement1.moduleSpecifier.startsWith("..")) {
319
+ if (statement.moduleSpecifier.startsWith("./") || statement.moduleSpecifier.startsWith("..")) {
319
320
  continue;
320
321
  }
321
- for (const namedImport of statement1.namedImports) {
322
+ for (const namedImport of statement.namedImports) {
322
323
  const name = namedImport.alias || namedImport.name;
323
- imports.add(name, statement1.moduleSpecifier);
324
+ imports.add(name, statement.moduleSpecifier);
324
325
  }
325
- if (statement1.defaultImport) {
326
+ if (statement.defaultImport) {
326
327
  imports.create({
327
- from: statement1.moduleSpecifier,
328
- name: statement1.defaultImport,
329
- defaultImport: statement1.defaultImport
328
+ from: statement.moduleSpecifier,
329
+ name: statement.defaultImport,
330
+ defaultImport: statement.defaultImport
330
331
  });
331
332
  }
332
- if (statement1.namespaceImport) {
333
+ if (statement.namespaceImport) {
333
334
  imports.create({
334
- from: statement1.moduleSpecifier,
335
- name: statement1.namespaceImport,
336
- namespaceImport: statement1.namespaceImport
335
+ from: statement.moduleSpecifier,
336
+ name: statement.namespaceImport,
337
+ namespaceImport: statement.namespaceImport
337
338
  });
338
339
  }
339
340
  break;
340
341
  case import_ts_morph2.StructureKind.Enum:
341
- enums.unshift(statement1);
342
+ enums.unshift(statement);
342
343
  break;
343
344
  case import_ts_morph2.StructureKind.Class:
344
- classes.push(statement1);
345
+ classes.push(statement);
345
346
  break;
346
347
  }
347
348
  }
@@ -604,11 +605,11 @@ __name(getPropertyType, "getPropertyType");
604
605
  var import_ts_morph3 = require("ts-morph");
605
606
  function propertyStructure(args) {
606
607
  const { isNullable, propertyType, name, isList, hasQuestionToken, hasExclamationToken } = args;
607
- const type1 = propertyType.map((type) => isList ? `Array<${type}>` : type).join(" | ");
608
+ const type = propertyType.map((type2) => isList ? `Array<${type2}>` : type2).join(" | ");
608
609
  return {
609
610
  kind: import_ts_morph3.StructureKind.Property,
610
611
  name,
611
- type: type1,
612
+ type,
612
613
  hasQuestionToken: hasQuestionToken ?? isNullable,
613
614
  hasExclamationToken: hasExclamationToken ?? !isNullable,
614
615
  decorators: [],
@@ -619,17 +620,17 @@ __name(propertyStructure, "propertyStructure");
619
620
 
620
621
  // src/handlers/input-type.ts
621
622
  function inputType(args) {
622
- const { classDecoratorName, classTransformerTypeModels, config, eventEmitter, fieldSettings, fileType, getModelName: getModelName2, getSourceFile, inputType: inputType1, models, removeTypes, typeNames } = args;
623
- typeNames.add(inputType1.name);
623
+ const { classDecoratorName, classTransformerTypeModels, config, eventEmitter, fieldSettings, fileType, getModelName: getModelName2, getSourceFile, inputType: inputType2, models, removeTypes, typeNames } = args;
624
+ typeNames.add(inputType2.name);
624
625
  const importDeclarations = new ImportDeclarationMap();
625
626
  const sourceFile = getSourceFile({
626
- name: inputType1.name,
627
+ name: inputType2.name,
627
628
  type: fileType
628
629
  });
629
630
  const classStructure = {
630
631
  kind: import_ts_morph4.StructureKind.Class,
631
632
  isExported: true,
632
- name: inputType1.name,
633
+ name: inputType2.name,
633
634
  decorators: [
634
635
  {
635
636
  name: classDecoratorName,
@@ -638,7 +639,7 @@ function inputType(args) {
638
639
  ],
639
640
  properties: []
640
641
  };
641
- const modelName = getModelName2(inputType1.name) || "";
642
+ const modelName = getModelName2(inputType2.name) || "";
642
643
  const model = models.get(modelName);
643
644
  const modelFieldSettings = model && fieldSettings.get(model.name);
644
645
  const moduleSpecifier = "@nestjs/graphql";
@@ -657,8 +658,8 @@ function inputType(args) {
657
658
  ],
658
659
  moduleSpecifier
659
660
  });
660
- const useInputType = config.useInputType.find((x) => inputType1.name.includes(x.typeName));
661
- for (const field of inputType1.fields) {
661
+ const useInputType = config.useInputType.find((x) => inputType2.name.includes(x.typeName));
662
+ for (const field of inputType2.fields) {
662
663
  field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(String(t.type)));
663
664
  eventEmitter.emitSync("BeforeGenerateField", field, args);
664
665
  const { inputTypes, isRequired, name } = field;
@@ -671,7 +672,7 @@ function inputType(args) {
671
672
  const typeName = String(type);
672
673
  const settings = modelFieldSettings?.get(name);
673
674
  const propertySettings = settings?.getPropertyType({
674
- name: inputType1.name,
675
+ name: inputType2.name,
675
676
  input: true
676
677
  });
677
678
  const modelField = model?.fields.find((f) => f.name === name);
@@ -696,11 +697,11 @@ function inputType(args) {
696
697
  }
697
698
  let graphqlType;
698
699
  const shouldHideField = settings?.shouldHideField({
699
- name: inputType1.name,
700
+ name: inputType2.name,
700
701
  input: true
701
- }) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType1.name));
702
+ }) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType2.name));
702
703
  const fieldType = settings?.getFieldType({
703
- name: inputType1.name,
704
+ name: inputType2.name,
704
705
  input: true
705
706
  });
706
707
  if (fieldType && isCustomsApplicable && !shouldHideField) {
@@ -721,7 +722,7 @@ function inputType(args) {
721
722
  if (location === "enumTypes") {
722
723
  referenceName = (0, import_lodash3.last)(referenceName.split(" "));
723
724
  }
724
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputType1.name) {
725
+ if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputType2.name) {
725
726
  importDeclarations.set(graphqlImport.name, {
726
727
  namedImports: [
727
728
  {
@@ -801,7 +802,7 @@ function inputType(args) {
801
802
  }
802
803
  }
803
804
  for (const decorate of config.decorate) {
804
- if (decorate.isMatchField(name) && decorate.isMatchType(inputType1.name)) {
805
+ if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
805
806
  property.decorators.push({
806
807
  name: decorate.name,
807
808
  arguments: decorate.arguments?.map((x) => (0, import_pupa.default)(x, {
@@ -884,9 +885,9 @@ var ObjectSettings = class extends Array {
884
885
  return resultArguments.map((x) => import_json52.default.stringify(x));
885
886
  }
886
887
  fieldArguments() {
887
- const item1 = this.find((item) => item.kind === "Field");
888
- if (item1) {
889
- return item1.arguments;
888
+ const item = this.find((item2) => item2.kind === "Field");
889
+ if (item) {
890
+ return item.arguments;
890
891
  }
891
892
  }
892
893
  };
@@ -958,24 +959,24 @@ function createSettingElement({ line, config, fieldElement, match }) {
958
959
  "FieldType",
959
960
  "PropertyType"
960
961
  ].includes(name) && match.groups?.args) {
961
- const options2 = customType(match.groups.args);
962
- (0, import_lodash4.merge)(element, options2.namespace && config.fields[options2.namespace], options2, {
962
+ const options = customType(match.groups.args);
963
+ (0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, {
963
964
  kind: name
964
965
  });
965
966
  return result;
966
967
  }
967
968
  if (name === "ObjectType" && match.groups?.args) {
968
969
  element.kind = "ObjectType";
969
- const options2 = customType(match.groups.args);
970
- if (typeof options2[0] === "string" && options2[0]) {
971
- options2.name = options2[0];
970
+ const options1 = customType(match.groups.args);
971
+ if (typeof options1[0] === "string" && options1[0]) {
972
+ options1.name = options1[0];
972
973
  }
973
- if ((0, import_lodash4.isObject)(options2[1])) {
974
- (0, import_lodash4.merge)(options2, options2[1]);
974
+ if ((0, import_lodash4.isObject)(options1[1])) {
975
+ (0, import_lodash4.merge)(options1, options1[1]);
975
976
  }
976
977
  element.arguments = {
977
- name: options2.name,
978
- isAbstract: options2.isAbstract
978
+ name: options1.name,
979
+ isAbstract: options1.isAbstract
979
980
  };
980
981
  return result;
981
982
  }
@@ -994,11 +995,11 @@ function createSettingElement({ line, config, fieldElement, match }) {
994
995
  }
995
996
  const namespace = getNamespace(name);
996
997
  element.namespaceImport = namespace;
997
- const options = {
998
+ const options3 = {
998
999
  name,
999
1000
  arguments: (match.groups?.args || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
1000
1001
  };
1001
- (0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
1002
+ (0, import_lodash4.merge)(element, namespace && config.fields[namespace], options3);
1002
1003
  return result;
1003
1004
  }
1004
1005
  __name(createSettingElement, "createSettingElement");
@@ -1090,16 +1091,16 @@ function modelData(model, args) {
1090
1091
  modelFields.set(model.name, modelFieldsValue);
1091
1092
  const fieldSettingsValue = /* @__PURE__ */ new Map();
1092
1093
  fieldSettings.set(model.name, fieldSettingsValue);
1093
- for (const field1 of model.fields) {
1094
- if (field1.documentation) {
1094
+ for (const field of model.fields) {
1095
+ if (field.documentation) {
1095
1096
  const { documentation, settings } = createObjectSettings({
1096
- text: field1.documentation,
1097
+ text: field.documentation,
1097
1098
  config
1098
1099
  });
1099
- field1.documentation = documentation;
1100
- fieldSettingsValue.set(field1.name, settings);
1100
+ field.documentation = documentation;
1101
+ fieldSettingsValue.set(field.name, settings);
1101
1102
  }
1102
- modelFieldsValue.set(field1.name, field1);
1103
+ modelFieldsValue.set(field.name, field);
1103
1104
  }
1104
1105
  if (model.fields.some((field) => field.type === "Decimal")) {
1105
1106
  classTransformerTypeModels.add(model.name);
@@ -1194,12 +1195,12 @@ function modelOutputType(outputType2, args) {
1194
1195
  outputTypeName = getOutputTypeName(outputTypeName);
1195
1196
  }
1196
1197
  const modelField = modelFields.get(model.name)?.get(field.name);
1197
- const settings = fieldSettings.get(model.name)?.get(field.name);
1198
- const fieldType = settings?.getFieldType({
1198
+ const settings1 = fieldSettings.get(model.name)?.get(field.name);
1199
+ const fieldType = settings1?.getFieldType({
1199
1200
  name: outputType2.name,
1200
1201
  output: true
1201
1202
  });
1202
- const propertySettings = settings?.getPropertyType({
1203
+ const propertySettings = settings1?.getPropertyType({
1203
1204
  name: outputType2.name,
1204
1205
  output: true
1205
1206
  });
@@ -1242,7 +1243,7 @@ function modelOutputType(outputType2, args) {
1242
1243
  isList
1243
1244
  });
1244
1245
  if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1245
- property.leadingTrivia += createComment(modelField.documentation, settings);
1246
+ property.leadingTrivia += createComment(modelField.documentation, settings1);
1246
1247
  }
1247
1248
  classStructure.properties?.push(property);
1248
1249
  if (propertySettings) {
@@ -1253,7 +1254,7 @@ function modelOutputType(outputType2, args) {
1253
1254
  importDeclarations.add("Decimal", "@prisma/client/runtime");
1254
1255
  }
1255
1256
  (0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
1256
- if (settings?.shouldHideField({
1257
+ if (settings1?.shouldHideField({
1257
1258
  name: outputType2.name,
1258
1259
  output: true
1259
1260
  })) {
@@ -1268,7 +1269,7 @@ function modelOutputType(outputType2, args) {
1268
1269
  arguments: [
1269
1270
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1270
1271
  import_json53.default.stringify({
1271
- ...settings?.fieldArguments(),
1272
+ ...settings1?.fieldArguments(),
1272
1273
  nullable: Boolean(field.isNullable),
1273
1274
  defaultValue: [
1274
1275
  "number",
@@ -1279,7 +1280,7 @@ function modelOutputType(outputType2, args) {
1279
1280
  })
1280
1281
  ]
1281
1282
  });
1282
- for (const setting of settings || []) {
1283
+ for (const setting of settings1 || []) {
1283
1284
  if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
1284
1285
  property.decorators.push({
1285
1286
  name: setting.name,
@@ -1307,13 +1308,13 @@ function modelOutputType(outputType2, args) {
1307
1308
  propertyType
1308
1309
  });
1309
1310
  }
1310
- for (const setting of modelSettings || []) {
1311
- if (shouldBeDecorated(setting)) {
1311
+ for (const setting1 of modelSettings || []) {
1312
+ if (shouldBeDecorated(setting1)) {
1312
1313
  classStructure.decorators.push({
1313
- name: setting.name,
1314
- arguments: setting.arguments
1314
+ name: setting1.name,
1315
+ arguments: setting1.arguments
1315
1316
  });
1316
- importDeclarations.create(setting);
1317
+ importDeclarations.create(setting1);
1317
1318
  }
1318
1319
  }
1319
1320
  if (exportDeclaration) {
@@ -1359,11 +1360,11 @@ function noAtomicOperations(eventEmitter) {
1359
1360
  }
1360
1361
  __name(noAtomicOperations, "noAtomicOperations");
1361
1362
  function beforeInputType2(args) {
1362
- const { inputType: inputType1, getModelName: getModelName2 } = args;
1363
- for (const field of inputType1.fields) {
1363
+ const { inputType: inputType2, getModelName: getModelName2 } = args;
1364
+ for (const field of inputType2.fields) {
1364
1365
  const fieldName = field.name;
1365
- field.inputTypes = field.inputTypes.filter((inputType2) => {
1366
- const inputTypeName = String(inputType2.type);
1366
+ field.inputTypes = field.inputTypes.filter((inputType3) => {
1367
+ const inputTypeName = String(inputType3.type);
1367
1368
  const modelName = getModelName2(inputTypeName);
1368
1369
  if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName, fieldName)) {
1369
1370
  return false;
@@ -1401,29 +1402,29 @@ var import_json54 = __toESM(require("json5"));
1401
1402
  var import_lodash6 = require("lodash");
1402
1403
  var import_ts_morph6 = require("ts-morph");
1403
1404
  var nestjsGraphql2 = "@nestjs/graphql";
1404
- function outputType(outputType1, args) {
1405
+ function outputType(outputType2, args) {
1405
1406
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2, config } = args;
1406
1407
  const importDeclarations = new ImportDeclarationMap();
1407
1408
  const fileType = "output";
1408
- const modelName = getModelName2(outputType1.name) || "";
1409
+ const modelName = getModelName2(outputType2.name) || "";
1409
1410
  const model = models.get(modelName);
1410
- const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType1.name) && String(outputType1.name).startsWith(model.name);
1411
- const isCountOutput = model?.name && outputType1.name === `${model.name}CountOutputType`;
1412
- outputType1.name = getOutputTypeName(outputType1.name);
1411
+ const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
1412
+ const isCountOutput = model?.name && outputType2.name === `${model.name}CountOutputType`;
1413
+ outputType2.name = getOutputTypeName(outputType2.name);
1413
1414
  if (isAggregateOutput) {
1414
1415
  eventEmitter.emitSync("AggregateOutput", {
1415
1416
  ...args,
1416
- outputType: outputType1
1417
+ outputType: outputType2
1417
1418
  });
1418
1419
  }
1419
1420
  const sourceFile = getSourceFile({
1420
- name: outputType1.name,
1421
+ name: outputType2.name,
1421
1422
  type: fileType
1422
1423
  });
1423
1424
  const classStructure = {
1424
1425
  kind: import_ts_morph6.StructureKind.Class,
1425
1426
  isExported: true,
1426
- name: outputType1.name,
1427
+ name: outputType2.name,
1427
1428
  decorators: [
1428
1429
  {
1429
1430
  name: "ObjectType",
@@ -1434,12 +1435,12 @@ function outputType(outputType1, args) {
1434
1435
  };
1435
1436
  importDeclarations.add("Field", nestjsGraphql2);
1436
1437
  importDeclarations.add("ObjectType", nestjsGraphql2);
1437
- for (const field of outputType1.fields) {
1438
+ for (const field of outputType2.fields) {
1438
1439
  const { location, isList, type } = field.outputType;
1439
1440
  const outputTypeName = getOutputTypeName(String(type));
1440
1441
  const settings = isCountOutput ? void 0 : model && fieldSettings.get(model.name)?.get(field.name);
1441
1442
  const propertySettings = settings?.getPropertyType({
1442
- name: outputType1.name,
1443
+ name: outputType2.name,
1443
1444
  output: true
1444
1445
  });
1445
1446
  const isCustomsApplicable = outputTypeName === model?.fields.find((f) => f.name === field.name)?.type;
@@ -1465,11 +1466,11 @@ function outputType(outputType1, args) {
1465
1466
  }
1466
1467
  let graphqlType;
1467
1468
  const shouldHideField = settings?.shouldHideField({
1468
- name: outputType1.name,
1469
+ name: outputType2.name,
1469
1470
  output: true
1470
1471
  }) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName));
1471
1472
  const fieldType = settings?.getFieldType({
1472
- name: outputType1.name,
1473
+ name: outputType2.name,
1473
1474
  output: true
1474
1475
  });
1475
1476
  if (fieldType && isCustomsApplicable && !shouldHideField) {
@@ -1492,7 +1493,7 @@ function outputType(outputType1, args) {
1492
1493
  if (location === "enumTypes") {
1493
1494
  referenceName = (0, import_lodash6.last)(referenceName.split(" "));
1494
1495
  }
1495
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType1.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1496
+ if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1496
1497
  importDeclarations.set(graphqlImport.name, {
1497
1498
  namedImports: [
1498
1499
  {
@@ -1567,9 +1568,9 @@ function begin({ project, output }) {
1567
1568
  __name(begin, "begin");
1568
1569
  async function end({ project, output }) {
1569
1570
  const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1570
- for (const directory1 of directories || []) {
1571
+ for (const directory of directories || []) {
1571
1572
  try {
1572
- await import_fs.promises.rmdir(directory1);
1573
+ await import_fs.promises.rmdir(directory);
1573
1574
  } catch {
1574
1575
  }
1575
1576
  }
@@ -1620,23 +1621,23 @@ function beforeGenerateFiles2(args) {
1620
1621
  }
1621
1622
  }
1622
1623
  if (config.reExport === ReExport.Single) {
1623
- const exportDeclarations = project.getSourceFiles().filter((sourceFile) => {
1624
+ const exportDeclarations1 = project.getSourceFiles().filter((sourceFile) => {
1624
1625
  return sourceFile.getBaseName() !== "index.ts";
1625
1626
  }).map((sourceFile) => getExportDeclaration2(rootDirectory, sourceFile));
1626
1627
  rootDirectory.createSourceFile("index.ts", {
1627
- statements: exportDeclarations
1628
+ statements: exportDeclarations1
1628
1629
  }, {
1629
1630
  overwrite: true
1630
1631
  });
1631
1632
  }
1632
1633
  if (config.reExport === ReExport.All) {
1633
- const exportDeclarations = [];
1634
- for (const directory of rootDirectory.getDirectories()) {
1635
- const sourceFile = directory.getSourceFileOrThrow("index.ts");
1636
- exportDeclarations.push(getExportDeclaration2(rootDirectory, sourceFile));
1634
+ const exportDeclarations2 = [];
1635
+ for (const directory1 of rootDirectory.getDirectories()) {
1636
+ const sourceFile = directory1.getSourceFileOrThrow("index.ts");
1637
+ exportDeclarations2.push(getExportDeclaration2(rootDirectory, sourceFile));
1637
1638
  }
1638
1639
  rootDirectory.createSourceFile("index.ts", {
1639
- statements: exportDeclarations
1640
+ statements: exportDeclarations2
1640
1641
  }, {
1641
1642
  overwrite: true
1642
1643
  });
@@ -1867,18 +1868,18 @@ function generateFileName(args) {
1867
1868
  return (0, import_lodash8.kebabCase)(result);
1868
1869
  },
1869
1870
  get name() {
1870
- let result = (0, import_lodash8.kebabCase)(name);
1871
+ let result1 = (0, import_lodash8.kebabCase)(name);
1871
1872
  for (const suffix of [
1872
1873
  "input",
1873
1874
  "args",
1874
1875
  "enum"
1875
1876
  ]) {
1876
1877
  const ending = `-${suffix}`;
1877
- if (type === suffix && result.endsWith(ending)) {
1878
- result = result.slice(0, -ending.length);
1878
+ if (type === suffix && result1.endsWith(ending)) {
1879
+ result1 = result1.slice(0, -ending.length);
1879
1880
  }
1880
1881
  }
1881
- return result;
1882
+ return result1;
1882
1883
  },
1883
1884
  plural: {
1884
1885
  get type() {
@@ -1890,10 +1891,10 @@ function generateFileName(args) {
1890
1891
  __name(generateFileName, "generateFileName");
1891
1892
 
1892
1893
  // src/helpers/factory-get-source-file.ts
1893
- function factoryGetSourceFile(args1) {
1894
- const { outputFilePattern, output, getModelName: getModelName2, project } = args1;
1895
- return /* @__PURE__ */ __name(function getSourceFile(args) {
1896
- const { name, type } = args;
1894
+ function factoryGetSourceFile(args) {
1895
+ const { outputFilePattern, output, getModelName: getModelName2, project } = args;
1896
+ return /* @__PURE__ */ __name(function getSourceFile(args2) {
1897
+ const { name, type } = args2;
1897
1898
  let filePath = generateFileName({
1898
1899
  getModelName: getModelName2,
1899
1900
  name,
@@ -1930,30 +1931,30 @@ function getModelName(args) {
1930
1931
  }
1931
1932
  }
1932
1933
  for (const keyword1 of endsWithKeywords) {
1933
- const [test] = name.split(keyword1).slice(-1);
1934
- if (modelNames.includes(test)) {
1935
- return test;
1934
+ const [test1] = name.split(keyword1).slice(-1);
1935
+ if (modelNames.includes(test1)) {
1936
+ return test1;
1936
1937
  }
1937
1938
  }
1938
1939
  for (const [start, end2] of middleKeywords) {
1939
- let test = name.slice(start.length).slice(0, -end2.length);
1940
- if (modelNames.includes(test)) {
1941
- return test;
1940
+ let test2 = name.slice(start.length).slice(0, -end2.length);
1941
+ if (modelNames.includes(test2)) {
1942
+ return test2;
1942
1943
  }
1943
- test = name.slice(0, -(start + end2).length);
1944
- if (modelNames.includes(test)) {
1945
- return test;
1944
+ test2 = name.slice(0, -(start + end2).length);
1945
+ if (modelNames.includes(test2)) {
1946
+ return test2;
1946
1947
  }
1947
1948
  }
1948
1949
  if (name.slice(-19) === "CompoundUniqueInput") {
1949
- const test = name.slice(0, -19);
1950
- const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
1950
+ const test3 = name.slice(0, -19);
1951
+ const models = modelNames.filter((x) => test3.startsWith(x)).sort((a, b) => b.length - a.length);
1951
1952
  return (0, import_lodash9.first)(models);
1952
1953
  }
1953
1954
  if (name.slice(-5) === "Count") {
1954
- const test = name.slice(0, -5);
1955
- if (modelNames.includes(test)) {
1956
- return test;
1955
+ const test4 = name.slice(0, -5);
1956
+ if (modelNames.includes(test4)) {
1957
+ return test4;
1957
1958
  }
1958
1959
  }
1959
1960
  return void 0;
@@ -2153,19 +2154,19 @@ async function generate(args) {
2153
2154
  for (const enumType of enumTypes.prisma.concat(enumTypes.model || [])) {
2154
2155
  await eventEmitter.emit("EnumType", enumType, eventArguments);
2155
2156
  }
2156
- for (const outputType3 of outputObjectTypes.model) {
2157
- await eventEmitter.emit("ModelOutputType", outputType3, eventArguments);
2157
+ for (const outputType1 of outputObjectTypes.model) {
2158
+ await eventEmitter.emit("ModelOutputType", outputType1, eventArguments);
2158
2159
  }
2159
2160
  const queryOutputTypes = [];
2160
- for (const outputType1 of outputObjectTypes.prisma) {
2161
+ for (const outputType2 of outputObjectTypes.prisma) {
2161
2162
  if ([
2162
2163
  "Query",
2163
2164
  "Mutation"
2164
- ].includes(outputType1.name)) {
2165
- queryOutputTypes.push(outputType1);
2165
+ ].includes(outputType2.name)) {
2166
+ queryOutputTypes.push(outputType2);
2166
2167
  continue;
2167
2168
  }
2168
- await eventEmitter.emit("OutputType", outputType1, eventArguments);
2169
+ await eventEmitter.emit("OutputType", outputType2, eventArguments);
2169
2170
  }
2170
2171
  const inputTypes = inputObjectTypes.prisma.concat(inputObjectTypes.model || []);
2171
2172
  for (const inputType1 of inputTypes) {
@@ -2182,8 +2183,8 @@ async function generate(args) {
2182
2183
  await eventEmitter.emit("BeforeInputType", event);
2183
2184
  await eventEmitter.emit("InputType", event);
2184
2185
  }
2185
- for (const outputType2 of queryOutputTypes) {
2186
- for (const field of outputType2.fields) {
2186
+ for (const outputType3 of queryOutputTypes) {
2187
+ for (const field of outputType3.fields) {
2187
2188
  await eventEmitter.emit("ArgsType", field, eventArguments);
2188
2189
  }
2189
2190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "16.0.1",
3
+ "version": "17.0.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
  "main": "index.js",
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@prisma/generator-helper": "^3.14.0",
55
+ "@prisma/generator-helper": "^4.0.0",
56
56
  "await-event-emitter": "^2.0.2",
57
57
  "filenamify": "4.X",
58
58
  "flat": "^5.0.2",
@@ -73,7 +73,7 @@
73
73
  "@nestjs/graphql": "^10.0.12",
74
74
  "@nestjs/platform-express": "^8.4.5",
75
75
  "@paljs/plugins": "^4.1.0",
76
- "@prisma/client": "^3.14.0",
76
+ "@prisma/client": "^4.0.0",
77
77
  "@semantic-release/changelog": "^6.0.1",
78
78
  "@semantic-release/git": "^10.0.1",
79
79
  "@swc/core": "^1.2.189",
@@ -114,7 +114,7 @@
114
114
  "ololog": "^1.1.175",
115
115
  "precise-commits": "^1.0.2",
116
116
  "prettier": "^2.6.2",
117
- "prisma": "^3.14.0",
117
+ "prisma": "^4.0.0",
118
118
  "prisma-graphql-type-decimal": "^2.0.2",
119
119
  "reflect-metadata": "^0.1.13",
120
120
  "request": "^2.88.2",