@appium/universal-xml-plugin 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/attr-map.d.ts +3 -57
- package/build/lib/attr-map.d.ts.map +1 -1
- package/build/lib/attr-map.js +2 -5
- package/build/lib/attr-map.js.map +1 -1
- package/build/lib/index.d.ts +4 -3
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +20 -5
- package/build/lib/index.js.map +1 -1
- package/build/lib/node-map.d.ts +3 -199
- package/build/lib/node-map.d.ts.map +1 -1
- package/build/lib/node-map.js +2 -9
- package/build/lib/node-map.js.map +1 -1
- package/build/lib/plugin.d.ts +7 -6
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +16 -18
- package/build/lib/plugin.js.map +1 -1
- package/build/lib/source.d.ts +41 -47
- package/build/lib/source.d.ts.map +1 -1
- package/build/lib/source.js +104 -47
- package/build/lib/source.js.map +1 -1
- package/build/lib/transformers.d.ts +3 -7
- package/build/lib/transformers.d.ts.map +1 -1
- package/build/lib/transformers.js +9 -10
- package/build/lib/transformers.js.map +1 -1
- package/build/lib/types.d.ts +29 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/lib/xpath.d.ts +16 -7
- package/build/lib/xpath.d.ts.map +1 -1
- package/build/lib/xpath.js +19 -16
- package/build/lib/xpath.js.map +1 -1
- package/lib/{attr-map.js → attr-map.ts} +5 -5
- package/lib/{index.js → index.ts} +22 -4
- package/lib/{node-map.js → node-map.ts} +5 -1
- package/lib/plugin.ts +119 -0
- package/lib/source.ts +265 -0
- package/lib/{transformers.js → transformers.ts} +9 -12
- package/lib/types.ts +33 -0
- package/lib/{xpath.js → xpath.ts} +24 -20
- package/package.json +10 -10
- package/tsconfig.json +3 -2
- package/build/lib/logger.d.ts +0 -3
- package/build/lib/logger.d.ts.map +0 -1
- package/build/lib/logger.js +0 -6
- package/build/lib/logger.js.map +0 -1
- package/index.js +0 -7
- package/lib/logger.js +0 -3
- package/lib/plugin.js +0 -81
- package/lib/source.js +0 -226
package/build/lib/source.d.ts
CHANGED
|
@@ -1,69 +1,63 @@
|
|
|
1
|
+
import type { NodesAndAttributes, TransformSourceXmlOptions, TransformNodeOptions } from './types';
|
|
2
|
+
export declare const ATTR_PREFIX = "@_";
|
|
3
|
+
export declare const IDX_PATH_PREFIX = "@_indexPath";
|
|
4
|
+
export declare const IDX_PREFIX = "@_index";
|
|
1
5
|
/**
|
|
6
|
+
* Transforms source XML to universal format
|
|
2
7
|
*
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
8
|
+
* @param xmlStr - The XML string to transform
|
|
9
|
+
* @param platform - The platform name ('ios' or 'android')
|
|
10
|
+
* @param opts - Transformation options
|
|
11
|
+
* @param opts.metadata - Optional metadata object
|
|
12
|
+
* @param opts.addIndexPath - Whether to add index path attributes
|
|
13
|
+
* @returns Promise resolving to transformed XML and unknown nodes/attributes
|
|
7
14
|
*/
|
|
8
|
-
export function transformSourceXml(xmlStr: string, platform: string, { metadata, addIndexPath }?: {
|
|
9
|
-
metadata?: any;
|
|
10
|
-
addIndexPath?: boolean;
|
|
11
|
-
}): Promise<{
|
|
15
|
+
export declare function transformSourceXml(xmlStr: string, platform: string, { metadata, addIndexPath }?: TransformSourceXmlOptions): Promise<{
|
|
12
16
|
xml: string;
|
|
13
17
|
unknowns: NodesAndAttributes;
|
|
14
18
|
}>;
|
|
15
19
|
/**
|
|
20
|
+
* Gets the universal node name for a platform-specific node name
|
|
16
21
|
*
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @returns
|
|
22
|
+
* @param nodeName - The platform-specific node name
|
|
23
|
+
* @param platform - The platform name
|
|
24
|
+
* @returns The universal node name or null if not found
|
|
20
25
|
*/
|
|
21
|
-
export function getUniversalNodeName(nodeName:
|
|
26
|
+
export declare function getUniversalNodeName(nodeName: string, platform: string): string | null;
|
|
22
27
|
/**
|
|
28
|
+
* Gets the universal attribute name for a platform-specific attribute name
|
|
23
29
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @returns
|
|
30
|
+
* @param attrName - The platform-specific attribute name
|
|
31
|
+
* @param platform - The platform name
|
|
32
|
+
* @returns The universal attribute name or null if not found
|
|
27
33
|
*/
|
|
28
|
-
export function getUniversalAttrName(attrName: string, platform: string): string | null;
|
|
34
|
+
export declare function getUniversalAttrName(attrName: string, platform: string): string | null;
|
|
29
35
|
/**
|
|
36
|
+
* Transforms a node object recursively
|
|
30
37
|
*
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns
|
|
38
|
+
* @param nodeObj - The node object to transform
|
|
39
|
+
* @param platform - The platform name
|
|
40
|
+
* @param opts - Transformation options
|
|
41
|
+
* @returns Object containing unknown nodes and attributes
|
|
35
42
|
*/
|
|
36
|
-
export function transformNode(nodeObj: any, platform: string, { metadata, addIndexPath, parentPath }:
|
|
37
|
-
metadata?: any;
|
|
38
|
-
addIndexPath?: boolean;
|
|
39
|
-
parentPath?: string;
|
|
40
|
-
}): NodesAndAttributes;
|
|
43
|
+
export declare function transformNode(nodeObj: any, platform: string, { metadata, addIndexPath, parentPath }: TransformNodeOptions): NodesAndAttributes;
|
|
41
44
|
/**
|
|
45
|
+
* Transforms child nodes of a node object
|
|
42
46
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @returns
|
|
47
|
+
* @param nodeObj - The node object containing child nodes
|
|
48
|
+
* @param childNodeNames - Array of child node names
|
|
49
|
+
* @param platform - The platform name
|
|
50
|
+
* @param opts - Transformation options
|
|
51
|
+
* @returns Object containing unknown nodes and attributes
|
|
48
52
|
*/
|
|
49
|
-
export function transformChildNodes(nodeObj: any, childNodeNames: string[], platform: string, { metadata, addIndexPath, parentPath }:
|
|
50
|
-
metadata?: any;
|
|
51
|
-
addIndexPath?: boolean;
|
|
52
|
-
parentPath?: string;
|
|
53
|
-
}): NodesAndAttributes;
|
|
53
|
+
export declare function transformChildNodes(nodeObj: any, childNodeNames: string[], platform: string, { metadata, addIndexPath, parentPath }: TransformNodeOptions): NodesAndAttributes;
|
|
54
54
|
/**
|
|
55
|
+
* Transforms attributes of a node object
|
|
55
56
|
*
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
59
|
-
* @returns
|
|
57
|
+
* @param nodeObj - The node object containing attributes
|
|
58
|
+
* @param attrs - Array of attribute keys
|
|
59
|
+
* @param platform - The platform name
|
|
60
|
+
* @returns Array of unknown attribute names
|
|
60
61
|
*/
|
|
61
|
-
export function transformAttrs(nodeObj: any, attrs: string[], platform: string): string[];
|
|
62
|
-
export const ATTR_PREFIX: "@_";
|
|
63
|
-
export const IDX_PATH_PREFIX: "@_indexPath";
|
|
64
|
-
export const IDX_PREFIX: "@_index";
|
|
65
|
-
export type NodesAndAttributes = {
|
|
66
|
-
nodes: string[];
|
|
67
|
-
attrs: string[];
|
|
68
|
-
};
|
|
62
|
+
export declare function transformAttrs(nodeObj: any, attrs: string[], platform: string): string[];
|
|
69
63
|
//# sourceMappingURL=source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../lib/source.
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../lib/source.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,EAGrB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,WAAW,OAAO,CAAC;AAChC,eAAO,MAAM,eAAe,gBAA4B,CAAC;AACzD,eAAO,MAAM,UAAU,YAAwB,CAAC;AAKhD;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,EAAC,QAAkC,EAAE,YAAoB,EAAC,GAAE,yBAA8B,GACzF,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,kBAAkB,CAAA;CAAC,CAAC,CAatD;AA2BD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEtF;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEtF;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,MAAM,EAChB,EAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAC,EAAE,oBAAoB,GACzD,kBAAkB,CA6CpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,GAAG,EACZ,cAAc,EAAE,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,EAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAC,EAAE,oBAAoB,GACzD,kBAAkB,CA+CpB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAoBxF"}
|
package/build/lib/source.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -11,41 +44,46 @@ exports.transformNode = transformNode;
|
|
|
11
44
|
exports.transformChildNodes = transformChildNodes;
|
|
12
45
|
exports.transformAttrs = transformAttrs;
|
|
13
46
|
const lodash_1 = __importDefault(require("lodash"));
|
|
47
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
14
48
|
const node_map_1 = __importDefault(require("./node-map"));
|
|
15
49
|
const attr_map_1 = require("./attr-map");
|
|
16
|
-
const
|
|
50
|
+
const TRANSFORMS = __importStar(require("./transformers"));
|
|
17
51
|
exports.ATTR_PREFIX = '@_';
|
|
18
52
|
exports.IDX_PATH_PREFIX = `${exports.ATTR_PREFIX}indexPath`;
|
|
19
53
|
exports.IDX_PREFIX = `${exports.ATTR_PREFIX}index`;
|
|
20
|
-
const isAttr = (
|
|
21
|
-
const isNode = (
|
|
54
|
+
const isAttr = (k) => k.startsWith(exports.ATTR_PREFIX);
|
|
55
|
+
const isNode = (k) => !isAttr(k);
|
|
22
56
|
/**
|
|
57
|
+
* Transforms source XML to universal format
|
|
23
58
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @
|
|
59
|
+
* @param xmlStr - The XML string to transform
|
|
60
|
+
* @param platform - The platform name ('ios' or 'android')
|
|
61
|
+
* @param opts - Transformation options
|
|
62
|
+
* @param opts.metadata - Optional metadata object
|
|
63
|
+
* @param opts.addIndexPath - Whether to add index path attributes
|
|
64
|
+
* @returns Promise resolving to transformed XML and unknown nodes/attributes
|
|
28
65
|
*/
|
|
29
66
|
async function transformSourceXml(xmlStr, platform, { metadata = {}, addIndexPath = false } = {}) {
|
|
30
67
|
// first thing we want to do is modify the ios source root node, because it doesn't include the
|
|
31
68
|
// necessary index attribute, so we add it if it's not there
|
|
32
69
|
xmlStr = xmlStr.replace('<AppiumAUT>', '<AppiumAUT index="0">');
|
|
33
|
-
const xmlObj =
|
|
70
|
+
const xmlObj = singletonXmlParser().parse(xmlStr);
|
|
34
71
|
const unknowns = transformNode(xmlObj, platform, {
|
|
35
72
|
metadata,
|
|
36
73
|
addIndexPath,
|
|
37
74
|
parentPath: '',
|
|
38
75
|
});
|
|
39
|
-
let transformedXml =
|
|
76
|
+
let transformedXml = singletonXmlBuilder().build(xmlObj).trim();
|
|
40
77
|
transformedXml = `<?xml version="1.0" encoding="UTF-8"?>\n${transformedXml}`;
|
|
41
78
|
return { xml: transformedXml, unknowns };
|
|
42
79
|
}
|
|
43
80
|
/**
|
|
81
|
+
* Gets the universal name for a platform-specific name from a name map
|
|
44
82
|
*
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @returns
|
|
83
|
+
* @param nameMap - The name mapping object
|
|
84
|
+
* @param name - The platform-specific name
|
|
85
|
+
* @param platform - The platform name
|
|
86
|
+
* @returns The universal name or null if not found
|
|
49
87
|
*/
|
|
50
88
|
function getUniversalName(nameMap, name, platform) {
|
|
51
89
|
for (const translatedName of Object.keys(nameMap)) {
|
|
@@ -60,29 +98,32 @@ function getUniversalName(nameMap, name, platform) {
|
|
|
60
98
|
return null;
|
|
61
99
|
}
|
|
62
100
|
/**
|
|
101
|
+
* Gets the universal node name for a platform-specific node name
|
|
63
102
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @param
|
|
66
|
-
* @returns
|
|
103
|
+
* @param nodeName - The platform-specific node name
|
|
104
|
+
* @param platform - The platform name
|
|
105
|
+
* @returns The universal node name or null if not found
|
|
67
106
|
*/
|
|
68
107
|
function getUniversalNodeName(nodeName, platform) {
|
|
69
108
|
return getUniversalName(node_map_1.default, nodeName, platform);
|
|
70
109
|
}
|
|
71
110
|
/**
|
|
111
|
+
* Gets the universal attribute name for a platform-specific attribute name
|
|
72
112
|
*
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
75
|
-
* @returns
|
|
113
|
+
* @param attrName - The platform-specific attribute name
|
|
114
|
+
* @param platform - The platform name
|
|
115
|
+
* @returns The universal attribute name or null if not found
|
|
76
116
|
*/
|
|
77
117
|
function getUniversalAttrName(attrName, platform) {
|
|
78
118
|
return getUniversalName(attr_map_1.ATTR_MAP, attrName, platform);
|
|
79
119
|
}
|
|
80
120
|
/**
|
|
121
|
+
* Transforms a node object recursively
|
|
81
122
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
85
|
-
* @returns
|
|
123
|
+
* @param nodeObj - The node object to transform
|
|
124
|
+
* @param platform - The platform name
|
|
125
|
+
* @param opts - Transformation options
|
|
126
|
+
* @returns Object containing unknown nodes and attributes
|
|
86
127
|
*/
|
|
87
128
|
function transformNode(nodeObj, platform, { metadata, addIndexPath, parentPath }) {
|
|
88
129
|
const unknownNodes = [];
|
|
@@ -91,15 +132,18 @@ function transformNode(nodeObj, platform, { metadata, addIndexPath, parentPath }
|
|
|
91
132
|
const keys = Object.keys(nodeObj);
|
|
92
133
|
const childNodeNames = keys.filter(isNode);
|
|
93
134
|
const attrs = keys.filter(isAttr);
|
|
94
|
-
let thisIndexPath = parentPath;
|
|
135
|
+
let thisIndexPath = parentPath || '';
|
|
95
136
|
if (attrs.length && addIndexPath) {
|
|
96
137
|
if (!attrs.includes(exports.IDX_PREFIX)) {
|
|
97
138
|
throw new Error(`Index path is required but node found with no 'index' attribute`);
|
|
98
139
|
}
|
|
99
|
-
thisIndexPath = `${parentPath}/${nodeObj[exports.IDX_PREFIX]}`;
|
|
140
|
+
thisIndexPath = `${parentPath || ''}/${nodeObj[exports.IDX_PREFIX]}`;
|
|
100
141
|
nodeObj[exports.IDX_PATH_PREFIX] = thisIndexPath;
|
|
101
142
|
}
|
|
102
|
-
|
|
143
|
+
const transformFn = TRANSFORMS[platform];
|
|
144
|
+
if (transformFn) {
|
|
145
|
+
transformFn(nodeObj, metadata || {});
|
|
146
|
+
}
|
|
103
147
|
unknownAttrs.push(...transformAttrs(nodeObj, attrs, platform));
|
|
104
148
|
const unknowns = transformChildNodes(nodeObj, childNodeNames, platform, {
|
|
105
149
|
metadata,
|
|
@@ -114,7 +158,7 @@ function transformNode(nodeObj, platform, { metadata, addIndexPath, parentPath }
|
|
|
114
158
|
const { nodes, attrs } = transformNode(childObj, platform, {
|
|
115
159
|
metadata,
|
|
116
160
|
addIndexPath,
|
|
117
|
-
parentPath,
|
|
161
|
+
parentPath: parentPath || '',
|
|
118
162
|
});
|
|
119
163
|
unknownNodes.push(...nodes);
|
|
120
164
|
unknownAttrs.push(...attrs);
|
|
@@ -126,12 +170,13 @@ function transformNode(nodeObj, platform, { metadata, addIndexPath, parentPath }
|
|
|
126
170
|
};
|
|
127
171
|
}
|
|
128
172
|
/**
|
|
173
|
+
* Transforms child nodes of a node object
|
|
129
174
|
*
|
|
130
|
-
* @param
|
|
131
|
-
* @param
|
|
132
|
-
* @param
|
|
133
|
-
* @param
|
|
134
|
-
* @returns
|
|
175
|
+
* @param nodeObj - The node object containing child nodes
|
|
176
|
+
* @param childNodeNames - Array of child node names
|
|
177
|
+
* @param platform - The platform name
|
|
178
|
+
* @param opts - Transformation options
|
|
179
|
+
* @returns Object containing unknown nodes and attributes
|
|
135
180
|
*/
|
|
136
181
|
function transformChildNodes(nodeObj, childNodeNames, platform, { metadata, addIndexPath, parentPath }) {
|
|
137
182
|
const unknownNodes = [];
|
|
@@ -141,7 +186,7 @@ function transformChildNodes(nodeObj, childNodeNames, platform, { metadata, addI
|
|
|
141
186
|
const { nodes, attrs } = transformNode(nodeObj[nodeName], platform, {
|
|
142
187
|
metadata,
|
|
143
188
|
addIndexPath,
|
|
144
|
-
parentPath,
|
|
189
|
+
parentPath: parentPath || '',
|
|
145
190
|
});
|
|
146
191
|
unknownNodes.push(...nodes);
|
|
147
192
|
unknownAttrs.push(...attrs);
|
|
@@ -158,7 +203,23 @@ function transformChildNodes(nodeObj, childNodeNames, platform, { metadata, addI
|
|
|
158
203
|
// if we already have a node with the universal name, that means we are mapping a second
|
|
159
204
|
// original node name to the same universal node name, so we just push all its children into
|
|
160
205
|
// the list
|
|
161
|
-
|
|
206
|
+
if (lodash_1.default.isArray(nodeObj[universalName])) {
|
|
207
|
+
if (lodash_1.default.isArray(nodeObj[nodeName])) {
|
|
208
|
+
nodeObj[universalName].push(...nodeObj[nodeName]);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
nodeObj[universalName].push(nodeObj[nodeName]);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
nodeObj[universalName] = [nodeObj[universalName]];
|
|
216
|
+
if (lodash_1.default.isArray(nodeObj[nodeName])) {
|
|
217
|
+
nodeObj[universalName].push(...nodeObj[nodeName]);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
nodeObj[universalName].push(nodeObj[nodeName]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
162
223
|
}
|
|
163
224
|
else {
|
|
164
225
|
nodeObj[universalName] = nodeObj[nodeName];
|
|
@@ -168,11 +229,12 @@ function transformChildNodes(nodeObj, childNodeNames, platform, { metadata, addI
|
|
|
168
229
|
return { nodes: unknownNodes, attrs: unknownAttrs };
|
|
169
230
|
}
|
|
170
231
|
/**
|
|
232
|
+
* Transforms attributes of a node object
|
|
171
233
|
*
|
|
172
|
-
* @param
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
* @returns
|
|
234
|
+
* @param nodeObj - The node object containing attributes
|
|
235
|
+
* @param attrs - Array of attribute keys
|
|
236
|
+
* @param platform - The platform name
|
|
237
|
+
* @returns Array of unknown attribute names
|
|
176
238
|
*/
|
|
177
239
|
function transformAttrs(nodeObj, attrs, platform) {
|
|
178
240
|
const unknownAttrs = [];
|
|
@@ -195,25 +257,20 @@ function transformAttrs(nodeObj, attrs, platform) {
|
|
|
195
257
|
}
|
|
196
258
|
return unknownAttrs;
|
|
197
259
|
}
|
|
198
|
-
const singletonXmlBuilder = lodash_1.default.memoize(
|
|
199
|
-
|
|
200
|
-
return new XMLBuilder({
|
|
260
|
+
const singletonXmlBuilder = lodash_1.default.memoize(function makeXmlBuilder() {
|
|
261
|
+
return new fast_xml_parser_1.XMLBuilder({
|
|
201
262
|
ignoreAttributes: false,
|
|
202
263
|
attributeNamePrefix: exports.ATTR_PREFIX,
|
|
203
264
|
suppressBooleanAttributes: false,
|
|
204
265
|
format: true,
|
|
205
266
|
});
|
|
206
267
|
});
|
|
207
|
-
const singletonXmlParser = lodash_1.default.memoize(
|
|
208
|
-
|
|
209
|
-
return new XMLParser({
|
|
268
|
+
const singletonXmlParser = lodash_1.default.memoize(function makeXmlParser() {
|
|
269
|
+
return new fast_xml_parser_1.XMLParser({
|
|
210
270
|
ignoreAttributes: false,
|
|
211
271
|
ignoreDeclaration: true,
|
|
212
272
|
attributeNamePrefix: exports.ATTR_PREFIX,
|
|
213
273
|
isArray: (name, jPath, isLeafNode, isAttribute) => !isAttribute,
|
|
214
274
|
});
|
|
215
275
|
});
|
|
216
|
-
/**
|
|
217
|
-
* @typedef {{nodes: string[], attrs: string[]}} NodesAndAttributes
|
|
218
|
-
*/
|
|
219
276
|
//# sourceMappingURL=source.js.map
|
package/build/lib/source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../lib/source.
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../lib/source.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,gDAiBC;AAkCD,oDAEC;AASD,oDAEC;AAUD,sCAiDC;AAWD,kDAoDC;AAUD,wCAoBC;AAtPD,oDAAuB;AACvB,qDAAsD;AACtD,0DAAkC;AAClC,yCAAkD;AAClD,2DAA6C;AAShC,QAAA,WAAW,GAAG,IAAI,CAAC;AACnB,QAAA,eAAe,GAAG,GAAG,mBAAW,WAAW,CAAC;AAC5C,QAAA,UAAU,GAAG,GAAG,mBAAW,OAAO,CAAC;AAEhD,MAAM,MAAM,GAAG,CAAC,CAAS,EAAW,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,mBAAW,CAAC,CAAC;AACjE,MAAM,MAAM,GAAG,CAAC,CAAS,EAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACI,KAAK,UAAU,kBAAkB,CACtC,MAAc,EACd,QAAgB,EAChB,EAAC,QAAQ,GAAG,EAAuB,EAAE,YAAY,GAAG,KAAK,KAA+B,EAAE;IAE1F,+FAA+F;I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AAM,EAAE,IAAI;KACb,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,gBAAC,CAAC,OAAO,CAAC,SAAS,aAAa;IACzD,OAAO,IAAI,2BAAS,CAAC;QACnB,gBAAgB,EAAE,KAAK;QACvB,iBAAiB,EAAE,IAAI;QACvB,mBAAmB,EAAE,mBAAW;QAChC,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,WAAW;KAChE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export default _default;
|
|
6
|
-
declare function ios(nodeObj: any): any;
|
|
7
|
-
declare function android(nodeObj: any, metadata: any): void;
|
|
1
|
+
import type { TransformMetadata } from './types';
|
|
2
|
+
export declare function ios(_nodeObj: any): void;
|
|
3
|
+
export declare function android(nodeObj: any, metadata: TransformMetadata): void;
|
|
8
4
|
//# sourceMappingURL=transformers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../lib/transformers.
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../lib/transformers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAG/C,wBAAgB,GAAG,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAEvC;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAoBvE"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ios = ios;
|
|
4
|
+
exports.android = android;
|
|
3
5
|
const source_1 = require("./source");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
function ios(_nodeObj) {
|
|
8
|
+
// iOS transformer does nothing
|
|
6
9
|
}
|
|
7
10
|
function android(nodeObj, metadata) {
|
|
8
11
|
// strip android:id from front of id
|
|
@@ -16,16 +19,12 @@ function android(nodeObj, metadata) {
|
|
|
16
19
|
.split(/\[|\]|,/)
|
|
17
20
|
.filter((str) => str !== '');
|
|
18
21
|
const [x, y, x2, y2] = boundsArray;
|
|
19
|
-
const width = x2 - x;
|
|
20
|
-
const height = y2 - y;
|
|
22
|
+
const width = parseInt(x2, 10) - parseInt(x, 10);
|
|
23
|
+
const height = parseInt(y2, 10) - parseInt(y, 10);
|
|
21
24
|
nodeObj[`${source_1.ATTR_PREFIX}x`] = x;
|
|
22
25
|
nodeObj[`${source_1.ATTR_PREFIX}y`] = y;
|
|
23
|
-
nodeObj[`${source_1.ATTR_PREFIX}width`] = width;
|
|
24
|
-
nodeObj[`${source_1.ATTR_PREFIX}height`] = height;
|
|
26
|
+
nodeObj[`${source_1.ATTR_PREFIX}width`] = width.toString();
|
|
27
|
+
nodeObj[`${source_1.ATTR_PREFIX}height`] = height.toString();
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
exports.default = {
|
|
28
|
-
ios,
|
|
29
|
-
android,
|
|
30
|
-
};
|
|
31
30
|
//# sourceMappingURL=transformers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.js","sourceRoot":"","sources":["../../lib/transformers.
|
|
1
|
+
{"version":3,"file":"transformers.js","sourceRoot":"","sources":["../../lib/transformers.ts"],"names":[],"mappings":";;AAIA,kBAEC;AAED,0BAoBC;AA5BD,qCAAqC;AAGrC,6DAA6D;AAC7D,SAAgB,GAAG,CAAC,QAAa;IAC/B,+BAA+B;AACjC,CAAC;AAED,SAAgB,OAAO,CAAC,OAAY,EAAE,QAA2B;IAC/D,oCAAoC;IACpC,MA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}
|
|
5
|
+
/**
|
|
6
|
+
* Metadata used for XML transformations
|
|
7
|
+
*/
|
|
8
|
+
export interface TransformMetadata {
|
|
9
|
+
appPackage?: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface TransformSourceXmlOptions {
|
|
13
|
+
metadata?: TransformMetadata;
|
|
14
|
+
addIndexPath?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface TransformNodeOptions extends TransformSourceXmlOptions {
|
|
17
|
+
parentPath?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Type for platform-specific name mappings
|
|
21
|
+
* Values can be a string or an array of strings (for many-to-one mappings)
|
|
22
|
+
*/
|
|
23
|
+
export type PlatformNameMap = Record<string, string | readonly string[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Type for universal name maps
|
|
26
|
+
* Keys are universal names, values are platform-specific mappings
|
|
27
|
+
*/
|
|
28
|
+
export type UniversalNameMap = Record<string, Partial<PlatformNameMap>>;
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAqB,SAAQ,yBAAyB;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC;AAEzE;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":""}
|
package/build/lib/xpath.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
export function runQuery(query:
|
|
1
|
+
export declare function runQuery(query: string, xmlStr: string): any[];
|
|
2
2
|
/**
|
|
3
|
+
* Transforms an XPath query to work with the original platform-specific XML
|
|
3
4
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @returns
|
|
5
|
+
* @param query - The XPath query to transform
|
|
6
|
+
* @param xmlStr - The transformed XML string
|
|
7
|
+
* @param multiple - Whether to return multiple matches
|
|
8
|
+
* @returns The transformed query string or null if no matches found
|
|
8
9
|
*/
|
|
9
|
-
export function transformQuery(query: string, xmlStr: string, multiple: boolean): string | null;
|
|
10
|
-
|
|
10
|
+
export declare function transformQuery(query: string, xmlStr: string, multiple: boolean): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the value of a node attribute
|
|
13
|
+
*
|
|
14
|
+
* @param node - The XML node
|
|
15
|
+
* @param attr - The attribute name
|
|
16
|
+
* @returns The attribute value
|
|
17
|
+
* @throws {Error} If the attribute doesn't exist
|
|
18
|
+
*/
|
|
19
|
+
export declare function getNodeAttrVal(node: any, attr: string): string;
|
|
11
20
|
//# sourceMappingURL=xpath.d.ts.map
|
package/build/lib/xpath.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xpath.d.ts","sourceRoot":"","sources":["../../lib/xpath.
|
|
1
|
+
{"version":3,"file":"xpath.d.ts","sourceRoot":"","sources":["../../lib/xpath.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,CAM7D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CA2B9F;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM9D"}
|
package/build/lib/xpath.js
CHANGED
|
@@ -17,11 +17,12 @@ function runQuery(query, xmlStr) {
|
|
|
17
17
|
return nodes;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
+
* Transforms an XPath query to work with the original platform-specific XML
|
|
20
21
|
*
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @returns
|
|
22
|
+
* @param query - The XPath query to transform
|
|
23
|
+
* @param xmlStr - The transformed XML string
|
|
24
|
+
* @param multiple - Whether to return multiple matches
|
|
25
|
+
* @returns The transformed query string or null if no matches found
|
|
25
26
|
*/
|
|
26
27
|
function transformQuery(query, xmlStr, multiple) {
|
|
27
28
|
const nodes = runQuery(query, xmlStr);
|
|
@@ -31,9 +32,9 @@ function transformQuery(query, xmlStr, multiple) {
|
|
|
31
32
|
const newQueries = nodes.map((node) => {
|
|
32
33
|
const indexPath = getNodeAttrVal(node, 'indexPath');
|
|
33
34
|
// at this point indexPath will look like /0/0/1/1/0/1/0/2
|
|
34
|
-
|
|
35
|
+
const newQuery = indexPath
|
|
35
36
|
.substring(1) // remove leading / so we can split
|
|
36
|
-
.split('/') // split into
|
|
37
|
+
.split('/') // split into indexes
|
|
37
38
|
.map((indexStr) => {
|
|
38
39
|
// map to xpath node indexes (1-based)
|
|
39
40
|
const xpathIndex = parseInt(indexStr, 10) + 1;
|
|
@@ -43,19 +44,21 @@ function transformQuery(query, xmlStr, multiple) {
|
|
|
43
44
|
// now to make this a valid xpath from the root, prepend the / we removed earlier
|
|
44
45
|
return `/${newQuery}`;
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (multiple) {
|
|
49
|
-
newSelector = newQueries.join(' | ');
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
newSelector = newQueries[0];
|
|
53
|
-
}
|
|
47
|
+
if (newQueries.length === 0) {
|
|
48
|
+
return null;
|
|
54
49
|
}
|
|
55
|
-
return
|
|
50
|
+
return multiple ? newQueries.join(' | ') : newQueries[0];
|
|
56
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the value of a node attribute
|
|
54
|
+
*
|
|
55
|
+
* @param node - The XML node
|
|
56
|
+
* @param attr - The attribute name
|
|
57
|
+
* @returns The attribute value
|
|
58
|
+
* @throws {Error} If the attribute doesn't exist
|
|
59
|
+
*/
|
|
57
60
|
function getNodeAttrVal(node, attr) {
|
|
58
|
-
const attrObjs = Object.values(node.attributes).filter((obj) => obj.name === attr);
|
|
61
|
+
const attrObjs = Object.values(node.attributes || {}).filter((obj) => obj.name === attr);
|
|
59
62
|
if (!attrObjs.length) {
|
|
60
63
|
throw new Error(`Tried to retrieve a node attribute '${attr}' but the node didn't have it`);
|
|
61
64
|
}
|
package/build/lib/xpath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xpath.js","sourceRoot":"","sources":["../../lib/xpath.
|
|
1
|
+
{"version":3,"file":"xpath.js","sourceRoot":"","sources":["../../lib/xpath.ts"],"names":[],"mappings":";;;;;AAIA,4BAMC;AAUD,wCA2BC;AAUD,wCAMC;AA/DD,iCAA2C;AAC3C,2CAAoD;AACpD,oDAAuB;AAEvB,SAAgB,QAAQ,CAAC,KAAa,EAAE,MAAc;IACpD,MAAM,GAAG,GAAG,IAAI,kBAAS,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,kBAAS,CAAC,QAAQ,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