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/dist/CogsState.d.ts +8 -8
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +523 -540
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +13 -52
package/package.json
CHANGED
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
|
|
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
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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
|
-
|
|
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,
|