@pegasusheavy/nestjs-prisma-graphql 1.4.3 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -7
- package/dist/benchmark/analysis.d.ts +7 -0
- package/dist/benchmark/analysis.d.ts.map +1 -0
- package/dist/benchmark/analysis.js +265 -0
- package/dist/benchmark/analysis.js.map +1 -0
- package/dist/benchmark/index.d.ts +7 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/dist/benchmark/index.js +272 -0
- package/dist/benchmark/index.js.map +1 -0
- package/dist/event-names.d.ts +2 -0
- package/dist/event-names.d.ts.map +1 -0
- package/dist/event-names.js +2 -0
- package/dist/event-names.js.map +1 -0
- package/dist/generate.d.ts +4 -140
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +199 -2826
- package/dist/generate.js.map +1 -1
- package/dist/handlers/args-type.d.ts +7 -0
- package/dist/handlers/args-type.d.ts.map +1 -0
- package/dist/handlers/args-type.js +68 -0
- package/dist/handlers/args-type.js.map +1 -0
- package/dist/handlers/combine-scalar-filters.d.ts +6 -0
- package/dist/handlers/combine-scalar-filters.d.ts.map +1 -0
- package/dist/handlers/combine-scalar-filters.js +110 -0
- package/dist/handlers/combine-scalar-filters.js.map +1 -0
- package/dist/handlers/create-aggregate-input.d.ts +10 -0
- package/dist/handlers/create-aggregate-input.d.ts.map +1 -0
- package/dist/handlers/create-aggregate-input.js +33 -0
- package/dist/handlers/create-aggregate-input.js.map +1 -0
- package/dist/handlers/decimal-helpers.d.ts +10 -0
- package/dist/handlers/decimal-helpers.d.ts.map +1 -0
- package/dist/handlers/decimal-helpers.js +73 -0
- package/dist/handlers/decimal-helpers.js.map +1 -0
- package/dist/handlers/emit-single.d.ts +3 -0
- package/dist/handlers/emit-single.d.ts.map +1 -0
- package/dist/handlers/emit-single.js +14 -0
- package/dist/handlers/emit-single.js.map +1 -0
- package/dist/handlers/generate-barrel-exports.d.ts +13 -0
- package/dist/handlers/generate-barrel-exports.d.ts.map +1 -0
- package/dist/handlers/generate-barrel-exports.js +69 -0
- package/dist/handlers/generate-barrel-exports.js.map +1 -0
- package/dist/handlers/generate-files.d.ts +3 -0
- package/dist/handlers/generate-files.d.ts.map +1 -0
- package/dist/handlers/generate-files.js +133 -0
- package/dist/handlers/generate-files.js.map +1 -0
- package/dist/handlers/input-type.d.ts +7 -0
- package/dist/handlers/input-type.d.ts.map +1 -0
- package/dist/handlers/input-type.js +297 -0
- package/dist/handlers/input-type.js.map +1 -0
- package/dist/handlers/model-data.d.ts +3 -0
- package/dist/handlers/model-data.d.ts.map +1 -0
- package/dist/handlers/model-data.js +27 -0
- package/dist/handlers/model-data.js.map +1 -0
- package/dist/handlers/model-output-type.d.ts +3 -0
- package/dist/handlers/model-output-type.d.ts.map +1 -0
- package/dist/handlers/model-output-type.js +283 -0
- package/dist/handlers/model-output-type.js.map +1 -0
- package/dist/handlers/no-atomic-operations.d.ts +3 -0
- package/dist/handlers/no-atomic-operations.d.ts.map +1 -0
- package/dist/handlers/no-atomic-operations.js +41 -0
- package/dist/handlers/no-atomic-operations.js.map +1 -0
- package/dist/handlers/output-type.d.ts +3 -0
- package/dist/handlers/output-type.d.ts.map +1 -0
- package/dist/handlers/output-type.js +179 -0
- package/dist/handlers/output-type.js.map +1 -0
- package/dist/handlers/patch-type-registry.d.ts +16 -0
- package/dist/handlers/patch-type-registry.d.ts.map +1 -0
- package/dist/handlers/patch-type-registry.js +47 -0
- package/dist/handlers/patch-type-registry.js.map +1 -0
- package/dist/handlers/post-process-imports.d.ts +11 -0
- package/dist/handlers/post-process-imports.d.ts.map +1 -0
- package/dist/handlers/post-process-imports.js +44 -0
- package/dist/handlers/post-process-imports.js.map +1 -0
- package/dist/handlers/prisma-enum-doc.d.ts +11 -0
- package/dist/handlers/prisma-enum-doc.d.ts.map +1 -0
- package/dist/handlers/prisma-enum-doc.js +16 -0
- package/dist/handlers/prisma-enum-doc.js.map +1 -0
- package/dist/handlers/purge-output.d.ts +3 -0
- package/dist/handlers/purge-output.d.ts.map +1 -0
- package/dist/handlers/purge-output.js +34 -0
- package/dist/handlers/purge-output.js.map +1 -0
- package/dist/handlers/re-export.d.ts +9 -0
- package/dist/handlers/re-export.d.ts.map +1 -0
- package/dist/handlers/re-export.js +101 -0
- package/dist/handlers/re-export.js.map +1 -0
- package/dist/handlers/register-all-types.d.ts +13 -0
- package/dist/handlers/register-all-types.d.ts.map +1 -0
- package/dist/handlers/register-all-types.js +99 -0
- package/dist/handlers/register-all-types.js.map +1 -0
- package/dist/handlers/register-enum.d.ts +3 -0
- package/dist/handlers/register-enum.d.ts.map +1 -0
- package/dist/handlers/register-enum.js +65 -0
- package/dist/handlers/register-enum.js.map +1 -0
- package/dist/handlers/require-single-fields-in-whereunique-input.d.ts +3 -0
- package/dist/handlers/require-single-fields-in-whereunique-input.d.ts.map +1 -0
- package/dist/handlers/require-single-fields-in-whereunique-input.js +15 -0
- package/dist/handlers/require-single-fields-in-whereunique-input.js.map +1 -0
- package/dist/handlers/type-registry.d.ts +14 -0
- package/dist/handlers/type-registry.d.ts.map +1 -0
- package/dist/handlers/type-registry.js +151 -0
- package/dist/handlers/type-registry.js.map +1 -0
- package/dist/handlers/warning.d.ts +2 -0
- package/dist/handlers/warning.d.ts.map +1 -0
- package/dist/handlers/warning.js +14 -0
- package/dist/handlers/warning.js.map +1 -0
- package/dist/helpers/create-comment.d.ts +3 -0
- package/dist/helpers/create-comment.d.ts.map +1 -0
- package/dist/helpers/create-comment.js +23 -0
- package/dist/helpers/create-comment.js.map +1 -0
- package/dist/helpers/create-config.d.ts +51 -0
- package/dist/helpers/create-config.d.ts.map +1 -0
- package/dist/helpers/create-config.js +165 -0
- package/dist/helpers/create-config.js.map +1 -0
- package/dist/helpers/create-emit-blocks.d.ts +5 -0
- package/dist/helpers/create-emit-blocks.d.ts.map +1 -0
- package/dist/helpers/create-emit-blocks.js +37 -0
- package/dist/helpers/create-emit-blocks.js.map +1 -0
- package/dist/helpers/detect-circular-deps.d.ts +28 -0
- package/dist/helpers/detect-circular-deps.d.ts.map +1 -0
- package/dist/helpers/detect-circular-deps.js +92 -0
- package/dist/helpers/detect-circular-deps.js.map +1 -0
- package/dist/helpers/factory-get-source-file.d.ts +13 -0
- package/dist/helpers/factory-get-source-file.d.ts.map +1 -0
- package/dist/helpers/factory-get-source-file.js +17 -0
- package/dist/helpers/factory-get-source-file.js.map +1 -0
- package/dist/helpers/file-type-by-location.d.ts +3 -0
- package/dist/helpers/file-type-by-location.d.ts.map +1 -0
- package/dist/helpers/file-type-by-location.js +19 -0
- package/dist/helpers/file-type-by-location.js.map +1 -0
- package/dist/helpers/generate-file-name.d.ts +7 -0
- package/dist/helpers/generate-file-name.d.ts.map +1 -0
- package/dist/helpers/generate-file-name.js +35 -0
- package/dist/helpers/generate-file-name.js.map +1 -0
- package/dist/helpers/get-enum-name.d.ts +2 -0
- package/dist/helpers/get-enum-name.d.ts.map +1 -0
- package/dist/helpers/get-enum-name.js +5 -0
- package/dist/helpers/get-enum-name.js.map +1 -0
- package/dist/helpers/get-graphql-import.d.ts +19 -0
- package/dist/helpers/get-graphql-import.d.ts.map +1 -0
- package/dist/helpers/get-graphql-import.js +52 -0
- package/dist/helpers/get-graphql-import.js.map +1 -0
- package/dist/helpers/get-graphql-input-type.d.ts +6 -0
- package/dist/helpers/get-graphql-input-type.d.ts.map +1 -0
- package/dist/helpers/get-graphql-input-type.js +64 -0
- package/dist/helpers/get-graphql-input-type.js.map +1 -0
- package/dist/helpers/get-model-name.d.ts +2 -0
- package/dist/helpers/get-model-name.d.ts.map +1 -0
- package/dist/helpers/get-model-name.js +130 -0
- package/dist/helpers/get-model-name.js.map +1 -0
- package/dist/helpers/get-output-type-name.d.ts +2 -0
- package/dist/helpers/get-output-type-name.d.ts.map +1 -0
- package/dist/helpers/get-output-type-name.js +4 -0
- package/dist/helpers/get-output-type-name.js.map +1 -0
- package/dist/helpers/get-property-type.d.ts +9 -0
- package/dist/helpers/get-property-type.d.ts.map +1 -0
- package/dist/helpers/get-property-type.js +48 -0
- package/dist/helpers/get-property-type.js.map +1 -0
- package/dist/helpers/get-where-unique-at-least-keys.d.ts +3 -0
- package/dist/helpers/get-where-unique-at-least-keys.d.ts.map +1 -0
- package/dist/helpers/get-where-unique-at-least-keys.js +17 -0
- package/dist/helpers/get-where-unique-at-least-keys.js.map +1 -0
- package/dist/helpers/import-declaration-map.d.ts +19 -0
- package/dist/helpers/import-declaration-map.d.ts.map +1 -0
- package/dist/helpers/import-declaration-map.js +69 -0
- package/dist/helpers/import-declaration-map.js.map +1 -0
- package/dist/helpers/is-many-and-return.d.ts +2 -0
- package/dist/helpers/is-many-and-return.d.ts.map +1 -0
- package/dist/helpers/is-many-and-return.js +9 -0
- package/dist/helpers/is-many-and-return.js.map +1 -0
- package/dist/helpers/is-where-unique-input-type.d.ts +2 -0
- package/dist/helpers/is-where-unique-input-type.d.ts.map +1 -0
- package/dist/helpers/is-where-unique-input-type.js +4 -0
- package/dist/helpers/is-where-unique-input-type.js.map +1 -0
- package/dist/helpers/object-settings.d.ts +39 -0
- package/dist/helpers/object-settings.d.ts.map +1 -0
- package/dist/helpers/object-settings.js +297 -0
- package/dist/helpers/object-settings.js.map +1 -0
- package/dist/helpers/pascal-case.d.ts +2 -0
- package/dist/helpers/pascal-case.d.ts.map +1 -0
- package/dist/helpers/pascal-case.js +5 -0
- package/dist/helpers/pascal-case.js.map +1 -0
- package/dist/helpers/property-structure.d.ts +13 -0
- package/dist/helpers/property-structure.d.ts.map +1 -0
- package/dist/helpers/property-structure.js +20 -0
- package/dist/helpers/property-structure.js.map +1 -0
- package/dist/helpers/relative-path.d.ts +2 -0
- package/dist/helpers/relative-path.d.ts.map +1 -0
- package/dist/helpers/relative-path.js +20 -0
- package/dist/helpers/relative-path.js.map +1 -0
- package/dist/helpers/type-safe-assert.d.ts +7 -0
- package/dist/helpers/type-safe-assert.d.ts.map +1 -0
- package/dist/helpers/type-safe-assert.js +10 -0
- package/dist/helpers/type-safe-assert.js.map +1 -0
- package/dist/helpers/update-object-property.d.ts +7 -0
- package/dist/helpers/update-object-property.d.ts.map +1 -0
- package/dist/helpers/update-object-property.js +21 -0
- package/dist/helpers/update-object-property.js.map +1 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +135 -2956
- package/dist/index.js.map +1 -1
- package/dist/test/test-utils.d.ts +4 -0
- package/dist/test/test-utils.d.ts.map +1 -0
- package/dist/test/test-utils.js +14 -0
- package/dist/test/test-utils.js.map +1 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import JSON5 from 'json5';
|
|
2
|
+
import { castArray } from 'lodash-es';
|
|
3
|
+
import pupa from 'pupa';
|
|
4
|
+
import { StructureKind, } from 'ts-morph';
|
|
5
|
+
import { BeforeGenerateField } from '../event-names.js';
|
|
6
|
+
import { getGraphqlImport } from '../helpers/get-graphql-import.js';
|
|
7
|
+
import { getGraphqlInputType } from '../helpers/get-graphql-input-type.js';
|
|
8
|
+
import { getPropertyType } from '../helpers/get-property-type.js';
|
|
9
|
+
import { getWhereUniqueAtLeastKeys } from '../helpers/get-where-unique-at-least-keys.js';
|
|
10
|
+
import { ImportDeclarationMap } from '../helpers/import-declaration-map.js';
|
|
11
|
+
import { isWhereUniqueInputType } from '../helpers/is-where-unique-input-type.js';
|
|
12
|
+
import { propertyStructure } from '../helpers/property-structure.js';
|
|
13
|
+
import { relativePath } from '../helpers/relative-path.js';
|
|
14
|
+
import { ok } from '../helpers/type-safe-assert.js';
|
|
15
|
+
export function inputType(args) {
|
|
16
|
+
const { classDecoratorName, classTransformerTypeModels, config, eventEmitter, fieldSettings, fileType, getModelName, getSourceFile, inputType: inputTypeArg, models, output, removeTypes, typeNames, } = args;
|
|
17
|
+
typeNames.add(inputTypeArg.name);
|
|
18
|
+
const importDeclarations = new ImportDeclarationMap();
|
|
19
|
+
const sourceFile = getSourceFile({
|
|
20
|
+
name: inputTypeArg.name,
|
|
21
|
+
type: fileType,
|
|
22
|
+
});
|
|
23
|
+
const classStructure = {
|
|
24
|
+
decorators: [
|
|
25
|
+
{
|
|
26
|
+
arguments: [],
|
|
27
|
+
name: classDecoratorName,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
isExported: true,
|
|
31
|
+
kind: StructureKind.Class,
|
|
32
|
+
name: inputTypeArg.name,
|
|
33
|
+
properties: [],
|
|
34
|
+
};
|
|
35
|
+
const modelName = getModelName(inputTypeArg.name) ?? '';
|
|
36
|
+
const model = models.get(modelName);
|
|
37
|
+
const modelFieldSettings = model && fieldSettings.get(model.name);
|
|
38
|
+
const moduleSpecifier = '@nestjs/graphql';
|
|
39
|
+
// Track types that need lazy loading due to circular dependencies
|
|
40
|
+
const lazyTypes = new Set();
|
|
41
|
+
importDeclarations
|
|
42
|
+
.set('Field', {
|
|
43
|
+
moduleSpecifier,
|
|
44
|
+
namedImports: [{ name: 'Field' }],
|
|
45
|
+
})
|
|
46
|
+
.set(classDecoratorName, {
|
|
47
|
+
moduleSpecifier,
|
|
48
|
+
namedImports: [{ name: classDecoratorName }],
|
|
49
|
+
});
|
|
50
|
+
// Add type registry imports if ESM compatible mode is enabled
|
|
51
|
+
if (config.esmCompatible) {
|
|
52
|
+
let typeRegistryPath = relativePath(sourceFile.getFilePath(), `${output}/type-registry.ts`);
|
|
53
|
+
// Add .js extension for ESM module resolution
|
|
54
|
+
if (!typeRegistryPath.endsWith('.js')) {
|
|
55
|
+
typeRegistryPath += '.js';
|
|
56
|
+
}
|
|
57
|
+
importDeclarations.add('registerType', typeRegistryPath);
|
|
58
|
+
importDeclarations.add('getType', typeRegistryPath);
|
|
59
|
+
}
|
|
60
|
+
const useInputType = config.useInputType.find(x => inputTypeArg.name.includes(x.typeName));
|
|
61
|
+
const isWhereUnique = isWhereUniqueInputType(inputTypeArg.name);
|
|
62
|
+
for (const field of inputTypeArg.fields) {
|
|
63
|
+
field.inputTypes = field.inputTypes.filter(t => !removeTypes.has(t.type));
|
|
64
|
+
eventEmitter.emitSync(BeforeGenerateField, field, args);
|
|
65
|
+
const { inputTypes, isRequired, name } = field;
|
|
66
|
+
if (inputTypes.length === 0) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const usePattern = useInputType?.ALL ?? useInputType?.[name];
|
|
70
|
+
const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
|
|
71
|
+
const { isList, location, type } = graphqlInputType;
|
|
72
|
+
const typeName = type;
|
|
73
|
+
const settings = modelFieldSettings?.get(name);
|
|
74
|
+
const propertySettings = settings?.getPropertyType({
|
|
75
|
+
input: true,
|
|
76
|
+
name: inputTypeArg.name,
|
|
77
|
+
});
|
|
78
|
+
const modelField = model?.fields.find(f => f.name === name);
|
|
79
|
+
const isCustomsApplicable = typeName === modelField?.type;
|
|
80
|
+
const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
|
|
81
|
+
const whereUniqueInputTypeValue = isWhereUniqueInputType(typeName) &&
|
|
82
|
+
atLeastKeys &&
|
|
83
|
+
`Prisma.AtLeast<${typeName}, ${atLeastKeys.map(n => `'${n}'`).join(' | ')}>`;
|
|
84
|
+
const propertyType = castArray(propertySettings?.name ??
|
|
85
|
+
whereUniqueInputTypeValue ??
|
|
86
|
+
getPropertyType({
|
|
87
|
+
location,
|
|
88
|
+
type: typeName,
|
|
89
|
+
})).filter((p) => typeof p === 'string');
|
|
90
|
+
const hasExclamationToken = Boolean(isWhereUnique &&
|
|
91
|
+
config.unsafeCompatibleWhereUniqueInput &&
|
|
92
|
+
atLeastKeys?.includes(name));
|
|
93
|
+
const property = propertyStructure({
|
|
94
|
+
hasExclamationToken: hasExclamationToken || undefined,
|
|
95
|
+
hasQuestionToken: hasExclamationToken ? false : undefined,
|
|
96
|
+
isList,
|
|
97
|
+
isNullable: !isRequired,
|
|
98
|
+
name,
|
|
99
|
+
propertyType,
|
|
100
|
+
});
|
|
101
|
+
if (classStructure.properties) {
|
|
102
|
+
classStructure.properties.push(property);
|
|
103
|
+
}
|
|
104
|
+
if (propertySettings) {
|
|
105
|
+
importDeclarations.create({ ...propertySettings });
|
|
106
|
+
}
|
|
107
|
+
else if (propertyType.some(p => p.includes('Prisma.Decimal'))) {
|
|
108
|
+
importDeclarations.add('Prisma', config.prismaClientImport);
|
|
109
|
+
}
|
|
110
|
+
else if (propertyType.some(p => p.startsWith('Prisma.'))) {
|
|
111
|
+
importDeclarations.add('Prisma', config.prismaClientImport);
|
|
112
|
+
}
|
|
113
|
+
// Get graphql type
|
|
114
|
+
let graphqlType;
|
|
115
|
+
let useGetType = false;
|
|
116
|
+
const shouldHideField = settings?.shouldHideField({
|
|
117
|
+
input: true,
|
|
118
|
+
name: inputTypeArg.name,
|
|
119
|
+
}) ??
|
|
120
|
+
config.decorate.some(d => d.name === 'HideField' &&
|
|
121
|
+
d.from === moduleSpecifier &&
|
|
122
|
+
d.isMatchField(name) &&
|
|
123
|
+
d.isMatchType(inputTypeArg.name));
|
|
124
|
+
const fieldType = settings?.getFieldType({
|
|
125
|
+
input: true,
|
|
126
|
+
name: inputTypeArg.name,
|
|
127
|
+
});
|
|
128
|
+
if (fieldType && isCustomsApplicable && !shouldHideField) {
|
|
129
|
+
graphqlType = fieldType.name;
|
|
130
|
+
importDeclarations.create({ ...fieldType });
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Import property type class
|
|
134
|
+
const graphqlImport = getGraphqlImport({
|
|
135
|
+
config,
|
|
136
|
+
getSourceFile,
|
|
137
|
+
location,
|
|
138
|
+
sourceFile,
|
|
139
|
+
typeName,
|
|
140
|
+
});
|
|
141
|
+
graphqlType = graphqlImport.name;
|
|
142
|
+
// Extract the actual type name from complex property types like "typeof X | Y"
|
|
143
|
+
if (location === 'enumTypes') {
|
|
144
|
+
const parts = String(propertyType[0]).split(' ');
|
|
145
|
+
const lastPart = parts.at(-1);
|
|
146
|
+
if (lastPart !== undefined) {
|
|
147
|
+
// Use lastPart for enum type resolution
|
|
148
|
+
void lastPart;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// In ESM mode, always use getType() for input object types
|
|
152
|
+
const shouldUseLazyType = config.esmCompatible && location === 'inputObjectTypes';
|
|
153
|
+
// Handle self-references
|
|
154
|
+
if (graphqlImport.name === inputTypeArg.name && shouldUseLazyType) {
|
|
155
|
+
lazyTypes.add(graphqlImport.name);
|
|
156
|
+
useGetType = true;
|
|
157
|
+
}
|
|
158
|
+
else if (graphqlImport.specifier !== null &&
|
|
159
|
+
graphqlImport.specifier !== undefined &&
|
|
160
|
+
!importDeclarations.has(graphqlImport.name) &&
|
|
161
|
+
graphqlImport.name !== inputTypeArg.name) {
|
|
162
|
+
if (shouldUseLazyType) {
|
|
163
|
+
importDeclarations.addType(graphqlImport.name, graphqlImport.specifier);
|
|
164
|
+
lazyTypes.add(graphqlImport.name);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
importDeclarations.set(graphqlImport.name, {
|
|
168
|
+
moduleSpecifier: graphqlImport.specifier,
|
|
169
|
+
namedImports: [{ name: graphqlImport.name }],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Check if this type should use lazy loading
|
|
174
|
+
if (lazyTypes.has(graphqlImport.name)) {
|
|
175
|
+
useGetType = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
ok(property.decorators !== undefined && property.decorators !== null, 'property.decorators is undefined');
|
|
179
|
+
if (shouldHideField) {
|
|
180
|
+
importDeclarations.add('HideField', moduleSpecifier);
|
|
181
|
+
property.decorators.push({ arguments: [], name: 'HideField' });
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
let typeExpression;
|
|
185
|
+
if (useGetType) {
|
|
186
|
+
typeExpression = isList
|
|
187
|
+
? `() => [getType('${graphqlType}')]`
|
|
188
|
+
: `() => getType('${graphqlType}')`;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
typeExpression = isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`;
|
|
192
|
+
}
|
|
193
|
+
property.decorators.push({
|
|
194
|
+
arguments: [
|
|
195
|
+
typeExpression,
|
|
196
|
+
JSON5.stringify({
|
|
197
|
+
...settings?.fieldArguments(),
|
|
198
|
+
nullable: !isRequired,
|
|
199
|
+
}),
|
|
200
|
+
],
|
|
201
|
+
name: 'Field',
|
|
202
|
+
});
|
|
203
|
+
if (graphqlType === 'GraphQLDecimal') {
|
|
204
|
+
// Import from generated decimal-helpers.ts instead of prisma-graphql-type-decimal
|
|
205
|
+
// This provides Prisma 7+ compatibility
|
|
206
|
+
let decimalHelpersPath = relativePath(sourceFile.getFilePath(), `${output}/decimal-helpers.ts`);
|
|
207
|
+
// Add .js extension for ESM module resolution
|
|
208
|
+
if (config.esmCompatible && !decimalHelpersPath.endsWith('.js')) {
|
|
209
|
+
decimalHelpersPath += '.js';
|
|
210
|
+
}
|
|
211
|
+
importDeclarations.add('transformToDecimal', decimalHelpersPath);
|
|
212
|
+
importDeclarations.add('Transform', 'class-transformer');
|
|
213
|
+
importDeclarations.add('Type', 'class-transformer');
|
|
214
|
+
property.decorators.push({
|
|
215
|
+
arguments: ['() => Object'],
|
|
216
|
+
name: 'Type',
|
|
217
|
+
}, {
|
|
218
|
+
arguments: ['transformToDecimal'],
|
|
219
|
+
name: 'Transform',
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else if (location === 'inputObjectTypes' &&
|
|
223
|
+
(modelField?.type === 'Decimal' ||
|
|
224
|
+
[
|
|
225
|
+
'connect',
|
|
226
|
+
'connectOrCreate',
|
|
227
|
+
'create',
|
|
228
|
+
'createMany',
|
|
229
|
+
'data',
|
|
230
|
+
'delete',
|
|
231
|
+
'deleteMany',
|
|
232
|
+
'disconnect',
|
|
233
|
+
'set',
|
|
234
|
+
'update',
|
|
235
|
+
'updateMany',
|
|
236
|
+
'upsert',
|
|
237
|
+
'where',
|
|
238
|
+
].includes(name) ||
|
|
239
|
+
classTransformerTypeModels.has(getModelName(graphqlType) ?? '') ||
|
|
240
|
+
(modelField?.kind === 'object' &&
|
|
241
|
+
models
|
|
242
|
+
.get(modelField.type)
|
|
243
|
+
?.fields.some(f => f.kind === 'object' && classTransformerTypeModels.has(f.type)) === true))) {
|
|
244
|
+
importDeclarations.add('Type', 'class-transformer');
|
|
245
|
+
if (useGetType) {
|
|
246
|
+
property.decorators.push({
|
|
247
|
+
arguments: [`getType('${graphqlType}')`],
|
|
248
|
+
name: 'Type',
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
property.decorators.push({ arguments: [`() => ${graphqlType}`], name: 'Type' });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (isCustomsApplicable) {
|
|
256
|
+
for (const options of settings ?? []) {
|
|
257
|
+
if ((options.kind === 'Decorator' && options.input && options.match?.(name)) ??
|
|
258
|
+
true) {
|
|
259
|
+
property.decorators.push({
|
|
260
|
+
arguments: options.arguments,
|
|
261
|
+
name: options.name,
|
|
262
|
+
});
|
|
263
|
+
ok(options.from !== undefined && options.from !== null && options.from !== '', "Missed 'from' part in configuration or field setting");
|
|
264
|
+
importDeclarations.create(options);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
for (const decorate of config.decorate) {
|
|
269
|
+
if (decorate.isMatchField(name) && decorate.isMatchType(inputTypeArg.name)) {
|
|
270
|
+
property.decorators.push({
|
|
271
|
+
arguments: decorate.arguments?.map(x => pupa(x, { propertyType })),
|
|
272
|
+
name: decorate.name,
|
|
273
|
+
});
|
|
274
|
+
importDeclarations.create(decorate);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
eventEmitter.emitSync('ClassProperty', property, {
|
|
279
|
+
isList,
|
|
280
|
+
location,
|
|
281
|
+
propertyType,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
// Build statements array
|
|
285
|
+
const statements = [
|
|
286
|
+
...importDeclarations.toStatements(),
|
|
287
|
+
classStructure,
|
|
288
|
+
];
|
|
289
|
+
// Add registerType call if ESM compatible mode is enabled
|
|
290
|
+
if (config.esmCompatible) {
|
|
291
|
+
statements.push(`\nregisterType('${inputTypeArg.name}', ${inputTypeArg.name});`);
|
|
292
|
+
}
|
|
293
|
+
sourceFile.set({
|
|
294
|
+
statements,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=input-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-type.js","sourceRoot":"","sources":["../../src/handlers/input-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAGL,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,MAAM,UAAU,SAAS,CACvB,IAIC;IAED,MAAM,EACJ,kBAAkB,EAClB,0BAA0B,EAC1B,M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U;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-data.d.ts","sourceRoot":"","sources":["../../src/handlers/model-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,KAAK,EAAE,MAAM,aAAa,CAAC;AAIhE,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAsClE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createObjectSettings } from '../helpers/object-settings.js';
|
|
2
|
+
export function modelData(model, args) {
|
|
3
|
+
const { classTransformerTypeModels, config, fieldSettings, modelFields, modelNames, models, } = args;
|
|
4
|
+
modelNames.push(model.name);
|
|
5
|
+
models.set(model.name, model);
|
|
6
|
+
const modelFieldsValue = new Map();
|
|
7
|
+
modelFields.set(model.name, modelFieldsValue);
|
|
8
|
+
const fieldSettingsValue = new Map();
|
|
9
|
+
fieldSettings.set(model.name, fieldSettingsValue);
|
|
10
|
+
for (const field of model.fields) {
|
|
11
|
+
if (field.documentation !== null &&
|
|
12
|
+
field.documentation !== undefined &&
|
|
13
|
+
field.documentation.length > 0) {
|
|
14
|
+
const { documentation, settings } = createObjectSettings({
|
|
15
|
+
config,
|
|
16
|
+
text: field.documentation,
|
|
17
|
+
});
|
|
18
|
+
field.documentation = documentation;
|
|
19
|
+
fieldSettingsValue.set(field.name, settings);
|
|
20
|
+
}
|
|
21
|
+
modelFieldsValue.set(field.name, field);
|
|
22
|
+
}
|
|
23
|
+
if (model.fields.some(field => field.type === 'Decimal')) {
|
|
24
|
+
classTransformerTypeModels.add(model.name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=model-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-data.js","sourceRoot":"","sources":["../../src/handlers/model-data.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB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AE,CAAC;QACzD,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-output-type.d.ts","sourceRoot":"","sources":["../../src/handlers/model-output-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA+B9D,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CA2TlF"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import JSON5 from 'json5';
|
|
2
|
+
import { castArray } from 'lodash-es';
|
|
3
|
+
import pupa from 'pupa';
|
|
4
|
+
import { StructureKind, } from 'ts-morph';
|
|
5
|
+
import { createComment } from '../helpers/create-comment.js';
|
|
6
|
+
import { hasCircularDependency } from '../helpers/detect-circular-deps.js';
|
|
7
|
+
import { getGraphqlImport } from '../helpers/get-graphql-import.js';
|
|
8
|
+
import { getOutputTypeName } from '../helpers/get-output-type-name.js';
|
|
9
|
+
import { getPropertyType } from '../helpers/get-property-type.js';
|
|
10
|
+
import { ImportDeclarationMap } from '../helpers/import-declaration-map.js';
|
|
11
|
+
import { isManyAndReturnOutputType } from '../helpers/is-many-and-return.js';
|
|
12
|
+
import { createObjectSettings, } from '../helpers/object-settings.js';
|
|
13
|
+
import { propertyStructure } from '../helpers/property-structure.js';
|
|
14
|
+
import { relativePath } from '../helpers/relative-path.js';
|
|
15
|
+
import { ok } from '../helpers/type-safe-assert.js';
|
|
16
|
+
const nestjsGraphql = '@nestjs/graphql';
|
|
17
|
+
export function modelOutputType(outputType, args) {
|
|
18
|
+
const { circularDependencies, config, eventEmitter, fieldSettings, getSourceFile, modelFields, models, output, } = args;
|
|
19
|
+
if (isManyAndReturnOutputType(outputType.name)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const model = models.get(outputType.name);
|
|
23
|
+
ok(model, `Cannot find model by name ${outputType.name}`);
|
|
24
|
+
const sourceFile = getSourceFile({
|
|
25
|
+
name: outputType.name,
|
|
26
|
+
type: 'model',
|
|
27
|
+
});
|
|
28
|
+
const sourceFileStructure = sourceFile.getStructure();
|
|
29
|
+
const exportDeclaration = getExportDeclaration(model.name, sourceFileStructure.statements);
|
|
30
|
+
const importDeclarations = new ImportDeclarationMap();
|
|
31
|
+
const classStructure = {
|
|
32
|
+
decorators: [
|
|
33
|
+
{
|
|
34
|
+
arguments: [],
|
|
35
|
+
name: 'ObjectType',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
isExported: true,
|
|
39
|
+
kind: StructureKind.Class,
|
|
40
|
+
name: outputType.name,
|
|
41
|
+
properties: [],
|
|
42
|
+
};
|
|
43
|
+
sourceFileStructure.statements.push(classStructure);
|
|
44
|
+
ok(classStructure.decorators, 'classStructure.decorators is undefined');
|
|
45
|
+
const decorator = classStructure.decorators.find(d => d.name === 'ObjectType');
|
|
46
|
+
ok(decorator, 'ObjectType decorator not found');
|
|
47
|
+
let modelSettings;
|
|
48
|
+
// Get model settings from documentation
|
|
49
|
+
if (model.documentation !== null &&
|
|
50
|
+
model.documentation !== undefined &&
|
|
51
|
+
model.documentation.length > 0) {
|
|
52
|
+
const objectTypeOptions = {};
|
|
53
|
+
const { documentation, settings } = createObjectSettings({
|
|
54
|
+
config,
|
|
55
|
+
text: model.documentation,
|
|
56
|
+
});
|
|
57
|
+
if (documentation !== undefined && documentation.length > 0) {
|
|
58
|
+
classStructure.leadingTrivia ??= createComment(documentation);
|
|
59
|
+
objectTypeOptions.description = documentation;
|
|
60
|
+
}
|
|
61
|
+
decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
|
|
62
|
+
modelSettings = settings;
|
|
63
|
+
}
|
|
64
|
+
importDeclarations.add('Field', nestjsGraphql);
|
|
65
|
+
importDeclarations.add('ObjectType', nestjsGraphql);
|
|
66
|
+
// Track types that need lazy loading due to circular dependencies
|
|
67
|
+
const lazyTypes = new Set();
|
|
68
|
+
// Add type registry imports if ESM compatible mode is enabled
|
|
69
|
+
if (config.esmCompatible) {
|
|
70
|
+
let typeRegistryPath = relativePath(sourceFile.getFilePath(), `${output}/type-registry.ts`);
|
|
71
|
+
// Add .js extension for ESM module resolution
|
|
72
|
+
if (!typeRegistryPath.endsWith('.js')) {
|
|
73
|
+
typeRegistryPath += '.js';
|
|
74
|
+
}
|
|
75
|
+
importDeclarations.add('registerType', typeRegistryPath);
|
|
76
|
+
importDeclarations.add('getType', typeRegistryPath);
|
|
77
|
+
}
|
|
78
|
+
for (const field of outputType.fields) {
|
|
79
|
+
if (config.omitModelsCount && field.name === '_count') {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
let fileType = 'model';
|
|
83
|
+
const { isList, location, namespace, type } = field.outputType;
|
|
84
|
+
let outputTypeName = type;
|
|
85
|
+
if (namespace !== 'model') {
|
|
86
|
+
fileType = 'output';
|
|
87
|
+
outputTypeName = getOutputTypeName(outputTypeName);
|
|
88
|
+
}
|
|
89
|
+
const modelField = modelFields.get(model.name)?.get(field.name);
|
|
90
|
+
const settings = fieldSettings.get(model.name)?.get(field.name);
|
|
91
|
+
const fieldType = settings?.getFieldType({
|
|
92
|
+
name: outputType.name,
|
|
93
|
+
output: true,
|
|
94
|
+
});
|
|
95
|
+
const propertySettings = settings?.getPropertyType({
|
|
96
|
+
name: outputType.name,
|
|
97
|
+
output: true,
|
|
98
|
+
});
|
|
99
|
+
const propertyType = castArray(propertySettings?.name ??
|
|
100
|
+
getPropertyType({
|
|
101
|
+
location,
|
|
102
|
+
type: outputTypeName,
|
|
103
|
+
}));
|
|
104
|
+
// For model we keep only one type
|
|
105
|
+
propertyType.splice(1, propertyType.length);
|
|
106
|
+
if (field.isNullable === true && !isList) {
|
|
107
|
+
propertyType.push('null');
|
|
108
|
+
}
|
|
109
|
+
let graphqlType;
|
|
110
|
+
let useGetType = false;
|
|
111
|
+
if (fieldType === undefined) {
|
|
112
|
+
const graphqlImport = getGraphqlImport({
|
|
113
|
+
config,
|
|
114
|
+
fileType,
|
|
115
|
+
getSourceFile,
|
|
116
|
+
isId: modelField?.isId,
|
|
117
|
+
location,
|
|
118
|
+
noTypeId: config.noTypeId,
|
|
119
|
+
sourceFile,
|
|
120
|
+
typeName: outputTypeName,
|
|
121
|
+
});
|
|
122
|
+
graphqlType = graphqlImport.name;
|
|
123
|
+
if (graphqlImport.name !== outputType.name &&
|
|
124
|
+
graphqlImport.specifier !== null &&
|
|
125
|
+
graphqlImport.specifier !== undefined &&
|
|
126
|
+
graphqlImport.specifier.length > 0) {
|
|
127
|
+
// Check for circular dependency in ESM mode
|
|
128
|
+
const isCircular = config.esmCompatible &&
|
|
129
|
+
location === 'outputObjectTypes' &&
|
|
130
|
+
namespace === 'model' &&
|
|
131
|
+
hasCircularDependency(circularDependencies, outputType.name, outputTypeName);
|
|
132
|
+
if (isCircular) {
|
|
133
|
+
// Use regular import (not type-only) so registerType() executes
|
|
134
|
+
importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
|
|
135
|
+
lazyTypes.add(graphqlImport.name);
|
|
136
|
+
useGetType = true;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
importDeclarations.add(graphqlImport.name, graphqlImport.specifier);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
graphqlType = fieldType.name;
|
|
145
|
+
importDeclarations.create({ ...fieldType });
|
|
146
|
+
}
|
|
147
|
+
const property = propertyStructure({
|
|
148
|
+
hasExclamationToken: true,
|
|
149
|
+
hasQuestionToken: location === 'outputObjectTypes',
|
|
150
|
+
isList,
|
|
151
|
+
isNullable: field.isNullable,
|
|
152
|
+
name: field.name,
|
|
153
|
+
propertyType,
|
|
154
|
+
});
|
|
155
|
+
if (typeof property.leadingTrivia === 'string' &&
|
|
156
|
+
modelField?.documentation !== null &&
|
|
157
|
+
modelField?.documentation !== undefined &&
|
|
158
|
+
modelField.documentation.length > 0) {
|
|
159
|
+
property.leadingTrivia += createComment(modelField.documentation, settings);
|
|
160
|
+
}
|
|
161
|
+
if (classStructure.properties !== undefined) {
|
|
162
|
+
classStructure.properties.push(property);
|
|
163
|
+
}
|
|
164
|
+
if (propertySettings !== undefined) {
|
|
165
|
+
importDeclarations.create({ ...propertySettings });
|
|
166
|
+
}
|
|
167
|
+
else if (propertyType.some(p => p.includes('Prisma.Decimal'))) {
|
|
168
|
+
importDeclarations.add('Prisma', config.prismaClientImport);
|
|
169
|
+
}
|
|
170
|
+
ok(property.decorators !== undefined, 'property.decorators is undefined');
|
|
171
|
+
const shouldHideField = settings?.shouldHideField({ name: outputType.name, output: true }) === true ||
|
|
172
|
+
config.decorate.some(d => d.name === 'HideField' &&
|
|
173
|
+
d.from === '@nestjs/graphql' &&
|
|
174
|
+
d.isMatchField(field.name) &&
|
|
175
|
+
d.isMatchType(outputTypeName));
|
|
176
|
+
if (shouldHideField) {
|
|
177
|
+
importDeclarations.add('HideField', nestjsGraphql);
|
|
178
|
+
property.decorators.push({ arguments: [], name: 'HideField' });
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// Generate `@Field()` decorator
|
|
182
|
+
let typeExpression;
|
|
183
|
+
if (useGetType) {
|
|
184
|
+
typeExpression = isList
|
|
185
|
+
? `() => [getType('${graphqlType}')]`
|
|
186
|
+
: `() => getType('${graphqlType}')`;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
typeExpression = isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`;
|
|
190
|
+
}
|
|
191
|
+
property.decorators.push({
|
|
192
|
+
arguments: [
|
|
193
|
+
typeExpression,
|
|
194
|
+
JSON5.stringify({
|
|
195
|
+
...settings?.fieldArguments(),
|
|
196
|
+
defaultValue: ['number', 'string', 'boolean'].includes(typeof modelField?.default)
|
|
197
|
+
? modelField?.default
|
|
198
|
+
: undefined,
|
|
199
|
+
description: modelField?.documentation !== null &&
|
|
200
|
+
modelField?.documentation !== undefined &&
|
|
201
|
+
modelField.documentation !== ''
|
|
202
|
+
? modelField.documentation
|
|
203
|
+
: undefined,
|
|
204
|
+
nullable: Boolean(field.isNullable),
|
|
205
|
+
}),
|
|
206
|
+
],
|
|
207
|
+
name: 'Field',
|
|
208
|
+
});
|
|
209
|
+
for (const setting of settings ?? []) {
|
|
210
|
+
if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
|
|
211
|
+
property.decorators.push({
|
|
212
|
+
arguments: setting.arguments,
|
|
213
|
+
name: setting.name,
|
|
214
|
+
});
|
|
215
|
+
ok(setting.from && setting.from.length > 0, "Missed 'from' part in configuration or field setting");
|
|
216
|
+
importDeclarations.create(setting);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const decorate of config.decorate) {
|
|
220
|
+
if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
|
|
221
|
+
property.decorators.push({
|
|
222
|
+
arguments: decorate.arguments?.map(x => pupa(x, { propertyType })),
|
|
223
|
+
name: decorate.name,
|
|
224
|
+
});
|
|
225
|
+
importDeclarations.create(decorate);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
eventEmitter.emitSync('ClassProperty', property, {
|
|
230
|
+
isList,
|
|
231
|
+
location,
|
|
232
|
+
propertyType,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// Generate class decorators from model settings
|
|
236
|
+
for (const setting of modelSettings ?? []) {
|
|
237
|
+
if (shouldBeDecorated(setting)) {
|
|
238
|
+
classStructure.decorators.push({
|
|
239
|
+
arguments: setting.arguments,
|
|
240
|
+
name: setting.name,
|
|
241
|
+
});
|
|
242
|
+
importDeclarations.create(setting);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// Build statements array
|
|
246
|
+
const statements = [
|
|
247
|
+
...importDeclarations.toStatements(),
|
|
248
|
+
classStructure,
|
|
249
|
+
];
|
|
250
|
+
// Add registerType call if ESM compatible mode is enabled
|
|
251
|
+
if (config.esmCompatible) {
|
|
252
|
+
statements.push(`\nregisterType('${outputType.name}', ${outputType.name});`);
|
|
253
|
+
}
|
|
254
|
+
if (exportDeclaration) {
|
|
255
|
+
sourceFile.set({
|
|
256
|
+
statements: [exportDeclaration, '\n', classStructure],
|
|
257
|
+
});
|
|
258
|
+
const classDeclaration = sourceFile.getClassOrThrow(model.name);
|
|
259
|
+
const commentedText = classDeclaration
|
|
260
|
+
.getText()
|
|
261
|
+
.split('\n')
|
|
262
|
+
.map(x => `// ${x}`);
|
|
263
|
+
classDeclaration.remove();
|
|
264
|
+
sourceFile.addStatements(['\n', ...commentedText]);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
sourceFile.set({
|
|
268
|
+
statements,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function shouldBeDecorated(setting) {
|
|
273
|
+
return (setting.kind === 'Decorator' &&
|
|
274
|
+
(setting.output || setting.model) &&
|
|
275
|
+
!(setting.output && setting.model));
|
|
276
|
+
}
|
|
277
|
+
function getExportDeclaration(name, statements) {
|
|
278
|
+
return statements.find(structure => {
|
|
279
|
+
return (structure.kind === StructureKind.ExportDeclaration &&
|
|
280
|
+
structure.namedExports.some(o => (o.alias ?? o.name) === name));
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=model-output-type.js.map
|