@volter/tabnode 0.5.11 → 0.5.12

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/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ import { Runtime, RuntimeOptions } from './runtime';
44
44
  import { PackageManager } from './npm';
45
45
  import { ServerBridge } from './server-bridge';
46
46
  import { type Socket as NetSocket } from './node-lib/net-module';
47
+ import { type NativeStreamHandleView } from './native-stream-owner';
47
48
  import { runPid, processByPid } from './process-tokens';
48
49
  export { runPid, processByPid };
49
50
  export { createProcessRegistryScope, installProcessRegistry, ownerProcessRegistryScope, ownerProcessTable } from './process-tokens';
@@ -52,7 +53,7 @@ export type { NodeProcessLaunch, NodeProcessHost } from './node-process-host';
52
53
  export type { ProcessIdentity, ProcessRegistry, ProcessRegistryScope, InitialProcessRegistration } from './process-registry';
53
54
  export { NativeStreamScope } from './native-stream-owner';
54
55
  export { installNativeStreamTransport, nativeStreamDescriptor } from './native-stream-binding';
55
- export type { NativeStreamDescriptor, NativeStreamLimits, NativeStreamEvent, NativeStreamOperation, NativeStreamReply, NativeStreamTransport } from './native-stream-owner';
56
+ export type { NativeStreamDescriptor, NativeStreamLimits, NativeStreamEvent, NativeStreamOperation, NativeStreamReply, NativeStreamTransport, NativeStreamHandleView } from './native-stream-owner';
56
57
  export interface RunResult {
57
58
  stdout: string;
58
59
  stderr: string;
@@ -116,6 +117,8 @@ export declare function createContainer(options?: ContainerOptions): {
116
117
  processPorts: (token: string) => number[];
117
118
  /** The pid of the process listening on a port of this engine, where a guest process is: `/proc`'s socket owner. */
118
119
  portPid: (port: number) => number | undefined;
120
+ /** The stream handles the processes of other workers hold through this engine: `/proc/<pid>/fd`. */
121
+ streamHandles: () => NativeStreamHandleView[];
119
122
  /** Deliver a signal to the named run as another process's `kill(pid)` does; false when the run is gone. */
120
123
  signalProcess: (token: string, signal: string) => boolean;
121
124
  stopProcess: (token: string) => boolean;
package/dist/index.mjs CHANGED
@@ -38098,6 +38098,7 @@ function resetServerBridge() {
38098
38098
  globalBridge = null;
38099
38099
  }
38100
38100
  const scopes = /* @__PURE__ */ new WeakMap();
38101
+ const liveScopes = /* @__PURE__ */ new Set();
38101
38102
  class NativeStreamScope {
38102
38103
  /**
38103
38104
  * `ownerPid` names the process whose worker this scope serves: a listener
@@ -38116,6 +38117,19 @@ class NativeStreamScope {
38116
38117
  this.ownerPid = ownerPid;
38117
38118
  if ([limits.maxHandles, limits.maxReadChunkBytes, limits.maxQueuedBytes, limits.maxQueuedHandles, limits.maxPendingWriteBytes].some((value) => !Number.isSafeInteger(value) || value < 1) || limits.maxReadChunkBytes > 2147483647 || limits.maxReadChunkBytes > limits.maxQueuedBytes || limits.maxReadChunkBytes > limits.maxPendingWriteBytes) throw new Error("Invalid native stream resource limits.");
38118
38119
  this.limits = Object.freeze({ ...limits });
38120
+ liveScopes.add(this);
38121
+ }
38122
+ /** This scope's open handles, with the process it serves. */
38123
+ handles() {
38124
+ var _a2;
38125
+ if (this.disposed) return [];
38126
+ const pid = (_a2 = this.ownerPid) == null ? void 0 : _a2.call(this);
38127
+ return [...this.entries.values()].map(({ handle, descriptor }) => ({
38128
+ ...pid !== void 0 ? { pid } : {},
38129
+ id: descriptor.id,
38130
+ kind: descriptor.kind,
38131
+ listening: !!handle.listening
38132
+ }));
38119
38133
  }
38120
38134
  entry(id) {
38121
38135
  return this.disposed ? void 0 : this.entries.get(id);
@@ -38387,6 +38401,7 @@ class NativeStreamScope {
38387
38401
  dispose() {
38388
38402
  if (this.disposed) return;
38389
38403
  this.disposed = true;
38404
+ liveScopes.delete(this);
38390
38405
  const failures = [];
38391
38406
  for (const id of [...this.entries.keys()]) {
38392
38407
  try {
@@ -38402,6 +38417,9 @@ function nativeStreamOwnerPid(handle) {
38402
38417
  var _a2, _b2;
38403
38418
  return (_b2 = (_a2 = scopes.get(handle)) == null ? void 0 : _a2.ownerPid) == null ? void 0 : _b2.call(_a2);
38404
38419
  }
38420
+ function nativeStreamHandles() {
38421
+ return [...liveScopes].flatMap((scope) => scope.handles());
38422
+ }
38405
38423
  let __nextRunName = 1;
38406
38424
  function createContainer(options) {
38407
38425
  const vfs2 = options && options.vfs || new VirtualFS();
@@ -38464,6 +38482,7 @@ function createContainer(options) {
38464
38482
  if (!listener) return void 0;
38465
38483
  return ((_a2 = runPid(ownerOf(listener))) == null ? void 0 : _a2.pid) ?? nativeStreamOwnerPid(listener);
38466
38484
  },
38485
+ streamHandles: () => nativeStreamHandles(),
38467
38486
  /**
38468
38487
  * Deliver a signal to the named run as another process's `kill(pid)` does:
38469
38488
  * the guest's listeners for it run, else its default action ends the run.
@@ -88,6 +88,13 @@ export interface NativeStreamTransport {
88
88
  write(id: number, bytes: Uint8Array, handle?: number): Promise<number>;
89
89
  onEvent(listener: (event: NativeStreamEvent) => void): () => void;
90
90
  }
91
+ /** One open stream handle, as a process's descriptor table shows it. */
92
+ export interface NativeStreamHandleView {
93
+ pid?: number;
94
+ id: number;
95
+ kind: 'tcp' | 'pipe';
96
+ listening: boolean;
97
+ }
91
98
  /**
92
99
  * One capability namespace per worker. Only the trusted host can inherit a
93
100
  * descriptor from another scope; wire operations can name this scope's IDs only.
@@ -108,6 +115,8 @@ export declare class NativeStreamScope {
108
115
  * it opens is that process's socket, as the container's /proc shows it.
109
116
  */
110
117
  constructor(limits: NativeStreamLimits, emit: (event: NativeStreamEvent) => void, ownerPid?: (() => number | undefined) | undefined);
118
+ /** This scope's open handles, with the process it serves. */
119
+ handles(): NativeStreamHandleView[];
111
120
  private entry;
112
121
  private publish;
113
122
  private claim;
@@ -126,3 +135,5 @@ export declare class NativeStreamScope {
126
135
  }
127
136
  /** The process a handle opened for another worker's process belongs to, where a scope holds it. */
128
137
  export declare function nativeStreamOwnerPid(handle: object): number | undefined;
138
+ /** Every open native stream handle in this worker, by the process each scope serves. */
139
+ export declare function nativeStreamHandles(): NativeStreamHandleView[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/tabnode",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "description": "Node's own library, in a browser tab.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -56,7 +56,7 @@ import { runCommand, registerRunStreams, releaseRunStreams, sendStdin } from './
56
56
  import { Server as NetServer, __releaseOwnedHandles, type Socket as NetSocket } from './node-lib/net-module';
57
57
  import { __adoptHandle, ownerOf, type OwnedHandle } from './node-lib/binding/handles';
58
58
  import { listenerOnPort } from './node-lib/binding/tcp_wrap';
59
- import { nativeStreamOwnerPid } from './native-stream-owner';
59
+ import { nativeStreamHandles, nativeStreamOwnerPid, type NativeStreamHandleView } from './native-stream-owner';
60
60
 
61
61
  import { __currentProcessToken, __runFor, __signalOwnedProcess, __takeTermination, __stopOwnedProcess, runPid, processByPid } from './process-tokens';
62
62
  export { runPid, processByPid };
@@ -66,7 +66,7 @@ export type { NodeProcessLaunch, NodeProcessHost } from './node-process-host';
66
66
  export type { ProcessIdentity, ProcessRegistry, ProcessRegistryScope, InitialProcessRegistration } from './process-registry';
67
67
  export { NativeStreamScope } from './native-stream-owner';
68
68
  export { installNativeStreamTransport, nativeStreamDescriptor } from './native-stream-binding';
69
- export type { NativeStreamDescriptor, NativeStreamLimits, NativeStreamEvent, NativeStreamOperation, NativeStreamReply, NativeStreamTransport } from './native-stream-owner';
69
+ export type { NativeStreamDescriptor, NativeStreamLimits, NativeStreamEvent, NativeStreamOperation, NativeStreamReply, NativeStreamTransport, NativeStreamHandleView } from './native-stream-owner';
70
70
 
71
71
  export interface RunResult {
72
72
  stdout: string;
@@ -129,6 +129,8 @@ export function createContainer(options?: ContainerOptions): {
129
129
  processPorts: (token: string) => number[];
130
130
  /** The pid of the process listening on a port of this engine, where a guest process is: `/proc`'s socket owner. */
131
131
  portPid: (port: number) => number | undefined;
132
+ /** The stream handles the processes of other workers hold through this engine: `/proc/<pid>/fd`. */
133
+ streamHandles: () => NativeStreamHandleView[];
132
134
  /** Deliver a signal to the named run as another process's `kill(pid)` does; false when the run is gone. */
133
135
  signalProcess: (token: string, signal: string) => boolean;
134
136
  stopProcess: (token: string) => boolean;
@@ -224,6 +226,7 @@ export function createContainer(options?: ContainerOptions): {
224
226
  // a guest's own listener, or one this engine holds for another worker's process
225
227
  return runPid(ownerOf(listener as unknown as OwnedHandle))?.pid ?? nativeStreamOwnerPid(listener);
226
228
  },
229
+ streamHandles: (): NativeStreamHandleView[] => nativeStreamHandles(),
227
230
  /**
228
231
  * Deliver a signal to the named run as another process's `kill(pid)` does:
229
232
  * the guest's listeners for it run, else its default action ends the run.
@@ -41,6 +41,12 @@ export interface NativeStreamTransport {
41
41
  type NativeHandle = TCP | Pipe;
42
42
  interface Entry { handle: NativeHandle; descriptor: NativeStreamDescriptor; buffer?: Uint8Array }
43
43
  const scopes = new WeakMap<LibuvStreamWrap, NativeStreamScope>();
44
+ // Every scope not yet disposed: what the container's /proc lists as each
45
+ // process's descriptors.
46
+ const liveScopes = new Set<NativeStreamScope>();
47
+
48
+ /** One open stream handle, as a process's descriptor table shows it. */
49
+ export interface NativeStreamHandleView { pid?: number; id: number; kind: 'tcp' | 'pipe'; listening: boolean }
44
50
 
45
51
  /**
46
52
  * One capability namespace per worker. Only the trusted host can inherit a
@@ -66,6 +72,16 @@ export class NativeStreamScope {
66
72
  || limits.maxReadChunkBytes > limits.maxQueuedBytes
67
73
  || limits.maxReadChunkBytes > limits.maxPendingWriteBytes) throw new Error('Invalid native stream resource limits.');
68
74
  this.limits = Object.freeze({ ...limits });
75
+ liveScopes.add(this);
76
+ }
77
+
78
+ /** This scope's open handles, with the process it serves. */
79
+ handles(): NativeStreamHandleView[] {
80
+ if (this.disposed) return [];
81
+ const pid = this.ownerPid?.();
82
+ return [...this.entries.values()].map(({ handle, descriptor }) => ({
83
+ ...(pid !== undefined ? { pid } : {}), id: descriptor.id, kind: descriptor.kind, listening: !!handle.listening,
84
+ }));
69
85
  }
70
86
 
71
87
  private entry(id: number): Entry | undefined {
@@ -318,6 +334,7 @@ export class NativeStreamScope {
318
334
  dispose(): void {
319
335
  if (this.disposed) return;
320
336
  this.disposed = true;
337
+ liveScopes.delete(this);
321
338
  const failures: unknown[] = [];
322
339
  for (const id of [...this.entries.keys()]) {
323
340
  try { this.close(id); } catch (cause) { failures.push(cause); }
@@ -330,3 +347,8 @@ export class NativeStreamScope {
330
347
  export function nativeStreamOwnerPid(handle: object): number | undefined {
331
348
  return scopes.get(handle as NativeHandle)?.ownerPid?.();
332
349
  }
350
+
351
+ /** Every open native stream handle in this worker, by the process each scope serves. */
352
+ export function nativeStreamHandles(): NativeStreamHandleView[] {
353
+ return [...liveScopes].flatMap(scope => scope.handles());
354
+ }