@orangecharts/wrun-chart-host 0.8.0 → 0.9.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 +2 -1
- package/dist/constants/feature-flags.constants.d.ts +4 -0
- package/dist/constants/feature-flags.constants.js +27 -0
- package/dist/constants/marketCapabilities.constants.d.ts +14 -9
- package/dist/constants/marketCapabilities.constants.js +36 -13
- package/dist/constants/opra-compliance.constants.d.ts +14 -0
- package/dist/constants/opra-compliance.constants.js +14 -0
- package/dist/constants/option-venues.constants.d.ts +11 -6
- package/dist/constants/option-venues.constants.js +5 -2
- package/dist/host-env.d.ts +10 -4
- package/dist/host-ports.types.d.ts +39 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
- package/dist/interfaces/opra-realtime.interface.js +10 -10
- package/dist/interfaces/wrun-runtime.interface.d.ts +34 -13
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +53 -10
- package/dist/kscript-data/controls/live-trades-merge.util.js +81 -16
- package/dist/market-data/billing.interface.d.ts +138 -17
- package/dist/market-data/billing.interface.js +25 -8
- package/dist/market-data/venues/index.d.ts +3 -3
- package/dist/market-data/venues/opra.contract.copy.json +5 -3
- package/dist/market-data/venues/opra.d.ts +3 -3
- package/dist/market-data/venues/opra.js +5 -4
- package/dist/replay/replayLadder.js +3 -1
- package/dist/utility/chart/crypto-index.leaf.d.ts +2 -2
- package/dist/utility/chart/crypto-index.leaf.js +2 -2
- package/dist/utility/chart/index-mode-admission.util.js +9 -1
- package/dist/utility/chart/index-mode.util.d.ts +5 -2
- package/dist/utility/chart/index-mode.util.js +23 -13
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +28 -21
- package/dist/utility/chart/kscript-venue-policy.util.js +30 -24
- package/dist/utility/chart/marketKind.util.d.ts +12 -10
- package/dist/utility/chart/marketKind.util.js +17 -7
- package/dist/utility/chart/om-panel-push-style.util.d.ts +7 -7
- package/dist/utility/chart/om-panel-push-style.util.js +17 -15
- package/dist/utility/chart/om-panel.util.js +6 -6
- package/dist/utility/chart/profile-block-size.util.d.ts +16 -0
- package/dist/utility/chart/profile-block-size.util.js +7 -0
- package/dist/utility/chart/quote-perp.leaf.d.ts +17 -0
- package/dist/utility/chart/quote-perp.leaf.js +20 -0
- package/dist/utility/chart/wrun-run-result.util.d.ts +5 -0
- package/dist/utility/chart/wrun-run-result.util.js +4 -1
- package/dist/utility/common/transformations.util.d.ts +7 -0
- package/dist/utility/common/transformations.util.js +11 -0
- package/dist/utility/options/option-venue.util.d.ts +3 -3
- package/dist/utility/options/option-venue.util.js +3 -3
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +1 -1
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +2 -2
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +2 -2
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +5 -1
- package/dist/utility/wrun/sources/row-lane-registry.js +3 -2
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +9 -3
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +13 -5
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +11 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +63 -9
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +8 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +12 -0
- package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +5 -2
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +5 -2
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +11 -5
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +31 -10
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +33 -1
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +95 -6
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +25 -5
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +55 -18
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +146 -40
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +16 -3
- package/dist/utility/wrun/wrun-batched-marks.util.js +30 -19
- package/dist/utility/wrun/wrun-batched-readout.util.d.ts +37 -9
- package/dist/utility/wrun/wrun-batched-readout.util.js +61 -15
- package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-cell-capacity.leaf.d.ts +66 -0
- package/dist/utility/wrun/wrun-cell-capacity.leaf.js +86 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +147 -9
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +345 -11
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +19 -9
- package/dist/utility/wrun/wrun-color-facts.util.js +24 -14
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +15 -4
- package/dist/utility/wrun/wrun-color-settings.util.js +31 -12
- package/dist/utility/wrun/wrun-dollar-unit-port.leaf.d.ts +17 -0
- package/dist/utility/wrun/wrun-dollar-unit-port.leaf.js +9 -0
- package/dist/utility/wrun/wrun-download-meter.util.d.ts +92 -0
- package/dist/utility/wrun/wrun-download-meter.util.js +122 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +6 -1
- package/dist/utility/wrun/wrun-draft-overlay.util.js +23 -3
- package/dist/utility/wrun/wrun-frames.js +5 -5
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +7 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +33 -17
- package/dist/utility/wrun/wrun-hud-looks.util.js +30 -16
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +8 -6
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +8 -6
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -2
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +6 -2
- package/dist/utility/wrun/wrun-live-intake.util.js +136 -21
- package/dist/utility/wrun/wrun-live-tick.util.js +91 -38
- package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.d.ts +53 -0
- package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.js +162 -0
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +166 -48
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +216 -33
- package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +51 -7
- package/dist/utility/wrun/wrun-market-size-defaults.util.js +314 -56
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +41 -2
- package/dist/utility/wrun/wrun-option-prints.util.js +80 -13
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +3 -0
- package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-option-strike-flow.util.js +55 -0
- package/dist/utility/wrun/wrun-option-views.util.d.ts +51 -7
- package/dist/utility/wrun/wrun-option-views.util.js +151 -28
- package/dist/utility/wrun/wrun-options-stop.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-options-stop.util.js +3 -2
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +31 -14
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +22 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +7 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +25 -1
- package/dist/utility/wrun/wrun-overlay-result.util.d.ts +7 -1
- package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +34 -6
- package/dist/utility/wrun/wrun-overlay-run.util.js +416 -171
- package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +4 -4
- package/dist/utility/wrun/wrun-pack-widths.leaf.js +4 -4
- package/dist/utility/wrun/wrun-pack.util.d.ts +7 -3
- package/dist/utility/wrun/wrun-pack.util.js +20 -9
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +27 -15
- package/dist/utility/wrun/wrun-panel-style.util.js +42 -20
- package/dist/utility/wrun/wrun-param-map.util.d.ts +7 -6
- package/dist/utility/wrun/wrun-param-map.util.js +8 -5
- package/dist/utility/wrun/wrun-param-values.util.d.ts +10 -2
- package/dist/utility/wrun/wrun-param-values.util.js +2 -0
- package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
- package/dist/utility/wrun/wrun-refusal.util.js +10 -1
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +7 -0
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-source-rows.util.js +92 -40
- package/dist/utility/wrun/wrun-tape-source.util.d.ts +126 -50
- package/dist/utility/wrun/wrun-tape-source.util.js +193 -68
- package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +7 -5
- package/dist/utility/wrun/wrun-volume-profile-lane.util.js +8 -6
- package/dist/workers/utils/volume-profile.worker.util.d.ts +4 -1
- package/dist/workers/utils/volume-profile.worker.util.js +5 -2
- package/dist/workers/wrun/wrun-abi-host.js +3 -2
- package/package.json +11 -11
|
@@ -204,8 +204,9 @@ import { attachWrunHandles, wrunHandlesOf } from './wrun-handles.util.js';
|
|
|
204
204
|
import { mergeWrunCandleEvidence, wrunCandleFingerprintsOf } from './wrun-prefix-proof.util.js';
|
|
205
205
|
import { noteWrunLaneRevision } from './wrun-prefix-lanes.util.js';
|
|
206
206
|
import { attachWrunFrames, WRUN_CELL_BLOCK_TOO_LARGE_CODE, wrunAbiVersion, wrunCellTupleWidths, wrunFramesOf, } from './wrun-pack.util.js';
|
|
207
|
+
import { wrunCellBoundWords, wrunSheetCellBlockTuples } from './wrun-cell-capacity.leaf.js';
|
|
207
208
|
import { LIVE_MAX_CELLS_PER_BAR, tradesBarOpenMs, tradesLaneLimits, tradesServedStartMs, } from '../../kscript-data/controls/live-trades-merge.util.js';
|
|
208
|
-
import { parseWrunTapeHistory, wrunTapeFloorSettings, wrunTapeHistoryOf } from './wrun-tape-source.util.js';
|
|
209
|
+
import { isWrunAskedTapeSource, parseWrunTapeHistory, wrunTapeAcquisitionFloor, wrunTapeFloorSettings, wrunTapeFloorSettingWords, wrunTapeHistoryOf, } from './wrun-tape-source.util.js';
|
|
209
210
|
import { serverNowMs } from '../auth/server-clock.util.js';
|
|
210
211
|
import { wrunModuleReadsBarCount } from './wrun-bar-count.util.js';
|
|
211
212
|
import { isWrunBatchedChildRefused, mountWrunChildOverlays } from './wrun-panel-mount.util.js';
|
|
@@ -220,11 +221,11 @@ import { wrunLiveReconcileMaySound } from './wrun-signal-sound-reasons.leaf.js';
|
|
|
220
221
|
import { wrunCanvasChildId, wrunCellRowsOf } from './wrun-canvases.util.js';
|
|
221
222
|
import { readWrunBatchedSections, wrunBatchedChildId, wrunSheetHasBatchedMarks } from './wrun-batched-marks.util.js';
|
|
222
223
|
import { isWrunStyleTargetHidden } from './wrun-color-settings.util.js';
|
|
223
|
-
import { buildWrunOverlayRunResult, closedLegCandles, forgetWrunOverlayCanvasState, openLegCandles, wrunLegReadsFormingOpen, wrunLegReadsLiveCandleOnly, cutWrunOddsLegRows, placeWrunResultTables, presentWrunIntegration, publishWrunRunHealth, publishWrunSessionCanvasNotices, recordWrunHostBuildMs, reseedWrunOverlayFromBuffers, wrunCanvasHostFillFor, wrunChartPriceDigits, wrunHostFillContextFor, wrunLegFetchType, wrunLegPayloadExtras, wrunIntegratedRowsView, wrunSessionCanvasFillOf, wrunSessionPinnedSheet, wrunSessionRespelledSheet, wrunSessionRunHealth, } from './wrun-overlay-run.util.js';
|
|
224
|
+
import { buildWrunOverlayRunResult, closedLegCandles, forgetWrunOverlayCanvasState, openLegCandles, wrunLegReadsFormingOpen, wrunLegReadsLiveCandleOnly, cutWrunOddsLegRows, placeWrunResultTables, presentWrunIntegration, publishWrunRunHealth, publishWrunSessionCanvasNotices, recordWrunHostBuildMs, reseedWrunOverlayFromBuffers, wrunCanvasHostFillFor, wrunChartPriceDigits, wrunHostFillContextFor, wrunLegFetchType, wrunLegPayloadExtras, wrunIntegratedRowsView, wrunSessionCanvasFillOf, wrunSessionPinnedSheet, wrunSessionRespelledSheet, wrunResultMarketUnits, wrunSessionRunHealth, } from './wrun-overlay-run.util.js';
|
|
224
225
|
import { forgetWrunCanvasCache } from './wrun-canvas-cache.util.js';
|
|
225
226
|
import { wrunLegNativeRowsOption } from './wrun-pin-venues.util.js';
|
|
226
227
|
import { wrunSessionChartNamesOf } from './wrun-chart-context-names.util.js';
|
|
227
|
-
import {
|
|
228
|
+
import { wrunReadsMarketFacts } from './wrun-chart-market-facts.util.js';
|
|
228
229
|
import { wrunReadsEarningsFacts } from './wrun-earnings-facts.util.js';
|
|
229
230
|
import { wrunLaneRefusalLeavesWindowOwed, wrunLaneRefusedCodeOf } from './wrun-lane-refusal.leaf.js';
|
|
230
231
|
import { WRUN_RUN_INTERVAL_ROWS_KEY, wrunRunIntervalComputeRows, wrunRunIntervalProjectionOf, wrunRunIntervalRowsThrough, wrunRunIntervalSentRow, wrunRunIntervalSessionOf, } from './wrun-run-interval-session.util.js';
|
|
@@ -237,6 +238,7 @@ import { advanceWrunInputCarry, buildWrunInputTailRows, planWrunPinnedWires, wru
|
|
|
237
238
|
import { isWrunTradesLegLane, WRUN_TRADES_LANES, wrunTradesLegExtras } from './wrun-trades-lane.util.js';
|
|
238
239
|
import { drainWrunLiveIntake, dropWrunLiveQueuedBuckets, dropWrunLiveQueuedLegBuckets, enqueueWrunLiveFrame, markWrunLiveGap, noteWrunLiveIntakeEvent, setWrunLiveDrainRequester, takeWrunLiveGaps, wrunLaneAnswerCoversBucket, wrunLiveBucketTs, wrunLiveIntakeBacklogDue, wrunLiveIntakeStats, WRUN_LIVE_LANE_OF_SCRIPT_SOURCE, } from './wrun-live-intake.util.js';
|
|
239
240
|
import { stampWrunLiveFrameOpra } from './wrun-cloud-opra-stamp.util.js';
|
|
241
|
+
import { createWrunDownloadMeter } from './wrun-download-meter.util.js';
|
|
240
242
|
/** Book frames are full snapshots and book runs are the heavy case: same 1s
|
|
241
243
|
* floor the kScript coalescer applies to orderbook-sourced scripts. */
|
|
242
244
|
const WRUN_BOOK_LIVE_UPDATE_MIN_MS = 1_000;
|
|
@@ -355,6 +357,17 @@ const wrunHiddenHeldIds = new Set();
|
|
|
355
357
|
* which wakes a drain that re-asks the legs. Dropped on teardown. */
|
|
356
358
|
const pinnedCloseTimers = new Map();
|
|
357
359
|
const ledgers = new Map();
|
|
360
|
+
/** Each live session's download meter (wrun-download-meter.util), by session: every reconcile ask charges it. Counted,
|
|
361
|
+
* never budgeted: a reconcile re-asks the newest bars, and the add's attempt settled with its first run. */
|
|
362
|
+
const liveDownloadMeters = new WeakMap();
|
|
363
|
+
function wrunLiveDownloadMeter(context) {
|
|
364
|
+
let meter = liveDownloadMeters.get(context);
|
|
365
|
+
if (meter === undefined) {
|
|
366
|
+
meter = createWrunDownloadMeter(0);
|
|
367
|
+
liveDownloadMeters.set(context, meter);
|
|
368
|
+
}
|
|
369
|
+
return meter;
|
|
370
|
+
}
|
|
358
371
|
function emptyTickStats() {
|
|
359
372
|
return {
|
|
360
373
|
computes: 0,
|
|
@@ -1770,15 +1783,18 @@ export class WrunTapeLiveRefusal extends Error {
|
|
|
1770
1783
|
this.name = 'WrunTapeLiveRefusal';
|
|
1771
1784
|
}
|
|
1772
1785
|
}
|
|
1773
|
-
/** The tape inputs
|
|
1774
|
-
*
|
|
1786
|
+
/** The tape inputs the session asks (isWrunAskedTapeSource: an unasked tape reads zero cells and folds no print), by
|
|
1787
|
+
* declaration order: index, name, `max_cells`, the tuples a bar's block may hold in the module (the packer's own
|
|
1788
|
+
* bound, wrun-cell-capacity.leaf `wrunSheetCellBlockTuples`: the sheet's `capacity ?? max_cells`, unbounded without
|
|
1789
|
+
* either), and whether an oversize block reads empty (C1.2b `missing: "empty"`, the packer's own rule). */
|
|
1775
1790
|
function wrunTapeInputsOf(metadata) {
|
|
1776
1791
|
return metadata.inputs
|
|
1777
|
-
.filter((input) => metadata.inputSources[input.name]
|
|
1792
|
+
.filter((input) => isWrunAskedTapeSource(metadata.inputSources[input.name]))
|
|
1778
1793
|
.map((input) => ({
|
|
1779
1794
|
index: input.index,
|
|
1780
1795
|
name: input.name,
|
|
1781
1796
|
...(input.max_cells !== undefined ? { maxCells: input.max_cells } : {}),
|
|
1797
|
+
capacity: wrunSheetCellBlockTuples(metadata, input),
|
|
1782
1798
|
emptyWhenOversize: metadata.inputSources[input.name]?.missing === 'empty',
|
|
1783
1799
|
}));
|
|
1784
1800
|
}
|
|
@@ -1793,7 +1809,8 @@ function refuseWrunTapeCappedBucket(context) {
|
|
|
1793
1809
|
const input = wrunTapeInputsOf(context.metadata)[0];
|
|
1794
1810
|
throw attachWrunRefusal(new WrunTapeLiveRefusal(`WRUN ${context.metadata.id}: input '${input?.name ?? 'tape'}' bar at ts ${bucket} holds more prints than ` +
|
|
1795
1811
|
`the live tape keeps (${LIVE_MAX_CELLS_PER_BAR}), so its block would be truncated ` +
|
|
1796
|
-
`(${WRUN_CELL_BLOCK_TOO_LARGE_CODE}). Blocks are never truncated: raise
|
|
1812
|
+
`(${WRUN_CELL_BLOCK_TOO_LARGE_CODE}). Blocks are never truncated: raise ${wrunTapeFloorSettingWords(context.metadata)} ` +
|
|
1813
|
+
'so fewer prints qualify'), { cls: 'live-stopped', severity: 'note', out: { kind: 'resume-live' } });
|
|
1797
1814
|
}
|
|
1798
1815
|
/** The intake's queue cap dropped live prints of a tape bar that nothing can restore (a live-edge
|
|
1799
1816
|
* tape, history "0", or a market the large-print table never holds; a restorable loss rides the
|
|
@@ -1807,12 +1824,13 @@ function refuseWrunTapeLostBucket(context) {
|
|
|
1807
1824
|
const input = wrunTapeInputsOf(context.metadata)[0];
|
|
1808
1825
|
throw attachWrunRefusal(new WrunTapeLiveRefusal(`WRUN ${context.metadata.id}: input '${input?.name ?? 'tape'}' bar at ts ${bucket} lost live prints to the ` +
|
|
1809
1826
|
'intake queue cap between drains, and nothing restores them (a live-edge tape with history "0", or a ' +
|
|
1810
|
-
'market the large-print table does not hold), so its block would be incomplete. Raise
|
|
1811
|
-
|
|
1827
|
+
'market the large-print table does not hold), so its block would be incomplete. Raise ' +
|
|
1828
|
+
`${wrunTapeFloorSettingWords(context.metadata)} so fewer prints qualify, or declare a history so the reconcile ` +
|
|
1829
|
+
'can restore them'), { cls: 'live-stopped', severity: 'note', out: { kind: 'resume-live' } });
|
|
1812
1830
|
}
|
|
1813
|
-
/** A forming tape block over its
|
|
1814
|
-
* record reads the counts): a tape bar's block only grows until the bar closes. An input reading
|
|
1815
|
-
*
|
|
1831
|
+
/** A forming tape block over the tuples its module holds a bar in (the packer's bound and refusal, in its words, so
|
|
1832
|
+
* the record reads the counts): a tape bar's block only grows until the bar closes. An input reading an oversize
|
|
1833
|
+
* block as empty (C1.2b) is left to the packer. */
|
|
1816
1834
|
function refuseWrunTapeTailOverCap(context, tailRows) {
|
|
1817
1835
|
const inputs = wrunTapeInputsOf(context.metadata);
|
|
1818
1836
|
if (inputs.length === 0)
|
|
@@ -1820,14 +1838,14 @@ function refuseWrunTapeTailOverCap(context, tailRows) {
|
|
|
1820
1838
|
const width = wrunCellTupleWidths().tape ?? 4;
|
|
1821
1839
|
for (const row of tailRows) {
|
|
1822
1840
|
for (const input of inputs) {
|
|
1823
|
-
if (input.
|
|
1841
|
+
if (input.emptyWhenOversize)
|
|
1824
1842
|
continue;
|
|
1825
1843
|
const tuples = (row.cellBlocks?.get(input.index)?.length ?? 0) / width;
|
|
1826
|
-
if (!(tuples > input.
|
|
1844
|
+
if (!(tuples > input.capacity))
|
|
1827
1845
|
continue;
|
|
1828
1846
|
throw new WrunTapeLiveRefusal(`WRUN ${context.metadata.id}: ${WRUN_CELL_BLOCK_TOO_LARGE_CODE}: input ${input.index} bar at ts ${row.ts} ` +
|
|
1829
|
-
`has ${tuples} cells;
|
|
1830
|
-
`truncated): raise max_cells or
|
|
1847
|
+
`has ${tuples} cells; ${wrunCellBoundWords(input.maxCells, input.capacity)}, so the evaluation is refused ` +
|
|
1848
|
+
`(a block is never truncated): raise max_cells or ${wrunTapeFloorSettingWords(context.metadata)}`);
|
|
1831
1849
|
}
|
|
1832
1850
|
}
|
|
1833
1851
|
}
|
|
@@ -2308,8 +2326,9 @@ async function integrateWrunLiveTail(tail) {
|
|
|
2308
2326
|
// reads like the session's and a superseded run's late lookup never
|
|
2309
2327
|
// retitles it.
|
|
2310
2328
|
chartNames: wrunSessionChartNamesOf(context),
|
|
2311
|
-
// The session market's size unit
|
|
2312
|
-
|
|
2329
|
+
// The session market's size unit (an output its `visible_by` leaves out mounts nothing) and its dollar unit
|
|
2330
|
+
// (the batched marks' `units`), the ones its full run handed the children.
|
|
2331
|
+
...wrunResultMarketUnits(context.market),
|
|
2313
2332
|
// A session at another interval: the run timeline rides the result
|
|
2314
2333
|
// (the adapter's projection places its bar-index drawings).
|
|
2315
2334
|
...(runSession ? { runTimeline: true } : {}),
|
|
@@ -2796,7 +2815,7 @@ function laneSourcesOf(context, ohlcvRows) {
|
|
|
2796
2815
|
tapeRows: context.tapeRows,
|
|
2797
2816
|
// The session's own tape floor, the one its lane was asked at (a param-bound floor the plan
|
|
2798
2817
|
// resolves from these settings).
|
|
2799
|
-
settings: wrunTapeFloorSettings(context.metadata, context.acquisition.tape
|
|
2818
|
+
settings: wrunTapeFloorSettings(context.metadata, wrunTapeAcquisitionFloor(context.acquisition.tape)),
|
|
2800
2819
|
pollLanes: context.pollLanes,
|
|
2801
2820
|
pollLaneRows: context.pollLaneRows,
|
|
2802
2821
|
rowLanes: context.rowLanes,
|
|
@@ -3161,7 +3180,12 @@ async function fetchWrunReconcileLane(context, ledger, lane, fromTs, toTs, meta)
|
|
|
3161
3180
|
// The full run already stamped this overlay's legend; a reconcile
|
|
3162
3181
|
// must not re-stamp it (every stamp is a legend repaint). A session
|
|
3163
3182
|
// at another interval asks its lanes at the run interval.
|
|
3164
|
-
{
|
|
3183
|
+
{
|
|
3184
|
+
...wrunReconcileRunIntervalOption(context),
|
|
3185
|
+
...fetchOptions,
|
|
3186
|
+
silentLegend: true,
|
|
3187
|
+
meter: wrunLiveDownloadMeter(context),
|
|
3188
|
+
}), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${spec.type}' for '${context.fetchKey}'`);
|
|
3165
3189
|
// Packed-lane SUCCESS arrives as the packed transport object: unpack it,
|
|
3166
3190
|
// or a real success misclassifies as a decline.
|
|
3167
3191
|
if (isPackedOhlcvRows(fetched))
|
|
@@ -3220,6 +3244,7 @@ async function askWrunReconcileSourceAnswer(context, ledger, ask, meta) {
|
|
|
3220
3244
|
...(ask.interval === undefined ? wrunReconcileRunIntervalOption(context) : { interval: ask.interval }),
|
|
3221
3245
|
...(ask.nativeRows === true ? { nativeRows: true } : {}),
|
|
3222
3246
|
...(ask.endExclusive === true ? { endExclusive: true } : {}),
|
|
3247
|
+
meter: wrunLiveDownloadMeter(context),
|
|
3223
3248
|
}), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${ask.type}' (${ask.key}) for '${context.fetchKey}'`);
|
|
3224
3249
|
return Array.isArray(fetched) ? fetched : null;
|
|
3225
3250
|
}
|
|
@@ -3482,7 +3507,12 @@ async function fetchWrunReconcileLeg(context, ledger, leg, meta) {
|
|
|
3482
3507
|
const native = leg.nativeRows === true ? { nativeRows: true } : wrunLegNativeRowsOption(leg, context.market?.exchange);
|
|
3483
3508
|
const fetchType = wrunLegFetchType(leg);
|
|
3484
3509
|
const ask = async (fromTs, toTs, options, onSourceVerdict) => {
|
|
3485
|
-
const fetched = await withWrunDeadline(wrunChartHostEnv().transport.fetchSource(context.chartIndex, fetchType, { symbol: 'currentSymbol', exchange: 'currentExchange', ...wrunLegPayloadExtras(leg) }, fromTs, toTs, meta, `${context.fetchKey}-live-${suffix}`, false, {
|
|
3510
|
+
const fetched = await withWrunDeadline(wrunChartHostEnv().transport.fetchSource(context.chartIndex, fetchType, { symbol: 'currentSymbol', exchange: 'currentExchange', ...wrunLegPayloadExtras(leg) }, fromTs, toTs, meta, `${context.fetchKey}-live-${suffix}`, false, {
|
|
3511
|
+
silentLegend: true,
|
|
3512
|
+
...options,
|
|
3513
|
+
...(onSourceVerdict !== undefined ? { onSourceVerdict } : {}),
|
|
3514
|
+
meter: wrunLiveDownloadMeter(context),
|
|
3515
|
+
}), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${fetchType}' (${suffix}) for '${context.fetchKey}'`);
|
|
3486
3516
|
if (isPackedOhlcvRows(fetched))
|
|
3487
3517
|
return unpackOhlcvRows(fetched);
|
|
3488
3518
|
return Array.isArray(fetched) ? fetched : [];
|
|
@@ -3660,8 +3690,9 @@ function noteWrunRunIntervalLive(context, session, details) {
|
|
|
3660
3690
|
* lane's covered watermark advances to the window's end, and a closed bar
|
|
3661
3691
|
* (before the session watermark) whose value changed reports as revised.
|
|
3662
3692
|
*
|
|
3663
|
-
* Every answered row is installed whatever its stamp
|
|
3664
|
-
*
|
|
3693
|
+
* Every answered row is installed whatever its stamp (but a row lane drawing
|
|
3694
|
+
* its first slice alone, `rowLaneFilling`, takes none before the slice), so a
|
|
3695
|
+
* revision is looked for over every row the answer can replace: from the window's start
|
|
3665
3696
|
* or the earliest answered row, whichever is earlier. A control may answer
|
|
3666
3697
|
* rows stamped before its window (a monthly series answers the month its
|
|
3667
3698
|
* window opens inside, stamped on the 1st); such a row used to overwrite the
|
|
@@ -3679,7 +3710,12 @@ servedStartMs) {
|
|
|
3679
3710
|
// window's day, the lane's lookback earlier): the answer is authoritative
|
|
3680
3711
|
// from there, and a revised or late-published day is detected from there,
|
|
3681
3712
|
// not from the chart-bar window.
|
|
3682
|
-
|
|
3713
|
+
// A row lane drawing its first slice alone (`rowLaneFilling`, by the slice's first bar): the reconcile lands none of
|
|
3714
|
+
// its rows before that bar. Those bars read partial until the fill, with the earlier bars of their session, so a row
|
|
3715
|
+
// landed on one would sum a session from its middle; the fill's own run lands them all.
|
|
3716
|
+
const fillFromTs = isWrunRowLaneId(lane) ? context.rowLaneFilling?.[lane] : undefined;
|
|
3717
|
+
const windowFrom = Math.max(wrunReconcileLaneWindowFrom(context, lane, fromTs, toTs), fillFromTs ?? Number.NEGATIVE_INFINITY);
|
|
3718
|
+
const answerRowsInWindow = fillFromTs === undefined ? answerRows : answerRows.filter((row) => Number(row[0]) >= fillFromTs);
|
|
3683
3719
|
const before = laneRowsOf(context, lane) ?? [];
|
|
3684
3720
|
// The tape lane answers DENSE rows from its served start only: K_TRADES aligns and clamps the
|
|
3685
3721
|
// history start (the declared history, the gateway's bar limit, the table's retention), so a
|
|
@@ -3699,7 +3735,7 @@ servedStartMs) {
|
|
|
3699
3735
|
? answerRows
|
|
3700
3736
|
: wrunTapeAnswerWithoutPartialHead(answerRows, servedStartMs, context.intervalMs, context.market?.exchange), before)
|
|
3701
3737
|
: isWrunRowLaneId(lane)
|
|
3702
|
-
? wrunRowLaneReconcileAnswer(context, lane, before,
|
|
3738
|
+
? wrunRowLaneReconcileAnswer(context, lane, before, answerRowsInWindow)
|
|
3703
3739
|
: answerRows;
|
|
3704
3740
|
const horizonTs = lane === 'tape' ? wrunTapeAnswerHorizonTs(answer) : Number.NEGATIVE_INFINITY;
|
|
3705
3741
|
// A row lane fed live with a union rule of its own (`liveByCoin.reconcile`) keeps, like the tape, every held bar the
|
|
@@ -3901,18 +3937,27 @@ function wrunTapeAnswerWithoutPartialHead(answer, servedStartMs, intervalMs, exc
|
|
|
3901
3937
|
return answer;
|
|
3902
3938
|
return answer.filter((row) => Number(row[0]) !== horizonTs);
|
|
3903
3939
|
}
|
|
3904
|
-
/** A tape print's
|
|
3905
|
-
|
|
3906
|
-
|
|
3940
|
+
/** A tape print's place in a union: its `[offsetMs, price, size, side]` tuple without the size, the columns both
|
|
3941
|
+
* copies of one print carry bit for bit (the stamp and the price as the venue sent them, the side). */
|
|
3942
|
+
function wrunTapePrintPlaceKey(cell) {
|
|
3943
|
+
return `${cell[0]}|${cell[1]}|${cell[3]}`;
|
|
3907
3944
|
}
|
|
3908
3945
|
/**
|
|
3909
3946
|
* A tape answer folded over the held rows: each answered bucket with a held row becomes the union
|
|
3910
|
-
* of both rows' prints, a multiset union by
|
|
3947
|
+
* of both rows' prints, a multiset union by print (a print the two share is kept once, two equal
|
|
3911
3948
|
* prints of one row stay two), in time order with the answer's prints first among equal offsets.
|
|
3912
3949
|
* A reconcile only ever adds prints to a bar: the large-print table holds no print of a quote it
|
|
3913
3950
|
* does not price, and the live floors can still keep a print it lacks (a contract's notional, a
|
|
3914
3951
|
* print the writer had not committed when the ask landed), so a print shown live never vanishes
|
|
3915
3952
|
* on the next poll.
|
|
3953
|
+
*
|
|
3954
|
+
* A print is the same print in both rows when its stamp, price and side are equal and its size agrees within float
|
|
3955
|
+
* rounding (`laneValuesEqual`, the session's own noise rule): two hosts compute one print's size, and under a dollar
|
|
3956
|
+
* floor (C-DOLLAR) they compute it differently, the gateway's writer on the stored row (an inverse contract's dollar
|
|
3957
|
+
* face), this browser as price x the live-feed COIN-arm size x the market's dollar unit: Binance delivery BTCUSD_PERP
|
|
3958
|
+
* trade 1160180465 (2026-10-22, tests/fixtures/wrun/tape-live-history-pairs.json) is $179,300 stored and
|
|
3959
|
+
* 84,428.9 x 2.12368039853652 = 179299.99999999997 live. Two equal prints still stay two: each held print matches one
|
|
3960
|
+
* answer print at most.
|
|
3916
3961
|
*/
|
|
3917
3962
|
function wrunTapeAnswerUnion(answer, held) {
|
|
3918
3963
|
if (held.length === 0)
|
|
@@ -3924,21 +3969,26 @@ function wrunTapeAnswerUnion(answer, held) {
|
|
|
3924
3969
|
const previous = heldByTs.get(Number(row[0]));
|
|
3925
3970
|
if (previous === undefined || previous.length <= 1)
|
|
3926
3971
|
return row;
|
|
3972
|
+
// The answer's sizes not matched yet, by the place of their print.
|
|
3927
3973
|
const unmatched = new Map();
|
|
3928
3974
|
const cells = [];
|
|
3929
3975
|
for (let at = 1; at < row.length; at += 1) {
|
|
3930
3976
|
const cell = row[at];
|
|
3931
3977
|
cells.push(cell);
|
|
3932
|
-
const key =
|
|
3933
|
-
|
|
3978
|
+
const key = wrunTapePrintPlaceKey(cell);
|
|
3979
|
+
const sizes = unmatched.get(key);
|
|
3980
|
+
if (sizes === undefined)
|
|
3981
|
+
unmatched.set(key, [cell[2]]);
|
|
3982
|
+
else
|
|
3983
|
+
sizes.push(cell[2]);
|
|
3934
3984
|
}
|
|
3935
3985
|
const extra = [];
|
|
3936
3986
|
for (let at = 1; at < previous.length; at += 1) {
|
|
3937
3987
|
const cell = previous[at];
|
|
3938
|
-
const
|
|
3939
|
-
const
|
|
3940
|
-
if (
|
|
3941
|
-
|
|
3988
|
+
const sizes = unmatched.get(wrunTapePrintPlaceKey(cell));
|
|
3989
|
+
const match = sizes === undefined ? -1 : sizes.findIndex((size) => laneValuesEqual(size, cell[2]));
|
|
3990
|
+
if (match >= 0)
|
|
3991
|
+
sizes?.splice(match, 1);
|
|
3942
3992
|
else
|
|
3943
3993
|
extra.push(cell);
|
|
3944
3994
|
}
|
|
@@ -3962,9 +4012,12 @@ function wrunTapeServedStartMs(context, windowFromTs, nowMs) {
|
|
|
3962
4012
|
catch {
|
|
3963
4013
|
// The full run validated the history; a malformed record reads as the live edge.
|
|
3964
4014
|
}
|
|
3965
|
-
// The lane the ask rode (tradesLaneLimits, the control's own rule): the table's
|
|
3966
|
-
// limit,
|
|
3967
|
-
|
|
4015
|
+
// The lane the ask rode (tradesLaneLimits, the control's own rule, under the acquisition's floor): the table's
|
|
4016
|
+
// retention and bar limit, the raw tape's two-hour seed on a CME Group root the table skips, or no history at all
|
|
4017
|
+
// for a dollar floor there.
|
|
4018
|
+
const lane = tradesLaneLimits(context.acquisition.tape?.large === true, context.market ?? {}, {
|
|
4019
|
+
minValue: context.acquisition.tape?.minValue,
|
|
4020
|
+
});
|
|
3968
4021
|
return tradesServedStartMs(nowMs, Math.min(historySec, lane.historyCapSec), context.intervalMs, {
|
|
3969
4022
|
windowFromMs: windowFromTs,
|
|
3970
4023
|
retentionSec: lane.retentionSec,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** One carry into a contracts param (`to`), from the raw count's old name (`raw`) or the changed dollar param
|
|
2
|
+
* (`dollars`). */
|
|
3
|
+
export interface WrunContractCarryRule {
|
|
4
|
+
readonly to: string;
|
|
5
|
+
readonly raw: string;
|
|
6
|
+
readonly dollars: string;
|
|
7
|
+
}
|
|
8
|
+
/** The contracts carries by package, by param name (never by version: every saved version moves the same way).
|
|
9
|
+
* tests/utility/wrun/wrun-market-size-contract-carry.leaf.spec.ts holds each row to the 0.8.0 sheet and its dollar
|
|
10
|
+
* rule. */
|
|
11
|
+
export declare const WRUN_CONTRACT_CARRIES: Readonly<Record<string, readonly WrunContractCarryRule[]>>;
|
|
12
|
+
/** The record's stamp of a pending migration carry (above): `true` from the pin move until a run head settles it. */
|
|
13
|
+
export declare const WRUN_CONTRACT_CARRY_PENDING = "wrunContractCarryPending";
|
|
14
|
+
/** A pending contracts carry: the rule and what it carries from (`raw`: the count itself; `dollars`: a dollar value
|
|
15
|
+
* priced at the market's dollars per contract; `stale`: a raw count a later dollar choice of the user's replaced,
|
|
16
|
+
* cleared and carried nowhere). */
|
|
17
|
+
export type WrunPendingContractCarry = WrunContractCarryRule & ({
|
|
18
|
+
readonly from: 'raw';
|
|
19
|
+
readonly count: number;
|
|
20
|
+
} | {
|
|
21
|
+
readonly from: 'dollars';
|
|
22
|
+
readonly value: number;
|
|
23
|
+
} | {
|
|
24
|
+
readonly from: 'stale';
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* The smallest whole contract count at or above `dollars` at `perContract` dollars a contract: `ceil(dollars /
|
|
28
|
+
* perContract)`, the float noise of a count priced back taken off first (6.9999999999 is 7, never 8). Undefined when
|
|
29
|
+
* either is not finite and above zero (the carry waits, never guesses).
|
|
30
|
+
*/
|
|
31
|
+
export declare function wrunCarriedContracts(dollars: unknown, perContract: number): number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The contracts carries a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) holds
|
|
34
|
+
* for a sheet declaring `sheetParams`, on a market of size unit `sizeUnit`, in table order: none off contracts, none
|
|
35
|
+
* for a contracts param the sheet does not declare or the user already set (or a carry marked). Pure.
|
|
36
|
+
*/
|
|
37
|
+
export declare function wrunPendingContractCarries(settings: unknown, packageName: string | undefined, sheetParams: ReadonlySet<string>, sizeUnit: number | undefined): WrunPendingContractCarry[];
|
|
38
|
+
/**
|
|
39
|
+
* Whether the run head settles the record's migration stamp now (`WRUN_CONTRACT_CARRY_PENDING` cleared on the engine
|
|
40
|
+
* copy and the workspace row): a stamped record, on a sheet declaring its package's contracts params (the version the
|
|
41
|
+
* stamp moved it to), at once on a market that does not count contracts (nothing converts there, and nothing may later),
|
|
42
|
+
* and on one that does once no dollar carry of `pending` waits on its price (`perContract` unproven: the next run asks
|
|
43
|
+
* again). Pure.
|
|
44
|
+
*/
|
|
45
|
+
export declare function wrunContractCarrySettles(settings: unknown, packageName: string | undefined, sheetParams: ReadonlySet<string>, sizeUnit: number | undefined, pending: readonly WrunPendingContractCarry[], perContract: number | undefined): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The patch that carries a record's pending contracts carries once (above): each contracts value (a raw count as it
|
|
48
|
+
* is, a dollar value at `perContract` dollars a contract, `wrunCarriedContracts`), held to its row's bounds, written
|
|
49
|
+
* flat under the contracts param with its row marked (`carriedValue`); the old name cleared; the dollar row back to
|
|
50
|
+
* untouched (its row default, its mark dropped). A dollar carry with no proven `perContract` writes nothing (the next
|
|
51
|
+
* run asks again). Undefined when nothing moves. Pure.
|
|
52
|
+
*/
|
|
53
|
+
export declare function wrunContractCarryPatch(settings: unknown, pending: readonly WrunPendingContractCarry[], perContract: number | undefined): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { WRUN_MARKET_SIZE_UNITS } from './wrun-market-facts.util.js';
|
|
2
|
+
/** The contracts carries by package, by param name (never by version: every saved version moves the same way).
|
|
3
|
+
* tests/utility/wrun/wrun-market-size-contract-carry.leaf.spec.ts holds each row to the 0.8.0 sheet and its dollar
|
|
4
|
+
* rule. */
|
|
5
|
+
export const WRUN_CONTRACT_CARRIES = Object.freeze({
|
|
6
|
+
'@om-core/big-trades': Object.freeze([
|
|
7
|
+
Object.freeze({ to: 'min_contracts', raw: 'min_size', dollars: 'min_value' }),
|
|
8
|
+
Object.freeze({ to: 'whale_contracts', raw: 'whale_size', dollars: 'whale_value' }),
|
|
9
|
+
]),
|
|
10
|
+
});
|
|
11
|
+
/** The record's stamp of a pending migration carry (above): `true` from the pin move until a run head settles it. */
|
|
12
|
+
export const WRUN_CONTRACT_CARRY_PENDING = 'wrunContractCarryPending';
|
|
13
|
+
/** `market.size_unit()`'s contracts code (the kit's table, wrun-market-facts.util). */
|
|
14
|
+
const CONTRACTS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('contracts');
|
|
15
|
+
/** The float noise a dollar value priced from a whole count carries (7 x $584,875 read back as 6.9999999999). */
|
|
16
|
+
const CONTRACTS_EPSILON = 1e-9;
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function positive(value) {
|
|
21
|
+
const number = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN;
|
|
22
|
+
return Number.isFinite(number) && number > 0 ? number : undefined;
|
|
23
|
+
}
|
|
24
|
+
function rowNamed(record, name) {
|
|
25
|
+
const rows = Array.isArray(record.scriptInputs) ? record.scriptInputs : [];
|
|
26
|
+
return rows.find((row) => isRecord(row) && row.name === name);
|
|
27
|
+
}
|
|
28
|
+
/** Whether a number row reads untouched: its value is its row default and it holds no carried mark (the settings
|
|
29
|
+
* panel's reset test on a plain number row: the value absent reads the default). */
|
|
30
|
+
function untouched(record, row) {
|
|
31
|
+
if (row === undefined || typeof row.carriedValue === 'number')
|
|
32
|
+
return false;
|
|
33
|
+
const value = record[row.name];
|
|
34
|
+
return value === undefined || value === null || Number(value) === Number(row.defaultValue);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The smallest whole contract count at or above `dollars` at `perContract` dollars a contract: `ceil(dollars /
|
|
38
|
+
* perContract)`, the float noise of a count priced back taken off first (6.9999999999 is 7, never 8). Undefined when
|
|
39
|
+
* either is not finite and above zero (the carry waits, never guesses).
|
|
40
|
+
*/
|
|
41
|
+
export function wrunCarriedContracts(dollars, perContract) {
|
|
42
|
+
const value = positive(dollars);
|
|
43
|
+
if (value === undefined || !Number.isFinite(perContract) || perContract <= 0)
|
|
44
|
+
return undefined;
|
|
45
|
+
const count = Math.ceil(value / perContract - CONTRACTS_EPSILON);
|
|
46
|
+
return Number.isFinite(count) && count >= 1 ? count : 1;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The contracts carries a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) holds
|
|
50
|
+
* for a sheet declaring `sheetParams`, on a market of size unit `sizeUnit`, in table order: none off contracts, none
|
|
51
|
+
* for a contracts param the sheet does not declare or the user already set (or a carry marked). Pure.
|
|
52
|
+
*/
|
|
53
|
+
export function wrunPendingContractCarries(settings, packageName, sheetParams, sizeUnit) {
|
|
54
|
+
if (sizeUnit !== CONTRACTS_SIZE_UNIT || packageName === undefined)
|
|
55
|
+
return [];
|
|
56
|
+
if (!Object.hasOwn(WRUN_CONTRACT_CARRIES, packageName))
|
|
57
|
+
return [];
|
|
58
|
+
const record = isRecord(settings) ? settings : {};
|
|
59
|
+
const pending = [];
|
|
60
|
+
for (const rule of WRUN_CONTRACT_CARRIES[packageName]) {
|
|
61
|
+
if (!sheetParams.has(rule.to) || !untouched(record, rowNamed(record, rule.to)))
|
|
62
|
+
continue;
|
|
63
|
+
const dollarsRow = rowNamed(record, rule.dollars);
|
|
64
|
+
const mark = typeof dollarsRow?.carriedValue === 'number' ? dollarsRow.carriedValue : undefined;
|
|
65
|
+
const dollars = Number(record[rule.dollars]);
|
|
66
|
+
// The raw count is the user's latest word while the dollar row was never priced from it, or still reads the value
|
|
67
|
+
// that carry priced (an edit since is newer).
|
|
68
|
+
const count = sheetParams.has(rule.raw) ? undefined : positive(record[rule.raw]);
|
|
69
|
+
if (count !== undefined && (mark === undefined || dollars === mark)) {
|
|
70
|
+
pending.push({ ...rule, from: 'raw', count });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// A changed dollar value (the settings panel's test: off its row default, or the value a carry marked), on a
|
|
74
|
+
// migration's first head alone: a record never stamped converts no dollar value.
|
|
75
|
+
const changed = record[WRUN_CONTRACT_CARRY_PENDING] === true &&
|
|
76
|
+
dollarsRow !== undefined &&
|
|
77
|
+
positive(dollars) !== undefined &&
|
|
78
|
+
(dollars !== Number(dollarsRow.defaultValue) || (mark !== undefined && dollars === mark));
|
|
79
|
+
if (changed)
|
|
80
|
+
pending.push({ ...rule, from: 'dollars', value: dollars });
|
|
81
|
+
else if (count !== undefined)
|
|
82
|
+
pending.push({ ...rule, from: 'stale' });
|
|
83
|
+
}
|
|
84
|
+
return pending;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Whether the run head settles the record's migration stamp now (`WRUN_CONTRACT_CARRY_PENDING` cleared on the engine
|
|
88
|
+
* copy and the workspace row): a stamped record, on a sheet declaring its package's contracts params (the version the
|
|
89
|
+
* stamp moved it to), at once on a market that does not count contracts (nothing converts there, and nothing may later),
|
|
90
|
+
* and on one that does once no dollar carry of `pending` waits on its price (`perContract` unproven: the next run asks
|
|
91
|
+
* again). Pure.
|
|
92
|
+
*/
|
|
93
|
+
export function wrunContractCarrySettles(settings, packageName, sheetParams, sizeUnit, pending, perContract) {
|
|
94
|
+
const record = isRecord(settings) ? settings : {};
|
|
95
|
+
if (record[WRUN_CONTRACT_CARRY_PENDING] !== true || packageName === undefined)
|
|
96
|
+
return false;
|
|
97
|
+
if (!Object.hasOwn(WRUN_CONTRACT_CARRIES, packageName))
|
|
98
|
+
return false;
|
|
99
|
+
if (!WRUN_CONTRACT_CARRIES[packageName].some((rule) => sheetParams.has(rule.to)))
|
|
100
|
+
return false;
|
|
101
|
+
if (sizeUnit !== CONTRACTS_SIZE_UNIT)
|
|
102
|
+
return true;
|
|
103
|
+
return !pending.some((carry) => carry.from === 'dollars' &&
|
|
104
|
+
(perContract === undefined || wrunCarriedContracts(carry.value, perContract) === undefined));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The patch that carries a record's pending contracts carries once (above): each contracts value (a raw count as it
|
|
108
|
+
* is, a dollar value at `perContract` dollars a contract, `wrunCarriedContracts`), held to its row's bounds, written
|
|
109
|
+
* flat under the contracts param with its row marked (`carriedValue`); the old name cleared; the dollar row back to
|
|
110
|
+
* untouched (its row default, its mark dropped). A dollar carry with no proven `perContract` writes nothing (the next
|
|
111
|
+
* run asks again). Undefined when nothing moves. Pure.
|
|
112
|
+
*/
|
|
113
|
+
export function wrunContractCarryPatch(settings, pending, perContract) {
|
|
114
|
+
if (pending.length === 0)
|
|
115
|
+
return undefined;
|
|
116
|
+
const record = isRecord(settings) ? settings : {};
|
|
117
|
+
const patch = {};
|
|
118
|
+
const carried = new Map();
|
|
119
|
+
const reset = new Set();
|
|
120
|
+
for (const carry of pending) {
|
|
121
|
+
if (carry.from === 'stale') {
|
|
122
|
+
// The user's later dollar choice replaced the count: the old name goes, nothing carries.
|
|
123
|
+
patch[carry.raw] = undefined;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const counted = carry.from === 'raw'
|
|
127
|
+
? carry.count
|
|
128
|
+
: perContract === undefined
|
|
129
|
+
? undefined
|
|
130
|
+
: wrunCarriedContracts(carry.value, perContract);
|
|
131
|
+
if (counted === undefined)
|
|
132
|
+
continue;
|
|
133
|
+
const row = rowNamed(record, carry.to);
|
|
134
|
+
const min = typeof row?.constraints?.min === 'number' ? row.constraints.min : undefined;
|
|
135
|
+
const max = typeof row?.constraints?.max === 'number' ? row.constraints.max : undefined;
|
|
136
|
+
const value = min !== undefined && counted < min ? min : max !== undefined && counted > max ? max : counted;
|
|
137
|
+
patch[carry.to] = value;
|
|
138
|
+
if (Object.hasOwn(record, carry.raw))
|
|
139
|
+
patch[carry.raw] = undefined;
|
|
140
|
+
const dollarsRow = rowNamed(record, carry.dollars);
|
|
141
|
+
if (dollarsRow !== undefined)
|
|
142
|
+
patch[carry.dollars] = dollarsRow.defaultValue;
|
|
143
|
+
carried.set(carry.to, value);
|
|
144
|
+
reset.add(carry.dollars);
|
|
145
|
+
}
|
|
146
|
+
if (carried.size === 0)
|
|
147
|
+
return Object.keys(patch).length > 0 ? patch : undefined;
|
|
148
|
+
if (Array.isArray(record.scriptInputs)) {
|
|
149
|
+
patch.scriptInputs = record.scriptInputs.map((row) => {
|
|
150
|
+
if (!isRecord(row) || typeof row.name !== 'string')
|
|
151
|
+
return row;
|
|
152
|
+
if (carried.has(row.name))
|
|
153
|
+
return { ...row, carriedValue: carried.get(row.name) };
|
|
154
|
+
if (reset.has(row.name) && Object.hasOwn(row, 'carriedValue')) {
|
|
155
|
+
const { carriedValue: _mark, ...rest } = row;
|
|
156
|
+
return rest;
|
|
157
|
+
}
|
|
158
|
+
return row;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return patch;
|
|
162
|
+
}
|