@mikro-orm/core 6.3.11-dev.7 → 6.3.11-dev.9

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.
@@ -6,6 +6,7 @@ const Collection_1 = require("../entity/Collection");
6
6
  const Reference_1 = require("../entity/Reference");
7
7
  const Utils_1 = require("../utils/Utils");
8
8
  const enums_1 = require("../enums");
9
+ const RawQueryFragment_1 = require("../utils/RawQueryFragment");
9
10
  class ObjectHydrator extends Hydrator_1.Hydrator {
10
11
  hydrators = {
11
12
  full: new Map(),
@@ -48,6 +49,15 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
48
49
  context.set('isPrimaryKey', Utils_1.Utils.isPrimaryKey);
49
50
  context.set('Collection', Collection_1.Collection);
50
51
  context.set('Reference', Reference_1.Reference);
52
+ const registerCustomType = (prop, convertorKey, method, context) => {
53
+ context.set(`${method}_${convertorKey}`, (val) => {
54
+ if (RawQueryFragment_1.RawQueryFragment.isKnownFragment(val)) {
55
+ return val;
56
+ }
57
+ return prop.customType[method](val, this.platform, { mode: 'serialization' });
58
+ });
59
+ return convertorKey;
60
+ };
51
61
  const hydrateScalar = (prop, object, path, dataKey) => {
52
62
  const entityKey = path.map(k => this.wrap(k)).join('');
53
63
  const tz = this.platform.getTimezone();
@@ -66,8 +76,8 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
66
76
  ret.push(` entity${entityKey} = ${nullVal};`);
67
77
  ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
68
78
  if (prop.customType) {
69
- context.set(`convertToJSValue_${convertorKey}`, (val) => prop.customType.convertToJSValue(val, this.platform));
70
- context.set(`convertToDatabaseValue_${convertorKey}`, (val) => prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'hydration' }));
79
+ registerCustomType(prop, convertorKey, 'convertToJSValue', context);
80
+ registerCustomType(prop, convertorKey, 'convertToDatabaseValue', context);
71
81
  ret.push(` if (convertCustomTypes) {`, ` const value = convertToJSValue_${convertorKey}(data${dataKey});`);
72
82
  if (prop.customType.ensureComparable(meta, prop)) {
73
83
  ret.push(` data${dataKey} = convertToDatabaseValue_${convertorKey}(value);`);
@@ -142,7 +152,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
142
152
  }
143
153
  }
144
154
  if (prop.customType?.ensureComparable(meta, prop)) {
145
- context.set(`convertToDatabaseValue_${this.safeKey(prop.name)}`, (val) => prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'hydration' }));
155
+ registerCustomType(prop, this.safeKey(prop.name), 'convertToDatabaseValue', context);
146
156
  ret.push(` if (data${dataKey} != null && typeof data${dataKey} !== 'object' && convertCustomTypes) {`);
147
157
  ret.push(` data${dataKey} = convertToDatabaseValue_${this.safeKey(prop.name)}(entity${entityKey}.__helper.getPrimaryKey());`);
