* @param {Map } customCommands * A map of custom command definitions. * @param {!cmd.Command} command The command to resolve. * @return {!Request} A promise that will resolve with the * command to execute.
(customCommands, command)
| 361 | * command to execute. |
| 362 | */ |
| 363 | function buildRequest(customCommands, command) { |
| 364 | log_.finest(() => `Translating command: ${command.getName()}`) |
| 365 | let spec = customCommands && customCommands.get(command.getName()) |
| 366 | if (spec) { |
| 367 | return toHttpRequest(spec) |
| 368 | } |
| 369 | |
| 370 | spec = W3C_COMMAND_MAP.get(command.getName()) |
| 371 | if (typeof spec === 'function') { |
| 372 | log_.finest(() => `Transforming command for W3C: ${command.getName()}`) |
| 373 | let newCommand = spec(command) |
| 374 | return buildRequest(customCommands, newCommand) |
| 375 | } else if (spec) { |
| 376 | return toHttpRequest(spec) |
| 377 | } |
| 378 | throw new error.UnknownCommandError('Unrecognized command: ' + command.getName()) |
| 379 | |
| 380 | /** |
| 381 | * @param {CommandSpec} resource |
| 382 | * @return {!Request} |
| 383 | */ |
| 384 | function toHttpRequest(resource) { |
| 385 | log_.finest(() => `Building HTTP request: ${JSON.stringify(resource)}`) |
| 386 | let parameters = command.getParameters() |
| 387 | let path = buildPath(resource.path, parameters) |
| 388 | return new Request(resource.method, path, parameters) |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | const CLIENTS = /** !WeakMap<!Executor, !(Client|IThenable<!Client>)> */ new WeakMap() |
| 393 |
no test coverage detected