@mikro-orm/core 7.0.0-dev.255 → 7.0.0-dev.257
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/entity/BaseEntity.d.ts +2 -2
- package/entity/EntityHelper.js +2 -2
- package/entity/WrappedEntity.d.ts +2 -2
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/serialization/EntitySerializer.d.ts +3 -3
- package/typings.d.ts +30 -6
- package/typings.js +2 -0
- package/utils/Utils.js +1 -1
package/entity/BaseEntity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Ref } from './Reference.js';
|
|
2
|
-
import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
2
|
+
import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected, SerializeDTO } from '../typings.js';
|
|
3
3
|
import { type AssignOptions } from './EntityAssigner.js';
|
|
4
4
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
5
5
|
import { type SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
@@ -73,7 +73,7 @@ export declare abstract class BaseEntity {
|
|
|
73
73
|
*/
|
|
74
74
|
toObject<Entity extends this = this, Ignored extends EntityKey<Entity> = never>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
75
75
|
toPOJO<Entity extends this = this>(): EntityDTO<Entity>;
|
|
76
|
-
serialize<Entity extends this = this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>):
|
|
76
|
+
serialize<Entity extends this = this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
|
|
77
77
|
assign<Entity extends this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
78
78
|
init<Entity extends this = this, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
|
|
79
79
|
getSchema(): string | undefined;
|
package/entity/EntityHelper.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EagerProps, EntityRepositoryType, HiddenProps, OptionalProps, PrimaryKeyProp, } from '../typings.js';
|
|
1
|
+
import { EagerProps, EntityName, EntityRepositoryType, HiddenProps, OptionalProps, PrimaryKeyProp, } from '../typings.js';
|
|
2
2
|
import { EntityTransformer } from '../serialization/EntityTransformer.js';
|
|
3
3
|
import { Reference } from './Reference.js';
|
|
4
4
|
import { Utils } from '../utils/Utils.js';
|
|
@@ -130,7 +130,7 @@ export class EntityHelper {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
// ensure we dont have internal symbols in the POJO
|
|
133
|
-
[OptionalProps, EntityRepositoryType, PrimaryKeyProp, EagerProps, HiddenProps].forEach(sym => delete object[sym]);
|
|
133
|
+
[OptionalProps, EntityRepositoryType, PrimaryKeyProp, EagerProps, HiddenProps, EntityName].forEach(sym => delete object[sym]);
|
|
134
134
|
meta.props
|
|
135
135
|
.filter(prop => object[prop.name] === undefined)
|
|
136
136
|
.forEach(prop => delete object[prop.name]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PopulatePath } from '../enums.js';
|
|
2
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
3
|
-
import type { Dictionary, EntityData, EntityDictionary, EntityMetadata, IHydrator, EntityKey, PopulateOptions, Primary, AutoPath, Ref, AddEager, LoadedReference, EntityDTO, Loaded, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
3
|
+
import type { Dictionary, EntityData, EntityDictionary, EntityMetadata, IHydrator, EntityKey, PopulateOptions, Primary, AutoPath, Ref, AddEager, LoadedReference, EntityDTO, Loaded, SerializeDTO, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
4
4
|
import { Reference } from './Reference.js';
|
|
5
5
|
import { type AssignOptions } from './EntityAssigner.js';
|
|
6
6
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
@@ -44,7 +44,7 @@ export declare class WrappedEntity<Entity extends object> {
|
|
|
44
44
|
setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
45
45
|
toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
46
46
|
toObject<Ignored extends EntityKey<Entity> = never>(ignoreFields?: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
47
|
-
serialize<Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Entity, Hint, Exclude>):
|
|
47
|
+
serialize<Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Entity, Hint, Exclude>): SerializeDTO<Entity, Hint, Exclude>;
|
|
48
48
|
toPOJO(): EntityDTO<Entity>;
|
|
49
49
|
toJSON(...args: any[]): EntityDictionary<Entity>;
|
|
50
50
|
assign<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
package/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
|
-
export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity,
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
|
|
6
|
+
export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, InferEntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, EntityDTOFlat, EntityDTOProp, SerializeDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, RequiredEntityData, CheckCallback, IndexCallback, FormulaCallback, FormulaTable, SchemaTable, SchemaColumns, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, CheckConstraint, GeneratedColumnCallback, FilterDef, EntityCtor, Subquery, PopulateHintOptions, Prefixes, } from './typings.js';
|
|
7
7
|
export * from './enums.js';
|
|
8
8
|
export * from './errors.js';
|
|
9
9
|
export * from './exceptions.js';
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
|
|
6
6
|
export * from './enums.js';
|
|
7
7
|
export * from './errors.js';
|
|
8
8
|
export * from './exceptions.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.257",
|
|
5
5
|
"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.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ArrayElement, AutoPath, CleanTypeConfig,
|
|
1
|
+
import type { ArrayElement, AutoPath, CleanTypeConfig, SerializeDTO, FromEntityType, TypeConfig, UnboxArray } from '../typings.js';
|
|
2
2
|
import { type PopulatePath } from '../enums.js';
|
|
3
3
|
export declare class EntitySerializer {
|
|
4
|
-
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>):
|
|
4
|
+
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>): SerializeDTO<T, P, E>;
|
|
5
5
|
private static propertyName;
|
|
6
6
|
private static processProperty;
|
|
7
7
|
private static processCustomType;
|
|
@@ -39,4 +39,4 @@ export interface SerializeOptions<T, P extends string = never, E extends string
|
|
|
39
39
|
* const dto2 = wrap(user).serialize({ exclude: ['id', 'email'], forceObject: true });
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ?
|
|
42
|
+
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ? SerializeDTO<ArrayElement<Naked>, Populate, Exclude, CleanTypeConfig<Config>>[] : SerializeDTO<Naked, Populate, Exclude, CleanTypeConfig<Config>>;
|
package/typings.d.ts
CHANGED
|
@@ -110,6 +110,10 @@ export declare const OptionalProps: unique symbol;
|
|
|
110
110
|
export declare const EagerProps: unique symbol;
|
|
111
111
|
export declare const HiddenProps: unique symbol;
|
|
112
112
|
export declare const Config: unique symbol;
|
|
113
|
+
export declare const EntityName: unique symbol;
|
|
114
|
+
export type InferEntityName<T> = T extends {
|
|
115
|
+
[EntityName]?: infer Name;
|
|
116
|
+
} ? Name extends string ? Name : never : never;
|
|
113
117
|
export type Opt<T = unknown> = T & Opt.Brand;
|
|
114
118
|
export declare namespace Opt {
|
|
115
119
|
const __optional: unique symbol;
|
|
@@ -251,7 +255,7 @@ export interface IWrappedEntity<Entity extends object> {
|
|
|
251
255
|
toObject<Ignored extends EntityKey<Entity>>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
252
256
|
toJSON(...args: any[]): EntityDTO<Entity>;
|
|
253
257
|
toPOJO(): EntityDTO<Entity>;
|
|
254
|
-
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>):
|
|
258
|
+
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
|
|
255
259
|
setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
256
260
|
assign<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
257
261
|
getSchema(): string | undefined;
|
|
@@ -385,9 +389,10 @@ type PreferExplicitConfig<E, I> = IsNever<E, I, E>;
|
|
|
385
389
|
type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true ? {
|
|
386
390
|
[K in PrimaryProperty<U> & keyof U]: U[K];
|
|
387
391
|
} : Primary<U>;
|
|
388
|
-
|
|
392
|
+
type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
|
|
393
|
+
export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar ? T : T extends ScalarReference<infer U> ? U : T extends {
|
|
389
394
|
__serialized?: infer U;
|
|
390
|
-
} ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReferenceShape<infer U> ?
|
|
395
|
+
} ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReferenceShape<infer U> ? DTOWrapper<U, C, Flat> : T extends ReferenceShape<infer U> ? PrimaryOrObject<E, U, C> : T extends LoadedCollectionShape<infer U> ? DTOWrapper<U & object, C, Flat>[] : T extends CollectionShape<infer U> ? PrimaryOrObject<E, U & object, C>[] : T extends readonly (infer U)[] ? U extends Scalar ? T : EntityDTOProp<E, U, C, Flat>[] : T extends Relation<T> ? DTOWrapper<T, C, Flat> : T;
|
|
391
396
|
type UnwrapLoadedEntity<T> = T extends {
|
|
392
397
|
[__loadedType]?: infer U;
|
|
393
398
|
} ? NonNullable<U> : T;
|
|
@@ -400,6 +405,27 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
400
405
|
} & {
|
|
401
406
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
402
407
|
};
|
|
408
|
+
/**
|
|
409
|
+
* @internal
|
|
410
|
+
* 1-pass variant of EntityDTO — ~2x cheaper to resolve but all keys are required
|
|
411
|
+
* (optional keys use `| undefined` in value type instead of `?` modifier).
|
|
412
|
+
* Use only for internal type computations (output types), never as a user-facing
|
|
413
|
+
* function parameter type where generic assignability checks are needed.
|
|
414
|
+
*/
|
|
415
|
+
export type EntityDTOFlat<T, C extends TypeConfig = never> = {
|
|
416
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K>]: EntityDTOProp<T, T[K], C, true> | AddOptional<T[K]>;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* @internal
|
|
420
|
+
* Single-pass fused type that combines Loaded + EntityDTO into one mapped type.
|
|
421
|
+
* ~40x faster than `EntityDTO<Loaded<T, H>>` for populated entities.
|
|
422
|
+
*/
|
|
423
|
+
type SerializeTopHints<H extends string> = H extends `${infer Top}.${string}` ? Top : H;
|
|
424
|
+
type SerializeSubHints<K extends string, H extends string> = H extends `${K}.${infer Rest}` ? Rest : never;
|
|
425
|
+
type SerializePropValue<T, K extends keyof T, H extends string, C extends TypeConfig = never> = (K & string) extends SerializeTopHints<H> ? NonNullable<T[K]> extends CollectionShape<infer U> ? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C>[] : SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C> | Extract<T[K], null | undefined> : EntityDTOProp<T, T[K], C>;
|
|
426
|
+
export type SerializeDTO<T, H extends string = never, E extends string = never, C extends TypeConfig = never> = string extends H ? EntityDTOFlat<T, C> : {
|
|
427
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>)]: SerializePropValue<T, K, H, C> | Extract<T[K], null | undefined>;
|
|
428
|
+
};
|
|
403
429
|
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
404
430
|
type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
405
431
|
export type FormulaTable = {
|
|
@@ -981,9 +1007,7 @@ type LoadedProp<T, L extends string = never, F extends string = '*', E extends s
|
|
|
981
1007
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
982
1008
|
export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
983
1009
|
export type Selected<T, L extends string = never, F extends string = '*'> = {
|
|
984
|
-
[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]>;
|
|
985
|
-
} & {
|
|
986
|
-
[K in keyof T as FunctionKeys<T, K>]: T[K];
|
|
1010
|
+
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>> | FunctionKeys<T, K>]: T[K] extends Function ? T[K] : LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
987
1011
|
} & {
|
|
988
1012
|
[__selectedType]?: T;
|
|
989
1013
|
};
|
package/typings.js
CHANGED
|
@@ -11,6 +11,8 @@ export const OptionalProps = Symbol('OptionalProps');
|
|
|
11
11
|
export const EagerProps = Symbol('EagerProps');
|
|
12
12
|
export const HiddenProps = Symbol('HiddenProps');
|
|
13
13
|
export const Config = Symbol('Config');
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
15
|
+
export const EntityName = Symbol('EntityName');
|
|
14
16
|
export class EntityMetadata {
|
|
15
17
|
static counter = 0;
|
|
16
18
|
_id = 1000 * EntityMetadata.counter++; // keep the id >= 1000 to allow computing cache keys by simple addition
|
package/utils/Utils.js
CHANGED
|
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
|
|
|
123
123
|
}
|
|
124
124
|
export class Utils {
|
|
125
125
|
static PK_SEPARATOR = '~~~';
|
|
126
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.257';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|