(data: any, command: any)
| 220 | } |
| 221 | |
| 222 | function applyCommand(data: any, command: any): any { |
| 223 | if (command == null) { |
| 224 | throw new Error("Invalid command (null)"); |
| 225 | } |
| 226 | if (!isObject(command)) { |
| 227 | throw new Error("Invalid command (not an object): " + command); |
| 228 | } |
| 229 | const commandType = command.type; |
| 230 | if (commandType == null) { |
| 231 | throw new Error("Invalid command (no type): " + command); |
| 232 | } |
| 233 | const path = getCommandPath(command); |
| 234 | if (!checkPath(path)) { |
| 235 | throw new Error("Invalid command path: " + formatPath(path)); |
| 236 | } |
| 237 | switch (commandType) { |
| 238 | case "set": |
| 239 | return setPath(data, path, command.value, null); |
| 240 | |
| 241 | case "del": |
| 242 | return setPath(data, path, null, { remove: true }); |
| 243 | |
| 244 | case "append": |
| 245 | return setPath(data, path, command.value, { combinefn: combineFn_arrayAppend }); |
| 246 | |
| 247 | default: |
| 248 | throw new Error("Invalid command type: " + commandType); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | export { applyCommand, combineFn_arrayAppend, getPath, setPath }; |
| 253 | export type { PathType, SetPathOpts }; |
nothing calls this directly
no test coverage detected