refactor(views): reuse Android JNI collection filters (#16812)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 02:50:44 +08:00
1 parent 819ecf1ad4
commit 8e5ca2490b
1 file changed
+40 -49
+40 -49
View File
@@ -32,7 +32,11 @@ import {
pageViewCoverage,
analysisViewCoverageSchema,
} from "./analysisViewCoverage.js";
import { filterSet, pickSourceOrderedFields } from "./selectViewRows.js";
import {
filterSet,
matchingViewFields,
pickSourceOrderedFields,
} from "./selectViewRows.js";
import {
PLACEHOLDER_COVERAGE,
selectByteBoundedViewRows,
@@ -273,11 +277,11 @@ export const projectAndroidJniView = (
coverage: PLACEHOLDER_COVERAGE,
};
const pick = <Row extends object>(
rows: readonly Row[],
matches: (row: Row) => boolean,
) =>
selectByteBoundedViewRows(
rows,
source: readonly Row[],
matches: ((row: Row) => boolean) | undefined,
) => {
const selected = selectByteBoundedViewRows(
source,
view,
{
matches,
@@ -290,39 +294,38 @@ export const projectAndroidJniView = (
facet: `JNI ${view.collection}`,
},
);
let selected: ReturnType<typeof pick<object>>;
if (!selected.ok) return selected;
const { rows, total } = selected.value;
return ok({
...envelope,
items: androidJniViewItemsSchema.parse(rows),
coverage: pageViewCoverage(view.offset, rows.length, total),
});
};
switch (view.collection) {
case "declarations": {
const classes = filterSet(view.class_names),
names = filterSet(view.method_names),
ids = filterSet(view.declaration_ids),
descriptors = filterSet(view.descriptors);
selected = pick(
case "declarations":
return pick(
report.declarations,
(row) =>
(classes === undefined || classes.has(row.class_name)) &&
(names === undefined || names.has(row.method_name)) &&
(ids === undefined || ids.has(row.declaration_id)) &&
(descriptors === undefined || descriptors.has(row.descriptor)),
matchingViewFields([
["class_name", view.class_names],
["method_name", view.method_names],
["declaration_id", view.declaration_ids],
["descriptor", view.descriptors],
]),
);
break;
}
case "libraries": {
const ids = filterSet(view.library_ids),
abis = filterSet(view.abis);
selected = pick(
case "libraries":
return pick(
report.libraries,
(row) =>
(ids === undefined || ids.has(row.library_id)) &&
(abis === undefined || abis.has(row.abi)),
matchingViewFields([
["library_id", view.library_ids],
["abi", view.abis],
]),
);
break;
}
case "candidates": {
const ids = filterSet(view.declaration_ids),
libs = filterSet(view.library_ids),
candidates = filterSet(view.candidate_ids);
selected = pick(
return pick(
report.candidates,
(row) =>
(ids === undefined ||
@@ -330,28 +333,16 @@ export const projectAndroidJniView = (
(libs === undefined || libs.has(row.library_id)) &&
(candidates === undefined || candidates.has(row.candidate_id)),
);
break;
}
case "bindings": {
const ids = filterSet(view.declaration_ids),
abis = filterSet(view.abis),
statuses = filterSet(view.statuses);
selected = pick(
case "bindings":
return pick(
report.bindings,
(row) =>
(ids === undefined || ids.has(row.declaration_id)) &&
(abis === undefined || abis.has(row.abi)) &&
(statuses === undefined || statuses.has(row.status)),
matchingViewFields([
["declaration_id", view.declaration_ids],
["abi", view.abis],
["status", view.statuses],
]),
);
break;
}
}
if (!selected.ok) return selected;
const { rows, total } = selected.value;
return ok({
...envelope,
items: androidJniViewItemsSchema.parse(rows),
coverage: pageViewCoverage(view.offset, rows.length, total),
});
}
};