api-core-lib 12.0.14 → 12.0.15

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.
@@ -255,4 +255,4 @@ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<
255
255
  dehydrate: () => string;
256
256
  }
257
257
 
258
- export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, MiddlewareContext as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ApiClientConfig as d, ActionOptions as e, UseApiQuery as f, ApiError as g, TokenManager as h, Middleware as i, RefreshTokenConfig as j, ActionConfig as k, ActionStateModule as l, UseApiState as m, ActionState as n, ExecuteOptions as o, ModuleActions as p, ModuleStates as q };
258
+ export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, MiddlewareContext as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ApiClientConfig as d, ActionOptions as e, ActionStateModule as f, UseApiQuery as g, ApiError as h, TokenManager as i, Middleware as j, RefreshTokenConfig as k, ActionConfig as l, UseApiState as m, ActionState as n, ExecuteOptions as o, ModuleActions as p, ModuleStates as q };
@@ -255,4 +255,4 @@ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<
255
255
  dehydrate: () => string;
256
256
  }
257
257
 
258
- export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, MiddlewareContext as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ApiClientConfig as d, ActionOptions as e, UseApiQuery as f, ApiError as g, TokenManager as h, Middleware as i, RefreshTokenConfig as j, ActionConfig as k, ActionStateModule as l, UseApiState as m, ActionState as n, ExecuteOptions as o, ModuleActions as p, ModuleStates as q };
258
+ export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, MiddlewareContext as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ApiClientConfig as d, ActionOptions as e, ActionStateModule as f, UseApiQuery as g, ApiError as h, TokenManager as i, Middleware as j, RefreshTokenConfig as k, ActionConfig as l, UseApiState as m, ActionState as n, ExecuteOptions as o, ModuleActions as p, ModuleStates as q };
package/dist/client.cjs CHANGED
@@ -34,8 +34,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
34
34
  var client_exports = {};
35
35
  __export(client_exports, {
36
36
  ApiModuleProvider: () => ApiModuleProvider,
37
- generateCacheKey: () => generateCacheKey,
38
- globalStateManager: () => globalStateManager,
39
37
  useApi: () => useApi,
40
38
  useApiModule: () => useApiModule,
41
39
  useApiRecord: () => useApiRecord,
@@ -679,6 +677,17 @@ var GlobalStateManager = class {
679
677
  };
680
678
  var globalStateManager = new GlobalStateManager();
681
679
 
680
+ // src/core/cacheKey.ts
681
+ var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
682
+ const params = { path: callOptions.pathParams, body: input };
683
+ try {
684
+ return `${moduleName}/${actionName}::${JSON.stringify(params)}`;
685
+ } catch (error) {
686
+ console.warn("Could not stringify cache key params, falling back to timestamp.", { moduleName, actionName, error });
687
+ return `${moduleName}/${actionName}::${Date.now()}`;
688
+ }
689
+ };
690
+
682
691
  // src/hooks/useApiModule/useApiModule.ts
683
692
  var ApiModuleContext = (0, import_react4.createContext)(null);
684
693
  var ApiModuleProvider = ApiModuleContext.Provider;
@@ -863,83 +872,9 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
863
872
  }, []);
864
873
  return { actions, states, queries, dehydrate };
865
874
  }
