forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-types.d.ts
76 lines (63 loc) · 2.91 KB
/
node-types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// https://github.com/cloudflare/workers-sdk/pull/2496#discussion_r1062516883
import { WebAssembly as WorkerWebAssembly } from "@cloudflare/workers-types";
import type {
EventTargetAddEventListenerOptions,
EventTargetEventListenerOptions,
} from "@cloudflare/workers-types";
declare global {
type EventListenerOptions = EventTargetEventListenerOptions;
type AddEventListenerOptions = EventTargetAddEventListenerOptions;
// (can't use EventTarget from "@cloudflare/workers-types" as it's event map
// type parameters are incompatible with `tinybench`, a `vitest` dependency)
// `WebAssembly` has been global since Node 8, but isn't included in
// `@types/node`.
type BufferSource = ArrayBufferView | ArrayBuffer;
namespace WebAssembly {
class CompileError extends WorkerWebAssembly.CompileError {}
class RuntimeError extends WorkerWebAssembly.RuntimeError {}
type ValueType = WorkerWebAssembly.ValueType;
type GlobalDescriptor = WorkerWebAssembly.GlobalDescriptor;
class Global extends WorkerWebAssembly.Global {}
type ImportValue = WorkerWebAssembly.ImportValue;
type ModuleImports = WorkerWebAssembly.ModuleImports;
type Imports = WorkerWebAssembly.Imports;
type ExportValue = WorkerWebAssembly.ExportValue;
type Exports = WorkerWebAssembly.Exports;
class Instance extends WorkerWebAssembly.Instance {}
type MemoryDescriptor = WorkerWebAssembly.MemoryDescriptor;
class Memory extends WorkerWebAssembly.Memory {}
type ImportExportKind = WorkerWebAssembly.ImportExportKind;
type ModuleExportDescriptor = WorkerWebAssembly.ModuleExportDescriptor;
type ModuleImportDescriptor = WorkerWebAssembly.ModuleImportDescriptor;
class Module extends WorkerWebAssembly.Module {
// Node.js allows dynamic compilation of WebAssembly unlike Workers
constructor(bytes: BufferSource);
}
type TableKind = WorkerWebAssembly.TableKind;
type TableDescriptor = WorkerWebAssembly.TableDescriptor;
class Table extends WorkerWebAssembly.Table {}
// Node.js allows dynamic compilation of WebAssembly unlike Workers
interface WebAssemblyInstantiatedSource {
instance: Instance;
module: Module;
}
function compile(bytes: BufferSource): Promise<Module>;
function instantiate(
bytes: BufferSource,
importObject?: Imports
): Promise<WebAssemblyInstantiatedSource>;
function instantiate(
moduleObject: Module,
importObject?: Imports
): Promise<Instance>;
function validate(bytes: BufferSource): boolean;
}
// `Worker` isn't defined on the global scope in Node.js, but it's required
// by `vite`. Therefore, define it as an empty interface.
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Worker {}
// `MessagePort` has been global since Node 15, but isn't included in
// `@types/node`. This is required by `undici`'s types.
// eslint-disable-next-line no-var,@typescript-eslint/consistent-type-imports
var MessagePort: typeof import("worker_threads").MessagePort;
}