@gloom-sh/terminal 0.20.14 → 0.20.17
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/api-client/data.ts +13 -3
- package/src/api-client/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +4 -2
- package/src/api-client/types/billing.ts +45 -0
- package/src/api-client/types/econ.ts +3 -0
- package/src/api-client/yearly-plan.ts +132 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +3 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
- package/src/app/since-last-visit/keys.ts +26 -0
- package/src/app/since-last-visit/model.ts +266 -0
- package/src/app/since-last-visit/strip.tsx +193 -0
- package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
- package/src/app/since-last-visit/visit-tracker.ts +191 -0
- package/src/app.tsx +15 -0
- package/src/cli/commands/fred-series.ts +3 -1
- package/src/cli/commands/market.ts +8 -4
- package/src/cli/commands/overview.ts +65 -13
- package/src/cli/commands/system.ts +29 -1
- package/src/cli/commands/ticker.ts +12 -5
- package/src/cli/csv-export.ts +73 -0
- package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
- package/src/cli/desktop-pane-shot-browser.ts +2 -1
- package/src/cli/desktop-pane-shot-view.ts +3 -7
- package/src/cli/desktop-pane-shot.ts +29 -30
- package/src/cli/help.ts +5 -2
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +41 -4
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +70 -3
- package/src/cli/pane-functions/index.ts +4 -4
- package/src/cli/pane-functions/resolver.ts +43 -0
- package/src/cli/pane-functions/screenshot-bridge.ts +4 -2
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +37 -8
- package/src/cli/result.ts +3 -6
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- package/src/components/chart/composite/composite-chart.tsx +3 -3
- package/src/components/chart/composite/legend.tsx +37 -7
- package/src/components/command-bar/commands/direct/index.ts +31 -8
- package/src/components/command-bar/commands/registry.ts +7 -0
- package/src/components/command-bar/routes/root/command-items.ts +8 -0
- package/src/components/command-bar/routes/root/results.ts +16 -0
- package/src/components/company-logo.tsx +10 -3
- package/src/components/data-table/sections.ts +6 -1
- package/src/components/layout/pane/title.ts +6 -2
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- package/src/components/ticker/badge/format.ts +12 -3
- package/src/components/ticker/badge/index.tsx +9 -3
- package/src/components/ticker/list-table-view.tsx +119 -17
- package/src/components/ui/data-table/display-columns.ts +19 -0
- package/src/components/ui/data-table/hooks.ts +2 -3
- package/src/components/ui/data-table/index.tsx +43 -9
- package/src/components/ui/data-table/types.ts +21 -0
- package/src/components/ui/data-table/visible-range.ts +11 -1
- package/src/core/state/app/layout-reducer.ts +3 -1
- package/src/core/state/app/layout.ts +2 -2
- package/src/data/config/layout.ts +14 -0
- package/src/data/config/store/normalize.ts +11 -1
- package/src/i18n/es.ts +38 -0
- package/src/i18n/ja.ts +38 -0
- package/src/i18n/ko.ts +38 -0
- package/src/i18n/zh-cn.ts +38 -0
- package/src/i18n/zh-tw.ts +38 -0
- package/src/layout/pane-follow.ts +141 -4
- package/src/layout/pane-layout-move.ts +10 -7
- package/src/layout/ticker-navigation.ts +13 -19
- package/src/layout/ticker-retarget.ts +3 -2
- package/src/market-data/market/index-level.ts +19 -0
- package/src/plugins/builtin/account-management/keyboard.ts +14 -0
- package/src/plugins/builtin/account-management/model.ts +2 -0
- package/src/plugins/builtin/account-management/pane.tsx +79 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
- package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
- package/src/plugins/builtin/awards/pane.tsx +12 -10
- package/src/plugins/builtin/changelog/index.tsx +6 -44
- package/src/plugins/builtin/changelog/versions.ts +17 -68
- package/src/plugins/builtin/chart-composer/pane.tsx +4 -1
- package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
- package/src/plugins/builtin/cpi/pane.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/series.ts +2 -2
- package/src/plugins/builtin/debt-maturities/model.ts +1 -1
- package/src/plugins/builtin/earnings/board-model.ts +12 -0
- package/src/plugins/builtin/earnings/board-table.ts +8 -5
- package/src/plugins/builtin/earnings/board.tsx +38 -18
- package/src/plugins/builtin/earnings/highlight.ts +47 -0
- package/src/plugins/builtin/earnings/history-table.ts +1 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- package/src/plugins/builtin/econ/calendar-model.ts +2 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +1 -256
- package/src/plugins/builtin/econ-statistics/cache.ts +1 -1
- package/src/plugins/builtin/econ-statistics/client.ts +11 -10
- package/src/plugins/builtin/econ-statistics/detail.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/headless.ts +42 -6
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +7 -2
- package/src/plugins/builtin/econ-statistics/stats.ts +2 -1
- package/src/plugins/builtin/econ-statistics/view.ts +9 -3
- package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
- package/src/plugins/builtin/exposure/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +6 -4
- package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +11 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
- package/src/plugins/builtin/market-valuation/view.ts +14 -0
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
- package/src/plugins/builtin/pe-band/pane.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +176 -17
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +90 -15
- package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
- package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
- package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
- package/src/plugins/builtin/shared/fred-catalog.ts +256 -0
- package/src/plugins/builtin/shared/headless-options.ts +1 -1
- package/src/plugins/builtin/shared/series-cache.ts +3 -0
- package/src/plugins/builtin/shared/series-detail-chart.tsx +3 -0
- package/src/plugins/builtin/short-interest/watch-pane.tsx +7 -7
- package/src/plugins/builtin/social-mentions/model.ts +2 -2
- package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +16 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +8 -4
- package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
- package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
- package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
- package/src/plugins/builtin/ticker-detail/headless.ts +254 -34
- package/src/plugins/builtin/ticker-detail/overview/model.ts +7 -3
- package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
- package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
- package/src/plugins/builtin/time-sales/headless.ts +4 -1
- package/src/plugins/builtin/time-sales/pane.tsx +2 -0
- package/src/plugins/builtin/time-sales/window.ts +12 -0
- package/src/plugins/builtin/treasury-auctions/client.ts +4 -0
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +2 -0
- package/src/plugins/builtin/treasury-daily/client.ts +23 -11
- package/src/portfolio/column-values.ts +20 -8
- package/src/portfolio/suffixed-listings.ts +3 -1
- package/src/portfolio/watchlist-groups.ts +212 -0
- package/src/react/ticker-source.ts +3 -1
- package/src/renderers/dom/styles.css +7 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -0
- package/src/sources/gloomberb-cloud/fred-publisher.ts +25 -0
- package/src/sources/gloomberb-cloud/fred-series.ts +1 -1
- package/src/state/app/bootstrap.ts +11 -0
- package/src/state/app/context/index.tsx +6 -0
- package/src/sync/collections-contributor.ts +5 -2
- package/src/sync/config-merge.ts +10 -2
- package/src/sync/sanitize.ts +28 -0
- package/src/telemetry/usage-counts.ts +17 -0
- package/src/time-series/base-series.ts +3 -0
- package/src/time-series/chart-seed.ts +1 -1
- package/src/time-series/financial-period-coverage.ts +4 -12
- package/src/time-series/ice-credit.ts +1 -0
- package/src/time-series/parsed-history-cache.ts +1 -1
- package/src/time-series/resolve.ts +1 -1
- package/src/time-series/types.ts +1 -0
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/headless.ts +9 -2
- package/src/types/plugin-context.ts +5 -0
- package/src/types/ticker.ts +14 -0
- package/src/ui/ascii-font.ts +1 -4
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/csv.ts +44 -5
- package/src/utils/futures-generic.ts +3 -0
- package/src/utils/throttled-fetch.ts +15 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FRED_CATALOG_SERIES } from "../../plugins/builtin/shared/fred-catalog";
|
|
2
|
+
import { ICE_CREDIT_PUBLISHER, ICE_CREDIT_SERIES } from "../../time-series/ice-credit";
|
|
3
|
+
import { seriesNotOnFred } from "./fred-series";
|
|
4
|
+
|
|
5
|
+
const publishers = new Map([
|
|
6
|
+
...FRED_CATALOG_SERIES.map((series): [string, string] => [series.id.slice(5), series.publisher!]),
|
|
7
|
+
...ICE_CREDIT_SERIES.map((series): [string, string] => [series.seriesId, ICE_CREDIT_PUBLISHER]),
|
|
8
|
+
]);
|
|
9
|
+
const additional: Readonly<Record<string, string>> = {
|
|
10
|
+
GDPNOW: "Federal Reserve Bank of Atlanta",
|
|
11
|
+
NFCI: "Federal Reserve Bank of Chicago",
|
|
12
|
+
STLFSI4: "Federal Reserve Bank of St. Louis",
|
|
13
|
+
MEDCPIM158SFRBCLE: "Federal Reserve Bank of Cleveland",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function fredPublisher(seriesId: string, source?: string | null): string | null {
|
|
17
|
+
const normalized = seriesId.trim().toUpperCase();
|
|
18
|
+
return publishers.get(normalized) ?? additional[normalized]
|
|
19
|
+
?? (/^DGS\d|^DFII\d/.test(normalized) ? "Federal Reserve Board" : source?.trim() || null);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function fredCitation(seriesId: string, source?: string | null): string {
|
|
23
|
+
const publisher = fredPublisher(seriesId, source);
|
|
24
|
+
return seriesNotOnFred(seriesId) ? publisher ?? "Gloom Cloud" : publisher ? `${publisher} via FRED` : "Publisher not stated via FRED";
|
|
25
|
+
}
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
const CACHE_KIND = "fred-series";
|
|
10
10
|
const CACHE_SOURCE = "gloomberb-cloud";
|
|
11
11
|
// Refresh persisted metadata that predates FRED's source coverage dates.
|
|
12
|
-
const CACHE_SCHEMA_VERSION =
|
|
12
|
+
const CACHE_SCHEMA_VERSION = 3;
|
|
13
13
|
const CACHE_POLICY = {
|
|
14
14
|
staleMs: 24 * 60 * 60 * 1000,
|
|
15
15
|
expireMs: 30 * 24 * 60 * 60 * 1000,
|
|
@@ -15,6 +15,7 @@ import { getDockedPaneIds } from "../../layout/pane-manager";
|
|
|
15
15
|
import { debugLog } from "../../utils/debug-log";
|
|
16
16
|
import { measurePerf, measurePerfAsync } from "../../utils/perf-marks";
|
|
17
17
|
import { mergeSavedSuffixedListings } from "../../portfolio/suffixed-listings";
|
|
18
|
+
import { withoutStaleWatchlistGroupSymbols } from "../../portfolio/watchlist-groups";
|
|
18
19
|
import { saveConfigImmediately } from "../config-save-scheduler";
|
|
19
20
|
|
|
20
21
|
export const DEFAULT_WATCHLIST_TICKERS: Array<Pick<TickerMetadata, "ticker" | "exchange" | "currency" | "name">> = [
|
|
@@ -276,6 +277,16 @@ export async function initializeAppState({
|
|
|
276
277
|
startupLog.warn("suffixed listing merge failed", { message: error instanceof Error ? error.message : String(error) });
|
|
277
278
|
}
|
|
278
279
|
|
|
280
|
+
// A ticker that left a list some other way than its own remove leaves the list's groups too.
|
|
281
|
+
const ungrouped = withoutStaleWatchlistGroupSymbols(config, tickers);
|
|
282
|
+
if (ungrouped !== config) {
|
|
283
|
+
config = ungrouped;
|
|
284
|
+
dispatch({ type: "SET_CONFIG", config });
|
|
285
|
+
await saveConfigImmediately(config).catch((error: unknown) => {
|
|
286
|
+
startupLog.warn("stale watchlist group symbols not saved", { message: error instanceof Error ? error.message : String(error) });
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
279
290
|
// Seed default watchlist tickers on first run
|
|
280
291
|
if (tickers.length === 0) {
|
|
281
292
|
const defaultWatchlistId = config.watchlists[0]?.id ?? "watchlist";
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "react";
|
|
15
15
|
import type { AppSessionStorePort } from "../../../core/app-service-ports";
|
|
16
16
|
import { ThemeProvider } from "../../../theme/theme-context";
|
|
17
|
+
import { setCsvDecimal } from "../../../utils/csv";
|
|
17
18
|
import { syncFontScale } from "../../../theme/font-scale";
|
|
18
19
|
import {
|
|
19
20
|
findPaneInstance,
|
|
@@ -698,6 +699,11 @@ export function AppProvider({
|
|
|
698
699
|
}
|
|
699
700
|
}, [state.config.fontSize]);
|
|
700
701
|
|
|
702
|
+
// Every CSV the app exports (a table's Export CSV, the quote board's) writes the decimal mark the reader set.
|
|
703
|
+
useLayoutEffect(() => {
|
|
704
|
+
setCsvDecimal(state.config.csvDecimal);
|
|
705
|
+
}, [state.config.csvDecimal]);
|
|
706
|
+
|
|
701
707
|
useLayoutEffect(() => {
|
|
702
708
|
stateRef.current = state;
|
|
703
709
|
for (const listener of listenersRef.current) {
|
|
@@ -8,6 +8,7 @@ import type { SyncContributor } from "./types";
|
|
|
8
8
|
import { isRecord, recordOrNull } from "../utils/guards";
|
|
9
9
|
import { withoutMissingWatchlists } from "../portfolio/mutations";
|
|
10
10
|
import { mergeSuffixedListings, moveTargetWeights } from "../portfolio/suffixed-listings";
|
|
11
|
+
import { moveWatchlistGroupSymbols } from "../portfolio/watchlist-groups";
|
|
11
12
|
import { knownBrokerHoldings } from "../brokers/broker-portfolio-sync";
|
|
12
13
|
import {
|
|
13
14
|
localOnlyScope,
|
|
@@ -23,7 +24,7 @@ import {
|
|
|
23
24
|
} from "./analytics-payload";
|
|
24
25
|
import { idEntries } from "./broker-instances";
|
|
25
26
|
import { CORE_CONFIG_CONTRIBUTOR_ID, log } from "./config-contributor";
|
|
26
|
-
import { sanitizePortfolio, sanitizeWatchlist } from "./sanitize";
|
|
27
|
+
import { sanitizePortfolio, sanitizeWatchlist, WATCHLISTS_CARRY_GROUPS } from "./sanitize";
|
|
27
28
|
import {
|
|
28
29
|
lastSyncedTickersById,
|
|
29
30
|
latestBrokerPortfolioSyncs,
|
|
@@ -55,6 +56,8 @@ export function collectCoreCollectionsPayload(
|
|
|
55
56
|
exchangeRates: { USD: 1 },
|
|
56
57
|
portfolios: config.portfolios.map(sanitizePortfolio),
|
|
57
58
|
watchlists: config.watchlists.map(sanitizeWatchlist),
|
|
59
|
+
// The lists carry their groups, as the config payload's do: a reader can tell a list without them from an older build's.
|
|
60
|
+
[WATCHLISTS_CARRY_GROUPS]: true,
|
|
58
61
|
analyticsByPortfolio: collectAnalyticsByPortfolio(config, tickers, financials, exchangeRates, brokerAccounts),
|
|
59
62
|
accountsByPortfolio: collectAccountsByPortfolio(config, brokerAccounts),
|
|
60
63
|
tickers: records,
|
|
@@ -168,6 +171,6 @@ function mergePulledSuffixedListings(
|
|
|
168
171
|
else changed.push(row);
|
|
169
172
|
}
|
|
170
173
|
for (const kept of merged.keptCustom) log.info("sync.suffixed-listing.custom-kept", kept);
|
|
171
|
-
const next = moveTargetWeights(config, merged.moved);
|
|
174
|
+
const next = moveWatchlistGroupSymbols(moveTargetWeights(config, merged.moved), merged.moved);
|
|
172
175
|
return { config: next === config ? null : next };
|
|
173
176
|
}
|
package/src/sync/config-merge.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizeStoredBaseCurrency } from "../utils/base-currency";
|
|
2
2
|
import { stableStringify } from "../utils/hash";
|
|
3
3
|
import type { AppConfig, BrokerInstanceConfig } from "../types/config";
|
|
4
|
-
import type { Portfolio } from "../types/ticker";
|
|
4
|
+
import type { Portfolio, Watchlist } from "../types/ticker";
|
|
5
5
|
import {
|
|
6
6
|
addLegacyBuiltinDisabledPluginAliases,
|
|
7
7
|
addLegacyBuiltinPluginOwnerAliases,
|
|
@@ -33,7 +33,9 @@ import {
|
|
|
33
33
|
sanitizePortfolio,
|
|
34
34
|
sanitizeUnknown,
|
|
35
35
|
sanitizeWatchlist,
|
|
36
|
+
WATCHLISTS_CARRY_GROUPS,
|
|
36
37
|
withLocalPluginSecrets,
|
|
38
|
+
withLocalWatchlistGroups,
|
|
37
39
|
} from "./sanitize";
|
|
38
40
|
|
|
39
41
|
export function collectCoreConfigPayload(config: AppConfig) {
|
|
@@ -43,6 +45,7 @@ export function collectCoreConfigPayload(config: AppConfig) {
|
|
|
43
45
|
refreshIntervalMinutes: config.refreshIntervalMinutes,
|
|
44
46
|
portfolios: config.portfolios.map(sanitizePortfolio),
|
|
45
47
|
watchlists: config.watchlists.map(sanitizeWatchlist),
|
|
48
|
+
[WATCHLISTS_CARRY_GROUPS]: true,
|
|
46
49
|
...collectLayoutPayload(config),
|
|
47
50
|
brokerInstances: config.brokerInstances.map(sanitizeBrokerInstance),
|
|
48
51
|
// This build merges profiles one by one before it pushes, so a profile
|
|
@@ -169,7 +172,12 @@ export function mergeConfigPayload(
|
|
|
169
172
|
? mergeLocalBrokerPortfolioIdentity(config.portfolios, syncedPortfolios as Portfolio[], next.brokerInstances)
|
|
170
173
|
: syncedPortfolios as AppConfig["portfolios"];
|
|
171
174
|
}
|
|
172
|
-
|
|
175
|
+
// An older build pushes its lists without their groups: they keep the groups they have here.
|
|
176
|
+
if ("watchlists" in payload && canApply("watchlists")) {
|
|
177
|
+
next.watchlists = Array.isArray(payload.watchlists)
|
|
178
|
+
? withLocalWatchlistGroups(payload.watchlists, config.watchlists, payload[WATCHLISTS_CARRY_GROUPS] === true)
|
|
179
|
+
: payload.watchlists as Watchlist[];
|
|
180
|
+
}
|
|
173
181
|
assign("disabledSources");
|
|
174
182
|
assign("theme");
|
|
175
183
|
assign("chartPreferences");
|
package/src/sync/sanitize.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AppConfig, BrokerInstanceConfig } from "../types/config";
|
|
2
2
|
import type { Portfolio, TickerPosition, Watchlist } from "../types/ticker";
|
|
3
3
|
import { isRecord } from "../utils/guards";
|
|
4
|
+
import { normalizeWatchlistGroups } from "../portfolio/watchlist-groups";
|
|
4
5
|
|
|
5
6
|
const SENSITIVE_KEY_PATTERN = /(token|secret|password|credential|private|api[_-]?key|access[_-]?key|refresh[_-]?key|session|cookie|dataDir|path|directory|localPath)/i;
|
|
6
7
|
|
|
@@ -77,11 +78,38 @@ export function sanitizePortfolio(portfolio: Portfolio): Portfolio {
|
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Set on every payload this build pushes with watchlists: its lists carry their
|
|
83
|
+
* groups, so one without `groups` has none. An older build's lists never carry
|
|
84
|
+
* them, and taken as they came they would erase the groups here and then
|
|
85
|
+
* everywhere this device pushes to.
|
|
86
|
+
*/
|
|
87
|
+
export const WATCHLISTS_CARRY_GROUPS = "watchlistsCarryGroups";
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Pulled watchlists, each list an older build pushed (no `WATCHLISTS_CARRY_GROUPS`)
|
|
91
|
+
* keeping the groups it has here; a build that sends groups is taken as it
|
|
92
|
+
* came, so a group removed there is removed here.
|
|
93
|
+
*/
|
|
94
|
+
export function withLocalWatchlistGroups(pulled: unknown[], local: readonly Watchlist[], carriesGroups: boolean): Watchlist[] {
|
|
95
|
+
if (carriesGroups) return pulled as Watchlist[];
|
|
96
|
+
return pulled.map((entry) => {
|
|
97
|
+
if (!isRecord(entry) || entry.groups !== undefined) return entry as unknown as Watchlist;
|
|
98
|
+
const groups = local.find((watchlist) => watchlist.id === entry.id)?.groups;
|
|
99
|
+
return (groups ? { ...entry, groups } : entry) as unknown as Watchlist;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
80
103
|
export function sanitizeWatchlist(watchlist: Watchlist): Watchlist {
|
|
104
|
+
// The user's own sections: a pulled list without them would erase them on this device. A list
|
|
105
|
+
// without groups goes as before. They are an array, never keyed by a name or symbol, which
|
|
106
|
+
// `sanitizeUnknown` would drop for reading like a secret (a Private group, the PATH ticker).
|
|
107
|
+
const groups = normalizeWatchlistGroups(watchlist.groups);
|
|
81
108
|
return {
|
|
82
109
|
id: watchlist.id,
|
|
83
110
|
name: watchlist.name,
|
|
84
111
|
description: watchlist.description,
|
|
112
|
+
...(groups ? { groups } : {}),
|
|
85
113
|
};
|
|
86
114
|
}
|
|
87
115
|
|
|
@@ -241,6 +241,23 @@ export function recordRestoredFunctions(fns: readonly UsageFunction[]): void {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Counts a function that put itself on screen at launch, with nothing opened
|
|
246
|
+
* by the user (the since-last-visit strip): in `restored`, never `opened`, and
|
|
247
|
+
* no open listener hears of it. Unlike `recordRestoredFunctions` it can be
|
|
248
|
+
* called on its own, once the function knows it showed. Never throws.
|
|
249
|
+
*/
|
|
250
|
+
export function recordFunctionShown(fn: UsageFunction): void {
|
|
251
|
+
try {
|
|
252
|
+
if (automationDepth > 0) return;
|
|
253
|
+
if (host && !host.isEnabled()) return;
|
|
254
|
+
count(fn, "restored");
|
|
255
|
+
scheduleFlush();
|
|
256
|
+
} catch (error) {
|
|
257
|
+
logFailure("telemetry-usage-counts", "Could not record a function shown at launch")(error);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
244
261
|
/** The install as its usage counts name it: the random install id, the surface and the OS. */
|
|
245
262
|
export interface UsageInstall {
|
|
246
263
|
installId: string;
|
|
@@ -52,6 +52,7 @@ export function unloadableSeries(spec: ChartSeriesSpec, index: number, warning:
|
|
|
52
52
|
return {
|
|
53
53
|
id: spec.id,
|
|
54
54
|
label: spec.label?.trim() || label,
|
|
55
|
+
legendContext: spec.label?.trim() ? undefined : field?.seriesLabel ?? field?.shortLabel,
|
|
55
56
|
color: spec.color ?? SERIES_COLORS[index % SERIES_COLORS.length]!,
|
|
56
57
|
unit: field?.unit ?? "",
|
|
57
58
|
unitGroup: field?.unitGroup ?? "unknown",
|
|
@@ -242,6 +243,8 @@ export function baseSecuritySeries(
|
|
|
242
243
|
id: spec.id,
|
|
243
244
|
label: spec.label?.trim() || (generic ? futuresGenericCaption(generic)
|
|
244
245
|
: `${symbol} ${field.id === "market.volume" && volumeBasis ? INDEX_MEMBERS_VOLUME_LABEL : field.seriesLabel ?? field.shortLabel}`),
|
|
246
|
+
legendContext: spec.label?.trim() || generic ? undefined
|
|
247
|
+
: field.id === "market.volume" && volumeBasis ? INDEX_MEMBERS_VOLUME_LABEL : field.seriesLabel ?? field.shortLabel,
|
|
245
248
|
color: spec.color ?? SERIES_COLORS[index % SERIES_COLORS.length]!,
|
|
246
249
|
unit,
|
|
247
250
|
unitGroup: currencyUnitGroup,
|
|
@@ -85,7 +85,7 @@ export function seedChartResolutionResult(
|
|
|
85
85
|
const facts = readSeedListingFacts(seriesSpec.source.instrument);
|
|
86
86
|
const { symbol, exchange } = seriesSpec.source.instrument;
|
|
87
87
|
const bars = builtBarSize ? aggregatePriceBars(history, builtBarSize, { symbol, exchange }) : history;
|
|
88
|
-
const base = baseSecuritySeries(seriesSpec, emptyFinancials(bars), index, resolution, facts?.quoteMetadata, facts?.contractUnit);
|
|
88
|
+
const base = baseSecuritySeries(seriesSpec, emptyFinancials(bars), index, resolution, facts?.quoteMetadata ?? undefined, facts?.contractUnit);
|
|
89
89
|
const resolved = base && builtBarSize ? withBuiltBarSize(base, builtBarSize) : base;
|
|
90
90
|
if (!resolved?.points.length) return;
|
|
91
91
|
if (hidden) {
|
|
@@ -15,19 +15,11 @@ export function limitSeriesObservations(spec: ChartSpec, series: ResolvedSeries)
|
|
|
15
15
|
if (!isFinancialSeries(definition)) {
|
|
16
16
|
return { ...series, points: series.points.slice(-spec.viewport.maxPoints) };
|
|
17
17
|
}
|
|
18
|
+
// The latest N periods, a missing one among them, so `--periods 5` reads the last five fiscal years and never reaches
|
|
19
|
+
// back past a gap for older ones; the gap stays a point so a chart cannot draw through it, and the coverage counts
|
|
20
|
+
// how many of the N have a value.
|
|
18
21
|
const points = series.points.filter((point) => point.periodLabel !== "Current");
|
|
19
|
-
|
|
20
|
-
let start = points.length;
|
|
21
|
-
for (let index = points.length - 1; index >= 0; index--) {
|
|
22
|
-
if (!isUsableFinancialObservation(points[index]!)) continue;
|
|
23
|
-
start = index;
|
|
24
|
-
if (--remaining <= 0) break;
|
|
25
|
-
}
|
|
26
|
-
// Count usable observations, but retain missing periods within the selected
|
|
27
|
-
// history and at its end so charts cannot draw through absent financial data.
|
|
28
|
-
// If coverage is short, retain leading gaps too: they explain which requested
|
|
29
|
-
// periods failed, including the case where every observation is unavailable.
|
|
30
|
-
return { ...series, points: points.slice(remaining > 0 ? 0 : start) };
|
|
22
|
+
return { ...series, points: points.slice(-spec.viewport.maxPoints) };
|
|
31
23
|
}
|
|
32
24
|
|
|
33
25
|
export interface FinancialPeriodCoverage {
|
|
@@ -22,6 +22,7 @@ export interface IceCreditSeries {
|
|
|
22
22
|
|
|
23
23
|
/** What every surface that shows an ICE series says about how far back FRED carries it. */
|
|
24
24
|
export const ICE_HISTORY_LIMIT_NOTICE = "History limited to 3 years by the publisher.";
|
|
25
|
+
export const ICE_CREDIT_PUBLISHER = "ICE Data Indices";
|
|
25
26
|
|
|
26
27
|
const HIGH_YIELD = ["high yield", "junk"];
|
|
27
28
|
const EMERGING = ["EM", "emerging markets"];
|
|
@@ -33,7 +33,7 @@ export function parsedPriceHistoryKey(
|
|
|
33
33
|
* moment later moves the plot and redraws every label.
|
|
34
34
|
*/
|
|
35
35
|
interface SeedListingFacts {
|
|
36
|
-
quoteMetadata?: QuoteMetadata;
|
|
36
|
+
quoteMetadata?: QuoteMetadata | null;
|
|
37
37
|
/** What a future's price counts ("USD / gallon"), so a seed states the unit the settled chart will. */
|
|
38
38
|
contractUnit?: string;
|
|
39
39
|
resolutionSupport?: ChartResolutionSupport[];
|
|
@@ -991,7 +991,7 @@ async function resolveChartSpecPass(
|
|
|
991
991
|
if (marketField) {
|
|
992
992
|
// Same precedence as baseSecuritySeries: the quote's own facts first.
|
|
993
993
|
const listingFacts = mergeQuoteMetadata(merged.quote ? quoteMetadataFromQuote(merged.quote) : undefined, quoteMetadata);
|
|
994
|
-
|
|
994
|
+
rememberSeedListingFacts(source.instrument, { quoteMetadata: listingFacts ?? null });
|
|
995
995
|
if (contractUnit) rememberSeedListingFacts(source.instrument, { contractUnit });
|
|
996
996
|
}
|
|
997
997
|
if (history) {
|
package/src/time-series/types.ts
CHANGED
|
@@ -217,6 +217,7 @@ export interface ResolvedSeries {
|
|
|
217
217
|
* "8058 Close · M..." and "8031 Close · M...".
|
|
218
218
|
*/
|
|
219
219
|
compactLabel?: string;
|
|
220
|
+
legendContext?: string;
|
|
220
221
|
color: string;
|
|
221
222
|
unit: string;
|
|
222
223
|
/** Unit of rawValue, retained when presentation transforms change unit. */
|
|
@@ -33,6 +33,7 @@ import { withFormulaNextMonths } from "./formula-months";
|
|
|
33
33
|
import {
|
|
34
34
|
parsedPriceHistoryKey,
|
|
35
35
|
readParsedHistoryResult,
|
|
36
|
+
readSeedListingFacts,
|
|
36
37
|
} from "./parsed-history-cache";
|
|
37
38
|
|
|
38
39
|
export interface UseChartResolutionResult extends ChartResolutionResult {
|
|
@@ -223,7 +224,11 @@ export function useChartResolution(
|
|
|
223
224
|
const now = sources.now ?? new Date();
|
|
224
225
|
// The first paint prices a formula's legs in one month as the settled chart does, from the next months it read.
|
|
225
226
|
const seedSpec = withFormulaNextMonths(spec);
|
|
226
|
-
|
|
227
|
+
const history = collectSeedHistory(seedSpec, now, options);
|
|
228
|
+
if (seedSpec.series.some(({ source }) => source.kind === "security"
|
|
229
|
+
&& history.has(chartQuoteOverrideKeyForSource(source))
|
|
230
|
+
&& readSeedListingFacts(source.instrument)?.quoteMetadata === undefined)) return null;
|
|
231
|
+
return seedChartResolutionResult(seedSpec, history, now, options);
|
|
227
232
|
};
|
|
228
233
|
const [state, setState] = useState(() => ({
|
|
229
234
|
key: specKey,
|
package/src/types/config.ts
CHANGED
|
@@ -103,6 +103,25 @@ export interface PaneInstanceConfig {
|
|
|
103
103
|
locked?: boolean;
|
|
104
104
|
/** Set by Move to New Layout and cleared by Move Back; never published. */
|
|
105
105
|
movedFrom?: PaneMovedFrom;
|
|
106
|
+
/** Set when a follower was pinned on its ticker; read only while it follows nothing. Never published. */
|
|
107
|
+
unlinkedFrom?: PaneUnlinkedFrom;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The link a follower left when it was pinned on the ticker it showed. Its title says so
|
|
112
|
+
* (`AAPL ⧉ Unlinked`) until it is linked again.
|
|
113
|
+
*/
|
|
114
|
+
export interface PaneUnlinkedFrom {
|
|
115
|
+
/** The pane it followed. */
|
|
116
|
+
instanceId: string;
|
|
117
|
+
/** That pane's kind (`portfolio-list`), so a research pane can follow a new one of it. */
|
|
118
|
+
paneId?: string;
|
|
119
|
+
/**
|
|
120
|
+
* The app cut the link, not the user: the source closed or left the layout, or another
|
|
121
|
+
* research pane took it. A research pane pinned this way follows again once its source, or
|
|
122
|
+
* one of that kind, is in the layout with no research pane of its own (`relinkPinnedResearchPanes`).
|
|
123
|
+
*/
|
|
124
|
+
auto?: true;
|
|
106
125
|
}
|
|
107
126
|
|
|
108
127
|
interface DockPaneNode {
|
|
@@ -380,6 +399,13 @@ export interface AppConfig {
|
|
|
380
399
|
* are never shifted by it.
|
|
381
400
|
*/
|
|
382
401
|
timezone?: string;
|
|
402
|
+
/**
|
|
403
|
+
* The decimal mark CSV exports write numbers with, the CLI's and the app's:
|
|
404
|
+
* `comma` writes `17,2` with cells split by `;`, as a spreadsheet in a
|
|
405
|
+
* decimal-comma locale reads them. Absent is the dot. Text and JSON keep
|
|
406
|
+
* the dot. Kept on this machine only.
|
|
407
|
+
*/
|
|
408
|
+
csvDecimal?: "comma" | "dot";
|
|
383
409
|
/**
|
|
384
410
|
* Presentation mode: the panes fill the window, without the header or the
|
|
385
411
|
* status bar, for a screen that is shown rather than worked at. Absent is off.
|
|
@@ -390,6 +416,12 @@ export interface AppConfig {
|
|
|
390
416
|
* benchmark of this machine's time zone. Kept on this machine only.
|
|
391
417
|
*/
|
|
392
418
|
headerMarket?: HeaderMarketChoice;
|
|
419
|
+
/**
|
|
420
|
+
* The strip above the layout that says what moved in the user's portfolios
|
|
421
|
+
* and watchlists since their last visit. `false` turns it off; absent means
|
|
422
|
+
* on. Kept on this machine only.
|
|
423
|
+
*/
|
|
424
|
+
sinceLastVisit?: boolean;
|
|
393
425
|
}
|
|
394
426
|
|
|
395
427
|
/** A benchmark the header offers, by its id (`hang-seng`), or any listing the user searched for. */
|
package/src/types/headless.ts
CHANGED
|
@@ -240,6 +240,11 @@ export interface HeadlessPaneColumn {
|
|
|
240
240
|
* screen; JSON keeps the row's figure whole.
|
|
241
241
|
*/
|
|
242
242
|
exportAsShown?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* A column the export gained after its others were set (RV's `Fwd P/E period`): CSV and NDJSON write it last,
|
|
245
|
+
* after the fixed columns and `retrieved_at`, so no column an earlier export had moves.
|
|
246
|
+
*/
|
|
247
|
+
exportLast?: boolean;
|
|
243
248
|
/**
|
|
244
249
|
* The text report prints the value on its own lines under the row instead
|
|
245
250
|
* of in a column, for a footnote that belongs to that row; an empty value
|
|
@@ -638,6 +643,7 @@ export type HeadlessBundleSection =
|
|
|
638
643
|
* lists them all.
|
|
639
644
|
*/
|
|
640
645
|
rowSourceKey?: string;
|
|
646
|
+
appendedColumns?: number;
|
|
641
647
|
/** The symbol every row is of, where the report's own is not (a section per name): each exported row names it in `symbol_or_series`. */
|
|
642
648
|
symbol?: string;
|
|
643
649
|
/** When every row was observed (an ISO date or instant), where it is not the report's newest: each exported row names it in `as_of`. */
|
|
@@ -656,6 +662,7 @@ export type HeadlessBundleSection =
|
|
|
656
662
|
| {
|
|
657
663
|
title: string;
|
|
658
664
|
entries: HeadlessPaneEntry[];
|
|
665
|
+
source?: string;
|
|
659
666
|
/**
|
|
660
667
|
* The lines the text report prints in place of `entries`, when the pane
|
|
661
668
|
* says in one line what the exported records keep apart (a range as
|
|
@@ -678,9 +685,9 @@ export type HeadlessBundleSection =
|
|
|
678
685
|
rows?: never;
|
|
679
686
|
textColumns?: never;
|
|
680
687
|
textRows?: never;
|
|
681
|
-
unit?:
|
|
688
|
+
unit?: string;
|
|
682
689
|
rowUnitKey?: never;
|
|
683
|
-
interval?:
|
|
690
|
+
interval?: string;
|
|
684
691
|
rowIntervalKey?: never;
|
|
685
692
|
rowSourceKey?: never;
|
|
686
693
|
locked?: never;
|
|
@@ -53,6 +53,11 @@ export interface PinTickerOptions {
|
|
|
53
53
|
tabId?: string;
|
|
54
54
|
/** Merge this state into the resolved research pane when selecting `tabId`. */
|
|
55
55
|
tabState?: Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* A pinned pane of `paneType` that shows the ticker instead of a new one, when no pane shows
|
|
58
|
+
* it yet: Enter on a list row with no research pane of its own.
|
|
59
|
+
*/
|
|
60
|
+
reusePaneId?: string;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
export interface GloomPluginContext {
|
package/src/types/ticker.ts
CHANGED
|
@@ -117,10 +117,24 @@ export interface PortfolioCash {
|
|
|
117
117
|
currency: string;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/** A named section of a watchlist's tickers (`Watchlist.groups`). */
|
|
121
|
+
export interface WatchlistGroup {
|
|
122
|
+
name: string;
|
|
123
|
+
/** The tickers' keys (`TickerMetadata.ticker`); a ticker is in one group of a list at most. */
|
|
124
|
+
symbols: string[];
|
|
125
|
+
}
|
|
126
|
+
|
|
120
127
|
export interface Watchlist {
|
|
121
128
|
id: string;
|
|
122
129
|
name: string;
|
|
123
130
|
description?: string;
|
|
124
131
|
/** Set on watchlists shared with a team; the server holds the items. */
|
|
125
132
|
teamId?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Sections the user put the list's tickers in, in the order they show; a
|
|
135
|
+
* ticker in none shows under Ungrouped. Kept on the list, not the ticker, so
|
|
136
|
+
* a ticker on two lists can sit in a different group on each. Absent on a
|
|
137
|
+
* list without groups, which shows and syncs as it did before groups.
|
|
138
|
+
*/
|
|
139
|
+
groups?: WatchlistGroup[];
|
|
126
140
|
}
|
package/src/ui/ascii-font.ts
CHANGED
|
@@ -72,10 +72,7 @@ const GLOOMBERB_WORDMARK = [
|
|
|
72
72
|
/** The first five letters of the wordmark above. */
|
|
73
73
|
const GLOOM_WORDMARK = GLOOMBERB_WORDMARK.map((line) => line.slice(0, 15));
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* The drawn wordmarks, by the text they spell. The app is Gloom; chart
|
|
77
|
-
* screenshots keep the Gloomberb watermark.
|
|
78
|
-
*/
|
|
75
|
+
/** The drawn wordmarks, by the text they spell. */
|
|
79
76
|
const WORDMARKS = new Map<string, string[]>([
|
|
80
77
|
["gloom", GLOOM_WORDMARK],
|
|
81
78
|
["gloomberb", GLOOMBERB_WORDMARK],
|
|
@@ -53,8 +53,8 @@ export function abortable<T>(promise: Promise<T>, signal: AbortSignal | undefine
|
|
|
53
53
|
if (!signal) return promise;
|
|
54
54
|
return new Promise<T>((resolve, reject) => {
|
|
55
55
|
const abort = () => reject(abortError(message));
|
|
56
|
-
if (signal.aborted)
|
|
57
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
56
|
+
if (signal.aborted) abort();
|
|
57
|
+
else signal.addEventListener("abort", abort, { once: true });
|
|
58
58
|
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
59
59
|
});
|
|
60
60
|
}
|
package/src/utils/csv.ts
CHANGED
|
@@ -23,22 +23,61 @@ function normalizeCsvCell(value: unknown): string {
|
|
|
23
23
|
return String(value);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The decimal mark a CSV writes its numbers with. `comma` is what a
|
|
28
|
+
* spreadsheet set to a decimal-comma locale (German, French, Brazilian) reads
|
|
29
|
+
* as a number: `17,2`, never the date `17.2` becomes. Its cells are then
|
|
30
|
+
* separated by `;`, as those spreadsheets read them, so a decimal comma never
|
|
31
|
+
* splits a cell. Text, dates and JSON are never changed.
|
|
32
|
+
*/
|
|
33
|
+
export type CsvDecimal = "dot" | "comma";
|
|
34
|
+
|
|
35
|
+
let defaultDecimal: CsvDecimal = "dot";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The decimal mark every CSV is written with unless the caller names one:
|
|
39
|
+
* the `csvDecimal` setting, or `--decimal` for one command. Null or absent is
|
|
40
|
+
* the dot.
|
|
41
|
+
*/
|
|
42
|
+
export function setCsvDecimal(decimal: CsvDecimal | null | undefined): void {
|
|
43
|
+
defaultDecimal = decimal === "comma" ? "comma" : "dot";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The decimal mark CSVs are written with now (setCsvDecimal). */
|
|
47
|
+
export function csvDecimal(): CsvDecimal {
|
|
48
|
+
return defaultDecimal;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The cell separator that goes with a decimal mark: `;` beside a decimal comma, `,` beside a dot. */
|
|
52
|
+
function csvSeparator(decimal: CsvDecimal = defaultDecimal): string {
|
|
53
|
+
return decimal === "comma" ? ";" : ",";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** `1,234.5` and `-0.07%` as a decimal-comma spreadsheet reads them: `1234,5` and `-0,07%`. Other text stays. */
|
|
57
|
+
function withDecimalComma(text: string): string {
|
|
58
|
+
if (!isNumericCsvText(text)) return text;
|
|
59
|
+
return text.trim().replace(/,/g, "").replace(".", ",");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function escapeCsvCell(value: unknown, excelCompatible: boolean, decimal: CsvDecimal): string {
|
|
27
63
|
const normalized = normalizeCsvCell(value);
|
|
28
64
|
// A signed number is data, not a formula: "-2.10" must stay a number.
|
|
29
|
-
const
|
|
65
|
+
const guarded = excelCompatible && FORMULA_START.test(normalized) && !isNumericCsvText(normalized)
|
|
30
66
|
? `'${normalized}`
|
|
31
67
|
: normalized;
|
|
32
|
-
|
|
68
|
+
const text = decimal === "comma" && (typeof value === "number" || typeof value === "string") ? withDecimalComma(guarded) : guarded;
|
|
69
|
+
const separator = csvSeparator(decimal);
|
|
70
|
+
if (!text.includes(separator) && !/["\n\r]/.test(text)) return text;
|
|
33
71
|
return `"${text.replace(/"/g, '""')}"`;
|
|
34
72
|
}
|
|
35
73
|
|
|
36
74
|
export function serializeCsv(
|
|
37
75
|
rows: readonly (readonly unknown[])[],
|
|
38
|
-
options: { excelCompatible?: boolean } = {},
|
|
76
|
+
options: { excelCompatible?: boolean; decimal?: CsvDecimal } = {},
|
|
39
77
|
): string {
|
|
40
78
|
const excelCompatible = options.excelCompatible === true;
|
|
41
|
-
const
|
|
79
|
+
const decimal = options.decimal ?? defaultDecimal;
|
|
80
|
+
const csv = rows.map((row) => row.map((cell) => escapeCsvCell(cell, excelCompatible, decimal)).join(csvSeparator(decimal))).join("\n");
|
|
42
81
|
return excelCompatible ? `${EXCEL_CSV_BOM}${csv}` : csv;
|
|
43
82
|
}
|
|
44
83
|
|
|
@@ -240,6 +240,9 @@ export function futuresContractMonth(code: string): { root: string; month: numbe
|
|
|
240
240
|
export function venueOfDatedContract(code: string): string | null {
|
|
241
241
|
const match = /^([A-Z0-9]{1,4}?)([FGHJKMNQUVXZ])(\d{2})$/.exec(code.trim().toUpperCase());
|
|
242
242
|
if (!match) return null;
|
|
243
|
+
const year = 2000 + Number(match[3]);
|
|
244
|
+
const currentYear = new Date().getUTCFullYear();
|
|
245
|
+
if (year < currentYear - 1 || year > currentYear + 10) return null;
|
|
243
246
|
const root = ALIASES[match[1]!] ?? match[1]!;
|
|
244
247
|
const venue = ROOT_VENUES[root];
|
|
245
248
|
return venue ? `${root}${match[2]}${match[3]}.${venue}` : null;
|
|
@@ -31,6 +31,14 @@ export interface ThrottledFetchOptions {
|
|
|
31
31
|
* rate-limited feed cannot hold its callers for that long. Default: 10000
|
|
32
32
|
*/
|
|
33
33
|
maxRetryWaitMs?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Whether an attempt that ran out its `timeoutMs` is tried again (default
|
|
36
|
+
* true). Off for a host that stalls rather than blips: one that has not
|
|
37
|
+
* answered in the timeout does not on the retry either, and the caller's
|
|
38
|
+
* fallback (another source, a saved copy) should not wait out every attempt.
|
|
39
|
+
* Network errors, 429s and 5xx answers are retried either way.
|
|
40
|
+
*/
|
|
41
|
+
retryTimeouts?: boolean;
|
|
34
42
|
/** Default headers applied to every request */
|
|
35
43
|
defaultHeaders?: Record<string, string>;
|
|
36
44
|
/** Share concurrent GET requests to the same URL. Default: true */
|
|
@@ -58,6 +66,7 @@ export function createThrottledFetch(
|
|
|
58
66
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
59
67
|
const backoffBaseMs = options.backoffBaseMs ?? BACKOFF_BASE_MS;
|
|
60
68
|
const maxRetryWaitMs = options.maxRetryWaitMs ?? DEFAULT_MAX_RETRY_WAIT_MS;
|
|
69
|
+
const retryTimeouts = options.retryTimeouts ?? true;
|
|
61
70
|
const defaultHeaders = options.defaultHeaders ?? {};
|
|
62
71
|
const dedupeGetRequests = options.dedupeGetRequests ?? true;
|
|
63
72
|
const fetchTransport =
|
|
@@ -129,6 +138,11 @@ export function createThrottledFetch(
|
|
|
129
138
|
);
|
|
130
139
|
}
|
|
131
140
|
|
|
141
|
+
/** The attempt's own timeout (the caller's abort has been ruled out by then). */
|
|
142
|
+
function isTimeoutError(error: unknown): boolean {
|
|
143
|
+
return error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
|
|
144
|
+
}
|
|
145
|
+
|
|
132
146
|
function abortReason(signal: AbortSignal): unknown {
|
|
133
147
|
return signal.reason ?? abortError("The operation was aborted.");
|
|
134
148
|
}
|
|
@@ -188,7 +202,7 @@ export function createThrottledFetch(
|
|
|
188
202
|
resp = await fetchTransport(url, mergedInit);
|
|
189
203
|
} catch (error) {
|
|
190
204
|
throwIfAborted(callerSignal);
|
|
191
|
-
if (retriesLeft > 0 && isRetryableFetchError(error)) {
|
|
205
|
+
if (retriesLeft > 0 && isRetryableFetchError(error) && (retryTimeouts || !isTimeoutError(error))) {
|
|
192
206
|
await wait(getBackoffMs(retriesLeft), callerSignal);
|
|
193
207
|
return executeRequest(url, init, retriesLeft - 1);
|
|
194
208
|
}
|