Skip to content

Commit

Permalink
fix: declare File for envs without lib.dom (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Mar 22, 2023
1 parent 75064df commit 1e9cb5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/assets/AssetsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ResponseEvent,
SanityAssetDocument,
SanityImageAssetDocument,
UploadBody,
UploadClientConfig,
} from '../types'
import * as validators from '../validators'
Expand All @@ -32,7 +33,7 @@ export class ObservableAssetsClient {
*/
upload(
assetType: 'file',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Observable<HttpRequestEvent<{document: SanityAssetDocument}>>

Expand All @@ -45,7 +46,7 @@ export class ObservableAssetsClient {
*/
upload(
assetType: 'image',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
/**
Expand All @@ -57,12 +58,12 @@ export class ObservableAssetsClient {
*/
upload(
assetType: 'file' | 'image',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
upload(
assetType: 'file' | 'image',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
return _upload(this.#client, this.#httpRequest, assetType, body, options)
Expand All @@ -87,7 +88,7 @@ export class AssetsClient {
*/
upload(
assetType: 'file',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Promise<SanityAssetDocument>
/**
Expand All @@ -99,7 +100,7 @@ export class AssetsClient {
*/
upload(
assetType: 'image',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Promise<SanityImageAssetDocument>
/**
Expand All @@ -111,12 +112,12 @@ export class AssetsClient {
*/
upload(
assetType: 'file' | 'image',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Promise<SanityAssetDocument | SanityImageAssetDocument>
upload(
assetType: 'file' | 'image',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
options?: UploadClientConfig
): Promise<SanityAssetDocument | SanityImageAssetDocument> {
const observable = _upload(this.#client, this.#httpRequest, assetType, body, options)
Expand All @@ -137,7 +138,7 @@ function _upload(
client: SanityClient | ObservableSanityClient,
httpRequest: HttpRequest,
assetType: 'image' | 'file',
body: File | Blob | Buffer | NodeJS.ReadableStream,
body: UploadBody,
opts: UploadClientConfig = {}
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
validators.validateAssetType(assetType)
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// deno-lint-ignore-file no-empty-interface
import type {Requester} from 'get-it'

/**
Expand All @@ -6,6 +7,14 @@ import type {Requester} from 'get-it'
*/
export type Any = any // eslint-disable-line @typescript-eslint/no-explicit-any

declare global {
// Declare empty stub interfaces for environments where "dom" lib is not included
interface File {}
}

/** @public */
export type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream

/** @public */
export interface RequestOptions {
timeout?: number
Expand Down
2 changes: 1 addition & 1 deletion test/warnings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Client config warnings', async () => {
)
})

test.skipIf(isEdge)('warns if in browser on localhost and a token is provided', () => {
test('warns if in browser on localhost and a token is provided', () => {
const restoreWindow = global.window
global.window = {location: {hostname: 'localhost'}} as any
createClient({projectId: 'abc123', useCdn: false, token: 'foo', apiVersion: '1'})
Expand Down

0 comments on commit 1e9cb5e

Please sign in to comment.