Skip to content

Commit d7903fb

Browse files
fix: typescript codegen changes
1 parent 5f04488 commit d7903fb

File tree

6 files changed

+294
-583
lines changed

6 files changed

+294
-583
lines changed

commonjs/core.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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;
23
var helpers_js_1 = require("./helpers.js");
34
exports.JsonPatchError = helpers_js_1.PatchError;
45
exports.deepClone = helpers_js_1._deepClone;
@@ -30,7 +31,7 @@ var objOps = {
3031
and is potentially unneeded */
3132
var removed = getValueByPointer(document, this.path);
3233
if (removed) {
33-
removed = helpers_js_1._deepClone(removed);
34+
removed = (0, helpers_js_1._deepClone)(removed);
3435
}
3536
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
3637
applyOperation(document, { op: "add", path: this.path, value: originalValue });
@@ -39,7 +40,7 @@ var objOps = {
3940
copy: function (obj, key, document) {
4041
var valueToCopy = getValueByPointer(document, this.from);
4142
// enforce copy by value so further operations don't affect source (see issue #177)
42-
applyOperation(document, { op: "add", path: this.path, value: helpers_js_1._deepClone(valueToCopy) });
43+
applyOperation(document, { op: "add", path: this.path, value: (0, helpers_js_1._deepClone)(valueToCopy) });
4344
return { newDocument: document };
4445
},
4546
test: function (obj, key, document) {
@@ -53,7 +54,7 @@ var objOps = {
5354
/* The operations applicable to an array. Many are the same as for the object */
5455
var arrOps = {
5556
add: function (arr, i, document) {
56-
if (helpers_js_1.isInteger(i)) {
57+
if ((0, helpers_js_1.isInteger)(i)) {
5758
arr.splice(i, 0, this.value);
5859
}
5960
else { // array props
@@ -167,7 +168,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
167168
} /* END ROOT OPERATIONS */
168169
else {
169170
if (!mutateDocument) {
170-
document = helpers_js_1._deepClone(document);
171+
document = (0, helpers_js_1._deepClone)(document);
171172
}
172173
var path = operation.path || "";
173174
var keys = path.split('/');
@@ -186,7 +187,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
186187
while (true) {
187188
key = keys[t];
188189
if (key && key.indexOf('~') != -1) {
189-
key = helpers_js_1.unescapePathComponent(key);
190+
key = (0, helpers_js_1.unescapePathComponent)(key);
190191
}
191192
if (banPrototypeModifications &&
192193
(key == '__proto__' ||
@@ -212,10 +213,10 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
212213
key = obj.length;
213214
}
214215
else {
215-
if (validateOperation && !helpers_js_1.isInteger(key)) {
216+
if (validateOperation && !(0, helpers_js_1.isInteger)(key)) {
216217
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);
217218
} // only parse key when it's an integer for `arr.prop` to work
218-
else if (helpers_js_1.isInteger(key)) {
219+
else if ((0, helpers_js_1.isInteger)(key)) {
219220
key = ~~key;
220221
}
221222
}
@@ -272,7 +273,7 @@ function applyPatch(document, patch, validateOperation, mutateDocument, banProto
272273
}
273274
}
274275
if (!mutateDocument) {
275-
document = helpers_js_1._deepClone(document);
276+
document = (0, helpers_js_1._deepClone)(document);
276277
}
277278
var results = new Array(patch.length);
278279
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
@@ -328,7 +329,7 @@ function validator(operation, index, document, existingPathFragment) {
328329
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
329330
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
330331
}
331-
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_js_1.hasUndefined(operation.value)) {
332+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && (0, helpers_js_1.hasUndefined)(operation.value)) {
332333
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);
333334
}
334335
else if (document) {
@@ -368,7 +369,7 @@ function validate(sequence, document, externalValidator) {
368369
}
369370
if (document) {
370371
//clone document and sequence so that we can safely try applying operations
371-
applyPatch(helpers_js_1._deepClone(document), helpers_js_1._deepClone(sequence), externalValidator || true);
372+
applyPatch((0, helpers_js_1._deepClone)(document), (0, helpers_js_1._deepClone)(sequence), externalValidator || true);
372373
}
373374
else {
374375
externalValidator = externalValidator || validator;

commonjs/duplex.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Object.defineProperty(exports, "__esModule", { value: true });
2+
exports.compare = exports.generate = exports.observe = exports.unobserve = void 0;
23
/*!
34
* https://github.com/Starcounter-Jack/JSON-Patch
45
* (c) 2017-2021 Joachim Wester
@@ -56,7 +57,7 @@ function observe(obj, callback) {
5657
return observer;
5758
}
5859
observer = {};
59-
mirror.value = helpers_js_1._deepClone(obj);
60+
mirror.value = (0, helpers_js_1._deepClone)(obj);
6061
if (callback) {
6162
observer.callback = callback;
6263
observer.next = null;
@@ -101,7 +102,7 @@ function generate(observer, invertible) {
101102
var mirror = beforeDict.get(observer.object);
102103
_generate(mirror.value, observer.object, observer.patches, "", invertible);
103104
if (observer.patches.length) {
104-
core_js_1.applyPatch(mirror.value, observer.patches);
105+
(0, core_js_1.applyPatch)(mirror.value, observer.patches);
105106
}
106107
var temp = observer.patches;
107108
if (temp.length > 0) {
@@ -121,34 +122,34 @@ function _generate(mirror, obj, patches, path, invertible) {
121122
if (typeof obj.toJSON === "function") {
122123
obj = obj.toJSON();
123124
}
124-
var newKeys = helpers_js_1._objectKeys(obj);
125-
var oldKeys = helpers_js_1._objectKeys(mirror);
125+
var newKeys = (0, helpers_js_1._objectKeys)(obj);
126+
var oldKeys = (0, helpers_js_1._objectKeys)(mirror);
126127
var changed = false;
127128
var deleted = false;
128129
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
129130
for (var t = oldKeys.length - 1; t >= 0; t--) {
130131
var key = oldKeys[t];
131132
var oldVal = mirror[key];
132-
if (helpers_js_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
133+
if ((0, helpers_js_1.hasOwnProperty)(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
133134
var newVal = obj[key];
134135
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
135-
_generate(oldVal, newVal, patches, path + "/" + helpers_js_1.escapePathComponent(key), invertible);
136+
_generate(oldVal, newVal, patches, path + "/" + (0, helpers_js_1.escapePathComponent)(key), invertible);
136137
}
137138
else {
138139
if (oldVal !== newVal) {
139140
changed = true;
140141
if (invertible) {
141-
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
142+
patches.push({ op: "test", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(oldVal) });
142143
}
143-
patches.push({ op: "replace", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(newVal) });
144+
patches.push({ op: "replace", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(newVal) });
144145
}
145146
}
146147
}
147148
else if (Array.isArray(mirror) === Array.isArray(obj)) {
148149
if (invertible) {
149-
patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
150+
patches.push({ op: "test", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key), value: (0, helpers_js_1._deepClone)(oldVal) });
150151
}
151-
patches.push({ op: "remove", path: path + "/" + helpers_js_1.escapePathComponent(key) });
152+
patches.push({ op: "remove", path: path + "/" + (0, helpers_js_1.escapePathComponent)(key) });
152153
deleted = true; // property has been deleted
153154
}
154155
else {
@@ -164,8 +165,8 @@ function _generate(mirror, obj, patches, path, invertible) {
164165
}
165166
for (var t = 0; t < newKeys.length; t++) {
166167
var key = newKeys[t];
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]) });
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]) });
169170
}
170171
}
171172
}

commonjs/helpers.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ 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 (b.hasOwnProperty(p)) d[p] = b[p]; };
10+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, 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");
1416
extendStatics(d, b);
1517
function __() { this.constructor = d; }
1618
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1719
};
1820
})();
1921
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;
2023
var _hasOwnProperty = Object.prototype.hasOwnProperty;
2124
function hasOwnProperty(obj, key) {
2225
return _hasOwnProperty.call(obj, key);
@@ -122,7 +125,7 @@ function getPath(root, obj) {
122125
if (path === '') {
123126
throw new Error("Object not found in root");
124127
}
125-
return "/" + path;
128+
return "/".concat(path);
126129
}
127130
exports.getPath = getPath;
128131
/**
@@ -158,7 +161,7 @@ function patchErrorMessageFormatter(message, args) {
158161
for (var key in args) {
159162
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
160163
if (typeof value !== 'undefined') {
161-
messageParts.push(key + ": " + value);
164+
messageParts.push("".concat(key, ": ").concat(value));
162165
}
163166
}
164167
return messageParts.join('\n');

module/helpers.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ 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 (b.hasOwnProperty(p)) d[p] = b[p]; };
10+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, 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");
1416
extendStatics(d, b);
1517
function __() { this.constructor = d; }
1618
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -114,7 +116,7 @@ export function getPath(root, obj) {
114116
if (path === '') {
115117
throw new Error("Object not found in root");
116118
}
117-
return "/" + path;
119+
return "/".concat(path);
118120
}
119121
/**
120122
* Recursively checks whether an object has any undefined values inside.
@@ -148,7 +150,7 @@ function patchErrorMessageFormatter(message, args) {
148150
for (var key in args) {
149151
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
150152
if (typeof value !== 'undefined') {
151-
messageParts.push(key + ": " + value);
153+
messageParts.push("".concat(key, ": ").concat(value));
152154
}
153155
}
154156
return messageParts.join('\n');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy