mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
perf(javascript): reuse validated immutable graphs (#1112)
* perf(javascript): reuse validated immutable graphs * fix(ci): follow the moved process CLI boundary test
This commit is contained in:
@@ -2,6 +2,7 @@ import { z } from "zod";
|
||||
|
||||
import { canonicalDigest, canonicalJson } from "../comparisonSemantics.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { freezeOwnedJsonSnapshotSteps } from "../immutableJson.js";
|
||||
import type { ApplicationGraphEvidence } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import {
|
||||
JAVASCRIPT_SEMANTIC_RELATION_FAMILIES,
|
||||
@@ -561,4 +562,28 @@ export const createJavaScriptSemanticGraph = (
|
||||
return record;
|
||||
};
|
||||
|
||||
const validatedImmutableSemanticGraphs = new WeakSet<object>();
|
||||
|
||||
/** Clone and validate synchronously, then return steps to seal the owned graph. */
|
||||
export const createImmutableJavaScriptSemanticGraphSteps = (
|
||||
input: unknown,
|
||||
): Generator<void, JavaScriptSemanticGraph> =>
|
||||
sealValidatedSemanticGraphSteps(createJavaScriptSemanticGraph(input));
|
||||
|
||||
function* sealValidatedSemanticGraphSteps(
|
||||
graph: JavaScriptSemanticGraph,
|
||||
): Generator<void, JavaScriptSemanticGraph> {
|
||||
yield* freezeOwnedJsonSnapshotSteps(graph);
|
||||
validatedImmutableSemanticGraphs.add(graph);
|
||||
return graph;
|
||||
}
|
||||
|
||||
/** Recognize the exact completely sealed graph produced by the owned factory. */
|
||||
export const isValidatedImmutableJavaScriptSemanticGraph = (
|
||||
value: unknown,
|
||||
): value is JavaScriptSemanticGraph =>
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
validatedImmutableSemanticGraphs.has(value);
|
||||
|
||||
export type { JavaScriptSemanticGraphNode, JavaScriptSemanticGraphRelation };
|
||||
|
||||
Reference in New Issue
Block a user