MCPcopy
hub / github.com/flightcontrolhq/superjson / applyReferentialEqualityAnnotations

Function applyReferentialEqualityAnnotations

src/plainer.ts:81–115  ·  view source on GitHub ↗
(
  plain: any,
  annotations: ReferentialEqualityAnnotations,
  version: number
)

Source from the content-addressed store, hash-verified

79}
80
81export function applyReferentialEqualityAnnotations(
82 plain: any,
83 annotations: ReferentialEqualityAnnotations,
84 version: number
85) {
86 const legacyPaths = enableLegacyPaths(version);
87 function apply(identicalPaths: string[], path: string) {
88 const object = getDeep(plain, parsePath(path, legacyPaths));
89
90 identicalPaths
91 .map(path => parsePath(path, legacyPaths))
92 .forEach(identicalObjectPath => {
93 plain = setDeep(plain, identicalObjectPath, () => object);
94 });
95 }
96
97 if (isArray(annotations)) {
98 const [root, other] = annotations;
99 root.forEach(identicalPath => {
100 plain = setDeep(
101 plain,
102 parsePath(identicalPath, legacyPaths),
103 () => plain
104 );
105 });
106
107 if (other) {
108 forEach(other, apply);
109 }
110 } else {
111 forEach(annotations, apply);
112 }
113
114 return plain;
115}
116
117const isDeep = (object: any, superJson: SuperJSON): boolean =>
118 isPlainObject(object) ||

Callers 1

deserializeMethod · 0.85

Calls 5

enableLegacyPathsFunction · 0.85
isArrayFunction · 0.85
setDeepFunction · 0.85
parsePathFunction · 0.85
forEachFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…