gloomberb 0.19.3 → 0.19.4
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 +2 -2
- package/src/api-client/errors.ts +8 -0
- package/src/api-client/index.ts +18 -0
- package/src/api-client/request.ts +295 -42
- package/src/api-client/socket.ts +95 -0
- package/src/app/keybindings/actions.ts +1 -1
- package/src/app/pane-runtime/index.tsx +1 -1
- package/src/app/pane-runtime/ticker-inspector-runtime.ts +1 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +1 -1
- package/src/app/pane-runtime/ticker-open-target.ts +12 -2
- package/src/cli/desktop-pane-shot-api-policy.ts +10 -2
- package/src/cli/desktop-pane-shot.ts +2 -1
- package/src/components/command-bar/action-runtime.ts +2 -0
- package/src/components/command-bar/commands/direct/runtime.ts +3 -3
- package/src/components/command-bar/helpers.ts +2 -0
- package/src/components/command-bar/list/model.ts +9 -0
- package/src/components/command-bar/pane-actions.ts +46 -35
- package/src/components/command-bar/pane-templates/workflow.ts +6 -0
- package/src/components/command-bar/panel/index.tsx +30 -3
- package/src/components/command-bar/panel/types.ts +7 -0
- package/src/components/command-bar/routes/root/results.ts +4 -4
- package/src/components/command-bar/routes/root/selection.ts +3 -2
- package/src/components/command-bar/routes/ticker-search/actions.ts +21 -16
- package/src/components/command-bar/routing/launch-request.ts +3 -2
- package/src/components/command-bar/routing/list-state.ts +4 -1
- package/src/components/command-bar/surface/index.tsx +15 -1
- package/src/components/layout/floating-pane.tsx +10 -0
- package/src/components/layout/pane/frame.tsx +6 -0
- package/src/components/layout/pane/header.tsx +244 -42
- package/src/components/layout/pane/index.tsx +20 -2
- package/src/components/layout/shell/active-drag.ts +128 -27
- package/src/components/layout/shell/drag/index.ts +99 -96
- package/src/components/layout/shell/drag/live.ts +3 -17
- package/src/components/layout/shell/drag/magnets.ts +198 -0
- package/src/components/layout/shell/drag/overlays.tsx +77 -75
- package/src/components/layout/shell/drag/runtime.ts +12 -7
- package/src/components/layout/shell/index.tsx +66 -32
- package/src/components/layout/shell/native/pointer-runtime.ts +7 -2
- package/src/components/layout/shell/native/surfaces.ts +1 -9
- package/src/components/layout/shell/native/window-state.ts +21 -25
- package/src/components/layout/shell/pane/layers.tsx +153 -24
- package/src/components/layout/shell/shortcuts.ts +4 -1
- package/src/components/layout/shell/terminal-pointer-runtime.ts +24 -1
- package/src/components/layout/shell/window-mode/overlays.tsx +14 -6
- package/src/components/layout/status-bar.tsx +75 -6
- package/src/core/app-runtime.ts +4 -1
- package/src/core/connection-health.ts +76 -1
- package/src/core/state/app/command-bar-launch.ts +12 -0
- package/src/core/state/app/layout.ts +4 -3
- package/src/core/state/app/types.ts +4 -1
- package/src/data/config/layout.ts +2 -2
- package/src/data/config/store/fold-panes.ts +6 -1
- package/src/i18n/es.ts +8 -1
- package/src/i18n/ja.ts +8 -1
- package/src/i18n/ko.ts +8 -1
- package/src/i18n/zh-cn.ts +8 -1
- package/src/i18n/zh-tw.ts +8 -1
- package/src/layout/pane-follow.ts +3 -2
- package/src/layout/pane-layout-move.ts +2 -1
- package/src/layout/pane-manager/dock-stack.ts +38 -0
- package/src/layout/pane-manager/dock-tree.ts +76 -15
- package/src/layout/pane-manager/docking.ts +48 -6
- package/src/layout/pane-manager/floating-actions.ts +12 -3
- package/src/layout/pane-manager/floating-placement.ts +189 -0
- package/src/layout/pane-manager/floating.ts +23 -4
- package/src/layout/pane-manager/gridlock.ts +16 -4
- package/src/layout/pane-manager/hidden-panes.ts +30 -1
- package/src/layout/pane-manager/index.ts +2 -0
- package/src/layout/pane-manager/layout-state.ts +17 -0
- package/src/layout/pane-manager/types.ts +4 -1
- package/src/layout/ticker-retarget.ts +88 -0
- package/src/layout-marketplace/cloud.ts +9 -1
- package/src/market-data/connection-follow.ts +68 -0
- package/src/market-data/coordinator/entries.ts +15 -3
- package/src/market-data/coordinator/financials.ts +20 -7
- package/src/market-data/coordinator/index.ts +217 -4
- package/src/market-data/coordinator/quotes.ts +10 -0
- package/src/market-data/hooks.tsx +31 -0
- package/src/news/aggregator.ts +12 -1
- package/src/plugins/builtin/buildout/company/pane.tsx +2 -1
- package/src/plugins/builtin/buildout/model/index.ts +6 -0
- package/src/plugins/builtin/buildout/pane/index.tsx +2 -1
- package/src/plugins/builtin/chart-composer/index.tsx +13 -0
- package/src/plugins/builtin/chat/controller/index.ts +10 -3
- package/src/plugins/builtin/chat/controller/session-runtime.ts +9 -2
- package/src/plugins/builtin/chat/status-widget.tsx +3 -1
- package/src/plugins/builtin/help/index.tsx +1 -1
- package/src/plugins/builtin/sectors/client.ts +18 -8
- package/src/plugins/builtin/sectors/index.tsx +19 -5
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +25 -2
- package/src/react/async-resource.ts +12 -0
- package/src/remote/controller.ts +3 -1
- package/src/renderers/browser/app-services.ts +8 -1
- package/src/renderers/browser/cloud-transport.ts +6 -1
- package/src/renderers/cloudflare/worker.ts +24 -2
- package/src/renderers/dom/styles.css +32 -0
- package/src/shares/portable-layout.ts +99 -2
- package/src/sources/provider-router/index.ts +2 -2
- package/src/sources/provider-router/sources.ts +26 -1
- package/src/sync/core-contributors.ts +18 -4
- package/src/time-series/resolve.ts +12 -0
- package/src/types/config.ts +17 -1
- package/src/types/plugin.ts +6 -0
|
@@ -205,7 +205,7 @@ function HelpPane({ focused, width, height }: PaneProps) {
|
|
|
205
205
|
? [entry("cmd-open", commandBarBadges, "Open command mode for actions, pane commands, and typed prefixes.")]
|
|
206
206
|
: []),
|
|
207
207
|
...(tickerSearchBadges.length > 0
|
|
208
|
-
? [entry("cmd-ticker-search", tickerSearchBadges, "
|
|
208
|
+
? [entry("cmd-ticker-search", tickerSearchBadges, "Ticker search: Enter changes the focused pane's ticker and the panes linked to it, as a click on the ticker in a pane's title does on the desktop and the web. Shift+Enter opens a new pane. From a pane with no ticker it opens DES.")]
|
|
209
209
|
: []),
|
|
210
210
|
entry("cmd-des", ["DES", "<ticker>"], "Open security details for a specific ticker."),
|
|
211
211
|
entry("cmd-help-card", ["HELP", "<function>"], "Open a function's help card: what it shows, its keys, how fresh its data is. HELP HELP reaches support."),
|
|
@@ -20,9 +20,17 @@ export interface SectorRowOutcome {
|
|
|
20
20
|
row: Partial<SectorRow> | null;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The year of daily bars each fund's returns are read from, by fund. A load
|
|
25
|
+
* given one asks only for the funds it lacks and adds what it reads, so a
|
|
26
|
+
* refresh of the prices alone sends no history request.
|
|
27
|
+
*/
|
|
28
|
+
export type SectorHistories = Map<string, PricePoint[]>;
|
|
29
|
+
|
|
23
30
|
export async function loadSectorRows(
|
|
24
31
|
sectors: readonly SectorDef[],
|
|
25
32
|
provider: DataProvider,
|
|
33
|
+
options: { histories?: SectorHistories } = {},
|
|
26
34
|
): Promise<SectorRowOutcome[]> {
|
|
27
35
|
const quotes = new Map<string, Quote | null>();
|
|
28
36
|
if (provider.getQuotesBatch) {
|
|
@@ -41,10 +49,12 @@ export async function loadSectorRows(
|
|
|
41
49
|
}
|
|
42
50
|
}));
|
|
43
51
|
|
|
44
|
-
const histories = new Map(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
]
|
|
52
|
+
const histories: SectorHistories = options.histories ?? new Map();
|
|
53
|
+
// Funds whose history this load reads; a stored one is not asked again, nor for its boundary buffer.
|
|
54
|
+
const read = new Set(sectors.filter((sector) => !histories.get(sector.etf)?.length).map((sector) => sector.etf));
|
|
55
|
+
await Promise.all([...read].map(async (etf) => {
|
|
56
|
+
histories.set(etf, await provider.getPriceHistory(etf, "", "1Y").catch(logFailure("sectors", "Sector price history failed", [])));
|
|
57
|
+
}));
|
|
48
58
|
// The quotes as sent carry any pre-market or after-hours print, for its own column.
|
|
49
59
|
const sentQuotes = new Map(quotes);
|
|
50
60
|
// Pre-market quotes whose last completed session nothing confirms.
|
|
@@ -62,7 +72,7 @@ export async function loadSectorRows(
|
|
|
62
72
|
const datedQuotes = [...quoteDates].filter((entry): entry is [string, string] => entry[1] != null);
|
|
63
73
|
const confirmedQuotes = datedQuotes.filter(([symbol]) => !unconfirmed.has(symbol));
|
|
64
74
|
const asOfDate = [...(confirmedQuotes.length > 0 ? confirmedQuotes : datedQuotes).map(([, date]) => date),
|
|
65
|
-
...
|
|
75
|
+
...sectors.map((sector) => latestHistoryDate(histories.get(sector.etf) ?? []))]
|
|
66
76
|
.filter((date): date is string => date != null).sort().at(-1) ?? null;
|
|
67
77
|
|
|
68
78
|
const outcomes = await Promise.all(sectors.map(async (sector) => {
|
|
@@ -90,7 +100,7 @@ export async function loadSectorRows(
|
|
|
90
100
|
const quoteIssue = priceIssue ?? (changePercent == null ? "1D change unavailable" : null);
|
|
91
101
|
// A strict trailing request may begin after the prior year's weekend or
|
|
92
102
|
// holiday. Ask for a small boundary buffer when the provider supports it.
|
|
93
|
-
if (asOfDate && computeTrailingReturn(history, "1Y", price, asOfDate)?.value == null
|
|
103
|
+
if (read.has(sector.etf) && asOfDate && computeTrailingReturn(history, "1Y", price, asOfDate)?.value == null
|
|
94
104
|
&& provider.getDetailedPriceHistory) {
|
|
95
105
|
const start = new Date(`${sectorReturnTargetDate(asOfDate, "1Y")}T00:00:00Z`);
|
|
96
106
|
start.setUTCDate(start.getUTCDate() - SECTOR_RETURN_BASE_MAX_GAP_DAYS);
|
|
@@ -133,8 +143,8 @@ export async function loadSectorRows(
|
|
|
133
143
|
// These ETFs share a market calendar. A missing observation for one fund
|
|
134
144
|
// must not silently give it an earlier baseline than its peers. Use every
|
|
135
145
|
// reported baseline, independently of whether that fund has an ending price.
|
|
136
|
-
const sharedStartDate = (range: "1M" | "1Y") =>
|
|
137
|
-
.map((
|
|
146
|
+
const sharedStartDate = (range: "1M" | "1Y") => sectors
|
|
147
|
+
.map((sector) => sectorReturnStartDate(histories.get(sector.etf) ?? [], range, asOfDate))
|
|
138
148
|
.filter((date): date is string => !!date).sort().at(-1);
|
|
139
149
|
const monthStartDate = sharedStartDate("1M");
|
|
140
150
|
const yearStartDate = sharedStartDate("1Y");
|
|
@@ -4,7 +4,7 @@ import { DataTableView, usePaneFooter, usePaneNoticeFooter, usePaneTabs, type Da
|
|
|
4
4
|
import { handleRefreshKey, loadingErrorFooterInfo } from "../../../components/data-table/table-pane";
|
|
5
5
|
import type { PaneProps } from "../../../types/plugin";
|
|
6
6
|
import type { PluginModule } from "../plugin-module";
|
|
7
|
-
import { usePaneInstance, usePaneSettingValue } from "../../../state/app/context";
|
|
7
|
+
import { useAppSelector, usePaneInstance, usePaneSettingValue } from "../../../state/app/context";
|
|
8
8
|
import { colors, priceColor } from "../../../theme/colors";
|
|
9
9
|
import { formatCurrency, formatPercentRaw } from "../../../utils/format";
|
|
10
10
|
import { useAssetData, useDebouncedPluginPaneState, usePluginPaneState, usePluginTickerActions } from "../../runtime";
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
type SectorRowsByCollection,
|
|
47
47
|
type SectorSortPreference,
|
|
48
48
|
} from "./sector-model";
|
|
49
|
-
import { loadSectorRows } from "./client";
|
|
49
|
+
import { loadSectorRows, type SectorHistories } from "./client";
|
|
50
50
|
import { sectorsHeadless } from "./headless";
|
|
51
51
|
import { membersCache, themesCache } from "../themes/client";
|
|
52
52
|
import { themesHeadless } from "../themes/headless";
|
|
@@ -60,7 +60,9 @@ const NO_SAVED_ETFS: string[] = [];
|
|
|
60
60
|
* Prices, the day move and the returns stream; the year of history behind the
|
|
61
61
|
* returns only reloads on the app's research cadence. While the feed is not
|
|
62
62
|
* carrying a fund, the last load failed, or a fund printed in a session the
|
|
63
|
-
* board has not rolled to, the
|
|
63
|
+
* board has not rolled to, the quotes reload quietly at this pace, read
|
|
64
|
+
* against the history already loaded: outside regular hours that is all an
|
|
65
|
+
* open board asks for.
|
|
64
66
|
*/
|
|
65
67
|
const SECTOR_FALLBACK_REFRESH_MS = 60_000;
|
|
66
68
|
|
|
@@ -150,6 +152,9 @@ function EtfBoard({ collectionId, focused, width, height, rootBefore }: EtfBoard
|
|
|
150
152
|
);
|
|
151
153
|
|
|
152
154
|
const fetchGenRef = useRef(0);
|
|
155
|
+
const researchIntervalMinutes = useAppSelector((state) => state.config.refreshIntervalMinutes);
|
|
156
|
+
/** The history the last full load read, for the funds it was read for, which quote refreshes reuse. */
|
|
157
|
+
const historiesRef = useRef<{ funds: string; loadedAt: number; histories: SectorHistories } | null>(null);
|
|
153
158
|
const [loadError, setLoadError] = useState<string | null>(null);
|
|
154
159
|
|
|
155
160
|
const rows = useMemo(
|
|
@@ -223,6 +228,14 @@ function EtfBoard({ collectionId, focused, width, height, rootBefore }: EtfBoard
|
|
|
223
228
|
const gen = fetchGenRef.current;
|
|
224
229
|
const collectionId = activeCollection.id;
|
|
225
230
|
const sectorDefs = activeItems;
|
|
231
|
+
// A background refresh reads its quotes against the history already loaded
|
|
232
|
+
// for these funds, until that history is one research interval old.
|
|
233
|
+
const funds = sectorDefs.map((item) => item.etf).join(",");
|
|
234
|
+
const stored = historiesRef.current;
|
|
235
|
+
// The app's own research cadence (app-runtime): a minute at least, and an unreadable setting reloads.
|
|
236
|
+
const researchMs = Math.max(1, researchIntervalMinutes) * 60_000;
|
|
237
|
+
const reuse = background && stored?.funds === funds && Date.now() - stored.loadedAt < researchMs;
|
|
238
|
+
const histories: SectorHistories = reuse ? stored!.histories : new Map();
|
|
226
239
|
const updateRows = (updater: (rows: SectorRow[]) => SectorRow[]) => {
|
|
227
240
|
setRowsByCollection((prev) => updateRowsForCollection(prev, collectionId, sectorDefs, updater));
|
|
228
241
|
};
|
|
@@ -238,8 +251,9 @@ function EtfBoard({ collectionId, focused, width, height, rootBefore }: EtfBoard
|
|
|
238
251
|
|
|
239
252
|
if (!background) updateRows((rows) => rows.map((row) => ({ ...row, loading: true })));
|
|
240
253
|
|
|
241
|
-
loadSectorRows(sectorDefs, dataProvider).then((outcomes) => {
|
|
254
|
+
loadSectorRows(sectorDefs, dataProvider, { histories }).then((outcomes) => {
|
|
242
255
|
if (fetchGenRef.current !== gen) return;
|
|
256
|
+
if (!reuse) historiesRef.current = { funds, loadedAt: Date.now(), histories };
|
|
243
257
|
const loadedByEtf = new Map(outcomes.map((outcome) => [outcome.etf, outcome.row]));
|
|
244
258
|
updateRows((rows) => applySectorReload(rows, loadedByEtf, background));
|
|
245
259
|
|
|
@@ -253,7 +267,7 @@ function EtfBoard({ collectionId, focused, width, height, rootBefore }: EtfBoard
|
|
|
253
267
|
setLoadError("Sector data unavailable");
|
|
254
268
|
if (!background) updateRows(clearLoading);
|
|
255
269
|
});
|
|
256
|
-
}, [activeCollection.id, activeItems, dataProvider, setLastRefreshByCollection, setRowsByCollection]);
|
|
270
|
+
}, [activeCollection.id, activeItems, dataProvider, researchIntervalMinutes, setLastRefreshByCollection, setRowsByCollection]);
|
|
257
271
|
const fetchAll = useCallback(() => load(false), [load]);
|
|
258
272
|
const refreshInBackground = useCallback(() => load(true), [load]);
|
|
259
273
|
|
|
@@ -15,12 +15,14 @@ import { OverviewTab } from "../overview-tab";
|
|
|
15
15
|
import { useOpenResearchTab } from "../research-tab-navigation";
|
|
16
16
|
import type { OverviewFunctionLink } from "./types";
|
|
17
17
|
import { useOverviewDividend } from "./dividend";
|
|
18
|
+
import { useTickerSnapshotState } from "../../../../market-data/hooks";
|
|
18
19
|
|
|
19
20
|
/** Registered by the chart composer, in the same plugin as this tab. */
|
|
20
21
|
const CHART_TAB_ID = "chart";
|
|
21
22
|
|
|
22
23
|
export function OverviewResearchTab({ width, height, focused }: TickerResearchTabProps) {
|
|
23
|
-
const { ticker, financials } = usePaneTicker();
|
|
24
|
+
const { symbol, ticker, financials } = usePaneTicker();
|
|
25
|
+
const snapshot = useTickerSnapshotState(symbol, ticker);
|
|
24
26
|
const dispatch = useAppDispatch();
|
|
25
27
|
const paneId = useOptionalPaneInstanceId();
|
|
26
28
|
const paneInstance = usePaneInstance();
|
|
@@ -48,6 +50,7 @@ export function OverviewResearchTab({ width, height, focused }: TickerResearchTa
|
|
|
48
50
|
onOpenChart={paneId && !lockedToOneTab ? openChart : undefined}
|
|
49
51
|
onOpenFunction={openFunction}
|
|
50
52
|
dividend={dividend}
|
|
53
|
+
snapshot={snapshot}
|
|
51
54
|
perpetuals={ticker ? (contentWidth: number) => {
|
|
52
55
|
const instrumentType = financials?.quote?.instrumentType ?? ticker.metadata.assetCategory;
|
|
53
56
|
// A contract's own DES shows its funding and premium; a stock or a coin lists its markets across venues.
|
|
@@ -6,13 +6,13 @@ import { mayBeUsEquityOrFundTicker } from "../../../utils/sec";
|
|
|
6
6
|
import { ResearchTradeActions, researchTradeMatches, useResearchTrading } from "../shared/research-trading";
|
|
7
7
|
import { instrumentFromTicker } from "../../../market-data/request-types";
|
|
8
8
|
import { useMemo, type ReactNode } from "react";
|
|
9
|
-
import { EmptyState, ExternalLinkText, PaneLinkMenu, SectionHeading, usePaneNoticeFooter } from "../../../components";
|
|
9
|
+
import { EmptyState, ExternalLinkText, PaneLinkMenu, PaneStatusBody, SectionHeading, unavailableText, usePaneNoticeFooter } from "../../../components";
|
|
10
10
|
import { CompositeChart, pricePointsToResolvedSeries } from "../../../components/chart/composite";
|
|
11
11
|
import { CompanyLogo, resolveCompanyLogoSrc } from "../../../components/company-logo";
|
|
12
12
|
import { bodyLineInk, FigureText, figureLineInk, useFigureCells } from "../../../components/ui/figure";
|
|
13
13
|
import { PriceReturnStrip } from "../../../components/price-performance";
|
|
14
14
|
import { t } from "../../../i18n";
|
|
15
|
-
import { useFxRateObservations } from "../../../market-data/hooks";
|
|
15
|
+
import { useFxRateObservations, type TickerSnapshotState } from "../../../market-data/hooks";
|
|
16
16
|
import { formatMarketPriceWithCurrency, formatSignedMarketPrice, liveQuoteFormatOptions } from "../../../market-data/market/format";
|
|
17
17
|
import { priceSeriesUnit } from "../../../market-data/market/index-level";
|
|
18
18
|
import {
|
|
@@ -103,10 +103,33 @@ interface OverviewTabProps {
|
|
|
103
103
|
onOpenFunction?: (link: OverviewFunctionLink) => void;
|
|
104
104
|
/** The history the dividend yield reads (useOverviewDividend): a trailing one's cash, a forward one's lapse; without it the yield stands. */
|
|
105
105
|
dividend?: OverviewDividendState;
|
|
106
|
+
/** Where the ticker's snapshot load stands (useTickerSnapshotState), for the state shown before anything of it is in. */
|
|
107
|
+
snapshot?: TickerSnapshotState;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Nothing of the ticker is in yet: no quote, profile, figures or history. */
|
|
111
|
+
function hasNothingToShow(financials: TickerFinancials | null): boolean {
|
|
112
|
+
if (!financials) return true;
|
|
113
|
+
return !financials.quote && !financials.profile && (financials.priceHistory?.length ?? 0) === 0
|
|
114
|
+
&& Object.keys(financials.fundamentals ?? {}).length === 0
|
|
115
|
+
&& financials.annualStatements.length === 0 && financials.quarterlyStatements.length === 0;
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
export function OverviewTab(props: OverviewTabProps) {
|
|
109
119
|
if (!props.ticker) return <EmptyState title={t("No ticker selected.")} />;
|
|
120
|
+
// Before anything of the ticker is in, the tab says it is loading, or why it could not, rather than standing empty.
|
|
121
|
+
const { snapshot } = props;
|
|
122
|
+
if (snapshot && (snapshot.loading || snapshot.error) && hasNothingToShow(props.financials)) {
|
|
123
|
+
return (
|
|
124
|
+
<PaneStatusBody
|
|
125
|
+
loading={snapshot.loading}
|
|
126
|
+
error={snapshot.loading ? null : snapshot.error}
|
|
127
|
+
subject="overview"
|
|
128
|
+
errorTitle={unavailableText(t("Overview"))}
|
|
129
|
+
retry={{ onRetry: snapshot.retry }}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
110
133
|
return <ResolvedOverviewTab {...props} ticker={props.ticker} />;
|
|
111
134
|
}
|
|
112
135
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { connectionHealth, GLOOM_CLOUD_HTTP_CONNECTION_ID } from "../core/connection-health";
|
|
2
3
|
|
|
3
4
|
interface ResourceState<T> {
|
|
4
5
|
data: T | null;
|
|
@@ -74,6 +75,17 @@ export function useAsyncResource<T>(
|
|
|
74
75
|
const { data, loading, error, updatedAt } = state.owner === loader ? state
|
|
75
76
|
: keepPreviousData && loader ? { ...state, loading: true, error: null }
|
|
76
77
|
: { data: null, loading: !!loader, error: null, updatedAt: null };
|
|
78
|
+
|
|
79
|
+
// A load that failed is asked again once the data service answers after an
|
|
80
|
+
// outage, so a pane recovers by itself instead of keeping the failure.
|
|
81
|
+
const failedRef = useRef(false);
|
|
82
|
+
failedRef.current = !!loader && error !== null && !loading;
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!loader) return;
|
|
85
|
+
return connectionHealth.subscribeRecovery((sourceId) => {
|
|
86
|
+
if (sourceId === GLOOM_CLOUD_HTTP_CONNECTION_ID && failedRef.current) void load();
|
|
87
|
+
});
|
|
88
|
+
}, [load, loader]);
|
|
77
89
|
const status = error !== null ? "error" : data !== null ? "loaded" : loading ? "loading" : "idle";
|
|
78
90
|
return { data, loading, error, updatedAt, status, load, reload };
|
|
79
91
|
}
|
package/src/remote/controller.ts
CHANGED
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
import { createRemoteResources } from "./resources";
|
|
65
65
|
import { dismissTopmostDialog, isDialogOpen as isAnyDialogOpen } from "../ui/dialog-stack";
|
|
66
66
|
import { asRecord } from "../utils/guards";
|
|
67
|
+
import { SECURITY_DESCRIPTION_SEARCH } from "../core/state/app/command-bar-launch";
|
|
67
68
|
import { runAutomated } from "../telemetry/usage-counts";
|
|
68
69
|
import {
|
|
69
70
|
applyWatchlistChange,
|
|
@@ -277,7 +278,8 @@ export function createAppRemoteController({
|
|
|
277
278
|
await afterMutation();
|
|
278
279
|
}
|
|
279
280
|
if (mode === "ticker") {
|
|
280
|
-
|
|
281
|
+
// DES's search: a remote pick opens the ticker, it does not change the focused pane's.
|
|
282
|
+
dispatch({ type: "SET_COMMAND_BAR", open: true, launch: { kind: "ticker-search", query, payload: SECURITY_DESCRIPTION_SEARCH } });
|
|
281
283
|
await afterMutation();
|
|
282
284
|
return mutationSummary(getState(), { commandBar: getResource("app://command-bar") });
|
|
283
285
|
}
|
|
@@ -7,6 +7,7 @@ import { AssetDataRouter } from "../../sources/provider-router";
|
|
|
7
7
|
import { JsonPersistence } from "../../data/json-persistence";
|
|
8
8
|
import { isBrokerAccountSnapshotKey } from "../../brokers/account-cache";
|
|
9
9
|
import { JsonTickerRepository } from "../../data/json-ticker-repository";
|
|
10
|
+
import { registerGloomCloudConnectionSources } from "../../core/connection-health";
|
|
10
11
|
|
|
11
12
|
export function createBrowserAppServices({ config, plugins, externalPlugins }: AppServicesFactoryOptions) {
|
|
12
13
|
const cloudProvider = createGloomberbCloudProvider();
|
|
@@ -27,7 +28,13 @@ export function createBrowserAppServices({ config, plugins, externalPlugins }: A
|
|
|
27
28
|
priority: 0,
|
|
28
29
|
provider: { fetchNews: (query) => cloudNews?.provider.fetchNews(query) ?? Promise.resolve([]) },
|
|
29
30
|
}));
|
|
30
|
-
|
|
31
|
+
// The page sends its own Gloom Cloud requests and holds its own stream: their health is this registry's to keep.
|
|
32
|
+
const disposeCloudSources = registerGloomCloudConnectionSources(pluginRegistry.connectionHealth);
|
|
33
|
+
const stopRecording = pluginRegistry.events.on("host:portfolio-ticker-saved", () => recordResearchActivity("ticker_saved"));
|
|
34
|
+
return () => {
|
|
35
|
+
stopRecording();
|
|
36
|
+
disposeCloudSources();
|
|
37
|
+
};
|
|
31
38
|
},
|
|
32
39
|
});
|
|
33
40
|
}
|
|
@@ -28,7 +28,12 @@ export function browserCredentialedFetch(url: string, init: RequestInit = {}): P
|
|
|
28
28
|
// carrying them into fetch would either fail or misrepresent the web origin.
|
|
29
29
|
headers.delete("Cookie");
|
|
30
30
|
headers.delete("Origin");
|
|
31
|
-
|
|
31
|
+
// Reads skip the HTTP cache. Chromium lets only one request per URL use the
|
|
32
|
+
// cache at a time, so the same read from a second tab, or a second pane,
|
|
33
|
+
// waits for the first to finish and then goes to the network anyway: three
|
|
34
|
+
// tabs opened together waited seconds per request that way.
|
|
35
|
+
const read = (init.method ?? "GET").toUpperCase() === "GET" && init.cache === undefined;
|
|
36
|
+
return fetch(url, { ...init, headers, credentials: "include", ...(read ? { cache: "no-store" as const } : {}) });
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
function parseResponseHeaders(raw: string): Headers {
|
|
@@ -15,6 +15,23 @@ const LAYOUT_SHARE_PATH = /^\/l\/[a-f0-9]{32}\/?$/;
|
|
|
15
15
|
const API_PATH = /^\/api(?:\/|$)/;
|
|
16
16
|
const APPLE_APP_SITE_ASSOCIATION_PATH = "/.well-known/apple-app-site-association";
|
|
17
17
|
const ROBOTS_PATH = "/robots.txt";
|
|
18
|
+
/**
|
|
19
|
+
* Files the web build names after their contents (`main-<hash>.js`, the launch
|
|
20
|
+
* frame, the bundled plugins: `withContentHash` in scripts/build-web.ts, the
|
|
21
|
+
* first 16 hex digits of a SHA-256). A name never serves other bytes, so a
|
|
22
|
+
* browser keeps them for a year without asking again; the bundle audit checks
|
|
23
|
+
* each such name against its file. Lazy chunks keep plain names and are
|
|
24
|
+
* revalidated as before.
|
|
25
|
+
*/
|
|
26
|
+
export const IMMUTABLE_ASSET_PATH = /^\/assets\/.+-[a-f0-9]{16}\.(?:js|css)$/;
|
|
27
|
+
const IMMUTABLE_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
28
|
+
/**
|
|
29
|
+
* The icons and the install manifest keep their names from build to build.
|
|
30
|
+
* The browser asked whether each had changed before the first paint of every
|
|
31
|
+
* open; a copy up to a day old does no harm.
|
|
32
|
+
*/
|
|
33
|
+
const DAILY_ASSET_PATH = /^\/(?:favicon\.(?:ico|svg)|manifest\.webmanifest|app-icon-\d+\.png)$/;
|
|
34
|
+
const DAILY_CACHE_CONTROL = "public, max-age=86400";
|
|
18
35
|
|
|
19
36
|
/**
|
|
20
37
|
* Crawling stays allowed on purpose. Deep links are kept out of the index by
|
|
@@ -64,13 +81,17 @@ export const SECURITY_HEADERS = {
|
|
|
64
81
|
"x-frame-options": "DENY",
|
|
65
82
|
} as const;
|
|
66
83
|
|
|
67
|
-
export function withSecurityHeaders(response: Response, options: { share?: boolean; noindex?: boolean } = {}): Response {
|
|
84
|
+
export function withSecurityHeaders(response: Response, options: { share?: boolean; noindex?: boolean; keep?: "immutable" | "daily" } = {}): Response {
|
|
68
85
|
const headers = new Headers(response.headers);
|
|
69
86
|
for (const [name, value] of Object.entries(SECURITY_HEADERS)) headers.set(name, value);
|
|
70
87
|
const html = (headers.get("content-type") ?? "").includes("text/html");
|
|
71
88
|
if (options.share) headers.set("x-robots-tag", "noindex, nofollow, noarchive");
|
|
72
89
|
else if (options.noindex && html) headers.set("x-robots-tag", "noindex");
|
|
73
90
|
if (html) headers.set("cache-control", "no-store");
|
|
91
|
+
// Only the file itself: a name the build no longer has falls back to the app's HTML, which stays no-store.
|
|
92
|
+
else if (options.keep && (response.ok || response.status === 304)) {
|
|
93
|
+
headers.set("cache-control", options.keep === "immutable" ? IMMUTABLE_CACHE_CONTROL : DAILY_CACHE_CONTROL);
|
|
94
|
+
}
|
|
74
95
|
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
75
96
|
}
|
|
76
97
|
|
|
@@ -135,7 +156,8 @@ export async function handleRequest(request: Request, env: WorkerEnv, fetchApi:
|
|
|
135
156
|
// `/?ticker=GPC&tab=executives` would be indexed as thin duplicates. Only the
|
|
136
157
|
// bare root stays indexable.
|
|
137
158
|
const deepLink = url.pathname !== "/" || url.search !== "";
|
|
138
|
-
|
|
159
|
+
const keep = IMMUTABLE_ASSET_PATH.test(url.pathname) ? "immutable" : DAILY_ASSET_PATH.test(url.pathname) ? "daily" : undefined;
|
|
160
|
+
return withSecurityHeaders(await env.ASSETS.fetch(request), { noindex: deepLink, keep });
|
|
139
161
|
}
|
|
140
162
|
|
|
141
163
|
export default {
|
|
@@ -176,6 +176,21 @@ button, [data-gloom-interactive="true"] { cursor: pointer; }
|
|
|
176
176
|
border: 0;
|
|
177
177
|
border-radius: 0;
|
|
178
178
|
}
|
|
179
|
+
/* Docked panes sit a small gap apart (the shell's dock geometry). Each one
|
|
180
|
+
rules the sides that face another pane across it, in the colour of the line
|
|
181
|
+
that ran between them, so the gap reads in every theme. */
|
|
182
|
+
[data-gloom-role="pane-window"][data-floating="false"][data-dock-edges]::after {
|
|
183
|
+
content: "";
|
|
184
|
+
position: absolute;
|
|
185
|
+
inset: 0;
|
|
186
|
+
border: 0 solid var(--gloom-border);
|
|
187
|
+
pointer-events: none;
|
|
188
|
+
z-index: 100;
|
|
189
|
+
}
|
|
190
|
+
[data-gloom-role="pane-window"][data-floating="false"][data-dock-edges~="left"]::after { border-left-width: 1px; }
|
|
191
|
+
[data-gloom-role="pane-window"][data-floating="false"][data-dock-edges~="right"]::after { border-right-width: 1px; }
|
|
192
|
+
[data-gloom-role="pane-window"][data-floating="false"][data-dock-edges~="top"]::after { border-top-width: 1px; }
|
|
193
|
+
[data-gloom-role="pane-window"][data-floating="false"][data-dock-edges~="bottom"]::after { border-bottom-width: 1px; }
|
|
179
194
|
[data-gloom-role="pane-window"][data-floating="false"][data-focused="true"] {
|
|
180
195
|
box-shadow: inset 0 0 0 1px var(--pane-border-color, var(--gloom-border-focused));
|
|
181
196
|
}
|
|
@@ -663,10 +678,25 @@ button, [data-gloom-interactive="true"] { cursor: pointer; }
|
|
|
663
678
|
[data-gloom-role="dock-divider"] {
|
|
664
679
|
background: transparent !important;
|
|
665
680
|
}
|
|
681
|
+
/* Where a moving pane would land (a spot it would join or stack in, a
|
|
682
|
+
screen-edge snap, window mode's keyboard move): the exact rectangle,
|
|
683
|
+
outlined in the accent over a light tint of it, so the panes under it still
|
|
684
|
+
show. */
|
|
685
|
+
[data-gloom-role="drop-preview"],
|
|
686
|
+
[data-gloom-role="window-mode-drop-preview"] {
|
|
687
|
+
border: 2px solid var(--gloom-accent);
|
|
688
|
+
border-radius: var(--gloom-radius-md);
|
|
689
|
+
background: color-mix(in srgb, var(--gloom-accent) 12%, transparent);
|
|
690
|
+
}
|
|
691
|
+
/* The gap between the panes is the divider at rest; its line shows while it
|
|
692
|
+
is dragged or resized from the keyboard. */
|
|
666
693
|
[data-gloom-role="dock-divider"]::before {
|
|
667
694
|
content: "";
|
|
668
695
|
position: absolute;
|
|
669
696
|
background: var(--divider-color);
|
|
697
|
+
opacity: 0;
|
|
698
|
+
}
|
|
699
|
+
[data-gloom-role="dock-divider"][data-active="true"]::before {
|
|
670
700
|
opacity: .9;
|
|
671
701
|
}
|
|
672
702
|
[data-gloom-role="dock-divider"][data-axis="horizontal"] {
|
|
@@ -1288,6 +1318,7 @@ html[data-gloom-screenshot="true"] [data-gloom-role="chart-watermark"] {
|
|
|
1288
1318
|
overflow clip without changing the layout size. */
|
|
1289
1319
|
[data-gloom-role="pane-header"] [data-gloom-role="pane-title"],
|
|
1290
1320
|
[data-gloom-role="pane-header-tabs"] [data-gloom-role="tab-label"],
|
|
1321
|
+
[data-gloom-role="pane-stack-tabs"] [data-gloom-role="tab-label"],
|
|
1291
1322
|
.gloom-qb-label,
|
|
1292
1323
|
.gloom-qb-value,
|
|
1293
1324
|
.gloom-qb-text,
|
|
@@ -1298,6 +1329,7 @@ html[data-gloom-screenshot="true"] [data-gloom-role="chart-watermark"] {
|
|
|
1298
1329
|
}
|
|
1299
1330
|
[data-gloom-role="pane-header"] [data-gloom-role="pane-title"],
|
|
1300
1331
|
[data-gloom-role="pane-header-tabs"] [data-gloom-role="tab-label"],
|
|
1332
|
+
[data-gloom-role="pane-stack-tabs"] [data-gloom-role="tab-label"],
|
|
1301
1333
|
.gloom-qb-title,
|
|
1302
1334
|
.gloom-qb-meta {
|
|
1303
1335
|
padding-block: var(--gloom-space-xs);
|
|
@@ -16,6 +16,8 @@ import type {
|
|
|
16
16
|
} from "../types/plugin";
|
|
17
17
|
import type { TickerRecord } from "../types/ticker";
|
|
18
18
|
import { isRecord } from "../utils/guards";
|
|
19
|
+
import { buildDockStack, isDockStack } from "../layout/pane-manager/dock-stack";
|
|
20
|
+
import { getDockedInstanceIds } from "../layout/pane-manager/dock-tree";
|
|
19
21
|
|
|
20
22
|
const MAX_LAYOUT_BYTES = 128 * 1024;
|
|
21
23
|
// Pane runtime state doubles as a cache (news panes keep six figures of bytes of
|
|
@@ -464,6 +466,81 @@ function mapDockNode(node: DockLayoutNode | null, ids: ReadonlyMap<string, strin
|
|
|
464
466
|
};
|
|
465
467
|
}
|
|
466
468
|
|
|
469
|
+
/**
|
|
470
|
+
* A stack of tabs travels as its panes side by side, the form every app and
|
|
471
|
+
* the gallery accept, with its tabs in the state of its first pane under this
|
|
472
|
+
* key: an app that knows stacks puts them back together, and an older one
|
|
473
|
+
* shows them side by side and ignores the key.
|
|
474
|
+
*/
|
|
475
|
+
export const SHARED_STACK_STATE_KEY = "dockStack";
|
|
476
|
+
|
|
477
|
+
interface SharedStack {
|
|
478
|
+
/** The stack's panes in tab order. */
|
|
479
|
+
tabs: string[];
|
|
480
|
+
/** The one it shows. */
|
|
481
|
+
shown: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Panes side by side, as even as a split tree goes, as shallow as it goes too: a long stack stays within the depth a share allows. */
|
|
485
|
+
function sideBySide(ids: readonly string[]): DockLayoutNode {
|
|
486
|
+
if (ids.length === 1) return { kind: "pane", instanceId: ids[0]! };
|
|
487
|
+
const half = Math.ceil(ids.length / 2);
|
|
488
|
+
return {
|
|
489
|
+
kind: "split",
|
|
490
|
+
axis: "horizontal",
|
|
491
|
+
ratio: half / ids.length,
|
|
492
|
+
first: sideBySide(ids.slice(0, half)),
|
|
493
|
+
second: sideBySide(ids.slice(half)),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** `node` with every stack laid out side by side, the stacks it had added to `stacks`. */
|
|
498
|
+
function withStacksSideBySide(node: DockLayoutNode | null, stacks: SharedStack[]): DockLayoutNode | null {
|
|
499
|
+
if (!node || node.kind === "pane") return node;
|
|
500
|
+
if (isDockStack(node)) {
|
|
501
|
+
const tabs = getDockedInstanceIds(node);
|
|
502
|
+
stacks.push({ tabs, shown: tabs.includes(node.tabs.active) ? node.tabs.active : tabs[0]! });
|
|
503
|
+
return sideBySide(tabs);
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
kind: "split",
|
|
507
|
+
axis: node.axis,
|
|
508
|
+
ratio: node.ratio,
|
|
509
|
+
first: withStacksSideBySide(node.first, stacks)!,
|
|
510
|
+
second: withStacksSideBySide(node.second, stacks)!,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function parseSharedStack(value: unknown): SharedStack | null {
|
|
515
|
+
if (!isRecord(value) || !Array.isArray(value.tabs) || typeof value.shown !== "string") return null;
|
|
516
|
+
const tabs = value.tabs.filter((id): id is string => typeof id === "string");
|
|
517
|
+
return tabs.length === value.tabs.length ? { tabs, shown: value.shown } : null;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* `node` with the panes of `stack` stacked again, where they still fill one
|
|
522
|
+
* part of the tree on their own; as it is otherwise.
|
|
523
|
+
*/
|
|
524
|
+
function restack(node: DockLayoutNode | null, stack: SharedStack): DockLayoutNode | null {
|
|
525
|
+
const want = new Set(stack.tabs);
|
|
526
|
+
let done = false;
|
|
527
|
+
const visit = (current: DockLayoutNode): { node: DockLayoutNode; ids: string[] } => {
|
|
528
|
+
if (current.kind === "pane") return { node: current, ids: [current.instanceId] };
|
|
529
|
+
const first = visit(current.first);
|
|
530
|
+
const second = visit(current.second);
|
|
531
|
+
const ids = [...first.ids, ...second.ids];
|
|
532
|
+
if (!done && ids.length === want.size && ids.every((id) => want.has(id))) {
|
|
533
|
+
done = true;
|
|
534
|
+
return { node: buildDockStack(stack.tabs, stack.shown)!, ids };
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
node: first.node === current.first && second.node === current.second ? current : { ...current, first: first.node, second: second.node },
|
|
538
|
+
ids,
|
|
539
|
+
};
|
|
540
|
+
};
|
|
541
|
+
return node && want.size > 1 ? visit(node).node : node;
|
|
542
|
+
}
|
|
543
|
+
|
|
467
544
|
function mapBinding(binding: PaneBinding | undefined, ids: ReadonlyMap<string, string>): PaneBinding | undefined {
|
|
468
545
|
return binding?.kind === "follow"
|
|
469
546
|
? { kind: "follow", sourceInstanceId: ids.get(binding.sourceInstanceId) ?? binding.sourceInstanceId }
|
|
@@ -525,8 +602,17 @@ function publishableLayout(
|
|
|
525
602
|
...(settings ? { settings } : {}),
|
|
526
603
|
};
|
|
527
604
|
});
|
|
605
|
+
const stacks: SharedStack[] = [];
|
|
606
|
+
const dockRoot = mapDockNode(withStacksSideBySide(publicLayout.dockRoot, stacks), ids);
|
|
607
|
+
for (const stack of stacks) {
|
|
608
|
+
const tabs = stack.tabs.map((id) => ids.get(id) ?? id);
|
|
609
|
+
projectedState[tabs[0]!] = {
|
|
610
|
+
...projectedState[tabs[0]!],
|
|
611
|
+
[SHARED_STACK_STATE_KEY]: { tabs, shown: ids.get(stack.shown) ?? stack.shown },
|
|
612
|
+
} as PaneRuntimeState;
|
|
613
|
+
}
|
|
528
614
|
const projected: LayoutConfig = {
|
|
529
|
-
dockRoot
|
|
615
|
+
dockRoot,
|
|
530
616
|
instances,
|
|
531
617
|
floating: publicLayout.floating.map(({ instanceId, x, y, width, height, zIndex }) => ({
|
|
532
618
|
instanceId: ids.get(instanceId) ?? instanceId,
|
|
@@ -665,8 +751,19 @@ export function materializeMarketplaceLayout(
|
|
|
665
751
|
createId(instance.paneId, index),
|
|
666
752
|
]));
|
|
667
753
|
if (new Set(ids.values()).size !== ids.size) throw new Error("Could not create unique pane ids for this layout.");
|
|
754
|
+
// The stacks travel side by side, their tabs noted in their first pane's state.
|
|
755
|
+
let dockRoot = mapDockNode(source.layout.dockRoot, ids);
|
|
756
|
+
for (const [id, state] of Object.entries(source.paneState)) {
|
|
757
|
+
const stack = parseSharedStack(state?.[SHARED_STACK_STATE_KEY]);
|
|
758
|
+
if (!stack) continue;
|
|
759
|
+
const tabs = stack.tabs.map((tab) => ids.get(folded.idMap.get(tab) ?? tab)).filter((tab): tab is string => !!tab);
|
|
760
|
+
const shown = ids.get(folded.idMap.get(stack.shown) ?? stack.shown);
|
|
761
|
+
if (tabs.length > 1 && tabs.length === new Set(tabs).size) dockRoot = restack(dockRoot, { tabs, shown: shown ?? tabs[0]! });
|
|
762
|
+
const { [SHARED_STACK_STATE_KEY]: _stack, ...rest } = state;
|
|
763
|
+
source.paneState[id] = rest as PaneRuntimeState;
|
|
764
|
+
}
|
|
668
765
|
const layout: LayoutConfig = {
|
|
669
|
-
dockRoot
|
|
766
|
+
dockRoot,
|
|
670
767
|
instances: source.layout.instances.map((instance) => ({
|
|
671
768
|
...structuredClone(instance),
|
|
672
769
|
instanceId: ids.get(instance.instanceId)!,
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
type ProviderRouterCachePolicyKey,
|
|
52
52
|
} from "./cache";
|
|
53
53
|
import { ProviderRouterSearchRoutes } from "./search";
|
|
54
|
-
import { collectCapabilityRouteSources, normalizeRouteSource } from "./sources";
|
|
54
|
+
import { collectCapabilityRouteSources, mergeRouteSourcesById, normalizeRouteSource } from "./sources";
|
|
55
55
|
import type { ProviderRouterCoreDeps } from "./route-types";
|
|
56
56
|
import { withProviderConnectionHealth } from "./connection-health";
|
|
57
57
|
import { withFiledTrailingEps } from "../../time-series/filed-trailing-eps";
|
|
@@ -612,7 +612,7 @@ export class AssetDataRouter implements DataProvider {
|
|
|
612
612
|
...this.registry.getEnabledCapabilities("news"),
|
|
613
613
|
]));
|
|
614
614
|
}
|
|
615
|
-
return sources
|
|
615
|
+
return mergeRouteSourcesById(sources)
|
|
616
616
|
.filter((source) => source.id !== this.id && source.id !== this.fallbackSource?.id)
|
|
617
617
|
.sort((a, b) => routeSourcePriority(a) - routeSourcePriority(b));
|
|
618
618
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AssetDataCapability, NewsCapability, PluginCapability } from "../../capabilities";
|
|
2
|
-
import type
|
|
2
|
+
import { routeSourcePriority, type CapabilityRouteSource } from "../../types/capability-route-source";
|
|
3
3
|
import type { DataProvider } from "../../types/data-provider";
|
|
4
4
|
|
|
5
5
|
type RouteSourceCapability = AssetDataCapability | NewsCapability;
|
|
@@ -20,6 +20,31 @@ export function collectCapabilityRouteSources(capabilities: PluginCapability[]):
|
|
|
20
20
|
return [...capabilitySources.values()];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* One source per id. A host can hand the router a source a plugin also
|
|
25
|
+
* registers (the web app passes its own Gloom Cloud client, which stays when
|
|
26
|
+
* the plugin is turned off): asked as two, every read that falls through to
|
|
27
|
+
* the next source, or races it, sends the same request twice. The first one
|
|
28
|
+
* listed keeps its clients; the other fills in what it lacks.
|
|
29
|
+
*/
|
|
30
|
+
export function mergeRouteSourcesById(sources: readonly CapabilityRouteSource[]): CapabilityRouteSource[] {
|
|
31
|
+
const byId = new Map<string, CapabilityRouteSource>();
|
|
32
|
+
for (const source of sources) {
|
|
33
|
+
const kept = byId.get(source.id);
|
|
34
|
+
byId.set(source.id, kept ? {
|
|
35
|
+
id: kept.id,
|
|
36
|
+
name: kept.name,
|
|
37
|
+
priority: kept.priority === undefined && source.priority === undefined
|
|
38
|
+
? undefined : Math.min(routeSourcePriority(kept), routeSourcePriority(source)),
|
|
39
|
+
cachePolicy: kept.cachePolicy ?? source.cachePolicy,
|
|
40
|
+
isEnabled: kept.isEnabled ?? source.isEnabled,
|
|
41
|
+
market: kept.market ?? source.market,
|
|
42
|
+
news: kept.news ?? source.news,
|
|
43
|
+
} : source);
|
|
44
|
+
}
|
|
45
|
+
return [...byId.values()];
|
|
46
|
+
}
|
|
47
|
+
|
|
23
48
|
function routeSourceFromMarketProvider(provider: DataProvider): CapabilityRouteSource {
|
|
24
49
|
return {
|
|
25
50
|
id: provider.id,
|