@mikro-orm/core 7.0.0-rc.1 → 7.0.0-rc.3
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 +3 -2
- package/EntityManager.js +107 -43
- package/MikroORM.js +4 -4
- package/cache/FileCacheAdapter.js +1 -3
- package/connections/Connection.js +16 -3
- package/drivers/DatabaseDriver.js +26 -8
- package/drivers/IDatabaseDriver.d.ts +49 -1
- package/entity/BaseEntity.d.ts +3 -3
- package/entity/Collection.js +43 -17
- package/entity/EntityAssigner.js +23 -11
- package/entity/EntityFactory.js +36 -13
- package/entity/EntityHelper.js +27 -18
- package/entity/EntityLoader.d.ts +6 -6
- package/entity/EntityLoader.js +55 -22
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/Reference.d.ts +1 -1
- package/entity/Reference.js +37 -8
- package/entity/WrappedEntity.d.ts +3 -3
- package/entity/WrappedEntity.js +5 -1
- package/entity/defineEntity.d.ts +202 -58
- package/entity/defineEntity.js +20 -24
- package/entity/utils.js +28 -26
- package/entity/validators.js +2 -1
- package/enums.js +12 -17
- package/errors.js +18 -8
- package/events/EventManager.js +1 -1
- package/exceptions.js +7 -2
- package/hydration/ObjectHydrator.js +27 -13
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/logging/DefaultLogger.js +3 -5
- package/logging/colors.js +3 -6
- package/metadata/EntitySchema.d.ts +2 -2
- package/metadata/EntitySchema.js +12 -2
- package/metadata/MetadataDiscovery.js +107 -48
- package/metadata/MetadataProvider.js +26 -1
- package/metadata/MetadataStorage.js +2 -4
- package/metadata/MetadataValidator.js +20 -5
- package/metadata/types.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +5 -2
- package/not-supported.js +5 -1
- package/package.json +40 -37
- package/platforms/Platform.d.ts +4 -1
- package/platforms/Platform.js +50 -24
- package/serialization/EntitySerializer.d.ts +3 -3
- package/serialization/EntitySerializer.js +7 -3
- package/serialization/EntityTransformer.js +6 -4
- package/serialization/SerializationContext.js +1 -1
- package/typings.d.ts +73 -33
- package/typings.js +11 -9
- package/unit-of-work/ChangeSet.js +4 -4
- package/unit-of-work/ChangeSetComputer.js +8 -6
- package/unit-of-work/ChangeSetPersister.js +15 -10
- package/unit-of-work/CommitOrderCalculator.js +4 -2
- package/unit-of-work/UnitOfWork.d.ts +7 -1
- package/unit-of-work/UnitOfWork.js +51 -22
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.js +2 -1
- package/utils/AsyncContext.js +1 -1
- package/utils/Configuration.d.ts +3 -1
- package/utils/Configuration.js +8 -4
- package/utils/Cursor.js +4 -2
- package/utils/DataloaderUtils.js +15 -12
- package/utils/EntityComparator.js +51 -43
- package/utils/QueryHelper.js +38 -26
- package/utils/RawQueryFragment.js +3 -2
- package/utils/TransactionManager.js +2 -1
- package/utils/Utils.d.ts +1 -1
- package/utils/Utils.js +36 -30
- package/utils/env-vars.js +6 -5
- package/utils/fs-utils.d.ts +1 -0
- package/utils/fs-utils.js +6 -5
- package/utils/index.d.ts +0 -2
- package/utils/index.js +0 -2
- package/utils/upsert-utils.js +6 -3
package/entity/validators.js
CHANGED
|
@@ -52,7 +52,8 @@ export function validateParams(params, type = 'search condition', field) {
|
|
|
52
52
|
}
|
|
53
53
|
/** @internal */
|
|
54
54
|
export function validatePrimaryKey(entity, meta) {
|
|
55
|
-
const pkExists = meta.primaryKeys.every(pk => entity[pk] != null) ||
|
|
55
|
+
const pkExists = meta.primaryKeys.every(pk => entity[pk] != null) ||
|
|
56
|
+
(meta.serializedPrimaryKey && entity[meta.serializedPrimaryKey] != null);
|
|
56
57
|
if (!entity || !pkExists) {
|
|
57
58
|
throw ValidationError.fromMergeWithoutPK(meta);
|
|
58
59
|
}
|
package/enums.js
CHANGED
|
@@ -49,22 +49,8 @@ export var QueryOperator;
|
|
|
49
49
|
QueryOperator["$hasKeys"] = "?&";
|
|
50
50
|
QueryOperator["$hasSomeKeys"] = "?|";
|
|
51
51
|
})(QueryOperator || (QueryOperator = {}));
|
|
52
|
-
export const ARRAY_OPERATORS = [
|
|
53
|
-
|
|
54
|
-
'$gt',
|
|
55
|
-
'$gte',
|
|
56
|
-
'$lt',
|
|
57
|
-
'$lte',
|
|
58
|
-
'$ne',
|
|
59
|
-
'$overlap',
|
|
60
|
-
'$contains',
|
|
61
|
-
'$contained',
|
|
62
|
-
];
|
|
63
|
-
export const JSON_KEY_OPERATORS = [
|
|
64
|
-
'$hasKey',
|
|
65
|
-
'$hasKeys',
|
|
66
|
-
'$hasSomeKeys',
|
|
67
|
-
];
|
|
52
|
+
export const ARRAY_OPERATORS = ['$eq', '$gt', '$gte', '$lt', '$lte', '$ne', '$overlap', '$contains', '$contained'];
|
|
53
|
+
export const JSON_KEY_OPERATORS = ['$hasKey', '$hasKeys', '$hasSomeKeys'];
|
|
68
54
|
export var QueryOrder;
|
|
69
55
|
(function (QueryOrder) {
|
|
70
56
|
QueryOrder["ASC"] = "ASC";
|
|
@@ -100,7 +86,16 @@ export var QueryFlag;
|
|
|
100
86
|
QueryFlag["IDENTITY_INSERT"] = "IDENTITY_INSERT";
|
|
101
87
|
QueryFlag["OUTPUT_TABLE"] = "OUTPUT_TABLE";
|
|
102
88
|
})(QueryFlag || (QueryFlag = {}));
|
|
103
|
-
export const SCALAR_TYPES = new Set([
|
|
89
|
+
export const SCALAR_TYPES = new Set([
|
|
90
|
+
'string',
|
|
91
|
+
'number',
|
|
92
|
+
'boolean',
|
|
93
|
+
'bigint',
|
|
94
|
+
'Uint8Array',
|
|
95
|
+
'Date',
|
|
96
|
+
'Buffer',
|
|
97
|
+
'RegExp',
|
|
98
|
+
]);
|
|
104
99
|
export var ReferenceKind;
|
|
105
100
|
(function (ReferenceKind) {
|
|
106
101
|
ReferenceKind["SCALAR"] = "scalar";
|
package/errors.js
CHANGED
|
@@ -34,12 +34,19 @@ export class ValidationError extends Error {
|
|
|
34
34
|
return new ValidationError(`Entity ${entity.constructor.name} is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager.persist()`);
|
|
35
35
|
}
|
|
36
36
|
static notEntity(owner, prop, data) {
|
|
37
|
-
const type = Object.prototype.toString
|
|
37
|
+
const type = Object.prototype.toString
|
|
38
|
+
.call(data)
|
|
39
|
+
.match(/\[object (\w+)]/)[1]
|
|
40
|
+
.toLowerCase();
|
|
38
41
|
return new ValidationError(`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${inspect(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`);
|
|
39
42
|
}
|
|
40
43
|
static notDiscoveredEntity(data, meta, action = 'persist') {
|
|
41
44
|
/* v8 ignore next */
|
|
42
|
-
const type = meta?.className ??
|
|
45
|
+
const type = meta?.className ??
|
|
46
|
+
Object.prototype.toString
|
|
47
|
+
.call(data)
|
|
48
|
+
.match(/\[object (\w+)]/)[1]
|
|
49
|
+
.toLowerCase();
|
|
43
50
|
let err = `Trying to ${action} not discovered entity of type ${type}.`;
|
|
44
51
|
if (meta) {
|
|
45
52
|
err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
|
|
@@ -56,7 +63,10 @@ export class ValidationError extends Error {
|
|
|
56
63
|
return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
|
|
57
64
|
}
|
|
58
65
|
static invalidType(type, value, mode) {
|
|
59
|
-
const valueType = Object.prototype.toString
|
|
66
|
+
const valueType = Object.prototype.toString
|
|
67
|
+
.call(value)
|
|
68
|
+
.match(/\[object (\w+)]/)[1]
|
|
69
|
+
.toLowerCase();
|
|
60
70
|
if (value instanceof Date) {
|
|
61
71
|
value = value.toISOString();
|
|
62
72
|
}
|
|
@@ -69,8 +79,8 @@ export class ValidationError extends Error {
|
|
|
69
79
|
static cannotModifyInverseCollection(owner, property) {
|
|
70
80
|
const inverseCollection = `${owner.constructor.name}.${property.name}`;
|
|
71
81
|
const ownerCollection = `${property.type}.${property.mappedBy}`;
|
|
72
|
-
const error = `You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. `
|
|
73
|
-
|
|
82
|
+
const error = `You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. ` +
|
|
83
|
+
`Consider working with the owning side instead (${ownerCollection}).`;
|
|
74
84
|
return new ValidationError(error, owner);
|
|
75
85
|
}
|
|
76
86
|
static cannotModifyReadonlyCollection(owner, property) {
|
|
@@ -79,7 +89,7 @@ export class ValidationError extends Error {
|
|
|
79
89
|
static cannotRemoveFromCollectionWithoutOrphanRemoval(owner, property) {
|
|
80
90
|
const options = [
|
|
81
91
|
' - add `orphanRemoval: true` to the collection options',
|
|
82
|
-
|
|
92
|
+
" - add `deleteRule: 'cascade'` to the owning side options",
|
|
83
93
|
' - add `nullable: true` to the owning side options',
|
|
84
94
|
].join('\n');
|
|
85
95
|
return new ValidationError(`Removing items from collection ${owner.constructor.name}.${property.name} without \`orphanRemoval: true\` would break non-null constraint on the owning side. You have several options: \n${options}`, owner);
|
|
@@ -91,7 +101,7 @@ export class ValidationError extends Error {
|
|
|
91
101
|
return new ValidationError('You cannot call em.flush() from inside lifecycle hook handlers');
|
|
92
102
|
}
|
|
93
103
|
static cannotUseGlobalContext() {
|
|
94
|
-
return new ValidationError(
|
|
104
|
+
return new ValidationError("Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead.");
|
|
95
105
|
}
|
|
96
106
|
static cannotUseOperatorsInsideEmbeddables(entityName, propName, payload) {
|
|
97
107
|
return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${Utils.className(entityName)}.${propName}, payload: ${inspect(payload)})`);
|
|
@@ -164,7 +174,7 @@ export class MetadataError extends ValidationError {
|
|
|
164
174
|
return new MetadataError(`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`);
|
|
165
175
|
}
|
|
166
176
|
static multipleVersionFields(meta, fields) {
|
|
167
|
-
return new MetadataError(`Entity ${meta.className} has multiple version properties defined: '${fields.join('
|
|
177
|
+
return new MetadataError(`Entity ${meta.className} has multiple version properties defined: '${fields.join("', '")}'. Only one version property is allowed per entity.`);
|
|
168
178
|
}
|
|
169
179
|
static invalidVersionFieldType(meta) {
|
|
170
180
|
const prop = meta.properties[meta.versionProperty];
|
package/events/EventManager.js
CHANGED
|
@@ -35,7 +35,7 @@ export class EventManager {
|
|
|
35
35
|
const hooks = (meta?.hooks[event] || []);
|
|
36
36
|
listeners.push(...hooks.map(hook => {
|
|
37
37
|
const prototypeHook = meta?.prototype[hook];
|
|
38
|
-
const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
|
|
38
|
+
const handler = typeof hook === 'function' ? hook : (entity[hook] ?? prototypeHook);
|
|
39
39
|
return handler.bind(entity);
|
|
40
40
|
}));
|
|
41
41
|
for (const listener of this.listeners[event] ?? new Set()) {
|
package/exceptions.js
CHANGED
|
@@ -9,10 +9,15 @@ export class DriverException extends Error {
|
|
|
9
9
|
errmsg;
|
|
10
10
|
constructor(previous) {
|
|
11
11
|
super(previous.message);
|
|
12
|
-
Object.getOwnPropertyNames(previous).forEach(k => this[k] = previous[k]);
|
|
12
|
+
Object.getOwnPropertyNames(previous).forEach(k => (this[k] = previous[k]));
|
|
13
13
|
this.name = this.constructor.name;
|
|
14
14
|
Error.captureStackTrace(this, this.constructor);
|
|
15
|
-
this.stack +=
|
|
15
|
+
this.stack +=
|
|
16
|
+
'\n\n' +
|
|
17
|
+
previous
|
|
18
|
+
.stack.split('\n')
|
|
19
|
+
.filter(l => l.trim().startsWith('at '))
|
|
20
|
+
.join('\n');
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
@@ -66,7 +66,10 @@ 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 => !k.match(/\[idx_\d+]/))
|
|
71
|
+
.map(k => this.safeKey(k))
|
|
72
|
+
.join('_');
|
|
70
73
|
const ret = [];
|
|
71
74
|
const idx = this.tmpIndex++;
|
|
72
75
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
@@ -139,7 +142,9 @@ 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}'` : '';
|
|
@@ -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 => !k.match(/\[idx_\d+]/))
|
|
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);
|
|
@@ -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,8 +315,9 @@ 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
|
});
|
|
@@ -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 */
|
|
@@ -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,9 +397,9 @@ 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
405
|
this.hydrators[key].set(meta.class, hydrator);
|
package/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
|
-
export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity,
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
|
|
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';
|
|
9
9
|
export * from './exceptions.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 } 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));
|
package/logging/colors.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
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
|
-
|
|
6
|
-
&& boolIfDefined('FORCE_COLOR')
|
|
7
|
-
&& boolIfDefined('MIKRO_ORM_COLORS');
|
|
8
|
-
const wrap = (fn) => (text) => enabled() ? fn(text) : text;
|
|
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');
|
|
5
|
+
const wrap = (fn) => (text) => (enabled() ? fn(text) : text);
|
|
9
6
|
/** @internal */
|
|
10
7
|
export const colors = {
|
|
11
8
|
red: wrap((text) => `\x1B[31m${text}\x1B[39m`),
|
|
@@ -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>;
|
|
@@ -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
|
}
|