@mikro-orm/entity-generator 7.0.0-dev.23 → 7.0.0-dev.231
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/DefineEntitySourceFile.d.ts +5 -0
- package/DefineEntitySourceFile.js +115 -0
- package/EntityGenerator.d.ts +2 -1
- package/EntityGenerator.js +111 -34
- package/EntitySchemaSourceFile.d.ts +3 -2
- package/EntitySchemaSourceFile.js +47 -36
- package/NativeEnumSourceFile.d.ts +16 -0
- package/NativeEnumSourceFile.js +47 -0
- package/README.md +2 -0
- package/SourceFile.d.ts +4 -1
- package/SourceFile.js +141 -49
- package/package.json +6 -6
- package/tsconfig.build.tsbuildinfo +1 -0
package/SourceFile.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { Cascade, Config, DecimalType, ReferenceKind, SCALAR_TYPES, UnknownType, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { Cascade, Config, DecimalType, ReferenceKind, SCALAR_TYPES, UnknownType, Utils, inspect, } from '@mikro-orm/core';
|
|
2
2
|
import { parse, relative } from 'node:path';
|
|
3
|
-
import { inspect } from 'node:util';
|
|
4
3
|
import { POSSIBLE_TYPE_IMPORTS } from './CoreImportsHelper.js';
|
|
5
4
|
/**
|
|
6
5
|
* @see https://github.com/tc39/proposal-regexp-unicode-property-escapes#other-examples
|
|
7
6
|
*/
|
|
8
7
|
export const identifierRegex = /^(?:[$_\p{ID_Start}])(?:[$\u200C\u200D\p{ID_Continue}])*$/u;
|
|
9
|
-
const primitivesAndLibs = [...SCALAR_TYPES, '
|
|
8
|
+
const primitivesAndLibs = [...SCALAR_TYPES, 'unknown', 'object', 'any'];
|
|
10
9
|
export class SourceFile {
|
|
11
10
|
meta;
|
|
12
11
|
namingStrategy;
|
|
13
12
|
platform;
|
|
14
13
|
options;
|
|
15
14
|
coreImports = new Set();
|
|
15
|
+
decoratorImports = new Set();
|
|
16
16
|
entityImports = new Set();
|
|
17
|
+
enumImports = new Map();
|
|
17
18
|
constructor(meta, namingStrategy, platform, options) {
|
|
18
19
|
this.meta = meta;
|
|
19
20
|
this.namingStrategy = namingStrategy;
|
|
@@ -25,24 +26,24 @@ export class SourceFile {
|
|
|
25
26
|
if (this.meta.embeddable || this.meta.collection) {
|
|
26
27
|
if (this.meta.embeddable) {
|
|
27
28
|
const options = this.getEmbeddableDeclOptions();
|
|
28
|
-
ret += `@${this.
|
|
29
|
+
ret += `@${this.referenceDecoratorImport('Embeddable')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
32
|
const options = this.getEntityDeclOptions();
|
|
32
|
-
ret += `@${this.
|
|
33
|
+
ret += `@${this.referenceDecoratorImport('Entity')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
for (const index of this.meta.indexes) {
|
|
36
37
|
if (index.properties?.length === 1 && typeof this.meta.properties[index.properties[0]] !== 'undefined') {
|
|
37
38
|
continue;
|
|
38
39
|
}
|
|
39
|
-
ret += `@${this.
|
|
40
|
+
ret += `@${this.referenceDecoratorImport('Index')}(${this.serializeObject(this.getIndexOptions(index))})\n`;
|
|
40
41
|
}
|
|
41
42
|
for (const index of this.meta.uniques) {
|
|
42
43
|
if (index.properties?.length === 1 && typeof this.meta.properties[index.properties[0]] !== 'undefined') {
|
|
43
44
|
continue;
|
|
44
45
|
}
|
|
45
|
-
ret += `@${this.
|
|
46
|
+
ret += `@${this.referenceDecoratorImport('Unique')}(${this.serializeObject(this.getUniqueOptions(index))})\n`;
|
|
46
47
|
}
|
|
47
48
|
let classHead = '';
|
|
48
49
|
if (this.meta.className === this.options.customBaseEntityName) {
|
|
@@ -65,7 +66,10 @@ export class SourceFile {
|
|
|
65
66
|
classBody += definition;
|
|
66
67
|
classBody += '\n';
|
|
67
68
|
if (prop.enum) {
|
|
68
|
-
|
|
69
|
+
const def = this.getEnumClassDefinition(prop, 2);
|
|
70
|
+
if (def.length) {
|
|
71
|
+
enumDefinitions.push(def);
|
|
72
|
+
}
|
|
69
73
|
}
|
|
70
74
|
if (prop.eager) {
|
|
71
75
|
eagerProperties.push(prop);
|
|
@@ -141,37 +145,61 @@ export class SourceFile {
|
|
|
141
145
|
return ret;
|
|
142
146
|
}).join(', '))} } from '@mikro-orm/core';`);
|
|
143
147
|
}
|
|
148
|
+
if (this.decoratorImports.size > 0) {
|
|
149
|
+
const type = this.options.decorators;
|
|
150
|
+
imports.add(`import { ${([...this.decoratorImports].sort().map(t => {
|
|
151
|
+
let ret = t;
|
|
152
|
+
if (this.options.coreImportsPrefix) {
|
|
153
|
+
const resolvedIdentifier = `${this.options.coreImportsPrefix}${t}`;
|
|
154
|
+
ret += ` as ${resolvedIdentifier}`;
|
|
155
|
+
}
|
|
156
|
+
return ret;
|
|
157
|
+
}).join(', '))} } from '@mikro-orm/decorators/${type}';`);
|
|
158
|
+
}
|
|
144
159
|
const extension = this.options.esmImport ? '.js' : '';
|
|
145
160
|
const { dir, base } = parse(`${this.options.path ?? '.'}/${this.getBaseName()}`);
|
|
146
161
|
const basePath = relative(dir, this.options.path ?? '.') || '.';
|
|
147
162
|
(this.options.extraImports?.(basePath, base) ?? []).forEach(v => this.entityImports.add(v));
|
|
148
163
|
const entityImports = [...this.entityImports].filter(e => e !== this.meta.className);
|
|
149
|
-
|
|
164
|
+
const importMap = new Map();
|
|
165
|
+
for (const entity of entityImports) {
|
|
150
166
|
const file = this.options.onImport?.(entity, basePath, extension, base) ?? {
|
|
151
167
|
path: `${basePath}/${this.options.fileName(entity)}${extension}`,
|
|
152
168
|
name: entity,
|
|
153
169
|
};
|
|
154
170
|
if (file.path === '') {
|
|
155
171
|
if (file.name === '') {
|
|
156
|
-
|
|
172
|
+
continue;
|
|
157
173
|
}
|
|
158
|
-
|
|
159
|
-
|
|
174
|
+
importMap.set(file.path, `import ${this.quote(file.name)};`);
|
|
175
|
+
continue;
|
|
160
176
|
}
|
|
161
177
|
if (file.name === '') {
|
|
162
|
-
|
|
163
|
-
|
|
178
|
+
importMap.set(file.path, `import * as ${entity} from ${this.quote(file.path)};`);
|
|
179
|
+
continue;
|
|
164
180
|
}
|
|
165
181
|
if (file.name === 'default') {
|
|
166
|
-
|
|
167
|
-
|
|
182
|
+
importMap.set(file.path, `import ${entity} from ${this.quote(file.path)};`);
|
|
183
|
+
continue;
|
|
168
184
|
}
|
|
169
185
|
if (file.name === entity) {
|
|
170
|
-
|
|
171
|
-
|
|
186
|
+
importMap.set(file.path, `import { ${entity} } from ${this.quote(file.path)};`);
|
|
187
|
+
continue;
|
|
172
188
|
}
|
|
173
|
-
|
|
174
|
-
}
|
|
189
|
+
importMap.set(file.path, `import { ${identifierRegex.test(file.name) ? file.name : this.quote(file.name)} as ${entity} } from ${this.quote(file.path)};`);
|
|
190
|
+
}
|
|
191
|
+
if (this.enumImports.size) {
|
|
192
|
+
for (const [name, exports] of this.enumImports.entries()) {
|
|
193
|
+
const file = this.options.onImport?.(name, basePath, extension, base) ?? {
|
|
194
|
+
path: `${basePath}/${this.options.fileName(name)}${extension}`,
|
|
195
|
+
name,
|
|
196
|
+
};
|
|
197
|
+
importMap.set(file.path, `import { ${exports.join(', ')} } from ${this.quote(file.path)};`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const key of [...importMap.keys()].sort()) {
|
|
201
|
+
imports.add(importMap.get(key));
|
|
202
|
+
}
|
|
175
203
|
return Array.from(imports.values()).join('\n');
|
|
176
204
|
}
|
|
177
205
|
getEntityClass(classBody) {
|
|
@@ -181,8 +209,8 @@ export class SourceFile {
|
|
|
181
209
|
}
|
|
182
210
|
ret += `class ${this.meta.className}`;
|
|
183
211
|
if (this.meta.extends) {
|
|
184
|
-
this.entityImports.add(this.meta.extends);
|
|
185
|
-
ret += ` extends ${this.meta.extends}`;
|
|
212
|
+
this.entityImports.add(Utils.className(this.meta.extends));
|
|
213
|
+
ret += ` extends ${Utils.className(this.meta.extends)}`;
|
|
186
214
|
}
|
|
187
215
|
else if (this.options.useCoreBaseEntity) {
|
|
188
216
|
ret += ` extends ${this.referenceCoreImport('BaseEntity')}`;
|
|
@@ -201,6 +229,7 @@ export class SourceFile {
|
|
|
201
229
|
getPropertyDefinition(prop, padLeft) {
|
|
202
230
|
const padding = ' '.repeat(padLeft);
|
|
203
231
|
const propName = identifierRegex.test(prop.name) ? prop.name : this.quote(prop.name);
|
|
232
|
+
const enumMode = this.options.enumMode;
|
|
204
233
|
let hiddenType = '';
|
|
205
234
|
if (prop.hidden) {
|
|
206
235
|
hiddenType += ` & ${this.referenceCoreImport('Hidden')}`;
|
|
@@ -218,7 +247,11 @@ export class SourceFile {
|
|
|
218
247
|
: (() => {
|
|
219
248
|
if (isScalar) {
|
|
220
249
|
if (prop.enum) {
|
|
221
|
-
|
|
250
|
+
const method = enumMode === 'ts-enum' ? 'getEnumClassName' : 'getEnumTypeName';
|
|
251
|
+
if (prop.nativeEnumName) {
|
|
252
|
+
return this.namingStrategy[method](prop.nativeEnumName, undefined, this.meta.schema);
|
|
253
|
+
}
|
|
254
|
+
return this.namingStrategy[method](prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
222
255
|
}
|
|
223
256
|
breakdownOfIType = this.breakdownOfIType(prop);
|
|
224
257
|
if (typeof breakdownOfIType !== 'undefined') {
|
|
@@ -253,8 +286,14 @@ export class SourceFile {
|
|
|
253
286
|
return `${padding}${ret};\n`;
|
|
254
287
|
}
|
|
255
288
|
if (prop.enum && typeof prop.default === 'string') {
|
|
289
|
+
if (enumMode === 'union-type') {
|
|
290
|
+
return `${padding}${ret} = ${this.quote(prop.default)};\n`;
|
|
291
|
+
}
|
|
292
|
+
const enumClassName = prop.nativeEnumName
|
|
293
|
+
? this.namingStrategy.getEnumClassName(prop.nativeEnumName, undefined, this.meta.schema)
|
|
294
|
+
: this.namingStrategy.getEnumClassName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
256
295
|
const enumVal = this.namingStrategy.enumValueToEnumProperty(prop.default, prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
257
|
-
return `${padding}${ret} = ${
|
|
296
|
+
return `${padding}${ret} = ${enumClassName}${identifierRegex.test(enumVal) ? `.${enumVal}` : `[${this.quote(enumVal)}]`};\n`;
|
|
258
297
|
}
|
|
259
298
|
if (prop.fieldNames?.length > 1) {
|
|
260
299
|
// TODO: Composite FKs with default values require additions to default/defaultRaw that are not yet supported.
|
|
@@ -270,15 +309,51 @@ export class SourceFile {
|
|
|
270
309
|
return `${padding}${ret} = ${prop.ref ? this.referenceCoreImport('ref') : this.referenceCoreImport('rel')}(${propType}, ${defaultVal});\n`;
|
|
271
310
|
}
|
|
272
311
|
getEnumClassDefinition(prop, padLeft) {
|
|
312
|
+
const enumMode = this.options.enumMode;
|
|
313
|
+
if (prop.nativeEnumName) {
|
|
314
|
+
const imports = [];
|
|
315
|
+
if (enumMode !== 'union-type') {
|
|
316
|
+
imports.push(prop.runtimeType);
|
|
317
|
+
}
|
|
318
|
+
if (!this.options.inferEntityType && enumMode !== 'ts-enum') {
|
|
319
|
+
const enumTypeName = this.namingStrategy.getEnumTypeName(prop.nativeEnumName, undefined, this.meta.schema);
|
|
320
|
+
imports.push(enumTypeName);
|
|
321
|
+
}
|
|
322
|
+
this.enumImports.set(prop.runtimeType, imports);
|
|
323
|
+
return '';
|
|
324
|
+
}
|
|
273
325
|
const enumClassName = this.namingStrategy.getEnumClassName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
326
|
+
const enumTypeName = this.namingStrategy.getEnumTypeName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
274
327
|
const padding = ' '.repeat(padLeft);
|
|
275
|
-
let ret = `export enum ${enumClassName} {\n`;
|
|
276
328
|
const enumValues = prop.items;
|
|
329
|
+
if (enumMode === 'union-type') {
|
|
330
|
+
return `export type ${enumTypeName} = ${enumValues.map(item => this.quote(item)).join(' | ')};\n`;
|
|
331
|
+
}
|
|
332
|
+
let ret = '';
|
|
333
|
+
if (enumMode === 'dictionary') {
|
|
334
|
+
ret += `export const ${enumClassName} = {\n`;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
ret += `export enum ${enumClassName} {\n`;
|
|
338
|
+
}
|
|
277
339
|
for (const enumValue of enumValues) {
|
|
278
340
|
const enumName = this.namingStrategy.enumValueToEnumProperty(enumValue, prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
279
|
-
|
|
341
|
+
if (enumMode === 'dictionary') {
|
|
342
|
+
ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)}: ${this.quote(enumValue)},\n`;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${this.quote(enumValue)},\n`;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (enumMode === 'dictionary') {
|
|
349
|
+
ret += '} as const;\n';
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
ret += '}\n';
|
|
353
|
+
}
|
|
354
|
+
if (enumMode === 'dictionary') {
|
|
355
|
+
ret += `\nexport type ${enumTypeName} = (typeof ${enumClassName})[keyof typeof ${enumClassName}];\n`;
|
|
280
356
|
}
|
|
281
|
-
ret += '}\n';
|
|
282
357
|
return ret;
|
|
283
358
|
}
|
|
284
359
|
serializeObject(options, wordwrap, spaces, level = 0) {
|
|
@@ -308,8 +383,8 @@ export class SourceFile {
|
|
|
308
383
|
}
|
|
309
384
|
getEntityDeclOptions() {
|
|
310
385
|
const options = {};
|
|
311
|
-
if (this.meta.
|
|
312
|
-
options.tableName = this.quote(this.meta.
|
|
386
|
+
if (this.meta.tableName !== this.namingStrategy.classToTableName(this.meta.className)) {
|
|
387
|
+
options.tableName = this.quote(this.meta.tableName);
|
|
313
388
|
}
|
|
314
389
|
if (this.meta.schema && this.meta.schema !== this.platform.getDefaultSchemaName()) {
|
|
315
390
|
options.schema = this.quote(this.meta.schema);
|
|
@@ -318,7 +393,7 @@ export class SourceFile {
|
|
|
318
393
|
options.expression = this.quote(this.meta.expression);
|
|
319
394
|
}
|
|
320
395
|
else if (typeof this.meta.expression === 'function') {
|
|
321
|
-
options.expression =
|
|
396
|
+
options.expression = this.meta.expression.toString();
|
|
322
397
|
}
|
|
323
398
|
if (this.meta.repositoryClass) {
|
|
324
399
|
this.entityImports.add(this.meta.repositoryClass);
|
|
@@ -351,14 +426,14 @@ export class SourceFile {
|
|
|
351
426
|
}
|
|
352
427
|
if (this.meta.discriminatorMap) {
|
|
353
428
|
options.discriminatorMap = Object.fromEntries(Object.entries(this.meta.discriminatorMap)
|
|
354
|
-
.map(([discriminatorValue,
|
|
429
|
+
.map(([discriminatorValue, cls]) => [discriminatorValue, this.quote(Utils.className(cls))]));
|
|
355
430
|
}
|
|
356
431
|
return options;
|
|
357
432
|
}
|
|
358
433
|
getPropertyDecorator(prop, padLeft) {
|
|
359
434
|
const padding = ' '.repeat(padLeft);
|
|
360
435
|
const options = {};
|
|
361
|
-
let decorator = `@${this.
|
|
436
|
+
let decorator = `@${this.referenceDecoratorImport(this.getDecoratorType(prop))}`;
|
|
362
437
|
if (prop.kind === ReferenceKind.MANY_TO_MANY) {
|
|
363
438
|
this.getManyToManyDecoratorOptions(options, prop);
|
|
364
439
|
}
|
|
@@ -379,7 +454,7 @@ export class SourceFile {
|
|
|
379
454
|
decorator = [...indexes.sort(), decorator].map(d => padding + d).join('\n');
|
|
380
455
|
const decoratorArgs = [];
|
|
381
456
|
if (prop.formula) {
|
|
382
|
-
decoratorArgs.push(
|
|
457
|
+
decoratorArgs.push(prop.formula.toString());
|
|
383
458
|
}
|
|
384
459
|
if (Utils.hasObjectKeys(options)) {
|
|
385
460
|
decoratorArgs.push(`${this.serializeObject(options)}`);
|
|
@@ -408,26 +483,26 @@ export class SourceFile {
|
|
|
408
483
|
let propIndexIsNonTrivialIndex = false;
|
|
409
484
|
const nonTrivialIndexes = this.meta.indexes.filter(i => i.properties?.length === 1 && i.properties[0] === prop.name);
|
|
410
485
|
for (const i of nonTrivialIndexes) {
|
|
411
|
-
ret.push(`@${this.
|
|
486
|
+
ret.push(`@${this.referenceDecoratorImport('Index')}(${this.serializeObject(this.getIndexOptions(i, false))})`);
|
|
412
487
|
if (prop.index === i.name) {
|
|
413
488
|
propIndexIsNonTrivialIndex = true;
|
|
414
489
|
delete options.index;
|
|
415
490
|
}
|
|
416
491
|
}
|
|
417
492
|
if (prop.index && !options.index && !propIndexIsNonTrivialIndex) {
|
|
418
|
-
ret.push(`@${this.
|
|
493
|
+
ret.push(`@${this.referenceDecoratorImport('Index')}(${typeof prop.index === 'string' ? `{ name: ${this.quote(prop.index)} }` : ''})`);
|
|
419
494
|
}
|
|
420
495
|
let propIndexIsNonTrivialUnique = false;
|
|
421
496
|
const nonTrivialUnique = this.meta.uniques.filter(i => i.properties?.length === 1 && i.properties[0] === prop.name);
|
|
422
497
|
for (const i of nonTrivialUnique) {
|
|
423
|
-
ret.push(`@${this.
|
|
498
|
+
ret.push(`@${this.referenceDecoratorImport('Unique')}(${this.serializeObject(this.getUniqueOptions(i, false))})`);
|
|
424
499
|
if (prop.unique === i.name) {
|
|
425
500
|
propIndexIsNonTrivialUnique = true;
|
|
426
501
|
delete options.unique;
|
|
427
502
|
}
|
|
428
503
|
}
|
|
429
504
|
if (prop.unique && !options.unique && !propIndexIsNonTrivialUnique) {
|
|
430
|
-
ret.push(`@${this.
|
|
505
|
+
ret.push(`@${this.referenceDecoratorImport('Unique')}(${typeof prop.unique === 'string' ? `{ name: ${this.quote(prop.unique)} }` : ''})`);
|
|
431
506
|
}
|
|
432
507
|
return ret;
|
|
433
508
|
}
|
|
@@ -438,7 +513,7 @@ export class SourceFile {
|
|
|
438
513
|
if (prop.primary && (prop.enum || !(typeof prop.kind === 'undefined' || prop.kind === ReferenceKind.SCALAR))) {
|
|
439
514
|
options.primary = true;
|
|
440
515
|
}
|
|
441
|
-
['persist', 'hydrate'
|
|
516
|
+
['persist', 'hydrate']
|
|
442
517
|
.filter(key => prop[key] === false)
|
|
443
518
|
.forEach(key => options[key] = false);
|
|
444
519
|
['onCreate', 'onUpdate', 'serializer']
|
|
@@ -537,12 +612,23 @@ export class SourceFile {
|
|
|
537
612
|
this.propTypeBreakdowns.set(prop, r);
|
|
538
613
|
return r;
|
|
539
614
|
}
|
|
540
|
-
getScalarPropertyDecoratorOptions(options, prop) {
|
|
615
|
+
getScalarPropertyDecoratorOptions(options, prop, quote = true) {
|
|
541
616
|
if (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {
|
|
542
617
|
options.fieldName = this.quote(prop.fieldNames[0]);
|
|
543
618
|
}
|
|
544
619
|
if (prop.enum) {
|
|
545
|
-
options.
|
|
620
|
+
if (this.options.enumMode === 'union-type') {
|
|
621
|
+
options.items = `[${prop.items.map(item => this.quote(item)).join(', ')}]`;
|
|
622
|
+
}
|
|
623
|
+
else if (prop.nativeEnumName) {
|
|
624
|
+
const enumClassName = this.namingStrategy.getEnumClassName(prop.nativeEnumName, undefined, this.meta.schema);
|
|
625
|
+
options.items = `() => ${enumClassName}`;
|
|
626
|
+
options.nativeEnumName = this.quote(prop.nativeEnumName);
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
const enumClassName = this.namingStrategy.getEnumClassName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
|
|
630
|
+
options.items = `() => ${enumClassName}`;
|
|
631
|
+
}
|
|
546
632
|
}
|
|
547
633
|
// For enum properties, we don't need a column type
|
|
548
634
|
// or the property length or other information in the decorator.
|
|
@@ -571,7 +657,7 @@ export class SourceFile {
|
|
|
571
657
|
return ((useDefault && !hasUsableNullDefault) || (prop.optional && !prop.nullable));
|
|
572
658
|
})() // also when there is the "| Opt" type modifier (because reflect-metadata can't extract the base)
|
|
573
659
|
) {
|
|
574
|
-
options.type = this.quote(prop.type);
|
|
660
|
+
options.type = quote ? this.quote(prop.type) : prop.type;
|
|
575
661
|
}
|
|
576
662
|
}
|
|
577
663
|
const columnTypeFromMappedRuntimeType = mappedRuntimeType.getColumnType({ ...prop, autoincrement: false }, this.platform);
|
|
@@ -598,7 +684,7 @@ export class SourceFile {
|
|
|
598
684
|
assign('length');
|
|
599
685
|
}
|
|
600
686
|
// those are already included in the `columnType` in most cases, and when that option is present, they would be ignored anyway
|
|
601
|
-
/* v8 ignore next
|
|
687
|
+
/* v8 ignore next */
|
|
602
688
|
if (mappedColumnType instanceof DecimalType && !options.columnType) {
|
|
603
689
|
assign('precision');
|
|
604
690
|
assign('scale');
|
|
@@ -632,12 +718,12 @@ export class SourceFile {
|
|
|
632
718
|
options.mappedBy = this.quote(prop.mappedBy);
|
|
633
719
|
return;
|
|
634
720
|
}
|
|
635
|
-
if (prop.pivotTable !== this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name)) {
|
|
721
|
+
if (prop.pivotTable !== this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name, this.meta.tableName)) {
|
|
636
722
|
options.pivotTable = this.quote(prop.pivotTable);
|
|
637
723
|
}
|
|
638
|
-
if (prop.pivotEntity && prop.pivotEntity !== prop.pivotTable) {
|
|
639
|
-
this.entityImports.add(prop.pivotEntity);
|
|
640
|
-
options.pivotEntity = `() => ${prop.pivotEntity}`;
|
|
724
|
+
if (prop.pivotEntity && Utils.className(prop.pivotEntity) !== prop.pivotTable) {
|
|
725
|
+
this.entityImports.add(Utils.className(prop.pivotEntity));
|
|
726
|
+
options.pivotEntity = `() => ${Utils.className(prop.pivotEntity)}`;
|
|
641
727
|
}
|
|
642
728
|
if (prop.joinColumns.length === 1) {
|
|
643
729
|
options.joinColumn = this.quote(prop.joinColumns[0]);
|
|
@@ -672,7 +758,7 @@ export class SourceFile {
|
|
|
672
758
|
if (prop.array) {
|
|
673
759
|
options.array = true;
|
|
674
760
|
}
|
|
675
|
-
if (prop.object) {
|
|
761
|
+
if (prop.object && !prop.array) {
|
|
676
762
|
options.object = true;
|
|
677
763
|
}
|
|
678
764
|
if (prop.prefix === false || typeof prop.prefix === 'string') {
|
|
@@ -705,10 +791,10 @@ export class SourceFile {
|
|
|
705
791
|
if (prop.ownColumns && prop.ownColumns.length !== prop.fieldNames.length) {
|
|
706
792
|
options.referencedColumnNames = prop.referencedColumnNames.map(fieldName => this.quote(fieldName));
|
|
707
793
|
}
|
|
708
|
-
if (
|
|
794
|
+
if (prop.updateRule) {
|
|
709
795
|
options.updateRule = this.quote(prop.updateRule);
|
|
710
796
|
}
|
|
711
|
-
if (
|
|
797
|
+
if (prop.deleteRule) {
|
|
712
798
|
options.deleteRule = this.quote(prop.deleteRule);
|
|
713
799
|
}
|
|
714
800
|
if (prop.primary) {
|
|
@@ -755,4 +841,10 @@ export class SourceFile {
|
|
|
755
841
|
? `${this.options.coreImportsPrefix}${identifier}`
|
|
756
842
|
: identifier;
|
|
757
843
|
}
|
|
844
|
+
referenceDecoratorImport(identifier) {
|
|
845
|
+
this.decoratorImports.add(identifier);
|
|
846
|
+
return this.options.coreImportsPrefix
|
|
847
|
+
? `${this.options.coreImportsPrefix}${identifier}`
|
|
848
|
+
: identifier;
|
|
849
|
+
}
|
|
758
850
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.231",
|
|
5
5
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://mikro-orm.io",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">= 22.
|
|
41
|
+
"node": ">= 22.17.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "yarn
|
|
44
|
+
"build": "yarn compile && yarn copy",
|
|
45
45
|
"clean": "yarn run -T rimraf ./dist",
|
|
46
46
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/
|
|
53
|
+
"@mikro-orm/sql": "7.0.0-dev.231"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@mikro-orm/core": "^6.
|
|
56
|
+
"@mikro-orm/core": "^6.6.4"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.0.0-dev.231"
|
|
60
60
|
}
|
|
61
61
|
}
|