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

Function buildModel

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

* Build the binding-neutral model from the AST. Type refs are CDDL names. * Shape per domain key: * { commands: [{ method, name, params, result }], * events: [{ method, name, params }] } * `params`/`result` are null when there are no params / no return value.

(ast)

Source from the content-addressed store, hash-verified

575 * `params`/`result` are null when there are no params / no return value.
576 */
577function buildModel(ast) {
578 const model = {}
579 const resultTypes = buildResultTypeNames(ast)
580 const ensure = (domain) => (model[domain] ??= { commands: [], events: [] })
581
582 // A vendor entry carries its namespace so the schema projector can file it under
583 // `vendor.<namespace>`; spec entries carry none, so a vendor-free AST yields the same model.
584 const provenance = (entry) => (entry.vendor ? { vendor: entry.vendor } : {})
585
586 for (const c of extractCommands(ast)) {
587 const result = c.cddlName + 'Result'
588 ensure(c.domain).commands.push({
589 method: c.methodStr,
590 name: c.methodName,
591 params: c.hasParams ? c.paramsCddl : null,
592 result: resultTypes.has(result) ? result : null,
593 ...provenance(c),
594 })
595 }
596
597 for (const e of extractEvents(ast)) {
598 ensure(e.domain).events.push({
599 method: e.methodStr,
600 name: e.eventName,
601 params: e.paramsCddl || null,
602 ...provenance(e),
603 })
604 }
605
606 return model
607}
608
609/** Result type names the spec defines with a value; an absent or `EmptyResult`-aliased result is void. */
610function buildResultTypeNames(ast) {

Callers 1

mainFunction · 0.85

Calls 6

buildResultTypeNamesFunction · 0.85
extractCommandsFunction · 0.85
ensureFunction · 0.85
provenanceFunction · 0.85
extractEventsFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected