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 +46 -12
- package/dist/index.mjs +46 -12
- package/package.json +1 -1
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
|
|
387
|
-
const allSingleKey =
|
|
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 =
|
|
390
|
-
const allSameKey =
|
|
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
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
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
|
|
337
|
-
const allSingleKey =
|
|
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 =
|
|
340
|
-
const allSameKey =
|
|
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
|
|
344
|
-
const
|
|
345
|
-
if (
|
|
346
|
-
|
|
347
|
-
|
|
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
|
}
|