api-core-lib 12.0.11 → 12.0.13
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 +41 -29
- package/dist/client.js +41 -29
- package/dist/index.cjs +6 -4
- package/dist/index.d.cts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +6 -4
- package/dist/server.cjs +6 -4
- package/dist/server.js +6 -4
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -586,11 +586,13 @@ var GlobalStateManager = class {
|
|
|
586
586
|
constructor() {
|
|
587
587
|
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
588
588
|
}
|
|
589
|
-
/**
|
|
590
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
591
|
-
*/
|
|
592
589
|
getSnapshot(key) {
|
|
593
|
-
|
|
590
|
+
if (!this.store.has(key)) {
|
|
591
|
+
const initialState = createInitialState();
|
|
592
|
+
this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
|
|
593
|
+
return initialState;
|
|
594
|
+
}
|
|
595
|
+
return this.store.get(key).state;
|
|
594
596
|
}
|
|
595
597
|
/**
|
|
596
598
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
|
@@ -678,6 +680,26 @@ var globalStateManager = new GlobalStateManager();
|
|
|
678
680
|
// src/hooks/useApiModule/useApiModule.ts
|
|
679
681
|
var ApiModuleContext = (0, import_react4.createContext)(null);
|
|
680
682
|
var ApiModuleProvider = ApiModuleContext.Provider;
|
|
683
|
+
function useApiActionState(actionConfig, cacheKey, actionExecutor, enabled) {
|
|
684
|
+
const getClientSnapshot = () => globalStateManager.getSnapshot(cacheKey);
|
|
685
|
+
const getServerSnapshot = () => globalStateManager.getSnapshot(cacheKey);
|
|
686
|
+
const state = (0, import_react4.useSyncExternalStore)(
|
|
687
|
+
(callback) => globalStateManager.subscribe(cacheKey, callback),
|
|
688
|
+
getClientSnapshot,
|
|
689
|
+
// لقطة العميل
|
|
690
|
+
getServerSnapshot
|
|
691
|
+
// لقطة الخادم
|
|
692
|
+
);
|
|
693
|
+
const input = actionConfig.hasQuery ? state.options : void 0;
|
|
694
|
+
(0, import_react4.useEffect)(() => {
|
|
695
|
+
if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
|
|
696
|
+
actionExecutor(input);
|
|
697
|
+
} else if (enabled && state.isStale && !state.loading) {
|
|
698
|
+
actionExecutor(input);
|
|
699
|
+
}
|
|
700
|
+
}, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, actionExecutor, input]);
|
|
701
|
+
return state;
|
|
702
|
+
}
|
|
681
703
|
function useModuleContext() {
|
|
682
704
|
const context = (0, import_react4.useContext)(ApiModuleContext);
|
|
683
705
|
if (!context) {
|
|
@@ -784,32 +806,22 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
784
806
|
}
|
|
785
807
|
return builtQueries;
|
|
786
808
|
}, [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
|
-
});
|
|
809
|
+
const states = {};
|
|
810
|
+
for (const actionName in moduleConfig.actions) {
|
|
811
|
+
if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
|
|
812
|
+
const actionConfig = moduleConfig.actions[actionName];
|
|
813
|
+
const query = queries[actionName]?.options;
|
|
814
|
+
const input = actionConfig.hasQuery ? query : void 0;
|
|
815
|
+
const pathParams = JSON.parse(pathParamsString);
|
|
816
|
+
const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
|
|
817
|
+
states[actionName] = useApiActionState(
|
|
818
|
+
actionConfig,
|
|
819
|
+
cacheKey,
|
|
820
|
+
actions[actionName].execute,
|
|
821
|
+
enabled
|
|
822
|
+
);
|
|
810
823
|
}
|
|
811
|
-
|
|
812
|
-
}, [moduleConfig, pathParamsString, queries, enabled, actions]);
|
|
824
|
+
}
|
|
813
825
|
(0, import_react4.useEffect)(() => {
|
|
814
826
|
if (!enabled) return;
|
|
815
827
|
const actionKeys = Object.keys(moduleConfig.actions);
|
package/dist/client.js
CHANGED
|
@@ -547,11 +547,13 @@ var GlobalStateManager = class {
|
|
|
547
547
|
constructor() {
|
|
548
548
|
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
549
549
|
}
|
|
550
|
-
/**
|
|
551
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
552
|
-
*/
|
|
553
550
|
getSnapshot(key) {
|
|
554
|
-
|
|
551
|
+
if (!this.store.has(key)) {
|
|
552
|
+
const initialState = createInitialState();
|
|
553
|
+
this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
|
|
554
|
+
return initialState;
|
|
555
|
+
}
|
|
556
|
+
return this.store.get(key).state;
|
|
555
557
|
}
|
|
556
558
|
/**
|
|
557
559
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
|
@@ -639,6 +641,26 @@ var globalStateManager = new GlobalStateManager();
|
|
|
639
641
|
// src/hooks/useApiModule/useApiModule.ts
|
|
640
642
|
var ApiModuleContext = createContext(null);
|
|
641
643
|
var ApiModuleProvider = ApiModuleContext.Provider;
|
|
644
|
+
function useApiActionState(actionConfig, cacheKey, actionExecutor, enabled) {
|
|
645
|
+
const getClientSnapshot = () => globalStateManager.getSnapshot(cacheKey);
|
|
646
|
+
const getServerSnapshot = () => globalStateManager.getSnapshot(cacheKey);
|
|
647
|
+
const state = useSyncExternalStore(
|
|
648
|
+
(callback) => globalStateManager.subscribe(cacheKey, callback),
|
|
649
|
+
getClientSnapshot,
|
|
650
|
+
// لقطة العميل
|
|
651
|
+
getServerSnapshot
|
|
652
|
+
// لقطة الخادم
|
|
653
|
+
);
|
|
654
|
+
const input = actionConfig.hasQuery ? state.options : void 0;
|
|
655
|
+
useEffect4(() => {
|
|
656
|
+
if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
|
|
657
|
+
actionExecutor(input);
|
|
658
|
+
} else if (enabled && state.isStale && !state.loading) {
|
|
659
|
+
actionExecutor(input);
|
|
660
|
+
}
|
|
661
|
+
}, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, actionExecutor, input]);
|
|
662
|
+
return state;
|
|
663
|
+
}
|
|
642
664
|
function useModuleContext() {
|
|
643
665
|
const context = useContext(ApiModuleContext);
|
|
644
666
|
if (!context) {
|
|
@@ -745,32 +767,22 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
745
767
|
}
|
|
746
768
|
return builtQueries;
|
|
747
769
|
}, [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
|
-
});
|
|
770
|
+
const states = {};
|
|
771
|
+
for (const actionName in moduleConfig.actions) {
|
|
772
|
+
if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
|
|
773
|
+
const actionConfig = moduleConfig.actions[actionName];
|
|
774
|
+
const query = queries[actionName]?.options;
|
|
775
|
+
const input = actionConfig.hasQuery ? query : void 0;
|
|
776
|
+
const pathParams = JSON.parse(pathParamsString);
|
|
777
|
+
const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
|
|
778
|
+
states[actionName] = useApiActionState(
|
|
779
|
+
actionConfig,
|
|
780
|
+
cacheKey,
|
|
781
|
+
actions[actionName].execute,
|
|
782
|
+
enabled
|
|
783
|
+
);
|
|
771
784
|
}
|
|
772
|
-
|
|
773
|
-
}, [moduleConfig, pathParamsString, queries, enabled, actions]);
|
|
785
|
+
}
|
|
774
786
|
useEffect4(() => {
|
|
775
787
|
if (!enabled) return;
|
|
776
788
|
const actionKeys = Object.keys(moduleConfig.actions);
|
package/dist/index.cjs
CHANGED
|
@@ -543,11 +543,13 @@ var GlobalStateManager = class {
|
|
|
543
543
|
constructor() {
|
|
544
544
|
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
545
545
|
}
|
|
546
|
-
/**
|
|
547
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
548
|
-
*/
|
|
549
546
|
getSnapshot(key) {
|
|
550
|
-
|
|
547
|
+
if (!this.store.has(key)) {
|
|
548
|
+
const initialState = createInitialState();
|
|
549
|
+
this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
|
|
550
|
+
return initialState;
|
|
551
|
+
}
|
|
552
|
+
return this.store.get(key).state;
|
|
551
553
|
}
|
|
552
554
|
/**
|
|
553
555
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
package/dist/index.d.cts
CHANGED
|
@@ -74,9 +74,6 @@ declare function createApiActions<TActions extends Record<string, {
|
|
|
74
74
|
|
|
75
75
|
declare class GlobalStateManager {
|
|
76
76
|
private store;
|
|
77
|
-
/**
|
|
78
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
79
|
-
*/
|
|
80
77
|
getSnapshot<T>(key: string): ActionStateModule<T>;
|
|
81
78
|
/**
|
|
82
79
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
package/dist/index.d.ts
CHANGED
|
@@ -74,9 +74,6 @@ declare function createApiActions<TActions extends Record<string, {
|
|
|
74
74
|
|
|
75
75
|
declare class GlobalStateManager {
|
|
76
76
|
private store;
|
|
77
|
-
/**
|
|
78
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
79
|
-
*/
|
|
80
77
|
getSnapshot<T>(key: string): ActionStateModule<T>;
|
|
81
78
|
/**
|
|
82
79
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
package/dist/index.js
CHANGED
|
@@ -502,11 +502,13 @@ var GlobalStateManager = class {
|
|
|
502
502
|
constructor() {
|
|
503
503
|
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
504
504
|
}
|
|
505
|
-
/**
|
|
506
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
507
|
-
*/
|
|
508
505
|
getSnapshot(key) {
|
|
509
|
-
|
|
506
|
+
if (!this.store.has(key)) {
|
|
507
|
+
const initialState = createInitialState();
|
|
508
|
+
this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
|
|
509
|
+
return initialState;
|
|
510
|
+
}
|
|
511
|
+
return this.store.get(key).state;
|
|
510
512
|
}
|
|
511
513
|
/**
|
|
512
514
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
package/dist/server.cjs
CHANGED
|
@@ -195,11 +195,13 @@ var GlobalStateManager = class {
|
|
|
195
195
|
constructor() {
|
|
196
196
|
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
197
197
|
}
|
|
198
|
-
/**
|
|
199
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
200
|
-
*/
|
|
201
198
|
getSnapshot(key) {
|
|
202
|
-
|
|
199
|
+
if (!this.store.has(key)) {
|
|
200
|
+
const initialState = createInitialState();
|
|
201
|
+
this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
|
|
202
|
+
return initialState;
|
|
203
|
+
}
|
|
204
|
+
return this.store.get(key).state;
|
|
203
205
|
}
|
|
204
206
|
/**
|
|
205
207
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
package/dist/server.js
CHANGED
|
@@ -161,11 +161,13 @@ var GlobalStateManager = class {
|
|
|
161
161
|
constructor() {
|
|
162
162
|
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
163
163
|
}
|
|
164
|
-
/**
|
|
165
|
-
* يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
|
|
166
|
-
*/
|
|
167
164
|
getSnapshot(key) {
|
|
168
|
-
|
|
165
|
+
if (!this.store.has(key)) {
|
|
166
|
+
const initialState = createInitialState();
|
|
167
|
+
this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
|
|
168
|
+
return initialState;
|
|
169
|
+
}
|
|
170
|
+
return this.store.get(key).state;
|
|
169
171
|
}
|
|
170
172
|
/**
|
|
171
173
|
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|