@ricsam/isolate 0.1.12 → 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.
Files changed (48) hide show
  1. package/README.md +15 -0
  2. package/dist/cjs/bridge/runtime-bindings.cjs +11 -10
  3. package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
  4. package/dist/cjs/bridge/sandbox-isolate.cjs +58 -2
  5. package/dist/cjs/bridge/sandbox-isolate.cjs.map +3 -3
  6. package/dist/cjs/host/create-isolate-host.cjs +7 -2
  7. package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
  8. package/dist/cjs/host/nested-host-controller.cjs +36 -4
  9. package/dist/cjs/host/nested-host-controller.cjs.map +3 -3
  10. package/dist/cjs/internal/client/connection.cjs +9 -9
  11. package/dist/cjs/internal/client/connection.cjs.map +3 -3
  12. package/dist/cjs/internal/runtime/index.cjs +5 -2
  13. package/dist/cjs/internal/runtime/index.cjs.map +3 -3
  14. package/dist/cjs/internal/typecheck/isolate-types.cjs +50 -1
  15. package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
  16. package/dist/cjs/package.json +1 -1
  17. package/dist/cjs/runtime/namespaced-runtime.cjs +4 -1
  18. package/dist/cjs/runtime/namespaced-runtime.cjs.map +3 -3
  19. package/dist/cjs/runtime/test-event-subscriptions.cjs +76 -0
  20. package/dist/cjs/runtime/test-event-subscriptions.cjs.map +10 -0
  21. package/dist/cjs/runtime/test-runtime.cjs +26 -3
  22. package/dist/cjs/runtime/test-runtime.cjs.map +3 -3
  23. package/dist/mjs/bridge/runtime-bindings.mjs +11 -10
  24. package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
  25. package/dist/mjs/bridge/sandbox-isolate.mjs +58 -2
  26. package/dist/mjs/bridge/sandbox-isolate.mjs.map +3 -3
  27. package/dist/mjs/host/create-isolate-host.mjs +7 -2
  28. package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
  29. package/dist/mjs/host/nested-host-controller.mjs +36 -4
  30. package/dist/mjs/host/nested-host-controller.mjs.map +3 -3
  31. package/dist/mjs/internal/client/connection.mjs +9 -9
  32. package/dist/mjs/internal/client/connection.mjs.map +3 -3
  33. package/dist/mjs/internal/runtime/index.mjs +5 -2
  34. package/dist/mjs/internal/runtime/index.mjs.map +3 -3
  35. package/dist/mjs/internal/typecheck/isolate-types.mjs +50 -1
  36. package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
  37. package/dist/mjs/package.json +1 -1
  38. package/dist/mjs/runtime/namespaced-runtime.mjs +4 -1
  39. package/dist/mjs/runtime/namespaced-runtime.mjs.map +3 -3
  40. package/dist/mjs/runtime/test-event-subscriptions.mjs +36 -0
  41. package/dist/mjs/runtime/test-event-subscriptions.mjs.map +10 -0
  42. package/dist/mjs/runtime/test-runtime.mjs +26 -3
  43. package/dist/mjs/runtime/test-runtime.mjs.map +3 -3
  44. package/dist/types/internal/typecheck/isolate-types.d.ts +2 -2
  45. package/dist/types/runtime/namespaced-runtime.d.ts +3 -1
  46. package/dist/types/runtime/test-event-subscriptions.d.ts +12 -0
  47. package/dist/types/types.d.ts +6 -0
  48. package/package.json +1 -1
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/bridge/sandbox-isolate.ts"],
4
4
  "sourcesContent": [
5
- "import { ISOLATE_BROWSER_DESCRIPTOR_PROPERTY } from \"../internal/browser-source.mjs\";\nimport type {\n CreateAppServerOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.mjs\";\n\nexport const SANDBOX_ISOLATE_MODULE_SPECIFIER = \"@ricsam/isolate\";\n\nexport type NestedResourceKind =\n | \"runtime\"\n | \"appServer\"\n | \"testRuntime\"\n | \"namespacedRuntime\";\n\nexport interface NestedHostBindings {\n createHost(context: HostCallContext): Promise<string>;\n closeHost(hostId: string, context: HostCallContext): Promise<void>;\n diagnostics(\n hostId: string,\n context: HostCallContext,\n ): Promise<{ runtimes: number; servers: number; connected: boolean }>;\n createResource(\n hostId: string,\n kind: NestedResourceKind,\n options:\n | CreateRuntimeOptions\n | CreateAppServerOptions\n | CreateTestRuntimeOptions\n | {\n key: string;\n options: CreateNamespacedRuntimeOptions;\n },\n context: HostCallContext,\n ): Promise<string>;\n disposeNamespace(\n hostId: string,\n key: string,\n options: { reason?: string } | undefined,\n context: HostCallContext,\n ): Promise<void>;\n callResource(\n kind: NestedResourceKind,\n resourceId: string,\n method: string,\n args: unknown[],\n context: HostCallContext,\n ): Promise<unknown>;\n}\n\nexport const SANDBOX_ISOLATE_MODULE_SOURCE = `\nconst __isolateBrowserDescriptorProperty = ${JSON.stringify(ISOLATE_BROWSER_DESCRIPTOR_PROPERTY)};\n\nfunction __normalizeBrowserHandle(value) {\n if (\n value &&\n typeof value === \"object\" &&\n value[__isolateBrowserDescriptorProperty]\n ) {\n return {\n [__isolateBrowserDescriptorProperty]: value[__isolateBrowserDescriptorProperty],\n };\n }\n return value;\n}\n\nfunction __normalizeBindings(bindings) {\n if (!bindings || typeof bindings !== \"object\") {\n return {};\n }\n\n const normalized = { ...bindings };\n if (\"browser\" in normalized) {\n normalized.browser = __normalizeBrowserHandle(normalized.browser);\n }\n return normalized;\n}\n\nfunction __normalizeRuntimeOptions(options) {\n const normalized = options ? { ...options } : {};\n normalized.bindings = __normalizeBindings(normalized.bindings);\n return normalized;\n}\n\nfunction __normalizeNamespacedRuntimeOptions(key, options) {\n return {\n key,\n options: __normalizeRuntimeOptions(options),\n };\n}\n\nasync function __serializeRequest(requestLike) {\n const request = requestLike instanceof Request\n ? requestLike\n : new Request(requestLike);\n const headers = [];\n request.headers.forEach((value, key) => {\n headers.push([key, value]);\n });\n let body = null;\n if (request.body) {\n const cloned = request.clone();\n body = Array.from(new Uint8Array(await cloned.arrayBuffer()));\n }\n return {\n url: request.url,\n method: request.method,\n headers,\n body,\n };\n}\n\nfunction __normalizeEvalOptions(options) {\n if (typeof options === \"string\") {\n return { filename: options };\n }\n return options ?? null;\n}\n\nasync function __waitForNestedCallbacks() {\n await new Promise((resolve) => setTimeout(resolve, 0));\n}\n\nclass NestedScriptRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nclass NestedAppServer {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async handle(request, options) {\n const serializedRequest = await __serializeRequest(request);\n const result = await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"handle\",\n [\n serializedRequest,\n options\n ? {\n requestId: options.requestId,\n metadata: options.metadata,\n }\n : null,\n ],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n ws = {\n open: async (connectionId) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.open\",\n [connectionId],\n );\n await __waitForNestedCallbacks();\n },\n message: async (connectionId, data) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.message\",\n [connectionId, data],\n );\n await __waitForNestedCallbacks();\n },\n close: async (connectionId, code, reason) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.close\",\n [connectionId, code, reason],\n );\n await __waitForNestedCallbacks();\n },\n error: async (connectionId, error) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.error\",\n [connectionId, error],\n );\n await __waitForNestedCallbacks();\n },\n };\n\n async reload(reason) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"reload\",\n [reason ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n}\n\nclass NestedTestRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async run(code, options) {\n const result = await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"run\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n}\n\nclass NestedNamespacedRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async runTests(code, options) {\n const result = await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"runTests\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nexport function createIsolateHost() {\n let hostIdPromise;\n\n const ensureHostId = async () => {\n if (!hostIdPromise) {\n hostIdPromise = __isolateHost_createHost();\n }\n return await hostIdPromise;\n };\n\n return {\n async createRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"runtime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedScriptRuntime(resourceId);\n },\n async createAppServer(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"appServer\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedAppServer(resourceId);\n },\n async createTestRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"testRuntime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedTestRuntime(resourceId);\n },\n async getNamespacedRuntime(key, options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"namespacedRuntime\",\n __normalizeNamespacedRuntimeOptions(key, options),\n );\n return new NestedNamespacedRuntime(resourceId);\n },\n async disposeNamespace(key, options) {\n const hostId = await ensureHostId();\n await __isolateHost_disposeNamespace(hostId, key, options ?? null);\n await __waitForNestedCallbacks();\n },\n async diagnostics() {\n return await __isolateHost_hostDiagnostics(await ensureHostId());\n },\n async close() {\n const hostId = await ensureHostId();\n await __isolateHost_closeHost(hostId);\n await __waitForNestedCallbacks();\n },\n };\n}\n`;\n"
5
+ "import { ISOLATE_BROWSER_DESCRIPTOR_PROPERTY } from \"../internal/browser-source.mjs\";\nimport type {\n CreateAppServerOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.mjs\";\n\nexport const SANDBOX_ISOLATE_MODULE_SPECIFIER = \"@ricsam/isolate\";\n\nexport type NestedResourceKind =\n | \"runtime\"\n | \"appServer\"\n | \"testRuntime\"\n | \"namespacedRuntime\";\n\nexport interface NestedHostBindings {\n createHost(context: HostCallContext): Promise<string>;\n closeHost(hostId: string, context: HostCallContext): Promise<void>;\n diagnostics(\n hostId: string,\n context: HostCallContext,\n ): Promise<{ runtimes: number; servers: number; connected: boolean }>;\n createResource(\n hostId: string,\n kind: NestedResourceKind,\n options:\n | CreateRuntimeOptions\n | CreateAppServerOptions\n | CreateTestRuntimeOptions\n | {\n key: string;\n options: CreateNamespacedRuntimeOptions;\n },\n context: HostCallContext,\n ): Promise<string>;\n disposeNamespace(\n hostId: string,\n key: string,\n options: { reason?: string } | undefined,\n context: HostCallContext,\n ): Promise<void>;\n callResource(\n kind: NestedResourceKind,\n resourceId: string,\n method: string,\n args: unknown[],\n context: HostCallContext,\n ): Promise<unknown>;\n}\n\nexport const SANDBOX_ISOLATE_MODULE_SOURCE = `\nconst __isolateBrowserDescriptorProperty = ${JSON.stringify(ISOLATE_BROWSER_DESCRIPTOR_PROPERTY)};\n\nfunction __normalizeBrowserHandle(value) {\n if (\n value &&\n typeof value === \"object\" &&\n value[__isolateBrowserDescriptorProperty]\n ) {\n return {\n [__isolateBrowserDescriptorProperty]: value[__isolateBrowserDescriptorProperty],\n };\n }\n return value;\n}\n\nfunction __normalizeBindings(bindings) {\n if (!bindings || typeof bindings !== \"object\") {\n return {};\n }\n\n const normalized = { ...bindings };\n if (\"browser\" in normalized) {\n normalized.browser = __normalizeBrowserHandle(normalized.browser);\n }\n return normalized;\n}\n\nfunction __normalizeRuntimeOptions(options) {\n const normalized = options ? { ...options } : {};\n normalized.bindings = __normalizeBindings(normalized.bindings);\n return normalized;\n}\n\nfunction __normalizeNamespacedRuntimeOptions(key, options) {\n return {\n key,\n options: __normalizeRuntimeOptions(options),\n };\n}\n\nasync function __serializeRequest(requestLike) {\n const request = requestLike instanceof Request\n ? requestLike\n : new Request(requestLike);\n const headers = [];\n request.headers.forEach((value, key) => {\n headers.push([key, value]);\n });\n let body = null;\n if (request.body) {\n const cloned = request.clone();\n body = Array.from(new Uint8Array(await cloned.arrayBuffer()));\n }\n return {\n url: request.url,\n method: request.method,\n headers,\n body,\n };\n}\n\nfunction __normalizeEvalOptions(options) {\n if (typeof options === \"string\") {\n return { filename: options };\n }\n return options ?? null;\n}\n\nasync function __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": ";AAAA;AASO,IAAM,mCAAmC;AA2CzC,IAAM,gCAAgC;AAAA,6CACA,KAAK,UAAU,mCAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;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;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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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;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;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
8
+ "debugId": "9CE3670C55EE670464756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -11,6 +11,7 @@ import { createRuntimeBindingsAdapter } from "../bridge/runtime-bindings.mjs";
11
11
  import { createNamespacedRuntimeAdapter } from "../runtime/namespaced-runtime.mjs";
12
12
  import { createScriptRuntimeAdapter } from "../runtime/script-runtime.mjs";
13
13
  import { createTestRuntimeAdapter } from "../runtime/test-runtime.mjs";
14
+ import { createTestEventSubscriptions } from "../runtime/test-event-subscriptions.mjs";
14
15
  import { createAppServerAdapter } from "../server/app-server.mjs";
15
16
  import { createNestedHostBindings } from "./nested-host-controller.mjs";
16
17
  function resolveDefaultDaemonEntrypoint() {
@@ -151,6 +152,7 @@ class HostImpl {
151
152
  }
152
153
  this.pendingNamespacedKeys.add(key);
153
154
  const diagnostics = createRuntimeDiagnostics();
155
+ const testEvents = createTestEventSubscriptions();
154
156
  let runtimeId = key;
155
157
  const browserSource = createBrowserSourceFromBindings(options.bindings.browser);
156
158
  const bindingsAdapter = createRuntimeBindingsAdapter(options.bindings, () => runtimeId, diagnostics, {
@@ -162,13 +164,16 @@ class HostImpl {
162
164
  cwd: options.cwd,
163
165
  memoryLimitMB: options.memoryLimitMB,
164
166
  executionTimeout: options.executionTimeout,
165
- testEnvironment: true
167
+ testEnvironment: {
168
+ onEvent: (event) => testEvents.emit(event)
169
+ }
166
170
  }, key);
167
171
  runtimeId = runtime.id;
168
172
  let adapter;
169
173
  adapter = createNamespacedRuntimeAdapter(runtime, diagnostics, {
170
174
  hasBrowser: Boolean(options.bindings.browser),
171
175
  abortBindings: (reason) => bindingsAdapter.abort(reason),
176
+ testEvents,
172
177
  onRelease: () => {
173
178
  if (this.namespacedRuntimes.get(key) === adapter) {
174
179
  this.namespacedRuntimes.delete(key);
@@ -275,4 +280,4 @@ export {
275
280
  createIsolateHost
276
281
  };
277
282
 
278
- //# debugId=A2B0180C1C69A0B864756E2164756E21
283
+ //# debugId=0A3E3B0D9033E3BC64756E2164756E21
@@ -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 { createNamespacedRuntimeAdapter } from \"../runtime/namespaced-runtime.mjs\";\nimport { createScriptRuntimeAdapter } from \"../runtime/script-runtime.mjs\";\nimport { createTestRuntimeAdapter } from \"../runtime/test-runtime.mjs\";\nimport { createAppServerAdapter } from \"../server/app-server.mjs\";\nimport { createNestedHostBindings } from \"./nested-host-controller.mjs\";\nimport type {\n AppServer,\n CreateAppServerOptions,\n CreateIsolateHostOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n IsolateHost,\n NamespacedRuntime,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.mjs\";\n\nfunction resolveDefaultDaemonEntrypoint(): string | null {\n const localPath = path.resolve(import.meta.dirname, \"../daemon.ts\");\n if (fs.existsSync(localPath)) {\n return localPath;\n }\n return null;\n}\n\nasync function waitForSocket(socketPath: string, timeoutMs: number): Promise<void> {\n const startTime = Date.now();\n while (Date.now() - startTime < timeoutMs) {\n if (fs.existsSync(socketPath)) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 50));\n }\n\n throw new Error(`Daemon socket not available after ${timeoutMs}ms`);\n}\n\nfunction createNamedError(name: string, message: string): Error {\n const error = new Error(message);\n error.name = name;\n return error;\n}\n\nfunction normalizeNamespaceInUseError(error: unknown, key: string): Error {\n if (error instanceof Error && error.name === \"NamespaceInUseError\") {\n return error;\n }\n\n const message =\n error instanceof Error ? error.message : String(error ?? \"\");\n if (/already has an active runtime|creation already in progress/i.test(message)) {\n return createNamedError(\n \"NamespaceInUseError\",\n `Namespace \"${key}\" already has a live runtime.`,\n );\n }\n\n return error instanceof Error ? error : new Error(message);\n}\n\nclass HostImpl implements IsolateHost {\n private readonly options: CreateIsolateHostOptions;\n private daemonProcess: ChildProcess | null = null;\n private connection: DaemonConnection | null = null;\n private connectionPromise: Promise<DaemonConnection> | null = null;\n private readonly servers = new Set<object>();\n private readonly runtimes = new Set<object>();\n private readonly namespacedRuntimes = new Map<string, ReturnType<typeof createNamespacedRuntimeAdapter>>();\n private readonly pendingNamespacedKeys = new Set<string>();\n\n constructor(options?: CreateIsolateHostOptions) {\n this.options = options ?? {};\n }\n\n async createAppServer(options: CreateAppServerOptions) {\n return await this.createAppServerInternal(options);\n }\n\n async createRuntime(options: CreateRuntimeOptions) {\n return await this.createRuntimeInternal(options);\n }\n\n async createTestRuntime(options: CreateTestRuntimeOptions) {\n return await this.createTestRuntimeInternal(options);\n }\n\n async getNamespacedRuntime(\n key: string,\n options: CreateNamespacedRuntimeOptions,\n ) {\n return await this.createNamespacedRuntimeInternal(key, options);\n }\n\n async disposeNamespace(key: string, options?: { reason?: string }) {\n this.pendingNamespacedKeys.delete(key);\n const runtime = this.namespacedRuntimes.get(key);\n if (runtime) {\n runtime.invalidate(\n options?.reason\n ? `Namespace \"${key}\" was disposed: ${options.reason}`\n : `Namespace \"${key}\" was disposed.`,\n );\n this.namespacedRuntimes.delete(key);\n }\n\n const connection = await this.getConnection();\n await connection.disposeNamespace(key, {\n reason: options?.reason,\n });\n }\n\n async diagnostics() {\n return {\n runtimes: this.runtimes.size,\n servers: this.servers.size,\n connected: this.connection?.isConnected() ?? false,\n };\n }\n\n async close(): Promise<void> {\n for (const [key, runtime] of this.namespacedRuntimes) {\n runtime.invalidate(`Host closed while namespace \"${key}\" was active.`);\n }\n this.namespacedRuntimes.clear();\n this.pendingNamespacedKeys.clear();\n\n if (this.connection) {\n await this.connection.close().catch(() => {});\n }\n this.connection = null;\n this.connectionPromise = null;\n\n if (this.daemonProcess) {\n const process = this.daemonProcess;\n this.daemonProcess = null;\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n process.kill(\"SIGKILL\");\n resolve();\n }, 5000);\n process.once(\"exit\", () => {\n clearTimeout(timeout);\n resolve();\n });\n process.kill(\"SIGTERM\");\n });\n }\n }\n\n private async createRuntimeInternal(\n options: CreateRuntimeOptions,\n ): Promise<ScriptRuntime> {\n const diagnostics = createRuntimeDiagnostics();\n let runtimeId = options.key ?? \"runtime\";\n const browserSource = createBrowserSourceFromBindings(options.bindings.browser);\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n {\n nestedHost: this.createNestedBindings(browserSource),\n },\n );\n const runtime = await this.createRemoteRuntime(\n {\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n },\n options.key,\n );\n runtimeId = runtime.id;\n const adapter = createScriptRuntimeAdapter(runtime, diagnostics, {\n hasBrowser: Boolean(options.bindings.browser),\n onBeforeDispose: (reason) => bindingsAdapter.abort(reason),\n });\n this.runtimes.add(adapter);\n return adapter;\n }\n\n private async createTestRuntimeInternal(\n options: CreateTestRuntimeOptions,\n ): Promise<TestRuntime> {\n const testRuntime = await createTestRuntimeAdapter(\n async (runtimeOptions) => await this.createRemoteRuntime(runtimeOptions, options.key),\n options,\n {\n nestedHost: this.createNestedBindings(\n createBrowserSourceFromBindings(options.bindings.browser),\n ),\n },\n );\n this.runtimes.add(testRuntime);\n return testRuntime;\n }\n\n private async createNamespacedRuntimeInternal(\n key: string,\n options: CreateNamespacedRuntimeOptions,\n ): Promise<NamespacedRuntime> {\n if (this.pendingNamespacedKeys.has(key) || this.namespacedRuntimes.has(key)) {\n throw createNamedError(\n \"NamespaceInUseError\",\n `Namespace \"${key}\" already has a live runtime.`,\n );\n }\n\n this.pendingNamespacedKeys.add(key);\n const diagnostics = createRuntimeDiagnostics();\n let runtimeId = key;\n const browserSource = createBrowserSourceFromBindings(options.bindings.browser);\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n {\n nestedHost: this.createNestedBindings(browserSource),\n },\n );\n\n try {\n const runtime = await this.createRemoteRuntime(\n {\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n testEnvironment: true,\n },\n key,\n );\n runtimeId = runtime.id;\n\n let adapter: ReturnType<typeof createNamespacedRuntimeAdapter>;\n adapter = createNamespacedRuntimeAdapter(runtime, diagnostics, {\n hasBrowser: Boolean(options.bindings.browser),\n abortBindings: (reason) => bindingsAdapter.abort(reason),\n onRelease: () => {\n if (this.namespacedRuntimes.get(key) === adapter) {\n this.namespacedRuntimes.delete(key);\n }\n },\n });\n\n this.namespacedRuntimes.set(key, adapter);\n this.runtimes.add(adapter);\n return adapter;\n } catch (error) {\n throw normalizeNamespaceInUseError(error, key);\n } finally {\n this.pendingNamespacedKeys.delete(key);\n }\n }\n\n private async createAppServerInternal(\n options: CreateAppServerOptions,\n ): Promise<AppServer> {\n const server = await createAppServerAdapter(\n () => this.getConnection(),\n options,\n {\n nestedHost: this.createNestedBindings(\n createBrowserSourceFromBindings(options.bindings.browser),\n ),\n },\n );\n this.servers.add(server);\n return server;\n }\n\n private createNestedBindings(\n defaultBrowserSource: BrowserSource | undefined,\n ) {\n return createNestedHostBindings(\n {\n createRuntime: async (options) => await this.createRuntimeInternal(options),\n createAppServer: async (options) =>\n await this.createAppServerInternal(options),\n createTestRuntime: async (options) =>\n await this.createTestRuntimeInternal(options),\n getNamespacedRuntime: async (key, options) =>\n await this.createNamespacedRuntimeInternal(key, options),\n disposeNamespace: async (key, options) =>\n await this.disposeNamespace(key, options),\n isConnected: () => this.connection?.isConnected() ?? false,\n },\n defaultBrowserSource,\n );\n }\n\n private async createRemoteRuntime(options: RuntimeOptions, key?: string): Promise<RemoteRuntime> {\n const connection = await this.getConnection();\n if (key) {\n return await connection.createNamespace(key).createRuntime(options);\n }\n return await connection.createRuntime(options);\n }\n\n private async getConnection(): Promise<DaemonConnection> {\n if (this.connection?.isConnected()) {\n return this.connection;\n }\n if (this.connectionPromise) {\n return this.connectionPromise;\n }\n\n this.connectionPromise = (async () => {\n await this.ensureDaemon();\n this.connection = await connect({\n socket: this.options.daemon?.socketPath ?? \"/tmp/isolate.sock\",\n timeout: this.options.daemon?.timeoutMs ?? 5000,\n });\n return this.connection;\n })();\n\n return await this.connectionPromise.finally(() => {\n this.connectionPromise = null;\n });\n }\n\n private async ensureDaemon(): Promise<void> {\n if (this.connection?.isConnected()) {\n return;\n }\n\n if (this.options.daemon?.autoStart === false) {\n return;\n }\n\n if (this.daemonProcess) {\n return;\n }\n\n const socketPath = this.options.daemon?.socketPath ?? \"/tmp/isolate.sock\";\n const entrypoint = this.options.daemon?.entrypoint ?? resolveDefaultDaemonEntrypoint();\n\n try {\n if (fs.existsSync(socketPath)) {\n fs.unlinkSync(socketPath);\n }\n } catch {\n // ignore stale socket cleanup failures\n }\n\n const cli = entrypoint\n ? [\"node\", \"--experimental-strip-types\", entrypoint, \"--socket\", socketPath]\n : [\"isolate-daemon\", \"--socket\", socketPath];\n const cwd = this.options.daemon?.cwd ?? (entrypoint ? path.resolve(import.meta.dirname, \"../..\") : process.cwd());\n this.daemonProcess = spawn(cli[0]!, cli.slice(1), {\n cwd,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n env: {\n ...process.env,\n NODE_OPTIONS: \"\",\n },\n });\n\n this.daemonProcess.stdout?.on(\"data\", (data: Buffer) => {\n console.log(\"[isolate-host]\", data.toString().trim());\n });\n this.daemonProcess.stderr?.on(\"data\", (data: Buffer) => {\n console.error(\"[isolate-host]\", data.toString().trim());\n });\n this.daemonProcess.on(\"exit\", () => {\n this.daemonProcess = null;\n this.connection = null;\n this.connectionPromise = null;\n });\n\n await waitForSocket(socketPath, this.options.daemon?.timeoutMs ?? 10_000);\n }\n}\n\nexport async function createIsolateHost(options?: CreateIsolateHostOptions): Promise<IsolateHost> {\n return new HostImpl(options);\n}\n"
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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AAS,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
  }
@@ -95,7 +95,7 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
95
95
  host.runtimeIds.delete(resourceId);
96
96
  }
97
97
  }
98
- if (record.kind === "runtime" || record.kind === "namespacedRuntime") {
98
+ if (record.kind === "runtime" || record.kind === "testRuntime" || record.kind === "namespacedRuntime") {
99
99
  for (const unsubscribe of record.subscriptions.values()) {
100
100
  unsubscribe();
101
101
  }
@@ -182,7 +182,8 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
182
182
  resources.set(resourceId, {
183
183
  kind,
184
184
  hostId,
185
- resource
185
+ resource,
186
+ subscriptions: new Map
186
187
  });
187
188
  host.runtimeIds.add(resourceId);
188
189
  return resourceId;
@@ -270,7 +271,8 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
270
271
  }
271
272
  }
272
273
  case "testRuntime": {
273
- const runtime = record.resource;
274
+ const runtimeRecord = record;
275
+ const runtime = runtimeRecord.resource;
274
276
  switch (method) {
275
277
  case "run":
276
278
  return await runtime.run(args[0], args[1] ?? undefined);
@@ -279,6 +281,21 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
279
281
  return;
280
282
  case "diagnostics":
281
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
+ }
282
299
  default:
283
300
  throw new Error(`Unsupported nested test runtime method: ${method}`);
284
301
  }
@@ -296,6 +313,21 @@ function createNestedHostBindings(factory, defaultBrowserSource) {
296
313
  return;
297
314
  case "diagnostics":
298
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
+ }
299
331
  case "events.on": {
300
332
  const subscriptionId = randomUUID();
301
333
  const unsubscribe = runtimeRecord.resource.events.on(args[0], args[1]);
@@ -330,4 +362,4 @@ export {
330
362
  createNestedHostBindings
331
363
  };
332
364
 
333
- //# debugId=D247008EEEB47EC864756E2164756E21
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 CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostBindings,\n HostCallContext,\n NamespacedRuntime,\n RequestResult,\n ScriptRuntime,\n TestRuntime,\n} from \"../types.mjs\";\n\ninterface NestedHostFactory {\n createRuntime(options: CreateRuntimeOptions): Promise<ScriptRuntime>;\n createAppServer(options: CreateAppServerOptions): Promise<AppServer>;\n createTestRuntime(options: CreateTestRuntimeOptions): Promise<TestRuntime>;\n getNamespacedRuntime(\n key: string,\n options: CreateNamespacedRuntimeOptions,\n ): Promise<NamespacedRuntime>;\n disposeNamespace(key: string, options?: { reason?: string }): Promise<void>;\n isConnected(): boolean;\n}\n\ninterface NestedHostRecord {\n runtimeIds: Set<string>;\n serverIds: Set<string>;\n closed: boolean;\n}\n\ninterface RuntimeResourceRecord {\n kind: \"runtime\";\n hostId: string;\n resource: ScriptRuntime;\n subscriptions: Map<string, () => void>;\n}\n\ninterface AppServerResourceRecord {\n kind: \"appServer\";\n hostId: string;\n resource: AppServer;\n}\n\ninterface TestRuntimeResourceRecord {\n kind: \"testRuntime\";\n hostId: string;\n resource: TestRuntime;\n}\n\ninterface NamespacedRuntimeResourceRecord {\n kind: \"namespacedRuntime\";\n hostId: string;\n resource: NamespacedRuntime;\n subscriptions: Map<string, () => void>;\n}\n\ntype NestedResourceRecord =\n | RuntimeResourceRecord\n | AppServerResourceRecord\n | TestRuntimeResourceRecord\n | NamespacedRuntimeResourceRecord;\n\ninterface SerializedRequestLike {\n url: string;\n method?: string;\n headers?: Array<[string, string]>;\n body?: number[] | null;\n}\n\nfunction toRequest(serialized: SerializedRequestLike): Request {\n return new Request(serialized.url, {\n method: serialized.method ?? \"GET\",\n headers: serialized.headers,\n body: serialized.body ? new Uint8Array(serialized.body) : null,\n });\n}\n\nfunction normalizeBindings(\n bindings: HostBindings | undefined,\n defaultBrowserSource: BrowserSource | undefined,\n): HostBindings {\n const normalized: HostBindings = {\n console: bindings?.console,\n fetch: bindings?.fetch,\n files: bindings?.files,\n modules: bindings?.modules,\n tools: bindings?.tools,\n };\n\n if (!bindings || !(\"browser\" in bindings) || bindings.browser === undefined) {\n return normalized;\n }\n\n if (isDefaultBrowserDescriptor(bindings.browser)) {\n normalized.browser = requireBrowserSource(\n defaultBrowserSource,\n \"Nested browser bindings\",\n );\n return normalized;\n }\n\n const browserSource = createBrowserSourceFromUnknown(bindings.browser);\n if (!browserSource) {\n throw new Error(\n \"Nested browser bindings must use the sandbox browser handle, a Playwright handler, or expose createContext()/createPage().\",\n );\n }\n\n normalized.browser = browserSource;\n return normalized;\n}\n\nfunction normalizeRuntimeOptions(\n options: CreateRuntimeOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateRuntimeOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction normalizeAppServerOptions(\n options: CreateAppServerOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateAppServerOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction normalizeNamespacedRuntimeOptions(\n options: CreateNamespacedRuntimeOptions,\n defaultBrowserSource: BrowserSource | undefined,\n): CreateNamespacedRuntimeOptions {\n return {\n ...options,\n bindings: normalizeBindings(options.bindings, defaultBrowserSource),\n };\n}\n\nfunction toError(value: unknown): Error {\n if (value instanceof Error) {\n return value;\n }\n\n if (\n value &&\n typeof value === \"object\" &&\n \"message\" in value &&\n typeof (value as { message?: unknown }).message === \"string\"\n ) {\n const error = new Error((value as { message: string }).message);\n if (\n \"name\" in value &&\n typeof (value as { name?: unknown }).name === \"string\"\n ) {\n error.name = (value as { name: string }).name;\n }\n return error;\n }\n\n return new Error(String(value));\n}\n\nexport function createNestedHostBindings(\n factory: NestedHostFactory,\n defaultBrowserSource: BrowserSource | undefined,\n): NestedHostBindings {\n const hosts = new Map<string, NestedHostRecord>();\n const resources = new Map<string, NestedResourceRecord>();\n\n const requireHost = (hostId: string): NestedHostRecord => {\n const host = hosts.get(hostId);\n if (!host || host.closed) {\n throw new Error(`Nested host ${hostId} is not available.`);\n }\n return host;\n };\n\n const requireResource = (\n resourceId: string,\n expectedKind: NestedResourceKind,\n ): NestedResourceRecord => {\n const resource = resources.get(resourceId);\n if (!resource || resource.kind !== expectedKind) {\n throw new Error(\n `Nested resource ${resourceId} is not available for ${expectedKind}.`,\n );\n }\n return resource;\n };\n\n const unregisterResource = (resourceId: string): void => {\n const record = resources.get(resourceId);\n if (!record) {\n return;\n }\n\n const host = hosts.get(record.hostId);\n if (host) {\n if (record.kind === \"appServer\") {\n host.serverIds.delete(resourceId);\n } else {\n host.runtimeIds.delete(resourceId);\n }\n }\n\n if (record.kind === \"runtime\" || record.kind === \"namespacedRuntime\") {\n for (const unsubscribe of record.subscriptions.values()) {\n unsubscribe();\n }\n record.subscriptions.clear();\n }\n\n resources.delete(resourceId);\n };\n\n const disposeResource = async (\n resourceId: string,\n options: { hard?: boolean; reason?: string },\n ): Promise<void> => {\n const record = resources.get(resourceId);\n if (!record) {\n return;\n }\n\n try {\n await record.resource.dispose(options);\n } finally {\n unregisterResource(resourceId);\n }\n };\n\n return {\n async createHost() {\n const hostId = randomUUID();\n hosts.set(hostId, {\n runtimeIds: new Set(),\n serverIds: new Set(),\n closed: false,\n });\n return hostId;\n },\n async closeHost(hostId) {\n const host = requireHost(hostId);\n host.closed = true;\n const resourceIds = [\n ...host.serverIds,\n ...host.runtimeIds,\n ];\n await Promise.allSettled(\n resourceIds.map(async (resourceId) => {\n await disposeResource(resourceId, {\n hard: true,\n reason: \"Nested isolate host closed\",\n });\n }),\n );\n hosts.delete(hostId);\n },\n async diagnostics(hostId) {\n const host = requireHost(hostId);\n return {\n runtimes: host.runtimeIds.size,\n servers: host.serverIds.size,\n connected: factory.isConnected(),\n };\n },\n async createResource(hostId, kind, rawOptions) {\n const host = requireHost(hostId);\n switch (kind) {\n case \"runtime\": {\n const options = normalizeRuntimeOptions(\n rawOptions as CreateRuntimeOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createRuntime(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n subscriptions: new Map(),\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n\n case \"appServer\": {\n const options = normalizeAppServerOptions(\n rawOptions as CreateAppServerOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createAppServer(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n });\n host.serverIds.add(resourceId);\n return resourceId;\n }\n\n case \"testRuntime\": {\n const options = normalizeRuntimeOptions(\n rawOptions as CreateTestRuntimeOptions,\n defaultBrowserSource,\n );\n const resource = await factory.createTestRuntime(options);\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n\n case \"namespacedRuntime\": {\n const namespacedOptions = rawOptions as {\n key: string;\n options: CreateNamespacedRuntimeOptions;\n };\n const resource = await factory.getNamespacedRuntime(\n namespacedOptions.key,\n normalizeNamespacedRuntimeOptions(\n namespacedOptions.options,\n defaultBrowserSource,\n ),\n );\n const resourceId = randomUUID();\n resources.set(resourceId, {\n kind,\n hostId,\n resource,\n subscriptions: new Map(),\n });\n host.runtimeIds.add(resourceId);\n return resourceId;\n }\n }\n },\n async callResource(kind, resourceId, method, args) {\n const record = requireResource(resourceId, kind);\n\n switch (kind) {\n case \"runtime\": {\n const runtimeRecord = record as RuntimeResourceRecord;\n switch (method) {\n case \"eval\":\n await runtimeRecord.resource.eval(\n args[0] as string,\n (args[1] as string | { filename?: string; executionTimeout?: number } | null) ??\n undefined,\n );\n return undefined;\n case \"dispose\":\n await disposeResource(resourceId, (args[0] as { hard?: boolean; reason?: string } | null) ?? {});\n return undefined;\n case \"diagnostics\":\n return await runtimeRecord.resource.diagnostics();\n case \"events.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtimeRecord.resource.events.on(\n args[0] as string,\n args[1] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"events.off\": {\n const subscriptionId = args[0] as string;\n const unsubscribe = runtimeRecord.subscriptions.get(subscriptionId);\n if (unsubscribe) {\n unsubscribe();\n runtimeRecord.subscriptions.delete(subscriptionId);\n }\n return undefined;\n }\n case \"events.emit\":\n await runtimeRecord.resource.events.emit(\n args[0] as string,\n args[1],\n );\n return undefined;\n default:\n throw new Error(`Unsupported nested runtime method: ${method}`);\n }\n }\n\n case \"appServer\": {\n const server = (record as AppServerResourceRecord).resource;\n switch (method) {\n case \"handle\": {\n const result = await server.handle(\n toRequest(args[0] as SerializedRequestLike),\n ((args[1] as {\n requestId?: string;\n metadata?: Record<string, string>;\n } | null) ?? undefined),\n );\n return result;\n }\n case \"ws.open\":\n await server.ws.open(args[0] as string);\n return undefined;\n case \"ws.message\":\n await server.ws.message(\n args[0] as string,\n args[1] as string | ArrayBuffer,\n );\n return undefined;\n case \"ws.close\":\n await server.ws.close(\n args[0] as string,\n args[1] as number,\n args[2] as string,\n );\n return undefined;\n case \"ws.error\":\n await server.ws.error(\n args[0] as string,\n toError(args[1]),\n );\n return undefined;\n case \"reload\":\n await server.reload((args[0] as string | null) ?? undefined);\n return undefined;\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await server.diagnostics();\n default:\n throw new Error(`Unsupported nested app server method: ${method}`);\n }\n }\n\n case \"testRuntime\": {\n const runtime = (record as TestRuntimeResourceRecord).resource;\n switch (method) {\n case \"run\":\n return await runtime.run(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n timeoutMs?: number;\n } | null) ?? undefined),\n );\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await runtime.diagnostics();\n default:\n throw new Error(\n `Unsupported nested test runtime method: ${method}`,\n );\n }\n }\n\n case \"namespacedRuntime\": {\n const runtimeRecord = record as NamespacedRuntimeResourceRecord;\n switch (method) {\n case \"eval\":\n await runtimeRecord.resource.eval(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n executionTimeout?: number;\n } | null) ?? undefined),\n );\n return undefined;\n case \"runTests\":\n return await runtimeRecord.resource.runTests(\n args[0] as string,\n ((args[1] as {\n filename?: string;\n timeoutMs?: number;\n } | null) ?? undefined),\n );\n case \"dispose\":\n await disposeResource(\n resourceId,\n ((args[0] as { hard?: boolean; reason?: string } | null) ?? {}),\n );\n return undefined;\n case \"diagnostics\":\n return await runtimeRecord.resource.diagnostics();\n case \"events.on\": {\n const subscriptionId = randomUUID();\n const unsubscribe = runtimeRecord.resource.events.on(\n args[0] as string,\n args[1] as (payload: unknown) => void,\n );\n runtimeRecord.subscriptions.set(subscriptionId, unsubscribe);\n return subscriptionId;\n }\n case \"events.off\": {\n const subscriptionId = args[0] as string;\n const unsubscribe =\n runtimeRecord.subscriptions.get(subscriptionId);\n if (unsubscribe) {\n unsubscribe();\n runtimeRecord.subscriptions.delete(subscriptionId);\n }\n return undefined;\n }\n case \"events.emit\":\n await runtimeRecord.resource.events.emit(\n args[0] as string,\n args[1],\n );\n return undefined;\n default:\n throw new Error(\n `Unsupported nested namespaced runtime method: ${method}`,\n );\n }\n }\n }\n },\n async disposeNamespace(hostId, key, options) {\n requireHost(hostId);\n await factory.disposeNamespace(key, options);\n },\n };\n}\n"
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;AA6EA,SAAS,SAAS,CAAC,YAA4C;AAAA,EAC7D,OAAO,IAAI,QAAQ,WAAW,KAAK;AAAA,IACjC,QAAQ,WAAW,UAAU;AAAA,IAC7B,SAAS,WAAW;AAAA,IACpB,MAAM,WAAW,OAAO,IAAI,WAAW,WAAW,IAAI,IAAI;AAAA,EAC5D,CAAC;AAAA;AAGH,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;AAAA;AAGT,SAAS,uBAAuB,CAC9B,SACA,sBACsB;AAAA,EACtB,OAAO;AAAA,OACF;AAAA,IACH,UAAU,kBAAkB,QAAQ,UAAU,oBAAoB;AAAA,EACpE;AAAA;AAGF,SAAS,yBAAyB,CAChC,SACA,sBACwB;AAAA,EACx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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
  }
@@ -165,7 +165,7 @@ async function connect(options = {}) {
165
165
  testEnvCallbacks.onEvent = {
166
166
  callbackId: onEventCallbackId,
167
167
  name: "testEnvironment.onEvent",
168
- type: "sync"
168
+ type: "async"
169
169
  };
170
170
  }
171
171
  testEnvironmentOption = {
@@ -699,7 +699,7 @@ async function createRuntime(state, options = {}, namespaceId) {
699
699
  testEnvCallbacks.onEvent = {
700
700
  callbackId: onEventCallbackId,
701
701
  name: "testEnvironment.onEvent",
702
- type: "sync"
702
+ type: "async"
703
703
  };
704
704
  }
705
705
  testEnvironmentOption = {
@@ -1129,8 +1129,8 @@ async function createRuntime(state, options = {}, namespaceId) {
1129
1129
  }
1130
1130
  function registerEventCallback(state, handler) {
1131
1131
  const callbackId = state.nextCallbackId++;
1132
- state.callbacks.set(callbackId, (data) => {
1133
- handler(data);
1132
+ state.callbacks.set(callbackId, async (data) => {
1133
+ await handler(data);
1134
1134
  return;
1135
1135
  });
1136
1136
  return callbackId;
@@ -1139,10 +1139,10 @@ function registerConsoleCallbacks(state, callbacks) {
1139
1139
  const registrations = {};
1140
1140
  if (callbacks.onEntry) {
1141
1141
  const callbackId = state.nextCallbackId++;
1142
- state.callbacks.set(callbackId, (entry) => {
1143
- callbacks.onEntry(entry);
1142
+ state.callbacks.set(callbackId, async (entry) => {
1143
+ await callbacks.onEntry(entry);
1144
1144
  });
1145
- registrations.onEntry = { callbackId, name: "onEntry", type: "sync" };
1145
+ registrations.onEntry = { callbackId, name: "onEntry", type: "async" };
1146
1146
  }
1147
1147
  return registrations;
1148
1148
  }
@@ -1440,7 +1440,7 @@ function registerCustomFunctions(state, customFunctions) {
1440
1440
  registerCallback: (fn) => {
1441
1441
  const returnedCallbackId = state.nextCallbackId++;
1442
1442
  state.callbacks.set(returnedCallbackId, async (...args) => {
1443
- const fnResult = await fn(...args);
1443
+ const fnResult = fn(...args);
1444
1444
  const marshalledResult = await marshalValue(fnResult, marshalCtx);
1445
1445
  return addCallbackIdsToRefs(marshalledResult);
1446
1446
  });
@@ -1914,4 +1914,4 @@ export {
1914
1914
  connect
1915
1915
  };
1916
1916
 
1917
- //# debugId=C25497E94950531064756E2164756E21
1917
+ //# debugId=5E7F07BECF47B02E64756E2164756E21