mirror of
https://github.com/morluto/rea.git
synced 2026-10-27 09:55:46 +00:00
fix(javascript): retain shorter literal metadata encodings (#1408)
Choose the shorter complete JSON or digest key and string display label. Short values keep their existing identities and labels, while large values retain the payload-copy reduction without an arbitrary truncation limit.
This commit is contained in:
1 parent
8550913cda
commit
de8fc67195
2 files changed
+23
-12
No files matched your search
@@ -154,18 +154,27 @@ const addLiteralNode = (
|
||||
binding: JavaScriptSemanticBinding,
|
||||
value: string | number | boolean | null,
|
||||
role: string,
|
||||
) =>
|
||||
retainSemanticGraphNode(context.state, context.file, {
|
||||
) => {
|
||||
const encodedValue = JSON.stringify(value);
|
||||
const valueDigest = `value-sha256:${digestCanonicalValue(value, "Semantic literal")}`;
|
||||
const valueKey =
|
||||
encodedValue.length <= valueDigest.length ? encodedValue : valueDigest;
|
||||
const stringLabel = "string literal";
|
||||
return retainSemanticGraphNode(context.state, context.file, {
|
||||
kind: "literal",
|
||||
// Identity needs an exact value commitment, not another payload copy.
|
||||
// Keep the complete literal in properties for queries and Evidence export.
|
||||
roleKey: `literal:${binding.bindingId}:${role}:value-sha256:${digestCanonicalValue(value, "Semantic literal")}`,
|
||||
roleKey: `literal:${binding.bindingId}:${role}:${valueKey}`,
|
||||
location: binding.definitions[0]?.location ?? null,
|
||||
label: typeof value === "string" ? "string literal" : JSON.stringify(value),
|
||||
label:
|
||||
typeof value === "string" && encodedValue.length > stringLabel.length
|
||||
? stringLabel
|
||||
: encodedValue,
|
||||
functionNodeId:
|
||||
context.bindingNodes.get(binding.bindingId)?.function_node_id ?? null,
|
||||
properties: { value },
|
||||
});
|
||||
};
|
||||
|
||||
/** Create one canonical slot for a root binding and exact static property path. */
|
||||
export const semanticPropertySlot = (
|
||||
|
||||
Reference in new issue
Block a user