@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321
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 +71 -63
- package/EntityManager.js +365 -283
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -142
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +1 -2
- package/cache/FileCacheAdapter.js +19 -14
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +101 -29
- package/entity/Collection.js +473 -115
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +7 -1
- package/entity/EntityFactory.js +116 -64
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +11 -10
- package/entity/EntityLoader.js +264 -102
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +2 -6
- package/entity/Reference.js +52 -19
- package/entity/WrappedEntity.d.ts +3 -8
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +525 -311
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +20 -10
- package/errors.js +63 -31
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +24 -13
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +105 -46
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +5 -7
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +64 -9
- package/metadata/MetadataDiscovery.js +867 -354
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +72 -41
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +53 -29
- package/serialization/EntityTransformer.js +33 -21
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +4 -4
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +3 -8
- package/unit-of-work/ChangeSetComputer.js +49 -26
- package/unit-of-work/ChangeSetPersister.d.ts +13 -12
- package/unit-of-work/ChangeSetPersister.js +107 -44
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +34 -4
- package/unit-of-work/UnitOfWork.js +294 -107
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +796 -211
- package/utils/Configuration.js +160 -197
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +29 -14
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +16 -9
- package/utils/EntityComparator.js +202 -96
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -7
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +106 -401
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +34 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- 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 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- 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 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- 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 -28
- 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 -14
- 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 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- 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
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import type { EntityMetadata } from '../typings.js';
|
|
2
2
|
import type { Logger } from '../logging/Logger.js';
|
|
3
|
+
import type { SyncCacheAdapter } from '../cache/CacheAdapter.js';
|
|
4
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
3
5
|
export interface IConfiguration {
|
|
4
6
|
get(key: string, defaultValue?: any): any;
|
|
5
7
|
getLogger(): Logger;
|
|
8
|
+
getMetadataCacheAdapter(): SyncCacheAdapter;
|
|
9
|
+
getPlatform(): Platform;
|
|
6
10
|
}
|
|
7
|
-
export declare
|
|
11
|
+
export declare class MetadataProvider {
|
|
8
12
|
protected readonly config: IConfiguration;
|
|
9
13
|
constructor(config: IConfiguration);
|
|
10
|
-
|
|
14
|
+
loadEntityMetadata(meta: EntityMetadata): void;
|
|
11
15
|
loadFromCache(meta: EntityMetadata, cache: EntityMetadata): void;
|
|
16
|
+
static useCache(): boolean;
|
|
12
17
|
useCache(): boolean;
|
|
18
|
+
saveToCache(meta: EntityMetadata): void;
|
|
19
|
+
getCachedMetadata<T>(meta: Pick<EntityMetadata<T>, 'className' | 'path' | 'root'>, root: EntityMetadata<T>): EntityMetadata<T> | undefined;
|
|
20
|
+
combineCache(): void;
|
|
21
|
+
getCacheKey(meta: Pick<EntityMetadata, 'className' | 'path'>): string;
|
|
13
22
|
}
|
|
@@ -1,20 +1,89 @@
|
|
|
1
1
|
import { Utils } from '../utils/Utils.js';
|
|
2
|
+
import { EntitySchema } from './EntitySchema.js';
|
|
2
3
|
export class MetadataProvider {
|
|
3
4
|
config;
|
|
4
5
|
constructor(config) {
|
|
5
6
|
this.config = config;
|
|
6
7
|
}
|
|
8
|
+
loadEntityMetadata(meta) {
|
|
9
|
+
for (const prop of meta.props) {
|
|
10
|
+
/* v8 ignore next */
|
|
11
|
+
if (typeof prop.entity === 'string') {
|
|
12
|
+
prop.type = prop.entity;
|
|
13
|
+
}
|
|
14
|
+
else if (prop.entity) {
|
|
15
|
+
const tmp = prop.entity();
|
|
16
|
+
prop.type = Array.isArray(tmp)
|
|
17
|
+
? tmp
|
|
18
|
+
.map(t => Utils.className(t))
|
|
19
|
+
.sort()
|
|
20
|
+
.join(' | ')
|
|
21
|
+
: Utils.className(tmp);
|
|
22
|
+
prop.target = tmp instanceof EntitySchema ? tmp.meta.class : tmp;
|
|
23
|
+
}
|
|
24
|
+
else if (!prop.type && !((prop.enum || prop.array) && (prop.items?.length ?? 0) > 0)) {
|
|
25
|
+
throw new Error(`Please provide either 'type' or 'entity' attribute in ${meta.className}.${prop.name}.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
7
29
|
loadFromCache(meta, cache) {
|
|
8
30
|
Object.values(cache.properties).forEach(prop => {
|
|
9
31
|
const metaProp = meta.properties[prop.name];
|
|
10
|
-
/* v8 ignore next
|
|
32
|
+
/* v8 ignore next */
|
|
11
33
|
if (metaProp?.enum && Array.isArray(metaProp.items)) {
|
|
12
34
|
delete prop.items;
|
|
13
35
|
}
|
|
14
36
|
});
|
|
37
|
+
// Preserve function expressions from indexes/uniques — they can't survive JSON cache serialization
|
|
38
|
+
const expressionMap = new Map();
|
|
39
|
+
for (const arr of [meta.indexes, meta.uniques]) {
|
|
40
|
+
for (const idx of arr ?? []) {
|
|
41
|
+
if (typeof idx.expression === 'function' && idx.name) {
|
|
42
|
+
expressionMap.set(idx.name, idx.expression);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
15
46
|
Utils.mergeConfig(meta, cache);
|
|
47
|
+
// Restore function expressions that were lost during JSON serialization
|
|
48
|
+
if (expressionMap.size > 0) {
|
|
49
|
+
for (const arr of [meta.indexes, meta.uniques]) {
|
|
50
|
+
for (const idx of arr ?? []) {
|
|
51
|
+
const fn = idx.name && expressionMap.get(idx.name);
|
|
52
|
+
if (fn && typeof idx.expression !== 'function') {
|
|
53
|
+
idx.expression = fn;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
static useCache() {
|
|
60
|
+
return false;
|
|
16
61
|
}
|
|
17
62
|
useCache() {
|
|
18
|
-
return this.config.get('metadataCache').enabled ??
|
|
63
|
+
return this.config.get('metadataCache').enabled ?? MetadataProvider.useCache();
|
|
64
|
+
}
|
|
65
|
+
saveToCache(meta) {
|
|
66
|
+
//
|
|
67
|
+
}
|
|
68
|
+
getCachedMetadata(meta, root) {
|
|
69
|
+
if (!this.useCache()) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const cache = meta.path && this.config.getMetadataCacheAdapter().get(this.getCacheKey(meta));
|
|
73
|
+
if (cache) {
|
|
74
|
+
this.loadFromCache(meta, cache);
|
|
75
|
+
meta.root = root;
|
|
76
|
+
}
|
|
77
|
+
return cache;
|
|
78
|
+
}
|
|
79
|
+
combineCache() {
|
|
80
|
+
const path = this.config.getMetadataCacheAdapter().combine?.();
|
|
81
|
+
// override the path in the options, so we can log it from the CLI in `cache:generate` command
|
|
82
|
+
if (path) {
|
|
83
|
+
this.config.get('metadataCache').combined = path;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
getCacheKey(meta) {
|
|
87
|
+
return meta.className;
|
|
19
88
|
}
|
|
20
89
|
}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Dictionary, EntityMetadata, type EntityName } from '../typings.js';
|
|
2
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
3
3
|
export declare class MetadataStorage {
|
|
4
4
|
static readonly PATH_SYMBOL: unique symbol;
|
|
5
5
|
private static readonly metadata;
|
|
6
6
|
private readonly metadata;
|
|
7
|
+
private readonly idMap;
|
|
8
|
+
private readonly classNameMap;
|
|
9
|
+
private readonly uniqueNameMap;
|
|
7
10
|
constructor(metadata?: Dictionary<EntityMetadata>);
|
|
8
11
|
static getMetadata(): Dictionary<EntityMetadata>;
|
|
9
12
|
static getMetadata<T = any>(entity: string, path: string): EntityMetadata<T>;
|
|
10
13
|
static isKnownEntity(name: string): boolean;
|
|
11
|
-
static getMetadataFromDecorator<T = any>(target: T & Dictionary & {
|
|
12
|
-
[MetadataStorage.PATH_SYMBOL]?: string;
|
|
13
|
-
}): EntityMetadata<T>;
|
|
14
|
-
static init(): MetadataStorage;
|
|
15
14
|
static clear(): void;
|
|
16
|
-
getAll():
|
|
17
|
-
|
|
18
|
-
get<T = any>(entityName: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
|
|
15
|
+
getAll(): Map<EntityName, EntityMetadata>;
|
|
16
|
+
get<T = any>(entityName: EntityName<T>, init?: boolean): EntityMetadata<T>;
|
|
19
17
|
find<T = any>(entityName: EntityName<T>): EntityMetadata<T> | undefined;
|
|
20
|
-
has(
|
|
21
|
-
set(
|
|
22
|
-
reset(
|
|
18
|
+
has<T>(entityName: EntityName<T>): boolean;
|
|
19
|
+
set<T>(entityName: EntityName<T>, meta: EntityMetadata): EntityMetadata;
|
|
20
|
+
reset<T>(entityName: EntityName<T>): void;
|
|
23
21
|
decorate(em: EntityManager): void;
|
|
24
22
|
[Symbol.iterator](): IterableIterator<EntityMetadata>;
|
|
23
|
+
getById<T>(id: number): EntityMetadata<T>;
|
|
24
|
+
getByClassName<T = any, V extends boolean = true>(className: string, validate?: V): V extends true ? EntityMetadata<T> : EntityMetadata<T> | undefined;
|
|
25
|
+
getByUniqueName<T = any, V extends boolean = true>(uniqueName: string, validate?: V): V extends true ? EntityMetadata<T> : EntityMetadata<T> | undefined;
|
|
26
|
+
private validate;
|
|
25
27
|
}
|
|
@@ -2,15 +2,31 @@ import { EntityMetadata } from '../typings.js';
|
|
|
2
2
|
import { Utils } from '../utils/Utils.js';
|
|
3
3
|
import { MetadataError } from '../errors.js';
|
|
4
4
|
import { EntityHelper } from '../entity/EntityHelper.js';
|
|
5
|
+
import { EntitySchema } from './EntitySchema.js';
|
|
6
|
+
function getGlobalStorage(namespace) {
|
|
7
|
+
const key = `mikro-orm-${namespace}`;
|
|
8
|
+
globalThis[key] = globalThis[key] || {};
|
|
9
|
+
return globalThis[key];
|
|
10
|
+
}
|
|
5
11
|
export class MetadataStorage {
|
|
6
|
-
static PATH_SYMBOL = Symbol('MetadataStorage.PATH_SYMBOL');
|
|
7
|
-
static metadata =
|
|
8
|
-
metadata;
|
|
12
|
+
static PATH_SYMBOL = Symbol.for('@mikro-orm/core/MetadataStorage.PATH_SYMBOL');
|
|
13
|
+
static metadata = getGlobalStorage('metadata');
|
|
14
|
+
metadata = new Map();
|
|
15
|
+
idMap;
|
|
16
|
+
classNameMap;
|
|
17
|
+
uniqueNameMap;
|
|
9
18
|
constructor(metadata = {}) {
|
|
10
|
-
this.
|
|
19
|
+
this.idMap = {};
|
|
20
|
+
this.uniqueNameMap = {};
|
|
21
|
+
this.classNameMap = Utils.copy(metadata, false);
|
|
22
|
+
for (const meta of Object.values(this.classNameMap)) {
|
|
23
|
+
this.idMap[meta._id] = meta;
|
|
24
|
+
this.uniqueNameMap[meta.uniqueName] = meta;
|
|
25
|
+
this.metadata.set(meta.class, meta);
|
|
26
|
+
}
|
|
11
27
|
}
|
|
12
28
|
static getMetadata(entity, path) {
|
|
13
|
-
const key = entity && path ? entity + '-' + Utils.hash(path
|
|
29
|
+
const key = entity && path ? entity + '-' + Utils.hash(path) : null;
|
|
14
30
|
if (key && !MetadataStorage.metadata[key]) {
|
|
15
31
|
MetadataStorage.metadata[key] = new EntityMetadata({ className: entity, path });
|
|
16
32
|
}
|
|
@@ -22,63 +38,78 @@ export class MetadataStorage {
|
|
|
22
38
|
static isKnownEntity(name) {
|
|
23
39
|
return !!Object.values(this.metadata).find(meta => meta.className === name);
|
|
24
40
|
}
|
|
25
|
-
static getMetadataFromDecorator(target) {
|
|
26
|
-
if (!Object.hasOwn(target, MetadataStorage.PATH_SYMBOL)) {
|
|
27
|
-
Object.defineProperty(target, MetadataStorage.PATH_SYMBOL, { value: Utils.lookupPathFromDecorator(target.name), writable: true });
|
|
28
|
-
}
|
|
29
|
-
return MetadataStorage.getMetadata(target.name, target[MetadataStorage.PATH_SYMBOL]);
|
|
30
|
-
}
|
|
31
|
-
static init() {
|
|
32
|
-
return new MetadataStorage(MetadataStorage.metadata);
|
|
33
|
-
}
|
|
34
41
|
static clear() {
|
|
35
42
|
Object.keys(this.metadata).forEach(k => delete this.metadata[k]);
|
|
36
43
|
}
|
|
37
44
|
getAll() {
|
|
38
45
|
return this.metadata;
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
const type = meta.root.discriminatorMap[value];
|
|
46
|
-
return this.metadata[type];
|
|
47
|
-
}
|
|
48
|
-
get(entityName, init = false, validate = true) {
|
|
49
|
-
entityName = Utils.className(entityName);
|
|
50
|
-
if (validate && !init && !this.has(entityName)) {
|
|
51
|
-
throw MetadataError.missingMetadata(entityName);
|
|
47
|
+
get(entityName, init = false) {
|
|
48
|
+
const exists = this.find(entityName);
|
|
49
|
+
if (exists) {
|
|
50
|
+
return exists;
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const className = Utils.className(entityName);
|
|
53
|
+
if (!init) {
|
|
54
|
+
throw MetadataError.missingMetadata(className);
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const meta = new EntityMetadata({ class: entityName, name: className });
|
|
57
|
+
this.set(entityName, meta);
|
|
58
|
+
return meta;
|
|
57
59
|
}
|
|
58
60
|
find(entityName) {
|
|
59
61
|
if (!entityName) {
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
const meta = this.metadata.get(entityName);
|
|
65
|
+
if (meta) {
|
|
66
|
+
return meta;
|
|
67
|
+
}
|
|
68
|
+
if (entityName instanceof EntitySchema) {
|
|
69
|
+
return this.metadata.get(entityName.meta.class) ?? entityName.meta;
|
|
70
|
+
}
|
|
71
|
+
return this.classNameMap[Utils.className(entityName)];
|
|
64
72
|
}
|
|
65
|
-
has(
|
|
66
|
-
return
|
|
73
|
+
has(entityName) {
|
|
74
|
+
return this.metadata.has(entityName);
|
|
67
75
|
}
|
|
68
|
-
set(
|
|
69
|
-
|
|
76
|
+
set(entityName, meta) {
|
|
77
|
+
this.metadata.set(entityName, meta);
|
|
78
|
+
this.idMap[meta._id] = meta;
|
|
79
|
+
this.uniqueNameMap[meta.uniqueName] = meta;
|
|
80
|
+
this.classNameMap[Utils.className(entityName)] = meta;
|
|
81
|
+
return meta;
|
|
70
82
|
}
|
|
71
|
-
reset(
|
|
72
|
-
|
|
83
|
+
reset(entityName) {
|
|
84
|
+
const meta = this.find(entityName);
|
|
85
|
+
if (meta) {
|
|
86
|
+
this.metadata.delete(meta.class);
|
|
87
|
+
delete this.idMap[meta._id];
|
|
88
|
+
delete this.uniqueNameMap[meta.uniqueName];
|
|
89
|
+
delete this.classNameMap[meta.className];
|
|
90
|
+
}
|
|
73
91
|
}
|
|
74
92
|
decorate(em) {
|
|
75
|
-
|
|
76
|
-
.filter(meta => meta.prototype)
|
|
77
|
-
.forEach(meta => EntityHelper.decorate(meta, em));
|
|
93
|
+
[...this.metadata.values()].filter(meta => meta.prototype).forEach(meta => EntityHelper.decorate(meta, em));
|
|
78
94
|
}
|
|
79
95
|
*[Symbol.iterator]() {
|
|
80
|
-
for (const meta of
|
|
96
|
+
for (const meta of this.metadata.values()) {
|
|
81
97
|
yield meta;
|
|
82
98
|
}
|
|
83
99
|
}
|
|
100
|
+
getById(id) {
|
|
101
|
+
return this.idMap[id];
|
|
102
|
+
}
|
|
103
|
+
getByClassName(className, validate = true) {
|
|
104
|
+
return this.validate(this.classNameMap[className], className, validate);
|
|
105
|
+
}
|
|
106
|
+
getByUniqueName(uniqueName, validate = true) {
|
|
107
|
+
return this.validate(this.uniqueNameMap[uniqueName], uniqueName, validate);
|
|
108
|
+
}
|
|
109
|
+
validate(meta, id, validate) {
|
|
110
|
+
if (!meta && validate) {
|
|
111
|
+
throw MetadataError.missingMetadata(id);
|
|
112
|
+
}
|
|
113
|
+
return meta;
|
|
114
|
+
}
|
|
84
115
|
}
|
|
@@ -1,24 +1,47 @@
|
|
|
1
|
-
import type { EntityMetadata } from '../typings.js';
|
|
1
|
+
import type { EntityMetadata, EntityName } from '../typings.js';
|
|
2
2
|
import { type MetadataDiscoveryOptions } from '../utils/Configuration.js';
|
|
3
|
-
import { ReferenceKind } from '../enums.js';
|
|
4
3
|
import type { MetadataStorage } from './MetadataStorage.js';
|
|
5
4
|
/**
|
|
6
5
|
* @internal
|
|
7
6
|
*/
|
|
8
7
|
export declare class MetadataValidator {
|
|
9
|
-
|
|
10
|
-
* Validate there is only one property decorator. This disallows using `@Property()` together with e.g. `@ManyToOne()`
|
|
11
|
-
* on the same property. One should use only `@ManyToOne()` in such case.
|
|
12
|
-
* We allow the existence of the property in metadata if the reference type is the same, this should allow things like HMR to work.
|
|
13
|
-
*/
|
|
14
|
-
static validateSingleDecorator(meta: EntityMetadata, propertyName: string, reference: ReferenceKind): void;
|
|
15
|
-
validateEntityDefinition<T>(metadata: MetadataStorage, name: string, options: MetadataDiscoveryOptions): void;
|
|
8
|
+
validateEntityDefinition<T>(metadata: MetadataStorage, name: EntityName<T>, options: MetadataDiscoveryOptions): void;
|
|
16
9
|
validateDiscovered(discovered: EntityMetadata[], options: MetadataDiscoveryOptions): void;
|
|
17
10
|
private validateReference;
|
|
11
|
+
private validateTargetKey;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a property has a unique constraint (either via `unique: true` or single-property `@Unique` decorator).
|
|
14
|
+
* Composite unique constraints are not sufficient for targetKey.
|
|
15
|
+
*/
|
|
16
|
+
private isPropertyUnique;
|
|
17
|
+
private validatePolymorphicTargets;
|
|
18
18
|
private validateBidirectional;
|
|
19
19
|
private validateOwningSide;
|
|
20
20
|
private validateInverseSide;
|
|
21
21
|
private validateIndexes;
|
|
22
22
|
private validateDuplicateFieldNames;
|
|
23
23
|
private validateVersionField;
|
|
24
|
+
/**
|
|
25
|
+
* Validates that entity properties do not use dangerous names that could lead to
|
|
26
|
+
* prototype pollution vulnerabilities. This validation ensures that property names
|
|
27
|
+
* cannot be exploited to modify object prototypes when values are assigned during
|
|
28
|
+
* entity hydration or persistence operations.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
private validatePropertyNames;
|
|
33
|
+
/**
|
|
34
|
+
* Validates view entity configuration.
|
|
35
|
+
* View entities must have an expression.
|
|
36
|
+
*/
|
|
37
|
+
private validateViewEntity;
|
|
38
|
+
/**
|
|
39
|
+
* Validates that STI and TPT are not mixed in the same inheritance hierarchy.
|
|
40
|
+
* An entity hierarchy can use either STI (discriminatorColumn) or TPT (inheritance: 'tpt'),
|
|
41
|
+
* but not both.
|
|
42
|
+
*
|
|
43
|
+
* Note: This validation runs before `initTablePerTypeInheritance` sets `inheritanceType`,
|
|
44
|
+
* so we check the raw `inheritance` option from the decorator/schema.
|
|
45
|
+
*/
|
|
46
|
+
private validateInheritanceStrategies;
|
|
24
47
|
}
|