@orangecharts/wrun-chart-host 0.4.0 → 0.6.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.
- package/README.md +17 -5
- package/dist/constants/exchange-names.leaf.d.ts +8 -0
- package/dist/constants/exchange-names.leaf.js +101 -0
- package/dist/constants/feature-flags.constants.js +7 -2
- package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +15 -0
- package/dist/constants/kscript-data-interval-restrictions.constants.js +40 -0
- package/dist/constants/opra-compliance.constants.d.ts +19 -0
- package/dist/constants/opra-compliance.constants.js +19 -0
- package/dist/constants/replay-ladder.leaf.d.ts +30 -0
- package/dist/constants/replay-ladder.leaf.js +99 -0
- package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +168 -0
- package/dist/constants/scriptEditor/cme-official-scripts.constants.js +398 -0
- package/dist/constants/scriptEditor/converted-script-id.leaf.d.ts +8 -0
- package/dist/constants/scriptEditor/converted-script-id.leaf.js +10 -0
- package/dist/constants/scriptEditor/execution.constants.d.ts +4 -0
- package/dist/constants/scriptEditor/execution.constants.js +14 -0
- package/dist/constants/wrun-prefix-safe.constants.d.ts +23 -0
- package/dist/constants/wrun-prefix-safe.constants.js +26 -0
- package/dist/host-env.d.ts +301 -22
- package/dist/host-env.js +15 -0
- package/dist/host-ports.types.d.ts +853 -29
- package/dist/index.d.ts +140 -2
- package/dist/index.js +140 -2
- package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +31 -0
- package/dist/instances/script-engine-worker-ohlcv-transfer.js +164 -0
- package/dist/interfaces/market-event.interface.d.ts +231 -0
- package/dist/interfaces/market-event.interface.js +15 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +70 -134
- package/dist/interfaces/opra-realtime.interface.js +34 -59
- package/dist/interfaces/replay.interface.d.ts +285 -0
- package/dist/interfaces/replay.interface.js +1 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
- package/dist/interfaces/wrun-runtime.interface.js +17 -3
- package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +1 -0
- package/dist/kscript-data/controls/live-ohlcv-merge.util.js +93 -0
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +5 -1
- package/dist/kscript-data/controls/live-trades-merge.util.js +2 -2
- package/dist/market-data/billing.interface.d.ts +219 -0
- package/dist/market-data/billing.interface.js +58 -0
- package/dist/market-data/venue-governed.util.d.ts +2 -0
- package/dist/market-data/venue-governed.util.js +10 -0
- package/dist/market-data/venue.d.ts +122 -0
- package/dist/market-data/venue.js +1 -0
- package/dist/market-data/venues/index.d.ts +97 -0
- package/dist/market-data/venues/index.js +33 -0
- package/dist/market-data/venues/opra.contract.copy.json +35 -0
- package/dist/market-data/venues/opra.d.ts +70 -0
- package/dist/market-data/venues/opra.js +74 -0
- package/dist/replay/replayIndicatorRows.d.ts +31 -0
- package/dist/replay/replayIndicatorRows.js +117 -0
- package/dist/replay/replayLadder.d.ts +85 -0
- package/dist/replay/replayLadder.js +388 -0
- package/dist/utility/auth/server-clock.util.d.ts +81 -0
- package/dist/utility/auth/server-clock.util.js +238 -0
- package/dist/utility/chart/builtin-identity.util.d.ts +18 -0
- package/dist/utility/chart/builtin-identity.util.js +51 -0
- package/dist/utility/chart/cache-alignment.util.d.ts +454 -0
- package/dist/utility/chart/cache-alignment.util.js +926 -0
- package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +15 -0
- package/dist/utility/chart/chart-data-fetch-generation.util.js +22 -0
- package/dist/utility/chart/chart-mount-epoch.util.d.ts +17 -0
- package/dist/utility/chart/chart-mount-epoch.util.js +61 -0
- package/dist/utility/chart/chart-time-domain.util.d.ts +12 -0
- package/dist/utility/chart/chart-time-domain.util.js +23 -0
- package/dist/utility/chart/color-customization.leaf.d.ts +10 -0
- package/dist/utility/chart/color-customization.leaf.js +16 -0
- package/dist/utility/chart/footprint-tick-grid.util.d.ts +106 -0
- package/dist/utility/chart/footprint-tick-grid.util.js +167 -0
- package/dist/utility/chart/gesture-timing.leaf.d.ts +29 -0
- package/dist/utility/chart/gesture-timing.leaf.js +29 -0
- package/dist/utility/chart/governed-contract-coin.util.d.ts +22 -0
- package/dist/utility/chart/governed-contract-coin.util.js +39 -0
- package/dist/utility/chart/host-bar-placement.util.d.ts +107 -0
- package/dist/utility/chart/host-bar-placement.util.js +447 -0
- package/dist/utility/chart/index-host-tier.util.d.ts +31 -0
- package/dist/utility/chart/index-host-tier.util.js +118 -0
- package/dist/utility/chart/index-mode-admission.util.d.ts +34 -0
- package/dist/utility/chart/index-mode-admission.util.js +67 -0
- package/dist/utility/chart/indicator-error-message.util.d.ts +35 -0
- package/dist/utility/chart/indicator-error-message.util.js +44 -0
- package/dist/utility/chart/kscript-apply-fingerprint.util.d.ts +65 -0
- package/dist/utility/chart/kscript-apply-fingerprint.util.js +357 -0
- package/dist/utility/chart/kscript-chart-flush.leaf.d.ts +22 -0
- package/dist/utility/chart/kscript-chart-flush.leaf.js +13 -0
- package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +6 -0
- package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +27 -0
- package/dist/utility/chart/kscript-integration-decision.leaf.d.ts +89 -0
- package/dist/utility/chart/kscript-integration-decision.leaf.js +80 -0
- package/dist/utility/chart/kscript-live-coalesce.util.d.ts +76 -0
- package/dist/utility/chart/kscript-live-coalesce.util.js +156 -0
- package/dist/utility/chart/kscript-live-rest-pace.util.d.ts +34 -0
- package/dist/utility/chart/kscript-live-rest-pace.util.js +134 -0
- package/dist/utility/chart/kscript-live-source-identity.util.d.ts +98 -0
- package/dist/utility/chart/kscript-live-source-identity.util.js +121 -0
- package/dist/utility/chart/kscript-mounted-plot-set.leaf.d.ts +48 -0
- package/dist/utility/chart/kscript-mounted-plot-set.leaf.js +145 -0
- package/dist/utility/chart/kscript-perf-tracker.util.d.ts +243 -0
- package/dist/utility/chart/kscript-perf-tracker.util.js +522 -0
- package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +43 -0
- package/dist/utility/chart/kscript-run-interval-projection.util.js +471 -0
- package/dist/utility/chart/kscript-run-result-equality.util.d.ts +38 -0
- package/dist/utility/chart/kscript-run-result-equality.util.js +89 -0
- package/dist/utility/chart/kscript-settings-revision.leaf.d.ts +2 -0
- package/dist/utility/chart/kscript-settings-revision.leaf.js +12 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +63 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.js +68 -0
- package/dist/utility/chart/kscript-source-retention.util.d.ts +134 -0
- package/dist/utility/chart/kscript-source-retention.util.js +218 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +57 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.js +61 -0
- package/dist/utility/chart/kscript-titancharts-preparation.util.d.ts +15 -0
- package/dist/utility/chart/kscript-titancharts-preparation.util.js +376 -0
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +9 -0
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +130 -0
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +217 -0
- package/dist/utility/chart/kscript-venue-policy.util.js +324 -0
- package/dist/utility/chart/live-cadence.util.d.ts +38 -0
- package/dist/utility/chart/live-cadence.util.js +37 -0
- package/dist/utility/chart/live-feed-series-match.leaf.d.ts +13 -0
- package/dist/utility/chart/live-feed-series-match.leaf.js +21 -0
- package/dist/utility/chart/local-engine-self-heal-backoff.util.d.ts +46 -0
- package/dist/utility/chart/local-engine-self-heal-backoff.util.js +46 -0
- package/dist/utility/chart/local-engine-uninit.leaf.d.ts +21 -0
- package/dist/utility/chart/local-engine-uninit.leaf.js +22 -0
- package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +62 -0
- package/dist/utility/chart/local-kscript-source-revalidation.util.js +123 -0
- package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +214 -0
- package/dist/utility/chart/local-kscript-warmup-depth.util.js +376 -0
- package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.d.ts +85 -0
- package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.js +197 -0
- package/dist/utility/chart/local-technical-script-range.leaf.d.ts +72 -0
- package/dist/utility/chart/local-technical-script-range.leaf.js +126 -0
- package/dist/utility/chart/mixed-mode.util.d.ts +167 -0
- package/dist/utility/chart/mixed-mode.util.js +139 -0
- package/dist/utility/chart/ohlcv-row-readiness.util.d.ts +36 -0
- package/dist/utility/chart/ohlcv-row-readiness.util.js +90 -0
- package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +19 -0
- package/dist/utility/chart/opra-user-scripts-gate.util.js +32 -0
- package/dist/utility/chart/overlay-execution-guard-key.leaf.d.ts +8 -0
- package/dist/utility/chart/overlay-execution-guard-key.leaf.js +10 -0
- package/dist/utility/chart/price-precision.util.d.ts +40 -0
- package/dist/utility/chart/price-precision.util.js +70 -0
- package/dist/utility/chart/profile-block-size.util.d.ts +64 -0
- package/dist/utility/chart/profile-block-size.util.js +141 -0
- package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.d.ts +11 -0
- package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.js +29 -0
- package/dist/utility/chart/protected-kscript-empty-output.util.d.ts +28 -0
- package/dist/utility/chart/protected-kscript-empty-output.util.js +84 -0
- package/dist/utility/chart/run-interval-unservable.leaf.d.ts +9 -0
- package/dist/utility/chart/run-interval-unservable.leaf.js +20 -0
- package/dist/utility/chart/run-interval-warmup.leaf.d.ts +19 -0
- package/dist/utility/chart/run-interval-warmup.leaf.js +35 -0
- package/dist/utility/chart/titan-constants.pin.d.ts +9 -5
- package/dist/utility/chart/titan-constants.pin.js +18 -5
- package/dist/utility/chart/warmup-backfill-retry.leaf.d.ts +9 -0
- package/dist/utility/chart/warmup-backfill-retry.leaf.js +9 -0
- package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +11 -2
- package/dist/utility/chart/wrun-bar-session-facts.util.js +10 -3
- package/dist/utility/chart/wrun-run-result.util.d.ts +5 -1
- package/dist/utility/chart/wrun-run-result.util.js +20 -14
- package/dist/utility/common/data-processing.util.d.ts +138 -0
- package/dist/utility/common/data-processing.util.js +346 -0
- package/dist/utility/common/visible-timeout.util.d.ts +13 -4
- package/dist/utility/common/visible-timeout.util.js +23 -8
- package/dist/utility/exchange-format.leaf.d.ts +1 -0
- package/dist/utility/exchange-format.leaf.js +47 -0
- package/dist/utility/market-events/earnings-scope.util.d.ts +60 -0
- package/dist/utility/market-events/earnings-scope.util.js +92 -0
- package/dist/utility/market-events/market-events.util.d.ts +147 -0
- package/dist/utility/market-events/market-events.util.js +392 -0
- package/dist/utility/market-events/zoned-clock.util.d.ts +1 -0
- package/dist/utility/market-events/zoned-clock.util.js +11 -0
- package/dist/utility/options/option-venue-disclosure.util.d.ts +43 -0
- package/dist/utility/options/option-venue-disclosure.util.js +56 -0
- package/dist/utility/scriptEditor/package-semver.util.d.ts +51 -0
- package/dist/utility/scriptEditor/package-semver.util.js +120 -0
- package/dist/utility/scriptEditor/temp-script-id.util.d.ts +18 -0
- package/dist/utility/scriptEditor/temp-script-id.util.js +25 -0
- package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.d.ts +20 -0
- package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.js +81 -0
- package/dist/utility/v2/governed-tier.leaf.d.ts +103 -0
- package/dist/utility/v2/governed-tier.leaf.js +113 -0
- package/dist/utility/watchlist/import/import-request.leaf.d.ts +10 -0
- package/dist/utility/watchlist/import/import-request.leaf.js +10 -0
- package/dist/utility/wrun/sources/lanes/series.js +2 -2
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +4 -4
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +5 -6
- package/dist/utility/wrun/wrun-alert-outputs.registry.d.ts +166 -0
- package/dist/utility/wrun/wrun-alert-outputs.registry.js +219 -0
- package/dist/utility/wrun/wrun-bar-count.util.d.ts +94 -0
- package/dist/utility/wrun/wrun-bar-count.util.js +274 -0
- package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +84 -0
- package/dist/utility/wrun/wrun-chart-context-names.util.js +186 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +253 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +731 -0
- package/dist/utility/wrun/wrun-cloud-opra-stamp.util.d.ts +28 -0
- package/dist/utility/wrun/wrun-cloud-opra-stamp.util.js +45 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.js +47 -0
- package/dist/utility/wrun/wrun-deadline.util.js +2 -1
- package/dist/utility/wrun/wrun-debug-output.util.d.ts +39 -0
- package/dist/utility/wrun/wrun-debug-output.util.js +63 -0
- package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +113 -0
- package/dist/utility/wrun/wrun-declared-warmup.util.js +181 -0
- package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +43 -0
- package/dist/utility/wrun/wrun-draft-legend-note.util.js +158 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +181 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.js +357 -0
- package/dist/utility/wrun/wrun-draw-skipped.leaf.d.ts +16 -0
- package/dist/utility/wrun/wrun-draw-skipped.leaf.js +16 -0
- package/dist/utility/wrun/wrun-earnings-facts.util.d.ts +42 -0
- package/dist/utility/wrun/wrun-earnings-facts.util.js +131 -0
- package/dist/utility/wrun/wrun-first-run-depth.util.d.ts +32 -0
- package/dist/utility/wrun/wrun-first-run-depth.util.js +118 -0
- package/dist/utility/wrun/wrun-gate-plane-readers.util.d.ts +24 -0
- package/dist/utility/wrun/wrun-gate-plane-readers.util.js +31 -0
- package/dist/utility/wrun/wrun-held-lanes.util.d.ts +32 -0
- package/dist/utility/wrun/wrun-held-lanes.util.js +94 -0
- package/dist/utility/wrun/wrun-host-visible-clock.util.d.ts +2 -0
- package/dist/utility/wrun/wrun-host-visible-clock.util.js +17 -0
- package/dist/utility/wrun/wrun-host.service.d.ts +330 -0
- package/dist/utility/wrun/wrun-host.service.js +855 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-hover.util.js +25 -4
- package/dist/utility/wrun/wrun-inert-legend.util.d.ts +33 -0
- package/dist/utility/wrun/wrun-inert-legend.util.js +125 -0
- package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +155 -0
- package/dist/utility/wrun/wrun-input-requirements.leaf.js +450 -0
- package/dist/utility/wrun/wrun-integration-route.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-integration-route.util.js +59 -0
- package/dist/utility/wrun/wrun-latest-history.leaf.d.ts +8 -0
- package/dist/utility/wrun/wrun-latest-history.leaf.js +8 -0
- package/dist/utility/wrun/wrun-legend-hover.lazy.d.ts +12 -0
- package/dist/utility/wrun/wrun-legend-hover.lazy.js +96 -0
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +21 -0
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +21 -0
- package/dist/utility/wrun/wrun-live-hidden-hold.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-live-hidden-hold.util.js +13 -0
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +374 -0
- package/dist/utility/wrun/wrun-live-intake.util.js +2027 -0
- package/dist/utility/wrun/wrun-live-patch.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-live-patch.util.js +523 -0
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +619 -0
- package/dist/utility/wrun/wrun-live-tick.util.js +4974 -0
- package/dist/utility/wrun/wrun-loading-owner.util.d.ts +58 -0
- package/dist/utility/wrun/wrun-loading-owner.util.js +89 -0
- package/dist/utility/wrun/wrun-official-scope.leaf.d.ts +29 -0
- package/dist/utility/wrun/wrun-official-scope.leaf.js +36 -0
- package/dist/utility/wrun/wrun-oi-lane.util.d.ts +27 -0
- package/dist/utility/wrun/wrun-oi-lane.util.js +42 -0
- package/dist/utility/wrun/wrun-options-stop.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-options-stop.util.js +123 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +719 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +1180 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +50 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +131 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +118 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +466 -0
- package/dist/utility/wrun/wrun-overlay-metadata.util.d.ts +45 -0
- package/dist/utility/wrun/wrun-overlay-metadata.util.js +112 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +114 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +971 -0
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +858 -0
- package/dist/utility/wrun/wrun-overlay-run.util.js +11013 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +24 -9
- package/dist/utility/wrun/wrun-panel-mount.util.js +138 -43
- package/dist/utility/wrun/wrun-param-map.util.d.ts +19 -4
- package/dist/utility/wrun/wrun-param-map.util.js +40 -47
- package/dist/utility/wrun/wrun-param-values.util.d.ts +9 -3
- package/dist/utility/wrun/wrun-param-values.util.js +5 -5
- package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +93 -0
- package/dist/utility/wrun/wrun-prefix-cohort.util.js +484 -0
- package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +114 -0
- package/dist/utility/wrun/wrun-prefix-lanes.util.js +486 -0
- package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +317 -0
- package/dist/utility/wrun/wrun-prefix-proof.util.js +630 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +73 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.js +380 -0
- package/dist/utility/wrun/wrun-refusal-text.util.d.ts +15 -0
- package/dist/utility/wrun/wrun-refusal-text.util.js +40 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-replay-lane.util.d.ts +139 -0
- package/dist/utility/wrun/wrun-replay-lane.util.js +520 -0
- package/dist/utility/wrun/wrun-replay-rows.util.d.ts +21 -0
- package/dist/utility/wrun/wrun-replay-rows.util.js +172 -0
- package/dist/utility/wrun/wrun-row-source-factory.d.ts +53 -0
- package/dist/utility/wrun/wrun-row-source-factory.js +435 -0
- package/dist/utility/wrun/wrun-run-cells.util.d.ts +36 -0
- package/dist/utility/wrun/wrun-run-cells.util.js +46 -0
- package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +133 -0
- package/dist/utility/wrun/wrun-run-interval-session.util.js +121 -0
- package/dist/utility/wrun/wrun-run-interval.util.d.ts +98 -0
- package/dist/utility/wrun/wrun-run-interval.util.js +207 -0
- package/dist/utility/wrun/wrun-run-retained.util.d.ts +122 -0
- package/dist/utility/wrun/wrun-run-retained.util.js +255 -0
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +184 -0
- package/dist/utility/wrun/wrun-sandbox-row-source.js +444 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +4 -4
- package/dist/utility/wrun/wrun-series-stream.util.d.ts +86 -0
- package/dist/utility/wrun/wrun-series-stream.util.js +537 -0
- package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
- package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
- package/dist/utility/wrun/wrun-sheet-remembered.util.d.ts +21 -0
- package/dist/utility/wrun/wrun-sheet-remembered.util.js +36 -0
- package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.d.ts +7 -0
- package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.js +12 -0
- package/dist/utility/wrun/wrun-socket-row-source.js +4 -2
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +175 -3
- package/dist/utility/wrun/wrun-source-rows.util.js +294 -8
- package/dist/utility/wrun/wrun-stats-strip.util.d.ts +46 -0
- package/dist/utility/wrun/wrun-stats-strip.util.js +87 -0
- package/dist/utility/wrun/wrun-table-chrome.util.d.ts +163 -0
- package/dist/utility/wrun/wrun-table-chrome.util.js +557 -0
- package/dist/utility/wrun/wrun-text-params.util.d.ts +11 -6
- package/dist/utility/wrun/wrun-text-params.util.js +19 -30
- package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +64 -0
- package/dist/utility/wrun/wrun-transient-rerun.util.js +317 -0
- package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +10 -0
- package/dist/utility/wrun/wrun-twin-lookback.util.js +43 -0
- package/dist/utility/wrun/wrun-warmup-head-store.util.d.ts +41 -0
- package/dist/utility/wrun/wrun-warmup-head-store.util.js +120 -0
- package/dist/utility/wrun-alert-params.leaf.d.ts +24 -0
- package/dist/utility/wrun-alert-params.leaf.js +24 -0
- package/dist/utils/replay/replay-buffer-math.d.ts +148 -0
- package/dist/utils/replay/replay-buffer-math.js +684 -0
- package/dist/workers/wrun/wrun-abi-host.d.ts +203 -0
- package/dist/workers/wrun/wrun-abi-host.js +1220 -0
- package/dist/workers/wrun/wrun-engine-handler.d.ts +20 -0
- package/dist/workers/wrun/wrun-engine-handler.js +380 -0
- package/package.json +3 -3
|
@@ -0,0 +1,1180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mounted browser-WRUN overlay registry: the chart-lifecycle seam between the
|
|
3
|
+
* wrun loaders (services/wrun-dev-loader.service.ts,
|
|
4
|
+
* services/wrun-registry-loader.service.ts) and the chart's shared triggers
|
|
5
|
+
* (the lazy-load indicator wave in instances/titan-charts.ts and the live
|
|
6
|
+
* fan-out in services/live-feed.service.ts).
|
|
7
|
+
*
|
|
8
|
+
* Each loader registers a DRIVER when it mounts an overlay: chart placement,
|
|
9
|
+
* an isMounted probe, and the loader's own full-recompute entry point. The
|
|
10
|
+
* chart triggers only consult this registry; they never import a loader, so
|
|
11
|
+
* the dependency arrow stays instances -> utility.
|
|
12
|
+
*
|
|
13
|
+
* Failure policy: a failed recompute NEVER breaks the rendered overlay. The
|
|
14
|
+
* run only integrates on success, so the last good result stays mounted and
|
|
15
|
+
* the failure logs. The executor never words a failure itself: the run pass
|
|
16
|
+
* (and the loader, for its own phases) project each one as a refusal record
|
|
17
|
+
* through the common surface (wrun-refusal-surface.util), which toasts at
|
|
18
|
+
* most once per failed attempt a person made.
|
|
19
|
+
*
|
|
20
|
+
* Refusal attempts (WRUN-REFUSALS amendment 9): every run answers one attempt
|
|
21
|
+
* token, resolved before the run starts so the run pass reads it before its
|
|
22
|
+
* first await. A request a person made (a Retry, a settings save, a switch)
|
|
23
|
+
* opens a user attempt; 'initial' keeps the token the loader opened at mount
|
|
24
|
+
* (a user add, or a restore that is system); every other request is the
|
|
25
|
+
* chart's own and opens a system attempt, unless a user attempt is still
|
|
26
|
+
* waiting on its first answer (it keeps that one, so an automatic run in
|
|
27
|
+
* between never takes its notice away). A teardown closes the overlay's
|
|
28
|
+
* attempts, so a late settlement claims nothing.
|
|
29
|
+
*
|
|
30
|
+
* Every run carries a reason and, optionally, a clamped window (the shared
|
|
31
|
+
* vocabulary of wrun-lifecycle.contract.ts). Requests queued behind a run
|
|
32
|
+
* merge into its one follow-up by rank, and each one's caller waits for that
|
|
33
|
+
* follow-up (a settings save's tail settles after the run that computes its
|
|
34
|
+
* settings, never after the run that was already in flight); a pan wave
|
|
35
|
+
* asking for rows the last good run already computed over the same main rows
|
|
36
|
+
* is skipped (the kScript wave's duplicate-range rule, widened to coverage: a
|
|
37
|
+
* pan-back page's live rebuild already computed the rows its wave then asks
|
|
38
|
+
* for). Settled runs and successful computes are announced through hooks, so
|
|
39
|
+
* the lifecycle door and the recovery ladders follow the executor without
|
|
40
|
+
* this module importing them.
|
|
41
|
+
*
|
|
42
|
+
* Settings sync (SETTINGS-RAPID-TOGGLE C1, C4): every settled run reports the
|
|
43
|
+
* settings generation it computed with and its outcome (applied, dropped,
|
|
44
|
+
* held, failed) to the chart store's `noteIndicatorSettingsSettled`, with a
|
|
45
|
+
* `settings-run-settled` ring event, so a failed or held trailing run reaches
|
|
46
|
+
* the store's reconcile instead of keeping the last good picture silently.
|
|
47
|
+
* The run pass notes the generation and the outcome
|
|
48
|
+
* (`noteWrunOverlayRunSettle`); the report goes out after the follow-up
|
|
49
|
+
* decision, so `isWrunOverlayFullRerunInFlight` answers whether a run computing
|
|
50
|
+
* newer settings over the whole loaded window is already on its way. A run
|
|
51
|
+
* over a partial window (a pan page) computes its rows only and keeps the
|
|
52
|
+
* mounted rows and the live session outside it: it reports nothing.
|
|
53
|
+
*
|
|
54
|
+
* Prefix runs (C1 v3): a pan wave the door planned as a prefix run rides
|
|
55
|
+
* the executor tagged; it is replanned when it starts (its prefix window,
|
|
56
|
+
* the wave whole, or no run when nothing is left), any full request merged
|
|
57
|
+
* with it wins, and its coverage counts only once its commit landed. The
|
|
58
|
+
* plan itself lives with the run pass (`setWrunPrefixRuntime`).
|
|
59
|
+
*
|
|
60
|
+
* Unanswered drops (C4's backstop): a dropped run settles quietly on the
|
|
61
|
+
* promise that a newer run reports for the overlay. When the follow-up
|
|
62
|
+
* decision finds none (nothing queued, and no first-compute waiter, whose
|
|
63
|
+
* loader keeps its own deadline), the executor arms ONE visible-time run
|
|
64
|
+
* deadline (`WRUN_RUN_DEADLINE_MS`) for the overlay, first run or rerun. A
|
|
65
|
+
* full run that starts clears it (a run in flight is the answer until it
|
|
66
|
+
* settles; dropped again with nothing after it, it arms a fresh one), and so
|
|
67
|
+
* do any run that fails or is held (each says what the overlay shows), a
|
|
68
|
+
* buffer reseed that draws (`noteWrunOverlayWholeWindowDrawn`), a waiter
|
|
69
|
+
* latching, a re-register, a pause and a teardown. If it fires, the run pass
|
|
70
|
+
* (`setWrunUnansweredDropSurface`) shows the run deadline's retryable
|
|
71
|
+
* not-reached record with the cause `superseded` and settles the mount's
|
|
72
|
+
* attempt with it: a quiet settle that nothing answered ends in a chip and a
|
|
73
|
+
* counted failure, never a blank row. The surface works across awaits, so it
|
|
74
|
+
* re-checks `isCurrent()`: anything that would have cleared the deadline also
|
|
75
|
+
* retires a surface already on its way.
|
|
76
|
+
*/
|
|
77
|
+
import { startVisibleTimeout } from '../common/visible-timeout.util.js';
|
|
78
|
+
import { wrunHostVisibleClock } from './wrun-host-visible-clock.util.js';
|
|
79
|
+
import { WRUN_RUN_DEADLINE_MS } from './wrun-deadline.util.js';
|
|
80
|
+
import { WrunChartGoneError, WrunDeadlineError } from './wrun-registry-errors.util.js';
|
|
81
|
+
import { closeWrunRefusalAttempts, liveWrunRefusalAttempt, openWrunRefusalAttempt, wrunRefusalAttemptOrigin, } from './wrun-refusal-surface.util.js';
|
|
82
|
+
import { attachWrunRefusal, stampWrunRefusalTelemetry } from './wrun-refusal.util.js';
|
|
83
|
+
import { wrunRunFailedIdentityOf } from './wrun-cap-notice.util.js';
|
|
84
|
+
import { wrunChartHostEnv } from '../../host-env.js';
|
|
85
|
+
const drivers = new Map();
|
|
86
|
+
/** The executor's merge rank (wrun-lifecycle.contract.ts): settings > switch
|
|
87
|
+
* > theme > resume = retry > heal > live-rebuild > the range reasons.
|
|
88
|
+
* 'initial', the loader's first run of a mount, outranks them all: it owes
|
|
89
|
+
* everything a settings run does, and an initial compute's outcome tap
|
|
90
|
+
* rides the follow-up it latches. 'replay' outranks 'initial': while the
|
|
91
|
+
* chart replays only the replay lane's run may paint (any other run ends
|
|
92
|
+
* superseded), and outside replay a replay run ends superseded itself. */
|
|
93
|
+
const WRUN_RUN_REASON_RANK = {
|
|
94
|
+
replay: 8,
|
|
95
|
+
initial: 7,
|
|
96
|
+
settings: 6,
|
|
97
|
+
switch: 5,
|
|
98
|
+
theme: 4,
|
|
99
|
+
resume: 3,
|
|
100
|
+
retry: 3,
|
|
101
|
+
heal: 2,
|
|
102
|
+
'live-rebuild': 1,
|
|
103
|
+
'history-range': 0,
|
|
104
|
+
'budget-lift': 0,
|
|
105
|
+
'lazy-range-refresh': 0,
|
|
106
|
+
'loaded-range-refresh': 0,
|
|
107
|
+
'source-recovery': 0,
|
|
108
|
+
};
|
|
109
|
+
function wrunRunRequestOf(options) {
|
|
110
|
+
const reason = options?.reason ?? 'loaded-range-refresh';
|
|
111
|
+
// 'initial' inherits the loader's attempt; an explicit origin (a settings save carrying its
|
|
112
|
+
// sync origin) wins; every other reason is a person's or the chart's by U1's rule.
|
|
113
|
+
const userOrigin = reason !== 'initial' &&
|
|
114
|
+
(options?.origin !== undefined ? options.origin === 'user' : wrunRefusalAttemptOrigin(reason, null) === 'user');
|
|
115
|
+
return {
|
|
116
|
+
reason,
|
|
117
|
+
...(options?.window ? { window: options.window } : {}),
|
|
118
|
+
...(userOrigin ? { userOrigin } : {}),
|
|
119
|
+
// Only a pan wave is ever planned as a prefix run.
|
|
120
|
+
...(options?.prefix && reason === 'lazy-range-refresh' ? { prefix: options.prefix } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** The options a driver's rerun receives: the reason and the window only. */
|
|
124
|
+
function wrunRerunOptionsOf(request) {
|
|
125
|
+
return request.window ? { reason: request.reason, window: request.window } : { reason: request.reason };
|
|
126
|
+
}
|
|
127
|
+
/** Latest-wins by rank: the higher-ranked reason wins and a tie goes to the
|
|
128
|
+
* newer request; the wider window wins (a tie to the newer), and an absent
|
|
129
|
+
* window is the whole loaded window, the widest of all. A merged request a
|
|
130
|
+
* person made stays theirs (its follow-up answers that Retry, save or
|
|
131
|
+
* switch, whichever reason outranked it). */
|
|
132
|
+
function mergeWrunRunRequests(pending, incoming) {
|
|
133
|
+
if (!pending)
|
|
134
|
+
return incoming;
|
|
135
|
+
const reason = WRUN_RUN_REASON_RANK[incoming.reason] >= WRUN_RUN_REASON_RANK[pending.reason] ? incoming.reason : pending.reason;
|
|
136
|
+
const origin = pending.userOrigin === true || incoming.userOrigin === true ? { userOrigin: true } : {};
|
|
137
|
+
// A prefix tag survives only a merge of two planned pan waves (the newer tag: it is replanned
|
|
138
|
+
// when the run starts anyway); any full request merged with one wins (C1 v3).
|
|
139
|
+
const prefix = pending.prefix !== undefined && incoming.prefix !== undefined ? { prefix: incoming.prefix } : {};
|
|
140
|
+
if (!pending.window || !incoming.window)
|
|
141
|
+
return { reason, ...origin, ...prefix };
|
|
142
|
+
const window = incoming.window.toMs - incoming.window.fromMs >= pending.window.toMs - pending.window.fromMs
|
|
143
|
+
? incoming.window
|
|
144
|
+
: pending.window;
|
|
145
|
+
return { reason, window, ...origin, ...prefix };
|
|
146
|
+
}
|
|
147
|
+
/** Merge a request into the queued follow-up; a prefix tag the merge dropped will never run. */
|
|
148
|
+
function queueWrunRunRequest(indicatorId, state, incoming) {
|
|
149
|
+
const pending = state.pendingOptions;
|
|
150
|
+
const merged = mergeWrunRunRequests(pending, incoming);
|
|
151
|
+
for (const tag of [pending?.prefix, incoming.prefix]) {
|
|
152
|
+
if (tag !== undefined && tag.requestId !== merged.prefix?.requestId) {
|
|
153
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, tag, 'superseded');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
state.pendingAgain = true;
|
|
157
|
+
state.pendingOptions = merged;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The refusal attempt a run answers (amendment 9), resolved when the run
|
|
161
|
+
* starts, before the run pass's first await:
|
|
162
|
+
* - a request a person made opens a user attempt (each Retry its own, so a
|
|
163
|
+
* failing second Retry is noticed again);
|
|
164
|
+
* - 'initial' keeps the live token the loader opened at mount (a user add, or
|
|
165
|
+
* a restore, which is system and never noticed);
|
|
166
|
+
* - every other request is the chart's own: it keeps a user attempt still
|
|
167
|
+
* waiting on its first answer (the loader's add while a pan wave computes
|
|
168
|
+
* first), else it opens a system attempt.
|
|
169
|
+
* `owned`: the attempt is this run's to answer, so its settlement concludes it.
|
|
170
|
+
*/
|
|
171
|
+
function beginWrunRunAttempt(indicatorId, state, request) {
|
|
172
|
+
const chartIndex = state.driver.chartIndex;
|
|
173
|
+
if (request.userOrigin) {
|
|
174
|
+
return {
|
|
175
|
+
token: openWrunRefusalAttempt(chartIndex, indicatorId, { origin: 'user', reason: request.reason }),
|
|
176
|
+
owned: true,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const live = liveWrunRefusalAttempt(chartIndex, indicatorId);
|
|
180
|
+
if (request.reason === 'initial')
|
|
181
|
+
return { token: live, owned: true };
|
|
182
|
+
if (live && live.origin === 'user' && live.generation !== state.answeredUserAttempt) {
|
|
183
|
+
return { token: live, owned: false };
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
token: openWrunRefusalAttempt(chartIndex, indicatorId, { origin: 'system', reason: request.reason }),
|
|
187
|
+
owned: true,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** A settled run concludes the user attempt it owned, and a pending one it
|
|
191
|
+
* borrowed once it computed a good result for it (a failure there already
|
|
192
|
+
* spent that attempt's one notice). */
|
|
193
|
+
function concludeWrunRunAttempt(state, attempt, ok) {
|
|
194
|
+
const token = attempt.token;
|
|
195
|
+
if (token?.origin === 'user' && (attempt.owned || ok))
|
|
196
|
+
state.answeredUserAttempt = token.generation;
|
|
197
|
+
}
|
|
198
|
+
// The reader of a chart's main-rows identity (the market, the first row, the
|
|
199
|
+
// newest closed row and the row count), registered by the live tick lane at
|
|
200
|
+
// import: it owns the chart imports this module stays off. Without one,
|
|
201
|
+
// nothing is skipped as covered.
|
|
202
|
+
let chartRowsIdentityReader = null;
|
|
203
|
+
/** Register (or clear, with null) the chart main-rows identity reader the
|
|
204
|
+
* pan wave's coverage skip compares runs by. */
|
|
205
|
+
export function setWrunChartRowsIdentityReader(reader) {
|
|
206
|
+
chartRowsIdentityReader = reader;
|
|
207
|
+
}
|
|
208
|
+
/** The chart's main-rows identity now, as the overlay's coverage reads it (the
|
|
209
|
+
* reader names none while a page in front of the overlay's session waits for
|
|
210
|
+
* its prefix run); undefined without a reader, rows, or when the reader
|
|
211
|
+
* throws (the executor never breaks on it). */
|
|
212
|
+
function readWrunChartRowsIdentity(chartIndex, indicatorId) {
|
|
213
|
+
try {
|
|
214
|
+
return chartRowsIdentityReader?.(chartIndex, indicatorId) ?? undefined;
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/** Whether a run over `computed` (absent: the whole loaded window) covers a
|
|
221
|
+
* request for `asked` over the same rows: the whole window covers any
|
|
222
|
+
* window; a window covers the windows inside it, and covers the whole
|
|
223
|
+
* window only when it was not partial (it spanned the loaded range). */
|
|
224
|
+
function wrunRunWindowCovers(computed, asked) {
|
|
225
|
+
if (computed === undefined)
|
|
226
|
+
return true;
|
|
227
|
+
if (asked === undefined)
|
|
228
|
+
return !computed.partial;
|
|
229
|
+
return computed.fromMs <= asked.fromMs && asked.toMs <= computed.toMs;
|
|
230
|
+
}
|
|
231
|
+
/** The pan wave's coverage skip (the kScript wave's duplicate-range rule,
|
|
232
|
+
* widened): a 'lazy-range-refresh' whose window the last good run already
|
|
233
|
+
* computed, over main rows that have not changed since it started, has
|
|
234
|
+
* nothing new to compute. Every other reason asks for a run the rows alone
|
|
235
|
+
* do not decide (a rebuild, a settings, theme or venue change, a lane retry
|
|
236
|
+
* or a revalidation re-fetching the lanes over the same rows) and never
|
|
237
|
+
* skips. Callers check it only with nothing in flight. */
|
|
238
|
+
function isWrunCoveredWaveRequest(indicatorId, state, request) {
|
|
239
|
+
if (request.reason !== 'lazy-range-refresh' || !state.hasGoodResult)
|
|
240
|
+
return false;
|
|
241
|
+
const coverage = state.lastCoverage;
|
|
242
|
+
if (coverage === undefined || !wrunRunWindowCovers(coverage.window, request.window))
|
|
243
|
+
return false;
|
|
244
|
+
return readWrunChartRowsIdentity(state.driver.chartIndex, indicatorId) === coverage.rowsIdentity;
|
|
245
|
+
}
|
|
246
|
+
const runSettledHooks = new Set();
|
|
247
|
+
const computeSucceededHooks = new Set();
|
|
248
|
+
/** Run every subscriber; a throwing one is logged and never breaks the
|
|
249
|
+
* caller or the subscribers after it. */
|
|
250
|
+
function notifyWrunOverlayHooks(hooks, label, indicatorId, ...args) {
|
|
251
|
+
for (const hook of hooks) {
|
|
252
|
+
try {
|
|
253
|
+
hook(...args);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
console.warn(`[wrun] ${label} hook failed for '${indicatorId}':`, error);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/** Subscribe to every settled executor run (wave, initial compute, follow-up):
|
|
261
|
+
* once per run, with the run's reason and outcome. Returns the unsubscribe. */
|
|
262
|
+
export function onWrunOverlayRunSettled(fn) {
|
|
263
|
+
runSettledHooks.add(fn);
|
|
264
|
+
return () => {
|
|
265
|
+
runSettledHooks.delete(fn);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** Subscribe to the run pass's success marker (`markWrunOverlayComputeSucceeded`),
|
|
269
|
+
* with the driver's chart index. Returns the unsubscribe. */
|
|
270
|
+
export function onWrunOverlayComputeSucceeded(fn) {
|
|
271
|
+
computeSucceededHooks.add(fn);
|
|
272
|
+
return () => {
|
|
273
|
+
computeSucceededHooks.delete(fn);
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const liveContexts = new Map();
|
|
277
|
+
// Per overlay id: the live generation counter (bumped by every install and
|
|
278
|
+
// teardown), the hooks that run on teardown, and the session lock.
|
|
279
|
+
const liveGenerations = new Map();
|
|
280
|
+
const liveTeardownHooks = new Set();
|
|
281
|
+
const sessionLocks = new Map();
|
|
282
|
+
// The hooks chart teardown runs with the chart index (onWrunChartTeardown).
|
|
283
|
+
const chartTeardownHooks = new Set();
|
|
284
|
+
/** The sandbox worker's live-series end, handed over by the browser host as it evaluates
|
|
285
|
+
* (`wrun-host.service.ts`, `bindWrunHostLiveSeriesEnd`): the host spawns the only worker that
|
|
286
|
+
* can hold a live series, so before it evaluates there is nothing to end and the teardown's last
|
|
287
|
+
* step is a no-op. This module never imports the host (its worker, packer and kit stay off the
|
|
288
|
+
* boot graph, docs/features/kscript/wrun/wrun-browser-runtime.md "Boot doors"). */
|
|
289
|
+
let endHostLiveSeries;
|
|
290
|
+
/** The host's side of the teardown door: bound once, when the host service evaluates. */
|
|
291
|
+
export function bindWrunHostLiveSeriesEnd(end) {
|
|
292
|
+
endHostLiveSeries = end;
|
|
293
|
+
}
|
|
294
|
+
/** Bump and return the overlay's live generation. Every install (the full
|
|
295
|
+
* run opening a session) and every teardown moves it; the run passes the
|
|
296
|
+
* new value to the worker as the session epoch and stores it on the
|
|
297
|
+
* context, so frames and drains carrying an older value are discarded. */
|
|
298
|
+
export function nextWrunOverlayLiveGeneration(indicatorId) {
|
|
299
|
+
const next = (liveGenerations.get(indicatorId) ?? 0) + 1;
|
|
300
|
+
liveGenerations.set(indicatorId, next);
|
|
301
|
+
return next;
|
|
302
|
+
}
|
|
303
|
+
/** The overlay's current live generation (0 before the first install). */
|
|
304
|
+
export function currentWrunOverlayLiveGeneration(indicatorId) {
|
|
305
|
+
return liveGenerations.get(indicatorId) ?? 0;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Register a synchronous teardown hook: called with the overlay id by
|
|
309
|
+
* `teardownWrunOverlay` (and so by the chart teardown) and by
|
|
310
|
+
* `suspendWrunOverlayLiveSession` AFTER the generation bump and BEFORE the
|
|
311
|
+
* registries are deleted and the worker session ended, so a hook can still
|
|
312
|
+
* read the context it is disposing state for. The cause tells a hook that
|
|
313
|
+
* holds overlay state (not session state) to keep it on 'suspend'. The
|
|
314
|
+
* push intake and the tick lane register at import time. Returns the
|
|
315
|
+
* unregister function.
|
|
316
|
+
*/
|
|
317
|
+
export function onWrunOverlayLiveTeardown(fn) {
|
|
318
|
+
liveTeardownHooks.add(fn);
|
|
319
|
+
return () => {
|
|
320
|
+
liveTeardownHooks.delete(fn);
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Per-overlay async mutex for SESSION operations (a tick's worker call plus
|
|
325
|
+
* its apply, a reseed, the full run's live-start plus its context install):
|
|
326
|
+
* `fn` runs after every earlier holder settled, and the lock is released
|
|
327
|
+
* whether it resolves or rejects (the caller gets `fn`'s own outcome).
|
|
328
|
+
* Non-reentrant: a holder must never call it again for the same id (the
|
|
329
|
+
* reseed takes the lock itself, so it is called from OUTSIDE a held lock).
|
|
330
|
+
*/
|
|
331
|
+
export function withWrunOverlaySessionLock(indicatorId, fn) {
|
|
332
|
+
const previous = sessionLocks.get(indicatorId) ?? Promise.resolve();
|
|
333
|
+
const run = previous.then(() => fn());
|
|
334
|
+
const settled = run.then(() => undefined, () => undefined);
|
|
335
|
+
sessionLocks.set(indicatorId, settled);
|
|
336
|
+
void settled.then(() => {
|
|
337
|
+
if (sessionLocks.get(indicatorId) === settled)
|
|
338
|
+
sessionLocks.delete(indicatorId);
|
|
339
|
+
});
|
|
340
|
+
return run;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The market identity a wrun run is bound to: exchange, symbol, interval and
|
|
344
|
+
* transformations of the chart's main series. Read from the chart metadata
|
|
345
|
+
* the caller hands in (the store stays out of this registry's eager graph).
|
|
346
|
+
*/
|
|
347
|
+
export function wrunChartMarketIdentity(metadata) {
|
|
348
|
+
if (!metadata)
|
|
349
|
+
return '';
|
|
350
|
+
return [metadata.exchange, metadata.symbol, metadata.interval, metadata.transformations]
|
|
351
|
+
.map((part) => (part === undefined || part === null ? '' : String(part)))
|
|
352
|
+
.join('|');
|
|
353
|
+
}
|
|
354
|
+
export function registerWrunOverlayDriver(indicatorId, driver) {
|
|
355
|
+
const existing = drivers.get(indicatorId);
|
|
356
|
+
if (existing) {
|
|
357
|
+
// A re-register under the same id (a rehydrate, a remount, a revival in
|
|
358
|
+
// the add path) swaps the driver on the SAME executor state: a run in
|
|
359
|
+
// flight settles into it and its follow-up runs on the new driver (a
|
|
360
|
+
// fresh state would inherit the in-flight mark with nothing left to clear
|
|
361
|
+
// it). The good marker stays (the overlay on screen still shows the
|
|
362
|
+
// earlier good result); the last good coverage goes, since the new
|
|
363
|
+
// driver has computed nothing yet.
|
|
364
|
+
existing.driver = driver;
|
|
365
|
+
existing.lastCoverage = undefined;
|
|
366
|
+
// The new driver's loader runs its first compute under its own deadline.
|
|
367
|
+
clearWrunUnansweredDrop(existing);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
drivers.set(indicatorId, {
|
|
371
|
+
driver,
|
|
372
|
+
inFlight: null,
|
|
373
|
+
inFlightRequest: undefined,
|
|
374
|
+
pendingAgain: false,
|
|
375
|
+
pendingOptions: undefined,
|
|
376
|
+
followUp: undefined,
|
|
377
|
+
runNote: undefined,
|
|
378
|
+
lastGeneration: 0,
|
|
379
|
+
hasGoodResult: false,
|
|
380
|
+
answeredUserAttempt: undefined,
|
|
381
|
+
outcomeTaps: [],
|
|
382
|
+
lastFailure: undefined,
|
|
383
|
+
lastCoverage: undefined,
|
|
384
|
+
unansweredDrop: undefined,
|
|
385
|
+
unansweredDropEpoch: 0,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
export function hasWrunOverlayDriver(indicatorId) {
|
|
389
|
+
return drivers.has(indicatorId);
|
|
390
|
+
}
|
|
391
|
+
/** Marked by the shared run pass after a successful integrate, whatever
|
|
392
|
+
* triggered it (add, rehydrate, wave, tick rebuild); announced to the
|
|
393
|
+
* compute-succeeded subscribers with the driver's chart. */
|
|
394
|
+
export function markWrunOverlayComputeSucceeded(indicatorId) {
|
|
395
|
+
const state = drivers.get(indicatorId);
|
|
396
|
+
if (!state)
|
|
397
|
+
return;
|
|
398
|
+
state.hasGoodResult = true;
|
|
399
|
+
notifyWrunOverlayHooks(computeSucceededHooks, 'compute-succeeded', indicatorId, indicatorId, state.driver.chartIndex);
|
|
400
|
+
}
|
|
401
|
+
/** Noted by the run pass for the run it is computing (C1): the generation it
|
|
402
|
+
* computed with and how it settled. The executor reports the note once the
|
|
403
|
+
* run settles; a later note of the same run replaces an earlier one. */
|
|
404
|
+
export function noteWrunOverlayRunSettle(indicatorId, note) {
|
|
405
|
+
const state = drivers.get(indicatorId);
|
|
406
|
+
if (!state)
|
|
407
|
+
return;
|
|
408
|
+
state.runNote = note;
|
|
409
|
+
state.lastGeneration = note.generation;
|
|
410
|
+
}
|
|
411
|
+
export function setWrunOverlayLiveContext(context) {
|
|
412
|
+
liveContexts.set(context.indicatorId, context);
|
|
413
|
+
}
|
|
414
|
+
export function getWrunOverlayLiveContext(indicatorId) {
|
|
415
|
+
return liveContexts.get(indicatorId);
|
|
416
|
+
}
|
|
417
|
+
export function hasWrunOverlayLiveContext(indicatorId) {
|
|
418
|
+
return liveContexts.has(indicatorId);
|
|
419
|
+
}
|
|
420
|
+
// The reader of the sheet a live session builds with, registered by the live tick lane at import: the lane keeps each
|
|
421
|
+
// source-fed session's verdict (its refusal set) with the run pass's cut seam, and each browser session's respelled
|
|
422
|
+
// pins sit beside its context. Without one, no session is cut or respelled.
|
|
423
|
+
let liveSheetReader = null;
|
|
424
|
+
/** Register (or clear, with null) the reader of the sheet a live session builds with. */
|
|
425
|
+
export function setWrunLiveSheetReader(reader) {
|
|
426
|
+
liveSheetReader = reader;
|
|
427
|
+
}
|
|
428
|
+
/** The sheet `context` builds with as `settings` paint `sheet` (the overlay's own): when a row source feeds it, the
|
|
429
|
+
* sheet the source ran less every family its refusals leave out now; for a browser session whose installing run
|
|
430
|
+
* respelled pins, the painted sheet with those pins laid on again (the respelling lives on the run's copy, never on
|
|
431
|
+
* the overlay's sheet). Undefined for any other session: the overlay's sheet with the settings is the one it builds
|
|
432
|
+
* with. */
|
|
433
|
+
export function wrunLiveContextSheetFor(context, settings, sheet) {
|
|
434
|
+
return liveSheetReader?.(context, settings, sheet);
|
|
435
|
+
}
|
|
436
|
+
/** Drop everything the lifecycle holds for one overlay: the driver, the live
|
|
437
|
+
* context, the intake/tick state (through the teardown hooks), and the
|
|
438
|
+
* worker-side live session. Called when the overlay is found unmounted
|
|
439
|
+
* (and safe to call redundantly). The order is frozen (plan section 8
|
|
440
|
+
* fold 3): capture the identity, bump the generation, run the synchronous
|
|
441
|
+
* hooks, delete the registries, ALWAYS end the worker session. */
|
|
442
|
+
export function teardownWrunOverlay(indicatorId) {
|
|
443
|
+
releaseWrunOverlayLiveSession(indicatorId, 'teardown');
|
|
444
|
+
}
|
|
445
|
+
/** Pause: end the overlay's live session in the teardown order (generation
|
|
446
|
+
* bump, teardown hooks with cause 'suspend', context delete, worker session
|
|
447
|
+
* end) while the driver stays registered, so nothing ticks or reconciles
|
|
448
|
+
* until Resume reruns it. A no-op for an id with neither a driver nor a
|
|
449
|
+
* live context. */
|
|
450
|
+
export function suspendWrunOverlayLiveSession(indicatorId) {
|
|
451
|
+
if (!drivers.has(indicatorId) && !liveContexts.has(indicatorId))
|
|
452
|
+
return;
|
|
453
|
+
releaseWrunOverlayLiveSession(indicatorId, 'suspend');
|
|
454
|
+
}
|
|
455
|
+
function releaseWrunOverlayLiveSession(indicatorId, cause) {
|
|
456
|
+
// The identity being torn down: read before anything moves, so the bump
|
|
457
|
+
// and the hooks act on the live context (a hook may still read it).
|
|
458
|
+
const context = liveContexts.get(indicatorId);
|
|
459
|
+
const state = drivers.get(indicatorId);
|
|
460
|
+
const chartIndex = state?.driver.chartIndex ?? context?.chartIndex;
|
|
461
|
+
// A pause shows Paused and a teardown leaves nothing to word: no unanswered drop waits on either.
|
|
462
|
+
if (state !== undefined)
|
|
463
|
+
clearWrunUnansweredDrop(state);
|
|
464
|
+
nextWrunOverlayLiveGeneration(indicatorId);
|
|
465
|
+
for (const hook of liveTeardownHooks) {
|
|
466
|
+
try {
|
|
467
|
+
hook(indicatorId, cause);
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
console.warn(`[wrun] live teardown hook failed for '${indicatorId}' (chart ${context?.chartIndex}):`, error);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (cause === 'teardown') {
|
|
474
|
+
drivers.delete(indicatorId);
|
|
475
|
+
// The overlay's refusal attempts and verdicts go with it: a settlement
|
|
476
|
+
// landing after this claims nothing, and a later tenant starts clean.
|
|
477
|
+
if (chartIndex !== undefined)
|
|
478
|
+
closeWrunRefusalAttempts(chartIndex, indicatorId);
|
|
479
|
+
// Taps a dropped run left waiting settle now, dropped (C4): the loader lowers what it raised and
|
|
480
|
+
// records nothing failed. A run in flight settles the taps it holds and those of its follow-up.
|
|
481
|
+
if (state !== undefined && state.inFlight === null && state.outcomeTaps.length > 0) {
|
|
482
|
+
rejectOutcomeTaps(state, new WrunChartGoneError(`wrun overlay '${indicatorId}' left the chart before its first run settled`));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
liveContexts.delete(indicatorId);
|
|
486
|
+
// Unconditional once the host exists: live-end is idempotent in the
|
|
487
|
+
// worker, and a context that was never stored here can still shadow a
|
|
488
|
+
// session opened by an earlier mount under the same id. No host yet: no
|
|
489
|
+
// worker, no session to end.
|
|
490
|
+
endHostLiveSeries?.(indicatorId);
|
|
491
|
+
}
|
|
492
|
+
/** Chart teardown: drop every driver, live context, and worker session this
|
|
493
|
+
* chart owns (a rebuilt chart at the same index must not inherit them), then
|
|
494
|
+
* run the chart-teardown hooks (`onWrunChartTeardown`). */
|
|
495
|
+
export function teardownWrunOverlaysForChart(chartIndex) {
|
|
496
|
+
const ids = new Set();
|
|
497
|
+
for (const [indicatorId, state] of drivers) {
|
|
498
|
+
if (state.driver.chartIndex === chartIndex)
|
|
499
|
+
ids.add(indicatorId);
|
|
500
|
+
}
|
|
501
|
+
for (const [indicatorId, context] of liveContexts) {
|
|
502
|
+
if (context.chartIndex === chartIndex)
|
|
503
|
+
ids.add(indicatorId);
|
|
504
|
+
}
|
|
505
|
+
for (const indicatorId of ids)
|
|
506
|
+
teardownWrunOverlay(indicatorId);
|
|
507
|
+
for (const hook of chartTeardownHooks) {
|
|
508
|
+
try {
|
|
509
|
+
hook(chartIndex);
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
console.warn(`[wrun] chart teardown hook failed for chart ${chartIndex}:`, error);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Register a synchronous chart-teardown hook: called with the chart index at
|
|
518
|
+
* the end of `teardownWrunOverlaysForChart` (chart destroy and group
|
|
519
|
+
* teardown), after the per-overlay teardowns, for state a chart owns that no
|
|
520
|
+
* driver or live context names. Returns the unregister function.
|
|
521
|
+
*/
|
|
522
|
+
export function onWrunChartTeardown(fn) {
|
|
523
|
+
chartTeardownHooks.add(fn);
|
|
524
|
+
return () => {
|
|
525
|
+
chartTeardownHooks.delete(fn);
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/** The lane buffers a live context keeps one array of rows for. */
|
|
529
|
+
const WRUN_CENSUS_LANE_BUFFERS = [
|
|
530
|
+
'bookRows',
|
|
531
|
+
'buySellVolumeRows',
|
|
532
|
+
'buySellVolumeUsdRows',
|
|
533
|
+
'openInterestRows',
|
|
534
|
+
'volumeProfileRows',
|
|
535
|
+
'tradeVolumeBySizeRows',
|
|
536
|
+
'tapeRows',
|
|
537
|
+
'liquidationRows',
|
|
538
|
+
'fundingRateRows',
|
|
539
|
+
'impliedVolatilityRows',
|
|
540
|
+
'skewRows',
|
|
541
|
+
'optionsChainRows',
|
|
542
|
+
'etfFlowRows',
|
|
543
|
+
];
|
|
544
|
+
/** The buffers it keeps one array of rows per key for (a poll lane instance, a leg's fetch key). */
|
|
545
|
+
const WRUN_CENSUS_KEYED_BUFFERS = [
|
|
546
|
+
'pollLaneRows',
|
|
547
|
+
'tradeLegRows',
|
|
548
|
+
'pinnedCandleRows',
|
|
549
|
+
'pinnedLiveCandleRows',
|
|
550
|
+
'intrabarRows',
|
|
551
|
+
];
|
|
552
|
+
/** Rows a buffer's byte estimate samples, spread across it. */
|
|
553
|
+
const WRUN_CENSUS_SAMPLED_ROWS = 32;
|
|
554
|
+
/** The numbers one row holds: its cells, and a nested cell's own (a tape bar's prints, a profile's buckets). */
|
|
555
|
+
function wrunCensusRowNumbers(row) {
|
|
556
|
+
if (typeof row !== 'object' || row === null || !('length' in row))
|
|
557
|
+
return typeof row === 'number' ? 1 : 0;
|
|
558
|
+
const cells = row;
|
|
559
|
+
let numbers = 0;
|
|
560
|
+
for (let at = 0; at < cells.length; at += 1) {
|
|
561
|
+
const cell = cells[at];
|
|
562
|
+
numbers += typeof cell === 'object' && cell !== null && 'length' in cell ? cell.length : 1;
|
|
563
|
+
}
|
|
564
|
+
return numbers;
|
|
565
|
+
}
|
|
566
|
+
/** A buffer's bytes at 8 a number, from up to WRUN_CENSUS_SAMPLED_ROWS of its rows. */
|
|
567
|
+
function wrunCensusBufferBytes(rows) {
|
|
568
|
+
const sampled = Math.min(rows.length, WRUN_CENSUS_SAMPLED_ROWS);
|
|
569
|
+
if (sampled === 0)
|
|
570
|
+
return 0;
|
|
571
|
+
let numbers = 0;
|
|
572
|
+
for (let at = 0; at < sampled; at += 1) {
|
|
573
|
+
numbers += wrunCensusRowNumbers(rows[Math.floor((at * rows.length) / sampled)]);
|
|
574
|
+
}
|
|
575
|
+
return Math.round((numbers / sampled) * rows.length * 8);
|
|
576
|
+
}
|
|
577
|
+
/** The data rows of a built result, over its outputs. */
|
|
578
|
+
function wrunCensusResultRows(result) {
|
|
579
|
+
let rows = 0;
|
|
580
|
+
for (const output of Object.values(result?.outputs ?? {})) {
|
|
581
|
+
rows += Array.isArray(output.data) ? output.data.length : 0;
|
|
582
|
+
}
|
|
583
|
+
return rows;
|
|
584
|
+
}
|
|
585
|
+
/** Every live session's retention (memory spec 4.4), read-only: rows counted, bytes sampled, nothing created. */
|
|
586
|
+
export function wrunOverlayMemoryCensus() {
|
|
587
|
+
const entries = [];
|
|
588
|
+
for (const context of liveContexts.values()) {
|
|
589
|
+
const buffers = [];
|
|
590
|
+
for (const key of WRUN_CENSUS_LANE_BUFFERS) {
|
|
591
|
+
const rows = context[key];
|
|
592
|
+
if (rows !== undefined)
|
|
593
|
+
buffers.push(rows);
|
|
594
|
+
}
|
|
595
|
+
for (const key of WRUN_CENSUS_KEYED_BUFFERS)
|
|
596
|
+
buffers.push(...Object.values(context[key] ?? {}));
|
|
597
|
+
if (context.formingPreRoll !== undefined)
|
|
598
|
+
buffers.push(context.formingPreRoll.rows);
|
|
599
|
+
let laneRows = 0;
|
|
600
|
+
let laneBytes = 0;
|
|
601
|
+
for (const rows of buffers) {
|
|
602
|
+
laneRows += rows.length;
|
|
603
|
+
laneBytes += wrunCensusBufferBytes(rows);
|
|
604
|
+
}
|
|
605
|
+
const applied = context.liveApplied;
|
|
606
|
+
const build = applied?.build?.result;
|
|
607
|
+
entries.push({
|
|
608
|
+
id: context.indicatorId,
|
|
609
|
+
chartIndex: context.chartIndex,
|
|
610
|
+
liveRows: context.outputRows.length,
|
|
611
|
+
laneRows,
|
|
612
|
+
laneBytes,
|
|
613
|
+
liveAppliedRows: wrunCensusResultRows(applied?.result) + (build !== applied?.result ? wrunCensusResultRows(build) : 0),
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
return entries;
|
|
617
|
+
}
|
|
618
|
+
let prefixRuntime = null;
|
|
619
|
+
/** Register (or clear, with null) the run pass's prefix side. */
|
|
620
|
+
export function setWrunPrefixRuntime(runtime) {
|
|
621
|
+
prefixRuntime = runtime;
|
|
622
|
+
}
|
|
623
|
+
/** The lifecycle door's plan for a pan wave: none without a driver or a registered prefix side. */
|
|
624
|
+
export function planWrunOverlayPrefixRequest(chartIndex, indicatorId) {
|
|
625
|
+
return drivers.has(indicatorId) ? prefixRuntime?.plan(chartIndex, indicatorId) : undefined;
|
|
626
|
+
}
|
|
627
|
+
/** A plan the lifecycle door queued no run for (held, skipped, failed). */
|
|
628
|
+
export function dropWrunOverlayPrefixRequest(chartIndex, indicatorId, tag, why) {
|
|
629
|
+
try {
|
|
630
|
+
prefixRuntime?.drop(chartIndex, indicatorId, tag, why);
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
console.warn(`[wrun] prefix drop failed for '${indicatorId}':`, error);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
/** Whether a run window is a prefix run's (its tag rides it). */
|
|
637
|
+
export function isWrunPrefixRunWindow(window) {
|
|
638
|
+
return typeof window?.prefix?.requestId === 'string';
|
|
639
|
+
}
|
|
640
|
+
/** Whether a request that replaces the session waits behind the run in flight (the prefix commit's
|
|
641
|
+
* staleness rule): any queued follow-up but another planned pan wave. */
|
|
642
|
+
export function isWrunOverlayReplacementPending(indicatorId) {
|
|
643
|
+
const state = drivers.get(indicatorId);
|
|
644
|
+
if (state === undefined || !state.pendingAgain)
|
|
645
|
+
return false;
|
|
646
|
+
return state.pendingOptions?.prefix === undefined;
|
|
647
|
+
}
|
|
648
|
+
/** A tagged request at its execution start, replanned by the run pass: its prefix window, the wave
|
|
649
|
+
* whole, or null (nothing left to compute: no run). No prefix side: the wave whole. */
|
|
650
|
+
function startWrunPrefixRequest(indicatorId, state, request) {
|
|
651
|
+
const tag = request.prefix;
|
|
652
|
+
if (tag === undefined)
|
|
653
|
+
return request;
|
|
654
|
+
const { prefix: _tag, window: wave, ...rest } = request;
|
|
655
|
+
let started = { window: wave };
|
|
656
|
+
try {
|
|
657
|
+
if (prefixRuntime)
|
|
658
|
+
started = prefixRuntime.start(state.driver.chartIndex, indicatorId, tag, wave);
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
console.warn(`[wrun] prefix replan failed for '${indicatorId}' (the wave runs whole):`, error);
|
|
662
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, tag, 'replan-failed');
|
|
663
|
+
}
|
|
664
|
+
if (started === null)
|
|
665
|
+
return null;
|
|
666
|
+
return started.window ? { ...rest, window: started.window } : rest;
|
|
667
|
+
}
|
|
668
|
+
/** True while a chart-wave recompute for this overlay is running: the live
|
|
669
|
+
* tick lane skips its work then (the rerun rebuilds the session and the
|
|
670
|
+
* tick's inputs/session would straddle two generations). */
|
|
671
|
+
export function isWrunOverlayRerunInFlight(indicatorId) {
|
|
672
|
+
return drivers.get(indicatorId)?.inFlight != null;
|
|
673
|
+
}
|
|
674
|
+
/** Whether a run over the whole loaded window is in flight (C1): it computes the
|
|
675
|
+
* overlay's latest settings everywhere and reports its settle. A run over a
|
|
676
|
+
* partial window (a pan page) does not count: it computes its rows only and
|
|
677
|
+
* reports nothing, so the store's reconcile never waits on it. */
|
|
678
|
+
export function isWrunOverlayFullRerunInFlight(indicatorId) {
|
|
679
|
+
const state = drivers.get(indicatorId);
|
|
680
|
+
return state?.inFlight != null && state.inFlightRequest?.window?.partial !== true;
|
|
681
|
+
}
|
|
682
|
+
/** Reject (and clear) every latched outcome tap: a run they were waiting on
|
|
683
|
+
* can no longer happen (teardown mid-run, or unmounted before a follow-up).
|
|
684
|
+
* Callers of the initial-compute entry race a deadline that pre-marks the
|
|
685
|
+
* rejection handled, so a stranded tap must reject rather than hang. */
|
|
686
|
+
function rejectOutcomeTaps(state, error) {
|
|
687
|
+
const taps = state.outcomeTaps;
|
|
688
|
+
state.outcomeTaps = [];
|
|
689
|
+
for (const tap of taps)
|
|
690
|
+
tap.reject(error);
|
|
691
|
+
}
|
|
692
|
+
/** Whether a run settled `dropped` (C4): the quiet WrunChartGoneError of a run its overlay's newer intent
|
|
693
|
+
* superseded (the run pass rewraps any rejection of such a run), of an overlay that left or of replay
|
|
694
|
+
* taking the chart. Nothing failed. The one rule readers of a settled run tell dropped from failed by. */
|
|
695
|
+
export function isWrunRunDroppedError(error) {
|
|
696
|
+
return error instanceof WrunChartGoneError;
|
|
697
|
+
}
|
|
698
|
+
/** A dropped run's first-compute taps (C4): while the mount stands they wait for the run that replaces it
|
|
699
|
+
* (queued now or asked next; `wrunRunRequestOwedToTaps`) and settle with its outcome; once the mount left
|
|
700
|
+
* they settle now, dropped. A teardown settles waiting ones (`releaseWrunOverlayLiveSession`). */
|
|
701
|
+
function handOverDroppedRunTaps(indicatorId, state, taps, dropped) {
|
|
702
|
+
if (taps.length === 0)
|
|
703
|
+
return;
|
|
704
|
+
if (drivers.get(indicatorId) === state && state.driver.isMounted()) {
|
|
705
|
+
state.outcomeTaps = [...taps, ...state.outcomeTaps];
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
for (const tap of taps)
|
|
709
|
+
tap.reject(dropped);
|
|
710
|
+
}
|
|
711
|
+
/** A run that starts with taps waiting runs as the mount's first run: 'initial' merged in by rank, the
|
|
712
|
+
* whole loaded window, the loader's attempt answered (a prefix tag the merge drops never runs). */
|
|
713
|
+
function wrunRunRequestOwedToTaps(indicatorId, state, request) {
|
|
714
|
+
if (state.outcomeTaps.length === 0)
|
|
715
|
+
return request;
|
|
716
|
+
const owed = mergeWrunRunRequests(request, { reason: 'initial' });
|
|
717
|
+
if (request.prefix !== undefined && owed.prefix === undefined) {
|
|
718
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, request.prefix, 'superseded');
|
|
719
|
+
}
|
|
720
|
+
return owed;
|
|
721
|
+
}
|
|
722
|
+
// The run pass's surface for an unanswered drop, registered at its import (the registry stays off the chart
|
|
723
|
+
// imports). Without one, the deadline only rings.
|
|
724
|
+
let unansweredDropSurface = null;
|
|
725
|
+
/** Register (or clear, with null) the surface an unanswered drop's deadline hands its rejection to. */
|
|
726
|
+
export function setWrunUnansweredDropSurface(surface) {
|
|
727
|
+
unansweredDropSurface = surface;
|
|
728
|
+
}
|
|
729
|
+
/** The rejection an unanswered drop settles with: the run deadline's (`WrunDeadlineError`, the retryable
|
|
730
|
+
* `not-reached` record), stamped with the cause `superseded` (a run its overlay's newer intent superseded, and
|
|
731
|
+
* no run replaced it), so the attempt, the record and the shown failure name one cause. */
|
|
732
|
+
export function wrunUnansweredDropError(indicatorId) {
|
|
733
|
+
const seconds = Math.round(WRUN_RUN_DEADLINE_MS / 1000);
|
|
734
|
+
const error = new WrunDeadlineError(`wrun overlay '${indicatorId}' drew nothing within ${seconds}s of visible time: no run replaced a superseded one`);
|
|
735
|
+
attachWrunRefusal(error, { cls: 'not-reached', variant: 'run' });
|
|
736
|
+
return stampWrunRefusalTelemetry(error, { cause: 'superseded' });
|
|
737
|
+
}
|
|
738
|
+
function clearWrunUnansweredDrop(state) {
|
|
739
|
+
state.unansweredDrop?.clear();
|
|
740
|
+
state.unansweredDrop = undefined;
|
|
741
|
+
state.unansweredDropEpoch += 1;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* The overlay drew its whole window outside the executor: a buffer reseed that integrated (the run pass's
|
|
745
|
+
* `reseedWrunOverlayFromBuffers`, which supersedes every earlier verdict like a full run, contract C3). An
|
|
746
|
+
* unanswered drop's deadline, and a surface it already handed over, have nothing left to say.
|
|
747
|
+
*/
|
|
748
|
+
export function noteWrunOverlayWholeWindowDrawn(indicatorId) {
|
|
749
|
+
const state = drivers.get(indicatorId);
|
|
750
|
+
if (state !== undefined)
|
|
751
|
+
clearWrunUnansweredDrop(state);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* A dropped full run's follow-up decision found no run to answer for it (C4's backstop): arm the overlay's one
|
|
755
|
+
* visible-time run deadline, unless one already waits, a first-compute waiter holds the wait (its loader's
|
|
756
|
+
* deadline is the one deadline) or the overlay left. It never runs out under a full run in flight: that run's
|
|
757
|
+
* start cleared it, and only its own drop arms it again. When it fires on the same mount, the run pass gets the
|
|
758
|
+
* drop to show (`WrunUnansweredDrop`), current until anything that would have cleared the deadline happens.
|
|
759
|
+
*/
|
|
760
|
+
function armWrunUnansweredDrop(indicatorId, state) {
|
|
761
|
+
if (state.unansweredDrop !== undefined || state.outcomeTaps.length > 0)
|
|
762
|
+
return;
|
|
763
|
+
if (drivers.get(indicatorId) !== state || !state.driver.isMounted())
|
|
764
|
+
return;
|
|
765
|
+
const chartIndex = state.driver.chartIndex;
|
|
766
|
+
if (wrunChartHostEnv().diagnostics.debugEnabled()) {
|
|
767
|
+
wrunChartHostEnv().diagnostics.debug('wrun-unanswered-drop-armed', {
|
|
768
|
+
chartIndex,
|
|
769
|
+
indicatorId,
|
|
770
|
+
deadlineMs: WRUN_RUN_DEADLINE_MS,
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
state.unansweredDrop = startVisibleTimeout(() => {
|
|
774
|
+
state.unansweredDrop = undefined;
|
|
775
|
+
const epoch = state.unansweredDropEpoch;
|
|
776
|
+
const isCurrent = () => state.unansweredDropEpoch === epoch &&
|
|
777
|
+
drivers.get(indicatorId) === state &&
|
|
778
|
+
state.driver.chartIndex === chartIndex &&
|
|
779
|
+
state.driver.isMounted();
|
|
780
|
+
if (!isCurrent())
|
|
781
|
+
return;
|
|
782
|
+
const drop = {
|
|
783
|
+
chartIndex,
|
|
784
|
+
indicatorId,
|
|
785
|
+
error: wrunUnansweredDropError(indicatorId),
|
|
786
|
+
isCurrent,
|
|
787
|
+
answer: (token) => {
|
|
788
|
+
if (isCurrent() && token?.origin === 'user')
|
|
789
|
+
state.answeredUserAttempt = token.generation;
|
|
790
|
+
},
|
|
791
|
+
};
|
|
792
|
+
if (wrunChartHostEnv().diagnostics.debugEnabled()) {
|
|
793
|
+
wrunChartHostEnv().diagnostics.debug('wrun-unanswered-drop', {
|
|
794
|
+
chartIndex,
|
|
795
|
+
indicatorId,
|
|
796
|
+
deadlineMs: WRUN_RUN_DEADLINE_MS,
|
|
797
|
+
runInFlight: state.inFlight !== null,
|
|
798
|
+
surfaced: unansweredDropSurface !== null,
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
try {
|
|
802
|
+
unansweredDropSurface?.(drop);
|
|
803
|
+
}
|
|
804
|
+
catch (surfaceError) {
|
|
805
|
+
console.warn(`[wrun] unanswered drop of '${indicatorId}' was not surfaced:`, surfaceError);
|
|
806
|
+
}
|
|
807
|
+
}, WRUN_RUN_DEADLINE_MS, wrunHostVisibleClock());
|
|
808
|
+
}
|
|
809
|
+
let chartStoreModule;
|
|
810
|
+
/** The chart store module, loaded on first use through the host's loader
|
|
811
|
+
* (`chart.loadChartStore`; never at import: the store must not enter this
|
|
812
|
+
* registry's eager graph) and shared by every caller here, so settles
|
|
813
|
+
* landing together never ask for it twice; a failed load is retried. */
|
|
814
|
+
function loadWrunChartStoreModule() {
|
|
815
|
+
chartStoreModule ??= wrunChartHostEnv()
|
|
816
|
+
.chart.loadChartStore()
|
|
817
|
+
.catch((error) => {
|
|
818
|
+
chartStoreModule = undefined;
|
|
819
|
+
throw error;
|
|
820
|
+
});
|
|
821
|
+
return chartStoreModule;
|
|
822
|
+
}
|
|
823
|
+
/** The settle a run reports (C1): the run pass's note, else (the run settled
|
|
824
|
+
* before the run pass noted anything: the loader's own phases) its plain
|
|
825
|
+
* outcome under the last generation a run of this overlay computed with. */
|
|
826
|
+
function takeWrunRunSettle(state, ok, error) {
|
|
827
|
+
const note = state.runNote;
|
|
828
|
+
state.runNote = undefined;
|
|
829
|
+
if (note)
|
|
830
|
+
return note;
|
|
831
|
+
if (ok)
|
|
832
|
+
return { generation: state.lastGeneration, outcome: 'applied' };
|
|
833
|
+
return {
|
|
834
|
+
generation: state.lastGeneration,
|
|
835
|
+
outcome: 'failed',
|
|
836
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
/** The store's settings sync as the lane reads it (C1): the generation the
|
|
840
|
+
* overlay's latest save asked for, or null while the store cannot say. */
|
|
841
|
+
function wrunRequestedSettingsGeneration(store, chartIndex, indicatorId) {
|
|
842
|
+
try {
|
|
843
|
+
const requestedGen = store.indicatorSettingsSync(chartIndex, indicatorId)?.requestedGen;
|
|
844
|
+
return typeof requestedGen === 'number' ? requestedGen : null;
|
|
845
|
+
}
|
|
846
|
+
catch {
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Report one settled run (C1, C4): the `settings-run-settled` ring event,
|
|
852
|
+
* then the store's `noteIndicatorSettingsSettled` with the generation the run
|
|
853
|
+
* computed with, so a failed or held run reaches the store's reconcile (the
|
|
854
|
+
* last good picture never stays silently). Called after the follow-up
|
|
855
|
+
* decision. `toStore` false: the overlay left (torn down meanwhile), only the
|
|
856
|
+
* ring hears of it. Never throws.
|
|
857
|
+
*/
|
|
858
|
+
function reportWrunRunSettled(indicatorId, chartIndex, settle, toStore) {
|
|
859
|
+
void loadWrunChartStoreModule()
|
|
860
|
+
.then(({ useChartStore }) => {
|
|
861
|
+
const store = useChartStore();
|
|
862
|
+
if (wrunChartHostEnv().diagnostics.debugEnabled()) {
|
|
863
|
+
wrunChartHostEnv().diagnostics.debug('settings-run-settled', {
|
|
864
|
+
chartIndex,
|
|
865
|
+
indicatorId,
|
|
866
|
+
lane: 'wrun',
|
|
867
|
+
gen: settle.generation,
|
|
868
|
+
requestedGen: wrunRequestedSettingsGeneration(store, chartIndex, indicatorId),
|
|
869
|
+
outcome: settle.outcome,
|
|
870
|
+
reason: settle.reason ?? null,
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
if (toStore) {
|
|
874
|
+
store.noteIndicatorSettingsSettled(chartIndex, indicatorId, settle.generation, settle.outcome, settle.reason);
|
|
875
|
+
}
|
|
876
|
+
})
|
|
877
|
+
.catch(() => undefined);
|
|
878
|
+
}
|
|
879
|
+
/** The queued requests' one follow-up waiter, made by the first of them. */
|
|
880
|
+
function followUpWaitersOf(state) {
|
|
881
|
+
if (!state.followUp) {
|
|
882
|
+
let resolve = () => undefined;
|
|
883
|
+
const promise = new Promise((settle) => {
|
|
884
|
+
resolve = settle;
|
|
885
|
+
});
|
|
886
|
+
state.followUp = { promise, resolve };
|
|
887
|
+
}
|
|
888
|
+
return state.followUp;
|
|
889
|
+
}
|
|
890
|
+
/** The follow-up decision of a run that settled (the overlay still this
|
|
891
|
+
* state's): the queued requests' ONE follow-up run, or undefined when none
|
|
892
|
+
* runs (nothing queued, the overlay left the chart, a pan wave the run just
|
|
893
|
+
* covered). */
|
|
894
|
+
function startWrunFollowUp(indicatorId, state) {
|
|
895
|
+
state.inFlight = null;
|
|
896
|
+
state.inFlightRequest = undefined;
|
|
897
|
+
if (!state.pendingAgain)
|
|
898
|
+
return undefined;
|
|
899
|
+
const next = state.pendingOptions ?? wrunRunRequestOf(undefined);
|
|
900
|
+
state.pendingAgain = false;
|
|
901
|
+
state.pendingOptions = undefined;
|
|
902
|
+
if (!state.driver.isMounted()) {
|
|
903
|
+
teardownWrunOverlay(indicatorId);
|
|
904
|
+
rejectOutcomeTaps(state, new WrunChartGoneError(`wrun overlay '${indicatorId}' is no longer on the chart`));
|
|
905
|
+
return undefined;
|
|
906
|
+
}
|
|
907
|
+
// A pan wave queued behind the run that just computed its rows over the
|
|
908
|
+
// same main rows (a pan-back page's live rebuild) has nothing new to
|
|
909
|
+
// compute (a latched tap always rides an 'initial' follow-up, which no
|
|
910
|
+
// range reason outranks).
|
|
911
|
+
if (state.outcomeTaps.length === 0 && isWrunCoveredWaveRequest(indicatorId, state, next)) {
|
|
912
|
+
if (next.prefix)
|
|
913
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, next.prefix, 'covered');
|
|
914
|
+
return undefined;
|
|
915
|
+
}
|
|
916
|
+
return beginExecutorRun(indicatorId, state, next);
|
|
917
|
+
}
|
|
918
|
+
/** Two run failures that read the same: one error class and message (a rerun into the same cause). */
|
|
919
|
+
function isSameWrunFailure(previous, next) {
|
|
920
|
+
if (previous instanceof Error && next instanceof Error) {
|
|
921
|
+
return previous.constructor === next.constructor && previous.message === next.message;
|
|
922
|
+
}
|
|
923
|
+
return previous === next;
|
|
924
|
+
}
|
|
925
|
+
/** One executor run + the follow-up decision, shared by the chart-wave entry
|
|
926
|
+
* and the add/rehydrate initial-compute entry. The run consumes the taps
|
|
927
|
+
* latched at its start: they settle with THIS run's own outcome (a dropped
|
|
928
|
+
* run hands them to the run that replaces it, C4). Every
|
|
929
|
+
* settled run is announced once to the run-settled subscribers, and reported
|
|
930
|
+
* once to the store's settings sync. */
|
|
931
|
+
function beginExecutorRun(indicatorId, state, planned) {
|
|
932
|
+
// A planned pan wave is replanned against the current session as it starts (C1 v3): its prefix
|
|
933
|
+
// window, the full wave it falls back to, or nothing left to compute (dropped: no run at all).
|
|
934
|
+
const request = startWrunPrefixRequest(indicatorId, state, wrunRunRequestOwedToTaps(indicatorId, state, planned));
|
|
935
|
+
if (request === null)
|
|
936
|
+
return Promise.resolve();
|
|
937
|
+
// A full run in flight answers for the overlay until it settles: an unanswered drop's deadline (and a surface it
|
|
938
|
+
// already handed over) stands down, and this run's own drop arms a fresh one if nothing follows it.
|
|
939
|
+
if (request.window?.partial !== true)
|
|
940
|
+
clearWrunUnansweredDrop(state);
|
|
941
|
+
// The prefix run's tag, read back when it settles: its coverage counts only once it landed.
|
|
942
|
+
const prefixRun = isWrunPrefixRunWindow(request.window) ? request.window.prefix : undefined;
|
|
943
|
+
const prefixTag = prefixRun ? { requestId: prefixRun.requestId } : undefined;
|
|
944
|
+
// The attempt this run answers, live before the run pass's first await.
|
|
945
|
+
const attempt = beginWrunRunAttempt(indicatorId, state, request);
|
|
946
|
+
// What the run settled with (the run pass's note), reported after the follow-up decision.
|
|
947
|
+
let settled;
|
|
948
|
+
// The run settled dropped: the follow-up decision says whether any run answers for it.
|
|
949
|
+
let dropped = false;
|
|
950
|
+
const announce = (ok, error) => {
|
|
951
|
+
const failedIdentity = ok ? undefined : wrunRunFailedIdentityOf(error);
|
|
952
|
+
const event = {
|
|
953
|
+
indicatorId,
|
|
954
|
+
chartIndex: state.driver.chartIndex,
|
|
955
|
+
reason: request.reason,
|
|
956
|
+
ok,
|
|
957
|
+
// A failed run names the window and settings it failed on, so the narrow deterministic
|
|
958
|
+
// latch (an over-budget output) compares a later wave's candidate against it.
|
|
959
|
+
...(ok ? {} : { error }),
|
|
960
|
+
...(failedIdentity ? { failedIdentity } : {}),
|
|
961
|
+
};
|
|
962
|
+
notifyWrunOverlayHooks(runSettledHooks, 'run-settled', indicatorId, event);
|
|
963
|
+
};
|
|
964
|
+
const runOnce = () => {
|
|
965
|
+
const taps = state.outcomeTaps;
|
|
966
|
+
state.outcomeTaps = [];
|
|
967
|
+
let ranDriver;
|
|
968
|
+
let ranRowsIdentity;
|
|
969
|
+
return Promise.resolve()
|
|
970
|
+
.then(() => {
|
|
971
|
+
ranDriver = state.driver;
|
|
972
|
+
// The rows this run starts on: a page landing during the run makes
|
|
973
|
+
// the next wave differ, so it computes.
|
|
974
|
+
ranRowsIdentity = readWrunChartRowsIdentity(ranDriver.chartIndex, indicatorId);
|
|
975
|
+
// The run pass notes this run's settle afresh.
|
|
976
|
+
state.runNote = undefined;
|
|
977
|
+
return ranDriver.rerun(wrunRerunOptionsOf(request));
|
|
978
|
+
})
|
|
979
|
+
.then(() => {
|
|
980
|
+
settled = takeWrunRunSettle(state, true);
|
|
981
|
+
// The overlay drew its whole window: an unanswered drop's deadline has nothing left to say (a pan
|
|
982
|
+
// page draws its own rows only).
|
|
983
|
+
if (request.window?.partial !== true)
|
|
984
|
+
clearWrunUnansweredDrop(state);
|
|
985
|
+
// A prefix run that settled before its pass recorded an outcome leaves no owner pending.
|
|
986
|
+
if (prefixTag !== undefined) {
|
|
987
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, prefixTag, 'unsettled');
|
|
988
|
+
}
|
|
989
|
+
state.hasGoodResult = true;
|
|
990
|
+
state.lastFailure = undefined;
|
|
991
|
+
// Only the current driver's run counts as computed (a driver
|
|
992
|
+
// re-registered mid-run has not run it), over rows it identified.
|
|
993
|
+
// A prefix run counts only once its commit landed, and then for the
|
|
994
|
+
// wave it stood for: the session it extended covers the rest.
|
|
995
|
+
const counts = state.driver === ranDriver &&
|
|
996
|
+
(prefixTag === undefined || prefixRuntime?.landed(indicatorId, prefixTag.requestId) === true);
|
|
997
|
+
state.lastCoverage =
|
|
998
|
+
counts && ranRowsIdentity !== undefined
|
|
999
|
+
? {
|
|
1000
|
+
window: prefixRun !== undefined ? prefixRun.fallback : request.window,
|
|
1001
|
+
rowsIdentity: ranRowsIdentity,
|
|
1002
|
+
}
|
|
1003
|
+
: undefined;
|
|
1004
|
+
concludeWrunRunAttempt(state, attempt, true);
|
|
1005
|
+
for (const tap of taps)
|
|
1006
|
+
tap.resolve();
|
|
1007
|
+
announce(true);
|
|
1008
|
+
}, (error) => {
|
|
1009
|
+
settled = takeWrunRunSettle(state, false, error);
|
|
1010
|
+
if (prefixTag !== undefined) {
|
|
1011
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, prefixTag, 'unsettled');
|
|
1012
|
+
}
|
|
1013
|
+
// A failed or dropped run covers nothing: the next wave for its rows runs.
|
|
1014
|
+
state.lastCoverage = undefined;
|
|
1015
|
+
if (isWrunRunDroppedError(error)) {
|
|
1016
|
+
// A dropped run is a named outcome the ring records (`settings-run-settled`): nothing failed
|
|
1017
|
+
// (C4). No failure kept, no warning (a tap storm printed one per retired run, 2026-10-15),
|
|
1018
|
+
// no Strategy Tester mark, no attempt answered; its taps wait for the replacement run, and with
|
|
1019
|
+
// no replacement on its way the overlay's run deadline waits instead (armWrunUnansweredDrop).
|
|
1020
|
+
handOverDroppedRunTaps(indicatorId, state, taps, error);
|
|
1021
|
+
dropped = true;
|
|
1022
|
+
announce(false, error);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
// A failed or held run says so on the overlay (its record, Paused, the venue wall, a source chip):
|
|
1026
|
+
// an unanswered drop's deadline has nothing left to say.
|
|
1027
|
+
clearWrunUnansweredDrop(state);
|
|
1028
|
+
const repeated = state.lastFailure !== undefined && isSameWrunFailure(state.lastFailure.error, error);
|
|
1029
|
+
state.lastFailure = { at: Date.now(), error };
|
|
1030
|
+
// Keep-last-good: the run integrates only on success, so the
|
|
1031
|
+
// mounted overlay still shows the previous result. The failure is
|
|
1032
|
+
// worded where it is known: the run pass projects its record on the
|
|
1033
|
+
// overlay (and the loader its own phases'), toasting once for the
|
|
1034
|
+
// attempt this run answers when a person made it; a tapped run's
|
|
1035
|
+
// rejection still propagates to its add/rehydrate caller. The
|
|
1036
|
+
// store's settings sync hears of it below (the settle report), so a
|
|
1037
|
+
// failed trailing run is retried by its reconcile, never kept silently.
|
|
1038
|
+
// A failure that repeats the last one (a retry, heal or source-recovery rung meeting the same
|
|
1039
|
+
// missing source) is warned once until a run succeeds: every rerun printed the same stack again
|
|
1040
|
+
// (7 in 72 s for one Order Book Pressure on 2026-10-15), while the overlay already shows it.
|
|
1041
|
+
if (!repeated) {
|
|
1042
|
+
console.warn(`[wrun] recompute failed for '${indicatorId}' (keeping the last rendered result):`, error);
|
|
1043
|
+
}
|
|
1044
|
+
// A strategy package's Strategy Tester still shows the last good
|
|
1045
|
+
// run's numbers; flag them stale the way the kScript path does on a
|
|
1046
|
+
// terminal failed re-run (the payload stays, the badge names the
|
|
1047
|
+
// last successful run). A no-op when no payload was ever published.
|
|
1048
|
+
void loadWrunChartStoreModule()
|
|
1049
|
+
.then(({ useChartStore }) => useChartStore().markStrategyTesterRunFailed(state.driver.chartIndex, indicatorId))
|
|
1050
|
+
.catch(() => undefined);
|
|
1051
|
+
concludeWrunRunAttempt(state, attempt, false);
|
|
1052
|
+
for (const tap of taps)
|
|
1053
|
+
tap.reject(error);
|
|
1054
|
+
announce(false, error);
|
|
1055
|
+
});
|
|
1056
|
+
};
|
|
1057
|
+
// The follow-up decision lives in the finally, AFTER inFlight clears:
|
|
1058
|
+
// pendingAgain is only ever set while inFlight is non-null, so a hit
|
|
1059
|
+
// landing between the run's settlement and any earlier follow-up check
|
|
1060
|
+
// would otherwise orphan (pendingAgain true, nothing scheduled). Checking
|
|
1061
|
+
// here closes that window: once inFlight is null, new hits start fresh.
|
|
1062
|
+
// Taps latched while this run was in flight belong to the follow-up run
|
|
1063
|
+
// (latest-wins: it recomputes over the CURRENT rows); when no follow-up
|
|
1064
|
+
// can happen they reject here instead of stranding their awaiter. The
|
|
1065
|
+
// queued requests' waiters go the same way: they resolve with the
|
|
1066
|
+
// follow-up, or here when none runs.
|
|
1067
|
+
const chain = runOnce().finally(() => {
|
|
1068
|
+
const followUp = state.followUp;
|
|
1069
|
+
state.followUp = undefined;
|
|
1070
|
+
let next;
|
|
1071
|
+
if (drivers.get(indicatorId) !== state) {
|
|
1072
|
+
// torn down mid-run
|
|
1073
|
+
rejectOutcomeTaps(state, new WrunChartGoneError(`wrun overlay '${indicatorId}' was torn down mid-recompute`));
|
|
1074
|
+
}
|
|
1075
|
+
else {
|
|
1076
|
+
next = startWrunFollowUp(indicatorId, state);
|
|
1077
|
+
// A dropped full run that nothing answers for (no follow-up; a waiter's loader keeps its own deadline)
|
|
1078
|
+
// arms the overlay's one run deadline. A partial window (a pan page) keeps the rows outside it.
|
|
1079
|
+
if (dropped && next === undefined && request.window?.partial !== true) {
|
|
1080
|
+
armWrunUnansweredDrop(indicatorId, state);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (followUp) {
|
|
1084
|
+
if (next)
|
|
1085
|
+
void next.then(followUp.resolve, followUp.resolve);
|
|
1086
|
+
else
|
|
1087
|
+
followUp.resolve();
|
|
1088
|
+
}
|
|
1089
|
+
// Once the follow-up is decided, so the store's reconcile reads whether a
|
|
1090
|
+
// run computing newer settings is on its way (isWrunOverlayFullRerunInFlight).
|
|
1091
|
+
// A partial window computed its rows only (the rows outside it and the
|
|
1092
|
+
// live session keep their settings): never a settings settle, applied or
|
|
1093
|
+
// not; the settings run owns the overlay's verdict.
|
|
1094
|
+
if (settled && request.window?.partial !== true) {
|
|
1095
|
+
reportWrunRunSettled(indicatorId, state.driver.chartIndex, settled, drivers.get(indicatorId) === state);
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
state.inFlight = chain;
|
|
1099
|
+
state.inFlightRequest = request;
|
|
1100
|
+
return chain;
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Chart-wave recompute entry (the lazy-load pan lane, and every lifecycle
|
|
1104
|
+
* rerun): single flight per overlay with latest-wins coalescing, exactly one
|
|
1105
|
+
* queued follow-up whose options merge by rank (`mergeWrunRunRequests`).
|
|
1106
|
+
* Returns the completion of the run that computes this request (never
|
|
1107
|
+
* rejects): the run it starts, or, behind a run in flight, the follow-up's
|
|
1108
|
+
* (every request queued behind one run shares it), so a settings save's tail
|
|
1109
|
+
* waits for its own settings to land, not for the run that read the older
|
|
1110
|
+
* ones. Undefined when the overlay has no driver, is no longer mounted (which
|
|
1111
|
+
* also tears it down), or the request is a pan wave whose window the last
|
|
1112
|
+
* good run already computed over the same main rows while nothing is in
|
|
1113
|
+
* flight (the coverage skip).
|
|
1114
|
+
*/
|
|
1115
|
+
export function rerunWrunOverlayForChartWave(indicatorId, options) {
|
|
1116
|
+
const state = drivers.get(indicatorId);
|
|
1117
|
+
if (!state)
|
|
1118
|
+
return undefined;
|
|
1119
|
+
if (!state.driver.isMounted()) {
|
|
1120
|
+
teardownWrunOverlay(indicatorId);
|
|
1121
|
+
return undefined;
|
|
1122
|
+
}
|
|
1123
|
+
const request = wrunRunRequestOf(options);
|
|
1124
|
+
if (state.inFlight) {
|
|
1125
|
+
queueWrunRunRequest(indicatorId, state, request);
|
|
1126
|
+
return followUpWaitersOf(state).promise;
|
|
1127
|
+
}
|
|
1128
|
+
if (isWrunCoveredWaveRequest(indicatorId, state, request)) {
|
|
1129
|
+
if (request.prefix)
|
|
1130
|
+
dropWrunOverlayPrefixRequest(state.driver.chartIndex, indicatorId, request.prefix, 'covered');
|
|
1131
|
+
return undefined;
|
|
1132
|
+
}
|
|
1133
|
+
return beginExecutorRun(indicatorId, state, request);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Add/rehydrate-time initial compute, routed THROUGH the same single-flight
|
|
1137
|
+
* executor as the chart wave: the driver is registered before the initial run,
|
|
1138
|
+
* so a lazy wave firing during the add must coalesce with it instead of
|
|
1139
|
+
* starting a concurrent duplicate compute (two overlapping runs also
|
|
1140
|
+
* interleaved the legend loader's raise/lower). Unlike the wave entry, the
|
|
1141
|
+
* returned promise settles with the run's OWN outcome: a failure rejects here
|
|
1142
|
+
* so the caller's typed error semantics stay intact. When a wave run is
|
|
1143
|
+
* already in flight, this latches the executor's one follow-up and settles
|
|
1144
|
+
* with that follow-up's outcome (the same computation over the current rows).
|
|
1145
|
+
* The run it settles with carries the reason 'initial', so it answers the
|
|
1146
|
+
* attempt the loader opened at mount.
|
|
1147
|
+
*/
|
|
1148
|
+
export function runWrunOverlayInitialComputeThroughExecutor(indicatorId) {
|
|
1149
|
+
const state = drivers.get(indicatorId);
|
|
1150
|
+
if (!state) {
|
|
1151
|
+
return Promise.reject(new WrunChartGoneError(`wrun overlay '${indicatorId}' has no registered driver`));
|
|
1152
|
+
}
|
|
1153
|
+
if (!state.driver.isMounted()) {
|
|
1154
|
+
teardownWrunOverlay(indicatorId);
|
|
1155
|
+
return Promise.reject(new WrunChartGoneError(`wrun overlay '${indicatorId}' is no longer on the chart`));
|
|
1156
|
+
}
|
|
1157
|
+
const outcome = new Promise((resolve, reject) => {
|
|
1158
|
+
state.outcomeTaps.push({ resolve, reject });
|
|
1159
|
+
});
|
|
1160
|
+
// The waiter's loader races this run against its own deadline: that is the one deadline now.
|
|
1161
|
+
clearWrunUnansweredDrop(state);
|
|
1162
|
+
const request = { reason: 'initial' };
|
|
1163
|
+
if (state.inFlight) {
|
|
1164
|
+
queueWrunRunRequest(indicatorId, state, request);
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
beginExecutorRun(indicatorId, state, request);
|
|
1168
|
+
}
|
|
1169
|
+
return outcome;
|
|
1170
|
+
}
|
|
1171
|
+
export function __resetWrunOverlayDriversForTests() {
|
|
1172
|
+
for (const state of drivers.values())
|
|
1173
|
+
clearWrunUnansweredDrop(state);
|
|
1174
|
+
drivers.clear();
|
|
1175
|
+
liveContexts.clear();
|
|
1176
|
+
liveGenerations.clear();
|
|
1177
|
+
sessionLocks.clear();
|
|
1178
|
+
// The teardown hooks are module registrations (the intake and the tick
|
|
1179
|
+
// register at import), never per-test state: they stay.
|
|
1180
|
+
}
|