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:
@@ -1,6 +1,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,
|
||||
@@ -450,6 +451,30 @@ export const createJavaScriptApplicationGraph = (
|
||||
});
|
||||
};
|
||||
|
||||
const validatedImmutableApplicationGraphs = new WeakSet<object>();
|
||||
|
||||
/** Clone and validate synchronously, then return steps to seal the owned graph. */
|
||||
export const createImmutableJavaScriptApplicationGraphSteps = (
|
||||
input: unknown,
|
||||
): Generator<void, JavaScriptApplicationGraph> =>
|
||||
sealValidatedApplicationGraphSteps(createJavaScriptApplicationGraph(input));
|
||||
|
||||
function* sealValidatedApplicationGraphSteps(
|
||||
graph: JavaScriptApplicationGraph,
|
||||
): Generator<void, JavaScriptApplicationGraph> {
|
||||
yield* freezeOwnedJsonSnapshotSteps(graph);
|
||||
validatedImmutableApplicationGraphs.add(graph);
|
||||
return graph;
|
||||
}
|
||||
|
||||
/** Recognize the exact completely sealed graph produced by the owned factory. */
|
||||
export const isValidatedImmutableJavaScriptApplicationGraph = (
|
||||
value: unknown,
|
||||
): value is JavaScriptApplicationGraph =>
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
validatedImmutableApplicationGraphs.has(value);
|
||||
|
||||
/** Parse a stored graph and reject stale IDs. */
|
||||
export const parseJavaScriptApplicationGraph = (
|
||||
input: unknown,
|
||||
|
||||
Reference in New Issue
Block a user