Consolidate server utilities into shared module
- Add lib/server/utils/normalize.ts with normalizeTicker, normalizeTagsOrNull, nowIso, todayIso - Add lib/server/utils/validation.ts with asRecord, asBoolean, asStringArray, asEnum - Add lib/server/utils/index.ts re-exporting all utilities - Remove duplicate lib/server/utils.ts (old file) - Update all repos and files to use shared utilities - Remove redundant ?? '' from normalizeTicker calls - Update watchlist.ts to use normalizeTagsOrNull for null-return tags
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { format } from 'date-fns';
|
||||
import type { Filing, RecentDevelopmentItem, RecentDevelopments } from '@/lib/types';
|
||||
import { normalizeTicker } from '@/lib/server/utils';
|
||||
|
||||
export type RecentDevelopmentSourceContext = {
|
||||
filings: Filing[];
|
||||
@@ -115,9 +116,9 @@ export async function getRecentDevelopments(
|
||||
limit?: number;
|
||||
}
|
||||
): Promise<RecentDevelopments> {
|
||||
const normalizedTicker = ticker.trim().toUpperCase();
|
||||
const normalizedTicker = normalizeTicker(ticker);
|
||||
const limit = options?.limit ?? 6;
|
||||
const cacheKey = `${normalizedTicker}:${context.filings.map((filing) => filing.accession_number).join(',')}`;
|
||||
const cacheKey = `${normalizedTicker ?? ''}:${context.filings.map((filing) => filing.accession_number).join(',')}`;
|
||||
const cached = recentDevelopmentsCache.get(cacheKey);
|
||||
|
||||
if (cached && cached.expiresAt > Date.now()) {
|
||||
@@ -128,7 +129,7 @@ export async function getRecentDevelopments(
|
||||
const itemCollections = await Promise.all(
|
||||
sources.map(async (source) => {
|
||||
try {
|
||||
return await source.fetch(normalizedTicker, context);
|
||||
return await source.fetch(normalizedTicker ?? '', context);
|
||||
} catch {
|
||||
return [] satisfies RecentDevelopmentItem[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user