@mikro-orm/core 7.0.0-dev.300 → 7.0.0-dev.301
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityManager.d.ts +1 -1
- package/EntityManager.js +94 -43
- package/MikroORM.js +4 -4
- package/cache/FileCacheAdapter.js +1 -3
- package/connections/Connection.js +16 -3
- package/drivers/DatabaseDriver.js +25 -7
- package/entity/Collection.js +43 -17
- package/entity/EntityAssigner.js +23 -11
- package/entity/EntityFactory.js +32 -12
- package/entity/EntityHelper.js +12 -8
- package/entity/EntityLoader.js +55 -22
- package/entity/Reference.d.ts +1 -1
- package/entity/Reference.js +37 -8
- package/entity/WrappedEntity.js +5 -1
- package/entity/defineEntity.d.ts +5 -7
- package/entity/utils.js +28 -26
- package/entity/validators.js +2 -1
- package/enums.js +12 -17
- package/errors.js +18 -8
- package/events/EventManager.js +1 -1
- package/exceptions.js +7 -2
- package/hydration/ObjectHydrator.js +27 -13
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/logging/DefaultLogger.js +3 -5
- package/logging/colors.js +3 -6
- package/metadata/EntitySchema.js +12 -2
- package/metadata/MetadataDiscovery.js +101 -46
- package/metadata/MetadataProvider.js +6 -1
- package/metadata/MetadataStorage.js +1 -3
- package/metadata/MetadataValidator.js +20 -5
- package/metadata/types.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +5 -2
- package/not-supported.js +5 -1
- package/package.json +38 -38
- package/platforms/Platform.js +46 -23
- package/serialization/EntitySerializer.js +7 -3
- package/serialization/SerializationContext.js +1 -1
- package/typings.d.ts +23 -23
- package/typings.js +9 -9
- package/unit-of-work/ChangeSet.js +4 -4
- package/unit-of-work/ChangeSetComputer.js +8 -6
- package/unit-of-work/ChangeSetPersister.js +13 -8
- package/unit-of-work/CommitOrderCalculator.js +4 -2
- package/unit-of-work/UnitOfWork.d.ts +7 -1
- package/unit-of-work/UnitOfWork.js +51 -22
- package/utils/AbstractMigrator.js +3 -5
- package/utils/AbstractSchemaGenerator.js +2 -1
- package/utils/AsyncContext.js +1 -1
- package/utils/Configuration.js +8 -4
- package/utils/Cursor.js +4 -2
- package/utils/DataloaderUtils.js +15 -12
- package/utils/EntityComparator.js +51 -43
- package/utils/QueryHelper.js +38 -26
- package/utils/RawQueryFragment.js +3 -2
- package/utils/TransactionManager.js +2 -1
- package/utils/Utils.d.ts +1 -1
- package/utils/Utils.js +36 -30
- package/utils/env-vars.js +6 -5
- package/utils/fs-utils.js +2 -5
- package/utils/upsert-utils.js +6 -3
package/utils/Utils.js
CHANGED
|
@@ -25,7 +25,7 @@ export function compareObjects(a, b) {
|
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
26
26
|
return a.sql === b.sql && compareArrays(a.params, b.params);
|
|
27
27
|
}
|
|
28
|
-
if (
|
|
28
|
+
if (a instanceof Date && b instanceof Date) {
|
|
29
29
|
const timeA = a.getTime();
|
|
30
30
|
const timeB = b.getTime();
|
|
31
31
|
if (isNaN(timeA) || isNaN(timeB)) {
|
|
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
|
|
|
123
123
|
}
|
|
124
124
|
export class Utils {
|
|
125
125
|
static PK_SEPARATOR = '~~~';
|
|
126
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.301';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|
|
@@ -305,7 +305,7 @@ export class Utils {
|
|
|
305
305
|
.split(',')
|
|
306
306
|
.map(s => s.trim().replace(/=.*$/, '').trim())
|
|
307
307
|
.filter(Boolean)
|
|
308
|
-
.map(raw => raw.startsWith('{') && raw.endsWith('}') ? '' : raw);
|
|
308
|
+
.map(raw => (raw.startsWith('{') && raw.endsWith('}') ? '' : raw));
|
|
309
309
|
}
|
|
310
310
|
/**
|
|
311
311
|
* Checks whether the argument looks like primary key (string, number or ObjectId).
|
|
@@ -374,7 +374,8 @@ export class Utils {
|
|
|
374
374
|
return Utils.getPrimaryKeyHash(pks);
|
|
375
375
|
}
|
|
376
376
|
static getPrimaryKeyHash(pks) {
|
|
377
|
-
return pks
|
|
377
|
+
return pks
|
|
378
|
+
.map(pk => {
|
|
378
379
|
if (Buffer.isBuffer(pk)) {
|
|
379
380
|
return pk.toString('hex');
|
|
380
381
|
}
|
|
@@ -382,7 +383,8 @@ export class Utils {
|
|
|
382
383
|
return pk.toISOString();
|
|
383
384
|
}
|
|
384
385
|
return pk;
|
|
385
|
-
})
|
|
386
|
+
})
|
|
387
|
+
.join(this.PK_SEPARATOR);
|
|
386
388
|
}
|
|
387
389
|
static splitPrimaryKeys(key) {
|
|
388
390
|
return key.split(this.PK_SEPARATOR);
|
|
@@ -419,7 +421,7 @@ export class Utils {
|
|
|
419
421
|
}
|
|
420
422
|
if (allowScalar) {
|
|
421
423
|
if (Utils.isPlainObject(pk)) {
|
|
422
|
-
return pk[
|
|
424
|
+
return pk[meta.primaryKeys[0]];
|
|
423
425
|
}
|
|
424
426
|
return pk;
|
|
425
427
|
}
|
|
@@ -527,7 +529,7 @@ export class Utils {
|
|
|
527
529
|
static extractChildElements(items, prefix, allSymbol) {
|
|
528
530
|
return items
|
|
529
531
|
.filter(field => field === allSymbol || field.startsWith(`${prefix}.`))
|
|
530
|
-
.map(field => field === allSymbol ? allSymbol : field.substring(prefix.length + 1));
|
|
532
|
+
.map(field => (field === allSymbol ? allSymbol : field.substring(prefix.length + 1)));
|
|
531
533
|
}
|
|
532
534
|
/**
|
|
533
535
|
* Tries to detect TypeScript support.
|
|
@@ -536,17 +538,17 @@ export class Utils {
|
|
|
536
538
|
/* v8 ignore next */
|
|
537
539
|
const process = globalThis.process ?? {};
|
|
538
540
|
/* v8 ignore next */
|
|
539
|
-
return process.argv?.[0]?.endsWith('ts-node') // running via ts-node directly
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
return arg.includes('ts-node') // check for ts-node loader
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
});
|
|
541
|
+
return (process.argv?.[0]?.endsWith('ts-node') || // running via ts-node directly
|
|
542
|
+
!!process.env?.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS || // forced explicitly or enabled via `registerTypeScriptSupport()`
|
|
543
|
+
!!process.env?.TS_JEST || // check if ts-jest is used
|
|
544
|
+
!!process.env?.VITEST || // check if vitest is used
|
|
545
|
+
!!process.versions?.bun || // check if bun is used
|
|
546
|
+
process.argv?.slice(1).some(arg => arg.match(/\.([mc]?ts|tsx)$/)) || // executing `.ts` file
|
|
547
|
+
process.execArgv?.some(arg => {
|
|
548
|
+
return (arg.includes('ts-node') || // check for ts-node loader
|
|
549
|
+
arg.includes('@swc-node/register') || // check for swc-node/register loader
|
|
550
|
+
arg.includes('node_modules/tsx/')); // check for tsx loader
|
|
551
|
+
}));
|
|
550
552
|
}
|
|
551
553
|
/**
|
|
552
554
|
* Gets the type of the argument.
|
|
@@ -567,12 +569,13 @@ export class Utils {
|
|
|
567
569
|
* Checks whether the value is POJO (e.g. `{ foo: 'bar' }`, and not instance of `Foo`)
|
|
568
570
|
*/
|
|
569
571
|
static isPlainObject(value) {
|
|
570
|
-
return (value !== null
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
572
|
+
return ((value !== null &&
|
|
573
|
+
typeof value === 'object' &&
|
|
574
|
+
typeof value.constructor === 'function' &&
|
|
575
|
+
(Object.hasOwn(value.constructor.prototype, 'isPrototypeOf') ||
|
|
576
|
+
Object.getPrototypeOf(value.constructor.prototype) === null)) ||
|
|
577
|
+
(value && Object.getPrototypeOf(value) === null) ||
|
|
578
|
+
value instanceof PlainObject);
|
|
576
579
|
}
|
|
577
580
|
/**
|
|
578
581
|
* Executes the `cb` promise serially on every element of the `items` array and returns array of resolved values.
|
|
@@ -633,17 +636,20 @@ export class Utils {
|
|
|
633
636
|
const keys = Object.keys(target);
|
|
634
637
|
const values = Object.values(target);
|
|
635
638
|
const numeric = !!values.find(v => typeof v === 'number');
|
|
636
|
-
const constEnum = values.length % 2 === 0 // const enum will have even number of items
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
639
|
+
const constEnum = values.length % 2 === 0 && // const enum will have even number of items
|
|
640
|
+
values.slice(0, values.length / 2).every(v => typeof v === 'string') && // first half are strings
|
|
641
|
+
values.slice(values.length / 2).every(v => typeof v === 'number') && // second half are numbers
|
|
642
|
+
this.equals(keys, values
|
|
643
|
+
.slice(values.length / 2)
|
|
644
|
+
.concat(values.slice(0, values.length / 2))
|
|
645
|
+
.map(v => '' + v)); // and when swapped, it will match the keys
|
|
640
646
|
if (numeric || constEnum) {
|
|
641
647
|
return values.filter(val => !keys.includes(val));
|
|
642
648
|
}
|
|
643
649
|
return values;
|
|
644
650
|
}
|
|
645
651
|
static flatten(arrays, deep) {
|
|
646
|
-
return arrays.flatMap(v => deep && Array.isArray(v) ? this.flatten(v, true) : v);
|
|
652
|
+
return arrays.flatMap(v => (deep && Array.isArray(v) ? this.flatten(v, true) : v));
|
|
647
653
|
}
|
|
648
654
|
static isOperator(key, includeGroupOperators = true) {
|
|
649
655
|
if (!includeGroupOperators) {
|
|
@@ -784,7 +790,7 @@ export class Utils {
|
|
|
784
790
|
}
|
|
785
791
|
}
|
|
786
792
|
}
|
|
787
|
-
static async tryImport({ module, warning }) {
|
|
793
|
+
static async tryImport({ module, warning, }) {
|
|
788
794
|
try {
|
|
789
795
|
return await import(module);
|
|
790
796
|
}
|
package/utils/env-vars.js
CHANGED
|
@@ -13,10 +13,11 @@ export function getEnv(key) {
|
|
|
13
13
|
export function loadEnvironmentVars() {
|
|
14
14
|
const ret = {};
|
|
15
15
|
const getEnvKey = (key, envPrefix = 'MIKRO_ORM_') => {
|
|
16
|
-
return envPrefix +
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
return (envPrefix +
|
|
17
|
+
key
|
|
18
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
19
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
20
|
+
.toUpperCase());
|
|
20
21
|
};
|
|
21
22
|
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
22
23
|
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
@@ -28,7 +29,7 @@ export function loadEnvironmentVars() {
|
|
|
28
29
|
o[key] = mapper(getEnv(envKey));
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
|
-
const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
32
|
+
const cleanup = (o, k) => (Utils.hasObjectKeys(o[k]) ? {} : delete o[k]);
|
|
32
33
|
const read0 = read.bind(null, ret, 'MIKRO_ORM_');
|
|
33
34
|
read0('baseDir');
|
|
34
35
|
read0('entities', array);
|
package/utils/fs-utils.js
CHANGED
|
@@ -95,10 +95,7 @@ export const fs = {
|
|
|
95
95
|
},
|
|
96
96
|
getORMPackages() {
|
|
97
97
|
const pkg = this.getPackageConfig();
|
|
98
|
-
return new Set([
|
|
99
|
-
...Object.keys(pkg.dependencies ?? {}),
|
|
100
|
-
...Object.keys(pkg.devDependencies ?? {}),
|
|
101
|
-
]);
|
|
98
|
+
return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
102
99
|
},
|
|
103
100
|
getORMPackageVersion(name) {
|
|
104
101
|
try {
|
|
@@ -153,7 +150,7 @@ export const fs = {
|
|
|
153
150
|
}
|
|
154
151
|
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
155
152
|
path = normalize(path).replace(/\\/g, '/');
|
|
156
|
-
return
|
|
153
|
+
return path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!') ? path : './' + path;
|
|
157
154
|
},
|
|
158
155
|
/**
|
|
159
156
|
* Determines the relative path between two paths. If either path is a `file:` URL,
|
package/utils/upsert-utils.js
CHANGED
|
@@ -73,7 +73,8 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
73
73
|
if (!meta) {
|
|
74
74
|
return '*';
|
|
75
75
|
}
|
|
76
|
-
const keys = meta.comparableProps
|
|
76
|
+
const keys = meta.comparableProps
|
|
77
|
+
.filter(p => {
|
|
77
78
|
if (p.lazy || p.embeddable) {
|
|
78
79
|
return false;
|
|
79
80
|
}
|
|
@@ -81,7 +82,8 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
81
82
|
return true;
|
|
82
83
|
}
|
|
83
84
|
return Array.isArray(uniqueFields) && !uniqueFields.includes(p.name);
|
|
84
|
-
})
|
|
85
|
+
})
|
|
86
|
+
.map(p => p.name);
|
|
85
87
|
if (meta.versionProperty) {
|
|
86
88
|
keys.push(meta.versionProperty);
|
|
87
89
|
}
|
|
@@ -113,7 +115,8 @@ function getPropertyValue(obj, key) {
|
|
|
113
115
|
/** @internal */
|
|
114
116
|
export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
115
117
|
const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
|
|
116
|
-
const propIndex = !isRaw(unique) &&
|
|
118
|
+
const propIndex = !isRaw(unique) &&
|
|
119
|
+
unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
|
|
117
120
|
if (onConflictFields || where == null) {
|
|
118
121
|
if (propIndex !== false && propIndex >= 0) {
|
|
119
122
|
let key = unique[propIndex];
|