File tree 4 files changed +45
-11
lines changed
4 files changed +45
-11
lines changed Original file line number Diff line number Diff line change @@ -635,12 +635,12 @@ export class Openint {
635
635
fetchOptions . method = method . toUpperCase ( ) ;
636
636
}
637
637
638
- return (
638
+ try {
639
639
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
640
- this . fetch . call ( undefined , url , fetchOptions ) . finally ( ( ) => {
641
- clearTimeout ( timeout ) ;
642
- } )
643
- ) ;
640
+ return await this . fetch . call ( undefined , url , fetchOptions ) ;
641
+ } finally {
642
+ clearTimeout ( timeout ) ;
643
+ }
644
644
}
645
645
646
646
private shouldRetry ( response : Response ) : boolean {
Original file line number Diff line number Diff line change 3
3
type HeaderValue = string | undefined | null ;
4
4
export type HeadersLike =
5
5
| Headers
6
- | readonly [ string , HeaderValue ] [ ]
6
+ | readonly HeaderValue [ ] [ ]
7
7
| Record < string , HeaderValue | readonly HeaderValue [ ] >
8
8
| undefined
9
9
| null
@@ -40,7 +40,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
40
40
}
41
41
42
42
let shouldClear = false ;
43
- let iter : Iterable < readonly [ string , HeaderValue | readonly HeaderValue [ ] ] > ;
43
+ let iter : Iterable < readonly ( HeaderValue | readonly HeaderValue [ ] ) [ ] > ;
44
44
if ( headers instanceof Headers ) {
45
45
iter = headers . entries ( ) ;
46
46
} else if ( isArray ( headers ) ) {
@@ -51,6 +51,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
51
51
}
52
52
for ( let row of iter ) {
53
53
const name = row [ 0 ] ;
54
+ if ( typeof name !== 'string' ) throw new TypeError ( 'expected header name to be a string' ) ;
54
55
const values = isArray ( row [ 1 ] ) ? row [ 1 ] : [ row [ 1 ] ] ;
55
56
let didClear = false ;
56
57
for ( const value of values ) {
Original file line number Diff line number Diff line change 1
1
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
3
3
import { OpenintError } from '../../core/error' ;
4
+ import { encodeUTF8 } from './bytes' ;
4
5
5
6
export const toBase64 = ( data : string | Uint8Array | null | undefined ) : string => {
6
7
if ( ! data ) return '' ;
7
8
8
- if ( typeof data === 'string' ) {
9
- data = new ( globalThis as any ) . TextEncoder ( ) . encode ( data ) ;
10
- }
11
-
12
9
if ( typeof ( globalThis as any ) . Buffer !== 'undefined' ) {
13
10
return ( globalThis as any ) . Buffer . from ( data ) . toString ( 'base64' ) ;
14
11
}
15
12
13
+ if ( typeof data === 'string' ) {
14
+ data = encodeUTF8 ( data ) ;
15
+ }
16
+
16
17
if ( typeof btoa !== 'undefined' ) {
17
18
return btoa ( String . fromCharCode . apply ( null , data as any ) ) ;
18
19
}
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