@solidstarters/solid-code-builder 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/code-builder/index.js +21 -8
- package/dist/code-builder/index.js.map +1 -1
- package/dist/code-builder/lib/field/FieldManager.d.ts +1 -1
- package/dist/code-builder/lib/field/FieldManager.js +14 -1
- package/dist/code-builder/lib/field/FieldManager.js.map +1 -1
- package/dist/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.d.ts +4 -0
- package/dist/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js +44 -2
- package/dist/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js.map +1 -1
- package/dist/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js +1 -1
- package/dist/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +18 -9
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +6 -5
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +5 -5
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +5 -4
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +5 -6
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js.map +1 -1
- package/dist/code-builder/lib/model/helpers.d.ts +3 -0
- package/dist/code-builder/lib/model/helpers.js +8 -3
- package/dist/code-builder/lib/model/helpers.js.map +1 -1
- package/dist/files/generate-model/entities/__model@dasherize__.entity.ts +2 -2
- package/dist/files/generate-model/services/__model@dasherize__.service.ts +8 -7
- package/dist/files/generate-module/__name@dasherize__.module.ts +4 -0
- package/files/generate-model/entities/__model@dasherize__.entity.ts +2 -2
- package/files/generate-model/services/__model@dasherize__.service.ts +8 -7
- package/files/generate-module/__name@dasherize__.module.ts +4 -0
- package/package.json +2 -2
- package/src/code-builder/index.ts +31 -11
- package/src/code-builder/lib/field/FieldManager.ts +15 -1
- package/src/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.ts +75 -2
- package/src/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.ts +1 -1
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.ts +18 -11
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.ts +6 -5
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.ts +6 -5
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.ts +6 -4
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.ts +6 -6
- package/src/code-builder/lib/model/helpers.ts +7 -2
- package/solidstarters-solid-code-builder-1.0.1.tgz +0 -0
|
@@ -9,6 +9,9 @@ interface JoinTableDecoratorOptions {
|
|
|
9
9
|
field: any;
|
|
10
10
|
fieldName: string;
|
|
11
11
|
modelName: string;
|
|
12
|
+
relationJoinTableName: string;
|
|
13
|
+
relationTableModelName: string;
|
|
14
|
+
relationTableModelNameInverse: string;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
export class JoinTableDecoratorManager implements DecoratorManager {
|
|
@@ -35,7 +38,7 @@ export class JoinTableDecoratorManager implements DecoratorManager {
|
|
|
35
38
|
// changes.push(decoratorImport);
|
|
36
39
|
// }
|
|
37
40
|
fieldSourceLines.push(
|
|
38
|
-
`@${this.decoratorName()}()`,
|
|
41
|
+
`@${this.decoratorName()}(${this.buildRelationOptionsCode()})`,
|
|
39
42
|
);
|
|
40
43
|
changes.push(...this.decoratorImports());
|
|
41
44
|
|
|
@@ -92,14 +95,84 @@ export class JoinTableDecoratorManager implements DecoratorManager {
|
|
|
92
95
|
return [updatedProperty, changes];
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
private buildRelationOptionsCode(): string {
|
|
99
|
+
const options: Record<string, string | Record<string, string>> = {};
|
|
100
|
+
|
|
101
|
+
// Add 'name' attribute
|
|
102
|
+
options['name'] = this.options.relationJoinTableName
|
|
103
|
+
? `"${this.options.relationJoinTableName}"`
|
|
104
|
+
: `"${this.options.fieldName}"`;
|
|
105
|
+
|
|
106
|
+
// Add 'joinColumn' attribute
|
|
107
|
+
options['joinColumn'] = {
|
|
108
|
+
name: `"${this.options.relationTableModelName ? `${this.options.relationTableModelName}_id` : `${this.options.fieldName}_id`}"`,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Add 'inverseJoinColumn' attribute
|
|
112
|
+
options['inverseJoinColumn'] = {
|
|
113
|
+
name: `"${this.options.relationTableModelNameInverse ? `${this.options.relationTableModelNameInverse}_id` : `${this.options.fieldName}_id`}"`,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return `{ ${Object.entries(options)
|
|
117
|
+
.map(([key, value]) => {
|
|
118
|
+
if (typeof value === 'string') {
|
|
119
|
+
return `${key}: ${value}`;
|
|
120
|
+
}
|
|
121
|
+
const nestedOptions = Object.entries(value)
|
|
122
|
+
.map(([nestedKey, nestedValue]) => `${nestedKey}: ${nestedValue}`)
|
|
123
|
+
.join(', ');
|
|
124
|
+
return `${key}: { ${nestedOptions} }`;
|
|
125
|
+
})
|
|
126
|
+
.join(', ')} }`;
|
|
127
|
+
}
|
|
128
|
+
|
|
95
129
|
private createDecorator(existingDecorator: ts.Decorator | undefined): ts.Decorator {
|
|
96
130
|
let existingRelationOptions: ts.ObjectLiteralElementLike[] = this.existingDecoratorOptions(existingDecorator);
|
|
97
131
|
|
|
98
132
|
// const mergedRelationOptions: ObjectLiteralElementLike[] = this.mergeNewAndExistingDecoratorOptions(existingRelationOptions);
|
|
99
133
|
|
|
134
|
+
const newRelationOptions: ts.ObjectLiteralElementLike[] = [
|
|
135
|
+
ts.factory.createPropertyAssignment(
|
|
136
|
+
'name',
|
|
137
|
+
ts.factory.createStringLiteral(
|
|
138
|
+
this.options.relationJoinTableName
|
|
139
|
+
? `${this.options.relationJoinTableName}`
|
|
140
|
+
: `${this.options.fieldName}`
|
|
141
|
+
)
|
|
142
|
+
),
|
|
143
|
+
ts.factory.createPropertyAssignment(
|
|
144
|
+
'joinColumn',
|
|
145
|
+
ts.factory.createObjectLiteralExpression([
|
|
146
|
+
ts.factory.createPropertyAssignment(
|
|
147
|
+
'name',
|
|
148
|
+
ts.factory.createStringLiteral(
|
|
149
|
+
this.options.relationTableModelName ? `${this.options.relationTableModelName}_id` : `${this.options.fieldName}_id`)
|
|
150
|
+
)
|
|
151
|
+
])
|
|
152
|
+
),
|
|
153
|
+
ts.factory.createPropertyAssignment(
|
|
154
|
+
'inverseJoinColumn',
|
|
155
|
+
ts.factory.createObjectLiteralExpression([
|
|
156
|
+
ts.factory.createPropertyAssignment(
|
|
157
|
+
'name',
|
|
158
|
+
ts.factory.createStringLiteral(
|
|
159
|
+
this.options.relationTableModelNameInverse ? `${this.options.relationTableModelNameInverse}_id` : `${this.options.fieldName}_id`)
|
|
160
|
+
)
|
|
161
|
+
])
|
|
162
|
+
),
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
// Merge existing and new options, avoiding duplicates
|
|
166
|
+
const mergedRelationOptions = [
|
|
167
|
+
...existingRelationOptions.filter(
|
|
168
|
+
(option) => !(ts.isPropertyAssignment(option) && option.name.getText() === 'name')
|
|
169
|
+
),
|
|
170
|
+
...newRelationOptions,
|
|
171
|
+
];
|
|
172
|
+
|
|
100
173
|
// Re-create the decorator with the merged decorator options
|
|
101
174
|
const decoratorIdentifier = ts.factory.createIdentifier(this.decoratorName());
|
|
102
|
-
const argumentsArray: ts.Expression[] = this.createDecoratorArguments(
|
|
175
|
+
const argumentsArray: ts.Expression[] = this.createDecoratorArguments(mergedRelationOptions);
|
|
103
176
|
const call = ts.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
104
177
|
return ts.factory.createDecorator(call)
|
|
105
178
|
}
|
|
@@ -55,7 +55,7 @@ export class UniqueIndexDecoratorManager {
|
|
|
55
55
|
const existingUniqueIndexDecorator = this.findUniqueIndexDecorator(existingModifiers);
|
|
56
56
|
|
|
57
57
|
//Remove the Index decorator if the Index decorator exists
|
|
58
|
-
newModifiers = [...this.filterOtherDecorators(this.decoratorName(), existingModifiers), ...this.filterOtherIndexDecorators(this.decoratorName(), this.options, existingModifiers)
|
|
58
|
+
newModifiers = [...this.filterNonDecorators(existingModifiers),...this.filterOtherDecorators(this.decoratorName(), existingModifiers), ...this.filterOtherIndexDecorators(this.decoratorName(), this.options, existingModifiers)];
|
|
59
59
|
|
|
60
60
|
//Add the column decorator if column decorator is required
|
|
61
61
|
const changes: Change[] = [];
|
|
@@ -48,7 +48,6 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
48
48
|
tree,
|
|
49
49
|
`src/${dasherize(moduleName)}/entities/${dasherize(modelName)}.entity.ts`,
|
|
50
50
|
);
|
|
51
|
-
// this.relationInverseSource = createSourceFile(tree, `src/${dasherize(this.field.relationModelSingularName)}/dtos/create-${dasherize(this.field.relationModelSingularName)}.dto.ts`)
|
|
52
51
|
|
|
53
52
|
const fieldPropertyDeclarationNode = this.getFieldIdentifierNode(
|
|
54
53
|
this.fieldName(),
|
|
@@ -105,6 +104,9 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
105
104
|
field: this.field,
|
|
106
105
|
fieldName: this.fieldName(),
|
|
107
106
|
modelName: this.modelName,
|
|
107
|
+
relationJoinTableName: this.field.relationJoinTableName,
|
|
108
|
+
relationTableModelName: this.field.relationTableModelName,
|
|
109
|
+
relationTableModelNameInverse: this. field.relationTableModelNameInverse
|
|
108
110
|
},
|
|
109
111
|
);
|
|
110
112
|
this.uniqueIndexDecoratorManager = new UniqueIndexDecoratorManager(
|
|
@@ -258,16 +260,21 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
258
260
|
updatedPropertyDeclarationNode = updatedPropertyDeclarationNodeTransformed;
|
|
259
261
|
changes.push(...decoratorChanges);
|
|
260
262
|
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
// Currently additional field support is only limited to relation fields for entities, so there is no need to update the class nodes
|
|
264
|
+
// Since unique index decorator supported is only for fields which are not relation fields.
|
|
265
|
+
// Also the current additional field algorithm is not able to deal with the class where the primary field operations modifies the class node
|
|
266
|
+
if (!this.isAdditionalFieldRequired()) {
|
|
267
|
+
// Update the property declaration node in the class hierarchy with the updated property declaration node
|
|
268
|
+
// Then calculate the replace changes
|
|
269
|
+
this.uniqueIndexDecoratorManager.setFieldNode(updatedPropertyDeclarationNode);
|
|
270
|
+
// Apply the unique index decorator changes at the class node level
|
|
271
|
+
const [updatedClassNode, uniqueIndexDecoratorChanges] = this.uniqueIndexDecoratorChanges();
|
|
272
|
+
changes.push(...uniqueIndexDecoratorChanges);
|
|
273
|
+
changes.push(...this.calculateReplaceChanges(this.printNode(updatedClassNode, source), this.getClassNode(this.modelName, source), source)); //FIXME: avoid this.modelName to passed in for avoiding statefullness
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
changes.push (...this.calculateReplaceChanges(this.printNode(updatedPropertyDeclarationNode, source), fieldPropertyDeclarationNode, source));
|
|
277
|
+
}
|
|
271
278
|
return {
|
|
272
279
|
filePath: source.fileName,
|
|
273
280
|
field: field,
|
package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.ts
CHANGED
|
@@ -4,10 +4,10 @@ import ts, { PropertyDeclaration } from '@schematics/angular/third_party/github.
|
|
|
4
4
|
import { Change } from '@schematics/angular/utility/change';
|
|
5
5
|
import { ArrayDecoratorManager } from '../../decorator-managers/dto/ArrayDecoratorManager';
|
|
6
6
|
import { OptionalDecoratorManager } from '../../decorator-managers/dto/OptionalDecoratorManager';
|
|
7
|
+
import { StringDecoratorManager } from '../../decorator-managers/dto/StringDecoratorManager';
|
|
7
8
|
import { TransformDecoratorManager } from '../../decorator-managers/dto/TransformDecoratorManager';
|
|
8
9
|
import { DecoratorManager, DecoratorType, DtoSourceType, FieldChange, FieldManager, FieldType, ManagerForDtoOptions, createSourceFile, safeInsertImport } from '../../FieldManager';
|
|
9
10
|
import { BaseFieldManagerForDto } from '../base/BaseFieldManagerForDto';
|
|
10
|
-
import { StringDecoratorManager } from '../../decorator-managers/dto/StringDecoratorManager';
|
|
11
11
|
|
|
12
12
|
export class ManyToManyRelationFieldManagerForDto
|
|
13
13
|
extends BaseFieldManagerForDto
|
|
@@ -191,10 +191,11 @@ export class ManyToManyRelationFieldManagerForDto
|
|
|
191
191
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
private inverseFieldImport(modelName: string,
|
|
194
|
+
private inverseFieldImport(modelName: string, currentModuleName: string, source: ts.SourceFile): Change {
|
|
195
195
|
const inverseEntityImportName = `update-${dasherize(modelName)}.dto`;
|
|
196
|
-
const
|
|
197
|
-
|
|
196
|
+
const modulePath = `src/${currentModuleName}`;
|
|
197
|
+
const inverseEntityPath = `${modulePath}/dtos/${inverseEntityImportName}`;
|
|
198
|
+
return safeInsertImport(source, `Update${classify(modelName)}Dto`, inverseEntityPath, currentModuleName);
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
private addAdditionalInverseField() : FieldChange {
|
|
@@ -439,7 +440,7 @@ export class ManyToManyRelationFieldManagerForDto
|
|
|
439
440
|
relatedFieldImport(): Change {
|
|
440
441
|
const relatedEntityImportName = `update-${dasherize(this.field.relationModelSingularName)}.dto`;
|
|
441
442
|
const relatedEntityPath = this.field.relationModelModuleName ? `src/${this.field.relationModelModuleName}/dtos/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
|
|
442
|
-
return safeInsertImport(this.source, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
|
|
443
|
+
return safeInsertImport(this.source, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath, this.moduleName);
|
|
443
444
|
// return insertImport(this.source, this.source.fileName, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
|
|
444
445
|
} //Uncomment this method while implementing many-to-many relation changes
|
|
445
446
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { classify, dasherize } from '@angular-devkit/core/src/utils/strings';
|
|
2
2
|
import { Tree } from '@angular-devkit/schematics';
|
|
3
3
|
import ts, { PropertyDeclaration } from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
4
|
-
import { insertImport } from '@schematics/angular/utility/ast-utils';
|
|
5
4
|
import { Change } from '@schematics/angular/utility/change';
|
|
6
5
|
import { ManyToManyDecoratorManager } from '../../decorator-managers/entity/ManyToManyDecoratorManager';
|
|
7
6
|
import { OneToManyDecoratorManager } from '../../decorator-managers/entity/OneToManyDecoratorManager';
|
|
@@ -90,7 +89,7 @@ export class ManyToManyRelationFieldManagerForEntity
|
|
|
90
89
|
relatedFieldImport(): Change {
|
|
91
90
|
const relatedEntityImportName = `${dasherize(this.field.relationModelSingularName)}.entity`;
|
|
92
91
|
const relatedEntityPath = this.field.relationModelModuleName ? `src/${dasherize(this.field.relationModelModuleName)}/entities/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
|
|
93
|
-
return
|
|
92
|
+
return safeInsertImport(this.source, classify(this.field.relationModelSingularName), relatedEntityPath, this.moduleName);
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
override removeAdditionalField(): FieldChange {
|
|
@@ -137,11 +136,13 @@ export class ManyToManyRelationFieldManagerForEntity
|
|
|
137
136
|
return fieldChange;
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
private inverseFieldImport(modelName: string,
|
|
139
|
+
private inverseFieldImport(modelName: string, currentModuleName: string, source: ts.SourceFile): Change {
|
|
141
140
|
const inverseEntityImportName = `${dasherize(modelName)}.entity`;
|
|
142
|
-
const
|
|
141
|
+
const modulePath = `src/${currentModuleName}`;
|
|
142
|
+
|
|
143
|
+
const inverseEntityPath = `${modulePath}/entities/${inverseEntityImportName}`;
|
|
143
144
|
|
|
144
|
-
return safeInsertImport(source, `${classify(modelName)}`, inverseEntityPath);
|
|
145
|
+
return safeInsertImport(source, `${classify(modelName)}`, inverseEntityPath, currentModuleName);
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
override addOrUpdateAdditionalField(): FieldChange[] {
|
package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.ts
CHANGED
|
@@ -4,10 +4,10 @@ import ts, { PropertyDeclaration } from '@schematics/angular/third_party/github.
|
|
|
4
4
|
import { Change } from '@schematics/angular/utility/change';
|
|
5
5
|
import { ArrayDecoratorManager } from '../../decorator-managers/dto/ArrayDecoratorManager';
|
|
6
6
|
import { OptionalDecoratorManager } from '../../decorator-managers/dto/OptionalDecoratorManager';
|
|
7
|
+
import { StringDecoratorManager } from '../../decorator-managers/dto/StringDecoratorManager';
|
|
7
8
|
import { TransformDecoratorManager } from '../../decorator-managers/dto/TransformDecoratorManager';
|
|
8
9
|
import { DecoratorManager, DecoratorType, DtoSourceType, FieldChange, FieldManager, FieldType, ManagerForDtoOptions, createSourceFile, safeInsertImport } from '../../FieldManager';
|
|
9
10
|
import { BaseFieldManagerForDto } from '../base/BaseFieldManagerForDto';
|
|
10
|
-
import { StringDecoratorManager } from '../../decorator-managers/dto/StringDecoratorManager';
|
|
11
11
|
|
|
12
12
|
export class ManyToOneRelationFieldManagerForDto
|
|
13
13
|
extends BaseFieldManagerForDto
|
|
@@ -305,11 +305,13 @@ export class ManyToOneRelationFieldManagerForDto
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
private inverseFieldImport(modelName: string,
|
|
308
|
+
private inverseFieldImport(modelName: string, currentModuleName: string, source: ts.SourceFile): Change {
|
|
309
309
|
const inverseEntityImportName = `update-${dasherize(modelName)}.dto`;
|
|
310
|
-
const
|
|
310
|
+
const modulePath = `src/${currentModuleName}`;
|
|
311
|
+
|
|
312
|
+
const inverseEntityPath = `${modulePath}/dtos/${inverseEntityImportName}`;
|
|
311
313
|
|
|
312
|
-
return safeInsertImport(source, `Update${classify(modelName)}Dto`, inverseEntityPath);
|
|
314
|
+
return safeInsertImport(source, `Update${classify(modelName)}Dto`, inverseEntityPath, currentModuleName);
|
|
313
315
|
}
|
|
314
316
|
|
|
315
317
|
override removeAdditionalField(): FieldChange[] {
|
package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { classify, dasherize } from '@angular-devkit/core/src/utils/strings';
|
|
2
2
|
import { Tree } from '@angular-devkit/schematics';
|
|
3
3
|
import ts, { PropertyDeclaration } from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
4
|
-
import { insertImport } from '@schematics/angular/utility/ast-utils';
|
|
5
4
|
import { Change } from '@schematics/angular/utility/change';
|
|
6
5
|
import { OneToManyDecoratorManager } from '../../decorator-managers/entity/OneToManyDecoratorManager';
|
|
7
6
|
import { DecoratorManager, FieldChange, FieldManager, FieldType, RelationType, createSourceFile, safeInsertImport } from '../../FieldManager';
|
|
@@ -29,7 +28,6 @@ export class ManyToOneRelationFieldManagerForEntity
|
|
|
29
28
|
relatedEntityPath,
|
|
30
29
|
);
|
|
31
30
|
|
|
32
|
-
// this.relationInverseSource = createSourceFile(tree, `src/${dasherize(this.field.relationModelSingularName)}/entities/${dasherize(this.field.relationModelSingularName)}.entity.ts`)
|
|
33
31
|
this.oneToManyDecoratorManager = new OneToManyDecoratorManager(
|
|
34
32
|
{
|
|
35
33
|
isOneToMany: this.isOneToMany(),
|
|
@@ -113,7 +111,7 @@ export class ManyToOneRelationFieldManagerForEntity
|
|
|
113
111
|
relatedFieldImport(): Change {
|
|
114
112
|
const relatedEntityImportName = `${dasherize(this.field.relationModelSingularName)}.entity`;
|
|
115
113
|
const relatedEntityPath = this.field.relationModelModuleName ? `src/${dasherize(this.field.relationModelModuleName)}/entities/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
|
|
116
|
-
return
|
|
114
|
+
return safeInsertImport(this.source, classify(this.field.relationModelSingularName), relatedEntityPath, this.moduleName);
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
private isOneToMany(): boolean {
|
|
@@ -164,10 +162,12 @@ export class ManyToOneRelationFieldManagerForEntity
|
|
|
164
162
|
return fieldChange;
|
|
165
163
|
}
|
|
166
164
|
|
|
167
|
-
private inverseFieldImport(modelName: string,
|
|
165
|
+
private inverseFieldImport(modelName: string, currentModuleName: string, source: ts.SourceFile): Change {
|
|
168
166
|
const inverseEntityImportName = `${dasherize(modelName)}.entity`;
|
|
169
|
-
const
|
|
170
|
-
|
|
167
|
+
const modulePath = `src/${currentModuleName}`;
|
|
168
|
+
|
|
169
|
+
const inverseEntityPath = `${modulePath}/entities/${inverseEntityImportName}`;
|
|
170
|
+
return safeInsertImport(source, classify(modelName), inverseEntityPath, currentModuleName);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
override addOrUpdateAdditionalField(): FieldChange[] {
|
|
@@ -5,6 +5,8 @@ import ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/
|
|
|
5
5
|
import { insertImport } from '@schematics/angular/utility/ast-utils';
|
|
6
6
|
import { Change, InsertChange } from '@schematics/angular/utility/change';
|
|
7
7
|
import * as crypto from 'crypto';
|
|
8
|
+
export const SOLID_CORE_MODULE_NAME = 'solid-core';
|
|
9
|
+
export const SOLID_CORE_MODULE_NPM_PACKAGE_NAME = '@solidstarters/solid-core';
|
|
8
10
|
|
|
9
11
|
import {
|
|
10
12
|
FieldChange,
|
|
@@ -199,7 +201,7 @@ export function loadModuleMetadata(tree: Tree, moduleName: string) : ModuleMetad
|
|
|
199
201
|
}
|
|
200
202
|
|
|
201
203
|
function getModuleMetadataFilePath(moduleName: string) {
|
|
202
|
-
if (
|
|
204
|
+
if (moduleName === SOLID_CORE_MODULE_NAME) {
|
|
203
205
|
return `src/${moduleName}/seeders/seed-data/${moduleName}-metadata.json`
|
|
204
206
|
}
|
|
205
207
|
else {
|
|
@@ -393,7 +395,6 @@ export function handleUpdateChecksums(tree: any, moduleName: string, ...filePath
|
|
|
393
395
|
// Refer -> https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
|
|
394
396
|
// https://learning-notes.mistermicheels.com/javascript/typescript/compiler-api/
|
|
395
397
|
export function removeUnusedImports(tree: Tree, filePath: string): string {
|
|
396
|
-
// const sourceFile = createSourceFile(tree, filePath);
|
|
397
398
|
const sourceCode = tree.readText(filePath);
|
|
398
399
|
// const compilerOptions = {
|
|
399
400
|
// getScriptFileNames: () => [filePath],
|
|
@@ -478,4 +479,8 @@ export function takeBackupIfChecksumsMismatch(tree: Tree, moduleName: string) {
|
|
|
478
479
|
createBackup(tree, filePath, fileContent);
|
|
479
480
|
}
|
|
480
481
|
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function calculateModuleFileImportPath(moduleName: string, internalPath: string) {
|
|
485
|
+
return (moduleName === SOLID_CORE_MODULE_NAME) ? internalPath : SOLID_CORE_MODULE_NPM_PACKAGE_NAME;
|
|
481
486
|
}
|
|
Binary file
|