@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
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 +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/utils/Utils.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import { glob, isDynamicPattern } from 'tinyglobby';
|
|
3
|
-
import { extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
|
-
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
6
|
-
import { createHash } from 'node:crypto';
|
|
7
|
-
import { tokenize } from 'esprima';
|
|
8
1
|
import { clone } from './clone.js';
|
|
9
|
-
import {
|
|
2
|
+
import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
|
|
10
3
|
import { helper } from '../entity/wrap.js';
|
|
11
|
-
|
|
4
|
+
import { Raw } from './RawQueryFragment.js';
|
|
12
5
|
function compareConstructors(a, b) {
|
|
13
6
|
if (a.constructor === b.constructor) {
|
|
14
7
|
return true;
|
|
@@ -32,7 +25,7 @@ export function compareObjects(a, b) {
|
|
|
32
25
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
33
26
|
return a.sql === b.sql && compareArrays(a.params, b.params);
|
|
34
27
|
}
|
|
35
|
-
if (
|
|
28
|
+
if (a instanceof Date && b instanceof Date) {
|
|
36
29
|
const timeA = a.getTime();
|
|
37
30
|
const timeB = b.getTime();
|
|
38
31
|
if (isNaN(timeA) || isNaN(timeB)) {
|
|
@@ -40,9 +33,8 @@ export function compareObjects(a, b) {
|
|
|
40
33
|
}
|
|
41
34
|
return timeA === timeB;
|
|
42
35
|
}
|
|
43
|
-
/* v8 ignore next
|
|
36
|
+
/* v8 ignore next */
|
|
44
37
|
if ((typeof a === 'function' && typeof b === 'function') ||
|
|
45
|
-
(typeof a === 'object' && a.client && ['Ref', 'Raw'].includes(a.constructor.name) && typeof b === 'object' && b.client && ['Ref', 'Raw'].includes(b.constructor.name)) || // knex qb
|
|
46
38
|
(a instanceof RegExp && b instanceof RegExp) ||
|
|
47
39
|
(a instanceof String && b instanceof String) ||
|
|
48
40
|
(a instanceof Number && b instanceof Number)) {
|
|
@@ -118,7 +110,7 @@ export function equals(a, b) {
|
|
|
118
110
|
const equalsFn = equals;
|
|
119
111
|
export function parseJsonSafe(value) {
|
|
120
112
|
if (typeof value === 'string') {
|
|
121
|
-
/* v8 ignore next
|
|
113
|
+
/* v8 ignore next */
|
|
122
114
|
try {
|
|
123
115
|
return JSON.parse(value);
|
|
124
116
|
}
|
|
@@ -131,50 +123,13 @@ export function parseJsonSafe(value) {
|
|
|
131
123
|
}
|
|
132
124
|
export class Utils {
|
|
133
125
|
static PK_SEPARATOR = '~~~';
|
|
134
|
-
|
|
135
|
-
* Checks if the argument is not undefined
|
|
136
|
-
*/
|
|
137
|
-
static isDefined(data) {
|
|
138
|
-
return typeof data !== 'undefined';
|
|
139
|
-
}
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.331';
|
|
140
127
|
/**
|
|
141
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
142
129
|
*/
|
|
143
130
|
static isObject(o) {
|
|
144
131
|
return !!o && typeof o === 'object' && !Array.isArray(o);
|
|
145
132
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Relation decorators allow using two signatures
|
|
148
|
-
* - using first parameter as options object
|
|
149
|
-
* - using all parameters
|
|
150
|
-
*
|
|
151
|
-
* This function validates those two ways are not mixed and returns the final options object.
|
|
152
|
-
* If the second way is used, we always consider the last parameter as options object.
|
|
153
|
-
* @internal
|
|
154
|
-
*/
|
|
155
|
-
static processDecoratorParameters(params) {
|
|
156
|
-
const keys = Object.keys(params);
|
|
157
|
-
const values = Object.values(params);
|
|
158
|
-
if (!Utils.isPlainObject(values[0])) {
|
|
159
|
-
const lastKey = keys[keys.length - 1];
|
|
160
|
-
const last = params[lastKey];
|
|
161
|
-
delete params[lastKey];
|
|
162
|
-
return { ...last, ...params };
|
|
163
|
-
}
|
|
164
|
-
// validate only first parameter is used if its an option object
|
|
165
|
-
const empty = (v) => v == null || (Utils.isPlainObject(v) && !Utils.hasObjectKeys(v));
|
|
166
|
-
if (values.slice(1).some(v => !empty(v))) {
|
|
167
|
-
throw new Error('Mixing first decorator parameter as options object with other parameters is forbidden. ' +
|
|
168
|
-
'If you want to use the options parameter at first position, provide all options inside it.');
|
|
169
|
-
}
|
|
170
|
-
return values[0];
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Checks if the argument is instance of `Object`, but not one of the blacklisted types. Returns false for arrays.
|
|
174
|
-
*/
|
|
175
|
-
static isNotObject(o, not) {
|
|
176
|
-
return this.isObject(o) && !not.some(cls => o instanceof cls);
|
|
177
|
-
}
|
|
178
133
|
/**
|
|
179
134
|
* Removes `undefined` properties (recursively) so they are not saved as nulls
|
|
180
135
|
*/
|
|
@@ -222,18 +177,6 @@ export class Utils {
|
|
|
222
177
|
}
|
|
223
178
|
return false;
|
|
224
179
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Checks if the argument is string
|
|
227
|
-
*/
|
|
228
|
-
static isString(s) {
|
|
229
|
-
return typeof s === 'string';
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Checks if the argument is number
|
|
233
|
-
*/
|
|
234
|
-
static isNumber(s) {
|
|
235
|
-
return typeof s === 'number';
|
|
236
|
-
}
|
|
237
180
|
/**
|
|
238
181
|
* Checks if arguments are deeply (but not strictly) equal.
|
|
239
182
|
*/
|
|
@@ -279,7 +222,7 @@ export class Utils {
|
|
|
279
222
|
target[key] = Utils.copy(value);
|
|
280
223
|
continue;
|
|
281
224
|
}
|
|
282
|
-
/* v8 ignore next
|
|
225
|
+
/* v8 ignore next */
|
|
283
226
|
if (!(key in target)) {
|
|
284
227
|
Object.assign(target, { [key]: {} });
|
|
285
228
|
}
|
|
@@ -292,30 +235,6 @@ export class Utils {
|
|
|
292
235
|
}
|
|
293
236
|
return Utils._merge(target, sources, ignoreUndefined);
|
|
294
237
|
}
|
|
295
|
-
static getRootEntity(metadata, meta) {
|
|
296
|
-
const base = meta.extends && metadata.find(Utils.className(meta.extends));
|
|
297
|
-
if (!base || base === meta) { // make sure we do not fall into infinite loop
|
|
298
|
-
return meta;
|
|
299
|
-
}
|
|
300
|
-
const root = Utils.getRootEntity(metadata, base);
|
|
301
|
-
if (root.discriminatorColumn) {
|
|
302
|
-
return root;
|
|
303
|
-
}
|
|
304
|
-
return meta;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Computes difference between two objects, ignoring items missing in `b`.
|
|
308
|
-
*/
|
|
309
|
-
static diff(a, b) {
|
|
310
|
-
const ret = {};
|
|
311
|
-
for (const k of Object.keys(b)) {
|
|
312
|
-
if (Utils.equals(a[k], b[k])) {
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
ret[k] = b[k];
|
|
316
|
-
}
|
|
317
|
-
return ret;
|
|
318
|
-
}
|
|
319
238
|
/**
|
|
320
239
|
* Creates deep copy of given object.
|
|
321
240
|
*/
|
|
@@ -356,53 +275,37 @@ export class Utils {
|
|
|
356
275
|
}
|
|
357
276
|
}
|
|
358
277
|
/**
|
|
359
|
-
* Returns array of functions argument names. Uses
|
|
278
|
+
* Returns array of functions argument names. Uses basic regex for source code analysis, might not work with advanced syntax.
|
|
360
279
|
*/
|
|
361
|
-
static
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
try {
|
|
367
|
-
return tokenize(func.toString(), { tolerant: true });
|
|
280
|
+
static getConstructorParams(func) {
|
|
281
|
+
const source = func.toString();
|
|
282
|
+
const i = source.indexOf('constructor');
|
|
283
|
+
if (i === -1) {
|
|
284
|
+
return undefined;
|
|
368
285
|
}
|
|
369
|
-
|
|
370
|
-
|
|
286
|
+
const start = source.indexOf('(', i);
|
|
287
|
+
if (start === -1) {
|
|
288
|
+
return undefined;
|
|
371
289
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const ret = [];
|
|
378
|
-
const tokens = this.tokenize(func);
|
|
379
|
-
let inside = 0;
|
|
380
|
-
let currentBlockStart = 0;
|
|
381
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
382
|
-
const token = tokens[i];
|
|
383
|
-
if (token.type === 'Identifier' && token.value === methodName) {
|
|
384
|
-
inside = 1;
|
|
385
|
-
currentBlockStart = i;
|
|
386
|
-
continue;
|
|
290
|
+
let depth = 0;
|
|
291
|
+
let end = start;
|
|
292
|
+
for (; end < source.length; end++) {
|
|
293
|
+
if (source[end] === '(') {
|
|
294
|
+
depth++;
|
|
387
295
|
}
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
currentBlockStart = i;
|
|
391
|
-
continue;
|
|
296
|
+
if (source[end] === ')') {
|
|
297
|
+
depth--;
|
|
392
298
|
}
|
|
393
|
-
if (
|
|
299
|
+
if (depth === 0) {
|
|
394
300
|
break;
|
|
395
301
|
}
|
|
396
|
-
if (inside === 2 && token.type === 'Punctuator' && token.value === '{' && i === currentBlockStart + 1) {
|
|
397
|
-
ret.push(ObjectBindingPattern);
|
|
398
|
-
i = tokens.findIndex((t, idx) => idx > i + 2 && t.type === 'Punctuator' && t.value === '}');
|
|
399
|
-
continue;
|
|
400
|
-
}
|
|
401
|
-
if (inside === 2 && token.type === 'Identifier') {
|
|
402
|
-
ret.push(token.value);
|
|
403
|
-
}
|
|
404
302
|
}
|
|
405
|
-
|
|
303
|
+
const raw = source.slice(start + 1, end);
|
|
304
|
+
return raw
|
|
305
|
+
.split(',')
|
|
306
|
+
.map(s => s.trim().replace(/=.*$/, '').trim())
|
|
307
|
+
.filter(Boolean)
|
|
308
|
+
.map(raw => (raw.startsWith('{') && raw.endsWith('}') ? '' : raw));
|
|
406
309
|
}
|
|
407
310
|
/**
|
|
408
311
|
* Checks whether the argument looks like primary key (string, number or ObjectId).
|
|
@@ -415,7 +318,7 @@ export class Utils {
|
|
|
415
318
|
return true;
|
|
416
319
|
}
|
|
417
320
|
if (Utils.isObject(key)) {
|
|
418
|
-
if (key.constructor
|
|
321
|
+
if (key.constructor?.name === 'ObjectId') {
|
|
419
322
|
return true;
|
|
420
323
|
}
|
|
421
324
|
if (!Utils.isPlainObject(key) && !Utils.isEntity(key, true)) {
|
|
@@ -445,7 +348,7 @@ export class Utils {
|
|
|
445
348
|
if (meta.compositePK) {
|
|
446
349
|
return this.getCompositeKeyValue(data, meta);
|
|
447
350
|
}
|
|
448
|
-
return data[meta.primaryKeys[0]]
|
|
351
|
+
return data[meta.primaryKeys[0]] ?? data[meta.serializedPrimaryKey] ?? null;
|
|
449
352
|
}
|
|
450
353
|
return null;
|
|
451
354
|
}
|
|
@@ -471,7 +374,8 @@ export class Utils {
|
|
|
471
374
|
return Utils.getPrimaryKeyHash(pks);
|
|
472
375
|
}
|
|
473
376
|
static getPrimaryKeyHash(pks) {
|
|
474
|
-
return pks
|
|
377
|
+
return pks
|
|
378
|
+
.map(pk => {
|
|
475
379
|
if (Buffer.isBuffer(pk)) {
|
|
476
380
|
return pk.toString('hex');
|
|
477
381
|
}
|
|
@@ -479,14 +383,14 @@ export class Utils {
|
|
|
479
383
|
return pk.toISOString();
|
|
480
384
|
}
|
|
481
385
|
return pk;
|
|
482
|
-
})
|
|
386
|
+
})
|
|
387
|
+
.join(this.PK_SEPARATOR);
|
|
483
388
|
}
|
|
484
389
|
static splitPrimaryKeys(key) {
|
|
485
390
|
return key.split(this.PK_SEPARATOR);
|
|
486
391
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
/* v8 ignore next 3 */
|
|
392
|
+
static getPrimaryKeyValues(entity, meta, allowScalar = false, convertCustomTypes = false) {
|
|
393
|
+
/* v8 ignore next */
|
|
490
394
|
if (entity == null) {
|
|
491
395
|
return entity;
|
|
492
396
|
}
|
|
@@ -496,15 +400,13 @@ export class Utils {
|
|
|
496
400
|
}
|
|
497
401
|
return val;
|
|
498
402
|
}
|
|
499
|
-
const meta = Array.isArray(primaryKeys) ? undefined : primaryKeys;
|
|
500
|
-
primaryKeys = Array.isArray(primaryKeys) ? primaryKeys : meta.primaryKeys;
|
|
501
403
|
let pk;
|
|
502
404
|
if (Utils.isEntity(entity, true)) {
|
|
503
405
|
pk = helper(entity).getPrimaryKey(convertCustomTypes);
|
|
504
406
|
}
|
|
505
407
|
else {
|
|
506
|
-
pk = primaryKeys.reduce((o, pk) => {
|
|
507
|
-
const targetMeta = meta
|
|
408
|
+
pk = meta.primaryKeys.reduce((o, pk) => {
|
|
409
|
+
const targetMeta = meta.properties[pk].targetMeta;
|
|
508
410
|
if (targetMeta && Utils.isPlainObject(entity[pk])) {
|
|
509
411
|
o[pk] = Utils.getPrimaryKeyValues(entity[pk], targetMeta, allowScalar, convertCustomTypes);
|
|
510
412
|
}
|
|
@@ -514,12 +416,12 @@ export class Utils {
|
|
|
514
416
|
return o;
|
|
515
417
|
}, {});
|
|
516
418
|
}
|
|
517
|
-
if (primaryKeys.length > 1) {
|
|
419
|
+
if (meta.primaryKeys.length > 1) {
|
|
518
420
|
return toArray(pk);
|
|
519
421
|
}
|
|
520
422
|
if (allowScalar) {
|
|
521
423
|
if (Utils.isPlainObject(pk)) {
|
|
522
|
-
return pk[primaryKeys[0]];
|
|
424
|
+
return pk[meta.primaryKeys[0]];
|
|
523
425
|
}
|
|
524
426
|
return pk;
|
|
525
427
|
}
|
|
@@ -603,12 +505,6 @@ export class Utils {
|
|
|
603
505
|
static isScalarReference(data, allowReference = false) {
|
|
604
506
|
return typeof data === 'object' && data?.__scalarReference;
|
|
605
507
|
}
|
|
606
|
-
/**
|
|
607
|
-
* Checks whether the argument is ObjectId instance
|
|
608
|
-
*/
|
|
609
|
-
static isObjectID(key) {
|
|
610
|
-
return Utils.isObject(key) && key.constructor && key.constructor.name.toLowerCase() === 'objectid';
|
|
611
|
-
}
|
|
612
508
|
/**
|
|
613
509
|
* Checks whether the argument is empty (array without items, object without keys or falsy value).
|
|
614
510
|
*/
|
|
@@ -633,61 +529,26 @@ export class Utils {
|
|
|
633
529
|
static extractChildElements(items, prefix, allSymbol) {
|
|
634
530
|
return items
|
|
635
531
|
.filter(field => field === allSymbol || field.startsWith(`${prefix}.`))
|
|
636
|
-
.map(field => field === allSymbol ? allSymbol : field.substring(prefix.length + 1));
|
|
532
|
+
.map(field => (field === allSymbol ? allSymbol : field.substring(prefix.length + 1)));
|
|
637
533
|
}
|
|
638
534
|
/**
|
|
639
535
|
* Tries to detect TypeScript support.
|
|
640
536
|
*/
|
|
641
537
|
static detectTypeScriptSupport() {
|
|
642
|
-
/* v8 ignore next
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
* Uses some dark magic to get source path to caller where decorator is used.
|
|
657
|
-
* Analyses stack trace of error created inside the function call.
|
|
658
|
-
*/
|
|
659
|
-
static lookupPathFromDecorator(name, stack) {
|
|
660
|
-
// use some dark magic to get source path to caller
|
|
661
|
-
stack = stack || new Error().stack.split('\n');
|
|
662
|
-
// In some situations (e.g. swc 1.3.4+), the presence of a source map can obscure the call to
|
|
663
|
-
// __decorate(), replacing it with the constructor name. To support these cases we look for
|
|
664
|
-
// Reflect.decorate() as well. Also when babel is used, we need to check
|
|
665
|
-
// the `_applyDecoratedDescriptor` method instead.
|
|
666
|
-
let line = stack.findIndex(line => line.match(/__decorate|Reflect\.decorate|_applyDecoratedDescriptor/));
|
|
667
|
-
// bun does not have those lines at all, only the DecorateProperty/DecorateConstructor,
|
|
668
|
-
// but those are also present in node, so we need to check this only if they weren't found.
|
|
669
|
-
if (line === -1) {
|
|
670
|
-
// here we handle bun which stack is different from nodejs so we search for reflect-metadata
|
|
671
|
-
// Different bun versions might have different stack traces. The "last index" works for both 1.2.6 and 1.2.7.
|
|
672
|
-
const reflectLine = stack.findLastIndex(line => Utils.normalizePath(line).includes('node_modules/reflect-metadata/Reflect.js'));
|
|
673
|
-
if (reflectLine === -1 || reflectLine + 2 >= stack.length || !stack[reflectLine + 1].includes('bun:wrap')) {
|
|
674
|
-
return name;
|
|
675
|
-
}
|
|
676
|
-
line = reflectLine + 2;
|
|
677
|
-
}
|
|
678
|
-
if (stack[line].includes('Reflect.decorate')) {
|
|
679
|
-
line++;
|
|
680
|
-
}
|
|
681
|
-
if (Utils.normalizePath(stack[line]).includes('node_modules/tslib/tslib')) {
|
|
682
|
-
line++;
|
|
683
|
-
}
|
|
684
|
-
try {
|
|
685
|
-
const re = stack[line].match(/\(.+\)/i) ? /\((.*):\d+:\d+\)/ : /at\s*(.*):\d+:\d+$/;
|
|
686
|
-
return Utils.normalizePath(stack[line].match(re)[1]);
|
|
687
|
-
}
|
|
688
|
-
catch {
|
|
689
|
-
return name;
|
|
690
|
-
}
|
|
538
|
+
/* v8 ignore next */
|
|
539
|
+
const process = globalThis.process ?? {};
|
|
540
|
+
/* v8 ignore next */
|
|
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 => /\.([mc]?ts|tsx)$/.exec(arg)) || // 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
|
+
}));
|
|
691
552
|
}
|
|
692
553
|
/**
|
|
693
554
|
* Gets the type of the argument.
|
|
@@ -698,22 +559,23 @@ export class Utils {
|
|
|
698
559
|
return simple;
|
|
699
560
|
}
|
|
700
561
|
const objectType = Object.prototype.toString.call(value);
|
|
701
|
-
const type =
|
|
562
|
+
const type = /^\[object (.+)]$/.exec(objectType)[1];
|
|
702
563
|
if (type === 'Uint8Array') {
|
|
703
564
|
return 'Buffer';
|
|
704
565
|
}
|
|
705
|
-
return
|
|
566
|
+
return type;
|
|
706
567
|
}
|
|
707
568
|
/**
|
|
708
569
|
* Checks whether the value is POJO (e.g. `{ foo: 'bar' }`, and not instance of `Foo`)
|
|
709
570
|
*/
|
|
710
571
|
static isPlainObject(value) {
|
|
711
|
-
return (value !== null
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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);
|
|
717
579
|
}
|
|
718
580
|
/**
|
|
719
581
|
* Executes the `cb` promise serially on every element of the `items` array and returns array of resolved values.
|
|
@@ -728,67 +590,14 @@ export class Utils {
|
|
|
728
590
|
static isCollection(item) {
|
|
729
591
|
return item?.__collection;
|
|
730
592
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
* If any part is a `file:` URL, it is converted to a local path. If any part is an
|
|
738
|
-
* absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
|
|
739
|
-
* Trailing directory separators are removed, and all directory separators are converted
|
|
740
|
-
* to POSIX-style separators (`/`).
|
|
741
|
-
*/
|
|
742
|
-
static normalizePath(...parts) {
|
|
743
|
-
let start = 0;
|
|
744
|
-
for (let i = 0; i < parts.length; i++) {
|
|
745
|
-
const part = parts[i];
|
|
746
|
-
if (isAbsolute(part)) {
|
|
747
|
-
start = i;
|
|
748
|
-
}
|
|
749
|
-
else if (part.startsWith('file:')) {
|
|
750
|
-
start = i;
|
|
751
|
-
parts[i] = Utils.fileURLToPath(part);
|
|
752
|
-
}
|
|
593
|
+
// FNV-1a 64-bit
|
|
594
|
+
static hash(data, length) {
|
|
595
|
+
let h1 = 0xcbf29ce484222325n;
|
|
596
|
+
for (let i = 0; i < data.length; i++) {
|
|
597
|
+
h1 ^= BigInt(data.charCodeAt(i));
|
|
598
|
+
h1 = (h1 * 0x100000001b3n) & 0xffffffffffffffffn;
|
|
753
599
|
}
|
|
754
|
-
|
|
755
|
-
parts = parts.slice(start);
|
|
756
|
-
}
|
|
757
|
-
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
758
|
-
path = normalize(path).replace(/\\/g, '/');
|
|
759
|
-
return (path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!')) ? path : './' + path;
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* Determines the relative path between two paths. If either path is a `file:` URL,
|
|
763
|
-
* it is converted to a local path.
|
|
764
|
-
*/
|
|
765
|
-
static relativePath(path, relativeTo) {
|
|
766
|
-
if (!path) {
|
|
767
|
-
return path;
|
|
768
|
-
}
|
|
769
|
-
path = Utils.normalizePath(path);
|
|
770
|
-
if (path.startsWith('.')) {
|
|
771
|
-
return path;
|
|
772
|
-
}
|
|
773
|
-
path = relative(Utils.normalizePath(relativeTo), path);
|
|
774
|
-
return Utils.normalizePath(path);
|
|
775
|
-
}
|
|
776
|
-
/**
|
|
777
|
-
* Computes the absolute path to for the given path relative to the provided base directory.
|
|
778
|
-
* If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
|
|
779
|
-
*/
|
|
780
|
-
static absolutePath(path, baseDir = process.cwd()) {
|
|
781
|
-
if (!path) {
|
|
782
|
-
return Utils.normalizePath(baseDir);
|
|
783
|
-
}
|
|
784
|
-
if (!isAbsolute(path) && !path.startsWith('file://')) {
|
|
785
|
-
path = baseDir + '/' + path;
|
|
786
|
-
}
|
|
787
|
-
return Utils.normalizePath(path);
|
|
788
|
-
}
|
|
789
|
-
static hash(data, length, algorithm) {
|
|
790
|
-
const hashAlgorithm = algorithm || 'sha256';
|
|
791
|
-
const hash = createHash(hashAlgorithm).update(data).digest('hex');
|
|
600
|
+
const hash = h1.toString(16).padStart(16, '0');
|
|
792
601
|
if (length) {
|
|
793
602
|
return hash.substring(0, length);
|
|
794
603
|
}
|
|
@@ -804,7 +613,7 @@ export class Utils {
|
|
|
804
613
|
}
|
|
805
614
|
static findDuplicates(items) {
|
|
806
615
|
return items.reduce((acc, v, i, arr) => {
|
|
807
|
-
return arr.indexOf(v) !== i && acc.
|
|
616
|
+
return arr.indexOf(v) !== i && !acc.includes(v) ? acc.concat(v) : acc;
|
|
808
617
|
}, []);
|
|
809
618
|
}
|
|
810
619
|
static removeDuplicates(items) {
|
|
@@ -820,13 +629,6 @@ export class Utils {
|
|
|
820
629
|
static randomInt(min, max) {
|
|
821
630
|
return Math.round(Math.random() * (max - min)) + min;
|
|
822
631
|
}
|
|
823
|
-
static async pathExists(path, options = {}) {
|
|
824
|
-
if (isDynamicPattern(path)) {
|
|
825
|
-
const found = await glob(path, options);
|
|
826
|
-
return found.length > 0;
|
|
827
|
-
}
|
|
828
|
-
return this.pathExistsSync(path);
|
|
829
|
-
}
|
|
830
632
|
/**
|
|
831
633
|
* Extracts all possible values of a TS enum. Works with both string and numeric enums.
|
|
832
634
|
*/
|
|
@@ -834,17 +636,20 @@ export class Utils {
|
|
|
834
636
|
const keys = Object.keys(target);
|
|
835
637
|
const values = Object.values(target);
|
|
836
638
|
const numeric = !!values.find(v => typeof v === 'number');
|
|
837
|
-
const constEnum = values.length % 2 === 0 // const enum will have even number of items
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
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
|
|
841
646
|
if (numeric || constEnum) {
|
|
842
647
|
return values.filter(val => !keys.includes(val));
|
|
843
648
|
}
|
|
844
649
|
return values;
|
|
845
650
|
}
|
|
846
|
-
static flatten(arrays) {
|
|
847
|
-
return
|
|
651
|
+
static flatten(arrays, deep) {
|
|
652
|
+
return arrays.flatMap(v => (deep && Array.isArray(v) ? this.flatten(v, true) : v));
|
|
848
653
|
}
|
|
849
654
|
static isOperator(key, includeGroupOperators = true) {
|
|
850
655
|
if (!includeGroupOperators) {
|
|
@@ -852,15 +657,6 @@ export class Utils {
|
|
|
852
657
|
}
|
|
853
658
|
return key in GroupOperator || key in QueryOperator;
|
|
854
659
|
}
|
|
855
|
-
static isGroupOperator(key) {
|
|
856
|
-
return key in GroupOperator;
|
|
857
|
-
}
|
|
858
|
-
static isArrayOperator(key) {
|
|
859
|
-
return ARRAY_OPERATORS.includes(key);
|
|
860
|
-
}
|
|
861
|
-
static isJsonKeyOperator(key) {
|
|
862
|
-
return JSON_KEY_OPERATORS.includes(key);
|
|
863
|
-
}
|
|
864
660
|
static hasNestedKey(object, key) {
|
|
865
661
|
if (!object) {
|
|
866
662
|
return false;
|
|
@@ -873,74 +669,17 @@ export class Utils {
|
|
|
873
669
|
}
|
|
874
670
|
return false;
|
|
875
671
|
}
|
|
876
|
-
static getGlobalStorage(namespace) {
|
|
877
|
-
const key = `mikro-orm-${namespace}`;
|
|
878
|
-
globalThis[key] = globalThis[key] || {};
|
|
879
|
-
return globalThis[key];
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Require a module from a specific location
|
|
883
|
-
* @param id The module to require
|
|
884
|
-
* @param [from] Location to start the node resolution
|
|
885
|
-
*/
|
|
886
|
-
static requireFrom(id, from = process.cwd()) {
|
|
887
|
-
if (!extname(from)) {
|
|
888
|
-
from = join(from, '__fake.js');
|
|
889
|
-
}
|
|
890
|
-
return createRequire(resolve(from))(id);
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Resolve path to a module.
|
|
894
|
-
* @param id The module to require
|
|
895
|
-
* @param [from] Location to start the node resolution
|
|
896
|
-
*/
|
|
897
|
-
static resolveModulePath(id, from = process.cwd()) {
|
|
898
|
-
if (!extname(from)) {
|
|
899
|
-
from = join(from, '__fake.js');
|
|
900
|
-
}
|
|
901
|
-
const path = Utils.normalizePath(createRequire(resolve(from)).resolve(id));
|
|
902
|
-
const parts = path.split('/');
|
|
903
|
-
const idx = parts.lastIndexOf(id) + 1;
|
|
904
|
-
parts.splice(idx, parts.length - idx);
|
|
905
|
-
return parts.join('/');
|
|
906
|
-
}
|
|
907
|
-
static async dynamicImport(id) {
|
|
908
|
-
/* v8 ignore next */
|
|
909
|
-
const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
|
|
910
|
-
return import(specifier);
|
|
911
|
-
}
|
|
912
|
-
static ensureDir(path) {
|
|
913
|
-
if (!existsSync(path)) {
|
|
914
|
-
mkdirSync(path, { recursive: true });
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
static pathExistsSync(path) {
|
|
918
|
-
return existsSync(path);
|
|
919
|
-
}
|
|
920
|
-
static readJSONSync(path) {
|
|
921
|
-
const file = readFileSync(path);
|
|
922
|
-
return JSON.parse(file.toString());
|
|
923
|
-
}
|
|
924
672
|
static getORMVersion() {
|
|
925
|
-
|
|
926
|
-
// this works during development where we have `src` folder
|
|
927
|
-
return this.requireFrom('../../package.json', import.meta.dirname).version;
|
|
928
|
-
/* v8 ignore next 5 */
|
|
929
|
-
}
|
|
930
|
-
catch {
|
|
931
|
-
try {
|
|
932
|
-
// this works in production build where we do not have the `src` folder
|
|
933
|
-
return this.requireFrom('../package.json', import.meta.dirname).version;
|
|
934
|
-
}
|
|
935
|
-
catch {
|
|
936
|
-
return 'N/A';
|
|
937
|
-
}
|
|
938
|
-
}
|
|
673
|
+
return this.#ORM_VERSION;
|
|
939
674
|
}
|
|
940
|
-
static createFunction(context, code) {
|
|
675
|
+
static createFunction(context, code, compiledFunctions, key) {
|
|
676
|
+
if (key && compiledFunctions?.[key]) {
|
|
677
|
+
return compiledFunctions[key](...context.values());
|
|
678
|
+
}
|
|
941
679
|
try {
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
942
681
|
return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
|
|
943
|
-
/* v8 ignore next
|
|
682
|
+
/* v8 ignore next */
|
|
944
683
|
}
|
|
945
684
|
catch (e) {
|
|
946
685
|
// eslint-disable-next-line no-console
|
|
@@ -953,7 +692,7 @@ export class Utils {
|
|
|
953
692
|
return fn(...args);
|
|
954
693
|
}
|
|
955
694
|
catch (e) {
|
|
956
|
-
/* v8 ignore
|
|
695
|
+
/* v8 ignore next */
|
|
957
696
|
if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
|
|
958
697
|
const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
|
|
959
698
|
let code = fn.toString();
|
|
@@ -970,18 +709,9 @@ export class Utils {
|
|
|
970
709
|
// eslint-disable-next-line no-console
|
|
971
710
|
console.error(`JIT runtime error: ${e.message}\n\n${code}`);
|
|
972
711
|
}
|
|
973
|
-
/* v8 ignore stop */
|
|
974
712
|
throw e;
|
|
975
713
|
}
|
|
976
714
|
}
|
|
977
|
-
/**
|
|
978
|
-
* @see https://github.com/mikro-orm/mikro-orm/issues/840
|
|
979
|
-
*/
|
|
980
|
-
static propertyDecoratorReturnValue() {
|
|
981
|
-
if (process.env.BABEL_DECORATORS_COMPAT) {
|
|
982
|
-
return {};
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
715
|
static unwrapProperty(entity, meta, prop, payload = false) {
|
|
986
716
|
let p = prop;
|
|
987
717
|
const path = [];
|
|
@@ -1061,57 +791,21 @@ export class Utils {
|
|
|
1061
791
|
}
|
|
1062
792
|
}
|
|
1063
793
|
}
|
|
1064
|
-
static
|
|
1065
|
-
allowError ??= `Cannot find module '${module}'`;
|
|
1066
|
-
from ??= process.cwd();
|
|
1067
|
-
try {
|
|
1068
|
-
return Utils.requireFrom(module, from);
|
|
1069
|
-
}
|
|
1070
|
-
catch (err) {
|
|
1071
|
-
if (err.message.includes(allowError)) {
|
|
1072
|
-
// eslint-disable-next-line no-console
|
|
1073
|
-
console.warn(warning);
|
|
1074
|
-
return undefined;
|
|
1075
|
-
}
|
|
1076
|
-
throw err;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
static async tryImport({ module, warning }) {
|
|
794
|
+
static async tryImport({ module, warning, }) {
|
|
1080
795
|
try {
|
|
1081
796
|
return await import(module);
|
|
1082
797
|
}
|
|
1083
798
|
catch (err) {
|
|
1084
799
|
if (err.code === 'ERR_MODULE_NOT_FOUND') {
|
|
1085
|
-
|
|
1086
|
-
|
|
800
|
+
if (warning) {
|
|
801
|
+
// eslint-disable-next-line no-console
|
|
802
|
+
console.warn(warning);
|
|
803
|
+
}
|
|
1087
804
|
return undefined;
|
|
1088
805
|
}
|
|
1089
806
|
throw err;
|
|
1090
807
|
}
|
|
1091
808
|
}
|
|
1092
|
-
static stripRelativePath(str) {
|
|
1093
|
-
return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* simple process.argv parser, supports only properties with long names, prefixed with `--`
|
|
1097
|
-
*/
|
|
1098
|
-
static parseArgs() {
|
|
1099
|
-
let lastKey;
|
|
1100
|
-
return process.argv.slice(2).reduce((args, arg) => {
|
|
1101
|
-
if (arg.includes('=')) {
|
|
1102
|
-
const [key, value] = arg.split('=');
|
|
1103
|
-
args[key.substring(2)] = value;
|
|
1104
|
-
}
|
|
1105
|
-
else if (lastKey) {
|
|
1106
|
-
args[lastKey] = arg;
|
|
1107
|
-
lastKey = undefined;
|
|
1108
|
-
}
|
|
1109
|
-
else if (arg.startsWith('--')) {
|
|
1110
|
-
lastKey = arg.substring(2);
|
|
1111
|
-
}
|
|
1112
|
-
return args;
|
|
1113
|
-
}, {});
|
|
1114
|
-
}
|
|
1115
809
|
static xor(a, b) {
|
|
1116
810
|
return (a || b) && !(a && b);
|
|
1117
811
|
}
|
|
@@ -1140,4 +834,12 @@ export class Utils {
|
|
|
1140
834
|
return o;
|
|
1141
835
|
}, {});
|
|
1142
836
|
}
|
|
837
|
+
static getObjectQueryKeys(obj) {
|
|
838
|
+
return Reflect.ownKeys(obj).filter(key => {
|
|
839
|
+
if (!Object.prototype.propertyIsEnumerable.call(obj, key)) {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
return typeof key === 'string' || Raw.isKnownFragmentSymbol(key);
|
|
843
|
+
});
|
|
844
|
+
}
|
|
1143
845
|
}
|