@pegasusheavy/nestjs-prisma-graphql 1.2.2 → 1.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.
package/dist/generate.js CHANGED
@@ -1,17 +1,23 @@
1
- import { ok } from 'assert';
2
- import { createRequire } from 'module';
3
1
  import { memoize, mapKeys, merge, trim, castArray, uniqWith, isEqual, countBy, startCase, camelCase, keyBy, remove, partition, kebabCase, isObject, omit, cloneDeep } from 'lodash-es';
2
+ import { createRequire } from 'module';
4
3
  import { Project, QuoteKind, StructureKind } from 'ts-morph';
4
+ import { ok as ok$1 } from 'assert';
5
5
  import JSON52 from 'json5';
6
6
  import pupa from 'pupa';
7
7
  import getRelativePath from 'get-relative-path';
8
8
  import outmatch2 from 'outmatch';
9
- import { existsSync, rmdirSync } from 'fs';
9
+ import { existsSync, rmdirSync as rmdirSync$1 } from 'fs';
10
10
  import { unflatten } from 'flat';
11
11
  import filenamify from 'filenamify';
12
12
  import pluralize from 'pluralize';
13
13
 
14
14
  // src/generate.ts
15
+ function ok(value, message) {
16
+ ok$1(
17
+ value,
18
+ message
19
+ );
20
+ }
15
21
 
16
22
  // src/helpers/is-many-and-return.ts
17
23
  function isManyAndReturnOutputType(name) {
@@ -30,8 +36,10 @@ function argsType(field, args) {
30
36
  if (["queryRaw", "executeRaw"].includes(field.name)) {
31
37
  return;
32
38
  }
33
- if (isManyAndReturnOutputType(field.name)) return;
34
- const { eventEmitter, typeNames, getModelName: getModelName2 } = args;
39
+ if (isManyAndReturnOutputType(field.name)) {
40
+ return;
41
+ }
42
+ const { eventEmitter, getModelName: getModelName2, typeNames } = args;
35
43
  let className = pascalCase(`${field.name}Args`);
36
44
  const modelName = getModelName2(className) ?? "";
37
45
  switch (className) {
@@ -46,8 +54,8 @@ function argsType(field, args) {
46
54
  }
47
55
  const inputType2 = {
48
56
  constraints: { maxNumFields: null, minNumFields: null },
49
- name: className,
50
- fields: [...field.args]
57
+ fields: [...field.args],
58
+ name: className
51
59
  };
52
60
  if (!field.args.some((x) => x.name === "_count") && [`${modelName}AggregateArgs`, `${modelName}GroupByArgs`].includes(className)) {
53
61
  const names = ["Count", "Avg", "Sum", "Min", "Max"];
@@ -62,24 +70,24 @@ function argsType(field, args) {
62
70
  continue;
63
71
  }
64
72
  inputType2.fields.push({
65
- name: `_${name.toLowerCase()}`,
66
- isRequired: false,
67
- isNullable: true,
68
73
  inputTypes: [
69
74
  {
75
+ isList: false,
70
76
  location: "inputObjectTypes",
71
- type: `${modelName}${name}AggregateInput`,
72
- isList: false
77
+ type: `${modelName}${name}AggregateInput`
73
78
  }
74
- ]
79
+ ],
80
+ isNullable: true,
81
+ isRequired: false,
82
+ name: `_${name.toLowerCase()}`
75
83
  });
76
84
  }
77
85
  }
78
86
  eventEmitter.emitSync("InputType", {
79
87
  ...args,
80
- inputType: inputType2,
88
+ classDecoratorName: "ArgsType",
81
89
  fileType: "args",
82
- classDecoratorName: "ArgsType"
90
+ inputType: inputType2
83
91
  });
84
92
  }
85
93
 
@@ -104,7 +112,7 @@ function beforeGenerateField(field) {
104
112
  if (fieldInput.location !== "inputObjectTypes") {
105
113
  continue;
106
114
  }
107
- const fieldInputType = String(fieldInput.type);
115
+ const fieldInputType = fieldInput.type;
108
116
  if (isContainBogus(fieldInputType)) {
109
117
  fieldInput.type = replaceBogus(fieldInputType);
110
118
  }
@@ -195,32 +203,98 @@ function createAggregateInput(args) {
195
203
  const className = `${outputType2.name}Input`;
196
204
  const inputType2 = {
197
205
  constraints: { maxNumFields: null, minNumFields: null },
198
- name: className,
199
206
  fields: outputType2.fields.map((x) => ({
200
- name: x.name,
201
- isNullable: x.isNullable ?? true,
202
- isRequired: false,
203
207
  inputTypes: [
204
208
  {
205
209
  isList: false,
206
- type: "true",
207
- location: "scalar"
210
+ location: "scalar",
211
+ type: "true"
208
212
  }
209
- ]
210
- }))
213
+ ],
214
+ isNullable: x.isNullable ?? true,
215
+ isRequired: false,
216
+ name: x.name
217
+ })),
218
+ name: className
211
219
  };
212
220
  eventEmitter.emitSync("InputType", {
213
221
  ...args,
214
- inputType: inputType2,
222
+ classDecoratorName: "InputType",
215
223
  fileType: "input",
216
- classDecoratorName: "InputType"
224
+ inputType: inputType2
225
+ });
226
+ }
227
+
228
+ // src/handlers/decimal-helpers.ts
229
+ function generateDecimalHelpers(args) {
230
+ const { output, project } = args;
231
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
232
+ const sourceFile = rootDirectory.createSourceFile("decimal-helpers.ts", void 0, {
233
+ overwrite: true
234
+ });
235
+ const helpersCode = `/**
236
+ * Decimal Helpers for Prisma GraphQL
237
+ *
238
+ * This module provides utilities for transforming Decimal values
239
+ * between GraphQL and Prisma, compatible with Prisma 7+.
240
+ *
241
+ * These functions replace the prisma-graphql-type-decimal package
242
+ * which is incompatible with Prisma 7's new client structure.
243
+ */
244
+
245
+ import Decimal from 'decimal.js';
246
+
247
+ /**
248
+ * Reconstruct a Decimal from a serialized object.
249
+ * Prisma serializes Decimals as objects with d, e, s properties.
250
+ */
251
+ function createDecimalFromObject(object: { d: number[]; e: number; s: number }): Decimal {
252
+ return Object.create(Decimal.prototype, {
253
+ d: { value: object.d },
254
+ e: { value: object.e },
255
+ s: { value: object.s },
217
256
  });
218
257
  }
258
+
259
+ /**
260
+ * Transform input values to Decimal instances.
261
+ * Used as a class-transformer Transform decorator argument.
262
+ *
263
+ * @param params - The transform parameters from class-transformer
264
+ * @returns The transformed Decimal or array of Decimals
265
+ */
266
+ export function transformToDecimal({ value }: { value: unknown }): Decimal | Decimal[] | null | undefined {
267
+ if (value == null) return value as null | undefined;
268
+
269
+ if (Array.isArray(value)) {
270
+ return value.map((v) => {
271
+ if (v instanceof Decimal) return v;
272
+ if (typeof v === 'object' && v !== null && 'd' in v && 'e' in v && 's' in v) {
273
+ return createDecimalFromObject(v as { d: number[]; e: number; s: number });
274
+ }
275
+ return new Decimal(v as string | number);
276
+ });
277
+ }
278
+
279
+ if (value instanceof Decimal) return value;
280
+ if (typeof value === 'object' && value !== null && 'd' in value && 'e' in value && 's' in value) {
281
+ return createDecimalFromObject(value as { d: number[]; e: number; s: number });
282
+ }
283
+ return new Decimal(value as string | number);
284
+ }
285
+
286
+ /**
287
+ * Re-export Decimal class for convenience
288
+ */
289
+ export { Decimal };
290
+ `;
291
+ sourceFile.addStatements(helpersCode);
292
+ }
219
293
  function emitSingle(emitter) {
220
294
  emitter.on("ClassProperty", classProperty);
221
295
  }
