@kubb/plugin-client 0.0.0-canary-20241214001945 → 0.0.0-canary-20250108203132

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.
Files changed (48) hide show
  1. package/dist/{chunk-UIFBYWMG.js → chunk-7JWZVEC4.js} +35 -11
  2. package/dist/chunk-7JWZVEC4.js.map +1 -0
  3. package/dist/{chunk-TX2PSIPH.cjs → chunk-FO6GU3BS.cjs} +37 -13
  4. package/dist/chunk-FO6GU3BS.cjs.map +1 -0
  5. package/dist/{chunk-4OXWRJFQ.cjs → chunk-GUUH6APU.cjs} +43 -13
  6. package/dist/chunk-GUUH6APU.cjs.map +1 -0
  7. package/dist/{chunk-3WVVUCEB.js → chunk-HVZSAZQR.js} +44 -15
  8. package/dist/chunk-HVZSAZQR.js.map +1 -0
  9. package/dist/clients/axios.cjs.map +1 -1
  10. package/dist/clients/axios.d.cts +4 -3
  11. package/dist/clients/axios.d.ts +4 -3
  12. package/dist/clients/axios.js.map +1 -1
  13. package/dist/clients/fetch.cjs +9 -2
  14. package/dist/clients/fetch.cjs.map +1 -1
  15. package/dist/clients/fetch.d.cts +5 -4
  16. package/dist/clients/fetch.d.ts +5 -4
  17. package/dist/clients/fetch.js +9 -2
  18. package/dist/clients/fetch.js.map +1 -1
  19. package/dist/components.cjs +7 -3
  20. package/dist/components.d.cts +32 -7
  21. package/dist/components.d.ts +32 -7
  22. package/dist/components.js +1 -1
  23. package/dist/generators.cjs +5 -5
  24. package/dist/generators.js +2 -2
  25. package/dist/index.cjs +4 -4
  26. package/dist/index.js +2 -2
  27. package/package.json +11 -11
  28. package/src/clients/axios.ts +3 -1
  29. package/src/clients/fetch.ts +15 -4
  30. package/src/components/Client.tsx +20 -13
  31. package/src/components/Url.tsx +68 -0
  32. package/src/components/index.ts +1 -0
  33. package/src/generators/__snapshots__/deletePet.ts +7 -3
  34. package/src/generators/__snapshots__/deletePetObject.ts +7 -3
  35. package/src/generators/__snapshots__/findByTags.ts +11 -2
  36. package/src/generators/__snapshots__/findByTagsFull.ts +11 -2
  37. package/src/generators/__snapshots__/findByTagsObject.ts +11 -2
  38. package/src/generators/__snapshots__/findByTagsWithZod.ts +11 -2
  39. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +11 -2
  40. package/src/generators/__snapshots__/importPath.ts +11 -2
  41. package/src/generators/__snapshots__/updatePetById.ts +11 -2
  42. package/src/generators/clientGenerator.tsx +18 -1
  43. package/src/generators/groupedClientGenerator.tsx +5 -5
  44. package/src/plugin.ts +9 -2
  45. package/dist/chunk-3WVVUCEB.js.map +0 -1
  46. package/dist/chunk-4OXWRJFQ.cjs.map +0 -1
  47. package/dist/chunk-TX2PSIPH.cjs.map +0 -1
  48. package/dist/chunk-UIFBYWMG.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import * as axios from 'axios';
2
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
3
3
 
