@mikro-orm/core 6.3.13 → 6.3.14-dev.1

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,9 +1,12 @@
1
1
  import type { AnyEntity } from '../typings';
2
2
  export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
3
+ /** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
4
+ export type EmbeddedPrefixMode = 'absolute' | 'relative';
3
5
  export type EmbeddedOptions = {
4
6
  entity?: string | (() => AnyEntity | AnyEntity[]);
5
7
  type?: string;
6
8
  prefix?: string | boolean;
9
+ prefixMode?: EmbeddedPrefixMode;
7
10
  nullable?: boolean;
8
11
  object?: boolean;
9
12
  array?: boolean;
@@ -63,6 +63,7 @@ export declare class MetadataDiscovery {
63
63
  private initRelation;
64
64
  private initColumnType;
65
65
  private getMappedType;
66
+ private getPrefix;
66
67
  private initUnsigned;
67
68
  private initIndexes;
68
69
  private getEntityClassOrSchema;
@@ -797,11 +797,8 @@ class MetadataDiscovery {
797
797
  const parentProperty = meta.properties[embeddedProp.embedded?.[0] ?? ''];
798
798
  const object = isParentObject(embeddedProp);
799
799
  this.initFieldName(embeddedProp, rootProperty !== embeddedProp && object);
800
- const prefix = embeddedProp.prefix === false
801
- ? (parentProperty?.prefix || '')
802
- : embeddedProp.prefix === true
803
- ? embeddedProp.embeddedPath?.join('_') ?? embeddedProp.fieldNames[0] + '_'
804
- : embeddedProp.prefix;
800
+ // the prefix of the parent can not be a boolean; it already passed here
801
+ const prefix = this.getPrefix(embeddedProp, parentProperty);
805
802
  for (const prop of Object.values(embeddable.properties)) {
806
803
  const name = (embeddedProp.embeddedPath?.join('_') ?? embeddedProp.fieldNames[0] + '_') + prop.name;
807
804
  meta.properties[name] = Utils_1.Utils.copy(prop, false);
@@ -1231,6 +1228,18 @@ class MetadataDiscovery {
1231
1228
  }
1232
1229
  return this.platform.getMappedType(t);
1233
1230
  }
1231
+ getPrefix(prop, parent) {
1232
+ const { embeddedPath = [], fieldNames, prefix = true, prefixMode } = prop;
1233
+ if (prefix === true) {
1234
+ return (embeddedPath.length ? embeddedPath.join('_') : fieldNames[0]) + '_';
1235
+ }
1236
+ const prefixParent = parent ? this.getPrefix(parent, null) : '';
1237
+ if (prefix === false) {
1238
+ return prefixParent;
1239
+ }
1240
+ const mode = prefixMode ?? this.config.get('embeddables').prefixMode;
1241
+ return mode === 'absolute' ? prefix : prefixParent + prefix;
1242
+ }
1234
1243
  initUnsigned(prop) {
1235
1244
  if (prop.unsigned != null) {
1236
1245
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.3.13",
3
+ "version": "6.3.14-dev.1",
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.3.13",
67
+ "mikro-orm": "6.3.14-dev.1",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/typings.d.ts CHANGED
@@ -7,6 +7,7 @@ import type { Type, types } from './types';
7
7
  import type { Platform } from './platforms';
8
8
  import type { Configuration } from './utils';
9
9
  import type { EntityManager } from './EntityManager';
10
+ import type { EmbeddedPrefixMode } from './decorators/Embedded';
10
11
  import type { EventSubscriber } from './events';
11
12
  import type { FindOneOptions, FindOptions, LoadHint } from './drivers';
12
13
  export type Constructor<T = unknown> = new (...args: any[]) => T;
@@ -319,6 +320,7 @@ export interface EntityProperty<Owner = any, Target = any> {
319
320
  defaultRaw?: string;
320
321
  formula?: (alias: string) => string;
321
322
  prefix?: string | boolean;
323
+ prefixMode?: EmbeddedPrefixMode;
322
324
  embedded?: [EntityKey<Owner>, EntityKey<Owner>];
323
325
  embeddedPath?: string[];
324
326
  embeddable: EntityClass<Owner>;
@@ -1,7 +1,7 @@
1
1
  import type { NamingStrategy } from '../naming-strategy';
2
2
  import { FileCacheAdapter, type SyncCacheAdapter, type CacheAdapter } from '../cache';
3
3
  import type { EntityRepository } from '../entity/EntityRepository';
4
- import type { AnyEntity, Constructor, Dictionary, EntityClass, EntityClassGroup, FilterDef, Highlighter, HydratorConstructor, IHydrator, IMigrationGenerator, IPrimaryKey, MaybePromise, MigrationObject, EntityMetadata, EnsureDatabaseOptions, GenerateOptions } from '../typings';
4
+ import type { AnyEntity, Constructor, Dictionary, EntityClass, EntityClassGroup, FilterDef, Highlighter, HydratorConstructor, IHydrator, IMigrationGenerator, IPrimaryKey, MaybePromise, MigrationObject, EntityMetadata, EnsureDatabaseOptions, GenerateOptions, Migration } from '../typings';
5
5
  import { ObjectHydrator } from '../hydration';
6
6
  import { NullHighlighter } from '../utils/NullHighlighter';
7
7
  import { type Logger, type LoggerNamespace, type LoggerOptions } from '../logging';
@@ -11,6 +11,7 @@ import type { EntitySchema } from '../metadata/EntitySchema';
11
11
  import type { MetadataProvider } from '../metadata/MetadataProvider';
12
12
  import type { MetadataStorage } from '../metadata/MetadataStorage';
13
13
  import { ReflectMetadataProvider } from '../metadata/ReflectMetadataProvider';
14
+ import type { EmbeddedPrefixMode } from '../decorators/Embedded';
14
15
  import type { EventSubscriber } from '../events';
15
16
  import type { AssignOptions } from '../entity/EntityAssigner';
16
17
  import type { EntityManagerType, IDatabaseDriver } from '../drivers/IDatabaseDriver';
@@ -97,6 +98,9 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
97
98
  createForeignKeyConstraints: true;
98
99
  ignoreSchema: never[];
99
100
  };
101
+ embeddables: {
102
+ prefixMode: "absolute";
103
+ };
100
104
  entityGenerator: {
101
105
  bidirectionalRelations: false;
102
106
  identifiedReferences: false;
@@ -253,7 +257,7 @@ export type MigrationsOptions = {
253
257
  emit?: 'js' | 'ts' | 'cjs';
254
258
  generator?: Constructor<IMigrationGenerator>;
255
259
  fileName?: (timestamp: string, name?: string) => string;
256
- migrationsList?: MigrationObject[];
260
+ migrationsList?: (MigrationObject | Constructor<Migration>)[];
257
261
  };
258
262
  export interface SeederOptions {
259
263
  path?: string;
@@ -367,6 +371,9 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
367
371
  ignoreSchema?: string[];
368
372
  managementDbName?: string;
369
373
  };
374
+ embeddables: {
375
+ prefixMode: EmbeddedPrefixMode;
376
+ };
370
377
  entityGenerator: GenerateOptions;
371
378
  metadataCache: {
372
379
  enabled?: boolean;
@@ -92,6 +92,9 @@ class Configuration {
92
92
  createForeignKeyConstraints: true,
93
93
  ignoreSchema: [],
94
94
  },
95
+ embeddables: {
96
+ prefixMode: 'absolute',
97
+ },
95
98
  entityGenerator: {
96
99
  bidirectionalRelations: false,
97
100
  identifiedReferences: false,