api-core-lib 12.9.4 → 12.11.4

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/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method, AxiosError } from 'axios';
2
- import React$1, { Dispatch, SetStateAction } from 'react';
2
+ import * as React$1 from 'react';
3
+ import React__default, { Dispatch, SetStateAction } from 'react';
3
4
 
4
5
  /**
5
6
  * يمثل معلومات الترقيم (Pagination) التي قد تعود من ה-API.
@@ -120,22 +121,11 @@ interface ActionConfig<TInput = any, TOutput = any> {
120
121
  isList?: boolean;
121
122
  invalidates?: string[];
122
123
  }
123
- /**
124
- * خيارات الإعداد لهوك useApiModule.
125
- */
126
- interface UseApiModuleOptions {
127
- onSuccess?: (actionName: string, message: string, data: any) => void;
128
- onError?: (actionName: string, message: string, error?: ApiError | null) => void;
129
- staleTime?: number;
130
- cacheTime?: number;
131
- refetchOnWindowFocus?: boolean;
132
- pathParams?: Record<string, any>;
133
- }
134
124
  /**
135
125
  * [مُحدَّث] يمثل الحالة التفاعلية الكاملة لإجراء واحد.
136
126
  * هذا هو النوع الذي يتم إرجاعه في `states` من الهوك.
137
127
  */
