@mikro-orm/core 7.2.11-dev.4 → 7.2.11-dev.6

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.11-dev.4",
3
+ "version": "7.2.11-dev.6",
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",
@@ -249,7 +249,7 @@ export class UnitOfWork {
249
249
  /** Attempts to extract a primary key from the where condition and look up the entity in the identity map. */
250
250
  tryGetById(entityName, where, schema, strict = true, convertCustomTypes) {
251
251
  const pk = Utils.extractPK(where, this.#metadata.find(entityName), strict);
252
- if (!pk) {
252
+ if (pk == null) {
253
253
  return null;
254
254
  }
255
255
  return this.getById(entityName, pk, schema, convertCustomTypes);
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.11-dev.4';
156
+ static #ORM_VERSION = '7.2.11-dev.6';
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}`;
@@ -335,23 +335,55 @@ export class Utils {
335
335
  }
336
336
  let depth = 0;
337
337
  let end = start;
338
+ let paramStart = start + 1;
339
+ const params = [];
340
+ let quote;
338
341
  for (; end < source.length; end++) {
339
- if (source[end] === '(') {
342
+ if (quote) {
343
+ if (source[end] === '\\') {
344
+ end++;
345
+ }
346
+ else if (source[end] === quote) {
347
+ quote = undefined;
348
+ }
349
+ continue;
350
+ }
351
+ const commentEnd = source.startsWith('/*', end) ? '*/' : source.startsWith('//', end) ? '\n' : undefined;
352
+ if (commentEnd) {
353
+ const close = source.indexOf(commentEnd, end + 2);
354
+ end = close === -1 ? source.length : close + commentEnd.length - 1;
355
+ continue;
356
+ }
357
+ // a slash that does not follow an operand starts a regex literal
358
+ if (source[end] === '/' && !/[\w$)\]]\s*$/.test(source.slice(start, end))) {
359
+ const regex = /\/(?:\\.|\[(?:\\.|[^\]\\])*\]|[^/\\[\n])+\//y;
360
+ regex.lastIndex = end;
361
+ end += (regex.exec(source)?.[0].length ?? 1) - 1;
362
+ continue;
363
+ }
364
+ if (`'"\``.includes(source[end])) {
365
+ quote = source[end];
366
+ continue;
367
+ }
368
+ if ('([{'.includes(source[end])) {
340
369
  depth++;
341
370
  }
342
- if (source[end] === ')') {
371
+ if (')]}'.includes(source[end])) {
343
372
  depth--;
344
373
  }
345
374
  if (depth === 0) {
346
375
  break;
347
376
  }
377
+ if (depth === 1 && source[end] === ',') {
378
+ params.push(source.slice(paramStart, end));
379
+ paramStart = end + 1;
380
+ }
348
381
  }
349
- const raw = source.slice(start + 1, end);
350
- return raw
351
- .split(',')
352
- .map(s => s.trim().replace(/=.*$/, '').trim())
382
+ params.push(source.slice(paramStart, end));
383
+ return params
384
+ .map(s => s.replace(/\/\*.*?\*\/|\/\/[^\n]*/gs, '').trim())
353
385
  .filter(Boolean)
354
- .map(raw => (raw.startsWith('{') && raw.endsWith('}') ? '' : raw));
386
+ .map(raw => (/^[{[]/.test(raw) ? '' : raw.replace(/=.*$/s, '').trim()));
355
387
  }
356
388
  /**
357
389
  * Checks whether the argument looks like primary key (string, number or ObjectId).