@heojeongbo/wirestage 0.0.0-stage → 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 (489) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSES.md +21 -0
  3. package/README.md +150 -2
  4. package/dist/app/playwright/index.d.ts +3 -0
  5. package/dist/app/playwright/index.d.ts.map +1 -0
  6. package/dist/app/playwright/index.js +2 -0
  7. package/dist/app/playwright/index.js.map +1 -0
  8. package/dist/app/playwright/lib/fixture.d.ts +61 -0
  9. package/dist/app/playwright/lib/fixture.d.ts.map +1 -0
  10. package/dist/app/playwright/lib/fixture.js +110 -0
  11. package/dist/app/playwright/lib/fixture.js.map +1 -0
  12. package/dist/connect.d.ts +7 -0
  13. package/dist/connect.d.ts.map +1 -0
  14. package/dist/connect.js +7 -0
  15. package/dist/connect.js.map +1 -0
  16. package/dist/entities/frame/@x/plugin.d.ts +9 -0
  17. package/dist/entities/frame/@x/plugin.d.ts.map +1 -0
  18. package/dist/entities/frame/@x/plugin.js +2 -0
  19. package/dist/entities/frame/@x/plugin.js.map +1 -0
  20. package/dist/entities/frame/index.d.ts +6 -0
  21. package/dist/entities/frame/index.d.ts.map +1 -0
  22. package/dist/entities/frame/index.js +4 -0
  23. package/dist/entities/frame/index.js.map +1 -0
  24. package/dist/entities/frame/lib/filter.d.ts +8 -0
  25. package/dist/entities/frame/lib/filter.d.ts.map +1 -0
  26. package/dist/entities/frame/lib/filter.js +62 -0
  27. package/dist/entities/frame/lib/filter.js.map +1 -0
  28. package/dist/entities/frame/lib/payload.d.ts +8 -0
  29. package/dist/entities/frame/lib/payload.d.ts.map +1 -0
  30. package/dist/entities/frame/lib/payload.js +42 -0
  31. package/dist/entities/frame/lib/payload.js.map +1 -0
  32. package/dist/entities/frame/lib/snapshot.d.ts +15 -0
  33. package/dist/entities/frame/lib/snapshot.d.ts.map +1 -0
  34. package/dist/entities/frame/lib/snapshot.js +90 -0
  35. package/dist/entities/frame/lib/snapshot.js.map +1 -0
  36. package/dist/entities/frame/lib/timeline.d.ts +23 -0
  37. package/dist/entities/frame/lib/timeline.d.ts.map +1 -0
  38. package/dist/entities/frame/lib/timeline.js +122 -0
  39. package/dist/entities/frame/lib/timeline.js.map +1 -0
  40. package/dist/entities/frame/model/frame.d.ts +182 -0
  41. package/dist/entities/frame/model/frame.d.ts.map +1 -0
  42. package/dist/entities/frame/model/frame.js +2 -0
  43. package/dist/entities/frame/model/frame.js.map +1 -0
  44. package/dist/entities/plugin/index.d.ts +9 -0
  45. package/dist/entities/plugin/index.d.ts.map +1 -0
  46. package/dist/entities/plugin/index.js +3 -0
  47. package/dist/entities/plugin/index.js.map +1 -0
  48. package/dist/entities/plugin/lib/define-plugin.d.ts +8 -0
  49. package/dist/entities/plugin/lib/define-plugin.d.ts.map +1 -0
  50. package/dist/entities/plugin/lib/define-plugin.js +9 -0
  51. package/dist/entities/plugin/lib/define-plugin.js.map +1 -0
  52. package/dist/entities/plugin/lib/named.d.ts +10 -0
  53. package/dist/entities/plugin/lib/named.d.ts.map +1 -0
  54. package/dist/entities/plugin/lib/named.js +17 -0
  55. package/dist/entities/plugin/lib/named.js.map +1 -0
  56. package/dist/entities/plugin/model/attachment.d.ts +18 -0
  57. package/dist/entities/plugin/model/attachment.d.ts.map +1 -0
  58. package/dist/entities/plugin/model/attachment.js +2 -0
  59. package/dist/entities/plugin/model/attachment.js.map +1 -0
  60. package/dist/entities/plugin/model/http.d.ts +126 -0
  61. package/dist/entities/plugin/model/http.d.ts.map +1 -0
  62. package/dist/entities/plugin/model/http.js +2 -0
  63. package/dist/entities/plugin/model/http.js.map +1 -0
  64. package/dist/entities/plugin/model/page.d.ts +100 -0
  65. package/dist/entities/plugin/model/page.d.ts.map +1 -0
  66. package/dist/entities/plugin/model/page.js +2 -0
  67. package/dist/entities/plugin/model/page.js.map +1 -0
  68. package/dist/entities/plugin/model/plugin.d.ts +83 -0
  69. package/dist/entities/plugin/model/plugin.d.ts.map +1 -0
  70. package/dist/entities/plugin/model/plugin.js +2 -0
  71. package/dist/entities/plugin/model/plugin.js.map +1 -0
  72. package/dist/entities/plugin/model/socket.d.ts +102 -0
  73. package/dist/entities/plugin/model/socket.d.ts.map +1 -0
  74. package/dist/entities/plugin/model/socket.js +2 -0
  75. package/dist/entities/plugin/model/socket.js.map +1 -0
  76. package/dist/entities/plugin/model/stream.d.ts +43 -0
  77. package/dist/entities/plugin/model/stream.d.ts.map +1 -0
  78. package/dist/entities/plugin/model/stream.js +2 -0
  79. package/dist/entities/plugin/model/stream.js.map +1 -0
  80. package/dist/features/connect/index.d.ts +5 -0
  81. package/dist/features/connect/index.d.ts.map +1 -0
  82. package/dist/features/connect/index.js +4 -0
  83. package/dist/features/connect/index.js.map +1 -0
  84. package/dist/features/connect/lib/calls.d.ts +9 -0
  85. package/dist/features/connect/lib/calls.d.ts.map +1 -0
  86. package/dist/features/connect/lib/calls.js +46 -0
  87. package/dist/features/connect/lib/calls.js.map +1 -0
  88. package/dist/features/connect/lib/client.d.ts +33 -0
  89. package/dist/features/connect/lib/client.d.ts.map +1 -0
  90. package/dist/features/connect/lib/client.js +147 -0
  91. package/dist/features/connect/lib/client.js.map +1 -0
  92. package/dist/features/connect/lib/create-connect.d.ts +14 -0
  93. package/dist/features/connect/lib/create-connect.d.ts.map +1 -0
  94. package/dist/features/connect/lib/create-connect.js +124 -0
  95. package/dist/features/connect/lib/create-connect.js.map +1 -0
  96. package/dist/features/connect/lib/faults.d.ts +18 -0
  97. package/dist/features/connect/lib/faults.d.ts.map +1 -0
  98. package/dist/features/connect/lib/faults.js +85 -0
  99. package/dist/features/connect/lib/faults.js.map +1 -0
  100. package/dist/features/connect/lib/protocol.d.ts +42 -0
  101. package/dist/features/connect/lib/protocol.d.ts.map +1 -0
  102. package/dist/features/connect/lib/protocol.js +228 -0
  103. package/dist/features/connect/lib/protocol.js.map +1 -0
  104. package/dist/features/connect/lib/record.d.ts +14 -0
  105. package/dist/features/connect/lib/record.d.ts.map +1 -0
  106. package/dist/features/connect/lib/record.js +36 -0
  107. package/dist/features/connect/lib/record.js.map +1 -0
  108. package/dist/features/connect/lib/recorder.d.ts +77 -0
  109. package/dist/features/connect/lib/recorder.d.ts.map +1 -0
  110. package/dist/features/connect/lib/recorder.js +209 -0
  111. package/dist/features/connect/lib/recorder.js.map +1 -0
  112. package/dist/features/connect/lib/rules.d.ts +51 -0
  113. package/dist/features/connect/lib/rules.d.ts.map +1 -0
  114. package/dist/features/connect/lib/rules.js +222 -0
  115. package/dist/features/connect/lib/rules.js.map +1 -0
  116. package/dist/features/connect/lib/serve.d.ts +10 -0
  117. package/dist/features/connect/lib/serve.d.ts.map +1 -0
  118. package/dist/features/connect/lib/serve.js +78 -0
  119. package/dist/features/connect/lib/serve.js.map +1 -0
  120. package/dist/features/connect/lib/status-of.d.ts +11 -0
  121. package/dist/features/connect/lib/status-of.d.ts.map +1 -0
  122. package/dist/features/connect/lib/status-of.js +22 -0
  123. package/dist/features/connect/lib/status-of.js.map +1 -0
  124. package/dist/features/connect/lib/stubs.d.ts +18 -0
  125. package/dist/features/connect/lib/stubs.d.ts.map +1 -0
  126. package/dist/features/connect/lib/stubs.js +174 -0
  127. package/dist/features/connect/lib/stubs.js.map +1 -0
  128. package/dist/features/connect/lib/universal.d.ts +19 -0
  129. package/dist/features/connect/lib/universal.d.ts.map +1 -0
  130. package/dist/features/connect/lib/universal.js +71 -0
  131. package/dist/features/connect/lib/universal.js.map +1 -0
  132. package/dist/features/connect/model/types.d.ts +247 -0
  133. package/dist/features/connect/model/types.d.ts.map +1 -0
  134. package/dist/features/connect/model/types.js +2 -0
  135. package/dist/features/connect/model/types.js.map +1 -0
  136. package/dist/features/rest/index.d.ts +5 -0
  137. package/dist/features/rest/index.d.ts.map +1 -0
  138. package/dist/features/rest/index.js +3 -0
  139. package/dist/features/rest/index.js.map +1 -0
  140. package/dist/features/rest/lib/calls.d.ts +8 -0
  141. package/dist/features/rest/lib/calls.d.ts.map +1 -0
  142. package/dist/features/rest/lib/calls.js +32 -0
  143. package/dist/features/rest/lib/calls.js.map +1 -0
  144. package/dist/features/rest/lib/create-rest.d.ts +8 -0
  145. package/dist/features/rest/lib/create-rest.d.ts.map +1 -0
  146. package/dist/features/rest/lib/create-rest.js +136 -0
  147. package/dist/features/rest/lib/create-rest.js.map +1 -0
  148. package/dist/features/rest/lib/path.d.ts +14 -0
  149. package/dist/features/rest/lib/path.d.ts.map +1 -0
  150. package/dist/features/rest/lib/path.js +58 -0
  151. package/dist/features/rest/lib/path.js.map +1 -0
  152. package/dist/features/rest/lib/reply.d.ts +25 -0
  153. package/dist/features/rest/lib/reply.d.ts.map +1 -0
  154. package/dist/features/rest/lib/reply.js +40 -0
  155. package/dist/features/rest/lib/reply.js.map +1 -0
  156. package/dist/features/rest/model/types.d.ts +74 -0
  157. package/dist/features/rest/model/types.d.ts.map +1 -0
  158. package/dist/features/rest/model/types.js +2 -0
  159. package/dist/features/rest/model/types.js.map +1 -0
  160. package/dist/features/sse/index.d.ts +4 -0
  161. package/dist/features/sse/index.d.ts.map +1 -0
  162. package/dist/features/sse/index.js +3 -0
  163. package/dist/features/sse/index.js.map +1 -0
  164. package/dist/features/sse/lib/create-sse.d.ts +9 -0
  165. package/dist/features/sse/lib/create-sse.d.ts.map +1 -0
  166. package/dist/features/sse/lib/create-sse.js +120 -0
  167. package/dist/features/sse/lib/create-sse.js.map +1 -0
  168. package/dist/features/sse/lib/encode.d.ts +8 -0
  169. package/dist/features/sse/lib/encode.d.ts.map +1 -0
  170. package/dist/features/sse/lib/encode.js +29 -0
  171. package/dist/features/sse/lib/encode.js.map +1 -0
  172. package/dist/features/sse/model/types.d.ts +62 -0
  173. package/dist/features/sse/model/types.d.ts.map +1 -0
  174. package/dist/features/sse/model/types.js +2 -0
  175. package/dist/features/sse/model/types.js.map +1 -0
  176. package/dist/features/webrtc/index.d.ts +3 -0
  177. package/dist/features/webrtc/index.d.ts.map +1 -0
  178. package/dist/features/webrtc/index.js +2 -0
  179. package/dist/features/webrtc/index.js.map +1 -0
  180. package/dist/features/webrtc/lib/create-webrtc.d.ts +9 -0
  181. package/dist/features/webrtc/lib/create-webrtc.d.ts.map +1 -0
  182. package/dist/features/webrtc/lib/create-webrtc.js +123 -0
  183. package/dist/features/webrtc/lib/create-webrtc.js.map +1 -0
  184. package/dist/features/webrtc/lib/rtc-page-module.d.ts +22 -0
  185. package/dist/features/webrtc/lib/rtc-page-module.d.ts.map +1 -0
  186. package/dist/features/webrtc/lib/rtc-page-module.js +161 -0
  187. package/dist/features/webrtc/lib/rtc-page-module.js.map +1 -0
  188. package/dist/features/webrtc/lib/to-frame.d.ts +9 -0
  189. package/dist/features/webrtc/lib/to-frame.d.ts.map +1 -0
  190. package/dist/features/webrtc/lib/to-frame.js +43 -0
  191. package/dist/features/webrtc/lib/to-frame.js.map +1 -0
  192. package/dist/features/webrtc/model/types.d.ts +70 -0
  193. package/dist/features/webrtc/model/types.d.ts.map +1 -0
  194. package/dist/features/webrtc/model/types.js +2 -0
  195. package/dist/features/webrtc/model/types.js.map +1 -0
  196. package/dist/features/websocket/index.d.ts +3 -0
  197. package/dist/features/websocket/index.d.ts.map +1 -0
  198. package/dist/features/websocket/index.js +2 -0
  199. package/dist/features/websocket/index.js.map +1 -0
  200. package/dist/features/websocket/lib/create-websocket.d.ts +9 -0
  201. package/dist/features/websocket/lib/create-websocket.d.ts.map +1 -0
  202. package/dist/features/websocket/lib/create-websocket.js +34 -0
  203. package/dist/features/websocket/lib/create-websocket.js.map +1 -0
  204. package/dist/features/websocket/lib/mock.d.ts +6 -0
  205. package/dist/features/websocket/lib/mock.d.ts.map +1 -0
  206. package/dist/features/websocket/lib/mock.js +96 -0
  207. package/dist/features/websocket/lib/mock.js.map +1 -0
  208. package/dist/features/websocket/lib/proxy.d.ts +9 -0
  209. package/dist/features/websocket/lib/proxy.d.ts.map +1 -0
  210. package/dist/features/websocket/lib/proxy.js +107 -0
  211. package/dist/features/websocket/lib/proxy.js.map +1 -0
  212. package/dist/features/websocket/lib/wire.d.ts +16 -0
  213. package/dist/features/websocket/lib/wire.d.ts.map +1 -0
  214. package/dist/features/websocket/lib/wire.js +46 -0
  215. package/dist/features/websocket/lib/wire.js.map +1 -0
  216. package/dist/features/websocket/model/types.d.ts +129 -0
  217. package/dist/features/websocket/model/types.d.ts.map +1 -0
  218. package/dist/features/websocket/model/types.js +2 -0
  219. package/dist/features/websocket/model/types.js.map +1 -0
  220. package/dist/index.d.ts +27 -0
  221. package/dist/index.d.ts.map +1 -0
  222. package/dist/index.js +16 -0
  223. package/dist/index.js.map +1 -0
  224. package/dist/playwright.d.ts +4 -0
  225. package/dist/playwright.d.ts.map +1 -0
  226. package/dist/playwright.js +2 -0
  227. package/dist/playwright.js.map +1 -0
  228. package/dist/rest.d.ts +3 -0
  229. package/dist/rest.d.ts.map +1 -0
  230. package/dist/rest.js +3 -0
  231. package/dist/rest.js.map +1 -0
  232. package/dist/shared/api/http-server/index.d.ts +3 -0
  233. package/dist/shared/api/http-server/index.d.ts.map +1 -0
  234. package/dist/shared/api/http-server/index.js +2 -0
  235. package/dist/shared/api/http-server/index.js.map +1 -0
  236. package/dist/shared/api/http-server/listen.d.ts +25 -0
  237. package/dist/shared/api/http-server/listen.d.ts.map +1 -0
  238. package/dist/shared/api/http-server/listen.js +44 -0
  239. package/dist/shared/api/http-server/listen.js.map +1 -0
  240. package/dist/shared/api/playwright/index.d.ts +2 -0
  241. package/dist/shared/api/playwright/index.d.ts.map +1 -0
  242. package/dist/shared/api/playwright/index.js +2 -0
  243. package/dist/shared/api/playwright/index.js.map +1 -0
  244. package/dist/shared/api/playwright/ports.d.ts +117 -0
  245. package/dist/shared/api/playwright/ports.d.ts.map +1 -0
  246. package/dist/shared/api/playwright/ports.js +11 -0
  247. package/dist/shared/api/playwright/ports.js.map +1 -0
  248. package/dist/shared/api/stream-server/index.d.ts +3 -0
  249. package/dist/shared/api/stream-server/index.d.ts.map +1 -0
  250. package/dist/shared/api/stream-server/index.js +2 -0
  251. package/dist/shared/api/stream-server/index.js.map +1 -0
  252. package/dist/shared/api/stream-server/stream-server.d.ts +43 -0
  253. package/dist/shared/api/stream-server/stream-server.d.ts.map +1 -0
  254. package/dist/shared/api/stream-server/stream-server.js +160 -0
  255. package/dist/shared/api/stream-server/stream-server.js.map +1 -0
  256. package/dist/shared/lib/async/arrivals.d.ts +31 -0
  257. package/dist/shared/lib/async/arrivals.d.ts.map +1 -0
  258. package/dist/shared/lib/async/arrivals.js +57 -0
  259. package/dist/shared/lib/async/arrivals.js.map +1 -0
  260. package/dist/shared/lib/async/async-queue.d.ts +23 -0
  261. package/dist/shared/lib/async/async-queue.d.ts.map +1 -0
  262. package/dist/shared/lib/async/async-queue.js +80 -0
  263. package/dist/shared/lib/async/async-queue.js.map +1 -0
  264. package/dist/shared/lib/async/deferred.d.ts +12 -0
  265. package/dist/shared/lib/async/deferred.d.ts.map +1 -0
  266. package/dist/shared/lib/async/deferred.js +34 -0
  267. package/dist/shared/lib/async/deferred.js.map +1 -0
  268. package/dist/shared/lib/async/index.d.ts +8 -0
  269. package/dist/shared/lib/async/index.d.ts.map +1 -0
  270. package/dist/shared/lib/async/index.js +5 -0
  271. package/dist/shared/lib/async/index.js.map +1 -0
  272. package/dist/shared/lib/async/run-all.d.ts +8 -0
  273. package/dist/shared/lib/async/run-all.d.ts.map +1 -0
  274. package/dist/shared/lib/async/run-all.js +22 -0
  275. package/dist/shared/lib/async/run-all.js.map +1 -0
  276. package/dist/shared/lib/bytes/bytes.d.ts +18 -0
  277. package/dist/shared/lib/bytes/bytes.d.ts.map +1 -0
  278. package/dist/shared/lib/bytes/bytes.js +48 -0
  279. package/dist/shared/lib/bytes/bytes.js.map +1 -0
  280. package/dist/shared/lib/bytes/index.d.ts +3 -0
  281. package/dist/shared/lib/bytes/index.d.ts.map +1 -0
  282. package/dist/shared/lib/bytes/index.js +2 -0
  283. package/dist/shared/lib/bytes/index.js.map +1 -0
  284. package/dist/shared/lib/clock/clock.d.ts +29 -0
  285. package/dist/shared/lib/clock/clock.d.ts.map +1 -0
  286. package/dist/shared/lib/clock/clock.js +85 -0
  287. package/dist/shared/lib/clock/clock.js.map +1 -0
  288. package/dist/shared/lib/clock/index.d.ts +3 -0
  289. package/dist/shared/lib/clock/index.d.ts.map +1 -0
  290. package/dist/shared/lib/clock/index.js +2 -0
  291. package/dist/shared/lib/clock/index.js.map +1 -0
  292. package/dist/shared/lib/cookies/index.d.ts +3 -0
  293. package/dist/shared/lib/cookies/index.d.ts.map +1 -0
  294. package/dist/shared/lib/cookies/index.js +2 -0
  295. package/dist/shared/lib/cookies/index.js.map +1 -0
  296. package/dist/shared/lib/cookies/set-cookie.d.ts +22 -0
  297. package/dist/shared/lib/cookies/set-cookie.d.ts.map +1 -0
  298. package/dist/shared/lib/cookies/set-cookie.js +89 -0
  299. package/dist/shared/lib/cookies/set-cookie.js.map +1 -0
  300. package/dist/shared/lib/envelope/envelope.d.ts +50 -0
  301. package/dist/shared/lib/envelope/envelope.d.ts.map +1 -0
  302. package/dist/shared/lib/envelope/envelope.js +111 -0
  303. package/dist/shared/lib/envelope/envelope.js.map +1 -0
  304. package/dist/shared/lib/envelope/index.d.ts +3 -0
  305. package/dist/shared/lib/envelope/index.d.ts.map +1 -0
  306. package/dist/shared/lib/envelope/index.js +2 -0
  307. package/dist/shared/lib/envelope/index.js.map +1 -0
  308. package/dist/shared/lib/errors/index.d.ts +3 -0
  309. package/dist/shared/lib/errors/index.d.ts.map +1 -0
  310. package/dist/shared/lib/errors/index.js +2 -0
  311. package/dist/shared/lib/errors/index.js.map +1 -0
  312. package/dist/shared/lib/errors/wirestage-error.d.ts +28 -0
  313. package/dist/shared/lib/errors/wirestage-error.d.ts.map +1 -0
  314. package/dist/shared/lib/errors/wirestage-error.js +16 -0
  315. package/dist/shared/lib/errors/wirestage-error.js.map +1 -0
  316. package/dist/shared/lib/id/id.d.ts +10 -0
  317. package/dist/shared/lib/id/id.d.ts.map +1 -0
  318. package/dist/shared/lib/id/id.js +26 -0
  319. package/dist/shared/lib/id/id.js.map +1 -0
  320. package/dist/shared/lib/id/index.d.ts +2 -0
  321. package/dist/shared/lib/id/index.d.ts.map +1 -0
  322. package/dist/shared/lib/id/index.js +2 -0
  323. package/dist/shared/lib/id/index.js.map +1 -0
  324. package/dist/shared/lib/logger/index.d.ts +3 -0
  325. package/dist/shared/lib/logger/index.d.ts.map +1 -0
  326. package/dist/shared/lib/logger/index.js +2 -0
  327. package/dist/shared/lib/logger/index.js.map +1 -0
  328. package/dist/shared/lib/logger/logger.d.ts +46 -0
  329. package/dist/shared/lib/logger/logger.d.ts.map +1 -0
  330. package/dist/shared/lib/logger/logger.js +67 -0
  331. package/dist/shared/lib/logger/logger.js.map +1 -0
  332. package/dist/shared/lib/match/index.d.ts +3 -0
  333. package/dist/shared/lib/match/index.d.ts.map +1 -0
  334. package/dist/shared/lib/match/index.js +2 -0
  335. package/dist/shared/lib/match/index.js.map +1 -0
  336. package/dist/shared/lib/match/url-matcher.d.ts +27 -0
  337. package/dist/shared/lib/match/url-matcher.d.ts.map +1 -0
  338. package/dist/shared/lib/match/url-matcher.js +88 -0
  339. package/dist/shared/lib/match/url-matcher.js.map +1 -0
  340. package/dist/sse.d.ts +3 -0
  341. package/dist/sse.d.ts.map +1 -0
  342. package/dist/sse.js +3 -0
  343. package/dist/sse.js.map +1 -0
  344. package/dist/webrtc.d.ts +3 -0
  345. package/dist/webrtc.d.ts.map +1 -0
  346. package/dist/webrtc.js +3 -0
  347. package/dist/webrtc.js.map +1 -0
  348. package/dist/websocket.d.ts +3 -0
  349. package/dist/websocket.d.ts.map +1 -0
  350. package/dist/websocket.js +3 -0
  351. package/dist/websocket.js.map +1 -0
  352. package/dist/widgets/stage/index.d.ts +3 -0
  353. package/dist/widgets/stage/index.d.ts.map +1 -0
  354. package/dist/widgets/stage/index.js +2 -0
  355. package/dist/widgets/stage/index.js.map +1 -0
  356. package/dist/widgets/stage/lib/attached-context.d.ts +10 -0
  357. package/dist/widgets/stage/lib/attached-context.d.ts.map +1 -0
  358. package/dist/widgets/stage/lib/attached-context.js +2 -0
  359. package/dist/widgets/stage/lib/attached-context.js.map +1 -0
  360. package/dist/widgets/stage/lib/create-stage.d.ts +12 -0
  361. package/dist/widgets/stage/lib/create-stage.d.ts.map +1 -0
  362. package/dist/widgets/stage/lib/create-stage.js +248 -0
  363. package/dist/widgets/stage/lib/create-stage.js.map +1 -0
  364. package/dist/widgets/stage/lib/http-router.d.ts +35 -0
  365. package/dist/widgets/stage/lib/http-router.d.ts.map +1 -0
  366. package/dist/widgets/stage/lib/http-router.js +455 -0
  367. package/dist/widgets/stage/lib/http-router.js.map +1 -0
  368. package/dist/widgets/stage/lib/page-host.d.ts +36 -0
  369. package/dist/widgets/stage/lib/page-host.d.ts.map +1 -0
  370. package/dist/widgets/stage/lib/page-host.js +240 -0
  371. package/dist/widgets/stage/lib/page-host.js.map +1 -0
  372. package/dist/widgets/stage/lib/page-runtime.d.ts +93 -0
  373. package/dist/widgets/stage/lib/page-runtime.d.ts.map +1 -0
  374. package/dist/widgets/stage/lib/page-runtime.js +247 -0
  375. package/dist/widgets/stage/lib/page-runtime.js.map +1 -0
  376. package/dist/widgets/stage/lib/reads.d.ts +21 -0
  377. package/dist/widgets/stage/lib/reads.d.ts.map +1 -0
  378. package/dist/widgets/stage/lib/reads.js +97 -0
  379. package/dist/widgets/stage/lib/reads.js.map +1 -0
  380. package/dist/widgets/stage/lib/response-stream.d.ts +9 -0
  381. package/dist/widgets/stage/lib/response-stream.d.ts.map +1 -0
  382. package/dist/widgets/stage/lib/response-stream.js +56 -0
  383. package/dist/widgets/stage/lib/response-stream.js.map +1 -0
  384. package/dist/widgets/stage/lib/socket-router.d.ts +25 -0
  385. package/dist/widgets/stage/lib/socket-router.d.ts.map +1 -0
  386. package/dist/widgets/stage/lib/socket-router.js +204 -0
  387. package/dist/widgets/stage/lib/socket-router.js.map +1 -0
  388. package/dist/widgets/stage/model/stage.d.ts +86 -0
  389. package/dist/widgets/stage/model/stage.d.ts.map +1 -0
  390. package/dist/widgets/stage/model/stage.js +2 -0
  391. package/dist/widgets/stage/model/stage.js.map +1 -0
  392. package/package.json +140 -5
  393. package/src/app/playwright/index.ts +7 -0
  394. package/src/app/playwright/lib/fixture.ts +201 -0
  395. package/src/connect.ts +6 -0
  396. package/src/entities/frame/@x/plugin.ts +8 -0
  397. package/src/entities/frame/index.ts +19 -0
  398. package/src/entities/frame/lib/filter.ts +58 -0
  399. package/src/entities/frame/lib/payload.ts +42 -0
  400. package/src/entities/frame/lib/snapshot.ts +105 -0
  401. package/src/entities/frame/lib/timeline.ts +147 -0
  402. package/src/entities/frame/model/frame.ts +191 -0
  403. package/src/entities/plugin/index.ts +36 -0
  404. package/src/entities/plugin/lib/define-plugin.ts +12 -0
  405. package/src/entities/plugin/lib/named.ts +21 -0
  406. package/src/entities/plugin/model/attachment.ts +18 -0
  407. package/src/entities/plugin/model/http.ts +147 -0
  408. package/src/entities/plugin/model/page.ts +110 -0
  409. package/src/entities/plugin/model/plugin.ts +96 -0
  410. package/src/entities/plugin/model/socket.ts +108 -0
  411. package/src/entities/plugin/model/stream.ts +43 -0
  412. package/src/features/connect/index.ts +23 -0
  413. package/src/features/connect/lib/calls.ts +58 -0
  414. package/src/features/connect/lib/client.ts +203 -0
  415. package/src/features/connect/lib/create-connect.ts +164 -0
  416. package/src/features/connect/lib/faults.ts +132 -0
  417. package/src/features/connect/lib/protocol.ts +321 -0
  418. package/src/features/connect/lib/record.ts +48 -0
  419. package/src/features/connect/lib/recorder.ts +306 -0
  420. package/src/features/connect/lib/rules.ts +385 -0
  421. package/src/features/connect/lib/serve.ts +114 -0
  422. package/src/features/connect/lib/status-of.ts +20 -0
  423. package/src/features/connect/lib/stubs.ts +282 -0
  424. package/src/features/connect/lib/universal.ts +100 -0
  425. package/src/features/connect/model/types.ts +305 -0
  426. package/src/features/rest/index.ts +23 -0
  427. package/src/features/rest/lib/calls.ts +31 -0
  428. package/src/features/rest/lib/create-rest.ts +169 -0
  429. package/src/features/rest/lib/path.ts +70 -0
  430. package/src/features/rest/lib/reply.ts +74 -0
  431. package/src/features/rest/model/types.ts +113 -0
  432. package/src/features/sse/index.ts +10 -0
  433. package/src/features/sse/lib/create-sse.ts +128 -0
  434. package/src/features/sse/lib/encode.ts +28 -0
  435. package/src/features/sse/model/types.ts +66 -0
  436. package/src/features/webrtc/index.ts +6 -0
  437. package/src/features/webrtc/lib/create-webrtc.ts +149 -0
  438. package/src/features/webrtc/lib/rtc-page-module.ts +189 -0
  439. package/src/features/webrtc/lib/to-frame.ts +63 -0
  440. package/src/features/webrtc/model/types.ts +80 -0
  441. package/src/features/websocket/index.ts +15 -0
  442. package/src/features/websocket/lib/create-websocket.ts +41 -0
  443. package/src/features/websocket/lib/mock.ts +114 -0
  444. package/src/features/websocket/lib/proxy.ts +141 -0
  445. package/src/features/websocket/lib/wire.ts +78 -0
  446. package/src/features/websocket/model/types.ts +130 -0
  447. package/src/index.ts +111 -0
  448. package/src/playwright.ts +8 -0
  449. package/src/rest.ts +2 -0
  450. package/src/shared/api/http-server/index.ts +2 -0
  451. package/src/shared/api/http-server/listen.ts +71 -0
  452. package/src/shared/api/playwright/index.ts +17 -0
  453. package/src/shared/api/playwright/ports.ts +145 -0
  454. package/src/shared/api/stream-server/index.ts +7 -0
  455. package/src/shared/api/stream-server/stream-server.ts +246 -0
  456. package/src/shared/lib/async/arrivals.ts +91 -0
  457. package/src/shared/lib/async/async-queue.ts +101 -0
  458. package/src/shared/lib/async/deferred.ts +38 -0
  459. package/src/shared/lib/async/index.ts +11 -0
  460. package/src/shared/lib/async/run-all.ts +19 -0
  461. package/src/shared/lib/bytes/bytes.ts +53 -0
  462. package/src/shared/lib/bytes/index.ts +9 -0
  463. package/src/shared/lib/clock/clock.ts +114 -0
  464. package/src/shared/lib/clock/index.ts +2 -0
  465. package/src/shared/lib/cookies/index.ts +2 -0
  466. package/src/shared/lib/cookies/set-cookie.ts +105 -0
  467. package/src/shared/lib/envelope/envelope.ts +133 -0
  468. package/src/shared/lib/envelope/index.ts +9 -0
  469. package/src/shared/lib/errors/index.ts +5 -0
  470. package/src/shared/lib/errors/wirestage-error.ts +50 -0
  471. package/src/shared/lib/id/id.ts +29 -0
  472. package/src/shared/lib/id/index.ts +1 -0
  473. package/src/shared/lib/logger/index.ts +12 -0
  474. package/src/shared/lib/logger/logger.ts +126 -0
  475. package/src/shared/lib/match/index.ts +6 -0
  476. package/src/shared/lib/match/url-matcher.ts +107 -0
  477. package/src/sse.ts +2 -0
  478. package/src/webrtc.ts +2 -0
  479. package/src/websocket.ts +2 -0
  480. package/src/widgets/stage/index.ts +9 -0
  481. package/src/widgets/stage/lib/attached-context.ts +10 -0
  482. package/src/widgets/stage/lib/create-stage.ts +305 -0
  483. package/src/widgets/stage/lib/http-router.ts +620 -0
  484. package/src/widgets/stage/lib/page-host.ts +375 -0
  485. package/src/widgets/stage/lib/page-runtime.ts +314 -0
  486. package/src/widgets/stage/lib/reads.ts +128 -0
  487. package/src/widgets/stage/lib/response-stream.ts +66 -0
  488. package/src/widgets/stage/lib/socket-router.ts +271 -0
  489. package/src/widgets/stage/model/stage.ts +108 -0
