cogsbox-state 0.5.439 → 0.5.440

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-state",
3
- "version": "0.5.439",
3
+ "version": "0.5.440",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/CogsState.tsx CHANGED
@@ -592,6 +592,7 @@ type SyncSchemaStructure<T = any> = {
592
592
  >;
593
593
  notifications: Record<string, (state: any, context: any) => any>;
594
594
  };
595
+ // Minimal change - just add a second parameter to detect sync schema
595
596
  export const createCogsState = <State extends Record<StateKeys, unknown>>(
596
597
  initialState: State,
597
598
  opt?: {
@@ -614,6 +615,7 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
614
615
  .getState()
615
616
  .setInitialStateOptions('__notifications', opt.__syncNotifications);
616
617
  }
618
+
617
619
  // ... rest of your existing createCogsState code unchanged ...
618
620
 
619
621
  Object.keys(statePart).forEach((key) => {
@@ -713,14 +715,23 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
713
715
  return { useCogsState, setCogsOptions } as CogsApi<State>;
714
716
  };
715
717
 
718
+ // Helper to extract just the data shape, not the full Zod types
719
+ type SimplifyType<T> = T extends object
720
+ ? T extends (...args: any[]) => any
721
+ ? T
722
+ : { [K in keyof T]: SimplifyType<T[K]> }
723
+ : T;
724
+
716
725
  type ExtractStateFromSync<T> = T extends { schemas: infer S }
717
726
  ? S extends Record<string, any>
718
727
  ? {
719
728
  [K in keyof S]: S[K] extends { rawSchema: infer R }
720
- ? R
729
+ ? SimplifyType<R>
721
730
  : S[K] extends { schemas: { defaults: infer D } }
722
- ? D
723
- : any;
731
+ ? SimplifyType<D>
732
+ : S[K] extends { _tableName: string }
733
+ ? SimplifyType<S[K]>
734
+ : never;
724
735
  }
725
736
  : never
726
737
  : never;
@@ -739,6 +750,9 @@ export function createCogsStateFromSync<
739
750
  initialState[key as keyof StateType] = entry.rawSchema;
740
751
  } else if (entry.schemas?.defaults) {
741
752
  initialState[key as keyof StateType] = entry.schemas.defaults;
753
+ } else if (entry._tableName) {
754
+ // It's a raw schema object
755
+ initialState[key as keyof StateType] = entry;
742
756
  } else {
743
757
  initialState[key as keyof StateType] = {} as any;
744
758
  }
@@ -749,7 +763,6 @@ export function createCogsStateFromSync<
749
763
  __syncNotifications: syncSchema.notifications,
750
764
  });
751
765
  }
752
-
753
766
  const {
754
767
  getInitialOptions,
755
768
  getValidationErrors,