@mikro-orm/core 7.0.0-dev.7 → 7.0.0-dev.71
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 +85 -42
- package/EntityManager.js +282 -194
- package/MikroORM.d.ts +11 -29
- package/MikroORM.js +33 -127
- package/README.md +3 -2
- package/cache/FileCacheAdapter.js +1 -2
- package/connections/Connection.d.ts +11 -7
- package/connections/Connection.js +16 -14
- package/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +13 -4
- package/drivers/IDatabaseDriver.d.ts +27 -5
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +98 -30
- package/entity/Collection.js +432 -93
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +9 -1
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +63 -40
- package/entity/EntityHelper.js +26 -9
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +69 -36
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/EntityValidator.js +4 -4
- package/entity/Reference.d.ts +9 -7
- package/entity/Reference.js +32 -5
- package/entity/WrappedEntity.d.ts +0 -2
- package/entity/WrappedEntity.js +1 -5
- package/entity/defineEntity.d.ts +549 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +2 -1
- package/entity/index.js +2 -1
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +15 -3
- package/enums.d.ts +20 -5
- package/enums.js +13 -0
- package/errors.d.ts +6 -1
- package/errors.js +14 -4
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +35 -24
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +9 -13
- package/metadata/EntitySchema.js +44 -26
- package/metadata/MetadataDiscovery.d.ts +6 -7
- package/metadata/MetadataDiscovery.js +161 -162
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +15 -0
- package/metadata/MetadataStorage.d.ts +0 -4
- package/metadata/MetadataStorage.js +6 -10
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +4 -13
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +39 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +1 -1
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
- package/naming-strategy/AbstractNamingStrategy.js +7 -1
- package/naming-strategy/NamingStrategy.d.ts +11 -1
- package/package.json +11 -10
- package/platforms/Platform.d.ts +6 -10
- package/platforms/Platform.js +6 -22
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +29 -11
- package/serialization/EntityTransformer.js +22 -12
- package/serialization/SerializationContext.js +14 -11
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +1 -2
- package/types/BigIntType.d.ts +8 -6
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +1 -1
- package/types/DoubleType.js +1 -1
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +0 -3
- package/types/index.d.ts +1 -1
- package/typings.d.ts +112 -77
- package/typings.js +32 -32
- package/unit-of-work/ChangeSetComputer.js +8 -3
- package/unit-of-work/ChangeSetPersister.d.ts +4 -2
- package/unit-of-work/ChangeSetPersister.js +37 -16
- package/unit-of-work/UnitOfWork.d.ts +8 -1
- package/unit-of-work/UnitOfWork.js +111 -54
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +10 -8
- package/utils/Configuration.d.ts +200 -191
- package/utils/Configuration.js +141 -152
- package/utils/ConfigurationLoader.d.ts +3 -44
- package/utils/ConfigurationLoader.js +26 -239
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +3 -0
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +53 -7
- package/utils/EntityComparator.d.ts +8 -4
- package/utils/EntityComparator.js +107 -60
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +69 -8
- package/utils/RawQueryFragment.d.ts +36 -4
- package/utils/RawQueryFragment.js +34 -13
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +17 -84
- package/utils/Utils.js +132 -252
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/upsert-utils.d.ts +7 -2
- package/utils/upsert-utils.js +52 -1
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -402
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/enums.js
CHANGED
|
@@ -95,7 +95,9 @@ export var QueryFlag;
|
|
|
95
95
|
QueryFlag["INCLUDE_LAZY_FORMULAS"] = "INCLUDE_LAZY_FORMULAS";
|
|
96
96
|
QueryFlag["AUTO_JOIN_ONE_TO_ONE_OWNER"] = "AUTO_JOIN_ONE_TO_ONE_OWNER";
|
|
97
97
|
QueryFlag["INFER_POPULATE"] = "INFER_POPULATE";
|
|
98
|
+
QueryFlag["DISABLE_NESTED_INNER_JOIN"] = "DISABLE_NESTED_INNER_JOIN";
|
|
98
99
|
QueryFlag["IDENTITY_INSERT"] = "IDENTITY_INSERT";
|
|
100
|
+
QueryFlag["OUTPUT_TABLE"] = "OUTPUT_TABLE";
|
|
99
101
|
})(QueryFlag || (QueryFlag = {}));
|
|
100
102
|
export const SCALAR_TYPES = ['string', 'number', 'boolean', 'bigint', 'Date', 'Buffer', 'RegExp'];
|
|
101
103
|
export var ReferenceKind;
|
|
@@ -122,6 +124,7 @@ export var LoadStrategy;
|
|
|
122
124
|
(function (LoadStrategy) {
|
|
123
125
|
LoadStrategy["SELECT_IN"] = "select-in";
|
|
124
126
|
LoadStrategy["JOINED"] = "joined";
|
|
127
|
+
LoadStrategy["BALANCED"] = "balanced";
|
|
125
128
|
})(LoadStrategy || (LoadStrategy = {}));
|
|
126
129
|
export var DataloaderType;
|
|
127
130
|
(function (DataloaderType) {
|
|
@@ -175,6 +178,16 @@ export const EventTypeMap = Object.keys(EventType).reduce((a, b, i) => {
|
|
|
175
178
|
a[b] = i;
|
|
176
179
|
return a;
|
|
177
180
|
}, {});
|
|
181
|
+
export var TransactionPropagation;
|
|
182
|
+
(function (TransactionPropagation) {
|
|
183
|
+
TransactionPropagation["REQUIRED"] = "required";
|
|
184
|
+
TransactionPropagation["REQUIRES_NEW"] = "requires_new";
|
|
185
|
+
TransactionPropagation["NESTED"] = "nested";
|
|
186
|
+
TransactionPropagation["NOT_SUPPORTED"] = "not_supported";
|
|
187
|
+
TransactionPropagation["SUPPORTS"] = "supports";
|
|
188
|
+
TransactionPropagation["MANDATORY"] = "mandatory";
|
|
189
|
+
TransactionPropagation["NEVER"] = "never";
|
|
190
|
+
})(TransactionPropagation || (TransactionPropagation = {}));
|
|
178
191
|
export class PlainObject {
|
|
179
192
|
}
|
|
180
193
|
export var DeferMode;
|
package/errors.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
24
24
|
static cannotCommit(): ValidationError;
|
|
25
25
|
static cannotUseGlobalContext(): ValidationError;
|
|
26
26
|
static cannotUseOperatorsInsideEmbeddables(className: string, propName: string, payload: unknown): ValidationError;
|
|
27
|
+
static cannotUseGroupOperatorsInsideScalars(className: string, propName: string, payload: unknown): ValidationError;
|
|
27
28
|
static invalidEmbeddableQuery(className: string, propName: string, embeddableType: string): ValidationError;
|
|
28
29
|
}
|
|
29
30
|
export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
@@ -43,7 +44,6 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
43
44
|
static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError;
|
|
44
45
|
static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
|
|
45
46
|
static fromInversideSidePrimary(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
|
|
46
|
-
static entityNotFound(name: string, path: string): MetadataError;
|
|
47
47
|
static unknownIndexProperty(meta: EntityMetadata, prop: string, type: string): MetadataError;
|
|
48
48
|
static multipleVersionFields(meta: EntityMetadata, fields: string[]): MetadataError;
|
|
49
49
|
static invalidVersionFieldType(meta: EntityMetadata): MetadataError;
|
|
@@ -66,3 +66,8 @@ export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
66
66
|
static findOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
|
|
67
67
|
static findExactlyOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
|
|
68
68
|
}
|
|
69
|
+
export declare class TransactionStateError extends ValidationError {
|
|
70
|
+
static requiredTransactionNotFound(propagation: string): TransactionStateError;
|
|
71
|
+
static transactionNotAllowed(propagation: string): TransactionStateError;
|
|
72
|
+
static invalidPropagation(propagation: string): TransactionStateError;
|
|
73
|
+
}
|
package/errors.js
CHANGED
|
@@ -94,6 +94,9 @@ export class ValidationError extends Error {
|
|
|
94
94
|
static cannotUseOperatorsInsideEmbeddables(className, propName, payload) {
|
|
95
95
|
return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${className}.${propName}, payload: ${inspect(payload)})`);
|
|
96
96
|
}
|
|
97
|
+
static cannotUseGroupOperatorsInsideScalars(className, propName, payload) {
|
|
98
|
+
return new ValidationError(`Using group operators ($and/$or) inside scalar properties is not allowed, move the operator above. (property: ${className}.${propName}, payload: ${inspect(payload)})`);
|
|
99
|
+
}
|
|
97
100
|
static invalidEmbeddableQuery(className, propName, embeddableType) {
|
|
98
101
|
return new ValidationError(`Invalid query for entity '${className}', property '${propName}' does not exist in embeddable '${embeddableType}'`);
|
|
99
102
|
}
|
|
@@ -151,10 +154,6 @@ export class MetadataError extends ValidationError {
|
|
|
151
154
|
static fromInversideSidePrimary(meta, owner, prop) {
|
|
152
155
|
return new MetadataError(`${meta.className}.${prop.name} cannot be primary key as it is defined as inverse side. Maybe you should swap the use of 'inversedBy' and 'mappedBy'.`);
|
|
153
156
|
}
|
|
154
|
-
/* v8 ignore next 3 */
|
|
155
|
-
static entityNotFound(name, path) {
|
|
156
|
-
return new MetadataError(`Entity '${name}' not found in ${path}`);
|
|
157
|
-
}
|
|
158
157
|
static unknownIndexProperty(meta, prop, type) {
|
|
159
158
|
return new MetadataError(`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`);
|
|
160
159
|
}
|
|
@@ -220,3 +219,14 @@ export class NotFoundError extends ValidationError {
|
|
|
220
219
|
return new NotFoundError(`Wrong number of ${name} entities found for query ${inspect(where)}, expected exactly one`);
|
|
221
220
|
}
|
|
222
221
|
}
|
|
222
|
+
export class TransactionStateError extends ValidationError {
|
|
223
|
+
static requiredTransactionNotFound(propagation) {
|
|
224
|
+
return new TransactionStateError(`No existing transaction found for transaction marked with propagation "${propagation}"`);
|
|
225
|
+
}
|
|
226
|
+
static transactionNotAllowed(propagation) {
|
|
227
|
+
return new TransactionStateError(`Existing transaction found for transaction marked with propagation "${propagation}"`);
|
|
228
|
+
}
|
|
229
|
+
static invalidPropagation(propagation) {
|
|
230
|
+
return new TransactionStateError(`Unsupported transaction propagation type: ${propagation}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -13,7 +13,9 @@ export interface FlushEventArgs extends Omit<EventArgs<any>, 'entity' | 'changeS
|
|
|
13
13
|
uow: UnitOfWork;
|
|
14
14
|
}
|
|
15
15
|
export interface TransactionEventArgs extends Omit<EventArgs<any>, 'entity' | 'meta' | 'changeSet'> {
|
|
16
|
-
transaction?: Transaction
|
|
16
|
+
transaction?: Transaction & {
|
|
17
|
+
savepointName?: string;
|
|
18
|
+
};
|
|
17
19
|
uow?: UnitOfWork;
|
|
18
20
|
}
|
|
19
21
|
export interface EventSubscriber<T = any> {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { EntityData, EntityMetadata } from '../typings.js';
|
|
2
2
|
import { Hydrator } from './Hydrator.js';
|
|
3
3
|
import type { EntityFactory } from '../entity/EntityFactory.js';
|
|
4
|
-
type EntityHydrator<T extends object> = (entity: T, data: EntityData<T>, factory: EntityFactory, newEntity: boolean, convertCustomTypes: boolean, schema?: string, parentSchema?: string) => void;
|
|
4
|
+
type EntityHydrator<T extends object> = (entity: T, data: EntityData<T>, factory: EntityFactory, newEntity: boolean, convertCustomTypes: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean) => void;
|
|
5
5
|
export declare class ObjectHydrator extends Hydrator {
|
|
6
6
|
private readonly hydrators;
|
|
7
7
|
private tmpIndex;
|
|
8
8
|
/**
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
|
-
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
11
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
12
12
|
/**
|
|
13
13
|
* @inheritDoc
|
|
14
14
|
*/
|
|
15
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
15
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
16
16
|
/**
|
|
17
17
|
* @internal Highly performance-sensitive method.
|
|
18
18
|
*/
|
|
19
|
-
getEntityHydrator<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference'): EntityHydrator<T>;
|
|
19
|
+
getEntityHydrator<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference', normalizeAccessors?: boolean): EntityHydrator<T>;
|
|
20
20
|
private createCollectionItemMapper;
|
|
21
21
|
private wrap;
|
|
22
22
|
private safeKey;
|
|
@@ -6,37 +6,40 @@ import { ReferenceKind } from '../enums.js';
|
|
|
6
6
|
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
7
7
|
export class ObjectHydrator extends Hydrator {
|
|
8
8
|
hydrators = {
|
|
9
|
-
full: new Map(),
|
|
10
|
-
|
|
9
|
+
'full~true': new Map(),
|
|
10
|
+
'full~false': new Map(),
|
|
11
|
+
'reference~true': new Map(),
|
|
12
|
+
'reference~false': new Map(),
|
|
11
13
|
};
|
|
12
14
|
tmpIndex = 0;
|
|
13
15
|
/**
|
|
14
16
|
* @inheritDoc
|
|
15
17
|
*/
|
|
16
|
-
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema, parentSchema) {
|
|
17
|
-
const hydrate = this.getEntityHydrator(meta, type);
|
|
18
|
+
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema, parentSchema, normalizeAccessors) {
|
|
19
|
+
const hydrate = this.getEntityHydrator(meta, type, normalizeAccessors);
|
|
18
20
|
const running = this.running;
|
|
19
21
|
// the running state is used to consider propagation as hydration, saving the values directly to the entity data,
|
|
20
22
|
// but we don't want that for new entities, their propagation should result in entity updates when flushing
|
|
21
23
|
this.running = !newEntity;
|
|
22
|
-
Utils.callCompiledFunction(hydrate, entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema);
|
|
24
|
+
Utils.callCompiledFunction(hydrate, entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors);
|
|
23
25
|
this.running = running;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* @inheritDoc
|
|
27
29
|
*/
|
|
28
|
-
hydrateReference(entity, meta, data, factory, convertCustomTypes = false, schema, parentSchema) {
|
|
29
|
-
const hydrate = this.getEntityHydrator(meta, 'reference');
|
|
30
|
+
hydrateReference(entity, meta, data, factory, convertCustomTypes = false, schema, parentSchema, normalizeAccessors) {
|
|
31
|
+
const hydrate = this.getEntityHydrator(meta, 'reference', normalizeAccessors);
|
|
30
32
|
const running = this.running;
|
|
31
33
|
this.running = true;
|
|
32
|
-
Utils.callCompiledFunction(hydrate, entity, data, factory, false, convertCustomTypes, schema, parentSchema);
|
|
34
|
+
Utils.callCompiledFunction(hydrate, entity, data, factory, false, convertCustomTypes, schema, parentSchema, normalizeAccessors);
|
|
33
35
|
this.running = running;
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* @internal Highly performance-sensitive method.
|
|
37
39
|
*/
|
|
38
|
-
getEntityHydrator(meta, type) {
|
|
39
|
-
const
|
|
40
|
+
getEntityHydrator(meta, type, normalizeAccessors = false) {
|
|
41
|
+
const key = `${type}~${normalizeAccessors}`;
|
|
42
|
+
const exists = this.hydrators[key].get(meta.className);
|
|
40
43
|
if (exists) {
|
|
41
44
|
return exists;
|
|
42
45
|
}
|
|
@@ -63,7 +66,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
63
66
|
const ret = [];
|
|
64
67
|
const idx = this.tmpIndex++;
|
|
65
68
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
66
|
-
if (prop.getter && !prop.setter) {
|
|
69
|
+
if (prop.getter && !prop.setter && prop.persist === false) {
|
|
67
70
|
return [];
|
|
68
71
|
}
|
|
69
72
|
if (prop.ref) {
|
|
@@ -71,7 +74,14 @@ export class ObjectHydrator extends Hydrator {
|
|
|
71
74
|
ret.push(` const oldValue_${idx} = entity${entityKey};`);
|
|
72
75
|
}
|
|
73
76
|
ret.push(` if (data${dataKey} === null) {`);
|
|
74
|
-
|
|
77
|
+
if (prop.ref) {
|
|
78
|
+
ret.push(` entity${entityKey} = new ScalarReference();`);
|
|
79
|
+
ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
|
|
80
|
+
ret.push(` entity${entityKey}.set(${nullVal});`);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
ret.push(` entity${entityKey} = ${nullVal};`);
|
|
84
|
+
}
|
|
75
85
|
ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
|
|
76
86
|
if (prop.customType) {
|
|
77
87
|
registerCustomType(prop, convertorKey, 'convertToJSValue', context);
|
|
@@ -126,17 +136,17 @@ export class ObjectHydrator extends Hydrator {
|
|
|
126
136
|
ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
|
|
127
137
|
ret.push(` if (isPrimaryKey(data${dataKey}, true)) {`);
|
|
128
138
|
if (prop.ref) {
|
|
129
|
-
ret.push(` entity${entityKey} = Reference.create(factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, schema }));`);
|
|
139
|
+
ret.push(` entity${entityKey} = Reference.create(factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema }));`);
|
|
130
140
|
}
|
|
131
141
|
else {
|
|
132
|
-
ret.push(` entity${entityKey} = factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, schema });`);
|
|
142
|
+
ret.push(` entity${entityKey} = factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema });`);
|
|
133
143
|
}
|
|
134
144
|
ret.push(` } else if (data${dataKey} && typeof data${dataKey} === 'object') {`);
|
|
135
145
|
if (prop.ref) {
|
|
136
|
-
ret.push(` entity${entityKey} = Reference.create(factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, schema }));`);
|
|
146
|
+
ret.push(` entity${entityKey} = Reference.create(factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, normalizeAccessors, schema }));`);
|
|
137
147
|
}
|
|
138
148
|
else {
|
|
139
|
-
ret.push(` entity${entityKey} = factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, schema });`);
|
|
149
|
+
ret.push(` entity${entityKey} = factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, normalizeAccessors, schema });`);
|
|
140
150
|
}
|
|
141
151
|
ret.push(` }`);
|
|
142
152
|
ret.push(` }`);
|
|
@@ -245,7 +255,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
245
255
|
// weak comparison as we can have numbers that might have been converted to strings due to being object keys
|
|
246
256
|
ret.push(` if (data${childDataKey} == '${childMeta.discriminatorValue}') {`);
|
|
247
257
|
ret.push(` if (entity${entityKey} == null) {`);
|
|
248
|
-
ret.push(` entity${entityKey} = factory.createEmbeddable('${childMeta.className}', embeddedData, { newEntity, convertCustomTypes });`);
|
|
258
|
+
ret.push(` entity${entityKey} = factory.createEmbeddable('${childMeta.className}', embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
|
|
249
259
|
ret.push(` }`);
|
|
250
260
|
meta.props
|
|
251
261
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
@@ -256,6 +266,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
256
266
|
...prop2,
|
|
257
267
|
name: childProp.name,
|
|
258
268
|
embedded: childProp.embedded,
|
|
269
|
+
embeddedProps: childProp.embeddedProps,
|
|
259
270
|
};
|
|
260
271
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
261
272
|
ret.push(...hydrateProperty(prop3, childProp.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
|
|
@@ -265,7 +276,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
265
276
|
}
|
|
266
277
|
else {
|
|
267
278
|
ret.push(` if (entity${entityKey} == null) {`);
|
|
268
|
-
ret.push(` entity${entityKey} = factory.createEmbeddable('${prop.targetMeta.className}', embeddedData, { newEntity, convertCustomTypes });`);
|
|
279
|
+
ret.push(` entity${entityKey} = factory.createEmbeddable('${prop.targetMeta.className}', embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
|
|
269
280
|
ret.push(` }`);
|
|
270
281
|
meta.props
|
|
271
282
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
@@ -303,7 +314,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
303
314
|
};
|
|
304
315
|
const hydrateProperty = (prop, object = prop.object, path = [prop.name], dataKey) => {
|
|
305
316
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
306
|
-
dataKey = dataKey ?? (object ? entityKey : this.wrap(prop.name));
|
|
317
|
+
dataKey = dataKey ?? (object ? entityKey : this.wrap(normalizeAccessors ? (prop.accessor ?? prop.name) : prop.name));
|
|
307
318
|
const ret = [];
|
|
308
319
|
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.mapToPk) {
|
|
309
320
|
ret.push(...hydrateToOne(prop, dataKey, entityKey));
|
|
@@ -333,11 +344,11 @@ export class ObjectHydrator extends Hydrator {
|
|
|
333
344
|
for (const prop of props) {
|
|
334
345
|
lines.push(...hydrateProperty(prop));
|
|
335
346
|
}
|
|
336
|
-
const code = `// compiled hydrator for entity ${meta.className} (${type})\n`
|
|
337
|
-
+ `return function(entity, data, factory, newEntity, convertCustomTypes, schema) {\n`
|
|
347
|
+
const code = `// compiled hydrator for entity ${meta.className} (${type + normalizeAccessors ? ' normalized' : ''})\n`
|
|
348
|
+
+ `return function(entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors) {\n`
|
|
338
349
|
+ `${lines.join('\n')}\n}`;
|
|
339
350
|
const hydrator = Utils.createFunction(context, code);
|
|
340
|
-
this.hydrators[
|
|
351
|
+
this.hydrators[key].set(meta.className, hydrator);
|
|
341
352
|
return hydrator;
|
|
342
353
|
}
|
|
343
354
|
createCollectionItemMapper(prop) {
|
|
@@ -350,9 +361,9 @@ export class ObjectHydrator extends Hydrator {
|
|
|
350
361
|
lines.push(` value = { ...value, ['${prop2.name}']: Reference.wrapReference(entity, { ref: ${prop2.ref} }) };`);
|
|
351
362
|
lines.push(` }`);
|
|
352
363
|
}
|
|
353
|
-
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference('${prop.type}', value, { convertCustomTypes, schema, merge: true });`);
|
|
364
|
+
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference('${prop.type}', value, { convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
354
365
|
lines.push(` if (value && value.__entity) return value;`);
|
|
355
|
-
lines.push(` return factory.create('${prop.type}', value, { newEntity, convertCustomTypes, schema, merge: true });`);
|
|
366
|
+
lines.push(` return factory.create('${prop.type}', value, { newEntity, convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
356
367
|
lines.push(` }`);
|
|
357
368
|
return lines;
|
|
358
369
|
}
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export {
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
|
+
export type { Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, RequiredEntityData, CheckCallback, IndexCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, NoInfer, 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, } from './typings.js';
|
|
6
7
|
export * from './enums.js';
|
|
7
8
|
export * from './errors.js';
|
|
8
9
|
export * from './exceptions.js';
|
|
@@ -22,4 +23,3 @@ export * from './types/index.js';
|
|
|
22
23
|
export * from './naming-strategy/index.js';
|
|
23
24
|
export * from './metadata/index.js';
|
|
24
25
|
export * from './cache/index.js';
|
|
25
|
-
export * from './decorators/index.js';
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export {
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
6
|
export * from './enums.js';
|
|
7
7
|
export * from './errors.js';
|
|
8
8
|
export * from './exceptions.js';
|
|
@@ -22,4 +22,3 @@ export * from './types/index.js';
|
|
|
22
22
|
export * from './naming-strategy/index.js';
|
|
23
23
|
export * from './metadata/index.js';
|
|
24
24
|
export * from './cache/index.js';
|
|
25
|
-
export * from './decorators/index.js';
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { EntityMetadata, type AnyEntity, type EntityKey, type Constructor, type DeepPartial, type EntityName, type EntityProperty, type CleanKeys, type ExpandProperty, type IsNever, type EntityClass } from '../typings.js';
|
|
2
|
-
import type { EmbeddedOptions } from '../decorators/Embedded.js';
|
|
3
|
-
import type { EnumOptions } from '../decorators/Enum.js';
|
|
4
|
-
import type { IndexOptions, UniqueOptions } from '../decorators/Indexed.js';
|
|
5
|
-
import type { ManyToManyOptions } from '../decorators/ManyToMany.js';
|
|
6
|
-
import type { ManyToOneOptions } from '../decorators/ManyToOne.js';
|
|
7
|
-
import type { OneToManyOptions } from '../decorators/OneToMany.js';
|
|
8
|
-
import type { OneToOneOptions } from '../decorators/OneToOne.js';
|
|
9
|
-
import type { PrimaryKeyOptions, SerializedPrimaryKeyOptions } from '../decorators/PrimaryKey.js';
|
|
10
|
-
import type { PropertyOptions } from '../decorators/Property.js';
|
|
11
2
|
import { ReferenceKind } from '../enums.js';
|
|
12
3
|
import { Type } from '../types/Type.js';
|
|
4
|
+
import type { PropertyOptions, ManyToOneOptions, OneToOneOptions, OneToManyOptions, ManyToManyOptions, EmbeddedOptions, EnumOptions, PrimaryKeyOptions, SerializedPrimaryKeyOptions, IndexOptions, UniqueOptions } from './types.js';
|
|
13
5
|
type TypeType = string | NumberConstructor | StringConstructor | BooleanConstructor | DateConstructor | ArrayConstructor | Constructor<Type<any>> | Type<any>;
|
|
14
6
|
type TypeDef<Target> = {
|
|
15
7
|
type: TypeType;
|
|
@@ -31,7 +23,7 @@ export type EntitySchemaProperty<Target, Owner> = ({
|
|
|
31
23
|
kind: ReferenceKind.MANY_TO_MANY | 'm:n';
|
|
32
24
|
} & TypeDef<Target> & ManyToManyOptions<Owner, Target>) | ({
|
|
33
25
|
kind: ReferenceKind.EMBEDDED | 'embedded';
|
|
34
|
-
} & EmbeddedTypeDef<Target> & EmbeddedOptions & PropertyOptions<Owner>) | ({
|
|
26
|
+
} & EmbeddedTypeDef<Target> & EmbeddedOptions<Owner, Target> & PropertyOptions<Owner>) | ({
|
|
35
27
|
enum: true;
|
|
36
28
|
} & EnumOptions<Owner>) | (TypeDef<Target> & PropertyOptions<Owner>);
|
|
37
29
|
type OmitBaseProps<Entity, Base> = IsNever<Base> extends true ? Entity : Omit<Entity, keyof Base>;
|
|
@@ -41,7 +33,7 @@ export type EntitySchemaMetadata<Entity, Base = never> = Omit<Partial<EntityMeta
|
|
|
41
33
|
class: EntityClass<Entity>;
|
|
42
34
|
name?: string;
|
|
43
35
|
}) & {
|
|
44
|
-
extends?:
|
|
36
|
+
extends?: EntityName<Base>;
|
|
45
37
|
} & {
|
|
46
38
|
properties?: {
|
|
47
39
|
[Key in keyof OmitBaseProps<Entity, Base> as CleanKeys<OmitBaseProps<Entity, Base>, Key>]-?: EntitySchemaProperty<ExpandProperty<NonNullable<Entity[Key]>>, Entity>;
|
|
@@ -63,7 +55,7 @@ export declare class EntitySchema<Entity = any, Base = never> {
|
|
|
63
55
|
addVersion(name: EntityKey<Entity>, type: TypeType, options?: PropertyOptions<Entity>): void;
|
|
64
56
|
addPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: PrimaryKeyOptions<Entity>): void;
|
|
65
57
|
addSerializedPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: SerializedPrimaryKeyOptions<Entity>): void;
|
|
66
|
-
addEmbedded<Target = AnyEntity>(name: EntityKey<Entity>, options: EmbeddedOptions): void;
|
|
58
|
+
addEmbedded<Target = AnyEntity>(name: EntityKey<Entity>, options: EmbeddedOptions<Entity, Target>): void;
|
|
67
59
|
addManyToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToOneOptions<Entity, Target>): void;
|
|
68
60
|
addManyToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToManyOptions<Entity, Target>): void;
|
|
69
61
|
addOneToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToManyOptions<Entity, Target>): void;
|
|
@@ -71,10 +63,12 @@ export declare class EntitySchema<Entity = any, Base = never> {
|
|
|
71
63
|
addIndex<Key extends string>(options: IndexOptions<Entity, Key>): void;
|
|
72
64
|
addUnique<Key extends string>(options: UniqueOptions<Entity, Key>): void;
|
|
73
65
|
setCustomRepository(repository: () => Constructor): void;
|
|
74
|
-
setExtends(base:
|
|
66
|
+
setExtends(base: EntityName<any>): void;
|
|
75
67
|
setClass(proto: EntityClass<Entity>): void;
|
|
76
68
|
get meta(): EntityMetadata<Entity>;
|
|
77
69
|
get name(): EntityName<Entity>;
|
|
70
|
+
get tableName(): string;
|
|
71
|
+
get properties(): Record<string, any>;
|
|
78
72
|
/**
|
|
79
73
|
* @internal
|
|
80
74
|
*/
|
|
@@ -83,5 +77,7 @@ export declare class EntitySchema<Entity = any, Base = never> {
|
|
|
83
77
|
private initPrimaryKeys;
|
|
84
78
|
private normalizeType;
|
|
85
79
|
private createProperty;
|
|
80
|
+
private rename;
|
|
81
|
+
private renameCompositeOptions;
|
|
86
82
|
}
|
|
87
83
|
export {};
|
package/metadata/EntitySchema.js
CHANGED
|
@@ -34,29 +34,13 @@ export class EntitySchema {
|
|
|
34
34
|
return schema;
|
|
35
35
|
}
|
|
36
36
|
addProperty(name, type, options = {}) {
|
|
37
|
-
|
|
38
|
-
if (from in options && !(to in options)) {
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
options[to] = [options[from]];
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
delete options[from];
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
if (name !== options.name) {
|
|
46
|
-
Utils.renameKey(options, 'name', 'fieldName');
|
|
47
|
-
}
|
|
48
|
-
rename(options, 'fieldName', 'fieldNames');
|
|
49
|
-
rename(options, 'ref', 'ref');
|
|
50
|
-
rename(options, 'joinColumn', 'joinColumns');
|
|
51
|
-
rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
|
|
52
|
-
rename(options, 'referenceColumnName', 'referencedColumnNames');
|
|
53
|
-
rename(options, 'columnType', 'columnTypes');
|
|
37
|
+
this.renameCompositeOptions(name, options);
|
|
54
38
|
const prop = { name, kind: ReferenceKind.SCALAR, ...options, type: this.normalizeType(options, type) };
|
|
55
39
|
if (type && Type.isMappedType(type.prototype)) {
|
|
56
40
|
prop.type = type;
|
|
57
41
|
}
|
|
58
|
-
if (
|
|
59
|
-
const formula = prop.formula;
|
|
42
|
+
if (typeof prop.formula === 'string') {
|
|
43
|
+
const formula = prop.formula;
|
|
60
44
|
prop.formula = () => formula;
|
|
61
45
|
}
|
|
62
46
|
if (prop.formula) {
|
|
@@ -91,9 +75,10 @@ export class EntitySchema {
|
|
|
91
75
|
}
|
|
92
76
|
addSerializedPrimaryKey(name, type, options = {}) {
|
|
93
77
|
this._meta.serializedPrimaryKey = name;
|
|
94
|
-
this.addProperty(name, type, options);
|
|
78
|
+
this.addProperty(name, type, { serializedPrimaryKey: true, ...options });
|
|
95
79
|
}
|
|
96
80
|
addEmbedded(name, options) {
|
|
81
|
+
this.renameCompositeOptions(name, options);
|
|
97
82
|
Utils.defaultValue(options, 'prefix', true);
|
|
98
83
|
if (options.array) {
|
|
99
84
|
options.object = true; // force object mode for arrays
|
|
@@ -114,6 +99,8 @@ export class EntitySchema {
|
|
|
114
99
|
if (prop.fieldNames && !prop.joinColumns) {
|
|
115
100
|
prop.joinColumns = prop.fieldNames;
|
|
116
101
|
}
|
|
102
|
+
// By default, the foreign key constraint is created on the relation
|
|
103
|
+
Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
|
|
117
104
|
this.addProperty(name, type, prop);
|
|
118
105
|
}
|
|
119
106
|
addManyToMany(name, type, options) {
|
|
@@ -123,6 +110,8 @@ export class EntitySchema {
|
|
|
123
110
|
}
|
|
124
111
|
if (options.owner) {
|
|
125
112
|
Utils.renameKey(options, 'mappedBy', 'inversedBy');
|
|
113
|
+
// By default, the foreign key constraint is created on the relation
|
|
114
|
+
Utils.defaultValue(options, 'createForeignKeyConstraint', true);
|
|
126
115
|
}
|
|
127
116
|
const prop = this.createProperty(ReferenceKind.MANY_TO_MANY, options);
|
|
128
117
|
this.addProperty(name, type, prop);
|
|
@@ -135,8 +124,12 @@ export class EntitySchema {
|
|
|
135
124
|
const prop = this.createProperty(ReferenceKind.ONE_TO_ONE, options);
|
|
136
125
|
Utils.defaultValue(prop, 'owner', !!prop.inversedBy || !prop.mappedBy);
|
|
137
126
|
Utils.defaultValue(prop, 'unique', prop.owner);
|
|
138
|
-
if (prop.owner
|
|
139
|
-
|
|
127
|
+
if (prop.owner) {
|
|
128
|
+
if (options.mappedBy) {
|
|
129
|
+
Utils.renameKey(prop, 'mappedBy', 'inversedBy');
|
|
130
|
+
}
|
|
131
|
+
// By default, the foreign key constraint is created on the relation
|
|
132
|
+
Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
|
|
140
133
|
}
|
|
141
134
|
if (prop.joinColumns && !prop.fieldNames) {
|
|
142
135
|
prop.fieldNames = prop.joinColumns;
|
|
@@ -164,9 +157,7 @@ export class EntitySchema {
|
|
|
164
157
|
this._meta.prototype = proto.prototype;
|
|
165
158
|
this._meta.className = proto.name;
|
|
166
159
|
if (!sameClass || !this._meta.constructorParams) {
|
|
167
|
-
|
|
168
|
-
this._meta.constructorParams = Utils.getParamNames(tokens, 'constructor');
|
|
169
|
-
this._meta.toJsonParams = Utils.getParamNames(tokens, 'toJSON').filter(p => p !== '...args');
|
|
160
|
+
this._meta.constructorParams = Utils.getConstructorParams(proto);
|
|
170
161
|
}
|
|
171
162
|
if (!this.internal) {
|
|
172
163
|
EntitySchema.REGISTRY.set(proto, this);
|
|
@@ -181,6 +172,12 @@ export class EntitySchema {
|
|
|
181
172
|
get name() {
|
|
182
173
|
return this._meta.className;
|
|
183
174
|
}
|
|
175
|
+
get tableName() {
|
|
176
|
+
return this._meta.tableName;
|
|
177
|
+
}
|
|
178
|
+
get properties() {
|
|
179
|
+
return this._meta.properties;
|
|
180
|
+
}
|
|
184
181
|
/**
|
|
185
182
|
* @internal
|
|
186
183
|
*/
|
|
@@ -266,7 +263,7 @@ export class EntitySchema {
|
|
|
266
263
|
}
|
|
267
264
|
normalizeType(options, type) {
|
|
268
265
|
if ('entity' in options) {
|
|
269
|
-
if (
|
|
266
|
+
if (typeof options.entity === 'string') {
|
|
270
267
|
type = options.type = options.entity;
|
|
271
268
|
}
|
|
272
269
|
else if (options.entity) {
|
|
@@ -289,4 +286,25 @@ export class EntitySchema {
|
|
|
289
286
|
...options,
|
|
290
287
|
};
|
|
291
288
|
}
|
|
289
|
+
rename(data, from, to) {
|
|
290
|
+
if (from in data && !(to in data)) {
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
data[to] = [data[from]];
|
|
293
|
+
// @ts-ignore
|
|
294
|
+
delete data[from];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
renameCompositeOptions(name, options = {}) {
|
|
298
|
+
if (name !== options.name && !options.fieldNames) {
|
|
299
|
+
Utils.renameKey(options, 'name', 'fieldName');
|
|
300
|
+
}
|
|
301
|
+
else if (options.name && (options.fieldNames?.length ?? 0) > 1) {
|
|
302
|
+
delete options.name;
|
|
303
|
+
}
|
|
304
|
+
this.rename(options, 'fieldName', 'fieldNames');
|
|
305
|
+
this.rename(options, 'joinColumn', 'joinColumns');
|
|
306
|
+
this.rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
|
|
307
|
+
this.rename(options, 'referenceColumnName', 'referencedColumnNames');
|
|
308
|
+
this.rename(options, 'columnType', 'columnTypes');
|
|
309
|
+
}
|
|
292
310
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EntityClass, EntityMetadata } from '../typings.js';
|
|
2
2
|
import type { Configuration } from '../utils/Configuration.js';
|
|
3
3
|
import { MetadataStorage } from './MetadataStorage.js';
|
|
4
4
|
import { EntitySchema } from './EntitySchema.js';
|
|
@@ -16,17 +16,18 @@ export declare class MetadataDiscovery {
|
|
|
16
16
|
private readonly discovered;
|
|
17
17
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
18
18
|
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
19
|
-
discoverSync(
|
|
19
|
+
discoverSync(): MetadataStorage;
|
|
20
|
+
validateDiscovered(metadata: EntityMetadata[]): void;
|
|
20
21
|
private mapDiscoveredEntities;
|
|
22
|
+
private initAccessors;
|
|
21
23
|
processDiscoveredEntities(discovered: EntityMetadata[]): EntityMetadata[];
|
|
22
24
|
private findEntities;
|
|
23
25
|
private discoverMissingTargets;
|
|
24
26
|
private tryDiscoverTargets;
|
|
25
|
-
|
|
26
|
-
discoverReferences<T>(refs: (Constructor<T> | EntitySchema<T>)[]): EntityMetadata<T>[];
|
|
27
|
+
discoverReferences<T>(refs: Iterable<EntityClass<T> | EntitySchema<T>>, validate?: boolean): EntityMetadata<T>[];
|
|
27
28
|
reset(className: string): void;
|
|
28
|
-
private prepare;
|
|
29
29
|
private getSchema;
|
|
30
|
+
private getRootEntity;
|
|
30
31
|
private discoverEntity;
|
|
31
32
|
private saveToCache;
|
|
32
33
|
private initNullability;
|
|
@@ -54,7 +55,6 @@ export declare class MetadataDiscovery {
|
|
|
54
55
|
private initAutoincrement;
|
|
55
56
|
private initCheckConstraints;
|
|
56
57
|
private initGeneratedColumn;
|
|
57
|
-
private createColumnMappingObject;
|
|
58
58
|
private getDefaultVersionValue;
|
|
59
59
|
private inferDefaultValue;
|
|
60
60
|
private initDefaultValue;
|
|
@@ -67,6 +67,5 @@ export declare class MetadataDiscovery {
|
|
|
67
67
|
private getPrefix;
|
|
68
68
|
private initUnsigned;
|
|
69
69
|
private initIndexes;
|
|
70
|
-
private getEntityClassOrSchema;
|
|
71
70
|
private shouldForceConstructorUsage;
|
|
72
71
|
}
|