forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-types.d.ts
91 lines (79 loc) · 3.22 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// https://github.com/cloudflare/wrangler2/pull/2496#discussion_r1062516883
import {
Event as WorkerEvent,
WebAssembly as WorkerWebAssembly,
} from "@cloudflare/workers-types";
import type {
EventListenerOrEventListenerObject,
EventTargetAddEventListenerOptions,
EventTargetEventListenerOptions,
} from "@cloudflare/workers-types";
declare global {
// `Event` and `EventTarget` have been global since Node 15, but aren't
// included in `@types/node`.
class Event extends WorkerEvent {}
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)
class EventTarget {
addEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: EventTargetAddEventListenerOptions | boolean
): void;
dispatchEvent(event: Event): boolean;
removeEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: EventTargetEventListenerOptions | boolean
): void;
}
// `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 {}
}