Skip to content

Commit

Permalink
fix(historical): correctly map adjclose -> adjClose (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Sep 20, 2024
1 parent 386bf82 commit d8851ec
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/modules/historical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit d8851ec

Please sign in to comment.