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

Function parseLeafDef

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

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

(def)

Source from the content-addressed store, hash-verified

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

Callers 2

extractCommandsFunction · 0.85
extractEventsFunction · 0.85

Calls 1

findMethod · 0.80

Tested by

no test coverage detected