@mikro-orm/core 7.0.0-dev.4 → 7.0.0-dev.6

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.
@@ -1,3 +1,3 @@
1
- import type { CheckConstraint } from '../typings.js';
2
- export declare function Check<T>(options: CheckOptions<T>): (target: any, propertyName?: string) => any;
1
+ import type { CheckConstraint, EntityClass } from '../typings.js';
2
+ export declare function Check<T>(options: CheckOptions<T>): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
3
3
  export type CheckOptions<T = any> = CheckConstraint<T>;
@@ -1,8 +1,8 @@
1
- import type { Dictionary } from '../typings.js';
2
- export declare function Embeddable(options?: EmbeddableOptions): <T>(target: T & Dictionary) => T & Dictionary;
3
- export type EmbeddableOptions = {
4
- discriminatorColumn?: string;
1
+ import type { AnyString, Dictionary, EntityClass } from '../typings.js';
2
+ export declare function Embeddable<T>(options?: EmbeddableOptions<T>): (target: T) => T;
3
+ export interface EmbeddableOptions<T> {
4
+ discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
5
5
  discriminatorMap?: Dictionary<string>;
6
6
  discriminatorValue?: number | string;
7
7
  abstract?: boolean;
8
- };
8
+ }
@@ -3,7 +3,7 @@ export function Embeddable(options = {}) {
3
3
  return function (target) {
4
4
  const meta = MetadataStorage.getMetadataFromDecorator(target);
5
5
  meta.class = target;
6
- meta.name = target.name;
6
+ meta.name = meta.class.name;
7
7
  meta.embeddable = true;
8
8
  Object.assign(meta, options);
9
9
  return target;
@@ -2,7 +2,7 @@ import type { AnyEntity } from '../typings.js';
2
2
  export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
3
3
  /** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
4
4
  export type EmbeddedPrefixMode = 'absolute' | 'relative';
5
- export type EmbeddedOptions = {
5
+ export interface EmbeddedOptions {
6
6
  entity?: string | (() => AnyEntity | AnyEntity[]);
7
7
  type?: string;
8
8
  prefix?: string | boolean;
@@ -15,4 +15,4 @@ export type EmbeddedOptions = {
15
15
  serializedName?: string;
16
16
  groups?: string[];
17
17
  persist?: boolean;
18
- };
18
+ }
@@ -1,6 +1,6 @@
1
1
  import type { PropertyOptions } from './Property.js';
2
2
  import type { AnyEntity, Dictionary } from '../typings.js';
3
- export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: AnyEntity, propertyName: string) => any;
3
+ export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: T, propertyName: string) => any;
4
4
  export interface EnumOptions<T> extends PropertyOptions<T> {
5
5
  items?: (number | string)[] | (() => Dictionary);
6
6
  array?: boolean;
@@ -1,5 +1,4 @@
1
- import type { AnyEntity } from '../typings.js';
2
1
  import type { PropertyOptions } from './Property.js';
3
- export declare function Formula<T extends object>(formula: string | ((alias: string) => string), options?: FormulaOptions<T>): (target: AnyEntity, propertyName: string) => any;
2
+ export declare function Formula<T extends object>(formula: string | ((alias: string) => string), options?: FormulaOptions<T>): (target: T, propertyName: string) => any;
4
3
  export interface FormulaOptions<T> extends PropertyOptions<T> {
5
4
  }
@@ -1,7 +1,7 @@
1
1
  import type { ReferenceOptions } from './Property.js';
2
- import type { EntityName, AnyEntity, FilterQuery, AnyString } from '../typings.js';
2
+ import type { EntityName, FilterQuery, AnyString } from '../typings.js';
3
3
  import { type QueryOrderMap } from '../enums.js';
4
- export declare function ManyToMany<T extends object, O>(entity?: ManyToManyOptions<T, O> | string | (() => EntityName<T>), mappedBy?: (string & keyof T) | ((e: T) => any), options?: Partial<ManyToManyOptions<T, O>>): (target: AnyEntity, propertyName: string) => any;
4
+ export declare function ManyToMany<Target extends object, Owner extends object>(entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>), mappedBy?: (string & keyof Target) | ((e: Target) => any), options?: Partial<ManyToManyOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
5
5
  export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
6
6
  /** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
7
7
  owner?: boolean;
@@ -1,7 +1,7 @@
1
1
  import type { ReferenceOptions } from './Property.js';
2
2
  import { type DeferMode } from '../enums.js';
3
- import type { AnyEntity, AnyString, EntityName } from '../typings.js';
4
- export declare function ManyToOne<T extends object, O>(entity?: ManyToOneOptions<T, O> | string | ((e?: any) => EntityName<T>), options?: Partial<ManyToOneOptions<T, O>>): (target: AnyEntity, propertyName: string) => any;
3
+ import type { AnyString, EntityName } from '../typings.js';
4
+ export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), options?: Partial<ManyToOneOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
5
5
  export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
6
6
  /** Point to the inverse side property name. */
7
7
  inversedBy?: (string & keyof Target) | ((e: Target) => any);
@@ -1,9 +1,9 @@
1
1
  import type { ReferenceOptions } from './Property.js';
2
2
  import { ReferenceKind, type QueryOrderMap } from '../enums.js';
3
- import type { EntityName, AnyEntity, FilterQuery } from '../typings.js';
4
- export declare function createOneToDecorator<Target, Owner>(entity: OneToManyOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any) | undefined, options: Partial<OneToManyOptions<Owner, Target>>, kind: ReferenceKind): (target: AnyEntity, propertyName: string) => any;
5
- export declare function OneToMany<Target, Owner>(entity: string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target: AnyEntity, propertyName: string) => void;
6
- export declare function OneToMany<Target, Owner>(options: OneToManyOptions<Owner, Target>): (target: AnyEntity, propertyName: string) => void;
3
+ import type { EntityName, FilterQuery } from '../typings.js';
4
+ export declare function createOneToDecorator<Target, Owner>(entity: OneToManyOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any) | undefined, options: Partial<OneToManyOptions<Owner, Target>>, kind: ReferenceKind): (target: Owner, propertyName: string) => any;
5
+ export declare function OneToMany<Target, Owner>(entity: string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
6
+ export declare function OneToMany<Target, Owner>(options: OneToManyOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
7
7
  export interface OneToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
8
8
  /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
9
9
  orphanRemoval?: boolean;
@@ -1,7 +1,7 @@
1
1
  import { type DeferMode } from '../enums.js';
2
2
  import { type OneToManyOptions } from './OneToMany.js';
3
3
  import type { AnyString, EntityName } from '../typings.js';
4
- export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: import("../typings.js").AnyEntity, propertyName: string) => any;
4
+ export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: Owner, propertyName: string) => any;
5
5
  export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>> {
6
6
  /** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
7
7
  owner?: boolean;
@@ -1,7 +1,6 @@
1
1
  import type { PropertyOptions } from './Property.js';
2
- import type { AnyEntity } from '../typings.js';
3
- export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: AnyEntity, propertyName: string) => any;
4
- export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: AnyEntity, propertyName: string) => any;
2
+ export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
3
+ export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
5
4
  export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
6
5
  }
7
6
  export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
@@ -3,7 +3,7 @@ import type { EntityName, Constructor, CheckCallback, GeneratedColumnCallback, A
3
3
  import type { Type, types } from '../types/index.js';
4
4
  import type { EntityManager } from '../EntityManager.js';
5
5
  import type { SerializeOptions } from '../serialization/EntitySerializer.js';
6
- export declare function Property<T extends object>(options?: PropertyOptions<T>): (target: any, propertyName: string) => any;
6
+ export declare function Property<T extends object>(options?: PropertyOptions<T>): (target: T, propertyName: string) => any;
7
7
  export interface PropertyOptions<Owner> {
8
8
  /**
9
9
  * Alias for `fieldName`.
@@ -249,9 +249,13 @@ export class EntityLoader {
249
249
  }
250
250
  }
251
251
  }
252
+ const orderBy = [...Utils.asArray(options.orderBy), ...propOrderBy].filter((order, idx, array) => {
253
+ // skip consecutive ordering with the same key to get around mongo issues
254
+ return idx === 0 || !Utils.equals(Object.keys(array[idx - 1]), Object.keys(order));
255
+ });
252
256
  const items = await this.em.find(prop.type, where, {
253
257
  filters, convertCustomTypes, lockMode, populateWhere, logging,
254
- orderBy: [...Utils.asArray(options.orderBy), ...propOrderBy],
258
+ orderBy,
255
259
  populate: populate.children ?? populate.all ?? [],
256
260
  exclude: Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop.name) : options.exclude,
257
261
  strategy, fields, schema, connectionType,
@@ -905,11 +905,13 @@ export class MetadataDiscovery {
905
905
  }
906
906
  if (!meta.root.discriminatorMap) {
907
907
  meta.root.discriminatorMap = {};
908
- const children = metadata.filter(m => m.root.className === meta.root.className && !m.abstract);
909
- children.forEach(m => {
908
+ const children = metadata
909
+ .filter(m => m.root.className === meta.root.className && !m.abstract)
910
+ .sort((a, b) => a.className.localeCompare(b.className));
911
+ for (const m of children) {
910
912
  const name = m.discriminatorValue ?? this.namingStrategy.classToTableName(m.className);
911
913
  meta.root.discriminatorMap[name] = m.className;
912
- });
914
+ }
913
915
  }
914
916
  meta.discriminatorValue = Object.entries(meta.root.discriminatorMap).find(([, className]) => className === meta.className)?.[0];
915
917
  if (!meta.root.properties[meta.root.discriminatorColumn]) {
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",
4
+ "version": "7.0.0-dev.6",
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",
@@ -55,7 +55,7 @@
55
55
  "dotenv": "16.4.7",
56
56
  "esprima": "4.0.1",
57
57
  "globby": "11.1.0",
58
- "mikro-orm": "7.0.0-dev.4",
58
+ "mikro-orm": "7.0.0-dev.6",
59
59
  "reflect-metadata": "0.2.2"
60
60
  }
61
61
  }
package/typings.d.ts CHANGED
@@ -293,7 +293,8 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
293
293
  } & {
294
294
  [K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
295
295
  };
296
- type CheckKey<T> = IsUnknown<T> extends false ? keyof T : string;
296
+ type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
297
+ type CheckKey<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
297
298
  export type CheckCallback<T> = (columns: Record<CheckKey<T>, string>) => string;
298
299
  export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
299
300
  export interface CheckConstraint<T = any> {