@mikro-orm/core 7.0.0-dev.7 → 7.0.0-dev.71
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 +85 -42
- package/EntityManager.js +282 -194
- package/MikroORM.d.ts +11 -29
- package/MikroORM.js +33 -127
- package/README.md +3 -2
- package/cache/FileCacheAdapter.js +1 -2
- package/connections/Connection.d.ts +11 -7
- package/connections/Connection.js +16 -14
- package/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +13 -4
- package/drivers/IDatabaseDriver.d.ts +27 -5
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +98 -30
- package/entity/Collection.js +432 -93
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +9 -1
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +63 -40
- package/entity/EntityHelper.js +26 -9
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +69 -36
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/EntityValidator.js +4 -4
- package/entity/Reference.d.ts +9 -7
- package/entity/Reference.js +32 -5
- package/entity/WrappedEntity.d.ts +0 -2
- package/entity/WrappedEntity.js +1 -5
- package/entity/defineEntity.d.ts +549 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +2 -1
- package/entity/index.js +2 -1
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +15 -3
- package/enums.d.ts +20 -5
- package/enums.js +13 -0
- package/errors.d.ts +6 -1
- package/errors.js +14 -4
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +35 -24
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +9 -13
- package/metadata/EntitySchema.js +44 -26
- package/metadata/MetadataDiscovery.d.ts +6 -7
- package/metadata/MetadataDiscovery.js +161 -162
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +15 -0
- package/metadata/MetadataStorage.d.ts +0 -4
- package/metadata/MetadataStorage.js +6 -10
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +4 -13
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +39 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +1 -1
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
- package/naming-strategy/AbstractNamingStrategy.js +7 -1
- package/naming-strategy/NamingStrategy.d.ts +11 -1
- package/package.json +11 -10
- package/platforms/Platform.d.ts +6 -10
- package/platforms/Platform.js +6 -22
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +29 -11
- package/serialization/EntityTransformer.js +22 -12
- package/serialization/SerializationContext.js +14 -11
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +1 -2
- package/types/BigIntType.d.ts +8 -6
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +1 -1
- package/types/DoubleType.js +1 -1
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +0 -3
- package/types/index.d.ts +1 -1
- package/typings.d.ts +112 -77
- package/typings.js +32 -32
- package/unit-of-work/ChangeSetComputer.js +8 -3
- package/unit-of-work/ChangeSetPersister.d.ts +4 -2
- package/unit-of-work/ChangeSetPersister.js +37 -16
- package/unit-of-work/UnitOfWork.d.ts +8 -1
- package/unit-of-work/UnitOfWork.js +111 -54
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +10 -8
- package/utils/Configuration.d.ts +200 -191
- package/utils/Configuration.js +141 -152
- package/utils/ConfigurationLoader.d.ts +3 -44
- package/utils/ConfigurationLoader.js +26 -239
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +3 -0
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +53 -7
- package/utils/EntityComparator.d.ts +8 -4
- package/utils/EntityComparator.js +107 -60
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +69 -8
- package/utils/RawQueryFragment.d.ts +36 -4
- package/utils/RawQueryFragment.js +34 -13
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +17 -84
- package/utils/Utils.js +132 -252
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/upsert-utils.d.ts +7 -2
- package/utils/upsert-utils.js +52 -1
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -402
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/entity/Reference.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
import type { AddEager, Dictionary, EntityClass, EntityKey, EntityProperty, Loaded, LoadedReference, Primary, Ref } from '../typings.js';
|
|
2
|
+
import type { AddEager, AddOptional, Dictionary, EntityClass, EntityKey, EntityProperty, Loaded, LoadedReference, Primary, Ref } from '../typings.js';
|
|
3
3
|
import type { FindOneOptions, FindOneOrFailOptions } from '../drivers/IDatabaseDriver.js';
|
|
4
4
|
export declare class Reference<T extends object> {
|
|
5
5
|
private entity;
|
|
6
|
+
private property?;
|
|
6
7
|
constructor(entity: T);
|
|
7
8
|
static create<T extends object>(entity: T | Ref<T>): Ref<T>;
|
|
8
9
|
static createFromPK<T extends object>(entityType: EntityClass<T>, pk: Primary<T>, options?: {
|
|
@@ -56,6 +57,11 @@ export declare class ScalarReference<Value> {
|
|
|
56
57
|
* Returns either the whole entity, or the requested property.
|
|
57
58
|
*/
|
|
58
59
|
load(options?: Omit<LoadReferenceOptions<any, any>, 'populate' | 'fields' | 'exclude'>): Promise<Value | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Ensures the underlying entity is loaded first (without reloading it if it already is loaded).
|
|
62
|
+
* Returns the entity or throws an error just like `em.findOneOrFail()` (and respects the same config options).
|
|
63
|
+
*/
|
|
64
|
+
loadOrFail(options?: Omit<LoadReferenceOrFailOptions<any, any>, 'populate' | 'fields' | 'exclude'>): Promise<Value>;
|
|
59
65
|
set(value: Value): void;
|
|
60
66
|
bind<Entity extends object>(entity: Entity, property: EntityKey<Entity>): void;
|
|
61
67
|
unwrap(): Value | undefined;
|
|
@@ -72,15 +78,11 @@ export interface LoadReferenceOrFailOptions<T extends object, P extends string =
|
|
|
72
78
|
/**
|
|
73
79
|
* shortcut for `wrap(entity).toReference()`
|
|
74
80
|
*/
|
|
75
|
-
export declare function ref<
|
|
81
|
+
export declare function ref<I extends unknown | Ref<unknown> | undefined | null, T extends I & {}>(entity: I): Ref<T> & LoadedReference<Loaded<T, AddEager<T>>> | AddOptional<typeof entity>;
|
|
76
82
|
/**
|
|
77
83
|
* shortcut for `Reference.createFromPK(entityType, pk)`
|
|
78
84
|
*/
|
|
79
|
-
export declare function ref<T, PKV extends Primary<T> = Primary<T>>(entityType: EntityClass<T>, pk
|
|
80
|
-
/**
|
|
81
|
-
* shortcut for `wrap(entity).toReference()`
|
|
82
|
-
*/
|
|
83
|
-
export declare function ref<T>(value: T | Ref<T>): Ref<T> & LoadedReference<Loaded<T, AddEager<T>>>;
|
|
85
|
+
export declare function ref<I extends unknown | undefined | null, T, PKV extends Primary<T> = Primary<T>>(entityType: EntityClass<T>, pk: I): Ref<T> | AddOptional<typeof pk>;
|
|
84
86
|
/**
|
|
85
87
|
* shortcut for `Reference.createNakedFromPK(entityType, pk)`
|
|
86
88
|
*/
|
package/entity/Reference.js
CHANGED
|
@@ -2,8 +2,11 @@ import { inspect } from 'node:util';
|
|
|
2
2
|
import { DataloaderType } from '../enums.js';
|
|
3
3
|
import { helper, wrap } from './wrap.js';
|
|
4
4
|
import { Utils } from '../utils/Utils.js';
|
|
5
|
+
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
6
|
+
import { NotFoundError } from '../errors.js';
|
|
5
7
|
export class Reference {
|
|
6
8
|
entity;
|
|
9
|
+
property;
|
|
7
10
|
constructor(entity) {
|
|
8
11
|
this.entity = entity;
|
|
9
12
|
this.set(entity);
|
|
@@ -33,10 +36,15 @@ export class Reference {
|
|
|
33
36
|
}
|
|
34
37
|
static createFromPK(entityType, pk, options) {
|
|
35
38
|
const ref = this.createNakedFromPK(entityType, pk, options);
|
|
36
|
-
return helper(ref)
|
|
39
|
+
return helper(ref)?.toReference() ?? ref;
|
|
37
40
|
}
|
|
38
41
|
static createNakedFromPK(entityType, pk, options) {
|
|
39
42
|
const factory = entityType.prototype.__factory;
|
|
43
|
+
if (!factory) {
|
|
44
|
+
// this can happen only if `ref()` is used as a property initializer, and the value is important only for the
|
|
45
|
+
// inference of defaults, so it's fine to return it directly without wrapping with `Reference` class
|
|
46
|
+
return pk;
|
|
47
|
+
}
|
|
40
48
|
const entity = factory.createReference(entityType, pk, {
|
|
41
49
|
merge: false,
|
|
42
50
|
convertCustomTypes: false,
|
|
@@ -58,7 +66,9 @@ export class Reference {
|
|
|
58
66
|
*/
|
|
59
67
|
static wrapReference(entity, prop) {
|
|
60
68
|
if (entity && prop.ref && !Reference.isReference(entity)) {
|
|
61
|
-
|
|
69
|
+
const ref = Reference.create(entity);
|
|
70
|
+
ref.property = prop;
|
|
71
|
+
return ref;
|
|
62
72
|
}
|
|
63
73
|
return entity;
|
|
64
74
|
}
|
|
@@ -78,13 +88,14 @@ export class Reference {
|
|
|
78
88
|
if (!wrapped.__em) {
|
|
79
89
|
return this.entity;
|
|
80
90
|
}
|
|
91
|
+
options = { ...options, filters: QueryHelper.mergePropertyFilters(this.property?.filters, options.filters) };
|
|
81
92
|
if (this.isInitialized() && !options.refresh && options.populate) {
|
|
82
93
|
await wrapped.__em.populate(this.entity, options.populate, options);
|
|
83
94
|
}
|
|
84
95
|
if (!this.isInitialized() || options.refresh) {
|
|
85
96
|
if (options.dataloader ?? [DataloaderType.ALL, DataloaderType.REFERENCE].includes(wrapped.__em.config.getDataloaderType())) {
|
|
86
|
-
|
|
87
|
-
return
|
|
97
|
+
const dataLoader = await wrapped.__em.getDataLoader('ref');
|
|
98
|
+
return dataLoader.load([this, options]);
|
|
88
99
|
}
|
|
89
100
|
return wrapped.init(options);
|
|
90
101
|
}
|
|
@@ -137,7 +148,7 @@ export class Reference {
|
|
|
137
148
|
/** @ignore */
|
|
138
149
|
[inspect.custom](depth = 2) {
|
|
139
150
|
const object = { ...this };
|
|
140
|
-
const hidden = ['meta'];
|
|
151
|
+
const hidden = ['meta', 'property'];
|
|
141
152
|
hidden.forEach(k => delete object[k]);
|
|
142
153
|
const ret = inspect(object, { depth });
|
|
143
154
|
const wrapped = helper(this.entity);
|
|
@@ -171,6 +182,22 @@ export class ScalarReference {
|
|
|
171
182
|
}
|
|
172
183
|
return this.value;
|
|
173
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Ensures the underlying entity is loaded first (without reloading it if it already is loaded).
|
|
187
|
+
* Returns the entity or throws an error just like `em.findOneOrFail()` (and respects the same config options).
|
|
188
|
+
*/
|
|
189
|
+
async loadOrFail(options = {}) {
|
|
190
|
+
const ret = await this.load(options);
|
|
191
|
+
if (ret == null) {
|
|
192
|
+
const wrapped = helper(this.entity);
|
|
193
|
+
options.failHandler ??= wrapped.__em.config.get('findOneOrFailHandler');
|
|
194
|
+
const entityName = this.entity.constructor.name;
|
|
195
|
+
const where = wrapped.getPrimaryKey();
|
|
196
|
+
const whereString = typeof where === 'object' ? inspect(where) : where;
|
|
197
|
+
throw new NotFoundError(`${entityName} (${whereString}) failed to load property '${this.property}'`);
|
|
198
|
+
}
|
|
199
|
+
return ret;
|
|
200
|
+
}
|
|
174
201
|
set(value) {
|
|
175
202
|
this.value = value;
|
|
176
203
|
this.initialized = true;
|
|
@@ -11,7 +11,6 @@ import { type SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
|
11
11
|
import type { FindOneOptions, LoadHint } from '../drivers/IDatabaseDriver.js';
|
|
12
12
|
export declare class WrappedEntity<Entity extends object> {
|
|
13
13
|
__initialized: boolean;
|
|
14
|
-
__touched: boolean;
|
|
15
14
|
__populated?: boolean;
|
|
16
15
|
__managed?: boolean;
|
|
17
16
|
__onLoadFired?: boolean;
|
|
@@ -41,7 +40,6 @@ export declare class WrappedEntity<Entity extends object> {
|
|
|
41
40
|
private readonly pkGetterConverted?;
|
|
42
41
|
constructor(entity: Entity, hydrator: IHydrator, pkGetter?: (e: Entity) => Primary<Entity>, pkSerializer?: (e: Entity) => string, pkGetterConverted?: (e: Entity) => Primary<Entity>);
|
|
43
42
|
isInitialized(): boolean;
|
|
44
|
-
isTouched(): boolean;
|
|
45
43
|
isManaged(): boolean;
|
|
46
44
|
populated(populated?: boolean | undefined): void;
|
|
47
45
|
setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
package/entity/WrappedEntity.js
CHANGED
|
@@ -15,7 +15,6 @@ export class WrappedEntity {
|
|
|
15
15
|
this.pkSerializer = pkSerializer;
|
|
16
16
|
this.pkGetterConverted = pkGetterConverted;
|
|
17
17
|
this.__initialized = true;
|
|
18
|
-
this.__touched = false;
|
|
19
18
|
this.__serializationContext = {};
|
|
20
19
|
this.__loadedProperties = new Set();
|
|
21
20
|
this.__data = {};
|
|
@@ -24,9 +23,6 @@ export class WrappedEntity {
|
|
|
24
23
|
isInitialized() {
|
|
25
24
|
return this.__initialized;
|
|
26
25
|
}
|
|
27
|
-
isTouched() {
|
|
28
|
-
return this.__touched;
|
|
29
|
-
}
|
|
30
26
|
isManaged() {
|
|
31
27
|
return !!this.__managed;
|
|
32
28
|
}
|
|
@@ -150,7 +146,7 @@ export class WrappedEntity {
|
|
|
150
146
|
return this.__em?.config ?? this.entity.__config;
|
|
151
147
|
}
|
|
152
148
|
get __primaryKeys() {
|
|
153
|
-
return Utils.getPrimaryKeyValues(this.entity, this.__meta
|
|
149
|
+
return Utils.getPrimaryKeyValues(this.entity, this.__meta);
|
|
154
150
|
}
|
|
155
151
|
/** @ignore */
|
|
156
152
|
[inspect.custom]() {
|