@k0lyan/typegraphql-prisma-nestjs 0.28.20 → 0.28.21

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.
Files changed (88) hide show
  1. package/lib/cli/dev.d.ts +1 -0
  2. package/lib/cli/dev.js +5 -0
  3. package/lib/cli/dev.js.map +1 -0
  4. package/lib/cli/generator.d.ts +1 -0
  5. package/lib/cli/generator.js +13 -0
  6. package/lib/cli/generator.js.map +1 -0
  7. package/lib/cli/helpers.d.ts +4 -0
  8. package/lib/cli/helpers.js +52 -0
  9. package/lib/cli/helpers.js.map +1 -0
  10. package/lib/cli/prisma-generator.d.ts +2 -0
  11. package/lib/cli/prisma-generator.js +79 -0
  12. package/lib/cli/prisma-generator.js.map +1 -0
  13. package/lib/generator/args-class.d.ts +4 -0
  14. package/lib/generator/args-class.js +56 -0
  15. package/lib/generator/args-class.js.map +1 -0
  16. package/lib/generator/config.d.ts +22 -0
  17. package/lib/generator/config.js +39 -0
  18. package/lib/generator/config.js.map +1 -0
  19. package/lib/generator/dmmf/dmmf-document.d.ts +19 -0
  20. package/lib/generator/dmmf/dmmf-document.js +60 -0
  21. package/lib/generator/dmmf/dmmf-document.js.map +1 -0
  22. package/lib/generator/dmmf/helpers.d.ts +5 -0
  23. package/lib/generator/dmmf/helpers.js +42 -0
  24. package/lib/generator/dmmf/helpers.js.map +1 -0
  25. package/lib/generator/dmmf/transform.d.ts +11 -0
  26. package/lib/generator/dmmf/transform.js +456 -0
  27. package/lib/generator/dmmf/transform.js.map +1 -0
  28. package/lib/generator/dmmf/types.d.ts +230 -0
  29. package/lib/generator/dmmf/types.js +28 -0
  30. package/lib/generator/dmmf/types.js.map +1 -0
  31. package/lib/generator/emit-block.d.ts +4 -0
  32. package/lib/generator/emit-block.js +35 -0
  33. package/lib/generator/emit-block.js.map +1 -0
  34. package/lib/generator/enum.d.ts +4 -0
  35. package/lib/generator/enum.js +39 -0
  36. package/lib/generator/enum.js.map +1 -0
  37. package/lib/generator/generate-code.d.ts +3 -0
  38. package/lib/generator/generate-code.js +229 -0
  39. package/lib/generator/generate-code.js.map +1 -0
  40. package/lib/generator/generate-enhance.d.ts +5 -0
  41. package/lib/generator/generate-enhance.js +492 -0
  42. package/lib/generator/generate-enhance.js.map +1 -0
  43. package/lib/generator/generate-helpers.d.ts +3 -0
  44. package/lib/generator/generate-helpers.js +113 -0
  45. package/lib/generator/generate-helpers.js.map +1 -0
  46. package/lib/generator/generate-scalars.d.ts +3 -0
  47. package/lib/generator/generate-scalars.js +27 -0
  48. package/lib/generator/generate-scalars.js.map +1 -0
  49. package/lib/generator/helpers.d.ts +14 -0
  50. package/lib/generator/helpers.js +226 -0
  51. package/lib/generator/helpers.js.map +1 -0
  52. package/lib/generator/imports.d.ts +28 -0
  53. package/lib/generator/imports.js +311 -0
  54. package/lib/generator/imports.js.map +1 -0
  55. package/lib/generator/model-type-class.d.ts +4 -0
  56. package/lib/generator/model-type-class.js +152 -0
  57. package/lib/generator/model-type-class.js.map +1 -0
  58. package/lib/generator/options.d.ts +40 -0
  59. package/lib/generator/options.js +3 -0
  60. package/lib/generator/options.js.map +1 -0
  61. package/lib/generator/resolvers/full-crud.d.ts +5 -0
  62. package/lib/generator/resolvers/full-crud.js +45 -0
  63. package/lib/generator/resolvers/full-crud.js.map +1 -0
  64. package/lib/generator/resolvers/helpers.d.ts +5 -0
  65. package/lib/generator/resolvers/helpers.js +81 -0
  66. package/lib/generator/resolvers/helpers.js.map +1 -0
  67. package/lib/generator/resolvers/relations.d.ts +5 -0
  68. package/lib/generator/resolvers/relations.js +254 -0
  69. package/lib/generator/resolvers/relations.js.map +1 -0
  70. package/lib/generator/resolvers/separate-action.d.ts +5 -0
  71. package/lib/generator/resolvers/separate-action.js +33 -0
  72. package/lib/generator/resolvers/separate-action.js.map +1 -0
  73. package/lib/generator/type-class.d.ts +12 -0
  74. package/lib/generator/type-class.js +340 -0
  75. package/lib/generator/type-class.js.map +1 -0
  76. package/lib/generator/types.d.ts +5 -0
  77. package/lib/generator/types.js +3 -0
  78. package/lib/generator/types.js.map +1 -0
  79. package/lib/generator.d.ts +2 -0
  80. package/lib/generator.js +5 -0
  81. package/lib/generator.js.map +1 -0
  82. package/lib/utils/prisma-version.d.ts +1 -0
  83. package/lib/utils/prisma-version.js +34 -0
  84. package/lib/utils/prisma-version.js.map +1 -0
  85. package/lib/utils/removeDir.d.ts +1 -0
  86. package/lib/utils/removeDir.js +19 -0
  87. package/lib/utils/removeDir.js.map +1 -0
  88. package/package.json +1 -1
