@ricsam/isolate 0.1.11 → 0.1.13
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 +101 -1
- package/dist/cjs/bridge/runtime-bindings.cjs +36 -8
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +157 -2
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +3 -3
- package/dist/cjs/host/create-isolate-host.cjs +85 -1
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +95 -5
- 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 +20 -9
- 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/runtime/index.cjs +5 -2
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +82 -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 +184 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs.map +10 -0
- package/dist/cjs/runtime/test-event-subscriptions.cjs +76 -0
- package/dist/cjs/runtime/test-event-subscriptions.cjs.map +10 -0
- package/dist/cjs/runtime/test-runtime.cjs +26 -3
- package/dist/cjs/runtime/test-runtime.cjs.map +3 -3
- package/dist/mjs/bridge/runtime-bindings.mjs +36 -8
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +157 -2
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +3 -3
- package/dist/mjs/host/create-isolate-host.mjs +85 -1
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +95 -5
- 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 +20 -9
- 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/runtime/index.mjs +5 -2
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +82 -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 +146 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs.map +10 -0
- package/dist/mjs/runtime/test-event-subscriptions.mjs +36 -0
- package/dist/mjs/runtime/test-event-subscriptions.mjs.map +10 -0
- package/dist/mjs/runtime/test-runtime.mjs +26 -3
- package/dist/mjs/runtime/test-runtime.mjs.map +3 -3
- 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 +13 -0
- package/dist/types/runtime/test-event-subscriptions.d.ts +12 -0
- package/dist/types/types.d.ts +51 -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.cjs\";\nimport type {\n CreateAppServerOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.cjs\";\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.cjs\";\nimport type {\n CreateAppServerOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.cjs\";\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 __waitForCallbackTurn() {\n await Promise.resolve();\n await new Promise((resolve) => setTimeout(resolve, 0));\n}\n\nasync function __waitForNestedCallbacks() {\n const settleTurns = 3;\n\n if (typeof __isolateHost_drainCallbacks === \"function\") {\n await __isolateHost_drainCallbacks(settleTurns);\n return;\n }\n\n for (let index = 0; index < settleTurns; index += 1) {\n await __waitForCallbackTurn();\n }\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 test = {\n onEvent: (handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"test.on\",\n [handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"test.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\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 test = {\n onEvent: (handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"test.on\",\n [handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"test.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAoD,IAApD;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAoD,IAApD;AASO,IAAM,mCAAmC;AA2CzC,IAAM,gCAAgC;AAAA,6CACA,KAAK,UAAU,yDAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
8
|
+
"debugId": "9CC38FF33427223764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -73,8 +73,10 @@ 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");
|
|
79
|
+
var import_test_event_subscriptions = require("../runtime/test-event-subscriptions.cjs");
|
|
78
80
|
var import_app_server = require("../server/app-server.cjs");
|
|
79
81
|
var import_nested_host_controller = require("./nested-host-controller.cjs");
|
|
80
82
|
function resolveDefaultDaemonEntrypoint() {
|
|
@@ -95,6 +97,21 @@ async function waitForSocket(socketPath, timeoutMs) {
|
|
|
95
97
|
}
|
|
96
98
|
throw new Error(`Daemon socket not available after ${timeoutMs}ms`);
|
|
97
99
|
}
|
|
100
|
+
function createNamedError(name, message) {
|
|
101
|
+
const error = new Error(message);
|
|
102
|
+
error.name = name;
|
|
103
|
+
return error;
|
|
104
|
+
}
|
|
105
|
+
function normalizeNamespaceInUseError(error, key) {
|
|
106
|
+
if (error instanceof Error && error.name === "NamespaceInUseError") {
|
|
107
|
+
return error;
|
|
108
|
+
}
|
|
109
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
110
|
+
if (/already has an active runtime|creation already in progress/i.test(message)) {
|
|
111
|
+
return createNamedError("NamespaceInUseError", `Namespace "${key}" already has a live runtime.`);
|
|
112
|
+
}
|
|
113
|
+
return error instanceof Error ? error : new Error(message);
|
|
114
|
+
}
|
|
98
115
|
|
|
99
116
|
class HostImpl {
|
|
100
117
|
options;
|
|
@@ -103,6 +120,8 @@ class HostImpl {
|
|
|
103
120
|
connectionPromise = null;
|
|
104
121
|
servers = new Set;
|
|
105
122
|
runtimes = new Set;
|
|
123
|
+
namespacedRuntimes = new Map;
|
|
124
|
+
pendingNamespacedKeys = new Set;
|
|
106
125
|
constructor(options) {
|
|
107
126
|
this.options = options ?? {};
|
|
108
127
|
}
|
|
@@ -115,6 +134,21 @@ class HostImpl {
|
|
|
115
134
|
async createTestRuntime(options) {
|
|
116
135
|
return await this.createTestRuntimeInternal(options);
|
|
117
136
|
}
|
|
137
|
+
async getNamespacedRuntime(key, options) {
|
|
138
|
+
return await this.createNamespacedRuntimeInternal(key, options);
|
|
139
|
+
}
|
|
140
|
+
async disposeNamespace(key, options) {
|
|
141
|
+
this.pendingNamespacedKeys.delete(key);
|
|
142
|
+
const runtime = this.namespacedRuntimes.get(key);
|
|
143
|
+
if (runtime) {
|
|
144
|
+
runtime.invalidate(options?.reason ? `Namespace "${key}" was disposed: ${options.reason}` : `Namespace "${key}" was disposed.`);
|
|
145
|
+
this.namespacedRuntimes.delete(key);
|
|
146
|
+
}
|
|
147
|
+
const connection = await this.getConnection();
|
|
148
|
+
await connection.disposeNamespace(key, {
|
|
149
|
+
reason: options?.reason
|
|
150
|
+
});
|
|
151
|
+
}
|
|
118
152
|
async diagnostics() {
|
|
119
153
|
return {
|
|
120
154
|
runtimes: this.runtimes.size,
|
|
@@ -123,6 +157,11 @@ class HostImpl {
|
|
|
123
157
|
};
|
|
124
158
|
}
|
|
125
159
|
async close() {
|
|
160
|
+
for (const [key, runtime] of this.namespacedRuntimes) {
|
|
161
|
+
runtime.invalidate(`Host closed while namespace "${key}" was active.`);
|
|
162
|
+
}
|
|
163
|
+
this.namespacedRuntimes.clear();
|
|
164
|
+
this.pendingNamespacedKeys.clear();
|
|
126
165
|
if (this.connection) {
|
|
127
166
|
await this.connection.close().catch(() => {});
|
|
128
167
|
}
|
|
@@ -172,6 +211,49 @@ class HostImpl {
|
|
|
172
211
|
this.runtimes.add(testRuntime);
|
|
173
212
|
return testRuntime;
|
|
174
213
|
}
|
|
214
|
+
async createNamespacedRuntimeInternal(key, options) {
|
|
215
|
+
if (this.pendingNamespacedKeys.has(key) || this.namespacedRuntimes.has(key)) {
|
|
216
|
+
throw createNamedError("NamespaceInUseError", `Namespace "${key}" already has a live runtime.`);
|
|
217
|
+
}
|
|
218
|
+
this.pendingNamespacedKeys.add(key);
|
|
219
|
+
const diagnostics = import_diagnostics.createRuntimeDiagnostics();
|
|
220
|
+
const testEvents = import_test_event_subscriptions.createTestEventSubscriptions();
|
|
221
|
+
let runtimeId = key;
|
|
222
|
+
const browserSource = import_browser_source.createBrowserSourceFromBindings(options.bindings.browser);
|
|
223
|
+
const bindingsAdapter = import_runtime_bindings.createRuntimeBindingsAdapter(options.bindings, () => runtimeId, diagnostics, {
|
|
224
|
+
nestedHost: this.createNestedBindings(browserSource)
|
|
225
|
+
});
|
|
226
|
+
try {
|
|
227
|
+
const runtime = await this.createRemoteRuntime({
|
|
228
|
+
...bindingsAdapter.runtimeOptions,
|
|
229
|
+
cwd: options.cwd,
|
|
230
|
+
memoryLimitMB: options.memoryLimitMB,
|
|
231
|
+
executionTimeout: options.executionTimeout,
|
|
232
|
+
testEnvironment: {
|
|
233
|
+
onEvent: (event) => testEvents.emit(event)
|
|
234
|
+
}
|
|
235
|
+
}, key);
|
|
236
|
+
runtimeId = runtime.id;
|
|
237
|
+
let adapter;
|
|
238
|
+
adapter = import_namespaced_runtime.createNamespacedRuntimeAdapter(runtime, diagnostics, {
|
|
239
|
+
hasBrowser: Boolean(options.bindings.browser),
|
|
240
|
+
abortBindings: (reason) => bindingsAdapter.abort(reason),
|
|
241
|
+
testEvents,
|
|
242
|
+
onRelease: () => {
|
|
243
|
+
if (this.namespacedRuntimes.get(key) === adapter) {
|
|
244
|
+
this.namespacedRuntimes.delete(key);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
this.namespacedRuntimes.set(key, adapter);
|
|
249
|
+
this.runtimes.add(adapter);
|
|
250
|
+
return adapter;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
throw normalizeNamespaceInUseError(error, key);
|
|
253
|
+
} finally {
|
|
254
|
+
this.pendingNamespacedKeys.delete(key);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
175
257
|
async createAppServerInternal(options) {
|
|
176
258
|
const server = await import_app_server.createAppServerAdapter(() => this.getConnection(), options, {
|
|
177
259
|
nestedHost: this.createNestedBindings(import_browser_source.createBrowserSourceFromBindings(options.bindings.browser))
|
|
@@ -184,6 +266,8 @@ class HostImpl {
|
|
|
184
266
|
createRuntime: async (options) => await this.createRuntimeInternal(options),
|
|
185
267
|
createAppServer: async (options) => await this.createAppServerInternal(options),
|
|
186
268
|
createTestRuntime: async (options) => await this.createTestRuntimeInternal(options),
|
|
269
|
+
getNamespacedRuntime: async (key, options) => await this.createNamespacedRuntimeInternal(key, options),
|
|
270
|
+
disposeNamespace: async (key, options) => await this.disposeNamespace(key, options),
|
|
187
271
|
isConnected: () => this.connection?.isConnected() ?? false
|
|
188
272
|
}, defaultBrowserSource);
|
|
189
273
|
}
|
|
@@ -258,4 +342,4 @@ async function createIsolateHost(options) {
|
|
|
258
342
|
return new HostImpl(options);
|
|
259
343
|
}
|
|
260
344
|
|
|
261
|
-
//# debugId=
|
|
345
|
+
//# debugId=9808B79FF11AEC9864756E2164756E21
|
|
@@ -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 { createTestEventSubscriptions } from \"../runtime/test-event-subscriptions.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 const testEvents = createTestEventSubscriptions();\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: {\n onEvent: (event) => testEvents.emit(event),\n },\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 testEvents,\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,IAAzC;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAe,IAAf;AACiB,IAAjB;AACyC,IAAzC;AACwF,IAAxF;AAIO,IAHP;AAIyC,IAAzC;AAC6C,IAA7C;AAC+C,IA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S,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": "9808B79FF11AEC9864756E2164756E21",
|
|
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 === "testRuntime" || record.kind === "namespacedRuntime") {
|
|
132
138
|
for (const unsubscribe of record.subscriptions.values()) {
|
|
133
139
|
unsubscribe();
|
|
134
140
|
}
|
|
@@ -215,7 +221,21 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
215
221
|
resources.set(resourceId, {
|
|
216
222
|
kind,
|
|
217
223
|
hostId,
|
|
218
|
-
resource
|
|
224
|
+
resource,
|
|
225
|
+
subscriptions: new Map
|
|
226
|
+
});
|
|
227
|
+
host.runtimeIds.add(resourceId);
|
|
228
|
+
return resourceId;
|
|
229
|
+
}
|
|
230
|
+
case "namespacedRuntime": {
|
|
231
|
+
const namespacedOptions = rawOptions;
|
|
232
|
+
const resource = await factory.getNamespacedRuntime(namespacedOptions.key, normalizeNamespacedRuntimeOptions(namespacedOptions.options, defaultBrowserSource));
|
|
233
|
+
const resourceId = import_node_crypto.randomUUID();
|
|
234
|
+
resources.set(resourceId, {
|
|
235
|
+
kind,
|
|
236
|
+
hostId,
|
|
237
|
+
resource,
|
|
238
|
+
subscriptions: new Map
|
|
219
239
|
});
|
|
220
240
|
host.runtimeIds.add(resourceId);
|
|
221
241
|
return resourceId;
|
|
@@ -290,7 +310,8 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
290
310
|
}
|
|
291
311
|
}
|
|
292
312
|
case "testRuntime": {
|
|
293
|
-
const
|
|
313
|
+
const runtimeRecord = record;
|
|
314
|
+
const runtime = runtimeRecord.resource;
|
|
294
315
|
switch (method) {
|
|
295
316
|
case "run":
|
|
296
317
|
return await runtime.run(args[0], args[1] ?? undefined);
|
|
@@ -299,13 +320,82 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
299
320
|
return;
|
|
300
321
|
case "diagnostics":
|
|
301
322
|
return await runtime.diagnostics();
|
|
323
|
+
case "test.on": {
|
|
324
|
+
const subscriptionId = import_node_crypto.randomUUID();
|
|
325
|
+
const unsubscribe = runtime.test.onEvent(args[0]);
|
|
326
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
327
|
+
return subscriptionId;
|
|
328
|
+
}
|
|
329
|
+
case "test.off": {
|
|
330
|
+
const subscriptionId = args[0];
|
|
331
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
332
|
+
if (unsubscribe) {
|
|
333
|
+
unsubscribe();
|
|
334
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
302
338
|
default:
|
|
303
339
|
throw new Error(`Unsupported nested test runtime method: ${method}`);
|
|
304
340
|
}
|
|
305
341
|
}
|
|
342
|
+
case "namespacedRuntime": {
|
|
343
|
+
const runtimeRecord = record;
|
|
344
|
+
switch (method) {
|
|
345
|
+
case "eval":
|
|
346
|
+
await runtimeRecord.resource.eval(args[0], args[1] ?? undefined);
|
|
347
|
+
return;
|
|
348
|
+
case "runTests":
|
|
349
|
+
return await runtimeRecord.resource.runTests(args[0], args[1] ?? undefined);
|
|
350
|
+
case "dispose":
|
|
351
|
+
await disposeResource(resourceId, args[0] ?? {});
|
|
352
|
+
return;
|
|
353
|
+
case "diagnostics":
|
|
354
|
+
return await runtimeRecord.resource.diagnostics();
|
|
355
|
+
case "test.on": {
|
|
356
|
+
const subscriptionId = import_node_crypto.randomUUID();
|
|
357
|
+
const unsubscribe = runtimeRecord.resource.test.onEvent(args[0]);
|
|
358
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
359
|
+
return subscriptionId;
|
|
360
|
+
}
|
|
361
|
+
case "test.off": {
|
|
362
|
+
const subscriptionId = args[0];
|
|
363
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
364
|
+
if (unsubscribe) {
|
|
365
|
+
unsubscribe();
|
|
366
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
367
|
+
}
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
case "events.on": {
|
|
371
|
+
const subscriptionId = import_node_crypto.randomUUID();
|
|
372
|
+
const unsubscribe = runtimeRecord.resource.events.on(args[0], args[1]);
|
|
373
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
374
|
+
return subscriptionId;
|
|
375
|
+
}
|
|
376
|
+
case "events.off": {
|
|
377
|
+
const subscriptionId = args[0];
|
|
378
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
379
|
+
if (unsubscribe) {
|
|
380
|
+
unsubscribe();
|
|
381
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
382
|
+
}
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
case "events.emit":
|
|
386
|
+
await runtimeRecord.resource.events.emit(args[0], args[1]);
|
|
387
|
+
return;
|
|
388
|
+
default:
|
|
389
|
+
throw new Error(`Unsupported nested namespaced runtime method: ${method}`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
306
392
|
}
|
|
393
|
+
},
|
|
394
|
+
async disposeNamespace(hostId, key, options) {
|
|
395
|
+
requireHost(hostId);
|
|
396
|
+
await factory.disposeNamespace(key, options);
|
|
307
397
|
}
|
|
308
398
|
};
|
|
309
399
|
}
|
|
310
400
|
|
|
311
|
-
//# debugId=
|
|
401
|
+
//# debugId=BA30316728BB35DA64756E2164756E21
|
|
@@ -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 subscriptions: Map<string, () => void>;\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 (\n record.kind === \"runtime\" ||\n record.kind === \"testRuntime\" ||\n record.kind === \"namespacedRuntime\"\n ) {\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 subscriptions: new Map(),\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 runtimeRecord = record as TestRuntimeResourceRecord;\n const runtime = runtimeRecord.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 case \"test.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtime.test.onEvent(\n args[0] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"test.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 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 \"test.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtimeRecord.resource.test.onEvent(\n args[0] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"test.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.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;AA8EA,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,SAAS,iBAAiB,CACxB,UACA,sBACc;AAAA,EACd,MAAM,aAA2B;AAAA,IAC/B,SAAS,UAAU;AAAA,IACnB,OAAO,UAAU;AAAA,IACjB,OAAO,UAAU;AAAA,IACjB,SAAS,UAAU;AAAA,IACnB,OAAO,UAAU;AAAA,EACnB;AAAA,EAEA,IAAI,CAAC,YAAY,EAAE,aAAa,aAAa,SAAS,YAAY,WAAW;AAAA,IAC3E,OAAO;AAAA,EACT;AAAA,EAEA,IAAI,iDAA2B,SAAS,OAAO,GAAG;AAAA,IAChD,WAAW,UAAU,2CACnB,sBACA,yBACF;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,gBAAgB,qDAA+B,SAAS,OAAO;AAAA,EACrE,IAAI,CAAC,eAAe;AAAA,IAClB,MAAM,IAAI,MAC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AgB,WAAW;AAAA,cAC3D,OAAO;AAAA,YACT;AAAA,iBACK,YAAY;AAAA,cACf,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;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": "BA30316728BB35DA64756E2164756E21",
|
|
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
|