@ricsam/isolate 0.0.1 → 0.1.1

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/README.md +243 -34
  2. package/dist/cjs/bridge/diagnostics.cjs +58 -0
  3. package/dist/cjs/bridge/diagnostics.cjs.map +10 -0
  4. package/dist/cjs/bridge/legacy-adapters.cjs +242 -0
  5. package/dist/cjs/bridge/legacy-adapters.cjs.map +10 -0
  6. package/dist/cjs/bridge/request-context.cjs +59 -0
  7. package/dist/cjs/bridge/request-context.cjs.map +10 -0
  8. package/dist/cjs/bridge/runtime-bindings.cjs +367 -0
  9. package/dist/cjs/bridge/runtime-bindings.cjs.map +10 -0
  10. package/dist/cjs/browser/browser-runtime.cjs +157 -0
  11. package/dist/cjs/browser/browser-runtime.cjs.map +10 -0
  12. package/dist/cjs/daemon.cjs +91 -0
  13. package/dist/cjs/daemon.cjs.map +10 -0
  14. package/dist/cjs/files/index.cjs +140 -0
  15. package/dist/cjs/files/index.cjs.map +10 -0
  16. package/dist/cjs/host/create-isolate-host.cjs +235 -0
  17. package/dist/cjs/host/create-isolate-host.cjs.map +10 -0
  18. package/dist/cjs/host/index.cjs +47 -0
  19. package/dist/cjs/host/index.cjs.map +10 -0
  20. package/dist/cjs/index.cjs +55 -0
  21. package/dist/cjs/index.cjs.map +10 -0
  22. package/dist/cjs/internal/client/connection.cjs +1919 -0
  23. package/dist/cjs/internal/client/connection.cjs.map +10 -0
  24. package/dist/cjs/internal/client/index.cjs +48 -0
  25. package/dist/cjs/internal/client/index.cjs.map +10 -0
  26. package/dist/cjs/internal/client/types.cjs +30 -0
  27. package/dist/cjs/internal/client/types.cjs.map +9 -0
  28. package/dist/cjs/internal/console/index.cjs +506 -0
  29. package/dist/cjs/internal/console/index.cjs.map +10 -0
  30. package/dist/cjs/internal/console/utils.cjs +70 -0
  31. package/dist/cjs/internal/console/utils.cjs.map +10 -0
  32. package/dist/cjs/internal/core/index.cjs +2745 -0
  33. package/dist/cjs/internal/core/index.cjs.map +10 -0
  34. package/dist/cjs/internal/crypto/index.cjs +470 -0
  35. package/dist/cjs/internal/crypto/index.cjs.map +10 -0
  36. package/dist/cjs/internal/daemon/callback-fs-handler.cjs +355 -0
  37. package/dist/cjs/internal/daemon/callback-fs-handler.cjs.map +10 -0
  38. package/dist/cjs/internal/daemon/connection.cjs +1952 -0
  39. package/dist/cjs/internal/daemon/connection.cjs.map +10 -0
  40. package/dist/cjs/internal/daemon/daemon.cjs +98 -0
  41. package/dist/cjs/internal/daemon/daemon.cjs.map +10 -0
  42. package/dist/cjs/internal/daemon/index.cjs +145 -0
  43. package/dist/cjs/internal/daemon/index.cjs.map +10 -0
  44. package/dist/cjs/internal/daemon/runtime-pool.cjs +106 -0
  45. package/dist/cjs/internal/daemon/runtime-pool.cjs.map +10 -0
  46. package/dist/cjs/internal/daemon/types.cjs +30 -0
  47. package/dist/cjs/internal/daemon/types.cjs.map +9 -0
  48. package/dist/cjs/internal/encoding/index.cjs +419 -0
  49. package/dist/cjs/internal/encoding/index.cjs.map +10 -0
  50. package/dist/cjs/internal/fetch/consistency/origins.cjs +598 -0
  51. package/dist/cjs/internal/fetch/consistency/origins.cjs.map +10 -0
  52. package/dist/cjs/internal/fetch/index.cjs +2640 -0
  53. package/dist/cjs/internal/fetch/index.cjs.map +10 -0
  54. package/dist/cjs/internal/fetch/stream-state.cjs +256 -0
  55. package/dist/cjs/internal/fetch/stream-state.cjs.map +10 -0
  56. package/dist/cjs/internal/fs/index.cjs +847 -0
  57. package/dist/cjs/internal/fs/index.cjs.map +10 -0
  58. package/dist/cjs/internal/fs/node-adapter.cjs +254 -0
  59. package/dist/cjs/internal/fs/node-adapter.cjs.map +10 -0
  60. package/dist/cjs/internal/module-loader/bundle.cjs +482 -0
  61. package/dist/cjs/internal/module-loader/bundle.cjs.map +10 -0
  62. package/dist/cjs/internal/module-loader/index.cjs +240 -0
  63. package/dist/cjs/internal/module-loader/index.cjs.map +10 -0
  64. package/dist/cjs/internal/module-loader/mappings.cjs +120 -0
  65. package/dist/cjs/internal/module-loader/mappings.cjs.map +10 -0
  66. package/dist/cjs/internal/module-loader/resolve.cjs +177 -0
  67. package/dist/cjs/internal/module-loader/resolve.cjs.map +10 -0
  68. package/dist/cjs/internal/module-loader/strip-types.cjs +236 -0
  69. package/dist/cjs/internal/module-loader/strip-types.cjs.map +10 -0
  70. package/dist/cjs/internal/path/index.cjs +503 -0
  71. package/dist/cjs/internal/path/index.cjs.map +10 -0
  72. package/dist/cjs/internal/playwright/client.cjs +49 -0
  73. package/dist/cjs/internal/playwright/client.cjs.map +10 -0
  74. package/dist/cjs/internal/playwright/handler.cjs +1416 -0
  75. package/dist/cjs/internal/playwright/handler.cjs.map +10 -0
  76. package/dist/cjs/internal/playwright/index.cjs +1289 -0
  77. package/dist/cjs/internal/playwright/index.cjs.map +10 -0
  78. package/dist/cjs/internal/playwright/types.cjs +47 -0
  79. package/dist/cjs/internal/playwright/types.cjs.map +10 -0
  80. package/dist/cjs/internal/protocol/codec.cjs +510 -0
  81. package/dist/cjs/internal/protocol/codec.cjs.map +10 -0
  82. package/dist/cjs/internal/protocol/framing.cjs +141 -0
  83. package/dist/cjs/internal/protocol/framing.cjs.map +10 -0
  84. package/dist/cjs/internal/protocol/index.cjs +110 -0
  85. package/dist/cjs/internal/protocol/index.cjs.map +10 -0
  86. package/dist/cjs/internal/protocol/marshalValue.cjs +518 -0
  87. package/dist/cjs/internal/protocol/marshalValue.cjs.map +10 -0
  88. package/dist/cjs/internal/protocol/serialization.cjs +109 -0
  89. package/dist/cjs/internal/protocol/serialization.cjs.map +10 -0
  90. package/dist/cjs/internal/protocol/types.cjs +181 -0
  91. package/dist/cjs/internal/protocol/types.cjs.map +10 -0
  92. package/dist/cjs/internal/runtime/index.cjs +1235 -0
  93. package/dist/cjs/internal/runtime/index.cjs.map +10 -0
  94. package/dist/cjs/internal/server/index.cjs +223 -0
  95. package/dist/cjs/internal/server/index.cjs.map +10 -0
  96. package/dist/cjs/internal/test-environment/index.cjs +1415 -0
  97. package/dist/cjs/internal/test-environment/index.cjs.map +10 -0
  98. package/dist/cjs/internal/timers/index.cjs +200 -0
  99. package/dist/cjs/internal/timers/index.cjs.map +10 -0
  100. package/dist/cjs/internal/transform/index.cjs +361 -0
  101. package/dist/cjs/internal/transform/index.cjs.map +10 -0
  102. package/dist/cjs/internal/typecheck/index.cjs +60 -0
  103. package/dist/cjs/internal/typecheck/index.cjs.map +10 -0
  104. package/dist/cjs/internal/typecheck/isolate-types.cjs +2614 -0
  105. package/dist/cjs/internal/typecheck/isolate-types.cjs.map +10 -0
  106. package/dist/cjs/internal/typecheck/typecheck.cjs +131 -0
  107. package/dist/cjs/internal/typecheck/typecheck.cjs.map +10 -0
  108. package/dist/cjs/modules/index.cjs +160 -0
  109. package/dist/cjs/modules/index.cjs.map +10 -0
  110. package/dist/cjs/package.json +5 -0
  111. package/dist/cjs/runtime/script-runtime.cjs +97 -0
  112. package/dist/cjs/runtime/script-runtime.cjs.map +10 -0
  113. package/dist/cjs/server/app-server.cjs +158 -0
  114. package/dist/cjs/server/app-server.cjs.map +10 -0
  115. package/dist/cjs/testing/integration-helpers.cjs +127 -0
  116. package/dist/cjs/testing/integration-helpers.cjs.map +10 -0
  117. package/dist/cjs/typecheck/index.cjs +96 -0
  118. package/dist/cjs/typecheck/index.cjs.map +10 -0
  119. package/dist/cjs/types.cjs +30 -0
  120. package/dist/cjs/types.cjs.map +9 -0
  121. package/dist/mjs/bridge/diagnostics.mjs +18 -0
  122. package/dist/mjs/bridge/diagnostics.mjs.map +10 -0
  123. package/dist/mjs/bridge/legacy-adapters.mjs +178 -0
  124. package/dist/mjs/bridge/legacy-adapters.mjs.map +10 -0
  125. package/dist/mjs/bridge/request-context.mjs +19 -0
  126. package/dist/mjs/bridge/request-context.mjs.map +10 -0
  127. package/dist/mjs/bridge/runtime-bindings.mjs +303 -0
  128. package/dist/mjs/bridge/runtime-bindings.mjs.map +10 -0
  129. package/dist/mjs/browser/browser-runtime.mjs +93 -0
  130. package/dist/mjs/browser/browser-runtime.mjs.map +10 -0
  131. package/dist/mjs/daemon.mjs +91 -0
  132. package/dist/mjs/daemon.mjs.map +10 -0
  133. package/dist/mjs/files/index.mjs +76 -0
  134. package/dist/mjs/files/index.mjs.map +10 -0
  135. package/dist/mjs/host/create-isolate-host.mjs +171 -0
  136. package/dist/mjs/host/create-isolate-host.mjs.map +10 -0
  137. package/dist/mjs/host/index.mjs +7 -0
  138. package/dist/mjs/host/index.mjs.map +10 -0
  139. package/dist/mjs/index.mjs +15 -0
  140. package/dist/mjs/index.mjs.map +10 -0
  141. package/dist/mjs/internal/client/connection.mjs +1872 -0
  142. package/dist/mjs/internal/client/connection.mjs.map +10 -0
  143. package/dist/mjs/internal/client/index.mjs +8 -0
  144. package/dist/mjs/internal/client/index.mjs.map +10 -0
  145. package/dist/mjs/internal/client/types.mjs +2 -0
  146. package/dist/mjs/internal/client/types.mjs.map +9 -0
  147. package/dist/mjs/internal/console/index.mjs +442 -0
  148. package/dist/mjs/internal/console/index.mjs.map +10 -0
  149. package/dist/mjs/internal/console/utils.mjs +30 -0
  150. package/dist/mjs/internal/console/utils.mjs.map +10 -0
  151. package/dist/mjs/internal/core/index.mjs +2681 -0
  152. package/dist/mjs/internal/core/index.mjs.map +10 -0
  153. package/dist/mjs/internal/crypto/index.mjs +406 -0
  154. package/dist/mjs/internal/crypto/index.mjs.map +10 -0
  155. package/dist/mjs/internal/daemon/callback-fs-handler.mjs +315 -0
  156. package/dist/mjs/internal/daemon/callback-fs-handler.mjs.map +10 -0
  157. package/dist/mjs/internal/daemon/connection.mjs +1931 -0
  158. package/dist/mjs/internal/daemon/connection.mjs.map +10 -0
  159. package/dist/mjs/internal/daemon/daemon.mjs +98 -0
  160. package/dist/mjs/internal/daemon/daemon.mjs.map +10 -0
  161. package/dist/mjs/internal/daemon/index.mjs +105 -0
  162. package/dist/mjs/internal/daemon/index.mjs.map +10 -0
  163. package/dist/mjs/internal/daemon/runtime-pool.mjs +66 -0
  164. package/dist/mjs/internal/daemon/runtime-pool.mjs.map +10 -0
  165. package/dist/mjs/internal/daemon/types.mjs +2 -0
  166. package/dist/mjs/internal/daemon/types.mjs.map +9 -0
  167. package/dist/mjs/internal/encoding/index.mjs +379 -0
  168. package/dist/mjs/internal/encoding/index.mjs.map +10 -0
  169. package/dist/mjs/internal/fetch/consistency/origins.mjs +558 -0
  170. package/dist/mjs/internal/fetch/consistency/origins.mjs.map +10 -0
  171. package/dist/mjs/internal/fetch/index.mjs +2580 -0
  172. package/dist/mjs/internal/fetch/index.mjs.map +10 -0
  173. package/dist/mjs/internal/fetch/stream-state.mjs +216 -0
  174. package/dist/mjs/internal/fetch/stream-state.mjs.map +10 -0
  175. package/dist/mjs/internal/fs/index.mjs +783 -0
  176. package/dist/mjs/internal/fs/index.mjs.map +10 -0
  177. package/dist/mjs/internal/fs/node-adapter.mjs +190 -0
  178. package/dist/mjs/internal/fs/node-adapter.mjs.map +10 -0
  179. package/dist/mjs/internal/module-loader/bundle.mjs +418 -0
  180. package/dist/mjs/internal/module-loader/bundle.mjs.map +10 -0
  181. package/dist/mjs/internal/module-loader/index.mjs +185 -0
  182. package/dist/mjs/internal/module-loader/index.mjs.map +10 -0
  183. package/dist/mjs/internal/module-loader/mappings.mjs +80 -0
  184. package/dist/mjs/internal/module-loader/mappings.mjs.map +10 -0
  185. package/dist/mjs/internal/module-loader/resolve.mjs +113 -0
  186. package/dist/mjs/internal/module-loader/resolve.mjs.map +10 -0
  187. package/dist/mjs/internal/module-loader/strip-types.mjs +172 -0
  188. package/dist/mjs/internal/module-loader/strip-types.mjs.map +10 -0
  189. package/dist/mjs/internal/path/index.mjs +463 -0
  190. package/dist/mjs/internal/path/index.mjs.map +10 -0
  191. package/dist/mjs/internal/playwright/client.mjs +13 -0
  192. package/dist/mjs/internal/playwright/client.mjs.map +10 -0
  193. package/dist/mjs/internal/playwright/handler.mjs +1378 -0
  194. package/dist/mjs/internal/playwright/handler.mjs.map +10 -0
  195. package/dist/mjs/internal/playwright/index.mjs +1234 -0
  196. package/dist/mjs/internal/playwright/index.mjs.map +10 -0
  197. package/dist/mjs/internal/playwright/types.mjs +7 -0
  198. package/dist/mjs/internal/playwright/types.mjs.map +10 -0
  199. package/dist/mjs/internal/protocol/codec.mjs +470 -0
  200. package/dist/mjs/internal/protocol/codec.mjs.map +10 -0
  201. package/dist/mjs/internal/protocol/framing.mjs +101 -0
  202. package/dist/mjs/internal/protocol/framing.mjs.map +10 -0
  203. package/dist/mjs/internal/protocol/index.mjs +98 -0
  204. package/dist/mjs/internal/protocol/index.mjs.map +10 -0
  205. package/dist/mjs/internal/protocol/marshalValue.mjs +494 -0
  206. package/dist/mjs/internal/protocol/marshalValue.mjs.map +10 -0
  207. package/dist/mjs/internal/protocol/serialization.mjs +69 -0
  208. package/dist/mjs/internal/protocol/serialization.mjs.map +10 -0
  209. package/dist/mjs/internal/protocol/types.mjs +141 -0
  210. package/dist/mjs/internal/protocol/types.mjs.map +10 -0
  211. package/dist/mjs/internal/runtime/index.mjs +1198 -0
  212. package/dist/mjs/internal/runtime/index.mjs.map +10 -0
  213. package/dist/mjs/internal/server/index.mjs +183 -0
  214. package/dist/mjs/internal/server/index.mjs.map +10 -0
  215. package/dist/mjs/internal/test-environment/index.mjs +1351 -0
  216. package/dist/mjs/internal/test-environment/index.mjs.map +10 -0
  217. package/dist/mjs/internal/timers/index.mjs +136 -0
  218. package/dist/mjs/internal/timers/index.mjs.map +10 -0
  219. package/dist/mjs/internal/transform/index.mjs +321 -0
  220. package/dist/mjs/internal/transform/index.mjs.map +10 -0
  221. package/dist/mjs/internal/typecheck/index.mjs +35 -0
  222. package/dist/mjs/internal/typecheck/index.mjs.map +10 -0
  223. package/dist/mjs/internal/typecheck/isolate-types.mjs +2574 -0
  224. package/dist/mjs/internal/typecheck/isolate-types.mjs.map +10 -0
  225. package/dist/mjs/internal/typecheck/typecheck.mjs +91 -0
  226. package/dist/mjs/internal/typecheck/typecheck.mjs.map +10 -0
  227. package/dist/mjs/modules/index.mjs +96 -0
  228. package/dist/mjs/modules/index.mjs.map +10 -0
  229. package/dist/mjs/package.json +5 -0
  230. package/dist/mjs/runtime/script-runtime.mjs +57 -0
  231. package/dist/mjs/runtime/script-runtime.mjs.map +10 -0
  232. package/dist/mjs/server/app-server.mjs +118 -0
  233. package/dist/mjs/server/app-server.mjs.map +10 -0
  234. package/dist/mjs/testing/integration-helpers.mjs +63 -0
  235. package/dist/mjs/testing/integration-helpers.mjs.map +10 -0
  236. package/dist/mjs/typecheck/index.mjs +56 -0
  237. package/dist/mjs/typecheck/index.mjs.map +10 -0
  238. package/dist/mjs/types.mjs +2 -0
  239. package/dist/mjs/types.mjs.map +9 -0
  240. package/dist/types/bridge/diagnostics.d.ts +12 -0
  241. package/dist/types/bridge/legacy-adapters.d.ts +14 -0
  242. package/dist/types/bridge/request-context.d.ts +10 -0
  243. package/dist/types/bridge/runtime-bindings.d.ts +14 -0
  244. package/dist/types/browser/browser-runtime.d.ts +3 -0
  245. package/dist/types/daemon.d.ts +2 -0
  246. package/dist/types/files/index.d.ts +5 -0
  247. package/dist/types/host/create-isolate-host.d.ts +2 -0
  248. package/dist/types/host/index.d.ts +1 -0
  249. package/dist/types/index.d.ts +5 -0
  250. package/dist/types/internal/client/connection.d.ts +9 -0
  251. package/dist/types/internal/client/index.d.ts +8 -0
  252. package/dist/types/internal/client/types.d.ts +198 -0
  253. package/dist/types/internal/console/index.d.ts +108 -0
  254. package/dist/types/internal/console/utils.d.ts +27 -0
  255. package/dist/types/internal/core/index.d.ts +119 -0
  256. package/dist/types/internal/crypto/index.d.ts +18 -0
  257. package/dist/types/internal/daemon/callback-fs-handler.d.ts +28 -0
  258. package/dist/types/internal/daemon/connection.d.ts +9 -0
  259. package/dist/types/internal/daemon/daemon.d.ts +2 -0
  260. package/dist/types/internal/daemon/index.d.ts +14 -0
  261. package/dist/types/internal/daemon/runtime-pool.d.ts +16 -0
  262. package/dist/types/internal/daemon/types.d.ts +211 -0
  263. package/dist/types/internal/encoding/index.d.ts +21 -0
  264. package/dist/types/internal/fetch/consistency/origins.d.ts +179 -0
  265. package/dist/types/internal/fetch/index.d.ts +93 -0
  266. package/dist/types/internal/fetch/stream-state.d.ts +65 -0
  267. package/dist/types/internal/fs/index.d.ts +70 -0
  268. package/dist/types/internal/fs/node-adapter.d.ts +24 -0
  269. package/dist/types/internal/module-loader/bundle.d.ts +33 -0
  270. package/dist/types/internal/module-loader/index.d.ts +30 -0
  271. package/dist/types/internal/module-loader/mappings.d.ts +47 -0
  272. package/dist/types/internal/module-loader/resolve.d.ts +26 -0
  273. package/dist/types/internal/module-loader/strip-types.d.ts +19 -0
  274. package/dist/types/internal/path/index.d.ts +23 -0
  275. package/dist/types/internal/playwright/client.d.ts +7 -0
  276. package/dist/types/internal/playwright/handler.d.ts +44 -0
  277. package/dist/types/internal/playwright/index.d.ts +14 -0
  278. package/dist/types/internal/playwright/types.d.ts +145 -0
  279. package/dist/types/internal/protocol/codec.d.ts +242 -0
  280. package/dist/types/internal/protocol/framing.d.ts +89 -0
  281. package/dist/types/internal/protocol/index.d.ts +10 -0
  282. package/dist/types/internal/protocol/marshalValue.d.ts +79 -0
  283. package/dist/types/internal/protocol/serialization.d.ts +23 -0
  284. package/dist/types/internal/protocol/types.d.ts +996 -0
  285. package/dist/types/internal/runtime/index.d.ts +200 -0
  286. package/dist/types/internal/server/index.d.ts +42 -0
  287. package/dist/types/internal/test-environment/index.d.ts +112 -0
  288. package/dist/types/internal/timers/index.d.ts +22 -0
  289. package/dist/types/internal/transform/index.d.ts +36 -0
  290. package/dist/types/internal/typecheck/index.d.ts +7 -0
  291. package/dist/types/internal/typecheck/isolate-types.d.ts +94 -0
  292. package/dist/types/internal/typecheck/typecheck.d.ts +148 -0
  293. package/dist/types/modules/index.d.ts +2 -0
  294. package/dist/types/runtime/script-runtime.d.ts +6 -0
  295. package/dist/types/server/app-server.d.ts +3 -0
  296. package/dist/types/testing/integration-helpers.d.ts +9 -0
  297. package/dist/types/typecheck/index.d.ts +8 -0
  298. package/dist/types/types.d.ts +233 -0
  299. package/package.json +82 -6
