@volter/tabnode 0.4.1 → 0.5.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.
Files changed (80) hide show
  1. package/dist/__sw__.js +259 -5
  2. package/dist/assets/{runtime-worker-LWfW6VWE.js → runtime-worker-B9buriZs.js} +4004 -2955
  3. package/dist/fetch-transport.d.ts +20 -0
  4. package/dist/guest-timers.d.ts +15 -0
  5. package/dist/http-client-transport.d.ts +19 -0
  6. package/dist/index.d.ts +11 -0
  7. package/dist/index.mjs +5187 -3051
  8. package/dist/native-stream-binding.d.ts +57 -0
  9. package/dist/native-stream-owner.d.ts +121 -0
  10. package/dist/node-lib/binding/duplex_stream.d.ts +26 -0
  11. package/dist/node-lib/binding/fds.d.ts +8 -0
  12. package/dist/node-lib/binding/fs.d.ts +311 -78
  13. package/dist/node-lib/binding/misc.d.ts +1 -0
  14. package/dist/node-lib/binding/pipe_wrap.d.ts +4 -4
  15. package/dist/node-lib/binding/process_wrap.d.ts +12 -1
  16. package/dist/node-lib/binding/stream_wrap.d.ts +27 -18
  17. package/dist/node-lib/binding/tcp_wrap.d.ts +0 -1
  18. package/dist/node-lib/binding/tty_wrap.d.ts +43 -2
  19. package/dist/node-lib/binding/util.d.ts +83 -0
  20. package/dist/node-lib/binding/uv.d.ts +4 -0
  21. package/dist/node-lib/fs-module.d.ts +1 -0
  22. package/dist/node-lib/internals/buffer-and-streams.d.ts +30 -17
  23. package/dist/node-lib/internals/index.d.ts +1 -1
  24. package/dist/node-lib/load.d.ts +17 -3
  25. package/dist/node-lib/module-hooks.d.ts +1 -0
  26. package/dist/node-lib/public-modules.d.ts +1 -1
  27. package/dist/node-lib/timers.d.ts +38 -0
  28. package/dist/node-process-host.d.ts +41 -0
  29. package/dist/process-registry.d.ts +39 -0
  30. package/dist/process-tokens.d.ts +11 -0
  31. package/dist/promise-ownership.d.ts +3 -0
  32. package/dist/runtime.d.ts +10 -9
  33. package/dist/shims/child_process.d.ts +2 -0
  34. package/dist/shims/crypto.d.ts +660 -119
  35. package/dist/shims/dns.d.ts +76 -2
  36. package/dist/shims/process.d.ts +1 -0
  37. package/dist/shims/string_decoder.d.ts +19 -3
  38. package/dist/shims/tls.d.ts +853 -31
  39. package/dist/source-edits.d.ts +7 -0
  40. package/package.json +1 -1
  41. package/src/code-transforms.ts +2 -3
  42. package/src/fetch-transport.ts +98 -0
  43. package/src/guest-timers.ts +89 -0
  44. package/src/http-client-transport.ts +169 -0
  45. package/src/index.ts +12 -0
  46. package/src/native-stream-binding.ts +393 -0
  47. package/src/native-stream-owner.ts +317 -0
  48. package/src/node-lib/binding/duplex_stream.ts +95 -0
  49. package/src/node-lib/binding/fds.ts +18 -1
  50. package/src/node-lib/binding/fs.ts +45 -17
  51. package/src/node-lib/binding/misc.ts +2 -0
  52. package/src/node-lib/binding/pipe_wrap.ts +35 -12
  53. package/src/node-lib/binding/process_wrap.ts +50 -9
  54. package/src/node-lib/binding/stream_wrap.ts +196 -72
  55. package/src/node-lib/binding/tcp_wrap.ts +43 -8
  56. package/src/node-lib/binding/tty_wrap.ts +135 -8
  57. package/src/node-lib/binding/util.ts +24 -15
  58. package/src/node-lib/binding/uv.ts +4 -0
  59. package/src/node-lib/fs-module.ts +2 -18
  60. package/src/node-lib/internal/navigator.js +149 -0
  61. package/src/node-lib/internals/buffer-and-streams.ts +50 -11
  62. package/src/node-lib/internals/events-util.ts +5 -0
  63. package/src/node-lib/internals/index.ts +12 -2
  64. package/src/node-lib/load.ts +170 -62
  65. package/src/node-lib/module-hooks.ts +5 -2
  66. package/src/node-lib/public-modules.ts +12 -48
  67. package/src/node-lib/sources.ts +4 -0
  68. package/src/node-lib/timers.ts +93 -0
  69. package/src/node-process-host.ts +124 -0
  70. package/src/process-registry.ts +144 -0
  71. package/src/process-tokens.ts +55 -6
  72. package/src/promise-ownership.ts +28 -0
  73. package/src/runtime.ts +90 -214
  74. package/src/shims/child_process.ts +310 -80
  75. package/src/shims/crypto.ts +115 -100
  76. package/src/shims/dns.ts +17 -1
  77. package/src/shims/process.ts +33 -11
  78. package/src/shims/string_decoder.ts +10 -6
  79. package/src/shims/tls.ts +49 -19
  80. package/src/source-edits.ts +20 -0
