@mikro-orm/core 7.0.0-dev.12 → 7.0.0-dev.120
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 -56
- package/EntityManager.js +332 -293
- package/MikroORM.d.ts +41 -32
- package/MikroORM.js +100 -140
- package/README.md +3 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +8 -7
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +0 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +16 -7
- package/connections/Connection.js +23 -14
- package/drivers/DatabaseDriver.d.ts +25 -16
- package/drivers/DatabaseDriver.js +35 -19
- package/drivers/IDatabaseDriver.d.ts +38 -17
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -30
- package/entity/Collection.js +439 -99
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +26 -18
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +72 -53
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +30 -15
- package/entity/EntityLoader.d.ts +7 -6
- package/entity/EntityLoader.js +84 -72
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/EntityRepository.js +2 -2
- package/entity/Reference.d.ts +6 -5
- package/entity/Reference.js +34 -9
- package/entity/WrappedEntity.d.ts +2 -7
- package/entity/WrappedEntity.js +3 -8
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +3 -2
- package/entity/index.js +3 -2
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +16 -4
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/enums.d.ts +21 -6
- package/enums.js +14 -1
- package/errors.d.ts +17 -9
- package/errors.js +41 -21
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +50 -33
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +1 -0
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/index.d.ts +1 -0
- package/logging/index.js +1 -0
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +13 -17
- package/metadata/EntitySchema.js +67 -51
- package/metadata/MetadataDiscovery.d.ts +6 -10
- package/metadata/MetadataDiscovery.js +289 -298
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +46 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +70 -37
- package/metadata/MetadataValidator.d.ts +2 -9
- package/metadata/MetadataValidator.js +22 -38
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +1 -1
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +8 -4
- package/naming-strategy/AbstractNamingStrategy.js +8 -2
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +14 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -11
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +6 -13
- package/platforms/Platform.js +17 -43
- package/serialization/EntitySerializer.d.ts +5 -0
- package/serialization/EntitySerializer.js +47 -27
- package/serialization/EntityTransformer.js +28 -18
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +16 -13
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.d.ts +8 -6
- package/types/BigIntType.js +1 -1
- 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 +3 -3
- package/types/DoubleType.js +2 -2
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/index.d.ts +1 -1
- package/typings.d.ts +124 -86
- package/typings.js +50 -42
- package/unit-of-work/ChangeSet.d.ts +2 -6
- package/unit-of-work/ChangeSet.js +4 -5
- package/unit-of-work/ChangeSetComputer.d.ts +1 -3
- package/unit-of-work/ChangeSetComputer.js +14 -12
- package/unit-of-work/ChangeSetPersister.d.ts +5 -4
- package/unit-of-work/ChangeSetPersister.js +65 -33
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/UnitOfWork.d.ts +10 -3
- package/unit-of-work/UnitOfWork.js +139 -96
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +18 -16
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +753 -207
- package/utils/Configuration.js +145 -190
- package/utils/ConfigurationLoader.d.ts +1 -54
- package/utils/ConfigurationLoader.js +1 -352
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +9 -6
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +65 -17
- package/utils/EntityComparator.d.ts +13 -9
- package/utils/EntityComparator.js +85 -43
- package/utils/QueryHelper.d.ts +14 -6
- package/utils/QueryHelper.js +87 -25
- package/utils/RawQueryFragment.d.ts +48 -25
- package/utils/RawQueryFragment.js +66 -70
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +12 -119
- package/utils/Utils.js +97 -373
- package/utils/clone.js +8 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +97 -0
- package/utils/fs-utils.d.ts +32 -0
- package/utils/fs-utils.js +178 -0
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -1
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +55 -4
- 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/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
2
|
export declare class UnderscoreNamingStrategy extends AbstractNamingStrategy {
|
|
3
|
-
classToTableName(entityName: string): string;
|
|
3
|
+
classToTableName(entityName: string, tableName?: string): string;
|
|
4
4
|
joinColumnName(propertyName: string): string;
|
|
5
|
-
joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
|
|
6
|
-
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string): string;
|
|
5
|
+
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
|
|
6
|
+
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
|
|
7
7
|
propertyToColumnName(propertyName: string, object?: boolean): string;
|
|
8
8
|
referenceColumnName(): string;
|
|
9
9
|
private underscore;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
2
|
export class UnderscoreNamingStrategy extends AbstractNamingStrategy {
|
|
3
|
-
classToTableName(entityName) {
|
|
4
|
-
return this.underscore(entityName);
|
|
3
|
+
classToTableName(entityName, tableName) {
|
|
4
|
+
return tableName ?? this.underscore(entityName);
|
|
5
5
|
}
|
|
6
6
|
joinColumnName(propertyName) {
|
|
7
7
|
return this.underscore(propertyName) + '_' + this.referenceColumnName();
|
|
8
8
|
}
|
|
9
|
-
joinKeyColumnName(entityName, referencedColumnName) {
|
|
10
|
-
return this.classToTableName(entityName) + '_' + (referencedColumnName || this.referenceColumnName());
|
|
9
|
+
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
|
|
10
|
+
return this.classToTableName(entityName, tableName) + '_' + (referencedColumnName || this.referenceColumnName());
|
|
11
11
|
}
|
|
12
|
-
joinTableName(sourceEntity, targetEntity, propertyName) {
|
|
13
|
-
return this.classToTableName(sourceEntity) + '_' + this.classToTableName(propertyName);
|
|
12
|
+
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
|
|
13
|
+
return this.classToTableName(sourceEntity, tableName) + '_' + this.classToTableName(propertyName);
|
|
14
14
|
}
|
|
15
15
|
propertyToColumnName(propertyName, object) {
|
|
16
16
|
return this.underscore(propertyName);
|
package/not-supported.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.120",
|
|
5
5
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
8
|
-
".": "./index.js"
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./file-discovery": {
|
|
10
|
+
"node": "./metadata/discover-entities.js",
|
|
11
|
+
"browser": "./not-supported.js"
|
|
12
|
+
},
|
|
13
|
+
"./fs-utils": {
|
|
14
|
+
"node": "./utils/fs-utils.js",
|
|
15
|
+
"browser": "./not-supported.js"
|
|
16
|
+
}
|
|
9
17
|
},
|
|
10
18
|
"repository": {
|
|
11
19
|
"type": "git",
|
|
@@ -39,10 +47,10 @@
|
|
|
39
47
|
},
|
|
40
48
|
"homepage": "https://mikro-orm.io",
|
|
41
49
|
"engines": {
|
|
42
|
-
"node": ">= 22.
|
|
50
|
+
"node": ">= 22.17.0"
|
|
43
51
|
},
|
|
44
52
|
"scripts": {
|
|
45
|
-
"build": "yarn
|
|
53
|
+
"build": "yarn compile && yarn copy",
|
|
46
54
|
"clean": "yarn run -T rimraf ./dist",
|
|
47
55
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
48
56
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -50,12 +58,12 @@
|
|
|
50
58
|
"publishConfig": {
|
|
51
59
|
"access": "public"
|
|
52
60
|
},
|
|
53
|
-
"
|
|
54
|
-
"dataloader": "2.2.3"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"dataloader": "2.2.3"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"dataloader": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
60
68
|
}
|
|
61
69
|
}
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
3
2
|
import { type NamingStrategy } from '../naming-strategy/NamingStrategy.js';
|
|
4
|
-
import type { Constructor, EntityProperty, IPrimaryKey, ISchemaGenerator, PopulateOptions, Primary,
|
|
3
|
+
import type { Constructor, EntityMetadata, EntityProperty, IPrimaryKey, ISchemaGenerator, PopulateOptions, Primary, SimpleColumnMeta } from '../typings.js';
|
|
5
4
|
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
5
|
import type { EntityManager } from '../EntityManager.js';
|
|
7
6
|
import type { Configuration } from '../utils/Configuration.js';
|
|
@@ -30,7 +29,6 @@ export declare abstract class Platform {
|
|
|
30
29
|
usesEnumCheckConstraints(): boolean;
|
|
31
30
|
getSchemaHelper(): unknown;
|
|
32
31
|
indexForeignKeys(): boolean;
|
|
33
|
-
allowsMultiInsert(): boolean;
|
|
34
32
|
/**
|
|
35
33
|
* Whether or not the driver supports retuning list of created PKs back when multi-inserting
|
|
36
34
|
*/
|
|
@@ -48,11 +46,6 @@ export declare abstract class Platform {
|
|
|
48
46
|
* Converts scalar primary key representation to native driver wrapper (e.g. string to mongodb's ObjectId)
|
|
49
47
|
*/
|
|
50
48
|
denormalizePrimaryKey(data: IPrimaryKey): IPrimaryKey;
|
|
51
|
-
/**
|
|
52
|
-
* Used when serializing via toObject and toJSON methods, allows to use different PK field name (like `id` instead of `_id`)
|
|
53
|
-
*/
|
|
54
|
-
getSerializedPrimaryKeyField(field: string): string;
|
|
55
|
-
usesDifferentSerializedPrimaryKey(): boolean;
|
|
56
49
|
/**
|
|
57
50
|
* Returns the SQL specific for the platform to get the current timestamp
|
|
58
51
|
*/
|
|
@@ -158,7 +151,7 @@ export declare abstract class Platform {
|
|
|
158
151
|
getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
|
|
159
152
|
convertsJsonAutomatically(): boolean;
|
|
160
153
|
convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
|
|
161
|
-
convertJsonToJSValue(value: unknown,
|
|
154
|
+
convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
|
|
162
155
|
convertDateToJSValue(value: string | Date): string;
|
|
163
156
|
convertIntervalToJSValue(value: string): unknown;
|
|
164
157
|
convertIntervalToDatabaseValue(value: unknown): unknown;
|
|
@@ -175,7 +168,9 @@ export declare abstract class Platform {
|
|
|
175
168
|
getExtension<T>(extensionName: string, extensionKey: string, moduleName: string, em: EntityManager): T;
|
|
176
169
|
getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): ISchemaGenerator;
|
|
177
170
|
processDateProperty(value: unknown): string | number | Date;
|
|
178
|
-
quoteIdentifier(id: string
|
|
171
|
+
quoteIdentifier(id: string | {
|
|
172
|
+
toString: () => string;
|
|
173
|
+
}, quote?: string): string;
|
|
179
174
|
quoteValue(value: any): string;
|
|
180
175
|
escape(value: any): string;
|
|
181
176
|
formatQuery(sql: string, params: readonly any[]): string;
|
|
@@ -193,7 +188,7 @@ export declare abstract class Platform {
|
|
|
193
188
|
getDefaultPrimaryName(tableName: string, columns: string[]): string;
|
|
194
189
|
supportsCustomPrimaryKeyNames(): boolean;
|
|
195
190
|
isPopulated<T>(key: string, populate: readonly PopulateOptions<T>[] | boolean): boolean;
|
|
196
|
-
shouldHaveColumn<T>(prop: EntityProperty<T>, populate: readonly PopulateOptions<T>[] | boolean, exclude?: string[], includeFormulas?: boolean): boolean;
|
|
191
|
+
shouldHaveColumn<T>(prop: EntityProperty<T>, populate: readonly PopulateOptions<T>[] | boolean, exclude?: string[], includeFormulas?: boolean, ignoreInlineEmbeddables?: boolean): boolean;
|
|
197
192
|
/**
|
|
198
193
|
* Currently not supported due to how knex does complex sqlite diffing (always based on current schema)
|
|
199
194
|
*/
|
|
@@ -225,6 +220,4 @@ export declare abstract class Platform {
|
|
|
225
220
|
* @internal
|
|
226
221
|
*/
|
|
227
222
|
clone(): this;
|
|
228
|
-
/** @ignore */
|
|
229
|
-
[inspect.custom](): string;
|
|
230
223
|
}
|
package/platforms/Platform.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { clone } from '../utils/clone.js';
|
|
3
2
|
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
4
3
|
import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
|
|
5
4
|
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
|
-
import { ArrayType, BigIntType, BlobType,
|
|
7
|
-
import { parseJsonSafe
|
|
5
|
+
import { ArrayType, BigIntType, BlobType, BooleanType, CharacterType, DateTimeType, DateType, DecimalType, DoubleType, EnumType, FloatType, IntegerType, IntervalType, JsonType, MediumIntType, SmallIntType, StringType, TextType, TimeType, TinyIntType, Type, Uint8ArrayType, UnknownType, UuidType, } from '../types/index.js';
|
|
6
|
+
import { parseJsonSafe } from '../utils/Utils.js';
|
|
8
7
|
import { ReferenceKind } from '../enums.js';
|
|
9
|
-
import {
|
|
8
|
+
import { Raw } from '../utils/RawQueryFragment.js';
|
|
10
9
|
export const JsonProperty = Symbol('JsonProperty');
|
|
11
10
|
export class Platform {
|
|
12
11
|
exceptionConverter = new ExceptionConverter();
|
|
@@ -48,9 +47,6 @@ export class Platform {
|
|
|
48
47
|
indexForeignKeys() {
|
|
49
48
|
return false;
|
|
50
49
|
}
|
|
51
|
-
allowsMultiInsert() {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
50
|
/**
|
|
55
51
|
* Whether or not the driver supports retuning list of created PKs back when multi-inserting
|
|
56
52
|
*/
|
|
@@ -78,15 +74,6 @@ export class Platform {
|
|
|
78
74
|
denormalizePrimaryKey(data) {
|
|
79
75
|
return data;
|
|
80
76
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Used when serializing via toObject and toJSON methods, allows to use different PK field name (like `id` instead of `_id`)
|
|
83
|
-
*/
|
|
84
|
-
getSerializedPrimaryKeyField(field) {
|
|
85
|
-
return field;
|
|
86
|
-
}
|
|
87
|
-
usesDifferentSerializedPrimaryKey() {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
77
|
/**
|
|
91
78
|
* Returns the SQL specific for the platform to get the current timestamp
|
|
92
79
|
*/
|
|
@@ -133,7 +120,7 @@ export class Platform {
|
|
|
133
120
|
return true;
|
|
134
121
|
}
|
|
135
122
|
isBigIntProperty(prop) {
|
|
136
|
-
return prop.columnTypes
|
|
123
|
+
return prop.columnTypes?.[0] === 'bigint';
|
|
137
124
|
}
|
|
138
125
|
getDefaultSchemaName() {
|
|
139
126
|
return undefined;
|
|
@@ -169,7 +156,7 @@ export class Platform {
|
|
|
169
156
|
return `text`;
|
|
170
157
|
}
|
|
171
158
|
getEnumTypeDeclarationSQL(column) {
|
|
172
|
-
if (column.items?.every(item =>
|
|
159
|
+
if (column.items?.every(item => typeof item === 'string')) {
|
|
173
160
|
return `enum('${column.items.join("','")}')`;
|
|
174
161
|
}
|
|
175
162
|
return this.getTinyIntTypeDeclarationSQL(column);
|
|
@@ -269,7 +256,7 @@ export class Platform {
|
|
|
269
256
|
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
270
257
|
return path.join('.');
|
|
271
258
|
}
|
|
272
|
-
/* v8 ignore next
|
|
259
|
+
/* v8 ignore next */
|
|
273
260
|
getJsonIndexDefinition(index) {
|
|
274
261
|
return index.columnNames;
|
|
275
262
|
}
|
|
@@ -288,11 +275,7 @@ export class Platform {
|
|
|
288
275
|
convertJsonToDatabaseValue(value, context) {
|
|
289
276
|
return JSON.stringify(value);
|
|
290
277
|
}
|
|
291
|
-
convertJsonToJSValue(value,
|
|
292
|
-
const isObjectEmbedded = prop.embedded && prop.object;
|
|
293
|
-
if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
|
|
294
|
-
return value;
|
|
295
|
-
}
|
|
278
|
+
convertJsonToJSValue(value, context) {
|
|
296
279
|
return parseJsonSafe(value);
|
|
297
280
|
}
|
|
298
281
|
convertDateToJSValue(value) {
|
|
@@ -306,7 +289,7 @@ export class Platform {
|
|
|
306
289
|
}
|
|
307
290
|
parseDate(value) {
|
|
308
291
|
const date = new Date(value);
|
|
309
|
-
/* v8 ignore next
|
|
292
|
+
/* v8 ignore next */
|
|
310
293
|
if (isNaN(date.getTime())) {
|
|
311
294
|
return value;
|
|
312
295
|
}
|
|
@@ -336,19 +319,10 @@ export class Platform {
|
|
|
336
319
|
if (extension) {
|
|
337
320
|
return extension;
|
|
338
321
|
}
|
|
339
|
-
/* v8 ignore next
|
|
340
|
-
|
|
341
|
-
module: moduleName,
|
|
342
|
-
warning: `Please install ${moduleName} package.`,
|
|
343
|
-
});
|
|
344
|
-
/* v8 ignore next 3 */
|
|
345
|
-
if (module) {
|
|
346
|
-
return this.config.getCachedService(module[extensionName], em);
|
|
347
|
-
}
|
|
348
|
-
/* v8 ignore next 2 */
|
|
349
|
-
throw new Error(`${extensionName} extension not registered.`);
|
|
322
|
+
/* v8 ignore next */
|
|
323
|
+
throw new Error(`${extensionName} extension not registered. Provide it in the ORM config, or use the async \`MikroORM.init()\` method to load extensions automatically.`);
|
|
350
324
|
}
|
|
351
|
-
/* v8 ignore next
|
|
325
|
+
/* v8 ignore next: kept for type inference only */
|
|
352
326
|
getSchemaGenerator(driver, em) {
|
|
353
327
|
throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
|
|
354
328
|
}
|
|
@@ -356,7 +330,7 @@ export class Platform {
|
|
|
356
330
|
return value;
|
|
357
331
|
}
|
|
358
332
|
quoteIdentifier(id, quote = '`') {
|
|
359
|
-
const raw =
|
|
333
|
+
const raw = Raw.getKnownFragment(id);
|
|
360
334
|
if (raw) {
|
|
361
335
|
return this.formatQuery(raw.sql, raw.params);
|
|
362
336
|
}
|
|
@@ -365,7 +339,7 @@ export class Platform {
|
|
|
365
339
|
quoteValue(value) {
|
|
366
340
|
return value;
|
|
367
341
|
}
|
|
368
|
-
/* v8 ignore next
|
|
342
|
+
/* v8 ignore next */
|
|
369
343
|
escape(value) {
|
|
370
344
|
return value;
|
|
371
345
|
}
|
|
@@ -455,7 +429,7 @@ export class Platform {
|
|
|
455
429
|
isPopulated(key, populate) {
|
|
456
430
|
return populate === true || (populate !== false && populate.some(p => p.field === key || p.all));
|
|
457
431
|
}
|
|
458
|
-
shouldHaveColumn(prop, populate, exclude, includeFormulas = true) {
|
|
432
|
+
shouldHaveColumn(prop, populate, exclude, includeFormulas = true, ignoreInlineEmbeddables = true) {
|
|
459
433
|
if (exclude?.includes(prop.name)) {
|
|
460
434
|
return false;
|
|
461
435
|
}
|
|
@@ -475,7 +449,7 @@ export class Platform {
|
|
|
475
449
|
return true;
|
|
476
450
|
}
|
|
477
451
|
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
478
|
-
return
|
|
452
|
+
return prop.object || ignoreInlineEmbeddables;
|
|
479
453
|
}
|
|
480
454
|
return prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner;
|
|
481
455
|
}
|
|
@@ -522,9 +496,9 @@ export class Platform {
|
|
|
522
496
|
clone() {
|
|
523
497
|
return this;
|
|
524
498
|
}
|
|
525
|
-
/* v8 ignore next 4 */
|
|
526
499
|
/** @ignore */
|
|
527
|
-
|
|
500
|
+
/* v8 ignore next */
|
|
501
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
528
502
|
return `[${this.constructor.name}]`;
|
|
529
503
|
}
|
|
530
504
|
}
|
|
@@ -4,6 +4,7 @@ export declare class EntitySerializer {
|
|
|
4
4
|
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>): EntityDTO<Loaded<T, P>>;
|
|
5
5
|
private static propertyName;
|
|
6
6
|
private static processProperty;
|
|
7
|
+
private static processCustomType;
|
|
7
8
|
private static extractChildOptions;
|
|
8
9
|
private static processEntity;
|
|
9
10
|
private static processCollection;
|
|
@@ -17,10 +18,14 @@ export interface SerializeOptions<T, P extends string = never, E extends string
|
|
|
17
18
|
forceObject?: boolean;
|
|
18
19
|
/** Ignore custom property serializers. */
|
|
19
20
|
ignoreSerializers?: boolean;
|
|
21
|
+
/** Include properties marked as `hidden`. */
|
|
22
|
+
includeHidden?: boolean;
|
|
20
23
|
/** Skip properties with `null` value. */
|
|
21
24
|
skipNull?: boolean;
|
|
22
25
|
/** Only include properties for a specific group. If a property does not specify any group, it will be included, otherwise only properties with a matching group are included. */
|
|
23
26
|
groups?: string[];
|
|
27
|
+
/** Convert custom types to their database representation. By default, the `Type.toJSON` method is invoked instead. */
|
|
28
|
+
convertCustomTypes?: boolean;
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts entity instance to POJO, converting the `Collection`s to arrays and unwrapping the `Reference` wrapper, while respecting the serialization options.
|
|
@@ -15,8 +15,8 @@ function isVisible(meta, propName, options) {
|
|
|
15
15
|
if (options.exclude?.find(item => item === propName)) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
|
-
const visible = prop && !prop.hidden;
|
|
19
|
-
const prefixed = prop && !prop.primary && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
18
|
+
const visible = prop && !(prop.hidden && !options.includeHidden);
|
|
19
|
+
const prefixed = prop && !prop.primary && !prop.accessor && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
20
20
|
return visible && !prefixed;
|
|
21
21
|
}
|
|
22
22
|
function isPopulated(propName, options) {
|
|
@@ -41,23 +41,41 @@ export class EntitySerializer {
|
|
|
41
41
|
}
|
|
42
42
|
const root = wrapped.__serializationContext.root;
|
|
43
43
|
const ret = {};
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const props = new Set();
|
|
45
|
+
if (meta.serializedPrimaryKey && !meta.compositePK) {
|
|
46
|
+
props.add(meta.serializedPrimaryKey);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
meta.primaryKeys.forEach(pk => props.add(pk));
|
|
50
|
+
}
|
|
51
|
+
if (wrapped.isInitialized() || !wrapped.hasPrimaryKey()) {
|
|
52
|
+
const entityKeys = new Set(Object.keys(entity));
|
|
53
|
+
for (const prop of meta.props) {
|
|
54
|
+
if (entityKeys.has(prop.name) || (prop.getter && prop.accessor === prop.name)) {
|
|
55
|
+
props.add(prop.name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const key of entityKeys) {
|
|
59
|
+
if (!meta.properties[key]) {
|
|
60
|
+
props.add(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
46
64
|
const visited = root.visited.has(entity);
|
|
47
65
|
if (!visited) {
|
|
48
66
|
root.visited.add(entity);
|
|
49
67
|
}
|
|
50
|
-
for (const prop of
|
|
68
|
+
for (const prop of props) {
|
|
51
69
|
if (!isVisible(meta, prop, options)) {
|
|
52
70
|
continue;
|
|
53
71
|
}
|
|
54
|
-
const cycle = root.visit(meta.
|
|
72
|
+
const cycle = root.visit(meta.class, prop);
|
|
55
73
|
if (cycle && visited) {
|
|
56
74
|
continue;
|
|
57
75
|
}
|
|
58
76
|
const val = this.processProperty(prop, entity, options);
|
|
59
77
|
if (!cycle) {
|
|
60
|
-
root.leave(meta.
|
|
78
|
+
root.leave(meta.class, prop);
|
|
61
79
|
}
|
|
62
80
|
if (options.skipNull && Utils.isPlainObject(val)) {
|
|
63
81
|
Utils.dropUndefinedProperties(val, null);
|
|
@@ -67,7 +85,7 @@ export class EntitySerializer {
|
|
|
67
85
|
}
|
|
68
86
|
const visible = typeof val !== 'undefined' && !(val === null && options.skipNull);
|
|
69
87
|
if (visible) {
|
|
70
|
-
ret[this.propertyName(meta, prop
|
|
88
|
+
ret[this.propertyName(meta, prop)] = val;
|
|
71
89
|
}
|
|
72
90
|
}
|
|
73
91
|
if (contextCreated) {
|
|
@@ -81,26 +99,26 @@ export class EntitySerializer {
|
|
|
81
99
|
if (prop.getterName != null) {
|
|
82
100
|
const visible = entity[prop.getterName] instanceof Function && isVisible(meta, prop.name, options);
|
|
83
101
|
if (visible) {
|
|
84
|
-
ret[this.propertyName(meta, prop.name
|
|
102
|
+
ret[this.propertyName(meta, prop.name)] = this.processProperty(prop.getterName, entity, options);
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
else {
|
|
88
106
|
// decorated getters
|
|
89
107
|
const visible = typeof entity[prop.name] !== 'undefined' && isVisible(meta, prop.name, options);
|
|
90
108
|
if (visible) {
|
|
91
|
-
ret[this.propertyName(meta, prop.name
|
|
109
|
+
ret[this.propertyName(meta, prop.name)] = this.processProperty(prop.name, entity, options);
|
|
92
110
|
}
|
|
93
111
|
}
|
|
94
112
|
}
|
|
95
113
|
return ret;
|
|
96
114
|
}
|
|
97
|
-
static propertyName(meta, prop
|
|
98
|
-
/* v8 ignore next
|
|
115
|
+
static propertyName(meta, prop) {
|
|
116
|
+
/* v8 ignore next */
|
|
99
117
|
if (meta.properties[prop]?.serializedName) {
|
|
100
118
|
return meta.properties[prop].serializedName;
|
|
101
119
|
}
|
|
102
|
-
if (meta.properties[prop]?.primary &&
|
|
103
|
-
return
|
|
120
|
+
if (meta.properties[prop]?.primary && meta.serializedPrimaryKey) {
|
|
121
|
+
return meta.serializedPrimaryKey;
|
|
104
122
|
}
|
|
105
123
|
return prop;
|
|
106
124
|
}
|
|
@@ -119,7 +137,7 @@ export class EntitySerializer {
|
|
|
119
137
|
}
|
|
120
138
|
return returnValue;
|
|
121
139
|
}
|
|
122
|
-
/* v8 ignore next
|
|
140
|
+
/* v8 ignore next */
|
|
123
141
|
if (!options.ignoreSerializers && serializer) {
|
|
124
142
|
return serializer(value);
|
|
125
143
|
}
|
|
@@ -132,7 +150,7 @@ export class EntitySerializer {
|
|
|
132
150
|
if (Utils.isScalarReference(value)) {
|
|
133
151
|
return value.unwrap();
|
|
134
152
|
}
|
|
135
|
-
/* v8 ignore next
|
|
153
|
+
/* v8 ignore next */
|
|
136
154
|
if (property?.kind === ReferenceKind.EMBEDDED) {
|
|
137
155
|
if (Array.isArray(value)) {
|
|
138
156
|
return value.map(item => helper(item).toJSON());
|
|
@@ -141,12 +159,20 @@ export class EntitySerializer {
|
|
|
141
159
|
return helper(value).toJSON();
|
|
142
160
|
}
|
|
143
161
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return customType.toJSON(value, wrapped.__platform);
|
|
162
|
+
if (property.customType) {
|
|
163
|
+
return this.processCustomType(value, property, wrapped.__platform, options.convertCustomTypes);
|
|
147
164
|
}
|
|
148
165
|
return wrapped.__platform.normalizePrimaryKey(value);
|
|
149
166
|
}
|
|
167
|
+
static processCustomType(value, prop, platform, convertCustomTypes) {
|
|
168
|
+
if (!prop.customType) {
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
if (convertCustomTypes) {
|
|
172
|
+
return prop.customType.convertToDatabaseValue(value, platform, { mode: 'serialization' });
|
|
173
|
+
}
|
|
174
|
+
return prop.customType.toJSON(value, platform);
|
|
175
|
+
}
|
|
150
176
|
static extractChildOptions(options, prop) {
|
|
151
177
|
return {
|
|
152
178
|
...options,
|
|
@@ -165,10 +191,7 @@ export class EntitySerializer {
|
|
|
165
191
|
if (expand) {
|
|
166
192
|
return this.serialize(child, childOptions);
|
|
167
193
|
}
|
|
168
|
-
|
|
169
|
-
if (prop.customType) {
|
|
170
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
171
|
-
}
|
|
194
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
172
195
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
173
196
|
return Utils.primaryKeyToObject(meta, pk, visible);
|
|
174
197
|
}
|
|
@@ -192,10 +215,7 @@ export class EntitySerializer {
|
|
|
192
215
|
if (populated || !wrapped.__managed) {
|
|
193
216
|
return this.serialize(item, this.extractChildOptions(options, prop.name));
|
|
194
217
|
}
|
|
195
|
-
|
|
196
|
-
if (prop.customType) {
|
|
197
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
198
|
-
}
|
|
218
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
199
219
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
200
220
|
return Utils.primaryKeyToObject(wrapped.__meta, pk);
|
|
201
221
|
}
|
|
@@ -6,7 +6,7 @@ import { isRaw } from '../utils/RawQueryFragment.js';
|
|
|
6
6
|
function isVisible(meta, propName, ignoreFields = []) {
|
|
7
7
|
const prop = meta.properties[propName];
|
|
8
8
|
const visible = prop && !prop.hidden;
|
|
9
|
-
const prefixed = prop && !prop.primary && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
9
|
+
const prefixed = prop && !prop.primary && !prop.accessor && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
10
10
|
return visible && !prefixed && !ignoreFields.includes(propName);
|
|
11
11
|
}
|
|
12
12
|
export class EntityTransformer {
|
|
@@ -27,39 +27,49 @@ export class EntityTransformer {
|
|
|
27
27
|
const root = wrapped.__serializationContext.root;
|
|
28
28
|
const meta = wrapped.__meta;
|
|
29
29
|
const ret = {};
|
|
30
|
-
const
|
|
30
|
+
const props = new Set();
|
|
31
31
|
if (meta.serializedPrimaryKey && !meta.compositePK) {
|
|
32
|
-
|
|
32
|
+
props.add(meta.serializedPrimaryKey);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
meta.primaryKeys.forEach(pk =>
|
|
35
|
+
meta.primaryKeys.forEach(pk => props.add(pk));
|
|
36
36
|
}
|
|
37
37
|
if (wrapped.isInitialized() || !wrapped.hasPrimaryKey()) {
|
|
38
|
-
|
|
38
|
+
const entityKeys = new Set(Object.keys(entity));
|
|
39
|
+
for (const prop of meta.props) {
|
|
40
|
+
if (entityKeys.has(prop.name) || (prop.getter && prop.accessor === prop.name)) {
|
|
41
|
+
props.add(prop.name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const key of entityKeys) {
|
|
45
|
+
if (!meta.properties[key]) {
|
|
46
|
+
props.add(key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
50
|
const visited = root.visited.has(entity);
|
|
41
51
|
const includePrimaryKeys = wrapped.__config.get('serialization').includePrimaryKeys;
|
|
42
52
|
if (!visited) {
|
|
43
53
|
root.visited.add(entity);
|
|
44
54
|
}
|
|
45
|
-
for (const prop of
|
|
55
|
+
for (const prop of props) {
|
|
46
56
|
const visible = raw ? meta.properties[prop] : isVisible(meta, prop, ignoreFields);
|
|
47
57
|
if (!visible) {
|
|
48
58
|
continue;
|
|
49
59
|
}
|
|
50
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
51
|
-
const partiallyLoaded = root.isPartiallyLoaded(meta.
|
|
60
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop);
|
|
61
|
+
const partiallyLoaded = root.isPartiallyLoaded(meta.class, prop);
|
|
52
62
|
const isPrimary = includePrimaryKeys && meta.properties[prop].primary;
|
|
53
63
|
if (!partiallyLoaded && !populated && !isPrimary) {
|
|
54
64
|
continue;
|
|
55
65
|
}
|
|
56
|
-
const cycle = root.visit(meta.
|
|
66
|
+
const cycle = root.visit(meta.class, prop);
|
|
57
67
|
if (cycle && visited) {
|
|
58
68
|
continue;
|
|
59
69
|
}
|
|
60
70
|
const val = EntityTransformer.processProperty(prop, entity, raw, populated);
|
|
61
71
|
if (!cycle) {
|
|
62
|
-
root.leave(meta.
|
|
72
|
+
root.leave(meta.class, prop);
|
|
63
73
|
}
|
|
64
74
|
if (isRaw(val)) {
|
|
65
75
|
throw new Error(`Trying to serialize raw SQL fragment: '${val.sql}'`);
|
|
@@ -67,7 +77,7 @@ export class EntityTransformer {
|
|
|
67
77
|
if (typeof val === 'undefined') {
|
|
68
78
|
continue;
|
|
69
79
|
}
|
|
70
|
-
ret[this.propertyName(meta, prop,
|
|
80
|
+
ret[this.propertyName(meta, prop, raw)] = val;
|
|
71
81
|
}
|
|
72
82
|
if (!wrapped.isInitialized() && wrapped.hasPrimaryKey()) {
|
|
73
83
|
return ret;
|
|
@@ -76,17 +86,17 @@ export class EntityTransformer {
|
|
|
76
86
|
// decorated get methods
|
|
77
87
|
if (prop.getterName != null) {
|
|
78
88
|
const visible = !prop.hidden && entity[prop.getterName] instanceof Function;
|
|
79
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
89
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop.name);
|
|
80
90
|
if (visible) {
|
|
81
|
-
ret[this.propertyName(meta, prop.name,
|
|
91
|
+
ret[this.propertyName(meta, prop.name, raw)] = this.processProperty(prop.getterName, entity, raw, populated);
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
else {
|
|
85
95
|
// decorated getters
|
|
86
96
|
const visible = !prop.hidden && typeof entity[prop.name] !== 'undefined';
|
|
87
|
-
const populated = root.isMarkedAsPopulated(meta.
|
|
97
|
+
const populated = root.isMarkedAsPopulated(meta.class, prop.name);
|
|
88
98
|
if (visible) {
|
|
89
|
-
ret[this.propertyName(meta, prop.name,
|
|
99
|
+
ret[this.propertyName(meta, prop.name, raw)] = this.processProperty(prop.name, entity, raw, populated);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
}
|
|
@@ -95,15 +105,15 @@ export class EntityTransformer {
|
|
|
95
105
|
}
|
|
96
106
|
return ret;
|
|
97
107
|
}
|
|
98
|
-
static propertyName(meta, prop,
|
|
108
|
+
static propertyName(meta, prop, raw) {
|
|
99
109
|
if (raw) {
|
|
100
110
|
return prop;
|
|
101
111
|
}
|
|
102
112
|
if (meta.properties[prop].serializedName) {
|
|
103
113
|
return meta.properties[prop].serializedName;
|
|
104
114
|
}
|
|
105
|
-
if (meta.properties[prop].primary &&
|
|
106
|
-
return
|
|
115
|
+
if (meta.properties[prop].primary && meta.serializedPrimaryKey) {
|
|
116
|
+
return meta.serializedPrimaryKey;
|
|
107
117
|
}
|
|
108
118
|
return prop;
|
|
109
119
|
}
|