@pegasusheavy/nestjs-prisma-graphql 1.2.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/dist/generate.d.ts +41 -40
- package/dist/generate.js +724 -542
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +1 -17
- package/dist/index.js +774 -561
- package/dist/index.js.map +1 -1
- package/package.json +33 -33
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))
|
|
34
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
|
|
88
|
+
classDecoratorName: "ArgsType",
|
|
81
89
|
fileType: "args",
|
|
82
|
-
|
|
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 =
|
|
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
|
-
|
|
207
|
-
|
|
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
|
-
|
|
222
|
+
classDecoratorName: "InputType",
|
|
215
223
|
fileType: "input",
|
|
216
|
-
|
|
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 {
|
|
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 }]
|
|
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 {
|
|
255
|
-
let name = args
|
|
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
|
-
|
|
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 (
|
|
277
|
-
|
|
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
|
|
379
|
-
|
|
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
|
-
|
|
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
|
-
|
|
423
|
-
|
|
522
|
+
let fromPath = from;
|
|
523
|
+
let toPath = to;
|
|
524
|
+
if (!fromPath.startsWith("/")) {
|
|
525
|
+
fromPath = `/${fromPath}`;
|
|
424
526
|
}
|
|
425
|
-
if (!
|
|
426
|
-
|
|
527
|
+
if (!toPath.startsWith("/")) {
|
|
528
|
+
toPath = `/${toPath}`;
|
|
427
529
|
}
|
|
428
|
-
let result = getRelativePath(
|
|
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(
|
|
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(
|
|
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) =>
|
|
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
|
-
|
|
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(", ")
|
|
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 =
|
|
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 {
|
|
612
|
-
return name
|
|
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
|
-
|
|
625
|
-
hasQuestionToken,
|
|
626
|
-
hasExclamationToken
|
|
726
|
+
propertyType
|
|
627
727
|
} = args;
|
|
628
|
-
const
|
|
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:
|
|
751
|
+
inputType: inputTypeArg,
|
|
653
752
|
models,
|
|
654
753
|
output,
|
|
655
754
|
removeTypes,
|
|
656
755
|
typeNames
|
|
657
756
|
} = args;
|
|
658
|
-
typeNames.add(
|
|
757
|
+
typeNames.add(inputTypeArg.name);
|
|
659
758
|
const importDeclarations = new ImportDeclarationMap();
|
|
660
759
|
const sourceFile = getSourceFile({
|
|
661
|
-
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
|
-
|
|
671
|
-
|
|
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(
|
|
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
|
-
|
|
683
|
-
|
|
781
|
+
moduleSpecifier,
|
|
782
|
+
namedImports: [{ name: "Field" }]
|
|
684
783
|
}).set(classDecoratorName, {
|
|
685
|
-
|
|
686
|
-
|
|
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) =>
|
|
796
|
+
(x) => inputTypeArg.name.includes(x.typeName)
|
|
698
797
|
);
|
|
699
|
-
const isWhereUnique = isWhereUniqueInputType(
|
|
700
|
-
for (const field of
|
|
701
|
-
field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(
|
|
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,52 +806,56 @@ 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 =
|
|
809
|
+
const typeName = type;
|
|
711
810
|
const settings = modelFieldSettings?.get(name);
|
|
712
811
|
const propertySettings = settings?.getPropertyType({
|
|
713
|
-
|
|
714
|
-
|
|
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 ??
|
|
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
|
-
|
|
735
|
-
|
|
831
|
+
isList,
|
|
832
|
+
isNullable: !isRequired,
|
|
833
|
+
name,
|
|
834
|
+
propertyType
|
|
736
835
|
});
|
|
737
|
-
classStructure.properties
|
|
836
|
+
if (classStructure.properties) {
|
|
837
|
+
classStructure.properties.push(property);
|
|
838
|
+
}
|
|
738
839
|
if (propertySettings) {
|
|
739
840
|
importDeclarations.create({ ...propertySettings });
|
|
740
|
-
} else if (propertyType.some(
|
|
841
|
+
} else if (propertyType.some(
|
|
842
|
+
(p) => typeof p === "string" && p.includes("Prisma.Decimal")
|
|
843
|
+
)) {
|
|
741
844
|
importDeclarations.add("Prisma", config.prismaClientImport);
|
|
742
|
-
} else if (propertyType.some((p) => p.startsWith("Prisma."))) {
|
|
845
|
+
} else if (propertyType.some((p) => typeof p === "string" && p.startsWith("Prisma."))) {
|
|
743
846
|
importDeclarations.add("Prisma", config.prismaClientImport);
|
|
744
847
|
}
|
|
745
848
|
let graphqlType;
|
|
746
849
|
let useGetType = false;
|
|
747
850
|
const shouldHideField = settings?.shouldHideField({
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
})
|
|
751
|
-
(d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(
|
|
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)
|
|
752
855
|
);
|
|
753
856
|
const fieldType = settings?.getFieldType({
|
|
754
|
-
|
|
755
|
-
|
|
857
|
+
input: true,
|
|
858
|
+
name: inputTypeArg.name
|
|
756
859
|
});
|
|
757
860
|
if (fieldType && isCustomsApplicable && !shouldHideField) {
|
|
758
861
|
graphqlType = fieldType.name;
|
|
@@ -760,29 +863,28 @@ function inputType(args) {
|
|
|
760
863
|
} else {
|
|
761
864
|
const graphqlImport = getGraphqlImport({
|
|
762
865
|
config,
|
|
763
|
-
|
|
866
|
+
getSourceFile,
|
|
764
867
|
location,
|
|
765
|
-
|
|
766
|
-
|
|
868
|
+
sourceFile,
|
|
869
|
+
typeName
|
|
767
870
|
});
|
|
768
871
|
graphqlType = graphqlImport.name;
|
|
769
|
-
let referenceName = propertyType[0];
|
|
770
872
|
if (location === "enumTypes") {
|
|
771
|
-
const parts =
|
|
772
|
-
|
|
873
|
+
const parts = String(propertyType[0]).split(" ");
|
|
874
|
+
parts.at(-1);
|
|
773
875
|
}
|
|
774
876
|
const shouldUseLazyType = config.esmCompatible && location === "inputObjectTypes";
|
|
775
|
-
if (graphqlImport.name ===
|
|
877
|
+
if (graphqlImport.name === inputTypeArg.name && shouldUseLazyType) {
|
|
776
878
|
lazyTypes.add(graphqlImport.name);
|
|
777
879
|
useGetType = true;
|
|
778
|
-
} else if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !==
|
|
880
|
+
} else if (graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && !importDeclarations.has(graphqlImport.name) && graphqlImport.name !== inputTypeArg.name) {
|
|
779
881
|
if (shouldUseLazyType) {
|
|
780
882
|
importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
|
|
781
883
|
lazyTypes.add(graphqlImport.name);
|
|
782
884
|
} else {
|
|
783
885
|
importDeclarations.set(graphqlImport.name, {
|
|
784
|
-
|
|
785
|
-
|
|
886
|
+
moduleSpecifier: graphqlImport.specifier,
|
|
887
|
+
namedImports: [{ name: graphqlImport.name }]
|
|
786
888
|
});
|
|
787
889
|
}
|
|
788
890
|
}
|
|
@@ -790,10 +892,13 @@ function inputType(args) {
|
|
|
790
892
|
useGetType = true;
|
|
791
893
|
}
|
|
792
894
|
}
|
|
793
|
-
ok(
|
|
895
|
+
ok(
|
|
896
|
+
property.decorators !== void 0 && property.decorators !== null,
|
|
897
|
+
"property.decorators is undefined"
|
|
898
|
+
);
|
|
794
899
|
if (shouldHideField) {
|
|
795
900
|
importDeclarations.add("HideField", moduleSpecifier);
|
|
796
|
-
property.decorators.push({ name: "HideField"
|
|
901
|
+
property.decorators.push({ arguments: [], name: "HideField" });
|
|
797
902
|
} else {
|
|
798
903
|
let typeExpression;
|
|
799
904
|
if (useGetType) {
|
|
@@ -802,14 +907,14 @@ function inputType(args) {
|
|
|
802
907
|
typeExpression = isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`;
|
|
803
908
|
}
|
|
804
909
|
property.decorators.push({
|
|
805
|
-
name: "Field",
|
|
806
910
|
arguments: [
|
|
807
911
|
typeExpression,
|
|
808
912
|
JSON52.stringify({
|
|
809
913
|
...settings?.fieldArguments(),
|
|
810
914
|
nullable: !isRequired
|
|
811
915
|
})
|
|
812
|
-
]
|
|
916
|
+
],
|
|
917
|
+
name: "Field"
|
|
813
918
|
});
|
|
814
919
|
if (graphqlType === "GraphQLDecimal") {
|
|
815
920
|
const decimalHelpersPath = relativePath(
|
|
@@ -821,12 +926,12 @@ function inputType(args) {
|
|
|
821
926
|
importDeclarations.add("Type", "class-transformer");
|
|
822
927
|
property.decorators.push(
|
|
823
928
|
{
|
|
824
|
-
|
|
825
|
-
|
|
929
|
+
arguments: ["() => Object"],
|
|
930
|
+
name: "Type"
|
|
826
931
|
},
|
|
827
932
|
{
|
|
828
|
-
|
|
829
|
-
|
|
933
|
+
arguments: ["transformToDecimal"],
|
|
934
|
+
name: "Transform"
|
|
830
935
|
}
|
|
831
936
|
);
|
|
832
937
|
} else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
|
|
@@ -843,44 +948,47 @@ function inputType(args) {
|
|
|
843
948
|
"updateMany",
|
|
844
949
|
"upsert",
|
|
845
950
|
"where"
|
|
846
|
-
].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type)
|
|
951
|
+
].includes(name) || classTransformerTypeModels.has(getModelName2(graphqlType) ?? "") || modelField?.kind === "object" && models.get(modelField.type)?.fields.some(
|
|
847
952
|
(f) => f.kind === "object" && classTransformerTypeModels.has(f.type)
|
|
848
|
-
))) {
|
|
953
|
+
) === true)) {
|
|
849
954
|
importDeclarations.add("Type", "class-transformer");
|
|
850
955
|
if (useGetType) {
|
|
851
956
|
property.decorators.push({
|
|
852
|
-
|
|
853
|
-
|
|
957
|
+
arguments: [`getType('${graphqlType}')`],
|
|
958
|
+
name: "Type"
|
|
854
959
|
});
|
|
855
960
|
} else {
|
|
856
|
-
property.decorators.push({
|
|
961
|
+
property.decorators.push({ arguments: [`() => ${graphqlType}`], name: "Type" });
|
|
857
962
|
}
|
|
858
963
|
}
|
|
859
964
|
if (isCustomsApplicable) {
|
|
860
965
|
for (const options of settings ?? []) {
|
|
861
966
|
if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
|
|
862
967
|
property.decorators.push({
|
|
863
|
-
|
|
864
|
-
|
|
968
|
+
arguments: options.arguments,
|
|
969
|
+
name: options.name
|
|
865
970
|
});
|
|
866
|
-
ok(
|
|
971
|
+
ok(
|
|
972
|
+
options.from !== void 0 && options.from !== null && options.from !== "",
|
|
973
|
+
"Missed 'from' part in configuration or field setting"
|
|
974
|
+
);
|
|
867
975
|
importDeclarations.create(options);
|
|
868
976
|
}
|
|
869
977
|
}
|
|
870
978
|
}
|
|
871
979
|
for (const decorate of config.decorate) {
|
|
872
|
-
if (decorate.isMatchField(name) && decorate.isMatchType(
|
|
980
|
+
if (decorate.isMatchField(name) && decorate.isMatchType(inputTypeArg.name)) {
|
|
873
981
|
property.decorators.push({
|
|
874
|
-
|
|
875
|
-
|
|
982
|
+
arguments: decorate.arguments?.map((x) => pupa(x, { propertyType })),
|
|
983
|
+
name: decorate.name
|
|
876
984
|
});
|
|
877
985
|
importDeclarations.create(decorate);
|
|
878
986
|
}
|
|
879
987
|
}
|
|
880
988
|
}
|
|
881
989
|
eventEmitter.emitSync("ClassProperty", property, {
|
|
882
|
-
location,
|
|
883
990
|
isList,
|
|
991
|
+
location,
|
|
884
992
|
propertyType
|
|
885
993
|
});
|
|
886
994
|
}
|
|
@@ -890,7 +998,7 @@ function inputType(args) {
|
|
|
890
998
|
];
|
|
891
999
|
if (config.esmCompatible) {
|
|
892
1000
|
statements.push(`
|
|
893
|
-
registerType('${
|
|
1001
|
+
registerType('${inputTypeArg.name}', ${inputTypeArg.name});`);
|
|
894
1002
|
}
|
|
895
1003
|
sourceFile.set({
|
|
896
1004
|
statements
|
|
@@ -898,8 +1006,8 @@ registerType('${inputType2.name}', ${inputType2.name});`);
|
|
|
898
1006
|
}
|
|
899
1007
|
var ObjectSettings = class extends Array {
|
|
900
1008
|
shouldHideField({
|
|
901
|
-
name,
|
|
902
1009
|
input = false,
|
|
1010
|
+
name,
|
|
903
1011
|
output = false
|
|
904
1012
|
}) {
|
|
905
1013
|
const hideField = this.find((s) => s.name === "HideField");
|
|
@@ -908,8 +1016,8 @@ var ObjectSettings = class extends Array {
|
|
|
908
1016
|
);
|
|
909
1017
|
}
|
|
910
1018
|
getFieldType({
|
|
911
|
-
name,
|
|
912
1019
|
input,
|
|
1020
|
+
name,
|
|
913
1021
|
output
|
|
914
1022
|
}) {
|
|
915
1023
|
const fieldType = this.find((s) => s.kind === "FieldType");
|
|
@@ -928,8 +1036,8 @@ var ObjectSettings = class extends Array {
|
|
|
928
1036
|
return fieldType;
|
|
929
1037
|
}
|
|
930
1038
|
getPropertyType({
|
|
931
|
-
name,
|
|
932
1039
|
input,
|
|
1040
|
+
name,
|
|
933
1041
|
output
|
|
934
1042
|
}) {
|
|
935
1043
|
const propertyType = this.find((s) => s.kind === "PropertyType");
|
|
@@ -952,19 +1060,20 @@ var ObjectSettings = class extends Array {
|
|
|
952
1060
|
const resultArguments = [objectTypeOptions];
|
|
953
1061
|
const objectType = this.find((s) => s.kind === "ObjectType");
|
|
954
1062
|
if (objectType && isObject(objectType.arguments)) {
|
|
955
|
-
const name = objectType.arguments
|
|
1063
|
+
const { name } = objectType.arguments;
|
|
956
1064
|
merge(objectTypeOptions, omit(objectType.arguments, "name"));
|
|
957
|
-
if (name) {
|
|
1065
|
+
if (name !== null && name !== void 0 && name !== "") {
|
|
958
1066
|
resultArguments.unshift(name);
|
|
959
1067
|
}
|
|
960
1068
|
}
|
|
961
1069
|
return resultArguments.map((x) => JSON52.stringify(x));
|
|
962
1070
|
}
|
|
963
1071
|
fieldArguments() {
|
|
964
|
-
const
|
|
965
|
-
if (
|
|
966
|
-
return
|
|
1072
|
+
const fieldItem = this.find((item) => item.kind === "Field");
|
|
1073
|
+
if (fieldItem) {
|
|
1074
|
+
return fieldItem.arguments;
|
|
967
1075
|
}
|
|
1076
|
+
return void 0;
|
|
968
1077
|
}
|
|
969
1078
|
};
|
|
970
1079
|
function createObjectSettings(args) {
|
|
@@ -974,18 +1083,23 @@ function createObjectSettings(args) {
|
|
|
974
1083
|
const documentationLines = [];
|
|
975
1084
|
let fieldElement = result.find((item) => item.kind === "Field");
|
|
976
1085
|
if (!fieldElement) {
|
|
977
|
-
|
|
978
|
-
|
|
1086
|
+
const newFieldElement = {
|
|
1087
|
+
arguments: {},
|
|
1088
|
+
from: "",
|
|
1089
|
+
input: false,
|
|
979
1090
|
kind: "Field",
|
|
980
|
-
|
|
1091
|
+
model: false,
|
|
1092
|
+
name: "",
|
|
1093
|
+
output: false
|
|
981
1094
|
};
|
|
1095
|
+
fieldElement = newFieldElement;
|
|
982
1096
|
}
|
|
983
1097
|
for (const line of textLines) {
|
|
984
1098
|
const match = /^@(?<name>\w+(\.(\w+))?)\((?<args>.*)\)/.exec(line);
|
|
985
|
-
const {
|
|
986
|
-
line,
|
|
1099
|
+
const { documentLine, element } = createSettingElement({
|
|
987
1100
|
config,
|
|
988
1101
|
fieldElement,
|
|
1102
|
+
line,
|
|
989
1103
|
match
|
|
990
1104
|
});
|
|
991
1105
|
if (element) {
|
|
@@ -996,14 +1110,14 @@ function createObjectSettings(args) {
|
|
|
996
1110
|
}
|
|
997
1111
|
}
|
|
998
1112
|
return {
|
|
999
|
-
|
|
1000
|
-
|
|
1113
|
+
documentation: documentationLines.filter(Boolean).join("\n") || void 0,
|
|
1114
|
+
settings: result
|
|
1001
1115
|
};
|
|
1002
1116
|
}
|
|
1003
1117
|
function createSettingElement({
|
|
1004
|
-
line,
|
|
1005
1118
|
config,
|
|
1006
1119
|
fieldElement,
|
|
1120
|
+
line,
|
|
1007
1121
|
match
|
|
1008
1122
|
}) {
|
|
1009
1123
|
const result = {
|
|
@@ -1011,75 +1125,95 @@ function createSettingElement({
|
|
|
1011
1125
|
element: void 0
|
|
1012
1126
|
};
|
|
1013
1127
|
if (line.startsWith("@deprecated")) {
|
|
1014
|
-
|
|
1015
|
-
|
|
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;
|
|
1016
1137
|
return result;
|
|
1017
1138
|
}
|
|
1018
1139
|
if (line.startsWith("@complexity")) {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
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;
|
|
1023
1154
|
return result;
|
|
1024
1155
|
}
|
|
1025
1156
|
const name = match?.groups?.name;
|
|
1026
|
-
if (!(match && name)) {
|
|
1157
|
+
if (!(match && name !== void 0 && name !== "")) {
|
|
1027
1158
|
result.documentLine = line;
|
|
1028
1159
|
return result;
|
|
1029
1160
|
}
|
|
1030
1161
|
const element = {
|
|
1031
|
-
kind: "Decorator",
|
|
1032
|
-
name: "",
|
|
1033
1162
|
arguments: [],
|
|
1163
|
+
from: "",
|
|
1034
1164
|
input: false,
|
|
1035
|
-
|
|
1165
|
+
kind: "Decorator",
|
|
1036
1166
|
model: false,
|
|
1037
|
-
|
|
1167
|
+
name: "",
|
|
1168
|
+
output: false
|
|
1038
1169
|
};
|
|
1039
1170
|
result.element = element;
|
|
1040
1171
|
if (name === "TypeGraphQL.omit" || name === "HideField") {
|
|
1041
1172
|
Object.assign(element, hideFieldDecorator(match));
|
|
1042
1173
|
return result;
|
|
1043
1174
|
}
|
|
1044
|
-
if (["FieldType", "PropertyType"].includes(name) && match.groups?.args) {
|
|
1175
|
+
if (["FieldType", "PropertyType"].includes(name) && match.groups?.args !== void 0 && match.groups.args !== "") {
|
|
1045
1176
|
const options2 = customType(match.groups.args);
|
|
1046
|
-
|
|
1177
|
+
const namespaceConfig2 = options2.namespace !== void 0 && options2.namespace !== "" ? config.fields[options2.namespace] : void 0;
|
|
1178
|
+
merge(element, namespaceConfig2, options2, {
|
|
1047
1179
|
kind: name
|
|
1048
1180
|
});
|
|
1049
1181
|
return result;
|
|
1050
1182
|
}
|
|
1051
|
-
if (name === "ObjectType" && match.groups?.args) {
|
|
1183
|
+
if (name === "ObjectType" && match.groups?.args !== void 0 && match.groups.args !== "") {
|
|
1052
1184
|
element.kind = "ObjectType";
|
|
1053
1185
|
const options2 = customType(match.groups.args);
|
|
1054
|
-
if (typeof options2[0] === "string" && options2[0]) {
|
|
1186
|
+
if (typeof options2[0] === "string" && options2[0] !== "") {
|
|
1055
1187
|
options2.name = options2[0];
|
|
1056
1188
|
}
|
|
1057
1189
|
if (isObject(options2[1])) {
|
|
1058
1190
|
merge(options2, options2[1]);
|
|
1059
1191
|
}
|
|
1060
1192
|
element.arguments = {
|
|
1061
|
-
|
|
1062
|
-
|
|
1193
|
+
isAbstract: options2.isAbstract,
|
|
1194
|
+
name: options2.name
|
|
1063
1195
|
};
|
|
1064
1196
|
return result;
|
|
1065
1197
|
}
|
|
1066
|
-
if (name === "Directive" && match.groups?.args) {
|
|
1198
|
+
if (name === "Directive" && match.groups?.args !== void 0 && match.groups.args !== "") {
|
|
1067
1199
|
const options2 = customType(match.groups.args);
|
|
1068
|
-
merge(element, {
|
|
1069
|
-
|
|
1070
|
-
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,
|
|
1071
1202
|
kind: "Decorator",
|
|
1072
|
-
|
|
1203
|
+
name,
|
|
1204
|
+
namespace: false
|
|
1073
1205
|
});
|
|
1074
1206
|
return result;
|
|
1075
1207
|
}
|
|
1076
1208
|
const namespace = getNamespace(name);
|
|
1077
1209
|
element.namespaceImport = namespace;
|
|
1210
|
+
const args = match.groups?.args ?? "";
|
|
1078
1211
|
const options = {
|
|
1079
|
-
|
|
1080
|
-
|
|
1212
|
+
arguments: args.split(",").map((s) => trim(s)).filter(Boolean),
|
|
1213
|
+
name
|
|
1081
1214
|
};
|
|
1082
|
-
|
|
1215
|
+
const namespaceConfig = namespace !== void 0 && namespace !== "" ? config.fields[namespace] : void 0;
|
|
1216
|
+
merge(element, namespaceConfig, options);
|
|
1083
1217
|
return result;
|
|
1084
1218
|
}
|
|
1085
1219
|
function customType(args) {
|
|
@@ -1091,7 +1225,8 @@ function customType(args) {
|
|
|
1091
1225
|
Object.assign(result, options);
|
|
1092
1226
|
const namespace = getNamespace(options.name);
|
|
1093
1227
|
result.namespace = namespace;
|
|
1094
|
-
|
|
1228
|
+
const optionsWithName = options;
|
|
1229
|
+
if (optionsWithName.name !== void 0 && optionsWithName.name !== "" && optionsWithName.name.includes(".")) {
|
|
1095
1230
|
result.namespaceImport = namespace;
|
|
1096
1231
|
}
|
|
1097
1232
|
if (typeof options.match === "string" || Array.isArray(options.match)) {
|
|
@@ -1101,29 +1236,30 @@ function customType(args) {
|
|
|
1101
1236
|
}
|
|
1102
1237
|
function hideFieldDecorator(match) {
|
|
1103
1238
|
const result = {
|
|
1104
|
-
name: "HideField",
|
|
1105
1239
|
arguments: [],
|
|
1106
|
-
from: "@nestjs/graphql",
|
|
1107
1240
|
defaultImport: void 0,
|
|
1108
|
-
|
|
1109
|
-
match: void 0
|
|
1241
|
+
from: "@nestjs/graphql",
|
|
1242
|
+
match: void 0,
|
|
1243
|
+
name: "HideField",
|
|
1244
|
+
namespaceImport: void 0
|
|
1110
1245
|
};
|
|
1111
|
-
|
|
1246
|
+
const args = match.groups?.args;
|
|
1247
|
+
if (args === void 0 || args === "") {
|
|
1112
1248
|
result.output = true;
|
|
1113
1249
|
return result;
|
|
1114
1250
|
}
|
|
1115
|
-
if (
|
|
1116
|
-
const options = parseArgs(
|
|
1251
|
+
if (args.includes("{") && args.includes("}")) {
|
|
1252
|
+
const options = parseArgs(args);
|
|
1117
1253
|
result.output = Boolean(options.output);
|
|
1118
1254
|
result.input = Boolean(options.input);
|
|
1119
1255
|
if (typeof options.match === "string" || Array.isArray(options.match)) {
|
|
1120
1256
|
result.match = outmatch2(options.match, { separator: false });
|
|
1121
1257
|
}
|
|
1122
1258
|
} else {
|
|
1123
|
-
if (/output:\s*true/.test(
|
|
1259
|
+
if (/output:\s*true/.test(args)) {
|
|
1124
1260
|
result.output = true;
|
|
1125
1261
|
}
|
|
1126
|
-
if (/input:\s*true/.test(
|
|
1262
|
+
if (/input:\s*true/.test(args)) {
|
|
1127
1263
|
result.input = true;
|
|
1128
1264
|
}
|
|
1129
1265
|
}
|
|
@@ -1141,12 +1277,22 @@ function parseArgs(string) {
|
|
|
1141
1277
|
}
|
|
1142
1278
|
}
|
|
1143
1279
|
function getNamespace(name) {
|
|
1144
|
-
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 === "") {
|
|
1145
1288
|
return void 0;
|
|
1146
1289
|
}
|
|
1147
|
-
let result = String(name);
|
|
1148
1290
|
if (result.includes(".")) {
|
|
1149
|
-
|
|
1291
|
+
const parts = result.split(".");
|
|
1292
|
+
result = parts[0] ?? "";
|
|
1293
|
+
}
|
|
1294
|
+
if (result === "") {
|
|
1295
|
+
return void 0;
|
|
1150
1296
|
}
|
|
1151
1297
|
return result;
|
|
1152
1298
|
}
|
|
@@ -1154,12 +1300,12 @@ function getNamespace(name) {
|
|
|
1154
1300
|
// src/handlers/model-data.ts
|
|
1155
1301
|
function modelData(model, args) {
|
|
1156
1302
|
const {
|
|
1303
|
+
classTransformerTypeModels,
|
|
1157
1304
|
config,
|
|
1158
|
-
modelNames,
|
|
1159
|
-
models,
|
|
1160
|
-
modelFields,
|
|
1161
1305
|
fieldSettings,
|
|
1162
|
-
|
|
1306
|
+
modelFields,
|
|
1307
|
+
modelNames,
|
|
1308
|
+
models
|
|
1163
1309
|
} = args;
|
|
1164
1310
|
modelNames.push(model.name);
|
|
1165
1311
|
models.set(model.name, model);
|
|
@@ -1168,10 +1314,10 @@ function modelData(model, args) {
|
|
|
1168
1314
|
const fieldSettingsValue = /* @__PURE__ */ new Map();
|
|
1169
1315
|
fieldSettings.set(model.name, fieldSettingsValue);
|
|
1170
1316
|
for (const field of model.fields) {
|
|
1171
|
-
if (field.documentation) {
|
|
1317
|
+
if (field.documentation !== null && field.documentation !== void 0 && field.documentation.length > 0) {
|
|
1172
1318
|
const { documentation, settings } = createObjectSettings({
|
|
1173
|
-
|
|
1174
|
-
|
|
1319
|
+
config,
|
|
1320
|
+
text: field.documentation
|
|
1175
1321
|
});
|
|
1176
1322
|
field.documentation = documentation;
|
|
1177
1323
|
fieldSettingsValue.set(field.name, settings);
|
|
@@ -1190,8 +1336,14 @@ function createComment(documentation, settings) {
|
|
|
1190
1336
|
for (const line of documentationLines) {
|
|
1191
1337
|
commentLines.push(` * ${line}`);
|
|
1192
1338
|
}
|
|
1193
|
-
const
|
|
1194
|
-
|
|
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) {
|
|
1195
1347
|
commentLines.push(` * @deprecated ${deprecationReason}`);
|
|
1196
1348
|
}
|
|
1197
1349
|
commentLines.push(" */\n");
|
|
@@ -1206,6 +1358,9 @@ function buildDependencyGraph(models) {
|
|
|
1206
1358
|
}
|
|
1207
1359
|
for (const model of models) {
|
|
1208
1360
|
const dependencies = graph.get(model.name);
|
|
1361
|
+
if (!dependencies) {
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1209
1364
|
for (const field of model.fields) {
|
|
1210
1365
|
if (field.kind === "object" && field.type !== model.name) {
|
|
1211
1366
|
if (graph.has(field.type)) {
|
|
@@ -1225,7 +1380,7 @@ function detectCircularDependencies(graph) {
|
|
|
1225
1380
|
visited.add(node);
|
|
1226
1381
|
recursionStack.add(node);
|
|
1227
1382
|
path.push(node);
|
|
1228
|
-
const dependencies = graph.get(node)
|
|
1383
|
+
const dependencies = graph.get(node) ?? /* @__PURE__ */ new Set();
|
|
1229
1384
|
for (const dep of dependencies) {
|
|
1230
1385
|
if (!visited.has(dep)) {
|
|
1231
1386
|
dfs(dep);
|
|
@@ -1275,7 +1430,9 @@ function modelOutputType(outputType2, args) {
|
|
|
1275
1430
|
models,
|
|
1276
1431
|
output
|
|
1277
1432
|
} = args;
|
|
1278
|
-
if (isManyAndReturnOutputType(outputType2.name))
|
|
1433
|
+
if (isManyAndReturnOutputType(outputType2.name)) {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1279
1436
|
const model = models.get(outputType2.name);
|
|
1280
1437
|
ok(model, `Cannot find model by name ${outputType2.name}`);
|
|
1281
1438
|
const sourceFile = getSourceFile({
|
|
@@ -1305,16 +1462,14 @@ function modelOutputType(outputType2, args) {
|
|
|
1305
1462
|
const decorator = classStructure.decorators.find((d) => d.name === "ObjectType");
|
|
1306
1463
|
ok(decorator, "ObjectType decorator not found");
|
|
1307
1464
|
let modelSettings;
|
|
1308
|
-
if (model.documentation) {
|
|
1465
|
+
if (model.documentation !== null && model.documentation !== void 0 && model.documentation.length > 0) {
|
|
1309
1466
|
const objectTypeOptions = {};
|
|
1310
1467
|
const { documentation, settings } = createObjectSettings({
|
|
1311
1468
|
config,
|
|
1312
1469
|
text: model.documentation
|
|
1313
1470
|
});
|
|
1314
|
-
if (documentation) {
|
|
1315
|
-
|
|
1316
|
-
classStructure.leadingTrivia = createComment(documentation);
|
|
1317
|
-
}
|
|
1471
|
+
if (documentation !== void 0 && documentation.length > 0) {
|
|
1472
|
+
classStructure.leadingTrivia ??= createComment(documentation);
|
|
1318
1473
|
objectTypeOptions.description = documentation;
|
|
1319
1474
|
}
|
|
1320
1475
|
decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
|
|
@@ -1332,10 +1487,12 @@ function modelOutputType(outputType2, args) {
|
|
|
1332
1487
|
importDeclarations.add("getType", typeRegistryPath);
|
|
1333
1488
|
}
|
|
1334
1489
|
for (const field of outputType2.fields) {
|
|
1335
|
-
if (config.omitModelsCount && field.name === "_count")
|
|
1490
|
+
if (config.omitModelsCount && field.name === "_count") {
|
|
1491
|
+
continue;
|
|
1492
|
+
}
|
|
1336
1493
|
let fileType = "model";
|
|
1337
1494
|
const { isList, location, namespace, type } = field.outputType;
|
|
1338
|
-
let outputTypeName =
|
|
1495
|
+
let outputTypeName = type;
|
|
1339
1496
|
if (namespace !== "model") {
|
|
1340
1497
|
fileType = "output";
|
|
1341
1498
|
outputTypeName = getOutputTypeName(outputTypeName);
|
|
@@ -1357,15 +1514,12 @@ function modelOutputType(outputType2, args) {
|
|
|
1357
1514
|
})
|
|
1358
1515
|
);
|
|
1359
1516
|
propertyType.splice(1, propertyType.length);
|
|
1360
|
-
if (field.isNullable && !isList) {
|
|
1517
|
+
if (field.isNullable === true && !isList) {
|
|
1361
1518
|
propertyType.push("null");
|
|
1362
1519
|
}
|
|
1363
1520
|
let graphqlType;
|
|
1364
1521
|
let useGetType = false;
|
|
1365
|
-
if (fieldType) {
|
|
1366
|
-
graphqlType = fieldType.name;
|
|
1367
|
-
importDeclarations.create({ ...fieldType });
|
|
1368
|
-
} else {
|
|
1522
|
+
if (fieldType === void 0) {
|
|
1369
1523
|
const graphqlImport = getGraphqlImport({
|
|
1370
1524
|
config,
|
|
1371
1525
|
fileType,
|
|
@@ -1377,7 +1531,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1377
1531
|
typeName: outputTypeName
|
|
1378
1532
|
});
|
|
1379
1533
|
graphqlType = graphqlImport.name;
|
|
1380
|
-
if (graphqlImport.name !== outputType2.name && graphqlImport.specifier) {
|
|
1534
|
+
if (graphqlImport.name !== outputType2.name && graphqlImport.specifier !== null && graphqlImport.specifier !== void 0 && graphqlImport.specifier.length > 0) {
|
|
1381
1535
|
const isCircular = config.esmCompatible && location === "outputObjectTypes" && namespace === "model" && hasCircularDependency(circularDependencies, outputType2.name, outputTypeName);
|
|
1382
1536
|
if (isCircular) {
|
|
1383
1537
|
importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
|
|
@@ -1387,6 +1541,9 @@ function modelOutputType(outputType2, args) {
|
|
|
1387
1541
|
importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
|
|
1388
1542
|
}
|
|
1389
1543
|
}
|
|
1544
|
+
} else {
|
|
1545
|
+
graphqlType = fieldType.name;
|
|
1546
|
+
importDeclarations.create({ ...fieldType });
|
|
1390
1547
|
}
|
|
1391
1548
|
const property = propertyStructure({
|
|
1392
1549
|
hasExclamationToken: true,
|
|
@@ -1396,17 +1553,19 @@ function modelOutputType(outputType2, args) {
|
|
|
1396
1553
|
name: field.name,
|
|
1397
1554
|
propertyType
|
|
1398
1555
|
});
|
|
1399
|
-
if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
|
|
1556
|
+
if (typeof property.leadingTrivia === "string" && modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation.length > 0) {
|
|
1400
1557
|
property.leadingTrivia += createComment(modelField.documentation, settings);
|
|
1401
1558
|
}
|
|
1402
|
-
classStructure.properties
|
|
1403
|
-
|
|
1559
|
+
if (classStructure.properties !== void 0) {
|
|
1560
|
+
classStructure.properties.push(property);
|
|
1561
|
+
}
|
|
1562
|
+
if (propertySettings !== void 0) {
|
|
1404
1563
|
importDeclarations.create({ ...propertySettings });
|
|
1405
1564
|
} else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
|
|
1406
1565
|
importDeclarations.add("Prisma", config.prismaClientImport);
|
|
1407
1566
|
}
|
|
1408
|
-
ok(property.decorators, "property.decorators is undefined");
|
|
1409
|
-
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(
|
|
1410
1569
|
(d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
|
|
1411
1570
|
);
|
|
1412
1571
|
if (shouldHideField) {
|
|
@@ -1427,7 +1586,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1427
1586
|
defaultValue: ["number", "string", "boolean"].includes(
|
|
1428
1587
|
typeof modelField?.default
|
|
1429
1588
|
) ? modelField?.default : void 0,
|
|
1430
|
-
description: modelField?.documentation,
|
|
1589
|
+
description: modelField?.documentation !== null && modelField?.documentation !== void 0 && modelField.documentation !== "" ? modelField.documentation : void 0,
|
|
1431
1590
|
nullable: Boolean(field.isNullable)
|
|
1432
1591
|
})
|
|
1433
1592
|
],
|
|
@@ -1439,7 +1598,10 @@ function modelOutputType(outputType2, args) {
|
|
|
1439
1598
|
arguments: setting.arguments,
|
|
1440
1599
|
name: setting.name
|
|
1441
1600
|
});
|
|
1442
|
-
ok(
|
|
1601
|
+
ok(
|
|
1602
|
+
setting.from && setting.from.length > 0,
|
|
1603
|
+
"Missed 'from' part in configuration or field setting"
|
|
1604
|
+
);
|
|
1443
1605
|
importDeclarations.create(setting);
|
|
1444
1606
|
}
|
|
1445
1607
|
}
|
|
@@ -1507,13 +1669,14 @@ function noAtomicOperations(eventEmitter) {
|
|
|
1507
1669
|
eventEmitter.on("BeforeGenerateFiles", beforeGenerateFiles);
|
|
1508
1670
|
}
|
|
1509
1671
|
function beforeInputType2(args) {
|
|
1510
|
-
const {
|
|
1672
|
+
const { getModelName: getModelName2, inputType: inputType2 } = args;
|
|
1511
1673
|
for (const field of inputType2.fields) {
|
|
1512
1674
|
const fieldName = field.name;
|
|
1513
1675
|
field.inputTypes = field.inputTypes.filter((it) => {
|
|
1514
|
-
const inputTypeName =
|
|
1676
|
+
const inputTypeName = it.type;
|
|
1515
1677
|
const modelName = getModelName2(inputTypeName);
|
|
1516
|
-
|
|
1678
|
+
const isModelNameValid = modelName !== null && modelName !== void 0 && modelName.length > 0;
|
|
1679
|
+
if (isAtomicOperation(inputTypeName) || isModelNameValid && isListInput(inputTypeName, modelName, fieldName)) {
|
|
1517
1680
|
return false;
|
|
1518
1681
|
}
|
|
1519
1682
|
return true;
|
|
@@ -1524,7 +1687,8 @@ function beforeGenerateFiles(args) {
|
|
|
1524
1687
|
const { project } = args;
|
|
1525
1688
|
for (const sourceFile of project.getSourceFiles()) {
|
|
1526
1689
|
const className = sourceFile.getClass(() => true)?.getName();
|
|
1527
|
-
|
|
1690
|
+
const isClassNameValid = className !== void 0 && className !== null && className.length > 0;
|
|
1691
|
+
if (isClassNameValid && isAtomicOperation(className)) {
|
|
1528
1692
|
project.removeSourceFile(sourceFile);
|
|
1529
1693
|
}
|
|
1530
1694
|
}
|
|
@@ -1550,11 +1714,13 @@ function outputType(outputTypeArg, args) {
|
|
|
1550
1714
|
const { config, eventEmitter, fieldSettings, getModelName: getModelName2, getSourceFile, models } = args;
|
|
1551
1715
|
const importDeclarations = new ImportDeclarationMap();
|
|
1552
1716
|
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) &&
|
|
1556
|
-
const isCountOutput = model?.name && outputTypeArg.name === `${model.name}CountOutputType`;
|
|
1557
|
-
if (
|
|
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
|
+
}
|
|
1558
1724
|
outputTypeArg.name = getOutputTypeName(outputTypeArg.name);
|
|
1559
1725
|
if (isAggregateOutput) {
|
|
1560
1726
|
eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputTypeArg });
|
|
@@ -1579,8 +1745,15 @@ function outputType(outputTypeArg, args) {
|
|
|
1579
1745
|
importDeclarations.add("ObjectType", nestjsGraphql2);
|
|
1580
1746
|
for (const field of outputTypeArg.fields) {
|
|
1581
1747
|
const { isList, location, type } = field.outputType;
|
|
1582
|
-
const outputTypeName = getOutputTypeName(
|
|
1583
|
-
|
|
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
|
+
}
|
|
1584
1757
|
const propertySettings = settings?.getPropertyType({
|
|
1585
1758
|
name: outputTypeArg.name,
|
|
1586
1759
|
output: true
|
|
@@ -1601,7 +1774,7 @@ function outputType(outputTypeArg, args) {
|
|
|
1601
1774
|
propertyType
|
|
1602
1775
|
});
|
|
1603
1776
|
classStructure.properties?.push(property);
|
|
1604
|
-
if (propertySettings) {
|
|
1777
|
+
if (propertySettings !== void 0) {
|
|
1605
1778
|
importDeclarations.create({ ...propertySettings });
|
|
1606
1779
|
} else if (propertyType.some((p) => p.includes("Prisma.Decimal"))) {
|
|
1607
1780
|
importDeclarations.add("Prisma", config.prismaClientImport);
|
|
@@ -1610,14 +1783,14 @@ function outputType(outputTypeArg, args) {
|
|
|
1610
1783
|
const shouldHideField = settings?.shouldHideField({
|
|
1611
1784
|
name: outputTypeArg.name,
|
|
1612
1785
|
output: true
|
|
1613
|
-
}) || config.decorate.some(
|
|
1786
|
+
}) === true || config.decorate.some(
|
|
1614
1787
|
(d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
|
|
1615
1788
|
);
|
|
1616
1789
|
const fieldType = settings?.getFieldType({
|
|
1617
1790
|
name: outputTypeArg.name,
|
|
1618
1791
|
output: true
|
|
1619
1792
|
});
|
|
1620
|
-
if (fieldType && isCustomsApplicable && !shouldHideField) {
|
|
1793
|
+
if (fieldType !== void 0 && isCustomsApplicable && !shouldHideField) {
|
|
1621
1794
|
graphqlType = fieldType.name;
|
|
1622
1795
|
importDeclarations.create({ ...fieldType });
|
|
1623
1796
|
} else {
|
|
@@ -1632,14 +1805,14 @@ function outputType(outputTypeArg, args) {
|
|
|
1632
1805
|
});
|
|
1633
1806
|
const referenceName = location === "enumTypes" ? getEnumName(propertyType[0]) : propertyType[0];
|
|
1634
1807
|
graphqlType = graphqlImport.name;
|
|
1635
|
-
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)) {
|
|
1636
1809
|
importDeclarations.set(graphqlImport.name, {
|
|
1637
1810
|
moduleSpecifier: graphqlImport.specifier,
|
|
1638
1811
|
namedImports: [{ name: graphqlImport.name }]
|
|
1639
1812
|
});
|
|
1640
1813
|
}
|
|
1641
1814
|
}
|
|
1642
|
-
ok(property.decorators, "property.decorators is undefined");
|
|
1815
|
+
ok(property.decorators !== void 0, "property.decorators is undefined");
|
|
1643
1816
|
if (shouldHideField) {
|
|
1644
1817
|
importDeclarations.add("HideField", nestjsGraphql2);
|
|
1645
1818
|
property.decorators.push({ arguments: [], name: "HideField" });
|
|
@@ -1656,12 +1829,16 @@ function outputType(outputTypeArg, args) {
|
|
|
1656
1829
|
});
|
|
1657
1830
|
if (isCustomsApplicable) {
|
|
1658
1831
|
for (const options of settings ?? []) {
|
|
1659
|
-
|
|
1832
|
+
const shouldApplyDecorator = options.kind === "Decorator" && options.output && (options.match?.(field.name) ?? true);
|
|
1833
|
+
if (shouldApplyDecorator) {
|
|
1660
1834
|
property.decorators.push({
|
|
1661
1835
|
arguments: options.arguments,
|
|
1662
1836
|
name: options.name
|
|
1663
1837
|
});
|
|
1664
|
-
ok(
|
|
1838
|
+
ok(
|
|
1839
|
+
options.from !== null && options.from !== void 0 && options.from.length > 0,
|
|
1840
|
+
"Missed 'from' part in configuration or field setting"
|
|
1841
|
+
);
|
|
1665
1842
|
importDeclarations.create(options);
|
|
1666
1843
|
}
|
|
1667
1844
|
}
|
|
@@ -1677,11 +1854,15 @@ function outputType(outputTypeArg, args) {
|
|
|
1677
1854
|
statements: [...importDeclarations.toStatements(), classStructure]
|
|
1678
1855
|
});
|
|
1679
1856
|
}
|
|
1857
|
+
var rmdirTyped = rmdirSync$1;
|
|
1858
|
+
var rmdirSync = (path) => {
|
|
1859
|
+
rmdirTyped(path);
|
|
1860
|
+
};
|
|
1680
1861
|
function purgeOutput(emitter) {
|
|
1681
1862
|
emitter.on("Begin", begin);
|
|
1682
1863
|
emitter.on("End", end);
|
|
1683
1864
|
}
|
|
1684
|
-
function begin({
|
|
1865
|
+
function begin({ output, project }) {
|
|
1685
1866
|
const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
|
|
1686
1867
|
if (sourceFiles) {
|
|
1687
1868
|
for (const sourceFile of sourceFiles) {
|
|
@@ -1689,9 +1870,10 @@ function begin({ project, output }) {
|
|
|
1689
1870
|
}
|
|
1690
1871
|
}
|
|
1691
1872
|
}
|
|
1692
|
-
function end({
|
|
1873
|
+
function end({ output, project }) {
|
|
1693
1874
|
const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
|
|
1694
|
-
|
|
1875
|
+
const directoryList = directories ?? [];
|
|
1876
|
+
for (const directory of directoryList) {
|
|
1695
1877
|
try {
|
|
1696
1878
|
rmdirSync(directory);
|
|
1697
1879
|
} catch {
|
|
@@ -1709,7 +1891,7 @@ function reExport(emitter) {
|
|
|
1709
1891
|
emitter.on("BeforeGenerateFiles", beforeGenerateFiles2);
|
|
1710
1892
|
}
|
|
1711
1893
|
function beforeGenerateFiles2(args) {
|
|
1712
|
-
const {
|
|
1894
|
+
const { config, output, project } = args;
|
|
1713
1895
|
const rootDirectory = project.getDirectoryOrThrow(output);
|
|
1714
1896
|
if (["Directories" /* Directories */, "All" /* All */].includes(config.reExport)) {
|
|
1715
1897
|
const directories = [...rootDirectory.getDescendantDirectories()];
|
|
@@ -1756,7 +1938,9 @@ function beforeGenerateFiles2(args) {
|
|
|
1756
1938
|
const exportDeclarations = [];
|
|
1757
1939
|
const directories = rootDirectory.getDirectories();
|
|
1758
1940
|
for (const directory of directories) {
|
|
1759
|
-
if (directory.getBaseName() === "node_modules")
|
|
1941
|
+
if (directory.getBaseName() === "node_modules") {
|
|
1942
|
+
continue;
|
|
1943
|
+
}
|
|
1760
1944
|
const indexFile = directory.getSourceFile("index.ts");
|
|
1761
1945
|
if (indexFile) {
|
|
1762
1946
|
const dirName = directory.getBaseName();
|
|
@@ -1778,9 +1962,9 @@ function beforeGenerateFiles2(args) {
|
|
|
1778
1962
|
function getExportDeclaration2(directory, sourceFile) {
|
|
1779
1963
|
let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceFile);
|
|
1780
1964
|
if (!moduleSpecifier.endsWith(".js") && !moduleSpecifier.endsWith(".ts")) {
|
|
1781
|
-
moduleSpecifier
|
|
1965
|
+
moduleSpecifier += ".js";
|
|
1782
1966
|
} else if (moduleSpecifier.endsWith(".ts")) {
|
|
1783
|
-
moduleSpecifier = moduleSpecifier.slice(0, -3)
|
|
1967
|
+
moduleSpecifier = `${moduleSpecifier.slice(0, -3)}.js`;
|
|
1784
1968
|
}
|
|
1785
1969
|
return {
|
|
1786
1970
|
kind: StructureKind.ExportDeclaration,
|
|
@@ -1790,7 +1974,7 @@ function getExportDeclaration2(directory, sourceFile) {
|
|
|
1790
1974
|
function getNamespaceExportDeclaration(directory, sourceDirectory) {
|
|
1791
1975
|
let moduleSpecifier = directory.getRelativePathAsModuleSpecifierTo(sourceDirectory);
|
|
1792
1976
|
if (!moduleSpecifier.endsWith("/index.js")) {
|
|
1793
|
-
moduleSpecifier
|
|
1977
|
+
moduleSpecifier += "/index.js";
|
|
1794
1978
|
}
|
|
1795
1979
|
return {
|
|
1796
1980
|
kind: StructureKind.ExportDeclaration,
|
|
@@ -1798,74 +1982,16 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
|
|
|
1798
1982
|
};
|
|
1799
1983
|
}
|
|
1800
1984
|
|
|
1801
|
-
// src/handlers/
|
|
1802
|
-
function
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
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" }]
|
|
1985
|
+
// src/handlers/register-all-types.ts
|
|
1986
|
+
function generateRegisterAllTypes(args) {
|
|
1987
|
+
const { config, output, project } = args;
|
|
1988
|
+
if (!config.esmCompatible) {
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
|
|
1992
|
+
const sourceFile = rootDirectory.createSourceFile("register-all-types.ts", void 0, {
|
|
1993
|
+
overwrite: true
|
|
1830
1994
|
});
|
|
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
|
-
}
|
|
1858
|
-
function generateRegisterAllTypes(args) {
|
|
1859
|
-
const { config, output, project } = args;
|
|
1860
|
-
if (!config.esmCompatible) {
|
|
1861
|
-
return;
|
|
1862
|
-
}
|
|
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
|
-
);
|
|
1869
1995
|
const importPaths = [];
|
|
1870
1996
|
const typeNames = [];
|
|
1871
1997
|
const allSourceFiles = project.getSourceFiles(`${output}/**/*.ts`);
|
|
@@ -1875,7 +2001,7 @@ function generateRegisterAllTypes(args) {
|
|
|
1875
2001
|
continue;
|
|
1876
2002
|
}
|
|
1877
2003
|
const fileText = file.getText();
|
|
1878
|
-
const registerMatch =
|
|
2004
|
+
const registerMatch = /registerType\(['"]([^'"]+)['"]/.exec(fileText);
|
|
1879
2005
|
if (registerMatch) {
|
|
1880
2006
|
const relPath = relativePath(sourceFile.getFilePath(), filePath);
|
|
1881
2007
|
importPaths.push(relPath);
|
|
@@ -1929,6 +2055,76 @@ export type RegisteredTypeName = typeof registeredTypes[number];
|
|
|
1929
2055
|
sourceFile.addStatements(fileContent);
|
|
1930
2056
|
}
|
|
1931
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
|
+
|
|
1932
2128
|
// src/handlers/require-single-fields-in-whereunique-input.ts
|
|
1933
2129
|
function requireSingleFieldsInWhereUniqueInput(eventEmitter) {
|
|
1934
2130
|
eventEmitter.on("BeforeInputType", beforeInputType3);
|
|
@@ -1943,17 +2139,17 @@ function beforeInputType3(args) {
|
|
|
1943
2139
|
field.isNullable = false;
|
|
1944
2140
|
}
|
|
1945
2141
|
}
|
|
2142
|
+
|
|
2143
|
+
// src/handlers/type-registry.ts
|
|
1946
2144
|
function generateTypeRegistry(args) {
|
|
1947
2145
|
const { config, output, project } = args;
|
|
1948
2146
|
if (!config.esmCompatible) {
|
|
1949
2147
|
return;
|
|
1950
2148
|
}
|
|
1951
|
-
const rootDirectory = project.getDirectory(output)
|
|
1952
|
-
const sourceFile = rootDirectory.createSourceFile(
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
{ overwrite: true }
|
|
1956
|
-
);
|
|
2149
|
+
const rootDirectory = project.getDirectory(output) ?? project.createDirectory(output);
|
|
2150
|
+
const sourceFile = rootDirectory.createSourceFile("type-registry.ts", void 0, {
|
|
2151
|
+
overwrite: true
|
|
2152
|
+
});
|
|
1957
2153
|
const registryCode = `/**
|
|
1958
2154
|
* Type Registry for ESM Circular Dependency Resolution
|
|
1959
2155
|
*
|
|
@@ -2084,81 +2280,17 @@ export function validateRegistry(expectedTypes: string[]): void {
|
|
|
2084
2280
|
sourceFile.addStatements(registryCode);
|
|
2085
2281
|
}
|
|
2086
2282
|
|
|
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
2283
|
// src/handlers/warning.ts
|
|
2284
|
+
var globalConsole = globalThis.console;
|
|
2285
|
+
var log = (msg) => {
|
|
2286
|
+
globalConsole.log(msg);
|
|
2287
|
+
};
|
|
2156
2288
|
function warning(message) {
|
|
2157
2289
|
if (Array.isArray(message)) {
|
|
2158
|
-
|
|
2159
|
-
|
|
2290
|
+
log("nestjs-prisma-graphql:");
|
|
2291
|
+
log(message.join("\n"));
|
|
2160
2292
|
} else {
|
|
2161
|
-
|
|
2293
|
+
log(`nestjs-prisma-graphql: ${message}`);
|
|
2162
2294
|
}
|
|
2163
2295
|
}
|
|
2164
2296
|
|
|
@@ -2172,44 +2304,51 @@ var allEmmittedBlocks = [
|
|
|
2172
2304
|
"outputs"
|
|
2173
2305
|
];
|
|
2174
2306
|
var blocksDependencyMap = {
|
|
2307
|
+
args: ["args", "inputs", "prismaEnums"],
|
|
2175
2308
|
enums: ["schemaEnums", "prismaEnums"],
|
|
2176
|
-
models: ["models", "schemaEnums"],
|
|
2177
2309
|
inputs: ["inputs", "prismaEnums"],
|
|
2178
|
-
|
|
2179
|
-
|
|
2310
|
+
models: ["models", "schemaEnums"],
|
|
2311
|
+
outputs: ["outputs"]
|
|
2180
2312
|
};
|
|
2181
2313
|
function createEmitBlocks(data) {
|
|
2182
2314
|
if (!data) {
|
|
2183
|
-
|
|
2315
|
+
const entries = allEmmittedBlocks.map((block) => [block, true]);
|
|
2316
|
+
const allBlocks = Object.fromEntries(entries);
|
|
2317
|
+
return allBlocks;
|
|
2184
2318
|
}
|
|
2185
|
-
|
|
2319
|
+
const initialBlocks = {};
|
|
2320
|
+
let currentBlocks = initialBlocks;
|
|
2186
2321
|
for (const block of data) {
|
|
2187
|
-
if (!Object.keys(blocksDependencyMap).includes(block))
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
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
|
|
2193
2332
|
};
|
|
2194
2333
|
}
|
|
2195
|
-
return
|
|
2334
|
+
return currentBlocks;
|
|
2196
2335
|
}
|
|
2197
2336
|
|
|
2198
2337
|
// src/helpers/create-config.ts
|
|
2199
2338
|
function createConfig(data) {
|
|
2200
2339
|
const config = merge({}, unflatten(data, { delimiter: "_" }));
|
|
2201
2340
|
const $warnings = [];
|
|
2202
|
-
const
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
outputFilePattern = trim(
|
|
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, "/");
|
|
2207
2346
|
if (outputFilePattern !== configOutputFilePattern) {
|
|
2208
2347
|
$warnings.push(
|
|
2209
2348
|
`Due to invalid filepath 'outputFilePattern' changed to '${outputFilePattern}'`
|
|
2210
2349
|
);
|
|
2211
2350
|
}
|
|
2212
|
-
if (config.reExportAll) {
|
|
2351
|
+
if (config.reExportAll !== void 0 && config.reExportAll !== null && config.reExportAll !== false) {
|
|
2213
2352
|
$warnings.push(`Option 'reExportAll' is deprecated, use 'reExport' instead`);
|
|
2214
2353
|
if (toBoolean(config.reExportAll)) {
|
|
2215
2354
|
config.reExport = "All";
|
|
@@ -2221,105 +2360,118 @@ function createConfig(data) {
|
|
|
2221
2360
|
).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
|
|
2222
2361
|
const fieldSetting = {
|
|
2223
2362
|
arguments: [],
|
|
2224
|
-
|
|
2363
|
+
defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
|
|
2364
|
+
from: value.from,
|
|
2225
2365
|
input: toBoolean(value.input),
|
|
2226
2366
|
model: toBoolean(value.model),
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
namespaceImport: value.namespaceImport
|
|
2367
|
+
namespaceImport: value.namespaceImport,
|
|
2368
|
+
output: toBoolean(value.output)
|
|
2230
2369
|
};
|
|
2231
2370
|
return [name, fieldSetting];
|
|
2232
2371
|
})
|
|
2233
2372
|
);
|
|
2234
2373
|
const decorate = [];
|
|
2235
|
-
const
|
|
2236
|
-
|
|
2237
|
-
);
|
|
2374
|
+
const decorateConfig = config.decorate !== void 0 && config.decorate !== null ? config.decorate : {};
|
|
2375
|
+
const configDecorate = Object.values(decorateConfig);
|
|
2238
2376
|
for (const element of configDecorate) {
|
|
2239
|
-
if (
|
|
2377
|
+
if (element === void 0 || element === null) {
|
|
2378
|
+
continue;
|
|
2379
|
+
}
|
|
2240
2380
|
ok(
|
|
2241
|
-
element.from && element.name,
|
|
2381
|
+
element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
|
|
2242
2382
|
`Missed 'from' or 'name' part in configuration for decorate`
|
|
2243
2383
|
);
|
|
2244
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,
|
|
2245
2388
|
isMatchField: outmatch2(element.field, { separator: false }),
|
|
2246
2389
|
isMatchType: outmatch2(element.type, { separator: false }),
|
|
2247
|
-
from: element.from,
|
|
2248
2390
|
name: element.name,
|
|
2249
2391
|
namedImport: toBoolean(element.namedImport),
|
|
2250
|
-
|
|
2251
|
-
namespaceImport: element.namespaceImport,
|
|
2252
|
-
arguments: element.arguments ? JSON52.parse(element.arguments) : void 0
|
|
2392
|
+
namespaceImport: element.namespaceImport
|
|
2253
2393
|
});
|
|
2254
2394
|
}
|
|
2255
2395
|
const customImport = [];
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
);
|
|
2396
|
+
const customImportConfig = config.customImport !== void 0 && config.customImport !== null ? config.customImport : {};
|
|
2397
|
+
const configCustomImport = Object.values(customImportConfig);
|
|
2259
2398
|
for (const element of configCustomImport) {
|
|
2260
|
-
if (
|
|
2399
|
+
if (element === void 0 || element === null) {
|
|
2400
|
+
continue;
|
|
2401
|
+
}
|
|
2261
2402
|
ok(
|
|
2262
|
-
element.from && element.name,
|
|
2403
|
+
element.from !== void 0 && element.from !== "" && element.name !== void 0 && element.name !== "",
|
|
2263
2404
|
`Missed 'from' or 'name' part in configuration for customImport`
|
|
2264
2405
|
);
|
|
2265
2406
|
customImport.push({
|
|
2407
|
+
defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
|
|
2266
2408
|
from: element.from,
|
|
2267
2409
|
name: element.name,
|
|
2268
2410
|
namedImport: toBoolean(element.namedImport),
|
|
2269
|
-
defaultImport: toBoolean(element.defaultImport) ? true : element.defaultImport,
|
|
2270
2411
|
namespaceImport: element.namespaceImport
|
|
2271
2412
|
});
|
|
2272
2413
|
}
|
|
2273
2414
|
return {
|
|
2274
|
-
|
|
2275
|
-
tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
|
|
2276
|
-
prismaClientImport: createPrismaImport(config.prismaClientImport),
|
|
2415
|
+
$warnings,
|
|
2277
2416
|
combineScalarFilters: toBoolean(config.combineScalarFilters),
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
emitSingle: toBoolean(config.emitSingle),
|
|
2281
|
-
emitCompiled: toBoolean(config.emitCompiled),
|
|
2417
|
+
customImport,
|
|
2418
|
+
decorate,
|
|
2282
2419
|
emitBlocks: createEmitBlocks(config.emitBlocks),
|
|
2283
|
-
|
|
2284
|
-
|
|
2420
|
+
emitCompiled: toBoolean(config.emitCompiled),
|
|
2421
|
+
emitSingle: toBoolean(config.emitSingle),
|
|
2422
|
+
esmCompatible: toBoolean(config.esmCompatible),
|
|
2285
2423
|
fields,
|
|
2286
|
-
|
|
2287
|
-
|
|
2424
|
+
graphqlScalars: config.graphqlScalars ?? {},
|
|
2425
|
+
noAtomicOperations: toBoolean(config.noAtomicOperations),
|
|
2288
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 */,
|
|
2289
2432
|
requireSingleFieldsInWhereUniqueInput: toBoolean(
|
|
2290
2433
|
config.requireSingleFieldsInWhereUniqueInput
|
|
2291
2434
|
),
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
customImport,
|
|
2298
|
-
esmCompatible: toBoolean(config.esmCompatible)
|
|
2435
|
+
tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
|
|
2436
|
+
unsafeCompatibleWhereUniqueInput: toBoolean(config.unsafeCompatibleWhereUniqueInput),
|
|
2437
|
+
useInputType: createUseInputType(
|
|
2438
|
+
config.useInputType
|
|
2439
|
+
)
|
|
2299
2440
|
};
|
|
2300
2441
|
}
|
|
2301
|
-
var
|
|
2302
|
-
|
|
2442
|
+
var existsSyncTyped = existsSync;
|
|
2443
|
+
var tsConfigFileExistsRaw = memoize((filePath) => {
|
|
2444
|
+
const exists = existsSyncTyped(filePath);
|
|
2445
|
+
return exists;
|
|
2303
2446
|
});
|
|
2447
|
+
var tsConfigFileExists = tsConfigFileExistsRaw;
|
|
2304
2448
|
function createTsConfigFilePathValue(value) {
|
|
2305
|
-
if (typeof value === "string"
|
|
2306
|
-
|
|
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;
|
|
2307
2457
|
}
|
|
2308
2458
|
function createPrismaImport(value) {
|
|
2309
|
-
if (typeof value === "string"
|
|
2459
|
+
if (typeof value === "string" && value !== "") {
|
|
2460
|
+
return value;
|
|
2461
|
+
}
|
|
2310
2462
|
return "@prisma/client";
|
|
2311
2463
|
}
|
|
2312
2464
|
function createUseInputType(data) {
|
|
2313
|
-
if (
|
|
2465
|
+
if (data === void 0 || data === null) {
|
|
2314
2466
|
return [];
|
|
2315
2467
|
}
|
|
2316
2468
|
const result = [];
|
|
2317
2469
|
for (const [typeName, useInputs] of Object.entries(data)) {
|
|
2318
2470
|
const entry = {
|
|
2319
|
-
|
|
2320
|
-
|
|
2471
|
+
ALL: void 0,
|
|
2472
|
+
typeName
|
|
2321
2473
|
};
|
|
2322
|
-
if (useInputs.ALL) {
|
|
2474
|
+
if (useInputs.ALL !== void 0 && useInputs.ALL !== "") {
|
|
2323
2475
|
entry.ALL = useInputs.ALL;
|
|
2324
2476
|
delete useInputs.ALL;
|
|
2325
2477
|
}
|
|
@@ -2337,7 +2489,7 @@ function generateFileName(args) {
|
|
|
2337
2489
|
const { getModelName: getModelName2, name, template, type } = args;
|
|
2338
2490
|
const rawPath = pupa(template, {
|
|
2339
2491
|
get model() {
|
|
2340
|
-
const result = getModelName2(name)
|
|
2492
|
+
const result = getModelName2(name) ?? "prisma";
|
|
2341
2493
|
return kebabCase(result);
|
|
2342
2494
|
},
|
|
2343
2495
|
get name() {
|
|
@@ -2362,61 +2514,19 @@ function generateFileName(args) {
|
|
|
2362
2514
|
|
|
2363
2515
|
// src/helpers/factory-get-source-file.ts
|
|
2364
2516
|
function factoryGetSourceFile(args) {
|
|
2365
|
-
const {
|
|
2366
|
-
return function getSourceFile(
|
|
2367
|
-
const { name, type } =
|
|
2517
|
+
const { getModelName: getModelName2, output, outputFilePattern, project } = args;
|
|
2518
|
+
return function getSourceFile(getSourceFileArgs) {
|
|
2519
|
+
const { name, type } = getSourceFileArgs;
|
|
2368
2520
|
let filePath = generateFileName({
|
|
2369
2521
|
getModelName: getModelName2,
|
|
2370
2522
|
name,
|
|
2371
|
-
|
|
2372
|
-
|
|
2523
|
+
template: outputFilePattern,
|
|
2524
|
+
type
|
|
2373
2525
|
});
|
|
2374
2526
|
filePath = `${output}/${filePath}`;
|
|
2375
|
-
return project.getSourceFile(filePath)
|
|
2527
|
+
return project.getSourceFile(filePath) ?? project.createSourceFile(filePath, void 0, { overwrite: true });
|
|
2376
2528
|
};
|
|
2377
2529
|
}
|
|
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
2530
|
var splitKeywords = [
|
|
2421
2531
|
"CreateInput",
|
|
2422
2532
|
"CreateMany",
|
|
@@ -2496,28 +2606,85 @@ var middleKeywords = [
|
|
|
2496
2606
|
["GroupBy", "Args"],
|
|
2497
2607
|
["OrderBy", "Args"]
|
|
2498
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
|
+
}
|
|
2499
2652
|
|
|
2500
2653
|
// src/generate.ts
|
|
2501
|
-
var
|
|
2502
|
-
var
|
|
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;
|
|
2503
2660
|
async function generate(args) {
|
|
2504
2661
|
const { connectCallback, dmmf, generator, skipAddOutputSourceFiles } = args;
|
|
2505
|
-
const generatorOutputValue = generator.output?.value;
|
|
2506
|
-
ok(generatorOutputValue, "Missing generator configuration: output");
|
|
2662
|
+
const generatorOutputValue = generator.output?.value ?? "";
|
|
2663
|
+
ok(generatorOutputValue !== "", "Missing generator configuration: output");
|
|
2507
2664
|
const config = createConfig(generator.config);
|
|
2508
|
-
const eventEmitter = new
|
|
2665
|
+
const eventEmitter = new AwaitEventEmitterClass();
|
|
2509
2666
|
eventEmitter.on("Warning", warning);
|
|
2510
|
-
config.emitBlocks.models
|
|
2667
|
+
if (config.emitBlocks.models) {
|
|
2668
|
+
eventEmitter.on("Model", modelData);
|
|
2669
|
+
}
|
|
2511
2670
|
if (config.emitBlocks.prismaEnums || config.emitBlocks.schemaEnums) {
|
|
2512
2671
|
eventEmitter.on("EnumType", registerEnum);
|
|
2513
2672
|
}
|
|
2514
2673
|
if (config.emitBlocks.outputs || config.emitBlocks.models && !config.omitModelsCount) {
|
|
2515
2674
|
eventEmitter.on("OutputType", outputType);
|
|
2516
2675
|
}
|
|
2517
|
-
config.emitBlocks.models
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
config.emitBlocks.
|
|
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
|
+
}
|
|
2521
2688
|
eventEmitter.on("GenerateFiles", generateFiles);
|
|
2522
2689
|
for (const message of config.$warnings) {
|
|
2523
2690
|
eventEmitter.emitSync("Warning", message);
|
|
@@ -2530,18 +2697,30 @@ async function generate(args) {
|
|
|
2530
2697
|
skipLoadingLibFiles: !config.emitCompiled,
|
|
2531
2698
|
tsConfigFilePath: config.tsConfigFilePath
|
|
2532
2699
|
});
|
|
2533
|
-
if (
|
|
2700
|
+
if (skipAddOutputSourceFiles !== true) {
|
|
2534
2701
|
project.addSourceFilesAtPaths([
|
|
2535
2702
|
`${generatorOutputValue}/**/*.ts`,
|
|
2536
2703
|
`!${generatorOutputValue}/**/*.d.ts`
|
|
2537
2704
|
]);
|
|
2538
2705
|
}
|
|
2539
|
-
config.combineScalarFilters
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
config.
|
|
2543
|
-
|
|
2544
|
-
|
|
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
|
+
}
|
|
2545
2724
|
const models = /* @__PURE__ */ new Map();
|
|
2546
2725
|
const modelNames = [];
|
|
2547
2726
|
const modelFields = /* @__PURE__ */ new Map();
|
|
@@ -2555,7 +2734,8 @@ async function generate(args) {
|
|
|
2555
2734
|
});
|
|
2556
2735
|
const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf));
|
|
2557
2736
|
const removeTypes = /* @__PURE__ */ new Set();
|
|
2558
|
-
const
|
|
2737
|
+
const datamodelTypes = datamodel.types ?? [];
|
|
2738
|
+
const allModels = [...datamodel.models, ...datamodelTypes];
|
|
2559
2739
|
const dependencyGraph = buildDependencyGraph(allModels);
|
|
2560
2740
|
const circularDependencies = detectCircularDependencies(dependencyGraph);
|
|
2561
2741
|
const eventArguments = {
|
|
@@ -2587,7 +2767,7 @@ async function generate(args) {
|
|
|
2587
2767
|
for (const model of datamodel.models) {
|
|
2588
2768
|
await eventEmitter.emit("Model", model, eventArguments);
|
|
2589
2769
|
}
|
|
2590
|
-
for (const model of
|
|
2770
|
+
for (const model of datamodelTypes) {
|
|
2591
2771
|
await eventEmitter.emit("Model", model, eventArguments);
|
|
2592
2772
|
}
|
|
2593
2773
|
const { enumTypes, inputObjectTypes, outputObjectTypes } = schema;
|
|
@@ -2632,7 +2812,9 @@ async function generate(args) {
|
|
|
2632
2812
|
await eventEmitter.emit("BeforeGenerateFiles", eventArguments);
|
|
2633
2813
|
await eventEmitter.emit("GenerateFiles", eventArguments);
|
|
2634
2814
|
await eventEmitter.emit("End", eventArguments);
|
|
2635
|
-
for (const name of Object.keys(
|
|
2815
|
+
for (const name of Object.keys(
|
|
2816
|
+
eventEmitter._events
|
|
2817
|
+
)) {
|
|
2636
2818
|
eventEmitter.off(name);
|
|
2637
2819
|
}
|
|
2638
2820
|
}
|