Expand financials surfaces with ratios, KPIs, and cadence support
- Add bundled financial modeling pipeline (ratios, KPI dimensions/notes, trend series, standardization) - Introduce company financial bundles storage (Drizzle migration + repo wiring) - Refactor financials page/API/query flow to use surfaceKind + cadence and new response shapes
This commit is contained in:
53
lib/server/financials/bundles.ts
Normal file
53
lib/server/financials/bundles.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import type {
|
||||
FinancialCadence,
|
||||
FinancialSurfaceKind
|
||||
} from '@/lib/types';
|
||||
import {
|
||||
getCompanyFinancialBundle,
|
||||
upsertCompanyFinancialBundle
|
||||
} from '@/lib/server/repos/company-financial-bundles';
|
||||
import type { FilingTaxonomySnapshotRecord } from '@/lib/server/repos/filing-taxonomy';
|
||||
|
||||
export function computeSourceSignature(snapshots: FilingTaxonomySnapshotRecord[]) {
|
||||
return snapshots
|
||||
.map((snapshot) => `${snapshot.id}:${snapshot.updated_at}`)
|
||||
.sort((left, right) => left.localeCompare(right))
|
||||
.join('|');
|
||||
}
|
||||
|
||||
export async function readCachedFinancialBundle(input: {
|
||||
ticker: string;
|
||||
surfaceKind: FinancialSurfaceKind;
|
||||
cadence: FinancialCadence;
|
||||
snapshots: FilingTaxonomySnapshotRecord[];
|
||||
}) {
|
||||
const sourceSignature = computeSourceSignature(input.snapshots);
|
||||
const cached = await getCompanyFinancialBundle({
|
||||
ticker: input.ticker,
|
||||
surfaceKind: input.surfaceKind,
|
||||
cadence: input.cadence
|
||||
});
|
||||
|
||||
if (!cached || cached.source_signature !== sourceSignature) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cached.payload;
|
||||
}
|
||||
|
||||
export async function writeFinancialBundle(input: {
|
||||
ticker: string;
|
||||
surfaceKind: FinancialSurfaceKind;
|
||||
cadence: FinancialCadence;
|
||||
snapshots: FilingTaxonomySnapshotRecord[];
|
||||
payload: Record<string, unknown>;
|
||||
}) {
|
||||
return await upsertCompanyFinancialBundle({
|
||||
ticker: input.ticker,
|
||||
surfaceKind: input.surfaceKind,
|
||||
cadence: input.cadence,
|
||||
sourceSnapshotIds: input.snapshots.map((snapshot) => snapshot.id),
|
||||
sourceSignature: computeSourceSignature(input.snapshots),
|
||||
payload: input.payload
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user