Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: declare File for envs without lib.dom #175

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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