File tree Expand file tree Collapse file tree 4 files changed +45
-11
lines changed
Expand file tree Collapse file tree 4 files changed +45
-11
lines changed Original file line number Diff line number Diff line change @@ -478,12 +478,12 @@ export class StainlessV0 {
478478 fetchOptions . method = method . toUpperCase ( ) ;
479479 }
480480
481- return (
481+ try {
482482 // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
483- this . fetch . call ( undefined , url , fetchOptions ) . finally ( ( ) => {
484- clearTimeout ( timeout ) ;
485- } )
486- ) ;
483+ return await this . fetch . call ( undefined , url , fetchOptions ) ;
484+ } finally {
485+ clearTimeout ( timeout ) ;
486+ }
487487 }
488488
489489 private shouldRetry ( response : Response ) : boolean {
Original file line number Diff line number Diff line change 33type HeaderValue = string | undefined | null ;
44export type HeadersLike =
55 | Headers
6- | readonly [ string , HeaderValue ] [ ]
6+ | readonly HeaderValue [ ] [ ]
77 | Record < string , HeaderValue | readonly HeaderValue [ ] >
88 | undefined
99 | null
@@ -40,7 +40,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
4040 }
4141
4242 let shouldClear = false ;
43- let iter : Iterable < readonly [ string , HeaderValue | readonly HeaderValue [ ] ] > ;
43+ let iter : Iterable < readonly ( HeaderValue | readonly HeaderValue [ ] ) [ ] > ;
4444 if ( headers instanceof Headers ) {
4545 iter = headers . entries ( ) ;
4646 } else if ( isArray ( headers ) ) {
@@ -51,6 +51,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
5151 }
5252 for ( let row of iter ) {
5353 const name = row [ 0 ] ;
54+ if ( typeof name !== 'string' ) throw new TypeError ( 'expected header name to be a string' ) ;
5455 const values = isArray ( row [ 1 ] ) ? row [ 1 ] : [ row [ 1 ] ] ;
5556 let didClear = false ;
5657 for ( const value of values ) {
Original file line number Diff line number Diff line change 11// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22
33import { StainlessV0Error } from '../../core/error' ;
4+ import { encodeUTF8 } from './bytes' ;
45
56export const toBase64 = ( data : string | Uint8Array | null | undefined ) : string => {
67 if ( ! data ) return '' ;
78
8- if ( typeof data === 'string' ) {
9- data = new ( globalThis as any ) . TextEncoder ( ) . encode ( data ) ;
10- }
11-
129 if ( typeof ( globalThis as any ) . Buffer !== 'undefined' ) {
1310 return ( globalThis as any ) . Buffer . from ( data ) . toString ( 'base64' ) ;
1411 }
1512
13+ if ( typeof data === 'string' ) {
14+ data = encodeUTF8 ( data ) ;
15+ }
16+
1617 if ( typeof btoa !== 'undefined' ) {
1718 return btoa ( String . fromCharCode . apply ( null , data as any ) ) ;
1819 }
Original file line number Diff line number Diff line change 1+ export function concatBytes ( buffers : Uint8Array [ ] ) : Uint8Array {
2+ let length = 0 ;
3+ for ( const buffer of buffers ) {
4+ length += buffer . length ;
5+ }
6+ const output = new Uint8Array ( length ) ;
7+ let index = 0 ;
8+ for ( const buffer of buffers ) {
9+ output . set ( buffer , index ) ;
10+ index += buffer . length ;
11+ }
12+
13+ return output ;
14+ }
15+
16+ let encodeUTF8_ : ( str : string ) => Uint8Array ;
17+ export function encodeUTF8 ( str : string ) {
18+ let encoder ;
19+ return (
20+ encodeUTF8_ ??
21+ ( ( encoder = new ( globalThis as any ) . TextEncoder ( ) ) , ( encodeUTF8_ = encoder . encode . bind ( encoder ) ) )
22+ ) ( str ) ;
23+ }
24+
25+ let decodeUTF8_ : ( bytes : Uint8Array ) => string ;
26+ export function decodeUTF8 ( bytes : Uint8Array ) {
27+ let decoder ;
28+ return (
29+ decodeUTF8_ ??
30+ ( ( decoder = new ( globalThis as any ) . TextDecoder ( ) ) , ( decodeUTF8_ = decoder . decode . bind ( decoder ) ) )
31+ ) ( bytes ) ;
32+ }
You can’t perform that action at this time.
0 commit comments