MCPcopy Create free account
hub / github.com/Kong/insomnia / getKeySource

Function getKeySource

packages/insomnia/src/common/render.ts:56–87  ·  view source on GitHub ↗
(
  subObject: string | Record<string, any>,
  inKey: string,
  meta: VariableSourceMeta,
  keySource: Record<string, string>,
  keySourceMeta: Record<string, VariableSourceMeta>,
)

Source from the content-addressed store, hash-verified

54
55// Function that gets Keys and stores their Source location
56function getKeySource(
57 subObject: string | Record<string, any>,
58 inKey: string,
59 meta: VariableSourceMeta,
60 keySource: Record<string, string>,
61 keySourceMeta: Record<string, VariableSourceMeta>,
62) {
63 // Add key to map if it's not root
64 if (inKey) {
65 const normalizedKey = templatingUtils.normalizeToDotAndBracketNotation(inKey);
66 // The label doubles as the keySource entry the "Template tags show variable source and value"
67 // setting renders. Transient sources (runner upload data, script-local
68 // variables) carry no workspaceId, so overwriting an environment's metadata
69 // with one of these keeps consumers honest without becoming navigable.
70 keySource[normalizedKey] = meta.label;
71 keySourceMeta[normalizedKey] = meta;
72 }
73
74 // Recurse down for Objects and Arrays
75 const typeStr = Object.prototype.toString.call(subObject);
76
77 if (typeStr === '[object Object]') {
78 for (const key of Object.keys(subObject)) {
79 // @ts-expect-error -- mapping unsoundness
80 getKeySource(subObject[key], templatingUtils.forceBracketNotation(inKey, key), meta, keySource, keySourceMeta);
81 }
82 } else if (typeStr === '[object Array]' && Array.isArray(subObject)) {
83 for (const [i, element] of subObject.entries()) {
84 getKeySource(element, templatingUtils.forceBracketNotation(inKey, i), meta, keySource, keySourceMeta);
85 }
86 }
87}
88
89interface EnvironmentRenderLayer {
90 data: Record<string, any>;

Callers 1

buildRenderContextFunction · 0.85

Calls 1

keysMethod · 0.65

Tested by

no test coverage detected