@mikro-orm/core 7.0.0-dev.65 → 7.0.0-dev.67
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/Collection.d.ts +95 -27
- package/entity/Collection.js +413 -91
- package/entity/EntityFactory.js +1 -1
- package/entity/EntityValidator.js +2 -2
- package/entity/index.d.ts +0 -1
- package/entity/index.js +0 -1
- package/metadata/EntitySchema.js +3 -3
- package/metadata/MetadataDiscovery.d.ts +1 -0
- package/metadata/MetadataDiscovery.js +15 -4
- package/metadata/MetadataStorage.d.ts +0 -4
- package/metadata/MetadataStorage.js +6 -10
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +0 -10
- package/package.json +2 -2
- package/platforms/Platform.d.ts +1 -1
- package/platforms/Platform.js +2 -2
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +1 -2
- package/typings.d.ts +1 -1
- package/typings.js +1 -1
- package/unit-of-work/UnitOfWork.js +1 -1
- package/utils/Configuration.js +1 -1
- package/utils/EntityComparator.js +2 -2
- package/utils/QueryHelper.js +5 -5
- package/utils/Utils.d.ts +2 -50
- package/utils/Utils.js +2 -140
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -410
package/EntityManager.js
CHANGED
|
@@ -627,7 +627,7 @@ export class EntityManager {
|
|
|
627
627
|
where = await em.processWhere(entityName, where, options, 'read');
|
|
628
628
|
em.validator.validateEmptyWhere(where);
|
|
629
629
|
em.checkLockRequirements(options.lockMode, meta);
|
|
630
|
-
const isOptimisticLocking =
|
|
630
|
+
const isOptimisticLocking = options.lockMode == null || options.lockMode === LockMode.OPTIMISTIC;
|
|
631
631
|
if (entity && !em.shouldRefresh(meta, entity, options) && isOptimisticLocking) {
|
|
632
632
|
return em.lockAndPopulate(meta, entity, where, options);
|
|
633
633
|
}
|
|
@@ -1711,7 +1711,7 @@ export class EntityManager {
|
|
|
1711
1711
|
options.flags.push(QueryFlag.INFER_POPULATE);
|
|
1712
1712
|
return [];
|
|
1713
1713
|
}
|
|
1714
|
-
if (
|
|
1714
|
+
if (typeof field === 'string') {
|
|
1715
1715
|
return [{ field, strategy: options.strategy }];
|
|
1716
1716
|
}
|
|
1717
1717
|
return [field];
|
|
@@ -1818,7 +1818,7 @@ export class EntityManager {
|
|
|
1818
1818
|
config ??= this.config.get('resultCache').global;
|
|
1819
1819
|
if (config) {
|
|
1820
1820
|
const em = this.getContext();
|
|
1821
|
-
const expiration = Array.isArray(config) ? config[1] : (
|
|
1821
|
+
const expiration = Array.isArray(config) ? config[1] : (typeof config === 'number' ? config : undefined);
|
|
1822
1822
|
await em.resultCache.set(key.key, data instanceof Function ? data() : data, '', expiration);
|
|
1823
1823
|
}
|
|
1824
1824
|
}
|
package/entity/Collection.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
|
|
3
3
|
import { Reference } from './Reference.js';
|
|
4
4
|
import type { Transaction } from '../connections/Connection.js';
|
|
5
5
|
import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
|
|
@@ -9,10 +9,18 @@ export interface MatchingOptions<T extends object, P extends string = never> ext
|
|
|
9
9
|
store?: boolean;
|
|
10
10
|
ctx?: Transaction;
|
|
11
11
|
}
|
|
12
|
-
export declare class Collection<T extends object, O extends object = object>
|
|
12
|
+
export declare class Collection<T extends object, O extends object = object> {
|
|
13
|
+
readonly owner: O;
|
|
14
|
+
[k: number]: T;
|
|
15
|
+
protected readonly items: Set<T>;
|
|
16
|
+
protected initialized: boolean;
|
|
17
|
+
protected dirty: boolean;
|
|
18
|
+
protected partial: boolean;
|
|
19
|
+
protected snapshot: T[] | undefined;
|
|
13
20
|
private readonly?;
|
|
21
|
+
protected _count?: number;
|
|
22
|
+
private _property?;
|
|
14
23
|
private _populated?;
|
|
15
|
-
private _snapshot?;
|
|
16
24
|
constructor(owner: O, items?: T[], initialized?: boolean);
|
|
17
25
|
/**
|
|
18
26
|
* Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
|
|
@@ -41,57 +49,117 @@ export declare class Collection<T extends object, O extends object = object> ext
|
|
|
41
49
|
toJSON<TT extends T>(): EntityDTO<TT>[];
|
|
42
50
|
add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): number;
|
|
43
51
|
/**
|
|
44
|
-
*
|
|
52
|
+
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
53
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
54
|
+
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
55
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
45
56
|
*/
|
|
46
57
|
remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): number;
|
|
47
58
|
contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
|
|
48
59
|
count(): number;
|
|
49
60
|
isEmpty(): boolean;
|
|
61
|
+
shouldPopulate(populated?: boolean): boolean;
|
|
62
|
+
populated(populated?: boolean | undefined): void;
|
|
63
|
+
init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
|
|
64
|
+
private getEntityManager;
|
|
65
|
+
private createCondition;
|
|
66
|
+
private createOrderBy;
|
|
67
|
+
private createManyToManyCondition;
|
|
68
|
+
private createLoadCountCondition;
|
|
69
|
+
private checkInitialized;
|
|
70
|
+
/**
|
|
71
|
+
* re-orders items after searching with `$in` operator
|
|
72
|
+
*/
|
|
73
|
+
private reorderItems;
|
|
74
|
+
private cancelOrphanRemoval;
|
|
75
|
+
private validateModification;
|
|
76
|
+
toArray<TT extends T>(): EntityDTO<TT>[];
|
|
77
|
+
getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
addWithoutPropagation(entity: T): void;
|
|
82
|
+
set(items: Iterable<T | Reference<T>>): void;
|
|
83
|
+
private compare;
|
|
84
|
+
/**
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
|
|
88
|
+
/**
|
|
89
|
+
* Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
|
|
90
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
91
|
+
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
92
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
93
|
+
*/
|
|
94
|
+
removeAll(): void;
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
removeWithoutPropagation(entity: T): void;
|
|
50
99
|
/**
|
|
51
|
-
*
|
|
100
|
+
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
101
|
+
* If end is null it returns all elements from start to the end of the collection.
|
|
52
102
|
*/
|
|
53
103
|
slice(start?: number, end?: number): T[];
|
|
54
104
|
/**
|
|
55
|
-
*
|
|
105
|
+
* Tests for the existence of an element that satisfies the given predicate.
|
|
56
106
|
*/
|
|
57
107
|
exists(cb: (item: T) => boolean): boolean;
|
|
58
108
|
/**
|
|
59
|
-
*
|
|
109
|
+
* Returns the first element of this collection that satisfies the predicate.
|
|
60
110
|
*/
|
|
61
111
|
find(cb: (item: T, index: number) => boolean): T | undefined;
|
|
62
112
|
/**
|
|
63
|
-
*
|
|
113
|
+
* Extracts a subset of the collection items.
|
|
64
114
|
*/
|
|
65
115
|
filter(cb: (item: T, index: number) => boolean): T[];
|
|
66
116
|
/**
|
|
67
|
-
*
|
|
117
|
+
* Maps the collection items based on your provided mapper function.
|
|
68
118
|
*/
|
|
69
119
|
map<R>(mapper: (item: T, index: number) => R): R[];
|
|
70
120
|
/**
|
|
71
|
-
*
|
|
121
|
+
* Maps the collection items based on your provided mapper function to a single object.
|
|
122
|
+
*/
|
|
123
|
+
reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
|
|
124
|
+
/**
|
|
125
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
126
|
+
* If there are more items with the same key, only the first one will be present.
|
|
72
127
|
*/
|
|
73
128
|
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
|
|
74
129
|
/**
|
|
75
|
-
*
|
|
130
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
131
|
+
* If there are more items with the same key, only the first one will be present.
|
|
76
132
|
*/
|
|
77
133
|
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
private createManyToManyCondition;
|
|
85
|
-
private createLoadCountCondition;
|
|
86
|
-
private modify;
|
|
87
|
-
private checkInitialized;
|
|
134
|
+
isInitialized(fully?: boolean): boolean;
|
|
135
|
+
isDirty(): boolean;
|
|
136
|
+
isPartial(): boolean;
|
|
137
|
+
setDirty(dirty?: boolean): void;
|
|
138
|
+
get length(): number;
|
|
139
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
88
140
|
/**
|
|
89
|
-
*
|
|
141
|
+
* @internal
|
|
90
142
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
143
|
+
takeSnapshot(forcePropagate?: boolean): void;
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
getSnapshot(): T[] | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
get property(): EntityProperty;
|
|
152
|
+
/**
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
set property(prop: EntityProperty);
|
|
156
|
+
protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
157
|
+
protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
158
|
+
protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
159
|
+
protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
|
|
160
|
+
protected incrementCount(value: number): void;
|
|
161
|
+
/** @ignore */
|
|
162
|
+
[inspect.custom](depth?: number): string;
|
|
95
163
|
}
|
|
96
164
|
export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
|
|
97
165
|
dataloader?: boolean;
|