4
4
  /**
5
5
  * Subset of AxiosRequestConfig
@@ -21,8 +21,9 @@ type ResponseConfig<TData = unknown> = {
21
21
  data: TData;
22
22
  status: number;
23
23
  statusText: string;
24
- headers?: AxiosResponse['headers'];
24
+ headers: AxiosResponse['headers'];
25
25
  };
26
+ type ResponseErrorConfig<TError = unknown> = AxiosError<TError>;
26
27
  declare const getConfig: () => Partial<RequestConfig<unknown>>;
27
28
  declare const setConfig: (config: RequestConfig) => Partial<RequestConfig<unknown>>;
28
29
  declare const axiosInstance: axios.AxiosInstance;
@@ -32,4 +33,4 @@ declare const axiosClient: {
32
33
  setConfig: (config: RequestConfig) => Partial<RequestConfig<unknown>>;
33
34
  };
34
35
 
35
- export { type RequestConfig, type ResponseConfig, axiosClient, axiosInstance, axiosClient as default, getConfig, setConfig };
36
+ export { type RequestConfig, type ResponseConfig, type ResponseErrorConfig, axiosClient, axiosInstance, axiosClient as default, getConfig, setConfig };
@@ -1,5 +1,5 @@
1
1
  import * as axios from 'axios';
2
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
3
3
 
4
4
  /**
5
5
  * Subset of AxiosRequestConfig
@@ -21,8 +21,9 @@ type ResponseConfig<TData = unknown> = {
21
21
  data: TData;
22
22
  status: number;
23
23
  statusText: string;
24
- headers?: AxiosResponse['headers'];
24
+ headers: AxiosResponse['headers'];
25
25
  };
26
+ type ResponseErrorConfig<TError = unknown> = AxiosError<TError>;
26
27
  declare const getConfig: () => Partial<RequestConfig<unknown>>;
27
28
  declare const setConfig: (config: RequestConfig) => Partial<RequestConfig<unknown>>;
28
29
  declare const axiosInstance: axios.AxiosInstance;
@@ -32,4 +33,4 @@ declare const axiosClient: {
32
33
  setConfig: (config: RequestConfig) => Partial<RequestConfig<unknown>>;
33
34
  };
34
35
 
35
- export { type RequestConfig, type ResponseConfig, axiosClient, axiosInstance, axiosClient as default, getConfig, setConfig };
36
+ export { type RequestConfig, type ResponseConfig, type ResponseErrorConfig, axiosClient, axiosInstance, axiosClient as default, getConfig, setConfig };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/clients/axios.ts"],"names":[],"mappings":";;;AA8BA,IAAI,OAAkC,GAAA;AAAA,EACpC,OAAS,EAAA,OAAO,UAAe,KAAA,WAAA,GAAc,UAAa,GAAA,KAAA,CAAA;AAAA,EAC1D,SAAS,OAAO,aAAA,KAAkB,cAAe,IAAK,CAAA,KAAA,CAAM,aAAa,CAAqB,GAAA,KAAA;AAChG,CAAA;AAEO,IAAM,YAAY,MAAM;AAElB,IAAA,SAAA,GAAY,CAAC,MAA0B,KAAA;AAClD,EAAU,OAAA,GAAA,MAAA;AACV,EAAA,OAAO,SAAU,EAAA;AACnB;AAEO,IAAM,aAAgB,GAAA,KAAA,CAAM,MAAO,CAAA,SAAA,EAAW;AAExC,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAA,MAAM,eAAe,SAAU,EAAA;AAE/B,EAAA,OAAO,cACJ,OAAsC,CAAA;AAAA,IACrC,GAAG,YAAA;AAAA,IACH,GAAG,MAAA;AAAA,IACH,OAAS,EAAA;AAAA,MACP,GAAG,YAAa,CAAA,OAAA;AAAA,MAChB,GAAG,MAAO,CAAA;AAAA;AACZ,GACD,CAAA,CACA,KAAM,CAAA,CAAC,CAA0B,KAAA;AAChC,IAAM,MAAA,CAAA;AAAA,GACP,CAAA;AACL;AAEA,WAAA,CAAY,SAAY,GAAA,SAAA;AACxB,WAAA,CAAY,SAAY,GAAA,SAAA;AAExB,IAAO,aAAQ,GAAA","file":"axios.js","sourcesContent":["import axios from 'axios'\n\nimport type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios'\n\ndeclare const AXIOS_BASE: string\ndeclare const AXIOS_HEADERS: string\n\n/**\n * Subset of AxiosRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n headers?: AxiosRequestConfig['headers']\n}\n/**\n * Subset of AxiosResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers?: AxiosResponse['headers']\n}\n\nlet _config: Partial<RequestConfig> = {\n baseURL: typeof AXIOS_BASE !== 'undefined' ? AXIOS_BASE : undefined,\n headers: typeof AXIOS_HEADERS !== 'undefined' ? (JSON.parse(AXIOS_HEADERS) as AxiosHeaders) : undefined,\n}\n\nexport const getConfig = () => _config\n\nexport const setConfig = (config: RequestConfig) => {\n _config = config\n return getConfig()\n}\n\nexport const axiosInstance = axios.create(getConfig())\n\nexport const axiosClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const globalConfig = getConfig()\n\n return axiosInstance\n .request<TData, ResponseConfig<TData>>({\n ...globalConfig,\n ...config,\n headers: {\n ...globalConfig.headers,\n ...config.headers,\n },\n })\n .catch((e: AxiosError<TError>) => {\n throw e\n })\n}\n\naxiosClient.getConfig = getConfig\naxiosClient.setConfig = setConfig\n\nexport default axiosClient\n"]}
1
+ {"version":3,"sources":["../../src/clients/axios.ts"],"names":[],"mappings":";;;AAgCA,IAAI,OAAkC,GAAA;AAAA,EACpC,OAAS,EAAA,OAAO,UAAe,KAAA,WAAA,GAAc,UAAa,GAAA,KAAA,CAAA;AAAA,EAC1D,SAAS,OAAO,aAAA,KAAkB,cAAe,IAAK,CAAA,KAAA,CAAM,aAAa,CAAqB,GAAA,KAAA;AAChG,CAAA;AAEO,IAAM,YAAY,MAAM;AAElB,IAAA,SAAA,GAAY,CAAC,MAA0B,KAAA;AAClD,EAAU,OAAA,GAAA,MAAA;AACV,EAAA,OAAO,SAAU,EAAA;AACnB;AAEO,IAAM,aAAgB,GAAA,KAAA,CAAM,MAAO,CAAA,SAAA,EAAW;AAExC,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAA,MAAM,eAAe,SAAU,EAAA;AAE/B,EAAA,OAAO,cACJ,OAAsC,CAAA;AAAA,IACrC,GAAG,YAAA;AAAA,IACH,GAAG,MAAA;AAAA,IACH,OAAS,EAAA;AAAA,MACP,GAAG,YAAa,CAAA,OAAA;AAAA,MAChB,GAAG,MAAO,CAAA;AAAA;AACZ,GACD,CAAA,CACA,KAAM,CAAA,CAAC,CAA0B,KAAA;AAChC,IAAM,MAAA,CAAA;AAAA,GACP,CAAA;AACL;AAEA,WAAA,CAAY,SAAY,GAAA,SAAA;AACxB,WAAA,CAAY,SAAY,GAAA,SAAA;AAExB,IAAO,aAAQ,GAAA","file":"axios.js","sourcesContent":["import axios from 'axios'\n\nimport type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios'\n\ndeclare const AXIOS_BASE: string\ndeclare const AXIOS_HEADERS: string\n\n/**\n * Subset of AxiosRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n headers?: AxiosRequestConfig['headers']\n}\n/**\n * Subset of AxiosResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers: AxiosResponse['headers']\n}\n\nexport type ResponseErrorConfig<TError = unknown> = AxiosError<TError>\n\nlet _config: Partial<RequestConfig> = {\n baseURL: typeof AXIOS_BASE !== 'undefined' ? AXIOS_BASE : undefined,\n headers: typeof AXIOS_HEADERS !== 'undefined' ? (JSON.parse(AXIOS_HEADERS) as AxiosHeaders) : undefined,\n}\n\nexport const getConfig = () => _config\n\nexport const setConfig = (config: RequestConfig) => {\n _config = config\n return getConfig()\n}\n\nexport const axiosInstance = axios.create(getConfig())\n\nexport const axiosClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const globalConfig = getConfig()\n\n return axiosInstance\n .request<TData, ResponseConfig<TData>>({\n ...globalConfig,\n ...config,\n headers: {\n ...globalConfig.headers,\n ...config.headers,\n },\n })\n .catch((e: AxiosError<TError>) => {\n throw e\n })\n}\n\naxiosClient.getConfig = getConfig\naxiosClient.setConfig = setConfig\n\nexport default axiosClient\n"]}
@@ -4,7 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  // src/clients/fetch.ts
6
6
  var fetchClient = async (config) => {
7
- const response = await fetch("https://example.org/post", {
7
+ const url = new URL(config.url || "", config.baseURL ? new URL(config.baseURL) : void 0);
8
+ Object.entries(config.params || {}).forEach(([key, value]) => {
9
+ if (value !== void 0) {
10
+ url.searchParams.append(key, value === null ? "null" : value.toString());
11
+ }
12
+ });
13
+ const response = await fetch(url.toString(), {
8
14
  method: config.method.toUpperCase(),
9
15
  body: JSON.stringify(config.data),
10
16
  signal: config.signal,
@@ -14,7 +20,8 @@ var fetchClient = async (config) => {
14
20
  return {
15
21
  data,
16
22
  status: response.status,
17
- statusText: response.statusText
23
+ statusText: response.statusText,
24
+ headers: response.headers
18
25
  };
19
26
  };
20
27
  fetchClient.getConfig = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/clients/fetch.ts"],"names":[],"mappings":";;;;;AAuBa,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAM,MAAA,QAAA,GAAW,MAAM,KAAA,CAAM,0BAA4B,EAAA;AAAA,IACvD,MAAA,EAAQ,MAAO,CAAA,MAAA,CAAO,WAAY,EAAA;AAAA,IAClC,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA,IAChC,QAAQ,MAAO,CAAA,MAAA;AAAA,IACf,SAAS,MAAO,CAAA;AAAA,GACjB,CAAA;AAED,EAAM,MAAA,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAK,EAAA;AAElC,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,QAAQ,QAAS,CAAA,MAAA;AAAA,IACjB,YAAY,QAAS,CAAA;AAAA,GACvB;AACF;AAEA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AACA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AAEA,IAAO,aAAQ,GAAA","file":"fetch.cjs","sourcesContent":["/**\n * Subset of AxiosRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n headers?: [string, string][] | Record<string, string>\n}\n/**\n * Subset of AxiosResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers?: [string, string][] | Record<string, string>\n}\n\nexport const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const response = await fetch('https://example.org/post', {\n method: config.method.toUpperCase(),\n body: JSON.stringify(config.data),\n signal: config.signal,\n headers: config.headers,\n })\n\n const data = (await response.json()) as TData\n\n return {\n data,\n status: response.status,\n statusText: response.statusText,\n }\n}\n\nfetchClient.getConfig = () => {\n throw new Error('Not supported')\n}\nfetchClient.setConfig = () => {\n throw new Error('Not supported')\n}\n\nexport default fetchClient\n"]}
1
+ {"version":3,"sources":["../../src/clients/fetch.ts"],"names":[],"mappings":";;;;;AAyBa,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAA,MAAM,GAAM,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,GAAO,IAAA,EAAA,EAAI,MAAO,CAAA,OAAA,GAAU,IAAI,GAAA,CAAI,MAAO,CAAA,OAAO,IAAI,KAAS,CAAA,CAAA;AAE1F,EAAO,MAAA,CAAA,OAAA,CAAQ,MAAO,CAAA,MAAA,IAAU,EAAE,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAC,GAAK,EAAA,KAAK,CAAM,KAAA;AAC5D,IAAA,IAAI,UAAU,KAAW,CAAA,EAAA;AACvB,MAAI,GAAA,CAAA,YAAA,CAAa,OAAO,GAAK,EAAA,KAAA,KAAU,OAAO,MAAS,GAAA,KAAA,CAAM,UAAU,CAAA;AAAA;AACzE,GACD,CAAA;AAED,EAAA,MAAM,QAAW,GAAA,MAAM,KAAM,CAAA,GAAA,CAAI,UAAY,EAAA;AAAA,IAC3C,MAAA,EAAQ,MAAO,CAAA,MAAA,CAAO,WAAY,EAAA;AAAA,IAClC,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA,IAChC,QAAQ,MAAO,CAAA,MAAA;AAAA,IACf,SAAS,MAAO,CAAA;AAAA,GACjB,CAAA;AAED,EAAM,MAAA,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAK,EAAA;AAElC,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,QAAQ,QAAS,CAAA,MAAA;AAAA,IACjB,YAAY,QAAS,CAAA,UAAA;AAAA,IACrB,SAAS,QAAS,CAAA;AAAA,GACpB;AACF;AAEA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AACA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AAEA,IAAO,aAAQ,GAAA","file":"fetch.cjs","sourcesContent":["/**\n * Subset of FetchRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n headers?: [string, string][] | Record<string, string>\n}\n/**\n * Subset of FetchResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers: Headers\n}\n\nexport type ResponseErrorConfig<TError = unknown> = TError\n\nexport const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const url = new URL(config.url || '', config.baseURL ? new URL(config.baseURL) : undefined)\n\n Object.entries(config.params || {}).forEach(([key, value]) => {\n if (value !== undefined) {\n url.searchParams.append(key, value === null ? 'null' : value.toString())\n }\n })\n\n const response = await fetch(url.toString(), {\n method: config.method.toUpperCase(),\n body: JSON.stringify(config.data),\n signal: config.signal,\n headers: config.headers,\n })\n\n const data = (await response.json()) as TData\n\n return {\n data,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers as Headers,\n }\n}\n\nfetchClient.getConfig = () => {\n throw new Error('Not supported')\n}\nfetchClient.setConfig = () => {\n throw new Error('Not supported')\n}\n\nexport default fetchClient\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Subset of AxiosRequestConfig
2
+ * Subset of FetchRequestConfig
3
3
  */
