@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
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/bridge/sandbox-isolate.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { ISOLATE_BROWSER_DESCRIPTOR_PROPERTY } from \"../internal/browser-source.mjs\";\nimport type {\n CreateAppServerOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.mjs\";\n\nexport const SANDBOX_ISOLATE_MODULE_SPECIFIER = \"@ricsam/isolate\";\n\nexport type NestedResourceKind = \"runtime\" | \"appServer\" | \"testRuntime\";\n\nexport interface NestedHostBindings {\n createHost(context: HostCallContext): Promise<string>;\n closeHost(hostId: string, context: HostCallContext): Promise<void>;\n diagnostics(\n hostId: string,\n context: HostCallContext,\n ): Promise<{ runtimes: number; servers: number; connected: boolean }>;\n createResource(\n hostId: string,\n kind: NestedResourceKind,\n options:\n | CreateRuntimeOptions\n | CreateAppServerOptions\n | CreateTestRuntimeOptions,\n context: HostCallContext,\n ): Promise<string>;\n callResource(\n kind: NestedResourceKind,\n resourceId: string,\n method: string,\n args: unknown[],\n context: HostCallContext,\n ): Promise<unknown>;\n}\n\nexport const SANDBOX_ISOLATE_MODULE_SOURCE = `\nconst __isolateBrowserDescriptorProperty = ${JSON.stringify(ISOLATE_BROWSER_DESCRIPTOR_PROPERTY)};\n\nfunction __normalizeBrowserHandle(value) {\n if (\n value &&\n typeof value === \"object\" &&\n value[__isolateBrowserDescriptorProperty]\n ) {\n return {\n [__isolateBrowserDescriptorProperty]: value[__isolateBrowserDescriptorProperty],\n };\n }\n return value;\n}\n\nfunction __normalizeBindings(bindings) {\n if (!bindings || typeof bindings !== \"object\") {\n return {};\n }\n\n const normalized = { ...bindings };\n if (\"browser\" in normalized) {\n normalized.browser = __normalizeBrowserHandle(normalized.browser);\n }\n return normalized;\n}\n\nfunction __normalizeRuntimeOptions(options) {\n const normalized = options ? { ...options } : {};\n normalized.bindings = __normalizeBindings(normalized.bindings);\n return normalized;\n}\n\nasync function __serializeRequest(requestLike) {\n const request = requestLike instanceof Request\n ? requestLike\n : new Request(requestLike);\n const headers = [];\n request.headers.forEach((value, key) => {\n headers.push([key, value]);\n });\n let body = null;\n if (request.body) {\n const cloned = request.clone();\n body = Array.from(new Uint8Array(await cloned.arrayBuffer()));\n }\n return {\n url: request.url,\n method: request.method,\n headers,\n body,\n };\n}\n\nfunction __normalizeEvalOptions(options) {\n if (typeof options === \"string\") {\n return { filename: options };\n }\n return options ?? null;\n}\n\nasync function __waitForNestedCallbacks() {\n await new Promise((resolve) => setTimeout(resolve, 0));\n}\n\nclass NestedScriptRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nclass NestedAppServer {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async handle(request, options) {\n const serializedRequest = await __serializeRequest(request);\n const result = await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"handle\",\n [\n serializedRequest,\n options\n ? {\n requestId: options.requestId,\n metadata: options.metadata,\n }\n : null,\n ],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n ws = {\n open: async (connectionId) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.open\",\n [connectionId],\n );\n await __waitForNestedCallbacks();\n },\n message: async (connectionId, data) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.message\",\n [connectionId, data],\n );\n await __waitForNestedCallbacks();\n },\n close: async (connectionId, code, reason) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.close\",\n [connectionId, code, reason],\n );\n await __waitForNestedCallbacks();\n },\n error: async (connectionId, error) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.error\",\n [connectionId, error],\n );\n await __waitForNestedCallbacks();\n },\n };\n\n async reload(reason) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"reload\",\n [reason ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n}\n\nclass NestedTestRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async run(code, options) {\n const result = await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"run\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n}\n\nexport function createIsolateHost() {\n let hostIdPromise;\n\n const ensureHostId = async () => {\n if (!hostIdPromise) {\n hostIdPromise = __isolateHost_createHost();\n }\n return await hostIdPromise;\n };\n\n return {\n async createRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"runtime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedScriptRuntime(resourceId);\n },\n async createAppServer(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"appServer\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedAppServer(resourceId);\n },\n async createTestRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"testRuntime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedTestRuntime(resourceId);\n },\n async diagnostics() {\n return await __isolateHost_hostDiagnostics(await ensureHostId());\n },\n async close() {\n const hostId = await ensureHostId();\n await __isolateHost_closeHost(hostId);\n await __waitForNestedCallbacks();\n },\n };\n}\n`;\n"
|
|
5
|
+
"import { ISOLATE_BROWSER_DESCRIPTOR_PROPERTY } from \"../internal/browser-source.mjs\";\nimport type {\n CreateAppServerOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.mjs\";\n\nexport const SANDBOX_ISOLATE_MODULE_SPECIFIER = \"@ricsam/isolate\";\n\nexport type NestedResourceKind =\n | \"runtime\"\n | \"appServer\"\n | \"testRuntime\"\n | \"namespacedRuntime\";\n\nexport interface NestedHostBindings {\n createHost(context: HostCallContext): Promise<string>;\n closeHost(hostId: string, context: HostCallContext): Promise<void>;\n diagnostics(\n hostId: string,\n context: HostCallContext,\n ): Promise<{ runtimes: number; servers: number; connected: boolean }>;\n createResource(\n hostId: string,\n kind: NestedResourceKind,\n options:\n | CreateRuntimeOptions\n | CreateAppServerOptions\n | CreateTestRuntimeOptions\n | {\n key: string;\n options: CreateNamespacedRuntimeOptions;\n },\n context: HostCallContext,\n ): Promise<string>;\n disposeNamespace(\n hostId: string,\n key: string,\n options: { reason?: string } | undefined,\n context: HostCallContext,\n ): Promise<void>;\n callResource(\n kind: NestedResourceKind,\n resourceId: string,\n method: string,\n args: unknown[],\n context: HostCallContext,\n ): Promise<unknown>;\n}\n\nexport const SANDBOX_ISOLATE_MODULE_SOURCE = `\nconst __isolateBrowserDescriptorProperty = ${JSON.stringify(ISOLATE_BROWSER_DESCRIPTOR_PROPERTY)};\n\nfunction __normalizeBrowserHandle(value) {\n if (\n value &&\n typeof value === \"object\" &&\n value[__isolateBrowserDescriptorProperty]\n ) {\n return {\n [__isolateBrowserDescriptorProperty]: value[__isolateBrowserDescriptorProperty],\n };\n }\n return value;\n}\n\nfunction __normalizeBindings(bindings) {\n if (!bindings || typeof bindings !== \"object\") {\n return {};\n }\n\n const normalized = { ...bindings };\n if (\"browser\" in normalized) {\n normalized.browser = __normalizeBrowserHandle(normalized.browser);\n }\n return normalized;\n}\n\nfunction __normalizeRuntimeOptions(options) {\n const normalized = options ? { ...options } : {};\n normalized.bindings = __normalizeBindings(normalized.bindings);\n return normalized;\n}\n\nfunction __normalizeNamespacedRuntimeOptions(key, options) {\n return {\n key,\n options: __normalizeRuntimeOptions(options),\n };\n}\n\nasync function __serializeRequest(requestLike) {\n const request = requestLike instanceof Request\n ? requestLike\n : new Request(requestLike);\n const headers = [];\n request.headers.forEach((value, key) => {\n headers.push([key, value]);\n });\n let body = null;\n if (request.body) {\n const cloned = request.clone();\n body = Array.from(new Uint8Array(await cloned.arrayBuffer()));\n }\n return {\n url: request.url,\n method: request.method,\n headers,\n body,\n };\n}\n\nfunction __normalizeEvalOptions(options) {\n if (typeof options === \"string\") {\n return { filename: options };\n }\n return options ?? null;\n}\n\nasync function __waitForNestedCallbacks() {\n await new Promise((resolve) => setTimeout(resolve, 0));\n}\n\nclass NestedScriptRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nclass NestedAppServer {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async handle(request, options) {\n const serializedRequest = await __serializeRequest(request);\n const result = await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"handle\",\n [\n serializedRequest,\n options\n ? {\n requestId: options.requestId,\n metadata: options.metadata,\n }\n : null,\n ],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n ws = {\n open: async (connectionId) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.open\",\n [connectionId],\n );\n await __waitForNestedCallbacks();\n },\n message: async (connectionId, data) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.message\",\n [connectionId, data],\n );\n await __waitForNestedCallbacks();\n },\n close: async (connectionId, code, reason) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.close\",\n [connectionId, code, reason],\n );\n await __waitForNestedCallbacks();\n },\n error: async (connectionId, error) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.error\",\n [connectionId, error],\n );\n await __waitForNestedCallbacks();\n },\n };\n\n async reload(reason) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"reload\",\n [reason ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n}\n\nclass NestedTestRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async run(code, options) {\n const result = await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"run\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n}\n\nclass NestedNamespacedRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async runTests(code, options) {\n const result = await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"runTests\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nexport function createIsolateHost() {\n let hostIdPromise;\n\n const ensureHostId = async () => {\n if (!hostIdPromise) {\n hostIdPromise = __isolateHost_createHost();\n }\n return await hostIdPromise;\n };\n\n return {\n async createRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"runtime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedScriptRuntime(resourceId);\n },\n async createAppServer(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"appServer\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedAppServer(resourceId);\n },\n async createTestRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"testRuntime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedTestRuntime(resourceId);\n },\n async getNamespacedRuntime(key, options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"namespacedRuntime\",\n __normalizeNamespacedRuntimeOptions(key, options),\n );\n return new NestedNamespacedRuntime(resourceId);\n },\n async disposeNamespace(key, options) {\n const hostId = await ensureHostId();\n await __isolateHost_disposeNamespace(hostId, key, options ?? null);\n await __waitForNestedCallbacks();\n },\n async diagnostics() {\n return await __isolateHost_hostDiagnostics(await ensureHostId());\n },\n async close() {\n const hostId = await ensureHostId();\n await __isolateHost_closeHost(hostId);\n await __waitForNestedCallbacks();\n },\n };\n}\n`;\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AASO,IAAM,mCAAmC;AA2CzC,IAAM,gCAAgC;AAAA,6CACA,KAAK,UAAU,mCAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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import {
|
|
|
8
8
|
} from "../internal/browser-source.mjs";
|
|
9
9
|
import { createRuntimeDiagnostics } from "../bridge/diagnostics.mjs";
|
|
10
10
|
import { createRuntimeBindingsAdapter } from "../bridge/runtime-bindings.mjs";
|
|
11
|
+
import { createNamespacedRuntimeAdapter } from "../runtime/namespaced-runtime.mjs";
|
|
11
12
|
import { createScriptRuntimeAdapter } from "../runtime/script-runtime.mjs";
|
|
12
13
|
import { createTestRuntimeAdapter } from "../runtime/test-runtime.mjs";
|
|
13
14
|
import { createAppServerAdapter } from "../server/app-server.mjs";
|
|
@@ -30,6 +31,21 @@ async function waitForSocket(socketPath, timeoutMs) {
|
|
|
30
31
|
}
|
|
31
32
|
throw new Error(`Daemon socket not available after ${timeoutMs}ms`);
|
|
32
33
|
}
|
|
34
|
+
function createNamedError(name, message) {
|
|
35
|
+
const error = new Error(message);
|
|
36
|
+
error.name = name;
|
|
37
|
+
return error;
|
|
38
|
+
}
|
|
39
|
+
function normalizeNamespaceInUseError(error, key) {
|
|
40
|
+
if (error instanceof Error && error.name === "NamespaceInUseError") {
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
43
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
44
|
+
if (/already has an active runtime|creation already in progress/i.test(message)) {
|
|
45
|
+
return createNamedError("NamespaceInUseError", `Namespace "${key}" already has a live runtime.`);
|
|
46
|
+
}
|
|
47
|
+
return error instanceof Error ? error : new Error(message);
|
|
48
|
+
}
|
|
33
49
|
|
|
34
50
|
class HostImpl {
|
|
35
51
|
options;
|
|
@@ -38,6 +54,8 @@ class HostImpl {
|
|
|
38
54
|
connectionPromise = null;
|
|
39
55
|
servers = new Set;
|
|
40
56
|
runtimes = new Set;
|
|
57
|
+
namespacedRuntimes = new Map;
|
|
58
|
+
pendingNamespacedKeys = new Set;
|
|
41
59
|
constructor(options) {
|
|
42
60
|
this.options = options ?? {};
|
|
43
61
|
}
|
|
@@ -50,6 +68,21 @@ class HostImpl {
|
|
|
50
68
|
async createTestRuntime(options) {
|
|
51
69
|
return await this.createTestRuntimeInternal(options);
|
|
52
70
|
}
|
|
71
|
+
async getNamespacedRuntime(key, options) {
|
|
72
|
+
return await this.createNamespacedRuntimeInternal(key, options);
|
|
73
|
+
}
|
|
74
|
+
async disposeNamespace(key, options) {
|
|
75
|
+
this.pendingNamespacedKeys.delete(key);
|
|
76
|
+
const runtime = this.namespacedRuntimes.get(key);
|
|
77
|
+
if (runtime) {
|
|
78
|
+
runtime.invalidate(options?.reason ? `Namespace "${key}" was disposed: ${options.reason}` : `Namespace "${key}" was disposed.`);
|
|
79
|
+
this.namespacedRuntimes.delete(key);
|
|
80
|
+
}
|
|
81
|
+
const connection = await this.getConnection();
|
|
82
|
+
await connection.disposeNamespace(key, {
|
|
83
|
+
reason: options?.reason
|
|
84
|
+
});
|
|
85
|
+
}
|
|
53
86
|
async diagnostics() {
|
|
54
87
|
return {
|
|
55
88
|
runtimes: this.runtimes.size,
|
|
@@ -58,6 +91,11 @@ class HostImpl {
|
|
|
58
91
|
};
|
|
59
92
|
}
|
|
60
93
|
async close() {
|
|
94
|
+
for (const [key, runtime] of this.namespacedRuntimes) {
|
|
95
|
+
runtime.invalidate(`Host closed while namespace "${key}" was active.`);
|
|
96
|
+
}
|
|
97
|
+
this.namespacedRuntimes.clear();
|
|
98
|
+
this.pendingNamespacedKeys.clear();
|
|
61
99
|
if (this.connection) {
|
|
62
100
|
await this.connection.close().catch(() => {});
|
|
63
101
|
}
|
|
@@ -107,6 +145,45 @@ class HostImpl {
|
|
|
107
145
|
this.runtimes.add(testRuntime);
|
|
108
146
|
return testRuntime;
|
|
109
147
|
}
|
|
148
|
+
async createNamespacedRuntimeInternal(key, options) {
|
|
149
|
+
if (this.pendingNamespacedKeys.has(key) || this.namespacedRuntimes.has(key)) {
|
|
150
|
+
throw createNamedError("NamespaceInUseError", `Namespace "${key}" already has a live runtime.`);
|
|
151
|
+
}
|
|
152
|
+
this.pendingNamespacedKeys.add(key);
|
|
153
|
+
const diagnostics = createRuntimeDiagnostics();
|
|
154
|
+
let runtimeId = key;
|
|
155
|
+
const browserSource = createBrowserSourceFromBindings(options.bindings.browser);
|
|
156
|
+
const bindingsAdapter = createRuntimeBindingsAdapter(options.bindings, () => runtimeId, diagnostics, {
|
|
157
|
+
nestedHost: this.createNestedBindings(browserSource)
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
const runtime = await this.createRemoteRuntime({
|
|
161
|
+
...bindingsAdapter.runtimeOptions,
|
|
162
|
+
cwd: options.cwd,
|
|
163
|
+
memoryLimitMB: options.memoryLimitMB,
|
|
164
|
+
executionTimeout: options.executionTimeout,
|
|
165
|
+
testEnvironment: true
|
|
166
|
+
}, key);
|
|
167
|
+
runtimeId = runtime.id;
|
|
168
|
+
let adapter;
|
|
169
|
+
adapter = createNamespacedRuntimeAdapter(runtime, diagnostics, {
|
|
170
|
+
hasBrowser: Boolean(options.bindings.browser),
|
|
171
|
+
abortBindings: (reason) => bindingsAdapter.abort(reason),
|
|
172
|
+
onRelease: () => {
|
|
173
|
+
if (this.namespacedRuntimes.get(key) === adapter) {
|
|
174
|
+
this.namespacedRuntimes.delete(key);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
this.namespacedRuntimes.set(key, adapter);
|
|
179
|
+
this.runtimes.add(adapter);
|
|
180
|
+
return adapter;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
throw normalizeNamespaceInUseError(error, key);
|
|
183
|
+
} finally {
|
|
184
|
+
this.pendingNamespacedKeys.delete(key);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
110
187
|
async createAppServerInternal(options) {
|
|
111
188
|
const server = await createAppServerAdapter(() => this.getConnection(), options, {
|
|
112
189
|
nestedHost: this.createNestedBindings(createBrowserSourceFromBindings(options.bindings.browser))
|
|
@@ -119,6 +196,8 @@ class HostImpl {
|
|
|
119
196
|
createRuntime: async (options) => await this.createRuntimeInternal(options),
|
|
120
197
|
createAppServer: async (options) => await this.createAppServerInternal(options),
|
|
121
198
|
createTestRuntime: async (options) => await this.createTestRuntimeInternal(options),
|
|
199
|
+
getNamespacedRuntime: async (key, options) => await this.createNamespacedRuntimeInternal(key, options),
|
|
200
|
+
disposeNamespace: async (key, options) => await this.disposeNamespace(key, options),
|
|
122
201
|
isConnected: () => this.connection?.isConnected() ?? false
|
|
123
202
|
}, defaultBrowserSource);
|
|
124
203
|
}
|
|
@@ -196,4 +275,4 @@ export {
|
|
|
196
275
|
createIsolateHost
|
|
197
276
|
};
|
|
198
277
|
|
|
199
|
-
//# debugId=
|
|
278
|
+
//# debugId=A2B0180C1C69A0B864756E2164756E21
|
|
@@ -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.mjs\";\nimport {\n createBrowserSourceFromBindings,\n type BrowserSource,\n} from \"../internal/browser-source.mjs\";\nimport { createRuntimeDiagnostics } from \"../bridge/diagnostics.mjs\";\nimport { createRuntimeBindingsAdapter } from \"../bridge/runtime-bindings.mjs\";\nimport { createScriptRuntimeAdapter } from \"../runtime/script-runtime.mjs\";\nimport { createTestRuntimeAdapter } from \"../runtime/test-runtime.mjs\";\nimport { createAppServerAdapter } from \"../server/app-server.mjs\";\nimport { createNestedHostBindings } from \"./nested-host-controller.mjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateIsolateHostOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n IsolateHost,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.mjs\";\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.mjs\";\nimport {\n createBrowserSourceFromBindings,\n type BrowserSource,\n} from \"../internal/browser-source.mjs\";\nimport { createRuntimeDiagnostics } from \"../bridge/diagnostics.mjs\";\nimport { createRuntimeBindingsAdapter } from \"../bridge/runtime-bindings.mjs\";\nimport { createNamespacedRuntimeAdapter } from \"../runtime/namespaced-runtime.mjs\";\nimport { createScriptRuntimeAdapter } from \"../runtime/script-runtime.mjs\";\nimport { createTestRuntimeAdapter } from \"../runtime/test-runtime.mjs\";\nimport { createAppServerAdapter } from \"../server/app-server.mjs\";\nimport { createNestedHostBindings } from \"./nested-host-controller.mjs\";\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.mjs\";\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
|
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,QAAQ,YAAY,SAAS,OAAO,IAAI,QAAQ,IAAI;AAAA,IAC/G,KAAK,gBAAgB,MAAM,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": "A2B0180C1C69A0B864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -29,7 +29,7 @@ function normalizeBindings(bindings, defaultBrowserSource) {
|
|
|
29
29
|
}
|
|
30
30
|
const browserSource = createBrowserSourceFromUnknown(bindings.browser);
|
|
31
31
|
if (!browserSource) {
|
|
32
|
-
throw new Error("Nested browser bindings must use the sandbox browser handle or expose createContext()/createPage().");
|
|
32
|
+
throw new Error("Nested browser bindings must use the sandbox browser handle, a Playwright handler, or expose createContext()/createPage().");
|
|
33
33
|
}
|
|
34
34
|
normalized.browser = browserSource;
|
|
35
35
|
return normalized;
|
|
@@ -46,6 +46,12 @@ function normalizeAppServerOptions(options, defaultBrowserSource) {
|
|
|
46
46
|
bindings: normalizeBindings(options.bindings, defaultBrowserSource)
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
function normalizeNamespacedRuntimeOptions(options, defaultBrowserSource) {
|
|
50
|
+
return {
|
|
51
|
+
...options,
|
|
52
|
+
bindings: normalizeBindings(options.bindings, defaultBrowserSource)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
49
55
|
function toError(value) {
|
|
50
56
|
if (value instanceof Error) {
|
|
51
57
|
return value;
|
|
@@ -89,7 +95,7 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
89
95
|
host.runtimeIds.delete(resourceId);
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
|
-
if (record.kind === "runtime") {
|
|
98
|
+
if (record.kind === "runtime" || record.kind === "namespacedRuntime") {
|
|
93
99
|
for (const unsubscribe of record.subscriptions.values()) {
|
|
94
100
|
unsubscribe();
|
|
95
101
|
}
|
|
@@ -181,6 +187,19 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
181
187
|
host.runtimeIds.add(resourceId);
|
|
182
188
|
return resourceId;
|
|
183
189
|
}
|
|
190
|
+
case "namespacedRuntime": {
|
|
191
|
+
const namespacedOptions = rawOptions;
|
|
192
|
+
const resource = await factory.getNamespacedRuntime(namespacedOptions.key, normalizeNamespacedRuntimeOptions(namespacedOptions.options, defaultBrowserSource));
|
|
193
|
+
const resourceId = randomUUID();
|
|
194
|
+
resources.set(resourceId, {
|
|
195
|
+
kind,
|
|
196
|
+
hostId,
|
|
197
|
+
resource,
|
|
198
|
+
subscriptions: new Map
|
|
199
|
+
});
|
|
200
|
+
host.runtimeIds.add(resourceId);
|
|
201
|
+
return resourceId;
|
|
202
|
+
}
|
|
184
203
|
}
|
|
185
204
|
},
|
|
186
205
|
async callResource(kind, resourceId, method, args) {
|
|
@@ -264,7 +283,46 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
264
283
|
throw new Error(`Unsupported nested test runtime method: ${method}`);
|
|
265
284
|
}
|
|
266
285
|
}
|
|
286
|
+
case "namespacedRuntime": {
|
|
287
|
+
const runtimeRecord = record;
|
|
288
|
+
switch (method) {
|
|
289
|
+
case "eval":
|
|
290
|
+
await runtimeRecord.resource.eval(args[0], args[1] ?? undefined);
|
|
291
|
+
return;
|
|
292
|
+
case "runTests":
|
|
293
|
+
return await runtimeRecord.resource.runTests(args[0], args[1] ?? undefined);
|
|
294
|
+
case "dispose":
|
|
295
|
+
await disposeResource(resourceId, args[0] ?? {});
|
|
296
|
+
return;
|
|
297
|
+
case "diagnostics":
|
|
298
|
+
return await runtimeRecord.resource.diagnostics();
|
|
299
|
+
case "events.on": {
|
|
300
|
+
const subscriptionId = randomUUID();
|
|
301
|
+
const unsubscribe = runtimeRecord.resource.events.on(args[0], args[1]);
|
|
302
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
303
|
+
return subscriptionId;
|
|
304
|
+
}
|
|
305
|
+
case "events.off": {
|
|
306
|
+
const subscriptionId = args[0];
|
|
307
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
308
|
+
if (unsubscribe) {
|
|
309
|
+
unsubscribe();
|
|
310
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
case "events.emit":
|
|
315
|
+
await runtimeRecord.resource.events.emit(args[0], args[1]);
|
|
316
|
+
return;
|
|
317
|
+
default:
|
|
318
|
+
throw new Error(`Unsupported nested namespaced runtime method: ${method}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
267
321
|
}
|
|
322
|
+
},
|
|
323
|
+
async disposeNamespace(hostId, key, options) {
|
|
324
|
+
requireHost(hostId);
|
|
325
|
+
await factory.disposeNamespace(key, options);
|
|
268
326
|
}
|
|
269
327
|
};
|
|
270
328
|
}
|
|
@@ -272,4 +330,4 @@ export {
|
|
|
272
330
|
createNestedHostBindings
|
|
273
331
|
};
|
|
274
332
|
|
|
275
|
-
//# debugId=
|
|
333
|
+
//# debugId=D247008EEEB47EC864756E2164756E21
|
|
@@ -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.mjs\";\nimport {\n createBrowserSourceFromUnknown,\n isDefaultBrowserDescriptor,\n requireBrowserSource,\n type BrowserSource,\n} from \"../internal/browser-source.mjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostBindings,\n HostCallContext,\n RequestResult,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.mjs\";\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.mjs\";\nimport {\n createBrowserSourceFromUnknown,\n isDefaultBrowserDescriptor,\n requireBrowserSource,\n type BrowserSource,\n} from \"../internal/browser-source.mjs\";\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.mjs\";\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": ";AAAA;AAEA;AAAA;AAAA;AAAA;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AAEA;AAAA;AAAA;AAAA;AAAA;AA6EA,SAAS,SAAS,CAAC,YAA4C;AAAA,EAC7D,OAAO,IAAI,QAAQ,WAAW,KAAK;AAAA,IACjC,QAAQ,WAAW,UAAU;AAAA,IAC7B,SAAS,WAAW;AAAA,IACpB,MAAM,WAAW,OAAO,IAAI,WAAW,WAAW,IAAI,IAAI;AAAA,EAC5D,CAAC;AAAA;AAGH,S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ACL,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": "D247008EEEB47EC864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/index.mjs.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.mjs\";\nexport { createModuleResolver } from \"./modules/index.mjs\";\nexport { createFileBindings } from \"./files/index.mjs\";\nexport { getTypeProfile, typecheck, formatTypecheckErrors } from \"./typecheck/index.mjs\";\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.mjs\";\n"
|
|
5
|
+
"export { createIsolateHost } from \"./host/index.mjs\";\nexport { createModuleResolver } from \"./modules/index.mjs\";\nexport { createFileBindings } from \"./files/index.mjs\";\nexport { getTypeProfile, typecheck, formatTypecheckErrors } from \"./typecheck/index.mjs\";\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.mjs\";\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAAA;AACA;AACA;AACA;",
|
|
8
8
|
"debugId": "CB823D2BFBB00D8F64756E2164756E21",
|
|
@@ -6,7 +6,7 @@ function isBrowserBindingLike(value) {
|
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
const candidate = value;
|
|
9
|
-
return typeof candidate.createContext === "function" || typeof candidate.createPage === "function";
|
|
9
|
+
return typeof candidate.handler === "function" || typeof candidate.createContext === "function" || typeof candidate.createPage === "function";
|
|
10
10
|
}
|
|
11
11
|
function isDefaultBrowserDescriptor(value) {
|
|
12
12
|
return Boolean(value && typeof value === "object" && value[ISOLATE_BROWSER_DESCRIPTOR_PROPERTY] === ISOLATE_BROWSER_DESCRIPTOR_VALUE);
|
|
@@ -15,9 +15,20 @@ function createBrowserSourceFromBindings(browser) {
|
|
|
15
15
|
if (!browser) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
+
if ("handler" in browser && typeof browser.handler === "function") {
|
|
19
|
+
return {
|
|
20
|
+
handler: browser.handler,
|
|
21
|
+
captureConsole: browser.captureConsole,
|
|
22
|
+
onEvent: browser.onEvent
|
|
23
|
+
};
|
|
24
|
+
}
|
|
18
25
|
return {
|
|
19
26
|
createContext: browser.createContext,
|
|
20
|
-
createPage: browser.createPage
|
|
27
|
+
createPage: browser.createPage,
|
|
28
|
+
captureConsole: browser.captureConsole,
|
|
29
|
+
onEvent: browser.onEvent,
|
|
30
|
+
readFile: browser.readFile,
|
|
31
|
+
writeFile: browser.writeFile
|
|
21
32
|
};
|
|
22
33
|
}
|
|
23
34
|
function createBrowserSourceFromUnknown(browser) {
|
|
@@ -27,8 +38,8 @@ function createBrowserSourceFromUnknown(browser) {
|
|
|
27
38
|
return createBrowserSourceFromBindings(browser);
|
|
28
39
|
}
|
|
29
40
|
function requireBrowserSource(source, operation) {
|
|
30
|
-
if (!source
|
|
31
|
-
throw new Error(`${operation} requires a browser binding
|
|
41
|
+
if (!source) {
|
|
42
|
+
throw new Error(`${operation} requires a browser binding.`);
|
|
32
43
|
}
|
|
33
44
|
return source;
|
|
34
45
|
}
|
|
@@ -48,4 +59,4 @@ export {
|
|
|
48
59
|
ISOLATE_BROWSER_DESCRIPTOR_PROPERTY
|
|
49
60
|
};
|
|
50
61
|
|
|
51
|
-
//# debugId=
|
|
62
|
+
//# debugId=7F19B92AD0C08BD964756E2164756E21
|
|
@@ -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.mjs\";\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.mjs\";\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,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,YAAY,cAC7B,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,IAAI,aAAa,WAAW,OAAO,QAAQ,YAAY,YAAY;AAAA,IACjE,OAAO;AAAA,MACL,SAAS,QAAQ;AAAA,MACjB,gBAAgB,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,eAAe,QAAQ;AAAA,IACvB,YAAY,QAAQ;AAAA,IACpB,gBAAgB,QAAQ;AAAA,IACxB,SAAS,QAAQ;AAAA,IACjB,UAAU,QAAQ;AAAA,IAClB,WAAW,QAAQ;AAAA,EACrB;AAAA;AAGK,SAAS,8BAA8B,CAC5C,SAC2B;AAAA,EAC3B,IAAI,CAAC,qBAAqB,OAAO,GAAG;AAAA,IAClC;AAAA,EACF;AAAA,EAEA,OAAO,gCAAgC,OAAO;AAAA;AAGzC,SAAS,oBAAoB,CAClC,QACA,WACe;AAAA,EACf,IAAI,CAAC,QAAQ;AAAA,IACX,MAAM,IAAI,MACR,GAAG,uCACL;AAAA,EACF;AAAA,EACA,OAAO;AAAA;AAGF,SAAS,sBAAsB,GAA2B;AAAA,EAC/D,OAAO;AAAA,KACJ,sCAAsC;AAAA,EACzC;AAAA;",
|
|
8
|
+
"debugId": "7F19B92AD0C08BD964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -206,6 +206,17 @@ async function connect(options = {}) {
|
|
|
206
206
|
id,
|
|
207
207
|
createRuntime: (runtimeOptions) => createRuntime(state, runtimeOptions, id)
|
|
208
208
|
}),
|
|
209
|
+
disposeNamespace: async (id, options2) => {
|
|
210
|
+
state.namespacedRuntimes.delete(id);
|
|
211
|
+
const requestId = state.nextRequestId++;
|
|
212
|
+
const request = {
|
|
213
|
+
type: MessageType.DISPOSE_NAMESPACE,
|
|
214
|
+
requestId,
|
|
215
|
+
namespaceId: id,
|
|
216
|
+
reason: typeof options2?.reason === "string" && options2.reason.length > 0 ? options2.reason : undefined
|
|
217
|
+
};
|
|
218
|
+
await sendRequest(state, request);
|
|
219
|
+
},
|
|
209
220
|
close: async () => {
|
|
210
221
|
state.closing = true;
|
|
211
222
|
state.connected = false;
|
|
@@ -1903,4 +1914,4 @@ export {
|
|
|
1903
1914
|
connect
|
|
1904
1915
|
};
|
|
1905
1916
|
|
|
1906
|
-
//# debugId=
|
|
1917
|
+
//# debugId=C25497E94950531064756E2164756E21
|