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

Function extractVendor

javascript/selenium-webdriver/project_bidi_schema.mjs:805–840  ·  view source on GitHub ↗

* Move everything vendor-tagged out of the shared `types` into the `vendor` section (see the * header block). A field's `via` names the extension group it flowed through; the field having * resolved into a real shared record (the extension-group splice and group flatten) is what * proves the merg

(types, messages)

Source from the content-addressed store, hash-verified

803 * @returns {object} The vendor section, empty when there is no vendor content.
804 */
805function extractVendor(types, messages) {
806 const vendor = {}
807 const anchors = new Set()
808 const section = (ns) => (vendor[ns] ??= { extends: {}, commands: [], events: [], types: {} })
809 for (const kind of ['commands', 'events'])
810 for (const { vendor: ns, ...clean } of messages[kind]) section(ns)[kind].push(clean)
811 for (const [typeName, node] of Object.entries(types)) {
812 if (node.vendor) {
813 const { vendor: ns, ...clean } = node
814 section(ns).types[typeName] = clean
815 delete types[typeName]
816 continue
817 }
818 if (node.kind !== 'record' || !Array.isArray(node.fields)) continue
819 const kept = []
820 for (const field of node.fields) {
821 if (!field.vendor) {
822 kept.push(field)
823 continue
824 }
825 anchors.add(field.via)
826 // The extension point's own type carries a copy of its fields; drop that copy (the anchor
827 // itself is removed below) and route only the copy that resolved into a real target type.
828 if (field.via === typeName) continue
829 const { vendor: ns, via, ...clean } = field
830 const entry = (section(ns).extends[typeName] ??= { via, fields: [] })
831 entry.fields.push(clean)
832 }
833 node.fields = kept
834 }
835 for (const name of anchors) {
836 const anchor = types[name]
837 if (anchor && anchor.kind === 'record' && (anchor.fields?.length ?? 0) === 0) delete types[name]
838 }
839 return vendor
840}
841
842// The vendor model's `vendor`-tagged commands and events, as model entries. The untagged
843// rest duplicates the shared model (the vendor AST is the base AST plus overlays).

Callers 1

projectSchemaFunction · 0.85

Calls 3

sectionFunction · 0.85
entriesMethod · 0.80
addMethod · 0.65

Tested by

no test coverage detected