Skip to content

Commit

Permalink
Merge pull request #1674 from ale18V/main
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos authored Feb 5, 2025
2 parents 146dc3c + 7f0f4a7 commit 86f4918
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .changeset/quick-actors-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@hey-api/client-axios': patch
'@hey-api/client-core': patch
'@hey-api/client-fetch': patch
'@hey-api/client-next': patch
'@hey-api/client-nuxt': patch
---

Return a string from urlSearchParamsBodySerializer instead of a URLSearchParams object.
This is due to some runtimes not being able to handle the URLSearchParams object as fetch body.
2 changes: 1 addition & 1 deletion packages/client-core/src/bodySerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ export const urlSearchParamsBodySerializer = {
}
});

return data;
return data.toString();
},
};
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
'use strict';var B=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var B__default=/*#__PURE__*/_interopDefault(B);var w=async(t,r)=>{let e=typeof r=="function"?await r(t):r;if(e)return t.scheme==="bearer"?`Bearer ${e}`:t.scheme==="basic"?`Basic ${btoa(e)}`:e},z=(t,r,e)=>{typeof e=="string"||e instanceof Blob?t.append(r,e):t.append(r,JSON.stringify(e));},O=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},j={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>z(r,e,a)):z(r,e,i));}),r}},q={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},P={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>O(r,e,a)):O(r,e,i));}),r}},v=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},k=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},h=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(!r){let n=(t?a:a.map(o=>encodeURIComponent(o))).join($(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let s=v(i),l=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):f({allowReserved:t,name:e,value:n})).join(s);return i==="label"||i==="matrix"?s+l:l},f=({allowReserved:t,name:r,value:e})=>{if(e==null)return "";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${t?e:encodeURIComponent(e)}`},g=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(a instanceof Date)return `${e}=${a.toISOString()}`;if(i!=="deepObject"&&!r){let n=[];Object.entries(a).forEach(([u,d])=>{n=[...n,u,t?d:encodeURIComponent(d)];});let o=n.join(",");switch(i){case "form":return `${e}=${o}`;case "label":return `.${o}`;case "matrix":return `;${e}=${o}`;default:return o}}let s=k(i),l=Object.entries(a).map(([n,o])=>f({allowReserved:t,name:i==="deepObject"?`${e}[${n}]`:n,value:o})).join(s);return i==="label"||i==="matrix"?s+l:l};var T=/\{[^{}]+\}/g,E=({path:t,url:r})=>{let e=r,i=r.match(T);if(i)for(let a of i){let s=false,l=a.substring(1,a.length-1),n="simple";l.endsWith("*")&&(s=true,l=l.substring(0,l.length-1)),l.startsWith(".")?(l=l.substring(1),n="label"):l.startsWith(";")&&(l=l.substring(1),n="matrix");let o=t[l];if(o==null)continue;if(Array.isArray(o)){e=e.replace(a,h({explode:s,name:l,style:n,value:o}));continue}if(typeof o=="object"){e=e.replace(a,g({explode:s,name:l,style:n,value:o}));continue}if(n==="matrix"){e=e.replace(a,`;${f({name:l,value:o})}`);continue}let u=encodeURIComponent(n==="label"?`.${o}`:o);e=e.replace(a,u);}return e},U=({allowReserved:t,array:r,object:e}={})=>a=>{let s=[];if(a&&typeof a=="object")for(let l in a){let n=a[l];if(n!=null){if(Array.isArray(n)){s=[...s,h({allowReserved:t,explode:true,name:l,style:"form",value:n,...r})];continue}if(typeof n=="object"){s=[...s,g({allowReserved:t,explode:true,name:l,style:"deepObject",value:n,...e})];continue}s=[...s,f({allowReserved:t,name:l,value:n})];}}return s.join("&")},A=async({security:t,...r})=>{for(let e of t){let i=await w(e,r.auth);if(!i)continue;let a=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[a]=i;break;case "header":default:r.headers[a]=i;break}return}},b=t=>D({path:t.path,query:t.paramsSerializer?undefined:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:U(t.querySerializer),url:t.url}),D=({path:t,query:r,querySerializer:e,url:i})=>{let s=i.startsWith("/")?i:`/${i}`;t&&(s=E({path:t,url:s}));let l=r?e(r):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(s+=`?${l}`),s},S=(t,r)=>{let e={...t,...r};return e.headers=y(t.headers,r.headers),e},H=["common","delete","get","head","patch","post","put"],y=(...t)=>{let r={};for(let e of t){if(!e||typeof e!="object")continue;let i=Object.entries(e);for(let[a,s]of i)if(H.includes(a)&&typeof s=="object")r[a]={...r[a],...s};else if(s===null)delete r[a];else if(Array.isArray(s))for(let l of s)r[a]=[...r[a]??[],l];else s!==undefined&&(r[a]=typeof s=="object"?JSON.stringify(s):s);}return r},x=(t={})=>({...t});var I=(t={})=>{let r=S(x(),t),{auth:e,...i}=r,a=B__default.default.create(i),s=()=>({...r}),l=o=>(r=S(r,o),a.defaults={...a.defaults,...r,headers:y(a.defaults.headers,r.headers)},s()),n=async o=>{let u={...r,...o,axios:o.axios??r.axios??a,headers:y(r.headers,o.headers)};u.security&&await A({...u,security:u.security}),u.body&&u.bodySerializer&&(u.body=u.bodySerializer(u.body));let d=b(u);try{let m=u.axios,{auth:c,...R}=u,C=await m({...R,baseURL:u.baseURL,data:u.body,headers:u.headers,params:u.paramsSerializer?u.query:void 0,url:d}),{data:p}=C;return u.responseType==="json"&&(u.responseValidator&&await u.responseValidator(p),u.responseTransformer&&(p=await u.responseTransformer(p))),{...C,data:p??{}}}catch(m){let c=m;if(u.throwOnError)throw c;return c.error=c.response?.data??{},c}};return {buildUrl:b,delete:o=>n({...o,method:"DELETE"}),get:o=>n({...o,method:"GET"}),getConfig:s,head:o=>n({...o,method:"HEAD"}),instance:a,options:o=>n({...o,method:"OPTIONS"}),patch:o=>n({...o,method:"PATCH"}),post:o=>n({...o,method:"POST"}),put:o=>n({...o,method:"PUT"}),request:n,setConfig:l}};exports.createClient=I;exports.createConfig=x;exports.formDataBodySerializer=j;exports.jsonBodySerializer=q;exports.urlSearchParamsBodySerializer=P;//# sourceMappingURL=index.cjs.map
'use strict';var B=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var B__default=/*#__PURE__*/_interopDefault(B);var w=async(t,r)=>{let e=typeof r=="function"?await r(t):r;if(e)return t.scheme==="bearer"?`Bearer ${e}`:t.scheme==="basic"?`Basic ${btoa(e)}`:e},z=(t,r,e)=>{typeof e=="string"||e instanceof Blob?t.append(r,e):t.append(r,JSON.stringify(e));},O=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},j={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>z(r,e,a)):z(r,e,i));}),r}},q={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},P={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>O(r,e,a)):O(r,e,i));}),r.toString()}},v=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},k=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},h=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(!r){let n=(t?a:a.map(o=>encodeURIComponent(o))).join($(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let s=v(i),l=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):f({allowReserved:t,name:e,value:n})).join(s);return i==="label"||i==="matrix"?s+l:l},f=({allowReserved:t,name:r,value:e})=>{if(e==null)return "";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${t?e:encodeURIComponent(e)}`},g=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(a instanceof Date)return `${e}=${a.toISOString()}`;if(i!=="deepObject"&&!r){let n=[];Object.entries(a).forEach(([u,d])=>{n=[...n,u,t?d:encodeURIComponent(d)];});let o=n.join(",");switch(i){case "form":return `${e}=${o}`;case "label":return `.${o}`;case "matrix":return `;${e}=${o}`;default:return o}}let s=k(i),l=Object.entries(a).map(([n,o])=>f({allowReserved:t,name:i==="deepObject"?`${e}[${n}]`:n,value:o})).join(s);return i==="label"||i==="matrix"?s+l:l};var T=/\{[^{}]+\}/g,E=({path:t,url:r})=>{let e=r,i=r.match(T);if(i)for(let a of i){let s=false,l=a.substring(1,a.length-1),n="simple";l.endsWith("*")&&(s=true,l=l.substring(0,l.length-1)),l.startsWith(".")?(l=l.substring(1),n="label"):l.startsWith(";")&&(l=l.substring(1),n="matrix");let o=t[l];if(o==null)continue;if(Array.isArray(o)){e=e.replace(a,h({explode:s,name:l,style:n,value:o}));continue}if(typeof o=="object"){e=e.replace(a,g({explode:s,name:l,style:n,value:o}));continue}if(n==="matrix"){e=e.replace(a,`;${f({name:l,value:o})}`);continue}let u=encodeURIComponent(n==="label"?`.${o}`:o);e=e.replace(a,u);}return e},U=({allowReserved:t,array:r,object:e}={})=>a=>{let s=[];if(a&&typeof a=="object")for(let l in a){let n=a[l];if(n!=null){if(Array.isArray(n)){s=[...s,h({allowReserved:t,explode:true,name:l,style:"form",value:n,...r})];continue}if(typeof n=="object"){s=[...s,g({allowReserved:t,explode:true,name:l,style:"deepObject",value:n,...e})];continue}s=[...s,f({allowReserved:t,name:l,value:n})];}}return s.join("&")},A=async({security:t,...r})=>{for(let e of t){let i=await w(e,r.auth);if(!i)continue;let a=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[a]=i;break;case "header":default:r.headers[a]=i;break}return}},b=t=>D({path:t.path,query:t.paramsSerializer?undefined:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:U(t.querySerializer),url:t.url}),D=({path:t,query:r,querySerializer:e,url:i})=>{let s=i.startsWith("/")?i:`/${i}`;t&&(s=E({path:t,url:s}));let l=r?e(r):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(s+=`?${l}`),s},S=(t,r)=>{let e={...t,...r};return e.headers=y(t.headers,r.headers),e},H=["common","delete","get","head","patch","post","put"],y=(...t)=>{let r={};for(let e of t){if(!e||typeof e!="object")continue;let i=Object.entries(e);for(let[a,s]of i)if(H.includes(a)&&typeof s=="object")r[a]={...r[a],...s};else if(s===null)delete r[a];else if(Array.isArray(s))for(let l of s)r[a]=[...r[a]??[],l];else s!==undefined&&(r[a]=typeof s=="object"?JSON.stringify(s):s);}return r},x=(t={})=>({...t});var I=(t={})=>{let r=S(x(),t),{auth:e,...i}=r,a=B__default.default.create(i),s=()=>({...r}),l=o=>(r=S(r,o),a.defaults={...a.defaults,...r,headers:y(a.defaults.headers,r.headers)},s()),n=async o=>{let u={...r,...o,axios:o.axios??r.axios??a,headers:y(r.headers,o.headers)};u.security&&await A({...u,security:u.security}),u.body&&u.bodySerializer&&(u.body=u.bodySerializer(u.body));let d=b(u);try{let m=u.axios,{auth:c,...R}=u,C=await m({...R,baseURL:u.baseURL,data:u.body,headers:u.headers,params:u.paramsSerializer?u.query:void 0,url:d}),{data:p}=C;return u.responseType==="json"&&(u.responseValidator&&await u.responseValidator(p),u.responseTransformer&&(p=await u.responseTransformer(p))),{...C,data:p??{}}}catch(m){let c=m;if(u.throwOnError)throw c;return c.error=c.response?.data??{},c}};return {buildUrl:b,delete:o=>n({...o,method:"DELETE"}),get:o=>n({...o,method:"GET"}),getConfig:s,head:o=>n({...o,method:"HEAD"}),instance:a,options:o=>n({...o,method:"OPTIONS"}),patch:o=>n({...o,method:"PATCH"}),post:o=>n({...o,method:"POST"}),put:o=>n({...o,method:"PUT"}),request:n,setConfig:l}};exports.createClient=I;exports.createConfig=x;exports.formDataBodySerializer=j;exports.jsonBodySerializer=q;exports.urlSearchParamsBodySerializer=P;//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ declare const jsonBodySerializer: {
bodySerializer: <T>(body: T) => string;
};
declare const urlSearchParamsBodySerializer: {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => URLSearchParams;
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
};

interface Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ declare const jsonBodySerializer: {
bodySerializer: <T>(body: T) => string;
};
declare const urlSearchParamsBodySerializer: {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => URLSearchParams;
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
};

interface Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never> {
Expand Down
Loading

0 comments on commit 86f4918

Please sign in to comment.