@mikro-orm/core 7.0.0-dev.126 → 7.0.0-dev.128
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/defineEntity.d.ts +18 -11
- package/metadata/EntitySchema.d.ts +3 -3
- package/package.json +1 -1
- package/typings.d.ts +1 -1
- package/typings.js +7 -2
- package/utils/Configuration.d.ts +3 -2
- package/utils/Configuration.js +1 -0
- package/utils/Utils.js +1 -1
package/entity/defineEntity.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EntityManager } from '../EntityManager.js';
|
|
2
2
|
import type { ColumnType, PropertyOptions, ReferenceOptions, EnumOptions, EmbeddedOptions, ManyToOneOptions, OneToManyOptions, OneToOneOptions, ManyToManyOptions } from '../metadata/types.js';
|
|
3
|
-
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, IndexCallback, EntityCtor } from '../typings.js';
|
|
3
|
+
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, IndexCallback, EntityCtor, IsNever } from '../typings.js';
|
|
4
4
|
import type { ScalarReference } from './Reference.js';
|
|
5
5
|
import type { SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
6
6
|
import type { Cascade, DeferMode, EmbeddedPrefixMode, EventType, LoadStrategy, QueryOrderMap } from '../enums.js';
|
|
@@ -409,13 +409,13 @@ declare const propertyBuilders: {
|
|
|
409
409
|
interval: () => UniversalPropertyOptionsBuilder<string, EmptyOptions, IncludeKeysForProperty>;
|
|
410
410
|
unknown: () => UniversalPropertyOptionsBuilder<{}, EmptyOptions, IncludeKeysForProperty>;
|
|
411
411
|
};
|
|
412
|
-
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminatorColumn' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques'> {
|
|
412
|
+
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminatorColumn' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques'> {
|
|
413
413
|
name: TName;
|
|
414
414
|
tableName?: TTableName;
|
|
415
415
|
extends?: EntityName<TBase>;
|
|
416
416
|
properties: TProperties | ((properties: typeof propertyBuilders) => TProperties);
|
|
417
417
|
primaryKeys?: TPK & InferPrimaryKey<TProperties>[];
|
|
418
|
-
hooks?: DefineEntityHooks<InferEntityFromProperties<TProperties, TPK>>;
|
|
418
|
+
hooks?: DefineEntityHooks<InferEntityFromProperties<TProperties, TPK, TBase>>;
|
|
419
419
|
discriminatorColumn?: keyof TProperties;
|
|
420
420
|
versionProperty?: keyof TProperties;
|
|
421
421
|
concurrencyCheckKeys?: Set<keyof TProperties>;
|
|
@@ -425,22 +425,22 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
425
425
|
name?: string;
|
|
426
426
|
type?: string;
|
|
427
427
|
options?: Dictionary;
|
|
428
|
-
expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK>>;
|
|
428
|
+
expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK, TBase>>;
|
|
429
429
|
}[];
|
|
430
430
|
uniques?: {
|
|
431
431
|
properties?: keyof TProperties | (keyof TProperties)[];
|
|
432
432
|
name?: string;
|
|
433
433
|
options?: Dictionary;
|
|
434
|
-
expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK>>;
|
|
434
|
+
expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK, TBase>>;
|
|
435
435
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
436
436
|
}[];
|
|
437
437
|
}
|
|
438
|
-
export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK>, TBase, TProperties>;
|
|
439
|
-
export declare function defineEntity<const TEntity = any, const TProperties extends Record<string, any> = Record<string, any>, const TClassName extends string = string, const TTableName extends string = string, const TBase = never, const TClass extends EntityCtor =
|
|
438
|
+
export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase>, TBase, TProperties>;
|
|
439
|
+
export declare function defineEntity<const TEntity = any, const TProperties extends Record<string, any> = Record<string, any>, const TClassName extends string = string, const TTableName extends string = string, const TBase = never, const TClass extends EntityCtor = EntityCtor<TEntity>>(meta: Omit<Partial<EntityMetadata<TEntity>>, 'properties' | 'extends' | 'className' | 'tableName'> & {
|
|
440
440
|
class: TClass;
|
|
441
441
|
className?: TClassName;
|
|
442
442
|
tableName?: TTableName;
|
|
443
|
-
extends?:
|
|
443
|
+
extends?: TBase;
|
|
444
444
|
properties: TProperties | ((properties: typeof propertyBuilders) => TProperties);
|
|
445
445
|
}): EntitySchemaWithMeta<TClassName, TTableName, TEntity, TBase, TProperties, TClass>;
|
|
446
446
|
export declare namespace defineEntity {
|
|
@@ -495,11 +495,18 @@ type InferPropertyValueType<T extends PropertyValueType> = T extends string ? In
|
|
|
495
495
|
type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJSType<typeof types[T]> : InferColumnType<T>;
|
|
496
496
|
type InferJSType<T> = T extends typeof Type<infer TValue, any> ? NonNullable<TValue> : never;
|
|
497
497
|
type InferColumnType<T extends string> = T extends 'int' | 'int4' | 'integer' | 'bigint' | 'int8' | 'int2' | 'tinyint' | 'smallint' | 'mediumint' ? number : T extends 'double' | 'double precision' | 'real' | 'float8' | 'decimal' | 'numeric' | 'float' | 'float4' ? number : T extends 'datetime' | 'time' | 'time with time zone' | 'timestamp' | 'timestamp with time zone' | 'timetz' | 'timestamptz' | 'date' | 'interval' ? Date : T extends 'ObjectId' | 'objectId' | 'character varying' | 'varchar' | 'char' | 'character' | 'uuid' | 'text' | 'tinytext' | 'mediumtext' | 'longtext' | 'enum' ? string : T extends 'boolean' | 'bool' | 'bit' ? boolean : T extends 'blob' | 'tinyblob' | 'mediumblob' | 'longblob' | 'bytea' ? Buffer : T extends 'point' | 'line' | 'lseg' | 'box' | 'circle' | 'path' | 'polygon' | 'geometry' ? number[] : T extends 'tsvector' | 'tsquery' ? string[] : T extends 'json' | 'jsonb' ? any : any;
|
|
498
|
-
export type InferEntityFromProperties<Properties extends Record<string, any>, PK extends (keyof Properties)[] | undefined = undefined> = {
|
|
498
|
+
export type InferEntityFromProperties<Properties extends Record<string, any>, PK extends (keyof Properties)[] | undefined = undefined, Base = never> = {
|
|
499
499
|
-readonly [K in keyof Properties]: InferBuilderValue<MaybeReturnType<Properties[K]>>;
|
|
500
500
|
} & {
|
|
501
|
-
[PrimaryKeyProp]?:
|
|
502
|
-
};
|
|
501
|
+
[PrimaryKeyProp]?: InferCombinedPrimaryKey<Properties, PK, Base>;
|
|
502
|
+
} & (IsNever<Base> extends true ? {} : Omit<Base, typeof PrimaryKeyProp>);
|
|
503
|
+
type InferCombinedPrimaryKey<Properties extends Record<string, any>, PK, Base> = PK extends undefined ? CombinePrimaryKeys<InferPrimaryKey<Properties>, ExtractBasePrimaryKey<Base>> : PK;
|
|
504
|
+
type ExtractBasePrimaryKey<Base> = Base extends {
|
|
505
|
+
[PrimaryKeyProp]?: infer BasePK;
|
|
506
|
+
} ? BasePK : never;
|
|
507
|
+
type CombinePrimaryKeys<ChildPK, BasePK> = [
|
|
508
|
+
ChildPK
|
|
509
|
+
] extends [never] ? BasePK : [BasePK] extends [never] ? IsUnion<ChildPK> extends true ? ChildPK[] : ChildPK : ChildPK | BasePK;
|
|
503
510
|
export type InferPrimaryKey<Properties extends Record<string, any>> = {
|
|
504
511
|
[K in keyof Properties]: MaybeReturnType<Properties[K]> extends {
|
|
505
512
|
'~options': {
|
|
@@ -27,7 +27,7 @@ export type EntitySchemaProperty<Target, Owner> = ({
|
|
|
27
27
|
enum: true;
|
|
28
28
|
} & EnumOptions<Owner>) | (TypeDef<Target> & PropertyOptions<Owner>);
|
|
29
29
|
type OmitBaseProps<Entity, Base> = IsNever<Base> extends true ? Entity : Omit<Entity, keyof Base>;
|
|
30
|
-
export type EntitySchemaMetadata<Entity, Base = never, Class extends EntityCtor =
|
|
30
|
+
export type EntitySchemaMetadata<Entity, Base = never, Class extends EntityCtor = EntityCtor<Entity>> = Omit<Partial<EntityMetadata<Entity>>, 'name' | 'properties' | 'extends'> & ({
|
|
31
31
|
name: string;
|
|
32
32
|
} | {
|
|
33
33
|
class: Class;
|
|
@@ -39,12 +39,12 @@ export type EntitySchemaMetadata<Entity, Base = never, Class extends EntityCtor
|
|
|
39
39
|
[Key in keyof OmitBaseProps<Entity, Base> as CleanKeys<OmitBaseProps<Entity, Base>, Key>]-?: EntitySchemaProperty<ExpandProperty<NonNullable<Entity[Key]>>, Entity>;
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
export declare class EntitySchema<Entity = any, Base = never, Class extends EntityCtor =
|
|
42
|
+
export declare class EntitySchema<Entity = any, Base = never, Class extends EntityCtor = EntityCtor<Entity>> {
|
|
43
43
|
/**
|
|
44
44
|
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
45
45
|
* so we can use the class in `entities` option just like the EntitySchema instance.
|
|
46
46
|
*/
|
|
47
|
-
static REGISTRY: Map<Partial<any>, EntitySchema<any, never, any
|
|
47
|
+
static REGISTRY: Map<Partial<any>, EntitySchema<any, never, EntityCtor<any>>>;
|
|
48
48
|
private readonly _meta;
|
|
49
49
|
private internal;
|
|
50
50
|
private initialized;
|
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.128",
|
|
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",
|
package/typings.d.ts
CHANGED
|
@@ -848,7 +848,7 @@ export interface Seeder<T extends Dictionary = Dictionary> {
|
|
|
848
848
|
export type ConnectionType = 'read' | 'write';
|
|
849
849
|
export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
|
|
850
850
|
export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
851
|
-
export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>, TClass extends EntityCtor =
|
|
851
|
+
export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>, TClass extends EntityCtor = EntityCtor<TEntity>> extends EntitySchema<TEntity, TBase, TClass> {
|
|
852
852
|
readonly name: TName;
|
|
853
853
|
readonly properties: TProperties;
|
|
854
854
|
readonly tableName: TTableName;
|
package/typings.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Reference } from './entity/Reference.js';
|
|
|
3
3
|
import { EntityHelper } from './entity/EntityHelper.js';
|
|
4
4
|
import { Utils } from './utils/Utils.js';
|
|
5
5
|
import { EntityComparator } from './utils/EntityComparator.js';
|
|
6
|
+
import { BaseEntity } from './entity/BaseEntity.js';
|
|
6
7
|
export const EntityRepositoryType = Symbol('EntityRepositoryType');
|
|
7
8
|
export const PrimaryKeyProp = Symbol('PrimaryKeyProp');
|
|
8
9
|
export const OptionalProps = Symbol('OptionalProps');
|
|
@@ -27,8 +28,12 @@ export class EntityMetadata {
|
|
|
27
28
|
Object.assign(this, meta);
|
|
28
29
|
const name = meta.className ?? meta.name;
|
|
29
30
|
if (!this.class && name) {
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const Class = this.extends === BaseEntity
|
|
32
|
+
? ({ [name]: class extends BaseEntity {
|
|
33
|
+
} })[name]
|
|
34
|
+
: ({ [name]: class {
|
|
35
|
+
} })[name];
|
|
36
|
+
this.class = Class;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
addProperty(prop) {
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ declare const DEFAULTS: {
|
|
|
69
69
|
readonly upsertManaged: true;
|
|
70
70
|
readonly forceEntityConstructor: false;
|
|
71
71
|
readonly forceUndefined: false;
|
|
72
|
+
readonly forceUtcTimezone: true;
|
|
72
73
|
readonly processOnCreateHooksEarly: true;
|
|
73
74
|
readonly ensureDatabase: true;
|
|
74
75
|
readonly ensureIndexes: false;
|
|
@@ -623,9 +624,9 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
623
624
|
processOnCreateHooksEarly?: boolean;
|
|
624
625
|
/**
|
|
625
626
|
* Force `Date` values to be stored in UTC for datetime columns without timezone.
|
|
626
|
-
* Works for MySQL (`datetime` type)
|
|
627
|
+
* Works for MySQL (`datetime` type), PostgreSQL (`timestamp` type), and MSSQL (`datetime`/`datetime2` types).
|
|
627
628
|
* SQLite does this by default.
|
|
628
|
-
* @default
|
|
629
|
+
* @default true
|
|
629
630
|
*/
|
|
630
631
|
forceUtcTimezone?: boolean;
|
|
631
632
|
/**
|
package/utils/Configuration.js
CHANGED
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.128';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|