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:
2026-03-15 15:56:16 -04:00
parent edf1cfb421
commit 5f0abbb007
14 changed files with 193 additions and 127 deletions

View File

@@ -17,6 +17,7 @@ import {
listResearchJournalEntries,
listResearchJournalEntriesForUser
} from '@/lib/server/repos/research-journal';
import { normalizeTicker } from '@/lib/server/utils';
type SearchDocumentScope = 'global' | 'user';
type SearchDocumentSourceKind = 'filing_document' | 'filing_brief' | 'research_note';
@@ -131,11 +132,6 @@ function escapeLike(value: string) {
return value.replace(/[%_]/g, (match) => `\\${match}`);
}
function normalizeTicker(value: string | null | undefined) {
const normalized = value?.trim().toUpperCase() ?? '';
return normalized.length > 0 ? normalized : null;
}
function normalizeSearchSources(sources?: SearchSource[]) {
const normalized = new Set<SearchSource>();