Skip to content

Commit

Permalink
3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Starcounter-Jack committed Mar 24, 2022
1 parent d7903fb commit e4f4eb3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 41 deletions.
21 changes: 10 additions & 11 deletions commonjs/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports._areEquals = exports.validate = exports.validator = exports.applyReducer = exports.applyPatch = exports.applyOperation = exports.getValueByPointer = exports.deepClone = exports.JsonPatchError = void 0;
var helpers_js_1 = require("./helpers.js");
exports.JsonPatchError = helpers_js_1.PatchError;
exports.deepClone = helpers_js_1._deepClone;
Expand Down Expand Up @@ -31,7 +30,7 @@ var objOps = {
and is potentially unneeded */
var removed = getValueByPointer(document, this.path);
if (removed) {
removed = (0, helpers_js_1._deepClone)(removed);
removed = helpers_js_1._deepClone(removed);
}
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
applyOperation(document, { op: "add", path: this.path, value: originalValue });
Expand All @@ -40,7 +39,7 @@ var objOps = {
copy: function (obj, key, document) {
var valueToCopy = getValueByPointer(document, this.from);
// enforce copy by value so further operations don't affect source (see issue #177)
applyOperation(document, { op: "add", path: this.path, value: (0, helpers_js_1._deepClone)(valueToCopy) });
applyOperation(document, { op: "add", path: this.path, value: helpers_js_1._deepClone(valueToCopy) });
return { newDocument: document };
},
test: function (obj, key, document) {
Expand All @@ -54,7 +53,7 @@ var objOps = {
/* The operations applicable to an array. Many are the same as for the object */
var arrOps = {
add: function (arr, i, document) {
if ((0, helpers_js_1.isInteger)(i)) {
if (helpers_js_1.isInteger(i)) {
arr.splice(i, 0, this.value);
}
else { // array props
Expand Down Expand Up @@ -168,7 +167,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
} /* END ROOT OPERATIONS */
else {
if (!mutateDocument) {
document = (0, helpers_js_1._deepClone)(document);
document = helpers_js_1._deepClone(document);
}
var path = operation.path || "";
var keys = path.split('/');
Expand All @@ -187,7 +186,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
while (true) {
key = keys[t];
if (key && key.indexOf('~') != -1) {
key = (0, helpers_js_1.unescapePathComponent)(key);
key = helpers_js_1.unescapePathComponent(key);
}
if (banPrototypeModifications &&
(key == '__proto__' ||
Expand All @@ -213,10 +212,10 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
key = obj.length;
}
else {
if (validateOperation && !(0, helpers_js_1.isInteger)(key)) {
if (validateOperation && !helpers_js_1.isInteger(key)) {
throw new exports.JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
} // only parse key when it's an integer for `arr.prop` to work
else if ((0, helpers_js_1.isInteger)(key)) {
else if (helpers_js_1.isInteger(key)) {
key = ~~key;
}
}
Expand Down Expand Up @@ -273,7 +272,7 @@ function applyPatch(document, patch, validateOperation, mutateDocument, banProto
}
}
if (!mutateDocument) {
document = (0, helpers_js_1._deepClone)(document);
document = helpers_js_1._deepClone(document);
}
var results = new Array(patch.length);
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
Expand Down Expand Up @@ -329,7 +328,7 @@ function validator(operation, index, document, existingPathFragment) {
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
}
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && (0, helpers_js_1.hasUndefined)(operation.value)) {
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_js_1.hasUndefined(operation.value)) {
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
}
else if (document) {
Expand Down Expand Up @@ -369,7 +368,7 @@ function validate(sequence, document, externalValidator) {
}
if (document) {
//clone document and sequence so that we can safely try applying operations
applyPatch((0, helpers_js_1._deepClone)(document), (0, helpers_js_1._deepClone)(sequence), externalValidator || true);
applyPatch(helpers_js_1._deepClone(document), helpers_js_1._deepClone(sequence), externalValidator || true);
}
else {
externalValidator = externalValidator || validator;
Expand Down
25 changes: 12 additions & 13 deletions commonjs/duplex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.compare = exports.generate = exports.observe = exports.unobserve = void 0;
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017-2021 Joachim Wester
Expand Down Expand Up @@ -57,7 +56,7 @@ function observe(obj, callback) {
return observer;
}
observer = {};
mirror.value = (0, helpers_js_1._deepClone)(obj);
mirror.value = helpers_js_1._deepClone(obj);
if (callback) {
observer.callback = callback;
observer.next = null;
Expand Down Expand Up @@ -102,7 +101,7 @@ function generate(observer, invertible) {
var mirror = beforeDict.get(observer.object);
_generate(mirror.value, observer.object, observer.patches, "", invertible);
if (observer.patches.length) {
(0, core_js_1.applyPatch)(mirror.value, observer.patches);
core_js_1.applyPatch(mirror.value, observer.patches);
}
var temp = observer.patches;
if (temp.length > 0) {
Expand All @@ -122,34 +121,34 @@ function _generate(mirror, obj, patches, path, invertible) {
if (typeof obj.toJSON === "function") {
obj = obj.toJSON();
}
var newKeys = (0, helpers_js_1._objectKeys)(obj);
var oldKeys = (0, helpers_js_1._objectKeys)(mirror);
var newKeys = helpers_js_1._objectKeys(obj);
var oldKeys = helpers_js_1._objectKeys(mirror);
var changed = false;
var deleted = false;
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
for (var t = oldKeys.length - 1; t >= 0; t--) {
var key = oldKeys[t];
var oldVal = mirror[key];
if ((0, helpers_js_1.hasOwnProperty)(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
if (helpers_js_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
var newVal = obj[key];
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
_generate(oldVal, newVal, patches, path + "/" + (0, helpers_js_1.escapePathComponent)(key), invertible);
_generate(oldVal, newVal, patches, path + "/" + helpers_js_1.escapePathComponent(key), invertible);
}
else {
if (oldVal !== newVal) {
changed = true;
if (invertible) {
patches.push({ op: "test", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(oldVal) });
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
}
patches.push({ op: "replace", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(newVal) });
patches.push({ op: "replace", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(newVal) });
}
}
}
else if (Array.isArray(mirror) === Array.isArray(obj)) {
if (invertible) {
patches.push({ op: "test", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(oldVal) });
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
}
patches.push({ op: "remove", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key) });
patches.push({ op: "remove", path: path + "/" + helpers_js_1.escapePathComponent(key) });
deleted = true; // property has been deleted
}
else {
Expand All @@ -165,8 +164,8 @@ function _generate(mirror, obj, patches, path, invertible) {
}
for (var t = 0; t < newKeys.length; t++) {
var key = newKeys[t];
if (!(0, helpers_js_1.hasOwnProperty)(mirror, key) && obj[key] !== undefined) {
patches.push({ op: "add", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(obj[key]) });
if (!helpers_js_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) {
patches.push({ op: "add", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(obj[key]) });
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions commonjs/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.PatchError = exports.hasUndefined = exports.getPath = exports._getPathRecursive = exports.unescapePathComponent = exports.escapePathComponent = exports.isInteger = exports._deepClone = exports._objectKeys = exports.hasOwnProperty = void 0;
var _hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwnProperty(obj, key) {
return _hasOwnProperty.call(obj, key);
Expand Down Expand Up @@ -125,7 +122,7 @@ function getPath(root, obj) {
if (path === '') {
throw new Error("Object not found in root");
}
return "/".concat(path);
return "/" + path;
}
exports.getPath = getPath;
/**
Expand Down Expand Up @@ -161,7 +158,7 @@ function patchErrorMessageFormatter(message, args) {
for (var key in args) {
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
if (typeof value !== 'undefined') {
messageParts.push("".concat(key, ": ").concat(value));
messageParts.push(key + ": " + value);
}
}
return messageParts.join('\n');
Expand Down
2 changes: 1 addition & 1 deletion dist/fast-json-patch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! fast-json-patch, version: 3.1.0 */
/*! fast-json-patch, version: 3.1.1 */
var jsonpatch =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down
2 changes: 1 addition & 1 deletion dist/fast-json-patch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions module/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down Expand Up @@ -116,7 +114,7 @@ export function getPath(root, obj) {
if (path === '') {
throw new Error("Object not found in root");
}
return "/".concat(path);
return "/" + path;
}
/**
* Recursively checks whether an object has any undefined values inside.
Expand Down Expand Up @@ -150,7 +148,7 @@ function patchErrorMessageFormatter(message, args) {
for (var key in args) {
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
if (typeof value !== 'undefined') {
messageParts.push("".concat(key, ": ").concat(value));
messageParts.push(key + ": " + value);
}
}
return messageParts.join('\n');
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-json-patch",
"version": "3.1.0",
"version": "3.1.1",
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",
"homepage": "https://github.com/Starcounter-Jack/JSON-Patch",
"keywords": [
Expand Down Expand Up @@ -62,4 +62,4 @@
"bench-core": "node test/spec/coreBenchmark.js",
"bench-duplex": "node test/spec/coreBenchmark.js && node test/spec/duplexBenchmark.js"
}
}
}

0 comments on commit e4f4eb3

Please sign in to comment.