@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
|
@@ -1,149 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Utils } from './Utils.js';
|
|
3
|
-
import { colors } from '../logging/colors.js';
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export class ConfigurationLoader {
|
|
8
|
-
static loadEnvironmentVars() {
|
|
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
|
-
};
|
|
16
|
-
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
17
|
-
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
18
|
-
const num = (v) => +v;
|
|
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]);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
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);
|
|
54
|
-
ret.discovery = {};
|
|
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');
|
|
63
|
-
cleanup(ret, 'discovery');
|
|
64
|
-
ret.migrations = {};
|
|
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');
|
|
79
|
-
cleanup(ret, 'migrations');
|
|
80
|
-
ret.schemaGenerator = {};
|
|
81
|
-
const read3 = read.bind(null, ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_');
|
|
82
|
-
read3('disableForeignKeys', bool);
|
|
83
|
-
read3('createForeignKeyConstraints', bool);
|
|
84
|
-
cleanup(ret, 'schemaGenerator');
|
|
85
|
-
ret.seeder = {};
|
|
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');
|
|
92
|
-
cleanup(ret, 'seeder');
|
|
93
|
-
return ret;
|
|
94
|
-
}
|
|
95
|
-
static getPackageConfig(basePath = process.cwd()) {
|
|
96
|
-
if (Utils.pathExists(`${basePath}/package.json`)) {
|
|
97
|
-
/* v8 ignore next 5 */
|
|
98
|
-
try {
|
|
99
|
-
return Utils.readJSONSync(`${basePath}/package.json`);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const parentFolder = realpathSync(`${basePath}/..`);
|
|
106
|
-
// we reached the root folder
|
|
107
|
-
if (basePath === parentFolder) {
|
|
108
|
-
return {};
|
|
109
|
-
}
|
|
110
|
-
return this.getPackageConfig(parentFolder);
|
|
111
|
-
}
|
|
112
|
-
static getORMPackages() {
|
|
113
|
-
const pkg = this.getPackageConfig();
|
|
114
|
-
return new Set([
|
|
115
|
-
...Object.keys(pkg.dependencies ?? {}),
|
|
116
|
-
...Object.keys(pkg.devDependencies ?? {}),
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
static getORMPackageVersion(name) {
|
|
120
|
-
try {
|
|
121
|
-
const pkg = Utils.requireFrom(`${name}/package.json`);
|
|
122
|
-
/* v8 ignore next */
|
|
123
|
-
return pkg?.version;
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
130
|
-
static checkPackageVersion() {
|
|
131
|
-
const coreVersion = Utils.getORMVersion();
|
|
132
|
-
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === 'N/A') {
|
|
133
|
-
return coreVersion;
|
|
134
|
-
}
|
|
135
|
-
const deps = this.getORMPackages();
|
|
136
|
-
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
137
|
-
const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
|
|
138
|
-
for (const ormPackage of ormPackages) {
|
|
139
|
-
const version = this.getORMPackageVersion(ormPackage);
|
|
140
|
-
if (version != null && version !== coreVersion) {
|
|
141
|
-
throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
|
|
142
|
-
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
|
|
143
|
-
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
144
|
-
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return coreVersion;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
1
|
+
export {};
|
package/utils/Cursor.js
CHANGED
|
@@ -162,8 +162,8 @@ export class Cursor {
|
|
|
162
162
|
return ret;
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
/* v8 ignore start */
|
|
166
165
|
/** @ignore */
|
|
166
|
+
/* v8 ignore next */
|
|
167
167
|
[inspect.custom]() {
|
|
168
168
|
const type = this.items[0]?.constructor.name;
|
|
169
169
|
const { items, startCursor, endCursor, hasPrevPage, hasNextPage, totalCount, length } = this;
|
package/utils/DataloaderUtils.js
CHANGED
|
@@ -168,7 +168,7 @@ export class DataloaderUtils {
|
|
|
168
168
|
const entities = resultsMap.get(key);
|
|
169
169
|
if (entities == null) {
|
|
170
170
|
// Should never happen
|
|
171
|
-
/* v8 ignore next
|
|
171
|
+
/* v8 ignore next */
|
|
172
172
|
throw new Error('Cannot match results');
|
|
173
173
|
}
|
|
174
174
|
return entities.filter(DataloaderUtils.getColFilter(col));
|
|
@@ -221,7 +221,7 @@ export class DataloaderUtils {
|
|
|
221
221
|
return (this.DataLoader ??= DataLoader);
|
|
222
222
|
}
|
|
223
223
|
catch {
|
|
224
|
-
/* v8 ignore next
|
|
224
|
+
/* v8 ignore next */
|
|
225
225
|
throw new Error('DataLoader is not found, make sure `dataloader` package is installed in your project\'s dependencies.');
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -48,7 +48,7 @@ export class EntityComparator {
|
|
|
48
48
|
*/
|
|
49
49
|
getPkGetter(meta) {
|
|
50
50
|
const exists = this.pkGetters.get(meta.className);
|
|
51
|
-
/* v8 ignore next
|
|
51
|
+
/* v8 ignore next */
|
|
52
52
|
if (exists) {
|
|
53
53
|
return exists;
|
|
54
54
|
}
|
|
@@ -98,7 +98,7 @@ export class EntityComparator {
|
|
|
98
98
|
*/
|
|
99
99
|
getPkGetterConverted(meta) {
|
|
100
100
|
const exists = this.pkGettersConverted.get(meta.className);
|
|
101
|
-
/* v8 ignore next
|
|
101
|
+
/* v8 ignore next */
|
|
102
102
|
if (exists) {
|
|
103
103
|
return exists;
|
|
104
104
|
}
|
|
@@ -148,7 +148,7 @@ export class EntityComparator {
|
|
|
148
148
|
*/
|
|
149
149
|
getPkSerializer(meta) {
|
|
150
150
|
const exists = this.pkSerializers.get(meta.className);
|
|
151
|
-
/* v8 ignore next
|
|
151
|
+
/* v8 ignore next */
|
|
152
152
|
if (exists) {
|
|
153
153
|
return exists;
|
|
154
154
|
}
|
|
@@ -477,7 +477,7 @@ export class EntityComparator {
|
|
|
477
477
|
registerCustomType(prop, context) {
|
|
478
478
|
const convertorKey = this.safeKey(prop.name);
|
|
479
479
|
context.set(`convertToDatabaseValue_${convertorKey}`, (val) => {
|
|
480
|
-
/* v8 ignore next
|
|
480
|
+
/* v8 ignore next */
|
|
481
481
|
if (RawQueryFragment.isKnownFragment(val)) {
|
|
482
482
|
return val;
|
|
483
483
|
}
|
package/utils/QueryHelper.js
CHANGED
package/utils/Utils.d.ts
CHANGED
|
@@ -153,8 +153,6 @@ export declare class Utils {
|
|
|
153
153
|
static findDuplicates<T>(items: T[]): T[];
|
|
154
154
|
static removeDuplicates<T>(items: T[]): T[];
|
|
155
155
|
static randomInt(min: number, max: number): number;
|
|
156
|
-
static glob(input: string | string[], cwd?: string): string[];
|
|
157
|
-
static pathExists(path: string): boolean;
|
|
158
156
|
/**
|
|
159
157
|
* Extracts all possible values of a TS enum. Works with both string and numeric enums.
|
|
160
158
|
*/
|
|
@@ -162,26 +160,12 @@ export declare class Utils {
|
|
|
162
160
|
static flatten<T>(arrays: T[][]): T[];
|
|
163
161
|
static isOperator(key: PropertyKey, includeGroupOperators?: boolean): boolean;
|
|
164
162
|
static hasNestedKey(object: unknown, key: string): boolean;
|
|
165
|
-
/**
|
|
166
|
-
* Require a module from a specific location
|
|
167
|
-
* @param id The module to require
|
|
168
|
-
* @param [from] Location to start the node resolution
|
|
169
|
-
*/
|
|
170
|
-
static requireFrom<T extends Dictionary>(id: string, from?: string): T;
|
|
171
163
|
static dynamicImport<T = any>(id: string): Promise<T>;
|
|
172
|
-
static ensureDir(path: string): void;
|
|
173
|
-
static readJSONSync(path: string): Dictionary;
|
|
174
164
|
static getORMVersion(): string;
|
|
175
165
|
static createFunction(context: Map<string, any>, code: string): any;
|
|
176
166
|
static callCompiledFunction<T extends unknown[], R>(fn: (...args: T) => R, ...args: T): R;
|
|
177
167
|
static unwrapProperty<T>(entity: T, meta: EntityMetadata<T>, prop: EntityProperty<T>, payload?: boolean): [unknown, number[]][];
|
|
178
168
|
static setPayloadProperty<T>(entity: EntityDictionary<T>, meta: EntityMetadata<T>, prop: EntityProperty<T>, value: unknown, idx: number[]): void;
|
|
179
|
-
static tryRequire<T extends Dictionary = any>({ module, from, allowError, warning }: {
|
|
180
|
-
module: string;
|
|
181
|
-
warning?: string;
|
|
182
|
-
from?: string;
|
|
183
|
-
allowError?: string;
|
|
184
|
-
}): T | undefined;
|
|
185
169
|
static tryImport<T extends Dictionary = any>({ module, warning }: {
|
|
186
170
|
module: string;
|
|
187
171
|
warning?: string;
|
package/utils/Utils.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
|
|
1
|
+
import { isAbsolute, normalize, relative } from 'node:path';
|
|
3
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
-
import { existsSync, globSync, statSync, mkdirSync, readFileSync } from 'node:fs';
|
|
5
3
|
import { clone } from './clone.js';
|
|
6
4
|
import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
|
|
7
5
|
import { helper } from '../entity/wrap.js';
|
|
@@ -36,7 +34,7 @@ export function compareObjects(a, b) {
|
|
|
36
34
|
}
|
|
37
35
|
return timeA === timeB;
|
|
38
36
|
}
|
|
39
|
-
/* v8 ignore next
|
|
37
|
+
/* v8 ignore next */
|
|
40
38
|
if ((typeof a === 'function' && typeof b === 'function') ||
|
|
41
39
|
(typeof a === 'object' && a.client && ['Ref', 'Raw'].includes(a.constructor.name) && typeof b === 'object' && b.client && ['Ref', 'Raw'].includes(b.constructor.name)) || // knex qb
|
|
42
40
|
(a instanceof RegExp && b instanceof RegExp) ||
|
|
@@ -114,7 +112,7 @@ export function equals(a, b) {
|
|
|
114
112
|
const equalsFn = equals;
|
|
115
113
|
export function parseJsonSafe(value) {
|
|
116
114
|
if (typeof value === 'string') {
|
|
117
|
-
/* v8 ignore next
|
|
115
|
+
/* v8 ignore next */
|
|
118
116
|
try {
|
|
119
117
|
return JSON.parse(value);
|
|
120
118
|
}
|
|
@@ -227,7 +225,7 @@ export class Utils {
|
|
|
227
225
|
target[key] = Utils.copy(value);
|
|
228
226
|
continue;
|
|
229
227
|
}
|
|
230
|
-
/* v8 ignore next
|
|
228
|
+
/* v8 ignore next */
|
|
231
229
|
if (!(key in target)) {
|
|
232
230
|
Object.assign(target, { [key]: {} });
|
|
233
231
|
}
|
|
@@ -393,7 +391,7 @@ export class Utils {
|
|
|
393
391
|
return key.split(this.PK_SEPARATOR);
|
|
394
392
|
}
|
|
395
393
|
static getPrimaryKeyValues(entity, meta, allowScalar = false, convertCustomTypes = false) {
|
|
396
|
-
/* v8 ignore next
|
|
394
|
+
/* v8 ignore next */
|
|
397
395
|
if (entity == null) {
|
|
398
396
|
return entity;
|
|
399
397
|
}
|
|
@@ -538,7 +536,7 @@ export class Utils {
|
|
|
538
536
|
* Tries to detect TypeScript support.
|
|
539
537
|
*/
|
|
540
538
|
static detectTypeScriptSupport() {
|
|
541
|
-
/* v8 ignore next
|
|
539
|
+
/* v8 ignore next */
|
|
542
540
|
return process.argv[0].endsWith('ts-node') // running via ts-node directly
|
|
543
541
|
|| !!process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
|
|
544
542
|
|| !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)
|
|
@@ -687,33 +685,6 @@ export class Utils {
|
|
|
687
685
|
static randomInt(min, max) {
|
|
688
686
|
return Math.round(Math.random() * (max - min)) + min;
|
|
689
687
|
}
|
|
690
|
-
static glob(input, cwd) {
|
|
691
|
-
if (Array.isArray(input)) {
|
|
692
|
-
return input.flatMap(paths => this.glob(paths, cwd));
|
|
693
|
-
}
|
|
694
|
-
const hasGlobChars = /[*?[\]]/.test(input);
|
|
695
|
-
if (!hasGlobChars) {
|
|
696
|
-
try {
|
|
697
|
-
const s = statSync(cwd ? Utils.normalizePath(cwd, input) : input);
|
|
698
|
-
if (s.isDirectory()) {
|
|
699
|
-
const files = globSync(join(input, '**'), { cwd, withFileTypes: true });
|
|
700
|
-
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
catch {
|
|
704
|
-
// ignore
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
const files = globSync(input, { cwd, withFileTypes: true });
|
|
708
|
-
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
709
|
-
}
|
|
710
|
-
static pathExists(path) {
|
|
711
|
-
if (/[*?[\]]/.test(path)) {
|
|
712
|
-
const found = globSync(path);
|
|
713
|
-
return found.length > 0;
|
|
714
|
-
}
|
|
715
|
-
return existsSync(path);
|
|
716
|
-
}
|
|
717
688
|
/**
|
|
718
689
|
* Extracts all possible values of a TS enum. Works with both string and numeric enums.
|
|
719
690
|
*/
|
|
@@ -751,51 +722,18 @@ export class Utils {
|
|
|
751
722
|
}
|
|
752
723
|
return false;
|
|
753
724
|
}
|
|
754
|
-
/**
|
|
755
|
-
* Require a module from a specific location
|
|
756
|
-
* @param id The module to require
|
|
757
|
-
* @param [from] Location to start the node resolution
|
|
758
|
-
*/
|
|
759
|
-
static requireFrom(id, from = process.cwd()) {
|
|
760
|
-
if (!extname(from)) {
|
|
761
|
-
from = join(from, '__fake.js');
|
|
762
|
-
}
|
|
763
|
-
return createRequire(resolve(from))(id);
|
|
764
|
-
}
|
|
765
725
|
static async dynamicImport(id) {
|
|
766
726
|
/* v8 ignore next */
|
|
767
727
|
const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
|
|
768
728
|
return this.dynamicImportProvider(specifier);
|
|
769
729
|
}
|
|
770
|
-
static ensureDir(path) {
|
|
771
|
-
if (!existsSync(path)) {
|
|
772
|
-
mkdirSync(path, { recursive: true });
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
static readJSONSync(path) {
|
|
776
|
-
const file = readFileSync(path);
|
|
777
|
-
return JSON.parse(file.toString());
|
|
778
|
-
}
|
|
779
730
|
static getORMVersion() {
|
|
780
|
-
|
|
781
|
-
// this works during development where we have `src` folder
|
|
782
|
-
return this.requireFrom('../../package.json', import.meta.dirname).version;
|
|
783
|
-
/* v8 ignore next 5 */
|
|
784
|
-
}
|
|
785
|
-
catch {
|
|
786
|
-
try {
|
|
787
|
-
// this works in production build where we do not have the `src` folder
|
|
788
|
-
return this.requireFrom('../package.json', import.meta.dirname).version;
|
|
789
|
-
}
|
|
790
|
-
catch {
|
|
791
|
-
return 'N/A';
|
|
792
|
-
}
|
|
793
|
-
}
|
|
731
|
+
return '6.6.1';
|
|
794
732
|
}
|
|
795
733
|
static createFunction(context, code) {
|
|
796
734
|
try {
|
|
797
735
|
return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
|
|
798
|
-
/* v8 ignore next
|
|
736
|
+
/* v8 ignore next */
|
|
799
737
|
}
|
|
800
738
|
catch (e) {
|
|
801
739
|
// eslint-disable-next-line no-console
|
|
@@ -808,7 +746,7 @@ export class Utils {
|
|
|
808
746
|
return fn(...args);
|
|
809
747
|
}
|
|
810
748
|
catch (e) {
|
|
811
|
-
/* v8 ignore
|
|
749
|
+
/* v8 ignore next */
|
|
812
750
|
if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
|
|
813
751
|
const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
|
|
814
752
|
let code = fn.toString();
|
|
@@ -825,7 +763,6 @@ export class Utils {
|
|
|
825
763
|
// eslint-disable-next-line no-console
|
|
826
764
|
console.error(`JIT runtime error: ${e.message}\n\n${code}`);
|
|
827
765
|
}
|
|
828
|
-
/* v8 ignore stop */
|
|
829
766
|
throw e;
|
|
830
767
|
}
|
|
831
768
|
}
|
|
@@ -908,23 +845,6 @@ export class Utils {
|
|
|
908
845
|
}
|
|
909
846
|
}
|
|
910
847
|
}
|
|
911
|
-
static tryRequire({ module, from, allowError, warning }) {
|
|
912
|
-
allowError ??= `Cannot find module '${module}'`;
|
|
913
|
-
from ??= process.cwd();
|
|
914
|
-
try {
|
|
915
|
-
return Utils.requireFrom(module, from);
|
|
916
|
-
}
|
|
917
|
-
catch (err) {
|
|
918
|
-
if (err.message.includes(allowError)) {
|
|
919
|
-
if (warning) {
|
|
920
|
-
// eslint-disable-next-line no-console
|
|
921
|
-
console.warn(warning);
|
|
922
|
-
}
|
|
923
|
-
return undefined;
|
|
924
|
-
}
|
|
925
|
-
throw err;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
848
|
static async tryImport({ module, warning }) {
|
|
929
849
|
try {
|
|
930
850
|
return await import(module);
|
package/utils/clone.js
CHANGED
|
@@ -126,7 +126,7 @@ export function clone(parent, respectCustomCloneMethod = true) {
|
|
|
126
126
|
for (let i = 0; i < symbols.length; i++) {
|
|
127
127
|
const symbol = symbols[i];
|
|
128
128
|
const descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
|
|
129
|
-
/* v8 ignore next
|
|
129
|
+
/* v8 ignore next */
|
|
130
130
|
if (descriptor && !descriptor.enumerable) {
|
|
131
131
|
continue;
|
|
132
132
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Utils } from './Utils.js';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function loadEnvironmentVars() {
|
|
4
|
+
const ret = {};
|
|
5
|
+
const getEnvKey = (key, envPrefix = 'MIKRO_ORM_') => {
|
|
6
|
+
return envPrefix + key
|
|
7
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
8
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
9
|
+
.toUpperCase();
|
|
10
|
+
};
|
|
11
|
+
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
12
|
+
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
13
|
+
const num = (v) => +v;
|
|
14
|
+
const read = (o, envPrefix, key, mapper = v => v) => {
|
|
15
|
+
const envKey = getEnvKey(key, envPrefix);
|
|
16
|
+
if (envKey in process.env) {
|
|
17
|
+
o[key] = mapper(process.env[envKey]);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
21
|
+
const read0 = read.bind(null, ret, 'MIKRO_ORM_');
|
|
22
|
+
read0('baseDir');
|
|
23
|
+
read0('entities', array);
|
|
24
|
+
read0('entitiesTs', array);
|
|
25
|
+
read0('clientUrl');
|
|
26
|
+
read0('host');
|
|
27
|
+
read0('port', num);
|
|
28
|
+
read0('user');
|
|
29
|
+
read0('password');
|
|
30
|
+
read0('dbName');
|
|
31
|
+
read0('schema');
|
|
32
|
+
read0('loadStrategy');
|
|
33
|
+
read0('batchSize', num);
|
|
34
|
+
read0('useBatchInserts', bool);
|
|
35
|
+
read0('useBatchUpdates', bool);
|
|
36
|
+
read0('allowGlobalContext', bool);
|
|
37
|
+
read0('autoJoinOneToOneOwner', bool);
|
|
38
|
+
read0('populateAfterFlush', bool);
|
|
39
|
+
read0('forceEntityConstructor', bool);
|
|
40
|
+
read0('forceUndefined', bool);
|
|
41
|
+
read0('forceUtcTimezone', bool);
|
|
42
|
+
read0('timezone');
|
|
43
|
+
read0('ensureIndexes', bool);
|
|
44
|
+
read0('implicitTransactions', bool);
|
|
45
|
+
read0('debug', bool);
|
|
46
|
+
read0('colors', bool);
|
|
47
|
+
ret.discovery = {};
|
|
48
|
+
const read1 = read.bind(null, ret.discovery, 'MIKRO_ORM_DISCOVERY_');
|
|
49
|
+
read1('warnWhenNoEntities', bool);
|
|
50
|
+
read1('checkDuplicateTableNames', bool);
|
|
51
|
+
read1('checkDuplicateFieldNames', bool);
|
|
52
|
+
read1('checkDuplicateEntities', bool);
|
|
53
|
+
read1('checkNonPersistentCompositeProps', bool);
|
|
54
|
+
read1('inferDefaultValues', bool);
|
|
55
|
+
read1('tsConfigPath');
|
|
56
|
+
cleanup(ret, 'discovery');
|
|
57
|
+
ret.migrations = {};
|
|
58
|
+
const read2 = read.bind(null, ret.migrations, 'MIKRO_ORM_MIGRATIONS_');
|
|
59
|
+
read2('tableName');
|
|
60
|
+
read2('path');
|
|
61
|
+
read2('pathTs');
|
|
62
|
+
read2('glob');
|
|
63
|
+
read2('transactional', bool);
|
|
64
|
+
read2('disableForeignKeys', bool);
|
|
65
|
+
read2('allOrNothing', bool);
|
|
66
|
+
read2('dropTables', bool);
|
|
67
|
+
read2('safe', bool);
|
|
68
|
+
read2('silent', bool);
|
|
69
|
+
read2('emit');
|
|
70
|
+
read2('snapshot', bool);
|
|
71
|
+
read2('snapshotName');
|
|
72
|
+
cleanup(ret, 'migrations');
|
|
73
|
+
ret.schemaGenerator = {};
|
|
74
|
+
const read3 = read.bind(null, ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_');
|
|
75
|
+
read3('disableForeignKeys', bool);
|
|
76
|
+
read3('createForeignKeyConstraints', bool);
|
|
77
|
+
cleanup(ret, 'schemaGenerator');
|
|
78
|
+
ret.seeder = {};
|
|
79
|
+
const read4 = read.bind(null, ret.seeder, 'MIKRO_ORM_SEEDER_');
|
|
80
|
+
read4('path');
|
|
81
|
+
read4('pathTs');
|
|
82
|
+
read4('glob');
|
|
83
|
+
read4('emit');
|
|
84
|
+
read4('defaultSeeder');
|
|
85
|
+
cleanup(ret, 'seeder');
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Dictionary } from '../typings.js';
|
|
2
|
+
export declare const fs: {
|
|
3
|
+
pathExists(path: string): boolean;
|
|
4
|
+
ensureDir(path: string): void;
|
|
5
|
+
readJSONSync<T = Dictionary>(path: string): T;
|
|
6
|
+
glob(input: string | string[], cwd?: string): string[];
|
|
7
|
+
getPackageConfig<T extends Dictionary>(basePath?: string): Promise<T>;
|
|
8
|
+
getORMPackages(): Promise<Set<string>>;
|
|
9
|
+
getORMPackageVersion(name: string): string | undefined;
|
|
10
|
+
checkPackageVersion(): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export * from '../cache/FileCacheAdapter.js';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { existsSync, globSync, mkdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { Utils } from './Utils.js';
|
|
5
|
+
import { colors } from '../logging/colors.js';
|
|
6
|
+
export const fs = {
|
|
7
|
+
pathExists(path) {
|
|
8
|
+
if (/[*?[\]]/.test(path)) {
|
|
9
|
+
return globSync(path).length > 0;
|
|
10
|
+
}
|
|
11
|
+
return existsSync(path);
|
|
12
|
+
},
|
|
13
|
+
ensureDir(path) {
|
|
14
|
+
if (!existsSync(path)) {
|
|
15
|
+
mkdirSync(path, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
readJSONSync(path) {
|
|
19
|
+
const file = readFileSync(path);
|
|
20
|
+
return JSON.parse(file.toString());
|
|
21
|
+
},
|
|
22
|
+
glob(input, cwd) {
|
|
23
|
+
if (Array.isArray(input)) {
|
|
24
|
+
return input.flatMap(paths => this.glob(paths, cwd));
|
|
25
|
+
}
|
|
26
|
+
const hasGlobChars = /[*?[\]]/.test(input);
|
|
27
|
+
if (!hasGlobChars) {
|
|
28
|
+
try {
|
|
29
|
+
const s = statSync(cwd ? Utils.normalizePath(cwd, input) : input);
|
|
30
|
+
if (s.isDirectory()) {
|
|
31
|
+
const files = globSync(join(input, '**'), { cwd, withFileTypes: true });
|
|
32
|
+
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// ignore
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const files = globSync(input, { cwd, withFileTypes: true });
|
|
40
|
+
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
41
|
+
},
|
|
42
|
+
async getPackageConfig(basePath = process.cwd()) {
|
|
43
|
+
if (this.pathExists(`${basePath}/package.json`)) {
|
|
44
|
+
try {
|
|
45
|
+
return await Utils.dynamicImport(`${basePath}/package.json`);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
/* v8 ignore next */
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const parentFolder = realpathSync(`${basePath}/..`);
|
|
53
|
+
// we reached the root folder
|
|
54
|
+
if (basePath === parentFolder) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
return this.getPackageConfig(parentFolder);
|
|
58
|
+
},
|
|
59
|
+
async getORMPackages() {
|
|
60
|
+
const pkg = await this.getPackageConfig();
|
|
61
|
+
return new Set([
|
|
62
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
63
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
64
|
+
]);
|
|
65
|
+
},
|
|
66
|
+
getORMPackageVersion(name) {
|
|
67
|
+
try {
|
|
68
|
+
const path = import.meta.resolve(`${name}/package.json`);
|
|
69
|
+
const pkg = this.readJSONSync(fileURLToPath(path));
|
|
70
|
+
return pkg?.version;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
77
|
+
async checkPackageVersion() {
|
|
78
|
+
const coreVersion = Utils.getORMVersion();
|
|
79
|
+
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const deps = await this.getORMPackages();
|
|
83
|
+
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
84
|
+
const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
|
|
85
|
+
for (const ormPackage of ormPackages) {
|
|
86
|
+
const version = this.getORMPackageVersion(ormPackage);
|
|
87
|
+
if (version != null && version !== coreVersion) {
|
|
88
|
+
throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
|
|
89
|
+
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
|
|
90
|
+
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
91
|
+
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
export * from '../cache/FileCacheAdapter.js';
|
package/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './Configuration.js';
|
|
2
|
-
export * from './ConfigurationLoader.js';
|
|
3
2
|
export * from './Cursor.js';
|
|
4
3
|
export * from './DataloaderUtils.js';
|
|
5
4
|
export * from './Utils.js';
|
|
@@ -11,4 +10,5 @@ export * from './NullHighlighter.js';
|
|
|
11
10
|
export * from './EntityComparator.js';
|
|
12
11
|
export * from './AbstractSchemaGenerator.js';
|
|
13
12
|
export * from './RawQueryFragment.js';
|
|
13
|
+
export * from './env-vars.js';
|
|
14
14
|
export * from './upsert-utils.js';
|