@ricsam/isolate 0.0.1 → 0.1.0

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 (299) hide show
  1. package/dist/cjs/bridge/diagnostics.cjs +58 -0
  2. package/dist/cjs/bridge/diagnostics.cjs.map +10 -0
  3. package/dist/cjs/bridge/legacy-adapters.cjs +242 -0
  4. package/dist/cjs/bridge/legacy-adapters.cjs.map +10 -0
  5. package/dist/cjs/bridge/request-context.cjs +59 -0
  6. package/dist/cjs/bridge/request-context.cjs.map +10 -0
  7. package/dist/cjs/bridge/runtime-bindings.cjs +367 -0
  8. package/dist/cjs/bridge/runtime-bindings.cjs.map +10 -0
  9. package/dist/cjs/browser/browser-runtime.cjs +157 -0
  10. package/dist/cjs/browser/browser-runtime.cjs.map +10 -0
  11. package/dist/cjs/daemon.cjs +91 -0
  12. package/dist/cjs/daemon.cjs.map +10 -0
  13. package/dist/cjs/files/index.cjs +140 -0
  14. package/dist/cjs/files/index.cjs.map +10 -0
  15. package/dist/cjs/host/create-isolate-host.cjs +235 -0
  16. package/dist/cjs/host/create-isolate-host.cjs.map +10 -0
  17. package/dist/cjs/host/index.cjs +47 -0
  18. package/dist/cjs/host/index.cjs.map +10 -0
  19. package/dist/cjs/index.cjs +55 -0
  20. package/dist/cjs/index.cjs.map +10 -0
  21. package/dist/cjs/internal/client/connection.cjs +1919 -0
  22. package/dist/cjs/internal/client/connection.cjs.map +10 -0
  23. package/dist/cjs/internal/client/index.cjs +48 -0
  24. package/dist/cjs/internal/client/index.cjs.map +10 -0
  25. package/dist/cjs/internal/client/types.cjs +30 -0
  26. package/dist/cjs/internal/client/types.cjs.map +9 -0
  27. package/dist/cjs/internal/console/index.cjs +506 -0
  28. package/dist/cjs/internal/console/index.cjs.map +10 -0
  29. package/dist/cjs/internal/console/utils.cjs +70 -0
  30. package/dist/cjs/internal/console/utils.cjs.map +10 -0
  31. package/dist/cjs/internal/core/index.cjs +2745 -0
  32. package/dist/cjs/internal/core/index.cjs.map +10 -0
  33. package/dist/cjs/internal/crypto/index.cjs +470 -0
  34. package/dist/cjs/internal/crypto/index.cjs.map +10 -0
  35. package/dist/cjs/internal/daemon/callback-fs-handler.cjs +355 -0
  36. package/dist/cjs/internal/daemon/callback-fs-handler.cjs.map +10 -0
  37. package/dist/cjs/internal/daemon/connection.cjs +1952 -0
  38. package/dist/cjs/internal/daemon/connection.cjs.map +10 -0
  39. package/dist/cjs/internal/daemon/daemon.cjs +98 -0
  40. package/dist/cjs/internal/daemon/daemon.cjs.map +10 -0
  41. package/dist/cjs/internal/daemon/index.cjs +145 -0
  42. package/dist/cjs/internal/daemon/index.cjs.map +10 -0
  43. package/dist/cjs/internal/daemon/runtime-pool.cjs +106 -0
  44. package/dist/cjs/internal/daemon/runtime-pool.cjs.map +10 -0
  45. package/dist/cjs/internal/daemon/types.cjs +30 -0
  46. package/dist/cjs/internal/daemon/types.cjs.map +9 -0
  47. package/dist/cjs/internal/encoding/index.cjs +419 -0
  48. package/dist/cjs/internal/encoding/index.cjs.map +10 -0
  49. package/dist/cjs/internal/fetch/consistency/origins.cjs +598 -0
  50. package/dist/cjs/internal/fetch/consistency/origins.cjs.map +10 -0
  51. package/dist/cjs/internal/fetch/index.cjs +2640 -0
  52. package/dist/cjs/internal/fetch/index.cjs.map +10 -0
  53. package/dist/cjs/internal/fetch/stream-state.cjs +256 -0
  54. package/dist/cjs/internal/fetch/stream-state.cjs.map +10 -0
  55. package/dist/cjs/internal/fs/index.cjs +847 -0
  56. package/dist/cjs/internal/fs/index.cjs.map +10 -0
  57. package/dist/cjs/internal/fs/node-adapter.cjs +254 -0
  58. package/dist/cjs/internal/fs/node-adapter.cjs.map +10 -0
  59. package/dist/cjs/internal/module-loader/bundle.cjs +482 -0
  60. package/dist/cjs/internal/module-loader/bundle.cjs.map +10 -0
  61. package/dist/cjs/internal/module-loader/index.cjs +240 -0
  62. package/dist/cjs/internal/module-loader/index.cjs.map +10 -0
  63. package/dist/cjs/internal/module-loader/mappings.cjs +120 -0
  64. package/dist/cjs/internal/module-loader/mappings.cjs.map +10 -0
  65. package/dist/cjs/internal/module-loader/resolve.cjs +177 -0
  66. package/dist/cjs/internal/module-loader/resolve.cjs.map +10 -0
  67. package/dist/cjs/internal/module-loader/strip-types.cjs +236 -0
  68. package/dist/cjs/internal/module-loader/strip-types.cjs.map +10 -0
  69. package/dist/cjs/internal/path/index.cjs +503 -0
  70. package/dist/cjs/internal/path/index.cjs.map +10 -0
  71. package/dist/cjs/internal/playwright/client.cjs +49 -0
  72. package/dist/cjs/internal/playwright/client.cjs.map +10 -0
  73. package/dist/cjs/internal/playwright/handler.cjs +1416 -0
  74. package/dist/cjs/internal/playwright/handler.cjs.map +10 -0
  75. package/dist/cjs/internal/playwright/index.cjs +1289 -0
  76. package/dist/cjs/internal/playwright/index.cjs.map +10 -0
  77. package/dist/cjs/internal/playwright/types.cjs +47 -0
  78. package/dist/cjs/internal/playwright/types.cjs.map +10 -0
  79. package/dist/cjs/internal/protocol/codec.cjs +510 -0
  80. package/dist/cjs/internal/protocol/codec.cjs.map +10 -0
  81. package/dist/cjs/internal/protocol/framing.cjs +141 -0
  82. package/dist/cjs/internal/protocol/framing.cjs.map +10 -0
  83. package/dist/cjs/internal/protocol/index.cjs +110 -0
  84. package/dist/cjs/internal/protocol/index.cjs.map +10 -0
  85. package/dist/cjs/internal/protocol/marshalValue.cjs +518 -0
  86. package/dist/cjs/internal/protocol/marshalValue.cjs.map +10 -0
  87. package/dist/cjs/internal/protocol/serialization.cjs +109 -0
  88. package/dist/cjs/internal/protocol/serialization.cjs.map +10 -0
  89. package/dist/cjs/internal/protocol/types.cjs +181 -0
  90. package/dist/cjs/internal/protocol/types.cjs.map +10 -0
  91. package/dist/cjs/internal/runtime/index.cjs +1235 -0
  92. package/dist/cjs/internal/runtime/index.cjs.map +10 -0
  93. package/dist/cjs/internal/server/index.cjs +223 -0
  94. package/dist/cjs/internal/server/index.cjs.map +10 -0
  95. package/dist/cjs/internal/test-environment/index.cjs +1415 -0
  96. package/dist/cjs/internal/test-environment/index.cjs.map +10 -0
  97. package/dist/cjs/internal/timers/index.cjs +200 -0
  98. package/dist/cjs/internal/timers/index.cjs.map +10 -0
  99. package/dist/cjs/internal/transform/index.cjs +361 -0
  100. package/dist/cjs/internal/transform/index.cjs.map +10 -0
  101. package/dist/cjs/internal/typecheck/index.cjs +60 -0
  102. package/dist/cjs/internal/typecheck/index.cjs.map +10 -0
  103. package/dist/cjs/internal/typecheck/isolate-types.cjs +2614 -0
  104. package/dist/cjs/internal/typecheck/isolate-types.cjs.map +10 -0
  105. package/dist/cjs/internal/typecheck/typecheck.cjs +131 -0
  106. package/dist/cjs/internal/typecheck/typecheck.cjs.map +10 -0
  107. package/dist/cjs/modules/index.cjs +160 -0
  108. package/dist/cjs/modules/index.cjs.map +10 -0
  109. package/dist/cjs/package.json +5 -0
  110. package/dist/cjs/runtime/script-runtime.cjs +97 -0
  111. package/dist/cjs/runtime/script-runtime.cjs.map +10 -0
  112. package/dist/cjs/server/app-server.cjs +158 -0
  113. package/dist/cjs/server/app-server.cjs.map +10 -0
  114. package/dist/cjs/testing/integration-helpers.cjs +127 -0
  115. package/dist/cjs/testing/integration-helpers.cjs.map +10 -0
  116. package/dist/cjs/typecheck/index.cjs +96 -0
  117. package/dist/cjs/typecheck/index.cjs.map +10 -0
  118. package/dist/cjs/types.cjs +30 -0
  119. package/dist/cjs/types.cjs.map +9 -0
  120. package/dist/mjs/bridge/diagnostics.mjs +18 -0
  121. package/dist/mjs/bridge/diagnostics.mjs.map +10 -0
  122. package/dist/mjs/bridge/legacy-adapters.mjs +178 -0
  123. package/dist/mjs/bridge/legacy-adapters.mjs.map +10 -0
  124. package/dist/mjs/bridge/request-context.mjs +19 -0
  125. package/dist/mjs/bridge/request-context.mjs.map +10 -0
  126. package/dist/mjs/bridge/runtime-bindings.mjs +303 -0
  127. package/dist/mjs/bridge/runtime-bindings.mjs.map +10 -0
  128. package/dist/mjs/browser/browser-runtime.mjs +93 -0
  129. package/dist/mjs/browser/browser-runtime.mjs.map +10 -0
  130. package/dist/mjs/daemon.mjs +91 -0
  131. package/dist/mjs/daemon.mjs.map +10 -0
  132. package/dist/mjs/files/index.mjs +76 -0
  133. package/dist/mjs/files/index.mjs.map +10 -0
  134. package/dist/mjs/host/create-isolate-host.mjs +171 -0
  135. package/dist/mjs/host/create-isolate-host.mjs.map +10 -0
  136. package/dist/mjs/host/index.mjs +7 -0
  137. package/dist/mjs/host/index.mjs.map +10 -0
  138. package/dist/mjs/index.mjs +15 -0
  139. package/dist/mjs/index.mjs.map +10 -0
  140. package/dist/mjs/internal/client/connection.mjs +1872 -0
  141. package/dist/mjs/internal/client/connection.mjs.map +10 -0
  142. package/dist/mjs/internal/client/index.mjs +8 -0
  143. package/dist/mjs/internal/client/index.mjs.map +10 -0
  144. package/dist/mjs/internal/client/types.mjs +2 -0
  145. package/dist/mjs/internal/client/types.mjs.map +9 -0
  146. package/dist/mjs/internal/console/index.mjs +442 -0
  147. package/dist/mjs/internal/console/index.mjs.map +10 -0
  148. package/dist/mjs/internal/console/utils.mjs +30 -0
  149. package/dist/mjs/internal/console/utils.mjs.map +10 -0
  150. package/dist/mjs/internal/core/index.mjs +2681 -0
  151. package/dist/mjs/internal/core/index.mjs.map +10 -0
  152. package/dist/mjs/internal/crypto/index.mjs +406 -0
  153. package/dist/mjs/internal/crypto/index.mjs.map +10 -0
  154. package/dist/mjs/internal/daemon/callback-fs-handler.mjs +315 -0
  155. package/dist/mjs/internal/daemon/callback-fs-handler.mjs.map +10 -0
  156. package/dist/mjs/internal/daemon/connection.mjs +1931 -0
  157. package/dist/mjs/internal/daemon/connection.mjs.map +10 -0
  158. package/dist/mjs/internal/daemon/daemon.mjs +98 -0
  159. package/dist/mjs/internal/daemon/daemon.mjs.map +10 -0
  160. package/dist/mjs/internal/daemon/index.mjs +105 -0
  161. package/dist/mjs/internal/daemon/index.mjs.map +10 -0
  162. package/dist/mjs/internal/daemon/runtime-pool.mjs +66 -0
  163. package/dist/mjs/internal/daemon/runtime-pool.mjs.map +10 -0
  164. package/dist/mjs/internal/daemon/types.mjs +2 -0
  165. package/dist/mjs/internal/daemon/types.mjs.map +9 -0
  166. package/dist/mjs/internal/encoding/index.mjs +379 -0
  167. package/dist/mjs/internal/encoding/index.mjs.map +10 -0
  168. package/dist/mjs/internal/fetch/consistency/origins.mjs +558 -0
  169. package/dist/mjs/internal/fetch/consistency/origins.mjs.map +10 -0
  170. package/dist/mjs/internal/fetch/index.mjs +2580 -0
  171. package/dist/mjs/internal/fetch/index.mjs.map +10 -0
  172. package/dist/mjs/internal/fetch/stream-state.mjs +216 -0
  173. package/dist/mjs/internal/fetch/stream-state.mjs.map +10 -0
  174. package/dist/mjs/internal/fs/index.mjs +783 -0
  175. package/dist/mjs/internal/fs/index.mjs.map +10 -0
  176. package/dist/mjs/internal/fs/node-adapter.mjs +190 -0
  177. package/dist/mjs/internal/fs/node-adapter.mjs.map +10 -0
  178. package/dist/mjs/internal/module-loader/bundle.mjs +418 -0
  179. package/dist/mjs/internal/module-loader/bundle.mjs.map +10 -0
  180. package/dist/mjs/internal/module-loader/index.mjs +185 -0
  181. package/dist/mjs/internal/module-loader/index.mjs.map +10 -0
  182. package/dist/mjs/internal/module-loader/mappings.mjs +80 -0
  183. package/dist/mjs/internal/module-loader/mappings.mjs.map +10 -0
  184. package/dist/mjs/internal/module-loader/resolve.mjs +113 -0
  185. package/dist/mjs/internal/module-loader/resolve.mjs.map +10 -0
  186. package/dist/mjs/internal/module-loader/strip-types.mjs +172 -0
  187. package/dist/mjs/internal/module-loader/strip-types.mjs.map +10 -0
  188. package/dist/mjs/internal/path/index.mjs +463 -0
  189. package/dist/mjs/internal/path/index.mjs.map +10 -0
  190. package/dist/mjs/internal/playwright/client.mjs +13 -0
  191. package/dist/mjs/internal/playwright/client.mjs.map +10 -0
  192. package/dist/mjs/internal/playwright/handler.mjs +1378 -0
  193. package/dist/mjs/internal/playwright/handler.mjs.map +10 -0
  194. package/dist/mjs/internal/playwright/index.mjs +1234 -0
  195. package/dist/mjs/internal/playwright/index.mjs.map +10 -0
  196. package/dist/mjs/internal/playwright/types.mjs +7 -0
  197. package/dist/mjs/internal/playwright/types.mjs.map +10 -0
  198. package/dist/mjs/internal/protocol/codec.mjs +470 -0
  199. package/dist/mjs/internal/protocol/codec.mjs.map +10 -0
  200. package/dist/mjs/internal/protocol/framing.mjs +101 -0
  201. package/dist/mjs/internal/protocol/framing.mjs.map +10 -0
  202. package/dist/mjs/internal/protocol/index.mjs +98 -0
  203. package/dist/mjs/internal/protocol/index.mjs.map +10 -0
  204. package/dist/mjs/internal/protocol/marshalValue.mjs +494 -0
  205. package/dist/mjs/internal/protocol/marshalValue.mjs.map +10 -0
  206. package/dist/mjs/internal/protocol/serialization.mjs +69 -0
  207. package/dist/mjs/internal/protocol/serialization.mjs.map +10 -0
  208. package/dist/mjs/internal/protocol/types.mjs +141 -0
  209. package/dist/mjs/internal/protocol/types.mjs.map +10 -0
  210. package/dist/mjs/internal/runtime/index.mjs +1198 -0
  211. package/dist/mjs/internal/runtime/index.mjs.map +10 -0
  212. package/dist/mjs/internal/server/index.mjs +183 -0
  213. package/dist/mjs/internal/server/index.mjs.map +10 -0
  214. package/dist/mjs/internal/test-environment/index.mjs +1351 -0
  215. package/dist/mjs/internal/test-environment/index.mjs.map +10 -0
  216. package/dist/mjs/internal/timers/index.mjs +136 -0
  217. package/dist/mjs/internal/timers/index.mjs.map +10 -0
  218. package/dist/mjs/internal/transform/index.mjs +321 -0
  219. package/dist/mjs/internal/transform/index.mjs.map +10 -0
  220. package/dist/mjs/internal/typecheck/index.mjs +35 -0
  221. package/dist/mjs/internal/typecheck/index.mjs.map +10 -0
  222. package/dist/mjs/internal/typecheck/isolate-types.mjs +2574 -0
  223. package/dist/mjs/internal/typecheck/isolate-types.mjs.map +10 -0
  224. package/dist/mjs/internal/typecheck/typecheck.mjs +91 -0
  225. package/dist/mjs/internal/typecheck/typecheck.mjs.map +10 -0
  226. package/dist/mjs/modules/index.mjs +96 -0
  227. package/dist/mjs/modules/index.mjs.map +10 -0
  228. package/dist/mjs/package.json +5 -0
  229. package/dist/mjs/runtime/script-runtime.mjs +57 -0
  230. package/dist/mjs/runtime/script-runtime.mjs.map +10 -0
  231. package/dist/mjs/server/app-server.mjs +118 -0
  232. package/dist/mjs/server/app-server.mjs.map +10 -0
  233. package/dist/mjs/testing/integration-helpers.mjs +63 -0
  234. package/dist/mjs/testing/integration-helpers.mjs.map +10 -0
  235. package/dist/mjs/typecheck/index.mjs +56 -0
  236. package/dist/mjs/typecheck/index.mjs.map +10 -0
  237. package/dist/mjs/types.mjs +2 -0
  238. package/dist/mjs/types.mjs.map +9 -0
  239. package/dist/types/bridge/diagnostics.d.ts +12 -0
  240. package/dist/types/bridge/legacy-adapters.d.ts +14 -0
  241. package/dist/types/bridge/request-context.d.ts +10 -0
  242. package/dist/types/bridge/runtime-bindings.d.ts +14 -0
  243. package/dist/types/browser/browser-runtime.d.ts +3 -0
  244. package/dist/types/daemon.d.ts +2 -0
  245. package/dist/types/files/index.d.ts +5 -0
  246. package/dist/types/host/create-isolate-host.d.ts +2 -0
  247. package/dist/types/host/index.d.ts +1 -0
  248. package/dist/types/index.d.ts +5 -0
  249. package/dist/types/internal/client/connection.d.ts +9 -0
  250. package/dist/types/internal/client/index.d.ts +8 -0
  251. package/dist/types/internal/client/types.d.ts +198 -0
  252. package/dist/types/internal/console/index.d.ts +108 -0
  253. package/dist/types/internal/console/utils.d.ts +27 -0
  254. package/dist/types/internal/core/index.d.ts +119 -0
  255. package/dist/types/internal/crypto/index.d.ts +18 -0
  256. package/dist/types/internal/daemon/callback-fs-handler.d.ts +28 -0
  257. package/dist/types/internal/daemon/connection.d.ts +9 -0
  258. package/dist/types/internal/daemon/daemon.d.ts +2 -0
  259. package/dist/types/internal/daemon/index.d.ts +14 -0
  260. package/dist/types/internal/daemon/runtime-pool.d.ts +16 -0
  261. package/dist/types/internal/daemon/types.d.ts +211 -0
  262. package/dist/types/internal/encoding/index.d.ts +21 -0
  263. package/dist/types/internal/fetch/consistency/origins.d.ts +179 -0
  264. package/dist/types/internal/fetch/index.d.ts +93 -0
  265. package/dist/types/internal/fetch/stream-state.d.ts +65 -0
  266. package/dist/types/internal/fs/index.d.ts +70 -0
  267. package/dist/types/internal/fs/node-adapter.d.ts +24 -0
  268. package/dist/types/internal/module-loader/bundle.d.ts +33 -0
  269. package/dist/types/internal/module-loader/index.d.ts +30 -0
  270. package/dist/types/internal/module-loader/mappings.d.ts +47 -0
  271. package/dist/types/internal/module-loader/resolve.d.ts +26 -0
  272. package/dist/types/internal/module-loader/strip-types.d.ts +19 -0
  273. package/dist/types/internal/path/index.d.ts +23 -0
  274. package/dist/types/internal/playwright/client.d.ts +7 -0
  275. package/dist/types/internal/playwright/handler.d.ts +44 -0
  276. package/dist/types/internal/playwright/index.d.ts +14 -0
  277. package/dist/types/internal/playwright/types.d.ts +145 -0
  278. package/dist/types/internal/protocol/codec.d.ts +242 -0
  279. package/dist/types/internal/protocol/framing.d.ts +89 -0
  280. package/dist/types/internal/protocol/index.d.ts +10 -0
  281. package/dist/types/internal/protocol/marshalValue.d.ts +79 -0
  282. package/dist/types/internal/protocol/serialization.d.ts +23 -0
  283. package/dist/types/internal/protocol/types.d.ts +996 -0
  284. package/dist/types/internal/runtime/index.d.ts +200 -0
  285. package/dist/types/internal/server/index.d.ts +42 -0
  286. package/dist/types/internal/test-environment/index.d.ts +112 -0
  287. package/dist/types/internal/timers/index.d.ts +22 -0
  288. package/dist/types/internal/transform/index.d.ts +36 -0
  289. package/dist/types/internal/typecheck/index.d.ts +7 -0
  290. package/dist/types/internal/typecheck/isolate-types.d.ts +94 -0
  291. package/dist/types/internal/typecheck/typecheck.d.ts +148 -0
  292. package/dist/types/modules/index.d.ts +2 -0
  293. package/dist/types/runtime/script-runtime.d.ts +6 -0
  294. package/dist/types/server/app-server.d.ts +3 -0
  295. package/dist/types/testing/integration-helpers.d.ts +9 -0
  296. package/dist/types/typecheck/index.d.ts +8 -0
  297. package/dist/types/types.d.ts +233 -0
  298. package/package.json +74 -6
  299. package/README.md +0 -45
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Helper functions for creating web objects from different origins.
3
+ * Used to test that objects behave identically regardless of how they were created.
4
+ *
5
+ * Note: The `customFunction` origin is tested where supported. For Response and Request,
6
+ * this requires constructing the object in the isolate using parameters passed from
7
+ * a host custom function, since native objects cannot be serialized across the boundary.
8
+ */
9
+ import { type RuntimeHandle } from "../../runtime/index.ts";
10
+ export type ResponseOrigin = "direct" | "customFunction" | "fetchCallback";
11
+ export type RequestOrigin = "direct" | "customFunction" | "serveRequest";
12
+ export type HeadersOrigin = "direct" | "fromResponse" | "fromRequest";
13
+ export type BlobOrigin = "direct";
14
+ export type FileOrigin = "direct";
15
+ export type URLOrigin = "direct" | "customFunction";
16
+ export type URLSearchParamsOrigin = "direct" | "fromURL" | "fromCustomFunctionURL";
17
+ export type FormDataOrigin = "direct" | "fromResponse";
18
+ export type ReadableStreamOrigin = "direct" | "responseBody" | "blobStream" | "transformReadable";
19
+ export type WritableStreamOrigin = "direct" | "transformWritable";
20
+ export type TransformStreamOrigin = "direct";
21
+ export type TextEncoderStreamOrigin = "direct";
22
+ export type TextDecoderStreamOrigin = "direct";
23
+ export type QueuingStrategyOrigin = "direct";
24
+ export declare const RESPONSE_ORIGINS: ResponseOrigin[];
25
+ export declare const REQUEST_ORIGINS: RequestOrigin[];
26
+ export declare const HEADERS_ORIGINS: HeadersOrigin[];
27
+ export declare const BLOB_ORIGINS: BlobOrigin[];
28
+ export declare const FILE_ORIGINS: FileOrigin[];
29
+ export declare const URL_ORIGINS: URLOrigin[];
30
+ export declare const URLSEARCHPARAMS_ORIGINS: URLSearchParamsOrigin[];
31
+ export declare const FORMDATA_ORIGINS: FormDataOrigin[];
32
+ export declare const READABLE_STREAM_ORIGINS: ReadableStreamOrigin[];
33
+ export declare const WRITABLE_STREAM_ORIGINS: WritableStreamOrigin[];
34
+ export declare const TRANSFORM_STREAM_ORIGINS: TransformStreamOrigin[];
35
+ export declare const TEXT_ENCODER_STREAM_ORIGINS: TextEncoderStreamOrigin[];
36
+ export declare const TEXT_DECODER_STREAM_ORIGINS: TextDecoderStreamOrigin[];
37
+ export declare const QUEUING_STRATEGY_ORIGINS: QueuingStrategyOrigin[];
38
+ export type AbortControllerOrigin = "direct";
39
+ export type AbortSignalOrigin = "direct";
40
+ export declare const ABORT_CONTROLLER_ORIGINS: AbortControllerOrigin[];
41
+ export declare const ABORT_SIGNAL_ORIGINS: AbortSignalOrigin[];
42
+ export interface ConsistencyTestContext {
43
+ /** The runtime handle */
44
+ runtime: RuntimeHandle;
45
+ /** Execute code in the runtime */
46
+ eval(code: string): Promise<void>;
47
+ /** Dispatch an HTTP request to the serve() handler */
48
+ dispatchRequest(request: Request): Promise<Response>;
49
+ /** Set the mock response for the next fetch call */
50
+ setMockResponse(response: MockResponse): void;
51
+ /** Get a result from the isolate via setResult() */
52
+ getResult<T = unknown>(): T | undefined;
53
+ /** Clear the stored result */
54
+ clearResult(): void;
55
+ /** Dispose all resources */
56
+ dispose(): Promise<void>;
57
+ }
58
+ export interface MockResponse {
59
+ status?: number;
60
+ statusText?: string;
61
+ body?: string;
62
+ headers?: Record<string, string>;
63
+ }
64
+ /**
65
+ * Create a test context for consistency tests.
66
+ * Provides helpers for creating objects from different origins.
67
+ */
68
+ export declare function createConsistencyTestContext(): Promise<ConsistencyTestContext>;
69
+ export interface ResponseOptions {
70
+ status?: number;
71
+ statusText?: string;
72
+ headers?: Record<string, string>;
73
+ }
74
+ /**
75
+ * Create a Response in the isolate from the specified origin.
76
+ * The Response is stored at globalThis.__testResponse.
77
+ */
78
+ export declare function getResponseFromOrigin(ctx: ConsistencyTestContext, origin: ResponseOrigin, body: string, options?: ResponseOptions): Promise<void>;
79
+ export interface RequestOptions {
80
+ method?: string;
81
+ headers?: Record<string, string>;
82
+ body?: string;
83
+ }
84
+ /**
85
+ * Create a Request in the isolate from the specified origin.
86
+ * The Request is stored at globalThis.__testRequest.
87
+ */
88
+ export declare function getRequestFromOrigin(ctx: ConsistencyTestContext, origin: RequestOrigin, url: string, options?: RequestOptions): Promise<void>;
89
+ /**
90
+ * Create Headers in the isolate from the specified origin.
91
+ * The Headers is stored at globalThis.__testHeaders.
92
+ */
93
+ export declare function getHeadersFromOrigin(ctx: ConsistencyTestContext, origin: HeadersOrigin, init: Record<string, string>): Promise<void>;
94
+ export interface BlobOptions {
95
+ type?: string;
96
+ }
97
+ /**
98
+ * Create a Blob in the isolate from the specified origin.
99
+ * The Blob is stored at globalThis.__testBlob.
100
+ */
101
+ export declare function getBlobFromOrigin(ctx: ConsistencyTestContext, origin: BlobOrigin, content: string, options?: BlobOptions): Promise<void>;
102
+ export interface FileOptions {
103
+ type?: string;
104
+ lastModified?: number;
105
+ }
106
+ /**
107
+ * Create a File in the isolate from the specified origin.
108
+ * The File is stored at globalThis.__testFile.
109
+ */
110
+ export declare function getFileFromOrigin(ctx: ConsistencyTestContext, origin: FileOrigin, content: string, filename: string, options?: FileOptions): Promise<void>;
111
+ /**
112
+ * Create FormData in the isolate from the specified origin.
113
+ * The FormData is stored at globalThis.__testFormData.
114
+ */
115
+ export declare function getFormDataFromOrigin(ctx: ConsistencyTestContext, origin: FormDataOrigin, entries: Array<[string, string]>): Promise<void>;
116
+ /**
117
+ * Setup a serve handler that returns the specified response.
118
+ */
119
+ export declare function setupServeHandler(ctx: ConsistencyTestContext, body: string, options?: ResponseOptions): Promise<void>;
120
+ /**
121
+ * Dispatch a request and get the Response on the host side.
122
+ * This tests the host-side conversion of Response from isolate.
123
+ */
124
+ export declare function getDispatchResponse(ctx: ConsistencyTestContext, body: string, options?: ResponseOptions): Promise<Response>;
125
+ /**
126
+ * Create a ReadableStream in the isolate from the specified origin.
127
+ * The ReadableStream is stored at globalThis.__testReadableStream.
128
+ */
129
+ export declare function getReadableStreamFromOrigin(ctx: ConsistencyTestContext, origin: ReadableStreamOrigin, chunks?: string[]): Promise<void>;
130
+ /**
131
+ * Create a WritableStream in the isolate from the specified origin.
132
+ * The WritableStream is stored at globalThis.__testWritableStream.
133
+ * Also stores written chunks at globalThis.__testWrittenChunks.
134
+ */
135
+ export declare function getWritableStreamFromOrigin(ctx: ConsistencyTestContext, origin: WritableStreamOrigin): Promise<void>;
136
+ /**
137
+ * Create a TransformStream in the isolate from the specified origin.
138
+ * The TransformStream is stored at globalThis.__testTransformStream.
139
+ */
140
+ export declare function getTransformStreamFromOrigin(ctx: ConsistencyTestContext, _origin: TransformStreamOrigin): Promise<void>;
141
+ /**
142
+ * Create a TextEncoderStream in the isolate from the specified origin.
143
+ * The TextEncoderStream is stored at globalThis.__testTextEncoderStream.
144
+ */
145
+ export declare function getTextEncoderStreamFromOrigin(ctx: ConsistencyTestContext, _origin: TextEncoderStreamOrigin): Promise<void>;
146
+ export interface TextDecoderStreamOptions {
147
+ fatal?: boolean;
148
+ ignoreBOM?: boolean;
149
+ }
150
+ /**
151
+ * Create a TextDecoderStream in the isolate from the specified origin.
152
+ * The TextDecoderStream is stored at globalThis.__testTextDecoderStream.
153
+ */
154
+ export declare function getTextDecoderStreamFromOrigin(ctx: ConsistencyTestContext, _origin: TextDecoderStreamOrigin, options?: TextDecoderStreamOptions): Promise<void>;
155
+ /**
156
+ * Create a ByteLengthQueuingStrategy or CountQueuingStrategy in the isolate.
157
+ * The strategy is stored at globalThis.__testQueuingStrategy.
158
+ */
159
+ export declare function getQueuingStrategyFromOrigin(ctx: ConsistencyTestContext, strategyType: "ByteLength" | "Count", highWaterMark?: number): Promise<void>;
160
+ /**
161
+ * Create a URL in the isolate from the specified origin.
162
+ * The URL is stored at globalThis.__testURL.
163
+ */
164
+ export declare function getURLFromOrigin(ctx: ConsistencyTestContext, origin: URLOrigin, urlString: string): Promise<void>;
165
+ /**
166
+ * Create URLSearchParams in the isolate from the specified origin.
167
+ * The URLSearchParams is stored at globalThis.__testURLSearchParams.
168
+ */
169
+ export declare function getURLSearchParamsFromOrigin(ctx: ConsistencyTestContext, origin: URLSearchParamsOrigin, init?: string): Promise<void>;
170
+ /**
171
+ * Create an AbortController in the isolate from the specified origin.
172
+ * The AbortController is stored at globalThis.__testAbortController.
173
+ */
174
+ export declare function getAbortControllerFromOrigin(ctx: ConsistencyTestContext, _origin: AbortControllerOrigin): Promise<void>;
175
+ /**
176
+ * Create an AbortSignal in the isolate from the specified origin.
177
+ * The AbortSignal is stored at globalThis.__testAbortSignal.
178
+ */
179
+ export declare function getAbortSignalFromOrigin(ctx: ConsistencyTestContext, _origin: AbortSignalOrigin): Promise<void>;
@@ -0,0 +1,93 @@
1
+ import ivm from "isolated-vm";
2
+ import { clearAllInstanceState } from "../core/index.ts";
3
+ export { clearAllInstanceState };
4
+ export interface FetchRequestInit {
5
+ method: string;
6
+ headers: [string, string][];
7
+ rawBody: Uint8Array | null;
8
+ body: BodyInit | null;
9
+ signal: AbortSignal;
10
+ }
11
+ export interface FetchOptions {
12
+ /** Handler for fetch requests from the isolate */
13
+ onFetch?: (url: string, init: FetchRequestInit) => Promise<Response>;
14
+ }
15
+ export interface UpgradeRequest {
16
+ requested: true;
17
+ connectionId: string;
18
+ }
19
+ export interface WebSocketCommand {
20
+ type: "message" | "close";
21
+ connectionId: string;
22
+ data?: string | ArrayBuffer;
23
+ code?: number;
24
+ reason?: string;
25
+ }
26
+ export interface ClientWebSocketCommand {
27
+ type: "connect" | "send" | "close";
28
+ socketId: string;
29
+ url?: string;
30
+ protocols?: string[];
31
+ data?: string | ArrayBuffer;
32
+ code?: number;
33
+ reason?: string;
34
+ }
35
+ export interface DispatchRequestOptions {
36
+ /** AbortSignal to mirror cancellation into request.signal inside isolate */
37
+ signal?: AbortSignal;
38
+ }
39
+ export interface FetchHandle {
40
+ dispose(): void;
41
+ /** Dispatch an HTTP request to the isolate's serve() handler */
42
+ dispatchRequest(request: Request, options?: DispatchRequestOptions): Promise<Response>;
43
+ /** Check if isolate requested WebSocket upgrade */
44
+ getUpgradeRequest(): UpgradeRequest | null;
45
+ /** Dispatch WebSocket open event to isolate */
46
+ dispatchWebSocketOpen(connectionId: string): void;
47
+ /** Dispatch WebSocket message event to isolate */
48
+ dispatchWebSocketMessage(connectionId: string, message: string | ArrayBuffer): void;
49
+ /** Dispatch WebSocket close event to isolate */
50
+ dispatchWebSocketClose(connectionId: string, code: number, reason: string): void;
51
+ /** Dispatch WebSocket error event to isolate */
52
+ dispatchWebSocketError(connectionId: string, error: Error): void;
53
+ /** Register callback for WebSocket commands from isolate */
54
+ onWebSocketCommand(callback: (cmd: WebSocketCommand) => void): () => void;
55
+ /** Check if serve() has been called */
56
+ hasServeHandler(): boolean;
57
+ /** Check if there are active WebSocket connections */
58
+ hasActiveConnections(): boolean;
59
+ /** Dispatch open event to a client WebSocket in the isolate */
60
+ dispatchClientWebSocketOpen(socketId: string, protocol: string, extensions: string): void;
61
+ /** Dispatch message event to a client WebSocket in the isolate */
62
+ dispatchClientWebSocketMessage(socketId: string, data: string | ArrayBuffer): void;
63
+ /** Dispatch close event to a client WebSocket in the isolate */
64
+ dispatchClientWebSocketClose(socketId: string, code: number, reason: string, wasClean: boolean): void;
65
+ /** Dispatch error event to a client WebSocket in the isolate */
66
+ dispatchClientWebSocketError(socketId: string): void;
67
+ /** Register callback for client WebSocket commands from isolate */
68
+ onClientWebSocketCommand(callback: (cmd: ClientWebSocketCommand) => void): () => void;
69
+ /** Register callback for events emitted from isolate code */
70
+ onEvent(callback: (event: string, payload: unknown) => void): () => void;
71
+ /** Dispatch an event into the isolate (calls __on listeners) */
72
+ dispatchEvent(event: string, payload: unknown): void;
73
+ }
74
+ /**
75
+ * Setup Fetch API in an isolated-vm context
76
+ *
77
+ * Injects fetch, Request, Response, Headers, FormData
78
+ * Also sets up core APIs (Blob, File, AbortController, etc.) if not already present
79
+ *
80
+ * @example
81
+ * const handle = await setupFetch(context, {
82
+ * onFetch: async (url, init) => {
83
+ * // Proxy fetch requests to the host
84
+ * return fetch(url, init);
85
+ * }
86
+ * });
87
+ *
88
+ * await context.eval(`
89
+ * const response = await fetch("https://example.com");
90
+ * const text = await response.text();
91
+ * `);
92
+ */
93
+ export declare function setupFetch(context: ivm.Context, options?: FetchOptions): Promise<FetchHandle>;
@@ -0,0 +1,65 @@
1
+ import ivm from "isolated-vm";
2
+ export interface StreamState {
3
+ /** Buffered chunks waiting to be read */
4
+ queue: Uint8Array[];
5
+ /** Total bytes in queue (for backpressure) */
6
+ queueSize: number;
7
+ /** Stream has been closed (no more data) */
8
+ closed: boolean;
9
+ /** Stream encountered an error */
10
+ errored: boolean;
11
+ /** The error value if errored */
12
+ errorValue: unknown;
13
+ /** A pull is waiting for data */
14
+ pullWaiting: boolean;
15
+ /** Resolve function for waiting pull */
16
+ pullResolve: ((chunk: Uint8Array | null) => void) | null;
17
+ /** Reject function for waiting pull */
18
+ pullReject: ((error: unknown) => void) | null;
19
+ }
20
+ export interface StreamStateRegistry {
21
+ /** Create a new stream and return its ID */
22
+ create(): number;
23
+ /** Get stream state by ID */
24
+ get(streamId: number): StreamState | undefined;
25
+ /** Push a chunk to the stream's queue */
26
+ push(streamId: number, chunk: Uint8Array): boolean;
27
+ /** Pull a chunk from the stream (returns Promise that resolves when data available) */
28
+ pull(streamId: number): Promise<{
29
+ value: Uint8Array;
30
+ done: false;
31
+ } | {
32
+ done: true;
33
+ }>;
34
+ /** Close the stream (no more data) */
35
+ close(streamId: number): void;
36
+ /** Error the stream */
37
+ error(streamId: number, errorValue: unknown): void;
38
+ /** Check if stream queue is above high-water mark */
39
+ isQueueFull(streamId: number): boolean;
40
+ /** Delete stream state (cleanup) */
41
+ delete(streamId: number): void;
42
+ /** Clear all streams (context cleanup) */
43
+ clear(): void;
44
+ /** Cancel a stream and call its cleanup function */
45
+ cancel(streamId: number): void;
46
+ /** Register a cleanup function for a stream */
47
+ setCleanup(streamId: number, cleanup: () => Promise<void>): void;
48
+ }
49
+ /** Maximum bytes to buffer before backpressure kicks in */
50
+ export declare const HIGH_WATER_MARK: number;
51
+ /** Maximum number of chunks in queue */
52
+ export declare const MAX_QUEUE_CHUNKS = 16;
53
+ export declare function createStreamStateRegistry(): StreamStateRegistry;
54
+ export declare function getStreamRegistryForContext(context: ivm.Context): StreamStateRegistry;
55
+ export declare function clearStreamRegistryForContext(context: ivm.Context): void;
56
+ /**
57
+ * Start reading from a native ReadableStream and push to host queue.
58
+ * Respects backpressure by pausing when queue is full.
59
+ *
60
+ * @param nativeStream The native ReadableStream to read from
61
+ * @param streamId The stream ID in the registry
62
+ * @param registry The stream state registry
63
+ * @returns Async cleanup function to cancel the reader
64
+ */
65
+ export declare function startNativeStreamReader(nativeStream: ReadableStream<Uint8Array>, streamId: number, registry: StreamStateRegistry): () => Promise<void>;
@@ -0,0 +1,70 @@
1
+ import ivm from "isolated-vm";
2
+ import { clearAllInstanceState } from "../core/index.ts";
3
+ export { clearAllInstanceState };
4
+ export interface FileSystemHandler {
5
+ /** Get or create a file handle at the given path */
6
+ getFileHandle(path: string, options?: {
7
+ create?: boolean;
8
+ }): Promise<void>;
9
+ /** Get or create a directory handle at the given path */
10
+ getDirectoryHandle(path: string, options?: {
11
+ create?: boolean;
12
+ }): Promise<void>;
13
+ /** Remove a file or directory at the given path */
14
+ removeEntry(path: string, options?: {
15
+ recursive?: boolean;
16
+ }): Promise<void>;
17
+ /** List contents of a directory */
18
+ readDirectory(path: string): Promise<Array<{
19
+ name: string;
20
+ kind: "file" | "directory";
21
+ }>>;
22
+ /** Read file content */
23
+ readFile(path: string): Promise<{
24
+ data: Uint8Array;
25
+ size: number;
26
+ lastModified: number;
27
+ type: string;
28
+ }>;
29
+ /** Write data to a file */
30
+ writeFile(path: string, data: Uint8Array, position?: number): Promise<void>;
31
+ /** Truncate a file to a specific size */
32
+ truncateFile(path: string, size: number): Promise<void>;
33
+ /** Get file metadata without reading content */
34
+ getFileMetadata(path: string): Promise<{
35
+ size: number;
36
+ lastModified: number;
37
+ type: string;
38
+ }>;
39
+ }
40
+ export interface FsOptions {
41
+ /** Get a file system handler for the given path */
42
+ getDirectory(path: string): Promise<FileSystemHandler>;
43
+ }
44
+ export interface FsHandle {
45
+ dispose(): void;
46
+ }
47
+ /**
48
+ * Setup File System Access API in an isolated-vm context
49
+ *
50
+ * Provides an OPFS-compatible FileSystemDirectoryHandle API
51
+ *
52
+ * @example
53
+ * const handle = await setupFs(context, {
54
+ * getDirectory: async (path) => {
55
+ * // Return a FileSystemHandler rooted at the given path
56
+ * return createNodeFileSystemHandler(`./data${path}`);
57
+ * }
58
+ * });
59
+ *
60
+ * await context.eval(`
61
+ * const root = await getDirectory("/uploads");
62
+ * const fileHandle = await root.getFileHandle("test.txt", { create: true });
63
+ * const writable = await fileHandle.createWritable();
64
+ * await writable.write("hello world");
65
+ * await writable.close();
66
+ * `);
67
+ */
68
+ export declare function setupFs(context: ivm.Context, options: FsOptions): Promise<FsHandle>;
69
+ export { createNodeFileSystemHandler } from "./node-adapter.ts";
70
+ export type { NodeFileSystemHandlerOptions } from "./node-adapter.ts";
@@ -0,0 +1,24 @@
1
+ import * as nodeFs from "node:fs";
2
+ import type { FileSystemHandler } from "./index.ts";
3
+ export interface NodeFileSystemHandlerOptions {
4
+ /** Custom fs module (e.g., memfs for testing). Defaults to Node.js fs */
5
+ fs?: typeof nodeFs;
6
+ }
7
+ /**
8
+ * Create a FileSystemHandler backed by the Node.js filesystem
9
+ *
10
+ * @param rootPath - Absolute path to the root directory for the sandbox
11
+ * @param options - Optional configuration
12
+ * @returns FileSystemHandler implementation
13
+ *
14
+ * @example
15
+ * import { createNodeFileSystemHandler } from "./index.ts";
16
+ *
17
+ * const handler = createNodeFileSystemHandler("/tmp/sandbox");
18
+ *
19
+ * // Use with createRuntime
20
+ * const runtime = await createRuntime({
21
+ * fs: { handler }
22
+ * });
23
+ */
24
+ export declare function createNodeFileSystemHandler(rootPath: string, options?: NodeFileSystemHandlerOptions): FileSystemHandler;
@@ -0,0 +1,33 @@
1
+ export declare function getNodeBuiltinShimCode(source: string): string;
2
+ /**
3
+ * Bundle a bare specifier (npm package) using Rollup.
4
+ *
5
+ * Each unique bare specifier gets its own bundle with:
6
+ * - node-resolve with browser conditions
7
+ * - commonjs conversion
8
+ * - json support
9
+ * - process.env.NODE_ENV replacement
10
+ * - External deps (other npm packages) left as import statements
11
+ *
12
+ * Results are cached permanently (npm packages are static).
13
+ */
14
+ export declare function bundleSpecifier(specifier: string, rootDir: string): Promise<{
15
+ code: string;
16
+ }>;
17
+ /**
18
+ * Bundle a host file using Rollup, inlining its relative imports.
19
+ *
20
+ * - Uses the host file path as Rollup input
21
+ * - Externalizes ALL bare specifiers (npm packages)
22
+ * - Strips TypeScript via processTypeScript
23
+ * - Shares the bundleCache/bundlesInFlight (no key collision since file paths start with `/`)
24
+ *
25
+ * Results are cached permanently.
26
+ */
27
+ export declare function bundleHostFile(hostFilePath: string): Promise<{
28
+ code: string;
29
+ }>;
30
+ /**
31
+ * Clear the bundle cache. Useful for testing.
32
+ */
33
+ export declare function clearBundleCache(): void;
@@ -0,0 +1,30 @@
1
+ import type { ModuleLoaderCallback } from "../protocol/index.ts";
2
+ import { type MappingConfig } from "./mappings.ts";
3
+ export { parseMappings, virtualToHost, findNodeModulesMapping, findModuleAlias } from "./mappings.ts";
4
+ export type { MappingConfig, PathMapping } from "./mappings.ts";
5
+ export { resolveFilePath, detectFormat, parseSpecifier, isBareSpecifier } from "./resolve.ts";
6
+ export { bundleSpecifier, bundleHostFile, clearBundleCache } from "./bundle.ts";
7
+ export { isTypeScriptFile, processTypeScript } from "./strip-types.ts";
8
+ /**
9
+ * Create a module loader callback that handles common patterns:
10
+ * - Mapping host filesystem paths to virtual isolate paths
11
+ * - Bundling npm packages with Rollup (ESM-first, browser conditions)
12
+ * - Reading user files directly from the host filesystem
13
+ *
14
+ * Each npm package subpath is bundled independently and cached as static.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { defaultModuleLoader } from './index.ts';
19
+ *
20
+ * const loader = defaultModuleLoader(
21
+ * { from: '/host/project/node_modules', to: '/node_modules' },
22
+ * { from: '/host/project/src/entry.ts', to: '/app/entry.ts' }
23
+ * );
24
+ *
25
+ * const runtime = await createRuntime({
26
+ * moduleLoader: loader,
27
+ * });
28
+ * ```
29
+ */
30
+ export declare function defaultModuleLoader(...paths: MappingConfig[]): ModuleLoaderCallback;
@@ -0,0 +1,47 @@
1
+ export interface PathMapping {
2
+ /** Original 'from' path (host) */
3
+ from: string;
4
+ /** Original 'to' path (virtual) */
5
+ to: string;
6
+ /** Whether this is a glob pattern */
7
+ isGlob: boolean;
8
+ /** For globs: the base path before the glob (host-side) */
9
+ hostBase: string;
10
+ /** For globs: the virtual mount point */
11
+ virtualMount: string;
12
+ /** Whether the host base ends with node_modules */
13
+ isNodeModules: boolean;
14
+ /** Whether this mapping is a module alias (to doesn't start with '/') */
15
+ isModuleAlias: boolean;
16
+ }
17
+ export interface MappingConfig {
18
+ from: string;
19
+ to: string;
20
+ }
21
+ /**
22
+ * Parse {from, to} pairs into structured PathMapping objects.
23
+ *
24
+ * - Glob patterns (contain `*`): extract base path before glob -> prefix mapping
25
+ * - Direct file paths (no glob): 1:1 mapping
26
+ * - Node modules detection: if base path ends with `node_modules`, flag as isNodeModules
27
+ */
28
+ export declare function parseMappings(configs: MappingConfig[]): PathMapping[];
29
+ /**
30
+ * Map a virtual path to a host path using the configured mappings.
31
+ * Returns null if no mapping matches.
32
+ */
33
+ export declare function virtualToHost(virtualPath: string, mappings: PathMapping[]): string | null;
34
+ /**
35
+ * Map a host path to a virtual path using the configured mappings.
36
+ * Returns null if no mapping matches.
37
+ */
38
+ export declare function hostToVirtual(hostPath: string, mappings: PathMapping[]): string | null;
39
+ /**
40
+ * Find the node_modules mapping (if any).
41
+ */
42
+ export declare function findNodeModulesMapping(mappings: PathMapping[]): PathMapping | undefined;
43
+ /**
44
+ * Find a module alias mapping that matches the given bare specifier.
45
+ * Returns undefined if no module alias matches.
46
+ */
47
+ export declare function findModuleAlias(specifier: string, mappings: PathMapping[]): PathMapping | undefined;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Resolve a file path with extension probing, index fallback, and browser variant probing.
3
+ * Returns the resolved absolute path, or null if not found.
4
+ */
5
+ export declare function resolveFilePath(basePath: string): string | null;
6
+ /**
7
+ * Detect the format of a file based on its extension and content.
8
+ */
9
+ export declare function detectFormat(filePath: string, code: string): "cjs" | "esm" | "json";
10
+ /**
11
+ * Parse a bare specifier into package name and subpath.
12
+ *
13
+ * Examples:
14
+ * "lodash" -> { packageName: "lodash", subpath: "" }
15
+ * "lodash/chunk" -> { packageName: "lodash", subpath: "/chunk" }
16
+ * "@scope/pkg" -> { packageName: "@scope/pkg", subpath: "" }
17
+ * "@scope/pkg/sub/path" -> { packageName: "@scope/pkg", subpath: "/sub/path" }
18
+ */
19
+ export declare function parseSpecifier(specifier: string): {
20
+ packageName: string;
21
+ subpath: string;
22
+ };
23
+ /**
24
+ * Check if a specifier is a bare specifier (npm package name, not relative/absolute).
25
+ */
26
+ export declare function isBareSpecifier(specifier: string): boolean;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Check if a file path is a TypeScript file that needs type processing.
3
+ */
4
+ export declare function isTypeScriptFile(filePath: string): boolean;
5
+ /**
6
+ * Process a TypeScript file for isolate use:
7
+ *
8
+ * 1. Strip TypeScript types
9
+ * 2. Elide import specifiers no longer referenced in the code body
10
+ * (handles: `import { SomeType } from 'pkg'` where SomeType was only
11
+ * used in type positions — the import survives stripping but the
12
+ * usage doesn't, so V8 demands an export that doesn't exist in the bundle)
13
+ * 3. Add placeholder exports for type-only export names
14
+ * (handles: `export interface Foo {}` disappears after stripping,
15
+ * but other files may `import { Foo }` from this module)
16
+ *
17
+ * Returns valid JavaScript.
18
+ */
19
+ export declare function processTypeScript(code: string, filename: string): string;
@@ -0,0 +1,23 @@
1
+ import type ivm from "isolated-vm";
2
+ export interface PathOptions {
3
+ /** Current working directory for path.resolve(). Defaults to "/" */
4
+ cwd?: string;
5
+ }
6
+ export interface PathHandle {
7
+ dispose(): void;
8
+ }
9
+ /**
10
+ * Setup path utilities in an isolated-vm context
11
+ *
12
+ * Provides path manipulation utilities similar to Node.js path module
13
+ * Uses POSIX-style paths only (always uses '/' as separator)
14
+ *
15
+ * @example
16
+ * const handle = await setupPath(context, { cwd: "/home/user" });
17
+ * await context.eval(\`
18
+ * const joined = path.join("/foo", "bar", "baz");
19
+ * const dir = path.dirname("/foo/bar/baz.txt");
20
+ * const resolved = path.resolve("relative"); // Uses configured cwd
21
+ * \`);
22
+ */
23
+ export declare function setupPath(context: ivm.Context, options?: PathOptions): Promise<PathHandle>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Client-safe exports for ./index.ts
3
+ * This module can be imported without loading isolated-vm
4
+ */
5
+ export type { NetworkRequestInfo, NetworkResponseInfo, BrowserConsoleLogEntry, PageErrorInfo, RequestFailureInfo, DefaultPlaywrightHandler, DefaultPlaywrightHandlerMetadata, DefaultPlaywrightHandlerOptions, PlaywrightSetupOptions, PlaywrightHandle, PlaywrightCallback, } from "./types.ts";
6
+ export type { PlaywrightOperation, PlaywrightResult, PlaywrightEvent, PlaywrightFileData } from "../protocol/index.ts";
7
+ export { createPlaywrightHandler, defaultPlaywrightHandler, getDefaultPlaywrightHandlerMetadata, } from "./handler.ts";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Shared handler code for ./index.ts
3
+ * Used by both index.ts (with isolated-vm) and client.ts (without isolated-vm)
4
+ */
5
+ import type { Page, Locator as PlaywrightLocator, BrowserContext, Response } from "playwright";
6
+ import { type DefaultPlaywrightHandlerMetadata, type DefaultPlaywrightHandlerOptions, type PlaywrightCallback, type PlaywrightSetupOptions } from "./types.ts";
7
+ type ReadFileCallback = NonNullable<PlaywrightSetupOptions['readFile']>;
8
+ type WriteFileCallback = NonNullable<PlaywrightSetupOptions['writeFile']>;
9
+ export interface FileIOCallbacks {
10
+ readFile?: ReadFileCallback;
11
+ writeFile?: WriteFileCallback;
12
+ }
13
+ export declare function getLocator(page: Page, selectorType: string, selectorValue: string, optionsJson: string | null): PlaywrightLocator;
14
+ export declare function executeLocatorAction(locator: PlaywrightLocator, action: string, actionArg: unknown, timeout: number, fileIO?: FileIOCallbacks): Promise<unknown>;
15
+ export declare function executeExpectAssertion(locator: PlaywrightLocator, matcher: string, expected: unknown, negated: boolean, timeout: number): Promise<void>;
16
+ export declare function executePageExpectAssertion(page: Page, matcher: string, expected: unknown, negated: boolean, timeout: number): Promise<void>;
17
+ /**
18
+ * Registry for tracking multiple pages and contexts.
19
+ */
20
+ export interface PlaywrightRegistry {
21
+ pages: Map<string, Page>;
22
+ contexts: Map<string, BrowserContext>;
23
+ nextPageId: number;
24
+ nextContextId: number;
25
+ pendingResponses: Map<string, Promise<Response>>;
26
+ pendingRequests: Map<string, Promise<import("playwright").Request>>;
27
+ nextListenerId: number;
28
+ }
29
+ /**
30
+ * Create a playwright handler from a Page object.
31
+ * This handler is called by the daemon (via callback) when sandbox needs page operations.
32
+ * Used for remote runtime where the browser runs on the client.
33
+ */
34
+ export declare function createPlaywrightHandler(page: Page, options?: DefaultPlaywrightHandlerOptions): PlaywrightCallback;
35
+ /**
36
+ * Public helper for handler-first runtime options.
37
+ * Adds metadata used by adapters for local event capture and collected data.
38
+ */
39
+ export declare function defaultPlaywrightHandler(page: Page, options?: DefaultPlaywrightHandlerOptions): PlaywrightCallback;
40
+ /**
41
+ * Extract metadata from handlers created by defaultPlaywrightHandler().
42
+ */
43
+ export declare function getDefaultPlaywrightHandlerMetadata(handler: PlaywrightCallback): DefaultPlaywrightHandlerMetadata | undefined;
44
+ export {};