cry-synced-db-client 0.1.164 → 0.1.165
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 +18 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -562,6 +562,14 @@ function isTerminalBracketKey(path) {
|
|
|
562
562
|
const last = tokens[tokens.length - 1];
|
|
563
563
|
return !!(last && last.length >= 2 && last.charCodeAt(0) === 91 && last.charCodeAt(last.length - 1) === 93);
|
|
564
564
|
}
|
|
565
|
+
function canExpandArrayToBrackets(value) {
|
|
566
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
567
|
+
for (const el of value) {
|
|
568
|
+
if (el === null || typeof el !== "object") return false;
|
|
569
|
+
if (el._id == null) return false;
|
|
570
|
+
}
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
565
573
|
function mergeDirtyPath(accumulated, newPath, newValue) {
|
|
566
574
|
for (const existingKey of Object.keys(accumulated)) {
|
|
567
575
|
if (existingKey === newPath) continue;
|
|
@@ -575,7 +583,16 @@ function mergeDirtyPath(accumulated, newPath, newValue) {
|
|
|
575
583
|
if (existingIsTerminal && Array.isArray(existingValue) && existingValue.length === 1) {
|
|
576
584
|
mutationTarget = existingValue[0];
|
|
577
585
|
}
|
|
578
|
-
|
|
586
|
+
if (!existingIsTerminal && newPath[existingKey.length] === "[" && canExpandArrayToBrackets(existingValue)) {
|
|
587
|
+
delete accumulated[existingKey];
|
|
588
|
+
for (const el of existingValue) {
|
|
589
|
+
accumulated[`${existingKey}[${String(el._id)}]`] = [el];
|
|
590
|
+
}
|
|
591
|
+
mergeDirtyPath(accumulated, newPath, newValue);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const sepChar = newPath[existingKey.length];
|
|
595
|
+
const relativePath = sepChar === "[" ? newPath.substring(existingKey.length) : newPath.substring(existingKey.length + 1);
|
|
579
596
|
const ok = setByPath(mutationTarget, relativePath, newValue);
|
|
580
597
|
if (ok) return;
|
|
581
598
|
break;
|