@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.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 +18 -13
- package/EntityManager.js +203 -203
- package/MikroORM.d.ts +7 -6
- package/MikroORM.js +33 -45
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +18 -26
- package/cache/GeneratedCacheAdapter.d.ts +2 -2
- package/cache/GeneratedCacheAdapter.js +1 -5
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +5 -5
- package/cache/index.js +5 -21
- package/connections/Connection.d.ts +7 -7
- package/connections/Connection.js +8 -12
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/decorators/Check.d.ts +1 -1
- package/decorators/Check.js +5 -8
- package/decorators/CreateRequestContext.d.ts +1 -1
- package/decorators/CreateRequestContext.js +13 -14
- package/decorators/Embeddable.d.ts +1 -1
- package/decorators/Embeddable.js +3 -6
- package/decorators/Embedded.d.ts +1 -1
- package/decorators/Embedded.js +10 -12
- package/decorators/Entity.d.ts +2 -2
- package/decorators/Entity.js +5 -8
- package/decorators/Enum.d.ts +2 -2
- package/decorators/Enum.js +7 -10
- package/decorators/Filter.d.ts +1 -1
- package/decorators/Filter.js +3 -6
- package/decorators/Formula.d.ts +2 -2
- package/decorators/Formula.js +7 -10
- package/decorators/Indexed.d.ts +2 -2
- package/decorators/Indexed.js +6 -10
- package/decorators/ManyToMany.d.ts +3 -3
- package/decorators/ManyToMany.js +10 -12
- package/decorators/ManyToOne.d.ts +3 -3
- package/decorators/ManyToOne.js +10 -12
- package/decorators/OneToMany.d.ts +3 -3
- package/decorators/OneToMany.js +11 -14
- package/decorators/OneToOne.d.ts +4 -4
- package/decorators/OneToOne.js +4 -7
- package/decorators/PrimaryKey.d.ts +2 -2
- package/decorators/PrimaryKey.js +10 -13
- package/decorators/Property.d.ts +5 -5
- package/decorators/Property.js +10 -12
- package/decorators/Transactional.d.ts +2 -2
- package/decorators/Transactional.js +7 -10
- package/decorators/hooks.js +23 -35
- package/decorators/index.d.ts +17 -17
- package/decorators/index.js +17 -36
- package/drivers/DatabaseDriver.d.ts +13 -12
- package/drivers/DatabaseDriver.js +60 -64
- package/drivers/IDatabaseDriver.d.ts +12 -12
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/ArrayCollection.d.ts +2 -2
- package/entity/ArrayCollection.js +29 -33
- package/entity/BaseEntity.d.ts +6 -6
- package/entity/BaseEntity.js +17 -21
- package/entity/Collection.d.ts +6 -6
- package/entity/Collection.js +40 -44
- package/entity/EntityAssigner.d.ts +2 -2
- package/entity/EntityAssigner.js +58 -63
- package/entity/EntityFactory.d.ts +3 -3
- package/entity/EntityFactory.js +58 -62
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +41 -45
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +5 -5
- package/entity/EntityLoader.js +92 -96
- package/entity/EntityRepository.d.ts +7 -7
- package/entity/EntityRepository.js +7 -11
- package/entity/EntityValidator.d.ts +1 -1
- package/entity/EntityValidator.js +25 -29
- package/entity/Reference.d.ts +2 -2
- package/entity/Reference.js +35 -42
- package/entity/WrappedEntity.d.ts +12 -12
- package/entity/WrappedEntity.js +23 -27
- package/entity/index.d.ts +13 -13
- package/entity/index.js +13 -29
- package/entity/utils.d.ts +1 -1
- package/entity/utils.js +9 -12
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +3 -3
- package/enums.js +37 -41
- package/errors.d.ts +1 -1
- package/errors.js +15 -24
- package/events/EventManager.d.ts +3 -3
- package/events/EventManager.js +8 -12
- package/events/EventSubscriber.d.ts +5 -4
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +3 -6
- package/hydration/ObjectHydrator.d.ts +3 -3
- package/hydration/ObjectHydrator.js +25 -28
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +21 -46
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +9 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +2 -2
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +4 -4
- package/logging/index.js +4 -20
- package/metadata/EntitySchema.d.ts +12 -4
- package/metadata/EntitySchema.js +41 -45
- package/metadata/MetadataDiscovery.d.ts +7 -7
- package/metadata/MetadataDiscovery.js +174 -177
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +4 -7
- package/metadata/MetadataStorage.d.ts +2 -2
- package/metadata/MetadataStorage.js +15 -19
- package/metadata/MetadataValidator.d.ts +4 -4
- package/metadata/MetadataValidator.js +49 -53
- package/metadata/ReflectMetadataProvider.d.ts +2 -2
- package/metadata/ReflectMetadataProvider.js +8 -12
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +4 -8
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +1 -1
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/package.json +5 -14
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +10 -10
- package/platforms/Platform.js +57 -61
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +2 -2
- package/serialization/EntitySerializer.js +36 -41
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +27 -31
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +10 -14
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +7 -11
- package/types/BigIntType.d.ts +3 -3
- package/types/BigIntType.js +3 -6
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +2 -8
- package/types/BooleanType.d.ts +3 -3
- package/types/BooleanType.js +2 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +3 -3
- package/types/DecimalType.js +4 -7
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +3 -6
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +5 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +3 -3
- package/types/JsonType.js +2 -6
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +2 -2
- package/types/Type.js +5 -9
- package/types/Uint8ArrayType.d.ts +3 -3
- package/types/Uint8ArrayType.js +3 -9
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +22 -20
- package/typings.js +34 -38
- package/unit-of-work/ChangeSet.d.ts +1 -1
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -7
- package/unit-of-work/ChangeSetComputer.js +26 -30
- package/unit-of-work/ChangeSetPersister.d.ts +7 -6
- package/unit-of-work/ChangeSetPersister.js +44 -47
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +8 -7
- package/unit-of-work/UnitOfWork.js +171 -172
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +6 -6
- package/utils/AbstractSchemaGenerator.js +7 -11
- package/utils/Configuration.d.ts +26 -27
- package/utils/Configuration.js +50 -55
- package/utils/ConfigurationLoader.d.ts +9 -8
- package/utils/ConfigurationLoader.js +71 -86
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +22 -25
- package/utils/DataloaderUtils.d.ts +4 -4
- package/utils/DataloaderUtils.js +12 -16
- package/utils/EntityComparator.d.ts +2 -2
- package/utils/EntityComparator.js +48 -52
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +3 -3
- package/utils/QueryHelper.js +47 -51
- package/utils/RawQueryFragment.d.ts +1 -1
- package/utils/RawQueryFragment.js +16 -24
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/Utils.d.ts +16 -12
- package/utils/Utils.js +89 -93
- package/utils/clone.js +8 -11
- package/utils/index.d.ts +13 -13
- package/utils/index.js +13 -29
- package/utils/resolveContextProvider.d.ts +3 -3
- package/utils/resolveContextProvider.js +9 -12
- package/utils/upsert-utils.d.ts +3 -3
- package/utils/upsert-utils.js +5 -9
- package/index.mjs +0 -199
package/naming-strategy/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./NamingStrategy"), exports);
|
|
18
|
-
__exportStar(require("./AbstractNamingStrategy"), exports);
|
|
19
|
-
__exportStar(require("./MongoNamingStrategy"), exports);
|
|
20
|
-
__exportStar(require("./UnderscoreNamingStrategy"), exports);
|
|
21
|
-
__exportStar(require("./EntityCaseNamingStrategy"), exports);
|
|
1
|
+
export * from './NamingStrategy.js';
|
|
2
|
+
export * from './AbstractNamingStrategy.js';
|
|
3
|
+
export * from './MongoNamingStrategy.js';
|
|
4
|
+
export * from './UnderscoreNamingStrategy.js';
|
|
5
|
+
export * from './EntityCaseNamingStrategy.js';
|
package/package.json
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "7.0.0-dev.3",
|
|
4
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.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"module": "index.mjs",
|
|
7
|
-
"typings": "index.d.ts",
|
|
8
6
|
"exports": {
|
|
9
7
|
"./package.json": "./package.json",
|
|
10
|
-
".":
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./index.d.ts",
|
|
13
|
-
"default": "./index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"require": "./index.js"
|
|
16
|
-
}
|
|
8
|
+
".": "./index.js"
|
|
17
9
|
},
|
|
18
10
|
"repository": {
|
|
19
11
|
"type": "git",
|
|
@@ -50,7 +42,7 @@
|
|
|
50
42
|
"node": ">= 22.11.0"
|
|
51
43
|
},
|
|
52
44
|
"scripts": {
|
|
53
|
-
"build": "yarn clean && yarn compile && yarn copy
|
|
45
|
+
"build": "yarn clean && yarn compile && yarn copy",
|
|
54
46
|
"clean": "yarn run -T rimraf ./dist",
|
|
55
47
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
56
48
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -62,9 +54,8 @@
|
|
|
62
54
|
"dataloader": "2.2.3",
|
|
63
55
|
"dotenv": "16.4.7",
|
|
64
56
|
"esprima": "4.0.1",
|
|
65
|
-
"fs-extra": "11.3.0",
|
|
66
57
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "7.0.0-dev.
|
|
58
|
+
"mikro-orm": "7.0.0-dev.3",
|
|
68
59
|
"reflect-metadata": "0.2.2"
|
|
69
60
|
}
|
|
70
61
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Dictionary } from '../typings';
|
|
2
|
-
import { DriverException } from '../exceptions';
|
|
1
|
+
import type { Dictionary } from '../typings.js';
|
|
2
|
+
import { DriverException } from '../exceptions.js';
|
|
3
3
|
export declare class ExceptionConverter {
|
|
4
4
|
convertException(exception: Error & Dictionary): DriverException;
|
|
5
5
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const exceptions_1 = require("../exceptions");
|
|
5
|
-
class ExceptionConverter {
|
|
6
|
-
/* istanbul ignore next */
|
|
1
|
+
import { DriverException } from '../exceptions.js';
|
|
2
|
+
export class ExceptionConverter {
|
|
3
|
+
/* v8 ignore next 3 */
|
|
7
4
|
convertException(exception) {
|
|
8
|
-
return new
|
|
5
|
+
return new DriverException(exception);
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
exports.ExceptionConverter = ExceptionConverter;
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
import { EntityRepository } from '../entity';
|
|
3
|
-
import { type NamingStrategy } from '../naming-strategy';
|
|
4
|
-
import type { Constructor, EntityProperty, IPrimaryKey, ISchemaGenerator, PopulateOptions, Primary, EntityMetadata, SimpleColumnMeta } from '../typings';
|
|
5
|
-
import { ExceptionConverter } from './ExceptionConverter';
|
|
6
|
-
import type { EntityManager } from '../EntityManager';
|
|
7
|
-
import type { Configuration } from '../utils/Configuration';
|
|
8
|
-
import type { IDatabaseDriver } from '../drivers/IDatabaseDriver';
|
|
9
|
-
import { Type } from '../types';
|
|
10
|
-
import type { MikroORM } from '../MikroORM';
|
|
11
|
-
import type { TransformContext } from '../types/Type';
|
|
2
|
+
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
3
|
+
import { type NamingStrategy } from '../naming-strategy/NamingStrategy.js';
|
|
4
|
+
import type { Constructor, EntityProperty, IPrimaryKey, ISchemaGenerator, PopulateOptions, Primary, EntityMetadata, SimpleColumnMeta } from '../typings.js';
|
|
5
|
+
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
7
|
+
import type { Configuration } from '../utils/Configuration.js';
|
|
8
|
+
import type { IDatabaseDriver } from '../drivers/IDatabaseDriver.js';
|
|
9
|
+
import { Type } from '../types/index.js';
|
|
10
|
+
import type { MikroORM } from '../MikroORM.js';
|
|
11
|
+
import type { TransformContext } from '../types/Type.js';
|
|
12
12
|
export declare const JsonProperty: unique symbol;
|
|
13
13
|
export declare abstract class Platform {
|
|
14
14
|
protected readonly exceptionConverter: ExceptionConverter;
|
package/platforms/Platform.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.JsonProperty = Symbol('JsonProperty');
|
|
14
|
-
class Platform {
|
|
15
|
-
exceptionConverter = new ExceptionConverter_1.ExceptionConverter();
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { clone } from '../utils/clone.js';
|
|
3
|
+
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
4
|
+
import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
|
|
5
|
+
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
|
+
import { ArrayType, BigIntType, BlobType, Uint8ArrayType, BooleanType, CharacterType, DateType, DecimalType, DoubleType, JsonType, SmallIntType, TimeType, TinyIntType, Type, UuidType, StringType, IntegerType, FloatType, DateTimeType, TextType, EnumType, UnknownType, MediumIntType, IntervalType, } from '../types/index.js';
|
|
7
|
+
import { parseJsonSafe, Utils } from '../utils/Utils.js';
|
|
8
|
+
import { ReferenceKind } from '../enums.js';
|
|
9
|
+
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
10
|
+
export const JsonProperty = Symbol('JsonProperty');
|
|
11
|
+
export class Platform {
|
|
12
|
+
exceptionConverter = new ExceptionConverter();
|
|
16
13
|
config;
|
|
17
14
|
namingStrategy;
|
|
18
15
|
timezone;
|
|
@@ -26,7 +23,7 @@ class Platform {
|
|
|
26
23
|
return true;
|
|
27
24
|
}
|
|
28
25
|
getNamingStrategy() {
|
|
29
|
-
return
|
|
26
|
+
return UnderscoreNamingStrategy;
|
|
30
27
|
}
|
|
31
28
|
usesReturningStatement() {
|
|
32
29
|
return false;
|
|
@@ -172,7 +169,7 @@ class Platform {
|
|
|
172
169
|
return `text`;
|
|
173
170
|
}
|
|
174
171
|
getEnumTypeDeclarationSQL(column) {
|
|
175
|
-
if (column.items?.every(item =>
|
|
172
|
+
if (column.items?.every(item => Utils.isString(item))) {
|
|
176
173
|
return `enum('${column.items.join("','")}')`;
|
|
177
174
|
}
|
|
178
175
|
return this.getTinyIntTypeDeclarationSQL(column);
|
|
@@ -207,39 +204,39 @@ class Platform {
|
|
|
207
204
|
}
|
|
208
205
|
getDefaultMappedType(type) {
|
|
209
206
|
if (type.endsWith('[]')) {
|
|
210
|
-
return
|
|
207
|
+
return Type.getType(ArrayType);
|
|
211
208
|
}
|
|
212
209
|
switch (this.extractSimpleType(type)) {
|
|
213
210
|
case 'character':
|
|
214
|
-
case 'char': return
|
|
211
|
+
case 'char': return Type.getType(CharacterType);
|
|
215
212
|
case 'string':
|
|
216
|
-
case 'varchar': return
|
|
217
|
-
case 'interval': return
|
|
218
|
-
case 'text': return
|
|
213
|
+
case 'varchar': return Type.getType(StringType);
|
|
214
|
+
case 'interval': return Type.getType(IntervalType);
|
|
215
|
+
case 'text': return Type.getType(TextType);
|
|
219
216
|
case 'int':
|
|
220
|
-
case 'number': return
|
|
221
|
-
case 'bigint': return
|
|
222
|
-
case 'smallint': return
|
|
223
|
-
case 'tinyint': return
|
|
224
|
-
case 'mediumint': return
|
|
225
|
-
case 'float': return
|
|
226
|
-
case 'double': return
|
|
227
|
-
case 'integer': return
|
|
217
|
+
case 'number': return Type.getType(IntegerType);
|
|
218
|
+
case 'bigint': return Type.getType(BigIntType);
|
|
219
|
+
case 'smallint': return Type.getType(SmallIntType);
|
|
220
|
+
case 'tinyint': return Type.getType(TinyIntType);
|
|
221
|
+
case 'mediumint': return Type.getType(MediumIntType);
|
|
222
|
+
case 'float': return Type.getType(FloatType);
|
|
223
|
+
case 'double': return Type.getType(DoubleType);
|
|
224
|
+
case 'integer': return Type.getType(IntegerType);
|
|
228
225
|
case 'decimal':
|
|
229
|
-
case 'numeric': return
|
|
230
|
-
case 'boolean': return
|
|
226
|
+
case 'numeric': return Type.getType(DecimalType);
|
|
227
|
+
case 'boolean': return Type.getType(BooleanType);
|
|
231
228
|
case 'blob':
|
|
232
|
-
case 'buffer': return
|
|
233
|
-
case 'uint8array': return
|
|
234
|
-
case 'uuid': return
|
|
235
|
-
case 'date': return
|
|
229
|
+
case 'buffer': return Type.getType(BlobType);
|
|
230
|
+
case 'uint8array': return Type.getType(Uint8ArrayType);
|
|
231
|
+
case 'uuid': return Type.getType(UuidType);
|
|
232
|
+
case 'date': return Type.getType(DateType);
|
|
236
233
|
case 'datetime':
|
|
237
|
-
case 'timestamp': return
|
|
238
|
-
case 'time': return
|
|
234
|
+
case 'timestamp': return Type.getType(DateTimeType);
|
|
235
|
+
case 'time': return Type.getType(TimeType);
|
|
239
236
|
case 'object':
|
|
240
|
-
case 'json': return
|
|
241
|
-
case 'enum': return
|
|
242
|
-
default: return
|
|
237
|
+
case 'json': return Type.getType(JsonType);
|
|
238
|
+
case 'enum': return Type.getType(EnumType);
|
|
239
|
+
default: return Type.getType(UnknownType);
|
|
243
240
|
}
|
|
244
241
|
}
|
|
245
242
|
supportsMultipleCascadePaths() {
|
|
@@ -272,7 +269,7 @@ class Platform {
|
|
|
272
269
|
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
273
270
|
return path.join('.');
|
|
274
271
|
}
|
|
275
|
-
/*
|
|
272
|
+
/* v8 ignore next 3 */
|
|
276
273
|
getJsonIndexDefinition(index) {
|
|
277
274
|
return index.columnNames;
|
|
278
275
|
}
|
|
@@ -296,7 +293,7 @@ class Platform {
|
|
|
296
293
|
if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
|
|
297
294
|
return value;
|
|
298
295
|
}
|
|
299
|
-
return
|
|
296
|
+
return parseJsonSafe(value);
|
|
300
297
|
}
|
|
301
298
|
convertDateToJSValue(value) {
|
|
302
299
|
return value;
|
|
@@ -309,14 +306,14 @@ class Platform {
|
|
|
309
306
|
}
|
|
310
307
|
parseDate(value) {
|
|
311
308
|
const date = new Date(value);
|
|
312
|
-
/*
|
|
309
|
+
/* v8 ignore next 3 */
|
|
313
310
|
if (isNaN(date.getTime())) {
|
|
314
311
|
return value;
|
|
315
312
|
}
|
|
316
313
|
return date;
|
|
317
314
|
}
|
|
318
315
|
getRepositoryClass() {
|
|
319
|
-
return
|
|
316
|
+
return EntityRepository;
|
|
320
317
|
}
|
|
321
318
|
getDefaultCharset() {
|
|
322
319
|
return 'utf8';
|
|
@@ -339,19 +336,19 @@ class Platform {
|
|
|
339
336
|
if (extension) {
|
|
340
337
|
return extension;
|
|
341
338
|
}
|
|
342
|
-
/*
|
|
343
|
-
const module =
|
|
339
|
+
/* v8 ignore next 4 */
|
|
340
|
+
const module = Utils.tryRequire({
|
|
344
341
|
module: moduleName,
|
|
345
342
|
warning: `Please install ${moduleName} package.`,
|
|
346
343
|
});
|
|
347
|
-
/*
|
|
344
|
+
/* v8 ignore next 3 */
|
|
348
345
|
if (module) {
|
|
349
346
|
return this.config.getCachedService(module[extensionName], em);
|
|
350
347
|
}
|
|
351
|
-
/*
|
|
348
|
+
/* v8 ignore next 2 */
|
|
352
349
|
throw new Error(`${extensionName} extension not registered.`);
|
|
353
350
|
}
|
|
354
|
-
/*
|
|
351
|
+
/* v8 ignore next 3: kept for type inference only */
|
|
355
352
|
getSchemaGenerator(driver, em) {
|
|
356
353
|
throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
|
|
357
354
|
}
|
|
@@ -359,7 +356,7 @@ class Platform {
|
|
|
359
356
|
return value;
|
|
360
357
|
}
|
|
361
358
|
quoteIdentifier(id, quote = '`') {
|
|
362
|
-
const raw =
|
|
359
|
+
const raw = RawQueryFragment.getKnownFragment(id);
|
|
363
360
|
if (raw) {
|
|
364
361
|
return this.formatQuery(raw.sql, raw.params);
|
|
365
362
|
}
|
|
@@ -368,7 +365,7 @@ class Platform {
|
|
|
368
365
|
quoteValue(value) {
|
|
369
366
|
return value;
|
|
370
367
|
}
|
|
371
|
-
/*
|
|
368
|
+
/* v8 ignore next 3 */
|
|
372
369
|
escape(value) {
|
|
373
370
|
return value;
|
|
374
371
|
}
|
|
@@ -412,9 +409,9 @@ class Platform {
|
|
|
412
409
|
return ret;
|
|
413
410
|
}
|
|
414
411
|
cloneEmbeddable(data) {
|
|
415
|
-
const copy =
|
|
412
|
+
const copy = clone(data);
|
|
416
413
|
// tag the copy so we know it should be stringified when quoting (so we know how to treat JSON arrays)
|
|
417
|
-
Object.defineProperty(copy,
|
|
414
|
+
Object.defineProperty(copy, JsonProperty, { enumerable: false, value: true });
|
|
418
415
|
return copy;
|
|
419
416
|
}
|
|
420
417
|
setConfig(config) {
|
|
@@ -438,7 +435,7 @@ class Platform {
|
|
|
438
435
|
return numericMappedType || prop.type === 'number' || this.isBigIntProperty(prop);
|
|
439
436
|
}
|
|
440
437
|
isNumericColumn(mappedType) {
|
|
441
|
-
return [
|
|
438
|
+
return [IntegerType, SmallIntType, BigIntType, TinyIntType].some(t => mappedType instanceof t);
|
|
442
439
|
}
|
|
443
440
|
supportsUnsigned() {
|
|
444
441
|
return false;
|
|
@@ -474,13 +471,13 @@ class Platform {
|
|
|
474
471
|
if (prop.lazy && (populate === false || (populate !== true && !populate.some(p => p.field === prop.name)))) {
|
|
475
472
|
return false;
|
|
476
473
|
}
|
|
477
|
-
if ([
|
|
474
|
+
if ([ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
|
|
478
475
|
return true;
|
|
479
476
|
}
|
|
480
|
-
if (prop.kind ===
|
|
477
|
+
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
481
478
|
return !!prop.object;
|
|
482
479
|
}
|
|
483
|
-
return prop.kind ===
|
|
480
|
+
return prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner;
|
|
484
481
|
}
|
|
485
482
|
/**
|
|
486
483
|
* Currently not supported due to how knex does complex sqlite diffing (always based on current schema)
|
|
@@ -525,10 +522,9 @@ class Platform {
|
|
|
525
522
|
clone() {
|
|
526
523
|
return this;
|
|
527
524
|
}
|
|
528
|
-
/*
|
|
525
|
+
/* v8 ignore next 4 */
|
|
529
526
|
/** @ignore */
|
|
530
|
-
[
|
|
527
|
+
[inspect.custom]() {
|
|
531
528
|
return `[${this.constructor.name}]`;
|
|
532
529
|
}
|
|
533
530
|
}
|
|
534
|
-
exports.Platform = Platform;
|
package/platforms/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './Platform';
|
|
2
|
-
export * from './ExceptionConverter';
|
|
1
|
+
export * from './Platform.js';
|
|
2
|
+
export * from './ExceptionConverter.js';
|
package/platforms/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Platform"), exports);
|
|
18
|
-
__exportStar(require("./ExceptionConverter"), exports);
|
|
1
|
+
export * from './Platform.js';
|
|
2
|
+
export * from './ExceptionConverter.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArrayElement, AutoPath, CleanTypeConfig, EntityDTO, FromEntityType, Loaded, TypeConfig, UnboxArray } from '../typings';
|
|
2
|
-
import { type PopulatePath } from '../enums';
|
|
1
|
+
import type { ArrayElement, AutoPath, CleanTypeConfig, EntityDTO, FromEntityType, Loaded, TypeConfig, UnboxArray } from '../typings.js';
|
|
2
|
+
import { type PopulatePath } from '../enums.js';
|
|
3
3
|
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;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const enums_1 = require("../enums");
|
|
8
|
-
const Reference_1 = require("../entity/Reference");
|
|
9
|
-
const SerializationContext_1 = require("./SerializationContext");
|
|
10
|
-
const RawQueryFragment_1 = require("../utils/RawQueryFragment");
|
|
1
|
+
import { helper } from '../entity/wrap.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
import { ReferenceKind } from '../enums.js';
|
|
4
|
+
import { Reference } from '../entity/Reference.js';
|
|
5
|
+
import { SerializationContext } from './SerializationContext.js';
|
|
6
|
+
import { isRaw } from '../utils/RawQueryFragment.js';
|
|
11
7
|
function isVisible(meta, propName, options) {
|
|
12
8
|
const prop = meta.properties[propName];
|
|
13
9
|
if (options.groups && prop?.groups) {
|
|
@@ -32,21 +28,21 @@ function isPopulated(propName, options) {
|
|
|
32
28
|
}
|
|
33
29
|
return false;
|
|
34
30
|
}
|
|
35
|
-
class EntitySerializer {
|
|
31
|
+
export class EntitySerializer {
|
|
36
32
|
static serialize(entity, options = {}) {
|
|
37
|
-
const wrapped =
|
|
33
|
+
const wrapped = helper(entity);
|
|
38
34
|
const meta = wrapped.__meta;
|
|
39
35
|
let contextCreated = false;
|
|
40
36
|
if (!wrapped.__serializationContext.root) {
|
|
41
|
-
const root = new
|
|
42
|
-
|
|
43
|
-
options.populate = (options.populate ?
|
|
37
|
+
const root = new SerializationContext(wrapped.__config);
|
|
38
|
+
SerializationContext.propagate(root, entity, (meta, prop) => meta.properties[prop]?.kind !== ReferenceKind.SCALAR);
|
|
39
|
+
options.populate = (options.populate ? Utils.asArray(options.populate) : options.populate);
|
|
44
40
|
contextCreated = true;
|
|
45
41
|
}
|
|
46
42
|
const root = wrapped.__serializationContext.root;
|
|
47
43
|
const ret = {};
|
|
48
44
|
const keys = new Set(meta.primaryKeys);
|
|
49
|
-
|
|
45
|
+
Utils.keys(entity).forEach(prop => keys.add(prop));
|
|
50
46
|
const visited = root.visited.has(entity);
|
|
51
47
|
if (!visited) {
|
|
52
48
|
root.visited.add(entity);
|
|
@@ -63,10 +59,10 @@ class EntitySerializer {
|
|
|
63
59
|
if (!cycle) {
|
|
64
60
|
root.leave(meta.className, prop);
|
|
65
61
|
}
|
|
66
|
-
if (options.skipNull &&
|
|
67
|
-
|
|
62
|
+
if (options.skipNull && Utils.isPlainObject(val)) {
|
|
63
|
+
Utils.dropUndefinedProperties(val, null);
|
|
68
64
|
}
|
|
69
|
-
if (
|
|
65
|
+
if (isRaw(val)) {
|
|
70
66
|
throw new Error(`Trying to serialize raw SQL fragment: '${val.sql}'`);
|
|
71
67
|
}
|
|
72
68
|
const visible = typeof val !== 'undefined' && !(val === null && options.skipNull);
|
|
@@ -99,7 +95,7 @@ class EntitySerializer {
|
|
|
99
95
|
return ret;
|
|
100
96
|
}
|
|
101
97
|
static propertyName(meta, prop, platform) {
|
|
102
|
-
/*
|
|
98
|
+
/* v8 ignore next 3 */
|
|
103
99
|
if (meta.properties[prop]?.serializedName) {
|
|
104
100
|
return meta.properties[prop].serializedName;
|
|
105
101
|
}
|
|
@@ -111,7 +107,7 @@ class EntitySerializer {
|
|
|
111
107
|
static processProperty(prop, entity, options) {
|
|
112
108
|
const parts = prop.split('.');
|
|
113
109
|
prop = parts[0];
|
|
114
|
-
const wrapped =
|
|
110
|
+
const wrapped = helper(entity);
|
|
115
111
|
const property = wrapped.__meta.properties[prop] ?? { name: prop };
|
|
116
112
|
const serializer = property?.serializer;
|
|
117
113
|
const value = entity[prop];
|
|
@@ -123,26 +119,26 @@ class EntitySerializer {
|
|
|
123
119
|
}
|
|
124
120
|
return returnValue;
|
|
125
121
|
}
|
|
126
|
-
/*
|
|
122
|
+
/* v8 ignore next 3 */
|
|
127
123
|
if (!options.ignoreSerializers && serializer) {
|
|
128
124
|
return serializer(value);
|
|
129
125
|
}
|
|
130
|
-
if (
|
|
126
|
+
if (Utils.isCollection(value)) {
|
|
131
127
|
return this.processCollection(property, entity, options);
|
|
132
128
|
}
|
|
133
|
-
if (
|
|
129
|
+
if (Utils.isEntity(value, true)) {
|
|
134
130
|
return this.processEntity(property, entity, wrapped.__platform, options);
|
|
135
131
|
}
|
|
136
|
-
if (
|
|
132
|
+
if (Utils.isScalarReference(value)) {
|
|
137
133
|
return value.unwrap();
|
|
138
134
|
}
|
|
139
|
-
/*
|
|
140
|
-
if (property?.kind ===
|
|
135
|
+
/* v8 ignore next 9 */
|
|
136
|
+
if (property?.kind === ReferenceKind.EMBEDDED) {
|
|
141
137
|
if (Array.isArray(value)) {
|
|
142
|
-
return value.map(item =>
|
|
138
|
+
return value.map(item => helper(item).toJSON());
|
|
143
139
|
}
|
|
144
|
-
if (
|
|
145
|
-
return
|
|
140
|
+
if (Utils.isObject(value)) {
|
|
141
|
+
return helper(value).toJSON();
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
144
|
const customType = property?.customType;
|
|
@@ -154,13 +150,13 @@ class EntitySerializer {
|
|
|
154
150
|
static extractChildOptions(options, prop) {
|
|
155
151
|
return {
|
|
156
152
|
...options,
|
|
157
|
-
populate: Array.isArray(options.populate) ?
|
|
158
|
-
exclude: Array.isArray(options.exclude) ?
|
|
153
|
+
populate: Array.isArray(options.populate) ? Utils.extractChildElements(options.populate, prop, '*') : options.populate,
|
|
154
|
+
exclude: Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop) : options.exclude,
|
|
159
155
|
};
|
|
160
156
|
}
|
|
161
157
|
static processEntity(prop, entity, platform, options) {
|
|
162
|
-
const child =
|
|
163
|
-
const wrapped =
|
|
158
|
+
const child = Reference.unwrapReference(entity[prop.name]);
|
|
159
|
+
const wrapped = helper(child);
|
|
164
160
|
const populated = isPopulated(prop.name, options) && wrapped.isInitialized();
|
|
165
161
|
const expand = populated || !wrapped.__managed;
|
|
166
162
|
const meta = wrapped.__meta;
|
|
@@ -174,10 +170,10 @@ class EntitySerializer {
|
|
|
174
170
|
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
175
171
|
}
|
|
176
172
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
177
|
-
return
|
|
173
|
+
return Utils.primaryKeyToObject(meta, pk, visible);
|
|
178
174
|
}
|
|
179
|
-
if (
|
|
180
|
-
const pruned =
|
|
175
|
+
if (Utils.isPlainObject(pk)) {
|
|
176
|
+
const pruned = Utils.primaryKeyToObject(meta, pk, visible);
|
|
181
177
|
if (visible.length === 1) {
|
|
182
178
|
return platform.normalizePrimaryKey(pruned[visible[0]]);
|
|
183
179
|
}
|
|
@@ -192,7 +188,7 @@ class EntitySerializer {
|
|
|
192
188
|
}
|
|
193
189
|
return col.getItems(false).map(item => {
|
|
194
190
|
const populated = isPopulated(prop.name, options);
|
|
195
|
-
const wrapped =
|
|
191
|
+
const wrapped = helper(item);
|
|
196
192
|
if (populated || !wrapped.__managed) {
|
|
197
193
|
return this.serialize(item, this.extractChildOptions(options, prop.name));
|
|
198
194
|
}
|
|
@@ -201,13 +197,12 @@ class EntitySerializer {
|
|
|
201
197
|
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
202
198
|
}
|
|
203
199
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
204
|
-
return
|
|
200
|
+
return Utils.primaryKeyToObject(wrapped.__meta, pk);
|
|
205
201
|
}
|
|
206
202
|
return pk;
|
|
207
203
|
});
|
|
208
204
|
}
|
|
209
205
|
}
|
|
210
|
-
exports.EntitySerializer = EntitySerializer;
|
|
211
206
|
/**
|
|
212
207
|
* Converts entity instance to POJO, converting the `Collection`s to arrays and unwrapping the `Reference` wrapper, while respecting the serialization options.
|
|
213
208
|
* This method accepts either a single entity or an array of entities, and returns the corresponding POJO or an array of POJO.
|
|
@@ -220,7 +215,7 @@ exports.EntitySerializer = EntitySerializer;
|
|
|
220
215
|
* const dto2 = wrap(user).serialize({ exclude: ['id', 'email'], forceObject: true });
|
|
221
216
|
* ```
|
|
222
217
|
*/
|
|
223
|
-
function serialize(entities, options) {
|
|
218
|
+
export function serialize(entities, options) {
|
|
224
219
|
if (Array.isArray(entities)) {
|
|
225
220
|
return entities.map(e => EntitySerializer.serialize(e, options));
|
|
226
221
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityDTO, EntityKey } from '../typings';
|
|
1
|
+
import type { EntityDTO, EntityKey } from '../typings.js';
|
|
2
2
|
export declare class EntityTransformer {
|
|
3
3
|
static toObject<Entity extends object, Ignored extends EntityKey<Entity> = never>(entity: Entity, ignoreFields?: Ignored[], raw?: boolean): Omit<EntityDTO<Entity>, Ignored>;
|
|
4
4
|
private static propertyName;
|