Extract {domain, methodStr, operationName, paramsCddl} from a command/event leaf def.
(def)
| 475 | |
| 476 | /** Extract {domain, methodStr, operationName, paramsCddl} from a command/event leaf def. */ |
| 477 | function parseLeafDef(def) { |
| 478 | const flatProps = (def.Properties ?? []).flatMap((p) => (Array.isArray(p) ? p : [p])) |
| 479 | |
| 480 | const methodProp = flatProps.find((p) => p.Name === 'method') |
| 481 | const paramsProp = flatProps.find((p) => p.Name === 'params') |
| 482 | if (!methodProp || !paramsProp) return null |
| 483 | |
| 484 | const methodLiteral = Array.isArray(methodProp.Type) ? methodProp.Type : [methodProp.Type] |
| 485 | if (methodLiteral[0]?.Type !== 'literal') return null |
| 486 | |
| 487 | const methodStr = methodLiteral[0].Value // e.g. "browser.createUserContext" |
| 488 | const dotIdx = methodStr.indexOf('.') |
| 489 | if (dotIdx === -1) return null |
| 490 | |
| 491 | const domain = methodStr.slice(0, dotIdx) |
| 492 | const operationName = methodStr.slice(dotIdx + 1) |
| 493 | // A vendor leaf (tagged by tagVendorDefs) carries its namespace into the model. |
| 494 | const vendor = def['x-selenium-vendor'] |
| 495 | |
| 496 | const paramsTypeEntries = Array.isArray(paramsProp.Type) ? paramsProp.Type : [paramsProp.Type] |
| 497 | let paramsCddl = null |
| 498 | if (paramsTypeEntries[0]?.Type === 'group' && paramsTypeEntries[0]?.Value) { |
| 499 | paramsCddl = paramsTypeEntries[0].Value |
| 500 | } |
| 501 | |
| 502 | return { domain, methodStr, operationName, paramsCddl, vendor } |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * Collect all leaf command/event names from every XxxCommand / XxxEvent |
no test coverage detected