projen 0.61.13 → 0.61.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/.jsii +325 -33
  2. package/docs/api/API.md +166 -0
  3. package/docs/escape-hatches.md +3 -3
  4. package/lib/awscdk/auto-discover.js +5 -5
  5. package/lib/awscdk/awscdk-app-java.js +1 -1
  6. package/lib/awscdk/awscdk-app-py.js +1 -1
  7. package/lib/awscdk/awscdk-app-ts.js +1 -1
  8. package/lib/awscdk/awscdk-construct.js +2 -2
  9. package/lib/awscdk/awscdk-deps-java.js +1 -1
  10. package/lib/awscdk/awscdk-deps-js.js +1 -1
  11. package/lib/awscdk/awscdk-deps.js +1 -1
  12. package/lib/awscdk/cdk-config.js +1 -1
  13. package/lib/awscdk/cdk-tasks.js +1 -1
  14. package/lib/awscdk/integration-test.js +1 -1
  15. package/lib/awscdk/lambda-extension.js +1 -1
  16. package/lib/awscdk/lambda-function.js +2 -2
  17. package/lib/build/build-workflow.js +1 -1
  18. package/lib/cdk/auto-discover-base.js +2 -2
  19. package/lib/cdk/construct-lib.js +1 -1
  20. package/lib/cdk/integration-test-base.js +1 -1
  21. package/lib/cdk/jsii-docgen.js +1 -1
  22. package/lib/cdk/jsii-project.d.ts +1 -0
  23. package/lib/cdk/jsii-project.js +3 -2
  24. package/lib/cdk8s/auto-discover.js +2 -2
  25. package/lib/cdk8s/cdk8s-app-py.js +1 -1
  26. package/lib/cdk8s/cdk8s-app-ts.js +1 -1
  27. package/lib/cdk8s/cdk8s-construct.js +1 -1
  28. package/lib/cdk8s/cdk8s-deps-py.js +1 -1
  29. package/lib/cdk8s/cdk8s-deps.js +1 -1
  30. package/lib/cdk8s/integration-test.js +1 -1
  31. package/lib/cdktf/cdktf-construct.js +1 -1
  32. package/lib/circleci/circleci.js +1 -1
  33. package/lib/component.js +1 -1
  34. package/lib/dependencies.js +1 -1
  35. package/lib/dev-env.js +1 -1
  36. package/lib/docker-compose.js +2 -2
  37. package/lib/file.js +1 -1
  38. package/lib/gitattributes.js +1 -1
  39. package/lib/github/auto-approve.js +1 -1
  40. package/lib/github/auto-merge.js +1 -1
  41. package/lib/github/dependabot.js +1 -1
  42. package/lib/github/github-credentials.js +1 -1
  43. package/lib/github/github-project.js +1 -1
  44. package/lib/github/github.js +1 -1
  45. package/lib/github/mergify.js +1 -1
  46. package/lib/github/pr-template.js +1 -1
  47. package/lib/github/pull-request-lint.js +1 -1
  48. package/lib/github/stale.js +1 -1
  49. package/lib/github/task-workflow.js +1 -1
  50. package/lib/github/workflows.js +1 -1
  51. package/lib/gitlab/configuration.js +1 -1
  52. package/lib/gitlab/gitlab-configuration.js +1 -1
  53. package/lib/gitlab/nested-configuration.js +1 -1
  54. package/lib/gitpod.js +1 -1
  55. package/lib/ignore-file.js +1 -1
  56. package/lib/index.d.ts +1 -0
  57. package/lib/index.js +2 -1
  58. package/lib/ini.js +1 -1
  59. package/lib/java/java-project.js +1 -1
  60. package/lib/java/junit.js +1 -1
  61. package/lib/java/maven-compile.js +1 -1
  62. package/lib/java/maven-packaging.js +1 -1
  63. package/lib/java/maven-sample.js +1 -1
  64. package/lib/java/pom.js +1 -1
  65. package/lib/java/projenrc.js +1 -1
  66. package/lib/javascript/bundler.js +1 -1
  67. package/lib/javascript/eslint.js +1 -1
  68. package/lib/javascript/jest.js +1 -1
  69. package/lib/javascript/node-package.js +1 -1
  70. package/lib/javascript/node-project.js +1 -1
  71. package/lib/javascript/npm-config.js +1 -1
  72. package/lib/javascript/prettier.js +1 -1
  73. package/lib/javascript/projenrc.js +1 -1
  74. package/lib/javascript/typescript-config.js +1 -1
  75. package/lib/javascript/upgrade-dependencies.js +2 -2
  76. package/lib/json-patch.d.ts +75 -0
  77. package/lib/json-patch.js +105 -0
  78. package/lib/json.js +1 -1
  79. package/lib/license.js +1 -1
  80. package/lib/logger.js +1 -1
  81. package/lib/makefile.js +1 -1
  82. package/lib/object-file.d.ts +36 -0
  83. package/lib/object-file.js +39 -3
  84. package/lib/project-build.js +1 -1
  85. package/lib/project.js +1 -1
  86. package/lib/projects.js +1 -1
  87. package/lib/projenrc-json.js +1 -1
  88. package/lib/python/pip.js +1 -1
  89. package/lib/python/poetry.js +2 -2
  90. package/lib/python/projenrc.js +1 -1
  91. package/lib/python/pytest-sample.js +1 -1
  92. package/lib/python/pytest.js +1 -1
  93. package/lib/python/python-project.js +1 -1
  94. package/lib/python/python-sample.js +1 -1
  95. package/lib/python/requirements-file.js +1 -1
  96. package/lib/python/setuppy.js +1 -1
  97. package/lib/python/setuptools.js +1 -1
  98. package/lib/python/venv.js +1 -1
  99. package/lib/readme.js +1 -1
  100. package/lib/release/publisher.js +1 -1
  101. package/lib/release/release-trigger.js +1 -1
  102. package/lib/release/release.js +1 -1
  103. package/lib/renovatebot.js +1 -1
  104. package/lib/run-task.js +1833 -0
  105. package/lib/sample-file.js +2 -2
  106. package/lib/semver.js +1 -1
  107. package/lib/source-code.js +1 -1
  108. package/lib/task-runtime.js +1 -1
  109. package/lib/task.js +1 -1
  110. package/lib/tasks.js +1 -1
  111. package/lib/testing.js +1 -1
  112. package/lib/textfile.js +1 -1
  113. package/lib/toml.js +1 -1
  114. package/lib/typescript/projenrc.js +1 -1
  115. package/lib/typescript/typescript-typedoc.js +1 -1
  116. package/lib/typescript/typescript.js +3 -3
  117. package/lib/version.js +1 -1
  118. package/lib/vscode/devcontainer.js +1 -1
  119. package/lib/vscode/launch-config.js +1 -1
  120. package/lib/vscode/vscode.js +1 -1
  121. package/lib/web/next.js +3 -3
  122. package/lib/web/postcss.js +1 -1
  123. package/lib/web/react.js +4 -4
  124. package/lib/web/tailwind.js +1 -1
  125. package/lib/xmlfile.js +1 -1
  126. package/lib/yaml.js +1 -1
  127. package/node_modules/fast-json-patch/LICENSE.txt +22 -0
  128. package/node_modules/fast-json-patch/README.md +428 -0
  129. package/node_modules/fast-json-patch/commonjs/core.d.ts +111 -0
  130. package/node_modules/fast-json-patch/commonjs/core.js +441 -0
  131. package/node_modules/fast-json-patch/commonjs/duplex.d.ts +23 -0
  132. package/node_modules/fast-json-patch/commonjs/duplex.js +181 -0
  133. package/node_modules/fast-json-patch/commonjs/helpers.d.ts +41 -0
  134. package/node_modules/fast-json-patch/commonjs/helpers.js +181 -0
  135. package/node_modules/fast-json-patch/dist/fast-json-patch.js +928 -0
  136. package/node_modules/fast-json-patch/dist/fast-json-patch.min.js +14 -0
  137. package/node_modules/fast-json-patch/index.d.ts +34 -0
  138. package/node_modules/fast-json-patch/index.js +11 -0
  139. package/node_modules/fast-json-patch/index.mjs +29 -0
  140. package/node_modules/fast-json-patch/index.ts +31 -0
  141. package/node_modules/fast-json-patch/jasmine-run.mjs +23 -0
  142. package/node_modules/fast-json-patch/module/core.d.ts +111 -0
  143. package/node_modules/fast-json-patch/module/core.mjs +433 -0
  144. package/node_modules/fast-json-patch/module/duplex.d.ts +23 -0
  145. package/node_modules/fast-json-patch/module/duplex.mjs +176 -0
  146. package/node_modules/fast-json-patch/module/helpers.d.ts +41 -0
  147. package/node_modules/fast-json-patch/module/helpers.mjs +171 -0
  148. package/node_modules/fast-json-patch/package.json +65 -0
  149. package/node_modules/fast-json-patch/tsc-to-mjs.sh +10 -0
  150. package/node_modules/fast-json-patch/webpack.config.js +63 -0
  151. package/package.json +3 -1
