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 +30 -25
- package/dist/client.js +30 -25
- package/package.json +1 -1
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 =
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
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
|
-
|
|
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 =
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
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
|
-
|
|
773
|
-
}, [moduleConfig, pathParamsString, queries, enabled, actions]);
|
|
778
|
+
}
|
|
774
779
|
useEffect4(() => {
|
|
775
780
|
if (!enabled) return;
|
|
776
781
|
const actionKeys = Object.keys(moduleConfig.actions);
|