cogsbox-state 0.5.453 → 0.5.454

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.453",
3
+ "version": "0.5.454",
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
@@ -38,7 +38,6 @@ import { Operation } from 'fast-json-patch';
38
38
  import { useInView } from 'react-intersection-observer';
39
39
  import * as z3 from 'zod/v3';
40
40
  import z, * as z4 from 'zod/v4';
41
- import { keyof } from 'zod';
42
41
 
43
42
  type Prettify<T> = T extends any ? { [K in keyof T]: T[K] } : never;
44
43
 
@@ -684,7 +683,7 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
684
683
 
685
684
  return { useCogsState, setCogsOptions } as CogsApi<State>;
686
685
  };
687
- // Fixed version that properly handles the apiParams type without complex inference
686
+
688
687
  export function createCogsStateFromSync<
689
688
  TSyncSchema extends {
690
689
  schemas: Record<
@@ -697,20 +696,7 @@ export function createCogsStateFromSync<
697
696
  >;
698
697
  notifications: Record<string, any>;
699
698
  },
700
- >(
701
- syncSchema: TSyncSchema
702
- ): {
703
- useCogsState: <K extends keyof TSyncSchema['schemas']>(
704
- stateKey: K,
705
- options?: OptionsType<
706
- TSyncSchema['schemas'][K]['schemas']['defaultValues'],
707
- any
708
- > & {
709
- apiParams?: any;
710
- }
711
- ) => StateObject<TSyncSchema['schemas'][K]['schemas']['defaultValues']>;
712
- setCogsOptions: any;
713
- } {
699
+ >(syncSchema: TSyncSchema) {
714
700
  const schemas = syncSchema.schemas;
715
701
  const initialState: any = {};
716
702
 
@@ -726,30 +712,12 @@ export function createCogsStateFromSync<
726
712
  __syncNotifications: syncSchema.notifications,
727
713
  });
728
714
 
729
- // Create the properly typed useCogsState function
715
+ // Override the useCogsState function to handle apiParams properly
730
716
  const useCogsState = <K extends keyof TSyncSchema['schemas']>(
731
717
  stateKey: K,
732
- options?: OptionsType<
733
- TSyncSchema['schemas'][K]['schemas']['defaultValues'],
734
- any
735
- > & {
736
- apiParams?: any;
737
- }
738
- ): StateObject<TSyncSchema['schemas'][K]['schemas']['defaultValues']> => {
739
- // Runtime validation of API params
740
- const schemaEntry = schemas[stateKey as keyof typeof schemas];
741
- if (schemaEntry?.apiParamsSchema && options?.apiParams) {
742
- const result = schemaEntry.apiParamsSchema.safeParse(options.apiParams);
743
- if (!result.success) {
744
- throw new Error(
745
- `Invalid API params for ${String(stateKey)}: ${result.error.message}`
746
- );
747
- }
748
- }
749
-
750
- return baseApi.useCogsState(stateKey as any, options as any) as StateObject<
751
- TSyncSchema['schemas'][K]['schemas']['defaultValues']
752
- >;
718
+ options?: any // Just make this flexible
719
+ ) => {
720
+ return baseApi.useCogsState(stateKey as any, options);
753
721
  };
754
722
 
755
723
  return {
@@ -757,6 +725,7 @@ export function createCogsStateFromSync<
757
725
  setCogsOptions: baseApi.setCogsOptions,
758
726
  };
759
727
  }
728
+
760
729
  const {
761
730
  getInitialOptions,
762
731
  getValidationErrors,