( input: unknown, operations: StateJsonUpdateOperation[], filePath: string )
| 50 | } |
| 51 | |
| 52 | export function updateJsonValue( |
| 53 | input: unknown, |
| 54 | operations: StateJsonUpdateOperation[], |
| 55 | filePath: string |
| 56 | ): StateJsonUpdateResult { |
| 57 | const clone = structuredClone(input) as unknown; |
| 58 | for (const operation of operations) { |
| 59 | const tokens = parseJsonPath(operation.path); |
| 60 | if (operation.op === "set") { |
| 61 | setJsonPathValue(clone, tokens, operation.value); |
| 62 | } else { |
| 63 | deleteJsonPathValue(clone, tokens); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | const content = JSON.stringify(clone, null, 2) + "\n"; |
| 68 | return { |
| 69 | value: clone, |
| 70 | content, |
| 71 | diff: |
| 72 | JSON.stringify(input) === JSON.stringify(clone) |
| 73 | ? "" |
| 74 | : diffContent( |
| 75 | JSON.stringify(input, null, 2) + "\n", |
| 76 | content, |
| 77 | filePath, |
| 78 | filePath |
| 79 | ), |
| 80 | operationsApplied: operations.length |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | export async function buildTree( |
| 85 | root: string, |
no test coverage detected