prisma-nestjs-graphql 14.1.0 → 14.3.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 +43 -0
  2. package/index.js +284 -186
  3. package/package.json +18 -20
package/README.md CHANGED
@@ -126,6 +126,13 @@ Disable usage of graphql `ID` type and use `Int/Float` for fields marked as `@id
126
126
  Type: `boolean`
127
127
  Default: `false`
128
128
 
129
+ #### `requireSingleFieldsInWhereUniqueInput`
130
+
131
+ When a `Model`s `WhereUniqueInput` class has only a single field, mark that field as **required** (TypeScript) and **not nullable** (GraphQL).
132
+ See [#58](https://github.com/unlight/prisma-nestjs-graphql/issues/58) for more details.
133
+ Type: `boolean`
134
+ Default: `false`
135
+
129
136
  #### `useInputType`
130
137
 
131
138
  Since GraphQL does not support input union type, this setting map
@@ -520,8 +527,44 @@ export class User {
520
527
  }
521
528
  ```
522
529
 
530
+ #### @ObjectType()
531
+
532
+ Allow rename type in schema and mark as abstract.
533
+
534
+ Example 1:
535
+
536
+ ```
537
+ // schema.prisma
538
+ /// @ObjectType({ isAbstract: true })
539
+ model User {
540
+ id Int @id
541
+ }
542
+ ```
543
+
544
+ ```ts
545
+ @ObjectType({ isAbstract: true })
546
+ export class User {}
547
+ ```
548
+
549
+ Example 2:
550
+
551
+ ```
552
+ // schema.prisma
553
+ /// @ObjectType('Human', { isAbstract: true })
554
+ model User {
555
+ id Int @id
556
+ }
557
+ ```
558
+
559
+ ```ts
560
+ @ObjectType('Human', { isAbstract: true })
561
+ export class User {}
562
+ ```
563
+
523
564
  ## Similar Projects
524
565
 
566
+ - https://github.com/rfermann/nestjs-prisma-graphql-generator
567
+ - https://github.com/madscience/graphql-codegen-nestjs
525
568
  - https://github.com/wSedlacek/prisma-generators/tree/master/libs/nestjs
526
569
  - https://github.com/EndyKaufman/typegraphql-prisma-nestjs
527
570
  - https://github.com/MichalLytek/typegraphql-prisma
package/index.js CHANGED
@@ -1,7 +1,11 @@
1
- "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
2
3
  var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
5
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
10
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -17,23 +21,35 @@ var __spreadValues = (a, b) => {
17
21
  return a;
18
22
  };
19
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __require = typeof require !== "undefined" ? require : (x) => {
21
- throw new Error('Dynamic require of "' + x + '" is not supported');
24
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
+ var __reExport = (target, module2, desc) => {
26
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
27
+ for (let key of __getOwnPropNames(module2))
28
+ if (!__hasOwnProp.call(target, key) && key !== "default")
29
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
30
+ }
31
+ return target;
22
32
  };
33
+ var __toModule = (module2) => {
34
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
35
+ };
36
+
37
+ // ../../../../.npm/_npx/7d72304e626f8399/node_modules/tsup/assets/cjs_shims.js
38
+ var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
23
39
 
24
40
  // src/index.ts
25
- var _generatorhelper = require('@prisma/generator-helper');
41
+ var import_generator_helper = __toModule(require("@prisma/generator-helper"));
26
42
 
27
43
  // src/generate.ts
28
- var _assert = require('assert');
29
- var _awaiteventemitter = require('await-event-emitter'); var _awaiteventemitter2 = _interopRequireDefault(_awaiteventemitter);
30
- var _lodash = require('lodash');
31
- var _tsmorph = require('ts-morph');
44
+ var import_assert6 = __toModule(require("assert"));
45
+ var import_await_event_emitter = __toModule(require("await-event-emitter"));
46
+ var import_lodash10 = __toModule(require("lodash"));
47
+ var import_ts_morph9 = __toModule(require("ts-morph"));
32
48
 
33
49
  // src/helpers/pascal-case.ts
34
-
50
+ var import_lodash = __toModule(require("lodash"));
35
51
  function pascalCase(string) {
36
- return _lodash.startCase.call(void 0, _lodash.camelCase.call(void 0, string)).replace(/ /g, "");
52
+ return (0, import_lodash.startCase)((0, import_lodash.camelCase)(string)).replace(/ /g, "");
37
53
  }
38
54
 
39
55
  // src/handlers/args-type.ts
@@ -167,22 +183,22 @@ function emitSingle(emitter) {
167
183
  emitter.on("ClassProperty", classProperty);
168
184
  }
169
185
  function classProperty(property, eventArguments) {
170
- const { location, isList } = eventArguments;
186
+ const { location, isList, propertyType } = eventArguments;
171
187
  if (["inputObjectTypes", "outputObjectTypes"].includes(location) && !isList) {
172
- property.type = `InstanceType<typeof ${String(property.type)}>`;
188
+ const types = propertyType.filter((t) => t !== "null");
189
+ property.type = types.map((t) => `InstanceType<typeof ${t}>`).join(" | ");
190
+ if (types.length !== propertyType.length) {
191
+ property.type += " | null";
192
+ }
173
193
  }
174
194
  }
175
195
 
176
196
  // src/handlers/generate-files.ts
177
-
178
-
179
-
180
-
197
+ var import_assert = __toModule(require("assert"));
198
+ var import_ts_morph2 = __toModule(require("ts-morph"));
181
199
 
182
200
  // src/helpers/import-declaration-map.ts
