api-core-lib 12.0.24 → 12.0.26

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.
@@ -253,14 +253,19 @@ type ModuleActions<TActions extends Record<string, ActionConfigModule<any, any>>
253
253
  type ModuleStates<TActions extends Record<string, ActionConfigModule<any, any>>> = {
254
254
  [K in keyof TActions]: ActionState<OutputOf<TActions[K]>>;
255
255
  };
256
- /** @description The complete, fully-typed return object of the `useApiModule` hook. */
256
+ /**
257
+ /** @description The complete, fully-typed return object of the `useApiModule` hook.
258
+ */
259
+ type ActionsWithQuery<TActions extends Record<string, any>> = {
260
+ [K in keyof TActions]: TActions[K] extends {
261
+ hasQuery: true;
262
+ } ? K : never;
263
+ }[keyof TActions];
257
264
  type UseApiModuleReturn<TActions extends Record<string, any>, TExtra = {}> = {
258
265
  states: ModuleStates<TActions>;
259
266
  actions: ModuleActions<TActions>;
260
267
  queries: {
261
- [K in keyof TActions]?: TActions[K] extends {
262
- hasQuery: true;
263
- } ? UseApiQuery : never;
268
+ [K in ActionsWithQuery<TActions>]: UseApiQuery;
264
269
  };
265
270
  dehydrate: () => string;
266
271
  } & TExtra;
@@ -282,4 +287,4 @@ type ActionMethods<TAction extends ActionConfigModule<any, any>> = {
282
287
  }) => void;
283
288
  };
284
289
 
285
- export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e, ApiClientConfig as f, ActionOptions as g, ActionStateModule as h, ApiError as i, TokenManager as j, MiddlewareContext as k, Middleware as l, RefreshTokenConfig as m, ActionConfig as n, UseApiState as o, ActionState as p, ExecuteOptions as q, ActionMethods as r, t };
290
+ export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e, ApiClientConfig as f, ActionOptions as g, ActionStateModule as h, ApiError as i, TokenManager as j, MiddlewareContext as k, Middleware as l, RefreshTokenConfig as m, ActionConfig as n, UseApiState as o, ActionState as p, ExecuteOptions as q, ActionsWithQuery as r, ActionMethods as s, t };
@@ -253,14 +253,19 @@ type ModuleActions<TActions extends Record<string, ActionConfigModule<any, any>>
253
253
  type ModuleStates<TActions extends Record<string, ActionConfigModule<any, any>>> = {
254
254
  [K in keyof TActions]: ActionState<OutputOf<TActions[K]>>;
255
255
  };
256
- /** @description The complete, fully-typed return object of the `useApiModule` hook. */
256
+ /**
257
+ /** @description The complete, fully-typed return object of the `useApiModule` hook.
258
+ */
259
+ type ActionsWithQuery<TActions extends Record<string, any>> = {
260
+ [K in keyof TActions]: TActions[K] extends {
261
+ hasQuery: true;
262
+ } ? K : never;
263
+ }[keyof TActions];
257
264
  type UseApiModuleReturn<TActions extends Record<string, any>, TExtra = {}> = {
258
265
  states: ModuleStates<TActions>;
259
266
  actions: ModuleActions<TActions>;
260
267
  queries: {
261
- [K in keyof TActions]?: TActions[K] extends {
262
- hasQuery: true;
263
- } ? UseApiQuery : never;
268
+ [K in ActionsWithQuery<TActions>]: UseApiQuery;
264
269
  };
265
270
  dehydrate: () => string;
266
271
  } & TExtra;
@@ -282,4 +287,4 @@ type ActionMethods<TAction extends ActionConfigModule<any, any>> = {
282
287
  }) => void;
283
288
  };
284
289
 
