@mikro-orm/core 7.0.0-dev.70 → 7.0.0-dev.72
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/cache/FileCacheAdapter.d.ts +1 -2
- package/cache/FileCacheAdapter.js +2 -4
- package/connections/Connection.js +0 -1
- package/metadata/MetadataStorage.js +1 -1
- package/package.json +1 -1
- package/unit-of-work/UnitOfWork.js +2 -1
- package/utils/Configuration.d.ts +0 -2
- package/utils/Configuration.js +1 -2
- package/utils/ConfigurationLoader.js +69 -59
- package/utils/Utils.d.ts +1 -7
- package/utils/Utils.js +8 -19
|
@@ -3,13 +3,12 @@ export declare class FileCacheAdapter implements SyncCacheAdapter {
|
|
|
3
3
|
private readonly options;
|
|
4
4
|
private readonly baseDir;
|
|
5
5
|
private readonly pretty;
|
|
6
|
-
private readonly hashAlgorithm;
|
|
7
6
|
private readonly VERSION;
|
|
8
7
|
private cache;
|
|
9
8
|
constructor(options: {
|
|
10
9
|
cacheDir: string;
|
|
11
10
|
combined?: boolean | string;
|
|
12
|
-
}, baseDir: string, pretty?: boolean
|
|
11
|
+
}, baseDir: string, pretty?: boolean);
|
|
13
12
|
/**
|
|
14
13
|
* @inheritDoc
|
|
15
14
|
*/
|
|
@@ -4,14 +4,12 @@ export class FileCacheAdapter {
|
|
|
4
4
|
options;
|
|
5
5
|
baseDir;
|
|
6
6
|
pretty;
|
|
7
|
-
hashAlgorithm;
|
|
8
7
|
VERSION = Utils.getORMVersion();
|
|
9
8
|
cache = {};
|
|
10
|
-
constructor(options, baseDir, pretty = false
|
|
9
|
+
constructor(options, baseDir, pretty = false) {
|
|
11
10
|
this.options = options;
|
|
12
11
|
this.baseDir = baseDir;
|
|
13
12
|
this.pretty = pretty;
|
|
14
|
-
this.hashAlgorithm = hashAlgorithm;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
15
|
* @inheritDoc
|
|
@@ -78,6 +76,6 @@ export class FileCacheAdapter {
|
|
|
78
76
|
return null;
|
|
79
77
|
}
|
|
80
78
|
const contents = readFileSync(origin);
|
|
81
|
-
return Utils.hash(contents.toString() + this.VERSION
|
|
79
|
+
return Utils.hash(contents.toString() + this.VERSION);
|
|
82
80
|
}
|
|
83
81
|
}
|
|
@@ -15,7 +15,7 @@ export class MetadataStorage {
|
|
|
15
15
|
this.metadata = Utils.copy(metadata, false);
|
|
16
16
|
}
|
|
17
17
|
static getMetadata(entity, path) {
|
|
18
|
-
const key = entity && path ? entity + '-' + Utils.hash(path
|
|
18
|
+
const key = entity && path ? entity + '-' + Utils.hash(path) : null;
|
|
19
19
|
if (key && !MetadataStorage.metadata[key]) {
|
|
20
20
|
MetadataStorage.metadata[key] = new EntityMetadata({ className: entity, path });
|
|
21
21
|
}
|
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.72",
|
|
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",
|
|
@@ -327,7 +327,8 @@ export class UnitOfWork {
|
|
|
327
327
|
this.filterCollectionUpdates();
|
|
328
328
|
// nothing to do, do not start transaction
|
|
329
329
|
if (this.changeSets.size === 0 && this.collectionUpdates.size === 0 && this.extraUpdates.size === 0) {
|
|
330
|
-
|
|
330
|
+
await this.eventManager.dispatchEvent(EventType.afterFlush, { em: this.em, uow: this });
|
|
331
|
+
return;
|
|
331
332
|
}
|
|
332
333
|
const groups = this.getChangeSetGroups();
|
|
333
334
|
const platform = this.em.getPlatform();
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -76,7 +76,6 @@ declare const DEFAULTS: {
|
|
|
76
76
|
readonly ensureDatabase: true;
|
|
77
77
|
readonly ensureIndexes: false;
|
|
78
78
|
readonly batchSize: 300;
|
|
79
|
-
readonly hashAlgorithm: "md5";
|
|
80
79
|
readonly debug: false;
|
|
81
80
|
readonly ignoreDeprecations: false;
|
|
82
81
|
readonly verbose: false;
|
|
@@ -407,7 +406,6 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
407
406
|
seeder?: SeederOptions;
|
|
408
407
|
preferReadReplicas?: boolean;
|
|
409
408
|
dynamicImportProvider?: (id: string) => Promise<unknown>;
|
|
410
|
-
hashAlgorithm?: 'md5' | 'sha256';
|
|
411
409
|
}
|
|
412
410
|
type MarkRequired<T, D> = {
|
|
413
411
|
[K in keyof T as Extract<K, keyof D>]-?: T[K];
|
package/utils/Configuration.js
CHANGED
|
@@ -68,7 +68,6 @@ const DEFAULTS = {
|
|
|
68
68
|
ensureDatabase: true,
|
|
69
69
|
ensureIndexes: false,
|
|
70
70
|
batchSize: 300,
|
|
71
|
-
hashAlgorithm: 'md5',
|
|
72
71
|
debug: false,
|
|
73
72
|
ignoreDeprecations: false,
|
|
74
73
|
verbose: false,
|
|
@@ -262,7 +261,7 @@ export class Configuration {
|
|
|
262
261
|
* Gets instance of metadata CacheAdapter. (cached)
|
|
263
262
|
*/
|
|
264
263
|
getMetadataCacheAdapter() {
|
|
265
|
-
return this.getCachedService(this.options.metadataCache.adapter, this.options.metadataCache.options, this.options.baseDir, this.options.metadataCache.pretty
|
|
264
|
+
return this.getCachedService(this.options.metadataCache.adapter, this.options.metadataCache.options, this.options.baseDir, this.options.metadataCache.pretty);
|
|
266
265
|
}
|
|
267
266
|
/**
|
|
268
267
|
* Gets instance of CacheAdapter for result cache. (cached)
|
|
@@ -7,78 +7,88 @@ import { colors } from '../logging/colors.js';
|
|
|
7
7
|
export class ConfigurationLoader {
|
|
8
8
|
static loadEnvironmentVars() {
|
|
9
9
|
const ret = {};
|
|
10
|
+
const getEnvKey = (key, envPrefix = 'MIKRO_ORM_') => {
|
|
11
|
+
return envPrefix + key
|
|
12
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
13
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
14
|
+
.toUpperCase();
|
|
15
|
+
};
|
|
10
16
|
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
11
17
|
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
12
18
|
const num = (v) => +v;
|
|
13
|
-
const read = (o,
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
const read = (o, envPrefix, key, mapper = v => v) => {
|
|
20
|
+
const envKey = getEnvKey(key, envPrefix);
|
|
21
|
+
if (envKey in process.env) {
|
|
22
|
+
o[key] = mapper(process.env[envKey]);
|
|
16
23
|
}
|
|
17
|
-
const val = process.env[envKey];
|
|
18
|
-
o[key] = mapper(val);
|
|
19
24
|
};
|
|
20
25
|
const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
21
|
-
read(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
const read0 = read.bind(null, ret, 'MIKRO_ORM_');
|
|
27
|
+
read0('baseDir');
|
|
28
|
+
read0('entities', array);
|
|
29
|
+
read0('entitiesTs', array);
|
|
30
|
+
read0('clientUrl');
|
|
31
|
+
read0('host');
|
|
32
|
+
read0('port', num);
|
|
33
|
+
read0('user');
|
|
34
|
+
read0('password');
|
|
35
|
+
read0('dbName');
|
|
36
|
+
read0('schema');
|
|
37
|
+
read0('loadStrategy');
|
|
38
|
+
read0('batchSize', num);
|
|
39
|
+
read0('useBatchInserts', bool);
|
|
40
|
+
read0('useBatchUpdates', bool);
|
|
41
|
+
read0('strict', bool);
|
|
42
|
+
read0('validate', bool);
|
|
43
|
+
read0('allowGlobalContext', bool);
|
|
44
|
+
read0('autoJoinOneToOneOwner', bool);
|
|
45
|
+
read0('populateAfterFlush', bool);
|
|
46
|
+
read0('forceEntityConstructor', bool);
|
|
47
|
+
read0('forceUndefined', bool);
|
|
48
|
+
read0('forceUtcTimezone', bool);
|
|
49
|
+
read0('timezone');
|
|
50
|
+
read0('ensureIndexes', bool);
|
|
51
|
+
read0('implicitTransactions', bool);
|
|
52
|
+
read0('debug', bool);
|
|
53
|
+
read0('colors', bool);
|
|
48
54
|
ret.discovery = {};
|
|
49
|
-
read(ret.discovery, '
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const read1 = read.bind(null, ret.discovery, 'MIKRO_ORM_DISCOVERY_');
|
|
56
|
+
read1('warnWhenNoEntities', bool);
|
|
57
|
+
read1('checkDuplicateTableNames', bool);
|
|
58
|
+
read1('checkDuplicateFieldNames', bool);
|
|
59
|
+
read1('checkDuplicateEntities', bool);
|
|
60
|
+
read1('checkNonPersistentCompositeProps', bool);
|
|
61
|
+
read1('inferDefaultValues', bool);
|
|
62
|
+
read1('tsConfigPath');
|
|
56
63
|
cleanup(ret, 'discovery');
|
|
57
64
|
ret.migrations = {};
|
|
58
|
-
read(ret.migrations, '
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const read2 = read.bind(null, ret.migrations, 'MIKRO_ORM_MIGRATIONS_');
|
|
66
|
+
read2('tableName');
|
|
67
|
+
read2('path');
|
|
68
|
+
read2('pathTs');
|
|
69
|
+
read2('glob');
|
|
70
|
+
read2('transactional', bool);
|
|
71
|
+
read2('disableForeignKeys', bool);
|
|
72
|
+
read2('allOrNothing', bool);
|
|
73
|
+
read2('dropTables', bool);
|
|
74
|
+
read2('safe', bool);
|
|
75
|
+
read2('silent', bool);
|
|
76
|
+
read2('emit');
|
|
77
|
+
read2('snapshot', bool);
|
|
78
|
+
read2('snapshotName');
|
|
71
79
|
cleanup(ret, 'migrations');
|
|
72
80
|
ret.schemaGenerator = {};
|
|
73
|
-
read(ret.schemaGenerator, '
|
|
74
|
-
|
|
81
|
+
const read3 = read.bind(null, ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_');
|
|
82
|
+
read3('disableForeignKeys', bool);
|
|
83
|
+
read3('createForeignKeyConstraints', bool);
|
|
75
84
|
cleanup(ret, 'schemaGenerator');
|
|
76
85
|
ret.seeder = {};
|
|
77
|
-
read(ret.seeder, '
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
const read4 = read.bind(null, ret.seeder, 'MIKRO_ORM_SEEDER_');
|
|
87
|
+
read4('path');
|
|
88
|
+
read4('pathTs');
|
|
89
|
+
read4('glob');
|
|
90
|
+
read4('emit');
|
|
91
|
+
read4('defaultSeeder');
|
|
82
92
|
cleanup(ret, 'seeder');
|
|
83
93
|
return ret;
|
|
84
94
|
}
|
package/utils/Utils.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ export declare class Utils {
|
|
|
147
147
|
* If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
|
|
148
148
|
*/
|
|
149
149
|
static absolutePath(path: string, baseDir?: string): string;
|
|
150
|
-
static hash(data: string, length?: number
|
|
150
|
+
static hash(data: string, length?: number): string;
|
|
151
151
|
static runIfNotEmpty(clause: () => any, data: any): void;
|
|
152
152
|
static defaultValue<T extends Dictionary>(prop: T, option: keyof T, defaultValue: any): void;
|
|
153
153
|
static findDuplicates<T>(items: T[]): T[];
|
|
@@ -168,12 +168,6 @@ export declare class Utils {
|
|
|
168
168
|
* @param [from] Location to start the node resolution
|
|
169
169
|
*/
|
|
170
170
|
static requireFrom<T extends Dictionary>(id: string, from?: string): T;
|
|
171
|
-
/**
|
|
172
|
-
* Resolve path to a module.
|
|
173
|
-
* @param id The module to require
|
|
174
|
-
* @param [from] Location to start the node resolution
|
|
175
|
-
*/
|
|
176
|
-
static resolveModulePath(id: string, from?: string): string;
|
|
177
171
|
static dynamicImport<T = any>(id: string): Promise<T>;
|
|
178
172
|
static ensureDir(path: string): void;
|
|
179
173
|
static readJSONSync(path: string): Dictionary;
|
package/utils/Utils.js
CHANGED
|
@@ -2,7 +2,6 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
4
|
import { existsSync, globSync, statSync, mkdirSync, readFileSync } from 'node:fs';
|
|
5
|
-
import { createHash } from 'node:crypto';
|
|
6
5
|
import { clone } from './clone.js';
|
|
7
6
|
import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
|
|
8
7
|
import { helper } from '../entity/wrap.js';
|
|
@@ -649,9 +648,14 @@ export class Utils {
|
|
|
649
648
|
}
|
|
650
649
|
return Utils.normalizePath(path);
|
|
651
650
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
651
|
+
// FNV-1a 64-bit
|
|
652
|
+
static hash(data, length) {
|
|
653
|
+
let h1 = 0xcbf29ce484222325n;
|
|
654
|
+
for (let i = 0; i < data.length; i++) {
|
|
655
|
+
h1 ^= BigInt(data.charCodeAt(i));
|
|
656
|
+
h1 = (h1 * 0x100000001b3n) & 0xffffffffffffffffn;
|
|
657
|
+
}
|
|
658
|
+
const hash = h1.toString(16).padStart(16, '0');
|
|
655
659
|
if (length) {
|
|
656
660
|
return hash.substring(0, length);
|
|
657
661
|
}
|
|
@@ -758,21 +762,6 @@ export class Utils {
|
|
|
758
762
|
}
|
|
759
763
|
return createRequire(resolve(from))(id);
|
|
760
764
|
}
|
|
761
|
-
/**
|
|
762
|
-
* Resolve path to a module.
|
|
763
|
-
* @param id The module to require
|
|
764
|
-
* @param [from] Location to start the node resolution
|
|
765
|
-
*/
|
|
766
|
-
static resolveModulePath(id, from = process.cwd()) {
|
|
767
|
-
if (!extname(from)) {
|
|
768
|
-
from = join(from, '__fake.js');
|
|
769
|
-
}
|
|
770
|
-
const path = Utils.normalizePath(createRequire(resolve(from)).resolve(id));
|
|
771
|
-
const parts = path.split('/');
|
|
772
|
-
const idx = parts.lastIndexOf(id) + 1;
|
|
773
|
-
parts.splice(idx, parts.length - idx);
|
|
774
|
-
return parts.join('/');
|
|
775
|
-
}
|
|
776
765
|
static async dynamicImport(id) {
|
|
777
766
|
/* v8 ignore next */
|
|
778
767
|
const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
|