@mikro-orm/core 7.0.0-rc.2 → 7.0.0
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 +4 -16
- package/EntityManager.js +248 -181
- package/MikroORM.d.ts +4 -6
- package/MikroORM.js +24 -24
- package/README.md +5 -4
- package/cache/FileCacheAdapter.d.ts +1 -5
- package/cache/FileCacheAdapter.js +22 -24
- package/cache/GeneratedCacheAdapter.d.ts +1 -1
- package/cache/GeneratedCacheAdapter.js +6 -6
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +1 -0
- package/connections/Connection.js +43 -14
- package/drivers/DatabaseDriver.d.ts +0 -2
- package/drivers/DatabaseDriver.js +28 -12
- package/drivers/IDatabaseDriver.d.ts +43 -0
- package/entity/Collection.d.ts +1 -9
- package/entity/Collection.js +124 -108
- package/entity/EntityAssigner.js +23 -11
- package/entity/EntityFactory.d.ts +1 -8
- package/entity/EntityFactory.js +79 -59
- package/entity/EntityHelper.js +25 -16
- package/entity/EntityLoader.d.ts +1 -3
- package/entity/EntityLoader.js +90 -60
- package/entity/Reference.d.ts +2 -3
- package/entity/Reference.js +48 -19
- package/entity/WrappedEntity.d.ts +4 -2
- package/entity/WrappedEntity.js +5 -1
- package/entity/defineEntity.d.ts +42 -85
- package/entity/utils.js +28 -26
- package/entity/validators.js +2 -1
- package/enums.d.ts +2 -1
- package/enums.js +13 -17
- package/errors.d.ts +11 -11
- package/errors.js +8 -8
- package/events/EventManager.d.ts +1 -4
- package/events/EventManager.js +26 -23
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/ObjectHydrator.d.ts +1 -2
- package/hydration/ObjectHydrator.js +41 -27
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/logging/DefaultLogger.js +6 -7
- package/logging/Logger.d.ts +2 -1
- package/logging/colors.js +2 -5
- package/logging/index.d.ts +1 -1
- package/logging/index.js +0 -1
- package/metadata/EntitySchema.d.ts +3 -3
- package/metadata/EntitySchema.js +12 -2
- package/metadata/MetadataDiscovery.d.ts +1 -9
- package/metadata/MetadataDiscovery.js +251 -179
- package/metadata/MetadataProvider.js +26 -1
- package/metadata/MetadataStorage.d.ts +1 -5
- package/metadata/MetadataStorage.js +37 -39
- package/metadata/MetadataValidator.js +20 -5
- package/metadata/discover-entities.js +1 -1
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +6 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.js +5 -1
- package/package.json +38 -38
- package/platforms/Platform.d.ts +24 -1
- package/platforms/Platform.js +106 -27
- package/serialization/EntitySerializer.js +8 -4
- package/serialization/EntityTransformer.js +4 -1
- package/serialization/SerializationContext.d.ts +4 -8
- package/serialization/SerializationContext.js +21 -16
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +2 -1
- package/typings.d.ts +35 -24
- package/typings.js +9 -9
- package/unit-of-work/ChangeSet.js +4 -4
- package/unit-of-work/ChangeSetComputer.d.ts +1 -6
- package/unit-of-work/ChangeSetComputer.js +29 -27
- package/unit-of-work/ChangeSetPersister.d.ts +1 -9
- package/unit-of-work/ChangeSetPersister.js +63 -58
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +2 -5
- package/unit-of-work/IdentityMap.js +18 -18
- package/unit-of-work/UnitOfWork.d.ts +12 -20
- package/unit-of-work/UnitOfWork.js +228 -191
- package/utils/AbstractMigrator.d.ts +2 -2
- package/utils/AbstractMigrator.js +10 -12
- package/utils/AbstractSchemaGenerator.js +2 -1
- package/utils/AsyncContext.js +1 -1
- package/utils/Configuration.d.ts +90 -189
- package/utils/Configuration.js +97 -77
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +8 -6
- package/utils/DataloaderUtils.js +15 -12
- package/utils/EntityComparator.d.ts +8 -15
- package/utils/EntityComparator.js +100 -92
- package/utils/QueryHelper.d.ts +16 -1
- package/utils/QueryHelper.js +108 -50
- package/utils/RawQueryFragment.d.ts +4 -4
- package/utils/RawQueryFragment.js +3 -2
- package/utils/TransactionManager.js +3 -3
- package/utils/Utils.d.ts +2 -2
- package/utils/Utils.js +39 -32
- package/utils/clone.js +5 -0
- package/utils/env-vars.js +6 -5
- package/utils/fs-utils.d.ts +3 -17
- package/utils/fs-utils.js +2 -5
- package/utils/upsert-utils.js +7 -4
|
@@ -7,13 +7,13 @@ import { ReferenceKind } from '../enums.js';
|
|
|
7
7
|
import { Raw } from '../utils/RawQueryFragment.js';
|
|
8
8
|
import { ValidationError } from '../errors.js';
|
|
9
9
|
export class ObjectHydrator extends Hydrator {
|
|
10
|
-
hydrators = {
|
|
10
|
+
#hydrators = {
|
|
11
11
|
'full~true': new Map(),
|
|
12
12
|
'full~false': new Map(),
|
|
13
13
|
'reference~true': new Map(),
|
|
14
14
|
'reference~false': new Map(),
|
|
15
15
|
};
|
|
16
|
-
tmpIndex = 0;
|
|
16
|
+
#tmpIndex = 0;
|
|
17
17
|
/**
|
|
18
18
|
* @inheritDoc
|
|
19
19
|
*/
|
|
@@ -41,7 +41,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
41
41
|
*/
|
|
42
42
|
getEntityHydrator(meta, type, normalizeAccessors = false) {
|
|
43
43
|
const key = `${type}~${normalizeAccessors}`;
|
|
44
|
-
const exists = this
|
|
44
|
+
const exists = this.#hydrators[key].get(meta.class);
|
|
45
45
|
if (exists) {
|
|
46
46
|
return exists;
|
|
47
47
|
}
|
|
@@ -66,9 +66,12 @@ export class ObjectHydrator extends Hydrator {
|
|
|
66
66
|
const hydrateScalar = (prop, path, dataKey) => {
|
|
67
67
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
68
68
|
const tz = this.platform.getTimezone();
|
|
69
|
-
const convertorKey = path
|
|
69
|
+
const convertorKey = path
|
|
70
|
+
.filter(k => !/\[idx_\d+]/.exec(k))
|
|
71
|
+
.map(k => this.safeKey(k))
|
|
72
|
+
.join('_');
|
|
70
73
|
const ret = [];
|
|
71
|
-
const idx = this
|
|
74
|
+
const idx = this.#tmpIndex++;
|
|
72
75
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
73
76
|
if (prop.getter && !prop.setter && prop.persist === false) {
|
|
74
77
|
return [];
|
|
@@ -139,13 +142,15 @@ export class ObjectHydrator extends Hydrator {
|
|
|
139
142
|
ret.push(` if (data${dataKey} === null) {\n entity${entityKey} = ${nullVal};`);
|
|
140
143
|
ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
|
|
141
144
|
// For polymorphic: instanceof check; for regular: isPrimaryKey() check
|
|
142
|
-
const pkCheck = prop.polymorphic
|
|
145
|
+
const pkCheck = prop.polymorphic
|
|
146
|
+
? `data${dataKey} instanceof PolymorphicRef`
|
|
147
|
+
: `isPrimaryKey(data${dataKey}, true)`;
|
|
143
148
|
ret.push(` if (${pkCheck}) {`);
|
|
144
149
|
// When targetKey is set, pass the key option to createReference so it uses the alternate key
|
|
145
150
|
const keyOption = prop.targetKey ? `, key: '${prop.targetKey}'` : '';
|
|
146
151
|
if (prop.polymorphic) {
|
|
147
152
|
// For polymorphic: target class from discriminator map, PK from data.id
|
|
148
|
-
const discriminatorMapKey = this.safeKey(`discriminatorMap_${prop.name}_${this
|
|
153
|
+
const discriminatorMapKey = this.safeKey(`discriminatorMap_${prop.name}_${this.#tmpIndex++}`);
|
|
149
154
|
context.set(discriminatorMapKey, prop.discriminatorMap);
|
|
150
155
|
ret.push(` const targetClass = ${discriminatorMapKey}[data${dataKey}.discriminator];`);
|
|
151
156
|
ret.push(` if (!targetClass) throw new ValidationError(\`Unknown discriminator value '\${data${dataKey}.discriminator}' for polymorphic relation '${prop.name}'. Valid values: \${Object.keys(${discriminatorMapKey}).join(', ')}\`);`);
|
|
@@ -158,7 +163,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
158
163
|
}
|
|
159
164
|
else {
|
|
160
165
|
// For regular: fixed target class, PK is the data itself
|
|
161
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
166
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
162
167
|
context.set(targetKey, prop.targetMeta.class);
|
|
163
168
|
if (prop.ref) {
|
|
164
169
|
ret.push(` entity${entityKey} = Reference.create(factory.createReference(${targetKey}, data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema${keyOption} }));`);
|
|
@@ -174,7 +179,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
174
179
|
hydrateTargetExpr = `data${dataKey}.constructor`;
|
|
175
180
|
}
|
|
176
181
|
else {
|
|
177
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
182
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
178
183
|
context.set(targetKey, prop.targetMeta.class);
|
|
179
184
|
hydrateTargetExpr = targetKey;
|
|
180
185
|
}
|
|
@@ -232,7 +237,10 @@ export class ObjectHydrator extends Hydrator {
|
|
|
232
237
|
return ret;
|
|
233
238
|
};
|
|
234
239
|
const registerEmbeddedPrototype = (prop, path) => {
|
|
235
|
-
const convertorKey = path
|
|
240
|
+
const convertorKey = path
|
|
241
|
+
.filter(k => !/\[idx_\d+]/.exec(k))
|
|
242
|
+
.map(k => this.safeKey(k))
|
|
243
|
+
.join('_');
|
|
236
244
|
if (prop.targetMeta?.polymorphs) {
|
|
237
245
|
prop.targetMeta.polymorphs.forEach(meta => {
|
|
238
246
|
context.set(`prototype_${convertorKey}_${meta.className}`, meta.prototype);
|
|
@@ -279,7 +287,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
279
287
|
else {
|
|
280
288
|
ret.push(` const embeddedData = {`);
|
|
281
289
|
for (const childProp of Object.values(prop.embeddedProps)) {
|
|
282
|
-
const key = childProp.embedded[1]
|
|
290
|
+
const key = /^\w+$/.exec(childProp.embedded[1]) ? childProp.embedded[1] : `'${childProp.embedded[1]}'`;
|
|
283
291
|
ret.push(` ${key}: data${this.wrap(childProp.name)},`);
|
|
284
292
|
}
|
|
285
293
|
ret.push(` };`);
|
|
@@ -297,7 +305,9 @@ export class ObjectHydrator extends Hydrator {
|
|
|
297
305
|
meta.props
|
|
298
306
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
299
307
|
.forEach(childProp => {
|
|
300
|
-
const childDataKey = prop.object
|
|
308
|
+
const childDataKey = prop.object
|
|
309
|
+
? dataKey + this.wrap(childProp.embedded[1])
|
|
310
|
+
: this.wrap(childProp.name);
|
|
301
311
|
const prop2 = childMeta.properties[childProp.embedded[1]];
|
|
302
312
|
const prop3 = {
|
|
303
313
|
...prop2,
|
|
@@ -305,14 +315,15 @@ export class ObjectHydrator extends Hydrator {
|
|
|
305
315
|
embedded: childProp.embedded,
|
|
306
316
|
embeddedProps: childProp.embeddedProps,
|
|
307
317
|
};
|
|
308
|
-
|
|
309
|
-
|
|
318
|
+
ret.push(
|
|
319
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define, no-use-before-define
|
|
320
|
+
...hydrateProperty(prop3, childProp.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
|
|
310
321
|
});
|
|
311
322
|
ret.push(` }`);
|
|
312
323
|
});
|
|
313
324
|
}
|
|
314
325
|
else {
|
|
315
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
326
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
316
327
|
context.set(targetKey, prop.targetMeta.class);
|
|
317
328
|
ret.push(` if (entity${entityKey} == null) {`);
|
|
318
329
|
ret.push(` entity${entityKey} = factory.createEmbeddable(${targetKey}, embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
|
|
@@ -321,8 +332,9 @@ export class ObjectHydrator extends Hydrator {
|
|
|
321
332
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
322
333
|
.forEach(childProp => {
|
|
323
334
|
const childDataKey = prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
|
|
324
|
-
|
|
325
|
-
|
|
335
|
+
ret.push(
|
|
336
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define, no-use-before-define
|
|
337
|
+
...hydrateProperty(childProp, prop.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
|
|
326
338
|
});
|
|
327
339
|
}
|
|
328
340
|
/* v8 ignore next */
|
|
@@ -340,7 +352,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
340
352
|
const hydrateEmbeddedArray = (prop, path, dataKey) => {
|
|
341
353
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
342
354
|
const ret = [];
|
|
343
|
-
const idx = this
|
|
355
|
+
const idx = this.#tmpIndex++;
|
|
344
356
|
registerEmbeddedPrototype(prop, path);
|
|
345
357
|
parseObjectEmbeddable(prop, dataKey, ret);
|
|
346
358
|
ret.push(` if (Array.isArray(data${dataKey})) {`);
|
|
@@ -353,7 +365,8 @@ export class ObjectHydrator extends Hydrator {
|
|
|
353
365
|
};
|
|
354
366
|
const hydrateProperty = (prop, object = prop.object, path = [prop.name], dataKey) => {
|
|
355
367
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
356
|
-
dataKey =
|
|
368
|
+
dataKey =
|
|
369
|
+
dataKey ?? (object ? entityKey : this.wrap(normalizeAccessors ? (prop.accessor ?? prop.name) : prop.name));
|
|
357
370
|
const ret = [];
|
|
358
371
|
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.mapToPk) {
|
|
359
372
|
ret.push(...hydrateToOne(prop, dataKey, entityKey));
|
|
@@ -372,7 +385,8 @@ export class ObjectHydrator extends Hydrator {
|
|
|
372
385
|
}
|
|
373
386
|
}
|
|
374
387
|
}
|
|
375
|
-
else {
|
|
388
|
+
else {
|
|
389
|
+
// ReferenceKind.SCALAR
|
|
376
390
|
ret.push(...hydrateScalar(prop, path, dataKey));
|
|
377
391
|
}
|
|
378
392
|
if (this.config.get('forceUndefined')) {
|
|
@@ -383,12 +397,12 @@ export class ObjectHydrator extends Hydrator {
|
|
|
383
397
|
for (const prop of props) {
|
|
384
398
|
lines.push(...hydrateProperty(prop));
|
|
385
399
|
}
|
|
386
|
-
const code = `// compiled hydrator for entity ${meta.className} (${type + normalizeAccessors ? ' normalized' : ''})\n`
|
|
387
|
-
|
|
388
|
-
|
|
400
|
+
const code = `// compiled hydrator for entity ${meta.className} (${type + normalizeAccessors ? ' normalized' : ''})\n` +
|
|
401
|
+
`return function(entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors) {\n` +
|
|
402
|
+
`${lines.join('\n')}\n}`;
|
|
389
403
|
const fnKey = `hydrator-${meta.uniqueName}-${type}-${normalizeAccessors}`;
|
|
390
404
|
const hydrator = Utils.createFunction(context, code, this.config.get('compiledFunctions'), fnKey);
|
|
391
|
-
this
|
|
405
|
+
this.#hydrators[key].set(meta.class, hydrator);
|
|
392
406
|
return hydrator;
|
|
393
407
|
}
|
|
394
408
|
createCollectionItemMapper(prop, context) {
|
|
@@ -401,7 +415,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
401
415
|
lines.push(` value = { ...value, ['${prop2.name}']: Reference.wrapReference(entity, { ref: ${prop2.ref} }) };`);
|
|
402
416
|
lines.push(` }`);
|
|
403
417
|
}
|
|
404
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
418
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
405
419
|
context.set(targetKey, prop.targetMeta.class);
|
|
406
420
|
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference(${targetKey}, value, { convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
407
421
|
lines.push(` if (value && value.__entity) return value;`);
|
|
@@ -410,10 +424,10 @@ export class ObjectHydrator extends Hydrator {
|
|
|
410
424
|
return lines;
|
|
411
425
|
}
|
|
412
426
|
wrap(key) {
|
|
413
|
-
if (
|
|
427
|
+
if (/^\[.*]$/.exec(key)) {
|
|
414
428
|
return key;
|
|
415
429
|
}
|
|
416
|
-
return
|
|
430
|
+
return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
|
|
417
431
|
}
|
|
418
432
|
safeKey(key) {
|
|
419
433
|
return key.replace(/\W/g, '_');
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
|
|
6
6
|
export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, InferEntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, EntityDTOFlat, EntityDTOProp, SerializeDTO, MigrationDiff, GenerateOptions, FilterObject, IMigrationRunner, IEntityGenerator, ISeedManager, SeederObject, IMigratorStorage, RequiredEntityData, CheckCallback, IndexCallback, FormulaCallback, FormulaTable, SchemaTable, SchemaColumns, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, MigrationInfo, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, CheckConstraint, GeneratedColumnCallback, FilterDef, EntityCtor, Subquery, PopulateHintOptions, Prefixes, } from './typings.js';
|
|
7
7
|
export * from './enums.js';
|
|
8
8
|
export * from './errors.js';
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
|
|
6
6
|
export * from './enums.js';
|
|
7
7
|
export * from './errors.js';
|
|
8
8
|
export * from './exceptions.js';
|
package/logging/DefaultLogger.js
CHANGED
|
@@ -29,9 +29,7 @@ export class DefaultLogger {
|
|
|
29
29
|
if (context?.level === 'warning') {
|
|
30
30
|
message = colors.yellow(message);
|
|
31
31
|
}
|
|
32
|
-
const label = context?.label
|
|
33
|
-
? colors.cyan(`(${context.label}) `)
|
|
34
|
-
: '';
|
|
32
|
+
const label = context?.label ? colors.cyan(`(${context.label}) `) : '';
|
|
35
33
|
this.writer(colors.grey(`[${namespace}] `) + label + message);
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
@@ -60,8 +58,8 @@ export class DefaultLogger {
|
|
|
60
58
|
if (namespace === 'deprecated') {
|
|
61
59
|
const { ignoreDeprecations = false } = this.options;
|
|
62
60
|
return Array.isArray(ignoreDeprecations)
|
|
63
|
-
/* v8 ignore next */
|
|
64
|
-
|
|
61
|
+
? /* v8 ignore next */
|
|
62
|
+
!ignoreDeprecations.includes(context?.label ?? '')
|
|
65
63
|
: !ignoreDeprecations;
|
|
66
64
|
}
|
|
67
65
|
return !!debugMode && (!Array.isArray(debugMode) || debugMode.includes(namespace));
|
|
@@ -70,7 +68,8 @@ export class DefaultLogger {
|
|
|
70
68
|
* @inheritDoc
|
|
71
69
|
*/
|
|
72
70
|
logQuery(context) {
|
|
73
|
-
|
|
71
|
+
const namespace = context.namespace ?? 'query';
|
|
72
|
+
if (!this.isEnabled(namespace, context)) {
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
76
75
|
/* v8 ignore next */
|
|
@@ -88,7 +87,7 @@ export class DefaultLogger {
|
|
|
88
87
|
if (this.usesReplicas && context.connection) {
|
|
89
88
|
msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
|
|
90
89
|
}
|
|
91
|
-
return this.log(
|
|
90
|
+
return this.log(namespace, msg, context);
|
|
92
91
|
}
|
|
93
92
|
static create(options) {
|
|
94
93
|
return new DefaultLogger(options);
|
package/logging/Logger.d.ts
CHANGED
|
@@ -22,10 +22,11 @@ export interface Logger {
|
|
|
22
22
|
setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
|
|
23
23
|
isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
|
|
24
24
|
}
|
|
25
|
-
export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated';
|
|
25
|
+
export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated' | 'slow-query';
|
|
26
26
|
export interface LogContext extends Dictionary {
|
|
27
27
|
query?: string;
|
|
28
28
|
label?: string;
|
|
29
|
+
namespace?: LoggerNamespace;
|
|
29
30
|
params?: readonly unknown[];
|
|
30
31
|
took?: number;
|
|
31
32
|
results?: number;
|
package/logging/colors.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { getEnv } from '../utils/env-vars.js';
|
|
2
2
|
const bool = (k) => ['true', 't', '1'].includes(getEnv(k)?.toLowerCase() ?? '');
|
|
3
|
-
const boolIfDefined = (k) => getEnv(k) != null ? bool(k) : true;
|
|
4
|
-
const enabled = () => !bool('NO_COLOR')
|
|
5
|
-
&& !bool('MIKRO_ORM_NO_COLOR')
|
|
6
|
-
&& boolIfDefined('FORCE_COLOR')
|
|
7
|
-
&& boolIfDefined('MIKRO_ORM_COLORS');
|
|
3
|
+
const boolIfDefined = (k) => (getEnv(k) != null ? bool(k) : true);
|
|
4
|
+
const enabled = () => !bool('NO_COLOR') && !bool('MIKRO_ORM_NO_COLOR') && boolIfDefined('FORCE_COLOR') && boolIfDefined('MIKRO_ORM_COLORS');
|
|
8
5
|
const wrap = (fn) => (text) => enabled() ? fn(text) : text;
|
|
9
6
|
/** @internal */
|
|
10
7
|
export const colors = {
|
package/logging/index.d.ts
CHANGED
package/logging/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityMetadata, type AnyEntity, type EntityKey, type Constructor, type DeepPartial, type EntityName, type EntityProperty, type CleanKeys, type ExpandProperty, type IsNever, type EntityCtor } from '../typings.js';
|
|
2
2
|
import { type EventType, ReferenceKind } from '../enums.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { EventArgs } from '../events/EventSubscriber.js';
|
|
4
4
|
import { Type } from '../types/Type.js';
|
|
5
5
|
import type { PropertyOptions, ManyToOneOptions, OneToOneOptions, OneToManyOptions, ManyToManyOptions, EmbeddedOptions, EnumOptions, PrimaryKeyOptions, SerializedPrimaryKeyOptions, IndexOptions, UniqueOptions } from './types.js';
|
|
6
6
|
type TypeType = string | NumberConstructor | StringConstructor | BooleanConstructor | DateConstructor | ArrayConstructor | Constructor<Type<any>> | Type<any>;
|
|
@@ -47,7 +47,7 @@ export declare class EntitySchema<Entity = any, Base = never, Class extends Enti
|
|
|
47
47
|
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
48
48
|
* so we can use the class in `entities` option just like the EntitySchema instance.
|
|
49
49
|
*/
|
|
50
|
-
static REGISTRY: Map<
|
|
50
|
+
static REGISTRY: Map<AnyEntity, EntitySchema>;
|
|
51
51
|
/** @internal Type-level marker for fast entity type inference */
|
|
52
52
|
readonly '~entity': Entity;
|
|
53
53
|
private readonly _meta;
|
|
@@ -108,6 +108,6 @@ export declare class EntitySchema<Entity = any, Base = never, Class extends Enti
|
|
|
108
108
|
* });
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
addHook<
|
|
111
|
+
addHook<T extends Entity = Entity>(event: EventType | `${EventType}`, handler: (args: EventArgs<T>) => void | Promise<void>): this;
|
|
112
112
|
}
|
|
113
113
|
export {};
|
package/metadata/EntitySchema.js
CHANGED
|
@@ -34,7 +34,12 @@ export class EntitySchema {
|
|
|
34
34
|
}
|
|
35
35
|
addProperty(name, type, options = {}) {
|
|
36
36
|
this.renameCompositeOptions(name, options);
|
|
37
|
-
const prop = {
|
|
37
|
+
const prop = {
|
|
38
|
+
name,
|
|
39
|
+
kind: ReferenceKind.SCALAR,
|
|
40
|
+
...options,
|
|
41
|
+
...this.normalizeType(options, type),
|
|
42
|
+
};
|
|
38
43
|
if (type && Type.isMappedType(type.prototype)) {
|
|
39
44
|
prop.type = type;
|
|
40
45
|
}
|
|
@@ -299,7 +304,12 @@ export class EntitySchema {
|
|
|
299
304
|
}
|
|
300
305
|
else if (options.entity) {
|
|
301
306
|
const tmp = options.entity();
|
|
302
|
-
type = options.type = Array.isArray(tmp)
|
|
307
|
+
type = options.type = Array.isArray(tmp)
|
|
308
|
+
? tmp
|
|
309
|
+
.map(t => Utils.className(t))
|
|
310
|
+
.sort()
|
|
311
|
+
.join(' | ')
|
|
312
|
+
: Utils.className(tmp);
|
|
303
313
|
const target = tmp instanceof EntitySchema ? tmp.meta.class : tmp;
|
|
304
314
|
return { type, target };
|
|
305
315
|
}
|
|
@@ -4,15 +4,7 @@ import { MetadataStorage } from './MetadataStorage.js';
|
|
|
4
4
|
import { EntitySchema } from './EntitySchema.js';
|
|
5
5
|
import type { Platform } from '../platforms/Platform.js';
|
|
6
6
|
export declare class MetadataDiscovery {
|
|
7
|
-
private
|
|
8
|
-
private readonly platform;
|
|
9
|
-
private readonly config;
|
|
10
|
-
private readonly namingStrategy;
|
|
11
|
-
private readonly metadataProvider;
|
|
12
|
-
private readonly logger;
|
|
13
|
-
private readonly schemaHelper;
|
|
14
|
-
private readonly validator;
|
|
15
|
-
private readonly discovered;
|
|
7
|
+
#private;
|
|
16
8
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
17
9
|
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
18
10
|
discoverSync(): MetadataStorage;
|