cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/_shims/index-deno.ts
110lines · modecode
| 1 | import { MultipartBody } from './MultipartBody'; |
| 2 | import { type RequestOptions } from '../core'; |
| 3 | |
| 4 | export const kind: string = 'web'; |
| 5 | |
| 6 | export type Agent = any; |
| 7 | |
| 8 | const _fetch = fetch; |
| 9 | type _fetch = typeof fetch; |
| 10 | export { _fetch as fetch }; |
| 11 | |
| 12 | const _Request = Request; |
| 13 | type _Request = Request; |
| 14 | export { _Request as Request }; |
| 15 | |
| 16 | type _RequestInfo = RequestInfo; |
| 17 | export { type _RequestInfo as RequestInfo }; |
| 18 | |
| 19 | type _RequestInit = RequestInit; |
| 20 | export { type _RequestInit as RequestInit }; |
| 21 | |
| 22 | const _Response = Response; |
| 23 | type _Response = Response; |
| 24 | export { _Response as Response }; |
| 25 | |
| 26 | type _ResponseInit = ResponseInit; |
| 27 | export { type _ResponseInit as ResponseInit }; |
| 28 | |
| 29 | type _ResponseType = ResponseType; |
| 30 | export { type _ResponseType as ResponseType }; |
| 31 | |
| 32 | type _BodyInit = BodyInit; |
| 33 | export { type _BodyInit as BodyInit }; |
| 34 | |
| 35 | const _Headers = Headers; |
| 36 | type _Headers = Headers; |
| 37 | export { _Headers as Headers }; |
| 38 | |
| 39 | type _HeadersInit = HeadersInit; |
| 40 | export { type _HeadersInit as HeadersInit }; |
| 41 | |
| 42 | type EndingType = 'native' | 'transparent'; |
| 43 | |
| 44 | export interface BlobPropertyBag { |
| 45 | endings?: EndingType; |
| 46 | type?: string; |
| 47 | } |
| 48 | |
| 49 | export interface FilePropertyBag extends BlobPropertyBag { |
| 50 | lastModified?: number; |
| 51 | } |
| 52 | |
| 53 | export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>; |
| 54 | |
| 55 | const _FormData = FormData; |
| 56 | type _FormData = FormData; |
| 57 | export { _FormData as FormData }; |
| 58 | |
| 59 | const _File = File; |
| 60 | type _File = File; |
| 61 | export { _File as File }; |
| 62 | |
| 63 | const _Blob = Blob; |
| 64 | type _Blob = Blob; |
| 65 | export { _Blob as Blob }; |
| 66 | |
| 67 | export async function getMultipartRequestOptions<T = Record<string, unknown>>( |
| 68 | form: FormData, |
| 69 | opts: RequestOptions<T>, |
| 70 | ): Promise<RequestOptions<T>> { |
| 71 | return { |
| 72 | ...opts, |
| 73 | body: new MultipartBody(form) as any, |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | export function getDefaultAgent(url: string) { |
| 78 | return undefined; |
| 79 | } |
| 80 | export function fileFromPath() { |
| 81 | throw new Error( |
| 82 | 'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/cloudflare/cloudflare-typescript#file-uploads', |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | export const isFsReadStream = (value: any) => false; |
| 87 | |
| 88 | export declare class Readable { |
| 89 | readable: boolean; |
| 90 | readonly readableEnded: boolean; |
| 91 | readonly readableFlowing: boolean | null; |
| 92 | readonly readableHighWaterMark: number; |
| 93 | readonly readableLength: number; |
| 94 | readonly readableObjectMode: boolean; |
| 95 | destroyed: boolean; |
| 96 | read(size?: number): any; |
| 97 | pause(): this; |
| 98 | resume(): this; |
| 99 | isPaused(): boolean; |
| 100 | destroy(error?: Error): this; |
| 101 | [Symbol.asyncIterator](): AsyncIterableIterator<any>; |
| 102 | } |
| 103 | |
| 104 | export declare class FsReadStream extends Readable { |
| 105 | path: {}; // node type is string | Buffer |
| 106 | } |
| 107 | |
| 108 | const _ReadableStream = ReadableStream; |
| 109 | type _ReadableStream = ReadableStream; |
| 110 | export { _ReadableStream as ReadableStream }; |
| 111 | |