diff --git a/commonjs/core.js b/commonjs/core.js index 921d54f..16ee5bb 100644 --- a/commonjs/core.js +++ b/commonjs/core.js @@ -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; @@ -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 }); @@ -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) { @@ -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 @@ -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('/'); @@ -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__' || @@ -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; } } @@ -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++) { @@ -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) { @@ -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; diff --git a/commonjs/duplex.js b/commonjs/duplex.js index d2d0ebf..88975c6 100644 --- a/commonjs/duplex.js +++ b/commonjs/duplex.js @@ -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 @@ -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; @@ -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) { @@ -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 { @@ -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]) }); } } } diff --git a/commonjs/helpers.js b/commonjs/helpers.js index db0c6f5..5f2350e 100644 --- a/commonjs/helpers.js +++ b/commonjs/helpers.js @@ -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); @@ -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; /** @@ -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'); diff --git a/dist/fast-json-patch.js b/dist/fast-json-patch.js index 0825c48..c0f4b80 100644 --- a/dist/fast-json-patch.js +++ b/dist/fast-json-patch.js @@ -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 diff --git a/dist/fast-json-patch.min.js b/dist/fast-json-patch.min.js index 9ab5c76..74a6a36 100644 --- a/dist/fast-json-patch.min.js +++ b/dist/fast-json-patch.min.js @@ -1,4 +1,4 @@ -/*! fast-json-patch, version: 3.1.0 */ +/*! fast-json-patch, version: 3.1.1 */ var jsonpatch=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t){ /*! * https://github.com/Starcounter-Jack/JSON-Patch diff --git a/module/helpers.mjs b/module/helpers.mjs index a090f68..592f560 100644 --- a/module/helpers.mjs +++ b/module/helpers.mjs @@ -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 __()); @@ -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. @@ -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'); diff --git a/package-lock.json b/package-lock.json index 179ef01..cd21723 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fast-json-patch", - "version": "3.2.0", + "version": "3.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fast-json-patch", - "version": "3.2.0", + "version": "3.1.1", "license": "MIT", "devDependencies": { "benchmark": "^2.1.4", diff --git a/package.json b/package.json index 138c88b..688a6d0 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -62,4 +62,4 @@ "bench-core": "node test/spec/coreBenchmark.js", "bench-duplex": "node test/spec/coreBenchmark.js && node test/spec/duplexBenchmark.js" } -} \ No newline at end of file +}