@@ -0,0 +1,240 @@
1
+ import { WirestageError } from "../../../shared/lib/errors/index.js";
2
+ import { buildPageScript, commandRuntime, detachRuntime, flushRuntime, } from "./page-runtime.js";
3
+ /** How to take a hook back out, where this Playwright can. */
4
+ const remover = (handle) => handle?.dispose === undefined
5
+ ? undefined
6
+ : () => handle.dispose();
7
+ /**
8
+ * Node half of the page host: one binding and one init script per context,
9
+ * carrying every registered module.
10
+ *
11
+ * Modules are sealed at the first attach. An init script cannot be amended
12
+ * after the fact, so a module registered later would silently be missing from
13
+ * pages of the contexts already attached; failing loudly is the better DX.
14
+ */
15
+ export function createPageHost(deps) {
16
+ const modules = new Map();
17
+ const attachments = new Set();
18
+ const installed = new WeakMap();
19
+ const binding = `__wirestage_${deps.stage}`;
20
+ const { flushMs, timeoutMs } = deps;
21
+ let sealed = false;
22
+ /** Every frame of every open page: page hooks run in iframes too. */
23
+ const openFrames = (among, pageFilter) => {
24
+ const frames = [];
25
+ for (const attachment of among)
26
+ for (const page of attachment.context.pages())
27
+ if (!page.isClosed() &&
28
+ (pageFilter === undefined || deps.pageId(page) === pageFilter))
29
+ frames.push(...page.frames());
30
+ return frames;
31
+ };
32
+ /**
33
+ * `work`'s value, or undefined once `timeoutMs` have passed — with `late`
34
+ * logged, and the work left to finish on its own.
35
+ */
36
+ const inTime = async (work, late) => {
37
+ const waiting = new AbortController();
38
+ try {
39
+ return await Promise.race([
40
+ work.then((value) => ({ value })),
41
+ deps.clock.sleep(timeoutMs, waiting.signal).then(() => {
42
+ deps.log.warn(late, { timeoutMs });
43
+ return undefined;
44
+ },
45
+ // The work finished first.
46
+ () => undefined),
47
+ ]);
48
+ }
49
+ finally {
50
+ waiting.abort();
51
+ }
52
+ };
53
+ /**
54
+ * Evaluate in one frame, within the time a frame is given. A frame that
55
+ * is navigating or gone has nothing to say, which is not a failure.
56
+ */
57
+ const ask = async (frame, pageFunction, arg, what) => {
58
+ try {
59
+ return await inTime(frame.evaluate(pageFunction, arg), `a frame did not answer a ${what} in time and was passed over; what it recorded may be missing (is a dialog open?)`);
60
+ }
61
+ catch (error) {
62
+ deps.log.debug(`${what} skipped`, {}, error);
63
+ return undefined;
64
+ }
65
+ };
66
+ /**
67
+ * Take the binding or the init script back out, within the same time.
68
+ * Playwright's `dispose()` reaches every page of the context, and a page
69
+ * with a dialog open answers nothing until the dialog closes: a detach
70
+ * that waited for it would hang the test's teardown.
71
+ */
72
+ const release = async (remove, what) => {
73
+ try {
74
+ await inTime(remove(), `the page ${what} was not taken out in time; detaching goes on, and Playwright removes it once the page responds (is a dialog open?)`);
75
+ }
76
+ catch (error) {
77
+ // A context that closed first took it with it.
78
+ deps.log.debug("page hook already gone", {}, error);
79
+ }
80
+ };
81
+ const receive = (source, message, attachment) => {
82
+ if (message.type === "hello") {
83
+ const states = {};
84
+ for (const [id, module] of modules)
85
+ try {
86
+ states[id] = module.state();
87
+ }
88
+ catch (error) {
89
+ // One plugin's bug: its module starts without a state, every
90
+ // other module with its own, and the log says whose it was.
91
+ deps.log.error("page module failed to give its state", { module: id }, error);
92
+ }
93
+ return states;
94
+ }
95
+ const page = deps.pageId(source.page);
96
+ if (message.type === "failure") {
97
+ deps.log.error(`page module failed in its ${message.handler} handler`, { module: message.module, page }, message.error);
98
+ return undefined;
99
+ }
100
+ const byModule = new Map();
101
+ for (const { module, entry } of message.entries) {
102
+ const list = byModule.get(module) ?? [];
103
+ list.push(entry);
104
+ byModule.set(module, list);
105
+ }
106
+ for (const [id, entries] of byModule) {
107
+ const module = modules.get(id);
108
+ if (module === undefined)
109
+ continue;
110
+ try {
111
+ module.receive(entries, { page, context: attachment.id });
112
+ }
113
+ catch (error) {
114
+ deps.log.error("page module failed to receive entries", { module: id }, error);
115
+ }
116
+ }
117
+ return undefined;
118
+ };
119
+ const command = async (module, op, args, options = {}) => {
120
+ // No module, no runtime handler: a frame would have nothing to answer.
121
+ if (!modules.has(module))
122
+ return [];
123
+ const results = await Promise.all(openFrames(attachments, options.page).map((frame) => ask(frame, commandRuntime, { binding, module, op, args }, "command")));
124
+ const answers = [];
125
+ const failures = [];
126
+ for (const result of results) {
127
+ // No answer, or a frame the init script never ran in.
128
+ const outcome = result?.value;
129
+ if (outcome === undefined)
130
+ continue;
131
+ if ("error" in outcome)
132
+ failures.push(outcome.error);
133
+ else
134
+ answers.push(outcome.value);
135
+ }
136
+ if (failures.length > 0)
137
+ // Not "no frame answered": the module's own code failed in the page.
138
+ throw new WirestageError("INVALID_STATE", `page module "${module}" failed to run "${op}" in ${failures.length} frame(s): ${failures[0]}`, { details: { module, op, failures } });
139
+ return answers;
140
+ };
141
+ return {
142
+ register(module) {
143
+ if (sealed)
144
+ throw new WirestageError("INVALID_STATE", `page module "${module.id}" registered after the stage was attached; register every plugin before calling attach()`);
145
+ if (modules.has(module.id))
146
+ throw new WirestageError("INVALID_ARGUMENT", `page module "${module.id}" is already registered`);
147
+ try {
148
+ // Parsed the way the init script will use it. A source that is
149
+ // not an expression — a method, a bound or a native function —
150
+ // is a SyntaxError there that takes every module down with it,
151
+ // and nothing in Node would say so.
152
+ new Function(`return (${module.install.toString()});`);
153
+ }
154
+ catch (error) {
155
+ throw new WirestageError("INVALID_ARGUMENT", `page module "${module.id}" cannot run in the page: its install does not serialize to a function expression (${String(error)}); declare it with \`function\` or as an arrow function, not as an object method or a bound function`, { cause: error });
156
+ }
157
+ modules.set(module.id, module);
158
+ },
159
+ async attach(attachment) {
160
+ sealed = true;
161
+ attachments.add(attachment);
162
+ if (modules.size === 0)
163
+ return;
164
+ const before = installed.get(attachment.context);
165
+ if (before !== undefined) {
166
+ // Still in the context from an earlier attach this Playwright
167
+ // could not take back: point it at the new attachment.
168
+ before.current = attachment;
169
+ return;
170
+ }
171
+ const slot = { current: attachment };
172
+ installed.set(attachment.context, slot);
173
+ const installers = {};
174
+ for (const [id, module] of modules)
175
+ installers[id] = module.install;
176
+ try {
177
+ slot.removeBinding = remover((await attachment.context.exposeBinding(binding, (source, message) => slot.current === undefined
178
+ ? undefined
179
+ : receive(source, message, slot.current))));
180
+ slot.removeScript = remover((await attachment.context.addInitScript({
181
+ content: buildPageScript({
182
+ binding,
183
+ flushMs,
184
+ modules: [...modules].map(([id, m]) => ({
185
+ id,
186
+ config: m.config,
187
+ })),
188
+ }, installers),
189
+ })));
190
+ }
191
+ catch (error) {
192
+ installed.delete(attachment.context);
193
+ // A binding left behind would make the next attach fail with
194
+ // "already registered".
195
+ if (slot.removeBinding !== undefined)
196
+ await release(slot.removeBinding, "binding");
197
+ throw error;
198
+ }
199
+ },
200
+ async detach(attachment) {
201
+ if (!attachments.delete(attachment))
202
+ return;
203
+ const slot = installed.get(attachment.context);
204
+ if (slot === undefined)
205
+ return;
206
+ const { removeBinding, removeScript } = slot;
207
+ // A Playwright that cannot take a binding or an init script back
208
+ // leaves them in the context, switched off; they serve it again if
209
+ // it is attached again.
210
+ const removable = removeBinding !== undefined && removeScript !== undefined;
211
+ if (removable) {
212
+ installed.delete(attachment.context);
213
+ // The init script first: a document that loaded while the open
214
+ // ones were being detached would start a runtime no detach
215
+ // reaches, and then lose its binding under it.
216
+ await release(removeScript, "init script");
217
+ }
218
+ // Undo the hooks in the documents that are open, and take what they
219
+ // still hold, while the binding is there to carry it.
220
+ await Promise.all(openFrames([attachment]).map((frame) => ask(frame, detachRuntime, binding, "detach")));
221
+ slot.current = undefined;
222
+ if (removable)
223
+ await release(removeBinding, "binding");
224
+ },
225
+ async sync() {
226
+ if (modules.size === 0)
227
+ return;
228
+ await Promise.all(openFrames(attachments).map((frame) => ask(frame, flushRuntime, binding, "flush")));
229
+ },
230
+ command,
231
+ async refresh(module) {
232
+ const target = modules.get(module);
233
+ if (target === undefined)
234
+ throw new WirestageError("INVALID_ARGUMENT", `no page module "${module}" is registered`);
235
+ await command(module, "__state", target.state());
236
+ },
237
+ pageId: deps.pageId,
238
+ };
239
+ }
240
+ //# sourceMappingURL=page-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-host.js","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/page-host.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAGrE,OAAO,EACN,eAAe,EAEf,cAAc,EACd,aAAa,EACb,YAAY,GAEZ,MAAM,mBAAmB,CAAC;AAwC3B,8DAA8D;AAC9D,MAAM,OAAO,GAAG,CAAC,MAAuB,EAAE,EAAE,CAC3C,MAAM,EAAE,OAAO,KAAK,SAAS;IAC5B,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,GAAG,EAAE,CAAE,MAAM,CAAC,OAA+B,EAAE,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,IAAkB;IAChD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwC,CAAC;IAChE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC/C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AAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACrC,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAC1C,CACD,CAAC;QACH,CAAC;QACD,OAAO;QACP,KAAK,CAAC,OAAO,CAAC,MAAM;YACnB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACnC,IAAI,MAAM,KAAK,SAAS;gBACvB,MAAM,IAAI,cAAc,CACvB,kBAAkB,EAClB,mBAAmB,MAAM,iBAAiB,CAC1C,CAAC;YACH,MAAM,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,MAAM,EAAE,IAAI,CAAC,MAAM;KACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The page half of the page host. Everything in this file that is exported as
3
+ * a function runs INSIDE the page: it is serialized with `toString()`, so it is
4
+ * self-contained — no imports, no references to module scope.
5
+ */
6
+ export interface PageRuntimeInit {
7
+ /** The binding Node exposed; also the runtime's key in `__wirestage`. */
8
+ readonly binding: string;
9
+ /** How long entries may wait for company before the batch is flushed. */
10
+ readonly flushMs: number;
11
+ readonly modules: readonly {
12
+ readonly id: string;
13
+ readonly config: unknown;
14
+ }[];
15
+ }
16
+ /** Messages the runtime sends through the binding. */
17
+ export type RuntimeMessage = {
18
+ readonly type: "hello";
19
+ } | {
20
+ readonly type: "entries";
21
+ readonly entries: readonly {
22
+ readonly module: string;
23
+ readonly entry: unknown;
24
+ }[];
25
+ } | {
26
+ /** A module's own handler threw, with no call to reject: Node logs it. */
27
+ readonly type: "failure";
28
+ readonly module: string;
29
+ /** `install`, `onState` or `onDetach`. */
30
+ readonly handler: string;
31
+ readonly error: string;
32
+ };
33
+ /** What the runtime publishes on `globalThis.__wirestage[binding]`. */
34
+ export interface RuntimeHandle {
35
+ flush(): Promise<unknown>;
36
+ command(module: string, op: string, args: unknown): unknown;
37
+ /** Undo every module's hooks, send what is still held, and step aside. */
38
+ detach(): Promise<unknown>;
39
+ }
40
+ /** A command's answer, or why its handler failed. */
41
+ export type CommandResult = {
42
+ readonly value: unknown;
43
+ } | {
44
+ readonly error: string;
45
+ };
46
+ type Installer = (env: unknown) => void;
47
+ /**
48
+ * Install every module, batch what they emit, and answer Node's flushes and
49
+ * commands.
50
+ *
51
+ * Batching is what keeps a 60 Hz channel cheap: one binding call per flush
52
+ * window instead of one per message. The first entry after a quiet spell is
53
+ * not held back, though — it leaves at once, so it reaches Node ahead of a
54
+ * request the page makes right after it and the two land on the timeline in
55
+ * the order they happened.
56
+ *
57
+ * `flush()` returns the binding's promise, so a Node-side `evaluate(flush)`
58
+ * resolves only after Node has appended the entries: a read that flushes
59
+ * first sees everything the page recorded before it.
60
+ *
61
+ * Nothing the runtime does throws into the page's own code: a module whose
62
+ * handler throws is reported to Node, and a binding that has been taken away
63
+ * makes the runtime step aside.
64
+ */
65
+ export declare function pageRuntime(scope: Record<string, unknown>, init: PageRuntimeInit, installers: Record<string, Installer>): void;
66
+ /** Flush one frame's runtime. Runs in the page via `frame.evaluate`. */
67
+ export declare function flushRuntime(binding: string): Promise<unknown> | undefined;
68
+ /** Detach one frame's runtime. Runs in the page via `frame.evaluate`. */
69
+ export declare function detachRuntime(binding: string): Promise<unknown> | undefined;
70
+ /**
71
+ * Run one command in one frame's runtime. Runs in the page via
72
+ * `frame.evaluate`. Undefined when the frame has no runtime (a document the
73
+ * init script never ran in); otherwise the handler's answer, or its failure
74
+ * as text — an exception would cross back to Node as a rejected evaluate,
75
+ * indistinguishable from a frame that went away.
76
+ */
77
+ export declare function commandRuntime(arg: {
78
+ readonly binding: string;
79
+ readonly module: string;
80
+ readonly op: string;
81
+ readonly args: unknown;
82
+ }): Promise<CommandResult> | undefined;
83
+ /**
84
+ * The init script: the runtime, then every installer, then the call.
85
+ *
86
+ * Wrapped in a scope that defines `__name`: esbuild's `keepNames` (on by
87
+ * default in tsx) rewrites `const f = () => {}` into `__name(() => {}, "f")`,
88
+ * so code serialized from a tsx-run process calls a helper the page does not
89
+ * have, and the whole runtime dies with "__name is not defined".
90
+ */
91
+ export declare function buildPageScript(init: PageRuntimeInit, installers: Readonly<Record<string, Installer>>): string;
92
+ export {};
93
+ //# sourceMappingURL=page-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-runtime.d.ts","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/page-runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,eAAe;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS;QAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;KACzB,EAAE,CAAC;CACJ;AAED,sDAAsD;AACtD,MAAM,MAAM,cAAc,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IACA,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS;QAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;KACxB,EAAE,CAAC;CACH,GACD;IACA,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACtB,CAAC;AAEL,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC7B,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1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GAC7C,MAAM,CAKR"}
@@ -0,0 +1,247 @@
1
+ /**
2
+ * The page half of the page host. Everything in this file that is exported as
3
+ * a function runs INSIDE the page: it is serialized with `toString()`, so it is
4
+ * self-contained — no imports, no references to module scope.
5
+ */
6
+ /**
7
+ * Install every module, batch what they emit, and answer Node's flushes and
8
+ * commands.
9
+ *
10
+ * Batching is what keeps a 60 Hz channel cheap: one binding call per flush
11
+ * window instead of one per message. The first entry after a quiet spell is
12
+ * not held back, though — it leaves at once, so it reaches Node ahead of a
13
+ * request the page makes right after it and the two land on the timeline in
14
+ * the order they happened.
15
+ *
16
+ * `flush()` returns the binding's promise, so a Node-side `evaluate(flush)`
17
+ * resolves only after Node has appended the entries: a read that flushes
18
+ * first sees everything the page recorded before it.
19
+ *
20
+ * Nothing the runtime does throws into the page's own code: a module whose
21
+ * handler throws is reported to Node, and a binding that has been taken away
22
+ * makes the runtime step aside.
23
+ */
24
+ export function pageRuntime(scope, init, installers) {
25
+ scope["__wirestage"] ??= {};
26
+ const root = scope["__wirestage"];
27
+ const bind = scope[init.binding];
28
+ // Init scripts run again in every frame and on every navigation; a second
29
+ // run in the same realm would double every entry.
30
+ if (root[init.binding] !== undefined || typeof bind !== "function")
31
+ return;
32
+ const send = bind;
33
+ const queue = [];
34
+ /** Set once the runtime steps aside: a module still emitting talks to nobody. */
35
+ let detached = false;
36
+ let timer;
37
+ /** When the last batch left; far enough back that the first entry is not held. */
38
+ let sentAt = Number.NEGATIVE_INFINITY;
39
+ const commands = new Map();
40
+ const stateHandlers = new Map();
41
+ const detachHandlers = [];
42
+ const now = () => performance.timeOrigin + performance.now();
43
+ /** Undo every module's hooks, newest first: stacked hooks come off in order. */
44
+ const unhook = () => {
45
+ for (const { module, undo } of detachHandlers.splice(0).reverse()) {
46
+ try {
47
+ undo();
48
+ }
49
+ catch (error) {
50
+ // One module failing to undo must not keep the rest hooked.
51
+ report(module, "onDetach", error);
52
+ }
53
+ }
54
+ delete root[init.binding];
55
+ };
56
+ /**
57
+ * Send through the binding. Playwright's throws, synchronously, once it
58
+ * has been removed — in a document the stage's detach did not reach, one
59
+ * that loaded while the stage was detaching. Thrown on from `emit`, that
60
+ * would fail the app's own call (`RTCDataChannel.send()`) or surface as a
61
+ * page error; nothing the runtime holds can reach Node any more, so it
62
+ * steps aside instead, putting back what the modules wrapped.
63
+ */
64
+ const post = (message) => {
65
+ try {
66
+ return send(message);
67
+ }
68
+ catch {
69
+ detached = true;
70
+ queue.length = 0;
71
+ unhook();
72
+ return Promise.resolve(undefined);
73
+ }
74
+ };
75
+ /** Tell Node a module's handler threw, so it is logged against the module. */
76
+ const report = (module, handler, error) => {
77
+ // Stepping aside for want of a binding: there is nobody left to tell.
78
+ if (detached)
79
+ return;
80
+ post({ type: "failure", module, handler, error: String(error) }).catch(() => { });
81
+ };
82
+ const flush = () => {
83
+ if (timer !== undefined) {
84
+ clearTimeout(timer);
85
+ timer = undefined;
86
+ }
87
+ if (queue.length === 0)
88
+ return Promise.resolve(undefined);
89
+ sentAt = now();
90
+ return post({ type: "entries", entries: queue.splice(0, queue.length) });
91
+ };
92
+ const schedule = () => {
93
+ const wait = sentAt + init.flushMs - now();
94
+ if (wait <= 0) {
95
+ flush().catch(() => { });
96
+ return;
97
+ }
98
+ timer ??= setTimeout(() => {
99
+ timer = undefined;
100
+ flush().catch(() => { });
101
+ }, wait);
102
+ };
103
+ const encode = (bytes) => {
104
+ let binary = "";
105
+ // Chunked: spreading a large array into fromCharCode overflows the stack.
106
+ for (let i = 0; i < bytes.length; i += 0x8000)
107
+ binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
108
+ return btoa(binary);
109
+ };
110
+ const decode = (text) => {
111
+ const binary = atob(text);
112
+ const out = new Uint8Array(binary.length);
113
+ for (let i = 0; i < binary.length; i++)
114
+ out[i] = binary.charCodeAt(i);
115
+ return out;
116
+ };
117
+ /** Run each of a module's state handlers, whatever the others do; return what threw. */
118
+ const applyState = (module, state) => {
119
+ const failures = [];
120
+ for (const handler of stateHandlers.get(module) ?? [])
121
+ try {
122
+ handler(state);
123
+ }
124
+ catch (error) {
125
+ failures.push(error);
126
+ }
127
+ return failures;
128
+ };
129
+ for (const module of init.modules) {
130
+ const install = installers[module.id];
131
+ if (install === undefined)
132
+ continue;
133
+ const emit = (entry) => {
134
+ if (detached)
135
+ return;
136
+ queue.push({ module: module.id, entry });
137
+ schedule();
138
+ };
139
+ try {
140
+ install({
141
+ window: scope,
142
+ config: module.config,
143
+ emit,
144
+ now,
145
+ encode,
146
+ decode,
147
+ onCommand: (op, handler) => {
148
+ commands.set(`${module.id}\u0000${op}`, handler);
149
+ },
150
+ onState: (handler) => {
151
+ const list = stateHandlers.get(module.id) ?? [];
152
+ list.push(handler);
153
+ stateHandlers.set(module.id, list);
154
+ },
155
+ onDetach: (handler) => {
156
+ detachHandlers.push({ module: module.id, undo: handler });
157
+ },
158
+ });
159
+ }
160
+ catch (error) {
161
+ // A broken module must not take the page down with it: an entry puts
162
+ // the failure on its timeline, and Node logs it against the module.
163
+ emit({ type: "error", at: now(), text: String(error) });
164
+ report(module.id, "install", error);
165
+ }
166
+ }
167
+ const handle = {
168
+ flush,
169
+ command(module, op, args) {
170
+ if (op === "__state") {
171
+ // Every handler gets the state; the command still fails when one
172
+ // threw, so the `refresh()` that sent it says which module broke.
173
+ const failures = applyState(module, args);
174
+ if (failures.length > 0)
175
+ throw failures[0];
176
+ return true;
177
+ }
178
+ const handler = commands.get(`${module}\u0000${op}`);
179
+ return handler === undefined ? undefined : handler(args);
180
+ },
181
+ detach() {
182
+ unhook();
183
+ // After the undos: what they emit still leaves with the last flush.
184
+ detached = true;
185
+ return flush();
186
+ },
187
+ };
188
+ root[init.binding] = handle;
189
+ // Chromium loses a binding call made from `pagehide` when the main frame
190
+ // navigates — the document is gone before Node hears of it — while one
191
+ // made from `beforeunload` still arrives. `pagehide` stays for the ways
192
+ // out that fire no `beforeunload`: a page closed, an iframe removed.
193
+ for (const type of ["beforeunload", "pagehide"])
194
+ scope.addEventListener(type, () => {
195
+ flush().catch(() => { });
196
+ });
197
+ post({ type: "hello" }).then((states) => {
198
+ const byModule = (states ?? {});
199
+ for (const module of stateHandlers.keys())
200
+ if (byModule[module] !== undefined)
201
+ // No call to fail: Node hears of each failure, and the
202
+ // modules after this one still get their state.
203
+ for (const error of applyState(module, byModule[module]))
204
+ report(module, "onState", error);
205
+ }, () => { });
206
+ }
207
+ /** Flush one frame's runtime. Runs in the page via `frame.evaluate`. */
208
+ export function flushRuntime(binding) {
209
+ const root = globalThis["__wirestage"];
210
+ return root?.[binding]?.flush();
211
+ }
212
+ /** Detach one frame's runtime. Runs in the page via `frame.evaluate`. */
213
+ export function detachRuntime(binding) {
214
+ const root = globalThis["__wirestage"];
215
+ return root?.[binding]?.detach();
216
+ }
217
+ /**
218
+ * Run one command in one frame's runtime. Runs in the page via
219
+ * `frame.evaluate`. Undefined when the frame has no runtime (a document the
220
+ * init script never ran in); otherwise the handler's answer, or its failure
221
+ * as text — an exception would cross back to Node as a rejected evaluate,
222
+ * indistinguishable from a frame that went away.
223
+ */
224
+ export function commandRuntime(arg) {
225
+ const root = globalThis["__wirestage"];
226
+ const handle = root?.[arg.binding];
227
+ if (handle === undefined)
228
+ return undefined;
229
+ return Promise.resolve()
230
+ .then(() => handle.command(arg.module, arg.op, arg.args))
231
+ .then((value) => ({ value }), (error) => ({ error: String(error) }));
232
+ }
233
+ /**
234
+ * The init script: the runtime, then every installer, then the call.
235
+ *
236
+ * Wrapped in a scope that defines `__name`: esbuild's `keepNames` (on by
237
+ * default in tsx) rewrites `const f = () => {}` into `__name(() => {}, "f")`,
238
+ * so code serialized from a tsx-run process calls a helper the page does not
239
+ * have, and the whole runtime dies with "__name is not defined".
240
+ */
241
+ export function buildPageScript(init, installers) {
242
+ const list = Object.entries(installers)
243
+ .map(([id, install]) => `${JSON.stringify(id)}: (${install.toString()})`)
244
+ .join(",\n");
245
+ return `(() => {\nconst __name = (target) => target;\n(${pageRuntime.toString()})(globalThis, ${JSON.stringify(init)}, {\n${list}\n});\n})();`;
246
+ }
247
+ //# sourceMappingURL=page-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-runtime.js","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/page-runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+CH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAC1B,KAA8B,EAC9B,IAAqB,EACrB,UAAqC;IAErC,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,CAA4B,CAAC;IAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,0EAA0E;IAC1E,kDAAkD;IAClD,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,UAAU;QAAE,OAAO;IAC3E,MAAM,IAAI,GAAG,IAAqD,CAAC;IAEnE,MAAM,KAAK,GAAyC,EAAE,CAAC;IACvD,iFAAiF;IACjF,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,KAAgD,CAAC;IACrD,kFAAkF;IAClF,IAAI,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACtC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC/D,MAAM,aAAa,GAAG,IAAI,GAAG,EAAwC,CAAC;IACtE,MAAM,cAAc,GAAgD,EAAE,CAAC;IAEvE,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAC7D,gFAAgF;IAChF,MAAM,MAAM,GAAG,GAAG,EAAE;QACnB,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YACnE,IAAI,CAAC;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,21 @@
1
+ import type { Timeline } from "../../../entities/frame/index.js";
2
+ import type { Clock } from "../../../shared/lib/clock/index.js";
3
+ import type { StageCore } from "../model/stage.js";
4
+ export interface ReadsDeps {
5
+ readonly timeline: Timeline;
6
+ readonly clock: Clock;
7
+ /** Flush every page buffer into the timeline. */
8
+ readonly sync: () => Promise<void>;
9
+ /** Defaults for `waitFor`, in milliseconds. */
10
+ readonly wait: {
11
+ readonly timeout: number;
12
+ readonly interval: number;
13
+ };
14
+ }
15
+ export type StageReads = Pick<StageCore, "frames" | "drain" | "mark" | "since" | "between" | "waitFor" | "report">;
16
+ /**
17
+ * The stage's reads of its timeline. Every one flushes the page buffers
18
+ * first: that flush is what makes arrival order the order things happened in.
19
+ */
20
+ export declare function createReads(deps: ReadsDeps): StageReads;
21
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/reads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,QAAQ,EACR,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACvE;AASD,MAAM,MAAM,UAAU,GAAG,IAAI,CAC5B,SAAS,EACT,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CACxE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAmFvD"}