mirror of
https://github.com/morluto/rea
synced 2026-10-29 15:20:44 -04:00
refactor(javascript): use shared canonical identity primitives
This commit is contained in:
@@ -1,18 +1,9 @@
|
||||
import canonicalize from "canonicalize";
|
||||
import { canonicalJson } from "../comparisonSemantics.js";
|
||||
import {
|
||||
javaScriptSemanticGraphSchema,
|
||||
type JavaScriptSemanticGraph,
|
||||
} from "./javascriptSemanticGraph.js";
|
||||
|
||||
const canonicalJson = (value: unknown): string => {
|
||||
const encoded = canonicalize(value);
|
||||
if (encoded === undefined)
|
||||
throw new TypeError(
|
||||
"JavaScript semantic graph could not canonicalize data",
|
||||
);
|
||||
return encoded;
|
||||
};
|
||||
|
||||
/** Parse a stored semantic graph and reject stale IDs. */
|
||||
export const parseJavaScriptSemanticGraph = (
|
||||
input: unknown,
|
||||
@@ -20,4 +11,7 @@ export const parseJavaScriptSemanticGraph = (
|
||||
|
||||
/** Serialize a verified semantic graph as canonical JSON. */
|
||||
export const serializeJavaScriptSemanticGraph = (input: unknown): string =>
|
||||
canonicalJson(parseJavaScriptSemanticGraph(input));
|
||||
canonicalJson(
|
||||
parseJavaScriptSemanticGraph(input),
|
||||
"JavaScript semantic graph",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user