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

Function getKeySource

packages/insomnia/src/common/render.ts:55–86  ·  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

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

Callers 1

buildRenderContextFunction · 0.85

Calls 1

keysMethod · 0.65

Tested by

no test coverage detected