@yandjin-mikro-orm/core 6.1.4-rc-sti-changes-1
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 +553 -0
- package/EntityManager.js +1736 -0
- package/LICENSE +21 -0
- package/MikroORM.d.ts +102 -0
- package/MikroORM.js +258 -0
- package/README.md +383 -0
- package/cache/CacheAdapter.d.ts +40 -0
- package/cache/CacheAdapter.js +2 -0
- package/cache/FileCacheAdapter.d.ts +31 -0
- package/cache/FileCacheAdapter.js +90 -0
- package/cache/GeneratedCacheAdapter.d.ts +25 -0
- package/cache/GeneratedCacheAdapter.js +38 -0
- package/cache/MemoryCacheAdapter.d.ts +24 -0
- package/cache/MemoryCacheAdapter.js +44 -0
- package/cache/NullCacheAdapter.d.ts +19 -0
- package/cache/NullCacheAdapter.js +30 -0
- package/cache/index.d.ts +5 -0
- package/cache/index.js +21 -0
- package/connections/Connection.d.ts +85 -0
- package/connections/Connection.js +128 -0
- package/connections/index.d.ts +1 -0
- package/connections/index.js +17 -0
- package/decorators/Check.d.ts +3 -0
- package/decorators/Check.js +17 -0
- package/decorators/CreateRequestContext.d.ts +2 -0
- package/decorators/CreateRequestContext.js +31 -0
- package/decorators/Embeddable.d.ts +8 -0
- package/decorators/Embeddable.js +15 -0
- package/decorators/Embedded.d.ts +13 -0
- package/decorators/Embedded.js +21 -0
- package/decorators/EnsureRequestContext.d.ts +2 -0
- package/decorators/EnsureRequestContext.js +26 -0
- package/decorators/Entity.d.ts +18 -0
- package/decorators/Entity.js +17 -0
- package/decorators/Enum.d.ts +9 -0
- package/decorators/Enum.js +20 -0
- package/decorators/Filter.d.ts +2 -0
- package/decorators/Filter.js +12 -0
- package/decorators/Formula.d.ts +5 -0
- package/decorators/Formula.js +19 -0
- package/decorators/Indexed.d.ts +12 -0
- package/decorators/Indexed.js +25 -0
- package/decorators/ManyToMany.d.ts +21 -0
- package/decorators/ManyToMany.js +17 -0
- package/decorators/ManyToOne.d.ts +15 -0
- package/decorators/ManyToOne.js +17 -0
- package/decorators/OneToMany.d.ts +18 -0
- package/decorators/OneToMany.js +21 -0
- package/decorators/OneToOne.d.ts +12 -0
- package/decorators/OneToOne.js +11 -0
- package/decorators/PrimaryKey.d.ts +8 -0
- package/decorators/PrimaryKey.js +24 -0
- package/decorators/Property.d.ts +218 -0
- package/decorators/Property.js +35 -0
- package/decorators/Subscriber.d.ts +1 -0
- package/decorators/Subscriber.js +2 -0
- package/decorators/hooks.d.ts +16 -0
- package/decorators/hooks.js +60 -0
- package/decorators/index.d.ts +17 -0
- package/decorators/index.js +36 -0
- package/drivers/DatabaseDriver.d.ts +72 -0
- package/drivers/DatabaseDriver.js +358 -0
- package/drivers/IDatabaseDriver.d.ts +193 -0
- package/drivers/IDatabaseDriver.js +4 -0
- package/drivers/index.d.ts +2 -0
- package/drivers/index.js +18 -0
- package/entity/ArrayCollection.d.ts +113 -0
- package/entity/ArrayCollection.js +386 -0
- package/entity/BaseEntity.d.ts +22 -0
- package/entity/BaseEntity.js +47 -0
- package/entity/Collection.d.ts +104 -0
- package/entity/Collection.js +373 -0
- package/entity/EntityAssigner.d.ts +28 -0
- package/entity/EntityAssigner.js +226 -0
- package/entity/EntityFactory.d.ts +41 -0
- package/entity/EntityFactory.js +302 -0
- package/entity/EntityHelper.d.ts +29 -0
- package/entity/EntityHelper.js +250 -0
- package/entity/EntityIdentifier.d.ts +10 -0
- package/entity/EntityIdentifier.js +19 -0
- package/entity/EntityLoader.d.ts +65 -0
- package/entity/EntityLoader.js +579 -0
- package/entity/EntityRepository.d.ts +161 -0
- package/entity/EntityRepository.js +207 -0
- package/entity/EntityValidator.d.ts +19 -0
- package/entity/EntityValidator.js +152 -0
- package/entity/Reference.d.ts +89 -0
- package/entity/Reference.js +242 -0
- package/entity/WrappedEntity.d.ts +67 -0
- package/entity/WrappedEntity.js +146 -0
- package/entity/index.d.ts +13 -0
- package/entity/index.js +29 -0
- package/entity/wrap.d.ts +15 -0
- package/entity/wrap.js +26 -0
- package/enums.d.ts +160 -0
- package/enums.js +169 -0
- package/errors.d.ts +65 -0
- package/errors.js +222 -0
- package/events/EventManager.d.ts +17 -0
- package/events/EventManager.js +77 -0
- package/events/EventSubscriber.d.ts +39 -0
- package/events/EventSubscriber.js +2 -0
- package/events/TransactionEventBroadcaster.d.ts +11 -0
- package/events/TransactionEventBroadcaster.js +17 -0
- package/events/index.d.ts +3 -0
- package/events/index.js +19 -0
- package/exceptions.d.ts +104 -0
- package/exceptions.js +130 -0
- package/hydration/Hydrator.d.ts +23 -0
- package/hydration/Hydrator.js +51 -0
- package/hydration/ObjectHydrator.d.ts +24 -0
- package/hydration/ObjectHydrator.js +332 -0
- package/hydration/index.d.ts +2 -0
- package/hydration/index.js +18 -0
- package/index.d.ts +25 -0
- package/index.js +50 -0
- package/index.mjs +192 -0
- package/logging/DefaultLogger.d.ts +32 -0
- package/logging/DefaultLogger.js +90 -0
- package/logging/Logger.d.ts +56 -0
- package/logging/Logger.js +2 -0
- package/logging/SimpleLogger.d.ts +17 -0
- package/logging/SimpleLogger.js +31 -0
- package/logging/colors.d.ts +9 -0
- package/logging/colors.js +20 -0
- package/logging/index.d.ts +4 -0
- package/logging/index.js +20 -0
- package/metadata/EntitySchema.d.ts +74 -0
- package/metadata/EntitySchema.js +293 -0
- package/metadata/MetadataDiscovery.d.ts +71 -0
- package/metadata/MetadataDiscovery.js +1244 -0
- package/metadata/MetadataProvider.d.ts +11 -0
- package/metadata/MetadataProvider.js +23 -0
- package/metadata/MetadataStorage.d.ts +22 -0
- package/metadata/MetadataStorage.js +87 -0
- package/metadata/MetadataValidator.d.ts +24 -0
- package/metadata/MetadataValidator.js +213 -0
- package/metadata/ReflectMetadataProvider.d.ts +8 -0
- package/metadata/ReflectMetadataProvider.js +48 -0
- package/metadata/index.d.ts +6 -0
- package/metadata/index.js +22 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
- package/naming-strategy/AbstractNamingStrategy.js +48 -0
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
- package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
- package/naming-strategy/MongoNamingStrategy.js +25 -0
- package/naming-strategy/NamingStrategy.d.ts +52 -0
- package/naming-strategy/NamingStrategy.js +2 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
- package/naming-strategy/index.d.ts +5 -0
- package/naming-strategy/index.js +21 -0
- package/package.json +70 -0
- package/platforms/ExceptionConverter.d.ts +5 -0
- package/platforms/ExceptionConverter.js +11 -0
- package/platforms/Platform.d.ts +201 -0
- package/platforms/Platform.js +452 -0
- package/platforms/index.d.ts +2 -0
- package/platforms/index.js +18 -0
- package/serialization/EntitySerializer.d.ts +34 -0
- package/serialization/EntitySerializer.js +206 -0
- package/serialization/EntityTransformer.d.ts +8 -0
- package/serialization/EntityTransformer.js +192 -0
- package/serialization/SerializationContext.d.ts +30 -0
- package/serialization/SerializationContext.js +111 -0
- package/serialization/index.d.ts +3 -0
- package/serialization/index.js +19 -0
- package/types/ArrayType.d.ts +13 -0
- package/types/ArrayType.js +47 -0
- package/types/BigIntType.d.ts +16 -0
- package/types/BigIntType.js +45 -0
- package/types/BlobType.d.ts +10 -0
- package/types/BlobType.js +27 -0
- package/types/BooleanType.d.ts +8 -0
- package/types/BooleanType.js +16 -0
- package/types/DateTimeType.d.ts +8 -0
- package/types/DateTimeType.js +16 -0
- package/types/DateType.d.ts +8 -0
- package/types/DateType.js +16 -0
- package/types/DecimalType.d.ts +11 -0
- package/types/DecimalType.js +22 -0
- package/types/DoubleType.d.ts +11 -0
- package/types/DoubleType.js +22 -0
- package/types/EnumArrayType.d.ts +9 -0
- package/types/EnumArrayType.js +32 -0
- package/types/EnumType.d.ts +8 -0
- package/types/EnumType.js +16 -0
- package/types/FloatType.d.ts +8 -0
- package/types/FloatType.js +16 -0
- package/types/IntegerType.d.ts +8 -0
- package/types/IntegerType.js +16 -0
- package/types/IntervalType.d.ts +8 -0
- package/types/IntervalType.js +16 -0
- package/types/JsonType.d.ts +13 -0
- package/types/JsonType.js +34 -0
- package/types/MediumIntType.d.ts +6 -0
- package/types/MediumIntType.js +10 -0
- package/types/SmallIntType.d.ts +8 -0
- package/types/SmallIntType.js +16 -0
- package/types/StringType.d.ts +8 -0
- package/types/StringType.js +16 -0
- package/types/TextType.d.ts +8 -0
- package/types/TextType.js +16 -0
- package/types/TimeType.d.ts +9 -0
- package/types/TimeType.js +23 -0
- package/types/TinyIntType.d.ts +8 -0
- package/types/TinyIntType.js +16 -0
- package/types/Type.d.ts +64 -0
- package/types/Type.js +84 -0
- package/types/Uint8ArrayType.d.ts +11 -0
- package/types/Uint8ArrayType.js +37 -0
- package/types/UnknownType.d.ts +7 -0
- package/types/UnknownType.js +13 -0
- package/types/UuidType.d.ts +7 -0
- package/types/UuidType.js +13 -0
- package/types/index.d.ts +75 -0
- package/types/index.js +77 -0
- package/typings.d.ts +767 -0
- package/typings.js +198 -0
- package/unit-of-work/ChangeSet.d.ts +34 -0
- package/unit-of-work/ChangeSet.js +62 -0
- package/unit-of-work/ChangeSetComputer.d.ts +26 -0
- package/unit-of-work/ChangeSetComputer.js +153 -0
- package/unit-of-work/ChangeSetPersister.d.ts +50 -0
- package/unit-of-work/ChangeSetPersister.js +361 -0
- package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
- package/unit-of-work/CommitOrderCalculator.js +113 -0
- package/unit-of-work/IdentityMap.d.ts +17 -0
- package/unit-of-work/IdentityMap.js +84 -0
- package/unit-of-work/UnitOfWork.d.ts +124 -0
- package/unit-of-work/UnitOfWork.js +1013 -0
- package/unit-of-work/index.d.ts +6 -0
- package/unit-of-work/index.js +22 -0
- package/utils/AbstractSchemaGenerator.d.ts +38 -0
- package/utils/AbstractSchemaGenerator.js +101 -0
- package/utils/Configuration.d.ts +390 -0
- package/utils/Configuration.js +357 -0
- package/utils/ConfigurationLoader.d.ts +29 -0
- package/utils/ConfigurationLoader.js +282 -0
- package/utils/Cursor.d.ts +77 -0
- package/utils/Cursor.js +169 -0
- package/utils/DataloaderUtils.d.ts +43 -0
- package/utils/DataloaderUtils.js +194 -0
- package/utils/EntityComparator.d.ts +73 -0
- package/utils/EntityComparator.js +568 -0
- package/utils/NullHighlighter.d.ts +4 -0
- package/utils/NullHighlighter.js +9 -0
- package/utils/QueryHelper.d.ts +28 -0
- package/utils/QueryHelper.js +228 -0
- package/utils/RawQueryFragment.d.ts +96 -0
- package/utils/RawQueryFragment.js +188 -0
- package/utils/RequestContext.d.ts +34 -0
- package/utils/RequestContext.js +54 -0
- package/utils/TransactionContext.d.ts +19 -0
- package/utils/TransactionContext.js +34 -0
- package/utils/Utils.d.ts +274 -0
- package/utils/Utils.js +1073 -0
- package/utils/clone.d.ts +6 -0
- package/utils/clone.js +127 -0
- package/utils/index.d.ts +13 -0
- package/utils/index.js +29 -0
- package/utils/upsert-utils.d.ts +6 -0
- package/utils/upsert-utils.js +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Martin Adámek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/MikroORM.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { EntityManagerType, IDatabaseDriver } from './drivers';
|
|
2
|
+
import { MetadataStorage } from './metadata';
|
|
3
|
+
import { Configuration, type Options } from './utils';
|
|
4
|
+
import type { EntityManager } from './EntityManager';
|
|
5
|
+
import type { Constructor, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings';
|
|
6
|
+
/**
|
|
7
|
+
* Helper class for bootstrapping the MikroORM.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager> {
|
|
10
|
+
/** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
|
|
11
|
+
em: EM;
|
|
12
|
+
readonly config: Configuration<D>;
|
|
13
|
+
private metadata;
|
|
14
|
+
private readonly driver;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private readonly discovery;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
|
|
19
|
+
* If you omit the `options` parameter, your CLI config will be used.
|
|
20
|
+
*/
|
|
21
|
+
static init<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options?: Options<D, EM>): Promise<MikroORM<D, EM>>;
|
|
22
|
+
/**
|
|
23
|
+
* Synchronous variant of the `init` method with some limitations:
|
|
24
|
+
* - database connection will be established when you first interact with the database (or you can use `orm.connect()` explicitly)
|
|
25
|
+
* - no loading of the `config` file, `options` parameter is mandatory
|
|
26
|
+
* - no support for folder based discovery
|
|
27
|
+
* - no check for mismatched package versions
|
|
28
|
+
*/
|
|
29
|
+
static initSync<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options: Options<D, EM>): MikroORM<D, EM>;
|
|
30
|
+
constructor(options: Options<D, EM> | Configuration<D, EM>);
|
|
31
|
+
/**
|
|
32
|
+
* Connects to the database.
|
|
33
|
+
*/
|
|
34
|
+
connect(): Promise<D>;
|
|
35
|
+
/**
|
|
36
|
+
* Reconnects, possibly to a different database.
|
|
37
|
+
*/
|
|
38
|
+
reconnect(options?: Options): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Checks whether the database connection is active.
|
|
41
|
+
*/
|
|
42
|
+
isConnected(): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether the database connection is active, returns .
|
|
45
|
+
*/
|
|
46
|
+
checkConnection(): Promise<{
|
|
47
|
+
ok: boolean;
|
|
48
|
+
reason?: string;
|
|
49
|
+
error?: Error;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Closes the database connection.
|
|
53
|
+
*/
|
|
54
|
+
close(force?: boolean): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the `MetadataStorage`.
|
|
57
|
+
*/
|
|
58
|
+
getMetadata(): MetadataStorage;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the `EntityMetadata` instance when provided with the `entityName` parameter.
|
|
61
|
+
*/
|
|
62
|
+
getMetadata<Entity extends object>(entityName: EntityName<Entity>): EntityMetadata<Entity>;
|
|
63
|
+
discoverEntities(): Promise<void>;
|
|
64
|
+
discoverEntitiesSync(): void;
|
|
65
|
+
private createEntityManager;
|
|
66
|
+
/**
|
|
67
|
+
* Allows dynamically discovering new entity by reference, handy for testing schema diffing.
|
|
68
|
+
*/
|
|
69
|
+
discoverEntity(entities: Constructor | Constructor[]): void;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the SchemaGenerator.
|
|
72
|
+
*/
|
|
73
|
+
getSchemaGenerator(): ReturnType<ReturnType<D['getPlatform']>['getSchemaGenerator']>;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the EntityGenerator.
|
|
76
|
+
*/
|
|
77
|
+
getEntityGenerator<T extends IEntityGenerator = IEntityGenerator>(): T;
|
|
78
|
+
/**
|
|
79
|
+
* Gets the Migrator.
|
|
80
|
+
*/
|
|
81
|
+
getMigrator<T extends IMigrator = IMigrator>(): T;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the SeedManager
|
|
84
|
+
*/
|
|
85
|
+
getSeeder<T extends ISeedManager = ISeedManager>(): T;
|
|
86
|
+
/**
|
|
87
|
+
* Shortcut for `orm.getSchemaGenerator()`
|
|
88
|
+
*/
|
|
89
|
+
get schema(): ReturnType<ReturnType<D["getPlatform"]>["getSchemaGenerator"]>;
|
|
90
|
+
/**
|
|
91
|
+
* Shortcut for `orm.getSeeder()`
|
|
92
|
+
*/
|
|
93
|
+
get seeder(): ISeedManager;
|
|
94
|
+
/**
|
|
95
|
+
* Shortcut for `orm.getMigrator()`
|
|
96
|
+
*/
|
|
97
|
+
get migrator(): IMigrator;
|
|
98
|
+
/**
|
|
99
|
+
* Shortcut for `orm.getEntityGenerator()`
|
|
100
|
+
*/
|
|
101
|
+
get entityGenerator(): IEntityGenerator;
|
|
102
|
+
}
|
package/MikroORM.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MikroORM = void 0;
|
|
4
|
+
const metadata_1 = require("./metadata");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const logging_1 = require("./logging");
|
|
7
|
+
const cache_1 = require("./cache");
|
|
8
|
+
/**
|
|
9
|
+
* Helper class for bootstrapping the MikroORM.
|
|
10
|
+
*/
|
|
11
|
+
class MikroORM {
|
|
12
|
+
/** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
|
|
13
|
+
em;
|
|
14
|
+
config;
|
|
15
|
+
metadata;
|
|
16
|
+
driver;
|
|
17
|
+
logger;
|
|
18
|
+
discovery;
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
|
|
21
|
+
* If you omit the `options` parameter, your CLI config will be used.
|
|
22
|
+
*/
|
|
23
|
+
static async init(options) {
|
|
24
|
+
utils_1.ConfigurationLoader.registerDotenv(options);
|
|
25
|
+
const coreVersion = await utils_1.ConfigurationLoader.checkPackageVersion();
|
|
26
|
+
const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
|
|
27
|
+
if (!options) {
|
|
28
|
+
options = (await utils_1.ConfigurationLoader.getConfiguration()).getAll();
|
|
29
|
+
}
|
|
30
|
+
options = utils_1.Utils.mergeConfig(options, env);
|
|
31
|
+
await utils_1.ConfigurationLoader.commonJSCompat(options);
|
|
32
|
+
if ('DRIVER' in this && !options.driver) {
|
|
33
|
+
options.driver = this.DRIVER;
|
|
34
|
+
}
|
|
35
|
+
const orm = new MikroORM(options);
|
|
36
|
+
orm.logger.log('info', `MikroORM version: ${logging_1.colors.green(coreVersion)}`);
|
|
37
|
+
// we need to allow global context here as we are not in a scope of requests yet
|
|
38
|
+
const allowGlobalContext = orm.config.get('allowGlobalContext');
|
|
39
|
+
orm.config.set('allowGlobalContext', true);
|
|
40
|
+
await orm.discoverEntities();
|
|
41
|
+
orm.config.set('allowGlobalContext', allowGlobalContext);
|
|
42
|
+
orm.driver.getPlatform().lookupExtensions(orm);
|
|
43
|
+
if (orm.config.get('connect')) {
|
|
44
|
+
await orm.connect();
|
|
45
|
+
}
|
|
46
|
+
for (const extension of orm.config.get('extensions')) {
|
|
47
|
+
extension.register(orm);
|
|
48
|
+
}
|
|
49
|
+
if (orm.config.get('connect') && orm.config.get('ensureIndexes')) {
|
|
50
|
+
await orm.getSchemaGenerator().ensureIndexes();
|
|
51
|
+
}
|
|
52
|
+
return orm;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Synchronous variant of the `init` method with some limitations:
|
|
56
|
+
* - database connection will be established when you first interact with the database (or you can use `orm.connect()` explicitly)
|
|
57
|
+
* - no loading of the `config` file, `options` parameter is mandatory
|
|
58
|
+
* - no support for folder based discovery
|
|
59
|
+
* - no check for mismatched package versions
|
|
60
|
+
*/
|
|
61
|
+
static initSync(options) {
|
|
62
|
+
utils_1.ConfigurationLoader.registerDotenv(options);
|
|
63
|
+
const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
|
|
64
|
+
options = utils_1.Utils.merge(options, env);
|
|
65
|
+
if ('DRIVER' in this && !options.driver) {
|
|
66
|
+
options.driver = this.DRIVER;
|
|
67
|
+
}
|
|
68
|
+
const orm = new MikroORM(options);
|
|
69
|
+
// we need to allow global context here as we are not in a scope of requests yet
|
|
70
|
+
const allowGlobalContext = orm.config.get('allowGlobalContext');
|
|
71
|
+
orm.config.set('allowGlobalContext', true);
|
|
72
|
+
orm.discoverEntitiesSync();
|
|
73
|
+
orm.config.set('allowGlobalContext', allowGlobalContext);
|
|
74
|
+
orm.driver.getPlatform().lookupExtensions(orm);
|
|
75
|
+
for (const extension of orm.config.get('extensions')) {
|
|
76
|
+
extension.register(orm);
|
|
77
|
+
}
|
|
78
|
+
return orm;
|
|
79
|
+
}
|
|
80
|
+
constructor(options) {
|
|
81
|
+
if (options instanceof utils_1.Configuration) {
|
|
82
|
+
this.config = options;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.config = new utils_1.Configuration(options);
|
|
86
|
+
}
|
|
87
|
+
const discovery = this.config.get('discovery');
|
|
88
|
+
if (discovery.disableDynamicFileAccess) {
|
|
89
|
+
this.config.set('metadataProvider', metadata_1.ReflectMetadataProvider);
|
|
90
|
+
this.config.set('metadataCache', { adapter: cache_1.NullCacheAdapter });
|
|
91
|
+
discovery.requireEntitiesArray = true;
|
|
92
|
+
}
|
|
93
|
+
this.driver = this.config.getDriver();
|
|
94
|
+
this.logger = this.config.getLogger();
|
|
95
|
+
this.discovery = new metadata_1.MetadataDiscovery(new metadata_1.MetadataStorage(), this.driver.getPlatform(), this.config);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Connects to the database.
|
|
99
|
+
*/
|
|
100
|
+
async connect() {
|
|
101
|
+
const connection = await this.driver.connect();
|
|
102
|
+
const clientUrl = connection.getClientUrl();
|
|
103
|
+
const dbName = this.config.get('dbName');
|
|
104
|
+
const db = dbName + (clientUrl ? ' on ' + clientUrl : '');
|
|
105
|
+
if (this.config.get('ensureDatabase')) {
|
|
106
|
+
const options = this.config.get('ensureDatabase');
|
|
107
|
+
await this.schema.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
|
|
108
|
+
}
|
|
109
|
+
if (await this.isConnected()) {
|
|
110
|
+
this.logger.log('info', `MikroORM successfully connected to database ${logging_1.colors.green(db)}`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.logger.error('info', `MikroORM failed to connect to database ${db}`);
|
|
114
|
+
}
|
|
115
|
+
return this.driver;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Reconnects, possibly to a different database.
|
|
119
|
+
*/
|
|
120
|
+
async reconnect(options = {}) {
|
|
121
|
+
/* istanbul ignore next */
|
|
122
|
+
for (const key of utils_1.Utils.keys(options)) {
|
|
123
|
+
this.config.set(key, options[key]);
|
|
124
|
+
}
|
|
125
|
+
await this.driver.reconnect();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Checks whether the database connection is active.
|
|
129
|
+
*/
|
|
130
|
+
async isConnected() {
|
|
131
|
+
return this.driver.getConnection().isConnected();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Checks whether the database connection is active, returns .
|
|
135
|
+
*/
|
|
136
|
+
async checkConnection() {
|
|
137
|
+
return this.driver.getConnection().checkConnection();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Closes the database connection.
|
|
141
|
+
*/
|
|
142
|
+
async close(force = false) {
|
|
143
|
+
if (await this.isConnected()) {
|
|
144
|
+
await this.driver.close(force);
|
|
145
|
+
}
|
|
146
|
+
if (this.config.getMetadataCacheAdapter()?.close) {
|
|
147
|
+
await this.config.getMetadataCacheAdapter().close();
|
|
148
|
+
}
|
|
149
|
+
if (this.config.getResultCacheAdapter()?.close) {
|
|
150
|
+
await this.config.getResultCacheAdapter().close();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the `MetadataStorage` (without parameters) or `EntityMetadata` instance when provided with the `entityName` parameter.
|
|
155
|
+
*/
|
|
156
|
+
getMetadata(entityName) {
|
|
157
|
+
if (entityName) {
|
|
158
|
+
entityName = utils_1.Utils.className(entityName);
|
|
159
|
+
return this.metadata.get(entityName);
|
|
160
|
+
}
|
|
161
|
+
return this.metadata;
|
|
162
|
+
}
|
|
163
|
+
async discoverEntities() {
|
|
164
|
+
this.metadata = await this.discovery.discover(this.config.get('tsNode'));
|
|
165
|
+
this.createEntityManager();
|
|
166
|
+
}
|
|
167
|
+
discoverEntitiesSync() {
|
|
168
|
+
this.metadata = this.discovery.discoverSync(this.config.get('tsNode'));
|
|
169
|
+
this.createEntityManager();
|
|
170
|
+
}
|
|
171
|
+
createEntityManager() {
|
|
172
|
+
this.driver.setMetadata(this.metadata);
|
|
173
|
+
this.em = this.driver.createEntityManager();
|
|
174
|
+
this.em.global = true;
|
|
175
|
+
this.metadata.decorate(this.em);
|
|
176
|
+
this.driver.setMetadata(this.metadata);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Allows dynamically discovering new entity by reference, handy for testing schema diffing.
|
|
180
|
+
*/
|
|
181
|
+
discoverEntity(entities) {
|
|
182
|
+
entities = utils_1.Utils.asArray(entities);
|
|
183
|
+
const tmp = this.discovery.discoverReferences(entities);
|
|
184
|
+
const options = this.config.get('discovery');
|
|
185
|
+
new metadata_1.MetadataValidator().validateDiscovered([...Object.values(this.metadata.getAll()), ...tmp], options);
|
|
186
|
+
const metadata = this.discovery.processDiscoveredEntities(tmp);
|
|
187
|
+
metadata.forEach(meta => this.metadata.set(meta.className, meta));
|
|
188
|
+
this.metadata.decorate(this.em);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Gets the SchemaGenerator.
|
|
192
|
+
*/
|
|
193
|
+
getSchemaGenerator() {
|
|
194
|
+
const extension = this.config.getExtension('@mikro-orm/schema-generator');
|
|
195
|
+
if (extension) {
|
|
196
|
+
return extension;
|
|
197
|
+
}
|
|
198
|
+
/* istanbul ignore next */
|
|
199
|
+
throw new Error(`SchemaGenerator extension not registered.`);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Gets the EntityGenerator.
|
|
203
|
+
*/
|
|
204
|
+
getEntityGenerator() {
|
|
205
|
+
const extension = this.config.getExtension('@mikro-orm/entity-generator');
|
|
206
|
+
if (extension) {
|
|
207
|
+
return extension;
|
|
208
|
+
}
|
|
209
|
+
throw new Error(`EntityGenerator extension not registered.`);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Gets the Migrator.
|
|
213
|
+
*/
|
|
214
|
+
getMigrator() {
|
|
215
|
+
const extension = this.config.getExtension('@mikro-orm/migrator');
|
|
216
|
+
if (extension) {
|
|
217
|
+
return extension;
|
|
218
|
+
}
|
|
219
|
+
/* istanbul ignore next */
|
|
220
|
+
throw new Error(`Migrator extension not registered.`);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Gets the SeedManager
|
|
224
|
+
*/
|
|
225
|
+
getSeeder() {
|
|
226
|
+
const extension = this.config.getExtension('@mikro-orm/seeder');
|
|
227
|
+
if (extension) {
|
|
228
|
+
return extension;
|
|
229
|
+
}
|
|
230
|
+
/* istanbul ignore next */
|
|
231
|
+
throw new Error(`SeedManager extension not registered.`);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Shortcut for `orm.getSchemaGenerator()`
|
|
235
|
+
*/
|
|
236
|
+
get schema() {
|
|
237
|
+
return this.getSchemaGenerator();
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Shortcut for `orm.getSeeder()`
|
|
241
|
+
*/
|
|
242
|
+
get seeder() {
|
|
243
|
+
return this.getSeeder();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Shortcut for `orm.getMigrator()`
|
|
247
|
+
*/
|
|
248
|
+
get migrator() {
|
|
249
|
+
return this.getMigrator();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Shortcut for `orm.getEntityGenerator()`
|
|
253
|
+
*/
|
|
254
|
+
get entityGenerator() {
|
|
255
|
+
return this.getEntityGenerator();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.MikroORM = MikroORM;
|