4
4
  type RequestConfig<TData = unknown> = {
5
5
  baseURL?: string;
@@ -12,18 +12,19 @@ type RequestConfig<TData = unknown> = {
12
12
  headers?: [string, string][] | Record<string, string>;
13
13
  };
14
14
  /**
15
- * Subset of AxiosResponse
15
+ * Subset of FetchResponse
16
16
  */
17
17
  type ResponseConfig<TData = unknown> = {
18
18
  data: TData;
19
19
  status: number;
20
20
  statusText: string;
21
- headers?: [string, string][] | Record<string, string>;
21
+ headers: Headers;
22
22
  };
23
+ type ResponseErrorConfig<TError = unknown> = TError;
23
24
  declare const fetchClient: {
24
25
  <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>>;
25
26
  getConfig(): never;
26
27
  setConfig(): never;
27
28
  };
28
29
 
29
- export { type RequestConfig, type ResponseConfig, fetchClient as default, fetchClient };
30
+ export { type RequestConfig, type ResponseConfig, type ResponseErrorConfig, fetchClient as default, fetchClient };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Subset of AxiosRequestConfig
2
+ * Subset of FetchRequestConfig
3
3
  */
4
4
  type RequestConfig<TData = unknown> = {
5
5
  baseURL?: string;
@@ -12,18 +12,19 @@ type RequestConfig<TData = unknown> = {
12
12
  headers?: [string, string][] | Record<string, string>;
13
13
  };
14
14
  /**
15
- * Subset of AxiosResponse
15
+ * Subset of FetchResponse
16
16
  */
17
17
  type ResponseConfig<TData = unknown> = {
18
18
  data: TData;
19
19
  status: number;
20
20
  statusText: string;
21
- headers?: [string, string][] | Record<string, string>;
21
+ headers: Headers;
22
22
  };
23
+ type ResponseErrorConfig<TError = unknown> = TError;
23
24
  declare const fetchClient: {
24
25
  <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>>;
25
26
  getConfig(): never;
26
27
  setConfig(): never;
27
28
  };
28
29
 
29
- export { type RequestConfig, type ResponseConfig, fetchClient as default, fetchClient };
30
+ export { type RequestConfig, type ResponseConfig, type ResponseErrorConfig, fetchClient as default, fetchClient };
@@ -1,6 +1,12 @@
1
1
  // src/clients/fetch.ts
2
2
  var fetchClient = async (config) => {
3
- const response = await fetch("https://example.org/post", {
3
+ const url = new URL(config.url || "", config.baseURL ? new URL(config.baseURL) : void 0);
4
+ Object.entries(config.params || {}).forEach(([key, value]) => {
5
+ if (value !== void 0) {
6
+ url.searchParams.append(key, value === null ? "null" : value.toString());
7
+ }
8
+ });
9
+ const response = await fetch(url.toString(), {
4
10
  method: config.method.toUpperCase(),
5
11
  body: JSON.stringify(config.data),
6
12
  signal: config.signal,
@@ -10,7 +16,8 @@ var fetchClient = async (config) => {
10
16
  return {
11
17
  data,
12
18
  status: response.status,
13
- statusText: response.statusText
19
+ statusText: response.statusText,
20
+ headers: response.headers
14
21
  };
15
22
  };
16
23
  fetchClient.getConfig = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/clients/fetch.ts"],"names":[],"mappings":";AAuBa,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAM,MAAA,QAAA,GAAW,MAAM,KAAA,CAAM,0BAA4B,EAAA;AAAA,IACvD,MAAA,EAAQ,MAAO,CAAA,MAAA,CAAO,WAAY,EAAA;AAAA,IAClC,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA,IAChC,QAAQ,MAAO,CAAA,MAAA;AAAA,IACf,SAAS,MAAO,CAAA;AAAA,GACjB,CAAA;AAED,EAAM,MAAA,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAK,EAAA;AAElC,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,QAAQ,QAAS,CAAA,MAAA;AAAA,IACjB,YAAY,QAAS,CAAA;AAAA,GACvB;AACF;AAEA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AACA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AAEA,IAAO,aAAQ,GAAA","file":"fetch.js","sourcesContent":["/**\n * Subset of AxiosRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n headers?: [string, string][] | Record<string, string>\n}\n/**\n * Subset of AxiosResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers?: [string, string][] | Record<string, string>\n}\n\nexport const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const response = await fetch('https://example.org/post', {\n method: config.method.toUpperCase(),\n body: JSON.stringify(config.data),\n signal: config.signal,\n headers: config.headers,\n })\n\n const data = (await response.json()) as TData\n\n return {\n data,\n status: response.status,\n statusText: response.statusText,\n }\n}\n\nfetchClient.getConfig = () => {\n throw new Error('Not supported')\n}\nfetchClient.setConfig = () => {\n throw new Error('Not supported')\n}\n\nexport default fetchClient\n"]}
1
+ {"version":3,"sources":["../../src/clients/fetch.ts"],"names":[],"mappings":";AAyBa,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAA,MAAM,GAAM,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,GAAO,IAAA,EAAA,EAAI,MAAO,CAAA,OAAA,GAAU,IAAI,GAAA,CAAI,MAAO,CAAA,OAAO,IAAI,KAAS,CAAA,CAAA;AAE1F,EAAO,MAAA,CAAA,OAAA,CAAQ,MAAO,CAAA,MAAA,IAAU,EAAE,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAC,GAAK,EAAA,KAAK,CAAM,KAAA;AAC5D,IAAA,IAAI,UAAU,KAAW,CAAA,EAAA;AACvB,MAAI,GAAA,CAAA,YAAA,CAAa,OAAO,GAAK,EAAA,KAAA,KAAU,OAAO,MAAS,GAAA,KAAA,CAAM,UAAU,CAAA;AAAA;AACzE,GACD,CAAA;AAED,EAAA,MAAM,QAAW,GAAA,MAAM,KAAM,CAAA,GAAA,CAAI,UAAY,EAAA;AAAA,IAC3C,MAAA,EAAQ,MAAO,CAAA,MAAA,CAAO,WAAY,EAAA;AAAA,IAClC,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA,IAChC,QAAQ,MAAO,CAAA,MAAA;AAAA,IACf,SAAS,MAAO,CAAA;AAAA,GACjB,CAAA;AAED,EAAM,MAAA,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAK,EAAA;AAElC,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,QAAQ,QAAS,CAAA,MAAA;AAAA,IACjB,YAAY,QAAS,CAAA,UAAA;AAAA,IACrB,SAAS,QAAS,CAAA;AAAA,GACpB;AACF;AAEA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AACA,WAAA,CAAY,YAAY,MAAM;AAC5B,EAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AACjC,CAAA;AAEA,IAAO,aAAQ,GAAA","file":"fetch.js","sourcesContent":["/**\n * Subset of FetchRequestConfig\n */\nexport type RequestConfig<TData = unknown> = {\n baseURL?: string\n url?: string\n method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'\n params?: unknown\n data?: TData | FormData\n responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n signal?: AbortSignal\n headers?: [string, string][] | Record<string, string>\n}\n/**\n * Subset of FetchResponse\n */\nexport type ResponseConfig<TData = unknown> = {\n data: TData\n status: number\n statusText: string\n headers: Headers\n}\n\nexport type ResponseErrorConfig<TError = unknown> = TError\n\nexport const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {\n const url = new URL(config.url || '', config.baseURL ? new URL(config.baseURL) : undefined)\n\n Object.entries(config.params || {}).forEach(([key, value]) => {\n if (value !== undefined) {\n url.searchParams.append(key, value === null ? 'null' : value.toString())\n }\n })\n\n const response = await fetch(url.toString(), {\n method: config.method.toUpperCase(),\n body: JSON.stringify(config.data),\n signal: config.signal,\n headers: config.headers,\n })\n\n const data = (await response.json()) as TData\n\n return {\n data,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers as Headers,\n }\n}\n\nfetchClient.getConfig = () => {\n throw new Error('Not supported')\n}\nfetchClient.setConfig = () => {\n throw new Error('Not supported')\n}\n\nexport default fetchClient\n"]}
@@ -1,16 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var chunk4OXWRJFQ_cjs = require('./chunk-4OXWRJFQ.cjs');
3
+ var chunkGUUH6APU_cjs = require('./chunk-GUUH6APU.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "Client", {
8
8
  enumerable: true,
9
- get: function () { return chunk4OXWRJFQ_cjs.Client; }
9
+ get: function () { return chunkGUUH6APU_cjs.Client; }
10
10
  });
11
11
  Object.defineProperty(exports, "Operations", {
12
12
  enumerable: true,
13
- get: function () { return chunk4OXWRJFQ_cjs.Operations; }
13
+ get: function () { return chunkGUUH6APU_cjs.Operations; }
14
+ });
15
+ Object.defineProperty(exports, "Url", {
16
+ enumerable: true,
17
+ get: function () { return chunkGUUH6APU_cjs.Url; }
14
18
  });
15
19
  //# sourceMappingURL=components.cjs.map
16
20
  //# sourceMappingURL=components.cjs.map
@@ -1,15 +1,15 @@
1
1
  import { Operation } from '@kubb/oas';
2
2
  import { OperationSchemas } from '@kubb/plugin-oas';
3
3
  import { FunctionParams } from '@kubb/react';
4
- import { KubbNode } from '@kubb/react/types';
5
4
  import { P as PluginClient } from './types-P398e_Yv.cjs';
6
5
  import '@kubb/core';
7
6
 
8
- type Props = {
7
+ type Props$1 = {
9
8
  /**
10
9
  * Name of the function
11
10
  */
12
11
  name: string;
12
+ urlName?: string;
13
13
  isExportable?: boolean;
14
14
  isIndexable?: boolean;
15
15
  baseURL: string | undefined;
@@ -22,21 +22,46 @@ type Props = {
22
22
  zodSchemas: OperationSchemas | undefined;
23
23
  operation: Operation;
24
24
  };
25
- type GetParamsProps = {
25
+ type GetParamsProps$1 = {
26
26
  paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
27
27
  paramsType: PluginClient['resolvedOptions']['paramsType'];
28
28
  pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
29
29
  typeSchemas: OperationSchemas;
30
30
  };
31
- declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, }: Props): KubbNode;
31
+ declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, }: Props$1): any;
32
32
  declare namespace Client {
33
- var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) => FunctionParams;
33
+ var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
34
34
  }
35
35
 
36
36
  type OperationsProps = {
37
37
  name: string;
38
38
  operations: Array<Operation>;
39
39
  };
40
- declare function Operations({ name, operations }: OperationsProps): JSX.Element;
40
+ declare function Operations({ name, operations }: OperationsProps): any;
41
+
42
+ type Props = {
43
+ /**
44
+ * Name of the function
45
+ */
46
+ name: string;
47
+ isExportable?: boolean;
48
+ isIndexable?: boolean;
49
+ baseURL: string | undefined;
50
+ paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
51
+ paramsType: PluginClient['resolvedOptions']['pathParamsType'];
52
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
53
+ typeSchemas: OperationSchemas;
54
+ operation: Operation;
55
+ };
56
+ type GetParamsProps = {
57
+ paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
58
+ paramsType: PluginClient['resolvedOptions']['paramsType'];
59
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
60
+ typeSchemas: OperationSchemas;
61
+ };
62
+ declare function Url({ name, isExportable, isIndexable, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }: Props): any;
63
+ declare namespace Url {
64
+ var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) => FunctionParams;
65
+ }
41
66
 
42
- export { Client, Operations };
67
+ export { Client, Operations, Url };
@@ -1,15 +1,15 @@
1
1
  import { Operation } from '@kubb/oas';
2
2
  import { OperationSchemas } from '@kubb/plugin-oas';
3
3
  import { FunctionParams } from '@kubb/react';
4
- import { KubbNode } from '@kubb/react/types';
5
4
  import { P as PluginClient } from './types-P398e_Yv.js';
6
5
  import '@kubb/core';
7
6
 
8
- type Props = {
7
+ type Props$1 = {
9
8
  /**
10
9
  * Name of the function
11
10
  */
12
11
  name: string;
12
+ urlName?: string;
13
13
  isExportable?: boolean;
14
14
  isIndexable?: boolean;
15
15
  baseURL: string | undefined;
@@ -22,21 +22,46 @@ type Props = {
22
22
  zodSchemas: OperationSchemas | undefined;
23
23
  operation: Operation;
24
24
  };
25
- type GetParamsProps = {
25
+ type GetParamsProps$1 = {
26
26
  paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
27
27
  paramsType: PluginClient['resolvedOptions']['paramsType'];
28
28
  pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
29
29
  typeSchemas: OperationSchemas;
30
30
  };
31
- declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, }: Props): KubbNode;
31
+ declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, }: Props$1): any;
32
32
  declare namespace Client {
33
- var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) => FunctionParams;
33
+ var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
34
34
  }
35
35
 
36
36
  type OperationsProps = {
37
37
  name: string;
38
38
  operations: Array<Operation>;
39
39
  };
40
- declare function Operations({ name, operations }: OperationsProps): JSX.Element;
40
+ declare function Operations({ name, operations }: OperationsProps): any;
41
+
42
+ type Props = {
43
+ /**
44
+ * Name of the function
45
+ */
46
+ name: string;
47
+ isExportable?: boolean;
48
+ isIndexable?: boolean;
49
+ baseURL: string | undefined;
50
+ paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
51
+ paramsType: PluginClient['resolvedOptions']['pathParamsType'];
52
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
53
+ typeSchemas: OperationSchemas;
54
+ operation: Operation;
55
+ };
56
+ type GetParamsProps = {
57
+ paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
58
+ paramsType: PluginClient['resolvedOptions']['paramsType'];
59
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
60
+ typeSchemas: OperationSchemas;
61
+ };
62
+ declare function Url({ name, isExportable, isIndexable, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }: Props): any;
63
+ declare namespace Url {
64
+ var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) => FunctionParams;
65
+ }
41
66
 
42
- export { Client, Operations };
67
+ export { Client, Operations, Url };
@@ -1,3 +1,3 @@
1
- export { Client, Operations } from './chunk-3WVVUCEB.js';
1
+ export { Client, Operations, Url } from './chunk-HVZSAZQR.js';
2
2
  //# sourceMappingURL=components.js.map
3
3
  //# sourceMappingURL=components.js.map
@@ -1,21 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var chunkTX2PSIPH_cjs = require('./chunk-TX2PSIPH.cjs');
4
- require('./chunk-4OXWRJFQ.cjs');
3
+ var chunkFO6GU3BS_cjs = require('./chunk-FO6GU3BS.cjs');
4
+ require('./chunk-GUUH6APU.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "clientGenerator", {
9
9
  enumerable: true,
10
- get: function () { return chunkTX2PSIPH_cjs.clientGenerator; }
10
+ get: function () { return chunkFO6GU3BS_cjs.clientGenerator; }
11
11
  });
