@orangecharts/wrun-chart-host 0.1.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.
Files changed (198) hide show
  1. package/README.md +72 -0
  2. package/dist/constants/governed-exchanges.constants.d.ts +11 -0
  3. package/dist/constants/governed-exchanges.constants.js +11 -0
  4. package/dist/constants/indicator-sets.constants.d.ts +8 -0
  5. package/dist/constants/indicator-sets.constants.js +8 -0
  6. package/dist/constants/interval.constants.d.ts +34 -0
  7. package/dist/constants/interval.constants.js +121 -0
  8. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
  9. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
  10. package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
  11. package/dist/constants/tpo-color-schemes.constants.js +32 -0
  12. package/dist/host-env.d.ts +102 -0
  13. package/dist/host-env.js +26 -0
  14. package/dist/index.d.ts +93 -0
  15. package/dist/index.js +96 -0
  16. package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
  17. package/dist/indicators/controls/tpo-letter.util.js +13 -0
  18. package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
  19. package/dist/indicators/controls/tpo-session.util.js +389 -0
  20. package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
  21. package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
  22. package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
  23. package/dist/interfaces/om-panel-data.interface.js +7 -0
  24. package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
  25. package/dist/interfaces/wrun-runtime.interface.js +55 -0
  26. package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
  27. package/dist/utility/chart/calendar-interval.util.js +81 -0
  28. package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
  29. package/dist/utility/chart/candle-bar-end.util.js +23 -0
  30. package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
  31. package/dist/utility/chart/cme-realtime.util.js +53 -0
  32. package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
  33. package/dist/utility/chart/interval-ladder.util.js +92 -0
  34. package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
  35. package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
  36. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
  37. package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
  38. package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
  39. package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
  40. package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
  41. package/dist/utility/chart/kscript-output-role.util.js +215 -0
  42. package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
  43. package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
  44. package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
  45. package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
  46. package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
  47. package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
  48. package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
  49. package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
  50. package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
  51. package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
  52. package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
  53. package/dist/utility/chart/om-panel-push-style.util.js +301 -0
  54. package/dist/utility/chart/om-panel.util.d.ts +166 -0
  55. package/dist/utility/chart/om-panel.util.js +815 -0
  56. package/dist/utility/chart/om-series.util.d.ts +42 -0
  57. package/dist/utility/chart/om-series.util.js +330 -0
  58. package/dist/utility/chart/om-target.util.d.ts +11 -0
  59. package/dist/utility/chart/om-target.util.js +24 -0
  60. package/dist/utility/chart/om-widget.util.d.ts +148 -0
  61. package/dist/utility/chart/om-widget.util.js +413 -0
  62. package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
  63. package/dist/utility/chart/overlay-output-budget.util.js +109 -0
  64. package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
  65. package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
  66. package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
  67. package/dist/utility/chart/profile-row-height.util.js +110 -0
  68. package/dist/utility/chart/session-interval.util.d.ts +1 -0
  69. package/dist/utility/chart/session-interval.util.js +35 -0
  70. package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
  71. package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
  72. package/dist/utility/chart/trading-day.util.d.ts +70 -0
  73. package/dist/utility/chart/trading-day.util.js +238 -0
  74. package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
  75. package/dist/utility/chart/wrun-legend-name.util.js +87 -0
  76. package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
  77. package/dist/utility/chart/wrun-run-result.util.js +5179 -0
  78. package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
  79. package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
  80. package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
  81. package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
  82. package/dist/utility/number-format.util.d.ts +68 -0
  83. package/dist/utility/number-format.util.js +188 -0
  84. package/dist/utility/v2/opra-governed.util.d.ts +1 -0
  85. package/dist/utility/v2/opra-governed.util.js +13 -0
  86. package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
  87. package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
  88. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
  89. package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
  90. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
  91. package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
  92. package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
  93. package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
  94. package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
  95. package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
  96. package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
  97. package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
  98. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
  99. package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
  100. package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
  101. package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
  102. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
  103. package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
  104. package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
  105. package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
  106. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
  107. package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
  108. package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
  109. package/dist/utility/wrun/wrun-card-style.util.js +539 -0
  110. package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
  111. package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
  112. package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
  113. package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
  114. package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
  115. package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
  116. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
  117. package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
  118. package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
  119. package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
  120. package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
  121. package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
  122. package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
  123. package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
  124. package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
  125. package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
  126. package/dist/utility/wrun/wrun-frames.d.ts +217 -0
  127. package/dist/utility/wrun/wrun-frames.js +1021 -0
  128. package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
  129. package/dist/utility/wrun/wrun-handles.util.js +2050 -0
  130. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
  131. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
  132. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
  133. package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
  134. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
  135. package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
  136. package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
  137. package/dist/utility/wrun/wrun-hover.util.js +534 -0
  138. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
  139. package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
  140. package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
  141. package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
  142. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
  143. package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
  144. package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
  145. package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
  146. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
  147. package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
  148. package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
  149. package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
  150. package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
  151. package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
  152. package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
  153. package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
  154. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
  155. package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
  156. package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
  157. package/dist/utility/wrun/wrun-pack.util.js +301 -0
  158. package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
  159. package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
  160. package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
  161. package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
  162. package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
  163. package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
  164. package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
  165. package/dist/utility/wrun/wrun-param-values.util.js +230 -0
  166. package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
  167. package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
  168. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
  169. package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
  170. package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
  171. package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
  172. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
  173. package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
  174. package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
  175. package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
  176. package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
  177. package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
  178. package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
  179. package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
  180. package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
  181. package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
  182. package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
  183. package/dist/utility/wrun/wrun-style-words.util.js +439 -0
  184. package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
  185. package/dist/utility/wrun/wrun-table-look.util.js +225 -0
  186. package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
  187. package/dist/utility/wrun/wrun-text-look.util.js +227 -0
  188. package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
  189. package/dist/utility/wrun/wrun-text-params.util.js +171 -0
  190. package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
  191. package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
  192. package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
  193. package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
  194. package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
  195. package/dist/utility/wrun/wrun-visibility-table.js +237 -0
  196. package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
  197. package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
  198. package/package.json +38 -0
