@orangecharts/wrun-chart-host 0.9.0 → 0.11.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 (252) hide show
  1. package/README.md +2 -0
  2. package/dist/constants/feature-flags.constants.d.ts +15 -1
  3. package/dist/constants/feature-flags.constants.js +130 -24
  4. package/dist/constants/governed-exchanges.constants.d.ts +12 -0
  5. package/dist/constants/governed-exchanges.constants.js +16 -0
  6. package/dist/constants/opra-compliance.constants.d.ts +3 -2
  7. package/dist/constants/opra-compliance.constants.js +3 -2
  8. package/dist/constants/option-venues.constants.d.ts +2 -2
  9. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
  10. package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
  11. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
  12. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
  13. package/dist/constants/venue-presets.constants.d.ts +20 -20
  14. package/dist/constants/venue-presets.constants.js +24 -26
  15. package/dist/host-env.d.ts +21 -5
  16. package/dist/host-env.js +6 -0
  17. package/dist/host-ports.types.d.ts +102 -19
  18. package/dist/index.d.ts +18 -0
  19. package/dist/index.js +18 -0
  20. package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
  21. package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
  22. package/dist/interfaces/cme-realtime.interface.js +6 -3
  23. package/dist/interfaces/kscript-diagnostics.interface.d.ts +12 -0
  24. package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
  25. package/dist/interfaces/prediction-market.interface.d.ts +7 -0
  26. package/dist/interfaces/replay.interface.d.ts +8 -0
  27. package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
  28. package/dist/interfaces/stocks-realtime.interface.js +32 -0
  29. package/dist/interfaces/wrun-runtime.interface.d.ts +18 -2
  30. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +62 -94
  31. package/dist/kscript-data/controls/live-trades-merge.util.js +106 -171
  32. package/dist/market-data/billing.interface.d.ts +174 -36
  33. package/dist/market-data/billing.interface.js +58 -8
  34. package/dist/market-data/venue.d.ts +152 -7
  35. package/dist/market-data/venues/cme.contract.copy.json +66 -0
  36. package/dist/market-data/venues/cme.d.ts +126 -0
  37. package/dist/market-data/venues/cme.js +133 -0
  38. package/dist/market-data/venues/index.d.ts +294 -7
  39. package/dist/market-data/venues/index.js +49 -6
  40. package/dist/market-data/venues/opra.contract.copy.json +3 -2
  41. package/dist/market-data/venues/opra.d.ts +2 -2
  42. package/dist/market-data/venues/opra.js +5 -2
  43. package/dist/market-data/venues/stocks.contract.copy.json +64 -0
  44. package/dist/market-data/venues/stocks.d.ts +130 -0
  45. package/dist/market-data/venues/stocks.js +117 -0
  46. package/dist/settings-templates/footprint-rows.js +35 -2
  47. package/dist/settings-templates/form-rows.d.ts +2 -1
  48. package/dist/settings-templates/index.js +7 -3
  49. package/dist/settings-templates/indicator-fields.d.ts +5 -4
  50. package/dist/settings-templates/indicator-fields.js +79 -10
  51. package/dist/settings-templates/tool-rules.d.ts +32 -15
  52. package/dist/settings-templates/tool-rules.js +33 -11
  53. package/dist/settings-templates/tool-tables.generated.js +95 -31
  54. package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
  55. package/dist/utility/chart/book-live-bucket.util.js +47 -0
  56. package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
  57. package/dist/utility/chart/cme-cache-context.util.js +10 -6
  58. package/dist/utility/chart/cme-realtime.util.js +10 -0
  59. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
  60. package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
  61. package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
  62. package/dist/utility/chart/effective-chart-session.util.js +39 -0
  63. package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
  64. package/dist/utility/chart/host-bar-placement.util.js +170 -30
  65. package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
  66. package/dist/utility/chart/index-host-tier.util.js +7 -2
  67. package/dist/utility/chart/index-mode-admission.util.js +30 -3
  68. package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
  69. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
  70. package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
  71. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +9 -7
  72. package/dist/utility/chart/kscript-live-coalesce.util.js +13 -8
  73. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
  74. package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
  75. package/dist/utility/chart/kscript-provenance-keys.util.js +13 -0
  76. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +5 -1
  77. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
  78. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
  79. package/dist/utility/chart/kscript-venue-policy.util.d.ts +156 -43
  80. package/dist/utility/chart/kscript-venue-policy.util.js +249 -59
  81. package/dist/utility/chart/live-bucket.util.d.ts +24 -8
  82. package/dist/utility/chart/live-bucket.util.js +85 -27
  83. package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
  84. package/dist/utility/chart/market-session-schedule.util.js +16 -0
  85. package/dist/utility/chart/marketKind.util.js +5 -0
  86. package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
  87. package/dist/utility/chart/mixed-mode.util.js +14 -0
  88. package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
  89. package/dist/utility/chart/opra-read-access.leaf.js +5 -3
  90. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
  91. package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
  92. package/dist/utility/chart/rth-session.util.d.ts +12 -10
  93. package/dist/utility/chart/rth-session.util.js +25 -21
  94. package/dist/utility/chart/trading-day.util.d.ts +17 -0
  95. package/dist/utility/chart/trading-day.util.js +59 -0
  96. package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
  97. package/dist/utility/chart/window-geometry.leaf.js +22 -6
  98. package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
  99. package/dist/utility/chart/window-owner.leaf.js +45 -3
  100. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
  101. package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
  102. package/dist/utility/chart/wrun-run-result.util.d.ts +12 -0
  103. package/dist/utility/chart/wrun-run-result.util.js +141 -6
  104. package/dist/utility/intl-locale.util.js +5 -0
  105. package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
  106. package/dist/utility/options/option-bar-anchor.util.js +340 -0
  107. package/dist/utility/options/option-venue.util.d.ts +18 -0
  108. package/dist/utility/options/option-venue.util.js +27 -0
  109. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +4 -0
  110. package/dist/utility/v2/gate-plane.util.d.ts +12 -3
  111. package/dist/utility/v2/gate-plane.util.js +30 -4
  112. package/dist/utility/v2/gate-session-latch.util.js +1 -1
  113. package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
  114. package/dist/utility/v2/stocks-governed.util.js +34 -0
  115. package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
  116. package/dist/utility/wrun/derived-roots.leaf.js +27 -0
  117. package/dist/utility/wrun/derived-roots.util.d.ts +205 -0
  118. package/dist/utility/wrun/derived-roots.util.js +451 -0
  119. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +43 -7
  120. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
  121. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
  122. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
  123. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +4 -2
  124. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +4 -2
  125. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
  126. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
  127. package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
  128. package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
  129. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
  130. package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
  131. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
  132. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +2 -1
  133. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +3 -0
  134. package/dist/utility/wrun/sources/row-lanes/option_prints.js +19 -4
  135. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
  136. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +52 -13
  137. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +88 -19
  138. package/dist/utility/wrun/sources/row-lanes/option_surface.js +2 -1
  139. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
  140. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +24 -9
  141. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +41 -10
  142. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +111 -0
  143. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +133 -0
  144. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +15 -3
  145. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +22 -3
  146. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -0
  147. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +197 -13
  148. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +761 -27
  149. package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
  150. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
  151. package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
  152. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +60 -16
  153. package/dist/utility/wrun/wrun-chart-market-facts.util.js +113 -61
  154. package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
  155. package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
  156. package/dist/utility/wrun/wrun-download-meter.util.d.ts +15 -0
  157. package/dist/utility/wrun/wrun-download-meter.util.js +14 -2
  158. package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
  159. package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
  160. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
  161. package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
  162. package/dist/utility/wrun/wrun-frames.d.ts +27 -6
  163. package/dist/utility/wrun/wrun-frames.js +73 -10
  164. package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
  165. package/dist/utility/wrun/wrun-handles.util.js +9 -8
  166. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
  167. package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
  168. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +18 -4
  169. package/dist/utility/wrun/wrun-hud-looks.util.js +45 -13
  170. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
  171. package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
  172. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
  173. package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
  174. package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
  175. package/dist/utility/wrun/wrun-live-intake.util.d.ts +35 -15
  176. package/dist/utility/wrun/wrun-live-intake.util.js +243 -126
  177. package/dist/utility/wrun/wrun-live-tick.util.d.ts +13 -5
  178. package/dist/utility/wrun/wrun-live-tick.util.js +279 -99
  179. package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
  180. package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
  181. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +60 -11
  182. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +70 -5
  183. package/dist/utility/wrun/wrun-market-size-defaults.util.js +31 -5
  184. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
  185. package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
  186. package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
  187. package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
  188. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
  189. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
  190. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +23 -6
  191. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +47 -11
  192. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +86 -19
  193. package/dist/utility/wrun/wrun-option-strike-flow.util.js +168 -62
  194. package/dist/utility/wrun/wrun-option-views.util.d.ts +323 -28
  195. package/dist/utility/wrun/wrun-option-views.util.js +484 -71
  196. package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
  197. package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
  198. package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
  199. package/dist/utility/wrun/wrun-output-style.util.js +20 -2
  200. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +32 -2
  201. package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
  202. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
  203. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
  204. package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
  205. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +160 -42
  206. package/dist/utility/wrun/wrun-overlay-run.util.js +1244 -209
  207. package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
  208. package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
  209. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
  210. package/dist/utility/wrun/wrun-panel-mount.util.js +114 -19
  211. package/dist/utility/wrun/wrun-panel-style.util.d.ts +10 -9
  212. package/dist/utility/wrun/wrun-panel-style.util.js +58 -9
  213. package/dist/utility/wrun/wrun-param-map.util.d.ts +14 -11
  214. package/dist/utility/wrun/wrun-param-map.util.js +10 -5
  215. package/dist/utility/wrun/wrun-param-values.util.d.ts +14 -4
  216. package/dist/utility/wrun/wrun-param-values.util.js +4 -0
  217. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
  218. package/dist/utility/wrun/wrun-pin-spelling.util.js +39 -14
  219. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
  220. package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
  221. package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
  222. package/dist/utility/wrun/wrun-refusal.util.js +22 -0
  223. package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
  224. package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
  225. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
  226. package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
  227. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
  228. package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
  229. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
  230. package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
  231. package/dist/utility/wrun/wrun-run-interval.util.d.ts +43 -9
  232. package/dist/utility/wrun/wrun-run-interval.util.js +58 -15
  233. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +45 -1
  234. package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
  235. package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
  236. package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
  237. package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
  238. package/dist/utility/wrun/wrun-socket-row-source.js +118 -8
  239. package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -18
  240. package/dist/utility/wrun/wrun-source-rows.util.js +61 -27
  241. package/dist/utility/wrun/wrun-style-words.util.js +6 -4
  242. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
  243. package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
  244. package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
  245. package/dist/utility/wrun/wrun-tape-per-order.util.js +7 -0
  246. package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
  247. package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
  248. package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
  249. package/dist/utils/replay/replay-buffer-math.js +227 -20
  250. package/dist/workers/constants/socket-slots.d.ts +91 -6
  251. package/dist/workers/constants/socket-slots.js +85 -6
  252. package/package.json +5 -5
