MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / findAndReplaceID

Function findAndReplaceID

lib/edge-runtime/apiResponseSimplification.ts:26–50  ·  view source on GitHub ↗
(json: Json | Json[])

Source from the content-addressed store, hash-verified

24 let idIdx = Object.entries(store).length;
25
26 function findAndReplaceID(json: Json | Json[]) {
27 if (!json || typeof json !== "object") return;
28
29 // Creates the same iterator for both arrays and objects
30 const entries = Array.isArray(json)
31 ? json.entries()
32 : Object.entries(json as { [key: string]: Json });
33
34 for (const [key, value] of entries) {
35 const k = key as string;
36 if (typeof value === "object") {
37 findAndReplaceID(value);
38 } else if (typeof value === "string") {
39 if (value.includes("/")) {
40 // If string is a path, operate on individual segments
41 const urlParts = value
42 .split("/")
43 .map((part) => (isID(part) ? getOrGenerateID(part) : part));
44 (json as any)[k] = urlParts.join("/");
45 } else if (isID(value)) {
46 (json as any)[k] = getOrGenerateID(value);
47 }
48 }
49 }
50 }
51
52 function getOrGenerateID(value: string): string {
53 let id = store[value];

Callers 2

removeIdsFromObjsFunction · 0.85
repopulateVariablesFunction · 0.85

Calls 2

isIDFunction · 0.90
getOrGenerateIDFunction · 0.85

Tested by

no test coverage detected