api-core-lib 11.11.10 → 12.0.0
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 +93 -5
- package/dist/index.d.ts +93 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @file src/types.ts
|
|
@@ -449,11 +450,98 @@ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiErro
|
|
|
449
450
|
declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
|
|
450
451
|
|
|
451
452
|
/**
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
* while guaranteeing stable function references to prevent re-renders.
|
|
453
|
+
* هوك متقدم يقوم ببناء مجموعة من الإجراءات القابلة للتنفيذ من إعدادات موديول API،
|
|
454
|
+
* مع فصل تام بين الدوال المستقرة والحالات المتغيرة لمنع الحلقات اللانهائية.
|
|
455
455
|
*/
|
|
456
|
-
declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions):
|
|
456
|
+
declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions): any;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Represents the internal state of the `useApiRecord` hook.
|
|
460
|
+
* It mirrors the `StandardResponse` structure, which is the unified response format
|
|
461
|
+
* used across the library.
|
|
462
|
+
* @template T The data type of the record.
|
|
463
|
+
*/
|
|
464
|
+
type UseApiRecordState<T> = StandardResponse<T>;
|
|
465
|
+
/**
|
|
466
|
+
* Defines the action methods provided by the `useApiRecord` hook to interact with
|
|
467
|
+
* a single API resource.
|
|
468
|
+
* @template T The data type of the record.
|
|
469
|
+
*/
|
|
470
|
+
interface UseApiRecordActions<T> {
|
|
471
|
+
/**
|
|
472
|
+
* Manually fetches or refetches the record from the API.
|
|
473
|
+
*/
|
|
474
|
+
fetch: () => Promise<void>;
|
|
475
|
+
/**
|
|
476
|
+
* Partially updates the record using an HTTP PATCH request.
|
|
477
|
+
* @param updatedItem An object containing the fields to update.
|
|
478
|
+
* @param options Additional request options, allowing overrides for this specific action.
|
|
479
|
+
* @returns A promise that resolves to the standard response object for the updated record.
|
|
480
|
+
*/
|
|
481
|
+
update: (updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
482
|
+
/**
|
|
483
|
+
* Replaces the entire record with a new one using an HTTP PUT request.
|
|
484
|
+
* @param item The complete new record object.
|
|
485
|
+
* @param options Additional request options.
|
|
486
|
+
* @returns A promise that resolves to the standard response object for the replaced record.
|
|
487
|
+
*/
|
|
488
|
+
put: (item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
489
|
+
/**
|
|
490
|
+
* Deletes the record using an HTTP DELETE request.
|
|
491
|
+
* @param options Additional request options.
|
|
492
|
+
* @returns A promise that resolves to a standard response object with a null data payload.
|
|
493
|
+
*/
|
|
494
|
+
remove: (options?: ActionOptions) => Promise<StandardResponse<null>>;
|
|
495
|
+
/**
|
|
496
|
+
* Resets the hook's state to its initial value.
|
|
497
|
+
*/
|
|
498
|
+
resetState: () => void;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Defines the configuration options for the `useApiRecord` hook.
|
|
502
|
+
* @template T The data type of the record.
|
|
503
|
+
*/
|
|
504
|
+
interface UseApiRecordConfig<T> {
|
|
505
|
+
/** The base API endpoint for the resource (e.g., '/users'). */
|
|
506
|
+
endpoint: string;
|
|
507
|
+
/** The unique identifier of the record to fetch or modify. */
|
|
508
|
+
recordId?: string | number | null;
|
|
509
|
+
/** Optional initial data to populate the state before the first fetch is complete. */
|
|
510
|
+
initialData?: T | null;
|
|
511
|
+
/** If `false`, the hook will not automatically fetch data on mount. Defaults to `true`. */
|
|
512
|
+
enabled?: boolean;
|
|
513
|
+
/** If `true`, the record will be refetched after a successful `update`, `put`, or `remove` action. Defaults to `true`. */
|
|
514
|
+
refetchAfterChange?: boolean;
|
|
515
|
+
/** Default `RequestConfig` to apply to the initial GET request made by the hook. */
|
|
516
|
+
requestConfig?: RequestConfig;
|
|
517
|
+
/** A callback function executed on a successful API action. */
|
|
518
|
+
onSuccess?: (message: string, data?: any) => void;
|
|
519
|
+
/** A callback function executed on a failed API action. */
|
|
520
|
+
onError?: (message: string, error?: ApiError) => void;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* The return value of the `useApiRecord` hook.
|
|
524
|
+
* @template T The data type of the record.
|
|
525
|
+
*/
|
|
526
|
+
interface UseApiRecordReturn<T> {
|
|
527
|
+
/** The current state of the API request, including data, loading, and error status. */
|
|
528
|
+
state: UseApiRecordState<T>;
|
|
529
|
+
/** Action methods to manipulate the record. */
|
|
530
|
+
actions: UseApiRecordActions<T>;
|
|
531
|
+
/** A React dispatch function to manually set the hook's state. Use with caution. */
|
|
532
|
+
setState: Dispatch<SetStateAction<UseApiRecordState<T>>>;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* A React hook for managing the lifecycle of a single API resource (a record).
|
|
537
|
+
* It handles fetching, updating, replacing, and deleting a record, while managing
|
|
538
|
+
* loading, error, and data states.
|
|
539
|
+
*/
|
|
540
|
+
declare function useApiRecord<T>(axiosInstance: AxiosInstance, config: UseApiRecordConfig<T>): UseApiRecordReturn<T>;
|
|
541
|
+
|
|
542
|
+
type EffectCallback = () => (void | (() => void));
|
|
543
|
+
type DependencyList = readonly any[];
|
|
544
|
+
declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): void;
|
|
457
545
|
|
|
458
546
|
type ApiResourceStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
459
547
|
interface UseApiResourceState<T> {
|
|
@@ -501,4 +589,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
|
|
|
501
589
|
setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
|
|
502
590
|
}
|
|
503
591
|
|
|
504
|
-
export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, 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 UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule };
|
|
592
|
+
export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @file src/types.ts
|
|
@@ -449,11 +450,98 @@ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiErro
|
|
|
449
450
|
declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
|
|
450
451
|
|
|
451
452
|
/**
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
* while guaranteeing stable function references to prevent re-renders.
|
|
453
|
+
* هوك متقدم يقوم ببناء مجموعة من الإجراءات القابلة للتنفيذ من إعدادات موديول API،
|
|
454
|
+
* مع فصل تام بين الدوال المستقرة والحالات المتغيرة لمنع الحلقات اللانهائية.
|
|
455
455
|
*/
|
|
456
|
-
declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions):
|
|
456
|
+
declare function useApiModule<TModule extends ApiModuleConfig>(axiosInstance: AxiosInstance, moduleConfig: TModule, options?: UseApiModuleOptions): any;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Represents the internal state of the `useApiRecord` hook.
|
|
460
|
+
* It mirrors the `StandardResponse` structure, which is the unified response format
|
|
461
|
+
* used across the library.
|
|
462
|
+
* @template T The data type of the record.
|
|
463
|
+
*/
|
|
464
|
+
type UseApiRecordState<T> = StandardResponse<T>;
|
|
465
|
+
/**
|
|
466
|
+
* Defines the action methods provided by the `useApiRecord` hook to interact with
|
|
467
|
+
* a single API resource.
|
|
468
|
+
* @template T The data type of the record.
|
|
469
|
+
*/
|
|
470
|
+
interface UseApiRecordActions<T> {
|
|
471
|
+
/**
|
|
472
|
+
* Manually fetches or refetches the record from the API.
|
|
473
|
+
*/
|
|
474
|
+
fetch: () => Promise<void>;
|
|
475
|
+
/**
|
|
476
|
+
* Partially updates the record using an HTTP PATCH request.
|
|
477
|
+
* @param updatedItem An object containing the fields to update.
|
|
478
|
+
* @param options Additional request options, allowing overrides for this specific action.
|
|
479
|
+
* @returns A promise that resolves to the standard response object for the updated record.
|
|
480
|
+
*/
|
|
481
|
+
update: (updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
482
|
+
/**
|
|
483
|
+
* Replaces the entire record with a new one using an HTTP PUT request.
|
|
484
|
+
* @param item The complete new record object.
|
|
485
|
+
* @param options Additional request options.
|
|
486
|
+
* @returns A promise that resolves to the standard response object for the replaced record.
|
|
487
|
+
*/
|
|
488
|
+
put: (item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
489
|
+
/**
|
|
490
|
+
* Deletes the record using an HTTP DELETE request.
|
|
491
|
+
* @param options Additional request options.
|
|
492
|
+
* @returns A promise that resolves to a standard response object with a null data payload.
|
|
493
|
+
*/
|
|
494
|
+
remove: (options?: ActionOptions) => Promise<StandardResponse<null>>;
|
|
495
|
+
/**
|
|
496
|
+
* Resets the hook's state to its initial value.
|
|
497
|
+
*/
|
|
498
|
+
resetState: () => void;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Defines the configuration options for the `useApiRecord` hook.
|
|
502
|
+
* @template T The data type of the record.
|
|
503
|
+
*/
|
|
504
|
+
interface UseApiRecordConfig<T> {
|
|
505
|
+
/** The base API endpoint for the resource (e.g., '/users'). */
|
|
506
|
+
endpoint: string;
|
|
507
|
+
/** The unique identifier of the record to fetch or modify. */
|
|
508
|
+
recordId?: string | number | null;
|
|
509
|
+
/** Optional initial data to populate the state before the first fetch is complete. */
|
|
510
|
+
initialData?: T | null;
|
|
511
|
+
/** If `false`, the hook will not automatically fetch data on mount. Defaults to `true`. */
|
|
512
|
+
enabled?: boolean;
|
|
513
|
+
/** If `true`, the record will be refetched after a successful `update`, `put`, or `remove` action. Defaults to `true`. */
|
|
514
|
+
refetchAfterChange?: boolean;
|
|
515
|
+
/** Default `RequestConfig` to apply to the initial GET request made by the hook. */
|
|
516
|
+
requestConfig?: RequestConfig;
|
|
517
|
+
/** A callback function executed on a successful API action. */
|
|
518
|
+
onSuccess?: (message: string, data?: any) => void;
|
|
519
|
+
/** A callback function executed on a failed API action. */
|
|
520
|
+
onError?: (message: string, error?: ApiError) => void;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* The return value of the `useApiRecord` hook.
|
|
524
|
+
* @template T The data type of the record.
|
|
525
|
+
*/
|
|
526
|
+
interface UseApiRecordReturn<T> {
|
|
527
|
+
/** The current state of the API request, including data, loading, and error status. */
|
|
528
|
+
state: UseApiRecordState<T>;
|
|
529
|
+
/** Action methods to manipulate the record. */
|
|
530
|
+
actions: UseApiRecordActions<T>;
|
|
531
|
+
/** A React dispatch function to manually set the hook's state. Use with caution. */
|
|
532
|
+
setState: Dispatch<SetStateAction<UseApiRecordState<T>>>;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* A React hook for managing the lifecycle of a single API resource (a record).
|
|
537
|
+
* It handles fetching, updating, replacing, and deleting a record, while managing
|
|
538
|
+
* loading, error, and data states.
|
|
539
|
+
*/
|
|
540
|
+
declare function useApiRecord<T>(axiosInstance: AxiosInstance, config: UseApiRecordConfig<T>): UseApiRecordReturn<T>;
|
|
541
|
+
|
|
542
|
+
type EffectCallback = () => (void | (() => void));
|
|
543
|
+
type DependencyList = readonly any[];
|
|
544
|
+
declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): void;
|
|
457
545
|
|
|
458
546
|
type ApiResourceStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
459
547
|
interface UseApiResourceState<T> {
|
|
@@ -501,4 +589,4 @@ interface UseApiResourceReturn<T, TCreate, TUpdate, TPathParams> {
|
|
|
501
589
|
setQuery: React.Dispatch<React.SetStateAction<QueryOptions>>;
|
|
502
590
|
}
|
|
503
591
|
|
|
504
|
-
export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, 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 UseApiResourceActions, type UseApiResourceConfig, type UseApiResourceReturn, type UseApiResourceState, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi, useApiModule };
|
|
592
|
+
export { type ActionConfig, type ActionOptions, type ActionState, type ApiClientConfig, type ApiError, type ApiModuleConfig, type ApiResourceStatus, type ApiResponse, 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 };
|