api-core-lib 12.0.20 → 12.0.22

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/client.cjs CHANGED
@@ -717,25 +717,20 @@ function useApiActionState(actionConfig, cacheKey, execute, input, enabled) {
717
717
  const refetch = (0, import_react4.useCallback)(() => {
718
718
  execute(inputRef.current);
719
719
  }, [execute]);
720
- const previousInput = (0, import_react4.useRef)(JSON.stringify(input));
720
+ const prevCacheKeyRef = (0, import_react4.useRef)(cacheKey);
721
721
  (0, import_react4.useEffect)(() => {
722
- const currentInputString = JSON.stringify(input);
723
- if (previousInput.current === currentInputString) {
724
- return;
725
- }
726
- if (enabled && state.called) {
727
- console.log("[Query Changed] Input changed, refetching...");
722
+ if (prevCacheKeyRef.current !== cacheKey && enabled && state.called) {
723
+ console.log(`[Cache Key Changed] from ${prevCacheKeyRef.current} to ${cacheKey}. Refetching...`);
728
724
  refetch();
729
- }
730
- previousInput.current = currentInputString;
731
- }, [input, enabled, state.called, refetch]);
732
- (0, import_react4.useEffect)(() => {
733
- if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
725
+ } else if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
726
+ console.log(`[Auto Fetch] for ${cacheKey}. Fetching...`);
734
727
  refetch();
735
728
  } else if (enabled && state.isStale && !state.loading) {
729
+ console.log(`[Stale State] for ${cacheKey}. Refetching...`);
736
730
  refetch();
737
731
  }
738
- }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, refetch]);
732
+ prevCacheKeyRef.current = cacheKey;
733
+ }, [cacheKey, enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, refetch]);
739
734
  return state;
740
735
  }
741
736
  function useModuleContext() {
@@ -850,19 +845,21 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
850
845
  const builtQueries = {};
851
846
  for (const actionName in moduleConfig.actions) {
852
847
  if (moduleConfig.actions[actionName]?.hasQuery) {
853
- const setActionQueryOptions = (updater) => {
848
+ const setActionQueryOptions = (0, import_react4.useCallback)((updater) => {
854
849
  setQueryOptions((prev) => ({ ...prev, [actionName]: typeof updater === "function" ? updater(prev[actionName] || {}) : updater }));
855
- };
850
+ }, []);
856
851
  builtQueries[actionName] = {
852
+ // `options` ستتغير، وهذا صحيح
857
853
  options: queryOptions[actionName] || {},
854
+ // `setOptions` والدوال الأخرى ستكون الآن مستقرة
858
855
  setOptions: setActionQueryOptions,
859
- setPage: (page) => setActionQueryOptions((p) => ({ ...p, page })),
860
- setLimit: (limit) => setActionQueryOptions((p) => ({ ...p, limit, page: 1 })),
861
- setSearchTerm: (search) => setActionQueryOptions((p) => ({ ...p, search, page: 1 })),
862
- setFilters: (filter) => setActionQueryOptions((p) => ({ ...p, filter, page: 1 })),
863
- setSorting: (sortBy) => setActionQueryOptions((p) => ({ ...p, sortBy })),
864
- setQueryParam: (key, value) => setActionQueryOptions((p) => ({ ...p, [key]: value, page: key !== "page" ? value : p.page })),
865
- reset: () => setActionQueryOptions({})
856
+ setPage: (0, import_react4.useCallback)((page) => setActionQueryOptions((p) => ({ ...p, page })), [setActionQueryOptions]),
857
+ setLimit: (0, import_react4.useCallback)((limit) => setActionQueryOptions((p) => ({ ...p, limit, page: 1 })), [setActionQueryOptions]),
858
+ setSearchTerm: (0, import_react4.useCallback)((search) => setActionQueryOptions((p) => ({ ...p, search, page: 1 })), [setActionQueryOptions]),
859
+ setFilters: (0, import_react4.useCallback)((filter) => setActionQueryOptions((p) => ({ ...p, filter, page: 1 })), [setActionQueryOptions]),
860
+ setSorting: (0, import_react4.useCallback)((sortBy) => setActionQueryOptions((p) => ({ ...p, sortBy })), [setActionQueryOptions]),
861
+ setQueryParam: (0, import_react4.useCallback)((key, value) => setActionQueryOptions((p) => ({ ...p, [key]: value, page: key !== "page" ? value : p.page })), [setActionQueryOptions]),
862
+ reset: (0, import_react4.useCallback)(() => setActionQueryOptions({}), [setActionQueryOptions])
866
863
  };
867
864
  }
868
865
  }
package/dist/client.js CHANGED
@@ -678,25 +678,20 @@ function useApiActionState(actionConfig, cacheKey, execute, input, enabled) {
678
678
  const refetch = useCallback3(() => {
679
679
  execute(inputRef.current);
680
680
  }, [execute]);
681
- const previousInput = useRef4(JSON.stringify(input));
681
+ const prevCacheKeyRef = useRef4(cacheKey);
682
682
  useEffect4(() => {
683
- const currentInputString = JSON.stringify(input);
684
- if (previousInput.current === currentInputString) {
685
- return;
686
- }
687
- if (enabled && state.called) {
688
- console.log("[Query Changed] Input changed, refetching...");
683
+ if (prevCacheKeyRef.current !== cacheKey && enabled && state.called) {
684
+ console.log(`[Cache Key Changed] from ${prevCacheKeyRef.current} to ${cacheKey}. Refetching...`);
689
685
  refetch();
690
- }
691
- previousInput.current = currentInputString;
692
- }, [input, enabled, state.called, refetch]);
693
- useEffect4(() => {
694
- if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
686
+ } else if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
687
+ console.log(`[Auto Fetch] for ${cacheKey}. Fetching...`);
695
688
  refetch();
696
689
  } else if (enabled && state.isStale && !state.loading) {
690
+ console.log(`[Stale State] for ${cacheKey}. Refetching...`);
697
691
  refetch();
698
692
  }
699
- }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, refetch]);
693
+ prevCacheKeyRef.current = cacheKey;
694
+ }, [cacheKey, enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, refetch]);
700
695
  return state;
