@buoy-gg/jotai 7.0.40 → 7.0.42
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/README.md +11 -76
- package/lib/commonjs/index.js +1 -112
- package/lib/commonjs/jotai/components/JotaiAtomBrowser.js +1 -199
- package/lib/commonjs/jotai/components/JotaiAtomChangeItem.js +1 -85
- package/lib/commonjs/jotai/components/JotaiAtomDetailContent.js +1 -715
- package/lib/commonjs/jotai/components/JotaiAtomValueDetailContent.js +1 -444
- package/lib/commonjs/jotai/components/JotaiEventFilterView.js +1 -43
- package/lib/commonjs/jotai/components/JotaiIcon.js +1 -18
- package/lib/commonjs/jotai/components/JotaiModal.js +1 -743
- package/lib/commonjs/jotai/hooks/useJotaiAtomChanges.js +1 -69
- package/lib/commonjs/jotai/sync/jotaiSyncAdapter.js +1 -306
- package/lib/commonjs/jotai/types/index.js +1 -1
- package/lib/commonjs/jotai/utils/jotaiStateStore.js +1 -321
- package/lib/commonjs/jotai/utils/snapshotProvider.js +1 -215
- package/lib/commonjs/jotai/utils/testIDs.js +1 -90
- package/lib/commonjs/jotai/utils/watchAtoms.js +1 -162
- package/lib/commonjs/jotai/utils/writeSemantics.js +1 -47
- package/lib/commonjs/preset.js +1 -90
- package/lib/module/index.js +1 -85
- package/lib/module/jotai/components/JotaiAtomBrowser.js +1 -195
- package/lib/module/jotai/components/JotaiAtomChangeItem.js +1 -81
- package/lib/module/jotai/components/JotaiAtomDetailContent.js +1 -710
- package/lib/module/jotai/components/JotaiAtomValueDetailContent.js +1 -442
- package/lib/module/jotai/components/JotaiEventFilterView.js +1 -39
- package/lib/module/jotai/components/JotaiIcon.js +1 -11
- package/lib/module/jotai/components/JotaiModal.js +1 -738
- package/lib/module/jotai/hooks/useJotaiAtomChanges.js +1 -65
- package/lib/module/jotai/sync/jotaiSyncAdapter.js +1 -303
- package/lib/module/jotai/types/index.js +1 -1
- package/lib/module/jotai/utils/jotaiStateStore.js +1 -317
- package/lib/module/jotai/utils/snapshotProvider.js +1 -214
- package/lib/module/jotai/utils/testIDs.js +1 -82
- package/lib/module/jotai/utils/watchAtoms.js +1 -157
- package/lib/module/jotai/utils/writeSemantics.js +1 -43
- package/lib/module/preset.js +1 -87
- package/lib/web/index.mjs +2 -0
- package/package.json +35 -12
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiAtomBrowser.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiAtomChangeItem.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiAtomDetailContent.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiAtomValueDetailContent.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiEventFilterView.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiIcon.d.ts.map +0 -1
- package/lib/typescript/jotai/components/JotaiModal.d.ts.map +0 -1
- package/lib/typescript/jotai/hooks/useJotaiAtomChanges.d.ts.map +0 -1
- package/lib/typescript/jotai/sync/jotaiSyncAdapter.d.ts.map +0 -1
- package/lib/typescript/jotai/types/index.d.ts.map +0 -1
- package/lib/typescript/jotai/utils/jotaiStateStore.d.ts.map +0 -1
- package/lib/typescript/jotai/utils/snapshotProvider.d.ts.map +0 -1
- package/lib/typescript/jotai/utils/testIDs.d.ts.map +0 -1
- package/lib/typescript/jotai/utils/watchAtoms.d.ts.map +0 -1
- package/lib/typescript/jotai/utils/writeSemantics.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
|
@@ -1,69 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useJotaiAtomChanges = useJotaiAtomChanges;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
9
|
-
var _jotaiStateStore = require("../utils/jotaiStateStore");
|
|
10
|
-
/**
|
|
11
|
-
* Hook for consuming Jotai atom changes from the store
|
|
12
|
-
*
|
|
13
|
-
* The subscribe / filter / pause / clear plumbing is shared `useChangeLog`;
|
|
14
|
-
* this file owns the jotai-specific filter, stats and atom registry.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
function filterChanges(changes, filter) {
|
|
18
|
-
let filtered = changes;
|
|
19
|
-
if (filter.searchText) {
|
|
20
|
-
const search = filter.searchText.toLowerCase();
|
|
21
|
-
filtered = filtered.filter(c => c.atomLabel.toLowerCase().includes(search) || c.valuePreview.toLowerCase().includes(search) || c.changedKeys.some(k => k.toLowerCase().includes(search)));
|
|
22
|
-
}
|
|
23
|
-
if (filter.atomLabels && filter.atomLabels.length > 0) {
|
|
24
|
-
filtered = filtered.filter(c => filter.atomLabels.includes(c.atomLabel));
|
|
25
|
-
}
|
|
26
|
-
if (filter.onlyWithChanges) {
|
|
27
|
-
filtered = filtered.filter(c => c.hasValueChange);
|
|
28
|
-
}
|
|
29
|
-
return filtered;
|
|
30
|
-
}
|
|
31
|
-
const readAtoms = () => _jotaiStateStore.jotaiStateStore.getAtoms();
|
|
32
|
-
const subscribeToAtoms = listener => _jotaiStateStore.jotaiStateStore.subscribeToAtoms(listener);
|
|
33
|
-
function useJotaiAtomChanges() {
|
|
34
|
-
const log = (0, _sharedUi.useChangeLog)(_jotaiStateStore.jotaiStateStore, {
|
|
35
|
-
filterItems: filterChanges
|
|
36
|
-
});
|
|
37
|
-
const atoms = (0, _sharedUi.useSubscribedValue)(readAtoms, subscribeToAtoms);
|
|
38
|
-
const stats = (0, _react.useMemo)(() => {
|
|
39
|
-
const total = log.items.length;
|
|
40
|
-
const withChanges = log.items.filter(c => c.hasValueChange).length;
|
|
41
|
-
return {
|
|
42
|
-
totalChanges: total,
|
|
43
|
-
changesWithValueChange: withChanges,
|
|
44
|
-
changesWithoutValueChange: total - withChanges,
|
|
45
|
-
atomCount: atoms.length
|
|
46
|
-
};
|
|
47
|
-
}, [log.items, atoms]);
|
|
48
|
-
const atomLabels = (0, _react.useMemo)(() => {
|
|
49
|
-
return _jotaiStateStore.jotaiStateStore.getUniqueAtomLabels();
|
|
50
|
-
}, [atoms]);
|
|
51
|
-
const getChangeById = (0, _react.useCallback)(id => {
|
|
52
|
-
return _jotaiStateStore.jotaiStateStore.getAtomChangeById(id);
|
|
53
|
-
}, []);
|
|
54
|
-
return {
|
|
55
|
-
atomChanges: log.items,
|
|
56
|
-
filteredChanges: log.filteredItems,
|
|
57
|
-
filter: log.filter,
|
|
58
|
-
setFilter: log.setFilter,
|
|
59
|
-
stats,
|
|
60
|
-
atoms,
|
|
61
|
-
// Not the shared log.clear: the store also owns each atom's change
|
|
62
|
-
// count, and only clearAtomChanges resets those with the list.
|
|
63
|
-
clearChanges: _jotaiStateStore.jotaiStateStore.clearAtomChanges.bind(_jotaiStateStore.jotaiStateStore),
|
|
64
|
-
isEnabled: log.isEnabled,
|
|
65
|
-
toggleCapture: log.toggleCapture,
|
|
66
|
-
atomLabels,
|
|
67
|
-
getChangeById
|
|
68
|
-
};
|
|
69
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useJotaiAtomChanges=useJotaiAtomChanges;var _react=require("react");var _sharedUi=require("@buoy-gg/shared-ui");var _jotaiStateStore=require("../utils/jotaiStateStore");function filterChanges(e,t){let a=e;if(t.searchText){const s=t.searchText.toLowerCase();a=a.filter(r=>r.atomLabel.toLowerCase().includes(s)||r.valuePreview.toLowerCase().includes(s)||r.changedKeys.some(o=>o.toLowerCase().includes(s)))}if(t.atomLabels&&t.atomLabels.length>0){a=a.filter(s=>t.atomLabels.includes(s.atomLabel))}if(t.onlyWithChanges){a=a.filter(s=>s.hasValueChange)}return a}const readAtoms=()=>_jotaiStateStore.jotaiStateStore.getAtoms();const subscribeToAtoms=e=>_jotaiStateStore.jotaiStateStore.subscribeToAtoms(e);function useJotaiAtomChanges(){const e=(0,_sharedUi.useChangeLog)(_jotaiStateStore.jotaiStateStore,{filterItems:filterChanges});const t=(0,_sharedUi.useSubscribedValue)(readAtoms,subscribeToAtoms);const a=(0,_react.useMemo)(()=>{const o=e.items.length;const n=e.items.filter(i=>i.hasValueChange).length;return{totalChanges:o,changesWithValueChange:n,changesWithoutValueChange:o-n,atomCount:t.length}},[e.items,t]);const s=(0,_react.useMemo)(()=>{return _jotaiStateStore.jotaiStateStore.getUniqueAtomLabels()},[t]);const r=(0,_react.useCallback)(o=>{return _jotaiStateStore.jotaiStateStore.getAtomChangeById(o)},[]);return{atomChanges:e.items,filteredChanges:e.filteredItems,filter:e.filter,setFilter:e.setFilter,stats:a,atoms:t,clearChanges:_jotaiStateStore.jotaiStateStore.clearAtomChanges.bind(_jotaiStateStore.jotaiStateStore),isEnabled:e.isEnabled,toggleCapture:e.toggleCapture,atomLabels:s,getChangeById:r}}
|
|
@@ -1,306 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.jotaiSyncAdapter = exports.VALUE_ON_DEVICE = void 0;
|
|
7
|
-
var _jotaiStateStore = require("../utils/jotaiStateStore");
|
|
8
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
9
|
-
/**
|
|
10
|
-
* Sentinel used in WIRE-FORM snapshots in place of raw prevValue/nextValue.
|
|
11
|
-
* Same hazard as redux/zustand: up to 200 changes × 2 values on every
|
|
12
|
-
* snapshot. Dashboards fetch values via `getChangeDetail`.
|
|
13
|
-
*/
|
|
14
|
-
const VALUE_ON_DEVICE = exports.VALUE_ON_DEVICE = (0, _sharedUi.onDeviceMarker)("Value", "Atom values stay on the device — fetched on demand via getChangeDetail / getAtomValue.");
|
|
15
|
-
const isPlainObj = v => !!v && typeof v === "object" && !Array.isArray(v);
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Merge a patch into an atom's value.
|
|
19
|
-
*
|
|
20
|
-
* An atom is not always an object — plenty hold a number, a string or a list —
|
|
21
|
-
* so a merge only means anything when BOTH sides are plain objects. Anything
|
|
22
|
-
* else replaces, which is what a caller asking to merge a scalar can only have
|
|
23
|
-
* meant. Arrays replace too: the id-addressed form has already been expanded to
|
|
24
|
-
* a whole array by the time this runs, so merging element-wise here would undo
|
|
25
|
-
* the deletion half of that expansion.
|
|
26
|
-
*/
|
|
27
|
-
function deepMergeInto(base, patch) {
|
|
28
|
-
if (!isPlainObj(base) || !isPlainObj(patch)) return patch;
|
|
29
|
-
const out = {
|
|
30
|
-
...base
|
|
31
|
-
};
|
|
32
|
-
for (const [k, v] of Object.entries(patch)) out[k] = k in base ? deepMergeInto(base[k], v) : v;
|
|
33
|
-
return out;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Does this patch write into the list at `path`? Only then is an
|
|
38
|
-
* unchecked-shape warning about that list worth saying.
|
|
39
|
-
*/
|
|
40
|
-
function touchesList(patch, path) {
|
|
41
|
-
let cur = patch;
|
|
42
|
-
for (const seg of path.split(".")) {
|
|
43
|
-
if (!isPlainObj(cur)) return false;
|
|
44
|
-
if (!(seg in cur)) return false;
|
|
45
|
-
cur = cur[seg];
|
|
46
|
-
}
|
|
47
|
-
return Array.isArray(cur) ? cur.length > 0 : !!cur && typeof cur === "object";
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Per-change wire cache — the store prepends and never mutates a recorded
|
|
52
|
-
* change, so identity is a correct, self-invalidating key.
|
|
53
|
-
*/
|
|
54
|
-
const toWireChange = (0, _sharedUi.memoByIdentity)(change => ({
|
|
55
|
-
...change,
|
|
56
|
-
prevValue: VALUE_ON_DEVICE,
|
|
57
|
-
nextValue: VALUE_ON_DEVICE
|
|
58
|
-
}));
|
|
59
|
-
const toWireValue = value => (0, _sharedUi.toWire)(value, VALUE_ON_DEVICE);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Sync adapter for the jotai tool, consumed by @buoy-gg/external-sync's
|
|
63
|
-
* `useExternalSync`.
|
|
64
|
-
*
|
|
65
|
-
* Atom changes are captured by watchAtoms(), independent of whether a
|
|
66
|
-
* dashboard is watching — subscribing here only streams what the store
|
|
67
|
-
* already records. The snapshot carries both the change timeline and the
|
|
68
|
-
* atom registry (with each atom's current value) so the dashboard can render
|
|
69
|
-
* the atom browser.
|
|
70
|
-
*
|
|
71
|
-
* v2: change-log prevValue/nextValue are replaced with on-device markers.
|
|
72
|
-
* Dashboards fetch values via `getChangeDetail`. Oversized / unserializable
|
|
73
|
-
* `atoms[].currentValue` uses the same marker and is fetched via `getAtomValue`.
|
|
74
|
-
*/
|
|
75
|
-
const jotaiSyncAdapter = exports.jotaiSyncAdapter = (0, _sharedUi.createSyncAdapter)({
|
|
76
|
-
version: 2,
|
|
77
|
-
getSnapshot: () => ({
|
|
78
|
-
changes: _jotaiStateStore.jotaiStateStore.getAtomChanges().map(toWireChange),
|
|
79
|
-
atoms: _jotaiStateStore.jotaiStateStore.getAtomSnapshots().map(atom => ({
|
|
80
|
-
...atom,
|
|
81
|
-
currentValue: toWireValue(atom.currentValue)
|
|
82
|
-
}))
|
|
83
|
-
}),
|
|
84
|
-
subscribe: [onChange => _jotaiStateStore.jotaiStateStore.subscribe(onChange), onChange => _jotaiStateStore.jotaiStateStore.subscribeToAtoms(onChange)],
|
|
85
|
-
actions: {
|
|
86
|
-
clearEvents: () => {
|
|
87
|
-
_jotaiStateStore.jotaiStateStore.clearAtomChanges();
|
|
88
|
-
},
|
|
89
|
-
/**
|
|
90
|
-
* On-demand detail: one change's real prevValue/nextValue.
|
|
91
|
-
* The per-snapshot stream stays value-free; this is the explicit,
|
|
92
|
-
* size-guarded channel for the detail pane.
|
|
93
|
-
*/
|
|
94
|
-
getChangeDetail: (0, _sharedUi.detailByIdAction)(id => _jotaiStateStore.jotaiStateStore.getAtomChangeById(id), (change, cap) => ({
|
|
95
|
-
prevValue: cap(change.prevValue),
|
|
96
|
-
nextValue: cap(change.nextValue)
|
|
97
|
-
})),
|
|
98
|
-
/**
|
|
99
|
-
* On-demand current value for one atom. Wire-form snapshots replace
|
|
100
|
-
* oversized / unserializable `currentValue` with VALUE_ON_DEVICE.
|
|
101
|
-
*/
|
|
102
|
-
getAtomValue: params => {
|
|
103
|
-
const {
|
|
104
|
-
label,
|
|
105
|
-
path
|
|
106
|
-
} = (0, _sharedUi.readParams)(params);
|
|
107
|
-
if (!label) return {
|
|
108
|
-
found: false,
|
|
109
|
-
reason: "missing label"
|
|
110
|
-
};
|
|
111
|
-
const atom = _jotaiStateStore.jotaiStateStore.getAtom(label);
|
|
112
|
-
if (!atom) return {
|
|
113
|
-
found: false,
|
|
114
|
-
reason: "unknown label"
|
|
115
|
-
};
|
|
116
|
-
let currentValue;
|
|
117
|
-
try {
|
|
118
|
-
currentValue = atom.getValue();
|
|
119
|
-
} catch {
|
|
120
|
-
currentValue = undefined;
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
JSON.stringify(currentValue);
|
|
124
|
-
} catch {
|
|
125
|
-
return {
|
|
126
|
-
found: true,
|
|
127
|
-
label,
|
|
128
|
-
currentValue: VALUE_ON_DEVICE
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
// One slice instead of the whole atom, when asked. The reason to want it
|
|
132
|
-
// is the engine's 24,000-character result cap: a caller that never saw the
|
|
133
|
-
// field it means to edit is left inventing a shape.
|
|
134
|
-
if (path) {
|
|
135
|
-
const at = (0, _sharedUi.readPath)(currentValue, path);
|
|
136
|
-
if (!at.ok) return {
|
|
137
|
-
found: false,
|
|
138
|
-
reason: at.error
|
|
139
|
-
};
|
|
140
|
-
return {
|
|
141
|
-
found: true,
|
|
142
|
-
label,
|
|
143
|
-
path,
|
|
144
|
-
shape: (0, _sharedUi.shapeSummary)(at.value),
|
|
145
|
-
currentValue: at.value
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
// `shape` BEFORE `currentValue`: a result is truncated by slicing the
|
|
149
|
-
// encoded string, so what is serialised first is what survives the cut,
|
|
150
|
-
// and the sketch does not grow with the data.
|
|
151
|
-
return {
|
|
152
|
-
found: true,
|
|
153
|
-
label,
|
|
154
|
-
...((0, _sharedUi.shapeSummary)(currentValue) ? {
|
|
155
|
-
shape: (0, _sharedUi.shapeSummary)(currentValue)
|
|
156
|
-
} : {}),
|
|
157
|
-
currentValue: (0, _sharedUi.capDetail)(currentValue, _sharedUi.WIRE_DETAIL_LIMIT_BYTES)
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
/**
|
|
161
|
-
* Compact current-value reader for a remote driver (MCP/LLM): registered
|
|
162
|
-
* atoms with light metadata; each atom's `currentValue` stays on the device
|
|
163
|
-
* unless `includeValues` is set. `writable` tells the caller which atoms
|
|
164
|
-
* can be set via `setAtom`.
|
|
165
|
-
*/
|
|
166
|
-
listAtoms: params => {
|
|
167
|
-
const {
|
|
168
|
-
includeValues = false,
|
|
169
|
-
limit
|
|
170
|
-
} = (0, _sharedUi.readParams)(params);
|
|
171
|
-
const all = _jotaiStateStore.jotaiStateStore.getAtoms();
|
|
172
|
-
const capped = typeof limit === "number" && limit > 0 ? all.slice(0, limit) : all;
|
|
173
|
-
const atoms = capped.map(a => {
|
|
174
|
-
let value;
|
|
175
|
-
if (includeValues) {
|
|
176
|
-
try {
|
|
177
|
-
value = a.getValue();
|
|
178
|
-
} catch {
|
|
179
|
-
value = undefined;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
// The compact view is what a caller reaches for precisely because it
|
|
183
|
-
// does not want the data; the item shape of a list is the one thing it
|
|
184
|
-
// cannot infer without it, and it costs a line.
|
|
185
|
-
let shape;
|
|
186
|
-
try {
|
|
187
|
-
shape = (0, _sharedUi.shapeSummary)(a.getValue());
|
|
188
|
-
} catch {
|
|
189
|
-
shape = undefined;
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
label: a.label,
|
|
193
|
-
changes: a.changeCount,
|
|
194
|
-
writable: typeof a.setValue === "function",
|
|
195
|
-
...(shape ? {
|
|
196
|
-
shape
|
|
197
|
-
} : {}),
|
|
198
|
-
...(includeValues ? {
|
|
199
|
-
currentValue: value
|
|
200
|
-
} : {})
|
|
201
|
-
};
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
atoms,
|
|
205
|
-
total: all.length,
|
|
206
|
-
returned: atoms.length,
|
|
207
|
-
includedValues: includeValues
|
|
208
|
-
};
|
|
209
|
-
},
|
|
210
|
-
/**
|
|
211
|
-
* Write to a writable atom (throws for unknown/read-only atoms).
|
|
212
|
-
*
|
|
213
|
-
* THIS USED TO BE FOUR LINES WITH NO GUARD. `setAtom` took whatever it was
|
|
214
|
-
* given and wrote it: a string over a number, `null` over a list the screen
|
|
215
|
-
* maps, a one-item array over a fifty-item one — every failure mode the
|
|
216
|
-
* zustand and react-query adapters refuse, jotai accepted silently. It was
|
|
217
|
-
* the only writable state tool with no protection at all, and it had never
|
|
218
|
-
* had an eval case, so nothing had ever measured it.
|
|
219
|
-
*
|
|
220
|
-
* It now takes the same three forms as `zustand.setState`, backed by the
|
|
221
|
-
* same shared implementations:
|
|
222
|
-
* { value } replace (guarded unless force)
|
|
223
|
-
* { value, merge: true } merge a patch, id-addressed lists allowed
|
|
224
|
-
* { path, value } set one value; no depth to get wrong
|
|
225
|
-
*/
|
|
226
|
-
setAtom: params => {
|
|
227
|
-
const {
|
|
228
|
-
label,
|
|
229
|
-
value,
|
|
230
|
-
merge,
|
|
231
|
-
path,
|
|
232
|
-
force
|
|
233
|
-
} = (0, _sharedUi.readParams)(params);
|
|
234
|
-
if (!label) throw new Error("setAtom requires a `label`");
|
|
235
|
-
const atom = _jotaiStateStore.jotaiStateStore.getAtom(label);
|
|
236
|
-
let current;
|
|
237
|
-
try {
|
|
238
|
-
current = atom?.getValue();
|
|
239
|
-
} catch {
|
|
240
|
-
current = undefined;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// A replace with no guard is the old behaviour; keep it reachable via
|
|
244
|
-
// `force`, and keep it the ONLY way to get it.
|
|
245
|
-
let effective = value;
|
|
246
|
-
let keyedNotes = [];
|
|
247
|
-
let unchecked = [];
|
|
248
|
-
const merging = merge === true || path !== undefined;
|
|
249
|
-
if (path !== undefined) {
|
|
250
|
-
if (value === undefined) {
|
|
251
|
-
return {
|
|
252
|
-
ok: false,
|
|
253
|
-
error: `Refused: sent \`path\` without \`value\`. Say what to set "${path}" to.`
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
const built = (0, _sharedUi.patchFromPath)(current, path, value);
|
|
257
|
-
if (!built.ok) return {
|
|
258
|
-
ok: false,
|
|
259
|
-
error: `Refused: ${built.error}`
|
|
260
|
-
};
|
|
261
|
-
effective = built.patch;
|
|
262
|
-
}
|
|
263
|
-
if (!force && merging && current !== undefined) {
|
|
264
|
-
const expanded = (0, _sharedUi.expandKeyedArrays)(current, effective);
|
|
265
|
-
// See keyedArrays.ts: an added item whose id disagrees with the key it
|
|
266
|
-
// was sent under is ambiguous, and only this layer can say so.
|
|
267
|
-
if (expanded.error) {
|
|
268
|
-
return {
|
|
269
|
-
ok: false,
|
|
270
|
-
error: `Refused: ${expanded.error}`
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
effective = expanded.patch;
|
|
274
|
-
keyedNotes = expanded.notes;
|
|
275
|
-
unchecked = (0, _sharedUi.unshapedLists)(current).filter(p => touchesList(effective, p));
|
|
276
|
-
const violations = (0, _sharedUi.typedEditViolations)(current, effective, {
|
|
277
|
-
noun: "atom"
|
|
278
|
-
});
|
|
279
|
-
if (violations.length) {
|
|
280
|
-
const suggestion = (0, _sharedUi.suggestedPatch)(effective, violations);
|
|
281
|
-
return {
|
|
282
|
-
ok: false,
|
|
283
|
-
error: (0, _sharedUi.refusalText)(violations, "atom", suggestion),
|
|
284
|
-
violations,
|
|
285
|
-
...(suggestion ? {
|
|
286
|
-
suggestedValue: suggestion
|
|
287
|
-
} : {})
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
_jotaiStateStore.jotaiStateStore.setAtomValue(label, merging ? deepMergeInto(current, effective) : effective);
|
|
292
|
-
return {
|
|
293
|
-
ok: true,
|
|
294
|
-
...(path !== undefined ? {
|
|
295
|
-
path
|
|
296
|
-
} : {}),
|
|
297
|
-
...(keyedNotes.length ? {
|
|
298
|
-
keyed: keyedNotes
|
|
299
|
-
} : {}),
|
|
300
|
-
...(unchecked.length ? {
|
|
301
|
-
unchecked: unchecked.map(p => `\`${p}\` was empty, so nothing knows what its items look like and the shape of what you added was NOT checked.`)
|
|
302
|
-
} : {})
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.jotaiSyncAdapter=exports.VALUE_ON_DEVICE=void 0;var _jotaiStateStore=require("../utils/jotaiStateStore");var _sharedUi=require("@buoy-gg/shared-ui");const VALUE_ON_DEVICE=exports.VALUE_ON_DEVICE=(0,_sharedUi.onDeviceMarker)("Value","Atom values stay on the device \u2014 fetched on demand via getChangeDetail / getAtomValue.");const isPlainObj=e=>!!e&&typeof e==="object"&&!Array.isArray(e);function deepMergeInto(e,r){if(!isPlainObj(e)||!isPlainObj(r))return r;const t={...e};for(const[o,a]of Object.entries(r))t[o]=o in e?deepMergeInto(e[o],a):a;return t}function touchesList(e,r){let t=e;for(const o of r.split(".")){if(!isPlainObj(t))return false;if(!(o in t))return false;t=t[o]}return Array.isArray(t)?t.length>0:!!t&&typeof t==="object"}const toWireChange=(0,_sharedUi.memoByIdentity)(e=>({...e,prevValue:VALUE_ON_DEVICE,nextValue:VALUE_ON_DEVICE}));const toWireValue=e=>(0,_sharedUi.toWire)(e,VALUE_ON_DEVICE);const jotaiSyncAdapter=exports.jotaiSyncAdapter=(0,_sharedUi.createSyncAdapter)({version:2,getSnapshot:()=>({changes:_jotaiStateStore.jotaiStateStore.getAtomChanges().map(toWireChange),atoms:_jotaiStateStore.jotaiStateStore.getAtomSnapshots().map(e=>({...e,currentValue:toWireValue(e.currentValue)}))}),subscribe:[e=>_jotaiStateStore.jotaiStateStore.subscribe(e),e=>_jotaiStateStore.jotaiStateStore.subscribeToAtoms(e)],actions:{clearEvents:()=>{_jotaiStateStore.jotaiStateStore.clearAtomChanges()},getChangeDetail:(0,_sharedUi.detailByIdAction)(e=>_jotaiStateStore.jotaiStateStore.getAtomChangeById(e),(e,r)=>({prevValue:r(e.prevValue),nextValue:r(e.nextValue)})),getAtomValue:e=>{const{label:r,path:t}=(0,_sharedUi.readParams)(e);if(!r)return{found:false,reason:"missing label"};const o=_jotaiStateStore.jotaiStateStore.getAtom(r);if(!o)return{found:false,reason:"unknown label"};let a;try{a=o.getValue()}catch{a=void 0}try{JSON.stringify(a)}catch{return{found:true,label:r,currentValue:VALUE_ON_DEVICE}}if(t){const i=(0,_sharedUi.readPath)(a,t);if(!i.ok)return{found:false,reason:i.error};return{found:true,label:r,path:t,shape:(0,_sharedUi.shapeSummary)(i.value),currentValue:i.value}}return{found:true,label:r,...(0,_sharedUi.shapeSummary)(a)?{shape:(0,_sharedUi.shapeSummary)(a)}:{},currentValue:(0,_sharedUi.capDetail)(a,_sharedUi.WIRE_DETAIL_LIMIT_BYTES)}},listAtoms:e=>{const{includeValues:r=false,limit:t}=(0,_sharedUi.readParams)(e);const o=_jotaiStateStore.jotaiStateStore.getAtoms();const a=typeof t==="number"&&t>0?o.slice(0,t):o;const i=a.map(l=>{let s;if(r){try{s=l.getValue()}catch{s=void 0}}let n;try{n=(0,_sharedUi.shapeSummary)(l.getValue())}catch{n=void 0}return{label:l.label,changes:l.changeCount,writable:typeof l.setValue==="function",...n?{shape:n}:{},...r?{currentValue:s}:{}}});return{atoms:i,total:o.length,returned:i.length,includedValues:r}},setAtom:e=>{const{label:r,value:t,merge:o,path:a,force:i}=(0,_sharedUi.readParams)(e);if(!r)throw new Error("setAtom requires a `label`");const l=_jotaiStateStore.jotaiStateStore.getAtom(r);let s;try{s=l?.getValue()}catch{s=void 0}let n=t;let f=[];let h=[];const m=o===true||a!==void 0;if(a!==void 0){if(t===void 0){return{ok:false,error:`Refused: sent \`path\` without \`value\`. Say what to set "${a}" to.`}}const u=(0,_sharedUi.patchFromPath)(s,a,t);if(!u.ok)return{ok:false,error:`Refused: ${u.error}`};n=u.patch}if(!i&&m&&s!==void 0){const u=(0,_sharedUi.expandKeyedArrays)(s,n);if(u.error){return{ok:false,error:`Refused: ${u.error}`}}n=u.patch;f=u.notes;h=(0,_sharedUi.unshapedLists)(s).filter(c=>touchesList(n,c));const d=(0,_sharedUi.typedEditViolations)(s,n,{noun:"atom"});if(d.length){const c=(0,_sharedUi.suggestedPatch)(n,d);return{ok:false,error:(0,_sharedUi.refusalText)(d,"atom",c),violations:d,...c?{suggestedValue:c}:{}}}}_jotaiStateStore.jotaiStateStore.setAtomValue(r,m?deepMergeInto(s,n):n);return{ok:true,...a!==void 0?{path:a}:{},...f.length?{keyed:f}:{},...h.length?{unchecked:h.map(u=>`\`${u}\` was empty, so nothing knows what its items look like and the shape of what you added was NOT checked.`)}:{}}}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|