-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle reactive refs in Nuxt client body #1649
Conversation
Run & review this pull request in StackBlitz Codeflow. |
🦋 Changeset detectedLatest commit: 603541e The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -1,2 +1,2 @@ | |||
'use strict';var app=require('nuxt/app'),vue=require('vue');var $=async(r,t)=>{let e=typeof t=="function"?await t(r):t;if(e)return r.scheme==="bearer"?`Bearer ${e}`:r.scheme==="basic"?`Basic ${btoa(e)}`:e},P=(r,t,e)=>{typeof e=="string"||e instanceof Blob?r.append(t,e):r.append(t,JSON.stringify(e));},U=(r,t,e)=>{typeof e=="string"?r.append(t,e):r.append(t,JSON.stringify(e));},L={bodySerializer:r=>{let t=new FormData;return Object.entries(r).forEach(([e,s])=>{s!=null&&(Array.isArray(s)?s.forEach(o=>P(t,e,o)):P(t,e,s));}),t}},R={bodySerializer:r=>JSON.stringify(r)},H={bodySerializer:r=>{let t=new URLSearchParams;return Object.entries(r).forEach(([e,s])=>{s!=null&&(Array.isArray(s)?s.forEach(o=>U(t,e,o)):U(t,e,s));}),t}},D=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},N=r=>{switch(r){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},I=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},C=({allowReserved:r,explode:t,name:e,style:s,value:o})=>{if(!t){let n=(r?o:o.map(u=>encodeURIComponent(u))).join(N(s));switch(s){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let a=D(s),i=o.map(n=>s==="label"||s==="simple"?r?n:encodeURIComponent(n):y({allowReserved:r,name:e,value:n})).join(a);return s==="label"||s==="matrix"?a+i:i},y=({allowReserved:r,name:t,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 `${t}=${r?e:encodeURIComponent(e)}`},S=({allowReserved:r,explode:t,name:e,style:s,value:o})=>{if(o instanceof Date)return `${e}=${o.toISOString()}`;if(s!=="deepObject"&&!t){let n=[];Object.entries(o).forEach(([l,p])=>{n=[...n,l,r?p:encodeURIComponent(p)];});let u=n.join(",");switch(s){case "form":return `${e}=${u}`;case "label":return `.${u}`;case "matrix":return `;${e}=${u}`;default:return u}}let a=I(s),i=Object.entries(o).map(([n,u])=>y({allowReserved:r,name:s==="deepObject"?`${e}[${n}]`:n,value:u})).join(a);return s==="label"||s==="matrix"?a+i:i};var Q=/\{[^{}]+\}/g,V=({path:r,url:t})=>{let e=t,s=t.match(Q);if(s)for(let o of s){let a=false,i=o.substring(1,o.length-1),n="simple";i.endsWith("*")&&(a=true,i=i.substring(0,i.length-1)),i.startsWith(".")?(i=i.substring(1),n="label"):i.startsWith(";")&&(i=i.substring(1),n="matrix");let u=vue.toValue(vue.toValue(r)[i]);if(u==null)continue;if(Array.isArray(u)){e=e.replace(o,C({explode:a,name:i,style:n,value:u}));continue}if(typeof u=="object"){e=e.replace(o,S({explode:a,name:i,style:n,value:u}));continue}if(n==="matrix"){e=e.replace(o,`;${y({name:i,value:u})}`);continue}let l=encodeURIComponent(n==="label"?`.${u}`:u);e=e.replace(o,l);}return e},E=({allowReserved:r,array:t,object:e}={})=>o=>{let a=[],i=vue.toValue(o);if(i&&typeof i=="object")for(let n in i){let u=vue.toValue(i[n]);if(u!=null){if(Array.isArray(u)){a=[...a,C({allowReserved:r,explode:true,name:n,style:"form",value:u,...t})];continue}if(typeof u=="object"){a=[...a,S({allowReserved:r,explode:true,name:n,style:"deepObject",value:u,...e})];continue}a=[...a,y({allowReserved:r,name:n,value:u})];}}return a.join("&")},k=async({security:r,...t})=>{for(let e of r){let s=await $(e,t.auth);if(!s)continue;let o=e.name??"Authorization";switch(e.in){case "query":t.query||(t.query={}),vue.toValue(t.query)[o]=s;break;case "header":default:t.headers.set(o,s);break}return}},d=r=>F({baseUrl:r.baseURL??"",path:r.path,query:r.query,querySerializer:typeof r.querySerializer=="function"?r.querySerializer:E(r.querySerializer),url:r.url}),F=({baseUrl:r,path:t,query:e,querySerializer:s,url:o})=>{let a=o.startsWith("/")?o:`/${o}`,i=r+a;t&&(i=V({path:t,url:i}));let n=e?s(e):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(i+=`?${n}`),i},x=(r,t)=>{let e={...r,...t};return e.baseURL?.endsWith("/")&&(e.baseURL=e.baseURL.substring(0,e.baseURL.length-1)),e.headers=T(r.headers,t.headers),e},T=(...r)=>{let t=new Headers;for(let e of r){if(!e||typeof e!="object")continue;let s=e;vue.isRef(s)&&(s=vue.unref(s));let o=s instanceof Headers?s.entries():Object.entries(s);for(let[a,i]of o)if(i===null)t.delete(a);else if(Array.isArray(i))for(let n of i)t.append(a,f(n));else if(i!==undefined){let n=f(i);t.set(a,typeof n=="object"?JSON.stringify(n):n);}}return t},w=(...r)=>r.reduce((t,e)=>{if(typeof e=="function")t.push(e);else if(Array.isArray(e))return t.concat(e);return t},[]),W=E({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),J={"Content-Type":"application/json"},q=(r={})=>({...R,baseURL:"",headers:J,querySerializer:W,...r}),f=r=>{if(r===null||typeof r!="object"||r instanceof Headers)return vue.isRef(r)?vue.unref(r):r;if(Array.isArray(r))return r.map(e=>f(e));if(vue.isRef(r))return f(vue.unref(r));let t={};for(let e in r)t[e]=f(r[e]);return t};var K=(r={})=>{let t=x(q(),r),e=()=>({...t}),s=a=>(t=x(t,a),e()),o=({asyncDataOptions:a,composable:i,key:n,...u})=>{let l={...t,...u,$fetch:u.$fetch??t.$fetch??$fetch,headers:T(t.headers,u.headers),onRequest:w(t.onRequest,u.onRequest),onResponse:w(t.onResponse,u.onResponse)},{responseTransformer:p,responseValidator:g,security:j}=l;j&&(l.onRequest=[async({options:c})=>{await k({auth:l.auth,headers:c.headers,query:c.query,security:j});},...l.onRequest]),(p||g)&&(l.onResponse=[...l.onResponse,async({options:c,response:b})=>{c.responseType&&c.responseType!=="json"||(g&&await g(b._data),p&&(b._data=await p(b._data)));}]),l.body&&l.bodySerializer&&(l.body=l.bodySerializer(f(l.body))),l.body||l.headers.delete("Content-Type");let O=l.$fetch;if(i==="$fetch"){let c=d(l);return O(c,f(l))}if(i==="useFetch"){let c=d(l);return app.useFetch(c,l)}if(i==="useLazyFetch"){let c=d(l);return app.useLazyFetch(c,l)}let h=()=>{let c=d(l);return O(c,f(l))};if(i==="useAsyncData")return n?app.useAsyncData(n,h,a):app.useAsyncData(h,a);if(i==="useLazyAsyncData")return n?app.useLazyAsyncData(n,h,a):app.useLazyAsyncData(h,a)};return {buildUrl:d,connect:a=>o({...a,method:"CONNECT"}),delete:a=>o({...a,method:"DELETE"}),get:a=>o({...a,method:"GET"}),getConfig:e,head:a=>o({...a,method:"HEAD"}),options:a=>o({...a,method:"OPTIONS"}),patch:a=>o({...a,method:"PATCH"}),post:a=>o({...a,method:"POST"}),put:a=>o({...a,method:"PUT"}),request:o,setConfig:s,trace:a=>o({...a,method:"TRACE"})}};exports.createClient=K;exports.createConfig=q;exports.formDataBodySerializer=L;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=H;//# sourceMappingURL=index.cjs.map | |||
'use strict';var app=require('nuxt/app'),vue=require('vue');var k=async(r,t)=>{let e=typeof t=="function"?await t(r):t;if(e)return r.scheme==="bearer"?`Bearer ${e}`:r.scheme==="basic"?`Basic ${btoa(e)}`:e},U=(r,t,e)=>{typeof e=="string"||e instanceof Blob?r.append(t,e):r.append(t,JSON.stringify(e));},$=(r,t,e)=>{typeof e=="string"?r.append(t,e):r.append(t,JSON.stringify(e));},N={bodySerializer:r=>{let t=new FormData;return Object.entries(r).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(o=>U(t,e,o)):U(t,e,i));}),t}},R={bodySerializer:r=>JSON.stringify(r,(t,e)=>typeof e=="bigint"?e.toString():e)},F={bodySerializer:r=>{let t=new URLSearchParams;return Object.entries(r).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(o=>$(t,e,o)):$(t,e,i));}),t}},I=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},Q=r=>{switch(r){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},V=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},C=({allowReserved:r,explode:t,name:e,style:i,value:o})=>{if(!t){let n=(r?o:o.map(u=>encodeURIComponent(u))).join(Q(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let a=I(i),s=o.map(n=>i==="label"||i==="simple"?r?n:encodeURIComponent(n):p({allowReserved:r,name:e,value:n})).join(a);return i==="label"||i==="matrix"?a+s:s},p=({allowReserved:r,name:t,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 `${t}=${r?e:encodeURIComponent(e)}`},S=({allowReserved:r,explode:t,name:e,style:i,value:o})=>{if(o instanceof Date)return `${e}=${o.toISOString()}`;if(i!=="deepObject"&&!t){let n=[];Object.entries(o).forEach(([l,y])=>{n=[...n,l,r?y:encodeURIComponent(y)];});let u=n.join(",");switch(i){case "form":return `${e}=${u}`;case "label":return `.${u}`;case "matrix":return `;${e}=${u}`;default:return u}}let a=V(i),s=Object.entries(o).map(([n,u])=>p({allowReserved:r,name:i==="deepObject"?`${e}[${n}]`:n,value:u})).join(a);return i==="label"||i==="matrix"?a+s:s};var W=/\{[^{}]+\}/g,J=({path:r,url:t})=>{let e=t,i=t.match(W);if(i)for(let o of i){let a=false,s=o.substring(1,o.length-1),n="simple";s.endsWith("*")&&(a=true,s=s.substring(0,s.length-1)),s.startsWith(".")?(s=s.substring(1),n="label"):s.startsWith(";")&&(s=s.substring(1),n="matrix");let u=vue.toValue(vue.toValue(r)[s]);if(u==null)continue;if(Array.isArray(u)){e=e.replace(o,C({explode:a,name:s,style:n,value:u}));continue}if(typeof u=="object"){e=e.replace(o,S({explode:a,name:s,style:n,value:u}));continue}if(n==="matrix"){e=e.replace(o,`;${p({name:s,value:u})}`);continue}let l=encodeURIComponent(n==="label"?`.${u}`:u);e=e.replace(o,l);}return e},E=({allowReserved:r,array:t,object:e}={})=>o=>{let a=[],s=vue.toValue(o);if(s&&typeof s=="object")for(let n in s){let u=vue.toValue(s[n]);if(u!=null){if(Array.isArray(u)){a=[...a,C({allowReserved:r,explode:true,name:n,style:"form",value:u,...t})];continue}if(typeof u=="object"){a=[...a,S({allowReserved:r,explode:true,name:n,style:"deepObject",value:u,...e})];continue}a=[...a,p({allowReserved:r,name:n,value:u})];}}return a.join("&")},v=async({security:r,...t})=>{for(let e of r){let i=await k(e,t.auth);if(!i)continue;let o=e.name??"Authorization";switch(e.in){case "query":t.query||(t.query={}),vue.toValue(t.query)[o]=i;break;case "header":default:t.headers.set(o,i);break}return}},h=r=>M({baseUrl:r.baseURL??"",path:r.path,query:r.query,querySerializer:typeof r.querySerializer=="function"?r.querySerializer:E(r.querySerializer),url:r.url}),M=({baseUrl:r,path:t,query:e,querySerializer:i,url:o})=>{let a=o.startsWith("/")?o:`/${o}`,s=r+a;t&&(s=J({path:t,url:s}));let n=e?i(e):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(s+=`?${n}`),s},x=(r,t)=>{let e={...r,...t};return e.baseURL?.endsWith("/")&&(e.baseURL=e.baseURL.substring(0,e.baseURL.length-1)),e.headers=T(r.headers,t.headers),e},T=(...r)=>{let t=new Headers;for(let e of r){if(!e||typeof e!="object")continue;let i=e;vue.isRef(i)&&(i=vue.unref(i));let o=i instanceof Headers?i.entries():Object.entries(i);for(let[a,s]of o)if(s===null)t.delete(a);else if(Array.isArray(s))for(let n of s)t.append(a,d(n));else if(s!==undefined){let n=d(s);t.set(a,typeof n=="object"?JSON.stringify(n):n);}}return t},w=(...r)=>r.reduce((t,e)=>{if(typeof e=="function")t.push(e);else if(Array.isArray(e))return t.concat(e);return t},[]),_=E({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),K={"Content-Type":"application/json"},q=(r={})=>({...R,baseURL:"",headers:K,querySerializer:_,...r}),d=r=>{if(r===null||typeof r!="object"||r instanceof Headers)return vue.isRef(r)?vue.unref(r):r;if(Array.isArray(r))return r.map(e=>d(e));if(vue.isRef(r))return d(vue.unref(r));let t={};for(let e in r)t[e]=d(r[e]);return t};var P=r=>r.body&&r.bodySerializer?r.bodySerializer(r.body):r.body,H=(r,t)=>{let e=d(r);return e.body=P(e),t(h(r),e)},re=(r={})=>{let t=x(q(),r),e=()=>({...t}),i=a=>(t=x(t,a),e()),o=({asyncDataOptions:a,composable:s,key:n,...u})=>{let l={...t,...u,$fetch:u.$fetch??t.$fetch??$fetch,headers:T(t.headers,u.headers),onRequest:w(t.onRequest,u.onRequest),onResponse:w(t.onResponse,u.onResponse)},{responseTransformer:y,responseValidator:g,security:O}=l;O&&(l.onRequest=[async({options:c})=>{await v({auth:l.auth,headers:c.headers,query:c.query,security:O});},...l.onRequest]),(y||g)&&(l.onResponse=[...l.onResponse,async({options:c,response:f})=>{c.responseType&&c.responseType!=="json"||f.ok&&(g&&await g(f._data),y&&(f._data=await y(f._data)));}]),l.body||l.headers.delete("Content-Type");let j=l.$fetch;if(s==="$fetch")return H(l,j);if(s==="useFetch"||s==="useLazyFetch"){let c=vue.reactive({body:l.body,bodySerializer:l.bodySerializer}),f=vue.ref(P(l));return l.body=f,vue.watch(c,D=>{f.value=P(D);}),s==="useLazyFetch"?app.useLazyFetch(()=>h(l),l):app.useFetch(()=>h(l),l)}let b=()=>H(l,j);if(s==="useAsyncData")return n?app.useAsyncData(n,b,a):app.useAsyncData(b,a);if(s==="useLazyAsyncData")return n?app.useLazyAsyncData(n,b,a):app.useLazyAsyncData(b,a)};return {buildUrl:h,connect:a=>o({...a,method:"CONNECT"}),delete:a=>o({...a,method:"DELETE"}),get:a=>o({...a,method:"GET"}),getConfig:e,head:a=>o({...a,method:"HEAD"}),options:a=>o({...a,method:"OPTIONS"}),patch:a=>o({...a,method:"PATCH"}),post:a=>o({...a,method:"POST"}),put:a=>o({...a,method:"PUT"}),request:o,setConfig:i,trace:a=>o({...a,method:"TRACE"})}};exports.createClient=re;exports.createConfig=q;exports.formDataBodySerializer=N;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=F;//# sourceMappingURL=index.cjs.map |
Check notice
Code scanning / CodeQL
Semicolon insertion
eb96ba2
to
d7f71fe
Compare
d7f71fe
to
603541e
Compare
commit: |
Closes #1647