183
-
184
-
185
-
201
+ var import_ts_morph = __toModule(require("ts-morph"));
186
202
  var ImportDeclarationMap = class extends Map {
187
203
  add(name, value) {
188
204
  if (!this.has(name)) {
@@ -218,7 +234,7 @@ var ImportDeclarationMap = class extends Map {
218
234
  let result = iterator.next();
219
235
  while (result.value) {
220
236
  yield __spreadProps(__spreadValues({}, result.value), {
221
- kind: _tsmorph.StructureKind.ImportDeclaration
237
+ kind: import_ts_morph.StructureKind.ImportDeclaration
222
238
  });
223
239
  result = iterator.next();
224
240
  }
@@ -240,13 +256,13 @@ function beforeGenerateFiles(args) {
240
256
  const statements2 = s.getStructure().statements;
241
257
  if (Array.isArray(statements2)) {
242
258
  for (const statement of statements2) {
243
- if (!(typeof statement === "object" && statement.kind === _tsmorph.StructureKind.Class)) {
259
+ if (!(typeof statement === "object" && statement.kind === import_ts_morph2.StructureKind.Class)) {
244
260
  continue;
245
261
  }
246
262
  for (const property of statement.properties || []) {
247
263
  for (const decorator of property.decorators || []) {
248
264
  const fullName = (_b = (_a = classDeclaration == null ? void 0 : classDeclaration.getProperty(property.name)) == null ? void 0 : _a.getDecorator(decorator.name)) == null ? void 0 : _b.getFullName();
249
- _assert.ok.call(void 0, fullName, `Cannot get full name of decorator of class ${statement.name}`);
265
+ (0, import_assert.ok)(fullName, `Cannot get full name of decorator of class ${statement.name}`);
250
266
  decorator.name = fullName;
251
267
  }
252
268
  }
@@ -266,7 +282,7 @@ function beforeGenerateFiles(args) {
266
282
  continue;
267
283
  }
268
284
  switch (statement.kind) {
269
- case _tsmorph.StructureKind.ImportDeclaration:
285
+ case import_ts_morph2.StructureKind.ImportDeclaration:
270
286
  if (statement.moduleSpecifier.startsWith("./") || statement.moduleSpecifier.startsWith("..")) {
271
287
  continue;
272
288
  }
@@ -289,16 +305,16 @@ function beforeGenerateFiles(args) {
289
305
  });
290
306
  }
291
307
  break;
292
- case _tsmorph.StructureKind.Enum:
308
+ case import_ts_morph2.StructureKind.Enum:
293
309
  enums.unshift(statement);
294
310
  break;
295
- case _tsmorph.StructureKind.Class:
311
+ case import_ts_morph2.StructureKind.Class:
296
312
  classes.push(statement);
297
313
  break;
298
314
  }
299
315
  }
300
316
  sourceFile.set({
301
- kind: _tsmorph.StructureKind.SourceFile,
317
+ kind: import_ts_morph2.StructureKind.SourceFile,
302
318
  statements: [...imports.toStatements(), ...enums, ...classes]
303
319
  });
304
320
  }
@@ -325,11 +341,11 @@ async function generateFiles(args) {
325
341
  }
326
342
 
327
343
  // src/handlers/input-type.ts
328
-
329
- var _json5 = require('json5'); var _json52 = _interopRequireDefault(_json5);
330
-
331
- var _pupa = require('pupa'); var _pupa2 = _interopRequireDefault(_pupa);
332
-
344
+ var import_assert2 = __toModule(require("assert"));
345
+ var import_json5 = __toModule(require("json5"));
346
+ var import_lodash3 = __toModule(require("lodash"));
347
+ var import_pupa = __toModule(require("pupa"));
348
+ var import_ts_morph4 = __toModule(require("ts-morph"));
333
349
 
334
350
  // src/helpers/file-type-by-location.ts
335
351
  function fileTypeByLocation(fieldLocation) {
@@ -345,7 +361,7 @@ function fileTypeByLocation(fieldLocation) {
345
361
  }
346
362
 
347
363
  // src/helpers/relative-path.ts
348
- var _getrelativepath = require('get-relative-path'); var _getrelativepath2 = _interopRequireDefault(_getrelativepath);
364
+ var import_get_relative_path = __toModule(require("get-relative-path"));
349
365
  function relativePath(from, to) {
350
366
  if (!from.startsWith("/")) {
351
367
  from = `/${from}`;
@@ -353,7 +369,7 @@ function relativePath(from, to) {
353
369
  if (!to.startsWith("/")) {
354
370
  to = `/${to}`;
355
371
  }
356
- let result = _getrelativepath2.default.call(void 0, from, to);
372
+ let result = (0, import_get_relative_path.default)(from, to);
357
373
  if (!result.startsWith(".")) {
358
374
  result = `./${result}`;
359
375
  }
@@ -401,15 +417,15 @@ function getGraphqlImport(args) {
401
417
  }
402
418
 
403
419
  // src/helpers/get-graphql-input-type.ts
404
-
405
- var _outmatch = require('outmatch'); var _outmatch2 = _interopRequireDefault(_outmatch);
420
+ var import_lodash2 = __toModule(require("lodash"));
421
+ var import_outmatch = __toModule(require("outmatch"));
406
422
  function getGraphqlInputType(inputTypes, pattern) {
407
423
  let result;
408
424
  inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(String(t.type)));
409
425
  if (inputTypes.length === 1) {
410
426
  return inputTypes[0];
411
427
  }
412
- const countTypes = _lodash.countBy.call(void 0, inputTypes, (x) => x.location);
428
+ const countTypes = (0, import_lodash2.countBy)(inputTypes, (x) => x.location);
413
429
  const isOneType = Object.keys(countTypes).length === 1;
414
430
  if (isOneType) {
415
431
  result = inputTypes.find((x) => x.isList);
@@ -420,7 +436,7 @@ function getGraphqlInputType(inputTypes, pattern) {
420
436
  if (pattern) {
421
437
  if (pattern.startsWith("matcher:") || pattern.startsWith("match:")) {
422
438
  const { 1: patternValue } = pattern.split(":", 2);
423
- const isMatch = _outmatch2.default.call(void 0, patternValue, { separator: false });
439
+ const isMatch = (0, import_outmatch.default)(patternValue, { separator: false });
424
440
  result = inputTypes.find((x) => isMatch(String(x.type)));
425
441
  if (result) {
426
442
  return result;
@@ -480,7 +496,7 @@ function getPropertyType(args) {
480
496
  }
481
497
 
482
498
  // src/helpers/property-structure.ts
483
-
499
+ var import_ts_morph3 = __toModule(require("ts-morph"));
484
500
  function propertyStructure(args) {
485
501
  const {
486
502
  isNullable,
@@ -492,7 +508,7 @@ function propertyStructure(args) {
492
508
  } = args;
493
509
  const type = propertyType.map((type2) => isList ? `Array<${type2}>` : type2).join(" | ");
494
510
  return {
495
- kind: _tsmorph.StructureKind.Property,
511
+ kind: import_ts_morph3.StructureKind.Property,
496
512
  name,
497
513
  type,
498
514
  hasQuestionToken: hasQuestionToken != null ? hasQuestionToken : isNullable,
@@ -525,7 +541,7 @@ function inputType(args) {
525
541
  type: fileType
526
542
  });
527
543
  const classStructure = {
528
- kind: _tsmorph.StructureKind.Class,
544
+ kind: import_ts_morph4.StructureKind.Class,
529
545
  isExported: true,
530
546
  name: inputType2.name,
531
547
  decorators: [
@@ -559,7 +575,7 @@ function inputType(args) {
559
575
  const settings = modelFieldSettings == null ? void 0 : modelFieldSettings.get(name);
560
576
  const propertySettings = settings == null ? void 0 : settings.getPropertyType();
561
577
  const isCustomsApplicable = typeName === ((_a = model == null ? void 0 : model.fields.find((f) => f.name === name)) == null ? void 0 : _a.type);
562
- const propertyType = _lodash.castArray.call(void 0, (propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
578
+ const propertyType = (0, import_lodash3.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
563
579
  location,
564
580
  type: typeName
565
581
  }));
@@ -573,36 +589,36 @@ function inputType(args) {
573
589
  if (propertySettings) {
574
590
  importDeclarations.create(__spreadValues({}, propertySettings));
575
591
  }
576
- let graphqlType;
577
- const fieldType = settings == null ? void 0 : settings.getFieldType();
578
- if (fieldType && fieldType.input && isCustomsApplicable) {
579
- graphqlType = fieldType.name;
580
- importDeclarations.create(__spreadValues({}, fieldType));
581
- } else {
582
- const graphqlImport = getGraphqlImport({
583
- sourceFile,
584
- location,
585
- typeName,
586
- getSourceFile
587
- });
588
- graphqlType = graphqlImport.name;
589
- if (graphqlImport.name !== inputType2.name && graphqlImport.specifier && !importDeclarations.has(graphqlImport.name)) {
590
- importDeclarations.set(graphqlImport.name, {
591
- namedImports: [{ name: graphqlImport.name }],
592
- moduleSpecifier: graphqlImport.specifier
593
- });
594
- }
595
- }
596
592
  if (settings == null ? void 0 : settings.shouldHideField({ name: inputType2.name, input: true })) {
597
593
  importDeclarations.add("HideField", "@nestjs/graphql");
598
594
  (_c = property.decorators) == null ? void 0 : _c.push({ name: "HideField", arguments: [] });
599
595
  } else {
600
- _assert.ok.call(void 0, property.decorators);
596
+ (0, import_assert2.ok)(property.decorators);
597
+ let graphqlType;
598
+ const fieldType = settings == null ? void 0 : settings.getFieldType();
599
+ if (fieldType && fieldType.input && isCustomsApplicable) {
600
+ graphqlType = fieldType.name;
601
+ importDeclarations.create(__spreadValues({}, fieldType));
602
+ } else {
603
+ const graphqlImport = getGraphqlImport({
604
+ sourceFile,
605
+ location,
606
+ typeName,
607
+ getSourceFile
608
+ });
609
+ graphqlType = graphqlImport.name;
610
+ if (graphqlImport.name !== inputType2.name && graphqlImport.specifier && !importDeclarations.has(graphqlImport.name)) {
611
+ importDeclarations.set(graphqlImport.name, {
612
+ namedImports: [{ name: graphqlImport.name }],
613
+ moduleSpecifier: graphqlImport.specifier
614
+ });
615
+ }
616
+ }
601
617
  property.decorators.push({
602
618
  name: "Field",
603
619
  arguments: [
604
- `() => ${isList ? `[${graphqlType}]` : graphqlType}`,
605
- _json52.default.stringify({
620
+ isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
621
+ import_json5.default.stringify({
606
622
  nullable: !isRequired
607
623
  })
608
624
  ]
@@ -616,7 +632,7 @@ function inputType(args) {
616
632
  name: options.name,
617
633
  arguments: options.arguments
618
634
  });
619
- _assert.ok.call(void 0, options.from, "Missed 'from' part in configuration or field setting");
635
+ (0, import_assert2.ok)(options.from, "Missed 'from' part in configuration or field setting");
620
636
  importDeclarations.create(options);
621
637
  }
622
638
  }
@@ -624,24 +640,28 @@ function inputType(args) {
624
640
  if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
625
641
  property.decorators.push({
626
642
  name: decorate.name,
627
- arguments: (_d = decorate.arguments) == null ? void 0 : _d.map((x) => _pupa2.default.call(void 0, x, { propertyType }))
643
+ arguments: (_d = decorate.arguments) == null ? void 0 : _d.map((x) => (0, import_pupa.default)(x, { propertyType }))
628
644
  });
629
645
  importDeclarations.create(decorate);
630
646
  }
631
647
  }
632
648
  }
633
- eventEmitter.emitSync("ClassProperty", property, { location, isList });
649
+ eventEmitter.emitSync("ClassProperty", property, {
650
+ location,
651
+ isList,
652
+ propertyType
653
+ });
634
654
  }
635
655
  sourceFile.set({
636
656
  statements: [...importDeclarations.toStatements(), classStructure]
637
657
  });
638
658
  }
639
659
 
640
- // src/helpers/field-settings.ts
641
-
642
-
643
-
644
- var FieldSettings = class extends Array {
660
+ // src/helpers/object-settings.ts
661
+ var import_json52 = __toModule(require("json5"));
662
+ var import_lodash4 = __toModule(require("lodash"));
663
+ var import_outmatch2 = __toModule(require("outmatch"));
664
+ var ObjectSettings = class extends Array {
645
665
  shouldHideField({
646
666
  name,
647
667
  input = false,
@@ -657,11 +677,24 @@ var FieldSettings = class extends Array {
657
677
  getPropertyType() {
658
678
  return this.find((s) => s.kind === "PropertyType");
659
679
  }
680
+ getObjectTypeArguments(options) {
681
+ const objectTypeOptions = (0, import_lodash4.merge)({}, options);
682
+ const resultArguments = [objectTypeOptions];
683
+ const objectType = this.find((s) => s.kind === "ObjectType");
684
+ if (objectType && (0, import_lodash4.isObject)(objectType.arguments)) {
685
+ const name = objectType.arguments.name;
686
+ (0, import_lodash4.merge)(objectTypeOptions, (0, import_lodash4.omit)(objectType.arguments, "name"));
687
+ if (name) {
688
+ resultArguments.unshift(name);
689
+ }
690
+ }
691
+ return resultArguments.map((x) => import_json52.default.stringify(x));
692
+ }
660
693
  };
661
- function createFieldSettings(args) {
662
- var _a, _b, _c;
694
+ function createObjectSettings(args) {
695
+ var _a, _b, _c, _d;
663
696
  const { config, text } = args;
664
- const result = new FieldSettings();
697
+ const result = new ObjectSettings();
665
698
  const textLines = text.split("\n");
666
699
  const documentationLines = [];
667
700
  for (const line of textLines) {
@@ -671,7 +704,7 @@ function createFieldSettings(args) {
671
704
  documentationLines.push(line);
672
705
  continue;
673
706
  }
674
- const decorator = {
707
+ const element = {
675
708
  kind: "Decorator",
676
709
  name: "",
677
710
  arguments: [],
@@ -680,27 +713,44 @@ function createFieldSettings(args) {
680
713
  from: ""
681
714
  };
682
715
  if (name === "TypeGraphQL.omit" || name === "HideField") {
683
- Object.assign(decorator, hideFieldDecorator(match));
716
+ Object.assign(element, hideFieldDecorator(match));
684
717
  } else if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
685
718
  const options = customType(match.groups.args);
686
- _lodash.merge.call(void 0, decorator, options.namespace && config.fields[options.namespace], options, { kind: name });
719
+ (0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, { kind: name });
720
+ } else if (name === "IsAbstract") {
721
+ element.kind = "ObjectType";
722
+ element.arguments = { isAbstract: true };
723
+ } else if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
724
+ element.kind = "ObjectType";
725
+ const options = customType(match.groups.args);
726
+ if (typeof options[0] === "string" && options[0]) {
727
+ options.name = options[0];
728
+ }
729
+ if ((0, import_lodash4.isObject)(options[1])) {
730
+ (0, import_lodash4.merge)(options, options[1]);
731
+ }
732
+ element.arguments = {
733
+ name: options.name,
734
+ isAbstract: options.isAbstract
735
+ };
687
736
  } else {
688
737
  const namespace = getNamespace(name);
689
- decorator.namespaceImport = namespace;
738
+ element.namespaceImport = namespace;
690
739
  const options = {
691
740
  name,
692
- arguments: (((_c = match.groups) == null ? void 0 : _c.args) || "").split(",").map((s) => _lodash.trim.call(void 0, s)).filter(Boolean)
741
+ arguments: (((_d = match.groups) == null ? void 0 : _d.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
693
742
  };
694
- _lodash.merge.call(void 0, decorator, config.fields[namespace], options);
743
+ (0, import_lodash4.merge)(element, config.fields[namespace], options);
695
744
  }
696
- result.push(decorator);
745
+ result.push(element);
697
746
  }
698
747
  return {
699
- result,
748
+ settings: result,
700
749
  documentation: documentationLines.filter(Boolean).join("\\n") || void 0
701
750
  };
702
751
  }
703
752
  function customType(args) {
753
+ var _a;
704
754
  const result = {};
705
755
  let options = parseArgs(args);
706
756
  if (typeof options === "string") {
@@ -709,7 +759,7 @@ function customType(args) {
709
759
  Object.assign(result, options);
710
760
  const namespace = getNamespace(options.name);
711
761
  result.namespace = namespace;
712
- if (options.name.includes(".")) {
762
+ if ((_a = options.name) == null ? void 0 : _a.includes(".")) {
713
763
  result.namespaceImport = namespace;
714
764
  }
715
765
  return result;
@@ -733,7 +783,7 @@ function hideFieldDecorator(match) {
733
783
  result.output = Boolean(options.output);
734
784
  result.input = Boolean(options.input);
735
785
  if (typeof options.match === "string" || Array.isArray(options.match)) {
736
- result.match = _outmatch2.default.call(void 0, options.match, { separator: false });
786
+ result.match = (0, import_outmatch2.default)(options.match, { separator: false });
737
787
  }
738
788
  } else {
739
789
  if (/output:\s*true/.test(match.groups.args)) {
@@ -747,9 +797,13 @@ function hideFieldDecorator(match) {
747
797
  }
748
798
  function parseArgs(string) {
749
799
  try {
750
- return _json52.default.parse(string);
800
+ return import_json52.default.parse(string);
751
801
  } catch (e) {
752
- throw new Error(`Failed to parse: ${string}`);
802
+ try {
803
+ return import_json52.default.parse(`[${string}]`);
804
+ } catch (e2) {
805
+ throw new Error(`Failed to parse: ${string}`);
806
+ }
753
807
  }
754
808
  }
755
809
  function getNamespace(name) {
@@ -771,38 +825,36 @@ function modelData(model, args) {
771
825
  fieldSettings.set(model.name, fieldSettingsValue);
772
826
  for (const field of model.fields) {
773
827
  if (field.documentation) {
774
- const { documentation, result } = createFieldSettings({
828
+ const { documentation, settings } = createObjectSettings({
775
829
  text: field.documentation,
776
830
  config
777
831
  });
778
832
  field.documentation = documentation;
779
- fieldSettingsValue.set(field.name, result);
833
+ fieldSettingsValue.set(field.name, settings);
780
834
  }
781
835
  modelFieldsValue.set(field.name, field);
782
836
  }
783
837
  }
784
838
 
785
839
  // src/handlers/model-output-type.ts
786
-
787
-
788
-
789
-
790
-
791
-
792
-
840
+ var import_assert3 = __toModule(require("assert"));
841
+ var import_json53 = __toModule(require("json5"));
842
+ var import_lodash5 = __toModule(require("lodash"));
843
+ var import_pupa2 = __toModule(require("pupa"));
844
+ var import_ts_morph5 = __toModule(require("ts-morph"));
793
845
 
794
846
  // src/helpers/get-output-type-name.ts
795
847
  function getOutputTypeName(name) {
796
- return name.replace(/(OutputType|Output)$/, "");
848
+ return name.replace(/(?:OutputType|Output)$/, "");
797
849
  }
798
850
 
799
851
  // src/handlers/model-output-type.ts
800
852
  var nestjsGraphql = "@nestjs/graphql";
801
853
  function modelOutputType(outputType2, args) {
802
- var _a, _b, _c, _d, _e, _f, _g;
854
+ var _a, _b, _c, _d, _e;
803
855
  const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
804
856
  const model = models.get(outputType2.name);
805
- _assert.ok.call(void 0, model, `Cannot find model by name ${outputType2.name}`);
857
+ (0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
806
858
  const sourceFile = getSourceFile({
807
859
  name: outputType2.name,
808
860
  type: "model"
@@ -811,7 +863,7 @@ function modelOutputType(outputType2, args) {
811
863
  const exportDeclaration = getExportDeclaration(model.name, sourceFileStructure.statements);
812
864
  const importDeclarations = new ImportDeclarationMap();
813
865
  const classStructure = {
814
- kind: _tsmorph.StructureKind.Class,
866
+ kind: import_ts_morph5.StructureKind.Class,
815
867
  isExported: true,
816
868
  name: outputType2.name,
817
869
  decorators: [
@@ -824,18 +876,22 @@ function modelOutputType(outputType2, args) {
824
876
  };
825
877
  sourceFileStructure.statements.push(classStructure);
826
878
  const decorator = (_a = classStructure.decorators) == null ? void 0 : _a.find((d) => d.name === "ObjectType");
827
- _assert.ok.call(void 0, decorator, "ObjectType decorator not found");
828
- const decoratorArgument = ((_b = decorator.arguments) == null ? void 0 : _b[0]) ? _json52.default.parse(decorator.arguments[0]) : {};
879
+ (0, import_assert3.ok)(decorator, "ObjectType decorator not found");
829
880
  if (model.documentation) {
830
- if (!classStructure.leadingTrivia) {
831
- classStructure.leadingTrivia = `/** ${model.documentation} */
881
+ const objectTypeOptions = {};
882
+ const { documentation, settings } = createObjectSettings({
883
+ text: model.documentation,
884
+ config
885
+ });
886
+ if (documentation) {
887
+ if (!classStructure.leadingTrivia) {
888
+ classStructure.leadingTrivia = `/** ${documentation} */
832
889
  `;
890
+ }
891
+ objectTypeOptions.description = documentation;
833
892
  }
834
- decoratorArgument.description = model.documentation;
835
- } else {
836
- delete decoratorArgument.description;
893
+ decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
837
894
  }
838
- decorator.arguments = Object.keys(decoratorArgument).length > 0 ? [_json52.default.stringify(decoratorArgument)] : [];
839
895
  importDeclarations.add("Field", nestjsGraphql);
840
896
  importDeclarations.add("ObjectType", nestjsGraphql);
841
897
  for (const field of outputType2.fields) {
@@ -846,16 +902,16 @@ function modelOutputType(outputType2, args) {
846
902
  fileType = "output";
847
903
  outputTypeName = getOutputTypeName(outputTypeName);
848
904
  }
849
- const modelField = (_c = modelFields.get(model.name)) == null ? void 0 : _c.get(field.name);
850
- const settings = (_d = fieldSettings.get(model.name)) == null ? void 0 : _d.get(field.name);
905
+ const modelField = (_b = modelFields.get(model.name)) == null ? void 0 : _b.get(field.name);
906
+ const settings = (_c = fieldSettings.get(model.name)) == null ? void 0 : _c.get(field.name);
851
907
  const fieldType = settings == null ? void 0 : settings.getFieldType();
852
908
  const propertySettings = settings == null ? void 0 : settings.getPropertyType();
853
- const propertyType = _lodash.castArray.call(void 0, (propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
909
+ const propertyType = (0, import_lodash5.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
854
910
  location,
855
911
  type: outputTypeName
856
912
  }));
857
913
  propertyType.splice(1, propertyType.length);
858
- if (field.isNullable && !isList && ["enumTypes", "scalar"].includes(location)) {
914
+ if (field.isNullable && !isList) {
859
915
  propertyType.push("null");
860
916
  }
861
917
  let graphqlType;
@@ -889,20 +945,20 @@ function modelOutputType(outputType2, args) {
889
945
  property.leadingTrivia += `/** ${modelField.documentation} */
890
946
  `;
891
947
  }
892
- (_e = classStructure.properties) == null ? void 0 : _e.push(property);
948
+ (_d = classStructure.properties) == null ? void 0 : _d.push(property);
893
949
  if (propertySettings) {
894
950
  importDeclarations.create(__spreadValues({}, propertySettings));
895
951
  }
952
+ (0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
896
953
  if (settings == null ? void 0 : settings.shouldHideField({ name: outputType2.name, output: true })) {
897
954
  importDeclarations.add("HideField", nestjsGraphql);
898
- (_f = property.decorators) == null ? void 0 : _f.push({ name: "HideField", arguments: [] });
955
+ property.decorators.push({ name: "HideField", arguments: [] });
899
956
  } else {
900
- _assert.ok.call(void 0, property.decorators);
901
957
  property.decorators.push({
902
958
  name: "Field",
903
959
  arguments: [
904
- `() => ${isList ? `[${graphqlType}]` : graphqlType}`,
905
- _json52.default.stringify({
960
+ isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
961
+ import_json53.default.stringify({
906
962
  nullable: Boolean(field.isNullable),
907
963
  defaultValue: ["number", "string", "boolean"].includes(typeof (modelField == null ? void 0 : modelField.default)) ? modelField == null ? void 0 : modelField.default : void 0,
908
964
  description: modelField == null ? void 0 : modelField.documentation
@@ -917,20 +973,24 @@ function modelOutputType(outputType2, args) {
917
973
  name: options.name,
918
974
  arguments: options.arguments
919
975
  });
920
- _assert.ok.call(void 0, options.from, "Missed 'from' part in configuration or field setting");
976
+ (0, import_assert3.ok)(options.from, "Missed 'from' part in configuration or field setting");
921
977
  importDeclarations.create(options);
922
978
  }
923
979
  for (const decorate of config.decorate) {
924
980
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
925
981
  property.decorators.push({
926
982
  name: decorate.name,
927
- arguments: (_g = decorate.arguments) == null ? void 0 : _g.map((x) => _pupa2.default.call(void 0, x, { propertyType }))
983
+ arguments: (_e = decorate.arguments) == null ? void 0 : _e.map((x) => (0, import_pupa2.default)(x, { propertyType }))
928
984
  });
929
985
  importDeclarations.create(decorate);
930
986
  }
931
987
  }
932
988
  }
933
- eventEmitter.emitSync("ClassProperty", property, { location, isList });
989
+ eventEmitter.emitSync("ClassProperty", property, {
990
+ location,
991
+ isList,
992
+ propertyType
993
+ });
934
994
  }
935
995
  if (exportDeclaration) {
936
996
  sourceFile.set({
@@ -948,7 +1008,7 @@ function modelOutputType(outputType2, args) {
948
1008
  }
949
1009
  function getExportDeclaration(name, statements) {
950
1010
  return statements.find((structure) => {
951
- return structure.kind === _tsmorph.StructureKind.ExportDeclaration && structure.namedExports.some((o) => (o.alias || o.name) === name);
1011
+ return structure.kind === import_ts_morph5.StructureKind.ExportDeclaration && structure.namedExports.some((o) => (o.alias || o.name) === name);
952
1012
  });
953
1013
  }
954
1014
 
@@ -983,19 +1043,19 @@ function isAtomicOperation(name) {
983
1043
  }
984
1044
 
985
1045
  // src/handlers/output-type.ts
986
-
987
-
988
-
989
-
1046
+ var import_assert4 = __toModule(require("assert"));
1047
+ var import_json54 = __toModule(require("json5"));
1048
+ var import_lodash6 = __toModule(require("lodash"));
1049
+ var import_ts_morph6 = __toModule(require("ts-morph"));
990
1050
  var nestjsGraphql2 = "@nestjs/graphql";
991
1051
  function outputType(outputType2, args) {
992
- var _a, _b, _c, _d, _e, _f;
993
- const { getSourceFile, models, config, eventEmitter, fieldSettings, getModelName: getModelName2 } = args;
1052
+ var _a, _b, _c;
1053
+ const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2 } = args;
994
1054
  const importDeclarations = new ImportDeclarationMap();
995
1055
  const fileType = "output";
996
1056
  const modelName = getModelName2(outputType2.name) || "";
997
1057
  const model = models.get(modelName);
998
- const isAggregateOutput = model && /(Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
1058
+ const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
999
1059
  const isCountOutput = (model == null ? void 0 : model.name) && outputType2.name === `${model.name}CountOutputType`;
1000
1060
  outputType2.name = getOutputTypeName(outputType2.name);
1001
1061
  if (isAggregateOutput) {
@@ -1006,7 +1066,7 @@ function outputType(outputType2, args) {
1006
1066
  type: fileType
1007
1067
  });
1008
1068
  const classStructure = {
1009
- kind: _tsmorph.StructureKind.Class,
1069
+ kind: import_ts_morph6.StructureKind.Class,
1010
1070
  isExported: true,
1011
1071
  name: outputType2.name,
1012
1072
  decorators: [
@@ -1026,7 +1086,7 @@ function outputType(outputType2, args) {
1026
1086
  const propertySettings = settings == null ? void 0 : settings.getPropertyType();
1027
1087
  const isCustomsApplicable = outputTypeName === ((_b = model == null ? void 0 : model.fields.find((f) => f.name === field.name)) == null ? void 0 : _b.type);
1028
1088
  field.outputType.type = outputTypeName;
1029
- const propertyType = _lodash.castArray.call(void 0, (propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1089
+ const propertyType = (0, import_lodash6.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1030
1090
  location,
1031
1091
  type: outputTypeName
1032
1092
  }));
@@ -1040,27 +1100,38 @@ function outputType(outputType2, args) {
1040
1100
  if (propertySettings) {
1041
1101
  importDeclarations.create(__spreadValues({}, propertySettings));
1042
1102
  }
1043
- const graphqlImport = getGraphqlImport({
1044
- sourceFile,
1045
- fileType,
1046
- location,
1047
- isId: false,
1048
- typeName: outputTypeName,
1049
- getSourceFile
1050
- });
1051
- const graphqlType = graphqlImport.name;
1052
- if (graphqlImport.name !== outputType2.name && graphqlImport.specifier) {
1053
- importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
1054
- }
1103
+ (0, import_assert4.ok)(property.decorators, "property.decorators is undefined");
1055
1104
  if (settings == null ? void 0 : settings.shouldHideField({ name: outputType2.name, output: true })) {
1056
1105
  importDeclarations.add("HideField", nestjsGraphql2);
1057
- (_d = property.decorators) == null ? void 0 : _d.push({ name: "HideField", arguments: [] });
1106
+ property.decorators.push({ name: "HideField", arguments: [] });
1058
1107
  } else {
1059
- (_e = property.decorators) == null ? void 0 : _e.push({
1108
+ let graphqlType;
1109
+ const fieldType = settings == null ? void 0 : settings.getFieldType();
1110
+ if (fieldType && fieldType.output && isCustomsApplicable) {
1111
+ graphqlType = fieldType.name;
1112
+ importDeclarations.create(__spreadValues({}, fieldType));
1113
+ } else {
1114
+ const graphqlImport = getGraphqlImport({
1115
+ sourceFile,
1116
+ fileType,
1117
+ location,
1118
+ isId: false,
1119
+ typeName: outputTypeName,
1120
+ getSourceFile
1121
+ });
1122
+ graphqlType = graphqlImport.name;
1123
+ if (graphqlImport.name !== outputType2.name && graphqlImport.specifier && !importDeclarations.has(graphqlImport.name)) {
1124
+ importDeclarations.set(graphqlImport.name, {
1125
+ namedImports: [{ name: graphqlImport.name }],
1126
+ moduleSpecifier: graphqlImport.specifier
1127
+ });
1128
+ }
1129
+ }
1130
+ property.decorators.push({
1060
1131
  name: "Field",
1061
1132
  arguments: [
1062
- `() => ${isList ? `[${graphqlType}]` : graphqlType}`,
1063
- _json52.default.stringify({
1133
+ isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1134
+ import_json54.default.stringify({
1064
1135
  nullable: Boolean(field.isNullable)
1065
1136
  })
1066
1137
  ]
@@ -1070,16 +1141,20 @@ function outputType(outputType2, args) {
1070
1141
  if (!options.output || options.kind !== "Decorator") {
1071
1142
  continue;
1072
1143
  }
1073
- (_f = property.decorators) == null ? void 0 : _f.push({
1144
+ property.decorators.push({
1074
1145
  name: options.name,
1075
1146
  arguments: options.arguments
1076
1147
  });
1077
- _assert.ok.call(void 0, options.from, "Missed 'from' part in configuration or field setting");
1148
+ (0, import_assert4.ok)(options.from, "Missed 'from' part in configuration or field setting");
1078
1149
  importDeclarations.create(options);
1079
1150
  }
1080
1151
  }
1081
1152
  }
1082
- eventEmitter.emitSync("ClassProperty", property, { location, isList });
1153
+ eventEmitter.emitSync("ClassProperty", property, {
1154
+ location,
1155
+ isList,
1156
+ propertyType
1157
+ });
1083
1158
  }
1084
1159
  sourceFile.set({
1085
1160
  statements: [...importDeclarations.toStatements(), classStructure]
@@ -1087,7 +1162,7 @@ function outputType(outputType2, args) {
1087
1162
  }
1088
1163
 
1089
1164
  // src/handlers/purge-output.ts
1090
- var _fs = require('fs');
1165
+ var import_fs = __toModule(require("fs"));
1091
1166
  function purgeOutput(emitter) {
1092
1167
  emitter.on("Begin", begin);
1093
1168
  emitter.on("End", end);
@@ -1106,16 +1181,14 @@ async function end({ project, output }) {
1106
1181
  const directories = (_a = project.getDirectory(output)) == null ? void 0 : _a.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1107
1182
  for (const directory of directories || []) {
1108
1183
  try {
1109
- await _fs.promises.rmdir(directory);
1184
+ await import_fs.promises.rmdir(directory);
1110
1185
  } catch (e) {
1111
1186
  }
1112
1187
  }
1113
1188
  }
1114
1189
 
1115
1190
  // src/handlers/re-export.ts
1116
-
1117
-
1118
-
1191
+ var import_ts_morph7 = __toModule(require("ts-morph"));
1119
1192
  var ReExport;
1120
1193
  (function(ReExport2) {
1121
1194
  ReExport2["None"] = "None";
@@ -1166,14 +1239,14 @@ function beforeGenerateFiles3(args) {
1166
1239
  }
1167
1240
  function getExportDeclaration2(directory, sourceFile) {
1168
1241
  return {
1169
- kind: _tsmorph.StructureKind.ExportDeclaration,
1242
+ kind: import_ts_morph7.StructureKind.ExportDeclaration,
1170
1243
  namedExports: sourceFile.getExportSymbols().map((s) => ({ name: s.getName() })),
1171
1244
  moduleSpecifier: directory.getRelativePathAsModuleSpecifierTo(sourceFile)
1172
1245
  };
1173
1246
  }
1174
1247
 
1175
1248
  // src/handlers/register-enum.ts
1176
-
1249
+ var import_ts_morph8 = __toModule(require("ts-morph"));
1177
1250
  function registerEnum(enumType, args) {
1178
1251
  const { getSourceFile, enums } = args;
1179
1252
  const dataModelEnum = enums[enumType.name];
@@ -1187,7 +1260,7 @@ function registerEnum(enumType, args) {
1187
1260
  moduleSpecifier: "@nestjs/graphql"
1188
1261
  });
1189
1262
  const enumStructure = {
1190
- kind: _tsmorph.StructureKind.Enum,
1263
+ kind: import_ts_morph8.StructureKind.Enum,
1191
1264
  isExported: true,
1192
1265
  name: enumType.name,
1193
1266
  members: enumType.values.map((v) => ({
@@ -1205,6 +1278,24 @@ function registerEnum(enumType, args) {
1205
1278
  });
1206
1279
  }
1207
1280
 
1281
+ // src/handlers/require-single-fields-in-whereunique-input.ts
1282
+ function requireSingleFieldsInWhereUniqueInput(eventEmitter) {
1283
+ eventEmitter.on("BeforeInputType", beforeInputType3);
1284
+ }
1285
+ function beforeInputType3(args) {
1286
+ const { inputType: inputType2 } = args;
1287
+ if (!isWhereUniqueInputType(inputType2.name) || inputType2.fields.length !== 1) {
1288
+ return;
1289
+ }
1290
+ for (const field of inputType2.fields) {
1291
+ field.isRequired = true;
1292
+ field.isNullable = false;
1293
+ }
1294
+ }
1295
+ function isWhereUniqueInputType(name) {
1296
+ return name.endsWith("WhereUniqueInput");
1297
+ }
1298
+
1208
1299
  // src/handlers/warning.ts
1209
1300
  function warning(message) {
1210
1301
  if (Array.isArray(message)) {
@@ -1216,21 +1307,21 @@ function warning(message) {
1216
1307
  }
1217
1308
 
1218
1309
  // src/helpers/create-config.ts
1219
-
1220
- var _filenamify = require('filenamify'); var _filenamify2 = _interopRequireDefault(_filenamify);
1221
- var _flat = require('flat');
1222
-
1223
-
1224
-
1310
+ var import_assert5 = __toModule(require("assert"));
1311
+ var import_filenamify = __toModule(require("filenamify"));
1312
+ var import_flat = __toModule(require("flat"));
1313
+ var import_json55 = __toModule(require("json5"));
1314
+ var import_lodash7 = __toModule(require("lodash"));
1315
+ var import_outmatch3 = __toModule(require("outmatch"));
1225
1316
  function createConfig(data) {
1226
1317
  var _a;
1227
- const config = _lodash.merge.call(void 0, {}, _flat.unflatten.call(void 0, data, { delimiter: "_" }));
1318
+ const config = (0, import_lodash7.merge)({}, (0, import_flat.unflatten)(data, { delimiter: "_" }));
1228
1319
  const $warnings = [];
1229
1320
  const configOutputFilePattern = String(config.outputFilePattern || `{model}/{name}.{type}.ts`);
1230
- let outputFilePattern = _filenamify2.default.call(void 0, configOutputFilePattern, {
1321
+ let outputFilePattern = (0, import_filenamify.default)(configOutputFilePattern, {
1231
1322
  replacement: "/"
1232
1323
  }).replace(/\.\./g, "/").replace(/\/+/g, "/");
1233
- outputFilePattern = _lodash.trim.call(void 0, outputFilePattern, "/");
1324
+ outputFilePattern = (0, import_lodash7.trim)(outputFilePattern, "/");
1234
1325
  if (outputFilePattern !== configOutputFilePattern) {
1235
1326
  $warnings.push(`Due to invalid filepath 'outputFilePattern' changed to '${outputFilePattern}'`);
1236
1327
  }
@@ -1256,16 +1347,16 @@ function createConfig(data) {
1256
1347
  for (const element of configDecorate) {
1257
1348
  if (!element)
1258
1349
  continue;
1259
- _assert.ok.call(void 0, element.from && element.name, `Missed 'from' or 'name' part in configuration for decorate`);
1350
+ (0, import_assert5.ok)(element.from && element.name, `Missed 'from' or 'name' part in configuration for decorate`);
1260
1351
  decorate.push({
1261
- isMatchField: _outmatch2.default.call(void 0, element.field, { separator: false }),
1262
- isMatchType: _outmatch2.default.call(void 0, element.type, { separator: false }),
1352
+ isMatchField: (0, import_outmatch3.default)(element.field, { separator: false }),
1353
+ isMatchType: (0, import_outmatch3.default)(element.type, { separator: false }),
1263
1354
  from: element.from,
1264
1355
  name: element.name,
1265
1356
  namedImport: toBoolean(element.namedImport),
1266
1357
  defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
1267
1358
  namespaceImport: element.namespaceImport,
1268
- arguments: element.arguments ? _json52.default.parse(element.arguments) : void 0
1359
+ arguments: element.arguments ? import_json55.default.parse(element.arguments) : void 0
1269
1360
  });
1270
1361
  }
1271
1362
  return {
@@ -1281,6 +1372,7 @@ function createConfig(data) {
1281
1372
  purgeOutput: toBoolean(config.purgeOutput),
1282
1373
  useInputType: createUseInputType(config.useInputType),
1283
1374
  noTypeId: toBoolean(config.noTypeId),
1375
+ requireSingleFieldsInWhereUniqueInput: toBoolean(config.requireSingleFieldsInWhereUniqueInput),
1284
1376
  decorate
1285
1377
  };
1286
1378
  }
@@ -1310,19 +1402,19 @@ function toBoolean(value) {
1310
1402
  }
1311
1403
 
1312
1404
  // src/helpers/generate-file-name.ts
1313
-
1314
- var _pluralize = require('pluralize'); var _pluralize2 = _interopRequireDefault(_pluralize);
1315
-
1405
+ var import_lodash8 = __toModule(require("lodash"));
1406
+ var import_pluralize = __toModule(require("pluralize"));
1407
+ var import_pupa3 = __toModule(require("pupa"));
1316
1408
  function generateFileName(args) {
1317
1409
  const { template, type, name, getModelName: getModelName2 } = args;
1318
- return _pupa2.default.call(void 0, template, {
1410
+ return (0, import_pupa3.default)(template, {
1319
1411
  type,
1320
1412
  get model() {
1321
1413
  const result = getModelName2(name) || "prisma";
1322
- return _lodash.kebabCase.call(void 0, result);
1414
+ return (0, import_lodash8.kebabCase)(result);
1323
1415
  },
1324
1416
  get name() {
1325
- let result = _lodash.kebabCase.call(void 0, name);
1417
+ let result = (0, import_lodash8.kebabCase)(name);
1326
1418
  for (const suffix of ["input", "args", "enum"]) {
1327
1419
  const ending = `-${suffix}`;
1328
1420
  if (type === suffix && result.endsWith(ending)) {
@@ -1333,7 +1425,7 @@ function generateFileName(args) {
1333
1425
  },
1334
1426
  plural: {
1335
1427
  get type() {
1336
- return _pluralize2.default.call(void 0, type);
1428
+ return (0, import_pluralize.default)(type);
1337
1429
  }
1338
1430
  }
1339
1431
  });
@@ -1356,9 +1448,9 @@ function factoryGetSourceFile(args) {
1356
1448
  }
1357
1449
 
1358
1450
  // src/helpers/get-model-name.ts
1359
-
1451
+ var import_lodash9 = __toModule(require("lodash"));
1360
1452
  function createGetModelName(modelNames) {
1361
- return _lodash.memoize.call(void 0, tryGetName);
1453
+ return (0, import_lodash9.memoize)(tryGetName);
1362
1454
  function tryGetName(name) {
1363
1455
  return getModelName({ modelNames, name });
1364
1456
  }
@@ -1387,6 +1479,11 @@ function getModelName(args) {
1387
1479
  return test;
1388
1480
  }
1389
1481
  }
1482
+ if (name.slice(-19) === "CompoundUniqueInput") {
1483
+ const test = name.slice(0, -19);
1484
+ const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
1485
+ return (0, import_lodash9.first)(models);
1486
+ }
1390
1487
  if (name.slice(-5) === "Count") {
1391
1488
  const test = name.slice(0, -5);
1392
1489
  if (modelNames.includes(test)) {
@@ -1470,8 +1567,8 @@ async function generate(args) {
1470
1567
  var _a;
1471
1568
  const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
1472
1569
  const generatorOutputValue = (_a = generator.output) == null ? void 0 : _a.value;
1473
- _assert.ok.call(void 0, generatorOutputValue, "Missing generator configuration: output");
1474
- const eventEmitter = new (0, _awaiteventemitter2.default)();
1570
+ (0, import_assert6.ok)(generatorOutputValue, "Missing generator configuration: output");
1571
+ const eventEmitter = new import_await_event_emitter.default();
1475
1572
  eventEmitter.on("Warning", warning);
1476
1573
  eventEmitter.on("Model", modelData);
1477
1574
  eventEmitter.on("EnumType", registerEnum);
@@ -1486,12 +1583,12 @@ async function generate(args) {
1486
1583
  for (const message of config.$warnings) {
1487
1584
  eventEmitter.emitSync("Warning", message);
1488
1585
  }
1489
- const project = new (0, _tsmorph.Project)({
1586
+ const project = new import_ts_morph9.Project({
1490
1587
  tsConfigFilePath: config.tsConfigFilePath,
1491
1588
  skipAddingFilesFromTsConfig: true,
1492
1589
  skipLoadingLibFiles: !config.emitCompiled,
1493
1590
  manipulationSettings: {
1494
- quoteKind: _tsmorph.QuoteKind.Single
1591
+ quoteKind: import_ts_morph9.QuoteKind.Single
1495
1592
  }
1496
1593
  });
1497
1594
  if (!skipAddOutputSourceFiles) {
@@ -1505,6 +1602,7 @@ async function generate(args) {
1505
1602
  config.reExport !== ReExport.None && reExport(eventEmitter);
1506
1603
  config.emitSingle && emitSingle(eventEmitter);
1507
1604
  config.purgeOutput && purgeOutput(eventEmitter);
1605
+ config.requireSingleFieldsInWhereUniqueInput && requireSingleFieldsInWhereUniqueInput(eventEmitter);
1508
1606
  const models = new Map();
1509
1607
  const modelNames = [];
1510
1608
  const modelFields = new Map();
@@ -1533,8 +1631,8 @@ async function generate(args) {
1533
1631
  getSourceFile,
1534
1632
  eventEmitter,
1535
1633
  typeNames: new Set(),
1536
- enums: _lodash.mapKeys.call(void 0, datamodel.enums, (x) => x.name),
1537
- getModelName: createGetModelName(modelNames),
1634
+ enums: (0, import_lodash10.mapKeys)(datamodel.enums, (x) => x.name),
1635
+ getModelName: getModelName2,
1538
1636
  removeTypes
1539
1637
  };
1540
1638
  if (connectCallback) {
@@ -1587,7 +1685,7 @@ async function generate(args) {
1587
1685
  }
1588
1686
 
1589
1687
  // src/index.ts
1590
- _generatorhelper.generatorHandler.call(void 0, {
1688
+ (0, import_generator_helper.generatorHandler)({
1591
1689
  async onGenerate(options) {
1592
1690
  await generate(options);
1593
1691
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "14.1.0",
3
+ "version": "14.3.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",
@@ -47,7 +47,7 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "@prisma/generator-helper": "^3.0.2",
50
+ "@prisma/generator-helper": "^3.1.1",
51
51
  "await-event-emitter": "^2.0.2",
52
52
  "filenamify": "4.X",
53
53
  "flat": "^5.0.2",
@@ -59,7 +59,6 @@
59
59
  "pupa": "2.X",
60
60
  "ts-morph": ">=11 <=12"
61
61
  },
62
- "peerDependencies": {},
63
62
  "devDependencies": {
64
63
  "@arkweid/lefthook": "0.7.6",
65
64
  "@commitlint/cli": "^13.1.0",
@@ -68,18 +67,17 @@
68
67
  "@nestjs/core": "^8.0.6",
69
68
  "@nestjs/graphql": "^9.0.4",
70
69
  "@nestjs/platform-express": "^8.0.6",
71
- "@paljs/plugins": "^4.0.7",
72
- "@prisma/client": "^3.0.2",
73
- "@semantic-release/changelog": "^5.0.1",
74
- "@semantic-release/git": "^9.0.1",
75
- "@types/find-cache-dir": "^3.2.1",
70
+ "@paljs/plugins": "^4.0.8",
71
+ "@prisma/client": "^3.1.1",
72
+ "@semantic-release/changelog": "^6.0.0",
73
+ "@semantic-release/git": "^10.0.0",
76
74
  "@types/flat": "^5.0.2",
77
- "@types/lodash": "^4.14.172",
75
+ "@types/lodash": "^4.14.173",
78
76
  "@types/mocha": "^9.0.0",
79
- "@types/node": "^16.9.1",
77
+ "@types/node": "^16.9.6",
80
78
  "@types/pluralize": "^0.0.29",
81
- "@typescript-eslint/eslint-plugin": "^4.31.0",
82
- "@typescript-eslint/parser": "^4.31.0",
79
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
80
+ "@typescript-eslint/parser": "^4.31.2",
83
81
  "apollo-server-express": "^3.3.0",
84
82
  "c8": "^7.9.0",
85
83
  "class-transformer": "^0.4.0",
@@ -99,28 +97,28 @@
99
97
  "eslint-plugin-sonarjs": "^0.10.0",
100
98
  "eslint-plugin-sort-class-members": "^1.11.0",
101
99
  "eslint-plugin-total-functions": "^4.10.1",
102
- "eslint-plugin-unicorn": "^35.0.0",
100
+ "eslint-plugin-unicorn": "^36.0.0",
103
101
  "eslint-plugin-wix-editor": "^3.3.0",
104
- "expect": "^27.1.1",
105
- "find-cache-dir": "^3.3.2",
102
+ "expect": "^27.2.1",
106
103
  "git-branch-is": "^4.0.0",
107
- "graphql": "^15.5.3",
104
+ "graphql": "^15.6.0",
108
105
  "graphql-scalars": "^1.10.1",
109
106
  "graphql-type-json": "^0.3.2",
110
107
  "mocha": "^9.1.1",
111
108
  "ololog": "^1.1.175",
112
109
  "precise-commits": "^1.0.2",
113
- "prettier": "^2.4.0",
114
- "prisma": "^3.0.2",
110
+ "prettier": "^2.4.1",
111
+ "prisma": "^3.1.1",
115
112
  "prisma-graphql-type-decimal": "^1.0.0",
116
113
  "reflect-metadata": "^0.1.13",
117
114
  "rxjs": "^7.3.0",
118
- "semantic-release": "^17.4.7",
115
+ "semantic-release": "^18.0.0",
119
116
  "simplytyped": "^3.3.0",
117
+ "temp-dir": "^2.0.0",
120
118
  "ts-node": "^10.2.1",
121
119
  "ts-node-dev": "^1.1.8",
122
120
  "tslib": "^2.3.1",
123
- "typescript": "^4.4.2",
121
+ "typescript": "^4.4.3",
124
122
  "watchexec-bin": "^1.0.0"
125
123
  }
126
124
  }