@@ -33,10 +33,6 @@ interface BufferClass {
33
33
  from(value: unknown, offset?: unknown, length?: number): Buffer;
34
34
  alloc(size: number): Buffer;
35
35
  }
36
- let bufferClass: BufferClass | undefined;
37
- function Bytes(): BufferClass {
38
- return bufferClass ??= (loadNodeLib('buffer') as { Buffer: BufferClass }).Buffer;
39
- }
40
36
  import {
41
37
  ERR_INVALID_ARG_TYPE,
42
38
  ERR_INVALID_THIS,
@@ -66,6 +62,8 @@ interface StringDecoderConstructor {
66
62
  prototype: StringDecoder;
67
63
  }
68
64
 
65
+ /** A decoder's constructors and held bytes belong to one builtin graph. */
66
+ export function createStringDecoderModule(Bytes: () => BufferClass) {
69
67
  /** lib/internal/util.js normalizeEncoding, with Node's aliases. */
70
68
  const kEncodingAliases: Record<string, string> = {
71
69
  utf8: 'utf8', 'utf-8': 'utf8',
@@ -391,6 +389,12 @@ decoderPrototype.fillLast = function fillLast(this: unknown, buf: Buffer): strin
391
389
  return undefined;
392
390
  };
393
391
 
394
- export const StringDecoder = StringDecoderImpl as unknown as StringDecoderConstructor;
392
+ const StringDecoder = StringDecoderImpl as unknown as StringDecoderConstructor;
393
+
394
+ return { StringDecoder };
395
395
 
396
- export default { StringDecoder };
396
+ }
397
+ let bufferClass: BufferClass | undefined;
398
+ const decoder = createStringDecoderModule(() => bufferClass ??= (loadNodeLib('buffer') as { Buffer: BufferClass }).Buffer);
399
+ export const StringDecoder = decoder.StringDecoder;
400
+ export default decoder;
package/src/shims/tls.ts CHANGED
@@ -1,16 +1,40 @@
1
1
  /**
2
2
  * tls shim - TLS/SSL is not available in browser
3
- * Provides stubs that allow code to load without crashing
3
+ * No TLS transport is installed. A connection must fail asynchronously rather
4
+ * than pretending to connect and leaving Node's HTTPS client waiting forever.
4
5
  */
5
6
 
6
7
  import { EventEmitter } from '../node-lib/events-module';
7
-
8
- export class TLSSocket extends EventEmitter {
8
+ import { lazyExport } from '../node-lib/lazy';
9
+ import type { Socket } from '../node-lib/net-module';
10
+
11
+ // Keep the ordinary stream lifecycle (error, close, destroy) from Node's own
12
+ // Socket. Resolve it lazily, like the other builtin classes, to avoid a loader
13
+ // cycle while the engine is being imported.
14
+ /** Native TLS refusal keeps the requesting graph's Socket identity. */
15
+ export function createTlsModule(require?: (name: string) => any) {
16
+ const NetSocket = require ? require('net').Socket as new (options?: object) => Socket
17
+ : lazyExport<new (options?: object) => Socket>('net', 'Socket');
18
+ const Events = require ? require('events').EventEmitter as typeof EventEmitter : EventEmitter;
19
+
20
+ class TLSSocket extends NetSocket {
9
21
  authorized = false;
10
22
  encrypted = true;
11
23
 
12
24
  constructor(_socket?: unknown, _options?: unknown) {
13
- super();
25
+ super({ allowHalfOpen: false });
26
+ }
27
+
28
+ connect(..._args: unknown[]): this {
29
+ this.connecting = true;
30
+ // Never inherit a plain TCP connect while advertising an encrypted socket.
31
+ // Agent assigns its socket on nextTick after connect returns, so failure
32
+ // follows that assignment and reaches ClientRequest's error listener.
33
+ queueMicrotask(() => queueMicrotask(() => this.destroy(Object.assign(
34
+ new Error('TLS transport is unavailable in this runtime; HTTPS requires an admitted HTTP transport.'),
35
+ { code: 'ERR_TLS_UNAVAILABLE' },
36
+ ))));
37
+ return this;
14
38
  }
15
39
 
16
40
  getPeerCertificate(_detailed?: boolean): object {
@@ -32,7 +56,7 @@ export class TLSSocket extends EventEmitter {
32
56
  }
33
57
  }
34
58
 
35
- export class Server extends EventEmitter {
59
+ class Server extends Events {
36
60
  constructor(_options?: unknown, _connectionListener?: (socket: TLSSocket) => void) {
37
61
  super();
38
62
  }
@@ -50,7 +74,7 @@ export class Server extends EventEmitter {
50
74
  }
51
75
 
52
76
  getTicketKeys(): Buffer {
53
- return Buffer.from('');
77
+ return (require ? require('buffer').Buffer : Buffer).from('');
54
78
  }
55
79
 
56
80
  setTicketKeys(_keys: Buffer): void {}
@@ -58,29 +82,27 @@ export class Server extends EventEmitter {
58
82
  setSecureContext(_options: unknown): void {}
59
83
  }
60
84
 
61
- export function createServer(_options?: unknown, _connectionListener?: (socket: TLSSocket) => void): Server {
85
+ function createServer(_options?: unknown, _connectionListener?: (socket: TLSSocket) => void): Server {
62
86
  return new Server(_options, _connectionListener);
63
87
  }
64
88
 
65
- export function connect(_options: unknown, _callback?: () => void): TLSSocket {
89
+ function connect(_options: unknown, _callback?: () => void): TLSSocket {
66
90
  const socket = new TLSSocket();
67
- if (_callback) {
68
- setTimeout(_callback, 0);
69
- }
70
- return socket;
91
+ if (_callback) socket.once('secureConnect', _callback);
92
+ return socket.connect();
71
93
  }
72
94
 
73
- export const createSecureContext = (_options?: unknown) => ({});
95
+ const createSecureContext = (_options?: unknown) => ({});
74
96
 
75
- export const getCiphers = () => ['TLS_AES_256_GCM_SHA384', 'TLS_AES_128_GCM_SHA256'];
97
+ const getCiphers = () => ['TLS_AES_256_GCM_SHA384', 'TLS_AES_128_GCM_SHA256'];
76
98
 
77
- export const DEFAULT_ECDH_CURVE = 'auto';
78
- export const DEFAULT_MAX_VERSION = 'TLSv1.3';
79
- export const DEFAULT_MIN_VERSION = 'TLSv1.2';
99
+ const DEFAULT_ECDH_CURVE = 'auto';
100
+ const DEFAULT_MAX_VERSION = 'TLSv1.3';
101
+ const DEFAULT_MIN_VERSION = 'TLSv1.2';
80
102
 
81
- export const rootCertificates: string[] = [];
103
+ const rootCertificates: string[] = [];
82
104
 
83
- export default {
105
+ return {
84
106
  TLSSocket,
85
107
  Server,
86
108
  createServer,
@@ -92,3 +114,11 @@ export default {
92
114
  DEFAULT_MIN_VERSION,
93
115
  rootCertificates,
94
116
  };
117
+
118
+ }
119
+ const tls = createTlsModule();
120
+ export const { TLSSocket, Server, createServer, connect, createSecureContext, getCiphers,
121
+ DEFAULT_ECDH_CURVE, DEFAULT_MAX_VERSION, DEFAULT_MIN_VERSION, rootCertificates } = tls;
122
+ export type TLSSocket = InstanceType<typeof TLSSocket>;
123
+ export type Server = InstanceType<typeof Server>;
124
+ export default tls;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Apply non-overlapping edits in descending source order. The AST visitors
3
+ * decide the replacements; assembly must not copy a large module once per
4
+ * reference. For equal-position insertions, later edits appear before earlier
5
+ * ones, matching the former repeated slice/concatenate operation.
6
+ */
7
+ export function applySourceEdits(
8
+ source: string,
9
+ edits: readonly (readonly [start: number, end: number, text: string])[],
10
+ ): string {
11
+ if (edits.length === 0) return source;
12
+ const chunks: string[] = [];
13
+ let cursor = source.length;
14
+ for (const [start, end, text] of edits) {
15
+ chunks.push(source.slice(end, cursor), text);
16
+ cursor = start;
17
+ }
18
+ chunks.push(source.slice(0, cursor));
19
+ return chunks.reverse().join('');
20
+ }