@mikro-orm/entity-generator 6.3.5-dev.8 → 6.3.5
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 +2 -1
- package/SourceFile.d.ts +2 -0
- package/SourceFile.js +53 -34
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
143
143
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
144
|
- [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate)
|
|
145
145
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
|
-
- [Lifecycle Hooks](https://mikro-orm.io/docs/
|
|
146
|
+
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
147
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
148
148
|
- [Schema Generator](https://mikro-orm.io/docs/schema-generator)
|
|
149
149
|
- [Entity Generator](https://mikro-orm.io/docs/entity-generator)
|
|
@@ -163,6 +163,7 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
|
|
|
163
163
|
- [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs)
|
|
164
164
|
- [Accounts.js REST and GraphQL authentication + SQLite](https://github.com/darkbasic/mikro-orm-accounts-example)
|
|
165
165
|
- [Nest + Shopify + PostgreSQL + GraphQL](https://github.com/Cloudshelf/Shopify_CSConnector)
|
|
166
|
+
- [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
|
|
166
167
|
|
|
167
168
|
### JavaScript Examples
|
|
168
169
|
|
package/SourceFile.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare class SourceFile {
|
|
|
28
28
|
private getPropertyDecorator;
|
|
29
29
|
protected getPropertyIndexes(prop: EntityProperty, options: Dictionary): string[];
|
|
30
30
|
protected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
31
|
+
private propTypeBreakdowns;
|
|
32
|
+
private breakdownOfIType;
|
|
31
33
|
protected getScalarPropertyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
32
34
|
protected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
33
35
|
protected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
package/SourceFile.js
CHANGED
|
@@ -215,31 +215,16 @@ class SourceFile {
|
|
|
215
215
|
if (prop.enum) {
|
|
216
216
|
return prop.runtimeType;
|
|
217
217
|
}
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
? this.platform.getMappedType(prop.columnTypes[0])
|
|
221
|
-
: mappedDeclaredType));
|
|
222
|
-
const rawType = mappedRawType.runtimeType;
|
|
223
|
-
const serializedType = (prop.customType ?? mappedRawType).runtimeType;
|
|
224
|
-
// Add non-lib imports where needed.
|
|
225
|
-
for (const typeSpec of [prop.runtimeType, rawType, serializedType]) {
|
|
226
|
-
const simplePropType = typeSpec.replace(/\[]+$/, '');
|
|
227
|
-
if (!primitivesAndLibs.includes(simplePropType)) {
|
|
228
|
-
this.entityImports.add(simplePropType);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (prop.runtimeType !== rawType || rawType !== serializedType) {
|
|
218
|
+
const breakdownOfIType = this.breakdownOfIType(prop);
|
|
219
|
+
if (typeof breakdownOfIType !== 'undefined') {
|
|
232
220
|
hasITypeWrapper = true;
|
|
233
|
-
|
|
234
|
-
return `${this.referenceCoreImport('IType')}<${prop.runtimeType}, ${rawType}, ${serializedType}>`;
|
|
235
|
-
}
|
|
236
|
-
return `${this.referenceCoreImport('IType')}<${prop.runtimeType}, ${rawType}>`;
|
|
221
|
+
return `${this.referenceCoreImport('IType')}<${breakdownOfIType.join(', ')}>`;
|
|
237
222
|
}
|
|
238
223
|
return prop.runtimeType;
|
|
239
224
|
}
|
|
240
225
|
return prop.type;
|
|
241
226
|
})();
|
|
242
|
-
const useDefault = prop.default != null;
|
|
227
|
+
const useDefault = prop.default != null && (propType !== 'unknown');
|
|
243
228
|
const optional = prop.nullable ? '?' : (useDefault ? '' : '!');
|
|
244
229
|
let ret = `${propName}${optional}: ${prop.ref ? `${this.referenceCoreImport('Ref')}<${propType}>` : `${(this.options.esmImport && !isScalar) ? `${this.referenceCoreImport('Rel')}<${propType}>` : propType}`}`;
|
|
245
230
|
if (prop.array && (prop.kind === core_1.ReferenceKind.EMBEDDED || prop.enum)) {
|
|
@@ -249,7 +234,7 @@ class SourceFile {
|
|
|
249
234
|
if (useDefault || (prop.optional && !prop.nullable)) {
|
|
250
235
|
ret += ` & ${this.referenceCoreImport('Opt')}`;
|
|
251
236
|
}
|
|
252
|
-
if (!useDefault || hasITypeWrapper) {
|
|
237
|
+
if (!useDefault || hasITypeWrapper || prop.type === 'unknown') {
|
|
253
238
|
return `${padding}${ret};\n`;
|
|
254
239
|
}
|
|
255
240
|
if (prop.enum && typeof prop.default === 'string') {
|
|
@@ -462,15 +447,7 @@ class SourceFile {
|
|
|
462
447
|
prop.defaultRaw !== (typeof prop.default === 'string' ? this.quote(prop.default) : `${prop.default}`)) {
|
|
463
448
|
options.defaultRaw = `\`${prop.defaultRaw}\``;
|
|
464
449
|
}
|
|
465
|
-
else if (prop.default != null && (prop.ref || (!prop.enum && (typeof prop.kind === 'undefined' || prop.kind === core_1.ReferenceKind.SCALAR) && (()
|
|
466
|
-
const mappedDeclaredType = this.platform.getMappedType(prop.type);
|
|
467
|
-
const mappedRawType = (prop.customTypes?.[0] ?? ((prop.type !== 'unknown' && mappedDeclaredType instanceof core_1.UnknownType)
|
|
468
|
-
? this.platform.getMappedType(prop.columnTypes[0])
|
|
469
|
-
: mappedDeclaredType));
|
|
470
|
-
const rawType = mappedRawType.runtimeType;
|
|
471
|
-
const serializedType = (prop.customType ?? mappedRawType).runtimeType;
|
|
472
|
-
return prop.runtimeType !== rawType || rawType !== serializedType;
|
|
473
|
-
})()))) {
|
|
450
|
+
else if (prop.default != null && (prop.ref || (!prop.enum && (typeof prop.kind === 'undefined' || prop.kind === core_1.ReferenceKind.SCALAR) && (prop.type === 'unknown' || typeof this.breakdownOfIType(prop) !== 'undefined')))) {
|
|
474
451
|
options.default = typeof prop.default === 'string' ? this.quote(prop.default) : prop.default;
|
|
475
452
|
}
|
|
476
453
|
}
|
|
@@ -480,6 +457,42 @@ class SourceFile {
|
|
|
480
457
|
if (prop.deferMode) {
|
|
481
458
|
options.deferMode = `${this.referenceCoreImport('DeferMode')}.INITIALLY_${prop.deferMode.toUpperCase()}`;
|
|
482
459
|
}
|
|
460
|
+
if (typeof prop.ignoreSchemaChanges !== 'undefined') {
|
|
461
|
+
options.ignoreSchemaChanges ??= [];
|
|
462
|
+
options.ignoreSchemaChanges.push(...prop.ignoreSchemaChanges.map(v => this.quote(v)));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
propTypeBreakdowns = new WeakMap();
|
|
466
|
+
breakdownOfIType(prop) {
|
|
467
|
+
if (this.propTypeBreakdowns.has(prop)) {
|
|
468
|
+
return this.propTypeBreakdowns.get(prop);
|
|
469
|
+
}
|
|
470
|
+
const mappedDeclaredType = this.platform.getMappedType(prop.type);
|
|
471
|
+
const mappedRawType = (prop.customTypes?.[0] ?? ((prop.type !== 'unknown' && mappedDeclaredType instanceof core_1.UnknownType)
|
|
472
|
+
? this.platform.getMappedType(prop.columnTypes[0])
|
|
473
|
+
: mappedDeclaredType));
|
|
474
|
+
const rawType = mappedRawType.runtimeType;
|
|
475
|
+
const serializedType = (prop.customType ?? mappedRawType).runtimeType;
|
|
476
|
+
// Add non-lib imports where needed.
|
|
477
|
+
for (const typeSpec of [prop.runtimeType, rawType, serializedType]) {
|
|
478
|
+
const simplePropType = typeSpec.replace(/\[]+$/, '');
|
|
479
|
+
if (!primitivesAndLibs.includes(simplePropType)) {
|
|
480
|
+
this.entityImports.add(simplePropType);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (prop.runtimeType !== rawType || rawType !== serializedType) {
|
|
484
|
+
if (rawType !== serializedType) {
|
|
485
|
+
const r = [prop.runtimeType, rawType, serializedType];
|
|
486
|
+
this.propTypeBreakdowns.set(prop, r);
|
|
487
|
+
return r;
|
|
488
|
+
}
|
|
489
|
+
const r = [prop.runtimeType, rawType];
|
|
490
|
+
this.propTypeBreakdowns.set(prop, r);
|
|
491
|
+
return r;
|
|
492
|
+
}
|
|
493
|
+
const r = undefined;
|
|
494
|
+
this.propTypeBreakdowns.set(prop, r);
|
|
495
|
+
return r;
|
|
483
496
|
}
|
|
484
497
|
getScalarPropertyDecoratorOptions(options, prop) {
|
|
485
498
|
if (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {
|
|
@@ -515,11 +528,17 @@ class SourceFile {
|
|
|
515
528
|
const columnTypeFromMappedRuntimeType = mappedRuntimeType.getColumnType({ ...prop, autoincrement: false }, this.platform);
|
|
516
529
|
const columnTypeFromMappedColumnType = mappedColumnType.getColumnType({ ...prop, autoincrement: false }, this.platform);
|
|
517
530
|
const columnTypeFromMappedDeclaredType = mappedDeclaredType.getColumnType({ ...prop, autoincrement: false }, this.platform);
|
|
518
|
-
|
|
519
|
-
||
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
531
|
+
const needsExplicitColumnType = () => {
|
|
532
|
+
if (isTypeStringMissingFromMap || [mappedRuntimeType, mappedColumnType, columnTypeFromMappedDeclaredType].some(t => t instanceof core_1.UnknownType)) {
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
if (this.platform.normalizeColumnType(prop.columnTypes[0], prop) !== this.platform.normalizeColumnType(columnTypeFromMappedColumnType, prop)) {
|
|
536
|
+
return prop.columnTypes[0] !== columnTypeFromMappedColumnType;
|
|
537
|
+
}
|
|
538
|
+
return columnTypeFromMappedRuntimeType !== columnTypeFromMappedColumnType || columnTypeFromMappedDeclaredType !== columnTypeFromMappedColumnType;
|
|
539
|
+
};
|
|
540
|
+
if (needsExplicitColumnType()) {
|
|
541
|
+
options.columnType = this.quote(prop.columnTypes[0]);
|
|
523
542
|
}
|
|
524
543
|
const assign = (key) => {
|
|
525
544
|
if (prop[key] != null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
|
-
"version": "6.3.5
|
|
3
|
+
"version": "6.3.5",
|
|
4
4
|
"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.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -58,13 +58,13 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@mikro-orm/knex": "6.3.5
|
|
61
|
+
"@mikro-orm/knex": "6.3.5",
|
|
62
62
|
"fs-extra": "11.2.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@mikro-orm/core": "^6.3.
|
|
65
|
+
"@mikro-orm/core": "^6.3.5"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@mikro-orm/core": "6.
|
|
68
|
+
"@mikro-orm/core": "^6.0.0"
|
|
69
69
|
}
|
|
70
70
|
}
|