138
- interface ActionState<TOutput> {
128
+ interface ActionStateModule<TOutput> {
139
129
  data: TOutput | null;
140
130
  links?: Record<string, string | null>;
141
131
  meta?: PaginationMeta | Record<string, any>;
@@ -146,12 +136,14 @@ interface ActionState<TOutput> {
146
136
  message?: string;
147
137
  validationErrors?: ValidationError[];
148
138
  rawResponse: any | null;
139
+ isStale?: boolean;
140
+ lastSuccessAt?: number;
149
141
  }
150
142
  /**
151
143
  * الكائن الموحد الذي يتم إرجاعه لكل إجراء، ويحتوي على حالته ومنفذه وأدوات التحكم.
152
144
  */
153
145
  interface ExecutableAction<TInput, TOutput> {
154
- state: ActionState<TOutput>;
146
+ state: ActionStateModule<TOutput>;
155
147
  execute: (input?: TInput, options?: {
156
148
  pathParams?: Record<string, any>;
157
149
  config?: AxiosRequestConfig;
@@ -160,18 +152,12 @@ interface ExecutableAction<TInput, TOutput> {
160
152
  reset: () => void;
161
153
  query?: UseApiQuery;
162
154
  }
163
- /**
164
- * النوع النهائي الذي يعيده هوك useApiModule.
165
- */
166
- type ModuleActions<TModule extends ApiModuleConfig> = {
167
- [K in keyof TModule['actions']]: TModule['actions'][K] extends ActionConfig<infer TInput, infer TOutput> ? ExecutableAction<TInput, TOutput> : never;
168
- };
169
155
  type UseApiState<T> = StandardResponse<T>;
170
156
  interface UseApiQuery {
171
157
  /** The current query options state. */
172
158
  options: QueryOptions;
173
159
  /** A function to set the entire query options object at once. */
174
- setOptions: React$1.Dispatch<React$1.SetStateAction<QueryOptions>>;
160
+ setOptions: React__default.Dispatch<React__default.SetStateAction<QueryOptions>>;
175
161
  /** Sets the current page number. */
176
162
  setPage: (page: number) => void;
177
163
  /** Sets the number of items per page and resets to the first page. */
@@ -202,19 +188,72 @@ interface UseApiConfig<T> {
202
188
  onSuccess?: (message: string, data?: T) => void;
203
189
  onError?: (message: string, error?: ApiError) => void;
204
190
  }
205
- interface ActionConfigModule<TInput = any, TOutput = any> {
191
+
192
+ declare function createApiClient(config: ApiClientConfig): AxiosInstance;
193
+
194
+ /** @description Extends the base ActionState with an `isStale` flag for automatic refetching. */
195
+ interface ActionState<TOutput> extends ActionStateModule<TOutput> {
196
+ isStale?: boolean;
197
+ }
198
+ /** @description Defines the configuration for a single API action within a module. */
199
+ interface ActionConfigModule<TInput = unknown, TOutput = unknown> {
206
200
  method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
207
201
  path: string;
208
202
  description?: string;
209
- isList?: boolean;
203
+ hasQuery?: boolean;
204
+ autoFetch?: boolean;
210
205
  invalidates?: string[];
206
+ _input?: TInput;
207
+ _output?: TOutput;
211
208
  }
212
- interface ApiModuleConfig {
209
+ /** @description Defines the complete structure of an API module. */
210
+ interface ApiModuleConfig<TActions extends Record<string, ActionConfigModule<any, any>>> {
213
211
  baseEndpoint: string;
214
- actions: Record<string, ActionConfigModule<any, any>>;
212
+ actions: TActions;
213
+ }
214
+ /** @description Configuration options passed directly to the `useApiModule` hook. */
215
+ interface UseApiModuleOptions {
216
+ onSuccess?: (actionName: string, message: string, data: unknown) => void;
217
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
218
+ refetchOnWindowFocus?: boolean;
219
+ pathParams?: Record<string, any>;
220
+ enabled?: boolean;
221
+ }
222
+ /** A utility type to infer the Input type (`TInput`) from an ActionConfigModule. */
223
+ type InputOf<TActionConfig> = TActionConfig extends ActionConfigModule<infer TInput, any> ? TInput : never;
224
+ /** A utility type to infer the Output type (`TOutput`) from an ActionConfigModule. */
225
+ type OutputOf<TActionConfig> = TActionConfig extends ActionConfigModule<any, infer TOutput> ? TOutput : never;
226
+ /** @description Defines the options for the `execute` function, enabling optimistic updates. */
227
+ interface ExecuteOptions<TInput, TOutput, TContext = unknown> {
228
+ pathParams?: Record<string, any>;
229
+ config?: AxiosRequestConfig;
230
+ onMutate?: (variables: TInput) => TContext | Promise<TContext>;
231
+ onSuccess?: (data: TOutput, context?: TContext) => void;
232
+ onError?: (error: ApiError, context?: TContext) => void;
233
+ }
234
+ /** @description A fully-typed object representing the callable actions for a module. */
235
+ type ModuleActions<TActions extends Record<string, ActionConfigModule<any, any>>> = {
236
+ [K in keyof TActions]: {
237
+ execute: <TContext = unknown>(input?: InputOf<TActions[K]>, options?: ExecuteOptions<InputOf<TActions[K]>, OutputOf<TActions[K]>, TContext>) => Promise<StandardResponse<OutputOf<TActions[K]>>>;
238
+ reset: (input?: InputOf<TActions[K]>, options?: {
239
+ pathParams?: Record<string, any>;
240
+ }) => void;
241
+ };
242
+ };
243
+ /** @description A fully-typed object representing the reactive states for each action in a module. */
244
+ type ModuleStates<TActions extends Record<string, ActionConfigModule<any, any>>> = {
245
+ [K in keyof TActions]: ActionState<OutputOf<TActions[K]>>;
246
+ };
247
+ /** @description The complete, fully-typed return object of the `useApiModule` hook. */
248
+ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<any, any>>> {
249
+ states: ModuleStates<TActions>;
250
+ actions: ModuleActions<TActions>;
251
+ queries: {
252
+ [K in keyof TActions]?: TActions[K] extends {
253
+ hasQuery: true;
254
+ } ? UseApiQuery : never;
255
+ };
215
256
  }
216
-
217
- declare function createApiClient(config: ApiClientConfig): AxiosInstance;
218
257
 
219
258
  /**
220
259
  * A factory function to create a reusable set of API services for a specific endpoint.
@@ -231,6 +270,22 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
231
270
  bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
232
271
  upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
233
272
  };
273
+ /**
274
+ * [نسخة محدثة ومحسّنة]
275
+ * دالة عامة وصريحة لتنفيذ أي طلب API.
276
+ * تستقبل وسائط منظمة بدلاً من محاولة تخمينها.
277
+ *
278
+ * @param axiosInstance - نسخة Axios.
279
+ * @param baseEndpoint - نقطة النهاية الأساسية للموديول.
280
+ * @param actionConfig - إعدادات الإجراء المحدد.
281
+ * @param params - كائن يحتوي على جميع البارامترات اللازمة للطلب.
282
+ * @returns Promise<StandardResponse<any>>
283
+ */
284
+ declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
285
+ pathParams?: Record<string, string | number>;
286
+ body?: any;
287
+ config?: AxiosRequestConfig;
288
+ }): Promise<StandardResponse<any>>;
234
289
 
235
290
  /**
236
291
  * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
@@ -303,8 +358,6 @@ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | AxiosEr
303
358
 
304
359
  declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
305
360
 
306
- declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions): any;
307
-
308
361
  /**
309
362
  * Represents the internal state of the `useApiRecord` hook.
310
363
  * It mirrors the `StandardResponse` structure, which is the unified response format
@@ -407,6 +460,38 @@ type EffectCallback = () => (void | (() => void));
407
460
  type DependencyList = readonly any[];
408
461
  declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): void;
409
462
 
463
+ declare const ApiModuleProvider: React$1.Provider<UseApiModuleReturn<any> | null>;
464
+ declare function useModuleContext<TActions extends Record<string, ActionConfigModule<any, any>>>(): UseApiModuleReturn<TActions>;
465
+ declare function useApiModule<TActions extends Record<string, ActionConfigModule<any, any>>>(axiosInstance: AxiosInstance, moduleConfig: ApiModuleConfig<TActions>, options?: UseApiModuleOptions): UseApiModuleReturn<TActions>;
466
+
467
+ declare class GlobalStateManager {
468
+ private store;
469
+ /**
470
+ * يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
471
+ */
472
+ getSnapshot<T>(key: string): ActionStateModule<T>;
473
+ /**
474
+ * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
475
+ * @returns دالة لإلغاء الاشتراك.
476
+ */
477
+ subscribe(key: string, callback: () => void): () => void;
478
+ /**
479
+ * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
480
+ */
481
+ setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
482
+ /**
483
+ * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
484
+ */
485
+ invalidate(key: string): void;
486
+ /**
487
+ * [نسخة محدثة وأكثر قوة]
488
+ * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
489
+ * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
490
+ */
491
+ invalidateByPrefix(prefix: string): void;
492
+ }
493
+ declare const globalStateManager: GlobalStateManager;
494
+
410
495
  /**
411
496
  * @file src/hooks/useApi.types.ts
412
497
  * @description This file defines the professional, publicly-facing types for the `useApi` hook,
@@ -436,8 +521,8 @@ interface UseApiActions<T, TListItem = T extends (infer U)[] ? U : T> {
436
521
  * @template T The type of the data entity being managed.
437
522
  */
438
523
  interface UseApiReturn<T> {
439
- state: UseApiState<T>;
440
- setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
524
+ state: StandardResponse<T>;
525
+ setState: React.Dispatch<React.SetStateAction<StandardResponse<T>>>;
441
526
  actions: UseApiActions<T>;
442
527
  query: UseApiQuery;
443
528
  }
@@ -488,4 +573,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
488
573
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
489
574
  }
490
575
 
491
- export { type ActionConfig, type ActionConfigModule, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ExecutableAction, type LogLevel, type Middleware, type MiddlewareContext, type ModuleActions, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiActions, type UseApiConfig, type UseApiModuleOptions, type UseApiQuery, type UseApiRecordActions, type UseApiRecordConfig, type UseApiRecordReturn, type UseApiRecordState, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule, useApiRecord, useDeepCompareEffect };
576
+ export { type ActionConfig, type ActionConfigModule, type ActionOptions, type ActionState, type ActionStateModule, type ApiClientConfig, type ApiError, type ApiModuleConfig, ApiModuleProvider, type ApiResourceStatus, type ExecutableAction, type ExecuteOptions, type InputOf, type LogLevel, type Middleware, type MiddlewareContext, type ModuleActions, type ModuleStates, type OutputOf, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiActions, type UseApiConfig, type UseApiModuleOptions, type UseApiModuleReturn, type UseApiQuery, type UseApiRecordActions, type UseApiRecordConfig, type UseApiRecordReturn, type UseApiRecordState, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, globalStateManager, processResponse, useApi, useApiModule, useApiRecord, useDeepCompareEffect, useModuleContext };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method, AxiosError } from 'axios';
2
- import React$1, { Dispatch, SetStateAction } from 'react';
2
+ import * as React$1 from 'react';
3
+ import React__default, { Dispatch, SetStateAction } from 'react';
3
4
 
4
5
  /**
5
6
  * يمثل معلومات الترقيم (Pagination) التي قد تعود من ה-API.
@@ -120,22 +121,11 @@ interface ActionConfig<TInput = any, TOutput = any> {
120
121
  isList?: boolean;
121
122
  invalidates?: string[];
122
123
  }
123
- /**
124
- * خيارات الإعداد لهوك useApiModule.
125
- */
126
- interface UseApiModuleOptions {
127
- onSuccess?: (actionName: string, message: string, data: any) => void;
128
- onError?: (actionName: string, message: string, error?: ApiError | null) => void;
129
- staleTime?: number;
130
- cacheTime?: number;
131
- refetchOnWindowFocus?: boolean;
132
- pathParams?: Record<string, any>;
133
- }
134
124
  /**
135
125
  * [مُحدَّث] يمثل الحالة التفاعلية الكاملة لإجراء واحد.
136
126
  * هذا هو النوع الذي يتم إرجاعه في `states` من الهوك.
137
127
  */
138
- interface ActionState<TOutput> {
128
+ interface ActionStateModule<TOutput> {
139
129
  data: TOutput | null;
140
130
  links?: Record<string, string | null>;
141
131
  meta?: PaginationMeta | Record<string, any>;
@@ -146,12 +136,14 @@ interface ActionState<TOutput> {
146
136
  message?: string;
147
137
  validationErrors?: ValidationError[];
148
138
  rawResponse: any | null;
139
+ isStale?: boolean;
140
+ lastSuccessAt?: number;
149
141
  }
150
142
  /**
151
143
  * الكائن الموحد الذي يتم إرجاعه لكل إجراء، ويحتوي على حالته ومنفذه وأدوات التحكم.
152
144
  */
153
145
  interface ExecutableAction<TInput, TOutput> {
154
- state: ActionState<TOutput>;
146
+ state: ActionStateModule<TOutput>;
155
147
  execute: (input?: TInput, options?: {
156
148
  pathParams?: Record<string, any>;
157
149
  config?: AxiosRequestConfig;
@@ -160,18 +152,12 @@ interface ExecutableAction<TInput, TOutput> {
160
152
  reset: () => void;
161
153
  query?: UseApiQuery;
162
154
  }
163
- /**
164
- * النوع النهائي الذي يعيده هوك useApiModule.
165
- */
166
- type ModuleActions<TModule extends ApiModuleConfig> = {
167
- [K in keyof TModule['actions']]: TModule['actions'][K] extends ActionConfig<infer TInput, infer TOutput> ? ExecutableAction<TInput, TOutput> : never;
168
- };
169
155
  type UseApiState<T> = StandardResponse<T>;
170
156
  interface UseApiQuery {
171
157
  /** The current query options state. */
172
158
  options: QueryOptions;
173
159
  /** A function to set the entire query options object at once. */
174
- setOptions: React$1.Dispatch<React$1.SetStateAction<QueryOptions>>;
160
+ setOptions: React__default.Dispatch<React__default.SetStateAction<QueryOptions>>;
175
161
  /** Sets the current page number. */
176
162
  setPage: (page: number) => void;
177
163
  /** Sets the number of items per page and resets to the first page. */
@@ -202,19 +188,72 @@ interface UseApiConfig<T> {
202
188
  onSuccess?: (message: string, data?: T) => void;
203
189
  onError?: (message: string, error?: ApiError) => void;
204
190
  }
205
- interface ActionConfigModule<TInput = any, TOutput = any> {
191
+
192
+ declare function createApiClient(config: ApiClientConfig): AxiosInstance;
193
+
194
+ /** @description Extends the base ActionState with an `isStale` flag for automatic refetching. */
195
+ interface ActionState<TOutput> extends ActionStateModule<TOutput> {
196
+ isStale?: boolean;
197
+ }
198
+ /** @description Defines the configuration for a single API action within a module. */
199
+ interface ActionConfigModule<TInput = unknown, TOutput = unknown> {
206
200
  method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
207
201
  path: string;
208
202
  description?: string;
209
- isList?: boolean;
203
+ hasQuery?: boolean;
204
+ autoFetch?: boolean;
210
205
  invalidates?: string[];
206
+ _input?: TInput;
207
+ _output?: TOutput;
211
208
  }
212
- interface ApiModuleConfig {
209
+ /** @description Defines the complete structure of an API module. */
210
+ interface ApiModuleConfig<TActions extends Record<string, ActionConfigModule<any, any>>> {
213
211
  baseEndpoint: string;
214
- actions: Record<string, ActionConfigModule<any, any>>;
212
+ actions: TActions;
213
+ }
214
+ /** @description Configuration options passed directly to the `useApiModule` hook. */
215
+ interface UseApiModuleOptions {
216
+ onSuccess?: (actionName: string, message: string, data: unknown) => void;
217
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
218
+ refetchOnWindowFocus?: boolean;
219
+ pathParams?: Record<string, any>;
220
+ enabled?: boolean;
221
+ }
222
+ /** A utility type to infer the Input type (`TInput`) from an ActionConfigModule. */
223
+ type InputOf<TActionConfig> = TActionConfig extends ActionConfigModule<infer TInput, any> ? TInput : never;
224
+ /** A utility type to infer the Output type (`TOutput`) from an ActionConfigModule. */
225
+ type OutputOf<TActionConfig> = TActionConfig extends ActionConfigModule<any, infer TOutput> ? TOutput : never;
226
+ /** @description Defines the options for the `execute` function, enabling optimistic updates. */
227
+ interface ExecuteOptions<TInput, TOutput, TContext = unknown> {
228
+ pathParams?: Record<string, any>;
229
+ config?: AxiosRequestConfig;
230
+ onMutate?: (variables: TInput) => TContext | Promise<TContext>;
231
+ onSuccess?: (data: TOutput, context?: TContext) => void;
232
+ onError?: (error: ApiError, context?: TContext) => void;
233
+ }
234
+ /** @description A fully-typed object representing the callable actions for a module. */
235
+ type ModuleActions<TActions extends Record<string, ActionConfigModule<any, any>>> = {
236
+ [K in keyof TActions]: {
237
+ execute: <TContext = unknown>(input?: InputOf<TActions[K]>, options?: ExecuteOptions<InputOf<TActions[K]>, OutputOf<TActions[K]>, TContext>) => Promise<StandardResponse<OutputOf<TActions[K]>>>;
238
+ reset: (input?: InputOf<TActions[K]>, options?: {
239
+ pathParams?: Record<string, any>;
240
+ }) => void;
241
+ };
242
+ };
243
+ /** @description A fully-typed object representing the reactive states for each action in a module. */
244
+ type ModuleStates<TActions extends Record<string, ActionConfigModule<any, any>>> = {
245
+ [K in keyof TActions]: ActionState<OutputOf<TActions[K]>>;
246
+ };
247
+ /** @description The complete, fully-typed return object of the `useApiModule` hook. */
248
+ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<any, any>>> {
249
+ states: ModuleStates<TActions>;
250
+ actions: ModuleActions<TActions>;
251
+ queries: {
252
+ [K in keyof TActions]?: TActions[K] extends {
253
+ hasQuery: true;
254
+ } ? UseApiQuery : never;
255
+ };
215
256
  }
216
-
217
- declare function createApiClient(config: ApiClientConfig): AxiosInstance;
218
257
 
219
258
  /**
220
259
  * A factory function to create a reusable set of API services for a specific endpoint.
@@ -231,6 +270,22 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
231
270
  bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
232
271
  upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
233
272
  };
273
+ /**
274
+ * [نسخة محدثة ومحسّنة]
275
+ * دالة عامة وصريحة لتنفيذ أي طلب API.
276
+ * تستقبل وسائط منظمة بدلاً من محاولة تخمينها.
277
+ *
278
+ * @param axiosInstance - نسخة Axios.
279
+ * @param baseEndpoint - نقطة النهاية الأساسية للموديول.
280
+ * @param actionConfig - إعدادات الإجراء المحدد.
281
+ * @param params - كائن يحتوي على جميع البارامترات اللازمة للطلب.
282
+ * @returns Promise<StandardResponse<any>>
283
+ */
284
+ declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
285
+ pathParams?: Record<string, string | number>;
286
+ body?: any;
287
+ config?: AxiosRequestConfig;
288
+ }): Promise<StandardResponse<any>>;
234
289
 
235
290
  /**
236
291
  * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
@@ -303,8 +358,6 @@ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | AxiosEr
303
358
 
304
359
  declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
305
360
 
306
- declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions): any;
307
-
308
361
  /**
309
362
  * Represents the internal state of the `useApiRecord` hook.
310
363
  * It mirrors the `StandardResponse` structure, which is the unified response format
@@ -407,6 +460,38 @@ type EffectCallback = () => (void | (() => void));
407
460
  type DependencyList = readonly any[];
408
461
  declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): void;
409
462
 
463
+ declare const ApiModuleProvider: React$1.Provider<UseApiModuleReturn<any> | null>;
464
+ declare function useModuleContext<TActions extends Record<string, ActionConfigModule<any, any>>>(): UseApiModuleReturn<TActions>;
465
+ declare function useApiModule<TActions extends Record<string, ActionConfigModule<any, any>>>(axiosInstance: AxiosInstance, moduleConfig: ApiModuleConfig<TActions>, options?: UseApiModuleOptions): UseApiModuleReturn<TActions>;
466
+
467
+ declare class GlobalStateManager {
468
+ private store;
469
+ /**
470
+ * يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
471
+ */
472
+ getSnapshot<T>(key: string): ActionStateModule<T>;
473
+ /**
474
+ * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
475
+ * @returns دالة لإلغاء الاشتراك.
476
+ */
477
+ subscribe(key: string, callback: () => void): () => void;
478
+ /**
479
+ * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
480
+ */
481
+ setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
482
+ /**
483
+ * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
484
+ */
485
+ invalidate(key: string): void;
486
+ /**
487
+ * [نسخة محدثة وأكثر قوة]
488
+ * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
489
+ * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
490
+ */
491
+ invalidateByPrefix(prefix: string): void;
492
+ }
493
+ declare const globalStateManager: GlobalStateManager;
494
+
410
495
  /**
411
496
  * @file src/hooks/useApi.types.ts
412
497
  * @description This file defines the professional, publicly-facing types for the `useApi` hook,
@@ -436,8 +521,8 @@ interface UseApiActions<T, TListItem = T extends (infer U)[] ? U : T> {
436
521
  * @template T The type of the data entity being managed.
437
522
  */
438
523
  interface UseApiReturn<T> {
439
- state: UseApiState<T>;
440
- setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
524
+ state: StandardResponse<T>;
525
+ setState: React.Dispatch<React.SetStateAction<StandardResponse<T>>>;
441
526
  actions: UseApiActions<T>;
442
527
  query: UseApiQuery;
443
528
  }
@@ -488,4 +573,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
488
573
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
489
574
  }
490
575
 
491
- export { type ActionConfig, type ActionConfigModule, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ExecutableAction, type LogLevel, type Middleware, type MiddlewareContext, type ModuleActions, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiActions, type UseApiConfig, type UseApiModuleOptions, type UseApiQuery, type UseApiRecordActions, type UseApiRecordConfig, type UseApiRecordReturn, type UseApiRecordState, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule, useApiRecord, useDeepCompareEffect };
576
+ export { type ActionConfig, type ActionConfigModule, type ActionOptions, type ActionState, type ActionStateModule, type ApiClientConfig, type ApiError, type ApiModuleConfig, ApiModuleProvider, type ApiResourceStatus, type ExecutableAction, type ExecuteOptions, type InputOf, type LogLevel, type Middleware, type MiddlewareContext, type ModuleActions, type ModuleStates, type OutputOf, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiActions, type UseApiConfig, type UseApiModuleOptions, type UseApiModuleReturn, type UseApiQuery, type UseApiRecordActions, type UseApiRecordConfig, type UseApiRecordReturn, type UseApiRecordState, type UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, callDynamicApi, createApiActions, createApiClient, createApiServices, globalStateManager, processResponse, useApi, useApiModule, useApiRecord, useDeepCompareEffect, useModuleContext };