Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

command.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const logger_1 = __importDefault(require("@wdio/logger"));
  7. const utils_1 = require("@wdio/utils");
  8. const request_1 = __importDefault(require("./request"));
  9. const log = logger_1.default('webdriver');
  10. function default_1(method, endpointUri, commandInfo, doubleEncodeVariables = false) {
  11. const { command, ref, parameters, variables = [], isHubCommand = false } = commandInfo;
  12. return function protocolCommand(...args) {
  13. let endpoint = endpointUri;
  14. const commandParams = [...variables.map((v) => Object.assign(v, {
  15. required: true,
  16. type: 'string'
  17. })), ...parameters];
  18. const commandUsage = `${command}(${commandParams.map((p) => p.name).join(', ')})`;
  19. const moreInfo = `\n\nFor more info see ${ref}\n`;
  20. const body = {};
  21. const minAllowedParams = commandParams.filter((param) => param.required).length;
  22. if (args.length < minAllowedParams || args.length > commandParams.length) {
  23. const parameterDescription = commandParams.length
  24. ? `\n\nProperty Description:\n${commandParams.map((p) => ` "${p.name}" (${p.type}): ${p.description}`).join('\n')}`
  25. : '';
  26. throw new Error(`Wrong parameters applied for ${command}\n` +
  27. `Usage: ${commandUsage}` +
  28. parameterDescription +
  29. moreInfo);
  30. }
  31. for (const [it, arg] of Object.entries(args)) {
  32. const i = parseInt(it, 10);
  33. const commandParam = commandParams[i];
  34. if (!utils_1.isValidParameter(arg, commandParam.type)) {
  35. if (typeof arg === 'undefined' && !commandParam.required) {
  36. continue;
  37. }
  38. const actual = commandParam.type.endsWith('[]')
  39. ? `(${(Array.isArray(arg) ? arg : [arg]).map((a) => utils_1.getArgumentType(a))})[]`
  40. : utils_1.getArgumentType(arg);
  41. throw new Error(`Malformed type for "${commandParam.name}" parameter of command ${command}\n` +
  42. `Expected: ${commandParam.type}\n` +
  43. `Actual: ${actual}` +
  44. moreInfo);
  45. }
  46. if (i < variables.length) {
  47. const encodedArg = doubleEncodeVariables ? encodeURIComponent(encodeURIComponent(arg)) : encodeURIComponent(arg);
  48. endpoint = endpoint.replace(`:${commandParams[i].name}`, encodedArg);
  49. continue;
  50. }
  51. body[commandParams[i].name] = arg;
  52. }
  53. const request = new request_1.default(method, endpoint, body, isHubCommand);
  54. this.emit('command', { method, endpoint, body });
  55. log.info('COMMAND', utils_1.commandCallStructure(command, args));
  56. return request.makeRequest(this.options, this.sessionId).then((result) => {
  57. if (result.value != null) {
  58. log.info('RESULT', /screenshot|recording/i.test(command)
  59. && typeof result.value === 'string' && result.value.length > 64
  60. ? `${result.value.substr(0, 61)}...` : result.value);
  61. }
  62. this.emit('result', { method, endpoint, body, result });
  63. if (command === 'deleteSession') {
  64. logger_1.default.clearLogger();
  65. }
  66. return result.value;
  67. });
  68. };
  69. }
  70. exports.default = default_1;