@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
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 +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- 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 +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- package/events/EventSubscriber.d.ts +8 -5
- 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 +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- 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 +12 -2
- 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/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -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 +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -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 +4 -4
- package/types/JsonType.js +9 -8
- 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 +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- 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 +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- 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 +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- 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/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
package/utils/clone.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Inspired by https://github.com/pvorb/clone but simplified and never tries to
|
|
4
3
|
* clone `EventEmitter`s to get around https://github.com/mikro-orm/mikro-orm/issues/2748
|
|
5
4
|
* @internal
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
exports.clone = clone;
|
|
9
|
-
const node_events_1 = require("node:events");
|
|
10
|
-
const RawQueryFragment_1 = require("./RawQueryFragment");
|
|
6
|
+
import { RawQueryFragment } from './RawQueryFragment.js';
|
|
11
7
|
/**
|
|
12
8
|
* Get the property descriptor of a property on an object or its prototype chain.
|
|
13
9
|
*
|
|
@@ -25,7 +21,7 @@ function getPropertyDescriptor(obj, prop) {
|
|
|
25
21
|
}
|
|
26
22
|
return null;
|
|
27
23
|
}
|
|
28
|
-
function clone(parent, respectCustomCloneMethod = true) {
|
|
24
|
+
export function clone(parent, respectCustomCloneMethod = true) {
|
|
29
25
|
const allParents = [];
|
|
30
26
|
const allChildren = [];
|
|
31
27
|
function _clone(parent) {
|
|
@@ -33,11 +29,11 @@ function clone(parent, respectCustomCloneMethod = true) {
|
|
|
33
29
|
if (parent === null) {
|
|
34
30
|
return null;
|
|
35
31
|
}
|
|
36
|
-
const raw =
|
|
32
|
+
const raw = RawQueryFragment.getKnownFragment(parent, false);
|
|
37
33
|
if (raw && respectCustomCloneMethod) {
|
|
38
34
|
return raw.clone();
|
|
39
35
|
}
|
|
40
|
-
if (typeof parent !== 'object'
|
|
36
|
+
if (typeof parent !== 'object') {
|
|
41
37
|
return parent;
|
|
42
38
|
}
|
|
43
39
|
if (respectCustomCloneMethod && 'clone' in parent && typeof parent.clone === 'function') {
|
|
@@ -84,7 +80,7 @@ function clone(parent, respectCustomCloneMethod = true) {
|
|
|
84
80
|
return child;
|
|
85
81
|
}
|
|
86
82
|
else if (parent instanceof Error) {
|
|
87
|
-
child =
|
|
83
|
+
child = new parent.constructor(parent.message);
|
|
88
84
|
}
|
|
89
85
|
else {
|
|
90
86
|
proto = Object.getPrototypeOf(parent);
|
|
@@ -117,7 +113,7 @@ function clone(parent, respectCustomCloneMethod = true) {
|
|
|
117
113
|
if (attrs && typeof attrs.get === 'function' && attrs.set == null) {
|
|
118
114
|
continue;
|
|
119
115
|
}
|
|
120
|
-
const raw =
|
|
116
|
+
const raw = RawQueryFragment.getKnownFragment(i, false);
|
|
121
117
|
if (raw && respectCustomCloneMethod) {
|
|
122
118
|
const i2 = raw.clone().toString();
|
|
123
119
|
child[i2] = _clone(parent[i]);
|
|
@@ -130,7 +126,7 @@ function clone(parent, respectCustomCloneMethod = true) {
|
|
|
130
126
|
for (let i = 0; i < symbols.length; i++) {
|
|
131
127
|
const symbol = symbols[i];
|
|
132
128
|
const descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
|
|
133
|
-
/*
|
|
129
|
+
/* v8 ignore next */
|
|
134
130
|
if (descriptor && !descriptor.enumerable) {
|
|
135
131
|
continue;
|
|
136
132
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Utils } from './Utils.js';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function loadEnvironmentVars() {
|
|
4
|
+
const ret = {};
|
|
5
|
+
const getEnvKey = (key, envPrefix = 'MIKRO_ORM_') => {
|
|
6
|
+
return envPrefix + key
|
|
7
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
8
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
9
|
+
.toUpperCase();
|
|
10
|
+
};
|
|
11
|
+
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
12
|
+
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
13
|
+
const num = (v) => +v;
|
|
14
|
+
const read = (o, envPrefix, key, mapper = v => v) => {
|
|
15
|
+
const envKey = getEnvKey(key, envPrefix);
|
|
16
|
+
if (envKey in process.env) {
|
|
17
|
+
o[key] = mapper(process.env[envKey]);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
21
|
+
const read0 = read.bind(null, ret, 'MIKRO_ORM_');
|
|
22
|
+
read0('baseDir');
|
|
23
|
+
read0('entities', array);
|
|
24
|
+
read0('entitiesTs', array);
|
|
25
|
+
read0('clientUrl');
|
|
26
|
+
read0('host');
|
|
27
|
+
read0('port', num);
|
|
28
|
+
read0('user');
|
|
29
|
+
read0('password');
|
|
30
|
+
read0('dbName');
|
|
31
|
+
read0('schema');
|
|
32
|
+
read0('loadStrategy');
|
|
33
|
+
read0('batchSize', num);
|
|
34
|
+
read0('useBatchInserts', bool);
|
|
35
|
+
read0('useBatchUpdates', bool);
|
|
36
|
+
read0('allowGlobalContext', bool);
|
|
37
|
+
read0('autoJoinOneToOneOwner', bool);
|
|
38
|
+
read0('populateAfterFlush', bool);
|
|
39
|
+
read0('forceEntityConstructor', bool);
|
|
40
|
+
read0('forceUndefined', bool);
|
|
41
|
+
read0('forceUtcTimezone', bool);
|
|
42
|
+
read0('timezone');
|
|
43
|
+
read0('ensureIndexes', bool);
|
|
44
|
+
read0('implicitTransactions', bool);
|
|
45
|
+
read0('debug', bool);
|
|
46
|
+
read0('colors', bool);
|
|
47
|
+
ret.discovery = {};
|
|
48
|
+
const read1 = read.bind(null, ret.discovery, 'MIKRO_ORM_DISCOVERY_');
|
|
49
|
+
read1('warnWhenNoEntities', bool);
|
|
50
|
+
read1('checkDuplicateTableNames', bool);
|
|
51
|
+
read1('checkDuplicateFieldNames', bool);
|
|
52
|
+
read1('checkDuplicateEntities', bool);
|
|
53
|
+
read1('checkNonPersistentCompositeProps', bool);
|
|
54
|
+
read1('inferDefaultValues', bool);
|
|
55
|
+
read1('tsConfigPath');
|
|
56
|
+
cleanup(ret, 'discovery');
|
|
57
|
+
ret.migrations = {};
|
|
58
|
+
const read2 = read.bind(null, ret.migrations, 'MIKRO_ORM_MIGRATIONS_');
|
|
59
|
+
read2('tableName');
|
|
60
|
+
read2('path');
|
|
61
|
+
read2('pathTs');
|
|
62
|
+
read2('glob');
|
|
63
|
+
read2('transactional', bool);
|
|
64
|
+
read2('disableForeignKeys', bool);
|
|
65
|
+
read2('allOrNothing', bool);
|
|
66
|
+
read2('dropTables', bool);
|
|
67
|
+
read2('safe', bool);
|
|
68
|
+
read2('silent', bool);
|
|
69
|
+
read2('emit');
|
|
70
|
+
read2('snapshot', bool);
|
|
71
|
+
read2('snapshotName');
|
|
72
|
+
cleanup(ret, 'migrations');
|
|
73
|
+
ret.schemaGenerator = {};
|
|
74
|
+
const read3 = read.bind(null, ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_');
|
|
75
|
+
read3('disableForeignKeys', bool);
|
|
76
|
+
read3('createForeignKeyConstraints', bool);
|
|
77
|
+
cleanup(ret, 'schemaGenerator');
|
|
78
|
+
ret.seeder = {};
|
|
79
|
+
const read4 = read.bind(null, ret.seeder, 'MIKRO_ORM_SEEDER_');
|
|
80
|
+
read4('path');
|
|
81
|
+
read4('pathTs');
|
|
82
|
+
read4('glob');
|
|
83
|
+
read4('emit');
|
|
84
|
+
read4('defaultSeeder');
|
|
85
|
+
cleanup(ret, 'seeder');
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Dictionary } from '../typings.js';
|
|
2
|
+
export declare const fs: {
|
|
3
|
+
pathExists(path: string): boolean;
|
|
4
|
+
ensureDir(path: string): void;
|
|
5
|
+
readJSONSync<T = Dictionary>(path: string): T;
|
|
6
|
+
glob(input: string | string[], cwd?: string): string[];
|
|
7
|
+
getPackageConfig<T extends Dictionary>(basePath?: string): T;
|
|
8
|
+
getORMPackages(): Set<string>;
|
|
9
|
+
getORMPackageVersion(name: string): string | undefined;
|
|
10
|
+
checkPackageVersion(): void;
|
|
11
|
+
};
|
|
12
|
+
export * from '../cache/FileCacheAdapter.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { existsSync, globSync, mkdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { Utils } from './Utils.js';
|
|
5
|
+
import { colors } from '../logging/colors.js';
|
|
6
|
+
export const fs = {
|
|
7
|
+
pathExists(path) {
|
|
8
|
+
if (/[*?[\]]/.test(path)) {
|
|
9
|
+
return globSync(path).length > 0;
|
|
10
|
+
}
|
|
11
|
+
return existsSync(path);
|
|
12
|
+
},
|
|
13
|
+
ensureDir(path) {
|
|
14
|
+
if (!existsSync(path)) {
|
|
15
|
+
mkdirSync(path, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
readJSONSync(path) {
|
|
19
|
+
const file = readFileSync(path);
|
|
20
|
+
return JSON.parse(file.toString());
|
|
21
|
+
},
|
|
22
|
+
glob(input, cwd) {
|
|
23
|
+
if (Array.isArray(input)) {
|
|
24
|
+
return input.flatMap(paths => this.glob(paths, cwd));
|
|
25
|
+
}
|
|
26
|
+
const hasGlobChars = /[*?[\]]/.test(input);
|
|
27
|
+
if (!hasGlobChars) {
|
|
28
|
+
try {
|
|
29
|
+
const s = statSync(cwd ? Utils.normalizePath(cwd, input) : input);
|
|
30
|
+
if (s.isDirectory()) {
|
|
31
|
+
const files = globSync(join(input, '**'), { cwd, withFileTypes: true });
|
|
32
|
+
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// ignore
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const files = globSync(input, { cwd, withFileTypes: true });
|
|
40
|
+
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
41
|
+
},
|
|
42
|
+
getPackageConfig(basePath = process.cwd()) {
|
|
43
|
+
if (this.pathExists(`${basePath}/package.json`)) {
|
|
44
|
+
try {
|
|
45
|
+
const path = import.meta.resolve(`${basePath}/package.json`);
|
|
46
|
+
return this.readJSONSync(fileURLToPath(path));
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
/* v8 ignore next */
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const parentFolder = realpathSync(`${basePath}/..`);
|
|
54
|
+
// we reached the root folder
|
|
55
|
+
if (basePath === parentFolder) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
return this.getPackageConfig(parentFolder);
|
|
59
|
+
},
|
|
60
|
+
getORMPackages() {
|
|
61
|
+
const pkg = this.getPackageConfig();
|
|
62
|
+
return new Set([
|
|
63
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
64
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
65
|
+
]);
|
|
66
|
+
},
|
|
67
|
+
getORMPackageVersion(name) {
|
|
68
|
+
try {
|
|
69
|
+
const path = import.meta.resolve(`${name}/package.json`);
|
|
70
|
+
const pkg = this.readJSONSync(fileURLToPath(path));
|
|
71
|
+
return pkg?.version;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
78
|
+
checkPackageVersion() {
|
|
79
|
+
const coreVersion = Utils.getORMVersion();
|
|
80
|
+
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const deps = this.getORMPackages();
|
|
84
|
+
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
85
|
+
const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
|
|
86
|
+
for (const ormPackage of ormPackages) {
|
|
87
|
+
const version = this.getORMPackageVersion(ormPackage);
|
|
88
|
+
if (version != null && version !== coreVersion) {
|
|
89
|
+
throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
|
|
90
|
+
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
|
|
91
|
+
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
92
|
+
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
export * from '../cache/FileCacheAdapter.js';
|
package/utils/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export * from './Configuration';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './QueryHelper';
|
|
9
|
-
export * from './NullHighlighter';
|
|
10
|
-
export * from './EntityComparator';
|
|
11
|
-
export * from './AbstractSchemaGenerator';
|
|
12
|
-
export * from './RawQueryFragment';
|
|
13
|
-
export * from './
|
|
1
|
+
export * from './Configuration.js';
|
|
2
|
+
export * from './Cursor.js';
|
|
3
|
+
export * from './DataloaderUtils.js';
|
|
4
|
+
export * from './Utils.js';
|
|
5
|
+
export * from './RequestContext.js';
|
|
6
|
+
export * from './TransactionContext.js';
|
|
7
|
+
export * from './TransactionManager.js';
|
|
8
|
+
export * from './QueryHelper.js';
|
|
9
|
+
export * from './NullHighlighter.js';
|
|
10
|
+
export * from './EntityComparator.js';
|
|
11
|
+
export * from './AbstractSchemaGenerator.js';
|
|
12
|
+
export * from './RawQueryFragment.js';
|
|
13
|
+
export * from './env-vars.js';
|
|
14
|
+
export * from './upsert-utils.js';
|
package/utils/index.js
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Configuration"), exports);
|
|
18
|
-
__exportStar(require("./ConfigurationLoader"), exports);
|
|
19
|
-
__exportStar(require("./Cursor"), exports);
|
|
20
|
-
__exportStar(require("./DataloaderUtils"), exports);
|
|
21
|
-
__exportStar(require("./Utils"), exports);
|
|
22
|
-
__exportStar(require("./RequestContext"), exports);
|
|
23
|
-
__exportStar(require("./TransactionContext"), exports);
|
|
24
|
-
__exportStar(require("./QueryHelper"), exports);
|
|
25
|
-
__exportStar(require("./NullHighlighter"), exports);
|
|
26
|
-
__exportStar(require("./EntityComparator"), exports);
|
|
27
|
-
__exportStar(require("./AbstractSchemaGenerator"), exports);
|
|
28
|
-
__exportStar(require("./RawQueryFragment"), exports);
|
|
29
|
-
__exportStar(require("./upsert-utils"), exports);
|
|
1
|
+
export * from './Configuration.js';
|
|
2
|
+
export * from './Cursor.js';
|
|
3
|
+
export * from './DataloaderUtils.js';
|
|
4
|
+
export * from './Utils.js';
|
|
5
|
+
export * from './RequestContext.js';
|
|
6
|
+
export * from './TransactionContext.js';
|
|
7
|
+
export * from './TransactionManager.js';
|
|
8
|
+
export * from './QueryHelper.js';
|
|
9
|
+
export * from './NullHighlighter.js';
|
|
10
|
+
export * from './EntityComparator.js';
|
|
11
|
+
export * from './AbstractSchemaGenerator.js';
|
|
12
|
+
export * from './RawQueryFragment.js';
|
|
13
|
+
export * from './env-vars.js';
|
|
14
|
+
export * from './upsert-utils.js';
|
package/utils/upsert-utils.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { EntityData, EntityMetadata } from '../typings';
|
|
2
|
-
import type { UpsertOptions } from '../drivers/IDatabaseDriver';
|
|
3
|
-
import type
|
|
1
|
+
import type { EntityData, EntityMetadata, FilterQuery } from '../typings.js';
|
|
2
|
+
import type { UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
3
|
+
import { type RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
4
4
|
/** @internal */
|
|
5
5
|
export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | RawQueryFragment, options: UpsertOptions<T>): (keyof T)[];
|
|
6
6
|
/** @internal */
|
|
7
7
|
export declare function getOnConflictReturningFields<T, P extends string>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | RawQueryFragment, options: UpsertOptions<T, P>): (keyof T)[] | '*';
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function getWhereCondition<T extends object>(meta: EntityMetadata<T>, onConflictFields: (keyof T)[] | RawQueryFragment | undefined, data: EntityData<T>, where: FilterQuery<T>): {
|
|
10
|
+
where: FilterQuery<T>;
|
|
11
|
+
propIndex: number | false;
|
|
12
|
+
};
|
package/utils/upsert-utils.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getOnConflictFields = getOnConflictFields;
|
|
4
|
-
exports.getOnConflictReturningFields = getOnConflictReturningFields;
|
|
1
|
+
import { isRaw } from '../utils/RawQueryFragment.js';
|
|
2
|
+
import { Utils } from './Utils.js';
|
|
5
3
|
function expandEmbeddedProperties(prop, key) {
|
|
6
4
|
if (prop.object) {
|
|
7
5
|
return [prop.name];
|
|
8
6
|
}
|
|
9
7
|
return Object.values(prop.embeddedProps).flatMap(p => {
|
|
10
|
-
/*
|
|
8
|
+
/* v8 ignore next */
|
|
11
9
|
if (p.embeddable && !p.object) {
|
|
12
10
|
return expandEmbeddedProperties(p);
|
|
13
11
|
}
|
|
@@ -41,12 +39,12 @@ function expandFields(meta, fields) {
|
|
|
41
39
|
});
|
|
42
40
|
}
|
|
43
41
|
/** @internal */
|
|
44
|
-
function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
42
|
+
export function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
45
43
|
if (options.onConflictMergeFields) {
|
|
46
44
|
const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
|
|
47
45
|
return onConflictMergeFields.flatMap(f => {
|
|
48
46
|
const prop = meta?.properties[f];
|
|
49
|
-
/*
|
|
47
|
+
/* v8 ignore next */
|
|
50
48
|
if (prop?.embeddable && !prop.object) {
|
|
51
49
|
return Object.values(prop.embeddedProps).map(p => p.name);
|
|
52
50
|
}
|
|
@@ -70,12 +68,20 @@ function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
|
70
68
|
return keys;
|
|
71
69
|
}
|
|
72
70
|
/** @internal */
|
|
73
|
-
function getOnConflictReturningFields(meta, data, uniqueFields, options) {
|
|
74
|
-
/*
|
|
71
|
+
export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
|
|
72
|
+
/* v8 ignore next */
|
|
75
73
|
if (!meta) {
|
|
76
74
|
return '*';
|
|
77
75
|
}
|
|
78
|
-
const keys = meta.comparableProps.filter(p =>
|
|
76
|
+
const keys = meta.comparableProps.filter(p => {
|
|
77
|
+
if (p.lazy || p.embeddable) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (p.autoincrement) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return Array.isArray(uniqueFields) && !uniqueFields.includes(p.name);
|
|
84
|
+
}).map(p => p.name);
|
|
79
85
|
if (meta.versionProperty) {
|
|
80
86
|
keys.push(meta.versionProperty);
|
|
81
87
|
}
|
|
@@ -92,3 +98,44 @@ function getOnConflictReturningFields(meta, data, uniqueFields, options) {
|
|
|
92
98
|
}
|
|
93
99
|
return keys.filter(key => !(key in data));
|
|
94
100
|
}
|
|
101
|
+
function getPropertyValue(obj, key) {
|
|
102
|
+
if (key.indexOf('.') === -1) {
|
|
103
|
+
return obj[key];
|
|
104
|
+
}
|
|
105
|
+
const parts = key.split('.');
|
|
106
|
+
let curr = obj;
|
|
107
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
108
|
+
curr[parts[i]] ??= {};
|
|
109
|
+
curr = curr[parts[i]];
|
|
110
|
+
}
|
|
111
|
+
return curr[parts[parts.length - 1]];
|
|
112
|
+
}
|
|
113
|
+
/** @internal */
|
|
114
|
+
export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
115
|
+
const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
|
|
116
|
+
const propIndex = !isRaw(unique) && unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
|
|
117
|
+
if (onConflictFields || where == null) {
|
|
118
|
+
if (propIndex !== false && propIndex >= 0) {
|
|
119
|
+
let key = unique[propIndex];
|
|
120
|
+
if (key.includes('.')) {
|
|
121
|
+
const prop = meta.properties[key.substring(0, key.indexOf('.'))];
|
|
122
|
+
if (prop) {
|
|
123
|
+
key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
where = { [key]: getPropertyValue(data, unique[propIndex]) };
|
|
127
|
+
}
|
|
128
|
+
else if (meta.uniques.length > 0) {
|
|
129
|
+
for (const u of meta.uniques) {
|
|
130
|
+
if (Utils.asArray(u.properties).every(p => data[p] != null)) {
|
|
131
|
+
where = Utils.asArray(u.properties).reduce((o, key) => {
|
|
132
|
+
o[key] = data[key];
|
|
133
|
+
return o;
|
|
134
|
+
}, {});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { where, propIndex };
|
|
141
|
+
}
|
package/decorators/Check.d.ts
DELETED
package/decorators/Check.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Check = Check;
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
const Utils_1 = require("../utils/Utils");
|
|
6
|
-
function Check(options) {
|
|
7
|
-
return function (target, propertyName) {
|
|
8
|
-
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator((propertyName ? target.constructor : target));
|
|
9
|
-
options.property ??= propertyName;
|
|
10
|
-
meta.checks.push(options);
|
|
11
|
-
if (!propertyName) {
|
|
12
|
-
return target;
|
|
13
|
-
}
|
|
14
|
-
return Utils_1.Utils.propertyDecoratorReturnValue();
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ContextProvider } from '../typings';
|
|
2
|
-
export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
|
|
3
|
-
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateRequestContext = CreateRequestContext;
|
|
4
|
-
exports.EnsureRequestContext = EnsureRequestContext;
|
|
5
|
-
const RequestContext_1 = require("../utils/RequestContext");
|
|
6
|
-
const resolveContextProvider_1 = require("../utils/resolveContextProvider");
|
|
7
|
-
const TransactionContext_1 = require("../utils/TransactionContext");
|
|
8
|
-
function CreateRequestContext(context, respectExistingContext = false) {
|
|
9
|
-
return function (target, propertyKey, descriptor) {
|
|
10
|
-
const originalMethod = descriptor.value;
|
|
11
|
-
descriptor.value = async function (...args) {
|
|
12
|
-
const em = await (0, resolveContextProvider_1.resolveContextProvider)(this, context);
|
|
13
|
-
if (!em) {
|
|
14
|
-
const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
|
|
15
|
-
throw new Error(`@${name}() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@${name}(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
16
|
-
}
|
|
17
|
-
// reuse existing context if available for given respect `contextName`
|
|
18
|
-
if (respectExistingContext && RequestContext_1.RequestContext.getEntityManager(em.name)) {
|
|
19
|
-
return originalMethod.apply(this, args);
|
|
20
|
-
}
|
|
21
|
-
// Otherwise, the outer tx context would be preferred.
|
|
22
|
-
const txContext = TransactionContext_1.TransactionContext.currentTransactionContext();
|
|
23
|
-
const provider = txContext ? TransactionContext_1.TransactionContext : RequestContext_1.RequestContext;
|
|
24
|
-
return txContext
|
|
25
|
-
? provider.create(em.fork({ useContext: true }), () => originalMethod.apply(this, args))
|
|
26
|
-
: provider.create(em, () => originalMethod.apply(this, args));
|
|
27
|
-
};
|
|
28
|
-
return descriptor;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function EnsureRequestContext(context) {
|
|
32
|
-
return CreateRequestContext(context, true);
|
|
33
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Dictionary } from '../typings';
|
|
2
|
-
export declare function Embeddable(options?: EmbeddableOptions): <T>(target: T & Dictionary) => T & Dictionary;
|
|
3
|
-
export type EmbeddableOptions = {
|
|
4
|
-
discriminatorColumn?: string;
|
|
5
|
-
discriminatorMap?: Dictionary<string>;
|
|
6
|
-
discriminatorValue?: number | string;
|
|
7
|
-
abstract?: boolean;
|
|
8
|
-
};
|
package/decorators/Embeddable.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Embeddable = Embeddable;
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
function Embeddable(options = {}) {
|
|
6
|
-
return function (target) {
|
|
7
|
-
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target);
|
|
8
|
-
meta.class = target;
|
|
9
|
-
meta.name = target.name;
|
|
10
|
-
meta.embeddable = true;
|
|
11
|
-
Object.assign(meta, options);
|
|
12
|
-
return target;
|
|
13
|
-
};
|
|
14
|
-
}
|
package/decorators/Embedded.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AnyEntity } from '../typings';
|
|
2
|
-
export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
|
|
3
|
-
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|
|
4
|
-
export type EmbeddedPrefixMode = 'absolute' | 'relative';
|
|
5
|
-
export type EmbeddedOptions = {
|
|
6
|
-
entity?: string | (() => AnyEntity | AnyEntity[]);
|
|
7
|
-
type?: string;
|
|
8
|
-
prefix?: string | boolean;
|
|
9
|
-
prefixMode?: EmbeddedPrefixMode;
|
|
10
|
-
nullable?: boolean;
|
|
11
|
-
object?: boolean;
|
|
12
|
-
array?: boolean;
|
|
13
|
-
hidden?: boolean;
|
|
14
|
-
serializer?: (value: any) => any;
|
|
15
|
-
serializedName?: string;
|
|
16
|
-
groups?: string[];
|
|
17
|
-
persist?: boolean;
|
|
18
|
-
};
|
package/decorators/Embedded.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Embedded = Embedded;
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const enums_1 = require("../enums");
|
|
7
|
-
function Embedded(type = {}, options = {}) {
|
|
8
|
-
return function (target, propertyName) {
|
|
9
|
-
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
10
|
-
metadata_1.MetadataValidator.validateSingleDecorator(meta, propertyName, enums_1.ReferenceKind.EMBEDDED);
|
|
11
|
-
options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
|
|
12
|
-
utils_1.Utils.defaultValue(options, 'prefix', true);
|
|
13
|
-
meta.properties[propertyName] = {
|
|
14
|
-
name: propertyName,
|
|
15
|
-
kind: enums_1.ReferenceKind.EMBEDDED,
|
|
16
|
-
...options,
|
|
17
|
-
};
|
|
18
|
-
return utils_1.Utils.propertyDecoratorReturnValue();
|
|
19
|
-
};
|
|
20
|
-
}
|
package/decorators/Entity.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Constructor, Dictionary, FilterQuery } from '../typings';
|
|
2
|
-
import type { FindOptions } from '../drivers/IDatabaseDriver';
|
|
3
|
-
export declare function Entity(options?: EntityOptions<any>): <T>(target: T & Dictionary) => T & Dictionary;
|
|
4
|
-
export type EntityOptions<T> = {
|
|
5
|
-
tableName?: string;
|
|
6
|
-
schema?: string;
|
|
7
|
-
collection?: string;
|
|
8
|
-
discriminatorColumn?: string;
|
|
9
|
-
discriminatorMap?: Dictionary<string>;
|
|
10
|
-
discriminatorValue?: number | string;
|
|
11
|
-
forceConstructor?: boolean;
|
|
12
|
-
comment?: string;
|
|
13
|
-
abstract?: boolean;
|
|
14
|
-
readonly?: boolean;
|
|
15
|
-
virtual?: boolean;
|
|
16
|
-
expression?: string | ((em: any, where: FilterQuery<T>, options: FindOptions<T, any, any, any>) => object);
|
|
17
|
-
repository?: () => Constructor;
|
|
18
|
-
};
|
package/decorators/Entity.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Entity = Entity;
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
function Entity(options = {}) {
|
|
7
|
-
return function (target) {
|
|
8
|
-
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target);
|
|
9
|
-
utils_1.Utils.mergeConfig(meta, options);
|
|
10
|
-
meta.class = target;
|
|
11
|
-
if (!options.abstract || meta.discriminatorColumn) {
|
|
12
|
-
meta.name = target.name;
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
}
|
package/decorators/Enum.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PropertyOptions } from './Property';
|
|
2
|
-
import type { AnyEntity, Dictionary } from '../typings';
|
|
3
|
-
export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: AnyEntity, propertyName: string) => any;
|
|
4
|
-
export interface EnumOptions<T> extends PropertyOptions<T> {
|
|
5
|
-
items?: (number | string)[] | (() => Dictionary);
|
|
6
|
-
array?: boolean;
|
|
7
|
-
/** for postgres, by default it uses text column with check constraint */
|
|
8
|
-
nativeEnumName?: string;
|
|
9
|
-
}
|
package/decorators/Enum.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Enum = Enum;
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
const enums_1 = require("../enums");
|
|
6
|
-
const Utils_1 = require("../utils/Utils");
|
|
7
|
-
function Enum(options = {}) {
|
|
8
|
-
return function (target, propertyName) {
|
|
9
|
-
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
10
|
-
options = options instanceof Function ? { items: options } : options;
|
|
11
|
-
meta.properties[propertyName] = {
|
|
12
|
-
name: propertyName,
|
|
13
|
-
kind: enums_1.ReferenceKind.SCALAR,
|
|
14
|
-
enum: true,
|
|
15
|
-
...options,
|
|
16
|
-
};
|
|
17
|
-
return Utils_1.Utils.propertyDecoratorReturnValue();
|
|
18
|
-
};
|
|
19
|
-
}
|