Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-07-12 18:13:23 +0300
committerGar <wraithgar@github.com>2022-07-12 21:35:40 +0300
commit18ddc57c7a54165d55c81b413ef9de981c790148 (patch)
tree395df7070f0fda07e658a2a2b074b3c3cba5c566
parentc94919dd4874196d3a84eff4fab450a17dcd4867 (diff)
deps: just-diff-apply@5.3.1
-rw-r--r--node_modules/just-diff-apply/index.d.ts2
-rw-r--r--node_modules/just-diff-apply/index.mjs69
-rw-r--r--node_modules/just-diff-apply/package.json2
-rw-r--r--package-lock.json7
4 files changed, 64 insertions, 16 deletions
diff --git a/node_modules/just-diff-apply/index.d.ts b/node_modules/just-diff-apply/index.d.ts
index 9fc05257a..7547b722f 100644
--- a/node_modules/just-diff-apply/index.d.ts
+++ b/node_modules/just-diff-apply/index.d.ts
@@ -1,6 +1,6 @@
// Definitions by: Eddie Atkinson <https://github.com/eddie-atkinson>
-type Operation = "add" | "replace" | "remove";
+type Operation = "add" | "replace" | "remove" | "move";
type DiffOps = Array<{
op: Operation;
diff --git a/node_modules/just-diff-apply/index.mjs b/node_modules/just-diff-apply/index.mjs
index 045830507..adc5f46ed 100644
--- a/node_modules/just-diff-apply/index.mjs
+++ b/node_modules/just-diff-apply/index.mjs
@@ -42,6 +42,7 @@
var REMOVE = 'remove';
var REPLACE = 'replace';
var ADD = 'add';
+var MOVE = 'move';
function diffApply(obj, diff, pathConverter) {
if (!obj || typeof obj != 'object') {
@@ -57,23 +58,40 @@ function diffApply(obj, diff, pathConverter) {
var thisDiff = diff[i];
var subObject = obj;
var thisOp = thisDiff.op;
- var thisPath = thisDiff.path;
- if (pathConverter) {
- thisPath = pathConverter(thisPath);
- if (!Array.isArray(thisPath)) {
- throw new Error('pathConverter must return an array');
+
+ var thisPath = transformPath(pathConverter, thisDiff.path);
+ var thisFromPath = thisDiff.from && transformPath(pathConverter, thisDiff.from);
+ var toPath, toPathCopy, lastToProp, subToObject, valueToMove;
+
+ if (thisFromPath) {
+ // MOVE only, "fromPath" is effectively path and "path" is toPath
+ toPath = thisPath;
+ thisPath = thisFromPath;
+
+ toPathCopy = toPath.slice();
+ lastToProp = toPathCopy.pop();
+ prototypeCheck(lastToProp);
+ if (lastToProp == null) {
+ return false;
}
- } else {
- if (!Array.isArray(thisPath)) {
- throw new Error('diff path must be an array, consider supplying a path converter');
+
+ var thisToProp;
+ while (((thisToProp = toPathCopy.shift())) != null) {
+ prototypeCheck(thisToProp);
+ if (!(thisToProp in subToObject)) {
+ subToObject[thisToProp] = {};
+ }
+ subToObject = subToObject[thisToProp];
}
}
+
var pathCopy = thisPath.slice();
var lastProp = pathCopy.pop();
prototypeCheck(lastProp);
if (lastProp == null) {
return false;
}
+
var thisProp;
while (((thisProp = pathCopy.shift())) != null) {
prototypeCheck(thisProp);
@@ -82,21 +100,50 @@ function diffApply(obj, diff, pathConverter) {
}
subObject = subObject[thisProp];
}
- if (thisOp === REMOVE || thisOp === REPLACE) {
+ if (thisOp === REMOVE || thisOp === REPLACE || thisOp === MOVE) {
+ var path = thisOp === MOVE ? thisDiff.from : thisDiff.path;
if (!subObject.hasOwnProperty(lastProp)) {
- throw new Error(['expected to find property', thisDiff.path, 'in object', obj].join(' '));
+ throw new Error(['expected to find property', path, 'in object', obj].join(' '));
}
}
- if (thisOp === REMOVE) {
+ if (thisOp === REMOVE || thisOp === MOVE) {
+ if (thisOp === MOVE) {
+ valueToMove = subObject[lastProp];
+ }
Array.isArray(subObject) ? subObject.splice(lastProp, 1) : delete subObject[lastProp];
}
if (thisOp === REPLACE || thisOp === ADD) {
subObject[lastProp] = thisDiff.value;
}
+
+ if (thisOp === MOVE) {
+ subObject[lastToProp] = valueToMove;
+ }
}
return subObject;
}
+function transformPath(pathConverter, thisPath) {
+ if(pathConverter) {
+ thisPath = pathConverter(thisPath);
+ if(!Array.isArray(thisPath)) {
+ throw new Error([
+ 'pathConverter must return an array, returned:',
+ thisPath,
+ ].join(' '));
+ }
+ } else {
+ if(!Array.isArray(thisPath)) {
+ throw new Error([
+ 'diff path',
+ thisPath,
+ 'must be an array, consider supplying a path converter']
+ .join(' '));
+ }
+ }
+ return thisPath;
+}
+
function jsonPatchPathConverter(stringPath) {
return stringPath.split('/').slice(1);
}
diff --git a/node_modules/just-diff-apply/package.json b/node_modules/just-diff-apply/package.json
index b8e5012ff..b2f80b73a 100644
--- a/node_modules/just-diff-apply/package.json
+++ b/node_modules/just-diff-apply/package.json
@@ -1,6 +1,6 @@
{
"name": "just-diff-apply",
- "version": "5.2.0",
+ "version": "5.3.1",
"description": "Apply a diff to an object. Optionally supports jsonPatch protocol",
"main": "index.js",
"module": "index.mjs",
diff --git a/package-lock.json b/package-lock.json
index b19e31040..e2c6397e9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4396,9 +4396,10 @@
"inBundle": true
},
"node_modules/just-diff-apply": {
- "version": "5.2.0",
- "inBundle": true,
- "license": "MIT"
+ "version": "5.3.1",
+ "resolved": "https://registry.npmjs.org/just-diff-apply/-/just-diff-apply-5.3.1.tgz",
+ "integrity": "sha512-dgFenZnMsc1xGNqgdtgnh7DK+Oy352CE3VZLbzcbQpsBs9iI2K3M0IRrdgREZ72eItTjbl0suRyvKRdVQa9GbA==",
+ "inBundle": true
},
"node_modules/lcov-parse": {
"version": "1.0.0",