From dc4cc070fccfe7583f9ed205c4d9ed5ce255d10a Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 26 Mar 2022 03:38:51 -0700 Subject: [PATCH] Move .d.ts into a better folder --- types/{src => bun}/bun.d.ts | 109 ++++++++++++++++++++++++++++++++++-- types/bun/package.json | 4 ++ 2 files changed, 109 insertions(+), 4 deletions(-) rename types/{src => bun}/bun.d.ts (82%) create mode 100644 types/bun/package.json diff --git a/types/src/bun.d.ts b/types/bun/bun.d.ts similarity index 82% rename from types/src/bun.d.ts rename to types/bun/bun.d.ts index 7f0374fd55..11cf72a0ff 100644 --- a/types/src/bun.d.ts +++ b/types/bun/bun.d.ts @@ -10,11 +10,109 @@ declare global { written: number; } + export interface Process { + version: string; + nextTick(callback, ...args): void; + versions: Record; + ppid: number; + pid: number; + arch: + | "arm64" + | "arm" + | "ia32" + | "mips" + | "mipsel" + | "ppc" + | "ppc64" + | "s390" + | "s390x" + | "x32" + | "x64" + | "x86"; + platform: "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "win32"; + argv: string[]; + // execArgv: string[]; + env: Record & { + NODE_ENV: string; + }; + // execPath: string; + // abort(): void; + chdir(directory: string): void; + cwd(): string; + exit(code?: number): void; + getgid(): number; + setgid(id: number | string): void; + getuid(): number; + setuid(id: number | string): void; + } + + export var process: Process; + + export interface BlobInterface { + text(): Promise; + arrayBuffer(): Promise; + json(): Promise; + } + + type BlobPart = string | Blob | ArrayBufferView | ArrayBuffer | FileBlob; + interface BlobPropertyBag { + /** Set a default "type" */ + type?: string; + + /** Not implemented in Bun yet. */ + endings?: "transparent" | "native"; + } + + type HeadersInit = string[][] | Record | Headers; + + export class Blob implements BlobInterface { + slice(begin?: number, end?: number): Blob; + text(): Promise; + arrayBuffer(): Promise; + json(): Promise; + } + + export class Response implements BlobInterface { + constructor( + body: BlobPart | BlobPart[] | Blob, + options: { + headers?: HeadersInit; + } + ); + headers: Headers; + text(): Promise; + arrayBuffer(): Promise; + json(): Promise; + } + + export class Request implements BlobInterface { + constructor( + body: BlobPart | BlobPart[] | Blob, + options: { + headers?: HeadersInit; + } + ); + headers: Headers; + text(): Promise; + arrayBuffer(): Promise; + json(): Promise; + } + export interface Crypto { getRandomValues(array: TypedArray): void; randomUUID(): string; } + var crypto: Crypto; + + /** + * [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) converts ascii text into base64. + * + * @param asciiText The ascii text to convert. + */ + export function atob(asciiText: string): string; + export function btoa(base64Text: string): string; + /** * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All * instances of `TextEncoder` only support UTF-8 encoding. @@ -128,7 +226,7 @@ declare global { export function addEventListener( event: "fetch", - listener: (event: FetchEvent) => Promise + listener: (event: FetchEvent) => Promise | void ): void; type JavaScriptLoader = "jsx" | "js" | "ts" | "tsx"; @@ -288,7 +386,7 @@ declare global { fetch(request: Request): Response | Promise; error?: ( - request: Request + request: Errorlike ) => Response | Promise | undefined | Promise; } @@ -436,7 +534,7 @@ declare global { * ```js * const file = Bun.file("./hello.json"); * console.log(file.type); // "application/json" - * console.log(await file.json()); // { hello: "world" } + * console.log(await file.text()); // '{"hello":"world"}' * ``` * * @example @@ -448,6 +546,9 @@ declare global { * ``` * */ - export interface FileBlob extends Blob {} + export interface FileBlob extends Blob { + /** Currently, "name" is not exposed because it may or may not exist */ + name: never; + } } export {}; diff --git a/types/bun/package.json b/types/bun/package.json new file mode 100644 index 0000000000..4725dafe2f --- /dev/null +++ b/types/bun/package.json @@ -0,0 +1,4 @@ +{ + "name": "@types/bun", + "types": "./bun.d.ts" +}