12
12
  Object.defineProperty(exports, "groupedClientGenerator", {
13
13
  enumerable: true,
14
- get: function () { return chunkTX2PSIPH_cjs.groupedClientGenerator; }
14
+ get: function () { return chunkFO6GU3BS_cjs.groupedClientGenerator; }
15
15
  });
16
16
  Object.defineProperty(exports, "operationsGenerator", {
17
17
  enumerable: true,
18
- get: function () { return chunkTX2PSIPH_cjs.operationsGenerator; }
18
+ get: function () { return chunkFO6GU3BS_cjs.operationsGenerator; }
19
19
  });
20
20
  //# sourceMappingURL=generators.cjs.map
21
21
  //# sourceMappingURL=generators.cjs.map
@@ -1,4 +1,4 @@
1
- export { clientGenerator, groupedClientGenerator, operationsGenerator } from './chunk-UIFBYWMG.js';
2
- import './chunk-3WVVUCEB.js';
1
+ export { clientGenerator, groupedClientGenerator, operationsGenerator } from './chunk-7JWZVEC4.js';
2
+ import './chunk-HVZSAZQR.js';
3
3
  //# sourceMappingURL=generators.js.map
4
4
  //# sourceMappingURL=generators.js.map
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunkTX2PSIPH_cjs = require('./chunk-TX2PSIPH.cjs');
4
- require('./chunk-4OXWRJFQ.cjs');
3
+ var chunkFO6GU3BS_cjs = require('./chunk-FO6GU3BS.cjs');
4
+ require('./chunk-GUUH6APU.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "pluginClient", {
9
9
  enumerable: true,
10
- get: function () { return chunkTX2PSIPH_cjs.pluginClient; }
10
+ get: function () { return chunkFO6GU3BS_cjs.pluginClient; }
11
11
  });
