Extract {domain, methodStr, operationName, paramsCddl} from a command/event leaf def.
(def)
| 452 | |
| 453 | /** Extract {domain, methodStr, operationName, paramsCddl} from a command/event leaf def. */ |
| 454 | function parseLeafDef(def) { |
| 455 | const flatProps = (def.Properties ?? []).flatMap((p) => (Array.isArray(p) ? p : [p])) |
| 456 | |
| 457 | const methodProp = flatProps.find((p) => p.Name === 'method') |
| 458 | const paramsProp = flatProps.find((p) => p.Name === 'params') |
| 459 | if (!methodProp || !paramsProp) return null |
| 460 | |
| 461 | const methodLiteral = Array.isArray(methodProp.Type) ? methodProp.Type : [methodProp.Type] |
| 462 | if (methodLiteral[0]?.Type !== 'literal') return null |
| 463 | |
| 464 | const methodStr = methodLiteral[0].Value // e.g. "browser.createUserContext" |
| 465 | const dotIdx = methodStr.indexOf('.') |
| 466 | if (dotIdx === -1) return null |
| 467 | |
| 468 | const domain = methodStr.slice(0, dotIdx) |
| 469 | const operationName = methodStr.slice(dotIdx + 1) |
| 470 | // A vendor leaf (tagged by tagVendorDefs) carries its namespace into the model. |
| 471 | const vendor = def['x-selenium-vendor'] |
| 472 | |
| 473 | const paramsTypeEntries = Array.isArray(paramsProp.Type) ? paramsProp.Type : [paramsProp.Type] |
| 474 | let paramsCddl = null |
| 475 | if (paramsTypeEntries[0]?.Type === 'group' && paramsTypeEntries[0]?.Value) { |
| 476 | paramsCddl = paramsTypeEntries[0].Value |
| 477 | } |
| 478 | |
| 479 | return { domain, methodStr, operationName, paramsCddl, vendor } |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Collect all leaf command/event names from every XxxCommand / XxxEvent |
no test coverage detected