@buoy-gg/zustand 7.0.35 → 7.0.36
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.
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.zustandSyncAdapter = exports.STATE_ON_DEVICE = exports.PAYLOAD_ON_DEVICE = void 0;
|
|
7
|
-
var _zustandStateStore = require("../utils/zustandStateStore");
|
|
8
7
|
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
8
|
+
var _zustandStateStore = require("../utils/zustandStateStore");
|
|
9
9
|
/**
|
|
10
10
|
* Sentinel used in WIRE-FORM snapshots in place of raw prevState/nextState.
|
|
11
11
|
* Same hazard as redux: up to 200 changes × 2 full trees on every snapshot
|
|
@@ -15,6 +15,23 @@ const STATE_ON_DEVICE = exports.STATE_ON_DEVICE = (0, _sharedUi.onDeviceMarker)(
|
|
|
15
15
|
|
|
16
16
|
/** Wire-form sentinel for an oversized `partial` (replace can carry a whole tree). */
|
|
17
17
|
const PAYLOAD_ON_DEVICE = exports.PAYLOAD_ON_DEVICE = (0, _sharedUi.onDeviceMarker)("Payload", "Partial stays on the device — fetched on demand via getChangeDetail.");
|
|
18
|
+
const isPlainObject = v => !!v && typeof v === "object" && !Array.isArray(v);
|
|
19
|
+
/**
|
|
20
|
+
* Does this patch write into the list at `path`? Only then is an unchecked-shape
|
|
21
|
+
* warning about that list worth saying — a patch that changes `promoCode` should
|
|
22
|
+
* not be told about an empty `lines`.
|
|
23
|
+
*/
|
|
24
|
+
function touchesList(patch, path) {
|
|
25
|
+
let cur = patch;
|
|
26
|
+
for (const seg of path.split(".")) {
|
|
27
|
+
if (!cur || typeof cur !== "object" || Array.isArray(cur)) return false;
|
|
28
|
+
if (!(seg in cur)) return false;
|
|
29
|
+
cur = cur[seg];
|
|
30
|
+
}
|
|
31
|
+
// An empty list stays empty; there is no new item to be unsure about.
|
|
32
|
+
return Array.isArray(cur) ? cur.length > 0 : !!cur && typeof cur === "object";
|
|
33
|
+
}
|
|
34
|
+
|
|
18
35
|
/** Top-level keys of an object state, for the compact (no-values) view. */
|
|
19
36
|
function topLevelKeys(state) {
|
|
20
37
|
return state && typeof state === "object" && !Array.isArray(state) ? Object.keys(state) : undefined;
|
|
@@ -80,7 +97,8 @@ const zustandSyncAdapter = exports.zustandSyncAdapter = (0, _sharedUi.createSync
|
|
|
80
97
|
*/
|
|
81
98
|
getStoreState: params => {
|
|
82
99
|
const {
|
|
83
|
-
storeName
|
|
100
|
+
storeName,
|
|
101
|
+
path
|
|
84
102
|
} = (0, _sharedUi.readParams)(params);
|
|
85
103
|
if (!storeName) return {
|
|
86
104
|
found: false,
|
|
@@ -97,16 +115,46 @@ const zustandSyncAdapter = exports.zustandSyncAdapter = (0, _sharedUi.createSync
|
|
|
97
115
|
} catch {
|
|
98
116
|
currentState = undefined;
|
|
99
117
|
}
|
|
118
|
+
// One slice instead of the whole store. The reason to want it is the
|
|
119
|
+
// engine's 24,000-character result cap: a caller that never saw the field
|
|
120
|
+
// it means to edit is left inventing a shape, which is the failure this
|
|
121
|
+
// whole surface keeps producing.
|
|
122
|
+
if (path) {
|
|
123
|
+
const at = (0, _sharedUi.readPath)(currentState, path);
|
|
124
|
+
if (!at.ok) return {
|
|
125
|
+
found: false,
|
|
126
|
+
reason: at.error
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
found: true,
|
|
130
|
+
storeName,
|
|
131
|
+
path,
|
|
132
|
+
shape: (0, _sharedUi.shapeSummary)(at.value),
|
|
133
|
+
currentState: at.value
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// The sketch goes BEFORE currentState, deliberately. The engine truncates
|
|
137
|
+
// a result by slicing the encoded string at 24,000 characters, so whatever
|
|
138
|
+
// is serialised first is what survives — and the reads most in need of a
|
|
139
|
+
// shape are exactly the long ones that get cut. It costs ~150 characters
|
|
140
|
+
// and does not grow with the data.
|
|
141
|
+
const shape = (0, _sharedUi.shapeSummary)(currentState);
|
|
100
142
|
if (!(0, _sharedUi.isOverWireBudget)(currentState, _sharedUi.WIRE_DETAIL_LIMIT_BYTES)) {
|
|
101
143
|
return {
|
|
102
144
|
found: true,
|
|
103
145
|
storeName,
|
|
146
|
+
...(shape ? {
|
|
147
|
+
shape
|
|
148
|
+
} : {}),
|
|
104
149
|
currentState
|
|
105
150
|
};
|
|
106
151
|
}
|
|
107
152
|
return {
|
|
108
153
|
found: true,
|
|
109
154
|
storeName,
|
|
155
|
+
...(shape ? {
|
|
156
|
+
shape
|
|
157
|
+
} : {}),
|
|
110
158
|
currentState: (0, _sharedUi.isJsonSerializable)(currentState) ? (0, _sharedUi.truncatedNote)(_sharedUi.WIRE_DETAIL_LIMIT_BYTES) : STATE_ON_DEVICE
|
|
111
159
|
};
|
|
112
160
|
},
|
|
@@ -133,7 +181,13 @@ const zustandSyncAdapter = exports.zustandSyncAdapter = (0, _sharedUi.createSync
|
|
|
133
181
|
currentState: s.currentState
|
|
134
182
|
} : {
|
|
135
183
|
keys: topLevelKeys(s.currentState)
|
|
136
|
-
})
|
|
184
|
+
}),
|
|
185
|
+
// Cheap enough to always include: this is the compact view a caller
|
|
186
|
+
// reaches for precisely because it does not want to pull the data, and
|
|
187
|
+
// the item shape of a list is the one thing it cannot infer without it.
|
|
188
|
+
...((0, _sharedUi.shapeSummary)(s.currentState) ? {
|
|
189
|
+
shape: (0, _sharedUi.shapeSummary)(s.currentState)
|
|
190
|
+
} : {})
|
|
137
191
|
}));
|
|
138
192
|
return {
|
|
139
193
|
stores,
|
|
@@ -146,8 +200,14 @@ const zustandSyncAdapter = exports.zustandSyncAdapter = (0, _sharedUi.createSync
|
|
|
146
200
|
const {
|
|
147
201
|
storeName,
|
|
148
202
|
state,
|
|
149
|
-
replace
|
|
203
|
+
replace,
|
|
204
|
+
force,
|
|
205
|
+
path,
|
|
206
|
+
value
|
|
150
207
|
} = (0, _sharedUi.readParams)(params);
|
|
208
|
+
let effective = state;
|
|
209
|
+
let keyedNotes = [];
|
|
210
|
+
let unchecked = [];
|
|
151
211
|
if (!storeName) return {
|
|
152
212
|
ok: false,
|
|
153
213
|
error: "Missing storeName."
|
|
@@ -157,9 +217,112 @@ const zustandSyncAdapter = exports.zustandSyncAdapter = (0, _sharedUi.createSync
|
|
|
157
217
|
ok: false,
|
|
158
218
|
error: `No store named "${storeName}".`
|
|
159
219
|
};
|
|
160
|
-
|
|
220
|
+
// `path` is sugar over a merge: it can only ever produce a patch, which
|
|
221
|
+
// then goes through the guard below like any other. Its value is that
|
|
222
|
+
// there is no nesting depth for the caller to get wrong.
|
|
223
|
+
// `state` is no longer schema-required, because `path`+`value` is a valid
|
|
224
|
+
// alternative — so the handler has to be the thing that rejects NEITHER.
|
|
225
|
+
// Without this, `state` arrives undefined and falls through to
|
|
226
|
+
// `setState(undefined, true)`, which is zustand's whole-state replace: the
|
|
227
|
+
// store's data AND its action functions, gone, from a call that looks like
|
|
228
|
+
// a typo. This is the most destructive thing in this file.
|
|
229
|
+
if (state === undefined && path === undefined) {
|
|
230
|
+
return {
|
|
231
|
+
ok: false,
|
|
232
|
+
error: `Refused: no change was described. Send \`state\` with the fields to merge, or \`path\` and \`value\` to set one value.`
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
let pathed = false;
|
|
236
|
+
if (path !== undefined) {
|
|
237
|
+
if (value === undefined) {
|
|
238
|
+
return {
|
|
239
|
+
ok: false,
|
|
240
|
+
error: `Refused: sent \`path\` without \`value\`. Say what to set "${path}" to; if you mean to clear it, send value:null and the field must already be nullable.`
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
let currentForPath;
|
|
244
|
+
try {
|
|
245
|
+
currentForPath = store.api.getState();
|
|
246
|
+
} catch {
|
|
247
|
+
currentForPath = undefined;
|
|
248
|
+
}
|
|
249
|
+
const built = (0, _sharedUi.patchFromPath)(currentForPath, path, value);
|
|
250
|
+
if (!built.ok) return {
|
|
251
|
+
ok: false,
|
|
252
|
+
error: `Refused: ${built.error}`
|
|
253
|
+
};
|
|
254
|
+
effective = built.patch;
|
|
255
|
+
pathed = true;
|
|
256
|
+
}
|
|
257
|
+
// On a MERGE (replace:false), constrain it to a typed edit so a remote
|
|
258
|
+
// caller can't hand the store a field of the wrong type or a malformed
|
|
259
|
+
// new list item — the same protection the query cache has. A replace
|
|
260
|
+
// (whole-store reset) and an explicit `force` skip this.
|
|
261
|
+
if (!force && (replace === false || pathed)) {
|
|
262
|
+
let current;
|
|
263
|
+
try {
|
|
264
|
+
current = store.api.getState();
|
|
265
|
+
} catch {
|
|
266
|
+
current = undefined;
|
|
267
|
+
}
|
|
268
|
+
// Expand id-addressed list edits BEFORE validating, so the typed-edit
|
|
269
|
+
// guard below sees a real array and every existing protection still
|
|
270
|
+
// applies to the result.
|
|
271
|
+
if (current !== undefined) {
|
|
272
|
+
const expanded = (0, _sharedUi.expandKeyedArrays)(current, effective);
|
|
273
|
+
// See keyedArrays.ts: an added item whose id disagrees with the key
|
|
274
|
+
// it was sent under is ambiguous, and only this layer can say so.
|
|
275
|
+
if (expanded.error) {
|
|
276
|
+
return {
|
|
277
|
+
ok: false,
|
|
278
|
+
error: `Refused: ${expanded.error}`
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
effective = expanded.patch;
|
|
282
|
+
keyedNotes = expanded.notes;
|
|
283
|
+
}
|
|
284
|
+
// The guard builds its template from `list[0]`, so a list that is EMPTY
|
|
285
|
+
// has no template and an added item is written with nothing to check it
|
|
286
|
+
// against. That is not a rare corner: it is every "add the first thing"
|
|
287
|
+
// flow, and it is where models invent shapes, because on an empty list
|
|
288
|
+
// the item shape genuinely exists nowhere in the running app. We cannot
|
|
289
|
+
// refuse it — refusing would break adding the first item to anything —
|
|
290
|
+
// so we say so instead of letting the guess through unremarked.
|
|
291
|
+
if (current !== undefined) {
|
|
292
|
+
unchecked = (0, _sharedUi.unshapedLists)(current).filter(path => touchesList(effective, path));
|
|
293
|
+
}
|
|
294
|
+
if (current !== undefined) {
|
|
295
|
+
const violations = (0, _sharedUi.typedEditViolations)(current, effective, {
|
|
296
|
+
noun: "store"
|
|
297
|
+
});
|
|
298
|
+
if (violations.length > 0) {
|
|
299
|
+
return {
|
|
300
|
+
ok: false,
|
|
301
|
+
error: (0, _sharedUi.refusalText)(violations, "store", (0, _sharedUi.suggestedPatch)(effective, violations)),
|
|
302
|
+
...((0, _sharedUi.suggestedPatch)(effective, violations) ? {
|
|
303
|
+
suggestedState: (0, _sharedUi.suggestedPatch)(effective, violations)
|
|
304
|
+
} : {}),
|
|
305
|
+
violations
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// A pathed write is a merge by construction — it names one value, so it
|
|
311
|
+
// must never fall through to zustand's default whole-state replace.
|
|
312
|
+
store.api.setState(effective, pathed ? false : replace ?? true);
|
|
313
|
+
// Say what an addressed edit resolved to. A caller that meant to change one
|
|
314
|
+
// line and sees "17 item(s) remain" has caught its own mistake.
|
|
161
315
|
return {
|
|
162
|
-
ok: true
|
|
316
|
+
ok: true,
|
|
317
|
+
...(path !== undefined ? {
|
|
318
|
+
path
|
|
319
|
+
} : {}),
|
|
320
|
+
...(keyedNotes.length ? {
|
|
321
|
+
keyed: keyedNotes
|
|
322
|
+
} : {}),
|
|
323
|
+
...(unchecked.length ? {
|
|
324
|
+
unchecked: unchecked.map(path => `\`${path}\` was empty, so nothing in the app knows what its items look like and the shape of what you added was NOT checked. If the app renders a field you left out, it will render undefined — read the store back and compare against how the screen uses it.`)
|
|
325
|
+
} : {})
|
|
163
326
|
};
|
|
164
327
|
},
|
|
165
328
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { expandKeyedArrays, patchFromPath, readPath, refusalText, shapeSummary, suggestedPatch, typedEditViolations, unshapedLists } from "@buoy-gg/shared-ui";
|
|
3
4
|
import { zustandStateStore } from "../utils/zustandStateStore";
|
|
4
5
|
import { WIRE_DETAIL_LIMIT_BYTES, createSyncAdapter, detailByIdAction, isJsonSerializable, isOverWireBudget, memoByIdentity, onDeviceMarker, readParams, toWire, truncatedNote } from "@buoy-gg/shared-ui";
|
|
5
6
|
|
|
@@ -12,6 +13,23 @@ export const STATE_ON_DEVICE = onDeviceMarker("State", "State trees stay on the
|
|
|
12
13
|
|
|
13
14
|
/** Wire-form sentinel for an oversized `partial` (replace can carry a whole tree). */
|
|
14
15
|
export const PAYLOAD_ON_DEVICE = onDeviceMarker("Payload", "Partial stays on the device — fetched on demand via getChangeDetail.");
|
|
16
|
+
const isPlainObject = v => !!v && typeof v === "object" && !Array.isArray(v);
|
|
17
|
+
/**
|
|
18
|
+
* Does this patch write into the list at `path`? Only then is an unchecked-shape
|
|
19
|
+
* warning about that list worth saying — a patch that changes `promoCode` should
|
|
20
|
+
* not be told about an empty `lines`.
|
|
21
|
+
*/
|
|
22
|
+
function touchesList(patch, path) {
|
|
23
|
+
let cur = patch;
|
|
24
|
+
for (const seg of path.split(".")) {
|
|
25
|
+
if (!cur || typeof cur !== "object" || Array.isArray(cur)) return false;
|
|
26
|
+
if (!(seg in cur)) return false;
|
|
27
|
+
cur = cur[seg];
|
|
28
|
+
}
|
|
29
|
+
// An empty list stays empty; there is no new item to be unsure about.
|
|
30
|
+
return Array.isArray(cur) ? cur.length > 0 : !!cur && typeof cur === "object";
|
|
31
|
+
}
|
|
32
|
+
|
|
15
33
|
/** Top-level keys of an object state, for the compact (no-values) view. */
|
|
16
34
|
function topLevelKeys(state) {
|
|
17
35
|
return state && typeof state === "object" && !Array.isArray(state) ? Object.keys(state) : undefined;
|
|
@@ -77,7 +95,8 @@ export const zustandSyncAdapter = createSyncAdapter({
|
|
|
77
95
|
*/
|
|
78
96
|
getStoreState: params => {
|
|
79
97
|
const {
|
|
80
|
-
storeName
|
|
98
|
+
storeName,
|
|
99
|
+
path
|
|
81
100
|
} = readParams(params);
|
|
82
101
|
if (!storeName) return {
|
|
83
102
|
found: false,
|
|
@@ -94,16 +113,46 @@ export const zustandSyncAdapter = createSyncAdapter({
|
|
|
94
113
|
} catch {
|
|
95
114
|
currentState = undefined;
|
|
96
115
|
}
|
|
116
|
+
// One slice instead of the whole store. The reason to want it is the
|
|
117
|
+
// engine's 24,000-character result cap: a caller that never saw the field
|
|
118
|
+
// it means to edit is left inventing a shape, which is the failure this
|
|
119
|
+
// whole surface keeps producing.
|
|
120
|
+
if (path) {
|
|
121
|
+
const at = readPath(currentState, path);
|
|
122
|
+
if (!at.ok) return {
|
|
123
|
+
found: false,
|
|
124
|
+
reason: at.error
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
found: true,
|
|
128
|
+
storeName,
|
|
129
|
+
path,
|
|
130
|
+
shape: shapeSummary(at.value),
|
|
131
|
+
currentState: at.value
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// The sketch goes BEFORE currentState, deliberately. The engine truncates
|
|
135
|
+
// a result by slicing the encoded string at 24,000 characters, so whatever
|
|
136
|
+
// is serialised first is what survives — and the reads most in need of a
|
|
137
|
+
// shape are exactly the long ones that get cut. It costs ~150 characters
|
|
138
|
+
// and does not grow with the data.
|
|
139
|
+
const shape = shapeSummary(currentState);
|
|
97
140
|
if (!isOverWireBudget(currentState, WIRE_DETAIL_LIMIT_BYTES)) {
|
|
98
141
|
return {
|
|
99
142
|
found: true,
|
|
100
143
|
storeName,
|
|
144
|
+
...(shape ? {
|
|
145
|
+
shape
|
|
146
|
+
} : {}),
|
|
101
147
|
currentState
|
|
102
148
|
};
|
|
103
149
|
}
|
|
104
150
|
return {
|
|
105
151
|
found: true,
|
|
106
152
|
storeName,
|
|
153
|
+
...(shape ? {
|
|
154
|
+
shape
|
|
155
|
+
} : {}),
|
|
107
156
|
currentState: isJsonSerializable(currentState) ? truncatedNote(WIRE_DETAIL_LIMIT_BYTES) : STATE_ON_DEVICE
|
|
108
157
|
};
|
|
109
158
|
},
|
|
@@ -130,7 +179,13 @@ export const zustandSyncAdapter = createSyncAdapter({
|
|
|
130
179
|
currentState: s.currentState
|
|
131
180
|
} : {
|
|
132
181
|
keys: topLevelKeys(s.currentState)
|
|
133
|
-
})
|
|
182
|
+
}),
|
|
183
|
+
// Cheap enough to always include: this is the compact view a caller
|
|
184
|
+
// reaches for precisely because it does not want to pull the data, and
|
|
185
|
+
// the item shape of a list is the one thing it cannot infer without it.
|
|
186
|
+
...(shapeSummary(s.currentState) ? {
|
|
187
|
+
shape: shapeSummary(s.currentState)
|
|
188
|
+
} : {})
|
|
134
189
|
}));
|
|
135
190
|
return {
|
|
136
191
|
stores,
|
|
@@ -143,8 +198,14 @@ export const zustandSyncAdapter = createSyncAdapter({
|
|
|
143
198
|
const {
|
|
144
199
|
storeName,
|
|
145
200
|
state,
|
|
146
|
-
replace
|
|
201
|
+
replace,
|
|
202
|
+
force,
|
|
203
|
+
path,
|
|
204
|
+
value
|
|
147
205
|
} = readParams(params);
|
|
206
|
+
let effective = state;
|
|
207
|
+
let keyedNotes = [];
|
|
208
|
+
let unchecked = [];
|
|
148
209
|
if (!storeName) return {
|
|
149
210
|
ok: false,
|
|
150
211
|
error: "Missing storeName."
|
|
@@ -154,9 +215,112 @@ export const zustandSyncAdapter = createSyncAdapter({
|
|
|
154
215
|
ok: false,
|
|
155
216
|
error: `No store named "${storeName}".`
|
|
156
217
|
};
|
|
157
|
-
|
|
218
|
+
// `path` is sugar over a merge: it can only ever produce a patch, which
|
|
219
|
+
// then goes through the guard below like any other. Its value is that
|
|
220
|
+
// there is no nesting depth for the caller to get wrong.
|
|
221
|
+
// `state` is no longer schema-required, because `path`+`value` is a valid
|
|
222
|
+
// alternative — so the handler has to be the thing that rejects NEITHER.
|
|
223
|
+
// Without this, `state` arrives undefined and falls through to
|
|
224
|
+
// `setState(undefined, true)`, which is zustand's whole-state replace: the
|
|
225
|
+
// store's data AND its action functions, gone, from a call that looks like
|
|
226
|
+
// a typo. This is the most destructive thing in this file.
|
|
227
|
+
if (state === undefined && path === undefined) {
|
|
228
|
+
return {
|
|
229
|
+
ok: false,
|
|
230
|
+
error: `Refused: no change was described. Send \`state\` with the fields to merge, or \`path\` and \`value\` to set one value.`
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
let pathed = false;
|
|
234
|
+
if (path !== undefined) {
|
|
235
|
+
if (value === undefined) {
|
|
236
|
+
return {
|
|
237
|
+
ok: false,
|
|
238
|
+
error: `Refused: sent \`path\` without \`value\`. Say what to set "${path}" to; if you mean to clear it, send value:null and the field must already be nullable.`
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
let currentForPath;
|
|
242
|
+
try {
|
|
243
|
+
currentForPath = store.api.getState();
|
|
244
|
+
} catch {
|
|
245
|
+
currentForPath = undefined;
|
|
246
|
+
}
|
|
247
|
+
const built = patchFromPath(currentForPath, path, value);
|
|
248
|
+
if (!built.ok) return {
|
|
249
|
+
ok: false,
|
|
250
|
+
error: `Refused: ${built.error}`
|
|
251
|
+
};
|
|
252
|
+
effective = built.patch;
|
|
253
|
+
pathed = true;
|
|
254
|
+
}
|
|
255
|
+
// On a MERGE (replace:false), constrain it to a typed edit so a remote
|
|
256
|
+
// caller can't hand the store a field of the wrong type or a malformed
|
|
257
|
+
// new list item — the same protection the query cache has. A replace
|
|
258
|
+
// (whole-store reset) and an explicit `force` skip this.
|
|
259
|
+
if (!force && (replace === false || pathed)) {
|
|
260
|
+
let current;
|
|
261
|
+
try {
|
|
262
|
+
current = store.api.getState();
|
|
263
|
+
} catch {
|
|
264
|
+
current = undefined;
|
|
265
|
+
}
|
|
266
|
+
// Expand id-addressed list edits BEFORE validating, so the typed-edit
|
|
267
|
+
// guard below sees a real array and every existing protection still
|
|
268
|
+
// applies to the result.
|
|
269
|
+
if (current !== undefined) {
|
|
270
|
+
const expanded = expandKeyedArrays(current, effective);
|
|
271
|
+
// See keyedArrays.ts: an added item whose id disagrees with the key
|
|
272
|
+
// it was sent under is ambiguous, and only this layer can say so.
|
|
273
|
+
if (expanded.error) {
|
|
274
|
+
return {
|
|
275
|
+
ok: false,
|
|
276
|
+
error: `Refused: ${expanded.error}`
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
effective = expanded.patch;
|
|
280
|
+
keyedNotes = expanded.notes;
|
|
281
|
+
}
|
|
282
|
+
// The guard builds its template from `list[0]`, so a list that is EMPTY
|
|
283
|
+
// has no template and an added item is written with nothing to check it
|
|
284
|
+
// against. That is not a rare corner: it is every "add the first thing"
|
|
285
|
+
// flow, and it is where models invent shapes, because on an empty list
|
|
286
|
+
// the item shape genuinely exists nowhere in the running app. We cannot
|
|
287
|
+
// refuse it — refusing would break adding the first item to anything —
|
|
288
|
+
// so we say so instead of letting the guess through unremarked.
|
|
289
|
+
if (current !== undefined) {
|
|
290
|
+
unchecked = unshapedLists(current).filter(path => touchesList(effective, path));
|
|
291
|
+
}
|
|
292
|
+
if (current !== undefined) {
|
|
293
|
+
const violations = typedEditViolations(current, effective, {
|
|
294
|
+
noun: "store"
|
|
295
|
+
});
|
|
296
|
+
if (violations.length > 0) {
|
|
297
|
+
return {
|
|
298
|
+
ok: false,
|
|
299
|
+
error: refusalText(violations, "store", suggestedPatch(effective, violations)),
|
|
300
|
+
...(suggestedPatch(effective, violations) ? {
|
|
301
|
+
suggestedState: suggestedPatch(effective, violations)
|
|
302
|
+
} : {}),
|
|
303
|
+
violations
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// A pathed write is a merge by construction — it names one value, so it
|
|
309
|
+
// must never fall through to zustand's default whole-state replace.
|
|
310
|
+
store.api.setState(effective, pathed ? false : replace ?? true);
|
|
311
|
+
// Say what an addressed edit resolved to. A caller that meant to change one
|
|
312
|
+
// line and sees "17 item(s) remain" has caught its own mistake.
|
|
158
313
|
return {
|
|
159
|
-
ok: true
|
|
314
|
+
ok: true,
|
|
315
|
+
...(path !== undefined ? {
|
|
316
|
+
path
|
|
317
|
+
} : {}),
|
|
318
|
+
...(keyedNotes.length ? {
|
|
319
|
+
keyed: keyedNotes
|
|
320
|
+
} : {}),
|
|
321
|
+
...(unchecked.length ? {
|
|
322
|
+
unchecked: unchecked.map(path => `\`${path}\` was empty, so nothing in the app knows what its items look like and the shape of what you added was NOT checked. If the app renders a field you left out, it will render undefined — read the store back and compare against how the screen uses it.`)
|
|
323
|
+
} : {})
|
|
160
324
|
};
|
|
161
325
|
},
|
|
162
326
|
/**
|
|
@@ -63,12 +63,29 @@ export declare const zustandSyncAdapter: import("@buoy-gg/shared-ui").SyncAdapte
|
|
|
63
63
|
found: false;
|
|
64
64
|
reason: string;
|
|
65
65
|
storeName?: undefined;
|
|
66
|
+
path?: undefined;
|
|
67
|
+
shape?: undefined;
|
|
66
68
|
currentState?: undefined;
|
|
67
69
|
} | {
|
|
68
70
|
found: true;
|
|
69
71
|
storeName: string;
|
|
72
|
+
path: string;
|
|
73
|
+
shape: {
|
|
74
|
+
shape: string;
|
|
75
|
+
lists?: import("@buoy-gg/shared-ui").ListShape[];
|
|
76
|
+
} | undefined;
|
|
70
77
|
currentState: unknown;
|
|
71
78
|
reason?: undefined;
|
|
79
|
+
} | {
|
|
80
|
+
currentState: unknown;
|
|
81
|
+
shape?: {
|
|
82
|
+
shape: string;
|
|
83
|
+
lists?: import("@buoy-gg/shared-ui").ListShape[];
|
|
84
|
+
} | undefined;
|
|
85
|
+
found: true;
|
|
86
|
+
storeName: string;
|
|
87
|
+
reason?: undefined;
|
|
88
|
+
path?: undefined;
|
|
72
89
|
};
|
|
73
90
|
/**
|
|
74
91
|
* Compact current-state reader for a remote driver (MCP/LLM): the registered
|
|
@@ -78,6 +95,10 @@ export declare const zustandSyncAdapter: import("@buoy-gg/shared-ui").SyncAdapte
|
|
|
78
95
|
*/
|
|
79
96
|
listStores: (params?: unknown) => {
|
|
80
97
|
stores: ({
|
|
98
|
+
shape?: {
|
|
99
|
+
shape: string;
|
|
100
|
+
lists?: import("@buoy-gg/shared-ui").ListShape[];
|
|
101
|
+
} | undefined;
|
|
81
102
|
currentState: unknown;
|
|
82
103
|
name: string;
|
|
83
104
|
changes: number;
|
|
@@ -85,6 +106,10 @@ export declare const zustandSyncAdapter: import("@buoy-gg/shared-ui").SyncAdapte
|
|
|
85
106
|
persistName: string | undefined;
|
|
86
107
|
canRehydrate: boolean | undefined;
|
|
87
108
|
} | {
|
|
109
|
+
shape?: {
|
|
110
|
+
shape: string;
|
|
111
|
+
lists?: import("@buoy-gg/shared-ui").ListShape[];
|
|
112
|
+
} | undefined;
|
|
88
113
|
keys: string[] | undefined;
|
|
89
114
|
name: string;
|
|
90
115
|
changes: number;
|
|
@@ -100,7 +125,15 @@ export declare const zustandSyncAdapter: import("@buoy-gg/shared-ui").SyncAdapte
|
|
|
100
125
|
ok: boolean;
|
|
101
126
|
error: string;
|
|
102
127
|
} | {
|
|
128
|
+
violations: import("@buoy-gg/shared-ui").EditViolation[];
|
|
129
|
+
suggestedState?: Record<string, unknown> | undefined;
|
|
103
130
|
ok: boolean;
|
|
131
|
+
error: string;
|
|
132
|
+
} | {
|
|
133
|
+
unchecked?: string[] | undefined;
|
|
134
|
+
keyed?: string[] | undefined;
|
|
135
|
+
path?: string | undefined;
|
|
136
|
+
ok: true;
|
|
104
137
|
error?: undefined;
|
|
105
138
|
};
|
|
106
139
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zustandSyncAdapter.d.ts","sourceRoot":"","sources":["../../../../src/zustand/sync/zustandSyncAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zustandSyncAdapter.d.ts","sourceRoot":"","sources":["../../../../src/zustand/sync/zustandSyncAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAenD;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;EAG3B,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,iBAAiB;;;;EAG7B,CAAC;AAuEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;IAiB3B;;;;OAIG;;;;;;IASH;;;OAGG;6BACsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsChC;;;;;OAKG;0BACmB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0BT,OAAO;;;;;;;;;;;;;;;IAwG3B;;;;;;;;;;;;;;;;;;;;OAoBG;yBACwB,OAAO;;;;;;;;;;;EAqBV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/zustand",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.36",
|
|
4
4
|
"description": "Zustand devtools inside your React Native app — state diffs, jump-to-state & one-tap store reset, no middleware. 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/shared-ui": "^7.0.
|
|
33
|
-
"@buoy-gg/license": "^7.0.
|
|
32
|
+
"@buoy-gg/shared-ui": "^7.0.36",
|
|
33
|
+
"@buoy-gg/license": "^7.0.36"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "*",
|