(data any, command Command, budget int)
| 595 | } |
| 596 | |
| 597 | func ApplyCommand(data any, command Command, budget int) (any, error) { |
| 598 | commandType := getCommandType(command) |
| 599 | if commandType == "" { |
| 600 | return nil, fmt.Errorf("ApplyCommand: missing type field") |
| 601 | } |
| 602 | switch commandType { |
| 603 | case SetCommandStr: |
| 604 | path := getCommandPath(command) |
| 605 | return SetPath(data, path, command["data"], &SetPathOpts{Budget: budget}) |
| 606 | case DelCommandStr: |
| 607 | path := getCommandPath(command) |
| 608 | return SetPath(data, path, nil, &SetPathOpts{Remove: true, Budget: budget}) |
| 609 | case AppendCommandStr: |
| 610 | path := getCommandPath(command) |
| 611 | return SetPath(data, path, command["data"], &SetPathOpts{CombineFn: CombineFn_ArrayAppend, Budget: budget}) |
| 612 | default: |
| 613 | return nil, fmt.Errorf("ApplyCommand: unknown command type %q", commandType) |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | func ApplyCommands(data any, commands []Command, budget int) (any, error) { |
| 618 | for _, command := range commands { |
no test coverage detected