@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,259 @@
1
+ /**
2
+ * The wrun-6 row count (om docs/WRUN6_ABI.md): `wrun_bar_count() -> i32`, the number of bars the
3
+ * run holds while a row is evaluated, the forming bar included. It is the length of the series a
4
+ * kScript script reads ahead in (the engine's source `data.length`, the bound ichimoku()'s lagging
5
+ * span tests `i + displacement` against), so a row can tell whether a later row exists.
6
+ *
7
+ * The engine's semantics (v3.0.92), which every host mirrors: a full run and every reseed load the
8
+ * source whole, so every bar reads the bars loaded; live, a forming tick recomputes the forming bar
9
+ * only (the count it reads is unchanged), and a NEW bar re-seeds, recomputing every bar with the
10
+ * new length. The chart's worker answers the count (wrun-abi-host); the live tick reopens the
11
+ * session over every bar when a bar appears for a module that imports it (the reseed), and every
12
+ * other module keeps the close-confirm.
13
+ *
14
+ * Beside it, the chart's corroboration of the history-independent stamp (`history_independent: true`,
15
+ * kit 0.66.0): a module that reads the row count is never history-independent, and the stamp is
16
+ * admitted only when the module imports nothing outside the kit's per-bar list
17
+ * (`wrunStampCorroborated`) and the sheet passes the kit's sheet facts (`wrunStampSheetRefusal`, the
18
+ * kit's own rules ported), so a stamp hand-added to a published sheet still answers to the module it
19
+ * ships beside and to the facts the kit checks.
20
+ *
21
+ * The exact warm-up stamp (`history_warmup`, round A of the warm-up program) answers to the same module and
22
+ * sheet checks (`wrunWarmupStampOf` reads it, `wrunWarmupSheetRefusal` adds the one fact of its own: never
23
+ * beside `history_independent`), and a warm-up session must read the chart's own candles alone
24
+ * (`wrunWarmupSheetReadsCandlesOnly`): its hidden head is candles, so a book, a leg, a feed or a poll lane
25
+ * would reach the head's bars without their rows.
26
+ *
27
+ * Pure and worker-safe.
28
+ */
29
+ import { abiAtLeast } from '../../interfaces/wrun-runtime.interface.js';
30
+ import { wrunHistoryWarmupOf } from './wrun-declared-warmup.util.js';
31
+ import { isWrunLegStreamClass } from './wrun-leg-stream-classes.js';
32
+ /** The import (the one the shared host links under wrun-6; wrun-bar-count.kit-mirror.spec.ts). */
33
+ export const WRUN6_BAR_IMPORTS = ['wrun:wrun_bar_count'];
34
+ /** The refusal names a host raises on the row count (a code of the shared host's refusal table). */
35
+ export const WRUN6_BAR_REFUSALS = {
36
+ /** wrun_bar_count called outside state() and finalize(). */
37
+ phase: 'wrun_bar_count_phase',
38
+ };
39
+ const BAR_COUNT_IMPORT_NAME = WRUN6_BAR_IMPORTS[0].slice('wrun:'.length);
40
+ const importsByModule = new WeakMap();
41
+ /** Whether a module imports the row count (read once per module). */
42
+ export function wrunModuleImportsBarCount(module) {
43
+ let imports = importsByModule.get(module);
44
+ if (imports === undefined) {
45
+ imports = WebAssembly.Module.imports(module).some((entry) => entry.module === 'wrun' && entry.name === BAR_COUNT_IMPORT_NAME);
46
+ importsByModule.set(module, imports);
47
+ }
48
+ return imports;
49
+ }
50
+ /** Whether a module READS the row count under its ABI: wrun-6 or later and the import declared.
51
+ * Such a module's live session re-runs every bar when a bar appears; any other keeps the
52
+ * close-confirm. */
53
+ export function wrunModuleReadsBarCount(module, abi) {
54
+ return abiAtLeast(abi, 'wrun-6') && wrunModuleImportsBarCount(module);
55
+ }
56
+ /**
57
+ * The import names a stamped module may carry: the kit's own list (`WRUN_HISTORY_INDEPENDENT_IMPORTS`,
58
+ * wrun-history-independence.ts, kit 0.67.1), name for name, read as the kit's decision reads them
59
+ * (`WebAssembly.Module.imports(module).map((entry) => entry.name)`): the argument readers `wrun_arg_*`
60
+ * (a row's scalar inputs and, during init(), the numeric and boolean setting readers), the cell channel
61
+ * `wrun_arg_len` and `wrun_arg_bytes` (this bar's block), the output writers `wrun_output_f64` and
62
+ * `wrun_result_write`, `abort`, and the text channel `wrun_param_len` and `wrun_param_bytes`. The text
63
+ * channel is admitted because a text setting is fixed for the run and read once in init(): the generated
64
+ * reader runs there, before onStart(), both hosts trap the two imports anywhere else, and the kit's walker
65
+ * refuses every `pt_*` read, so the setting's byte count reaches bar code through `p_<name>()` like any
66
+ * setting. Every other import refuses: the row count (`wrun_bar_count`), the last-bar signal
67
+ * (`wrun_bar_last`), the draw, string, frame and strategy channels, and any import a later kit adds until
68
+ * it is listed here (wrun-bar-count.util.spec.ts runs the kit's own decision over every host import and
69
+ * holds this list to exactly the names it admits).
70
+ */
71
+ export const WRUN_STAMP_IMPORTS = new Set([
72
+ 'abort',
73
+ 'wrun_arg_count',
74
+ 'wrun_arg_i32',
75
+ 'wrun_arg_i64',
76
+ 'wrun_arg_f32',
77
+ 'wrun_arg_f64',
78
+ 'wrun_output_f64',
79
+ 'wrun_result_write',
80
+ 'wrun_arg_len',
81
+ 'wrun_arg_bytes',
82
+ 'wrun_param_len',
83
+ 'wrun_param_bytes',
84
+ ]);
85
+ const stampImportsByModule = new WeakMap();
86
+ /** Whether every import of a module is on the kit's per-bar list (`WRUN_STAMP_IMPORTS`), read once per
87
+ * module; a module the engine cannot read answers false. */
88
+ export function wrunStampCorroborated(module) {
89
+ const known = stampImportsByModule.get(module);
90
+ if (known !== undefined)
91
+ return known;
92
+ let within = false;
93
+ try {
94
+ within = WebAssembly.Module.imports(module).every((entry) => WRUN_STAMP_IMPORTS.has(entry.name));
95
+ }
96
+ catch {
97
+ // Not a module the engine can read: never corroborated.
98
+ }
99
+ stampImportsByModule.set(module, within);
100
+ return within;
101
+ }
102
+ // ---------------------------------------------------------------------------------------------------
103
+ // The stamp's sheet facts: the kit's `sheetRefusal` (wrun-history-independence.ts, kit 0.66.0) ported
104
+ // rule for rule, with its helpers (`carries`, `wrunTapeHistorySeconds` of wrun-vocab.ts), so a stamp
105
+ // hand-added to a published sheet answers to the facts the kit checked before it wrote an honest one.
106
+ // The kit's decision is not reachable here without loading the whole kit on the main thread;
107
+ // wrun-bar-count.util.spec.ts holds the port to the kit's own answers once the kit exports it.
108
+ // ---------------------------------------------------------------------------------------------------
109
+ /** The sheet sections whose presence refuses (the kit's REFUSED_SHEET_KEYS): each keeps or shows state a
110
+ * later bar reads (a handle, a string slot, a drawing, a frame), draws across bars (renderers, levels,
111
+ * panels), or runs a broker or an alert over the whole series. Present means not undefined: an empty
112
+ * section and a null one refuse too. */
113
+ const STAMP_REFUSED_SHEET_KEYS = [
114
+ 'handles',
115
+ 'string_slots',
116
+ 'drawings',
117
+ 'renderers',
118
+ 'frames',
119
+ 'levels',
120
+ 'panels',
121
+ 'strategy',
122
+ 'alerts',
123
+ ];
124
+ /** The ABIs without the row count (wrun-6's `wrun_bar_count`); an absent `abi_version` is wrun-1. */
125
+ const STAMP_BAR_COUNT_FREE_ABIS = ['wrun-1', 'wrun-2', 'wrun-3', 'wrun-4', 'wrun-5'];
126
+ /** A tape `history` duration: digits, then a unit. "0" alone is the live edge (the default). */
127
+ const TAPE_HISTORY_RE = /^(\d+)(s|m|h|d)$/;
128
+ const TAPE_HISTORY_UNIT_SEC = { s: 1, m: 60, h: 3600, d: 86_400 };
129
+ /** The seconds a tape input's `history` facet reaches back (the kit's `wrunTapeHistorySeconds`): 0 for an
130
+ * absent facet, for "0" and for a zero-length duration ("0m"), the duration's length otherwise, NaN for
131
+ * any other spelling. */
132
+ function tapeHistorySeconds(history) {
133
+ if (history === undefined || history === '0')
134
+ return 0;
135
+ const match = TAPE_HISTORY_RE.exec(history);
136
+ if (match === null)
137
+ return Number.NaN;
138
+ return Number(match[1]) * (TAPE_HISTORY_UNIT_SEC[match[2]] ?? Number.NaN);
139
+ }
140
+ function isRecord(value) {
141
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
142
+ }
143
+ /** The first sheet fact that reads or draws beyond the bar at hand, in the kit's own words
144
+ * (`sheet:<fact>[:<name>]`); undefined when the sheet passes. */
145
+ export function wrunStampSheetRefusal(sheet) {
146
+ if (!isRecord(sheet))
147
+ return 'sheet:invalid';
148
+ for (const key of STAMP_REFUSED_SHEET_KEYS) {
149
+ if (sheet[key] !== undefined)
150
+ return `sheet:${key}`;
151
+ }
152
+ if (sheet.abi_version !== undefined && !STAMP_BAR_COUNT_FREE_ABIS.includes(sheet.abi_version)) {
153
+ return `sheet:abi_version:${String(sheet.abi_version)}`;
154
+ }
155
+ const inputSources = sheet.inputSources;
156
+ if (!isRecord(inputSources))
157
+ return 'sheet:inputSources';
158
+ const inputs = Array.isArray(sheet.inputs) ? sheet.inputs : [];
159
+ for (const [name, source] of Object.entries(inputSources)) {
160
+ if (!isRecord(source))
161
+ return `sheet:input:${name}`;
162
+ // A leg (an `interval` or a `view` option), a leg stream (candles, oi_candles, volume_profile_candles) or an
163
+ // intrabar input: its first delivered rows depend on where the run starts (a view such as `is_new_period`
164
+ // reads 1 on the first delivered row; a stream's first block carries its backlog from before the window).
165
+ if (source.interval !== undefined ||
166
+ source.view !== undefined ||
167
+ isWrunLegStreamClass(source.source) ||
168
+ source.source === 'intrabar') {
169
+ return `sheet:input-leg:${name}`;
170
+ }
171
+ // A leg's or a candles stream's fetch depth: the bar reads earlier candles.
172
+ if (source.bars !== undefined)
173
+ return `sheet:input-bars:${name}`;
174
+ // A tape lookback: the host seeds prints from before the run's window; a zero-length spelling ("0",
175
+ // the default) is the live edge alone.
176
+ if (source.history !== undefined) {
177
+ if (typeof source.history !== 'string' || tapeHistorySeconds(source.history) !== 0) {
178
+ return `sheet:input-history:${name}`;
179
+ }
180
+ }
181
+ const input = inputs.find((entry) => isRecord(entry) && entry.name === name);
182
+ if (carries(source, isRecord(input) ? input : undefined))
183
+ return `sheet:input-carry:${name}`;
184
+ }
185
+ const outputs = Array.isArray(sheet.outputs) ? sheet.outputs : [];
186
+ for (const output of outputs) {
187
+ if (!isRecord(output))
188
+ return 'sheet:outputs';
189
+ if (output.displacement_bars !== undefined || output.displacement_bars_by !== undefined) {
190
+ return `sheet:output-displacement:${String(output.name)}`;
191
+ }
192
+ }
193
+ return undefined;
194
+ }
195
+ /** Whether an input can hand a bar a value observed on an earlier bar (the kit's `carries`): `missing:
196
+ * "carry"`, or the default that means it (a series source, and any other scalar input beside the primary
197
+ * that is not the chart's own candle or time feed, which observes every bar). A celled input reads an
198
+ * empty block on a bar with no observation; "nan", "zero" and "empty" carry nothing. */
199
+ function carries(source, input) {
200
+ if (source.missing === 'carry')
201
+ return true;
202
+ if (source.missing !== undefined)
203
+ return false;
204
+ if (source.source === 'series')
205
+ return true;
206
+ if (input !== undefined && input.cellType === 'array')
207
+ return false;
208
+ if (input !== undefined && input.index === 0)
209
+ return false;
210
+ const chartFeed = (source.source === 'ohlcv' || source.source === 'time') &&
211
+ Object.keys(source).every((key) => key === 'source' || key === 'field' || source[key] === undefined);
212
+ return !chartFeed;
213
+ }
214
+ // ---------------------------------------------------------------------------------------------------
215
+ // The exact warm-up stamp (`history_warmup`): read, its sheet fact, the candles-only rule.
216
+ // ---------------------------------------------------------------------------------------------------
217
+ /** The sheet's raw exact warm-up stamp: its `history_warmup` in the frozen shape (wrun-declared-warmup.util
218
+ * `wrunHistoryWarmupOf`), undefined for no key, another kind or a malformed value. The chart admits a
219
+ * session on it only once the module and the sheet corroborate it (wrun-overlay-run.util). */
220
+ export function wrunWarmupStampOf(sheet) {
221
+ return isRecord(sheet) ? wrunHistoryWarmupOf(sheet.history_warmup) : undefined;
222
+ }
223
+ /** The first sheet fact that refuses an exact warm-up stamp: `sheet:history-both` for a sheet that also carries
224
+ * `history_independent` (the kit writes one stamp or the other, never both: a sheet holding both was assembled
225
+ * by hand), then the per-bar stamp's own sheet facts (`wrunStampSheetRefusal`, the same rules: a warm-up module
226
+ * carries kit instances, never a handle, a string slot, a leg or a carried input); undefined when it passes. */
227
+ export function wrunWarmupSheetRefusal(sheet) {
228
+ if (isRecord(sheet) && sheet.history_independent !== undefined)
229
+ return 'sheet:history-both';
230
+ return wrunStampSheetRefusal(sheet);
231
+ }
232
+ /** The input-source keys a chart-feed input may carry: the chart's own feed field and its missing policy. */
233
+ const CHART_FEED_SOURCE_KEYS = new Set(['source', 'field', 'missing']);
234
+ /** Whether one input reads the chart's own feed, the chart-feed shape (the plan's D3, the kit's `sheet:lanes`
235
+ * rule): `ohlcv` or `time`, with no key besides source, field and missing (no market, interval, view or depth of
236
+ * its own) and no cells. A row of the chart's candles carries every such input itself: its prices, and the bar
237
+ * times read off its own open. The exact warm-up rule below reads it, and the prefix lanes rule reads it for a
238
+ * `time` input (wrun-overlay-run.util). */
239
+ export function wrunInputReadsChartFeed(input, source) {
240
+ if (!isRecord(source) || (source.source !== 'ohlcv' && source.source !== 'time'))
241
+ return false;
242
+ if (isRecord(input) && input.cellType !== undefined)
243
+ return false;
244
+ return Object.keys(source).every((key) => CHART_FEED_SOURCE_KEYS.has(key) || source[key] === undefined);
245
+ }
246
+ /** Whether every input the sheet declares reads the chart's own feed (`wrunInputReadsChartFeed`). Those are the
247
+ * only rows an exact warm-up session's hidden head carries: its candles, and the bar times read off their own
248
+ * opens. A sheet with no input reads nothing a head could feed and is not candles-only. */
249
+ export function wrunWarmupSheetReadsCandlesOnly(sheet) {
250
+ if (!isRecord(sheet) || !isRecord(sheet.inputSources) || !Array.isArray(sheet.inputs))
251
+ return false;
252
+ if (sheet.inputs.length === 0)
253
+ return false;
254
+ const sources = sheet.inputSources;
255
+ return sheet.inputs.every((input) => {
256
+ const name = isRecord(input) ? input.name : undefined;
257
+ return wrunInputReadsChartFeed(input, typeof name === 'string' ? sources[name] : undefined);
258
+ });
259
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The chart names a WRUN run's `{{symbol}}`, `{{exchange}}` and
3
+ * `{{timeframe}}` placeholders read (KITS-ROUND-2-PLAN, "Chart-name
4
+ * placeholders"), resolved on the main thread per chart index exactly the
5
+ * way the chart header shows them:
6
+ *
7
+ * - symbol: the TickerBar's display symbol (useSymbolData's `displaySymbol`,
8
+ * built on `resolveChartSymbolData`: the "prefix+coin+quote" of a market, a
9
+ * formula's expression by labels, an economic series' label, a prediction
10
+ * market's title; the raw metadata symbol before the resolve lands).
11
+ * - exchange: the header's display exchange name (TBSymbolButton: a
12
+ * prediction market's `formatEnhancedExchangeName` upper-cased, a formula's
13
+ * one venue label, an economic series' publisher label, else
14
+ * `formatExchangeDisplay` over the venue and `displayTransformations`).
15
+ * - timeframe: the short label the interval button shows (the replay
16
+ * display interval when replaying, else the chart interval word).
17
+ *
18
+ * The resolve is async (the symbol lookup). A run resolves its names beside
19
+ * its fetches and integrates with the names IT resolved; the names a live
20
+ * session was integrated with ride beside the session's live context
21
+ * (`rememberWrunSessionChartNames`, set by the full run and the reseed) and
22
+ * the live tick and the latest-values snapshot read them from there, so a
23
+ * superseded run's late lookup can never retitle a later session. The
24
+ * per-chart "latest" record (`wrunChartNamesFor`) is written only by the
25
+ * newest resolve started for that chart: every write is fenced by a token
26
+ * captured at the resolve's start and a stale resolve is dropped. Main
27
+ * thread only: the header formatters reach i18n, which the worker graph must
28
+ * not.
29
+ */
30
+ import type { WrunSymbolDisplayData } from '../../host-ports.types.js';
31
+ import type { WrunChartNames } from './wrun-chart-context.util.js';
32
+ /** The chart metadata slice the names read. */
33
+ export interface WrunChartNameSource {
34
+ symbol?: unknown;
35
+ exchange?: unknown;
36
+ interval?: unknown;
37
+ displayTransformations?: unknown;
38
+ polymarketMetadata?: {
39
+ fullName?: unknown;
40
+ title?: unknown;
41
+ } | null;
42
+ }
43
+ /** The header's display symbol (useSymbolData's `displaySymbol`): a
44
+ * prediction market's title, a formula's labelled expression, an economic
45
+ * series' label, else "prefix+coin+quote" (a pool address appended), and
46
+ * the raw metadata symbol while nothing is resolved. On a plain market the
47
+ * three parts are slices of the venue's own symbol, so the name is that
48
+ * symbol, the string a kScript's `currentSymbol` reads on the same chart
49
+ * (1000PEPEUSDT keeps its 1000, KRW-RLUSD its KRW-). */
50
+ export declare function wrunChartDisplaySymbol(meta: WrunChartNameSource | undefined, data: WrunSymbolDisplayData | null | undefined): string;
51
+ /** The header's display exchange name (TBSymbolButton): a prediction
52
+ * market's short venue label upper-cased (HYPERLIQUID_HIP4 reads "HL
53
+ * HIP4"), a formula's one venue label, an economic series' resolved
54
+ * publisher label, else `formatExchangeDisplay` over the venue and
55
+ * `displayTransformations`. */
56
+ export declare function wrunChartDisplayExchange(meta: WrunChartNameSource | undefined, data: WrunSymbolDisplayData | null | undefined): string;
57
+ /** The short label the interval button shows: the replay display interval
58
+ * while replaying, else the chart interval word ('15m', '1h'). */
59
+ export declare function wrunChartTimeframe(meta: WrunChartNameSource | undefined, displayInterval: unknown): string;
60
+ /** Keep the names a live session was integrated with beside its live
61
+ * context (the full run's install, the reseed's commit); undefined forgets. */
62
+ export declare function rememberWrunSessionChartNames(session: object, names: WrunChartNames | undefined): void;
63
+ /** The names a live session was integrated with (the live tick's and the
64
+ * snapshot's synchronous read); undefined for a session that resolved none. */
65
+ export declare function wrunSessionChartNamesOf(session: object | undefined): WrunChartNames | undefined;
66
+ /** The newest resolve's names for a chart (fenced: a late, superseded
67
+ * resolve never writes it); undefined before any resolve. Diagnostic and
68
+ * fallback reader; the run path reads its session's names instead. */
69
+ export declare function wrunChartNamesFor(chartIndex: number): WrunChartNames | undefined;
70
+ export declare function __resetWrunChartNamesForTests(): void;
71
+ /**
72
+ * Resolve a chart's names off the store and the header's symbol resolver.
73
+ * The chart metadata is read at the start (the names describe the chart the
74
+ * run computes on), the symbol lookup follows; the per-chart latest record
75
+ * is written only when no newer resolve for the chart started meanwhile
76
+ * (the token captured here), so a superseded run's late answer is dropped
77
+ * there while the run itself still receives its own names. Never throws: a
78
+ * chart that is gone answers undefined; a symbol resolve that fails (or a
79
+ * store the spec did not stand up) falls back to the raw metadata names, the
80
+ * way the header shows the raw symbol before its resolve lands. The store
81
+ * and the resolver are loaded lazily: their graphs are heavy and only a run
82
+ * needs them here.
83
+ */
84
+ export declare function resolveWrunChartNames(chartIndex: number): Promise<WrunChartNames | undefined>;
@@ -0,0 +1,186 @@
1
+ /**
2
+ * The chart names a WRUN run's `{{symbol}}`, `{{exchange}}` and
3
+ * `{{timeframe}}` placeholders read (KITS-ROUND-2-PLAN, "Chart-name
4
+ * placeholders"), resolved on the main thread per chart index exactly the
5
+ * way the chart header shows them:
6
+ *
7
+ * - symbol: the TickerBar's display symbol (useSymbolData's `displaySymbol`,
8
+ * built on `resolveChartSymbolData`: the "prefix+coin+quote" of a market, a
9
+ * formula's expression by labels, an economic series' label, a prediction
10
+ * market's title; the raw metadata symbol before the resolve lands).
11
+ * - exchange: the header's display exchange name (TBSymbolButton: a
12
+ * prediction market's `formatEnhancedExchangeName` upper-cased, a formula's
13
+ * one venue label, an economic series' publisher label, else
14
+ * `formatExchangeDisplay` over the venue and `displayTransformations`).
15
+ * - timeframe: the short label the interval button shows (the replay
16
+ * display interval when replaying, else the chart interval word).
17
+ *
18
+ * The resolve is async (the symbol lookup). A run resolves its names beside
19
+ * its fetches and integrates with the names IT resolved; the names a live
20
+ * session was integrated with ride beside the session's live context
21
+ * (`rememberWrunSessionChartNames`, set by the full run and the reseed) and
22
+ * the live tick and the latest-values snapshot read them from there, so a
23
+ * superseded run's late lookup can never retitle a later session. The
24
+ * per-chart "latest" record (`wrunChartNamesFor`) is written only by the
25
+ * newest resolve started for that chart: every write is fenced by a token
26
+ * captured at the resolve's start and a stale resolve is dropped. Main
27
+ * thread only: the header formatters reach i18n, which the worker graph must
28
+ * not.
29
+ */
30
+ import { wrunChartHostEnv } from '../../host-env.js';
31
+ import { formatEnhancedExchangeName } from '../../constants/exchange-names.leaf.js';
32
+ import { checkIsPredictionMarket } from '../chart/index-mode.util.js';
33
+ import { formatExchangeDisplay } from '../exchange-format.leaf.js';
34
+ import { formatPoolAddress } from '../pool-symbol.leaf.js';
35
+ function nonEmptyString(value) {
36
+ return typeof value === 'string' && value !== '' ? value : undefined;
37
+ }
38
+ /** The header's display symbol (useSymbolData's `displaySymbol`): a
39
+ * prediction market's title, a formula's labelled expression, an economic
40
+ * series' label, else "prefix+coin+quote" (a pool address appended), and
41
+ * the raw metadata symbol while nothing is resolved. On a plain market the
42
+ * three parts are slices of the venue's own symbol, so the name is that
43
+ * symbol, the string a kScript's `currentSymbol` reads on the same chart
44
+ * (1000PEPEUSDT keeps its 1000, KRW-RLUSD its KRW-). */
45
+ export function wrunChartDisplaySymbol(meta, data) {
46
+ const raw = nonEmptyString(meta?.symbol) ?? '';
47
+ const pm = meta?.polymarketMetadata;
48
+ if (pm)
49
+ return nonEmptyString(pm.fullName) ?? nonEmptyString(pm.title) ?? raw;
50
+ if (!data)
51
+ return raw;
52
+ if (data.isTransformation)
53
+ return data.displayExpression ?? data.fullSymbol;
54
+ if (data.isFred)
55
+ return data.coin;
56
+ return `${data.prefix ?? ''}${data.coin}${data.quote}${data.poolAddress ? ` · ${formatPoolAddress(data.poolAddress)}` : ''}`;
57
+ }
58
+ /** The header's display exchange name (TBSymbolButton): a prediction
59
+ * market's short venue label upper-cased (HYPERLIQUID_HIP4 reads "HL
60
+ * HIP4"), a formula's one venue label, an economic series' resolved
61
+ * publisher label, else `formatExchangeDisplay` over the venue and
62
+ * `displayTransformations`. */
63
+ export function wrunChartDisplayExchange(meta, data) {
64
+ const exchange = nonEmptyString(meta?.exchange);
65
+ if (exchange !== undefined && checkIsPredictionMarket(exchange)) {
66
+ return formatEnhancedExchangeName(exchange).toUpperCase();
67
+ }
68
+ if (data?.isTransformation)
69
+ return data.formulaVenueLabel ?? '';
70
+ if (data?.isFred && nonEmptyString(data.exchangeDisplay) !== undefined)
71
+ return data.exchangeDisplay;
72
+ if (exchange === undefined)
73
+ return '';
74
+ return formatExchangeDisplay(exchange.toUpperCase(), nonEmptyString(meta?.displayTransformations));
75
+ }
76
+ /** The short label the interval button shows: the replay display interval
77
+ * while replaying, else the chart interval word ('15m', '1h'). */
78
+ export function wrunChartTimeframe(meta, displayInterval) {
79
+ return nonEmptyString(displayInterval) ?? nonEmptyString(meta?.interval) ?? '';
80
+ }
81
+ // ---------------------------------------------------------------------------
82
+ // Per-session names (the live context) and the fenced per-chart latest.
83
+ // ---------------------------------------------------------------------------
84
+ const namesBySession = new WeakMap();
85
+ /** Keep the names a live session was integrated with beside its live
86
+ * context (the full run's install, the reseed's commit); undefined forgets. */
87
+ export function rememberWrunSessionChartNames(session, names) {
88
+ if (names === undefined)
89
+ namesBySession.delete(session);
90
+ else
91
+ namesBySession.set(session, names);
92
+ }
93
+ /** The names a live session was integrated with (the live tick's and the
94
+ * snapshot's synchronous read); undefined for a session that resolved none. */
95
+ export function wrunSessionChartNamesOf(session) {
96
+ return session === undefined ? undefined : namesBySession.get(session);
97
+ }
98
+ const latestByChart = new Map();
99
+ const generationByChart = new Map();
100
+ /**
101
+ * Whether a chart header exists to mirror: the header's symbol resolver
102
+ * (`resolveChartSymbolData`) lives in the DOM app's graph (the icon
103
+ * composable, the user store, the metadata service), already loaded by the
104
+ * TickerBar before any run, so its lazy import resolves within microtasks.
105
+ * A host without a document (the node specs, a headless run) has no header,
106
+ * and loading that graph there is a cold, seconds-long import that would hold
107
+ * the run open across timer ticks; the raw metadata names are what such a
108
+ * host shows.
109
+ */
110
+ function wrunChartHeaderPresent() {
111
+ return typeof document !== 'undefined';
112
+ }
113
+ /** The newest resolve's names for a chart (fenced: a late, superseded
114
+ * resolve never writes it); undefined before any resolve. Diagnostic and
115
+ * fallback reader; the run path reads its session's names instead. */
116
+ export function wrunChartNamesFor(chartIndex) {
117
+ return latestByChart.get(chartIndex);
118
+ }
119
+ export function __resetWrunChartNamesForTests() {
120
+ latestByChart.clear();
121
+ generationByChart.clear();
122
+ }
123
+ /**
124
+ * Resolve a chart's names off the store and the header's symbol resolver.
125
+ * The chart metadata is read at the start (the names describe the chart the
126
+ * run computes on), the symbol lookup follows; the per-chart latest record
127
+ * is written only when no newer resolve for the chart started meanwhile
128
+ * (the token captured here), so a superseded run's late answer is dropped
129
+ * there while the run itself still receives its own names. Never throws: a
130
+ * chart that is gone answers undefined; a symbol resolve that fails (or a
131
+ * store the spec did not stand up) falls back to the raw metadata names, the
132
+ * way the header shows the raw symbol before its resolve lands. The store
133
+ * and the resolver are loaded lazily: their graphs are heavy and only a run
134
+ * needs them here.
135
+ */
136
+ export async function resolveWrunChartNames(chartIndex) {
137
+ const token = (generationByChart.get(chartIndex) ?? 0) + 1;
138
+ generationByChart.set(chartIndex, token);
139
+ const current = () => generationByChart.get(chartIndex) === token;
140
+ let meta;
141
+ let displayInterval;
142
+ try {
143
+ const { useChartStore } = await wrunChartHostEnv().chart.loadChartStore();
144
+ const store = useChartStore();
145
+ meta = store.mergedAllCharts[chartIndex]?.metadata;
146
+ displayInterval = store
147
+ .replayDisplayIntervalByChart?.[chartIndex];
148
+ }
149
+ catch {
150
+ meta = undefined;
151
+ }
152
+ if (meta === undefined) {
153
+ if (current())
154
+ latestByChart.delete(chartIndex);
155
+ return undefined;
156
+ }
157
+ let data = null;
158
+ if (wrunChartHeaderPresent()) {
159
+ try {
160
+ const { resolveChartSymbolData } = await wrunChartHostEnv().market.loadSymbolDisplay();
161
+ data = await resolveChartSymbolData(chartIndex);
162
+ }
163
+ catch {
164
+ // The raw metadata names below, the way the header shows the raw symbol before its resolve lands.
165
+ }
166
+ }
167
+ let names;
168
+ try {
169
+ names = {
170
+ symbol: wrunChartDisplaySymbol(meta, data),
171
+ exchange: wrunChartDisplayExchange(meta, data),
172
+ timeframe: wrunChartTimeframe(meta, displayInterval),
173
+ };
174
+ }
175
+ catch {
176
+ // A header formatter a spec did not stand up: the raw metadata names.
177
+ names = {
178
+ symbol: nonEmptyString(meta.symbol) ?? '',
179
+ exchange: nonEmptyString(meta.exchange) ?? '',
180
+ timeframe: wrunChartTimeframe(meta, displayInterval),
181
+ };
182
+ }
183
+ if (current())
184
+ latestByChart.set(chartIndex, names);
185
+ return names;
186
+ }