@orangecharts/wrun-chart-host 0.4.0 → 0.5.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 (322) hide show
  1. package/README.md +15 -4
  2. package/dist/constants/exchange-names.leaf.d.ts +8 -0
  3. package/dist/constants/exchange-names.leaf.js +101 -0
  4. package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +15 -0
  5. package/dist/constants/kscript-data-interval-restrictions.constants.js +40 -0
  6. package/dist/constants/opra-compliance.constants.d.ts +19 -0
  7. package/dist/constants/opra-compliance.constants.js +19 -0
  8. package/dist/constants/replay-ladder.leaf.d.ts +30 -0
  9. package/dist/constants/replay-ladder.leaf.js +99 -0
  10. package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +168 -0
  11. package/dist/constants/scriptEditor/cme-official-scripts.constants.js +398 -0
  12. package/dist/constants/scriptEditor/converted-script-id.leaf.d.ts +8 -0
  13. package/dist/constants/scriptEditor/converted-script-id.leaf.js +10 -0
  14. package/dist/constants/scriptEditor/execution.constants.d.ts +4 -0
  15. package/dist/constants/scriptEditor/execution.constants.js +14 -0
  16. package/dist/constants/wrun-prefix-safe.constants.d.ts +23 -0
  17. package/dist/constants/wrun-prefix-safe.constants.js +26 -0
  18. package/dist/host-env.d.ts +313 -18
  19. package/dist/host-env.js +15 -0
  20. package/dist/host-ports.types.d.ts +853 -16
  21. package/dist/index.d.ts +139 -2
  22. package/dist/index.js +139 -2
  23. package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +31 -0
  24. package/dist/instances/script-engine-worker-ohlcv-transfer.js +164 -0
  25. package/dist/interfaces/market-event.interface.d.ts +231 -0
  26. package/dist/interfaces/market-event.interface.js +15 -0
  27. package/dist/interfaces/opra-realtime.interface.d.ts +70 -134
  28. package/dist/interfaces/opra-realtime.interface.js +34 -59
  29. package/dist/interfaces/replay.interface.d.ts +285 -0
  30. package/dist/interfaces/replay.interface.js +1 -0
  31. package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +1 -0
  32. package/dist/kscript-data/controls/live-ohlcv-merge.util.js +93 -0
  33. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +5 -1
  34. package/dist/kscript-data/controls/live-trades-merge.util.js +2 -2
  35. package/dist/market-data/billing.interface.d.ts +219 -0
  36. package/dist/market-data/billing.interface.js +58 -0
  37. package/dist/market-data/venue-governed.util.d.ts +2 -0
  38. package/dist/market-data/venue-governed.util.js +10 -0
  39. package/dist/market-data/venue.d.ts +122 -0
  40. package/dist/market-data/venue.js +1 -0
  41. package/dist/market-data/venues/index.d.ts +97 -0
  42. package/dist/market-data/venues/index.js +33 -0
  43. package/dist/market-data/venues/opra.contract.copy.json +35 -0
  44. package/dist/market-data/venues/opra.d.ts +70 -0
  45. package/dist/market-data/venues/opra.js +74 -0
  46. package/dist/replay/replayIndicatorRows.d.ts +31 -0
  47. package/dist/replay/replayIndicatorRows.js +117 -0
  48. package/dist/replay/replayLadder.d.ts +85 -0
  49. package/dist/replay/replayLadder.js +388 -0
  50. package/dist/utility/auth/server-clock.util.d.ts +81 -0
  51. package/dist/utility/auth/server-clock.util.js +238 -0
  52. package/dist/utility/chart/builtin-identity.util.d.ts +18 -0
  53. package/dist/utility/chart/builtin-identity.util.js +51 -0
  54. package/dist/utility/chart/cache-alignment.util.d.ts +454 -0
  55. package/dist/utility/chart/cache-alignment.util.js +926 -0
  56. package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +15 -0
  57. package/dist/utility/chart/chart-data-fetch-generation.util.js +22 -0
  58. package/dist/utility/chart/chart-mount-epoch.util.d.ts +5 -0
  59. package/dist/utility/chart/chart-mount-epoch.util.js +29 -0
  60. package/dist/utility/chart/chart-time-domain.util.d.ts +12 -0
  61. package/dist/utility/chart/chart-time-domain.util.js +23 -0
  62. package/dist/utility/chart/color-customization.leaf.d.ts +10 -0
  63. package/dist/utility/chart/color-customization.leaf.js +16 -0
  64. package/dist/utility/chart/footprint-tick-grid.util.d.ts +106 -0
  65. package/dist/utility/chart/footprint-tick-grid.util.js +167 -0
  66. package/dist/utility/chart/gesture-timing.leaf.d.ts +29 -0
  67. package/dist/utility/chart/gesture-timing.leaf.js +29 -0
  68. package/dist/utility/chart/governed-contract-coin.util.d.ts +22 -0
  69. package/dist/utility/chart/governed-contract-coin.util.js +39 -0
  70. package/dist/utility/chart/host-bar-placement.util.d.ts +107 -0
  71. package/dist/utility/chart/host-bar-placement.util.js +447 -0
  72. package/dist/utility/chart/index-host-tier.util.d.ts +31 -0
  73. package/dist/utility/chart/index-host-tier.util.js +118 -0
  74. package/dist/utility/chart/index-mode-admission.util.d.ts +34 -0
  75. package/dist/utility/chart/index-mode-admission.util.js +67 -0
  76. package/dist/utility/chart/indicator-error-message.util.d.ts +35 -0
  77. package/dist/utility/chart/indicator-error-message.util.js +44 -0
  78. package/dist/utility/chart/kscript-apply-fingerprint.util.d.ts +65 -0
  79. package/dist/utility/chart/kscript-apply-fingerprint.util.js +357 -0
  80. package/dist/utility/chart/kscript-chart-flush.leaf.d.ts +22 -0
  81. package/dist/utility/chart/kscript-chart-flush.leaf.js +13 -0
  82. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +6 -0
  83. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +27 -0
  84. package/dist/utility/chart/kscript-integration-decision.leaf.d.ts +89 -0
  85. package/dist/utility/chart/kscript-integration-decision.leaf.js +80 -0
  86. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +76 -0
  87. package/dist/utility/chart/kscript-live-coalesce.util.js +156 -0
  88. package/dist/utility/chart/kscript-live-rest-pace.util.d.ts +34 -0
  89. package/dist/utility/chart/kscript-live-rest-pace.util.js +134 -0
  90. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +98 -0
  91. package/dist/utility/chart/kscript-live-source-identity.util.js +121 -0
  92. package/dist/utility/chart/kscript-mounted-plot-set.leaf.d.ts +48 -0
  93. package/dist/utility/chart/kscript-mounted-plot-set.leaf.js +145 -0
  94. package/dist/utility/chart/kscript-perf-tracker.util.d.ts +243 -0
  95. package/dist/utility/chart/kscript-perf-tracker.util.js +522 -0
  96. package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +43 -0
  97. package/dist/utility/chart/kscript-run-interval-projection.util.js +471 -0
  98. package/dist/utility/chart/kscript-run-result-equality.util.d.ts +38 -0
  99. package/dist/utility/chart/kscript-run-result-equality.util.js +89 -0
  100. package/dist/utility/chart/kscript-settings-revision.leaf.d.ts +2 -0
  101. package/dist/utility/chart/kscript-settings-revision.leaf.js +12 -0
  102. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +63 -0
  103. package/dist/utility/chart/kscript-source-degrade.leaf.js +68 -0
  104. package/dist/utility/chart/kscript-source-retention.util.d.ts +134 -0
  105. package/dist/utility/chart/kscript-source-retention.util.js +218 -0
  106. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +57 -0
  107. package/dist/utility/chart/kscript-standin-identity.leaf.js +61 -0
  108. package/dist/utility/chart/kscript-titancharts-preparation.util.d.ts +15 -0
  109. package/dist/utility/chart/kscript-titancharts-preparation.util.js +376 -0
  110. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +9 -0
  111. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +130 -0
  112. package/dist/utility/chart/kscript-venue-policy.util.d.ts +217 -0
  113. package/dist/utility/chart/kscript-venue-policy.util.js +324 -0
  114. package/dist/utility/chart/live-cadence.util.d.ts +38 -0
  115. package/dist/utility/chart/live-cadence.util.js +37 -0
  116. package/dist/utility/chart/live-feed-series-match.leaf.d.ts +13 -0
  117. package/dist/utility/chart/live-feed-series-match.leaf.js +21 -0
  118. package/dist/utility/chart/local-engine-self-heal-backoff.util.d.ts +46 -0
  119. package/dist/utility/chart/local-engine-self-heal-backoff.util.js +46 -0
  120. package/dist/utility/chart/local-engine-uninit.leaf.d.ts +21 -0
  121. package/dist/utility/chart/local-engine-uninit.leaf.js +22 -0
  122. package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +62 -0
  123. package/dist/utility/chart/local-kscript-source-revalidation.util.js +123 -0
  124. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +214 -0
  125. package/dist/utility/chart/local-kscript-warmup-depth.util.js +376 -0
  126. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.d.ts +85 -0
  127. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.js +197 -0
  128. package/dist/utility/chart/local-technical-script-range.leaf.d.ts +72 -0
  129. package/dist/utility/chart/local-technical-script-range.leaf.js +126 -0
  130. package/dist/utility/chart/mixed-mode.util.d.ts +167 -0
  131. package/dist/utility/chart/mixed-mode.util.js +139 -0
  132. package/dist/utility/chart/ohlcv-row-readiness.util.d.ts +36 -0
  133. package/dist/utility/chart/ohlcv-row-readiness.util.js +90 -0
  134. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +19 -0
  135. package/dist/utility/chart/opra-user-scripts-gate.util.js +32 -0
  136. package/dist/utility/chart/overlay-execution-guard-key.leaf.d.ts +8 -0
  137. package/dist/utility/chart/overlay-execution-guard-key.leaf.js +10 -0
  138. package/dist/utility/chart/price-precision.util.d.ts +40 -0
  139. package/dist/utility/chart/price-precision.util.js +70 -0
  140. package/dist/utility/chart/profile-block-size.util.d.ts +64 -0
  141. package/dist/utility/chart/profile-block-size.util.js +141 -0
  142. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.d.ts +11 -0
  143. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.js +29 -0
  144. package/dist/utility/chart/protected-kscript-empty-output.util.d.ts +28 -0
  145. package/dist/utility/chart/protected-kscript-empty-output.util.js +84 -0
  146. package/dist/utility/chart/run-interval-unservable.leaf.d.ts +9 -0
  147. package/dist/utility/chart/run-interval-unservable.leaf.js +20 -0
  148. package/dist/utility/chart/run-interval-warmup.leaf.d.ts +19 -0
  149. package/dist/utility/chart/run-interval-warmup.leaf.js +35 -0
  150. package/dist/utility/chart/titan-constants.pin.d.ts +9 -5
  151. package/dist/utility/chart/titan-constants.pin.js +18 -5
  152. package/dist/utility/chart/warmup-backfill-retry.leaf.d.ts +9 -0
  153. package/dist/utility/chart/warmup-backfill-retry.leaf.js +9 -0
  154. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +11 -2
  155. package/dist/utility/chart/wrun-bar-session-facts.util.js +10 -3
  156. package/dist/utility/chart/wrun-run-result.util.d.ts +5 -1
  157. package/dist/utility/chart/wrun-run-result.util.js +20 -14
  158. package/dist/utility/common/data-processing.util.d.ts +138 -0
  159. package/dist/utility/common/data-processing.util.js +346 -0
  160. package/dist/utility/common/visible-timeout.util.d.ts +13 -4
  161. package/dist/utility/common/visible-timeout.util.js +23 -8
  162. package/dist/utility/exchange-format.leaf.d.ts +1 -0
  163. package/dist/utility/exchange-format.leaf.js +47 -0
  164. package/dist/utility/market-events/earnings-scope.util.d.ts +60 -0
  165. package/dist/utility/market-events/earnings-scope.util.js +92 -0
  166. package/dist/utility/market-events/market-events.util.d.ts +147 -0
  167. package/dist/utility/market-events/market-events.util.js +392 -0
  168. package/dist/utility/market-events/zoned-clock.util.d.ts +1 -0
  169. package/dist/utility/market-events/zoned-clock.util.js +11 -0
  170. package/dist/utility/options/option-venue-disclosure.util.d.ts +43 -0
  171. package/dist/utility/options/option-venue-disclosure.util.js +56 -0
  172. package/dist/utility/scriptEditor/package-semver.util.d.ts +51 -0
  173. package/dist/utility/scriptEditor/package-semver.util.js +120 -0
  174. package/dist/utility/scriptEditor/temp-script-id.util.d.ts +18 -0
  175. package/dist/utility/scriptEditor/temp-script-id.util.js +25 -0
  176. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.d.ts +20 -0
  177. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.js +81 -0
  178. package/dist/utility/v2/governed-tier.leaf.d.ts +103 -0
  179. package/dist/utility/v2/governed-tier.leaf.js +113 -0
  180. package/dist/utility/watchlist/import/import-request.leaf.d.ts +10 -0
  181. package/dist/utility/watchlist/import/import-request.leaf.js +10 -0
  182. package/dist/utility/wrun/sources/lanes/series.js +2 -2
  183. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +4 -4
  184. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +5 -6
  185. package/dist/utility/wrun/wrun-alert-outputs.registry.d.ts +166 -0
  186. package/dist/utility/wrun/wrun-alert-outputs.registry.js +219 -0
  187. package/dist/utility/wrun/wrun-bar-count.util.d.ts +83 -0
  188. package/dist/utility/wrun/wrun-bar-count.util.js +259 -0
  189. package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +84 -0
  190. package/dist/utility/wrun/wrun-chart-context-names.util.js +186 -0
  191. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +253 -0
  192. package/dist/utility/wrun/wrun-chart-market-facts.util.js +731 -0
  193. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.d.ts +28 -0
  194. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.js +45 -0
  195. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +18 -0
  196. package/dist/utility/wrun/wrun-coin-lane-live.util.js +47 -0
  197. package/dist/utility/wrun/wrun-deadline.util.js +2 -1
  198. package/dist/utility/wrun/wrun-debug-output.util.d.ts +39 -0
  199. package/dist/utility/wrun/wrun-debug-output.util.js +63 -0
  200. package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +113 -0
  201. package/dist/utility/wrun/wrun-declared-warmup.util.js +181 -0
  202. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +43 -0
  203. package/dist/utility/wrun/wrun-draft-legend-note.util.js +158 -0
  204. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +181 -0
  205. package/dist/utility/wrun/wrun-draft-overlay.util.js +357 -0
  206. package/dist/utility/wrun/wrun-draw-skipped.leaf.d.ts +16 -0
  207. package/dist/utility/wrun/wrun-draw-skipped.leaf.js +16 -0
  208. package/dist/utility/wrun/wrun-earnings-facts.util.d.ts +42 -0
  209. package/dist/utility/wrun/wrun-earnings-facts.util.js +131 -0
  210. package/dist/utility/wrun/wrun-first-run-depth.util.d.ts +32 -0
  211. package/dist/utility/wrun/wrun-first-run-depth.util.js +118 -0
  212. package/dist/utility/wrun/wrun-gate-plane-readers.util.d.ts +24 -0
  213. package/dist/utility/wrun/wrun-gate-plane-readers.util.js +31 -0
  214. package/dist/utility/wrun/wrun-held-lanes.util.d.ts +32 -0
  215. package/dist/utility/wrun/wrun-held-lanes.util.js +94 -0
  216. package/dist/utility/wrun/wrun-host-visible-clock.util.d.ts +2 -0
  217. package/dist/utility/wrun/wrun-host-visible-clock.util.js +17 -0
  218. package/dist/utility/wrun/wrun-host.service.d.ts +266 -0
  219. package/dist/utility/wrun/wrun-host.service.js +655 -0
  220. package/dist/utility/wrun/wrun-inert-legend.util.d.ts +33 -0
  221. package/dist/utility/wrun/wrun-inert-legend.util.js +125 -0
  222. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +155 -0
  223. package/dist/utility/wrun/wrun-input-requirements.leaf.js +450 -0
  224. package/dist/utility/wrun/wrun-integration-route.util.d.ts +51 -0
  225. package/dist/utility/wrun/wrun-integration-route.util.js +59 -0
  226. package/dist/utility/wrun/wrun-latest-history.leaf.d.ts +8 -0
  227. package/dist/utility/wrun/wrun-latest-history.leaf.js +8 -0
  228. package/dist/utility/wrun/wrun-legend-hover.lazy.d.ts +12 -0
  229. package/dist/utility/wrun/wrun-legend-hover.lazy.js +96 -0
  230. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +21 -0
  231. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +21 -0
  232. package/dist/utility/wrun/wrun-live-hidden-hold.util.d.ts +23 -0
  233. package/dist/utility/wrun/wrun-live-hidden-hold.util.js +13 -0
  234. package/dist/utility/wrun/wrun-live-intake.util.d.ts +374 -0
  235. package/dist/utility/wrun/wrun-live-intake.util.js +2027 -0
  236. package/dist/utility/wrun/wrun-live-patch.util.d.ts +116 -0
  237. package/dist/utility/wrun/wrun-live-patch.util.js +523 -0
  238. package/dist/utility/wrun/wrun-live-tick.util.d.ts +619 -0
  239. package/dist/utility/wrun/wrun-live-tick.util.js +4974 -0
  240. package/dist/utility/wrun/wrun-loading-owner.util.d.ts +58 -0
  241. package/dist/utility/wrun/wrun-loading-owner.util.js +89 -0
  242. package/dist/utility/wrun/wrun-official-scope.leaf.d.ts +29 -0
  243. package/dist/utility/wrun/wrun-official-scope.leaf.js +36 -0
  244. package/dist/utility/wrun/wrun-oi-lane.util.d.ts +27 -0
  245. package/dist/utility/wrun/wrun-oi-lane.util.js +42 -0
  246. package/dist/utility/wrun/wrun-options-stop.util.d.ts +52 -0
  247. package/dist/utility/wrun/wrun-options-stop.util.js +123 -0
  248. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +719 -0
  249. package/dist/utility/wrun/wrun-overlay-drivers.util.js +1180 -0
  250. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +50 -0
  251. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +131 -0
  252. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +118 -0
  253. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +466 -0
  254. package/dist/utility/wrun/wrun-overlay-metadata.util.d.ts +45 -0
  255. package/dist/utility/wrun/wrun-overlay-metadata.util.js +112 -0
  256. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +114 -0
  257. package/dist/utility/wrun/wrun-overlay-recovery.util.js +971 -0
  258. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +858 -0
  259. package/dist/utility/wrun/wrun-overlay-run.util.js +11013 -0
  260. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +24 -9
  261. package/dist/utility/wrun/wrun-panel-mount.util.js +138 -43
  262. package/dist/utility/wrun/wrun-param-map.util.d.ts +19 -4
  263. package/dist/utility/wrun/wrun-param-map.util.js +40 -47
  264. package/dist/utility/wrun/wrun-param-values.util.d.ts +9 -3
  265. package/dist/utility/wrun/wrun-param-values.util.js +5 -5
  266. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +93 -0
  267. package/dist/utility/wrun/wrun-prefix-cohort.util.js +484 -0
  268. package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +114 -0
  269. package/dist/utility/wrun/wrun-prefix-lanes.util.js +486 -0
  270. package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +317 -0
  271. package/dist/utility/wrun/wrun-prefix-proof.util.js +630 -0
  272. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +73 -0
  273. package/dist/utility/wrun/wrun-refusal-surface.util.js +380 -0
  274. package/dist/utility/wrun/wrun-refusal-text.util.d.ts +15 -0
  275. package/dist/utility/wrun/wrun-refusal-text.util.js +40 -0
  276. package/dist/utility/wrun/wrun-replay-lane.util.d.ts +139 -0
  277. package/dist/utility/wrun/wrun-replay-lane.util.js +520 -0
  278. package/dist/utility/wrun/wrun-replay-rows.util.d.ts +21 -0
  279. package/dist/utility/wrun/wrun-replay-rows.util.js +172 -0
  280. package/dist/utility/wrun/wrun-row-source-factory.d.ts +53 -0
  281. package/dist/utility/wrun/wrun-row-source-factory.js +435 -0
  282. package/dist/utility/wrun/wrun-run-cells.util.d.ts +36 -0
  283. package/dist/utility/wrun/wrun-run-cells.util.js +46 -0
  284. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +133 -0
  285. package/dist/utility/wrun/wrun-run-interval-session.util.js +121 -0
  286. package/dist/utility/wrun/wrun-run-interval.util.d.ts +98 -0
  287. package/dist/utility/wrun/wrun-run-interval.util.js +207 -0
  288. package/dist/utility/wrun/wrun-run-retained.util.d.ts +122 -0
  289. package/dist/utility/wrun/wrun-run-retained.util.js +255 -0
  290. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +184 -0
  291. package/dist/utility/wrun/wrun-sandbox-row-source.js +444 -0
  292. package/dist/utility/wrun/wrun-script-inputs.util.js +4 -4
  293. package/dist/utility/wrun/wrun-series-stream.util.d.ts +86 -0
  294. package/dist/utility/wrun/wrun-series-stream.util.js +537 -0
  295. package/dist/utility/wrun/wrun-sheet-remembered.util.d.ts +21 -0
  296. package/dist/utility/wrun/wrun-sheet-remembered.util.js +36 -0
  297. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.d.ts +7 -0
  298. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.js +12 -0
  299. package/dist/utility/wrun/wrun-socket-row-source.js +4 -2
  300. package/dist/utility/wrun/wrun-source-rows.util.d.ts +175 -3
  301. package/dist/utility/wrun/wrun-source-rows.util.js +294 -8
  302. package/dist/utility/wrun/wrun-stats-strip.util.d.ts +46 -0
  303. package/dist/utility/wrun/wrun-stats-strip.util.js +87 -0
  304. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +163 -0
  305. package/dist/utility/wrun/wrun-table-chrome.util.js +557 -0
  306. package/dist/utility/wrun/wrun-text-params.util.d.ts +11 -6
  307. package/dist/utility/wrun/wrun-text-params.util.js +19 -30
  308. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +64 -0
  309. package/dist/utility/wrun/wrun-transient-rerun.util.js +317 -0
  310. package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +10 -0
  311. package/dist/utility/wrun/wrun-twin-lookback.util.js +43 -0
  312. package/dist/utility/wrun/wrun-warmup-head-store.util.d.ts +41 -0
  313. package/dist/utility/wrun/wrun-warmup-head-store.util.js +120 -0
  314. package/dist/utility/wrun-alert-params.leaf.d.ts +24 -0
  315. package/dist/utility/wrun-alert-params.leaf.js +24 -0
  316. package/dist/utils/replay/replay-buffer-math.d.ts +148 -0
  317. package/dist/utils/replay/replay-buffer-math.js +684 -0
  318. package/dist/workers/wrun/wrun-abi-host.d.ts +190 -0
  319. package/dist/workers/wrun/wrun-abi-host.js +1201 -0
  320. package/dist/workers/wrun/wrun-engine-handler.d.ts +37 -0
  321. package/dist/workers/wrun/wrun-engine-handler.js +211 -0
  322. package/package.json +3 -3
