mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
Classify legacy class-object names at the Hopper boundary and carry the typed fact into class discovery. Preserve exact labels, literal filtering, unrelated row metadata, and raw replies; derive classification from source text rather than incoming tags. Closes #5617
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import type { JsonValue } from "../domain/jsonValue.js";
|
|
import { z } from "zod";
|
|
|
|
const LEGACY_OBJC_CLASS_LABEL_PREFIX = "__objc_class_";
|
|
const LEGACY_OBJC_CLASS_LABEL_SUFFIX = "_class";
|
|
const addressedNameRowsSchema = z.array(
|
|
z.object({ address: z.string(), value: z.string() }),
|
|
);
|
|
|
|
const isLegacyObjcClassObjectLabel = (value: string): boolean =>
|
|
value.startsWith(LEGACY_OBJC_CLASS_LABEL_PREFIX) &&
|
|
value.endsWith(LEGACY_OBJC_CLASS_LABEL_SUFFIX) &&
|
|
value.length >
|
|
LEGACY_OBJC_CLASS_LABEL_PREFIX.length +
|
|
LEGACY_OBJC_CLASS_LABEL_SUFFIX.length;
|
|
|
|
/** Tag Hopper's stripped class-object labels while retaining their exact text. */
|
|
export const projectHopperNameInventory = (
|
|
value: JsonValue,
|
|
): { readonly result: JsonValue; readonly changed: boolean } => {
|
|
const parsed = addressedNameRowsSchema.safeParse(value);
|
|
if (!parsed.success) return { result: value, changed: false };
|
|
|
|
let changed = false;
|
|
if (!Array.isArray(value)) return { result: value, changed: false };
|
|
const result = value.map((entry, index) => {
|
|
if (entry === null || Array.isArray(entry) || typeof entry !== "object")
|
|
return entry;
|
|
const parsedEntry = parsed.data[index];
|
|
if (parsedEntry === undefined) return entry;
|
|
const { objc_class_label: _untrustedLabel, ...sourceFields } = entry;
|
|
const ownsLegacyLabel = isLegacyObjcClassObjectLabel(parsedEntry.value);
|
|
if (ownsLegacyLabel) {
|
|
changed = true;
|
|
return {
|
|
...sourceFields,
|
|
objc_class_label: "hopper_legacy_class_object" as const,
|
|
};
|
|
}
|
|
if (_untrustedLabel !== undefined) {
|
|
changed = true;
|
|
return sourceFields;
|
|
}
|
|
return entry;
|
|
});
|
|
return changed ? { result, changed } : { result: value, changed: false };
|
|
};
|