* Find a block index by ID or ID prefix. Returns -1 if not found.
(blocks: DeepnoteBlock[], idOrPrefix: string)
| 26 | * Find a block index by ID or ID prefix. Returns -1 if not found. |
| 27 | */ |
| 28 | function findBlockIndex(blocks: DeepnoteBlock[], idOrPrefix: string): number { |
| 29 | const matches = blocks |
| 30 | .map((block, index) => ({ block, index })) |
| 31 | .filter(({ block }) => block.id === idOrPrefix || block.id.startsWith(idOrPrefix)) |
| 32 | if (matches.length > 1) { |
| 33 | throw new Error(`Ambiguous block ID prefix "${idOrPrefix}" matches multiple blocks`) |
| 34 | } |
| 35 | return matches.length === 1 ? matches[0].index : -1 |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Resolve a block ID or prefix to the full block ID. Returns undefined if not found. |
no outgoing calls
no test coverage detected