866
-
867
- // src/core/client.ts
868
- var import_axios3 = __toESM(require("axios"), 1);
869
- var import_uuid = require("uuid");
870
-
871
- // src/core/cache.ts
872
- var CacheManager = class {
873
- constructor() {
874
- __publicField(this, "cache", /* @__PURE__ */ new Map());
875
- __publicField(this, "defaultDuration", 15 * 60 * 1e3);
876
- }
877
- // 15 minutes
878
- set(key, data, duration) {
879
- this.cache.set(key, {
880
- data,
881
- timestamp: Date.now(),
882
- duration: duration || this.defaultDuration
883
- });
884
- }
885
- get(key) {
886
- const item = this.cache.get(key);
887
- if (!item) return null;
888
- const isExpired = Date.now() - item.timestamp > item.duration;
889
- if (isExpired) {
890
- this.cache.delete(key);
891
- return null;
892
- }
893
- return item.data;
894
- }
895
- /**
896
- * [FIX] تم تحويلها إلى دالة عامة (generic) لتعيد النوع الصحيح.
897
- * الآن بدلًا من إرجاع CacheItem<unknown>، ستُرجع CacheItem<T>.
898
- */
899
- getWithMeta(key) {
900
- const item = this.cache.get(key);
901
- if (!item) return null;
902
- const isExpired = Date.now() - item.timestamp > item.duration;
903
- if (isExpired) {
904
- this.cache.delete(key);
905
- return null;
906
- }
907
- return item;
908
- }
909
- delete(key) {
910
- this.cache.delete(key);
911
- }
912
- clear() {
913
- this.cache.clear();
914
- }
915
- invalidateByPrefix(prefix) {
916
- const keysToDelete = [];
917
- for (const key of this.cache.keys()) {
918
- if (key.startsWith(prefix)) {
919
- keysToDelete.push(key);
920
- }
921
- }
922
- keysToDelete.forEach((key) => this.cache.delete(key));
923
- console.log(`Invalidated ${keysToDelete.length} cache entries with prefix: ${prefix}`);
924
- }
925
- };
926
- var cacheManager = new CacheManager();
927
-
928
- // src/core/cacheKey.ts
929
- var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
930
- const params = { path: callOptions.pathParams, body: input };
931
- try {
932
- return `${moduleName}/${actionName}::${JSON.stringify(params)}`;
933
- } catch (error) {
934
- console.warn("Could not stringify cache key params, falling back to timestamp.", { moduleName, actionName, error });
935
- return `${moduleName}/${actionName}::${Date.now()}`;
936
- }
937
- };
938
875
  // Annotate the CommonJS export names for ESM import in node:
939
876
  0 && (module.exports = {
940
877
  ApiModuleProvider,
941
- generateCacheKey,
942
- globalStateManager,
943
878
  useApi,
944
879
  useApiModule,
945
880
  useApiRecord,
package/dist/client.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn } from './apiModule.types-Cvp9QdAc.cjs';
3
- import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './cacheKey-BNQ1ii6y.cjs';
4
- export { b as generateCacheKey, g as globalStateManager } from './cacheKey-BNQ1ii6y.cjs';
2
+ import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn } from './apiModule.types-BTtRM9wO.cjs';
3
+ import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-CBP3Ufvu.cjs';
5
4
  import * as React from 'react';
6
5
 
7
6
  declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
package/dist/client.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn } from './apiModule.types-Cvp9QdAc.js';
3
- import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './cacheKey-BJQaehcQ.js';
4
- export { b as generateCacheKey, g as globalStateManager } from './cacheKey-BJQaehcQ.js';
2
+ import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn } from './apiModule.types-BTtRM9wO.js';
3
+ import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-BsOSJZ5l.js';
5
4
  import * as React from 'react';
6
5
 
7
6
  declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
package/dist/client.js CHANGED
@@ -638,6 +638,17 @@ var GlobalStateManager = class {
638
638
  };
639
639
  var globalStateManager = new GlobalStateManager();
640
640
 
641
+ // src/core/cacheKey.ts
642
+ var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
643
+ const params = { path: callOptions.pathParams, body: input };
644
+ try {
645
+ return `${moduleName}/${actionName}::${JSON.stringify(params)}`;
646
+ } catch (error) {
647
+ console.warn("Could not stringify cache key params, falling back to timestamp.", { moduleName, actionName, error });
648
+ return `${moduleName}/${actionName}::${Date.now()}`;
649
+ }
650
+ };
651
+
641
652
  // src/hooks/useApiModule/useApiModule.ts
642
653
  var ApiModuleContext = createContext(null);
643
654
  var ApiModuleProvider = ApiModuleContext.Provider;
@@ -822,82 +833,8 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
822
833
  }, []);
