MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / parseLeafDef

Function parseLeafDef

javascript/selenium-webdriver/generate_bidi.mjs:454–480  ·  view source on GitHub ↗

Extract {domain, methodStr, operationName, paramsCddl} from a command/event leaf def.

(def)

Source from the content-addressed store, hash-verified

452
453/** Extract {domain, methodStr, operationName, paramsCddl} from a command/event leaf def. */
454function 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

Callers 2

extractCommandsFunction · 0.85
extractEventsFunction · 0.85

Calls 1

findMethod · 0.80

Tested by

no test coverage detected