(
obj: any,
path: string[],
options: { allowLargeValueRefs?: boolean; executionContext?: ExecutionContext } = {}
)
| 126 | * navigatePath({items: [{name: 'test'}]}, ['items', '0', 'name']) => 'test' |
| 127 | */ |
| 128 | export 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) |
no test coverage detected