823
834
  return { actions, states, queries, dehydrate };
824
835
  }
825
-
826
- // src/core/client.ts
827
- import axios3 from "axios";
828
- import { v4 as uuidv4 } from "uuid";
829
-
830
- // src/core/cache.ts
831
- var CacheManager = class {
832
- constructor() {
833
- __publicField(this, "cache", /* @__PURE__ */ new Map());
834
- __publicField(this, "defaultDuration", 15 * 60 * 1e3);
835
- }
836
- // 15 minutes
837
- set(key, data, duration) {
838
- this.cache.set(key, {
839
- data,
840
- timestamp: Date.now(),
841
- duration: duration || this.defaultDuration
842
- });
843
- }
844
- get(key) {
845
- const item = this.cache.get(key);
846
- if (!item) return null;
847
- const isExpired = Date.now() - item.timestamp > item.duration;
848
- if (isExpired) {
849
- this.cache.delete(key);
850
- return null;
851
- }
852
- return item.data;
853
- }
854
- /**
855
- * [FIX] تم تحويلها إلى دالة عامة (generic) لتعيد النوع الصحيح.
856
- * الآن بدلًا من إرجاع CacheItem<unknown>، ستُرجع CacheItem<T>.
857
- */
858
- getWithMeta(key) {
859
- const item = this.cache.get(key);
860
- if (!item) return null;
861
- const isExpired = Date.now() - item.timestamp > item.duration;
862
- if (isExpired) {
863
- this.cache.delete(key);
864
- return null;
865
- }
866
- return item;
867
- }
868
- delete(key) {
869
- this.cache.delete(key);
870
- }
871
- clear() {
872
- this.cache.clear();
873
- }
874
- invalidateByPrefix(prefix) {
875
- const keysToDelete = [];
876
- for (const key of this.cache.keys()) {
877
- if (key.startsWith(prefix)) {
878
- keysToDelete.push(key);
879
- }
880
- }
881
- keysToDelete.forEach((key) => this.cache.delete(key));
882
- console.log(`Invalidated ${keysToDelete.length} cache entries with prefix: ${prefix}`);
883
- }
884
- };
885
- var cacheManager = new CacheManager();
886
-
887
- // src/core/cacheKey.ts
888
- var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
889
- const params = { path: callOptions.pathParams, body: input };
890
- try {
891
- return `${moduleName}/${actionName}::${JSON.stringify(params)}`;
892
- } catch (error) {
893
- console.warn("Could not stringify cache key params, falling back to timestamp.", { moduleName, actionName, error });
894
- return `${moduleName}/${actionName}::${Date.now()}`;
895
- }
896
- };
897
836
  export {
898
837
  ApiModuleProvider,
899
- generateCacheKey,
900
- globalStateManager,
901
838
  useApi,
902
839
  useApiModule,
903
840
  useApiRecord,
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { d as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, e as ActionOptions, R as RequestConfig, Q as QueryOptions, f as UseApiQuery, g as ApiError, L as LogLevel } from './apiModule.types-Cvp9QdAc.cjs';
3
- export { k as ActionConfig, n as ActionState, l as ActionStateModule, a as ApiModuleConfig, E as ExecutableAction, o as ExecuteOptions, I as InputOf, i as Middleware, M as MiddlewareContext, p as ModuleActions, q as ModuleStates, O as OutputOf, P as PaginationMeta, j as RefreshTokenConfig, h as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, m as UseApiState, V as ValidationError } from './apiModule.types-Cvp9QdAc.cjs';
4
- export { d as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, c as UseApiRecordState, b as generateCacheKey, g as globalStateManager } from './cacheKey-BNQ1ii6y.cjs';
2
+ import { d as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, e as ActionOptions, R as RequestConfig, f as ActionStateModule, Q as QueryOptions, g as UseApiQuery, h as ApiError, L as LogLevel } from './apiModule.types-BTtRM9wO.cjs';
3
+ export { l as ActionConfig, n as ActionState, a as ApiModuleConfig, E as ExecutableAction, o as ExecuteOptions, I as InputOf, j as Middleware, M as MiddlewareContext, p as ModuleActions, q as ModuleStates, O as OutputOf, P as PaginationMeta, k as RefreshTokenConfig, i as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, m as UseApiState, V as ValidationError } from './apiModule.types-BTtRM9wO.cjs';
4
+ export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-CBP3Ufvu.cjs';
5
5
  import 'react';
6
6
 
7
7
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
@@ -72,6 +72,43 @@ declare function createApiActions<TActions extends Record<string, {
72
72
  [K in keyof TActions]: ApiAction<TActions[K]['requestType'], TActions[K]['responseType']>;
73
73
  };
74
74
 
75
+ declare class GlobalStateManager {
76
+ private store;
77
+ getSnapshot<T>(key: string): ActionStateModule<T>;
78
+ /**
79
+ * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
80
+ * @returns دالة لإلغاء الاشتراك.
81
+ */
82
+ subscribe(key: string, callback: () => void): () => void;
83
+ /**
84
+ * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
85
+ */
86
+ setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
87
+ /**
88
+ * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
89
+ */
90
+ invalidate(key: string): void;
91
+ /**
92
+ * [نسخة محدثة وأكثر قوة]
93
+ * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
94
+ * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
95
+ */
96
+ invalidateByPrefix(prefix: string): void;
97
+ /**
98
+ * Serializes the current state of the query store into a JSON string.
99
+ * This is used on the server to pass the initial state to the client.
100
+ * @returns A JSON string representing the dehydrated state.
101
+ */
102
+ dehydrate(): string;
103
+ /**
104
+ * Merges a dehydrated state object into the current store.
105
+ * This is used on the client to hydrate the state received from the server.
106
+ * @param hydratedState - A JSON string from the `dehydrate` method.
107
+ */
108
+ rehydrate(hydratedState: string): void;
109
+ }
110
+ declare const globalStateManager: GlobalStateManager;
111
+
75
112
  /**
76
113
  * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
77
114
  * يدعم الآن الفلاتر المتداخلة (filter[key]=value) والترتيب المتعدد.
@@ -107,6 +144,19 @@ declare class CacheManager {
107
144
  }
108
145
  declare const cacheManager: CacheManager;
109
146
 
147
+ /**
148
+ * يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
149
+ * هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
150
+ * @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
151
+ * @param actionName - اسم الإجراء (مثل 'list', 'create').
152
+ * @param input - بيانات الطلب (body/query params).
153
+ * @param callOptions - خيارات إضافية مثل `pathParams`.
154
+ * @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
155
+ */
156
+ declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
157
+ pathParams?: Record<string, any>;
158
+ }) => string;
159
+
110
160
  /**
111
161
  * @file src/hooks/useApi.types.ts
112
162
  * @description This file defines the professional, publicly-facing types for the `useApi` hook,
@@ -188,4 +238,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
188
238
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
189
239
  }
190
240
 
191
- export { ActionConfigModule, ActionOptions, ApiClientConfig, ApiError, type ApiResourceStatus, LogLevel, QueryOptions, RequestConfig, StandardResponse, type UseApiActions, UseApiQuery, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, processResponse };
241
+ export { ActionConfigModule, ActionOptions, ActionStateModule, ApiClientConfig, ApiError, type ApiResourceStatus, LogLevel, QueryOptions, RequestConfig, StandardResponse, type UseApiActions, UseApiQuery, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, generateCacheKey, globalStateManager, processResponse };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { d as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, e as ActionOptions, R as RequestConfig, Q as QueryOptions, f as UseApiQuery, g as ApiError, L as LogLevel } from './apiModule.types-Cvp9QdAc.js';
3
- export { k as ActionConfig, n as ActionState, l as ActionStateModule, a as ApiModuleConfig, E as ExecutableAction, o as ExecuteOptions, I as InputOf, i as Middleware, M as MiddlewareContext, p as ModuleActions, q as ModuleStates, O as OutputOf, P as PaginationMeta, j as RefreshTokenConfig, h as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, m as UseApiState, V as ValidationError } from './apiModule.types-Cvp9QdAc.js';
4
- export { d as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, c as UseApiRecordState, b as generateCacheKey, g as globalStateManager } from './cacheKey-BJQaehcQ.js';
2
+ import { d as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, e as ActionOptions, R as RequestConfig, f as ActionStateModule, Q as QueryOptions, g as UseApiQuery, h as ApiError, L as LogLevel } from './apiModule.types-BTtRM9wO.js';
3
+ export { l as ActionConfig, n as ActionState, a as ApiModuleConfig, E as ExecutableAction, o as ExecuteOptions, I as InputOf, j as Middleware, M as MiddlewareContext, p as ModuleActions, q as ModuleStates, O as OutputOf, P as PaginationMeta, k as RefreshTokenConfig, i as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, m as UseApiState, V as ValidationError } from './apiModule.types-BTtRM9wO.js';
4
+ export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-BsOSJZ5l.js';
5
5
  import 'react';
6
6
 
7
7
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
@@ -72,6 +72,43 @@ declare function createApiActions<TActions extends Record<string, {
72
72
  [K in keyof TActions]: ApiAction<TActions[K]['requestType'], TActions[K]['responseType']>;
73
73
  };
74
74
 
75
+ declare class GlobalStateManager {
76
+ private store;
77
+ getSnapshot<T>(key: string): ActionStateModule<T>;
78
+ /**
79
+ * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
80
+ * @returns دالة لإلغاء الاشتراك.
81
+ */
82
+ subscribe(key: string, callback: () => void): () => void;
83
+ /**
84
+ * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
85
+ */
86
+ setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
87
+ /**
88
+ * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
89
+ */
90
+ invalidate(key: string): void;
91
+ /**
92
+ * [نسخة محدثة وأكثر قوة]
93
+ * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
94
+ * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
95
+ */
96
+ invalidateByPrefix(prefix: string): void;
97
+ /**
98
+ * Serializes the current state of the query store into a JSON string.
99
+ * This is used on the server to pass the initial state to the client.
100
+ * @returns A JSON string representing the dehydrated state.
101
+ */
102
+ dehydrate(): string;
103
+ /**
104
+ * Merges a dehydrated state object into the current store.
105
+ * This is used on the client to hydrate the state received from the server.
106
+ * @param hydratedState - A JSON string from the `dehydrate` method.
107
+ */
108
+ rehydrate(hydratedState: string): void;
109
+ }
110
+ declare const globalStateManager: GlobalStateManager;
111
+
75
112
  /**
76
113
  * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
77
114
  * يدعم الآن الفلاتر المتداخلة (filter[key]=value) والترتيب المتعدد.
@@ -107,6 +144,19 @@ declare class CacheManager {
107
144
  }
108
145
  declare const cacheManager: CacheManager;
109
146
 
147
+ /**
148
+ * يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
149
+ * هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
150
+ * @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
151
+ * @param actionName - اسم الإجراء (مثل 'list', 'create').
152
+ * @param input - بيانات الطلب (body/query params).
153
+ * @param callOptions - خيارات إضافية مثل `pathParams`.
154
+ * @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
155
+ */
156
+ declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
157
+ pathParams?: Record<string, any>;
158
+ }) => string;
159
+
110
160
  /**
111
161
  * @file src/hooks/useApi.types.ts
112
162
  * @description This file defines the professional, publicly-facing types for the `useApi` hook,
@@ -188,4 +238,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
188
238
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
189
239
  }
190
240
 
191
- export { ActionConfigModule, ActionOptions, ApiClientConfig, ApiError, type ApiResourceStatus, LogLevel, QueryOptions, RequestConfig, StandardResponse, type UseApiActions, UseApiQuery, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, processResponse };
241
+ export { ActionConfigModule, ActionOptions, ActionStateModule, ApiClientConfig, ApiError, type ApiResourceStatus, LogLevel, QueryOptions, RequestConfig, StandardResponse, type UseApiActions, UseApiQuery, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, generateCacheKey, globalStateManager, processResponse };
package/dist/server.cjs CHANGED
@@ -286,82 +286,6 @@ var GlobalStateManager = class {
286
286
  };
287
287
  var globalStateManager = new GlobalStateManager();
288
288
 
289
- // src/hooks/useApi.ts
290
- var import_react = require("react");
291
-
292
- // src/hooks/useApiRecord/index.ts
293
- var import_react2 = require("react");
294
-
295
- // src/hooks/useDeepCompareEffect/index.ts
296
- var import_react3 = require("react");
297
- var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
298
-
299
- // src/hooks/useApiModule/useApiModule.ts
300
- var import_react4 = require("react");
301
- var ApiModuleContext = (0, import_react4.createContext)(null);
302
- var ApiModuleProvider = ApiModuleContext.Provider;
303
-
304
- // src/core/client.ts
305
- var import_axios3 = __toESM(require("axios"), 1);
306
- var import_uuid = require("uuid");
307
-
308
- // src/core/cache.ts
309
- var CacheManager = class {
310
- constructor() {
311
- __publicField(this, "cache", /* @__PURE__ */ new Map());
312
- __publicField(this, "defaultDuration", 15 * 60 * 1e3);
313
- }
314
- // 15 minutes
315
- set(key, data, duration) {
316
- this.cache.set(key, {
317
- data,
318
- timestamp: Date.now(),
319
- duration: duration || this.defaultDuration
320
- });
321
- }
322
- get(key) {
323
- const item = this.cache.get(key);
324
- if (!item) return null;
325
- const isExpired = Date.now() - item.timestamp > item.duration;
326
- if (isExpired) {
327
- this.cache.delete(key);
328
- return null;
329
- }
330
- return item.data;
331
- }
332
- /**
333
- * [FIX] تم تحويلها إلى دالة عامة (generic) لتعيد النوع الصحيح.
334
- * الآن بدلًا من إرجاع CacheItem<unknown>، ستُرجع CacheItem<T>.
335
- */
336
- getWithMeta(key) {
337
- const item = this.cache.get(key);
338
- if (!item) return null;
339
- const isExpired = Date.now() - item.timestamp > item.duration;
340
- if (isExpired) {
341
- this.cache.delete(key);
342
- return null;
343
- }
344
- return item;
345
- }
346
- delete(key) {
347
- this.cache.delete(key);
348
- }
349
- clear() {
350
- this.cache.clear();
351
- }
352
- invalidateByPrefix(prefix) {
353
- const keysToDelete = [];
354
- for (const key of this.cache.keys()) {
355
- if (key.startsWith(prefix)) {
356
- keysToDelete.push(key);
357
- }
358
- }
359
- keysToDelete.forEach((key) => this.cache.delete(key));
360
- console.log(`Invalidated ${keysToDelete.length} cache entries with prefix: ${prefix}`);
361
- }
362
- };
363
- var cacheManager = new CacheManager();
364
-
365
289
  // src/core/cacheKey.ts
