@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
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 +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
|
@@ -1,99 +1,65 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { inspect } from 'node:util';
|
|
3
1
|
import { Utils } from './Utils.js';
|
|
4
2
|
export class RawQueryFragment {
|
|
5
3
|
sql;
|
|
6
4
|
params;
|
|
7
|
-
static #
|
|
8
|
-
static #storage = new AsyncLocalStorage();
|
|
9
|
-
static #index = 0n;
|
|
10
|
-
static cloneRegistry;
|
|
11
|
-
#assigned = false;
|
|
12
|
-
#used = 0;
|
|
5
|
+
static #rawQueryReferences = new WeakMap();
|
|
13
6
|
#key;
|
|
14
7
|
constructor(sql, params = []) {
|
|
15
8
|
this.sql = sql;
|
|
16
9
|
this.params = params;
|
|
17
|
-
this.#key = `[raw]: ${this.sql} (#${RawQueryFragment.#index++})`;
|
|
18
10
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return new RawQueryFragment(`${this.sql} as ${alias}`, this.params);
|
|
11
|
+
get key() {
|
|
12
|
+
if (!this.#key) {
|
|
13
|
+
this.#key = Symbol(this.toJSON());
|
|
14
|
+
RawQueryFragment.#rawQueryReferences.set(this.#key, this);
|
|
24
15
|
}
|
|
16
|
+
return this.#key;
|
|
17
|
+
}
|
|
18
|
+
as(alias) {
|
|
25
19
|
return new RawQueryFragment(`${this.sql} as ??`, [...this.params, alias]);
|
|
26
20
|
}
|
|
27
|
-
|
|
21
|
+
[Symbol.toPrimitive](hint) {
|
|
22
|
+
// if a fragment is converted to string (used as an object key), return a unique symbol
|
|
23
|
+
// and save a weak reference to map so we can retrieve it when compiling the query
|
|
24
|
+
if (hint === 'string') {
|
|
25
|
+
return this.key;
|
|
26
|
+
}
|
|
28
27
|
throw new Error(`Trying to modify raw SQL fragment: '${this.sql}'`);
|
|
29
28
|
}
|
|
29
|
+
get [Symbol.toStringTag]() {
|
|
30
|
+
return this.toJSON();
|
|
31
|
+
}
|
|
30
32
|
toJSON() {
|
|
31
|
-
return this
|
|
33
|
+
return `raw('${this.sql}')`;
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.#used++;
|
|
36
|
-
return this.#key;
|
|
35
|
+
clone() {
|
|
36
|
+
return this;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (this.#assigned) {
|
|
41
|
-
throw new Error(`Cannot reassign already used RawQueryFragment: '${this.sql}'`);
|
|
42
|
-
}
|
|
43
|
-
this.#assigned = true;
|
|
38
|
+
static isKnownFragmentSymbol(key) {
|
|
39
|
+
return typeof key === 'symbol' && this.#rawQueryReferences.has(key);
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
static async run(cb) {
|
|
50
|
-
const removeStack = new Set();
|
|
51
|
-
const res = await this.#storage.run(removeStack, cb);
|
|
52
|
-
removeStack.forEach(key => RawQueryFragment.remove(key));
|
|
53
|
-
removeStack.clear();
|
|
54
|
-
return res;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @internal allows testing we don't leak memory, as the raw fragments cache needs to be cleared automatically
|
|
58
|
-
*/
|
|
59
|
-
static checkCacheSize() {
|
|
60
|
-
return this.#rawQueryCache.size;
|
|
41
|
+
static hasObjectFragments(object) {
|
|
42
|
+
return (Utils.isPlainObject(object) &&
|
|
43
|
+
Object.getOwnPropertySymbols(object).some(symbol => this.isKnownFragmentSymbol(symbol)));
|
|
61
44
|
}
|
|
62
45
|
static isKnownFragment(key) {
|
|
63
46
|
if (key instanceof RawQueryFragment) {
|
|
64
47
|
return true;
|
|
65
48
|
}
|
|
66
|
-
return this
|
|
49
|
+
return this.isKnownFragmentSymbol(key);
|
|
67
50
|
}
|
|
68
|
-
static getKnownFragment(key
|
|
51
|
+
static getKnownFragment(key) {
|
|
69
52
|
if (key instanceof RawQueryFragment) {
|
|
70
53
|
return key;
|
|
71
54
|
}
|
|
72
|
-
|
|
73
|
-
if (raw && cleanup) {
|
|
74
|
-
this.remove(key);
|
|
75
|
-
}
|
|
76
|
-
return raw;
|
|
77
|
-
}
|
|
78
|
-
static remove(key) {
|
|
79
|
-
const raw = this.#rawQueryCache.get(key);
|
|
80
|
-
if (!raw) {
|
|
55
|
+
if (typeof key !== 'symbol') {
|
|
81
56
|
return;
|
|
82
57
|
}
|
|
83
|
-
|
|
84
|
-
if (raw.#used <= 0) {
|
|
85
|
-
const removeStack = this.#storage.getStore();
|
|
86
|
-
if (removeStack) {
|
|
87
|
-
removeStack.add(key);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.#rawQueryCache.delete(key);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
58
|
+
return this.#rawQueryReferences.get(key);
|
|
93
59
|
}
|
|
94
|
-
/* v8 ignore next 8 */
|
|
95
60
|
/** @ignore */
|
|
96
|
-
|
|
61
|
+
/* v8 ignore next */
|
|
62
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
97
63
|
if (this.params) {
|
|
98
64
|
return { sql: this.sql, params: this.params };
|
|
99
65
|
}
|
|
@@ -204,20 +170,19 @@ export function raw(sql, params) {
|
|
|
204
170
|
*
|
|
205
171
|
* // value can be empty array
|
|
206
172
|
* await em.find(User, { [sql`(select 1 = 1)`]: [] });
|
|
173
|
+
*
|
|
174
|
+
* // with type parameter for assignment without casting
|
|
175
|
+
* entity.date = sql<Date>`now()`;
|
|
207
176
|
* ```
|
|
208
177
|
*/
|
|
209
178
|
export function sql(sql, ...values) {
|
|
210
|
-
return raw(sql.
|
|
211
|
-
const valueExists = i < values.length;
|
|
212
|
-
const text = query + queryPart;
|
|
213
|
-
return valueExists ? text + '?' : text;
|
|
214
|
-
}, ''), values);
|
|
179
|
+
return raw(sql.join('?'), values);
|
|
215
180
|
}
|
|
216
181
|
export function createSqlFunction(func, key) {
|
|
217
182
|
if (typeof key === 'string') {
|
|
218
183
|
return raw(`${func}(${key})`);
|
|
219
184
|
}
|
|
220
|
-
return raw(a => `${func}(${
|
|
185
|
+
return raw(a => `${func}(${key(a)})`);
|
|
221
186
|
}
|
|
222
187
|
sql.ref = (...keys) => raw('??', [keys.join('.')]);
|
|
223
188
|
sql.now = (length) => raw('current_timestamp' + (length == null ? '' : `(${length})`));
|
|
@@ -231,7 +196,7 @@ sql.upper = (key) => createSqlFunction('upper', key);
|
|
|
231
196
|
* ```ts
|
|
232
197
|
* // On postgres, will produce: create index "index custom_idx_on_name" on "library.author" ("name")
|
|
233
198
|
* // On mysql, will produce: create index `index custom_idx_on_name` on `library.author` (`name`)
|
|
234
|
-
* @Index({ name: 'custom_idx_on_name', expression: (table, columns) => quote`create index ${
|
|
199
|
+
* @Index({ name: 'custom_idx_on_name', expression: (table, columns, indexName) => quote`create index ${indexName} on ${table} (${columns.name})` })
|
|
235
200
|
* @Entity({ schema: 'library' })
|
|
236
201
|
* export class Author { ... }
|
|
237
202
|
* ```
|
package/utils/RequestContext.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAsyncContext } from './AsyncContext.js';
|
|
2
2
|
/**
|
|
3
3
|
* Uses `AsyncLocalStorage` to create async context that holds the current EM fork.
|
|
4
4
|
*/
|
|
5
5
|
export class RequestContext {
|
|
6
6
|
map;
|
|
7
|
-
static storage =
|
|
7
|
+
static storage = createAsyncContext();
|
|
8
8
|
static counter = 1;
|
|
9
9
|
id = RequestContext.counter++;
|
|
10
10
|
constructor(map) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAsyncContext } from './AsyncContext.js';
|
|
2
2
|
export class TransactionContext {
|
|
3
3
|
em;
|
|
4
|
-
static storage =
|
|
4
|
+
static storage = createAsyncContext();
|
|
5
5
|
id;
|
|
6
6
|
constructor(em) {
|
|
7
7
|
this.em = em;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransactionPropagation } from '../enums.js';
|
|
1
|
+
import { ReferenceKind, TransactionPropagation } from '../enums.js';
|
|
2
2
|
import { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
|
|
3
3
|
import { TransactionContext } from '../utils/TransactionContext.js';
|
|
4
4
|
import { ChangeSetType } from '../unit-of-work/ChangeSet.js';
|
|
@@ -17,9 +17,7 @@ export class TransactionManager {
|
|
|
17
17
|
*/
|
|
18
18
|
async handle(cb, options = {}) {
|
|
19
19
|
const em = this.em.getContext(false);
|
|
20
|
-
// Set NESTED as the default propagation type
|
|
21
20
|
options.propagation ??= TransactionPropagation.NESTED;
|
|
22
|
-
// Set the context to the current transaction context if not already set
|
|
23
21
|
options.ctx ??= em.getTransactionContext();
|
|
24
22
|
const hasExistingTransaction = !!em.getTransactionContext();
|
|
25
23
|
return this.executeWithPropagation(options.propagation, em, cb, options, hasExistingTransaction);
|
|
@@ -162,12 +160,16 @@ export class TransactionManager {
|
|
|
162
160
|
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
163
161
|
const wrapped = helper(entity);
|
|
164
162
|
const meta = wrapped.__meta;
|
|
165
|
-
|
|
166
|
-
const parentEntity = parentUoW.getById(meta.className, wrapped.getPrimaryKey(), parent['_schema'], true);
|
|
163
|
+
const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent.schema, true);
|
|
167
164
|
if (parentEntity && parentEntity !== entity) {
|
|
168
165
|
const parentWrapped = helper(parentEntity);
|
|
169
|
-
parentWrapped.__data =
|
|
170
|
-
parentWrapped.__originalEntityData =
|
|
166
|
+
parentWrapped.__data = wrapped.__data;
|
|
167
|
+
parentWrapped.__originalEntityData = wrapped.__originalEntityData;
|
|
168
|
+
for (const prop of meta.hydrateProps) {
|
|
169
|
+
if (prop.kind === ReferenceKind.SCALAR) {
|
|
170
|
+
parentEntity[prop.name] = entity[prop.name];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
171
173
|
}
|
|
172
174
|
else {
|
|
173
175
|
parentUoW.merge(entity, new Set([entity]));
|
|
@@ -180,7 +182,8 @@ export class TransactionManager {
|
|
|
180
182
|
registerDeletionHandler(fork, parent) {
|
|
181
183
|
fork.getEventManager().registerSubscriber({
|
|
182
184
|
afterFlush: (args) => {
|
|
183
|
-
const deletionChangeSets = args.uow
|
|
185
|
+
const deletionChangeSets = args.uow
|
|
186
|
+
.getChangeSets()
|
|
184
187
|
.filter(cs => cs.type === ChangeSetType.DELETE || cs.type === ChangeSetType.DELETE_EARLY);
|
|
185
188
|
for (const cs of deletionChangeSets) {
|
|
186
189
|
parent.getUnitOfWork(false).unsetIdentity(cs.entity);
|
package/utils/Utils.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, IMetadataStorage, Primary } from '../typings.js';
|
|
1
|
+
import type { CompiledFunctions, Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, Primary } from '../typings.js';
|
|
3
2
|
import type { Collection } from '../entity/Collection.js';
|
|
4
3
|
import type { Platform } from '../platforms/Platform.js';
|
|
5
|
-
import type
|
|
6
|
-
|
|
4
|
+
import { type ScalarReference } from '../entity/Reference.js';
|
|
5
|
+
import { type RawQueryFragmentSymbol } from './RawQueryFragment.js';
|
|
7
6
|
export declare function compareObjects(a: any, b: any): boolean;
|
|
8
7
|
export declare function compareArrays(a: any[] | string, b: any[] | string): boolean;
|
|
9
8
|
export declare function compareBooleans(a: unknown, b: unknown): boolean;
|
|
@@ -14,33 +13,16 @@ export declare function compareBuffers(a: Uint8Array, b: Uint8Array): boolean;
|
|
|
14
13
|
export declare function equals(a: any, b: any): boolean;
|
|
15
14
|
export declare function parseJsonSafe<T = unknown>(value: unknown): T;
|
|
16
15
|
export declare class Utils {
|
|
16
|
+
#private;
|
|
17
17
|
static readonly PK_SEPARATOR = "~~~";
|
|
18
|
-
/**
|
|
19
|
-
* Checks if the argument is not undefined
|
|
20
|
-
*/
|
|
21
|
-
static isDefined<T = Record<string, unknown>>(data: any): data is T;
|
|
22
18
|
/**
|
|
23
19
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
24
20
|
*/
|
|
25
21
|
static isObject<T = Dictionary>(o: any): o is T;
|
|
26
|
-
/**
|
|
27
|
-
* Relation decorators allow using two signatures
|
|
28
|
-
* - using first parameter as options object
|
|
29
|
-
* - using all parameters
|
|
30
|
-
*
|
|
31
|
-
* This function validates those two ways are not mixed and returns the final options object.
|
|
32
|
-
* If the second way is used, we always consider the last parameter as options object.
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
static processDecoratorParameters<T>(params: Dictionary): T;
|
|
36
|
-
/**
|
|
37
|
-
* Checks if the argument is instance of `Object`, but not one of the blacklisted types. Returns false for arrays.
|
|
38
|
-
*/
|
|
39
|
-
static isNotObject<T = Dictionary>(o: any, not: any[]): o is T;
|
|
40
22
|
/**
|
|
41
23
|
* Removes `undefined` properties (recursively) so they are not saved as nulls
|
|
42
24
|
*/
|
|
43
|
-
static dropUndefinedProperties
|
|
25
|
+
static dropUndefinedProperties(o: any, value?: null, visited?: Set<unknown>): void;
|
|
44
26
|
/**
|
|
45
27
|
* Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.
|
|
46
28
|
* @see https://github.com/deepkit/deepkit-framework/blob/master/packages/core/src/core.ts
|
|
@@ -51,14 +33,6 @@ export declare class Utils {
|
|
|
51
33
|
* @see https://github.com/deepkit/deepkit-framework/blob/master/packages/core/src/core.ts
|
|
52
34
|
*/
|
|
53
35
|
static hasObjectKeys(object: Dictionary): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Checks if the argument is string
|
|
56
|
-
*/
|
|
57
|
-
static isString(s: any): s is string;
|
|
58
|
-
/**
|
|
59
|
-
* Checks if the argument is number
|
|
60
|
-
*/
|
|
61
|
-
static isNumber<T = number>(s: any): s is T;
|
|
62
36
|
/**
|
|
63
37
|
* Checks if arguments are deeply (but not strictly) equal.
|
|
64
38
|
*/
|
|
@@ -79,11 +53,6 @@ export declare class Utils {
|
|
|
79
53
|
* Merges all sources into the target recursively.
|
|
80
54
|
*/
|
|
81
55
|
private static _merge;
|
|
82
|
-
static getRootEntity(metadata: IMetadataStorage, meta: EntityMetadata): EntityMetadata;
|
|
83
|
-
/**
|
|
84
|
-
* Computes difference between two objects, ignoring items missing in `b`.
|
|
85
|
-
*/
|
|
86
|
-
static diff(a: Dictionary, b: Dictionary): Record<keyof (typeof a & typeof b), any>;
|
|
87
56
|
/**
|
|
88
57
|
* Creates deep copy of given object.
|
|
89
58
|
*/
|
|
@@ -101,26 +70,11 @@ export declare class Utils {
|
|
|
101
70
|
*/
|
|
102
71
|
static renameKey<T>(payload: T, from: string | keyof T, to: string): void;
|
|
103
72
|
/**
|
|
104
|
-
* Returns array of functions argument names. Uses
|
|
105
|
-
*/
|
|
106
|
-
static tokenize(func: {
|
|
107
|
-
toString(): string;
|
|
108
|
-
} | string | {
|
|
109
|
-
type: string;
|
|
110
|
-
value: string;
|
|
111
|
-
}[]): {
|
|
112
|
-
type: string;
|
|
113
|
-
value: string;
|
|
114
|
-
}[];
|
|
115
|
-
/**
|
|
116
|
-
* Returns array of functions argument names. Uses `esprima` for source code analysis.
|
|
73
|
+
* Returns array of functions argument names. Uses basic regex for source code analysis, might not work with advanced syntax.
|
|
117
74
|
*/
|
|
118
|
-
static
|
|
75
|
+
static getConstructorParams(func: {
|
|
119
76
|
toString(): string;
|
|
120
|
-
}
|
|
121
|
-
type: string;
|
|
122
|
-
value: string;
|
|
123
|
-
}[], methodName?: string): string[];
|
|
77
|
+
}): string[] | undefined;
|
|
124
78
|
/**
|
|
125
79
|
* Checks whether the argument looks like primary key (string, number or ObjectId).
|
|
126
80
|
*/
|
|
@@ -133,7 +87,7 @@ export declare class Utils {
|
|
|
133
87
|
static getCompositeKeyHash<T>(data: EntityData<T>, meta: EntityMetadata<T>, convertCustomTypes?: boolean, platform?: Platform, flat?: boolean): string;
|
|
134
88
|
static getPrimaryKeyHash(pks: (string | Buffer | Date)[]): string;
|
|
135
89
|
static splitPrimaryKeys<T extends object>(key: string): EntityKey<T>[];
|
|
136
|
-
static getPrimaryKeyValues<T>(entity: T,
|
|
90
|
+
static getPrimaryKeyValues<T>(entity: T, meta: EntityMetadata<T>, allowScalar?: boolean, convertCustomTypes?: boolean): any;
|
|
137
91
|
static getPrimaryKeyCond<T>(entity: T, primaryKeys: EntityKey<T>[]): Record<string, Primary<T>> | null;
|
|
138
92
|
/**
|
|
139
93
|
* Maps nested FKs from `[1, 2, 3]` to `[1, [2, 3]]`.
|
|
@@ -149,12 +103,6 @@ export declare class Utils {
|
|
|
149
103
|
* Checks whether given object is a scalar reference.
|
|
150
104
|
*/
|
|
151
105
|
static isScalarReference<T = unknown>(data: any, allowReference?: boolean): data is ScalarReference<any> & {};
|
|
152
|
-
/**
|
|
153
|
-
* Checks whether the argument is ObjectId instance
|
|
154
|
-
*/
|
|
155
|
-
static isObjectID(key: any): key is {
|
|
156
|
-
toHexString: () => string;
|
|
157
|
-
};
|
|
158
106
|
/**
|
|
159
107
|
* Checks whether the argument is empty (array without items, object without keys or falsy value).
|
|
160
108
|
*/
|
|
@@ -162,17 +110,12 @@ export declare class Utils {
|
|
|
162
110
|
/**
|
|
163
111
|
* Gets string name of given class.
|
|
164
112
|
*/
|
|
165
|
-
static className<T>(classOrName: EntityName<T>): string;
|
|
113
|
+
static className<T>(classOrName: string | EntityName<T>): string;
|
|
166
114
|
static extractChildElements(items: string[], prefix: string, allSymbol?: string): string[];
|
|
167
115
|
/**
|
|
168
116
|
* Tries to detect TypeScript support.
|
|
169
117
|
*/
|
|
170
118
|
static detectTypeScriptSupport(): boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Uses some dark magic to get source path to caller where decorator is used.
|
|
173
|
-
* Analyses stack trace of error created inside the function call.
|
|
174
|
-
*/
|
|
175
|
-
static lookupPathFromDecorator(name: string, stack?: string[]): string;
|
|
176
119
|
/**
|
|
177
120
|
* Gets the type of the argument.
|
|
178
121
|
*/
|
|
@@ -186,86 +129,32 @@ export declare class Utils {
|
|
|
186
129
|
*/
|
|
187
130
|
static runSerial<T = any, U = any>(items: Iterable<U>, cb: (item: U) => Promise<T>): Promise<T[]>;
|
|
188
131
|
static isCollection<T extends object, O extends object = object>(item: any): item is Collection<T, O>;
|
|
189
|
-
static
|
|
190
|
-
/**
|
|
191
|
-
* Resolves and normalizes a series of path parts relative to each preceding part.
|
|
192
|
-
* If any part is a `file:` URL, it is converted to a local path. If any part is an
|
|
193
|
-
* absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
|
|
194
|
-
* Trailing directory separators are removed, and all directory separators are converted
|
|
195
|
-
* to POSIX-style separators (`/`).
|
|
196
|
-
*/
|
|
197
|
-
static normalizePath(...parts: string[]): string;
|
|
198
|
-
/**
|
|
199
|
-
* Determines the relative path between two paths. If either path is a `file:` URL,
|
|
200
|
-
* it is converted to a local path.
|
|
201
|
-
*/
|
|
202
|
-
static relativePath(path: string, relativeTo: string): string;
|
|
203
|
-
/**
|
|
204
|
-
* Computes the absolute path to for the given path relative to the provided base directory.
|
|
205
|
-
* If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
|
|
206
|
-
*/
|
|
207
|
-
static absolutePath(path: string, baseDir?: string): string;
|
|
208
|
-
static hash(data: string, length?: number, algorithm?: 'md5' | 'sha256'): string;
|
|
132
|
+
static hash(data: string, length?: number): string;
|
|
209
133
|
static runIfNotEmpty(clause: () => any, data: any): void;
|
|
210
134
|
static defaultValue<T extends Dictionary>(prop: T, option: keyof T, defaultValue: any): void;
|
|
211
135
|
static findDuplicates<T>(items: T[]): T[];
|
|
212
136
|
static removeDuplicates<T>(items: T[]): T[];
|
|
213
137
|
static randomInt(min: number, max: number): number;
|
|
214
|
-
static pathExists(path: string, options?: GlobOptions): Promise<boolean>;
|
|
215
138
|
/**
|
|
216
139
|
* Extracts all possible values of a TS enum. Works with both string and numeric enums.
|
|
217
140
|
*/
|
|
218
141
|
static extractEnumValues(target: Dictionary): (string | number)[];
|
|
219
|
-
static flatten<T>(arrays: T[][]): T[];
|
|
142
|
+
static flatten<T>(arrays: T[][], deep?: boolean): T[];
|
|
220
143
|
static isOperator(key: PropertyKey, includeGroupOperators?: boolean): boolean;
|
|
221
|
-
static isGroupOperator(key: PropertyKey): boolean;
|
|
222
|
-
static isArrayOperator(key: PropertyKey): boolean;
|
|
223
|
-
static isJsonKeyOperator(key: PropertyKey): boolean;
|
|
224
144
|
static hasNestedKey(object: unknown, key: string): boolean;
|
|
225
|
-
static getGlobalStorage(namespace: string): Dictionary;
|
|
226
|
-
/**
|
|
227
|
-
* Require a module from a specific location
|
|
228
|
-
* @param id The module to require
|
|
229
|
-
* @param [from] Location to start the node resolution
|
|
230
|
-
*/
|
|
231
|
-
static requireFrom<T extends Dictionary>(id: string, from?: string): T;
|
|
232
|
-
/**
|
|
233
|
-
* Resolve path to a module.
|
|
234
|
-
* @param id The module to require
|
|
235
|
-
* @param [from] Location to start the node resolution
|
|
236
|
-
*/
|
|
237
|
-
static resolveModulePath(id: string, from?: string): string;
|
|
238
|
-
static dynamicImport<T = any>(id: string): Promise<T>;
|
|
239
|
-
static ensureDir(path: string): void;
|
|
240
|
-
static pathExistsSync(path: string): boolean;
|
|
241
|
-
static readJSONSync(path: string): Dictionary;
|
|
242
145
|
static getORMVersion(): string;
|
|
243
|
-
static createFunction(context: Map<string, any>, code: string): any;
|
|
146
|
+
static createFunction(context: Map<string, any>, code: string, compiledFunctions?: CompiledFunctions, key?: string): any;
|
|
244
147
|
static callCompiledFunction<T extends unknown[], R>(fn: (...args: T) => R, ...args: T): R;
|
|
245
|
-
/**
|
|
246
|
-
* @see https://github.com/mikro-orm/mikro-orm/issues/840
|
|
247
|
-
*/
|
|
248
|
-
static propertyDecoratorReturnValue(): any;
|
|
249
148
|
static unwrapProperty<T>(entity: T, meta: EntityMetadata<T>, prop: EntityProperty<T>, payload?: boolean): [unknown, number[]][];
|
|
250
149
|
static setPayloadProperty<T>(entity: EntityDictionary<T>, meta: EntityMetadata<T>, prop: EntityProperty<T>, value: unknown, idx: number[]): void;
|
|
251
|
-
static
|
|
252
|
-
module: string;
|
|
253
|
-
warning: string;
|
|
254
|
-
from?: string;
|
|
255
|
-
allowError?: string;
|
|
256
|
-
}): T | undefined;
|
|
257
|
-
static tryImport<T extends Dictionary = any>({ module, warning }: {
|
|
150
|
+
static tryImport<T extends Dictionary = any>({ module, warning, }: {
|
|
258
151
|
module: string;
|
|
259
|
-
warning
|
|
152
|
+
warning?: string;
|
|
260
153
|
}): Promise<T | undefined>;
|
|
261
|
-
static stripRelativePath(str: string): string;
|
|
262
|
-
/**
|
|
263
|
-
* simple process.argv parser, supports only properties with long names, prefixed with `--`
|
|
264
|
-
*/
|
|
265
|
-
static parseArgs<T extends Dictionary = Dictionary>(): T;
|
|
266
154
|
static xor(a: boolean, b: boolean): boolean;
|
|
267
155
|
static keys<T extends object>(obj: T): (keyof T)[];
|
|
268
156
|
static values<T extends object>(obj: T): T[keyof T][];
|
|
269
157
|
static entries<T extends object>(obj: T): [keyof T, T[keyof T]][];
|
|
270
158
|
static primaryKeyToObject<T>(meta: EntityMetadata<T>, primaryKey: Primary<T> | T, visible?: (keyof T)[]): T;
|
|
159
|
+
static getObjectQueryKeys<T extends Dictionary, K extends string = Extract<keyof T, string>>(obj: T): (K | RawQueryFragmentSymbol)[];
|
|
271
160
|
}
|