@mikro-orm/core 7.2.2-dev.3 → 7.2.2-dev.30

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/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.2.2-dev.3';
156
+ static #ORM_VERSION = '7.2.2-dev.30';
157
157
  /** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
158
158
  static getRlsSettingName(filterName, argName) {
159
159
  return `mikro.${filterName}.${argName}`;
@@ -1,6 +1,7 @@
1
1
  import type { EntityData, EntityKey, EntityMetadata, FilterQuery } from '../typings.js';
2
2
  import type { UpsertOptions } from '../drivers/IDatabaseDriver.js';
3
3
  import { type Raw } from '../utils/RawQueryFragment.js';
4
+ import type { Platform } from '../platforms/Platform.js';
4
5
  /** @internal */
5
6
  export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T>): (keyof T)[];
6
7
  /**
@@ -12,7 +13,7 @@ export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefin
12
13
  */
13
14
  export declare function getOnCreateGeneratedFields<T extends object>(meta: EntityMetadata<T>, data: T | EntityData<T>): EntityKey<T>[];
14
15
  /** @internal */
15
- export declare function getOnConflictReturningFields<T, P extends string>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T, P>): (keyof T)[] | '*';
16
+ export declare function getOnConflictReturningFields<T, P extends string>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T, P>, platform?: Platform): (keyof T)[] | '*';
16
17
  /** @internal */
17
18
  export declare function getWhereCondition<T extends object>(meta: EntityMetadata<T>, onConflictFields: (keyof T)[] | Raw | undefined, data: EntityData<T>, where: FilterQuery<T>): {
18
19
  where: FilterQuery<T>;
@@ -89,11 +89,15 @@ export function getOnCreateGeneratedFields(meta, data) {
89
89
  .map(prop => prop.name);
90
90
  }
91
91
  /** @internal */
92
- export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
92
+ export function getOnConflictReturningFields(meta, data, uniqueFields, options, platform) {
93
93
  /* v8 ignore next */
94
94
  if (!meta) {
95
95
  return '*';
96
96
  }
97
+ // props with explicit `returning` hint are reloaded even when supplied, as the database might normalize them
98
+ const returning = platform?.usesReturningStatement() || platform?.usesOutputStatement()
99
+ ? meta.props.filter(p => p.returning).map(p => p.name)
100
+ : [];
97
101
  const keys = meta.comparableProps
98
102
  .filter(p => {
99
103
  if (p.lazy || p.embeddable) {
@@ -112,17 +116,17 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
112
116
  keys.push(meta.versionProperty);
113
117
  }
114
118
  if (options.onConflictAction === 'ignore') {
115
- return keys;
119
+ return Utils.unique([...keys, ...returning]);
116
120
  }
117
121
  if (options.onConflictMergeFields) {
118
122
  const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
119
- return keys.filter(key => !onConflictMergeFields.includes(key));
123
+ return Utils.unique([...keys.filter(key => !onConflictMergeFields.includes(key)), ...returning]);
120
124
  }
121
125
  if (options.onConflictExcludeFields) {
122
126
  const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
123
- return [...new Set(keys.concat(...onConflictExcludeFields))];
127
+ return Utils.unique([...keys, ...onConflictExcludeFields, ...returning]);
124
128
  }
125
- return keys.filter(key => !(key in data));
129
+ return Utils.unique([...keys.filter(key => !(key in data)), ...returning]);
126
130
  }
127
131
  function getPropertyValue(obj, key) {
128
132
  if (!key.includes('.')) {