145 lines
3.6 KiB
TypeScript
145 lines
3.6 KiB
TypeScript
import { queryOptions } from '@tanstack/react-query';
|
|
import {
|
|
getCompanyAiReport,
|
|
getCompanyAnalysis,
|
|
getCompanyFinancialStatements,
|
|
getLatestPortfolioInsight,
|
|
getPortfolioSummary,
|
|
getTask,
|
|
getTaskTimeline,
|
|
listFilings,
|
|
listHoldings,
|
|
listRecentTasks,
|
|
listWatchlist
|
|
} from '@/lib/api';
|
|
import { queryKeys } from '@/lib/query/keys';
|
|
import type {
|
|
FinancialHistoryWindow,
|
|
FinancialStatementKind,
|
|
FinancialStatementMode
|
|
} from '@/lib/types';
|
|
|
|
export function companyAnalysisQueryOptions(ticker: string) {
|
|
const normalizedTicker = ticker.trim().toUpperCase();
|
|
|
|
return queryOptions({
|
|
queryKey: queryKeys.companyAnalysis(normalizedTicker),
|
|
queryFn: () => getCompanyAnalysis(normalizedTicker),
|
|
staleTime: 120_000
|
|
});
|
|
}
|
|
|
|
export function companyFinancialStatementsQueryOptions(input: {
|
|
ticker: string;
|
|
mode: FinancialStatementMode;
|
|
statement: FinancialStatementKind;
|
|
window: FinancialHistoryWindow;
|
|
includeDimensions?: boolean;
|
|
cursor?: string | null;
|
|
limit?: number;
|
|
}) {
|
|
const normalizedTicker = input.ticker.trim().toUpperCase();
|
|
const includeDimensions = input.includeDimensions ?? false;
|
|
const cursor = input.cursor ?? null;
|
|
const limit = input.limit ?? 40;
|
|
|
|
return queryOptions({
|
|
queryKey: queryKeys.companyFinancialStatements(
|
|
normalizedTicker,
|
|
input.mode,
|
|
input.statement,
|
|
input.window,
|
|
includeDimensions,
|
|
cursor,
|
|
limit
|
|
),
|
|
queryFn: () => getCompanyFinancialStatements({
|
|
ticker: normalizedTicker,
|
|
mode: input.mode,
|
|
statement: input.statement,
|
|
window: input.window,
|
|
includeDimensions,
|
|
cursor,
|
|
limit
|
|
}),
|
|
staleTime: 60_000
|
|
});
|
|
}
|
|
|
|
export function filingsQueryOptions(input: { ticker?: string; limit?: number } = {}) {
|
|
const normalizedTicker = input.ticker?.trim().toUpperCase() ?? null;
|
|
const limit = input.limit ?? 120;
|
|
|
|
return queryOptions({
|
|
queryKey: queryKeys.filings(normalizedTicker, limit),
|
|
queryFn: () => listFilings({ ticker: normalizedTicker ?? undefined, limit }),
|
|
staleTime: 60_000
|
|
});
|
|
}
|
|
|
|
export function aiReportQueryOptions(accessionNumber: string) {
|
|
const normalizedAccession = accessionNumber.trim();
|
|
|
|
return queryOptions({
|
|
queryKey: queryKeys.report(normalizedAccession),
|
|
queryFn: () => getCompanyAiReport(normalizedAccession),
|
|
staleTime: 300_000
|
|
});
|
|
}
|
|
|
|
export function watchlistQueryOptions() {
|
|
return queryOptions({
|
|
queryKey: queryKeys.watchlist(),
|
|
queryFn: () => listWatchlist(),
|
|
staleTime: 30_000
|
|
});
|
|
}
|
|
|
|
export function holdingsQueryOptions() {
|
|
return queryOptions({
|
|
queryKey: queryKeys.holdings(),
|
|
queryFn: () => listHoldings(),
|
|
staleTime: 30_000
|
|
});
|
|
}
|
|
|
|
export function portfolioSummaryQueryOptions() {
|
|
return queryOptions({
|
|
queryKey: queryKeys.portfolioSummary(),
|
|
queryFn: () => getPortfolioSummary(),
|
|
staleTime: 30_000
|
|
});
|
|
}
|
|
|
|
export function latestPortfolioInsightQueryOptions() {
|
|
return queryOptions({
|
|
queryKey: queryKeys.latestPortfolioInsight(),
|
|
queryFn: () => getLatestPortfolioInsight(),
|
|
staleTime: 30_000
|
|
});
|
|
}
|
|
|
|
export function taskQueryOptions(taskId: string) {
|
|
return queryOptions({
|
|
queryKey: queryKeys.task(taskId),
|
|
queryFn: () => getTask(taskId),
|
|
staleTime: 5_000
|
|
});
|
|
}
|
|
|
|
export function taskTimelineQueryOptions(taskId: string) {
|
|
return queryOptions({
|
|
queryKey: queryKeys.taskTimeline(taskId),
|
|
queryFn: () => getTaskTimeline(taskId),
|
|
staleTime: 5_000
|
|
});
|
|
}
|
|
|
|
export function recentTasksQueryOptions(limit = 20) {
|
|
return queryOptions({
|
|
queryKey: queryKeys.recentTasks(limit),
|
|
queryFn: () => listRecentTasks({ limit }),
|
|
staleTime: 5_000
|
|
});
|
|
}
|