@mikro-orm/core 7.0.0-dev.3 → 7.0.0-dev.30
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.d.ts +50 -7
- package/EntityManager.js +141 -97
- package/MikroORM.js +0 -1
- package/README.md +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -1
- package/cache/FileCacheAdapter.js +6 -4
- package/connections/Connection.d.ts +4 -2
- package/connections/Connection.js +2 -2
- 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 +6 -12
- package/decorators/Entity.d.ts +20 -5
- 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 +10 -8
- package/decorators/Indexed.js +1 -1
- package/decorators/ManyToMany.d.ts +4 -2
- package/decorators/ManyToOne.d.ts +6 -2
- package/decorators/OneToMany.d.ts +4 -4
- package/decorators/OneToOne.d.ts +5 -1
- package/decorators/PrimaryKey.d.ts +2 -3
- package/decorators/Property.d.ts +1 -1
- package/decorators/Transactional.d.ts +1 -0
- package/decorators/Transactional.js +3 -3
- package/drivers/IDatabaseDriver.d.ts +8 -1
- package/entity/ArrayCollection.d.ts +4 -2
- package/entity/ArrayCollection.js +18 -6
- package/entity/Collection.d.ts +1 -2
- package/entity/Collection.js +16 -10
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +9 -1
- package/entity/EntityFactory.d.ts +6 -0
- package/entity/EntityFactory.js +21 -7
- package/entity/EntityHelper.js +8 -1
- package/entity/EntityLoader.d.ts +3 -2
- package/entity/EntityLoader.js +54 -35
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/EntityValidator.js +1 -1
- package/entity/Reference.d.ts +8 -7
- package/entity/Reference.js +22 -1
- package/entity/WrappedEntity.js +1 -1
- package/entity/defineEntity.d.ts +537 -0
- package/entity/defineEntity.js +693 -0
- package/entity/index.d.ts +2 -0
- package/entity/index.js +2 -0
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +15 -3
- package/enums.d.ts +16 -3
- package/enums.js +13 -0
- package/errors.d.ts +6 -0
- package/errors.js +14 -0
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/ObjectHydrator.js +10 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/metadata/EntitySchema.d.ts +6 -4
- package/metadata/EntitySchema.js +33 -19
- package/metadata/MetadataDiscovery.d.ts +0 -1
- package/metadata/MetadataDiscovery.js +51 -29
- package/metadata/MetadataStorage.js +1 -1
- package/metadata/MetadataValidator.js +4 -3
- package/package.json +5 -5
- package/platforms/Platform.d.ts +3 -1
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +1 -1
- package/serialization/SerializationContext.js +13 -10
- package/types/BigIntType.d.ts +9 -6
- package/types/BigIntType.js +3 -0
- package/types/BooleanType.d.ts +1 -1
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +1 -1
- package/types/DoubleType.js +1 -1
- package/typings.d.ts +72 -35
- package/typings.js +24 -4
- package/unit-of-work/ChangeSetComputer.js +3 -1
- package/unit-of-work/ChangeSetPersister.d.ts +4 -2
- package/unit-of-work/ChangeSetPersister.js +21 -11
- package/unit-of-work/UnitOfWork.d.ts +2 -1
- package/unit-of-work/UnitOfWork.js +71 -24
- package/utils/AbstractSchemaGenerator.js +5 -2
- package/utils/Configuration.d.ts +15 -5
- package/utils/Configuration.js +7 -7
- package/utils/ConfigurationLoader.d.ts +0 -2
- package/utils/ConfigurationLoader.js +2 -24
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +3 -0
- package/utils/DataloaderUtils.d.ts +7 -2
- package/utils/DataloaderUtils.js +38 -7
- package/utils/EntityComparator.d.ts +6 -2
- package/utils/EntityComparator.js +98 -59
- package/utils/QueryHelper.d.ts +6 -0
- package/utils/QueryHelper.js +48 -5
- package/utils/RawQueryFragment.d.ts +34 -0
- package/utils/RawQueryFragment.js +40 -1
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +220 -0
- package/utils/Utils.d.ts +11 -7
- package/utils/Utils.js +67 -33
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/upsert-utils.js +9 -1
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { globSync } from 'tinyglobby';
|
|
2
2
|
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
3
3
|
import { Utils } from '../utils/Utils.js';
|
|
4
4
|
export class FileCacheAdapter {
|
|
5
5
|
options;
|
|
6
6
|
baseDir;
|
|
7
7
|
pretty;
|
|
8
|
+
hashAlgorithm;
|
|
8
9
|
VERSION = Utils.getORMVersion();
|
|
9
10
|
cache = {};
|
|
10
|
-
constructor(options, baseDir, pretty = false) {
|
|
11
|
+
constructor(options, baseDir, pretty = false, hashAlgorithm = 'md5') {
|
|
11
12
|
this.options = options;
|
|
12
13
|
this.baseDir = baseDir;
|
|
13
14
|
this.pretty = pretty;
|
|
15
|
+
this.hashAlgorithm = hashAlgorithm;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* @inheritDoc
|
|
@@ -51,7 +53,7 @@ export class FileCacheAdapter {
|
|
|
51
53
|
*/
|
|
52
54
|
clear() {
|
|
53
55
|
const path = this.path('*');
|
|
54
|
-
const files =
|
|
56
|
+
const files = globSync(path);
|
|
55
57
|
files.forEach(file => unlinkSync(file));
|
|
56
58
|
this.cache = {};
|
|
57
59
|
}
|
|
@@ -77,6 +79,6 @@ export class FileCacheAdapter {
|
|
|
77
79
|
return null;
|
|
78
80
|
}
|
|
79
81
|
const contents = readFileSync(origin);
|
|
80
|
-
return Utils.hash(contents.toString() + this.VERSION);
|
|
82
|
+
return Utils.hash(contents.toString() + this.VERSION, undefined, this.hashAlgorithm);
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -45,15 +45,17 @@ export declare abstract class Connection {
|
|
|
45
45
|
readOnly?: boolean;
|
|
46
46
|
ctx?: Transaction;
|
|
47
47
|
eventBroadcaster?: TransactionEventBroadcaster;
|
|
48
|
+
loggerContext?: LogContext;
|
|
48
49
|
}): Promise<T>;
|
|
49
50
|
begin(options?: {
|
|
50
51
|
isolationLevel?: IsolationLevel;
|
|
51
52
|
readOnly?: boolean;
|
|
52
53
|
ctx?: Transaction;
|
|
53
54
|
eventBroadcaster?: TransactionEventBroadcaster;
|
|
55
|
+
loggerContext?: LogContext;
|
|
54
56
|
}): Promise<Transaction>;
|
|
55
|
-
commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
56
|
-
rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
57
|
+
commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
58
|
+
rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
57
59
|
abstract execute<T>(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise<QueryResult<T> | any | any[]>;
|
|
58
60
|
getConnectionOptions(): ConnectionConfig;
|
|
59
61
|
getClientUrl(): string;
|
|
@@ -46,10 +46,10 @@ export class Connection {
|
|
|
46
46
|
async begin(options) {
|
|
47
47
|
throw new Error(`Transactions are not supported by current driver`);
|
|
48
48
|
}
|
|
49
|
-
async commit(ctx, eventBroadcaster) {
|
|
49
|
+
async commit(ctx, eventBroadcaster, loggerContext) {
|
|
50
50
|
throw new Error(`Transactions are not supported by current driver`);
|
|
51
51
|
}
|
|
52
|
-
async rollback(ctx, eventBroadcaster) {
|
|
52
|
+
async rollback(ctx, eventBroadcaster, loggerContext) {
|
|
53
53
|
throw new Error(`Transactions are not supported by current driver`);
|
|
54
54
|
}
|
|
55
55
|
getConnectionOptions() {
|
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
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import type { AnyEntity } from '../typings.js';
|
|
2
|
-
|
|
1
|
+
import type { AnyEntity, EntityName } from '../typings.js';
|
|
2
|
+
import type { PropertyOptions } from './Property.js';
|
|
3
|
+
export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName<Target>[]), options?: EmbeddedOptions<Owner, Target>): (target: AnyEntity, propertyName: string) => any;
|
|
3
4
|
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|
|
4
5
|
export type EmbeddedPrefixMode = 'absolute' | 'relative';
|
|
5
|
-
export
|
|
6
|
-
entity?: string | (() =>
|
|
7
|
-
type?: string;
|
|
6
|
+
export interface EmbeddedOptions<Owner, Target> extends PropertyOptions<Owner> {
|
|
7
|
+
entity?: string | (() => EntityName<Target> | EntityName<Target>[]);
|
|
8
8
|
prefix?: string | boolean;
|
|
9
9
|
prefixMode?: EmbeddedPrefixMode;
|
|
10
|
-
nullable?: boolean;
|
|
11
10
|
object?: boolean;
|
|
12
11
|
array?: boolean;
|
|
13
|
-
|
|
14
|
-
serializer?: (value: any) => any;
|
|
15
|
-
serializedName?: string;
|
|
16
|
-
groups?: string[];
|
|
17
|
-
persist?: boolean;
|
|
18
|
-
};
|
|
12
|
+
}
|
package/decorators/Entity.d.ts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
import type { Constructor, Dictionary,
|
|
1
|
+
import type { AnyString, Constructor, Dictionary, EntityClass, ObjectQuery } from '../typings.js';
|
|
2
2
|
import type { FindOptions } from '../drivers/IDatabaseDriver.js';
|
|
3
|
-
export declare function Entity(options?: EntityOptions<
|
|
4
|
-
export type EntityOptions<T> = {
|
|
3
|
+
export declare function Entity<T extends EntityClass<unknown>>(options?: EntityOptions<T>): (target: T) => void;
|
|
4
|
+
export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
|
|
5
|
+
/** Override default collection/table name. Alias for `collection`. */
|
|
5
6
|
tableName?: string;
|
|
7
|
+
/** Sets the schema name. */
|
|
6
8
|
schema?: string;
|
|
9
|
+
/** Override default collection/table name. Alias for `tableName`. */
|
|
7
10
|
collection?: string;
|
|
8
|
-
|
|
11
|
+
/** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
|
|
12
|
+
discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
|
|
13
|
+
/** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
|
|
9
14
|
discriminatorMap?: Dictionary<string>;
|
|
15
|
+
/** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
|
|
10
16
|
discriminatorValue?: number | string;
|
|
17
|
+
/** Enforce use of constructor when creating managed entity instances. */
|
|
11
18
|
forceConstructor?: boolean;
|
|
19
|
+
/** Specify comment to table. (SQL only) */
|
|
12
20
|
comment?: string;
|
|
21
|
+
/** Marks entity as abstract, such entities are inlined during discovery. */
|
|
13
22
|
abstract?: boolean;
|
|
23
|
+
/** Disables change tracking - such entities are ignored during flush. */
|
|
14
24
|
readonly?: boolean;
|
|
25
|
+
/** Marks entity as {@doclink virtual-entities | virtual}. This is set automatically when you use `expression` option. */
|
|
15
26
|
virtual?: boolean;
|
|
16
|
-
|
|
27
|
+
/** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
|
|
28
|
+
hasTriggers?: boolean;
|
|
29
|
+
/** SQL query that maps to a {@doclink virtual-entities | virtual entity}. */
|
|
30
|
+
expression?: string | ((em: any, where: ObjectQuery<E>, options: FindOptions<E, any, any, any>) => object);
|
|
31
|
+
/** Set {@doclink repositories#custom-repository | custom repository class}. */
|
|
17
32
|
repository?: () => Constructor;
|
|
18
33
|
};
|
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, IndexCallback } 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
|
-
expression?: string;
|
|
11
|
+
expression?: string | (T extends EntityClass<infer P> ? IndexCallback<P> : IndexCallback<T>);
|
|
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;
|
|
@@ -37,4 +37,6 @@ export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner
|
|
|
37
37
|
deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
38
38
|
/** What to do when the reference to the target entity gets updated. */
|
|
39
39
|
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
40
|
+
/** Enable/disable foreign key constraint creation on this relation */
|
|
41
|
+
createForeignKeyConstraint?: boolean;
|
|
40
42
|
}
|
|
@@ -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);
|
|
@@ -27,4 +27,8 @@ export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner,
|
|
|
27
27
|
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
28
28
|
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
29
29
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
30
|
+
/** Enable/disable foreign key constraint creation on this relation */
|
|
31
|
+
createForeignKeyConstraint?: boolean;
|
|
32
|
+
/** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
|
|
33
|
+
foreignKeyName?: string;
|
|
30
34
|
}
|
|
@@ -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;
|
|
@@ -21,4 +21,8 @@ export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOp
|
|
|
21
21
|
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
22
22
|
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
23
23
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
24
|
+
/** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
|
|
25
|
+
foreignKeyName?: string;
|
|
26
|
+
/** Enable/disable foreign key constraint creation on this relation */
|
|
27
|
+
createForeignKeyConstraint?: boolean;
|
|
24
28
|
}
|
|
@@ -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`.
|
|
@@ -2,6 +2,7 @@ import type { TransactionOptions } from '../enums.js';
|
|
|
2
2
|
import type { ContextProvider } from '../typings.js';
|
|
3
3
|
type TransactionalOptions<T> = TransactionOptions & {
|
|
4
4
|
context?: ContextProvider<T>;
|
|
5
|
+
contextName?: string;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
8
|
* This decorator wraps the method with `em.transactional()`, so you can provide `TransactionOptions` just like with `em.transactional()`.
|
|
@@ -14,10 +14,10 @@ export function Transactional(options = {}) {
|
|
|
14
14
|
throw new Error('@Transactional() should be use with async functions');
|
|
15
15
|
}
|
|
16
16
|
descriptor.value = async function (...args) {
|
|
17
|
-
const { context, ...txOptions } = options;
|
|
17
|
+
const { context, contextName, ...txOptions } = options;
|
|
18
18
|
const em = (await resolveContextProvider(this, context))
|
|
19
|
-
|| TransactionContext.getEntityManager()
|
|
20
|
-
|| RequestContext.getEntityManager();
|
|
19
|
+
|| TransactionContext.getEntityManager(contextName)
|
|
20
|
+
|| RequestContext.getEntityManager(contextName);
|
|
21
21
|
if (!em) {
|
|
22
22
|
throw new Error(`@Transactional() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@Transactional(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
23
23
|
}
|
|
@@ -146,8 +146,11 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
|
|
|
146
146
|
hintComments?: string | string[];
|
|
147
147
|
loggerContext?: LogContext;
|
|
148
148
|
logging?: LoggingOptions;
|
|
149
|
+
/** @internal used to apply filters to the auto-joined relations */
|
|
150
|
+
em?: EntityManager;
|
|
149
151
|
}
|
|
150
|
-
export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
|
|
152
|
+
export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
|
|
153
|
+
includeCount?: I;
|
|
151
154
|
}
|
|
152
155
|
export interface FindOneOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
|
|
153
156
|
lockMode?: LockMode;
|
|
@@ -163,6 +166,7 @@ export interface NativeInsertUpdateOptions<T> {
|
|
|
163
166
|
schema?: string;
|
|
164
167
|
/** `nativeUpdate()` only option */
|
|
165
168
|
upsert?: boolean;
|
|
169
|
+
loggerContext?: LogContext;
|
|
166
170
|
}
|
|
167
171
|
export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOptions<T> {
|
|
168
172
|
processCollections?: boolean;
|
|
@@ -197,6 +201,8 @@ export interface CountOptions<T extends object, P extends string = never> {
|
|
|
197
201
|
hintComments?: string | string[];
|
|
198
202
|
loggerContext?: LogContext;
|
|
199
203
|
logging?: LoggingOptions;
|
|
204
|
+
/** @internal used to apply filters to the auto-joined relations */
|
|
205
|
+
em?: EntityManager;
|
|
200
206
|
}
|
|
201
207
|
export interface UpdateOptions<T> {
|
|
202
208
|
filters?: FilterOptions;
|
|
@@ -218,6 +224,7 @@ export interface LockOptions extends DriverMethodOptions {
|
|
|
218
224
|
export interface DriverMethodOptions {
|
|
219
225
|
ctx?: Transaction;
|
|
220
226
|
schema?: string;
|
|
227
|
+
loggerContext?: LogContext;
|
|
221
228
|
}
|
|
222
229
|
export interface GetReferenceOptions {
|
|
223
230
|
wrapped?: boolean;
|
|
@@ -6,6 +6,7 @@ export declare class ArrayCollection<T extends object, O extends object> {
|
|
|
6
6
|
protected readonly items: Set<T>;
|
|
7
7
|
protected initialized: boolean;
|
|
8
8
|
protected dirty: boolean;
|
|
9
|
+
protected partial: boolean;
|
|
9
10
|
protected snapshot: T[] | undefined;
|
|
10
11
|
protected _count?: number;
|
|
11
12
|
private _property?;
|
|
@@ -14,7 +15,7 @@ export declare class ArrayCollection<T extends object, O extends object> {
|
|
|
14
15
|
getItems(): T[];
|
|
15
16
|
toArray<TT extends T>(): EntityDTO<TT>[];
|
|
16
17
|
toJSON(): EntityDTO<T>[];
|
|
17
|
-
getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string): U[];
|
|
18
|
+
getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
|
|
18
19
|
add(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void;
|
|
19
20
|
/**
|
|
20
21
|
* @internal
|
|
@@ -25,7 +26,7 @@ export declare class ArrayCollection<T extends object, O extends object> {
|
|
|
25
26
|
/**
|
|
26
27
|
* @internal
|
|
27
28
|
*/
|
|
28
|
-
hydrate(items: T[], forcePropagate?: boolean): void;
|
|
29
|
+
hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
|
|
29
30
|
/**
|
|
30
31
|
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
31
32
|
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
@@ -83,6 +84,7 @@ export declare class ArrayCollection<T extends object, O extends object> {
|
|
|
83
84
|
count(): number;
|
|
84
85
|
isInitialized(fully?: boolean): boolean;
|
|
85
86
|
isDirty(): boolean;
|
|
87
|
+
isPartial(): boolean;
|
|
86
88
|
isEmpty(): boolean;
|
|
87
89
|
setDirty(dirty?: boolean): void;
|
|
88
90
|
get length(): number;
|
|
@@ -9,6 +9,7 @@ export class ArrayCollection {
|
|
|
9
9
|
items = new Set();
|
|
10
10
|
initialized = true;
|
|
11
11
|
dirty = false;
|
|
12
|
+
partial = false; // mark partially loaded collections, propagation is disabled for those
|
|
12
13
|
snapshot = []; // used to create a diff of the collection at commit time, undefined marks overridden values so we need to wipe when flushing
|
|
13
14
|
_count;
|
|
14
15
|
_property;
|
|
@@ -40,15 +41,22 @@ export class ArrayCollection {
|
|
|
40
41
|
}
|
|
41
42
|
getIdentifiers(field) {
|
|
42
43
|
const items = this.getItems();
|
|
44
|
+
const targetMeta = this.property.targetMeta;
|
|
43
45
|
if (items.length === 0) {
|
|
44
46
|
return [];
|
|
45
47
|
}
|
|
46
|
-
field ??=
|
|
48
|
+
field ??= targetMeta.compositePK ? targetMeta.primaryKeys : targetMeta.serializedPrimaryKey;
|
|
49
|
+
const cb = (i, f) => {
|
|
50
|
+
if (Utils.isEntity(i[f], true)) {
|
|
51
|
+
return wrap(i[f], true).getPrimaryKey();
|
|
52
|
+
}
|
|
53
|
+
return i[f];
|
|
54
|
+
};
|
|
47
55
|
return items.map(i => {
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
56
|
+
if (Array.isArray(field)) {
|
|
57
|
+
return field.map(f => cb(i, f));
|
|
50
58
|
}
|
|
51
|
-
return i
|
|
59
|
+
return cb(i, field);
|
|
52
60
|
});
|
|
53
61
|
}
|
|
54
62
|
add(entity, ...entities) {
|
|
@@ -100,11 +108,12 @@ export class ArrayCollection {
|
|
|
100
108
|
/**
|
|
101
109
|
* @internal
|
|
102
110
|
*/
|
|
103
|
-
hydrate(items, forcePropagate) {
|
|
111
|
+
hydrate(items, forcePropagate, partial) {
|
|
104
112
|
for (let i = 0; i < this.items.size; i++) {
|
|
105
113
|
delete this[i];
|
|
106
114
|
}
|
|
107
115
|
this.initialized = true;
|
|
116
|
+
this.partial = !!partial;
|
|
108
117
|
this.items.clear();
|
|
109
118
|
this._count = 0;
|
|
110
119
|
this.add(items);
|
|
@@ -267,6 +276,9 @@ export class ArrayCollection {
|
|
|
267
276
|
isDirty() {
|
|
268
277
|
return this.dirty;
|
|
269
278
|
}
|
|
279
|
+
isPartial() {
|
|
280
|
+
return this.partial;
|
|
281
|
+
}
|
|
270
282
|
isEmpty() {
|
|
271
283
|
return this.count() === 0;
|
|
272
284
|
}
|
|
@@ -383,7 +395,7 @@ export class ArrayCollection {
|
|
|
383
395
|
/** @ignore */
|
|
384
396
|
[inspect.custom](depth = 2) {
|
|
385
397
|
const object = { ...this };
|
|
386
|
-
const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_snapshot', '_lazyInitialized', '_em', 'readonly'];
|
|
398
|
+
const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_snapshot', '_lazyInitialized', '_em', 'readonly', 'partial'];
|
|
387
399
|
hidden.forEach(k => delete object[k]);
|
|
388
400
|
const ret = inspect(object, { depth });
|
|
389
401
|
const name = `${this.constructor.name}<${this.property?.type ?? 'unknown'}>`;
|
package/entity/Collection.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { EntityDTO, EntityKey, FilterQuery, Loaded, LoadedCollection, Popul
|
|
|
2
2
|
import { ArrayCollection } from './ArrayCollection.js';
|
|
3
3
|
import { Reference } from './Reference.js';
|
|
4
4
|
import type { Transaction } from '../connections/Connection.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
|
|
6
6
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
7
7
|
export interface MatchingOptions<T extends object, P extends string = never> extends FindOptions<T, P> {
|
|
8
8
|
where?: FilterQuery<T>;
|
|
@@ -12,7 +12,6 @@ export interface MatchingOptions<T extends object, P extends string = never> ext
|
|
|
12
12
|
export declare class Collection<T extends object, O extends object = object> extends ArrayCollection<T, O> {
|
|
13
13
|
private readonly?;
|
|
14
14
|
private _populated?;
|
|
15
|
-
private _em?;
|
|
16
15
|
private _snapshot?;
|
|
17
16
|
constructor(owner: O, items?: T[], initialized?: boolean);
|
|
18
17
|
/**
|
package/entity/Collection.js
CHANGED
|
@@ -7,7 +7,6 @@ import { helper } from './wrap.js';
|
|
|
7
7
|
export class Collection extends ArrayCollection {
|
|
8
8
|
readonly;
|
|
9
9
|
_populated;
|
|
10
|
-
_em;
|
|
11
10
|
// this is for some reason needed for TS, otherwise it can fail with `Type instantiation is excessively deep and possibly infinite.`
|
|
12
11
|
_snapshot;
|
|
13
12
|
constructor(owner, items, initialized = true) {
|
|
@@ -220,11 +219,21 @@ export class Collection extends ArrayCollection {
|
|
|
220
219
|
const em = this.getEntityManager();
|
|
221
220
|
if (options.dataloader ?? [DataloaderType.ALL, DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
|
|
222
221
|
const order = [...this.items]; // copy order of references
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
222
|
+
const orderBy = this.createOrderBy(options.orderBy);
|
|
223
|
+
const customOrder = orderBy.length > 0;
|
|
224
|
+
const pivotTable = this.property.kind === ReferenceKind.MANY_TO_MANY && em.getPlatform().usesPivotTable();
|
|
225
|
+
const loader = pivotTable ? 'colLoaderMtoN' : 'colLoader';
|
|
226
|
+
const items = await em[loader].load([
|
|
227
|
+
this,
|
|
228
|
+
{ ...options, orderBy },
|
|
229
|
+
]);
|
|
230
|
+
if (this.property.kind === ReferenceKind.MANY_TO_MANY) {
|
|
231
|
+
this.initialized = true;
|
|
232
|
+
this.dirty = false;
|
|
233
|
+
if (!customOrder) {
|
|
234
|
+
this.reorderItems(items, order);
|
|
235
|
+
}
|
|
236
|
+
return this;
|
|
228
237
|
}
|
|
229
238
|
this.items.clear();
|
|
230
239
|
let i = 0;
|
|
@@ -254,7 +263,7 @@ export class Collection extends ArrayCollection {
|
|
|
254
263
|
}
|
|
255
264
|
getEntityManager(items = [], required = true) {
|
|
256
265
|
const wrapped = helper(this.owner);
|
|
257
|
-
let em =
|
|
266
|
+
let em = wrapped.__em;
|
|
258
267
|
if (!em) {
|
|
259
268
|
for (const i of items) {
|
|
260
269
|
if (i && helper(i).__em) {
|
|
@@ -263,9 +272,6 @@ export class Collection extends ArrayCollection {
|
|
|
263
272
|
}
|
|
264
273
|
}
|
|
265
274
|
}
|
|
266
|
-
if (em) {
|
|
267
|
-
Object.defineProperty(this, '_em', { value: em });
|
|
268
|
-
}
|
|
269
275
|
if (!em && required) {
|
|
270
276
|
throw ValidationError.entityNotManaged(this.owner);
|
|
271
277
|
}
|
|
@@ -36,7 +36,7 @@ export interface AssignOptions<Convert extends boolean> {
|
|
|
36
36
|
*/
|
|
37
37
|
onlyProperties?: boolean;
|
|
38
38
|
/**
|
|
39
|
-
* With `onlyOwnProperties` enabled, to-many relations are skipped, and payloads of
|
|
39
|
+
* With `onlyOwnProperties` enabled, inverse sides of to-many relations are skipped, and payloads of other relations are converted
|
|
40
40
|
* to foreign keys. Defaults to `false`.
|
|
41
41
|
*/
|
|
42
42
|
onlyOwnProperties?: boolean;
|
package/entity/EntityAssigner.js
CHANGED
|
@@ -42,9 +42,17 @@ export class EntityAssigner {
|
|
|
42
42
|
}
|
|
43
43
|
const prop = { ...props[propName], name: propName };
|
|
44
44
|
if (prop && options.onlyOwnProperties) {
|
|
45
|
-
if ([ReferenceKind.
|
|
45
|
+
if ([ReferenceKind.ONE_TO_MANY].includes(prop.kind)) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
+
if ([ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
|
|
49
|
+
if (!prop.owner) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
else if (value?.map) {
|
|
53
|
+
value = value.map((v) => Utils.extractPK(v, prop.targetMeta));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
48
56
|
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
|
|
49
57
|
value = Utils.extractPK(value, prop.targetMeta);
|
|
50
58
|
}
|
|
@@ -4,6 +4,11 @@ import type { EntityComparator } from '../utils/EntityComparator.js';
|
|
|
4
4
|
export interface FactoryOptions {
|
|
5
5
|
initialized?: boolean;
|
|
6
6
|
newEntity?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Property `onCreate` hooks are normally executed during `flush` operation.
|
|
9
|
+
* With this option, they will be processed early inside `em.create()` method.
|
|
10
|
+
*/
|
|
11
|
+
processOnCreateHooksEarly?: boolean;
|
|
7
12
|
merge?: boolean;
|
|
8
13
|
refresh?: boolean;
|
|
9
14
|
convertCustomTypes?: boolean;
|
|
@@ -27,6 +32,7 @@ export declare class EntityFactory {
|
|
|
27
32
|
createEmbeddable<T extends object>(entityName: EntityName<T>, data: EntityData<T>, options?: Pick<FactoryOptions, 'newEntity' | 'convertCustomTypes'>): T;
|
|
28
33
|
getComparator(): EntityComparator;
|
|
29
34
|
private createEntity;
|
|
35
|
+
private assignDefaultValues;
|
|
30
36
|
private hydrate;
|
|
31
37
|
private findEntity;
|
|
32
38
|
private processDiscriminatorColumn;
|