av6-core 1.5.13 → 1.5.14

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/dist/index.js CHANGED
@@ -375,6 +375,30 @@ function smartAndMerge(a, b) {
375
375
  if (merged !== void 0) return merged;
376
376
  return andWrap(a, b);
377
377
  }
378
+ var SCALAR_OPS = /* @__PURE__ */ new Set([
379
+ "equals",
380
+ "in",
381
+ "notIn",
382
+ "lt",
383
+ "lte",
384
+ "gt",
385
+ "gte",
386
+ "contains",
387
+ "startsWith",
388
+ "endsWith",
389
+ "mode",
390
+ "search",
391
+ "not"
392
+ ]);
393
+ var RELATION_OPS = /* @__PURE__ */ new Set(["some", "every", "none", "is", "isNot"]);
394
+ function isScalarFilterObject(obj) {
395
+ if (!isPlainObject(obj)) return false;
396
+ return Object.keys(obj).some((k) => SCALAR_OPS.has(k));
397
+ }
398
+ function isRelationFilterObject(obj) {
399
+ if (!isPlainObject(obj)) return false;
400
+ return Object.keys(obj).some((k) => RELATION_OPS.has(k));
401
+ }
378
402
  function normalizeWhere(where) {
379
403
  if (Array.isArray(where)) return where.map(normalizeWhere);
380
404
  if (!isPlainObject(where)) return where;
@@ -383,23 +407,33 @@ function normalizeWhere(where) {
383
407
  }
384
408
  if (Array.isArray(where.OR) && where.OR.length > 0) {
385
409
  const orItems = where.OR;
386
- const keys = orItems.map((it) => isPlainObject(it) ? Object.keys(it) : []);
387
- const allSingleKey = keys.every((k) => k.length === 1);
410
+ const keysArr = orItems.map((it) => isPlainObject(it) ? Object.keys(it) : []);
411
+ const allSingleKey = keysArr.every((ks) => ks.length === 1);
388
412
  if (allSingleKey) {
389
- const commonKey = keys[0][0];
390
- const allSameKey = keys.every((k) => k[0] === commonKey);
413
+ const commonKey = keysArr[0][0];
414
+ const allSameKey = keysArr.every((ks) => ks[0] === commonKey);
391
415
  const isLogicalKey = commonKey === "AND" || commonKey === "OR" || commonKey === "NOT";
392
416
  if (allSameKey && !isLogicalKey) {
393
- const inner = orItems.map((it) => it[commonKey]).filter((v) => isPlainObject(v));
394
- const foldedRel = { OR: inner };
395
- if (isPlainObject(where[commonKey])) {
396
- where[commonKey] = { ...where[commonKey], ...foldedRel };
397
- if (Array.isArray(where[commonKey].OR) && Array.isArray(foldedRel.OR)) {
417
+ const innerList = orItems.map((it) => it[commonKey]).filter((v) => isPlainObject(v));
418
+ const anyScalar = innerList.some(isScalarFilterObject);
419
+ if (!anyScalar) {
420
+ const shouldFold = innerList.some(isRelationFilterObject) || innerList.some(
421
+ (o) => Object.keys(o).some((k) => !SCALAR_OPS.has(k) && k !== "AND" && k !== "OR" && k !== "NOT")
422
+ );
423
+ if (shouldFold) {
424
+ const foldedRel = { OR: innerList };
425
+ if (isPlainObject(where[commonKey])) {
426
+ if (Array.isArray(where[commonKey].OR)) {
427
+ where[commonKey].OR = [...where[commonKey].OR, ...innerList];
428
+ } else {
429
+ where[commonKey] = { ...where[commonKey], ...foldedRel };
430
+ }
431
+ } else {
432
+ where[commonKey] = foldedRel;
433
+ }
434
+ delete where.OR;
398
435
  }
399
- } else {
400
- where[commonKey] = foldedRel;
401
436
  }
402
- delete where.OR;
403
437
  }
404
438
  }
405
439
  }
package/dist/index.mjs CHANGED
@@ -325,6 +325,30 @@ function smartAndMerge(a, b) {
325
325
  if (merged !== void 0) return merged;
326
326
  return andWrap(a, b);
327
327
  }
328
+ var SCALAR_OPS = /* @__PURE__ */ new Set([
329
+ "equals",
330
+ "in",
331
+ "notIn",
332
+ "lt",
333
+ "lte",
334
+ "gt",
335
+ "gte",
336
+ "contains",
337
+ "startsWith",
338
+ "endsWith",
339
+ "mode",
340
+ "search",
341
+ "not"
342
+ ]);
343
+ var RELATION_OPS = /* @__PURE__ */ new Set(["some", "every", "none", "is", "isNot"]);
344
+ function isScalarFilterObject(obj) {
345
+ if (!isPlainObject(obj)) return false;
346
+ return Object.keys(obj).some((k) => SCALAR_OPS.has(k));
347
+ }
348
+ function isRelationFilterObject(obj) {
349
+ if (!isPlainObject(obj)) return false;
350
+ return Object.keys(obj).some((k) => RELATION_OPS.has(k));
351
+ }
328
352
  function normalizeWhere(where) {
329
353
  if (Array.isArray(where)) return where.map(normalizeWhere);
330
354
  if (!isPlainObject(where)) return where;
@@ -333,23 +357,33 @@ function normalizeWhere(where) {
333
357
  }
334
358
  if (Array.isArray(where.OR) && where.OR.length > 0) {
335
359
  const orItems = where.OR;
336
- const keys = orItems.map((it) => isPlainObject(it) ? Object.keys(it) : []);
337
- const allSingleKey = keys.every((k) => k.length === 1);
360
+ const keysArr = orItems.map((it) => isPlainObject(it) ? Object.keys(it) : []);
361
+ const allSingleKey = keysArr.every((ks) => ks.length === 1);
338
362
  if (allSingleKey) {
339
- const commonKey = keys[0][0];
340
- const allSameKey = keys.every((k) => k[0] === commonKey);
363
+ const commonKey = keysArr[0][0];
364
+ const allSameKey = keysArr.every((ks) => ks[0] === commonKey);
341
365
  const isLogicalKey = commonKey === "AND" || commonKey === "OR" || commonKey === "NOT";
342
366
  if (allSameKey && !isLogicalKey) {
343
- const inner = orItems.map((it) => it[commonKey]).filter((v) => isPlainObject(v));
344
- const foldedRel = { OR: inner };
345
- if (isPlainObject(where[commonKey])) {
346
- where[commonKey] = { ...where[commonKey], ...foldedRel };
347
- if (Array.isArray(where[commonKey].OR) && Array.isArray(foldedRel.OR)) {
367
+ const innerList = orItems.map((it) => it[commonKey]).filter((v) => isPlainObject(v));
368
+ const anyScalar = innerList.some(isScalarFilterObject);
369
+ if (!anyScalar) {
370
+ const shouldFold = innerList.some(isRelationFilterObject) || innerList.some(
371
+ (o) => Object.keys(o).some((k) => !SCALAR_OPS.has(k) && k !== "AND" && k !== "OR" && k !== "NOT")
372
+ );
373
+ if (shouldFold) {
374
+ const foldedRel = { OR: innerList };
375
+ if (isPlainObject(where[commonKey])) {
376
+ if (Array.isArray(where[commonKey].OR)) {
377
+ where[commonKey].OR = [...where[commonKey].OR, ...innerList];
378
+ } else {
379
+ where[commonKey] = { ...where[commonKey], ...foldedRel };
380
+ }
381
+ } else {
382
+ where[commonKey] = foldedRel;
383
+ }
384
+ delete where.OR;
348
385
  }
349
- } else {
350
- where[commonKey] = foldedRel;
351
386
  }
352
- delete where.OR;
353
387
  }
354
388
  }
355
389
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.5.13",
3
+ "version": "1.5.14",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",