@kubb/plugin-client 3.3.5 → 3.4.1

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 (46) hide show
  1. package/dist/{chunk-I5D6EX5E.js → chunk-7QARJQ4H.js} +21 -4
  2. package/dist/chunk-7QARJQ4H.js.map +1 -0
  3. package/dist/{chunk-OXQLOJ7C.js → chunk-CHUEGU2Q.js} +44 -15
  4. package/dist/chunk-CHUEGU2Q.js.map +1 -0
  5. package/dist/{chunk-Z2JXYMMA.cjs → chunk-IFYEQ5XI.cjs} +43 -13
  6. package/dist/chunk-IFYEQ5XI.cjs.map +1 -0
  7. package/dist/{chunk-LNZBKU4T.cjs → chunk-MXMH5JXO.cjs} +23 -6
  8. package/dist/chunk-MXMH5JXO.cjs.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 +3 -2
  16. package/dist/clients/fetch.d.ts +3 -2
  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 +31 -5
  21. package/dist/components.d.ts +31 -5
  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 +10 -10
  28. package/src/clients/axios.ts +3 -1
  29. package/src/clients/fetch.ts +13 -2
  30. package/src/components/Client.tsx +19 -11
  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/dist/chunk-I5D6EX5E.js.map +0 -1
  44. package/dist/chunk-LNZBKU4T.cjs.map +0 -1
  45. package/dist/chunk-OXQLOJ7C.js.map +0 -1
  46. package/dist/chunk-Z2JXYMMA.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/clients/fetch.ts"],"names":[],"mappings":";;;;;AAuBa,IAAA,WAAA,GAAc,OAAsD,MAAsE,KAAA;AACrJ,EAAA,MAAM,QAAW,GAAA,MAAM,KAAM,CAAA,CAAC,OAAO,OAAS,EAAA,MAAA,CAAO,GAAG,CAAA,CAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,EAAE,CAAG,EAAA;AAAA,IAClF,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 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?: [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([config.baseURL, config.url].filter(Boolean).join(''), {\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"]}
@@ -18,12 +18,13 @@ 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 };
@@ -18,12 +18,13 @@ 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([config.baseURL, config.url].filter(Boolean).join(""), {
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,EAAA,MAAM,QAAW,GAAA,MAAM,KAAM,CAAA,CAAC,OAAO,OAAS,EAAA,MAAA,CAAO,GAAG,CAAA,CAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,EAAE,CAAG,EAAA;AAAA,IAClF,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 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?: [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([config.baseURL, config.url].filter(Boolean).join(''), {\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 chunkZ2JXYMMA_cjs = require('./chunk-Z2JXYMMA.cjs');
3
+ var chunkIFYEQ5XI_cjs = require('./chunk-IFYEQ5XI.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "Client", {
8
8
  enumerable: true,
9
- get: function () { return chunkZ2JXYMMA_cjs.Client; }
9
+ get: function () { return chunkIFYEQ5XI_cjs.Client; }
10
10
  });
11
11
  Object.defineProperty(exports, "Operations", {
12
12
  enumerable: true,
13
- get: function () { return chunkZ2JXYMMA_cjs.Operations; }
13
+ get: function () { return chunkIFYEQ5XI_cjs.Operations; }
14
+ });
15
+ Object.defineProperty(exports, "Url", {
16
+ enumerable: true,
17
+ get: function () { return chunkIFYEQ5XI_cjs.Url; }
14
18
  });
15
19
  //# sourceMappingURL=components.cjs.map
16
20
  //# sourceMappingURL=components.cjs.map
@@ -4,11 +4,12 @@ import { FunctionParams } from '@kubb/react';
4
4
  import { P as PluginClient } from './types-P398e_Yv.cjs';
5
5
  import '@kubb/core';
6
6
 
7
- type Props = {
7
+ type Props$1 = {
8
8
  /**
9
9
  * Name of the function
10
10
  */
11
11
  name: string;
12
+ urlName?: string;
12
13
  isExportable?: boolean;
13
14
  isIndexable?: boolean;
14
15
  baseURL: string | undefined;
@@ -21,15 +22,15 @@ type Props = {
21
22
  zodSchemas: OperationSchemas | undefined;
22
23
  operation: Operation;
23
24
  };
24
- type GetParamsProps = {
25
+ type GetParamsProps$1 = {
25
26
  paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
26
27
  paramsType: PluginClient['resolvedOptions']['paramsType'];
27
28
  pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
28
29
  typeSchemas: OperationSchemas;
29
30
  };
30
- declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, }: Props): any;
31
+ declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, }: Props$1): any;
31
32
  declare namespace Client {
32
- var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) => FunctionParams;
33
+ var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
33
34
  }
34
35
 
35
36
  type OperationsProps = {
@@ -38,4 +39,29 @@ type OperationsProps = {
38
39
  };
39
40
  declare function Operations({ name, operations }: OperationsProps): any;
40
41
 
41
- export { Client, Operations };
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
+ }
66
+
67
+ export { Client, Operations, Url };
@@ -4,11 +4,12 @@ import { FunctionParams } from '@kubb/react';
4
4
  import { P as PluginClient } from './types-P398e_Yv.js';
5
5
  import '@kubb/core';
6
6
 
7
- type Props = {
7
+ type Props$1 = {
8
8
  /**
9
9
  * Name of the function
10
10
  */
11
11
  name: string;
12
+ urlName?: string;
12
13
  isExportable?: boolean;
13
14
  isIndexable?: boolean;
14
15
  baseURL: string | undefined;
@@ -21,15 +22,15 @@ type Props = {
21
22
  zodSchemas: OperationSchemas | undefined;
22
23
  operation: Operation;
23
24
  };
24
- type GetParamsProps = {
25
+ type GetParamsProps$1 = {
25
26
  paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
26
27
  paramsType: PluginClient['resolvedOptions']['paramsType'];
27
28
  pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
28
29
  typeSchemas: OperationSchemas;
29
30
  };
30
- declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, }: Props): any;
31
+ declare function Client({ name, isExportable, isIndexable, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, }: Props$1): any;
31
32
  declare namespace Client {
32
- var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) => FunctionParams;
33
+ var getParams: ({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
33
34
  }
34
35
 
35
36
  type OperationsProps = {
@@ -38,4 +39,29 @@ type OperationsProps = {
38
39
  };
39
40
  declare function Operations({ name, operations }: OperationsProps): any;
40
41
 
41
- export { Client, Operations };
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
+ }
66
+
67
+ export { Client, Operations, Url };
@@ -1,3 +1,3 @@
1
- export { Client, Operations } from './chunk-OXQLOJ7C.js';
1
+ export { Client, Operations, Url } from './chunk-CHUEGU2Q.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 chunkLNZBKU4T_cjs = require('./chunk-LNZBKU4T.cjs');
4
- require('./chunk-Z2JXYMMA.cjs');
3
+ var chunkMXMH5JXO_cjs = require('./chunk-MXMH5JXO.cjs');
4
+ require('./chunk-IFYEQ5XI.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "clientGenerator", {
9
9
  enumerable: true,
10
- get: function () { return chunkLNZBKU4T_cjs.clientGenerator; }
10
+ get: function () { return chunkMXMH5JXO_cjs.clientGenerator; }
11
11
  });
12
12
  Object.defineProperty(exports, "groupedClientGenerator", {
13
13
  enumerable: true,
14
- get: function () { return chunkLNZBKU4T_cjs.groupedClientGenerator; }
14
+ get: function () { return chunkMXMH5JXO_cjs.groupedClientGenerator; }
15
15
  });
16
16
  Object.defineProperty(exports, "operationsGenerator", {
17
17
  enumerable: true,
18
- get: function () { return chunkLNZBKU4T_cjs.operationsGenerator; }
18
+ get: function () { return chunkMXMH5JXO_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-I5D6EX5E.js';
2
- import './chunk-OXQLOJ7C.js';
1
+ export { clientGenerator, groupedClientGenerator, operationsGenerator } from './chunk-7QARJQ4H.js';
2
+ import './chunk-CHUEGU2Q.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 chunkLNZBKU4T_cjs = require('./chunk-LNZBKU4T.cjs');
4
- require('./chunk-Z2JXYMMA.cjs');
3
+ var chunkMXMH5JXO_cjs = require('./chunk-MXMH5JXO.cjs');
4
+ require('./chunk-IFYEQ5XI.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "pluginClient", {
9
9
  enumerable: true,
10
- get: function () { return chunkLNZBKU4T_cjs.pluginClient; }
10
+ get: function () { return chunkMXMH5JXO_cjs.pluginClient; }
11
11
  });
12
12
  Object.defineProperty(exports, "pluginClientName", {
13
13
  enumerable: true,
14
- get: function () { return chunkLNZBKU4T_cjs.pluginClientName; }
14
+ get: function () { return chunkMXMH5JXO_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-I5D6EX5E.js';
2
- import './chunk-OXQLOJ7C.js';
1
+ export { pluginClient, pluginClientName } from './chunk-7QARJQ4H.js';
2
+ import './chunk-CHUEGU2Q.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": "3.3.5",
3
+ "version": "3.4.1",
4
4
  "description": "Generator plugin-client",
5
5
  "keywords": [
6
6
  "typescript",
@@ -78,20 +78,20 @@
78
78
  "!/**/__tests__/**"
79
79
  ],
80
80
  "dependencies": {
81
- "@kubb/core": "3.3.5",
82
- "@kubb/fs": "3.3.5",
83
- "@kubb/oas": "3.3.5",
84
- "@kubb/plugin-oas": "3.3.5",
85
- "@kubb/plugin-ts": "3.3.5",
86
- "@kubb/plugin-zod": "3.3.5",
87
- "@kubb/react": "3.3.5"
81
+ "@kubb/core": "3.4.1",
82
+ "@kubb/fs": "3.4.1",
83
+ "@kubb/oas": "3.4.1",
84
+ "@kubb/plugin-oas": "3.4.1",
85
+ "@kubb/plugin-ts": "3.4.1",
86
+ "@kubb/plugin-zod": "3.4.1",
87
+ "@kubb/react": "3.4.1"
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": "3.3.5",
94
- "@kubb/config-tsup": "3.3.5"
93
+ "@kubb/config-ts": "3.4.1",
94
+ "@kubb/config-tsup": "3.4.1"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "@kubb/react": "^3.0.0",
@@ -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,
@@ -18,11 +18,21 @@ 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([config.baseURL, config.url].filter(Boolean).join(''), {
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
 
@@ -5,12 +5,14 @@ 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
7
  import type { PluginClient } from '../types.ts'
8
+ import { Url } from './Url.tsx'
8
9
 
9
10
  type Props = {
10
11
  /**
11
12
  * Name of the function
12
13
  */
13
14
  name: string
15
+ urlName?: string
14
16
  isExportable?: boolean
15
17
  isIndexable?: boolean
16
18
 
@@ -112,6 +114,7 @@ export function Client({
112
114
  paramsCasing,
113
115
  pathParamsType,
114
116
  operation,
117
+ urlName,
115
118
  }: Props) {
116
119
  const path = new URLPath(operation.path, { casing: paramsCasing })
117
120
  const contentType = operation.getContentType()
@@ -121,12 +124,16 @@ export function Client({
121
124
  typeSchemas.headerParams?.name ? '...headers' : undefined,
122
125
  ].filter(Boolean)
123
126
 
124
- const generics = [
125
- typeSchemas.response.name,
126
- typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error',
127
- typeSchemas.request?.name || 'unknown',
128
- ].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)
129
130
  const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
131
+ const urlParams = Url.getParams({
132
+ paramsType,
133
+ paramsCasing,
134
+ pathParamsType,
135
+ typeSchemas,
136
+ })
130
137
  const clientParams = FunctionParams.factory({
131
138
  config: {
132
139
  mode: 'object',
@@ -135,13 +142,14 @@ export function Client({
135
142
  value: JSON.stringify(operation.method.toUpperCase()),
136
143
  },
137
144
  url: {
138
- value: path.template,
145
+ value: urlName ? `${urlName}(${urlParams.toCall()}).toString()` : path.template,
139
146
  },
140
- baseURL: baseURL
141
- ? {
142
- value: JSON.stringify(baseURL),
143
- }
144
- : undefined,
147
+ baseURL:
148
+ baseURL && !urlName
149
+ ? {
150
+ value: JSON.stringify(baseURL),
151
+ }
152
+ : undefined,
145
153
  params: typeSchemas.queryParams?.name ? {} : undefined,
146
154
  data: typeSchemas.request?.name
147
155
  ? {
@@ -0,0 +1,68 @@
1
+ import { URLPath } from '@kubb/core/utils'
2
+
3
+ import { type Operation, isOptional } from '@kubb/oas'
4
+ import type { OperationSchemas } from '@kubb/plugin-oas'
5
+ import { getPathParams } from '@kubb/plugin-oas/utils'
6
+ import { File, Function, FunctionParams } from '@kubb/react'
7
+ import type { PluginClient } from '../types.ts'
8
+
9
+ type Props = {
10
+ /**
11
+ * Name of the function
12
+ */
13
+ name: string
14
+ isExportable?: boolean
15
+ isIndexable?: boolean
16
+
17
+ baseURL: string | undefined
18
+ paramsCasing: PluginClient['resolvedOptions']['paramsCasing']
19
+ paramsType: PluginClient['resolvedOptions']['pathParamsType']
20
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
21
+ typeSchemas: OperationSchemas
22
+ operation: Operation
23
+ }
24
+
25
+ type GetParamsProps = {
26
+ paramsCasing: PluginClient['resolvedOptions']['paramsCasing']
27
+ paramsType: PluginClient['resolvedOptions']['paramsType']
28
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
29
+ typeSchemas: OperationSchemas
30
+ }
31
+
32
+ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
33
+ if (paramsType === 'object') {
34
+ return FunctionParams.factory({
35
+ data: {
36
+ mode: 'object',
37
+ children: {
38
+ ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
39
+ },
40
+ },
41
+ })
42
+ }
43
+
44
+ return FunctionParams.factory({
45
+ pathParams: typeSchemas.pathParams?.name
46
+ ? {
47
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
48
+ children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
49
+ optional: isOptional(typeSchemas.pathParams?.schema),
50
+ }
51
+ : undefined,
52
+ })
53
+ }
54
+
55
+ export function Url({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }: Props) {
56
+ const path = new URLPath(operation.path, { casing: paramsCasing })
57
+ const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
58
+
59
+ return (
60
+ <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
61
+ <Function name={name} export={isExportable} params={params.toConstructor()}>
62
+ {baseURL ? `return new URL(${path.template.toString()}, '${baseURL}')` : `return new URL(${path.template.toString()})`}
63
+ </Function>
64
+ </File.Source>
65
+ )
66
+ }
67
+
68
+ Url.getParams = getParams
@@ -1,2 +1,3 @@
1
1
  export { Client } from './Client.tsx'
2
2
  export { Operations } from './Operations.tsx'
3
+ export { Url } from './Url.tsx'
@@ -1,6 +1,10 @@
1
1
  /* eslint-disable no-alert, no-console */
2
2
  import client from '@kubb/plugin-client/clients/axios'
3
- import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
3
+ import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
4
+
5
+ export function getDeletePetUrl(petId: DeletePetPathParams['petId']) {
6
+ return new URL(`/pet/${petId}`)
7
+ }
4
8
 
5
9
  /**
6
10
  * @description delete a pet
@@ -8,9 +12,9 @@ import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
8
12
  * {@link /pet/:petId}
9
13
  */
10
14
  export async function deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> = {}) {
11
- const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({
15
+ const res = await client<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
12
16
  method: 'DELETE',
13
- url: `/pet/${petId}`,
17
+ url: getDeletePetUrl(petId).toString(),
14
18
  headers: { ...headers, ...config.headers },
15
19
  ...config,
16
20
  })
@@ -1,6 +1,10 @@
1
1
  /* eslint-disable no-alert, no-console */
2
2
  import client from '@kubb/plugin-client/clients/axios'
3
- import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
3
+ import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
4
+
5
+ export function getDeletePetUrl({ petId }: { petId: DeletePetPathParams['petId'] }) {
6
+ return new URL(`/pet/${petId}`)
7
+ }
4
8
 
5
9
  /**
6
10
  * @description delete a pet
@@ -8,9 +12,9 @@ import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
8
12
  * {@link /pet/:petId}
9
13
  */
10
14
  export async function deletePet({ petId }: { petId: DeletePetPathParams['petId'] }, headers?: DeletePetHeaderParams, config: Partial<RequestConfig> = {}) {
11
- const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({
15
+ const res = await client<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
12
16
  method: 'DELETE',
13
- url: `/pet/${petId}`,
17
+ url: getDeletePetUrl({ petId }).toString(),
14
18
  headers: { ...headers, ...config.headers },
15
19
  ...config,
16
20
  })
@@ -1,6 +1,10 @@
1
1
  /* eslint-disable no-alert, no-console */
2
2
  import client from '@kubb/plugin-client/clients/axios'
3
- import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
3
+ import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
4
+
5
+ export function getFindPetsByTagsUrl() {
6
+ return new URL(`/pet/findByTags`)
7
+ }
4
8
 
5
9
  /**
6
10
  * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@@ -8,6 +12,11 @@ import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
8
12
  * {@link /pet/findByTags}
9
13
  */
10
14
  export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
11
- const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'GET', url: `/pet/findByTags`, params, ...config })
15
+ const res = await client<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
16
+ method: 'GET',
17
+ url: getFindPetsByTagsUrl().toString(),
18
+ params,
19
+ ...config,
20
+ })
12
21
  return res.data
13
22
  }
@@ -1,6 +1,10 @@
1
1
  /* eslint-disable no-alert, no-console */
2
2
  import client from '@kubb/plugin-client/clients/axios'
3
- import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
3
+ import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
4
+
5
+ export function getFindPetsByTagsUrl() {
6
+ return new URL(`/pet/findByTags`)
7
+ }
4
8
 
5
9
  /**
6
10
  * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@@ -8,6 +12,11 @@ import type { RequestConfig } from '@kubb/plugin-client/clients/axios'
8
12
  * {@link /pet/findByTags}
9
13
  */
10
14
  export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
11
- const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'GET', url: `/pet/findByTags`, params, ...config })
15
+ const res = await client<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
16
+ method: 'GET',
17
+ url: getFindPetsByTagsUrl().toString(),
18
+ params,
19
+ ...config,
20
+ })
12
21
  return res
13
22
  }