cogsbox-shape 0.5.215 → 0.5.217

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.
@@ -1,4 +1,3 @@
1
- import type { ChainMethodContext } from "cogsbox-state";
2
1
  import { z } from "zod";
3
2
  /** Minimal shape of a createSchemaBox entry — matches journalSchemaBox.journalTechnical etc. */
4
3
  export type ShapeRefineInfo = {
@@ -80,19 +79,19 @@ export declare function validateShapeKeys(box: ShapeSchemaBox, params: ShapeKeyV
80
79
  key: string;
81
80
  path: string[];
82
81
  success: boolean;
83
- data: any;
82
+ data: unknown;
84
83
  }[];
85
84
  };
86
85
  export declare function createShapePlugin<const TBox extends ShapeSchemaBox>(box: TBox): import("cogsbox-state").CogsPluginBuilder<"shape", {
87
86
  logs: boolean | undefined;
88
87
  }, unknown, unknown, never, {
89
- validateShape: import("cogsbox-state").ChainMethodDefinition<(ctx: ChainMethodContext, keys?: readonly string[]) => {
88
+ validateGroup: import("cogsbox-state").ChainMethodDefinition<(ctx: import("cogsbox-state").ChainMethodContext<any, any>, keys?: readonly string[] | undefined) => {
90
89
  success: boolean;
91
90
  results: {
92
91
  key: string;
93
92
  path: string[];
94
93
  success: boolean;
95
- data: any;
94
+ data: unknown;
96
95
  }[];
97
96
  }>;
98
97
  }, true, true, true, true, false, true, InferShapeBoxState<TBox>>;
@@ -3,6 +3,15 @@ import { z } from "zod";
3
3
  function pathKey(path) {
4
4
  return path.join("\0");
5
5
  }
6
+ function getValueAtPath(value, path) {
7
+ let cursor = value;
8
+ for (const segment of path) {
9
+ if (cursor === null || typeof cursor !== "object")
10
+ return undefined;
11
+ cursor = cursor[segment];
12
+ }
13
+ return cursor;
14
+ }
6
15
  function resolveRelatedPaths(blurPath, relatedFields) {
7
16
  const parent = blurPath.slice(0, -1);
8
17
  return [...relatedFields].map((field) => [...parent, field]);
@@ -296,7 +305,7 @@ export function validateShapeKeys(box, params) {
296
305
  key,
297
306
  path: [...params.path, key],
298
307
  success: true,
299
- data: store.getShadowValue(params.stateKey, [...params.path, key]),
308
+ data: getValueAtPath(rootState, [...params.path, key]),
300
309
  })) ?? [],
301
310
  };
302
311
  }
@@ -322,7 +331,7 @@ export function validateShapeKeys(box, params) {
322
331
  path: keyPath,
323
332
  success: keyIssues.length === 0,
324
333
  data: keyIssues.length === 0
325
- ? store.getShadowValue(params.stateKey, keyPath)
334
+ ? getValueAtPath(rootState, keyPath)
326
335
  : undefined,
327
336
  error: keyIssues.length === 0 ? undefined : { issues: keyIssues },
328
337
  };
@@ -361,7 +370,7 @@ export function createShapePlugin(box) {
361
370
  validateShapeRefinesOnUpdate(box, params);
362
371
  })
363
372
  .methods((m) => ({
364
- validateShape: m.object((ctx, keys) => validateShapeKeys(box, {
373
+ validateGroup: m.object((ctx, keys) => validateShapeKeys(box, {
365
374
  stateKey: ctx.stateKey,
366
375
  path: ctx.path,
367
376
  keys,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.215",
3
+ "version": "0.5.217",
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",
@@ -65,7 +65,6 @@
65
65
  "author": "",
66
66
  "license": "MIT",
67
67
  "dependencies": {
68
- "cogsbox-state": "^0.5.488",
69
68
  "commander": "^13.1.0",
70
69
  "kysely": "^0.29.2",
71
70
  "tsx": "^4.19.3",