cogsbox-shape 0.5.175 → 0.5.177

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.
Files changed (2) hide show
  1. package/dist/schema.js +34 -2
  2. package/package.json +3 -3
package/dist/schema.js CHANGED
@@ -786,7 +786,35 @@ export function createSchemaBox(schemas, resolver) {
786
786
  }
787
787
  return baseMapped;
788
788
  };
789
+ // --- NEW: Implement recursive toDb ---
790
+ const deepToDb = (clientData, currentSelection, currentKey) => {
791
+ if (!clientData)
792
+ return clientData;
793
+ if (Array.isArray(clientData))
794
+ return clientData.map((item) => deepToDb(item, currentSelection, currentKey));
795
+ const regEntry = finalRegistry[currentKey];
796
+ const baseMapped = regEntry.zodSchemas.toDb(clientData);
797
+ if (typeof currentSelection === "object") {
798
+ for (const relKey in currentSelection) {
799
+ if (currentSelection[relKey] &&
800
+ clientData[relKey] !== undefined &&
801
+ clientData[relKey] !== null) {
802
+ const relField = regEntry.rawSchema[relKey];
803
+ if (relField?.config?.sql?.schema) {
804
+ const targetTableName = relField.config.sql.schema()._tableName;
805
+ const nextRegKey = tableNameToRegistryKeyMap[targetTableName];
806
+ if (nextRegKey) {
807
+ baseMapped[relKey] = deepToDb(clientData[relKey], currentSelection[relKey], nextRegKey);
808
+ }
809
+ }
810
+ }
811
+ }
812
+ }
813
+ return baseMapped;
814
+ };
789
815
  const viewToClient = (dbData) => deepToClient(dbData, selection, tableName);
816
+ // --- NEW: View To Db ---
817
+ const viewToDb = (clientData) => deepToDb(clientData, selection, tableName);
790
818
  return {
791
819
  definition: entry.rawSchema,
792
820
  schemaKey: tableName,
@@ -797,9 +825,13 @@ export function createSchemaBox(schemas, resolver) {
797
825
  },
798
826
  transforms: {
799
827
  toClient: viewToClient,
800
- toDb: entry.zodSchemas.toDb,
828
+ toDb: viewToDb, // <--- UPDATED: now uses the recursive function
829
+ },
830
+ // --- UPDATED: uses view.server.parse to retain relation arrays/objects instead of stripping them
831
+ parseForDb: (appData) => {
832
+ const validData = view.server.parse(appData);
833
+ return viewToDb(validData);
801
834
  },
802
- parseForDb: entry.zodSchemas.parseForDb,
803
835
  parseFromDb: (dbData) => {
804
836
  const mapped = viewToClient(dbData);
805
837
  return view.client.parse(mapped);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.175",
3
+ "version": "0.5.177",
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",
@@ -38,11 +38,11 @@
38
38
  "dependencies": {
39
39
  "commander": "^13.1.0",
40
40
  "tsx": "^4.19.3",
41
- "uuid": "^9.0.0"
41
+ "uuid": "^11.0.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^20.10.5",
45
- "@types/uuid": "^9.0.7",
45
+ "@types/uuid": "^11.0.0",
46
46
  "@typescript-eslint/eslint-plugin": "^6.15.0",
47
47
  "@typescript-eslint/parser": "^6.15.0",
48
48
  "eslint": "^8.56.0",