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

Function buildVendorModules

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

* The vendor variants of one spec domain, one per namespace (`moz` → `MozWebExtension`), each a * subclass of the shared domain class, so the shared class never sends a vendor field or command * (received vendor fields are folded into the shared types by foldVendorExtensions). Mirrors * Ruby's ge

(schema, domain, parentClassName, specCommands)

Source from the content-addressed store, hash-verified

683 * types: Object<string, object>, commands: Array<object>}>}
684 */
685function buildVendorModules(schema, domain, parentClassName, specCommands) {
686 const vendorTypes = Object.assign({}, ...Object.values(schema.vendor ?? {}).map((s) => s.types ?? {}))
687
688 return Object.entries(schema.vendor ?? {}).flatMap(([namespace, section]) => {
689 const stray = (section.events ?? []).find((e) => e.domain === domain)
690 if (stray) {
691 throw new Error(`vendor event ${stray.method} in spec domain ${domain} is unsupported`)
692 }
693
694 const types = {}
695 const commands = []
696
697 for (const [typeName, entry] of Object.entries(section.extends ?? {})) {
698 const cmd = schema.commands.find((c) => c.params?.ref === typeName)
699 if (!cmd || cmd.domain !== domain) continue
700 const base = schema.types[typeName]
701 const taken = new Set(base.fields.map((f) => f.name))
702 const vendorFields = entry.fields.map((f) => ({ ...f, name: vendorFieldName(f.name, namespace, taken) }))
703 const vendorTypeName = vendorExtendedTypeName(namespace, typeName)
704 types[vendorTypeName] = { ...base, fields: [...base.fields, ...vendorFields] }
705 commands.push({ ...schemaToCommand(cmd), paramsTypeName: normalizeDottedName(vendorTypeName) })
706 }
707
708 const specNames = new Set(specCommands.map((c) => c.methodName))
709 for (const cmd of (section.commands ?? []).filter((c) => c.domain === domain)) {
710 const methodName = cmd.name.replace(`${namespace}:`, '')
711 if (specNames.has(methodName)) {
712 throw new Error(`vendor command ${cmd.method} would override spec command ${domain}.${methodName}`)
713 }
714 commands.push({ ...schemaToCommand(cmd), methodName, specUrl: null })
715 for (const ref of [cmd.params?.ref, cmd.result?.ref].filter(Boolean)) {
716 collectVendorTypes(ref, vendorTypes, types)
717 }
718 }
719
720 if (commands.length === 0) return []
721 return [{ namespace, className: `${pascalCase(namespace)}${parentClassName}`, parentClassName, types, commands }]
722 })
723}
724
725/**
726 * Folds each vendor's fields into the spec types it extends. ADR 17786 counts a supported vendor's

Callers 1

generateTypeScriptFunction · 0.85

Calls 13

vendorFieldNameFunction · 0.85
vendorExtendedTypeNameFunction · 0.85
schemaToCommandFunction · 0.85
normalizeDottedNameFunction · 0.85
collectVendorTypesFunction · 0.85
pascalCaseFunction · 0.85
valuesMethod · 0.80
entriesMethod · 0.80
findMethod · 0.80
pushMethod · 0.80
filterMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected