@mikro-orm/core 7.2.7-dev.10 → 7.2.7-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.7-dev.10",
3
+ "version": "7.2.7-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",
@@ -3,7 +3,7 @@ import { DANGEROUS_PROPERTY_NAMES, Utils } from './Utils.js';
3
3
  import { ARRAY_OPERATORS, GroupOperator, JSON_KEY_OPERATORS, ReferenceKind } from '../enums.js';
4
4
  import { JsonType } from '../types/JsonType.js';
5
5
  import { helper } from '../entity/wrap.js';
6
- import { isRaw, Raw } from './RawQueryFragment.js';
6
+ import { isRaw, isSubquery, Raw } from './RawQueryFragment.js';
7
7
  import { MetadataError, ValidationError } from '../errors.js';
8
8
  /** @internal */
9
9
  export class QueryHelper {
@@ -458,7 +458,8 @@ export class QueryHelper {
458
458
  if (Array.isArray(cond) && !(key && ARRAY_OPERATORS.includes(key))) {
459
459
  return cond.map(v => QueryHelper.processCustomType(prop, v, platform, key, fromQuery));
460
460
  }
461
- if (isRaw(cond)) {
461
+ // a query builder renders as a sub-query, not as a value of the property type
462
+ if (isRaw(cond) || isSubquery(cond)) {
462
463
  return cond;
463
464
  }
464
465
  return prop.customType.convertToDatabaseValue(cond, platform, { fromQuery, key, mode: 'query' });
@@ -1,11 +1,15 @@
1
- import type { AnyString, Dictionary, EntityKey } from '../typings.js';
1
+ import type { AnyString, Dictionary, EntityKey, Subquery } from '../typings.js';
2
2
  declare const rawFragmentSymbolBrand: unique symbol;
3
3
  /** Branded symbol type used as a unique key for tracking raw SQL fragments in object properties. */
4
4
  export type RawQueryFragmentSymbol = symbol & {
5
5
  readonly [rawFragmentSymbolBrand]: true;
6
6
  };
7
+ /** Prototype brand of query builders usable as sub-queries; a symbol so JSON payloads cannot carry it, `Symbol.for` so package copies agree. */
8
+ export declare const SUBQUERY_BRAND: unique symbol;
7
9
  /** Checks whether the given value is a `RawQueryFragment` instance. */
8
10
  export declare function isRaw(value: unknown): value is RawQueryFragment;
11
+ /** Checks whether the given value is a query builder usable as a sub-query (its prototype carries the `SUBQUERY_BRAND`). */
12
+ export declare function isSubquery(value: unknown): value is Subquery;
9
13
  /** Represents a raw SQL fragment with optional parameters, usable as both a value and an object key via Symbol coercion. */
10
14
  export declare class RawQueryFragment<Alias extends string = string> {
11
15
  #private;
@@ -1,11 +1,6 @@
1
1
  import { Utils } from './Utils.js';
2
- // Brand lives on the prototype so JSON payloads — whose proto is
3
- // `Object.prototype` — cannot forge it. String key, not a `Symbol.for(...)`,
4
- // so each CJS/ESM copy of this module independently installs it on its own
5
- // prototype without publishing a global key for the marker that controls raw
6
- // SQL assembly. The string is namespaced so it does not collide with property
7
- // names users might independently install on their own prototypes.
8
- const RAW_FRAGMENT_BRAND = '__mikroOrmRawFragment';
2
+ // Prototype brand of raw fragments; `Symbol.for` so package copies agree.
3
+ const RAW_FRAGMENT_BRAND = Symbol.for('mikro-orm.raw-fragment');
9
4
  // Back-references from a fragment's symbol key to the fragment itself, shared
10
5
  // across CJS/ESM module copies via globalThis: when one copy creates a fragment
11
6
  // via `raw('…')` and stores its symbol in a where-clause object key, the other
@@ -13,6 +8,20 @@ const RAW_FRAGMENT_BRAND = '__mikroOrmRawFragment';
13
8
  const REGISTRY_KEY = Symbol.for('@mikro-orm/core/RawQueryFragment.references');
14
9
  const rawQueryReferences = (globalThis[REGISTRY_KEY] ??=
15
10
  new WeakMap());
11
+ /** Prototype brand of query builders usable as sub-queries; a symbol so JSON payloads cannot carry it, `Symbol.for` so package copies agree. */
12
+ export const SUBQUERY_BRAND = Symbol.for('mikro-orm.subquery');
13
+ function hasPrototypeBrand(value, brand) {
14
+ // Walk the prototype chain starting from the *prototype* (not the value) so
15
+ // own-property spoofing from JSON payloads cannot forge the brand. Stop at
16
+ // `Object.prototype`, which is never branded — that bails plain objects,
17
+ // JSON payloads, and built-ins like `Date`/`Array`/`Map` at depth 1.
18
+ for (let p = Object.getPrototypeOf(value); p != null && p !== Object.prototype; p = Object.getPrototypeOf(p)) {
19
+ if (Object.hasOwn(p, brand)) {
20
+ return true;
21
+ }
22
+ }
23
+ return false;
24
+ }
16
25
  /** Checks whether the given value is a `RawQueryFragment` instance. */
17
26
  export function isRaw(value) {
18
27
  if (value == null || typeof value !== 'object') {
@@ -23,16 +32,11 @@ export function isRaw(value) {
23
32
  if (value instanceof RawQueryFragment) {
24
33
  return true;
25
34
  }
26
- // Walk the prototype chain starting from the *prototype* (not the value) so
27
- // own-property spoofing from JSON payloads cannot forge the brand. Stop at
28
- // `Object.prototype`, which is never branded — that bails plain objects,
29
- // JSON payloads, and built-ins like `Date`/`Array`/`Map` at depth 1.
30
- for (let p = Object.getPrototypeOf(value); p != null && p !== Object.prototype; p = Object.getPrototypeOf(p)) {
31
- if (Object.hasOwn(p, RAW_FRAGMENT_BRAND)) {
32
- return true;
33
- }
34
- }
35
- return false;
35
+ return hasPrototypeBrand(value, RAW_FRAGMENT_BRAND);
36
+ }
37
+ /** Checks whether the given value is a query builder usable as a sub-query (its prototype carries the `SUBQUERY_BRAND`). */
38
+ export function isSubquery(value) {
39
+ return value != null && typeof value === 'object' && hasPrototypeBrand(value, SUBQUERY_BRAND);
36
40
  }
37
41
  /** Represents a raw SQL fragment with optional parameters, usable as both a value and an object key via Symbol coercion. */
38
42
  export class RawQueryFragment {
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.7-dev.10';
156
+ static #ORM_VERSION = '7.2.7-dev.11';
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}`;