im_wower
·
2026-03-29
node-shims.d.ts
1declare class Buffer extends Uint8Array {
2 static alloc(size: number): Buffer;
3 static allocUnsafe(size: number): Buffer;
4 static byteLength(value: string, encoding?: string): number;
5 static concat(chunks: readonly Uint8Array[]): Buffer;
6 static from(value: string, encoding?: string): Buffer;
7 copy(target: Uint8Array, targetStart?: number): number;
8 readBigUInt64BE(offset?: number): bigint;
9 readUInt16BE(offset?: number): number;
10 subarray(start?: number, end?: number): Buffer;
11 toString(encoding?: string): string;
12 writeBigUInt64BE(value: bigint, offset?: number): number;
13 writeUInt16BE(value: number, offset?: number): number;
14}
15
16declare module "node:crypto" {
17 export function createHash(
18 algorithm: string
19 ): {
20 digest(encoding: string): string;
21 update(value: string): { digest(encoding: string): string };
22 };
23
24 export function randomUUID(): string;
25}
26
27declare module "node:net" {
28 export interface AddressInfo {
29 address: string;
30 family: string;
31 port: number;
32 }
33
34 export interface Socket {
35 destroy(error?: Error): this;
36 destroySoon?(): void;
37 end(chunk?: string | Uint8Array): this;
38 on(event: "close", listener: () => void): this;
39 on(event: "data", listener: (chunk: Buffer) => void): this;
40 on(event: "end", listener: () => void): this;
41 on(event: "error", listener: (error: Error) => void): this;
42 setNoDelay(noDelay?: boolean): this;
43 write(chunk: string | Uint8Array): boolean;
44 }
45}
46
47declare module "node:fs" {
48 export function appendFileSync(path: string, data: string): void;
49 export function mkdirSync(path: string, options?: { recursive?: boolean }): string | undefined;
50 export function readFileSync(path: string): Uint8Array;
51 export function readFileSync(path: string, encoding: string): string;
52}
53
54declare module "node:fs/promises" {
55 export interface FileOperationOptions {
56 encoding?: string;
57 flag?: string;
58 mode?: number;
59 }
60
61 export interface MakeDirectoryOptions {
62 mode?: number;
63 recursive?: boolean;
64 }
65
66 export function mkdir(
67 path: string,
68 options?: MakeDirectoryOptions
69 ): Promise<string | undefined>;
70
71 export function readFile(path: string): Promise<Buffer>;
72
73 export function readFile(
74 path: string,
75 options: FileOperationOptions | string
76 ): Promise<string | Buffer>;
77
78 export function writeFile(
79 path: string,
80 data: string,
81 options?: FileOperationOptions | string
82 ): Promise<void>;
83}
84
85declare module "node:http" {
86 import type { AddressInfo } from "node:net";
87
88 export interface IncomingMessage {
89 headers: Record<string, string | string[] | undefined>;
90 method?: string;
91 on?(event: "data", listener: (chunk: string | Uint8Array) => void): this;
92 on?(event: "end", listener: () => void): this;
93 on?(event: "error", listener: (error: Error) => void): this;
94 setEncoding?(encoding: string): void;
95 url?: string;
96 }
97
98 export interface ServerResponse<Request extends IncomingMessage = IncomingMessage> {
99 end(chunk?: string | Uint8Array): void;
100 setHeader(name: string, value: string): this;
101 statusCode: number;
102 }
103
104 export interface Server {
105 address(): AddressInfo | string | null;
106 close(callback?: (error?: Error) => void): this;
107 closeAllConnections?(): void;
108 listen(options: { host: string; port: number }): this;
109 on(
110 event: "upgrade",
111 listener: (request: IncomingMessage, socket: import("node:net").Socket, head: Buffer) => void
112 ): this;
113 off(event: "error", listener: (error: Error) => void): this;
114 off(event: "listening", listener: () => void): this;
115 off(event: string, listener: (...args: unknown[]) => void): this;
116 once(event: "error", listener: (error: Error) => void): this;
117 once(event: "listening", listener: () => void): this;
118 }
119
120 export function createServer(
121 handler: (request: IncomingMessage, response: ServerResponse<IncomingMessage>) => void
122 ): Server;
123}
124
125declare module "node:path" {
126 export function join(...paths: string[]): string;
127 export function resolve(...paths: string[]): string;
128}
129
130declare module "node:os" {
131 export function tmpdir(): string;
132}
133
134declare module "node:url" {
135 export function fileURLToPath(url: string | URL): string;
136}