@mikro-orm/core 6.4.7-dev.9 → 6.4.7
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/EntityManager.js +2 -2
- package/decorators/Entity.d.ts +3 -3
- package/decorators/Entity.js +0 -1
- package/decorators/Indexed.d.ts +9 -7
- package/decorators/Indexed.js +1 -1
- package/entity/EntityFactory.js +3 -1
- package/metadata/EntitySchema.d.ts +2 -2
- package/package.json +2 -2
- package/unit-of-work/UnitOfWork.js +1 -1
- package/utils/AbstractSchemaGenerator.js +1 -1
- package/utils/EntityComparator.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -702,7 +702,7 @@ class EntityManager {
|
|
|
702
702
|
convertCustomTypes: true,
|
|
703
703
|
connectionType: 'write',
|
|
704
704
|
});
|
|
705
|
-
em.getHydrator().hydrate(entity, meta, data2, em.entityFactory, 'full');
|
|
705
|
+
em.getHydrator().hydrate(entity, meta, data2, em.entityFactory, 'full', false, true);
|
|
706
706
|
}
|
|
707
707
|
// recompute the data as there might be some values missing (e.g. those with db column defaults)
|
|
708
708
|
const snapshot = this.comparator.prepareEntity(entity);
|
|
@@ -897,7 +897,7 @@ class EntityManager {
|
|
|
897
897
|
if (!row) {
|
|
898
898
|
throw new Error(`Cannot find matching entity for condition ${JSON.stringify(cond)}`);
|
|
899
899
|
}
|
|
900
|
-
em.getHydrator().hydrate(entity, meta, row, em.entityFactory, 'full');
|
|
900
|
+
em.getHydrator().hydrate(entity, meta, row, em.entityFactory, 'full', false, true);
|
|
901
901
|
}
|
|
902
902
|
if (loadPK.size !== data2.length && Array.isArray(uniqueFields)) {
|
|
903
903
|
for (let i = 0; i < allData.length; i++) {
|
package/decorators/Entity.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Constructor, Dictionary, FilterQuery } from '../typings';
|
|
1
|
+
import type { AnyString, Constructor, Dictionary, EntityClass, FilterQuery } from '../typings';
|
|
2
2
|
import type { FindOptions } from '../drivers/IDatabaseDriver';
|
|
3
|
-
export declare function Entity(options?: EntityOptions<
|
|
3
|
+
export declare function Entity<T extends EntityClass<unknown>>(options?: EntityOptions<T>): (target: T) => void;
|
|
4
4
|
export type EntityOptions<T> = {
|
|
5
5
|
tableName?: string;
|
|
6
6
|
schema?: string;
|
|
7
7
|
collection?: string;
|
|
8
|
-
discriminatorColumn?: string;
|
|
8
|
+
discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
|
|
9
9
|
discriminatorMap?: Dictionary<string>;
|
|
10
10
|
discriminatorValue?: number | string;
|
|
11
11
|
forceConstructor?: boolean;
|
package/decorators/Entity.js
CHANGED
package/decorators/Indexed.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityClass, Dictionary, AutoPath } from '../typings';
|
|
2
2
|
import type { DeferMode } from '../enums';
|
|
3
|
-
export declare function Index<T>(options?: IndexOptions<T>): (target:
|
|
4
|
-
export declare function Unique<T>(options?: UniqueOptions<T>): (target:
|
|
5
|
-
|
|
3
|
+
export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (target: T, propertyName?: (T extends EntityClass<unknown> ? undefined : keyof T) | undefined) => any;
|
|
4
|
+
export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (target: T, propertyName?: (T extends EntityClass<unknown> ? undefined : keyof T) | undefined) => any;
|
|
5
|
+
type MaybeArray<T> = T | T[];
|
|
6
|
+
type Properties<T, H extends string> = MaybeArray<AutoPath<T, H>>;
|
|
7
|
+
interface BaseOptions<T, H extends string> {
|
|
6
8
|
name?: string;
|
|
7
|
-
properties?:
|
|
9
|
+
properties?: (T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>);
|
|
8
10
|
options?: Dictionary;
|
|
9
11
|
expression?: string;
|
|
10
12
|
}
|
|
11
|
-
export interface UniqueOptions<T> extends BaseOptions<T> {
|
|
13
|
+
export interface UniqueOptions<T, H extends string = string> extends BaseOptions<T, H> {
|
|
12
14
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
13
15
|
}
|
|
14
|
-
export interface IndexOptions<T> extends BaseOptions<T> {
|
|
16
|
+
export interface IndexOptions<T, H extends string = string> extends BaseOptions<T, H> {
|
|
15
17
|
type?: string;
|
|
16
18
|
}
|
|
17
19
|
export {};
|
package/decorators/Indexed.js
CHANGED
|
@@ -7,7 +7,7 @@ const Utils_1 = require("../utils/Utils");
|
|
|
7
7
|
function createDecorator(options, unique) {
|
|
8
8
|
return function (target, propertyName) {
|
|
9
9
|
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(propertyName ? target.constructor : target);
|
|
10
|
-
options.properties
|
|
10
|
+
options.properties ??= propertyName;
|
|
11
11
|
const key = unique ? 'uniques' : 'indexes';
|
|
12
12
|
meta[key].push(options);
|
|
13
13
|
if (!propertyName) {
|
package/entity/EntityFactory.js
CHANGED
|
@@ -89,7 +89,9 @@ class EntityFactory {
|
|
|
89
89
|
}
|
|
90
90
|
if (options.merge && wrapped.hasPrimaryKey()) {
|
|
91
91
|
this.unitOfWork.register(entity, data, {
|
|
92
|
-
refresh
|
|
92
|
+
// Always refresh to ensure the payload is in correct shape for joined strategy. When loading nested relations,
|
|
93
|
+
// they will be created early without `Type.ensureComparable` being properly handled, resulting in extra updates.
|
|
94
|
+
refresh: options.initialized,
|
|
93
95
|
newEntity: options.newEntity,
|
|
94
96
|
loaded: options.initialized,
|
|
95
97
|
});
|
|
@@ -60,8 +60,8 @@ export declare class EntitySchema<Entity = any, Base = never> {
|
|
|
60
60
|
addManyToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToManyOptions<Entity, Target>): void;
|
|
61
61
|
addOneToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToManyOptions<Entity, Target>): void;
|
|
62
62
|
addOneToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToOneOptions<Entity, Target>): void;
|
|
63
|
-
addIndex(options: IndexOptions<Entity>): void;
|
|
64
|
-
addUnique(options: UniqueOptions<Entity>): void;
|
|
63
|
+
addIndex<Key extends string>(options: IndexOptions<Entity, Key>): void;
|
|
64
|
+
addUnique<Key extends string>(options: UniqueOptions<Entity, Key>): void;
|
|
65
65
|
setCustomRepository(repository: () => Constructor): void;
|
|
66
66
|
setExtends(base: string | EntitySchema): void;
|
|
67
67
|
setClass(proto: EntityClass<Entity>): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.7
|
|
3
|
+
"version": "6.4.7",
|
|
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",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.7
|
|
67
|
+
"mikro-orm": "6.4.7",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -884,7 +884,7 @@ class UnitOfWork {
|
|
|
884
884
|
collectionUpdates.push(coll);
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
|
-
await this.em.getDriver().syncCollections(collectionUpdates, { ctx });
|
|
887
|
+
await this.em.getDriver().syncCollections(collectionUpdates, { ctx, schema: this.em.schema });
|
|
888
888
|
for (const coll of this.collectionUpdates) {
|
|
889
889
|
coll.takeSnapshot();
|
|
890
890
|
}
|
|
@@ -77,7 +77,7 @@ class EntityComparator {
|
|
|
77
77
|
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) {`);
|
|
78
78
|
lines.push(` const pk = entity${this.wrap(pk)}.__helper.getPrimaryKey();`);
|
|
79
79
|
if (meta.properties[pk].targetMeta.compositePK) {
|
|
80
|
-
lines.push(` if (typeof pk === 'object') {`);
|
|
80
|
+
lines.push(` if (typeof pk === 'object' && pk != null) {`);
|
|
81
81
|
lines.push(` return [`);
|
|
82
82
|
for (const childPK of meta.properties[pk].targetMeta.primaryKeys) {
|
|
83
83
|
lines.push(` pk${this.wrap(childPK)},`);
|