285
- export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e, ApiClientConfig as f, ActionOptions as g, ActionStateModule as h, ApiError as i, TokenManager as j, MiddlewareContext as k, Middleware as l, RefreshTokenConfig as m, ActionConfig as n, UseApiState as o, ActionState as p, ExecuteOptions as q, ActionMethods as r, t };
290
+ export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e, ApiClientConfig as f, ActionOptions as g, ActionStateModule as h, ApiError as i, TokenManager as j, MiddlewareContext as k, Middleware as l, RefreshTokenConfig as m, ActionConfig as n, UseApiState as o, ActionState as p, ExecuteOptions as q, ActionsWithQuery as r, ActionMethods as s, t };
package/dist/client.cjs CHANGED
@@ -872,18 +872,28 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
872
872
  return builtQueries;
873
873
  }, [queryOptions, moduleConfig.actions]);
874
874
  const states = {};
875
+ function isActionWithQuery(key, actions2) {
876
+ return actions2[key]?.hasQuery === true;
877
+ }
875
878
  for (const actionName in moduleConfig.actions) {
876
879
  if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
877
880
  const actionConfig = moduleConfig.actions[actionName];
878
881
  if (actionConfig.cacheResponse !== false) {
879
- const query = queries[actionName]?.options;
880
- const input = actionConfig.hasQuery ? query : void 0;
882
+ let queryOptions2;
883
+ if (isActionWithQuery(actionName, moduleConfig.actions)) {
884
+ queryOptions2 = queries[actionName]?.options;
885
+ }
886
+ const input = queryOptions2;
881
887
  const pathParams = JSON.parse(pathParamsString);
882
- const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
888
+ const cacheKey = generateCacheKey(
889
+ moduleConfig.baseEndpoint,
890
+ actionName,
891
+ input,
892
+ { pathParams }
893
+ );
883
894
  states[actionName] = useApiActionState(
884
895
  actionConfig,
885
896
  cacheKey,
886
- // [تصحيح] مرر `execute` مباشرة
887
897
  actions[actionName].execute,
888
898
  input,
889
899
  enabled
package/dist/client.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery } from './apiModule.types-B_MxXat3.cjs';
3
- import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-A-m0WKKh.cjs';
2
+ import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery } from './apiModule.types-Bn0tJF7b.cjs';
3
+ import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-NZtPRga3.cjs';
4
4
  import * as React from 'react';
5
5
 
6
6
  declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
@@ -25,7 +25,7 @@ declare const ApiModuleProvider: React.Provider<{
25
25
  states: ModuleStates<any>;
26
26
  actions: ModuleActions<any>;
27
27
  queries: {
28
- [x: string]: UseApiQuery | undefined;
28
+ [x: string]: UseApiQuery;
29
29
  };
30
30
  dehydrate: () => string;
31
31
  } | null>;
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery } from './apiModule.types-B_MxXat3.js';
3
- import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-BgjdqOHw.js';
2
+ import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery } from './apiModule.types-Bn0tJF7b.js';
3
+ import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-CWhwCAB6.js';
4
4
  import * as React from 'react';
5
5
 
6
6
  declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
@@ -25,7 +25,7 @@ declare const ApiModuleProvider: React.Provider<{
25
25
  states: ModuleStates<any>;
26
26
  actions: ModuleActions<any>;
27
27
  queries: {
28
- [x: string]: UseApiQuery | undefined;
28
+ [x: string]: UseApiQuery;
29
29
  };
30
30
  dehydrate: () => string;
31
31
  } | null>;
package/dist/client.js CHANGED
@@ -833,18 +833,28 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
833
833
  return builtQueries;
834
834
  }, [queryOptions, moduleConfig.actions]);
835
835
  const states = {};
