cogsbox-shape 0.5.219 → 0.5.220
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.
|
@@ -70,7 +70,10 @@ type ShapeKeyValidationParams = {
|
|
|
70
70
|
getState?: () => unknown;
|
|
71
71
|
/** When true (default), writes filtered issues to shadow validation metadata. */
|
|
72
72
|
persist?: boolean;
|
|
73
|
+
/** When true, clears existing errors on sibling fields outside `keys`. */
|
|
74
|
+
clearOutsideKeys?: boolean;
|
|
73
75
|
};
|
|
76
|
+
export type ValidateGroupOptions = Pick<ShapeKeyValidationParams, "persist" | "clearOutsideKeys">;
|
|
74
77
|
export declare function wireShapeValidationOptions(box: ShapeSchemaBox, params: TransformStateParams): void;
|
|
75
78
|
/** Cross-field refine errors only — field rules are handled by state via setOptions. */
|
|
76
79
|
export declare function validateShapeRefines(box: ShapeSchemaBox, params: FormUpdateParams): void;
|
|
@@ -182,6 +182,9 @@ function notifyStateComponents(stateKey) {
|
|
|
182
182
|
}
|
|
183
183
|
function persistValidateGroupResults(params, keys, mapped) {
|
|
184
184
|
const validationParams = createShadowValidationBridge(params.stateKey);
|
|
185
|
+
if (params.clearOutsideKeys === true) {
|
|
186
|
+
clearOutsideGroupValidation(params, keys, validationParams);
|
|
187
|
+
}
|
|
185
188
|
const keyPaths = keys.map((key) => [...params.path, key]);
|
|
186
189
|
const activeKeys = new Set(mapped.map((issue) => pathKey(issue.path)));
|
|
187
190
|
const stalePaths = keyPaths.filter((targetPath) => !activeKeys.has(pathKey(targetPath)));
|
|
@@ -191,6 +194,25 @@ function persistValidateGroupResults(params, keys, mapped) {
|
|
|
191
194
|
}
|
|
192
195
|
notifyStateComponents(params.stateKey);
|
|
193
196
|
}
|
|
197
|
+
function clearOutsideGroupValidation(params, keys, validationParams) {
|
|
198
|
+
const store = getGlobalStore.getState();
|
|
199
|
+
const parentNode = store.getShadowNode(params.stateKey, params.path);
|
|
200
|
+
if (!parentNode)
|
|
201
|
+
return;
|
|
202
|
+
const keySet = new Set(keys);
|
|
203
|
+
const outsidePaths = [];
|
|
204
|
+
for (const childKey of Object.keys(parentNode)) {
|
|
205
|
+
if (childKey === "_meta" || keySet.has(childKey))
|
|
206
|
+
continue;
|
|
207
|
+
const fieldPath = [...params.path, childKey];
|
|
208
|
+
const status = store.getShadowMetadata(params.stateKey, fieldPath)
|
|
209
|
+
?.validation?.status;
|
|
210
|
+
if (status === "INVALID") {
|
|
211
|
+
outsidePaths.push(fieldPath);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
clearValidationPaths(validationParams, outsidePaths);
|
|
215
|
+
}
|
|
194
216
|
function issueMatchesSelectedKeys(issue, parentPath, selectedKeys) {
|
|
195
217
|
const issuePath = issue.path.map(String);
|
|
196
218
|
if (issuePath.length <= parentPath.length)
|
|
@@ -270,6 +292,22 @@ function resolveUpdateRefineTarget(entry, updatePath, oldValue, newValue) {
|
|
|
270
292
|
relatedPaths: resolveRelatedPaths(updatePath, relatedFields),
|
|
271
293
|
};
|
|
272
294
|
}
|
|
295
|
+
function clearStaleRefineValidation(box, params, target, state) {
|
|
296
|
+
const entry = box[params.stateKey];
|
|
297
|
+
const clientSchema = entry?.validators?.client ?? entry?.schemas.client;
|
|
298
|
+
if (!entry || !clientSchema)
|
|
299
|
+
return;
|
|
300
|
+
const result = clientSchema.safeParse(state);
|
|
301
|
+
if (result.success) {
|
|
302
|
+
clearValidationPaths(params, target.relatedPaths);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const issues = result.error.issues.filter((issue) => issueMatchesRelatedFields(issue, target.relatedFields));
|
|
306
|
+
const mapped = mapZodIssues(issues);
|
|
307
|
+
const activeKeys = new Set(mapped.map((entry) => pathKey(entry.path)));
|
|
308
|
+
const stalePaths = target.relatedPaths.filter((targetPath) => !activeKeys.has(pathKey(targetPath)));
|
|
309
|
+
clearValidationPaths(params, stalePaths);
|
|
310
|
+
}
|
|
273
311
|
function applyRefineValidation(box, params, target, state) {
|
|
274
312
|
const entry = box[params.stateKey];
|
|
275
313
|
const clientSchema = entry?.validators?.client ?? entry?.schemas.client;
|
|
@@ -327,7 +365,7 @@ export function validateShapeRefinesOnUpdate(box, params) {
|
|
|
327
365
|
const target = resolveUpdateRefineTarget(entry, params.update.path, params.update.oldValue, params.update.newValue);
|
|
328
366
|
if (!target)
|
|
329
367
|
return;
|
|
330
|
-
|
|
368
|
+
clearStaleRefineValidation(box, params, target, params.getState());
|
|
331
369
|
}
|
|
332
370
|
export function validateShapeKeys(box, params) {
|
|
333
371
|
const entry = box[params.stateKey];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.220",
|
|
4
4
|
"description": "A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for relationships and serialization.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|