@heojeongbo/wirestage 0.0.0-stage → 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 (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 +135 -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 +107 -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 +46 -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 +121 -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 +68 -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 +120 -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 +133 -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 +126 -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 +45 -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 +167 -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 +250 -0
  363. package/dist/widgets/stage/lib/create-stage.js.map +1 -0
  364. package/dist/widgets/stage/lib/http-router.d.ts +44 -0
  365. package/dist/widgets/stage/lib/http-router.d.ts.map +1 -0
  366. package/dist/widgets/stage/lib/http-router.js +696 -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 +23 -0
  381. package/dist/widgets/stage/lib/response-stream.d.ts.map +1 -0
  382. package/dist/widgets/stage/lib/response-stream.js +108 -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 +233 -0
  387. package/dist/widgets/stage/lib/socket-router.js.map +1 -0
  388. package/dist/widgets/stage/model/stage.d.ts +88 -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 +156 -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 +113 -0
  411. package/src/entities/plugin/model/stream.ts +46 -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 +129 -0
  434. package/src/features/sse/lib/encode.ts +28 -0
  435. package/src/features/sse/model/types.ts +72 -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 +153 -0
  445. package/src/features/websocket/lib/wire.ts +78 -0
  446. package/src/features/websocket/model/types.ts +134 -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 +150 -0
  454. package/src/shared/api/stream-server/index.ts +7 -0
  455. package/src/shared/api/stream-server/stream-server.ts +254 -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 +307 -0
  483. package/src/widgets/stage/lib/http-router.ts +954 -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 +139 -0
  488. package/src/widgets/stage/lib/socket-router.ts +300 -0
  489. package/src/widgets/stage/model/stage.ts +110 -0
@@ -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,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,CAAC,IAAI,CAAC,CAAC;SACxD,IAAI,CACJ,CAAC,KAAK,EAAiB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EACrC,CAAC,KAAc,EAAiB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAqB,EACrB,UAA+C;IAE/C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;SACrC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACxE,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,OAAO,kDAAkD,WAAW,CAAC,QAAQ,EAAE,iBAAiB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,IAAI,cAAc,CAAC;AAChJ,CAAC"}
@@ -0,0 +1,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"}
@@ -0,0 +1,97 @@
1
+ import { WirestageError } from "../../../shared/lib/errors/index.js";
2
+ /**
3
+ * Frames a report holds unless asked otherwise. A report is read from its
4
+ * end, and an unbounded one grows with the test: a long run would attach
5
+ * tens of megabytes, or fail to serialize at all.
6
+ */
7
+ const REPORT_LIMIT = 1_000;
8
+ /**
9
+ * The stage's reads of its timeline. Every one flushes the page buffers
10
+ * first: that flush is what makes arrival order the order things happened in.
11
+ */
12
+ export function createReads(deps) {
13
+ const { timeline, clock, sync } = deps;
14
+ const drainCursor = timeline.cursor();
15
+ const requireMarker = (name) => {
16
+ const marker = timeline.marker(name);
17
+ if (marker === undefined)
18
+ throw new WirestageError("INVALID_ARGUMENT", timeline.evicted > 0
19
+ ? `no marker "${name}" on the timeline: it was never placed, or it was among the ${timeline.evicted} frame(s) dropped at capacity`
20
+ : `no marker "${name}" on the timeline; place one with stage.mark("${name}")`);
21
+ return marker;
22
+ };
23
+ return {
24
+ async frames(filter) {
25
+ await sync();
26
+ return timeline.frames(filter);
27
+ },
28
+ async drain(filter) {
29
+ await sync();
30
+ return drainCursor.take(filter);
31
+ },
32
+ async mark(name, meta) {
33
+ await sync();
34
+ return timeline.append({
35
+ protocol: "wirestage",
36
+ kind: "marker",
37
+ direction: "none",
38
+ endpoint: name,
39
+ source: "test",
40
+ ...(meta === undefined ? {} : { meta }),
41
+ });
42
+ },
43
+ async since(marker, filter) {
44
+ await sync();
45
+ const after = requireMarker(marker).seq;
46
+ return timeline.frames({
47
+ ...filter,
48
+ after: Math.max(after, filter?.after ?? 0),
49
+ });
50
+ },
51
+ async between(from, to, filter) {
52
+ await sync();
53
+ const start = requireMarker(from).seq;
54
+ const end = requireMarker(to).seq;
55
+ const where = filter?.where;
56
+ return timeline.frames({
57
+ ...filter,
58
+ after: Math.max(start, filter?.after ?? 0),
59
+ where: (frame) => frame.seq < end && (where === undefined || where(frame)),
60
+ });
61
+ },
62
+ async waitFor(filter, options = {}) {
63
+ const count = options.count ?? 1;
64
+ const timeout = options.timeout ?? deps.wait.timeout;
65
+ const interval = options.interval ?? deps.wait.interval;
66
+ const deadline = clock.now() + timeout;
67
+ for (;;) {
68
+ await sync();
69
+ const found = timeline.frames(filter);
70
+ if (found.length >= count)
71
+ return found;
72
+ const remaining = deadline - clock.now();
73
+ if (remaining <= 0)
74
+ throw new WirestageError("TIMEOUT", `waited ${timeout} ms for ${count} frame(s) matching ${describeFilter(filter)}; ${found.length} matched. Last frames:\n${timeline.format(undefined, { limit: 20 })}`, { details: { count, matched: found.length, timeout } });
75
+ await clock.sleep(Math.min(interval, remaining));
76
+ }
77
+ },
78
+ report(filter, options = {}) {
79
+ const limit = options.limit ?? REPORT_LIMIT;
80
+ return {
81
+ snapshot: timeline.snapshot(filter, { limit }),
82
+ text: timeline.format(filter, { limit }),
83
+ };
84
+ },
85
+ };
86
+ }
87
+ /** A filter as JSON, with RegExps and callbacks spelled out instead of lost. */
88
+ function describeFilter(filter) {
89
+ return JSON.stringify(filter, (_key, value) => {
90
+ if (value instanceof RegExp)
91
+ return value.toString();
92
+ if (typeof value === "function")
93
+ return "[function]";
94
+ return value;
95
+ });
96
+ }
97
+ //# sourceMappingURL=reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.js","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/reads.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAYrE;;;;GAIG;AACH,MAAM,YAAY,GAAG,KAAK,CAAC;AAO3B;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAe;IAC1C,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACvC,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;IAEtC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAS,EAAE;QAC7C,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,SAAS;YACvB,MAAM,IAAI,cAAc,CACvB,kBAAkB,EAClB,QAAQ,CAAC,OAAO,GAAG,CAAC;gBACnB,CAAC,CAAC,cAAc,IAAI,+DAA+D,QAAQ,CAAC,OAAO,+BAA+B;gBAClI,CAAC,CAAC,cAAc,IAAI,iDAAiD,IAAI,IAAI,CAC9E,CAAC;QACH,OAAO,MAAM,CAAC;IACf,CAAC,CAAC;IAEF,OAAO;QACN,KAAK,CAAC,MAAM,CAAC,MAAM;YAClB,MAAM,IAAI,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;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AS,CAAC,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;QACD,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE;YAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC;YAC5C,OAAO;gBACN,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC;gBAC9C,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC;aACxC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,SAAS,cAAc,CAAC,MAAmB;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,KAAc,EAAE,EAAE;QACtD,IAAI,KAAK,YAAY,MAAM;YAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QACrD,IAAI,OAAO,KAAK,KAAK,UAAU;YAAE,OAAO,YAAY,CAAC;QACrD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import type { ResponseStream, StreamEnd } from "../../../entities/plugin/index.js";
3
+ /** A stream as the stage serves it: the rule's end of it, and the stage's. */
4
+ export interface ServedStream {
5
+ /** What the rule writes. */
6
+ readonly stream: ResponseStream;
7
+ /** The stub asked for the end, and `closed` is on its way. */
8
+ readonly closing: boolean;
9
+ /**
10
+ * The rule writing the stream failed: answer 500 with `body` while
11
+ * nothing has gone out, and cut the connection after. False when the
12
+ * response was over first — ended, cut, or let go of by the page.
13
+ */
14
+ fail(body: string): boolean;
15
+ }
16
+ /**
17
+ * A Node response as the stream a rule writes: the adapter between the
18
+ * stream server's sockets and the plugin contract, which knows nothing of
19
+ * Node. `onClose` hears how the response ended before `closed` resolves, so
20
+ * whoever awaits `closed` finds the end already on record.
21
+ */
22
+ export declare function createResponseStream(request: IncomingMessage, response: ServerResponse, onClose: (end: StreamEnd, failed: boolean) => void): ServedStream;
23
+ //# sourceMappingURL=response-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-stream.d.ts","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/response-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EAEf,cAAc,EACd,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EACX,cAAc,EACd,SAAS,EACT,MAAM,mCAAmC,CAAC;AAK3C,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC5B,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAChD,YAAY,CAoGd"}
@@ -0,0 +1,108 @@
1
+ import { createDeferred } from "../../../shared/lib/async/index.js";
2
+ import { toBytes } from "../../../shared/lib/bytes/index.js";
3
+ import { WirestageError } from "../../../shared/lib/errors/index.js";
4
+ /**
5
+ * A Node response as the stream a rule writes: the adapter between the
6
+ * stream server's sockets and the plugin contract, which knows nothing of
7
+ * Node. `onClose` hears how the response ended before `closed` resolves, so
8
+ * whoever awaits `closed` finds the end already on record.
9
+ */
10
+ export function createResponseStream(request, response, onClose) {
11
+ let state = "open";
12
+ let failed = false;
13
+ const closed = createDeferred();
14
+ response.once("close", () => {
15
+ // Not ended and not cut: the page let go of it.
16
+ const end = state === "open" ? "cancelled" : state;
17
+ onClose(end, failed);
18
+ closed.resolve(end);
19
+ });
20
+ /** The stream server's own headers (CORS, `connection`), before the rule's. */
21
+ const own = Object.entries(response.getHeaders());
22
+ /** Back to those: what a rule's head set is gone, what it replaced is back. */
23
+ const restore = () => {
24
+ for (const name of response.getHeaderNames())
25
+ response.removeHeader(name);
26
+ for (const [name, value] of own)
27
+ response.setHeader(name, value);
28
+ };
29
+ /**
30
+ * Whether a write can reach the page. Node drops a write — callback and
31
+ * all — into a socket destroyed or closed for writing, which is what the
32
+ * page letting go leaves, well before the response reports its close.
33
+ */
34
+ const writable = () => state === "open" && response.socket?.writable === true;
35
+ const requestHeaders = {};
36
+ for (const [name, value] of Object.entries(request.headers))
37
+ requestHeaders[name] = String(value);
38
+ return {
39
+ stream: {
40
+ requestHeaders,
41
+ head(status, headers = {}) {
42
+ // Node checks a status only as the head goes out, and refused by
43
+ // `end()` it leaves the response broken: a 500 after it has no body.
44
+ if (!Number.isInteger(status) || status < 100 || status > 999)
45
+ throw new WirestageError("INVALID_ARGUMENT", `a response status is an integer from 100 to 999, got ${status}`);
46
+ // Kept off the wire until the first write or flush, so a rule that
47
+ // fails before then can still be answered with its 500.
48
+ restore();
49
+ response.statusCode = status;
50
+ for (const [name, value] of Object.entries(headers)) {
51
+ // The stream server's to say: one response per connection.
52
+ if (name.toLowerCase() === "connection")
53
+ continue;
54
+ // Several values, one per line (`set-cookie`): Node sends a
55
+ // header line for each, and refuses a value with a newline.
56
+ const values = value.split("\n");
57
+ response.setHeader(name, values.length > 1 ? values : value);
58
+ }
59
+ },
60
+ flush() {
61
+ response.flushHeaders();
62
+ },
63
+ write(chunk) {
64
+ return new Promise((resolve, reject) => {
65
+ if (!writable()) {
66
+ reject(new WirestageError("CLOSED", "the response stream is closed"));
67
+ return;
68
+ }
69
+ response.write(toBytes(chunk), (error) => error ? reject(error) : resolve());
70
+ });
71
+ },
72
+ async end() {
73
+ if (writable()) {
74
+ state = "ended";
75
+ response.end();
76
+ }
77
+ await closed.promise;
78
+ },
79
+ cut() {
80
+ if (!writable())
81
+ return;
82
+ state = "cut";
83
+ response.destroy();
84
+ },
85
+ closed: closed.promise,
86
+ },
87
+ get closing() {
88
+ return state !== "open" && !closed.settled;
89
+ },
90
+ fail(body) {
91
+ if (!writable())
92
+ return false;
93
+ failed = true;
94
+ if (response.headersSent) {
95
+ state = "cut";
96
+ response.destroy();
97
+ return true;
98
+ }
99
+ state = "ended";
100
+ restore();
101
+ response
102
+ .writeHead(500, { "content-type": "text/plain; charset=utf-8" })
103
+ .end(body);
104
+ return true;
105
+ },
106
+ };
107
+ }
108
+ //# sourceMappingURL=response-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-stream.js","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/response-stream.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAgBrE;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAAwB,EACxB,QAAwB,EACxB,OAAkD;IAElD,IAAI,KAAK,GAA6B,MAAM,CAAC;IAC7C,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,MAAM,GAAG,cAAc,EAAa,CAAC;IAC3C,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;QAC3B,gDAAgD;QAChD,MAAM,GAAG,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC;QACnD,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACrB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IACH,+EAA+E;IAC/E,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAClD,+EAA+E;IAC/E,MAAM,OAAO,GAA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QAAQ,EAAE;gBAAE,OAAO,KAAK,CAAC;YAC9B,MAAM,GAAG,IAAI,CAAC;YACd,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;gBAC1B,KAAK,GAAG,KAAK,CAAC;gBACd,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,KAAK,GAAG,OAAO,CAAC;YAChB,OAAO,EAAE,CAAC;YACV,QAAQ;iBACN,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,CAAC;iBAC/D,GAAG,CAAC,IAAI,CAAC,CAAC;YACZ,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Timeline } from "../../../entities/frame/index.js";
2
+ import type { SocketRouter } from "../../../entities/plugin/index.js";
3
+ import type { ScopedLogger } from "../../../shared/lib/logger/index.js";
4
+ import type { AttachedContext } from "./attached-context.js";
5
+ export interface SocketRouterDeps {
6
+ readonly timeline: Timeline;
7
+ readonly log: ScopedLogger;
8
+ readonly correlation: () => string;
9
+ }
10
+ export interface SocketRouterEngine extends SocketRouter {
11
+ attach(attachment: AttachedContext): Promise<void>;
12
+ detach(attachment: AttachedContext): void;
13
+ }
14
+ /**
15
+ * Turns WebSocket rules into ONE Playwright WebSocket route per attached
16
+ * context, whose predicate asks the live rule list.
17
+ *
18
+ * One route, because Playwright cannot take a WebSocket route out again: a
19
+ * removed rule, or a detached context, simply stops matching, which sends the
20
+ * socket to the real server. And not before it is needed, because routing
21
+ * replaces `WebSocket` in every document of the context — the first rule
22
+ * installs it, or `prepare()` does at attach.
23
+ */
24
+ export declare function createSocketRouter(deps: SocketRouterDeps): SocketRouterEngine;
25
+ //# sourceMappingURL=socket-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-router.d.ts","sourceRoot":"","sources":["../../../../src/widgets/stage/lib/socket-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAEX,YAAY,EAIZ,MAAM,mCAAmC,CAAC;AAI3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACvD,MAAM,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,CAAC,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1C;AA8CD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,kBAAkB,CA2N7E"}