mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
refactor(views): share the capture facet page selector (#16711)
This commit is contained in:
1 parent
ab4b20aa9b
commit
012febae5c
3 files changed
+37
-63
No files matched your search
@@ -127,44 +127,36 @@ export const selectByteBoundedViewRows = <Source, Row>(
|
||||
};
|
||||
|
||||
/** Page one named facet with the enclosing result included in its byte budget. */
|
||||
export const selectByteBoundedFacetPage = <
|
||||
Envelope extends { readonly parent_evidence_id: string },
|
||||
Facet extends string,
|
||||
Source,
|
||||
Row,
|
||||
>(
|
||||
rows: readonly Source[],
|
||||
view: { readonly offset: number; readonly limit: number },
|
||||
envelope: Envelope,
|
||||
{
|
||||
facet,
|
||||
label,
|
||||
project,
|
||||
}: {
|
||||
readonly facet: Facet;
|
||||
readonly label: string;
|
||||
readonly project: (row: Source) => Row;
|
||||
},
|
||||
) => {
|
||||
const selected = selectByteBoundedViewRows(
|
||||
rows,
|
||||
view,
|
||||
{ matches: undefined, project },
|
||||
{
|
||||
parentEvidenceId: envelope.parent_evidence_id,
|
||||
envelope: {
|
||||
...envelope,
|
||||
page: { facet, items: [] },
|
||||
coverage: PLACEHOLDER_COVERAGE,
|
||||
} as unknown as JsonValue,
|
||||
facet: label,
|
||||
},
|
||||
);
|
||||
if (!selected.ok) return selected;
|
||||
const { rows: items, total } = selected.value;
|
||||
return ok({
|
||||
...envelope,
|
||||
page: { facet, items },
|
||||
coverage: pageViewCoverage(view.offset, items.length, total),
|
||||
});
|
||||
};
|
||||
export const createByteBoundedFacetSelector =
|
||||
<Envelope extends { readonly parent_evidence_id: string }>(
|
||||
view: { readonly offset: number; readonly limit: number },
|
||||
envelope: Envelope,
|
||||
label: string,
|
||||
) =>
|
||||
<Facet extends string, Source, Row>(
|
||||
facet: Facet,
|
||||
rows: readonly Source[],
|
||||
project: (row: Source) => Row,
|
||||
) => {
|
||||
const selected = selectByteBoundedViewRows(
|
||||
rows,
|
||||
view,
|
||||
{ matches: undefined, project },
|
||||
{
|
||||
parentEvidenceId: envelope.parent_evidence_id,
|
||||
envelope: {
|
||||
...envelope,
|
||||
page: { facet, items: [] },
|
||||
coverage: PLACEHOLDER_COVERAGE,
|
||||
} as unknown as JsonValue,
|
||||
facet: `${label} ${facet}`,
|
||||
},
|
||||
);
|
||||
if (!selected.ok) return selected;
|
||||
const { rows: items, total } = selected.value;
|
||||
return ok({
|
||||
...envelope,
|
||||
page: { facet, items },
|
||||
coverage: pageViewCoverage(view.offset, items.length, total),
|
||||
});
|
||||
};
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
type SummaryAnalysisView,
|
||||
} from "./analysisViewShape.js";
|
||||
import { completeWithinViewCoverage } from "./analysisViewCoverage.js";
|
||||
import { selectByteBoundedFacetPage } from "./byteBoundedViewRows.js";
|
||||
import { createByteBoundedFacetSelector } from "./byteBoundedViewRows.js";
|
||||
import { analysisTextPage } from "./analysisViewText.js";
|
||||
import { evidenceFileTarget } from "../evidence.js";
|
||||
|
||||
@@ -217,16 +217,7 @@ const selectRows = <Envelope extends { readonly parent_evidence_id: string }>(
|
||||
view: Exclude<PcapView, { facet: "diagnostics" }>,
|
||||
envelope: Envelope,
|
||||
) => {
|
||||
const select = <Facet extends string, Source, Row>(
|
||||
facet: Facet,
|
||||
rows: readonly Source[],
|
||||
project: (row: Source) => Row,
|
||||
) =>
|
||||
selectByteBoundedFacetPage(rows, view, envelope, {
|
||||
facet,
|
||||
label: `PCAP ${facet}`,
|
||||
project,
|
||||
});
|
||||
const select = createByteBoundedFacetSelector(view, envelope, "PCAP");
|
||||
const identity = <Row>(row: Row): Row => row;
|
||||
switch (view.facet) {
|
||||
case "endpoints":
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import type { Result } from "../result.js";
|
||||
import type { AnalysisError } from "../analysisErrorBase.js";
|
||||
import { invalidAnalysisView } from "./analysisViewErrors.js";
|
||||
import { selectByteBoundedFacetPage } from "./byteBoundedViewRows.js";
|
||||
import { createByteBoundedFacetSelector } from "./byteBoundedViewRows.js";
|
||||
import { pageViewCoverage } from "./analysisViewCoverage.js";
|
||||
|
||||
const traceSchema = qlogCaptureFactsSchema.shape.traces.element;
|
||||
@@ -145,16 +145,7 @@ export const projectQlogCapturePage = <
|
||||
> => {
|
||||
const { traces, ...context } = qlog;
|
||||
const envelope = { ...shared, kind: "qlog" as const, view, context };
|
||||
const select = <Facet extends string, Source, Row>(
|
||||
facet: Facet,
|
||||
rows: readonly Source[],
|
||||
project: (row: Source) => Row,
|
||||
) =>
|
||||
selectByteBoundedFacetPage(rows, view, envelope, {
|
||||
facet,
|
||||
label: `qlog ${facet}`,
|
||||
project,
|
||||
});
|
||||
const select = createByteBoundedFacetSelector(view, envelope, "qlog");
|
||||
|
||||
if (view.facet === "traces")
|
||||
return select(view.facet, traces, summarizeTrace);
|
||||
|
||||
Reference in new issue
Block a user