MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / applyCommand

Function applyCommand

frontend/util/ijson.ts:222–250  ·  view source on GitHub ↗
(data: any, command: any)

Source from the content-addressed store, hash-verified

220}
221
222function 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
252export { applyCommand, combineFn_arrayAppend, getPath, setPath };
253export type { PathType, SetPathOpts };

Callers

nothing calls this directly

Calls 5

checkPathFunction · 0.85
formatPathFunction · 0.85
setPathFunction · 0.85
isObjectFunction · 0.70
getCommandPathFunction · 0.70

Tested by

no test coverage detected