api-core-lib 12.5.0 → 12.6.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
@@ -155,8 +155,11 @@ 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;
158
+ /**
159
+ * [NEW] كائن يحتوي على قيم المتغيرات في قالب المسار.
160
+ */
159
161
  pathParams?: Record<string, string | number>;
162
+ encodeQuery?: boolean;
160
163
  /** Callback function executed on a successful action. */
161
164
  onSuccess?: (message: string, data?: T) => void;
162
165
  /** Callback function executed on a failed action. */
@@ -257,7 +260,7 @@ type UseApiState<T> = StandardResponse<T>;
257
260
  * @template T The type of the data entity being managed.
258
261
  */
259
262
  interface UseApiActions<T, TListItem = T extends (infer U)[] ? U : T> {
260
- fetch: () => Promise<void>;
263
+ fetch: (querryOptions?: QueryOptions) => Promise<void>;
261
264
  create: (newItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
262
265
  put: (id: string | number, item: TListItem, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
263
266
  update: (id: string | number, updatedItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
@@ -320,6 +323,7 @@ interface UseApiModuleOptions {
320
323
  staleTime?: number;
321
324
  cacheTime?: number;
322
325
  refetchOnWindowFocus?: boolean;
326
+ pathParams?: Record<string, any>;
323
327
  }
324
328
  interface ActionState<TOutput> {
325
329
  data: TOutput | null;
@@ -327,6 +331,7 @@ interface ActionState<TOutput> {
327
331
  loading: boolean;
328
332
  success: boolean;
329
333
  called: boolean;
334
+ response: StandardResponse<TOutput> | null;
330
335
  }
331
336
  /**
332
337
  * The unified object for a single action, containing its state, executor, and controls.
@@ -378,13 +383,16 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
378
383
  * بالإضافة إلى دوال التحقق من الأنواع (type guards).
379
384
  */
380
385
 
386
+ interface BuildQueryOptions {
387
+ encode?: boolean;
388
+ }
381
389
  /**
382
- * يبني سلسلة استعلام (query string) من كائن خيارات مرن.
383
- * يتعامل مع البارامترات القياسية والمخصصة.
384
- * @param query - كائن من نوع QueryOptions.
390
+ * يبني سلسلة استعلام (query string) من كائن الخيارات.
391
+ * @param options - كائن خيارات الاستعلام (فلترة, ترتيب, ...).
392
+ * @param config - إعدادات إضافية مثل التحكم في التشفير.
385
393
  * @returns سلسلة استعلام جاهزة للإضافة للرابط.
386
394
  */
387
- declare function buildPaginateQuery(query: QueryOptions): string;
395
+ declare function buildPaginateQuery(options: QueryOptions, config?: BuildQueryOptions): string;
388
396
 
389
397
  /**
390
398
  * Defines a single custom API action.
@@ -502,8 +510,17 @@ interface UseApiRecordActions<T> {
502
510
  * @template T The data type of the record.
503
511
  */
504
512
  interface UseApiRecordConfig<T> {
505
- /** The base API endpoint for the resource (e.g., '/users'). */
513
+ /**
514
+ * The base API endpoint template for the resource.
515
+ * Can contain placeholders like `{endpointName}`.
516
+ * @example 'v1/dynamic/{endpointName}'
517
+ */
506
518
  endpoint: string;
519
+ /**
520
+ * An object containing key-value pairs to replace placeholders in the endpoint template.
521
+ * @example { endpointName: 'products' }
522
+ */
523
+ pathParams?: Record<string, string | number>;
507
524
  /** The unique identifier of the record to fetch or modify. */
508
525
  recordId?: string | number | null;
509
526
  /** Optional initial data to populate the state before the first fetch is complete. */
@@ -535,7 +552,7 @@ interface UseApiRecordReturn<T> {
535
552
  /**
536
553
  * A React hook for managing the lifecycle of a single API resource (a record).
537
554
  * It handles fetching, updating, replacing, and deleting a record, while managing
538
- * loading, error, and data states.
555
+ * loading, error, and data states. It supports dynamic path parameters for flexible API routing.
539
556
  *
540
557
  * @template T The data type of the record being managed.
541
558
  * @param {AxiosInstance} axiosInstance - The configured Axios instance for making API calls.
package/dist/index.d.ts CHANGED
@@ -155,8 +155,11 @@ 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;
158
+ /**
159
+ * [NEW] كائن يحتوي على قيم المتغيرات في قالب المسار.
160
+ */
159
161
  pathParams?: Record<string, string | number>;
162
+ encodeQuery?: boolean;
160
163
  /** Callback function executed on a successful action. */
161
164
  onSuccess?: (message: string, data?: T) => void;
162
165
  /** Callback function executed on a failed action. */
@@ -257,7 +260,7 @@ type UseApiState<T> = StandardResponse<T>;
257
260
  * @template T The type of the data entity being managed.
258
261
  */
259
262
  interface UseApiActions<T, TListItem = T extends (infer U)[] ? U : T> {
260
- fetch: () => Promise<void>;
263
+ fetch: (querryOptions?: QueryOptions) => Promise<void>;
261
264
  create: (newItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
262
265
  put: (id: string | number, item: TListItem, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
263
266
  update: (id: string | number, updatedItem: Partial<TListItem>, options?: ActionOptions) => Promise<StandardResponse<TListItem>>;
@@ -320,6 +323,7 @@ interface UseApiModuleOptions {
320
323
  staleTime?: number;
321
324
  cacheTime?: number;
322
325
  refetchOnWindowFocus?: boolean;
326
+ pathParams?: Record<string, any>;
323
327
  }
324
328
  interface ActionState<TOutput> {
325
329
  data: TOutput | null;
@@ -327,6 +331,7 @@ interface ActionState<TOutput> {
327
331
  loading: boolean;
328
332
  success: boolean;
329
333
  called: boolean;
334
+ response: StandardResponse<TOutput> | null;
330
335
  }
331
336
  /**
332
337
  * The unified object for a single action, containing its state, executor, and controls.
@@ -378,13 +383,16 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
378
383
  * بالإضافة إلى دوال التحقق من الأنواع (type guards).
379
384
  */
380
385
 
386
+ interface BuildQueryOptions {
387
+ encode?: boolean;
388
+ }
381
389
  /**
382
- * يبني سلسلة استعلام (query string) من كائن خيارات مرن.
383
- * يتعامل مع البارامترات القياسية والمخصصة.
384
- * @param query - كائن من نوع QueryOptions.
390
+ * يبني سلسلة استعلام (query string) من كائن الخيارات.
391
+ * @param options - كائن خيارات الاستعلام (فلترة, ترتيب, ...).
392
+ * @param config - إعدادات إضافية مثل التحكم في التشفير.
385
393
  * @returns سلسلة استعلام جاهزة للإضافة للرابط.
386
394
  */
387
- declare function buildPaginateQuery(query: QueryOptions): string;
395
+ declare function buildPaginateQuery(options: QueryOptions, config?: BuildQueryOptions): string;
388
396
 
389
397
  /**
390
398
  * Defines a single custom API action.
@@ -502,8 +510,17 @@ interface UseApiRecordActions<T> {
502
510
  * @template T The data type of the record.
503
511
  */
504
512
  interface UseApiRecordConfig<T> {
505
- /** The base API endpoint for the resource (e.g., '/users'). */
513
+ /**
514
+ * The base API endpoint template for the resource.
515
+ * Can contain placeholders like `{endpointName}`.
516
+ * @example 'v1/dynamic/{endpointName}'
517
+ */
506
518
  endpoint: string;
519
+ /**
520
+ * An object containing key-value pairs to replace placeholders in the endpoint template.
521
+ * @example { endpointName: 'products' }
522
+ */
523
+ pathParams?: Record<string, string | number>;
507
524
  /** The unique identifier of the record to fetch or modify. */
508
525
  recordId?: string | number | null;
509
526
  /** Optional initial data to populate the state before the first fetch is complete. */
@@ -535,7 +552,7 @@ interface UseApiRecordReturn<T> {
535
552
  /**
536
553
  * A React hook for managing the lifecycle of a single API resource (a record).
537
554
  * It handles fetching, updating, replacing, and deleting a record, while managing
538
- * loading, error, and data states.
555
+ * loading, error, and data states. It supports dynamic path parameters for flexible API routing.
539
556
  *
540
557
  * @template T The data type of the record being managed.
541
558
  * @param {AxiosInstance} axiosInstance - The configured Axios instance for making API calls.