@mikro-orm/core 7.0.0-dev.83 → 7.0.0-dev.85
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 +0 -3
- package/EntityManager.js +1 -2
- package/entity/Collection.d.ts +0 -3
- package/entity/Collection.js +2 -2
- package/entity/EntityAssigner.js +2 -2
- package/entity/EntityHelper.js +3 -3
- package/entity/Reference.d.ts +0 -5
- package/entity/Reference.js +4 -6
- package/entity/WrappedEntity.d.ts +0 -3
- package/entity/WrappedEntity.js +1 -2
- package/errors.d.ts +4 -0
- package/errors.js +15 -1
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/logging/DefaultLogger.js +1 -0
- package/logging/index.d.ts +1 -0
- package/logging/index.js +1 -0
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/MetadataProvider.js +1 -1
- package/package.json +1 -1
- package/platforms/Platform.d.ts +0 -3
- package/platforms/Platform.js +1 -2
- package/types/EnumArrayType.js +1 -2
- package/types/Type.d.ts +0 -3
- package/types/Type.js +2 -2
- package/unit-of-work/ChangeSet.d.ts +0 -3
- package/unit-of-work/ChangeSet.js +2 -2
- package/utils/Configuration.d.ts +1 -1
- package/utils/Configuration.js +1 -1
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +2 -2
- package/utils/EntityComparator.js +4 -0
- package/utils/RawQueryFragment.d.ts +0 -9
- package/utils/RawQueryFragment.js +1 -2
- package/utils/Utils.js +1 -1
package/EntityManager.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { type Configuration } from './utils/Configuration.js';
|
|
3
2
|
import { Cursor } from './utils/Cursor.js';
|
|
4
3
|
import { EntityFactory } from './entity/EntityFactory.js';
|
|
@@ -553,8 +552,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
553
552
|
* if executed inside request context handler.
|
|
554
553
|
*/
|
|
555
554
|
get id(): number;
|
|
556
|
-
/** @ignore */
|
|
557
|
-
[inspect.custom](): string;
|
|
558
555
|
}
|
|
559
556
|
export interface CreateOptions<Convert extends boolean> {
|
|
560
557
|
/** creates a managed entity instance instead, bypassing the constructor call */
|
package/EntityManager.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { getOnConflictReturningFields, getWhereCondition } from './utils/upsert-utils.js';
|
|
3
2
|
import { Utils } from './utils/Utils.js';
|
|
4
3
|
import { Cursor } from './utils/Cursor.js';
|
|
@@ -1840,7 +1839,7 @@ export class EntityManager {
|
|
|
1840
1839
|
return this.getContext(false)._id;
|
|
1841
1840
|
}
|
|
1842
1841
|
/** @ignore */
|
|
1843
|
-
[inspect.custom]() {
|
|
1842
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
1844
1843
|
return `[EntityManager<${this.id}>]`;
|
|
1845
1844
|
}
|
|
1846
1845
|
}
|
package/entity/Collection.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
|
|
3
2
|
import { Reference } from './Reference.js';
|
|
4
3
|
import type { Transaction } from '../connections/Connection.js';
|
|
@@ -158,8 +157,6 @@ export declare class Collection<T extends object, O extends object = object> {
|
|
|
158
157
|
protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
159
158
|
protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
|
|
160
159
|
protected incrementCount(value: number): void;
|
|
161
|
-
/** @ignore */
|
|
162
|
-
[inspect.custom](depth?: number): string;
|
|
163
160
|
}
|
|
164
161
|
export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
|
|
165
162
|
dataloader?: boolean;
|
package/entity/Collection.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { Utils } from '../utils/Utils.js';
|
|
3
2
|
import { MetadataError, ValidationError } from '../errors.js';
|
|
4
3
|
import { DataloaderType, ReferenceKind } from '../enums.js';
|
|
5
4
|
import { Reference } from './Reference.js';
|
|
6
5
|
import { helper, wrap } from './wrap.js';
|
|
7
6
|
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
7
|
+
import { inspect } from '../logging/inspect.js';
|
|
8
8
|
export class Collection {
|
|
9
9
|
owner;
|
|
10
10
|
items = new Set();
|
|
@@ -695,7 +695,7 @@ export class Collection {
|
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
/** @ignore */
|
|
698
|
-
[inspect.custom](depth = 2) {
|
|
698
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
699
699
|
const object = { ...this };
|
|
700
700
|
const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_lazyInitialized', '_em', 'readonly', 'partial'];
|
|
701
701
|
hidden.forEach(k => delete object[k]);
|
package/entity/EntityAssigner.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { Collection } from './Collection.js';
|
|
3
2
|
import { Utils } from '../utils/Utils.js';
|
|
4
3
|
import { Reference } from './Reference.js';
|
|
@@ -6,6 +5,7 @@ import { ReferenceKind, SCALAR_TYPES } from '../enums.js';
|
|
|
6
5
|
import { validateProperty } from './validators.js';
|
|
7
6
|
import { helper, wrap } from './wrap.js';
|
|
8
7
|
import { EntityHelper } from './EntityHelper.js';
|
|
8
|
+
import { ValidationError } from '../errors.js';
|
|
9
9
|
export class EntityAssigner {
|
|
10
10
|
static assign(entity, data, options = {}) {
|
|
11
11
|
let opts = options;
|
|
@@ -181,7 +181,7 @@ export class EntityAssigner {
|
|
|
181
181
|
});
|
|
182
182
|
if (invalid.length > 0) {
|
|
183
183
|
const name = entity.constructor.name;
|
|
184
|
-
throw
|
|
184
|
+
throw ValidationError.invalidCollectionValues(name, prop.name, invalid);
|
|
185
185
|
}
|
|
186
186
|
if (Array.isArray(value)) {
|
|
187
187
|
collection.set(items);
|
package/entity/EntityHelper.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { EagerProps, EntityRepositoryType, HiddenProps, OptionalProps, PrimaryKeyProp, } from '../typings.js';
|
|
3
2
|
import { EntityTransformer } from '../serialization/EntityTransformer.js';
|
|
4
3
|
import { Reference } from './Reference.js';
|
|
@@ -6,6 +5,7 @@ import { Utils } from '../utils/Utils.js';
|
|
|
6
5
|
import { WrappedEntity } from './WrappedEntity.js';
|
|
7
6
|
import { ReferenceKind } from '../enums.js';
|
|
8
7
|
import { helper } from './wrap.js';
|
|
8
|
+
import { inspect } from '../logging/inspect.js';
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
@@ -110,7 +110,7 @@ export class EntityHelper {
|
|
|
110
110
|
}
|
|
111
111
|
static defineCustomInspect(meta) {
|
|
112
112
|
// @ts-ignore
|
|
113
|
-
meta.prototype[inspect.custom] ??= function (depth = 2) {
|
|
113
|
+
meta.prototype[Symbol.for('nodejs.util.inspect.custom')] ??= function (depth = 2) {
|
|
114
114
|
const object = {};
|
|
115
115
|
const keys = new Set(Utils.keys(this));
|
|
116
116
|
for (const prop of meta.props) {
|
|
@@ -129,7 +129,7 @@ export class EntityHelper {
|
|
|
129
129
|
.filter(prop => object[prop.name] === undefined)
|
|
130
130
|
.forEach(prop => delete object[prop.name]);
|
|
131
131
|
const ret = inspect(object, { depth });
|
|
132
|
-
let name =
|
|
132
|
+
let name = this.constructor.name;
|
|
133
133
|
const showEM = ['true', 't', '1'].includes(process.env.MIKRO_ORM_LOG_EM_ID?.toString().toLowerCase() ?? '');
|
|
134
134
|
if (showEM) {
|
|
135
135
|
if (helper(this).__em) {
|
package/entity/Reference.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { AddEager, AddOptional, Dictionary, EntityClass, EntityKey, EntityProperty, Loaded, LoadedReference, Primary, Ref } from '../typings.js';
|
|
3
2
|
import type { FindOneOptions, FindOneOrFailOptions } from '../drivers/IDatabaseDriver.js';
|
|
4
3
|
export declare class Reference<T extends object> {
|
|
@@ -43,8 +42,6 @@ export declare class Reference<T extends object> {
|
|
|
43
42
|
isInitialized(): boolean;
|
|
44
43
|
populated(populated?: boolean): void;
|
|
45
44
|
toJSON(...args: any[]): Dictionary;
|
|
46
|
-
/** @ignore */
|
|
47
|
-
[inspect.custom](depth?: number): string;
|
|
48
45
|
}
|
|
49
46
|
export declare class ScalarReference<Value> {
|
|
50
47
|
private value?;
|
|
@@ -66,8 +63,6 @@ export declare class ScalarReference<Value> {
|
|
|
66
63
|
bind<Entity extends object>(entity: Entity, property: EntityKey<Entity>): void;
|
|
67
64
|
unwrap(): Value | undefined;
|
|
68
65
|
isInitialized(): boolean;
|
|
69
|
-
/** @ignore */
|
|
70
|
-
[inspect.custom](): string;
|
|
71
66
|
}
|
|
72
67
|
export interface LoadReferenceOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends FindOneOptions<T, P, F, E> {
|
|
73
68
|
dataloader?: boolean;
|
package/entity/Reference.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { DataloaderType } from '../enums.js';
|
|
3
2
|
import { helper, wrap } from './wrap.js';
|
|
4
3
|
import { Utils } from '../utils/Utils.js';
|
|
5
4
|
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
6
5
|
import { NotFoundError } from '../errors.js';
|
|
6
|
+
import { inspect } from '../logging/inspect.js';
|
|
7
7
|
export class Reference {
|
|
8
8
|
entity;
|
|
9
9
|
property;
|
|
@@ -146,7 +146,7 @@ export class Reference {
|
|
|
146
146
|
return wrap(this.entity).toJSON(...args);
|
|
147
147
|
}
|
|
148
148
|
/** @ignore */
|
|
149
|
-
[inspect.custom](depth = 2) {
|
|
149
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
150
150
|
const object = { ...this };
|
|
151
151
|
const hidden = ['meta', 'property'];
|
|
152
152
|
hidden.forEach(k => delete object[k]);
|
|
@@ -192,9 +192,7 @@ export class ScalarReference {
|
|
|
192
192
|
const wrapped = helper(this.entity);
|
|
193
193
|
options.failHandler ??= wrapped.__em.config.get('findOneOrFailHandler');
|
|
194
194
|
const entityName = this.entity.constructor.name;
|
|
195
|
-
|
|
196
|
-
const whereString = typeof where === 'object' ? inspect(where) : where;
|
|
197
|
-
throw new NotFoundError(`${entityName} (${whereString}) failed to load property '${this.property}'`);
|
|
195
|
+
throw NotFoundError.failedToLoadProperty(entityName, this.property, wrapped.getPrimaryKey());
|
|
198
196
|
}
|
|
199
197
|
return ret;
|
|
200
198
|
}
|
|
@@ -215,7 +213,7 @@ export class ScalarReference {
|
|
|
215
213
|
}
|
|
216
214
|
/** @ignore */
|
|
217
215
|
/* v8 ignore next */
|
|
218
|
-
[inspect.custom]() {
|
|
216
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
219
217
|
return this.initialized ? `Ref<${inspect(this.value)}>` : `Ref<?>`;
|
|
220
218
|
}
|
|
221
219
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { PopulatePath } from '../enums.js';
|
|
2
|
-
import { inspect } from 'node:util';
|
|
3
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
4
3
|
import type { Dictionary, EntityData, EntityDictionary, EntityMetadata, IHydrator, EntityKey, PopulateOptions, Primary, AutoPath, Ref, AddEager, LoadedReference, EntityDTO, Loaded, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
5
4
|
import { Reference } from './Reference.js';
|
|
@@ -62,6 +61,4 @@ export declare class WrappedEntity<Entity extends object> {
|
|
|
62
61
|
get __platform(): import("@mikro-orm/knex").Platform;
|
|
63
62
|
get __config(): import("@mikro-orm/knex").Configuration<import("../drivers/IDatabaseDriver.js").IDatabaseDriver<import("@mikro-orm/knex").Connection>, EntityManager<import("../drivers/IDatabaseDriver.js").IDatabaseDriver<import("@mikro-orm/knex").Connection>>>;
|
|
64
63
|
get __primaryKeys(): Primary<Entity>[];
|
|
65
|
-
/** @ignore */
|
|
66
|
-
[inspect.custom](): string;
|
|
67
64
|
}
|
package/entity/WrappedEntity.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { Reference } from './Reference.js';
|
|
3
2
|
import { EntityTransformer } from '../serialization/EntityTransformer.js';
|
|
4
3
|
import { EntityAssigner } from './EntityAssigner.js';
|
|
@@ -149,7 +148,7 @@ export class WrappedEntity {
|
|
|
149
148
|
return Utils.getPrimaryKeyValues(this.entity, this.__meta);
|
|
150
149
|
}
|
|
151
150
|
/** @ignore */
|
|
152
|
-
[inspect.custom]() {
|
|
151
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
153
152
|
return `[WrappedEntity<${this.__meta.className}>]`;
|
|
154
153
|
}
|
|
155
154
|
}
|
package/errors.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
14
14
|
static notEntity(owner: AnyEntity, prop: EntityProperty, data: any): ValidationError;
|
|
15
15
|
static notDiscoveredEntity(data: any, meta?: EntityMetadata, action?: string): ValidationError;
|
|
16
16
|
static invalidPropertyName(entityName: string, invalid: string): ValidationError;
|
|
17
|
+
static invalidCollectionValues(entityName: string, propName: string, invalid: unknown): ValidationError;
|
|
18
|
+
static invalidEnumArrayItems(entityName: string, invalid: unknown): ValidationError;
|
|
17
19
|
static invalidType(type: Constructor<any>, value: any, mode: string): ValidationError;
|
|
18
20
|
static propertyRequired(entity: AnyEntity, property: EntityProperty): ValidationError;
|
|
19
21
|
static cannotModifyInverseCollection(owner: AnyEntity, property: EntityProperty): ValidationError;
|
|
@@ -25,6 +27,7 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
25
27
|
static cannotUseOperatorsInsideEmbeddables(className: string, propName: string, payload: unknown): ValidationError;
|
|
26
28
|
static cannotUseGroupOperatorsInsideScalars(className: string, propName: string, payload: unknown): ValidationError;
|
|
27
29
|
static invalidEmbeddableQuery(className: string, propName: string, embeddableType: string): ValidationError;
|
|
30
|
+
static invalidQueryCondition(cond: unknown): ValidationError;
|
|
28
31
|
}
|
|
29
32
|
export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
30
33
|
static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
|
|
@@ -64,6 +67,7 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
64
67
|
export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
65
68
|
static findOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
|
|
66
69
|
static findExactlyOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
|
|
70
|
+
static failedToLoadProperty(name: string, propName: string, where: unknown): NotFoundError;
|
|
67
71
|
}
|
|
68
72
|
export declare class TransactionStateError extends ValidationError {
|
|
69
73
|
static requiredTransactionNotFound(propagation: string): TransactionStateError;
|
package/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inspect } from '
|
|
1
|
+
import { inspect } from './logging/inspect.js';
|
|
2
2
|
export class ValidationError extends Error {
|
|
3
3
|
entity;
|
|
4
4
|
constructor(message, entity) {
|
|
@@ -48,6 +48,12 @@ export class ValidationError extends Error {
|
|
|
48
48
|
static invalidPropertyName(entityName, invalid) {
|
|
49
49
|
return new ValidationError(`Entity '${entityName}' does not have property '${invalid}'`);
|
|
50
50
|
}
|
|
51
|
+
static invalidCollectionValues(entityName, propName, invalid) {
|
|
52
|
+
return new ValidationError(`Invalid collection values provided for '${entityName}.${propName}' in ${entityName}.assign(): ${inspect(invalid)}`);
|
|
53
|
+
}
|
|
54
|
+
static invalidEnumArrayItems(entityName, invalid) {
|
|
55
|
+
return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
|
|
56
|
+
}
|
|
51
57
|
static invalidType(type, value, mode) {
|
|
52
58
|
const valueType = Object.prototype.toString.call(value).match(/\[object (\w+)]/)[1].toLowerCase();
|
|
53
59
|
if (value instanceof Date) {
|
|
@@ -95,6 +101,10 @@ export class ValidationError extends Error {
|
|
|
95
101
|
static invalidEmbeddableQuery(className, propName, embeddableType) {
|
|
96
102
|
return new ValidationError(`Invalid query for entity '${className}', property '${propName}' does not exist in embeddable '${embeddableType}'`);
|
|
97
103
|
}
|
|
104
|
+
/* v8 ignore next */
|
|
105
|
+
static invalidQueryCondition(cond) {
|
|
106
|
+
return new ValidationError(`Invalid query condition: ${inspect(cond, { depth: 5 })}`);
|
|
107
|
+
}
|
|
98
108
|
}
|
|
99
109
|
export class CursorError extends ValidationError {
|
|
100
110
|
static entityNotPopulated(entity, prop) {
|
|
@@ -213,6 +223,10 @@ export class NotFoundError extends ValidationError {
|
|
|
213
223
|
static findExactlyOneFailed(name, where) {
|
|
214
224
|
return new NotFoundError(`Wrong number of ${name} entities found for query ${inspect(where)}, expected exactly one`);
|
|
215
225
|
}
|
|
226
|
+
static failedToLoadProperty(name, propName, where) {
|
|
227
|
+
const whereString = typeof where === 'object' ? inspect(where) : where;
|
|
228
|
+
return new NotFoundError(`${name} (${whereString}) failed to load property '${propName}'`);
|
|
229
|
+
}
|
|
216
230
|
}
|
|
217
231
|
export class TransactionStateError extends ValidationError {
|
|
218
232
|
static requiredTransactionNotFound(propagation) {
|
package/events/EventManager.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export declare class EventManager {
|
|
|
6
6
|
private readonly entities;
|
|
7
7
|
private readonly cache;
|
|
8
8
|
private readonly subscribers;
|
|
9
|
-
constructor(subscribers: EventSubscriber
|
|
9
|
+
constructor(subscribers: Iterable<EventSubscriber>);
|
|
10
10
|
registerSubscriber(subscriber: EventSubscriber): void;
|
|
11
|
+
getSubscribers(): Set<EventSubscriber>;
|
|
11
12
|
dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
|
|
12
13
|
dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
|
|
13
14
|
dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
|
package/events/EventManager.js
CHANGED
|
@@ -4,21 +4,29 @@ export class EventManager {
|
|
|
4
4
|
listeners = {};
|
|
5
5
|
entities = new Map();
|
|
6
6
|
cache = new Map();
|
|
7
|
-
subscribers =
|
|
7
|
+
subscribers = new Set();
|
|
8
8
|
constructor(subscribers) {
|
|
9
|
-
|
|
9
|
+
for (const subscriber of subscribers) {
|
|
10
|
+
this.registerSubscriber(subscriber);
|
|
11
|
+
}
|
|
10
12
|
}
|
|
11
13
|
registerSubscriber(subscriber) {
|
|
12
|
-
this.subscribers.
|
|
14
|
+
if (this.subscribers.has(subscriber)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.subscribers.add(subscriber);
|
|
13
18
|
this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
|
|
14
19
|
this.cache.clear();
|
|
15
20
|
Utils.keys(EventType)
|
|
16
21
|
.filter(event => event in subscriber)
|
|
17
22
|
.forEach(event => {
|
|
18
|
-
this.listeners[event] ??=
|
|
19
|
-
this.listeners[event].
|
|
23
|
+
this.listeners[event] ??= new Set();
|
|
24
|
+
this.listeners[event].add(subscriber);
|
|
20
25
|
});
|
|
21
26
|
}
|
|
27
|
+
getSubscribers() {
|
|
28
|
+
return this.subscribers;
|
|
29
|
+
}
|
|
22
30
|
dispatchEvent(event, args, meta) {
|
|
23
31
|
const listeners = [];
|
|
24
32
|
const entity = args.entity;
|
|
@@ -30,9 +38,9 @@ export class EventManager {
|
|
|
30
38
|
const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
|
|
31
39
|
return handler.bind(entity);
|
|
32
40
|
}));
|
|
33
|
-
for (const listener of this.listeners[event]
|
|
41
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
34
42
|
const entities = this.entities.get(listener);
|
|
35
|
-
if (entities.
|
|
43
|
+
if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
|
|
36
44
|
listeners.push(listener[event].bind(listener));
|
|
37
45
|
}
|
|
38
46
|
}
|
|
@@ -51,9 +59,9 @@ export class EventManager {
|
|
|
51
59
|
this.cache.set(cacheKey, true);
|
|
52
60
|
return true;
|
|
53
61
|
}
|
|
54
|
-
for (const listener of this.listeners[event] ??
|
|
62
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
55
63
|
const entities = this.entities.get(listener);
|
|
56
|
-
if (entities.
|
|
64
|
+
if (entities.size === 0 || entities.has(meta.className)) {
|
|
57
65
|
this.cache.set(cacheKey, true);
|
|
58
66
|
return true;
|
|
59
67
|
}
|
|
@@ -66,8 +74,8 @@ export class EventManager {
|
|
|
66
74
|
}
|
|
67
75
|
getSubscribedEntities(listener) {
|
|
68
76
|
if (!listener.getSubscribedEntities) {
|
|
69
|
-
return
|
|
77
|
+
return new Set();
|
|
70
78
|
}
|
|
71
|
-
return listener.getSubscribedEntities().map(name => Utils.className(name));
|
|
79
|
+
return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
|
|
72
80
|
}
|
|
73
81
|
}
|
package/logging/DefaultLogger.js
CHANGED
|
@@ -60,6 +60,7 @@ export class DefaultLogger {
|
|
|
60
60
|
if (namespace === 'deprecated') {
|
|
61
61
|
const { ignoreDeprecations = false } = this.options;
|
|
62
62
|
return Array.isArray(ignoreDeprecations)
|
|
63
|
+
/* v8 ignore next */
|
|
63
64
|
? !ignoreDeprecations.includes(context?.label ?? '')
|
|
64
65
|
: !ignoreDeprecations;
|
|
65
66
|
}
|
package/logging/index.d.ts
CHANGED
package/logging/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let nodeInspect;
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function inspect(value, options) {
|
|
4
|
+
if (nodeInspect === undefined) {
|
|
5
|
+
/* v8 ignore else */
|
|
6
|
+
if (globalThis.process?.getBuiltinModule) {
|
|
7
|
+
nodeInspect = globalThis.process.getBuiltinModule('node:util').inspect;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/* v8 ignore else */
|
|
11
|
+
if (nodeInspect) {
|
|
12
|
+
return nodeInspect(value, options);
|
|
13
|
+
}
|
|
14
|
+
/* v8 ignore next */
|
|
15
|
+
return JSON.stringify(value, null, 2);
|
|
16
|
+
}
|
|
@@ -6,13 +6,13 @@ export class MetadataProvider {
|
|
|
6
6
|
}
|
|
7
7
|
loadEntityMetadata(meta) {
|
|
8
8
|
for (const prop of meta.props) {
|
|
9
|
+
/* v8 ignore next */
|
|
9
10
|
if (typeof prop.entity === 'string') {
|
|
10
11
|
prop.type = prop.entity;
|
|
11
12
|
}
|
|
12
13
|
else if (prop.entity) {
|
|
13
14
|
const tmp = prop.entity();
|
|
14
15
|
prop.type = Array.isArray(tmp) ? tmp.map(t => Utils.className(t)).sort().join(' | ') : Utils.className(tmp);
|
|
15
|
-
/* v8 ignore next */
|
|
16
16
|
}
|
|
17
17
|
else if (!prop.type && !(prop.enum && (prop.items?.length ?? 0) > 0)) {
|
|
18
18
|
throw new Error(`Please provide either 'type' or 'entity' attribute in ${meta.className}.${prop.name}.`);
|
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.85",
|
|
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",
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
3
2
|
import { type NamingStrategy } from '../naming-strategy/NamingStrategy.js';
|
|
4
3
|
import type { Constructor, EntityMetadata, EntityProperty, IPrimaryKey, ISchemaGenerator, PopulateOptions, Primary, SimpleColumnMeta } from '../typings.js';
|
|
@@ -221,6 +220,4 @@ export declare abstract class Platform {
|
|
|
221
220
|
* @internal
|
|
222
221
|
*/
|
|
223
222
|
clone(): this;
|
|
224
|
-
/** @ignore */
|
|
225
|
-
[inspect.custom](): string;
|
|
226
223
|
}
|
package/platforms/Platform.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { clone } from '../utils/clone.js';
|
|
3
2
|
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
4
3
|
import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
|
|
@@ -499,7 +498,7 @@ export class Platform {
|
|
|
499
498
|
}
|
|
500
499
|
/** @ignore */
|
|
501
500
|
/* v8 ignore next */
|
|
502
|
-
[inspect.custom]() {
|
|
501
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
503
502
|
return `[${this.constructor.name}]`;
|
|
504
503
|
}
|
|
505
504
|
}
|
package/types/EnumArrayType.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { ArrayType } from './ArrayType.js';
|
|
3
2
|
import { ValidationError } from '../errors.js';
|
|
4
3
|
function mapHydrator(items, hydrate) {
|
|
@@ -19,7 +18,7 @@ export class EnumArrayType extends ArrayType {
|
|
|
19
18
|
if (Array.isArray(value) && Array.isArray(this.items)) {
|
|
20
19
|
const invalid = value.filter(v => !this.items.includes(v));
|
|
21
20
|
if (invalid.length > 0) {
|
|
22
|
-
throw
|
|
21
|
+
throw ValidationError.invalidEnumArrayItems(this.owner, invalid);
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
return super.convertToDatabaseValue(value, platform, context);
|
package/types/Type.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { Platform } from '../platforms/Platform.js';
|
|
3
2
|
import type { Constructor, EntityMetadata, EntityProperty } from '../typings.js';
|
|
4
3
|
export interface TransformContext {
|
|
@@ -79,6 +78,4 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
|
|
|
79
78
|
* Checks whether the argument is instance of `Type`.
|
|
80
79
|
*/
|
|
81
80
|
static isMappedType(data: any): data is Type<any>;
|
|
82
|
-
/** @ignore */
|
|
83
|
-
[inspect.custom](depth?: number): string;
|
|
84
81
|
}
|
package/types/Type.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inspect } from '
|
|
1
|
+
import { inspect } from '../logging/inspect.js';
|
|
2
2
|
export class Type {
|
|
3
3
|
static types = new Map();
|
|
4
4
|
platform;
|
|
@@ -65,7 +65,7 @@ export class Type {
|
|
|
65
65
|
return !!data?.__mappedType;
|
|
66
66
|
}
|
|
67
67
|
/** @ignore */
|
|
68
|
-
[inspect.custom](depth = 2) {
|
|
68
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
69
69
|
const object = { ...this };
|
|
70
70
|
const hidden = ['prop', 'platform', 'meta'];
|
|
71
71
|
hidden.forEach(k => delete object[k]);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { EntityData, EntityMetadata, EntityDictionary, Primary } from '../typings.js';
|
|
3
2
|
export declare class ChangeSet<T extends object> {
|
|
4
3
|
entity: T;
|
|
@@ -10,8 +9,6 @@ export declare class ChangeSet<T extends object> {
|
|
|
10
9
|
constructor(entity: T, type: ChangeSetType, payload: EntityDictionary<T>, meta: EntityMetadata<T>);
|
|
11
10
|
getPrimaryKey(object?: boolean): Primary<T> | null;
|
|
12
11
|
getSerializedPrimaryKey(): string | null;
|
|
13
|
-
/** @ignore */
|
|
14
|
-
[inspect.custom](depth?: number): string;
|
|
15
12
|
}
|
|
16
13
|
export interface ChangeSet<T> {
|
|
17
14
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { helper } from '../entity/wrap.js';
|
|
3
2
|
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
import { inspect } from '../logging/inspect.js';
|
|
4
4
|
export class ChangeSet {
|
|
5
5
|
entity;
|
|
6
6
|
type;
|
|
@@ -46,7 +46,7 @@ export class ChangeSet {
|
|
|
46
46
|
return this.serializedPrimaryKey;
|
|
47
47
|
}
|
|
48
48
|
/** @ignore */
|
|
49
|
-
[inspect.custom](depth = 2) {
|
|
49
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
50
50
|
const object = { ...this };
|
|
51
51
|
const hidden = ['meta', 'serializedPrimaryKey'];
|
|
52
52
|
hidden.forEach(k => delete object[k]);
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -480,7 +480,7 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
480
480
|
* Event subscribers to register.
|
|
481
481
|
* Can be class references or instances.
|
|
482
482
|
*/
|
|
483
|
-
subscribers?:
|
|
483
|
+
subscribers?: Iterable<EventSubscriber | Constructor<EventSubscriber>>;
|
|
484
484
|
/**
|
|
485
485
|
* Global entity filters to apply.
|
|
486
486
|
* Filters are applied by default unless explicitly disabled.
|
package/utils/Configuration.js
CHANGED
|
@@ -319,7 +319,7 @@ export class Configuration {
|
|
|
319
319
|
if (!this.options.filtersOnRelations) {
|
|
320
320
|
this.options.autoJoinRefsForFilters ??= false;
|
|
321
321
|
}
|
|
322
|
-
this.options.subscribers =
|
|
322
|
+
this.options.subscribers = [...this.options.subscribers].map(subscriber => {
|
|
323
323
|
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
324
324
|
});
|
|
325
325
|
this.sync();
|
package/utils/Cursor.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { EntityMetadata, FilterObject, Loaded } from '../typings.js';
|
|
3
2
|
import type { FindByCursorOptions, OrderDefinition } from '../drivers/IDatabaseDriver.js';
|
|
4
3
|
import { type QueryOrder } from '../enums.js';
|
|
@@ -71,6 +70,4 @@ export declare class Cursor<Entity extends object, Hint extends string = never,
|
|
|
71
70
|
static encode(value: unknown[]): string;
|
|
72
71
|
static decode(value: string): unknown[];
|
|
73
72
|
static getDefinition<Entity extends object>(meta: EntityMetadata<Entity>, orderBy: OrderDefinition<Entity>): [never, QueryOrder][];
|
|
74
|
-
/** @ignore */
|
|
75
|
-
[inspect.custom](): string;
|
|
76
73
|
}
|
package/utils/Cursor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { Utils } from './Utils.js';
|
|
3
2
|
import { ReferenceKind } from '../enums.js';
|
|
4
3
|
import { Reference } from '../entity/Reference.js';
|
|
5
4
|
import { helper } from '../entity/wrap.js';
|
|
6
5
|
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
7
6
|
import { CursorError } from '../errors.js';
|
|
7
|
+
import { inspect } from '../logging/inspect.js';
|
|
8
8
|
/**
|
|
9
9
|
* As an alternative to the offset-based pagination with `limit` and `offset`, we can paginate based on a cursor.
|
|
10
10
|
* A cursor is an opaque string that defines a specific place in ordered entity graph. You can use `em.findByCursor()`
|
|
@@ -164,7 +164,7 @@ export class Cursor {
|
|
|
164
164
|
}
|
|
165
165
|
/** @ignore */
|
|
166
166
|
/* v8 ignore next */
|
|
167
|
-
[inspect.custom]() {
|
|
167
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
168
168
|
const type = this.items[0]?.constructor.name;
|
|
169
169
|
const { items, startCursor, endCursor, hasPrevPage, hasNextPage, totalCount, length } = this;
|
|
170
170
|
const options = inspect({ startCursor, endCursor, totalCount, hasPrevPage, hasNextPage, items, length }, { depth: 0 });
|
|
@@ -285,10 +285,14 @@ export class EntityComparator {
|
|
|
285
285
|
lines.push(`${padding} if (${value} == null || ${value} instanceof Date) {`);
|
|
286
286
|
lines.push(`${padding} ${key} = ${value};`);
|
|
287
287
|
if (!tz || tz === 'local') {
|
|
288
|
+
lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
|
|
289
|
+
lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
|
|
288
290
|
lines.push(`${padding} } else {`);
|
|
289
291
|
lines.push(`${padding} ${key} = parseDate(${value});`);
|
|
290
292
|
}
|
|
291
293
|
else {
|
|
294
|
+
lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
|
|
295
|
+
lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
|
|
292
296
|
lines.push(`${padding} } else if (typeof ${value} === 'number' || ${value}.includes('+') || ${value}.lastIndexOf('-') > 10 || ${value}.endsWith('Z')) {`);
|
|
293
297
|
lines.push(`${padding} ${key} = parseDate(${value});`);
|
|
294
298
|
lines.push(`${padding} } else {`);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { AnyString, Dictionary, EntityKey } from '../typings.js';
|
|
3
2
|
export declare class RawQueryFragment {
|
|
4
3
|
#private;
|
|
@@ -19,14 +18,6 @@ export declare class RawQueryFragment {
|
|
|
19
18
|
static isKnownFragment(key: string | RawQueryFragment): boolean;
|
|
20
19
|
static getKnownFragment(key: string | RawQueryFragment, cleanup?: boolean): RawQueryFragment | undefined;
|
|
21
20
|
static remove(key: string): void;
|
|
22
|
-
/** @ignore */
|
|
23
|
-
[inspect.custom](): {
|
|
24
|
-
sql: string;
|
|
25
|
-
params: unknown[];
|
|
26
|
-
} | {
|
|
27
|
-
sql: string;
|
|
28
|
-
params?: undefined;
|
|
29
|
-
};
|
|
30
21
|
}
|
|
31
22
|
export { RawQueryFragment as Raw };
|
|
32
23
|
export declare function isRaw(value: unknown): value is RawQueryFragment;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { inspect } from 'node:util';
|
|
3
2
|
import { Utils } from './Utils.js';
|
|
4
3
|
export class RawQueryFragment {
|
|
5
4
|
sql;
|
|
@@ -80,7 +79,7 @@ export class RawQueryFragment {
|
|
|
80
79
|
}
|
|
81
80
|
/** @ignore */
|
|
82
81
|
/* v8 ignore next */
|
|
83
|
-
[inspect.custom]() {
|
|
82
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
84
83
|
if (this.params) {
|
|
85
84
|
return { sql: this.sql, params: this.params };
|
|
86
85
|
}
|