836
+ function isActionWithQuery(key, actions2) {
837
+ return actions2[key]?.hasQuery === true;
838
+ }
836
839
  for (const actionName in moduleConfig.actions) {
837
840
  if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
838
841
  const actionConfig = moduleConfig.actions[actionName];
839
842
  if (actionConfig.cacheResponse !== false) {
840
- const query = queries[actionName]?.options;
841
- const input = actionConfig.hasQuery ? query : void 0;
843
+ let queryOptions2;
844
+ if (isActionWithQuery(actionName, moduleConfig.actions)) {
845
+ queryOptions2 = queries[actionName]?.options;
846
+ }
847
+ const input = queryOptions2;
842
848
  const pathParams = JSON.parse(pathParamsString);
843
- const cacheKey = generateCacheKey(moduleConfig.baseEndpoint, actionName, input, { pathParams });
849
+ const cacheKey = generateCacheKey(
850
+ moduleConfig.baseEndpoint,
851
+ actionName,
852
+ input,
853
+ { pathParams }
854
+ );
844
855
  states[actionName] = useApiActionState(
845
856
  actionConfig,
846
857
  cacheKey,
847
- // [تصحيح] مرر `execute` مباشرة
848
858
  actions[actionName].execute,
849
859
  input,
850
860
  enabled
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, e as UseApiQuery, i as ApiError, L as LogLevel } from './apiModule.types-B_MxXat3.cjs';
3
- export { n as ActionConfig, r as ActionMethods, p as ActionState, a as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-B_MxXat3.cjs';
4
- export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-A-m0WKKh.cjs';
2
+ import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, e as UseApiQuery, i as ApiError, L as LogLevel } from './apiModule.types-Bn0tJF7b.cjs';
3
+ export { n as ActionConfig, s as ActionMethods, p as ActionState, r as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-Bn0tJF7b.cjs';
4
+ export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-NZtPRga3.cjs';
5
5
  import 'react';
6
6
 
7
7
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, e as UseApiQuery, i as ApiError, L as LogLevel } from './apiModule.types-B_MxXat3.js';
3
- export { n as ActionConfig, r as ActionMethods, p as ActionState, a as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-B_MxXat3.js';
4
- export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-BgjdqOHw.js';
2
+ import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, e as UseApiQuery, i as ApiError, L as LogLevel } from './apiModule.types-Bn0tJF7b.js';
3
+ export { n as ActionConfig, s as ActionMethods, p as ActionState, r as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-Bn0tJF7b.js';
4
+ export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-CWhwCAB6.js';
5
5
  import 'react';
6
6
 
7
7
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-B_MxXat3.cjs';
2
+ import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-Bn0tJF7b.cjs';
3
3
  import 'react';
4
4
 
5
5
  /**
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-B_MxXat3.js';
2
+ import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-Bn0tJF7b.js';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- import { R as RequestConfig, i as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-B_MxXat3.js';
2
+ import { R as RequestConfig, i as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-Bn0tJF7b.js';
3
3
 
4
4
  /**
5
5
  * Represents the internal state of the `useApiRecord` hook.
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- import { R as RequestConfig, i as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-B_MxXat3.cjs';
2
+ import { R as RequestConfig, i as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-Bn0tJF7b.cjs';
3
3
 
4
4
  /**
5
5
  * Represents the internal state of the `useApiRecord` hook.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.24",
3
+ "version": "12.0.26",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
 
@@ -25,7 +25,9 @@
25
25
  "main": "./dist/index.cjs",
26
26
  "module": "./dist/index.js",
27
27
  "types": "./dist/index.d.ts",
28
-
28
+ "bin": {
29
+ "api-core-generate": "./dist/cli.js"
30
+ },
29
31
  "scripts": {
30
32
  "build": "tsup",
31
33
  "dev": "tsup --watch"
@@ -42,7 +44,12 @@
42
44
  "colorette": "^2.0.20",
43
45
  "fast-deep-equal": "^3.1.3",
44
46
  "path": "^0.12.7",
45
- "uuid": "^9.0.1"
47
+ "uuid": "^9.0.1",
48
+
49
+ "chalk": "^4.1.2",
50
+ "commander": "^9.4.1",
51
+ "dotenv": "^16.0.3",
52
+ "openapi-typescript": "^6.2.4"
46
53
  },
47
54
 
48
55
  "devDependencies": {