@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/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 { createTestEventSubscriptions } from \"../runtime/test-event-subscriptions.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 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": ";AAAA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAIA;AACA;AACA;AACA;AACA;AACA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AAC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AAO,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": "0A3E3B0D9033E3BC64756E2164756E21",
|
|
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 === "testRuntime" || record.kind === "namespacedRuntime") {
|
|
93
99
|
for (const unsubscribe of record.subscriptions.values()) {
|
|
94
100
|
unsubscribe();
|
|
95
101
|
}
|
|
@@ -176,7 +182,21 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
176
182
|
resources.set(resourceId, {
|
|
177
183
|
kind,
|
|
178
184
|
hostId,
|
|
179
|
-
resource
|
|
185
|
+
resource,
|
|
186
|
+
subscriptions: new Map
|
|
187
|
+
});
|
|
188
|
+
host.runtimeIds.add(resourceId);
|
|
189
|
+
return resourceId;
|
|
190
|
+
}
|
|
191
|
+
case "namespacedRuntime": {
|
|
192
|
+
const namespacedOptions = rawOptions;
|
|
193
|
+
const resource = await factory.getNamespacedRuntime(namespacedOptions.key, normalizeNamespacedRuntimeOptions(namespacedOptions.options, defaultBrowserSource));
|
|
194
|
+
const resourceId = randomUUID();
|
|
195
|
+
resources.set(resourceId, {
|
|
196
|
+
kind,
|
|
197
|
+
hostId,
|
|
198
|
+
resource,
|
|
199
|
+
subscriptions: new Map
|
|
180
200
|
});
|
|
181
201
|
host.runtimeIds.add(resourceId);
|
|
182
202
|
return resourceId;
|
|
@@ -251,7 +271,8 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
251
271
|
}
|
|
252
272
|
}
|
|
253
273
|
case "testRuntime": {
|
|
254
|
-
const
|
|
274
|
+
const runtimeRecord = record;
|
|
275
|
+
const runtime = runtimeRecord.resource;
|
|
255
276
|
switch (method) {
|
|
256
277
|
case "run":
|
|
257
278
|
return await runtime.run(args[0], args[1] ?? undefined);
|
|
@@ -260,11 +281,80 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
|
|
|
260
281
|
return;
|
|
261
282
|
case "diagnostics":
|
|
262
283
|
return await runtime.diagnostics();
|
|
284
|
+
case "test.on": {
|
|
285
|
+
const subscriptionId = randomUUID();
|
|
286
|
+
const unsubscribe = runtime.test.onEvent(args[0]);
|
|
287
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
288
|
+
return subscriptionId;
|
|
289
|
+
}
|
|
290
|
+
case "test.off": {
|
|
291
|
+
const subscriptionId = args[0];
|
|
292
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
293
|
+
if (unsubscribe) {
|
|
294
|
+
unsubscribe();
|
|
295
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
263
299
|
default:
|
|
264
300
|
throw new Error(`Unsupported nested test runtime method: ${method}`);
|
|
265
301
|
}
|
|
266
302
|
}
|
|
303
|
+
case "namespacedRuntime": {
|
|
304
|
+
const runtimeRecord = record;
|
|
305
|
+
switch (method) {
|
|
306
|
+
case "eval":
|
|
307
|
+
await runtimeRecord.resource.eval(args[0], args[1] ?? undefined);
|
|
308
|
+
return;
|
|
309
|
+
case "runTests":
|
|
310
|
+
return await runtimeRecord.resource.runTests(args[0], args[1] ?? undefined);
|
|
311
|
+
case "dispose":
|
|
312
|
+
await disposeResource(resourceId, args[0] ?? {});
|
|
313
|
+
return;
|
|
314
|
+
case "diagnostics":
|
|
315
|
+
return await runtimeRecord.resource.diagnostics();
|
|
316
|
+
case "test.on": {
|
|
317
|
+
const subscriptionId = randomUUID();
|
|
318
|
+
const unsubscribe = runtimeRecord.resource.test.onEvent(args[0]);
|
|
319
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
320
|
+
return subscriptionId;
|
|
321
|
+
}
|
|
322
|
+
case "test.off": {
|
|
323
|
+
const subscriptionId = args[0];
|
|
324
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
325
|
+
if (unsubscribe) {
|
|
326
|
+
unsubscribe();
|
|
327
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
case "events.on": {
|
|
332
|
+
const subscriptionId = randomUUID();
|
|
333
|
+
const unsubscribe = runtimeRecord.resource.events.on(args[0], args[1]);
|
|
334
|
+
runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);
|
|
335
|
+
return subscriptionId;
|
|
336
|
+
}
|
|
337
|
+
case "events.off": {
|
|
338
|
+
const subscriptionId = args[0];
|
|
339
|
+
const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);
|
|
340
|
+
if (unsubscribe) {
|
|
341
|
+
unsubscribe();
|
|
342
|
+
runtimeRecord.subscriptions.delete(subscriptionId);
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
case "events.emit":
|
|
347
|
+
await runtimeRecord.resource.events.emit(args[0], args[1]);
|
|
348
|
+
return;
|
|
349
|
+
default:
|
|
350
|
+
throw new Error(`Unsupported nested namespaced runtime method: ${method}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
267
353
|
}
|
|
354
|
+
},
|
|
355
|
+
async disposeNamespace(hostId, key, options) {
|
|
356
|
+
requireHost(hostId);
|
|
357
|
+
await factory.disposeNamespace(key, options);
|
|
268
358
|
}
|
|
269
359
|
};
|
|
270
360
|
}
|
|
@@ -272,4 +362,4 @@ export {
|
|
|
272
362
|
createNestedHostBindings
|
|
273
363
|
};
|
|
274
364
|
|
|
275
|
-
//# debugId=
|
|
365
|
+
//# debugId=73960FDA70D5C11564756E2164756E21
|
|
@@ -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 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": ";AAAA;AAEA;AAAA;AAAA;AAAA;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AAEA;AAAA;AAAA;AAAA;AAAA;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,2BAA2B,SAAS,OAAO,GAAG;AAAA,IAChD,WAAW,UAAU,qBACnB,sBACA,yBACF;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,gBAAgB,+BAA+B,SAAS,OAAO;AAAA,EACrE,IAAI,CAAC,eAAe;AAAA,IAClB,MAAM,IAAI,MACR,4HACF;AAAA,EACF;AAAA,EAEA,WAAW,UAAU;AAAA,EACrB,OAAO;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AAM,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,WAAW;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": "73960FDA70D5C11564756E2164756E21",
|
|
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,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acks.onEvent = {
|
|
166
166
|
callbackId: onEventCallbackId,
|
|
167
167
|
name: "testEnvironment.onEvent",
|
|
168
|
-
type: "
|
|
168
|
+
type: "async"
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
testEnvironmentOption = {
|
|
@@ -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;
|
|
@@ -688,7 +699,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
688
699
|
testEnvCallbacks.onEvent = {
|
|
689
700
|
callbackId: onEventCallbackId,
|
|
690
701
|
name: "testEnvironment.onEvent",
|
|
691
|
-
type: "
|
|
702
|
+
type: "async"
|
|
692
703
|
};
|
|
693
704
|
}
|
|
694
705
|
testEnvironmentOption = {
|
|
@@ -1118,8 +1129,8 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1118
1129
|
}
|
|
1119
1130
|
function registerEventCallback(state, handler) {
|
|
1120
1131
|
const callbackId = state.nextCallbackId++;
|
|
1121
|
-
state.callbacks.set(callbackId, (data) => {
|
|
1122
|
-
handler(data);
|
|
1132
|
+
state.callbacks.set(callbackId, async (data) => {
|
|
1133
|
+
await handler(data);
|
|
1123
1134
|
return;
|
|
1124
1135
|
});
|
|
1125
1136
|
return callbackId;
|
|
@@ -1128,10 +1139,10 @@ function registerConsoleCallbacks(state, callbacks) {
|
|
|
1128
1139
|
const registrations = {};
|
|
1129
1140
|
if (callbacks.onEntry) {
|
|
1130
1141
|
const callbackId = state.nextCallbackId++;
|
|
1131
|
-
state.callbacks.set(callbackId, (entry) => {
|
|
1132
|
-
callbacks.onEntry(entry);
|
|
1142
|
+
state.callbacks.set(callbackId, async (entry) => {
|
|
1143
|
+
await callbacks.onEntry(entry);
|
|
1133
1144
|
});
|
|
1134
|
-
registrations.onEntry = { callbackId, name: "onEntry", type: "
|
|
1145
|
+
registrations.onEntry = { callbackId, name: "onEntry", type: "async" };
|
|
1135
1146
|
}
|
|
1136
1147
|
return registrations;
|
|
1137
1148
|
}
|
|
@@ -1429,7 +1440,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1429
1440
|
registerCallback: (fn) => {
|
|
1430
1441
|
const returnedCallbackId = state.nextCallbackId++;
|
|
1431
1442
|
state.callbacks.set(returnedCallbackId, async (...args) => {
|
|
1432
|
-
const fnResult =
|
|
1443
|
+
const fnResult = fn(...args);
|
|
1433
1444
|
const marshalledResult = await marshalValue(fnResult, marshalCtx);
|
|
1434
1445
|
return addCallbackIdsToRefs(marshalledResult);
|
|
1435
1446
|
});
|
|
@@ -1903,4 +1914,4 @@ export {
|
|
|
1903
1914
|
connect
|
|
1904
1915
|
};
|
|
1905
1916
|
|
|
1906
|
-
//# debugId=
|
|
1917
|
+
//# debugId=5E7F07BECF47B02E64756E2164756E21
|