asab_webui_shell 27.3.8 → 27.3.9

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.
@@ -10,6 +10,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
  var _axios = _interopRequireDefault(require("axios"));
12
12
  var _asab_webui_components = require("asab_webui_components");
13
+ var _jsonParseWithBigInt2 = require("../utils/jsonParseWithBigInt");
13
14
  var _Header = _interopRequireDefault(require("./Header"));
14
15
  var _Sidebar = _interopRequireDefault(require("./Sidebar"));
15
16
  var _ToastContainer = _interopRequireDefault(require("./Toast/ToastContainer.js"));
@@ -253,34 +254,8 @@ class Application extends _react.Component {
253
254
  * - Only explicitly configured keys are converted to BigInt
254
255
  */
255
256
  jsonParseWithBigInt(source) {
256
- // If the input is not a string, return it immediately (no parsing needed)
257
- if (typeof source !== 'string') {
258
- return source;
259
- }
260
-
261
- // Save reference to 'this' for accessing instance properties
262
- var that = this;
263
-
264
- // Fast path: if no BigInt keys are configured, parse the JSON normally
265
- if (!that.JSONParseBigInt || that.JSONParseBigInt.size === 0) {
266
- return JSON.parse(source);
267
- }
268
-
269
- // Parse the JSON string with a custom reviver function to handle BigInt
270
- return JSON.parse(source, (key, value, context) => {
271
- try {
272
- // Convert numeric values to BigInt only for explicitly configured keys
273
- if (that.JSONParseBigInt.has(key) && typeof value === 'number' && (context === null || context === void 0 ? void 0 : context.source) !== undefined) {
274
- // Convert the numeric value to a BigInt to avoid precision loss
275
- return BigInt(context.source);
276
- }
277
- } catch (e) {
278
- console.error("Error converting to BigInt:", e, "key:", key, "value:", value);
279
- }
280
-
281
- // For all other keys/values, return the value as-is
282
- return value;
283
- });
257
+ // Use the internal function to parse the JSON with BigInt
258
+ return (0, _jsonParseWithBigInt2.jsonParseWithBigInt)(source, this.JSONParseBigInt);
284
259
  }
285
260
 
286
261
  /*
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.jsonParseWithBigInt = jsonParseWithBigInt;
7
+ /**
8
+ * Safely parses a JSON string, converting numeric values to BigInt for
9
+ * explicitly configured keys to avoid JavaScript's Number precision loss
10
+ * above Number.MAX_SAFE_INTEGER.
11
+ *
12
+ * @param {string} source - Raw JSON string to parse.
13
+ * @param {Set<string>} bigIntKeys - Set of JSON keys whose values should be
14
+ * converted to BigInt. Each key is the leaf property name as it appears
15
+ * in the JSON (e.g. "h", "related.events").
16
+ *
17
+ * Supported value shapes for a configured key:
18
+ * - Scalar number: BigInt via context.source (no precision loss)
19
+ * - Array of numbers: each element converted via context.source
20
+ */
21
+ function jsonParseWithBigInt(source, bigIntKeys) {
22
+ if (typeof source !== 'string') {
23
+ return source;
24
+ }
25
+ if (!(bigIntKeys !== null && bigIntKeys !== void 0 && bigIntKeys.size)) {
26
+ return JSON.parse(source);
27
+ }
28
+
29
+ /*
30
+ Bottom-up reviver order means array *elements* are visited before the
31
+ parent named key. It collect each numeric element's original source text
32
+ in a WeakMap keyed by the array reference, then convert them when the
33
+ named key is finally visited.
34
+ */
35
+ var pending = new WeakMap();
36
+ return JSON.parse(source, function (key, value, context) {
37
+ // Inside an array: stash the raw source text for numeric elements.
38
+ if (Array.isArray(this) && typeof value === 'number' && (context === null || context === void 0 ? void 0 : context.source) != undefined) {
39
+ if (!pending.has(this)) {
40
+ pending.set(this, []);
41
+ }
42
+ pending.get(this).push({
43
+ index: Number(key),
44
+ src: context.source
45
+ });
46
+ return value; // will be replaced when the named key is visited
47
+ }
48
+ if (!bigIntKeys.has(key)) {
49
+ return value;
50
+ }
51
+ try {
52
+ // Scalar number: use context.source to preserve exact digits.
53
+ if (typeof value === 'number' && (context === null || context === void 0 ? void 0 : context.source) != undefined) {
54
+ return BigInt(context.source);
55
+ }
56
+ /*
57
+ Array of numbers: apply the stashed sources. Convert on a copy and return it only if
58
+ all elements are converted successfully. This prevents mixed arrays on failure.
59
+ */
60
+ if (Array.isArray(value)) {
61
+ var convertedArray = [...value];
62
+ var numericSources = pending.get(value) || [];
63
+ numericSources.forEach(_ref => {
64
+ var {
65
+ index,
66
+ src
67
+ } = _ref;
68
+ convertedArray[index] = BigInt(src);
69
+ });
70
+ return convertedArray;
71
+ }
72
+ } catch (e) {
73
+ console.error("Error converting to BigInt:", e, "key:", key, "value:", value);
74
+ }
75
+ return value;
76
+ });
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_shell",
3
- "version": "27.3.8",
3
+ "version": "27.3.9",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Shell Application",
6
6
  "contributors": [