@mikro-orm/core 7.0.2-dev.10 → 7.0.2-dev.11

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.
@@ -1612,8 +1612,9 @@ export class MetadataDiscovery {
1612
1612
  !prop.customType) {
1613
1613
  // if the type is an ORM defined mapped type without `ensureComparable: true`,
1614
1614
  // we use just the type name, to have more performant hydration code
1615
+ const brand = Type.getOrmType(prop.type);
1615
1616
  const type = Utils.keys(t).find(type => {
1616
- return !Type.getType(t[type]).ensureComparable(meta, prop) && prop.type === t[type];
1617
+ return (!Type.getType(t[type]).ensureComparable(meta, prop) && (prop.type === t[type] || brand === type));
1617
1618
  });
1618
1619
  if (type) {
1619
1620
  prop.type = type === 'datetime' ? 'Date' : type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.2-dev.10",
3
+ "version": "7.0.2-dev.11",
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",
package/types/Type.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { Platform } from '../platforms/Platform.js';
2
2
  import type { Constructor, EntityMetadata, EntityProperty } from '../typings.js';
3
+ /** @internal */
4
+ export declare const ORM_TYPE: unique symbol;
3
5
  export interface TransformContext {
4
6
  fromQuery?: boolean;
5
7
  force?: boolean;
@@ -78,4 +80,10 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
78
80
  * Checks whether the argument is instance of `Type`.
79
81
  */
80
82
  static isMappedType(data: any): data is Type<any>;
83
+ /**
84
+ * @internal
85
+ * Returns the built-in type registry key if the given constructor is a branded ORM type
86
+ * (not a user subclass). Uses `Symbol.for()` so it works across CJS/ESM module graphs.
87
+ */
88
+ static getOrmType(cls: object): string | undefined;
81
89
  }
package/types/Type.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { inspect } from '../logging/inspect.js';
2
+ /** @internal */
3
+ export const ORM_TYPE = Symbol.for('@mikro-orm/type');
2
4
  export class Type {
3
5
  static types = new Map();
4
6
  platform;
@@ -64,6 +66,14 @@ export class Type {
64
66
  static isMappedType(data) {
65
67
  return !!data?.__mappedType;
66
68
  }
69
+ /**
70
+ * @internal
71
+ * Returns the built-in type registry key if the given constructor is a branded ORM type
72
+ * (not a user subclass). Uses `Symbol.for()` so it works across CJS/ESM module graphs.
73
+ */
74
+ static getOrmType(cls) {
75
+ return Object.hasOwn(cls, ORM_TYPE) ? cls[ORM_TYPE] : undefined;
76
+ }
67
77
  /** @ignore */
68
78
  [Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
69
79
  const object = { ...this };
package/types/index.js CHANGED
@@ -19,7 +19,7 @@ import { StringType } from './StringType.js';
19
19
  import { TextType } from './TextType.js';
20
20
  import { TimeType } from './TimeType.js';
21
21
  import { TinyIntType } from './TinyIntType.js';
22
- import { Type } from './Type.js';
22
+ import { ORM_TYPE, Type } from './Type.js';
23
23
  import { Uint8ArrayType } from './Uint8ArrayType.js';
24
24
  import { UnknownType } from './UnknownType.js';
25
25
  import { UuidType } from './UuidType.js';
@@ -51,3 +51,13 @@ export const types = {
51
51
  unknown: UnknownType,
52
52
  };
53
53
  export const t = types;
54
+ /**
55
+ * Brand each built-in type constructor with its registry key via a cross-module symbol.
56
+ * Symbol.for() returns the same symbol across CJS/ESM module graphs, so this survives
57
+ * the dual-package hazard (e.g. when using tsx or @swc-node/register with "type": "commonjs").
58
+ * Using Object.defineProperty ensures the brand is an own (non-inherited) property,
59
+ * so subclasses (e.g. MyJsonType extends JsonType) won't be detected as built-in types.
60
+ */
61
+ for (const [key, type] of Object.entries(types)) {
62
+ Object.defineProperty(type, ORM_TYPE, { value: key, enumerable: false });
63
+ }
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.2-dev.10';
126
+ static #ORM_VERSION = '7.0.2-dev.11';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */