Skip to content

Commit e4f4eb3

Browse files
3.1.1
1 parent d7903fb commit e4f4eb3

8 files changed

+34
-41
lines changed

commonjs/core.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Object.defineProperty(exports, "__esModule", { value: true });
2-
exports._areEquals = exports.validate = exports.validator = exports.applyReducer = exports.applyPatch = exports.applyOperation = exports.getValueByPointer = exports.deepClone = exports.JsonPatchError = void 0;
32
var helpers_js_1 = require("./helpers.js");
43
exports.JsonPatchError = helpers_js_1.PatchError;
54
exports.deepClone = helpers_js_1._deepClone;
@@ -31,7 +30,7 @@ var objOps = {
3130
and is potentially unneeded */
3231
var removed = getValueByPointer(document, this.path);
3332
if (removed) {
34-
removed = (0, helpers_js_1._deepClone)(removed);
33+
removed = helpers_js_1._deepClone(removed);
3534
}
3635
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
3736
applyOperation(document, { op: "add", path: this.path, value: originalValue });
@@ -40,7 +39,7 @@ var objOps = {
4039
copy: function (obj, key, document) {
4140
var valueToCopy = getValueByPointer(document, this.from);
4241
// enforce copy by value so further operations don't affect source (see issue #177)
43-
applyOperation(document, { op: "add", path: this.path, value: (0, helpers_js_1._deepClone)(valueToCopy) });
42+
applyOperation(document, { op: "add", path: this.path, value: helpers_js_1._deepClone(valueToCopy) });
4443
return { newDocument: document };
4544
},
4645
test: function (obj, key, document) {
@@ -54,7 +53,7 @@ var objOps = {
5453
/* The operations applicable to an array. Many are the same as for the object */
5554
var arrOps = {
5655
add: function (arr, i, document) {
57-
if ((0, helpers_js_1.isInteger)(i)) {
56+
if (helpers_js_1.isInteger(i)) {
5857
arr.splice(i, 0, this.value);
5958
}
6059
else { // array props
@@ -168,7 +167,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
168167
} /* END ROOT OPERATIONS */
169168
else {
170169
if (!mutateDocument) {
171-
document = (0, helpers_js_1._deepClone)(document);
170+
document = helpers_js_1._deepClone(document);
172171
}
173172
var path = operation.path || "";
174173
var keys = path.split('/');
@@ -187,7 +186,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
187186
while (true) {
188187
key = keys[t];
189188
if (key && key.indexOf('~') != -1) {
190-
key = (0, helpers_js_1.unescapePathComponent)(key);
189+
key = helpers_js_1.unescapePathComponent(key);
191190
}
192191
if (banPrototypeModifications &&
193192
(key == '__proto__' ||
@@ -213,10 +212,10 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
213212
key = obj.length;
214213
}
215214
else {
216-
if (validateOperation && !(0, helpers_js_1.isInteger)(key)) {
215+
if (validateOperation && !helpers_js_1.isInteger(key)) {
217216
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);
218217
} // only parse key when it's an integer for `arr.prop` to work
219-
else if ((0, helpers_js_1.isInteger)(key)) {
218+
else if (helpers_js_1.isInteger(key)) {
220219
key = ~~key;
221220
}
222221
}
@@ -273,7 +272,7 @@ function applyPatch(document, patch, validateOperation, mutateDocument, banProto
273272
}
274273
}
275274
if (!mutateDocument) {
276-
document = (0, helpers_js_1._deepClone)(document);
275+
document = helpers_js_1._deepClone(document);
277276
}
278277
var results = new Array(patch.length);
279278
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
@@ -329,7 +328,7 @@ function validator(operation, index, document, existingPathFragment) {
329328
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
330329
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
331330
}
332-
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && (0, helpers_js_1.hasUndefined)(operation.value)) {
331+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_js_1.hasUndefined(operation.value)) {
333332
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);
334333
}
335334
else if (document) {
@@ -369,7 +368,7 @@ function validate(sequence, document, externalValidator) {
369368
}
370369
if (document) {
371370
//clone document and sequence so that we can safely try applying operations
372-
applyPatch((0, helpers_js_1._deepClone)(document), (0, helpers_js_1._deepClone)(sequence), externalValidator || true);
371+
applyPatch(helpers_js_1._deepClone(document), helpers_js_1._deepClone(sequence), externalValidator || true);
373372
}
374373
else {
375374
externalValidator = externalValidator || validator;

commonjs/duplex.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Object.defineProperty(exports, "__esModule", { value: true });
2-
exports.compare = exports.generate = exports.observe = exports.unobserve = void 0;
32
/*!
43
* https://github.com/Starcounter-Jack/JSON-Patch
54
* (c) 2017-2021 Joachim Wester
@@ -57,7 +56,7 @@ function observe(obj, callback) {
5756
return observer;
5857
}
5958
observer = {};
60-
mirror.value = (0, helpers_js_1._deepClone)(obj);
59+
mirror.value = helpers_js_1._deepClone(obj);
6160
if (callback) {
6261
observer.callback = callback;
6362
observer.next = null;
@@ -102,7 +101,7 @@ function generate(observer, invertible) {
102101
var mirror = beforeDict.get(observer.object);
103102
_generate(mirror.value, observer.object, observer.patches, "", invertible);
104103
if (observer.patches.length) {
105-
(0, core_js_1.applyPatch)(mirror.value, observer.patches);
104+
core_js_1.applyPatch(mirror.value, observer.patches);
106105
}
107106
var temp = observer.patches;
108107
if (temp.length > 0) {
@@ -122,34 +121,34 @@ function _generate(mirror, obj, patches, path, invertible) {
122121
if (typeof obj.toJSON === "function") {
123122
obj = obj.toJSON();
124123
}
125-
var newKeys = (0, helpers_js_1._objectKeys)(obj);
126-
var oldKeys = (0, helpers_js_1._objectKeys)(mirror);
124+
var newKeys = helpers_js_1._objectKeys(obj);
125+
var oldKeys = helpers_js_1._objectKeys(mirror);
127126
var changed = false;
128127
var deleted = false;
129128
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
130129
for (var t = oldKeys.length - 1; t >= 0; t--) {
131130
var key = oldKeys[t];
132131
var oldVal = mirror[key];
133-
if ((0, helpers_js_1.hasOwnProperty)(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
132+
if (helpers_js_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
134133
var newVal = obj[key];
135134
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
136-
_generate(oldVal, newVal, patches, path + "/" + (0, helpers_js_1.escapePathComponent)(key), invertible);
135+
_generate(oldVal, newVal, patches, path + "/" + helpers_js_1.escapePathComponent(key), invertible);
137136
}
138137
else {
139138
if (oldVal !== newVal) {
140139
changed = true;
141140
if (invertible) {
142-
patches.push({ op: "test", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(oldVal) });
141+
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
143142
}
144-
patches.push({ op: "replace", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(newVal) });
143+
patches.push({ op: "replace", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(newVal) });
145144
}
146145
}
147146
}
148147
else if (Array.isArray(mirror) === Array.isArray(obj)) {
149148
if (invertible) {
150-
patches.push({ op: "test", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(oldVal) });
149+
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
151150
}
152-
patches.push({ op: "remove", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key) });
151+
patches.push({ op: "remove", path: path + "/" + helpers_js_1.escapePathComponent(key) });
153152
deleted = true; // property has been deleted
154153
}
155154
else {
@@ -165,8 +164,8 @@ function _generate(mirror, obj, patches, path, invertible) {
165164
}
166165
for (var t = 0; t < newKeys.length; t++) {
167166
var key = newKeys[t];
168-
if (!(0, helpers_js_1.hasOwnProperty)(mirror, key) && obj[key] !== undefined) {
169-
patches.push({ op: "add", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(obj[key]) });
167+
if (!helpers_js_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) {
168+
patches.push({ op: "add", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(obj[key]) });
170169
}
171170
}
172171
}

commonjs/helpers.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ var __extends = (this && this.__extends) || (function () {
77
var extendStatics = function (d, b) {
88
extendStatics = Object.setPrototypeOf ||
99
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
10+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1111
return extendStatics(d, b);
1212
};
1313
return function (d, b) {
14-
if (typeof b !== "function" && b !== null)
15-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1614
extendStatics(d, b);
1715
function __() { this.constructor = d; }
1816
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1917
};
2018
})();
2119
Object.defineProperty(exports, "__esModule", { value: true });
22-
exports.PatchError = exports.hasUndefined = exports.getPath = exports._getPathRecursive = exports.unescapePathComponent = exports.escapePathComponent = exports.isInteger = exports._deepClone = exports._objectKeys = exports.hasOwnProperty = void 0;
2320
var _hasOwnProperty = Object.prototype.hasOwnProperty;
2421
function hasOwnProperty(obj, key) {
2522
return _hasOwnProperty.call(obj, key);
@@ -125,7 +122,7 @@ function getPath(root, obj) {
125122
if (path === '') {
126123
throw new Error("Object not found in root");
127124
}
128-
return "/".concat(path);
125+
return "/" + path;
129126
}
130127
exports.getPath = getPath;
131128
/**
@@ -161,7 +158,7 @@ function patchErrorMessageFormatter(message, args) {
161158
for (var key in args) {
162159
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
163160
if (typeof value !== 'undefined') {
164-
messageParts.push("".concat(key, ": ").concat(value));
161+
messageParts.push(key + ": " + value);
165162
}
166163
}
167164
return messageParts.join('\n');

dist/fast-json-patch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! fast-json-patch, version: 3.1.0 */
1+
/*! fast-json-patch, version: 3.1.1 */
22
var jsonpatch =
33
/******/ (function(modules) { // webpackBootstrap
44
/******/ // The module cache

dist/fast-json-patch.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

module/helpers.mjs

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ var __extends = (this && this.__extends) || (function () {
77
var extendStatics = function (d, b) {
88
extendStatics = Object.setPrototypeOf ||
99
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
10+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1111
return extendStatics(d, b);
1212
};
1313
return function (d, b) {
14-
if (typeof b !== "function" && b !== null)
15-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1614
extendStatics(d, b);
1715
function __() { this.constructor = d; }
1816
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -116,7 +114,7 @@ export function getPath(root, obj) {
116114
if (path === '') {
117115
throw new Error("Object not found in root");
118116
}
119-
return "/".concat(path);
117+
return "/" + path;
120118
}
121119
/**
122120
* Recursively checks whether an object has any undefined values inside.
@@ -150,7 +148,7 @@ function patchErrorMessageFormatter(message, args) {
150148
for (var key in args) {
151149
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
152150
if (typeof value !== 'undefined') {
153-
messageParts.push("".concat(key, ": ").concat(value));
151+
messageParts.push(key + ": " + value);
154152
}
155153
}
156154
return messageParts.join('\n');

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fast-json-patch",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",
55
"homepage": "https://github.com/Starcounter-Jack/JSON-Patch",
66
"keywords": [
@@ -62,4 +62,4 @@
6262
"bench-core": "node test/spec/coreBenchmark.js",
6363
"bench-duplex": "node test/spec/coreBenchmark.js && node test/spec/duplexBenchmark.js"
6464
}
65-
}
65+
}

0 commit comments

Comments
 (0)