@buoy-gg/jotai 7.0.18 → 7.0.20

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.
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.jotaiSyncAdapter = exports.VALUE_ON_DEVICE = void 0;
7
7
  var _jotaiStateStore = require("../utils/jotaiStateStore");
8
+ var _sharedUi = require("@buoy-gg/shared-ui");
8
9
  /**
9
10
  * Sentinel used in WIRE-FORM snapshots in place of raw prevValue/nextValue.
10
11
  * Same hazard as redux/zustand: up to 200 changes × 2 values on every
@@ -16,47 +17,24 @@ const VALUE_ON_DEVICE = exports.VALUE_ON_DEVICE = Object.freeze({
16
17
  });
17
18
  const MAX_CHANGE_DETAIL_BYTES = 8 * 1024 * 1024;
18
19
  const MAX_WIRE_PAYLOAD_BYTES = 16 * 1024;
19
- function jsonLongerThan(value, limit) {
20
- let bytes = 0;
21
- const stack = [value];
22
- const seen = new Set();
23
- while (stack.length > 0) {
24
- if (bytes > limit) return true;
25
- const v = stack.pop();
26
- if (v === null || v === undefined) bytes += 4;else if (typeof v === "string") bytes += v.length + 2;else if (typeof v === "number") bytes += 8;else if (typeof v === "boolean") bytes += 5;else if (typeof v === "object") {
27
- if (seen.has(v)) continue;
28
- seen.add(v);
29
- if (Array.isArray(v)) {
30
- bytes += 2 + v.length;
31
- for (let i = 0; i < v.length; i++) stack.push(v[i]);
32
- } else {
33
- bytes += 2;
34
- for (const k in v) {
35
- bytes += k.length + 4;
36
- stack.push(v[k]);
37
- }
38
- }
39
- } else bytes += 4;
40
- }
41
- return bytes > limit;
42
- }
20
+ /**
21
+ * Per-change wire cache — the store prepends and never mutates a recorded
22
+ * change, so identity is a correct, self-invalidating key.
23
+ */
24
+ const changeCache = new WeakMap();
43
25
  function toWireChange(change) {
44
- return {
26
+ const cached = changeCache.get(change);
27
+ if (cached) return cached;
28
+ const wire = {
45
29
  ...change,
46
30
  prevValue: VALUE_ON_DEVICE,
47
31
  nextValue: VALUE_ON_DEVICE
48
32
  };
33
+ changeCache.set(change, wire);
34
+ return wire;
49
35
  }
50
36
  function toWireValue(value) {
51
- try {
52
- JSON.stringify(value);
53
- } catch {
54
- return VALUE_ON_DEVICE;
55
- }
56
- if (jsonLongerThan(value, MAX_WIRE_PAYLOAD_BYTES)) {
57
- return VALUE_ON_DEVICE;
58
- }
59
- return value;
37
+ return (0, _sharedUi.isOverWireBudget)(value, MAX_WIRE_PAYLOAD_BYTES) ? VALUE_ON_DEVICE : value;
60
38
  }
61
39
 
62
40
  /**
@@ -117,7 +95,7 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
117
95
  __buoyTruncated: true,
118
96
  note: `Exceeds the ${MAX_CHANGE_DETAIL_BYTES / (1024 * 1024)}MB detail limit — inspect it on-device.`
119
97
  };
120
- const cap = value => jsonLongerThan(value, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : value;
98
+ const cap = value => (0, _sharedUi.isOverWireBudget)(value, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : value;
121
99
  return {
122
100
  found: true,
123
101
  id,
@@ -164,7 +142,7 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
164
142
  return {
165
143
  found: true,
166
144
  label,
167
- currentValue: jsonLongerThan(currentValue, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : currentValue
145
+ currentValue: (0, _sharedUi.isOverWireBudget)(currentValue, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : currentValue
168
146
  };
169
147
  },
170
148
  /**
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  import { jotaiStateStore } from "../utils/jotaiStateStore";
4
+ import { isOverWireBudget } from "@buoy-gg/shared-ui";
5
+
4
6
  /**
5
7
  * Sentinel used in WIRE-FORM snapshots in place of raw prevValue/nextValue.
6
8
  * Same hazard as redux/zustand: up to 200 changes × 2 values on every
@@ -12,47 +14,24 @@ export const VALUE_ON_DEVICE = Object.freeze({
12
14
  });
13
15
  const MAX_CHANGE_DETAIL_BYTES = 8 * 1024 * 1024;
14
16
  const MAX_WIRE_PAYLOAD_BYTES = 16 * 1024;
15
- function jsonLongerThan(value, limit) {
16
- let bytes = 0;
17
- const stack = [value];
18
- const seen = new Set();
19
- while (stack.length > 0) {
20
- if (bytes > limit) return true;
21
- const v = stack.pop();
22
- if (v === null || v === undefined) bytes += 4;else if (typeof v === "string") bytes += v.length + 2;else if (typeof v === "number") bytes += 8;else if (typeof v === "boolean") bytes += 5;else if (typeof v === "object") {
23
- if (seen.has(v)) continue;
24
- seen.add(v);
25
- if (Array.isArray(v)) {
26
- bytes += 2 + v.length;
27
- for (let i = 0; i < v.length; i++) stack.push(v[i]);
28
- } else {
29
- bytes += 2;
30
- for (const k in v) {
31
- bytes += k.length + 4;
32
- stack.push(v[k]);
33
- }
34
- }
35
- } else bytes += 4;
36
- }
37
- return bytes > limit;
38
- }
17
+ /**
18
+ * Per-change wire cache — the store prepends and never mutates a recorded
19
+ * change, so identity is a correct, self-invalidating key.
20
+ */
21
+ const changeCache = new WeakMap();
39
22
  function toWireChange(change) {
40
- return {
23
+ const cached = changeCache.get(change);
24
+ if (cached) return cached;
25
+ const wire = {
41
26
  ...change,
42
27
  prevValue: VALUE_ON_DEVICE,
43
28
  nextValue: VALUE_ON_DEVICE
44
29
  };
30
+ changeCache.set(change, wire);
31
+ return wire;
45
32
  }
46
33
  function toWireValue(value) {
47
- try {
48
- JSON.stringify(value);
49
- } catch {
50
- return VALUE_ON_DEVICE;
51
- }
52
- if (jsonLongerThan(value, MAX_WIRE_PAYLOAD_BYTES)) {
53
- return VALUE_ON_DEVICE;
54
- }
55
- return value;
34
+ return isOverWireBudget(value, MAX_WIRE_PAYLOAD_BYTES) ? VALUE_ON_DEVICE : value;
56
35
  }
57
36
 
58
37
  /**
@@ -113,7 +92,7 @@ export const jotaiSyncAdapter = {
113
92
  __buoyTruncated: true,
114
93
  note: `Exceeds the ${MAX_CHANGE_DETAIL_BYTES / (1024 * 1024)}MB detail limit — inspect it on-device.`
115
94
  };
116
- const cap = value => jsonLongerThan(value, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : value;
95
+ const cap = value => isOverWireBudget(value, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : value;
117
96
  return {
118
97
  found: true,
119
98
  id,
@@ -160,7 +139,7 @@ export const jotaiSyncAdapter = {
160
139
  return {
161
140
  found: true,
162
141
  label,
163
- currentValue: jsonLongerThan(currentValue, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : currentValue
142
+ currentValue: isOverWireBudget(currentValue, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : currentValue
164
143
  };
165
144
  },
166
145
  /**
@@ -42,7 +42,7 @@ export declare const jotaiSyncAdapter: {
42
42
  * The per-snapshot stream stays value-free; this is the explicit,
43
43
  * size-guarded channel for the detail pane.
44
44
  */
45
- getChangeDetail: (params: unknown) => {
45
+ getChangeDetail: (params?: unknown) => {
46
46
  found: false;
47
47
  reason: string;
48
48
  id?: undefined;
@@ -59,7 +59,7 @@ export declare const jotaiSyncAdapter: {
59
59
  * On-demand current value for one atom. Wire-form snapshots replace
60
60
  * oversized / unserializable `currentValue` with VALUE_ON_DEVICE.
61
61
  */
62
- getAtomValue: (params: unknown) => {
62
+ getAtomValue: (params?: unknown) => {
63
63
  found: false;
64
64
  reason: string;
65
65
  label?: undefined;
@@ -76,7 +76,7 @@ export declare const jotaiSyncAdapter: {
76
76
  * unless `includeValues` is set. `writable` tells the caller which atoms
77
77
  * can be set via `setAtom`.
78
78
  */
79
- listAtoms: (params: unknown) => {
79
+ listAtoms: (params?: unknown) => {
80
80
  atoms: {
81
81
  currentValue?: unknown;
82
82
  label: string;
@@ -88,7 +88,7 @@ export declare const jotaiSyncAdapter: {
88
88
  includedValues: boolean;
89
89
  };
90
90
  /** Write a value to a writable atom (throws for unknown/read-only atoms). */
91
- setAtom: (params: unknown) => void;
91
+ setAtom: (params?: unknown) => void;
92
92
  };
93
93
  };
94
94
  //# sourceMappingURL=jotaiSyncAdapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jotaiSyncAdapter.d.ts","sourceRoot":"","sources":["../../../../src/jotai/sync/jotaiSyncAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;EAG1B,CAAC;AAkEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;0BASL,MAAM,IAAI;;;QAY9B;;;;WAIG;kCACuB,OAAO;;;;;;;;;;;;;QAkBjC;;;WAGG;+BACoB,OAAO;;;;;;;;;;;QAgC9B;;;;;WAKG;4BACiB,OAAO;;;;;;;;;;;QA6B3B,6EAA6E;0BAC3D,OAAO;;CAM5B,CAAC"}
1
+ {"version":3,"file":"jotaiSyncAdapter.d.ts","sourceRoot":"","sources":["../../../../src/jotai/sync/jotaiSyncAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;EAG1B,CAAC;AA0CH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;0BASL,MAAM,IAAI;;;QAY9B;;;;WAIG;mCACwB,OAAO;;;;;;;;;;;;;QAkBlC;;;WAGG;gCACqB,OAAO;;;;;;;;;;;QAgC/B;;;;;WAKG;6BACkB,OAAO;;;;;;;;;;;QA6B5B,6EAA6E;2BAC1D,OAAO;;CAM7B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buoy-gg/jotai",
3
- "version": "7.0.18",
3
+ "version": "7.0.20",
4
4
  "description": "Jotai devtools inside your React Native app — every atom write shows prev → next, with per-atom history & live values. Part of Buoy devtools.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -29,8 +29,8 @@
29
29
  "**/snapshotProvider.ts"
30
30
  ],
31
31
  "dependencies": {
32
- "@buoy-gg/license": "^7.0.18",
33
- "@buoy-gg/shared-ui": "^7.0.18"
32
+ "@buoy-gg/license": "^7.0.20",
33
+ "@buoy-gg/shared-ui": "^7.0.20"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "jotai": ">=2.0.0",
@@ -59,7 +59,12 @@
59
59
  "sourceMaps": false
60
60
  }
61
61
  ],
62
- "typescript"
62
+ [
63
+ "typescript",
64
+ {
65
+ "project": "tsconfig.build.json"
66
+ }
67
+ ]
63
68
  ]
64
69
  },
65
70
  "repository": {