@orangecharts/wrun-chart-host 0.19.0 → 0.19.1
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
CHANGED
|
@@ -128,6 +128,7 @@ What each published version holds. A host installs a version with the peers of i
|
|
|
128
128
|
|
|
129
129
|
| Version | Peers | What changed |
|
|
130
130
|
| --- | --- | --- |
|
|
131
|
+
| 0.19.1 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Three fixes to 0.19.0's typed threshold contract. `templatePatch` refuses a typed threshold's unit key (`currency`, `bigTradesThresholdUnit`) together with its refused values, so a destination's dollar amount never takes a coin unit; the new optional `TemplateContext.boundKeyParts` (the destination's `MarketBoundKeyParts`) rebuilds the destination's key in the unit the template writes, so a template on its own market in another unit writes its threshold with its unit (a host without it keeps the refusal). `reconcileMarketBound` no longer stashes a unit that holds its default (`options.defaults`, or no value) and drops an older entry for that key, so `BOUND_STASH_CAP` holds only typed values. `captureTemplate`, `toStoredEntry`, `migrateTemplate` and `templatePatch` handle `boundMarketKey` only for a type with a kept bound field, so a script input of that name stays an input. |
|
|
131
132
|
| 0.19.0 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Market-bound values in `settings-templates`: a value measured or typed on one market carries the market it belongs to. The heatmap scale leaf: `heatmapMarketKey`, `stampBoundKey`, `parseBoundKey`, `boundSignature`, `heatmapScaleSignature`, `stashBound`, `takeBound`, `BOUND_STASH_CAP` (row fields `settings.boundKey` and `settings.boundByMarket`). The typed threshold contract: each numeric field declares `quantity` (`relative`, `bound` or `amount`) and a kept bound one `keep`; `marketBoundKey(parts)` spells the key (exchange, unit, symbol, interval; a month is `1MO`); `reconcileMarketBound(type, settings, liveKey, options)` is the one decision at every door a row meets a market (its own key: unchanged; another key: the typed values are kept under their market and this market's remembered values or the caller's `defaults` come back; no stamp: trusted and stamped, or judged by `unkeyedAs`); `stampMarketBound` signs a user's edit; `unclassifiedNumericFields` feeds a host's classification guard. A host calls the reconcile at its mount, market switch, settings write and document doors, and the stamp on a user's edit; a script row is never settled. `templatePatch` writes a typed threshold only on the market it was saved on (`TemplateContext.boundKey`, kept in the bag as `boundMarketKey`); the schema version does not move, so a client before 0.19.0 lists that key as dropped and writes the threshold as before. The phone app's Big Trades (`BIG_TRADES`) gets a field table. |
|
|
132
133
|
| 0.18.0 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Four things a host acts on. The index and yield venue's official bars: the index leaf gains `INDEX_OTC_SERVER_BUILT_BARS_FROM_MS` and `barsAreServerBuilt(exchange, intervalMs)`, the root exports `chartBarsAreServerBuilt(market, intervalMs)` (`utility/chart/server-built-bars.util`, a formula leg counts), and the live intake refuses a live fold on such a chart; a host stops folding live prints and gap rows into a bar of one day or wider there and reads the newest bar again from the server. `FeatureFlag` loses `UsEquitiesFull`, `WrunConvergingPrefix`, `DrawingAlertOneClick`, `DrawingsUnderCandles`, `ChartDraftOrder` and `TypedServerFutures` (graduated on web) and gains `FuturesNinjaTraderDepth`. `MARKET_DATA_VENUES` now lists the US stocks venue beside OPRA (it left `FLAG_GATED_MARKET_DATA_VENUES`), so a host that holds stocks behind a switch of its own keeps that switch at its own door. The env gains the optional `isSignedIn()`: the licence and broker flags read as kill switches that default on for a signed-in session, and a host without the port reads every session as a guest. The package commits landed since 0.17.0 ride along (`git log 3ad609a1a4.. -- packages/wrun-chart-host` in the web repo). |
|
|
133
134
|
| 0.17.0 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Three things a host acts on. The marks section's `text.place` gains `fit` (2: the size inside the mark where the full number fits, else beside it), `fit_short` (3: as `fit`, rounded inside when only the rounded number fits) and `fit_only` (4: as `fit_short`, never beside), and the mount refuses them by name on an engine whose marks pack is below level 3 (`fit`) or 4 (the other two); 0.16.0 refuses a section that names one ("Needs a newer chart"). The data-fetching loader view supplies `mainRowsLoadedFor(chartIndex, metadata)` in place of `loadedMainIdentityOf` (`WrunLoadedMainIdentity` leaves): the host answers whether the mounted main rows are that metadata's market, so a chart whose rows come from another market (a US stock on Trades) proves its candles. The market size defaults count the last trading day on the market's own clock (whole days it stood closed are no part of it), so the first candles after a weekend or a holiday no longer read as a whole day. The peers move with web: the kit from 0.119.0 to 0.121.0 and the protocol enums from 12.84.0 to 12.86.0 (the index and yield venue, `utility/chart/index-otc.leaf`, joins the public modules). The other package commits landed since 0.16.0 ride along (`git log f9aeda13fd.. -- packages/wrun-chart-host` in the web repo). |
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type BoundCondition, type BoundKeep, type FieldQuantity } from './indicator-fields.js';
|
|
2
|
+
import { type MarketBoundKeyParts } from './market-bound.js';
|
|
2
3
|
import { type ToolTextRole } from './tool-rules.js';
|
|
3
4
|
import { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS } from './tool-tables.generated.js';
|
|
4
5
|
export { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS };
|
|
@@ -51,6 +52,13 @@ export interface TemplateContext {
|
|
|
51
52
|
* kept bound field.
|
|
52
53
|
*/
|
|
53
54
|
boundKey?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The parts of the destination's `boundKey` (marketBoundKey), on a patch. With them the template's key is compared
|
|
57
|
+
* with the destination's key in the unit the template writes (its `currency`), so a template applied on its own
|
|
58
|
+
* market (exchange, symbol, interval) in another unit writes its threshold together with its unit. Without them
|
|
59
|
+
* `boundKey` is compared as it is, and a template from another unit is refused with its unit. Optional since 0.19.1.
|
|
60
|
+
*/
|
|
61
|
+
boundKeyParts?: MarketBoundKeyParts;
|
|
54
62
|
/** Reserved for host rules that depend on the chart interval; no rule here reads it. */
|
|
55
63
|
intervalMs?: number;
|
|
56
64
|
declaredInputs?: readonly string[];
|
|
@@ -21,8 +21,11 @@
|
|
|
21
21
|
* - A kept bound field (a typed threshold: `quantity: 'bound'` with `keep`, ./market-bound) that is bound right now in
|
|
22
22
|
* the unit the template writes is written only when the template's market key (`boundKey`, captured from
|
|
23
23
|
* `ctx.boundKey`) equals the destination's (`ctx.boundKey`); when either key is missing, the template's `market` and
|
|
24
|
-
* `ctx.market` decide, as for a market-bound field. Its group companions follow it
|
|
25
|
-
*
|
|
24
|
+
* `ctx.market` decide, as for a market-bound field. Its group companions follow it, and so does its unit key (the
|
|
25
|
+
* `boundWhen` key): a refused value and its unit are refused together. Skipped, not dropped. With
|
|
26
|
+
* `ctx.boundKeyParts` the destination's key is rebuilt in the unit the template writes, so a template on its own
|
|
27
|
+
* market in another unit writes its threshold with its unit. A dollar amount (the field in a notional unit) is
|
|
28
|
+
* written onto any market.
|
|
26
29
|
* - "Show on" (`visibleIntervalsMs`): absent keeps the destination, `[]` is All intervals, a list is that list; a
|
|
27
30
|
* legacy clear (`null`, or a key held as undefined) is written as `[]`. A capture writes `[]` where the engine holds
|
|
28
31
|
* none, so a saved template always states it (an interval-bound drawing keeps its own, as instance state). A
|
|
@@ -53,7 +56,7 @@ import cloneDeep from 'lodash-es/cloneDeep.js';
|
|
|
53
56
|
import { isWrunViewerRowKey } from '../utility/wrun/wrun-color-facts.util.js';
|
|
54
57
|
import { FRVP_FIELD_ROWS, FRVP_TOOL_TYPE } from './frvp-fields.js';
|
|
55
58
|
import { INDICATOR_COMMON_FIELDS, INDICATOR_TYPE_FIELDS, RESERVED_SCRIPT_INPUT_NAMES, SCRIPT_INDICATOR_TYPE, SCRIPT_INPUT_FIELD, VIEWER_ROW_FIELD, } from './indicator-fields.js';
|
|
56
|
-
import { isBoundNow } from './market-bound.js';
|
|
59
|
+
import { boundFieldsOf, isBoundNow, marketBoundKey } from './market-bound.js';
|
|
57
60
|
import { textRoleOf, TOOL_TEMPLATE_RULES } from './tool-rules.js';
|
|
58
61
|
import { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS } from './tool-tables.generated.js';
|
|
59
62
|
export { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS };
|
|
@@ -103,6 +106,15 @@ const indicatorBaseType = (type) => type.startsWith(`${SCRIPT_INDICATOR_TYPE}:`)
|
|
|
103
106
|
const isScript = (kind, type) => kind === 'indicator' && indicatorBaseType(type) === SCRIPT_INDICATOR_TYPE;
|
|
104
107
|
const isFrvp = (kind, type) => kind === 'tool' && type === FRVP_TOOL_TYPE;
|
|
105
108
|
const isFrvpOwner = (owner) => owner === 'box' || owner === 'profile';
|
|
109
|
+
/**
|
|
110
|
+
* Whether a template of this type keeps the market key of its typed thresholds (`boundKey`, stored in the bag as
|
|
111
|
+
* TEMPLATE_BOUND_KEY_FIELD): only an indicator type with a kept bound field. Capture, storage, migration and patch ask
|
|
112
|
+
* this one rule, so the key never takes a bag name from a type whose bag is not the package's own: a script's inputs
|
|
113
|
+
* are the script's, and an input named `boundMarketKey` stays an input.
|
|
114
|
+
*/
|
|
115
|
+
const carriesBoundKey = (kind, type) => kind === 'indicator' && boundFieldsOf(type).length > 0;
|
|
116
|
+
/** The settings key that holds a row's unit: the unit part of marketBoundKey (MarketBoundKeyParts.currency). */
|
|
117
|
+
const BOUND_KEY_UNIT_FIELD = 'currency';
|
|
106
118
|
/** Whether a drawing type keeps the "Show on" intervals it was drawn with, whatever a template holds. */
|
|
107
119
|
export function isIntervalBoundTool(type) {
|
|
108
120
|
return INTERVAL_BOUND_TYPES.has(type);
|
|
@@ -331,8 +343,8 @@ export function captureTemplate(kind, type, engineSettings, ctx) {
|
|
|
331
343
|
const market = kind === 'indicator' ? nonEmpty(ctx?.market) : undefined;
|
|
332
344
|
if (market)
|
|
333
345
|
doc.market = market;
|
|
334
|
-
const boundKey = kind
|
|
335
|
-
if (boundKey
|
|
346
|
+
const boundKey = carriesBoundKey(kind, type) ? nonEmpty(ctx?.boundKey) : undefined;
|
|
347
|
+
if (boundKey)
|
|
336
348
|
doc.boundKey = boundKey;
|
|
337
349
|
if (Object.keys(groups.meta).length)
|
|
338
350
|
doc.meta = groups.meta;
|
|
@@ -384,18 +396,35 @@ export function templatePatch(kind, type, live, template, ctx) {
|
|
|
384
396
|
const sameMarket = !!templateMarket && templateMarket === nonEmpty(ctx?.market);
|
|
385
397
|
// A kept bound field is written on the market key it was typed on; a template or a context with no key falls back to
|
|
386
398
|
// the market (an in-memory older shape may still hold the key in its bag).
|
|
387
|
-
const savedBoundKey = kind
|
|
399
|
+
const savedBoundKey = carriesBoundKey(kind, type) && !bagSpecs.has(TEMPLATE_BOUND_KEY_FIELD)
|
|
400
|
+
? saved[TEMPLATE_BOUND_KEY_FIELD]
|
|
401
|
+
: undefined;
|
|
388
402
|
const templateBoundKey = nonEmpty(template?.boundKey) ?? nonEmpty(savedBoundKey);
|
|
389
|
-
|
|
403
|
+
// The destination's key as it will be once the template's unit is written, when the host gives its parts: the key
|
|
404
|
+
// holds the unit, so comparing the destination's current key would refuse a template on its own market for its unit.
|
|
405
|
+
const parts = ctx?.boundKeyParts;
|
|
406
|
+
const unitSpec = bagSpecs.get(BOUND_KEY_UNIT_FIELD);
|
|
407
|
+
const writesUnit = !!unitSpec?.lanes.includes('template') && Object.hasOwn(saved, BOUND_KEY_UNIT_FIELD);
|
|
408
|
+
const liveBoundKey = isRecord(parts)
|
|
409
|
+
? marketBoundKey({
|
|
410
|
+
...parts,
|
|
411
|
+
currency: writesUnit ? saved[BOUND_KEY_UNIT_FIELD] : parts.currency,
|
|
412
|
+
})
|
|
413
|
+
: nonEmpty(ctx?.boundKey);
|
|
390
414
|
const sameBoundMarket = templateBoundKey && liveBoundKey ? templateBoundKey === liveBoundKey : sameMarket;
|
|
391
415
|
// The unit a template writes: its own value of the unit key, else the destination's.
|
|
392
416
|
const writtenBag = { ...liveBag, ...saved };
|
|
393
417
|
const gated = new Set();
|
|
394
418
|
if (!sameBoundMarket) {
|
|
395
419
|
for (const spec of bagSpecs.values()) {
|
|
396
|
-
if (spec.keep
|
|
397
|
-
|
|
398
|
-
|
|
420
|
+
if (!spec.keep || !isBoundNow(spec.boundWhen, writtenBag))
|
|
421
|
+
continue;
|
|
422
|
+
for (const key of [spec.key, ...(spec.with ?? [])])
|
|
423
|
+
gated.add(key);
|
|
424
|
+
// A refused value and its unit travel together: the unit written alone would give the destination's own value
|
|
425
|
+
// the template's unit (a 250000 dollar threshold read as 250000 coins).
|
|
426
|
+
if (spec.boundWhen)
|
|
427
|
+
gated.add(spec.boundWhen.key);
|
|
399
428
|
}
|
|
400
429
|
}
|
|
401
430
|
const groups = { settings: {}, meta: {}, profile: {} };
|
|
@@ -498,7 +527,7 @@ _ctx) {
|
|
|
498
527
|
const market = nonEmpty(source.market);
|
|
499
528
|
if (market)
|
|
500
529
|
doc.market = market;
|
|
501
|
-
if (kind
|
|
530
|
+
if (carriesBoundKey(kind, type) && Object.hasOwn(settings, TEMPLATE_BOUND_KEY_FIELD)) {
|
|
502
531
|
const boundKey = nonEmpty(settings[TEMPLATE_BOUND_KEY_FIELD]);
|
|
503
532
|
delete settings[TEMPLATE_BOUND_KEY_FIELD];
|
|
504
533
|
if (boundKey)
|
|
@@ -529,7 +558,7 @@ export function toStoredEntry(doc) {
|
|
|
529
558
|
const market = nonEmpty(doc.market);
|
|
530
559
|
if (market)
|
|
531
560
|
entry.market = market;
|
|
532
|
-
const boundKey = doc.kind
|
|
561
|
+
const boundKey = carriesBoundKey(doc.kind, doc.type) ? nonEmpty(doc.boundKey) : undefined;
|
|
533
562
|
if (boundKey)
|
|
534
563
|
settings[TEMPLATE_BOUND_KEY_FIELD] = boundKey;
|
|
535
564
|
return entry;
|
|
@@ -198,7 +198,8 @@ export interface MarketBoundReconciliation<T> {
|
|
|
198
198
|
* reads its inputs defensively and never mutates them.
|
|
199
199
|
* - OWN (the stamp parses, its signature matches, its key is `liveKey`): unchanged, the same object.
|
|
200
200
|
* - FOREIGN (the stamp parses and signs, another key): the typed units bound right now are kept under the stamp's key
|
|
201
|
-
* in `boundByMarket` (measured ones are dropped
|
|
201
|
+
* in `boundByMarket` (measured ones are dropped, and so is a unit that holds what this reconcile restores where none
|
|
202
|
+
* is remembered: its default or no value; with none kept, an older entry for the stamp's key goes); each unit takes the live market's remembered values out of the
|
|
202
203
|
* stash, else `options.defaults`, else is removed; the row is stamped with `liveKey`. A group is one unit.
|
|
203
204
|
* - UNKEYED (no stamp, a malformed one, or a signature that does not match): the values are trusted on this market and
|
|
204
205
|
* stamped with `liveKey`; with `options.unkeyedAs` the row is first read as stamped with that key (OWN or FOREIGN).
|
|
@@ -262,12 +262,26 @@ export function stampMarketBound(type, settings, liveKey) {
|
|
|
262
262
|
return settings;
|
|
263
263
|
return { ...settings, boundKey: stamp };
|
|
264
264
|
}
|
|
265
|
+
/** A value as a signature reads it (undefined as null), for an equality of plain JSON values. */
|
|
266
|
+
const asJson = (value) => JSON.stringify(value === undefined ? null : value);
|
|
267
|
+
/**
|
|
268
|
+
* Whether a unit's values on a row are the ones a FOREIGN reconcile writes for it where no value is remembered: each
|
|
269
|
+
* key equal to the default (when `defaults` names the unit's field), else each key holding no value.
|
|
270
|
+
*/
|
|
271
|
+
function holdsDefaults(unit, settings, defaults) {
|
|
272
|
+
const source = defaults && Object.hasOwn(defaults, unit.key) ? defaults : null;
|
|
273
|
+
return unit.keys.every((key) => {
|
|
274
|
+
const expected = source && Object.hasOwn(source, key) ? source[key] : undefined;
|
|
275
|
+
return asJson(ownValue(settings, key)) === asJson(expected);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
265
278
|
/**
|
|
266
279
|
* The one decision a reader makes when a threshold row meets the live market `liveKey` (contract section 6). Pure:
|
|
267
280
|
* reads its inputs defensively and never mutates them.
|
|
268
281
|
* - OWN (the stamp parses, its signature matches, its key is `liveKey`): unchanged, the same object.
|
|
269
282
|
* - FOREIGN (the stamp parses and signs, another key): the typed units bound right now are kept under the stamp's key
|
|
270
|
-
* in `boundByMarket` (measured ones are dropped
|
|
283
|
+
* in `boundByMarket` (measured ones are dropped, and so is a unit that holds what this reconcile restores where none
|
|
284
|
+
* is remembered: its default or no value; with none kept, an older entry for the stamp's key goes); each unit takes the live market's remembered values out of the
|
|
271
285
|
* stash, else `options.defaults`, else is removed; the row is stamped with `liveKey`. A group is one unit.
|
|
272
286
|
* - UNKEYED (no stamp, a malformed one, or a signature that does not match): the values are trusted on this market and
|
|
273
287
|
* stamped with `liveKey`; with `options.unkeyedAs` the row is first read as stamped with that key (OWN or FOREIGN).
|
|
@@ -293,9 +307,12 @@ export function reconcileMarketBound(type, settings, liveKey, options) {
|
|
|
293
307
|
}
|
|
294
308
|
// FOREIGN: the values belong to `rowKey`.
|
|
295
309
|
const next = { ...settings };
|
|
310
|
+
const defaults = isPlainRecord(options?.defaults) ? options.defaults : null;
|
|
311
|
+
// Only a unit that differs from what this reconcile restores where nothing is remembered (its default, or no value)
|
|
312
|
+
// is kept: a default needs no memory, and a stash entry of defaults would push a typed value out of the capped list.
|
|
296
313
|
const typed = {};
|
|
297
314
|
for (const unit of units) {
|
|
298
|
-
if (unit.keep !== 'typed')
|
|
315
|
+
if (unit.keep !== 'typed' || holdsDefaults(unit, settings, defaults))
|
|
299
316
|
continue;
|
|
300
317
|
for (const key of unit.keys) {
|
|
301
318
|
const value = ownValue(settings, key);
|
|
@@ -305,9 +322,9 @@ export function reconcileMarketBound(type, settings, liveKey, options) {
|
|
|
305
322
|
}
|
|
306
323
|
const taken = takeBound(settings.boundByMarket, liveKey);
|
|
307
324
|
const stashed = Object.keys(typed).length > 0;
|
|
308
|
-
|
|
325
|
+
// With nothing typed, an older entry for `rowKey` goes too: on a return the defaults are what it held.
|
|
326
|
+
const list = stashed ? stashBound(taken.list, rowKey, typed) : taken.list.filter((entry) => entry.key !== rowKey);
|
|
309
327
|
const remembered = taken.values;
|
|
310
|
-
const defaults = isPlainRecord(options?.defaults) ? options.defaults : null;
|
|
311
328
|
let restored = false;
|
|
312
329
|
for (const unit of units) {
|
|
313
330
|
let source = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orangecharts/wrun-chart-host",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
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": [
|