cogsbox-state 0.5.453 → 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.453",
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,8 +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';
41
- import { keyof } from 'zod';
40
+ import * as z4 from 'zod/v4';
42
41
 
43
42
  type Prettify<T> = T extends any ? { [K in keyof T]: T[K] } : never;
44
43
 
@@ -684,14 +683,12 @@ 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
688
686
  export function createCogsStateFromSync<
689
687
  TSyncSchema extends {
690
688
  schemas: Record<
691
689
  string,
692
690
  {
693
691
  schemas: { defaultValues: any };
694
- apiParamsSchema?: z.ZodObject<any>;
695
692
  [key: string]: any;
696
693
  }
697
694
  >;
@@ -699,18 +696,16 @@ export function createCogsStateFromSync<
699
696
  },
700
697
  >(
701
698
  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
+ ): 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
+ > {
714
709
  const schemas = syncSchema.schemas;
715
710
  const initialState: any = {};
716
711
 
@@ -720,43 +715,9 @@ export function createCogsStateFromSync<
720
715
  initialState[key] = entry?.schemas?.defaultValues || {};
721
716
  }
722
717
 
723
- // Create the base CogsApi
724
- const baseApi = createCogsState(initialState, {
725
- __fromSyncSchema: true,
726
- __syncNotifications: syncSchema.notifications,
727
- });
728
-
729
- // Create the properly typed useCogsState function
730
- const useCogsState = <K extends keyof TSyncSchema['schemas']>(
731
- 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
- >;
753
- };
754
-
755
- return {
756
- useCogsState,
757
- setCogsOptions: baseApi.setCogsOptions,
758
- };
718
+ return createCogsState(initialState);
759
719
  }
720
+
760
721
  const {
761
722
  getInitialOptions,
762
723
  getValidationErrors,