@mikro-orm/core 7.0.0-dev.49 → 7.0.0-dev.50
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/MikroORM.d.ts +3 -3
- package/MikroORM.js +5 -8
- package/errors.d.ts +0 -1
- package/errors.js +0 -4
- package/index.d.ts +1 -1
- package/metadata/MetadataDiscovery.d.ts +2 -2
- package/metadata/MetadataDiscovery.js +54 -85
- package/package.json +2 -2
- package/typings.d.ts +0 -4
- package/utils/Configuration.d.ts +5 -5
package/MikroORM.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { type EntitySchema } from './metadata/EntitySchema.js';
|
|
|
3
3
|
import { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
4
4
|
import { Configuration, type Options } from './utils/Configuration.js';
|
|
5
5
|
import type { EntityManager } from './EntityManager.js';
|
|
6
|
-
import type { AnyEntity, Constructor, EntityClass,
|
|
6
|
+
import type { AnyEntity, Constructor, EntityClass, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings.js';
|
|
7
7
|
/**
|
|
8
8
|
* Helper class for bootstrapping the MikroORM.
|
|
9
9
|
*/
|
|
10
|
-
export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = Driver[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> |
|
|
10
|
+
export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = Driver[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> {
|
|
11
11
|
/** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
|
|
12
12
|
em: EM & {
|
|
13
13
|
'~entities'?: Entities;
|
|
@@ -21,7 +21,7 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
|
|
|
21
21
|
* Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
|
|
22
22
|
* If you omit the `options` parameter, your CLI config will be used.
|
|
23
23
|
*/
|
|
24
|
-
static init<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> |
|
|
24
|
+
static init<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): Promise<MikroORM<D, EM, Entities>>;
|
|
25
25
|
/**
|
|
26
26
|
* Synchronous variant of the `init` method with some limitations:
|
|
27
27
|
* - database connection will be established when you first interact with the database (or you can use `orm.connect()` explicitly)
|
package/MikroORM.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MetadataDiscovery } from './metadata/MetadataDiscovery.js';
|
|
2
2
|
import { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
3
|
-
import { MetadataValidator } from './metadata/MetadataValidator.js';
|
|
4
3
|
import { ReflectMetadataProvider } from './metadata/ReflectMetadataProvider.js';
|
|
5
4
|
import { Configuration } from './utils/Configuration.js';
|
|
6
5
|
import { ConfigurationLoader } from './utils/ConfigurationLoader.js';
|
|
@@ -118,7 +117,8 @@ export class MikroORM {
|
|
|
118
117
|
// we need to allow global context here as we are not in a scope of requests yet
|
|
119
118
|
const allowGlobalContext = this.config.get('allowGlobalContext');
|
|
120
119
|
this.config.set('allowGlobalContext', true);
|
|
121
|
-
|
|
120
|
+
const preferTs = this.config.get('preferTs', Utils.detectTypeScriptSupport());
|
|
121
|
+
this.metadata = await this.discovery.discover(preferTs);
|
|
122
122
|
this.createEntityManager();
|
|
123
123
|
this.config.set('allowGlobalContext', allowGlobalContext);
|
|
124
124
|
}
|
|
@@ -141,19 +141,16 @@ export class MikroORM {
|
|
|
141
141
|
* Allows dynamically discovering new entity by reference, handy for testing schema diffing.
|
|
142
142
|
*/
|
|
143
143
|
discoverEntity(entities, reset) {
|
|
144
|
-
entities = Utils.asArray(entities);
|
|
145
144
|
for (const className of Utils.asArray(reset)) {
|
|
146
145
|
this.metadata.reset(className);
|
|
147
146
|
this.discovery.reset(className);
|
|
148
147
|
}
|
|
149
|
-
const tmp = this.discovery.discoverReferences(entities);
|
|
150
|
-
const options = this.config.get('discovery');
|
|
151
|
-
new MetadataValidator().validateDiscovered([...Object.values(this.metadata.getAll()), ...tmp], options);
|
|
148
|
+
const tmp = this.discovery.discoverReferences(Utils.asArray(entities));
|
|
152
149
|
const metadata = this.discovery.processDiscoveredEntities(tmp);
|
|
153
|
-
|
|
150
|
+
for (const meta of metadata) {
|
|
154
151
|
this.metadata.set(meta.className, meta);
|
|
155
152
|
meta.root = this.metadata.get(meta.root.className);
|
|
156
|
-
}
|
|
153
|
+
}
|
|
157
154
|
this.metadata.decorate(this.em);
|
|
158
155
|
}
|
|
159
156
|
/**
|
package/errors.d.ts
CHANGED
|
@@ -44,7 +44,6 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
44
44
|
static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError;
|
|
45
45
|
static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
|
|
46
46
|
static fromInversideSidePrimary(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
|
|
47
|
-
static entityNotFound(name: string, path: string): MetadataError;
|
|
48
47
|
static unknownIndexProperty(meta: EntityMetadata, prop: string, type: string): MetadataError;
|
|
49
48
|
static multipleVersionFields(meta: EntityMetadata, fields: string[]): MetadataError;
|
|
50
49
|
static invalidVersionFieldType(meta: EntityMetadata): MetadataError;
|
package/errors.js
CHANGED
|
@@ -154,10 +154,6 @@ export class MetadataError extends ValidationError {
|
|
|
154
154
|
static fromInversideSidePrimary(meta, owner, prop) {
|
|
155
155
|
return new MetadataError(`${meta.className}.${prop.name} cannot be primary key as it is defined as inverse side. Maybe you should swap the use of 'inversedBy' and 'mappedBy'.`);
|
|
156
156
|
}
|
|
157
|
-
/* v8 ignore next 3 */
|
|
158
|
-
static entityNotFound(name, path) {
|
|
159
|
-
return new MetadataError(`Entity '${name}' not found in ${path}`);
|
|
160
|
-
}
|
|
161
157
|
static unknownIndexProperty(meta, prop, type) {
|
|
162
158
|
return new MetadataError(`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`);
|
|
163
159
|
}
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
5
|
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
|
-
export type { Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager,
|
|
6
|
+
export type { Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, RequiredEntityData, CheckCallback, IndexCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, } from './typings.js';
|
|
7
7
|
export * from './enums.js';
|
|
8
8
|
export * from './errors.js';
|
|
9
9
|
export * from './exceptions.js';
|
|
@@ -17,6 +17,7 @@ export declare class MetadataDiscovery {
|
|
|
17
17
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
18
18
|
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
19
19
|
discoverSync(): MetadataStorage;
|
|
20
|
+
validateDiscovered(metadata: EntityMetadata[]): void;
|
|
20
21
|
private mapDiscoveredEntities;
|
|
21
22
|
private initAccessors;
|
|
22
23
|
processDiscoveredEntities(discovered: EntityMetadata[]): EntityMetadata[];
|
|
@@ -24,9 +25,8 @@ export declare class MetadataDiscovery {
|
|
|
24
25
|
private discoverMissingTargets;
|
|
25
26
|
private tryDiscoverTargets;
|
|
26
27
|
private discoverDirectories;
|
|
27
|
-
discoverReferences<T>(refs: (Constructor<T> | EntitySchema<T>)[]): EntityMetadata<T>[];
|
|
28
|
+
discoverReferences<T>(refs: (Constructor<T> | EntitySchema<T>)[], validate?: boolean): EntityMetadata<T>[];
|
|
28
29
|
reset(className: string): void;
|
|
29
|
-
private prepare;
|
|
30
30
|
private getSchema;
|
|
31
31
|
private discoverEntity;
|
|
32
32
|
private saveToCache;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { basename, extname } from 'node:path';
|
|
2
2
|
import { glob } from 'tinyglobby';
|
|
3
|
-
import { EntityMetadata
|
|
3
|
+
import { EntityMetadata } from '../typings.js';
|
|
4
4
|
import { Utils } from '../utils/Utils.js';
|
|
5
5
|
import { MetadataValidator } from './MetadataValidator.js';
|
|
6
6
|
import { MetadataStorage } from './MetadataStorage.js';
|
|
7
7
|
import { EntitySchema } from './EntitySchema.js';
|
|
8
8
|
import { Cascade, ReferenceKind } from '../enums.js';
|
|
9
9
|
import { MetadataError } from '../errors.js';
|
|
10
|
-
import {
|
|
10
|
+
import { t, Type } from '../types/index.js';
|
|
11
11
|
import { colors } from '../logging/colors.js';
|
|
12
12
|
import { raw, RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
13
13
|
export class MetadataDiscovery {
|
|
@@ -63,6 +63,9 @@ export class MetadataDiscovery {
|
|
|
63
63
|
void this.config.get('discovery').afterDiscovered?.(storage, this.platform);
|
|
64
64
|
return storage;
|
|
65
65
|
}
|
|
66
|
+
validateDiscovered(metadata) {
|
|
67
|
+
return this.validator.validateDiscovered(metadata, this.config.get('discovery'));
|
|
68
|
+
}
|
|
66
69
|
mapDiscoveredEntities() {
|
|
67
70
|
const discovered = new MetadataStorage();
|
|
68
71
|
this.discovered
|
|
@@ -154,24 +157,18 @@ export class MetadataDiscovery {
|
|
|
154
157
|
findEntities(preferTs, sync = false) {
|
|
155
158
|
this.discovered.length = 0;
|
|
156
159
|
const options = this.config.get('discovery');
|
|
157
|
-
const key = (preferTs && this.config.get('
|
|
160
|
+
const key = (preferTs && this.config.get('entitiesTs').length > 0) ? 'entitiesTs' : 'entities';
|
|
158
161
|
const paths = this.config.get(key).filter(item => Utils.isString(item));
|
|
159
162
|
const refs = this.config.get(key).filter(item => !Utils.isString(item));
|
|
160
163
|
if (paths.length > 0) {
|
|
161
164
|
if (sync || options.requireEntitiesArray) {
|
|
162
165
|
throw new Error(`[requireEntitiesArray] Explicit list of entities is required, please use the 'entities' option.`);
|
|
163
166
|
}
|
|
164
|
-
return this.discoverDirectories(paths).then(
|
|
165
|
-
this.discoverReferences(refs);
|
|
166
|
-
this.discoverMissingTargets();
|
|
167
|
-
this.validator.validateDiscovered(this.discovered, options);
|
|
168
|
-
return this.discovered;
|
|
167
|
+
return this.discoverDirectories(paths).then(targets => {
|
|
168
|
+
return this.discoverReferences([...targets, ...refs]);
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
|
-
this.discoverReferences(refs);
|
|
172
|
-
this.discoverMissingTargets();
|
|
173
|
-
this.validator.validateDiscovered(this.discovered, options);
|
|
174
|
-
return this.discovered;
|
|
171
|
+
return this.discoverReferences(refs);
|
|
175
172
|
}
|
|
176
173
|
discoverMissingTargets() {
|
|
177
174
|
const unwrap = (type) => type
|
|
@@ -201,7 +198,7 @@ export class MetadataDiscovery {
|
|
|
201
198
|
for (const target of targets) {
|
|
202
199
|
const isDiscoverable = typeof target === 'function' || target instanceof EntitySchema;
|
|
203
200
|
if (isDiscoverable && target.name && !this.metadata.has(target.name)) {
|
|
204
|
-
this.discoverReferences([target]);
|
|
201
|
+
this.discoverReferences([target], false);
|
|
205
202
|
this.discoverMissingTargets();
|
|
206
203
|
}
|
|
207
204
|
}
|
|
@@ -210,40 +207,21 @@ export class MetadataDiscovery {
|
|
|
210
207
|
paths = paths.map(path => Utils.normalizePath(path));
|
|
211
208
|
const files = await glob(paths, { cwd: Utils.normalizePath(this.config.get('baseDir')) });
|
|
212
209
|
this.logger.log('discovery', `- processing ${colors.cyan('' + files.length)} files`);
|
|
213
|
-
const found =
|
|
210
|
+
const found = new Map();
|
|
214
211
|
for (const filepath of files) {
|
|
215
212
|
const filename = basename(filepath);
|
|
216
|
-
if (!filename.match(/\.[cm]?[jt]s$/) ||
|
|
217
|
-
filename.endsWith('.js.map') ||
|
|
218
|
-
filename.match(/\.d\.[cm]?ts/) ||
|
|
219
|
-
filename.startsWith('.') ||
|
|
220
|
-
filename.match(/index\.[cm]?[jt]s$/)) {
|
|
213
|
+
if (!filename.match(/\.[cm]?[jt]s$/) || filename.match(/\.d\.[cm]?ts/)) {
|
|
221
214
|
this.logger.log('discovery', `- ignoring file ${filename}`);
|
|
222
215
|
continue;
|
|
223
216
|
}
|
|
224
|
-
|
|
225
|
-
const path = Utils.normalizePath(this.config.get('baseDir'), filepath);
|
|
226
|
-
const targets = await this.getEntityClassOrSchema(path, name);
|
|
227
|
-
for (const target of targets) {
|
|
228
|
-
if (!(target instanceof Function) && !(target instanceof EntitySchema)) {
|
|
229
|
-
this.logger.log('discovery', `- ignoring file ${filename}`);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
const entity = this.prepare(target);
|
|
233
|
-
const schema = this.getSchema(entity, path);
|
|
234
|
-
const meta = schema.init().meta;
|
|
235
|
-
this.metadata.set(meta.className, meta);
|
|
236
|
-
found.push([schema, path]);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
for (const [schema, path] of found) {
|
|
240
|
-
this.discoverEntity(schema, path);
|
|
217
|
+
await this.getEntityClassOrSchema(filepath, found);
|
|
241
218
|
}
|
|
219
|
+
return found.keys();
|
|
242
220
|
}
|
|
243
|
-
discoverReferences(refs) {
|
|
221
|
+
discoverReferences(refs, validate = true) {
|
|
244
222
|
const found = [];
|
|
245
223
|
for (const entity of refs) {
|
|
246
|
-
const schema = this.getSchema(
|
|
224
|
+
const schema = this.getSchema(entity);
|
|
247
225
|
const meta = schema.init().meta;
|
|
248
226
|
this.metadata.set(meta.className, meta);
|
|
249
227
|
found.push(schema);
|
|
@@ -252,10 +230,10 @@ export class MetadataDiscovery {
|
|
|
252
230
|
for (const meta of this.metadata) {
|
|
253
231
|
let parent = meta.extends;
|
|
254
232
|
if (parent instanceof EntitySchema && !this.metadata.has(parent.meta.className)) {
|
|
255
|
-
this.discoverReferences([parent]);
|
|
233
|
+
this.discoverReferences([parent], false);
|
|
256
234
|
}
|
|
257
235
|
if (typeof parent === 'function' && parent.name && !this.metadata.has(parent.name)) {
|
|
258
|
-
this.discoverReferences([parent]);
|
|
236
|
+
this.discoverReferences([parent], false);
|
|
259
237
|
}
|
|
260
238
|
/* v8 ignore next 3 */
|
|
261
239
|
if (!meta.class) {
|
|
@@ -263,12 +241,16 @@ export class MetadataDiscovery {
|
|
|
263
241
|
}
|
|
264
242
|
parent = Object.getPrototypeOf(meta.class);
|
|
265
243
|
if (parent.name !== '' && !this.metadata.has(parent.name)) {
|
|
266
|
-
this.discoverReferences([parent]);
|
|
244
|
+
this.discoverReferences([parent], false);
|
|
267
245
|
}
|
|
268
246
|
}
|
|
269
247
|
for (const schema of found) {
|
|
270
248
|
this.discoverEntity(schema);
|
|
271
249
|
}
|
|
250
|
+
this.discoverMissingTargets();
|
|
251
|
+
if (validate) {
|
|
252
|
+
this.validateDiscovered(this.discovered);
|
|
253
|
+
}
|
|
272
254
|
return this.discovered.filter(meta => found.find(m => m.name === meta.className));
|
|
273
255
|
}
|
|
274
256
|
reset(className) {
|
|
@@ -278,22 +260,11 @@ export class MetadataDiscovery {
|
|
|
278
260
|
this.discovered.splice(exists, 1);
|
|
279
261
|
}
|
|
280
262
|
}
|
|
281
|
-
|
|
282
|
-
/* v8 ignore next 3 */
|
|
283
|
-
if ('schema' in entity && entity.schema instanceof EntitySchema) {
|
|
284
|
-
return entity.schema;
|
|
285
|
-
}
|
|
263
|
+
getSchema(entity) {
|
|
286
264
|
if (EntitySchema.REGISTRY.has(entity)) {
|
|
287
|
-
|
|
265
|
+
entity = EntitySchema.REGISTRY.get(entity);
|
|
288
266
|
}
|
|
289
|
-
return entity;
|
|
290
|
-
}
|
|
291
|
-
getSchema(entity, filepath) {
|
|
292
267
|
if (entity instanceof EntitySchema) {
|
|
293
|
-
if (filepath) {
|
|
294
|
-
// initialize global metadata for given entity
|
|
295
|
-
MetadataStorage.getMetadata(entity.meta.className, filepath);
|
|
296
|
-
}
|
|
297
268
|
const meta = Utils.copy(entity.meta, false);
|
|
298
269
|
return EntitySchema.fromMetadata(meta);
|
|
299
270
|
}
|
|
@@ -310,11 +281,12 @@ export class MetadataDiscovery {
|
|
|
310
281
|
schema.setClass(entity);
|
|
311
282
|
return schema;
|
|
312
283
|
}
|
|
313
|
-
discoverEntity(schema
|
|
314
|
-
this.logger.log('discovery', `- processing entity ${colors.cyan(schema.meta.className)}${colors.grey(path ? ` (${path})` : '')}`);
|
|
284
|
+
discoverEntity(schema) {
|
|
315
285
|
const meta = schema.meta;
|
|
286
|
+
const path = meta.path;
|
|
287
|
+
this.logger.log('discovery', `- processing entity ${colors.cyan(meta.className)}${colors.grey(path ? ` (${path})` : '')}`);
|
|
316
288
|
const root = Utils.getRootEntity(this.metadata, meta);
|
|
317
|
-
schema.meta.path = Utils.relativePath(
|
|
289
|
+
schema.meta.path = Utils.relativePath(meta.path, this.config.get('baseDir'));
|
|
318
290
|
const cache = this.metadataProvider.useCache() && meta.path && this.cache.get(meta.className + extname(meta.path));
|
|
319
291
|
if (cache) {
|
|
320
292
|
this.logger.log('discovery', `- using cached metadata for entity ${colors.cyan(meta.className)}`);
|
|
@@ -1145,44 +1117,44 @@ export class MetadataDiscovery {
|
|
|
1145
1117
|
return;
|
|
1146
1118
|
}
|
|
1147
1119
|
if (!prop.customType && ['json', 'jsonb'].includes(prop.type?.toLowerCase())) {
|
|
1148
|
-
prop.customType = new
|
|
1120
|
+
prop.customType = new t.json();
|
|
1149
1121
|
}
|
|
1150
1122
|
if (prop.kind === ReferenceKind.SCALAR && !prop.customType && prop.columnTypes && ['json', 'jsonb'].includes(prop.columnTypes[0])) {
|
|
1151
|
-
prop.customType = new
|
|
1123
|
+
prop.customType = new t.json();
|
|
1152
1124
|
}
|
|
1153
1125
|
if (prop.kind === ReferenceKind.EMBEDDED && !prop.customType && (prop.object || prop.array)) {
|
|
1154
|
-
prop.customType = new
|
|
1126
|
+
prop.customType = new t.json();
|
|
1155
1127
|
}
|
|
1156
1128
|
if (!prop.customType && prop.array && prop.items) {
|
|
1157
|
-
prop.customType = new
|
|
1129
|
+
prop.customType = new t.enumArray(`${meta.className}.${prop.name}`, prop.items);
|
|
1158
1130
|
}
|
|
1159
1131
|
const isArray = prop.type?.toLowerCase() === 'array' || prop.type?.toString().endsWith('[]');
|
|
1160
1132
|
if (objectEmbeddable && !prop.customType && isArray) {
|
|
1161
|
-
prop.customType = new
|
|
1133
|
+
prop.customType = new t.json();
|
|
1162
1134
|
}
|
|
1163
1135
|
// for number arrays we make sure to convert the items to numbers
|
|
1164
1136
|
if (!prop.customType && prop.type === 'number[]') {
|
|
1165
|
-
prop.customType = new
|
|
1137
|
+
prop.customType = new t.array(i => +i);
|
|
1166
1138
|
}
|
|
1167
1139
|
// `string[]` can be returned via ts-morph, while reflect metadata will give us just `array`
|
|
1168
1140
|
if (!prop.customType && isArray) {
|
|
1169
|
-
prop.customType = new
|
|
1141
|
+
prop.customType = new t.array();
|
|
1170
1142
|
}
|
|
1171
1143
|
if (!prop.customType && prop.type?.toLowerCase() === 'buffer') {
|
|
1172
|
-
prop.customType = new
|
|
1144
|
+
prop.customType = new t.blob();
|
|
1173
1145
|
}
|
|
1174
1146
|
if (!prop.customType && prop.type?.toLowerCase() === 'uint8array') {
|
|
1175
|
-
prop.customType = new
|
|
1147
|
+
prop.customType = new t.uint8array();
|
|
1176
1148
|
}
|
|
1177
1149
|
const mappedType = this.getMappedType(prop);
|
|
1178
1150
|
if (prop.fieldNames?.length === 1 && !prop.customType) {
|
|
1179
|
-
[
|
|
1151
|
+
[t.bigint, t.double, t.decimal, t.interval, t.date]
|
|
1180
1152
|
.filter(type => mappedType instanceof type)
|
|
1181
1153
|
.forEach((type) => prop.customType = new type());
|
|
1182
1154
|
}
|
|
1183
1155
|
if (prop.customType && !prop.columnTypes) {
|
|
1184
1156
|
const mappedType = this.getMappedType({ columnTypes: [prop.customType.getColumnType(prop, this.platform)] });
|
|
1185
|
-
if (prop.customType.compareAsType() === 'any' && ![
|
|
1157
|
+
if (prop.customType.compareAsType() === 'any' && ![t.json].some(t => prop.customType instanceof t)) {
|
|
1186
1158
|
prop.runtimeType ??= mappedType.runtimeType;
|
|
1187
1159
|
}
|
|
1188
1160
|
else {
|
|
@@ -1202,7 +1174,7 @@ export class MetadataDiscovery {
|
|
|
1202
1174
|
prop.columnTypes ??= [prop.customType.getColumnType(prop, this.platform)];
|
|
1203
1175
|
prop.hasConvertToJSValueSQL = !!prop.customType.convertToJSValueSQL && prop.customType.convertToJSValueSQL('', this.platform) !== '';
|
|
1204
1176
|
prop.hasConvertToDatabaseValueSQL = !!prop.customType.convertToDatabaseValueSQL && prop.customType.convertToDatabaseValueSQL('', this.platform) !== '';
|
|
1205
|
-
if (prop.customType instanceof
|
|
1177
|
+
if (prop.customType instanceof t.bigint && ['string', 'bigint', 'number'].includes(prop.runtimeType.toLowerCase())) {
|
|
1206
1178
|
prop.customType.mode = prop.runtimeType.toLowerCase();
|
|
1207
1179
|
}
|
|
1208
1180
|
}
|
|
@@ -1223,7 +1195,7 @@ export class MetadataDiscovery {
|
|
|
1223
1195
|
}
|
|
1224
1196
|
}
|
|
1225
1197
|
}
|
|
1226
|
-
if (prop.kind === ReferenceKind.SCALAR && !(mappedType instanceof
|
|
1198
|
+
if (prop.kind === ReferenceKind.SCALAR && !(mappedType instanceof t.unknown)) {
|
|
1227
1199
|
if (!prop.columnTypes && prop.nativeEnumName && meta.schema !== this.platform.getDefaultSchemaName() && meta.schema && !prop.nativeEnumName.includes('.')) {
|
|
1228
1200
|
prop.columnTypes = [`${meta.schema}.${prop.nativeEnumName}`];
|
|
1229
1201
|
}
|
|
@@ -1266,7 +1238,7 @@ export class MetadataDiscovery {
|
|
|
1266
1238
|
if (prop.kind === ReferenceKind.SCALAR) {
|
|
1267
1239
|
const mappedType = this.getMappedType(prop);
|
|
1268
1240
|
const SCALAR_TYPES = ['string', 'number', 'boolean', 'bigint', 'Date', 'Buffer', 'RegExp', 'any', 'unknown'];
|
|
1269
|
-
if (mappedType instanceof
|
|
1241
|
+
if (mappedType instanceof t.unknown
|
|
1270
1242
|
&& !prop.columnTypes
|
|
1271
1243
|
// it could be a runtime type from reflect-metadata
|
|
1272
1244
|
&& !SCALAR_TYPES.includes(prop.type)
|
|
@@ -1349,29 +1321,26 @@ export class MetadataDiscovery {
|
|
|
1349
1321
|
prop.index ??= true;
|
|
1350
1322
|
}
|
|
1351
1323
|
}
|
|
1352
|
-
async getEntityClassOrSchema(
|
|
1324
|
+
async getEntityClassOrSchema(filepath, allTargets) {
|
|
1325
|
+
const path = Utils.normalizePath(this.config.get('baseDir'), filepath);
|
|
1353
1326
|
const exports = await Utils.dynamicImport(path);
|
|
1354
|
-
const targets = Object.values(exports)
|
|
1355
|
-
.filter(item => item instanceof EntitySchema || (item instanceof Function && MetadataStorage.isKnownEntity(item.name)));
|
|
1327
|
+
const targets = Object.values(exports);
|
|
1356
1328
|
// ignore class implementations that are linked from an EntitySchema
|
|
1357
1329
|
for (const item of targets) {
|
|
1358
1330
|
if (item instanceof EntitySchema) {
|
|
1359
|
-
|
|
1331
|
+
for (const item2 of targets) {
|
|
1360
1332
|
if (item.meta.class === item2) {
|
|
1361
|
-
targets.splice(
|
|
1333
|
+
targets.splice(targets.indexOf(item2), 1);
|
|
1362
1334
|
}
|
|
1363
|
-
}
|
|
1335
|
+
}
|
|
1364
1336
|
}
|
|
1365
1337
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
if (!target) {
|
|
1372
|
-
throw MetadataError.entityNotFound(name, path.replace(this.config.get('baseDir'), '.'));
|
|
1338
|
+
for (const item of targets) {
|
|
1339
|
+
const validTarget = item instanceof EntitySchema || (item instanceof Function && MetadataStorage.isKnownEntity(item.name));
|
|
1340
|
+
if (validTarget && !allTargets.has(item)) {
|
|
1341
|
+
allTargets.set(item, path);
|
|
1342
|
+
}
|
|
1373
1343
|
}
|
|
1374
|
-
return [target];
|
|
1375
1344
|
}
|
|
1376
1345
|
shouldForceConstructorUsage(meta) {
|
|
1377
1346
|
const forceConstructor = this.config.get('forceEntityConstructor');
|
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.50",
|
|
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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dataloader": "2.2.3",
|
|
55
55
|
"dotenv": "17.2.3",
|
|
56
56
|
"esprima": "4.0.1",
|
|
57
|
-
"mikro-orm": "7.0.0-dev.
|
|
57
|
+
"mikro-orm": "7.0.0-dev.50",
|
|
58
58
|
"reflect-metadata": "0.2.2",
|
|
59
59
|
"tinyglobby": "0.2.13"
|
|
60
60
|
}
|
package/typings.d.ts
CHANGED
|
@@ -212,10 +212,6 @@ export type AnyEntity<T = any> = Partial<T>;
|
|
|
212
212
|
export type EntityClass<T> = Function & {
|
|
213
213
|
prototype: T;
|
|
214
214
|
};
|
|
215
|
-
export type EntityClassGroup<T> = {
|
|
216
|
-
entity: EntityClass<T>;
|
|
217
|
-
schema: EntityMetadata<T> | EntitySchema<T>;
|
|
218
|
-
};
|
|
219
215
|
export type EntityName<T> = string | EntityClass<T> | EntitySchema<T, any> | {
|
|
220
216
|
name: string;
|
|
221
217
|
};
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { NamingStrategy } from '../naming-strategy/NamingStrategy.js';
|
|
|
2
2
|
import { FileCacheAdapter } from '../cache/FileCacheAdapter.js';
|
|
3
3
|
import { type SyncCacheAdapter, type CacheAdapter } from '../cache/CacheAdapter.js';
|
|
4
4
|
import type { EntityRepository } from '../entity/EntityRepository.js';
|
|
5
|
-
import type { AnyEntity, Constructor, Dictionary, EntityClass,
|
|
5
|
+
import type { AnyEntity, Constructor, Dictionary, EntityClass, FilterDef, Highlighter, HydratorConstructor, IHydrator, IMigrationGenerator, IPrimaryKey, MaybePromise, MigrationObject, EntityMetadata, EnsureDatabaseOptions, GenerateOptions, Migration } from '../typings.js';
|
|
6
6
|
import { ObjectHydrator } from '../hydration/ObjectHydrator.js';
|
|
7
7
|
import { NullHighlighter } from '../utils/NullHighlighter.js';
|
|
8
8
|
import { type Logger, type LoggerNamespace, type LoggerOptions } from '../logging/Logger.js';
|
|
@@ -234,7 +234,7 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
234
234
|
/**
|
|
235
235
|
* Type helper to make it easier to use `mikro-orm.config.js`.
|
|
236
236
|
*/
|
|
237
|
-
export declare function defineConfig<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager<D> = EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> |
|
|
237
|
+
export declare function defineConfig<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager<D> = EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): Options<D, EM, Entities>;
|
|
238
238
|
export interface ConnectionOptions {
|
|
239
239
|
dbName?: string;
|
|
240
240
|
schema?: string;
|
|
@@ -299,8 +299,8 @@ export interface MetadataDiscoveryOptions {
|
|
|
299
299
|
skipSyncDiscovery?: boolean;
|
|
300
300
|
}
|
|
301
301
|
export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = EntityManager> extends ConnectionOptions {
|
|
302
|
-
entities: (string | EntityClass<AnyEntity> |
|
|
303
|
-
entitiesTs: (string | EntityClass<AnyEntity> |
|
|
302
|
+
entities: (string | EntityClass<AnyEntity> | EntitySchema)[];
|
|
303
|
+
entitiesTs: (string | EntityClass<AnyEntity> | EntitySchema)[];
|
|
304
304
|
extensions: {
|
|
305
305
|
register: (orm: MikroORM) => void;
|
|
306
306
|
}[];
|
|
@@ -415,6 +415,6 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
|
|
|
415
415
|
dynamicImportProvider: (id: string) => Promise<unknown>;
|
|
416
416
|
hashAlgorithm: 'md5' | 'sha256';
|
|
417
417
|
}
|
|
418
|
-
export interface Options<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> |
|
|
418
|
+
export interface Options<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends Pick<MikroORMOptions<D, EM>, Exclude<keyof MikroORMOptions, keyof typeof Configuration.DEFAULTS>>, Partial<MikroORMOptions<D, EM>> {
|
|
419
419
|
entities?: Entities;
|
|
420
420
|
}
|