cogsbox-state 0.5.457 → 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/dist/CogsState.d.ts +11 -3
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +70 -70
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +16 -12
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -426,7 +426,7 @@ export type OptionsType<T extends unknown = unknown, TApiParams = never> = {
|
|
|
426
426
|
syncUpdate?: Partial<UpdateTypeDetail>;
|
|
427
427
|
|
|
428
428
|
defaultState?: T;
|
|
429
|
-
|
|
429
|
+
|
|
430
430
|
dependencies?: any[];
|
|
431
431
|
};
|
|
432
432
|
|
|
@@ -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 {
|
|
@@ -708,7 +713,9 @@ export function createCogsStateFromSync<
|
|
|
708
713
|
string,
|
|
709
714
|
{
|
|
710
715
|
schemas: { defaultValues: any };
|
|
711
|
-
|
|
716
|
+
api?: {
|
|
717
|
+
queryData?: any;
|
|
718
|
+
};
|
|
712
719
|
[key: string]: any;
|
|
713
720
|
}
|
|
714
721
|
>;
|
|
@@ -721,11 +728,9 @@ export function createCogsStateFromSync<
|
|
|
721
728
|
[K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['schemas']['defaultValues'];
|
|
722
729
|
},
|
|
723
730
|
{
|
|
724
|
-
[K in keyof TSyncSchema['schemas']]:
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
? P
|
|
728
|
-
: never;
|
|
731
|
+
[K in keyof TSyncSchema['schemas']]: GetParamType<
|
|
732
|
+
TSyncSchema['schemas'][K]
|
|
733
|
+
>;
|
|
729
734
|
}
|
|
730
735
|
> {
|
|
731
736
|
const schemas = syncSchema.schemas;
|
|
@@ -737,9 +742,9 @@ export function createCogsStateFromSync<
|
|
|
737
742
|
const entry = schemas[key];
|
|
738
743
|
initialState[key] = entry?.schemas?.defaultValues || {};
|
|
739
744
|
|
|
740
|
-
//
|
|
741
|
-
if (entry?.
|
|
742
|
-
apiParamsMap[key] = entry.
|
|
745
|
+
// Extract apiParams from the api.queryData._paramType
|
|
746
|
+
if (entry?.api?.queryData?._paramType) {
|
|
747
|
+
apiParamsMap[key] = entry.api.queryData._paramType;
|
|
743
748
|
}
|
|
744
749
|
}
|
|
745
750
|
|
|
@@ -750,7 +755,6 @@ export function createCogsStateFromSync<
|
|
|
750
755
|
__apiParamsMap: apiParamsMap,
|
|
751
756
|
}) as any;
|
|
752
757
|
}
|
|
753
|
-
|
|
754
758
|
const {
|
|
755
759
|
getInitialOptions,
|
|
756
760
|
getValidationErrors,
|