@mikro-orm/core 7.0.4-dev.8 → 7.0.4
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 +884 -583
- package/EntityManager.js +1922 -1895
- package/MikroORM.d.ts +103 -74
- package/MikroORM.js +178 -179
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +30 -24
- package/cache/FileCacheAdapter.js +80 -78
- package/cache/GeneratedCacheAdapter.d.ts +18 -20
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +18 -20
- package/cache/MemoryCacheAdapter.js +35 -36
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +95 -84
- package/connections/Connection.js +165 -168
- package/drivers/DatabaseDriver.d.ts +186 -80
- package/drivers/DatabaseDriver.js +450 -443
- package/drivers/IDatabaseDriver.d.ts +440 -301
- package/entity/BaseEntity.d.ts +120 -83
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +212 -179
- package/entity/Collection.js +727 -721
- package/entity/EntityAssigner.d.ts +88 -77
- package/entity/EntityAssigner.js +231 -230
- package/entity/EntityFactory.d.ts +66 -54
- package/entity/EntityFactory.js +425 -383
- package/entity/EntityHelper.d.ts +34 -22
- package/entity/EntityHelper.js +280 -267
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +98 -72
- package/entity/EntityLoader.js +753 -723
- package/entity/EntityRepository.d.ts +316 -201
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +126 -82
- package/entity/Reference.js +278 -274
- package/entity/WrappedEntity.d.ts +115 -72
- package/entity/WrappedEntity.js +168 -166
- package/entity/defineEntity.d.ts +1315 -636
- package/entity/defineEntity.js +527 -518
- package/entity/utils.d.ts +13 -3
- package/entity/utils.js +71 -73
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +258 -253
- package/enums.js +251 -252
- package/errors.d.ts +114 -72
- package/errors.js +350 -253
- package/events/EventManager.d.ts +26 -14
- package/events/EventManager.js +79 -77
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +15 -8
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +23 -40
- package/exceptions.js +35 -52
- package/hydration/Hydrator.d.ts +42 -17
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +50 -17
- package/hydration/ObjectHydrator.js +481 -416
- package/index.d.ts +116 -2
- package/index.js +10 -1
- package/logging/DefaultLogger.d.ts +34 -32
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +13 -11
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +11 -10
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +211 -127
- package/metadata/EntitySchema.js +397 -398
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1951 -1863
- package/metadata/MetadataProvider.d.ts +24 -21
- package/metadata/MetadataProvider.js +82 -84
- package/metadata/MetadataStorage.d.ts +38 -32
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +381 -338
- package/metadata/discover-entities.d.ts +5 -2
- package/metadata/discover-entities.js +35 -27
- package/metadata/types.d.ts +615 -531
- package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
- package/naming-strategy/AbstractNamingStrategy.js +90 -85
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +109 -99
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +7 -4
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +310 -299
- package/platforms/Platform.js +663 -636
- package/serialization/EntitySerializer.d.ts +49 -26
- package/serialization/EntitySerializer.js +224 -218
- package/serialization/EntityTransformer.d.ts +10 -6
- package/serialization/EntityTransformer.js +219 -217
- package/serialization/SerializationContext.d.ts +27 -23
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +17 -10
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +83 -79
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +75 -49
- package/types/index.js +52 -26
- package/typings.d.ts +1250 -737
- package/typings.js +244 -231
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +178 -170
- package/unit-of-work/ChangeSetPersister.d.ts +63 -44
- package/unit-of-work/ChangeSetPersister.js +442 -421
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +89 -88
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +181 -141
- package/unit-of-work/UnitOfWork.js +1200 -1183
- package/utils/AbstractMigrator.d.ts +111 -91
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +43 -34
- package/utils/AbstractSchemaGenerator.js +121 -122
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +34 -35
- package/utils/Configuration.d.ts +852 -808
- package/utils/Configuration.js +359 -344
- package/utils/Cursor.d.ts +40 -22
- package/utils/Cursor.js +135 -127
- package/utils/DataloaderUtils.d.ts +58 -43
- package/utils/DataloaderUtils.js +203 -198
- package/utils/EntityComparator.d.ts +98 -81
- package/utils/EntityComparator.js +828 -728
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +79 -51
- package/utils/QueryHelper.js +372 -361
- package/utils/RawQueryFragment.d.ts +50 -34
- package/utils/RawQueryFragment.js +107 -105
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +52 -53
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +199 -197
- package/utils/Utils.d.ts +204 -145
- package/utils/Utils.js +812 -810
- package/utils/clone.js +104 -113
- package/utils/env-vars.js +90 -88
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +180 -181
- package/utils/upsert-utils.d.ts +20 -5
- package/utils/upsert-utils.js +114 -116
package/utils/fs-utils.js
CHANGED
|
@@ -5,189 +5,188 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
5
5
|
import { Utils } from './Utils.js';
|
|
6
6
|
import { colors } from '../logging/colors.js';
|
|
7
7
|
let globSync = (patterns, options) => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const files = nodeGlobSync(patterns, { ...options, withFileTypes: true });
|
|
9
|
+
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
10
10
|
};
|
|
11
11
|
export const fs = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return this.readJSONSync(path);
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
/* v8 ignore next */
|
|
86
|
-
return {};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const parentFolder = realpathSync(`${basePath}/..`);
|
|
90
|
-
// we reached the root folder
|
|
91
|
-
if (basePath === parentFolder) {
|
|
92
|
-
return {};
|
|
93
|
-
}
|
|
94
|
-
return this.getPackageConfig(parentFolder);
|
|
95
|
-
},
|
|
96
|
-
getORMPackages() {
|
|
97
|
-
const pkg = this.getPackageConfig();
|
|
98
|
-
return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
99
|
-
},
|
|
100
|
-
getORMPackageVersion(name) {
|
|
101
|
-
try {
|
|
102
|
-
const path = import.meta.resolve(`${name}/package.json`);
|
|
103
|
-
const pkg = this.readJSONSync(fileURLToPath(path));
|
|
104
|
-
return pkg?.version;
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
111
|
-
checkPackageVersion() {
|
|
112
|
-
const coreVersion = Utils.getORMVersion();
|
|
113
|
-
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const deps = this.getORMPackages();
|
|
117
|
-
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
118
|
-
const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
|
|
119
|
-
for (const ormPackage of ormPackages) {
|
|
120
|
-
const version = this.getORMPackageVersion(ormPackage);
|
|
121
|
-
if (version != null && version !== coreVersion) {
|
|
122
|
-
throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
|
|
123
|
-
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
|
|
124
|
-
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
125
|
-
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
/**
|
|
130
|
-
* Resolves and normalizes a series of path parts relative to each preceding part.
|
|
131
|
-
* If any part is a `file:` URL, it is converted to a local path. If any part is an
|
|
132
|
-
* absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
|
|
133
|
-
* Trailing directory separators are removed, and all directory separators are converted
|
|
134
|
-
* to POSIX-style separators (`/`).
|
|
135
|
-
*/
|
|
136
|
-
normalizePath(...parts) {
|
|
137
|
-
let start = 0;
|
|
138
|
-
for (let i = 0; i < parts.length; i++) {
|
|
139
|
-
const part = parts[i];
|
|
140
|
-
if (isAbsolute(part)) {
|
|
141
|
-
start = i;
|
|
142
|
-
}
|
|
143
|
-
else if (part.startsWith('file:')) {
|
|
144
|
-
start = i;
|
|
145
|
-
parts[i] = fileURLToPath(part);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (start > 0) {
|
|
149
|
-
parts = parts.slice(start);
|
|
150
|
-
}
|
|
151
|
-
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
152
|
-
path = normalize(path).replace(/\\/g, '/');
|
|
153
|
-
return /^[/.]|[a-zA-Z]:/.exec(path) || path.startsWith('!') ? path : './' + path;
|
|
154
|
-
},
|
|
155
|
-
/**
|
|
156
|
-
* Determines the relative path between two paths. If either path is a `file:` URL,
|
|
157
|
-
* it is converted to a local path.
|
|
158
|
-
*/
|
|
159
|
-
relativePath(path, relativeTo) {
|
|
160
|
-
if (!path) {
|
|
161
|
-
return path;
|
|
162
|
-
}
|
|
163
|
-
path = this.normalizePath(path);
|
|
164
|
-
if (path.startsWith('.')) {
|
|
165
|
-
return path;
|
|
166
|
-
}
|
|
167
|
-
path = relative(this.normalizePath(relativeTo), path);
|
|
168
|
-
return this.normalizePath(path);
|
|
169
|
-
},
|
|
170
|
-
/**
|
|
171
|
-
* Computes the absolute path to for the given path relative to the provided base directory.
|
|
172
|
-
* If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
|
|
173
|
-
*/
|
|
174
|
-
absolutePath(path, baseDir = process.cwd()) {
|
|
175
|
-
if (!path) {
|
|
176
|
-
return this.normalizePath(baseDir);
|
|
177
|
-
}
|
|
178
|
-
if (!isAbsolute(path) && !path.startsWith('file://')) {
|
|
179
|
-
path = baseDir + '/' + path;
|
|
180
|
-
}
|
|
181
|
-
return this.normalizePath(path);
|
|
182
|
-
},
|
|
183
|
-
async writeFile(path, data, options) {
|
|
184
|
-
await nodeWriteFile(path, data, options);
|
|
185
|
-
},
|
|
186
|
-
async dynamicImport(id) {
|
|
12
|
+
async init() {
|
|
13
|
+
const tinyGlobby = await import('tinyglobby').catch(() => null);
|
|
14
|
+
if (tinyGlobby) {
|
|
15
|
+
globSync = (patterns, options) => {
|
|
16
|
+
patterns = Utils.asArray(patterns).map(p => p.replace(/\\/g, '/'));
|
|
17
|
+
if (options?.cwd) {
|
|
18
|
+
options = { ...options, cwd: options.cwd.replace(/\\/g, '/') };
|
|
19
|
+
}
|
|
20
|
+
return tinyGlobby.globSync(patterns, { ...options, expandDirectories: false });
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
pathExists(path) {
|
|
25
|
+
if (/[*?[\]]/.test(path)) {
|
|
26
|
+
return globSync(path).length > 0;
|
|
27
|
+
}
|
|
28
|
+
return existsSync(path);
|
|
29
|
+
},
|
|
30
|
+
ensureDir(path) {
|
|
31
|
+
if (!existsSync(path)) {
|
|
32
|
+
mkdirSync(path, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
readJSONSync(path) {
|
|
36
|
+
const file = readFileSync(path);
|
|
37
|
+
return JSON.parse(file.toString());
|
|
38
|
+
},
|
|
39
|
+
glob(input, cwd) {
|
|
40
|
+
const patterns = Array.isArray(input) ? input : [input];
|
|
41
|
+
const positive = [];
|
|
42
|
+
const negative = [];
|
|
43
|
+
for (const p of patterns) {
|
|
44
|
+
if (p.startsWith('!')) {
|
|
45
|
+
negative.push(p.slice(1));
|
|
46
|
+
} else {
|
|
47
|
+
positive.push(p);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const included = new Set(this.resolveGlob(positive, cwd));
|
|
51
|
+
if (included.size > 0 && negative.length > 0) {
|
|
52
|
+
const excluded = this.resolveGlob(negative, cwd);
|
|
53
|
+
for (const file of excluded) {
|
|
54
|
+
included.delete(file);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [...included];
|
|
58
|
+
},
|
|
59
|
+
resolveGlob(input, cwd) {
|
|
60
|
+
if (Array.isArray(input)) {
|
|
61
|
+
return input.flatMap(paths => this.resolveGlob(paths, cwd));
|
|
62
|
+
}
|
|
63
|
+
const hasGlobChars = /[*?[\]]/.test(input);
|
|
64
|
+
if (!hasGlobChars) {
|
|
65
|
+
try {
|
|
66
|
+
const s = statSync(cwd ? this.normalizePath(cwd, input) : input);
|
|
67
|
+
if (s.isDirectory()) {
|
|
68
|
+
return globSync(join(input, '**'), { cwd });
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// ignore
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return globSync(input, { cwd });
|
|
75
|
+
},
|
|
76
|
+
getPackageConfig(basePath = process.cwd()) {
|
|
77
|
+
if (this.pathExists(`${basePath}/package.json`)) {
|
|
78
|
+
try {
|
|
79
|
+
const path = this.normalizePath(import.meta.resolve(`${basePath}/package.json`));
|
|
80
|
+
return this.readJSONSync(path);
|
|
81
|
+
} catch (e) {
|
|
187
82
|
/* v8 ignore next */
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const parentFolder = realpathSync(`${basePath}/..`);
|
|
87
|
+
// we reached the root folder
|
|
88
|
+
if (basePath === parentFolder) {
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
return this.getPackageConfig(parentFolder);
|
|
92
|
+
},
|
|
93
|
+
getORMPackages() {
|
|
94
|
+
const pkg = this.getPackageConfig();
|
|
95
|
+
return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
96
|
+
},
|
|
97
|
+
getORMPackageVersion(name) {
|
|
98
|
+
try {
|
|
99
|
+
const path = import.meta.resolve(`${name}/package.json`);
|
|
100
|
+
const pkg = this.readJSONSync(fileURLToPath(path));
|
|
101
|
+
return pkg?.version;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
107
|
+
checkPackageVersion() {
|
|
108
|
+
const coreVersion = Utils.getORMVersion();
|
|
109
|
+
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const deps = this.getORMPackages();
|
|
113
|
+
const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
|
|
114
|
+
const ormPackages = [...deps].filter(
|
|
115
|
+
d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)),
|
|
116
|
+
);
|
|
117
|
+
for (const ormPackage of ormPackages) {
|
|
118
|
+
const version = this.getORMPackageVersion(ormPackage);
|
|
119
|
+
if (version != null && version !== coreVersion) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
|
|
122
|
+
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
|
|
123
|
+
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
124
|
+
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Resolves and normalizes a series of path parts relative to each preceding part.
|
|
131
|
+
* If any part is a `file:` URL, it is converted to a local path. If any part is an
|
|
132
|
+
* absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
|
|
133
|
+
* Trailing directory separators are removed, and all directory separators are converted
|
|
134
|
+
* to POSIX-style separators (`/`).
|
|
135
|
+
*/
|
|
136
|
+
normalizePath(...parts) {
|
|
137
|
+
let start = 0;
|
|
138
|
+
for (let i = 0; i < parts.length; i++) {
|
|
139
|
+
const part = parts[i];
|
|
140
|
+
if (isAbsolute(part)) {
|
|
141
|
+
start = i;
|
|
142
|
+
} else if (part.startsWith('file:')) {
|
|
143
|
+
start = i;
|
|
144
|
+
parts[i] = fileURLToPath(part);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (start > 0) {
|
|
148
|
+
parts = parts.slice(start);
|
|
149
|
+
}
|
|
150
|
+
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
151
|
+
path = normalize(path).replace(/\\/g, '/');
|
|
152
|
+
return /^[/.]|[a-zA-Z]:/.exec(path) || path.startsWith('!') ? path : './' + path;
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* Determines the relative path between two paths. If either path is a `file:` URL,
|
|
156
|
+
* it is converted to a local path.
|
|
157
|
+
*/
|
|
158
|
+
relativePath(path, relativeTo) {
|
|
159
|
+
if (!path) {
|
|
160
|
+
return path;
|
|
161
|
+
}
|
|
162
|
+
path = this.normalizePath(path);
|
|
163
|
+
if (path.startsWith('.')) {
|
|
164
|
+
return path;
|
|
165
|
+
}
|
|
166
|
+
path = relative(this.normalizePath(relativeTo), path);
|
|
167
|
+
return this.normalizePath(path);
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Computes the absolute path to for the given path relative to the provided base directory.
|
|
171
|
+
* If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
|
|
172
|
+
*/
|
|
173
|
+
absolutePath(path, baseDir = process.cwd()) {
|
|
174
|
+
if (!path) {
|
|
175
|
+
return this.normalizePath(baseDir);
|
|
176
|
+
}
|
|
177
|
+
if (!isAbsolute(path) && !path.startsWith('file://')) {
|
|
178
|
+
path = baseDir + '/' + path;
|
|
179
|
+
}
|
|
180
|
+
return this.normalizePath(path);
|
|
181
|
+
},
|
|
182
|
+
async writeFile(path, data, options) {
|
|
183
|
+
await nodeWriteFile(path, data, options);
|
|
184
|
+
},
|
|
185
|
+
async dynamicImport(id) {
|
|
186
|
+
/* v8 ignore next */
|
|
187
|
+
const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
|
|
188
|
+
const dynamicImportProvider = globalThis.dynamicImportProvider ?? (id => import(id));
|
|
189
|
+
return dynamicImportProvider(specifier);
|
|
190
|
+
},
|
|
192
191
|
};
|
|
193
192
|
export * from '../cache/FileCacheAdapter.js';
|
package/utils/upsert-utils.d.ts
CHANGED
|
@@ -2,11 +2,26 @@ import type { EntityData, EntityMetadata, FilterQuery } from '../typings.js';
|
|
|
2
2
|
import type { UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
3
3
|
import { type Raw } from '../utils/RawQueryFragment.js';
|
|
4
4
|
/** @internal */
|
|
5
|
-
export declare function getOnConflictFields<T>(
|
|
5
|
+
export declare function getOnConflictFields<T>(
|
|
6
|
+
meta: EntityMetadata<T> | undefined,
|
|
7
|
+
data: EntityData<T>,
|
|
8
|
+
uniqueFields: (keyof T)[] | Raw,
|
|
9
|
+
options: UpsertOptions<T>,
|
|
10
|
+
): (keyof T)[];
|
|
6
11
|
/** @internal */
|
|
7
|
-
export declare function getOnConflictReturningFields<T, P extends string>(
|
|
12
|
+
export declare function getOnConflictReturningFields<T, P extends string>(
|
|
13
|
+
meta: EntityMetadata<T> | undefined,
|
|
14
|
+
data: EntityData<T>,
|
|
15
|
+
uniqueFields: (keyof T)[] | Raw,
|
|
16
|
+
options: UpsertOptions<T, P>,
|
|
17
|
+
): (keyof T)[] | '*';
|
|
8
18
|
/** @internal */
|
|
9
|
-
export declare function getWhereCondition<T extends object>(
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
export declare function getWhereCondition<T extends object>(
|
|
20
|
+
meta: EntityMetadata<T>,
|
|
21
|
+
onConflictFields: (keyof T)[] | Raw | undefined,
|
|
22
|
+
data: EntityData<T>,
|
|
23
|
+
where: FilterQuery<T>,
|
|
24
|
+
): {
|
|
25
|
+
where: FilterQuery<T>;
|
|
26
|
+
propIndex: number | false;
|
|
12
27
|
};
|
package/utils/upsert-utils.js
CHANGED
|
@@ -1,144 +1,142 @@
|
|
|
1
1
|
import { isRaw } from '../utils/RawQueryFragment.js';
|
|
2
2
|
import { Utils } from './Utils.js';
|
|
3
3
|
function expandEmbeddedProperties(prop, key) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
if (prop.object) {
|
|
5
|
+
return [prop.name];
|
|
6
|
+
}
|
|
7
|
+
return Object.values(prop.embeddedProps).flatMap(p => {
|
|
8
|
+
/* v8 ignore next */
|
|
9
|
+
if (p.embeddable && !p.object) {
|
|
10
|
+
return expandEmbeddedProperties(p);
|
|
6
11
|
}
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
if (p.embeddable && !p.object) {
|
|
10
|
-
return expandEmbeddedProperties(p);
|
|
11
|
-
}
|
|
12
|
-
return [p.name];
|
|
13
|
-
});
|
|
12
|
+
return [p.name];
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Expands dot paths and stars
|
|
17
17
|
*/
|
|
18
18
|
function expandFields(meta, fields) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
return expandEmbeddedProperties(prop, rest);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const prop = meta?.properties[f];
|
|
35
|
-
if (prop?.embeddable) {
|
|
36
|
-
return expandEmbeddedProperties(prop);
|
|
19
|
+
return fields.flatMap(f => {
|
|
20
|
+
if (f === '*' && meta) {
|
|
21
|
+
return meta.comparableProps.filter(p => !p.lazy && !p.embeddable).map(p => p.name);
|
|
22
|
+
}
|
|
23
|
+
if (f.includes('.')) {
|
|
24
|
+
const [k, ...tmp] = f.split('.');
|
|
25
|
+
const rest = tmp.join('.');
|
|
26
|
+
const prop = meta?.properties[k];
|
|
27
|
+
if (prop?.embeddable) {
|
|
28
|
+
if (rest === '*') {
|
|
29
|
+
return expandEmbeddedProperties(prop);
|
|
37
30
|
}
|
|
38
|
-
return
|
|
39
|
-
|
|
31
|
+
return expandEmbeddedProperties(prop, rest);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const prop = meta?.properties[f];
|
|
35
|
+
if (prop?.embeddable) {
|
|
36
|
+
return expandEmbeddedProperties(prop);
|
|
37
|
+
}
|
|
38
|
+
return [f];
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
41
|
/** @internal */
|
|
42
42
|
export function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
const keys = Object.keys(data).flatMap(f => {
|
|
55
|
-
if (!(Array.isArray(uniqueFields) && !uniqueFields.includes(f))) {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
const prop = meta?.properties[f];
|
|
59
|
-
if (prop?.embeddable && !prop.object) {
|
|
60
|
-
return expandEmbeddedProperties(prop);
|
|
61
|
-
}
|
|
62
|
-
return [f];
|
|
43
|
+
if (options.onConflictMergeFields) {
|
|
44
|
+
const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
|
|
45
|
+
return onConflictMergeFields.flatMap(f => {
|
|
46
|
+
const prop = meta?.properties[f];
|
|
47
|
+
/* v8 ignore next */
|
|
48
|
+
if (prop?.embeddable && !prop.object) {
|
|
49
|
+
return Object.values(prop.embeddedProps).map(p => p.name);
|
|
50
|
+
}
|
|
51
|
+
return f;
|
|
63
52
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
}
|
|
54
|
+
const keys = Object.keys(data).flatMap(f => {
|
|
55
|
+
if (!(Array.isArray(uniqueFields) && !uniqueFields.includes(f))) {
|
|
56
|
+
return [];
|
|
67
57
|
}
|
|
68
|
-
|
|
58
|
+
const prop = meta?.properties[f];
|
|
59
|
+
if (prop?.embeddable && !prop.object) {
|
|
60
|
+
return expandEmbeddedProperties(prop);
|
|
61
|
+
}
|
|
62
|
+
return [f];
|
|
63
|
+
});
|
|
64
|
+
if (options.onConflictExcludeFields) {
|
|
65
|
+
const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
|
|
66
|
+
return keys.filter(f => !onConflictExcludeFields.includes(f));
|
|
67
|
+
}
|
|
68
|
+
return keys;
|
|
69
69
|
}
|
|
70
70
|
/** @internal */
|
|
71
71
|
export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
/* v8 ignore next */
|
|
73
|
+
if (!meta) {
|
|
74
|
+
return '*';
|
|
75
|
+
}
|
|
76
|
+
const keys = meta.comparableProps
|
|
77
|
+
.filter(p => {
|
|
78
|
+
if (p.lazy || p.embeddable) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (p.autoincrement) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return Array.isArray(uniqueFields) && !uniqueFields.includes(p.name);
|
|
85
85
|
})
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
86
|
+
.map(p => p.name);
|
|
87
|
+
if (meta.versionProperty) {
|
|
88
|
+
keys.push(meta.versionProperty);
|
|
89
|
+
}
|
|
90
|
+
if (options.onConflictAction === 'ignore') {
|
|
91
|
+
return keys;
|
|
92
|
+
}
|
|
93
|
+
if (options.onConflictMergeFields) {
|
|
94
|
+
const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
|
|
95
|
+
return keys.filter(key => !onConflictMergeFields.includes(key));
|
|
96
|
+
}
|
|
97
|
+
if (options.onConflictExcludeFields) {
|
|
98
|
+
const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
|
|
99
|
+
return [...new Set(keys.concat(...onConflictExcludeFields))];
|
|
100
|
+
}
|
|
101
|
+
return keys.filter(key => !(key in data));
|
|
102
102
|
}
|
|
103
103
|
function getPropertyValue(obj, key) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
if (!key.includes('.')) {
|
|
105
|
+
return obj[key];
|
|
106
|
+
}
|
|
107
|
+
const parts = key.split('.');
|
|
108
|
+
let curr = obj;
|
|
109
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
110
|
+
curr[parts[i]] ??= {};
|
|
111
|
+
curr = curr[parts[i]];
|
|
112
|
+
}
|
|
113
|
+
return curr[parts[parts.length - 1]];
|
|
114
114
|
}
|
|
115
115
|
/** @internal */
|
|
116
116
|
export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
where = { [key]: getPropertyValue(data, unique[propIndex]) };
|
|
117
|
+
const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
|
|
118
|
+
const propIndex = !isRaw(unique) && unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
|
|
119
|
+
if (onConflictFields || where == null) {
|
|
120
|
+
if (propIndex !== false && propIndex >= 0) {
|
|
121
|
+
let key = unique[propIndex];
|
|
122
|
+
if (key.includes('.')) {
|
|
123
|
+
const prop = meta.properties[key.substring(0, key.indexOf('.'))];
|
|
124
|
+
if (prop) {
|
|
125
|
+
key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
|
|
130
126
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
127
|
+
}
|
|
128
|
+
where = { [key]: getPropertyValue(data, unique[propIndex]) };
|
|
129
|
+
} else if (meta.uniques.length > 0) {
|
|
130
|
+
for (const u of meta.uniques) {
|
|
131
|
+
if (Utils.asArray(u.properties).every(p => data[p] != null)) {
|
|
132
|
+
where = Utils.asArray(u.properties).reduce((o, key) => {
|
|
133
|
+
o[key] = data[key];
|
|
134
|
+
return o;
|
|
135
|
+
}, {});
|
|
136
|
+
break;
|
|
141
137
|
}
|
|
138
|
+
}
|
|
142
139
|
}
|
|
143
|
-
|
|
140
|
+
}
|
|
141
|
+
return { where, propIndex };
|
|
144
142
|
}
|