Files
reverse-engineering-anything/src/domain/known.ts
T
morluto 90ce8bae4a fix(javascript): report version-comparison coverage unknown when a source graph cannot tell (#11206)
* fix(javascript): report version-comparison coverage unknown when a source graph cannot tell

* refactor(javascript): name the unavailable-graph coverage mapping once

* fix(javascript): give the version change graph and its edges the same unknown coverage

* fix(javascript): report export-shape comparison coverage unknown when a source graph cannot tell (#11218)

* fix(javascript): report export-shape comparison coverage unknown when a source graph cannot tell

* test(javascript): keep unknown export-shape coverage beside a truncated projection

* fix(javascript): read runtime-reconciliation input coverage once and report unknown when a static graph cannot tell (#11230)

* fix(javascript): read runtime-reconciliation input coverage once and report unknown when a static graph cannot tell

* fix(javascript): keep a known input truncation beside unknown reconciliation coverage

* fix(javascript): report export-shape source omission counts unknown when a side has no projection (#11261)

compare_export_shapes reported left/right_omitted_fields and omitted_property_coverage as 0 for a side whose export selection recovered no return-shape projection (missing, ambiguous or unavailable), while the sibling source_omitted_variants already reported null. Add Known<T> (src/domain/known.ts) and read each side's source coverage once through it; the counts are now null (unknown) with a limitation naming why. The runtime-reconciliation graph's omission sum and its parallel 'omissions known' flag become one Known<number> via sumKnownCounts (no output change).
2026-11-15 23:59:23 +08:00

39 lines
1.1 KiB
TypeScript

/**
* A fact its producer established, or the reason it could not. An unknown
* fact is never a default value: a count it would have supplied is unknown,
* not zero, and a list is unknown, not empty.
*/
export type Known<T> =
| { readonly known: true; readonly value: T }
| { readonly known: false; readonly reason: string };
/** A fact the producer established. */
export const known = <T>(value: T): Known<T> => ({ known: true, value });
/** A fact the producer could not establish, with why. */
export const unknownBecause = (reason: string): Known<never> => ({
known: false,
reason,
});
/**
* Sum counts; one unknown count makes the sum unknown, with the first
* unknown's reason, rather than counting as zero.
*/
export const sumKnownCounts = (
counts: readonly Known<number>[],
): Known<number> => {
let total = 0;
for (const count of counts) {
if (!count.known) return count;
total += count.value;
}
return known(total);
};
/** Project a fact onto a wire field where `null` means unknown. */
export const knownOrNull = <T, R>(
fact: Known<T>,
read: (value: T) => R,
): R | null => (fact.known ? read(fact.value) : null);