@orangecharts/wrun-chart-host 0.1.0 → 0.3.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 +39 -6
- package/dist/constants/common.constants.d.ts +15 -0
- package/dist/constants/common.constants.js +23 -0
- package/dist/constants/data-source.constants.d.ts +1 -0
- package/dist/constants/data-source.constants.js +1 -0
- package/dist/constants/economic.constants.d.ts +39 -0
- package/dist/constants/economic.constants.js +77 -0
- package/dist/constants/etf-covered-coins.constants.d.ts +1 -0
- package/dist/constants/etf-covered-coins.constants.js +9 -0
- package/dist/constants/feature-flags.constants.d.ts +60 -0
- package/dist/constants/feature-flags.constants.js +308 -0
- package/dist/constants/feature-limits.constants.d.ts +134 -0
- package/dist/constants/feature-limits.constants.js +155 -0
- package/dist/constants/marketCapabilities.constants.d.ts +87 -0
- package/dist/constants/marketCapabilities.constants.js +213 -0
- package/dist/constants/option-venues.constants.d.ts +100 -0
- package/dist/constants/option-venues.constants.js +167 -0
- package/dist/constants/overlay-data.constants.d.ts +53 -0
- package/dist/constants/overlay-data.constants.js +80 -0
- package/dist/constants/pane-grid.constants.d.ts +15 -0
- package/dist/constants/pane-grid.constants.js +17 -0
- package/dist/constants/venue-presets.constants.d.ts +10 -0
- package/dist/constants/venue-presets.constants.js +22 -0
- package/dist/enums/chart.enum.d.ts +68 -0
- package/dist/enums/chart.enum.js +70 -0
- package/dist/helpers/data.helpers.d.ts +2 -0
- package/dist/helpers/data.helpers.js +14 -0
- package/dist/host-env.d.ts +161 -5
- package/dist/host-ports.types.d.ts +446 -0
- package/dist/host-ports.types.js +1 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +131 -0
- package/dist/indicators/controls/technical-script/technical-script-input-rendering.d.ts +86 -0
- package/dist/indicators/controls/technical-script/technical-script-input-rendering.js +179 -0
- package/dist/interfaces/asset-venue.interface.d.ts +91 -0
- package/dist/interfaces/asset-venue.interface.js +1 -0
- package/dist/interfaces/cancel-reason.interface.d.ts +24 -0
- package/dist/interfaces/cancel-reason.interface.js +2 -0
- package/dist/interfaces/catalog-display.interface.d.ts +3 -0
- package/dist/interfaces/catalog-display.interface.js +1 -0
- package/dist/interfaces/cme-realtime.interface.d.ts +251 -0
- package/dist/interfaces/cme-realtime.interface.js +46 -0
- package/dist/interfaces/feed.interface.d.ts +80 -0
- package/dist/interfaces/feed.interface.js +7 -0
- package/dist/interfaces/market-kind.interface.d.ts +8 -0
- package/dist/interfaces/market-kind.interface.js +1 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +224 -0
- package/dist/interfaces/opra-realtime.interface.js +105 -0
- package/dist/interfaces/option-instrument.interface.d.ts +32 -0
- package/dist/interfaces/option-instrument.interface.js +1 -0
- package/dist/interfaces/options-chain-scope.interface.d.ts +29 -0
- package/dist/interfaces/options-chain-scope.interface.js +7 -0
- package/dist/interfaces/prediction-market.interface.d.ts +88 -0
- package/dist/interfaces/prediction-market.interface.js +8 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +5 -0
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +185 -0
- package/dist/kscript-data/controls/live-trades-merge.util.js +357 -0
- package/dist/settings-templates/frvp-fields.d.ts +27 -0
- package/dist/settings-templates/frvp-fields.js +108 -0
- package/dist/settings-templates/index.d.ts +119 -0
- package/dist/settings-templates/index.js +442 -0
- package/dist/settings-templates/indicator-fields.d.ts +56 -0
- package/dist/settings-templates/indicator-fields.js +793 -0
- package/dist/settings-templates/tool-rules.d.ts +59 -0
- package/dist/settings-templates/tool-rules.js +49 -0
- package/dist/settings-templates/tool-tables.generated.d.ts +2 -0
- package/dist/settings-templates/tool-tables.generated.js +1668 -0
- package/dist/utility/blk-market.util.d.ts +5 -0
- package/dist/utility/blk-market.util.js +12 -0
- package/dist/utility/chart/chart-load-phase.util.d.ts +32 -0
- package/dist/utility/chart/chart-load-phase.util.js +78 -0
- package/dist/utility/chart/cme-cache-context.util.d.ts +108 -0
- package/dist/utility/chart/cme-cache-context.util.js +166 -0
- package/dist/utility/chart/cme-session-bucket.util.d.ts +82 -0
- package/dist/utility/chart/cme-session-bucket.util.js +343 -0
- package/dist/utility/chart/cme-trade-calendar.util.d.ts +26 -0
- package/dist/utility/chart/cme-trade-calendar.util.js +147 -0
- package/dist/utility/chart/continuous-contracts.util.d.ts +138 -0
- package/dist/utility/chart/continuous-contracts.util.js +374 -0
- package/dist/utility/chart/feed-interval.util.d.ts +119 -0
- package/dist/utility/chart/feed-interval.util.js +321 -0
- package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +110 -0
- package/dist/utility/chart/fetch-dedupe-policy.util.js +407 -0
- package/dist/utility/chart/footprint-band.util.d.ts +76 -0
- package/dist/utility/chart/footprint-band.util.js +205 -0
- package/dist/utility/chart/footprint-cell-identity.util.d.ts +82 -0
- package/dist/utility/chart/footprint-cell-identity.util.js +346 -0
- package/dist/utility/chart/formula-calendar.util.d.ts +27 -0
- package/dist/utility/chart/formula-calendar.util.js +59 -0
- package/dist/utility/chart/history-wall.util.d.ts +67 -0
- package/dist/utility/chart/history-wall.util.js +87 -0
- package/dist/utility/chart/index-mode.util.d.ts +66 -0
- package/dist/utility/chart/index-mode.util.js +360 -0
- package/dist/utility/chart/indicator-coverage-planner.util.d.ts +217 -0
- package/dist/utility/chart/indicator-coverage-planner.util.js +443 -0
- package/dist/utility/chart/indicator-coverage-state.util.d.ts +33 -0
- package/dist/utility/chart/indicator-coverage-state.util.js +110 -0
- package/dist/utility/chart/indicator-gap-detector.util.d.ts +127 -0
- package/dist/utility/chart/indicator-gap-detector.util.js +260 -0
- package/dist/utility/chart/indicator-gap-repair.util.d.ts +88 -0
- package/dist/utility/chart/indicator-gap-repair.util.js +177 -0
- package/dist/utility/chart/indicator-inflight-registry.util.d.ts +26 -0
- package/dist/utility/chart/indicator-inflight-registry.util.js +254 -0
- package/dist/utility/chart/interval-registry.util.d.ts +23 -0
- package/dist/utility/chart/interval-registry.util.js +83 -0
- package/dist/utility/chart/kscript-main-grid-stages.util.d.ts +21 -0
- package/dist/utility/chart/kscript-main-grid-stages.util.js +332 -0
- package/dist/utility/chart/legacy-exchange.leaf.d.ts +11 -0
- package/dist/utility/chart/legacy-exchange.leaf.js +43 -0
- package/dist/utility/chart/live-bucket.util.d.ts +66 -0
- package/dist/utility/chart/live-bucket.util.js +165 -0
- package/dist/utility/chart/market-session-schedule.util.d.ts +91 -0
- package/dist/utility/chart/market-session-schedule.util.js +337 -0
- package/dist/utility/chart/marketKind.util.d.ts +181 -0
- package/dist/utility/chart/marketKind.util.js +371 -0
- package/dist/utility/chart/om-panel.util.js +6 -0
- package/dist/utility/chart/om-widget.util.d.ts +4 -0
- package/dist/utility/chart/opra-read-access.leaf.d.ts +26 -0
- package/dist/utility/chart/opra-read-access.leaf.js +25 -0
- package/dist/utility/chart/prediction-identity.util.d.ts +159 -0
- package/dist/utility/chart/prediction-identity.util.js +236 -0
- package/dist/utility/chart/rth-session.util.d.ts +352 -0
- package/dist/utility/chart/rth-session.util.js +926 -0
- package/dist/utility/chart/titan-constants.pin.d.ts +43 -0
- package/dist/utility/chart/titan-constants.pin.js +50 -0
- package/dist/utility/chart/us-equities-session.util.d.ts +127 -0
- package/dist/utility/chart/us-equities-session.util.js +251 -0
- package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +100 -0
- package/dist/utility/chart/wrun-bar-session-facts.util.js +354 -0
- package/dist/utility/chart/wrun-run-result.util.js +10 -0
- package/dist/utility/chart/wrun-wire-ref.util.d.ts +23 -0
- package/dist/utility/chart/wrun-wire-ref.util.js +16 -0
- package/dist/utility/common/safe-math-eval.d.ts +18 -0
- package/dist/utility/common/safe-math-eval.js +160 -0
- package/dist/utility/common/time.util.d.ts +134 -0
- package/dist/utility/common/time.util.js +428 -0
- package/dist/utility/common/transformations.util.d.ts +126 -0
- package/dist/utility/common/transformations.util.js +711 -0
- package/dist/utility/common/visible-timeout.util.d.ts +17 -0
- package/dist/utility/common/visible-timeout.util.js +75 -0
- package/dist/utility/exchange-normalization.util.d.ts +8 -0
- package/dist/utility/exchange-normalization.util.js +32 -0
- package/dist/utility/intl-locale.util.d.ts +2 -0
- package/dist/utility/intl-locale.util.js +28 -0
- package/dist/utility/number-format.util.d.ts +14 -1
- package/dist/utility/number-format.util.js +50 -19
- package/dist/utility/options/option-symbol.util.d.ts +28 -0
- package/dist/utility/options/option-symbol.util.js +176 -0
- package/dist/utility/options/option-trade-units.util.d.ts +190 -0
- package/dist/utility/options/option-trade-units.util.js +283 -0
- package/dist/utility/options/option-venue.util.d.ts +75 -0
- package/dist/utility/options/option-venue.util.js +85 -0
- package/dist/utility/pool-symbol.leaf.d.ts +34 -0
- package/dist/utility/pool-symbol.leaf.js +95 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +109 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +302 -0
- package/dist/utility/symbol-selection/contract-expiry.util.d.ts +39 -0
- package/dist/utility/symbol-selection/contract-expiry.util.js +111 -0
- package/dist/utility/v2/gate-plane.util.d.ts +58 -0
- package/dist/utility/v2/gate-plane.util.js +99 -0
- package/dist/utility/v2/gate-session-latch.util.d.ts +22 -0
- package/dist/utility/v2/gate-session-latch.util.js +34 -0
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +76 -0
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +221 -0
- package/dist/utility/wrun/sources/host-grid-landing.d.ts +15 -0
- package/dist/utility/wrun/sources/host-grid-landing.js +26 -0
- package/dist/utility/wrun/sources/lanes/bitfinex_funding.d.ts +27 -0
- package/dist/utility/wrun/sources/lanes/bitfinex_funding.js +85 -0
- package/dist/utility/wrun/sources/lanes/economic.d.ts +27 -0
- package/dist/utility/wrun/sources/lanes/economic.js +79 -0
- package/dist/utility/wrun/sources/lanes/etf_holdings.d.ts +35 -0
- package/dist/utility/wrun/sources/lanes/etf_holdings.js +165 -0
- package/dist/utility/wrun/sources/lanes/etf_premium.d.ts +19 -0
- package/dist/utility/wrun/sources/lanes/etf_premium.js +114 -0
- package/dist/utility/wrun/sources/lanes/ethena_positions.d.ts +30 -0
- package/dist/utility/wrun/sources/lanes/ethena_positions.js +51 -0
- package/dist/utility/wrun/sources/lanes/index.d.ts +2 -0
- package/dist/utility/wrun/sources/lanes/index.js +32 -0
- package/dist/utility/wrun/sources/lanes/long_short_ratio.d.ts +17 -0
- package/dist/utility/wrun/sources/lanes/long_short_ratio.js +47 -0
- package/dist/utility/wrun/sources/lanes/option_daily.d.ts +30 -0
- package/dist/utility/wrun/sources/lanes/option_daily.js +53 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +23 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.js +20 -0
- package/dist/utility/wrun/sources/lanes/options_flow.d.ts +50 -0
- package/dist/utility/wrun/sources/lanes/options_flow.js +155 -0
- package/dist/utility/wrun/sources/lanes/options_oi.d.ts +29 -0
- package/dist/utility/wrun/sources/lanes/options_oi.js +59 -0
- package/dist/utility/wrun/sources/lanes/options_volume.d.ts +38 -0
- package/dist/utility/wrun/sources/lanes/options_volume.js +63 -0
- package/dist/utility/wrun/sources/lanes/series.d.ts +67 -0
- package/dist/utility/wrun/sources/lanes/series.js +321 -0
- package/dist/utility/wrun/sources/lanes/token_supply.d.ts +30 -0
- package/dist/utility/wrun/sources/lanes/token_supply.js +145 -0
- package/dist/utility/wrun/sources/lanes/treasury_balance.d.ts +25 -0
- package/dist/utility/wrun/sources/lanes/treasury_balance.js +47 -0
- package/dist/utility/wrun/sources/lanes/volatility_index.d.ts +21 -0
- package/dist/utility/wrun/sources/lanes/volatility_index.js +11 -0
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +196 -0
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +446 -0
- package/dist/utility/wrun/sources/registry.d.ts +21 -0
- package/dist/utility/wrun/sources/registry.js +207 -0
- package/dist/utility/wrun/sources/row-lane-registry.d.ts +28 -0
- package/dist/utility/wrun/sources/row-lane-registry.js +230 -0
- package/dist/utility/wrun/sources/row-lanes/index.d.ts +2 -0
- package/dist/utility/wrun/sources/row-lanes/index.js +12 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +2 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +38 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +6 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +70 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +4 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +191 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +13 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +137 -0
- package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +38 -0
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +150 -0
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +275 -0
- package/dist/utility/wrun/sources/wrun-poll-lane.types.js +26 -0
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +224 -0
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +394 -0
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +283 -0
- package/dist/utility/wrun/sources/wrun-row-lane.types.js +16 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +205 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +469 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +28 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.js +66 -0
- package/dist/utility/wrun/wrun-cloud-record.util.d.ts +65 -0
- package/dist/utility/wrun/wrun-cloud-record.util.js +121 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +1 -1
- package/dist/utility/wrun/wrun-daily-lane.util.d.ts +95 -0
- package/dist/utility/wrun/wrun-daily-lane.util.js +297 -0
- package/dist/utility/wrun/wrun-deadline.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-deadline.util.js +82 -0
- package/dist/utility/wrun/wrun-etf-flow-lane.util.d.ts +94 -0
- package/dist/utility/wrun/wrun-etf-flow-lane.util.js +224 -0
- package/dist/utility/wrun/wrun-etf-funds.util.d.ts +82 -0
- package/dist/utility/wrun/wrun-etf-funds.util.js +242 -0
- package/dist/utility/wrun/wrun-failure-cause.d.ts +39 -0
- package/dist/utility/wrun/wrun-failure-cause.js +94 -0
- package/dist/utility/wrun/wrun-frames.d.ts +28 -3
- package/dist/utility/wrun/wrun-frames.js +132 -52
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +167 -4
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +47 -2
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +5 -2
- package/dist/utility/wrun/wrun-hosted-wire.util.js +4 -2
- package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +22 -0
- package/dist/utility/wrun/wrun-lane-refusal.leaf.js +32 -0
- package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-lane-warmup.util.js +112 -0
- package/dist/utility/wrun/wrun-leg-close.util.d.ts +57 -0
- package/dist/utility/wrun/wrun-leg-close.util.js +187 -0
- package/dist/utility/wrun/wrun-leg-fetch.util.d.ts +144 -0
- package/dist/utility/wrun/wrun-leg-fetch.util.js +212 -0
- package/dist/utility/wrun/wrun-leg-stream-classes.d.ts +73 -0
- package/dist/utility/wrun/wrun-leg-stream-classes.js +86 -0
- package/dist/utility/wrun/wrun-levels-child.util.d.ts +101 -6
- package/dist/utility/wrun/wrun-levels-child.util.js +335 -157
- package/dist/utility/wrun/wrun-memory-clamp.util.d.ts +33 -0
- package/dist/utility/wrun/wrun-memory-clamp.util.js +146 -0
- package/dist/utility/wrun/wrun-odds-template-market.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-odds-template-market.util.js +251 -0
- package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +65 -0
- package/dist/utility/wrun/wrun-opra-flow.leaf.js +94 -0
- package/dist/utility/wrun/wrun-opra-lane.util.d.ts +47 -0
- package/dist/utility/wrun/wrun-opra-lane.util.js +58 -0
- package/dist/utility/wrun/wrun-opra-stats.leaf.d.ts +30 -0
- package/dist/utility/wrun/wrun-opra-stats.leaf.js +96 -0
- package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-opra-underlying.util.js +1 -0
- package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +142 -0
- package/dist/utility/wrun/wrun-option-contract-flow.util.js +451 -0
- package/dist/utility/wrun/wrun-option-knobs.util.d.ts +43 -0
- package/dist/utility/wrun/wrun-option-knobs.util.js +81 -0
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +144 -0
- package/dist/utility/wrun/wrun-option-prints.util.js +356 -0
- package/dist/utility/wrun/wrun-option-summary-lane.util.d.ts +102 -0
- package/dist/utility/wrun/wrun-option-summary-lane.util.js +143 -0
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +308 -0
- package/dist/utility/wrun/wrun-options-chain.util.js +502 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +9 -4
- package/dist/utility/wrun/wrun-overlay-identity.util.js +16 -6
- package/dist/utility/wrun/wrun-pack.util.d.ts +6 -2
- package/dist/utility/wrun/wrun-pack.util.js +13 -3
- package/dist/utility/wrun/wrun-param-map.util.d.ts +298 -0
- package/dist/utility/wrun/wrun-param-map.util.js +581 -0
- package/dist/utility/wrun/wrun-param-values.util.d.ts +8 -0
- package/dist/utility/wrun/wrun-param-values.util.js +8 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +149 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +523 -0
- package/dist/utility/wrun/wrun-pin-venues.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-pin-venues.util.js +320 -0
- package/dist/utility/wrun/wrun-pinned-interval.util.d.ts +20 -0
- package/dist/utility/wrun/wrun-pinned-interval.util.js +47 -0
- package/dist/utility/wrun/wrun-present-bits.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-present-bits.util.js +73 -0
- package/dist/utility/wrun/wrun-protocol-pending.util.d.ts +33 -0
- package/dist/utility/wrun/wrun-protocol-pending.util.js +57 -0
- package/dist/utility/wrun/wrun-refusal.util.d.ts +95 -7
- package/dist/utility/wrun/wrun-refusal.util.js +314 -18
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +1 -14
- package/dist/utility/wrun/wrun-registry-errors.util.js +0 -16
- package/dist/utility/wrun/wrun-render-select.util.js +1 -0
- package/dist/utility/wrun/wrun-row-market.util.d.ts +29 -0
- package/dist/utility/wrun/wrun-row-market.util.js +92 -0
- package/dist/utility/wrun/wrun-row-source.d.ts +158 -0
- package/dist/utility/wrun/wrun-row-source.js +75 -0
- package/dist/utility/wrun/wrun-run-health.util.d.ts +155 -0
- package/dist/utility/wrun/wrun-run-health.util.js +273 -0
- package/dist/utility/wrun/wrun-socket-row-source.d.ts +439 -0
- package/dist/utility/wrun/wrun-socket-row-source.js +1689 -0
- package/dist/utility/wrun/wrun-socket-session-losses.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-socket-session-losses.util.js +25 -0
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +911 -0
- package/dist/utility/wrun/wrun-source-rows.util.js +2597 -0
- package/dist/utility/wrun/wrun-symbol-code.util.d.ts +32 -0
- package/dist/utility/wrun/wrun-symbol-code.util.js +56 -0
- package/dist/utility/wrun/wrun-tape-source.util.d.ts +82 -0
- package/dist/utility/wrun/wrun-tape-source.util.js +151 -0
- package/dist/utility/wrun/wrun-tier-grid.util.d.ts +137 -0
- package/dist/utility/wrun/wrun-tier-grid.util.js +279 -0
- package/dist/utility/wrun/wrun-trades-lane.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-trades-lane.util.js +58 -0
- package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +41 -0
- package/dist/utility/wrun/wrun-volume-profile-lane.util.js +66 -0
- package/dist/utility/wrun-display-name.util.d.ts +33 -0
- package/dist/utility/wrun-display-name.util.js +64 -0
- package/dist/workers/constants/kscript-transport-codes.d.ts +15 -0
- package/dist/workers/constants/kscript-transport-codes.js +15 -0
- package/dist/workers/constants/socket-slots.d.ts +574 -0
- package/dist/workers/constants/socket-slots.js +539 -0
- package/dist/workers/utils/number.worker.util.d.ts +5 -0
- package/dist/workers/utils/number.worker.util.js +10 -0
- package/dist/workers/utils/time.worker.util.d.ts +12 -0
- package/dist/workers/utils/time.worker.util.js +24 -0
- package/dist/workers/utils/volume-profile.worker.util.d.ts +200 -0
- package/dist/workers/utils/volume-profile.worker.util.js +631 -0
- package/package.json +10 -4
|
@@ -0,0 +1,1689 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cloud lane's row source (WRUN-PARITY-PLAN contract C7, unit U14; plan rows 8, 10 and 18): a
|
|
3
|
+
* Protected wrun package's rows, cell grids, frames, handles and refusals, answered by kscript-backend
|
|
4
|
+
* over the kScript socket on the hosted wire (`wrunHost`, docs/features/kscript/wrun/wrun-browser-runtime.md)
|
|
5
|
+
* and merged by the socket row store (`wrun-socket-row-store.ts`), in the one `WrunRowBatch` shape the
|
|
6
|
+
* browser lane's sandbox source answers. The own run's pass asks a source for rows and never knows
|
|
7
|
+
* which: the lane is read once, by whoever constructs the source (the factory, from the record's
|
|
8
|
+
* `wrunRunTarget`), never by this module and never by the pass.
|
|
9
|
+
*
|
|
10
|
+
* A thin client: the kScript socket worker keeps the transport (the capability mint, the settings
|
|
11
|
+
* record or the numeric map by the hello's server caps, `changeSettings`, retire and recreate, the
|
|
12
|
+
* session sweep), and the default transport (the web half, `wrun-socket-transport.ts`) only builds the
|
|
13
|
+
* protected payload through the one builder (`TechnicalScriptControl.getReqPayload`), ensures the run
|
|
14
|
+
* capability through the one bridge, dispatches through the V2 fetch and ends the session through the one
|
|
15
|
+
* helper. Specs hand in a fake.
|
|
16
|
+
*
|
|
17
|
+
* - `create` asks the newest page of the window with the settings record (C4) and answers the first
|
|
18
|
+
* batch from the hosted wire reader. `range` pages the rest (plan Q3, decided 10-12: pan-back history
|
|
19
|
+
* as deep as the browser lane's, paged; no session cap, no refusal by a start's distance from now):
|
|
20
|
+
* the coverage planner (`planIndicatorCoverage`, trigger `wave-dispatch`) decides what is missing
|
|
21
|
+
* against the chart's bars, the windows the cloud answered are authoritative, every page goes through
|
|
22
|
+
* the in-flight registry the planner's executors share (`scheduleIndicatorInflightFetch`, never a
|
|
23
|
+
* registry of its own) under the policy the dedupe table names, and the source pages until the
|
|
24
|
+
* planner's coverage says done (`planWrunSocketPages`, pinned by
|
|
25
|
+
* `src/utility/wrun/__fixtures__/lane-parity/socket-window.json` before this code).
|
|
26
|
+
* - `changeSettings` sends the C5 patch over the session's newest page (never an interval, never a
|
|
27
|
+
* recreate), answers on the result seam, then pages the rest of what the session covered with the
|
|
28
|
+
* new settings; a refused patch keeps the session the cloud rolled back to. Once the cloud answered
|
|
29
|
+
* the patch the source computes with it for good: a page of the rest refused or failed fails the call
|
|
30
|
+
* marked `moved` (`markWrunRowSourceSettingsLeft`), and the session owes that window to its next ask.
|
|
31
|
+
* A patch the worker's request deadline met is marked `unanswered`: the source keeps the settings and
|
|
32
|
+
* the rows it held, under their own generation, so no live frame extends them.
|
|
33
|
+
* - `frames` streams the live frames, merged in arrival order with the results, as batches of the
|
|
34
|
+
* bars that moved; the pass queues them per session (`queueWrunSourceLiveFrame`) and the live tick's
|
|
35
|
+
* drain, on the browser twin's cadence, integrates every frame folded since the last drain as one
|
|
36
|
+
* tail (`integrateWrunOverlayLiveFrame`, wrun-live-tick.util: the build memo, the tail patch, the
|
|
37
|
+
* measure around the apply).
|
|
38
|
+
* - Historical mode: a session created while its chart replays runs with no live feed (the worker keys
|
|
39
|
+
* sessions on it), its pages bypass the in-flight registry (the dedupe table's replay-lane bypass),
|
|
40
|
+
* and the replay lane steps it through `range` (wrun-replay-lane.util), so a Protected heatmap mounts
|
|
41
|
+
* its canvas up to the playhead.
|
|
42
|
+
* - Load status rides the own run's signals (data-loading rule 2: raise, never set the visible state):
|
|
43
|
+
* the legend loader and the store's kScript loading flag through the loading owner
|
|
44
|
+
* (`wrun-loading-owner.util`), whose watchdog derives the "Still loading" and "Loading stopped"
|
|
45
|
+
* chips. Every raise is lowered on success, refusal, failure, abort and timeout alike (rule 3), and
|
|
46
|
+
* `teardown` lowers whatever is still up.
|
|
47
|
+
* - The `renderBytes` charge: the cloud's shaper charged it (`shapeWrunResult` on `chart-cloud`)
|
|
48
|
+
* before the wire; the source never charges a batch twice.
|
|
49
|
+
* - Refusals are the kit's codes (`{ family, code }`), never a sentence: a family the cloud left out
|
|
50
|
+
* rides the batch as the wire carried it, and a refused ask answers one refusal for the whole run
|
|
51
|
+
* (family `WRUN_SOCKET_RUN_REFUSAL_FAMILY`) with the code the error frame's `details.wrunRefusal`
|
|
52
|
+
* named (relayed by the socket worker, wrun-hosted-wire-caps `wrunFrameRefusalOf`; the code an older
|
|
53
|
+
* server's sentence leads with is the only fallback) and the facts it carried, the refused ask kept
|
|
54
|
+
* by its entry (`wrunSocketRunRefusalOf`).
|
|
55
|
+
* - The legacy pre-styled path: a reply without the hosted wire (a server answering a cloud record
|
|
56
|
+
* flat) is never read: it answers the whole-run refusal `WRUN_LEGACY_RESULT_CODE`, whose record's
|
|
57
|
+
* way out reloads the app (WRUN-PARITY-PLAN row 22), the one retract kept until the backend floor
|
|
58
|
+
* deletes the legacy path.
|
|
59
|
+
* - Every failed ask reads through one seam (`wrunSocketAskFailure`): a refusal the worker keeps for good
|
|
60
|
+
* carries its code, the facts its frame named and the frame as its details (the record reads the code,
|
|
61
|
+
* wrun-refusal.util `wrunCloudRefusalSeed`), a permission mint that did not land within the transient grace and the
|
|
62
|
+
* worker's request deadline are transient, and a denied capability holds the run behind the access door's "Access
|
|
63
|
+
* required" chip (a capability the cloud denied first heals once, as the protected fetch's does: one
|
|
64
|
+
* forced re-mint, one re-dispatch).
|
|
65
|
+
* - The run-level keys beside the wire ride every batch (`WrunRowBatch.strategy`, `.diagnostics`): a
|
|
66
|
+
* strategy package's `StrategyOutput` exactly as the reply carries it (the newest one the session's
|
|
67
|
+
* replies carried), and the reply's diagnostics normalized as the protected fetch normalizes them; a
|
|
68
|
+
* live frame carries the keys its own output carries.
|
|
69
|
+
* - The legs the cloud served from the history wall (`wrunServedLegs`, on create and range replies only):
|
|
70
|
+
* one `WRUN_LEG_HISTORY_CLAMPED` warning row per leg, the browser lane's row (`wrunClampedLegDiagnostics`)
|
|
71
|
+
* with the cloud's note as its message, kept apart from the execution diagnostics and composed after them
|
|
72
|
+
* into every list a batch or a live frame carries, so a frame's list (an empty one on every tick) never
|
|
73
|
+
* drops them. A create's or a settings change's reply replaces the set, a page's merges its own into it by
|
|
74
|
+
* fetch key, a reply without the key keeps it.
|
|
75
|
+
* - A reply the store did not merge is never an empty success: no reply (the V2 fetch launders a kick,
|
|
76
|
+
* a socket that is not open or a failed worker into a clean completion) rejects as transient
|
|
77
|
+
* (`WrunRowSourceTransientError`, the pass's retry path), the worker's superseded marker as a
|
|
78
|
+
* superseded stop, an unreadable wire as `WrunSocketReplyUnreadable`; a session the store held stands
|
|
79
|
+
* until a reply merged.
|
|
80
|
+
* - The one extra ask (wrun-browser-runtime.md "The one extra ask"): the socket worker names the fact
|
|
81
|
+
* lists a refused ask lacked (`KScriptMessages.WRUN_FACTS_NEEDED`, which the WorkerManager routes to
|
|
82
|
+
* `routeWrunSocketFactsNeeded`); they are remembered for the overlay, and once the market directory
|
|
83
|
+
* answers them the refused ask goes again, once per overlay and fact set: the ask still waiting asks
|
|
84
|
+
* again itself (a create as a recreate, a page through the range), else the overlay reruns through
|
|
85
|
+
* the lifecycle door.
|
|
86
|
+
*
|
|
87
|
+
* This module joins no boot graph: the factory loads it with `await import`, beside its web half
|
|
88
|
+
* (`wrun-socket-transport.ts`: the default transport, the load signals, the mounted chart's rows, the
|
|
89
|
+
* live route and the run capability's release), whose heavy dependencies (the store, the chart engine,
|
|
90
|
+
* the V2 fetch, the capability bridge) load inside the default transport and load signals only. The
|
|
91
|
+
* source reaches the host through the chart-host env, read at call time (`wrunChartHostEnv()`): the web
|
|
92
|
+
* half binds its five ports as it loads (`transport.hostedSocket`, `chart.hostedLoadSignals`,
|
|
93
|
+
* `chart.mainRows` and the two error predicates), the boot binder the replay flag and the loaders.
|
|
94
|
+
*/
|
|
95
|
+
import { wrunChartHostEnv } from '../../host-env.js';
|
|
96
|
+
import { resolveFetchDedupePolicy } from '../chart/fetch-dedupe-policy.util.js';
|
|
97
|
+
import { planIndicatorCoverage, sliceSortedRowsToSpanWithFlags, subtractSpansFromGap, } from '../chart/indicator-coverage-planner.util.js';
|
|
98
|
+
import { clearIndicatorInflight, scheduleIndicatorInflightFetch, } from '../chart/indicator-inflight-registry.util.js';
|
|
99
|
+
import { readWrunWireRef } from '../chart/wrun-wire-ref.util.js';
|
|
100
|
+
import { wrunSocketPayloadSettings } from './wrun-cloud-record.util.js';
|
|
101
|
+
import { wrunErrorFrameCodeOf, wrunForeignSupersedeOf, wrunFrameRefusalOf, wrunServerAnswerOfText, } from './wrun-hosted-wire-caps.js';
|
|
102
|
+
import { readWrunHostedRunLevel, readWrunHostedWire, } from './wrun-hosted-wire.util.js';
|
|
103
|
+
import { WRUN_LANE_WARMUP_LOOKBACK_CAP, wrunLaneWarmupBars } from './wrun-lane-warmup.util.js';
|
|
104
|
+
import { wrunClampedLegDiagnostics } from './wrun-leg-fetch.util.js';
|
|
105
|
+
import { wrunParamValuesFromSettings } from './wrun-param-values.util.js';
|
|
106
|
+
import { attachWrunRefusal, stampWrunRefusalTelemetry, WRUN_LEGACY_RESULT_CODE, WRUN_SESSION_LOST_CODE, wrunRefusalSeedOf, } from './wrun-refusal.util.js';
|
|
107
|
+
import { isWrunOverlayPausedError, WrunChartGoneError, WrunOverlayPausedError } from './wrun-registry-errors.util.js';
|
|
108
|
+
import { isWrunRowSourceTransientError, markWrunRowSourceSettingsLeft, WrunRowSourceTransientError, } from './wrun-row-source.js';
|
|
109
|
+
import { mergeWrunHostedReply, WRUN_SOCKET_ROW_STORE_UNCAPPED, wrunCellRowsFromHostedLanes, wrunHostedGridKey, wrunHostedGridLaneRowCount, wrunHostedGridLaneRows, } from './wrun-socket-row-store.js';
|
|
110
|
+
import { wrunSocketSessionLossCount } from './wrun-socket-session-losses.util.js';
|
|
111
|
+
import { KSCRIPT_CAPABILITY_UNAVAILABLE, KSCRIPT_TRANSPORT_DIAL_FAILED, KSCRIPT_TRANSPORT_DISCONNECTED, KSCRIPT_TRANSPORT_STALE, KSCRIPT_WORKER_RESTARTED, } from '../../workers/constants/kscript-transport-codes.js';
|
|
112
|
+
/** The most bars one socket ask carries: the cloud's per-request cap (kscript-backend `MAX_BARS`, 900
|
|
113
|
+
* bars per createScript or rangeChanged). Plan Q3 keeps the pages and drops every other cap; phase B
|
|
114
|
+
* (U9a, U9b) moves this number to the `chart-cloud` profile's `caps.barsPerRequest`. */
|
|
115
|
+
export const WRUN_SOCKET_PAGE_BARS = 900;
|
|
116
|
+
/** The family a refused ask names when its refusal names none: the whole run. */
|
|
117
|
+
export const WRUN_SOCKET_RUN_REFUSAL_FAMILY = '*';
|
|
118
|
+
/** The overlay id the page planner's snapshot names (its plain kind reads no per-overlay state). */
|
|
119
|
+
const COVERAGE_OVERLAY_ID = 'wrun-socket-row-source';
|
|
120
|
+
/** The superseded marker the protected worker control answers a dropped ask with (its own constant). */
|
|
121
|
+
const SUPERSEDED_OUTPUT_KEY = '__kiyoProtectedKScriptSuperseded';
|
|
122
|
+
// ── Errors ───────────────────────────────────────────────────────────────────────────────────────
|
|
123
|
+
/** A refused ask: the cloud answered a refusal code for it, with the facts its frame carried (`wrunSocketAskFailure`
|
|
124
|
+
* keeps the frame as its message). The source answers it as a refusal batch; the refusal record reads its code and
|
|
125
|
+
* facts (wrun-refusal.util `wrunCloudRefusalSeed`). */
|
|
126
|
+
export class WrunSocketRefusalError extends Error {
|
|
127
|
+
code;
|
|
128
|
+
family;
|
|
129
|
+
facts;
|
|
130
|
+
constructor(code, family, facts) {
|
|
131
|
+
super(code);
|
|
132
|
+
this.name = 'WrunSocketRefusalError';
|
|
133
|
+
this.code = code;
|
|
134
|
+
if (family !== undefined)
|
|
135
|
+
this.family = family;
|
|
136
|
+
if (facts !== undefined && Object.keys(facts).length > 0)
|
|
137
|
+
this.facts = facts;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** The refused ask each whole-run entry of a batch stands for (its code, the facts its frame carried and its frame), by
|
|
141
|
+
* entry: the batch keeps the wire's `{ family, code }` shape, and the row-source factory rejects with the very
|
|
142
|
+
* refusal. */
|
|
143
|
+
const runRefusals = new WeakMap();
|
|
144
|
+
/** The refusal a batch's whole-run entry stands for: its ask's own (the facts and the frame kept), else one of the
|
|
145
|
+
* entry's code. */
|
|
146
|
+
export function wrunSocketRunRefusalOf(entry) {
|
|
147
|
+
return runRefusals.get(entry) ?? new WrunSocketRefusalError(entry.code ?? 'wrun_refused');
|
|
148
|
+
}
|
|
149
|
+
/** The facts a batch's refusal entry carried, when it was a whole-run refusal that named any. */
|
|
150
|
+
export function wrunSocketRefusalFactsOf(refusal) {
|
|
151
|
+
return runRefusals.get(refusal)?.facts;
|
|
152
|
+
}
|
|
153
|
+
/** A denied run capability (the overlay's access ended): the bridge denied the mint, or the cloud denied the ask past
|
|
154
|
+
* the transport's one forced re-mint. The overlay carries the "Access required" chip through the one access door
|
|
155
|
+
* (useIndicatorAccessPrompt, the chip a revoked cloud run and a browser run whose access ended carry), and the run is
|
|
156
|
+
* held quietly, of the paused class (no refusal record words it, nothing toasts, the heal declines it). Access back
|
|
157
|
+
* (a purchase, a grant) mints again on the next run. */
|
|
158
|
+
export class WrunSocketAccessDeniedError extends WrunOverlayPausedError {
|
|
159
|
+
/** Whether the denied ask was dispatched: the cloud denied it, or the worker refused a frame that carried no
|
|
160
|
+
* capability after it ended the session a create replaces, so a create replaced the overlay's session. False when
|
|
161
|
+
* the bridge denied the mint: nothing was sent. */
|
|
162
|
+
dispatched;
|
|
163
|
+
constructor(message, dispatched = false) {
|
|
164
|
+
super('paused');
|
|
165
|
+
this.name = 'WrunSocketAccessDeniedError';
|
|
166
|
+
this.message = message;
|
|
167
|
+
this.dispatched = dispatched;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** An ask that stopped without an answer: a newer create or settings change superseded it, or the
|
|
171
|
+
* source was torn down. Its load signals are already lowered. The default transport rejects with it a
|
|
172
|
+
* create stopped after it went (`WrunSocketAsk.signal`): the worker opened that session all the same. */
|
|
173
|
+
export class WrunSocketRowSourceStopped extends Error {
|
|
174
|
+
reason;
|
|
175
|
+
constructor(reason) {
|
|
176
|
+
super(`wrun socket row source ask ${reason}`);
|
|
177
|
+
this.name = 'WrunSocketRowSourceStopped';
|
|
178
|
+
this.reason = reason;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** A reply the source cannot merge: an unreadable wire, or one the store refused. A failure, never a
|
|
182
|
+
* refusal: the next ask may answer. (A reply with no hosted wire at all is the legacy refusal.) */
|
|
183
|
+
export class WrunSocketReplyUnreadable extends Error {
|
|
184
|
+
constructor(reason) {
|
|
185
|
+
super(`wrun socket reply unreadable: ${reason}`);
|
|
186
|
+
this.name = 'WrunSocketReplyUnreadable';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The cloud's warm-up head for a record (wrun-lane-warmup.util: the kit planner's rule over the run's param values),
|
|
191
|
+
* clamped to the `chart-cloud` profile's cap once the shared host is loaded, else to the lookback cap: on a
|
|
192
|
+
* cloud-only chart the host may never load, and an uncapped head only re-asks more bars than the cloud ran.
|
|
193
|
+
*/
|
|
194
|
+
export function wrunSocketWarmupBars(record) {
|
|
195
|
+
let cap = WRUN_LANE_WARMUP_LOOKBACK_CAP;
|
|
196
|
+
try {
|
|
197
|
+
cap = wrunChartHostEnv().sharedHost().WRUN_HOST_PROFILES['chart-cloud'].caps.warmupBars;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// not loaded: the lookback cap
|
|
201
|
+
}
|
|
202
|
+
return wrunLaneWarmupBars(record.sheet, wrunParamValuesFromSettings(record.sheet, record.settings), cap);
|
|
203
|
+
}
|
|
204
|
+
/** A row the cloud answered cold: no outputs, or every output NaN (a cell-only row has none and is warm). */
|
|
205
|
+
function isWrunColdRow(row) {
|
|
206
|
+
return row.outputs === null || (row.outputs.length > 0 && row.outputs.every((value) => !Number.isFinite(value)));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The leading cold rows of every answered window, as windows (window policy rule 4): from the window's first held
|
|
210
|
+
* row while the rows stay cold, at most `headBars` rows. A window whose first row is warm yields nothing.
|
|
211
|
+
*/
|
|
212
|
+
export function wrunSocketColdHeads(rows, answered, headBars) {
|
|
213
|
+
const heads = [];
|
|
214
|
+
const cap = Math.max(0, Math.floor(headBars));
|
|
215
|
+
if (cap === 0 || rows.length === 0)
|
|
216
|
+
return heads;
|
|
217
|
+
for (const span of answered) {
|
|
218
|
+
let at = rows.findIndex((row) => row.ts >= span.fromMs);
|
|
219
|
+
if (at < 0 || rows[at].ts > span.toMs)
|
|
220
|
+
continue;
|
|
221
|
+
let last;
|
|
222
|
+
let count = 0;
|
|
223
|
+
while (at < rows.length && rows[at].ts <= span.toMs && count < cap && isWrunColdRow(rows[at])) {
|
|
224
|
+
last = rows[at].ts;
|
|
225
|
+
count += 1;
|
|
226
|
+
at += 1;
|
|
227
|
+
}
|
|
228
|
+
if (last !== undefined)
|
|
229
|
+
heads.push({ fromMs: span.fromMs, toMs: last });
|
|
230
|
+
}
|
|
231
|
+
return heads;
|
|
232
|
+
}
|
|
233
|
+
// ── The window policy (plan Q3), pure ──────────────────────────────────────────────────────────
|
|
234
|
+
/** The newest page of a window: what a create asks. */
|
|
235
|
+
export function newestWrunSocketPage(window, intervalMs, pageBars) {
|
|
236
|
+
return { fromMs: Math.max(window.fromMs, window.toMs - (pageBars - 1) * intervalMs), toMs: window.toMs };
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The pages a window still needs (plan Q3, pinned by the socket-window golden):
|
|
240
|
+
*
|
|
241
|
+
* 1. Missing spans: with two or more chart bars inside the window, the coverage planner's
|
|
242
|
+
* `wave-dispatch` plan for a plain overlay holding the store's bars (the repair detector against
|
|
243
|
+
* the chart's bars; at most two ranges a round, the rest filtered `overlay-cap` for the next
|
|
244
|
+
* round), with the cloud's answered windows as authoritative-empty spans (a span answered with no
|
|
245
|
+
* rows is never asked again). With fewer, the wave's degenerate-clip rule: the whole window.
|
|
246
|
+
* 2. Each span less the answered windows, less a held bar at either end (no bar is asked twice, but for rule 4).
|
|
247
|
+
* 3. Pages of at most `pageBars` bars, newest first across every span (pan-back continuity).
|
|
248
|
+
* 4. A span that adjoins a newer answered window (no chart bar between them) re-asks that window's leading cold
|
|
249
|
+
* rows (`reask`: the rows it answered with no output or every output NaN, at most the cloud's warm-up head,
|
|
250
|
+
* `wrunSocketColdHeads`). The cloud runs every window with the planner's head, so a package whose real warm-up
|
|
251
|
+
* outruns it (a displaced span, an internal lag) answered the window's first bars cold; only a run that starts
|
|
252
|
+
* earlier computes them warm, and the page's reply splices over them (store rule 2). The newest page carries
|
|
253
|
+
* the overlap, still at most `pageBars` bars; a window answered warm is never asked twice.
|
|
254
|
+
*
|
|
255
|
+
* No cap on the depth and no rule on a start's distance from now: the cloud's caps live in its profile.
|
|
256
|
+
*/
|
|
257
|
+
export function planWrunSocketPages(input) {
|
|
258
|
+
const { window, intervalMs, pageBars } = input;
|
|
259
|
+
const answered = mergeWrunSocketSpans(input.answered, intervalMs);
|
|
260
|
+
const heldInWindow = input.heldTs.filter((ts) => ts >= window.fromMs && ts <= window.toMs);
|
|
261
|
+
const chart = sliceSortedRowsToSpanWithFlags((input.chartRows ?? []), input.chartSyntheticFlags, window.fromMs, window.toMs);
|
|
262
|
+
const filtered = [];
|
|
263
|
+
let spans;
|
|
264
|
+
if (chart.rows.length >= 2) {
|
|
265
|
+
const plan = planIndicatorCoverage({
|
|
266
|
+
chartIndex: 0,
|
|
267
|
+
datasetKey: null,
|
|
268
|
+
intervalMs,
|
|
269
|
+
mainRows: chart.rows,
|
|
270
|
+
...(chart.flags !== undefined ? { mainSyntheticFlags: chart.flags } : {}),
|
|
271
|
+
overlays: [
|
|
272
|
+
{
|
|
273
|
+
overlayId: COVERAGE_OVERLAY_ID,
|
|
274
|
+
kind: 'plain',
|
|
275
|
+
rows: heldInWindow.map((ts) => [ts]),
|
|
276
|
+
authoritativeEmptySpans: answered,
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
}, 'wave-dispatch');
|
|
280
|
+
spans = plan.requests.map((request) => request.range);
|
|
281
|
+
for (const entry of plan.filtered) {
|
|
282
|
+
filtered.push({ fromMs: entry.gap.fromMs, toMs: entry.gap.toMs, reason: entry.reason });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
spans = [{ fromMs: window.fromMs, toMs: window.toMs }];
|
|
287
|
+
}
|
|
288
|
+
const held = new Set(heldInWindow);
|
|
289
|
+
const pieces = [];
|
|
290
|
+
for (const span of spans) {
|
|
291
|
+
for (const piece of subtractSpansFromGap(span, answered).kept) {
|
|
292
|
+
const fromMs = Math.max(window.fromMs, held.has(piece.fromMs) ? piece.fromMs + intervalMs : piece.fromMs);
|
|
293
|
+
const toMs = Math.min(window.toMs, held.has(piece.toMs) ? piece.toMs - intervalMs : piece.toMs);
|
|
294
|
+
if (fromMs <= toMs)
|
|
295
|
+
pieces.push({ fromMs, toMs });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
pieces.sort((a, b) => b.toMs - a.toMs);
|
|
299
|
+
const reask = input.reask ?? [];
|
|
300
|
+
if (reask.length > 0) {
|
|
301
|
+
const barTs = chart.rows.map((row) => row[0]);
|
|
302
|
+
const onGrid = barTs.length >= 2;
|
|
303
|
+
for (const piece of pieces) {
|
|
304
|
+
// At or after the piece's end: a piece reaches an answered window's first bar when that bar holds no row.
|
|
305
|
+
const newer = answered.find((span) => span.fromMs >= piece.toMs);
|
|
306
|
+
const cold = newer === undefined ? undefined : reask.find((span) => span.fromMs === newer.fromMs);
|
|
307
|
+
if (newer === undefined || cold === undefined)
|
|
308
|
+
continue;
|
|
309
|
+
const apart = onGrid
|
|
310
|
+
? barTs.some((ts) => ts > piece.toMs && ts < newer.fromMs)
|
|
311
|
+
: newer.fromMs - piece.toMs > intervalMs;
|
|
312
|
+
if (apart)
|
|
313
|
+
continue;
|
|
314
|
+
piece.toMs = Math.min(window.toMs, newer.toMs, Math.max(piece.toMs, cold.toMs));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const pages = [];
|
|
318
|
+
for (const piece of pieces) {
|
|
319
|
+
for (let toMs = piece.toMs; toMs >= piece.fromMs;) {
|
|
320
|
+
const fromMs = Math.max(piece.fromMs, toMs - (pageBars - 1) * intervalMs);
|
|
321
|
+
pages.push({ fromMs, toMs });
|
|
322
|
+
toMs = fromMs - intervalMs;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return { pages, filtered };
|
|
326
|
+
}
|
|
327
|
+
/** Answered windows as disjoint ascending spans: windows that overlap or touch (the next one opens
|
|
328
|
+
* within one interval of the last bar) join. */
|
|
329
|
+
export function mergeWrunSocketSpans(spans, intervalMs) {
|
|
330
|
+
const sorted = spans
|
|
331
|
+
.filter((span) => Number.isFinite(span.fromMs) && Number.isFinite(span.toMs) && span.fromMs <= span.toMs)
|
|
332
|
+
.map((span) => ({ fromMs: span.fromMs, toMs: span.toMs }))
|
|
333
|
+
.sort((a, b) => a.fromMs - b.fromMs);
|
|
334
|
+
const merged = [];
|
|
335
|
+
for (const span of sorted) {
|
|
336
|
+
const last = merged[merged.length - 1];
|
|
337
|
+
if (last !== undefined && span.fromMs <= last.toMs + intervalMs)
|
|
338
|
+
last.toMs = Math.max(last.toMs, span.toMs);
|
|
339
|
+
else
|
|
340
|
+
merged.push(span);
|
|
341
|
+
}
|
|
342
|
+
return merged;
|
|
343
|
+
}
|
|
344
|
+
/** The dedupe table's policy for the source's page asks: a live session's pages coalesce through the
|
|
345
|
+
* in-flight registry (`IND_SKIP_DUPLICATE`: a covering ask in flight is awaited, never sent twice); a
|
|
346
|
+
* replay lane's bypass it (`IND_REPLAY_LANE_BYPASS`: a replay ask must neither join nor poison the
|
|
347
|
+
* live overlay's entry). */
|
|
348
|
+
export function wrunSocketPagePolicy(historical) {
|
|
349
|
+
return resolveFetchDedupePolicy(historical ? { lane: 'indicator', isReplayBuffer: true } : { lane: 'indicator' });
|
|
350
|
+
}
|
|
351
|
+
/** The sources following each overlay's cloud session (`<chartIndex>:<indicatorId>`): a facts-needed note
|
|
352
|
+
* reaches the ask they have waiting. */
|
|
353
|
+
const factsFollowers = new Map();
|
|
354
|
+
/** The fact set each overlay was asked again for (`<chartIndex>:<indicatorId>`): once per overlay and set. */
|
|
355
|
+
const factsAskedAgain = new Map();
|
|
356
|
+
function overlayKeyOf(identity) {
|
|
357
|
+
return `${identity.chartIndex}:${identity.indicatorId}`;
|
|
358
|
+
}
|
|
359
|
+
/** The superseded marker the worker answers a dropped ask with (a sweep, a caps-outdated hello, a stale create). */
|
|
360
|
+
function isSupersededReply(output) {
|
|
361
|
+
return (typeof output === 'object' && output !== null && Boolean(output[SUPERSEDED_OUTPUT_KEY]));
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The refusal a superseded marker stands for when it carries a foreign supersede (wrun-hosted-wire-caps
|
|
365
|
+
* `wrunForeignSupersedeOf`: the server superseded the overlay's LIVE create, so another chart or tab created its
|
|
366
|
+
* instance id): the whole-run `WRUN_SESSION_LOST_CODE` refusal, whose record is the retryable `session-lost` note,
|
|
367
|
+
* never a superseded stop (the run would end silently on a session the cloud no longer holds) and never the generic
|
|
368
|
+
* words. The frame is its message (the record's details); it is stamped a foreign supersede for the monitoring join.
|
|
369
|
+
* Undefined for any other reply. WRUN-REPORTS-CLASSES C1.
|
|
370
|
+
*/
|
|
371
|
+
export function wrunSessionLostRefusalOf(output) {
|
|
372
|
+
if (!isSupersededReply(output))
|
|
373
|
+
return undefined;
|
|
374
|
+
const foreign = wrunForeignSupersedeOf(output);
|
|
375
|
+
if (foreign === undefined)
|
|
376
|
+
return undefined;
|
|
377
|
+
const refusal = new WrunSocketRefusalError(WRUN_SESSION_LOST_CODE);
|
|
378
|
+
refusal.message = `KScript error: ${foreign.code !== undefined ? `[${foreign.code}] ` : ''}${foreign.message ?? WRUN_SESSION_LOST_CODE}`;
|
|
379
|
+
return stampWrunRefusalTelemetry(refusal, {
|
|
380
|
+
foreignSupersede: true,
|
|
381
|
+
...(foreign.clientRequestId !== undefined ? { clientRequestId: foreign.clientRequestId } : {}),
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
/** A reply's skipped elements as it carries them (run-level keys beside the wire, or inside `wrunHost`): the list
|
|
385
|
+
* only when it is an array, the count only when it is a finite number; none when the reply names neither. */
|
|
386
|
+
function wrunSocketSkippedOf(output) {
|
|
387
|
+
if (typeof output !== 'object' || output === null)
|
|
388
|
+
return undefined;
|
|
389
|
+
const top = output;
|
|
390
|
+
const wire = top.wrunHost;
|
|
391
|
+
const holder = Object.hasOwn(top, 'skipped') || Object.hasOwn(top, 'skippedCount')
|
|
392
|
+
? top
|
|
393
|
+
: typeof wire === 'object' && wire !== null
|
|
394
|
+
? wire
|
|
395
|
+
: undefined;
|
|
396
|
+
if (holder === undefined)
|
|
397
|
+
return undefined;
|
|
398
|
+
const skipped = {};
|
|
399
|
+
if (Array.isArray(holder.skipped))
|
|
400
|
+
skipped.skipped = holder.skipped;
|
|
401
|
+
if (typeof holder.skippedCount === 'number' && Number.isFinite(holder.skippedCount)) {
|
|
402
|
+
skipped.skippedCount = holder.skippedCount;
|
|
403
|
+
}
|
|
404
|
+
return skipped.skipped !== undefined || skipped.skippedCount !== undefined ? skipped : undefined;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* A reply's run-level keys as a batch carries them (`readWrunHostedRunLevel`): the strategy exactly as the wire
|
|
408
|
+
* carries it, and the diagnostics normalized as the protected fetch normalizes a reply's (`normalizeRuntimeDiagnostics`,
|
|
409
|
+
* then the worker-transport rows through the error envelope, read by a published Indicator's audience: no fix-it copy;
|
|
410
|
+
* a cloud frame's refusal reads by its code, lane parity U16). A result always
|
|
411
|
+
* answers its list (none reads as an empty one: every result rewrites the rows); a live frame only when it carries
|
|
412
|
+
* the key. The normalizers load only for a list that holds a row. A result's served legs ride beside them
|
|
413
|
+
* (`wrunSocketServedLegsOf`); a live frame names none (the cloud sends them on create and range frames only).
|
|
414
|
+
*/
|
|
415
|
+
async function wrunSocketRunLevelOf(output, kind) {
|
|
416
|
+
const raw = readWrunHostedRunLevel(output);
|
|
417
|
+
const level = {};
|
|
418
|
+
if (raw.strategy !== undefined)
|
|
419
|
+
level.strategy = raw.strategy;
|
|
420
|
+
const servedLegs = kind === 'result' ? wrunSocketServedLegsOf(raw.wrunServedLegs) : undefined;
|
|
421
|
+
if (servedLegs !== undefined)
|
|
422
|
+
level.servedLegs = servedLegs;
|
|
423
|
+
const skipped = wrunSocketSkippedOf(output);
|
|
424
|
+
if (skipped !== undefined)
|
|
425
|
+
level.skipped = skipped;
|
|
426
|
+
// A result names its run's OPRA read either way; a live frame names it only when it carries the mark.
|
|
427
|
+
if (raw.wrunOpra === true)
|
|
428
|
+
level.opra = true;
|
|
429
|
+
else if (kind === 'result')
|
|
430
|
+
level.opra = false;
|
|
431
|
+
const rows = Array.isArray(raw.diagnostics) ? raw.diagnostics : undefined;
|
|
432
|
+
if (rows !== undefined && rows.length > 0) {
|
|
433
|
+
const [{ normalizeRuntimeDiagnostics }, { envelopeWorkerTransportDiagnostics }] = await Promise.all([
|
|
434
|
+
import('../scriptEditor/wrun-runtime-diagnostics.leaf.js'),
|
|
435
|
+
wrunChartHostEnv().transport.loadKScriptErrorEnvelope(),
|
|
436
|
+
]);
|
|
437
|
+
level.diagnostics = envelopeWorkerTransportDiagnostics(normalizeRuntimeDiagnostics(rows), { editorRun: false });
|
|
438
|
+
}
|
|
439
|
+
else if (rows !== undefined || kind === 'result') {
|
|
440
|
+
level.diagnostics = [];
|
|
441
|
+
}
|
|
442
|
+
return level;
|
|
443
|
+
}
|
|
444
|
+
/** A reply's `wrunServedLegs` as the source keeps them: undefined when the reply carries no list; an entry that is
|
|
445
|
+
* not a whole served leg (a fetch key and a note, both non-empty, and two finite starts) is dropped. */
|
|
446
|
+
function wrunSocketServedLegsOf(raw) {
|
|
447
|
+
if (!Array.isArray(raw))
|
|
448
|
+
return undefined;
|
|
449
|
+
return raw.flatMap((entry) => {
|
|
450
|
+
if (typeof entry !== 'object' || entry === null)
|
|
451
|
+
return [];
|
|
452
|
+
const { fetchKey, askedStartMs, servedStartMs, note } = entry;
|
|
453
|
+
if (typeof fetchKey !== 'string' || fetchKey.length === 0 || typeof note !== 'string' || note.length === 0) {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
if (typeof askedStartMs !== 'number' || !Number.isFinite(askedStartMs))
|
|
457
|
+
return [];
|
|
458
|
+
if (typeof servedStartMs !== 'number' || !Number.isFinite(servedStartMs))
|
|
459
|
+
return [];
|
|
460
|
+
return [{ fetchKey, askedStartMs, servedStartMs, note }];
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/** The session's served legs with a reply's merged in by fetch key (the reply's entry replaces the one it names, a
|
|
464
|
+
* key not held joins after the held ones): undefined while none is held. */
|
|
465
|
+
function mergeWrunSocketServedLegs(held, next) {
|
|
466
|
+
if (next === undefined || next.length === 0)
|
|
467
|
+
return held;
|
|
468
|
+
const byKey = new Map((held ?? []).map((leg) => [leg.fetchKey, leg]));
|
|
469
|
+
for (const leg of next)
|
|
470
|
+
byKey.set(leg.fetchKey, leg);
|
|
471
|
+
return [...byKey.values()];
|
|
472
|
+
}
|
|
473
|
+
/** The fix line of a leg the cloud served from the wall: the browser lane's words without its interval (the cloud
|
|
474
|
+
* names the leg by its fetch key alone, which the chart never parses). */
|
|
475
|
+
const WRUN_SERVED_LEG_FIX = "The chart's data reaches no further back: read fewer candles (a smaller bars), or treat the periods before the served start as absent.";
|
|
476
|
+
/** One warning row per leg the cloud served from the history wall: the browser lane's row for an ask the wall cut
|
|
477
|
+
* (`wrunClampedLegDiagnostics`: its stage, severity, code and type, the leg core's note verbatim as the message,
|
|
478
|
+
* which names the input), with the cloud's entry as its details. No input or interval is rebuilt from the fetch
|
|
479
|
+
* key: the note says it all. */
|
|
480
|
+
function wrunServedLegDiagnostics(legs) {
|
|
481
|
+
const rows = wrunClampedLegDiagnostics(legs.map((leg) => ({ inputName: '', intervalKey: '', note: leg.note })));
|
|
482
|
+
return rows.map((row, index) => ({ ...row, suggestedFix: WRUN_SERVED_LEG_FIX, details: { ...legs[index] } }));
|
|
483
|
+
}
|
|
484
|
+
/** The batch fields of a session's run-level keys (copies: a batch never shares the session's list). A list, when
|
|
485
|
+
* there is one, is the execution diagnostics then one warning row per served leg (`wrunServedLegDiagnostics`): a
|
|
486
|
+
* list replaces the source's rows on the legend (every result, a live frame that carries one), so every list
|
|
487
|
+
* carries the legs' warnings while the session holds them. */
|
|
488
|
+
function runLevelFields(level) {
|
|
489
|
+
return {
|
|
490
|
+
...(level.strategy !== undefined ? { strategy: level.strategy } : {}),
|
|
491
|
+
...(level.diagnostics !== undefined
|
|
492
|
+
? { diagnostics: [...level.diagnostics, ...wrunServedLegDiagnostics(level.servedLegs ?? [])] }
|
|
493
|
+
: {}),
|
|
494
|
+
...(level.skipped !== undefined ? level.skipped : {}),
|
|
495
|
+
...(level.opra !== undefined ? { opra: level.opra } : {}),
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
/** A session of the store seeded with the record's sheet, so a reply without one still merges. */
|
|
499
|
+
function seededSession(identity, sheet) {
|
|
500
|
+
return { identity, sheet, rows: [], grids: new Map(), refusals: [], asOfMs: Number.NaN };
|
|
501
|
+
}
|
|
502
|
+
/** The first index whose row opens at or after `ts` (rows ascending). */
|
|
503
|
+
function firstAtOrAfter(rows, ts) {
|
|
504
|
+
let lo = 0;
|
|
505
|
+
let hi = rows.length;
|
|
506
|
+
while (lo < hi) {
|
|
507
|
+
const mid = (lo + hi) >> 1;
|
|
508
|
+
if (rows[mid].ts < ts)
|
|
509
|
+
lo = mid + 1;
|
|
510
|
+
else
|
|
511
|
+
hi = mid;
|
|
512
|
+
}
|
|
513
|
+
return lo;
|
|
514
|
+
}
|
|
515
|
+
/** Handle bar stamps re-based from the session's rows onto a slice starting at `offset` (a stamp before
|
|
516
|
+
* the slice reads negative, as the wire's warm-up stamps do). */
|
|
517
|
+
function rebasedHandles(handles, offset) {
|
|
518
|
+
if (handles === undefined)
|
|
519
|
+
return undefined;
|
|
520
|
+
return handles.map((record) => ({
|
|
521
|
+
...record,
|
|
522
|
+
createdBar: record.createdBar - offset,
|
|
523
|
+
mutatedBar: record.mutatedBar - offset,
|
|
524
|
+
}));
|
|
525
|
+
}
|
|
526
|
+
function copyRecord(record) {
|
|
527
|
+
return { sheet: record.sheet, settings: { ...record.settings }, hostFill: { ...record.hostFill } };
|
|
528
|
+
}
|
|
529
|
+
/** The record a C5 patch leaves: the changed flat values, `null` dropping a value, and the fills. */
|
|
530
|
+
function patchedRecord(record, patch) {
|
|
531
|
+
const apply = (base, changes) => {
|
|
532
|
+
const next = { ...base };
|
|
533
|
+
for (const [key, value] of Object.entries(changes ?? {})) {
|
|
534
|
+
if (value === null)
|
|
535
|
+
delete next[key];
|
|
536
|
+
else
|
|
537
|
+
next[key] = value;
|
|
538
|
+
}
|
|
539
|
+
return next;
|
|
540
|
+
};
|
|
541
|
+
return {
|
|
542
|
+
sheet: record.sheet,
|
|
543
|
+
settings: apply(record.settings, patch.settings),
|
|
544
|
+
hostFill: apply(record.hostFill, patch.hostFill),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
/** A promise that settles as `work` does, or rejects with the stop once `signal` aborts. */
|
|
548
|
+
function untilStopped(work, signal) {
|
|
549
|
+
if (signal.aborted) {
|
|
550
|
+
void work.catch(() => undefined);
|
|
551
|
+
return Promise.reject(stoppedOf(signal));
|
|
552
|
+
}
|
|
553
|
+
return new Promise((resolve, reject) => {
|
|
554
|
+
const onAbort = () => reject(stoppedOf(signal));
|
|
555
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
556
|
+
work.then((value) => {
|
|
557
|
+
signal.removeEventListener('abort', onAbort);
|
|
558
|
+
resolve(value);
|
|
559
|
+
}, (error) => {
|
|
560
|
+
signal.removeEventListener('abort', onAbort);
|
|
561
|
+
reject(error);
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
function stoppedOf(signal) {
|
|
566
|
+
return signal.reason instanceof WrunSocketRowSourceStopped
|
|
567
|
+
? signal.reason
|
|
568
|
+
: new WrunSocketRowSourceStopped('superseded');
|
|
569
|
+
}
|
|
570
|
+
/** A signal that aborts with whichever of `a` and `b` aborts first, by hand: `AbortSignal.any` is missing in browsers
|
|
571
|
+
* still in use. */
|
|
572
|
+
function abortedByEither(a, b) {
|
|
573
|
+
const either = new AbortController();
|
|
574
|
+
const signals = [a, b];
|
|
575
|
+
const follow = () => {
|
|
576
|
+
const first = signals.find((signal) => signal.aborted);
|
|
577
|
+
for (const signal of signals)
|
|
578
|
+
signal.removeEventListener('abort', follow);
|
|
579
|
+
either.abort(first?.reason);
|
|
580
|
+
};
|
|
581
|
+
if (signals.some((signal) => signal.aborted))
|
|
582
|
+
follow();
|
|
583
|
+
else
|
|
584
|
+
for (const signal of signals)
|
|
585
|
+
signal.addEventListener('abort', follow, { once: true });
|
|
586
|
+
return either.signal;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* An entry's lane rows, extended from the ones its last conversion left. A merge keeps the entry's rows outside what
|
|
590
|
+
* it replaced as the very row objects (a live frame replaces the rows from its first bar, a page splices its window
|
|
591
|
+
* in), so the kept head and the kept tail keep their lane rows and only the rows between convert. An entry of another
|
|
592
|
+
* shape (class, width), or one that kept no row, converts whole.
|
|
593
|
+
*/
|
|
594
|
+
function extendWrunCellLane(previous, grid) {
|
|
595
|
+
if (previous?.grid === grid)
|
|
596
|
+
return previous;
|
|
597
|
+
if (previous === undefined || !sameWrunCellShape(previous.grid, grid)) {
|
|
598
|
+
return { grid, rows: wrunHostedGridLaneRows(grid) };
|
|
599
|
+
}
|
|
600
|
+
const before = previous.grid.rows;
|
|
601
|
+
const after = grid.rows;
|
|
602
|
+
const shared = Math.min(before.length, after.length);
|
|
603
|
+
let head = 0;
|
|
604
|
+
while (head < shared && before[head] === after[head])
|
|
605
|
+
head += 1;
|
|
606
|
+
let tail = 0;
|
|
607
|
+
while (tail < shared - head && before[before.length - 1 - tail] === after[after.length - 1 - tail])
|
|
608
|
+
tail += 1;
|
|
609
|
+
if (head + tail === 0)
|
|
610
|
+
return { grid, rows: wrunHostedGridLaneRows(grid) };
|
|
611
|
+
const lane = previous.rows;
|
|
612
|
+
if (head + tail === before.length && head + tail === after.length)
|
|
613
|
+
return { grid, rows: lane };
|
|
614
|
+
// The lane rows the kept tail made, and the ones the replaced rows made: the kept head's are the rest.
|
|
615
|
+
const tailLength = wrunHostedGridLaneRowCount(previous.grid, before.length - tail, before.length);
|
|
616
|
+
const replacedLength = wrunHostedGridLaneRowCount(previous.grid, head, before.length - tail);
|
|
617
|
+
const rows = lane.slice(0, lane.length - tailLength - replacedLength);
|
|
618
|
+
for (const row of wrunHostedGridLaneRows(grid, head, after.length - tail))
|
|
619
|
+
rows.push(row);
|
|
620
|
+
for (let at = lane.length - tailLength; at < lane.length; at += 1)
|
|
621
|
+
rows.push(lane[at]);
|
|
622
|
+
return { grid, rows };
|
|
623
|
+
}
|
|
624
|
+
/** Whether two entries' rows convert alike (kind, class and tuple width). */
|
|
625
|
+
function sameWrunCellShape(a, b) {
|
|
626
|
+
if (a.kind !== b.kind || a.width !== b.width)
|
|
627
|
+
return false;
|
|
628
|
+
return a.kind !== 'cells' || (b.kind === 'cells' && a.class === b.class);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* The cloud lane's `WrunRowSource`: one per overlay, one cloud session at a time. Asks run one at a time
|
|
632
|
+
* in call order; a create or a settings change supersedes the asks of the session before it (they stop
|
|
633
|
+
* with `WrunSocketRowSourceStopped`, their replies are never merged). Live frames and results merge into
|
|
634
|
+
* the store in arrival order.
|
|
635
|
+
*/
|
|
636
|
+
export class SocketWrunRowSource {
|
|
637
|
+
frames;
|
|
638
|
+
deps;
|
|
639
|
+
identity;
|
|
640
|
+
record;
|
|
641
|
+
historical = false;
|
|
642
|
+
transport;
|
|
643
|
+
loading;
|
|
644
|
+
unsubscribeLive;
|
|
645
|
+
current;
|
|
646
|
+
answered = [];
|
|
647
|
+
/** The session's newest run-level keys (the strategy, the diagnostics), which every batch carries, and the legs the
|
|
648
|
+
* history wall cut, whose warning rows every list carries after the diagnostics. */
|
|
649
|
+
runLevel = {};
|
|
650
|
+
/** The window the session owes: a patch the cloud answered moved it to new settings before the paging of what it
|
|
651
|
+
* covered completed (a page refused or failed). Its next page or patch pages it first. */
|
|
652
|
+
owed;
|
|
653
|
+
/** The overlay's session losses as the cloud's answer to the create that opened the session arrived, before its
|
|
654
|
+
* decode (`wrunSocketSessionLossCount`): the stamp every batch of the session carries (`sessionLosses`). */
|
|
655
|
+
lossesAtOpen;
|
|
656
|
+
/** The ask waiting on the socket (one at a time). */
|
|
657
|
+
flight;
|
|
658
|
+
generation = 0;
|
|
659
|
+
generationAbort = new AbortController();
|
|
660
|
+
closed = false;
|
|
661
|
+
scheduled = false;
|
|
662
|
+
listener;
|
|
663
|
+
lowers = new Set();
|
|
664
|
+
/** The asks, one at a time in call order. */
|
|
665
|
+
queue = Promise.resolve();
|
|
666
|
+
/** Every merge into the store (results and live frames), in arrival order. */
|
|
667
|
+
merges = Promise.resolve();
|
|
668
|
+
/** The cells memo: the last cell rows answered and each celled entry's lane rows (`cellRows`). */
|
|
669
|
+
cells;
|
|
670
|
+
constructor(deps = {}) {
|
|
671
|
+
this.deps = deps;
|
|
672
|
+
this.frames = {
|
|
673
|
+
subscribe: (listener) => {
|
|
674
|
+
this.listener = listener;
|
|
675
|
+
return () => {
|
|
676
|
+
if (this.listener === listener)
|
|
677
|
+
this.listener = undefined;
|
|
678
|
+
};
|
|
679
|
+
},
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/** The store's merged session (undefined before the first answer and after a teardown). */
|
|
683
|
+
get session() {
|
|
684
|
+
return this.current;
|
|
685
|
+
}
|
|
686
|
+
/** The session's run-level keys as a batch carries them (copies): the newest strategy output and diagnostics a
|
|
687
|
+
* result or a live frame carried, whichever merged last, the served legs' warning rows after the diagnostics. */
|
|
688
|
+
get sessionRunLevel() {
|
|
689
|
+
return runLevelFields(this.runLevel);
|
|
690
|
+
}
|
|
691
|
+
/** The session's cell rows in the shapes the price canvases read (the store's conversion), with the
|
|
692
|
+
* chart's own candles. The cells memo keeps each entry's lane rows between reads: a read after a merge
|
|
693
|
+
* converts only the rows the merge replaced (`extendWrunCellLane`), and a read with nothing merged since,
|
|
694
|
+
* over the same candles, answers the very object the last one did. */
|
|
695
|
+
cellRows(chartCandles) {
|
|
696
|
+
const session = this.current;
|
|
697
|
+
if (session === undefined)
|
|
698
|
+
return chartCandles !== undefined ? { ohlcvRows: chartCandles } : {};
|
|
699
|
+
const memo = this.cells;
|
|
700
|
+
if (memo?.grids === session.grids && memo.sheet === session.sheet && memo.candles === chartCandles) {
|
|
701
|
+
return memo.cells;
|
|
702
|
+
}
|
|
703
|
+
const lanes = new Map();
|
|
704
|
+
const laneOf = (grid) => {
|
|
705
|
+
const key = wrunHostedGridKey(grid);
|
|
706
|
+
const lane = extendWrunCellLane(memo?.lanes.get(key), grid);
|
|
707
|
+
lanes.set(key, lane);
|
|
708
|
+
return lane.rows;
|
|
709
|
+
};
|
|
710
|
+
const cells = wrunCellRowsFromHostedLanes(session.sheet, session.grids, laneOf, chartCandles);
|
|
711
|
+
this.cells = { grids: session.grids, sheet: session.sheet, candles: chartCandles, lanes, cells };
|
|
712
|
+
return cells;
|
|
713
|
+
}
|
|
714
|
+
create(identity, record, window, cancel) {
|
|
715
|
+
if (this.closed)
|
|
716
|
+
return Promise.reject(new WrunSocketRowSourceStopped('teardown'));
|
|
717
|
+
const generation = this.nextGeneration();
|
|
718
|
+
return this.enqueue(async () => {
|
|
719
|
+
this.assertCurrent(generation);
|
|
720
|
+
this.bind(identity);
|
|
721
|
+
this.record = copyRecord(record);
|
|
722
|
+
this.historical = (this.deps.historical ?? wrunChartHostEnv().chart.isReplaying)(identity.chartIndex);
|
|
723
|
+
// A create opens a new session: the one before it belongs to a superseded generation.
|
|
724
|
+
this.current = undefined;
|
|
725
|
+
this.answered = [];
|
|
726
|
+
this.runLevel = {};
|
|
727
|
+
this.lossesAtOpen = undefined;
|
|
728
|
+
this.followLive();
|
|
729
|
+
return this.withLoading(async () => {
|
|
730
|
+
const page = newestWrunSocketPage(window, this.intervalMs(), this.pageBars());
|
|
731
|
+
const reply = await this.ask('create', page, generation, undefined, cancel);
|
|
732
|
+
// The session opened as the cloud's answer arrived: the socket's losses read now, before the decode (a cold
|
|
733
|
+
// restore loads the shared host first) and the paging, so a loss noted meanwhile reads as the session's end.
|
|
734
|
+
const losses = wrunSocketSessionLossCount(identity.indicatorId);
|
|
735
|
+
if (reply.refusal !== undefined)
|
|
736
|
+
return this.refusalBatch(page, reply.refusal);
|
|
737
|
+
// Rejects for a reply it did not merge (a first run never answers an empty batch); a reply without the
|
|
738
|
+
// hosted wire answers the legacy refusal.
|
|
739
|
+
const legacy = await this.mergeOrRefuse(reply.output, generation, record.sheet);
|
|
740
|
+
if (legacy !== undefined)
|
|
741
|
+
return this.refusalBatch(page, legacy);
|
|
742
|
+
this.lossesAtOpen = losses;
|
|
743
|
+
return this.batchOf(page, true);
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
range(window) {
|
|
748
|
+
if (this.closed)
|
|
749
|
+
return Promise.reject(new WrunSocketRowSourceStopped('teardown'));
|
|
750
|
+
const generation = this.generation;
|
|
751
|
+
return this.enqueue(async () => {
|
|
752
|
+
this.assertCurrent(generation);
|
|
753
|
+
if (this.current === undefined)
|
|
754
|
+
throw new Error('wrun socket row source: range before a session answered');
|
|
755
|
+
return this.withLoading(async () => {
|
|
756
|
+
// What the session owes goes first: the batch and the session then stand for one computation.
|
|
757
|
+
const refusal = (await this.pageOwed(generation)) ?? (await this.pageWindow(window, generation));
|
|
758
|
+
return refusal !== undefined ? this.refusalBatch(window, refusal) : this.batchOf(window, false);
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
changeSettings(patch) {
|
|
763
|
+
if (this.closed)
|
|
764
|
+
return Promise.reject(new WrunSocketRowSourceStopped('teardown'));
|
|
765
|
+
const generation = this.nextGeneration();
|
|
766
|
+
return this.enqueue(async () => {
|
|
767
|
+
this.assertCurrent(generation);
|
|
768
|
+
const previous = this.current;
|
|
769
|
+
const record = this.record;
|
|
770
|
+
if (previous === undefined || record === undefined) {
|
|
771
|
+
throw new Error('wrun socket row source: changeSettings before a session answered');
|
|
772
|
+
}
|
|
773
|
+
const covered = this.coveredWindow(previous);
|
|
774
|
+
const previousAnswered = this.answered;
|
|
775
|
+
const previousLevel = this.runLevel;
|
|
776
|
+
const previousOwed = this.owed;
|
|
777
|
+
this.record = patchedRecord(record, patch);
|
|
778
|
+
return this.withLoading(async () => {
|
|
779
|
+
const page = newestWrunSocketPage(covered, this.intervalMs(), this.pageBars());
|
|
780
|
+
// The settings the source held and their rows stand: under this generation when the cloud kept (or rolled
|
|
781
|
+
// back to) them, so the live frames extend them again; under their own when the patch went unanswered, so
|
|
782
|
+
// no frame of a computation the cloud may have moved extends them.
|
|
783
|
+
const keepPrevious = (unanswered) => {
|
|
784
|
+
this.record = record;
|
|
785
|
+
this.current = unanswered ? previous : { ...previous, identity: this.storeIdentity(generation) };
|
|
786
|
+
this.answered = previousAnswered;
|
|
787
|
+
this.runLevel = previousLevel;
|
|
788
|
+
this.owed = previousOwed;
|
|
789
|
+
};
|
|
790
|
+
try {
|
|
791
|
+
const reply = await this.ask('changeSettings', page, generation, patch);
|
|
792
|
+
if (reply.refusal !== undefined) {
|
|
793
|
+
keepPrevious(false);
|
|
794
|
+
return this.refusalBatch(covered, reply.refusal);
|
|
795
|
+
}
|
|
796
|
+
// The new settings' rows replace the session's only once their reply merged. A reply without the hosted
|
|
797
|
+
// wire (the legacy path) is refused like a code: the settings the source held and their rows stand.
|
|
798
|
+
const legacy = await this.mergeOrRefuse(reply.output, generation, previous.sheet);
|
|
799
|
+
if (legacy !== undefined) {
|
|
800
|
+
keepPrevious(false);
|
|
801
|
+
return this.refusalBatch(covered, legacy);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
// A patch a newer ask superseded (or a teardown stopped) belongs to that ask. One that went out and met the
|
|
806
|
+
// worker's request deadline may still commit in the cloud (the worker retires such a session, and its next
|
|
807
|
+
// ask recreates it over that ask's window alone): the failure says so (`unanswered`). Every other way out
|
|
808
|
+
// (a failure, a reply answered nothing or dropped as superseded, an unreadable one, a denied capability)
|
|
809
|
+
// leaves what the cloud held.
|
|
810
|
+
if (!this.owns(generation))
|
|
811
|
+
throw error;
|
|
812
|
+
const unanswered = isWrunRowSourceTransientError(error) && error.reason === 'request-timeout';
|
|
813
|
+
keepPrevious(unanswered);
|
|
814
|
+
throw unanswered ? markWrunRowSourceSettingsLeft(error, 'unanswered') : error;
|
|
815
|
+
}
|
|
816
|
+
// The cloud answered the patch: the source computes with it for good (its record, its session, its frames),
|
|
817
|
+
// whatever the paging after it does, and owes what the session covered until that paging completes. A page
|
|
818
|
+
// refused or failed fails the call marked `moved`; a failed one as the transient incomplete paging (Retry).
|
|
819
|
+
this.owed = covered;
|
|
820
|
+
let refusal;
|
|
821
|
+
try {
|
|
822
|
+
refusal = await this.pageWindow(covered, generation);
|
|
823
|
+
}
|
|
824
|
+
catch (error) {
|
|
825
|
+
throw this.owns(generation) ? markWrunRowSourceSettingsLeft(wrunSocketPagingFailure(error), 'moved') : error;
|
|
826
|
+
}
|
|
827
|
+
if (refusal !== undefined) {
|
|
828
|
+
markWrunRowSourceSettingsLeft(refusal, 'moved');
|
|
829
|
+
return this.refusalBatch(covered, refusal);
|
|
830
|
+
}
|
|
831
|
+
this.owed = undefined;
|
|
832
|
+
return this.batchOf(covered, false);
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
teardown() {
|
|
837
|
+
if (this.closed)
|
|
838
|
+
return;
|
|
839
|
+
this.closed = true;
|
|
840
|
+
this.generationAbort.abort(new WrunSocketRowSourceStopped('teardown'));
|
|
841
|
+
for (const lower of [...this.lowers])
|
|
842
|
+
lower();
|
|
843
|
+
this.unsubscribeLive?.();
|
|
844
|
+
this.unsubscribeLive = undefined;
|
|
845
|
+
this.listener = undefined;
|
|
846
|
+
this.transport?.end();
|
|
847
|
+
if (this.identity !== undefined)
|
|
848
|
+
this.unfollowFacts(this.identity);
|
|
849
|
+
// The pages this source queued in the overlay's in-flight entry leave with it (their awaiters resolve).
|
|
850
|
+
if (this.scheduled && this.identity !== undefined) {
|
|
851
|
+
clearIndicatorInflight(this.identity.chartIndex, this.identity.indicatorId, 'protected');
|
|
852
|
+
}
|
|
853
|
+
this.current = undefined;
|
|
854
|
+
this.cells = undefined;
|
|
855
|
+
this.answered = [];
|
|
856
|
+
this.runLevel = {};
|
|
857
|
+
this.flight = undefined;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* A facts-needed note for the overlay this source follows (`routeWrunSocketFactsNeeded`): the ask waiting on the
|
|
861
|
+
* socket takes the retry, so its refusal asks again once the directory answered the lists. False when no ask waits.
|
|
862
|
+
*/
|
|
863
|
+
takeFactsRetry(retry) {
|
|
864
|
+
if (this.closed || this.flight === undefined)
|
|
865
|
+
return false;
|
|
866
|
+
this.flight.facts = retry;
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
// ── Asks ───────────────────────────────────────────────────────────────────────────────────
|
|
870
|
+
enqueue(work) {
|
|
871
|
+
const run = this.queue.then(work, work);
|
|
872
|
+
this.queue = run.then(() => undefined, () => undefined);
|
|
873
|
+
return run;
|
|
874
|
+
}
|
|
875
|
+
nextGeneration() {
|
|
876
|
+
this.generationAbort.abort(new WrunSocketRowSourceStopped('superseded'));
|
|
877
|
+
this.generationAbort = new AbortController();
|
|
878
|
+
this.generation += 1;
|
|
879
|
+
return this.generation;
|
|
880
|
+
}
|
|
881
|
+
assertCurrent(generation) {
|
|
882
|
+
if (this.closed)
|
|
883
|
+
throw new WrunSocketRowSourceStopped('teardown');
|
|
884
|
+
if (generation !== this.generation)
|
|
885
|
+
throw new WrunSocketRowSourceStopped('superseded');
|
|
886
|
+
}
|
|
887
|
+
/** Whether the asks of `generation` still own the session (no newer create or patch, no teardown). */
|
|
888
|
+
owns(generation) {
|
|
889
|
+
return !this.closed && generation === this.generation;
|
|
890
|
+
}
|
|
891
|
+
/** The transport and the load signals follow the overlay: a create for another one ends the old session. */
|
|
892
|
+
bind(identity) {
|
|
893
|
+
const same = this.identity !== undefined &&
|
|
894
|
+
this.identity.chartIndex === identity.chartIndex &&
|
|
895
|
+
this.identity.indicatorId === identity.indicatorId;
|
|
896
|
+
if (!same && this.transport !== undefined) {
|
|
897
|
+
this.unsubscribeLive?.();
|
|
898
|
+
this.unsubscribeLive = undefined;
|
|
899
|
+
this.transport.end();
|
|
900
|
+
this.transport = undefined;
|
|
901
|
+
this.loading = undefined;
|
|
902
|
+
}
|
|
903
|
+
if (!same && this.identity !== undefined)
|
|
904
|
+
this.unfollowFacts(this.identity);
|
|
905
|
+
this.identity = { ...identity };
|
|
906
|
+
this.transport ??= (this.deps.transportFor ?? wrunChartHostEnv().transport.hostedSocket)(this.identity);
|
|
907
|
+
this.loading ??= (this.deps.loadingFor ?? wrunChartHostEnv().chart.hostedLoadSignals)(this.identity);
|
|
908
|
+
const key = overlayKeyOf(this.identity);
|
|
909
|
+
const followers = factsFollowers.get(key) ?? new Set();
|
|
910
|
+
followers.add(this);
|
|
911
|
+
factsFollowers.set(key, followers);
|
|
912
|
+
}
|
|
913
|
+
unfollowFacts(identity) {
|
|
914
|
+
const key = overlayKeyOf(identity);
|
|
915
|
+
const followers = factsFollowers.get(key);
|
|
916
|
+
if (followers === undefined)
|
|
917
|
+
return;
|
|
918
|
+
followers.delete(this);
|
|
919
|
+
if (followers.size === 0)
|
|
920
|
+
factsFollowers.delete(key);
|
|
921
|
+
}
|
|
922
|
+
intervalMs() {
|
|
923
|
+
return (this.identity?.intervalSec ?? 60) * 1000;
|
|
924
|
+
}
|
|
925
|
+
pageBars() {
|
|
926
|
+
return this.deps.pageBars ?? WRUN_SOCKET_PAGE_BARS;
|
|
927
|
+
}
|
|
928
|
+
/** The leading cold rows of the windows the cloud answered, at most the record's warm-up head (rule 4). */
|
|
929
|
+
coldHeads() {
|
|
930
|
+
const record = this.record;
|
|
931
|
+
if (record === undefined)
|
|
932
|
+
return [];
|
|
933
|
+
const head = (this.deps.warmupBarsOf ?? wrunSocketWarmupBars)(record);
|
|
934
|
+
return wrunSocketColdHeads(this.current?.rows ?? [], this.answered, head);
|
|
935
|
+
}
|
|
936
|
+
storeIdentity(generation) {
|
|
937
|
+
return `${this.identity?.indicatorId ?? ''}#${generation}`;
|
|
938
|
+
}
|
|
939
|
+
async withLoading(work) {
|
|
940
|
+
const lower = await this.raiseLoading();
|
|
941
|
+
try {
|
|
942
|
+
return await work();
|
|
943
|
+
}
|
|
944
|
+
finally {
|
|
945
|
+
lower();
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
async raiseLoading() {
|
|
949
|
+
const signals = this.loading;
|
|
950
|
+
if (signals === undefined)
|
|
951
|
+
return () => undefined;
|
|
952
|
+
let lowerSignals;
|
|
953
|
+
try {
|
|
954
|
+
lowerSignals = await signals.raise();
|
|
955
|
+
}
|
|
956
|
+
catch (error) {
|
|
957
|
+
console.warn('[wrun] socket row source load signals unavailable:', error);
|
|
958
|
+
return () => undefined;
|
|
959
|
+
}
|
|
960
|
+
let lowered = false;
|
|
961
|
+
const lower = () => {
|
|
962
|
+
if (lowered)
|
|
963
|
+
return;
|
|
964
|
+
lowered = true;
|
|
965
|
+
this.lowers.delete(lower);
|
|
966
|
+
try {
|
|
967
|
+
lowerSignals();
|
|
968
|
+
}
|
|
969
|
+
catch (error) {
|
|
970
|
+
console.warn('[wrun] socket row source load signals lower failed:', error);
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
this.lowers.add(lower);
|
|
974
|
+
// Torn down while the raise loaded: nothing may stay up.
|
|
975
|
+
if (this.closed)
|
|
976
|
+
lower();
|
|
977
|
+
return lower;
|
|
978
|
+
}
|
|
979
|
+
async ask(kind, window, generation, patch, cancel) {
|
|
980
|
+
this.assertCurrent(generation);
|
|
981
|
+
const transport = this.transport;
|
|
982
|
+
const identity = this.identity;
|
|
983
|
+
const record = this.record;
|
|
984
|
+
if (transport === undefined || identity === undefined || record === undefined) {
|
|
985
|
+
throw new Error('wrun socket row source: ask before create');
|
|
986
|
+
}
|
|
987
|
+
const signal = this.generationAbort.signal;
|
|
988
|
+
const flight = {};
|
|
989
|
+
this.flight = flight;
|
|
990
|
+
try {
|
|
991
|
+
// The transport stops on a create's own cancel too, and asks nothing more for it; the ask still waits for
|
|
992
|
+
// whatever the transport answers (the pass drops a cancelled create's batch as superseded).
|
|
993
|
+
const output = await untilStopped(transport.ask({
|
|
994
|
+
kind,
|
|
995
|
+
identity,
|
|
996
|
+
record,
|
|
997
|
+
...(patch !== undefined ? { patch } : {}),
|
|
998
|
+
window: { fromMs: window.fromMs, toMs: window.toMs },
|
|
999
|
+
historical: this.historical,
|
|
1000
|
+
signal: cancel !== undefined ? abortedByEither(signal, cancel) : signal,
|
|
1001
|
+
}), signal);
|
|
1002
|
+
this.assertCurrent(generation);
|
|
1003
|
+
return { output };
|
|
1004
|
+
}
|
|
1005
|
+
catch (error) {
|
|
1006
|
+
// A superseded or torn-down ask reports the stop, whatever the transport said after it.
|
|
1007
|
+
this.assertCurrent(generation);
|
|
1008
|
+
// The cloud refused this ask for fact lists its payload lacked (the worker named them while it waited): once
|
|
1009
|
+
// the directory answered every one, the same ask goes again, a create as a recreate and a page through the
|
|
1010
|
+
// range's own paging, once per overlay and fact set (the next payload carries the lists).
|
|
1011
|
+
if (flight.facts !== undefined) {
|
|
1012
|
+
const claim = await untilStopped(flight.facts, signal);
|
|
1013
|
+
this.assertCurrent(generation);
|
|
1014
|
+
if (claim?.() === true)
|
|
1015
|
+
return await this.ask(kind, window, generation, patch, cancel);
|
|
1016
|
+
}
|
|
1017
|
+
if (error instanceof WrunSocketRefusalError)
|
|
1018
|
+
return { refusal: error };
|
|
1019
|
+
throw error;
|
|
1020
|
+
}
|
|
1021
|
+
finally {
|
|
1022
|
+
if (this.flight === flight)
|
|
1023
|
+
this.flight = undefined;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
/** One merge into the store, after every merge before it. */
|
|
1027
|
+
serial(work) {
|
|
1028
|
+
const run = this.merges.then(work, work);
|
|
1029
|
+
this.merges = run.then(() => undefined, () => undefined);
|
|
1030
|
+
return run;
|
|
1031
|
+
}
|
|
1032
|
+
/** Merge a result reply, or the legacy refusal a reply without the hosted wire answers (see mergeResult):
|
|
1033
|
+
* undefined when it merged. Every other reply it does not merge rejects as mergeResult does. */
|
|
1034
|
+
async mergeOrRefuse(output, generation, freshSheet) {
|
|
1035
|
+
try {
|
|
1036
|
+
await this.mergeResult(output, generation, freshSheet);
|
|
1037
|
+
return undefined;
|
|
1038
|
+
}
|
|
1039
|
+
catch (error) {
|
|
1040
|
+
if (error instanceof WrunSocketRefusalError)
|
|
1041
|
+
return error;
|
|
1042
|
+
throw error;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Merge a result reply into the store. A fresh session's reply (a create's, a patch's: `freshSheet` seeds it)
|
|
1047
|
+
* replaces the session held, its coverage and its run-level keys only once it merged; a page's extends the session.
|
|
1048
|
+
* A reply it does not merge rejects, and leaves the store as it was: no reply (the socket answered nothing: a
|
|
1049
|
+
* laundered kick, a socket that is not open, a failed worker, a skipped send) as `WrunRowSourceTransientError`,
|
|
1050
|
+
* the worker's superseded marker as a superseded stop, no hosted wire (a server answering a cloud record on the
|
|
1051
|
+
* legacy pre-styled path: never read) as the whole-run refusal `WRUN_LEGACY_RESULT_CODE`, an unreadable wire or
|
|
1052
|
+
* one the store refused as `WrunSocketReplyUnreadable`.
|
|
1053
|
+
*/
|
|
1054
|
+
mergeResult(output, generation, freshSheet) {
|
|
1055
|
+
return this.serial(async () => {
|
|
1056
|
+
this.assertCurrent(generation);
|
|
1057
|
+
// Another chart or tab took the live session (a foreign supersede): the session-lost refusal, not a stop.
|
|
1058
|
+
const lost = wrunSessionLostRefusalOf(output);
|
|
1059
|
+
if (lost !== undefined)
|
|
1060
|
+
throw lost;
|
|
1061
|
+
if (isSupersededReply(output))
|
|
1062
|
+
throw new WrunSocketRowSourceStopped('superseded');
|
|
1063
|
+
if (output === undefined || output === null)
|
|
1064
|
+
throw new WrunRowSourceTransientError('no-reply');
|
|
1065
|
+
const read = await readWrunHostedWire(output);
|
|
1066
|
+
this.assertCurrent(generation);
|
|
1067
|
+
if (read.kind === 'absent')
|
|
1068
|
+
throw new WrunSocketRefusalError(WRUN_LEGACY_RESULT_CODE);
|
|
1069
|
+
if (read.kind === 'unreadable')
|
|
1070
|
+
throw new WrunSocketReplyUnreadable(read.reason);
|
|
1071
|
+
const level = await wrunSocketRunLevelOf(output, 'result');
|
|
1072
|
+
this.assertCurrent(generation);
|
|
1073
|
+
const identity = this.storeIdentity(generation);
|
|
1074
|
+
const base = freshSheet !== undefined
|
|
1075
|
+
? seededSession(identity, freshSheet)
|
|
1076
|
+
: this.current?.identity === identity
|
|
1077
|
+
? this.current
|
|
1078
|
+
: undefined;
|
|
1079
|
+
const merge = mergeWrunHostedReply(base, read.wire, { identity, kind: 'result' }, WRUN_SOCKET_ROW_STORE_UNCAPPED);
|
|
1080
|
+
if ('refused' in merge)
|
|
1081
|
+
throw new WrunSocketReplyUnreadable(`the store refused the reply (${merge.refused})`);
|
|
1082
|
+
this.current = merge.session;
|
|
1083
|
+
const answered = freshSheet !== undefined ? [] : this.answered;
|
|
1084
|
+
this.answered = mergeWrunSocketSpans([...answered, read.wire.window], this.intervalMs());
|
|
1085
|
+
// A fresh session owes nothing of the one it replaced.
|
|
1086
|
+
if (freshSheet !== undefined)
|
|
1087
|
+
this.owed = undefined;
|
|
1088
|
+
// Every result rewrites the diagnostics; a page that leaves the strategy out keeps the session's newest.
|
|
1089
|
+
const strategy = level.strategy ?? (freshSheet !== undefined ? undefined : this.runLevel.strategy);
|
|
1090
|
+
// A fresh session's result names its own served legs (none without the key); a page merges its own into the
|
|
1091
|
+
// session's by fetch key (an older page names the legs its window cut), and one without the key keeps them.
|
|
1092
|
+
const servedLegs = mergeWrunSocketServedLegs(freshSheet !== undefined ? undefined : this.runLevel.servedLegs, level.servedLegs);
|
|
1093
|
+
// The skipped elements the newest answer named, as it named them; a page without the keys keeps the session's.
|
|
1094
|
+
const skipped = level.skipped ?? (freshSheet !== undefined ? undefined : this.runLevel.skipped);
|
|
1095
|
+
this.runLevel = {
|
|
1096
|
+
...(strategy !== undefined ? { strategy } : {}),
|
|
1097
|
+
diagnostics: level.diagnostics ?? [],
|
|
1098
|
+
...(servedLegs !== undefined ? { servedLegs } : {}),
|
|
1099
|
+
...(skipped !== undefined ? { skipped } : {}),
|
|
1100
|
+
// The newest result's OPRA word (every result answers one): a re-plan off OPRA names false.
|
|
1101
|
+
...(level.opra !== undefined ? { opra: level.opra } : {}),
|
|
1102
|
+
};
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Page a window until the planner's coverage says done: each round runs the pages still missing,
|
|
1107
|
+
* newest first and planned again after each one, through the in-flight registry (or around it, for a
|
|
1108
|
+
* replay lane's session). A round another ask of the overlay held the flight for (its covering run in flight) waits
|
|
1109
|
+
* for it and plans again; a round whose pages went and added nothing ends the paging (the cloud holds
|
|
1110
|
+
* no more). A refused page ends it with the refusal.
|
|
1111
|
+
*/
|
|
1112
|
+
async pageWindow(window, generation) {
|
|
1113
|
+
const identity = this.identity;
|
|
1114
|
+
if (identity === undefined)
|
|
1115
|
+
return undefined;
|
|
1116
|
+
const policy = wrunSocketPagePolicy(this.historical);
|
|
1117
|
+
for (;;) {
|
|
1118
|
+
this.assertCurrent(generation);
|
|
1119
|
+
const before = this.coverageMark();
|
|
1120
|
+
if ((await this.planPages(window)).pages.length === 0)
|
|
1121
|
+
return undefined;
|
|
1122
|
+
let refusal;
|
|
1123
|
+
let failure;
|
|
1124
|
+
let ran = false;
|
|
1125
|
+
const runner = async (range) => {
|
|
1126
|
+
ran = true;
|
|
1127
|
+
try {
|
|
1128
|
+
// The registry's range may be a union of asks: only what is still missing inside it goes. One page at a
|
|
1129
|
+
// time, planned again after each merge: a page's reply carries its own cold head (the cloud ran it with
|
|
1130
|
+
// the planner's head), and only a plan over the merged session sees it when the next older page is cut
|
|
1131
|
+
// (rule 4). A window asked once in a round is never asked again in it: the next round judges what it
|
|
1132
|
+
// added.
|
|
1133
|
+
const asked = new Set();
|
|
1134
|
+
for (;;) {
|
|
1135
|
+
const page = (await this.planPages({ fromMs: range.startMs, toMs: range.endMs - 1 })).pages[0];
|
|
1136
|
+
if (page === undefined)
|
|
1137
|
+
return;
|
|
1138
|
+
const key = `${page.fromMs}-${page.toMs}`;
|
|
1139
|
+
if (asked.has(key))
|
|
1140
|
+
return;
|
|
1141
|
+
asked.add(key);
|
|
1142
|
+
const reply = await this.ask('range', page, generation);
|
|
1143
|
+
if (reply.refusal !== undefined) {
|
|
1144
|
+
refusal = reply.refusal;
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
// Rejects for a page it did not merge: the window fails, never a batch short of the page.
|
|
1148
|
+
await this.mergeResult(reply.output, generation);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
catch (error) {
|
|
1152
|
+
if (error instanceof WrunSocketRefusalError)
|
|
1153
|
+
refusal ??= error;
|
|
1154
|
+
else
|
|
1155
|
+
failure ??= error;
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
// The registry's ranges are half-open: the window's last bar is inside [fromMs, toMs + 1).
|
|
1159
|
+
const range = { startMs: window.fromMs, endMs: window.toMs + 1 };
|
|
1160
|
+
if (policy.onPendingTwin === 'ignore') {
|
|
1161
|
+
await runner(range);
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
this.scheduled = true;
|
|
1165
|
+
const scheduled = scheduleIndicatorInflightFetch(identity.chartIndex, identity.indicatorId, range, runner, {
|
|
1166
|
+
profile: 'protected',
|
|
1167
|
+
...this.deps.inflight,
|
|
1168
|
+
});
|
|
1169
|
+
if (scheduled.status === 'ignored-invalid')
|
|
1170
|
+
return undefined;
|
|
1171
|
+
await untilStopped(scheduled.completion, this.generationAbort.signal);
|
|
1172
|
+
}
|
|
1173
|
+
this.assertCurrent(generation);
|
|
1174
|
+
if (failure !== undefined)
|
|
1175
|
+
throw failure;
|
|
1176
|
+
if (refusal !== undefined)
|
|
1177
|
+
return refusal;
|
|
1178
|
+
// Another ask of the overlay held the flight and this round's pages never went: ask again now.
|
|
1179
|
+
if (!ran)
|
|
1180
|
+
continue;
|
|
1181
|
+
if (this.coverageMark() === before)
|
|
1182
|
+
return undefined;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
/** Page the window the session owes (`owed`), when it owes one: paid once that paging completed. */
|
|
1186
|
+
async pageOwed(generation) {
|
|
1187
|
+
const owed = this.owed;
|
|
1188
|
+
if (owed === undefined)
|
|
1189
|
+
return undefined;
|
|
1190
|
+
const refusal = await this.pageWindow(owed, generation);
|
|
1191
|
+
if (refusal === undefined)
|
|
1192
|
+
this.owed = undefined;
|
|
1193
|
+
return refusal;
|
|
1194
|
+
}
|
|
1195
|
+
async planPages(window) {
|
|
1196
|
+
const chart = this.identity !== undefined ? await this.chartRowsOf(this.identity.chartIndex) : undefined;
|
|
1197
|
+
return planWrunSocketPages({
|
|
1198
|
+
window,
|
|
1199
|
+
intervalMs: this.intervalMs(),
|
|
1200
|
+
pageBars: this.pageBars(),
|
|
1201
|
+
heldTs: (this.current?.rows ?? []).map((row) => row.ts),
|
|
1202
|
+
answered: this.answered,
|
|
1203
|
+
reask: this.coldHeads(),
|
|
1204
|
+
...(chart !== undefined ? { chartRows: chart.rows } : {}),
|
|
1205
|
+
...(chart?.syntheticFlags !== undefined ? { chartSyntheticFlags: chart.syntheticFlags } : {}),
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
async chartRowsOf(chartIndex) {
|
|
1209
|
+
try {
|
|
1210
|
+
return await (this.deps.chartRows ?? wrunChartHostEnv().chart.mainRows)(chartIndex);
|
|
1211
|
+
}
|
|
1212
|
+
catch (error) {
|
|
1213
|
+
console.warn('[wrun] socket row source could not read the chart bars:', error);
|
|
1214
|
+
return undefined;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
/** What the session holds and the cloud answered, to tell a round that added nothing. */
|
|
1218
|
+
coverageMark() {
|
|
1219
|
+
const spans = this.answered.map((span) => `${span.fromMs}-${span.toMs}`).join(',');
|
|
1220
|
+
return `${this.current?.rows.length ?? 0}|${spans}`;
|
|
1221
|
+
}
|
|
1222
|
+
/** The span a session covers: its answered windows, its rows and the window it owes. */
|
|
1223
|
+
coveredWindow(session) {
|
|
1224
|
+
let fromMs = Number.POSITIVE_INFINITY;
|
|
1225
|
+
let toMs = Number.NEGATIVE_INFINITY;
|
|
1226
|
+
for (const span of this.owed !== undefined ? [...this.answered, this.owed] : this.answered) {
|
|
1227
|
+
fromMs = Math.min(fromMs, span.fromMs);
|
|
1228
|
+
toMs = Math.max(toMs, span.toMs);
|
|
1229
|
+
}
|
|
1230
|
+
if (session.rows.length > 0) {
|
|
1231
|
+
fromMs = Math.min(fromMs, session.rows[0].ts);
|
|
1232
|
+
toMs = Math.max(toMs, session.rows[session.rows.length - 1].ts);
|
|
1233
|
+
}
|
|
1234
|
+
return { fromMs, toMs };
|
|
1235
|
+
}
|
|
1236
|
+
// ── Batches ────────────────────────────────────────────────────────────────────────────────
|
|
1237
|
+
/** The session's rows, cell rows and snapshots inside a window, stamped with the socket's losses as the answer to
|
|
1238
|
+
* the session's create arrived (`sessionLosses`), with the elements the cloud skipped as it answered them. */
|
|
1239
|
+
batchOf(window, withSheet) {
|
|
1240
|
+
const session = this.current;
|
|
1241
|
+
if (session === undefined) {
|
|
1242
|
+
return {
|
|
1243
|
+
window: { ...window },
|
|
1244
|
+
asOfMs: Number.NaN,
|
|
1245
|
+
rows: [],
|
|
1246
|
+
grids: [],
|
|
1247
|
+
frames: undefined,
|
|
1248
|
+
handles: undefined,
|
|
1249
|
+
refusals: [],
|
|
1250
|
+
...runLevelFields(this.runLevel),
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
const start = firstAtOrAfter(session.rows, window.fromMs);
|
|
1254
|
+
const end = firstAtOrAfter(session.rows, window.toMs + 1);
|
|
1255
|
+
const grids = [...session.grids.values()].map((grid) => ({
|
|
1256
|
+
...grid,
|
|
1257
|
+
rows: grid.rows.filter((row) => row[0] >= window.fromMs && row[0] <= window.toMs),
|
|
1258
|
+
}));
|
|
1259
|
+
return {
|
|
1260
|
+
window: { ...window },
|
|
1261
|
+
asOfMs: session.asOfMs,
|
|
1262
|
+
rows: session.rows.slice(start, end),
|
|
1263
|
+
grids,
|
|
1264
|
+
frames: session.frames !== undefined ? [...session.frames] : undefined,
|
|
1265
|
+
handles: rebasedHandles(session.handles, start),
|
|
1266
|
+
refusals: session.refusals.map((refusal) => ({ ...refusal })),
|
|
1267
|
+
...(withSheet ? { sheet: session.sheet } : {}),
|
|
1268
|
+
...runLevelFields(this.runLevel),
|
|
1269
|
+
...(this.lossesAtOpen !== undefined ? { sessionLosses: this.lossesAtOpen } : {}),
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
/** A refused ask: the session's batch over the window (nothing, for a refused create), with the
|
|
1273
|
+
* refusal's code for the whole run (the refusal itself kept by its entry, wrunSocketRunRefusalOf: its facts with it,
|
|
1274
|
+
* wrunSocketRefusalFactsOf). */
|
|
1275
|
+
refusalBatch(window, refusal) {
|
|
1276
|
+
const batch = this.batchOf(window, false);
|
|
1277
|
+
const entry = { family: refusal.family ?? WRUN_SOCKET_RUN_REFUSAL_FAMILY, code: refusal.code };
|
|
1278
|
+
runRefusals.set(entry, refusal);
|
|
1279
|
+
return { ...batch, refusals: [...batch.refusals, entry] };
|
|
1280
|
+
}
|
|
1281
|
+
// ── Live frames ────────────────────────────────────────────────────────────────────────────
|
|
1282
|
+
/** A live session follows the transport's frames; a historical one has none. */
|
|
1283
|
+
followLive() {
|
|
1284
|
+
if (this.historical) {
|
|
1285
|
+
this.unsubscribeLive?.();
|
|
1286
|
+
this.unsubscribeLive = undefined;
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
if (this.unsubscribeLive !== undefined || this.transport === undefined)
|
|
1290
|
+
return;
|
|
1291
|
+
this.unsubscribeLive = this.transport.live((output) => this.onLiveOutput(output));
|
|
1292
|
+
}
|
|
1293
|
+
onLiveOutput(output) {
|
|
1294
|
+
if (this.closed)
|
|
1295
|
+
return;
|
|
1296
|
+
const generation = this.generation;
|
|
1297
|
+
void this.serial(async () => {
|
|
1298
|
+
if (this.closed || generation !== this.generation)
|
|
1299
|
+
return;
|
|
1300
|
+
const read = await readWrunHostedWire(output);
|
|
1301
|
+
// An unreadable frame is skipped: the next result repaints.
|
|
1302
|
+
if (read.kind !== 'wire' || this.closed || generation !== this.generation)
|
|
1303
|
+
return;
|
|
1304
|
+
const level = await wrunSocketRunLevelOf(output, 'live');
|
|
1305
|
+
if (this.closed || generation !== this.generation)
|
|
1306
|
+
return;
|
|
1307
|
+
const identity = this.storeIdentity(generation);
|
|
1308
|
+
// A frame before the session's first answer (or of a patch not yet answered) has nothing to extend.
|
|
1309
|
+
if (this.current?.identity !== identity)
|
|
1310
|
+
return;
|
|
1311
|
+
const merge = mergeWrunHostedReply(this.current, read.wire, { identity, kind: 'live' }, WRUN_SOCKET_ROW_STORE_UNCAPPED);
|
|
1312
|
+
if ('refused' in merge)
|
|
1313
|
+
return;
|
|
1314
|
+
this.current = merge.session;
|
|
1315
|
+
// A frame that carries a run-level key replaces the session's newest (the next batch reads it).
|
|
1316
|
+
if (level.strategy !== undefined)
|
|
1317
|
+
this.runLevel = { ...this.runLevel, strategy: level.strategy };
|
|
1318
|
+
if (level.diagnostics !== undefined)
|
|
1319
|
+
this.runLevel = { ...this.runLevel, diagnostics: level.diagnostics };
|
|
1320
|
+
if (level.skipped !== undefined)
|
|
1321
|
+
this.runLevel = { ...this.runLevel, skipped: level.skipped };
|
|
1322
|
+
this.emitFrame(read.wire, merge, level);
|
|
1323
|
+
}).catch((error) => {
|
|
1324
|
+
console.warn('[wrun] socket row source live frame skipped:', error);
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
/** The bars a live frame moved, as a batch: the session's rows from the frame's first bar, its cell
|
|
1328
|
+
* rows, its handles re-based onto those rows, the frames the frame replaced, the refusals, and the
|
|
1329
|
+
* run-level keys the frame itself carried, its list composed with the session's served legs (a frame
|
|
1330
|
+
* never names them, and its list replaces the legend's rows: an empty one keeps the legs' warnings). */
|
|
1331
|
+
emitFrame(wire, merge, level) {
|
|
1332
|
+
const listener = this.listener;
|
|
1333
|
+
if (listener === undefined)
|
|
1334
|
+
return;
|
|
1335
|
+
const session = merge.session;
|
|
1336
|
+
const start = wire.rows.length > 0 ? firstAtOrAfter(session.rows, wire.rows[0].ts) : session.rows.length;
|
|
1337
|
+
const frame = {
|
|
1338
|
+
window: { ...wire.window },
|
|
1339
|
+
asOfMs: session.asOfMs,
|
|
1340
|
+
rows: session.rows.slice(start),
|
|
1341
|
+
grids: wire.grids,
|
|
1342
|
+
frames: merge.acceptedSnapshots && wire.frames !== undefined ? session.frames : undefined,
|
|
1343
|
+
handles: rebasedHandles(session.handles, start),
|
|
1344
|
+
refusals: session.refusals.map((refusal) => ({ ...refusal })),
|
|
1345
|
+
...runLevelFields({ ...level, servedLegs: this.runLevel.servedLegs }),
|
|
1346
|
+
};
|
|
1347
|
+
try {
|
|
1348
|
+
listener(frame);
|
|
1349
|
+
}
|
|
1350
|
+
catch (error) {
|
|
1351
|
+
console.warn('[wrun] socket row source frame listener failed:', error);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
// ── The one extra ask after a refusal for absent facts ───────────────────────────────────────────
|
|
1356
|
+
/**
|
|
1357
|
+
* The cloud refused a hosted ask of this overlay because fact lists an input reads were absent from its payload:
|
|
1358
|
+
* the socket worker names them from the error frame (`details.wrunRefusal.needsFacts`) as
|
|
1359
|
+
* `KScriptMessages.WRUN_FACTS_NEEDED`, before the ask fails, and the WorkerManager routes them here
|
|
1360
|
+
* (wrun-browser-runtime.md "The one extra ask"). The names this client knows are remembered for the overlay
|
|
1361
|
+
* (`noteWrunHostedFactsAsked`:
|
|
1362
|
+
* its payloads send them from now on, beside the sheet's own), and once the market directory has a definite
|
|
1363
|
+
* non-empty answer for every list asked (`wrunAskedFactsReady` for the chart's coin, the glue's wait) the refused ask
|
|
1364
|
+
* goes again: an ask of a source following the overlay that still waits on the socket takes the retry and asks again
|
|
1365
|
+
* itself when it fails (a create as a recreate, a page through the range); with none waiting, the overlay reruns
|
|
1366
|
+
* through the lifecycle door (`requestWrunOverlayRerun`, reason `source-recovery`: a recreate on a fresh source,
|
|
1367
|
+
* held while the overlay is paused or tripped, its chart replays, or it left). Once per overlay and fact set (a later
|
|
1368
|
+
* refusal naming the same lists asks nothing more; refusals answered together ask once); a definite none (no coin,
|
|
1369
|
+
* a coin the ETF family does not cover, no fund listed) asks nothing and the refusal stands. Structured data only,
|
|
1370
|
+
* never a refusal's words. Never rejects.
|
|
1371
|
+
*/
|
|
1372
|
+
export function routeWrunSocketFactsNeeded(chartIndex, indicatorId, needsFacts) {
|
|
1373
|
+
const retry = wrunSocketFactsRetry(chartIndex, indicatorId, needsFacts);
|
|
1374
|
+
// Handed over in this turn: the ask still waiting meets its refusal with the retry in hand.
|
|
1375
|
+
let handed = false;
|
|
1376
|
+
for (const source of factsFollowers.get(overlayKeyOf({ chartIndex, indicatorId })) ?? []) {
|
|
1377
|
+
if (source.takeFactsRetry(retry))
|
|
1378
|
+
handed = true;
|
|
1379
|
+
}
|
|
1380
|
+
return retry.then(async (claim) => {
|
|
1381
|
+
if (handed || claim?.() !== true)
|
|
1382
|
+
return;
|
|
1383
|
+
try {
|
|
1384
|
+
const { requestWrunOverlayRerun } = await wrunChartHostEnv().run.loadOverlayLifecycleDoor();
|
|
1385
|
+
await (requestWrunOverlayRerun(chartIndex, indicatorId, 'source-recovery') || undefined);
|
|
1386
|
+
}
|
|
1387
|
+
catch (error) {
|
|
1388
|
+
console.warn(`[wrun] hosted facts rerun skipped for '${indicatorId}' (chart ${chartIndex}):`, error);
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
/** Remember the lists, wait for the directory, and hand back the retry's claim (undefined when none is due: no
|
|
1393
|
+
* list this client knows, a definite none, a failure). Never rejects. */
|
|
1394
|
+
async function wrunSocketFactsRetry(chartIndex, indicatorId, needsFacts) {
|
|
1395
|
+
try {
|
|
1396
|
+
const [{ readWrunNeededFacts }, facts] = await Promise.all([
|
|
1397
|
+
import('./wrun-param-map.util.js'),
|
|
1398
|
+
import('./wrun-etf-funds.util.js'),
|
|
1399
|
+
]);
|
|
1400
|
+
const kinds = readWrunNeededFacts(needsFacts);
|
|
1401
|
+
if (kinds.length === 0)
|
|
1402
|
+
return undefined;
|
|
1403
|
+
const asked = facts.noteWrunHostedFactsAsked(chartIndex, indicatorId, kinds);
|
|
1404
|
+
if (!(await facts.wrunAskedFactsReady(asked, await wrunChartCoinOf(chartIndex))))
|
|
1405
|
+
return undefined;
|
|
1406
|
+
const key = overlayKeyOf({ chartIndex, indicatorId });
|
|
1407
|
+
const identity = asked.join(',');
|
|
1408
|
+
return () => {
|
|
1409
|
+
// Read and written with no await between: refusals answered together ask once, and a set a newer refusal
|
|
1410
|
+
// grew is that refusal's to ask.
|
|
1411
|
+
if (factsAskedAgain.get(key) === identity)
|
|
1412
|
+
return false;
|
|
1413
|
+
if (facts.wrunHostedFactsAsked(chartIndex, indicatorId).join(',') !== identity)
|
|
1414
|
+
return false;
|
|
1415
|
+
factsAskedAgain.set(key, identity);
|
|
1416
|
+
return true;
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
catch (error) {
|
|
1420
|
+
console.warn(`[wrun] hosted facts ask skipped for '${indicatorId}' (chart ${chartIndex}):`, error);
|
|
1421
|
+
return undefined;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
/** The chart's coin, read where the protected payload reads it (the chart metadata's `coin`). */
|
|
1425
|
+
async function wrunChartCoinOf(chartIndex) {
|
|
1426
|
+
try {
|
|
1427
|
+
const { useChartStore } = await wrunChartHostEnv().chart.loadChartStore();
|
|
1428
|
+
return useChartStore().mergedAllCharts[chartIndex]?.metadata?.coin;
|
|
1429
|
+
}
|
|
1430
|
+
catch {
|
|
1431
|
+
return undefined;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
/** The run attempt an overlay's ask belongs to (the refusal surface's live token, `<chart>:<overlay>#<generation>`),
|
|
1435
|
+
* read as the ask is built, so the record of its failure names it for the monitoring join. None when no attempt is
|
|
1436
|
+
* open or the surface did not load. Never rejects. */
|
|
1437
|
+
export async function wrunSocketAttemptIdOf(chartIndex, indicatorId) {
|
|
1438
|
+
try {
|
|
1439
|
+
const { liveWrunRefusalAttempt } = await wrunChartHostEnv().run.loadRefusalSurface();
|
|
1440
|
+
const token = liveWrunRefusalAttempt(chartIndex, indicatorId);
|
|
1441
|
+
return token !== null ? `${token.key}#${token.generation}` : undefined;
|
|
1442
|
+
}
|
|
1443
|
+
catch {
|
|
1444
|
+
return undefined;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
/** What the cloud asked an overlay's session for (a refusal's absent facts, `noteWrunHostedFactsAsked`) and its one
|
|
1448
|
+
* extra ask leave with the session's end (the transport's, under its fence). Never rejects. */
|
|
1449
|
+
export function forgetWrunSocketFacts(chartIndex, indicatorId) {
|
|
1450
|
+
factsAskedAgain.delete(overlayKeyOf({ chartIndex, indicatorId }));
|
|
1451
|
+
void import('./wrun-etf-funds.util.js')
|
|
1452
|
+
.then(({ forgetWrunHostedFactsAsked }) => forgetWrunHostedFactsAsked(chartIndex, indicatorId))
|
|
1453
|
+
.catch(() => undefined);
|
|
1454
|
+
}
|
|
1455
|
+
// ── The one reading of a failed ask ──────────────────────────────────────────────────────────────
|
|
1456
|
+
/** The run capability literals the protected fetch fails with (data-fetching.util, the bridge's ensure outcomes): the
|
|
1457
|
+
* mint did not land within the transient grace the bridge waits (in visible time), or it denied the run. Neither sent
|
|
1458
|
+
* the ask. */
|
|
1459
|
+
const CAPABILITY_UNAVAILABLE = /\bKSCRIPT_CAPABILITY_UNAVAILABLE\b/;
|
|
1460
|
+
const CAPABILITY_DENIED = /\bKSCRIPT_CAPABILITY_DENIED\b/;
|
|
1461
|
+
/**
|
|
1462
|
+
* The kScript socket's own failures (kscript-transport-codes), by the transient reason each is: the socket closed
|
|
1463
|
+
* with the ask on it (`connection-lost`), the dial failed before the ask went (`dial-failed`), the keepalive retired a
|
|
1464
|
+
* socket that stopped answering (`socket-stale`), the data worker restarted under the ask (`worker-restarted`), no run
|
|
1465
|
+
* capability in time (`capability-unavailable`). Read by the code, never by the words around it.
|
|
1466
|
+
*/
|
|
1467
|
+
const KSCRIPT_TRANSPORT_REASONS = Object.freeze({
|
|
1468
|
+
[KSCRIPT_TRANSPORT_DISCONNECTED]: 'connection-lost',
|
|
1469
|
+
[KSCRIPT_TRANSPORT_DIAL_FAILED]: 'dial-failed',
|
|
1470
|
+
[KSCRIPT_TRANSPORT_STALE]: 'socket-stale',
|
|
1471
|
+
[KSCRIPT_WORKER_RESTARTED]: 'worker-restarted',
|
|
1472
|
+
[KSCRIPT_CAPABILITY_UNAVAILABLE]: 'capability-unavailable',
|
|
1473
|
+
});
|
|
1474
|
+
/** The code a failure's message leads with (the worker writes the code first): an upper-case word the rest does not
|
|
1475
|
+
* continue. */
|
|
1476
|
+
const LEADING_CODE = /^([A-Z][A-Z0-9_]*)(?![A-Za-z0-9_])/;
|
|
1477
|
+
/** The transient reason of the kScript socket code a failure carries: its `code` (a worker that attached one), else
|
|
1478
|
+
* the code its message leads with; undefined for any other failure. */
|
|
1479
|
+
function kscriptTransportReasonOf(failure, message) {
|
|
1480
|
+
const carried = failure.code;
|
|
1481
|
+
const code = typeof carried === 'string' && Object.hasOwn(KSCRIPT_TRANSPORT_REASONS, carried)
|
|
1482
|
+
? carried
|
|
1483
|
+
: LEADING_CODE.exec(message)?.[1];
|
|
1484
|
+
return code !== undefined && Object.hasOwn(KSCRIPT_TRANSPORT_REASONS, code)
|
|
1485
|
+
? KSCRIPT_TRANSPORT_REASONS[code]
|
|
1486
|
+
: undefined;
|
|
1487
|
+
}
|
|
1488
|
+
/** An abort (a DOMException or an Error named `AbortError`). */
|
|
1489
|
+
function isAbortFailure(failure) {
|
|
1490
|
+
return failure.name === 'AbortError';
|
|
1491
|
+
}
|
|
1492
|
+
/** The kScript socket worker's request deadline: a createScript, rangeChanged or changeSettings it sent and waited on
|
|
1493
|
+
* past its timer rejects with these words (kscript-ws.worker.service), which reach the transport as they are. */
|
|
1494
|
+
const REQUEST_TIMEOUT = /^Request timeout\b/;
|
|
1495
|
+
/** The record of the cloud's upstream market-data read failing (`isKScriptDataUnavailableError`): the run could not
|
|
1496
|
+
* load its data, which a second ask gets past once the data is back (Retry, and the heal ladder's retryable class). */
|
|
1497
|
+
const DATA_UNAVAILABLE_SEED = { cls: 'service-no-answer', variant: 'market-data' };
|
|
1498
|
+
/**
|
|
1499
|
+
* The one reading of a failed ask (the transport's error seam, wrun-browser-runtime.md "Failure classification"): what
|
|
1500
|
+
* the source and the pass meet for what the capability bridge or the cloud answered, read by code (WRUN-PARITY-PLAN
|
|
1501
|
+
* row 21), never by a pattern over the cloud's sentence.
|
|
1502
|
+
*
|
|
1503
|
+
* - The run capability: a mint that did not land within the bridge's wait (the transient grace) is transient
|
|
1504
|
+
* (`capability-unavailable`: the
|
|
1505
|
+
* pass's Retry and the heal ladder; the mint keeps running, so the next ask resolves from it); a denied one is the
|
|
1506
|
+
* access door's (`WrunSocketAccessDeniedError`): the bridge's denial sent nothing, and the cloud's (its FORBIDDEN
|
|
1507
|
+
* frame, read by the envelope's one classifier, `isKScriptCapabilityDeniedError`) answered an ask that went, past
|
|
1508
|
+
* the transport's one forced re-mint (`dispatched`).
|
|
1509
|
+
* - The worker's request deadline is transient (`request-timeout`: the pass's Retry): the ask went and no answer came
|
|
1510
|
+
* in time, so the next ask may answer.
|
|
1511
|
+
* - A superseded create's answer (the server answer table's `stale` verdict, wrun-hosted-wire-caps
|
|
1512
|
+
* `wrunServerAnswerOfText`) can only be the live attempt's own: the session-lost refusal (`WRUN_SESSION_LOST_CODE`,
|
|
1513
|
+
* a note with Retry), stamped a foreign supersede. The socket worker settles a replaced attempt's answer through
|
|
1514
|
+
* its marker before any of this.
|
|
1515
|
+
* - A refusal the worker keeps for good (the answer table's `memory`, `wrunFrameRefusalMemory`) is a `WrunSocketRefusalError`
|
|
1516
|
+
* of the code and the facts the error frame's `details.wrunRefusal` named (the socket worker relays them,
|
|
1517
|
+
* `wrunFrameRefusalOf`), else the code an older server's sentence leads with, else the frame's own code; the frame
|
|
1518
|
+
* is its message (the record's details). The source answers it as a refusal batch, and its record reads the code
|
|
1519
|
+
* (wrun-refusal.util `wrunCloudRefusalSeed`, against the chart the pass ran on).
|
|
1520
|
+
* - Our upstream market-data read failing (the error envelope's `DATA_UNAVAILABLE`, `isKScriptDataUnavailableError`)
|
|
1521
|
+
* keeps the frame's own error with the market-data record (`service-no-answer`, the envelope's own words and chip,
|
|
1522
|
+
* never the service names the frame carries), so the pass's Retry and the heal ladder re-ask it once the data is
|
|
1523
|
+
* back.
|
|
1524
|
+
* - Anything else passes as it came: a refusal that may pass on the next ask (one the kit raises while it reads the
|
|
1525
|
+
* window's data, a connection's cap, the no-candles answer) keeps the frame's own error, whose record the pass reads
|
|
1526
|
+
* by the code the frame names (`wrunRefusalFor`), as it reads a frame of no refusal or a transport failure.
|
|
1527
|
+
* - The kScript socket's own failures read by their code (kscript-transport-codes, `KSCRIPT_TRANSPORT_REASONS`), each a
|
|
1528
|
+
* transient reason the failure cause names word for word (wrun-failure-cause): `connection-lost`, `socket-stale`
|
|
1529
|
+
* and `worker-restarted` (the ask may have gone), `dial-failed` (nothing went: marked never sent,
|
|
1530
|
+
* `isWrunSocketAskUnsent`, so its create takes no session of the overlay), `capability-unavailable`. An abort is one
|
|
1531
|
+
* the ask's own signal did not cause (the transport answers its own stop before it reads a failure: a chart switch
|
|
1532
|
+
* cancelling the overlay's fetch): transient `aborted`, Retry, never the blocking generic failure.
|
|
1533
|
+
* - A thrown value that is no object (the V2 fetch hands a worker's terminal text over as a bare string) rides as an
|
|
1534
|
+
* Error of its words, its value as the cause, so the transport's stamp (the ask's clientRequestId) and the record's
|
|
1535
|
+
* cause ride it: a bare string used to reach the record unstamped, as `other`.
|
|
1536
|
+
*/
|
|
1537
|
+
export function wrunSocketAskFailure(error) {
|
|
1538
|
+
const failure = typeof error === 'object' && error !== null ? error : new Error(String(error), { cause: error });
|
|
1539
|
+
if (isWrunRowSourceTransientError(failure) ||
|
|
1540
|
+
failure instanceof WrunSocketRefusalError ||
|
|
1541
|
+
isWrunOverlayPausedError(failure)) {
|
|
1542
|
+
return failure;
|
|
1543
|
+
}
|
|
1544
|
+
const message = failure instanceof Error ? failure.message : String(failure);
|
|
1545
|
+
const transport = kscriptTransportReasonOf(failure, message);
|
|
1546
|
+
if (transport === 'dial-failed')
|
|
1547
|
+
return unsentAskFailure(new WrunRowSourceTransientError(transport, failure));
|
|
1548
|
+
if (transport !== undefined)
|
|
1549
|
+
return new WrunRowSourceTransientError(transport, failure);
|
|
1550
|
+
if (CAPABILITY_UNAVAILABLE.test(message))
|
|
1551
|
+
return new WrunRowSourceTransientError('capability-unavailable', failure);
|
|
1552
|
+
if (CAPABILITY_DENIED.test(message))
|
|
1553
|
+
return new WrunSocketAccessDeniedError(message);
|
|
1554
|
+
if (wrunChartHostEnv().transport.isCapabilityDeniedError(failure)) {
|
|
1555
|
+
return new WrunSocketAccessDeniedError(message, true);
|
|
1556
|
+
}
|
|
1557
|
+
if (REQUEST_TIMEOUT.test(message))
|
|
1558
|
+
return new WrunRowSourceTransientError('request-timeout', failure);
|
|
1559
|
+
if (isAbortFailure(failure))
|
|
1560
|
+
return new WrunRowSourceTransientError('aborted', failure);
|
|
1561
|
+
// Our upstream market-data read failed (the error envelope's DATA_UNAVAILABLE): the frame as it came, so the heal
|
|
1562
|
+
// ladder re-asks it, with the record that says so in plain words instead of the service names it carries.
|
|
1563
|
+
if (wrunChartHostEnv().transport.isDataUnavailableError(failure)) {
|
|
1564
|
+
return attachWrunRefusal(failure instanceof Error ? failure : new Error(message), DATA_UNAVAILABLE_SEED);
|
|
1565
|
+
}
|
|
1566
|
+
// A superseded create's answer reaches here only as the live attempt's own (the socket worker settles a replaced
|
|
1567
|
+
// attempt's through its marker): another chart or tab took the session, the session-lost refusal.
|
|
1568
|
+
const answer = wrunServerAnswerOfText(message);
|
|
1569
|
+
if (answer?.verdict === 'stale') {
|
|
1570
|
+
const lost = new WrunSocketRefusalError(WRUN_SESSION_LOST_CODE);
|
|
1571
|
+
lost.message = message;
|
|
1572
|
+
return stampWrunRefusalTelemetry(lost, { foreignSupersede: true });
|
|
1573
|
+
}
|
|
1574
|
+
// Kept for good only when the answer table remembers it (its `memory`, wrunFrameRefusalMemory's rows).
|
|
1575
|
+
if (answer?.memory === undefined || wrunErrorFrameCodeOf(message) === undefined)
|
|
1576
|
+
return failure;
|
|
1577
|
+
const { code, ...facts } = wrunFrameRefusalOf(message) ?? { code: wrunErrorFrameCodeOf(message) ?? 'wrun_refused' };
|
|
1578
|
+
const refusal = new WrunSocketRefusalError(code, undefined, facts);
|
|
1579
|
+
refusal.message = message;
|
|
1580
|
+
return refusal;
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* The failure a page of a create's window rejects with (the row-source factory's adapter pages the rest of the window
|
|
1584
|
+
* after the newest page the create answered): one with a verdict of its own as it came (a stop, a refusal, a frame
|
|
1585
|
+
* naming a refusal's code, the record a seed attaches, the access door's hold, a transient), any other (a failed or
|
|
1586
|
+
* unreadable page) as the transient error of an incomplete first paging. Never a clean success over history the cloud
|
|
1587
|
+
* did not answer.
|
|
1588
|
+
*/
|
|
1589
|
+
export function wrunSocketPagingFailure(error) {
|
|
1590
|
+
const verdict = error instanceof WrunChartGoneError ||
|
|
1591
|
+
error instanceof WrunSocketRowSourceStopped ||
|
|
1592
|
+
error instanceof WrunSocketRefusalError ||
|
|
1593
|
+
isWrunOverlayPausedError(error) ||
|
|
1594
|
+
isWrunRowSourceTransientError(error) ||
|
|
1595
|
+
wrunRefusalSeedOf(error) !== undefined ||
|
|
1596
|
+
wrunFrameRefusalOf(error instanceof Error ? error.message : String(error)) !== undefined;
|
|
1597
|
+
return verdict ? error : new WrunRowSourceTransientError('paging-incomplete', error);
|
|
1598
|
+
}
|
|
1599
|
+
/** The overlay's declarations a create carries live (C4): its input rows, which the cloud reads the settings record
|
|
1600
|
+
* over. The sheet's params ride the payload view of the sheet the source runs (wrun-cloud-record.util
|
|
1601
|
+
* `wrunSocketPayloadSettings`): a cloud record persists no sheet (lane parity U16). */
|
|
1602
|
+
const WRUN_SOCKET_LIVE_DECLARATIONS = ['scriptInputs'];
|
|
1603
|
+
/**
|
|
1604
|
+
* The settings a socket ask's protected payload is built from, by the ask's kind (contracts C4, C5 and C7; the wave-3
|
|
1605
|
+
* review round 3). Each reads what the session or the ask holds, never the overlay's saved settings beneath the record:
|
|
1606
|
+
* a key a save the cloud refused added stays in them (the store saved it) while the source rolled back to the record
|
|
1607
|
+
* the cloud kept, and it would ride an ask of a computation the session never took.
|
|
1608
|
+
* - A page (`range`) carries the session's identity alone: the payload view of its registry identity (the wire
|
|
1609
|
+
* identity, the capability's slug and the protected discriminator, `wrunSocketPayloadSettings`), never a value or a
|
|
1610
|
+
* declaration. It asks the session the worker holds for its window, and the worker reads it with the settings that
|
|
1611
|
+
* session holds (the payload's `sessionPage`, kscript-protected.worker).
|
|
1612
|
+
* - A create carries the record's values under the overlay's live declarations (`scriptInputs`, as the chart holds
|
|
1613
|
+
* them at send time) and the params of the sheet the source runs (the payload view): the rows a delivered sheet
|
|
1614
|
+
* reconciled reach the next create, and a declaration the overlay no longer holds is gone. With no overlay on the
|
|
1615
|
+
* chart, the record whole.
|
|
1616
|
+
* - A settings change carries the record its patch left (the settings the call computes with, whole), less every
|
|
1617
|
+
* value the patch drops.
|
|
1618
|
+
*/
|
|
1619
|
+
export function wrunSocketAskSettings(ask, live) {
|
|
1620
|
+
const settings = ask.record.settings;
|
|
1621
|
+
if (ask.kind === 'range') {
|
|
1622
|
+
const registry = settings.wrunRegistryRef;
|
|
1623
|
+
return wrunSocketPayloadSettings(registry !== undefined ? { wrunRegistryRef: registry } : {});
|
|
1624
|
+
}
|
|
1625
|
+
const carried = { ...settings };
|
|
1626
|
+
if (ask.kind === 'create') {
|
|
1627
|
+
if (typeof live !== 'object' || live === null)
|
|
1628
|
+
return carried;
|
|
1629
|
+
for (const key of WRUN_SOCKET_LIVE_DECLARATIONS) {
|
|
1630
|
+
if (Object.hasOwn(live, key))
|
|
1631
|
+
carried[key] = live[key];
|
|
1632
|
+
else
|
|
1633
|
+
delete carried[key];
|
|
1634
|
+
}
|
|
1635
|
+
return carried;
|
|
1636
|
+
}
|
|
1637
|
+
for (const [key, value] of Object.entries(ask.patch?.settings ?? {})) {
|
|
1638
|
+
if (value === null)
|
|
1639
|
+
delete carried[key];
|
|
1640
|
+
}
|
|
1641
|
+
return carried;
|
|
1642
|
+
}
|
|
1643
|
+
/** The failures the default transports rejected an ask with before they dispatched it (`isWrunSocketAskUnsent`). */
|
|
1644
|
+
const unsentAskFailures = new WeakSet();
|
|
1645
|
+
/** An ask's failure before its dispatch, marked never sent: the failure itself, so it reads as it came everywhere else
|
|
1646
|
+
* (a thrown value that is no object as an Error of its words). */
|
|
1647
|
+
export function unsentAskFailure(error) {
|
|
1648
|
+
const failure = typeof error === 'object' && error !== null ? error : new Error(String(error), { cause: error });
|
|
1649
|
+
unsentAskFailures.add(failure);
|
|
1650
|
+
return failure;
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Whether a default transport rejected an ask with `error` before it dispatched it (the modules the ask loads, the chart
|
|
1654
|
+
* and store reads, the payload builder, the run capability's ensure and the bridge's verdict, a stop before the send):
|
|
1655
|
+
* nothing of that ask reached the worker, so a create failed so replaced no session of the overlay, and its source
|
|
1656
|
+
* takes none (the row-source factory reads this before its own list, `wrunSocketCreateReachedCloud`). A failure past
|
|
1657
|
+
* the dispatch is never marked.
|
|
1658
|
+
*/
|
|
1659
|
+
export function isWrunSocketAskUnsent(error) {
|
|
1660
|
+
return typeof error === 'object' && error !== null && unsentAskFailures.has(error);
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* The run capability a socket ask mints with, read off the payload settings it sends (the slug the capability binds,
|
|
1664
|
+
* `customScriptId`, and the package tuple through the one wire reader, so the mint's tuple equals the payload's). A
|
|
1665
|
+
* mint started before the first ask (the restore pass's warm-up, wrun-registry-loader) reads it here too: the bridge
|
|
1666
|
+
* refuses a second tuple on a slug, so the warm-up's mint is the one the ask joins.
|
|
1667
|
+
*/
|
|
1668
|
+
export function wrunSocketCapabilityOf(settings) {
|
|
1669
|
+
return {
|
|
1670
|
+
scriptId: typeof settings.customScriptId === 'string' ? settings.customScriptId : '',
|
|
1671
|
+
wrun: readWrunWireRef(settings) ?? undefined,
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
/** The resets of the state the web half keeps beside the source's (its default transports' live routes, creates and
|
|
1675
|
+
* ask stamps, the denied overlays), registered as it loads (wrun-socket-transport.ts): the test reset reaches that
|
|
1676
|
+
* state without importing the web half. */
|
|
1677
|
+
const transportStateResets = new Set();
|
|
1678
|
+
/** Register a reset of socket state the web half keeps (run by `__resetWrunSocketRowSourceForTests`). */
|
|
1679
|
+
export function onWrunSocketRowSourceTestReset(reset) {
|
|
1680
|
+
transportStateResets.add(reset);
|
|
1681
|
+
}
|
|
1682
|
+
/** Test reset: the facts routes' state, and the state the web half registered (the default transports' live routes,
|
|
1683
|
+
* creates and ask stamps, the denied overlays). */
|
|
1684
|
+
export function __resetWrunSocketRowSourceForTests() {
|
|
1685
|
+
factsFollowers.clear();
|
|
1686
|
+
factsAskedAgain.clear();
|
|
1687
|
+
for (const reset of transportStateResets)
|
|
1688
|
+
reset();
|
|
1689
|
+
}
|