api-core-lib 12.0.11 → 12.0.12

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
@@ -678,6 +678,21 @@ var globalStateManager = new GlobalStateManager();
678
678
  // src/hooks/useApiModule/useApiModule.ts
679
679
  var ApiModuleContext = (0, import_react4.createContext)(null);
680
680
  var ApiModuleProvider = ApiModuleContext.Provider;
681
+ function useApiActionState(actionConfig, cacheKey, actionExecutor, enabled) {
682
+ const state = (0, import_react4.useSyncExternalStore)(
683
+ (callback) => globalStateManager.subscribe(cacheKey, callback),
684
+ () => globalStateManager.getSnapshot(cacheKey)
685
+ );
686
+ const input = actionConfig.hasQuery ? state.options : void 0;
687
+ (0, import_react4.useEffect)(() => {
688
+ if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
689
+ actionExecutor(input);
690
+ } else if (enabled && state.isStale && !state.loading) {
691
+ actionExecutor(input);
692
+ }
693
+ }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, actionExecutor, input]);
694
+ return state;
695
+ }
681
696
  function useModuleContext() {
682
697
  const context = (0, import_react4.useContext)(ApiModuleContext);
683
698
  if (!context) {
@@ -784,32 +799,22 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
784
799
  }
785
800
  return builtQueries;
786
801
  }, [queryOptions, moduleConfig.actions]);
787
- const states = (0, import_react4.useMemo)(() => {
788
- const finalStates = {};
789
- for (const actionName of Object.keys(moduleConfig.actions)) {
790
- Object.defineProperty(finalStates, actionName, {
791
- get: () => {
792
- const actionConfig = moduleConfig.actions[actionName];
793
- const query = queries[actionName]?.options;
794
- const input = actionConfig.hasQuery ? query : void 0;
795
- const pathParams = JSON.parse(pathParamsString);
796
- const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
797
- const state = (0, import_react4.useSyncExternalStore)(
798
- (callback) => globalStateManager.subscribe(cacheKey, callback),
799
- () => globalStateManager.getSnapshot(cacheKey)
800
- );
801
- (0, import_react4.useEffect)(() => {
802
- if (enabled && state.isStale && !state.loading) {
803
- actions[actionName].execute(input);
804
- }
805
- }, [enabled, state.isStale, state.loading, input, actions, actionName]);
806
- return state;
807
- },
808
- enumerable: true
809
- });
802
+ const states = {};
803
+ for (const actionName in moduleConfig.actions) {
804
+ if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
805
+ const actionConfig = moduleConfig.actions[actionName];
806
+ const query = queries[actionName]?.options;
807
+ const input = actionConfig.hasQuery ? query : void 0;
808
+ const pathParams = JSON.parse(pathParamsString);
809
+ const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
810
+ states[actionName] = useApiActionState(
811
+ actionConfig,
812
+ cacheKey,
813
+ actions[actionName].execute,
814
+ enabled
815
+ );
810
816
  }
811
- return finalStates;
812
- }, [moduleConfig, pathParamsString, queries, enabled, actions]);
817
+ }
813
818
  (0, import_react4.useEffect)(() => {
814
819
  if (!enabled) return;
815
820
  const actionKeys = Object.keys(moduleConfig.actions);
package/dist/client.js CHANGED
@@ -639,6 +639,21 @@ var globalStateManager = new GlobalStateManager();
639
639
  // src/hooks/useApiModule/useApiModule.ts
640
640
  var ApiModuleContext = createContext(null);
641
641
  var ApiModuleProvider = ApiModuleContext.Provider;
642
+ function useApiActionState(actionConfig, cacheKey, actionExecutor, enabled) {
643
+ const state = useSyncExternalStore(
644
+ (callback) => globalStateManager.subscribe(cacheKey, callback),
645
+ () => globalStateManager.getSnapshot(cacheKey)
646
+ );
647
+ const input = actionConfig.hasQuery ? state.options : void 0;
648
+ useEffect4(() => {
649
+ if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
650
+ actionExecutor(input);
651
+ } else if (enabled && state.isStale && !state.loading) {
652
+ actionExecutor(input);
653
+ }
654
+ }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, actionExecutor, input]);
655
+ return state;
656
+ }
642
657
  function useModuleContext() {
643
658
  const context = useContext(ApiModuleContext);
644
659
  if (!context) {
@@ -745,32 +760,22 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
745
760
  }
746
761
  return builtQueries;
747
762
  }, [queryOptions, moduleConfig.actions]);
748
- const states = useMemo3(() => {
749
- const finalStates = {};
750
- for (const actionName of Object.keys(moduleConfig.actions)) {
751
- Object.defineProperty(finalStates, actionName, {
752
- get: () => {
753
- const actionConfig = moduleConfig.actions[actionName];
754
- const query = queries[actionName]?.options;
755
- const input = actionConfig.hasQuery ? query : void 0;
756
- const pathParams = JSON.parse(pathParamsString);
757
- const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
758
- const state = useSyncExternalStore(
759
- (callback) => globalStateManager.subscribe(cacheKey, callback),
760
- () => globalStateManager.getSnapshot(cacheKey)
761
- );
762
- useEffect4(() => {
763
- if (enabled && state.isStale && !state.loading) {
764
- actions[actionName].execute(input);
765
- }
766
- }, [enabled, state.isStale, state.loading, input, actions, actionName]);
767
- return state;
768
- },
769
- enumerable: true
770
- });
763
+ const states = {};
764
+ for (const actionName in moduleConfig.actions) {
765
+ if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
766
+ const actionConfig = moduleConfig.actions[actionName];
767
+ const query = queries[actionName]?.options;
768
+ const input = actionConfig.hasQuery ? query : void 0;
769
+ const pathParams = JSON.parse(pathParamsString);
770
+ const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
771
+ states[actionName] = useApiActionState(
772
+ actionConfig,
773
+ cacheKey,
774
+ actions[actionName].execute,
775
+ enabled
776
+ );
771
777
  }
772
- return finalStates;
773
- }, [moduleConfig, pathParamsString, queries, enabled, actions]);
778
+ }
774
779
  useEffect4(() => {
775
780
  if (!enabled) return;
776
781
  const actionKeys = Object.keys(moduleConfig.actions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.11",
3
+ "version": "12.0.12",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6