12
12
  Object.defineProperty(exports, "pluginClientName", {
13
13
  enumerable: true,
14
- get: function () { return chunkTX2PSIPH_cjs.pluginClientName; }
14
+ get: function () { return chunkFO6GU3BS_cjs.pluginClientName; }
15
15
  });
16
16
  //# sourceMappingURL=index.cjs.map
17
17
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { pluginClient, pluginClientName } from './chunk-UIFBYWMG.js';
2
- import './chunk-3WVVUCEB.js';
1
+ export { pluginClient, pluginClientName } from './chunk-7JWZVEC4.js';
2
+ import './chunk-HVZSAZQR.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-client",
3
- "version": "0.0.0-canary-20241214001945",
3
+ "version": "0.0.0-canary-20250108203132",
4
4
  "description": "Generator plugin-client",
5
5
  "keywords": [
6
6
  "typescript",
@@ -78,23 +78,23 @@
78
78
  "!/**/__tests__/**"
79
79
  ],
80
80
  "dependencies": {
81
- "@kubb/core": "0.0.0-canary-20241214001945",
82
- "@kubb/fs": "0.0.0-canary-20241214001945",
83
- "@kubb/oas": "0.0.0-canary-20241214001945",
84
- "@kubb/plugin-oas": "0.0.0-canary-20241214001945",
85
- "@kubb/plugin-ts": "0.0.0-canary-20241214001945",
86
- "@kubb/plugin-zod": "0.0.0-canary-20241214001945",
87
- "@kubb/react": "0.0.0-canary-20241214001945"
81
+ "@kubb/core": "0.0.0-canary-20250108203132",
82
+ "@kubb/fs": "0.0.0-canary-20250108203132",
83
+ "@kubb/oas": "0.0.0-canary-20250108203132",
84
+ "@kubb/plugin-oas": "0.0.0-canary-20250108203132",
85
+ "@kubb/plugin-ts": "0.0.0-canary-20250108203132",
86
+ "@kubb/plugin-zod": "0.0.0-canary-20250108203132",
87
+ "@kubb/react": "0.0.0-canary-20250108203132"
88
88
  },
