@mikro-orm/core 7.0.4-dev.9 → 7.0.5-dev.0

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.
@@ -122,7 +122,7 @@ export class ObjectHydrator extends Hydrator {
122
122
  ret.push(` entity${entityKey} = data${dataKey};`);
123
123
  }
124
124
  if (prop.ref) {
125
- ret.push(` const value = entity${entityKey};`);
125
+ ret.push(` const value = entity${entityKey}?.__scalarReference ? entity${entityKey}.unwrap() : entity${entityKey};`);
126
126
  ret.push(` entity${entityKey} = oldValue_${idx} ?? new ScalarReference(value);`);
127
127
  ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
128
128
  ret.push(` entity${entityKey}.set(value);`);
@@ -1484,15 +1484,22 @@ export class MetadataDiscovery {
1484
1484
  }
1485
1485
  if (this.#platform.usesEnumCheckConstraints() && !meta.embeddable) {
1486
1486
  for (const prop of meta.props) {
1487
- if (prop.enum &&
1488
- prop.persist !== false &&
1489
- !prop.nativeEnumName &&
1490
- prop.items?.every(item => typeof item === 'string')) {
1491
- this.initFieldName(prop);
1487
+ if (prop.persist === false || prop.nativeEnumName || !prop.items?.every(item => typeof item === 'string')) {
1488
+ continue;
1489
+ }
1490
+ this.initFieldName(prop);
1491
+ let expression = null;
1492
+ if (prop.enum) {
1493
+ expression = `${this.#platform.quoteIdentifier(prop.fieldNames[0])} in ('${prop.items.join("', '")}')`;
1494
+ }
1495
+ else if (prop.array) {
1496
+ expression = this.#platform.getEnumArrayCheckConstraintExpression(prop.fieldNames[0], prop.items);
1497
+ }
1498
+ if (expression) {
1492
1499
  meta.checks.push({
1493
1500
  name: this.#namingStrategy.indexName(meta.tableName, prop.fieldNames, 'check'),
1494
1501
  property: prop.name,
1495
- expression: `${this.#platform.quoteIdentifier(prop.fieldNames[0])} in ('${prop.items.join("', '")}')`,
1502
+ expression,
1496
1503
  });
1497
1504
  }
1498
1505
  }
@@ -18,9 +18,19 @@ async function getEntityClassOrSchema(filepath, allTargets, baseDir) {
18
18
  }
19
19
  }
20
20
  for (const item of targets) {
21
- const validTarget = EntitySchema.is(item) || (item instanceof Function && MetadataStorage.isKnownEntity(item.name));
22
- if (validTarget && !allTargets.has(item)) {
23
- allTargets.set(item, path);
21
+ if (EntitySchema.is(item)) {
22
+ if (!allTargets.has(item)) {
23
+ allTargets.set(item, path);
24
+ }
25
+ }
26
+ else if (item instanceof Function) {
27
+ const schema = EntitySchema.REGISTRY.get(item);
28
+ if (schema && !allTargets.has(schema)) {
29
+ allTargets.set(schema, path);
30
+ }
31
+ else if (!schema && MetadataStorage.isKnownEntity(item.name) && !allTargets.has(item)) {
32
+ allTargets.set(item, path);
33
+ }
24
34
  }
25
35
  }
26
36
  }
@@ -499,7 +499,7 @@ export interface EmbeddableOptions<Owner> {
499
499
  abstract?: boolean;
500
500
  }
501
501
  export interface EnumOptions<T> extends PropertyOptions<T> {
502
- items?: (number | string)[] | (() => Dictionary);
502
+ items?: readonly (number | string)[] | (() => Dictionary);
503
503
  array?: boolean;
504
504
  /** for postgres, by default it uses text column with check constraint */
505
505
  nativeEnumName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.4-dev.9",
3
+ "version": "7.0.5-dev.0",
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
  "keywords": [
6
6
  "data-mapper",
@@ -37,6 +37,8 @@ export declare abstract class Platform {
37
37
  supportsNativeEnums(): boolean;
38
38
  /** for postgres text enums (default) */
39
39
  usesEnumCheckConstraints(): boolean;
40
+ /** Returns the check constraint expression for an enum array column, or null if unsupported. */
41
+ getEnumArrayCheckConstraintExpression(column: string, items: string[]): string | null;
40
42
  /** Whether this platform supports materialized views. */
41
43
  supportsMaterializedViews(): boolean;
42
44
  /** Returns the schema helper instance for this platform, or undefined if not supported. */
@@ -50,6 +50,10 @@ export class Platform {
50
50
  usesEnumCheckConstraints() {
51
51
  return false;
52
52
  }
53
+ /** Returns the check constraint expression for an enum array column, or null if unsupported. */
54
+ getEnumArrayCheckConstraintExpression(column, items) {
55
+ return null;
56
+ }
53
57
  /** Whether this platform supports materialized views. */
54
58
  supportsMaterializedViews() {
55
59
  return false;
@@ -6,7 +6,7 @@ import type { EntityProperty } from '../typings.js';
6
6
  export declare class EnumArrayType<T extends string | number = string> extends ArrayType<T> {
7
7
  private readonly owner;
8
8
  private readonly items?;
9
- constructor(owner: string, items?: T[] | undefined, hydrate?: (i: string) => T);
9
+ constructor(owner: string, items?: readonly T[] | undefined, hydrate?: (i: string) => T);
10
10
  convertToDatabaseValue(value: T[] | null, platform: Platform, context?: TransformContext): string | null;
11
11
  getColumnType(prop: EntityProperty, platform: Platform): string;
12
12
  }
@@ -525,7 +525,11 @@ export class EntityComparator {
525
525
  }
526
526
  getPropertySnapshot(meta, prop, context, dataKey, entityKey, path, level = 1, object) {
527
527
  const unwrap = prop.ref ? '?.unwrap()' : '';
528
- let ret = ` if (${this.getPropertyCondition(path)}) {\n`;
528
+ let ret = ` if (${this.getPropertyCondition(path)}`;
529
+ if (prop.lazy && prop.ref) {
530
+ ret += ` && entity${path.map(k => this.wrap(k)).join('')}?.isInitialized()`;
531
+ }
532
+ ret += `) {\n`;
529
533
  if (['number', 'string', 'boolean'].includes(prop.type.toLowerCase())) {
530
534
  return ret + ` ret${dataKey} = entity${entityKey}${unwrap};\n }\n`;
531
535
  }
package/utils/Utils.js CHANGED
@@ -129,7 +129,7 @@ export function parseJsonSafe(value) {
129
129
  /** Collection of general-purpose utility methods used throughout the ORM. */
130
130
  export class Utils {
131
131
  static PK_SEPARATOR = '~~~';
132
- static #ORM_VERSION = '7.0.4-dev.9';
132
+ static #ORM_VERSION = '7.0.5-dev.0';
133
133
  /**
134
134
  * Checks if the argument is instance of `Object`. Returns false for arrays.
135
135
  */
@@ -553,7 +553,9 @@ export class Utils {
553
553
  process.execArgv?.some(arg => {
554
554
  return (arg.includes('ts-node') || // check for ts-node loader
555
555
  arg.includes('@swc-node/register') || // check for swc-node/register loader
556
- arg.includes('node_modules/tsx/')); // check for tsx loader
556
+ arg.includes('node_modules/tsx/') || // check for tsx loader
557
+ arg.includes('@oxc-node/core') // check for oxc-node loader
558
+ );
557
559
  }));
558
560
  }
559
561
  /**