@@ -0,0 +1,42 @@
1
+ import type { SetSeriesData } from '../../interfaces/om-panel-data.interface.js';
2
+ export declare const OM_SERIES_MAX_ROWS = 2000;
3
+ export declare const OM_SERIES_MAX_PER_PANE = 16;
4
+ export declare const MAX_PANES = 64;
5
+ export declare const OM_SERIES_PAYLOAD_ID_PATTERN: RegExp;
6
+ /** Live frames retain wire seconds; downstream rendering uses only timesMs. */
7
+ export interface ParsedSeries {
8
+ chartIndex: number;
9
+ payloadId: string;
10
+ revision: number;
11
+ series: NonNullable<SetSeriesData['series']>;
12
+ times: number[];
13
+ timesMs: number[];
14
+ prices?: number[];
15
+ values: (number | null)[];
16
+ colors?: string[];
17
+ labels_text?: string[];
18
+ levels?: SetSeriesData['levels'];
19
+ inset?: SetSeriesData['inset'];
20
+ source?: SetSeriesData['source'];
21
+ /** The server's save time of a saved copy, set only by the persisted loader
22
+ * (news-pins-load.util) from its row's `pushedAt`: the legend's "as of"
23
+ * stamp. The parser never sets it and a live frame never has it. */
24
+ savedAtMs?: number;
25
+ }
26
+ export interface ParsedSeriesClear {
27
+ chartIndex: number;
28
+ payloadId: string;
29
+ revision: number;
30
+ clear: true;
31
+ }
32
+ export type ParsedSeriesFrame = ParsedSeries | ParsedSeriesClear;
33
+ export type SetSeriesParseResult = {
34
+ ok: true;
35
+ data: ParsedSeriesFrame;
36
+ } | {
37
+ ok: false;
38
+ rejectReason: string;
39
+ };
40
+ export declare function isSeriesClearFrame(frame: ParsedSeriesFrame): frame is ParsedSeriesClear;
41
+ /** Reject the whole envelope on any violation so malformed frames cannot advance floors. */
42
+ export declare function parseSetSeriesData(value: unknown): SetSeriesParseResult;
@@ -0,0 +1,330 @@
1
+ import { OM_MAIN_CADENCES } from './om-target.util.js';
2
+ export const OM_SERIES_MAX_ROWS = 2000;
3
+ const OM_SERIES_MAX_LEVELS = 512;
4
+ export const OM_SERIES_MAX_PER_PANE = 16;
5
+ export const MAX_PANES = 64;
6
+ export const OM_SERIES_PAYLOAD_ID_PATTERN = /^omse:c(0|[1-9][0-9]?):[a-z0-9][a-z0-9._-]{0,63}$/;
7
+ const SERIES_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
8
+ const COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/;
9
+ const FRAME_KEYS = new Set([
10
+ 'chartIndex',
11
+ 'payloadId',
12
+ 'revision',
13
+ 'clear',
14
+ 'series',
15
+ 'levels',
16
+ 'inset',
17
+ 'times',
18
+ 'values',
19
+ 'prices',
20
+ 'colors',
21
+ 'labels_text',
22
+ 'source',
23
+ ]);
24
+ const CLEAR_KEYS = new Set(['chartIndex', 'payloadId', 'revision', 'clear']);
25
+ const SERIES_KEYS = new Set(['id', 'title', 'kind', 'pane', 'group', 'scale', 'color', 'width', 'unit', 'cadence_s']);
26
+ /** Kinds that may share one lower pane; docked kinds and main series have their own homes. */
27
+ const GROUP_KINDS = new Set(['line', 'area', 'histogram', 'step', 'markers']);
28
+ const LEVELS_KEYS = new Set(['dock', 'width_frac', 'poc', 'labels', 'thickness_px']);
29
+ const INSET_KEYS = new Set(['dock', 'height_px', 'shape']);
30
+ const SOURCE_KEYS = new Set(['kind', 'ref', 'computedAtMs']);
31
+ const MAIN_CADENCES = new Set(OM_MAIN_CADENCES);
32
+ export function isSeriesClearFrame(frame) {
33
+ return frame.clear === true;
34
+ }
35
+ function isRecord(value) {
36
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
37
+ }
38
+ function isBoundedString(value, max) {
39
+ return typeof value === 'string' && value.length > 0 && value.length <= max;
40
+ }
41
+ function isFiniteNumber(value) {
42
+ return typeof value === 'number' && Number.isFinite(value);
43
+ }
44
+ function isNonnegativeInteger(value) {
45
+ return isFiniteNumber(value) && Number.isSafeInteger(value) && value >= 0;
46
+ }
47
+ /** Reject the whole envelope on any violation so malformed frames cannot advance floors. */
48
+ export function parseSetSeriesData(value) {
49
+ if (!isRecord(value))
50
+ return { ok: false, rejectReason: 'payload is not an object' };
51
+ if (Object.keys(value).some((key) => !FRAME_KEYS.has(key))) {
52
+ return { ok: false, rejectReason: 'unknown payload key' };
53
+ }
54
+ if (!isNonnegativeInteger(value.chartIndex) || value.chartIndex >= MAX_PANES) {
55
+ return { ok: false, rejectReason: 'invalid chartIndex' };
56
+ }
57
+ if (!isBoundedString(value.payloadId, 80) || !OM_SERIES_PAYLOAD_ID_PATTERN.test(value.payloadId)) {
58
+ return { ok: false, rejectReason: 'invalid payloadId' };
59
+ }
60
+ const payloadParts = value.payloadId.split(':');
61
+ if (payloadParts[1] !== `c${value.chartIndex}`) {
62
+ return { ok: false, rejectReason: 'payloadId does not match chartIndex' };
63
+ }
64
+ if (!isNonnegativeInteger(value.revision)) {
65
+ return { ok: false, rejectReason: 'invalid revision stamp' };
66
+ }
67
+ if (value.clear !== undefined && value.clear !== true) {
68
+ return { ok: false, rejectReason: 'invalid clear flag (only true is wire-legal)' };
69
+ }
70
+ if (value.clear === true) {
71
+ if (Object.keys(value).some((key) => !CLEAR_KEYS.has(key))) {
72
+ return { ok: false, rejectReason: 'clear payload carries baggage' };
73
+ }
74
+ return {
75
+ ok: true,
76
+ data: { chartIndex: value.chartIndex, payloadId: value.payloadId, revision: value.revision, clear: true },
77
+ };
78
+ }
79
+ const series = value.series;
80
+ if (!isRecord(series))
81
+ return { ok: false, rejectReason: 'invalid series' };
82
+ if (Object.keys(series).some((key) => !SERIES_KEYS.has(key))) {
83
+ return { ok: false, rejectReason: 'unknown series key' };
84
+ }
85
+ if (!isBoundedString(series.id, 64) || !SERIES_ID_PATTERN.test(series.id)) {
86
+ return { ok: false, rejectReason: 'invalid series.id' };
87
+ }
88
+ if (payloadParts[2] !== series.id)
89
+ return { ok: false, rejectReason: 'payloadId does not match series.id' };
90
+ if (!isBoundedString(series.title, 80))
91
+ return { ok: false, rejectReason: 'invalid series.title' };
92
+ if (series.kind !== 'line' &&
93
+ series.kind !== 'area' &&
94
+ series.kind !== 'histogram' &&
95
+ series.kind !== 'step' &&
96
+ series.kind !== 'markers' &&
97
+ series.kind !== 'levels' &&
98
+ series.kind !== 'inset') {
99
+ return { ok: false, rejectReason: 'invalid series.kind' };
100
+ }
101
+ if (series.pane !== 'overlay' && series.pane !== 'lower' && series.pane !== 'main') {
102
+ return { ok: false, rejectReason: 'invalid series.pane' };
103
+ }
104
+ if ((series.kind === 'levels' || series.kind === 'inset') && series.pane !== 'overlay') {
105
+ return { ok: false, rejectReason: 'docked series must use overlay pane' };
106
+ }
107
+ if (series.pane === 'main') {
108
+ if (series.kind !== 'line' && series.kind !== 'area' && series.kind !== 'step') {
109
+ return { ok: false, rejectReason: 'invalid main series kind' };
110
+ }
111
+ if (!isNonnegativeInteger(series.cadence_s) || !MAIN_CADENCES.has(series.cadence_s)) {
112
+ return { ok: false, rejectReason: 'invalid main series cadence_s' };
113
+ }
114
+ }
115
+ else if ('cadence_s' in series) {
116
+ return { ok: false, rejectReason: 'cadence_s is only legal on main' };
117
+ }
118
+ if (series.scale !== undefined &&
119
+ (series.pane !== 'overlay' || (series.scale !== 'shared' && series.scale !== 'own'))) {
120
+ return { ok: false, rejectReason: 'invalid series.scale' };
121
+ }
122
+ if (series.group !== undefined) {
123
+ if (!isBoundedString(series.group, 64) || !SERIES_ID_PATTERN.test(series.group)) {
124
+ return { ok: false, rejectReason: 'invalid series.group' };
125
+ }
126
+ if (series.pane !== 'lower' || !GROUP_KINDS.has(series.kind)) {
127
+ return { ok: false, rejectReason: 'group is only valid on the lower pane' };
128
+ }
129
+ }
130
+ if (series.color !== undefined && (typeof series.color !== 'string' || !COLOR_PATTERN.test(series.color))) {
131
+ return { ok: false, rejectReason: 'invalid series.color' };
132
+ }
133
+ if (series.width !== undefined && (!isNonnegativeInteger(series.width) || series.width < 1 || series.width > 10)) {
134
+ return { ok: false, rejectReason: 'invalid series.width' };
135
+ }
136
+ if (series.unit !== undefined && !isBoundedString(series.unit, 16)) {
137
+ return { ok: false, rejectReason: 'invalid series.unit' };
138
+ }
139
+ let levels;
140
+ let inset;
141
+ let prices;
142
+ let colors;
143
+ let labels_text;
144
+ const times = [];
145
+ if (series.kind === 'levels') {
146
+ if ('times' in value)
147
+ return { ok: false, rejectReason: 'levels cannot carry times' };
148
+ if ('inset' in value)
149
+ return { ok: false, rejectReason: 'inset is only legal on inset series' };
150
+ if (!isRecord(value.levels) || Object.keys(value.levels).some((key) => !LEVELS_KEYS.has(key))) {
151
+ return { ok: false, rejectReason: 'invalid levels object' };
152
+ }
153
+ const rawLevels = value.levels;
154
+ if (rawLevels.dock !== 'left' && rawLevels.dock !== 'right') {
155
+ return { ok: false, rejectReason: 'invalid levels.dock' };
156
+ }
157
+ if (rawLevels.width_frac !== undefined &&
158
+ (!isFiniteNumber(rawLevels.width_frac) || rawLevels.width_frac < 0.05 || rawLevels.width_frac > 0.5)) {
159
+ return { ok: false, rejectReason: 'invalid levels.width_frac' };
160
+ }
161
+ if (rawLevels.poc !== undefined && typeof rawLevels.poc !== 'boolean') {
162
+ return { ok: false, rejectReason: 'invalid levels.poc' };
163
+ }
164
+ if (rawLevels.labels !== undefined && typeof rawLevels.labels !== 'boolean') {
165
+ return { ok: false, rejectReason: 'invalid levels.labels' };
166
+ }
167
+ if (rawLevels.thickness_px !== undefined &&
168
+ (!isNonnegativeInteger(rawLevels.thickness_px) || rawLevels.thickness_px < 2 || rawLevels.thickness_px > 40)) {
169
+ return { ok: false, rejectReason: 'invalid levels.thickness_px' };
170
+ }
171
+ // Custom label text turns labels on: the engine paints level labels only
172
+ // under settings.labels, and a sender who wrote the words meant them to
173
+ // show. An explicit labels: false still wins.
174
+ const labels = rawLevels.labels ?? ('labels_text' in value ? true : undefined);
175
+ levels = {
176
+ dock: rawLevels.dock,
177
+ width_frac: rawLevels.width_frac ?? 0.12,
178
+ ...(rawLevels.poc !== undefined ? { poc: rawLevels.poc } : {}),
179
+ ...(labels !== undefined ? { labels } : {}),
180
+ ...(rawLevels.thickness_px !== undefined ? { thickness_px: rawLevels.thickness_px } : {}),
181
+ };
182
+ if (!Array.isArray(value.prices) || value.prices.length < 1 || value.prices.length > OM_SERIES_MAX_LEVELS) {
183
+ return { ok: false, rejectReason: `prices must contain 1..${OM_SERIES_MAX_LEVELS} items` };
184
+ }
185
+ prices = [];
186
+ let direction = 0;
187
+ for (const raw of value.prices) {
188
+ if (!isFiniteNumber(raw))
189
+ return { ok: false, rejectReason: 'non-finite price' };
190
+ const previous = prices.at(-1);
191
+ if (previous !== undefined) {
192
+ const step = Math.sign(raw - previous);
193
+ if (step === 0 || (direction !== 0 && step !== direction)) {
194
+ return { ok: false, rejectReason: 'prices are not strictly monotonic' };
195
+ }
196
+ direction = step;
197
+ }
198
+ prices.push(raw);
199
+ }
200
+ if (value.colors !== undefined) {
201
+ if (!Array.isArray(value.colors) ||
202
+ value.colors.length !== prices.length ||
203
+ value.colors.some((color) => typeof color !== 'string' || !COLOR_PATTERN.test(color))) {
204
+ return { ok: false, rejectReason: 'invalid levels colors' };
205
+ }
206
+ colors = [...value.colors];
207
+ }
208
+ if (value.labels_text !== undefined) {
209
+ if (!Array.isArray(value.labels_text) ||
210
+ value.labels_text.length !== prices.length ||
211
+ Array.from(value.labels_text).some((label) => !isBoundedString(label, 24))) {
212
+ return { ok: false, rejectReason: 'invalid levels labels_text' };
213
+ }
214
+ labels_text = [...value.labels_text];
215
+ }
216
+ }
217
+ else {
218
+ if ('prices' in value || 'colors' in value || 'labels_text' in value || 'levels' in value) {
219
+ return { ok: false, rejectReason: 'prices, colors, labels_text and levels are only legal on levels series' };
220
+ }
221
+ if (series.kind === 'inset') {
222
+ if (!isRecord(value.inset) || Object.keys(value.inset).some((key) => !INSET_KEYS.has(key))) {
223
+ return { ok: false, rejectReason: 'invalid inset object' };
224
+ }
225
+ const rawInset = value.inset;
226
+ if (rawInset.dock !== 'top' && rawInset.dock !== 'bottom') {
227
+ return { ok: false, rejectReason: 'invalid inset.dock' };
228
+ }
229
+ if (rawInset.height_px !== undefined &&
230
+ (!isFiniteNumber(rawInset.height_px) || rawInset.height_px < 16 || rawInset.height_px > 120)) {
231
+ return { ok: false, rejectReason: 'invalid inset.height_px' };
232
+ }
233
+ if (rawInset.shape !== undefined &&
234
+ rawInset.shape !== 'histogram' &&
235
+ rawInset.shape !== 'area' &&
236
+ rawInset.shape !== 'line') {
237
+ return { ok: false, rejectReason: 'invalid inset.shape' };
238
+ }
239
+ inset = {
240
+ dock: rawInset.dock,
241
+ height_px: rawInset.height_px ?? 28,
242
+ shape: rawInset.shape ?? 'histogram',
243
+ };
244
+ }
245
+ else if ('inset' in value) {
246
+ return { ok: false, rejectReason: 'inset is only legal on inset series' };
247
+ }
248
+ if (!Array.isArray(value.times))
249
+ return { ok: false, rejectReason: 'times is not an array' };
250
+ if (value.times.length < 1 || value.times.length > OM_SERIES_MAX_ROWS) {
251
+ return { ok: false, rejectReason: `rows must contain 1..${OM_SERIES_MAX_ROWS} items` };
252
+ }
253
+ for (const raw of value.times) {
254
+ if (!isNonnegativeInteger(raw))
255
+ return { ok: false, rejectReason: 'invalid timestamp' };
256
+ const previous = times[times.length - 1];
257
+ if (previous !== undefined && raw <= previous) {
258
+ return { ok: false, rejectReason: 'times are not strictly increasing' };
259
+ }
260
+ times.push(raw);
261
+ }
262
+ }
263
+ if (!Array.isArray(value.values))
264
+ return { ok: false, rejectReason: 'values is not an array' };
265
+ if (value.values.length !== (prices ?? times).length) {
266
+ return { ok: false, rejectReason: 'coordinates and values length mismatch' };
267
+ }
268
+ const values = [];
269
+ for (const raw of value.values) {
270
+ if (raw !== null && !isFiniteNumber(raw))
271
+ return { ok: false, rejectReason: 'non-finite value' };
272
+ values.push(raw);
273
+ }
274
+ if (series.kind !== 'levels' && !values.some((raw) => typeof raw === 'number')) {
275
+ return { ok: false, rejectReason: 'non-clear payload has no numeric values' };
276
+ }
277
+ let source;
278
+ if (value.source !== undefined) {
279
+ if (!isRecord(value.source))
280
+ return { ok: false, rejectReason: 'invalid source' };
281
+ const rawSource = value.source;
282
+ if (Object.keys(rawSource).some((key) => !SOURCE_KEYS.has(key))) {
283
+ return { ok: false, rejectReason: 'unknown source key' };
284
+ }
285
+ if (rawSource.kind !== 'watch' &&
286
+ rawSource.kind !== 'push' &&
287
+ rawSource.kind !== 'metric' &&
288
+ rawSource.kind !== 'custom') {
289
+ return { ok: false, rejectReason: 'invalid source.kind' };
290
+ }
291
+ if (!isBoundedString(rawSource.ref, 160))
292
+ return { ok: false, rejectReason: 'invalid source.ref' };
293
+ if (!isFiniteNumber(rawSource.computedAtMs) || rawSource.computedAtMs < 0) {
294
+ return { ok: false, rejectReason: 'invalid source.computedAtMs' };
295
+ }
296
+ source = { kind: rawSource.kind, ref: rawSource.ref, computedAtMs: rawSource.computedAtMs };
297
+ }
298
+ return {
299
+ ok: true,
300
+ data: {
301
+ chartIndex: value.chartIndex,
302
+ payloadId: value.payloadId,
303
+ revision: value.revision,
304
+ series: {
305
+ id: series.id,
306
+ title: series.title,
307
+ kind: series.kind,
308
+ pane: series.pane,
309
+ ...(series.group !== undefined ? { group: series.group } : {}),
310
+ ...(series.scale !== undefined ? { scale: series.scale } : {}),
311
+ ...(series.color !== undefined ? { color: series.color } : {}),
312
+ ...(series.width !== undefined ? { width: series.width } : {}),
313
+ ...(series.unit !== undefined ? { unit: series.unit } : {}),
314
+ ...(series.cadence_s !== undefined
315
+ ? { cadence_s: series.cadence_s }
316
+ : {}),
317
+ },
318
+ times,
319
+ // The single seconds-to-ms boundary for this receive lane.
320
+ timesMs: times.map((time) => time * 1000),
321
+ values,
322
+ ...(prices !== undefined ? { prices } : {}),
323
+ ...(colors !== undefined ? { colors } : {}),
324
+ ...(labels_text !== undefined ? { labels_text } : {}),
325
+ ...(levels !== undefined ? { levels } : {}),
326
+ ...(inset !== undefined ? { inset } : {}),
327
+ ...(source !== undefined ? { source } : {}),
328
+ },
329
+ };
330
+ }
@@ -0,0 +1,11 @@
1
+ export declare const TARGET_EXCHANGE = "OM";
2
+ export declare const OM_MAIN_CADENCES: readonly [60, 300, 900, 1800, 3600, 14400, 86400, 604800];
3
+ export type OmTargetMetadata = {
4
+ symbol?: unknown;
5
+ exchange?: unknown;
6
+ } | null | undefined;
7
+ export declare function isOmTargetSymbol(symbol: unknown): symbol is string;
8
+ export declare function isOmTargetPane(metadata: OmTargetMetadata): boolean;
9
+ export declare function omTargetKind(metadata: OmTargetMetadata): 'series' | 'panel' | null;
10
+ /** Only daemon cadences are legal, even when another chart interval exists. */
11
+ export declare function cadenceToInterval(cadenceSeconds: unknown): string | null;
@@ -0,0 +1,24 @@
1
+ import { Intervals } from '../../constants/interval.constants.js';
2
+ import { intervalLabelForMs } from './interval-ladder.util.js';
3
+ export const TARGET_EXCHANGE = 'OM';
4
+ export const OM_MAIN_CADENCES = [60, 300, 900, 1800, 3600, 14400, 86400, 604800];
5
+ export function isOmTargetSymbol(symbol) {
6
+ return typeof symbol === 'string' && (symbol.startsWith('series:') || symbol.startsWith('panel:'));
7
+ }
8
+ export function isOmTargetPane(metadata) {
9
+ return metadata?.exchange === TARGET_EXCHANGE && isOmTargetSymbol(metadata?.symbol);
10
+ }
11
+ export function omTargetKind(metadata) {
12
+ if (!isOmTargetPane(metadata))
13
+ return null;
14
+ return metadata.symbol.startsWith('series:') ? 'series' : 'panel';
15
+ }
16
+ /** Only daemon cadences are legal, even when another chart interval exists. */
17
+ export function cadenceToInterval(cadenceSeconds) {
18
+ if (typeof cadenceSeconds !== 'number' || !OM_MAIN_CADENCES.includes(cadenceSeconds)) {
19
+ return null;
20
+ }
21
+ const milliseconds = cadenceSeconds * 1000;
22
+ const interval = intervalLabelForMs(milliseconds);
23
+ return interval && Intervals.map_unit[interval] === milliseconds ? interval : null;
24
+ }
@@ -0,0 +1,148 @@
1
+ export declare const OM_WIDGET_MAX_ROWS = 12;
2
+ export declare const OM_WIDGET_MAX_BYTES: number;
3
+ export declare const OM_WIDGET_MAX_PER_PANE = 8;
4
+ export declare const MAX_PANES = 64;
5
+ export declare const OM_WIDGET_PAYLOAD_ID_PATTERN: RegExp;
6
+ export type CardAnchor = 'top_left' | 'top_center' | 'top_right' | 'middle_left' | 'middle_center' | 'middle_right' | 'bottom_left' | 'bottom_center' | 'bottom_right';
7
+ interface CardRow {
8
+ label: string;
9
+ value?: string;
10
+ color?: string;
11
+ countdown_to?: number;
12
+ clock?: true;
13
+ spark?: number[];
14
+ }
15
+ interface AnchoredWidgetProps {
16
+ anchor?: CardAnchor;
17
+ offset?: [number, number];
18
+ z?: number;
19
+ }
20
+ export interface CardProps extends AnchoredWidgetProps {
21
+ title: string;
22
+ state?: 'ok' | 'armed' | 'fired' | 'error';
23
+ rows: CardRow[];
24
+ }
25
+ export interface CardWidget extends CardProps {
26
+ kind: 'card';
27
+ id: string;
28
+ }
29
+ export type LadderRow = [price: number, value: number, fraction: number, color?: string];
30
+ export interface LadderProps {
31
+ title: string;
32
+ side: 'right' | 'left';
33
+ divider?: {
34
+ label: string;
35
+ price: number;
36
+ };
37
+ rows: LadderRow[];
38
+ }
39
+ interface LadderWidget extends LadderProps {
40
+ kind: 'ladder';
41
+ id: string;
42
+ }
43
+ export type FeedLine = [timeMs: number, text: string, color?: string];
44
+ export interface FeedProps extends AnchoredWidgetProps {
45
+ title: string;
46
+ lines: FeedLine[];
47
+ }
48
+ interface FeedWidget extends FeedProps {
49
+ kind: 'feed';
50
+ id: string;
51
+ }
52
+ export interface MeterProps extends AnchoredWidgetProps {
53
+ title: string;
54
+ label: string;
55
+ fraction: number;
56
+ ramp: string[];
57
+ text?: string;
58
+ }
59
+ interface MeterWidget extends MeterProps {
60
+ kind: 'meter';
61
+ id: string;
62
+ }
63
+ type WidgetDrawingAnchor = CardAnchor | 'top' | 'bottom' | 'left' | 'right';
64
+ /** Where a label's text sits relative to (x, y): `left` starts there, `right` ends there, absent = `center`. */
65
+ type WidgetLabelAlign = 'left' | 'center' | 'right';
66
+ interface WidgetDrawingBase {
67
+ anchor?: WidgetDrawingAnchor;
68
+ color?: string;
69
+ }
70
+ interface WidgetDrawingCorners extends WidgetDrawingBase {
71
+ x1: number;
72
+ y1: number;
73
+ x2: number;
74
+ y2: number;
75
+ }
76
+ export type WidgetDrawingItem = (WidgetDrawingCorners & {
77
+ kind: 'line';
78
+ width?: number;
79
+ style?: 'solid' | 'dashed' | 'dotted';
80
+ }) | (WidgetDrawingCorners & {
81
+ kind: 'box';
82
+ border?: string;
83
+ border_width?: number;
84
+ text?: string;
85
+ text_color?: string;
86
+ text_size?: number;
87
+ }) | (WidgetDrawingBase & {
88
+ kind: 'label';
89
+ x: number;
90
+ y: number;
91
+ text: string;
92
+ size?: number;
93
+ align?: WidgetLabelAlign;
94
+ }) | (WidgetDrawingBase & {
95
+ kind: 'marker';
96
+ x: number;
97
+ y: number;
98
+ shape: 'circle' | 'square' | 'diamond' | 'up' | 'down' | 'cross';
99
+ size?: number;
100
+ }) | (WidgetDrawingBase & {
101
+ kind: 'polyline';
102
+ points: [number, number][];
103
+ width?: number;
104
+ });
105
+ export interface DrawingsWidget {
106
+ kind: 'drawings';
107
+ id: string;
108
+ title: string;
109
+ items: WidgetDrawingItem[];
110
+ }
111
+ export type OmWidget = CardWidget | LadderWidget | FeedWidget | MeterWidget | DrawingsWidget;
112
+ export type OmWidgetInput = (Omit<CardWidget, 'kind'> & {
113
+ kind?: 'card';
114
+ }) | LadderWidget | FeedWidget | MeterWidget | DrawingsWidget;
115
+ export interface WidgetSource {
116
+ kind: 'watch' | 'strategy' | 'metric' | 'custom';
117
+ ref: string;
118
+ computedAtMs: number;
119
+ }
120
+ export interface ParsedWidget {
121
+ chartIndex: number;
122
+ payloadId: string;
123
+ revision: number;
124
+ widget: OmWidget;
125
+ source?: WidgetSource;
126
+ /** The server's save time of a saved copy, set only by the persisted loader
127
+ * (news-pins-load.util) from its row's `pushedAt`: the legend's "as of"
128
+ * stamp. The parser never sets it and a live frame never has it. */
129
+ savedAtMs?: number;
130
+ }
131
+ export interface ParsedWidgetClear {
132
+ chartIndex: number;
133
+ payloadId: string;
134
+ revision: number;
135
+ clear: true;
136
+ }
137
+ export type ParsedWidgetFrame = ParsedWidget | ParsedWidgetClear;
138
+ export type WidgetParseResult = {
139
+ ok: true;
140
+ data: ParsedWidgetFrame;
141
+ } | {
142
+ ok: false;
143
+ rejectReason: string;
144
+ };
145
+ export declare function isWidgetClearFrame(frame: ParsedWidgetFrame): frame is ParsedWidgetClear;
146
+ /** Reject the whole envelope before a malformed frame can advance a revision floor. */
147
+ export declare function parseWidgetFrame(value: unknown): WidgetParseResult;
148
+ export {};