@mikro-orm/core 7.1.15-dev.10 → 7.1.15-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.
@@ -19,6 +19,8 @@ export declare class ObjectHydrator extends Hydrator {
19
19
  getEntityHydrator<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference', normalizeAccessors?: boolean): EntityHydrator<T>;
20
20
  private createCollectionItemMapper;
21
21
  private wrap;
22
+ /** Renders a key as a single-quoted JS string literal, safe to embed in generated code. */
23
+ private quote;
22
24
  private safeKey;
23
25
  }
24
26
  export {};
@@ -87,7 +87,7 @@ export class ObjectHydrator extends Hydrator {
87
87
  ret.push(` if (data${dataKey} === null) {`);
88
88
  if (prop.ref) {
89
89
  ret.push(` entity${entityKey} = new ScalarReference();`);
90
- ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
90
+ ret.push(` entity${entityKey}.bind(entity, ${this.quote(prop.name)});`);
91
91
  ret.push(` entity${entityKey}.set(${nullVal});`);
92
92
  }
93
93
  else {
@@ -127,14 +127,14 @@ export class ObjectHydrator extends Hydrator {
127
127
  if (prop.ref) {
128
128
  ret.push(` const value = isScalarReference(entity${entityKey}) ? entity${entityKey}.unwrap() : entity${entityKey};`);
129
129
  ret.push(` entity${entityKey} = oldValue_${idx} ?? new ScalarReference(value);`);
130
- ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
130
+ ret.push(` entity${entityKey}.bind(entity, ${this.quote(prop.name)});`);
131
131
  ret.push(` entity${entityKey}.set(value);`);
132
132
  }
133
133
  ret.push(` }`);
134
134
  if (prop.ref) {
135
135
  ret.push(` if (!entity${entityKey}) {`);
136
136
  ret.push(` entity${entityKey} = new ScalarReference();`);
137
- ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
137
+ ret.push(` entity${entityKey}.bind(entity, ${this.quote(prop.name)});`);
138
138
  ret.push(` }`);
139
139
  }
140
140
  return ret;
@@ -220,7 +220,7 @@ export class ObjectHydrator extends Hydrator {
220
220
  ret.push(` }`);
221
221
  ret.push(` if (Array.isArray(data${dataKey})) {`);
222
222
  ret.push(` const items = data${dataKey}.map(value => createCollectionItem_${this.safeKey(prop.name)}(value, entity));`);
223
- ret.push(` const coll = Collection.create(entity, '${prop.name}', items, newEntity);`);
223
+ ret.push(` const coll = Collection.create(entity, ${this.quote(prop.name)}, items, newEntity);`);
224
224
  ret.push(` if (newEntity) {`);
225
225
  ret.push(` coll.setDirty();`);
226
226
  ret.push(` } else {`);
@@ -231,11 +231,11 @@ export class ObjectHydrator extends Hydrator {
231
231
  if (!this.platform.usesPivotTable() && prop.owner && prop.kind === ReferenceKind.MANY_TO_MANY) {
232
232
  ret.push(` } else if (!entity${entityKey} && Array.isArray(data${dataKey})) {`);
233
233
  const items = this.platform.usesPivotTable() || !prop.owner ? 'undefined' : '[]';
234
- ret.push(` const coll = Collection.create(entity, '${prop.name}', ${items}, !!data${dataKey} || newEntity);`);
234
+ ret.push(` const coll = Collection.create(entity, ${this.quote(prop.name)}, ${items}, !!data${dataKey} || newEntity);`);
235
235
  ret.push(` coll.setDirty(false);`);
236
236
  }
237
237
  ret.push(` } else if (!entity${entityKey}) {`);
238
- ret.push(` const coll = Collection.create(entity, '${prop.name}', undefined, newEntity);`);
238
+ ret.push(` const coll = Collection.create(entity, ${this.quote(prop.name)}, undefined, newEntity);`);
239
239
  ret.push(` coll.setDirty(false);`);
240
240
  ret.push(` }`);
241
241
  return ret;
@@ -431,10 +431,14 @@ export class ObjectHydrator extends Hydrator {
431
431
  return lines;
432
432
  }
433
433
  wrap(key) {
434
- if (/^\[.*]$/.exec(key)) {
434
+ if (/^\[idx_\d+]$/.exec(key)) {
435
435
  return key;
436
436
  }
437
- return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
437
+ return /^\w+$/.exec(key) ? `.${key}` : `[${this.quote(key)}]`;
438
+ }
439
+ /** Renders a key as a single-quoted JS string literal, safe to embed in generated code. */
440
+ quote(key) {
441
+ return `'${key.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
438
442
  }
439
443
  safeKey(key) {
440
444
  return key.replace(/\W/g, '_');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.15-dev.10",
3
+ "version": "7.1.15-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",
@@ -80,6 +80,8 @@ export declare class EntityComparator {
80
80
  private getGenericComparator;
81
81
  private getPropertyComparator;
82
82
  private wrap;
83
+ /** Renders a key as a single-quoted JS string literal, safe to embed in generated code. */
84
+ private quote;
83
85
  private safeKey;
84
86
  /**
85
87
  * Sets the toArray helper in the context if not already set.
@@ -758,10 +758,14 @@ export class EntityComparator {
758
758
  return this.getGenericComparator(this.wrap(prop.name), `!equals(last${this.wrap(prop.name)}, current${this.wrap(prop.name)})`);
759
759
  }
760
760
  wrap(key) {
761
- if (/^\[.*]$/.exec(key)) {
761
+ if (/^\[idx_\d+]$/.exec(key)) {
762
762
  return key;
763
763
  }
764
- return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
764
+ return /^\w+$/.exec(key) ? `.${key}` : `[${this.quote(key)}]`;
765
+ }
766
+ /** Renders a key as a single-quoted JS string literal, safe to embed in generated code. */
767
+ quote(key) {
768
+ return `'${key.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
765
769
  }
766
770
  safeKey(key) {
767
771
  return key.replace(/\W/g, '_');
package/utils/Utils.js CHANGED
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
153
153
  /** Collection of general-purpose utility methods used throughout the ORM. */
154
154
  export class Utils {
155
155
  static PK_SEPARATOR = '~~~';
156
- static #ORM_VERSION = '7.1.15-dev.10';
156
+ static #ORM_VERSION = '7.1.15-dev.11';
157
157
  /**
158
158
  * Checks if the argument is instance of `Object`. Returns false for arrays.
159
159
  */