api-core-lib 12.10.4 → 12.12.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
@@ -211,14 +211,6 @@ interface ApiModuleConfig<TActions extends Record<string, ActionConfigModule<any
211
211
  baseEndpoint: string;
212
212
  actions: TActions;
213
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
214
  /** A utility type to infer the Input type (`TInput`) from an ActionConfigModule. */
223
215
  type InputOf<TActionConfig> = TActionConfig extends ActionConfigModule<infer TInput, any> ? TInput : never;
224
216
  /** A utility type to infer the Output type (`TOutput`) from an ActionConfigModule. */
@@ -244,6 +236,34 @@ type ModuleActions<TActions extends Record<string, ActionConfigModule<any, any>>
244
236
  type ModuleStates<TActions extends Record<string, ActionConfigModule<any, any>>> = {
245
237
  [K in keyof TActions]: ActionState<OutputOf<TActions[K]>>;
246
238
  };
239
+ /** @description Configuration options passed directly to the `useApiModule` hook. */
240
+ interface UseApiModuleOptions {
241
+ onSuccess?: (actionName: string, message: string, data: unknown) => void;
242
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
243
+ refetchOnWindowFocus?: boolean;
244
+ pathParams?: Record<string, any>;
245
+ enabled?: boolean;
246
+ }
247
+ /** @description Configuration options passed directly to the `useApiModule` hook. */
248
+ interface UseApiModuleOptions {
249
+ onSuccess?: (actionName: string, message: string, data: unknown) => void;
250
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
251
+ refetchOnWindowFocus?: boolean;
252
+ pathParams?: Record<string, any>;
253
+ enabled?: boolean;
254
+ /** [NEW.............] The dehydrated state string from the server to avoid re-fetching on the client. */
255
+ hydratedState?: string;
256
+ }
257
+ /** @description The complete, fully-typed return object of the `useApiModule` hook. */
258
+ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<any, any>>> {
259
+ states: ModuleStates<TActions>;
260
+ actions: ModuleActions<TActions>;
261
+ queries: {
262
+ [K in keyof TActions]?: TActions[K] extends {
263
+ hasQuery: true;
264
+ } ? UseApiQuery : never;
265
+ };
266
+ }
247
267
  /** @description The complete, fully-typed return object of the `useApiModule` hook. */
248
268
  interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<any, any>>> {
249
269
  states: ModuleStates<TActions>;
@@ -253,6 +273,8 @@ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<
253
273
  hasQuery: true;
254
274
  } ? UseApiQuery : never;
255
275
  };
276
+ /** [NEW.............] A function to serialize the current state of all queries in the hook's scope to a JSON string. */
277
+ dehydrate: () => string;
256
278
  }
257
279
 
258
280
  /**
@@ -270,6 +292,22 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
270
292
  bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
271
293
  upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
272
294
  };
295
+ /**
296
+ * [نسخة محدثة ومحسّنة]
297
+ * دالة عامة وصريحة لتنفيذ أي طلب API.
298
+ * تستقبل وسائط منظمة بدلاً من محاولة تخمينها.
299
+ *
300
+ * @param axiosInstance - نسخة Axios.
301
+ * @param baseEndpoint - نقطة النهاية الأساسية للموديول.
302
+ * @param actionConfig - إعدادات الإجراء المحدد.
303
+ * @param params - كائن يحتوي على جميع البارامترات اللازمة للطلب.
304
+ * @returns Promise<StandardResponse<any>>
305
+ */
306
+ declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
307
+ pathParams?: Record<string, string | number>;
308
+ body?: any;
309
+ config?: AxiosRequestConfig;
310
+ }): Promise<StandardResponse<any>>;
273
311
 
