@mikro-orm/core 6.4.3-dev.0 → 6.4.3-dev.10

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/README.md CHANGED
@@ -299,13 +299,13 @@ Or if you want to use UUID primary keys:
299
299
  **`./entities/UuidBook.ts`**
300
300
 
301
301
  ```typescript
302
- import { v4 } from 'uuid';
302
+ import { randomUUID } from 'node:crypto';
303
303
 
304
304
  @Entity()
305
305
  export class UuidBook {
306
306
 
307
307
  @PrimaryKey()
308
- uuid = v4();
308
+ uuid = randomUUID();
309
309
 
310
310
  }
311
311
  ```
@@ -13,6 +13,8 @@ export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOp
13
13
  primary?: boolean;
14
14
  /** Map this relation to the primary key value instead of an entity. */
15
15
  mapToPk?: boolean;
16
+ /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
17
+ ownColumns?: string[];
16
18
  /** What to do when the target entity gets deleted. */
17
19
  deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
18
20
  /** What to do when the reference to the target entity gets updated. */
@@ -23,9 +23,13 @@ export interface PropertyOptions<Owner> {
23
23
  */
24
24
  fieldNames?: string[];
25
25
  /**
26
- * Specify exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
26
+ * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is only for simple properties represented by a single column. (SQL only)
27
27
  */
28
28
  columnType?: ColumnType | AnyString;
29
+ /**
30
+ * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is suitable for composite keys, where one property is represented by multiple columns. (SQL only)
31
+ */
32
+ columnTypes?: (ColumnType | AnyString)[];
29
33
  /**
30
34
  * Explicitly specify the runtime type.
31
35
  *
package/errors.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare class OptimisticLockError<T extends AnyEntity = AnyEntity> extend
38
38
  export declare class MetadataError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
39
39
  static fromMissingPrimaryKey(meta: EntityMetadata): MetadataError;
40
40
  static fromWrongReference(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy', owner?: EntityProperty): MetadataError;
41
+ static fromWrongForeignKey(meta: EntityMetadata, prop: EntityProperty, key: string): MetadataError;
41
42
  static fromWrongTypeDefinition(meta: EntityMetadata, prop: EntityProperty): MetadataError;
42
43
  static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError;
43
44
  static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
package/errors.js CHANGED
@@ -138,6 +138,9 @@ class MetadataError extends ValidationError {
138
138
  }
139
139
  return MetadataError.fromMessage(meta, prop, `has unknown '${key}' reference: ${prop.type}.${prop[key]}`);
140
140
  }
141
+ static fromWrongForeignKey(meta, prop, key) {
142
+ return MetadataError.fromMessage(meta, prop, `requires explicit '${key}' option, since the 'joinColumns' are not matching the length.`);
143
+ }
141
144
  static fromWrongTypeDefinition(meta, prop) {
142
145
  if (!prop.type) {
143
146
  return MetadataError.fromMessage(meta, prop, `is missing type definition`);
@@ -364,7 +364,7 @@ class MetadataDiscovery {
364
364
  initOwnColumns(meta) {
365
365
  meta.sync();
366
366
  for (const prop of meta.props) {
367
- if (!prop.joinColumns || prop.ownColumns) {
367
+ if (!prop.joinColumns || !prop.columnTypes || prop.ownColumns || ![enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
368
368
  continue;
369
369
  }
370
370
  if (prop.joinColumns.length > 1) {
@@ -375,6 +375,19 @@ class MetadataDiscovery {
375
375
  if (!prop.ownColumns || prop.ownColumns.length === 0) {
376
376
  prop.ownColumns = prop.joinColumns;
377
377
  }
378
+ if (prop.joinColumns.length !== prop.columnTypes.length) {
379
+ prop.columnTypes = prop.joinColumns.flatMap(field => {
380
+ const matched = meta.props.find(p => p.fieldNames?.includes(field));
381
+ if (matched) {
382
+ return matched.columnTypes;
383
+ }
384
+ /* istanbul ignore next */
385
+ throw errors_1.MetadataError.fromWrongForeignKey(meta, prop, 'columnTypes');
386
+ });
387
+ }
388
+ if (prop.joinColumns.length !== prop.referencedColumnNames.length) {
389
+ throw errors_1.MetadataError.fromWrongForeignKey(meta, prop, 'referencedColumnNames');
390
+ }
378
391
  }
379
392
  }
380
393
  initFieldName(prop, object = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.3-dev.0",
3
+ "version": "6.4.3-dev.10",
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.4.3-dev.0",
67
+ "mikro-orm": "6.4.3-dev.10",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }