api-core-lib 5.5.5 → 6.6.5
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 +78 -29
- package/dist/index.d.ts +78 -29
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
|
|
2
|
-
import * as react from 'react';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @file src/types.ts
|
|
@@ -339,34 +338,84 @@ declare const cacheManager: CacheManager;
|
|
|
339
338
|
*/
|
|
340
339
|
declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiError, log?: boolean) => StandardResponse<T>;
|
|
341
340
|
|
|
341
|
+
/**
|
|
342
|
+
* @file src/hooks/useApi.types.ts
|
|
343
|
+
* @description This file defines the professional, publicly-facing types
|
|
344
|
+
* returned by the `useApi` hook, providing a clean and stable contract for consumers.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The primary state object managed by the `useApi` hook.
|
|
349
|
+
* It contains the fetched data, loading status, and any potential errors.
|
|
350
|
+
* @template T The type of the data entity being managed.
|
|
351
|
+
*/
|
|
352
|
+
type UseApiState<T> = StandardResponse<T | T[]>;
|
|
353
|
+
/**
|
|
354
|
+
* A collection of callable functions for performing CRUD and other operations.
|
|
355
|
+
* These actions automatically handle state updates like loading and refetching.
|
|
356
|
+
* @template T The type of the data entity being managed.
|
|
357
|
+
*/
|
|
358
|
+
interface UseApiActions<T> {
|
|
359
|
+
/** Fetches or refetches the list of data. */
|
|
360
|
+
fetch: (options?: QueryOptions) => Promise<void>;
|
|
361
|
+
/** Creates a new item. */
|
|
362
|
+
create: (newItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
363
|
+
/** Replaces an entire item. */
|
|
364
|
+
put: (id: string | number, item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
365
|
+
/** Partially updates an item. */
|
|
366
|
+
update: (id: string | number, updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
367
|
+
/** Deletes an item. */
|
|
368
|
+
remove: (id: string | number, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
369
|
+
/** Deletes multiple items in a single request. */
|
|
370
|
+
bulkRemove: (ids: Array<string | number>, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
371
|
+
/** Uploads a file, optionally with additional data. */
|
|
372
|
+
upload: (file: File, additionalData?: Record<string, any>, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A collection of functions and properties for controlling the query parameters
|
|
376
|
+
* used for fetching data, such as pagination, sorting, and filtering.
|
|
377
|
+
*/
|
|
378
|
+
interface UseApiQuery {
|
|
379
|
+
/** The current query options state. */
|
|
380
|
+
options: QueryOptions;
|
|
381
|
+
/** A function to set the entire query options object at once. */
|
|
382
|
+
setOptions: React.Dispatch<React.SetStateAction<QueryOptions>>;
|
|
383
|
+
/** Sets the current page number and resets to the first page. */
|
|
384
|
+
setPage: (page: number) => void;
|
|
385
|
+
/** Sets the number of items per page and resets to the first page. */
|
|
386
|
+
setLimit: (limit: number) => void;
|
|
387
|
+
/** Sets the search term and resets to the first page. */
|
|
388
|
+
setSearchTerm: (search: string) => void;
|
|
389
|
+
/** Sets the sorting configuration. */
|
|
390
|
+
setSorting: (sortBy: {
|
|
391
|
+
key: string;
|
|
392
|
+
direction: 'asc' | 'desc';
|
|
393
|
+
}[]) => void;
|
|
394
|
+
/** Sets the filter object and resets to the first page. */
|
|
395
|
+
setFilters: (filter: Record<string, any>) => void;
|
|
396
|
+
/** Sets a single, custom query parameter and resets to the first page. */
|
|
397
|
+
setQueryParam: (key: string, value: any) => void;
|
|
398
|
+
/** Resets the query options to their initial state. */
|
|
399
|
+
reset: () => void;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The complete return type of the `useApi` hook.
|
|
403
|
+
* It encapsulates the state, actions, and query controls for a given API resource.
|
|
404
|
+
* @template T The type of the data entity being managed.
|
|
405
|
+
*/
|
|
406
|
+
interface UseApiReturn<T> {
|
|
407
|
+
/** The current state of the API request (data, loading, error). */
|
|
408
|
+
state: UseApiState<T>;
|
|
409
|
+
/** A function to manually set the state. Use with caution. */
|
|
410
|
+
setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
|
|
411
|
+
/** An object containing all available data manipulation actions (create, update, delete, etc.). */
|
|
412
|
+
actions: UseApiActions<T>;
|
|
413
|
+
/** An object for controlling the query parameters for data fetching. */
|
|
414
|
+
query: UseApiQuery;
|
|
415
|
+
}
|
|
416
|
+
|
|
342
417
|
declare function useApi<T extends {
|
|
343
418
|
id?: string | number;
|
|
344
|
-
}>(axiosInstance: AxiosInstance, config: UseApiConfig<T>):
|
|
345
|
-
state: StandardResponse<T | T[]>;
|
|
346
|
-
setState: react.Dispatch<react.SetStateAction<StandardResponse<T | T[]>>>;
|
|
347
|
-
actions: {
|
|
348
|
-
fetch: (options?: QueryOptions) => Promise<void>;
|
|
349
|
-
create: (newItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
350
|
-
put: (id: string, item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
351
|
-
update: (id: string, updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
352
|
-
remove: (id: string, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
353
|
-
bulkRemove: (ids: string[], options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
354
|
-
upload: (file: File, additionalData?: Record<string, any>, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
355
|
-
};
|
|
356
|
-
query: {
|
|
357
|
-
options: QueryOptions;
|
|
358
|
-
setOptions: react.Dispatch<react.SetStateAction<QueryOptions>>;
|
|
359
|
-
setPage: (page: number) => void;
|
|
360
|
-
setLimit: (limit: number) => void;
|
|
361
|
-
setSearchTerm: (search: string) => void;
|
|
362
|
-
setSorting: (sortBy: {
|
|
363
|
-
key: string;
|
|
364
|
-
direction: "asc" | "desc";
|
|
365
|
-
}[]) => void;
|
|
366
|
-
setFilters: (filter: Record<string, any>) => void;
|
|
367
|
-
setQueryParam: (key: string, value: any) => void;
|
|
368
|
-
reset: () => void;
|
|
369
|
-
};
|
|
370
|
-
};
|
|
419
|
+
}>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
|
|
371
420
|
|
|
372
|
-
export { type ActionOptions, type ApiClientConfig, type ApiError, type ApiResponse, type LogLevel, type Logger, type Middleware, type MiddlewareContext, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiConfig, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi };
|
|
421
|
+
export { type ActionOptions, type ApiClientConfig, type ApiError, type ApiResponse, type LogLevel, type Logger, type Middleware, type MiddlewareContext, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiActions, type UseApiConfig, type UseApiQuery, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosProgressEvent, AxiosInstance, Method } from 'axios';
|
|
2
|
-
import * as react from 'react';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @file src/types.ts
|
|
@@ -339,34 +338,84 @@ declare const cacheManager: CacheManager;
|
|
|
339
338
|
*/
|
|
340
339
|
declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiError, log?: boolean) => StandardResponse<T>;
|
|
341
340
|
|
|
341
|
+
/**
|
|
342
|
+
* @file src/hooks/useApi.types.ts
|
|
343
|
+
* @description This file defines the professional, publicly-facing types
|
|
344
|
+
* returned by the `useApi` hook, providing a clean and stable contract for consumers.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The primary state object managed by the `useApi` hook.
|
|
349
|
+
* It contains the fetched data, loading status, and any potential errors.
|
|
350
|
+
* @template T The type of the data entity being managed.
|
|
351
|
+
*/
|
|
352
|
+
type UseApiState<T> = StandardResponse<T | T[]>;
|
|
353
|
+
/**
|
|
354
|
+
* A collection of callable functions for performing CRUD and other operations.
|
|
355
|
+
* These actions automatically handle state updates like loading and refetching.
|
|
356
|
+
* @template T The type of the data entity being managed.
|
|
357
|
+
*/
|
|
358
|
+
interface UseApiActions<T> {
|
|
359
|
+
/** Fetches or refetches the list of data. */
|
|
360
|
+
fetch: (options?: QueryOptions) => Promise<void>;
|
|
361
|
+
/** Creates a new item. */
|
|
362
|
+
create: (newItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
363
|
+
/** Replaces an entire item. */
|
|
364
|
+
put: (id: string | number, item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
365
|
+
/** Partially updates an item. */
|
|
366
|
+
update: (id: string | number, updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
367
|
+
/** Deletes an item. */
|
|
368
|
+
remove: (id: string | number, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
369
|
+
/** Deletes multiple items in a single request. */
|
|
370
|
+
bulkRemove: (ids: Array<string | number>, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
371
|
+
/** Uploads a file, optionally with additional data. */
|
|
372
|
+
upload: (file: File, additionalData?: Record<string, any>, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A collection of functions and properties for controlling the query parameters
|
|
376
|
+
* used for fetching data, such as pagination, sorting, and filtering.
|
|
377
|
+
*/
|
|
378
|
+
interface UseApiQuery {
|
|
379
|
+
/** The current query options state. */
|
|
380
|
+
options: QueryOptions;
|
|
381
|
+
/** A function to set the entire query options object at once. */
|
|
382
|
+
setOptions: React.Dispatch<React.SetStateAction<QueryOptions>>;
|
|
383
|
+
/** Sets the current page number and resets to the first page. */
|
|
384
|
+
setPage: (page: number) => void;
|
|
385
|
+
/** Sets the number of items per page and resets to the first page. */
|
|
386
|
+
setLimit: (limit: number) => void;
|
|
387
|
+
/** Sets the search term and resets to the first page. */
|
|
388
|
+
setSearchTerm: (search: string) => void;
|
|
389
|
+
/** Sets the sorting configuration. */
|
|
390
|
+
setSorting: (sortBy: {
|
|
391
|
+
key: string;
|
|
392
|
+
direction: 'asc' | 'desc';
|
|
393
|
+
}[]) => void;
|
|
394
|
+
/** Sets the filter object and resets to the first page. */
|
|
395
|
+
setFilters: (filter: Record<string, any>) => void;
|
|
396
|
+
/** Sets a single, custom query parameter and resets to the first page. */
|
|
397
|
+
setQueryParam: (key: string, value: any) => void;
|
|
398
|
+
/** Resets the query options to their initial state. */
|
|
399
|
+
reset: () => void;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The complete return type of the `useApi` hook.
|
|
403
|
+
* It encapsulates the state, actions, and query controls for a given API resource.
|
|
404
|
+
* @template T The type of the data entity being managed.
|
|
405
|
+
*/
|
|
406
|
+
interface UseApiReturn<T> {
|
|
407
|
+
/** The current state of the API request (data, loading, error). */
|
|
408
|
+
state: UseApiState<T>;
|
|
409
|
+
/** A function to manually set the state. Use with caution. */
|
|
410
|
+
setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
|
|
411
|
+
/** An object containing all available data manipulation actions (create, update, delete, etc.). */
|
|
412
|
+
actions: UseApiActions<T>;
|
|
413
|
+
/** An object for controlling the query parameters for data fetching. */
|
|
414
|
+
query: UseApiQuery;
|
|
415
|
+
}
|
|
416
|
+
|
|
342
417
|
declare function useApi<T extends {
|
|
343
418
|
id?: string | number;
|
|
344
|
-
}>(axiosInstance: AxiosInstance, config: UseApiConfig<T>):
|
|
345
|
-
state: StandardResponse<T | T[]>;
|
|
346
|
-
setState: react.Dispatch<react.SetStateAction<StandardResponse<T | T[]>>>;
|
|
347
|
-
actions: {
|
|
348
|
-
fetch: (options?: QueryOptions) => Promise<void>;
|
|
349
|
-
create: (newItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
350
|
-
put: (id: string, item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
351
|
-
update: (id: string, updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
352
|
-
remove: (id: string, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
353
|
-
bulkRemove: (ids: string[], options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
354
|
-
upload: (file: File, additionalData?: Record<string, any>, options?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
355
|
-
};
|
|
356
|
-
query: {
|
|
357
|
-
options: QueryOptions;
|
|
358
|
-
setOptions: react.Dispatch<react.SetStateAction<QueryOptions>>;
|
|
359
|
-
setPage: (page: number) => void;
|
|
360
|
-
setLimit: (limit: number) => void;
|
|
361
|
-
setSearchTerm: (search: string) => void;
|
|
362
|
-
setSorting: (sortBy: {
|
|
363
|
-
key: string;
|
|
364
|
-
direction: "asc" | "desc";
|
|
365
|
-
}[]) => void;
|
|
366
|
-
setFilters: (filter: Record<string, any>) => void;
|
|
367
|
-
setQueryParam: (key: string, value: any) => void;
|
|
368
|
-
reset: () => void;
|
|
369
|
-
};
|
|
370
|
-
};
|
|
419
|
+
}>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): UseApiReturn<T>;
|
|
371
420
|
|
|
372
|
-
export { type ActionOptions, type ApiClientConfig, type ApiError, type ApiResponse, type LogLevel, type Logger, type Middleware, type MiddlewareContext, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiConfig, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi };
|
|
421
|
+
export { type ActionOptions, type ApiClientConfig, type ApiError, type ApiResponse, type LogLevel, type Logger, type Middleware, type MiddlewareContext, type PaginationMeta, type QueryOptions, type RefreshTokenConfig, type RequestConfig, type StandardResponse, type TokenManager, type Tokens, type UseApiActions, type UseApiConfig, type UseApiQuery, type UseApiReturn, type UseApiState, type ValidationError, buildPaginateQuery, cacheManager, createApiActions, createApiClient, createApiServices, processResponse, useApi };
|