@gloom-sh/terminal 0.20.22 → 0.20.23
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/package.json +1 -1
- package/src/account/heard-from-question.tsx +6 -4
- package/src/account/heard-from.ts +3 -4
- package/src/api-client/exchange-announcements.ts +2 -2
- package/src/api-client/heard-from.ts +5 -7
- package/src/api-client/ownership-disclosures.ts +38 -5
- package/src/api-client/types/ticker-data.ts +3 -1
- package/src/architecture/dom-cell-metrics-allowlist.json +2 -2
- package/src/cli/commands/market.ts +5 -3
- package/src/cli/commands/overview.ts +7 -9
- package/src/cli/listing-arg.ts +45 -18
- package/src/cli/pane-functions/catalog-snapshot.json +2 -2
- package/src/cli/pane-functions/data.ts +3 -1
- package/src/cli/pane-functions/freshness.ts +6 -1
- package/src/cli/pane-functions/function-help.ts +0 -2
- package/src/cli/pane-functions/market-session.ts +12 -2
- package/src/cli/pane-functions/screenshot-payload.ts +3 -1
- package/src/cli/symbol-list.ts +52 -14
- package/src/cli/ticker-resolution.ts +133 -38
- package/src/components/chart/composite/composite-chart.tsx +12 -0
- package/src/components/chart/composite/types.ts +18 -0
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +38 -15
- package/src/components/chart-table/header.tsx +11 -5
- package/src/components/chart-table/selection.ts +20 -1
- package/src/components/data-table/view.tsx +2 -0
- package/src/components/feed-data-table/stack-view.tsx +85 -5
- package/src/components/layout/pane/header.tsx +12 -30
- package/src/components/ticker/badge/index.tsx +9 -4
- package/src/components/ticker/badge/list.tsx +3 -1
- package/src/components/ui/data-table/index.tsx +7 -1
- package/src/components/ui/data-table/muted-row.tsx +47 -0
- package/src/components/ui/data-table/opentui/index.tsx +42 -11
- package/src/components/ui/data-table/spill.ts +36 -0
- package/src/components/ui/data-table/types.ts +17 -1
- package/src/components/ui/data-table/use-column-order.ts +11 -0
- package/src/components/ui/icon.tsx +50 -3
- package/src/components/ui/list-view.tsx +2 -2
- package/src/components/ui/table-layout.ts +32 -0
- package/src/components/ui/terminal-hover-label.tsx +49 -0
- package/src/components/use-pinned-moment.ts +222 -13
- package/src/core/state/app/state.ts +11 -2
- package/src/core/state/app/types.ts +2 -1
- package/src/data/sqlite/access.ts +14 -1
- package/src/data/sqlite/checkpointer.ts +2 -2
- package/src/data/sqlite/database.ts +4 -0
- package/src/docs/snapshot.json +180 -26
- package/src/i18n/es.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/zh-cn.ts +1 -0
- package/src/i18n/zh-tw.ts +1 -0
- package/src/market-data/market/freshness.ts +2 -2
- package/src/market-data/market/globex-day.ts +14 -0
- package/src/market-data/published-us-sessions.ts +3 -2
- package/src/market-data/quotes/live-valuation.ts +4 -2
- package/src/market-data/quotes/metadata.ts +48 -5
- package/src/market-data/quotes/regular-session-valuation.ts +12 -1
- package/src/plugins/builtin/alerts/history-pane.tsx +19 -3
- package/src/plugins/builtin/broker-trading/orders.tsx +4 -2
- package/src/plugins/builtin/chat/attachments/desktop.tsx +46 -12
- package/src/plugins/builtin/chat/channels.ts +5 -2
- package/src/plugins/builtin/chat/content/composer-runtime.ts +64 -65
- package/src/plugins/builtin/chat/content/footer.tsx +17 -7
- package/src/plugins/builtin/chat/content/index.tsx +108 -36
- package/src/plugins/builtin/chat/content/new-dm-dialog.tsx +21 -8
- package/src/plugins/builtin/chat/content/selection-runtime.ts +16 -0
- package/src/plugins/builtin/chat/content/shortcuts.ts +3 -0
- package/src/plugins/builtin/chat/content/snapshot.ts +37 -13
- package/src/plugins/builtin/chat/content/transcript.tsx +12 -0
- package/src/plugins/builtin/chat/content/types.ts +2 -0
- package/src/plugins/builtin/chat/controller/channels.ts +15 -15
- package/src/plugins/builtin/chat/controller/index.ts +140 -34
- package/src/plugins/builtin/chat/controller/lifecycle.ts +8 -12
- package/src/plugins/builtin/chat/controller/persistence.ts +32 -4
- package/src/plugins/builtin/chat/controller/send.ts +41 -17
- package/src/plugins/builtin/chat/controller/session-runtime.ts +28 -27
- package/src/plugins/builtin/chat/controller/state.ts +17 -8
- package/src/plugins/builtin/chat/controller/storage.ts +41 -4
- package/src/plugins/builtin/chat/controller/view.ts +6 -3
- package/src/plugins/builtin/chat/index.tsx +1 -1
- package/src/plugins/builtin/chat/layout.ts +8 -1
- package/src/plugins/builtin/chat/message/desktop.tsx +15 -11
- package/src/plugins/builtin/chat/message/header.tsx +112 -30
- package/src/plugins/builtin/chat/message/reactions.tsx +10 -11
- package/src/plugins/builtin/chat/message/render-state.ts +4 -2
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/message/types.ts +5 -0
- package/src/plugins/builtin/cloud-tweets/table.tsx +25 -2
- package/src/plugins/builtin/company-kpis/model.ts +11 -3
- package/src/plugins/builtin/correlation/compute.ts +6 -1
- package/src/plugins/builtin/custom-view/loader.ts +95 -34
- package/src/plugins/builtin/custom-view/pane.tsx +31 -41
- package/src/plugins/builtin/custom-view/table.ts +201 -0
- package/src/plugins/builtin/dividend-yield/client.ts +14 -17
- package/src/plugins/builtin/dividend-yield/headless.ts +0 -1
- package/src/plugins/builtin/dividend-yield/model.ts +45 -6
- package/src/plugins/builtin/dividend-yield/pane.tsx +70 -7
- package/src/plugins/builtin/dividend-yield/types.ts +2 -3
- package/src/plugins/builtin/dividend-yield/view.ts +22 -2
- package/src/plugins/builtin/econ/calendar-model.ts +135 -0
- package/src/plugins/builtin/econ/columns.ts +132 -0
- package/src/plugins/builtin/econ/index.tsx +25 -65
- package/src/plugins/builtin/holders/disclosures-view.tsx +9 -6
- package/src/plugins/builtin/holders/disclosures.ts +20 -6
- package/src/plugins/builtin/holders/headless.ts +2 -2
- package/src/plugins/builtin/ipo-calendar/model.ts +30 -1
- package/src/plugins/builtin/ipo-calendar/pane.tsx +7 -3
- package/src/plugins/builtin/kelly-sizer/headless.ts +9 -4
- package/src/plugins/builtin/kelly-sizer/pane.tsx +19 -9
- package/src/plugins/builtin/kelly-sizer/units.ts +26 -0
- package/src/plugins/builtin/market-halts/pane.tsx +14 -2
- package/src/plugins/builtin/news/wire/news/row.ts +5 -12
- package/src/plugins/builtin/news/wire/news/table.tsx +32 -41
- package/src/plugins/builtin/pe-band/headless.ts +1 -1
- package/src/plugins/builtin/pe-band/model.ts +41 -18
- package/src/plugins/builtin/pe-band/pane.tsx +6 -5
- package/src/plugins/builtin/perps/equity-row.tsx +4 -6
- package/src/plugins/builtin/perps/markets-section.tsx +19 -15
- package/src/plugins/builtin/perps/model.ts +10 -2
- package/src/plugins/builtin/portfolio-list/cli/import-positions.ts +6 -18
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +1 -1
- package/src/plugins/builtin/portfolio-list/pane/purchase-date-fx.ts +1 -1
- package/src/plugins/builtin/portfolio-list/positions-import/index.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/positions-import/lookup.ts +28 -57
- package/src/plugins/builtin/research/event-data.ts +3 -1
- package/src/plugins/builtin/research/event-model.ts +17 -15
- package/src/plugins/builtin/research/relative-valuation-columns.ts +19 -6
- package/src/plugins/builtin/research/relative-valuation-headless.ts +1 -1
- package/src/plugins/builtin/scanner/flow-pane.tsx +10 -0
- package/src/plugins/builtin/sec/exchange-filings.ts +32 -7
- package/src/plugins/builtin/sec/headless.ts +8 -8
- package/src/plugins/builtin/sec/index.tsx +69 -29
- package/src/plugins/builtin/shared/report-freshness.ts +4 -1
- package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +1 -2
- package/src/plugins/builtin/ticker-detail/financials/exchange-table.tsx +61 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +38 -4
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +68 -39
- package/src/plugins/builtin/ticker-detail/headless.ts +4 -1
- package/src/plugins/builtin/ticker-detail/overview/model.ts +61 -15
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +5 -0
- package/src/plugins/builtin/time-sales/model.ts +16 -9
- package/src/plugins/builtin/time-sales/pane.tsx +27 -24
- package/src/plugins/builtin/treasury-daily/client.ts +43 -9
- package/src/plugins/builtin/treasury-daily/pane.tsx +48 -27
- package/src/plugins/builtin/treasury-daily/resource.ts +33 -0
- package/src/portfolio/positions-import/parse.ts +14 -6
- package/src/portfolio/positions-import/plan.ts +3 -2
- package/src/react/async-resource.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +40 -0
- package/src/renderers/dom/data-table/row.tsx +39 -3
- package/src/renderers/dom/desktop/icons.tsx +147 -3
- package/src/renderers/dom/desktop/popover.tsx +2 -2
- package/src/renderers/dom/host/media-surface.tsx +204 -45
- package/src/renderers/dom/host/tabs.tsx +1 -0
- package/src/renderers/dom/styles.css +14 -2
- package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
- package/src/renderers/electrobun/bun/desktop/rpc-timing.ts +9 -3
- package/src/renderers/electrobun/shared/protocol.ts +2 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +5 -2
- package/src/renderers/electrobun/view/rpc-timeout.ts +44 -3
- package/src/sources/gloomberb-cloud/index.ts +8 -7
- package/src/sources/gloomberb-cloud/normalizers.ts +7 -2
- package/src/sources/listing-symbols.ts +7 -1
- package/src/sources/provider-router/cache.ts +5 -4
- package/src/sources/provider-router/financials.ts +40 -18
- package/src/state/app/tab-cursor.ts +47 -6
- package/src/telemetry/stall-clocks.ts +3 -0
- package/src/telemetry/stall-reports.ts +12 -3
- package/src/telemetry/windows-process-activity.ts +41 -0
- package/src/telemetry/windows-time.ts +32 -0
- package/src/test-support/scoped-earnings.ts +24 -0
- package/src/tickers/terminal-codes.ts +1 -6
- package/src/time-series/daily-valuation.ts +13 -6
- package/src/time-series/filed-trailing-eps.ts +16 -3
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/historical-valuation.ts +20 -0
- package/src/time-series/fundamentals/series.ts +13 -1
- package/src/time-series/valuation-currency.ts +2 -0
- package/src/types/financials.ts +46 -10
- package/src/ui/dialog-context.ts +8 -0
- package/src/utils/datetime-format.ts +23 -1
- package/src/utils/declared-dividends.ts +12 -2
- package/src/utils/exchange-announcements.ts +4 -1
- package/src/utils/exchange-notation.generated.ts +3 -1
- package/src/utils/exchanges.ts +2 -1
- package/src/utils/fundamentals.ts +1 -0
- package/src/utils/main-thread-stall.ts +9 -1
- package/src/utils/rpc-timeout-error.ts +36 -11
- package/src/utils/sec.ts +3 -1
- package/src/utils/share-multiples.ts +1 -1
- package/src/utils/stall-process-activity.ts +70 -0
- package/src/utils/statement-scope.ts +103 -0
- package/src/utils/trailing-eps.ts +1 -1
- package/src/utils/zoned-date-time.ts +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listingSuffixExchange } from "../sources/listing-symbols";
|
|
2
2
|
import { canonicalExchange, parsePublicTickerKey, typedExchangeVenue } from "./exchanges";
|
|
3
|
+
import { nonUsSecListingVenue } from "./sec";
|
|
3
4
|
|
|
4
5
|
/** Where a listing's company announcements are published: the venue's page for the company, or its disclosure search. */
|
|
5
6
|
export interface ExchangeAnnouncementsPage {
|
|
@@ -38,6 +39,7 @@ const PAGES: Readonly<Record<string, (code: string) => ExchangeAnnouncementsPage
|
|
|
38
39
|
HNX: (code) => ({ name: "Hanoi Stock Exchange issuer disclosures", url: `https://www.hnx.vn/cophieu-etfs/chi-tiet-chung-khoan-ny-${encodeURIComponent(code.toLowerCase())}.html?_des_tab=3` }),
|
|
39
40
|
HOSE: () => ({ name: "Ho Chi Minh Stock Exchange issuer disclosures", url: "https://www.hsx.vn/vi/tin-tuc/tin-to-chuc-niem-yet" }),
|
|
40
41
|
JAKARTA: () => ({ name: "Indonesia Stock Exchange disclosures", url: "https://www.idx.id/en/listed-companies/disclosure" }),
|
|
42
|
+
XPHS: () => ({ name: "Philippine Stock Exchange company announcements", url: "https://edge.pse.com.ph/announcements/form.do" }),
|
|
41
43
|
JPX: () => ({ name: "TDnet timely disclosures", url: "https://www.release.tdnet.info/inbs/I_main_00.html" }),
|
|
42
44
|
HKEX: () => ({ name: "HKEXnews", url: "https://www1.hkexnews.hk/search/titlesearch.xhtml?lang=en" }),
|
|
43
45
|
SWX: () => ({ name: "SIX Swiss Exchange", url: "https://www.six-group.com/en/market-data/news-tools/equity-issuer-news.html" }),
|
|
@@ -60,7 +62,7 @@ export function issuerFilingSuffixVenue(symbol: string): string | undefined {
|
|
|
60
62
|
if (/^\d{4}\.KL$/i.test(symbol)) return "BURSAMY";
|
|
61
63
|
if (/^[A-Z]{4}\.JK$/i.test(symbol)) return "JAKARTA";
|
|
62
64
|
if (/^[A-Z0-9][A-Z0-9&-]*\.BK$/i.test(symbol)) return "SET";
|
|
63
|
-
return undefined;
|
|
65
|
+
return nonUsSecListingVenue(symbol) ?? undefined;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/** The overseas venue's disclosure page, when the listing has one. */
|
|
@@ -74,6 +76,7 @@ const PUBLISHERS: Readonly<Record<string, string>> = {
|
|
|
74
76
|
TWSE: "MOPS", TPEX: "MOPS",
|
|
75
77
|
BURSAMY: "Bursa Malaysia",
|
|
76
78
|
JAKARTA: "Indonesia Stock Exchange",
|
|
79
|
+
XPHS: "Philippine Stock Exchange",
|
|
77
80
|
ASX: "ASX", CXA: "ASX", HKEX: "HKEXnews", SWX: "SIX Swiss Exchange", NSE: "NSE", SET: "SET",
|
|
78
81
|
JPX: "TDnet", HNX: "HNX", HOSE: "HOSE", KRX: "DART", KOSDAQ: "DART", SGX: "SGX", SSE: "CNINFO", SZSE: "CNINFO",
|
|
79
82
|
};
|
|
@@ -139,6 +139,7 @@ export const EXCHANGE_NOTATION: ExchangeNotation = {
|
|
|
139
139
|
XWAR: "WSE",
|
|
140
140
|
PRA: "PSE",
|
|
141
141
|
XPRA: "PSE",
|
|
142
|
+
XPHS: "XPHS",
|
|
142
143
|
VIE: "VIE",
|
|
143
144
|
VIENNA: "VIE",
|
|
144
145
|
XWBO: "VIE",
|
|
@@ -363,6 +364,7 @@ export const EXCHANGE_NOTATION: ExchangeNotation = {
|
|
|
363
364
|
ICEX: "Nasdaq Iceland",
|
|
364
365
|
WSE: "Warsaw Stock Exchange",
|
|
365
366
|
PSE: "Prague Stock Exchange",
|
|
367
|
+
XPHS: "Philippine Stock Exchange",
|
|
366
368
|
VIE: "Vienna Stock Exchange",
|
|
367
369
|
WBDM: "Vienna MTF",
|
|
368
370
|
TWSE: "Taiwan Stock Exchange",
|
|
@@ -413,4 +415,4 @@ export const EXCHANGE_NOTATION: ExchangeNotation = {
|
|
|
413
415
|
},
|
|
414
416
|
}
|
|
415
417
|
|
|
416
|
-
export const EXCHANGE_NOTATION_VERSION = "
|
|
418
|
+
export const EXCHANGE_NOTATION_VERSION = "c496447bd0bb1aa4"
|
package/src/utils/exchanges.ts
CHANGED
|
@@ -47,6 +47,7 @@ export const EXCHANGE_TIME_ZONES: Record<string, string> = {
|
|
|
47
47
|
LSE: "Europe/London",
|
|
48
48
|
ASX: "Australia/Sydney",
|
|
49
49
|
SGX: "Asia/Singapore",
|
|
50
|
+
XPHS: "Asia/Manila",
|
|
50
51
|
HOSE: "Asia/Ho_Chi_Minh",
|
|
51
52
|
HNX: "Asia/Ho_Chi_Minh",
|
|
52
53
|
KRX: "Asia/Seoul",
|
|
@@ -213,7 +214,7 @@ const US_EQUITY_EXCHANGES: ReadonlySet<string> = new Set([
|
|
|
213
214
|
*/
|
|
214
215
|
export function isUsOtcVenue(value?: string): boolean {
|
|
215
216
|
const venue = canonicalExchange(value);
|
|
216
|
-
return US_OTC_EXCHANGES.has(venue) || /^(?:OTC MARKETS\b|
|
|
217
|
+
return US_OTC_EXCHANGES.has(venue) || /^(?:OTC MARKETS\b|OTC(?:PK|QX|QB|ID|BB|B|M|Q)$|OID$|PINX$|EXPM$|NASDAQ OTCBB$|PINK SHEETS$|OTHER OTC$)/.test(venue);
|
|
217
218
|
}
|
|
218
219
|
|
|
219
220
|
/** A US venue a stock or fund trades on, listed or over the counter. */
|
|
@@ -489,6 +489,7 @@ export function ttmAtAppRate<T extends Fundamentals>(fundamentals: T, rate: AppF
|
|
|
489
489
|
const factor = rate.rate / conversion.rate;
|
|
490
490
|
const shown: T = { ...fundamentals };
|
|
491
491
|
for (const key of TTM_AMOUNTS) {
|
|
492
|
+
if (key === "freeCashFlow" && fundamentals.freeCashFlowCurrency !== undefined && fundamentals.freeCashFlowCurrency !== fundamentals.financialCurrency) continue;
|
|
492
493
|
const value = fundamentals[key];
|
|
493
494
|
if (finiteNumber(value)) (shown as Fundamentals)[key] = Math.round(value * factor);
|
|
494
495
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { lastPerfSample, recordPerfSample, takeHeldPerfSample, takePersonWaitMs, withoutLastStep } from "./perf-marks";
|
|
2
|
+
import { processActivityDelta, type ProcessActivityDelta, type ProcessActivityReading } from "./stall-process-activity";
|
|
2
3
|
|
|
3
4
|
/** How often the monitor checks in. Short enough to date a stall precisely. */
|
|
4
5
|
const SAMPLE_INTERVAL_MS = 250;
|
|
@@ -29,6 +30,7 @@ export interface StallClockReading {
|
|
|
29
30
|
threadCpuMs: number | null;
|
|
30
31
|
/** CPU time the whole process has used, every thread together. */
|
|
31
32
|
processCpuMs: number | null;
|
|
33
|
+
processActivity?: ProcessActivityReading;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export interface StallEvent {
|
|
@@ -61,6 +63,8 @@ export interface StallEvent {
|
|
|
61
63
|
threadCpu?: number;
|
|
62
64
|
/** CPU the process's other threads used meanwhile, in cores (1: one core throughout). */
|
|
63
65
|
otherCpu?: number;
|
|
66
|
+
/** Windows process-wide counts over the sampling interval, not attribution to the stalled thread. */
|
|
67
|
+
processActivity?: ProcessActivityDelta;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
let stallSink: ((event: StallEvent) => void) | null = null;
|
|
@@ -102,7 +106,9 @@ function readStallClocks(read: (() => StallClockReading) | null): StallClockRead
|
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
function delta(after: number | null | undefined, before: number | null | undefined): number | null {
|
|
105
|
-
|
|
109
|
+
if (after == null || before == null) return null;
|
|
110
|
+
const elapsed = after - before;
|
|
111
|
+
return elapsed >= 0 && Number.isFinite(elapsed) ? elapsed : null;
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
/**
|
|
@@ -208,6 +214,7 @@ export function startMainThreadStallMonitor(
|
|
|
208
214
|
const sqlite = sample?.name === "sqlite.blocked" ? sqliteDetail(sample.metadata) : undefined;
|
|
209
215
|
const threadCpuMs = delta(currentClocks?.threadCpuMs, before?.threadCpuMs);
|
|
210
216
|
const processCpuMs = delta(currentClocks?.processCpuMs, before?.processCpuMs);
|
|
217
|
+
const activity = processActivityDelta(before === null ? null : before?.processActivity, currentClocks === null ? null : currentClocks?.processActivity);
|
|
211
218
|
report(blockedMs, {
|
|
212
219
|
...(sample
|
|
213
220
|
? { lastMeasured: sample.name, lastMeasuredEndedMsAgo: Math.round(current - sample.endedAt) }
|
|
@@ -220,6 +227,7 @@ export function startMainThreadStallMonitor(
|
|
|
220
227
|
...(threadCpuMs == null || processCpuMs == null
|
|
221
228
|
? {}
|
|
222
229
|
: { otherCpu: Math.max(0, (processCpuMs - threadCpuMs) / (elapsedMs - asleepMs)) }),
|
|
230
|
+
...(activity ? { processActivity: activity } : {}),
|
|
223
231
|
});
|
|
224
232
|
}, intervalMs);
|
|
225
233
|
if (handle && typeof (handle as { unref?: () => void }).unref === "function") {
|
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export interface RpcClockSample {
|
|
2
|
+
wallMs: number;
|
|
3
|
+
elapsedMs: number;
|
|
4
|
+
awakeMs: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const RPC_CLOCK_FRESHNESS_MS = 1_000;
|
|
8
|
+
const CLOCK_SLOP_MS = 100;
|
|
9
|
+
const MIN_SLEEP_MS = 5_000;
|
|
10
|
+
|
|
11
|
+
/** A conservative upper bound on the request's awake time, only when the clocks also show sleep. */
|
|
12
|
+
export function rpcAwakeTimeBound(
|
|
13
|
+
startedAt: number,
|
|
14
|
+
timedOutAt: number,
|
|
15
|
+
before: RpcClockSample | null,
|
|
16
|
+
after: RpcClockSample | null,
|
|
17
|
+
): number | null {
|
|
18
|
+
if (!before || !after || ![startedAt, timedOutAt, before.wallMs, after.wallMs, before.elapsedMs, after.elapsedMs, before.awakeMs, after.awakeMs].every(Number.isFinite)) return null;
|
|
19
|
+
if (timedOutAt <= startedAt || Math.abs(before.wallMs - startedAt) > RPC_CLOCK_FRESHNESS_MS
|
|
20
|
+
|| after.wallMs < timedOutAt || after.wallMs - timedOutAt > RPC_CLOCK_FRESHNESS_MS) return null;
|
|
21
|
+
if (before.awakeMs < 0 || before.elapsedMs < 0) return null;
|
|
22
|
+
const elapsed = after.elapsedMs - before.elapsedMs;
|
|
23
|
+
const awake = after.awakeMs - before.awakeMs;
|
|
24
|
+
if (elapsed <= 0 || awake < 0 || Math.abs(elapsed - (after.wallMs - before.wallMs)) > CLOCK_SLOP_MS) return null;
|
|
25
|
+
const outsideRequest = Math.max(0, startedAt - before.wallMs) + after.wallMs - timedOutAt;
|
|
26
|
+
if (elapsed - awake - outsideRequest - CLOCK_SLOP_MS < MIN_SLEEP_MS) return null;
|
|
27
|
+
return awake + Math.max(0, before.wallMs - startedAt) + CLOCK_SLOP_MS;
|
|
28
|
+
}
|
|
7
29
|
|
|
8
30
|
/** What a desktop pane says when the app's background process did not answer its request in time. */
|
|
9
31
|
export const REQUEST_TIMED_OUT_MESSAGE = "Request timed out";
|
|
@@ -23,23 +45,26 @@ export class RpcTimeoutError extends Error {
|
|
|
23
45
|
readonly elapsedMs: number;
|
|
24
46
|
readonly limitMs: number;
|
|
25
47
|
readonly report: string;
|
|
48
|
+
readonly awakeUpperBoundMs: number | null;
|
|
26
49
|
|
|
27
50
|
constructor(
|
|
28
51
|
message: string,
|
|
29
|
-
{ elapsedMs, limitMs, report, cause
|
|
52
|
+
{ elapsedMs, limitMs, report, cause, awakeUpperBoundMs = null }: {
|
|
53
|
+
elapsedMs: number; limitMs: number; report: string; cause?: unknown; awakeUpperBoundMs?: number | null;
|
|
54
|
+
},
|
|
30
55
|
) {
|
|
31
56
|
super(message, cause === undefined ? undefined : { cause });
|
|
32
57
|
this.elapsedMs = elapsedMs;
|
|
33
58
|
this.limitMs = limitMs;
|
|
34
59
|
this.report = report;
|
|
60
|
+
this.awakeUpperBoundMs = awakeUpperBoundMs;
|
|
35
61
|
}
|
|
36
62
|
}
|
|
37
63
|
|
|
38
64
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* process already lost. Nothing the user did failed, so it is not a crash.
|
|
65
|
+
* Suppress only when sleep is measured and the request did not have its full
|
|
66
|
+
* awake budget. Timer lateness alone also happens during a real awake stall.
|
|
42
67
|
*/
|
|
43
68
|
export function isSleepRpcTimeout(error: unknown): boolean {
|
|
44
|
-
return error instanceof RpcTimeoutError && error.
|
|
69
|
+
return error instanceof RpcTimeoutError && error.awakeUpperBoundMs !== null && error.awakeUpperBoundMs < error.limitMs;
|
|
45
70
|
}
|
package/src/utils/sec.ts
CHANGED
|
@@ -112,7 +112,9 @@ export function isKnownNonUsEquityTicker(ticker: TickerRecord | null | undefined
|
|
|
112
112
|
* destination or no venue at all, which look the symbol up as a US ticker.
|
|
113
113
|
*/
|
|
114
114
|
export function nonUsSecListingVenue(ticker: string, exchange?: string): string | null {
|
|
115
|
-
const
|
|
115
|
+
const listing = parsePublicTickerKey(ticker);
|
|
116
|
+
const venue = listing.exchange ?? (canonicalExchange(exchange)
|
|
117
|
+
|| (/^[A-Z0-9][A-Z0-9-]{0,11}\.PS$/i.test(listing.symbol) ? "XPHS" : ""));
|
|
116
118
|
if (!venue || ROUTING_EXCHANGES.has(venue) || isUsEquityExchange(venue)) return null;
|
|
117
119
|
return venue;
|
|
118
120
|
}
|
|
@@ -363,7 +363,7 @@ export function withShareMultiples<T extends EpsInputs>(financials: T): T {
|
|
|
363
363
|
const fundamentals = financials.fundamentals;
|
|
364
364
|
if (!fundamentals) return financials;
|
|
365
365
|
const share = notTheShare(financials);
|
|
366
|
-
const reason = share ?? noRateForEps(financials) ?? epsAgainstIncome(financials);
|
|
366
|
+
const reason = share ?? (fundamentals.scopedEarnings === undefined ? noRateForEps(financials) ?? epsAgainstIncome(financials) : undefined);
|
|
367
367
|
// A multiple an earlier pass withdrew is one the block had.
|
|
368
368
|
const had = fundamentals.notMeaningful ?? {};
|
|
369
369
|
const has: Record<keyof Withdrawn, boolean> = {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const IO_COUNTERS = ["readOps", "writeOps", "otherOps", "readBytes", "writeBytes", "otherBytes"] as const;
|
|
2
|
+
|
|
3
|
+
type IoCounter = typeof IO_COUNTERS[number];
|
|
4
|
+
type CounterStatus = "unavailable" | "failed" | "reset";
|
|
5
|
+
type CounterReading<T> = T | null | undefined;
|
|
6
|
+
|
|
7
|
+
export interface ProcessActivityReading {
|
|
8
|
+
pageFaults: CounterReading<bigint>;
|
|
9
|
+
io: CounterReading<ReadonlyArray<bigint>>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ProcessActivityDelta {
|
|
13
|
+
pageFaults: number | CounterStatus;
|
|
14
|
+
io: Record<IoCounter, number> | CounterStatus;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function pageFaultDelta(before: CounterReading<bigint>, after: CounterReading<bigint>): number | CounterStatus {
|
|
18
|
+
if (before === null || after === null) return "failed";
|
|
19
|
+
if (before === undefined || after === undefined) return "unavailable";
|
|
20
|
+
return difference(before, after);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function difference(before: bigint, after: bigint): number | "reset" {
|
|
24
|
+
return after < before ? "reset" : Math.min(Number.MAX_SAFE_INTEGER, Number(after - before));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function processActivityDelta(
|
|
28
|
+
before: ProcessActivityReading | null | undefined,
|
|
29
|
+
after: ProcessActivityReading | null | undefined,
|
|
30
|
+
): ProcessActivityDelta | undefined {
|
|
31
|
+
if (!before && !after) return undefined;
|
|
32
|
+
const beforeIo = before === null ? null : before?.io;
|
|
33
|
+
const afterIo = after === null ? null : after?.io;
|
|
34
|
+
let io: ProcessActivityDelta["io"];
|
|
35
|
+
if (beforeIo === null || afterIo === null) io = "failed";
|
|
36
|
+
else if (!beforeIo || !afterIo) io = "unavailable";
|
|
37
|
+
else {
|
|
38
|
+
const counts = {} as Record<IoCounter, number>;
|
|
39
|
+
io = counts;
|
|
40
|
+
for (const [index, counter] of IO_COUNTERS.entries()) {
|
|
41
|
+
const count = difference(beforeIo[index]!, afterIo[index]!);
|
|
42
|
+
if (count === "reset") {
|
|
43
|
+
io = count;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
counts[counter] = count;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
pageFaults: pageFaultDelta(before === null ? null : before?.pageFaults, after === null ? null : after?.pageFaults),
|
|
51
|
+
io,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function formatProcessActivity(activity: ProcessActivityDelta): string[] {
|
|
56
|
+
const { io } = activity;
|
|
57
|
+
return [
|
|
58
|
+
`pageFaults=${activity.pageFaults}`,
|
|
59
|
+
...(typeof io === "string" ? [`io=${io}`] : IO_COUNTERS.map((counter) => `${counter}=${io[counter]}`)),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Compact, fixed-order counters for the crash reporter's bounded details field. */
|
|
64
|
+
export function formatProcessActivitySummary({ pageFaults, io }: ProcessActivityDelta): string[] {
|
|
65
|
+
const bucket = (value: number | CounterStatus): string => {
|
|
66
|
+
if (typeof value !== "number") return value === "unavailable" ? "na" : value === "failed" ? "err" : "reset";
|
|
67
|
+
return value < 100 ? String(value) : `e${Math.floor(Math.log10(value))}`;
|
|
68
|
+
};
|
|
69
|
+
return [`pf=${bucket(pageFaults)}`, `io=${typeof io === "string" ? bucket(io) : IO_COUNTERS.map((counter) => bucket(io[counter])).join("/")}`];
|
|
70
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { FinancialStatement, Fundamentals, Quote, StatementScope, TickerFinancials } from "../types/financials";
|
|
2
|
+
import { completeAvailability, financialAvailabilityTime, statementFieldAvailability, statementPeriodMonths } from "./financial-statements";
|
|
3
|
+
import { reportedEarnings } from "./trailing-eps";
|
|
4
|
+
|
|
5
|
+
export function listingOwnsRow(scope: StatementScope | undefined, row: FinancialStatement): boolean {
|
|
6
|
+
if (!scope) return !row.statementScope;
|
|
7
|
+
return scope.basis === "standalone" && !!scope.entity && row.statementScope?.basis === "standalone"
|
|
8
|
+
&& row.statementScope.entity === scope.entity && row.statementScope.registrant === scope.registrant;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function listingOwnsSeries(data: Pick<TickerFinancials, "statementScope" | "quarterlyStatements" | "annualStatements">): boolean {
|
|
12
|
+
const owned = (row: FinancialStatement) => listingOwnsRow(data.statementScope, row);
|
|
13
|
+
return (!data.statementScope || data.statementScope.basis === "standalone")
|
|
14
|
+
&& data.annualStatements.every(owned) && data.quarterlyStatements.every(owned);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ScopedEarnings = NonNullable<Fundamentals["scopedEarnings"]>;
|
|
18
|
+
|
|
19
|
+
const DAY_MS = 86_400_000;
|
|
20
|
+
|
|
21
|
+
function spansDays(start: string, end: string, min: number, max: number): boolean {
|
|
22
|
+
const days = (Date.parse(end) - Date.parse(start)) / DAY_MS + 1;
|
|
23
|
+
return days >= min && days <= max;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function completeQuarterWindow(rows: FinancialStatement[], end: string): boolean {
|
|
27
|
+
if (rows.length !== 4 || rows[3]!.date !== end) return false;
|
|
28
|
+
const firstStart = rows[0]!.dateEvidence?.startDate;
|
|
29
|
+
return (firstStart === undefined || spansDays(firstStart, end, 350, 380)) && rows.every((row, index) => {
|
|
30
|
+
if (row.shareBasis !== rows[0]!.shareBasis || (statementPeriodMonths(row) ?? 3) !== 3) return false;
|
|
31
|
+
const start = row.dateEvidence?.startDate;
|
|
32
|
+
if (start !== undefined && !spansDays(start, row.date, 77, 105)) return false;
|
|
33
|
+
if (index === 0) return true;
|
|
34
|
+
const previousEnd = Date.parse(rows[index - 1]!.date);
|
|
35
|
+
const days = (Date.parse(row.date) - previousEnd) / DAY_MS;
|
|
36
|
+
return days >= 77 && days <= 105 && (start === undefined || Date.parse(start) === previousEnd + DAY_MS);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function sumFiledDecimals(values: number[]): number {
|
|
41
|
+
if (values.length === 1) return values[0]!;
|
|
42
|
+
const terms = values.map(value => {
|
|
43
|
+
const [digits, exponent] = value.toExponential().split("e");
|
|
44
|
+
const places = digits!.split(".")[1]?.length ?? 0;
|
|
45
|
+
return { units: BigInt(digits!.replace(".", "")), power: Number(exponent) - places };
|
|
46
|
+
});
|
|
47
|
+
const power = Math.min(...terms.map(term => term.power));
|
|
48
|
+
const units = terms.reduce((sum, term) => sum + term.units * 10n ** BigInt(term.power - power), 0n);
|
|
49
|
+
return Number(`${units}e${power}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function dateScopedEarnings(data: Pick<TickerFinancials, "statementScope" | "statementReview" | "annualStatements" | "quarterlyStatements">,
|
|
53
|
+
earnings: Omit<ScopedEarnings, "epsAvailableAt"> | null | undefined): ScopedEarnings | null {
|
|
54
|
+
const reviewedThrough = data.statementReview?.reviewedThrough;
|
|
55
|
+
if (data.statementScope?.basis !== "standalone" || !earnings || !Number.isFinite(earnings.eps) || !/^[A-Z]{3}$/.test(earnings.currency)
|
|
56
|
+
|| !reviewedThrough || !listingOwnsSeries(data)) return null;
|
|
57
|
+
const { eps, currency, periodEnd, priced } = earnings;
|
|
58
|
+
const quarters = data.quarterlyStatements.filter(row => row.date <= periodEnd)
|
|
59
|
+
.sort((first, second) => first.date.localeCompare(second.date)).slice(-4);
|
|
60
|
+
const candidates = data.annualStatements.filter(row => row.date === periodEnd
|
|
61
|
+
&& (row.dateEvidence?.startDate === undefined || spansDays(row.dateEvidence.startDate, periodEnd, 350, 380))).map(row => [row]);
|
|
62
|
+
if (completeQuarterWindow(quarters, periodEnd)) candidates.push(quarters);
|
|
63
|
+
const admittedTotals = new Set([eps]);
|
|
64
|
+
const totals = candidates.flatMap(rows => {
|
|
65
|
+
if (!rows.every(row => row.currency === currency && reportedEarnings(row, "eps") !== null)) return [];
|
|
66
|
+
const values = rows.map(row => row.eps!);
|
|
67
|
+
const total = sumFiledDecimals(values);
|
|
68
|
+
if (!Number.isFinite(total)) return [];
|
|
69
|
+
const roundoff = values.length * values.reduce((bound, value) => bound + Number.EPSILON * Math.abs(value), 0);
|
|
70
|
+
if (values.reduce((sum, value) => sum + value, 0) === eps && Math.abs(total - eps) <= roundoff) admittedTotals.add(total);
|
|
71
|
+
return [{ rows, total }];
|
|
72
|
+
});
|
|
73
|
+
const matchingInputs = totals.filter(({ total }) => admittedTotals.has(total)).flatMap(({ rows }) => rows);
|
|
74
|
+
const epsAvailableAt = completeAvailability(matchingInputs.map(row => {
|
|
75
|
+
const available = statementFieldAvailability(row, "eps");
|
|
76
|
+
return available && Date.parse(available) >= Date.parse(row.date) ? available : undefined;
|
|
77
|
+
}));
|
|
78
|
+
return epsAvailableAt && Date.parse(epsAvailableAt) >= Date.parse(periodEnd) && financialAvailabilityTime(epsAvailableAt) <= financialAvailabilityTime(reviewedThrough)
|
|
79
|
+
? { eps, currency, periodEnd, epsAvailableAt, priced }
|
|
80
|
+
: null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function captureScopedEarnings(data: TickerFinancials): TickerFinancials {
|
|
84
|
+
if (!data.statementScope || !data.fundamentals) return data;
|
|
85
|
+
const { eps, epsCurrency, trailingPeriodEnd, trailingPE } = data.fundamentals;
|
|
86
|
+
const scopedEarnings = typeof eps === "number" && epsCurrency && trailingPeriodEnd ? dateScopedEarnings(data, { eps, currency: epsCurrency,
|
|
87
|
+
periodEnd: trailingPeriodEnd, priced: typeof trailingPE === "number" && Number.isFinite(trailingPE) && trailingPE > 0 }) : null;
|
|
88
|
+
return { ...data, fundamentals: priceScopedEarnings({ ...data.fundamentals, scopedEarnings },
|
|
89
|
+
data.quote?.price, data.quote, data.quote?.lastUpdated) };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function priceScopedEarnings(stats: Fundamentals, price: number | null | undefined, quote: Pick<Quote, "currency" | "stale"> | null | undefined,
|
|
93
|
+
priceTime: number | undefined, now = Date.now()): Fundamentals {
|
|
94
|
+
const { eps: _eps, epsCurrency: _currency, trailingPE: _pe, trailingPEConversion: _conversion,
|
|
95
|
+
trailingEpsSource: _source, trailingEpsPeriodEnd: _end, ...rest } = stats;
|
|
96
|
+
const earnings = stats.scopedEarnings;
|
|
97
|
+
if (!earnings?.epsAvailableAt) return rest;
|
|
98
|
+
const filed = financialAvailabilityTime(earnings.epsAvailableAt);
|
|
99
|
+
if (!(filed <= now)) return rest;
|
|
100
|
+
const eligible = earnings.priced && !stats.notMeaningful?.trailingPE && earnings.eps > 0 && quote && !quote.stale && quote.currency === earnings.currency
|
|
101
|
+
&& priceTime !== undefined && priceTime >= filed && priceTime <= now && typeof price === "number" && Number.isFinite(price) && price > 0;
|
|
102
|
+
return { ...rest, eps: earnings.eps, epsCurrency: earnings.currency, ...(eligible ? { trailingPE: price / earnings.eps } : {}) };
|
|
103
|
+
}
|
|
@@ -5,7 +5,7 @@ import { hasStatementGap } from "./statement-gaps";
|
|
|
5
5
|
const DAY_MS = 86_400_000;
|
|
6
6
|
|
|
7
7
|
/** A per-share amount the row reports: finite, not declared unavailable, and diluted EPS on a resolved share basis. */
|
|
8
|
-
function reportedEarnings(row: FinancialStatement, field: EarningsField): number | null {
|
|
8
|
+
export function reportedEarnings(row: FinancialStatement, field: EarningsField): number | null {
|
|
9
9
|
if (hasStatementGap(row, field) || (field === "eps" && row.epsBasis?.status === "unresolved")) return null;
|
|
10
10
|
const value = row[field];
|
|
11
11
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
@@ -148,6 +148,7 @@ const TIME_ZONE_LABELS: Readonly<Record<string, string | SeasonNames>> = {
|
|
|
148
148
|
"Asia/Kolkata": "IST",
|
|
149
149
|
"Asia/Hong_Kong": "HKT",
|
|
150
150
|
"Asia/Singapore": "SGT",
|
|
151
|
+
"Asia/Manila": "PHT",
|
|
151
152
|
"Asia/Tokyo": "JST",
|
|
152
153
|
"Asia/Seoul": "KST",
|
|
153
154
|
"Australia/Sydney": "AET",
|