api-core-lib 7.6.6 → 7.7.7

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
@@ -127,7 +127,7 @@ interface QueryOptions {
127
127
  /**
128
128
  * Defines additional options for action methods like create, update, or delete.
129
129
  */
130
- interface ActionOptions {
130
+ interface ActionOptions extends RequestConfig {
131
131
  /**
132
132
  * Overrides the default endpoint for a specific action. Useful for specialized routes.
133
133
  * @example update('123', { status: 'active' }, { endpoint: '/items/123/activate' })
@@ -146,7 +146,7 @@ interface UseApiConfig<T> {
146
146
  /** The base API endpoint for the resource (e.g., '/users'). */
147
147
  endpoint: string;
148
148
  /** Initial data to populate the state before the first fetch. */
149
- initialData?: T | T[];
149
+ initialData?: T[];
150
150
  /** Default query options to use for the initial fetch. */
151
151
  initialQuery?: QueryOptions;
152
152
  /** If false, the hook will not fetch data automatically on mount. */
@@ -155,10 +155,10 @@ interface UseApiConfig<T> {
155
155
  refetchAfterChange?: boolean;
156
156
  /** A default `RequestConfig` to apply to all GET requests made by the hook. */
157
157
  requestConfig?: RequestConfig;
158
- encodeQuery: boolean;
159
- pathParams: Record<string, string | number>;
158
+ encodeQuery?: boolean;
159
+ pathParams?: Record<string, string | number>;
160
160
  /** Callback function executed on a successful action. */
161
- onSuccess?: (message: string, data?: T) => void;
161
+ onSuccess?: (message: string, data?: T[]) => void;
162
162
  /** Callback function executed on a failed action. */
163
163
  onError?: (message: string, error?: ApiError) => void;
164
164
  }
@@ -259,20 +259,15 @@ interface ApiClientConfig {
259
259
  */
260
260
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
261
261
 
262
- type CrudRequestConfig = RequestConfig & ActionOptions;
263
- /**
264
- * دالة مصنع (Factory Function) لإنشاء مجموعة خدمات API قابلة لإعادة الاستخدام لنقطة نهاية (endpoint) محددة.
265
- * توفر عمليات CRUD كاملة بالإضافة إلى ميزات متقدمة مثل الحذف الجماعي ورفع الملفات.
266
- */
267
- declare function createApiServices<T>(axiosInstance: AxiosInstance, endpoint: string): {
268
- get: (id?: string, config?: RequestConfig) => Promise<StandardResponse<T | T[]>>;
269
- getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T[]>>;
270
- post: (data: Partial<T>, config?: CrudRequestConfig) => Promise<StandardResponse<T>>;
271
- put: (id: string, data: T, config?: CrudRequestConfig) => Promise<StandardResponse<T>>;
272
- patch: (id: string, data: Partial<T>, config?: CrudRequestConfig) => Promise<StandardResponse<T>>;
273
- remove: (id: string, config?: CrudRequestConfig) => Promise<StandardResponse<any>>;
274
- bulkDelete: (ids: string[], config?: CrudRequestConfig) => Promise<StandardResponse<any>>;
275
- upload: (file: File, additionalData?: Record<string, any>, config?: CrudRequestConfig) => Promise<StandardResponse<any>>;
262
+ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
263
+ get: (id: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
264
+ getWithQuery: (query: string, config?: ActionOptions) => Promise<StandardResponse<T[]>>;
265
+ post: (data: Partial<T>, config?: ActionOptions) => Promise<StandardResponse<T>>;
266
+ put: (id: string | number, data: T, config?: ActionOptions) => Promise<StandardResponse<T>>;
267
+ patch: (id: string | number, data: Partial<T>, config?: ActionOptions) => Promise<StandardResponse<T>>;
268
+ remove: (id: string | number, config?: ActionOptions) => Promise<StandardResponse<any>>;
269
+ bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
270
+ upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
276
271
  };
277
272
 
278
273
  /**
@@ -361,37 +356,19 @@ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiErro
361
356
  * It contains the fetched data, loading status, and any potential errors.
362
357
  * @template T The type of the data entity being managed.
363
358
  */
364
- type UseApiState<T> = StandardResponse<T | T[]>;
359
+ type UseApiState<T> = StandardResponse<T[]>;
365
360
  /**
366
361
  * A collection of callable functions for performing CRUD and other operations.
367
362
  * These actions automatically handle state updates like loading and refetching.
368
363
  * @template T The type of the data entity being managed.
369
364
  */
370
365
  interface UseApiActions<T> {
371
- /**
372
- * Manually triggers a refetch of the hook's primary data using the current query options.
373
- * This is useful for manual refresh buttons.
374
- */
375
- /**
376
- * Fetches data from an arbitrary path, independent of the hook's main state.
377
- * This is useful for one-off requests that shouldn't affect the primary data.
378
- * @param path The relative or absolute path to fetch from.
379
- * @param pathParams Optional parameters to fill dynamic parts of the path.
380
- * @param options Optional Axios request configuration.
381
- * @returns A promise that resolves with the standard API response.
382
- */
383
- fetch: (options?: QueryOptions) => Promise<void>;
384
- /** Creates a new item. */
366
+ fetchList: () => Promise<void>;
385
367
  create: (newItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
386
- /** Replaces an entire item. */
387
368
  put: (id: string | number, item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
388
- /** Partially updates an item. */
389
369
  update: (id: string | number, updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
390
- /** Deletes an item. */
391
370
  remove: (id: string | number, options?: ActionOptions) => Promise<StandardResponse<any>>;
392
- /** Deletes multiple items in a single request. */
393
371
  bulkRemove: (ids: Array<string | number>, options?: ActionOptions) => Promise<StandardResponse<any>>;
394
- /** Uploads a file, optionally with additional data. */
395
372
  upload: (file: File, additionalData?: Record<string, any>, options?: ActionOptions) => Promise<StandardResponse<any>>;
396
373
  }
397
374
  /**
@@ -427,13 +404,9 @@ interface UseApiQuery {
427
404
  * @template T The type of the data entity being managed.
428
405
  */
429
406
  interface UseApiReturn<T> {
430
- /** The current state of the API request (data, loading, error). */
431
407
  state: UseApiState<T>;
432
- /** A function to manually set the state. Use with caution. */
433
408
  setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
434
- /** An object containing all available data manipulation actions (create, update, delete, etc.). */
435
409
  actions: UseApiActions<T>;
436
- /** An object for controlling the query parameters for data fetching. */
437
410
  query: UseApiQuery;
438
411
  }
439
412
 
package/dist/index.d.ts CHANGED
@@ -127,7 +127,7 @@ interface QueryOptions {
127
127
  /**
128
128
  * Defines additional options for action methods like create, update, or delete.
129
129
  */
130
- interface ActionOptions {
130
+ interface ActionOptions extends RequestConfig {
131
131
  /**
132
132
  * Overrides the default endpoint for a specific action. Useful for specialized routes.
133
133
  * @example update('123', { status: 'active' }, { endpoint: '/items/123/activate' })
@@ -146,7 +146,7 @@ interface UseApiConfig<T> {
146
146
  /** The base API endpoint for the resource (e.g., '/users'). */
147
147
  endpoint: string;
148
148
  /** Initial data to populate the state before the first fetch. */
149
- initialData?: T | T[];
149
+ initialData?: T[];
150
150
  /** Default query options to use for the initial fetch. */
151
151
  initialQuery?: QueryOptions;
152
152
  /** If false, the hook will not fetch data automatically on mount. */
@@ -155,10 +155,10 @@ interface UseApiConfig<T> {
155
155
  refetchAfterChange?: boolean;
156
156
  /** A default `RequestConfig` to apply to all GET requests made by the hook. */
157
157
  requestConfig?: RequestConfig;
158
- encodeQuery: boolean;
159
- pathParams: Record<string, string | number>;
158
+ encodeQuery?: boolean;
159
+ pathParams?: Record<string, string | number>;
160
160
  /** Callback function executed on a successful action. */
161
- onSuccess?: (message: string, data?: T) => void;
161
+ onSuccess?: (message: string, data?: T[]) => void;
162
162
  /** Callback function executed on a failed action. */
163
163
  onError?: (message: string, error?: ApiError) => void;
164
164
  }
@@ -259,20 +259,15 @@ interface ApiClientConfig {
259
259
  */
260
260
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
261
261
 
262
- type CrudRequestConfig = RequestConfig & ActionOptions;
263
- /**
264
- * دالة مصنع (Factory Function) لإنشاء مجموعة خدمات API قابلة لإعادة الاستخدام لنقطة نهاية (endpoint) محددة.
265
- * توفر عمليات CRUD كاملة بالإضافة إلى ميزات متقدمة مثل الحذف الجماعي ورفع الملفات.
266
- */
267
- declare function createApiServices<T>(axiosInstance: AxiosInstance, endpoint: string): {
268
- get: (id?: string, config?: RequestConfig) => Promise<StandardResponse<T | T[]>>;
269
- getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T[]>>;
270
- post: (data: Partial<T>, config?: CrudRequestConfig) => Promise<StandardResponse<T>>;
271
- put: (id: string, data: T, config?: CrudRequestConfig) => Promise<StandardResponse<T>>;
272
- patch: (id: string, data: Partial<T>, config?: CrudRequestConfig) => Promise<StandardResponse<T>>;
273
- remove: (id: string, config?: CrudRequestConfig) => Promise<StandardResponse<any>>;
274
- bulkDelete: (ids: string[], config?: CrudRequestConfig) => Promise<StandardResponse<any>>;
275
- upload: (file: File, additionalData?: Record<string, any>, config?: CrudRequestConfig) => Promise<StandardResponse<any>>;
262
+ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
263
+ get: (id: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
264
+ getWithQuery: (query: string, config?: ActionOptions) => Promise<StandardResponse<T[]>>;
265
+ post: (data: Partial<T>, config?: ActionOptions) => Promise<StandardResponse<T>>;
266
+ put: (id: string | number, data: T, config?: ActionOptions) => Promise<StandardResponse<T>>;
267
+ patch: (id: string | number, data: Partial<T>, config?: ActionOptions) => Promise<StandardResponse<T>>;
268
+ remove: (id: string | number, config?: ActionOptions) => Promise<StandardResponse<any>>;
269
+ bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
270
+ upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
276
271
  };
277
272
 
278
273
  /**
@@ -361,37 +356,19 @@ declare const processResponse: <T>(responseOrError: AxiosResponse<any> | ApiErro
361
356
  * It contains the fetched data, loading status, and any potential errors.
362
357
  * @template T The type of the data entity being managed.
363
358
  */
364
- type UseApiState<T> = StandardResponse<T | T[]>;
359
+ type UseApiState<T> = StandardResponse<T[]>;
365
360
  /**
366
361
  * A collection of callable functions for performing CRUD and other operations.
367
362
  * These actions automatically handle state updates like loading and refetching.
368
363
  * @template T The type of the data entity being managed.
369
364
  */
370
365
  interface UseApiActions<T> {
371
- /**
372
- * Manually triggers a refetch of the hook's primary data using the current query options.
373
- * This is useful for manual refresh buttons.
374
- */
375
- /**
376
- * Fetches data from an arbitrary path, independent of the hook's main state.
377
- * This is useful for one-off requests that shouldn't affect the primary data.
378
- * @param path The relative or absolute path to fetch from.
379
- * @param pathParams Optional parameters to fill dynamic parts of the path.
380
- * @param options Optional Axios request configuration.
381
- * @returns A promise that resolves with the standard API response.
382
- */
383
- fetch: (options?: QueryOptions) => Promise<void>;
384
- /** Creates a new item. */
366
+ fetchList: () => Promise<void>;
385
367
  create: (newItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
386
- /** Replaces an entire item. */
387
368
  put: (id: string | number, item: T, options?: ActionOptions) => Promise<StandardResponse<T>>;
388
- /** Partially updates an item. */
389
369
  update: (id: string | number, updatedItem: Partial<T>, options?: ActionOptions) => Promise<StandardResponse<T>>;
390
- /** Deletes an item. */
391
370
  remove: (id: string | number, options?: ActionOptions) => Promise<StandardResponse<any>>;
392
- /** Deletes multiple items in a single request. */
393
371
  bulkRemove: (ids: Array<string | number>, options?: ActionOptions) => Promise<StandardResponse<any>>;
394
- /** Uploads a file, optionally with additional data. */
395
372
  upload: (file: File, additionalData?: Record<string, any>, options?: ActionOptions) => Promise<StandardResponse<any>>;
396
373
  }
397
374
  /**
@@ -427,13 +404,9 @@ interface UseApiQuery {
427
404
  * @template T The type of the data entity being managed.
428
405
  */
429
406
  interface UseApiReturn<T> {
430
- /** The current state of the API request (data, loading, error). */
431
407
  state: UseApiState<T>;
432
- /** A function to manually set the state. Use with caution. */
433
408
  setState: React.Dispatch<React.SetStateAction<UseApiState<T>>>;
434
- /** An object containing all available data manipulation actions (create, update, delete, etc.). */
435
409
  actions: UseApiActions<T>;
436
- /** An object for controlling the query parameters for data fetching. */
437
410
  query: UseApiQuery;
438
411
  }
439
412