@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
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineConfig = exports.Configuration = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const cache_1 = require("../cache");
|
|
6
|
+
const hydration_1 = require("../hydration");
|
|
7
|
+
const NullHighlighter_1 = require("../utils/NullHighlighter");
|
|
8
|
+
const logging_1 = require("../logging");
|
|
9
|
+
const Utils_1 = require("../utils/Utils");
|
|
10
|
+
const ReflectMetadataProvider_1 = require("../metadata/ReflectMetadataProvider");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
const RequestContext_1 = require("./RequestContext");
|
|
13
|
+
const enums_1 = require("../enums");
|
|
14
|
+
const MemoryCacheAdapter_1 = require("../cache/MemoryCacheAdapter");
|
|
15
|
+
const EntityComparator_1 = require("./EntityComparator");
|
|
16
|
+
class Configuration {
|
|
17
|
+
static DEFAULTS = {
|
|
18
|
+
pool: {},
|
|
19
|
+
entities: [],
|
|
20
|
+
entitiesTs: [],
|
|
21
|
+
extensions: [],
|
|
22
|
+
subscribers: [],
|
|
23
|
+
filters: {},
|
|
24
|
+
discovery: {
|
|
25
|
+
warnWhenNoEntities: true,
|
|
26
|
+
requireEntitiesArray: false,
|
|
27
|
+
checkDuplicateTableNames: true,
|
|
28
|
+
checkDuplicateFieldNames: true,
|
|
29
|
+
alwaysAnalyseProperties: true,
|
|
30
|
+
disableDynamicFileAccess: false,
|
|
31
|
+
checkDuplicateEntities: true,
|
|
32
|
+
inferDefaultValues: true,
|
|
33
|
+
},
|
|
34
|
+
strict: false,
|
|
35
|
+
validate: false,
|
|
36
|
+
validateRequired: true,
|
|
37
|
+
context: (name) => RequestContext_1.RequestContext.getEntityManager(name),
|
|
38
|
+
contextName: 'default',
|
|
39
|
+
allowGlobalContext: false,
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
logger: console.log.bind(console),
|
|
42
|
+
colors: true,
|
|
43
|
+
findOneOrFailHandler: (entityName, where) => errors_1.NotFoundError.findOneFailed(entityName, where),
|
|
44
|
+
findExactlyOneOrFailHandler: (entityName, where) => errors_1.NotFoundError.findExactlyOneFailed(entityName, where),
|
|
45
|
+
baseDir: process.cwd(),
|
|
46
|
+
hydrator: hydration_1.ObjectHydrator,
|
|
47
|
+
flushMode: enums_1.FlushMode.AUTO,
|
|
48
|
+
loadStrategy: enums_1.LoadStrategy.JOINED,
|
|
49
|
+
dataloader: enums_1.DataloaderType.NONE,
|
|
50
|
+
populateWhere: enums_1.PopulateHint.ALL,
|
|
51
|
+
connect: true,
|
|
52
|
+
ignoreUndefinedInQuery: false,
|
|
53
|
+
autoJoinOneToOneOwner: true,
|
|
54
|
+
autoJoinRefsForFilters: true,
|
|
55
|
+
propagationOnPrototype: true,
|
|
56
|
+
populateAfterFlush: true,
|
|
57
|
+
serialization: {
|
|
58
|
+
includePrimaryKeys: true,
|
|
59
|
+
},
|
|
60
|
+
persistOnCreate: true,
|
|
61
|
+
forceEntityConstructor: false,
|
|
62
|
+
forceUndefined: false,
|
|
63
|
+
forceUtcTimezone: false,
|
|
64
|
+
ensureDatabase: true,
|
|
65
|
+
ensureIndexes: false,
|
|
66
|
+
batchSize: 300,
|
|
67
|
+
debug: false,
|
|
68
|
+
verbose: false,
|
|
69
|
+
driverOptions: {},
|
|
70
|
+
migrations: {
|
|
71
|
+
tableName: 'mikro_orm_migrations',
|
|
72
|
+
path: './migrations',
|
|
73
|
+
glob: '!(*.d).{js,ts,cjs}',
|
|
74
|
+
silent: false,
|
|
75
|
+
transactional: true,
|
|
76
|
+
disableForeignKeys: true,
|
|
77
|
+
allOrNothing: true,
|
|
78
|
+
dropTables: true,
|
|
79
|
+
safe: false,
|
|
80
|
+
snapshot: true,
|
|
81
|
+
emit: 'ts',
|
|
82
|
+
fileName: (timestamp, name) => `Migration${timestamp}${name ? '_' + name : ''}`,
|
|
83
|
+
},
|
|
84
|
+
schemaGenerator: {
|
|
85
|
+
disableForeignKeys: true,
|
|
86
|
+
createForeignKeyConstraints: true,
|
|
87
|
+
ignoreSchema: [],
|
|
88
|
+
},
|
|
89
|
+
entityGenerator: {
|
|
90
|
+
bidirectionalRelations: false,
|
|
91
|
+
identifiedReferences: false,
|
|
92
|
+
scalarTypeInDecorator: false,
|
|
93
|
+
scalarPropertiesForRelations: 'never',
|
|
94
|
+
fileName: (className) => className,
|
|
95
|
+
onlyPurePivotTables: false,
|
|
96
|
+
readOnlyPivotTables: false,
|
|
97
|
+
useCoreBaseEntity: false,
|
|
98
|
+
},
|
|
99
|
+
metadataCache: {
|
|
100
|
+
pretty: false,
|
|
101
|
+
adapter: cache_1.FileCacheAdapter,
|
|
102
|
+
options: { cacheDir: process.cwd() + '/temp' },
|
|
103
|
+
},
|
|
104
|
+
resultCache: {
|
|
105
|
+
adapter: MemoryCacheAdapter_1.MemoryCacheAdapter,
|
|
106
|
+
expiration: 1000, // 1s
|
|
107
|
+
options: {},
|
|
108
|
+
},
|
|
109
|
+
metadataProvider: ReflectMetadataProvider_1.ReflectMetadataProvider,
|
|
110
|
+
highlighter: new NullHighlighter_1.NullHighlighter(),
|
|
111
|
+
seeder: {
|
|
112
|
+
path: './seeders',
|
|
113
|
+
defaultSeeder: 'DatabaseSeeder',
|
|
114
|
+
glob: '!(*.d).{js,ts}',
|
|
115
|
+
emit: 'ts',
|
|
116
|
+
fileName: (className) => className,
|
|
117
|
+
},
|
|
118
|
+
preferReadReplicas: true,
|
|
119
|
+
dynamicImportProvider: /* istanbul ignore next */ (id) => import(id),
|
|
120
|
+
};
|
|
121
|
+
options;
|
|
122
|
+
logger;
|
|
123
|
+
driver;
|
|
124
|
+
platform;
|
|
125
|
+
cache = new Map();
|
|
126
|
+
extensions = new Map();
|
|
127
|
+
constructor(options, validate = true) {
|
|
128
|
+
if (options.dynamicImportProvider) {
|
|
129
|
+
Utils_1.Utils.setDynamicImportProvider(options.dynamicImportProvider);
|
|
130
|
+
}
|
|
131
|
+
this.options = Utils_1.Utils.mergeConfig({}, Configuration.DEFAULTS, options);
|
|
132
|
+
this.options.baseDir = Utils_1.Utils.absolutePath(this.options.baseDir);
|
|
133
|
+
if (validate) {
|
|
134
|
+
this.validateOptions();
|
|
135
|
+
}
|
|
136
|
+
this.options.loggerFactory ??= (options) => new logging_1.DefaultLogger(options);
|
|
137
|
+
this.logger = this.options.loggerFactory({
|
|
138
|
+
debugMode: this.options.debug,
|
|
139
|
+
usesReplicas: (this.options.replicas?.length ?? 0) > 0,
|
|
140
|
+
highlighter: this.options.highlighter,
|
|
141
|
+
writer: this.options.logger,
|
|
142
|
+
});
|
|
143
|
+
this.driver = new this.options.driver(this);
|
|
144
|
+
this.platform = this.driver.getPlatform();
|
|
145
|
+
this.platform.setConfig(this);
|
|
146
|
+
this.detectSourceFolder(options);
|
|
147
|
+
this.init();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets specific configuration option. Falls back to specified `defaultValue` if provided.
|
|
151
|
+
*/
|
|
152
|
+
get(key, defaultValue) {
|
|
153
|
+
if (typeof this.options[key] !== 'undefined') {
|
|
154
|
+
return this.options[key];
|
|
155
|
+
}
|
|
156
|
+
return defaultValue;
|
|
157
|
+
}
|
|
158
|
+
getAll() {
|
|
159
|
+
return this.options;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Overrides specified configuration value.
|
|
163
|
+
*/
|
|
164
|
+
set(key, value) {
|
|
165
|
+
this.options[key] = value;
|
|
166
|
+
this.sync();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Resets the configuration to its default value
|
|
170
|
+
*/
|
|
171
|
+
reset(key) {
|
|
172
|
+
this.options[key] = Configuration.DEFAULTS[key];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Gets Logger instance.
|
|
176
|
+
*/
|
|
177
|
+
getLogger() {
|
|
178
|
+
return this.logger;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets current client URL (connection string).
|
|
182
|
+
*/
|
|
183
|
+
getClientUrl(hidePassword = false) {
|
|
184
|
+
if (hidePassword) {
|
|
185
|
+
return this.options.clientUrl.replace(/\/\/([^:]+):(.+)@/, '//$1:*****@');
|
|
186
|
+
}
|
|
187
|
+
return this.options.clientUrl;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Gets current database driver instance.
|
|
191
|
+
*/
|
|
192
|
+
getDriver() {
|
|
193
|
+
return this.driver;
|
|
194
|
+
}
|
|
195
|
+
registerExtension(name, cb) {
|
|
196
|
+
this.extensions.set(name, cb);
|
|
197
|
+
}
|
|
198
|
+
getExtension(name) {
|
|
199
|
+
if (this.cache.has(name)) {
|
|
200
|
+
return this.cache.get(name);
|
|
201
|
+
}
|
|
202
|
+
const ext = this.extensions.get(name);
|
|
203
|
+
if (ext) {
|
|
204
|
+
this.cache.set(name, ext());
|
|
205
|
+
return this.cache.get(name);
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Gets instance of NamingStrategy. (cached)
|
|
211
|
+
*/
|
|
212
|
+
getNamingStrategy() {
|
|
213
|
+
return this.getCachedService(this.options.namingStrategy || this.platform.getNamingStrategy());
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Gets instance of Hydrator. (cached)
|
|
217
|
+
*/
|
|
218
|
+
getHydrator(metadata) {
|
|
219
|
+
return this.getCachedService(this.options.hydrator, metadata, this.platform, this);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets instance of Comparator. (cached)
|
|
223
|
+
*/
|
|
224
|
+
getComparator(metadata) {
|
|
225
|
+
return this.getCachedService(EntityComparator_1.EntityComparator, metadata, this.platform);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets instance of MetadataProvider. (cached)
|
|
229
|
+
*/
|
|
230
|
+
getMetadataProvider() {
|
|
231
|
+
return this.getCachedService(this.options.metadataProvider, this);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Gets instance of metadata CacheAdapter. (cached)
|
|
235
|
+
*/
|
|
236
|
+
getMetadataCacheAdapter() {
|
|
237
|
+
return this.getCachedService(this.options.metadataCache.adapter, this.options.metadataCache.options, this.options.baseDir, this.options.metadataCache.pretty);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Gets instance of CacheAdapter for result cache. (cached)
|
|
241
|
+
*/
|
|
242
|
+
getResultCacheAdapter() {
|
|
243
|
+
return this.getCachedService(this.options.resultCache.adapter, { expiration: this.options.resultCache.expiration, ...this.options.resultCache.options });
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Gets EntityRepository class to be instantiated.
|
|
247
|
+
*/
|
|
248
|
+
getRepositoryClass(repository) {
|
|
249
|
+
if (repository) {
|
|
250
|
+
return repository();
|
|
251
|
+
}
|
|
252
|
+
if (this.options.entityRepository) {
|
|
253
|
+
return this.options.entityRepository;
|
|
254
|
+
}
|
|
255
|
+
return this.platform.getRepositoryClass();
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Creates instance of given service and caches it.
|
|
259
|
+
*/
|
|
260
|
+
getCachedService(cls, ...args) {
|
|
261
|
+
if (!this.cache.has(cls.name)) {
|
|
262
|
+
const Class = cls;
|
|
263
|
+
this.cache.set(cls.name, new Class(...args));
|
|
264
|
+
}
|
|
265
|
+
return this.cache.get(cls.name);
|
|
266
|
+
}
|
|
267
|
+
resetServiceCache() {
|
|
268
|
+
this.cache.clear();
|
|
269
|
+
}
|
|
270
|
+
init() {
|
|
271
|
+
if (!this.getMetadataProvider().useCache()) {
|
|
272
|
+
this.options.metadataCache.adapter = cache_1.NullCacheAdapter;
|
|
273
|
+
}
|
|
274
|
+
if (!('enabled' in this.options.metadataCache)) {
|
|
275
|
+
this.options.metadataCache.enabled = this.getMetadataProvider().useCache();
|
|
276
|
+
}
|
|
277
|
+
if (!this.options.clientUrl) {
|
|
278
|
+
this.options.clientUrl = this.driver.getConnection().getDefaultClientUrl();
|
|
279
|
+
}
|
|
280
|
+
if (!('implicitTransactions' in this.options)) {
|
|
281
|
+
this.options.implicitTransactions = this.platform.usesImplicitTransactions();
|
|
282
|
+
}
|
|
283
|
+
const url = this.getClientUrl().match(/:\/\/.*\/([^?]+)/);
|
|
284
|
+
if (url) {
|
|
285
|
+
this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
286
|
+
}
|
|
287
|
+
if (!this.options.charset) {
|
|
288
|
+
this.options.charset = this.platform.getDefaultCharset();
|
|
289
|
+
}
|
|
290
|
+
Object.keys(this.options.filters).forEach(key => {
|
|
291
|
+
this.options.filters[key].default ??= true;
|
|
292
|
+
});
|
|
293
|
+
this.options.subscribers = Utils_1.Utils.unique(this.options.subscribers).map(subscriber => {
|
|
294
|
+
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
295
|
+
});
|
|
296
|
+
this.sync();
|
|
297
|
+
if (!logging_1.colors.enabled()) {
|
|
298
|
+
this.options.highlighter = new NullHighlighter_1.NullHighlighter();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
sync() {
|
|
302
|
+
process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
|
|
303
|
+
this.logger.setDebugMode(this.options.debug);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
307
|
+
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
308
|
+
* used for the TS variant (`pathTs` option).
|
|
309
|
+
*
|
|
310
|
+
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
311
|
+
* break existing projects, only help with the new ones.
|
|
312
|
+
*/
|
|
313
|
+
detectSourceFolder(options) {
|
|
314
|
+
if (!(0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/src')) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const migrationsPathExists = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/' + this.options.migrations.path);
|
|
318
|
+
const seedersPathExists = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/' + this.options.seeder.path);
|
|
319
|
+
const distDir = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/dist');
|
|
320
|
+
const buildDir = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/build');
|
|
321
|
+
// if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
|
|
322
|
+
const path = distDir ? './dist' : (buildDir ? './build' : './src');
|
|
323
|
+
// only if the user did not provide any values and if the default path does not exist
|
|
324
|
+
if (!options.migrations?.path && !options.migrations?.pathTs && !migrationsPathExists) {
|
|
325
|
+
this.options.migrations.path = `${path}/migrations`;
|
|
326
|
+
this.options.migrations.pathTs = './src/migrations';
|
|
327
|
+
}
|
|
328
|
+
// only if the user did not provide any values and if the default path does not exist
|
|
329
|
+
if (!options.seeder?.path && !options.seeder?.pathTs && !seedersPathExists) {
|
|
330
|
+
this.options.seeder.path = `${path}/seeders`;
|
|
331
|
+
this.options.seeder.pathTs = './src/seeders';
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
validateOptions() {
|
|
335
|
+
/* istanbul ignore next */
|
|
336
|
+
if ('type' in this.options) {
|
|
337
|
+
throw new Error('The `type` option has been removed in v6, please fill in the `driver` option instead or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from \'@mikro-orm/mysql\'; export default defineConfig({ ... })`).');
|
|
338
|
+
}
|
|
339
|
+
if (!this.options.driver) {
|
|
340
|
+
throw new Error('No driver specified, please fill in the `driver` option or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from \'@mikro-orm/mysql\'; export defineConfig({ ... })`).');
|
|
341
|
+
}
|
|
342
|
+
if (!this.options.dbName && !this.options.clientUrl) {
|
|
343
|
+
throw new Error('No database specified, please fill in `dbName` or `clientUrl` option');
|
|
344
|
+
}
|
|
345
|
+
if (this.options.entities.length === 0 && this.options.discovery.warnWhenNoEntities) {
|
|
346
|
+
throw new Error('No entities found, please use `entities` option');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.Configuration = Configuration;
|
|
351
|
+
/**
|
|
352
|
+
* Type helper to make it easier to use `mikro-orm.config.js`.
|
|
353
|
+
*/
|
|
354
|
+
function defineConfig(options) {
|
|
355
|
+
return options;
|
|
356
|
+
}
|
|
357
|
+
exports.defineConfig = defineConfig;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { EntityManagerType, IDatabaseDriver } from '../drivers';
|
|
2
|
+
import { Configuration, type Options } from './Configuration';
|
|
3
|
+
import type { Dictionary } from '../typings';
|
|
4
|
+
import type { EntityManager } from '../EntityManager';
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConfigurationLoader {
|
|
9
|
+
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(validate?: boolean, options?: Partial<Options>): Promise<Configuration<D, EM>>;
|
|
10
|
+
static getPackageConfig(basePath?: string): Promise<Dictionary>;
|
|
11
|
+
static getSettings(): Promise<Settings>;
|
|
12
|
+
static getConfigPaths(): Promise<string[]>;
|
|
13
|
+
static isESM(): Promise<boolean>;
|
|
14
|
+
static registerTsNode(configPath?: string): Promise<boolean>;
|
|
15
|
+
static registerDotenv<D extends IDatabaseDriver>(options?: Options<D> | Configuration<D>): void;
|
|
16
|
+
static loadEnvironmentVars<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
17
|
+
static getORMPackages(): Promise<Set<string>>;
|
|
18
|
+
/** @internal */
|
|
19
|
+
static commonJSCompat(options: Partial<Options>): Promise<void>;
|
|
20
|
+
static getORMPackageVersion(name: string): Promise<string | undefined>;
|
|
21
|
+
static checkPackageVersion(): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
export interface Settings {
|
|
24
|
+
alwaysAllowTs?: boolean;
|
|
25
|
+
verbose?: boolean;
|
|
26
|
+
useTsNode?: boolean;
|
|
27
|
+
tsConfigPath?: string;
|
|
28
|
+
configPaths?: string[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConfigurationLoader = void 0;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const os_1 = require("os");
|
|
11
|
+
const url_1 = require("url");
|
|
12
|
+
const Configuration_1 = require("./Configuration");
|
|
13
|
+
const Utils_1 = require("./Utils");
|
|
14
|
+
const colors_1 = require("../logging/colors");
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
class ConfigurationLoader {
|
|
19
|
+
static async getConfiguration(validate = true, options = {}) {
|
|
20
|
+
await this.commonJSCompat(options);
|
|
21
|
+
this.registerDotenv(options);
|
|
22
|
+
const paths = await this.getConfigPaths();
|
|
23
|
+
const env = this.loadEnvironmentVars();
|
|
24
|
+
for (let path of paths) {
|
|
25
|
+
path = Utils_1.Utils.absolutePath(path);
|
|
26
|
+
path = Utils_1.Utils.normalizePath(path);
|
|
27
|
+
if (await (0, fs_extra_1.pathExists)(path)) {
|
|
28
|
+
const config = await Utils_1.Utils.dynamicImport(path);
|
|
29
|
+
/* istanbul ignore next */
|
|
30
|
+
let tmp = config.default ?? config;
|
|
31
|
+
if (tmp instanceof Function) {
|
|
32
|
+
tmp = tmp();
|
|
33
|
+
}
|
|
34
|
+
if (tmp instanceof Promise) {
|
|
35
|
+
tmp = await tmp;
|
|
36
|
+
}
|
|
37
|
+
const esmConfigOptions = await this.isESM() ? { entityGenerator: { esmImport: true } } : {};
|
|
38
|
+
return new Configuration_1.Configuration(Utils_1.Utils.mergeConfig({}, esmConfigOptions, tmp, options, env), validate);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (Utils_1.Utils.hasObjectKeys(env)) {
|
|
42
|
+
return new Configuration_1.Configuration(Utils_1.Utils.mergeConfig({}, options, env), validate);
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
|
|
45
|
+
}
|
|
46
|
+
static async getPackageConfig(basePath = process.cwd()) {
|
|
47
|
+
if (await (0, fs_extra_1.pathExists)(`${basePath}/package.json`)) {
|
|
48
|
+
/* istanbul ignore next */
|
|
49
|
+
try {
|
|
50
|
+
return await Utils_1.Utils.dynamicImport(`${basePath}/package.json`);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const parentFolder = await (0, fs_extra_1.realpath)(`${basePath}/..`);
|
|
57
|
+
// we reached the root folder
|
|
58
|
+
if (basePath === parentFolder) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
return this.getPackageConfig(parentFolder);
|
|
62
|
+
}
|
|
63
|
+
static async getSettings() {
|
|
64
|
+
const config = await ConfigurationLoader.getPackageConfig();
|
|
65
|
+
const settings = { ...config['mikro-orm'] };
|
|
66
|
+
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
67
|
+
settings.useTsNode = process.env.MIKRO_ORM_CLI_USE_TS_NODE != null ? bool(process.env.MIKRO_ORM_CLI_USE_TS_NODE) : settings.useTsNode;
|
|
68
|
+
settings.tsConfigPath = process.env.MIKRO_ORM_CLI_TS_CONFIG_PATH ?? settings.tsConfigPath;
|
|
69
|
+
settings.alwaysAllowTs = process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS != null ? bool(process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS) : settings.alwaysAllowTs;
|
|
70
|
+
settings.verbose = process.env.MIKRO_ORM_CLI_VERBOSE != null ? bool(process.env.MIKRO_ORM_CLI_VERBOSE) : settings.verbose;
|
|
71
|
+
if (process.env.MIKRO_ORM_CLI_CONFIG?.endsWith('.ts')) {
|
|
72
|
+
settings.useTsNode = true;
|
|
73
|
+
}
|
|
74
|
+
return settings;
|
|
75
|
+
}
|
|
76
|
+
static async getConfigPaths() {
|
|
77
|
+
const options = Utils_1.Utils.parseArgs();
|
|
78
|
+
if (options.config) {
|
|
79
|
+
return [options.config];
|
|
80
|
+
}
|
|
81
|
+
const paths = [];
|
|
82
|
+
const settings = await ConfigurationLoader.getSettings();
|
|
83
|
+
if (process.env.MIKRO_ORM_CLI_CONFIG) {
|
|
84
|
+
paths.push(process.env.MIKRO_ORM_CLI_CONFIG);
|
|
85
|
+
}
|
|
86
|
+
paths.push(...(settings.configPaths || []));
|
|
87
|
+
if (settings.useTsNode || settings.alwaysAllowTs) {
|
|
88
|
+
paths.push('./src/mikro-orm.config.ts');
|
|
89
|
+
paths.push('./mikro-orm.config.ts');
|
|
90
|
+
}
|
|
91
|
+
const distDir = (0, fs_extra_1.pathExistsSync)(process.cwd() + '/dist');
|
|
92
|
+
const buildDir = (0, fs_extra_1.pathExistsSync)(process.cwd() + '/build');
|
|
93
|
+
/* istanbul ignore next */
|
|
94
|
+
const path = distDir ? 'dist' : (buildDir ? 'build' : 'src');
|
|
95
|
+
paths.push(`./${path}/mikro-orm.config.js`);
|
|
96
|
+
paths.push('./mikro-orm.config.js');
|
|
97
|
+
const tsNode = Utils_1.Utils.detectTsNode();
|
|
98
|
+
return Utils_1.Utils.unique(paths).filter(p => p.endsWith('.js') || tsNode || settings.alwaysAllowTs);
|
|
99
|
+
}
|
|
100
|
+
static async isESM() {
|
|
101
|
+
const config = await ConfigurationLoader.getPackageConfig();
|
|
102
|
+
const type = config?.type ?? '';
|
|
103
|
+
return type === 'module';
|
|
104
|
+
}
|
|
105
|
+
static async registerTsNode(configPath = 'tsconfig.json') {
|
|
106
|
+
const tsConfigPath = (0, path_1.isAbsolute)(configPath) ? configPath : (0, path_1.join)(process.cwd(), configPath);
|
|
107
|
+
const tsNode = Utils_1.Utils.tryRequire({
|
|
108
|
+
module: 'ts-node',
|
|
109
|
+
from: tsConfigPath,
|
|
110
|
+
warning: 'ts-node not installed, support for working with TS files might not work',
|
|
111
|
+
});
|
|
112
|
+
/* istanbul ignore next */
|
|
113
|
+
if (!tsNode) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const { options } = tsNode.register({
|
|
117
|
+
project: tsConfigPath,
|
|
118
|
+
transpileOnly: true,
|
|
119
|
+
// compilerOptions: {
|
|
120
|
+
// module: 'commonjs',
|
|
121
|
+
// },
|
|
122
|
+
}).config;
|
|
123
|
+
if (Object.entries(options?.paths ?? {}).length > 0) {
|
|
124
|
+
Utils_1.Utils.requireFrom('tsconfig-paths', tsConfigPath).register({
|
|
125
|
+
baseUrl: options.baseUrl ?? '.',
|
|
126
|
+
paths: options.paths,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
static registerDotenv(options) {
|
|
132
|
+
const baseDir = options instanceof Configuration_1.Configuration ? options.get('baseDir') : options?.baseDir;
|
|
133
|
+
const path = process.env.MIKRO_ORM_ENV ?? ((baseDir ?? process.cwd()) + '/.env');
|
|
134
|
+
const env = {};
|
|
135
|
+
dotenv_1.default.config({ path, processEnv: env });
|
|
136
|
+
// only propagate known env vars
|
|
137
|
+
for (const key of Object.keys(env)) {
|
|
138
|
+
if (key.startsWith('MIKRO_ORM_')) {
|
|
139
|
+
process.env[key] ??= env[key]; // respect user provided values
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
static loadEnvironmentVars() {
|
|
144
|
+
const ret = {};
|
|
145
|
+
// only to keep some sort of back compatibility with those using env vars only, to support `MIKRO_ORM_TYPE`
|
|
146
|
+
const PLATFORMS = {
|
|
147
|
+
'mongo': { className: 'MongoDriver', module: '@mikro-orm/mongodb' },
|
|
148
|
+
'mysql': { className: 'MySqlDriver', module: '@mikro-orm/mysql' },
|
|
149
|
+
'mariadb': { className: 'MariaDbDriver', module: '@mikro-orm/mariadb' },
|
|
150
|
+
'postgresql': { className: 'PostgreSqlDriver', module: '@mikro-orm/postgresql' },
|
|
151
|
+
'sqlite': { className: 'SqliteDriver', module: '@mikro-orm/sqlite' },
|
|
152
|
+
'better-sqlite': { className: 'BetterSqliteDriver', module: '@mikro-orm/better-sqlite' },
|
|
153
|
+
};
|
|
154
|
+
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
155
|
+
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
156
|
+
const num = (v) => +v;
|
|
157
|
+
const driver = (v) => Utils_1.Utils.requireFrom(PLATFORMS[v].module)[PLATFORMS[v].className];
|
|
158
|
+
const read = (o, envKey, key, mapper = v => v) => {
|
|
159
|
+
if (!(envKey in process.env)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const val = process.env[envKey];
|
|
163
|
+
o[key] = mapper(val);
|
|
164
|
+
};
|
|
165
|
+
const cleanup = (o, k) => Utils_1.Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
166
|
+
read(ret, 'MIKRO_ORM_BASE_DIR', 'baseDir');
|
|
167
|
+
read(ret, 'MIKRO_ORM_TYPE', 'driver', driver);
|
|
168
|
+
read(ret, 'MIKRO_ORM_ENTITIES', 'entities', array);
|
|
169
|
+
read(ret, 'MIKRO_ORM_ENTITIES_TS', 'entitiesTs', array);
|
|
170
|
+
read(ret, 'MIKRO_ORM_CLIENT_URL', 'clientUrl');
|
|
171
|
+
read(ret, 'MIKRO_ORM_HOST', 'host');
|
|
172
|
+
read(ret, 'MIKRO_ORM_PORT', 'port', num);
|
|
173
|
+
read(ret, 'MIKRO_ORM_USER', 'user');
|
|
174
|
+
read(ret, 'MIKRO_ORM_PASSWORD', 'password');
|
|
175
|
+
read(ret, 'MIKRO_ORM_DB_NAME', 'dbName');
|
|
176
|
+
read(ret, 'MIKRO_ORM_SCHEMA', 'schema');
|
|
177
|
+
read(ret, 'MIKRO_ORM_LOAD_STRATEGY', 'loadStrategy');
|
|
178
|
+
read(ret, 'MIKRO_ORM_BATCH_SIZE', 'batchSize', num);
|
|
179
|
+
read(ret, 'MIKRO_ORM_USE_BATCH_INSERTS', 'useBatchInserts', bool);
|
|
180
|
+
read(ret, 'MIKRO_ORM_USE_BATCH_UPDATES', 'useBatchUpdates', bool);
|
|
181
|
+
read(ret, 'MIKRO_ORM_STRICT', 'strict', bool);
|
|
182
|
+
read(ret, 'MIKRO_ORM_VALIDATE', 'validate', bool);
|
|
183
|
+
read(ret, 'MIKRO_ORM_ALLOW_GLOBAL_CONTEXT', 'allowGlobalContext', bool);
|
|
184
|
+
read(ret, 'MIKRO_ORM_AUTO_JOIN_ONE_TO_ONE_OWNER', 'autoJoinOneToOneOwner', bool);
|
|
185
|
+
read(ret, 'MIKRO_ORM_POPULATE_AFTER_FLUSH', 'populateAfterFlush', bool);
|
|
186
|
+
read(ret, 'MIKRO_ORM_FORCE_ENTITY_CONSTRUCTOR', 'forceEntityConstructor', bool);
|
|
187
|
+
read(ret, 'MIKRO_ORM_FORCE_UNDEFINED', 'forceUndefined', bool);
|
|
188
|
+
read(ret, 'MIKRO_ORM_FORCE_UTC_TIMEZONE', 'forceUtcTimezone', bool);
|
|
189
|
+
read(ret, 'MIKRO_ORM_TIMEZONE', 'timezone');
|
|
190
|
+
read(ret, 'MIKRO_ORM_ENSURE_INDEXES', 'ensureIndexes', bool);
|
|
191
|
+
read(ret, 'MIKRO_ORM_IMPLICIT_TRANSACTIONS', 'implicitTransactions', bool);
|
|
192
|
+
read(ret, 'MIKRO_ORM_DEBUG', 'debug', bool);
|
|
193
|
+
read(ret, 'MIKRO_ORM_COLORS', 'colors', bool);
|
|
194
|
+
ret.discovery = {};
|
|
195
|
+
read(ret.discovery, 'MIKRO_ORM_DISCOVERY_WARN_WHEN_NO_ENTITIES', 'warnWhenNoEntities', bool);
|
|
196
|
+
read(ret.discovery, 'MIKRO_ORM_DISCOVERY_REQUIRE_ENTITIES_ARRAY', 'requireEntitiesArray', bool);
|
|
197
|
+
read(ret.discovery, 'MIKRO_ORM_DISCOVERY_ALWAYS_ANALYSE_PROPERTIES', 'alwaysAnalyseProperties', bool);
|
|
198
|
+
read(ret.discovery, 'MIKRO_ORM_DISCOVERY_DISABLE_DYNAMIC_FILE_ACCESS', 'disableDynamicFileAccess', bool);
|
|
199
|
+
cleanup(ret, 'discovery');
|
|
200
|
+
ret.migrations = {};
|
|
201
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TABLE_NAME', 'tableName');
|
|
202
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_PATH', 'path');
|
|
203
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_PATH_TS', 'pathTs');
|
|
204
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_GLOB', 'glob');
|
|
205
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TRANSACTIONAL', 'transactional', bool);
|
|
206
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_DISABLE_FOREIGN_KEYS', 'disableForeignKeys', bool);
|
|
207
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_ALL_OR_NOTHING', 'allOrNothing', bool);
|
|
208
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_DROP_TABLES', 'dropTables', bool);
|
|
209
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SAFE', 'safe', bool);
|
|
210
|
+
read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_EMIT', 'emit');
|
|
211
|
+
cleanup(ret, 'migrations');
|
|
212
|
+
ret.schemaGenerator = {};
|
|
213
|
+
read(ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_DISABLE_FOREIGN_KEYS', 'disableForeignKeys', bool);
|
|
214
|
+
read(ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_CREATE_FOREIGN_KEY_CONSTRAINTS', 'createForeignKeyConstraints', bool);
|
|
215
|
+
cleanup(ret, 'schemaGenerator');
|
|
216
|
+
ret.seeder = {};
|
|
217
|
+
read(ret.seeder, 'MIKRO_ORM_SEEDER_PATH', 'path');
|
|
218
|
+
read(ret.seeder, 'MIKRO_ORM_SEEDER_PATH_TS', 'pathTs');
|
|
219
|
+
read(ret.seeder, 'MIKRO_ORM_SEEDER_GLOB', 'glob');
|
|
220
|
+
read(ret.seeder, 'MIKRO_ORM_SEEDER_EMIT', 'emit');
|
|
221
|
+
read(ret.seeder, 'MIKRO_ORM_SEEDER_DEFAULT_SEEDER', 'defaultSeeder');
|
|
222
|
+
cleanup(ret, 'seeder');
|
|
223
|
+
return ret;
|
|
224
|
+
}
|
|
225
|
+
static async getORMPackages() {
|
|
226
|
+
const pkg = await this.getPackageConfig();
|
|
227
|
+
return new Set([
|
|
228
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
229
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
230
|
+
]);
|
|
231
|
+
}
|
|
232
|
+
/** @internal */
|
|
233
|
+
static async commonJSCompat(options) {
|
|
234
|
+
if (await this.isESM()) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
/* istanbul ignore next */
|
|
238
|
+
options.dynamicImportProvider ??= id => {
|
|
239
|
+
if ((0, os_1.platform)() === 'win32') {
|
|
240
|
+
try {
|
|
241
|
+
id = (0, url_1.fileURLToPath)(id);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
// ignore
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return Utils_1.Utils.requireFrom(id);
|
|
248
|
+
};
|
|
249
|
+
Utils_1.Utils.setDynamicImportProvider(options.dynamicImportProvider);
|
|
250
|
+
}
|
|
251
|
+
static async getORMPackageVersion(name) {
|
|
252
|
+
/* istanbul ignore next */
|
|
253
|
+
try {
|
|
254
|
+
const pkg = Utils_1.Utils.requireFrom(`${name}/package.json`);
|
|
255
|
+
return pkg?.version;
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// inspired by https://github.com/facebook/mikro-orm/pull/3386
|
|
262
|
+
static async checkPackageVersion() {
|
|
263
|
+
const coreVersion = Utils_1.Utils.getORMVersion();
|
|
264
|
+
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH) {
|
|
265
|
+
return coreVersion;
|
|
266
|
+
}
|
|
267
|
+
const deps = await this.getORMPackages();
|
|
268
|
+
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
269
|
+
const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
|
|
270
|
+
for (const ormPackage of ormPackages) {
|
|
271
|
+
const version = await this.getORMPackageVersion(ormPackage);
|
|
272
|
+
if (version != null && version !== coreVersion) {
|
|
273
|
+
throw new Error(`Bad ${colors_1.colors.cyan(ormPackage)} version ${colors_1.colors.yellow('' + version)}.\n` +
|
|
274
|
+
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors_1.colors.green(coreVersion)}).\n` +
|
|
275
|
+
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
276
|
+
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return coreVersion;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.ConfigurationLoader = ConfigurationLoader;
|