@btc-embedded/cdk-extensions 0.23.3 → 0.23.5
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/.jsii +41 -41
- package/CHANGELOG.md +14 -0
- package/assets/cli/catnip.js +154 -166
- package/lib/constructs/EventPipe.js +1 -1
- package/lib/constructs/ExportedService.js +1 -1
- package/lib/constructs/S3Bucket.js +1 -1
- package/lib/constructs/SecureRestApi.js +1 -1
- package/lib/constructs/SecureRestApiV2.js +1 -1
- package/lib/constructs/api-keys/ApiKeyClientAuthorization.js +1 -1
- package/lib/constructs/api-keys/ApiKeyManagement.js +1 -1
- package/lib/constructs/api-keys/ApiKeyPreTokenHandler.js +1 -1
- package/lib/constructs/api-keys/ApiKeyStore.js +1 -1
- package/lib/extensions/ApiGatewayExtension.js +1 -1
- package/lib/extensions/ApplicationContainer.js +1 -1
- package/lib/extensions/ApplicationLoadBalancerExtension.js +1 -1
- package/lib/extensions/ApplicationLoadBalancerExtensionV2.js +1 -1
- package/lib/extensions/CloudMapExtension.js +1 -1
- package/lib/extensions/DeactivatableServiceExtension.js +1 -1
- package/lib/extensions/DeploymentConfigExtension.js +1 -1
- package/lib/extensions/DocumentDbAccessExtension.js +1 -1
- package/lib/extensions/DomainEventMessagingExtension.js +1 -1
- package/lib/extensions/EfsMountExtension.js +1 -1
- package/lib/extensions/ExtraContainerExtension.js +1 -1
- package/lib/extensions/HTTPApiExtension.js +1 -1
- package/lib/extensions/LogExtension.js +1 -1
- package/lib/extensions/ModifyContainerDefinitionExtension.js +1 -1
- package/lib/extensions/ModifyTaskDefinitionExtension.js +1 -1
- package/lib/extensions/OpenIdExtension.js +1 -1
- package/lib/extensions/OpenTelemetryExtension.js +1 -1
- package/lib/extensions/PostgresDbAccessExtension.js +1 -1
- package/lib/extensions/SharedVolumeExtension.js +1 -1
- package/lib/extensions/TcpKeepAliveExtension.js +1 -1
- package/lib/platform/ApiGateway.js +1 -1
- package/lib/platform/ApiGatewayVpcLink.js +2 -2
- package/lib/platform/ApplicationLoadBalancer.js +1 -1
- package/lib/platform/ApplicationLoadBalancerV2.d.ts +1 -0
- package/lib/platform/ApplicationLoadBalancerV2.js +10 -3
- package/lib/platform/AuroraPostgresDB.js +5 -4
- package/lib/platform/BTCLogGroup.js +1 -1
- package/lib/platform/CognitoUserPool.js +2 -2
- package/lib/platform/DefaultUserPoolClients.js +1 -1
- package/lib/platform/DocumentDB.js +2 -2
- package/lib/platform/EcsCluster.js +1 -1
- package/lib/platform/EfsFileSystem.js +1 -1
- package/lib/platform/HostedZone.js +1 -1
- package/lib/platform/PrivateDnsNamespace.js +1 -1
- package/lib/platform/ResourceServer.js +1 -1
- package/lib/platform/Vpc.js +1 -1
- package/lib/platform/VpcV2.js +1 -1
- package/lib/stacks/ApplicationStack.js +1 -1
- package/lib/utils/BasePlatformStackResolver.js +1 -1
- package/lib/utils/StackParameter.js +1 -1
- package/node_modules/@nodable/entities/README.md +41 -0
- package/node_modules/@nodable/entities/package.json +54 -0
- package/node_modules/@nodable/entities/src/EntityDecoder.js +543 -0
- package/node_modules/@nodable/entities/src/EntityEncoder.js +194 -0
- package/node_modules/@nodable/entities/src/entities.js +1177 -0
- package/node_modules/@nodable/entities/src/entityTries.js +49 -0
- package/node_modules/@nodable/entities/src/index.d.ts +264 -0
- package/node_modules/@nodable/entities/src/index.js +29 -0
- package/node_modules/fast-xml-builder/CHANGELOG.md +40 -0
- package/node_modules/fast-xml-builder/LICENSE +21 -0
- package/node_modules/fast-xml-builder/README.md +74 -0
- package/node_modules/fast-xml-builder/lib/fxb.cjs +1 -0
- package/node_modules/fast-xml-builder/lib/fxb.d.cts +270 -0
- package/node_modules/fast-xml-builder/lib/fxb.min.js +2 -0
- package/node_modules/fast-xml-builder/lib/fxb.min.js.map +1 -0
- package/node_modules/fast-xml-builder/package.json +81 -0
- package/node_modules/fast-xml-builder/src/fxb.d.ts +270 -0
- package/node_modules/fast-xml-builder/src/fxb.js +599 -0
- package/node_modules/fast-xml-builder/src/ignoreAttributes.js +18 -0
- package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +359 -0
- package/node_modules/fast-xml-builder/src/util.js +16 -0
- package/node_modules/fast-xml-parser/CHANGELOG.md +165 -0
- package/node_modules/fast-xml-parser/README.md +21 -44
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.d.cts +343 -31
- package/node_modules/fast-xml-parser/lib/fxp.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxparser.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxvalidator.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +1 -1
- package/node_modules/fast-xml-parser/package.json +13 -8
- package/node_modules/fast-xml-parser/src/fxp.d.ts +335 -30
- package/node_modules/fast-xml-parser/src/fxp.js +1 -1
- package/node_modules/fast-xml-parser/src/util.js +18 -25
- package/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +89 -87
- package/node_modules/fast-xml-parser/src/v6/OptionsBuilder.js +10 -10
- package/node_modules/fast-xml-parser/src/v6/OutputBuilders/BaseOutputBuilder.js +23 -23
- package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsArrBuilder.js +29 -29
- package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsMinArrBuilder.js +1 -1
- package/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsObjBuilder.js +39 -39
- package/node_modules/fast-xml-parser/src/v6/OutputBuilders/ParserOptionsBuilder.js +21 -21
- package/node_modules/fast-xml-parser/src/v6/XMLParser.js +22 -22
- package/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +85 -85
- package/node_modules/fast-xml-parser/src/validator.js +34 -34
- package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +5 -284
- package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +335 -293
- package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +160 -43
- package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +540 -308
- package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +26 -26
- package/node_modules/fast-xml-parser/src/xmlparser/node2json.js +99 -41
- package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +10 -10
- package/node_modules/path-expression-matcher/LICENSE +21 -0
- package/node_modules/path-expression-matcher/README.md +872 -0
- package/node_modules/path-expression-matcher/lib/pem.cjs +1 -0
- package/node_modules/path-expression-matcher/lib/pem.d.cts +634 -0
- package/node_modules/path-expression-matcher/lib/pem.min.js +2 -0
- package/node_modules/path-expression-matcher/lib/pem.min.js.map +1 -0
- package/node_modules/path-expression-matcher/package.json +78 -0
- package/node_modules/path-expression-matcher/src/Expression.js +232 -0
- package/node_modules/path-expression-matcher/src/ExpressionSet.js +209 -0
- package/node_modules/path-expression-matcher/src/Matcher.js +570 -0
- package/node_modules/path-expression-matcher/src/index.d.ts +523 -0
- package/node_modules/path-expression-matcher/src/index.js +29 -0
- package/node_modules/strnum/CHANGELOG.md +12 -2
- package/node_modules/strnum/README.md +1 -0
- package/node_modules/strnum/package.json +5 -4
- package/node_modules/strnum/strnum.js +99 -65
- package/node_modules/xml-naming/README.md +189 -0
- package/node_modules/xml-naming/package.json +54 -0
- package/node_modules/xml-naming/src/index.d.ts +74 -0
- package/node_modules/xml-naming/src/index.js +270 -0
- package/package.json +3 -2
- package/renovate.json5 +1 -0
- package/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js +0 -134
- package/node_modules/strnum/.github/SECURITY.md +0 -5
- package/node_modules/strnum/.vscode/launch.json +0 -25
- package/node_modules/strnum/algo.stflow +0 -84
- package/node_modules/strnum/strnum.test.js +0 -173
- package/node_modules/strnum/test.js +0 -9
- /package/node_modules/{fast-xml-parser/src/xmlbuilder → fast-xml-builder/src}/prettifyJs2Xml.js +0 -0
|
@@ -1,104 +1,106 @@
|
|
|
1
|
-
const ampEntity = { regex: /&(amp|#38|#x26);/g, val
|
|
1
|
+
const ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
|
|
2
2
|
const htmlEntities = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
4
|
+
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
|
5
|
+
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
|
6
|
+
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
|
7
|
+
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
|
8
|
+
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
|
9
|
+
"cent": { regex: /&(cent|#162);/g, val: "¢" },
|
|
10
|
+
"pound": { regex: /&(pound|#163);/g, val: "£" },
|
|
11
|
+
"yen": { regex: /&(yen|#165);/g, val: "¥" },
|
|
12
|
+
"euro": { regex: /&(euro|#8364);/g, val: "€" },
|
|
13
|
+
"copyright": { regex: /&(copy|#169);/g, val: "©" },
|
|
14
|
+
"reg": { regex: /&(reg|#174);/g, val: "®" },
|
|
15
|
+
"inr": { regex: /&(inr|#8377);/g, val: "₹" },
|
|
16
|
+
"num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 10)) },
|
|
17
|
+
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 16)) },
|
|
18
18
|
};
|
|
19
|
-
export default class EntitiesParser{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
export default class EntitiesParser {
|
|
20
|
+
constructor(replaceHtmlEntities) {
|
|
21
|
+
this.replaceHtmlEntities = replaceHtmlEntities;
|
|
22
|
+
this.docTypeEntities = {};
|
|
23
|
+
this.lastEntities = {
|
|
24
|
+
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
25
|
+
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
26
|
+
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
27
|
+
"quot": { regex: /&(quot|#34|#x22);/g, val: "\"" },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
31
|
+
addExternalEntities(externalEntities) {
|
|
32
|
+
const entKeys = Object.keys(externalEntities);
|
|
33
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
34
|
+
const ent = entKeys[i];
|
|
35
|
+
this.addExternalEntity(ent, externalEntities[ent])
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
}
|
|
38
|
+
addExternalEntity(key, val) {
|
|
39
|
+
validateEntityName(key);
|
|
40
|
+
const escaped = key.replace(/[.\-+*:]/g, '\\.');
|
|
41
|
+
if (val.indexOf("&") !== -1) {
|
|
42
|
+
reportWarning(`Entity ${key} is not added as '&' is found in value;`)
|
|
43
|
+
return;
|
|
44
|
+
} else {
|
|
45
|
+
this.lastEntities[key] = {
|
|
46
|
+
regex: new RegExp("&" + escaped + ";", "g"),
|
|
47
|
+
val: val
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
addDocTypeEntities(entities) {
|
|
53
|
+
const entKeys = Object.keys(entities);
|
|
54
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
55
|
+
const ent = entKeys[i];
|
|
56
|
+
const escaped = ent.replace(/[.\-+*:]/g, '\\.');
|
|
57
|
+
this.docTypeEntities[ent] = {
|
|
58
|
+
regex: new RegExp("&" + escaped + ";", "g"),
|
|
59
|
+
val: entities[ent]
|
|
60
|
+
}
|
|
60
61
|
}
|
|
62
|
+
}
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
parse(val) {
|
|
65
|
+
return this.replaceEntitiesValue(val)
|
|
66
|
+
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
val = val.replace( ampEntity.regex, ampEntity.val);
|
|
68
|
+
/**
|
|
69
|
+
* 1. Replace DOCTYPE entities
|
|
70
|
+
* 2. Replace external entities
|
|
71
|
+
* 3. Replace HTML entities if asked
|
|
72
|
+
* @param {string} val
|
|
73
|
+
*/
|
|
74
|
+
replaceEntitiesValue(val) {
|
|
75
|
+
if (typeof val === "string" && val.length > 0) {
|
|
76
|
+
for (let entityName in this.docTypeEntities) {
|
|
77
|
+
const entity = this.docTypeEntities[entityName];
|
|
78
|
+
val = val.replace(entity.regx, entity.val);
|
|
79
|
+
}
|
|
80
|
+
for (let entityName in this.lastEntities) {
|
|
81
|
+
const entity = this.lastEntities[entityName];
|
|
82
|
+
val = val.replace(entity.regex, entity.val);
|
|
83
|
+
}
|
|
84
|
+
if (this.replaceHtmlEntities) {
|
|
85
|
+
for (let entityName in htmlEntities) {
|
|
86
|
+
const entity = htmlEntities[entityName];
|
|
87
|
+
val = val.replace(entity.regex, entity.val);
|
|
89
88
|
}
|
|
90
|
-
|
|
89
|
+
}
|
|
90
|
+
val = val.replace(ampEntity.regex, ampEntity.val);
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
return val;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
93
95
|
|
|
94
96
|
//an entity name should not contains special characters that may be used in regex
|
|
95
97
|
//Eg !?\\\/[]$%{}^&*()<>
|
|
96
|
-
const specialChar = "
|
|
98
|
+
const specialChar = "!?\\/[]$%{}^&*()<>|+";
|
|
97
99
|
|
|
98
|
-
function validateEntityName(name){
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
function validateEntityName(name) {
|
|
101
|
+
for (let i = 0; i < specialChar.length; i++) {
|
|
102
|
+
const ch = specialChar[i];
|
|
103
|
+
if (name.indexOf(ch) !== -1) throw new Error(`Invalid character ${ch} in entity name`);
|
|
104
|
+
}
|
|
105
|
+
return name;
|
|
104
106
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import {JsObjOutputBuilder} from './OutputBuilders/JsObjBuilder.js';
|
|
2
|
+
import { JsObjOutputBuilder } from './OutputBuilders/JsObjBuilder.js';
|
|
3
3
|
|
|
4
4
|
export const defaultOptions = {
|
|
5
5
|
preserveOrder: false,
|
|
@@ -9,16 +9,16 @@ export const defaultOptions = {
|
|
|
9
9
|
// isArray: () => false, //User will set it
|
|
10
10
|
htmlEntities: false,
|
|
11
11
|
// skipEmptyListItem: false
|
|
12
|
-
tags:{
|
|
12
|
+
tags: {
|
|
13
13
|
unpaired: [],
|
|
14
|
-
nameFor:{
|
|
14
|
+
nameFor: {
|
|
15
15
|
cdata: false,
|
|
16
16
|
comment: false,
|
|
17
17
|
text: '#text'
|
|
18
18
|
},
|
|
19
19
|
separateTextProperty: false,
|
|
20
20
|
},
|
|
21
|
-
attributes:{
|
|
21
|
+
attributes: {
|
|
22
22
|
ignore: false,
|
|
23
23
|
booleanType: true,
|
|
24
24
|
entities: true,
|
|
@@ -34,19 +34,19 @@ export const defaultOptions = {
|
|
|
34
34
|
stop: [], //given tagPath will not be parsed. innerXML will be set as string value
|
|
35
35
|
OutputBuilder: new JsObjOutputBuilder(),
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
export const buildOptions = function(options) {
|
|
39
|
-
const finalOptions = { ...
|
|
40
|
-
copyProperties(finalOptions,options)
|
|
37
|
+
|
|
38
|
+
export const buildOptions = function (options) {
|
|
39
|
+
const finalOptions = { ...defaultOptions };
|
|
40
|
+
copyProperties(finalOptions, options)
|
|
41
41
|
return finalOptions;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
function copyProperties(target, source) {
|
|
45
45
|
for (let key in source) {
|
|
46
|
-
if (
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
47
47
|
if (key === 'OutputBuilder') {
|
|
48
48
|
target[key] = source[key];
|
|
49
|
-
}else if (typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
49
|
+
} else if (typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
50
50
|
// Recursively copy nested properties
|
|
51
51
|
if (typeof target[key] === 'undefined') {
|
|
52
52
|
target[key] = {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export default class BaseOutputBuilder{
|
|
2
|
-
constructor(){
|
|
1
|
+
export default class BaseOutputBuilder {
|
|
2
|
+
constructor() {
|
|
3
3
|
// this.attributes = {};
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
addAttribute(name, value){
|
|
7
|
-
if(this.options.onAttribute){
|
|
6
|
+
addAttribute(name, value) {
|
|
7
|
+
if (this.options.onAttribute) {
|
|
8
8
|
//TODO: better to pass tag path
|
|
9
9
|
const v = this.options.onAttribute(name, value, this.tagName);
|
|
10
|
-
if(v) this.attributes[v.name] = v.value;
|
|
11
|
-
}else{
|
|
10
|
+
if (v) this.attributes[v.name] = v.value;
|
|
11
|
+
} else {
|
|
12
12
|
name = this.options.attributes.prefix + name + this.options.attributes.suffix;
|
|
13
13
|
this.attributes[name] = this.parseValue(value, this.options.attributes.valueParsers);
|
|
14
14
|
}
|
|
@@ -19,37 +19,37 @@ export default class BaseOutputBuilder{
|
|
|
19
19
|
* @param {string} val
|
|
20
20
|
* @returns {any} parsed value if matching parser found
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
22
|
+
parseValue = function (val, valParsers) {
|
|
23
|
+
for (let i = 0; i < valParsers.length; i++) {
|
|
24
|
+
let valParser = valParsers[i];
|
|
25
|
+
if (typeof valParser === "string") {
|
|
26
|
+
valParser = this.registeredParsers[valParser];
|
|
27
|
+
}
|
|
28
|
+
if (valParser) {
|
|
29
|
+
val = valParser.parse(val);
|
|
31
30
|
}
|
|
32
|
-
return val;
|
|
33
31
|
}
|
|
32
|
+
return val;
|
|
33
|
+
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* To add a nested empty tag.
|
|
37
37
|
* @param {string} key
|
|
38
38
|
* @param {any} val
|
|
39
39
|
*/
|
|
40
|
-
_addChild(key, val){}
|
|
40
|
+
_addChild(key, val) { }
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* skip the comment if property is not set
|
|
44
44
|
*/
|
|
45
|
-
addComment(text){
|
|
46
|
-
if(this.options.nameFor.comment)
|
|
45
|
+
addComment(text) {
|
|
46
|
+
if (this.options.nameFor.comment)
|
|
47
47
|
this._addChild(this.options.nameFor.comment, text);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
//store CDATA separately if property is set
|
|
51
51
|
//otherwise add to tag's value
|
|
52
|
-
addCdata(text){
|
|
52
|
+
addCdata(text) {
|
|
53
53
|
if (this.options.nameFor.cdata) {
|
|
54
54
|
this._addChild(this.options.nameFor.cdata, text);
|
|
55
55
|
} else {
|
|
@@ -59,9 +59,9 @@ export default class BaseOutputBuilder{
|
|
|
59
59
|
|
|
60
60
|
addRawValue = text => this.addValue(text);
|
|
61
61
|
|
|
62
|
-
addDeclaration(){
|
|
63
|
-
if(!this.options.declaration){
|
|
64
|
-
}else{
|
|
62
|
+
addDeclaration() {
|
|
63
|
+
if (!this.options.declaration) {
|
|
64
|
+
} else {
|
|
65
65
|
this.addPi("?xml");
|
|
66
66
|
}
|
|
67
67
|
this.attributes = {}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {buildOptions,registerCommonValueParsers} from './ParserOptionsBuilder.js';
|
|
1
|
+
import { buildOptions, registerCommonValueParsers } from './ParserOptionsBuilder.js';
|
|
2
2
|
|
|
3
|
-
export default class OutputBuilder{
|
|
4
|
-
constructor(options){
|
|
3
|
+
export default class OutputBuilder {
|
|
4
|
+
constructor(options) {
|
|
5
5
|
this.options = buildOptions(options);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
this.registeredParsers = registerCommonValueParsers(this.options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
registerValueParser(name, parserInstance) {//existing name will override the parser without warning
|
|
10
|
+
this.registeredParsers[name] = parserInstance;
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
getInstance(parserOptions){
|
|
13
|
+
getInstance(parserOptions) {
|
|
14
14
|
return new JsArrBuilder(parserOptions, this.options, this.registeredParsers);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -18,9 +18,9 @@ export default class OutputBuilder{
|
|
|
18
18
|
const rootName = '!js_arr';
|
|
19
19
|
import BaseOutputBuilder from './BaseOutputBuilder.js';
|
|
20
20
|
|
|
21
|
-
class JsArrBuilder extends BaseOutputBuilder{
|
|
21
|
+
class JsArrBuilder extends BaseOutputBuilder {
|
|
22
22
|
|
|
23
|
-
constructor(parserOptions, options,registeredParsers) {
|
|
23
|
+
constructor(parserOptions, options, registeredParsers) {
|
|
24
24
|
super();
|
|
25
25
|
this.tagsStack = [];
|
|
26
26
|
this.parserOptions = parserOptions;
|
|
@@ -32,10 +32,10 @@ class JsArrBuilder extends BaseOutputBuilder{
|
|
|
32
32
|
this.attributes = {};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
addTag(tag){
|
|
35
|
+
addTag(tag) {
|
|
36
36
|
//when a new tag is added, it should be added as child of current node
|
|
37
37
|
//TODO: shift this check to the parser
|
|
38
|
-
if(tag.name === "__proto__") tag.name = "#__proto__";
|
|
38
|
+
if (tag.name === "__proto__") tag.name = "#__proto__";
|
|
39
39
|
|
|
40
40
|
this.tagsStack.push(this.currentNode);
|
|
41
41
|
this.currentNode = new Node(tag.name, this.attributes);
|
|
@@ -47,23 +47,23 @@ class JsArrBuilder extends BaseOutputBuilder{
|
|
|
47
47
|
* @param {Node} node
|
|
48
48
|
* @returns boolean: true if the node should not be added
|
|
49
49
|
*/
|
|
50
|
-
closeTag(){
|
|
50
|
+
closeTag() {
|
|
51
51
|
const node = this.currentNode;
|
|
52
52
|
this.currentNode = this.tagsStack.pop(); //set parent node in scope
|
|
53
|
-
if(this.options.onClose !== undefined){
|
|
53
|
+
if (this.options.onClose !== undefined) {
|
|
54
54
|
//TODO TagPathMatcher
|
|
55
|
-
const resultTag = this.options.onClose(node,
|
|
56
|
-
new TagPathMatcher(this.tagsStack,node));
|
|
55
|
+
const resultTag = this.options.onClose(node,
|
|
56
|
+
new TagPathMatcher(this.tagsStack, node));
|
|
57
57
|
|
|
58
|
-
if(resultTag) return;
|
|
58
|
+
if (resultTag) return;
|
|
59
59
|
}
|
|
60
60
|
this.currentNode.child.push(node); //to parent node
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
//Called by parent class methods
|
|
64
|
-
_addChild(key, val){
|
|
64
|
+
_addChild(key, val) {
|
|
65
65
|
// if(key === "__proto__") tagName = "#__proto__";
|
|
66
|
-
this.currentNode.child.push(
|
|
66
|
+
this.currentNode.child.push({ [key]: val });
|
|
67
67
|
// this.currentNode.leafType = false;
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -71,31 +71,31 @@ class JsArrBuilder extends BaseOutputBuilder{
|
|
|
71
71
|
* Add text value child node
|
|
72
72
|
* @param {string} text
|
|
73
73
|
*/
|
|
74
|
-
addValue(text){
|
|
75
|
-
this.currentNode.child.push(
|
|
74
|
+
addValue(text) {
|
|
75
|
+
this.currentNode.child.push({ [this.options.nameFor.text]: this.parseValue(text, this.options.tags.valueParsers) });
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
addPi(name){
|
|
78
|
+
addPi(name) {
|
|
79
79
|
//TODO: set pi flag
|
|
80
|
-
if(!this.options.ignorePiTags){
|
|
80
|
+
if (!this.options.ignorePiTags) {
|
|
81
81
|
const node = new Node(name, this.attributes);
|
|
82
82
|
this.currentNode[":@"] = this.attributes;
|
|
83
83
|
this.currentNode.child.push(node);
|
|
84
84
|
}
|
|
85
85
|
this.attributes = {};
|
|
86
86
|
}
|
|
87
|
-
getOutput(){
|
|
87
|
+
getOutput() {
|
|
88
88
|
return this.root.child[0];
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
class Node{
|
|
95
|
-
constructor(tagname, attributes){
|
|
94
|
+
class Node {
|
|
95
|
+
constructor(tagname, attributes) {
|
|
96
96
|
this.tagname = tagname;
|
|
97
97
|
this.child = []; //nested tags, text, cdata, comments
|
|
98
|
-
if(attributes && Object.keys(attributes).length > 0)
|
|
98
|
+
if (attributes && Object.keys(attributes).length > 0)
|
|
99
99
|
this[":@"] = attributes;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import {buildOptions,registerCommonValueParsers} from './ParserOptionsBuilder.js';
|
|
3
|
+
import { buildOptions, registerCommonValueParsers } from './ParserOptionsBuilder.js';
|
|
4
4
|
|
|
5
|
-
export default class OutputBuilder{
|
|
6
|
-
constructor(builderOptions){
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export default class OutputBuilder {
|
|
6
|
+
constructor(builderOptions) {
|
|
7
|
+
this.options = buildOptions(builderOptions);
|
|
8
|
+
this.registeredParsers = registerCommonValueParsers(this.options);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
registerValueParser(name,parserInstance){//existing name will override the parser without warning
|
|
11
|
+
registerValueParser(name, parserInstance) {//existing name will override the parser without warning
|
|
12
12
|
this.registeredParsers[name] = parserInstance;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
getInstance(parserOptions){
|
|
15
|
+
getInstance(parserOptions) {
|
|
16
16
|
return new JsObjBuilder(parserOptions, this.options, this.registeredParsers);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -20,9 +20,9 @@ export default class OutputBuilder{
|
|
|
20
20
|
import BaseOutputBuilder from './BaseOutputBuilder.js';
|
|
21
21
|
const rootName = '^';
|
|
22
22
|
|
|
23
|
-
class JsObjBuilder extends BaseOutputBuilder{
|
|
23
|
+
class JsObjBuilder extends BaseOutputBuilder {
|
|
24
24
|
|
|
25
|
-
constructor(parserOptions, builderOptions,registeredParsers) {
|
|
25
|
+
constructor(parserOptions, builderOptions, registeredParsers) {
|
|
26
26
|
super();
|
|
27
27
|
//hold the raw detail of a tag and sequence with reference to the output
|
|
28
28
|
this.tagsStack = [];
|
|
@@ -38,14 +38,14 @@ class JsObjBuilder extends BaseOutputBuilder{
|
|
|
38
38
|
this.attributes = {};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
addTag(tag){
|
|
41
|
+
addTag(tag) {
|
|
42
42
|
|
|
43
43
|
let value = "";
|
|
44
|
-
if(
|
|
44
|
+
if (!isEmpty(this.attributes)) {
|
|
45
45
|
value = {};
|
|
46
|
-
if(this.options.attributes.groupBy){
|
|
46
|
+
if (this.options.attributes.groupBy) {
|
|
47
47
|
value[this.options.attributes.groupBy] = this.attributes;
|
|
48
|
-
}else{
|
|
48
|
+
} else {
|
|
49
49
|
value = this.attributes;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -62,44 +62,44 @@ class JsObjBuilder extends BaseOutputBuilder{
|
|
|
62
62
|
* @param {Node} node
|
|
63
63
|
* @returns boolean: true if the node should not be added
|
|
64
64
|
*/
|
|
65
|
-
closeTag(){
|
|
65
|
+
closeTag() {
|
|
66
66
|
const tagName = this.tagName;
|
|
67
67
|
let value = this.value;
|
|
68
68
|
let textValue = this.textValue;
|
|
69
69
|
|
|
70
70
|
//update tag text value
|
|
71
|
-
if(typeof value !== "object" && !Array.isArray(value)){
|
|
71
|
+
if (typeof value !== "object" && !Array.isArray(value)) {
|
|
72
72
|
value = this.parseValue(textValue.trim(), this.options.tags.valueParsers);
|
|
73
|
-
}else if(textValue.length > 0){
|
|
73
|
+
} else if (textValue.length > 0) {
|
|
74
74
|
value[this.options.nameFor.text] = this.parseValue(textValue.trim(), this.options.tags.valueParsers);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
let resultTag= {
|
|
77
|
+
|
|
78
|
+
let resultTag = {
|
|
79
79
|
tagName: tagName,
|
|
80
80
|
value: value
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
if(this.options.onTagClose !== undefined){
|
|
83
|
+
if (this.options.onTagClose !== undefined) {
|
|
84
84
|
//TODO TagPathMatcher
|
|
85
|
-
resultTag = this.options.onClose(tagName, value, this.textValue, new TagPathMatcher(this.tagsStack,node));
|
|
85
|
+
resultTag = this.options.onClose(tagName, value, this.textValue, new TagPathMatcher(this.tagsStack, node));
|
|
86
86
|
|
|
87
|
-
if(!resultTag) return;
|
|
87
|
+
if (!resultTag) return;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//set parent node in scope
|
|
91
|
-
let arr = this.tagsStack.pop();
|
|
91
|
+
let arr = this.tagsStack.pop();
|
|
92
92
|
let parentTag = arr[2];
|
|
93
|
-
parentTag=this._addChildTo(resultTag.tagName, resultTag.value, parentTag);
|
|
93
|
+
parentTag = this._addChildTo(resultTag.tagName, resultTag.value, parentTag);
|
|
94
94
|
|
|
95
95
|
this.tagName = arr[0];
|
|
96
96
|
this.textValue = arr[1];
|
|
97
97
|
this.value = parentTag;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
_addChild(key, val){
|
|
101
|
-
if(typeof this.value === "string"){
|
|
102
|
-
this.value = { [this.options.nameFor.text]
|
|
100
|
+
_addChild(key, val) {
|
|
101
|
+
if (typeof this.value === "string") {
|
|
102
|
+
this.value = { [this.options.nameFor.text]: this.value };
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
this._addChildTo(key, val, this.value);
|
|
@@ -107,12 +107,12 @@ class JsObjBuilder extends BaseOutputBuilder{
|
|
|
107
107
|
this.attributes = {};
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
_addChildTo(key, val, node){
|
|
111
|
-
if(typeof node === 'string') node = {};
|
|
112
|
-
if(!node[key]){
|
|
110
|
+
_addChildTo(key, val, node) {
|
|
111
|
+
if (typeof node === 'string') node = {};
|
|
112
|
+
if (!node[key]) {
|
|
113
113
|
node[key] = val;
|
|
114
|
-
}else{ //Repeated
|
|
115
|
-
if(!Array.isArray(node[key])){ //but not stored as array
|
|
114
|
+
} else { //Repeated
|
|
115
|
+
if (!Array.isArray(node[key])) { //but not stored as array
|
|
116
116
|
node[key] = [node[key]];
|
|
117
117
|
}
|
|
118
118
|
node[key].push(val);
|
|
@@ -125,26 +125,26 @@ class JsObjBuilder extends BaseOutputBuilder{
|
|
|
125
125
|
* Add text value child node
|
|
126
126
|
* @param {string} text
|
|
127
127
|
*/
|
|
128
|
-
addValue(text){
|
|
128
|
+
addValue(text) {
|
|
129
129
|
//TODO: use bytes join
|
|
130
|
-
if(this.textValue.length > 0) this.textValue += " " + text;
|
|
130
|
+
if (this.textValue.length > 0) this.textValue += " " + text;
|
|
131
131
|
else this.textValue = text;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
addPi(name){
|
|
134
|
+
addPi(name) {
|
|
135
135
|
let value = "";
|
|
136
|
-
if(
|
|
136
|
+
if (!isEmpty(this.attributes)) {
|
|
137
137
|
value = {};
|
|
138
|
-
if(this.options.attributes.groupBy){
|
|
138
|
+
if (this.options.attributes.groupBy) {
|
|
139
139
|
value[this.options.attributes.groupBy] = this.attributes;
|
|
140
|
-
}else{
|
|
140
|
+
} else {
|
|
141
141
|
value = this.attributes;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
this._addChild(name, value);
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
}
|
|
147
|
-
getOutput(){
|
|
147
|
+
getOutput() {
|
|
148
148
|
return this.value;
|
|
149
149
|
}
|
|
150
150
|
}
|