MCPcopy Create free account
hub / github.com/appium/appium / transformNode

Function transformNode

packages/universal-xml-plugin/lib/source.ts:82–131  ·  view source on GitHub ↗
(
  nodeObj: any,
  platform: string,
  {metadata, addIndexPath, parentPath}: TransformNodeOptions,
)

Source from the content-addressed store, hash-verified

80 * @returns Object containing unknown nodes and attributes
81 */
82export function transformNode(
83 nodeObj: any,
84 platform: string,
85 {metadata, addIndexPath, parentPath}: TransformNodeOptions,
86): NodesAndAttributes {
87 const unknownNodes: string[] = [];
88 const unknownAttrs: string[] = [];
89 if (util.isPlainObject(nodeObj)) {
90 const keys = Object.keys(nodeObj);
91 const childNodeNames = keys.filter(isNode);
92 const attrs = keys.filter(isAttr);
93 let thisIndexPath = parentPath || '';
94
95 if (attrs.length && addIndexPath) {
96 if (!attrs.includes(IDX_PREFIX)) {
97 throw new Error(`Index path is required but node found with no 'index' attribute`);
98 }
99
100 thisIndexPath = `${parentPath || ''}/${nodeObj[IDX_PREFIX] as string}`;
101 nodeObj[IDX_PATH_PREFIX] = thisIndexPath;
102 }
103
104 const transformFn = TRANSFORMS[platform as keyof typeof TRANSFORMS];
105 if (transformFn) {
106 transformFn(nodeObj, metadata || ({} as TransformMetadata));
107 }
108 unknownAttrs.push(...transformAttrs(nodeObj, attrs, platform));
109 const unknowns = transformChildNodes(nodeObj, childNodeNames, platform, {
110 metadata,
111 addIndexPath,
112 parentPath: thisIndexPath,
113 });
114 unknownAttrs.push(...unknowns.attrs);
115 unknownNodes.push(...unknowns.nodes);
116 } else if (Array.isArray(nodeObj)) {
117 for (const childObj of nodeObj) {
118 const {nodes, attrs} = transformNode(childObj, platform, {
119 metadata,
120 addIndexPath,
121 parentPath: parentPath || '',
122 });
123 unknownNodes.push(...nodes);
124 unknownAttrs.push(...attrs);
125 }
126 }
127 return {
128 nodes: util.uniq(unknownNodes),
129 attrs: util.uniq(unknownAttrs),
130 };
131}
132
133/**
134 * Transforms child nodes of a node object

Callers 2

transformSourceXmlFunction · 0.85
transformChildNodesFunction · 0.85

Calls 3

transformAttrsFunction · 0.85
transformChildNodesFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected