@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
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 +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- package/events/EventSubscriber.d.ts +8 -5
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +12 -2
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +4 -4
- package/types/JsonType.js +9 -8
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- 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 +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
package/utils/Utils.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.Utils = exports.ObjectBindingPattern = void 0;
|
|
7
|
-
exports.compareObjects = compareObjects;
|
|
8
|
-
exports.compareArrays = compareArrays;
|
|
9
|
-
exports.compareBooleans = compareBooleans;
|
|
10
|
-
exports.compareBuffers = compareBuffers;
|
|
11
|
-
exports.equals = equals;
|
|
12
|
-
exports.parseJsonSafe = parseJsonSafe;
|
|
13
|
-
const node_module_1 = require("node:module");
|
|
14
|
-
const globby_1 = __importDefault(require("globby"));
|
|
15
|
-
const node_path_1 = require("node:path");
|
|
16
|
-
const node_os_1 = require("node:os");
|
|
17
|
-
const node_url_1 = require("node:url");
|
|
18
|
-
const fs_extra_1 = require("fs-extra");
|
|
19
|
-
const node_crypto_1 = require("node:crypto");
|
|
20
|
-
const esprima_1 = require("esprima");
|
|
21
|
-
const clone_1 = require("./clone");
|
|
22
|
-
const enums_1 = require("../enums");
|
|
23
|
-
const wrap_1 = require("../entity/wrap");
|
|
24
|
-
exports.ObjectBindingPattern = Symbol('ObjectBindingPattern');
|
|
1
|
+
import { isAbsolute, normalize, relative } from 'node:path';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
|
+
import { clone } from './clone.js';
|
|
4
|
+
import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
|
|
5
|
+
import { helper } from '../entity/wrap.js';
|
|
25
6
|
function compareConstructors(a, b) {
|
|
26
7
|
if (a.constructor === b.constructor) {
|
|
27
8
|
return true;
|
|
@@ -34,10 +15,7 @@ function compareConstructors(a, b) {
|
|
|
34
15
|
}
|
|
35
16
|
return false;
|
|
36
17
|
}
|
|
37
|
-
function
|
|
38
|
-
return typeof value === 'object' && !!value && '__raw' in value;
|
|
39
|
-
}
|
|
40
|
-
function compareObjects(a, b) {
|
|
18
|
+
export function compareObjects(a, b) {
|
|
41
19
|
if (a === b || (a == null && b == null)) {
|
|
42
20
|
return true;
|
|
43
21
|
}
|
|
@@ -56,6 +34,7 @@ function compareObjects(a, b) {
|
|
|
56
34
|
}
|
|
57
35
|
return timeA === timeB;
|
|
58
36
|
}
|
|
37
|
+
/* v8 ignore next */
|
|
59
38
|
if ((typeof a === 'function' && typeof b === 'function') ||
|
|
60
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
|
|
61
40
|
(a instanceof RegExp && b instanceof RegExp) ||
|
|
@@ -82,7 +61,7 @@ function compareObjects(a, b) {
|
|
|
82
61
|
}
|
|
83
62
|
return true;
|
|
84
63
|
}
|
|
85
|
-
function compareArrays(a, b) {
|
|
64
|
+
export function compareArrays(a, b) {
|
|
86
65
|
const length = a.length;
|
|
87
66
|
if (length !== b.length) {
|
|
88
67
|
return false;
|
|
@@ -95,12 +74,12 @@ function compareArrays(a, b) {
|
|
|
95
74
|
}
|
|
96
75
|
return true;
|
|
97
76
|
}
|
|
98
|
-
function compareBooleans(a, b) {
|
|
77
|
+
export function compareBooleans(a, b) {
|
|
99
78
|
a = typeof a === 'number' ? Boolean(a) : a;
|
|
100
79
|
b = typeof b === 'number' ? Boolean(b) : b;
|
|
101
80
|
return a === b;
|
|
102
81
|
}
|
|
103
|
-
function compareBuffers(a, b) {
|
|
82
|
+
export function compareBuffers(a, b) {
|
|
104
83
|
const length = a.length;
|
|
105
84
|
if (length !== b.length) {
|
|
106
85
|
return false;
|
|
@@ -115,7 +94,7 @@ function compareBuffers(a, b) {
|
|
|
115
94
|
/**
|
|
116
95
|
* Checks if arguments are deeply (but not strictly) equal.
|
|
117
96
|
*/
|
|
118
|
-
function equals(a, b) {
|
|
97
|
+
export function equals(a, b) {
|
|
119
98
|
if (a === b) {
|
|
120
99
|
return true;
|
|
121
100
|
}
|
|
@@ -131,8 +110,9 @@ function equals(a, b) {
|
|
|
131
110
|
return Number.isNaN(a) && Number.isNaN(b);
|
|
132
111
|
}
|
|
133
112
|
const equalsFn = equals;
|
|
134
|
-
function parseJsonSafe(value) {
|
|
113
|
+
export function parseJsonSafe(value) {
|
|
135
114
|
if (typeof value === 'string') {
|
|
115
|
+
/* v8 ignore next */
|
|
136
116
|
try {
|
|
137
117
|
return JSON.parse(value);
|
|
138
118
|
}
|
|
@@ -143,54 +123,17 @@ function parseJsonSafe(value) {
|
|
|
143
123
|
}
|
|
144
124
|
return value;
|
|
145
125
|
}
|
|
146
|
-
class Utils {
|
|
126
|
+
export class Utils {
|
|
147
127
|
static PK_SEPARATOR = '~~~';
|
|
148
|
-
|
|
128
|
+
static #ORM_VERSION = '7.0.0-dev.100';
|
|
129
|
+
/* v8 ignore next */
|
|
149
130
|
static dynamicImportProvider = (id) => import(id);
|
|
150
|
-
/**
|
|
151
|
-
* Checks if the argument is not undefined
|
|
152
|
-
*/
|
|
153
|
-
static isDefined(data) {
|
|
154
|
-
return typeof data !== 'undefined';
|
|
155
|
-
}
|
|
156
131
|
/**
|
|
157
132
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
158
133
|
*/
|
|
159
134
|
static isObject(o) {
|
|
160
135
|
return !!o && typeof o === 'object' && !Array.isArray(o);
|
|
161
136
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Relation decorators allow using two signatures
|
|
164
|
-
* - using first parameter as options object
|
|
165
|
-
* - using all parameters
|
|
166
|
-
*
|
|
167
|
-
* This function validates those two ways are not mixed and returns the final options object.
|
|
168
|
-
* If the second way is used, we always consider the last parameter as options object.
|
|
169
|
-
* @internal
|
|
170
|
-
*/
|
|
171
|
-
static processDecoratorParameters(params) {
|
|
172
|
-
const keys = Object.keys(params);
|
|
173
|
-
const values = Object.values(params);
|
|
174
|
-
if (!Utils.isPlainObject(values[0])) {
|
|
175
|
-
const lastKey = keys[keys.length - 1];
|
|
176
|
-
const last = params[lastKey];
|
|
177
|
-
delete params[lastKey];
|
|
178
|
-
return { ...last, ...params };
|
|
179
|
-
}
|
|
180
|
-
// validate only first parameter is used if its an option object
|
|
181
|
-
const empty = (v) => v == null || (Utils.isPlainObject(v) && !Utils.hasObjectKeys(v));
|
|
182
|
-
if (values.slice(1).some(v => !empty(v))) {
|
|
183
|
-
throw new Error('Mixing first decorator parameter as options object with other parameters is forbidden. ' +
|
|
184
|
-
'If you want to use the options parameter at first position, provide all options inside it.');
|
|
185
|
-
}
|
|
186
|
-
return values[0];
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Checks if the argument is instance of `Object`, but not one of the blacklisted types. Returns false for arrays.
|
|
190
|
-
*/
|
|
191
|
-
static isNotObject(o, not) {
|
|
192
|
-
return this.isObject(o) && !not.some(cls => o instanceof cls);
|
|
193
|
-
}
|
|
194
137
|
/**
|
|
195
138
|
* Removes `undefined` properties (recursively) so they are not saved as nulls
|
|
196
139
|
*/
|
|
@@ -220,7 +163,6 @@ class Utils {
|
|
|
220
163
|
static getObjectKeysSize(object) {
|
|
221
164
|
let size = 0;
|
|
222
165
|
for (const key in object) {
|
|
223
|
-
/* istanbul ignore else */
|
|
224
166
|
if (Object.hasOwn(object, key)) {
|
|
225
167
|
size++;
|
|
226
168
|
}
|
|
@@ -233,25 +175,12 @@ class Utils {
|
|
|
233
175
|
*/
|
|
234
176
|
static hasObjectKeys(object) {
|
|
235
177
|
for (const key in object) {
|
|
236
|
-
/* istanbul ignore else */
|
|
237
178
|
if (Object.hasOwn(object, key)) {
|
|
238
179
|
return true;
|
|
239
180
|
}
|
|
240
181
|
}
|
|
241
182
|
return false;
|
|
242
183
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Checks if the argument is string
|
|
245
|
-
*/
|
|
246
|
-
static isString(s) {
|
|
247
|
-
return typeof s === 'string';
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Checks if the argument is number
|
|
251
|
-
*/
|
|
252
|
-
static isNumber(s) {
|
|
253
|
-
return typeof s === 'number';
|
|
254
|
-
}
|
|
255
184
|
/**
|
|
256
185
|
* Checks if arguments are deeply (but not strictly) equal.
|
|
257
186
|
*/
|
|
@@ -297,7 +226,7 @@ class Utils {
|
|
|
297
226
|
target[key] = Utils.copy(value);
|
|
298
227
|
continue;
|
|
299
228
|
}
|
|
300
|
-
/*
|
|
229
|
+
/* v8 ignore next */
|
|
301
230
|
if (!(key in target)) {
|
|
302
231
|
Object.assign(target, { [key]: {} });
|
|
303
232
|
}
|
|
@@ -310,35 +239,11 @@ class Utils {
|
|
|
310
239
|
}
|
|
311
240
|
return Utils._merge(target, sources, ignoreUndefined);
|
|
312
241
|
}
|
|
313
|
-
static getRootEntity(metadata, meta) {
|
|
314
|
-
const base = meta.extends && metadata.find(Utils.className(meta.extends));
|
|
315
|
-
if (!base || base === meta) { // make sure we do not fall into infinite loop
|
|
316
|
-
return meta;
|
|
317
|
-
}
|
|
318
|
-
const root = Utils.getRootEntity(metadata, base);
|
|
319
|
-
if (root.discriminatorColumn) {
|
|
320
|
-
return root;
|
|
321
|
-
}
|
|
322
|
-
return meta;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Computes difference between two objects, ignoring items missing in `b`.
|
|
326
|
-
*/
|
|
327
|
-
static diff(a, b) {
|
|
328
|
-
const ret = {};
|
|
329
|
-
for (const k of Object.keys(b)) {
|
|
330
|
-
if (Utils.equals(a[k], b[k])) {
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
ret[k] = b[k];
|
|
334
|
-
}
|
|
335
|
-
return ret;
|
|
336
|
-
}
|
|
337
242
|
/**
|
|
338
243
|
* Creates deep copy of given object.
|
|
339
244
|
*/
|
|
340
245
|
static copy(entity, respectCustomCloneMethod = true) {
|
|
341
|
-
return
|
|
246
|
+
return clone(entity, respectCustomCloneMethod);
|
|
342
247
|
}
|
|
343
248
|
/**
|
|
344
249
|
* Normalize the argument to always be an array.
|
|
@@ -374,53 +279,37 @@ class Utils {
|
|
|
374
279
|
}
|
|
375
280
|
}
|
|
376
281
|
/**
|
|
377
|
-
* Returns array of functions argument names. Uses
|
|
282
|
+
* Returns array of functions argument names. Uses basic regex for source code analysis, might not work with advanced syntax.
|
|
378
283
|
*/
|
|
379
|
-
static
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return (0, esprima_1.tokenize)(func.toString(), { tolerant: true });
|
|
284
|
+
static getConstructorParams(func) {
|
|
285
|
+
const source = func.toString();
|
|
286
|
+
const i = source.indexOf('constructor');
|
|
287
|
+
if (i === -1) {
|
|
288
|
+
return undefined;
|
|
385
289
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return
|
|
290
|
+
const start = source.indexOf('(', i);
|
|
291
|
+
if (start === -1) {
|
|
292
|
+
return undefined;
|
|
389
293
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const ret = [];
|
|
396
|
-
const tokens = this.tokenize(func);
|
|
397
|
-
let inside = 0;
|
|
398
|
-
let currentBlockStart = 0;
|
|
399
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
400
|
-
const token = tokens[i];
|
|
401
|
-
if (token.type === 'Identifier' && token.value === methodName) {
|
|
402
|
-
inside = 1;
|
|
403
|
-
currentBlockStart = i;
|
|
404
|
-
continue;
|
|
294
|
+
let depth = 0;
|
|
295
|
+
let end = start;
|
|
296
|
+
for (; end < source.length; end++) {
|
|
297
|
+
if (source[end] === '(') {
|
|
298
|
+
depth++;
|
|
405
299
|
}
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
currentBlockStart = i;
|
|
409
|
-
continue;
|
|
300
|
+
if (source[end] === ')') {
|
|
301
|
+
depth--;
|
|
410
302
|
}
|
|
411
|
-
if (
|
|
303
|
+
if (depth === 0) {
|
|
412
304
|
break;
|
|
413
305
|
}
|
|
414
|
-
if (inside === 2 && token.type === 'Punctuator' && token.value === '{' && i === currentBlockStart + 1) {
|
|
415
|
-
ret.push(exports.ObjectBindingPattern);
|
|
416
|
-
i = tokens.findIndex((t, idx) => idx > i + 2 && t.type === 'Punctuator' && t.value === '}');
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
if (inside === 2 && token.type === 'Identifier') {
|
|
420
|
-
ret.push(token.value);
|
|
421
|
-
}
|
|
422
306
|
}
|
|
423
|
-
|
|
307
|
+
const raw = source.slice(start + 1, end);
|
|
308
|
+
return raw
|
|
309
|
+
.split(',')
|
|
310
|
+
.map(s => s.trim().replace(/=.*$/, '').trim())
|
|
311
|
+
.filter(Boolean)
|
|
312
|
+
.map(raw => raw.startsWith('{') && raw.endsWith('}') ? '' : raw);
|
|
424
313
|
}
|
|
425
314
|
/**
|
|
426
315
|
* Checks whether the argument looks like primary key (string, number or ObjectId).
|
|
@@ -433,7 +322,7 @@ class Utils {
|
|
|
433
322
|
return true;
|
|
434
323
|
}
|
|
435
324
|
if (Utils.isObject(key)) {
|
|
436
|
-
if (key.constructor
|
|
325
|
+
if (key.constructor?.name === 'ObjectId') {
|
|
437
326
|
return true;
|
|
438
327
|
}
|
|
439
328
|
if (!Utils.isPlainObject(key) && !Utils.isEntity(key, true)) {
|
|
@@ -450,7 +339,11 @@ class Utils {
|
|
|
450
339
|
return data;
|
|
451
340
|
}
|
|
452
341
|
if (Utils.isEntity(data, true)) {
|
|
453
|
-
|
|
342
|
+
const wrapped = helper(data);
|
|
343
|
+
if (wrapped.__meta.compositePK) {
|
|
344
|
+
return wrapped.getPrimaryKeys();
|
|
345
|
+
}
|
|
346
|
+
return wrapped.getPrimaryKey();
|
|
454
347
|
}
|
|
455
348
|
if (strict && meta && Utils.getObjectKeysSize(data) !== meta.primaryKeys.length) {
|
|
456
349
|
return null;
|
|
@@ -459,7 +352,7 @@ class Utils {
|
|
|
459
352
|
if (meta.compositePK) {
|
|
460
353
|
return this.getCompositeKeyValue(data, meta);
|
|
461
354
|
}
|
|
462
|
-
return data[meta.primaryKeys[0]]
|
|
355
|
+
return data[meta.primaryKeys[0]] ?? data[meta.serializedPrimaryKey] ?? null;
|
|
463
356
|
}
|
|
464
357
|
return null;
|
|
465
358
|
}
|
|
@@ -498,8 +391,8 @@ class Utils {
|
|
|
498
391
|
static splitPrimaryKeys(key) {
|
|
499
392
|
return key.split(this.PK_SEPARATOR);
|
|
500
393
|
}
|
|
501
|
-
static getPrimaryKeyValues(entity,
|
|
502
|
-
/*
|
|
394
|
+
static getPrimaryKeyValues(entity, meta, allowScalar = false, convertCustomTypes = false) {
|
|
395
|
+
/* v8 ignore next */
|
|
503
396
|
if (entity == null) {
|
|
504
397
|
return entity;
|
|
505
398
|
}
|
|
@@ -509,15 +402,28 @@ class Utils {
|
|
|
509
402
|
}
|
|
510
403
|
return val;
|
|
511
404
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
405
|
+
let pk;
|
|
406
|
+
if (Utils.isEntity(entity, true)) {
|
|
407
|
+
pk = helper(entity).getPrimaryKey(convertCustomTypes);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
pk = meta.primaryKeys.reduce((o, pk) => {
|
|
411
|
+
const targetMeta = meta.properties[pk].targetMeta;
|
|
412
|
+
if (targetMeta && Utils.isPlainObject(entity[pk])) {
|
|
413
|
+
o[pk] = Utils.getPrimaryKeyValues(entity[pk], targetMeta, allowScalar, convertCustomTypes);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
o[pk] = entity[pk];
|
|
417
|
+
}
|
|
418
|
+
return o;
|
|
419
|
+
}, {});
|
|
420
|
+
}
|
|
421
|
+
if (meta.primaryKeys.length > 1) {
|
|
516
422
|
return toArray(pk);
|
|
517
423
|
}
|
|
518
424
|
if (allowScalar) {
|
|
519
425
|
if (Utils.isPlainObject(pk)) {
|
|
520
|
-
return pk[primaryKeys[0]];
|
|
426
|
+
return pk[(meta.primaryKeys)[0]];
|
|
521
427
|
}
|
|
522
428
|
return pk;
|
|
523
429
|
}
|
|
@@ -561,7 +467,7 @@ class Utils {
|
|
|
561
467
|
return o;
|
|
562
468
|
}, {});
|
|
563
469
|
}
|
|
564
|
-
static getOrderedPrimaryKeys(id, meta, platform, convertCustomTypes = false) {
|
|
470
|
+
static getOrderedPrimaryKeys(id, meta, platform, convertCustomTypes = false, allowScalar = false) {
|
|
565
471
|
const data = (Utils.isPrimaryKey(id) ? { [meta.primaryKeys[0]]: id } : id);
|
|
566
472
|
const pks = meta.primaryKeys.map((pk, idx) => {
|
|
567
473
|
const prop = meta.properties[pk];
|
|
@@ -570,12 +476,15 @@ class Utils {
|
|
|
570
476
|
if (convertCustomTypes && platform && prop.customType && !prop.targetMeta) {
|
|
571
477
|
value = prop.customType.convertToJSValue(value, platform);
|
|
572
478
|
}
|
|
573
|
-
if (prop.kind !==
|
|
574
|
-
const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes);
|
|
479
|
+
if (prop.kind !== ReferenceKind.SCALAR && prop.targetMeta) {
|
|
480
|
+
const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes, allowScalar);
|
|
575
481
|
value = value2.length > 1 ? value2 : value2[0];
|
|
576
482
|
}
|
|
577
483
|
return value;
|
|
578
484
|
});
|
|
485
|
+
if (allowScalar && pks.length === 1) {
|
|
486
|
+
return pks[0];
|
|
487
|
+
}
|
|
579
488
|
// we need to flatten the PKs as composite PKs can be build from another composite PKs
|
|
580
489
|
// and this method is used to get the PK hash in identity map, that expects flat array
|
|
581
490
|
return Utils.flatten(pks);
|
|
@@ -598,12 +507,6 @@ class Utils {
|
|
|
598
507
|
static isScalarReference(data, allowReference = false) {
|
|
599
508
|
return typeof data === 'object' && data?.__scalarReference;
|
|
600
509
|
}
|
|
601
|
-
/**
|
|
602
|
-
* Checks whether the argument is ObjectId instance
|
|
603
|
-
*/
|
|
604
|
-
static isObjectID(key) {
|
|
605
|
-
return Utils.isObject(key) && key.constructor && key.constructor.name.toLowerCase() === 'objectid';
|
|
606
|
-
}
|
|
607
510
|
/**
|
|
608
511
|
* Checks whether the argument is empty (array without items, object without keys or falsy value).
|
|
609
512
|
*/
|
|
@@ -631,55 +534,21 @@ class Utils {
|
|
|
631
534
|
.map(field => field === allSymbol ? allSymbol : field.substring(prefix.length + 1));
|
|
632
535
|
}
|
|
633
536
|
/**
|
|
634
|
-
* Tries to detect
|
|
537
|
+
* Tries to detect TypeScript support.
|
|
635
538
|
*/
|
|
636
|
-
static
|
|
637
|
-
/*
|
|
539
|
+
static detectTypeScriptSupport() {
|
|
540
|
+
/* v8 ignore next */
|
|
638
541
|
return process.argv[0].endsWith('ts-node') // running via ts-node directly
|
|
639
|
-
//
|
|
640
|
-
|| !!process[Symbol.for('ts-node.register.instance')] // check if internal ts-node symbol exists
|
|
542
|
+
|| !!process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
|
|
641
543
|
|| !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)
|
|
642
544
|
|| !!process.env.VITEST // check if vitest is used
|
|
643
545
|
|| !!process.versions.bun // check if bun is used
|
|
644
|
-
|| process.argv.slice(1).some(arg => arg.
|
|
645
|
-
|| process.execArgv.some(arg =>
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
* Analyses stack trace of error created inside the function call.
|
|
651
|
-
*/
|
|
652
|
-
static lookupPathFromDecorator(name, stack) {
|
|
653
|
-
// use some dark magic to get source path to caller
|
|
654
|
-
stack = stack || new Error().stack.split('\n');
|
|
655
|
-
// In some situations (e.g. swc 1.3.4+), the presence of a source map can obscure the call to
|
|
656
|
-
// __decorate(), replacing it with the constructor name. To support these cases we look for
|
|
657
|
-
// Reflect.decorate() as well. Also when babel is used, we need to check
|
|
658
|
-
// the `_applyDecoratedDescriptor` method instead.
|
|
659
|
-
let line = stack.findIndex(line => line.match(/__decorate|Reflect\.decorate|_applyDecoratedDescriptor/));
|
|
660
|
-
// bun does not have those lines at all, only the DecorateProperty/DecorateConstructor,
|
|
661
|
-
// but those are also present in node, so we need to check this only if they weren't found.
|
|
662
|
-
if (line === -1) {
|
|
663
|
-
// here we handle bun which stack is different from nodejs so we search for reflect-metadata
|
|
664
|
-
const reflectLine = stack.findIndex(line => Utils.normalizePath(line).includes('node_modules/reflect-metadata/Reflect.js'));
|
|
665
|
-
if (reflectLine === -1 || reflectLine + 2 >= stack.length || !stack[reflectLine + 1].includes('bun:wrap')) {
|
|
666
|
-
return name;
|
|
667
|
-
}
|
|
668
|
-
line = reflectLine + 2;
|
|
669
|
-
}
|
|
670
|
-
if (stack[line].includes('Reflect.decorate')) {
|
|
671
|
-
line++;
|
|
672
|
-
}
|
|
673
|
-
if (Utils.normalizePath(stack[line]).includes('node_modules/tslib/tslib')) {
|
|
674
|
-
line++;
|
|
675
|
-
}
|
|
676
|
-
try {
|
|
677
|
-
const re = stack[line].match(/\(.+\)/i) ? /\((.*):\d+:\d+\)/ : /at\s*(.*):\d+:\d+$/;
|
|
678
|
-
return Utils.normalizePath(stack[line].match(re)[1]);
|
|
679
|
-
}
|
|
680
|
-
catch {
|
|
681
|
-
return name;
|
|
682
|
-
}
|
|
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
|
+
});
|
|
683
552
|
}
|
|
684
553
|
/**
|
|
685
554
|
* Gets the type of the argument.
|
|
@@ -690,11 +559,11 @@ class Utils {
|
|
|
690
559
|
return simple;
|
|
691
560
|
}
|
|
692
561
|
const objectType = Object.prototype.toString.call(value);
|
|
693
|
-
const type = objectType.match(
|
|
562
|
+
const type = objectType.match(/^\[object (.+)]$/)[1];
|
|
694
563
|
if (type === 'Uint8Array') {
|
|
695
564
|
return 'Buffer';
|
|
696
565
|
}
|
|
697
|
-
return
|
|
566
|
+
return type;
|
|
698
567
|
}
|
|
699
568
|
/**
|
|
700
569
|
* Checks whether the value is POJO (e.g. `{ foo: 'bar' }`, and not instance of `Foo`)
|
|
@@ -705,7 +574,7 @@ class Utils {
|
|
|
705
574
|
&& typeof value.constructor === 'function'
|
|
706
575
|
&& (Object.hasOwn(value.constructor.prototype, 'isPrototypeOf') || Object.getPrototypeOf(value.constructor.prototype) === null))
|
|
707
576
|
|| (value && Object.getPrototypeOf(value) === null)
|
|
708
|
-
|| value instanceof
|
|
577
|
+
|| value instanceof PlainObject;
|
|
709
578
|
}
|
|
710
579
|
/**
|
|
711
580
|
* Executes the `cb` promise serially on every element of the `items` array and returns array of resolved values.
|
|
@@ -722,7 +591,7 @@ class Utils {
|
|
|
722
591
|
}
|
|
723
592
|
static fileURLToPath(url) {
|
|
724
593
|
// expose `fileURLToPath` on Utils so that it can be properly mocked in tests
|
|
725
|
-
return
|
|
594
|
+
return fileURLToPath(url);
|
|
726
595
|
}
|
|
727
596
|
/**
|
|
728
597
|
* Resolves and normalizes a series of path parts relative to each preceding part.
|
|
@@ -735,7 +604,7 @@ class Utils {
|
|
|
735
604
|
let start = 0;
|
|
736
605
|
for (let i = 0; i < parts.length; i++) {
|
|
737
606
|
const part = parts[i];
|
|
738
|
-
if (
|
|
607
|
+
if (isAbsolute(part)) {
|
|
739
608
|
start = i;
|
|
740
609
|
}
|
|
741
610
|
else if (part.startsWith('file:')) {
|
|
@@ -747,7 +616,7 @@ class Utils {
|
|
|
747
616
|
parts = parts.slice(start);
|
|
748
617
|
}
|
|
749
618
|
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
750
|
-
path =
|
|
619
|
+
path = normalize(path).replace(/\\/g, '/');
|
|
751
620
|
return (path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!')) ? path : './' + path;
|
|
752
621
|
}
|
|
753
622
|
/**
|
|
@@ -762,7 +631,7 @@ class Utils {
|
|
|
762
631
|
if (path.startsWith('.')) {
|
|
763
632
|
return path;
|
|
764
633
|
}
|
|
765
|
-
path =
|
|
634
|
+
path = relative(Utils.normalizePath(relativeTo), path);
|
|
766
635
|
return Utils.normalizePath(path);
|
|
767
636
|
}
|
|
768
637
|
/**
|
|
@@ -773,13 +642,19 @@ class Utils {
|
|
|
773
642
|
if (!path) {
|
|
774
643
|
return Utils.normalizePath(baseDir);
|
|
775
644
|
}
|
|
776
|
-
if (!
|
|
645
|
+
if (!isAbsolute(path) && !path.startsWith('file://')) {
|
|
777
646
|
path = baseDir + '/' + path;
|
|
778
647
|
}
|
|
779
648
|
return Utils.normalizePath(path);
|
|
780
649
|
}
|
|
650
|
+
// FNV-1a 64-bit
|
|
781
651
|
static hash(data, length) {
|
|
782
|
-
|
|
652
|
+
let h1 = 0xcbf29ce484222325n;
|
|
653
|
+
for (let i = 0; i < data.length; i++) {
|
|
654
|
+
h1 ^= BigInt(data.charCodeAt(i));
|
|
655
|
+
h1 = (h1 * 0x100000001b3n) & 0xffffffffffffffffn;
|
|
656
|
+
}
|
|
657
|
+
const hash = h1.toString(16).padStart(16, '0');
|
|
783
658
|
if (length) {
|
|
784
659
|
return hash.substring(0, length);
|
|
785
660
|
}
|
|
@@ -811,13 +686,6 @@ class Utils {
|
|
|
811
686
|
static randomInt(min, max) {
|
|
812
687
|
return Math.round(Math.random() * (max - min)) + min;
|
|
813
688
|
}
|
|
814
|
-
static async pathExists(path, options = {}) {
|
|
815
|
-
if (globby_1.default.hasMagic(path)) {
|
|
816
|
-
const found = await (0, globby_1.default)(path, options);
|
|
817
|
-
return found.length > 0;
|
|
818
|
-
}
|
|
819
|
-
return (0, fs_extra_1.pathExistsSync)(path);
|
|
820
|
-
}
|
|
821
689
|
/**
|
|
822
690
|
* Extracts all possible values of a TS enum. Works with both string and numeric enums.
|
|
823
691
|
*/
|
|
@@ -839,18 +707,9 @@ class Utils {
|
|
|
839
707
|
}
|
|
840
708
|
static isOperator(key, includeGroupOperators = true) {
|
|
841
709
|
if (!includeGroupOperators) {
|
|
842
|
-
return key in
|
|
710
|
+
return key in QueryOperator;
|
|
843
711
|
}
|
|
844
|
-
return key in
|
|
845
|
-
}
|
|
846
|
-
static isGroupOperator(key) {
|
|
847
|
-
return key in enums_1.GroupOperator;
|
|
848
|
-
}
|
|
849
|
-
static isArrayOperator(key) {
|
|
850
|
-
return enums_1.ARRAY_OPERATORS.includes(key);
|
|
851
|
-
}
|
|
852
|
-
static isJsonKeyOperator(key) {
|
|
853
|
-
return enums_1.JSON_KEY_OPERATORS.includes(key);
|
|
712
|
+
return key in GroupOperator || key in QueryOperator;
|
|
854
713
|
}
|
|
855
714
|
static hasNestedKey(object, key) {
|
|
856
715
|
if (!object) {
|
|
@@ -864,60 +723,18 @@ class Utils {
|
|
|
864
723
|
}
|
|
865
724
|
return false;
|
|
866
725
|
}
|
|
867
|
-
static getGlobalStorage(namespace) {
|
|
868
|
-
const key = `mikro-orm-${namespace}`;
|
|
869
|
-
globalThis[key] = globalThis[key] || {};
|
|
870
|
-
return globalThis[key];
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
* Require a module from a specific location
|
|
874
|
-
* @param id The module to require
|
|
875
|
-
* @param [from] Location to start the node resolution
|
|
876
|
-
*/
|
|
877
|
-
static requireFrom(id, from = process.cwd()) {
|
|
878
|
-
if (!(0, node_path_1.extname)(from)) {
|
|
879
|
-
from = (0, node_path_1.join)(from, '__fake.js');
|
|
880
|
-
}
|
|
881
|
-
return (0, node_module_1.createRequire)((0, node_path_1.resolve)(from))(id);
|
|
882
|
-
}
|
|
883
726
|
static async dynamicImport(id) {
|
|
884
|
-
/*
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
id = (0, node_url_1.pathToFileURL)(id).toString();
|
|
888
|
-
}
|
|
889
|
-
catch {
|
|
890
|
-
// ignore
|
|
891
|
-
}
|
|
892
|
-
// If the extension is not registered, we need to fall back to a file path.
|
|
893
|
-
if (require.extensions && !require.extensions[(0, node_path_1.extname)(id)]) {
|
|
894
|
-
id = (0, node_url_1.fileURLToPath)(id);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
/* istanbul ignore next */
|
|
898
|
-
return this.dynamicImportProvider(id);
|
|
899
|
-
}
|
|
900
|
-
/* istanbul ignore next */
|
|
901
|
-
static setDynamicImportProvider(provider) {
|
|
902
|
-
this.dynamicImportProvider = provider;
|
|
727
|
+
/* v8 ignore next */
|
|
728
|
+
const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
|
|
729
|
+
return this.dynamicImportProvider(specifier);
|
|
903
730
|
}
|
|
904
731
|
static getORMVersion() {
|
|
905
|
-
|
|
906
|
-
try {
|
|
907
|
-
// this works with ts-node during development (where we have `src` folder)
|
|
908
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
909
|
-
return require('../../package.json').version;
|
|
910
|
-
}
|
|
911
|
-
catch {
|
|
912
|
-
// this works with node in production build (where we do not have the `src` folder)
|
|
913
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
914
|
-
return require('../package.json').version;
|
|
915
|
-
}
|
|
732
|
+
return this.#ORM_VERSION;
|
|
916
733
|
}
|
|
917
|
-
/* istanbul ignore next */
|
|
918
734
|
static createFunction(context, code) {
|
|
919
735
|
try {
|
|
920
736
|
return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
|
|
737
|
+
/* v8 ignore next */
|
|
921
738
|
}
|
|
922
739
|
catch (e) {
|
|
923
740
|
// eslint-disable-next-line no-console
|
|
@@ -925,12 +742,12 @@ class Utils {
|
|
|
925
742
|
throw e;
|
|
926
743
|
}
|
|
927
744
|
}
|
|
928
|
-
/* istanbul ignore next */
|
|
929
745
|
static callCompiledFunction(fn, ...args) {
|
|
930
746
|
try {
|
|
931
747
|
return fn(...args);
|
|
932
748
|
}
|
|
933
749
|
catch (e) {
|
|
750
|
+
/* v8 ignore next */
|
|
934
751
|
if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
|
|
935
752
|
const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
|
|
936
753
|
let code = fn.toString();
|
|
@@ -950,14 +767,6 @@ class Utils {
|
|
|
950
767
|
throw e;
|
|
951
768
|
}
|
|
952
769
|
}
|
|
953
|
-
/**
|
|
954
|
-
* @see https://github.com/mikro-orm/mikro-orm/issues/840
|
|
955
|
-
*/
|
|
956
|
-
static propertyDecoratorReturnValue() {
|
|
957
|
-
if (process.env.BABEL_DECORATORS_COMPAT) {
|
|
958
|
-
return {};
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
770
|
static unwrapProperty(entity, meta, prop, payload = false) {
|
|
962
771
|
let p = prop;
|
|
963
772
|
const path = [];
|
|
@@ -1037,44 +846,21 @@ class Utils {
|
|
|
1037
846
|
}
|
|
1038
847
|
}
|
|
1039
848
|
}
|
|
1040
|
-
static
|
|
1041
|
-
allowError ??= `Cannot find module '${module}'`;
|
|
1042
|
-
from ??= process.cwd();
|
|
849
|
+
static async tryImport({ module, warning }) {
|
|
1043
850
|
try {
|
|
1044
|
-
return
|
|
851
|
+
return await import(module);
|
|
1045
852
|
}
|
|
1046
853
|
catch (err) {
|
|
1047
|
-
if (err.
|
|
1048
|
-
|
|
1049
|
-
|
|
854
|
+
if (err.code === 'ERR_MODULE_NOT_FOUND') {
|
|
855
|
+
if (warning) {
|
|
856
|
+
// eslint-disable-next-line no-console
|
|
857
|
+
console.warn(warning);
|
|
858
|
+
}
|
|
1050
859
|
return undefined;
|
|
1051
860
|
}
|
|
1052
861
|
throw err;
|
|
1053
862
|
}
|
|
1054
863
|
}
|
|
1055
|
-
static stripRelativePath(str) {
|
|
1056
|
-
return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* simple process.argv parser, supports only properties with long names, prefixed with `--`
|
|
1060
|
-
*/
|
|
1061
|
-
static parseArgs() {
|
|
1062
|
-
let lastKey;
|
|
1063
|
-
return process.argv.slice(2).reduce((args, arg) => {
|
|
1064
|
-
if (arg.includes('=')) {
|
|
1065
|
-
const [key, value] = arg.split('=');
|
|
1066
|
-
args[key.substring(2)] = value;
|
|
1067
|
-
}
|
|
1068
|
-
else if (lastKey) {
|
|
1069
|
-
args[lastKey] = arg;
|
|
1070
|
-
lastKey = undefined;
|
|
1071
|
-
}
|
|
1072
|
-
else if (arg.startsWith('--')) {
|
|
1073
|
-
lastKey = arg.substring(2);
|
|
1074
|
-
}
|
|
1075
|
-
return args;
|
|
1076
|
-
}, {});
|
|
1077
|
-
}
|
|
1078
864
|
static xor(a, b) {
|
|
1079
865
|
return (a || b) && !(a && b);
|
|
1080
866
|
}
|
|
@@ -1087,9 +873,6 @@ class Utils {
|
|
|
1087
873
|
static entries(obj) {
|
|
1088
874
|
return Object.entries(obj);
|
|
1089
875
|
}
|
|
1090
|
-
static isRawSql(value) {
|
|
1091
|
-
return isRawSql(value);
|
|
1092
|
-
}
|
|
1093
876
|
static primaryKeyToObject(meta, primaryKey, visible) {
|
|
1094
877
|
const pks = meta.compositePK && Utils.isPlainObject(primaryKey) ? Object.values(primaryKey) : Utils.asArray(primaryKey);
|
|
1095
878
|
const pkProps = meta.getPrimaryProps();
|
|
@@ -1107,4 +890,3 @@ class Utils {
|
|
|
1107
890
|
}, {});
|
|
1108
891
|
}
|
|
1109
892
|
}
|
|
1110
|
-
exports.Utils = Utils;
|