701
696
  }
702
697
  function useModuleContext() {
@@ -811,19 +806,21 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
811
806
  const builtQueries = {};
812
807
  for (const actionName in moduleConfig.actions) {
813
808
  if (moduleConfig.actions[actionName]?.hasQuery) {
814
- const setActionQueryOptions = (updater) => {
809
+ const setActionQueryOptions = useCallback3((updater) => {
815
810
  setQueryOptions((prev) => ({ ...prev, [actionName]: typeof updater === "function" ? updater(prev[actionName] || {}) : updater }));
816
- };
811
+ }, []);
817
812
  builtQueries[actionName] = {
813
+ // `options` ستتغير، وهذا صحيح
818
814
  options: queryOptions[actionName] || {},
815
+ // `setOptions` والدوال الأخرى ستكون الآن مستقرة
819
816
  setOptions: setActionQueryOptions,
820
- setPage: (page) => setActionQueryOptions((p) => ({ ...p, page })),
821
- setLimit: (limit) => setActionQueryOptions((p) => ({ ...p, limit, page: 1 })),
822
- setSearchTerm: (search) => setActionQueryOptions((p) => ({ ...p, search, page: 1 })),
823
- setFilters: (filter) => setActionQueryOptions((p) => ({ ...p, filter, page: 1 })),
824
- setSorting: (sortBy) => setActionQueryOptions((p) => ({ ...p, sortBy })),
825
- setQueryParam: (key, value) => setActionQueryOptions((p) => ({ ...p, [key]: value, page: key !== "page" ? value : p.page })),
826
- reset: () => setActionQueryOptions({})
817
+ setPage: useCallback3((page) => setActionQueryOptions((p) => ({ ...p, page })), [setActionQueryOptions]),
818
+ setLimit: useCallback3((limit) => setActionQueryOptions((p) => ({ ...p, limit, page: 1 })), [setActionQueryOptions]),
819
+ setSearchTerm: useCallback3((search) => setActionQueryOptions((p) => ({ ...p, search, page: 1 })), [setActionQueryOptions]),
820
+ setFilters: useCallback3((filter) => setActionQueryOptions((p) => ({ ...p, filter, page: 1 })), [setActionQueryOptions]),
821
+ setSorting: useCallback3((sortBy) => setActionQueryOptions((p) => ({ ...p, sortBy })), [setActionQueryOptions]),
822
+ setQueryParam: useCallback3((key, value) => setActionQueryOptions((p) => ({ ...p, [key]: value, page: key !== "page" ? value : p.page })), [setActionQueryOptions]),
823
+ reset: useCallback3(() => setActionQueryOptions({}), [setActionQueryOptions])
827
824
  };
828
825
  }
829
826
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.20",
3
+ "version": "12.0.22",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6