@mikro-orm/core 6.4.7-dev.2 → 6.4.7-dev.20
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 +3 -3
- package/entity/EntityFactory.js +3 -1
- package/index.d.ts +1 -1
- package/package.json +2 -2
- package/typings.d.ts +5 -3
- package/unit-of-work/UnitOfWork.js +1 -1
- package/utils/AbstractSchemaGenerator.js +5 -2
- package/utils/EntityComparator.js +1 -1
- package/utils/RawQueryFragment.js +1 -0
package/EntityManager.js
CHANGED
|
@@ -360,7 +360,7 @@ class EntityManager {
|
|
|
360
360
|
if (!args && filter.cond.length > 0 && filter.args !== false) {
|
|
361
361
|
throw new Error(`No arguments provided for filter '${filter.name}'`);
|
|
362
362
|
}
|
|
363
|
-
cond = await filter.cond(args, type, this, findOptions);
|
|
363
|
+
cond = await filter.cond(args, type, this, findOptions, entityName);
|
|
364
364
|
}
|
|
365
365
|
else {
|
|
366
366
|
cond = filter.cond;
|
|
@@ -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/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
|
});
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, } from './typings';
|
|
5
|
+
export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, } from './typings';
|
|
6
6
|
export * from './enums';
|
|
7
7
|
export * from './errors';
|
|
8
8
|
export * from './exceptions';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.7-dev.
|
|
3
|
+
"version": "6.4.7-dev.20",
|
|
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-dev.
|
|
67
|
+
"mikro-orm": "6.4.7-dev.20",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type EntityKey<T = unknown, B extends boolean = false> = string & {
|
|
|
19
19
|
[K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
|
|
20
20
|
}[keyof T];
|
|
21
21
|
export type EntityValue<T> = T[EntityKey<T>];
|
|
22
|
+
export type EntityDataValue<T> = EntityData<T>[EntityKey<T>];
|
|
22
23
|
export type FilterKey<T> = keyof FilterQuery<T>;
|
|
23
24
|
export type AsyncFunction<R = any, T = Dictionary> = (args: T) => Promise<T>;
|
|
24
25
|
export type Compute<T> = {
|
|
@@ -231,7 +232,7 @@ type IsOptional<T, K extends keyof T, I> = T[K] extends Collection<any, any> ? t
|
|
|
231
232
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
232
233
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
233
234
|
export type EntityData<T, C extends boolean = false> = {
|
|
234
|
-
[K in EntityKey<T>]?: EntityDataItem<T[K], C>;
|
|
235
|
+
[K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
|
|
235
236
|
};
|
|
236
237
|
export type RequiredEntityData<T, I = never, C extends boolean = false> = {
|
|
237
238
|
[K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]>;
|
|
@@ -283,7 +284,8 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
283
284
|
} & {
|
|
284
285
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
285
286
|
};
|
|
286
|
-
|
|
287
|
+
type CheckKey<T> = IsUnknown<T> extends false ? keyof T : string;
|
|
288
|
+
export type CheckCallback<T> = (columns: Record<CheckKey<T>, string>) => string;
|
|
287
289
|
export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
|
|
288
290
|
export interface CheckConstraint<T = any> {
|
|
289
291
|
name?: string;
|
|
@@ -671,7 +673,7 @@ export interface MigrationObject {
|
|
|
671
673
|
}
|
|
672
674
|
export type FilterDef = {
|
|
673
675
|
name: string;
|
|
674
|
-
cond: Dictionary | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>) => Dictionary | Promise<Dictionary>);
|
|
676
|
+
cond: Dictionary | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>, entityName?: EntityName<any>) => Dictionary | Promise<Dictionary>);
|
|
675
677
|
default?: boolean;
|
|
676
678
|
entity?: string[];
|
|
677
679
|
args?: boolean;
|
|
@@ -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
|
}
|
|
@@ -35,7 +35,7 @@ class AbstractSchemaGenerator {
|
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
await this.ensureDatabase();
|
|
38
|
-
await this.dropSchema();
|
|
38
|
+
await this.dropSchema(options);
|
|
39
39
|
}
|
|
40
40
|
await this.createSchema(options);
|
|
41
41
|
}
|
|
@@ -104,7 +104,10 @@ class AbstractSchemaGenerator {
|
|
|
104
104
|
}
|
|
105
105
|
return calc.sort()
|
|
106
106
|
.map(cls => this.metadata.find(cls))
|
|
107
|
-
.filter(meta =>
|
|
107
|
+
.filter(meta => {
|
|
108
|
+
const targetSchema = meta.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName());
|
|
109
|
+
return schema ? [schema, '*'].includes(targetSchema) : meta.schema !== '*';
|
|
110
|
+
});
|
|
108
111
|
}
|
|
109
112
|
notImplemented() {
|
|
110
113
|
throw new Error(`This method is not supported by ${this.driver.constructor.name} driver`);
|
|
@@ -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)},`);
|