274
312
  /**
275
313
  * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
@@ -448,6 +486,46 @@ declare const ApiModuleProvider: React$1.Provider<UseApiModuleReturn<any> | null
448
486
  declare function useModuleContext<TActions extends Record<string, ActionConfigModule<any, any>>>(): UseApiModuleReturn<TActions>;
449
487
  declare function useApiModule<TActions extends Record<string, ActionConfigModule<any, any>>>(axiosInstance: AxiosInstance, moduleConfig: ApiModuleConfig<TActions>, options?: UseApiModuleOptions): UseApiModuleReturn<TActions>;
450
488
 
489
+ declare class GlobalStateManager {
490
+ private store;
491
+ /**
492
+ * يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
493
+ */
494
+ getSnapshot<T>(key: string): ActionStateModule<T>;
495
+ /**
496
+ * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
497
+ * @returns دالة لإلغاء الاشتراك.
498
+ */
499
+ subscribe(key: string, callback: () => void): () => void;
500
+ /**
501
+ * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
502
+ */
503
+ setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
504
+ /**
505
+ * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
506
+ */
507
+ invalidate(key: string): void;
508
+ /**
509
+ * [نسخة محدثة وأكثر قوة]
510
+ * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
511
+ * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
512
+ */
513
+ invalidateByPrefix(prefix: string): void;
514
+ /**
515
+ * Serializes the current state of the query store into a JSON string.
516
+ * This is used on the server to pass the initial state to the client.
517
+ * @returns A JSON string representing the dehydrated state.
518
+ */
519
+ dehydrate(): string;
520
+ /**
521
+ * Merges a dehydrated state object into the current store.
522
+ * This is used on the client to hydrate the state received from the server.
523
+ * @param hydratedState - A JSON string from the `dehydrate` method.
524
+ */
525
+ rehydrate(hydratedState: string): void;
526
+ }
527
+ declare const globalStateManager: GlobalStateManager;
528
+
451
529
  /**
452
530
  * @file src/hooks/useApi.types.ts
453
531
  * @description This file defines the professional, publicly-facing types for the `useApi` hook,
@@ -529,4 +607,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
529
607
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
530
608
  }
531
609
 
532
- 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, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule, useApiRecord, useDeepCompareEffect, useModuleContext };
610
+ 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
@@ -211,14 +211,6 @@ interface ApiModuleConfig<TActions extends Record<string, ActionConfigModule<any
211
211
  baseEndpoint: string;
212
212
  actions: TActions;
213
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
214
  /** A utility type to infer the Input type (`TInput`) from an ActionConfigModule. */
223
215
  type InputOf<TActionConfig> = TActionConfig extends ActionConfigModule<infer TInput, any> ? TInput : never;
224
216
  /** A utility type to infer the Output type (`TOutput`) from an ActionConfigModule. */
@@ -244,6 +236,34 @@ type ModuleActions<TActions extends Record<string, ActionConfigModule<any, any>>
244
236
  type ModuleStates<TActions extends Record<string, ActionConfigModule<any, any>>> = {
245
237
  [K in keyof TActions]: ActionState<OutputOf<TActions[K]>>;
246
238
  };
239
+ /** @description Configuration options passed directly to the `useApiModule` hook. */
240
+ interface UseApiModuleOptions {
241
+ onSuccess?: (actionName: string, message: string, data: unknown) => void;
242
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
243
+ refetchOnWindowFocus?: boolean;
244
+ pathParams?: Record<string, any>;
245
+ enabled?: boolean;
246
+ }
247
+ /** @description Configuration options passed directly to the `useApiModule` hook. */
248
+ interface UseApiModuleOptions {
249
+ onSuccess?: (actionName: string, message: string, data: unknown) => void;
250
+ onError?: (actionName: string, message: string, error?: ApiError | null) => void;
251
+ refetchOnWindowFocus?: boolean;
252
+ pathParams?: Record<string, any>;
253
+ enabled?: boolean;
254
+ /** [NEW.............] The dehydrated state string from the server to avoid re-fetching on the client. */
255
+ hydratedState?: string;
256
+ }
257
+ /** @description The complete, fully-typed return object of the `useApiModule` hook. */
258
+ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<any, any>>> {
259
+ states: ModuleStates<TActions>;
260
+ actions: ModuleActions<TActions>;
261
+ queries: {
262
+ [K in keyof TActions]?: TActions[K] extends {
263
+ hasQuery: true;
264
+ } ? UseApiQuery : never;
265
+ };
266
+ }
247
267
  /** @description The complete, fully-typed return object of the `useApiModule` hook. */
