@mikro-orm/core 6.2.10-dev.7 → 6.2.10-dev.71
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 +1 -2
- package/EntityManager.js +26 -24
- package/decorators/Check.js +1 -2
- package/decorators/CreateRequestContext.js +2 -3
- package/decorators/Embeddable.js +1 -2
- package/decorators/Embedded.js +1 -2
- package/decorators/Entity.js +1 -2
- package/decorators/Enum.js +1 -2
- package/decorators/Filter.js +1 -2
- package/decorators/Formula.js +1 -2
- package/decorators/Indexed.d.ts +3 -3
- package/decorators/Indexed.js +2 -3
- package/decorators/ManyToMany.js +1 -2
- package/decorators/ManyToOne.js +1 -2
- package/decorators/OneToMany.js +2 -3
- package/decorators/OneToOne.d.ts +1 -1
- package/decorators/OneToOne.js +1 -2
- package/decorators/PrimaryKey.d.ts +3 -2
- package/decorators/PrimaryKey.js +2 -3
- package/decorators/Property.js +1 -2
- package/decorators/hooks.js +10 -11
- package/drivers/DatabaseDriver.js +1 -1
- package/drivers/IDatabaseDriver.d.ts +2 -1
- package/entity/ArrayCollection.d.ts +0 -1
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityLoader.js +3 -0
- package/entity/Reference.d.ts +0 -1
- package/entity/Reference.js +10 -7
- package/entity/WrappedEntity.d.ts +0 -1
- package/entity/wrap.js +2 -3
- package/events/TransactionEventBroadcaster.d.ts +2 -2
- package/metadata/MetadataDiscovery.js +4 -3
- package/naming-strategy/AbstractNamingStrategy.d.ts +8 -0
- package/naming-strategy/AbstractNamingStrategy.js +12 -0
- package/naming-strategy/NamingStrategy.d.ts +21 -0
- package/package.json +2 -2
- package/platforms/Platform.d.ts +0 -1
- package/platforms/Platform.js +0 -3
- package/serialization/EntitySerializer.js +2 -2
- package/types/BigIntType.d.ts +2 -2
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/DecimalType.d.ts +2 -2
- package/types/Type.d.ts +1 -2
- package/types/Uint8ArrayType.d.ts +0 -1
- package/typings.d.ts +14 -14
- package/unit-of-work/ChangeSet.d.ts +0 -1
- package/unit-of-work/ChangeSetPersister.d.ts +1 -1
- package/unit-of-work/ChangeSetPersister.js +5 -3
- package/unit-of-work/UnitOfWork.d.ts +1 -1
- package/unit-of-work/UnitOfWork.js +32 -18
- package/utils/Configuration.js +2 -2
- package/utils/ConfigurationLoader.js +1 -0
- package/utils/Cursor.d.ts +0 -1
- package/utils/DataloaderUtils.d.ts +3 -3
- package/utils/DataloaderUtils.js +4 -4
- package/utils/EntityComparator.d.ts +13 -0
- package/utils/EntityComparator.js +62 -34
- package/utils/RawQueryFragment.d.ts +1 -2
- package/utils/RawQueryFragment.js +4 -4
- package/utils/Utils.d.ts +4 -6
- package/utils/Utils.js +13 -10
- package/utils/clone.js +1 -2
- package/utils/upsert-utils.d.ts +3 -2
- package/utils/upsert-utils.js +4 -5
|
@@ -8,6 +8,14 @@ export declare abstract class AbstractNamingStrategy implements NamingStrategy {
|
|
|
8
8
|
*/
|
|
9
9
|
getEntityName(tableName: string, schemaName?: string): string;
|
|
10
10
|
columnNameToProperty(columnName: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
getEnumClassName(columnName: string, tableName: string, schemaName?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
|
|
11
19
|
aliasName(entityName: string, index: number): string;
|
|
12
20
|
abstract classToTableName(entityName: string): string;
|
|
13
21
|
abstract joinColumnName(propertyName: string): string;
|
|
@@ -47,6 +47,18 @@ class AbstractNamingStrategy {
|
|
|
47
47
|
}
|
|
48
48
|
return propName;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* @inheritDoc
|
|
52
|
+
*/
|
|
53
|
+
getEnumClassName(columnName, tableName, schemaName) {
|
|
54
|
+
return this.getEntityName(`${tableName}_${columnName}`, schemaName);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
59
|
+
enumValueToEnumProperty(enumValue, columnName, tableName, schemaName) {
|
|
60
|
+
return enumValue.toUpperCase();
|
|
61
|
+
}
|
|
50
62
|
aliasName(entityName, index) {
|
|
51
63
|
// Take only the first letter of the prefix to keep character counts down since some engines have character limits
|
|
52
64
|
return entityName.charAt(0).toLowerCase() + index;
|
|
@@ -15,6 +15,27 @@ export interface NamingStrategy {
|
|
|
15
15
|
* Return a column name for a property
|
|
16
16
|
*/
|
|
17
17
|
propertyToColumnName(propertyName: string, object?: boolean): string;
|
|
18
|
+
/**
|
|
19
|
+
* Get an enum class name.
|
|
20
|
+
*
|
|
21
|
+
* @param columnName The column name which has the enum.
|
|
22
|
+
* @param tableName The table name of the column.
|
|
23
|
+
* @param schemaName The schema name of the column.
|
|
24
|
+
*
|
|
25
|
+
* @return A new class name that will be used for the enum.
|
|
26
|
+
*/
|
|
27
|
+
getEnumClassName(columnName: string, tableName: string, schemaName?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get an enum option name for a given enum value.
|
|
30
|
+
*
|
|
31
|
+
* @param enumValue The enum value to generate a name for.
|
|
32
|
+
* @param columnName The column name which has the enum.
|
|
33
|
+
* @param tableName The table name of the column.
|
|
34
|
+
* @param schemaName The schema name of the column.
|
|
35
|
+
*
|
|
36
|
+
* @return The name of the enum property that will hold the value.
|
|
37
|
+
*/
|
|
38
|
+
enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
|
|
18
39
|
/**
|
|
19
40
|
* Return a name of the entity class based on database table name (used in `EntityGenerator`).
|
|
20
41
|
* Default implementation ignores the schema name.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.2.10-dev.
|
|
3
|
+
"version": "6.2.10-dev.71",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.2.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.2.10-dev.
|
|
67
|
+
"mikro-orm": "6.2.10-dev.71",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -69,7 +69,6 @@ export declare abstract class Platform {
|
|
|
69
69
|
quoteVersionValue(value: Date | number, prop: EntityProperty): Date | string | number;
|
|
70
70
|
getDefaultVersionLength(): number;
|
|
71
71
|
allowsComparingTuples(): boolean;
|
|
72
|
-
allowsUniqueBatchUpdates(): boolean;
|
|
73
72
|
isBigIntProperty(prop: EntityProperty): boolean;
|
|
74
73
|
isRaw(value: any): boolean;
|
|
75
74
|
getDefaultSchemaName(): string | undefined;
|
package/platforms/Platform.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EntitySerializer = void 0;
|
|
4
|
+
exports.serialize = serialize;
|
|
4
5
|
const wrap_1 = require("../entity/wrap");
|
|
5
6
|
const Utils_1 = require("../utils/Utils");
|
|
6
7
|
const enums_1 = require("../enums");
|
|
@@ -210,4 +211,3 @@ function serialize(entities, options) {
|
|
|
210
211
|
}
|
|
211
212
|
return EntitySerializer.serialize(entities, options);
|
|
212
213
|
}
|
|
213
|
-
exports.serialize = serialize;
|
package/types/BigIntType.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import type { EntityProperty } from '../typings';
|
|
|
6
6
|
* or numbers (safe only for values up to `Number.MAX_SAFE_INTEGER`), or strings, depending on the `mode`.
|
|
7
7
|
*/
|
|
8
8
|
export declare class BigIntType extends Type<string | bigint | number | null | undefined, string | null | undefined> {
|
|
9
|
-
mode?: "
|
|
10
|
-
constructor(mode?: "
|
|
9
|
+
mode?: ("bigint" | "number" | "string") | undefined;
|
|
10
|
+
constructor(mode?: ("bigint" | "number" | "string") | undefined);
|
|
11
11
|
convertToDatabaseValue(value: string | bigint | null | undefined): string | null | undefined;
|
|
12
12
|
convertToJSValue(value: string | bigint | null | undefined): bigint | number | string | null | undefined;
|
|
13
13
|
toJSON(value: string | bigint | null | undefined): string | bigint | null | undefined;
|
package/types/BigIntType.js
CHANGED
package/types/BlobType.d.ts
CHANGED
package/types/DecimalType.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { EntityProperty } from '../typings';
|
|
|
5
5
|
* Type that maps an SQL DECIMAL to a JS string or number.
|
|
6
6
|
*/
|
|
7
7
|
export declare class DecimalType extends Type<string | number, string> {
|
|
8
|
-
mode?: "
|
|
9
|
-
constructor(mode?: "
|
|
8
|
+
mode?: ("number" | "string") | undefined;
|
|
9
|
+
constructor(mode?: ("number" | "string") | undefined);
|
|
10
10
|
convertToJSValue(value: string): number | string;
|
|
11
11
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
12
12
|
compareAsType(): string;
|
package/types/Type.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { inspect } from 'util';
|
|
3
2
|
import type { Platform } from '../platforms';
|
|
4
3
|
import type { Constructor, EntityMetadata, EntityProperty } from '../typings';
|
|
@@ -59,7 +58,7 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
|
|
|
59
58
|
* Gets the SQL declaration snippet for a field of this type.
|
|
60
59
|
*/
|
|
61
60
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
62
|
-
static getType<JSType, DBType = JSType
|
|
61
|
+
static getType<JSType, DBType = JSType, TypeClass extends Constructor<Type<JSType, DBType>> = Constructor<Type<JSType, DBType>>>(cls: TypeClass): InstanceType<TypeClass>;
|
|
63
62
|
/**
|
|
64
63
|
* Checks whether the argument is instance of `Type`.
|
|
65
64
|
*/
|
package/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transaction } from './connections';
|
|
2
|
-
import { type
|
|
2
|
+
import { type Cascade, type DeferMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums';
|
|
3
3
|
import { type AssignOptions, type Collection, type EntityFactory, type EntityIdentifier, type EntityLoaderOptions, type EntityRepository, Reference, type ScalarReference } from './entity';
|
|
4
4
|
import type { SerializationContext, SerializeOptions } from './serialization';
|
|
5
5
|
import type { EntitySchema, MetadataStorage } from './metadata';
|
|
@@ -223,7 +223,7 @@ type ExplicitlyOptionalProps<T> = (T extends {
|
|
|
223
223
|
type NullableKeys<T, V = null> = {
|
|
224
224
|
[K in keyof T]: V extends T[K] ? K : never;
|
|
225
225
|
}[keyof T];
|
|
226
|
-
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> |
|
|
226
|
+
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | NonNullable<NullableKeys<T>>;
|
|
227
227
|
type IsOptional<T, K extends keyof T, I> = T[K] extends Collection<any, any> ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
|
|
228
228
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
229
229
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
@@ -271,7 +271,7 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
|
|
|
271
271
|
export type EntityDTOProp<E, T, C extends TypeConfig = never> = T extends Scalar ? T : T extends {
|
|
272
272
|
__serialized?: infer U;
|
|
273
273
|
} ? U : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollection<infer U> ? EntityDTO<U, C>[] : T extends Collection<infer U> ? PrimaryOrObject<E, U, C>[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation<T> ? EntityDTO<T, C> : T;
|
|
274
|
-
type DTOProbablyOptionalProps<T> =
|
|
274
|
+
type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<T, undefined>>;
|
|
275
275
|
type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollection<any> ? false : K extends PrimaryProperty<T> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
|
|
276
276
|
type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
|
|
277
277
|
type DTOOptionalKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
|
|
@@ -537,6 +537,7 @@ export interface GenerateOptions {
|
|
|
537
537
|
readOnlyPivotTables?: boolean;
|
|
538
538
|
customBaseEntityName?: string;
|
|
539
539
|
useCoreBaseEntity?: boolean;
|
|
540
|
+
coreImportsPrefix?: string;
|
|
540
541
|
onInitialMetadata?: MetadataProcessor;
|
|
541
542
|
onProcessedMetadata?: MetadataProcessor;
|
|
542
543
|
}
|
|
@@ -668,7 +669,7 @@ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
668
669
|
type CollectionKeys<T> = T extends object ? {
|
|
669
670
|
[K in keyof T]: T[K] extends Collection<any> ? IsAny<T[K]> extends true ? never : K & string : never;
|
|
670
671
|
}[keyof T] & {} : never;
|
|
671
|
-
export type AutoPath<O, P extends string | boolean, E extends string = never, D extends Prev[number] = 9> = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ? (P & `${string}.` extends never ? P : P & `${string}.`) extends infer Q ? Q extends `${infer A}.${infer B}` ? A extends StringKeys<O, E> ? `${A}.${AutoPath<
|
|
672
|
+
export type AutoPath<O, P extends string | boolean, E extends string = never, D extends Prev[number] = 9> = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ? (P & `${string}.` extends never ? P : P & `${string}.`) extends infer Q ? Q extends `${infer A}.${infer B}` ? A extends StringKeys<O, E> ? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}` : never : Q extends StringKeys<O, E> ? (NonNullable<GetStringKey<O, Q, E>> extends unknown ? Exclude<P, `${string}.`> : never) | (StringKeys<NonNullable<GetStringKey<O, Q, E>>, E> extends never ? never : `${Q & string}.`) : StringKeys<O, E> | `${CollectionKeys<O>}:ref` : never : never : never;
|
|
672
673
|
export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
|
|
673
674
|
export type ArrayElement<ArrayType extends unknown[]> = ArrayType extends (infer ElementType)[] ? ElementType : never;
|
|
674
675
|
export type ExpandProperty<T> = T extends Reference<infer U> ? NonNullable<U> : T extends Collection<infer U, any> ? NonNullable<U> : T extends (infer U)[] ? NonNullable<U> : NonNullable<T>;
|
|
@@ -679,7 +680,6 @@ type Prefix<T, K> = K extends `${infer S}.${string}` ? S : (K extends '*' ? keyo
|
|
|
679
680
|
type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
|
|
680
681
|
export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> = IsNever<E> extends false ? IsPrefixedExclude<T, K, E> : K extends symbol ? never : IsTrue<L> extends true ? (T[K] & {} extends Loadable<any> ? K : never) : IsNever<StringLiteral<L>> extends true ? never : K extends Prefix<T, L> ? K : K extends PrimaryProperty<T> ? K : never;
|
|
681
682
|
type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? (Pref extends Key ? Suf : never) : Hint extends All ? Hint : never;
|
|
682
|
-
type Defined<T> = T & {};
|
|
683
683
|
export type IsSubset<T, U> = keyof U extends keyof T ? {} : Dictionary extends U ? {} : {
|
|
684
684
|
[K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
|
|
685
685
|
};
|
|
@@ -695,7 +695,7 @@ type LoadedProp<T, L extends string = never, F extends string = '*', E extends s
|
|
|
695
695
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
696
696
|
export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
697
697
|
export type Selected<T, L extends string = never, F extends string = '*'> = {
|
|
698
|
-
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>>]: LoadedProp<
|
|
698
|
+
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
699
699
|
} & {
|
|
700
700
|
[K in keyof T as FunctionKeys<T, K>]: T[K];
|
|
701
701
|
} & {
|
|
@@ -711,9 +711,9 @@ export type FromEntityType<T> = T extends LoadedEntityType<infer U> ? U : T;
|
|
|
711
711
|
type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [
|
|
712
712
|
F
|
|
713
713
|
] extends ['*'] ? IsNever<E> extends true ? T & {
|
|
714
|
-
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>>]: LoadedProp<
|
|
714
|
+
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>> | AddOptional<T[K]>;
|
|
715
715
|
} : {
|
|
716
|
-
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>, E>]: LoadedProp<
|
|
716
|
+
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>, E>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>> | AddOptional<T[K]>;
|
|
717
717
|
} : Selected<T, L, F>;
|
|
718
718
|
/**
|
|
719
719
|
* Represents entity with its loaded relations (`populate` hint) and selected properties (`fields` hint).
|
|
@@ -721,13 +721,13 @@ type LoadedInternal<T, L extends string = never, F extends string = '*', E exten
|
|
|
721
721
|
export type Loaded<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedInternal<T, L, F, E> & {
|
|
722
722
|
[__loadedType]?: T;
|
|
723
723
|
};
|
|
724
|
-
export interface LoadedReference<T> extends Reference<
|
|
725
|
-
$:
|
|
726
|
-
get():
|
|
724
|
+
export interface LoadedReference<T> extends Reference<NonNullable<T>> {
|
|
725
|
+
$: NonNullable<T>;
|
|
726
|
+
get(): NonNullable<T>;
|
|
727
727
|
}
|
|
728
|
-
export interface LoadedScalarReference<T> extends ScalarReference<
|
|
729
|
-
$:
|
|
730
|
-
get():
|
|
728
|
+
export interface LoadedScalarReference<T> extends ScalarReference<T> {
|
|
729
|
+
$: T;
|
|
730
|
+
get(): T;
|
|
731
731
|
}
|
|
732
732
|
export interface LoadedCollection<T extends object> extends Collection<T> {
|
|
733
733
|
$: Collection<T>;
|
|
@@ -47,5 +47,5 @@ export declare class ChangeSetPersister {
|
|
|
47
47
|
* No need to handle composite keys here as they need to be set upfront.
|
|
48
48
|
* We do need to map to the change set payload too, as it will be used in the originalEntityData for new entities.
|
|
49
49
|
*/
|
|
50
|
-
mapReturnedValues<T extends object>(entity: T, payload: EntityDictionary<T>, row: Dictionary | undefined, meta: EntityMetadata<T
|
|
50
|
+
mapReturnedValues<T extends object>(entity: T | null | undefined, payload: EntityDictionary<T>, row: Dictionary | undefined, meta: EntityMetadata<T>, upsert?: boolean): void;
|
|
51
51
|
}
|
|
@@ -351,10 +351,12 @@ class ChangeSetPersister {
|
|
|
351
351
|
* No need to handle composite keys here as they need to be set upfront.
|
|
352
352
|
* We do need to map to the change set payload too, as it will be used in the originalEntityData for new entities.
|
|
353
353
|
*/
|
|
354
|
-
mapReturnedValues(entity, payload, row, meta) {
|
|
355
|
-
if (this.usesReturningStatement && row && utils_1.Utils.hasObjectKeys(row)) {
|
|
354
|
+
mapReturnedValues(entity, payload, row, meta, upsert = false) {
|
|
355
|
+
if ((this.usesReturningStatement || upsert) && row && utils_1.Utils.hasObjectKeys(row)) {
|
|
356
356
|
const mapped = this.comparator.mapResult(meta.className, row);
|
|
357
|
-
|
|
357
|
+
if (entity) {
|
|
358
|
+
this.hydrator.hydrate(entity, meta, mapped, this.factory, 'full', false, true);
|
|
359
|
+
}
|
|
358
360
|
Object.assign(payload, mapped); // merge to the changeset payload, so it gets saved to the entity snapshot
|
|
359
361
|
}
|
|
360
362
|
}
|
|
@@ -52,7 +52,7 @@ export declare class UnitOfWork {
|
|
|
52
52
|
getRemoveStack(): Set<AnyEntity>;
|
|
53
53
|
getChangeSets(): ChangeSet<AnyEntity>[];
|
|
54
54
|
getCollectionUpdates(): Collection<AnyEntity>[];
|
|
55
|
-
getExtraUpdates(): Set<[AnyEntity, string | string[], (AnyEntity | AnyEntity[] | Reference<any> | Collection<any>), ChangeSet<any> | undefined]>;
|
|
55
|
+
getExtraUpdates(): Set<[AnyEntity, string | string[], (AnyEntity | AnyEntity[] | Reference<any> | Collection<any>), ChangeSet<any> | undefined, ChangeSetType]>;
|
|
56
56
|
shouldAutoFlush<T extends object>(meta: EntityMetadata<T>): boolean;
|
|
57
57
|
clearActionsQueue(): void;
|
|
58
58
|
computeChangeSet<T extends object>(entity: T, type?: ChangeSetType): void;
|
|
@@ -423,15 +423,24 @@ class UnitOfWork {
|
|
|
423
423
|
return;
|
|
424
424
|
}
|
|
425
425
|
let conflicts = false;
|
|
426
|
+
let type = ChangeSet_1.ChangeSetType.UPDATE;
|
|
427
|
+
if (!props.some(prop => prop.name in changeSet.payload)) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
426
430
|
for (const cs of this.changeSets.values()) {
|
|
427
|
-
|
|
428
|
-
|
|
431
|
+
for (const prop of props) {
|
|
432
|
+
if (prop.name in cs.payload && cs.rootName === changeSet.rootName && cs.type === changeSet.type) {
|
|
433
|
+
conflicts = true;
|
|
434
|
+
if (changeSet.payload[prop.name] == null) {
|
|
435
|
+
type = ChangeSet_1.ChangeSetType.UPDATE_EARLY;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
429
438
|
}
|
|
430
439
|
}
|
|
431
440
|
if (!conflicts) {
|
|
432
441
|
return;
|
|
433
442
|
}
|
|
434
|
-
this.extraUpdates.add([changeSet.entity, props.map(p => p.name), props.map(p => changeSet.entity[p.name]), changeSet]);
|
|
443
|
+
this.extraUpdates.add([changeSet.entity, props.map(p => p.name), props.map(p => changeSet.entity[p.name]), changeSet, type]);
|
|
435
444
|
for (const p of props) {
|
|
436
445
|
delete changeSet.entity[p.name];
|
|
437
446
|
delete changeSet.payload[p.name];
|
|
@@ -483,13 +492,13 @@ class UnitOfWork {
|
|
|
483
492
|
* Returns `true` when the change set should be skipped as it will be empty after the extra update.
|
|
484
493
|
*/
|
|
485
494
|
checkUniqueProps(changeSet) {
|
|
486
|
-
if (
|
|
495
|
+
if (changeSet.type !== ChangeSet_1.ChangeSetType.UPDATE) {
|
|
487
496
|
return false;
|
|
488
497
|
}
|
|
489
|
-
// when changing a unique nullable property (or a 1:1 relation), we can't do it in a single
|
|
498
|
+
// when changing a unique nullable property (or a 1:1 relation), we can't do it in a single
|
|
499
|
+
// query as it would cause unique constraint violations
|
|
490
500
|
const uniqueProps = changeSet.meta.uniqueProps.filter(prop => {
|
|
491
|
-
return (prop.nullable || changeSet.type !== ChangeSet_1.ChangeSetType.CREATE)
|
|
492
|
-
&& changeSet.payload[prop.name] != null;
|
|
501
|
+
return (prop.nullable || changeSet.type !== ChangeSet_1.ChangeSetType.CREATE);
|
|
493
502
|
});
|
|
494
503
|
this.scheduleExtraUpdate(changeSet, uniqueProps);
|
|
495
504
|
return changeSet.type === ChangeSet_1.ChangeSetType.UPDATE && !Utils_1.Utils.hasObjectKeys(changeSet.payload);
|
|
@@ -558,7 +567,7 @@ class UnitOfWork {
|
|
|
558
567
|
}
|
|
559
568
|
processToManyReference(collection, visited, processed, parent, prop) {
|
|
560
569
|
if (this.isCollectionSelfReferenced(collection, processed)) {
|
|
561
|
-
this.extraUpdates.add([parent, prop.name, collection, undefined]);
|
|
570
|
+
this.extraUpdates.add([parent, prop.name, collection, undefined, ChangeSet_1.ChangeSetType.UPDATE]);
|
|
562
571
|
const coll = new entity_1.Collection(parent);
|
|
563
572
|
coll.property = prop;
|
|
564
573
|
parent[prop.name] = coll;
|
|
@@ -710,31 +719,33 @@ class UnitOfWork {
|
|
|
710
719
|
}
|
|
711
720
|
const commitOrder = this.getCommitOrder();
|
|
712
721
|
const commitOrderReversed = [...commitOrder].reverse();
|
|
713
|
-
//
|
|
722
|
+
// early delete - when we recreate entity in the same UoW, we need to issue those delete queries before inserts
|
|
714
723
|
for (const name of commitOrderReversed) {
|
|
715
724
|
await this.commitDeleteChangeSets(groups[ChangeSet_1.ChangeSetType.DELETE_EARLY].get(name) ?? [], ctx);
|
|
716
725
|
}
|
|
717
|
-
//
|
|
726
|
+
// early update - when we recreate entity in the same UoW, we need to issue those delete queries before inserts
|
|
718
727
|
for (const name of commitOrder) {
|
|
719
728
|
await this.commitUpdateChangeSets(groups[ChangeSet_1.ChangeSetType.UPDATE_EARLY].get(name) ?? [], ctx);
|
|
720
729
|
}
|
|
721
|
-
//
|
|
730
|
+
// extra updates
|
|
731
|
+
await this.commitExtraUpdates(ChangeSet_1.ChangeSetType.UPDATE_EARLY, ctx);
|
|
732
|
+
// create
|
|
722
733
|
for (const name of commitOrder) {
|
|
723
734
|
await this.commitCreateChangeSets(groups[ChangeSet_1.ChangeSetType.CREATE].get(name) ?? [], ctx);
|
|
724
735
|
}
|
|
725
|
-
//
|
|
736
|
+
// update
|
|
726
737
|
for (const name of commitOrder) {
|
|
727
738
|
await this.commitUpdateChangeSets(groups[ChangeSet_1.ChangeSetType.UPDATE].get(name) ?? [], ctx);
|
|
728
739
|
}
|
|
729
|
-
//
|
|
730
|
-
await this.commitExtraUpdates(ctx);
|
|
731
|
-
//
|
|
740
|
+
// extra updates
|
|
741
|
+
await this.commitExtraUpdates(ChangeSet_1.ChangeSetType.UPDATE, ctx);
|
|
742
|
+
// collection updates
|
|
732
743
|
await this.commitCollectionUpdates(ctx);
|
|
733
|
-
//
|
|
744
|
+
// delete - entity deletions need to be in reverse commit order
|
|
734
745
|
for (const name of commitOrderReversed) {
|
|
735
746
|
await this.commitDeleteChangeSets(groups[ChangeSet_1.ChangeSetType.DELETE].get(name) ?? [], ctx);
|
|
736
747
|
}
|
|
737
|
-
//
|
|
748
|
+
// take snapshots of all persisted collections
|
|
738
749
|
const visited = new Set();
|
|
739
750
|
for (const changeSet of this.changeSets.values()) {
|
|
740
751
|
this.takeCollectionSnapshots(changeSet.entity, visited);
|
|
@@ -825,9 +836,12 @@ class UnitOfWork {
|
|
|
825
836
|
await this.runHooks(enums_1.EventType.afterDelete, changeSet);
|
|
826
837
|
}
|
|
827
838
|
}
|
|
828
|
-
async commitExtraUpdates(ctx) {
|
|
839
|
+
async commitExtraUpdates(type, ctx) {
|
|
829
840
|
const extraUpdates = [];
|
|
830
841
|
for (const extraUpdate of this.extraUpdates) {
|
|
842
|
+
if (extraUpdate[4] !== type) {
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
831
845
|
if (Array.isArray(extraUpdate[1])) {
|
|
832
846
|
extraUpdate[1].forEach((p, i) => extraUpdate[0][p] = extraUpdate[2][i]);
|
|
833
847
|
}
|
package/utils/Configuration.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Configuration = void 0;
|
|
4
|
+
exports.defineConfig = defineConfig;
|
|
4
5
|
const fs_extra_1 = require("fs-extra");
|
|
5
6
|
const cache_1 = require("../cache");
|
|
6
7
|
const hydration_1 = require("../hydration");
|
|
@@ -373,4 +374,3 @@ exports.Configuration = Configuration;
|
|
|
373
374
|
function defineConfig(options) {
|
|
374
375
|
return options;
|
|
375
376
|
}
|
|
376
|
-
exports.defineConfig = defineConfig;
|
package/utils/Cursor.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { type LoadReferenceOptions } from '../entity/Reference';
|
|
|
7
7
|
export declare class DataloaderUtils {
|
|
8
8
|
/**
|
|
9
9
|
* Groups identified references by entity and returns a Map with the
|
|
10
|
-
* class name as the index and the
|
|
10
|
+
* class name as the index and the corresponding primary keys as the value.
|
|
11
11
|
*/
|
|
12
12
|
static groupPrimaryKeysByEntityAndOpts(refsWithOpts: readonly [Ref<any>, Omit<LoadReferenceOptions<any, any>, 'dataloader'>?][]): Map<string, Set<Primary<any>>>;
|
|
13
13
|
/**
|
|
14
14
|
* Returns the reference dataloader batchLoadFn, which aggregates references by entity,
|
|
15
|
-
* makes one query per entity and maps each input reference to the
|
|
15
|
+
* makes one query per entity and maps each input reference to the corresponding result.
|
|
16
16
|
*/
|
|
17
17
|
static getRefBatchLoadFn(em: EntityManager): DataLoader.BatchLoadFn<[Ref<any>, Omit<LoadReferenceOptions<any, any>, 'dataloader'>?], any>;
|
|
18
18
|
/**
|
|
@@ -36,7 +36,7 @@ export declare class DataloaderUtils {
|
|
|
36
36
|
static getColFilter<T, S extends T>(collection: Collection<any, object>): (result: T) => result is S;
|
|
37
37
|
/**
|
|
38
38
|
* Returns the collection dataloader batchLoadFn, which aggregates collections by entity,
|
|
39
|
-
* makes one query per entity and maps each input collection to the
|
|
39
|
+
* makes one query per entity and maps each input collection to the corresponding result.
|
|
40
40
|
*/
|
|
41
41
|
static getColBatchLoadFn(em: EntityManager): DataLoader.BatchLoadFn<[Collection<any>, Omit<InitCollectionOptions<any, any>, 'dataloader'>?], any>;
|
|
42
42
|
static getDataloaderType(dataloaderCfg: DataloaderType | boolean): DataloaderType;
|
package/utils/DataloaderUtils.js
CHANGED
|
@@ -7,7 +7,7 @@ const enums_1 = require("../enums");
|
|
|
7
7
|
class DataloaderUtils {
|
|
8
8
|
/**
|
|
9
9
|
* Groups identified references by entity and returns a Map with the
|
|
10
|
-
* class name as the index and the
|
|
10
|
+
* class name as the index and the corresponding primary keys as the value.
|
|
11
11
|
*/
|
|
12
12
|
static groupPrimaryKeysByEntityAndOpts(refsWithOpts) {
|
|
13
13
|
const map = new Map();
|
|
@@ -20,7 +20,7 @@ class DataloaderUtils {
|
|
|
20
20
|
In real-world scenarios (GraphQL) most of the time you will end up batching the same sets of options anyway,
|
|
21
21
|
so we end up getting most of the benefits with the much simpler implementation.
|
|
22
22
|
Also there are scenarios where the single query per entity implementation may end up being slower, for example
|
|
23
|
-
if the vast majority of the
|
|
23
|
+
if the vast majority of the references batched for a certain entity don't have populate options while a few ones have
|
|
24
24
|
a wildcard populate so you end up doing the additional joins for all the entities.
|
|
25
25
|
Thus such approach should probably be configurable, if not opt-in.
|
|
26
26
|
NOTE: meta + opts multi maps (https://github.com/martian17/ds-js) might be a more elegant way
|
|
@@ -37,7 +37,7 @@ class DataloaderUtils {
|
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Returns the reference dataloader batchLoadFn, which aggregates references by entity,
|
|
40
|
-
* makes one query per entity and maps each input reference to the
|
|
40
|
+
* makes one query per entity and maps each input reference to the corresponding result.
|
|
41
41
|
*/
|
|
42
42
|
static getRefBatchLoadFn(em) {
|
|
43
43
|
return async (refsWithOpts) => {
|
|
@@ -159,7 +159,7 @@ class DataloaderUtils {
|
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Returns the collection dataloader batchLoadFn, which aggregates collections by entity,
|
|
162
|
-
* makes one query per entity and maps each input collection to the
|
|
162
|
+
* makes one query per entity and maps each input collection to the corresponding result.
|
|
163
163
|
*/
|
|
164
164
|
static getColBatchLoadFn(em) {
|
|
165
165
|
return async (collsWithOpts) => {
|
|
@@ -3,6 +3,7 @@ import type { Platform } from '../platforms';
|
|
|
3
3
|
type Comparator<T> = (a: T, b: T) => EntityData<T>;
|
|
4
4
|
type ResultMapper<T> = (result: EntityData<T>) => EntityData<T> | null;
|
|
5
5
|
type SnapshotGenerator<T> = (entity: T) => EntityData<T>;
|
|
6
|
+
type CompositeKeyPart = string | CompositeKeyPart[];
|
|
6
7
|
export declare class EntityComparator {
|
|
7
8
|
private readonly metadata;
|
|
8
9
|
private readonly platform;
|
|
@@ -44,6 +45,18 @@ export declare class EntityComparator {
|
|
|
44
45
|
* @internal Highly performance-sensitive method.
|
|
45
46
|
*/
|
|
46
47
|
getSnapshotGenerator<T>(entityName: string): SnapshotGenerator<T>;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
propName(name: string, parent?: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* @internal respects nested composite keys, e.g. `[1, [2, 3]]`
|
|
54
|
+
*/
|
|
55
|
+
createCompositeKeyArray(prop: EntityProperty, parents?: EntityProperty[]): string;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
formatCompositeKeyPart(part: CompositeKeyPart): string;
|
|
47
60
|
/**
|
|
48
61
|
* @internal Highly performance-sensitive method.
|
|
49
62
|
*/
|