@mikro-orm/core 7.0.0-dev.3 → 7.0.0-dev.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/EntityManager.js +3 -3
- package/decorators/Check.d.ts +2 -2
- package/decorators/Embeddable.d.ts +5 -5
- package/decorators/Embeddable.js +1 -1
- package/decorators/Embedded.d.ts +2 -2
- package/decorators/Entity.d.ts +3 -3
- package/decorators/Entity.js +0 -1
- package/decorators/Enum.d.ts +1 -1
- package/decorators/Formula.d.ts +1 -2
- package/decorators/Indexed.d.ts +9 -7
- package/decorators/Indexed.js +1 -1
- package/decorators/ManyToMany.d.ts +2 -2
- package/decorators/ManyToOne.d.ts +2 -2
- package/decorators/OneToMany.d.ts +4 -4
- package/decorators/OneToOne.d.ts +1 -1
- package/decorators/PrimaryKey.d.ts +2 -3
- package/decorators/Property.d.ts +1 -1
- package/entity/EntityFactory.js +3 -1
- package/entity/EntityLoader.js +5 -1
- package/index.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +2 -2
- package/package.json +2 -2
- package/typings.d.ts +6 -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 +6 -1
package/EntityManager.js
CHANGED
|
@@ -367,7 +367,7 @@ export class EntityManager {
|
|
|
367
367
|
if (!args && filter.cond.length > 0 && filter.args !== false) {
|
|
368
368
|
throw new Error(`No arguments provided for filter '${filter.name}'`);
|
|
369
369
|
}
|
|
370
|
-
cond = await filter.cond(args, type, this, findOptions);
|
|
370
|
+
cond = await filter.cond(args, type, this, findOptions, entityName);
|
|
371
371
|
}
|
|
372
372
|
else {
|
|
373
373
|
cond = filter.cond;
|
|
@@ -717,7 +717,7 @@ export class EntityManager {
|
|
|
717
717
|
convertCustomTypes: true,
|
|
718
718
|
connectionType: 'write',
|
|
719
719
|
});
|
|
720
|
-
em.getHydrator().hydrate(entity, meta, data2, em.entityFactory, 'full');
|
|
720
|
+
em.getHydrator().hydrate(entity, meta, data2, em.entityFactory, 'full', false, true);
|
|
721
721
|
}
|
|
722
722
|
// recompute the data as there might be some values missing (e.g. those with db column defaults)
|
|
723
723
|
const snapshot = this.comparator.prepareEntity(entity);
|
|
@@ -911,7 +911,7 @@ export class EntityManager {
|
|
|
911
911
|
if (!row) {
|
|
912
912
|
throw new Error(`Cannot find matching entity for condition ${JSON.stringify(cond)}`);
|
|
913
913
|
}
|
|
914
|
-
em.getHydrator().hydrate(entity, meta, row, em.entityFactory, 'full');
|
|
914
|
+
em.getHydrator().hydrate(entity, meta, row, em.entityFactory, 'full', false, true);
|
|
915
915
|
}
|
|
916
916
|
if (loadPK.size !== data2.length && Array.isArray(uniqueFields)) {
|
|
917
917
|
for (let i = 0; i < allData.length; i++) {
|
package/decorators/Check.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CheckConstraint } from '../typings.js';
|
|
2
|
-
export declare function Check<T>(options: CheckOptions<T>): (target:
|
|
1
|
+
import type { CheckConstraint, EntityClass } from '../typings.js';
|
|
2
|
+
export declare function Check<T>(options: CheckOptions<T>): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
|
3
3
|
export type CheckOptions<T = any> = CheckConstraint<T>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Dictionary } from '../typings.js';
|
|
2
|
-
export declare function Embeddable(options?: EmbeddableOptions):
|
|
3
|
-
export
|
|
4
|
-
discriminatorColumn?: string;
|
|
1
|
+
import type { AnyString, Dictionary, EntityClass } from '../typings.js';
|
|
2
|
+
export declare function Embeddable<T>(options?: EmbeddableOptions<T>): (target: T) => T;
|
|
3
|
+
export interface EmbeddableOptions<T> {
|
|
4
|
+
discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
|
|
5
5
|
discriminatorMap?: Dictionary<string>;
|
|
6
6
|
discriminatorValue?: number | string;
|
|
7
7
|
abstract?: boolean;
|
|
8
|
-
}
|
|
8
|
+
}
|
package/decorators/Embeddable.js
CHANGED
|
@@ -3,7 +3,7 @@ export function Embeddable(options = {}) {
|
|
|
3
3
|
return function (target) {
|
|
4
4
|
const meta = MetadataStorage.getMetadataFromDecorator(target);
|
|
5
5
|
meta.class = target;
|
|
6
|
-
meta.name =
|
|
6
|
+
meta.name = meta.class.name;
|
|
7
7
|
meta.embeddable = true;
|
|
8
8
|
Object.assign(meta, options);
|
|
9
9
|
return target;
|
package/decorators/Embedded.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AnyEntity } from '../typings.js';
|
|
|
2
2
|
export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
|
|
3
3
|
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|
|
4
4
|
export type EmbeddedPrefixMode = 'absolute' | 'relative';
|
|
5
|
-
export
|
|
5
|
+
export interface EmbeddedOptions {
|
|
6
6
|
entity?: string | (() => AnyEntity | AnyEntity[]);
|
|
7
7
|
type?: string;
|
|
8
8
|
prefix?: string | boolean;
|
|
@@ -15,4 +15,4 @@ export type EmbeddedOptions = {
|
|
|
15
15
|
serializedName?: string;
|
|
16
16
|
groups?: string[];
|
|
17
17
|
persist?: boolean;
|
|
18
|
-
}
|
|
18
|
+
}
|
package/decorators/Entity.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Constructor, Dictionary, FilterQuery } from '../typings.js';
|
|
1
|
+
import type { AnyString, Constructor, Dictionary, EntityClass, FilterQuery } from '../typings.js';
|
|
2
2
|
import type { FindOptions } from '../drivers/IDatabaseDriver.js';
|
|
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/Enum.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PropertyOptions } from './Property.js';
|
|
2
2
|
import type { AnyEntity, Dictionary } from '../typings.js';
|
|
3
|
-
export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target:
|
|
3
|
+
export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: T, propertyName: string) => any;
|
|
4
4
|
export interface EnumOptions<T> extends PropertyOptions<T> {
|
|
5
5
|
items?: (number | string)[] | (() => Dictionary);
|
|
6
6
|
array?: boolean;
|
package/decorators/Formula.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity } from '../typings.js';
|
|
2
1
|
import type { PropertyOptions } from './Property.js';
|
|
3
|
-
export declare function Formula<T extends object>(formula: string | ((alias: string) => string), options?: FormulaOptions<T>): (target:
|
|
2
|
+
export declare function Formula<T extends object>(formula: string | ((alias: string) => string), options?: FormulaOptions<T>): (target: T, propertyName: string) => any;
|
|
4
3
|
export interface FormulaOptions<T> extends PropertyOptions<T> {
|
|
5
4
|
}
|
package/decorators/Indexed.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityClass, Dictionary, AutoPath } from '../typings.js';
|
|
2
2
|
import type { DeferMode } from '../enums.js';
|
|
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
|
@@ -3,7 +3,7 @@ import { Utils } from '../utils/Utils.js';
|
|
|
3
3
|
function createDecorator(options, unique) {
|
|
4
4
|
return function (target, propertyName) {
|
|
5
5
|
const meta = MetadataStorage.getMetadataFromDecorator(propertyName ? target.constructor : target);
|
|
6
|
-
options.properties
|
|
6
|
+
options.properties ??= propertyName;
|
|
7
7
|
const key = unique ? 'uniques' : 'indexes';
|
|
8
8
|
meta[key].push(options);
|
|
9
9
|
if (!propertyName) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReferenceOptions } from './Property.js';
|
|
2
|
-
import type { EntityName,
|
|
2
|
+
import type { EntityName, FilterQuery, AnyString } from '../typings.js';
|
|
3
3
|
import { type QueryOrderMap } from '../enums.js';
|
|
4
|
-
export declare function ManyToMany<
|
|
4
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>), mappedBy?: (string & keyof Target) | ((e: Target) => any), options?: Partial<ManyToManyOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
|
|
5
5
|
export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
|
|
6
6
|
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
7
7
|
owner?: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReferenceOptions } from './Property.js';
|
|
2
2
|
import { type DeferMode } from '../enums.js';
|
|
3
|
-
import type {
|
|
4
|
-
export declare function ManyToOne<
|
|
3
|
+
import type { AnyString, EntityName } from '../typings.js';
|
|
4
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), options?: Partial<ManyToOneOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
|
|
5
5
|
export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
|
|
6
6
|
/** Point to the inverse side property name. */
|
|
7
7
|
inversedBy?: (string & keyof Target) | ((e: Target) => any);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ReferenceOptions } from './Property.js';
|
|
2
2
|
import { ReferenceKind, type QueryOrderMap } from '../enums.js';
|
|
3
|
-
import type { EntityName,
|
|
4
|
-
export declare function createOneToDecorator<Target, Owner>(entity: OneToManyOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any) | undefined, options: Partial<OneToManyOptions<Owner, Target>>, kind: ReferenceKind): (target:
|
|
5
|
-
export declare function OneToMany<Target, Owner>(entity: string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target:
|
|
6
|
-
export declare function OneToMany<Target, Owner>(options: OneToManyOptions<Owner, Target>): (target:
|
|
3
|
+
import type { EntityName, FilterQuery } from '../typings.js';
|
|
4
|
+
export declare function createOneToDecorator<Target, Owner>(entity: OneToManyOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any) | undefined, options: Partial<OneToManyOptions<Owner, Target>>, kind: ReferenceKind): (target: Owner, propertyName: string) => any;
|
|
5
|
+
export declare function OneToMany<Target, Owner>(entity: string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
|
|
6
|
+
export declare function OneToMany<Target, Owner>(options: OneToManyOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
|
7
7
|
export interface OneToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
|
|
8
8
|
/** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
|
|
9
9
|
orphanRemoval?: boolean;
|
package/decorators/OneToOne.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type DeferMode } from '../enums.js';
|
|
2
2
|
import { type OneToManyOptions } from './OneToMany.js';
|
|
3
3
|
import type { AnyString, EntityName } from '../typings.js';
|
|
4
|
-
export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target:
|
|
4
|
+
export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: Owner, propertyName: string) => any;
|
|
5
5
|
export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>> {
|
|
6
6
|
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
7
7
|
owner?: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PropertyOptions } from './Property.js';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: AnyEntity, propertyName: string) => any;
|
|
2
|
+
export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
|
|
3
|
+
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
|
|
5
4
|
export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
|
|
6
5
|
}
|
|
7
6
|
export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
|
package/decorators/Property.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { EntityName, Constructor, CheckCallback, GeneratedColumnCallback, A
|
|
|
3
3
|
import type { Type, types } from '../types/index.js';
|
|
4
4
|
import type { EntityManager } from '../EntityManager.js';
|
|
5
5
|
import type { SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
6
|
-
export declare function Property<T extends object>(options?: PropertyOptions<T>): (target:
|
|
6
|
+
export declare function Property<T extends object>(options?: PropertyOptions<T>): (target: T, propertyName: string) => any;
|
|
7
7
|
export interface PropertyOptions<Owner> {
|
|
8
8
|
/**
|
|
9
9
|
* Alias for `fieldName`.
|
package/entity/EntityFactory.js
CHANGED
|
@@ -86,7 +86,9 @@ export class EntityFactory {
|
|
|
86
86
|
}
|
|
87
87
|
if (options.merge && wrapped.hasPrimaryKey()) {
|
|
88
88
|
this.unitOfWork.register(entity, data, {
|
|
89
|
-
refresh
|
|
89
|
+
// Always refresh to ensure the payload is in correct shape for joined strategy. When loading nested relations,
|
|
90
|
+
// they will be created early without `Type.ensureComparable` being properly handled, resulting in extra updates.
|
|
91
|
+
refresh: options.initialized,
|
|
90
92
|
newEntity: options.newEntity,
|
|
91
93
|
loaded: options.initialized,
|
|
92
94
|
});
|
package/entity/EntityLoader.js
CHANGED
|
@@ -249,9 +249,13 @@ export class EntityLoader {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
+
const orderBy = [...Utils.asArray(options.orderBy), ...propOrderBy].filter((order, idx, array) => {
|
|
253
|
+
// skip consecutive ordering with the same key to get around mongo issues
|
|
254
|
+
return idx === 0 || !Utils.equals(Object.keys(array[idx - 1]), Object.keys(order));
|
|
255
|
+
});
|
|
252
256
|
const items = await this.em.find(prop.type, where, {
|
|
253
257
|
filters, convertCustomTypes, lockMode, populateWhere, logging,
|
|
254
|
-
orderBy
|
|
258
|
+
orderBy,
|
|
255
259
|
populate: populate.children ?? populate.all ?? [],
|
|
256
260
|
exclude: Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop.name) : options.exclude,
|
|
257
261
|
strategy, fields, schema, connectionType,
|
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.js';
|
|
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.js';
|
|
6
6
|
export * from './enums.js';
|
|
7
7
|
export * from './errors.js';
|
|
8
8
|
export * from './exceptions.js';
|
|
@@ -68,8 +68,8 @@ export declare class EntitySchema<Entity = any, Base = never> {
|
|
|
68
68
|
addManyToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToManyOptions<Entity, Target>): void;
|
|
69
69
|
addOneToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToManyOptions<Entity, Target>): void;
|
|
70
70
|
addOneToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToOneOptions<Entity, Target>): void;
|
|
71
|
-
addIndex(options: IndexOptions<Entity>): void;
|
|
72
|
-
addUnique(options: UniqueOptions<Entity>): void;
|
|
71
|
+
addIndex<Key extends string>(options: IndexOptions<Entity, Key>): void;
|
|
72
|
+
addUnique<Key extends string>(options: UniqueOptions<Entity, Key>): void;
|
|
73
73
|
setCustomRepository(repository: () => Constructor): void;
|
|
74
74
|
setExtends(base: string | EntitySchema): void;
|
|
75
75
|
setClass(proto: EntityClass<Entity>): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.5",
|
|
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",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"dotenv": "16.4.7",
|
|
56
56
|
"esprima": "4.0.1",
|
|
57
57
|
"globby": "11.1.0",
|
|
58
|
-
"mikro-orm": "7.0.0-dev.
|
|
58
|
+
"mikro-orm": "7.0.0-dev.5",
|
|
59
59
|
"reflect-metadata": "0.2.2"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/typings.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type EntityKey<T = unknown, B extends boolean = false> = string & {
|
|
|
28
28
|
[K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
|
|
29
29
|
}[keyof T];
|
|
30
30
|
export type EntityValue<T> = T[EntityKey<T>];
|
|
31
|
+
export type EntityDataValue<T> = EntityData<T>[EntityKey<T>];
|
|
31
32
|
export type FilterKey<T> = keyof FilterQuery<T>;
|
|
32
33
|
export type AsyncFunction<R = any, T = Dictionary> = (args: T) => Promise<T>;
|
|
33
34
|
export type Compute<T> = {
|
|
@@ -240,7 +241,7 @@ type IsOptional<T, K extends keyof T, I> = T[K] extends Collection<any, any> ? t
|
|
|
240
241
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
241
242
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
242
243
|
export type EntityData<T, C extends boolean = false> = {
|
|
243
|
-
[K in EntityKey<T>]?: EntityDataItem<T[K], C>;
|
|
244
|
+
[K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
|
|
244
245
|
};
|
|
245
246
|
export type RequiredEntityData<T, I = never, C extends boolean = false> = {
|
|
246
247
|
[K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]>;
|
|
@@ -292,7 +293,9 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
292
293
|
} & {
|
|
293
294
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
294
295
|
};
|
|
295
|
-
|
|
296
|
+
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
297
|
+
type CheckKey<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
298
|
+
export type CheckCallback<T> = (columns: Record<CheckKey<T>, string>) => string;
|
|
296
299
|
export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
|
|
297
300
|
export interface CheckConstraint<T = any> {
|
|
298
301
|
name?: string;
|
|
@@ -681,7 +684,7 @@ export interface MigrationObject {
|
|
|
681
684
|
}
|
|
682
685
|
export type FilterDef = {
|
|
683
686
|
name: string;
|
|
684
|
-
cond: Dictionary | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>) => Dictionary | Promise<Dictionary>);
|
|
687
|
+
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>);
|
|
685
688
|
default?: boolean;
|
|
686
689
|
entity?: string[];
|
|
687
690
|
args?: boolean;
|
|
@@ -884,7 +884,7 @@ export 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
|
}
|
|
@@ -32,7 +32,7 @@ export class AbstractSchemaGenerator {
|
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
await this.ensureDatabase();
|
|
35
|
-
await this.dropSchema();
|
|
35
|
+
await this.dropSchema(options);
|
|
36
36
|
}
|
|
37
37
|
if (options?.createSchema !== false) {
|
|
38
38
|
await this.createSchema(options);
|
|
@@ -103,7 +103,10 @@ export class AbstractSchemaGenerator {
|
|
|
103
103
|
}
|
|
104
104
|
return calc.sort()
|
|
105
105
|
.map(cls => this.metadata.find(cls))
|
|
106
|
-
.filter(meta =>
|
|
106
|
+
.filter(meta => {
|
|
107
|
+
const targetSchema = meta.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName());
|
|
108
|
+
return schema ? [schema, '*'].includes(targetSchema) : meta.schema !== '*';
|
|
109
|
+
});
|
|
107
110
|
}
|
|
108
111
|
notImplemented() {
|
|
109
112
|
throw new Error(`This method is not supported by ${this.driver.constructor.name} driver`);
|
|
@@ -74,7 +74,7 @@ export class EntityComparator {
|
|
|
74
74
|
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) {`);
|
|
75
75
|
lines.push(` const pk = entity${this.wrap(pk)}.__helper.getPrimaryKey();`);
|
|
76
76
|
if (meta.properties[pk].targetMeta.compositePK) {
|
|
77
|
-
lines.push(` if (typeof pk === 'object') {`);
|
|
77
|
+
lines.push(` if (typeof pk === 'object' && pk != null) {`);
|
|
78
78
|
lines.push(` return [`);
|
|
79
79
|
for (const childPK of meta.properties[pk].targetMeta.primaryKeys) {
|
|
80
80
|
lines.push(` pk${this.wrap(childPK)},`);
|
|
@@ -17,7 +17,12 @@ export class RawQueryFragment {
|
|
|
17
17
|
this.#key = `[raw]: ${this.sql} (#${RawQueryFragment.#index++})`;
|
|
18
18
|
}
|
|
19
19
|
as(alias) {
|
|
20
|
-
|
|
20
|
+
// TODO: to be removed in v7
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
if (alias.startsWith('`') || alias.startsWith('"')) {
|
|
23
|
+
return new RawQueryFragment(`${this.sql} as ${alias}`, this.params);
|
|
24
|
+
}
|
|
25
|
+
return new RawQueryFragment(`${this.sql} as ??`, [...this.params, alias]);
|
|
21
26
|
}
|
|
22
27
|
valueOf() {
|
|
23
28
|
throw new Error(`Trying to modify raw SQL fragment: '${this.sql}'`);
|