@@ -0,0 +1,172 @@
1
+ /**
2
+ * The row cut of a wrun replay lane (wrun-replay-lane.util): a replay
3
+ * session's mounted rows keep to the replay's bars, from the chart's first
4
+ * bar through the lane's cutoff. The run-interval projection and the index
5
+ * decorators' alignment place rows on every main row, the forming one
6
+ * included, and the replay window's warm-up head computes rows before the
7
+ * chart's first bar; the kScript replay lane re-grids its rows onto the
8
+ * revealed main rows for the same reason. Every integrate of a replay session
9
+ * (the full run, the reseed, the tick apply) cuts in its own task, before
10
+ * the frame paints.
11
+ *
12
+ * The batched marks children (WRUN-BATCHED-MARKS: `<id>::marks:<name>`, `::spans:<name>`,
13
+ * `::rays:<name>`) are per-bar rows keyed by their timestamp like the series rows, so they join the
14
+ * cut (round-2 fold 9): a cut takes their engine rows AND, in the same task, the child mount's record
15
+ * of them (the input a theme or timezone retranslate rebuilds from) and their cell ledger
16
+ * (wrun-panel-mount.util `cutWrunBatchedChildRecords`, through its door), and tells the engine the
17
+ * rows moved in place so a pack's cached geometry is read again. A backward step therefore keeps the
18
+ * cut rows out until the reseed lands, a retranslate while the reseed is held included.
19
+ *
20
+ * The order of a batched child's cut is the engine's (titan's ingestion queue): during a gesture
21
+ * `updateData` may QUEUE a row swap instead of applying it, and every live-path entry point,
22
+ * `notifyLiveDataMutated` included, applies the overlay's queued swaps first. A cut that read the
23
+ * mounted rows and then notified would land a queued, uncut swap on top of its cut (rows past the
24
+ * playhead back in the engine). So the cut notifies BEFORE it reads the rows (the queued swaps land
25
+ * and the cut reads the rows the engine holds after them), cuts, and notifies again when it cut (the
26
+ * pack re-reads its geometry; nothing is queued then). Titan has no public per-overlay flush: the
27
+ * notify is the documented door to its own (`flushQueuedDataUpdatesFor` is private).
28
+ */
29
+ import { isReplaySideOutputPlot, replayRowHasTs } from '../../replay/replayIndicatorRows.js';
30
+ import { flushKScriptChartPaint } from '../chart/kscript-chart-flush.leaf.js';
31
+ import { cutWrunBatchedChildRecords } from './wrun-panel-mount.lazy.js';
32
+ import { wrunPaneChildId } from './wrun-output-style.util.js';
33
+ import { wrunReplayPaintCutoffOf } from './wrun-replay-lane.util.js';
34
+ /** The child id prefixes of a wrun overlay's batched marks children (wrun-batched-marks.util ids). */
35
+ const BATCHED_CHILD_KINDS = ['marks', 'spans', 'rays'];
36
+ /** A batched marks child of the overlay: `<id>::marks:<name>`, `::spans:<name>` or `::rays:<name>`. */
37
+ function isWrunReplayBatchedMetaOf(metaId, indicatorId) {
38
+ return (typeof metaId === 'string' && BATCHED_CHILD_KINDS.some((kind) => metaId.startsWith(`${indicatorId}::${kind}:`)));
39
+ }
40
+ /** A wrun overlay's metas: its own, its series child panes' (`<id>::series:<pane>`, wrunPaneChildId)
41
+ * and its batched marks children's. */
42
+ function isWrunReplayMetaOf(metaId, indicatorId) {
43
+ return (typeof metaId === 'string' &&
44
+ (metaId === indicatorId ||
45
+ metaId.startsWith(wrunPaneChildId(indicatorId, '')) ||
46
+ isWrunReplayBatchedMetaOf(metaId, indicatorId)));
47
+ }
48
+ function rowTs(row) {
49
+ return Array.isArray(row) ? Number(row[0]) : Number.NaN;
50
+ }
51
+ /** The first index whose row is stamped at or after `ts` (rows ascending). */
52
+ function firstRowAtOrAfter(rows, ts) {
53
+ let lo = 0;
54
+ let hi = rows.length;
55
+ while (lo < hi) {
56
+ const mid = (lo + hi) >>> 1;
57
+ if (rowTs(rows[mid]) < ts)
58
+ lo = mid + 1;
59
+ else
60
+ hi = mid;
61
+ }
62
+ return lo;
63
+ }
64
+ /** The first index whose row is stamped after `ts` (rows ascending). */
65
+ function firstRowAfter(rows, ts) {
66
+ let lo = 0;
67
+ let hi = rows.length;
68
+ while (lo < hi) {
69
+ const mid = (lo + hi) >>> 1;
70
+ if (rowTs(rows[mid]) <= ts)
71
+ lo = mid + 1;
72
+ else
73
+ hi = mid;
74
+ }
75
+ return lo;
76
+ }
77
+ /** Every row field a mounted meta draws, autoscales and reads legend values
78
+ * from (and the adapter's `data` mirror), kept to [fromTs, toTs]. A side
79
+ * output's rows that carry no bar time (the singleton `[null, payload]`) have
80
+ * no bar to cut at: they stay with `keepUntimed` only, and every other cut
81
+ * takes them off. */
82
+ function cutWrunReplayMetaRows(meta, fromTs, toTs, keepUntimed) {
83
+ const rows = meta.rawData;
84
+ if (!Array.isArray(rows) || rows.length === 0)
85
+ return false;
86
+ let kept;
87
+ if (isReplaySideOutputPlot(meta) && !rows.every(replayRowHasTs)) {
88
+ kept = rows.filter((row) => {
89
+ if (!replayRowHasTs(row))
90
+ return keepUntimed;
91
+ const ts = rowTs(row);
92
+ return (!Number.isFinite(fromTs) || ts >= fromTs) && ts <= toTs;
93
+ });
94
+ if (kept.length === rows.length)
95
+ return false;
96
+ }
97
+ else {
98
+ const start = Number.isFinite(fromTs) ? firstRowAtOrAfter(rows, fromTs) : 0;
99
+ const end = Math.max(start, firstRowAfter(rows, toTs));
100
+ if (start === 0 && end === rows.length)
101
+ return false;
102
+ kept = rows.slice(start, end);
103
+ }
104
+ meta.rawData = kept;
105
+ meta.activeData = kept;
106
+ if (Array.isArray(meta.data))
107
+ meta.data = kept;
108
+ meta.subsetRange = kept.length > 0 ? [0, kept.length - 1] : [0, 0];
109
+ return true;
110
+ }
111
+ /**
112
+ * Keep a wrun overlay's mounted rows (the parent, its nested plots, its
113
+ * series child panes and their nested plots) to the replay's bars: from the
114
+ * chart's first bar through `cutoffTs`. A cut claims full damage and flushes
115
+ * one paint (the integration's rule for a wholesale row change). The legends
116
+ * then read the rows now mounted, through titan's own hover-aware pass (the
117
+ * one its live write path runs, which the kScript replay lane's writes ride):
118
+ * a legend shows the last row it was handed, so an integrate's rows never
119
+ * stand in for the replay's. `keepUntimedSideOutputs` keeps a side output's
120
+ * singleton row, which only the run that computed it through `cutoffTs` may
121
+ * ask for (cutWrunReplayRowsAfterApply); the blank of a held or failed lane
122
+ * and a backward step's cut take it off. True when anything was cut.
123
+ */
124
+ export function cutWrunReplayRows(tc, indicatorId, cutoffTs, options = {}) {
125
+ const chart = tc;
126
+ const metadata = chart?.metadata;
127
+ if (!Array.isArray(metadata) || Number.isNaN(cutoffTs))
128
+ return false;
129
+ const mainRows = metadata[0]?.rawData;
130
+ const firstChartTs = Array.isArray(mainRows) && mainRows.length > 0 ? rowTs(mainRows[0]) : Number.NaN;
131
+ const keepUntimed = options.keepUntimedSideOutputs === true;
132
+ let cut = false;
133
+ for (const meta of metadata) {
134
+ if (!isWrunReplayMetaOf(meta?.id, indicatorId))
135
+ continue;
136
+ const batched = isWrunReplayBatchedMetaOf(meta.id, indicatorId);
137
+ // A batched child's queued row swap lands before the cut reads its rows, never after it (above).
138
+ if (batched)
139
+ chart?.notifyLiveDataMutated?.(meta.id);
140
+ const metaCut = cutWrunReplayMetaRows(meta, firstChartTs, cutoffTs, keepUntimed);
141
+ cut = metaCut || cut;
142
+ // A batched child's engine rows moved in place: its pack re-reads its cached geometry.
143
+ if (metaCut && batched)
144
+ chart?.notifyLiveDataMutated?.(meta.id);
145
+ const nested = Array.isArray(meta.nestedMeta) ? meta.nestedMeta : [];
146
+ for (const plot of nested) {
147
+ if (plot)
148
+ cut = cutWrunReplayMetaRows(plot, firstChartTs, cutoffTs, keepUntimed) || cut;
149
+ }
150
+ }
151
+ // The batched children's mount records and cell ledger, in the same task as their engine rows.
152
+ if (cutWrunBatchedChildRecords(tc, indicatorId, firstChartTs, cutoffTs).length > 0)
153
+ cut = true;
154
+ if (cut) {
155
+ chart?.noteLiveDamage?.('full');
156
+ if (chart?.renderQueue)
157
+ chart.renderQueue.fullRender = true;
158
+ flushKScriptChartPaint(tc);
159
+ }
160
+ chart?.updateLegendsOnLiveTick?.();
161
+ return cut;
162
+ }
163
+ /** The cut an integrate of a replay session owes, at its lane's paint cutoff
164
+ * (the run or step in progress). That run computed a side output's singleton
165
+ * through the cutoff, so the cut keeps it. A no-op without a lane. True when
166
+ * anything was cut. */
167
+ export function cutWrunReplayRowsAfterApply(tc, indicatorId) {
168
+ const cutoffTs = wrunReplayPaintCutoffOf(indicatorId);
169
+ return cutoffTs === undefined
170
+ ? false
171
+ : cutWrunReplayRows(tc, indicatorId, cutoffTs, { keepUntimedSideOutputs: true });
172
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The one place a wrun Indicator's row source is chosen (WRUN-PARITY-PLAN contract C7): the lane is the author's
3
+ * publishing choice, read from the record once, here (`wrunRowSourceKindOf`: the record's `wrunRunTarget`), and never
4
+ * a predicate in the pass. A record with `wrunRunTarget: 'cloud'` runs on the socket source, every other record on
5
+ * the sandbox; removing the field from one record rolls that overlay back onto the sandbox (no flag).
6
+ *
7
+ * `host` is the pass's side of the seam: the mount it computes for and the browser lane's lanes the sandbox source
8
+ * wraps (`WrunSandboxHost`). The socket source reads none of it: the cloud resolves its own lanes.
9
+ *
10
+ * What the pass holds (`WrunPassRowSource`) is the interface plus three answers the pass reads without knowing the
11
+ * lane: the cell rows the source keeps for its live frames (`cellRowsOf`), its whole session as it holds it now
12
+ * (`sessionBatch`: every page it answered and frame it merged, the run-level keys and the calculation they belong to,
13
+ * so a session's live context starts from all of it) and whether it still serves a record (`serves`, the record field
14
+ * read again: a record moved to the other source is created afresh).
15
+ *
16
+ * The socket source joins no boot graph and no browser run: its module, the record's payload view (the protected
17
+ * payload builder's wire identity and discriminator, wrun-cloud-record.util `wrunSocketPayloadSettings`) and the live
18
+ * feed's route load on its first ask (the socket's web half and the live feed through the host's transport loaders).
19
+ * Its adapter here answers the pass's terms on the socket's: a window without finite bounds is the chart's loaded bars
20
+ * (the replay's completed bars through the lane's cutoff while the chart replays), a create pages the rest of its
21
+ * window after the newest page it asks first (a page that fails fails the create, never a clean success over part of
22
+ * the window), a refusal the cloud answered for the whole run rejects as that refusal (its code, its frame and its
23
+ * record), and a superseded or torn-down ask rejects as a superseded run.
24
+ */
25
+ import type { WrunCellRows } from './wrun-canvases.util.js';
26
+ import { type WrunRowBatch, type WrunRowSource, type WrunRowSourceRecord } from './wrun-row-source.js';
27
+ import { type WrunSandboxHost } from './wrun-sandbox-row-source.js';
28
+ /** A source's whole session as the pass installs a live session from it (`WrunPassRowSource.sessionBatch`). */
29
+ export interface WrunSessionBatch extends WrunRowBatch {
30
+ /** The calculation the session's rows and live frames belong to: a create or a settings change opens another, a
31
+ * page keeps it. Absent for a source that names none. */
32
+ generation?: string;
33
+ }
34
+ /** A row source as the pass holds it across runs (see the header). */
35
+ export interface WrunPassRowSource extends WrunRowSource {
36
+ /** The cell rows the source keeps for its live frames, with the chart's candles (the price canvases' rows). */
37
+ cellRowsOf(ohlcvRows: ReadonlyArray<ArrayLike<number>>): WrunCellRows;
38
+ /** Every row the source's session holds (each page it answered, each frame it merged) with the run-level keys and
39
+ * the refusals as it holds them now and the calculation they belong to, or undefined when its batches are the
40
+ * session. */
41
+ sessionBatch(): WrunSessionBatch | undefined;
42
+ /** Whether this source still serves `record` (the record field selects the same source). */
43
+ serves(record: WrunRowSourceRecord): boolean;
44
+ /** Whether the source holds a session of its own for the overlay now, whose frames feed the overlay's live
45
+ * context: false for a source whose batches are the session, and once another source's create replaced the
46
+ * session or the source ended it. */
47
+ holdsSession(): boolean;
48
+ /** The overlay's session ended (its teardown, a Pause): release what the source holds beyond the browser
49
+ * worker's session, which the drivers' teardown ends itself. */
50
+ release(): void;
51
+ }
52
+ /** The row source `record` runs on. */
53
+ export declare function wrunRowSourceFor(record: WrunRowSourceRecord, host: WrunSandboxHost): WrunPassRowSource;
@@ -0,0 +1,435 @@
1
+ /**
2
+ * The one place a wrun Indicator's row source is chosen (WRUN-PARITY-PLAN contract C7): the lane is the author's
3
+ * publishing choice, read from the record once, here (`wrunRowSourceKindOf`: the record's `wrunRunTarget`), and never
4
+ * a predicate in the pass. A record with `wrunRunTarget: 'cloud'` runs on the socket source, every other record on
5
+ * the sandbox; removing the field from one record rolls that overlay back onto the sandbox (no flag).
6
+ *
7
+ * `host` is the pass's side of the seam: the mount it computes for and the browser lane's lanes the sandbox source
8
+ * wraps (`WrunSandboxHost`). The socket source reads none of it: the cloud resolves its own lanes.
9
+ *
10
+ * What the pass holds (`WrunPassRowSource`) is the interface plus three answers the pass reads without knowing the
11
+ * lane: the cell rows the source keeps for its live frames (`cellRowsOf`), its whole session as it holds it now
12
+ * (`sessionBatch`: every page it answered and frame it merged, the run-level keys and the calculation they belong to,
13
+ * so a session's live context starts from all of it) and whether it still serves a record (`serves`, the record field
14
+ * read again: a record moved to the other source is created afresh).
15
+ *
16
+ * The socket source joins no boot graph and no browser run: its module, the record's payload view (the protected
17
+ * payload builder's wire identity and discriminator, wrun-cloud-record.util `wrunSocketPayloadSettings`) and the live
18
+ * feed's route load on its first ask (the socket's web half and the live feed through the host's transport loaders).
19
+ * Its adapter here answers the pass's terms on the socket's: a window without finite bounds is the chart's loaded bars
20
+ * (the replay's completed bars through the lane's cutoff while the chart replays), a create pages the rest of its
21
+ * window after the newest page it asks first (a page that fails fails the create, never a clean success over part of
22
+ * the window), a refusal the cloud answered for the whole run rejects as that refusal (its code, its frame and its
23
+ * record), and a superseded or torn-down ask rejects as a superseded run.
24
+ */
25
+ import { wrunChartHostEnv } from '../../host-env.js';
26
+ import { onWrunOverlayLiveTeardown } from './wrun-overlay-drivers.util.js';
27
+ import { wrunRowSourceKindOf } from './wrun-overlay-identity.util.js';
28
+ import { WrunChartGoneError } from './wrun-registry-errors.util.js';
29
+ import { wrunReplayRunPlanOf } from './wrun-replay-lane.util.js';
30
+ import { isWrunRowSourceTransientError, } from './wrun-row-source.js';
31
+ import { SandboxWrunRowSource } from './wrun-sandbox-row-source.js';
32
+ import { wrunChartCandleRows } from './wrun-source-rows.util.js';
33
+ /** The row source `record` runs on. */
34
+ export function wrunRowSourceFor(record, host) {
35
+ return wrunRowSourceKindOf(record.settings) === 'socket'
36
+ ? new SocketWrunRowSourceAdapter()
37
+ : new SandboxWrunRowSourceAdapter(host);
38
+ }
39
+ function servesKind(kind, record) {
40
+ return wrunRowSourceKindOf(record.settings) === kind;
41
+ }
42
+ /** The sandbox as the pass holds it: the source itself; its batches carry their own cell rows. */
43
+ class SandboxWrunRowSourceAdapter extends SandboxWrunRowSource {
44
+ cellRowsOf(ohlcvRows) {
45
+ return { ohlcvRows };
46
+ }
47
+ sessionBatch() {
48
+ return undefined;
49
+ }
50
+ serves(record) {
51
+ return servesKind('sandbox', record);
52
+ }
53
+ /** None of its own: its batches are the session, the drivers own the engine worker's live series, and a drain
54
+ * that finds the series a failed create ended reseeds it. */
55
+ holdsSession() {
56
+ return false;
57
+ }
58
+ /** Nothing beyond the worker session: the drivers' teardown ends it, and the source's frame session goes with
59
+ * the teardown hook it bound. */
60
+ release() { }
61
+ }
62
+ // ---------------------------------------------------------------------------
63
+ // The socket source
64
+ // ---------------------------------------------------------------------------
65
+ let socketModule;
66
+ /** The socket module and its web half (wrun-socket-transport.ts, the host's `transport.loadWrunSocketTransport()`: the
67
+ * default transport, the live route and the run capability's release; its chart-host ports bind as it loads) as one
68
+ * module, and what they need beside them, once: the live feed's route (`transport.loadLiveFeedService()`) is bound as
69
+ * they load, so a live frame of a session it follows reaches it before any other lane reads the frame. A failed load
70
+ * is retried. */
71
+ function loadWrunSocketModule() {
72
+ socketModule ??= Promise.all([
73
+ import('./wrun-socket-row-source.js'),
74
+ wrunChartHostEnv().transport.loadWrunSocketTransport(),
75
+ ]).then(([socket, transport]) => {
76
+ const module = { ...transport, ...socket };
77
+ void wrunChartHostEnv()
78
+ .transport.loadLiveFeedService()
79
+ .then(({ bindWrunRowSourceLiveRoute }) => bindWrunRowSourceLiveRoute(transport.routeWrunSocketLiveFrame))
80
+ .catch((error) => {
81
+ console.warn('[wrun] the live route of the socket row source could not bind:', error);
82
+ });
83
+ return module;
84
+ }, (error) => {
85
+ socketModule = undefined;
86
+ throw error;
87
+ });
88
+ return socketModule;
89
+ }
90
+ /** The source holding each overlay's cloud session (`<chartIndex>:<indicatorId>`): the cloud keys its session by the
91
+ * overlay, so one source at a time holds it, takes its live frames and may end it. A source holds it once the cloud
92
+ * answered its create (the worker replaced whatever session the overlay had with this one), or once its create was
93
+ * stopped after it went (its overlay left the chart while the cloud computed it: the worker opened the session all
94
+ * the same, and the source's release ends it), never before: a create that fails before it reaches the cloud (the
95
+ * run capability, the payload, the module, a stop before the send) leaves the session, its live frames and its end
96
+ * with the source that held them, and its own teardown ends nothing of it. */
97
+ const socketSessionHolders = new Map();
98
+ function socketKeyOf(identity) {
99
+ return `${identity.chartIndex}:${identity.indicatorId}`;
100
+ }
101
+ /**
102
+ * The overlays whose run capability a socket ask ensured (`<chartIndex>:<indicatorId>`). The capability is the
103
+ * overlay's on the bridge, one hold whichever source asked, apart from its session, which one source holds at a time:
104
+ * the session's holder ends the session alone (DESTROY_INSTANCE, `destroyProtectedKScriptInstance`), and no other
105
+ * source posts a DESTROY. The hold stays with the overlay while it is on the chart, whichever session it runs on (a
106
+ * mint that outlived its deadline lands for the retry, a create the cloud denied ends its session and leaves the
107
+ * denied overlay in the bridge's recovery walk, a Pause keeps it for the Resume) and goes once the overlay left it,
108
+ * whether or not a source of it held the session: its removal releases it (the teardown hook below), and a source that
109
+ * ends, or an ask that settles after its source ended, once the overlay left releases what an ensure took after the
110
+ * removal.
111
+ */
112
+ const socketCapabilityOverlays = new Map();
113
+ /** Whether the overlay's record is on its chart: a removal takes it off in the same turn as the overlay's teardown. */
114
+ function socketOverlayOnChart({ chartIndex, indicatorId }) {
115
+ const records = wrunChartHostEnv().chart.instance(chartIndex)?.metadata;
116
+ return Array.isArray(records) && records.some((record) => record?.id === indicatorId);
117
+ }
118
+ /** The overlay's run capability goes, its session left to its holder (`releaseWrunSocketCapability`). */
119
+ function releaseSocketCapability(asked) {
120
+ socketCapabilityOverlays.delete(socketKeyOf(asked));
121
+ asked.module.releaseWrunSocketCapability(asked.chartIndex, asked.indicatorId);
122
+ }
123
+ // An overlay leaving the chart (its removal, the chart's teardown, a swap's predecessor: the driver's teardown, the
124
+ // loader's remove) takes its run capability with it, whether or not a source of it ever held the session. A Pause
125
+ // keeps it: the session's holder ends the session alone, and the overlay stays on the chart.
126
+ try {
127
+ onWrunOverlayLiveTeardown((indicatorId, cause) => {
128
+ if (cause === 'suspend')
129
+ return;
130
+ for (const asked of [...socketCapabilityOverlays.values()]) {
131
+ if (asked.indicatorId === indicatorId)
132
+ releaseSocketCapability(asked);
133
+ }
134
+ });
135
+ }
136
+ catch {
137
+ // partial module mock (specs)
138
+ }
139
+ /** The transient reasons of a create that never went: the run capability's mint deadline, and the settles the
140
+ * transport launders before the send (no reply, a session kick, a socket that is not open, the chart gone, a stop
141
+ * before the send or one after a later create of the overlay replaced the session it opened). Named one by one, never
142
+ * any transient: the worker's request deadline (`request-timeout`) comes after the send. */
143
+ const WRUN_SOCKET_UNSENT_REASONS = new Set([
144
+ 'capability-unavailable',
145
+ 'no-reply',
146
+ 'session-kicked',
147
+ 'connection-unavailable',
148
+ 'chart-gone',
149
+ ]);
150
+ /** The transport's own failure for a record that builds no protected payload (it asks nothing). */
151
+ const WRUN_SOCKET_NO_PAYLOAD = /\bbuilds no protected payload\b/;
152
+ /**
153
+ * Whether a create the transport failed reached the cloud: the worker replaces the overlay's session as it sends
154
+ * createScript, so every failure answered after the send did (a refusal, a frame of any words, the request's timeout,
155
+ * the stream's deadline, the cloud's capability denial past the transport's re-mint). Never sent is first the
156
+ * transport's own mark: every failure it threw before its dispatch (`isWrunSocketAskUnsent`: the modules the ask
157
+ * loads, the chart and store reads, the payload builder, the run capability's ensure and the bridge's verdict, a stop
158
+ * before the send), so a source whose create never went takes no session (its end, owning no create of the overlay,
159
+ * would post nothing past the end's fence, and the session it took over would outlive the overlay). Then the
160
+ * transport's own list, read off its one seam (`wrunSocketAskFailure`): the run capability's (the mint's deadline, a
161
+ * transient; the bridge's denial, an access door's hold not `dispatched`), a record that builds no payload, and a
162
+ * socket that was not open or a worker gone before the send (the no-reply transients), a stop before the send. A
163
+ * create the transport stopped after it went (its stop, `WrunSocketRowSourceStopped`: its overlay left the chart while
164
+ * the cloud computed it) reached the cloud, which opened its session all the same; the transport fails it as never
165
+ * sent once a later create of the overlay replaced that session. Anything else reads as reached: a frame read as never
166
+ * sent would leave the overlay frozen behind a context that reads healthy.
167
+ */
168
+ function wrunSocketCreateReachedCloud(module, error) {
169
+ if (module.isWrunSocketAskUnsent(error))
170
+ return false;
171
+ if (error instanceof module.WrunSocketRowSourceStopped)
172
+ return true;
173
+ if (isWrunRowSourceTransientError(error))
174
+ return !WRUN_SOCKET_UNSENT_REASONS.has(error.reason);
175
+ if (error instanceof module.WrunSocketAccessDeniedError)
176
+ return error.dispatched;
177
+ return !WRUN_SOCKET_NO_PAYLOAD.test(error instanceof Error ? error.message : String(error));
178
+ }
179
+ /** The default transport with the record's payload view (the protected payload builder reads the wire identity and
180
+ * its discriminator off `wrunSocketPayloadSettings`, never off the record, and the worker the sheet's style knobs),
181
+ * whose session is the source's once the cloud answered its create, or once its create was stopped after it went
182
+ * (`wrunSocketCreateReachedCloud`): the overlay's live route reaches the source from then on, and only the session's
183
+ * holder ends it. The run capability its asks ensure is the overlay's (`socketCapabilityOverlays`), never ended with
184
+ * a session. */
185
+ function payloadTransportFor(module, payloadSettings, owner) {
186
+ return (identity) => {
187
+ const key = socketKeyOf(identity);
188
+ const transport = module.createWrunSocketTransport(identity);
189
+ const { chartIndex, indicatorId } = identity;
190
+ const asked = { chartIndex, indicatorId, module };
191
+ let live;
192
+ /** The source ended (its teardown, or a create for another overlay); an ask still out settles after it. */
193
+ let ended = false;
194
+ const bindLive = () => {
195
+ if (live !== undefined && live.unbind === undefined)
196
+ live.unbind = transport.live(live.listener);
197
+ };
198
+ const takeSession = () => {
199
+ if (owner.takeSession(key))
200
+ bindLive();
201
+ };
202
+ /** Once the overlay left the chart, the capability goes: an ensure of this source's asks may have taken it again
203
+ * after the removal released the overlay's. */
204
+ const releaseIfLeft = () => {
205
+ if (!socketOverlayOnChart(asked))
206
+ releaseSocketCapability(asked);
207
+ };
208
+ return {
209
+ ...transport,
210
+ ask: async (ask) => {
211
+ // The ask ensures the overlay's run capability, which goes with the overlay.
212
+ socketCapabilityOverlays.set(key, asked);
213
+ let output;
214
+ try {
215
+ output = await transport.ask({
216
+ ...ask,
217
+ record: { ...ask.record, settings: payloadSettings(ask.record.settings, ask.record.sheet) },
218
+ });
219
+ }
220
+ catch (error) {
221
+ // A create the cloud answered with a failure, or one stopped after it went, replaced the overlay's session all
222
+ // the same: the source's release ends it.
223
+ if (ask.kind === 'create' && wrunSocketCreateReachedCloud(module, error))
224
+ takeSession();
225
+ throw error;
226
+ }
227
+ finally {
228
+ if (ended)
229
+ releaseIfLeft();
230
+ }
231
+ // The cloud answered the create: the worker replaced whatever session the overlay had with this source's.
232
+ if (ask.kind === 'create')
233
+ takeSession();
234
+ return output;
235
+ },
236
+ live: (listener) => {
237
+ const binding = { listener };
238
+ live = binding;
239
+ if (socketSessionHolders.get(key) === owner)
240
+ bindLive();
241
+ return () => {
242
+ if (live === binding)
243
+ live = undefined;
244
+ binding.unbind?.();
245
+ };
246
+ },
247
+ end: () => {
248
+ ended = true;
249
+ // Only the session's holder ends the session, DESTROY_INSTANCE alone: the capability stays the overlay's while
250
+ // it is on the chart (a failed create's end keeps a denied overlay in the bridge's recovery walk).
251
+ if (socketSessionHolders.get(key) === owner) {
252
+ socketSessionHolders.delete(key);
253
+ transport.end();
254
+ }
255
+ releaseIfLeft();
256
+ },
257
+ };
258
+ };
259
+ }
260
+ /** The whole window a session spans (both bounds open). */
261
+ const WRUN_SOCKET_SESSION_WINDOW = { fromMs: Number.NEGATIVE_INFINITY, toMs: Number.POSITIVE_INFINITY };
262
+ /** The bars a window without finite bounds asks for: the replay lane's window through its cutoff while the chart
263
+ * replays, else the chart's loaded bars. A finite window passes through. */
264
+ function wrunSocketWindowOf(identity, window) {
265
+ if (Number.isFinite(window.fromMs) && Number.isFinite(window.toMs))
266
+ return window;
267
+ const { chartIndex, indicatorId } = identity;
268
+ if (wrunChartHostEnv().chart.isReplaying(chartIndex)) {
269
+ const replay = wrunReplayRunPlanOf(chartIndex, indicatorId);
270
+ if (replay === undefined) {
271
+ throw new WrunChartGoneError(`wrun overlay '${indicatorId}' was superseded (no replay lane)`);
272
+ }
273
+ return { fromMs: replay.fromMs, toMs: replay.cutoffTs };
274
+ }
275
+ const rows = wrunChartCandleRows(wrunChartHostEnv().chart.instance(chartIndex));
276
+ if (rows.length === 0)
277
+ throw new WrunChartGoneError(`chart ${chartIndex} holds no bars for '${indicatorId}'`);
278
+ return {
279
+ fromMs: Number.isFinite(window.fromMs) ? window.fromMs : rows[0][0],
280
+ toMs: Number.isFinite(window.toMs) ? window.toMs : rows[rows.length - 1][0],
281
+ };
282
+ }
283
+ /**
284
+ * The socket source as the pass holds it (see the header). One adapter per session: the socket source is built on
285
+ * the first create, and every later call waits for the module the create loaded.
286
+ */
287
+ class SocketWrunRowSourceAdapter {
288
+ frames;
289
+ source;
290
+ module;
291
+ pending;
292
+ listener;
293
+ unsubscribe;
294
+ torn = false;
295
+ /** The overlay whose cloud session this source took (`socketSessionHolders`), once the cloud answered its create. */
296
+ sessionKey;
297
+ constructor() {
298
+ this.frames = {
299
+ subscribe: (listener) => {
300
+ this.listener = listener;
301
+ this.unsubscribe?.();
302
+ this.unsubscribe = this.source?.frames.subscribe(listener);
303
+ return () => {
304
+ if (this.listener !== listener)
305
+ return;
306
+ this.listener = undefined;
307
+ this.unsubscribe?.();
308
+ this.unsubscribe = undefined;
309
+ };
310
+ },
311
+ };
312
+ }
313
+ async create(identity, record, window, cancel) {
314
+ const source = await this.loaded();
315
+ // A session spans the chart's bars up to its newest (the live edge its frames extend), whatever window the
316
+ // run asks: the create asks there, and the asked window is paged after. The overlay's session is this
317
+ // source's once the cloud answered the create (`takeSession`), never before.
318
+ const spans = wrunSocketWindowOf(identity, WRUN_SOCKET_SESSION_WINDOW);
319
+ const asked = wrunSocketWindowOf(identity, window);
320
+ const created = await this.answer(() => source.create(identity, record, spans, cancel));
321
+ // The create answered the newest page of the window: the rest is paged before the pass paints, so the
322
+ // whole window is computed as the browser lane computes it. Never a clean success over history the cloud
323
+ // did not answer: a page that fails fails the run, with its own verdict (a stop, a refusal, a record, the
324
+ // access door) or as the transient error of an incomplete first paging (the pass's Retry, the heal ladder).
325
+ let whole;
326
+ try {
327
+ whole = await this.answer(() => source.range(asked));
328
+ }
329
+ catch (error) {
330
+ throw this.module !== undefined ? this.module.wrunSocketPagingFailure(error) : error;
331
+ }
332
+ return created.sheet !== undefined && whole.sheet === undefined ? { ...whole, sheet: created.sheet } : whole;
333
+ }
334
+ async range(window) {
335
+ const source = await this.loaded();
336
+ return this.answer(() => source.range(window));
337
+ }
338
+ async changeSettings(patch) {
339
+ const source = await this.loaded();
340
+ return this.answer(() => source.changeSettings(patch));
341
+ }
342
+ teardown() {
343
+ if (this.torn)
344
+ return;
345
+ this.torn = true;
346
+ this.unsubscribe?.();
347
+ this.unsubscribe = undefined;
348
+ this.listener = undefined;
349
+ this.source?.teardown();
350
+ }
351
+ cellRowsOf(ohlcvRows) {
352
+ return this.source !== undefined ? this.source.cellRows(ohlcvRows) : { ohlcvRows };
353
+ }
354
+ sessionBatch() {
355
+ const source = this.source;
356
+ const session = source?.session;
357
+ if (source === undefined || session === undefined || session.rows.length === 0)
358
+ return undefined;
359
+ return {
360
+ window: { fromMs: session.rows[0].ts, toMs: session.rows[session.rows.length - 1].ts },
361
+ asOfMs: session.asOfMs,
362
+ rows: session.rows.slice(),
363
+ grids: [...session.grids.values()],
364
+ frames: session.frames !== undefined ? [...session.frames] : undefined,
365
+ // The store's handle stamps index its own rows, which these are.
366
+ handles: session.handles,
367
+ refusals: session.refusals.map((refusal) => ({ ...refusal })),
368
+ sheet: session.sheet,
369
+ // The strategy output and the diagnostics as the session holds them now: a live frame merged after the last
370
+ // batch moves them, and before the pass subscribes no listener takes that frame.
371
+ ...source.sessionRunLevel,
372
+ // The store keys its session by the calculation it holds (a create or a settings change opens another).
373
+ generation: session.identity,
374
+ };
375
+ }
376
+ serves(record) {
377
+ return servesKind('socket', record);
378
+ }
379
+ /** The overlay's cloud session is this source's while it holds it: from the cloud's answer to its create until
380
+ * another source's create took it or this source ended it. */
381
+ holdsSession() {
382
+ return this.sessionKey !== undefined && socketSessionHolders.get(this.sessionKey) === this;
383
+ }
384
+ /** The cloud answered this source's create for the overlay `key`: the overlay's session is the source's from here
385
+ * (its live route, its end). A source already torn down takes nothing. */
386
+ takeSession(key) {
387
+ if (this.torn)
388
+ return false;
389
+ this.sessionKey = key;
390
+ socketSessionHolders.set(key, this);
391
+ return true;
392
+ }
393
+ /** The cloud session is the source's own: it ends with it (while the source still holds it). */
394
+ release() {
395
+ this.teardown();
396
+ }
397
+ /** The socket source, built once its module and the payload view loaded. */
398
+ loaded() {
399
+ if (this.torn)
400
+ return Promise.reject(new WrunChartGoneError('the socket row source was released (superseded)'));
401
+ this.pending ??= Promise.all([loadWrunSocketModule(), import('./wrun-cloud-record.util.js')]).then(([module, { wrunSocketPayloadSettings }]) => {
402
+ this.module = module;
403
+ const source = new module.SocketWrunRowSource({
404
+ transportFor: payloadTransportFor(module, wrunSocketPayloadSettings, this),
405
+ });
406
+ this.source = source;
407
+ if (this.torn)
408
+ source.teardown();
409
+ else if (this.listener !== undefined)
410
+ this.unsubscribe = source.frames.subscribe(this.listener);
411
+ return source;
412
+ });
413
+ return this.pending;
414
+ }
415
+ /** One ask in the pass's terms: a refusal for the whole run rejects as the refusal itself (its code, the facts its
416
+ * frame carried, its frame and its record), a stop as a superseded run. */
417
+ async answer(ask) {
418
+ const module = this.module;
419
+ let batch;
420
+ try {
421
+ batch = await ask();
422
+ }
423
+ catch (error) {
424
+ if (module !== undefined && error instanceof module.WrunSocketRowSourceStopped) {
425
+ throw new WrunChartGoneError(`the socket row source ask was ${error.reason} (superseded)`);
426
+ }
427
+ throw error;
428
+ }
429
+ const refused = batch.refusals.find((refusal) => refusal.family === module?.WRUN_SOCKET_RUN_REFUSAL_FAMILY);
430
+ // The very refusal its ask failed with: its code, its frame and the record the frame reads as.
431
+ if (refused !== undefined && module !== undefined)
432
+ throw module.wrunSocketRunRefusalOf(refused);
433
+ return batch;
434
+ }
435
+ }