@pegasusheavy/nestjs-prisma-graphql 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,34 +808,36 @@ 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
843
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
@@ -747,14 +848,14 @@ function inputType(args) {
747
848
  let graphqlType;
748
849
  let useGetType = false;
749
850
  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)
851
+ input: true,
852
+ name: inputTypeArg.name
853
+ }) ?? config.decorate.some(
854
+ (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputTypeArg.name)
754
855
  );
755
856
  const fieldType = settings?.getFieldType({
756
- name: inputType2.name,
757
- input: true
857
+ input: true,
858
+ name: inputTypeArg.name
758
859
  });
759
860
  if (fieldType && isCustomsApplicable && !shouldHideField) {
760
861
  graphqlType = fieldType.name;
@@ -762,29 +863,28 @@ function inputType(args) {
762
863
  } else {
763
864
  const graphqlImport = getGraphqlImport({
764
865
  config,
765
- sourceFile,
866
+ getSourceFile,
766
867
  location,
767
- typeName,
768
- getSourceFile
868
+ sourceFile,
869
+ typeName
769
870
  });
770
871
  graphqlType = graphqlImport.name;
771
- let referenceName = propertyType[0];
772
872
  if (location === "enumTypes") {
773
- const parts = referenceName.split(" ");
774
- referenceName = parts.at(-1) ?? parts[0];
873
+ const parts = String(propertyType[0]).split(" ");
874
+ parts.at(-1);
775
875
  }
776
876
  const shouldUseLazyType = config.esmCompatible && location === "inputObjectTypes";
777
- if (graphqlImport.name === inputType2.name && shouldUseLazyType) {
877
+ if (graphqlImport.name === inputTypeArg.name && shouldUseLazyType) {
778
878
  lazyTypes.add(graphqlImport.name);
779
879
  useGetType = true;
780
- } else if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputType2.name) {
880
+ } else if (graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputTypeArg.name) {
781
881
  if (shouldUseLazyType) {
782
882
  importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
783
883
  lazyTypes.add(graphqlImport.name);
784
884
  } else {
785
885
  importDeclarations.set(graphqlImport.name, {
786
- namedImports: [{ name: graphqlImport.name }],
787
- moduleSpecifier: graphqlImport.specifier
886
+ moduleSpecifier: graphqlImport.specifier,
887
+ namedImports: [{ name: graphqlImport.name }]
788
888
  });
789
889
  }
790
890
  }
@@ -792,10 +892,13 @@ function inputType(args) {
792
892
  useGetType = true;
793
893
  }
794
894
  }
795
- ok(property.decorators, "property.decorators is undefined");
895
+ ok(
896
+ property.decorators !== void 0 && property.decorators !== null,
897
+ "property.decorators is undefined"
898
+ );
796
899
  if (shouldHideField) {
797
900
  importDeclarations.add("HideField", moduleSpecifier);
798
- property.decorators.push({ name: "HideField", arguments: [] });
901
+ property.decorators.push({ arguments: [], name: "HideField" });
799
902
  } else {
800
903
  let typeExpression;
801
904
  if (useGetType) {
@@ -804,14 +907,14 @@ function inputType(args) {
804
907
  typeExpression = isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`;
805
908
  }
806
909
  property.decorators.push({
807
- name: "Field",
808
910
  arguments: [
809
911
  typeExpression,
810
912
  JSON52.stringify({
811
913
  ...settings?.fieldArguments(),
812
914
  nullable: !isRequired
813
915
  })
814
- ]
916
+ ],
917
+ name: "Field"
815
918
  });
816
919
  if (graphqlType === "GraphQLDecimal") {
817
920
  const decimalHelpersPath = relativePath(
@@ -823,12 +926,12 @@ function inputType(args) {
823
926
  importDeclarations.add("Type", "class-transformer");
824
927
  property.decorators.push(
825
928
  {
826
- name: "Type",
827
- arguments: ["() => Object"]
929
+ arguments: ["() => Object"],
930
+ name: "Type"
828
931
  },
829
932
  {
830
- name: "Transform",
831
- arguments: ["transformToDecimal"]
933
+ arguments: ["transformToDecimal"],
934
+ name: "Transform"
832
935
  }
833
936
  );
834
937
  } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
@@ -845,44 +948,47 @@ function inputType(args) {
845
948
  "updateMany",
846
949
  "upsert",
847
950
  "where"
848
- ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type) && models.get(modelField.type)?.fields.some(
951
+ ].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type)?.fields.some(
849
952
  (f) => f.kind === "object" && classTransformerTypeModels.has(f.type)
850
- ))) {
953
+ ) === true)) {
851
954
  importDeclarations.add("Type", "class-transformer");
852
955
  if (useGetType) {
853
956
  property.decorators.push({
854
- name: "Type",
855
- arguments: [`getType('${graphqlType}')`]
957
+ arguments: [`getType('${graphqlType}')`],
958
+ name: "Type"
856
959
  });
857
960
  } else {
858
- property.decorators.push({ name: "Type", arguments: [`() => ${graphqlType}`] });
961
+ property.decorators.push({ arguments: [`() => ${graphqlType}`], name: "Type" });
859
962
  }
860
963
  }
861
964
  if (isCustomsApplicable) {
862
965
  for (const options of settings ?? []) {
863
966
  if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
864
967
  property.decorators.push({
865
- name: options.name,
866
- arguments: options.arguments
968
+ arguments: options.arguments,
969
+ name: options.name
867
970
  });
868
- ok(options.from, "Missed 'from' part in configuration or field setting");
971
+ ok(
972
+ options.from !== void 0 && options.from !== null && options.from !== "",
973
+ "Missed 'from' part in configuration or field setting"
974
+ );
869
975
  importDeclarations.create(options);
870
976
  }
871
977
  }
872
978
  }
873
979
  for (const decorate of config.decorate) {
874
- if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
980
+ if (decorate.isMatchField(name) && decorate.isMatchType(inputTypeArg.name)) {
875
981
  property.decorators.push({
876
- name: decorate.name,
877
- arguments: decorate.arguments?.map((x) => pupa(x, { propertyType }))
982
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType })),
983
+ name: decorate.name
878
984
  });
879
985
  importDeclarations.create(decorate);
880
986
  }
881
987
  }
882
988
  }
883
989
  eventEmitter.emitSync("ClassProperty", property, {
884
- location,
885
990
  isList,
991
+ location,
886
992
  propertyType
887
993
  });
888
994
  }
@@ -892,7 +998,7 @@ function inputType(args) {
892
998
  ];
893
999
  if (config.esmCompatible) {
894
1000
  statements.push(`
895
- registerType('${inputType2.name}', ${inputType2.name});`);
1001
+ registerType('${inputTypeArg.name}', ${inputTypeArg.name});`);
896
1002
  }
897
1003
  sourceFile.set({
898
1004
  statements
@@ -900,8 +1006,8 @@ registerType('${inputType2.name}', ${inputType2.name});`);
900
1006
  }
901
1007
  var ObjectSettings = class extends Array {
902
1008
  shouldHideField({
903
- name,
904
1009
  input = false,
1010
+ name,
905
1011
  output = false
906
1012
  }) {
907
1013
  const hideField = this.find((s) => s.name === "HideField");
@@ -910,8 +1016,8 @@ var ObjectSettings = class extends Array {
910
1016
  );
911
1017
  }
912
1018
  getFieldType({
913
- name,
914
1019
  input,
1020
+ name,
915
1021
  output
916
1022
  }) {
917
1023
  const fieldType = this.find((s) => s.kind === "FieldType");
@@ -930,8 +1036,8 @@ var ObjectSettings = class extends Array {
930
1036
  return fieldType;
931
1037
  }
932
1038
  getPropertyType({
933
- name,
934
1039
  input,
1040
+ name,
935
1041
  output
936
1042
  }) {
937
1043
  const propertyType = this.find((s) => s.kind === "PropertyType");
@@ -954,19 +1060,20 @@ var ObjectSettings = class extends Array {
954
1060
  const resultArguments = [objectTypeOptions];
955
1061
  const objectType = this.find((s) => s.kind === "ObjectType");
956
1062
  if (objectType && isObject(objectType.arguments)) {
957
- const name = objectType.arguments.name;
1063
+ const { name } = objectType.arguments;
958
1064
  merge(objectTypeOptions, omit(objectType.arguments, "name"));
959
- if (name) {
1065
+ if (name !== null && name !== void 0 && name !== "") {
960
1066
  resultArguments.unshift(name);
961
1067
  }
962
1068
  }
963
1069
  return resultArguments.map((x) => JSON52.stringify(x));
964
1070
  }
965
1071
  fieldArguments() {
966
- const item = this.find((item2) => item2.kind === "Field");
967
- if (item) {
968
- return item.arguments;
1072
+ const fieldItem = this.find((item) => item.kind === "Field");
1073
+ if (fieldItem) {
1074
+ return fieldItem.arguments;
969
1075
  }
1076
+ return void 0;
970
1077
  }
971
1078
  };
972
1079
  function createObjectSettings(args) {
@@ -976,18 +1083,23 @@ function createObjectSettings(args) {
976
1083
  const documentationLines = [];
977
1084
  let fieldElement = result.find((item) => item.kind === "Field");
978
1085
  if (!fieldElement) {
979
- fieldElement = {
980
- name: "",
1086
+ const newFieldElement = {
1087
+ arguments: {},
1088
+ from: "",
1089
+ input: false,
981
1090
  kind: "Field",
982
- arguments: {}
1091
+ model: false,
1092
+ name: "",
1093
+ output: false
983
1094
  };
1095
+ fieldElement = newFieldElement;
984
1096
  }
985
1097
  for (const line of textLines) {
986
1098
  const match = /^@(?<name>\w+(\.(\w+))?)\((?<args>.*)\)/.exec(line);
987
- const { element, documentLine } = createSettingElement({
988
- line,
1099
+ const { documentLine, element } = createSettingElement({
989
1100
  config,
990
1101
  fieldElement,
1102
+ line,
991
1103
  match
992
1104
  });
993
1105
  if (element) {
@@ -998,14 +1110,14 @@ function createObjectSettings(args) {
998
1110
  }
999
1111
  }
1000
1112
  return {
1001
- settings: result,
1002
- documentation: documentationLines.filter(Boolean).join("\n") || void 0
1113
+ documentation: documentationLines.filter(Boolean).join("\n") || void 0,
1114
+ settings: result
1003
1115
  };
1004
1116
  }
1005
1117
  function createSettingElement({
1006
- line,
1007
1118
  config,
1008
1119
  fieldElement,
1120
+ line,
1009
1121
  match
1010
1122
  }) {
1011
1123
  const result = {
@@ -1013,75 +1125,95 @@ function createSettingElement({
1013
1125
  element: void 0
1014
1126
  };
1015
1127
  if (line.startsWith("@deprecated")) {
1016
- fieldElement.arguments["deprecationReason"] = trim(line.slice(11));
1017
- result.element = fieldElement;
1128
+ const DEPRECATED_PREFIX_LENGTH = 11;
1129
+ const updatedFieldElement = {
1130
+ ...fieldElement,
1131
+ arguments: {
1132
+ ...fieldElement.arguments,
1133
+ deprecationReason: trim(line.slice(DEPRECATED_PREFIX_LENGTH))
1134
+ }
1135
+ };
1136
+ result.element = updatedFieldElement;
1018
1137
  return result;
1019
1138
  }
1020
1139
  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;
1140
+ const COMPLEXITY_PREFIX_LENGTH = 11;
1141
+ const MIN_COMPLEXITY = 1;
1142
+ let n = Number.parseInt(trim(line.slice(COMPLEXITY_PREFIX_LENGTH)), 10);
1143
+ if (Number.isNaN(n) || n < MIN_COMPLEXITY) {
1144
+ n = MIN_COMPLEXITY;
1145
+ }
1146
+ const updatedFieldElement = {
1147
+ ...fieldElement,
1148
+ arguments: {
1149
+ ...fieldElement.arguments,
1150
+ complexity: n
1151
+ }
1152
+ };
1153
+ result.element = updatedFieldElement;
1025
1154
  return result;
1026
1155
  }
1027
1156
  const name = match?.groups?.name;
1028
- if (!(match && name)) {
1157
+ if (!(match && name !== void 0 && name !== "")) {
1029
1158
  result.documentLine = line;
1030
1159
  return result;
1031
1160
  }
1032
1161
  const element = {
1033
- kind: "Decorator",
1034
- name: "",
1035
1162
  arguments: [],
1163
+ from: "",
1036
1164
  input: false,
1037
- output: false,
1165
+ kind: "Decorator",
1038
1166
  model: false,
1039
- from: ""
1167
+ name: "",
1168
+ output: false
1040
1169
  };
1041
1170
  result.element = element;
1042
1171
  if (name === "TypeGraphQL.omit" || name === "HideField") {
1043
1172
  Object.assign(element, hideFieldDecorator(match));
1044
1173
  return result;
1045
1174
  }
1046
- if (["FieldType", "PropertyType"].includes(name) && match.groups?.args) {
1175
+ if (["FieldType", "PropertyType"].includes(name) && match.groups?.args !== void 0 && match.groups.args !== "") {
1047
1176
  const options2 = customType(match.groups.args);
1048
- merge(element, options2.namespace && config.fields[options2.namespace], options2, {
1177
+ const namespaceConfig2 = options2.namespace !== void 0 && options2.namespace !== "" ? config.fields[options2.namespace] : void 0;
1178
+ merge(element, namespaceConfig2, options2, {
1049
1179
  kind: name
1050
1180
  });
1051
1181
  return result;
1052
1182
  }
1053
- if (name === "ObjectType" && match.groups?.args) {
1183
+ if (name === "ObjectType" && match.groups?.args !== void 0 && match.groups.args !== "") {
1054
1184
  element.kind = "ObjectType";
1055
1185
  const options2 = customType(match.groups.args);
1056
- if (typeof options2[0] === "string" && options2[0]) {
1186
+ if (typeof options2[0] === "string" && options2[0] !== "") {
1057
1187
  options2.name = options2[0];
1058
1188
  }
1059
1189
  if (isObject(options2[1])) {
1060
1190
  merge(options2, options2[1]);
1061
1191
  }
1062
1192
  element.arguments = {
1063
- name: options2.name,
1064
- isAbstract: options2.isAbstract
1193
+ isAbstract: options2.isAbstract,
1194
+ name: options2.name
1065
1195
  };
1066
1196
  return result;
1067
1197
  }
1068
- if (name === "Directive" && match.groups?.args) {
1198
+ if (name === "Directive" && match.groups?.args !== void 0 && match.groups.args !== "") {
1069
1199
  const options2 = customType(match.groups.args);
1070
- merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
1071
- name,
1072
- namespace: false,
1200
+ merge(element, { from: "@nestjs/graphql", model: true }, options2, {
1201
+ arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => JSON52.stringify(s)) : options2.arguments,
1073
1202
  kind: "Decorator",
1074
- arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => JSON52.stringify(s)) : options2.arguments
1203
+ name,
1204
+ namespace: false
1075
1205
  });
1076
1206
  return result;
1077
1207
  }
1078
1208
  const namespace = getNamespace(name);
1079
1209
  element.namespaceImport = namespace;
1210
+ const args = match.groups?.args ?? "";
1080
1211
  const options = {
1081
- name,
1082
- arguments: (match.groups?.args || "").split(",").map((s) => trim(s)).filter(Boolean)
1212
+ arguments: args.split(",").map((s) => trim(s)).filter(Boolean),
1213
+ name
1083
1214
  };
1084
- merge(element, namespace && config.fields[namespace], options);
1215
+ const namespaceConfig = namespace !== void 0 && namespace !== "" ? config.fields[namespace] : void 0;
1216
+ merge(element, namespaceConfig, options);
1085
1217
  return result;
1086
1218
  }
1087
1219
  function customType(args) {
@@ -1093,7 +1225,8 @@ function customType(args) {
1093
1225
  Object.assign(result, options);
1094
1226
  const namespace = getNamespace(options.name);
1095
1227
  result.namespace = namespace;
1096
- if (options.name?.includes(".")) {
1228
+ const optionsWithName = options;
1229
+ if (optionsWithName.name !== void 0 && optionsWithName.name !== "" && optionsWithName.name.includes(".")) {
1097
1230
  result.namespaceImport = namespace;
1098
1231
  }
1099
1232
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -1103,29 +1236,30 @@ function customType(args) {
1103
1236
  }
1104
1237
  function hideFieldDecorator(match) {
1105
1238
  const result = {
1106
- name: "HideField",
1107
1239
  arguments: [],
1108
- from: "@nestjs/graphql",
1109
1240
  defaultImport: void 0,
1110
- namespaceImport: void 0,
1111
- match: void 0
1241
+ from: "@nestjs/graphql",
1242
+ match: void 0,
1243
+ name: "HideField",
1244
+ namespaceImport: void 0
1112
1245
  };
1113
- if (!match.groups?.args) {
1246
+ const args = match.groups?.args;
1247
+ if (args === void 0 || args === "") {
1114
1248
  result.output = true;
1115
1249
  return result;
1116
1250
  }
1117
- if (match.groups.args.includes("{") && match.groups.args.includes("}")) {
1118
- const options = parseArgs(match.groups.args);
1251
+ if (args.includes("{") && args.includes("}")) {
1252
+ const options = parseArgs(args);
1119
1253
  result.output = Boolean(options.output);
1120
1254
  result.input = Boolean(options.input);
1121
1255
  if (typeof options.match === "string" || Array.isArray(options.match)) {
1122
1256
  result.match = outmatch2(options.match, { separator: false });
1123
1257
  }
1124
1258
  } else {
1125
- if (/output:\s*true/.test(match.groups.args)) {
1259
+ if (/output:\s*true/.test(args)) {
1126
1260
  result.output = true;
1127
1261
  }
1128
- if (/input:\s*true/.test(match.groups.args)) {
1262
+ if (/input:\s*true/.test(args)) {
1129
1263
  result.input = true;
1130
1264
  }
1131
1265
  }
@@ -1143,12 +1277,22 @@ function parseArgs(string) {
1143
1277
  }
1144
1278
  }
1145
1279
  function getNamespace(name) {
1146
- if (name === void 0) {
1280
+ if (name === void 0 || name === null) {
1281
+ return void 0;
1282
+ }
1283
+ if (typeof name !== "string") {
1284
+ return void 0;
1285
+ }
1286
+ let result = name;
1287
+ if (result === "") {
1147
1288
  return void 0;
1148
1289
  }
1149
- let result = String(name);
1150
1290
  if (result.includes(".")) {
1151
- [result] = result.split(".");
1291
+ const parts = result.split(".");
1292
+ result = parts[0] ?? "";
1293
+ }
1294
+ if (result === "") {
1295
+ return void 0;
1152
1296
  }
1153
1297
  return result;
1154
1298
  }
@@ -1156,12 +1300,12 @@ function getNamespace(name) {
1156
1300
  // src/handlers/model-data.ts
1157
1301
  function modelData(model, args) {
1158
1302
  const {
1303
+ classTransformerTypeModels,
1159
1304
  config,
1160
- modelNames,
1161
- models,
1162
- modelFields,
1163
1305
  fieldSettings,
1164
- classTransformerTypeModels
1306
+ modelFields,
1307
+ modelNames,
1308
+ models
1165
1309
  } = args;
1166
1310
  modelNames.push(model.name);
1167
1311
  models.set(model.name, model);
@@ -1170,10 +1314,10 @@ function modelData(model, args) {
1170
1314
  const fieldSettingsValue = /* @__PURE__ */ new Map();
1171
1315
  fieldSettings.set(model.name, fieldSettingsValue);
1172
1316
  for (const field of model.fields) {
1173
- if (field.documentation) {
1317
+ if (field.documentation !== null && field.documentation !== void 0 && field.documentation.length > 0) {
1174
1318
  const { documentation, settings } = createObjectSettings({
1175
- text: field.documentation,
1176
- config
1319
+ config,
1320
+ text: field.documentation
1177
1321
  });
1178
1322
  field.documentation = documentation;
1179
1323
  fieldSettingsValue.set(field.name, settings);
@@ -1192,8 +1336,14 @@ function createComment(documentation, settings) {
1192
1336
  for (const line of documentationLines) {
1193
1337
  commentLines.push(` * ${line}`);
1194
1338
  }
1195
- const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1196
- if (deprecationReason) {
1339
+ const fieldArgs = settings?.fieldArguments();
1340
+ let deprecationReason;
1341
+ if (fieldArgs === void 0) {
1342
+ deprecationReason = void 0;
1343
+ } else {
1344
+ deprecationReason = fieldArgs.deprecationReason;
1345
+ }
1346
+ if (deprecationReason !== void 0 && deprecationReason !== null && deprecationReason.length > 0) {
1197
1347
  commentLines.push(` * @deprecated ${deprecationReason}`);
1198
1348
  }
1199
1349
  commentLines.push(" */\n");
@@ -1208,6 +1358,9 @@ function buildDependencyGraph(models) {
1208
1358
  }
1209
1359
  for (const model of models) {
1210
1360
  const dependencies = graph.get(model.name);
1361
+ if (!dependencies) {
1362
+ continue;
1363
+ }
1211
1364
  for (const field of model.fields) {
1212
1365
  if (field.kind === "object" && field.type !== model.name) {
1213
1366
  if (graph.has(field.type)) {
@@ -1227,7 +1380,7 @@ function detectCircularDependencies(graph) {
1227
1380
  visited.add(node);
1228
1381
  recursionStack.add(node);
1229
1382
  path.push(node);
1230
- const dependencies = graph.get(node) || /* @__PURE__ */ new Set();
1383
+ const dependencies = graph.get(node) ?? /* @__PURE__ */ new Set();
1231
1384
  for (const dep of dependencies) {
1232
1385
  if (!visited.has(dep)) {
1233
1386
  dfs(dep);
@@ -1277,7 +1430,9 @@ function modelOutputType(outputType2, args) {
1277
1430
  models,
1278
1431
  output
1279
1432
  } = args;
1280
- if (isManyAndReturnOutputType(outputType2.name)) return;
1433
+ if (isManyAndReturnOutputType(outputType2.name)) {
1434
+ return;
1435
+ }
1281
1436
  const model = models.get(outputType2.name);
1282
1437
  ok(model, `Cannot find model by name ${outputType2.name}`);
1283
1438
  const sourceFile = getSourceFile({
@@ -1307,16 +1462,14 @@ function modelOutputType(outputType2, args) {
1307
1462
  const decorator = classStructure.decorators.find((d) => d.name === "ObjectType");
1308
1463
  ok(decorator, "ObjectType decorator not found");
1309
1464
  let modelSettings;
1310
- if (model.documentation) {
1465
+ if (model.documentation !== null && model.documentation !== void 0 && model.documentation.length > 0) {
1311
1466
  const objectTypeOptions = {};
1312
1467
  const { documentation, settings } = createObjectSettings({
1313
1468
  config,
1314
1469
  text: model.documentation
1315
1470
  });
1316
- if (documentation) {
1317
- if (!classStructure.leadingTrivia) {
1318
- classStructure.leadingTrivia = createComment(documentation);
1319
- }
1471
+ if (documentation !== void 0 && documentation.length > 0) {
1472
+ classStructure.leadingTrivia ??= createComment(documentation);
1320
1473
  objectTypeOptions.description = documentation;
1321
1474
  }
1322
1475
  decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
@@ -1334,10 +1487,12 @@ function modelOutputType(outputType2, args) {
1334
1487
  importDeclarations.add("getType", typeRegistryPath);
1335
1488
  }
1336
1489
  for (const field of outputType2.fields) {
1337
- if (config.omitModelsCount && field.name === "_count") continue;
1490
+ if (config.omitModelsCount && field.name === "_count") {
1491
+ continue;
1492
+ }
1338
1493
  let fileType = "model";
1339
1494
  const { isList, location, namespace, type } = field.outputType;
1340
- let outputTypeName = String(type);
1495
+ let outputTypeName = type;
1341
1496
  if (namespace !== "model") {
1342
1497
  fileType = "output";
1343
1498
  outputTypeName = getOutputTypeName(outputTypeName);
@@ -1359,15 +1514,12 @@ function modelOutputType(outputType2, args) {
1359
1514
  })
1360
1515
  );
1361
1516
  propertyType.splice(1, propertyType.length);
1362
- if (field.isNullable && !isList) {
1517
+ if (field.isNullable === true && !isList) {
1363
1518
  propertyType.push("null");
1364
1519
  }
1365
1520
  let graphqlType;
1366
1521
  let useGetType = false;
1367
- if (fieldType) {
1368
- graphqlType = fieldType.name;
1369
- importDeclarations.create({ ...fieldType });
1370
- } else {
1522
+ if (fieldType === void 0) {
1371
1523
  const graphqlImport = getGraphqlImport({
1372
1524
  config,
1373
1525
  fileType,
@@ -1379,7 +1531,7 @@ function modelOutputType(outputType2, args) {
1379
1531
  typeName: outputTypeName
1380
1532
  });
1381
1533
  graphqlType = graphqlImport.name;
1382
- if (graphqlImport.name !== outputType2.name && graphqlImport.specifier) {
1534
+ if (graphqlImport.name !== outputType2.name && graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && graphqlImport.specifier.length > 0) {
1383
1535
  const isCircular = config.esmCompatible && location === "outputObjectTypes" && namespace === "model" && hasCircularDependency(circularDependencies, outputType2.name, outputTypeName);
1384
1536
  if (isCircular) {
1385
1537
  importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
@@ -1389,6 +1541,9 @@ function modelOutputType(outputType2, args) {
1389
1541
  importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
1390
1542
  }
1391
1543
  }
1544
+ } else {
1545
+ graphqlType = fieldType.name;
1546
+ importDeclarations.create({ ...fieldType });
1392
1547
  }
1393
1548
  const property = propertyStructure({
1394
1549
  hasExclamationToken: true,
@@ -1398,17 +1553,19 @@ function modelOutputType(outputType2, args) {
1398
1553
  name: field.name,
1399
1554
  propertyType
1400
1555
  });
1401
- if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1556
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation.length > 0) {
1402
1557
  property.leadingTrivia += createComment(modelField.documentation, settings);
1403
1558
  }
1404
- classStructure.properties?.push(property);
1405
- if (propertySettings) {
1559
+ if (classStructure.properties !== void 0) {
1560
+ classStructure.properties.push(property);
1561
+ }
1562
+ if (propertySettings !== void 0) {
1406
1563
  importDeclarations.create({ ...propertySettings });
1407
1564
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
1408
1565
  importDeclarations.add("Prisma", config.prismaClientImport);
1409
1566
  }
1410
- ok(property.decorators, "property.decorators is undefined");
1411
- const shouldHideField = settings?.shouldHideField({ name: outputType2.name, output: true }) || config.decorate.some(
1567
+ ok(property.decorators !== void 0, "property.decorators is undefined");
1568
+ const shouldHideField = settings?.shouldHideField({ name: outputType2.name, output: true }) === true || config.decorate.some(
1412
1569
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1413
1570
  );
1414
1571
  if (shouldHideField) {
@@ -1429,7 +1586,7 @@ function modelOutputType(outputType2, args) {
1429
1586
  defaultValue: ["number", "string", "boolean"].includes(
1430
1587
  typeof modelField?.default
1431
1588
  ) ? modelField?.default : void 0,
1432
- description: modelField?.documentation,
1589
+ description: modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation !== "" ? modelField.documentation : void 0,
1433
1590
  nullable: Boolean(field.isNullable)
1434
1591
  })
1435
1592
  ],
@@ -1441,7 +1598,10 @@ function modelOutputType(outputType2, args) {
1441
1598
  arguments: setting.arguments,
1442
1599
  name: setting.name
1443
1600
  });
1444
- ok(setting.from, "Missed 'from' part in configuration or field setting");
1601
+ ok(
1602
+ setting.from && setting.from.length > 0,
1603
+ "Missed 'from' part in configuration or field setting"
1604
+ );
1445
1605
  importDeclarations.create(setting);
1446
1606
  }
1447
1607
  }
@@ -1509,13 +1669,14 @@ function noAtomicOperations(eventEmitter) {
1509
1669
  eventEmitter.on("BeforeGenerateFiles", beforeGenerateFiles);
1510
1670
  }
1511
1671
  function beforeInputType2(args) {
1512
- const { inputType: inputType2, getModelName: getModelName2 } = args;
1672
+ const { getModelName: getModelName2, inputType: inputType2 } = args;
1513
1673
  for (const field of inputType2.fields) {
1514
1674
  const fieldName = field.name;
1515
1675
  field.inputTypes = field.inputTypes.filter((it) => {
1516
- const inputTypeName = String(it.type);
1676
+ const inputTypeName = it.type;
1517
1677
  const modelName = getModelName2(inputTypeName);
1518
- if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName, fieldName)) {
1678
+ const isModelNameValid = modelName !== null && modelName !== void 0 && modelName.length > 0;
1679
+ if (isAtomicOperation(inputTypeName) || isModelNameValid && isListInput(inputTypeName, modelName, fieldName)) {
1519
1680
  return false;
1520
1681
  }
1521
1682
  return true;
@@ -1526,7 +1687,8 @@ function beforeGenerateFiles(args) {
1526
1687
  const { project } = args;
1527
1688
  for (const sourceFile of project.getSourceFiles()) {
1528
1689
  const className = sourceFile.getClass(() => true)?.getName();
1529
- if (className && isAtomicOperation(className)) {
1690
+ const isClassNameValid = className !== void 0 && className !== null && className.length > 0;
1691
+ if (isClassNameValid && isAtomicOperation(className)) {
1530
1692
  project.removeSourceFile(sourceFile);
1531
1693
  }
1532
1694
  }
@@ -1552,11 +1714,13 @@ function outputType(outputTypeArg, args) {
1552
1714
  const { config, eventEmitter, fieldSettings, getModelName: getModelName2, getSourceFile, models } = args;
1553
1715
  const importDeclarations = new ImportDeclarationMap();
1554
1716
  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;
1717
+ const modelName = getModelName2(outputTypeArg.name);
1718
+ const model = modelName === void 0 ? void 0 : models.get(modelName);
1719
+ const isAggregateOutput = model !== void 0 && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputTypeArg.name) && outputTypeArg.name.startsWith(model.name);
1720
+ const isCountOutput = model?.name !== void 0 && model.name !== "" && outputTypeArg.name === `${model.name}CountOutputType`;
1721
+ if (config.emitBlocks.outputs || isCountOutput) ; else {
1722
+ return;
1723
+ }
1560
1724
  outputTypeArg.name = getOutputTypeName(outputTypeArg.name);
1561
1725
  if (isAggregateOutput) {
1562
1726
  eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputTypeArg });
@@ -1581,8 +1745,15 @@ function outputType(outputTypeArg, args) {
1581
1745
  importDeclarations.add("ObjectType", nestjsGraphql2);
1582
1746
  for (const field of outputTypeArg.fields) {
1583
1747
  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);
1748
+ const outputTypeName = getOutputTypeName(type);
1749
+ let settings;
1750
+ if (isCountOutput) {
1751
+ settings = void 0;
1752
+ } else if (model === void 0) {
1753
+ settings = void 0;
1754
+ } else {
1755
+ settings = fieldSettings.get(model.name)?.get(field.name);
1756
+ }
1586
1757
  const propertySettings = settings?.getPropertyType({
1587
1758
  name: outputTypeArg.name,
1588
1759
  output: true
@@ -1603,7 +1774,7 @@ function outputType(outputTypeArg, args) {
1603
1774
  propertyType
1604
1775
  });
1605
1776
  classStructure.properties?.push(property);
1606
- if (propertySettings) {
1777
+ if (propertySettings !== void 0) {
1607
1778
  importDeclarations.create({ ...propertySettings });
1608
1779
  } else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
1609
1780
  importDeclarations.add("Prisma", config.prismaClientImport);
@@ -1612,14 +1783,14 @@ function outputType(outputTypeArg, args) {
1612
1783
  const shouldHideField = settings?.shouldHideField({
1613
1784
  name: outputTypeArg.name,
1614
1785
  output: true
1615
- }) || config.decorate.some(
1786
+ }) === true || config.decorate.some(
1616
1787
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1617
1788
  );
1618
1789
  const fieldType = settings?.getFieldType({
1619
1790
  name: outputTypeArg.name,
1620
1791
  output: true
1621
1792
  });
1622
- if (fieldType && isCustomsApplicable && !shouldHideField) {
1793
+ if (fieldType !== void 0 && isCustomsApplicable && !shouldHideField) {
1623
1794
  graphqlType = fieldType.name;
1624
1795
  importDeclarations.create({ ...fieldType });
1625
1796
  } else {
@@ -1634,14 +1805,14 @@ function outputType(outputTypeArg, args) {
1634
1805
  });
1635
1806
  const referenceName = location === "enumTypes" ? getEnumName(propertyType[0]) : propertyType[0];
1636
1807
  graphqlType = graphqlImport.name;
1637
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputTypeArg.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1808
+ 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
1809
  importDeclarations.set(graphqlImport.name, {
1639
1810
  moduleSpecifier: graphqlImport.specifier,
1640
1811
  namedImports: [{ name: graphqlImport.name }]
1641
1812
  });
1642
1813
  }
1643
1814
  }
1644
- ok(property.decorators, "property.decorators is undefined");
1815
+ ok(property.decorators !== void 0, "property.decorators is undefined");
1645
1816
  if (shouldHideField) {
1646
1817
  importDeclarations.add("HideField", nestjsGraphql2);
1647
1818
  property.decorators.push({ arguments: [], name: "HideField" });
@@ -1658,12 +1829,16 @@ function outputType(outputTypeArg, args) {
1658
1829
  });
1659
1830
  if (isCustomsApplicable) {
1660
1831
  for (const options of settings ?? []) {
1661
- if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1832
+ const shouldApplyDecorator = options.kind === "Decorator" && options.output && (options.match?.(field.name) ?? true);
1833
+ if (shouldApplyDecorator) {
1662
1834
  property.decorators.push({
1663
1835
  arguments: options.arguments,
1664
1836
  name: options.name
1665
1837
  });
1666
- ok(options.from, "Missed 'from' part in configuration or field setting");
1838
+ ok(
1839
+ options.from !== null && options.from !== void 0 && options.from.length > 0,
1840
+ "Missed 'from' part in configuration or field setting"
1841
+ );
1667
1842
  importDeclarations.create(options);
1668
1843
  }
1669
1844
  }
@@ -1679,11 +1854,15 @@ function outputType(outputTypeArg, args) {
1679
1854
  statements: [...importDeclarations.toStatements(), classStructure]
1680
1855
  });
1681
1856
  }
1857
+ var rmdirTyped = rmdirSync$1;
1858
+ var rmdirSync = (path) => {
1859
+ rmdirTyped(path);
1860
+ };
1682
1861
  function purgeOutput(emitter) {
1683
1862
  emitter.on("Begin", begin);
1684
1863
  emitter.on("End", end);
1685
1864
  }
1686
- function begin({ project, output }) {
1865
+ function begin({ output, project }) {
1687
1866
  const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1688
1867
  if (sourceFiles) {
1689
1868
  for (const sourceFile of sourceFiles) {
@@ -1691,9 +1870,10 @@ function begin({ project, output }) {
1691
1870
  }
1692
1871
  }
1693
1872
  }
1694
- function end({ project, output }) {
1873
+ function end({ output, project }) {
1695
1874
  const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1696
- for (const directory of directories ?? []) {
1875
+ const directoryList = directories ?? [];
1876
+ for (const directory of directoryList) {
1697
1877
  try {
1698
1878
  rmdirSync(directory);
1699
1879
  } catch {
@@ -1711,7 +1891,7 @@ function reExport(emitter) {
1711
1891
  emitter.on("BeforeGenerateFiles", beforeGenerateFiles2);
1712
1892
  }
1713
1893
  function beforeGenerateFiles2(args) {
1714
- const { project, output, config } = args;
1894
+ const { config, output, project } = args;
1715
1895
  const rootDirectory = project.getDirectoryOrThrow(output);
1716
1896
  if (["Directories" /* Directories */, "All" /* All */].includes(config.reExport)) {
1717
1897
  const directories = [...rootDirectory.getDescendantDirectories()];
@@ -1758,7 +1938,9 @@ function beforeGenerateFiles2(args) {
1758
1938
  const exportDeclarations = [];
1759
1939
  const directories = rootDirectory.getDirectories();
1760
1940
  for (const directory of directories) {
1761
- if (directory.getBaseName() === "node_modules") continue;
1941
+ if (directory.getBaseName() === "node_modules") {
1942
+ continue;
1943
+ }
1762
1944
  const indexFile = directory.getSourceFile("index.ts");
1763
1945
  if (indexFile) {
1764
1946
  const dirName = directory.getBaseName();
@@ -1780,9 +1962,9 @@ function beforeGenerateFiles2(args) {
1780
1962
  function getExportDeclaration2(directory, sourceFile) {
1781
1963
  let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceFile);
1782
1964
  if (!moduleSpecifier.endsWith(".js") && !moduleSpecifier.endsWith(".ts")) {
1783
- moduleSpecifier = moduleSpecifier + ".js";
1965
+ moduleSpecifier += ".js";
1784
1966
  } else if (moduleSpecifier.endsWith(".ts")) {
1785
- moduleSpecifier = moduleSpecifier.slice(0, -3) + ".js";
1967
+ moduleSpecifier = `${moduleSpecifier.slice(0, -3)}.js`;
1786
1968
  }
1787
1969
  return {
1788
1970
  kind: StructureKind.ExportDeclaration,
@@ -1792,7 +1974,7 @@ function getExportDeclaration2(directory, sourceFile) {
1792
1974
  function getNamespaceExportDeclaration(directory, sourceDirectory) {
1793
1975
  let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceDirectory);
1794
1976
  if (!moduleSpecifier.endsWith("/index.js")) {
1795
- moduleSpecifier = moduleSpecifier + "/index.js";
1977
+ moduleSpecifier += "/index.js";
1796
1978
  }
1797
1979
  return {
1798
1980
  kind: StructureKind.ExportDeclaration,
@@ -1800,74 +1982,16 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
1800
1982
  };
1801
1983
  }
1802
1984
 
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
- }
1985
+ // src/handlers/register-all-types.ts
1860
1986
  function generateRegisterAllTypes(args) {
1861
1987
  const { config, output, project } = args;
1862
1988
  if (!config.esmCompatible) {
1863
1989
  return;
1864
1990
  }
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
- );
1991
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
1992
+ const sourceFile = rootDirectory.createSourceFile("register-all-types.ts", void 0, {
1993
+ overwrite: true
1994
+ });
1871
1995
  const importPaths = [];
1872
1996
  const typeNames = [];
1873
1997
  const allSourceFiles = project.getSourceFiles(`${output}/**/*.ts`);
@@ -1877,7 +2001,7 @@ function generateRegisterAllTypes(args) {
1877
2001
  continue;
1878
2002
  }
1879
2003
  const fileText = file.getText();
1880
- const registerMatch = fileText.match(/registerType\(['"]([^'"]+)['"]/);
2004
+ const registerMatch = /registerType\(['"]([^'"]+)['"]/.exec(fileText);
1881
2005
  if (registerMatch) {
1882
2006
  const relPath = relativePath(sourceFile.getFilePath(), filePath);
1883
2007
  importPaths.push(relPath);
@@ -1931,6 +2055,76 @@ export type RegisteredTypeName = typeof registeredTypes[number];
1931
2055
  sourceFile.addStatements(fileContent);
1932
2056
  }
1933
2057
 
2058
+ // src/handlers/prisma-enum-doc.ts
2059
+ function extractEnumValueDocs(values) {
2060
+ return Object.fromEntries(
2061
+ values.map((value) => {
2062
+ const { name } = value;
2063
+ const { documentation } = value;
2064
+ if (typeof documentation !== "string") {
2065
+ return null;
2066
+ }
2067
+ if (documentation.startsWith("@deprecated")) {
2068
+ return [name, { deprecationReason: documentation.slice(11).trim() }];
2069
+ }
2070
+ return [name, { description: documentation }];
2071
+ }).filter((entry) => entry !== null)
2072
+ );
2073
+ }
2074
+
2075
+ // src/handlers/register-enum.ts
2076
+ function registerEnum(enumType, args) {
2077
+ const { config, enums, getSourceFile } = args;
2078
+ const enumTypeAsRecord = enumType;
2079
+ const rawName = enumTypeAsRecord.name;
2080
+ const enumName = typeof rawName === "string" ? rawName : String(rawName);
2081
+ const enumValue = enums[enumName];
2082
+ if (!config.emitBlocks.prismaEnums && enumValue === void 0) {
2083
+ return;
2084
+ }
2085
+ const dataModelEnum = enumValue;
2086
+ const enumTypesData = dataModelEnum?.values ?? [];
2087
+ const sourceFile = getSourceFile({
2088
+ name: enumName,
2089
+ type: "enum"
2090
+ });
2091
+ const importDeclarations = new ImportDeclarationMap();
2092
+ importDeclarations.set("registerEnumType", {
2093
+ moduleSpecifier: "@nestjs/graphql",
2094
+ namedImports: [{ name: "registerEnumType" }]
2095
+ });
2096
+ const valuesMap = extractEnumValueDocs(enumTypesData);
2097
+ const filteredValuesMap = Object.fromEntries(
2098
+ Object.entries(valuesMap).filter(([, v]) => Object.keys(v).length > 0)
2099
+ );
2100
+ const hasValuesMap = Object.keys(filteredValuesMap).length > 0;
2101
+ const formattedValuesMap = hasValuesMap ? JSON.stringify(filteredValuesMap, null, 2).replace(/"([^"]+)":/g, "$1:") : "";
2102
+ const valuesMapEntry = hasValuesMap ? `, valuesMap: ${formattedValuesMap}` : "";
2103
+ const enumTypeRecord = enumType;
2104
+ const rawValues = enumTypeRecord.values;
2105
+ const enumValues = Array.isArray(rawValues) ? rawValues.map((v) => String(v)) : [];
2106
+ const enumStructure = {
2107
+ isExported: true,
2108
+ kind: StructureKind.Enum,
2109
+ members: enumValues.map((v) => ({
2110
+ initializer: JSON.stringify(v),
2111
+ name: v
2112
+ })),
2113
+ name: enumName
2114
+ };
2115
+ const enumTypeName = enumName;
2116
+ sourceFile.set({
2117
+ statements: [
2118
+ ...importDeclarations.toStatements(),
2119
+ enumStructure,
2120
+ "\n",
2121
+ `registerEnumType(${enumTypeName}, { name: '${enumTypeName}', description: ${JSON.stringify(
2122
+ dataModelEnum?.documentation
2123
+ )}${valuesMapEntry} })`
2124
+ ]
2125
+ });
2126
+ }
2127
+
1934
2128
  // src/handlers/require-single-fields-in-whereunique-input.ts
1935
2129
  function requireSingleFieldsInWhereUniqueInput(eventEmitter) {
1936
2130
  eventEmitter.on("BeforeInputType", beforeInputType3);
@@ -1945,17 +2139,17 @@ function beforeInputType3(args) {
1945
2139
  field.isNullable = false;
1946
2140
  }
1947
2141
  }
2142
+
2143
+ // src/handlers/type-registry.ts
1948
2144
  function generateTypeRegistry(args) {
1949
2145
  const { config, output, project } = args;
1950
2146
  if (!config.esmCompatible) {
1951
2147
  return;
1952
2148
  }
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
- );
2149
+ const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
2150
+ const sourceFile = rootDirectory.createSourceFile("type-registry.ts", void 0, {
2151
+ overwrite: true
2152
+ });
1959
2153
  const registryCode = `/**
1960
2154
  * Type Registry for ESM Circular Dependency Resolution
1961
2155
  *
@@ -2086,81 +2280,17 @@ export function validateRegistry(expectedTypes: string[]): void {
2086
2280
  sourceFile.addStatements(registryCode);
2087
2281
  }
2088
2282
 
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
2283
  // src/handlers/warning.ts
2284
+ var globalConsole = globalThis.console;
2285
+ var log = (msg) => {
2286
+ globalConsole.log(msg);
2287
+ };
2158
2288
  function warning(message) {
2159
2289
  if (Array.isArray(message)) {
2160
- console.log("nestjs-prisma-graphql:");
2161
- console.log(message.join("\n"));
2290
+ log("nestjs-prisma-graphql:");
2291
+ log(message.join("\n"));
2162
2292
  } else {
2163
- console.log("nestjs-prisma-graphql:", message);
2293
+ log(`nestjs-prisma-graphql: ${message}`);
2164
2294
  }
2165
2295
  }
2166
2296
 
@@ -2174,44 +2304,51 @@ var allEmmittedBlocks = [
2174
2304
  "outputs"
2175
2305
  ];
2176
2306
  var blocksDependencyMap = {
2307
+ args: ["args", "inputs", "prismaEnums"],
2177
2308
  enums: ["schemaEnums", "prismaEnums"],
2178
- models: ["models", "schemaEnums"],
2179
2309
  inputs: ["inputs", "prismaEnums"],
2180
- outputs: ["outputs"],
2181
- args: ["args", "inputs", "prismaEnums"]
2310
+ models: ["models", "schemaEnums"],
2311
+ outputs: ["outputs"]
2182
2312
  };
2183
2313
  function createEmitBlocks(data) {
2184
2314
  if (!data) {
2185
- return Object.fromEntries(allEmmittedBlocks.map((block) => [block, true]));
2315
+ const entries = allEmmittedBlocks.map((block) => [block, true]);
2316
+ const allBlocks = Object.fromEntries(entries);
2317
+ return allBlocks;
2186
2318
  }
2187
- let blocksToEmit = {};
2319
+ const initialBlocks = {};
2320
+ let currentBlocks = initialBlocks;
2188
2321
  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
- )
2322
+ if (!Object.keys(blocksDependencyMap).includes(block)) {
2323
+ continue;
2324
+ }
2325
+ const blockEntries = blocksDependencyMap[block].map(
2326
+ (emittedBlock) => [emittedBlock, true]
2327
+ );
2328
+ const newBlocks = Object.fromEntries(blockEntries);
2329
+ currentBlocks = {
2330
+ ...currentBlocks,
2331
+ ...newBlocks
2195
2332
  };
2196
2333
  }
2197
- return blocksToEmit;
2334
+ return currentBlocks;
2198
2335
  }
2199
2336
 
2200
2337
  // src/helpers/create-config.ts
2201
2338
  function createConfig(data) {
2202
2339
  const config = merge({}, unflatten(data, { delimiter: "_" }));
2203
2340
  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, "/");
2341
+ const defaultPattern = `{model}/{name}.{type}.ts`;
2342
+ const outputFilePatternValue = config.outputFilePattern;
2343
+ const configOutputFilePattern = typeof outputFilePatternValue === "string" ? outputFilePatternValue : defaultPattern;
2344
+ const sanitizedStep1 = configOutputFilePattern.replaceAll("..", "/").replaceAll(/\/+/g, "/");
2345
+ const outputFilePattern = trim(sanitizedStep1, "/");
2209
2346
  if (outputFilePattern !== configOutputFilePattern) {
2210
2347
  $warnings.push(
2211
2348
  `Due to invalid filepath 'outputFilePattern' changed to '${outputFilePattern}'`
2212
2349
  );
2213
2350
  }
2214
- if (config.reExportAll) {
2351
+ if (config.reExportAll !== void 0 && config.reExportAll !== null && config.reExportAll !== false) {
2215
2352
  $warnings.push(`Option 'reExportAll' is deprecated, use 'reExport' instead`);
2216
2353
  if (toBoolean(config.reExportAll)) {
2217
2354
  config.reExport = "All";
@@ -2223,105 +2360,118 @@ function createConfig(data) {
2223
2360
  ).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
2224
2361
  const fieldSetting = {
2225
2362
  arguments: [],
2226
- output: toBoolean(value.output),
2363
+ defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
2364
+ from: value.from,
2227
2365
  input: toBoolean(value.input),
2228
2366
  model: toBoolean(value.model),
2229
- from: value.from,
2230
- defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
2231
- namespaceImport: value.namespaceImport
2367
+ namespaceImport: value.namespaceImport,
2368
+ output: toBoolean(value.output)
2232
2369
  };
2233
2370
  return [name, fieldSetting];
2234
2371
  })
2235
2372
  );
2236
2373
  const decorate = [];
2237
- const configDecorate = Object.values(
2238
- config.decorate || {}
2239
- );
2374
+ const decorateConfig = config.decorate !== void 0 && config.decorate !== null ? config.decorate : {};
2375
+ const configDecorate = Object.values(decorateConfig);
2240
2376
  for (const element of configDecorate) {
2241
- if (!element) continue;
2377
+ if (element === void 0 || element === null) {
2378
+ continue;
2379
+ }
2242
2380
  ok(
2243
- element.from && element.name,
2381
+ element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
2244
2382
  `Missed 'from' or 'name' part in configuration for decorate`
2245
2383
  );
2246
2384
  decorate.push({
2385
+ arguments: element.arguments !== void 0 && element.arguments !== "" ? JSON52.parse(element.arguments) : void 0,
2386
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2387
+ from: element.from,
2247
2388
  isMatchField: outmatch2(element.field, { separator: false }),
2248
2389
  isMatchType: outmatch2(element.type, { separator: false }),
2249
- from: element.from,
2250
2390
  name: element.name,
2251
2391
  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
2392
+ namespaceImport: element.namespaceImport
2255
2393
  });
2256
2394
  }
2257
2395
  const customImport = [];
2258
- const configCustomImport = Object.values(
2259
- config.customImport || {}
2260
- );
2396
+ const customImportConfig = config.customImport !== void 0 && config.customImport !== null ? config.customImport : {};
2397
+ const configCustomImport = Object.values(customImportConfig);
2261
2398
  for (const element of configCustomImport) {
2262
- if (!element) continue;
2399
+ if (element === void 0 || element === null) {
2400
+ continue;
2401
+ }
2263
2402
  ok(
2264
- element.from && element.name,
2403
+ element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
2265
2404
  `Missed 'from' or 'name' part in configuration for customImport`
2266
2405
  );
2267
2406
  customImport.push({
2407
+ defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2268
2408
  from: element.from,
2269
2409
  name: element.name,
2270
2410
  namedImport: toBoolean(element.namedImport),
2271
- defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
2272
2411
  namespaceImport: element.namespaceImport
2273
2412
  });
2274
2413
  }
2275
2414
  return {
2276
- outputFilePattern,
2277
- tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
2278
- prismaClientImport: createPrismaImport(config.prismaClientImport),
2415
+ $warnings,
2279
2416
  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),
2417
+ customImport,
2418
+ decorate,
2284
2419
  emitBlocks: createEmitBlocks(config.emitBlocks),
2285
- omitModelsCount: toBoolean(config.omitModelsCount),
2286
- $warnings,
2420
+ emitCompiled: toBoolean(config.emitCompiled),
2421
+ emitSingle: toBoolean(config.emitSingle),
2422
+ esmCompatible: toBoolean(config.esmCompatible),
2287
2423
  fields,
2288
- purgeOutput: toBoolean(config.purgeOutput),
2289
- useInputType: createUseInputType(config.useInputType),
2424
+ graphqlScalars: config.graphqlScalars ?? {},
2425
+ noAtomicOperations: toBoolean(config.noAtomicOperations),
2290
2426
  noTypeId: toBoolean(config.noTypeId),
2427
+ omitModelsCount: toBoolean(config.omitModelsCount),
2428
+ outputFilePattern,
2429
+ prismaClientImport: createPrismaImport(config.prismaClientImport),
2430
+ purgeOutput: toBoolean(config.purgeOutput),
2431
+ reExport: ReExport[String(config.reExport)] ?? "None" /* None */,
2291
2432
  requireSingleFieldsInWhereUniqueInput: toBoolean(
2292
2433
  config.requireSingleFieldsInWhereUniqueInput
2293
2434
  ),
2294
- unsafeCompatibleWhereUniqueInput: toBoolean(
2295
- config.unsafeCompatibleWhereUniqueInput
2296
- ),
2297
- graphqlScalars: config.graphqlScalars || {},
2298
- decorate,
2299
- customImport,
2300
- esmCompatible: toBoolean(config.esmCompatible)
2435
+ tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
2436
+ unsafeCompatibleWhereUniqueInput: toBoolean(config.unsafeCompatibleWhereUniqueInput),
2437
+ useInputType: createUseInputType(
2438
+ config.useInputType
2439
+ )
2301
2440
  };
2302
2441
  }
2303
- var tsConfigFileExists = memoize((filePath) => {
2304
- return existsSync(filePath);
2442
+ var existsSyncTyped = existsSync;
2443
+ var tsConfigFileExistsRaw = memoize((filePath) => {
2444
+ const exists = existsSyncTyped(filePath);
2445
+ return exists;
2305
2446
  });
2447
+ var tsConfigFileExists = tsConfigFileExistsRaw;
2306
2448
  function createTsConfigFilePathValue(value) {
2307
- if (typeof value === "string") return value;
2308
- if (tsConfigFileExists("tsconfig.json")) return "tsconfig.json";
2449
+ if (typeof value === "string" && value !== "") {
2450
+ return value;
2451
+ }
2452
+ const fileExists = tsConfigFileExists("tsconfig.json");
2453
+ if (fileExists) {
2454
+ return "tsconfig.json";
2455
+ }
2456
+ return void 0;
2309
2457
  }
2310
2458
  function createPrismaImport(value) {
2311
- if (typeof value === "string") return value;
2459
+ if (typeof value === "string" && value !== "") {
2460
+ return value;
2461
+ }
2312
2462
  return "@prisma/client";
2313
2463
  }
2314
2464
  function createUseInputType(data) {
2315
- if (!data) {
2465
+ if (data === void 0 || data === null) {
2316
2466
  return [];
2317
2467
  }
2318
2468
  const result = [];
2319
2469
  for (const [typeName, useInputs] of Object.entries(data)) {
2320
2470
  const entry = {
2321
- typeName,
2322
- ALL: void 0
2471
+ ALL: void 0,
2472
+ typeName
2323
2473
  };
2324
- if (useInputs.ALL) {
2474
+ if (useInputs.ALL !== void 0 && useInputs.ALL !== "") {
2325
2475
  entry.ALL = useInputs.ALL;
2326
2476
  delete useInputs.ALL;
2327
2477
  }
@@ -2339,7 +2489,7 @@ function generateFileName(args) {
2339
2489
  const { getModelName: getModelName2, name, template, type } = args;
2340
2490
  const rawPath = pupa(template, {
2341
2491
  get model() {
2342
- const result = getModelName2(name) || "prisma";
2492
+ const result = getModelName2(name) ?? "prisma";
2343
2493
  return kebabCase(result);
2344
2494
  },
2345
2495
  get name() {
@@ -2364,61 +2514,19 @@ function generateFileName(args) {
2364
2514
 
2365
2515
  // src/helpers/factory-get-source-file.ts
2366
2516
  function factoryGetSourceFile(args) {
2367
- const { outputFilePattern, output, getModelName: getModelName2, project } = args;
2368
- return function getSourceFile(args2) {
2369
- const { name, type } = args2;
2517
+ const { getModelName: getModelName2, output, outputFilePattern, project } = args;
2518
+ return function getSourceFile(getSourceFileArgs) {
2519
+ const { name, type } = getSourceFileArgs;
2370
2520
  let filePath = generateFileName({
2371
2521
  getModelName: getModelName2,
2372
2522
  name,
2373
- type,
2374
- template: outputFilePattern
2523
+ template: outputFilePattern,
2524
+ type
2375
2525
  });
2376
2526
  filePath = `${output}/${filePath}`;
2377
- return project.getSourceFile(filePath) || project.createSourceFile(filePath, void 0, { overwrite: true });
2527
+ return project.getSourceFile(filePath) ?? project.createSourceFile(filePath, void 0, { overwrite: true });
2378
2528
  };
2379
2529
  }
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
2530
  var splitKeywords = [
2423
2531
  "CreateInput",
2424
2532
  "CreateMany",
@@ -2498,28 +2606,85 @@ var middleKeywords = [
2498
2606
  ["GroupBy", "Args"],
2499
2607
  ["OrderBy", "Args"]
2500
2608
  ];
2609
+ function createGetModelName(modelNames) {
2610
+ return memoize(tryGetName);
2611
+ function tryGetName(name) {
2612
+ return getModelName({ modelNames, name });
2613
+ }
2614
+ }
2615
+ function getModelName(args) {
2616
+ const { modelNames, name } = args;
2617
+ for (const keyword of splitKeywords) {
2618
+ const [test] = name.split(keyword, 1);
2619
+ if (test !== void 0 && modelNames.includes(test)) {
2620
+ return test;
2621
+ }
2622
+ }
2623
+ for (const keyword of endsWithKeywords) {
2624
+ const test = name.split(keyword).at(-1);
2625
+ if (test !== void 0 && modelNames.includes(test)) {
2626
+ return test;
2627
+ }
2628
+ }
2629
+ for (const [start, end2] of middleKeywords) {
2630
+ let test = name.slice(start.length).slice(0, -end2.length);
2631
+ if (modelNames.includes(test) && name.startsWith(start) && name.endsWith(end2)) {
2632
+ return test;
2633
+ }
2634
+ test = name.slice(0, -(start + end2).length);
2635
+ if (modelNames.includes(test) && name.endsWith(start + end2)) {
2636
+ return test;
2637
+ }
2638
+ }
2639
+ if (name.endsWith("CompoundUniqueInput")) {
2640
+ const test = name.slice(0, -19);
2641
+ const models = modelNames.filter((x) => test.startsWith(x)).sort((a, b) => b.length - a.length);
2642
+ return models[0];
2643
+ }
2644
+ if (name.endsWith("Count")) {
2645
+ const test = name.slice(0, -5);
2646
+ if (modelNames.includes(test)) {
2647
+ return test;
2648
+ }
2649
+ }
2650
+ return void 0;
2651
+ }
2501
2652
 
2502
2653
  // src/generate.ts
2503
- var requireCjs = createRequire(import.meta.url);
2504
- var AwaitEventEmitter = requireCjs("await-event-emitter").default;
2654
+ var createRequireTyped = createRequire;
2655
+ var requireCjs = createRequireTyped(String(import.meta.url));
2656
+ var AwaitEventEmitter = requireCjs(
2657
+ "await-event-emitter"
2658
+ );
2659
+ var AwaitEventEmitterClass = AwaitEventEmitter.default;
2505
2660
  async function generate(args) {
2506
2661
  const { connectCallback, dmmf, generator, skipAddOutputSourceFiles } = args;
2507
- const generatorOutputValue = generator.output?.value;
2508
- ok(generatorOutputValue, "Missing generator configuration: output");
2662
+ const generatorOutputValue = generator.output?.value ?? "";
2663
+ ok(generatorOutputValue !== "", "Missing generator configuration: output");
2509
2664
  const config = createConfig(generator.config);
2510
- const eventEmitter = new AwaitEventEmitter();
2665
+ const eventEmitter = new AwaitEventEmitterClass();
2511
2666
  eventEmitter.on("Warning", warning);
2512
- config.emitBlocks.models && eventEmitter.on("Model", modelData);
2667
+ if (config.emitBlocks.models) {
2668
+ eventEmitter.on("Model", modelData);
2669
+ }
2513
2670
  if (config.emitBlocks.prismaEnums || config.emitBlocks.schemaEnums) {
2514
2671
  eventEmitter.on("EnumType", registerEnum);
2515
2672
  }
2516
2673
  if (config.emitBlocks.outputs || config.emitBlocks.models && !config.omitModelsCount) {
2517
2674
  eventEmitter.on("OutputType", outputType);
2518
2675
  }
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);
2676
+ if (config.emitBlocks.models) {
2677
+ eventEmitter.on("ModelOutputType", modelOutputType);
2678
+ }
2679
+ if (config.emitBlocks.outputs) {
2680
+ eventEmitter.on("AggregateOutput", createAggregateInput);
2681
+ }
2682
+ if (config.emitBlocks.inputs) {
2683
+ eventEmitter.on("InputType", inputType);
2684
+ }
2685
+ if (config.emitBlocks.args) {
2686
+ eventEmitter.on("ArgsType", argsType);
2687
+ }
2523
2688
  eventEmitter.on("GenerateFiles", generateFiles);
2524
2689
  for (const message of config.$warnings) {
2525
2690
  eventEmitter.emitSync("Warning", message);
@@ -2532,18 +2697,30 @@ async function generate(args) {
2532
2697
  skipLoadingLibFiles: !config.emitCompiled,
2533
2698
  tsConfigFilePath: config.tsConfigFilePath
2534
2699
  });
2535
- if (!skipAddOutputSourceFiles) {
2700
+ if (skipAddOutputSourceFiles !== true) {
2536
2701
  project.addSourceFilesAtPaths([
2537
2702
  `${generatorOutputValue}/**/*.ts`,
2538
2703
  `!${generatorOutputValue}/**/*.d.ts`
2539
2704
  ]);
2540
2705
  }
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);
2706
+ if (config.combineScalarFilters) {
2707
+ combineScalarFilters(eventEmitter);
2708
+ }
2709
+ if (config.noAtomicOperations) {
2710
+ noAtomicOperations(eventEmitter);
2711
+ }
2712
+ if (config.reExport !== "None" /* None */) {
2713
+ reExport(eventEmitter);
2714
+ }
2715
+ if (config.emitSingle) {
2716
+ emitSingle(eventEmitter);
2717
+ }
2718
+ if (config.purgeOutput) {
2719
+ purgeOutput(eventEmitter);
2720
+ }
2721
+ if (config.requireSingleFieldsInWhereUniqueInput) {
2722
+ requireSingleFieldsInWhereUniqueInput(eventEmitter);
2723
+ }
2547
2724
  const models = /* @__PURE__ */ new Map();
2548
2725
  const modelNames = [];
2549
2726
  const modelFields = /* @__PURE__ */ new Map();
@@ -2557,7 +2734,8 @@ async function generate(args) {
2557
2734
  });
2558
2735
  const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf));
2559
2736
  const removeTypes = /* @__PURE__ */ new Set();
2560
- const allModels = [...datamodel.models, ...datamodel.types ?? []];
2737
+ const datamodelTypes = datamodel.types ?? [];
2738
+ const allModels = [...datamodel.models, ...datamodelTypes];
2561
2739
  const dependencyGraph = buildDependencyGraph(allModels);
2562
2740
  const circularDependencies = detectCircularDependencies(dependencyGraph);
2563
2741
  const eventArguments = {
@@ -2589,7 +2767,7 @@ async function generate(args) {
2589
2767
  for (const model of datamodel.models) {
2590
2768
  await eventEmitter.emit("Model", model, eventArguments);
2591
2769
  }
2592
- for (const model of datamodel.types ?? []) {
2770
+ for (const model of datamodelTypes) {
2593
2771
  await eventEmitter.emit("Model", model, eventArguments);
2594
2772
  }
2595
2773
  const { enumTypes, inputObjectTypes, outputObjectTypes } = schema;
@@ -2634,28 +2812,46 @@ async function generate(args) {
2634
2812
  await eventEmitter.emit("BeforeGenerateFiles", eventArguments);
2635
2813
  await eventEmitter.emit("GenerateFiles", eventArguments);
2636
2814
  await eventEmitter.emit("End", eventArguments);
2637
- for (const name of Object.keys(eventEmitter._events)) {
2815
+ for (const name of Object.keys(
2816
+ eventEmitter._events
2817
+ )) {
2638
2818
  eventEmitter.off(name);
2639
2819
  }
2640
2820
  }
2641
2821
 
2642
2822
  // 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);
2823
+ var createRequireTyped2 = createRequire;
2824
+ var requireCjs2 = createRequireTyped2(String(import.meta.url));
2825
+ var gracefulFsRaw = requireCjs2("graceful-fs");
2826
+ var gracefulFs = gracefulFsRaw;
2827
+ var nodeFsRaw = requireCjs2("fs");
2828
+ var nodeFs = nodeFsRaw;
2829
+ gracefulFs.gracefulify(nodeFs);
2830
+ var globalConsole2 = globalThis.console;
2831
+ var logError = (msg) => {
2832
+ globalConsole2.log(msg);
2833
+ };
2834
+ var processTyped = process;
2835
+ processTyped.on("unhandledRejection", (reason) => {
2836
+ logError(`nestjs-prisma-graphql: unhandled rejection: ${String(reason)}`);
2647
2837
  if (reason instanceof Error && typeof reason.stack === "string") {
2648
- console.log(reason.stack);
2838
+ logError(reason.stack);
2649
2839
  }
2650
2840
  });
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);
2841
+ processTyped.on("uncaughtException", (error) => {
2842
+ const err = error;
2843
+ logError(`nestjs-prisma-graphql: uncaught exception: ${err.message}`);
2844
+ if (typeof err.stack === "string") {
2845
+ logError(err.stack);
2655
2846
  }
2656
2847
  });
2657
2848
  var { generatorHandler } = generatorHelper;
2658
- function isGeneratorDisabled(options, env = process.env) {
2849
+ var getProcessEnv = () => {
2850
+ const globalProcess = process;
2851
+ const processLike = globalProcess;
2852
+ return processLike.env;
2853
+ };
2854
+ function isGeneratorDisabled(options, env = getProcessEnv()) {
2659
2855
  const envVarsToCheck = [
2660
2856
  "DISABLE_NESTJS_PRISMA_GRAPHQL",
2661
2857
  "CI_SKIP_PRISMA_GRAPHQL",
@@ -2676,8 +2872,12 @@ function isGeneratorDisabled(options, env = process.env) {
2676
2872
  }
2677
2873
  function countFilesRecursive(dir) {
2678
2874
  let count = 0;
2679
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
2680
- if (entry.isDirectory()) {
2875
+ const readDirSyncTyped = readdirSync;
2876
+ const rawEntries = readDirSyncTyped(dir, { withFileTypes: true });
2877
+ const entries = rawEntries;
2878
+ for (const entry of entries) {
2879
+ const isDir = typeof entry.isDirectory === "function" ? entry.isDirectory() : false;
2880
+ if (isDir) {
2681
2881
  count += countFilesRecursive(`${dir}/${entry.name}`);
2682
2882
  } else {
2683
2883
  count++;
@@ -2685,20 +2885,31 @@ function countFilesRecursive(dir) {
2685
2885
  }
2686
2886
  return count;
2687
2887
  }
2888
+ var globalConsole22 = globalThis.console;
2889
+ var log2 = (msg) => {
2890
+ globalConsole22.log(msg);
2891
+ };
2688
2892
  generatorHandler({
2689
2893
  async onGenerate(options) {
2690
2894
  if (isGeneratorDisabled(options)) {
2691
- console.log(
2895
+ log2(
2692
2896
  "nestjs-prisma-graphql: generation skipped (disabled via environment variable or config)"
2693
2897
  );
2694
2898
  return;
2695
2899
  }
2696
2900
  const outputPath = options.generator.output?.value ?? "<unknown>";
2697
2901
  const startTime = Date.now();
2698
- console.log(
2902
+ const archTyped = arch;
2903
+ const platformTyped = platform;
2904
+ const archValue = String(archTyped());
2905
+ const platformValue = String(platformTyped());
2906
+ const globalProcess2Raw = process;
2907
+ const processWithVersion = globalProcess2Raw;
2908
+ const nodeVersion = processWithVersion.version;
2909
+ log2(
2699
2910
  [
2700
2911
  "nestjs-prisma-graphql: starting generation",
2701
- `(arch=${arch()}, platform=${platform()}, node=${process.version}, output=${outputPath})`
2912
+ `(arch=${archValue}, platform=${platformValue}, node=${nodeVersion}, output=${outputPath})`
2702
2913
  ].join(" ")
2703
2914
  );
2704
2915
  try {
@@ -2707,30 +2918,30 @@ generatorHandler({
2707
2918
  const elapsed2 = Date.now() - startTime;
2708
2919
  const message = error instanceof Error ? error.message : String(error);
2709
2920
  const stack = error instanceof Error ? error.stack : void 0;
2710
- console.log(
2921
+ log2(
2711
2922
  `nestjs-prisma-graphql: generation FAILED after ${String(elapsed2)}ms: ${message}`
2712
2923
  );
2713
2924
  if (typeof stack === "string") {
2714
- console.log(stack);
2925
+ log2(stack);
2715
2926
  }
2716
2927
  throw error;
2717
2928
  }
2718
2929
  const elapsed = Date.now() - startTime;
2719
- if (typeof outputPath === "string" && outputPath !== "<unknown>" && existsSync(outputPath)) {
2930
+ const existsSyncTyped2 = existsSync;
2931
+ const pathExists = typeof outputPath === "string" && outputPath !== "<unknown>" && existsSyncTyped2(outputPath);
2932
+ if (pathExists) {
2720
2933
  const fileCount = countFilesRecursive(outputPath);
2721
- console.log(
2722
- `nestjs-prisma-graphql: generated ${String(fileCount)} files in ${String(
2723
- elapsed
2724
- )}ms`
2934
+ log2(
2935
+ `nestjs-prisma-graphql: generated ${String(fileCount)} files in ${String(elapsed)}ms`
2725
2936
  );
2726
2937
  if (fileCount === 0) {
2727
2938
  const msg = "nestjs-prisma-graphql: generation produced 0 files \u2014 this likely indicates a silent failure";
2728
- console.log(msg);
2939
+ log2(msg);
2729
2940
  throw new Error(msg);
2730
2941
  }
2731
2942
  } else {
2732
2943
  const msg = `nestjs-prisma-graphql: output directory not found after generation: ${outputPath}`;
2733
- console.log(msg);
2944
+ log2(msg);
2734
2945
  throw new Error(msg);
2735
2946
  }
2736
2947
  },