@@ -0,0 +1,847 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __toCommonJS = (from) => {
33
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
34
+ if (entry)
35
+ return entry;
36
+ entry = __defProp({}, "__esModule", { value: true });
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (var key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(entry, key))
40
+ __defProp(entry, key, {
41
+ get: __accessProp.bind(from, key),
42
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
43
+ });
44
+ }
45
+ __moduleCache.set(from, entry);
46
+ return entry;
47
+ };
48
+ var __moduleCache;
49
+ var __returnValue = (v) => v;
50
+ function __exportSetter(name, newValue) {
51
+ this[name] = __returnValue.bind(null, newValue);
52
+ }
53
+ var __export = (target, all) => {
54
+ for (var name in all)
55
+ __defProp(target, name, {
56
+ get: all[name],
57
+ enumerable: true,
58
+ configurable: true,
59
+ set: __exportSetter.bind(all, name)
60
+ });
61
+ };
62
+
63
+ // src/internal/fs/index.ts
64
+ var exports_fs = {};
65
+ __export(exports_fs, {
66
+ setupFs: () => setupFs,
67
+ createNodeFileSystemHandler: () => import_node_adapter.createNodeFileSystemHandler,
68
+ clearAllInstanceState: () => import_core.clearAllInstanceState
69
+ });
70
+ module.exports = __toCommonJS(exports_fs);
71
+ var import_isolated_vm = __toESM(require("isolated-vm"));
72
+ var import_core = require("../core/index.cjs");
73
+ var import_node_adapter = require("./node-adapter.cjs");
74
+ var instanceStateMap = new WeakMap;
75
+ var nextInstanceId = 1;
76
+ function getInstanceStateMapForContext(context) {
77
+ let map = instanceStateMap.get(context);
78
+ if (!map) {
79
+ map = new Map;
80
+ instanceStateMap.set(context, map);
81
+ }
82
+ return map;
83
+ }
84
+ function setupFileSystemDirectoryHandle(context, stateMap) {
85
+ const global = context.global;
86
+ global.setSync("__FileSystemDirectoryHandle_get_name", new import_isolated_vm.default.Callback((instanceId) => {
87
+ const state = stateMap.get(instanceId);
88
+ return state?.name ?? "";
89
+ }));
90
+ global.setSync("__FileSystemDirectoryHandle_get_path", new import_isolated_vm.default.Callback((instanceId) => {
91
+ const state = stateMap.get(instanceId);
92
+ return state?.path ?? "/";
93
+ }));
94
+ const getFileHandleRef = new import_isolated_vm.default.Reference(async (instanceId, name, optionsJson) => {
95
+ const state = stateMap.get(instanceId);
96
+ if (!state) {
97
+ throw new Error("[NotFoundError]Directory handle not found");
98
+ }
99
+ const options = JSON.parse(optionsJson);
100
+ const childPath = state.path === "/" ? `/${name}` : `${state.path}/${name}`;
101
+ try {
102
+ await state.handler.getFileHandle(childPath, options);
103
+ } catch (err) {
104
+ if (err instanceof Error) {
105
+ throw new Error(err.message);
106
+ }
107
+ throw err;
108
+ }
109
+ const fileInstanceId = nextInstanceId++;
110
+ const fileState = {
111
+ instanceId: fileInstanceId,
112
+ path: childPath,
113
+ name,
114
+ handler: state.handler
115
+ };
116
+ stateMap.set(fileInstanceId, fileState);
117
+ return JSON.stringify({ instanceId: fileInstanceId });
118
+ });
119
+ global.setSync("__FileSystemDirectoryHandle_getFileHandle_ref", getFileHandleRef);
120
+ const getDirectoryHandleRef = new import_isolated_vm.default.Reference(async (instanceId, name, optionsJson) => {
121
+ const state = stateMap.get(instanceId);
122
+ if (!state) {
123
+ throw new Error("[NotFoundError]Directory handle not found");
124
+ }
125
+ const options = JSON.parse(optionsJson);
126
+ const childPath = state.path === "/" ? `/${name}` : `${state.path}/${name}`;
127
+ try {
128
+ await state.handler.getDirectoryHandle(childPath, options);
129
+ } catch (err) {
130
+ if (err instanceof Error) {
131
+ throw new Error(err.message);
132
+ }
133
+ throw err;
134
+ }
135
+ const dirInstanceId = nextInstanceId++;
136
+ const dirState = {
137
+ instanceId: dirInstanceId,
138
+ path: childPath,
139
+ name,
140
+ handler: state.handler
141
+ };
142
+ stateMap.set(dirInstanceId, dirState);
143
+ return JSON.stringify({ instanceId: dirInstanceId });
144
+ });
145
+ global.setSync("__FileSystemDirectoryHandle_getDirectoryHandle_ref", getDirectoryHandleRef);
146
+ const removeEntryRef = new import_isolated_vm.default.Reference(async (instanceId, name, optionsJson) => {
147
+ const state = stateMap.get(instanceId);
148
+ if (!state) {
149
+ throw new Error("[NotFoundError]Directory handle not found");
150
+ }
151
+ const options = JSON.parse(optionsJson);
152
+ const childPath = state.path === "/" ? `/${name}` : `${state.path}/${name}`;
153
+ try {
154
+ await state.handler.removeEntry(childPath, options);
155
+ } catch (err) {
156
+ if (err instanceof Error) {
157
+ throw new Error(err.message);
158
+ }
159
+ throw err;
160
+ }
161
+ });
162
+ global.setSync("__FileSystemDirectoryHandle_removeEntry_ref", removeEntryRef);
163
+ const readDirectoryRef = new import_isolated_vm.default.Reference(async (instanceId) => {
164
+ const state = stateMap.get(instanceId);
165
+ if (!state) {
166
+ throw new Error("[NotFoundError]Directory handle not found");
167
+ }
168
+ try {
169
+ const entries = await state.handler.readDirectory(state.path);
170
+ const result = entries.map((entry) => {
171
+ const entryId = nextInstanceId++;
172
+ const entryPath = state.path === "/" ? `/${entry.name}` : `${state.path}/${entry.name}`;
173
+ if (entry.kind === "file") {
174
+ const fileState = {
175
+ instanceId: entryId,
176
+ path: entryPath,
177
+ name: entry.name,
178
+ handler: state.handler
179
+ };
180
+ stateMap.set(entryId, fileState);
181
+ } else {
182
+ const dirState = {
183
+ instanceId: entryId,
184
+ path: entryPath,
185
+ name: entry.name,
186
+ handler: state.handler
187
+ };
188
+ stateMap.set(entryId, dirState);
189
+ }
190
+ return {
191
+ name: entry.name,
192
+ kind: entry.kind,
193
+ instanceId: entryId
194
+ };
195
+ });
196
+ return JSON.stringify(result);
197
+ } catch (err) {
198
+ if (err instanceof Error) {
199
+ throw new Error(err.message);
200
+ }
201
+ throw err;
202
+ }
203
+ });
204
+ global.setSync("__FileSystemDirectoryHandle_readDirectory_ref", readDirectoryRef);
205
+ global.setSync("__FileSystemDirectoryHandle_isSameEntry", new import_isolated_vm.default.Callback((id1, id2) => {
206
+ const state1 = stateMap.get(id1);
207
+ const state2 = stateMap.get(id2);
208
+ if (!state1 || !state2)
209
+ return false;
210
+ return state1.path === state2.path;
211
+ }));
212
+ const resolveRef = new import_isolated_vm.default.Reference(async (instanceId, descendantId) => {
213
+ const state = stateMap.get(instanceId);
214
+ const descendantState = stateMap.get(descendantId);
215
+ if (!state || !descendantState) {
216
+ return "null";
217
+ }
218
+ const basePath = state.path === "/" ? "" : state.path;
219
+ if (!descendantState.path.startsWith(basePath + "/") && descendantState.path !== state.path) {
220
+ return "null";
221
+ }
222
+ const relativePath = descendantState.path.slice(basePath.length);
223
+ const components = relativePath.split("/").filter((c) => c.length > 0);
224
+ return JSON.stringify(components);
225
+ });
226
+ global.setSync("__FileSystemDirectoryHandle_resolve_ref", resolveRef);
227
+ const directoryHandleCode = `
228
+ (function() {
229
+ const _directoryHandleInstanceIds = new WeakMap();
230
+
231
+ function __decodeError(err) {
232
+ if (!(err instanceof Error)) return err;
233
+ const match = err.message.match(/^\\[(TypeError|RangeError|NotFoundError|TypeMismatchError|InvalidModificationError|Error)\\](.*)$/);
234
+ if (match) {
235
+ if (['NotFoundError', 'TypeMismatchError', 'InvalidModificationError'].includes(match[1])) {
236
+ return new DOMException(match[2], match[1]);
237
+ }
238
+ const ErrorType = globalThis[match[1]] || Error;
239
+ return new ErrorType(match[2]);
240
+ }
241
+ return err;
242
+ }
243
+
244
+ class FileSystemDirectoryHandle {
245
+ constructor(path, name) {
246
+ // Internal construction from instance ID
247
+ if (typeof path === 'number' && name === null) {
248
+ _directoryHandleInstanceIds.set(this, path);
249
+ return;
250
+ }
251
+ const instanceId = __FileSystemDirectoryHandle_construct(path, name);
252
+ _directoryHandleInstanceIds.set(this, instanceId);
253
+ }
254
+
255
+ static _fromInstanceId(instanceId) {
256
+ return new FileSystemDirectoryHandle(instanceId, null);
257
+ }
258
+
259
+ _getInstanceId() {
260
+ return _directoryHandleInstanceIds.get(this);
261
+ }
262
+
263
+ get kind() {
264
+ return 'directory';
265
+ }
266
+
267
+ get name() {
268
+ return __FileSystemDirectoryHandle_get_name(this._getInstanceId());
269
+ }
270
+
271
+ async getFileHandle(name, options = {}) {
272
+ try {
273
+ const resultJson = await __FileSystemDirectoryHandle_getFileHandle_ref.apply(
274
+ undefined,
275
+ [this._getInstanceId(), name, JSON.stringify(options)],
276
+ { result: { promise: true, copy: true } }
277
+ );
278
+ const result = JSON.parse(resultJson);
279
+ return FileSystemFileHandle._fromInstanceId(result.instanceId);
280
+ } catch (err) {
281
+ throw __decodeError(err);
282
+ }
283
+ }
284
+
285
+ async getDirectoryHandle(name, options = {}) {
286
+ try {
287
+ const resultJson = await __FileSystemDirectoryHandle_getDirectoryHandle_ref.apply(
288
+ undefined,
289
+ [this._getInstanceId(), name, JSON.stringify(options)],
290
+ { result: { promise: true, copy: true } }
291
+ );
292
+ const result = JSON.parse(resultJson);
293
+ return FileSystemDirectoryHandle._fromInstanceId(result.instanceId);
294
+ } catch (err) {
295
+ throw __decodeError(err);
296
+ }
297
+ }
298
+
299
+ async removeEntry(name, options = {}) {
300
+ try {
301
+ await __FileSystemDirectoryHandle_removeEntry_ref.apply(
302
+ undefined,
303
+ [this._getInstanceId(), name, JSON.stringify(options)],
304
+ { result: { promise: true, copy: true } }
305
+ );
306
+ } catch (err) {
307
+ throw __decodeError(err);
308
+ }
309
+ }
310
+
311
+ async *entries() {
312
+ let entriesJson;
313
+ try {
314
+ entriesJson = await __FileSystemDirectoryHandle_readDirectory_ref.apply(
315
+ undefined,
316
+ [this._getInstanceId()],
317
+ { result: { promise: true, copy: true } }
318
+ );
319
+ } catch (err) {
320
+ throw __decodeError(err);
321
+ }
322
+ const entries = JSON.parse(entriesJson);
323
+ for (const entry of entries) {
324
+ if (entry.kind === 'file') {
325
+ yield [entry.name, FileSystemFileHandle._fromInstanceId(entry.instanceId)];
326
+ } else {
327
+ yield [entry.name, FileSystemDirectoryHandle._fromInstanceId(entry.instanceId)];
328
+ }
329
+ }
330
+ }
331
+
332
+ async *keys() {
333
+ for await (const [name] of this.entries()) {
334
+ yield name;
335
+ }
336
+ }
337
+
338
+ async *values() {
339
+ for await (const [, handle] of this.entries()) {
340
+ yield handle;
341
+ }
342
+ }
343
+
344
+ [Symbol.asyncIterator]() {
345
+ return this.entries();
346
+ }
347
+
348
+ async isSameEntry(other) {
349
+ if (!(other instanceof FileSystemDirectoryHandle)) {
350
+ return false;
351
+ }
352
+ return __FileSystemDirectoryHandle_isSameEntry(
353
+ this._getInstanceId(),
354
+ other._getInstanceId()
355
+ );
356
+ }
357
+
358
+ async resolve(possibleDescendant) {
359
+ try {
360
+ const resultJson = await __FileSystemDirectoryHandle_resolve_ref.apply(
361
+ undefined,
362
+ [this._getInstanceId(), possibleDescendant._getInstanceId()],
363
+ { result: { promise: true, copy: true } }
364
+ );
365
+ return resultJson === 'null' ? null : JSON.parse(resultJson);
366
+ } catch (err) {
367
+ throw __decodeError(err);
368
+ }
369
+ }
370
+ }
371
+
372
+ globalThis.FileSystemDirectoryHandle = FileSystemDirectoryHandle;
373
+ })();
374
+ `;
375
+ context.evalSync(directoryHandleCode);
376
+ }
377
+ function setupFileSystemFileHandle(context, stateMap) {
378
+ const global = context.global;
379
+ global.setSync("__FileSystemFileHandle_get_name", new import_isolated_vm.default.Callback((instanceId) => {
380
+ const state = stateMap.get(instanceId);
381
+ return state?.name ?? "";
382
+ }));
383
+ global.setSync("__FileSystemFileHandle_get_path", new import_isolated_vm.default.Callback((instanceId) => {
384
+ const state = stateMap.get(instanceId);
385
+ return state?.path ?? "";
386
+ }));
387
+ const getFileRef = new import_isolated_vm.default.Reference(async (instanceId) => {
388
+ const state = stateMap.get(instanceId);
389
+ if (!state) {
390
+ throw new Error("[NotFoundError]File handle not found");
391
+ }
392
+ try {
393
+ const fileData = await state.handler.readFile(state.path);
394
+ return JSON.stringify({
395
+ name: state.name,
396
+ data: Array.from(fileData.data),
397
+ size: fileData.size,
398
+ lastModified: fileData.lastModified,
399
+ type: fileData.type
400
+ });
401
+ } catch (err) {
402
+ if (err instanceof Error) {
403
+ throw new Error(err.message);
404
+ }
405
+ throw err;
406
+ }
407
+ });
408
+ global.setSync("__FileSystemFileHandle_getFile_ref", getFileRef);
409
+ const createWritableRef = new import_isolated_vm.default.Reference(async (instanceId, _optionsJson) => {
410
+ const state = stateMap.get(instanceId);
411
+ if (!state) {
412
+ throw new Error("[NotFoundError]File handle not found");
413
+ }
414
+ const streamInstanceId = nextInstanceId++;
415
+ const streamState = {
416
+ instanceId: streamInstanceId,
417
+ filePath: state.path,
418
+ position: 0,
419
+ buffer: [],
420
+ closed: false,
421
+ handler: state.handler
422
+ };
423
+ stateMap.set(streamInstanceId, streamState);
424
+ return streamInstanceId;
425
+ });
426
+ global.setSync("__FileSystemFileHandle_createWritable_ref", createWritableRef);
427
+ global.setSync("__FileSystemFileHandle_isSameEntry", new import_isolated_vm.default.Callback((id1, id2) => {
428
+ const state1 = stateMap.get(id1);
429
+ const state2 = stateMap.get(id2);
430
+ if (!state1 || !state2)
431
+ return false;
432
+ return state1.path === state2.path;
433
+ }));
434
+ const fileHandleCode = `
435
+ (function() {
436
+ const _fileHandleInstanceIds = new WeakMap();
437
+
438
+ function __decodeError(err) {
439
+ if (!(err instanceof Error)) return err;
440
+ const match = err.message.match(/^\\[(TypeError|RangeError|NotFoundError|TypeMismatchError|InvalidModificationError|Error)\\](.*)$/);
441
+ if (match) {
442
+ if (['NotFoundError', 'TypeMismatchError', 'InvalidModificationError'].includes(match[1])) {
443
+ return new DOMException(match[2], match[1]);
444
+ }
445
+ const ErrorType = globalThis[match[1]] || Error;
446
+ return new ErrorType(match[2]);
447
+ }
448
+ return err;
449
+ }
450
+
451
+ class FileSystemFileHandle {
452
+ constructor(path, name) {
453
+ // Internal construction from instance ID
454
+ if (typeof path === 'number' && name === null) {
455
+ _fileHandleInstanceIds.set(this, path);
456
+ return;
457
+ }
458
+ const instanceId = __FileSystemFileHandle_construct(path, name);
459
+ _fileHandleInstanceIds.set(this, instanceId);
460
+ }
461
+
462
+ static _fromInstanceId(instanceId) {
463
+ return new FileSystemFileHandle(instanceId, null);
464
+ }
465
+
466
+ _getInstanceId() {
467
+ return _fileHandleInstanceIds.get(this);
468
+ }
469
+
470
+ get kind() {
471
+ return 'file';
472
+ }
473
+
474
+ get name() {
475
+ return __FileSystemFileHandle_get_name(this._getInstanceId());
476
+ }
477
+
478
+ async getFile() {
479
+ try {
480
+ const metadataJson = await __FileSystemFileHandle_getFile_ref.apply(
481
+ undefined,
482
+ [this._getInstanceId()],
483
+ { result: { promise: true, copy: true } }
484
+ );
485
+ const metadata = JSON.parse(metadataJson);
486
+ // Create File object from metadata and content
487
+ const content = new Uint8Array(metadata.data);
488
+ return new File([content], metadata.name, {
489
+ type: metadata.type,
490
+ lastModified: metadata.lastModified
491
+ });
492
+ } catch (err) {
493
+ throw __decodeError(err);
494
+ }
495
+ }
496
+
497
+ async createWritable(options = {}) {
498
+ try {
499
+ const streamId = await __FileSystemFileHandle_createWritable_ref.apply(
500
+ undefined,
501
+ [this._getInstanceId(), JSON.stringify(options)],
502
+ { result: { promise: true, copy: true } }
503
+ );
504
+ return FileSystemWritableFileStream._fromInstanceId(streamId);
505
+ } catch (err) {
506
+ throw __decodeError(err);
507
+ }
508
+ }
509
+
510
+ async isSameEntry(other) {
511
+ if (!(other instanceof FileSystemFileHandle)) {
512
+ return false;
513
+ }
514
+ return __FileSystemFileHandle_isSameEntry(
515
+ this._getInstanceId(),
516
+ other._getInstanceId()
517
+ );
518
+ }
519
+ }
520
+
521
+ globalThis.FileSystemFileHandle = FileSystemFileHandle;
522
+ })();
523
+ `;
524
+ context.evalSync(fileHandleCode);
525
+ }
526
+ function setupFileSystemWritableFileStream(context, stateMap) {
527
+ const global = context.global;
528
+ const writeRef = new import_isolated_vm.default.Reference(async (instanceId, bytesJson, position) => {
529
+ const state = stateMap.get(instanceId);
530
+ if (!state) {
531
+ throw new Error("[InvalidStateError]Stream not found");
532
+ }
533
+ if (state.closed) {
534
+ throw new Error("[InvalidStateError]Stream is closed");
535
+ }
536
+ const bytes = JSON.parse(bytesJson);
537
+ const data = new Uint8Array(bytes);
538
+ if (position !== null) {
539
+ state.position = position;
540
+ }
541
+ try {
542
+ await state.handler.writeFile(state.filePath, data, state.position);
543
+ state.position += data.length;
544
+ } catch (err) {
545
+ if (err instanceof Error) {
546
+ throw new Error(err.message);
547
+ }
548
+ throw err;
549
+ }
550
+ });
551
+ global.setSync("__FileSystemWritableFileStream_write_ref", writeRef);
552
+ global.setSync("__FileSystemWritableFileStream_seek", new import_isolated_vm.default.Callback((instanceId, position) => {
553
+ const state = stateMap.get(instanceId);
554
+ if (!state) {
555
+ throw new Error("[InvalidStateError]Stream not found");
556
+ }
557
+ if (state.closed) {
558
+ throw new Error("[InvalidStateError]Stream is closed");
559
+ }
560
+ state.position = position;
561
+ }));
562
+ const truncateRef = new import_isolated_vm.default.Reference(async (instanceId, size) => {
563
+ const state = stateMap.get(instanceId);
564
+ if (!state) {
565
+ throw new Error("[InvalidStateError]Stream not found");
566
+ }
567
+ if (state.closed) {
568
+ throw new Error("[InvalidStateError]Stream is closed");
569
+ }
570
+ try {
571
+ await state.handler.truncateFile(state.filePath, size);
572
+ if (state.position > size) {
573
+ state.position = size;
574
+ }
575
+ } catch (err) {
576
+ if (err instanceof Error) {
577
+ throw new Error(err.message);
578
+ }
579
+ throw err;
580
+ }
581
+ });
582
+ global.setSync("__FileSystemWritableFileStream_truncate_ref", truncateRef);
583
+ const closeRef = new import_isolated_vm.default.Reference(async (instanceId) => {
584
+ const state = stateMap.get(instanceId);
585
+ if (!state) {
586
+ throw new Error("[InvalidStateError]Stream not found");
587
+ }
588
+ if (state.closed) {
589
+ throw new Error("[InvalidStateError]Stream is already closed");
590
+ }
591
+ state.closed = true;
592
+ });
593
+ global.setSync("__FileSystemWritableFileStream_close_ref", closeRef);
594
+ const abortRef = new import_isolated_vm.default.Reference(async (instanceId, _reason) => {
595
+ const state = stateMap.get(instanceId);
596
+ if (!state) {
597
+ throw new Error("[InvalidStateError]Stream not found");
598
+ }
599
+ state.closed = true;
600
+ state.buffer = [];
601
+ });
602
+ global.setSync("__FileSystemWritableFileStream_abort_ref", abortRef);
603
+ global.setSync("__FileSystemWritableFileStream_get_locked", new import_isolated_vm.default.Callback((instanceId) => {
604
+ const state = stateMap.get(instanceId);
605
+ return state ? !state.closed : false;
606
+ }));
607
+ const writableStreamCode = `
608
+ (function() {
609
+ const _writableStreamInstanceIds = new WeakMap();
610
+
611
+ function __decodeError(err) {
612
+ if (!(err instanceof Error)) return err;
613
+ const match = err.message.match(/^\\[(TypeError|RangeError|InvalidStateError|NotFoundError|Error)\\](.*)$/);
614
+ if (match) {
615
+ if (['InvalidStateError', 'NotFoundError'].includes(match[1])) {
616
+ return new DOMException(match[2], match[1]);
617
+ }
618
+ const ErrorType = globalThis[match[1]] || Error;
619
+ return new ErrorType(match[2]);
620
+ }
621
+ return err;
622
+ }
623
+
624
+ class FileSystemWritableFileStream {
625
+ constructor(instanceId) {
626
+ _writableStreamInstanceIds.set(this, instanceId);
627
+ }
628
+
629
+ static _fromInstanceId(instanceId) {
630
+ return new FileSystemWritableFileStream(instanceId);
631
+ }
632
+
633
+ _getInstanceId() {
634
+ return _writableStreamInstanceIds.get(this);
635
+ }
636
+
637
+ async write(data) {
638
+ try {
639
+ // Handle different data types
640
+ let writeData;
641
+ let position = null;
642
+ let type = 'write';
643
+
644
+ if (data && typeof data === 'object' && !ArrayBuffer.isView(data) &&
645
+ !(data instanceof Blob) && !(data instanceof ArrayBuffer) &&
646
+ !Array.isArray(data) && typeof data.type === 'string') {
647
+ // WriteParams object: { type, data, position, size }
648
+ type = data.type || 'write';
649
+ if (type === 'seek') {
650
+ return this.seek(data.position);
651
+ }
652
+ if (type === 'truncate') {
653
+ return this.truncate(data.size);
654
+ }
655
+ writeData = data.data;
656
+ position = data.position ?? null;
657
+ } else {
658
+ writeData = data;
659
+ }
660
+
661
+ // Convert data to bytes array for transfer
662
+ let bytes;
663
+ if (typeof writeData === 'string') {
664
+ bytes = Array.from(new TextEncoder().encode(writeData));
665
+ } else if (writeData instanceof Blob) {
666
+ const buffer = await writeData.arrayBuffer();
667
+ bytes = Array.from(new Uint8Array(buffer));
668
+ } else if (writeData instanceof ArrayBuffer) {
669
+ bytes = Array.from(new Uint8Array(writeData));
670
+ } else if (ArrayBuffer.isView(writeData)) {
671
+ bytes = Array.from(new Uint8Array(writeData.buffer, writeData.byteOffset, writeData.byteLength));
672
+ } else if (Array.isArray(writeData)) {
673
+ bytes = writeData;
674
+ } else {
675
+ throw new TypeError('Invalid data type for write');
676
+ }
677
+
678
+ await __FileSystemWritableFileStream_write_ref.apply(
679
+ undefined,
680
+ [this._getInstanceId(), JSON.stringify(bytes), position],
681
+ { result: { promise: true, copy: true } }
682
+ );
683
+ } catch (err) {
684
+ throw __decodeError(err);
685
+ }
686
+ }
687
+
688
+ seek(position) {
689
+ try {
690
+ __FileSystemWritableFileStream_seek(this._getInstanceId(), position);
691
+ } catch (err) {
692
+ throw __decodeError(err);
693
+ }
694
+ }
695
+
696
+ async truncate(size) {
697
+ try {
698
+ await __FileSystemWritableFileStream_truncate_ref.apply(
699
+ undefined,
700
+ [this._getInstanceId(), size],
701
+ { result: { promise: true, copy: true } }
702
+ );
703
+ } catch (err) {
704
+ throw __decodeError(err);
705
+ }
706
+ }
707
+
708
+ async close() {
709
+ try {
710
+ await __FileSystemWritableFileStream_close_ref.apply(
711
+ undefined,
712
+ [this._getInstanceId()],
713
+ { result: { promise: true, copy: true } }
714
+ );
715
+ } catch (err) {
716
+ throw __decodeError(err);
717
+ }
718
+ }
719
+
720
+ async abort(reason) {
721
+ try {
722
+ await __FileSystemWritableFileStream_abort_ref.apply(
723
+ undefined,
724
+ [this._getInstanceId(), reason ? String(reason) : null],
725
+ { result: { promise: true, copy: true } }
726
+ );
727
+ } catch (err) {
728
+ throw __decodeError(err);
729
+ }
730
+ }
731
+
732
+ get locked() {
733
+ return __FileSystemWritableFileStream_get_locked(this._getInstanceId());
734
+ }
735
+
736
+ getWriter() {
737
+ const stream = this;
738
+ let released = false;
739
+ let closedResolve;
740
+ let closedReject;
741
+ const closedPromise = new Promise((resolve, reject) => {
742
+ closedResolve = resolve;
743
+ closedReject = reject;
744
+ });
745
+
746
+ return {
747
+ get closed() {
748
+ return closedPromise;
749
+ },
750
+ get desiredSize() {
751
+ return 1;
752
+ },
753
+ get ready() {
754
+ return Promise.resolve();
755
+ },
756
+ async write(chunk) {
757
+ if (released) {
758
+ return Promise.reject(new TypeError('Writer has been released'));
759
+ }
760
+ try {
761
+ await stream.write(chunk);
762
+ return Promise.resolve();
763
+ } catch (err) {
764
+ return Promise.reject(err);
765
+ }
766
+ },
767
+ async close() {
768
+ if (released) {
769
+ return Promise.reject(new TypeError('Writer has been released'));
770
+ }
771
+ try {
772
+ await stream.close();
773
+ closedResolve();
774
+ return Promise.resolve();
775
+ } catch (err) {
776
+ closedReject(err);
777
+ return Promise.reject(err);
778
+ }
779
+ },
780
+ async abort(reason) {
781
+ if (released) {
782
+ return Promise.reject(new TypeError('Writer has been released'));
783
+ }
784
+ try {
785
+ await stream.abort(reason);
786
+ closedReject(reason || new Error('Stream aborted'));
787
+ return Promise.resolve();
788
+ } catch (err) {
789
+ return Promise.reject(err);
790
+ }
791
+ },
792
+ releaseLock() {
793
+ released = true;
794
+ }
795
+ };
796
+ }
797
+ }
798
+
799
+ globalThis.FileSystemWritableFileStream = FileSystemWritableFileStream;
800
+ })();
801
+ `;
802
+ context.evalSync(writableStreamCode);
803
+ }
804
+ function setupGetDirectoryGlobal(context, stateMap, options) {
805
+ const global = context.global;
806
+ const getDirectoryRef = new import_isolated_vm.default.Reference(async (path) => {
807
+ const handler = await options.getDirectory(path);
808
+ const instanceId = nextInstanceId++;
809
+ const state = {
810
+ instanceId,
811
+ path: "/",
812
+ name: path.split("/").filter(Boolean).pop() || "",
813
+ handler
814
+ };
815
+ stateMap.set(instanceId, state);
816
+ return instanceId;
817
+ });
818
+ global.setSync("__getDirectory_ref", getDirectoryRef);
819
+ const getDirectoryCode = `
820
+ (function() {
821
+ globalThis.getDirectory = async function(path) {
822
+ const instanceId = await __getDirectory_ref.apply(
823
+ undefined,
824
+ [path],
825
+ { result: { promise: true, copy: true } }
826
+ );
827
+ return FileSystemDirectoryHandle._fromInstanceId(instanceId);
828
+ };
829
+ })();
830
+ `;
831
+ context.evalSync(getDirectoryCode);
832
+ }
833
+ async function setupFs(context, options) {
834
+ await import_core.setupCore(context);
835
+ const stateMap = getInstanceStateMapForContext(context);
836
+ setupFileSystemDirectoryHandle(context, stateMap);
837
+ setupFileSystemFileHandle(context, stateMap);
838
+ setupFileSystemWritableFileStream(context, stateMap);
839
+ setupGetDirectoryGlobal(context, stateMap, options);
840
+ return {
841
+ dispose() {
842
+ stateMap.clear();
843
+ }
844
+ };
845
+ }
846
+
847
+ //# debugId=ADBCB5895F0DF93F64756E2164756E21