@pegasusheavy/nestjs-prisma-graphql 1.2.3 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { existsSync, readdirSync, rmdirSync } from 'fs';
1
+ import { existsSync, readdirSync, rmdirSync as rmdirSync$1 } from 'fs';
2
2
  import { createRequire } from 'module';
3
3
  import { arch, platform } from 'os';
4
4
  import generatorHelper from '@prisma/generator-helper';
5
- import { ok } from 'assert';
6
5
  import { memoize, mapKeys, merge, trim, castArray, uniqWith, isEqual, countBy, startCase, camelCase, keyBy, remove, partition, kebabCase, isObject, omit, cloneDeep } from 'lodash-es';
7
6
  import { Project, QuoteKind, StructureKind } from 'ts-morph';
7
+ import { ok as ok$1 } from 'assert';
8
8
  import JSON52 from 'json5';
9
9
  import pupa from 'pupa';
10
10
  import getRelativePath from 'get-relative-path';
@@ -14,6 +14,12 @@ import filenamify from 'filenamify';
14
14
  import pluralize from 'pluralize';
15
15
 
16
16
  // src/index.ts
17
+ function ok(value, message) {
18
+ ok$1(
19
+ value,
20
+ message
21
+ );
22
+ }
17
23
 
18
24
  // src/helpers/is-many-and-return.ts
19
25
  function isManyAndReturnOutputType(name) {
@@ -32,8 +38,10 @@ function argsType(field, args) {
32
38
  if (["queryRaw", "executeRaw"].includes(field.name)) {
33
39
  return;
34
40
  }
35
- if (isManyAndReturnOutputType(field.name)) return;
36
- const { eventEmitter, typeNames, getModelName: getModelName2 } = args;
41
+ if (isManyAndReturnOutputType(field.name)) {
42
+ return;
43
+ }
44
+ const { eventEmitter, getModelName: getModelName2, typeNames } = args;
37
45
  let className = pascalCase(`${field.name}Args`);
38
46
  const modelName = getModelName2(className) ?? "";
39
47
  switch (className) {
@@ -48,8 +56,8 @@ function argsType(field, args) {
48
56
  }
49
57
  const inputType2 = {
50
58
  constraints: { maxNumFields: null, minNumFields: null },
51
- name: className,
52
- fields: [...field.args]
59
+ fields: [...field.args],
60
+ name: className
53
61
  };
54
62
  if (!field.args.some((x) => x.name === "_count") && [`${modelName}AggregateArgs`, `${modelName}GroupByArgs`].includes(className)) {
55
63
  const names = ["Count", "Avg", "Sum", "Min", "Max"];
@@ -64,24 +72,24 @@ function argsType(field, args) {
64
72
  continue;
65
73
  }
66
74
  inputType2.fields.push({
67
- name: `_${name.toLowerCase()}`,
68
- isRequired: false,
69
- isNullable: true,
70
75
  inputTypes: [
71
76
  {
77
+ isList: false,
72
78
  location: "inputObjectTypes",
73
- type: `${modelName}${name}AggregateInput`,
74
- isList: false
79
+ type: `${modelName}${name}AggregateInput`
75
80
  }
76
- ]
81
+ ],
82
+ isNullable: true,
83
+ isRequired: false,
84
+ name: `_${name.toLowerCase()}`
77
85
  });
78
86
  }
79
87
  }
80
88
  eventEmitter.emitSync("InputType", {
81
89
  ...args,
82
- inputType: inputType2,
90
+ classDecoratorName: "ArgsType",
83
91
  fileType: "args",
84
- classDecoratorName: "ArgsType"
92
+ inputType: inputType2
85
93
  });
86
94
  }
87
95
 
@@ -106,7 +114,7 @@ function beforeGenerateField(field) {
106
114
  if (fieldInput.location !== "inputObjectTypes") {
107
115
  continue;
108
116
  }
109
- const fieldInputType = String(fieldInput.type);
117
+ const fieldInputType = fieldInput.type;
110
118
  if (isContainBogus(fieldInputType)) {
111
119
  fieldInput.type = replaceBogus(fieldInputType);
112
120
  }
@@ -197,32 +205,98 @@ function createAggregateInput(args) {
197
205
  const className = `${outputType2.name}Input`;
198
206
  const inputType2 = {
199
207
  constraints: { maxNumFields: null, minNumFields: null },
200
- name: className,
201
208
  fields: outputType2.fields.map((x) => ({
202
- name: x.name,
203
- isNullable: x.isNullable ?? true,
204
- isRequired: false,
205
209
  inputTypes: [
206
210
  {
207
211
  isList: false,
208
- type: "true",
209
- location: "scalar"
212
+ location: "scalar",
213
+ type: "true"
210
214
  }
211
- ]
212
- }))
215
+ ],
216
+ isNullable: x.isNullable ?? true,
217
+ isRequired: false,
218
+ name: x.name
219
+ })),
220
+ name: className
213
221
  };
214
222
  eventEmitter.emitSync("InputType", {
215
223
  ...args,
216
- inputType: inputType2,
224
+ classDecoratorName: "InputType",
217
225
  fileType: "input",
218
- classDecoratorName: "InputType"
226
+ inputType: inputType2
227
+ });
228
+ }
229
+
230
+ // src/handlers/decimal-helpers.ts
231
+ function generateDecimalHelpers(args) {
232
+ const { output, project } = args;
233
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
234
+ const sourceFile = rootDirectory.createSourceFile("decimal-helpers.ts", void 0, {
235
+ overwrite: true
236
+ });
237
+ const helpersCode = `/**
238
+ * Decimal Helpers for Prisma GraphQL
239
+ *
240
+ * This module provides utilities for transforming Decimal values
241
+ * between GraphQL and Prisma, compatible with Prisma 7+.
242
+ *
243
+ * These functions replace the prisma-graphql-type-decimal package
244
+ * which is incompatible with Prisma 7's new client structure.
245
+ */
246
+
247
+ import Decimal from 'decimal.js';
248
+
249
+ /**
250
+ * Reconstruct a Decimal from a serialized object.
251
+ * Prisma serializes Decimals as objects with d, e, s properties.
252
+ */
253
+ function createDecimalFromObject(object: { d: number[]; e: number; s: number }): Decimal {
254
+ return Object.create(Decimal.prototype, {
255
+ d: { value: object.d },
256
+ e: { value: object.e },
257
+ s: { value: object.s },
219
258
  });
220
259
  }
260
+
261
+ /**
262
+ * Transform input values to Decimal instances.
263
+ * Used as a class-transformer Transform decorator argument.
264
+ *
265
+ * @param params - The transform parameters from class-transformer
266
+ * @returns The transformed Decimal or array of Decimals
267
+ */
268
+ export function transformToDecimal({ value }: { value: unknown }): Decimal | Decimal[] | null | undefined {
269
+ if (value == null) return value as null | undefined;
270
+
271
+ if (Array.isArray(value)) {
272
+ return value.map((v) => {
273
+ if (v instanceof Decimal) return v;
274
+ if (typeof v === 'object' && v !== null && 'd' in v && 'e' in v && 's' in v) {
275
+ return createDecimalFromObject(v as { d: number[]; e: number; s: number });
276
+ }
277
+ return new Decimal(v as string | number);
278
+ });
279
+ }
280
+
281
+ if (value instanceof Decimal) return value;
282
+ if (typeof value === 'object' && value !== null && 'd' in value && 'e' in value && 's' in value) {
283
+ return createDecimalFromObject(value as { d: number[]; e: number; s: number });
284
+ }
285
+ return new Decimal(value as string | number);
286
+ }
287
+
288
+ /**
289
+ * Re-export Decimal class for convenience
290
+ */
291
+ export { Decimal };
292
+ `;
293
+ sourceFile.addStatements(helpersCode);
294
+ }
221
295
  function emitSingle(emitter) {
222
296
  emitter.on("ClassProperty", classProperty);
223
297
  }
