@mikro-orm/core 7.0.0-dev.99 → 7.0.0-rc.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 +34 -17
- package/EntityManager.js +95 -103
- package/MikroORM.d.ts +5 -5
- package/MikroORM.js +25 -20
- package/cache/FileCacheAdapter.js +11 -3
- package/connections/Connection.d.ts +3 -2
- package/connections/Connection.js +4 -3
- package/drivers/DatabaseDriver.d.ts +11 -11
- package/drivers/DatabaseDriver.js +91 -25
- package/drivers/IDatabaseDriver.d.ts +50 -20
- package/entity/BaseEntity.d.ts +61 -1
- package/entity/Collection.d.ts +8 -1
- package/entity/Collection.js +12 -13
- package/entity/EntityAssigner.js +9 -9
- package/entity/EntityFactory.d.ts +6 -1
- package/entity/EntityFactory.js +40 -22
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +27 -4
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +193 -80
- package/entity/EntityRepository.d.ts +27 -7
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/WrappedEntity.d.ts +2 -2
- package/entity/WrappedEntity.js +1 -1
- package/entity/defineEntity.d.ts +89 -50
- package/entity/defineEntity.js +12 -0
- package/entity/index.d.ts +1 -0
- package/entity/index.js +1 -0
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +33 -0
- package/entity/validators.js +2 -2
- package/enums.d.ts +2 -2
- package/enums.js +1 -0
- package/errors.d.ts +16 -8
- package/errors.js +40 -13
- package/hydration/ObjectHydrator.js +63 -21
- package/index.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/inspect.js +1 -6
- package/metadata/EntitySchema.d.ts +43 -13
- package/metadata/EntitySchema.js +82 -27
- package/metadata/MetadataDiscovery.d.ts +60 -3
- package/metadata/MetadataDiscovery.js +665 -154
- package/metadata/MetadataProvider.js +3 -1
- package/metadata/MetadataStorage.d.ts +13 -6
- package/metadata/MetadataStorage.js +64 -19
- package/metadata/MetadataValidator.d.ts +32 -2
- package/metadata/MetadataValidator.js +196 -31
- package/metadata/discover-entities.js +5 -5
- package/metadata/types.d.ts +111 -14
- package/naming-strategy/AbstractNamingStrategy.d.ts +11 -3
- package/naming-strategy/AbstractNamingStrategy.js +12 -0
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +17 -3
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/package.json +2 -2
- package/platforms/Platform.d.ts +4 -2
- package/platforms/Platform.js +5 -2
- package/serialization/EntitySerializer.d.ts +3 -0
- package/serialization/EntitySerializer.js +15 -13
- package/serialization/EntityTransformer.js +6 -6
- package/serialization/SerializationContext.d.ts +6 -6
- package/typings.d.ts +325 -110
- package/typings.js +84 -17
- package/unit-of-work/ChangeSet.d.ts +4 -3
- package/unit-of-work/ChangeSet.js +2 -3
- package/unit-of-work/ChangeSetComputer.d.ts +3 -6
- package/unit-of-work/ChangeSetComputer.js +34 -13
- package/unit-of-work/ChangeSetPersister.d.ts +12 -10
- package/unit-of-work/ChangeSetPersister.js +55 -25
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +21 -3
- package/unit-of-work/UnitOfWork.js +203 -56
- package/utils/AbstractSchemaGenerator.js +17 -8
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +52 -11
- package/utils/Configuration.js +12 -8
- package/utils/Cursor.js +21 -8
- package/utils/DataloaderUtils.js +13 -11
- package/utils/EntityComparator.d.ts +14 -7
- package/utils/EntityComparator.js +132 -46
- package/utils/QueryHelper.d.ts +16 -6
- package/utils/QueryHelper.js +53 -18
- package/utils/RawQueryFragment.d.ts +28 -23
- package/utils/RawQueryFragment.js +34 -56
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +1 -1
- package/utils/Utils.d.ts +7 -26
- package/utils/Utils.js +25 -79
- package/utils/clone.js +7 -21
- package/utils/env-vars.d.ts +4 -0
- package/utils/env-vars.js +13 -3
- package/utils/fs-utils.d.ts +21 -0
- package/utils/fs-utils.js +106 -11
- package/utils/upsert-utils.d.ts +4 -4
package/utils/fs-utils.js
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { existsSync, globSync, mkdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
1
|
+
import { existsSync, globSync as nodeGlobSync, mkdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join, normalize, relative } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
4
|
import { Utils } from './Utils.js';
|
|
5
5
|
import { colors } from '../logging/colors.js';
|
|
6
|
+
let globSync = (patterns, options) => {
|
|
7
|
+
const files = nodeGlobSync(patterns, { ...options, withFileTypes: true });
|
|
8
|
+
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
9
|
+
};
|
|
6
10
|
export const fs = {
|
|
11
|
+
async init() {
|
|
12
|
+
const tinyGlobby = await import('tinyglobby').catch(() => null);
|
|
13
|
+
if (tinyGlobby) {
|
|
14
|
+
globSync = (patterns, options) => {
|
|
15
|
+
patterns = Utils.asArray(patterns).map(p => p.replace(/\\/g, '/'));
|
|
16
|
+
if (options?.cwd) {
|
|
17
|
+
options = { ...options, cwd: options.cwd.replace(/\\/g, '/') };
|
|
18
|
+
}
|
|
19
|
+
return tinyGlobby.globSync(patterns, { ...options, expandDirectories: false });
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
},
|
|
7
23
|
pathExists(path) {
|
|
8
24
|
if (/[*?[\]]/.test(path)) {
|
|
9
25
|
return globSync(path).length > 0;
|
|
@@ -20,30 +36,49 @@ export const fs = {
|
|
|
20
36
|
return JSON.parse(file.toString());
|
|
21
37
|
},
|
|
22
38
|
glob(input, cwd) {
|
|
39
|
+
const patterns = Array.isArray(input) ? input : [input];
|
|
40
|
+
const positive = [];
|
|
41
|
+
const negative = [];
|
|
42
|
+
for (const p of patterns) {
|
|
43
|
+
if (p.startsWith('!')) {
|
|
44
|
+
negative.push(p.slice(1));
|
|
45
|
+
}
|
|
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) {
|
|
23
60
|
if (Array.isArray(input)) {
|
|
24
|
-
return input.flatMap(paths => this.
|
|
61
|
+
return input.flatMap(paths => this.resolveGlob(paths, cwd));
|
|
25
62
|
}
|
|
26
63
|
const hasGlobChars = /[*?[\]]/.test(input);
|
|
27
64
|
if (!hasGlobChars) {
|
|
28
65
|
try {
|
|
29
|
-
const s = statSync(cwd ?
|
|
66
|
+
const s = statSync(cwd ? this.normalizePath(cwd, input) : input);
|
|
30
67
|
if (s.isDirectory()) {
|
|
31
|
-
|
|
32
|
-
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
68
|
+
return globSync(join(input, '**'), { cwd });
|
|
33
69
|
}
|
|
34
70
|
}
|
|
35
71
|
catch {
|
|
36
72
|
// ignore
|
|
37
73
|
}
|
|
38
74
|
}
|
|
39
|
-
|
|
40
|
-
return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
|
|
75
|
+
return globSync(input, { cwd });
|
|
41
76
|
},
|
|
42
77
|
getPackageConfig(basePath = process.cwd()) {
|
|
43
78
|
if (this.pathExists(`${basePath}/package.json`)) {
|
|
44
79
|
try {
|
|
45
|
-
const path = import.meta.resolve(`${basePath}/package.json`);
|
|
46
|
-
return this.readJSONSync(
|
|
80
|
+
const path = this.normalizePath(import.meta.resolve(`${basePath}/package.json`));
|
|
81
|
+
return this.readJSONSync(path);
|
|
47
82
|
}
|
|
48
83
|
catch (e) {
|
|
49
84
|
/* v8 ignore next */
|
|
@@ -93,5 +128,65 @@ export const fs = {
|
|
|
93
128
|
}
|
|
94
129
|
}
|
|
95
130
|
},
|
|
131
|
+
/**
|
|
132
|
+
* Resolves and normalizes a series of path parts relative to each preceding part.
|
|
133
|
+
* If any part is a `file:` URL, it is converted to a local path. If any part is an
|
|
134
|
+
* absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
|
|
135
|
+
* Trailing directory separators are removed, and all directory separators are converted
|
|
136
|
+
* to POSIX-style separators (`/`).
|
|
137
|
+
*/
|
|
138
|
+
normalizePath(...parts) {
|
|
139
|
+
let start = 0;
|
|
140
|
+
for (let i = 0; i < parts.length; i++) {
|
|
141
|
+
const part = parts[i];
|
|
142
|
+
if (isAbsolute(part)) {
|
|
143
|
+
start = i;
|
|
144
|
+
}
|
|
145
|
+
else if (part.startsWith('file:')) {
|
|
146
|
+
start = i;
|
|
147
|
+
parts[i] = fileURLToPath(part);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (start > 0) {
|
|
151
|
+
parts = parts.slice(start);
|
|
152
|
+
}
|
|
153
|
+
let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
|
|
154
|
+
path = normalize(path).replace(/\\/g, '/');
|
|
155
|
+
return (path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!')) ? path : './' + path;
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Determines the relative path between two paths. If either path is a `file:` URL,
|
|
159
|
+
* it is converted to a local path.
|
|
160
|
+
*/
|
|
161
|
+
relativePath(path, relativeTo) {
|
|
162
|
+
if (!path) {
|
|
163
|
+
return path;
|
|
164
|
+
}
|
|
165
|
+
path = this.normalizePath(path);
|
|
166
|
+
if (path.startsWith('.')) {
|
|
167
|
+
return path;
|
|
168
|
+
}
|
|
169
|
+
path = relative(this.normalizePath(relativeTo), path);
|
|
170
|
+
return this.normalizePath(path);
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Computes the absolute path to for the given path relative to the provided base directory.
|
|
174
|
+
* If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
|
|
175
|
+
*/
|
|
176
|
+
absolutePath(path, baseDir = process.cwd()) {
|
|
177
|
+
if (!path) {
|
|
178
|
+
return this.normalizePath(baseDir);
|
|
179
|
+
}
|
|
180
|
+
if (!isAbsolute(path) && !path.startsWith('file://')) {
|
|
181
|
+
path = baseDir + '/' + path;
|
|
182
|
+
}
|
|
183
|
+
return this.normalizePath(path);
|
|
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
|
+
},
|
|
96
191
|
};
|
|
97
192
|
export * from '../cache/FileCacheAdapter.js';
|
package/utils/upsert-utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { EntityData, EntityMetadata, FilterQuery } from '../typings.js';
|
|
2
2
|
import type { UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type Raw } from '../utils/RawQueryFragment.js';
|
|
4
4
|
/** @internal */
|
|
5
|
-
export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] |
|
|
5
|
+
export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T>): (keyof T)[];
|
|
6
6
|
/** @internal */
|
|
7
|
-
export declare function getOnConflictReturningFields<T, P extends string>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] |
|
|
7
|
+
export declare function getOnConflictReturningFields<T, P extends string>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T, P>): (keyof T)[] | '*';
|
|
8
8
|
/** @internal */
|
|
9
|
-
export declare function getWhereCondition<T extends object>(meta: EntityMetadata<T>, onConflictFields: (keyof T)[] |
|
|
9
|
+
export declare function getWhereCondition<T extends object>(meta: EntityMetadata<T>, onConflictFields: (keyof T)[] | Raw | undefined, data: EntityData<T>, where: FilterQuery<T>): {
|
|
10
10
|
where: FilterQuery<T>;
|
|
11
11
|
propIndex: number | false;
|
|
12
12
|
};
|