222
296
  function classProperty(property, eventArguments) {
223
- const { location, isList, propertyType } = eventArguments;
297
+ const { isList, location, propertyType } = eventArguments;
224
298
  if (["inputObjectTypes", "outputObjectTypes"].includes(location) && !isList) {
225
299
  const [safeTypes, instanceofTypes] = partition(
226
300
  propertyType,
@@ -233,7 +307,7 @@ function classProperty(property, eventArguments) {
233
307
  var ImportDeclarationMap = class extends Map {
234
308
  add(name, value, isTypeOnly) {
235
309
  if (!this.has(name)) {
236
- const structure = typeof value === "string" ? { moduleSpecifier: value, namedImports: [{ name }], isTypeOnly } : value;
310
+ const structure = typeof value === "string" ? { isTypeOnly, moduleSpecifier: value, namedImports: [{ name }] } : value;
237
311
  this.set(name, structure);
238
312
  }
239
313
  }
@@ -244,43 +318,46 @@ var ImportDeclarationMap = class extends Map {
244
318
  const typeOnlyKey = `type:${name}`;
245
319
  if (!this.has(typeOnlyKey) && !this.has(name)) {
246
320
  this.set(typeOnlyKey, {
321
+ isTypeOnly: true,
247
322
  moduleSpecifier,
248
- namedImports: [{ name }],
249
- isTypeOnly: true
323
+ namedImports: [{ name }]
250
324
  });
251
325
  }
252
326
  }
253
327
  create(args) {
254
- const { from, defaultImport, namespaceImport, namedImport, isTypeOnly } = args;
255
- let name = args.name;
328
+ const { defaultImport, from, isTypeOnly, namedImport, namespaceImport } = args;
329
+ let { name } = args;
256
330
  const value = {
331
+ defaultImport: void 0,
332
+ isTypeOnly,
257
333
  moduleSpecifier: from,
258
334
  namedImports: [],
259
- defaultImport: void 0,
260
- namespaceImport: void 0,
261
- isTypeOnly
335
+ namespaceImport: void 0
262
336
  };
263
- if (namedImport === true && namespaceImport) {
337
+ if (namedImport === true && namespaceImport !== void 0) {
264
338
  value.namedImports = [{ name: namespaceImport }];
265
339
  name = namespaceImport;
266
- } else if (defaultImport) {
340
+ } else if (defaultImport === void 0) {
341
+ if (namespaceImport === void 0) {
342
+ value.namedImports = [{ name }];
343
+ } else {
344
+ value.namespaceImport = namespaceImport;
345
+ name = namespaceImport;
346
+ }
347
+ } else {
267
348
  value.defaultImport = defaultImport === true ? name : defaultImport;
268
349
  name = value.defaultImport;
269
- } else if (namespaceImport) {
270
- value.namespaceImport = namespaceImport;
271
- name = namespaceImport;
272
- } else {
273
- value.namedImports = [{ name }];
274
350
  }
275
- const key = isTypeOnly ? `type:${name}` : name;
276
- if (!this.has(key)) {
277
- this.set(key, value);
351
+ const key = isTypeOnly === true ? `type:${name}` : name;
352
+ if (this.has(key)) {
353
+ return;
278
354
  }
355
+ this.set(key, value);
279
356
  }
280
357
  *toStatements() {
281
358
  const iterator = this.values();
282
359
  let result = iterator.next();
283
- while (result.value) {
360
+ while (result.value !== void 0) {
284
361
  yield {
285
362
  ...result.value,
286
363
  kind: StructureKind.ImportDeclaration
@@ -311,8 +388,8 @@ async function generateFiles(args) {
311
388
  for (const decorator of property.decorators ?? []) {
312
389
  const fullName = classDeclaration?.getProperty(property.name)?.getDecorator(decorator.name)?.getFullName();
313
390
  ok(
314
- fullName,
315
- `Cannot get full name of decorator of class ${statement.name}`
391
+ fullName !== void 0,
392
+ `Cannot get full name of decorator of class ${String(statement.name)}`
316
393
  );
317
394
  decorator.name = fullName;
318
395
  }
@@ -375,6 +452,20 @@ async function generateFiles(args) {
375
452
  statements: [...imports.toStatements(), ...enums, ...classes]
376
453
  });
377
454
  }
455
+ const sourceFiles = project.getSourceFiles();
456
+ const sourceFileCount = sourceFiles.length;
457
+ const globalConsole2 = globalThis.console;
458
+ const logMessage = (msg) => {
459
+ globalConsole2.log(msg);
460
+ };
461
+ logMessage(
462
+ `nestjs-prisma-graphql: saving ${String(sourceFileCount)} source files to ${output}`
463
+ );
464
+ if (sourceFileCount === 0) {
465
+ throw new Error(
466
+ "nestjs-prisma-graphql: project has 0 source files \u2014 nothing to write"
467
+ );
468
+ }
378
469
  if (config.emitCompiled) {
379
470
  project.compilerOptions.set({
380
471
  declaration: true,
@@ -390,7 +481,21 @@ async function generateFiles(args) {
390
481
  eventEmitter.emitSync("Warning", errors);
391
482
  }
392
483
  } else {
393
- await project.save();
484
+ const BATCH_SIZE = 100;
485
+ if (sourceFileCount > BATCH_SIZE) {
486
+ logMessage(
487
+ `nestjs-prisma-graphql: using batched save for large schema (${String(sourceFileCount)} files)`
488
+ );
489
+ for (let i = 0; i < sourceFileCount; i += BATCH_SIZE) {
490
+ const batch = sourceFiles.slice(i, i + BATCH_SIZE);
491
+ logMessage(
492
+ `nestjs-prisma-graphql: saving batch ${String(Math.floor(i / BATCH_SIZE) + 1)}/${String(Math.ceil(sourceFileCount / BATCH_SIZE))} (${String(batch.length)} files)`
493
+ );
494
+ await Promise.all(batch.map(async (sf) => await sf.save()));
495
+ }
496
+ } else {
497
+ await project.save();
498
+ }
394
499
  }
395
500
  }
396
501
 
@@ -406,17 +511,23 @@ function fileTypeByLocation(fieldLocation) {
406
511
  case "enumTypes": {
407
512
  return "enum";
408
513
  }
514
+ case "fieldRefTypes":
515
+ case "scalar":
516
+ default: {
517
+ return "object";
518
+ }
409
519
  }
410
- return "object";
411
520
  }
412
521
  function relativePath(from, to) {
413
- if (!from.startsWith("/")) {
414
- from = `/${from}`;
522
+ let fromPath = from;
523
+ let toPath = to;
524
+ if (!fromPath.startsWith("/")) {
525
+ fromPath = `/${fromPath}`;
415
526
  }
416
- if (!to.startsWith("/")) {
417
- to = `/${to}`;
527
+ if (!toPath.startsWith("/")) {
528
+ toPath = `/${toPath}`;
418
529
  }
419
- let result = getRelativePath(from, to);
530
+ let result = getRelativePath(fromPath, toPath);
420
531
  if (!result.startsWith(".")) {
421
532
  result = `./${result}`;
422
533
  }
@@ -485,7 +596,7 @@ function getGraphqlImport(args) {
485
596
  }
486
597
  function getGraphqlInputType(inputTypes, pattern) {
487
598
  let result;
488
- inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(String(t.type)));
599
+ inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(t.type));
489
600
  inputTypes = uniqWith(inputTypes, isEqual);
490
601
  if (inputTypes.length === 1) {
491
602
  return inputTypes[0];
@@ -498,46 +609,44 @@ function getGraphqlInputType(inputTypes, pattern) {
498
609
  return result;
499
610
  }
500
611
  }
501
- if (pattern) {
612
+ if (pattern !== null && pattern !== void 0 && pattern.length > 0) {
502
613
  if (pattern.startsWith("matcher:") || pattern.startsWith("match:")) {
503
614
  const { 1: patternValue } = pattern.split(":", 2);
504
615
  const isMatch = outmatch2(patternValue, { separator: false });
505
- result = inputTypes.find((x) => isMatch(String(x.type)));
506
- if (result) {
616
+ result = inputTypes.find((x) => isMatch(x.type));
617
+ if (result !== void 0) {
507
618
  return result;
508
619
  }
509
620
  }
510
- result = inputTypes.find((x) => String(x.type).includes(pattern));
511
- if (result) {
621
+ result = inputTypes.find((x) => x.type.includes(pattern));
622
+ if (result !== void 0) {
512
623
  return result;
513
624
  }
514
625
  }
515
626
  result = inputTypes.find((x) => x.location === "inputObjectTypes");
516
- if (result) {
627
+ if (result !== void 0) {
517
628
  return result;
518
629
  }
519
- if (countTypes.enumTypes && countTypes.scalar && inputTypes.some((x) => x.type === "Json" && x.location === "scalar")) {
630
+ if ((countTypes.enumTypes ?? 0) > 0 && (countTypes.scalar ?? 0) > 0 && inputTypes.some((x) => x.type === "Json" && x.location === "scalar")) {
520
631
  result = inputTypes.find((x) => x.type === "Json" && x.location === "scalar");
521
- if (result) {
632
+ if (result !== void 0) {
522
633
  return result;
523
634
  }
524
635
  }
525
- if ((countTypes.scalar >= 1 || countTypes.enumTypes >= 1) && countTypes.fieldRefTypes === 1) {
636
+ if (((countTypes.scalar ?? 0) >= 1 || (countTypes.enumTypes ?? 0) >= 1) && countTypes.fieldRefTypes === 1) {
526
637
  result = inputTypes.find(
527
638
  (x) => (x.location === "scalar" || x.location === "enumTypes") && x.isList
528
639
  );
529
- if (result) {
640
+ if (result !== void 0) {
530
641
  return result;
531
642
  }
532
- result = inputTypes.find(
533
- (x) => x.location === "scalar" || x.location === "enumTypes"
534
- );
535
- if (result) {
643
+ result = inputTypes.find((x) => x.location === "scalar" || x.location === "enumTypes");
644
+ if (result !== void 0) {
536
645
  return result;
537
646
  }
538
647
  }
539
648
  throw new TypeError(
540
- `Cannot get matching input type from ${inputTypes.map((x) => x.type).join(", ") || "zero length inputTypes"}`
649
+ `Cannot get matching input type from ${inputTypes.length > 0 ? inputTypes.map((x) => x.type).join(", ") : "zero length inputTypes"}`
541
650
  );
542
651
  }
543
652
 
@@ -578,7 +687,7 @@ function getPropertyType(args) {
578
687
  return [type];
579
688
  }
580
689
  if (location === "enumTypes") {
581
- const enumType = "`${" + type + "}`";
690
+ const enumType = `\`\${${type}}\``;
582
691
  return [enumType];
583
692
  }
584
693
  if (location === "scalar") {
@@ -599,8 +708,8 @@ function getWhereUniqueAtLeastKeys(model) {
599
708
  return names;
600
709
  }
601
710
  function createFieldName(args) {
602
- const { name, fields } = args;
603
- return name || fields.join("_");
711
+ const { fields, name } = args;
712
+ return name !== null && name !== void 0 && name.length > 0 ? name : fields.join("_");
604
713
  }
605
714
 
606
715
  // src/helpers/is-where-unique-input-type.ts
@@ -609,29 +718,28 @@ function isWhereUniqueInputType(name) {
609
718
  }
610
719
  function propertyStructure(args) {
611
720
  const {
721
+ hasExclamationToken,
722
+ hasQuestionToken,
723
+ isList,
612
724
  isNullable,
613
- propertyType,
614
725
  name,
615
- isList,
616
- hasQuestionToken,
617
- hasExclamationToken
726
+ propertyType
618
727
  } = args;
619
- const type = propertyType.map((type2) => isList ? `Array<${type2}>` : type2).join(" | ");
728
+ const typeString = propertyType.map((typeItem) => isList ? `Array<${typeItem}>` : typeItem).join(" | ");
620
729
  return {
730
+ decorators: [],
731
+ hasExclamationToken: hasExclamationToken ?? !isNullable,
732
+ hasQuestionToken: hasQuestionToken ?? isNullable,
621
733
  kind: StructureKind.Property,
734
+ leadingTrivia: "\n",
622
735
  name,
623
- type,
624
- hasQuestionToken: hasQuestionToken ?? isNullable,
625
- hasExclamationToken: hasExclamationToken ?? !isNullable,
626
- decorators: [],
627
- leadingTrivia: "\n"
736
+ type: typeString
628
737
  };
629
738
  }
630
739
 
631
740
  // src/handlers/input-type.ts
632
741
  function inputType(args) {
633
742
  const {
634
- circularDependencies,
635
743
  classDecoratorName,
636
744
  classTransformerTypeModels,
637
745
  config,
@@ -640,41 +748,41 @@ function inputType(args) {
640
748
  fileType,
641
749
  getModelName: getModelName2,
642
750
  getSourceFile,
643
- inputType: inputType2,
751
+ inputType: inputTypeArg,
644
752
  models,
645
753
  output,
646
754
  removeTypes,
647
755
  typeNames
648
756
  } = args;
649
- typeNames.add(inputType2.name);
757
+ typeNames.add(inputTypeArg.name);
650
758
  const importDeclarations = new ImportDeclarationMap();
651
759
  const sourceFile = getSourceFile({
652
- name: inputType2.name,
760
+ name: inputTypeArg.name,
653
761
  type: fileType
654
762
  });
655
763
  const classStructure = {
656
- kind: StructureKind.Class,
657
- isExported: true,
658
- name: inputType2.name,
659
764
  decorators: [
660
765
  {
661
- name: classDecoratorName,
662
- arguments: []
766
+ arguments: [],
767
+ name: classDecoratorName
663
768
  }
664
769
  ],
770
+ isExported: true,
771
+ kind: StructureKind.Class,
772
+ name: inputTypeArg.name,
665
773
  properties: []
666
774
  };
667
- const modelName = getModelName2(inputType2.name) ?? "";
775
+ const modelName = getModelName2(inputTypeArg.name) ?? "";
668
776
  const model = models.get(modelName);
669
777
  const modelFieldSettings = model && fieldSettings.get(model.name);
670
778
  const moduleSpecifier = "@nestjs/graphql";
671
779
  const lazyTypes = /* @__PURE__ */ new Set();
672
780
  importDeclarations.set("Field", {
673
- namedImports: [{ name: "Field" }],
674
- moduleSpecifier
781
+ moduleSpecifier,
782
+ namedImports: [{ name: "Field" }]
675
783
  }).set(classDecoratorName, {
676
- namedImports: [{ name: classDecoratorName }],
677
- moduleSpecifier
784
+ moduleSpecifier,
785
+ namedImports: [{ name: classDecoratorName }]
678
786
  });
679
787
  if (config.esmCompatible) {
680
788
  const typeRegistryPath = relativePath(
@@ -685,11 +793,11 @@ function inputType(args) {
685
793
  importDeclarations.add("getType", typeRegistryPath);
686
794
  }
687
795
  const useInputType = config.useInputType.find(
688
- (x) => inputType2.name.includes(x.typeName)
796
+ (x) => inputTypeArg.name.includes(x.typeName)
689
797
  );
690
- const isWhereUnique = isWhereUniqueInputType(inputType2.name);
691
- for (const field of inputType2.fields) {
692
- field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(String(t.type)));
798
+ const isWhereUnique = isWhereUniqueInputType(inputTypeArg.name);
799
+ for (const field of inputTypeArg.fields) {
800
+ field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(t.type));
693
801
  eventEmitter.emitSync(BeforeGenerateField, field, args);
694
802
  const { inputTypes, isRequired, name } = field;
695
803
  if (inputTypes.length === 0) {
@@ -698,34 +806,36 @@ function inputType(args) {
698
806
  const usePattern = useInputType?.ALL ?? useInputType?.[name];
699
807
  const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
700
808
  const { isList, location, type } = graphqlInputType;
701
- const typeName = String(type);
809
+ const typeName = type;
702
810
  const settings = modelFieldSettings?.get(name);
703
811
  const propertySettings = settings?.getPropertyType({
704
- name: inputType2.name,
705
- input: true
812
+ input: true,
813
+ name: inputTypeArg.name
706
814
  });
707
815
  const modelField = model?.fields.find((f) => f.name === name);
708
816
  const isCustomsApplicable = typeName === modelField?.type;
709
817
  const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
710
818
  const whereUniqueInputTypeValue = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((n) => `'${n}'`).join(" | ")}>`;
711
819
  const propertyType = castArray(
712
- propertySettings?.name ?? (whereUniqueInputTypeValue || getPropertyType({
820
+ propertySettings?.name ?? whereUniqueInputTypeValue ?? getPropertyType({
713
821
  location,
714
822
  type: typeName
715
- }))
823
+ })
716
824
  );
717
825
  const hasExclamationToken = Boolean(
718
826
  isWhereUnique && config.unsafeCompatibleWhereUniqueInput && atLeastKeys?.includes(name)
719
827
  );
720
828
  const property = propertyStructure({
721
- name,
722
- isNullable: !isRequired,
723
829
  hasExclamationToken: hasExclamationToken || void 0,
724
830
  hasQuestionToken: hasExclamationToken ? false : void 0,
725
- propertyType,
726
- isList
831
+ isList,
832
+ isNullable: !isRequired,
833
+ name,
834
+ propertyType
727
835
  });
728
- classStructure.properties.push(property);
836
+ if (classStructure.properties) {
837
+ classStructure.properties.push(property);
838
+ }
729
839
  if (propertySettings) {
730
840
  importDeclarations.create({ ...propertySettings });
731
841
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
@@ -736,14 +846,14 @@ function inputType(args) {
736
846
  let graphqlType;
737
847
  let useGetType = false;
738
848
  const shouldHideField = settings?.shouldHideField({
739
- name: inputType2.name,
740
- input: true
741
- }) || config.decorate.some(
742
- (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
849
+ input: true,
850
+ name: inputTypeArg.name
851
+ }) ?? config.decorate.some(
852
+ (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputTypeArg.name)
743
853
  );
744
854
  const fieldType = settings?.getFieldType({
745
- name: inputType2.name,
746
- input: true
855
+ input: true,
856
+ name: inputTypeArg.name
747
857
  });
748
858
  if (fieldType && isCustomsApplicable && !shouldHideField) {
749
859
  graphqlType = fieldType.name;
@@ -751,29 +861,28 @@ function inputType(args) {
751
861
  } else {
752
862
  const graphqlImport = getGraphqlImport({
753
863
  config,
754
- sourceFile,
864
+ getSourceFile,
755
865
  location,
756
- typeName,
757
- getSourceFile
866
+ sourceFile,
867
+ typeName
758
868
  });
759
869
  graphqlType = graphqlImport.name;
760
- let referenceName = propertyType[0];
761
870
  if (location === "enumTypes") {
762
- const parts = referenceName.split(" ");
763
- referenceName = parts.at(-1) ?? parts[0];
871
+ const parts = String(propertyType[0]).split(" ");
872
+ parts.at(-1);
764
873
  }
765
874
  const shouldUseLazyType = config.esmCompatible && location === "inputObjectTypes";
766
- if (graphqlImport.name === inputType2.name && shouldUseLazyType) {
875
+ if (graphqlImport.name === inputTypeArg.name && shouldUseLazyType) {
767
876
  lazyTypes.add(graphqlImport.name);
768
877
  useGetType = true;
769
- } else if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputType2.name) {
878
+ } else if (graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputTypeArg.name) {
770
879
  if (shouldUseLazyType) {
771
880
  importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
772
881
  lazyTypes.add(graphqlImport.name);
773
882
  } else {
774
883
  importDeclarations.set(graphqlImport.name, {
775
- namedImports: [{ name: graphqlImport.name }],
776
- moduleSpecifier: graphqlImport.specifier
884
+ moduleSpecifier: graphqlImport.specifier,
885
+ namedImports: [{ name: graphqlImport.name }]
777
886
  });
778
887
  }
779
888
  }
@@ -781,10 +890,13 @@ function inputType(args) {
781
890
  useGetType = true;
782
891
  }
783
892
  }
784
- ok(property.decorators, "property.decorators is undefined");
893
+ ok(
894
+ property.decorators !== void 0 && property.decorators !== null,
895
+ "property.decorators is undefined"
896
+ );
785
897
  if (shouldHideField) {
786
898
  importDeclarations.add("HideField", moduleSpecifier);
787
- property.decorators.push({ name: "HideField", arguments: [] });
899
+ property.decorators.push({ arguments: [], name: "HideField" });
788
900
  } else {
789
901
  let typeExpression;
790
902
  if (useGetType) {
@@ -793,14 +905,14 @@ function inputType(args) {
793
905
  typeExpression = isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`;
794
906
  }
795
907
  property.decorators.push({
796
- name: "Field",
797
908
  arguments: [
798
909
  typeExpression,
799
910
  JSON52.stringify({
800
911
  ...settings?.fieldArguments(),
801
912
  nullable: !isRequired
802
913
  })
803
- ]
914
+ ],
915
+ name: "Field"
804
916
  });
805
917
  if (graphqlType === "GraphQLDecimal") {
806
918
  const decimalHelpersPath = relativePath(
@@ -812,12 +924,12 @@ function inputType(args) {
812
924
  importDeclarations.add("Type", "class-transformer");
813
925
  property.decorators.push(
814
926
  {
815
- name: "Type",
816
- arguments: ["() => Object"]
927
+ arguments: ["() => Object"],
928
+ name: "Type"
817
929
  },
818
930
  {
819
- name: "Transform",
820
- arguments: ["transformToDecimal"]
931
+ arguments: ["transformToDecimal"],
932
+ name: "Transform"
821
933
  }
822
934
  );
823
935
  } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
@@ -834,44 +946,47 @@ function inputType(args) {
834
946
  "updateMany",
835
947
  "upsert",
836
948
  "where"
837
- ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type) && models.get(modelField.type)?.fields.some(
949
+ ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type)?.fields.some(
838
950
  (f) => f.kind === "object" && classTransformerTypeModels.has(f.type)
839
- ))) {
951
+ ) === true)) {
840
952
  importDeclarations.add("Type", "class-transformer");
841
953
  if (useGetType) {
842
954
  property.decorators.push({
843
- name: "Type",
844
- arguments: [`getType('${graphqlType}')`]
955
+ arguments: [`getType('${graphqlType}')`],
956
+ name: "Type"
845
957
  });
846
958
  } else {
847
- property.decorators.push({ name: "Type", arguments: [`() => ${graphqlType}`] });
959
+ property.decorators.push({ arguments: [`() => ${graphqlType}`], name: "Type" });
848
960
  }
849
961
  }
850
962
  if (isCustomsApplicable) {
851
963
  for (const options of settings ?? []) {
852
964
  if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
853
965
  property.decorators.push({
854
- name: options.name,
855
- arguments: options.arguments
966
+ arguments: options.arguments,
967
+ name: options.name
856
968
  });
857
- ok(options.from, "Missed 'from' part in configuration or field setting");
969
+ ok(
970
+ options.from !== void 0 && options.from !== null && options.from !== "",
971
+ "Missed 'from' part in configuration or field setting"
972
+ );
858
973
  importDeclarations.create(options);
859
974
  }
860
975
  }
861
976
  }
862
977
  for (const decorate of config.decorate) {
863
- if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
978
+ if (decorate.isMatchField(name) && decorate.isMatchType(inputTypeArg.name)) {
864
979
  property.decorators.push({
865
- name: decorate.name,
866
- arguments: decorate.arguments?.map((x) => pupa(x, { propertyType }))
980
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType })),
981
+ name: decorate.name
867
982
  });
868
983
  importDeclarations.create(decorate);
869
984
  }
870
985
  }
871
986
  }
872
987
  eventEmitter.emitSync("ClassProperty", property, {
873
- location,
874
988
  isList,
989
+ location,
875
990
  propertyType
876
991
  });
877
992
  }
@@ -881,7 +996,7 @@ function inputType(args) {
881
996
  ];
882
997
  if (config.esmCompatible) {
883
998
  statements.push(`
884
- registerType('${inputType2.name}', ${inputType2.name});`);
999
+ registerType('${inputTypeArg.name}', ${inputTypeArg.name});`);
885
1000
  }
886
1001
  sourceFile.set({
887
1002
  statements
@@ -889,8 +1004,8 @@ registerType('${inputType2.name}', ${inputType2.name});`);
889
1004
  }
890
1005
  var ObjectSettings = class extends Array {
891
1006
  shouldHideField({
892
- name,
893
1007
  input = false,
1008
+ name,
894
1009
  output = false
895
1010
  }) {
896
1011
  const hideField = this.find((s) => s.name === "HideField");
@@ -899,8 +1014,8 @@ var ObjectSettings = class extends Array {
899
1014
  );
900
1015
  }
901
1016
  getFieldType({
902
- name,
903
1017
  input,
1018
+ name,
904
1019
  output
905
1020
  }) {
906
1021
  const fieldType = this.find((s) => s.kind === "FieldType");
@@ -919,8 +1034,8 @@ var ObjectSettings = class extends Array {
919
1034
  return fieldType;
920
1035
  }
921
1036
  getPropertyType({
922
- name,
923
1037
  input,
1038
+ name,
924
1039
  output
925
1040
  }) {
926
1041
  const propertyType = this.find((s) => s.kind === "PropertyType");
@@ -943,19 +1058,20 @@ var ObjectSettings = class extends Array {
943
1058
  const resultArguments = [objectTypeOptions];
944
1059
  const objectType = this.find((s) => s.kind === "ObjectType");
945
1060
  if (objectType && isObject(objectType.arguments)) {
946
- const name = objectType.arguments.name;
1061
+ const { name } = objectType.arguments;
947
1062
  merge(objectTypeOptions, omit(objectType.arguments, "name"));
948
- if (name) {
1063
+ if (name !== null && name !== void 0 && name !== "") {
949
1064
  resultArguments.unshift(name);
950
1065
  }
951
1066
  }
952
1067
  return resultArguments.map((x) => JSON52.stringify(x));
953
1068
  }
954
1069
  fieldArguments() {
955
- const item = this.find((item2) => item2.kind === "Field");
956
- if (item) {
957
- return item.arguments;
1070
+ const fieldItem = this.find((item) => item.kind === "Field");
1071
+ if (fieldItem) {
1072
+ return fieldItem.arguments;
958
1073
  }
1074
+ return void 0;
959
1075
  }
960
1076
  };
961
1077
  function createObjectSettings(args) {
@@ -965,18 +1081,23 @@ function createObjectSettings(args) {
965
1081
  const documentationLines = [];
966
1082
  let fieldElement = result.find((item) => item.kind === "Field");
967
1083
  if (!fieldElement) {
968
- fieldElement = {
969
- name: "",
1084
+ const newFieldElement = {
1085
+ arguments: {},
1086
+ from: "",
1087
+ input: false,
970
1088
  kind: "Field",
971
- arguments: {}
1089
+ model: false,
1090
+ name: "",
1091
+ output: false
972
1092
  };
1093
+ fieldElement = newFieldElement;
973
1094
  }
974
1095
  for (const line of textLines) {
975
1096
  const match = /^@(?<name>\w+(\.(\w+))?)\((?<args>.*)\)/.exec(line);
976
- const { element, documentLine } = createSettingElement({
977
- line,
1097
+ const { documentLine, element } = createSettingElement({
978
1098
  config,
979
1099
  fieldElement,
1100
+ line,
980
1101
  match
981
1102
  });
982
1103
  if (element) {
@@ -987,14 +1108,14 @@ function createObjectSettings(args) {
987
1108
  }
988
1109
  }
989
1110
  return {
990
- settings: result,
991
- documentation: documentationLines.filter(Boolean).join("\n") || void 0
1111
+ documentation: documentationLines.filter(Boolean).join("\n") || void 0,
1112
+ settings: result
992
1113
  };
993
1114
  }
994
1115
  function createSettingElement({
995
- line,
996
1116
  config,
997
1117
  fieldElement,
1118
+ line,
998
1119
  match
999
1120
  }) {
1000
1121
  const result = {
@@ -1002,75 +1123,95 @@ function createSettingElement({
1002
1123
  element: void 0
1003
1124
  };
1004
1125
  if (line.startsWith("@deprecated")) {
1005
- fieldElement.arguments["deprecationReason"] = trim(line.slice(11));
1006
- result.element = fieldElement;
1126
+ const DEPRECATED_PREFIX_LENGTH = 11;
1127
+ const updatedFieldElement = {
1128
+ ...fieldElement,
1129
+ arguments: {
1130
+ ...fieldElement.arguments,
1131
+ deprecationReason: trim(line.slice(DEPRECATED_PREFIX_LENGTH))
1132
+ }
1133
+ };
1134
+ result.element = updatedFieldElement;
1007
1135
  return result;
1008
1136
  }
1009
1137
  if (line.startsWith("@complexity")) {
1010
- let n = Number.parseInt(trim(line.slice(11)));
1011
- if (n !== n || n < 1) n = 1;
1012
- fieldElement.arguments["complexity"] = n;
1013
- result.element = fieldElement;
1138
+ const COMPLEXITY_PREFIX_LENGTH = 11;
1139
+ const MIN_COMPLEXITY = 1;
1140
+ let n = Number.parseInt(trim(line.slice(COMPLEXITY_PREFIX_LENGTH)), 10);
1141
+ if (Number.isNaN(n) || n < MIN_COMPLEXITY) {
1142
+ n = MIN_COMPLEXITY;
1143
+ }
1144
+ const updatedFieldElement = {
1145
+ ...fieldElement,
1146
+ arguments: {
1147
+ ...fieldElement.arguments,
1148
+ complexity: n
1149
+ }
1150
+ };
1151
+ result.element = updatedFieldElement;
1014
1152
  return result;
1015
1153
  }
1016
1154
  const name = match?.groups?.name;
1017
- if (!(match && name)) {
1155
+ if (!(match && name !== void 0 && name !== "")) {
1018
1156
  result.documentLine = line;
1019
1157
  return result;
1020
1158
  }
1021
1159
  const element = {
1022
- kind: "Decorator",
1023
- name: "",
1024
1160
  arguments: [],
1161
+ from: "",
1025
1162
  input: false,
1026
- output: false,
1163
+ kind: "Decorator",
1027
1164
  model: false,
1028
- from: ""
1165
+ name: "",
1166
+ output: false
1029
1167
  };
1030
1168
  result.element = element;
1031
1169
  if (name === "TypeGraphQL.omit" || name === "HideField") {
1032
1170
  Object.assign(element, hideFieldDecorator(match));
1033
1171
  return result;
1034
1172
  }
1035
- if (["FieldType", "PropertyType"].includes(name) && match.groups?.args) {
1173
+ if (["FieldType", "PropertyType"].includes(name) && match.groups?.args !== void 0 && match.groups.args !== "") {
1036
1174
  const options2 = customType(match.groups.args);
1037
- merge(element, options2.namespace && config.fields[options2.namespace], options2, {
1175
+ const namespaceConfig2 = options2.namespace !== void 0 && options2.namespace !== "" ? config.fields[options2.namespace] : void 0;
1176
+ merge(element, namespaceConfig2, options2, {
1038
1177
  kind: name
1039
1178
  });
1040
1179
  return result;
1041
1180
  }
1042
- if (name === "ObjectType" && match.groups?.args) {
1181
+ if (name === "ObjectType" && match.groups?.args !== void 0 && match.groups.args !== "") {
1043
1182
  element.kind = "ObjectType";
1044
1183
  const options2 = customType(match.groups.args);
1045
- if (typeof options2[0] === "string" && options2[0]) {
1184
+ if (typeof options2[0] === "string" && options2[0] !== "") {
1046
1185
  options2.name = options2[0];
1047
1186
  }
1048
1187
  if (isObject(options2[1])) {
1049
1188
  merge(options2, options2[1]);
1050
1189
  }
1051
1190
  element.arguments = {
1052
- name: options2.name,
1053
- isAbstract: options2.isAbstract
1191
+ isAbstract: options2.isAbstract,
1192
+ name: options2.name
1054
1193
  };
1055
1194
  return result;
1056
1195
  }
1057
- if (name === "Directive" && match.groups?.args) {
1196
+ if (name === "Directive" && match.groups?.args !== void 0 && match.groups.args !== "") {
1058
1197
  const options2 = customType(match.groups.args);
1059
- merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
1060
- name,
1061
- namespace: false,
1198
+ merge(element, { from: "@nestjs/graphql", model: true }, options2, {
1199
+ arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => JSON52.stringify(s)) : options2.arguments,
1062
1200
  kind: "Decorator",
1063
- arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => JSON52.stringify(s)) : options2.arguments
1201
+ name,
1202
+ namespace: false
1064
1203
  });
1065
1204
  return result;
1066
1205
  }
1067
1206
  const namespace = getNamespace(name);
1068
1207
  element.namespaceImport = namespace;
1208
+ const args = match.groups?.args ?? "";
1069
1209
  const options = {
1070
- name,
1071
- arguments: (match.groups?.args || "").split(",").map((s) => trim(s)).filter(Boolean)
1210
+ arguments: args.split(",").map((s) => trim(s)).filter(Boolean),
1211
+ name
1072
1212
  };
1073
- merge(element, namespace && config.fields[namespace], options);
1213
+ const namespaceConfig = namespace !== void 0 && namespace !== "" ? config.fields[namespace] : void 0;
1214
+ merge(element, namespaceConfig, options);
1074
1215
  return result;
1075
1216
  }
1076
1217
  function customType(args) {
@@ -1082,7 +1223,8 @@ function customType(args) {
1082
1223
  Object.assign(result, options);
1083
1224
  const namespace = getNamespace(options.name);
1084
1225
  result.namespace = namespace;
1085
- if (options.name?.includes(".")) {
1226
+ const optionsWithName = options;
1227
+ if (optionsWithName.name !== void 0 && optionsWithName.name !== "" && optionsWithName.name.includes(".")) {
1086
1228
  result.namespaceImport = namespace;
1087
1229
  }
1088
1230
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -1092,29 +1234,30 @@ function customType(args) {
1092
1234
  }
1093
1235
  function hideFieldDecorator(match) {
1094
1236
  const result = {
1095
- name: "HideField",
1096
1237
  arguments: [],
1097
- from: "@nestjs/graphql",
1098
1238
  defaultImport: void 0,
1099
- namespaceImport: void 0,
1100
- match: void 0
1239
+ from: "@nestjs/graphql",
1240
+ match: void 0,
1241
+ name: "HideField",
1242
+ namespaceImport: void 0
1101
1243
  };
1102
- if (!match.groups?.args) {
1244
+ const args = match.groups?.args;
1245
+ if (args === void 0 || args === "") {
1103
1246
  result.output = true;
1104
1247
  return result;
1105
1248
  }
1106
- if (match.groups.args.includes("{") && match.groups.args.includes("}")) {
1107
- const options = parseArgs(match.groups.args);
1249
+ if (args.includes("{") && args.includes("}")) {
1250
+ const options = parseArgs(args);
1108
1251
  result.output = Boolean(options.output);
1109
1252
  result.input = Boolean(options.input);
1110
1253
  if (typeof options.match === "string" || Array.isArray(options.match)) {
1111
1254
  result.match = outmatch2(options.match, { separator: false });
1112
1255
  }
1113
1256
  } else {
1114
- if (/output:\s*true/.test(match.groups.args)) {
1257
+ if (/output:\s*true/.test(args)) {
1115
1258
  result.output = true;
1116
1259
  }
1117
- if (/input:\s*true/.test(match.groups.args)) {
1260
+ if (/input:\s*true/.test(args)) {
1118
1261
  result.input = true;
1119
1262
  }
1120
1263
  }
@@ -1132,12 +1275,22 @@ function parseArgs(string) {
1132
1275
  }
1133
1276
  }
1134
1277
  function getNamespace(name) {
1135
- if (name === void 0) {
1278
+ if (name === void 0 || name === null) {
1279
+ return void 0;
1280
+ }
1281
+ if (typeof name !== "string") {
1282
+ return void 0;
1283
+ }
1284
+ let result = name;
1285
+ if (result === "") {
1136
1286
  return void 0;
1137
1287
  }
1138
- let result = String(name);
1139
1288
  if (result.includes(".")) {
1140
- [result] = result.split(".");
1289
+ const parts = result.split(".");
1290
+ result = parts[0] ?? "";
1291
+ }
1292
+ if (result === "") {
1293
+ return void 0;
1141
1294
  }
1142
1295
  return result;
1143
1296
  }
@@ -1145,12 +1298,12 @@ function getNamespace(name) {
1145
1298
  // src/handlers/model-data.ts
1146
1299
  function modelData(model, args) {
1147
1300
  const {
1301
+ classTransformerTypeModels,
1148
1302
  config,
1149
- modelNames,
1150
- models,
1151
- modelFields,
1152
1303
  fieldSettings,
1153
- classTransformerTypeModels
1304
+ modelFields,
1305
+ modelNames,
1306
+ models
1154
1307
  } = args;
1155
1308
  modelNames.push(model.name);
1156
1309
  models.set(model.name, model);
@@ -1159,10 +1312,10 @@ function modelData(model, args) {
1159
1312
  const fieldSettingsValue = /* @__PURE__ */ new Map();
1160
1313
  fieldSettings.set(model.name, fieldSettingsValue);
1161
1314
  for (const field of model.fields) {
1162
- if (field.documentation) {
1315
+ if (field.documentation !== null && field.documentation !== void 0 && field.documentation.length > 0) {
1163
1316
  const { documentation, settings } = createObjectSettings({
1164
- text: field.documentation,
1165
- config
1317
+ config,
1318
+ text: field.documentation
1166
1319
  });
1167
1320
  field.documentation = documentation;
1168
1321
  fieldSettingsValue.set(field.name, settings);
@@ -1181,8 +1334,14 @@ function createComment(documentation, settings) {
1181
1334
  for (const line of documentationLines) {
1182
1335
  commentLines.push(` * ${line}`);
1183
1336
  }
1184
- const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1185
- if (deprecationReason) {
1337
+ const fieldArgs = settings?.fieldArguments();
1338
+ let deprecationReason;
1339
+ if (fieldArgs === void 0) {
1340
+ deprecationReason = void 0;
1341
+ } else {
1342
+ deprecationReason = fieldArgs.deprecationReason;
1343
+ }
1344
+ if (deprecationReason !== void 0 && deprecationReason !== null && deprecationReason.length > 0) {
1186
1345
  commentLines.push(` * @deprecated ${deprecationReason}`);
1187
1346
  }
1188
1347
  commentLines.push(" */\n");
@@ -1197,6 +1356,9 @@ function buildDependencyGraph(models) {
1197
1356
  }
1198
1357
  for (const model of models) {
1199
1358
  const dependencies = graph.get(model.name);
1359
+ if (!dependencies) {
1360
+ continue;
1361
+ }
1200
1362
  for (const field of model.fields) {
1201
1363
  if (field.kind === "object" && field.type !== model.name) {
1202
1364
  if (graph.has(field.type)) {
@@ -1216,7 +1378,7 @@ function detectCircularDependencies(graph) {
1216
1378
  visited.add(node);
1217
1379
  recursionStack.add(node);
1218
1380
  path.push(node);
1219
- const dependencies = graph.get(node) || /* @__PURE__ */ new Set();
1381
+ const dependencies = graph.get(node) ?? /* @__PURE__ */ new Set();
1220
1382
  for (const dep of dependencies) {
1221
1383
  if (!visited.has(dep)) {
1222
1384
  dfs(dep);
@@ -1266,7 +1428,9 @@ function modelOutputType(outputType2, args) {
1266
1428
  models,
1267
1429
  output
1268
1430
  } = args;
1269
- if (isManyAndReturnOutputType(outputType2.name)) return;
1431
+ if (isManyAndReturnOutputType(outputType2.name)) {
1432
+ return;
1433
+ }
1270
1434
  const model = models.get(outputType2.name);
1271
1435
  ok(model, `Cannot find model by name ${outputType2.name}`);
1272
1436
  const sourceFile = getSourceFile({
@@ -1296,16 +1460,14 @@ function modelOutputType(outputType2, args) {
1296
1460
  const decorator = classStructure.decorators.find((d) => d.name === "ObjectType");
1297
1461
  ok(decorator, "ObjectType decorator not found");
1298
1462
  let modelSettings;
1299
- if (model.documentation) {
1463
+ if (model.documentation !== null && model.documentation !== void 0 && model.documentation.length > 0) {
1300
1464
  const objectTypeOptions = {};
1301
1465
  const { documentation, settings } = createObjectSettings({
1302
1466
  config,
1303
1467
  text: model.documentation
1304
1468
  });
1305
- if (documentation) {
1306
- if (!classStructure.leadingTrivia) {
1307
- classStructure.leadingTrivia = createComment(documentation);
1308
- }
1469
+ if (documentation !== void 0 && documentation.length > 0) {
1470
+ classStructure.leadingTrivia ??= createComment(documentation);
1309
1471
  objectTypeOptions.description = documentation;
1310
1472
  }
1311
1473
  decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
@@ -1323,10 +1485,12 @@ function modelOutputType(outputType2, args) {
1323
1485
  importDeclarations.add("getType", typeRegistryPath);
1324
1486
  }
1325
1487
  for (const field of outputType2.fields) {
1326
- if (config.omitModelsCount && field.name === "_count") continue;
1488
+ if (config.omitModelsCount && field.name === "_count") {
1489
+ continue;
1490
+ }
1327
1491
  let fileType = "model";
1328
1492
  const { isList, location, namespace, type } = field.outputType;
1329
- let outputTypeName = String(type);
1493
+ let outputTypeName = type;
1330
1494
  if (namespace !== "model") {
1331
1495
  fileType = "output";
1332
1496
  outputTypeName = getOutputTypeName(outputTypeName);
@@ -1348,15 +1512,12 @@ function modelOutputType(outputType2, args) {
1348
1512
  })
1349
1513
  );
1350
1514
  propertyType.splice(1, propertyType.length);
1351
- if (field.isNullable && !isList) {
1515
+ if (field.isNullable === true && !isList) {
1352
1516
  propertyType.push("null");
1353
1517
  }
1354
1518
  let graphqlType;
1355
1519
  let useGetType = false;
1356
- if (fieldType) {
1357
- graphqlType = fieldType.name;
1358
- importDeclarations.create({ ...fieldType });
1359
- } else {
1520
+ if (fieldType === void 0) {
1360
1521
  const graphqlImport = getGraphqlImport({
1361
1522
  config,
1362
1523
  fileType,
@@ -1368,7 +1529,7 @@ function modelOutputType(outputType2, args) {
1368
1529
  typeName: outputTypeName
1369
1530
  });
1370
1531
  graphqlType = graphqlImport.name;
1371
- if (graphqlImport.name !== outputType2.name && graphqlImport.specifier) {
1532
+ if (graphqlImport.name !== outputType2.name && graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && graphqlImport.specifier.length > 0) {
1372
1533
  const isCircular = config.esmCompatible && location === "outputObjectTypes" && namespace === "model" && hasCircularDependency(circularDependencies, outputType2.name, outputTypeName);
1373
1534
  if (isCircular) {
1374
1535
  importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
@@ -1378,6 +1539,9 @@ function modelOutputType(outputType2, args) {
1378
1539
  importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
1379
1540
  }
1380
1541
  }
1542
+ } else {
1543
+ graphqlType = fieldType.name;
1544
+ importDeclarations.create({ ...fieldType });
1381
1545
  }
1382
1546
  const property = propertyStructure({
1383
1547
  hasExclamationToken: true,
@@ -1387,17 +1551,19 @@ function modelOutputType(outputType2, args) {
1387
1551
  name: field.name,
1388
1552
  propertyType
1389
1553
  });
1390
- if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1554
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation.length > 0) {
1391
1555
  property.leadingTrivia += createComment(modelField.documentation, settings);
1392
1556
  }
1393
- classStructure.properties?.push(property);
1394
- if (propertySettings) {
1557
+ if (classStructure.properties !== void 0) {
1558
+ classStructure.properties.push(property);
1559
+ }
1560
+ if (propertySettings !== void 0) {
1395
1561
  importDeclarations.create({ ...propertySettings });
1396
1562
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
1397
1563
  importDeclarations.add("Prisma", config.prismaClientImport);
1398
1564
  }
1399
- ok(property.decorators, "property.decorators is undefined");
1400
- const shouldHideField = settings?.shouldHideField({ name: outputType2.name, output: true }) || config.decorate.some(
1565
+ ok(property.decorators !== void 0, "property.decorators is undefined");
1566
+ const shouldHideField = settings?.shouldHideField({ name: outputType2.name, output: true }) === true || config.decorate.some(
1401
1567
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1402
1568
  );
1403
1569
  if (shouldHideField) {
@@ -1418,7 +1584,7 @@ function modelOutputType(outputType2, args) {
1418
1584
  defaultValue: ["number", "string", "boolean"].includes(
1419
1585
  typeof modelField?.default
1420
1586
  ) ? modelField?.default : void 0,
1421
- description: modelField?.documentation,
1587
+ description: modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation !== "" ? modelField.documentation : void 0,
1422
1588
  nullable: Boolean(field.isNullable)
1423
1589
  })
1424
1590
  ],
@@ -1430,7 +1596,10 @@ function modelOutputType(outputType2, args) {
1430
1596
  arguments: setting.arguments,
1431
1597
  name: setting.name
1432
1598
  });
1433
- ok(setting.from, "Missed 'from' part in configuration or field setting");
1599
+ ok(
1600
+ setting.from && setting.from.length > 0,
1601
+ "Missed 'from' part in configuration or field setting"
1602
+ );
1434
1603
  importDeclarations.create(setting);
1435
1604
  }
1436
1605
  }
@@ -1498,13 +1667,14 @@ function noAtomicOperations(eventEmitter) {
1498
1667
  eventEmitter.on("BeforeGenerateFiles", beforeGenerateFiles);
1499
1668
  }
1500
1669
  function beforeInputType2(args) {
1501
- const { inputType: inputType2, getModelName: getModelName2 } = args;
1670
+ const { getModelName: getModelName2, inputType: inputType2 } = args;
1502
1671
  for (const field of inputType2.fields) {
1503
1672
  const fieldName = field.name;
1504
1673
  field.inputTypes = field.inputTypes.filter((it) => {
1505
- const inputTypeName = String(it.type);
1674
+ const inputTypeName = it.type;
1506
1675
  const modelName = getModelName2(inputTypeName);
1507
- if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName, fieldName)) {
1676
+ const isModelNameValid = modelName !== null && modelName !== void 0 && modelName.length > 0;
1677
+ if (isAtomicOperation(inputTypeName) || isModelNameValid && isListInput(inputTypeName, modelName, fieldName)) {
1508
1678
  return false;
1509
1679
  }
1510
1680
  return true;
@@ -1515,7 +1685,8 @@ function beforeGenerateFiles(args) {
1515
1685
  const { project } = args;
1516
1686
  for (const sourceFile of project.getSourceFiles()) {
1517
1687
  const className = sourceFile.getClass(() => true)?.getName();
1518
- if (className && isAtomicOperation(className)) {
1688
+ const isClassNameValid = className !== void 0 && className !== null && className.length > 0;
1689
+ if (isClassNameValid && isAtomicOperation(className)) {
1519
1690
  project.removeSourceFile(sourceFile);
1520
1691
  }
1521
1692
  }
@@ -1541,11 +1712,13 @@ function outputType(outputTypeArg, args) {
1541
1712
  const { config, eventEmitter, fieldSettings, getModelName: getModelName2, getSourceFile, models } = args;
1542
1713
  const importDeclarations = new ImportDeclarationMap();
1543
1714
  const fileType = "output";
1544
- const modelName = getModelName2(outputTypeArg.name) ?? "";
1545
- const model = models.get(modelName);
1546
- const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputTypeArg.name) && String(outputTypeArg.name).startsWith(model.name);
1547
- const isCountOutput = model?.name && outputTypeArg.name === `${model.name}CountOutputType`;
1548
- if (!config.emitBlocks.outputs && !isCountOutput) return;
1715
+ const modelName = getModelName2(outputTypeArg.name);
1716
+ const model = modelName === void 0 ? void 0 : models.get(modelName);
1717
+ const isAggregateOutput = model !== void 0 && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputTypeArg.name) && outputTypeArg.name.startsWith(model.name);
1718
+ const isCountOutput = model?.name !== void 0 && model.name !== "" && outputTypeArg.name === `${model.name}CountOutputType`;
1719
+ if (config.emitBlocks.outputs || isCountOutput) ; else {
1720
+ return;
1721
+ }
1549
1722
  outputTypeArg.name = getOutputTypeName(outputTypeArg.name);
1550
1723
  if (isAggregateOutput) {
1551
1724
  eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputTypeArg });
@@ -1570,8 +1743,15 @@ function outputType(outputTypeArg, args) {
1570
1743
  importDeclarations.add("ObjectType", nestjsGraphql2);
1571
1744
  for (const field of outputTypeArg.fields) {
1572
1745
  const { isList, location, type } = field.outputType;
1573
- const outputTypeName = getOutputTypeName(String(type));
1574
- const settings = isCountOutput ? void 0 : model && fieldSettings.get(model.name)?.get(field.name);
1746
+ const outputTypeName = getOutputTypeName(type);
1747
+ let settings;
1748
+ if (isCountOutput) {
1749
+ settings = void 0;
1750
+ } else if (model === void 0) {
1751
+ settings = void 0;
1752
+ } else {
1753
+ settings = fieldSettings.get(model.name)?.get(field.name);
1754
+ }
1575
1755
  const propertySettings = settings?.getPropertyType({
1576
1756
  name: outputTypeArg.name,
1577
1757
  output: true
@@ -1592,7 +1772,7 @@ function outputType(outputTypeArg, args) {
1592
1772
  propertyType
1593
1773
  });
1594
1774
  classStructure.properties?.push(property);
1595
- if (propertySettings) {
1775
+ if (propertySettings !== void 0) {
1596
1776
  importDeclarations.create({ ...propertySettings });
1597
1777
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
1598
1778
  importDeclarations.add("Prisma", config.prismaClientImport);
@@ -1601,14 +1781,14 @@ function outputType(outputTypeArg, args) {
1601
1781
  const shouldHideField = settings?.shouldHideField({
1602
1782
  name: outputTypeArg.name,
1603
1783
  output: true
1604
- }) || config.decorate.some(
1784
+ }) === true || config.decorate.some(
1605
1785
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1606
1786
  );
1607
1787
  const fieldType = settings?.getFieldType({
1608
1788
  name: outputTypeArg.name,
1609
1789
  output: true
1610
1790
  });
1611
- if (fieldType && isCustomsApplicable && !shouldHideField) {
1791
+ if (fieldType !== void 0 && isCustomsApplicable && !shouldHideField) {
1612
1792
  graphqlType = fieldType.name;
1613
1793
  importDeclarations.create({ ...fieldType });
1614
1794
  } else {
@@ -1623,14 +1803,14 @@ function outputType(outputTypeArg, args) {
1623
1803
  });
1624
1804
  const referenceName = location === "enumTypes" ? getEnumName(propertyType[0]) : propertyType[0];
1625
1805
  graphqlType = graphqlImport.name;
1626
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputTypeArg.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1806
+ if (graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && graphqlImport.specifier.length > 0 && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputTypeArg.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1627
1807
  importDeclarations.set(graphqlImport.name, {
1628
1808
  moduleSpecifier: graphqlImport.specifier,
1629
1809
  namedImports: [{ name: graphqlImport.name }]
1630
1810
  });
1631
1811
  }
1632
1812
  }
1633
- ok(property.decorators, "property.decorators is undefined");
1813
+ ok(property.decorators !== void 0, "property.decorators is undefined");
1634
1814
  if (shouldHideField) {
1635
1815
  importDeclarations.add("HideField", nestjsGraphql2);
1636
1816
  property.decorators.push({ arguments: [], name: "HideField" });
@@ -1647,12 +1827,16 @@ function outputType(outputTypeArg, args) {
1647
1827
  });
1648
1828
  if (isCustomsApplicable) {
1649
1829
  for (const options of settings ?? []) {
1650
- if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1830
+ const shouldApplyDecorator = options.kind === "Decorator" && options.output && (options.match?.(field.name) ?? true);
1831
+ if (shouldApplyDecorator) {
1651
1832
  property.decorators.push({
1652
1833
  arguments: options.arguments,
1653
1834
  name: options.name
1654
1835
  });
1655
- ok(options.from, "Missed 'from' part in configuration or field setting");
1836
+ ok(
1837
+ options.from !== null && options.from !== void 0 && options.from.length > 0,
1838
+ "Missed 'from' part in configuration or field setting"
1839
+ );
1656
1840
  importDeclarations.create(options);
1657
1841
  }
1658
1842
  }
@@ -1668,11 +1852,15 @@ function outputType(outputTypeArg, args) {
1668
1852
  statements: [...importDeclarations.toStatements(), classStructure]
1669
1853
  });
1670
1854
  }
1855
+ var rmdirTyped = rmdirSync$1;
1856
+ var rmdirSync = (path) => {
1857
+ rmdirTyped(path);
1858
+ };
1671
1859
  function purgeOutput(emitter) {
1672
1860
  emitter.on("Begin", begin);
1673
1861
  emitter.on("End", end);
1674
1862
  }
1675
- function begin({ project, output }) {
1863
+ function begin({ output, project }) {
1676
1864
  const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1677
1865
  if (sourceFiles) {
1678
1866
  for (const sourceFile of sourceFiles) {
@@ -1680,9 +1868,10 @@ function begin({ project, output }) {
1680
1868
  }
1681
1869
  }
1682
1870
  }
1683
- function end({ project, output }) {
1871
+ function end({ output, project }) {
1684
1872
  const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1685
- for (const directory of directories ?? []) {
1873
+ const directoryList = directories ?? [];
1874
+ for (const directory of directoryList) {
1686
1875
  try {
1687
1876
  rmdirSync(directory);
1688
1877
  } catch {
@@ -1700,7 +1889,7 @@ function reExport(emitter) {
1700
1889
  emitter.on("BeforeGenerateFiles", beforeGenerateFiles2);
1701
1890
  }
1702
1891
  function beforeGenerateFiles2(args) {
1703
- const { project, output, config } = args;
1892
+ const { config, output, project } = args;
1704
1893
  const rootDirectory = project.getDirectoryOrThrow(output);
1705
1894
  if (["Directories" /* Directories */, "All" /* All */].includes(config.reExport)) {
1706
1895
  const directories = [...rootDirectory.getDescendantDirectories()];
@@ -1747,7 +1936,9 @@ function beforeGenerateFiles2(args) {
1747
1936
  const exportDeclarations = [];
1748
1937
  const directories = rootDirectory.getDirectories();
1749
1938
  for (const directory of directories) {
1750
- if (directory.getBaseName() === "node_modules") continue;
1939
+ if (directory.getBaseName() === "node_modules") {
1940
+ continue;
1941
+ }
1751
1942
  const indexFile = directory.getSourceFile("index.ts");
1752
1943
  if (indexFile) {
1753
1944
  const dirName = directory.getBaseName();
@@ -1769,9 +1960,9 @@ function beforeGenerateFiles2(args) {
1769
1960
  function getExportDeclaration2(directory, sourceFile) {
1770
1961
  let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceFile);
1771
1962
  if (!moduleSpecifier.endsWith(".js") && !moduleSpecifier.endsWith(".ts")) {
1772
- moduleSpecifier = moduleSpecifier + ".js";
1963
+ moduleSpecifier += ".js";
1773
1964
  } else if (moduleSpecifier.endsWith(".ts")) {
1774
- moduleSpecifier = moduleSpecifier.slice(0, -3) + ".js";
1965
+ moduleSpecifier = `${moduleSpecifier.slice(0, -3)}.js`;
1775
1966
  }
1776
1967
  return {
1777
1968
  kind: StructureKind.ExportDeclaration,
@@ -1781,7 +1972,7 @@ function getExportDeclaration2(directory, sourceFile) {
1781
1972
  function getNamespaceExportDeclaration(directory, sourceDirectory) {
1782
1973
  let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceDirectory);
1783
1974
  if (!moduleSpecifier.endsWith("/index.js")) {
1784
- moduleSpecifier = moduleSpecifier + "/index.js";
1975
+ moduleSpecifier += "/index.js";
1785
1976
  }
1786
1977
  return {
1787
1978
  kind: StructureKind.ExportDeclaration,
@@ -1789,74 +1980,16 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
1789
1980
  };
1790
1981
  }
1791
1982
 
1792
- // src/handlers/prisma-enum-doc.ts
1793
- function extractEnumValueDocs(values) {
1794
- return Object.fromEntries(
1795
- values.map((value) => {
1796
- const { name } = value;
1797
- const documentation = value.documentation;
1798
- if (typeof documentation !== "string") return null;
1799
- if (documentation.startsWith("@deprecated")) {
1800
- return [name, { deprecationReason: documentation.slice(11).trim() }];
1801
- }
1802
- return [name, { description: documentation }];
1803
- }).filter((entry) => entry !== null)
1804
- );
1805
- }
1806
-
1807
- // src/handlers/register-enum.ts
1808
- function registerEnum(enumType, args) {
1809
- const { config, enums, getSourceFile } = args;
1810
- if (!config.emitBlocks.prismaEnums && !enums[enumType.name]) return;
1811
- const dataModelEnum = enums[enumType.name];
1812
- const enumTypesData = dataModelEnum?.values ?? [];
1813
- const sourceFile = getSourceFile({
1814
- name: enumType.name,
1815
- type: "enum"
1816
- });
1817
- const importDeclarations = new ImportDeclarationMap();
1818
- importDeclarations.set("registerEnumType", {
1819
- moduleSpecifier: "@nestjs/graphql",
1820
- namedImports: [{ name: "registerEnumType" }]
1983
+ // src/handlers/register-all-types.ts
1984
+ function generateRegisterAllTypes(args) {
1985
+ const { config, output, project } = args;
1986
+ if (!config.esmCompatible) {
1987
+ return;
1988
+ }
1989
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
1990
+ const sourceFile = rootDirectory.createSourceFile("register-all-types.ts", void 0, {
1991
+ overwrite: true
1821
1992
  });
1822
- const valuesMap = extractEnumValueDocs(enumTypesData);
1823
- const filteredValuesMap = Object.fromEntries(
1824
- Object.entries(valuesMap).filter(([, v]) => Object.keys(v).length > 0)
1825
- );
1826
- const hasValuesMap = Object.keys(filteredValuesMap).length > 0;
1827
- const formattedValuesMap = hasValuesMap ? JSON.stringify(filteredValuesMap, null, 2).replace(/"([^"]+)":/g, "$1:") : "";
1828
- const valuesMapEntry = hasValuesMap ? `, valuesMap: ${formattedValuesMap}` : "";
1829
- const enumStructure = {
1830
- kind: StructureKind.Enum,
1831
- isExported: true,
1832
- name: enumType.name,
1833
- members: enumType.values.map((v) => ({
1834
- name: v,
1835
- initializer: JSON.stringify(v)
1836
- }))
1837
- };
1838
- sourceFile.set({
1839
- statements: [
1840
- ...importDeclarations.toStatements(),
1841
- enumStructure,
1842
- "\n",
1843
- `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(
1844
- dataModelEnum?.documentation
1845
- )}${valuesMapEntry} })`
1846
- ]
1847
- });
1848
- }
1849
- function generateRegisterAllTypes(args) {
1850
- const { config, output, project } = args;
1851
- if (!config.esmCompatible) {
1852
- return;
1853
- }
1854
- const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
1855
- const sourceFile = rootDirectory.createSourceFile(
1856
- "register-all-types.ts",
1857
- void 0,
1858
- { overwrite: true }
1859
- );
1860
1993
  const importPaths = [];
1861
1994
  const typeNames = [];
1862
1995
  const allSourceFiles = project.getSourceFiles(`${output}/**/*.ts`);
@@ -1866,7 +1999,7 @@ function generateRegisterAllTypes(args) {
1866
1999
  continue;
1867
2000
  }
1868
2001
  const fileText = file.getText();
1869
- const registerMatch = fileText.match(/registerType\(['"]([^'"]+)['"]/);
2002
+ const registerMatch = /registerType\(['"]([^'"]+)['"]/.exec(fileText);
1870
2003
  if (registerMatch) {
1871
2004
  const relPath = relativePath(sourceFile.getFilePath(), filePath);
1872
2005
  importPaths.push(relPath);
@@ -1920,6 +2053,76 @@ export type RegisteredTypeName = typeof registeredTypes[number];
1920
2053
  sourceFile.addStatements(fileContent);
1921
2054
  }
1922
2055
 
2056
+ // src/handlers/prisma-enum-doc.ts
2057
+ function extractEnumValueDocs(values) {
2058
+ return Object.fromEntries(
2059
+ values.map((value) => {
2060
+ const { name } = value;
2061
+ const { documentation } = value;
2062
+ if (typeof documentation !== "string") {
2063
+ return null;
2064
+ }
2065
+ if (documentation.startsWith("@deprecated")) {
2066
+ return [name, { deprecationReason: documentation.slice(11).trim() }];
2067
+ }
2068
+ return [name, { description: documentation }];
2069
+ }).filter((entry) => entry !== null)
2070
+ );
2071
+ }
2072
+
2073
+ // src/handlers/register-enum.ts
2074
+ function registerEnum(enumType, args) {
2075
+ const { config, enums, getSourceFile } = args;
2076
+ const enumTypeAsRecord = enumType;
2077
+ const rawName = enumTypeAsRecord.name;
2078
+ const enumName = typeof rawName === "string" ? rawName : String(rawName);
2079
+ const enumValue = enums[enumName];
2080
+ if (!config.emitBlocks.prismaEnums && enumValue === void 0) {
2081
+ return;
2082
+ }
2083
+ const dataModelEnum = enumValue;
2084
+ const enumTypesData = dataModelEnum?.values ?? [];
2085
+ const sourceFile = getSourceFile({
2086
+ name: enumName,
2087
+ type: "enum"
2088
+ });
2089
+ const importDeclarations = new ImportDeclarationMap();
2090
+ importDeclarations.set("registerEnumType", {
2091
+ moduleSpecifier: "@nestjs/graphql",
2092
+ namedImports: [{ name: "registerEnumType" }]
2093
+ });
2094
+ const valuesMap = extractEnumValueDocs(enumTypesData);
2095
+ const filteredValuesMap = Object.fromEntries(
2096
+ Object.entries(valuesMap).filter(([, v]) => Object.keys(v).length > 0)
2097
+ );
2098
+ const hasValuesMap = Object.keys(filteredValuesMap).length > 0;
2099
+ const formattedValuesMap = hasValuesMap ? JSON.stringify(filteredValuesMap, null, 2).replace(/"([^"]+)":/g, "$1:") : "";
2100
+ const valuesMapEntry = hasValuesMap ? `, valuesMap: ${formattedValuesMap}` : "";
2101
+ const enumTypeRecord = enumType;
2102
+ const rawValues = enumTypeRecord.values;
2103
+ const enumValues = Array.isArray(rawValues) ? rawValues.map((v) => String(v)) : [];
2104
+ const enumStructure = {
2105
+ isExported: true,
2106
+ kind: StructureKind.Enum,
2107
+ members: enumValues.map((v) => ({
2108
+ initializer: JSON.stringify(v),
2109
+ name: v
2110
+ })),
2111
+ name: enumName
2112
+ };
2113
+ const enumTypeName = enumName;
2114
+ sourceFile.set({
2115
+ statements: [
2116
+ ...importDeclarations.toStatements(),
2117
+ enumStructure,
2118
+ "\n",
2119
+ `registerEnumType(${enumTypeName}, { name: '${enumTypeName}', description: ${JSON.stringify(
2120
+ dataModelEnum?.documentation
2121
+ )}${valuesMapEntry} })`
2122
+ ]
2123
+ });
2124
+ }
2125
+
1923
2126
  // src/handlers/require-single-fields-in-whereunique-input.ts
1924
2127
  function requireSingleFieldsInWhereUniqueInput(eventEmitter) {
1925
2128
  eventEmitter.on("BeforeInputType", beforeInputType3);
@@ -1934,17 +2137,17 @@ function beforeInputType3(args) {
1934
2137
  field.isNullable = false;
1935
2138
  }
1936
2139
  }
2140
+
2141
+ // src/handlers/type-registry.ts
1937
2142
  function generateTypeRegistry(args) {
1938
2143
  const { config, output, project } = args;
1939
2144
  if (!config.esmCompatible) {
1940
2145
  return;
1941
2146
  }
1942
- const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
1943
- const sourceFile = rootDirectory.createSourceFile(
1944
- "type-registry.ts",
1945
- void 0,
1946
- { overwrite: true }
1947
- );
2147
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
2148
+ const sourceFile = rootDirectory.createSourceFile("type-registry.ts", void 0, {
2149
+ overwrite: true
2150
+ });
1948
2151
  const registryCode = `/**
1949
2152
  * Type Registry for ESM Circular Dependency Resolution
1950
2153
  *
@@ -2075,81 +2278,17 @@ export function validateRegistry(expectedTypes: string[]): void {
2075
2278
  sourceFile.addStatements(registryCode);
2076
2279
  }
2077
2280
 
2078
- // src/handlers/decimal-helpers.ts
2079
- function generateDecimalHelpers(args) {
2080
- const { config, output, project } = args;
2081
- const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
2082
- const sourceFile = rootDirectory.createSourceFile(
2083
- "decimal-helpers.ts",
2084
- void 0,
2085
- { overwrite: true }
2086
- );
2087
- const helpersCode = `/**
2088
- * Decimal Helpers for Prisma GraphQL
2089
- *
2090
- * This module provides utilities for transforming Decimal values
2091
- * between GraphQL and Prisma, compatible with Prisma 7+.
2092
- *
2093
- * These functions replace the prisma-graphql-type-decimal package
2094
- * which is incompatible with Prisma 7's new client structure.
2095
- */
2096
-
2097
- import Decimal from 'decimal.js';
2098
-
2099
- /**
2100
- * Reconstruct a Decimal from a serialized object.
2101
- * Prisma serializes Decimals as objects with d, e, s properties.
2102
- */
2103
- function createDecimalFromObject(object: { d: number[]; e: number; s: number }): Decimal {
2104
- return Object.create(Decimal.prototype, {
2105
- d: { value: object.d },
2106
- e: { value: object.e },
2107
- s: { value: object.s },
2108
- });
2109
- }
2110
-
2111
- /**
2112
- * Transform input values to Decimal instances.
2113
- * Used as a class-transformer Transform decorator argument.
2114
- *
2115
- * @param params - The transform parameters from class-transformer
2116
- * @returns The transformed Decimal or array of Decimals
2117
- */
2118
- export function transformToDecimal({ value }: { value: unknown }): Decimal | Decimal[] | null | undefined {
2119
- if (value == null) return value as null | undefined;
2120
-
2121
- if (Array.isArray(value)) {
2122
- return value.map((v) => {
2123
- if (v instanceof Decimal) return v;
2124
- if (typeof v === 'object' && v !== null && 'd' in v && 'e' in v && 's' in v) {
2125
- return createDecimalFromObject(v as { d: number[]; e: number; s: number });
2126
- }
2127
- return new Decimal(v as string | number);
2128
- });
2129
- }
2130
-
2131
- if (value instanceof Decimal) return value;
2132
- if (typeof value === 'object' && value !== null && 'd' in value && 'e' in value && 's' in value) {
2133
- return createDecimalFromObject(value as { d: number[]; e: number; s: number });
2134
- }
2135
- return new Decimal(value as string | number);
2136
- }
2137
-
2138
- /**
2139
- * Re-export Decimal class for convenience
2140
- */
2141
- export { Decimal };
2142
- `;
2143
- sourceFile.addStatements(helpersCode);
2144
- }
2145
-
2146
2281
  // src/handlers/warning.ts
2282
+ var globalConsole = globalThis.console;
2283
+ var log = (msg) => {
2284
+ globalConsole.log(msg);
2285
+ };
2147
2286
  function warning(message) {
2148
2287
  if (Array.isArray(message)) {
2149
- console.log("nestjs-prisma-graphql:");
2150
- console.log(message.join("\n"));
2288
+ log("nestjs-prisma-graphql:");
2289
+ log(message.join("\n"));
2151
2290
  } else {
2152
- console.log("nestjs-prisma-graphql:", message);
2291
+ log(`nestjs-prisma-graphql: ${message}`);
2153
2292
  }
2154
2293
  }
2155
2294
 
@@ -2163,44 +2302,51 @@ var allEmmittedBlocks = [
2163
2302
  "outputs"
2164
2303
  ];
2165
2304
  var blocksDependencyMap = {
2305
+ args: ["args", "inputs", "prismaEnums"],
2166
2306
  enums: ["schemaEnums", "prismaEnums"],
2167
- models: ["models", "schemaEnums"],
2168
2307
  inputs: ["inputs", "prismaEnums"],
2169
- outputs: ["outputs"],
2170
- args: ["args", "inputs", "prismaEnums"]
2308
+ models: ["models", "schemaEnums"],
2309
+ outputs: ["outputs"]
2171
2310
  };
2172
2311
  function createEmitBlocks(data) {
2173
2312
  if (!data) {
2174
- return Object.fromEntries(allEmmittedBlocks.map((block) => [block, true]));
2313
+ const entries = allEmmittedBlocks.map((block) => [block, true]);
2314
+ const allBlocks = Object.fromEntries(entries);
2315
+ return allBlocks;
2175
2316
  }
2176
- let blocksToEmit = {};
2317
+ const initialBlocks = {};
2318
+ let currentBlocks = initialBlocks;
2177
2319
  for (const block of data) {
2178
- if (!Object.keys(blocksDependencyMap).includes(block)) continue;
2179
- blocksToEmit = {
2180
- ...blocksToEmit,
2181
- ...Object.fromEntries(
2182
- blocksDependencyMap[block].map((block2) => [block2, true])
2183
- )
2320
+ if (!Object.keys(blocksDependencyMap).includes(block)) {
2321
+ continue;
2322
+ }
2323
+ const blockEntries = blocksDependencyMap[block].map(
2324
+ (emittedBlock) => [emittedBlock, true]
2325
+ );
2326
+ const newBlocks = Object.fromEntries(blockEntries);
2327
+ currentBlocks = {
2328
+ ...currentBlocks,
2329
+ ...newBlocks
2184
2330
  };
2185
2331
  }
2186
- return blocksToEmit;
2332
+ return currentBlocks;
2187
2333
  }
2188
2334
 
2189
2335
  // src/helpers/create-config.ts
2190
2336
  function createConfig(data) {
2191
2337
  const config = merge({}, unflatten(data, { delimiter: "_" }));
2192
2338
  const $warnings = [];
2193
- const configOutputFilePattern = String(
2194
- config.outputFilePattern || `{model}/{name}.{type}.ts`
2195
- );
2196
- let outputFilePattern = configOutputFilePattern.replaceAll("..", "/").replaceAll(/\/+/g, "/");
2197
- outputFilePattern = trim(outputFilePattern, "/");
2339
+ const defaultPattern = `{model}/{name}.{type}.ts`;
2340
+ const outputFilePatternValue = config.outputFilePattern;
2341
+ const configOutputFilePattern = typeof outputFilePatternValue === "string" ? outputFilePatternValue : defaultPattern;
2342
+ const sanitizedStep1 = configOutputFilePattern.replaceAll("..", "/").replaceAll(/\/+/g, "/");
2343
+ const outputFilePattern = trim(sanitizedStep1, "/");
2198
2344
  if (outputFilePattern !== configOutputFilePattern) {
2199
2345
  $warnings.push(
2200
2346
  `Due to invalid filepath 'outputFilePattern' changed to '${outputFilePattern}'`
2201
2347
  );
2202
2348
  }
2203
- if (config.reExportAll) {
2349
+ if (config.reExportAll !== void 0 && config.reExportAll !== null && config.reExportAll !== false) {
2204
2350
  $warnings.push(`Option 'reExportAll' is deprecated, use 'reExport' instead`);
2205
2351
  if (toBoolean(config.reExportAll)) {
2206
2352
  config.reExport = "All";
@@ -2212,105 +2358,118 @@ function createConfig(data) {
2212
2358
  ).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
2213
2359
  const fieldSetting = {
2214
2360
  arguments: [],
2215
- output: toBoolean(value.output),
2361
+ defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
2362
+ from: value.from,
2216
2363
  input: toBoolean(value.input),
2217
2364
  model: toBoolean(value.model),
2218
- from: value.from,
2219
- defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
2220
- namespaceImport: value.namespaceImport
2365
+ namespaceImport: value.namespaceImport,
2366
+ output: toBoolean(value.output)
2221
2367
  };
2222
2368
  return [name, fieldSetting];
2223
2369
  })
2224
2370
  );
2225
2371
  const decorate = [];
2226
- const configDecorate = Object.values(
2227
- config.decorate || {}
2228
- );
2372
+ const decorateConfig = config.decorate !== void 0 && config.decorate !== null ? config.decorate : {};
2373
+ const configDecorate = Object.values(decorateConfig);
2229
2374
  for (const element of configDecorate) {
2230
- if (!element) continue;
2375
+ if (element === void 0 || element === null) {
2376
+ continue;
2377
+ }
2231
2378
  ok(
2232
- element.from && element.name,
2379
+ element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
2233
2380
  `Missed 'from' or 'name' part in configuration for decorate`
2234
2381
  );
2235
2382
  decorate.push({
2383
+ arguments: element.arguments !== void 0 && element.arguments !== "" ? JSON52.parse(element.arguments) : void 0,
2384
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2385
+ from: element.from,
2236
2386
  isMatchField: outmatch2(element.field, { separator: false }),
2237
2387
  isMatchType: outmatch2(element.type, { separator: false }),
2238
- from: element.from,
2239
2388
  name: element.name,
2240
2389
  namedImport: toBoolean(element.namedImport),
2241
- defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2242
- namespaceImport: element.namespaceImport,
2243
- arguments: element.arguments ? JSON52.parse(element.arguments) : void 0
2390
+ namespaceImport: element.namespaceImport
2244
2391
  });
2245
2392
  }
2246
2393
  const customImport = [];
2247
- const configCustomImport = Object.values(
2248
- config.customImport || {}
2249
- );
2394
+ const customImportConfig = config.customImport !== void 0 && config.customImport !== null ? config.customImport : {};
2395
+ const configCustomImport = Object.values(customImportConfig);
2250
2396
  for (const element of configCustomImport) {
2251
- if (!element) continue;
2397
+ if (element === void 0 || element === null) {
2398
+ continue;
2399
+ }
2252
2400
  ok(
2253
- element.from && element.name,
2401
+ element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
2254
2402
  `Missed 'from' or 'name' part in configuration for customImport`
2255
2403
  );
2256
2404
  customImport.push({
2405
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2257
2406
  from: element.from,
2258
2407
  name: element.name,
2259
2408
  namedImport: toBoolean(element.namedImport),
2260
- defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2261
2409
  namespaceImport: element.namespaceImport
2262
2410
  });
2263
2411
  }
2264
2412
  return {
2265
- outputFilePattern,
2266
- tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
2267
- prismaClientImport: createPrismaImport(config.prismaClientImport),
2413
+ $warnings,
2268
2414
  combineScalarFilters: toBoolean(config.combineScalarFilters),
2269
- noAtomicOperations: toBoolean(config.noAtomicOperations),
2270
- reExport: ReExport[String(config.reExport)] || "None" /* None */,
2271
- emitSingle: toBoolean(config.emitSingle),
2272
- emitCompiled: toBoolean(config.emitCompiled),
2415
+ customImport,
2416
+ decorate,
2273
2417
  emitBlocks: createEmitBlocks(config.emitBlocks),
2274
- omitModelsCount: toBoolean(config.omitModelsCount),
2275
- $warnings,
2418
+ emitCompiled: toBoolean(config.emitCompiled),
2419
+ emitSingle: toBoolean(config.emitSingle),
2420
+ esmCompatible: toBoolean(config.esmCompatible),
2276
2421
  fields,
2277
- purgeOutput: toBoolean(config.purgeOutput),
2278
- useInputType: createUseInputType(config.useInputType),
2422
+ graphqlScalars: config.graphqlScalars ?? {},
2423
+ noAtomicOperations: toBoolean(config.noAtomicOperations),
2279
2424
  noTypeId: toBoolean(config.noTypeId),
2425
+ omitModelsCount: toBoolean(config.omitModelsCount),
2426
+ outputFilePattern,
2427
+ prismaClientImport: createPrismaImport(config.prismaClientImport),
2428
+ purgeOutput: toBoolean(config.purgeOutput),
2429
+ reExport: ReExport[String(config.reExport)] ?? "None" /* None */,
2280
2430
  requireSingleFieldsInWhereUniqueInput: toBoolean(
2281
2431
  config.requireSingleFieldsInWhereUniqueInput
2282
2432
  ),
2283
- unsafeCompatibleWhereUniqueInput: toBoolean(
2284
- config.unsafeCompatibleWhereUniqueInput
2285
- ),
2286
- graphqlScalars: config.graphqlScalars || {},
2287
- decorate,
2288
- customImport,
2289
- esmCompatible: toBoolean(config.esmCompatible)
2433
+ tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
2434
+ unsafeCompatibleWhereUniqueInput: toBoolean(config.unsafeCompatibleWhereUniqueInput),
2435
+ useInputType: createUseInputType(
2436
+ config.useInputType
2437
+ )
2290
2438
  };
2291
2439
  }
2292
- var tsConfigFileExists = memoize((filePath) => {
2293
- return existsSync(filePath);
2440
+ var existsSyncTyped = existsSync;
2441
+ var tsConfigFileExistsRaw = memoize((filePath) => {
2442
+ const exists = existsSyncTyped(filePath);
2443
+ return exists;
2294
2444
  });
2445
+ var tsConfigFileExists = tsConfigFileExistsRaw;
2295
2446
  function createTsConfigFilePathValue(value) {
2296
- if (typeof value === "string") return value;
2297
- if (tsConfigFileExists("tsconfig.json")) return "tsconfig.json";
2447
+ if (typeof value === "string" && value !== "") {
2448
+ return value;
2449
+ }
2450
+ const fileExists = tsConfigFileExists("tsconfig.json");
2451
+ if (fileExists) {
2452
+ return "tsconfig.json";
2453
+ }
2454
+ return void 0;
2298
2455
  }
2299
2456
  function createPrismaImport(value) {
2300
- if (typeof value === "string") return value;
2457
+ if (typeof value === "string" && value !== "") {
2458
+ return value;
2459
+ }
2301
2460
  return "@prisma/client";
2302
2461
  }
2303
2462
  function createUseInputType(data) {
2304
- if (!data) {
2463
+ if (data === void 0 || data === null) {
2305
2464
  return [];
2306
2465
  }
2307
2466
  const result = [];
2308
2467
  for (const [typeName, useInputs] of Object.entries(data)) {
2309
2468
  const entry = {
2310
- typeName,
2311
- ALL: void 0
2469
+ ALL: void 0,
2470
+ typeName
2312
2471
  };
2313
- if (useInputs.ALL) {
2472
+ if (useInputs.ALL !== void 0 && useInputs.ALL !== "") {
2314
2473
  entry.ALL = useInputs.ALL;
2315
2474
  delete useInputs.ALL;
2316
2475
  }
@@ -2328,7 +2487,7 @@ function generateFileName(args) {
2328
2487
  const { getModelName: getModelName2, name, template, type } = args;
2329
2488
  const rawPath = pupa(template, {
2330
2489
  get model() {
2331
- const result = getModelName2(name) || "prisma";
2490
+ const result = getModelName2(name) ?? "prisma";
2332
2491
  return kebabCase(result);
2333
2492
  },
2334
2493
  get name() {
@@ -2353,61 +2512,19 @@ function generateFileName(args) {
2353
2512
 
2354
2513
  // src/helpers/factory-get-source-file.ts
2355
2514
  function factoryGetSourceFile(args) {
2356
- const { outputFilePattern, output, getModelName: getModelName2, project } = args;
2357
- return function getSourceFile(args2) {
2358
- const { name, type } = args2;
2515
+ const { getModelName: getModelName2, output, outputFilePattern, project } = args;
2516
+ return function getSourceFile(getSourceFileArgs) {
2517
+ const { name, type } = getSourceFileArgs;
2359
2518
  let filePath = generateFileName({
2360
2519
  getModelName: getModelName2,
2361
2520
  name,
2362
- type,
2363
- template: outputFilePattern
2521
+ template: outputFilePattern,
2522
+ type
2364
2523
  });
2365
2524
  filePath = `${output}/${filePath}`;
2366
- return project.getSourceFile(filePath) || project.createSourceFile(filePath, void 0, { overwrite: true });
2525
+ return project.getSourceFile(filePath) ?? project.createSourceFile(filePath, void 0, { overwrite: true });
2367
2526
  };
2368
2527
  }
2369
- function createGetModelName(modelNames) {
2370
- return memoize(tryGetName);
2371
- function tryGetName(name) {
2372
- return getModelName({ modelNames, name });
2373
- }
2374
- }
2375
- function getModelName(args) {
2376
- const { modelNames, name } = args;
2377
- for (const keyword of splitKeywords) {
2378
- const [test] = name.split(keyword, 1);
2379
- if (modelNames.includes(test)) {
2380
- return test;
2381
- }
2382
- }
2383
- for (const keyword of endsWithKeywords) {
2384
- const [test] = name.split(keyword).slice(-1);
2385
- if (modelNames.includes(test)) {
2386
- return test;
2387
- }
2388
- }
2389
- for (const [start, end2] of middleKeywords) {
2390
- let test = name.slice(start.length).slice(0, -end2.length);
2391
- if (modelNames.includes(test) && name.startsWith(start) && name.endsWith(end2)) {
2392
- return test;
2393
- }
2394
- test = name.slice(0, -(start + end2).length);
2395
- if (modelNames.includes(test) && name.endsWith(start + end2)) {
2396
- return test;
2397
- }
2398
- }
2399
- if (name.slice(-19) === "CompoundUniqueInput") {
2400
- const test = name.slice(0, -19);
2401
- const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
2402
- return models[0];
2403
- }
2404
- if (name.slice(-5) === "Count") {
2405
- const test = name.slice(0, -5);
2406
- if (modelNames.includes(test)) {
2407
- return test;
2408
- }
2409
- }
2410
- }
2411
2528
  var splitKeywords = [
2412
2529
  "CreateInput",
2413
2530
  "CreateMany",
@@ -2487,28 +2604,85 @@ var middleKeywords = [
2487
2604
  ["GroupBy", "Args"],
2488
2605
  ["OrderBy", "Args"]
2489
2606
  ];
2607
+ function createGetModelName(modelNames) {
2608
+ return memoize(tryGetName);
2609
+ function tryGetName(name) {
2610
+ return getModelName({ modelNames, name });
2611
+ }
2612
+ }
2613
+ function getModelName(args) {
2614
+ const { modelNames, name } = args;
2615
+ for (const keyword of splitKeywords) {
2616
+ const [test] = name.split(keyword, 1);
2617
+ if (test !== void 0 && modelNames.includes(test)) {
2618
+ return test;
2619
+ }
2620
+ }
2621
+ for (const keyword of endsWithKeywords) {
2622
+ const test = name.split(keyword).at(-1);
2623
+ if (test !== void 0 && modelNames.includes(test)) {
2624
+ return test;
2625
+ }
2626
+ }
2627
+ for (const [start, end2] of middleKeywords) {
2628
+ let test = name.slice(start.length).slice(0, -end2.length);
2629
+ if (modelNames.includes(test) && name.startsWith(start) && name.endsWith(end2)) {
2630
+ return test;
2631
+ }
2632
+ test = name.slice(0, -(start + end2).length);
2633
+ if (modelNames.includes(test) && name.endsWith(start + end2)) {
2634
+ return test;
2635
+ }
2636
+ }
2637
+ if (name.endsWith("CompoundUniqueInput")) {
2638
+ const test = name.slice(0, -19);
2639
+ const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
2640
+ return models[0];
2641
+ }
2642
+ if (name.endsWith("Count")) {
2643
+ const test = name.slice(0, -5);
2644
+ if (modelNames.includes(test)) {
2645
+ return test;
2646
+ }
2647
+ }
2648
+ return void 0;
2649
+ }
2490
2650
 
2491
2651
  // src/generate.ts
2492
- var requireCjs = createRequire(import.meta.url);
2493
- var AwaitEventEmitter = requireCjs("await-event-emitter").default;
2652
+ var createRequireTyped = createRequire;
2653
+ var requireCjs = createRequireTyped(String(import.meta.url));
2654
+ var AwaitEventEmitter = requireCjs(
2655
+ "await-event-emitter"
2656
+ );
2657
+ var AwaitEventEmitterClass = AwaitEventEmitter.default;
2494
2658
  async function generate(args) {
2495
2659
  const { connectCallback, dmmf, generator, skipAddOutputSourceFiles } = args;
2496
- const generatorOutputValue = generator.output?.value;
2497
- ok(generatorOutputValue, "Missing generator configuration: output");
2660
+ const generatorOutputValue = generator.output?.value ?? "";
2661
+ ok(generatorOutputValue !== "", "Missing generator configuration: output");
2498
2662
  const config = createConfig(generator.config);
2499
- const eventEmitter = new AwaitEventEmitter();
2663
+ const eventEmitter = new AwaitEventEmitterClass();
2500
2664
  eventEmitter.on("Warning", warning);
2501
- config.emitBlocks.models && eventEmitter.on("Model", modelData);
2665
+ if (config.emitBlocks.models) {
2666
+ eventEmitter.on("Model", modelData);
2667
+ }
2502
2668
  if (config.emitBlocks.prismaEnums || config.emitBlocks.schemaEnums) {
2503
2669
  eventEmitter.on("EnumType", registerEnum);
2504
2670
  }
2505
2671
  if (config.emitBlocks.outputs || config.emitBlocks.models && !config.omitModelsCount) {
2506
2672
  eventEmitter.on("OutputType", outputType);
2507
2673
  }
2508
- config.emitBlocks.models && eventEmitter.on("ModelOutputType", modelOutputType);
2509
- config.emitBlocks.outputs && eventEmitter.on("AggregateOutput", createAggregateInput);
2510
- config.emitBlocks.inputs && eventEmitter.on("InputType", inputType);
2511
- config.emitBlocks.args && eventEmitter.on("ArgsType", argsType);
2674
+ if (config.emitBlocks.models) {
2675
+ eventEmitter.on("ModelOutputType", modelOutputType);
2676
+ }
2677
+ if (config.emitBlocks.outputs) {
2678
+ eventEmitter.on("AggregateOutput", createAggregateInput);
2679
+ }
2680
+ if (config.emitBlocks.inputs) {
2681
+ eventEmitter.on("InputType", inputType);
2682
+ }
2683
+ if (config.emitBlocks.args) {
2684
+ eventEmitter.on("ArgsType", argsType);
2685
+ }
2512
2686
  eventEmitter.on("GenerateFiles", generateFiles);
2513
2687
  for (const message of config.$warnings) {
2514
2688
  eventEmitter.emitSync("Warning", message);
@@ -2521,18 +2695,30 @@ async function generate(args) {
2521
2695
  skipLoadingLibFiles: !config.emitCompiled,
2522
2696
  tsConfigFilePath: config.tsConfigFilePath
2523
2697
  });
2524
- if (!skipAddOutputSourceFiles) {
2698
+ if (skipAddOutputSourceFiles !== true) {
2525
2699
  project.addSourceFilesAtPaths([
2526
2700
  `${generatorOutputValue}/**/*.ts`,
2527
2701
  `!${generatorOutputValue}/**/*.d.ts`
2528
2702
  ]);
2529
2703
  }
2530
- config.combineScalarFilters && combineScalarFilters(eventEmitter);
2531
- config.noAtomicOperations && noAtomicOperations(eventEmitter);
2532
- config.reExport !== "None" /* None */ && reExport(eventEmitter);
2533
- config.emitSingle && emitSingle(eventEmitter);
2534
- config.purgeOutput && purgeOutput(eventEmitter);
2535
- config.requireSingleFieldsInWhereUniqueInput && requireSingleFieldsInWhereUniqueInput(eventEmitter);
2704
+ if (config.combineScalarFilters) {
2705
+ combineScalarFilters(eventEmitter);
2706
+ }
2707
+ if (config.noAtomicOperations) {
2708
+ noAtomicOperations(eventEmitter);
2709
+ }
2710
+ if (config.reExport !== "None" /* None */) {
2711
+ reExport(eventEmitter);
2712
+ }
2713
+ if (config.emitSingle) {
2714
+ emitSingle(eventEmitter);
2715
+ }
2716
+ if (config.purgeOutput) {
2717
+ purgeOutput(eventEmitter);
2718
+ }
2719
+ if (config.requireSingleFieldsInWhereUniqueInput) {
2720
+ requireSingleFieldsInWhereUniqueInput(eventEmitter);
2721
+ }
2536
2722
  const models = /* @__PURE__ */ new Map();
2537
2723
  const modelNames = [];
2538
2724
  const modelFields = /* @__PURE__ */ new Map();
@@ -2546,7 +2732,8 @@ async function generate(args) {
2546
2732
  });
2547
2733
  const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf));
2548
2734
  const removeTypes = /* @__PURE__ */ new Set();
2549
- const allModels = [...datamodel.models, ...datamodel.types ?? []];
2735
+ const datamodelTypes = datamodel.types ?? [];
2736
+ const allModels = [...datamodel.models, ...datamodelTypes];
2550
2737
  const dependencyGraph = buildDependencyGraph(allModels);
2551
2738
  const circularDependencies = detectCircularDependencies(dependencyGraph);
2552
2739
  const eventArguments = {
@@ -2578,7 +2765,7 @@ async function generate(args) {
2578
2765
  for (const model of datamodel.models) {
2579
2766
  await eventEmitter.emit("Model", model, eventArguments);
2580
2767
  }
2581
- for (const model of datamodel.types ?? []) {
2768
+ for (const model of datamodelTypes) {
2582
2769
  await eventEmitter.emit("Model", model, eventArguments);
2583
2770
  }
2584
2771
  const { enumTypes, inputObjectTypes, outputObjectTypes } = schema;
@@ -2623,7 +2810,9 @@ async function generate(args) {
2623
2810
  await eventEmitter.emit("BeforeGenerateFiles", eventArguments);
2624
2811
  await eventEmitter.emit("GenerateFiles", eventArguments);
2625
2812
  await eventEmitter.emit("End", eventArguments);
2626
- for (const name of Object.keys(eventEmitter._events)) {
2813
+ for (const name of Object.keys(
2814
+ eventEmitter._events
2815
+ )) {
2627
2816
  eventEmitter.off(name);
2628
2817
  }
2629
2818
  }