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