88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import type {
|
|
FinancialCadence,
|
|
FinancialSurfaceKind,
|
|
FinancialUnit,
|
|
RatioRow
|
|
} from '@/lib/types';
|
|
import {
|
|
type ComputedDefinition,
|
|
type SurfaceDefinition,
|
|
ALL_COMPUTED,
|
|
INCOME_SURFACES,
|
|
BALANCE_SURFACES,
|
|
CASH_FLOW_SURFACES,
|
|
RATIO_CATEGORIES
|
|
} from '@/lib/generated';
|
|
|
|
export type GraphableFinancialSurfaceKind = Extract<
|
|
FinancialSurfaceKind,
|
|
'income_statement' | 'balance_sheet' | 'cash_flow_statement' | 'ratios'
|
|
>;
|
|
|
|
type StatementMetricDefinition = {
|
|
key: string;
|
|
label: string;
|
|
category: string;
|
|
order: number;
|
|
unit: FinancialUnit;
|
|
};
|
|
|
|
type RatioMetricDefinition = {
|
|
key: string;
|
|
label: string;
|
|
category: string;
|
|
order: number;
|
|
unit: RatioRow['unit'];
|
|
denominatorKey: string | null;
|
|
supportedCadences?: readonly FinancialCadence[];
|
|
};
|
|
|
|
export const GRAPHABLE_FINANCIAL_SURFACES: readonly GraphableFinancialSurfaceKind[] = [
|
|
'income_statement',
|
|
'balance_sheet',
|
|
'cash_flow_statement',
|
|
'ratios'
|
|
] as const;
|
|
|
|
function surfaceToMetric(surface: SurfaceDefinition): StatementMetricDefinition {
|
|
return {
|
|
key: surface.surface_key,
|
|
label: surface.label,
|
|
category: surface.category,
|
|
order: surface.order,
|
|
unit: surface.unit
|
|
};
|
|
}
|
|
|
|
function computedToRatioMetric(computed: ComputedDefinition): RatioMetricDefinition {
|
|
const denominatorKey = computed.computation.type === 'ratio'
|
|
? computed.computation.denominator
|
|
: computed.computation.type === 'per_share'
|
|
? computed.computation.shares_key
|
|
: null;
|
|
|
|
return {
|
|
key: computed.key,
|
|
label: computed.label,
|
|
category: computed.category,
|
|
order: computed.order,
|
|
unit: computed.unit as RatioRow['unit'],
|
|
denominatorKey,
|
|
supportedCadences: computed.supported_cadences as readonly FinancialCadence[] | undefined
|
|
};
|
|
}
|
|
|
|
export const INCOME_STATEMENT_METRIC_DEFINITIONS: StatementMetricDefinition[] =
|
|
INCOME_SURFACES.map(surfaceToMetric);
|
|
|
|
export const BALANCE_SHEET_METRIC_DEFINITIONS: StatementMetricDefinition[] =
|
|
BALANCE_SURFACES.map(surfaceToMetric);
|
|
|
|
export const CASH_FLOW_STATEMENT_METRIC_DEFINITIONS: StatementMetricDefinition[] =
|
|
CASH_FLOW_SURFACES.map(surfaceToMetric);
|
|
|
|
export const RATIO_DEFINITIONS: RatioMetricDefinition[] =
|
|
ALL_COMPUTED.map(computedToRatioMetric);
|
|
|
|
export { RATIO_CATEGORIES, } from '@/lib/generated';
|