366
290
  var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
367
291
  const params = { path: callOptions.pathParams, body: input };
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-Cvp9QdAc.cjs';
2
+ import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-BTtRM9wO.cjs';
3
3
  import 'react';
4
4
 
5
5
  /**
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-Cvp9QdAc.js';
2
+ import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-BTtRM9wO.js';
3
3
  import 'react';
4
4
 
5
5
  /**
package/dist/server.js CHANGED
@@ -252,82 +252,6 @@ var GlobalStateManager = class {
252
252
  };
253
253
  var globalStateManager = new GlobalStateManager();
254
254
 
255
- // src/hooks/useApi.ts
256
- import { useState, useEffect, useCallback, useRef, useMemo } from "react";
257
-
258
- // src/hooks/useApiRecord/index.ts
259
- import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2, useRef as useRef2, useMemo as useMemo2 } from "react";
260
-
261
- // src/hooks/useDeepCompareEffect/index.ts
262
- import { useEffect as useEffect3, useRef as useRef3 } from "react";
263
- import isEqual from "fast-deep-equal";
264
-
265
- // src/hooks/useApiModule/useApiModule.ts
266
- import { createContext, useContext, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef4, useState as useState3, useSyncExternalStore } from "react";
267
- var ApiModuleContext = createContext(null);
268
- var ApiModuleProvider = ApiModuleContext.Provider;
269
-
270
- // src/core/client.ts
271
- import axios3 from "axios";
272
- import { v4 as uuidv4 } from "uuid";
273
-
274
- // src/core/cache.ts
275
- var CacheManager = class {
276
- constructor() {
277
- __publicField(this, "cache", /* @__PURE__ */ new Map());
278
- __publicField(this, "defaultDuration", 15 * 60 * 1e3);
279
- }
280
- // 15 minutes
281
- set(key, data, duration) {
282
- this.cache.set(key, {
283
- data,
284
- timestamp: Date.now(),
285
- duration: duration || this.defaultDuration
286
- });
287
- }
288
- get(key) {
289
- const item = this.cache.get(key);
290
- if (!item) return null;
291
- const isExpired = Date.now() - item.timestamp > item.duration;
292
- if (isExpired) {
293
- this.cache.delete(key);
294
- return null;
295
- }
296
- return item.data;
297
- }
298
- /**
299
- * [FIX] تم تحويلها إلى دالة عامة (generic) لتعيد النوع الصحيح.
300
- * الآن بدلًا من إرجاع CacheItem<unknown>، ستُرجع CacheItem<T>.
301
- */
302
- getWithMeta(key) {
303
- const item = this.cache.get(key);
304
- if (!item) return null;
305
- const isExpired = Date.now() - item.timestamp > item.duration;
306
- if (isExpired) {
307
- this.cache.delete(key);
308
- return null;
309
- }
310
- return item;
311
- }
312
- delete(key) {
313
- this.cache.delete(key);
314
- }
315
- clear() {
316
- this.cache.clear();
317
- }
318
- invalidateByPrefix(prefix) {
319
- const keysToDelete = [];
320
- for (const key of this.cache.keys()) {
321
- if (key.startsWith(prefix)) {
322
- keysToDelete.push(key);
323
- }
324
- }
325
- keysToDelete.forEach((key) => this.cache.delete(key));
326
- console.log(`Invalidated ${keysToDelete.length} cache entries with prefix: ${prefix}`);
327
- }
328
- };
329
- var cacheManager = new CacheManager();
330
-
331
255
  // src/core/cacheKey.ts
