prisma-nestjs-graphql 17.1.0 → 18.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 (2) hide show
  1. package/index.js +74 -63
  2. package/package.json +33 -33
package/index.js CHANGED
@@ -15,6 +15,10 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
18
22
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
19
23
  mod
20
24
  ));
@@ -57,6 +61,7 @@ function argsType(field, args) {
57
61
  }
58
62
  }
59
63
  const inputType2 = {
64
+ // eslint-disable-next-line unicorn/no-null
60
65
  constraints: {
61
66
  maxNumFields: null,
62
67
  minNumFields: null
@@ -220,6 +225,7 @@ function createAggregateInput(args) {
220
225
  const { eventEmitter, outputType: outputType2 } = args;
221
226
  const className = `${outputType2.name}Input`;
222
227
  const inputType2 = {
228
+ // eslint-disable-next-line unicorn/no-null
223
229
  constraints: {
224
230
  maxNumFields: null,
225
231
  minNumFields: null
@@ -599,13 +605,18 @@ function getGraphqlInputType(inputTypes, pattern) {
599
605
  return result;
600
606
  }
601
607
  }
602
- if ((countTypes.scalar === 1 || countTypes.enumTypes === 1) && countTypes.fieldRefTypes === 1) {
608
+ if ((countTypes.scalar >= 1 || countTypes.enumTypes >= 1) && countTypes.fieldRefTypes === 1) {
609
+ result = inputTypes.find((x) => (x.location === "scalar" || x.location === "enumTypes") && x.isList);
610
+ if (result) {
611
+ return result;
612
+ }
603
613
  result = inputTypes.find((x) => x.location === "scalar" || x.location === "enumTypes");
604
614
  if (result) {
605
615
  return result;
606
616
  }
607
617
  }
608
618
  throw new TypeError(
619
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
609
620
  `Cannot get matching input type from ${inputTypes.map((x) => x.type).join(", ") || "zero length inputTypes"}`
610
621
  );
611
622
  }
@@ -780,7 +791,7 @@ function inputType(args) {
780
791
  ...propertySettings
781
792
  });
782
793
  } else if (propertyType.includes("Decimal")) {
783
- importDeclarations.add("Decimal", "@prisma/client/runtime");
794
+ importDeclarations.add("Decimal", "@prisma/client/runtime/library");
784
795
  }
785
796
  let graphqlType;
786
797
  const shouldHideField = settings?.shouldHideField({
@@ -1046,24 +1057,24 @@ function createSettingElement({ line, config, fieldElement, match }) {
1046
1057
  "FieldType",
1047
1058
  "PropertyType"
1048
1059
  ].includes(name) && match.groups?.args) {
1049
- const options = customType(match.groups.args);
1050
- (0, import_lodash5.merge)(element, options.namespace && config.fields[options.namespace], options, {
1060
+ const options2 = customType(match.groups.args);
1061
+ (0, import_lodash5.merge)(element, options2.namespace && config.fields[options2.namespace], options2, {
1051
1062
  kind: name
1052
1063
  });
1053
1064
  return result;
1054
1065
  }
1055
1066
  if (name === "ObjectType" && match.groups?.args) {
1056
1067
  element.kind = "ObjectType";
1057
- const options1 = customType(match.groups.args);
1058
- if (typeof options1[0] === "string" && options1[0]) {
1059
- options1.name = options1[0];
1068
+ const options2 = customType(match.groups.args);
1069
+ if (typeof options2[0] === "string" && options2[0]) {
1070
+ options2.name = options2[0];
1060
1071
  }
1061
- if ((0, import_lodash5.isObject)(options1[1])) {
1062
- (0, import_lodash5.merge)(options1, options1[1]);
1072
+ if ((0, import_lodash5.isObject)(options2[1])) {
1073
+ (0, import_lodash5.merge)(options2, options2[1]);
1063
1074
  }
1064
1075
  element.arguments = {
1065
- name: options1.name,
1066
- isAbstract: options1.isAbstract
1076
+ name: options2.name,
1077
+ isAbstract: options2.isAbstract
1067
1078
  };
1068
1079
  return result;
1069
1080
  }
@@ -1082,11 +1093,11 @@ function createSettingElement({ line, config, fieldElement, match }) {
1082
1093
  }
1083
1094
  const namespace = getNamespace(name);
1084
1095
  element.namespaceImport = namespace;
1085
- const options3 = {
1096
+ const options = {
1086
1097
  name,
1087
1098
  arguments: (match.groups?.args || "").split(",").map((s) => (0, import_lodash5.trim)(s)).filter(Boolean)
1088
1099
  };
1089
- (0, import_lodash5.merge)(element, namespace && config.fields[namespace], options3);
1100
+ (0, import_lodash5.merge)(element, namespace && config.fields[namespace], options);
1090
1101
  return result;
1091
1102
  }
1092
1103
  __name(createSettingElement, "createSettingElement");
@@ -1282,12 +1293,12 @@ function modelOutputType(outputType2, args) {
1282
1293
  outputTypeName = getOutputTypeName(outputTypeName);
1283
1294
  }
1284
1295
  const modelField = modelFields.get(model.name)?.get(field.name);
1285
- const settings1 = fieldSettings.get(model.name)?.get(field.name);
1286
- const fieldType = settings1?.getFieldType({
1296
+ const settings = fieldSettings.get(model.name)?.get(field.name);
1297
+ const fieldType = settings?.getFieldType({
1287
1298
  name: outputType2.name,
1288
1299
  output: true
1289
1300
  });
1290
- const propertySettings = settings1?.getPropertyType({
1301
+ const propertySettings = settings?.getPropertyType({
1291
1302
  name: outputType2.name,
1292
1303
  output: true
1293
1304
  });
@@ -1330,7 +1341,7 @@ function modelOutputType(outputType2, args) {
1330
1341
  isList
1331
1342
  });
1332
1343
  if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1333
- property.leadingTrivia += createComment(modelField.documentation, settings1);
1344
+ property.leadingTrivia += createComment(modelField.documentation, settings);
1334
1345
  }
1335
1346
  classStructure.properties?.push(property);
1336
1347
  if (propertySettings) {
@@ -1338,10 +1349,10 @@ function modelOutputType(outputType2, args) {
1338
1349
  ...propertySettings
1339
1350
  });
1340
1351
  } else if (propertyType.includes("Decimal")) {
1341
- importDeclarations.add("Decimal", "@prisma/client/runtime");
1352
+ importDeclarations.add("Decimal", "@prisma/client/runtime/library");
1342
1353
  }
1343
1354
  (0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
1344
- const shouldHideField = settings1?.shouldHideField({
1355
+ const shouldHideField = settings?.shouldHideField({
1345
1356
  name: outputType2.name,
1346
1357
  output: true
1347
1358
  }) || config.decorate.some((d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName));
@@ -1357,7 +1368,7 @@ function modelOutputType(outputType2, args) {
1357
1368
  arguments: [
1358
1369
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1359
1370
  import_json53.default.stringify({
1360
- ...settings1?.fieldArguments(),
1371
+ ...settings?.fieldArguments(),
1361
1372
  nullable: Boolean(field.isNullable),
1362
1373
  defaultValue: [
1363
1374
  "number",
@@ -1368,7 +1379,7 @@ function modelOutputType(outputType2, args) {
1368
1379
  })
1369
1380
  ]
1370
1381
  });
1371
- for (const setting of settings1 || []) {
1382
+ for (const setting of settings || []) {
1372
1383
  if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
1373
1384
  property.decorators.push({
1374
1385
  name: setting.name,
@@ -1396,13 +1407,13 @@ function modelOutputType(outputType2, args) {
1396
1407
  propertyType
1397
1408
  });
1398
1409
  }
1399
- for (const setting1 of modelSettings || []) {
1400
- if (shouldBeDecorated(setting1)) {
1410
+ for (const setting of modelSettings || []) {
1411
+ if (shouldBeDecorated(setting)) {
1401
1412
  classStructure.decorators.push({
1402
- name: setting1.name,
1403
- arguments: setting1.arguments
1413
+ name: setting.name,
1414
+ arguments: setting.arguments
1404
1415
  });
1405
- importDeclarations.create(setting1);
1416
+ importDeclarations.create(setting);
1406
1417
  }
1407
1418
  }
1408
1419
  if (exportDeclaration) {
@@ -1550,7 +1561,7 @@ function outputType(outputType2, args) {
1550
1561
  ...propertySettings
1551
1562
  });
1552
1563
  } else if (propertyType.includes("Decimal")) {
1553
- importDeclarations.add("Decimal", "@prisma/client/runtime");
1564
+ importDeclarations.add("Decimal", "@prisma/client/runtime/library");
1554
1565
  }
1555
1566
  let graphqlType;
1556
1567
  const shouldHideField = settings?.shouldHideField({
@@ -1709,23 +1720,23 @@ function beforeGenerateFiles2(args) {
1709
1720
  }
1710
1721
  }
1711
1722
  if (config.reExport === ReExport.Single) {
1712
- const exportDeclarations1 = project.getSourceFiles().filter((sourceFile) => {
1723
+ const exportDeclarations = project.getSourceFiles().filter((sourceFile) => {
1713
1724
  return sourceFile.getBaseName() !== "index.ts";
1714
1725
  }).map((sourceFile) => getExportDeclaration2(rootDirectory, sourceFile));
1715
1726
  rootDirectory.createSourceFile("index.ts", {
1716
- statements: exportDeclarations1
1727
+ statements: exportDeclarations
1717
1728
  }, {
1718
1729
  overwrite: true
1719
1730
  });
1720
1731
  }
1721
1732
  if (config.reExport === ReExport.All) {
1722
- const exportDeclarations2 = [];
1723
- for (const directory1 of rootDirectory.getDirectories()) {
1724
- const sourceFile = directory1.getSourceFileOrThrow("index.ts");
1725
- exportDeclarations2.push(getExportDeclaration2(rootDirectory, sourceFile));
1733
+ const exportDeclarations = [];
1734
+ for (const directory of rootDirectory.getDirectories()) {
1735
+ const sourceFile = directory.getSourceFileOrThrow("index.ts");
1736
+ exportDeclarations.push(getExportDeclaration2(rootDirectory, sourceFile));
1726
1737
  }
1727
1738
  rootDirectory.createSourceFile("index.ts", {
1728
- statements: exportDeclarations2
1739
+ statements: exportDeclarations
1729
1740
  }, {
1730
1741
  overwrite: true
1731
1742
  });
@@ -1956,18 +1967,18 @@ function generateFileName(args) {
1956
1967
  return (0, import_lodash9.kebabCase)(result);
1957
1968
  },
1958
1969
  get name() {
1959
- let result1 = (0, import_lodash9.kebabCase)(name);
1970
+ let result = (0, import_lodash9.kebabCase)(name);
1960
1971
  for (const suffix of [
1961
1972
  "input",
1962
1973
  "args",
1963
1974
  "enum"
1964
1975
  ]) {
1965
1976
  const ending = `-${suffix}`;
1966
- if (type === suffix && result1.endsWith(ending)) {
1967
- result1 = result1.slice(0, -ending.length);
1977
+ if (type === suffix && result.endsWith(ending)) {
1978
+ result = result.slice(0, -ending.length);
1968
1979
  }
1969
1980
  }
1970
- return result1;
1981
+ return result;
1971
1982
  },
1972
1983
  plural: {
1973
1984
  get type() {
@@ -2018,31 +2029,31 @@ function getModelName(args) {
2018
2029
  return test;
2019
2030
  }
2020
2031
  }
2021
- for (const keyword1 of endsWithKeywords) {
2022
- const [test1] = name.split(keyword1).slice(-1);
2023
- if (modelNames.includes(test1)) {
2024
- return test1;
2032
+ for (const keyword of endsWithKeywords) {
2033
+ const [test] = name.split(keyword).slice(-1);
2034
+ if (modelNames.includes(test)) {
2035
+ return test;
2025
2036
  }
2026
2037
  }
2027
2038
  for (const [start, end2] of middleKeywords) {
2028
- let test2 = name.slice(start.length).slice(0, -end2.length);
2029
- if (modelNames.includes(test2)) {
2030
- return test2;
2039
+ let test = name.slice(start.length).slice(0, -end2.length);
2040
+ if (modelNames.includes(test)) {
2041
+ return test;
2031
2042
  }
2032
- test2 = name.slice(0, -(start + end2).length);
2033
- if (modelNames.includes(test2)) {
2034
- return test2;
2043
+ test = name.slice(0, -(start + end2).length);
2044
+ if (modelNames.includes(test)) {
2045
+ return test;
2035
2046
  }
2036
2047
  }
2037
2048
  if (name.slice(-19) === "CompoundUniqueInput") {
2038
- const test3 = name.slice(0, -19);
2039
- const models = modelNames.filter((x) => test3.startsWith(x)).sort((a, b) => b.length - a.length);
2049
+ const test = name.slice(0, -19);
2050
+ const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
2040
2051
  return (0, import_lodash10.first)(models);
2041
2052
  }
2042
2053
  if (name.slice(-5) === "Count") {
2043
- const test4 = name.slice(0, -5);
2044
- if (modelNames.includes(test4)) {
2045
- return test4;
2054
+ const test = name.slice(0, -5);
2055
+ if (modelNames.includes(test)) {
2056
+ return test;
2046
2057
  }
2047
2058
  }
2048
2059
  return void 0;
@@ -2244,16 +2255,16 @@ async function generate(args) {
2244
2255
  for (const model of datamodel.models) {
2245
2256
  await eventEmitter.emit("Model", model, eventArguments);
2246
2257
  }
2247
- for (const model1 of datamodel.types || []) {
2248
- await eventEmitter.emit("Model", model1, eventArguments);
2258
+ for (const model of datamodel.types || []) {
2259
+ await eventEmitter.emit("Model", model, eventArguments);
2249
2260
  }
2250
2261
  const { inputObjectTypes, outputObjectTypes, enumTypes } = schema;
2251
2262
  await eventEmitter.emit("PostBegin", eventArguments);
2252
2263
  for (const enumType of enumTypes.prisma.concat(enumTypes.model || [])) {
2253
2264
  await eventEmitter.emit("EnumType", enumType, eventArguments);
2254
2265
  }
2255
- for (const outputType1 of outputObjectTypes.model) {
2256
- await eventEmitter.emit("ModelOutputType", outputType1, eventArguments);
2266
+ for (const outputType2 of outputObjectTypes.model) {
2267
+ await eventEmitter.emit("ModelOutputType", outputType2, eventArguments);
2257
2268
  }
2258
2269
  const queryOutputTypes = [];
2259
2270
  for (const outputType2 of outputObjectTypes.prisma) {
@@ -2267,22 +2278,22 @@ async function generate(args) {
2267
2278
  await eventEmitter.emit("OutputType", outputType2, eventArguments);
2268
2279
  }
2269
2280
  const inputTypes = inputObjectTypes.prisma.concat(inputObjectTypes.model || []);
2270
- for (const inputType1 of inputTypes) {
2281
+ for (const inputType2 of inputTypes) {
2271
2282
  const event = {
2272
2283
  ...eventArguments,
2273
- inputType: inputType1,
2284
+ inputType: inputType2,
2274
2285
  fileType: "input",
2275
2286
  classDecoratorName: "InputType"
2276
2287
  };
2277
- if (inputType1.fields.length === 0) {
2278
- removeTypes.add(inputType1.name);
2288
+ if (inputType2.fields.length === 0) {
2289
+ removeTypes.add(inputType2.name);
2279
2290
  continue;
2280
2291
  }
2281
2292
  await eventEmitter.emit("BeforeInputType", event);
2282
2293
  await eventEmitter.emit("InputType", event);
2283
2294
  }
2284
- for (const outputType3 of queryOutputTypes) {
2285
- for (const field of outputType3.fields) {
2295
+ for (const outputType2 of queryOutputTypes) {
2296
+ for (const field of outputType2.fields) {
2286
2297
  await eventEmitter.emit("ArgsType", field, eventArguments);
2287
2298
  }
2288
2299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "17.1.0",
3
+ "version": "18.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",
@@ -52,12 +52,12 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@prisma/generator-helper": "^4.7.1",
55
+ "@prisma/generator-helper": "^4.12.0",
56
56
  "await-event-emitter": "^2.0.2",
57
57
  "filenamify": "4.X",
58
58
  "flat": "^5.0.2",
59
59
  "get-relative-path": "^1.0.2",
60
- "json5": "^2.2.1",
60
+ "json5": "^2.2.3",
61
61
  "lodash": "^4.17.21",
62
62
  "outmatch": "^0.7.0",
63
63
  "pluralize": "^8.0.0",
@@ -65,66 +65,66 @@
65
65
  "ts-morph": ">=11 <=16"
66
66
  },
67
67
  "devDependencies": {
68
- "@commitlint/cli": "^17.3.0",
69
- "@commitlint/config-conventional": "^17.3.0",
68
+ "@commitlint/cli": "^17.5.1",
69
+ "@commitlint/config-conventional": "^17.4.4",
70
70
  "@nestjs/apollo": "^10.1.7",
71
- "@nestjs/common": "^9.2.1",
72
- "@nestjs/core": "^9.2.1",
71
+ "@nestjs/common": "^9.3.12",
72
+ "@nestjs/core": "^9.3.12",
73
73
  "@nestjs/graphql": "^10.1.7",
74
- "@nestjs/platform-express": "^9.2.1",
75
- "@paljs/plugins": "^5.1.0",
76
- "@prisma/client": "^4.7.1",
77
- "@semantic-release/changelog": "^6.0.2",
74
+ "@nestjs/platform-express": "^9.3.12",
75
+ "@paljs/plugins": "^5.3.0",
76
+ "@prisma/client": "^4.12.0",
77
+ "@semantic-release/changelog": "^6.0.3",
78
78
  "@semantic-release/git": "^10.0.1",
79
- "@swc/core": "^1.3.23",
79
+ "@swc/core": "^1.3.44",
80
80
  "@swc/helpers": "^0.4.14",
81
81
  "@swc/register": "^0.1.10",
82
82
  "@types/flat": "^5.0.2",
83
- "@types/lodash": "^4.14.191",
83
+ "@types/lodash": "^4.14.192",
84
84
  "@types/mocha": "^10.0.1",
85
- "@types/node": "^18.11.15",
85
+ "@types/node": "^18.15.11",
86
86
  "@types/pluralize": "^0.0.29",
87
- "@typescript-eslint/eslint-plugin": "^5.46.1",
88
- "@typescript-eslint/parser": "^5.46.1",
87
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
88
+ "@typescript-eslint/parser": "^5.57.0",
89
89
  "apollo-server-express": "^3.10.0",
90
- "c8": "^7.12.0",
90
+ "c8": "^7.13.0",
91
91
  "class-transformer": "^0.5.1",
92
92
  "class-validator": "^0.14.0",
93
- "commitizen": "^4.2.6",
93
+ "commitizen": "^4.3.0",
94
94
  "cz-customizable": "^7.0.0",
95
95
  "decimal.js": "^10.4.3",
96
- "eslint": "^8.29.0",
97
- "eslint-import-resolver-node": "^0.3.6",
96
+ "eslint": "^8.37.0",
97
+ "eslint-import-resolver-node": "^0.3.7",
98
98
  "eslint-plugin-etc": "^2.0.2",
99
- "eslint-plugin-import": "^2.26.0",
99
+ "eslint-plugin-import": "^2.27.5",
100
100
  "eslint-plugin-only-warn": "^1.1.0",
101
101
  "eslint-plugin-prettier": "^4.2.1",
102
- "eslint-plugin-regexp": "^1.11.0",
103
- "eslint-plugin-simple-import-sort": "^8.0.0",
102
+ "eslint-plugin-regexp": "^1.14.0",
103
+ "eslint-plugin-simple-import-sort": "^10.0.0",
104
104
  "eslint-plugin-sort-class-members": "^1.16.0",
105
- "eslint-plugin-unicorn": "^45.0.2",
105
+ "eslint-plugin-unicorn": "^46.0.0",
106
106
  "eslint-plugin-wix-editor": "^3.3.0",
107
- "expect": "^29.3.1",
107
+ "expect": "^29.5.0",
108
108
  "ghooks": "^2.0.4",
109
109
  "git-branch-is": "^4.0.0",
110
110
  "graphql": "^16.6.0",
111
- "graphql-scalars": "^1.20.1",
111
+ "graphql-scalars": "^1.21.3",
112
112
  "graphql-type-json": "^0.3.2",
113
113
  "mocha": "^10.2.0",
114
114
  "ololog": "^1.1.175",
115
115
  "precise-commits": "^1.0.2",
116
- "prettier": "^2.8.1",
117
- "prisma": "^4.7.1",
118
- "prisma-graphql-type-decimal": "^2.0.4",
116
+ "prettier": "^2.8.7",
117
+ "prisma": "^4.12.0",
118
+ "prisma-graphql-type-decimal": "^3.0.0",
119
119
  "reflect-metadata": "^0.1.13",
120
120
  "request": "^2.88.2",
121
- "rxjs": "^7.6.0",
122
- "semantic-release": "^19.0.5",
121
+ "rxjs": "^7.8.0",
122
+ "semantic-release": "^21.0.1",
123
123
  "simplytyped": "^3.3.0",
124
124
  "temp-dir": "2.X",
125
125
  "ts-node": "^10.9.1",
126
- "tslib": "^2.4.1",
127
- "typescript": "^4.9.4",
126
+ "tslib": "^2.5.0",
127
+ "typescript": "^5.0.3",
128
128
  "watchexec-bin": "^1.0.0"
129
129
  }
130
130
  }