@@ -0,0 +1,492 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEnhanceMap = generateEnhanceMap;
4
+ const ts_morph_1 = require("ts-morph");
5
+ const config_1 = require("./config");
6
+ function generateEnhanceMap(sourceFile, dmmfDocument, modelMappings, relationModels, models, inputs, outputs, generatorOptions) {
7
+ const hasRelations = relationModels.length > 0;
8
+ sourceFile.addImportDeclaration({
9
+ moduleSpecifier: "@nestjs/common",
10
+ namedImports: ["Type"],
11
+ });
12
+ sourceFile.addImportDeclaration({
13
+ moduleSpecifier: "tslib",
14
+ namespaceImport: "tslib",
15
+ });
16
+ if (dmmfDocument.shouldGenerateBlock("crudResolvers") ||
17
+ (hasRelations && dmmfDocument.shouldGenerateBlock("relationResolvers"))) {
18
+ sourceFile.addStatements(/* ts */ `
19
+ export type MethodDecoratorOverrideFn = (decorators: MethodDecorator[]) => MethodDecorator[];
20
+ `);
21
+ }
22
+ if (dmmfDocument.shouldGenerateBlock("crudResolvers")) {
23
+ sourceFile.addImportDeclaration({
24
+ moduleSpecifier: `./${config_1.resolversFolderName}/${config_1.crudResolversFolderName}/resolvers-crud.index`,
25
+ namespaceImport: "crudResolvers",
26
+ });
27
+ sourceFile.addImportDeclaration({
28
+ moduleSpecifier: `./${config_1.resolversFolderName}/${config_1.crudResolversFolderName}/args.index`,
29
+ namespaceImport: "argsTypes",
30
+ });
31
+ sourceFile.addVariableStatement({
32
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
33
+ declarations: [
34
+ {
35
+ name: "crudResolversMap",
36
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(modelMappings.map(mapping => [
37
+ mapping.modelTypeName,
38
+ `crudResolvers.${mapping.resolverName}`,
39
+ ]))),
40
+ },
41
+ ],
42
+ trailingTrivia: "\r\n",
43
+ });
44
+ sourceFile.addImportDeclaration({
45
+ moduleSpecifier: `./${config_1.resolversFolderName}/${config_1.crudResolversFolderName}/resolvers-actions.index`,
46
+ namespaceImport: "actionResolvers",
47
+ });
48
+ sourceFile.addVariableStatement({
49
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
50
+ declarations: [
51
+ {
52
+ name: "actionResolversMap",
53
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(modelMappings.map(mapping => [
54
+ mapping.modelTypeName,
55
+ ts_morph_1.Writers.object(Object.fromEntries(mapping.actions
56
+ .filter(a => !generatorOptions.emitActions?.includes(a.prismaMethod))
57
+ .map(action => [
58
+ action.name,
59
+ `actionResolvers.${action.actionResolverName}`,
60
+ ]))),
61
+ ]))),
62
+ },
63
+ ],
64
+ });
65
+ sourceFile.addVariableStatement({
66
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
67
+ declarations: [
68
+ {
69
+ name: "crudResolversInfo",
70
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(modelMappings.map(mapping => [
71
+ mapping.modelTypeName,
72
+ `[${mapping.actions
73
+ .filter(a => !generatorOptions.emitActions?.includes(a.prismaMethod))
74
+ .map(action => `"${action.name}"`)
75
+ .join(", ")}]`,
76
+ ]))),
77
+ },
78
+ ],
79
+ trailingTrivia: "\r\n",
80
+ });
81
+ const actions = modelMappings
82
+ .flatMap(it => it.actions)
83
+ .filter(it => it.argsTypeName);
84
+ sourceFile.addVariableStatement({
85
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
86
+ declarations: [
87
+ {
88
+ name: "argsInfo",
89
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(actions.map(action => [
90
+ action.argsTypeName,
91
+ `[${action.method.args
92
+ .map(arg => `"${arg.typeName}"`)
93
+ .join(", ")}]`,
94
+ ]))),
95
+ },
96
+ ],
97
+ trailingTrivia: "\r\n",
98
+ });
99
+ sourceFile.addStatements(/* ts */ `
100
+ type ResolverModelNames = keyof typeof crudResolversMap;
101
+
102
+ type ModelResolverActionNames<
103
+ TModel extends ResolverModelNames
104
+ > = keyof typeof crudResolversMap[TModel]["prototype"];
105
+
106
+ export type ResolverActionsConfig<
107
+ TModel extends ResolverModelNames
108
+ > = Partial<Record<ModelResolverActionNames<TModel>, MethodDecorator[] | MethodDecoratorOverrideFn>>
109
+ & {
110
+ _all?: MethodDecorator[];
111
+ _query?: MethodDecorator[];
112
+ _mutation?: MethodDecorator[];
113
+ };
114
+
115
+ export type ResolversEnhanceMap = {
116
+ [TModel in ResolverModelNames]?: ResolverActionsConfig<TModel>;
117
+ };
118
+
119
+ export function applyResolversEnhanceMap(
120
+ resolversEnhanceMap: ResolversEnhanceMap,
121
+ ) {
122
+ const mutationOperationPrefixes = [
123
+ ${config_1.supportedMutationActions.map(it => `"${it}"`).join(", ")}
124
+ ];
125
+ for (const resolversEnhanceMapKey of Object.keys(resolversEnhanceMap)) {
126
+ const modelName = resolversEnhanceMapKey as keyof typeof resolversEnhanceMap;
127
+ const crudTarget = crudResolversMap[modelName].prototype;
128
+ const resolverActionsConfig = resolversEnhanceMap[modelName]!;
129
+ const actionResolversConfig = actionResolversMap[modelName];
130
+ const allActionsDecorators = resolverActionsConfig._all;
131
+ const resolverActionNames = crudResolversInfo[modelName as keyof typeof crudResolversInfo];
132
+ for (const resolverActionName of resolverActionNames) {
133
+ const maybeDecoratorsOrFn = resolverActionsConfig[
134
+ resolverActionName as keyof typeof resolverActionsConfig
135
+ ] as MethodDecorator[] | MethodDecoratorOverrideFn | undefined;
136
+ const isWriteOperation = mutationOperationPrefixes.some(prefix => resolverActionName.startsWith(prefix));
137
+ const operationKindDecorators = isWriteOperation ? resolverActionsConfig._mutation : resolverActionsConfig._query;
138
+ const mainDecorators = [
139
+ ...allActionsDecorators ?? [],
140
+ ...operationKindDecorators ?? [],
141
+ ]
142
+ let decorators: MethodDecorator[];
143
+ if (typeof maybeDecoratorsOrFn === "function") {
144
+ decorators = maybeDecoratorsOrFn(mainDecorators);
145
+ } else {
146
+ decorators = [...mainDecorators, ...maybeDecoratorsOrFn ?? []];
147
+ }
148
+ const actionTarget = (actionResolversConfig[
149
+ resolverActionName as keyof typeof actionResolversConfig
150
+ ] as Function).prototype;
151
+ tslib.__decorate(decorators, crudTarget, resolverActionName, null);
152
+ tslib.__decorate(decorators, actionTarget, resolverActionName, null);
153
+ }
154
+ }
155
+ }
156
+ `);
157
+ sourceFile.addStatements(/* ts */ `
158
+ type ArgsTypesNames = keyof typeof argsTypes;
159
+
160
+ type ArgFieldNames<TArgsType extends ArgsTypesNames> = Exclude<
161
+ keyof typeof argsTypes[TArgsType]["prototype"],
162
+ number | symbol
163
+ >;
164
+
165
+ type ArgFieldsConfig<
166
+ TArgsType extends ArgsTypesNames
167
+ > = FieldsConfig<ArgFieldNames<TArgsType>>;
168
+
169
+ export type ArgConfig<TArgsType extends ArgsTypesNames> = {
170
+ class?: ClassDecorator[];
171
+ fields?: ArgFieldsConfig<TArgsType>;
172
+ };
173
+
174
+ export type ArgsTypesEnhanceMap = {
175
+ [TArgsType in ArgsTypesNames]?: ArgConfig<TArgsType>;
176
+ };
177
+
178
+ export function applyArgsTypesEnhanceMap(
179
+ argsTypesEnhanceMap: ArgsTypesEnhanceMap,
180
+ ) {
181
+ for (const argsTypesEnhanceMapKey of Object.keys(argsTypesEnhanceMap)) {
182
+ const argsTypeName = argsTypesEnhanceMapKey as keyof typeof argsTypesEnhanceMap;
183
+ const typeConfig = argsTypesEnhanceMap[argsTypeName]!;
184
+ const typeClass = argsTypes[argsTypeName];
185
+ const typeTarget = typeClass.prototype;
186
+ applyTypeClassEnhanceConfig(
187
+ typeConfig,
188
+ typeClass,
189
+ typeTarget,
190
+ argsInfo[argsTypeName as keyof typeof argsInfo],
191
+ );
192
+ }
193
+ }
194
+ `);
195
+ }
196
+ if (hasRelations && dmmfDocument.shouldGenerateBlock("relationResolvers")) {
197
+ sourceFile.addImportDeclaration({
198
+ moduleSpecifier: `./${config_1.resolversFolderName}/${config_1.relationsResolversFolderName}/resolvers.index`,
199
+ namespaceImport: "relationResolvers",
200
+ });
201
+ sourceFile.addVariableStatement({
202
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
203
+ declarations: [
204
+ {
205
+ name: "relationResolversMap",
206
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(relationModels.map(relationModel => [
207
+ relationModel.model.typeName,
208
+ `relationResolvers.${relationModel.resolverName}`,
209
+ ]))),
210
+ },
211
+ ],
212
+ trailingTrivia: "\r\n",
213
+ });
214
+ sourceFile.addVariableStatement({
215
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
216
+ declarations: [
217
+ {
218
+ name: "relationResolversInfo",
219
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(relationModels.map(relationModel => [
220
+ relationModel.model.typeName,
221
+ `[${relationModel.relationFields
222
+ .map(field => `"${field.name}"`)
223
+ .join(", ")}]`,
224
+ ]))),
225
+ },
226
+ ],
227
+ trailingTrivia: "\r\n",
228
+ });
229
+ sourceFile.addStatements(/* ts */ `
230
+ type RelationResolverModelNames = keyof typeof relationResolversMap;
231
+
232
+ type RelationResolverActionNames<
233
+ TModel extends RelationResolverModelNames
234
+ > = keyof typeof relationResolversMap[TModel]["prototype"];
235
+
236
+ export type RelationResolverActionsConfig<TModel extends RelationResolverModelNames>
237
+ = Partial<Record<RelationResolverActionNames<TModel>, MethodDecorator[] | MethodDecoratorOverrideFn>>
238
+ & { _all?: MethodDecorator[] };
239
+
240
+ export type RelationResolversEnhanceMap = {
241
+ [TModel in RelationResolverModelNames]?: RelationResolverActionsConfig<TModel>;
242
+ };
243
+
244
+ export function applyRelationResolversEnhanceMap(
245
+ relationResolversEnhanceMap: RelationResolversEnhanceMap,
246
+ ) {
247
+ for (const relationResolversEnhanceMapKey of Object.keys(relationResolversEnhanceMap)) {
248
+ const modelName = relationResolversEnhanceMapKey as keyof typeof relationResolversEnhanceMap;
249
+ const relationResolverTarget = relationResolversMap[modelName].prototype;
250
+ const relationResolverActionsConfig = relationResolversEnhanceMap[modelName]!;
251
+ const allActionsDecorators = relationResolverActionsConfig._all ?? [];
252
+ const relationResolverActionNames = relationResolversInfo[modelName as keyof typeof relationResolversInfo];
253
+ for (const relationResolverActionName of relationResolverActionNames) {
254
+ const maybeDecoratorsOrFn = relationResolverActionsConfig[
255
+ relationResolverActionName as keyof typeof relationResolverActionsConfig
256
+ ] as MethodDecorator[] | MethodDecoratorOverrideFn | undefined;
257
+ let decorators: MethodDecorator[];
258
+ if (typeof maybeDecoratorsOrFn === "function") {
259
+ decorators = maybeDecoratorsOrFn(allActionsDecorators);
260
+ } else {
261
+ decorators = [...allActionsDecorators, ...maybeDecoratorsOrFn ?? []];
262
+ }
263
+ tslib.__decorate(decorators, relationResolverTarget, relationResolverActionName, null);
264
+ }
265
+ }
266
+ }
267
+ `);
268
+ }
269
+ if (["outputs", "inputs", "models"].some(it => dmmfDocument.shouldGenerateBlock(it))) {
270
+ sourceFile.addStatements(/* ts */ `
271
+ type TypeConfig = {
272
+ class?: ClassDecorator[];
273
+ fields?: FieldsConfig;
274
+ };
275
+
276
+ export type PropertyDecoratorOverrideFn = (decorators: PropertyDecorator[]) => PropertyDecorator[];
277
+
278
+ type FieldsConfig<TTypeKeys extends string = string> = Partial<
279
+ Record<TTypeKeys, PropertyDecorator[] | PropertyDecoratorOverrideFn>
280
+ > & { _all?: PropertyDecorator[] };
281
+
282
+ function applyTypeClassEnhanceConfig<
283
+ TEnhanceConfig extends TypeConfig,
284
+ TType extends object
285
+ >(
286
+ enhanceConfig: TEnhanceConfig,
287
+ typeClass: Type<TType>,
288
+ typePrototype: TType,
289
+ typeFieldNames: string[]
290
+ ) {
291
+ if (enhanceConfig.class) {
292
+ tslib.__decorate(enhanceConfig.class, typeClass);
293
+ }
294
+ if (enhanceConfig.fields) {
295
+ const allFieldsDecorators = enhanceConfig.fields._all ?? [];
296
+ for (const typeFieldName of typeFieldNames) {
297
+ const maybeDecoratorsOrFn = enhanceConfig.fields[
298
+ typeFieldName
299
+ ] as PropertyDecorator[] | PropertyDecoratorOverrideFn | undefined;
300
+ let decorators: PropertyDecorator[];
301
+ if (typeof maybeDecoratorsOrFn === "function") {
302
+ decorators = maybeDecoratorsOrFn(allFieldsDecorators);
303
+ } else {
304
+ decorators = [...allFieldsDecorators, ...maybeDecoratorsOrFn ?? []];
305
+ }
306
+ tslib.__decorate(decorators, typePrototype, typeFieldName, void 0);
307
+ }
308
+ }
309
+ }
310
+ `);
311
+ }
312
+ if (dmmfDocument.shouldGenerateBlock("models")) {
313
+ sourceFile.addImportDeclaration({
314
+ moduleSpecifier: `./${config_1.modelsFolderName}`,
315
+ namespaceImport: "models",
316
+ });
317
+ sourceFile.addVariableStatement({
318
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
319
+ declarations: [
320
+ {
321
+ name: "modelsInfo",
322
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(
323
+ // TODO: support _count
324
+ models.map(model => {
325
+ const fieldsToEmit = model.fields.filter(field => !field.relationName && !field.isOmitted.output);
326
+ return [
327
+ model.typeName,
328
+ `[${fieldsToEmit
329
+ .map(field => `"${field.typeFieldAlias ?? field.name}"`)
330
+ .join(", ")}]`,
331
+ ];
332
+ }))),
333
+ },
334
+ ],
335
+ isExported: true,
336
+ trailingTrivia: "\r\n",
337
+ });
338
+ sourceFile.addStatements(/* ts */ `
339
+ type ModelNames = keyof typeof models;
340
+
341
+ type ModelFieldNames<TModel extends ModelNames> = Exclude<
342
+ keyof typeof models[TModel]["prototype"],
343
+ number | symbol
344
+ >;
345
+
346
+ type ModelFieldsConfig<TModel extends ModelNames> = FieldsConfig<
347
+ ModelFieldNames<TModel>
348
+ >;
349
+
350
+ export type ModelConfig<TModel extends ModelNames> = {
351
+ class?: ClassDecorator[];
352
+ fields?: ModelFieldsConfig<TModel>;
353
+ };
354
+
355
+ export type ModelsEnhanceMap = {
356
+ [TModel in ModelNames]?: ModelConfig<TModel>;
357
+ };
358
+
359
+ export function applyModelsEnhanceMap(modelsEnhanceMap: ModelsEnhanceMap) {
360
+ for (const modelsEnhanceMapKey of Object.keys(modelsEnhanceMap)) {
361
+ const modelName = modelsEnhanceMapKey as keyof typeof modelsEnhanceMap;
362
+ const modelConfig = modelsEnhanceMap[modelName]!;
363
+ const modelClass = models[modelName];
364
+ const modelTarget = modelClass.prototype;
365
+ applyTypeClassEnhanceConfig(
366
+ modelConfig,
367
+ modelClass,
368
+ modelTarget,
369
+ modelsInfo[modelName as keyof typeof modelsInfo],
370
+ );
371
+ }
372
+ }
373
+ `);
374
+ }
375
+ if (dmmfDocument.shouldGenerateBlock("outputs")) {
376
+ sourceFile.addImportDeclaration({
377
+ moduleSpecifier: `./${config_1.resolversFolderName}/${config_1.outputsFolderName}`,
378
+ namespaceImport: "outputTypes",
379
+ });
380
+ sourceFile.addVariableStatement({
381
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
382
+ declarations: [
383
+ {
384
+ name: "outputsInfo",
385
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(outputs.map(output => [
386
+ output.typeName,
387
+ `[${output.fields.map(field => `"${field.name}"`).join(", ")}]`,
388
+ ]))),
389
+ },
390
+ ],
391
+ trailingTrivia: "\r\n",
392
+ });
393
+ sourceFile.addStatements(/* ts */ `
394
+ type OutputTypesNames = keyof typeof outputTypes;
395
+
396
+ type OutputTypeFieldNames<TOutput extends OutputTypesNames> = Exclude<
397
+ keyof typeof outputTypes[TOutput]["prototype"],
398
+ number | symbol
399
+ >;
400
+
401
+ type OutputTypeFieldsConfig<
402
+ TOutput extends OutputTypesNames
403
+ > = FieldsConfig<OutputTypeFieldNames<TOutput>>;
404
+
405
+ export type OutputTypeConfig<TOutput extends OutputTypesNames> = {
406
+ class?: ClassDecorator[];
407
+ fields?: OutputTypeFieldsConfig<TOutput>;
408
+ };
409
+
410
+ export type OutputTypesEnhanceMap = {
411
+ [TOutput in OutputTypesNames]?: OutputTypeConfig<TOutput>;
412
+ };
413
+
414
+ export function applyOutputTypesEnhanceMap(
415
+ outputTypesEnhanceMap: OutputTypesEnhanceMap,
416
+ ) {
417
+ for (const outputTypeEnhanceMapKey of Object.keys(outputTypesEnhanceMap)) {
418
+ const outputTypeName = outputTypeEnhanceMapKey as keyof typeof outputTypesEnhanceMap;
419
+ const typeConfig = outputTypesEnhanceMap[outputTypeName]!;
420
+ const typeClass = outputTypes[outputTypeName];
421
+ const typeTarget = typeClass.prototype;
422
+ applyTypeClassEnhanceConfig(
423
+ typeConfig,
424
+ typeClass,
425
+ typeTarget,
426
+ outputsInfo[outputTypeName as keyof typeof outputsInfo],
427
+ );
428
+ }
429
+ }
430
+ `);
431
+ }
432
+ if (dmmfDocument.shouldGenerateBlock("inputs")) {
433
+ sourceFile.addImportDeclaration({
434
+ moduleSpecifier: `./${config_1.resolversFolderName}/${config_1.inputsFolderName}`,
435
+ namespaceImport: "inputTypes",
436
+ });
437
+ sourceFile.addVariableStatement({
438
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
439
+ declarations: [
440
+ {
441
+ name: "inputsInfo",
442
+ initializer: ts_morph_1.Writers.object(Object.fromEntries(inputs.map(input => [
443
+ input.typeName,
444
+ `[${input.fields
445
+ .map(field => `"${field.typeName}"`)
446
+ .join(", ")}]`,
447
+ ]))),
448
+ },
449
+ ],
450
+ trailingTrivia: "\r\n",
451
+ });
452
+ sourceFile.addStatements(/* ts */ `
453
+ type InputTypesNames = keyof typeof inputTypes;
454
+
455
+ type InputTypeFieldNames<TInput extends InputTypesNames> = Exclude<
456
+ keyof typeof inputTypes[TInput]["prototype"],
457
+ number | symbol
458
+ >;
459
+
460
+ type InputTypeFieldsConfig<
461
+ TInput extends InputTypesNames
462
+ > = FieldsConfig<InputTypeFieldNames<TInput>>;
463
+
464
+ export type InputTypeConfig<TInput extends InputTypesNames> = {
465
+ class?: ClassDecorator[];
466
+ fields?: InputTypeFieldsConfig<TInput>;
467
+ };
468
+
469
+ export type InputTypesEnhanceMap = {
470
+ [TInput in InputTypesNames]?: InputTypeConfig<TInput>;
471
+ };
472
+
473
+ export function applyInputTypesEnhanceMap(
474
+ inputTypesEnhanceMap: InputTypesEnhanceMap,
475
+ ) {
476
+ for (const inputTypeEnhanceMapKey of Object.keys(inputTypesEnhanceMap)) {
477
+ const inputTypeName = inputTypeEnhanceMapKey as keyof typeof inputTypesEnhanceMap;
478
+ const typeConfig = inputTypesEnhanceMap[inputTypeName]!;
479
+ const typeClass = inputTypes[inputTypeName];
480
+ const typeTarget = typeClass.prototype;
481
+ applyTypeClassEnhanceConfig(
482
+ typeConfig,
483
+ typeClass,
484
+ typeTarget,
485
+ inputsInfo[inputTypeName as keyof typeof inputsInfo],
486
+ );
487
+ }
488
+ }
489
+ `);
490
+ }
491
+ }
492
+ //# sourceMappingURL=generate-enhance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-enhance.js","sourceRoot":"","sources":["../../src/generator/generate-enhance.ts"],"names":[],"mappings":";;AAcA,gDAgjBC;AA9jBD,uCAAwE;AACxE,qCAQkB;AAKlB,SAAgB,kBAAkB,CAChC,UAAsB,EACtB,YAA0B,EAC1B,aAA2C,EAC3C,cAA6C,EAC7C,MAA6B,EAC7B,MAAiC,EACjC,OAAmC,EACnC,gBAAkC;IAElC,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;IAE/C,UAAU,CAAC,oBAAoB,CAAC;QAC9B,eAAe,EAAE,gBAAgB;QACjC,YAAY,EAAE,CAAC,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,UAAU,CAAC,oBAAoB,CAAC;QAC9B,eAAe,EAAE,OAAO;QACxB,eAAe,EAAE,OAAO;KACzB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;;;;;;;;;;;;;;;;;;;;KAqCjC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { SourceFile } from "ts-morph";
2
+ import { GeneratorOptions } from "./options";
3
+ export declare function generateHelpersFile(sourceFile: SourceFile, options: GeneratorOptions): void;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateHelpersFile = generateHelpersFile;
4
+ const imports_1 = require("./imports");
5
+ function generateHelpersFile(sourceFile, options) {
6
+ (0, imports_1.generateGraphQLInfoImport)(sourceFile);
7
+ (0, imports_1.generateGraphQLFieldsImport)(sourceFile);
8
+ sourceFile.addImportDeclaration({
9
+ moduleSpecifier: "dataloader",
10
+ namespaceImport: "DataLoader",
11
+ });
12
+ sourceFile.addStatements(/* ts */ `
13
+ export function transformInfoIntoPrismaArgs(info: GraphQLResolveInfo, modelName?: string, collectionName?: string, prismaMethod?: string, isResolveField?: boolean): Record<string, any> {
14
+ const fields: Record<string, any> = graphqlFields(
15
+ // suppress GraphQLResolveInfo types issue
16
+ info as any,
17
+ {},
18
+ {
19
+ excludedFields: ['__typename'],
20
+ processArguments: true,
21
+ }
22
+ );
23
+ return transformFields(fields, modelName, collectionName, prismaMethod, isResolveField);
24
+ }
25
+ `);
26
+ sourceFile.addStatements(/* ts */ `
27
+ function transformFields(fields: Record<string, any>, modelName?: string, collectionName?: string, prismaMethod?: string, isResolveField?: boolean): Record<string, any> {
28
+ return Object.fromEntries(
29
+ Object.entries(fields)
30
+ .map<[string, any]>(([key, value]) => {
31
+ if (Object.keys(value).length === 0) {
32
+ return [key, true];
33
+ }
34
+ if ("__arguments" in value) {
35
+ return [key, Object.fromEntries(
36
+ value.__arguments.map((argument: object) => {
37
+ const [[key, { value }]] = Object.entries(argument);
38
+ return [key, value];
39
+ })
40
+ )];
41
+ }
42
+ return [key, transformFields(value, modelName, collectionName, prismaMethod, isResolveField)];
43
+ }),
44
+ );
45
+ }
46
+ `);
47
+ sourceFile.addStatements(/* ts */ `
48
+ export function getPrismaFromContext(context: any) {
49
+ const prismaClient = context["${options.contextPrismaKey}"];
50
+ if (!prismaClient) {
51
+ throw new Error("Unable to find Prisma Client in GraphQL context. Please provide it under the \`context[\\"${options.contextPrismaKey}\\"]\` key.");
52
+ }
53
+ return prismaClient;
54
+ }
55
+ `);
56
+ sourceFile.addStatements(/* ts */ `
57
+ export function transformCountFieldIntoSelectRelationsCount(_count: object, modelName?: string, collectionName?: string, prismaMethod?: string, isResolveField?: boolean) {
58
+ return {
59
+ include: {
60
+ _count: {
61
+ select: {
62
+ ...Object.fromEntries(
63
+ Object.entries(_count).filter(([_, v]) => v != null)
64
+ ),
65
+ }
66
+ },
67
+ },
68
+ }
69
+ }
70
+ `);
71
+ sourceFile.addStatements(/* ts */ `
72
+ export let transformArgsIntoPrismaArgs = async function <TArgs = Record<string, any>, TContext = any>(info: GraphQLResolveInfo, args: TArgs, ctx: TContext, modelName?: string, collectionName?: string, prismaMethod?: string, afterProcessEvents?: ((result:any) => Promise<any>)[], isResolveField?: boolean): Promise<TArgs> {
73
+ return args;
74
+ };
75
+
76
+ export function setTransformArgsIntoPrismaArgs(newTransformArgsIntoPrismaArgs: typeof transformArgsIntoPrismaArgs) {
77
+ transformArgsIntoPrismaArgs = newTransformArgsIntoPrismaArgs;
78
+ }
79
+ `);
80
+ sourceFile.addStatements(/* ts */ `
81
+ /**
82
+ * Simple inline dataloader factory for type-graphql resolvers
83
+ * Creates a dataloader per request context
84
+ */
85
+ export function InlineLoader<ID, Type>(
86
+ createLoader: (ctx: any) => DataLoader<ID, Type>,
87
+ _target: any,
88
+ _propertyKey: string,
89
+ parameterIndex: number
90
+ ) {
91
+ // This is a parameter decorator that creates dataloaders
92
+ // The actual loader creation happens at runtime in the resolver
93
+ }
94
+
95
+ /**
96
+ * Helper to get or create a dataloader from context
97
+ */
98
+ export function getOrCreateLoader<ID, Type>(
99
+ ctx: any,
100
+ loaderKey: string,
101
+ createLoader: () => DataLoader<ID, Type>
102
+ ): DataLoader<ID, Type> {
103
+ if (!ctx._dataloaders) {
104
+ ctx._dataloaders = new Map();
105
+ }
106
+ if (!ctx._dataloaders.has(loaderKey)) {
107
+ ctx._dataloaders.set(loaderKey, createLoader());
108
+ }
109
+ return ctx._dataloaders.get(loaderKey);
110
+ }
111
+ `);
112
+ }
113
+ //# sourceMappingURL=generate-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/generator/generate-helpers.ts"],"names":[],"mappings":";;AAOA,kDAoHC;AA1HD,uCAGmB;AAGnB,SAAgB,mBAAmB,CACjC,UAAsB,EACtB,OAAyB;IAEzB,IAAA,mCAAyB,EAAC,UAAU,CAAC,CAAC;IACtC,IAAA,qCAA2B,EAAC,UAAU,CAAC,CAAC;IACxC,UAAU,CAAC,oBAAoB,CAAC;QAC9B,eAAe,EAAE,YAAY;QAC7B,eAAe,EAAE,YAAY;KAC9B,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;;;;;;;;;;;;GAajC,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;GAoBjC,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;sCAEE,OAAO,CAAC,gBAAgB;;qHAEuD,OAAO,CAAC,gBAAgB;;;;GAI1I,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;GAcjC,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;;;;;;;GAQjC,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BjC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { SourceFile } from "ts-morph";
2
+ import { GeneratorOptions } from "./options";
3
+ export declare function generateCustomScalars(sourceFile: SourceFile, options: GeneratorOptions): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCustomScalars = generateCustomScalars;
4
+ const imports_1 = require("./imports");
5
+ function generateCustomScalars(sourceFile, options) {
6
+ (0, imports_1.generatePrismaNamespaceImport)(sourceFile, options);
7
+ (0, imports_1.generateGraphQLScalarTypeImport)(sourceFile);
8
+ sourceFile.addStatements(/* ts */ `
9
+ export const DecimalJSScalar = new GraphQLScalarType({
10
+ name: "Decimal",
11
+ description: "GraphQL Scalar representing the Prisma.Decimal type, based on Decimal.js library.",
12
+ serialize: (value: unknown) => {
13
+ if (!(Prisma.Decimal.isDecimal(value))) {
14
+ throw new Error(\`[DecimalError] Invalid argument: \${Object.prototype.toString.call(value)}. Expected Prisma.Decimal.\`);
15
+ }
16
+ return (value as Prisma.Decimal).toString();
17
+ },
18
+ parseValue: (value: unknown) => {
19
+ if (!(typeof value === "string")) {
20
+ throw new Error(\`[DecimalError] Invalid argument: \${typeof value}. Expected string.\`);
21
+ }
22
+ return new Prisma.Decimal(value);
23
+ },
24
+ });
25
+ `);
26
+ }
27
+ //# sourceMappingURL=generate-scalars.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-scalars.js","sourceRoot":"","sources":["../../src/generator/generate-scalars.ts"],"names":[],"mappings":";;AAQA,sDAyBC;AAhCD,uCAGmB;AAInB,SAAgB,qBAAqB,CACnC,UAAsB,EACtB,OAAyB;IAEzB,IAAA,uCAA6B,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACnD,IAAA,yCAA+B,EAAC,UAAU,CAAC,CAAC;IAE5C,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;;GAiBjC,CAAC,CAAC;AACL,CAAC"}