(value: unknown, fields: readonly string[])
| 13 | * This reduces token usage while preserving the financial metrics needed for analysis. |
| 14 | */ |
| 15 | export function stripFieldsDeep(value: unknown, fields: readonly string[]): unknown { |
| 16 | const fieldsToStrip = new Set(fields); |
| 17 | |
| 18 | function walk(node: unknown): unknown { |
| 19 | if (Array.isArray(node)) { |
| 20 | return node.map(walk); |
| 21 | } |
| 22 | |
| 23 | if (!node || typeof node !== 'object') { |
| 24 | return node; |
| 25 | } |
| 26 | |
| 27 | const record = node as Record<string, unknown>; |
| 28 | const cleaned: Record<string, unknown> = {}; |
| 29 | |
| 30 | for (const [key, child] of Object.entries(record)) { |
| 31 | if (fieldsToStrip.has(key)) { |
| 32 | continue; |
| 33 | } |
| 34 | cleaned[key] = walk(child); |
| 35 | } |
| 36 | |
| 37 | return cleaned; |
| 38 | } |
| 39 | |
| 40 | return walk(value); |
| 41 | } |
| 42 | |
| 43 | function getApiKey(): string { |
| 44 | return process.env.FINANCIAL_DATASETS_API_KEY || ''; |
no test coverage detected