@mikro-orm/core 6.6.1-dev.1 → 6.6.1-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
@@ -383,6 +383,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
383
383
 
384
384
  Please ⭐️ this repository if this project helped you!
385
385
 
386
+ > If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
387
+
386
388
  ## 📝 License
387
389
 
388
390
  Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
@@ -1057,7 +1057,7 @@ class MetadataDiscovery {
1057
1057
  return '1';
1058
1058
  }
1059
1059
  inferDefaultValue(meta, prop) {
1060
- if (!meta.class || !this.config.get('discovery').inferDefaultValues) {
1060
+ if (!meta.class) {
1061
1061
  return;
1062
1062
  }
1063
1063
  try {
@@ -1066,7 +1066,7 @@ class MetadataDiscovery {
1066
1066
  const entity1 = new meta.class();
1067
1067
  const entity2 = new meta.class();
1068
1068
  // we compare the two values by reference, this will discard things like `new Date()` or `Date.now()`
1069
- if (prop.default === undefined && entity1[prop.name] != null && entity1[prop.name] === entity2[prop.name] && entity1[prop.name] !== now) {
1069
+ if (this.config.get('discovery').inferDefaultValues && prop.default === undefined && entity1[prop.name] != null && entity1[prop.name] === entity2[prop.name] && entity1[prop.name] !== now) {
1070
1070
  prop.default ??= entity1[prop.name];
1071
1071
  }
1072
1072
  // if the default value is null, infer nullability
@@ -1134,8 +1134,18 @@ class MetadataDiscovery {
1134
1134
  }
1135
1135
  // `prop.type` might also be custom type class (not instance), so `typeof MyType` will give us `function`, not `object`
1136
1136
  if (typeof prop.type === 'function' && types_1.Type.isMappedType(prop.type.prototype) && !prop.customType) {
1137
- prop.customType = new prop.type();
1138
- prop.type = prop.customType.constructor.name;
1137
+ // if the type is an ORM defined mapped type without `ensureComparable: true`,
1138
+ // we use just the type name, to have more performant hydration code
1139
+ const type = Utils_1.Utils.keys(types_1.t).find(type => {
1140
+ return !types_1.Type.getType(types_1.t[type]).ensureComparable(meta, prop) && prop.type === types_1.t[type];
1141
+ });
1142
+ if (type) {
1143
+ prop.type = type === 'datetime' ? 'Date' : type;
1144
+ }
1145
+ else {
1146
+ prop.customType = new prop.type();
1147
+ prop.type = prop.customType.constructor.name;
1148
+ }
1139
1149
  }
1140
1150
  if (simple) {
1141
1151
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.1-dev.1",
3
+ "version": "6.6.1-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.3.2",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.6.1-dev.1",
67
+ "mikro-orm": "6.6.1-dev.10",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -4,6 +4,5 @@ import type { EntityProperty } from '../typings';
4
4
  export declare class BlobType extends Uint8ArrayType {
5
5
  convertToJSValue(value: Buffer): Buffer | null;
6
6
  compareAsType(): string;
7
- ensureComparable(): boolean;
8
7
  getColumnType(prop: EntityProperty, platform: Platform): string;
9
8
  }
package/types/BlobType.js CHANGED
@@ -17,9 +17,6 @@ class BlobType extends Uint8ArrayType_1.Uint8ArrayType {
17
17
  compareAsType() {
18
18
  return 'Buffer';
19
19
  }
20
- ensureComparable() {
21
- return false;
22
- }
23
20
  getColumnType(prop, platform) {
24
21
  return platform.getBlobDeclarationSQL();
25
22
  }
@@ -4,5 +4,6 @@ import type { EntityProperty } from '../typings';
4
4
  export declare class BooleanType extends Type<boolean | null | undefined, boolean | null | undefined> {
5
5
  getColumnType(prop: EntityProperty, platform: Platform): string;
6
6
  compareAsType(): string;
7
+ convertToJSValue(value: boolean | null | undefined): boolean | null | undefined;
7
8
  ensureComparable(): boolean;
8
9
  }
@@ -9,6 +9,9 @@ class BooleanType extends Type_1.Type {
9
9
  compareAsType() {
10
10
  return 'boolean';
11
11
  }
12
+ convertToJSValue(value) {
13
+ return Boolean(value);
14
+ }
12
15
  ensureComparable() {
13
16
  return false;
14
17
  }
@@ -5,6 +5,5 @@ export declare class Uint8ArrayType extends Type<Uint8Array | null> {
5
5
  convertToDatabaseValue(value: Uint8Array): Buffer;
6
6
  convertToJSValue(value: Buffer): Uint8Array | null;
7
7
  compareAsType(): string;
8
- ensureComparable(): boolean;
9
8
  getColumnType(prop: EntityProperty, platform: Platform): string;
10
9
  }
@@ -27,9 +27,6 @@ class Uint8ArrayType extends Type_1.Type {
27
27
  compareAsType() {
28
28
  return 'Buffer';
29
29
  }
30
- ensureComparable() {
31
- return false;
32
- }
33
30
  getColumnType(prop, platform) {
34
31
  return platform.getBlobDeclarationSQL();
35
32
  }
@@ -291,11 +291,22 @@ class ChangeSetPersister {
291
291
  async reloadVersionValues(meta, changeSets, options) {
292
292
  const reloadProps = meta.versionProperty && !this.usesReturningStatement ? [meta.properties[meta.versionProperty]] : [];
293
293
  if (changeSets[0].type === ChangeSet_1.ChangeSetType.CREATE) {
294
- // do not reload things that already had a runtime value
295
- meta.props
296
- .filter(prop => prop.persist !== false && (prop.autoincrement || prop.generated || prop.defaultRaw))
297
- .filter(prop => (changeSets[0].entity[prop.name] == null && prop.defaultRaw !== 'null') || utils_1.Utils.isRawSql(changeSets[0].entity[prop.name]))
298
- .forEach(prop => reloadProps.push(prop));
294
+ for (const prop of meta.props) {
295
+ if (prop.persist === false) {
296
+ continue;
297
+ }
298
+ if (utils_1.Utils.isRawSql(changeSets[0].entity[prop.name])) {
299
+ reloadProps.push(prop);
300
+ continue;
301
+ }
302
+ // do not reload things that already had a runtime value
303
+ if (changeSets[0].entity[prop.name] != null || prop.defaultRaw === 'null') {
304
+ continue;
305
+ }
306
+ if (prop.autoincrement || prop.generated || prop.defaultRaw) {
307
+ reloadProps.push(prop);
308
+ }
309
+ }
299
310
  }
300
311
  if (changeSets[0].type === ChangeSet_1.ChangeSetType.UPDATE) {
301
312
  const returning = new Set();
@@ -1,4 +1,4 @@
1
- import type { EntityData, EntityDictionary, EntityMetadata, EntityProperty, IMetadataStorage } from '../typings';
1
+ import type { EntityData, EntityDictionary, EntityMetadata, EntityName, EntityProperty, IMetadataStorage } from '../typings';
2
2
  import type { Platform } from '../platforms';
3
3
  type Comparator<T> = (a: T, b: T, options?: {
4
4
  includeInverseSides?: boolean;
@@ -48,7 +48,7 @@ export declare class EntityComparator {
48
48
  /**
49
49
  * @internal Highly performance-sensitive method.
50
50
  */
51
- getSnapshotGenerator<T>(entityName: string): SnapshotGenerator<T>;
51
+ getSnapshotGenerator<T>(entityName: EntityName<T>): SnapshotGenerator<T>;
52
52
  /**
53
53
  * @internal
54
54
  */
@@ -202,6 +202,7 @@ class EntityComparator {
202
202
  * @internal Highly performance-sensitive method.
203
203
  */
204
204
  getSnapshotGenerator(entityName) {
205
+ entityName = Utils_1.Utils.className(entityName);
205
206
  const exists = this.snapshotGenerators.get(entityName);
206
207
  if (exists) {
207
208
  return exists;