fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2029 from henry-encord/add-interceptor-indexes

authored by

Lubos and committed by
GitHub
743b1e2d 33a417f8

+238 -81
+6
.changeset/clever-numbers-train.md
··· 1 + --- 2 + "@hey-api/client-fetch": patch 3 + "@hey-api/client-next": patch 4 + --- 5 + 6 + feat: support referencing interceptors by index
+43 -12
docs/openapi-ts/clients/fetch.md
··· 154 154 155 155 ## Interceptors 156 156 157 - Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with `use` and removed with `eject`. Fetch API does not have the interceptor functionality, so we implement our own. Below is an example request interceptor 157 + Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with `use`, removed with `eject`, and updated wth `update`. The `use` and `update` methods will return the id of the interceptor for use with `eject` and `update`. Fetch API does not have the interceptor functionality, so we implement our own. Below is an example request interceptor 158 158 159 159 ::: code-group 160 160 161 161 ```js [use] 162 162 import { client } from 'client/client.gen'; 163 - 164 163 // Supports async functions 165 - client.interceptors.request.use(async (request) => { 164 + async function myInterceptor(request) { 166 165 // do something 167 166 return request; 168 - }); 167 + } 168 + interceptorId = client.interceptors.request.use(myInterceptor); 169 169 ``` 170 170 171 171 ```js [eject] 172 172 import { client } from 'client/client.gen'; 173 173 174 - client.interceptors.request.eject((request) => { 174 + // eject interceptor by interceptor id 175 + client.interceptors.request.eject(interceptorId); 176 + 177 + // eject interceptor by reference to interceptor function 178 + client.interceptors.request.eject(myInterceptor); 179 + ``` 180 + 181 + ```js [update] 182 + import { client } from 'client/client.gen'; 183 + 184 + async function myNewInterceptor(request) { 175 185 // do something 176 186 return request; 177 - }); 187 + } 188 + // update interceptor by interceptor id 189 + client.interceptors.request.update(interceptorId, myNewInterceptor); 190 + 191 + // update interceptor by reference to interceptor function 192 + client.interceptors.request.update(myInterceptor, myNewInterceptor); 178 193 ``` 179 194 180 195 ::: ··· 185 200 186 201 ```js [use] 187 202 import { client } from 'client/client.gen'; 188 - 189 - client.interceptors.response.use((response) => { 203 + async function myInterceptor(response) { 190 204 // do something 191 205 return response; 192 - }); 206 + } 207 + // Supports async functions 208 + interceptorId = client.interceptors.response.use(myInterceptor); 193 209 ``` 194 210 195 211 ```js [eject] 196 212 import { client } from 'client/client.gen'; 197 213 198 - client.interceptors.response.eject((response) => { 214 + // eject interceptor by interceptor id 215 + client.interceptors.response.eject(interceptorId); 216 + 217 + // eject interceptor by reference to interceptor function 218 + client.interceptors.response.eject(myInterceptor); 219 + ``` 220 + 221 + ```js [update] 222 + import { client } from 'client/client.gen'; 223 + 224 + async function myNewInterceptor(response) { 199 225 // do something 200 226 return response; 201 - }); 227 + } 228 + // update interceptor by interceptor id 229 + client.interceptors.response.update(interceptorId, myNewInterceptor); 230 + 231 + // update interceptor by reference to interceptor function 232 + client.interceptors.response.update(myInterceptor, myNewInterceptor); 202 233 ``` 203 234 204 235 ::: 205 236 206 237 ::: tip 207 - To eject, you must provide a reference to the function that was passed to `use()`. 238 + To eject, you must provide the id or reference of the interceptor passed to `use()`, the id is the value returned by `use()` and `update()`. 208 239 ::: 209 240 210 241 ## Auth
+45 -12
docs/openapi-ts/clients/next-js.md
··· 148 148 149 149 ## Interceptors 150 150 151 - Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with `use` and removed with `eject`. Fetch API does not have the interceptor functionality, so we implement our own. Below is an example request interceptor 151 + Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with `use`, removed with `eject`, and updated wth `update`. The `use` and `update` methods will return the id of the interceptor for use with `eject` and `update`. Fetch API does not have the interceptor functionality, so we implement our own. Below is an example request interceptor 152 152 153 153 ::: code-group 154 154 155 155 ```js [use] 156 156 import { client } from 'client/client.gen'; 157 - 158 157 // Supports async functions 159 - client.interceptors.request.use(async (options) => { 158 + async function myInterceptor(request) { 160 159 // do something 161 - }); 160 + return request; 161 + } 162 + interceptorId = client.interceptors.request.use(myInterceptor); 162 163 ``` 163 164 164 165 ```js [eject] 165 166 import { client } from 'client/client.gen'; 166 167 167 - client.interceptors.request.eject((options) => { 168 + // eject interceptor by interceptor id 169 + client.interceptors.request.eject(interceptorId); 170 + 171 + // eject interceptor by reference to interceptor function 172 + client.interceptors.request.eject(myInterceptor); 173 + ``` 174 + 175 + ```js [update] 176 + import { client } from 'client/client.gen'; 177 + 178 + async function myNewInterceptor(request) { 168 179 // do something 169 - }); 180 + return request; 181 + } 182 + // update interceptor by interceptor id 183 + client.interceptors.request.update(interceptorId, myNewInterceptor); 184 + 185 + // update interceptor by reference to interceptor function 186 + client.interceptors.request.update(myInterceptor, myNewInterceptor); 170 187 ``` 171 188 172 189 ::: ··· 177 194 178 195 ```js [use] 179 196 import { client } from 'client/client.gen'; 180 - 181 - client.interceptors.response.use((response) => { 197 + async function myInterceptor(response) { 182 198 // do something 183 199 return response; 184 - }); 200 + } 201 + // Supports async functions 202 + interceptorId = client.interceptors.response.use(myInterceptor); 185 203 ``` 186 204 187 205 ```js [eject] 188 206 import { client } from 'client/client.gen'; 189 207 190 - client.interceptors.response.eject((response) => { 208 + // eject interceptor by interceptor id 209 + client.interceptors.response.eject(interceptorId); 210 + 211 + // eject interceptor by reference to interceptor function 212 + client.interceptors.response.eject(myInterceptor); 213 + ``` 214 + 215 + ```js [update] 216 + import { client } from 'client/client.gen'; 217 + 218 + async function myNewInterceptor(response) { 191 219 // do something 192 220 return response; 193 - }); 221 + } 222 + // update interceptor by interceptor id 223 + client.interceptors.response.update(interceptorId, myNewInterceptor); 224 + 225 + // update interceptor by reference to interceptor function 226 + client.interceptors.response.update(myInterceptor, myNewInterceptor); 194 227 ``` 195 228 196 229 ::: 197 230 198 231 ::: tip 199 - To eject, you must provide a reference to the function that was passed to `use()`. 232 + To eject, you must provide the id or reference of the interceptor passed to `use()`, the id is the value returned by `use()` and `update()`. 200 233 ::: 201 234 202 235 ## Auth
+9 -3
packages/client-custom/src/client.ts
··· 65 65 let request = new Request(url, requestInit); 66 66 67 67 for (const fn of interceptors.request._fns) { 68 - request = await fn(request, opts); 68 + if (fn) { 69 + request = await fn(request, opts); 70 + } 69 71 } 70 72 71 73 // fetch must be assigned here, otherwise it would throw the error: ··· 74 76 let response = await _fetch(request); 75 77 76 78 for (const fn of interceptors.response._fns) { 77 - response = await fn(response, request, opts); 79 + if (fn) { 80 + response = await fn(response, request, opts); 81 + } 78 82 } 79 83 80 84 const result = { ··· 133 137 let finalError = error; 134 138 135 139 for (const fn of interceptors.error._fns) { 136 - finalError = (await fn(error, response, request, opts)) as string; 140 + if (fn) { 141 + finalError = (await fn(error, response, request, opts)) as string; 142 + } 137 143 } 138 144 139 145 finalError = finalError || ({} as string);
+26 -7
packages/client-custom/src/utils.ts
··· 322 322 ) => Res | Promise<Res>; 323 323 324 324 class Interceptors<Interceptor> { 325 - _fns: Interceptor[]; 325 + _fns: (Interceptor | null)[]; 326 326 327 327 constructor() { 328 328 this._fns = []; ··· 332 332 this._fns = []; 333 333 } 334 334 335 - exists(fn: Interceptor) { 336 - return this._fns.indexOf(fn) !== -1; 335 + getInterceptorIndex(id: number | Interceptor): number { 336 + if (typeof id === 'number') { 337 + return this._fns[id] ? id : -1; 338 + } else { 339 + return this._fns.indexOf(id); 340 + } 341 + } 342 + exists(id: number | Interceptor) { 343 + const index = this.getInterceptorIndex(id); 344 + return !!this._fns[index]; 345 + } 346 + 347 + eject(id: number | Interceptor) { 348 + const index = this.getInterceptorIndex(id); 349 + if (this._fns[index]) { 350 + this._fns[index] = null; 351 + } 337 352 } 338 353 339 - eject(fn: Interceptor) { 340 - const index = this._fns.indexOf(fn); 341 - if (index !== -1) { 342 - this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; 354 + update(id: number | Interceptor, fn: Interceptor) { 355 + const index = this.getInterceptorIndex(id); 356 + if (this._fns[index]) { 357 + this._fns[index] = fn; 358 + return id; 359 + } else { 360 + return false; 343 361 } 344 362 } 345 363 346 364 use(fn: Interceptor) { 347 365 this._fns = [...this._fns, fn]; 366 + return this._fns.length - 1; 348 367 } 349 368 } 350 369
+9 -3
packages/client-fetch/src/client.ts
··· 65 65 let request = new Request(url, requestInit); 66 66 67 67 for (const fn of interceptors.request._fns) { 68 - request = await fn(request, opts); 68 + if (fn) { 69 + request = await fn(request, opts); 70 + } 69 71 } 70 72 71 73 // fetch must be assigned here, otherwise it would throw the error: ··· 74 76 let response = await _fetch(request); 75 77 76 78 for (const fn of interceptors.response._fns) { 77 - response = await fn(response, request, opts); 79 + if (fn) { 80 + response = await fn(response, request, opts); 81 + } 78 82 } 79 83 80 84 const result = { ··· 133 137 let finalError = error; 134 138 135 139 for (const fn of interceptors.error._fns) { 136 - finalError = (await fn(error, response, request, opts)) as string; 140 + if (fn) { 141 + finalError = (await fn(error, response, request, opts)) as string; 142 + } 137 143 } 138 144 139 145 finalError = finalError || ({} as string);
+26 -7
packages/client-fetch/src/utils.ts
··· 322 322 ) => Res | Promise<Res>; 323 323 324 324 class Interceptors<Interceptor> { 325 - _fns: Interceptor[]; 325 + _fns: (Interceptor | null)[]; 326 326 327 327 constructor() { 328 328 this._fns = []; ··· 332 332 this._fns = []; 333 333 } 334 334 335 - exists(fn: Interceptor) { 336 - return this._fns.indexOf(fn) !== -1; 335 + getInterceptorIndex(id: number | Interceptor): number { 336 + if (typeof id === 'number') { 337 + return this._fns[id] ? id : -1; 338 + } else { 339 + return this._fns.indexOf(id); 340 + } 341 + } 342 + exists(id: number | Interceptor) { 343 + const index = this.getInterceptorIndex(id); 344 + return !!this._fns[index]; 345 + } 346 + 347 + eject(id: number | Interceptor) { 348 + const index = this.getInterceptorIndex(id); 349 + if (this._fns[index]) { 350 + this._fns[index] = null; 351 + } 337 352 } 338 353 339 - eject(fn: Interceptor) { 340 - const index = this._fns.indexOf(fn); 341 - if (index !== -1) { 342 - this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; 354 + update(id: number | Interceptor, fn: Interceptor) { 355 + const index = this.getInterceptorIndex(id); 356 + if (this._fns[index]) { 357 + this._fns[index] = fn; 358 + return id; 359 + } else { 360 + return false; 343 361 } 344 362 } 345 363 346 364 use(fn: Interceptor) { 347 365 this._fns = [...this._fns, fn]; 366 + return this._fns.length - 1; 348 367 } 349 368 } 350 369
+9 -3
packages/client-next/src/client.ts
··· 52 52 } 53 53 54 54 for (const fn of interceptors.request._fns) { 55 - await fn(opts); 55 + if (fn) { 56 + await fn(opts); 57 + } 56 58 } 57 59 58 60 const url = buildUrl(opts); ··· 65 67 }); 66 68 67 69 for (const fn of interceptors.response._fns) { 68 - response = await fn(response, opts); 70 + if (fn) { 71 + response = await fn(response, opts); 72 + } 69 73 } 70 74 71 75 const result = { ··· 123 127 let finalError = error; 124 128 125 129 for (const fn of interceptors.error._fns) { 126 - finalError = (await fn(error, response, opts)) as string; 130 + if (fn) { 131 + finalError = (await fn(error, response, opts)) as string; 132 + } 127 133 } 128 134 129 135 finalError = finalError || ({} as string);
+26 -7
packages/client-next/src/utils.ts
··· 317 317 ) => Res | Promise<Res>; 318 318 319 319 class Interceptors<Interceptor> { 320 - _fns: Interceptor[]; 320 + _fns: (Interceptor | null)[]; 321 321 322 322 constructor() { 323 323 this._fns = []; ··· 327 327 this._fns = []; 328 328 } 329 329 330 - exists(fn: Interceptor) { 331 - return this._fns.indexOf(fn) !== -1; 330 + getInterceptorIndex(id: number | Interceptor): number { 331 + if (typeof id === 'number') { 332 + return this._fns[id] ? id : -1; 333 + } else { 334 + return this._fns.indexOf(id); 335 + } 336 + } 337 + exists(id: number | Interceptor) { 338 + const index = this.getInterceptorIndex(id); 339 + return !!this._fns[index]; 340 + } 341 + 342 + eject(id: number | Interceptor) { 343 + const index = this.getInterceptorIndex(id); 344 + if (this._fns[index]) { 345 + this._fns[index] = null; 346 + } 332 347 } 333 348 334 - eject(fn: Interceptor) { 335 - const index = this._fns.indexOf(fn); 336 - if (index !== -1) { 337 - this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; 349 + update(id: number | Interceptor, fn: Interceptor) { 350 + const index = this.getInterceptorIndex(id); 351 + if (this._fns[index]) { 352 + this._fns[index] = fn; 353 + return id; 354 + } else { 355 + return false; 338 356 } 339 357 } 340 358 341 359 use(fn: Interceptor) { 342 360 this._fns = [...this._fns, fn]; 361 + return this._fns.length - 1; 343 362 } 344 363 } 345 364
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs
··· 1 - 'use strict';var A=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));},j=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},k={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>z(r,e,i)):z(r,e,a));}),r}},R={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},$={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},U=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 ","}},D=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(!r){let s=(t?i:i.map(l=>encodeURIComponent(l))).join(_(a));switch(a){case "label":return `.${s}`;case "matrix":return `;${e}=${s}`;case "simple":return s;default:return `${e}=${s}`}}let o=U(a),n=i.map(s=>a==="label"||a==="simple"?t?s:encodeURIComponent(s):y({allowReserved:t,name:e,value:s})).join(o);return a==="label"||a==="matrix"?o+n:n},y=({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)}`},q=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let s=[];Object.entries(i).forEach(([f,u])=>{s=[...s,f,t?u:encodeURIComponent(u)];});let l=s.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=D(a),n=Object.entries(i).map(([s,l])=>y({allowReserved:t,name:a==="deepObject"?`${e}[${s}]`:s,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var H=/\{[^{}]+\}/g,B=({path:t,url:r})=>{let e=r,a=r.match(H);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),s="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),s="label"):n.startsWith(";")&&(n=n.substring(1),s="matrix");let l=t[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:s,value:l}));continue}if(typeof l=="object"){e=e.replace(i,q({explode:o,name:n,style:s,value:l}));continue}if(s==="matrix"){e=e.replace(i,`;${y({name:n,value:l})}`);continue}let f=encodeURIComponent(s==="label"?`.${l}`:l);e=e.replace(i,f);}return e},P=({allowReserved:t,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let s=i[n];if(s!=null)if(Array.isArray(s)){let l=O({allowReserved:t,explode:true,name:n,style:"form",value:s,...r});l&&o.push(l);}else if(typeof s=="object"){let l=q({allowReserved:t,explode:true,name:n,style:"deepObject",value:s,...e});l&&o.push(l);}else {let l=y({allowReserved:t,name:n,value:s});l&&o.push(l);}}return o.join("&")},E=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},I=async({security:t,...r})=>{for(let e of t){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "cookie":r.headers.append("Cookie",`${i}=${a}`);break;case "header":default:r.headers.set(i,a);break}return}},S=t=>W({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:P(t.querySerializer),url:t.url}),W=({baseUrl:t,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(t??"")+o;r&&(n=B({path:r,url:n}));let s=e?a(e):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(n+=`?${s}`),n},C=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(t.headers,r.headers),e},x=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==void 0&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},h=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},v=()=>({error:new h,request:new h,response:new h}),N=P({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Q={"Content-Type":"application/json"},w=(t={})=>({...R,headers:Q,parseAs:"auto",querySerializer:N,...t});var J=(t={})=>{let r=C(w(),t),e=()=>({...r}),a=n=>(r=C(r,n),e()),i=v(),o=async n=>{let s={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};s.security&&await I({...s,security:s.security}),s.body&&s.bodySerializer&&(s.body=s.bodySerializer(s.body)),(s.body===void 0||s.body==="")&&s.headers.delete("Content-Type");let l=S(s),f={redirect:"follow",...s},u=new Request(l,f);for(let p of i.request._fns)u=await p(u,s);let T=s.fetch,c=await T(u);for(let p of i.response._fns)c=await p(c,u,s);let m={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...m};let p=(s.parseAs==="auto"?E(c.headers.get("Content-Type")):s.parseAs)??"json";if(p==="stream")return {data:c.body,...m};let b=await c[p]();return p==="json"&&(s.responseValidator&&await s.responseValidator(b),s.responseTransformer&&(b=await s.responseTransformer(b))),{data:b,...m}}let g=await c.text();try{g=JSON.parse(g);}catch{}let d=g;for(let p of i.error._fns)d=await p(g,c,u,s);if(d=d||{},s.throwOnError)throw d;return {error:d,...m}};return {buildUrl:S,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=J;exports.createConfig=w;exports.formDataBodySerializer=k;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=$;//# sourceMappingURL=index.cjs.map 1 + 'use strict';var j=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));},I=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},k={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}},R={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},$={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>I(r,e,a)):I(r,e,i));}),r.toString()}},U=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 ","}},D=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(!r){let n=(t?a:a.map(l=>encodeURIComponent(l))).join(_(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let o=U(i),s=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):y({allowReserved:t,name:e,value:n})).join(o);return i==="label"||i==="matrix"?o+s:s},y=({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)}`},q=({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(([f,p])=>{n=[...n,f,t?p:encodeURIComponent(p)];});let l=n.join(",");switch(i){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=D(i),s=Object.entries(a).map(([n,l])=>y({allowReserved:t,name:i==="deepObject"?`${e}[${n}]`:n,value:l})).join(o);return i==="label"||i==="matrix"?o+s:s};var H=/\{[^{}]+\}/g,B=({path:t,url:r})=>{let e=r,i=r.match(H);if(i)for(let a of i){let o=false,s=a.substring(1,a.length-1),n="simple";s.endsWith("*")&&(o=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 l=t[s];if(l==null)continue;if(Array.isArray(l)){e=e.replace(a,O({explode:o,name:s,style:n,value:l}));continue}if(typeof l=="object"){e=e.replace(a,q({explode:o,name:s,style:n,value:l}));continue}if(n==="matrix"){e=e.replace(a,`;${y({name:s,value:l})}`);continue}let f=encodeURIComponent(n==="label"?`.${l}`:l);e=e.replace(a,f);}return e},A=({allowReserved:t,array:r,object:e}={})=>a=>{let o=[];if(a&&typeof a=="object")for(let s in a){let n=a[s];if(n!=null)if(Array.isArray(n)){let l=O({allowReserved:t,explode:true,name:s,style:"form",value:n,...r});l&&o.push(l);}else if(typeof n=="object"){let l=q({allowReserved:t,explode:true,name:s,style:"deepObject",value:n,...e});l&&o.push(l);}else {let l=y({allowReserved:t,name:s,value:n});l&&o.push(l);}}return o.join("&")},P=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},E=async({security:t,...r})=>{for(let e of t){let i=await j(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 "cookie":r.headers.append("Cookie",`${a}=${i}`);break;case "header":default:r.headers.set(a,i);break}return}},S=t=>W({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:A(t.querySerializer),url:t.url}),W=({baseUrl:t,path:r,query:e,querySerializer:i,url:a})=>{let o=a.startsWith("/")?a:`/${a}`,s=(t??"")+o;r&&(s=B({path:r,url:s}));let n=e?i(e):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(s+=`?${n}`),s},x=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=C(t.headers,r.headers),e},C=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let i=e instanceof Headers?e.entries():Object.entries(e);for(let[a,o]of i)if(o===null)r.delete(a);else if(Array.isArray(o))for(let s of o)r.append(a,s);else o!==void 0&&r.set(a,typeof o=="object"?JSON.stringify(o):o);}return r},h=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let e=this.getInterceptorIndex(r);return !!this._fns[e]}eject(r){let e=this.getInterceptorIndex(r);this._fns[e]&&(this._fns[e]=null);}update(r,e){let i=this.getInterceptorIndex(r);return this._fns[i]?(this._fns[i]=e,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},v=()=>({error:new h,request:new h,response:new h}),N=A({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Q={"Content-Type":"application/json"},w=(t={})=>({...R,headers:Q,parseAs:"auto",querySerializer:N,...t});var J=(t={})=>{let r=x(w(),t),e=()=>({...r}),i=s=>(r=x(r,s),e()),a=v(),o=async s=>{let n={...r,...s,fetch:s.fetch??r.fetch??globalThis.fetch,headers:C(r.headers,s.headers)};n.security&&await E({...n,security:n.security}),n.body&&n.bodySerializer&&(n.body=n.bodySerializer(n.body)),(n.body===void 0||n.body==="")&&n.headers.delete("Content-Type");let l=S(n),f={redirect:"follow",...n},p=new Request(l,f);for(let c of a.request._fns)c&&(p=await c(p,n));let T=n.fetch,u=await T(p);for(let c of a.response._fns)c&&(u=await c(u,p,n));let m={request:p,response:u};if(u.ok){if(u.status===204||u.headers.get("Content-Length")==="0")return {data:{},...m};let c=(n.parseAs==="auto"?P(u.headers.get("Content-Type")):n.parseAs)??"json";if(c==="stream")return {data:u.body,...m};let b=await u[c]();return c==="json"&&(n.responseValidator&&await n.responseValidator(b),n.responseTransformer&&(b=await n.responseTransformer(b))),{data:b,...m}}let g=await u.text();try{g=JSON.parse(g);}catch{}let d=g;for(let c of a.error._fns)c&&(d=await c(g,u,p,n));if(d=d||{},n.throwOnError)throw d;return {error:d,...m}};return {buildUrl:S,connect:s=>o({...s,method:"CONNECT"}),delete:s=>o({...s,method:"DELETE"}),get:s=>o({...s,method:"GET"}),getConfig:e,head:s=>o({...s,method:"HEAD"}),interceptors:a,options:s=>o({...s,method:"OPTIONS"}),patch:s=>o({...s,method:"PATCH"}),post:s=>o({...s,method:"POST"}),put:s=>o({...s,method:"PUT"}),request:o,setConfig:i,trace:s=>o({...s,method:"TRACE"})}};exports.createClient=J;exports.createConfig=w;exports.formDataBodySerializer=k;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=$;//# sourceMappingURL=index.cjs.map 2 2 //# sourceMappingURL=index.cjs.map
+6 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts
··· 112 112 type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>; 113 113 type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>; 114 114 declare class Interceptors<Interceptor> { 115 - _fns: Interceptor[]; 115 + _fns: (Interceptor | null)[]; 116 116 constructor(); 117 117 clear(): void; 118 - exists(fn: Interceptor): boolean; 119 - eject(fn: Interceptor): void; 120 - use(fn: Interceptor): void; 118 + getInterceptorIndex(id: number | Interceptor): number; 119 + exists(id: number | Interceptor): boolean; 120 + eject(id: number | Interceptor): void; 121 + update(id: number | Interceptor, fn: Interceptor): number | false | Interceptor; 122 + use(fn: Interceptor): number; 121 123 } 122 124 interface Middleware<Req, Res, Err, Options> { 123 125 error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, 'eject' | 'use'>;
+6 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts
··· 112 112 type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>; 113 113 type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>; 114 114 declare class Interceptors<Interceptor> { 115 - _fns: Interceptor[]; 115 + _fns: (Interceptor | null)[]; 116 116 constructor(); 117 117 clear(): void; 118 - exists(fn: Interceptor): boolean; 119 - eject(fn: Interceptor): void; 120 - use(fn: Interceptor): void; 118 + getInterceptorIndex(id: number | Interceptor): number; 119 + exists(id: number | Interceptor): boolean; 120 + eject(id: number | Interceptor): void; 121 + update(id: number | Interceptor, fn: Interceptor): number | false | Interceptor; 122 + use(fn: Interceptor): number; 121 123 } 122 124 interface Middleware<Req, Res, Err, Options> { 123 125 error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, 'eject' | 'use'>;
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs
··· 1 - 'use strict';var A=async(s,r)=>{let e=typeof r=="function"?await r(s):r;if(e)return s.scheme==="bearer"?`Bearer ${e}`:s.scheme==="basic"?`Basic ${btoa(e)}`:e},w=(s,r,e)=>{typeof e=="string"||e instanceof Blob?s.append(r,e):s.append(r,JSON.stringify(e));},j=(s,r,e)=>{typeof e=="string"?s.append(r,e):s.append(r,JSON.stringify(e));},v={bodySerializer:s=>{let r=new FormData;return Object.entries(s).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>w(r,e,i)):w(r,e,a));}),r}},b={bodySerializer:s=>JSON.stringify(s,(r,e)=>typeof e=="bigint"?e.toString():e)},T={bodySerializer:s=>{let r=new URLSearchParams;return Object.entries(s).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},k=s=>{switch(s){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=s=>{switch(s){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},U=s=>{switch(s){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:s,explode:r,name:e,style:a,value:i})=>{if(!r){let t=(s?i:i.map(l=>encodeURIComponent(l))).join($(a));switch(a){case "label":return `.${t}`;case "matrix":return `;${e}=${t}`;case "simple":return t;default:return `${e}=${t}`}}let o=k(a),n=i.map(t=>a==="label"||a==="simple"?s?t:encodeURIComponent(t):d({allowReserved:s,name:e,value:t})).join(o);return a==="label"||a==="matrix"?o+n:n},d=({allowReserved:s,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}=${s?e:encodeURIComponent(e)}`},S=({allowReserved:s,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let t=[];Object.entries(i).forEach(([u,c])=>{t=[...t,u,s?c:encodeURIComponent(c)];});let l=t.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=U(a),n=Object.entries(i).map(([t,l])=>d({allowReserved:s,name:a==="deepObject"?`${e}[${t}]`:t,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var _=/\{[^{}]+\}/g,D=({path:s,url:r})=>{let e=r,a=r.match(_);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),t="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),t="label"):n.startsWith(";")&&(n=n.substring(1),t="matrix");let l=s[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:t,value:l}));continue}if(typeof l=="object"){e=e.replace(i,S({explode:o,name:n,style:t,value:l}));continue}if(t==="matrix"){e=e.replace(i,`;${d({name:n,value:l})}`);continue}let u=encodeURIComponent(t==="label"?`.${l}`:l);e=e.replace(i,u);}return e},q=({allowReserved:s,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let t=i[n];if(t!=null)if(Array.isArray(t)){let l=O({allowReserved:s,explode:true,name:n,style:"form",value:t,...r});l&&o.push(l);}else if(typeof t=="object"){let l=S({allowReserved:s,explode:true,name:n,style:"deepObject",value:t,...e});l&&o.push(l);}else {let l=d({allowReserved:s,name:n,value:t});l&&o.push(l);}}return o.join("&")},P=s=>{if(!s)return "stream";let r=s.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},E=async({security:s,...r})=>{for(let e of s){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "cookie":r.headers.append("Cookie",`${i}=${a}`);break;case "header":default:r.headers.set(i,a);break}return}},C=s=>H({baseUrl:s.baseUrl,path:s.path,query:s.query,querySerializer:typeof s.querySerializer=="function"?s.querySerializer:q(s.querySerializer),url:s.url}),H=({baseUrl:s,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(s??"")+o;r&&(n=D({path:r,url:n}));let t=e?a(e):"";return t.startsWith("?")&&(t=t.substring(1)),t&&(n+=`?${t}`),n},R=(s,r)=>{let e={...s,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(s.headers,r.headers),e},x=(...s)=>{let r=new Headers;for(let e of s){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==void 0&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},y=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},I=()=>({error:new y,request:new y,response:new y}),B=q({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),W={"Content-Type":"application/json"},z=(s={})=>({...b,headers:W,parseAs:"auto",querySerializer:B,...s});var N=(s={})=>{let r=R(z(),s),e=()=>({...r}),a=n=>(r=R(r,n),e()),i=I(),o=async n=>{let t={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};t.security&&await E({...t,security:t.security}),t.body&&t.bodySerializer&&(t.body=t.bodySerializer(t.body)),(t.body===void 0||t.body==="")&&t.headers.delete("Content-Type");for(let p of i.request._fns)await p(t);let l=C(t),u=t.fetch,c=await u(l,{...t,body:t.body});for(let p of i.response._fns)c=await p(c,t);let h={response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...h};let p=(t.parseAs==="auto"?P(c.headers.get("Content-Type")):t.parseAs)??"json";if(p==="stream")return {data:c.body,...h};let g=await c[p]();return p==="json"&&(t.responseValidator&&await t.responseValidator(g),t.responseTransformer&&(g=await t.responseTransformer(g))),{data:g,...h}}let m=await c.text();try{m=JSON.parse(m);}catch{}let f=m;for(let p of i.error._fns)f=await p(m,c,t);if(f=f||{},t.throwOnError)throw f;return {error:f,...h}};return {buildUrl:C,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=N;exports.createConfig=z;exports.formDataBodySerializer=v;exports.jsonBodySerializer=b;exports.urlSearchParamsBodySerializer=T;//# sourceMappingURL=index.cjs.map 1 + 'use strict';var A=async(n,r)=>{let e=typeof r=="function"?await r(n):r;if(e)return n.scheme==="bearer"?`Bearer ${e}`:n.scheme==="basic"?`Basic ${btoa(e)}`:e},w=(n,r,e)=>{typeof e=="string"||e instanceof Blob?n.append(r,e):n.append(r,JSON.stringify(e));},j=(n,r,e)=>{typeof e=="string"?n.append(r,e):n.append(r,JSON.stringify(e));},v={bodySerializer:n=>{let r=new FormData;return Object.entries(n).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>w(r,e,a)):w(r,e,i));}),r}},b={bodySerializer:n=>JSON.stringify(n,(r,e)=>typeof e=="bigint"?e.toString():e)},T={bodySerializer:n=>{let r=new URLSearchParams;return Object.entries(n).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>j(r,e,a)):j(r,e,i));}),r.toString()}},k=n=>{switch(n){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=n=>{switch(n){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},U=n=>{switch(n){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:n,explode:r,name:e,style:i,value:a})=>{if(!r){let t=(n?a:a.map(l=>encodeURIComponent(l))).join($(i));switch(i){case "label":return `.${t}`;case "matrix":return `;${e}=${t}`;case "simple":return t;default:return `${e}=${t}`}}let o=k(i),s=a.map(t=>i==="label"||i==="simple"?n?t:encodeURIComponent(t):d({allowReserved:n,name:e,value:t})).join(o);return i==="label"||i==="matrix"?o+s:s},d=({allowReserved:n,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}=${n?e:encodeURIComponent(e)}`},S=({allowReserved:n,explode:r,name:e,style:i,value:a})=>{if(a instanceof Date)return `${e}=${a.toISOString()}`;if(i!=="deepObject"&&!r){let t=[];Object.entries(a).forEach(([p,c])=>{t=[...t,p,n?c:encodeURIComponent(c)];});let l=t.join(",");switch(i){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=U(i),s=Object.entries(a).map(([t,l])=>d({allowReserved:n,name:i==="deepObject"?`${e}[${t}]`:t,value:l})).join(o);return i==="label"||i==="matrix"?o+s:s};var _=/\{[^{}]+\}/g,D=({path:n,url:r})=>{let e=r,i=r.match(_);if(i)for(let a of i){let o=false,s=a.substring(1,a.length-1),t="simple";s.endsWith("*")&&(o=true,s=s.substring(0,s.length-1)),s.startsWith(".")?(s=s.substring(1),t="label"):s.startsWith(";")&&(s=s.substring(1),t="matrix");let l=n[s];if(l==null)continue;if(Array.isArray(l)){e=e.replace(a,O({explode:o,name:s,style:t,value:l}));continue}if(typeof l=="object"){e=e.replace(a,S({explode:o,name:s,style:t,value:l}));continue}if(t==="matrix"){e=e.replace(a,`;${d({name:s,value:l})}`);continue}let p=encodeURIComponent(t==="label"?`.${l}`:l);e=e.replace(a,p);}return e},I=({allowReserved:n,array:r,object:e}={})=>a=>{let o=[];if(a&&typeof a=="object")for(let s in a){let t=a[s];if(t!=null)if(Array.isArray(t)){let l=O({allowReserved:n,explode:true,name:s,style:"form",value:t,...r});l&&o.push(l);}else if(typeof t=="object"){let l=S({allowReserved:n,explode:true,name:s,style:"deepObject",value:t,...e});l&&o.push(l);}else {let l=d({allowReserved:n,name:s,value:t});l&&o.push(l);}}return o.join("&")},q=n=>{if(!n)return "stream";let r=n.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},P=async({security:n,...r})=>{for(let e of n){let i=await A(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 "cookie":r.headers.append("Cookie",`${a}=${i}`);break;case "header":default:r.headers.set(a,i);break}return}},x=n=>H({baseUrl:n.baseUrl,path:n.path,query:n.query,querySerializer:typeof n.querySerializer=="function"?n.querySerializer:I(n.querySerializer),url:n.url}),H=({baseUrl:n,path:r,query:e,querySerializer:i,url:a})=>{let o=a.startsWith("/")?a:`/${a}`,s=(n??"")+o;r&&(s=D({path:r,url:s}));let t=e?i(e):"";return t.startsWith("?")&&(t=t.substring(1)),t&&(s+=`?${t}`),s},C=(n,r)=>{let e={...n,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=R(n.headers,r.headers),e},R=(...n)=>{let r=new Headers;for(let e of n){if(!e||typeof e!="object")continue;let i=e instanceof Headers?e.entries():Object.entries(e);for(let[a,o]of i)if(o===null)r.delete(a);else if(Array.isArray(o))for(let s of o)r.append(a,s);else o!==void 0&&r.set(a,typeof o=="object"?JSON.stringify(o):o);}return r},y=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let e=this.getInterceptorIndex(r);return !!this._fns[e]}eject(r){let e=this.getInterceptorIndex(r);this._fns[e]&&(this._fns[e]=null);}update(r,e){let i=this.getInterceptorIndex(r);return this._fns[i]?(this._fns[i]=e,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},E=()=>({error:new y,request:new y,response:new y}),B=I({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),W={"Content-Type":"application/json"},z=(n={})=>({...b,headers:W,parseAs:"auto",querySerializer:B,...n});var N=(n={})=>{let r=C(z(),n),e=()=>({...r}),i=s=>(r=C(r,s),e()),a=E(),o=async s=>{let t={...r,...s,fetch:s.fetch??r.fetch??globalThis.fetch,headers:R(r.headers,s.headers)};t.security&&await P({...t,security:t.security}),t.body&&t.bodySerializer&&(t.body=t.bodySerializer(t.body)),(t.body===void 0||t.body==="")&&t.headers.delete("Content-Type");for(let u of a.request._fns)u&&await u(t);let l=x(t),p=t.fetch,c=await p(l,{...t,body:t.body});for(let u of a.response._fns)u&&(c=await u(c,t));let h={response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...h};let u=(t.parseAs==="auto"?q(c.headers.get("Content-Type")):t.parseAs)??"json";if(u==="stream")return {data:c.body,...h};let g=await c[u]();return u==="json"&&(t.responseValidator&&await t.responseValidator(g),t.responseTransformer&&(g=await t.responseTransformer(g))),{data:g,...h}}let m=await c.text();try{m=JSON.parse(m);}catch{}let f=m;for(let u of a.error._fns)u&&(f=await u(m,c,t));if(f=f||{},t.throwOnError)throw f;return {error:f,...h}};return {buildUrl:x,connect:s=>o({...s,method:"CONNECT"}),delete:s=>o({...s,method:"DELETE"}),get:s=>o({...s,method:"GET"}),getConfig:e,head:s=>o({...s,method:"HEAD"}),interceptors:a,options:s=>o({...s,method:"OPTIONS"}),patch:s=>o({...s,method:"PATCH"}),post:s=>o({...s,method:"POST"}),put:s=>o({...s,method:"PUT"}),request:o,setConfig:i,trace:s=>o({...s,method:"TRACE"})}};exports.createClient=N;exports.createConfig=z;exports.formDataBodySerializer=v;exports.jsonBodySerializer=b;exports.urlSearchParamsBodySerializer=T;//# sourceMappingURL=index.cjs.map 2 2 //# sourceMappingURL=index.cjs.map
+6 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.d.cts
··· 112 112 type ReqInterceptor<Options> = (options: Options) => void | Promise<void>; 113 113 type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>; 114 114 declare class Interceptors<Interceptor> { 115 - _fns: Interceptor[]; 115 + _fns: (Interceptor | null)[]; 116 116 constructor(); 117 117 clear(): void; 118 - exists(fn: Interceptor): boolean; 119 - eject(fn: Interceptor): void; 120 - use(fn: Interceptor): void; 118 + getInterceptorIndex(id: number | Interceptor): number; 119 + exists(id: number | Interceptor): boolean; 120 + eject(id: number | Interceptor): void; 121 + update(id: number | Interceptor, fn: Interceptor): number | false | Interceptor; 122 + use(fn: Interceptor): number; 121 123 } 122 124 interface Middleware<Res, Err, Options> { 123 125 error: Pick<Interceptors<ErrInterceptor<Err, Res, Options>>, 'eject' | 'use'>;
+6 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.d.ts
··· 112 112 type ReqInterceptor<Options> = (options: Options) => void | Promise<void>; 113 113 type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>; 114 114 declare class Interceptors<Interceptor> { 115 - _fns: Interceptor[]; 115 + _fns: (Interceptor | null)[]; 116 116 constructor(); 117 117 clear(): void; 118 - exists(fn: Interceptor): boolean; 119 - eject(fn: Interceptor): void; 120 - use(fn: Interceptor): void; 118 + getInterceptorIndex(id: number | Interceptor): number; 119 + exists(id: number | Interceptor): boolean; 120 + eject(id: number | Interceptor): void; 121 + update(id: number | Interceptor, fn: Interceptor): number | false | Interceptor; 122 + use(fn: Interceptor): number; 121 123 } 122 124 interface Middleware<Res, Err, Options> { 123 125 error: Pick<Interceptors<ErrInterceptor<Err, Res, Options>>, 'eject' | 'use'>;
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/client-custom/bundle/client/index.cjs
··· 1 - 'use strict';var A=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));},j=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},k={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>z(r,e,i)):z(r,e,a));}),r}},R={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},$={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},U=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 ","}},D=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(!r){let s=(t?i:i.map(l=>encodeURIComponent(l))).join(_(a));switch(a){case "label":return `.${s}`;case "matrix":return `;${e}=${s}`;case "simple":return s;default:return `${e}=${s}`}}let o=U(a),n=i.map(s=>a==="label"||a==="simple"?t?s:encodeURIComponent(s):y({allowReserved:t,name:e,value:s})).join(o);return a==="label"||a==="matrix"?o+n:n},y=({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)}`},q=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let s=[];Object.entries(i).forEach(([f,u])=>{s=[...s,f,t?u:encodeURIComponent(u)];});let l=s.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=D(a),n=Object.entries(i).map(([s,l])=>y({allowReserved:t,name:a==="deepObject"?`${e}[${s}]`:s,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var H=/\{[^{}]+\}/g,B=({path:t,url:r})=>{let e=r,a=r.match(H);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),s="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),s="label"):n.startsWith(";")&&(n=n.substring(1),s="matrix");let l=t[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:s,value:l}));continue}if(typeof l=="object"){e=e.replace(i,q({explode:o,name:n,style:s,value:l}));continue}if(s==="matrix"){e=e.replace(i,`;${y({name:n,value:l})}`);continue}let f=encodeURIComponent(s==="label"?`.${l}`:l);e=e.replace(i,f);}return e},P=({allowReserved:t,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let s=i[n];if(s!=null)if(Array.isArray(s)){let l=O({allowReserved:t,explode:true,name:n,style:"form",value:s,...r});l&&o.push(l);}else if(typeof s=="object"){let l=q({allowReserved:t,explode:true,name:n,style:"deepObject",value:s,...e});l&&o.push(l);}else {let l=y({allowReserved:t,name:n,value:s});l&&o.push(l);}}return o.join("&")},E=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},I=async({security:t,...r})=>{for(let e of t){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "cookie":r.headers.append("Cookie",`${i}=${a}`);break;case "header":default:r.headers.set(i,a);break}return}},S=t=>W({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:P(t.querySerializer),url:t.url}),W=({baseUrl:t,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(t??"")+o;r&&(n=B({path:r,url:n}));let s=e?a(e):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(n+=`?${s}`),n},C=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(t.headers,r.headers),e},x=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==void 0&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},h=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},v=()=>({error:new h,request:new h,response:new h}),N=P({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Q={"Content-Type":"application/json"},w=(t={})=>({...R,headers:Q,parseAs:"auto",querySerializer:N,...t});var J=(t={})=>{let r=C(w(),t),e=()=>({...r}),a=n=>(r=C(r,n),e()),i=v(),o=async n=>{let s={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};s.security&&await I({...s,security:s.security}),s.body&&s.bodySerializer&&(s.body=s.bodySerializer(s.body)),(s.body===void 0||s.body==="")&&s.headers.delete("Content-Type");let l=S(s),f={redirect:"follow",...s},u=new Request(l,f);for(let p of i.request._fns)u=await p(u,s);let T=s.fetch,c=await T(u);for(let p of i.response._fns)c=await p(c,u,s);let m={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...m};let p=(s.parseAs==="auto"?E(c.headers.get("Content-Type")):s.parseAs)??"json";if(p==="stream")return {data:c.body,...m};let b=await c[p]();return p==="json"&&(s.responseValidator&&await s.responseValidator(b),s.responseTransformer&&(b=await s.responseTransformer(b))),{data:b,...m}}let g=await c.text();try{g=JSON.parse(g);}catch{}let d=g;for(let p of i.error._fns)d=await p(g,c,u,s);if(d=d||{},s.throwOnError)throw d;return {error:d,...m}};return {buildUrl:S,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=J;exports.createConfig=w;exports.formDataBodySerializer=k;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=$;//# sourceMappingURL=index.cjs.map 1 + 'use strict';var j=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));},I=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},k={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}},R={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},$={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>I(r,e,a)):I(r,e,i));}),r.toString()}},U=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 ","}},D=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(!r){let n=(t?a:a.map(l=>encodeURIComponent(l))).join(_(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let o=U(i),s=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):y({allowReserved:t,name:e,value:n})).join(o);return i==="label"||i==="matrix"?o+s:s},y=({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)}`},q=({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(([f,p])=>{n=[...n,f,t?p:encodeURIComponent(p)];});let l=n.join(",");switch(i){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=D(i),s=Object.entries(a).map(([n,l])=>y({allowReserved:t,name:i==="deepObject"?`${e}[${n}]`:n,value:l})).join(o);return i==="label"||i==="matrix"?o+s:s};var H=/\{[^{}]+\}/g,B=({path:t,url:r})=>{let e=r,i=r.match(H);if(i)for(let a of i){let o=false,s=a.substring(1,a.length-1),n="simple";s.endsWith("*")&&(o=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 l=t[s];if(l==null)continue;if(Array.isArray(l)){e=e.replace(a,O({explode:o,name:s,style:n,value:l}));continue}if(typeof l=="object"){e=e.replace(a,q({explode:o,name:s,style:n,value:l}));continue}if(n==="matrix"){e=e.replace(a,`;${y({name:s,value:l})}`);continue}let f=encodeURIComponent(n==="label"?`.${l}`:l);e=e.replace(a,f);}return e},A=({allowReserved:t,array:r,object:e}={})=>a=>{let o=[];if(a&&typeof a=="object")for(let s in a){let n=a[s];if(n!=null)if(Array.isArray(n)){let l=O({allowReserved:t,explode:true,name:s,style:"form",value:n,...r});l&&o.push(l);}else if(typeof n=="object"){let l=q({allowReserved:t,explode:true,name:s,style:"deepObject",value:n,...e});l&&o.push(l);}else {let l=y({allowReserved:t,name:s,value:n});l&&o.push(l);}}return o.join("&")},P=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},E=async({security:t,...r})=>{for(let e of t){let i=await j(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 "cookie":r.headers.append("Cookie",`${a}=${i}`);break;case "header":default:r.headers.set(a,i);break}return}},S=t=>W({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:A(t.querySerializer),url:t.url}),W=({baseUrl:t,path:r,query:e,querySerializer:i,url:a})=>{let o=a.startsWith("/")?a:`/${a}`,s=(t??"")+o;r&&(s=B({path:r,url:s}));let n=e?i(e):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(s+=`?${n}`),s},x=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=C(t.headers,r.headers),e},C=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let i=e instanceof Headers?e.entries():Object.entries(e);for(let[a,o]of i)if(o===null)r.delete(a);else if(Array.isArray(o))for(let s of o)r.append(a,s);else o!==void 0&&r.set(a,typeof o=="object"?JSON.stringify(o):o);}return r},h=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let e=this.getInterceptorIndex(r);return !!this._fns[e]}eject(r){let e=this.getInterceptorIndex(r);this._fns[e]&&(this._fns[e]=null);}update(r,e){let i=this.getInterceptorIndex(r);return this._fns[i]?(this._fns[i]=e,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},v=()=>({error:new h,request:new h,response:new h}),N=A({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Q={"Content-Type":"application/json"},w=(t={})=>({...R,headers:Q,parseAs:"auto",querySerializer:N,...t});var J=(t={})=>{let r=x(w(),t),e=()=>({...r}),i=s=>(r=x(r,s),e()),a=v(),o=async s=>{let n={...r,...s,fetch:s.fetch??r.fetch??globalThis.fetch,headers:C(r.headers,s.headers)};n.security&&await E({...n,security:n.security}),n.body&&n.bodySerializer&&(n.body=n.bodySerializer(n.body)),(n.body===void 0||n.body==="")&&n.headers.delete("Content-Type");let l=S(n),f={redirect:"follow",...n},p=new Request(l,f);for(let c of a.request._fns)c&&(p=await c(p,n));let T=n.fetch,u=await T(p);for(let c of a.response._fns)c&&(u=await c(u,p,n));let m={request:p,response:u};if(u.ok){if(u.status===204||u.headers.get("Content-Length")==="0")return {data:{},...m};let c=(n.parseAs==="auto"?P(u.headers.get("Content-Type")):n.parseAs)??"json";if(c==="stream")return {data:u.body,...m};let b=await u[c]();return c==="json"&&(n.responseValidator&&await n.responseValidator(b),n.responseTransformer&&(b=await n.responseTransformer(b))),{data:b,...m}}let g=await u.text();try{g=JSON.parse(g);}catch{}let d=g;for(let c of a.error._fns)c&&(d=await c(g,u,p,n));if(d=d||{},n.throwOnError)throw d;return {error:d,...m}};return {buildUrl:S,connect:s=>o({...s,method:"CONNECT"}),delete:s=>o({...s,method:"DELETE"}),get:s=>o({...s,method:"GET"}),getConfig:e,head:s=>o({...s,method:"HEAD"}),interceptors:a,options:s=>o({...s,method:"OPTIONS"}),patch:s=>o({...s,method:"PATCH"}),post:s=>o({...s,method:"POST"}),put:s=>o({...s,method:"PUT"}),request:o,setConfig:i,trace:s=>o({...s,method:"TRACE"})}};exports.createClient=J;exports.createConfig=w;exports.formDataBodySerializer=k;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=$;//# sourceMappingURL=index.cjs.map 2 2 //# sourceMappingURL=index.cjs.map
+6 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/client-custom/bundle/client/index.d.cts
··· 112 112 type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>; 113 113 type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>; 114 114 declare class Interceptors<Interceptor> { 115 - _fns: Interceptor[]; 115 + _fns: (Interceptor | null)[]; 116 116 constructor(); 117 117 clear(): void; 118 - exists(fn: Interceptor): boolean; 119 - eject(fn: Interceptor): void; 120 - use(fn: Interceptor): void; 118 + getInterceptorIndex(id: number | Interceptor): number; 119 + exists(id: number | Interceptor): boolean; 120 + eject(id: number | Interceptor): void; 121 + update(id: number | Interceptor, fn: Interceptor): number | false | Interceptor; 122 + use(fn: Interceptor): number; 121 123 } 122 124 interface Middleware<Req, Res, Err, Options> { 123 125 error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, 'eject' | 'use'>;
+6 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/client-custom/bundle/client/index.d.ts
··· 112 112 type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>; 113 113 type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>; 114 114 declare class Interceptors<Interceptor> { 115 - _fns: Interceptor[]; 115 + _fns: (Interceptor | null)[]; 116 116 constructor(); 117 117 clear(): void; 118 - exists(fn: Interceptor): boolean; 119 - eject(fn: Interceptor): void; 120 - use(fn: Interceptor): void; 118 + getInterceptorIndex(id: number | Interceptor): number; 119 + exists(id: number | Interceptor): boolean; 120 + eject(id: number | Interceptor): void; 121 + update(id: number | Interceptor, fn: Interceptor): number | false | Interceptor; 122 + use(fn: Interceptor): number; 121 123 } 122 124 interface Middleware<Req, Res, Err, Options> { 123 125 error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, 'eject' | 'use'>;