MCPcopy Index your code
hub / github.com/simstudioai/sim / navigatePath

Function navigatePath

apps/sim/executor/variables/resolvers/reference.ts:128–201  ·  view source on GitHub ↗
(
  obj: any,
  path: string[],
  options: { allowLargeValueRefs?: boolean; executionContext?: ExecutionContext } = {}
)

Source from the content-addressed store, hash-verified

126 * navigatePath({items: [{name: 'test'}]}, ['items', '0', 'name']) => 'test'
127 */
128export function navigatePath(
129 obj: any,
130 path: string[],
131 options: { allowLargeValueRefs?: boolean; executionContext?: ExecutionContext } = {}
132): any {
133 let current = obj
134 for (const part of path) {
135 if (isLargeValueRef(current)) {
136 current = materializeLargeValueRefSyncOrThrow(current, options.executionContext)
137 }
138
139 if (current === null || current === undefined) {
140 return undefined
141 }
142
143 if (isLargeArrayManifest(current)) {
144 current = navigateManifestMetadataOrIndexSync(current, part, options.executionContext)
145 continue
146 }
147
148 const arrayMatch = part.match(/^([^[]+)(\[.+)$/)
149 if (arrayMatch) {
150 const [, prop, bracketsPart] = arrayMatch
151 current =
152 typeof current === 'object' && current !== null
153 ? (current as Record<string, unknown>)[prop]
154 : undefined
155 if (isLargeValueRef(current)) {
156 current = materializeLargeValueRefSyncOrThrow(current, options.executionContext)
157 }
158 if (current === undefined || current === null) {
159 return undefined
160 }
161
162 const indices = bracketsPart.match(/\[(\d+)\]/g)
163 if (indices) {
164 for (const indexMatch of indices) {
165 if (current === null || current === undefined) {
166 return undefined
167 }
168 if (isLargeValueRef(current)) {
169 current = materializeLargeValueRefSyncOrThrow(current, options.executionContext)
170 }
171 if (isLargeArrayManifest(current)) {
172 current = navigateManifestMetadataOrIndexSync(
173 current,
174 indexMatch.slice(1, -1),
175 options.executionContext
176 )
177 continue
178 }
179 const idx = Number.parseInt(indexMatch.slice(1, -1), 10)
180 current = Array.isArray(current) ? current[idx] : undefined
181 }
182 }
183 } else if (/^\d+$/.test(part)) {
184 const index = Number.parseInt(part, 10)
185 current = isLargeArrayManifest(current)

Callers 12

PreviewEditorContentFunction · 0.90
resolveBlockReferenceFunction · 0.90
resolveInternalMethod · 0.90
resolveOutputMethod · 0.90
resolveOutputAsyncMethod · 0.90
resolveMethod · 0.90
resolveAsyncMethod · 0.90
resolveInternalMethod · 0.90
resolveOutputMethod · 0.90
resolveOutputAsyncMethod · 0.90
reference.test.tsFile · 0.90

Calls 7

isLargeValueRefFunction · 0.90
isLargeArrayManifestFunction · 0.90
assertNoLargeValueRefsFunction · 0.90
readManifestIndexSyncFunction · 0.85
testMethod · 0.80

Tested by

no test coverage detected