Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-fetch

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-fetch - npm Package Compare versions

Comparing version 0.12.2 to 0.12.3

6

CHANGELOG.md
# openapi-fetch
## 0.12.3
### Patch Changes
- [#1936](https://github.com/openapi-ts/openapi-typescript/pull/1936) [`d14aa65`](https://github.com/openapi-ts/openapi-typescript/commit/d14aa65207b8abd1f369965bbd32ebb581e8d741) Thanks [@BlakeSzabo](https://github.com/BlakeSzabo)! - Fix multiple empty arrays in query params appending extra ampersands
## 0.12.2

@@ -4,0 +10,0 @@

3

dist/index.js

@@ -439,2 +439,5 @@ // settings & const

if (Array.isArray(value)) {
if (value.length === 0) {
continue;
}
search.push(

@@ -441,0 +444,0 @@ serializeArrayParam(name, value, {

2

dist/index.min.js

@@ -1,1 +0,1 @@

var v=/\{[^{}]+\}/g;function W(){return Math.random().toString(36).slice(2,11)}function H(n){let{baseUrl:e="",Request:t=globalThis.Request,fetch:i=globalThis.fetch,querySerializer:r,bodySerializer:s,headers:l,...c}={...n};e=D(e);let d=[];async function h(a,o){let{baseUrl:m,fetch:C=i,Request:_=t,headers:N,params:b={},parseAs:T="json",querySerializer:R,bodySerializer:q=s??M,body:U,...j}=o||{};m&&(e=D(m));let x=typeof r=="function"?r:P(r);R&&(x=typeof R=="function"?R:P({...typeof r=="object"?r:{},...R}));let E=U===void 0?void 0:q(U),k=E===void 0||E instanceof FormData?{}:{"Content-Type":"application/json"},B={redirect:"follow",...c,...j,body:E,headers:J(k,l,N,b.header)},g,A,p=new t(Q(a,{baseUrl:e,params:b,querySerializer:x}),B);for(let f in j)f in p||(p[f]=j[f]);if(d.length){g=W(),A=Object.freeze({baseUrl:e,fetch:C,parseAs:T,querySerializer:x,bodySerializer:q});for(let f of d)if(f&&typeof f=="object"&&typeof f.onRequest=="function"){let y=await f.onRequest({request:p,schemaPath:a,params:b,options:A,id:g});if(y){if(!(y instanceof t))throw new Error("onRequest: must return new Request() when modifying the request");p=y}}}let u=await C(p);if(d.length)for(let f=d.length-1;f>=0;f--){let y=d[f];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){let $=await y.onResponse({request:p,response:u,schemaPath:a,params:b,options:A,id:g});if($){if(!($ instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");u=$}}}if(u.status===204||u.headers.get("Content-Length")==="0")return u.ok?{data:{},response:u}:{error:{},response:u};if(u.ok)return T==="stream"?{data:u.body,response:u}:{data:await u[T](),response:u};let S=await u.text();try{S=JSON.parse(S)}catch{}return{error:S,response:u}}return{GET(a,o){return h(a,{...o,method:"GET"})},PUT(a,o){return h(a,{...o,method:"PUT"})},POST(a,o){return h(a,{...o,method:"POST"})},DELETE(a,o){return h(a,{...o,method:"DELETE"})},OPTIONS(a,o){return h(a,{...o,method:"OPTIONS"})},HEAD(a,o){return h(a,{...o,method:"HEAD"})},PATCH(a,o){return h(a,{...o,method:"PATCH"})},TRACE(a,o){return h(a,{...o,method:"TRACE"})},use(...a){for(let o of a)if(o){if(typeof o!="object"||!("onRequest"in o||"onResponse"in o))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");d.push(o)}},eject(...a){for(let o of a){let m=d.indexOf(o);m!==-1&&d.splice(m,1)}}}}var O=class{constructor(e,t){this.client=e,this.url=t}GET(e){return this.client.GET(this.url,e)}PUT(e){return this.client.PUT(this.url,e)}POST(e){return this.client.POST(this.url,e)}DELETE(e){return this.client.DELETE(this.url,e)}OPTIONS(e){return this.client.OPTIONS(this.url,e)}HEAD(e){return this.client.HEAD(this.url,e)}PATCH(e){return this.client.PATCH(this.url,e)}TRACE(e){return this.client.TRACE(this.url,e)}},z=class{constructor(){this.client=null}get(e,t){let i=new O(e,t);return this.client[t]=i,i}};function F(n){let e=new z,t=new Proxy(n,e);function i(){}i.prototype=t;let r=new i;return e.client=r,r}function K(n){return F(H(n))}function w(n,e,t){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`${n}=${t?.allowReserved===!0?e:encodeURIComponent(e)}`}function I(n,e,t){if(!e||typeof e!="object")return"";let i=[],r={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(let c in e)i.push(c,t.allowReserved===!0?e[c]:encodeURIComponent(e[c]));let l=i.join(",");switch(t.style){case"form":return`${n}=${l}`;case"label":return`.${l}`;case"matrix":return`;${n}=${l}`;default:return l}}for(let l in e){let c=t.style==="deepObject"?`${n}[${l}]`:l;i.push(w(c,e[l],t))}let s=i.join(r);return t.style==="label"||t.style==="matrix"?`${r}${s}`:s}function L(n,e,t){if(!Array.isArray(e))return"";if(t.explode===!1){let s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",l=(t.allowReserved===!0?e:e.map(c=>encodeURIComponent(c))).join(s);switch(t.style){case"simple":return l;case"label":return`.${l}`;case"matrix":return`;${n}=${l}`;default:return`${n}=${l}`}}let i={simple:",",label:".",matrix:";"}[t.style]||"&",r=[];for(let s of e)t.style==="simple"||t.style==="label"?r.push(t.allowReserved===!0?s:encodeURIComponent(s)):r.push(w(n,s,t));return t.style==="label"||t.style==="matrix"?`${i}${r.join(i)}`:r.join(i)}function P(n){return function(t){let i=[];if(t&&typeof t=="object")for(let r in t){let s=t[r];if(s!=null){if(Array.isArray(s)){i.push(L(r,s,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof s=="object"){i.push(I(r,s,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}i.push(w(r,s,n))}}return i.join("&")}}function G(n,e){let t=n;for(let i of n.match(v)??[]){let r=i.substring(1,i.length-1),s=!1,l="simple";if(r.endsWith("*")&&(s=!0,r=r.substring(0,r.length-1)),r.startsWith(".")?(l="label",r=r.substring(1)):r.startsWith(";")&&(l="matrix",r=r.substring(1)),!e||e[r]===void 0||e[r]===null)continue;let c=e[r];if(Array.isArray(c)){t=t.replace(i,L(r,c,{style:l,explode:s}));continue}if(typeof c=="object"){t=t.replace(i,I(r,c,{style:l,explode:s}));continue}if(l==="matrix"){t=t.replace(i,`;${w(r,c)}`);continue}t=t.replace(i,l==="label"?`.${encodeURIComponent(c)}`:encodeURIComponent(c))}return t}function M(n){return n instanceof FormData?n:JSON.stringify(n)}function Q(n,e){let t=`${e.baseUrl}${n}`;e.params?.path&&(t=G(t,e.params.path));let i=e.querySerializer(e.params.query??{});return i.startsWith("?")&&(i=i.substring(1)),i&&(t+=`?${i}`),t}function J(...n){let e=new Headers;for(let t of n){if(!t||typeof t!="object")continue;let i=t instanceof Headers?t.entries():Object.entries(t);for(let[r,s]of i)if(s===null)e.delete(r);else if(Array.isArray(s))for(let l of s)e.append(r,l);else s!==void 0&&e.set(r,s)}return e}function D(n){return n.endsWith("/")?n.substring(0,n.length-1):n}export{Q as createFinalURL,K as createPathBasedClient,P as createQuerySerializer,H as default,M as defaultBodySerializer,G as defaultPathSerializer,J as mergeHeaders,W as randomID,D as removeTrailingSlash,L as serializeArrayParam,I as serializeObjectParam,w as serializePrimitiveParam,F as wrapAsPathBasedClient};
var v=/\{[^{}]+\}/g;function W(){return Math.random().toString(36).slice(2,11)}function H(n){let{baseUrl:e="",Request:t=globalThis.Request,fetch:i=globalThis.fetch,querySerializer:r,bodySerializer:o,headers:l,...c}={...n};e=D(e);let d=[];async function h(a,s){let{baseUrl:m,fetch:C=i,Request:_=t,headers:N,params:b={},parseAs:T="json",querySerializer:R,bodySerializer:q=o??M,body:U,...j}=s||{};m&&(e=D(m));let x=typeof r=="function"?r:P(r);R&&(x=typeof R=="function"?R:P({...typeof r=="object"?r:{},...R}));let E=U===void 0?void 0:q(U),k=E===void 0||E instanceof FormData?{}:{"Content-Type":"application/json"},B={redirect:"follow",...c,...j,body:E,headers:J(k,l,N,b.header)},g,A,p=new t(Q(a,{baseUrl:e,params:b,querySerializer:x}),B);for(let f in j)f in p||(p[f]=j[f]);if(d.length){g=W(),A=Object.freeze({baseUrl:e,fetch:C,parseAs:T,querySerializer:x,bodySerializer:q});for(let f of d)if(f&&typeof f=="object"&&typeof f.onRequest=="function"){let y=await f.onRequest({request:p,schemaPath:a,params:b,options:A,id:g});if(y){if(!(y instanceof t))throw new Error("onRequest: must return new Request() when modifying the request");p=y}}}let u=await C(p);if(d.length)for(let f=d.length-1;f>=0;f--){let y=d[f];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){let $=await y.onResponse({request:p,response:u,schemaPath:a,params:b,options:A,id:g});if($){if(!($ instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");u=$}}}if(u.status===204||u.headers.get("Content-Length")==="0")return u.ok?{data:{},response:u}:{error:{},response:u};if(u.ok)return T==="stream"?{data:u.body,response:u}:{data:await u[T](),response:u};let S=await u.text();try{S=JSON.parse(S)}catch{}return{error:S,response:u}}return{GET(a,s){return h(a,{...s,method:"GET"})},PUT(a,s){return h(a,{...s,method:"PUT"})},POST(a,s){return h(a,{...s,method:"POST"})},DELETE(a,s){return h(a,{...s,method:"DELETE"})},OPTIONS(a,s){return h(a,{...s,method:"OPTIONS"})},HEAD(a,s){return h(a,{...s,method:"HEAD"})},PATCH(a,s){return h(a,{...s,method:"PATCH"})},TRACE(a,s){return h(a,{...s,method:"TRACE"})},use(...a){for(let s of a)if(s){if(typeof s!="object"||!("onRequest"in s||"onResponse"in s))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");d.push(s)}},eject(...a){for(let s of a){let m=d.indexOf(s);m!==-1&&d.splice(m,1)}}}}var O=class{constructor(e,t){this.client=e,this.url=t}GET(e){return this.client.GET(this.url,e)}PUT(e){return this.client.PUT(this.url,e)}POST(e){return this.client.POST(this.url,e)}DELETE(e){return this.client.DELETE(this.url,e)}OPTIONS(e){return this.client.OPTIONS(this.url,e)}HEAD(e){return this.client.HEAD(this.url,e)}PATCH(e){return this.client.PATCH(this.url,e)}TRACE(e){return this.client.TRACE(this.url,e)}},z=class{constructor(){this.client=null}get(e,t){let i=new O(e,t);return this.client[t]=i,i}};function F(n){let e=new z,t=new Proxy(n,e);function i(){}i.prototype=t;let r=new i;return e.client=r,r}function K(n){return F(H(n))}function w(n,e,t){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`${n}=${t?.allowReserved===!0?e:encodeURIComponent(e)}`}function I(n,e,t){if(!e||typeof e!="object")return"";let i=[],r={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(let c in e)i.push(c,t.allowReserved===!0?e[c]:encodeURIComponent(e[c]));let l=i.join(",");switch(t.style){case"form":return`${n}=${l}`;case"label":return`.${l}`;case"matrix":return`;${n}=${l}`;default:return l}}for(let l in e){let c=t.style==="deepObject"?`${n}[${l}]`:l;i.push(w(c,e[l],t))}let o=i.join(r);return t.style==="label"||t.style==="matrix"?`${r}${o}`:o}function L(n,e,t){if(!Array.isArray(e))return"";if(t.explode===!1){let o={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",l=(t.allowReserved===!0?e:e.map(c=>encodeURIComponent(c))).join(o);switch(t.style){case"simple":return l;case"label":return`.${l}`;case"matrix":return`;${n}=${l}`;default:return`${n}=${l}`}}let i={simple:",",label:".",matrix:";"}[t.style]||"&",r=[];for(let o of e)t.style==="simple"||t.style==="label"?r.push(t.allowReserved===!0?o:encodeURIComponent(o)):r.push(w(n,o,t));return t.style==="label"||t.style==="matrix"?`${i}${r.join(i)}`:r.join(i)}function P(n){return function(t){let i=[];if(t&&typeof t=="object")for(let r in t){let o=t[r];if(o!=null){if(Array.isArray(o)){if(o.length===0)continue;i.push(L(r,o,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof o=="object"){i.push(I(r,o,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}i.push(w(r,o,n))}}return i.join("&")}}function G(n,e){let t=n;for(let i of n.match(v)??[]){let r=i.substring(1,i.length-1),o=!1,l="simple";if(r.endsWith("*")&&(o=!0,r=r.substring(0,r.length-1)),r.startsWith(".")?(l="label",r=r.substring(1)):r.startsWith(";")&&(l="matrix",r=r.substring(1)),!e||e[r]===void 0||e[r]===null)continue;let c=e[r];if(Array.isArray(c)){t=t.replace(i,L(r,c,{style:l,explode:o}));continue}if(typeof c=="object"){t=t.replace(i,I(r,c,{style:l,explode:o}));continue}if(l==="matrix"){t=t.replace(i,`;${w(r,c)}`);continue}t=t.replace(i,l==="label"?`.${encodeURIComponent(c)}`:encodeURIComponent(c))}return t}function M(n){return n instanceof FormData?n:JSON.stringify(n)}function Q(n,e){let t=`${e.baseUrl}${n}`;e.params?.path&&(t=G(t,e.params.path));let i=e.querySerializer(e.params.query??{});return i.startsWith("?")&&(i=i.substring(1)),i&&(t+=`?${i}`),t}function J(...n){let e=new Headers;for(let t of n){if(!t||typeof t!="object")continue;let i=t instanceof Headers?t.entries():Object.entries(t);for(let[r,o]of i)if(o===null)e.delete(r);else if(Array.isArray(o))for(let l of o)e.append(r,l);else o!==void 0&&e.set(r,o)}return e}function D(n){return n.endsWith("/")?n.substring(0,n.length-1):n}export{Q as createFinalURL,K as createPathBasedClient,P as createQuerySerializer,H as default,M as defaultBodySerializer,G as defaultPathSerializer,J as mergeHeaders,W as randomID,D as removeTrailingSlash,L as serializeArrayParam,I as serializeObjectParam,w as serializePrimitiveParam,F as wrapAsPathBasedClient};
{
"name": "openapi-fetch",
"description": "Fast, type-safe fetch client for your OpenAPI schema. Only 6 kb (min). Works with React, Vue, Svelte, or vanilla JS.",
"version": "0.12.2",
"version": "0.12.3",
"author": {

@@ -63,3 +63,3 @@ "name": "Drew Powers",

"vite": "^5.4.6",
"openapi-typescript": "^7.4.1"
"openapi-typescript": "^7.4.2"
},

@@ -66,0 +66,0 @@ "scripts": {

@@ -439,2 +439,5 @@ // settings & const

if (Array.isArray(value)) {
if (value.length === 0) {
continue;
}
search.push(

@@ -441,0 +444,0 @@ serializeArrayParam(name, value, {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc