mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(protobuf): share row field filtering (#17442)
This commit is contained in:
@@ -75,6 +75,9 @@ export const protobufViewRequestSchema = z.discriminatedUnion("collection", [
|
||||
fields: z.array(fieldRow.keyof()).optional(),
|
||||
}),
|
||||
]);
|
||||
const embeddedRowFields = new Set(["frames", "fields", "pointer"]);
|
||||
const optInRowFields = new Set(["text", "schema_value", "schema_enum_values"]);
|
||||
|
||||
const requiredBodyFields = {
|
||||
record_ordinal: true,
|
||||
body_pointer: true,
|
||||
@@ -206,6 +209,7 @@ export const projectProtobufCapturePage = <
|
||||
? new Set(view.frame_indices)
|
||||
: undefined;
|
||||
const mandatory = Object.keys(mandatoryFields[view.collection]);
|
||||
const fields = view.fields;
|
||||
let total = 0;
|
||||
const items: Record<string, unknown>[] = [];
|
||||
const envelope = {
|
||||
@@ -262,19 +266,6 @@ export const projectProtobufCapturePage = <
|
||||
field_count: decoding.fields.length,
|
||||
}
|
||||
: source;
|
||||
const keys =
|
||||
view.fields ??
|
||||
Object.keys(row).filter(
|
||||
(key) =>
|
||||
![
|
||||
"frames",
|
||||
"fields",
|
||||
"pointer",
|
||||
"text",
|
||||
"schema_value",
|
||||
"schema_enum_values",
|
||||
].includes(key),
|
||||
);
|
||||
const projected: Record<string, unknown> = {
|
||||
record_ordinal: recordOrdinal,
|
||||
body_pointer: decoding.pointer,
|
||||
@@ -282,10 +273,11 @@ export const projectProtobufCapturePage = <
|
||||
body_status: decoding.status,
|
||||
offset_basis: decoding.offset_basis,
|
||||
};
|
||||
for (const key of keys)
|
||||
for (const key of fields ?? Object.keys(row))
|
||||
if (
|
||||
Object.hasOwn(row, key) &&
|
||||
!["frames", "fields", "pointer"].includes(key)
|
||||
!embeddedRowFields.has(key) &&
|
||||
(fields != null || !optInRowFields.has(key)) &&
|
||||
Object.hasOwn(row, key)
|
||||
)
|
||||
projected[key] = row[key];
|
||||
for (const key of mandatory)
|
||||
|
||||
Reference in New Issue
Block a user