typeorm-dto-generator 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +156 -0
- package/dist/index.d.ts +133 -52
- package/dist/index.js +833 -768
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +803 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +27 -9
- package/dist/.tsbuildinfo +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -43
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as ts_morph from 'ts-morph';
|
|
2
|
+
import { Project, SourceFile, ClassDeclaration, PropertyDeclaration } from 'ts-morph';
|
|
3
|
+
import * as typeorm from 'typeorm';
|
|
4
|
+
import { DataSource } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
type Config = {
|
|
7
|
+
datasource: DataSource;
|
|
8
|
+
debug: boolean;
|
|
9
|
+
dtoOutputDir: string;
|
|
10
|
+
mapperOutputFile: string;
|
|
11
|
+
sharedDTOImportPath: string;
|
|
12
|
+
excludePropertyNames: string[];
|
|
13
|
+
customScalarTypeMap: Record<string, string>;
|
|
14
|
+
includeExtensionOnImports: boolean;
|
|
15
|
+
};
|
|
16
|
+
type InitConfig = Partial<Config> & {
|
|
17
|
+
test: any;
|
|
18
|
+
datasource: DataSource;
|
|
19
|
+
};
|
|
20
|
+
type EntityMeta = {
|
|
21
|
+
className: string;
|
|
22
|
+
dtoName: string;
|
|
23
|
+
moduleName: string;
|
|
24
|
+
dtoFileName: string;
|
|
25
|
+
mapperName: string;
|
|
26
|
+
filePath?: string;
|
|
27
|
+
columns: ColumnMeta[];
|
|
28
|
+
relations: RelationMeta[];
|
|
29
|
+
};
|
|
30
|
+
type ColumnMeta = {
|
|
31
|
+
name: string;
|
|
32
|
+
optional: boolean;
|
|
33
|
+
type: string;
|
|
34
|
+
isDate: boolean;
|
|
35
|
+
mapAsNumber?: boolean;
|
|
36
|
+
enumValues?: (string | number)[];
|
|
37
|
+
};
|
|
38
|
+
type RelationMeta = {
|
|
39
|
+
name: string;
|
|
40
|
+
targetClassName: string;
|
|
41
|
+
targetDTOName: string;
|
|
42
|
+
isArray: boolean;
|
|
43
|
+
nullable: boolean;
|
|
44
|
+
};
|
|
45
|
+
type GenerateResult = {
|
|
46
|
+
metas: EntityMeta[];
|
|
47
|
+
dtoOutputDir: string;
|
|
48
|
+
mapperOutputFile: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type RuntimeColumn = {
|
|
52
|
+
propertyName: string;
|
|
53
|
+
type: unknown;
|
|
54
|
+
enum?: (string | number)[];
|
|
55
|
+
enumName?: string;
|
|
56
|
+
isNullable: boolean;
|
|
57
|
+
isSelect: boolean;
|
|
58
|
+
relationMetadata?: unknown;
|
|
59
|
+
};
|
|
60
|
+
type RuntimeRelation = {
|
|
61
|
+
propertyName: string;
|
|
62
|
+
inverseEntityMetadata: RuntimeEntityMetadata;
|
|
63
|
+
isManyToMany: boolean;
|
|
64
|
+
isOneToMany: boolean;
|
|
65
|
+
isNullable: boolean;
|
|
66
|
+
};
|
|
67
|
+
type RuntimeEntityMetadata = {
|
|
68
|
+
target: Function | string;
|
|
69
|
+
name: string;
|
|
70
|
+
columns: RuntimeColumn[];
|
|
71
|
+
relations: RuntimeRelation[];
|
|
72
|
+
};
|
|
73
|
+
type EntitySourceInfo = {
|
|
74
|
+
filePath?: string;
|
|
75
|
+
enumTypeByProperty: Map<string, string>;
|
|
76
|
+
typeByProperty: Map<string, string>;
|
|
77
|
+
};
|
|
78
|
+
declare class TORMDTOGenerator {
|
|
79
|
+
readonly config: Config;
|
|
80
|
+
protected readonly project: Project;
|
|
81
|
+
protected readonly sourceInfoByClassName: Map<string, EntitySourceInfo>;
|
|
82
|
+
constructor(config: InitConfig);
|
|
83
|
+
run(): Promise<GenerateResult>;
|
|
84
|
+
protected log(message: string): void;
|
|
85
|
+
protected createConfig(config: InitConfig): Config;
|
|
86
|
+
protected writeFile(filePath: string, content: string): void;
|
|
87
|
+
protected toKebabCase(value: string): string;
|
|
88
|
+
protected unique<T>(items: T[]): T[];
|
|
89
|
+
protected createRelativeJSImportPath(fromFile: string, targetFile: string): string;
|
|
90
|
+
protected getCommonTypesFilePath(): string;
|
|
91
|
+
protected getCommonTypesImportSpecifier(dtoFilePath: string): string;
|
|
92
|
+
protected getDatasourceEntities(): (string | Function | typeorm.EntitySchema<any>)[];
|
|
93
|
+
protected normalizeEntityPattern(pattern: string): string;
|
|
94
|
+
protected isSourceFilePath(filePath: string): boolean;
|
|
95
|
+
protected isEntitySourceFilePath(filePath: string): boolean;
|
|
96
|
+
protected normalizeAbsolutePath(filePath: string): string;
|
|
97
|
+
protected isIgnoredSourcePath(filePath: string): boolean;
|
|
98
|
+
protected discoverProjectSourcePaths(): string[];
|
|
99
|
+
protected addEntityOptionSourceFiles(): SourceFile[];
|
|
100
|
+
protected addDiscoveredSourceFiles(): SourceFile[];
|
|
101
|
+
protected loadEntitySourceInfo(): void;
|
|
102
|
+
protected isEntityClass(classDeclaration: ClassDeclaration): boolean;
|
|
103
|
+
protected getDecoratorObjectLiteral(property: PropertyDeclaration): ts_morph.ObjectLiteralExpression | null;
|
|
104
|
+
protected getColumnEnumInitializer(property: PropertyDeclaration): string | null;
|
|
105
|
+
protected getEnumTypeNameFromProperty(property: PropertyDeclaration): string | null;
|
|
106
|
+
protected collectEnumTypesByProperty(classDeclaration: ClassDeclaration): Map<string, string>;
|
|
107
|
+
protected cleanTypeText(value: string): string;
|
|
108
|
+
protected collectTypesByProperty(classDeclaration: ClassDeclaration): Map<string, string>;
|
|
109
|
+
protected collectProperties(classDeclaration: ClassDeclaration, visitedClassNames?: Set<string>): PropertyDeclaration[];
|
|
110
|
+
protected getClassName(target: Function | string, fallback: string): string;
|
|
111
|
+
protected ensureDatasourceMetadata(): Promise<void>;
|
|
112
|
+
protected isExcludedColumn(column: RuntimeColumn): boolean;
|
|
113
|
+
protected isDateColumn(column: RuntimeColumn): boolean;
|
|
114
|
+
protected isJsonColumn(column: RuntimeColumn): boolean;
|
|
115
|
+
protected resolveEnumTypeName(entityName: string, column: RuntimeColumn): string;
|
|
116
|
+
protected resolveSourcePropertyType(entityName: string, propertyName: string): string | null;
|
|
117
|
+
protected resolveColumnType(entityName: string, column: RuntimeColumn): string;
|
|
118
|
+
protected appendNullType(typeText: string): string;
|
|
119
|
+
protected columnToMeta(entityName: string, column: RuntimeColumn): ColumnMeta;
|
|
120
|
+
protected relationToMeta(relation: RuntimeRelation): RelationMeta;
|
|
121
|
+
protected createEntityMetas(): Promise<{
|
|
122
|
+
className: string;
|
|
123
|
+
dtoName: string;
|
|
124
|
+
moduleName: string;
|
|
125
|
+
dtoFileName: string;
|
|
126
|
+
mapperName: string;
|
|
127
|
+
filePath: string | undefined;
|
|
128
|
+
columns: ColumnMeta[];
|
|
129
|
+
relations: RelationMeta[];
|
|
130
|
+
}[]>;
|
|
131
|
+
protected findMetaByClassName(metas: EntityMeta[], className: string): EntityMeta | undefined;
|
|
132
|
+
protected getValidRelations(meta: EntityMeta, metas: EntityMeta[]): RelationMeta[];
|
|
133
|
+
protected createDTOContent(meta: EntityMeta, metas: EntityMeta[]): string;
|
|
134
|
+
protected collectExternalTypeImports(meta: EntityMeta, dtoFilePath: string, relationTypeNames: Set<string>): [string, string][];
|
|
135
|
+
protected collectExternalTypeSymbols(meta: EntityMeta, relationTypeNames: Set<string>): Set<string>;
|
|
136
|
+
protected collectAllExternalTypeSymbols(metas: EntityMeta[]): Set<string>;
|
|
137
|
+
protected findTypeDeclarationByName(typeName: string): ts_morph.InterfaceDeclaration | ts_morph.EnumDeclaration | ts_morph.TypeAliasDeclaration | null;
|
|
138
|
+
protected findEnumDeclarationByName(typeName: string): ts_morph.EnumDeclaration | null;
|
|
139
|
+
protected normalizeDeclarationToExportText(typeName: string, preferEnum?: boolean): string | null;
|
|
140
|
+
protected formatEnumKey(value: string | number): string;
|
|
141
|
+
protected formatEnumValue(value: string | number): string;
|
|
142
|
+
protected createCommonEnumDeclaration(typeName: string, values: (string | number)[]): string;
|
|
143
|
+
protected ensureCommonTypesFile(metas: EntityMeta[]): void;
|
|
144
|
+
protected resolveCommonTypesSourceContent(): string | null;
|
|
145
|
+
protected validateCommonTypeCoverage(metas: EntityMeta[]): void;
|
|
146
|
+
protected createDTOIndexContent(metas: EntityMeta[]): string;
|
|
147
|
+
protected getMetasWithFilePath(metas: EntityMeta[]): EntityMeta[];
|
|
148
|
+
protected createEntityImports(metas: EntityMeta[]): string;
|
|
149
|
+
protected getMapperEntityTypeName(meta: EntityMeta): string;
|
|
150
|
+
protected createStructuralEntityTypes(metas: EntityMeta[]): string;
|
|
151
|
+
protected createGeneratedMapperContent(metas: EntityMeta[]): string;
|
|
152
|
+
protected createMapperFunctionContent(meta: EntityMeta, metas: EntityMeta[]): string;
|
|
153
|
+
protected createRelationMapperLine(relation: RelationMeta, metas: EntityMeta[]): string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { TORMDTOGenerator };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,75 +1,156 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as ts_morph from 'ts-morph';
|
|
2
|
+
import { Project, SourceFile, ClassDeclaration, PropertyDeclaration } from 'ts-morph';
|
|
3
|
+
import * as typeorm from 'typeorm';
|
|
4
|
+
import { DataSource } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
type Config = {
|
|
7
|
+
datasource: DataSource;
|
|
8
|
+
debug: boolean;
|
|
9
|
+
dtoOutputDir: string;
|
|
10
|
+
mapperOutputFile: string;
|
|
11
|
+
sharedDTOImportPath: string;
|
|
12
|
+
excludePropertyNames: string[];
|
|
13
|
+
customScalarTypeMap: Record<string, string>;
|
|
14
|
+
includeExtensionOnImports: boolean;
|
|
15
|
+
};
|
|
16
|
+
type InitConfig = Partial<Config> & {
|
|
17
|
+
test: any;
|
|
18
|
+
datasource: DataSource;
|
|
19
|
+
};
|
|
20
|
+
type EntityMeta = {
|
|
21
|
+
className: string;
|
|
22
|
+
dtoName: string;
|
|
23
|
+
moduleName: string;
|
|
24
|
+
dtoFileName: string;
|
|
25
|
+
mapperName: string;
|
|
26
|
+
filePath?: string;
|
|
27
|
+
columns: ColumnMeta[];
|
|
28
|
+
relations: RelationMeta[];
|
|
29
|
+
};
|
|
30
|
+
type ColumnMeta = {
|
|
31
|
+
name: string;
|
|
32
|
+
optional: boolean;
|
|
33
|
+
type: string;
|
|
34
|
+
isDate: boolean;
|
|
35
|
+
mapAsNumber?: boolean;
|
|
36
|
+
enumValues?: (string | number)[];
|
|
37
|
+
};
|
|
38
|
+
type RelationMeta = {
|
|
39
|
+
name: string;
|
|
40
|
+
targetClassName: string;
|
|
41
|
+
targetDTOName: string;
|
|
42
|
+
isArray: boolean;
|
|
43
|
+
nullable: boolean;
|
|
44
|
+
};
|
|
45
|
+
type GenerateResult = {
|
|
46
|
+
metas: EntityMeta[];
|
|
47
|
+
dtoOutputDir: string;
|
|
48
|
+
mapperOutputFile: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type RuntimeColumn = {
|
|
52
|
+
propertyName: string;
|
|
53
|
+
type: unknown;
|
|
54
|
+
enum?: (string | number)[];
|
|
55
|
+
enumName?: string;
|
|
56
|
+
isNullable: boolean;
|
|
57
|
+
isSelect: boolean;
|
|
58
|
+
relationMetadata?: unknown;
|
|
59
|
+
};
|
|
60
|
+
type RuntimeRelation = {
|
|
61
|
+
propertyName: string;
|
|
62
|
+
inverseEntityMetadata: RuntimeEntityMetadata;
|
|
63
|
+
isManyToMany: boolean;
|
|
64
|
+
isOneToMany: boolean;
|
|
65
|
+
isNullable: boolean;
|
|
66
|
+
};
|
|
67
|
+
type RuntimeEntityMetadata = {
|
|
68
|
+
target: Function | string;
|
|
69
|
+
name: string;
|
|
70
|
+
columns: RuntimeColumn[];
|
|
71
|
+
relations: RuntimeRelation[];
|
|
72
|
+
};
|
|
73
|
+
type EntitySourceInfo = {
|
|
74
|
+
filePath?: string;
|
|
75
|
+
enumTypeByProperty: Map<string, string>;
|
|
76
|
+
typeByProperty: Map<string, string>;
|
|
77
|
+
};
|
|
78
|
+
declare class TORMDTOGenerator {
|
|
79
|
+
readonly config: Config;
|
|
5
80
|
protected readonly project: Project;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
81
|
+
protected readonly sourceInfoByClassName: Map<string, EntitySourceInfo>;
|
|
82
|
+
constructor(config: InitConfig);
|
|
83
|
+
run(): Promise<GenerateResult>;
|
|
84
|
+
protected log(message: string): void;
|
|
85
|
+
protected createConfig(config: InitConfig): Config;
|
|
9
86
|
protected writeFile(filePath: string, content: string): void;
|
|
10
87
|
protected toKebabCase(value: string): string;
|
|
11
88
|
protected unique<T>(items: T[]): T[];
|
|
12
|
-
protected cleanTypeText(value: string): string;
|
|
13
89
|
protected createRelativeJSImportPath(fromFile: string, targetFile: string): string;
|
|
14
90
|
protected getCommonTypesFilePath(): string;
|
|
15
91
|
protected getCommonTypesImportSpecifier(dtoFilePath: string): string;
|
|
16
|
-
protected
|
|
17
|
-
protected
|
|
92
|
+
protected getDatasourceEntities(): (string | Function | typeorm.EntitySchema<any>)[];
|
|
93
|
+
protected normalizeEntityPattern(pattern: string): string;
|
|
94
|
+
protected isSourceFilePath(filePath: string): boolean;
|
|
95
|
+
protected isEntitySourceFilePath(filePath: string): boolean;
|
|
96
|
+
protected normalizeAbsolutePath(filePath: string): string;
|
|
97
|
+
protected isIgnoredSourcePath(filePath: string): boolean;
|
|
98
|
+
protected discoverProjectSourcePaths(): string[];
|
|
99
|
+
protected addEntityOptionSourceFiles(): SourceFile[];
|
|
100
|
+
protected addDiscoveredSourceFiles(): SourceFile[];
|
|
101
|
+
protected loadEntitySourceInfo(): void;
|
|
18
102
|
protected isEntityClass(classDeclaration: ClassDeclaration): boolean;
|
|
19
|
-
protected
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
22
|
-
protected
|
|
23
|
-
protected
|
|
24
|
-
protected
|
|
25
|
-
protected isExcludedProperty(property: PropertyDeclaration): boolean;
|
|
26
|
-
protected isColumnProperty(property: PropertyDeclaration): boolean;
|
|
27
|
-
protected isRelationProperty(property: PropertyDeclaration): boolean;
|
|
103
|
+
protected getDecoratorObjectLiteral(property: PropertyDeclaration): ts_morph.ObjectLiteralExpression | null;
|
|
104
|
+
protected getColumnEnumInitializer(property: PropertyDeclaration): string | null;
|
|
105
|
+
protected getEnumTypeNameFromProperty(property: PropertyDeclaration): string | null;
|
|
106
|
+
protected collectEnumTypesByProperty(classDeclaration: ClassDeclaration): Map<string, string>;
|
|
107
|
+
protected cleanTypeText(value: string): string;
|
|
108
|
+
protected collectTypesByProperty(classDeclaration: ClassDeclaration): Map<string, string>;
|
|
28
109
|
protected collectProperties(classDeclaration: ClassDeclaration, visitedClassNames?: Set<string>): PropertyDeclaration[];
|
|
29
|
-
protected
|
|
30
|
-
protected
|
|
31
|
-
protected
|
|
32
|
-
protected
|
|
33
|
-
protected
|
|
34
|
-
protected
|
|
35
|
-
protected
|
|
36
|
-
protected
|
|
37
|
-
protected resolveEnumType(type: Type): string | null;
|
|
38
|
-
protected resolveEnumTypeFromProperty(property: PropertyDeclaration): string | null;
|
|
39
|
-
protected findEnumDeclarationByName(enumName: string): import("ts-morph").EnumDeclaration | null;
|
|
40
|
-
protected unwrapNullishType(typeText: string): string;
|
|
41
|
-
protected resolveSingleColumnType(type: Type, fallback: string): string;
|
|
42
|
-
protected resolveColumnType(property: PropertyDeclaration): string;
|
|
43
|
-
protected resolveAccessorType(accessor: GetAccessorDeclaration): string;
|
|
110
|
+
protected getClassName(target: Function | string, fallback: string): string;
|
|
111
|
+
protected ensureDatasourceMetadata(): Promise<void>;
|
|
112
|
+
protected isExcludedColumn(column: RuntimeColumn): boolean;
|
|
113
|
+
protected isDateColumn(column: RuntimeColumn): boolean;
|
|
114
|
+
protected isJsonColumn(column: RuntimeColumn): boolean;
|
|
115
|
+
protected resolveEnumTypeName(entityName: string, column: RuntimeColumn): string;
|
|
116
|
+
protected resolveSourcePropertyType(entityName: string, propertyName: string): string | null;
|
|
117
|
+
protected resolveColumnType(entityName: string, column: RuntimeColumn): string;
|
|
44
118
|
protected appendNullType(typeText: string): string;
|
|
45
|
-
protected
|
|
46
|
-
protected
|
|
47
|
-
protected
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
119
|
+
protected columnToMeta(entityName: string, column: RuntimeColumn): ColumnMeta;
|
|
120
|
+
protected relationToMeta(relation: RuntimeRelation): RelationMeta;
|
|
121
|
+
protected createEntityMetas(): Promise<{
|
|
122
|
+
className: string;
|
|
123
|
+
dtoName: string;
|
|
124
|
+
moduleName: string;
|
|
125
|
+
dtoFileName: string;
|
|
126
|
+
mapperName: string;
|
|
127
|
+
filePath: string | undefined;
|
|
128
|
+
columns: ColumnMeta[];
|
|
129
|
+
relations: RelationMeta[];
|
|
130
|
+
}[]>;
|
|
55
131
|
protected findMetaByClassName(metas: EntityMeta[], className: string): EntityMeta | undefined;
|
|
56
132
|
protected getValidRelations(meta: EntityMeta, metas: EntityMeta[]): RelationMeta[];
|
|
57
133
|
protected createDTOContent(meta: EntityMeta, metas: EntityMeta[]): string;
|
|
58
134
|
protected collectExternalTypeImports(meta: EntityMeta, dtoFilePath: string, relationTypeNames: Set<string>): [string, string][];
|
|
59
135
|
protected collectExternalTypeSymbols(meta: EntityMeta, relationTypeNames: Set<string>): Set<string>;
|
|
60
136
|
protected collectAllExternalTypeSymbols(metas: EntityMeta[]): Set<string>;
|
|
61
|
-
protected findTypeDeclarationByName(typeName: string):
|
|
62
|
-
protected
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
protected
|
|
137
|
+
protected findTypeDeclarationByName(typeName: string): ts_morph.InterfaceDeclaration | ts_morph.EnumDeclaration | ts_morph.TypeAliasDeclaration | null;
|
|
138
|
+
protected findEnumDeclarationByName(typeName: string): ts_morph.EnumDeclaration | null;
|
|
139
|
+
protected normalizeDeclarationToExportText(typeName: string, preferEnum?: boolean): string | null;
|
|
140
|
+
protected formatEnumKey(value: string | number): string;
|
|
141
|
+
protected formatEnumValue(value: string | number): string;
|
|
142
|
+
protected createCommonEnumDeclaration(typeName: string, values: (string | number)[]): string;
|
|
67
143
|
protected ensureCommonTypesFile(metas: EntityMeta[]): void;
|
|
68
|
-
protected
|
|
144
|
+
protected resolveCommonTypesSourceContent(): string | null;
|
|
69
145
|
protected validateCommonTypeCoverage(metas: EntityMeta[]): void;
|
|
70
146
|
protected createDTOIndexContent(metas: EntityMeta[]): string;
|
|
147
|
+
protected getMetasWithFilePath(metas: EntityMeta[]): EntityMeta[];
|
|
148
|
+
protected createEntityImports(metas: EntityMeta[]): string;
|
|
149
|
+
protected getMapperEntityTypeName(meta: EntityMeta): string;
|
|
150
|
+
protected createStructuralEntityTypes(metas: EntityMeta[]): string;
|
|
71
151
|
protected createGeneratedMapperContent(metas: EntityMeta[]): string;
|
|
72
152
|
protected createMapperFunctionContent(meta: EntityMeta, metas: EntityMeta[]): string;
|
|
73
153
|
protected createRelationMapperLine(relation: RelationMeta, metas: EntityMeta[]): string;
|
|
74
154
|
}
|
|
75
|
-
|
|
155
|
+
|
|
156
|
+
export { TORMDTOGenerator };
|