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

Function projectSchema

javascript/selenium-webdriver/project_bidi_schema.mjs:677–792  ·  view source on GitHub ↗
(ast, model, links = {}, vendorModel = null)

Source from the content-addressed store, hash-verified

675 * @returns {{schemaVersion: number, generatedBy: string, regenerateWith: string, commands: object[], events: object[], types: object, domains: object, vendor?: object}} The schema.
676 */
677export function projectSchema(ast, model, links = {}, vendorModel = null) {
678 const types = {}
679 for (const def of normalizeAst(ast)) {
680 if (!def?.Name) continue
681 const node = projectType(def)
682 // Types the normalizer minted for anonymous CDDL constructs (hoisted enums /
683 // inline records, union arms) carry their decomposition so a binding can name
684 // or nest them idiomatically without parsing the synthetic key. `owner` is the
685 // type the construct was lifted out of; `label` is the member name within it.
686 if (def['x-selenium-synthetic']) {
687 node.synthetic = true
688 node.owner = def['x-selenium-owner']
689 node.label = def['x-selenium-label']
690 }
691 // A vendor's own type (generate_bidi.mjs tags the def). Carried on the node only until
692 // extractVendor routes it into the `vendor` section.
693 if (def['x-selenium-vendor']) node.vendor = def['x-selenium-vendor']
694 // Link to the type's definition in the live spec, when the index covers it —
695 // the readable prose section where one exists, else the CDDL production.
696 // Synthetic types have no spec definition and are (correctly) never in it.
697 const typeHref = links.types?.[def.Name.toLowerCase()]
698 if (typeHref) node.specHref = typeHref
699 types[def.Name] = node
700 }
701 for (const [name, node] of Object.entries(types))
702 if (node.kind === 'union') node.selector = unionSelector(name, types)
703 // Override the result-grouping unions: they are dispatched by request id, so a
704 // payload selector for them is meaningless (and would be empty/ambiguous).
705 for (const name of correlatedUnions(types)) types[name].selector = { correlated: true }
706 // A first-class union whose every arm is an object rejects a non-object payload
707 // instead of passing it through. (An alias-union like input.Origin, which carries
708 // bare-string arms, is intentionally left unflagged so those arms still pass through.)
709 for (const node of Object.values(types))
710 if (node.kind === 'union' && node.variants.every((v) => variantIsObject(v, types))) node.objectOnly = true
711
712 const envelopeParams = commandEnvelopeParams(types)
713 // Commands and events link to their own prose section (`#command-*` / `#event-*`),
714 // keyed by the wire method; domains to their `#module-*` section. Present-only-when-known.
715 const link = (map, key) => (typeof key === 'string' ? map?.[key.toLowerCase()] : undefined)
716 const projectMessages = (modelEntries) => {
717 const commands = []
718 const events = []
719 for (const [domain, entry] of modelEntries) {
720 for (const c of entry.commands ?? []) {
721 const cmd = {
722 domain,
723 method: c.method,
724 name: c.name,
725 // Prefer the envelope's params (it captures inline params the model drops).
726 params: typeRef(envelopeParams.get(c.method) ?? c.params),
727 result: typeRef(c.result),
728 }
729 const href = link(links.commands, c.method)
730 if (href) cmd.specHref = href
731 if (c.vendor) cmd.vendor = c.vendor
732 commands.push(cmd)
733 }
734 for (const e of entry.events ?? []) {

Callers 4

fieldTypeFunction · 0.90
generateTypeScriptFunction · 0.90
mainFunction · 0.85

Calls 15

normalizeAstFunction · 0.90
projectTypeFunction · 0.85
unionSelectorFunction · 0.85
correlatedUnionsFunction · 0.85
variantIsObjectFunction · 0.85
commandEnvelopeParamsFunction · 0.85
projectMessagesFunction · 0.85
vendorModelEntriesFunction · 0.85
reachableTypesFunction · 0.85
linkFunction · 0.85
extractVendorFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected