@mikro-orm/core 7.0.9-dev.9 → 7.0.10-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.
package/MikroORM.js CHANGED
@@ -173,7 +173,6 @@ export class MikroORM {
173
173
  this.em = this.driver.createEntityManager();
174
174
  this.em.global = true;
175
175
  this.#metadata.decorate(this.em);
176
- this.driver.setMetadata(this.#metadata);
177
176
  }
178
177
  /**
179
178
  * Allows dynamically discovering new entity by reference, handy for testing schema diffing.
@@ -3,7 +3,7 @@ import type { ConnectionType, Constructor, Dictionary, EntityData, EntityDiction
3
3
  import type { MetadataStorage } from '../metadata/MetadataStorage.js';
4
4
  import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
5
5
  import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
6
- import { EntityComparator } from '../utils/EntityComparator.js';
6
+ import type { EntityComparator } from '../utils/EntityComparator.js';
7
7
  import { type QueryOrder } from '../enums.js';
8
8
  import type { Platform } from '../platforms/Platform.js';
9
9
  import type { Collection } from '../entity/Collection.js';
@@ -1,7 +1,6 @@
1
1
  import { EntityManagerType, } from './IDatabaseDriver.js';
2
2
  import { Utils } from '../utils/Utils.js';
3
3
  import { Cursor } from '../utils/Cursor.js';
4
- import { EntityComparator } from '../utils/EntityComparator.js';
5
4
  import { isRaw, raw } from '../utils/RawQueryFragment.js';
6
5
  import { QueryOrderNumeric, ReferenceKind } from '../enums.js';
7
6
  import { EntityManager } from '../EntityManager.js';
@@ -103,7 +102,7 @@ export class DatabaseDriver {
103
102
  /** Sets the metadata storage and initializes the comparator for all connections. */
104
103
  setMetadata(metadata) {
105
104
  this.metadata = metadata;
106
- this.comparator = new EntityComparator(this.metadata, this.platform);
105
+ this.comparator = this.config.getComparator(metadata);
107
106
  this.connection.setMetadata(metadata);
108
107
  this.connection.setPlatform(this.platform);
109
108
  this.replicas.forEach(replica => {
@@ -310,7 +309,7 @@ export class DatabaseDriver {
310
309
  if (prop.joinColumns && Array.isArray(data[k])) {
311
310
  const copy = Utils.flatten(data[k]);
312
311
  delete data[k];
313
- prop.joinColumns.forEach((joinColumn, idx) => (data[joinColumn] = copy[idx]));
312
+ (prop.ownColumns ?? prop.joinColumns).forEach(col => (data[col] = copy[prop.joinColumns.indexOf(col)]));
314
313
  return;
315
314
  }
316
315
  if (prop.joinColumns?.length > 1 && data[k] == null) {
@@ -167,9 +167,11 @@ export class EntityFactory {
167
167
  return diff2[key] === undefined;
168
168
  })
169
169
  .forEach(key => delete diff2[key]);
170
- // but always add collection properties and formulas if they are part of the `data`
170
+ // but always add collection properties, formulas, and generated columns if they are part of the `data`,
171
+ // as these are excluded from `comparableProps` and won't appear in the diff
171
172
  Utils.keys(data)
172
173
  .filter(key => meta.properties[key]?.formula ||
174
+ (meta.properties[key]?.generated && !meta.properties[key]?.primary) ||
173
175
  [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(meta.properties[key]?.kind))
174
176
  .forEach(key => (diff2[key] = data[key]));
175
177
  // rehydrated with the new values, skip those changed by user
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.9-dev.9",
3
+ "version": "7.0.10-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",
@@ -323,14 +323,47 @@ export class Platform {
323
323
  }
324
324
  /** Serializes a string array into its database storage format. */
325
325
  marshallArray(values) {
326
- return values.join(',');
326
+ return values.map(v => (/[,",\\]/.test(v) ? JSON.stringify(v) : v)).join(',');
327
327
  }
328
328
  /** Deserializes a database-stored array string back into a string array. */
329
329
  unmarshallArray(value) {
330
330
  if (value === '') {
331
331
  return [];
332
332
  }
333
- return value.split(',');
333
+ if (!value.includes('"')) {
334
+ return value.split(',');
335
+ }
336
+ const result = [];
337
+ let i = 0;
338
+ while (i < value.length) {
339
+ if (value[i] === '"') {
340
+ let j = i + 1;
341
+ while (j < value.length) {
342
+ if (value[j] === '\\') {
343
+ j += 2;
344
+ }
345
+ else if (value[j] === '"') {
346
+ j++;
347
+ break;
348
+ }
349
+ else {
350
+ j++;
351
+ }
352
+ }
353
+ result.push(JSON.parse(value.substring(i, j)));
354
+ i = j + 1;
355
+ }
356
+ else {
357
+ const comma = value.indexOf(',', i);
358
+ if (comma === -1) {
359
+ result.push(value.substring(i));
360
+ break;
361
+ }
362
+ result.push(value.substring(i, comma));
363
+ i = comma + 1;
364
+ }
365
+ }
366
+ return result;
334
367
  }
335
368
  getBlobDeclarationSQL() {
336
369
  return 'blob';
package/utils/Utils.js CHANGED
@@ -132,7 +132,7 @@ export function parseJsonSafe(value) {
132
132
  /** Collection of general-purpose utility methods used throughout the ORM. */
133
133
  export class Utils {
134
134
  static PK_SEPARATOR = '~~~';
135
- static #ORM_VERSION = '7.0.9-dev.9';
135
+ static #ORM_VERSION = '7.0.10-dev.0';
136
136
  /**
137
137
  * Checks if the argument is instance of `Object`. Returns false for arrays.
138
138
  */