@@ -0,0 +1,142 @@
1
+ /**
2
+ * The `cme-user-scripts` gate as the venue policy reads it (kscript-venue-policy.util, the one decider of the governed
3
+ * walls: `isCmeUserScriptRun`), and the authorisation epoch every door that lands a CME user study's answer compares.
4
+ * Dependency-free on purpose (zero imports), the shape of the pre-retirement opra-user-scripts gate: the venue policy
5
+ * stays worker-safe and store-free, so the main thread hands it readers instead.
6
+ *
7
+ * The gate is open only while BOTH of its facts answer `true`, each read live on every call:
8
+ * - The flag. The flags store registers its override-aware `isOn` as the fallback when it is created, and publishes
9
+ * its reader again after every successful fetch. Until a fetch publishes, the fallback answers, so the dev and
10
+ * internal `kiyo.flag-overrides` lens reaches the walls before the map lands and through a failed fetch, exactly as
11
+ * it reaches every surface that reads `isOn`: the walls and the surfaces never disagree.
12
+ * - The viewer's CME entitlement. The web hands its `viewerMayReadCme()` reader: signed in, not a guest, the CME data
13
+ * terms not blocked. Delayed and real-time access both count: the tier a read rides is the gate plane's, decided per
14
+ * socket, never this answer's.
15
+ *
16
+ * Fail closed everywhere: in any context neither reader reached (a worker, a guest, a spec without a store), a reader
17
+ * that throws and a reader that answers anything but `true` read the gate closed, today's CME wall. The flag is never
18
+ * read server-side: kscript-backend denies CME to every user run whatever it says.
19
+ *
20
+ * The authorisation epoch (`cmeStudyAuthEpoch`, `bumpCmeStudyAuthEpoch`, `captureCmeStudyAuth`,
21
+ * `isCmeStudyAuthCurrent`): the generation model of the options chain's governed access
22
+ * (src/workers/indicators/options-chain-state.worker.util.ts `syncGovernedChainAccess`), moved to the main thread. The
23
+ * main-thread lifecycle watcher (web: `installCmeUserStudyLifecycle`, cme-user-scripts-lifecycle.util) bumps it
24
+ * whenever an input of a CME user study's authorisation moves: the account id, the CME data-terms state, the CME served
25
+ * access, the flag, a session expiry or a session swap. A run captures a token before it asks; every door that lands
26
+ * its answer (titan-charts' dataFetch result, the script engine's result, the wrun run's `isCurrent`) compares the
27
+ * token and drops an answer from a previous authorisation context, so a late answer never lands after access changed.
28
+ * A missing token is never current. The epoch is main-thread state: a worker's copy of this module never sees a bump,
29
+ * so a worker carries the captured token back and never judges it. Publishing a reader never moves the epoch (a flag
30
+ * fetch publishes after every fetch, moved or not): only the watcher bumps it, on a move it saw.
31
+ *
32
+ * The stopped-study register (`markCmeStudyStopped`, `clearCmeStudyStopped`, `cmeStudyStopReason`,
33
+ * `isCmeStudyStopped`): the studies the lifecycle watcher stopped in place when the gate closed (the viewer's access
34
+ * changed, or the flag went dark), keyed by chart index and overlay id. Main-thread state, never persisted: the
35
+ * workspace row and the editor tab keep their source and settings, the register only tells Door H which words to paint
36
+ * ("Access changed; the study stopped" or "CME chart studies are turned off") and the local-engine self-heal which rows
37
+ * to leave alone. The re-judgment that mounts a study again clears its row; a chart teardown clears the chart's rows.
38
+ *
39
+ * The remount stash (`stashCmeStudyRemount`, `cmeStudyRemountStash`): what a stopped study's remount needs that its
40
+ * workspace row does not carry, kept beside its register row and dropped with it by `clearCmeStudyStopped` (one clear,
41
+ * so a stash never outlives the stop it belongs to). An editor draft's source is the case: the add strips
42
+ * `settings.script` from the mounted config once the worker engine holds it, and a draft's row is session-only, so
43
+ * once its engine is destroyed nothing else on the page holds its code. Typed `unknown` here: the web lifecycle writes
44
+ * it, the web re-judgment reads it. Main-thread state, never persisted.
45
+ */
46
+ let published = null;
47
+ let fallback = null;
48
+ let entitlement = null;
49
+ let authEpoch = 0;
50
+ const stopped = new Map();
51
+ const remountStash = new Map();
52
+ function stoppedKey(chartIndex, overlayId) {
53
+ return `${chartIndex}:${overlayId}`;
54
+ }
55
+ /** Record a study the lifecycle stopped in place (Door H paints the reason's words until it is cleared). */
56
+ export function markCmeStudyStopped(chartIndex, overlayId, reason) {
57
+ stopped.set(stoppedKey(chartIndex, overlayId), reason);
58
+ }
59
+ /** Forget one stopped study, or every stopped study of a chart when no overlay id is given, with its remount stash. */
60
+ export function clearCmeStudyStopped(chartIndex, overlayId) {
61
+ if (overlayId !== undefined) {
62
+ stopped.delete(stoppedKey(chartIndex, overlayId));
63
+ remountStash.delete(stoppedKey(chartIndex, overlayId));
64
+ return;
65
+ }
66
+ const prefix = `${chartIndex}:`;
67
+ for (const store of [stopped, remountStash]) {
68
+ for (const key of Array.from(store.keys())) {
69
+ if (key.startsWith(prefix))
70
+ store.delete(key);
71
+ }
72
+ }
73
+ }
74
+ /** Keep what a stopped study's remount needs and its row does not carry (the header); `clearCmeStudyStopped` drops it. */
75
+ export function stashCmeStudyRemount(chartIndex, overlayId, remount) {
76
+ remountStash.set(stoppedKey(chartIndex, overlayId), remount);
77
+ }
78
+ /** What the lifecycle kept for a stopped study's remount, or undefined when its row carries all it needs. */
79
+ export function cmeStudyRemountStash(chartIndex, overlayId) {
80
+ return remountStash.get(stoppedKey(chartIndex, overlayId));
81
+ }
82
+ /** The reason a study was stopped, or undefined for a study the lifecycle never stopped. */
83
+ export function cmeStudyStopReason(chartIndex, overlayId) {
84
+ return stopped.get(stoppedKey(chartIndex, overlayId));
85
+ }
86
+ /** Whether the lifecycle stopped this study and nothing has mounted it again since. */
87
+ export function isCmeStudyStopped(chartIndex, overlayId) {
88
+ return stopped.has(stoppedKey(chartIndex, overlayId));
89
+ }
90
+ /** Called by the flags store after a successful fetch (and by specs); null unpublishes. */
91
+ export function publishCmeUserScriptsFlag(next) {
92
+ published = next;
93
+ }
94
+ /** Called by the flags store when it is created: its override-aware `isOn`, read until a fetch publishes. */
95
+ export function setCmeUserScriptsFlagFallback(next) {
96
+ fallback = next;
97
+ }
98
+ /** Called by the web with its `viewerMayReadCme()` reader (signed in, not a guest, CME data terms not blocked); null
99
+ * unregisters, and no reader reads closed. */
100
+ export function setCmeUserScriptsEntitlementReader(next) {
101
+ entitlement = next;
102
+ }
103
+ /** Whether the `cme-user-scripts` flag is on for this session: the published answer, else the store's own; closed
104
+ * when neither can tell. The flag alone: the walls read `isCmeUserScriptsGateOpen`. */
105
+ export function isCmeUserScriptsFlagOn() {
106
+ try {
107
+ return (published ?? fallback)?.() === true;
108
+ }
109
+ catch {
110
+ return false;
111
+ }
112
+ }
113
+ /** Whether the viewer's entitlement reader answers `true`; closed with no reader. */
114
+ function viewerMayReadCmeNow() {
115
+ try {
116
+ return entitlement?.() === true;
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ /** Whether the CME plane may open to a user run the browser executes: the flag lit AND the viewer entitled. */
123
+ export function isCmeUserScriptsGateOpen() {
124
+ return isCmeUserScriptsFlagOn() && viewerMayReadCmeNow();
125
+ }
126
+ /** The authorisation epoch now (see the header). */
127
+ export function cmeStudyAuthEpoch() {
128
+ return authEpoch;
129
+ }
130
+ /** Move the epoch on: every token captured before is no longer current. Returns the new epoch. */
131
+ export function bumpCmeStudyAuthEpoch() {
132
+ authEpoch += 1;
133
+ return authEpoch;
134
+ }
135
+ /** The token a run captures before it asks (frozen: a holder cannot move it forward). */
136
+ export function captureCmeStudyAuth() {
137
+ return Object.freeze({ epoch: authEpoch });
138
+ }
139
+ /** Whether a captured token is from the current authorisation context; a missing or malformed token is not. */
140
+ export function isCmeStudyAuthCurrent(token) {
141
+ return typeof token?.epoch === 'number' && token.epoch === authEpoch;
142
+ }
@@ -0,0 +1,14 @@
1
+ export type ChartSessionWord = 'regular' | 'extended';
2
+ /**
3
+ * The session the chart rides on this market at this interval. An absent or unknown word reads as the market's
4
+ * default. On a market with an RTH window the answer is 'regular' only while `isChartRthActive` holds for a
5
+ * 'regular' choice at `interval` (the chart's interval label or milliseconds; an unknown interval reads as
6
+ * inactive), else 'extended'. Every other market keeps the normalised word.
7
+ */
8
+ export declare function effectiveChartSessionType(exchange: unknown, symbol: unknown, interval: unknown, sessionType: unknown): ChartSessionWord;
9
+ /**
10
+ * Whether the word only spells this market's default: it is absent (undefined or null) or equals
11
+ * `defaultChartSessionType(symbol, exchange)`. Writing such a word over an absent one changes the persisted document,
12
+ * never what the chart rides or what any request asks.
13
+ */
14
+ export declare function isSpelledChartSessionDefault(exchange: unknown, symbol: unknown, sessionType: unknown): boolean;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The chart session every identity, key, compare and planner frame reads: what the chart RIDES, never how its
3
+ * persisted word is spelled.
4
+ *
5
+ * `metadata.sessionType` is a persisted choice: 'regular' (RTH), 'extended' (ETH), or absent, which every reader takes
6
+ * as the market's default (`defaultChartSessionType`: 'extended' on a future with an RTH window, 'regular' elsewhere).
7
+ * The chart rides RTH only while `isChartRthActive` holds: a 'regular' choice, an intraday interval and a root with an
8
+ * RTH window. Read verbatim, the word turned two no-ops into session flips: a spelled default (a settings confirm
9
+ * stamps the default onto a document that never carried the word) and a 'regular' a future keeps at daily and higher,
10
+ * where the chart rides the full session. Left out of an identity, a real flip went unseen.
11
+ *
12
+ * Markets without an RTH window (Polygon equities, crypto, unmapped CME roots) keep the normalised word: there
13
+ * 'regular' and 'extended' are the equities extended-hours flag, which this module never folds.
14
+ *
15
+ * A pure leaf: it imports the RTH predicates only (rth-session.util, worker-safe and store-free), so the store-free
16
+ * modules that read it (the pane planner, the wrun drivers registry) keep the chart store out of their eager graph.
17
+ */
18
+ import { chartIntervalToMs, defaultChartSessionType, hasRthWindow, isChartRthActive } from './rth-session.util.js';
19
+ /**
20
+ * The session the chart rides on this market at this interval. An absent or unknown word reads as the market's
21
+ * default. On a market with an RTH window the answer is 'regular' only while `isChartRthActive` holds for a
22
+ * 'regular' choice at `interval` (the chart's interval label or milliseconds; an unknown interval reads as
23
+ * inactive), else 'extended'. Every other market keeps the normalised word.
24
+ */
25
+ export function effectiveChartSessionType(exchange, symbol, interval, sessionType) {
26
+ const word = sessionType === 'regular' || sessionType === 'extended' ? sessionType : null;
27
+ const chosen = word ?? defaultChartSessionType(symbol, exchange);
28
+ if (chosen === 'extended' || !hasRthWindow(symbol, exchange))
29
+ return chosen;
30
+ return isChartRthActive(exchange, symbol, 'regular', chartIntervalToMs(interval)) ? 'regular' : 'extended';
31
+ }
32
+ /**
33
+ * Whether the word only spells this market's default: it is absent (undefined or null) or equals
34
+ * `defaultChartSessionType(symbol, exchange)`. Writing such a word over an absent one changes the persisted document,
35
+ * never what the chart rides or what any request asks.
36
+ */
37
+ export function isSpelledChartSessionDefault(exchange, symbol, sessionType) {
38
+ return sessionType === undefined || sessionType === null || sessionType === defaultChartSessionType(symbol, exchange);
39
+ }
@@ -40,6 +40,14 @@ export interface IndexHostBars {
40
40
  * from its own rows, with no bucket call.
41
41
  */
42
42
  export declare function hostBarRowOf(barTs: number, rows: readonly number[][], merge: Exclude<IndexHostMerge, 'cells'>): number[];
43
+ /**
44
+ * A row's last instant (the last-instant placement's key): its bar's true end on the row's own grid less one
45
+ * (`rowVenue`, `liveBucketVenueOf` of the rows' market: a session's stub ends at its close, so a NYMEX RTH 4h row
46
+ * opening 13:00 New York lasts to 14:29:59, inside an ES RTH host's 13:30 bar, where its nominal span ran past the ES
47
+ * close and the row was dropped); the nominal span (`openMs + rowSpanMs - 1`) without a grid, or for a row that opens
48
+ * no bar on it.
49
+ */
50
+ export declare function rowLastInstantMs(openMs: number, rowSpanMs: number, rowVenue?: LiveBucketVenue | null): number;
43
51
  /** Options of `placeRowsInHostBars`. */
44
52
  export interface PlaceRowsInHostBarsOptions {
45
53
  /**
@@ -64,6 +72,14 @@ export interface PlaceRowsInHostBarsOptions {
64
72
  * absent or null, no row takes it.
65
73
  */
66
74
  formingBarTs?: number | null;
75
+ /**
76
+ * The rows' own bar grid at `rowSpanMs` (`liveBucketVenueOf` of their
77
+ * market, at the session their wire serves): a row's last instant is its
78
+ * bar's true end there (`rowLastInstantMs`: a session's stub ends at its
79
+ * close), not the nominal span, which overshoots a host's earlier close and
80
+ * dropped the row. Absent, the nominal span.
81
+ */
82
+ rowVenue?: LiveBucketVenue | null;
67
83
  }
68
84
  /**
69
85
  * Place every row in the host bar whose [open, close) holds its timestamp and
@@ -105,3 +121,15 @@ export declare function placeRowsInHostBars(rows: readonly number[][], bars: Ind
105
121
  export declare function createHostBucketResolver(intervalMs: number, venue: LiveBucketVenue | null | undefined): (tsMs: number) => number | null;
106
122
  /** The shared `createHostBucketResolver` of a host grid (every live door on that grid reuses its cached span). */
107
123
  export declare function hostBucketResolverFor(intervalMs: number, venue: LiveBucketVenue | null | undefined): (tsMs: number) => number | null;
124
+ /**
125
+ * A live door's bar for a frame of a source on its own row grid (`rowSpanMs` rows on `rowVenue`): the bar the
126
+ * last-instant placement (`placeRowsInHostBars` with `rowSpanMs` and `rowVenue`, dataFetch's STEP 4) puts the row
127
+ * holding the frame's instant in, judged at `nowMs` as a fetch then would, so a fold and the next fetch of its row land
128
+ * in one bar. A row opening a host bar lands on it; any other keys on its last instant (`rowLastInstantMs`): in a bar
129
+ * opened by then it lands there (a replay, a frame late across a boundary), in a later bar it shows in the forming bar
130
+ * holding its open (the live edge), and with no bar (closing past the session close) nowhere, null, as with no row at
131
+ * the instant. Judged at the later of `nowMs` and the instant (a device clock inside the server-clock deadband).
132
+ */
133
+ export declare function createSourceRowHostBarResolver(intervalMs: number, venue: LiveBucketVenue | null | undefined, rowSpanMs: number, rowVenue: LiveBucketVenue | null | undefined): (instantMs: number, nowMs: number) => number | null;
134
+ /** The shared `createSourceRowHostBarResolver` of a host grid and a row grid (every live door on the pair reuses it). */
135
+ export declare function sourceRowHostBarResolverFor(intervalMs: number, venue: LiveBucketVenue | null | undefined, rowSpanMs: number, rowVenue: LiveBucketVenue | null | undefined): (instantMs: number, nowMs: number) => number | null;
@@ -15,8 +15,9 @@
15
15
  *
16
16
  * Pure: the package's bucket function and session option, nothing else.
17
17
  */
18
- import { liveBucketStartMs } from './live-bucket.util.js';
18
+ import { liveBucketBarsAreLabels, liveBucketStartMs } from './live-bucket.util.js';
19
19
  import { usEquitiesSessionConfig } from './us-equities-session.util.js';
20
+ const MINUTE_MS = 60_000;
20
21
  function isAscendingByTs(rows) {
21
22
  for (let i = 1; i < rows.length; i++)
22
23
  if (rows[i][0] < rows[i - 1][0])
@@ -124,9 +125,15 @@ function heldRowsAfterOpen(keyAt, from, to, barTs, intervalMs, venue, hint) {
124
125
  * 12h, the last bar) asks the host's bucket function once per bar span
125
126
  * (`heldRowsAfterOpen`). Keys before the first bar, off session or in a bar
126
127
  * the host does not hold land nowhere. Returns where the keys the LAST bar
127
- * does not hold begin (`count` when none is left past it).
128
+ * does not hold begin (`count` when none is left past it). On a grid whose
129
+ * stamps are labels, not opens (`liveBucketBarsAreLabels`), a bar spans no
130
+ * [stamp, next stamp) window at all: `sweepLabelledHostBars` books every key,
131
+ * and a bar whose keys are interleaved with keys it does not hold (a 3d bar's
132
+ * nights) gets one run each: `onBar` takes every run of a bar, in key order.
128
133
  */
129
134
  function sweepHostBars(count, keyAt, main, intervalMs, venue, onBar) {
135
+ if (liveBucketBarsAreLabels(intervalMs, venue))
136
+ return sweepLabelledHostBars(count, keyAt, main, intervalMs, venue, onBar);
130
137
  let next = 0;
131
138
  let hint = 0;
132
139
  let pastLastBar = count;
@@ -155,6 +162,44 @@ function sweepHostBars(count, keyAt, main, intervalMs, venue, onBar) {
155
162
  }
156
163
  return pastLastBar;
157
164
  }
165
+ /**
166
+ * The sweep on a grid whose stamps are labels (`liveBucketBarsAreLabels`: the CME trade-date lattice from a day up, a
167
+ * regular-session stock's 3d group): every key lands on the mounted bar the host's own bucket function books it to
168
+ * (`hostBucketResolverFor`, one bucket call per bar span), the evening before a trade-date label included, a key
169
+ * stamped on a mounted label staying on it, so the placement and the live doors book an instant alike. Keys ascend and
170
+ * so do their bars, so each bar's keys are one run. Returns where the keys past the last bar begin: after the last key
171
+ * it holds, else at the first key booked past it (`count` when none is).
172
+ */
173
+ function sweepLabelledHostBars(count, keyAt, main, intervalMs, venue, onBar) {
174
+ const barOf = hostBucketResolverFor(intervalMs, venue);
175
+ const indexOfBar = new Map();
176
+ for (let index = 0; index < main.length; index++)
177
+ indexOfBar.set(main[index][0], index);
178
+ const lastIndex = main.length - 1;
179
+ const lastBarTs = main[lastIndex][0];
180
+ let lastHeldEnd = -1;
181
+ let firstPast = count;
182
+ let runIndex = -1;
183
+ let runFrom = 0;
184
+ for (let k = 0; k < count; k++) {
185
+ const key = keyAt(k);
186
+ const bar = indexOfBar.has(key) ? key : barOf(key);
187
+ const index = bar === null ? -1 : (indexOfBar.get(bar) ?? -1);
188
+ if (index !== runIndex) {
189
+ if (runIndex >= 0)
190
+ onBar(runIndex, runFrom, k);
191
+ runIndex = index;
192
+ runFrom = k;
193
+ }
194
+ if (index === lastIndex)
195
+ lastHeldEnd = k + 1;
196
+ else if (firstPast === count && (bar === null ? key > lastBarTs : bar > lastBarTs))
197
+ firstPast = k;
198
+ }
199
+ if (runIndex >= 0)
200
+ onBar(runIndex, runFrom, count);
201
+ return lastHeldEnd >= 0 ? lastHeldEnd : firstPast;
202
+ }
158
203
  /** The index of the mounted bar whose [open, close) holds `ms` (the sweep's own span rule), or -1. */
159
204
  function barIndexHolding(main, ms, intervalMs, venue) {
160
205
  let lo = 0;
@@ -169,40 +214,96 @@ function barIndexHolding(main, ms, intervalMs, venue) {
169
214
  else
170
215
  hi = mid - 1;
171
216
  }
217
+ if (found >= 0 && ms === main[found][0])
218
+ return found;
219
+ if (liveBucketBarsAreLabels(intervalMs, venue)) {
220
+ // A label bar holds instants before its stamp (the evening before a trade date): the bucket function names it.
221
+ const bar = liveBucketStartMs(ms, intervalMs, venue);
222
+ if (bar === null)
223
+ return -1;
224
+ if (found >= 0 && main[found][0] === bar)
225
+ return found;
226
+ return main[found + 1]?.[0] === bar ? found + 1 : -1;
227
+ }
172
228
  if (found < 0)
173
229
  return -1;
174
230
  const barTs = main[found][0];
175
- if (ms === barTs || main[found + 1]?.[0] === barTs + intervalMs)
231
+ if (main[found + 1]?.[0] === barTs + intervalMs)
176
232
  return found;
177
233
  return liveBucketStartMs(ms, intervalMs, venue) === barTs ? found : -1;
178
234
  }
235
+ /** Adds one run of a bar's keys (or rows) after its earlier runs: the sweep hands a bar each run in key order. */
236
+ function appendRun(groups, key, run) {
237
+ const held = groups.get(key);
238
+ if (held === undefined)
239
+ groups.set(key, run);
240
+ else
241
+ for (const item of run)
242
+ held.push(item);
243
+ }
179
244
  function isAscendingNumbers(values) {
180
245
  for (let i = 1; i < values.length; i++)
181
246
  if (values[i] < values[i - 1])
182
247
  return false;
183
248
  return true;
184
249
  }
250
+ /**
251
+ * The exclusive end of the bar opening at `openMs` on a venue's grid at `intervalMs` (`liveBucketStartMs`): the full
252
+ * interval where the bar holds its last instant, else the first minute past the open it does not hold (a session's
253
+ * stub ends at its close: an RTH 4h bar opening 13:00 New York on NYMEX ends 14:30), found by bisection on the minute
254
+ * grid every session boundary sits on.
255
+ */
256
+ function venueBarEndMs(openMs, intervalMs, venue) {
257
+ const full = openMs + intervalMs;
258
+ if (liveBucketStartMs(full - 1, intervalMs, venue) === openMs)
259
+ return full;
260
+ let held = Math.floor(openMs / MINUTE_MS);
261
+ let notHeld = Math.floor((full - 1) / MINUTE_MS);
262
+ while (notHeld - held > 1) {
263
+ const mid = Math.floor((held + notHeld) / 2);
264
+ if (liveBucketStartMs(mid * MINUTE_MS, intervalMs, venue) === openMs)
265
+ held = mid;
266
+ else
267
+ notHeld = mid;
268
+ }
269
+ return Math.max(openMs + 1, notHeld * MINUTE_MS);
270
+ }
271
+ /**
272
+ * A row's last instant (the last-instant placement's key): its bar's true end on the row's own grid less one
273
+ * (`rowVenue`, `liveBucketVenueOf` of the rows' market: a session's stub ends at its close, so a NYMEX RTH 4h row
274
+ * opening 13:00 New York lasts to 14:29:59, inside an ES RTH host's 13:30 bar, where its nominal span ran past the ES
275
+ * close and the row was dropped); the nominal span (`openMs + rowSpanMs - 1`) without a grid, or for a row that opens
276
+ * no bar on it.
277
+ */
278
+ export function rowLastInstantMs(openMs, rowSpanMs, rowVenue) {
279
+ const venue = rowVenue ?? undefined;
280
+ if (venue !== undefined && liveBucketStartMs(openMs, rowSpanMs, venue) === openMs) {
281
+ return venueBarEndMs(openMs, rowSpanMs, venue) - 1;
282
+ }
283
+ return openMs + rowSpanMs - 1;
284
+ }
185
285
  /**
186
286
  * The last-instant placement (`PlaceRowsInHostBarsOptions.rowSpanMs`): every
187
- * row keys on its last instant (`ts + rowSpanMs - 1`) unless it is stamped on
188
- * a mounted bar's open, the shared sweep lands the keys, and a row whose last
189
- * instant only a bar after the last mounted one holds (the live edge) lands in
190
- * the bar holding its open. Each bar's rows merge in timestamp order.
287
+ * row keys on its last instant (`rowLastInstantMs`: `ts + rowSpanMs - 1`, or
288
+ * its bar's true end on `rowVenue`) unless it is stamped on a mounted bar's
289
+ * open, the shared sweep lands the keys, and a row whose last instant only a
290
+ * bar after the last mounted one holds (the live edge) lands in the bar
291
+ * holding its open. Each bar's rows merge in timestamp order.
191
292
  */
192
- function placeRowsByLastInstant(sorted, bars, rowSpanMs, formingBarTs, land) {
293
+ function placeRowsByLastInstant(sorted, bars, rowSpanMs, formingBarTs, land, rowVenue) {
193
294
  const main = bars.mainRows;
194
295
  const { intervalMs } = bars;
195
296
  const venue = bars.venue ?? undefined;
196
297
  const opens = new Set();
197
298
  for (const bar of main)
198
299
  opens.add(bar[0]);
199
- const keys = sorted.map((row) => (opens.has(row[0]) ? row[0] : row[0] + rowSpanMs - 1));
300
+ const keys = sorted.map((row) => (opens.has(row[0]) ? row[0] : rowLastInstantMs(row[0], rowSpanMs, rowVenue)));
200
301
  const order = keys.map((_, index) => index);
201
302
  // Rows denser than their span can key out of order: sort by key, ties in timestamp order.
202
303
  if (!isAscendingNumbers(keys))
203
304
  order.sort((a, b) => keys[a] - keys[b] || a - b);
204
305
  const groups = new Map();
205
- const pastLastBar = sweepHostBars(order.length, (k) => keys[order[k]], main, intervalMs, venue, (barIndex, from, to) => groups.set(barIndex, order.slice(from, to)));
306
+ const pastLastBar = sweepHostBars(order.length, (k) => keys[order[k]], main, intervalMs, venue, (barIndex, from, to) => appendRun(groups, barIndex, order.slice(from, to)));
206
307
  // The live edge: a row whose last instant falls in a bar the host has not
207
308
  // printed yet is still forming, and the bar holding its open shows its
208
309
  // latest value, but only when that bar is the one forming NOW
@@ -280,7 +381,7 @@ function placeCellsInHostBars(sorted, bars, out, onMade) {
280
381
  if (!isAscendingNumbers(instants))
281
382
  order.sort((a, b) => instants[a] - instants[b] || a - b);
282
383
  const byBar = new Map();
283
- sweepHostBars(order.length, (k) => instants[order[k]], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => byBar.set(main[barIndex][0], order.slice(from, to)));
384
+ sweepHostBars(order.length, (k) => instants[order[k]], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => appendRun(byBar, main[barIndex][0], order.slice(from, to)));
284
385
  for (const barTs of bare.keys())
285
386
  if (!byBar.has(barTs))
286
387
  byBar.set(barTs, []);
@@ -343,10 +444,14 @@ export function placeRowsInHostBars(rows, bars, merge, onMade, opts) {
343
444
  };
344
445
  const rowSpanMs = opts?.rowSpanMs;
345
446
  if (typeof rowSpanMs === 'number' && Number.isFinite(rowSpanMs) && rowSpanMs > 0) {
346
- placeRowsByLastInstant(sorted, bars, rowSpanMs, opts?.formingBarTs ?? null, land);
447
+ placeRowsByLastInstant(sorted, bars, rowSpanMs, opts?.formingBarTs ?? null, land, opts?.rowVenue);
347
448
  return out;
348
449
  }
349
- sweepHostBars(sorted.length, (index) => sorted[index][0], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => land(main[barIndex][0], sorted.slice(from, to)));
450
+ // A bar's runs (one, but on a label grid's interleaved bar) land together, the bars in order.
451
+ const runs = new Map();
452
+ sweepHostBars(sorted.length, (index) => sorted[index][0], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => appendRun(runs, barIndex, sorted.slice(from, to)));
453
+ for (const [barIndex, group] of runs)
454
+ land(main[barIndex][0], group);
350
455
  return out;
351
456
  }
352
457
  /** The inputs `liveBucketStartMs` reads for a venue at an interval (the extended-hours option included). */
@@ -360,7 +465,6 @@ function gridKeyOf(intervalMs, venue) {
360
465
  usEquitiesSessionConfig.extendedHoursEnabled,
361
466
  ].join('|');
362
467
  }
363
- const MINUTE_MS = 60_000;
364
468
  /**
365
469
  * A host's bucket function for a stream of instants (a live door's ticks):
366
470
  * `liveBucketStartMs` over `venue` at `intervalMs`, asked only when an instant
@@ -397,22 +501,8 @@ export function createHostBucketResolver(intervalMs, venue) {
397
501
  barEnds.set(bar, end);
398
502
  return end;
399
503
  };
400
- const findBarEnd = (bar) => {
401
- const full = bar + intervalMs;
402
- if (liveBucketStartMs(full - 1, intervalMs, v) === bar)
403
- return full;
404
- // A stub: the first minute past `bar` that the bar does not hold.
405
- let held = Math.floor(bar / MINUTE_MS);
406
- let notHeld = Math.floor((full - 1) / MINUTE_MS);
407
- while (notHeld - held > 1) {
408
- const mid = Math.floor((held + notHeld) / 2);
409
- if (liveBucketStartMs(mid * MINUTE_MS, intervalMs, v) === bar)
410
- held = mid;
411
- else
412
- notHeld = mid;
413
- }
414
- return Math.max(bar + 1, notHeld * MINUTE_MS);
415
- };
504
+ // A stub's end is the first minute past `bar` that the bar does not hold.
505
+ const findBarEnd = (bar) => venueBarEndMs(bar, intervalMs, v);
416
506
  return (tsMs) => {
417
507
  if (!Number.isFinite(tsMs) || !(intervalMs > 0))
418
508
  return null;
@@ -445,3 +535,53 @@ export function hostBucketResolverFor(intervalMs, venue) {
445
535
  }
446
536
  return resolve;
447
537
  }
538
+ /**
539
+ * A live door's bar for a frame of a source on its own row grid (`rowSpanMs` rows on `rowVenue`): the bar the
540
+ * last-instant placement (`placeRowsInHostBars` with `rowSpanMs` and `rowVenue`, dataFetch's STEP 4) puts the row
541
+ * holding the frame's instant in, judged at `nowMs` as a fetch then would, so a fold and the next fetch of its row land
542
+ * in one bar. A row opening a host bar lands on it; any other keys on its last instant (`rowLastInstantMs`): in a bar
543
+ * opened by then it lands there (a replay, a frame late across a boundary), in a later bar it shows in the forming bar
544
+ * holding its open (the live edge), and with no bar (closing past the session close) nowhere, null, as with no row at
545
+ * the instant. Judged at the later of `nowMs` and the instant (a device clock inside the server-clock deadband).
546
+ */
547
+ export function createSourceRowHostBarResolver(intervalMs, venue, rowSpanMs, rowVenue) {
548
+ // One span cache per lookup (rows, the bars a row keys into, the bar forming now); a row's bars once per row.
549
+ const rowAt = createHostBucketResolver(rowSpanMs, rowVenue);
550
+ const barAt = createHostBucketResolver(intervalMs, venue);
551
+ const barNow = createHostBucketResolver(intervalMs, venue);
552
+ let row = Number.NaN;
553
+ let openBar = null;
554
+ let keyBar = null;
555
+ return (instantMs, nowMs) => {
556
+ const rowOpen = rowAt(instantMs);
557
+ if (rowOpen === null)
558
+ return null;
559
+ if (rowOpen !== row) {
560
+ openBar = barAt(rowOpen);
561
+ keyBar = openBar === rowOpen ? rowOpen : barAt(rowLastInstantMs(rowOpen, rowSpanMs, rowVenue));
562
+ row = rowOpen;
563
+ }
564
+ if (openBar === rowOpen || keyBar === null)
565
+ return keyBar;
566
+ const atMs = Math.max(nowMs, instantMs);
567
+ if (keyBar <= atMs)
568
+ return keyBar;
569
+ const forming = barNow(atMs);
570
+ if (keyBar === forming)
571
+ return keyBar;
572
+ return openBar !== null && openBar === forming ? openBar : null;
573
+ };
574
+ }
575
+ const sourceRowResolvers = new Map();
576
+ /** The shared `createSourceRowHostBarResolver` of a host grid and a row grid (every live door on the pair reuses it). */
577
+ export function sourceRowHostBarResolverFor(intervalMs, venue, rowSpanMs, rowVenue) {
578
+ const key = `${gridKeyOf(intervalMs, venue)}#${gridKeyOf(rowSpanMs, rowVenue)}`;
579
+ let resolve = sourceRowResolvers.get(key);
580
+ if (!resolve) {
581
+ if (sourceRowResolvers.size >= RESOLVER_MEMO_MAX)
582
+ sourceRowResolvers.clear();
583
+ resolve = createSourceRowHostBarResolver(intervalMs, venue, rowSpanMs, rowVenue);
584
+ sourceRowResolvers.set(key, resolve);
585
+ }
586
+ return resolve;
587
+ }
@@ -26,6 +26,8 @@ export declare function indexHostFetchTierMs(intervalMs: number, hostVenue: Live
26
26
  * Then the row closing first inside a host bar opens before that bar, so a
27
27
  * fetch placed by last instant (`PlaceRowsInHostBarsOptions.rowSpanMs`) asks
28
28
  * one source span early to hold the first bar's row. A source on the host's
29
- * own grid, or a finer grid dividing it, never straddles.
29
+ * own grid, or a finer grid dividing it, never straddles, and neither does a
30
+ * host bar no source row holds (a regular-session source's night under a 24/7
31
+ * host's 15m bars: no row opens before it).
30
32
  */
31
33
  export declare function sourceRowsStraddleHostBars(intervalMs: number, hostVenue: LiveBucketVenue | null | undefined, rowSpanMs: number, sourceVenue: LiveBucketVenue | null | undefined): boolean;
@@ -100,7 +100,9 @@ const straddleByGrids = new Map();
100
100
  * Then the row closing first inside a host bar opens before that bar, so a
101
101
  * fetch placed by last instant (`PlaceRowsInHostBarsOptions.rowSpanMs`) asks
102
102
  * one source span early to hold the first bar's row. A source on the host's
103
- * own grid, or a finer grid dividing it, never straddles.
103
+ * own grid, or a finer grid dividing it, never straddles, and neither does a
104
+ * host bar no source row holds (a regular-session source's night under a 24/7
105
+ * host's 15m bars: no row opens before it).
104
106
  */
105
107
  export function sourceRowsStraddleHostBars(intervalMs, hostVenue, rowSpanMs, sourceVenue) {
106
108
  if (!(intervalMs > 0) || !(rowSpanMs > 0))
@@ -110,7 +112,10 @@ export function sourceRowsStraddleHostBars(intervalMs, hostVenue, rowSpanMs, sou
110
112
  const memo = straddleByGrids.get(memoKey);
111
113
  if (memo !== undefined)
112
114
  return memo;
113
- const straddles = probeGrid(intervalMs, hostVenue, hostKey).opens.some((open) => liveBucketStartMs(open, rowSpanMs, sourceVenue ?? undefined) !== open);
115
+ const straddles = probeGrid(intervalMs, hostVenue, hostKey).opens.some((open) => {
116
+ const rowOpen = liveBucketStartMs(open, rowSpanMs, sourceVenue ?? undefined);
117
+ return rowOpen !== null && rowOpen !== open;
118
+ });
114
119
  if (straddleByGrids.size >= TIER_MEMO_MAX)
115
120
  straddleByGrids.clear();
116
121
  straddleByGrids.set(memoKey, straddles);
@@ -14,10 +14,17 @@
14
14
  * Two market facts narrow it for a browser-run Indicator's lanes (`wrunLaneServiceOnMarket`):
15
15
  * - the market-kind table: forex and commodities trade no volume the chart can split, keep no
16
16
  * book and list no options, so they serve no volume profile, buy/sell volume, order book,
17
- * implied volatility or skew, whatever the index-mode admission lets through; a crypto index
17
+ * implied volatility or skew, whatever the index-mode admission lets through; a US equity
18
+ * market of the tradfi kind (the listing venues, Polygon under both enum names) prints no
19
+ * aggressor side, so it serves no buy/sell volume either (the gateway writes every such trade
20
+ * row as side 0 and the lane keeps BUY and SELL rows only, so the lane is empty and a recipe's
21
+ * zero fill would draw that as flat flow), except the three consolidated tapes (`NASDAQ_TAPE`,
22
+ * `NYSE_TAPE`, `NYSE_ARCA_TAPE`), whose TRADE_AGG serves BUY and SELL envelopes; a crypto index
18
23
  * (CRYPTOCAP, not index-mode: it fetches by period like crypto) serves its value candles and no
19
24
  * other lane at all; a quote-priced perpetual market (Variational, also period-fetched) serves its
20
- * quote candles, funding and open interest, and no trade, volume, book, profile or options lane;
25
+ * quote candles, funding and open interest, and no trade, volume, book, profile or options lane; a
26
+ * consolidated tape serves its trades alone (candles, sided volume, the profile, the size flow, the large
27
+ * prints) and no book, open interest, liquidations, funding or options summary;
21
28
  * - the coin table: the option-summary lanes (implied volatility, skew) hold a series for the
22
29
  * coins `WRUN_OPTION_SUMMARY_COINS` lists (BTC and ETH) and no other.
23
30
  * The dispatcher's own admission (`isKScriptTypeServedOnIndexMode`) stays as it is.
@@ -25,7 +32,8 @@
25
32
  import { checkIsCryptoIndex } from './crypto-index.leaf.js';
26
33
  import { checkIsQuotePerp } from './quote-perp.leaf.js';
27
34
  import { checkIsIndexMode } from './index-mode.util.js';
28
- import { checkIsForexOrCommodity } from './marketKind.util.js';
35
+ import { checkIsForexOrCommodity, getMarketKind } from './marketKind.util.js';
36
+ import { isStocksTapeGoverned } from '../v2/stocks-governed.util.js';
29
37
  import { WRUN_OPTION_SUMMARY_COINS, WRUN_OPTION_SUMMARY_LANES } from '../wrun/wrun-option-summary-lane.util.js';
30
38
  /** The kScript source types the dispatcher serves on an index-mode payload exchange. */
31
39
  export function isKScriptTypeServedOnIndexMode(kScriptType) {
@@ -39,6 +47,18 @@ const FOREX_COMMODITY_UNSERVED_TYPES = new Set([
39
47
  WRUN_OPTION_SUMMARY_LANES.implied_volatility.type,
40
48
  WRUN_OPTION_SUMMARY_LANES.skew.type,
41
49
  ]);
50
+ /** The lane fetch types a US equity market never serves (the market-kind table): buy/sell volume. A Polygon or
51
+ * listing-venue print carries no aggressor side, so the lane's BUY/SELL split is empty there; it is the one lane
52
+ * needing a side that the index-mode admission lets through on a stock chart. The tapes are carved out below. */
53
+ const US_EQUITY_UNSERVED_TYPES = new Set(['buy_sell_volume']);
54
+ /** The lane fetch types a US stock tape serves (the stocks gate serves its trades alone): no book, OI or funding. */
55
+ const STOCK_TAPE_SERVED_TYPES = new Set([
56
+ 'ohlcv',
57
+ 'buy_sell_volume',
58
+ 'volume_profile',
59
+ 'trade_volume_by_size',
60
+ 'trades',
61
+ ]);
42
62
  /** The one lane fetch type a crypto index market serves (the market-kind table): its value candles. */
43
63
  const CRYPTO_INDEX_SERVED_TYPES = new Set(['ohlcv']);
44
64
  /** The lane fetch types a quote-priced perpetual market serves (the market-kind table): its quote candles and the
@@ -65,12 +85,19 @@ export function wrunLaneServiceOnMarket({ type, exchange, coin, nativeRows, }) {
65
85
  if (FOREX_COMMODITY_UNSERVED_TYPES.has(type) && checkIsForexOrCommodity(exchange)) {
66
86
  return { served: false, reason: 'market-kind' };
67
87
  }
88
+ // By the kind, not the index-mode set (listing venues outside that set included); a tape's TRADE_AGG is sided.
89
+ if (US_EQUITY_UNSERVED_TYPES.has(type) && getMarketKind(exchange) === 'tradfi' && !isStocksTapeGoverned(exchange)) {
90
+ return { served: false, reason: 'market-kind' };
91
+ }
68
92
  if (!CRYPTO_INDEX_SERVED_TYPES.has(type) && checkIsCryptoIndex(exchange)) {
69
93
  return { served: false, reason: 'market-kind' };
70
94
  }
71
95
  if (!QUOTE_PERP_SERVED_TYPES.has(type) && checkIsQuotePerp(exchange)) {
72
96
  return { served: false, reason: 'market-kind' };
73
97
  }
98
+ if (!STOCK_TAPE_SERVED_TYPES.has(type) && isStocksTapeGoverned(exchange)) {
99
+ return { served: false, reason: 'market-kind' };
100
+ }
74
101
  const coins = COIN_SERVED_TYPES[type];
75
102
  const word = typeof coin === 'string' ? coin.trim().toUpperCase() : '';
76
103
  if (coins !== undefined && word !== '' && !coins.includes(word))
@@ -29,7 +29,7 @@ const TABLES_JSON_CAP = 64;
29
29
  // No class fields: this module rides into the kScript worker's ENTRY chunk, and a
30
30
  // lowered field puts the bundler's defineProperty helper there for the lazy engine
31
31
  // chunk to import back, which WebKit answers by evaluating the entry twice
32
- // (scripts/worker-entry-reimport-guard.ts).
32
+ // (build/vite-plugins/worker-entry-reimport-guard.ts).
33
33
  class Fnv {
34
34
  constructor() {
35
35
  this.h = FNV_OFFSET;