@mikro-orm/core 7.0.0-dev.76 → 7.0.0-dev.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityManager.js +4 -4
- package/MikroORM.d.ts +29 -2
- package/MikroORM.js +62 -12
- package/drivers/DatabaseDriver.js +4 -4
- package/entity/Collection.js +2 -2
- package/entity/EntityAssigner.js +2 -2
- package/entity/EntityFactory.js +1 -1
- package/entity/EntityLoader.js +4 -4
- package/entity/Reference.js +1 -1
- package/entity/WrappedEntity.d.ts +2 -2
- package/entity/utils.js +1 -1
- package/entity/validators.js +1 -1
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.js +1 -1
- package/metadata/MetadataDiscovery.js +4 -4
- package/metadata/MetadataProvider.js +1 -1
- package/naming-strategy/AbstractNamingStrategy.js +1 -1
- package/package.json +1 -1
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.js +8 -17
- package/serialization/EntitySerializer.js +3 -3
- package/serialization/SerializationContext.js +2 -2
- package/types/ArrayType.js +1 -1
- package/types/BigIntType.js +1 -1
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/TinyIntType.js +1 -1
- package/types/Uint8ArrayType.js +1 -1
- package/typings.js +3 -3
- package/unit-of-work/UnitOfWork.js +1 -1
- package/utils/AbstractSchemaGenerator.js +1 -1
- package/utils/Configuration.d.ts +1 -3
- package/utils/Configuration.js +2 -4
- package/utils/ConfigurationLoader.d.ts +3 -3
- package/utils/ConfigurationLoader.js +11 -9
- package/utils/Cursor.js +1 -1
- package/utils/DataloaderUtils.js +2 -2
- package/utils/EntityComparator.js +4 -4
- package/utils/QueryHelper.js +1 -1
- package/utils/RawQueryFragment.js +1 -1
- package/utils/Utils.d.ts +0 -12
- package/utils/Utils.js +9 -52
- package/utils/clone.js +1 -1
- package/utils/upsert-utils.js +3 -3
package/EntityManager.js
CHANGED
|
@@ -239,7 +239,7 @@ export class EntityManager {
|
|
|
239
239
|
if (options.populateWhere === PopulateHint.ALL) {
|
|
240
240
|
return { where: {}, populateWhere: options.populateWhere };
|
|
241
241
|
}
|
|
242
|
-
/* v8 ignore next
|
|
242
|
+
/* v8 ignore next */
|
|
243
243
|
if (options.populateWhere === PopulateHint.INFER) {
|
|
244
244
|
return { where, populateWhere: options.populateWhere };
|
|
245
245
|
}
|
|
@@ -977,7 +977,7 @@ export class EntityManager {
|
|
|
977
977
|
});
|
|
978
978
|
return this.comparator.matching(entityName, cond, tmp);
|
|
979
979
|
});
|
|
980
|
-
/* v8 ignore next
|
|
980
|
+
/* v8 ignore next */
|
|
981
981
|
if (!row) {
|
|
982
982
|
throw new Error(`Cannot find matching entity for condition ${JSON.stringify(cond)}`);
|
|
983
983
|
}
|
|
@@ -1000,7 +1000,7 @@ export class EntityManager {
|
|
|
1000
1000
|
}, {});
|
|
1001
1001
|
return this.comparator.matching(entityName, cond, pk);
|
|
1002
1002
|
});
|
|
1003
|
-
/* v8 ignore next
|
|
1003
|
+
/* v8 ignore next */
|
|
1004
1004
|
if (!row) {
|
|
1005
1005
|
throw new Error(`Cannot find matching entity for condition ${JSON.stringify(cond)}`);
|
|
1006
1006
|
}
|
|
@@ -1674,7 +1674,7 @@ export class EntityManager {
|
|
|
1674
1674
|
}
|
|
1675
1675
|
if (typeof options.populate !== 'boolean') {
|
|
1676
1676
|
options.populate = Utils.asArray(options.populate).map(field => {
|
|
1677
|
-
/* v8 ignore next
|
|
1677
|
+
/* v8 ignore next */
|
|
1678
1678
|
if (typeof field === 'boolean' || field === PopulatePath.ALL) {
|
|
1679
1679
|
return [{ field: meta.primaryKeys[0], strategy: options.strategy, all: !!field }]; //
|
|
1680
1680
|
}
|
package/MikroORM.d.ts
CHANGED
|
@@ -4,8 +4,35 @@ import { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
|
4
4
|
import { Configuration, type Options } from './utils/Configuration.js';
|
|
5
5
|
import type { EntityManager } from './EntityManager.js';
|
|
6
6
|
import type { AnyEntity, Constructor, EntityClass, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings.js';
|
|
7
|
+
/** @internal */
|
|
8
|
+
export declare function lookupExtensions(options: Options): Promise<void>;
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
10
|
+
* The main class used to configure and bootstrap the ORM.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // import from driver package
|
|
15
|
+
* import { MikroORM, defineEntity, p } from '@mikro-orm/sqlite';
|
|
16
|
+
*
|
|
17
|
+
* const User = defineEntity({
|
|
18
|
+
* name: 'User',
|
|
19
|
+
* properties: {
|
|
20
|
+
* id: p.integer().primary(),
|
|
21
|
+
* name: p.string(),
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* const orm = new MikroORM({
|
|
26
|
+
* entities: [User],
|
|
27
|
+
* dbName: 'my.db',
|
|
28
|
+
* });
|
|
29
|
+
* await orm.schema.update();
|
|
30
|
+
*
|
|
31
|
+
* const em = orm.em.fork();
|
|
32
|
+
* const u1 = em.create(User, { name: 'John' });
|
|
33
|
+
* const u2 = em.create(User, { name: 'Ben' });
|
|
34
|
+
* await em.flush();
|
|
35
|
+
* ```
|
|
9
36
|
*/
|
|
10
37
|
export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver, EM extends Driver[typeof EntityManagerType] & EntityManager<Driver> = Driver[typeof EntityManagerType] & EntityManager<Driver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> {
|
|
11
38
|
/** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
|
|
@@ -42,7 +69,7 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
|
|
|
42
69
|
*/
|
|
43
70
|
isConnected(): Promise<boolean>;
|
|
44
71
|
/**
|
|
45
|
-
* Checks whether the database connection is active, returns .
|
|
72
|
+
* Checks whether the database connection is active, returns the reason if not.
|
|
46
73
|
*/
|
|
47
74
|
checkConnection(): Promise<{
|
|
48
75
|
ok: true;
|
package/MikroORM.js
CHANGED
|
@@ -4,8 +4,61 @@ import { Configuration } from './utils/Configuration.js';
|
|
|
4
4
|
import { ConfigurationLoader } from './utils/ConfigurationLoader.js';
|
|
5
5
|
import { Utils } from './utils/Utils.js';
|
|
6
6
|
import { colors } from './logging/colors.js';
|
|
7
|
+
async function registerExtension(name, mod, extensions) {
|
|
8
|
+
/* v8 ignore next */
|
|
9
|
+
const resolved = await mod.catch(() => null);
|
|
10
|
+
const module = resolved?.[name];
|
|
11
|
+
/* v8 ignore else */
|
|
12
|
+
if (module) {
|
|
13
|
+
extensions.push(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
export async function lookupExtensions(options) {
|
|
18
|
+
const extensions = options.extensions ?? [];
|
|
19
|
+
const exists = (name) => extensions.some(ext => ext.name === name);
|
|
20
|
+
if (!exists('SeedManager')) {
|
|
21
|
+
await registerExtension('SeedManager', import('@mikro-orm/seeder' + ''), extensions);
|
|
22
|
+
}
|
|
23
|
+
if (!exists('Migrator')) {
|
|
24
|
+
await registerExtension('Migrator', import('@mikro-orm/migrations' + ''), extensions);
|
|
25
|
+
}
|
|
26
|
+
/* v8 ignore if */
|
|
27
|
+
if (!exists('Migrator')) {
|
|
28
|
+
await registerExtension('Migrator', import('@mikro-orm/migrations-mongodb' + ''), extensions);
|
|
29
|
+
}
|
|
30
|
+
if (!exists('EntityGenerator')) {
|
|
31
|
+
await registerExtension('EntityGenerator', import('@mikro-orm/entity-generator' + ''), extensions);
|
|
32
|
+
}
|
|
33
|
+
options.extensions = extensions;
|
|
34
|
+
}
|
|
7
35
|
/**
|
|
8
|
-
*
|
|
36
|
+
* The main class used to configure and bootstrap the ORM.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* // import from driver package
|
|
41
|
+
* import { MikroORM, defineEntity, p } from '@mikro-orm/sqlite';
|
|
42
|
+
*
|
|
43
|
+
* const User = defineEntity({
|
|
44
|
+
* name: 'User',
|
|
45
|
+
* properties: {
|
|
46
|
+
* id: p.integer().primary(),
|
|
47
|
+
* name: p.string(),
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const orm = new MikroORM({
|
|
52
|
+
* entities: [User],
|
|
53
|
+
* dbName: 'my.db',
|
|
54
|
+
* });
|
|
55
|
+
* await orm.schema.update();
|
|
56
|
+
*
|
|
57
|
+
* const em = orm.em.fork();
|
|
58
|
+
* const u1 = em.create(User, { name: 'John' });
|
|
59
|
+
* const u2 = em.create(User, { name: 'Ben' });
|
|
60
|
+
* await em.flush();
|
|
61
|
+
* ```
|
|
9
62
|
*/
|
|
10
63
|
export class MikroORM {
|
|
11
64
|
/** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
|
|
@@ -20,12 +73,14 @@ export class MikroORM {
|
|
|
20
73
|
* If you omit the `options` parameter, your CLI config will be used.
|
|
21
74
|
*/
|
|
22
75
|
static async init(options) {
|
|
23
|
-
/* v8 ignore next
|
|
76
|
+
/* v8 ignore next */
|
|
24
77
|
if (!options) {
|
|
25
78
|
throw new Error(`options parameter is required`);
|
|
26
79
|
}
|
|
80
|
+
options = { ...options };
|
|
27
81
|
options.discovery ??= {};
|
|
28
82
|
options.discovery.skipSyncDiscovery ??= true;
|
|
83
|
+
await lookupExtensions(options);
|
|
29
84
|
const orm = new this(options);
|
|
30
85
|
const preferTs = orm.config.get('preferTs', Utils.detectTypeScriptSupport());
|
|
31
86
|
orm.metadata = await orm.discovery.discover(preferTs);
|
|
@@ -40,13 +95,12 @@ export class MikroORM {
|
|
|
40
95
|
*/
|
|
41
96
|
constructor(options) {
|
|
42
97
|
const env = ConfigurationLoader.loadEnvironmentVars();
|
|
43
|
-
const coreVersion = ConfigurationLoader.checkPackageVersion();
|
|
44
98
|
options = Utils.merge(options, env);
|
|
45
99
|
this.config = new Configuration(options);
|
|
46
100
|
const discovery = this.config.get('discovery');
|
|
47
101
|
this.driver = this.config.getDriver();
|
|
48
102
|
this.logger = this.config.getLogger();
|
|
49
|
-
this.logger.log('info', `MikroORM version: ${colors.green(
|
|
103
|
+
this.logger.log('info', `MikroORM version: ${colors.green(Utils.getORMVersion())}`);
|
|
50
104
|
this.discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
|
|
51
105
|
this.driver.getPlatform().init(this);
|
|
52
106
|
for (const extension of this.config.get('extensions')) {
|
|
@@ -68,7 +122,7 @@ export class MikroORM {
|
|
|
68
122
|
* Reconnects, possibly to a different database.
|
|
69
123
|
*/
|
|
70
124
|
async reconnect(options = {}) {
|
|
71
|
-
/* v8 ignore next
|
|
125
|
+
/* v8 ignore next */
|
|
72
126
|
for (const key of Utils.keys(options)) {
|
|
73
127
|
this.config.set(key, options[key]);
|
|
74
128
|
}
|
|
@@ -81,7 +135,7 @@ export class MikroORM {
|
|
|
81
135
|
return this.driver.getConnection().isConnected();
|
|
82
136
|
}
|
|
83
137
|
/**
|
|
84
|
-
* Checks whether the database connection is active, returns .
|
|
138
|
+
* Checks whether the database connection is active, returns the reason if not.
|
|
85
139
|
*/
|
|
86
140
|
async checkConnection() {
|
|
87
141
|
return this.driver.getConnection().checkConnection();
|
|
@@ -91,12 +145,8 @@ export class MikroORM {
|
|
|
91
145
|
*/
|
|
92
146
|
async close(force = false) {
|
|
93
147
|
await this.driver.close(force);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
if (this.config.getResultCacheAdapter()?.close) {
|
|
98
|
-
await this.config.getResultCacheAdapter().close();
|
|
99
|
-
}
|
|
148
|
+
await this.config.getMetadataCacheAdapter().close?.();
|
|
149
|
+
await this.config.getResultCacheAdapter().close?.();
|
|
100
150
|
}
|
|
101
151
|
/**
|
|
102
152
|
* Gets the `MetadataStorage` (without parameters) or `EntityMetadata` instance when provided with the `entityName` parameter.
|
|
@@ -31,11 +31,11 @@ export class DatabaseDriver {
|
|
|
31
31
|
const EntityManagerClass = this.config.get('entityManager', EntityManager);
|
|
32
32
|
return new EntityManagerClass(this.config, this, this.metadata, useContext);
|
|
33
33
|
}
|
|
34
|
-
/* v8 ignore next
|
|
34
|
+
/* v8 ignore next */
|
|
35
35
|
async findVirtual(entityName, where, options) {
|
|
36
36
|
throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
|
|
37
37
|
}
|
|
38
|
-
/* v8 ignore next
|
|
38
|
+
/* v8 ignore next */
|
|
39
39
|
async countVirtual(entityName, where, options) {
|
|
40
40
|
throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
|
|
41
41
|
}
|
|
@@ -53,7 +53,7 @@ export class DatabaseDriver {
|
|
|
53
53
|
}
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
/* v8 ignore next
|
|
56
|
+
/* v8 ignore next */
|
|
57
57
|
const pk = coll.property.targetMeta.primaryKeys[0];
|
|
58
58
|
const data = { [coll.property.name]: coll.getIdentifiers(pk) };
|
|
59
59
|
await this.nativeUpdate(coll.owner.constructor.name, helper(coll.owner).getPrimaryKey(), data, options);
|
|
@@ -253,7 +253,7 @@ export class DatabaseDriver {
|
|
|
253
253
|
return data;
|
|
254
254
|
}
|
|
255
255
|
inlineEmbeddables(meta, data, where) {
|
|
256
|
-
/* v8 ignore next
|
|
256
|
+
/* v8 ignore next */
|
|
257
257
|
if (data == null) {
|
|
258
258
|
return;
|
|
259
259
|
}
|
package/entity/Collection.js
CHANGED
|
@@ -18,7 +18,7 @@ export class Collection {
|
|
|
18
18
|
_populated;
|
|
19
19
|
constructor(owner, items, initialized = true) {
|
|
20
20
|
this.owner = owner;
|
|
21
|
-
/* v8 ignore next
|
|
21
|
+
/* v8 ignore next */
|
|
22
22
|
if (items) {
|
|
23
23
|
let i = 0;
|
|
24
24
|
this.items = new Set(items);
|
|
@@ -619,7 +619,7 @@ export class Collection {
|
|
|
619
619
|
get property() {
|
|
620
620
|
if (!this._property) {
|
|
621
621
|
const meta = wrap(this.owner, true).__meta;
|
|
622
|
-
/* v8 ignore next
|
|
622
|
+
/* v8 ignore next */
|
|
623
623
|
if (!meta) {
|
|
624
624
|
throw MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
|
|
625
625
|
}
|
package/entity/EntityAssigner.js
CHANGED
|
@@ -120,7 +120,7 @@ export class EntityAssigner {
|
|
|
120
120
|
}
|
|
121
121
|
const meta2 = helper(ref).__meta;
|
|
122
122
|
const prop2 = meta2.properties[prop.inversedBy || prop.mappedBy];
|
|
123
|
-
/* v8 ignore next
|
|
123
|
+
/* v8 ignore next */
|
|
124
124
|
if (prop2 && !ref[prop2.name]) {
|
|
125
125
|
if (Reference.isReference(ref)) {
|
|
126
126
|
ref.unwrap()[prop2.name] = Reference.wrapReference(entity, prop2);
|
|
@@ -173,7 +173,7 @@ export class EntityAssigner {
|
|
|
173
173
|
}
|
|
174
174
|
return this.createCollectionItem(item, em, prop, invalid, options);
|
|
175
175
|
}
|
|
176
|
-
/* v8 ignore next
|
|
176
|
+
/* v8 ignore next */
|
|
177
177
|
if (options.updateNestedEntities && !options.updateByPrimaryKey && collection[idx] && helper(collection[idx])?.isInitialized()) {
|
|
178
178
|
return EntityAssigner.assign(collection[idx], item, options);
|
|
179
179
|
}
|
package/entity/EntityFactory.js
CHANGED
package/entity/EntityLoader.js
CHANGED
|
@@ -41,7 +41,7 @@ export class EntityLoader {
|
|
|
41
41
|
}
|
|
42
42
|
populate = this.normalizePopulate(entityName, populate, options.strategy, options.lookup);
|
|
43
43
|
const invalid = populate.find(({ field }) => !this.em.canPopulate(entityName, field));
|
|
44
|
-
/* v8 ignore next
|
|
44
|
+
/* v8 ignore next */
|
|
45
45
|
if (options.validate && invalid) {
|
|
46
46
|
throw ValidationError.invalidPropertyName(entityName, invalid.field);
|
|
47
47
|
}
|
|
@@ -463,7 +463,7 @@ export class EntityLoader {
|
|
|
463
463
|
const parts = f.toString().split('.');
|
|
464
464
|
const propName = parts.shift();
|
|
465
465
|
const childPropName = parts.join('.');
|
|
466
|
-
/* v8 ignore next
|
|
466
|
+
/* v8 ignore next */
|
|
467
467
|
if (propName === prop.name) {
|
|
468
468
|
ret.push(childPropName);
|
|
469
469
|
}
|
|
@@ -514,7 +514,7 @@ export class EntityLoader {
|
|
|
514
514
|
return wrapped.__loadedProperties.has(field);
|
|
515
515
|
}
|
|
516
516
|
const [f, ...r] = field.split('.');
|
|
517
|
-
/* v8 ignore next
|
|
517
|
+
/* v8 ignore next */
|
|
518
518
|
if (!wrapped.__loadedProperties.has(f) || !wrapped.__meta.properties[f]?.targetMeta) {
|
|
519
519
|
return false;
|
|
520
520
|
}
|
|
@@ -547,7 +547,7 @@ export class EntityLoader {
|
|
|
547
547
|
.map(e => Reference.unwrapReference(e[field]));
|
|
548
548
|
}
|
|
549
549
|
filterByReferences(entities, field, refresh) {
|
|
550
|
-
/* v8 ignore next
|
|
550
|
+
/* v8 ignore next */
|
|
551
551
|
if (refresh) {
|
|
552
552
|
return entities;
|
|
553
553
|
}
|
package/entity/Reference.js
CHANGED
|
@@ -213,8 +213,8 @@ export class ScalarReference {
|
|
|
213
213
|
isInitialized() {
|
|
214
214
|
return this.initialized;
|
|
215
215
|
}
|
|
216
|
-
/* v8 ignore next 4 */
|
|
217
216
|
/** @ignore */
|
|
217
|
+
/* v8 ignore next */
|
|
218
218
|
[inspect.custom]() {
|
|
219
219
|
return this.initialized ? `Ref<${inspect(this.value)}>` : `Ref<?>`;
|
|
220
220
|
}
|
|
@@ -59,8 +59,8 @@ export declare class WrappedEntity<Entity extends object> {
|
|
|
59
59
|
setPrimaryKey(id: Primary<Entity> | null): void;
|
|
60
60
|
getSerializedPrimaryKey(): string;
|
|
61
61
|
get __meta(): EntityMetadata<Entity>;
|
|
62
|
-
get __platform(): import("
|
|
63
|
-
get __config(): import("
|
|
62
|
+
get __platform(): import("@mikro-orm/knex").Platform;
|
|
63
|
+
get __config(): import("@mikro-orm/knex").Configuration<import("../drivers/IDatabaseDriver.js").IDatabaseDriver<import("@mikro-orm/knex").Connection>, EntityManager<import("../drivers/IDatabaseDriver.js").IDatabaseDriver<import("@mikro-orm/knex").Connection>>>;
|
|
64
64
|
get __primaryKeys(): Primary<Entity>[];
|
|
65
65
|
/** @ignore */
|
|
66
66
|
[inspect.custom](): string;
|
package/entity/utils.js
CHANGED
|
@@ -21,7 +21,7 @@ export function expandDotPaths(meta, populate, normalized = false) {
|
|
|
21
21
|
if (typeof field === 'string') {
|
|
22
22
|
return { field };
|
|
23
23
|
}
|
|
24
|
-
/* v8 ignore next
|
|
24
|
+
/* v8 ignore next */
|
|
25
25
|
return typeof field === 'boolean' || field.field === PopulatePath.ALL
|
|
26
26
|
? { all: !!field, field: meta.primaryKeys[0] }
|
|
27
27
|
: field;
|
package/entity/validators.js
CHANGED
|
@@ -11,7 +11,7 @@ export function validateProperty(prop, givenValue, entity) {
|
|
|
11
11
|
const propName = prop.embedded ? prop.name.replace(/~/g, '.') : prop.name;
|
|
12
12
|
const givenType = Utils.getObjectType(givenValue);
|
|
13
13
|
if (prop.enum && prop.items) {
|
|
14
|
-
/* v8 ignore next
|
|
14
|
+
/* v8 ignore next */
|
|
15
15
|
if (!prop.items.some(it => it === givenValue)) {
|
|
16
16
|
throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
|
|
17
17
|
}
|
package/hydration/Hydrator.js
CHANGED
|
@@ -51,7 +51,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
51
51
|
context.set('Reference', Reference);
|
|
52
52
|
const registerCustomType = (prop, convertorKey, method, context) => {
|
|
53
53
|
context.set(`${method}_${convertorKey}`, (val) => {
|
|
54
|
-
/* v8 ignore next
|
|
54
|
+
/* v8 ignore next */
|
|
55
55
|
if (RawQueryFragment.isKnownFragment(val)) {
|
|
56
56
|
return val;
|
|
57
57
|
}
|
|
@@ -224,7 +224,7 @@ export class MetadataDiscovery {
|
|
|
224
224
|
if (typeof parent === 'function' && parent.name && !this.metadata.has(parent.name)) {
|
|
225
225
|
this.discoverReferences([parent], false);
|
|
226
226
|
}
|
|
227
|
-
/* v8 ignore next
|
|
227
|
+
/* v8 ignore next */
|
|
228
228
|
if (!meta.class) {
|
|
229
229
|
continue;
|
|
230
230
|
}
|
|
@@ -375,7 +375,7 @@ export class MetadataDiscovery {
|
|
|
375
375
|
if (prop.joinColumns.length !== prop.columnTypes.length) {
|
|
376
376
|
prop.columnTypes = prop.joinColumns.flatMap(field => {
|
|
377
377
|
const matched = meta.props.find(p => p.fieldNames?.includes(field));
|
|
378
|
-
/* v8 ignore next
|
|
378
|
+
/* v8 ignore next */
|
|
379
379
|
if (!matched) {
|
|
380
380
|
throw MetadataError.fromWrongForeignKey(meta, prop, 'columnTypes');
|
|
381
381
|
}
|
|
@@ -538,7 +538,7 @@ export class MetadataDiscovery {
|
|
|
538
538
|
}
|
|
539
539
|
else if (fks.length >= 2) {
|
|
540
540
|
[first, second] = fks;
|
|
541
|
-
/* v8 ignore next
|
|
541
|
+
/* v8 ignore next */
|
|
542
542
|
}
|
|
543
543
|
else {
|
|
544
544
|
return [];
|
|
@@ -1016,7 +1016,7 @@ export class MetadataDiscovery {
|
|
|
1016
1016
|
if (typeof prop.defaultRaw !== 'undefined') {
|
|
1017
1017
|
return prop.defaultRaw;
|
|
1018
1018
|
}
|
|
1019
|
-
/* v8 ignore next
|
|
1019
|
+
/* v8 ignore next */
|
|
1020
1020
|
if (prop.default != null) {
|
|
1021
1021
|
return '' + this.platform.quoteVersionValue(prop.default, prop);
|
|
1022
1022
|
}
|
|
@@ -22,7 +22,7 @@ export class MetadataProvider {
|
|
|
22
22
|
loadFromCache(meta, cache) {
|
|
23
23
|
Object.values(cache.properties).forEach(prop => {
|
|
24
24
|
const metaProp = meta.properties[prop.name];
|
|
25
|
-
/* v8 ignore next
|
|
25
|
+
/* v8 ignore next */
|
|
26
26
|
if (metaProp?.enum && Array.isArray(metaProp.items)) {
|
|
27
27
|
delete prop.items;
|
|
28
28
|
}
|
|
@@ -14,7 +14,7 @@ export class AbstractNamingStrategy {
|
|
|
14
14
|
return migrationName;
|
|
15
15
|
}
|
|
16
16
|
indexName(tableName, columns, type) {
|
|
17
|
-
/* v8 ignore next
|
|
17
|
+
/* v8 ignore next */
|
|
18
18
|
if (tableName.includes('.')) {
|
|
19
19
|
tableName = tableName.substring(tableName.indexOf('.') + 1);
|
|
20
20
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.77",
|
|
5
5
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
package/platforms/Platform.js
CHANGED
|
@@ -4,7 +4,7 @@ import { EntityRepository } from '../entity/EntityRepository.js';
|
|
|
4
4
|
import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
|
|
5
5
|
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
6
|
import { ArrayType, BigIntType, BlobType, BooleanType, CharacterType, DateTimeType, DateType, DecimalType, DoubleType, EnumType, FloatType, IntegerType, IntervalType, JsonType, MediumIntType, SmallIntType, StringType, TextType, TimeType, TinyIntType, Type, Uint8ArrayType, UnknownType, UuidType, } from '../types/index.js';
|
|
7
|
-
import { parseJsonSafe
|
|
7
|
+
import { parseJsonSafe } from '../utils/Utils.js';
|
|
8
8
|
import { ReferenceKind } from '../enums.js';
|
|
9
9
|
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
10
10
|
export const JsonProperty = Symbol('JsonProperty');
|
|
@@ -257,7 +257,7 @@ export class Platform {
|
|
|
257
257
|
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
258
258
|
return path.join('.');
|
|
259
259
|
}
|
|
260
|
-
/* v8 ignore next
|
|
260
|
+
/* v8 ignore next */
|
|
261
261
|
getJsonIndexDefinition(index) {
|
|
262
262
|
return index.columnNames;
|
|
263
263
|
}
|
|
@@ -290,7 +290,7 @@ export class Platform {
|
|
|
290
290
|
}
|
|
291
291
|
parseDate(value) {
|
|
292
292
|
const date = new Date(value);
|
|
293
|
-
/* v8 ignore next
|
|
293
|
+
/* v8 ignore next */
|
|
294
294
|
if (isNaN(date.getTime())) {
|
|
295
295
|
return value;
|
|
296
296
|
}
|
|
@@ -320,19 +320,10 @@ export class Platform {
|
|
|
320
320
|
if (extension) {
|
|
321
321
|
return extension;
|
|
322
322
|
}
|
|
323
|
-
/* v8 ignore next
|
|
324
|
-
|
|
325
|
-
module: moduleName,
|
|
326
|
-
warning: `Please install ${moduleName} package.`,
|
|
327
|
-
});
|
|
328
|
-
/* v8 ignore next 3 */
|
|
329
|
-
if (module) {
|
|
330
|
-
return this.config.getCachedService(module[extensionName], em);
|
|
331
|
-
}
|
|
332
|
-
/* v8 ignore next 2 */
|
|
333
|
-
throw new Error(`${extensionName} extension not registered.`);
|
|
323
|
+
/* v8 ignore next */
|
|
324
|
+
throw new Error(`${extensionName} extension not registered. Provide it in the ORM config, or use the async \`MikroORM.init()\` method to load extensions automatically.`);
|
|
334
325
|
}
|
|
335
|
-
/* v8 ignore next
|
|
326
|
+
/* v8 ignore next: kept for type inference only */
|
|
336
327
|
getSchemaGenerator(driver, em) {
|
|
337
328
|
throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
|
|
338
329
|
}
|
|
@@ -349,7 +340,7 @@ export class Platform {
|
|
|
349
340
|
quoteValue(value) {
|
|
350
341
|
return value;
|
|
351
342
|
}
|
|
352
|
-
/* v8 ignore next
|
|
343
|
+
/* v8 ignore next */
|
|
353
344
|
escape(value) {
|
|
354
345
|
return value;
|
|
355
346
|
}
|
|
@@ -506,8 +497,8 @@ export class Platform {
|
|
|
506
497
|
clone() {
|
|
507
498
|
return this;
|
|
508
499
|
}
|
|
509
|
-
/* v8 ignore next 4 */
|
|
510
500
|
/** @ignore */
|
|
501
|
+
/* v8 ignore next */
|
|
511
502
|
[inspect.custom]() {
|
|
512
503
|
return `[${this.constructor.name}]`;
|
|
513
504
|
}
|
|
@@ -113,7 +113,7 @@ export class EntitySerializer {
|
|
|
113
113
|
return ret;
|
|
114
114
|
}
|
|
115
115
|
static propertyName(meta, prop) {
|
|
116
|
-
/* v8 ignore next
|
|
116
|
+
/* v8 ignore next */
|
|
117
117
|
if (meta.properties[prop]?.serializedName) {
|
|
118
118
|
return meta.properties[prop].serializedName;
|
|
119
119
|
}
|
|
@@ -137,7 +137,7 @@ export class EntitySerializer {
|
|
|
137
137
|
}
|
|
138
138
|
return returnValue;
|
|
139
139
|
}
|
|
140
|
-
/* v8 ignore next
|
|
140
|
+
/* v8 ignore next */
|
|
141
141
|
if (!options.ignoreSerializers && serializer) {
|
|
142
142
|
return serializer(value);
|
|
143
143
|
}
|
|
@@ -150,7 +150,7 @@ export class EntitySerializer {
|
|
|
150
150
|
if (Utils.isScalarReference(value)) {
|
|
151
151
|
return value.unwrap();
|
|
152
152
|
}
|
|
153
|
-
/* v8 ignore next
|
|
153
|
+
/* v8 ignore next */
|
|
154
154
|
if (property?.kind === ReferenceKind.EMBEDDED) {
|
|
155
155
|
if (Array.isArray(value)) {
|
|
156
156
|
return value.map(item => helper(item).toJSON());
|
|
@@ -36,7 +36,7 @@ export class SerializationContext {
|
|
|
36
36
|
}
|
|
37
37
|
leave(entityName, prop) {
|
|
38
38
|
const last = this.path.pop();
|
|
39
|
-
/* v8 ignore next
|
|
39
|
+
/* v8 ignore next */
|
|
40
40
|
if (last?.[0] !== entityName || last[1] !== prop) {
|
|
41
41
|
throw new Error(`Trying to leave wrong property: ${entityName}.${prop} instead of ${last?.join('.')}`);
|
|
42
42
|
}
|
|
@@ -98,7 +98,7 @@ export class SerializationContext {
|
|
|
98
98
|
}
|
|
99
99
|
let fields = [...this.fields];
|
|
100
100
|
for (const segment of this.path) {
|
|
101
|
-
/* v8 ignore next
|
|
101
|
+
/* v8 ignore next */
|
|
102
102
|
if (fields.length === 0) {
|
|
103
103
|
return true;
|
|
104
104
|
}
|
package/types/ArrayType.js
CHANGED
package/types/BigIntType.js
CHANGED
package/types/DecimalType.js
CHANGED
|
@@ -8,7 +8,7 @@ export class DecimalType extends Type {
|
|
|
8
8
|
super();
|
|
9
9
|
this.mode = mode;
|
|
10
10
|
}
|
|
11
|
-
/* v8 ignore next
|
|
11
|
+
/* v8 ignore next */
|
|
12
12
|
convertToJSValue(value) {
|
|
13
13
|
if ((this.mode ?? this.prop?.runtimeType) === 'number') {
|
|
14
14
|
return +value;
|
|
@@ -19,7 +19,7 @@ export class DecimalType extends Type {
|
|
|
19
19
|
return this.format(a) === this.format(b);
|
|
20
20
|
}
|
|
21
21
|
format(val) {
|
|
22
|
-
/* v8 ignore next
|
|
22
|
+
/* v8 ignore next */
|
|
23
23
|
if (this.prop?.scale == null) {
|
|
24
24
|
return +val;
|
|
25
25
|
}
|
package/types/DoubleType.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Type } from './Type.js';
|
|
|
3
3
|
* Type that maps an SQL DOUBLE to a JS string or number.
|
|
4
4
|
*/
|
|
5
5
|
export class DoubleType extends Type {
|
|
6
|
-
/* v8 ignore next
|
|
6
|
+
/* v8 ignore next */
|
|
7
7
|
convertToJSValue(value) {
|
|
8
8
|
if (this.prop?.runtimeType === 'number') {
|
|
9
9
|
return +value;
|
package/types/TinyIntType.js
CHANGED
package/types/Uint8ArrayType.js
CHANGED
package/typings.js
CHANGED
|
@@ -32,7 +32,7 @@ export class EntityMetadata {
|
|
|
32
32
|
}
|
|
33
33
|
this.properties[prop.name] = prop;
|
|
34
34
|
this.propertyOrder.set(prop.name, this.props.length);
|
|
35
|
-
/* v8 ignore next
|
|
35
|
+
/* v8 ignore next */
|
|
36
36
|
if (sync) {
|
|
37
37
|
this.sync();
|
|
38
38
|
}
|
|
@@ -40,7 +40,7 @@ export class EntityMetadata {
|
|
|
40
40
|
removeProperty(name, sync = true) {
|
|
41
41
|
delete this.properties[name];
|
|
42
42
|
this.propertyOrder.delete(name);
|
|
43
|
-
/* v8 ignore next
|
|
43
|
+
/* v8 ignore next */
|
|
44
44
|
if (sync) {
|
|
45
45
|
this.sync();
|
|
46
46
|
}
|
|
@@ -181,7 +181,7 @@ export class EntityMetadata {
|
|
|
181
181
|
this.indexes.push({ properties: prop.name });
|
|
182
182
|
prop.index = false;
|
|
183
183
|
}
|
|
184
|
-
/* v8 ignore next
|
|
184
|
+
/* v8 ignore next */
|
|
185
185
|
if (owner && prop.fieldNames.length > 1 && prop.unique) {
|
|
186
186
|
this.uniques.push({ properties: prop.name });
|
|
187
187
|
prop.unique = false;
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -35,10 +35,8 @@ declare const DEFAULTS: {
|
|
|
35
35
|
readonly checkNonPersistentCompositeProps: true;
|
|
36
36
|
readonly inferDefaultValues: true;
|
|
37
37
|
};
|
|
38
|
-
readonly strict: false;
|
|
39
|
-
readonly validate: false;
|
|
40
38
|
readonly validateRequired: true;
|
|
41
|
-
readonly context: (name: string) => EntityManager<IDatabaseDriver<import("
|
|
39
|
+
readonly context: (name: string) => EntityManager<IDatabaseDriver<import("@mikro-orm/knex").Connection>> | undefined;
|
|
42
40
|
readonly contextName: "default";
|
|
43
41
|
readonly allowGlobalContext: false;
|
|
44
42
|
readonly logger: (message?: any, ...optionalParams: any[]) => void;
|
package/utils/Configuration.js
CHANGED
|
@@ -26,8 +26,6 @@ const DEFAULTS = {
|
|
|
26
26
|
checkNonPersistentCompositeProps: true,
|
|
27
27
|
inferDefaultValues: true,
|
|
28
28
|
},
|
|
29
|
-
strict: false,
|
|
30
|
-
validate: false,
|
|
31
29
|
validateRequired: true,
|
|
32
30
|
context: (name) => RequestContext.getEntityManager(name),
|
|
33
31
|
contextName: 'default',
|
|
@@ -226,7 +224,7 @@ export class Configuration {
|
|
|
226
224
|
return this.cache.get(name);
|
|
227
225
|
}
|
|
228
226
|
const ext = this.extensions.get(name);
|
|
229
|
-
/* v8 ignore next
|
|
227
|
+
/* v8 ignore next */
|
|
230
228
|
if (!ext) {
|
|
231
229
|
return undefined;
|
|
232
230
|
}
|
|
@@ -369,7 +367,7 @@ export class Configuration {
|
|
|
369
367
|
}
|
|
370
368
|
}
|
|
371
369
|
validateOptions() {
|
|
372
|
-
/* v8 ignore next
|
|
370
|
+
/* v8 ignore next */
|
|
373
371
|
if ('type' in this.options) {
|
|
374
372
|
throw new Error('The `type` option has been removed in v6, please fill in the `driver` option instead or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from \'@mikro-orm/mysql\'; export default defineConfig({ ... })`).');
|
|
375
373
|
}
|
|
@@ -6,8 +6,8 @@ import { type Options } from './Configuration.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ConfigurationLoader {
|
|
8
8
|
static loadEnvironmentVars<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
9
|
-
static getPackageConfig(basePath?: string):
|
|
10
|
-
static getORMPackages(): Set<string
|
|
9
|
+
static getPackageConfig<T extends Dictionary>(basePath?: string): Promise<T>;
|
|
10
|
+
static getORMPackages(): Promise<Set<string>>;
|
|
11
11
|
static getORMPackageVersion(name: string): string | undefined;
|
|
12
|
-
static checkPackageVersion(): string
|
|
12
|
+
static checkPackageVersion(): Promise<string>;
|
|
13
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import { Utils } from './Utils.js';
|
|
3
4
|
import { colors } from '../logging/colors.js';
|
|
4
5
|
/**
|
|
@@ -92,13 +93,13 @@ export class ConfigurationLoader {
|
|
|
92
93
|
cleanup(ret, 'seeder');
|
|
93
94
|
return ret;
|
|
94
95
|
}
|
|
95
|
-
static getPackageConfig(basePath = process.cwd()) {
|
|
96
|
+
static async getPackageConfig(basePath = process.cwd()) {
|
|
96
97
|
if (Utils.pathExists(`${basePath}/package.json`)) {
|
|
97
|
-
/* v8 ignore next 5 */
|
|
98
98
|
try {
|
|
99
|
-
return Utils.
|
|
99
|
+
return await Utils.dynamicImport(`${basePath}/package.json`);
|
|
100
100
|
}
|
|
101
|
-
catch {
|
|
101
|
+
catch (e) {
|
|
102
|
+
/* v8 ignore next */
|
|
102
103
|
return {};
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -109,8 +110,8 @@ export class ConfigurationLoader {
|
|
|
109
110
|
}
|
|
110
111
|
return this.getPackageConfig(parentFolder);
|
|
111
112
|
}
|
|
112
|
-
static getORMPackages() {
|
|
113
|
-
const pkg = this.getPackageConfig();
|
|
113
|
+
static async getORMPackages() {
|
|
114
|
+
const pkg = await this.getPackageConfig();
|
|
114
115
|
return new Set([
|
|
115
116
|
...Object.keys(pkg.dependencies ?? {}),
|
|
116
117
|
...Object.keys(pkg.devDependencies ?? {}),
|
|
@@ -118,7 +119,8 @@ export class ConfigurationLoader {
|
|
|
118
119
|
}
|
|
119
120
|
static getORMPackageVersion(name) {
|
|
120
121
|
try {
|
|
121
|
-
const
|
|
122
|
+
const path = import.meta.resolve(`${name}/package.json`);
|
|
123
|
+
const pkg = Utils.readJSONSync(fileURLToPath(path));
|
|
122
124
|
/* v8 ignore next */
|
|
123
125
|
return pkg?.version;
|
|
124
126
|
}
|
|
@@ -127,12 +129,12 @@ export class ConfigurationLoader {
|
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
130
|
-
static checkPackageVersion() {
|
|
132
|
+
static async checkPackageVersion() {
|
|
131
133
|
const coreVersion = Utils.getORMVersion();
|
|
132
134
|
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === 'N/A') {
|
|
133
135
|
return coreVersion;
|
|
134
136
|
}
|
|
135
|
-
const deps = this.getORMPackages();
|
|
137
|
+
const deps = await this.getORMPackages();
|
|
136
138
|
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
137
139
|
const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
|
|
138
140
|
for (const ormPackage of ormPackages) {
|
package/utils/Cursor.js
CHANGED
|
@@ -162,8 +162,8 @@ export class Cursor {
|
|
|
162
162
|
return ret;
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
/* v8 ignore start */
|
|
166
165
|
/** @ignore */
|
|
166
|
+
/* v8 ignore next */
|
|
167
167
|
[inspect.custom]() {
|
|
168
168
|
const type = this.items[0]?.constructor.name;
|
|
169
169
|
const { items, startCursor, endCursor, hasPrevPage, hasNextPage, totalCount, length } = this;
|
package/utils/DataloaderUtils.js
CHANGED
|
@@ -168,7 +168,7 @@ export class DataloaderUtils {
|
|
|
168
168
|
const entities = resultsMap.get(key);
|
|
169
169
|
if (entities == null) {
|
|
170
170
|
// Should never happen
|
|
171
|
-
/* v8 ignore next
|
|
171
|
+
/* v8 ignore next */
|
|
172
172
|
throw new Error('Cannot match results');
|
|
173
173
|
}
|
|
174
174
|
return entities.filter(DataloaderUtils.getColFilter(col));
|
|
@@ -221,7 +221,7 @@ export class DataloaderUtils {
|
|
|
221
221
|
return (this.DataLoader ??= DataLoader);
|
|
222
222
|
}
|
|
223
223
|
catch {
|
|
224
|
-
/* v8 ignore next
|
|
224
|
+
/* v8 ignore next */
|
|
225
225
|
throw new Error('DataLoader is not found, make sure `dataloader` package is installed in your project\'s dependencies.');
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -48,7 +48,7 @@ export class EntityComparator {
|
|
|
48
48
|
*/
|
|
49
49
|
getPkGetter(meta) {
|
|
50
50
|
const exists = this.pkGetters.get(meta.className);
|
|
51
|
-
/* v8 ignore next
|
|
51
|
+
/* v8 ignore next */
|
|
52
52
|
if (exists) {
|
|
53
53
|
return exists;
|
|
54
54
|
}
|
|
@@ -98,7 +98,7 @@ export class EntityComparator {
|
|
|
98
98
|
*/
|
|
99
99
|
getPkGetterConverted(meta) {
|
|
100
100
|
const exists = this.pkGettersConverted.get(meta.className);
|
|
101
|
-
/* v8 ignore next
|
|
101
|
+
/* v8 ignore next */
|
|
102
102
|
if (exists) {
|
|
103
103
|
return exists;
|
|
104
104
|
}
|
|
@@ -148,7 +148,7 @@ export class EntityComparator {
|
|
|
148
148
|
*/
|
|
149
149
|
getPkSerializer(meta) {
|
|
150
150
|
const exists = this.pkSerializers.get(meta.className);
|
|
151
|
-
/* v8 ignore next
|
|
151
|
+
/* v8 ignore next */
|
|
152
152
|
if (exists) {
|
|
153
153
|
return exists;
|
|
154
154
|
}
|
|
@@ -477,7 +477,7 @@ export class EntityComparator {
|
|
|
477
477
|
registerCustomType(prop, context) {
|
|
478
478
|
const convertorKey = this.safeKey(prop.name);
|
|
479
479
|
context.set(`convertToDatabaseValue_${convertorKey}`, (val) => {
|
|
480
|
-
/* v8 ignore next
|
|
480
|
+
/* v8 ignore next */
|
|
481
481
|
if (RawQueryFragment.isKnownFragment(val)) {
|
|
482
482
|
return val;
|
|
483
483
|
}
|
package/utils/QueryHelper.js
CHANGED
package/utils/Utils.d.ts
CHANGED
|
@@ -162,12 +162,6 @@ export declare class Utils {
|
|
|
162
162
|
static flatten<T>(arrays: T[][]): T[];
|
|
163
163
|
static isOperator(key: PropertyKey, includeGroupOperators?: boolean): boolean;
|
|
164
164
|
static hasNestedKey(object: unknown, key: string): boolean;
|
|
165
|
-
/**
|
|
166
|
-
* Require a module from a specific location
|
|
167
|
-
* @param id The module to require
|
|
168
|
-
* @param [from] Location to start the node resolution
|
|
169
|
-
*/
|
|
170
|
-
static requireFrom<T extends Dictionary>(id: string, from?: string): T;
|
|
171
165
|
static dynamicImport<T = any>(id: string): Promise<T>;
|
|
172
166
|
static ensureDir(path: string): void;
|
|
173
167
|
static readJSONSync(path: string): Dictionary;
|
|
@@ -176,12 +170,6 @@ export declare class Utils {
|
|
|
176
170
|
static callCompiledFunction<T extends unknown[], R>(fn: (...args: T) => R, ...args: T): R;
|
|
177
171
|
static unwrapProperty<T>(entity: T, meta: EntityMetadata<T>, prop: EntityProperty<T>, payload?: boolean): [unknown, number[]][];
|
|
178
172
|
static setPayloadProperty<T>(entity: EntityDictionary<T>, meta: EntityMetadata<T>, prop: EntityProperty<T>, value: unknown, idx: number[]): void;
|
|
179
|
-
static tryRequire<T extends Dictionary = any>({ module, from, allowError, warning }: {
|
|
180
|
-
module: string;
|
|
181
|
-
warning?: string;
|
|
182
|
-
from?: string;
|
|
183
|
-
allowError?: string;
|
|
184
|
-
}): T | undefined;
|
|
185
173
|
static tryImport<T extends Dictionary = any>({ module, warning }: {
|
|
186
174
|
module: string;
|
|
187
175
|
warning?: string;
|
package/utils/Utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
|
|
1
|
+
import { isAbsolute, join, normalize, relative } from 'node:path';
|
|
3
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
3
|
import { existsSync, globSync, statSync, mkdirSync, readFileSync } from 'node:fs';
|
|
5
4
|
import { clone } from './clone.js';
|
|
@@ -36,7 +35,7 @@ export function compareObjects(a, b) {
|
|
|
36
35
|
}
|
|
37
36
|
return timeA === timeB;
|
|
38
37
|
}
|
|
39
|
-
/* v8 ignore next
|
|
38
|
+
/* v8 ignore next */
|
|
40
39
|
if ((typeof a === 'function' && typeof b === 'function') ||
|
|
41
40
|
(typeof a === 'object' && a.client && ['Ref', 'Raw'].includes(a.constructor.name) && typeof b === 'object' && b.client && ['Ref', 'Raw'].includes(b.constructor.name)) || // knex qb
|
|
42
41
|
(a instanceof RegExp && b instanceof RegExp) ||
|
|
@@ -114,7 +113,7 @@ export function equals(a, b) {
|
|
|
114
113
|
const equalsFn = equals;
|
|
115
114
|
export function parseJsonSafe(value) {
|
|
116
115
|
if (typeof value === 'string') {
|
|
117
|
-
/* v8 ignore next
|
|
116
|
+
/* v8 ignore next */
|
|
118
117
|
try {
|
|
119
118
|
return JSON.parse(value);
|
|
120
119
|
}
|
|
@@ -227,7 +226,7 @@ export class Utils {
|
|
|
227
226
|
target[key] = Utils.copy(value);
|
|
228
227
|
continue;
|
|
229
228
|
}
|
|
230
|
-
/* v8 ignore next
|
|
229
|
+
/* v8 ignore next */
|
|
231
230
|
if (!(key in target)) {
|
|
232
231
|
Object.assign(target, { [key]: {} });
|
|
233
232
|
}
|
|
@@ -393,7 +392,7 @@ export class Utils {
|
|
|
393
392
|
return key.split(this.PK_SEPARATOR);
|
|
394
393
|
}
|
|
395
394
|
static getPrimaryKeyValues(entity, meta, allowScalar = false, convertCustomTypes = false) {
|
|
396
|
-
/* v8 ignore next
|
|
395
|
+
/* v8 ignore next */
|
|
397
396
|
if (entity == null) {
|
|
398
397
|
return entity;
|
|
399
398
|
}
|
|
@@ -538,7 +537,7 @@ export class Utils {
|
|
|
538
537
|
* Tries to detect TypeScript support.
|
|
539
538
|
*/
|
|
540
539
|
static detectTypeScriptSupport() {
|
|
541
|
-
/* v8 ignore next
|
|
540
|
+
/* v8 ignore next */
|
|
542
541
|
return process.argv[0].endsWith('ts-node') // running via ts-node directly
|
|
543
542
|
|| !!process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
|
|
544
543
|
|| !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)
|
|
@@ -751,17 +750,6 @@ export class Utils {
|
|
|
751
750
|
}
|
|
752
751
|
return false;
|
|
753
752
|
}
|
|
754
|
-
/**
|
|
755
|
-
* Require a module from a specific location
|
|
756
|
-
* @param id The module to require
|
|
757
|
-
* @param [from] Location to start the node resolution
|
|
758
|
-
*/
|
|
759
|
-
static requireFrom(id, from = process.cwd()) {
|
|
760
|
-
if (!extname(from)) {
|
|
761
|
-
from = join(from, '__fake.js');
|
|
762
|
-
}
|
|
763
|
-
return createRequire(resolve(from))(id);
|
|
764
|
-
}
|
|
765
753
|
static async dynamicImport(id) {
|
|
766
754
|
/* v8 ignore next */
|
|
767
755
|
const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
|
|
@@ -777,25 +765,12 @@ export class Utils {
|
|
|
777
765
|
return JSON.parse(file.toString());
|
|
778
766
|
}
|
|
779
767
|
static getORMVersion() {
|
|
780
|
-
|
|
781
|
-
// this works during development where we have `src` folder
|
|
782
|
-
return this.requireFrom('../../package.json', import.meta.dirname).version;
|
|
783
|
-
/* v8 ignore next 5 */
|
|
784
|
-
}
|
|
785
|
-
catch {
|
|
786
|
-
try {
|
|
787
|
-
// this works in production build where we do not have the `src` folder
|
|
788
|
-
return this.requireFrom('../package.json', import.meta.dirname).version;
|
|
789
|
-
}
|
|
790
|
-
catch {
|
|
791
|
-
return 'N/A';
|
|
792
|
-
}
|
|
793
|
-
}
|
|
768
|
+
return '6.6.1';
|
|
794
769
|
}
|
|
795
770
|
static createFunction(context, code) {
|
|
796
771
|
try {
|
|
797
772
|
return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
|
|
798
|
-
/* v8 ignore next
|
|
773
|
+
/* v8 ignore next */
|
|
799
774
|
}
|
|
800
775
|
catch (e) {
|
|
801
776
|
// eslint-disable-next-line no-console
|
|
@@ -808,7 +783,7 @@ export class Utils {
|
|
|
808
783
|
return fn(...args);
|
|
809
784
|
}
|
|
810
785
|
catch (e) {
|
|
811
|
-
/* v8 ignore
|
|
786
|
+
/* v8 ignore next */
|
|
812
787
|
if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
|
|
813
788
|
const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
|
|
814
789
|
let code = fn.toString();
|
|
@@ -825,7 +800,6 @@ export class Utils {
|
|
|
825
800
|
// eslint-disable-next-line no-console
|
|
826
801
|
console.error(`JIT runtime error: ${e.message}\n\n${code}`);
|
|
827
802
|
}
|
|
828
|
-
/* v8 ignore stop */
|
|
829
803
|
throw e;
|
|
830
804
|
}
|
|
831
805
|
}
|
|
@@ -908,23 +882,6 @@ export class Utils {
|
|
|
908
882
|
}
|
|
909
883
|
}
|
|
910
884
|
}
|
|
911
|
-
static tryRequire({ module, from, allowError, warning }) {
|
|
912
|
-
allowError ??= `Cannot find module '${module}'`;
|
|
913
|
-
from ??= process.cwd();
|
|
914
|
-
try {
|
|
915
|
-
return Utils.requireFrom(module, from);
|
|
916
|
-
}
|
|
917
|
-
catch (err) {
|
|
918
|
-
if (err.message.includes(allowError)) {
|
|
919
|
-
if (warning) {
|
|
920
|
-
// eslint-disable-next-line no-console
|
|
921
|
-
console.warn(warning);
|
|
922
|
-
}
|
|
923
|
-
return undefined;
|
|
924
|
-
}
|
|
925
|
-
throw err;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
885
|
static async tryImport({ module, warning }) {
|
|
929
886
|
try {
|
|
930
887
|
return await import(module);
|
package/utils/clone.js
CHANGED
|
@@ -126,7 +126,7 @@ export function clone(parent, respectCustomCloneMethod = true) {
|
|
|
126
126
|
for (let i = 0; i < symbols.length; i++) {
|
|
127
127
|
const symbol = symbols[i];
|
|
128
128
|
const descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
|
|
129
|
-
/* v8 ignore next
|
|
129
|
+
/* v8 ignore next */
|
|
130
130
|
if (descriptor && !descriptor.enumerable) {
|
|
131
131
|
continue;
|
|
132
132
|
}
|
package/utils/upsert-utils.js
CHANGED
|
@@ -5,7 +5,7 @@ function expandEmbeddedProperties(prop, key) {
|
|
|
5
5
|
return [prop.name];
|
|
6
6
|
}
|
|
7
7
|
return Object.values(prop.embeddedProps).flatMap(p => {
|
|
8
|
-
/* v8 ignore next
|
|
8
|
+
/* v8 ignore next */
|
|
9
9
|
if (p.embeddable && !p.object) {
|
|
10
10
|
return expandEmbeddedProperties(p);
|
|
11
11
|
}
|
|
@@ -44,7 +44,7 @@ export function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
|
44
44
|
const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
|
|
45
45
|
return onConflictMergeFields.flatMap(f => {
|
|
46
46
|
const prop = meta?.properties[f];
|
|
47
|
-
/* v8 ignore next
|
|
47
|
+
/* v8 ignore next */
|
|
48
48
|
if (prop?.embeddable && !prop.object) {
|
|
49
49
|
return Object.values(prop.embeddedProps).map(p => p.name);
|
|
50
50
|
}
|
|
@@ -69,7 +69,7 @@ export function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
|
69
69
|
}
|
|
70
70
|
/** @internal */
|
|
71
71
|
export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
|
|
72
|
-
/* v8 ignore next
|
|
72
|
+
/* v8 ignore next */
|
|
73
73
|
if (!meta) {
|
|
74
74
|
return '*';
|
|
75
75
|
}
|