almostnode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +731 -0
- package/dist/__sw__.js +394 -0
- package/dist/ai-chatbot-demo-entry.d.ts +6 -0
- package/dist/ai-chatbot-demo-entry.d.ts.map +1 -0
- package/dist/ai-chatbot-demo.d.ts +42 -0
- package/dist/ai-chatbot-demo.d.ts.map +1 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js +60543 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js.map +1 -0
- package/dist/convex-app-demo-entry.d.ts +6 -0
- package/dist/convex-app-demo-entry.d.ts.map +1 -0
- package/dist/convex-app-demo.d.ts +68 -0
- package/dist/convex-app-demo.d.ts.map +1 -0
- package/dist/cors-proxy.d.ts +46 -0
- package/dist/cors-proxy.d.ts.map +1 -0
- package/dist/create-runtime.d.ts +42 -0
- package/dist/create-runtime.d.ts.map +1 -0
- package/dist/demo.d.ts +6 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/dev-server.d.ts +97 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +202 -0
- package/dist/frameworks/next-dev-server.d.ts.map +1 -0
- package/dist/frameworks/vite-dev-server.d.ts +85 -0
- package/dist/frameworks/vite-dev-server.d.ts.map +1 -0
- package/dist/index.cjs +14965 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +14867 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next-demo.d.ts +49 -0
- package/dist/next-demo.d.ts.map +1 -0
- package/dist/npm/index.d.ts +71 -0
- package/dist/npm/index.d.ts.map +1 -0
- package/dist/npm/registry.d.ts +66 -0
- package/dist/npm/registry.d.ts.map +1 -0
- package/dist/npm/resolver.d.ts +52 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/tarball.d.ts +29 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/runtime-interface.d.ts +90 -0
- package/dist/runtime-interface.d.ts.map +1 -0
- package/dist/runtime.d.ts +103 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/sandbox-helpers.d.ts +43 -0
- package/dist/sandbox-helpers.d.ts.map +1 -0
- package/dist/sandbox-runtime.d.ts +65 -0
- package/dist/sandbox-runtime.d.ts.map +1 -0
- package/dist/server-bridge.d.ts +89 -0
- package/dist/server-bridge.d.ts.map +1 -0
- package/dist/shims/assert.d.ts +51 -0
- package/dist/shims/assert.d.ts.map +1 -0
- package/dist/shims/async_hooks.d.ts +37 -0
- package/dist/shims/async_hooks.d.ts.map +1 -0
- package/dist/shims/buffer.d.ts +20 -0
- package/dist/shims/buffer.d.ts.map +1 -0
- package/dist/shims/child_process-browser.d.ts +92 -0
- package/dist/shims/child_process-browser.d.ts.map +1 -0
- package/dist/shims/child_process.d.ts +93 -0
- package/dist/shims/child_process.d.ts.map +1 -0
- package/dist/shims/chokidar.d.ts +55 -0
- package/dist/shims/chokidar.d.ts.map +1 -0
- package/dist/shims/cluster.d.ts +52 -0
- package/dist/shims/cluster.d.ts.map +1 -0
- package/dist/shims/crypto.d.ts +122 -0
- package/dist/shims/crypto.d.ts.map +1 -0
- package/dist/shims/dgram.d.ts +34 -0
- package/dist/shims/dgram.d.ts.map +1 -0
- package/dist/shims/diagnostics_channel.d.ts +80 -0
- package/dist/shims/diagnostics_channel.d.ts.map +1 -0
- package/dist/shims/dns.d.ts +87 -0
- package/dist/shims/dns.d.ts.map +1 -0
- package/dist/shims/domain.d.ts +25 -0
- package/dist/shims/domain.d.ts.map +1 -0
- package/dist/shims/esbuild.d.ts +105 -0
- package/dist/shims/esbuild.d.ts.map +1 -0
- package/dist/shims/events.d.ts +37 -0
- package/dist/shims/events.d.ts.map +1 -0
- package/dist/shims/fs.d.ts +115 -0
- package/dist/shims/fs.d.ts.map +1 -0
- package/dist/shims/fsevents.d.ts +67 -0
- package/dist/shims/fsevents.d.ts.map +1 -0
- package/dist/shims/http.d.ts +217 -0
- package/dist/shims/http.d.ts.map +1 -0
- package/dist/shims/http2.d.ts +81 -0
- package/dist/shims/http2.d.ts.map +1 -0
- package/dist/shims/https.d.ts +36 -0
- package/dist/shims/https.d.ts.map +1 -0
- package/dist/shims/inspector.d.ts +25 -0
- package/dist/shims/inspector.d.ts.map +1 -0
- package/dist/shims/module.d.ts +22 -0
- package/dist/shims/module.d.ts.map +1 -0
- package/dist/shims/net.d.ts +100 -0
- package/dist/shims/net.d.ts.map +1 -0
- package/dist/shims/os.d.ts +159 -0
- package/dist/shims/os.d.ts.map +1 -0
- package/dist/shims/path.d.ts +72 -0
- package/dist/shims/path.d.ts.map +1 -0
- package/dist/shims/perf_hooks.d.ts +50 -0
- package/dist/shims/perf_hooks.d.ts.map +1 -0
- package/dist/shims/process.d.ts +93 -0
- package/dist/shims/process.d.ts.map +1 -0
- package/dist/shims/querystring.d.ts +23 -0
- package/dist/shims/querystring.d.ts.map +1 -0
- package/dist/shims/readdirp.d.ts +52 -0
- package/dist/shims/readdirp.d.ts.map +1 -0
- package/dist/shims/readline.d.ts +62 -0
- package/dist/shims/readline.d.ts.map +1 -0
- package/dist/shims/rollup.d.ts +34 -0
- package/dist/shims/rollup.d.ts.map +1 -0
- package/dist/shims/sentry.d.ts +163 -0
- package/dist/shims/sentry.d.ts.map +1 -0
- package/dist/shims/stream.d.ts +181 -0
- package/dist/shims/stream.d.ts.map +1 -0
- package/dist/shims/tls.d.ts +53 -0
- package/dist/shims/tls.d.ts.map +1 -0
- package/dist/shims/tty.d.ts +30 -0
- package/dist/shims/tty.d.ts.map +1 -0
- package/dist/shims/url.d.ts +64 -0
- package/dist/shims/url.d.ts.map +1 -0
- package/dist/shims/util.d.ts +106 -0
- package/dist/shims/util.d.ts.map +1 -0
- package/dist/shims/v8.d.ts +73 -0
- package/dist/shims/v8.d.ts.map +1 -0
- package/dist/shims/vfs-adapter.d.ts +126 -0
- package/dist/shims/vfs-adapter.d.ts.map +1 -0
- package/dist/shims/vm.d.ts +45 -0
- package/dist/shims/vm.d.ts.map +1 -0
- package/dist/shims/worker_threads.d.ts +66 -0
- package/dist/shims/worker_threads.d.ts.map +1 -0
- package/dist/shims/ws.d.ts +66 -0
- package/dist/shims/ws.d.ts.map +1 -0
- package/dist/shims/zlib.d.ts +161 -0
- package/dist/shims/zlib.d.ts.map +1 -0
- package/dist/transform.d.ts +24 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts +226 -0
- package/dist/virtual-fs.d.ts.map +1 -0
- package/dist/vite-demo.d.ts +35 -0
- package/dist/vite-demo.d.ts.map +1 -0
- package/dist/vite-sw.js +132 -0
- package/dist/worker/runtime-worker.d.ts +8 -0
- package/dist/worker/runtime-worker.d.ts.map +1 -0
- package/dist/worker-runtime.d.ts +50 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/package.json +85 -0
- package/src/ai-chatbot-demo-entry.ts +244 -0
- package/src/ai-chatbot-demo.ts +509 -0
- package/src/convex-app-demo-entry.ts +1107 -0
- package/src/convex-app-demo.ts +1316 -0
- package/src/cors-proxy.ts +81 -0
- package/src/create-runtime.ts +147 -0
- package/src/demo.ts +304 -0
- package/src/dev-server.ts +274 -0
- package/src/frameworks/next-dev-server.ts +2224 -0
- package/src/frameworks/vite-dev-server.ts +702 -0
- package/src/index.ts +101 -0
- package/src/next-demo.ts +1784 -0
- package/src/npm/index.ts +347 -0
- package/src/npm/registry.ts +152 -0
- package/src/npm/resolver.ts +385 -0
- package/src/npm/tarball.ts +209 -0
- package/src/runtime-interface.ts +103 -0
- package/src/runtime.ts +1046 -0
- package/src/sandbox-helpers.ts +173 -0
- package/src/sandbox-runtime.ts +252 -0
- package/src/server-bridge.ts +426 -0
- package/src/shims/assert.ts +664 -0
- package/src/shims/async_hooks.ts +86 -0
- package/src/shims/buffer.ts +75 -0
- package/src/shims/child_process-browser.ts +217 -0
- package/src/shims/child_process.ts +463 -0
- package/src/shims/chokidar.ts +313 -0
- package/src/shims/cluster.ts +67 -0
- package/src/shims/crypto.ts +830 -0
- package/src/shims/dgram.ts +47 -0
- package/src/shims/diagnostics_channel.ts +196 -0
- package/src/shims/dns.ts +172 -0
- package/src/shims/domain.ts +58 -0
- package/src/shims/esbuild.ts +805 -0
- package/src/shims/events.ts +195 -0
- package/src/shims/fs.ts +803 -0
- package/src/shims/fsevents.ts +63 -0
- package/src/shims/http.ts +904 -0
- package/src/shims/http2.ts +96 -0
- package/src/shims/https.ts +86 -0
- package/src/shims/inspector.ts +30 -0
- package/src/shims/module.ts +82 -0
- package/src/shims/net.ts +359 -0
- package/src/shims/os.ts +195 -0
- package/src/shims/path.ts +199 -0
- package/src/shims/perf_hooks.ts +92 -0
- package/src/shims/process.ts +346 -0
- package/src/shims/querystring.ts +97 -0
- package/src/shims/readdirp.ts +228 -0
- package/src/shims/readline.ts +110 -0
- package/src/shims/rollup.ts +80 -0
- package/src/shims/sentry.ts +133 -0
- package/src/shims/stream.ts +1126 -0
- package/src/shims/tls.ts +95 -0
- package/src/shims/tty.ts +64 -0
- package/src/shims/url.ts +171 -0
- package/src/shims/util.ts +312 -0
- package/src/shims/v8.ts +113 -0
- package/src/shims/vfs-adapter.ts +402 -0
- package/src/shims/vm.ts +83 -0
- package/src/shims/worker_threads.ts +111 -0
- package/src/shims/ws.ts +382 -0
- package/src/shims/zlib.ts +289 -0
- package/src/transform.ts +313 -0
- package/src/types/external.d.ts +67 -0
- package/src/virtual-fs.ts +903 -0
- package/src/vite-demo.ts +577 -0
- package/src/worker/runtime-worker.ts +128 -0
- package/src/worker-runtime.ts +145 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dgram shim - UDP sockets are not available in browser
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { EventEmitter } from './events';
|
|
6
|
+
|
|
7
|
+
export class Socket extends EventEmitter {
|
|
8
|
+
bind(_port?: number, _address?: string, _callback?: () => void): this {
|
|
9
|
+
if (_callback) setTimeout(_callback, 0);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
close(_callback?: () => void): void {
|
|
14
|
+
if (_callback) setTimeout(_callback, 0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
send(_msg: Buffer | string, _offset?: number, _length?: number, _port?: number, _address?: string, _callback?: (error: Error | null, bytes: number) => void): void {
|
|
18
|
+
if (_callback) setTimeout(() => _callback(null, 0), 0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
address(): { address: string; family: string; port: number } {
|
|
22
|
+
return { address: '0.0.0.0', family: 'IPv4', port: 0 };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setBroadcast(_flag: boolean): void {}
|
|
26
|
+
setTTL(_ttl: number): number { return _ttl; }
|
|
27
|
+
setMulticastTTL(_ttl: number): number { return _ttl; }
|
|
28
|
+
setMulticastLoopback(_flag: boolean): boolean { return _flag; }
|
|
29
|
+
setMulticastInterface(_multicastInterface: string): void {}
|
|
30
|
+
addMembership(_multicastAddress: string, _multicastInterface?: string): void {}
|
|
31
|
+
dropMembership(_multicastAddress: string, _multicastInterface?: string): void {}
|
|
32
|
+
ref(): this { return this; }
|
|
33
|
+
unref(): this { return this; }
|
|
34
|
+
setRecvBufferSize(_size: number): void {}
|
|
35
|
+
setSendBufferSize(_size: number): void {}
|
|
36
|
+
getRecvBufferSize(): number { return 0; }
|
|
37
|
+
getSendBufferSize(): number { return 0; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createSocket(_type: string | object, _callback?: (msg: Buffer, rinfo: object) => void): Socket {
|
|
41
|
+
return new Socket();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default {
|
|
45
|
+
Socket,
|
|
46
|
+
createSocket,
|
|
47
|
+
};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js diagnostics_channel module shim
|
|
3
|
+
* Provides basic diagnostics channel functionality for packages like undici
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EventEmitter } from './events';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A Channel is used to publish messages to subscribers
|
|
10
|
+
*/
|
|
11
|
+
export class Channel {
|
|
12
|
+
private name: string;
|
|
13
|
+
private _subscribers: Set<(message: unknown, name: string) => void> = new Set();
|
|
14
|
+
|
|
15
|
+
constructor(name: string) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get hasSubscribers(): boolean {
|
|
20
|
+
return this._subscribers.size > 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
publish(message: unknown): void {
|
|
24
|
+
for (const subscriber of this._subscribers) {
|
|
25
|
+
try {
|
|
26
|
+
subscriber(message, this.name);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error('Error in diagnostics channel subscriber:', err);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
subscribe(onMessage: (message: unknown, name: string) => void): void {
|
|
34
|
+
this._subscribers.add(onMessage);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
unsubscribe(onMessage: (message: unknown, name: string) => void): boolean {
|
|
38
|
+
return this._subscribers.delete(onMessage);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
bindStore(store: unknown, transform?: (message: unknown) => unknown): void {
|
|
42
|
+
// Stub - AsyncLocalStorage integration not implemented
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
unbindStore(store: unknown): boolean {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Channel registry
|
|
51
|
+
const channels = new Map<string, Channel>();
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get or create a channel by name
|
|
55
|
+
*/
|
|
56
|
+
export function channel(name: string): Channel {
|
|
57
|
+
let ch = channels.get(name);
|
|
58
|
+
if (!ch) {
|
|
59
|
+
ch = new Channel(name);
|
|
60
|
+
channels.set(name, ch);
|
|
61
|
+
}
|
|
62
|
+
return ch;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Check if a channel has subscribers
|
|
67
|
+
*/
|
|
68
|
+
export function hasSubscribers(name: string): boolean {
|
|
69
|
+
const ch = channels.get(name);
|
|
70
|
+
return ch ? ch.hasSubscribers : false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to a channel
|
|
75
|
+
*/
|
|
76
|
+
export function subscribe(name: string, onMessage: (message: unknown, name: string) => void): void {
|
|
77
|
+
channel(name).subscribe(onMessage);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Unsubscribe from a channel
|
|
82
|
+
*/
|
|
83
|
+
export function unsubscribe(name: string, onMessage: (message: unknown, name: string) => void): boolean {
|
|
84
|
+
const ch = channels.get(name);
|
|
85
|
+
return ch ? ch.unsubscribe(onMessage) : false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* TracingChannel for distributed tracing
|
|
90
|
+
*/
|
|
91
|
+
export class TracingChannel {
|
|
92
|
+
private channels: {
|
|
93
|
+
start: Channel;
|
|
94
|
+
end: Channel;
|
|
95
|
+
asyncStart: Channel;
|
|
96
|
+
asyncEnd: Channel;
|
|
97
|
+
error: Channel;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
constructor(nameOrChannels: string | { start: Channel; end: Channel; asyncStart: Channel; asyncEnd: Channel; error: Channel }) {
|
|
101
|
+
if (typeof nameOrChannels === 'string') {
|
|
102
|
+
this.channels = {
|
|
103
|
+
start: channel(`tracing:${nameOrChannels}:start`),
|
|
104
|
+
end: channel(`tracing:${nameOrChannels}:end`),
|
|
105
|
+
asyncStart: channel(`tracing:${nameOrChannels}:asyncStart`),
|
|
106
|
+
asyncEnd: channel(`tracing:${nameOrChannels}:asyncEnd`),
|
|
107
|
+
error: channel(`tracing:${nameOrChannels}:error`),
|
|
108
|
+
};
|
|
109
|
+
} else {
|
|
110
|
+
this.channels = nameOrChannels;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get hasSubscribers(): boolean {
|
|
115
|
+
return Object.values(this.channels).some(ch => ch.hasSubscribers);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
subscribe(handlers: {
|
|
119
|
+
start?: (message: unknown) => void;
|
|
120
|
+
end?: (message: unknown) => void;
|
|
121
|
+
asyncStart?: (message: unknown) => void;
|
|
122
|
+
asyncEnd?: (message: unknown) => void;
|
|
123
|
+
error?: (message: unknown) => void;
|
|
124
|
+
}): void {
|
|
125
|
+
if (handlers.start) this.channels.start.subscribe(handlers.start);
|
|
126
|
+
if (handlers.end) this.channels.end.subscribe(handlers.end);
|
|
127
|
+
if (handlers.asyncStart) this.channels.asyncStart.subscribe(handlers.asyncStart);
|
|
128
|
+
if (handlers.asyncEnd) this.channels.asyncEnd.subscribe(handlers.asyncEnd);
|
|
129
|
+
if (handlers.error) this.channels.error.subscribe(handlers.error);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
unsubscribe(handlers: {
|
|
133
|
+
start?: (message: unknown) => void;
|
|
134
|
+
end?: (message: unknown) => void;
|
|
135
|
+
asyncStart?: (message: unknown) => void;
|
|
136
|
+
asyncEnd?: (message: unknown) => void;
|
|
137
|
+
error?: (message: unknown) => void;
|
|
138
|
+
}): void {
|
|
139
|
+
if (handlers.start) this.channels.start.unsubscribe(handlers.start);
|
|
140
|
+
if (handlers.end) this.channels.end.unsubscribe(handlers.end);
|
|
141
|
+
if (handlers.asyncStart) this.channels.asyncStart.unsubscribe(handlers.asyncStart);
|
|
142
|
+
if (handlers.asyncEnd) this.channels.asyncEnd.unsubscribe(handlers.asyncEnd);
|
|
143
|
+
if (handlers.error) this.channels.error.unsubscribe(handlers.error);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
traceSync<T>(fn: () => T, context?: unknown, thisArg?: unknown): T {
|
|
147
|
+
this.channels.start.publish(context);
|
|
148
|
+
try {
|
|
149
|
+
const result = fn.call(thisArg);
|
|
150
|
+
this.channels.end.publish(context);
|
|
151
|
+
return result;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
this.channels.error.publish({ error, ...context as object });
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async tracePromise<T>(fn: () => Promise<T>, context?: unknown, thisArg?: unknown): Promise<T> {
|
|
159
|
+
this.channels.start.publish(context);
|
|
160
|
+
try {
|
|
161
|
+
const result = await fn.call(thisArg);
|
|
162
|
+
this.channels.asyncEnd.publish(context);
|
|
163
|
+
return result;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.channels.error.publish({ error, ...context as object });
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
traceCallback<T extends (...args: unknown[]) => unknown>(
|
|
171
|
+
fn: T,
|
|
172
|
+
position?: number,
|
|
173
|
+
context?: unknown,
|
|
174
|
+
thisArg?: unknown
|
|
175
|
+
): T {
|
|
176
|
+
// Simplified callback tracing
|
|
177
|
+
return fn;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Create a TracingChannel
|
|
183
|
+
*/
|
|
184
|
+
export function tracingChannel(name: string): TracingChannel {
|
|
185
|
+
return new TracingChannel(name);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export default {
|
|
189
|
+
channel,
|
|
190
|
+
hasSubscribers,
|
|
191
|
+
subscribe,
|
|
192
|
+
unsubscribe,
|
|
193
|
+
tracingChannel,
|
|
194
|
+
Channel,
|
|
195
|
+
TracingChannel,
|
|
196
|
+
};
|
package/src/shims/dns.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dns shim - DNS operations are not available in browser
|
|
3
|
+
* Provides stubs that work for basic use cases
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// DNS lookup callback type
|
|
7
|
+
type LookupCallback = (err: Error | null, address?: string, family?: number) => void;
|
|
8
|
+
type LookupAllCallback = (err: Error | null, addresses?: Array<{ address: string; family: number }>) => void;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Lookup a hostname - returns localhost in browser
|
|
12
|
+
*/
|
|
13
|
+
export function lookup(
|
|
14
|
+
hostname: string,
|
|
15
|
+
callback: LookupCallback
|
|
16
|
+
): void;
|
|
17
|
+
export function lookup(
|
|
18
|
+
hostname: string,
|
|
19
|
+
options: { family?: number; all?: boolean },
|
|
20
|
+
callback: LookupCallback | LookupAllCallback
|
|
21
|
+
): void;
|
|
22
|
+
export function lookup(
|
|
23
|
+
hostname: string,
|
|
24
|
+
optionsOrCallback: { family?: number; all?: boolean } | LookupCallback,
|
|
25
|
+
callback?: LookupCallback | LookupAllCallback
|
|
26
|
+
): void {
|
|
27
|
+
const cb = typeof optionsOrCallback === 'function' ? optionsOrCallback : callback;
|
|
28
|
+
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
29
|
+
|
|
30
|
+
// In browser, we can't do real DNS lookups
|
|
31
|
+
// Return localhost for localhost, or a fake IP for other hostnames
|
|
32
|
+
setImmediate(() => {
|
|
33
|
+
if (hostname === 'localhost' || hostname === '127.0.0.1') {
|
|
34
|
+
if (options.all) {
|
|
35
|
+
(cb as LookupAllCallback)(null, [{ address: '127.0.0.1', family: 4 }]);
|
|
36
|
+
} else {
|
|
37
|
+
(cb as LookupCallback)(null, '127.0.0.1', 4);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
// For other hostnames, we can't resolve them in browser
|
|
41
|
+
// Return an error or a placeholder
|
|
42
|
+
if (options.all) {
|
|
43
|
+
(cb as LookupAllCallback)(null, [{ address: '0.0.0.0', family: 4 }]);
|
|
44
|
+
} else {
|
|
45
|
+
(cb as LookupCallback)(null, '0.0.0.0', 4);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve hostname - stub
|
|
53
|
+
*/
|
|
54
|
+
export function resolve(
|
|
55
|
+
hostname: string,
|
|
56
|
+
callback: (err: Error | null, addresses?: string[]) => void
|
|
57
|
+
): void {
|
|
58
|
+
setImmediate(() => {
|
|
59
|
+
callback(null, ['0.0.0.0']);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function resolve4(
|
|
64
|
+
hostname: string,
|
|
65
|
+
callback: (err: Error | null, addresses?: string[]) => void
|
|
66
|
+
): void {
|
|
67
|
+
resolve(hostname, callback);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function resolve6(
|
|
71
|
+
hostname: string,
|
|
72
|
+
callback: (err: Error | null, addresses?: string[]) => void
|
|
73
|
+
): void {
|
|
74
|
+
setImmediate(() => {
|
|
75
|
+
callback(null, ['::1']);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Reverse lookup - stub
|
|
81
|
+
*/
|
|
82
|
+
export function reverse(
|
|
83
|
+
ip: string,
|
|
84
|
+
callback: (err: Error | null, hostnames?: string[]) => void
|
|
85
|
+
): void {
|
|
86
|
+
setImmediate(() => {
|
|
87
|
+
callback(null, ['localhost']);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Set servers - no-op in browser
|
|
93
|
+
*/
|
|
94
|
+
export function setServers(_servers: string[]): void {
|
|
95
|
+
// No-op
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get servers - return empty in browser
|
|
100
|
+
*/
|
|
101
|
+
export function getServers(): string[] {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Set default result order - no-op in browser
|
|
107
|
+
* Order can be 'ipv4first', 'ipv6first', or 'verbatim'
|
|
108
|
+
*/
|
|
109
|
+
export function setDefaultResultOrder(_order: string): void {
|
|
110
|
+
// No-op in browser
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get default result order
|
|
115
|
+
*/
|
|
116
|
+
export function getDefaultResultOrder(): string {
|
|
117
|
+
return 'verbatim';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Promises API
|
|
121
|
+
export const promises = {
|
|
122
|
+
lookup: (hostname: string, options?: { family?: number; all?: boolean }) => {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
lookup(hostname, options || {}, (err, address, family) => {
|
|
125
|
+
if (err) reject(err);
|
|
126
|
+
else resolve({ address, family });
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
resolve: (hostname: string) => {
|
|
131
|
+
return new Promise<string[]>((promiseResolve, promiseReject) => {
|
|
132
|
+
resolve(hostname, (err, addresses) => {
|
|
133
|
+
if (err) promiseReject(err);
|
|
134
|
+
else promiseResolve(addresses || []);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
resolve4: (hostname: string) => promises.resolve(hostname),
|
|
139
|
+
resolve6: (hostname: string) => {
|
|
140
|
+
return new Promise<string[]>((resolve) => {
|
|
141
|
+
resolve(['::1']);
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
reverse: (ip: string) => {
|
|
145
|
+
return new Promise<string[]>((resolve) => {
|
|
146
|
+
resolve(['localhost']);
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
setServers: (_servers: string[]) => {},
|
|
150
|
+
getServers: () => [] as string[],
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// Constants
|
|
154
|
+
export const ADDRCONFIG = 0;
|
|
155
|
+
export const V4MAPPED = 0;
|
|
156
|
+
export const ALL = 0;
|
|
157
|
+
|
|
158
|
+
export default {
|
|
159
|
+
lookup,
|
|
160
|
+
resolve,
|
|
161
|
+
resolve4,
|
|
162
|
+
resolve6,
|
|
163
|
+
reverse,
|
|
164
|
+
setServers,
|
|
165
|
+
getServers,
|
|
166
|
+
setDefaultResultOrder,
|
|
167
|
+
getDefaultResultOrder,
|
|
168
|
+
promises,
|
|
169
|
+
ADDRCONFIG,
|
|
170
|
+
V4MAPPED,
|
|
171
|
+
ALL,
|
|
172
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js domain module shim
|
|
3
|
+
* The domain module is deprecated but some packages still use it
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EventEmitter } from './events';
|
|
7
|
+
|
|
8
|
+
export class Domain extends EventEmitter {
|
|
9
|
+
members: unknown[] = [];
|
|
10
|
+
|
|
11
|
+
add(emitter: EventEmitter): void {
|
|
12
|
+
this.members.push(emitter);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
remove(emitter: EventEmitter): void {
|
|
16
|
+
const index = this.members.indexOf(emitter);
|
|
17
|
+
if (index !== -1) {
|
|
18
|
+
this.members.splice(index, 1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
bind<T extends (...args: unknown[]) => unknown>(callback: T): T {
|
|
23
|
+
return callback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
intercept<T extends (...args: unknown[]) => unknown>(callback: T): T {
|
|
27
|
+
return callback;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
run<T>(fn: () => T): T {
|
|
31
|
+
return fn();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
dispose(): void {
|
|
35
|
+
this.members = [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
enter(): void {
|
|
39
|
+
// Stub
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exit(): void {
|
|
43
|
+
// Stub
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function create(): Domain {
|
|
48
|
+
return new Domain();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Active domain (deprecated but some packages check for it)
|
|
52
|
+
export let active: Domain | null = null;
|
|
53
|
+
|
|
54
|
+
export default {
|
|
55
|
+
Domain,
|
|
56
|
+
create,
|
|
57
|
+
active,
|
|
58
|
+
};
|