332
256
  var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
333
257
  const params = { path: callOptions.pathParams, body: input };
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- import { R as RequestConfig, g as ApiError, S as StandardResponse, e as ActionOptions, l as ActionStateModule } from './apiModule.types-Cvp9QdAc.js';
2
+ import { R as RequestConfig, h as ApiError, S as StandardResponse, e as ActionOptions } from './apiModule.types-BTtRM9wO.js';
3
3
 
4
4
  /**
5
5
  * Represents the internal state of the `useApiRecord` hook.
@@ -87,54 +87,4 @@ interface UseApiRecordReturn<T> {
87
87
  setState: Dispatch<SetStateAction<UseApiRecordState<T>>>;
88
88
  }
89
89
 
90
- declare class GlobalStateManager {
91
- private store;
92
- getSnapshot<T>(key: string): ActionStateModule<T>;
93
- /**
94
- * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
95
- * @returns دالة لإلغاء الاشتراك.
96
- */
97
- subscribe(key: string, callback: () => void): () => void;
98
- /**
99
- * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
100
- */
101
- setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
102
- /**
103
- * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
104
- */
105
- invalidate(key: string): void;
106
- /**
107
- * [نسخة محدثة وأكثر قوة]
108
- * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
109
- * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
110
- */
111
- invalidateByPrefix(prefix: string): void;
112
- /**
113
- * Serializes the current state of the query store into a JSON string.
114
- * This is used on the server to pass the initial state to the client.
115
- * @returns A JSON string representing the dehydrated state.
116
- */
117
- dehydrate(): string;
118
- /**
119
- * Merges a dehydrated state object into the current store.
120
- * This is used on the client to hydrate the state received from the server.
121
- * @param hydratedState - A JSON string from the `dehydrate` method.
122
- */
123
- rehydrate(hydratedState: string): void;
124
- }
125
- declare const globalStateManager: GlobalStateManager;
126
-
127
- /**
128
- * يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
129
- * هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
130
- * @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
131
- * @param actionName - اسم الإجراء (مثل 'list', 'create').
132
- * @param input - بيانات الطلب (body/query params).
133
- * @param callOptions - خيارات إضافية مثل `pathParams`.
134
- * @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
135
- */
136
- declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
137
- pathParams?: Record<string, any>;
138
- }) => string;
139
-
140
- export { type UseApiRecordConfig as U, type UseApiRecordReturn as a, generateCacheKey as b, type UseApiRecordState as c, type UseApiRecordActions as d, globalStateManager as g };
90
+ export type { UseApiRecordConfig as U, UseApiRecordReturn as a, UseApiRecordState as b, UseApiRecordActions as c };
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- import { R as RequestConfig, g as ApiError, S as StandardResponse, e as ActionOptions, l as ActionStateModule } from './apiModule.types-Cvp9QdAc.cjs';
2
+ import { R as RequestConfig, h as ApiError, S as StandardResponse, e as ActionOptions } from './apiModule.types-BTtRM9wO.cjs';
3
3
 
