@mikro-orm/core 6.4.15-dev.1 → 6.4.15-dev.2

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,18 +1,12 @@
1
- import type { AnyEntity } from '../typings';
2
- export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
1
+ import type { AnyEntity, EntityName } from '../typings';
2
+ import type { PropertyOptions } from './Property';
3
+ export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName<Target>[]), options?: EmbeddedOptions<Owner, Target>): (target: AnyEntity, propertyName: string) => any;
3
4
  /** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
4
5
  export type EmbeddedPrefixMode = 'absolute' | 'relative';
5
- export type EmbeddedOptions = {
6
- entity?: string | (() => AnyEntity | AnyEntity[]);
7
- type?: string;
6
+ export interface EmbeddedOptions<Owner, Target> extends PropertyOptions<Owner> {
7
+ entity?: string | (() => EntityName<Target> | EntityName<Target>[]);
8
8
  prefix?: string | boolean;
9
9
  prefixMode?: EmbeddedPrefixMode;
10
- nullable?: boolean;
11
10
  object?: boolean;
12
11
  array?: boolean;
13
- hidden?: boolean;
14
- serializer?: (value: any) => any;
15
- serializedName?: string;
16
- groups?: string[];
17
- persist?: boolean;
18
- };
12
+ }
@@ -23,7 +23,7 @@ export type EntitySchemaProperty<Target, Owner> = ({
23
23
  kind: ReferenceKind.MANY_TO_MANY | 'm:n';
24
24
  } & TypeDef<Target> & ManyToManyOptions<Owner, Target>) | ({
25
25
  kind: ReferenceKind.EMBEDDED | 'embedded';
26
- } & EmbeddedTypeDef<Target> & EmbeddedOptions & PropertyOptions<Owner>) | ({
26
+ } & EmbeddedTypeDef<Target> & EmbeddedOptions<Owner, Target> & PropertyOptions<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>;
@@ -55,7 +55,7 @@ export declare class EntitySchema<Entity = any, Base = never> {
55
55
  addVersion(name: EntityKey<Entity>, type: TypeType, options?: PropertyOptions<Entity>): void;
56
56
  addPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: PrimaryKeyOptions<Entity>): void;
57
57
  addSerializedPrimaryKey(name: EntityKey<Entity>, type: TypeType, options?: SerializedPrimaryKeyOptions<Entity>): void;
58
- addEmbedded<Target = AnyEntity>(name: EntityKey<Entity>, options: EmbeddedOptions): void;
58
+ addEmbedded<Target = AnyEntity>(name: EntityKey<Entity>, options: EmbeddedOptions<Entity, Target>): void;
59
59
  addManyToOne<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToOneOptions<Entity, Target>): void;
60
60
  addManyToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: ManyToManyOptions<Entity, Target>): void;
61
61
  addOneToMany<Target = AnyEntity>(name: EntityKey<Entity>, type: TypeType, options: OneToManyOptions<Entity, Target>): void;
@@ -75,5 +75,7 @@ export declare class EntitySchema<Entity = any, Base = never> {
75
75
  private initPrimaryKeys;
76
76
  private normalizeType;
77
77
  private createProperty;
78
+ private rename;
79
+ private renameCompositeOptions;
78
80
  }
79
81
  export {};
@@ -37,23 +37,7 @@ class EntitySchema {
37
37
  return schema;
38
38
  }
39
39
  addProperty(name, type, options = {}) {
40
- const rename = (data, from, to) => {
41
- if (from in options && !(to in options)) {
42
- // @ts-ignore
43
- options[to] = [options[from]];
44
- // @ts-ignore
45
- delete options[from];
46
- }
47
- };
48
- if (name !== options.name) {
49
- utils_1.Utils.renameKey(options, 'name', 'fieldName');
50
- }
51
- rename(options, 'fieldName', 'fieldNames');
52
- rename(options, 'ref', 'ref');
53
- rename(options, 'joinColumn', 'joinColumns');
54
- rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
55
- rename(options, 'referenceColumnName', 'referencedColumnNames');
56
- rename(options, 'columnType', 'columnTypes');
40
+ this.renameCompositeOptions(name, options);
57
41
  const prop = { name, kind: enums_1.ReferenceKind.SCALAR, ...options, type: this.normalizeType(options, type) };
58
42
  if (type && types_1.Type.isMappedType(type.prototype)) {
59
43
  prop.type = type;
@@ -97,6 +81,7 @@ class EntitySchema {
97
81
  this.addProperty(name, type, options);
98
82
  }
99
83
  addEmbedded(name, options) {
84
+ this.renameCompositeOptions(name, options);
100
85
  utils_1.Utils.defaultValue(options, 'prefix', true);
101
86
  if (options.array) {
102
87
  options.object = true; // force object mode for arrays
@@ -292,5 +277,26 @@ class EntitySchema {
292
277
  ...options,
293
278
  };
294
279
  }
280
+ rename(data, from, to) {
281
+ if (from in data && !(to in data)) {
282
+ // @ts-ignore
283
+ data[to] = [data[from]];
284
+ // @ts-ignore
285
+ delete data[from];
286
+ }
287
+ }
288
+ renameCompositeOptions(name, options = {}) {
289
+ if (name !== options.name && !options.fieldNames) {
290
+ utils_1.Utils.renameKey(options, 'name', 'fieldName');
291
+ }
292
+ else if (options.name && (options.fieldNames?.length ?? 0) > 1) {
293
+ delete options.name;
294
+ }
295
+ this.rename(options, 'fieldName', 'fieldNames');
296
+ this.rename(options, 'joinColumn', 'joinColumns');
297
+ this.rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
298
+ this.rename(options, 'referenceColumnName', 'referencedColumnNames');
299
+ this.rename(options, 'columnType', 'columnTypes');
300
+ }
295
301
  }
296
302
  exports.EntitySchema = EntitySchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.15-dev.1",
3
+ "version": "6.4.15-dev.2",
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.3.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.15-dev.1",
67
+ "mikro-orm": "6.4.15-dev.2",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }