28 lines
794 B
TypeScript
28 lines
794 B
TypeScript
// Freshness never establishes completeness. Immutable ranges are planned by
|
|
// their coverage owners; these TTLs apply only to mutable source snapshots.
|
|
export const tbankSourceTtlMs = {
|
|
membership: 300_000,
|
|
portfolio: 60_000,
|
|
quote: 60_000,
|
|
candleTail: 60_000,
|
|
operationsTail: 300_000,
|
|
metadata: 86_400_000,
|
|
catalog: 86_400_000,
|
|
company: 86_400_000,
|
|
calendar: 86_400_000,
|
|
} as const;
|
|
|
|
export function tbankSourceNeedsRefresh(
|
|
source: keyof typeof tbankSourceTtlMs,
|
|
fetchedAt: Date | null,
|
|
now: Date,
|
|
force = false,
|
|
): boolean {
|
|
return (
|
|
force ||
|
|
!fetchedAt ||
|
|
// eslint-disable-next-line security/detect-object-injection -- The key is a member of the closed TbankSource union.
|
|
now.valueOf() - fetchedAt.valueOf() >= tbankSourceTtlMs[source]
|
|
);
|
|
}
|