224
298
  function classProperty(property, eventArguments) {
225
- const { location, isList, propertyType } = eventArguments;
299
+ const { isList, location, propertyType } = eventArguments;
226
300
  if (["inputObjectTypes", "outputObjectTypes"].includes(location) && !isList) {
227
301
  const [safeTypes, instanceofTypes] = partition(
228
302
  propertyType,
@@ -235,7 +309,7 @@ function classProperty(property, eventArguments) {
235
309
  var ImportDeclarationMap = class extends Map {
236
310
  add(name, value, isTypeOnly) {
237
311
  if (!this.has(name)) {
238
- const structure = typeof value === "string" ? { moduleSpecifier: value, namedImports: [{ name }], isTypeOnly } : value;
312
+ const structure = typeof value === "string" ? { isTypeOnly, moduleSpecifier: value, namedImports: [{ name }] } : value;
239
313
  this.set(name, structure);
240
314
  }
241
315
  }
@@ -246,43 +320,46 @@ var ImportDeclarationMap = class extends Map {
246
320
  const typeOnlyKey = `type:${name}`;
247
321
  if (!this.has(typeOnlyKey) && !this.has(name)) {
248
322
  this.set(typeOnlyKey, {
323
+ isTypeOnly: true,
249
324
  moduleSpecifier,
250
- namedImports: [{ name }],
251
- isTypeOnly: true
325
+ namedImports: [{ name }]
252
326
  });
253
327
  }
254
328
  }
255
329
  create(args) {
256
- const { from, defaultImport, namespaceImport, namedImport, isTypeOnly } = args;
257
- let name = args.name;
330
+ const { defaultImport, from, isTypeOnly, namedImport, namespaceImport } = args;
331
+ let { name } = args;
258
332
  const value = {
333
+ defaultImport: void 0,
334
+ isTypeOnly,
259
335
  moduleSpecifier: from,
260
336
  namedImports: [],
261
- defaultImport: void 0,
262
- namespaceImport: void 0,
263
- isTypeOnly
337
+ namespaceImport: void 0
264
338
  };
265
- if (namedImport === true && namespaceImport) {
339
+ if (namedImport === true && namespaceImport !== void 0) {
266
340
  value.namedImports = [{ name: namespaceImport }];
267
341
  name = namespaceImport;
268
- } else if (defaultImport) {
342
+ } else if (defaultImport === void 0) {
343
+ if (namespaceImport === void 0) {
344
+ value.namedImports = [{ name }];
345
+ } else {
346
+ value.namespaceImport = namespaceImport;
347
+ name = namespaceImport;
348
+ }
349
+ } else {
269
350
  value.defaultImport = defaultImport === true ? name : defaultImport;
270
351
  name = value.defaultImport;
271
- } else if (namespaceImport) {
272
- value.namespaceImport = namespaceImport;
273
- name = namespaceImport;
274
- } else {
275
- value.namedImports = [{ name }];
276
352
  }
277
- const key = isTypeOnly ? `type:${name}` : name;
278
- if (!this.has(key)) {
279
- this.set(key, value);
353
+ const key = isTypeOnly === true ? `type:${name}` : name;
354
+ if (this.has(key)) {
355
+ return;
280
356
  }
357
+ this.set(key, value);
281
358
  }
282
359
  *toStatements() {
283
360
  const iterator = this.values();
284
361
  let result = iterator.next();
285
- while (result.value) {
362
+ while (result.value !== void 0) {
286
363
  yield {
287
364
  ...result.value,
288
365
  kind: StructureKind.ImportDeclaration
@@ -313,8 +390,8 @@ async function generateFiles(args) {
313
390
  for (const decorator of property.decorators ?? []) {
314
391
  const fullName = classDeclaration?.getProperty(property.name)?.getDecorator(decorator.name)?.getFullName();
315
392
  ok(
316
- fullName,
317
- `Cannot get full name of decorator of class ${statement.name}`
393
+ fullName !== void 0,
394
+ `Cannot get full name of decorator of class ${String(statement.name)}`
318
395
  );
319
396
  decorator.name = fullName;
320
397
  }
@@ -377,8 +454,13 @@ async function generateFiles(args) {
377
454
  statements: [...imports.toStatements(), ...enums, ...classes]
378
455
  });
379
456
  }
380
- const sourceFileCount = project.getSourceFiles().length;
381
- console.log(
457
+ const sourceFiles = project.getSourceFiles();
458
+ const sourceFileCount = sourceFiles.length;
459
+ const globalConsole3 = globalThis.console;
460
+ const logMessage = (msg) => {
461
+ globalConsole3.log(msg);
462
+ };
463
+ logMessage(
382
464
  `nestjs-prisma-graphql: saving ${String(sourceFileCount)} source files to ${output}`
383
465
  );
384
466
  if (sourceFileCount === 0) {
@@ -401,7 +483,21 @@ async function generateFiles(args) {
401
483
  eventEmitter.emitSync("Warning", errors);
402
484
  }
403
485
  } else {
404
- await project.save();
486
+ const BATCH_SIZE = 100;
487
+ if (sourceFileCount > BATCH_SIZE) {
488
+ logMessage(
489
+ `nestjs-prisma-graphql: using batched save for large schema (${String(sourceFileCount)} files)`
490
+ );
491
+ for (let i = 0; i < sourceFileCount; i += BATCH_SIZE) {
492
+ const batch = sourceFiles.slice(i, i + BATCH_SIZE);
493
+ logMessage(
494
+ `nestjs-prisma-graphql: saving batch ${String(Math.floor(i / BATCH_SIZE) + 1)}/${String(Math.ceil(sourceFileCount / BATCH_SIZE))} (${String(batch.length)} files)`
495
+ );
496
+ await Promise.all(batch.map(async (sf) => await sf.save()));
497
+ }
498
+ } else {
499
+ await project.save();
500
+ }
405
501
  }
406
502
  }
407
503
 
@@ -417,17 +513,23 @@ function fileTypeByLocation(fieldLocation) {
417
513
  case "enumTypes": {
418
514
  return "enum";
419
515
  }
516
+ case "fieldRefTypes":
517
+ case "scalar":
518
+ default: {
519
+ return "object";
520
+ }
420
521
  }
421
- return "object";
422
522
  }
423
523
  function relativePath(from, to) {
424
- if (!from.startsWith("/")) {
425
- from = `/${from}`;
524
+ let fromPath = from;
525
+ let toPath = to;
526
+ if (!fromPath.startsWith("/")) {
527
+ fromPath = `/${fromPath}`;
426
528
  }
427
- if (!to.startsWith("/")) {
428
- to = `/${to}`;
529
+ if (!toPath.startsWith("/")) {
530
+ toPath = `/${toPath}`;
429
531
  }
430
- let result = getRelativePath(from, to);
532
+ let result = getRelativePath(fromPath, toPath);
431
533
  if (!result.startsWith(".")) {
432
534
  result = `./${result}`;
433
535
  }
@@ -496,7 +598,7 @@ function getGraphqlImport(args) {
496
598
  }
497
599
  function getGraphqlInputType(inputTypes, pattern) {
498
600
  let result;
499
- inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(String(t.type)));
601
+ inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(t.type));
500
602
  inputTypes = uniqWith(inputTypes, isEqual);
501
603
  if (inputTypes.length === 1) {
502
604
  return inputTypes[0];
@@ -509,46 +611,44 @@ function getGraphqlInputType(inputTypes, pattern) {
509
611
  return result;
510
612
  }
511
613
  }
512
- if (pattern) {
614
+ if (pattern !== null && pattern !== void 0 && pattern.length > 0) {
513
615
  if (pattern.startsWith("matcher:") || pattern.startsWith("match:")) {
514
616
  const { 1: patternValue } = pattern.split(":", 2);
515
617
  const isMatch = outmatch2(patternValue, { separator: false });
516
- result = inputTypes.find((x) => isMatch(String(x.type)));
517
- if (result) {
618
+ result = inputTypes.find((x) => isMatch(x.type));
619
+ if (result !== void 0) {
518
620
  return result;
519
621
  }
520
622
  }
521
- result = inputTypes.find((x) => String(x.type).includes(pattern));
522
- if (result) {
623
+ result = inputTypes.find((x) => x.type.includes(pattern));
624
+ if (result !== void 0) {
523
625
  return result;
524
626
  }
525
627
  }
526
628
  result = inputTypes.find((x) => x.location === "inputObjectTypes");
527
- if (result) {
629
+ if (result !== void 0) {
528
630
  return result;
529
631
  }
530
- if (countTypes.enumTypes && countTypes.scalar && inputTypes.some((x) => x.type === "Json" && x.location === "scalar")) {
632
+ if ((countTypes.enumTypes ?? 0) > 0 && (countTypes.scalar ?? 0) > 0 && inputTypes.some((x) => x.type === "Json" && x.location === "scalar")) {
531
633
  result = inputTypes.find((x) => x.type === "Json" && x.location === "scalar");
532
- if (result) {
634
+ if (result !== void 0) {
533
635
  return result;
534
636
  }
535
637
  }
536
- if ((countTypes.scalar >= 1 || countTypes.enumTypes >= 1) && countTypes.fieldRefTypes === 1) {
638
+ if (((countTypes.scalar ?? 0) >= 1 || (countTypes.enumTypes ?? 0) >= 1) && countTypes.fieldRefTypes === 1) {
537
639
  result = inputTypes.find(
538
640
  (x) => (x.location === "scalar" || x.location === "enumTypes") && x.isList
539
641
  );
540
- if (result) {
642
+ if (result !== void 0) {
541
643
  return result;
542
644
  }
543
- result = inputTypes.find(
544
- (x) => x.location === "scalar" || x.location === "enumTypes"
545
- );
546
- if (result) {
645
+ result = inputTypes.find((x) => x.location === "scalar" || x.location === "enumTypes");
646
+ if (result !== void 0) {
547
647
  return result;
548
648
  }
549
649
  }
550
650
  throw new TypeError(
551
- `Cannot get matching input type from ${inputTypes.map((x) => x.type).join(", ") || "zero length inputTypes"}`
651
+ `Cannot get matching input type from ${inputTypes.length > 0 ? inputTypes.map((x) => x.type).join(", ") : "zero length inputTypes"}`
552
652
  );
553
653
  }
554
654
 
@@ -589,7 +689,7 @@ function getPropertyType(args) {
589
689
  return [type];
590
690
  }
591
691
  if (location === "enumTypes") {
592
- const enumType = "`${" + type + "}`";
692
+ const enumType = `\`\${${type}}\``;
593
693
  return [enumType];
594
694
  }
595
695
  if (location === "scalar") {
@@ -610,8 +710,8 @@ function getWhereUniqueAtLeastKeys(model) {
610
710
  return names;
611
711
  }
612
712
  function createFieldName(args) {
613
- const { name, fields } = args;
614
- return name || fields.join("_");
713
+ const { fields, name } = args;
714
+ return name !== null && name !== void 0 && name.length > 0 ? name : fields.join("_");
615
715
  }
616
716
 
617
717
  // src/helpers/is-where-unique-input-type.ts
@@ -620,29 +720,28 @@ function isWhereUniqueInputType(name) {
620
720
  }
621
721
  function propertyStructure(args) {
622
722
  const {
723
+ hasExclamationToken,
724
+ hasQuestionToken,
725
+ isList,
623
726
  isNullable,
624
- propertyType,
625
727
  name,
626
- isList,
627
- hasQuestionToken,
628
- hasExclamationToken
728
+ propertyType
629
729
  } = args;
630
- const type = propertyType.map((type2) => isList ? `Array<${type2}>` : type2).join(" | ");
730
+ const typeString = propertyType.map((typeItem) => isList ? `Array<${typeItem}>` : typeItem).join(" | ");
631
731
  return {
732
+ decorators: [],
733
+ hasExclamationToken: hasExclamationToken ?? !isNullable,
734
+ hasQuestionToken: hasQuestionToken ?? isNullable,
632
735
  kind: StructureKind.Property,
736
+ leadingTrivia: "\n",
633
737
  name,
634
- type,
635
- hasQuestionToken: hasQuestionToken ?? isNullable,
636
- hasExclamationToken: hasExclamationToken ?? !isNullable,
637
- decorators: [],
638
- leadingTrivia: "\n"
738
+ type: typeString
639
739
  };
640
740
  }
641
741
 
642
742
  // src/handlers/input-type.ts
643
743
  function inputType(args) {
644
744
  const {
645
- circularDependencies,
646
745
  classDecoratorName,
647
746
  classTransformerTypeModels,
648
747
  config,
@@ -651,41 +750,41 @@ function inputType(args) {
651
750
  fileType,
652
751
  getModelName: getModelName2,
653
752
  getSourceFile,
654
- inputType: inputType2,
753
+ inputType: inputTypeArg,
655
754
  models,
656
755
  output,
657
756
  removeTypes,
658
757
  typeNames
659
758
  } = args;
660
- typeNames.add(inputType2.name);
759
+ typeNames.add(inputTypeArg.name);
661
760
  const importDeclarations = new ImportDeclarationMap();
662
761
  const sourceFile = getSourceFile({
663
- name: inputType2.name,
762
+ name: inputTypeArg.name,
664
763
  type: fileType
665
764
  });
666
765
  const classStructure = {
667
- kind: StructureKind.Class,
668
- isExported: true,
669
- name: inputType2.name,
670
766
  decorators: [
671
767
  {
672
- name: classDecoratorName,
673
- arguments: []
768
+ arguments: [],
769
+ name: classDecoratorName
674
770
  }
675
771
  ],
772
+ isExported: true,
773
+ kind: StructureKind.Class,
774
+ name: inputTypeArg.name,
676
775
  properties: []
677
776
  };
678
- const modelName = getModelName2(inputType2.name) ?? "";
777
+ const modelName = getModelName2(inputTypeArg.name) ?? "";
679
778
  const model = models.get(modelName);
680
779
  const modelFieldSettings = model && fieldSettings.get(model.name);
681
780
  const moduleSpecifier = "@nestjs/graphql";
682
781
  const lazyTypes = /* @__PURE__ */ new Set();
683
782
  importDeclarations.set("Field", {
684
- namedImports: [{ name: "Field" }],
685
- moduleSpecifier
783
+ moduleSpecifier,
784
+ namedImports: [{ name: "Field" }]
686
785
  }).set(classDecoratorName, {
687
- namedImports: [{ name: classDecoratorName }],
688
- moduleSpecifier
786
+ moduleSpecifier,
787
+ namedImports: [{ name: classDecoratorName }]
689
788
  });
690
789
  if (config.esmCompatible) {
691
790
  const typeRegistryPath = relativePath(
@@ -696,11 +795,11 @@ function inputType(args) {
696
795
  importDeclarations.add("getType", typeRegistryPath);
697
796
  }
698
797
  const useInputType = config.useInputType.find(
699
- (x) => inputType2.name.includes(x.typeName)
798
+ (x) => inputTypeArg.name.includes(x.typeName)
700
799
  );
701
- const isWhereUnique = isWhereUniqueInputType(inputType2.name);
702
- for (const field of inputType2.fields) {
703
- field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(String(t.type)));
800
+ const isWhereUnique = isWhereUniqueInputType(inputTypeArg.name);
801
+ for (const field of inputTypeArg.fields) {
802
+ field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(t.type));
704
803
  eventEmitter.emitSync(BeforeGenerateField, field, args);
705
804
  const { inputTypes, isRequired, name } = field;
706
805
  if (inputTypes.length === 0) {
@@ -709,52 +808,56 @@ function inputType(args) {
709
808
  const usePattern = useInputType?.ALL ?? useInputType?.[name];
710
809
  const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
711
810
  const { isList, location, type } = graphqlInputType;
712
- const typeName = String(type);
811
+ const typeName = type;
713
812
  const settings = modelFieldSettings?.get(name);
714
813
  const propertySettings = settings?.getPropertyType({
715
- name: inputType2.name,
716
- input: true
814
+ input: true,
815
+ name: inputTypeArg.name
717
816
  });
718
817
  const modelField = model?.fields.find((f) => f.name === name);
719
818
  const isCustomsApplicable = typeName === modelField?.type;
720
819
  const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
721
820
  const whereUniqueInputTypeValue = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((n) => `'${n}'`).join(" | ")}>`;
722
821
  const propertyType = castArray(
723
- propertySettings?.name ?? (whereUniqueInputTypeValue || getPropertyType({
822
+ propertySettings?.name ?? whereUniqueInputTypeValue ?? getPropertyType({
724
823
  location,
725
824
  type: typeName
726
- }))
825
+ })
727
826
  );
728
827
  const hasExclamationToken = Boolean(
729
828
  isWhereUnique && config.unsafeCompatibleWhereUniqueInput && atLeastKeys?.includes(name)
730
829
  );
731
830
  const property = propertyStructure({
732
- name,
733
- isNullable: !isRequired,
734
831
  hasExclamationToken: hasExclamationToken || void 0,
735
832
  hasQuestionToken: hasExclamationToken ? false : void 0,
736
- propertyType,
737
- isList
833
+ isList,
834
+ isNullable: !isRequired,
835
+ name,
836
+ propertyType
738
837
  });
739
- classStructure.properties.push(property);
838
+ if (classStructure.properties) {
839
+ classStructure.properties.push(property);
840
+ }
740
841
  if (propertySettings) {
741
842
  importDeclarations.create({ ...propertySettings });
742
- } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
843
+ } else if (propertyType.some(
844
+ (p) => typeof p === "string" && p.includes("Prisma.Decimal")
845
+ )) {
743
846
  importDeclarations.add("Prisma", config.prismaClientImport);
744
- } else if (propertyType.some((p) => p.startsWith("Prisma."))) {
847
+ } else if (propertyType.some((p) => typeof p === "string" && p.startsWith("Prisma."))) {
745
848
  importDeclarations.add("Prisma", config.prismaClientImport);
746
849
  }
747
850
  let graphqlType;
748
851
  let useGetType = false;
749
852
  const shouldHideField = settings?.shouldHideField({
750
- name: inputType2.name,
751
- input: true
752
- }) || config.decorate.some(
753
- (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
853
+ input: true,
854
+ name: inputTypeArg.name
855
+ }) ?? config.decorate.some(
856
+ (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputTypeArg.name)
754
857
  );
755
858
  const fieldType = settings?.getFieldType({
756
- name: inputType2.name,
757
- input: true
859
+ input: true,
860
+ name: inputTypeArg.name
758
861
  });
759
862
  if (fieldType && isCustomsApplicable && !shouldHideField) {
760
863
  graphqlType = fieldType.name;
@@ -762,29 +865,28 @@ function inputType(args) {
762
865
  } else {
763
866
  const graphqlImport = getGraphqlImport({
764
867
  config,
765
- sourceFile,
868
+ getSourceFile,
766
869
  location,
767
- typeName,
768
- getSourceFile
870
+ sourceFile,
871
+ typeName
769
872
  });
770
873
  graphqlType = graphqlImport.name;
771
- let referenceName = propertyType[0];
772
874
  if (location === "enumTypes") {
773
- const parts = referenceName.split(" ");
774
- referenceName = parts.at(-1) ?? parts[0];
875
+ const parts = String(propertyType[0]).split(" ");
876
+ parts.at(-1);
775
877
  }
776
878
  const shouldUseLazyType = config.esmCompatible && location === "inputObjectTypes";
777
- if (graphqlImport.name === inputType2.name && shouldUseLazyType) {
879
+ if (graphqlImport.name === inputTypeArg.name && shouldUseLazyType) {
778
880
  lazyTypes.add(graphqlImport.name);
779
881
  useGetType = true;
780
- } else if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputType2.name) {
882
+ } else if (graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputTypeArg.name) {
781
883
  if (shouldUseLazyType) {
782
884
  importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
783
885
  lazyTypes.add(graphqlImport.name);
784
886
  } else {
785
887
  importDeclarations.set(graphqlImport.name, {
786
- namedImports: [{ name: graphqlImport.name }],
787
- moduleSpecifier: graphqlImport.specifier
888
+ moduleSpecifier: graphqlImport.specifier,
889
+ namedImports: [{ name: graphqlImport.name }]
788
890
  });
789
891
  }
790
892
  }
@@ -792,10 +894,13 @@ function inputType(args) {
792
894
  useGetType = true;
793
895
  }
794
896
  }
795
- ok(property.decorators, "property.decorators is undefined");
897
+ ok(
898
+ property.decorators !== void 0 && property.decorators !== null,
899
+ "property.decorators is undefined"
900
+ );
796
901
  if (shouldHideField) {
797
902
  importDeclarations.add("HideField", moduleSpecifier);
798
- property.decorators.push({ name: "HideField", arguments: [] });
903
+ property.decorators.push({ arguments: [], name: "HideField" });
799
904
  } else {
800
905
  let typeExpression;
801
906
  if (useGetType) {
@@ -804,14 +909,14 @@ function inputType(args) {
804
909
  typeExpression = isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`;
805
910
  }
806
911
  property.decorators.push({
807
- name: "Field",
808
912
  arguments: [
809
913
  typeExpression,
810
914
  JSON52.stringify({
811
915
  ...settings?.fieldArguments(),
812
916
  nullable: !isRequired
813
917
  })
814
- ]
918
+ ],
919
+ name: "Field"
815
920
  });
816
921
  if (graphqlType === "GraphQLDecimal") {
817
922
  const decimalHelpersPath = relativePath(
@@ -823,12 +928,12 @@ function inputType(args) {
823
928
  importDeclarations.add("Type", "class-transformer");
824
929
  property.decorators.push(
825
930
  {
826
- name: "Type",
827
- arguments: ["() => Object"]
931
+ arguments: ["() => Object"],
932
+ name: "Type"
828
933
  },
829
934
  {
830
- name: "Transform",
831
- arguments: ["transformToDecimal"]
935
+ arguments: ["transformToDecimal"],
936
+ name: "Transform"
832
937
  }
833
938
  );
834
939
  } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
@@ -845,44 +950,47 @@ function inputType(args) {
845
950
  "updateMany",
846
951
  "upsert",
847
952
  "where"
848
- ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type) && models.get(modelField.type)?.fields.some(
953
+ ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type)?.fields.some(
849
954
  (f) => f.kind === "object" && classTransformerTypeModels.has(f.type)
850
- ))) {
955
+ ) === true)) {
851
956
  importDeclarations.add("Type", "class-transformer");
852
957
  if (useGetType) {
853
958
  property.decorators.push({
854
- name: "Type",
855
- arguments: [`getType('${graphqlType}')`]
959
+ arguments: [`getType('${graphqlType}')`],
960
+ name: "Type"
856
961
  });
857
962
  } else {
858
- property.decorators.push({ name: "Type", arguments: [`() => ${graphqlType}`] });
963
+ property.decorators.push({ arguments: [`() => ${graphqlType}`], name: "Type" });
859
964
  }
860
965
  }
861
966
  if (isCustomsApplicable) {
862
967
  for (const options of settings ?? []) {
863
968
  if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
864
969
  property.decorators.push({
865
- name: options.name,
866
- arguments: options.arguments
970
+ arguments: options.arguments,
971
+ name: options.name
867
972
  });
868
- ok(options.from, "Missed 'from' part in configuration or field setting");
973
+ ok(
974
+ options.from !== void 0 && options.from !== null && options.from !== "",
975
+ "Missed 'from' part in configuration or field setting"
976
+ );
869
977
  importDeclarations.create(options);
870
978
  }
871
979
  }
872
980
  }
873
981
  for (const decorate of config.decorate) {
874
- if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
982
+ if (decorate.isMatchField(name) && decorate.isMatchType(inputTypeArg.name)) {
875
983
  property.decorators.push({
876
- name: decorate.name,
877
- arguments: decorate.arguments?.map((x) => pupa(x, { propertyType }))
984
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType })),
985
+ name: decorate.name
878
986
  });
879
987
  importDeclarations.create(decorate);
880
988
  }
881
989
  }
882
990
  }
883
991
  eventEmitter.emitSync("ClassProperty", property, {
884
- location,
885
992
  isList,
993
+ location,
886
994
  propertyType
887
995
  });
888
996
  }
@@ -892,7 +1000,7 @@ function inputType(args) {
892
1000
  ];
893
1001
  if (config.esmCompatible) {
894
1002
  statements.push(`
895
- registerType('${inputType2.name}', ${inputType2.name});`);
1003
+ registerType('${inputTypeArg.name}', ${inputTypeArg.name});`);
896
1004
  }
897
1005
  sourceFile.set({
898
1006
  statements
@@ -900,8 +1008,8 @@ registerType('${inputType2.name}', ${inputType2.name});`);
900
1008
  }
901
1009
  var ObjectSettings = class extends Array {
902
1010
  shouldHideField({
903
- name,
904
1011
  input = false,
1012
+ name,
905
1013
  output = false
906
1014
  }) {
907
1015
  const hideField = this.find((s) => s.name === "HideField");
@@ -910,8 +1018,8 @@ var ObjectSettings = class extends Array {
910
1018
  );
911
1019
  }
912
1020
  getFieldType({
913
- name,
914
1021
  input,
1022
+ name,
915
1023
  output
916
1024
  }) {
917
1025
  const fieldType = this.find((s) => s.kind === "FieldType");
@@ -930,8 +1038,8 @@ var ObjectSettings = class extends Array {
930
1038
  return fieldType;
931
1039
  }
932
1040
  getPropertyType({
933
- name,
934
1041
  input,
1042
+ name,
935
1043
  output
936
1044
  }) {
937
1045
  const propertyType = this.find((s) => s.kind === "PropertyType");
@@ -954,19 +1062,20 @@ var ObjectSettings = class extends Array {
954
1062
  const resultArguments = [objectTypeOptions];
955
1063
  const objectType = this.find((s) => s.kind === "ObjectType");
956
1064
  if (objectType && isObject(objectType.arguments)) {
957
- const name = objectType.arguments.name;
1065
+ const { name } = objectType.arguments;
958
1066
  merge(objectTypeOptions, omit(objectType.arguments, "name"));
959
- if (name) {
1067
+ if (name !== null && name !== void 0 && name !== "") {
960
1068
  resultArguments.unshift(name);
961
1069
  }
962
1070
  }
963
1071
  return resultArguments.map((x) => JSON52.stringify(x));
964
1072
  }
965
1073
  fieldArguments() {
966
- const item = this.find((item2) => item2.kind === "Field");
967
- if (item) {
968
- return item.arguments;
1074
+ const fieldItem = this.find((item) => item.kind === "Field");
1075
+ if (fieldItem) {
1076
+ return fieldItem.arguments;
969
1077
  }
1078
+ return void 0;
970
1079
  }
971
1080
  };
972
1081
  function createObjectSettings(args) {
@@ -976,18 +1085,23 @@ function createObjectSettings(args) {
976
1085
  const documentationLines = [];
977
1086
  let fieldElement = result.find((item) => item.kind === "Field");
978
1087
  if (!fieldElement) {
979
- fieldElement = {
980
- name: "",
1088
+ const newFieldElement = {
1089
+ arguments: {},
1090
+ from: "",
1091
+ input: false,
981
1092
  kind: "Field",
982
- arguments: {}
1093
+ model: false,
1094
+ name: "",
1095
+ output: false
983
1096
  };
1097
+ fieldElement = newFieldElement;
984
1098
  }
985
1099
  for (const line of textLines) {
986
1100
  const match = /^@(?<name>\w+(\.(\w+))?)\((?<args>.*)\)/.exec(line);
987
- const { element, documentLine } = createSettingElement({
988
- line,
1101
+ const { documentLine, element } = createSettingElement({
989
1102
  config,
990
1103
  fieldElement,
1104
+ line,
991
1105
  match
992
1106
  });
993
1107
  if (element) {
@@ -998,14 +1112,14 @@ function createObjectSettings(args) {
998
1112
  }
999
1113
  }
1000
1114
  return {
1001
- settings: result,
1002
- documentation: documentationLines.filter(Boolean).join("\n") || void 0
1115
+ documentation: documentationLines.filter(Boolean).join("\n") || void 0,
1116
+ settings: result
1003
1117
  };
1004
1118
  }
1005
1119
  function createSettingElement({
1006
- line,
1007
1120
  config,
1008
1121
  fieldElement,
1122
+ line,
1009
1123
  match
1010
1124
  }) {
1011
1125
  const result = {
@@ -1013,75 +1127,95 @@ function createSettingElement({
1013
1127
  element: void 0
1014
1128
  };
1015
1129
  if (line.startsWith("@deprecated")) {
1016
- fieldElement.arguments["deprecationReason"] = trim(line.slice(11));
1017
- result.element = fieldElement;
1130
+ const DEPRECATED_PREFIX_LENGTH = 11;
1131
+ const updatedFieldElement = {
1132
+ ...fieldElement,
1133
+ arguments: {
1134
+ ...fieldElement.arguments,
1135
+ deprecationReason: trim(line.slice(DEPRECATED_PREFIX_LENGTH))
1136
+ }
1137
+ };
1138
+ result.element = updatedFieldElement;
1018
1139
  return result;
1019
1140
  }
1020
1141
  if (line.startsWith("@complexity")) {
1021
- let n = Number.parseInt(trim(line.slice(11)));
1022
- if (n !== n || n < 1) n = 1;
1023
- fieldElement.arguments["complexity"] = n;
1024
- result.element = fieldElement;
1142
+ const COMPLEXITY_PREFIX_LENGTH = 11;
1143
+ const MIN_COMPLEXITY = 1;
1144
+ let n = Number.parseInt(trim(line.slice(COMPLEXITY_PREFIX_LENGTH)), 10);
1145
+ if (Number.isNaN(n) || n < MIN_COMPLEXITY) {
1146
+ n = MIN_COMPLEXITY;
1147
+ }
1148
+ const updatedFieldElement = {
1149
+ ...fieldElement,
1150
+ arguments: {
1151
+ ...fieldElement.arguments,
1152
+ complexity: n
1153
+ }
1154
+ };
1155
+ result.element = updatedFieldElement;
1025
1156
  return result;
1026
1157
  }
1027
1158
  const name = match?.groups?.name;
1028
- if (!(match && name)) {
1159
+ if (!(match && name !== void 0 && name !== "")) {
1029
1160
  result.documentLine = line;
1030
1161
  return result;
1031
1162
  }
1032
1163
  const element = {
1033
- kind: "Decorator",
1034
- name: "",
1035
1164
  arguments: [],
1165
+ from: "",
1036
1166
  input: false,
1037
- output: false,
1167
+ kind: "Decorator",
1038
1168
  model: false,
1039
- from: ""
1169
+ name: "",
1170
+ output: false
1040
1171
  };
1041
1172
  result.element = element;
1042
1173
  if (name === "TypeGraphQL.omit" || name === "HideField") {
1043
1174
  Object.assign(element, hideFieldDecorator(match));
1044
1175
  return result;
1045
1176
  }
1046
- if (["FieldType", "PropertyType"].includes(name) && match.groups?.args) {
1177
+ if (["FieldType", "PropertyType"].includes(name) && match.groups?.args !== void 0 && match.groups.args !== "") {
1047
1178
  const options2 = customType(match.groups.args);
1048
- merge(element, options2.namespace && config.fields[options2.namespace], options2, {
1179
+ const namespaceConfig2 = options2.namespace !== void 0 && options2.namespace !== "" ? config.fields[options2.namespace] : void 0;
1180
+ merge(element, namespaceConfig2, options2, {
1049
1181
  kind: name
1050
1182
  });
1051
1183
  return result;
1052
1184
  }
1053
- if (name === "ObjectType" && match.groups?.args) {
1185
+ if (name === "ObjectType" && match.groups?.args !== void 0 && match.groups.args !== "") {
1054
1186
  element.kind = "ObjectType";
1055
1187
  const options2 = customType(match.groups.args);
1056
- if (typeof options2[0] === "string" && options2[0]) {
1188
+ if (typeof options2[0] === "string" && options2[0] !== "") {
1057
1189
  options2.name = options2[0];
1058
1190
  }
1059
1191
  if (isObject(options2[1])) {
1060
1192
  merge(options2, options2[1]);
1061
1193
  }
1062
1194
  element.arguments = {
1063
- name: options2.name,
1064
- isAbstract: options2.isAbstract
1195
+ isAbstract: options2.isAbstract,
1196
+ name: options2.name
1065
1197
  };
1066
1198
  return result;
1067
1199
  }
1068
- if (name === "Directive" && match.groups?.args) {
1200
+ if (name === "Directive" && match.groups?.args !== void 0 && match.groups.args !== "") {
1069
1201
  const options2 = customType(match.groups.args);
1070
- merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
1071
- name,
1072
- namespace: false,
1202
+ merge(element, { from: "@nestjs/graphql", model: true }, options2, {
1203
+ arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => JSON52.stringify(s)) : options2.arguments,
1073
1204
  kind: "Decorator",
1074
- arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => JSON52.stringify(s)) : options2.arguments
1205
+ name,
1206
+ namespace: false
1075
1207
  });
1076
1208
  return result;
1077
1209
  }
1078
1210
  const namespace = getNamespace(name);
1079
1211
  element.namespaceImport = namespace;
1212
+ const args = match.groups?.args ?? "";
1080
1213
  const options = {
1081
- name,
1082
- arguments: (match.groups?.args || "").split(",").map((s) => trim(s)).filter(Boolean)
1214
+ arguments: args.split(",").map((s) => trim(s)).filter(Boolean),
1215
+ name
1083
1216
  };
1084
- merge(element, namespace && config.fields[namespace], options);
1217
+ const namespaceConfig = namespace !== void 0 && namespace !== "" ? config.fields[namespace] : void 0;
1218
+ merge(element, namespaceConfig, options);
1085
1219
  return result;
1086
1220
  }
1087
1221
  function customType(args) {
@@ -1093,7 +1227,8 @@ function customType(args) {
1093
1227
  Object.assign(result, options);
1094
1228
  const namespace = getNamespace(options.name);
1095
1229
  result.namespace = namespace;
1096
- if (options.name?.includes(".")) {
1230
+ const optionsWithName = options;
1231
+ if (optionsWithName.name !== void 0 && optionsWithName.name !== "" && optionsWithName.name.includes(".")) {
1097
1232
  result.namespaceImport = namespace;
1098
1233
  }
1099
1234
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -1103,29 +1238,30 @@ function customType(args) {
1103
1238
  }
1104
1239
  function hideFieldDecorator(match) {
1105
1240
  const result = {
1106
- name: "HideField",
1107
1241
  arguments: [],
1108
- from: "@nestjs/graphql",
1109
1242
  defaultImport: void 0,
1110
- namespaceImport: void 0,
1111
- match: void 0
1243
+ from: "@nestjs/graphql",
1244
+ match: void 0,
1245
+ name: "HideField",
1246
+ namespaceImport: void 0
1112
1247
  };
1113
- if (!match.groups?.args) {
1248
+ const args = match.groups?.args;
1249
+ if (args === void 0 || args === "") {
1114
1250
  result.output = true;
1115
1251
  return result;
1116
1252
  }
1117
- if (match.groups.args.includes("{") && match.groups.args.includes("}")) {
1118
- const options = parseArgs(match.groups.args);
1253
+ if (args.includes("{") && args.includes("}")) {
1254
+ const options = parseArgs(args);
1119
1255
  result.output = Boolean(options.output);
1120
1256
  result.input = Boolean(options.input);
1121
1257
  if (typeof options.match === "string" || Array.isArray(options.match)) {
1122
1258
  result.match = outmatch2(options.match, { separator: false });
1123
1259
  }
1124
1260
  } else {
1125
- if (/output:\s*true/.test(match.groups.args)) {
1261
+ if (/output:\s*true/.test(args)) {
1126
1262
  result.output = true;
1127
1263
  }
1128
- if (/input:\s*true/.test(match.groups.args)) {
1264
+ if (/input:\s*true/.test(args)) {
1129
1265
  result.input = true;
1130
1266
  }
1131
1267
  }
@@ -1143,12 +1279,22 @@ function parseArgs(string) {
1143
1279
  }
1144
1280
  }
1145
1281
  function getNamespace(name) {
1146
- if (name === void 0) {
1282
+ if (name === void 0 || name === null) {
1283
+ return void 0;
1284
+ }
1285
+ if (typeof name !== "string") {
1286
+ return void 0;
1287
+ }
1288
+ let result = name;
1289
+ if (result === "") {
1147
1290
  return void 0;
1148
1291
  }
1149
- let result = String(name);
1150
1292
  if (result.includes(".")) {
1151
- [result] = result.split(".");
1293
+ const parts = result.split(".");
1294
+ result = parts[0] ?? "";
1295
+ }
1296
+ if (result === "") {
1297
+ return void 0;
1152
1298
  }
1153
1299
  return result;
1154
1300
  }
@@ -1156,12 +1302,12 @@ function getNamespace(name) {
1156
1302
  // src/handlers/model-data.ts
1157
1303
  function modelData(model, args) {
1158
1304
  const {
1305
+ classTransformerTypeModels,
1159
1306
  config,
1160
- modelNames,
1161
- models,
1162
- modelFields,
1163
1307
  fieldSettings,
1164
- classTransformerTypeModels
1308
+ modelFields,
1309
+ modelNames,
1310
+ models
1165
1311
  } = args;
1166
1312
  modelNames.push(model.name);
1167
1313
  models.set(model.name, model);
@@ -1170,10 +1316,10 @@ function modelData(model, args) {
1170
1316
  const fieldSettingsValue = /* @__PURE__ */ new Map();
1171
1317
  fieldSettings.set(model.name, fieldSettingsValue);
1172
1318
  for (const field of model.fields) {
1173
- if (field.documentation) {
1319
+ if (field.documentation !== null && field.documentation !== void 0 && field.documentation.length > 0) {
1174
1320
  const { documentation, settings } = createObjectSettings({
1175
- text: field.documentation,
1176
- config
1321
+ config,
1322
+ text: field.documentation
1177
1323
  });
1178
1324
  field.documentation = documentation;
1179
1325
  fieldSettingsValue.set(field.name, settings);
@@ -1192,8 +1338,14 @@ function createComment(documentation, settings) {
1192
1338
  for (const line of documentationLines) {
1193
1339
  commentLines.push(` * ${line}`);
1194
1340
  }
1195
- const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1196
- if (deprecationReason) {
1341
+ const fieldArgs = settings?.fieldArguments();
1342
+ let deprecationReason;
1343
+ if (fieldArgs === void 0) {
1344
+ deprecationReason = void 0;
1345
+ } else {
1346
+ deprecationReason = fieldArgs.deprecationReason;
1347
+ }
1348
+ if (deprecationReason !== void 0 && deprecationReason !== null && deprecationReason.length > 0) {
1197
1349
  commentLines.push(` * @deprecated ${deprecationReason}`);
1198
1350
  }
1199
1351
  commentLines.push(" */\n");
@@ -1208,6 +1360,9 @@ function buildDependencyGraph(models) {
1208
1360
  }
1209
1361
  for (const model of models) {
1210
1362
  const dependencies = graph.get(model.name);
1363
+ if (!dependencies) {
1364
+ continue;
1365
+ }
1211
1366
  for (const field of model.fields) {
1212
1367
  if (field.kind === "object" && field.type !== model.name) {
1213
1368
  if (graph.has(field.type)) {
@@ -1227,7 +1382,7 @@ function detectCircularDependencies(graph) {
1227
1382
  visited.add(node);
1228
1383
  recursionStack.add(node);
1229
1384
  path.push(node);
1230
- const dependencies = graph.get(node) || /* @__PURE__ */ new Set();
1385
+ const dependencies = graph.get(node) ?? /* @__PURE__ */ new Set();
1231
1386
  for (const dep of dependencies) {
1232
1387
  if (!visited.has(dep)) {
1233
1388
  dfs(dep);
@@ -1277,7 +1432,9 @@ function modelOutputType(outputType2, args) {
1277
1432
  models,
1278
1433
  output
1279
1434
  } = args;
1280
- if (isManyAndReturnOutputType(outputType2.name)) return;
1435
+ if (isManyAndReturnOutputType(outputType2.name)) {
1436
+ return;
1437
+ }
1281
1438
  const model = models.get(outputType2.name);
1282
1439
  ok(model, `Cannot find model by name ${outputType2.name}`);
1283
1440
  const sourceFile = getSourceFile({
@@ -1307,16 +1464,14 @@ function modelOutputType(outputType2, args) {
1307
1464
  const decorator = classStructure.decorators.find((d) => d.name === "ObjectType");
1308
1465
  ok(decorator, "ObjectType decorator not found");
1309
1466
  let modelSettings;
1310
- if (model.documentation) {
1467
+ if (model.documentation !== null && model.documentation !== void 0 && model.documentation.length > 0) {
1311
1468
  const objectTypeOptions = {};
1312
1469
  const { documentation, settings } = createObjectSettings({
1313
1470
  config,
1314
1471
  text: model.documentation
1315
1472
  });
1316
- if (documentation) {
1317
- if (!classStructure.leadingTrivia) {
1318
- classStructure.leadingTrivia = createComment(documentation);
1319
- }
1473
+ if (documentation !== void 0 && documentation.length > 0) {
1474
+ classStructure.leadingTrivia ??= createComment(documentation);
1320
1475
  objectTypeOptions.description = documentation;
1321
1476
  }
1322
1477
  decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
@@ -1334,10 +1489,12 @@ function modelOutputType(outputType2, args) {
1334
1489
  importDeclarations.add("getType", typeRegistryPath);
1335
1490
  }
1336
1491
  for (const field of outputType2.fields) {
1337
- if (config.omitModelsCount && field.name === "_count") continue;
1492
+ if (config.omitModelsCount && field.name === "_count") {
1493
+ continue;
1494
+ }
1338
1495
  let fileType = "model";
1339
1496
  const { isList, location, namespace, type } = field.outputType;
1340
- let outputTypeName = String(type);
1497
+ let outputTypeName = type;
1341
1498
  if (namespace !== "model") {
1342
1499
  fileType = "output";
1343
1500
  outputTypeName = getOutputTypeName(outputTypeName);
@@ -1359,15 +1516,12 @@ function modelOutputType(outputType2, args) {
1359
1516
  })
1360
1517
  );
1361
1518
  propertyType.splice(1, propertyType.length);
1362
- if (field.isNullable && !isList) {
1519
+ if (field.isNullable === true && !isList) {
1363
1520
  propertyType.push("null");
1364
1521
  }
1365
1522
  let graphqlType;
1366
1523
  let useGetType = false;
1367
- if (fieldType) {
1368
- graphqlType = fieldType.name;
1369
- importDeclarations.create({ ...fieldType });
1370
- } else {
1524
+ if (fieldType === void 0) {
1371
1525
  const graphqlImport = getGraphqlImport({
1372
1526
  config,
1373
1527
  fileType,
@@ -1379,7 +1533,7 @@ function modelOutputType(outputType2, args) {
1379
1533
  typeName: outputTypeName
1380
1534
  });
1381
1535
  graphqlType = graphqlImport.name;
1382
- if (graphqlImport.name !== outputType2.name && graphqlImport.specifier) {
1536
+ if (graphqlImport.name !== outputType2.name && graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && graphqlImport.specifier.length > 0) {
1383
1537
  const isCircular = config.esmCompatible && location === "outputObjectTypes" && namespace === "model" && hasCircularDependency(circularDependencies, outputType2.name, outputTypeName);
1384
1538
  if (isCircular) {
1385
1539
  importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
@@ -1389,6 +1543,9 @@ function modelOutputType(outputType2, args) {
1389
1543
  importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
1390
1544
  }
1391
1545
  }
1546
+ } else {
1547
+ graphqlType = fieldType.name;
1548
+ importDeclarations.create({ ...fieldType });
1392
1549
  }
1393
1550
  const property = propertyStructure({
1394
1551
  hasExclamationToken: true,
@@ -1398,17 +1555,19 @@ function modelOutputType(outputType2, args) {
1398
1555
  name: field.name,
1399
1556
  propertyType
1400
1557
  });
1401
- if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1558
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation.length > 0) {
1402
1559
  property.leadingTrivia += createComment(modelField.documentation, settings);
1403
1560
  }
1404
- classStructure.properties?.push(property);
1405
- if (propertySettings) {
1561
+ if (classStructure.properties !== void 0) {
1562
+ classStructure.properties.push(property);
1563
+ }
1564
+ if (propertySettings !== void 0) {
1406
1565
  importDeclarations.create({ ...propertySettings });
1407
1566
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
1408
1567
  importDeclarations.add("Prisma", config.prismaClientImport);
1409
1568
  }
1410
- ok(property.decorators, "property.decorators is undefined");
1411
- const shouldHideField = settings?.shouldHideField({ name: outputType2.name, output: true }) || config.decorate.some(
1569
+ ok(property.decorators !== void 0, "property.decorators is undefined");
1570
+ const shouldHideField = settings?.shouldHideField({ name: outputType2.name, output: true }) === true || config.decorate.some(
1412
1571
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1413
1572
  );
1414
1573
  if (shouldHideField) {
@@ -1429,7 +1588,7 @@ function modelOutputType(outputType2, args) {
1429
1588
  defaultValue: ["number", "string", "boolean"].includes(
1430
1589
  typeof modelField?.default
1431
1590
  ) ? modelField?.default : void 0,
1432
- description: modelField?.documentation,
1591
+ description: modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation !== "" ? modelField.documentation : void 0,
1433
1592
  nullable: Boolean(field.isNullable)
1434
1593
  })
1435
1594
  ],
@@ -1441,7 +1600,10 @@ function modelOutputType(outputType2, args) {
1441
1600
  arguments: setting.arguments,
1442
1601
  name: setting.name
1443
1602
  });
1444
- ok(setting.from, "Missed 'from' part in configuration or field setting");
1603
+ ok(
1604
+ setting.from && setting.from.length > 0,
1605
+ "Missed 'from' part in configuration or field setting"
1606
+ );
1445
1607
  importDeclarations.create(setting);
1446
1608
  }
1447
1609
  }
@@ -1509,13 +1671,14 @@ function noAtomicOperations(eventEmitter) {
1509
1671
  eventEmitter.on("BeforeGenerateFiles", beforeGenerateFiles);
1510
1672
  }
1511
1673
  function beforeInputType2(args) {
1512
- const { inputType: inputType2, getModelName: getModelName2 } = args;
1674
+ const { getModelName: getModelName2, inputType: inputType2 } = args;
1513
1675
  for (const field of inputType2.fields) {
1514
1676
  const fieldName = field.name;
1515
1677
  field.inputTypes = field.inputTypes.filter((it) => {
1516
- const inputTypeName = String(it.type);
1678
+ const inputTypeName = it.type;
1517
1679
  const modelName = getModelName2(inputTypeName);
1518
- if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName, fieldName)) {
1680
+ const isModelNameValid = modelName !== null && modelName !== void 0 && modelName.length > 0;
1681
+ if (isAtomicOperation(inputTypeName) || isModelNameValid && isListInput(inputTypeName, modelName, fieldName)) {
1519
1682
  return false;
1520
1683
  }
1521
1684
  return true;
@@ -1526,7 +1689,8 @@ function beforeGenerateFiles(args) {
1526
1689
  const { project } = args;
1527
1690
  for (const sourceFile of project.getSourceFiles()) {
1528
1691
  const className = sourceFile.getClass(() => true)?.getName();
1529
- if (className && isAtomicOperation(className)) {
1692
+ const isClassNameValid = className !== void 0 && className !== null && className.length > 0;
1693
+ if (isClassNameValid && isAtomicOperation(className)) {
1530
1694
  project.removeSourceFile(sourceFile);
1531
1695
  }
1532
1696
  }
@@ -1552,11 +1716,13 @@ function outputType(outputTypeArg, args) {
1552
1716
  const { config, eventEmitter, fieldSettings, getModelName: getModelName2, getSourceFile, models } = args;
1553
1717
  const importDeclarations = new ImportDeclarationMap();
1554
1718
  const fileType = "output";
1555
- const modelName = getModelName2(outputTypeArg.name) ?? "";
1556
- const model = models.get(modelName);
1557
- const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputTypeArg.name) && String(outputTypeArg.name).startsWith(model.name);
1558
- const isCountOutput = model?.name && outputTypeArg.name === `${model.name}CountOutputType`;
1559
- if (!config.emitBlocks.outputs && !isCountOutput) return;
1719
+ const modelName = getModelName2(outputTypeArg.name);
1720
+ const model = modelName === void 0 ? void 0 : models.get(modelName);
1721
+ const isAggregateOutput = model !== void 0 && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputTypeArg.name) && outputTypeArg.name.startsWith(model.name);
1722
+ const isCountOutput = model?.name !== void 0 && model.name !== "" && outputTypeArg.name === `${model.name}CountOutputType`;
1723
+ if (config.emitBlocks.outputs || isCountOutput) ; else {
1724
+ return;
1725
+ }
1560
1726
  outputTypeArg.name = getOutputTypeName(outputTypeArg.name);
1561
1727
  if (isAggregateOutput) {
1562
1728
  eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputTypeArg });
@@ -1581,8 +1747,15 @@ function outputType(outputTypeArg, args) {
1581
1747
  importDeclarations.add("ObjectType", nestjsGraphql2);
1582
1748
  for (const field of outputTypeArg.fields) {
1583
1749
  const { isList, location, type } = field.outputType;
1584
- const outputTypeName = getOutputTypeName(String(type));
1585
- const settings = isCountOutput ? void 0 : model && fieldSettings.get(model.name)?.get(field.name);
1750
+ const outputTypeName = getOutputTypeName(type);
1751
+ let settings;
1752
+ if (isCountOutput) {
1753
+ settings = void 0;
1754
+ } else if (model === void 0) {
1755
+ settings = void 0;
1756
+ } else {
1757
+ settings = fieldSettings.get(model.name)?.get(field.name);
1758
+ }
1586
1759
  const propertySettings = settings?.getPropertyType({
1587
1760
  name: outputTypeArg.name,
1588
1761
  output: true
@@ -1603,7 +1776,7 @@ function outputType(outputTypeArg, args) {
1603
1776
  propertyType
1604
1777
  });
1605
1778
  classStructure.properties?.push(property);
1606
- if (propertySettings) {
1779
+ if (propertySettings !== void 0) {
1607
1780
  importDeclarations.create({ ...propertySettings });
1608
1781
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
1609
1782
  importDeclarations.add("Prisma", config.prismaClientImport);
@@ -1612,14 +1785,14 @@ function outputType(outputTypeArg, args) {
1612
1785
  const shouldHideField = settings?.shouldHideField({
1613
1786
  name: outputTypeArg.name,
1614
1787
  output: true
1615
- }) || config.decorate.some(
1788
+ }) === true || config.decorate.some(
1616
1789
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1617
1790
  );
1618
1791
  const fieldType = settings?.getFieldType({
1619
1792
  name: outputTypeArg.name,
1620
1793
  output: true
1621
1794
  });
1622
- if (fieldType && isCustomsApplicable && !shouldHideField) {
1795
+ if (fieldType !== void 0 && isCustomsApplicable && !shouldHideField) {
1623
1796
  graphqlType = fieldType.name;
1624
1797
  importDeclarations.create({ ...fieldType });
1625
1798
  } else {
@@ -1634,14 +1807,14 @@ function outputType(outputTypeArg, args) {
1634
1807
  });
1635
1808
  const referenceName = location === "enumTypes" ? getEnumName(propertyType[0]) : propertyType[0];
1636
1809
  graphqlType = graphqlImport.name;
1637
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputTypeArg.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1810
+ 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)) {
1638
1811
  importDeclarations.set(graphqlImport.name, {
1639
1812
  moduleSpecifier: graphqlImport.specifier,
1640
1813
  namedImports: [{ name: graphqlImport.name }]
1641
1814
  });
1642
1815
  }
1643
1816
  }
1644
- ok(property.decorators, "property.decorators is undefined");
1817
+ ok(property.decorators !== void 0, "property.decorators is undefined");
1645
1818
  if (shouldHideField) {
1646
1819
  importDeclarations.add("HideField", nestjsGraphql2);
1647
1820
  property.decorators.push({ arguments: [], name: "HideField" });
@@ -1658,12 +1831,16 @@ function outputType(outputTypeArg, args) {
1658
1831
  });
1659
1832
  if (isCustomsApplicable) {
1660
1833
  for (const options of settings ?? []) {
1661
- if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1834
+ const shouldApplyDecorator = options.kind === "Decorator" && options.output && (options.match?.(field.name) ?? true);
1835
+ if (shouldApplyDecorator) {
1662
1836
  property.decorators.push({
1663
1837
  arguments: options.arguments,
1664
1838
  name: options.name
1665
1839
  });
1666
- ok(options.from, "Missed 'from' part in configuration or field setting");
1840
+ ok(
1841
+ options.from !== null && options.from !== void 0 && options.from.length > 0,
1842
+ "Missed 'from' part in configuration or field setting"
1843
+ );
1667
1844
  importDeclarations.create(options);
1668
1845
  }
1669
1846
  }
@@ -1679,11 +1856,15 @@ function outputType(outputTypeArg, args) {
1679
1856
  statements: [...importDeclarations.toStatements(), classStructure]
1680
1857
  });
1681
1858
  }
1859
+ var rmdirTyped = rmdirSync$1;
1860
+ var rmdirSync = (path) => {
1861
+ rmdirTyped(path);
1862
+ };
1682
1863
  function purgeOutput(emitter) {
1683
1864
  emitter.on("Begin", begin);
1684
1865
  emitter.on("End", end);
1685
1866
  }
1686
- function begin({ project, output }) {
1867
+ function begin({ output, project }) {
1687
1868
  const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1688
1869
  if (sourceFiles) {
1689
1870
  for (const sourceFile of sourceFiles) {
@@ -1691,9 +1872,10 @@ function begin({ project, output }) {
1691
1872
  }
1692
1873
  }
1693
1874
  }
1694
- function end({ project, output }) {
1875
+ function end({ output, project }) {
1695
1876
  const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1696
- for (const directory of directories ?? []) {
1877
+ const directoryList = directories ?? [];
1878
+ for (const directory of directoryList) {
1697
1879
  try {
1698
1880
  rmdirSync(directory);
1699
1881
  } catch {
@@ -1711,7 +1893,7 @@ function reExport(emitter) {
1711
1893
  emitter.on("BeforeGenerateFiles", beforeGenerateFiles2);
1712
1894
  }
1713
1895
  function beforeGenerateFiles2(args) {
1714
- const { project, output, config } = args;
1896
+ const { config, output, project } = args;
1715
1897
  const rootDirectory = project.getDirectoryOrThrow(output);
1716
1898
  if (["Directories" /* Directories */, "All" /* All */].includes(config.reExport)) {
1717
1899
  const directories = [...rootDirectory.getDescendantDirectories()];
@@ -1758,7 +1940,9 @@ function beforeGenerateFiles2(args) {
1758
1940
  const exportDeclarations = [];
1759
1941
  const directories = rootDirectory.getDirectories();
1760
1942
  for (const directory of directories) {
1761
- if (directory.getBaseName() === "node_modules") continue;
1943
+ if (directory.getBaseName() === "node_modules") {
1944
+ continue;
1945
+ }
1762
1946
  const indexFile = directory.getSourceFile("index.ts");
1763
1947
  if (indexFile) {
1764
1948
  const dirName = directory.getBaseName();
@@ -1780,9 +1964,9 @@ function beforeGenerateFiles2(args) {
1780
1964
  function getExportDeclaration2(directory, sourceFile) {
1781
1965
  let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceFile);
1782
1966
  if (!moduleSpecifier.endsWith(".js") && !moduleSpecifier.endsWith(".ts")) {
1783
- moduleSpecifier = moduleSpecifier + ".js";
1967
+ moduleSpecifier += ".js";
1784
1968
  } else if (moduleSpecifier.endsWith(".ts")) {
1785
- moduleSpecifier = moduleSpecifier.slice(0, -3) + ".js";
1969
+ moduleSpecifier = `${moduleSpecifier.slice(0, -3)}.js`;
1786
1970
  }
1787
1971
  return {
1788
1972
  kind: StructureKind.ExportDeclaration,
@@ -1792,7 +1976,7 @@ function getExportDeclaration2(directory, sourceFile) {
1792
1976
  function getNamespaceExportDeclaration(directory, sourceDirectory) {
1793
1977
  let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceDirectory);
1794
1978
  if (!moduleSpecifier.endsWith("/index.js")) {
1795
- moduleSpecifier = moduleSpecifier + "/index.js";
1979
+ moduleSpecifier += "/index.js";
1796
1980
  }
1797
1981
  return {
1798
1982
  kind: StructureKind.ExportDeclaration,
@@ -1800,74 +1984,16 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
1800
1984
  };
1801
1985
  }
1802
1986
 
1803
- // src/handlers/prisma-enum-doc.ts
1804
- function extractEnumValueDocs(values) {
1805
- return Object.fromEntries(
1806
- values.map((value) => {
1807
- const { name } = value;
1808
- const documentation = value.documentation;
1809
- if (typeof documentation !== "string") return null;
1810
- if (documentation.startsWith("@deprecated")) {
1811
- return [name, { deprecationReason: documentation.slice(11).trim() }];
1812
- }
1813
- return [name, { description: documentation }];
1814
- }).filter((entry) => entry !== null)
1815
- );
1816
- }
1817
-
1818
- // src/handlers/register-enum.ts
1819
- function registerEnum(enumType, args) {
1820
- const { config, enums, getSourceFile } = args;
1821
- if (!config.emitBlocks.prismaEnums && !enums[enumType.name]) return;
1822
- const dataModelEnum = enums[enumType.name];
1823
- const enumTypesData = dataModelEnum?.values ?? [];
1824
- const sourceFile = getSourceFile({
1825
- name: enumType.name,
1826
- type: "enum"
1827
- });
1828
- const importDeclarations = new ImportDeclarationMap();
1829
- importDeclarations.set("registerEnumType", {
1830
- moduleSpecifier: "@nestjs/graphql",
1831
- namedImports: [{ name: "registerEnumType" }]
1832
- });
1833
- const valuesMap = extractEnumValueDocs(enumTypesData);
1834
- const filteredValuesMap = Object.fromEntries(
1835
- Object.entries(valuesMap).filter(([, v]) => Object.keys(v).length > 0)
1836
- );
1837
- const hasValuesMap = Object.keys(filteredValuesMap).length > 0;
1838
- const formattedValuesMap = hasValuesMap ? JSON.stringify(filteredValuesMap, null, 2).replace(/"([^"]+)":/g, "$1:") : "";
1839
- const valuesMapEntry = hasValuesMap ? `, valuesMap: ${formattedValuesMap}` : "";
1840
- const enumStructure = {
1841
- kind: StructureKind.Enum,
1842
- isExported: true,
1843
- name: enumType.name,
1844
- members: enumType.values.map((v) => ({
1845
- name: v,
1846
- initializer: JSON.stringify(v)
1847
- }))
1848
- };
1849
- sourceFile.set({
1850
- statements: [
1851
- ...importDeclarations.toStatements(),
1852
- enumStructure,
1853
- "\n",
1854
- `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(
1855
- dataModelEnum?.documentation
1856
- )}${valuesMapEntry} })`
1857
- ]
1858
- });
1859
- }
1987
+ // src/handlers/register-all-types.ts
1860
1988
  function generateRegisterAllTypes(args) {
1861
1989
  const { config, output, project } = args;
1862
1990
  if (!config.esmCompatible) {
1863
1991
  return;
1864
1992
  }
1865
- const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
1866
- const sourceFile = rootDirectory.createSourceFile(
1867
- "register-all-types.ts",
1868
- void 0,
1869
- { overwrite: true }
1870
- );
1993
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
1994
+ const sourceFile = rootDirectory.createSourceFile("register-all-types.ts", void 0, {
1995
+ overwrite: true
1996
+ });
1871
1997
  const importPaths = [];
1872
1998
  const typeNames = [];
1873
1999
  const allSourceFiles = project.getSourceFiles(`${output}/**/*.ts`);
@@ -1877,7 +2003,7 @@ function generateRegisterAllTypes(args) {
1877
2003
  continue;
1878
2004
  }
1879
2005
  const fileText = file.getText();
1880
- const registerMatch = fileText.match(/registerType\(['"]([^'"]+)['"]/);
2006
+ const registerMatch = /registerType\(['"]([^'"]+)['"]/.exec(fileText);
1881
2007
  if (registerMatch) {
1882
2008
  const relPath = relativePath(sourceFile.getFilePath(), filePath);
1883
2009
  importPaths.push(relPath);
@@ -1931,6 +2057,76 @@ export type RegisteredTypeName = typeof registeredTypes[number];
1931
2057
  sourceFile.addStatements(fileContent);
1932
2058
  }
1933
2059
 
2060
+ // src/handlers/prisma-enum-doc.ts
2061
+ function extractEnumValueDocs(values) {
2062
+ return Object.fromEntries(
2063
+ values.map((value) => {
2064
+ const { name } = value;
2065
+ const { documentation } = value;
2066
+ if (typeof documentation !== "string") {
2067
+ return null;
2068
+ }
2069
+ if (documentation.startsWith("@deprecated")) {
2070
+ return [name, { deprecationReason: documentation.slice(11).trim() }];
2071
+ }
2072
+ return [name, { description: documentation }];
2073
+ }).filter((entry) => entry !== null)
2074
+ );
2075
+ }
2076
+
2077
+ // src/handlers/register-enum.ts
2078
+ function registerEnum(enumType, args) {
2079
+ const { config, enums, getSourceFile } = args;
2080
+ const enumTypeAsRecord = enumType;
2081
+ const rawName = enumTypeAsRecord.name;
2082
+ const enumName = typeof rawName === "string" ? rawName : String(rawName);
2083
+ const enumValue = enums[enumName];
2084
+ if (!config.emitBlocks.prismaEnums && enumValue === void 0) {
2085
+ return;
2086
+ }
2087
+ const dataModelEnum = enumValue;
2088
+ const enumTypesData = dataModelEnum?.values ?? [];
2089
+ const sourceFile = getSourceFile({
2090
+ name: enumName,
2091
+ type: "enum"
2092
+ });
2093
+ const importDeclarations = new ImportDeclarationMap();
2094
+ importDeclarations.set("registerEnumType", {
2095
+ moduleSpecifier: "@nestjs/graphql",
2096
+ namedImports: [{ name: "registerEnumType" }]
2097
+ });
2098
+ const valuesMap = extractEnumValueDocs(enumTypesData);
2099
+ const filteredValuesMap = Object.fromEntries(
2100
+ Object.entries(valuesMap).filter(([, v]) => Object.keys(v).length > 0)
2101
+ );
2102
+ const hasValuesMap = Object.keys(filteredValuesMap).length > 0;
2103
+ const formattedValuesMap = hasValuesMap ? JSON.stringify(filteredValuesMap, null, 2).replace(/"([^"]+)":/g, "$1:") : "";
2104
+ const valuesMapEntry = hasValuesMap ? `, valuesMap: ${formattedValuesMap}` : "";
2105
+ const enumTypeRecord = enumType;
2106
+ const rawValues = enumTypeRecord.values;
2107
+ const enumValues = Array.isArray(rawValues) ? rawValues.map((v) => String(v)) : [];
2108
+ const enumStructure = {
2109
+ isExported: true,
2110
+ kind: StructureKind.Enum,
2111
+ members: enumValues.map((v) => ({
2112
+ initializer: JSON.stringify(v),
2113
+ name: v
2114
+ })),
2115
+ name: enumName
2116
+ };
2117
+ const enumTypeName = enumName;
2118
+ sourceFile.set({
2119
+ statements: [
2120
+ ...importDeclarations.toStatements(),
2121
+ enumStructure,
2122
+ "\n",
2123
+ `registerEnumType(${enumTypeName}, { name: '${enumTypeName}', description: ${JSON.stringify(
2124
+ dataModelEnum?.documentation
2125
+ )}${valuesMapEntry} })`
2126
+ ]
2127
+ });
2128
+ }
2129
+
1934
2130
  // src/handlers/require-single-fields-in-whereunique-input.ts
1935
2131
  function requireSingleFieldsInWhereUniqueInput(eventEmitter) {
1936
2132
  eventEmitter.on("BeforeInputType", beforeInputType3);
@@ -1945,17 +2141,17 @@ function beforeInputType3(args) {
1945
2141
  field.isNullable = false;
1946
2142
  }
1947
2143
  }
2144
+
2145
+ // src/handlers/type-registry.ts
1948
2146
  function generateTypeRegistry(args) {
1949
2147
  const { config, output, project } = args;
1950
2148
  if (!config.esmCompatible) {
1951
2149
  return;
1952
2150
  }
1953
- const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
1954
- const sourceFile = rootDirectory.createSourceFile(
1955
- "type-registry.ts",
1956
- void 0,
1957
- { overwrite: true }
1958
- );
2151
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
2152
+ const sourceFile = rootDirectory.createSourceFile("type-registry.ts", void 0, {
2153
+ overwrite: true
2154
+ });
1959
2155
  const registryCode = `/**
1960
2156
  * Type Registry for ESM Circular Dependency Resolution
1961
2157
  *
@@ -2086,81 +2282,17 @@ export function validateRegistry(expectedTypes: string[]): void {
2086
2282
  sourceFile.addStatements(registryCode);
2087
2283
  }
2088
2284
 
2089
- // src/handlers/decimal-helpers.ts
2090
- function generateDecimalHelpers(args) {
2091
- const { config, output, project } = args;
2092
- const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
2093
- const sourceFile = rootDirectory.createSourceFile(
2094
- "decimal-helpers.ts",
2095
- void 0,
2096
- { overwrite: true }
2097
- );
2098
- const helpersCode = `/**
2099
- * Decimal Helpers for Prisma GraphQL
2100
- *
2101
- * This module provides utilities for transforming Decimal values
2102
- * between GraphQL and Prisma, compatible with Prisma 7+.
2103
- *
2104
- * These functions replace the prisma-graphql-type-decimal package
2105
- * which is incompatible with Prisma 7's new client structure.
2106
- */
2107
-
2108
- import Decimal from 'decimal.js';
2109
-
2110
- /**
2111
- * Reconstruct a Decimal from a serialized object.
2112
- * Prisma serializes Decimals as objects with d, e, s properties.
2113
- */
2114
- function createDecimalFromObject(object: { d: number[]; e: number; s: number }): Decimal {
2115
- return Object.create(Decimal.prototype, {
2116
- d: { value: object.d },
2117
- e: { value: object.e },
2118
- s: { value: object.s },
2119
- });
2120
- }
2121
-
2122
- /**
2123
- * Transform input values to Decimal instances.
2124
- * Used as a class-transformer Transform decorator argument.
2125
- *
2126
- * @param params - The transform parameters from class-transformer
2127
- * @returns The transformed Decimal or array of Decimals
2128
- */
2129
- export function transformToDecimal({ value }: { value: unknown }): Decimal | Decimal[] | null | undefined {
2130
- if (value == null) return value as null | undefined;
2131
-
2132
- if (Array.isArray(value)) {
2133
- return value.map((v) => {
2134
- if (v instanceof Decimal) return v;
2135
- if (typeof v === 'object' && v !== null && 'd' in v && 'e' in v && 's' in v) {
2136
- return createDecimalFromObject(v as { d: number[]; e: number; s: number });
2137
- }
2138
- return new Decimal(v as string | number);
2139
- });
2140
- }
2141
-
2142
- if (value instanceof Decimal) return value;
2143
- if (typeof value === 'object' && value !== null && 'd' in value && 'e' in value && 's' in value) {
2144
- return createDecimalFromObject(value as { d: number[]; e: number; s: number });
2145
- }
2146
- return new Decimal(value as string | number);
2147
- }
2148
-
2149
- /**
2150
- * Re-export Decimal class for convenience
2151
- */
2152
- export { Decimal };
2153
- `;
2154
- sourceFile.addStatements(helpersCode);
2155
- }
2156
-
2157
2285
  // src/handlers/warning.ts
2286
+ var globalConsole = globalThis.console;
2287
+ var log = (msg) => {
2288
+ globalConsole.log(msg);
2289
+ };
2158
2290
  function warning(message) {
2159
2291
  if (Array.isArray(message)) {
2160
- console.log("nestjs-prisma-graphql:");
2161
- console.log(message.join("\n"));
2292
+ log("nestjs-prisma-graphql:");
2293
+ log(message.join("\n"));
2162
2294
  } else {
2163
- console.log("nestjs-prisma-graphql:", message);
2295
+ log(`nestjs-prisma-graphql: ${message}`);
2164
2296
  }
2165
2297
  }
2166
2298
 
@@ -2174,44 +2306,51 @@ var allEmmittedBlocks = [
2174
2306
  "outputs"
2175
2307
  ];
2176
2308
  var blocksDependencyMap = {
2309
+ args: ["args", "inputs", "prismaEnums"],
2177
2310
  enums: ["schemaEnums", "prismaEnums"],
2178
- models: ["models", "schemaEnums"],
2179
2311
  inputs: ["inputs", "prismaEnums"],
2180
- outputs: ["outputs"],
2181
- args: ["args", "inputs", "prismaEnums"]
2312
+ models: ["models", "schemaEnums"],
2313
+ outputs: ["outputs"]
2182
2314
  };
2183
2315
  function createEmitBlocks(data) {
2184
2316
  if (!data) {
2185
- return Object.fromEntries(allEmmittedBlocks.map((block) => [block, true]));
2317
+ const entries = allEmmittedBlocks.map((block) => [block, true]);
2318
+ const allBlocks = Object.fromEntries(entries);
2319
+ return allBlocks;
2186
2320
  }
2187
- let blocksToEmit = {};
2321
+ const initialBlocks = {};
2322
+ let currentBlocks = initialBlocks;
2188
2323
  for (const block of data) {
2189
- if (!Object.keys(blocksDependencyMap).includes(block)) continue;
2190
- blocksToEmit = {
2191
- ...blocksToEmit,
2192
- ...Object.fromEntries(
2193
- blocksDependencyMap[block].map((block2) => [block2, true])
2194
- )
2324
+ if (!Object.keys(blocksDependencyMap).includes(block)) {
2325
+ continue;
2326
+ }
2327
+ const blockEntries = blocksDependencyMap[block].map(
2328
+ (emittedBlock) => [emittedBlock, true]
2329
+ );
2330
+ const newBlocks = Object.fromEntries(blockEntries);
2331
+ currentBlocks = {
2332
+ ...currentBlocks,
2333
+ ...newBlocks
2195
2334
  };
2196
2335
  }
2197
- return blocksToEmit;
2336
+ return currentBlocks;
2198
2337
  }
2199
2338
 
2200
2339
  // src/helpers/create-config.ts
2201
2340
  function createConfig(data) {
2202
2341
  const config = merge({}, unflatten(data, { delimiter: "_" }));
2203
2342
  const $warnings = [];
2204
- const configOutputFilePattern = String(
2205
- config.outputFilePattern || `{model}/{name}.{type}.ts`
2206
- );
2207
- let outputFilePattern = configOutputFilePattern.replaceAll("..", "/").replaceAll(/\/+/g, "/");
2208
- outputFilePattern = trim(outputFilePattern, "/");
2343
+ const defaultPattern = `{model}/{name}.{type}.ts`;
2344
+ const outputFilePatternValue = config.outputFilePattern;
2345
+ const configOutputFilePattern = typeof outputFilePatternValue === "string" ? outputFilePatternValue : defaultPattern;
2346
+ const sanitizedStep1 = configOutputFilePattern.replaceAll("..", "/").replaceAll(/\/+/g, "/");
2347
+ const outputFilePattern = trim(sanitizedStep1, "/");
2209
2348
  if (outputFilePattern !== configOutputFilePattern) {
2210
2349
  $warnings.push(
2211
2350
  `Due to invalid filepath 'outputFilePattern' changed to '${outputFilePattern}'`
2212
2351
  );
2213
2352
  }
2214
- if (config.reExportAll) {
2353
+ if (config.reExportAll !== void 0 && config.reExportAll !== null && config.reExportAll !== false) {
2215
2354
  $warnings.push(`Option 'reExportAll' is deprecated, use 'reExport' instead`);
2216
2355
  if (toBoolean(config.reExportAll)) {
2217
2356
  config.reExport = "All";
@@ -2223,105 +2362,118 @@ function createConfig(data) {
2223
2362
  ).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
2224
2363
  const fieldSetting = {
2225
2364
  arguments: [],
2226
- output: toBoolean(value.output),
2365
+ defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
2366
+ from: value.from,
2227
2367
  input: toBoolean(value.input),
2228
2368
  model: toBoolean(value.model),
2229
- from: value.from,
2230
- defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
2231
- namespaceImport: value.namespaceImport
2369
+ namespaceImport: value.namespaceImport,
2370
+ output: toBoolean(value.output)
2232
2371
  };
2233
2372
  return [name, fieldSetting];
2234
2373
  })
2235
2374
  );
2236
2375
  const decorate = [];
2237
- const configDecorate = Object.values(
2238
- config.decorate || {}
2239
- );
2376
+ const decorateConfig = config.decorate !== void 0 && config.decorate !== null ? config.decorate : {};
2377
+ const configDecorate = Object.values(decorateConfig);
2240
2378
  for (const element of configDecorate) {
2241
- if (!element) continue;
2379
+ if (element === void 0 || element === null) {
2380
+ continue;
2381
+ }
2242
2382
  ok(
2243
- element.from && element.name,
2383
+ element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
2244
2384
  `Missed 'from' or 'name' part in configuration for decorate`
2245
2385
  );
2246
2386
  decorate.push({
2387
+ arguments: element.arguments !== void 0 && element.arguments !== "" ? JSON52.parse(element.arguments) : void 0,
2388
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2389
+ from: element.from,
2247
2390
  isMatchField: outmatch2(element.field, { separator: false }),
2248
2391
  isMatchType: outmatch2(element.type, { separator: false }),
2249
- from: element.from,
2250
2392
  name: element.name,
2251
2393
  namedImport: toBoolean(element.namedImport),
2252
- defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2253
- namespaceImport: element.namespaceImport,
2254
- arguments: element.arguments ? JSON52.parse(element.arguments) : void 0
2394
+ namespaceImport: element.namespaceImport
2255
2395
  });
2256
2396
  }
2257
2397
  const customImport = [];
2258
- const configCustomImport = Object.values(
2259
- config.customImport || {}
2260
- );
2398
+ const customImportConfig = config.customImport !== void 0 && config.customImport !== null ? config.customImport : {};
2399
+ const configCustomImport = Object.values(customImportConfig);
2261
2400
  for (const element of configCustomImport) {
2262
- if (!element) continue;
2401
+ if (element === void 0 || element === null) {
2402
+ continue;
2403
+ }
2263
2404
  ok(
2264
- element.from && element.name,
2405
+ element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
2265
2406
  `Missed 'from' or 'name' part in configuration for customImport`
2266
2407
  );
2267
2408
  customImport.push({
2409
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2268
2410
  from: element.from,
2269
2411
  name: element.name,
2270
2412
  namedImport: toBoolean(element.namedImport),
2271
- defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2272
2413
  namespaceImport: element.namespaceImport
2273
2414
  });
2274
2415
  }
2275
2416
  return {
2276
- outputFilePattern,
2277
- tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
2278
- prismaClientImport: createPrismaImport(config.prismaClientImport),
2417
+ $warnings,
2279
2418
  combineScalarFilters: toBoolean(config.combineScalarFilters),
2280
- noAtomicOperations: toBoolean(config.noAtomicOperations),
2281
- reExport: ReExport[String(config.reExport)] || "None" /* None */,
2282
- emitSingle: toBoolean(config.emitSingle),
2283
- emitCompiled: toBoolean(config.emitCompiled),
2419
+ customImport,
2420
+ decorate,
2284
2421
  emitBlocks: createEmitBlocks(config.emitBlocks),
2285
- omitModelsCount: toBoolean(config.omitModelsCount),
2286
- $warnings,
2422
+ emitCompiled: toBoolean(config.emitCompiled),
2423
+ emitSingle: toBoolean(config.emitSingle),
2424
+ esmCompatible: toBoolean(config.esmCompatible),
2287
2425
  fields,
2288
- purgeOutput: toBoolean(config.purgeOutput),
2289
- useInputType: createUseInputType(config.useInputType),
2426
+ graphqlScalars: config.graphqlScalars ?? {},
2427
+ noAtomicOperations: toBoolean(config.noAtomicOperations),
2290
2428
  noTypeId: toBoolean(config.noTypeId),
2429
+ omitModelsCount: toBoolean(config.omitModelsCount),
2430
+ outputFilePattern,
2431
+ prismaClientImport: createPrismaImport(config.prismaClientImport),
2432
+ purgeOutput: toBoolean(config.purgeOutput),
2433
+ reExport: ReExport[String(config.reExport)] ?? "None" /* None */,
2291
2434
  requireSingleFieldsInWhereUniqueInput: toBoolean(
2292
2435
  config.requireSingleFieldsInWhereUniqueInput
2293
2436
  ),
2294
- unsafeCompatibleWhereUniqueInput: toBoolean(
2295
- config.unsafeCompatibleWhereUniqueInput
2296
- ),
2297
- graphqlScalars: config.graphqlScalars || {},
2298
- decorate,
2299
- customImport,
2300
- esmCompatible: toBoolean(config.esmCompatible)
2437
+ tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
2438
+ unsafeCompatibleWhereUniqueInput: toBoolean(config.unsafeCompatibleWhereUniqueInput),
2439
+ useInputType: createUseInputType(
2440
+ config.useInputType
2441
+ )
2301
2442
  };
2302
2443
  }
2303
- var tsConfigFileExists = memoize((filePath) => {
2304
- return existsSync(filePath);
2444
+ var existsSyncTyped = existsSync;
2445
+ var tsConfigFileExistsRaw = memoize((filePath) => {
2446
+ const exists = existsSyncTyped(filePath);
2447
+ return exists;
2305
2448
  });
2449
+ var tsConfigFileExists = tsConfigFileExistsRaw;
2306
2450
  function createTsConfigFilePathValue(value) {
2307
- if (typeof value === "string") return value;
2308
- if (tsConfigFileExists("tsconfig.json")) return "tsconfig.json";
2451
+ if (typeof value === "string" && value !== "") {
2452
+ return value;
2453
+ }
2454
+ const fileExists = tsConfigFileExists("tsconfig.json");
2455
+ if (fileExists) {
2456
+ return "tsconfig.json";
2457
+ }
2458
+ return void 0;
2309
2459
  }
2310
2460
  function createPrismaImport(value) {
2311
- if (typeof value === "string") return value;
2461
+ if (typeof value === "string" && value !== "") {
2462
+ return value;
2463
+ }
2312
2464
  return "@prisma/client";
2313
2465
  }
2314
2466
  function createUseInputType(data) {
2315
- if (!data) {
2467
+ if (data === void 0 || data === null) {
2316
2468
  return [];
2317
2469
  }
2318
2470
  const result = [];
2319
2471
  for (const [typeName, useInputs] of Object.entries(data)) {
2320
2472
  const entry = {
2321
- typeName,
2322
- ALL: void 0
2473
+ ALL: void 0,
2474
+ typeName
2323
2475
  };
2324
- if (useInputs.ALL) {
2476
+ if (useInputs.ALL !== void 0 && useInputs.ALL !== "") {
2325
2477
  entry.ALL = useInputs.ALL;
2326
2478
  delete useInputs.ALL;
2327
2479
  }
@@ -2339,7 +2491,7 @@ function generateFileName(args) {
2339
2491
  const { getModelName: getModelName2, name, template, type } = args;
2340
2492
  const rawPath = pupa(template, {
2341
2493
  get model() {
2342
- const result = getModelName2(name) || "prisma";
2494
+ const result = getModelName2(name) ?? "prisma";
2343
2495
  return kebabCase(result);
2344
2496
  },
2345
2497
  get name() {
@@ -2364,61 +2516,19 @@ function generateFileName(args) {
2364
2516
 
2365
2517
  // src/helpers/factory-get-source-file.ts
2366
2518
  function factoryGetSourceFile(args) {
2367
- const { outputFilePattern, output, getModelName: getModelName2, project } = args;
2368
- return function getSourceFile(args2) {
2369
- const { name, type } = args2;
2519
+ const { getModelName: getModelName2, output, outputFilePattern, project } = args;
2520
+ return function getSourceFile(getSourceFileArgs) {
2521
+ const { name, type } = getSourceFileArgs;
2370
2522
  let filePath = generateFileName({
2371
2523
  getModelName: getModelName2,
2372
2524
  name,
2373
- type,
2374
- template: outputFilePattern
2525
+ template: outputFilePattern,
2526
+ type
2375
2527
  });
2376
2528
  filePath = `${output}/${filePath}`;
2377
- return project.getSourceFile(filePath) || project.createSourceFile(filePath, void 0, { overwrite: true });
2529
+ return project.getSourceFile(filePath) ?? project.createSourceFile(filePath, void 0, { overwrite: true });
2378
2530
  };
2379
2531
  }
2380
- function createGetModelName(modelNames) {
2381
- return memoize(tryGetName);
2382
- function tryGetName(name) {
2383
- return getModelName({ modelNames, name });
2384
- }
2385
- }
2386
- function getModelName(args) {
2387
- const { modelNames, name } = args;
2388
- for (const keyword of splitKeywords) {
2389
- const [test] = name.split(keyword, 1);
2390
- if (modelNames.includes(test)) {
2391
- return test;
2392
- }
2393
- }
2394
- for (const keyword of endsWithKeywords) {
2395
- const [test] = name.split(keyword).slice(-1);
2396
- if (modelNames.includes(test)) {
2397
- return test;
2398
- }
2399
- }
2400
- for (const [start, end2] of middleKeywords) {
2401
- let test = name.slice(start.length).slice(0, -end2.length);
2402
- if (modelNames.includes(test) && name.startsWith(start) && name.endsWith(end2)) {
2403
- return test;
2404
- }
2405
- test = name.slice(0, -(start + end2).length);
2406
- if (modelNames.includes(test) && name.endsWith(start + end2)) {
2407
- return test;
2408
- }
2409
- }
2410
- if (name.slice(-19) === "CompoundUniqueInput") {
2411
- const test = name.slice(0, -19);
2412
- const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
2413
- return models[0];
2414
- }
2415
- if (name.slice(-5) === "Count") {
2416
- const test = name.slice(0, -5);
2417
- if (modelNames.includes(test)) {
2418
- return test;
2419
- }
2420
- }
2421
- }
2422
2532
  var splitKeywords = [
2423
2533
  "CreateInput",
2424
2534
  "CreateMany",
@@ -2498,28 +2608,85 @@ var middleKeywords = [
2498
2608
  ["GroupBy", "Args"],
2499
2609
  ["OrderBy", "Args"]
2500
2610
  ];
2611
+ function createGetModelName(modelNames) {
2612
+ return memoize(tryGetName);
2613
+ function tryGetName(name) {
2614
+ return getModelName({ modelNames, name });
2615
+ }
2616
+ }
2617
+ function getModelName(args) {
2618
+ const { modelNames, name } = args;
2619
+ for (const keyword of splitKeywords) {
2620
+ const [test] = name.split(keyword, 1);
2621
+ if (test !== void 0 && modelNames.includes(test)) {
2622
+ return test;
2623
+ }
2624
+ }
2625
+ for (const keyword of endsWithKeywords) {
2626
+ const test = name.split(keyword).at(-1);
2627
+ if (test !== void 0 && modelNames.includes(test)) {
2628
+ return test;
2629
+ }
2630
+ }
2631
+ for (const [start, end2] of middleKeywords) {
2632
+ let test = name.slice(start.length).slice(0, -end2.length);
2633
+ if (modelNames.includes(test) && name.startsWith(start) && name.endsWith(end2)) {
2634
+ return test;
2635
+ }
2636
+ test = name.slice(0, -(start + end2).length);
2637
+ if (modelNames.includes(test) && name.endsWith(start + end2)) {
2638
+ return test;
2639
+ }
2640
+ }
2641
+ if (name.endsWith("CompoundUniqueInput")) {
2642
+ const test = name.slice(0, -19);
2643
+ const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
2644
+ return models[0];
2645
+ }
2646
+ if (name.endsWith("Count")) {
2647
+ const test = name.slice(0, -5);
2648
+ if (modelNames.includes(test)) {
2649
+ return test;
2650
+ }
2651
+ }
2652
+ return void 0;
2653
+ }
2501
2654
 
2502
2655
  // src/generate.ts
2503
- var requireCjs = createRequire(import.meta.url);
2504
- var AwaitEventEmitter = requireCjs("await-event-emitter").default;
2656
+ var createRequireTyped = createRequire;
2657
+ var requireCjs = createRequireTyped(String(import.meta.url));
2658
+ var AwaitEventEmitter = requireCjs(
2659
+ "await-event-emitter"
2660
+ );
2661
+ var AwaitEventEmitterClass = AwaitEventEmitter.default;
2505
2662
  async function generate(args) {
2506
2663
  const { connectCallback, dmmf, generator, skipAddOutputSourceFiles } = args;
2507
- const generatorOutputValue = generator.output?.value;
2508
- ok(generatorOutputValue, "Missing generator configuration: output");
2664
+ const generatorOutputValue = generator.output?.value ?? "";
2665
+ ok(generatorOutputValue !== "", "Missing generator configuration: output");
2509
2666
  const config = createConfig(generator.config);
2510
- const eventEmitter = new AwaitEventEmitter();
2667
+ const eventEmitter = new AwaitEventEmitterClass();
2511
2668
  eventEmitter.on("Warning", warning);
2512
- config.emitBlocks.models && eventEmitter.on("Model", modelData);
2669
+ if (config.emitBlocks.models) {
2670
+ eventEmitter.on("Model", modelData);
2671
+ }
2513
2672
  if (config.emitBlocks.prismaEnums || config.emitBlocks.schemaEnums) {
2514
2673
  eventEmitter.on("EnumType", registerEnum);
2515
2674
  }
2516
2675
  if (config.emitBlocks.outputs || config.emitBlocks.models && !config.omitModelsCount) {
2517
2676
  eventEmitter.on("OutputType", outputType);
2518
2677
  }
2519
- config.emitBlocks.models && eventEmitter.on("ModelOutputType", modelOutputType);
2520
- config.emitBlocks.outputs && eventEmitter.on("AggregateOutput", createAggregateInput);
2521
- config.emitBlocks.inputs && eventEmitter.on("InputType", inputType);
2522
- config.emitBlocks.args && eventEmitter.on("ArgsType", argsType);
2678
+ if (config.emitBlocks.models) {
2679
+ eventEmitter.on("ModelOutputType", modelOutputType);
2680
+ }
2681
+ if (config.emitBlocks.outputs) {
2682
+ eventEmitter.on("AggregateOutput", createAggregateInput);
2683
+ }
2684
+ if (config.emitBlocks.inputs) {
2685
+ eventEmitter.on("InputType", inputType);
2686
+ }
2687
+ if (config.emitBlocks.args) {
2688
+ eventEmitter.on("ArgsType", argsType);
2689
+ }
2523
2690
  eventEmitter.on("GenerateFiles", generateFiles);
2524
2691
  for (const message of config.$warnings) {
2525
2692
  eventEmitter.emitSync("Warning", message);
@@ -2532,18 +2699,30 @@ async function generate(args) {
2532
2699
  skipLoadingLibFiles: !config.emitCompiled,
2533
2700
  tsConfigFilePath: config.tsConfigFilePath
2534
2701
  });
2535
- if (!skipAddOutputSourceFiles) {
2702
+ if (skipAddOutputSourceFiles !== true) {
2536
2703
  project.addSourceFilesAtPaths([
2537
2704
  `${generatorOutputValue}/**/*.ts`,
2538
2705
  `!${generatorOutputValue}/**/*.d.ts`
2539
2706
  ]);
2540
2707
  }
2541
- config.combineScalarFilters && combineScalarFilters(eventEmitter);
2542
- config.noAtomicOperations && noAtomicOperations(eventEmitter);
2543
- config.reExport !== "None" /* None */ && reExport(eventEmitter);
2544
- config.emitSingle && emitSingle(eventEmitter);
2545
- config.purgeOutput && purgeOutput(eventEmitter);
2546
- config.requireSingleFieldsInWhereUniqueInput && requireSingleFieldsInWhereUniqueInput(eventEmitter);
2708
+ if (config.combineScalarFilters) {
2709
+ combineScalarFilters(eventEmitter);
2710
+ }
2711
+ if (config.noAtomicOperations) {
2712
+ noAtomicOperations(eventEmitter);
2713
+ }
2714
+ if (config.reExport !== "None" /* None */) {
2715
+ reExport(eventEmitter);
2716
+ }
2717
+ if (config.emitSingle) {
2718
+ emitSingle(eventEmitter);
2719
+ }
2720
+ if (config.purgeOutput) {
2721
+ purgeOutput(eventEmitter);
2722
+ }
2723
+ if (config.requireSingleFieldsInWhereUniqueInput) {
2724
+ requireSingleFieldsInWhereUniqueInput(eventEmitter);
2725
+ }
2547
2726
  const models = /* @__PURE__ */ new Map();
2548
2727
  const modelNames = [];
2549
2728
  const modelFields = /* @__PURE__ */ new Map();
@@ -2557,7 +2736,8 @@ async function generate(args) {
2557
2736
  });
2558
2737
  const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf));
2559
2738
  const removeTypes = /* @__PURE__ */ new Set();
2560
- const allModels = [...datamodel.models, ...datamodel.types ?? []];
2739
+ const datamodelTypes = datamodel.types ?? [];
2740
+ const allModels = [...datamodel.models, ...datamodelTypes];
2561
2741
  const dependencyGraph = buildDependencyGraph(allModels);
2562
2742
  const circularDependencies = detectCircularDependencies(dependencyGraph);
2563
2743
  const eventArguments = {
@@ -2589,7 +2769,7 @@ async function generate(args) {
2589
2769
  for (const model of datamodel.models) {
2590
2770
  await eventEmitter.emit("Model", model, eventArguments);
2591
2771
  }
2592
- for (const model of datamodel.types ?? []) {
2772
+ for (const model of datamodelTypes) {
2593
2773
  await eventEmitter.emit("Model", model, eventArguments);
2594
2774
  }
2595
2775
  const { enumTypes, inputObjectTypes, outputObjectTypes } = schema;
@@ -2634,28 +2814,46 @@ async function generate(args) {
2634
2814
  await eventEmitter.emit("BeforeGenerateFiles", eventArguments);
2635
2815
  await eventEmitter.emit("GenerateFiles", eventArguments);
2636
2816
  await eventEmitter.emit("End", eventArguments);
2637
- for (const name of Object.keys(eventEmitter._events)) {
2817
+ for (const name of Object.keys(
2818
+ eventEmitter._events
2819
+ )) {
2638
2820
  eventEmitter.off(name);
2639
2821
  }
2640
2822
  }
2641
2823
 
2642
2824
  // src/index.ts
2643
- var requireCjs2 = createRequire(import.meta.url);
2644
- requireCjs2("graceful-fs").gracefulify(requireCjs2("fs"));
2645
- process.on("unhandledRejection", (reason) => {
2646
- console.log("nestjs-prisma-graphql: unhandled rejection:", reason);
2825
+ var createRequireTyped2 = createRequire;
2826
+ var requireCjs2 = createRequireTyped2(String(import.meta.url));
2827
+ var gracefulFsRaw = requireCjs2("graceful-fs");
2828
+ var gracefulFs = gracefulFsRaw;
2829
+ var nodeFsRaw = requireCjs2("fs");
2830
+ var nodeFs = nodeFsRaw;
2831
+ gracefulFs.gracefulify(nodeFs);
2832
+ var globalConsole2 = globalThis.console;
2833
+ var logError = (msg) => {
2834
+ globalConsole2.log(msg);
2835
+ };
2836
+ var processTyped = process;
2837
+ processTyped.on("unhandledRejection", (reason) => {
2838
+ logError(`nestjs-prisma-graphql: unhandled rejection: ${String(reason)}`);
2647
2839
  if (reason instanceof Error && typeof reason.stack === "string") {
2648
- console.log(reason.stack);
2840
+ logError(reason.stack);
2649
2841
  }
2650
2842
  });
2651
- process.on("uncaughtException", (error) => {
2652
- console.log("nestjs-prisma-graphql: uncaught exception:", error.message);
2653
- if (typeof error.stack === "string") {
2654
- console.log(error.stack);
2843
+ processTyped.on("uncaughtException", (error) => {
2844
+ const err = error;
2845
+ logError(`nestjs-prisma-graphql: uncaught exception: ${err.message}`);
2846
+ if (typeof err.stack === "string") {
2847
+ logError(err.stack);
2655
2848
  }
2656
2849
  });
2657
2850
  var { generatorHandler } = generatorHelper;
2658
- function isGeneratorDisabled(options, env = process.env) {
2851
+ var getProcessEnv = () => {
2852
+ const globalProcess = process;
2853
+ const processLike = globalProcess;
2854
+ return processLike.env;
2855
+ };
2856
+ function isGeneratorDisabled(options, env = getProcessEnv()) {
2659
2857
  const envVarsToCheck = [
2660
2858
  "DISABLE_NESTJS_PRISMA_GRAPHQL",
2661
2859
  "CI_SKIP_PRISMA_GRAPHQL",
@@ -2676,8 +2874,12 @@ function isGeneratorDisabled(options, env = process.env) {
2676
2874
  }
2677
2875
  function countFilesRecursive(dir) {
2678
2876
  let count = 0;
2679
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
2680
- if (entry.isDirectory()) {
2877
+ const readDirSyncTyped = readdirSync;
2878
+ const rawEntries = readDirSyncTyped(dir, { withFileTypes: true });
2879
+ const entries = rawEntries;
2880
+ for (const entry of entries) {
2881
+ const isDir = typeof entry.isDirectory === "function" ? entry.isDirectory() : false;
2882
+ if (isDir) {
2681
2883
  count += countFilesRecursive(`${dir}/${entry.name}`);
2682
2884
  } else {
2683
2885
  count++;
@@ -2685,20 +2887,31 @@ function countFilesRecursive(dir) {
2685
2887
  }
2686
2888
  return count;
2687
2889
  }
2890
+ var globalConsole22 = globalThis.console;
2891
+ var log2 = (msg) => {
2892
+ globalConsole22.log(msg);
2893
+ };
2688
2894
  generatorHandler({
2689
2895
  async onGenerate(options) {
2690
2896
  if (isGeneratorDisabled(options)) {
2691
- console.log(
2897
+ log2(
2692
2898
  "nestjs-prisma-graphql: generation skipped (disabled via environment variable or config)"
2693
2899
  );
2694
2900
  return;
2695
2901
  }
2696
2902
  const outputPath = options.generator.output?.value ?? "<unknown>";
2697
2903
  const startTime = Date.now();
2698
- console.log(
2904
+ const archTyped = arch;
2905
+ const platformTyped = platform;
2906
+ const archValue = String(archTyped());
2907
+ const platformValue = String(platformTyped());
2908
+ const globalProcess2Raw = process;
2909
+ const processWithVersion = globalProcess2Raw;
2910
+ const nodeVersion = processWithVersion.version;
2911
+ log2(
2699
2912
  [
2700
2913
  "nestjs-prisma-graphql: starting generation",
2701
- `(arch=${arch()}, platform=${platform()}, node=${process.version}, output=${outputPath})`
2914
+ `(arch=${archValue}, platform=${platformValue}, node=${nodeVersion}, output=${outputPath})`
2702
2915
  ].join(" ")
2703
2916
  );
2704
2917
  try {
@@ -2707,30 +2920,30 @@ generatorHandler({
2707
2920
  const elapsed2 = Date.now() - startTime;
2708
2921
  const message = error instanceof Error ? error.message : String(error);
2709
2922
  const stack = error instanceof Error ? error.stack : void 0;
2710
- console.log(
2923
+ log2(
2711
2924
  `nestjs-prisma-graphql: generation FAILED after ${String(elapsed2)}ms: ${message}`
2712
2925
  );
2713
2926
  if (typeof stack === "string") {
2714
- console.log(stack);
2927
+ log2(stack);
2715
2928
  }
2716
2929
  throw error;
2717
2930
  }
2718
2931
  const elapsed = Date.now() - startTime;
2719
- if (typeof outputPath === "string" && outputPath !== "<unknown>" && existsSync(outputPath)) {
2932
+ const existsSyncTyped2 = existsSync;
2933
+ const pathExists = typeof outputPath === "string" && outputPath !== "<unknown>" && existsSyncTyped2(outputPath);
2934
+ if (pathExists) {
2720
2935
  const fileCount = countFilesRecursive(outputPath);
2721
- console.log(
2722
- `nestjs-prisma-graphql: generated ${String(fileCount)} files in ${String(
2723
- elapsed
2724
- )}ms`
2936
+ log2(
2937
+ `nestjs-prisma-graphql: generated ${String(fileCount)} files in ${String(elapsed)}ms`
2725
2938
  );
2726
2939
  if (fileCount === 0) {
2727
2940
  const msg = "nestjs-prisma-graphql: generation produced 0 files \u2014 this likely indicates a silent failure";
2728
- console.log(msg);
2941
+ log2(msg);
2729
2942
  throw new Error(msg);
2730
2943
  }
2731
2944
  } else {
2732
2945
  const msg = `nestjs-prisma-graphql: output directory not found after generation: ${outputPath}`;
2733
- console.log(msg);
2946
+ log2(msg);
2734
2947
  throw new Error(msg);
2735
2948
  }
2736
2949
  },