@@ -0,0 +1,441 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ var helpers_js_1 = require("./helpers.js");
3
+ exports.JsonPatchError = helpers_js_1.PatchError;
4
+ exports.deepClone = helpers_js_1._deepClone;
5
+ /* We use a Javascript hash to store each
6
+ function. Each hash entry (property) uses
7
+ the operation identifiers specified in rfc6902.
8
+ In this way, we can map each patch operation
9
+ to its dedicated function in efficient way.
10
+ */
11
+ /* The operations applicable to an object */
12
+ var objOps = {
13
+ add: function (obj, key, document) {
14
+ obj[key] = this.value;
15
+ return { newDocument: document };
16
+ },
17
+ remove: function (obj, key, document) {
18
+ var removed = obj[key];
19
+ delete obj[key];
20
+ return { newDocument: document, removed: removed };
21
+ },
22
+ replace: function (obj, key, document) {
23
+ var removed = obj[key];
24
+ obj[key] = this.value;
25
+ return { newDocument: document, removed: removed };
26
+ },
27
+ move: function (obj, key, document) {
28
+ /* in case move target overwrites an existing value,
29
+ return the removed value, this can be taxing performance-wise,
30
+ and is potentially unneeded */
31
+ var removed = getValueByPointer(document, this.path);
32
+ if (removed) {
33
+ removed = helpers_js_1._deepClone(removed);
34
+ }
35
+ var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
36
+ applyOperation(document, { op: "add", path: this.path, value: originalValue });
37
+ return { newDocument: document, removed: removed };
38
+ },
39
+ copy: function (obj, key, document) {
40
+ var valueToCopy = getValueByPointer(document, this.from);
41
+ // 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
+ return { newDocument: document };
44
+ },
45
+ test: function (obj, key, document) {
46
+ return { newDocument: document, test: _areEquals(obj[key], this.value) };
47
+ },
48
+ _get: function (obj, key, document) {
49
+ this.value = obj[key];
50
+ return { newDocument: document };
51
+ }
52
+ };
53
+ /* The operations applicable to an array. Many are the same as for the object */
54
+ var arrOps = {
55
+ add: function (arr, i, document) {
56
+ if (helpers_js_1.isInteger(i)) {
57
+ arr.splice(i, 0, this.value);
58
+ }
59
+ else { // array props
60
+ arr[i] = this.value;
61
+ }
62
+ // this may be needed when using '-' in an array
63
+ return { newDocument: document, index: i };
64
+ },
65
+ remove: function (arr, i, document) {
66
+ var removedList = arr.splice(i, 1);
67
+ return { newDocument: document, removed: removedList[0] };
68
+ },
69
+ replace: function (arr, i, document) {
70
+ var removed = arr[i];
71
+ arr[i] = this.value;
72
+ return { newDocument: document, removed: removed };
73
+ },
74
+ move: objOps.move,
75
+ copy: objOps.copy,
76
+ test: objOps.test,
77
+ _get: objOps._get
78
+ };
79
+ /**
80
+ * Retrieves a value from a JSON document by a JSON pointer.
81
+ * Returns the value.
82
+ *
83
+ * @param document The document to get the value from
84
+ * @param pointer an escaped JSON pointer
85
+ * @return The retrieved value
86
+ */
87
+ function getValueByPointer(document, pointer) {
88
+ if (pointer == '') {
89
+ return document;
90
+ }
91
+ var getOriginalDestination = { op: "_get", path: pointer };
92
+ applyOperation(document, getOriginalDestination);
93
+ return getOriginalDestination.value;
94
+ }
95
+ exports.getValueByPointer = getValueByPointer;
96
+ /**
97
+ * Apply a single JSON Patch Operation on a JSON document.
98
+ * Returns the {newDocument, result} of the operation.
99
+ * It modifies the `document` and `operation` objects - it gets the values by reference.
100
+ * If you would like to avoid touching your values, clone them:
101
+ * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
102
+ *
103
+ * @param document The document to patch
104
+ * @param operation The operation to apply
105
+ * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
106
+ * @param mutateDocument Whether to mutate the original document or clone it before applying
107
+ * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
108
+ * @return `{newDocument, result}` after the operation
109
+ */
110
+ function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
111
+ if (validateOperation === void 0) { validateOperation = false; }
112
+ if (mutateDocument === void 0) { mutateDocument = true; }
113
+ if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
114
+ if (index === void 0) { index = 0; }
115
+ if (validateOperation) {
116
+ if (typeof validateOperation == 'function') {
117
+ validateOperation(operation, 0, document, operation.path);
118
+ }
119
+ else {
120
+ validator(operation, 0);
121
+ }
122
+ }
123
+ /* ROOT OPERATIONS */
124
+ if (operation.path === "") {
125
+ var returnValue = { newDocument: document };
126
+ if (operation.op === 'add') {
127
+ returnValue.newDocument = operation.value;
128
+ return returnValue;
129
+ }
130
+ else if (operation.op === 'replace') {
131
+ returnValue.newDocument = operation.value;
132
+ returnValue.removed = document; //document we removed
133
+ return returnValue;
134
+ }
135
+ else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
136
+ returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
137
+ if (operation.op === 'move') { // report removed item
138
+ returnValue.removed = document;
139
+ }
140
+ return returnValue;
141
+ }
142
+ else if (operation.op === 'test') {
143
+ returnValue.test = _areEquals(document, operation.value);
144
+ if (returnValue.test === false) {
145
+ throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
146
+ }
147
+ returnValue.newDocument = document;
148
+ return returnValue;
149
+ }
150
+ else if (operation.op === 'remove') { // a remove on root
151
+ returnValue.removed = document;
152
+ returnValue.newDocument = null;
153
+ return returnValue;
154
+ }
155
+ else if (operation.op === '_get') {
156
+ operation.value = document;
157
+ return returnValue;
158
+ }
159
+ else { /* bad operation */
160
+ if (validateOperation) {
161
+ throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
162
+ }
163
+ else {
164
+ return returnValue;
165
+ }
166
+ }
167
+ } /* END ROOT OPERATIONS */
168
+ else {
169
+ if (!mutateDocument) {
170
+ document = helpers_js_1._deepClone(document);
171
+ }
172
+ var path = operation.path || "";
173
+ var keys = path.split('/');
174
+ var obj = document;
175
+ var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
176
+ var len = keys.length;
177
+ var existingPathFragment = undefined;
178
+ var key = void 0;
179
+ var validateFunction = void 0;
180
+ if (typeof validateOperation == 'function') {
181
+ validateFunction = validateOperation;
182
+ }
183
+ else {
184
+ validateFunction = validator;
185
+ }
186
+ while (true) {
187
+ key = keys[t];
188
+ if (key && key.indexOf('~') != -1) {
189
+ key = helpers_js_1.unescapePathComponent(key);
190
+ }
191
+ if (banPrototypeModifications &&
192
+ (key == '__proto__' ||
193
+ (key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
194
+ throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
195
+ }
196
+ if (validateOperation) {
197
+ if (existingPathFragment === undefined) {
198
+ if (obj[key] === undefined) {
199
+ existingPathFragment = keys.slice(0, t).join('/');
200
+ }
201
+ else if (t == len - 1) {
202
+ existingPathFragment = operation.path;
203
+ }
204
+ if (existingPathFragment !== undefined) {
205
+ validateFunction(operation, 0, document, existingPathFragment);
206
+ }
207
+ }
208
+ }
209
+ t++;
210
+ if (Array.isArray(obj)) {
211
+ if (key === '-') {
212
+ key = obj.length;
213
+ }
214
+ else {
215
+ if (validateOperation && !helpers_js_1.isInteger(key)) {
216
+ 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);
217
+ } // only parse key when it's an integer for `arr.prop` to work
218
+ else if (helpers_js_1.isInteger(key)) {
219
+ key = ~~key;
220
+ }
221
+ }
222
+ if (t >= len) {
223
+ if (validateOperation && operation.op === "add" && key > obj.length) {
224
+ throw new exports.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
225
+ }
226
+ var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
227
+ if (returnValue.test === false) {
228
+ throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
229
+ }
230
+ return returnValue;
231
+ }
232
+ }
233
+ else {
234
+ if (t >= len) {
235
+ var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
236
+ if (returnValue.test === false) {
237
+ throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
238
+ }
239
+ return returnValue;
240
+ }
241
+ }
242
+ obj = obj[key];
243
+ // If we have more keys in the path, but the next value isn't a non-null object,
244
+ // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.
245
+ if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
246
+ throw new exports.JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
247
+ }
248
+ }
249
+ }
250
+ }
251
+ exports.applyOperation = applyOperation;
252
+ /**
253
+ * Apply a full JSON Patch array on a JSON document.
254
+ * Returns the {newDocument, result} of the patch.
255
+ * It modifies the `document` object and `patch` - it gets the values by reference.
256
+ * If you would like to avoid touching your values, clone them:
257
+ * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
258
+ *
259
+ * @param document The document to patch
260
+ * @param patch The patch to apply
261
+ * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
262
+ * @param mutateDocument Whether to mutate the original document or clone it before applying
263
+ * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
264
+ * @return An array of `{newDocument, result}` after the patch
265
+ */
266
+ function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
267
+ if (mutateDocument === void 0) { mutateDocument = true; }
268
+ if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
269
+ if (validateOperation) {
270
+ if (!Array.isArray(patch)) {
271
+ throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
272
+ }
273
+ }
274
+ if (!mutateDocument) {
275
+ document = helpers_js_1._deepClone(document);
276
+ }
277
+ var results = new Array(patch.length);
278
+ for (var i = 0, length_1 = patch.length; i < length_1; i++) {
279
+ // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
280
+ results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
281
+ document = results[i].newDocument; // in case root was replaced
282
+ }
283
+ results.newDocument = document;
284
+ return results;
285
+ }
286
+ exports.applyPatch = applyPatch;
287
+ /**
288
+ * Apply a single JSON Patch Operation on a JSON document.
289
+ * Returns the updated document.
290
+ * Suitable as a reducer.
291
+ *
292
+ * @param document The document to patch
293
+ * @param operation The operation to apply
294
+ * @return The updated document
295
+ */
296
+ function applyReducer(document, operation, index) {
297
+ var operationResult = applyOperation(document, operation);
298
+ if (operationResult.test === false) { // failed test
299
+ throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
300
+ }
301
+ return operationResult.newDocument;
302
+ }
303
+ exports.applyReducer = applyReducer;
304
+ /**
305
+ * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
306
+ * @param {object} operation - operation object (patch)
307
+ * @param {number} index - index of operation in the sequence
308
+ * @param {object} [document] - object where the operation is supposed to be applied
309
+ * @param {string} [existingPathFragment] - comes along with `document`
310
+ */
311
+ function validator(operation, index, document, existingPathFragment) {
312
+ if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
313
+ throw new exports.JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
314
+ }
315
+ else if (!objOps[operation.op]) {
316
+ throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
317
+ }
318
+ else if (typeof operation.path !== 'string') {
319
+ throw new exports.JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
320
+ }
321
+ else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
322
+ // paths that aren't empty string should start with "/"
323
+ throw new exports.JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
324
+ }
325
+ else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
326
+ throw new exports.JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
327
+ }
328
+ else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
329
+ throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
330
+ }
331
+ else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_js_1.hasUndefined(operation.value)) {
332
+ 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);
333
+ }
334
+ else if (document) {
335
+ if (operation.op == "add") {
336
+ var pathLen = operation.path.split("/").length;
337
+ var existingPathLen = existingPathFragment.split("/").length;
338
+ if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
339
+ throw new exports.JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
340
+ }
341
+ }
342
+ else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
343
+ if (operation.path !== existingPathFragment) {
344
+ throw new exports.JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
345
+ }
346
+ }
347
+ else if (operation.op === 'move' || operation.op === 'copy') {
348
+ var existingValue = { op: "_get", path: operation.from, value: undefined };
349
+ var error = validate([existingValue], document);
350
+ if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
351
+ throw new exports.JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
352
+ }
353
+ }
354
+ }
355
+ }
356
+ exports.validator = validator;
357
+ /**
358
+ * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
359
+ * If error is encountered, returns a JsonPatchError object
360
+ * @param sequence
361
+ * @param document
362
+ * @returns {JsonPatchError|undefined}
363
+ */
364
+ function validate(sequence, document, externalValidator) {
365
+ try {
366
+ if (!Array.isArray(sequence)) {
367
+ throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
368
+ }
369
+ if (document) {
370
+ //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
+ }
373
+ else {
374
+ externalValidator = externalValidator || validator;
375
+ for (var i = 0; i < sequence.length; i++) {
376
+ externalValidator(sequence[i], i, document, undefined);
377
+ }
378
+ }
379
+ }
380
+ catch (e) {
381
+ if (e instanceof exports.JsonPatchError) {
382
+ return e;
383
+ }
384
+ else {
385
+ throw e;
386
+ }
387
+ }
388
+ }
389
+ exports.validate = validate;
390
+ // based on https://github.com/epoberezkin/fast-deep-equal
391
+ // MIT License
392
+ // Copyright (c) 2017 Evgeny Poberezkin
393
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
394
+ // of this software and associated documentation files (the "Software"), to deal
395
+ // in the Software without restriction, including without limitation the rights
396
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
397
+ // copies of the Software, and to permit persons to whom the Software is
398
+ // furnished to do so, subject to the following conditions:
399
+ // The above copyright notice and this permission notice shall be included in all
400
+ // copies or substantial portions of the Software.
401
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
402
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
403
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
404
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
405
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
406
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
407
+ // SOFTWARE.
408
+ function _areEquals(a, b) {
409
+ if (a === b)
410
+ return true;
411
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
412
+ var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
413
+ if (arrA && arrB) {
414
+ length = a.length;
415
+ if (length != b.length)
416
+ return false;
417
+ for (i = length; i-- !== 0;)
418
+ if (!_areEquals(a[i], b[i]))
419
+ return false;
420
+ return true;
421
+ }
422
+ if (arrA != arrB)
423
+ return false;
424
+ var keys = Object.keys(a);
425
+ length = keys.length;
426
+ if (length !== Object.keys(b).length)
427
+ return false;
428
+ for (i = length; i-- !== 0;)
429
+ if (!b.hasOwnProperty(keys[i]))
430
+ return false;
431
+ for (i = length; i-- !== 0;) {
432
+ key = keys[i];
433
+ if (!_areEquals(a[key], b[key]))
434
+ return false;
435
+ }
436
+ return true;
437
+ }
438
+ return a !== a && b !== b;
439
+ }
440
+ exports._areEquals = _areEquals;
441
+ ;
@@ -0,0 +1,23 @@
1
+ import { Operation } from './core.js';
2
+ export interface Observer<T> {
3
+ object: T;
4
+ patches: Operation[];
5
+ unobserve: () => void;
6
+ callback: (patches: Operation[]) => void;
7
+ }
8
+ /**
9
+ * Detach an observer from an object
10
+ */
11
+ export declare function unobserve<T>(root: T, observer: Observer<T>): void;
12
+ /**
13
+ * Observes changes made to an object, which can then be retrieved using generate
14
+ */
15
+ export declare function observe<T>(obj: Object | Array<T>, callback?: (patches: Operation[]) => void): Observer<T>;
16
+ /**
17
+ * Generate an array of patches from an observer
18
+ */
19
+ export declare function generate<T>(observer: Observer<Object>, invertible?: boolean): Operation[];
20
+ /**
21
+ * Create an array of patches from the differences in two objects
22
+ */
23
+ export declare function compare(tree1: Object | Array<any>, tree2: Object | Array<any>, invertible?: boolean): Operation[];
@@ -0,0 +1,181 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ /*!
3
+ * https://github.com/Starcounter-Jack/JSON-Patch
4
+ * (c) 2017-2021 Joachim Wester
5
+ * MIT license
6
+ */
7
+ var helpers_js_1 = require("./helpers.js");
8
+ var core_js_1 = require("./core.js");
9
+ var beforeDict = new WeakMap();
10
+ var Mirror = /** @class */ (function () {
11
+ function Mirror(obj) {
12
+ this.observers = new Map();
13
+ this.obj = obj;
14
+ }
15
+ return Mirror;
16
+ }());
17
+ var ObserverInfo = /** @class */ (function () {
18
+ function ObserverInfo(callback, observer) {
19
+ this.callback = callback;
20
+ this.observer = observer;
21
+ }
22
+ return ObserverInfo;
23
+ }());
24
+ function getMirror(obj) {
25
+ return beforeDict.get(obj);
26
+ }
27
+ function getObserverFromMirror(mirror, callback) {
28
+ return mirror.observers.get(callback);
29
+ }
30
+ function removeObserverFromMirror(mirror, observer) {
31
+ mirror.observers.delete(observer.callback);
32
+ }
33
+ /**
34
+ * Detach an observer from an object
35
+ */
36
+ function unobserve(root, observer) {
37
+ observer.unobserve();
38
+ }
39
+ exports.unobserve = unobserve;
40
+ /**
41
+ * Observes changes made to an object, which can then be retrieved using generate
42
+ */
43
+ function observe(obj, callback) {
44
+ var patches = [];
45
+ var observer;
46
+ var mirror = getMirror(obj);
47
+ if (!mirror) {
48
+ mirror = new Mirror(obj);
49
+ beforeDict.set(obj, mirror);
50
+ }
51
+ else {
52
+ var observerInfo = getObserverFromMirror(mirror, callback);
53
+ observer = observerInfo && observerInfo.observer;
54
+ }
55
+ if (observer) {
56
+ return observer;
57
+ }
58
+ observer = {};
59
+ mirror.value = helpers_js_1._deepClone(obj);
60
+ if (callback) {
61
+ observer.callback = callback;
62
+ observer.next = null;
63
+ var dirtyCheck = function () {
64
+ generate(observer);
65
+ };
66
+ var fastCheck = function () {
67
+ clearTimeout(observer.next);
68
+ observer.next = setTimeout(dirtyCheck);
69
+ };
70
+ if (typeof window !== 'undefined') { //not Node
71
+ window.addEventListener('mouseup', fastCheck);
72
+ window.addEventListener('keyup', fastCheck);
73
+ window.addEventListener('mousedown', fastCheck);
74
+ window.addEventListener('keydown', fastCheck);
75
+ window.addEventListener('change', fastCheck);
76
+ }
77
+ }
78
+ observer.patches = patches;
79
+ observer.object = obj;
80
+ observer.unobserve = function () {
81
+ generate(observer);
82
+ clearTimeout(observer.next);
83
+ removeObserverFromMirror(mirror, observer);
84
+ if (typeof window !== 'undefined') {
85
+ window.removeEventListener('mouseup', fastCheck);
86
+ window.removeEventListener('keyup', fastCheck);
87
+ window.removeEventListener('mousedown', fastCheck);
88
+ window.removeEventListener('keydown', fastCheck);
89
+ window.removeEventListener('change', fastCheck);
90
+ }
91
+ };
92
+ mirror.observers.set(callback, new ObserverInfo(callback, observer));
93
+ return observer;
94
+ }
95
+ exports.observe = observe;
96
+ /**
97
+ * Generate an array of patches from an observer
98
+ */
99
+ function generate(observer, invertible) {
100
+ if (invertible === void 0) { invertible = false; }
101
+ var mirror = beforeDict.get(observer.object);
102
+ _generate(mirror.value, observer.object, observer.patches, "", invertible);
103
+ if (observer.patches.length) {
104
+ core_js_1.applyPatch(mirror.value, observer.patches);
105
+ }
106
+ var temp = observer.patches;
107
+ if (temp.length > 0) {
108
+ observer.patches = [];
109
+ if (observer.callback) {
110
+ observer.callback(temp);
111
+ }
112
+ }
113
+ return temp;
114
+ }
115
+ exports.generate = generate;
116
+ // Dirty check if obj is different from mirror, generate patches and update mirror
117
+ function _generate(mirror, obj, patches, path, invertible) {
118
+ if (obj === mirror) {
119
+ return;
120
+ }
121
+ if (typeof obj.toJSON === "function") {
122
+ obj = obj.toJSON();
123
+ }
124
+ var newKeys = helpers_js_1._objectKeys(obj);
125
+ var oldKeys = helpers_js_1._objectKeys(mirror);
126
+ var changed = false;
127
+ var deleted = false;
128
+ //if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
129
+ for (var t = oldKeys.length - 1; t >= 0; t--) {
130
+ var key = oldKeys[t];
131
+ var oldVal = mirror[key];
132
+ if (helpers_js_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
133
+ var newVal = obj[key];
134
+ 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
+ }
137
+ else {
138
+ if (oldVal !== newVal) {
139
+ changed = true;
140
+ if (invertible) {
141
+ patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
142
+ }
143
+ patches.push({ op: "replace", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(newVal) });
144
+ }
145
+ }
146
+ }
147
+ else if (Array.isArray(mirror) === Array.isArray(obj)) {
148
+ if (invertible) {
149
+ patches.push({ op: "test", path: path + "/" + helpers_js_1.escapePathComponent(key), value: helpers_js_1._deepClone(oldVal) });
150
+ }
151
+ patches.push({ op: "remove", path: path + "/" + helpers_js_1.escapePathComponent(key) });
152
+ deleted = true; // property has been deleted
153
+ }
154
+ else {
155
+ if (invertible) {
156
+ patches.push({ op: "test", path: path, value: mirror });
157
+ }
158
+ patches.push({ op: "replace", path: path, value: obj });
159
+ changed = true;
160
+ }
161
+ }
162
+ if (!deleted && newKeys.length == oldKeys.length) {
163
+ return;
164
+ }
165
+ for (var t = 0; t < newKeys.length; t++) {
166
+ 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]) });
169
+ }
170
+ }
171
+ }
172
+ /**
173
+ * Create an array of patches from the differences in two objects
174
+ */
175
+ function compare(tree1, tree2, invertible) {
176
+ if (invertible === void 0) { invertible = false; }
177
+ var patches = [];
178
+ _generate(tree1, tree2, patches, '', invertible);
179
+ return patches;
180
+ }
181
+ exports.compare = compare;
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * https://github.com/Starcounter-Jack/JSON-Patch
3
+ * (c) 2017-2022 Joachim Wester
4
+ * MIT licensed
5
+ */
6
+ export declare function hasOwnProperty(obj: any, key: any): any;
7
+ export declare function _objectKeys(obj: any): any[];
8
+ /**
9
+ * Deeply clone the object.
10
+ * https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
11
+ * @param {any} obj value to clone
12
+ * @return {any} cloned obj
13
+ */
14
+ export declare function _deepClone(obj: any): any;
15
+ export declare function isInteger(str: string): boolean;
16
+ /**
17
+ * Escapes a json pointer path
18
+ * @param path The raw pointer
19
+ * @return the Escaped path
20
+ */
21
+ export declare function escapePathComponent(path: string): string;
22
+ /**
23
+ * Unescapes a json pointer path
24
+ * @param path The escaped pointer
25
+ * @return The unescaped path
26
+ */
27
+ export declare function unescapePathComponent(path: string): string;
28
+ export declare function _getPathRecursive(root: Object, obj: Object): string;
29
+ export declare function getPath(root: Object, obj: Object): string;
30
+ /**
31
+ * Recursively checks whether an object has any undefined values inside.
32
+ */
33
+ export declare function hasUndefined(obj: any): boolean;
34
+ export declare type JsonPatchErrorName = 'SEQUENCE_NOT_AN_ARRAY' | 'OPERATION_NOT_AN_OBJECT' | 'OPERATION_OP_INVALID' | 'OPERATION_PATH_INVALID' | 'OPERATION_FROM_REQUIRED' | 'OPERATION_VALUE_REQUIRED' | 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED' | 'OPERATION_PATH_CANNOT_ADD' | 'OPERATION_PATH_UNRESOLVABLE' | 'OPERATION_FROM_UNRESOLVABLE' | 'OPERATION_PATH_ILLEGAL_ARRAY_INDEX' | 'OPERATION_VALUE_OUT_OF_BOUNDS' | 'TEST_OPERATION_FAILED';
35
+ export declare class PatchError extends Error {
36
+ name: JsonPatchErrorName;
37
+ index?: number;
38
+ operation?: any;
39
+ tree?: any;
40
+ constructor(message: string, name: JsonPatchErrorName, index?: number, operation?: any, tree?: any);
41
+ }