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.9.6 to 0.9.7

6

CHANGELOG.md
# openapi-fetch
## 0.9.7
### Patch Changes
- [#1672](https://github.com/drwpow/openapi-typescript/pull/1672) [`64cb619`](https://github.com/drwpow/openapi-typescript/commit/64cb6193ddd94523636fd55ba308117f2614a2e2) Thanks [@jaredLunde](https://github.com/jaredLunde)! - Fixes issue where native properties were not excluded from custom properties in the CustomRequest class
## 0.9.6

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

2

dist/index.js

@@ -17,3 +17,3 @@ // settings & const

for (const key in init) {
if (!this[key]) {
if (!(key in this)) {
this[key] = init[key];

@@ -20,0 +20,0 @@ }

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

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

@@ -6,0 +6,0 @@ "name": "Drew Powers",

@@ -17,3 +17,3 @@ // settings & const

for (const key in init) {
if (!this[key]) {
if (!(key in this)) {
this[key] = init[key];

@@ -20,0 +20,0 @@ }

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