@twin.org/core 0.0.1-next.48 → 0.0.1-next.49
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.
package/dist/cjs/index.cjs
CHANGED
|
@@ -2353,12 +2353,15 @@ class Converter {
|
|
|
2353
2353
|
}
|
|
2354
2354
|
}
|
|
2355
2355
|
|
|
2356
|
-
// Copyright 2024 IOTA Stiftung.
|
|
2357
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
2358
2356
|
/**
|
|
2359
2357
|
* Helpers methods for JSON objects.
|
|
2360
2358
|
*/
|
|
2361
2359
|
class JsonHelper {
|
|
2360
|
+
/**
|
|
2361
|
+
* Runtime name for the class.
|
|
2362
|
+
* @internal
|
|
2363
|
+
*/
|
|
2364
|
+
static _CLASS_NAME = "JsonHelper";
|
|
2362
2365
|
/**
|
|
2363
2366
|
* Serializes in canonical format.
|
|
2364
2367
|
* Based on https://www.rfc-editor.org/rfc/rfc8785.
|
|
@@ -2417,9 +2420,17 @@ class JsonHelper {
|
|
|
2417
2420
|
* @param object The object to patch.
|
|
2418
2421
|
* @param patches The second object.
|
|
2419
2422
|
* @returns The updated object.
|
|
2423
|
+
* @throws GeneralError if the patch fails.
|
|
2420
2424
|
*/
|
|
2421
2425
|
static patch(object, patches) {
|
|
2422
|
-
|
|
2426
|
+
const clone = ObjectHelper.clone(object);
|
|
2427
|
+
const result = rfc6902.applyPatch(clone, patches);
|
|
2428
|
+
for (let i = 0; i < result.length; i++) {
|
|
2429
|
+
if (!Is.empty(result[i])) {
|
|
2430
|
+
throw new GeneralError(JsonHelper._CLASS_NAME, "failedPatch", { index: i }, result[i]);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
return clone;
|
|
2423
2434
|
}
|
|
2424
2435
|
/**
|
|
2425
2436
|
* Stringify the JSON with support for extended data types date/bigint/uint8array.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2351,12 +2351,15 @@ class Converter {
|
|
|
2351
2351
|
}
|
|
2352
2352
|
}
|
|
2353
2353
|
|
|
2354
|
-
// Copyright 2024 IOTA Stiftung.
|
|
2355
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
2356
2354
|
/**
|
|
2357
2355
|
* Helpers methods for JSON objects.
|
|
2358
2356
|
*/
|
|
2359
2357
|
class JsonHelper {
|
|
2358
|
+
/**
|
|
2359
|
+
* Runtime name for the class.
|
|
2360
|
+
* @internal
|
|
2361
|
+
*/
|
|
2362
|
+
static _CLASS_NAME = "JsonHelper";
|
|
2360
2363
|
/**
|
|
2361
2364
|
* Serializes in canonical format.
|
|
2362
2365
|
* Based on https://www.rfc-editor.org/rfc/rfc8785.
|
|
@@ -2415,9 +2418,17 @@ class JsonHelper {
|
|
|
2415
2418
|
* @param object The object to patch.
|
|
2416
2419
|
* @param patches The second object.
|
|
2417
2420
|
* @returns The updated object.
|
|
2421
|
+
* @throws GeneralError if the patch fails.
|
|
2418
2422
|
*/
|
|
2419
2423
|
static patch(object, patches) {
|
|
2420
|
-
|
|
2424
|
+
const clone = ObjectHelper.clone(object);
|
|
2425
|
+
const result = applyPatch(clone, patches);
|
|
2426
|
+
for (let i = 0; i < result.length; i++) {
|
|
2427
|
+
if (!Is.empty(result[i])) {
|
|
2428
|
+
throw new GeneralError(JsonHelper._CLASS_NAME, "failedPatch", { index: i }, result[i]);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return clone;
|
|
2421
2432
|
}
|
|
2422
2433
|
/**
|
|
2423
2434
|
* Stringify the JSON with support for extended data types date/bigint/uint8array.
|
|
@@ -24,6 +24,7 @@ export declare class JsonHelper {
|
|
|
24
24
|
* @param object The object to patch.
|
|
25
25
|
* @param patches The second object.
|
|
26
26
|
* @returns The updated object.
|
|
27
|
+
* @throws GeneralError if the patch fails.
|
|
27
28
|
*/
|
|
28
29
|
static patch<T = unknown>(object: T, patches: IPatchOperation[]): T;
|
|
29
30
|
/**
|
package/docs/changelog.md
CHANGED
package/locales/en.json
CHANGED
|
@@ -95,6 +95,9 @@
|
|
|
95
95
|
},
|
|
96
96
|
"base58": {
|
|
97
97
|
"invalidCharacter": "Data contains a character \"{invalidCharacter}\" which is not in the charset"
|
|
98
|
+
},
|
|
99
|
+
"jsonHelper": {
|
|
100
|
+
"failedPatch": "Failed to patch the JSON object, patch index \"{index}\" failed"
|
|
98
101
|
}
|
|
99
102
|
},
|
|
100
103
|
"errorNames": {
|