@mikro-orm/core 7.0.0-dev.76 → 7.0.0-dev.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityManager.js +4 -4
- package/MikroORM.d.ts +29 -2
- package/MikroORM.js +69 -14
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +6 -4
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +0 -1
- package/cache/index.js +0 -1
- package/drivers/DatabaseDriver.js +4 -4
- package/entity/Collection.js +2 -2
- package/entity/EntityAssigner.js +2 -2
- package/entity/EntityFactory.js +1 -1
- package/entity/EntityLoader.js +4 -4
- package/entity/Reference.js +1 -1
- package/entity/WrappedEntity.d.ts +2 -2
- package/entity/utils.js +1 -1
- package/entity/validators.js +1 -1
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.js +1 -1
- package/metadata/MetadataDiscovery.d.ts +0 -2
- package/metadata/MetadataDiscovery.js +7 -45
- package/metadata/MetadataProvider.d.ts +9 -0
- package/metadata/MetadataProvider.js +29 -2
- package/metadata/discover-entities.js +2 -1
- package/naming-strategy/AbstractNamingStrategy.js +1 -1
- package/not-supported.d.ts +1 -0
- package/not-supported.js +2 -1
- package/package.json +5 -1
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.js +8 -17
- package/serialization/EntitySerializer.js +3 -3
- package/serialization/SerializationContext.js +2 -2
- package/types/ArrayType.js +1 -1
- package/types/BigIntType.js +1 -1
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/TinyIntType.js +1 -1
- package/types/Uint8ArrayType.js +1 -1
- package/typings.js +3 -3
- package/unit-of-work/UnitOfWork.js +1 -1
- package/utils/AbstractSchemaGenerator.js +1 -1
- package/utils/Configuration.d.ts +4 -24
- package/utils/Configuration.js +13 -50
- package/utils/ConfigurationLoader.d.ts +1 -13
- package/utils/ConfigurationLoader.js +1 -149
- package/utils/Cursor.js +1 -1
- package/utils/DataloaderUtils.js +2 -2
- package/utils/EntityComparator.js +4 -4
- package/utils/QueryHelper.js +1 -1
- package/utils/RawQueryFragment.js +1 -1
- package/utils/Utils.d.ts +0 -16
- package/utils/Utils.js +9 -89
- package/utils/clone.js +1 -1
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +96 -0
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -1
- package/utils/upsert-utils.js +3 -3
|
@@ -22,14 +22,41 @@ export class MetadataProvider {
|
|
|
22
22
|
loadFromCache(meta, cache) {
|
|
23
23
|
Object.values(cache.properties).forEach(prop => {
|
|
24
24
|
const metaProp = meta.properties[prop.name];
|
|
25
|
-
/* v8 ignore next
|
|
25
|
+
/* v8 ignore next */
|
|
26
26
|
if (metaProp?.enum && Array.isArray(metaProp.items)) {
|
|
27
27
|
delete prop.items;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Utils.mergeConfig(meta, cache);
|
|
31
31
|
}
|
|
32
|
+
static useCache() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
32
35
|
useCache() {
|
|
33
|
-
return this.config.get('metadataCache').enabled ??
|
|
36
|
+
return this.config.get('metadataCache').enabled ?? MetadataProvider.useCache();
|
|
37
|
+
}
|
|
38
|
+
saveToCache(meta) {
|
|
39
|
+
//
|
|
40
|
+
}
|
|
41
|
+
getCachedMetadata(meta, root) {
|
|
42
|
+
if (!this.useCache()) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const cache = meta.path && this.config.getMetadataCacheAdapter().get(this.getCacheKey(meta));
|
|
46
|
+
if (cache) {
|
|
47
|
+
this.loadFromCache(meta, cache);
|
|
48
|
+
meta.root = root;
|
|
49
|
+
}
|
|
50
|
+
return cache;
|
|
51
|
+
}
|
|
52
|
+
combineCache() {
|
|
53
|
+
const path = this.config.getMetadataCacheAdapter().combine?.();
|
|
54
|
+
// override the path in the options, so we can log it from the CLI in `cache:generate` command
|
|
55
|
+
if (path) {
|
|
56
|
+
this.config.get('metadataCache').combined = path;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
getCacheKey(meta) {
|
|
60
|
+
return meta.className;
|
|
34
61
|
}
|
|
35
62
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
|
+
import { fs } from '../utils/fs-utils.js';
|
|
2
3
|
import { Utils } from '../utils/Utils.js';
|
|
3
4
|
import { MetadataStorage } from './MetadataStorage.js';
|
|
4
5
|
import { EntitySchema } from './EntitySchema.js';
|
|
@@ -26,7 +27,7 @@ async function getEntityClassOrSchema(filepath, allTargets, baseDir) {
|
|
|
26
27
|
export async function discoverEntities(paths, options) {
|
|
27
28
|
paths = Utils.asArray(paths).map(path => Utils.normalizePath(path));
|
|
28
29
|
const baseDir = options?.baseDir ?? process.cwd();
|
|
29
|
-
const files =
|
|
30
|
+
const files = fs.glob(paths, Utils.normalizePath(baseDir));
|
|
30
31
|
const found = new Map();
|
|
31
32
|
for (const filepath of files) {
|
|
32
33
|
const filename = basename(filepath);
|
|
@@ -14,7 +14,7 @@ export class AbstractNamingStrategy {
|
|
|
14
14
|
return migrationName;
|
|
15
15
|
}
|
|
16
16
|
indexName(tableName, columns, type) {
|
|
17
|
-
/* v8 ignore next
|
|
17
|
+
/* v8 ignore next */
|
|
18
18
|
if (tableName.includes('.')) {
|
|
19
19
|
tableName = tableName.substring(tableName.indexOf('.') + 1);
|
|
20
20
|
}
|
package/not-supported.d.ts
CHANGED
package/not-supported.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export function discoverEntities() {
|
|
2
|
-
throw new Error('
|
|
2
|
+
throw new Error('Folder-based discovery is not supported in this environment.');
|
|
3
3
|
}
|
|
4
|
+
export const fs = new Proxy({}, { get: () => { throw new Error('File system is not supported in this environment.'); } });
|
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.78",
|
|
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",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"./file-discovery": {
|
|
10
10
|
"node": "./metadata/discover-entities.js",
|
|
11
11
|
"browser": "./not-supported.js"
|
|
12
|
+
},
|
|
13
|
+
"./fs-utils": {
|
|
14
|
+
"node": "./utils/fs-utils.js",
|
|
15
|
+
"browser": "./not-supported.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"repository": {
|
package/platforms/Platform.js
CHANGED
|
@@ -4,7 +4,7 @@ import { EntityRepository } from '../entity/EntityRepository.js';
|
|
|
4
4
|
import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
|
|
5
5
|
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
6
|
import { ArrayType, BigIntType, BlobType, BooleanType, CharacterType, DateTimeType, DateType, DecimalType, DoubleType, EnumType, FloatType, IntegerType, IntervalType, JsonType, MediumIntType, SmallIntType, StringType, TextType, TimeType, TinyIntType, Type, Uint8ArrayType, UnknownType, UuidType, } from '../types/index.js';
|
|
7
|
-
import { parseJsonSafe
|
|
7
|
+
import { parseJsonSafe } from '../utils/Utils.js';
|
|
8
8
|
import { ReferenceKind } from '../enums.js';
|
|
9
9
|
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
10
10
|
export const JsonProperty = Symbol('JsonProperty');
|
|
@@ -257,7 +257,7 @@ export class Platform {
|
|
|
257
257
|
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
258
258
|
return path.join('.');
|
|
259
259
|
}
|
|
260
|
-
/* v8 ignore next
|
|
260
|
+
/* v8 ignore next */
|
|
261
261
|
getJsonIndexDefinition(index) {
|
|
262
262
|
return index.columnNames;
|
|
263
263
|
}
|
|
@@ -290,7 +290,7 @@ export class Platform {
|
|
|
290
290
|
}
|
|
291
291
|
parseDate(value) {
|
|
292
292
|
const date = new Date(value);
|
|
293
|
-
/* v8 ignore next
|
|
293
|
+
/* v8 ignore next */
|
|
294
294
|
if (isNaN(date.getTime())) {
|
|
295
295
|
return value;
|
|
296
296
|
}
|
|
@@ -320,19 +320,10 @@ export class Platform {
|
|
|
320
320
|
if (extension) {
|
|
321
321
|
return extension;
|
|
322
322
|
}
|
|
323
|
-
/* v8 ignore next
|
|
324
|
-
|
|
325
|
-
module: moduleName,
|
|
326
|
-
warning: `Please install ${moduleName} package.`,
|
|
327
|
-
});
|
|
328
|
-
/* v8 ignore next 3 */
|
|
329
|
-
if (module) {
|
|
330
|
-
return this.config.getCachedService(module[extensionName], em);
|
|
331
|
-
}
|
|
332
|
-
/* v8 ignore next 2 */
|
|
333
|
-
throw new Error(`${extensionName} extension not registered.`);
|
|
323
|
+
/* v8 ignore next */
|
|
324
|
+
throw new Error(`${extensionName} extension not registered. Provide it in the ORM config, or use the async \`MikroORM.init()\` method to load extensions automatically.`);
|
|
334
325
|
}
|
|
335
|
-
/* v8 ignore next
|
|
326
|
+
/* v8 ignore next: kept for type inference only */
|
|
336
327
|
getSchemaGenerator(driver, em) {
|
|
337
328
|
throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
|
|
338
329
|
}
|
|
@@ -349,7 +340,7 @@ export class Platform {
|
|
|
349
340
|
quoteValue(value) {
|
|
350
341
|
return value;
|
|
351
342
|
}
|
|
352
|
-
/* v8 ignore next
|
|
343
|
+
/* v8 ignore next */
|
|
353
344
|
escape(value) {
|
|
354
345
|
return value;
|
|
355
346
|
}
|
|
@@ -506,8 +497,8 @@ export class Platform {
|
|
|
506
497
|
clone() {
|
|
507
498
|
return this;
|
|
508
499
|
}
|
|
509
|
-
/* v8 ignore next 4 */
|
|
510
500
|
/** @ignore */
|
|
501
|
+
/* v8 ignore next */
|
|
511
502
|
[inspect.custom]() {
|
|
512
503
|
return `[${this.constructor.name}]`;
|
|
513
504
|
}
|
|
@@ -113,7 +113,7 @@ export class EntitySerializer {
|
|
|
113
113
|
return ret;
|
|
114
114
|
}
|
|
115
115
|
static propertyName(meta, prop) {
|
|
116
|
-
/* v8 ignore next
|
|
116
|
+
/* v8 ignore next */
|
|
117
117
|
if (meta.properties[prop]?.serializedName) {
|
|
118
118
|
return meta.properties[prop].serializedName;
|
|
119
119
|
}
|
|
@@ -137,7 +137,7 @@ export class EntitySerializer {
|
|
|
137
137
|
}
|
|
138
138
|
return returnValue;
|
|
139
139
|
}
|
|
140
|
-
/* v8 ignore next
|
|
140
|
+
/* v8 ignore next */
|
|
141
141
|
if (!options.ignoreSerializers && serializer) {
|
|
142
142
|
return serializer(value);
|
|
143
143
|
}
|
|
@@ -150,7 +150,7 @@ export class EntitySerializer {
|
|
|
150
150
|
if (Utils.isScalarReference(value)) {
|
|
151
151
|
return value.unwrap();
|
|
152
152
|
}
|
|
153
|
-
/* v8 ignore next
|
|
153
|
+
/* v8 ignore next */
|
|
154
154
|
if (property?.kind === ReferenceKind.EMBEDDED) {
|
|
155
155
|
if (Array.isArray(value)) {
|
|
156
156
|
return value.map(item => helper(item).toJSON());
|
|
@@ -36,7 +36,7 @@ export class SerializationContext {
|
|
|
36
36
|
}
|
|
37
37
|
leave(entityName, prop) {
|
|
38
38
|
const last = this.path.pop();
|
|
39
|
-
/* v8 ignore next
|
|
39
|
+
/* v8 ignore next */
|
|
40
40
|
if (last?.[0] !== entityName || last[1] !== prop) {
|
|
41
41
|
throw new Error(`Trying to leave wrong property: ${entityName}.${prop} instead of ${last?.join('.')}`);
|
|
42
42
|
}
|
|
@@ -98,7 +98,7 @@ export class SerializationContext {
|
|
|
98
98
|
}
|
|
99
99
|
let fields = [...this.fields];
|
|
100
100
|
for (const segment of this.path) {
|
|
101
|
-
/* v8 ignore next
|
|
101
|
+
/* v8 ignore next */
|
|
102
102
|
if (fields.length === 0) {
|
|
103
103
|
return true;
|
|
104
104
|
}
|
package/types/ArrayType.js
CHANGED
package/types/BigIntType.js
CHANGED
package/types/DecimalType.js
CHANGED
|
@@ -8,7 +8,7 @@ export class DecimalType extends Type {
|
|
|
8
8
|
super();
|
|
9
9
|
this.mode = mode;
|
|
10
10
|
}
|
|
11
|
-
/* v8 ignore next
|
|
11
|
+
/* v8 ignore next */
|
|
12
12
|
convertToJSValue(value) {
|
|
13
13
|
if ((this.mode ?? this.prop?.runtimeType) === 'number') {
|
|
14
14
|
return +value;
|
|
@@ -19,7 +19,7 @@ export class DecimalType extends Type {
|
|
|
19
19
|
return this.format(a) === this.format(b);
|
|
20
20
|
}
|
|
21
21
|
format(val) {
|
|
22
|
-
/* v8 ignore next
|
|
22
|
+
/* v8 ignore next */
|
|
23
23
|
if (this.prop?.scale == null) {
|
|
24
24
|
return +val;
|
|
25
25
|
}
|
package/types/DoubleType.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Type } from './Type.js';
|
|
|
3
3
|
* Type that maps an SQL DOUBLE to a JS string or number.
|
|
4
4
|
*/
|
|
5
5
|
export class DoubleType extends Type {
|
|
6
|
-
/* v8 ignore next
|
|
6
|
+
/* v8 ignore next */
|
|
7
7
|
convertToJSValue(value) {
|
|
8
8
|
if (this.prop?.runtimeType === 'number') {
|
|
9
9
|
return +value;
|
package/types/TinyIntType.js
CHANGED
package/types/Uint8ArrayType.js
CHANGED
package/typings.js
CHANGED
|
@@ -32,7 +32,7 @@ export class EntityMetadata {
|
|
|
32
32
|
}
|
|
33
33
|
this.properties[prop.name] = prop;
|
|
34
34
|
this.propertyOrder.set(prop.name, this.props.length);
|
|
35
|
-
/* v8 ignore next
|
|
35
|
+
/* v8 ignore next */
|
|
36
36
|
if (sync) {
|
|
37
37
|
this.sync();
|
|
38
38
|
}
|
|
@@ -40,7 +40,7 @@ export class EntityMetadata {
|
|
|
40
40
|
removeProperty(name, sync = true) {
|
|
41
41
|
delete this.properties[name];
|
|
42
42
|
this.propertyOrder.delete(name);
|
|
43
|
-
/* v8 ignore next
|
|
43
|
+
/* v8 ignore next */
|
|
44
44
|
if (sync) {
|
|
45
45
|
this.sync();
|
|
46
46
|
}
|
|
@@ -181,7 +181,7 @@ export class EntityMetadata {
|
|
|
181
181
|
this.indexes.push({ properties: prop.name });
|
|
182
182
|
prop.index = false;
|
|
183
183
|
}
|
|
184
|
-
/* v8 ignore next
|
|
184
|
+
/* v8 ignore next */
|
|
185
185
|
if (owner && prop.fieldNames.length > 1 && prop.unique) {
|
|
186
186
|
this.uniques.push({ properties: prop.name });
|
|
187
187
|
prop.unique = false;
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NamingStrategy } from '../naming-strategy/NamingStrategy.js';
|
|
2
|
-
import { FileCacheAdapter } from '../cache/FileCacheAdapter.js';
|
|
3
2
|
import { type CacheAdapter, type SyncCacheAdapter } from '../cache/CacheAdapter.js';
|
|
4
3
|
import type { EntityRepository } from '../entity/EntityRepository.js';
|
|
5
4
|
import type { AnyEntity, Constructor, Dictionary, EnsureDatabaseOptions, EntityClass, EntityMetadata, FilterDef, GenerateOptions, Highlighter, HydratorConstructor, IHydrator, IMigrationGenerator, IPrimaryKey, MaybePromise, Migration, MigrationObject } from '../typings.js';
|
|
@@ -35,10 +34,8 @@ declare const DEFAULTS: {
|
|
|
35
34
|
readonly checkNonPersistentCompositeProps: true;
|
|
36
35
|
readonly inferDefaultValues: true;
|
|
37
36
|
};
|
|
38
|
-
readonly strict: false;
|
|
39
|
-
readonly validate: false;
|
|
40
37
|
readonly validateRequired: true;
|
|
41
|
-
readonly context: (name: string) => EntityManager<IDatabaseDriver<import("
|
|
38
|
+
readonly context: (name: string) => EntityManager<IDatabaseDriver<import("@mikro-orm/knex").Connection>> | undefined;
|
|
42
39
|
readonly contextName: "default";
|
|
43
40
|
readonly allowGlobalContext: false;
|
|
44
41
|
readonly logger: (message?: any, ...optionalParams: any[]) => void;
|
|
@@ -82,7 +79,6 @@ declare const DEFAULTS: {
|
|
|
82
79
|
readonly driverOptions: {};
|
|
83
80
|
readonly migrations: {
|
|
84
81
|
readonly tableName: "mikro_orm_migrations";
|
|
85
|
-
readonly path: "./migrations";
|
|
86
82
|
readonly glob: "!(*.d).{js,ts,cjs}";
|
|
87
83
|
readonly silent: false;
|
|
88
84
|
readonly transactional: true;
|
|
@@ -120,13 +116,7 @@ declare const DEFAULTS: {
|
|
|
120
116
|
readonly readOnlyPivotTables: false;
|
|
121
117
|
readonly useCoreBaseEntity: false;
|
|
122
118
|
};
|
|
123
|
-
readonly metadataCache: {
|
|
124
|
-
readonly pretty: false;
|
|
125
|
-
readonly adapter: typeof FileCacheAdapter;
|
|
126
|
-
readonly options: {
|
|
127
|
-
readonly cacheDir: string;
|
|
128
|
-
};
|
|
129
|
-
};
|
|
119
|
+
readonly metadataCache: {};
|
|
130
120
|
readonly resultCache: {
|
|
131
121
|
readonly adapter: typeof MemoryCacheAdapter;
|
|
132
122
|
readonly expiration: 1000;
|
|
@@ -135,7 +125,6 @@ declare const DEFAULTS: {
|
|
|
135
125
|
readonly metadataProvider: typeof MetadataProvider;
|
|
136
126
|
readonly highlighter: NullHighlighter;
|
|
137
127
|
readonly seeder: {
|
|
138
|
-
readonly path: "./seeders";
|
|
139
128
|
readonly defaultSeeder: "DatabaseSeeder";
|
|
140
129
|
readonly glob: "!(*.d).{js,ts}";
|
|
141
130
|
readonly emit: "ts";
|
|
@@ -215,15 +204,6 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
215
204
|
resetServiceCache(): void;
|
|
216
205
|
private init;
|
|
217
206
|
private sync;
|
|
218
|
-
/**
|
|
219
|
-
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
220
|
-
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
221
|
-
* used for the TS variant (`pathTs` option).
|
|
222
|
-
*
|
|
223
|
-
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
224
|
-
* break existing projects, only help with the new ones.
|
|
225
|
-
*/
|
|
226
|
-
private detectSourceFolder;
|
|
227
207
|
private validateOptions;
|
|
228
208
|
}
|
|
229
209
|
/**
|
|
@@ -905,8 +885,7 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
905
885
|
*/
|
|
906
886
|
pretty?: boolean;
|
|
907
887
|
/**
|
|
908
|
-
* Cache adapter class to use.
|
|
909
|
-
* @default FileCacheAdapter
|
|
888
|
+
* Cache adapter class to use. When cache is enabled, and no adapter is provided explicitly, {@link FileCacheAdapter} is used automatically - but only if you use the async `MikroORM.init()` method.
|
|
910
889
|
*/
|
|
911
890
|
adapter?: {
|
|
912
891
|
new (...params: any[]): SyncCacheAdapter;
|
|
@@ -952,6 +931,7 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
952
931
|
*/
|
|
953
932
|
metadataProvider?: {
|
|
954
933
|
new (config: Configuration): MetadataProvider;
|
|
934
|
+
useCache?: MetadataProvider['useCache'];
|
|
955
935
|
};
|
|
956
936
|
/**
|
|
957
937
|
* Seeder configuration options.
|
package/utils/Configuration.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FileCacheAdapter } from '../cache/FileCacheAdapter.js';
|
|
2
1
|
import { NullCacheAdapter } from '../cache/NullCacheAdapter.js';
|
|
3
2
|
import { ObjectHydrator } from '../hydration/ObjectHydrator.js';
|
|
4
3
|
import { NullHighlighter } from '../utils/NullHighlighter.js';
|
|
@@ -26,8 +25,6 @@ const DEFAULTS = {
|
|
|
26
25
|
checkNonPersistentCompositeProps: true,
|
|
27
26
|
inferDefaultValues: true,
|
|
28
27
|
},
|
|
29
|
-
strict: false,
|
|
30
|
-
validate: false,
|
|
31
28
|
validateRequired: true,
|
|
32
29
|
context: (name) => RequestContext.getEntityManager(name),
|
|
33
30
|
contextName: 'default',
|
|
@@ -74,7 +71,6 @@ const DEFAULTS = {
|
|
|
74
71
|
driverOptions: {},
|
|
75
72
|
migrations: {
|
|
76
73
|
tableName: 'mikro_orm_migrations',
|
|
77
|
-
path: './migrations',
|
|
78
74
|
glob: '!(*.d).{js,ts,cjs}',
|
|
79
75
|
silent: false,
|
|
80
76
|
transactional: true,
|
|
@@ -106,17 +102,14 @@ const DEFAULTS = {
|
|
|
106
102
|
entityDefinition: 'defineEntity',
|
|
107
103
|
decorators: 'legacy',
|
|
108
104
|
enumMode: 'dictionary',
|
|
105
|
+
/* v8 ignore next */
|
|
109
106
|
fileName: (className) => className,
|
|
110
107
|
onlyPurePivotTables: false,
|
|
111
108
|
outputPurePivotTables: false,
|
|
112
109
|
readOnlyPivotTables: false,
|
|
113
110
|
useCoreBaseEntity: false,
|
|
114
111
|
},
|
|
115
|
-
metadataCache: {
|
|
116
|
-
pretty: false,
|
|
117
|
-
adapter: FileCacheAdapter,
|
|
118
|
-
options: { cacheDir: process.cwd() + '/temp' },
|
|
119
|
-
},
|
|
112
|
+
metadataCache: {},
|
|
120
113
|
resultCache: {
|
|
121
114
|
adapter: MemoryCacheAdapter,
|
|
122
115
|
expiration: 1000, // 1s
|
|
@@ -125,7 +118,6 @@ const DEFAULTS = {
|
|
|
125
118
|
metadataProvider: MetadataProvider,
|
|
126
119
|
highlighter: new NullHighlighter(),
|
|
127
120
|
seeder: {
|
|
128
|
-
path: './seeders',
|
|
129
121
|
defaultSeeder: 'DatabaseSeeder',
|
|
130
122
|
glob: '!(*.d).{js,ts}',
|
|
131
123
|
emit: 'ts',
|
|
@@ -162,7 +154,6 @@ export class Configuration {
|
|
|
162
154
|
this.driver = new this.options.driver(this);
|
|
163
155
|
this.platform = this.driver.getPlatform();
|
|
164
156
|
this.platform.setConfig(this);
|
|
165
|
-
this.detectSourceFolder(options);
|
|
166
157
|
this.init(validate);
|
|
167
158
|
}
|
|
168
159
|
}
|
|
@@ -226,7 +217,7 @@ export class Configuration {
|
|
|
226
217
|
return this.cache.get(name);
|
|
227
218
|
}
|
|
228
219
|
const ext = this.extensions.get(name);
|
|
229
|
-
/* v8 ignore next
|
|
220
|
+
/* v8 ignore next */
|
|
230
221
|
if (!ext) {
|
|
231
222
|
return undefined;
|
|
232
223
|
}
|
|
@@ -294,16 +285,17 @@ export class Configuration {
|
|
|
294
285
|
this.cache.clear();
|
|
295
286
|
}
|
|
296
287
|
init(validate) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.options.metadataCache.enabled = this.getMetadataProvider().useCache();
|
|
302
|
-
}
|
|
303
|
-
if (!this.options.clientUrl) {
|
|
304
|
-
this.options.clientUrl = this.platform.getDefaultClientUrl();
|
|
288
|
+
const useCache = this.getMetadataProvider().useCache();
|
|
289
|
+
const metadataCache = this.options.metadataCache;
|
|
290
|
+
if (!useCache) {
|
|
291
|
+
metadataCache.adapter = NullCacheAdapter;
|
|
305
292
|
}
|
|
293
|
+
metadataCache.enabled ??= useCache;
|
|
294
|
+
this.options.clientUrl ??= this.platform.getDefaultClientUrl();
|
|
306
295
|
this.options.implicitTransactions ??= this.platform.usesImplicitTransactions();
|
|
296
|
+
if (metadataCache.enabled && !metadataCache.adapter) {
|
|
297
|
+
throw new Error('No metadata cache adapter specified, please fill in `metadataCache.adapter` option or use the async MikroORM.init() method which can autoload it.');
|
|
298
|
+
}
|
|
307
299
|
try {
|
|
308
300
|
const url = new URL(this.options.clientUrl);
|
|
309
301
|
if (url.pathname) {
|
|
@@ -339,37 +331,8 @@ export class Configuration {
|
|
|
339
331
|
process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
|
|
340
332
|
this.logger.setDebugMode(this.options.debug);
|
|
341
333
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
344
|
-
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
345
|
-
* used for the TS variant (`pathTs` option).
|
|
346
|
-
*
|
|
347
|
-
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
348
|
-
* break existing projects, only help with the new ones.
|
|
349
|
-
*/
|
|
350
|
-
detectSourceFolder(options) {
|
|
351
|
-
if (!Utils.pathExists(this.options.baseDir + '/src')) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
const migrationsPathExists = Utils.pathExists(this.options.baseDir + '/' + this.options.migrations.path);
|
|
355
|
-
const seedersPathExists = Utils.pathExists(this.options.baseDir + '/' + this.options.seeder.path);
|
|
356
|
-
const distDir = Utils.pathExists(this.options.baseDir + '/dist');
|
|
357
|
-
const buildDir = Utils.pathExists(this.options.baseDir + '/build');
|
|
358
|
-
// if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
|
|
359
|
-
const path = distDir ? './dist' : (buildDir ? './build' : './src');
|
|
360
|
-
// only if the user did not provide any values and if the default path does not exist
|
|
361
|
-
if (!options.migrations?.path && !options.migrations?.pathTs && !migrationsPathExists) {
|
|
362
|
-
this.options.migrations.path = `${path}/migrations`;
|
|
363
|
-
this.options.migrations.pathTs = './src/migrations';
|
|
364
|
-
}
|
|
365
|
-
// only if the user did not provide any values and if the default path does not exist
|
|
366
|
-
if (!options.seeder?.path && !options.seeder?.pathTs && !seedersPathExists) {
|
|
367
|
-
this.options.seeder.path = `${path}/seeders`;
|
|
368
|
-
this.options.seeder.pathTs = './src/seeders';
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
334
|
validateOptions() {
|
|
372
|
-
/* v8 ignore next
|
|
335
|
+
/* v8 ignore next */
|
|
373
336
|
if ('type' in this.options) {
|
|
374
337
|
throw new Error('The `type` option has been removed in v6, please fill in the `driver` option instead or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from \'@mikro-orm/mysql\'; export default defineConfig({ ... })`).');
|
|
375
338
|
}
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Dictionary } from '../typings.js';
|
|
3
|
-
import { type Options } from './Configuration.js';
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare class ConfigurationLoader {
|
|
8
|
-
static loadEnvironmentVars<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
9
|
-
static getPackageConfig(basePath?: string): Dictionary;
|
|
10
|
-
static getORMPackages(): Set<string>;
|
|
11
|
-
static getORMPackageVersion(name: string): string | undefined;
|
|
12
|
-
static checkPackageVersion(): string;
|
|
13
|
-
}
|
|
1
|
+
export {};
|