@orangecharts/wrun-chart-host 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -8
- package/dist/constants/feature-flags.constants.js +7 -2
- package/dist/constants/marketCapabilities.constants.d.ts +5 -0
- package/dist/constants/marketCapabilities.constants.js +16 -0
- package/dist/host-env.d.ts +3 -19
- package/dist/host-ports.types.d.ts +36 -17
- package/dist/index.d.ts +12 -1
- package/dist/index.js +12 -1
- package/dist/indicators/controls/tpo-session.util.js +42 -18
- package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
- package/dist/interfaces/wrun-runtime.interface.js +17 -3
- package/dist/market-data/billing.interface.d.ts +2 -1
- package/dist/settings-templates/indicator-fields.js +10 -0
- package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
- package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
- package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
- package/dist/utility/chart/crypto-index.leaf.js +19 -0
- package/dist/utility/chart/index-mode-admission.util.js +9 -1
- package/dist/utility/chart/index-mode.util.d.ts +11 -5
- package/dist/utility/chart/index-mode.util.js +22 -10
- package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
- package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
- package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
- package/dist/utility/chart/live-bucket.util.d.ts +2 -1
- package/dist/utility/chart/live-bucket.util.js +47 -15
- package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
- package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
- package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
- package/dist/utility/chart/market-session-schedule.util.js +24 -2
- package/dist/utility/chart/marketKind.util.d.ts +12 -7
- package/dist/utility/chart/marketKind.util.js +15 -5
- package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
- package/dist/utility/chart/ny-calendar.util.js +346 -0
- package/dist/utility/chart/om-panel.util.d.ts +14 -2
- package/dist/utility/chart/om-panel.util.js +108 -40
- package/dist/utility/chart/rth-session.util.d.ts +10 -7
- package/dist/utility/chart/rth-session.util.js +17 -22
- package/dist/utility/chart/trading-day.util.js +90 -18
- package/dist/utility/chart/us-equities-session.util.js +20 -67
- package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
- package/dist/utility/common/time.util.d.ts +7 -1
- package/dist/utility/common/time.util.js +11 -41
- package/dist/utility/number-format.util.d.ts +17 -7
- package/dist/utility/number-format.util.js +18 -8
- package/dist/utility/options/option-symbol.util.js +13 -2
- package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
- package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
- package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
- package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
- package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
- package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
- package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
- package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
- package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
- package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
- package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
- package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
- package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
- package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
- package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
- package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
- package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
- package/dist/utility/wrun/wrun-failure-cause.js +14 -0
- package/dist/utility/wrun/wrun-frames.js +6 -2
- package/dist/utility/wrun/wrun-host.service.d.ts +131 -59
- package/dist/utility/wrun/wrun-host.service.js +391 -194
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-hover.util.js +25 -4
- package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
- package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
- package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
- package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
- package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
- package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
- package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
- package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
- package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
- package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
- package/dist/utility/wrun/wrun-option-views.util.js +356 -0
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
- package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +20 -5
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +52 -8
- package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
- package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
- package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
- package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
- package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
- package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
- package/dist/utility/wrun/wrun-refusal.util.js +335 -40
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
- package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
- package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
- package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
- package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
- package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
- package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
- package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
- package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
- package/dist/workers/wrun/wrun-abi-host.js +31 -12
- package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
- package/dist/workers/wrun/wrun-engine-handler.js +181 -12
- package/package.json +5 -5
- package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
- package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
|
@@ -1,37 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The wrun sandbox worker's request handler, apart from its realm wiring: the worker's entry
|
|
3
|
-
* (src/workers/wrun-engine.worker.ts) sets the worker's chart-host env first, then binds `self.onmessage` to the
|
|
4
|
-
* handler this factory makes and hands it the realm's `postMessage` as `post`. Every answer leaves through `post`
|
|
5
|
-
* (one argument, or the transfer list as `{ transfer }`), so the handler reads no realm global and keeps no module
|
|
6
|
-
* state: its live sessions live in the factory's closure, one handler per worker realm, and die with the worker.
|
|
7
|
-
*
|
|
8
|
-
* Live forming-bar sessions: a `live-start` request runs like a classic
|
|
9
|
-
* request but KEEPS the instantiated guest under its sessionKey, so later
|
|
10
|
-
* `live-rows` ticks execute only the new/revised rows against the retained
|
|
11
|
-
* state (the ABI's snapshot/restore replays a revised forming bar, memory
|
|
12
|
-
* and ledger alike). Sessions die with the worker; a tick against an
|
|
13
|
-
* unknown key answers `sessionLost` so the main-thread driver rebuilds via
|
|
14
|
-
* a fresh live-start.
|
|
15
|
-
*
|
|
16
|
-
* Session ownership (push-intake contract, plan section 8 fold 3): every
|
|
17
|
-
* `live-start` carries the live context generation as its `epoch`. The
|
|
18
|
-
* worker keeps, per session key, the newest epoch seen and a live-end fence
|
|
19
|
-
* counter. Instantiation is asynchronous, so a start can still be pending
|
|
20
|
-
* when a newer start or a `live-end` (teardown) arrives; when its
|
|
21
|
-
* instantiation settles it installs its session ONLY if its epoch is still
|
|
22
|
-
* the newest and no live-end passed meanwhile (the block is still computed
|
|
23
|
-
* and answered: the caller's full run integrates it, and a later tick on
|
|
24
|
-
* the uninstalled key answers `sessionLost`, whose reseed opens a fresh
|
|
25
|
-
* session under the current generation). A `live-end` bumps the fence and
|
|
26
|
-
* deletes. The session key stays the indicator id.
|
|
27
|
-
*/
|
|
28
1
|
import { type WrunStrategyResponseFields } from './wrun-abi-host.js';
|
|
29
|
-
import type
|
|
2
|
+
import { type WrunAbiVersion, type WrunDrawSkips, type WrunWorkerRequest, type WrunWorkerResponse } from '../../interfaces/wrun-runtime.interface.js';
|
|
30
3
|
/** How the handler answers a request: the realm's `postMessage` (the worker's entry passes
|
|
31
4
|
* `(message, options) => self.postMessage(message, options)`); a transfer list rides `options`. */
|
|
32
5
|
type WrunEnginePost = (message: WrunWorkerResponse & WrunStrategyResponseFields & WrunDrawSkips, options?: StructuredSerializeOptions) => void;
|
|
33
6
|
/** Handles one request; the promise settles once its answer is posted. */
|
|
34
7
|
type WrunEngineHandler = (request: WrunWorkerRequest) => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* The module the engine worker compiles from a package's original bytes, in the order the main thread compiled them
|
|
10
|
+
* before 0.6.0: the memory clamp (clampWrunModuleMemory: a memory with no maximum gets the 4 MiB limit as its maximum,
|
|
11
|
+
* so the engine refuses a growth past it inside the guest's call; a refusal throws its plain words), then the shared
|
|
12
|
+
* host's `prepareModuleBytes` for the ABI (every mutable global exported under `__wrun_g<index>`, so the live lane's
|
|
13
|
+
* snapshot and restore cover a compiler's top-level scalars beside its memory), then the engine's compile. The
|
|
14
|
+
* module's identity stays its ORIGINAL bytes (the caller hashed them first); only the memory and export sections
|
|
15
|
+
* change. Exported for the ABI drive specs that run a module exactly as the worker compiles it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compileWrunModuleBytes(bytes: Uint8Array, abi: WrunAbiVersion): Promise<WebAssembly.Module>;
|
|
35
18
|
/** The engine worker's request handler, answering through `post`. The worker's entry makes one, after its env. */
|
|
36
19
|
export declare function createWrunEngineHandler(post: WrunEnginePost): WrunEngineHandler;
|
|
37
20
|
export {};
|
|
@@ -3,7 +3,23 @@
|
|
|
3
3
|
* (src/workers/wrun-engine.worker.ts) sets the worker's chart-host env first, then binds `self.onmessage` to the
|
|
4
4
|
* handler this factory makes and hands it the realm's `postMessage` as `post`. Every answer leaves through `post`
|
|
5
5
|
* (one argument, or the transfer list as `{ transfer }`), so the handler reads no realm global and keeps no module
|
|
6
|
-
* state: its live sessions live in the factory's closure, one handler per worker realm, and
|
|
6
|
+
* state: its compiled modules and its live sessions live in the factory's closure, one handler per worker realm, and
|
|
7
|
+
* die with the worker.
|
|
8
|
+
*
|
|
9
|
+
* Modules (the shared engine protocol, wrun-chart-host 0.6.0): the main thread never hashes or compiles a module; it
|
|
10
|
+
* posts the original bytes. A `module-load` hashes them (wrun-sha256.leaf), checks the sheet's pin, clamps the memory,
|
|
11
|
+
* prepares the bytes for the ABI and compiles them (`compileWrunModuleBytes`), caches the compiled module under
|
|
12
|
+
* `${sha256}|${abi}` and answers the key, the digest and the import list, which the client's handle carries. The cache
|
|
13
|
+
* is an LRU of WRUN_MODULE_CACHE_CAPACITY compiled modules: each entry is the compile's promise, inserted before the
|
|
14
|
+
* first await so every request for a key shares one compile; a compile in flight is never evicted; a failed compile
|
|
15
|
+
* leaves the cache before its requests read the failure. A full run and a live-start name their module by key and
|
|
16
|
+
* carry its bytes too: a cached key is reused as it is (the key was minted by a verified load, the bytes are the
|
|
17
|
+
* host's own snapshot), a miss (a respawned worker starts empty; an evicted key is gone) takes the load path over the
|
|
18
|
+
* request's own bytes, which must hash to the key's digest. Once a request's module is instantiated (right before the
|
|
19
|
+
* guest's first call; a live-rows' session at once) the handler posts `{ id, running: true }`: the client's run
|
|
20
|
+
* deadline starts there, the wait, the compile and the instantiation before it under the client's start ceiling.
|
|
21
|
+
* Instantiation is asynchronous, so `running` means executing: a request still awaiting its instantiation never reads
|
|
22
|
+
* as the one holding the worker's turn. A terminal answer may come without it (a lost session, a refused load).
|
|
7
23
|
*
|
|
8
24
|
* Live forming-bar sessions: a `live-start` request runs like a classic
|
|
9
25
|
* request but KEEPS the instantiated guest under its sessionKey, so later
|
|
@@ -16,22 +32,80 @@
|
|
|
16
32
|
* Session ownership (push-intake contract, plan section 8 fold 3): every
|
|
17
33
|
* `live-start` carries the live context generation as its `epoch`. The
|
|
18
34
|
* worker keeps, per session key, the newest epoch seen and a live-end fence
|
|
19
|
-
* counter
|
|
20
|
-
*
|
|
21
|
-
*
|
|
35
|
+
* counter, both read as the start ARRIVES, before its first await. The
|
|
36
|
+
* module's compile (on a miss) and its instantiation are asynchronous, so a
|
|
37
|
+
* start can still be pending when a newer start or a `live-end` (teardown)
|
|
38
|
+
* arrives; when it settles it installs its session ONLY if its epoch is still
|
|
22
39
|
* the newest and no live-end passed meanwhile (the block is still computed
|
|
23
40
|
* and answered: the caller's full run integrates it, and a later tick on
|
|
24
41
|
* the uninstalled key answers `sessionLost`, whose reseed opens a fresh
|
|
25
42
|
* session under the current generation). A `live-end` bumps the fence and
|
|
26
43
|
* deletes. The session key stays the indicator id.
|
|
27
44
|
*/
|
|
28
|
-
import {
|
|
45
|
+
import { ensureWrunChartHostSharedHost, wrunChartHostEnv } from '../../host-env.js';
|
|
46
|
+
import { createWrunAbiSession, runWrunPackedRequest, WrunLiveOrderError, wrunModuleImportList, } from './wrun-abi-host.js';
|
|
47
|
+
import { wrunModuleKey, } from '../../interfaces/wrun-runtime.interface.js';
|
|
48
|
+
import { clampWrunModuleMemory } from '../../utility/wrun/wrun-memory-clamp.util.js';
|
|
49
|
+
import { wrunSha256Hex } from '../../utility/wrun/wrun-sha256.leaf.js';
|
|
50
|
+
/** How many compiled modules one engine worker keeps by `${sha256}|${abi}`: every package version, draft Run and REPL
|
|
51
|
+
* compile mints a key, and a compiled module is mostly native memory the heap never shows. The client keeps its
|
|
52
|
+
* handles in an LRU of the same size under the same name (wrun-host.service.ts); this one is the worker's own, and
|
|
53
|
+
* stays unexported because the package index joins both modules. */
|
|
54
|
+
const WRUN_MODULE_CACHE_CAPACITY = 16;
|
|
55
|
+
/** Bytes that hash to another digest than the one they must carry (the sheet's pin on a load, the module key's on a
|
|
56
|
+
* full run or live-start compiling on a miss): answered `module-pin-mismatch` with the digest found; nothing is
|
|
57
|
+
* cached. */
|
|
58
|
+
class WrunModulePinMismatch extends Error {
|
|
59
|
+
sha256;
|
|
60
|
+
constructor(message, sha256) {
|
|
61
|
+
super(message);
|
|
62
|
+
this.name = 'WrunModulePinMismatch';
|
|
63
|
+
this.sha256 = sha256;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The module the engine worker compiles from a package's original bytes, in the order the main thread compiled them
|
|
68
|
+
* before 0.6.0: the memory clamp (clampWrunModuleMemory: a memory with no maximum gets the 4 MiB limit as its maximum,
|
|
69
|
+
* so the engine refuses a growth past it inside the guest's call; a refusal throws its plain words), then the shared
|
|
70
|
+
* host's `prepareModuleBytes` for the ABI (every mutable global exported under `__wrun_g<index>`, so the live lane's
|
|
71
|
+
* snapshot and restore cover a compiler's top-level scalars beside its memory), then the engine's compile. The
|
|
72
|
+
* module's identity stays its ORIGINAL bytes (the caller hashed them first); only the memory and export sections
|
|
73
|
+
* change. Exported for the ABI drive specs that run a module exactly as the worker compiles it.
|
|
74
|
+
*/
|
|
75
|
+
export async function compileWrunModuleBytes(bytes, abi) {
|
|
76
|
+
const bounded = clampWrunModuleMemory(bytes);
|
|
77
|
+
const hostLoading = ensureWrunChartHostSharedHost();
|
|
78
|
+
if (hostLoading)
|
|
79
|
+
await hostLoading;
|
|
80
|
+
const { prepareModuleBytes } = wrunChartHostEnv().sharedHost();
|
|
81
|
+
return WebAssembly.compile(prepareModuleBytes(bounded, abi));
|
|
82
|
+
}
|
|
83
|
+
/** A full run as the ABI host runs it: the request's module key and bytes turned into the compiled module. */
|
|
84
|
+
function resolvedRunRequest(request, module) {
|
|
85
|
+
const { moduleKey: _moduleKey, moduleBytes: _moduleBytes, ...fields } = request;
|
|
86
|
+
return { ...fields, module };
|
|
87
|
+
}
|
|
88
|
+
/** A failure as the client reads it: the error's words, and the module codes (a pin mismatch with the digest found,
|
|
89
|
+
* an engine compile refusal) the client maps back to today's error class and words. */
|
|
90
|
+
function failureOf(id, error) {
|
|
91
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
92
|
+
if (error instanceof WrunModulePinMismatch) {
|
|
93
|
+
return { id, ok: false, error: message, code: 'module-pin-mismatch', sha256: error.sha256 };
|
|
94
|
+
}
|
|
95
|
+
if (error instanceof WebAssembly.CompileError)
|
|
96
|
+
return { id, ok: false, error: message, code: 'module-compile-failed' };
|
|
97
|
+
return { id, ok: false, error: message };
|
|
98
|
+
}
|
|
29
99
|
/** The engine worker's request handler, answering through `post`. The worker's entry makes one, after its env. */
|
|
30
100
|
export function createWrunEngineHandler(post) {
|
|
31
101
|
const liveSessions = new Map();
|
|
32
102
|
/** The epoch the session installed under each key opened with (none for a legacy start). */
|
|
33
103
|
const liveSessionEpochs = new Map();
|
|
34
104
|
const liveEpochs = new Map();
|
|
105
|
+
/** Compiled modules by key, least recently used first (Map order: a hit moves its entry to the end). */
|
|
106
|
+
const modules = new Map();
|
|
107
|
+
/** The entries whose compile has not settled: never evicted, since every request for the key shares them. */
|
|
108
|
+
const compiling = new Set();
|
|
35
109
|
function liveEpochFor(sessionKey) {
|
|
36
110
|
let epoch = liveEpochs.get(sessionKey);
|
|
37
111
|
if (!epoch) {
|
|
@@ -40,17 +114,103 @@ export function createWrunEngineHandler(post) {
|
|
|
40
114
|
}
|
|
41
115
|
return epoch;
|
|
42
116
|
}
|
|
117
|
+
/** Evict compiled entries, least recently used first, until the cache is back at its capacity (a compile in flight
|
|
118
|
+
* stays: the cache passes the capacity only while more compiles than that are in flight). */
|
|
119
|
+
function trimModules() {
|
|
120
|
+
for (const [key, entry] of modules) {
|
|
121
|
+
if (modules.size <= WRUN_MODULE_CACHE_CAPACITY)
|
|
122
|
+
return;
|
|
123
|
+
if (!compiling.has(entry))
|
|
124
|
+
modules.delete(key);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** The cached module under `key` as the most recent use, or undefined. */
|
|
128
|
+
function cachedModule(key) {
|
|
129
|
+
const cached = modules.get(key);
|
|
130
|
+
if (cached === undefined)
|
|
131
|
+
return undefined;
|
|
132
|
+
modules.delete(key);
|
|
133
|
+
modules.set(key, cached);
|
|
134
|
+
return cached;
|
|
135
|
+
}
|
|
136
|
+
/** The module under `key`: the cached one, else the compile of `bytes`, cached under the key before this returns
|
|
137
|
+
* (synchronously, before any await of the caller's), so a request for the key arriving meanwhile joins it. */
|
|
138
|
+
function moduleUnder(key, bytes, abi) {
|
|
139
|
+
const cached = cachedModule(key);
|
|
140
|
+
if (cached !== undefined)
|
|
141
|
+
return cached;
|
|
142
|
+
const entry = compileWrunModuleBytes(bytes, abi).then((module) => {
|
|
143
|
+
compiling.delete(entry);
|
|
144
|
+
trimModules();
|
|
145
|
+
return module;
|
|
146
|
+
}, (error) => {
|
|
147
|
+
// A module that fails to load is never cached: the next request for its key tries the bytes again.
|
|
148
|
+
compiling.delete(entry);
|
|
149
|
+
if (modules.get(key) === entry)
|
|
150
|
+
modules.delete(key);
|
|
151
|
+
throw error;
|
|
152
|
+
});
|
|
153
|
+
compiling.add(entry);
|
|
154
|
+
modules.set(key, entry);
|
|
155
|
+
trimModules();
|
|
156
|
+
return entry;
|
|
157
|
+
}
|
|
158
|
+
/** A full run's or a live-start's module: the cached one under its key, else the load path over the request's own
|
|
159
|
+
* bytes, which must hash to the key's digest; they compile for the key's ABI, the load's. */
|
|
160
|
+
function moduleFor(request) {
|
|
161
|
+
const { moduleKey, moduleBytes } = request;
|
|
162
|
+
const cached = cachedModule(moduleKey);
|
|
163
|
+
if (cached !== undefined)
|
|
164
|
+
return cached;
|
|
165
|
+
if (typeof moduleKey !== 'string' || !ArrayBuffer.isView(moduleBytes) || moduleBytes.byteLength === 0) {
|
|
166
|
+
// A handle no host loaded (its runs carry no bytes) or a malformed request: refused by name.
|
|
167
|
+
return Promise.reject(new Error(`WRUN module ${moduleKey} is not in this worker and the run carries no bytes to compile it from`));
|
|
168
|
+
}
|
|
169
|
+
const at = moduleKey.lastIndexOf('|');
|
|
170
|
+
const sha256 = wrunSha256Hex(moduleBytes);
|
|
171
|
+
if (at < 0 || moduleKey.slice(0, at) !== sha256) {
|
|
172
|
+
return Promise.reject(new WrunModulePinMismatch(`WRUN module bytes (sha256 ${sha256}) do not match the run's module key ${moduleKey}`, sha256));
|
|
173
|
+
}
|
|
174
|
+
return moduleUnder(moduleKey, moduleBytes, moduleKey.slice(at + 1));
|
|
175
|
+
}
|
|
176
|
+
/** `module-load`: the digest of the original bytes, the sheet's pin, then the module under its key. */
|
|
177
|
+
async function loadModule(request) {
|
|
178
|
+
const sha256 = wrunSha256Hex(request.bytes);
|
|
179
|
+
if (request.sha256Pin && request.sha256Pin !== sha256) {
|
|
180
|
+
throw new WrunModulePinMismatch(`WRUN module sha256 mismatch (the sheet pins ${request.sha256Pin}, the bytes are ${sha256})`, sha256);
|
|
181
|
+
}
|
|
182
|
+
const key = wrunModuleKey(sha256, request.abi);
|
|
183
|
+
const module = await moduleUnder(key, request.bytes, request.abi);
|
|
184
|
+
const response = {
|
|
185
|
+
id: request.id,
|
|
186
|
+
ok: true,
|
|
187
|
+
kind: 'module-load',
|
|
188
|
+
key,
|
|
189
|
+
sha256,
|
|
190
|
+
imports: [...wrunModuleImportList(module)],
|
|
191
|
+
};
|
|
192
|
+
post(response);
|
|
193
|
+
}
|
|
43
194
|
async function handleRequest(request) {
|
|
44
195
|
try {
|
|
45
196
|
if (!('kind' in request)) {
|
|
46
|
-
|
|
197
|
+
const module = await moduleFor(request);
|
|
198
|
+
postOutput(request.id, await runWrunPackedRequest(resolvedRunRequest(request, module), {
|
|
199
|
+
// Instantiated: the run executes from here, and its deadline starts with it.
|
|
200
|
+
onInstantiated: () => post({ id: request.id, running: true }),
|
|
201
|
+
}));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (request.kind === 'module-load') {
|
|
205
|
+
await loadModule(request);
|
|
47
206
|
return;
|
|
48
207
|
}
|
|
49
208
|
if (request.kind === 'live-end') {
|
|
50
209
|
const gate = liveEpochFor(request.sessionKey);
|
|
51
210
|
if (request.epoch === undefined) {
|
|
52
|
-
// The fence moves BEFORE the delete: a start whose
|
|
53
|
-
// pending right now must find the fence moved when
|
|
211
|
+
// The fence moves BEFORE the delete: a start whose compile or
|
|
212
|
+
// instantiation is pending right now must find the fence moved when
|
|
213
|
+
// it settles.
|
|
54
214
|
gate.ends += 1;
|
|
55
215
|
liveSessions.delete(request.sessionKey);
|
|
56
216
|
liveSessionEpochs.delete(request.sessionKey);
|
|
@@ -79,9 +239,13 @@ export function createWrunEngineHandler(post) {
|
|
|
79
239
|
const staleOnArrival = epoch !== undefined && epoch < gate.newest;
|
|
80
240
|
if (epoch !== undefined && !staleOnArrival)
|
|
81
241
|
gate.newest = epoch;
|
|
242
|
+
// Read as the start arrives, before its first await (the module's
|
|
243
|
+
// compile on a miss, then the instantiation): a live-end that lands
|
|
244
|
+
// during either fences this start out.
|
|
82
245
|
const endsAtStart = gate.ends;
|
|
246
|
+
const module = await moduleFor(startRequest);
|
|
83
247
|
const session = await createWrunAbiSession({
|
|
84
|
-
module
|
|
248
|
+
module,
|
|
85
249
|
abi: startRequest.abi,
|
|
86
250
|
outputCount: startRequest.outputCount,
|
|
87
251
|
initArgs: startRequest.initArgs,
|
|
@@ -92,11 +256,15 @@ export function createWrunEngineHandler(post) {
|
|
|
92
256
|
// The strategy config rides the session (the broker is the session's
|
|
93
257
|
// committed fold); later ticks carry only their rows' broker feed.
|
|
94
258
|
strategy: startRequest.strategy,
|
|
259
|
+
// Instantiated: the start executes from here, and its deadline starts with it.
|
|
260
|
+
onInstantiated: () => post({ id: startRequest.id, running: true }),
|
|
95
261
|
});
|
|
96
262
|
// Replace-on-start: a remount/pan rebuild under the same key must not
|
|
97
263
|
// leak the superseded guest. The output of the failed create above
|
|
98
264
|
// never replaces an existing session (the throw skips this line).
|
|
99
265
|
const output = session.runRows(startRequest, 'live');
|
|
266
|
+
// The supersession check, now the module is in hand and the block ran:
|
|
267
|
+
// against the fence and the epoch read at arrival.
|
|
100
268
|
const current = liveEpochFor(startRequest.sessionKey);
|
|
101
269
|
const superseded = staleOnArrival ||
|
|
102
270
|
current.ends !== endsAtStart ||
|
|
@@ -116,6 +284,7 @@ export function createWrunEngineHandler(post) {
|
|
|
116
284
|
{
|
|
117
285
|
const session = liveSessions.get(rowsRequest.sessionKey);
|
|
118
286
|
if (!session) {
|
|
287
|
+
// A lost session answers at once, without `running`: the terminal answer settles the request.
|
|
119
288
|
const response = {
|
|
120
289
|
id: rowsRequest.id,
|
|
121
290
|
ok: false,
|
|
@@ -125,6 +294,8 @@ export function createWrunEngineHandler(post) {
|
|
|
125
294
|
post(response);
|
|
126
295
|
return;
|
|
127
296
|
}
|
|
297
|
+
// The session is in hand: the tick starts now, and its deadline with it.
|
|
298
|
+
post({ id: rowsRequest.id, running: true });
|
|
128
299
|
let output;
|
|
129
300
|
try {
|
|
130
301
|
output = session.runRows(rowsRequest, 'live');
|
|
@@ -155,9 +326,7 @@ export function createWrunEngineHandler(post) {
|
|
|
155
326
|
}
|
|
156
327
|
}
|
|
157
328
|
catch (error) {
|
|
158
|
-
|
|
159
|
-
const response = { id: request.id, ok: false, error: message };
|
|
160
|
-
post(response);
|
|
329
|
+
post(failureOf(request.id, error));
|
|
161
330
|
}
|
|
162
331
|
}
|
|
163
332
|
function postOutput(id, output) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orangecharts/wrun-chart-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The wrun chart-host layer shared by the kiyotaka web app and the mobile app: the wrun result reader and painter model, cut from the web app (its reference implementation).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@orangecharts/indicator-kit": "0.
|
|
32
|
-
"@orangecharts/orange-v2-pb-common": "12.
|
|
31
|
+
"@orangecharts/indicator-kit": "0.88.0",
|
|
32
|
+
"@orangecharts/orange-v2-pb-common": "12.72.0",
|
|
33
33
|
"dayjs": "1.11.23",
|
|
34
34
|
"lodash-es": "4.18.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@orangecharts/indicator-kit": "0.
|
|
38
|
-
"@orangecharts/orange-v2-pb-common": "12.
|
|
37
|
+
"@orangecharts/indicator-kit": "0.88.0",
|
|
38
|
+
"@orangecharts/orange-v2-pb-common": "12.72.0",
|
|
39
39
|
"@types/lodash-es": "4.17.12",
|
|
40
40
|
"dayjs": "1.11.23",
|
|
41
41
|
"lodash-es": "4.18.1",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The identity of an OPRA-only row lane on its chart (`option_prints`, `option_contract_flow`: the underlying the
|
|
3
|
-
* OPRA plane keys its series by, `coin`). A thin re-export kept for those lanes' imports: the wrapper lives beside the
|
|
4
|
-
* one chain resolver (sources/opra-option-lanes.util `resolveWrunOpraLaneUnderlying`, over the same chart chain
|
|
5
|
-
* resolution `option_surface` and `option_strikes` read), its refusals by name unchanged: the directory that did not
|
|
6
|
-
* answer (`service-no-answer` / `opra-directory`, Retry) and a chart OPRA lists no options for (`no-options` /
|
|
7
|
-
* `chain`).
|
|
8
|
-
*/
|
|
9
|
-
import type { WrunPollLaneContext } from './sources/wrun-poll-lane.types.js';
|
|
10
|
-
export { resolveWrunOpraLaneUnderlying } from './sources/opra-option-lanes.util.js';
|
|
11
|
-
/** The chart a lane resolves its underlying on (a row lane's plan context carries these). */
|
|
12
|
-
export type WrunOpraUnderlyingContext = Pick<WrunPollLaneContext, 'inputName' | 'sourceClass' | 'coin' | 'exchange' | 'symbol'>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { resolveWrunOpraLaneUnderlying } from './sources/opra-option-lanes.util.js';
|