89
89
  "devDependencies": {
90
90
  "axios": "^1.7.9",
91
91
  "tsup": "^8.3.5",
92
92
  "typescript": "^5.7.2",
93
- "@kubb/config-ts": "0.0.0-canary-20241214001945",
94
- "@kubb/config-tsup": "0.0.0-canary-20241214001945"
93
+ "@kubb/config-ts": "0.0.0-canary-20250108203132",
94
+ "@kubb/config-tsup": "0.0.0-canary-20250108203132"
95
95
  },
96
96
  "peerDependencies": {
97
- "@kubb/react": "0.0.0-canary-20241214001945",
97
+ "@kubb/react": "0.0.0-canary-20250108203132",
98
98
  "axios": "^1.7.2"
99
99
  },
100
100
  "peerDependenciesMeta": {
@@ -25,9 +25,11 @@ export type ResponseConfig<TData = unknown> = {
25
25
  data: TData
26
26
  status: number
27
27
  statusText: string
28
- headers?: AxiosResponse['headers']
28
+ headers: AxiosResponse['headers']
29
29
  }
30
30
 
31
+ export type ResponseErrorConfig<TError = unknown> = AxiosError<TError>
32
+
31
33
  let _config: Partial<RequestConfig> = {
32
34
  baseURL: typeof AXIOS_BASE !== 'undefined' ? AXIOS_BASE : undefined,
33
35
  headers: typeof AXIOS_HEADERS !== 'undefined' ? (JSON.parse(AXIOS_HEADERS) as AxiosHeaders) : undefined,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Subset of AxiosRequestConfig
2
+ * Subset of FetchRequestConfig
3
3
  */
4
4
  export type RequestConfig<TData = unknown> = {
5
5
  baseURL?: string
@@ -12,17 +12,27 @@ export type RequestConfig<TData = unknown> = {
12
12
  headers?: [string, string][] | Record<string, string>
13
13
  }
14
14
  /**
15
- * Subset of AxiosResponse
15
+ * Subset of FetchResponse
16
16
  */
17
17
  export type ResponseConfig<TData = unknown> = {
18
18
  data: TData
19
19
  status: number
20
20
  statusText: string
21
- headers?: [string, string][] | Record<string, string>
21
+ headers: Headers
22
22
  }
23
23
 
24
+ export type ResponseErrorConfig<TError = unknown> = TError
25
+
24
26
  export const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {
25
- const response = await fetch('https://example.org/post', {
27
+ const url = new URL(config.url || '', config.baseURL ? new URL(config.baseURL) : undefined)
28
+
29
+ Object.entries(config.params || {}).forEach(([key, value]) => {
30
+ if (value !== undefined) {
31
+ url.searchParams.append(key, value === null ? 'null' : value.toString())
32
+ }
33
+ })
34
+
35
+ const response = await fetch(url.toString(), {
26
36
  method: config.method.toUpperCase(),
27
37
  body: JSON.stringify(config.data),
28
38
  signal: config.signal,
@@ -35,6 +45,7 @@ export const fetchClient = async <TData, TError = unknown, TVariables = unknown>
35
45
  data,
36
46
  status: response.status,
37
47
  statusText: response.statusText,
48
+ headers: response.headers as Headers,
38
49
  }
39
50
  }
40
51
 
@@ -4,14 +4,15 @@ import { type Operation, isOptional } from '@kubb/oas'
4
4
  import type { OperationSchemas } from '@kubb/plugin-oas'
5
5
  import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
6
  import { File, Function, FunctionParams } from '@kubb/react'
7
- import type { KubbNode } from '@kubb/react/types'
8
7
  import type { PluginClient } from '../types.ts'
8
+ import { Url } from './Url.tsx'
9
9
 
10
10
  type Props = {
11
11
  /**
12
12
  * Name of the function
13
13
  */
14
14
  name: string
15
+ urlName?: string
15
16
  isExportable?: boolean
16
17
  isIndexable?: boolean
17
18
 
@@ -113,7 +114,8 @@ export function Client({
113
114
  paramsCasing,
114
115
  pathParamsType,
115
116
  operation,
116
- }: Props): KubbNode {
117
+ urlName,
118
+ }: Props) {
117
119
  const path = new URLPath(operation.path, { casing: paramsCasing })
118
120
  const contentType = operation.getContentType()
119
121
  const isFormData = contentType === 'multipart/form-data'
@@ -122,12 +124,16 @@ export function Client({
122
124
  typeSchemas.headerParams?.name ? '...headers' : undefined,
123
125
  ].filter(Boolean)
124
126
 
125
- const generics = [
126
- typeSchemas.response.name,
127
- typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error',
128
- typeSchemas.request?.name || 'unknown',
129
- ].filter(Boolean)
127
+ const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
128
+
129
+ const generics = [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)
130
130
  const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
131
+ const urlParams = Url.getParams({
132
+ paramsType,
133
+ paramsCasing,
134
+ pathParamsType,
135
+ typeSchemas,
136
+ })
131
137
  const clientParams = FunctionParams.factory({
132
138
  config: {
133
139
  mode: 'object',
@@ -136,13 +142,14 @@ export function Client({
136
142
  value: JSON.stringify(operation.method.toUpperCase()),
137
143
  },
138
144
  url: {
139
- value: path.template,
145
+ value: urlName ? `${urlName}(${urlParams.toCall()}).toString()` : path.template,
140
146
  },
141
- baseURL: baseURL
142
- ? {
143
- value: JSON.stringify(baseURL),
144
- }
145
- : undefined,
147
+ baseURL:
148
+ baseURL && !urlName
149
+ ? {
150
+ value: JSON.stringify(baseURL),
151
+ }
152
+ : undefined,
146
153
  params: typeSchemas.queryParams?.name ? {} : undefined,
147
154
  data: typeSchemas.request?.name
148
155
  ? {