4
4
  /**
5
5
  * Represents the internal state of the `useApiRecord` hook.
@@ -87,54 +87,4 @@ interface UseApiRecordReturn<T> {
87
87
  setState: Dispatch<SetStateAction<UseApiRecordState<T>>>;
88
88
  }
89
89
 
90
- declare class GlobalStateManager {
91
- private store;
92
- getSnapshot<T>(key: string): ActionStateModule<T>;
93
- /**
94
- * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
95
- * @returns دالة لإلغاء الاشتراك.
96
- */
97
- subscribe(key: string, callback: () => void): () => void;
98
- /**
99
- * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
100
- */
101
- setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
102
- /**
103
- * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
104
- */
105
- invalidate(key: string): void;
106
- /**
107
- * [نسخة محدثة وأكثر قوة]
108
- * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
109
- * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
110
- */
111
- invalidateByPrefix(prefix: string): void;
112
- /**
113
- * Serializes the current state of the query store into a JSON string.
114
- * This is used on the server to pass the initial state to the client.
115
- * @returns A JSON string representing the dehydrated state.
116
- */
117
- dehydrate(): string;
118
- /**
119
- * Merges a dehydrated state object into the current store.
120
- * This is used on the client to hydrate the state received from the server.
121
- * @param hydratedState - A JSON string from the `dehydrate` method.
122
- */
123
- rehydrate(hydratedState: string): void;
124
- }
125
- declare const globalStateManager: GlobalStateManager;
126
-
127
- /**
128
- * يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
129
- * هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
130
- * @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
131
- * @param actionName - اسم الإجراء (مثل 'list', 'create').
132
- * @param input - بيانات الطلب (body/query params).
133
- * @param callOptions - خيارات إضافية مثل `pathParams`.
134
- * @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
135
- */
136
- declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
137
- pathParams?: Record<string, any>;
138
- }) => string;
139
-
140
- export { type UseApiRecordConfig as U, type UseApiRecordReturn as a, generateCacheKey as b, type UseApiRecordState as c, type UseApiRecordActions as d, globalStateManager as g };
90
+ export type { UseApiRecordConfig as U, UseApiRecordReturn as a, UseApiRecordState as b, UseApiRecordActions as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.14",
3
+ "version": "12.0.15",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6