cogsbox-state 0.5.458 → 0.5.459

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.458",
3
+ "version": "0.5.459",
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
@@ -677,6 +677,7 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
677
677
 
678
678
  return { useCogsState, setCogsOptions } as CogsApi<State>;
679
679
  };
680
+
680
681
  // Fix for UseCogsStateHook to support per-key apiParams
681
682
  type UseCogsStateHook<
682
683
  T extends Record<string, any>,
@@ -700,7 +701,11 @@ type CogsApi<
700
701
  useCogsState: UseCogsStateHook<T, TApiParamsMap>;
701
702
  setCogsOptions: SetCogsOptionsFunc<T>;
702
703
  };
703
-
704
+ type GetParamType<SchemaEntry> = SchemaEntry extends {
705
+ api?: { queryData?: { _paramType?: infer P } };
706
+ }
707
+ ? P // If the full path exists, infer the parameter type P.
708
+ : never; // Otherwise, the type is 'never', meaning no params.
704
709
  // Fixed createCogsStateFromSync return type
705
710
  export function createCogsStateFromSync<
706
711
  TSyncSchema extends {
@@ -723,13 +728,9 @@ export function createCogsStateFromSync<
723
728
  [K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['schemas']['defaultValues'];
724
729
  },
725
730
  {
726
- [K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['api'] extends {
727
- queryData: infer Q;
728
- }
729
- ? Q extends { _paramType: infer P }
730
- ? P
731
- : never
732
- : never;
731
+ [K in keyof TSyncSchema['schemas']]: GetParamType<
732
+ TSyncSchema['schemas'][K]
733
+ >;
733
734
  }
734
735
  > {
735
736
  const schemas = syncSchema.schemas;