148
158
  ret.push(` }`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.3.11-dev.7",
3
+ "version": "6.3.11-dev.9",
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.11-dev.7",
67
+ "mikro-orm": "6.3.11-dev.9",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -175,6 +175,7 @@ export declare abstract class Platform {
175
175
  processDateProperty(value: unknown): string | number | Date;
176
176
  quoteIdentifier(id: string, quote?: string): string;
177
177
  quoteValue(value: any): string;
178
+ escape(value: any): string;
178
179
  formatQuery(sql: string, params: readonly any[]): string;
179
180
  cloneEmbeddable<T>(data: T): T;
180
181
  setConfig(config: Configuration): void;
@@ -361,6 +361,9 @@ class Platform {
361
361
  quoteValue(value) {
362
362
  return value;
363
363
  }
364
+ escape(value) {
365
+ return value;
366
+ }
364
367
  formatQuery(sql, params) {
365
368
  if (params.length === 0) {
366
369
  return sql;
@@ -69,6 +69,7 @@ export declare class EntityComparator {
69
69
  */
70
70
  private shouldSerialize;
71
71
  private getEmbeddedPropertySnapshot;
72
+ private registerCustomType;
72
73
  private getPropertySnapshot;
73
74
  /**
74
75
  * @internal Highly performance-sensitive method.
@@ -5,6 +5,7 @@ const clone_1 = require("./clone");
5
5
  const enums_1 = require("../enums");
6
6
  const Utils_1 = require("./Utils");
7
7
  const JsonType_1 = require("../types/JsonType");
8
+ const RawQueryFragment_1 = require("./RawQueryFragment");
8
9
  class EntityComparator {
9
10
  metadata;
10
11
  platform;
@@ -102,8 +103,7 @@ class EntityComparator {
102
103
  }
103
104
  else {
104
105
  if (meta.properties[pk].customType) {
105
- const convertorKey = this.safeKey(pk);
106
- context.set(`convertToDatabaseValue_${convertorKey}`, (val) => meta.properties[pk].customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' }));
106
+ const convertorKey = this.registerCustomType(meta.properties[pk], context);
107
107
  lines.push(` ${pk}: convertToDatabaseValue_${convertorKey}(entity${this.wrap(pk)}),`);
108
108
  }
109
109
  else {
@@ -121,8 +121,7 @@ class EntityComparator {
121
121
  lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) return entity${this.wrap(pk)}.__helper.getPrimaryKey(true);`);
122
122
  }
123
123
  if (meta.properties[pk].customType) {
124
- const convertorKey = this.safeKey(pk);
125
- context.set(`convertToDatabaseValue_${convertorKey}`, (val) => meta.properties[pk].customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' }));
124
+ const convertorKey = this.registerCustomType(meta.properties[pk], context);
126
125
  lines.push(` return convertToDatabaseValue_${convertorKey}(entity${this.wrap(pk)});`);
127
126
  }
128
127
  else {
@@ -414,8 +413,7 @@ class EntityComparator {
414
413
  .split('\n').map(l => padding + l).join('\n');
415
414
  }
416
415
  if (shouldProcessCustomType(childProp)) {
417
- const convertorKey = this.safeKey(childProp.name);
418
- context.set(`convertToDatabaseValue_${convertorKey}`, (val) => childProp.customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' }));
416
+ const convertorKey = this.registerCustomType(childProp, context);
419
417
  if (['number', 'string', 'boolean', 'bigint'].includes(childProp.customType.compareAsType().toLowerCase())) {
420
418
  return `${padding} if (${childCond}) ret${childDataKey} = convertToDatabaseValue_${convertorKey}(entity${childEntityKey});`;
421
419
  }
@@ -428,8 +426,17 @@ class EntityComparator {
428
426
  }
429
427
  return `${ret}${padding}}`;
430
428
  }
431
- getPropertySnapshot(meta, prop, context, dataKey, entityKey, path, level = 1, object) {
429
+ registerCustomType(prop, context) {
432
430
  const convertorKey = this.safeKey(prop.name);
431
+ context.set(`convertToDatabaseValue_${convertorKey}`, (val) => {
432
+ if (RawQueryFragment_1.RawQueryFragment.isKnownFragment(val)) {
433
+ return val;
434
+ }
435
+ return prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' });
436
+ });
437
+ return convertorKey;
438
+ }
439
+ getPropertySnapshot(meta, prop, context, dataKey, entityKey, path, level = 1, object) {
433
440
  const unwrap = prop.ref ? '?.unwrap()' : '';
434
441
  let ret = ` if (${this.getPropertyCondition(path)}) {\n`;
435
442
  if (['number', 'string', 'boolean'].includes(prop.type.toLowerCase())) {
@@ -444,7 +451,7 @@ class EntityComparator {
444
451
  if (prop.kind === enums_1.ReferenceKind.ONE_TO_ONE || prop.kind === enums_1.ReferenceKind.MANY_TO_ONE) {
445
452
  if (prop.mapToPk) {
446
453
  if (prop.customType) {
447
- context.set(`convertToDatabaseValue_${convertorKey}`, (val) => prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' }));
454
+ const convertorKey = this.registerCustomType(prop, context);
448
455
  ret += ` ret${dataKey} = convertToDatabaseValue_${convertorKey}(entity${entityKey});\n`;
449
456
  }
450
457
  else {
@@ -468,7 +475,7 @@ class EntityComparator {
468
475
  return ret + ' }\n';
469
476
  }
470
477
  if (prop.customType) {
471
- context.set(`convertToDatabaseValue_${convertorKey}`, (val) => prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' }));
478
+ const convertorKey = this.registerCustomType(prop, context);
472
479
  if (['number', 'string', 'boolean', 'bigint'].includes(prop.customType.compareAsType().toLowerCase())) {
473
480
  return ret + ` ret${dataKey} = convertToDatabaseValue_${convertorKey}(entity${entityKey}${unwrap});\n }\n`;
474
481
  }