@ricsam/isolate 0.1.11 → 0.1.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/README.md +86 -1
- package/dist/cjs/bridge/runtime-bindings.cjs +28 -1
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +100 -1
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +3 -3
- package/dist/cjs/host/create-isolate-host.cjs +80 -1
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +61 -3
- package/dist/cjs/host/nested-host-controller.cjs.map +3 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/internal/browser-source.cjs +16 -5
- package/dist/cjs/internal/browser-source.cjs.map +3 -3
- package/dist/cjs/internal/client/connection.cjs +12 -1
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/daemon/connection.cjs +28 -10
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/protocol/types.cjs +2 -1
- package/dist/cjs/internal/protocol/types.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +33 -1
- package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/playwright.cjs +76 -0
- package/dist/cjs/playwright.cjs.map +10 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs +181 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs.map +10 -0
- package/dist/mjs/bridge/runtime-bindings.mjs +28 -1
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +100 -1
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +3 -3
- package/dist/mjs/host/create-isolate-host.mjs +80 -1
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +61 -3
- package/dist/mjs/host/nested-host-controller.mjs.map +3 -3
- package/dist/mjs/index.mjs.map +1 -1
- package/dist/mjs/internal/browser-source.mjs +16 -5
- package/dist/mjs/internal/browser-source.mjs.map +3 -3
- package/dist/mjs/internal/client/connection.mjs +12 -1
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/daemon/connection.mjs +28 -10
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/protocol/types.mjs +2 -1
- package/dist/mjs/internal/protocol/types.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +33 -1
- package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/playwright.mjs +47 -0
- package/dist/mjs/playwright.mjs.map +10 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs +143 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs.map +10 -0
- package/dist/types/bridge/sandbox-isolate.d.ts +9 -3
- package/dist/types/host/nested-host-controller.d.ts +5 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/browser-source.d.ts +1 -2
- package/dist/types/internal/client/types.d.ts +4 -0
- package/dist/types/internal/protocol/types.d.ts +8 -1
- package/dist/types/internal/typecheck/isolate-types.d.ts +2 -2
- package/dist/types/playwright.d.ts +26 -0
- package/dist/types/runtime/namespaced-runtime.d.ts +11 -0
- package/dist/types/types.d.ts +45 -3
- package/package.json +6 -1
|
@@ -73,6 +73,7 @@ var import_client = require("../internal/client/index.cjs");
|
|
|
73
73
|
var import_browser_source = require("../internal/browser-source.cjs");
|
|
74
74
|
var import_diagnostics = require("../bridge/diagnostics.cjs");
|
|
75
75
|
var import_runtime_bindings = require("../bridge/runtime-bindings.cjs");
|
|
76
|
+
var import_namespaced_runtime = require("../runtime/namespaced-runtime.cjs");
|
|
76
77
|
var import_script_runtime = require("../runtime/script-runtime.cjs");
|
|
77
78
|
var import_test_runtime = require("../runtime/test-runtime.cjs");
|
|
78
79
|
var import_app_server = require("../server/app-server.cjs");
|
|
@@ -95,6 +96,21 @@ async function waitForSocket(socketPath, timeoutMs) {
|
|
|
95
96
|
}
|
|
96
97
|
throw new Error(`Daemon socket not available after ${timeoutMs}ms`);
|
|
97
98
|
}
|
|
99
|
+
function createNamedError(name, message) {
|
|
100
|
+
const error = new Error(message);
|
|
101
|
+
error.name = name;
|
|
102
|
+
return error;
|
|
103
|
+
}
|
|
104
|
+
function normalizeNamespaceInUseError(error, key) {
|
|
105
|
+
if (error instanceof Error && error.name === "NamespaceInUseError") {
|
|
106
|
+
return error;
|
|
107
|
+
}
|
|
108
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
109
|
+
if (/already has an active runtime|creation already in progress/i.test(message)) {
|
|
110
|
+
return createNamedError("NamespaceInUseError", `Namespace "${key}" already has a live runtime.`);
|
|
111
|
+
}
|
|
112
|
+
return error instanceof Error ? error : new Error(message);
|
|
113
|
+
}
|
|
98
114
|
|
|
99
115
|
class HostImpl {
|
|
100
116
|
options;
|
|
@@ -103,6 +119,8 @@ class HostImpl {
|
|
|
103
119
|
connectionPromise = null;
|
|
104
120
|
servers = new Set;
|
|
105
121
|
runtimes = new Set;
|
|
122
|
+
namespacedRuntimes = new Map;
|
|
123
|
+
pendingNamespacedKeys = new Set;
|
|
106
124
|
constructor(options) {
|
|
107
125
|
this.options = options ?? {};
|
|
108
126
|
}
|
|
@@ -115,6 +133,21 @@ class HostImpl {
|
|
|
115
133
|
async createTestRuntime(options) {
|
|
116
134
|
return await this.createTestRuntimeInternal(options);
|
|
117
135
|
}
|
|
136
|
+
async getNamespacedRuntime(key, options) {
|
|
137
|
+
return await this.createNamespacedRuntimeInternal(key, options);
|
|
138
|
+
}
|
|
139
|
+
async disposeNamespace(key, options) {
|
|
140
|
+
this.pendingNamespacedKeys.delete(key);
|
|
141
|
+
const runtime = this.namespacedRuntimes.get(key);
|
|
142
|
+
if (runtime) {
|
|
143
|
+
runtime.invalidate(options?.reason ? `Namespace "${key}" was disposed: ${options.reason}` : `Namespace "${key}" was disposed.`);
|
|
144
|
+
this.namespacedRuntimes.delete(key);
|
|
145
|
+
}
|
|
146
|
+
const connection = await this.getConnection();
|
|
147
|
+
await connection.disposeNamespace(key, {
|
|
148
|
+
reason: options?.reason
|
|
149
|
+
});
|
|
150
|
+
}
|
|
118
151
|
async diagnostics() {
|
|
119
152
|
return {
|
|
120
153
|
runtimes: this.runtimes.size,
|
|
@@ -123,6 +156,11 @@ class HostImpl {
|
|
|
123
156
|
};
|
|
124
157
|
}
|
|
125
158
|
async close() {
|
|
159
|
+
for (const [key, runtime] of this.namespacedRuntimes) {
|
|
160
|
+
runtime.invalidate(`Host closed while namespace "${key}" was active.`);
|
|
161
|
+
}
|
|
162
|
+
this.namespacedRuntimes.clear();
|
|
163
|
+
this.pendingNamespacedKeys.clear();
|
|
126
164
|
if (this.connection) {
|
|
127
165
|
await this.connection.close().catch(() => {});
|
|
128
166
|
}
|
|
@@ -172,6 +210,45 @@ class HostImpl {
|
|
|
172
210
|
this.runtimes.add(testRuntime);
|
|
173
211
|
return testRuntime;
|
|
174
212
|
}
|
|
213
|
+
async createNamespacedRuntimeInternal(key, options) {
|
|
214
|
+
if (this.pendingNamespacedKeys.has(key) || this.namespacedRuntimes.has(key)) {
|
|
215
|
+
throw createNamedError("NamespaceInUseError", `Namespace "${key}" already has a live runtime.`);
|
|
216
|
+
}
|
|
217
|
+
this.pendingNamespacedKeys.add(key);
|
|
218
|
+
const diagnostics = import_diagnostics.createRuntimeDiagnostics();
|
|
219
|
+
let runtimeId = key;
|
|
220
|
+
const browserSource = import_browser_source.createBrowserSourceFromBindings(options.bindings.browser);
|
|
221
|
+
const bindingsAdapter = import_runtime_bindings.createRuntimeBindingsAdapter(options.bindings, () => runtimeId, diagnostics, {
|
|
222
|
+
nestedHost: this.createNestedBindings(browserSource)
|
|
223
|
+
});
|
|
224
|
+
try {
|
|
225
|
+
const runtime = await this.createRemoteRuntime({
|
|
226
|
+
...bindingsAdapter.runtimeOptions,
|
|
227
|
+
cwd: options.cwd,
|
|
228
|
+
memoryLimitMB: options.memoryLimitMB,
|
|
229
|
+
executionTimeout: options.executionTimeout,
|
|
230
|
+
testEnvironment: true
|
|
231
|
+
}, key);
|
|
232
|
+
runtimeId = runtime.id;
|
|
233
|
+
let adapter;
|
|
234
|
+
adapter = import_namespaced_runtime.createNamespacedRuntimeAdapter(runtime, diagnostics, {
|
|
235
|
+
hasBrowser: Boolean(options.bindings.browser),
|
|
236
|
+
abortBindings: (reason) => bindingsAdapter.abort(reason),
|
|
237
|
+
onRelease: () => {
|
|
238
|
+
if (this.namespacedRuntimes.get(key) === adapter) {
|
|
239
|
+
this.namespacedRuntimes.delete(key);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
this.namespacedRuntimes.set(key, adapter);
|
|
244
|
+
this.runtimes.add(adapter);
|
|
245
|
+
return adapter;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
throw normalizeNamespaceInUseError(error, key);
|
|
248
|
+
} finally {
|
|
249
|
+
this.pendingNamespacedKeys.delete(key);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
175
252
|
async createAppServerInternal(options) {
|
|
176
253
|
const server = await import_app_server.createAppServerAdapter(() => this.getConnection(), options, {
|
|
177
254
|
nestedHost: this.createNestedBindings(import_browser_source.createBrowserSourceFromBindings(options.bindings.browser))
|
|
@@ -184,6 +261,8 @@ class HostImpl {
|
|
|
184
261
|
createRuntime: async (options) => await this.createRuntimeInternal(options),
|
|
185
262
|
createAppServer: async (options) => await this.createAppServerInternal(options),
|
|
186
263
|
createTestRuntime: async (options) => await this.createTestRuntimeInternal(options),
|
|
264
|
+
getNamespacedRuntime: async (key, options) => await this.createNamespacedRuntimeInternal(key, options),
|
|
265
|
+
disposeNamespace: async (key, options) => await this.disposeNamespace(key, options),
|
|
187
266
|
isConnected: () => this.connection?.isConnected() ?? false
|
|
188
267
|
}, defaultBrowserSource);
|
|
189
268
|
}
|
|
@@ -258,4 +337,4 @@ async function createIsolateHost(options) {
|
|
|
258
337
|
return new HostImpl(options);
|
|
259
338
|
}
|
|
260
339
|
|
|
261
|
-
//# debugId=
|
|
340
|
+
//# debugId=C33F7BE7F5125BD164756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/host/create-isolate-host.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { spawn, type ChildProcess } from \"node:child_process\";\nimport { connect, type DaemonConnection, type RemoteRuntime, type RuntimeOptions } from \"../internal/client/index.cjs\";\nimport {\n createBrowserSourceFromBindings,\n type BrowserSource,\n} from \"../internal/browser-source.cjs\";\nimport { createRuntimeDiagnostics } from \"../bridge/diagnostics.cjs\";\nimport { createRuntimeBindingsAdapter } from \"../bridge/runtime-bindings.cjs\";\nimport { createScriptRuntimeAdapter } from \"../runtime/script-runtime.cjs\";\nimport { createTestRuntimeAdapter } from \"../runtime/test-runtime.cjs\";\nimport { createAppServerAdapter } from \"../server/app-server.cjs\";\nimport { createNestedHostBindings } from \"./nested-host-controller.cjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateIsolateHostOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n IsolateHost,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.cjs\";\n\nfunction resolveDefaultDaemonEntrypoint(): string | null {\n const localPath = path.resolve(import.meta.dirname, \"../daemon.ts\");\n if (fs.existsSync(localPath)) {\n return localPath;\n }\n return null;\n}\n\nasync function waitForSocket(socketPath: string, timeoutMs: number): Promise<void> {\n const startTime = Date.now();\n while (Date.now() - startTime < timeoutMs) {\n if (fs.existsSync(socketPath)) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 50));\n }\n\n throw new Error(`Daemon socket not available after ${timeoutMs}ms`);\n}\n\nclass HostImpl implements IsolateHost {\n private readonly options: CreateIsolateHostOptions;\n private daemonProcess: ChildProcess | null = null;\n private connection: DaemonConnection | null = null;\n private connectionPromise: Promise<DaemonConnection> | null = null;\n private readonly servers = new Set<object>();\n private readonly runtimes = new Set<object>();\n\n constructor(options?: CreateIsolateHostOptions) {\n this.options = options ?? {};\n }\n\n async createAppServer(options: CreateAppServerOptions) {\n return await this.createAppServerInternal(options);\n }\n\n async createRuntime(options: CreateRuntimeOptions) {\n return await this.createRuntimeInternal(options);\n }\n\n async createTestRuntime(options: CreateTestRuntimeOptions) {\n return await this.createTestRuntimeInternal(options);\n }\n\n async diagnostics() {\n return {\n runtimes: this.runtimes.size,\n servers: this.servers.size,\n connected: this.connection?.isConnected() ?? false,\n };\n }\n\n async close(): Promise<void> {\n if (this.connection) {\n await this.connection.close().catch(() => {});\n }\n this.connection = null;\n this.connectionPromise = null;\n\n if (this.daemonProcess) {\n const process = this.daemonProcess;\n this.daemonProcess = null;\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n process.kill(\"SIGKILL\");\n resolve();\n }, 5000);\n process.once(\"exit\", () => {\n clearTimeout(timeout);\n resolve();\n });\n process.kill(\"SIGTERM\");\n });\n }\n }\n\n private async createRuntimeInternal(\n options: CreateRuntimeOptions,\n ): Promise<ScriptRuntime> {\n const diagnostics = createRuntimeDiagnostics();\n let runtimeId = options.key ?? \"runtime\";\n const browserSource = createBrowserSourceFromBindings(options.bindings.browser);\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n {\n nestedHost: this.createNestedBindings(browserSource),\n },\n );\n const runtime = await this.createRemoteRuntime(\n {\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n },\n options.key,\n );\n runtimeId = runtime.id;\n const adapter = createScriptRuntimeAdapter(runtime, diagnostics, {\n hasBrowser: Boolean(options.bindings.browser),\n onBeforeDispose: (reason) => bindingsAdapter.abort(reason),\n });\n this.runtimes.add(adapter);\n return adapter;\n }\n\n private async createTestRuntimeInternal(\n options: CreateTestRuntimeOptions,\n ): Promise<TestRuntime> {\n const testRuntime = await createTestRuntimeAdapter(\n async (runtimeOptions) => await this.createRemoteRuntime(runtimeOptions, options.key),\n options,\n {\n nestedHost: this.createNestedBindings(\n createBrowserSourceFromBindings(options.bindings.browser),\n ),\n },\n );\n this.runtimes.add(testRuntime);\n return testRuntime;\n }\n\n private async createAppServerInternal(\n options: CreateAppServerOptions,\n ): Promise<AppServer> {\n const server = await createAppServerAdapter(\n () => this.getConnection(),\n options,\n {\n nestedHost: this.createNestedBindings(\n createBrowserSourceFromBindings(options.bindings.browser),\n ),\n },\n );\n this.servers.add(server);\n return server;\n }\n\n private createNestedBindings(\n defaultBrowserSource: BrowserSource | undefined,\n ) {\n return createNestedHostBindings(\n {\n createRuntime: async (options) => await this.createRuntimeInternal(options),\n createAppServer: async (options) =>\n await this.createAppServerInternal(options),\n createTestRuntime: async (options) =>\n await this.createTestRuntimeInternal(options),\n isConnected: () => this.connection?.isConnected() ?? false,\n },\n defaultBrowserSource,\n );\n }\n\n private async createRemoteRuntime(options: RuntimeOptions, key?: string): Promise<RemoteRuntime> {\n const connection = await this.getConnection();\n if (key) {\n return await connection.createNamespace(key).createRuntime(options);\n }\n return await connection.createRuntime(options);\n }\n\n private async getConnection(): Promise<DaemonConnection> {\n if (this.connection?.isConnected()) {\n return this.connection;\n }\n if (this.connectionPromise) {\n return this.connectionPromise;\n }\n\n this.connectionPromise = (async () => {\n await this.ensureDaemon();\n this.connection = await connect({\n socket: this.options.daemon?.socketPath ?? \"/tmp/isolate.sock\",\n timeout: this.options.daemon?.timeoutMs ?? 5000,\n });\n return this.connection;\n })();\n\n return await this.connectionPromise.finally(() => {\n this.connectionPromise = null;\n });\n }\n\n private async ensureDaemon(): Promise<void> {\n if (this.connection?.isConnected()) {\n return;\n }\n\n if (this.options.daemon?.autoStart === false) {\n return;\n }\n\n if (this.daemonProcess) {\n return;\n }\n\n const socketPath = this.options.daemon?.socketPath ?? \"/tmp/isolate.sock\";\n const entrypoint = this.options.daemon?.entrypoint ?? resolveDefaultDaemonEntrypoint();\n\n try {\n if (fs.existsSync(socketPath)) {\n fs.unlinkSync(socketPath);\n }\n } catch {\n // ignore stale socket cleanup failures\n }\n\n const cli = entrypoint\n ? [\"node\", \"--experimental-strip-types\", entrypoint, \"--socket\", socketPath]\n : [\"isolate-daemon\", \"--socket\", socketPath];\n const cwd = this.options.daemon?.cwd ?? (entrypoint ? path.resolve(import.meta.dirname, \"../..\") : process.cwd());\n this.daemonProcess = spawn(cli[0]!, cli.slice(1), {\n cwd,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n env: {\n ...process.env,\n NODE_OPTIONS: \"\",\n },\n });\n\n this.daemonProcess.stdout?.on(\"data\", (data: Buffer) => {\n console.log(\"[isolate-host]\", data.toString().trim());\n });\n this.daemonProcess.stderr?.on(\"data\", (data: Buffer) => {\n console.error(\"[isolate-host]\", data.toString().trim());\n });\n this.daemonProcess.on(\"exit\", () => {\n this.daemonProcess = null;\n this.connection = null;\n this.connectionPromise = null;\n });\n\n await waitForSocket(socketPath, this.options.daemon?.timeoutMs ?? 10_000);\n }\n}\n\nexport async function createIsolateHost(options?: CreateIsolateHostOptions): Promise<IsolateHost> {\n return new HostImpl(options);\n}\n"
|
|
5
|
+
"import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { spawn, type ChildProcess } from \"node:child_process\";\nimport { connect, type DaemonConnection, type RemoteRuntime, type RuntimeOptions } from \"../internal/client/index.cjs\";\nimport {\n createBrowserSourceFromBindings,\n type BrowserSource,\n} from \"../internal/browser-source.cjs\";\nimport { createRuntimeDiagnostics } from \"../bridge/diagnostics.cjs\";\nimport { createRuntimeBindingsAdapter } from \"../bridge/runtime-bindings.cjs\";\nimport { createNamespacedRuntimeAdapter } from \"../runtime/namespaced-runtime.cjs\";\nimport { createScriptRuntimeAdapter } from \"../runtime/script-runtime.cjs\";\nimport { createTestRuntimeAdapter } from \"../runtime/test-runtime.cjs\";\nimport { createAppServerAdapter } from \"../server/app-server.cjs\";\nimport { createNestedHostBindings } from \"./nested-host-controller.cjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateIsolateHostOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n IsolateHost,\n NamespacedRuntime,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.cjs\";\n\nfunction resolveDefaultDaemonEntrypoint(): string | null {\n const localPath = path.resolve(import.meta.dirname, \"../daemon.ts\");\n if (fs.existsSync(localPath)) {\n return localPath;\n }\n return null;\n}\n\nasync function waitForSocket(socketPath: string, timeoutMs: number): Promise<void> {\n const startTime = Date.now();\n while (Date.now() - startTime < timeoutMs) {\n if (fs.existsSync(socketPath)) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 50));\n }\n\n throw new Error(`Daemon socket not available after ${timeoutMs}ms`);\n}\n\nfunction createNamedError(name: string, message: string): Error {\n const error = new Error(message);\n error.name = name;\n return error;\n}\n\nfunction normalizeNamespaceInUseError(error: unknown, key: string): Error {\n if (error instanceof Error && error.name === \"NamespaceInUseError\") {\n return error;\n }\n\n const message =\n error instanceof Error ? error.message : String(error ?? \"\");\n if (/already has an active runtime|creation already in progress/i.test(message)) {\n return createNamedError(\n \"NamespaceInUseError\",\n `Namespace \"${key}\" already has a live runtime.`,\n );\n }\n\n return error instanceof Error ? error : new Error(message);\n}\n\nclass HostImpl implements IsolateHost {\n private readonly options: CreateIsolateHostOptions;\n private daemonProcess: ChildProcess | null = null;\n private connection: DaemonConnection | null = null;\n private connectionPromise: Promise<DaemonConnection> | null = null;\n private readonly servers = new Set<object>();\n private readonly runtimes = new Set<object>();\n private readonly namespacedRuntimes = new Map<string, ReturnType<typeof createNamespacedRuntimeAdapter>>();\n private readonly pendingNamespacedKeys = new Set<string>();\n\n constructor(options?: CreateIsolateHostOptions) {\n this.options = options ?? {};\n }\n\n async createAppServer(options: CreateAppServerOptions) {\n return await this.createAppServerInternal(options);\n }\n\n async createRuntime(options: CreateRuntimeOptions) {\n return await this.createRuntimeInternal(options);\n }\n\n async createTestRuntime(options: CreateTestRuntimeOptions) {\n return await this.createTestRuntimeInternal(options);\n }\n\n async getNamespacedRuntime(\n key: string,\n options: CreateNamespacedRuntimeOptions,\n ) {\n return await this.createNamespacedRuntimeInternal(key, options);\n }\n\n async disposeNamespace(key: string, options?: { reason?: string }) {\n this.pendingNamespacedKeys.delete(key);\n const runtime = this.namespacedRuntimes.get(key);\n if (runtime) {\n runtime.invalidate(\n options?.reason\n ? `Namespace \"${key}\" was disposed: ${options.reason}`\n : `Namespace \"${key}\" was disposed.`,\n );\n this.namespacedRuntimes.delete(key);\n }\n\n const connection = await this.getConnection();\n await connection.disposeNamespace(key, {\n reason: options?.reason,\n });\n }\n\n async diagnostics() {\n return {\n runtimes: this.runtimes.size,\n servers: this.servers.size,\n connected: this.connection?.isConnected() ?? false,\n };\n }\n\n async close(): Promise<void> {\n for (const [key, runtime] of this.namespacedRuntimes) {\n runtime.invalidate(`Host closed while namespace \"${key}\" was active.`);\n }\n this.namespacedRuntimes.clear();\n this.pendingNamespacedKeys.clear();\n\n if (this.connection) {\n await this.connection.close().catch(() => {});\n }\n this.connection = null;\n this.connectionPromise = null;\n\n if (this.daemonProcess) {\n const process = this.daemonProcess;\n this.daemonProcess = null;\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n process.kill(\"SIGKILL\");\n resolve();\n }, 5000);\n process.once(\"exit\", () => {\n clearTimeout(timeout);\n resolve();\n });\n process.kill(\"SIGTERM\");\n });\n }\n }\n\n private async createRuntimeInternal(\n options: CreateRuntimeOptions,\n ): Promise<ScriptRuntime> {\n const diagnostics = createRuntimeDiagnostics();\n let runtimeId = options.key ?? \"runtime\";\n const browserSource = createBrowserSourceFromBindings(options.bindings.browser);\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n {\n nestedHost: this.createNestedBindings(browserSource),\n },\n );\n const runtime = await this.createRemoteRuntime(\n {\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n },\n options.key,\n );\n runtimeId = runtime.id;\n const adapter = createScriptRuntimeAdapter(runtime, diagnostics, {\n hasBrowser: Boolean(options.bindings.browser),\n onBeforeDispose: (reason) => bindingsAdapter.abort(reason),\n });\n this.runtimes.add(adapter);\n return adapter;\n }\n\n private async createTestRuntimeInternal(\n options: CreateTestRuntimeOptions,\n ): Promise<TestRuntime> {\n const testRuntime = await createTestRuntimeAdapter(\n async (runtimeOptions) => await this.createRemoteRuntime(runtimeOptions, options.key),\n options,\n {\n nestedHost: this.createNestedBindings(\n createBrowserSourceFromBindings(options.bindings.browser),\n ),\n },\n );\n this.runtimes.add(testRuntime);\n return testRuntime;\n }\n\n private async createNamespacedRuntimeInternal(\n key: string,\n options: CreateNamespacedRuntimeOptions,\n ): Promise<NamespacedRuntime> {\n if (this.pendingNamespacedKeys.has(key) || this.namespacedRuntimes.has(key)) {\n throw createNamedError(\n \"NamespaceInUseError\",\n `Namespace \"${key}\" already has a live runtime.`,\n );\n }\n\n this.pendingNamespacedKeys.add(key);\n const diagnostics = createRuntimeDiagnostics();\n let runtimeId = key;\n const browserSource = createBrowserSourceFromBindings(options.bindings.browser);\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n {\n nestedHost: this.createNestedBindings(browserSource),\n },\n );\n\n try {\n const runtime = await this.createRemoteRuntime(\n {\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n testEnvironment: true,\n },\n key,\n );\n runtimeId = runtime.id;\n\n let adapter: ReturnType<typeof createNamespacedRuntimeAdapter>;\n adapter = createNamespacedRuntimeAdapter(runtime, diagnostics, {\n hasBrowser: Boolean(options.bindings.browser),\n abortBindings: (reason) => bindingsAdapter.abort(reason),\n onRelease: () => {\n if (this.namespacedRuntimes.get(key) === adapter) {\n this.namespacedRuntimes.delete(key);\n }\n },\n });\n\n this.namespacedRuntimes.set(key, adapter);\n this.runtimes.add(adapter);\n return adapter;\n } catch (error) {\n throw normalizeNamespaceInUseError(error, key);\n } finally {\n this.pendingNamespacedKeys.delete(key);\n }\n }\n\n private async createAppServerInternal(\n options: CreateAppServerOptions,\n ): Promise<AppServer> {\n const server = await createAppServerAdapter(\n () => this.getConnection(),\n options,\n {\n nestedHost: this.createNestedBindings(\n createBrowserSourceFromBindings(options.bindings.browser),\n ),\n },\n );\n this.servers.add(server);\n return server;\n }\n\n private createNestedBindings(\n defaultBrowserSource: BrowserSource | undefined,\n ) {\n return createNestedHostBindings(\n {\n createRuntime: async (options) => await this.createRuntimeInternal(options),\n createAppServer: async (options) =>\n await this.createAppServerInternal(options),\n createTestRuntime: async (options) =>\n await this.createTestRuntimeInternal(options),\n getNamespacedRuntime: async (key, options) =>\n await this.createNamespacedRuntimeInternal(key, options),\n disposeNamespace: async (key, options) =>\n await this.disposeNamespace(key, options),\n isConnected: () => this.connection?.isConnected() ?? false,\n },\n defaultBrowserSource,\n );\n }\n\n private async createRemoteRuntime(options: RuntimeOptions, key?: string): Promise<RemoteRuntime> {\n const connection = await this.getConnection();\n if (key) {\n return await connection.createNamespace(key).createRuntime(options);\n }\n return await connection.createRuntime(options);\n }\n\n private async getConnection(): Promise<DaemonConnection> {\n if (this.connection?.isConnected()) {\n return this.connection;\n }\n if (this.connectionPromise) {\n return this.connectionPromise;\n }\n\n this.connectionPromise = (async () => {\n await this.ensureDaemon();\n this.connection = await connect({\n socket: this.options.daemon?.socketPath ?? \"/tmp/isolate.sock\",\n timeout: this.options.daemon?.timeoutMs ?? 5000,\n });\n return this.connection;\n })();\n\n return await this.connectionPromise.finally(() => {\n this.connectionPromise = null;\n });\n }\n\n private async ensureDaemon(): Promise<void> {\n if (this.connection?.isConnected()) {\n return;\n }\n\n if (this.options.daemon?.autoStart === false) {\n return;\n }\n\n if (this.daemonProcess) {\n return;\n }\n\n const socketPath = this.options.daemon?.socketPath ?? \"/tmp/isolate.sock\";\n const entrypoint = this.options.daemon?.entrypoint ?? resolveDefaultDaemonEntrypoint();\n\n try {\n if (fs.existsSync(socketPath)) {\n fs.unlinkSync(socketPath);\n }\n } catch {\n // ignore stale socket cleanup failures\n }\n\n const cli = entrypoint\n ? [\"node\", \"--experimental-strip-types\", entrypoint, \"--socket\", socketPath]\n : [\"isolate-daemon\", \"--socket\", socketPath];\n const cwd = this.options.daemon?.cwd ?? (entrypoint ? path.resolve(import.meta.dirname, \"../..\") : process.cwd());\n this.daemonProcess = spawn(cli[0]!, cli.slice(1), {\n cwd,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n env: {\n ...process.env,\n NODE_OPTIONS: \"\",\n },\n });\n\n this.daemonProcess.stdout?.on(\"data\", (data: Buffer) => {\n console.log(\"[isolate-host]\", data.toString().trim());\n });\n this.daemonProcess.stderr?.on(\"data\", (data: Buffer) => {\n console.error(\"[isolate-host]\", data.toString().trim());\n });\n this.daemonProcess.on(\"exit\", () => {\n this.daemonProcess = null;\n this.connection = null;\n this.connectionPromise = null;\n });\n\n await waitForSocket(socketPath, this.options.daemon?.timeoutMs ?? 10_000);\n }\n}\n\nexport async function createIsolateHost(options?: CreateIsolateHostOptions): Promise<IsolateHost> {\n return new HostImpl(options);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAe,IAAf;AACiB,IAAjB;AACyC,IAAzC;AACwF,IAAxF;AAIO,IAHP;AAIyC,IAAzC;AAC6C,IAA7C;AAC2C,IAA3C;AACyC,IAAzC;AACuC,IAAvC;AACyC,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AAU,IACzE,CAAC,kBAAkB,YAAY,UAAU;AAAA,IAC7C,MAAM,MAAM,KAAK,QAAQ,QAAQ,QAAQ,aAAa,yBAAK,QAAoB,8CAAS,OAAO,IAAI,QAAQ,IAAI;AAAA,IAC/G,KAAK,gBAAgB,gCAAM,IAAI,IAAK,IAAI,MAAM,CAAC,GAAG;AAAA,MAChD;AAAA,MACA,OAAO,CAAC,UAAU,QAAQ,MAAM;AAAA,MAChC,KAAK;AAAA,WACA,QAAQ;AAAA,QACX,cAAc;AAAA,MAChB;AAAA,IACF,CAAC;AAAA,IAED,KAAK,cAAc,QAAQ,GAAG,QAAQ,CAAC,SAAiB;AAAA,MACtD,QAAQ,IAAI,kBAAkB,KAAK,SAAS,EAAE,KAAK,CAAC;AAAA,KACrD;AAAA,IACD,KAAK,cAAc,QAAQ,GAAG,QAAQ,CAAC,SAAiB;AAAA,MACtD,QAAQ,MAAM,kBAAkB,KAAK,SAAS,EAAE,KAAK,CAAC;AAAA,KACvD;AAAA,IACD,KAAK,cAAc,GAAG,QAAQ,MAAM;AAAA,MAClC,KAAK,gBAAgB;AAAA,MACrB,KAAK,aAAa;AAAA,MAClB,KAAK,oBAAoB;AAAA,KAC1B;AAAA,IAED,MAAM,cAAc,YAAY,KAAK,QAAQ,QAAQ,aAAa,GAAM;AAAA;AAE5E;AAEA,eAAsB,iBAAiB,CAAC,SAA0D;AAAA,EAChG,OAAO,IAAI,SAAS,OAAO;AAAA;",
|
|
8
|
+
"debugId": "C33F7BE7F5125BD164756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -68,7 +68,7 @@ function normalizeBindings(bindings, defaultBrowserSource) {
|
|
|
68
68
|
}
|
|
69
69
|
const browserSource = import_browser_source.createBrowserSourceFromUnknown(bindings.browser);
|
|
70
70
|
if (!browserSource) {
|
|
71
|
-
throw new Error("Nested browser bindings must use the sandbox browser handle or expose createContext()/createPage().");
|
|
71
|
+
throw new Error("Nested browser bindings must use the sandbox browser handle, a Playwright handler, or expose createContext()/createPage().");
|
|
72
72
|
}
|
|
73
73
|
normalized.browser = browserSource;
|
|
74
74
|
return normalized;
|
|
@@ -85,6 +85,12 @@ function normalizeAppServerOptions(options, defaultBrowserSource) {
|
|
|
85
85
|
bindings: normalizeBindings(options.bindings, defaultBrowserSource)
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
+
function normalizeNamespacedRuntimeOptions(options, defaultBrowserSource) {
|
|
89
|
+
return {
|
|
90
|
+
...options,
|
|
91
|
+
bindings: normalizeBindings(options.bindings, defaultBrowserSource)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
88
94
|
function toError(value) {
|
|
89
95
|
if (value instanceof Error) {
|
|
90
96
|
return value;
|
|
@@ -128,7 +134,7 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
128
134
|
host.runtimeIds.delete(resourceId);
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
|
-
if (record.kind === "runtime") {
|
|
137
|
+
if (record.kind === "runtime" || record.kind === "namespacedRuntime") {
|
|
132
138
|
for (const unsubscribe of record.subscriptions.values()) {
|
|
133
139
|
unsubscribe();
|
|
134
140
|
}
|
|
@@ -220,6 +226,19 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
220
226
|
host.runtimeIds.add(resourceId);
|
|
221
227
|
return resourceId;
|
|
222
228
|
}
|
|
229
|
+
case "namespacedRuntime": {
|
|
230
|
+
const namespacedOptions = rawOptions;
|
|
231
|
+
const resource = await factory.getNamespacedRuntime(namespacedOptions.key, normalizeNamespacedRuntimeOptions(namespacedOptions.options, defaultBrowserSource));
|
|
232
|
+
const resourceId = import_node_crypto.randomUUID();
|
|
233
|
+
resources.set(resourceId, {
|
|
234
|
+
kind,
|
|
235
|
+
hostId,
|
|
236
|
+
resource,
|
|
237
|
+
subscriptions: new Map
|
|
238
|
+
});
|
|
239
|
+
host.runtimeIds.add(resourceId);
|
|
240
|
+
return resourceId;
|
|
241
|
+
}
|
|
223
242
|
}
|
|
224
243
|
},
|
|
225
244
|
async callResource(kind, resourceId, method, args) {
|
|
@@ -303,9 +322,48 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
303
322
|
throw new Error(`Unsupported nested test runtime method: ${method}`);
|
|
304
323
|
}
|
|
305
324
|
}
|
|
325
|
+
case "namespacedRuntime": {
|
|
326
|
+
const runtimeRecord = record;
|
|
327
|
+
switch (method) {
|
|
328
|
+
case "eval":
|
|
329
|
+
await runtimeRecord.resource.eval(args[0], args[1] ?? undefined);
|
|
330
|
+
return;
|
|
331
|
+
case "runTests":
|
|
332
|
+
return await runtimeRecord.resource.runTests(args[0], args[1] ?? undefined);
|
|
333
|
+
case "dispose":
|
|
334
|
+
await disposeResource(resourceId, args[0] ?? {});
|
|
335
|
+
return;
|
|
336
|
+
case "diagnostics":
|
|
337
|
+
return await runtimeRecord.resource.diagnostics();
|
|
338
|
+
case "events.on": {
|
|
339
|
+
const subscriptionId = import_node_crypto.randomUUID();
|
|
340
|
+
const unsubscribe = runtimeRecord.resource.events.on(args[0], args[1]);
|
|
341
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
342
|
+
return subscriptionId;
|
|
343
|
+
}
|
|
344
|
+
case "events.off": {
|
|
345
|
+
const subscriptionId = args[0];
|
|
346
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
347
|
+
if (unsubscribe) {
|
|
348
|
+
unsubscribe();
|
|
349
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
case "events.emit":
|
|
354
|
+
await runtimeRecord.resource.events.emit(args[0], args[1]);
|
|
355
|
+
return;
|
|
356
|
+
default:
|
|
357
|
+
throw new Error(`Unsupported nested namespaced runtime method: ${method}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
306
360
|
}
|
|
361
|
+
},
|
|
362
|
+
async disposeNamespace(hostId, key, options) {
|
|
363
|
+
requireHost(hostId);
|
|
364
|
+
await factory.disposeNamespace(key, options);
|
|
307
365
|
}
|
|
308
366
|
};
|
|
309
367
|
}
|
|
310
368
|
|
|
311
|
-
//# debugId=
|
|
369
|
+
//# debugId=1BF823129CE941AC64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/host/nested-host-controller.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { randomUUID } from \"node:crypto\";\nimport type { NestedHostBindings, NestedResourceKind } from \"../bridge/sandbox-isolate.cjs\";\nimport {\n createBrowserSourceFromUnknown,\n isDefaultBrowserDescriptor,\n requireBrowserSource,\n type BrowserSource,\n} from \"../internal/browser-source.cjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostBindings,\n HostCallContext,\n RequestResult,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.cjs\";\n\ninterface NestedHostFactory {\n createRuntime(options: CreateRuntimeOptions): Promise<ScriptRuntime>;\n createAppServer(options: CreateAppServerOptions): Promise<AppServer>;\n createTestRuntime(options: CreateTestRuntimeOptions): Promise<TestRuntime>;\n isConnected(): boolean;\n}\n\ninterface NestedHostRecord {\n runtimeIds: Set<string>;\n serverIds: Set<string>;\n closed: boolean;\n}\n\ninterface RuntimeResourceRecord {\n kind: \"runtime\";\n hostId: string;\n resource: ScriptRuntime;\n subscriptions: Map<string, () => void>;\n}\n\ninterface AppServerResourceRecord {\n kind: \"appServer\";\n hostId: string;\n resource: AppServer;\n}\n\ninterface TestRuntimeResourceRecord {\n kind: \"testRuntime\";\n hostId: string;\n resource: TestRuntime;\n}\n\ntype NestedResourceRecord =\n | RuntimeResourceRecord\n | AppServerResourceRecord\n | TestRuntimeResourceRecord;\n\ninterface SerializedRequestLike {\n url: string;\n method?: string;\n headers?: Array<[string, string]>;\n body?: number[] | null;\n}\n\nfunction toRequest(serialized: SerializedRequestLike): Request {\n return new Request(serialized.url, {\n method: serialized.method ?? \"GET\",\n headers: serialized.headers,\n body: serialized.body ? new Uint8Array(serialized.body) : null,\n });\n}\n\nfunction normalizeBindings(\n bindings: HostBindings | undefined,\n defaultBrowserSource: BrowserSource | undefined,\n): HostBindings {\n const normalized: HostBindings = {\n console: bindings?.console,\n fetch: bindings?.fetch,\n files: bindings?.files,\n modules: bindings?.modules,\n tools: bindings?.tools,\n };\n\n if (!bindings || !(\"browser\" in bindings) || bindings.browser === undefined) {\n return normalized;\n }\n\n if (isDefaultBrowserDescriptor(bindings.browser)) {\n normalized.browser = requireBrowserSource(\n defaultBrowserSource,\n \"Nested browser bindings\",\n );\n return normalized;\n }\n\n const browserSource = createBrowserSourceFromUnknown(bindings.browser);\n if (!browserSource) {\n throw new Error(\n \"Nested browser bindings must use the sandbox browser handle or expose createContext()/createPage().\",\n );\n }\n\n normalized.browser = browserSource;\n return normalized;\n}\n\nfunction normalizeRuntimeOptions(\n options: CreateRuntimeOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateRuntimeOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction normalizeAppServerOptions(\n options: CreateAppServerOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateAppServerOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction toError(value: unknown): Error {\n if (value instanceof Error) {\n return value;\n }\n\n if (\n value &&\n typeof value === \"object\" &&\n \"message\" in value &&\n typeof (value as { message?: unknown }).message === \"string\"\n ) {\n const error = new Error((value as { message: string }).message);\n if (\n \"name\" in value &&\n typeof (value as { name?: unknown }).name === \"string\"\n ) {\n error.name = (value as { name: string }).name;\n }\n return error;\n }\n\n return new Error(String(value));\n}\n\nexport function createNestedHostBindings(\n factory: NestedHostFactory,\n defaultBrowserSource: BrowserSource | undefined,\n): NestedHostBindings {\n const hosts = new Map<string, NestedHostRecord>();\n const resources = new Map<string, NestedResourceRecord>();\n\n const requireHost = (hostId: string): NestedHostRecord => {\n const host = hosts.get(hostId);\n if (!host || host.closed) {\n throw new Error(`Nested host ${hostId} is not available.`);\n }\n return host;\n };\n\n const requireResource = (\n resourceId: string,\n expectedKind: NestedResourceKind,\n ): NestedResourceRecord => {\n const resource = resources.get(resourceId);\n if (!resource || resource.kind !== expectedKind) {\n throw new Error(\n `Nested resource ${resourceId} is not available for ${expectedKind}.`,\n );\n }\n return resource;\n };\n\n const unregisterResource = (resourceId: string): void => {\n const record = resources.get(resourceId);\n if (!record) {\n return;\n }\n\n const host = hosts.get(record.hostId);\n if (host) {\n if (record.kind === \"appServer\") {\n host.serverIds.delete(resourceId);\n } else {\n host.runtimeIds.delete(resourceId);\n }\n }\n\n if (record.kind === \"runtime\") {\n for (const unsubscribe of record.subscriptions.values()) {\n unsubscribe();\n }\n record.subscriptions.clear();\n }\n\n resources.delete(resourceId);\n };\n\n const disposeResource = async (\n resourceId: string,\n options: { hard?: boolean; reason?: string },\n ): Promise<void> => {\n const record = resources.get(resourceId);\n if (!record) {\n return;\n }\n\n try {\n await record.resource.dispose(options);\n } finally {\n unregisterResource(resourceId);\n }\n };\n\n return {\n async createHost() {\n const hostId = randomUUID();\n hosts.set(hostId, {\n runtimeIds: new Set(),\n serverIds: new Set(),\n closed: false,\n });\n return hostId;\n },\n async closeHost(hostId) {\n const host = requireHost(hostId);\n host.closed = true;\n const resourceIds = [\n ...host.serverIds,\n ...host.runtimeIds,\n ];\n await Promise.allSettled(\n resourceIds.map(async (resourceId) => {\n await disposeResource(resourceId, {\n hard: true,\n reason: \"Nested isolate host closed\",\n });\n }),\n );\n hosts.delete(hostId);\n },\n async diagnostics(hostId) {\n const host = requireHost(hostId);\n return {\n runtimes: host.runtimeIds.size,\n servers: host.serverIds.size,\n connected: factory.isConnected(),\n };\n },\n async createResource(hostId, kind, rawOptions) {\n const host = requireHost(hostId);\n switch (kind) {\n case \"runtime\": {\n const options = normalizeRuntimeOptions(\n rawOptions as CreateRuntimeOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createRuntime(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n subscriptions: new Map(),\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n\n case \"appServer\": {\n const options = normalizeAppServerOptions(\n rawOptions as CreateAppServerOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createAppServer(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n });\n host.serverIds.add(resourceId);\n return resourceId;\n }\n\n case \"testRuntime\": {\n const options = normalizeRuntimeOptions(\n rawOptions as CreateTestRuntimeOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createTestRuntime(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n }\n },\n async callResource(kind, resourceId, method, args) {\n const record = requireResource(resourceId, kind);\n\n switch (kind) {\n case \"runtime\": {\n const runtimeRecord = record as RuntimeResourceRecord;\n switch (method) {\n case \"eval\":\n await runtimeRecord.resource.eval(\n args[0] as string,\n (args[1] as string | { filename?: string; executionTimeout?: number } | null) ??\n undefined,\n );\n return undefined;\n case \"dispose\":\n await disposeResource(resourceId, (args[0] as { hard?: boolean; reason?: string } | null) ?? {});\n return undefined;\n case \"diagnostics\":\n return await runtimeRecord.resource.diagnostics();\n case \"events.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtimeRecord.resource.events.on(\n args[0] as string,\n args[1] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"events.off\": {\n const subscriptionId = args[0] as string;\n const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);\n if (unsubscribe) {\n unsubscribe();\n runtimeRecord.subscriptions.delete(subscriptionId);\n }\n return undefined;\n }\n case \"events.emit\":\n await runtimeRecord.resource.events.emit(\n args[0] as string,\n args[1],\n );\n return undefined;\n default:\n throw new Error(`Unsupported nested runtime method: ${method}`);\n }\n }\n\n case \"appServer\": {\n const server = (record as AppServerResourceRecord).resource;\n switch (method) {\n case \"handle\": {\n const result = await server.handle(\n toRequest(args[0] as SerializedRequestLike),\n ((args[1] as {\n requestId?: string;\n metadata?: Record<string, string>;\n } | null) ?? undefined),\n );\n return result;\n }\n case \"ws.open\":\n await server.ws.open(args[0] as string);\n return undefined;\n case \"ws.message\":\n await server.ws.message(\n args[0] as string,\n args[1] as string | ArrayBuffer,\n );\n return undefined;\n case \"ws.close\":\n await server.ws.close(\n args[0] as string,\n args[1] as number,\n args[2] as string,\n );\n return undefined;\n case \"ws.error\":\n await server.ws.error(\n args[0] as string,\n toError(args[1]),\n );\n return undefined;\n case \"reload\":\n await server.reload((args[0] as string | null) ?? undefined);\n return undefined;\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await server.diagnostics();\n default:\n throw new Error(`Unsupported nested app server method: ${method}`);\n }\n }\n\n case \"testRuntime\": {\n const runtime = (record as TestRuntimeResourceRecord).resource;\n switch (method) {\n case \"run\":\n return await runtime.run(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n timeoutMs?: number;\n } | null) ?? undefined),\n );\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await runtime.diagnostics();\n default:\n throw new Error(\n `Unsupported nested test runtime method: ${method}`,\n );\n }\n }\n }\n },\n };\n}\n"
|
|
5
|
+
"import { randomUUID } from \"node:crypto\";\nimport type { NestedHostBindings, NestedResourceKind } from \"../bridge/sandbox-isolate.cjs\";\nimport {\n createBrowserSourceFromUnknown,\n isDefaultBrowserDescriptor,\n requireBrowserSource,\n type BrowserSource,\n} from \"../internal/browser-source.cjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostBindings,\n HostCallContext,\n NamespacedRuntime,\n RequestResult,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.cjs\";\n\ninterface NestedHostFactory {\n createRuntime(options: CreateRuntimeOptions): Promise<ScriptRuntime>;\n createAppServer(options: CreateAppServerOptions): Promise<AppServer>;\n createTestRuntime(options: CreateTestRuntimeOptions): Promise<TestRuntime>;\n getNamespacedRuntime(\n key: string,\n options: CreateNamespacedRuntimeOptions,\n ): Promise<NamespacedRuntime>;\n disposeNamespace(key: string, options?: { reason?: string }): Promise<void>;\n isConnected(): boolean;\n}\n\ninterface NestedHostRecord {\n runtimeIds: Set<string>;\n serverIds: Set<string>;\n closed: boolean;\n}\n\ninterface RuntimeResourceRecord {\n kind: \"runtime\";\n hostId: string;\n resource: ScriptRuntime;\n subscriptions: Map<string, () => void>;\n}\n\ninterface AppServerResourceRecord {\n kind: \"appServer\";\n hostId: string;\n resource: AppServer;\n}\n\ninterface TestRuntimeResourceRecord {\n kind: \"testRuntime\";\n hostId: string;\n resource: TestRuntime;\n}\n\ninterface NamespacedRuntimeResourceRecord {\n kind: \"namespacedRuntime\";\n hostId: string;\n resource: NamespacedRuntime;\n subscriptions: Map<string, () => void>;\n}\n\ntype NestedResourceRecord =\n | RuntimeResourceRecord\n | AppServerResourceRecord\n | TestRuntimeResourceRecord\n | NamespacedRuntimeResourceRecord;\n\ninterface SerializedRequestLike {\n url: string;\n method?: string;\n headers?: Array<[string, string]>;\n body?: number[] | null;\n}\n\nfunction toRequest(serialized: SerializedRequestLike): Request {\n return new Request(serialized.url, {\n method: serialized.method ?? \"GET\",\n headers: serialized.headers,\n body: serialized.body ? new Uint8Array(serialized.body) : null,\n });\n}\n\nfunction normalizeBindings(\n bindings: HostBindings | undefined,\n defaultBrowserSource: BrowserSource | undefined,\n): HostBindings {\n const normalized: HostBindings = {\n console: bindings?.console,\n fetch: bindings?.fetch,\n files: bindings?.files,\n modules: bindings?.modules,\n tools: bindings?.tools,\n };\n\n if (!bindings || !(\"browser\" in bindings) || bindings.browser === undefined) {\n return normalized;\n }\n\n if (isDefaultBrowserDescriptor(bindings.browser)) {\n normalized.browser = requireBrowserSource(\n defaultBrowserSource,\n \"Nested browser bindings\",\n );\n return normalized;\n }\n\n const browserSource = createBrowserSourceFromUnknown(bindings.browser);\n if (!browserSource) {\n throw new Error(\n \"Nested browser bindings must use the sandbox browser handle, a Playwright handler, or expose createContext()/createPage().\",\n );\n }\n\n normalized.browser = browserSource;\n return normalized;\n}\n\nfunction normalizeRuntimeOptions(\n options: CreateRuntimeOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateRuntimeOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction normalizeAppServerOptions(\n options: CreateAppServerOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateAppServerOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction normalizeNamespacedRuntimeOptions(\n options: CreateNamespacedRuntimeOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateNamespacedRuntimeOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction toError(value: unknown): Error {\n if (value instanceof Error) {\n return value;\n }\n\n if (\n value &&\n typeof value === \"object\" &&\n \"message\" in value &&\n typeof (value as { message?: unknown }).message === \"string\"\n ) {\n const error = new Error((value as { message: string }).message);\n if (\n \"name\" in value &&\n typeof (value as { name?: unknown }).name === \"string\"\n ) {\n error.name = (value as { name: string }).name;\n }\n return error;\n }\n\n return new Error(String(value));\n}\n\nexport function createNestedHostBindings(\n factory: NestedHostFactory,\n defaultBrowserSource: BrowserSource | undefined,\n): NestedHostBindings {\n const hosts = new Map<string, NestedHostRecord>();\n const resources = new Map<string, NestedResourceRecord>();\n\n const requireHost = (hostId: string): NestedHostRecord => {\n const host = hosts.get(hostId);\n if (!host || host.closed) {\n throw new Error(`Nested host ${hostId} is not available.`);\n }\n return host;\n };\n\n const requireResource = (\n resourceId: string,\n expectedKind: NestedResourceKind,\n ): NestedResourceRecord => {\n const resource = resources.get(resourceId);\n if (!resource || resource.kind !== expectedKind) {\n throw new Error(\n `Nested resource ${resourceId} is not available for ${expectedKind}.`,\n );\n }\n return resource;\n };\n\n const unregisterResource = (resourceId: string): void => {\n const record = resources.get(resourceId);\n if (!record) {\n return;\n }\n\n const host = hosts.get(record.hostId);\n if (host) {\n if (record.kind === \"appServer\") {\n host.serverIds.delete(resourceId);\n } else {\n host.runtimeIds.delete(resourceId);\n }\n }\n\n if (record.kind === \"runtime\" || record.kind === \"namespacedRuntime\") {\n for (const unsubscribe of record.subscriptions.values()) {\n unsubscribe();\n }\n record.subscriptions.clear();\n }\n\n resources.delete(resourceId);\n };\n\n const disposeResource = async (\n resourceId: string,\n options: { hard?: boolean; reason?: string },\n ): Promise<void> => {\n const record = resources.get(resourceId);\n if (!record) {\n return;\n }\n\n try {\n await record.resource.dispose(options);\n } finally {\n unregisterResource(resourceId);\n }\n };\n\n return {\n async createHost() {\n const hostId = randomUUID();\n hosts.set(hostId, {\n runtimeIds: new Set(),\n serverIds: new Set(),\n closed: false,\n });\n return hostId;\n },\n async closeHost(hostId) {\n const host = requireHost(hostId);\n host.closed = true;\n const resourceIds = [\n ...host.serverIds,\n ...host.runtimeIds,\n ];\n await Promise.allSettled(\n resourceIds.map(async (resourceId) => {\n await disposeResource(resourceId, {\n hard: true,\n reason: \"Nested isolate host closed\",\n });\n }),\n );\n hosts.delete(hostId);\n },\n async diagnostics(hostId) {\n const host = requireHost(hostId);\n return {\n runtimes: host.runtimeIds.size,\n servers: host.serverIds.size,\n connected: factory.isConnected(),\n };\n },\n async createResource(hostId, kind, rawOptions) {\n const host = requireHost(hostId);\n switch (kind) {\n case \"runtime\": {\n const options = normalizeRuntimeOptions(\n rawOptions as CreateRuntimeOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createRuntime(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n subscriptions: new Map(),\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n\n case \"appServer\": {\n const options = normalizeAppServerOptions(\n rawOptions as CreateAppServerOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createAppServer(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n });\n host.serverIds.add(resourceId);\n return resourceId;\n }\n\n case \"testRuntime\": {\n const options = normalizeRuntimeOptions(\n rawOptions as CreateTestRuntimeOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createTestRuntime(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n\n case \"namespacedRuntime\": {\n const namespacedOptions = rawOptions as {\n key: string;\n options: CreateNamespacedRuntimeOptions;\n };\n const resource = await factory.getNamespacedRuntime(\n namespacedOptions.key,\n normalizeNamespacedRuntimeOptions(\n namespacedOptions.options,\n defaultBrowserSource,\n ),\n );\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n subscriptions: new Map(),\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n }\n },\n async callResource(kind, resourceId, method, args) {\n const record = requireResource(resourceId, kind);\n\n switch (kind) {\n case \"runtime\": {\n const runtimeRecord = record as RuntimeResourceRecord;\n switch (method) {\n case \"eval\":\n await runtimeRecord.resource.eval(\n args[0] as string,\n (args[1] as string | { filename?: string; executionTimeout?: number } | null) ??\n undefined,\n );\n return undefined;\n case \"dispose\":\n await disposeResource(resourceId, (args[0] as { hard?: boolean; reason?: string } | null) ?? {});\n return undefined;\n case \"diagnostics\":\n return await runtimeRecord.resource.diagnostics();\n case \"events.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtimeRecord.resource.events.on(\n args[0] as string,\n args[1] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"events.off\": {\n const subscriptionId = args[0] as string;\n const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);\n if (unsubscribe) {\n unsubscribe();\n runtimeRecord.subscriptions.delete(subscriptionId);\n }\n return undefined;\n }\n case \"events.emit\":\n await runtimeRecord.resource.events.emit(\n args[0] as string,\n args[1],\n );\n return undefined;\n default:\n throw new Error(`Unsupported nested runtime method: ${method}`);\n }\n }\n\n case \"appServer\": {\n const server = (record as AppServerResourceRecord).resource;\n switch (method) {\n case \"handle\": {\n const result = await server.handle(\n toRequest(args[0] as SerializedRequestLike),\n ((args[1] as {\n requestId?: string;\n metadata?: Record<string, string>;\n } | null) ?? undefined),\n );\n return result;\n }\n case \"ws.open\":\n await server.ws.open(args[0] as string);\n return undefined;\n case \"ws.message\":\n await server.ws.message(\n args[0] as string,\n args[1] as string | ArrayBuffer,\n );\n return undefined;\n case \"ws.close\":\n await server.ws.close(\n args[0] as string,\n args[1] as number,\n args[2] as string,\n );\n return undefined;\n case \"ws.error\":\n await server.ws.error(\n args[0] as string,\n toError(args[1]),\n );\n return undefined;\n case \"reload\":\n await server.reload((args[0] as string | null) ?? undefined);\n return undefined;\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await server.diagnostics();\n default:\n throw new Error(`Unsupported nested app server method: ${method}`);\n }\n }\n\n case \"testRuntime\": {\n const runtime = (record as TestRuntimeResourceRecord).resource;\n switch (method) {\n case \"run\":\n return await runtime.run(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n timeoutMs?: number;\n } | null) ?? undefined),\n );\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await runtime.diagnostics();\n default:\n throw new Error(\n `Unsupported nested test runtime method: ${method}`,\n );\n }\n }\n\n case \"namespacedRuntime\": {\n const runtimeRecord = record as NamespacedRuntimeResourceRecord;\n switch (method) {\n case \"eval\":\n await runtimeRecord.resource.eval(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n executionTimeout?: number;\n } | null) ?? undefined),\n );\n return undefined;\n case \"runTests\":\n return await runtimeRecord.resource.runTests(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n timeoutMs?: number;\n } | null) ?? undefined),\n );\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await runtimeRecord.resource.diagnostics();\n case \"events.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtimeRecord.resource.events.on(\n args[0] as string,\n args[1] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"events.off\": {\n const subscriptionId = args[0] as string;\n const unsubscribe =\n runtimeRecord.subscriptions.get(subscriptionId);\n if (unsubscribe) {\n unsubscribe();\n runtimeRecord.subscriptions.delete(subscriptionId);\n }\n return undefined;\n }\n case \"events.emit\":\n await runtimeRecord.resource.events.emit(\n args[0] as string,\n args[1],\n );\n return undefined;\n default:\n throw new Error(\n `Unsupported nested namespaced runtime method: ${method}`,\n );\n }\n }\n }\n },\n async disposeNamespace(hostId, key, options) {\n requireHost(hostId);\n await factory.disposeNamespace(key, options);\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA2B,IAA3B;AAOO,IALP;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA2B,IAA3B;AAOO,IALP;AA6EA,SAAS,SAAS,CAAC,YAA4C;AAAA,EAC7D,OAAO,IAAI,QAAQ,WAAW,KAAK;AAAA,IACj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AA,cACH,OAAO,MAAM,cAAc,SAAS,YAAY;AAAA,iBAC7C,aAAa;AAAA,cAChB,MAAM,iBAAiB,8BAAW;AAAA,cAClC,MAAM,cAAc,cAAc,SAAS,OAAO,GAChD,KAAK,IACL,KAAK,EACP;AAAA,cACA,cAAc,cAAc,IAAI,gBAAgB,WAAW;AAAA,cAC3D,OAAO;AAAA,YACT;AAAA,iBACK,cAAc;AAAA,cACjB,MAAM,iBAAiB,KAAK;AAAA,cAC5B,MAAM,cACJ,cAAc,cAAc,IAAI,cAAc;AAAA,cAChD,IAAI,aAAa;AAAA,gBACf,YAAY;AAAA,gBACZ,cAAc,cAAc,OAAO,cAAc;AAAA,cACnD;AAAA,cACA;AAAA,YACF;AAAA,iBACK;AAAA,cACH,MAAM,cAAc,SAAS,OAAO,KAClC,KAAK,IACL,KAAK,EACP;AAAA,cACA;AAAA;AAAA,cAEA,MAAM,IAAI,MACR,iDAAiD,QACnD;AAAA;AAAA,QAEN;AAAA;AAAA;AAAA,SAGE,iBAAgB,CAAC,QAAQ,KAAK,SAAS;AAAA,MAC3C,YAAY,MAAM;AAAA,MAClB,MAAM,QAAQ,iBAAiB,KAAK,OAAO;AAAA;AAAA,EAE/C;AAAA;",
|
|
8
|
+
"debugId": "1BF823129CE941AC64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export { createIsolateHost } from \"./host/index.cjs\";\nexport { createModuleResolver } from \"./modules/index.cjs\";\nexport { createFileBindings } from \"./files/index.cjs\";\nexport { getTypeProfile, typecheck, formatTypecheckErrors } from \"./typecheck/index.cjs\";\n\nexport type {\n AppServer,\n BrowserDiagnostics,\n ConsoleEntry,\n CreateAppServerOptions,\n CreateIsolateHostOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n FileBindings,\n HostBindings,\n HostBrowserBindings,\n HostCallContext,\n IsolateHost,\n ModuleImporter,\n ModuleResolveResult,\n ModuleResolver,\n ModuleResolverFallback,\n ModuleResolverSourceLoader,\n ModuleSource,\n PlaywrightEvent,\n RequestResult,\n RuntimeResourceDiagnostics,\n RunResults,\n ScriptRuntime,\n TestDiagnostics,\n TestEvent,\n TestRuntime,\n TestRuntimeDiagnostics,\n ToolBindings,\n ToolHandler,\n RuntimeDiagnostics,\n TypeCapability,\n TypeProfile,\n TypeProfileName,\n TypecheckRequest,\n WebSocketUpgradeData,\n} from \"./types.cjs\";\n"
|
|
5
|
+
"export { createIsolateHost } from \"./host/index.cjs\";\nexport { createModuleResolver } from \"./modules/index.cjs\";\nexport { createFileBindings } from \"./files/index.cjs\";\nexport { getTypeProfile, typecheck, formatTypecheckErrors } from \"./typecheck/index.cjs\";\n\nexport type {\n AppServer,\n BrowserDiagnostics,\n ConsoleEntry,\n CreateAppServerOptions,\n CreateIsolateHostOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n FileBindings,\n HostBindings,\n HostBrowserBindings,\n HostBrowserFactoryBindings,\n HostBrowserHandlerBindings,\n HostCallContext,\n IsolateHost,\n ModuleImporter,\n ModuleResolveResult,\n ModuleResolver,\n NamespacedRuntime,\n ModuleResolverFallback,\n ModuleResolverSourceLoader,\n ModuleSource,\n PlaywrightEvent,\n RequestResult,\n RuntimeResourceDiagnostics,\n RunResults,\n ScriptRuntime,\n TestDiagnostics,\n TestEvent,\n TestRuntime,\n TestRuntimeDiagnostics,\n ToolBindings,\n ToolHandler,\n RuntimeDiagnostics,\n TypeCapability,\n TypeProfile,\n TypeProfileName,\n TypecheckRequest,\n WebSocketUpgradeData,\n} from \"./types.cjs\";\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAkC,IAAlC;AACqC,IAArC;AACmC,IAAnC;AACiE,IAAjE;",
|
|
8
8
|
"debugId": "DBA32E0AAF50F3A864756E2164756E21",
|
|
@@ -56,7 +56,7 @@ function isBrowserBindingLike(value) {
|
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
const candidate = value;
|
|
59
|
-
return typeof candidate.createContext === "function" || typeof candidate.createPage === "function";
|
|
59
|
+
return typeof candidate.handler === "function" || typeof candidate.createContext === "function" || typeof candidate.createPage === "function";
|
|
60
60
|
}
|
|
61
61
|
function isDefaultBrowserDescriptor(value) {
|
|
62
62
|
return Boolean(value && typeof value === "object" && value[ISOLATE_BROWSER_DESCRIPTOR_PROPERTY] === ISOLATE_BROWSER_DESCRIPTOR_VALUE);
|
|
@@ -65,9 +65,20 @@ function createBrowserSourceFromBindings(browser) {
|
|
|
65
65
|
if (!browser) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
+
if ("handler" in browser && typeof browser.handler === "function") {
|
|
69
|
+
return {
|
|
70
|
+
handler: browser.handler,
|
|
71
|
+
captureConsole: browser.captureConsole,
|
|
72
|
+
onEvent: browser.onEvent
|
|
73
|
+
};
|
|
74
|
+
}
|
|
68
75
|
return {
|
|
69
76
|
createContext: browser.createContext,
|
|
70
|
-
createPage: browser.createPage
|
|
77
|
+
createPage: browser.createPage,
|
|
78
|
+
captureConsole: browser.captureConsole,
|
|
79
|
+
onEvent: browser.onEvent,
|
|
80
|
+
readFile: browser.readFile,
|
|
81
|
+
writeFile: browser.writeFile
|
|
71
82
|
};
|
|
72
83
|
}
|
|
73
84
|
function createBrowserSourceFromUnknown(browser) {
|
|
@@ -77,8 +88,8 @@ function createBrowserSourceFromUnknown(browser) {
|
|
|
77
88
|
return createBrowserSourceFromBindings(browser);
|
|
78
89
|
}
|
|
79
90
|
function requireBrowserSource(source, operation) {
|
|
80
|
-
if (!source
|
|
81
|
-
throw new Error(`${operation} requires a browser binding
|
|
91
|
+
if (!source) {
|
|
92
|
+
throw new Error(`${operation} requires a browser binding.`);
|
|
82
93
|
}
|
|
83
94
|
return source;
|
|
84
95
|
}
|
|
@@ -88,4 +99,4 @@ function cloneBrowserDescriptor() {
|
|
|
88
99
|
};
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
//# debugId=
|
|
102
|
+
//# debugId=2B1987CA1D9F43BF64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/browser-source.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type {\n HostBrowserBindings,\n} from \"../types.cjs\";\n\nexport const ISOLATE_BROWSER_DESCRIPTOR_PROPERTY = \"__isolateBrowserBinding\";\nexport const ISOLATE_BROWSER_DESCRIPTOR_VALUE = \"default\";\n\nexport
|
|
5
|
+
"import type {\n HostBrowserBindings,\n} from \"../types.cjs\";\n\nexport const ISOLATE_BROWSER_DESCRIPTOR_PROPERTY = \"__isolateBrowserBinding\";\nexport const ISOLATE_BROWSER_DESCRIPTOR_VALUE = \"default\";\n\nexport type BrowserSource = HostBrowserBindings;\n\nexport function isBrowserBindingLike(value: unknown): value is HostBrowserBindings {\n if (!value || typeof value !== \"object\") {\n return false;\n }\n\n const candidate = value as Record<string, unknown>;\n return (\n typeof candidate.handler === \"function\" ||\n typeof candidate.createContext === \"function\" ||\n typeof candidate.createPage === \"function\"\n );\n}\n\nexport function isDefaultBrowserDescriptor(value: unknown): boolean {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n (value as Record<string, unknown>)[ISOLATE_BROWSER_DESCRIPTOR_PROPERTY] ===\n ISOLATE_BROWSER_DESCRIPTOR_VALUE,\n );\n}\n\nexport function createBrowserSourceFromBindings(\n browser: HostBrowserBindings | undefined,\n): BrowserSource | undefined {\n if (!browser) {\n return undefined;\n }\n\n if (\"handler\" in browser && typeof browser.handler === \"function\") {\n return {\n handler: browser.handler,\n captureConsole: browser.captureConsole,\n onEvent: browser.onEvent,\n };\n }\n\n return {\n createContext: browser.createContext,\n createPage: browser.createPage,\n captureConsole: browser.captureConsole,\n onEvent: browser.onEvent,\n readFile: browser.readFile,\n writeFile: browser.writeFile,\n };\n}\n\nexport function createBrowserSourceFromUnknown(\n browser: unknown,\n): BrowserSource | undefined {\n if (!isBrowserBindingLike(browser)) {\n return undefined;\n }\n\n return createBrowserSourceFromBindings(browser);\n}\n\nexport function requireBrowserSource(\n source: BrowserSource | undefined,\n operation: string,\n): BrowserSource {\n if (!source) {\n throw new Error(\n `${operation} requires a browser binding.`,\n );\n }\n return source;\n}\n\nexport function cloneBrowserDescriptor(): Record<string, string> {\n return {\n [ISOLATE_BROWSER_DESCRIPTOR_PROPERTY]: ISOLATE_BROWSER_DESCRIPTOR_VALUE,\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,sCAAsC;AAC5C,IAAM,mCAAmC;AAIzC,SAAS,oBAAoB,CAAC,OAA8C;AAAA,EACjF,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU;AAAA,IACvC,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,YAAY;AAAA,EAClB,OACE,OAAO,UAAU,kBAAkB,cACnC,OAAO,UAAU,eAAe;AAAA;AAI7B,SAAS,0BAA0B,CAAC,OAAyB;AAAA,EAClE,OAAO,QACL,SACE,OAAO,UAAU,YAChB,MAAkC,yCACjC,gCACN;AAAA;AAGK,SAAS,+BAA+B,CAC7C,SAC2B;AAAA,EAC3B,IAAI,CAAC,SAAS;AAAA,IACZ;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,eAAe,QAAQ;AAAA,IACvB,YAAY,QAAQ;AAAA,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,sCAAsC;AAC5C,IAAM,mCAAmC;AAIzC,SAA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@ -255,6 +255,17 @@ async function connect(options = {}) {
|
|
|
255
255
|
id,
|
|
256
256
|
createRuntime: (runtimeOptions) => createRuntime(state, runtimeOptions, id)
|
|
257
257
|
}),
|
|
258
|
+
disposeNamespace: async (id, options2) => {
|
|
259
|
+
state.namespacedRuntimes.delete(id);
|
|
260
|
+
const requestId = state.nextRequestId++;
|
|
261
|
+
const request = {
|
|
262
|
+
type: import_protocol.MessageType.DISPOSE_NAMESPACE,
|
|
263
|
+
requestId,
|
|
264
|
+
namespaceId: id,
|
|
265
|
+
reason: typeof options2?.reason === "string" && options2.reason.length > 0 ? options2.reason : undefined
|
|
266
|
+
};
|
|
267
|
+
await sendRequest(state, request);
|
|
268
|
+
},
|
|
258
269
|
close: async () => {
|
|
259
270
|
state.closing = true;
|
|
260
271
|
state.connected = false;
|
|
@@ -1948,4 +1959,4 @@ function handleClientWsClose(isolateId, payload, state) {
|
|
|
1948
1959
|
}
|
|
1949
1960
|
}
|
|
1950
1961
|
|
|
1951
|
-
//# debugId=
|
|
1962
|
+
//# debugId=6DFCE44C7F91C20864756E2164756E21
|