prisma-nestjs-graphql 13.0.0 → 14.2.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 (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +141 -19
  3. package/index.js +240 -134
  4. package/package.json +29 -32
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020
3
+ Copyright (c) 2021
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -143,8 +143,8 @@ Where:
143
143
  Example: `UserCreateInput` full name, `WhereInput` partial name, matches `UserWhereInput`, `PostWhereInput`, etc.
144
144
  - `property` Property of the class for which need to choose type. Special case name `ALL` means any / all properties.
145
145
  - `pattern` Part of name (or full) of type which should be chosen, you can use
146
- wild card or negate symbols, in this case pattern should starts with `matcher:`,
147
- e.g. `matcher:*UncheckedCreateInput` See [matcher](https://github.com/sindresorhus/matcher) for details.
146
+ wild card or negate symbols, in this case pattern should starts with `match:`,
147
+ e.g. `match:*UncheckedCreateInput` see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
148
148
 
149
149
  Example:
150
150
 
@@ -185,6 +185,92 @@ export class PostWhereInput {
185
185
  }
186
186
  ```
187
187
 
188
+ #### `decorate`
189
+
190
+ Allow to attach multiple decorators to any field of any type.
191
+
192
+ ```sh
193
+ generator nestgraphql {
194
+ decorate_{key}_type = "outmatch pattern"
195
+ decorate_{key}_field = "outmatch pattern"
196
+ decorate_{key}_from = "module specifier"
197
+ decorate_{key}_name = "import name"
198
+ decorate_{key}_arguments = "[argument1, argument2]"
199
+ decorate_{key}_defaultImport = "default import name" | true
200
+ decorate_{key}_namespaceImport = "namespace import name"
201
+ decorate_{key}_namedImport = "import name" | true
202
+ }
203
+ ```
204
+
205
+ Where `{key}` any identifier to group values (written in [flatten](https://github.com/hughsk/flat) style)
206
+
207
+ - `decorate_{key}_type` - outmatch pattern to match class name
208
+ - `decorate_{key}_field` - outmatch pattern to match field name
209
+ - `decorate_{key}_from` - module specifier to import from (e.g `class-validator`)
210
+ - `decorate_{key}_name` - import name or name with namespace
211
+ - `decorate_{key}_defaultImport` - import as default
212
+ - `decorate_{key}_namespaceImport` - use this name as import namespace
213
+ - `decorate_{key}_namedImport` - named import (without namespace)
214
+ - `decorate_{key}_arguments` - arguments for decorator (if decorator need to be called as function)
215
+ Special tokens can be used:
216
+ - `{propertyType.0}` - field's type (TypeScript type annotation)
217
+
218
+ Example of generated class:
219
+
220
+ ```ts
221
+ @ArgsType()
222
+ export class CreateOneUserArgs {
223
+ @Field(() => UserCreateInput, { nullable: false })
224
+ data!: UserCreateInput;
225
+ }
226
+ ```
227
+
228
+ To make it validateable (assuming `UserCreateInput` already contains validation decorators from `class-validator`),
229
+ it is necessary to add `@ValidateNested()` and `@Type()` from `class-transformer`.
230
+
231
+ ```sh
232
+ decorate_1_type = "CreateOneUserArgs"
233
+ decorate_1_field = data
234
+ decorate_1_name = ValidateNested
235
+ decorate_1_from = "class-validator"
236
+ decorate_1_arguments = "[]"
237
+ decorate_2_type = "CreateOneUserArgs"
238
+ decorate_2_field = data
239
+ decorate_2_from = "class-transformer"
240
+ decorate_2_arguments = "['() => {propertyType.0}']"
241
+ decorate_2_name = Type
242
+ ```
243
+
244
+ Result:
245
+
246
+ ```ts
247
+ import { ValidateNested } from 'class-validator';
248
+ import { Type } from 'class-transformer';
249
+
250
+ @ArgsType()
251
+ export class CreateOneUserArgs {
252
+ @Field(() => UserCreateInput, { nullable: false })
253
+ @ValidateNested()
254
+ @Type(() => UserCreateInput)
255
+ data!: UserCreateInput;
256
+ }
257
+ ```
258
+
259
+ Another example:
260
+
261
+ ```sh
262
+ decorate_2_namespaceImport = "Transform"
263
+ decorate_2_name = "Transform.Type"
264
+ ```
265
+
266
+ ```ts
267
+ import * as Transform from 'class-transformer';
268
+
269
+ @Transform.Type(() => UserCreateInput)
270
+ data!: UserCreateInput;
271
+
272
+ ```
273
+
188
274
  ## Field Settings
189
275
 
190
276
  Special directives in triple slash comments for more precise code generation.
@@ -249,52 +335,52 @@ Applying custom decorators requires configuration of generator.
249
335
 
250
336
  ```sh
251
337
  generator nestgraphql {
252
- fields_{Namespace}_from = "module specifier"
253
- fields_{Namespace}_input = true | false
254
- fields_{Namespace}_output = true | false
255
- fields_{Namespace}_defaultImport = "default import name" | true
256
- fields_{Namespace}_namespaceImport = "namespace import name"
257
- fields_{Namespace}_namedImport = true | false
338
+ fields_{namespace}_from = "module specifier"
339
+ fields_{namespace}_input = true | false
340
+ fields_{namespace}_output = true | false
341
+ fields_{namespace}_defaultImport = "default import name" | true
342
+ fields_{namespace}_namespaceImport = "namespace import name"
343
+ fields_{namespace}_namedImport = true | false
258
344
  }
259
345
  ```
260
346
 
261
- Create configuration map in [flatten](https://github.com/hughsk/flat) style for `{Namespace}`.
262
- Where `{Namespace}` is a namespace used in field triple slash comment.
347
+ Create configuration map in [flatten](https://github.com/hughsk/flat) style for `{namespace}`.
348
+ Where `{namespace}` is a namespace used in field triple slash comment.
263
349
 
264
- ##### `fields_{Namespace}_from`
350
+ ##### `fields_{namespace}_from`
265
351
 
266
352
  Required. Name of the module, which will be used in import (`class-validator`, `graphql-scalars`, etc.)
267
353
  Type: `string`
268
354
 
269
- ##### `fields_{Namespace}_input`
355
+ ##### `fields_{namespace}_input`
270
356
 
271
357
  Means that it will be applied on input types (classes decorated by `InputType`)
272
358
  Type: `boolean`
273
359
  Default: `false`
274
360
 
275
- ##### `fields_{Namespace}_output`
361
+ ##### `fields_{namespace}_output`
276
362
 
277
363
  Means that it will be applied on output types (classes decorated by `ObjectType`)
278
364
  Type: `boolean`
279
365
  Default: `false`
280
366
 
281
- ##### `fields_{Namespace}_defaultImport`
367
+ ##### `fields_{namespace}_defaultImport`
282
368
 
283
369
  Default import name, if module have no namespace.
284
370
  Type: `undefined | string | true`
285
371
  Default: `undefined`
286
- If defined as `true` then import name will be same as `{Namespace}`
372
+ If defined as `true` then import name will be same as `{namespace}`
287
373
 
288
- ##### `fields_{Namespace}_namespaceImport`
374
+ ##### `fields_{namespace}_namespaceImport`
289
375
 
290
376
  Import all as this namespace from module
291
377
  Type: `undefined | string`
292
- Default: Equals to `{Namespace}`
378
+ Default: Equals to `{namespace}`
293
379
 
294
- ##### `fields_{Namespace}_namedImport`
380
+ ##### `fields_{namespace}_namedImport`
295
381
 
296
382
  If imported module has internal namespace, this allow to generate named import,
297
- imported name will be equal to `{Namespace}`, see [example of usage](#propertytype)
383
+ imported name will be equal to `{namespace}`, see [example of usage](#propertytype)
298
384
  Type: `boolean`
299
385
  Default: `false`
300
386
 
@@ -434,8 +520,44 @@ export class User {
434
520
  }
435
521
  ```
436
522
 
523
+ #### @ObjectType()
524
+
525
+ Allow rename type in schema and make mark as abstract.
526
+
527
+ Example 1:
528
+
529
+ ```
530
+ // schema.prisma
531
+ /// @ObjectType({ isAbstract: true })
532
+ model User {
533
+ id Int @id
534
+ }
535
+ ```
536
+
537
+ ```ts
538
+ @ObjectType({ isAbstract: true })
539
+ export class User {}
540
+ ```
541
+
542
+ Example 2:
543
+
544
+ ```
545
+ // schema.prisma
546
+ /// @ObjectType('Human', { isAbstract: true })
547
+ model User {
548
+ id Int @id
549
+ }
550
+ ```
551
+
552
+ ```ts
553
+ @ObjectType('Human', { isAbstract: true })
554
+ export class User {}
555
+ ```
556
+
437
557
  ## Similar Projects
438
558
 
559
+ - https://github.com/rfermann/nestjs-prisma-graphql-generator
560
+ - https://github.com/madscience/graphql-codegen-nestjs
439
561
  - https://github.com/wSedlacek/prisma-generators/tree/master/libs/nestjs
440
562
  - https://github.com/EndyKaufman/typegraphql-prisma-nestjs
441
563
  - 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,20 +21,35 @@ var __spreadValues = (a, b) => {
17
21
  return a;
18
22
  };
19
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
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;
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;
20
39
 
21
40
  // src/index.ts
22
- var _generatorhelper = require('@prisma/generator-helper');
41
+ var import_generator_helper = __toModule(require("@prisma/generator-helper"));
23
42
 
24
43
  // src/generate.ts
25
- var _assert = require('assert');
26
- var _awaiteventemitter = require('await-event-emitter'); var _awaiteventemitter2 = _interopRequireDefault(_awaiteventemitter);
27
- var _lodash = require('lodash');
28
- 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"));
29
48
 
30
49
  // src/helpers/pascal-case.ts
31
-
50
+ var import_lodash = __toModule(require("lodash"));
32
51
  function pascalCase(string) {
33
- 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, "");
34
53
  }
35
54
 
36
55
  // src/handlers/args-type.ts
@@ -171,15 +190,11 @@ function classProperty(property, eventArguments) {
171
190
  }
172
191
 
173
192
  // src/handlers/generate-files.ts
174
-
175
-
176
-
177
-
193
+ var import_assert = __toModule(require("assert"));
194
+ var import_ts_morph2 = __toModule(require("ts-morph"));
178
195
 
179
196
  // src/helpers/import-declaration-map.ts
180
-
181
-
182
-
197
+ var import_ts_morph = __toModule(require("ts-morph"));
183
198
  var ImportDeclarationMap = class extends Map {
184
199
  add(name, value) {
185
200
  if (!this.has(name)) {
@@ -215,7 +230,7 @@ var ImportDeclarationMap = class extends Map {
215
230
  let result = iterator.next();
216
231
  while (result.value) {
217
232
  yield __spreadProps(__spreadValues({}, result.value), {
218
- kind: _tsmorph.StructureKind.ImportDeclaration
233
+ kind: import_ts_morph.StructureKind.ImportDeclaration
219
234
  });
220
235
  result = iterator.next();
221
236
  }
@@ -237,13 +252,13 @@ function beforeGenerateFiles(args) {
237
252
  const statements2 = s.getStructure().statements;
238
253
  if (Array.isArray(statements2)) {
239
254
  for (const statement of statements2) {
240
- if (!(typeof statement === "object" && statement.kind === _tsmorph.StructureKind.Class)) {
255
+ if (!(typeof statement === "object" && statement.kind === import_ts_morph2.StructureKind.Class)) {
241
256
  continue;
242
257
  }
243
258
  for (const property of statement.properties || []) {
244
259
  for (const decorator of property.decorators || []) {
245
260
  const fullName = (_b = (_a = classDeclaration == null ? void 0 : classDeclaration.getProperty(property.name)) == null ? void 0 : _a.getDecorator(decorator.name)) == null ? void 0 : _b.getFullName();
246
- _assert.ok.call(void 0, fullName, `Cannot get full name of decorator of class ${statement.name}`);
261
+ (0, import_assert.ok)(fullName, `Cannot get full name of decorator of class ${statement.name}`);
247
262
  decorator.name = fullName;
248
263
  }
249
264
  }
@@ -263,7 +278,7 @@ function beforeGenerateFiles(args) {
263
278
  continue;
264
279
  }
265
280
  switch (statement.kind) {
266
- case _tsmorph.StructureKind.ImportDeclaration:
281
+ case import_ts_morph2.StructureKind.ImportDeclaration:
267
282
  if (statement.moduleSpecifier.startsWith("./") || statement.moduleSpecifier.startsWith("..")) {
268
283
  continue;
269
284
  }
@@ -286,16 +301,16 @@ function beforeGenerateFiles(args) {
286
301
  });
287
302
  }
288
303
  break;
289
- case _tsmorph.StructureKind.Enum:
304
+ case import_ts_morph2.StructureKind.Enum:
290
305
  enums.unshift(statement);
291
306
  break;
292
- case _tsmorph.StructureKind.Class:
307
+ case import_ts_morph2.StructureKind.Class:
293
308
  classes.push(statement);
294
309
  break;
295
310
  }
296
311
  }
297
312
  sourceFile.set({
298
- kind: _tsmorph.StructureKind.SourceFile,
313
+ kind: import_ts_morph2.StructureKind.SourceFile,
299
314
  statements: [...imports.toStatements(), ...enums, ...classes]
300
315
  });
301
316
  }
@@ -322,10 +337,11 @@ async function generateFiles(args) {
322
337
  }
323
338
 
324
339
  // src/handlers/input-type.ts
325
-
326
- var _json5 = require('json5'); var _json52 = _interopRequireDefault(_json5);
327
-
328
-
340
+ var import_assert2 = __toModule(require("assert"));
341
+ var import_json5 = __toModule(require("json5"));
342
+ var import_lodash3 = __toModule(require("lodash"));
343
+ var import_pupa = __toModule(require("pupa"));
344
+ var import_ts_morph4 = __toModule(require("ts-morph"));
329
345
 
330
346
  // src/helpers/file-type-by-location.ts
331
347
  function fileTypeByLocation(fieldLocation) {
@@ -341,7 +357,7 @@ function fileTypeByLocation(fieldLocation) {
341
357
  }
342
358
 
343
359
  // src/helpers/relative-path.ts
344
- var _getrelativepath = require('get-relative-path'); var _getrelativepath2 = _interopRequireDefault(_getrelativepath);
360
+ var import_get_relative_path = __toModule(require("get-relative-path"));
345
361
  function relativePath(from, to) {
346
362
  if (!from.startsWith("/")) {
347
363
  from = `/${from}`;
@@ -349,7 +365,7 @@ function relativePath(from, to) {
349
365
  if (!to.startsWith("/")) {
350
366
  to = `/${to}`;
351
367
  }
352
- let result = _getrelativepath2.default.call(void 0, from, to);
368
+ let result = (0, import_get_relative_path.default)(from, to);
353
369
  if (!result.startsWith(".")) {
354
370
  result = `./${result}`;
355
371
  }
@@ -397,15 +413,15 @@ function getGraphqlImport(args) {
397
413
  }
398
414
 
399
415
  // src/helpers/get-graphql-input-type.ts
400
-
401
- var _matcher = require('matcher'); var _matcher2 = _interopRequireDefault(_matcher);
416
+ var import_lodash2 = __toModule(require("lodash"));
417
+ var import_outmatch = __toModule(require("outmatch"));
402
418
  function getGraphqlInputType(inputTypes, pattern) {
403
419
  let result;
404
420
  inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(String(t.type)));
405
421
  if (inputTypes.length === 1) {
406
422
  return inputTypes[0];
407
423
  }
408
- const countTypes = _lodash.countBy.call(void 0, inputTypes, (x) => x.location);
424
+ const countTypes = (0, import_lodash2.countBy)(inputTypes, (x) => x.location);
409
425
  const isOneType = Object.keys(countTypes).length === 1;
410
426
  if (isOneType) {
411
427
  result = inputTypes.find((x) => x.isList);
@@ -414,9 +430,10 @@ function getGraphqlInputType(inputTypes, pattern) {
414
430
  }
415
431
  }
416
432
  if (pattern) {
417
- if (pattern.startsWith("matcher:")) {
418
- const patternValue = pattern.slice(8);
419
- result = inputTypes.find((x) => _matcher2.default.isMatch(String(x.type), patternValue));
433
+ if (pattern.startsWith("matcher:") || pattern.startsWith("match:")) {
434
+ const { 1: patternValue } = pattern.split(":", 2);
435
+ const isMatch = (0, import_outmatch.default)(patternValue, { separator: false });
436
+ result = inputTypes.find((x) => isMatch(String(x.type)));
420
437
  if (result) {
421
438
  return result;
422
439
  }
@@ -430,6 +447,12 @@ function getGraphqlInputType(inputTypes, pattern) {
430
447
  if (result) {
431
448
  return result;
432
449
  }
450
+ if (countTypes.enumTypes && countTypes.scalar && inputTypes.some((x) => x.type === "Json" && x.location === "scalar")) {
451
+ result = inputTypes.find((x) => x.type === "Json" && x.location === "scalar");
452
+ if (result) {
453
+ return result;
454
+ }
455
+ }
433
456
  throw new TypeError(`Cannot get matching input type from ${inputTypes.map((x) => x.type).join(", ") || "zero length inputTypes"}`);
434
457
  }
435
458
 
@@ -469,7 +492,7 @@ function getPropertyType(args) {
469
492
  }
470
493
 
471
494
  // src/helpers/property-structure.ts
472
-
495
+ var import_ts_morph3 = __toModule(require("ts-morph"));
473
496
  function propertyStructure(args) {
474
497
  const {
475
498
  isNullable,
@@ -481,7 +504,7 @@ function propertyStructure(args) {
481
504
  } = args;
482
505
  const type = propertyType.map((type2) => isList ? `Array<${type2}>` : type2).join(" | ");
483
506
  return {
484
- kind: _tsmorph.StructureKind.Property,
507
+ kind: import_ts_morph3.StructureKind.Property,
485
508
  name,
486
509
  type,
487
510
  hasQuestionToken: hasQuestionToken != null ? hasQuestionToken : isNullable,
@@ -493,7 +516,7 @@ function propertyStructure(args) {
493
516
 
494
517
  // src/handlers/input-type.ts
495
518
  function inputType(args) {
496
- var _a, _b, _c;
519
+ var _a, _b, _c, _d;
497
520
  const {
498
521
  inputType: inputType2,
499
522
  fileType,
@@ -514,7 +537,7 @@ function inputType(args) {
514
537
  type: fileType
515
538
  });
516
539
  const classStructure = {
517
- kind: _tsmorph.StructureKind.Class,
540
+ kind: import_ts_morph4.StructureKind.Class,
518
541
  isExported: true,
519
542
  name: inputType2.name,
520
543
  decorators: [
@@ -528,12 +551,13 @@ function inputType(args) {
528
551
  const modelName = getModelName2(inputType2.name) || "";
529
552
  const model = models.get(modelName);
530
553
  const modelFieldSettings = model && fieldSettings.get(model.name);
554
+ const moduleSpecifier = "@nestjs/graphql";
531
555
  importDeclarations.set("Field", {
532
556
  namedImports: [{ name: "Field" }],
533
- moduleSpecifier: "@nestjs/graphql"
557
+ moduleSpecifier
534
558
  }).set(classDecoratorName, {
535
559
  namedImports: [{ name: classDecoratorName }],
536
- moduleSpecifier: "@nestjs/graphql"
560
+ moduleSpecifier
537
561
  });
538
562
  const useInputType = config.useInputType.find((x) => inputType2.name.includes(x.typeName));
539
563
  for (const field of inputType2.fields) {
@@ -547,7 +571,7 @@ function inputType(args) {
547
571
  const settings = modelFieldSettings == null ? void 0 : modelFieldSettings.get(name);
548
572
  const propertySettings = settings == null ? void 0 : settings.getPropertyType();
549
573
  const isCustomsApplicable = typeName === ((_a = model == null ? void 0 : model.fields.find((f) => f.name === name)) == null ? void 0 : _a.type);
550
- const propertyType = _lodash.castArray.call(void 0, (propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
574
+ const propertyType = (0, import_lodash3.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
551
575
  location,
552
576
  type: typeName
553
577
  }));
@@ -585,11 +609,12 @@ function inputType(args) {
585
609
  importDeclarations.add("HideField", "@nestjs/graphql");
586
610
  (_c = property.decorators) == null ? void 0 : _c.push({ name: "HideField", arguments: [] });
587
611
  } else {
612
+ (0, import_assert2.ok)(property.decorators);
588
613
  property.decorators.push({
589
614
  name: "Field",
590
615
  arguments: [
591
616
  `() => ${isList ? `[${graphqlType}]` : graphqlType}`,
592
- _json52.default.stringify({
617
+ import_json5.default.stringify({
593
618
  nullable: !isRequired
594
619
  })
595
620
  ]
@@ -603,10 +628,19 @@ function inputType(args) {
603
628
  name: options.name,
604
629
  arguments: options.arguments
605
630
  });
606
- _assert.ok.call(void 0, options.from, "Missed 'from' part in configuration or field setting");
631
+ (0, import_assert2.ok)(options.from, "Missed 'from' part in configuration or field setting");
607
632
  importDeclarations.create(options);
608
633
  }
609
634
  }
635
+ for (const decorate of config.decorate) {
636
+ if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
637
+ property.decorators.push({
638
+ name: decorate.name,
639
+ arguments: (_d = decorate.arguments) == null ? void 0 : _d.map((x) => (0, import_pupa.default)(x, { propertyType }))
640
+ });
641
+ importDeclarations.create(decorate);
642
+ }
643
+ }
610
644
  }
611
645
  eventEmitter.emitSync("ClassProperty", property, { location, isList });
612
646
  }
@@ -615,11 +649,11 @@ function inputType(args) {
615
649
  });
616
650
  }
617
651
 
618
- // src/helpers/field-settings.ts
619
-
620
-
621
- var _outmatch = require('outmatch'); var _outmatch2 = _interopRequireDefault(_outmatch);
622
- var FieldSettings = class extends Array {
652
+ // src/helpers/object-settings.ts
653
+ var import_json52 = __toModule(require("json5"));
654
+ var import_lodash4 = __toModule(require("lodash"));
655
+ var import_outmatch2 = __toModule(require("outmatch"));
656
+ var ObjectSettings = class extends Array {
623
657
  shouldHideField({
624
658
  name,
625
659
  input = false,
@@ -635,11 +669,24 @@ var FieldSettings = class extends Array {
635
669
  getPropertyType() {
636
670
  return this.find((s) => s.kind === "PropertyType");
637
671
  }
672
+ getObjectTypeArguments(options) {
673
+ const objectTypeOptions = (0, import_lodash4.merge)({}, options);
674
+ const resultArguments = [objectTypeOptions];
675
+ const objectType = this.find((s) => s.kind === "ObjectType");
676
+ if (objectType && (0, import_lodash4.isObject)(objectType.arguments)) {
677
+ const name = objectType.arguments.name;
678
+ (0, import_lodash4.merge)(objectTypeOptions, (0, import_lodash4.omit)(objectType.arguments, "name"));
679
+ if (name) {
680
+ resultArguments.unshift(name);
681
+ }
682
+ }
683
+ return resultArguments.map((x) => import_json52.default.stringify(x));
684
+ }
638
685
  };
639
- function createFieldSettings(args) {
640
- var _a, _b, _c;
686
+ function createObjectSettings(args) {
687
+ var _a, _b, _c, _d;
641
688
  const { config, text } = args;
642
- const result = new FieldSettings();
689
+ const result = new ObjectSettings();
643
690
  const textLines = text.split("\n");
644
691
  const documentationLines = [];
645
692
  for (const line of textLines) {
@@ -649,7 +696,7 @@ function createFieldSettings(args) {
649
696
  documentationLines.push(line);
650
697
  continue;
651
698
  }
652
- const decorator = {
699
+ const element = {
653
700
  kind: "Decorator",
654
701
  name: "",
655
702
  arguments: [],
@@ -658,27 +705,44 @@ function createFieldSettings(args) {
658
705
  from: ""
659
706
  };
660
707
  if (name === "TypeGraphQL.omit" || name === "HideField") {
661
- Object.assign(decorator, hideFieldDecorator(match));
708
+ Object.assign(element, hideFieldDecorator(match));
662
709
  } else if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
663
710
  const options = customType(match.groups.args);
664
- _lodash.merge.call(void 0, decorator, options.namespace && config.fields[options.namespace], options, { kind: name });
711
+ (0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, { kind: name });
712
+ } else if (name === "IsAbstract") {
713
+ element.kind = "ObjectType";
714
+ element.arguments = { isAbstract: true };
715
+ } else if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
716
+ element.kind = "ObjectType";
717
+ const options = customType(match.groups.args);
718
+ if (typeof options[0] === "string" && options[0]) {
719
+ options.name = options[0];
720
+ }
721
+ if ((0, import_lodash4.isObject)(options[1])) {
722
+ (0, import_lodash4.merge)(options, options[1]);
723
+ }
724
+ element.arguments = {
725
+ name: options.name,
726
+ isAbstract: options.isAbstract
727
+ };
665
728
  } else {
666
729
  const namespace = getNamespace(name);
667
- decorator.namespaceImport = namespace;
730
+ element.namespaceImport = namespace;
668
731
  const options = {
669
732
  name,
670
- arguments: (((_c = match.groups) == null ? void 0 : _c.args) || "").split(",").map((s) => _lodash.trim.call(void 0, s)).filter(Boolean)
733
+ arguments: (((_d = match.groups) == null ? void 0 : _d.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
671
734
  };
672
- _lodash.merge.call(void 0, decorator, config.fields[namespace], options);
735
+ (0, import_lodash4.merge)(element, config.fields[namespace], options);
673
736
  }
674
- result.push(decorator);
737
+ result.push(element);
675
738
  }
676
739
  return {
677
- result,
740
+ settings: result,
678
741
  documentation: documentationLines.filter(Boolean).join("\\n") || void 0
679
742
  };
680
743
  }
681
744
  function customType(args) {
745
+ var _a;
682
746
  const result = {};
683
747
  let options = parseArgs(args);
684
748
  if (typeof options === "string") {
@@ -687,7 +751,7 @@ function customType(args) {
687
751
  Object.assign(result, options);
688
752
  const namespace = getNamespace(options.name);
689
753
  result.namespace = namespace;
690
- if (options.name.includes(".")) {
754
+ if ((_a = options.name) == null ? void 0 : _a.includes(".")) {
691
755
  result.namespaceImport = namespace;
692
756
  }
693
757
  return result;
@@ -711,7 +775,7 @@ function hideFieldDecorator(match) {
711
775
  result.output = Boolean(options.output);
712
776
  result.input = Boolean(options.input);
713
777
  if (typeof options.match === "string" || Array.isArray(options.match)) {
714
- result.match = _outmatch2.default.call(void 0, options.match, { separator: false });
778
+ result.match = (0, import_outmatch2.default)(options.match, { separator: false });
715
779
  }
716
780
  } else {
717
781
  if (/output:\s*true/.test(match.groups.args)) {
@@ -725,9 +789,13 @@ function hideFieldDecorator(match) {
725
789
  }
726
790
  function parseArgs(string) {
727
791
  try {
728
- return _json52.default.parse(string);
792
+ return import_json52.default.parse(string);
729
793
  } catch (e) {
730
- throw new Error(`Failed to parse: ${string}`);
794
+ try {
795
+ return import_json52.default.parse(`[${string}]`);
796
+ } catch (e2) {
797
+ throw new Error(`Failed to parse: ${string}`);
798
+ }
731
799
  }
732
800
  }
733
801
  function getNamespace(name) {
@@ -749,24 +817,23 @@ function modelData(model, args) {
749
817
  fieldSettings.set(model.name, fieldSettingsValue);
750
818
  for (const field of model.fields) {
751
819
  if (field.documentation) {
752
- const { documentation, result } = createFieldSettings({
820
+ const { documentation, settings } = createObjectSettings({
753
821
  text: field.documentation,
754
822
  config
755
823
  });
756
824
  field.documentation = documentation;
757
- fieldSettingsValue.set(field.name, result);
825
+ fieldSettingsValue.set(field.name, settings);
758
826
  }
759
827
  modelFieldsValue.set(field.name, field);
760
828
  }
761
829
  }
762
830
 
763
831
  // src/handlers/model-output-type.ts
764
-
765
-
766
-
767
-
768
-
769
-
832
+ var import_assert3 = __toModule(require("assert"));
833
+ var import_json53 = __toModule(require("json5"));
834
+ var import_lodash5 = __toModule(require("lodash"));
835
+ var import_pupa2 = __toModule(require("pupa"));
836
+ var import_ts_morph5 = __toModule(require("ts-morph"));
770
837
 
771
838
  // src/helpers/get-output-type-name.ts
772
839
  function getOutputTypeName(name) {
@@ -776,10 +843,10 @@ function getOutputTypeName(name) {
776
843
  // src/handlers/model-output-type.ts
777
844
  var nestjsGraphql = "@nestjs/graphql";
778
845
  function modelOutputType(outputType2, args) {
779
- var _a, _b, _c, _d, _e, _f, _g, _h;
846
+ var _a, _b, _c, _d, _e;
780
847
  const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
781
848
  const model = models.get(outputType2.name);
782
- _assert.ok.call(void 0, model, `Cannot find model by name ${outputType2.name}`);
849
+ (0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
783
850
  const sourceFile = getSourceFile({
784
851
  name: outputType2.name,
785
852
  type: "model"
@@ -788,7 +855,7 @@ function modelOutputType(outputType2, args) {
788
855
  const exportDeclaration = getExportDeclaration(model.name, sourceFileStructure.statements);
789
856
  const importDeclarations = new ImportDeclarationMap();
790
857
  const classStructure = {
791
- kind: _tsmorph.StructureKind.Class,
858
+ kind: import_ts_morph5.StructureKind.Class,
792
859
  isExported: true,
793
860
  name: outputType2.name,
794
861
  decorators: [
@@ -801,18 +868,22 @@ function modelOutputType(outputType2, args) {
801
868
  };
802
869
  sourceFileStructure.statements.push(classStructure);
803
870
  const decorator = (_a = classStructure.decorators) == null ? void 0 : _a.find((d) => d.name === "ObjectType");
804
- _assert.ok.call(void 0, decorator, "ObjectType decorator not found");
805
- const decoratorArgument = ((_b = decorator.arguments) == null ? void 0 : _b[0]) ? _json52.default.parse(decorator.arguments[0]) : {};
871
+ (0, import_assert3.ok)(decorator, "ObjectType decorator not found");
806
872
  if (model.documentation) {
807
- if (!classStructure.leadingTrivia) {
808
- classStructure.leadingTrivia = `/** ${model.documentation} */
873
+ const objectTypeOptions = {};
874
+ const { documentation, settings } = createObjectSettings({
875
+ text: model.documentation,
876
+ config
877
+ });
878
+ if (documentation) {
879
+ if (!classStructure.leadingTrivia) {
880
+ classStructure.leadingTrivia = `/** ${documentation} */
809
881
  `;
882
+ }
883
+ objectTypeOptions.description = documentation;
810
884
  }
811
- decoratorArgument.description = model.documentation;
812
- } else {
813
- delete decoratorArgument.description;
885
+ decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
814
886
  }
815
- decorator.arguments = Object.keys(decoratorArgument).length > 0 ? [_json52.default.stringify(decoratorArgument)] : [];
816
887
  importDeclarations.add("Field", nestjsGraphql);
817
888
  importDeclarations.add("ObjectType", nestjsGraphql);
818
889
  for (const field of outputType2.fields) {
@@ -823,11 +894,11 @@ function modelOutputType(outputType2, args) {
823
894
  fileType = "output";
824
895
  outputTypeName = getOutputTypeName(outputTypeName);
825
896
  }
826
- const modelField = (_c = modelFields.get(model.name)) == null ? void 0 : _c.get(field.name);
827
- const settings = (_d = fieldSettings.get(model.name)) == null ? void 0 : _d.get(field.name);
897
+ const modelField = (_b = modelFields.get(model.name)) == null ? void 0 : _b.get(field.name);
898
+ const settings = (_c = fieldSettings.get(model.name)) == null ? void 0 : _c.get(field.name);
828
899
  const fieldType = settings == null ? void 0 : settings.getFieldType();
829
900
  const propertySettings = settings == null ? void 0 : settings.getPropertyType();
830
- const propertyType = _lodash.castArray.call(void 0, (propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
901
+ const propertyType = (0, import_lodash5.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
831
902
  location,
832
903
  type: outputTypeName
833
904
  }));
@@ -866,19 +937,20 @@ function modelOutputType(outputType2, args) {
866
937
  property.leadingTrivia += `/** ${modelField.documentation} */
867
938
  `;
868
939
  }
869
- (_e = classStructure.properties) == null ? void 0 : _e.push(property);
940
+ classStructure.properties.push(property);
870
941
  if (propertySettings) {
871
942
  importDeclarations.create(__spreadValues({}, propertySettings));
872
943
  }
873
944
  if (settings == null ? void 0 : settings.shouldHideField({ name: outputType2.name, output: true })) {
874
945
  importDeclarations.add("HideField", nestjsGraphql);
875
- (_f = property.decorators) == null ? void 0 : _f.push({ name: "HideField", arguments: [] });
946
+ (_d = property.decorators) == null ? void 0 : _d.push({ name: "HideField", arguments: [] });
876
947
  } else {
877
- (_g = property.decorators) == null ? void 0 : _g.push({
948
+ (0, import_assert3.ok)(property.decorators);
949
+ property.decorators.push({
878
950
  name: "Field",
879
951
  arguments: [
880
952
  `() => ${isList ? `[${graphqlType}]` : graphqlType}`,
881
- _json52.default.stringify({
953
+ import_json53.default.stringify({
882
954
  nullable: Boolean(field.isNullable),
883
955
  defaultValue: ["number", "string", "boolean"].includes(typeof (modelField == null ? void 0 : modelField.default)) ? modelField == null ? void 0 : modelField.default : void 0,
884
956
  description: modelField == null ? void 0 : modelField.documentation
@@ -889,13 +961,22 @@ function modelOutputType(outputType2, args) {
889
961
  if (!options.output || options.kind !== "Decorator") {
890
962
  continue;
891
963
  }
892
- (_h = property.decorators) == null ? void 0 : _h.push({
964
+ property.decorators.push({
893
965
  name: options.name,
894
966
  arguments: options.arguments
895
967
  });
896
- _assert.ok.call(void 0, options.from, "Missed 'from' part in configuration or field setting");
968
+ (0, import_assert3.ok)(options.from, "Missed 'from' part in configuration or field setting");
897
969
  importDeclarations.create(options);
898
970
  }
971
+ for (const decorate of config.decorate) {
972
+ if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
973
+ property.decorators.push({
974
+ name: decorate.name,
975
+ arguments: (_e = decorate.arguments) == null ? void 0 : _e.map((x) => (0, import_pupa2.default)(x, { propertyType }))
976
+ });
977
+ importDeclarations.create(decorate);
978
+ }
979
+ }
899
980
  }
900
981
  eventEmitter.emitSync("ClassProperty", property, { location, isList });
901
982
  }
@@ -915,7 +996,7 @@ function modelOutputType(outputType2, args) {
915
996
  }
916
997
  function getExportDeclaration(name, statements) {
917
998
  return statements.find((structure) => {
918
- return structure.kind === _tsmorph.StructureKind.ExportDeclaration && structure.namedExports.some((o) => (o.alias || o.name) === name);
999
+ return structure.kind === import_ts_morph5.StructureKind.ExportDeclaration && structure.namedExports.some((o) => (o.alias || o.name) === name);
919
1000
  });
920
1001
  }
921
1002
 
@@ -950,13 +1031,13 @@ function isAtomicOperation(name) {
950
1031
  }
951
1032
 
952
1033
  // src/handlers/output-type.ts
953
-
954
-
955
-
956
-
1034
+ var import_assert4 = __toModule(require("assert"));
1035
+ var import_json54 = __toModule(require("json5"));
1036
+ var import_lodash6 = __toModule(require("lodash"));
1037
+ var import_ts_morph6 = __toModule(require("ts-morph"));
957
1038
  var nestjsGraphql2 = "@nestjs/graphql";
958
1039
  function outputType(outputType2, args) {
959
- var _a, _b, _c, _d, _e, _f;
1040
+ var _a, _b, _c, _d;
960
1041
  const { getSourceFile, models, config, eventEmitter, fieldSettings, getModelName: getModelName2 } = args;
961
1042
  const importDeclarations = new ImportDeclarationMap();
962
1043
  const fileType = "output";
@@ -973,7 +1054,7 @@ function outputType(outputType2, args) {
973
1054
  type: fileType
974
1055
  });
975
1056
  const classStructure = {
976
- kind: _tsmorph.StructureKind.Class,
1057
+ kind: import_ts_morph6.StructureKind.Class,
977
1058
  isExported: true,
978
1059
  name: outputType2.name,
979
1060
  decorators: [
@@ -993,7 +1074,7 @@ function outputType(outputType2, args) {
993
1074
  const propertySettings = settings == null ? void 0 : settings.getPropertyType();
994
1075
  const isCustomsApplicable = outputTypeName === ((_b = model == null ? void 0 : model.fields.find((f) => f.name === field.name)) == null ? void 0 : _b.type);
995
1076
  field.outputType.type = outputTypeName;
996
- const propertyType = _lodash.castArray.call(void 0, (propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
1077
+ const propertyType = (0, import_lodash6.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
997
1078
  location,
998
1079
  type: outputTypeName
999
1080
  }));
@@ -1023,11 +1104,12 @@ function outputType(outputType2, args) {
1023
1104
  importDeclarations.add("HideField", nestjsGraphql2);
1024
1105
  (_d = property.decorators) == null ? void 0 : _d.push({ name: "HideField", arguments: [] });
1025
1106
  } else {
1026
- (_e = property.decorators) == null ? void 0 : _e.push({
1107
+ (0, import_assert4.ok)(property.decorators, "Missing property.decorators");
1108
+ property.decorators.push({
1027
1109
  name: "Field",
1028
1110
  arguments: [
1029
1111
  `() => ${isList ? `[${graphqlType}]` : graphqlType}`,
1030
- _json52.default.stringify({
1112
+ import_json54.default.stringify({
1031
1113
  nullable: Boolean(field.isNullable)
1032
1114
  })
1033
1115
  ]
@@ -1037,11 +1119,11 @@ function outputType(outputType2, args) {
1037
1119
  if (!options.output || options.kind !== "Decorator") {
1038
1120
  continue;
1039
1121
  }
1040
- (_f = property.decorators) == null ? void 0 : _f.push({
1122
+ property.decorators.push({
1041
1123
  name: options.name,
1042
1124
  arguments: options.arguments
1043
1125
  });
1044
- _assert.ok.call(void 0, options.from, "Missed 'from' part in configuration or field setting");
1126
+ (0, import_assert4.ok)(options.from, "Missed 'from' part in configuration or field setting");
1045
1127
  importDeclarations.create(options);
1046
1128
  }
1047
1129
  }
@@ -1054,7 +1136,7 @@ function outputType(outputType2, args) {
1054
1136
  }
1055
1137
 
1056
1138
  // src/handlers/purge-output.ts
1057
- var _fs = require('fs');
1139
+ var import_fs = __toModule(require("fs"));
1058
1140
  function purgeOutput(emitter) {
1059
1141
  emitter.on("Begin", begin);
1060
1142
  emitter.on("End", end);
@@ -1073,16 +1155,14 @@ async function end({ project, output }) {
1073
1155
  const directories = (_a = project.getDirectory(output)) == null ? void 0 : _a.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1074
1156
  for (const directory of directories || []) {
1075
1157
  try {
1076
- await _fs.promises.rmdir(directory);
1158
+ await import_fs.promises.rmdir(directory);
1077
1159
  } catch (e) {
1078
1160
  }
1079
1161
  }
1080
1162
  }
1081
1163
 
1082
1164
  // src/handlers/re-export.ts
1083
-
1084
-
1085
-
1165
+ var import_ts_morph7 = __toModule(require("ts-morph"));
1086
1166
  var ReExport;
1087
1167
  (function(ReExport2) {
1088
1168
  ReExport2["None"] = "None";
@@ -1133,14 +1213,14 @@ function beforeGenerateFiles3(args) {
1133
1213
  }
1134
1214
  function getExportDeclaration2(directory, sourceFile) {
1135
1215
  return {
1136
- kind: _tsmorph.StructureKind.ExportDeclaration,
1216
+ kind: import_ts_morph7.StructureKind.ExportDeclaration,
1137
1217
  namedExports: sourceFile.getExportSymbols().map((s) => ({ name: s.getName() })),
1138
1218
  moduleSpecifier: directory.getRelativePathAsModuleSpecifierTo(sourceFile)
1139
1219
  };
1140
1220
  }
1141
1221
 
1142
1222
  // src/handlers/register-enum.ts
1143
-
1223
+ var import_ts_morph8 = __toModule(require("ts-morph"));
1144
1224
  function registerEnum(enumType, args) {
1145
1225
  const { getSourceFile, enums } = args;
1146
1226
  const dataModelEnum = enums[enumType.name];
@@ -1154,7 +1234,7 @@ function registerEnum(enumType, args) {
1154
1234
  moduleSpecifier: "@nestjs/graphql"
1155
1235
  });
1156
1236
  const enumStructure = {
1157
- kind: _tsmorph.StructureKind.Enum,
1237
+ kind: import_ts_morph8.StructureKind.Enum,
1158
1238
  isExported: true,
1159
1239
  name: enumType.name,
1160
1240
  members: enumType.values.map((v) => ({
@@ -1183,18 +1263,21 @@ function warning(message) {
1183
1263
  }
1184
1264
 
1185
1265
  // src/helpers/create-config.ts
1186
- var _filenamify = require('filenamify'); var _filenamify2 = _interopRequireDefault(_filenamify);
1187
- var _flat = require('flat');
1188
-
1266
+ var import_assert5 = __toModule(require("assert"));
1267
+ var import_filenamify = __toModule(require("filenamify"));
1268
+ var import_flat = __toModule(require("flat"));
1269
+ var import_json55 = __toModule(require("json5"));
1270
+ var import_lodash7 = __toModule(require("lodash"));
1271
+ var import_outmatch3 = __toModule(require("outmatch"));
1189
1272
  function createConfig(data) {
1190
1273
  var _a;
1191
- const config = _lodash.merge.call(void 0, {}, _flat.unflatten.call(void 0, data, { delimiter: "_" }));
1274
+ const config = (0, import_lodash7.merge)({}, (0, import_flat.unflatten)(data, { delimiter: "_" }));
1192
1275
  const $warnings = [];
1193
1276
  const configOutputFilePattern = String(config.outputFilePattern || `{model}/{name}.{type}.ts`);
1194
- let outputFilePattern = _filenamify2.default.call(void 0, configOutputFilePattern, {
1277
+ let outputFilePattern = (0, import_filenamify.default)(configOutputFilePattern, {
1195
1278
  replacement: "/"
1196
1279
  }).replace(/\.\./g, "/").replace(/\/+/g, "/");
1197
- outputFilePattern = _lodash.trim.call(void 0, outputFilePattern, "/");
1280
+ outputFilePattern = (0, import_lodash7.trim)(outputFilePattern, "/");
1198
1281
  if (outputFilePattern !== configOutputFilePattern) {
1199
1282
  $warnings.push(`Due to invalid filepath 'outputFilePattern' changed to '${outputFilePattern}'`);
1200
1283
  }
@@ -1215,6 +1298,23 @@ function createConfig(data) {
1215
1298
  };
1216
1299
  return [name, fieldSetting];
1217
1300
  }));
1301
+ const decorate = [];
1302
+ const configDecorate = Object.values(config.decorate || {});
1303
+ for (const element of configDecorate) {
1304
+ if (!element)
1305
+ continue;
1306
+ (0, import_assert5.ok)(element.from && element.name, `Missed 'from' or 'name' part in configuration for decorate`);
1307
+ decorate.push({
1308
+ isMatchField: (0, import_outmatch3.default)(element.field, { separator: false }),
1309
+ isMatchType: (0, import_outmatch3.default)(element.type, { separator: false }),
1310
+ from: element.from,
1311
+ name: element.name,
1312
+ namedImport: toBoolean(element.namedImport),
1313
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
1314
+ namespaceImport: element.namespaceImport,
1315
+ arguments: element.arguments ? import_json55.default.parse(element.arguments) : void 0
1316
+ });
1317
+ }
1218
1318
  return {
1219
1319
  outputFilePattern,
1220
1320
  tsConfigFilePath: void 0,
@@ -1227,7 +1327,8 @@ function createConfig(data) {
1227
1327
  fields,
1228
1328
  purgeOutput: toBoolean(config.purgeOutput),
1229
1329
  useInputType: createUseInputType(config.useInputType),
1230
- noTypeId: toBoolean(config.noTypeId)
1330
+ noTypeId: toBoolean(config.noTypeId),
1331
+ decorate
1231
1332
  };
1232
1333
  }
1233
1334
  function createUseInputType(data) {
@@ -1256,19 +1357,19 @@ function toBoolean(value) {
1256
1357
  }
1257
1358
 
1258
1359
  // src/helpers/generate-file-name.ts
1259
-
1260
- var _pluralize = require('pluralize'); var _pluralize2 = _interopRequireDefault(_pluralize);
1261
- var _pupa = require('pupa'); var _pupa2 = _interopRequireDefault(_pupa);
1360
+ var import_lodash8 = __toModule(require("lodash"));
1361
+ var import_pluralize = __toModule(require("pluralize"));
1362
+ var import_pupa3 = __toModule(require("pupa"));
1262
1363
  function generateFileName(args) {
1263
1364
  const { template, type, name, getModelName: getModelName2 } = args;
1264
- return _pupa2.default.call(void 0, template, {
1365
+ return (0, import_pupa3.default)(template, {
1265
1366
  type,
1266
1367
  get model() {
1267
1368
  const result = getModelName2(name) || "prisma";
1268
- return _lodash.kebabCase.call(void 0, result);
1369
+ return (0, import_lodash8.kebabCase)(result);
1269
1370
  },
1270
1371
  get name() {
1271
- let result = _lodash.kebabCase.call(void 0, name);
1372
+ let result = (0, import_lodash8.kebabCase)(name);
1272
1373
  for (const suffix of ["input", "args", "enum"]) {
1273
1374
  const ending = `-${suffix}`;
1274
1375
  if (type === suffix && result.endsWith(ending)) {
@@ -1279,7 +1380,7 @@ function generateFileName(args) {
1279
1380
  },
1280
1381
  plural: {
1281
1382
  get type() {
1282
- return _pluralize2.default.call(void 0, type);
1383
+ return (0, import_pluralize.default)(type);
1283
1384
  }
1284
1385
  }
1285
1386
  });
@@ -1302,9 +1403,9 @@ function factoryGetSourceFile(args) {
1302
1403
  }
1303
1404
 
1304
1405
  // src/helpers/get-model-name.ts
1305
-
1406
+ var import_lodash9 = __toModule(require("lodash"));
1306
1407
  function createGetModelName(modelNames) {
1307
- return _lodash.memoize.call(void 0, tryGetName);
1408
+ return (0, import_lodash9.memoize)(tryGetName);
1308
1409
  function tryGetName(name) {
1309
1410
  return getModelName({ modelNames, name });
1310
1411
  }
@@ -1333,6 +1434,11 @@ function getModelName(args) {
1333
1434
  return test;
1334
1435
  }
1335
1436
  }
1437
+ if (name.slice(-19) === "CompoundUniqueInput") {
1438
+ const test = name.slice(0, -19);
1439
+ const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
1440
+ return (0, import_lodash9.first)(models);
1441
+ }
1336
1442
  if (name.slice(-5) === "Count") {
1337
1443
  const test = name.slice(0, -5);
1338
1444
  if (modelNames.includes(test)) {
@@ -1416,8 +1522,8 @@ async function generate(args) {
1416
1522
  var _a;
1417
1523
  const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
1418
1524
  const generatorOutputValue = (_a = generator.output) == null ? void 0 : _a.value;
1419
- _assert.ok.call(void 0, generatorOutputValue, "Missing generator configuration: output");
1420
- const eventEmitter = new (0, _awaiteventemitter2.default)();
1525
+ (0, import_assert6.ok)(generatorOutputValue, "Missing generator configuration: output");
1526
+ const eventEmitter = new import_await_event_emitter.default();
1421
1527
  eventEmitter.on("Warning", warning);
1422
1528
  eventEmitter.on("Model", modelData);
1423
1529
  eventEmitter.on("EnumType", registerEnum);
@@ -1432,12 +1538,12 @@ async function generate(args) {
1432
1538
  for (const message of config.$warnings) {
1433
1539
  eventEmitter.emitSync("Warning", message);
1434
1540
  }
1435
- const project = new (0, _tsmorph.Project)({
1541
+ const project = new import_ts_morph9.Project({
1436
1542
  tsConfigFilePath: config.tsConfigFilePath,
1437
1543
  skipAddingFilesFromTsConfig: true,
1438
1544
  skipLoadingLibFiles: !config.emitCompiled,
1439
1545
  manipulationSettings: {
1440
- quoteKind: _tsmorph.QuoteKind.Single
1546
+ quoteKind: import_ts_morph9.QuoteKind.Single
1441
1547
  }
1442
1548
  });
1443
1549
  if (!skipAddOutputSourceFiles) {
@@ -1479,8 +1585,8 @@ async function generate(args) {
1479
1585
  getSourceFile,
1480
1586
  eventEmitter,
1481
1587
  typeNames: new Set(),
1482
- enums: _lodash.mapKeys.call(void 0, datamodel.enums, (x) => x.name),
1483
- getModelName: createGetModelName(modelNames),
1588
+ enums: (0, import_lodash10.mapKeys)(datamodel.enums, (x) => x.name),
1589
+ getModelName: getModelName2,
1484
1590
  removeTypes
1485
1591
  };
1486
1592
  if (connectCallback) {
@@ -1533,7 +1639,7 @@ async function generate(args) {
1533
1639
  }
1534
1640
 
1535
1641
  // src/index.ts
1536
- _generatorhelper.generatorHandler.call(void 0, {
1642
+ (0, import_generator_helper.generatorHandler)({
1537
1643
  async onGenerate(options) {
1538
1644
  await generate(options);
1539
1645
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "13.0.0",
3
+ "version": "14.2.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",
@@ -34,9 +34,9 @@
34
34
  "eslint:fix": "npm run eslint -- --fix",
35
35
  "build": "sh Taskfile bundle",
36
36
  "prisma:g": "node node_modules/prisma/build/index.js generate",
37
- "format": "npx prettier src --write",
38
- "regen": "rm -rf src/@generated && npm run prisma:g && npm run eslint:fix && npm run format",
39
- "example": "ts-node-dev src/example/main.ts",
37
+ "format": "npx prettier ./@generated --write",
38
+ "regen": "rm -rf @generated && npm run prisma:g && npm run format",
39
+ "example": "ts-node-dev example/main.ts",
40
40
  "clean_cache": "rm -rf node_modules/.cache",
41
41
  "compatibilty_check": "sh Taskfile compatibilty_check",
42
42
  "commit": "cz"
@@ -47,44 +47,41 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "@prisma/generator-helper": "^2.30.0",
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",
54
54
  "get-relative-path": "^1.0.2",
55
55
  "json5": "^2.2.0",
56
56
  "lodash": "^4.17.21",
57
- "matcher": "^4.0.0",
58
57
  "outmatch": "^0.7.0",
59
58
  "pluralize": "^8.0.0",
60
59
  "pupa": "2.X",
61
60
  "ts-morph": ">=11 <=12"
62
61
  },
63
- "peerDependencies": {
64
- "@prisma/client": ">=2.16"
65
- },
62
+ "peerDependencies": {},
66
63
  "devDependencies": {
67
64
  "@arkweid/lefthook": "0.7.6",
68
65
  "@commitlint/cli": "^13.1.0",
69
66
  "@commitlint/config-conventional": "^13.1.0",
70
67
  "@nestjs/common": "^8.0.6",
71
68
  "@nestjs/core": "^8.0.6",
72
- "@nestjs/graphql": "^9.0.2",
69
+ "@nestjs/graphql": "^9.0.4",
73
70
  "@nestjs/platform-express": "^8.0.6",
74
- "@paljs/plugins": "^3.8.2",
75
- "@prisma/client": "^2.30.0",
76
- "@semantic-release/changelog": "^5.0.1",
77
- "@semantic-release/git": "^9.0.0",
71
+ "@paljs/plugins": "^4.0.8",
72
+ "@prisma/client": "^3.1.1",
73
+ "@semantic-release/changelog": "^6.0.0",
74
+ "@semantic-release/git": "^10.0.0",
78
75
  "@types/find-cache-dir": "^3.2.1",
79
76
  "@types/flat": "^5.0.2",
80
- "@types/lodash": "^4.14.172",
77
+ "@types/lodash": "^4.14.173",
81
78
  "@types/mocha": "^9.0.0",
82
- "@types/node": "^16.7.4",
79
+ "@types/node": "^16.9.6",
83
80
  "@types/pluralize": "^0.0.29",
84
- "@typescript-eslint/eslint-plugin": "^4.29.3",
85
- "@typescript-eslint/parser": "^4.29.3",
81
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
82
+ "@typescript-eslint/parser": "^4.31.2",
86
83
  "apollo-server-express": "^3.3.0",
87
- "c8": "^7.8.0",
84
+ "c8": "^7.9.0",
88
85
  "class-transformer": "^0.4.0",
89
86
  "class-validator": "^0.13.1",
90
87
  "commitizen": "^4.2.4",
@@ -95,35 +92,35 @@
95
92
  "eslint-plugin-etc": "^1.5.4",
96
93
  "eslint-plugin-import": "^2.24.2",
97
94
  "eslint-plugin-only-warn": "^1.0.3",
98
- "eslint-plugin-prettier": "^3.4.1",
95
+ "eslint-plugin-prettier": "^4.0.0",
99
96
  "eslint-plugin-promise": "^5.1.0",
100
- "eslint-plugin-regexp": "^1.0.0",
97
+ "eslint-plugin-regexp": "^1.1.0",
101
98
  "eslint-plugin-simple-import-sort": "^7.0.0",
102
99
  "eslint-plugin-sonarjs": "^0.10.0",
103
100
  "eslint-plugin-sort-class-members": "^1.11.0",
104
- "eslint-plugin-total-functions": "^4.9.0",
105
- "eslint-plugin-unicorn": "^35.0.0",
101
+ "eslint-plugin-total-functions": "^4.10.1",
102
+ "eslint-plugin-unicorn": "^36.0.0",
106
103
  "eslint-plugin-wix-editor": "^3.3.0",
107
- "expect": "^27.1.0",
108
- "find-cache-dir": "^3.3.1",
104
+ "expect": "^27.2.1",
105
+ "find-cache-dir": "^3.3.2",
109
106
  "git-branch-is": "^4.0.0",
110
- "graphql": "^15.5.1",
111
- "graphql-scalars": "^1.10.0",
107
+ "graphql": "^15.6.0",
108
+ "graphql-scalars": "^1.10.1",
112
109
  "graphql-type-json": "^0.3.2",
113
- "mocha": "^9.1.0",
110
+ "mocha": "^9.1.1",
114
111
  "ololog": "^1.1.175",
115
112
  "precise-commits": "^1.0.2",
116
- "prettier": "^2.3.2",
117
- "prisma": "^2.30.0",
113
+ "prettier": "^2.4.1",
114
+ "prisma": "^3.1.1",
118
115
  "prisma-graphql-type-decimal": "^1.0.0",
119
116
  "reflect-metadata": "^0.1.13",
120
117
  "rxjs": "^7.3.0",
121
- "semantic-release": "^17.4.7",
118
+ "semantic-release": "^18.0.0",
122
119
  "simplytyped": "^3.3.0",
123
120
  "ts-node": "^10.2.1",
124
121
  "ts-node-dev": "^1.1.8",
125
122
  "tslib": "^2.3.1",
126
- "typescript": "^4.4.2",
123
+ "typescript": "^4.4.3",
127
124
  "watchexec-bin": "^1.0.0"
128
125
  }
129
126
  }