From d8851ecc8169c7f6d7c1283109e60dc55ee989e6 Mon Sep 17 00:00:00 2001 From: Gadi Cohen Date: Fri, 20 Sep 2024 12:54:59 +0100 Subject: [PATCH] fix(historical): correctly map adjclose -> adjClose (#795) --- src/modules/historical.ts | 48 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/modules/historical.ts b/src/modules/historical.ts index 6177601e..0835dee0 100644 --- a/src/modules/historical.ts +++ b/src/modules/historical.ts @@ -257,27 +257,33 @@ export default async function historical( stockSplits: s.splitRatio, })); } else { - out = (result.quotes ?? []).filter((quote) => { - const fieldCount = Object.keys(quote).length; - const nullCount = nullFieldCount(quote); - - if (nullCount === 0) { - // No nulls is a legit (regular) result - return true; - } else if (nullCount !== fieldCount - 1 /* skip "date" */) { - // Unhandled case: some but not all values are null. - // Note: no need to check for null "date", validation does it for us - console.error(nullCount, quote); - throw new Error( - "Historical returned a result with SOME (but not " + - "all) null values. Please report this, and provide the " + - "query that caused it.", - ); - } else { - // All fields (except "date") are null - return false; - } - }); + out = (result.quotes ?? []) + .filter((quote) => { + const fieldCount = Object.keys(quote).length; + const nullCount = nullFieldCount(quote); + + if (nullCount === 0) { + // No nulls is a legit (regular) result + return true; + } else if (nullCount !== fieldCount - 1 /* skip "date" */) { + // Unhandled case: some but not all values are null. + // Note: no need to check for null "date", validation does it for us + console.error(nullCount, quote); + throw new Error( + "Historical returned a result with SOME (but not " + + "all) null values. Please report this, and provide the " + + "query that caused it.", + ); + } else { + // All fields (except "date") are null + return false; + } + }) + .map((quote) => { + if (!quote.adjclose) return quote; + const { adjclose, ...rest } = quote; + return { ...rest, adjClose: adjclose }; + }); } const validateResult =