cogsbox-state 0.5.454 → 0.5.455

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.454",
3
+ "version": "0.5.455",
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
@@ -37,7 +37,7 @@ import { useCogsConfig } from './CogsStateClient.js';
37
37
  import { Operation } from 'fast-json-patch';
38
38
  import { useInView } from 'react-intersection-observer';
39
39
  import * as z3 from 'zod/v3';
40
- import z, * as z4 from 'zod/v4';
40
+ import * as z4 from 'zod/v4';
41
41
 
42
42
  type Prettify<T> = T extends any ? { [K in keyof T]: T[K] } : never;
43
43
 
@@ -683,20 +683,29 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
683
683
 
684
684
  return { useCogsState, setCogsOptions } as CogsApi<State>;
685
685
  };
686
-
687
686
  export function createCogsStateFromSync<
688
687
  TSyncSchema extends {
689
688
  schemas: Record<
690
689
  string,
691
690
  {
692
691
  schemas: { defaultValues: any };
693
- apiParamsSchema?: z.ZodObject<any>;
694
692
  [key: string]: any;
695
693
  }
696
694
  >;
697
695
  notifications: Record<string, any>;
698
696
  },
699
- >(syncSchema: TSyncSchema) {
697
+ >(
698
+ syncSchema: TSyncSchema
699
+ ): CogsApi<
700
+ {
701
+ [K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['schemas']['defaultValues'];
702
+ },
703
+ {
704
+ [K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['apiParams'];
705
+ }[keyof {
706
+ [K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['apiParams'];
707
+ }]
708
+ > {
700
709
  const schemas = syncSchema.schemas;
701
710
  const initialState: any = {};
702
711
 
@@ -706,24 +715,7 @@ export function createCogsStateFromSync<
706
715
  initialState[key] = entry?.schemas?.defaultValues || {};
707
716
  }
708
717
 
709
- // Create the base CogsApi
710
- const baseApi = createCogsState(initialState, {
711
- __fromSyncSchema: true,
712
- __syncNotifications: syncSchema.notifications,
713
- });
714
-
715
- // Override the useCogsState function to handle apiParams properly
716
- const useCogsState = <K extends keyof TSyncSchema['schemas']>(
717
- stateKey: K,
718
- options?: any // Just make this flexible
719
- ) => {
720
- return baseApi.useCogsState(stateKey as any, options);
721
- };
722
-
723
- return {
724
- useCogsState,
725
- setCogsOptions: baseApi.setCogsOptions,
726
- };
718
+ return createCogsState(initialState);
727
719
  }
728
720
 
729
721
  const {