248
268
  interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<any, any>>> {
249
269
  states: ModuleStates<TActions>;
@@ -253,6 +273,8 @@ interface UseApiModuleReturn<TActions extends Record<string, ActionConfigModule<
253
273
  hasQuery: true;
254
274
  } ? UseApiQuery : never;
255
275
  };
276
+ /** [NEW.............] A function to serialize the current state of all queries in the hook's scope to a JSON string. */
277
+ dehydrate: () => string;
256
278
  }
257
279
 
258
280
  /**
@@ -270,6 +292,22 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
270
292
  bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
271
293
  upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
272
294
  };
295
+ /**
296
+ * [نسخة محدثة ومحسّنة]
297
+ * دالة عامة وصريحة لتنفيذ أي طلب API.
298
+ * تستقبل وسائط منظمة بدلاً من محاولة تخمينها.
299
+ *
300
+ * @param axiosInstance - نسخة Axios.
301
+ * @param baseEndpoint - نقطة النهاية الأساسية للموديول.
302
+ * @param actionConfig - إعدادات الإجراء المحدد.
303
+ * @param params - كائن يحتوي على جميع البارامترات اللازمة للطلب.
304
+ * @returns Promise<StandardResponse<any>>
305
+ */
306
+ declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
307
+ pathParams?: Record<string, string | number>;
308
+ body?: any;
309
+ config?: AxiosRequestConfig;
310
+ }): Promise<StandardResponse<any>>;
273
311
 
274
312
  /**
275
313
  * [نسخة مطورة] يبني سلسلة استعلام (query string) من كائن الخيارات.
@@ -448,6 +486,46 @@ declare const ApiModuleProvider: React$1.Provider<UseApiModuleReturn<any> | null
448
486
  declare function useModuleContext<TActions extends Record<string, ActionConfigModule<any, any>>>(): UseApiModuleReturn<TActions>;
449
487
  declare function useApiModule<TActions extends Record<string, ActionConfigModule<any, any>>>(axiosInstance: AxiosInstance, moduleConfig: ApiModuleConfig<TActions>, options?: UseApiModuleOptions): UseApiModuleReturn<TActions>;
450
488
 
489
+ declare class GlobalStateManager {
490
+ private store;
491
+ /**
492
+ * يحصل على لقطة (snapshot) للحالة الحالية لمفتاح معين.
493
+ */
494
+ getSnapshot<T>(key: string): ActionStateModule<T>;
495
+ /**
496
+ * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
497
+ * @returns دالة لإلغاء الاشتراك.
498
+ */
499
+ subscribe(key: string, callback: () => void): () => void;
500
+ /**
501
+ * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
502
+ */
503
+ setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
504
+ /**
505
+ * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
506
+ */
507
+ invalidate(key: string): void;
508
+ /**
509
+ * [نسخة محدثة وأكثر قوة]
510
+ * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
511
+ * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
512
+ */
513
+ invalidateByPrefix(prefix: string): void;
514
+ /**
515
+ * Serializes the current state of the query store into a JSON string.
516
+ * This is used on the server to pass the initial state to the client.
517
+ * @returns A JSON string representing the dehydrated state.
518
+ */
519
+ dehydrate(): string;
520
+ /**
521
+ * Merges a dehydrated state object into the current store.
522
+ * This is used on the client to hydrate the state received from the server.
523
+ * @param hydratedState - A JSON string from the `dehydrate` method.
524
+ */
525
+ rehydrate(hydratedState: string): void;
526
+ }
527
+ declare const globalStateManager: GlobalStateManager;
528
+
451
529
  /**
452
530
  * @file src/hooks/useApi.types.ts
453
531
  * @description This file defines the professional, publicly-facing types for the `useApi` hook,
@@ -529,4 +607,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
529
607
  setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
530
608
  }
531
609
 
532
- 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, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule, useApiRecord, useDeepCompareEffect, useModuleContext };
610
+ 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 };