@mikro-orm/core 7.0.2-dev.13 → 7.0.2-dev.14
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 +4 -0
- package/EntityManager.js +4 -0
- package/MikroORM.d.ts +2 -0
- package/MikroORM.js +2 -0
- package/cache/CacheAdapter.d.ts +2 -0
- package/cache/GeneratedCacheAdapter.d.ts +1 -0
- package/cache/GeneratedCacheAdapter.js +1 -0
- package/cache/MemoryCacheAdapter.d.ts +1 -0
- package/cache/MemoryCacheAdapter.js +1 -0
- package/cache/NullCacheAdapter.d.ts +1 -0
- package/cache/NullCacheAdapter.js +1 -0
- package/connections/Connection.d.ts +13 -0
- package/connections/Connection.js +9 -0
- package/drivers/DatabaseDriver.d.ts +12 -0
- package/drivers/DatabaseDriver.js +12 -0
- package/drivers/IDatabaseDriver.d.ts +44 -0
- package/drivers/IDatabaseDriver.js +1 -0
- package/entity/BaseEntity.d.ts +11 -0
- package/entity/BaseEntity.js +11 -0
- package/entity/Collection.d.ts +26 -0
- package/entity/Collection.js +15 -0
- package/entity/EntityAssigner.d.ts +3 -0
- package/entity/EntityAssigner.js +2 -0
- package/entity/EntityFactory.d.ts +16 -0
- package/entity/EntityFactory.js +6 -0
- package/entity/EntityLoader.d.ts +19 -0
- package/entity/EntityLoader.js +2 -0
- package/entity/EntityRepository.d.ts +2 -0
- package/entity/EntityRepository.js +2 -0
- package/entity/Reference.d.ts +20 -0
- package/entity/Reference.js +16 -0
- package/entity/WrappedEntity.d.ts +20 -0
- package/entity/WrappedEntity.js +21 -1
- package/entity/defineEntity.d.ts +10 -0
- package/entity/defineEntity.js +1 -0
- package/enums.d.ts +132 -0
- package/enums.js +132 -0
- package/errors.d.ts +6 -0
- package/errors.js +6 -0
- package/events/EventManager.d.ts +5 -0
- package/events/EventManager.js +5 -0
- package/events/EventSubscriber.d.ts +4 -0
- package/events/TransactionEventBroadcaster.d.ts +2 -0
- package/events/TransactionEventBroadcaster.js +2 -0
- package/hydration/Hydrator.d.ts +2 -0
- package/hydration/Hydrator.js +2 -0
- package/hydration/ObjectHydrator.d.ts +1 -0
- package/hydration/ObjectHydrator.js +1 -0
- package/logging/DefaultLogger.d.ts +3 -0
- package/logging/DefaultLogger.js +3 -0
- package/logging/Logger.d.ts +5 -0
- package/metadata/EntitySchema.d.ts +22 -0
- package/metadata/EntitySchema.js +20 -0
- package/metadata/MetadataDiscovery.d.ts +4 -0
- package/metadata/MetadataDiscovery.js +4 -0
- package/metadata/MetadataProvider.d.ts +8 -0
- package/metadata/MetadataProvider.js +8 -0
- package/metadata/MetadataStorage.d.ts +14 -0
- package/metadata/MetadataStorage.js +13 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +1 -0
- package/naming-strategy/AbstractNamingStrategy.js +1 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -0
- package/naming-strategy/MongoNamingStrategy.js +1 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +1 -0
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -0
- package/platforms/ExceptionConverter.js +1 -0
- package/platforms/Platform.d.ts +65 -0
- package/platforms/Platform.js +65 -0
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +2 -0
- package/serialization/EntityTransformer.d.ts +2 -0
- package/serialization/EntityTransformer.js +2 -0
- package/serialization/SerializationContext.d.ts +5 -0
- package/serialization/SerializationContext.js +5 -0
- package/types/ArrayType.d.ts +1 -0
- package/types/ArrayType.js +1 -0
- package/types/BlobType.d.ts +1 -0
- package/types/BlobType.js +1 -0
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +1 -0
- package/types/CharacterType.d.ts +1 -0
- package/types/CharacterType.js +1 -0
- package/types/DateTimeType.d.ts +1 -0
- package/types/DateTimeType.js +1 -0
- package/types/DateType.d.ts +1 -0
- package/types/DateType.js +1 -0
- package/types/EnumArrayType.d.ts +1 -0
- package/types/EnumArrayType.js +1 -0
- package/types/EnumType.d.ts +1 -0
- package/types/EnumType.js +1 -0
- package/types/FloatType.d.ts +1 -0
- package/types/FloatType.js +1 -0
- package/types/IntegerType.d.ts +1 -0
- package/types/IntegerType.js +1 -0
- package/types/IntervalType.d.ts +1 -0
- package/types/IntervalType.js +1 -0
- package/types/JsonType.d.ts +1 -0
- package/types/JsonType.js +1 -0
- package/types/MediumIntType.d.ts +1 -0
- package/types/MediumIntType.js +1 -0
- package/types/SmallIntType.d.ts +1 -0
- package/types/SmallIntType.js +1 -0
- package/types/StringType.d.ts +1 -0
- package/types/StringType.js +1 -0
- package/types/TextType.d.ts +1 -0
- package/types/TextType.js +1 -0
- package/types/TimeType.d.ts +1 -0
- package/types/TimeType.js +1 -0
- package/types/TinyIntType.d.ts +1 -0
- package/types/TinyIntType.js +1 -0
- package/types/Type.d.ts +3 -0
- package/types/Type.js +1 -0
- package/types/Uint8ArrayType.d.ts +1 -0
- package/types/Uint8ArrayType.js +1 -0
- package/types/UnknownType.d.ts +1 -0
- package/types/UnknownType.js +1 -0
- package/types/UuidType.d.ts +1 -0
- package/types/UuidType.js +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.js +2 -0
- package/typings.d.ts +177 -0
- package/typings.js +11 -0
- package/unit-of-work/ChangeSet.d.ts +4 -0
- package/unit-of-work/ChangeSet.js +4 -0
- package/unit-of-work/ChangeSetComputer.d.ts +2 -0
- package/unit-of-work/ChangeSetComputer.js +2 -0
- package/unit-of-work/ChangeSetPersister.d.ts +4 -0
- package/unit-of-work/ChangeSetPersister.js +4 -0
- package/unit-of-work/IdentityMap.d.ts +7 -0
- package/unit-of-work/IdentityMap.js +7 -0
- package/unit-of-work/UnitOfWork.d.ts +15 -0
- package/unit-of-work/UnitOfWork.js +15 -0
- package/utils/Configuration.d.ts +8 -0
- package/utils/Configuration.js +8 -0
- package/utils/EntityComparator.d.ts +2 -0
- package/utils/EntityComparator.js +2 -0
- package/utils/NullHighlighter.d.ts +1 -0
- package/utils/NullHighlighter.js +1 -0
- package/utils/RawQueryFragment.d.ts +10 -0
- package/utils/RawQueryFragment.js +9 -0
- package/utils/RequestContext.d.ts +1 -0
- package/utils/TransactionContext.d.ts +1 -0
- package/utils/TransactionContext.js +1 -0
- package/utils/Utils.d.ts +6 -0
- package/utils/Utils.js +7 -1
|
@@ -14,6 +14,7 @@ type EmbeddedTypeDef<Target> = {
|
|
|
14
14
|
} | {
|
|
15
15
|
entity: () => EntityName<Target> | EntityName[];
|
|
16
16
|
};
|
|
17
|
+
/** Union type representing all possible property definition shapes in an EntitySchema. */
|
|
17
18
|
export type EntitySchemaProperty<Target, Owner> = ({
|
|
18
19
|
kind: ReferenceKind.MANY_TO_ONE | 'm:1';
|
|
19
20
|
} & TypeDef<Target> & ManyToOneOptions<Owner, Target>) | ({
|
|
@@ -28,6 +29,7 @@ export type EntitySchemaProperty<Target, Owner> = ({
|
|
|
28
29
|
enum: true;
|
|
29
30
|
} & EnumOptions<Owner>) | (TypeDef<Target> & PropertyOptions<Owner>);
|
|
30
31
|
type OmitBaseProps<Entity, Base> = IsNever<Base> extends true ? Entity : Omit<Entity, keyof Base>;
|
|
32
|
+
/** Configuration object for defining an entity via EntitySchema. */
|
|
31
33
|
export type EntitySchemaMetadata<Entity, Base = never, Class extends EntityCtor = EntityCtor<Entity>> = Omit<Partial<EntityMetadata<Entity>>, 'name' | 'properties' | 'extends'> & ({
|
|
32
34
|
name: string;
|
|
33
35
|
} | {
|
|
@@ -42,6 +44,7 @@ export type EntitySchemaMetadata<Entity, Base = never, Class extends EntityCtor
|
|
|
42
44
|
} & {
|
|
43
45
|
inheritance?: 'tpt';
|
|
44
46
|
};
|
|
47
|
+
/** Class-less entity definition that provides a programmatic API for defining entities without decorators. */
|
|
45
48
|
export declare class EntitySchema<Entity = any, Base = never, Class extends EntityCtor = EntityCtor<Entity>> {
|
|
46
49
|
/**
|
|
47
50
|
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
@@ -60,24 +63,43 @@ export declare class EntitySchema<Entity = any, Base = never, Class extends Enti
|
|
|
60
63
|
* (e.g. when using `tsx` or `@swc-node/register` with `"type": "commonjs"` projects).
|
|
61
64
|
*/
|
|
62
65
|
static is(item: unknown): item is EntitySchema;
|
|
66
|
+
/** Creates an EntitySchema from existing EntityMetadata (used internally). */
|
|
63
67
|
static fromMetadata<T = AnyEntity, U = never>(meta: EntityMetadata<T> | DeepPartial<EntityMetadata<T>>): EntitySchema<T, U>;
|
|
68
|
+
/** Adds a scalar property to the entity schema. */
|
|
64
69
|
addProperty(name: EntityKey<Entity>, type?: TypeType, options?: PropertyOptions<Entity> | EntityProperty<Entity>): void;
|
|
70
|
+
/** Adds an enum property to the entity schema. */
|
|
65
71
|
addEnum(name: EntityKey<Entity>, type?: TypeType, options?: EnumOptions<Entity>): void;
|
|
72
|
+
/** Adds a version property for optimistic locking. */
|
|
66
73
|
addVersion(name: EntityKey<Entity>, type: TypeType, options?: PropertyOptions<Entity>): void;
|
|
74
|
+
/** Adds a primary key property to the entity schema. */
|
|
67
75
|
addPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: PrimaryKeyOptions<Entity>): void;
|
|
76
|
+
/** Adds a serialized primary key property (e.g. for MongoDB ObjectId). */
|
|
68
77
|
addSerializedPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: SerializedPrimaryKeyOptions<Entity>): void;
|
|
78
|
+
/** Adds an embedded property to the entity schema. */
|
|
69
79
|
addEmbedded<Target = AnyEntity>(name: EntityKey<Entity>, options: EmbeddedOptions<Entity, Target>): void;
|
|
80
|
+
/** Adds a many-to-one relation to the entity schema. */
|
|
70
81
|
addManyToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToOneOptions<Entity, Target>): void;
|
|
82
|
+
/** Adds a many-to-many relation to the entity schema. */
|
|
71
83
|
addManyToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToManyOptions<Entity, Target>): void;
|
|
84
|
+
/** Adds a one-to-many relation to the entity schema. */
|
|
72
85
|
addOneToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToManyOptions<Entity, Target>): void;
|
|
86
|
+
/** Adds a one-to-one relation to the entity schema. */
|
|
73
87
|
addOneToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToOneOptions<Entity, Target>): void;
|
|
88
|
+
/** Adds an index definition to the entity schema. */
|
|
74
89
|
addIndex<Key extends string>(options: IndexOptions<Entity, Key>): void;
|
|
90
|
+
/** Adds a unique constraint definition to the entity schema. */
|
|
75
91
|
addUnique<Key extends string>(options: UniqueOptions<Entity, Key>): void;
|
|
92
|
+
/** Sets a custom repository class for this entity. */
|
|
76
93
|
setCustomRepository(repository: () => Constructor): void;
|
|
94
|
+
/** Sets the base entity that this schema extends. */
|
|
77
95
|
setExtends(base: EntityName): void;
|
|
96
|
+
/** Sets or replaces the entity class associated with this schema. */
|
|
78
97
|
setClass(cls: Class): void;
|
|
98
|
+
/** Returns the underlying EntityMetadata. */
|
|
79
99
|
get meta(): EntityMetadata<Entity, Class>;
|
|
100
|
+
/** Returns the entity class name. */
|
|
80
101
|
get name(): string | EntityName<Entity>;
|
|
102
|
+
/** Returns the database table name. */
|
|
81
103
|
get tableName(): string;
|
|
82
104
|
get class(): Class;
|
|
83
105
|
get properties(): Record<string, any>;
|
package/metadata/EntitySchema.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Cascade, ReferenceKind } from '../enums.js';
|
|
|
4
4
|
import { Type } from '../types/Type.js';
|
|
5
5
|
import { Utils } from '../utils/Utils.js';
|
|
6
6
|
import { EnumArrayType } from '../types/EnumArrayType.js';
|
|
7
|
+
/** Class-less entity definition that provides a programmatic API for defining entities without decorators. */
|
|
7
8
|
export class EntitySchema {
|
|
8
9
|
/**
|
|
9
10
|
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
@@ -38,11 +39,13 @@ export class EntitySchema {
|
|
|
38
39
|
}
|
|
39
40
|
return item != null && typeof item === 'object' && item.constructor?.name === 'EntitySchema' && 'meta' in item;
|
|
40
41
|
}
|
|
42
|
+
/** Creates an EntitySchema from existing EntityMetadata (used internally). */
|
|
41
43
|
static fromMetadata(meta) {
|
|
42
44
|
const schema = new EntitySchema({ ...meta, internal: true });
|
|
43
45
|
schema.internal = true;
|
|
44
46
|
return schema;
|
|
45
47
|
}
|
|
48
|
+
/** Adds a scalar property to the entity schema. */
|
|
46
49
|
addProperty(name, type, options = {}) {
|
|
47
50
|
this.renameCompositeOptions(name, options);
|
|
48
51
|
const prop = {
|
|
@@ -63,6 +66,7 @@ export class EntitySchema {
|
|
|
63
66
|
}
|
|
64
67
|
this._meta.properties[name] = prop;
|
|
65
68
|
}
|
|
69
|
+
/** Adds an enum property to the entity schema. */
|
|
66
70
|
addEnum(name, type, options = {}) {
|
|
67
71
|
if (options.items instanceof Function) {
|
|
68
72
|
options.items = Utils.extractEnumValues(options.items());
|
|
@@ -82,16 +86,20 @@ export class EntitySchema {
|
|
|
82
86
|
}
|
|
83
87
|
this.addProperty(name, this.internal ? type : type || 'enum', prop);
|
|
84
88
|
}
|
|
89
|
+
/** Adds a version property for optimistic locking. */
|
|
85
90
|
addVersion(name, type, options = {}) {
|
|
86
91
|
this.addProperty(name, type, { version: true, ...options });
|
|
87
92
|
}
|
|
93
|
+
/** Adds a primary key property to the entity schema. */
|
|
88
94
|
addPrimaryKey(name, type, options = {}) {
|
|
89
95
|
this.addProperty(name, type, { primary: true, ...options });
|
|
90
96
|
}
|
|
97
|
+
/** Adds a serialized primary key property (e.g. for MongoDB ObjectId). */
|
|
91
98
|
addSerializedPrimaryKey(name, type, options = {}) {
|
|
92
99
|
this._meta.serializedPrimaryKey = name;
|
|
93
100
|
this.addProperty(name, type, { serializedPrimaryKey: true, ...options });
|
|
94
101
|
}
|
|
102
|
+
/** Adds an embedded property to the entity schema. */
|
|
95
103
|
addEmbedded(name, options) {
|
|
96
104
|
this.renameCompositeOptions(name, options);
|
|
97
105
|
Utils.defaultValue(options, 'prefix', true);
|
|
@@ -105,6 +113,7 @@ export class EntitySchema {
|
|
|
105
113
|
...options,
|
|
106
114
|
};
|
|
107
115
|
}
|
|
116
|
+
/** Adds a many-to-one relation to the entity schema. */
|
|
108
117
|
addManyToOne(name, type, options) {
|
|
109
118
|
const prop = this.createProperty(ReferenceKind.MANY_TO_ONE, options);
|
|
110
119
|
prop.owner = true;
|
|
@@ -118,6 +127,7 @@ export class EntitySchema {
|
|
|
118
127
|
Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
|
|
119
128
|
this.addProperty(name, type, prop);
|
|
120
129
|
}
|
|
130
|
+
/** Adds a many-to-many relation to the entity schema. */
|
|
121
131
|
addManyToMany(name, type, options) {
|
|
122
132
|
options.fixedOrder = options.fixedOrder || !!options.fixedOrderColumn;
|
|
123
133
|
if (!options.owner && !options.mappedBy) {
|
|
@@ -131,10 +141,12 @@ export class EntitySchema {
|
|
|
131
141
|
const prop = this.createProperty(ReferenceKind.MANY_TO_MANY, options);
|
|
132
142
|
this.addProperty(name, type, prop);
|
|
133
143
|
}
|
|
144
|
+
/** Adds a one-to-many relation to the entity schema. */
|
|
134
145
|
addOneToMany(name, type, options) {
|
|
135
146
|
const prop = this.createProperty(ReferenceKind.ONE_TO_MANY, options);
|
|
136
147
|
this.addProperty(name, type, prop);
|
|
137
148
|
}
|
|
149
|
+
/** Adds a one-to-one relation to the entity schema. */
|
|
138
150
|
addOneToOne(name, type, options) {
|
|
139
151
|
const prop = this.createProperty(ReferenceKind.ONE_TO_ONE, options);
|
|
140
152
|
Utils.defaultValue(prop, 'owner', !!prop.inversedBy || !prop.mappedBy);
|
|
@@ -154,18 +166,23 @@ export class EntitySchema {
|
|
|
154
166
|
}
|
|
155
167
|
this.addProperty(name, type, prop);
|
|
156
168
|
}
|
|
169
|
+
/** Adds an index definition to the entity schema. */
|
|
157
170
|
addIndex(options) {
|
|
158
171
|
this._meta.indexes.push(options);
|
|
159
172
|
}
|
|
173
|
+
/** Adds a unique constraint definition to the entity schema. */
|
|
160
174
|
addUnique(options) {
|
|
161
175
|
this._meta.uniques.push(options);
|
|
162
176
|
}
|
|
177
|
+
/** Sets a custom repository class for this entity. */
|
|
163
178
|
setCustomRepository(repository) {
|
|
164
179
|
this._meta.repository = repository;
|
|
165
180
|
}
|
|
181
|
+
/** Sets the base entity that this schema extends. */
|
|
166
182
|
setExtends(base) {
|
|
167
183
|
this._meta.extends = base;
|
|
168
184
|
}
|
|
185
|
+
/** Sets or replaces the entity class associated with this schema. */
|
|
169
186
|
setClass(cls) {
|
|
170
187
|
const oldClass = this._meta.class;
|
|
171
188
|
const sameClass = this._meta.class === cls;
|
|
@@ -191,12 +208,15 @@ export class EntitySchema {
|
|
|
191
208
|
this._meta.extends ??= base.name ? base : undefined;
|
|
192
209
|
}
|
|
193
210
|
}
|
|
211
|
+
/** Returns the underlying EntityMetadata. */
|
|
194
212
|
get meta() {
|
|
195
213
|
return this._meta;
|
|
196
214
|
}
|
|
215
|
+
/** Returns the entity class name. */
|
|
197
216
|
get name() {
|
|
198
217
|
return this._meta.className;
|
|
199
218
|
}
|
|
219
|
+
/** Returns the database table name. */
|
|
200
220
|
get tableName() {
|
|
201
221
|
return this._meta.tableName;
|
|
202
222
|
}
|
|
@@ -3,13 +3,17 @@ import type { Configuration } from '../utils/Configuration.js';
|
|
|
3
3
|
import { MetadataStorage } from './MetadataStorage.js';
|
|
4
4
|
import { EntitySchema } from './EntitySchema.js';
|
|
5
5
|
import type { Platform } from '../platforms/Platform.js';
|
|
6
|
+
/** Discovers, validates, and processes entity metadata from configured sources. */
|
|
6
7
|
export declare class MetadataDiscovery {
|
|
7
8
|
#private;
|
|
8
9
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
10
|
+
/** Discovers all entities asynchronously and returns the populated MetadataStorage. */
|
|
9
11
|
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
12
|
+
/** Discovers all entities synchronously and returns the populated MetadataStorage. */
|
|
10
13
|
discoverSync(): MetadataStorage;
|
|
11
14
|
private mapDiscoveredEntities;
|
|
12
15
|
private initAccessors;
|
|
16
|
+
/** Processes discovered entities: initializes relations, embeddables, indexes, and inheritance. */
|
|
13
17
|
processDiscoveredEntities(discovered: EntityMetadata[]): EntityMetadata[];
|
|
14
18
|
private findEntities;
|
|
15
19
|
private discoverMissingTargets;
|
|
@@ -11,6 +11,7 @@ import { t, Type } from '../types/index.js';
|
|
|
11
11
|
import { colors } from '../logging/colors.js';
|
|
12
12
|
import { raw, Raw } from '../utils/RawQueryFragment.js';
|
|
13
13
|
import { BaseEntity } from '../entity/BaseEntity.js';
|
|
14
|
+
/** Discovers, validates, and processes entity metadata from configured sources. */
|
|
14
15
|
export class MetadataDiscovery {
|
|
15
16
|
#namingStrategy;
|
|
16
17
|
#metadataProvider;
|
|
@@ -30,6 +31,7 @@ export class MetadataDiscovery {
|
|
|
30
31
|
this.#logger = this.#config.getLogger();
|
|
31
32
|
this.#schemaHelper = this.#platform.getSchemaHelper();
|
|
32
33
|
}
|
|
34
|
+
/** Discovers all entities asynchronously and returns the populated MetadataStorage. */
|
|
33
35
|
async discover(preferTs = true) {
|
|
34
36
|
this.#discovered.length = 0;
|
|
35
37
|
const startTime = Date.now();
|
|
@@ -50,6 +52,7 @@ export class MetadataDiscovery {
|
|
|
50
52
|
await this.#config.get('discovery').afterDiscovered?.(storage, this.#platform);
|
|
51
53
|
return storage;
|
|
52
54
|
}
|
|
55
|
+
/** Discovers all entities synchronously and returns the populated MetadataStorage. */
|
|
53
56
|
discoverSync() {
|
|
54
57
|
this.#discovered.length = 0;
|
|
55
58
|
const startTime = Date.now();
|
|
@@ -121,6 +124,7 @@ export class MetadataDiscovery {
|
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
}
|
|
127
|
+
/** Processes discovered entities: initializes relations, embeddables, indexes, and inheritance. */
|
|
124
128
|
processDiscoveredEntities(discovered) {
|
|
125
129
|
for (const meta of discovered) {
|
|
126
130
|
let i = 1;
|
|
@@ -8,15 +8,23 @@ export interface IConfiguration {
|
|
|
8
8
|
getMetadataCacheAdapter(): SyncCacheAdapter;
|
|
9
9
|
getPlatform(): Platform;
|
|
10
10
|
}
|
|
11
|
+
/** Base metadata provider that resolves entity type information and manages metadata caching. */
|
|
11
12
|
export declare class MetadataProvider {
|
|
12
13
|
protected readonly config: IConfiguration;
|
|
13
14
|
constructor(config: IConfiguration);
|
|
15
|
+
/** Resolves entity references and type information for all properties in the given metadata. */
|
|
14
16
|
loadEntityMetadata(meta: EntityMetadata): void;
|
|
17
|
+
/** Merges cached metadata into the given entity metadata, preserving function expressions. */
|
|
15
18
|
loadFromCache(meta: EntityMetadata, cache: EntityMetadata): void;
|
|
19
|
+
/** Whether this provider class uses metadata caching by default. */
|
|
16
20
|
static useCache(): boolean;
|
|
21
|
+
/** Whether metadata caching is enabled for this instance. */
|
|
17
22
|
useCache(): boolean;
|
|
18
23
|
saveToCache(meta: EntityMetadata): void;
|
|
24
|
+
/** Attempts to load metadata from cache, returning undefined if not available. */
|
|
19
25
|
getCachedMetadata<T>(meta: Pick<EntityMetadata<T>, 'className' | 'path' | 'root'>, root: EntityMetadata<T>): EntityMetadata<T> | undefined;
|
|
26
|
+
/** Combines individual metadata cache entries into a single file. */
|
|
20
27
|
combineCache(): void;
|
|
28
|
+
/** Returns the cache key for the given entity metadata. */
|
|
21
29
|
getCacheKey(meta: Pick<EntityMetadata, 'className' | 'path'>): string;
|
|
22
30
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Utils } from '../utils/Utils.js';
|
|
2
2
|
import { EntitySchema } from './EntitySchema.js';
|
|
3
|
+
/** Base metadata provider that resolves entity type information and manages metadata caching. */
|
|
3
4
|
export class MetadataProvider {
|
|
4
5
|
config;
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this.config = config;
|
|
7
8
|
}
|
|
9
|
+
/** Resolves entity references and type information for all properties in the given metadata. */
|
|
8
10
|
loadEntityMetadata(meta) {
|
|
9
11
|
for (const prop of meta.props) {
|
|
10
12
|
/* v8 ignore next */
|
|
@@ -26,6 +28,7 @@ export class MetadataProvider {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
31
|
+
/** Merges cached metadata into the given entity metadata, preserving function expressions. */
|
|
29
32
|
loadFromCache(meta, cache) {
|
|
30
33
|
Object.values(cache.properties).forEach(prop => {
|
|
31
34
|
const metaProp = meta.properties[prop.name];
|
|
@@ -56,15 +59,18 @@ export class MetadataProvider {
|
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
/** Whether this provider class uses metadata caching by default. */
|
|
59
63
|
static useCache() {
|
|
60
64
|
return false;
|
|
61
65
|
}
|
|
66
|
+
/** Whether metadata caching is enabled for this instance. */
|
|
62
67
|
useCache() {
|
|
63
68
|
return this.config.get('metadataCache').enabled ?? MetadataProvider.useCache();
|
|
64
69
|
}
|
|
65
70
|
saveToCache(meta) {
|
|
66
71
|
//
|
|
67
72
|
}
|
|
73
|
+
/** Attempts to load metadata from cache, returning undefined if not available. */
|
|
68
74
|
getCachedMetadata(meta, root) {
|
|
69
75
|
if (!this.useCache()) {
|
|
70
76
|
return undefined;
|
|
@@ -76,6 +82,7 @@ export class MetadataProvider {
|
|
|
76
82
|
}
|
|
77
83
|
return cache;
|
|
78
84
|
}
|
|
85
|
+
/** Combines individual metadata cache entries into a single file. */
|
|
79
86
|
combineCache() {
|
|
80
87
|
const path = this.config.getMetadataCacheAdapter().combine?.();
|
|
81
88
|
// override the path in the options, so we can log it from the CLI in `cache:generate` command
|
|
@@ -83,6 +90,7 @@ export class MetadataProvider {
|
|
|
83
90
|
this.config.get('metadataCache').combined = path;
|
|
84
91
|
}
|
|
85
92
|
}
|
|
93
|
+
/** Returns the cache key for the given entity metadata. */
|
|
86
94
|
getCacheKey(meta) {
|
|
87
95
|
return meta.className;
|
|
88
96
|
}
|
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
import { type Dictionary, EntityMetadata, type EntityName } from '../typings.js';
|
|
2
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
3
|
+
/** Registry that stores and provides access to entity metadata by class, name, or id. */
|
|
3
4
|
export declare class MetadataStorage {
|
|
4
5
|
#private;
|
|
5
6
|
static readonly PATH_SYMBOL: unique symbol;
|
|
6
7
|
constructor(metadata?: Dictionary<EntityMetadata>);
|
|
8
|
+
/** Returns the global metadata dictionary, or a specific entry by entity name and path. */
|
|
7
9
|
static getMetadata(): Dictionary<EntityMetadata>;
|
|
8
10
|
static getMetadata<T = any>(entity: string, path: string): EntityMetadata<T>;
|
|
11
|
+
/** Checks whether an entity with the given class name exists in the global metadata. */
|
|
9
12
|
static isKnownEntity(name: string): boolean;
|
|
13
|
+
/** Clears all entries from the global metadata registry. */
|
|
10
14
|
static clear(): void;
|
|
15
|
+
/** Returns the map of all registered entity metadata. */
|
|
11
16
|
getAll(): Map<EntityName, EntityMetadata>;
|
|
17
|
+
/** Returns metadata for the given entity, optionally initializing it if not found. */
|
|
12
18
|
get<T = any>(entityName: EntityName<T>, init?: boolean): EntityMetadata<T>;
|
|
19
|
+
/** Finds metadata for the given entity, returning undefined if not registered. */
|
|
13
20
|
find<T = any>(entityName: EntityName<T>): EntityMetadata<T> | undefined;
|
|
21
|
+
/** Checks whether metadata exists for the given entity. */
|
|
14
22
|
has<T>(entityName: EntityName<T>): boolean;
|
|
23
|
+
/** Registers metadata for the given entity. */
|
|
15
24
|
set<T>(entityName: EntityName<T>, meta: EntityMetadata): EntityMetadata;
|
|
25
|
+
/** Removes metadata for the given entity from all internal maps. */
|
|
16
26
|
reset<T>(entityName: EntityName<T>): void;
|
|
27
|
+
/** Decorates all entity prototypes with helper methods (e.g. init, toJSON). */
|
|
17
28
|
decorate(em: EntityManager): void;
|
|
18
29
|
[Symbol.iterator](): IterableIterator<EntityMetadata>;
|
|
30
|
+
/** Returns metadata by its internal numeric id. */
|
|
19
31
|
getById<T>(id: number): EntityMetadata<T>;
|
|
32
|
+
/** Returns metadata by class name, optionally throwing if not found. */
|
|
20
33
|
getByClassName<T = any, V extends boolean = true>(className: string, validate?: V): V extends true ? EntityMetadata<T> : EntityMetadata<T> | undefined;
|
|
34
|
+
/** Returns metadata by unique name, optionally throwing if not found. */
|
|
21
35
|
getByUniqueName<T = any, V extends boolean = true>(uniqueName: string, validate?: V): V extends true ? EntityMetadata<T> : EntityMetadata<T> | undefined;
|
|
22
36
|
private validate;
|
|
23
37
|
}
|
|
@@ -8,6 +8,7 @@ function getGlobalStorage(namespace) {
|
|
|
8
8
|
globalThis[key] = globalThis[key] || {};
|
|
9
9
|
return globalThis[key];
|
|
10
10
|
}
|
|
11
|
+
/** Registry that stores and provides access to entity metadata by class, name, or id. */
|
|
11
12
|
export class MetadataStorage {
|
|
12
13
|
static PATH_SYMBOL = Symbol.for('@mikro-orm/core/MetadataStorage.PATH_SYMBOL');
|
|
13
14
|
static #metadata = getGlobalStorage('metadata');
|
|
@@ -35,15 +36,19 @@ export class MetadataStorage {
|
|
|
35
36
|
}
|
|
36
37
|
return MetadataStorage.#metadata;
|
|
37
38
|
}
|
|
39
|
+
/** Checks whether an entity with the given class name exists in the global metadata. */
|
|
38
40
|
static isKnownEntity(name) {
|
|
39
41
|
return !!Object.values(this.#metadata).find(meta => meta.className === name);
|
|
40
42
|
}
|
|
43
|
+
/** Clears all entries from the global metadata registry. */
|
|
41
44
|
static clear() {
|
|
42
45
|
Object.keys(this.#metadata).forEach(k => delete this.#metadata[k]);
|
|
43
46
|
}
|
|
47
|
+
/** Returns the map of all registered entity metadata. */
|
|
44
48
|
getAll() {
|
|
45
49
|
return this.#metadataMap;
|
|
46
50
|
}
|
|
51
|
+
/** Returns metadata for the given entity, optionally initializing it if not found. */
|
|
47
52
|
get(entityName, init = false) {
|
|
48
53
|
const exists = this.find(entityName);
|
|
49
54
|
if (exists) {
|
|
@@ -57,6 +62,7 @@ export class MetadataStorage {
|
|
|
57
62
|
this.set(entityName, meta);
|
|
58
63
|
return meta;
|
|
59
64
|
}
|
|
65
|
+
/** Finds metadata for the given entity, returning undefined if not registered. */
|
|
60
66
|
find(entityName) {
|
|
61
67
|
if (!entityName) {
|
|
62
68
|
return;
|
|
@@ -70,9 +76,11 @@ export class MetadataStorage {
|
|
|
70
76
|
}
|
|
71
77
|
return this.#classNameMap[Utils.className(entityName)];
|
|
72
78
|
}
|
|
79
|
+
/** Checks whether metadata exists for the given entity. */
|
|
73
80
|
has(entityName) {
|
|
74
81
|
return this.#metadataMap.has(entityName);
|
|
75
82
|
}
|
|
83
|
+
/** Registers metadata for the given entity. */
|
|
76
84
|
set(entityName, meta) {
|
|
77
85
|
this.#metadataMap.set(entityName, meta);
|
|
78
86
|
this.#idMap[meta._id] = meta;
|
|
@@ -80,6 +88,7 @@ export class MetadataStorage {
|
|
|
80
88
|
this.#classNameMap[Utils.className(entityName)] = meta;
|
|
81
89
|
return meta;
|
|
82
90
|
}
|
|
91
|
+
/** Removes metadata for the given entity from all internal maps. */
|
|
83
92
|
reset(entityName) {
|
|
84
93
|
const meta = this.find(entityName);
|
|
85
94
|
if (meta) {
|
|
@@ -89,6 +98,7 @@ export class MetadataStorage {
|
|
|
89
98
|
delete this.#classNameMap[meta.className];
|
|
90
99
|
}
|
|
91
100
|
}
|
|
101
|
+
/** Decorates all entity prototypes with helper methods (e.g. init, toJSON). */
|
|
92
102
|
decorate(em) {
|
|
93
103
|
[...this.#metadataMap.values()].filter(meta => meta.prototype).forEach(meta => EntityHelper.decorate(meta, em));
|
|
94
104
|
}
|
|
@@ -97,12 +107,15 @@ export class MetadataStorage {
|
|
|
97
107
|
yield meta;
|
|
98
108
|
}
|
|
99
109
|
}
|
|
110
|
+
/** Returns metadata by its internal numeric id. */
|
|
100
111
|
getById(id) {
|
|
101
112
|
return this.#idMap[id];
|
|
102
113
|
}
|
|
114
|
+
/** Returns metadata by class name, optionally throwing if not found. */
|
|
103
115
|
getByClassName(className, validate = true) {
|
|
104
116
|
return this.validate(this.#classNameMap[className], className, validate);
|
|
105
117
|
}
|
|
118
|
+
/** Returns metadata by unique name, optionally throwing if not found. */
|
|
106
119
|
getByUniqueName(uniqueName, validate = true) {
|
|
107
120
|
return this.validate(this.#uniqueNameMap[uniqueName], uniqueName, validate);
|
|
108
121
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NamingStrategy } from './NamingStrategy.js';
|
|
2
2
|
import { type ReferenceKind } from '../enums.js';
|
|
3
|
+
/** Base class for naming strategies, providing default implementations for common naming conventions. */
|
|
3
4
|
export declare abstract class AbstractNamingStrategy implements NamingStrategy {
|
|
4
5
|
getClassName(file: string, separator?: string): string;
|
|
5
6
|
classToMigrationName(timestamp: string, customMigrationName?: string): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PopulatePath } from '../enums.js';
|
|
2
2
|
const populatePathMembers = Object.values(PopulatePath);
|
|
3
|
+
/** Base class for naming strategies, providing default implementations for common naming conventions. */
|
|
3
4
|
export class AbstractNamingStrategy {
|
|
4
5
|
getClassName(file, separator = '-') {
|
|
5
6
|
const name = file.split('.')[0];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
|
+
/** Naming strategy for MongoDB that uses camelCase property names and hyphenated collection names. */
|
|
2
3
|
export declare class MongoNamingStrategy extends AbstractNamingStrategy {
|
|
3
4
|
classToTableName(entityName: string, tableName?: string): string;
|
|
4
5
|
joinColumnName(propertyName: string): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
|
+
/** Naming strategy for MongoDB that uses camelCase property names and hyphenated collection names. */
|
|
2
3
|
export class MongoNamingStrategy extends AbstractNamingStrategy {
|
|
3
4
|
classToTableName(entityName, tableName) {
|
|
4
5
|
return tableName ?? entityName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
|
+
/** Naming strategy that converts camelCase names to snake_case for table and column names. */
|
|
2
3
|
export declare class UnderscoreNamingStrategy extends AbstractNamingStrategy {
|
|
3
4
|
classToTableName(entityName: string, tableName?: string): string;
|
|
4
5
|
joinColumnName(propertyName: string): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
|
+
/** Naming strategy that converts camelCase names to snake_case for table and column names. */
|
|
2
3
|
export class UnderscoreNamingStrategy extends AbstractNamingStrategy {
|
|
3
4
|
classToTableName(entityName, tableName) {
|
|
4
5
|
return tableName ?? this.underscore(entityName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.2-dev.
|
|
3
|
+
"version": "7.0.2-dev.14",
|
|
4
4
|
"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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Dictionary } from '../typings.js';
|
|
2
2
|
import { DriverException } from '../exceptions.js';
|
|
3
|
+
/** Converts native database errors into standardized DriverException instances. */
|
|
3
4
|
export declare class ExceptionConverter {
|
|
4
5
|
convertException(exception: Error & Dictionary): DriverException;
|
|
5
6
|
}
|