@cdk8s/awscdk-resolver 0.0.135 → 0.0.136

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.
Files changed (170) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/dist-cjs/index.js +9 -15
  4. package/node_modules/@aws-sdk/client-cloudformation/dist-es/CloudFormationClient.js +9 -15
  5. package/node_modules/@aws-sdk/client-cloudformation/dist-types/CloudFormationClient.d.ts +2 -4
  6. package/node_modules/@aws-sdk/client-cloudformation/dist-types/auth/httpAuthSchemeProvider.d.ts +4 -4
  7. package/node_modules/@aws-sdk/client-cloudformation/dist-types/runtimeConfig.browser.d.ts +2 -2
  8. package/node_modules/@aws-sdk/client-cloudformation/dist-types/runtimeConfig.d.ts +2 -2
  9. package/node_modules/@aws-sdk/client-cloudformation/dist-types/runtimeConfig.native.d.ts +2 -2
  10. package/node_modules/@aws-sdk/client-cloudformation/dist-types/ts3.4/CloudFormationClient.d.ts +6 -8
  11. package/node_modules/@aws-sdk/client-cloudformation/dist-types/ts3.4/runtimeConfig.browser.d.ts +5 -5
  12. package/node_modules/@aws-sdk/client-cloudformation/dist-types/ts3.4/runtimeConfig.d.ts +5 -5
  13. package/node_modules/@aws-sdk/client-cloudformation/dist-types/ts3.4/runtimeConfig.native.d.ts +5 -5
  14. package/node_modules/@aws-sdk/client-cloudformation/package.json +18 -18
  15. package/node_modules/@aws-sdk/client-sso/dist-cjs/index.js +9 -15
  16. package/node_modules/@aws-sdk/client-sso/dist-es/SSOClient.js +9 -15
  17. package/node_modules/@aws-sdk/client-sso/dist-types/SSOClient.d.ts +2 -4
  18. package/node_modules/@aws-sdk/client-sso/dist-types/auth/httpAuthSchemeProvider.d.ts +4 -4
  19. package/node_modules/@aws-sdk/client-sso/dist-types/runtimeConfig.browser.d.ts +2 -2
  20. package/node_modules/@aws-sdk/client-sso/dist-types/runtimeConfig.d.ts +2 -2
  21. package/node_modules/@aws-sdk/client-sso/dist-types/runtimeConfig.native.d.ts +2 -2
  22. package/node_modules/@aws-sdk/client-sso/dist-types/ts3.4/SSOClient.d.ts +6 -8
  23. package/node_modules/@aws-sdk/client-sso/dist-types/ts3.4/runtimeConfig.browser.d.ts +5 -5
  24. package/node_modules/@aws-sdk/client-sso/dist-types/ts3.4/runtimeConfig.d.ts +5 -5
  25. package/node_modules/@aws-sdk/client-sso/dist-types/ts3.4/runtimeConfig.native.d.ts +5 -5
  26. package/node_modules/@aws-sdk/client-sso/package.json +15 -15
  27. package/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/index.js +9 -15
  28. package/node_modules/@aws-sdk/client-sso-oidc/dist-es/SSOOIDCClient.js +9 -15
  29. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/SSOOIDCClient.d.ts +2 -4
  30. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/auth/httpAuthSchemeProvider.d.ts +4 -4
  31. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/runtimeConfig.browser.d.ts +2 -2
  32. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/runtimeConfig.d.ts +2 -2
  33. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/runtimeConfig.native.d.ts +2 -2
  34. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/ts3.4/SSOOIDCClient.d.ts +6 -8
  35. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/ts3.4/runtimeConfig.browser.d.ts +5 -5
  36. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/ts3.4/runtimeConfig.d.ts +5 -5
  37. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/ts3.4/runtimeConfig.native.d.ts +5 -5
  38. package/node_modules/@aws-sdk/client-sso-oidc/package.json +17 -17
  39. package/node_modules/@aws-sdk/client-sts/dist-cjs/STSClient.js +9 -15
  40. package/node_modules/@aws-sdk/client-sts/dist-cjs/index.js +17 -4
  41. package/node_modules/@aws-sdk/client-sts/dist-es/STSClient.js +9 -15
  42. package/node_modules/@aws-sdk/client-sts/dist-es/defaultStsRoleAssumers.js +17 -4
  43. package/node_modules/@aws-sdk/client-sts/dist-types/STSClient.d.ts +2 -4
  44. package/node_modules/@aws-sdk/client-sts/dist-types/auth/httpAuthSchemeProvider.d.ts +4 -4
  45. package/node_modules/@aws-sdk/client-sts/dist-types/runtimeConfig.browser.d.ts +2 -2
  46. package/node_modules/@aws-sdk/client-sts/dist-types/runtimeConfig.d.ts +2 -2
  47. package/node_modules/@aws-sdk/client-sts/dist-types/runtimeConfig.native.d.ts +2 -2
  48. package/node_modules/@aws-sdk/client-sts/dist-types/ts3.4/STSClient.d.ts +6 -8
  49. package/node_modules/@aws-sdk/client-sts/dist-types/ts3.4/runtimeConfig.browser.d.ts +5 -5
  50. package/node_modules/@aws-sdk/client-sts/dist-types/ts3.4/runtimeConfig.d.ts +5 -5
  51. package/node_modules/@aws-sdk/client-sts/dist-types/ts3.4/runtimeConfig.native.d.ts +5 -5
  52. package/node_modules/@aws-sdk/client-sts/package.json +17 -17
  53. package/node_modules/@aws-sdk/core/account-id-endpoint.js +6 -0
  54. package/node_modules/@aws-sdk/core/dist-cjs/submodules/account-id-endpoint/index.js +97 -0
  55. package/node_modules/@aws-sdk/core/dist-es/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.js +15 -0
  56. package/node_modules/@aws-sdk/core/dist-es/submodules/account-id-endpoint/AccountIdEndpointModeConstants.js +5 -0
  57. package/node_modules/@aws-sdk/core/dist-es/submodules/account-id-endpoint/NodeAccountIdEndpointModeConfigOptions.js +24 -0
  58. package/node_modules/@aws-sdk/core/dist-es/submodules/account-id-endpoint/index.js +3 -0
  59. package/node_modules/@aws-sdk/core/dist-types/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.d.ts +30 -0
  60. package/node_modules/@aws-sdk/core/dist-types/submodules/account-id-endpoint/AccountIdEndpointModeConstants.d.ts +7 -0
  61. package/node_modules/@aws-sdk/core/dist-types/submodules/account-id-endpoint/NodeAccountIdEndpointModeConfigOptions.d.ts +14 -0
  62. package/node_modules/@aws-sdk/core/dist-types/submodules/account-id-endpoint/index.d.ts +3 -0
  63. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.d.ts +15 -0
  64. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/account-id-endpoint/AccountIdEndpointModeConstants.d.ts +6 -0
  65. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/account-id-endpoint/NodeAccountIdEndpointModeConfigOptions.d.ts +7 -0
  66. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/account-id-endpoint/index.d.ts +3 -0
  67. package/node_modules/@aws-sdk/core/package.json +18 -8
  68. package/node_modules/@aws-sdk/credential-provider-env/dist-cjs/index.js +6 -1
  69. package/node_modules/@aws-sdk/credential-provider-env/dist-es/fromEnv.js +3 -0
  70. package/node_modules/@aws-sdk/credential-provider-env/dist-types/fromEnv.d.ts +4 -0
  71. package/node_modules/@aws-sdk/credential-provider-env/dist-types/ts3.4/fromEnv.d.ts +1 -0
  72. package/node_modules/@aws-sdk/credential-provider-env/package.json +1 -1
  73. package/node_modules/@aws-sdk/credential-provider-http/package.json +6 -6
  74. package/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/index.js +3 -2
  75. package/node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveStaticCredentials.js +4 -2
  76. package/node_modules/@aws-sdk/credential-provider-ini/dist-types/resolveStaticCredentials.d.ts +1 -0
  77. package/node_modules/@aws-sdk/credential-provider-ini/dist-types/ts3.4/resolveStaticCredentials.d.ts +1 -0
  78. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  79. package/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js +30 -6
  80. package/node_modules/@aws-sdk/credential-provider-node/dist-es/defaultProvider.js +29 -9
  81. package/node_modules/@aws-sdk/credential-provider-node/package.json +8 -8
  82. package/node_modules/@aws-sdk/credential-provider-process/dist-cjs/index.js +9 -3
  83. package/node_modules/@aws-sdk/credential-provider-process/dist-es/getValidatedProcessCredentials.js +6 -1
  84. package/node_modules/@aws-sdk/credential-provider-process/dist-es/resolveProcessCredentials.js +1 -1
  85. package/node_modules/@aws-sdk/credential-provider-process/dist-types/ProcessCredentials.d.ts +1 -0
  86. package/node_modules/@aws-sdk/credential-provider-process/dist-types/getValidatedProcessCredentials.d.ts +2 -2
  87. package/node_modules/@aws-sdk/credential-provider-process/dist-types/ts3.4/ProcessCredentials.d.ts +1 -0
  88. package/node_modules/@aws-sdk/credential-provider-process/dist-types/ts3.4/getValidatedProcessCredentials.d.ts +3 -2
  89. package/node_modules/@aws-sdk/credential-provider-process/package.json +1 -1
  90. package/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/index.js +11 -2
  91. package/node_modules/@aws-sdk/credential-provider-sso/dist-es/resolveSSOCredentials.js +9 -2
  92. package/node_modules/@aws-sdk/credential-provider-sso/package.json +3 -3
  93. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  94. package/node_modules/@aws-sdk/middleware-host-header/package.json +2 -2
  95. package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +2 -2
  96. package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
  97. package/node_modules/@smithy/core/dist-cjs/index.js +4 -2
  98. package/node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js +2 -1
  99. package/node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js +2 -1
  100. package/node_modules/@smithy/core/package.json +5 -5
  101. package/node_modules/@smithy/credential-provider-imds/dist-cjs/index.js +2 -1
  102. package/node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/ImdsCredentials.js +1 -0
  103. package/node_modules/@smithy/credential-provider-imds/dist-types/remoteProvider/ImdsCredentials.d.ts +1 -0
  104. package/node_modules/@smithy/credential-provider-imds/dist-types/ts3.4/remoteProvider/ImdsCredentials.d.ts +1 -0
  105. package/node_modules/@smithy/credential-provider-imds/package.json +1 -1
  106. package/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js +2 -1
  107. package/node_modules/@smithy/fetch-http-handler/dist-es/fetch-http-handler.js +1 -1
  108. package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
  109. package/node_modules/@smithy/middleware-content-length/package.json +3 -3
  110. package/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js +7 -0
  111. package/node_modules/@smithy/middleware-endpoint/dist-es/adaptors/createConfigValueProvider.js +7 -0
  112. package/node_modules/@smithy/middleware-endpoint/package.json +1 -1
  113. package/node_modules/@smithy/middleware-retry/package.json +4 -4
  114. package/node_modules/@smithy/node-http-handler/package.json +2 -2
  115. package/node_modules/@smithy/protocol-http/package.json +1 -1
  116. package/node_modules/@smithy/signature-v4/dist-cjs/index.js +4 -16
  117. package/node_modules/@smithy/signature-v4/dist-es/moveHeadersToQuery.js +2 -2
  118. package/node_modules/@smithy/signature-v4/dist-es/prepareRequest.js +2 -2
  119. package/node_modules/@smithy/signature-v4/dist-types/SignatureV4.d.ts +1 -1
  120. package/node_modules/@smithy/signature-v4/dist-types/moveHeadersToQuery.d.ts +3 -3
  121. package/node_modules/@smithy/signature-v4/dist-types/prepareRequest.d.ts +2 -2
  122. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/SignatureV4.d.ts +1 -1
  123. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/moveHeadersToQuery.d.ts +3 -3
  124. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/prepareRequest.d.ts +2 -2
  125. package/node_modules/@smithy/signature-v4/package.json +2 -2
  126. package/node_modules/@smithy/smithy-client/dist-cjs/index.js +1 -0
  127. package/node_modules/@smithy/smithy-client/dist-es/command.js +1 -0
  128. package/node_modules/@smithy/smithy-client/package.json +4 -4
  129. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  130. package/node_modules/@smithy/util-defaults-mode-node/package.json +3 -3
  131. package/node_modules/@smithy/util-stream/dist-types/stream-type-check.d.ts +9 -1
  132. package/node_modules/@smithy/util-stream/dist-types/ts3.4/stream-type-check.d.ts +9 -1
  133. package/node_modules/@smithy/util-stream/package.json +4 -4
  134. package/node_modules/fast-xml-parser/CHANGELOG.md +349 -309
  135. package/node_modules/fast-xml-parser/README.md +83 -51
  136. package/node_modules/fast-xml-parser/package.json +8 -5
  137. package/node_modules/fast-xml-parser/src/fxp.d.ts +365 -71
  138. package/node_modules/fast-xml-parser/src/v5/CharsSymbol.js +16 -0
  139. package/node_modules/fast-xml-parser/src/v5/EntitiesParser.js +107 -0
  140. package/node_modules/fast-xml-parser/src/v5/OptionsBuilder.js +64 -0
  141. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/BaseOutputBuilder.js +71 -0
  142. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/JsArrBuilder.js +103 -0
  143. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/JsMinArrBuilder.js +102 -0
  144. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/JsObjBuilder.js +156 -0
  145. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/ParserOptionsBuilder.js +99 -0
  146. package/node_modules/fast-xml-parser/src/v5/Report.js +0 -0
  147. package/node_modules/fast-xml-parser/src/v5/TagPath.js +81 -0
  148. package/node_modules/fast-xml-parser/src/v5/TagPathMatcher.js +15 -0
  149. package/node_modules/fast-xml-parser/src/v5/XMLParser.js +85 -0
  150. package/node_modules/fast-xml-parser/src/v5/Xml2JsParser.js +237 -0
  151. package/node_modules/fast-xml-parser/src/v5/XmlPartReader.js +212 -0
  152. package/node_modules/fast-xml-parser/src/v5/XmlSpecialTagsReader.js +118 -0
  153. package/node_modules/fast-xml-parser/src/v5/inputSource/BufferSource.js +118 -0
  154. package/node_modules/fast-xml-parser/src/v5/inputSource/StringSource.js +123 -0
  155. package/node_modules/fast-xml-parser/src/v5/valueParsers/EntitiesParser.js +107 -0
  156. package/node_modules/fast-xml-parser/src/v5/valueParsers/booleanParser.js +23 -0
  157. package/node_modules/fast-xml-parser/src/v5/valueParsers/booleanParserExt.js +20 -0
  158. package/node_modules/fast-xml-parser/src/v5/valueParsers/currency.js +40 -0
  159. package/node_modules/fast-xml-parser/src/v5/valueParsers/join.js +14 -0
  160. package/node_modules/fast-xml-parser/src/v5/valueParsers/number.js +16 -0
  161. package/node_modules/fast-xml-parser/src/v5/valueParsers/trim.js +8 -0
  162. package/node_modules/fast-xml-parser/src/validator.js +2 -0
  163. package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +31 -9
  164. package/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js +4 -0
  165. package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +25 -12
  166. package/package.json +8 -8
  167. package/node_modules/@smithy/signature-v4/dist-cjs/cloneRequest.js +0 -1
  168. package/node_modules/@smithy/signature-v4/dist-es/cloneRequest.js +0 -12
  169. package/node_modules/@smithy/signature-v4/dist-types/cloneRequest.d.ts +0 -6
  170. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/cloneRequest.d.ts +0 -6
@@ -0,0 +1,85 @@
1
+ const { buildOptions} = require("./OptionsBuilder");
2
+ const Xml2JsParser = require("./Xml2JsParser");
3
+
4
+ class XMLParser{
5
+
6
+ constructor(options){
7
+ this.externalEntities = {};
8
+ this.options = buildOptions(options);
9
+ // console.log(this.options)
10
+ }
11
+ /**
12
+ * Parse XML data string to JS object
13
+ * @param {string|Buffer} xmlData
14
+ * @param {boolean|Object} validationOption
15
+ */
16
+ parse(xmlData){
17
+ if(Array.isArray(xmlData) && xmlData.byteLength !== undefined){
18
+ return this.parse(xmlData);
19
+ }else if( xmlData.toString){
20
+ xmlData = xmlData.toString();
21
+ }else{
22
+ throw new Error("XML data is accepted in String or Bytes[] form.")
23
+ }
24
+ // if( validationOption){
25
+ // if(validationOption === true) validationOption = {}; //validate with default options
26
+
27
+ // const result = validator.validate(xmlData, validationOption);
28
+ // if (result !== true) {
29
+ // throw Error( `${result.err.msg}:${result.err.line}:${result.err.col}` )
30
+ // }
31
+ // }
32
+ const parser = new Xml2JsParser(this.options);
33
+ parser.entityParser.addExternalEntities(this.externalEntities);
34
+ return parser.parse(xmlData);
35
+ }
36
+ /**
37
+ * Parse XML data buffer to JS object
38
+ * @param {string|Buffer} xmlData
39
+ * @param {boolean|Object} validationOption
40
+ */
41
+ parseBytesArr(xmlData){
42
+ if(Array.isArray(xmlData) && xmlData.byteLength !== undefined){
43
+ }else{
44
+ throw new Error("XML data is accepted in Bytes[] form.")
45
+ }
46
+ const parser = new Xml2JsParser(this.options);
47
+ parser.entityParser.addExternalEntities(this.externalEntities);
48
+ return parser.parseBytesArr(xmlData);
49
+ }
50
+ /**
51
+ * Parse XML data stream to JS object
52
+ * @param {fs.ReadableStream} xmlDataStream
53
+ */
54
+ parseStream(xmlDataStream){
55
+ if(!isStream(xmlDataStream)) throw new Error("FXP: Invalid stream input");
56
+
57
+ const orderedObjParser = new Xml2JsParser(this.options);
58
+ orderedObjParser.entityParser.addExternalEntities(this.externalEntities);
59
+ return orderedObjParser.parseStream(xmlDataStream);
60
+ }
61
+
62
+ /**
63
+ * Add Entity which is not by default supported by this library
64
+ * @param {string} key
65
+ * @param {string} value
66
+ */
67
+ addEntity(key, value){
68
+ if(value.indexOf("&") !== -1){
69
+ throw new Error("Entity value can't have '&'")
70
+ }else if(key.indexOf("&") !== -1 || key.indexOf(";") !== -1){
71
+ throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'")
72
+ }else if(value === "&"){
73
+ throw new Error("An entity with value '&' is not permitted");
74
+ }else{
75
+ this.externalEntities[key] = value;
76
+ }
77
+ }
78
+ }
79
+
80
+ function isStream(stream){
81
+ if(stream && typeof stream.read === "function" && typeof stream.on === "function" && typeof stream.readableEnded === "boolean") return true;
82
+ return false;
83
+ }
84
+
85
+ module.exports = XMLParser;
@@ -0,0 +1,237 @@
1
+ const StringSource = require("./inputSource/StringSource");
2
+ const BufferSource = require("./inputSource/BufferSource");
3
+ const {readTagExp,readClosingTagName} = require("./XmlPartReader");
4
+ const {readComment, readCdata,readDocType,readPiTag} = require("./XmlSpecialTagsReader");
5
+ const TagPath = require("./TagPath");
6
+ const TagPathMatcher = require("./TagPathMatcher");
7
+ const EntitiesParser = require('./EntitiesParser');
8
+
9
+ //To hold the data of current tag
10
+ //This is usually used to compare jpath expression against current tag
11
+ class TagDetail{
12
+ constructor(name){
13
+ this.name = name;
14
+ this.position = 0;
15
+ // this.attributes = {};
16
+ }
17
+ }
18
+
19
+ class Xml2JsParser {
20
+ constructor(options) {
21
+ this.options = options;
22
+
23
+ this.currentTagDetail = null;
24
+ this.tagTextData = "";
25
+ this.tagsStack = [];
26
+ this.entityParser = new EntitiesParser(options.htmlEntities);
27
+ this.stopNodes = [];
28
+ for (let i = 0; i < this.options.stopNodes.length; i++) {
29
+ this.stopNodes.push(new TagPath(this.options.stopNodes[i]));
30
+ }
31
+ }
32
+
33
+ parse(strData) {
34
+ this.source = new StringSource(strData);
35
+ this.parseXml();
36
+ return this.outputBuilder.getOutput();
37
+ }
38
+ parseBytesArr(data) {
39
+ this.source = new BufferSource(data );
40
+ this.parseXml();
41
+ return this.outputBuilder.getOutput();
42
+ }
43
+
44
+ parseXml() {
45
+ //TODO: Separate TagValueParser as separate class. So no scope issue in node builder class
46
+
47
+ //OutputBuilder should be set in XML Parser
48
+ this.outputBuilder = this.options.OutputBuilder.getInstance(this.options);
49
+ this.root = { root: true};
50
+ this.currentTagDetail = this.root;
51
+
52
+ while(this.source.canRead()){
53
+ let ch = this.source.readCh();
54
+ if (ch === "") break;
55
+
56
+ if(ch === "<"){//tagStart
57
+ let nextChar = this.source.readChAt(0);
58
+ if (nextChar === "" ) throw new Error("Unexpected end of source");
59
+
60
+
61
+ if(nextChar === "!" || nextChar === "?"){
62
+ this.source.updateBufferBoundary();
63
+ //previously collected text should be added to current node
64
+ this.addTextNode();
65
+
66
+ this.readSpecialTag(nextChar);// Read DOCTYPE, comment, CDATA, PI tag
67
+ }else if(nextChar === "/"){
68
+ this.source.updateBufferBoundary();
69
+ this.readClosingTag();
70
+ // console.log(this.source.buffer.length, this.source.readable);
71
+ // console.log(this.tagsStack.length);
72
+ }else{//opening tag
73
+ this.readOpeningTag();
74
+ }
75
+ }else{
76
+ this.tagTextData += ch;
77
+ }
78
+ }//End While loop
79
+ if(this.tagsStack.length > 0 || ( this.tagTextData !== "undefined" && this.tagTextData.trimEnd().length > 0) ) throw new Error("Unexpected data in the end of document");
80
+ }
81
+
82
+ /**
83
+ * read closing paired tag. Set parent tag in scope.
84
+ * skip a node on user's choice
85
+ */
86
+ readClosingTag(){
87
+ const tagName = this.processTagName(readClosingTagName(this.source));
88
+ // console.log(tagName, this.tagsStack.length);
89
+ this.validateClosingTag(tagName);
90
+ // All the text data collected, belongs to current tag.
91
+ if(!this.currentTagDetail.root) this.addTextNode();
92
+ this.outputBuilder.closeTag();
93
+ // Since the tag is closed now, parent tag comes in scope
94
+ this.currentTagDetail = this.tagsStack.pop();
95
+ }
96
+
97
+ validateClosingTag(tagName){
98
+ // This can't be unpaired tag, or a stop tag.
99
+ if(this.isUnpaired(tagName) || this.isStopNode(tagName)) throw new Error(`Unexpected closing tag '${tagName}'`);
100
+ // This must match with last opening tag
101
+ else if(tagName !== this.currentTagDetail.name)
102
+ throw new Error(`Unexpected closing tag '${tagName}' expecting '${this.currentTagDetail.name}'`)
103
+ }
104
+
105
+ /**
106
+ * Read paired, unpaired, self-closing, stop and special tags.
107
+ * Create a new node
108
+ * Push paired tag in stack.
109
+ */
110
+ readOpeningTag(){
111
+ //save previously collected text data to current node
112
+ this.addTextNode();
113
+
114
+ //create new tag
115
+ let tagExp = readTagExp(this, ">" );
116
+
117
+ // process and skip from tagsStack For unpaired tag, self closing tag, and stop node
118
+ const tagDetail = new TagDetail(tagExp.tagName);
119
+ if(this.isUnpaired(tagExp.tagName)) {
120
+ //TODO: this will lead 2 extra stack operation
121
+ this.outputBuilder.addTag(tagDetail);
122
+ this.outputBuilder.closeTag();
123
+ } else if(tagExp.selfClosing){
124
+ this.outputBuilder.addTag(tagDetail);
125
+ this.outputBuilder.closeTag();
126
+ } else if(this.isStopNode(this.currentTagDetail)){
127
+ // TODO: let's user set a stop node boundary detector for complex contents like script tag
128
+ //TODO: pass tag name only to avoid string operations
129
+ const content = source.readUptoCloseTag(`</${tagExp.tagName}`);
130
+ this.outputBuilder.addTag(tagDetail);
131
+ this.outputBuilder.addValue(content);
132
+ this.outputBuilder.closeTag();
133
+ }else{//paired tag
134
+ //set new nested tag in scope.
135
+ this.tagsStack.push(this.currentTagDetail);
136
+ this.outputBuilder.addTag(tagDetail);
137
+ this.currentTagDetail = tagDetail;
138
+ }
139
+ // console.log(tagExp.tagName,this.tagsStack.length);
140
+ // this.options.onClose()
141
+
142
+ }
143
+
144
+ readSpecialTag(startCh){
145
+ if(startCh == "!"){
146
+ let nextChar = this.source.readCh();
147
+ if (nextChar === null || nextChar === undefined) throw new Error("Unexpected ending of the source");
148
+
149
+ if(nextChar === "-"){//comment
150
+ readComment(this);
151
+ }else if(nextChar === "["){//CDATA
152
+ readCdata(this);
153
+ }else if(nextChar === "D"){//DOCTYPE
154
+ readDocType(this);
155
+ }
156
+ }else if(startCh === "?"){
157
+ readPiTag(this);
158
+ }else{
159
+ throw new Error(`Invalid tag '<${startCh}' at ${this.source.line}:${this.source.col}`)
160
+ }
161
+ }
162
+ addTextNode = function() {
163
+ // if(this.currentTagDetail){
164
+ //save text as child node
165
+ // if(this.currentTagDetail.tagname !== '!xml')
166
+ if (this.tagTextData !== undefined && this.tagTextData !== "") { //store previously collected data as textNode
167
+ if(this.tagTextData.trim().length > 0){
168
+ //TODO: shift parsing to output builder
169
+
170
+ this.outputBuilder.addValue(this.replaceEntities(this.tagTextData));
171
+ }
172
+ this.tagTextData = "";
173
+ }
174
+ // }
175
+ }
176
+
177
+ processAttrName(name){
178
+ if(name === "__proto__") name = "#__proto__";
179
+ name = resolveNameSpace(name, this.removeNSPrefix);
180
+ return name;
181
+ }
182
+
183
+ processTagName(name){
184
+ if(name === "__proto__") name = "#__proto__";
185
+ name = resolveNameSpace(name, this.removeNSPrefix);
186
+ return name;
187
+ }
188
+
189
+ /**
190
+ * Generate tags path from tagsStack
191
+ */
192
+ tagsPath(tagName){
193
+ //TODO: return TagPath Object. User can call match method with path
194
+ return "";
195
+ }
196
+
197
+ isUnpaired(tagName){
198
+ return this.options.tags.unpaired.indexOf(tagName) !== -1;
199
+ }
200
+
201
+ /**
202
+ * valid expressions are
203
+ * tag nested
204
+ * * nested
205
+ * tag nested[attribute]
206
+ * tag nested[attribute=""]
207
+ * tag nested[attribute!=""]
208
+ * tag nested:0 //for future
209
+ * @param {string} tagName
210
+ * @returns
211
+ */
212
+ isStopNode(node){
213
+ for (let i = 0; i < this.stopNodes.length; i++) {
214
+ const givenPath = this.stopNodes[i];
215
+ if(givenPath.match(this.tagsStack, node)) return true;
216
+ }
217
+ return false
218
+ }
219
+
220
+ replaceEntities(text){
221
+ //TODO: if option is set then replace entities
222
+ return this.entityParser.parse(text)
223
+ }
224
+ }
225
+
226
+ function resolveNameSpace(name, removeNSPrefix) {
227
+ if (removeNSPrefix) {
228
+ const parts = name.split(':');
229
+ if(parts.length === 2){
230
+ if (parts[0] === 'xmlns') return '';
231
+ else return parts[1];
232
+ }else reportError(`Multiple namespaces ${name}`)
233
+ }
234
+ return name;
235
+ }
236
+
237
+ module.exports = Xml2JsParser;
@@ -0,0 +1,212 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * find paired tag for a stop node
5
+ * @param {string} xmlDoc
6
+ * @param {string} tagName
7
+ * @param {number} i : start index
8
+ */
9
+ function readStopNode(xmlDoc, tagName, i){
10
+ const startIndex = i;
11
+ // Starting at 1 since we already have an open tag
12
+ let openTagCount = 1;
13
+
14
+ for (; i < xmlDoc.length; i++) {
15
+ if( xmlDoc[i] === "<"){
16
+ if (xmlDoc[i+1] === "/") {//close tag
17
+ const closeIndex = findSubStrIndex(xmlDoc, ">", i, `${tagName} is not closed`);
18
+ let closeTagName = xmlDoc.substring(i+2,closeIndex).trim();
19
+ if(closeTagName === tagName){
20
+ openTagCount--;
21
+ if (openTagCount === 0) {
22
+ return {
23
+ tagContent: xmlDoc.substring(startIndex, i),
24
+ i : closeIndex
25
+ }
26
+ }
27
+ }
28
+ i=closeIndex;
29
+ } else if(xmlDoc[i+1] === '?') {
30
+ const closeIndex = findSubStrIndex(xmlDoc, "?>", i+1, "StopNode is not closed.")
31
+ i=closeIndex;
32
+ } else if(xmlDoc.substr(i + 1, 3) === '!--') {
33
+ const closeIndex = findSubStrIndex(xmlDoc, "-->", i+3, "StopNode is not closed.")
34
+ i=closeIndex;
35
+ } else if(xmlDoc.substr(i + 1, 2) === '![') {
36
+ const closeIndex = findSubStrIndex(xmlDoc, "]]>", i, "StopNode is not closed.") - 2;
37
+ i=closeIndex;
38
+ } else {
39
+ const tagData = readTagExp(xmlDoc, i, '>')
40
+
41
+ if (tagData) {
42
+ const openTagName = tagData && tagData.tagName;
43
+ if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== "/") {
44
+ openTagCount++;
45
+ }
46
+ i=tagData.closeIndex;
47
+ }
48
+ }
49
+ }
50
+ }//end for loop
51
+ }
52
+
53
+ /**
54
+ * Read closing tag name
55
+ * @param {Source} source
56
+ * @returns tag name
57
+ */
58
+ function readClosingTagName(source){
59
+ let text = ""; //temporary data
60
+ while(source.canRead()){
61
+ let ch = source.readCh();
62
+ // if (ch === null || ch === undefined) break;
63
+ // source.updateBuffer();
64
+
65
+ if (ch === ">") return text.trimEnd();
66
+ else text += ch;
67
+ }
68
+ throw new Error(`Unexpected end of source. Reading '${substr}'`);
69
+ }
70
+
71
+ /**
72
+ * Read XML tag and build attributes map
73
+ * This function can be used to read normal tag, pi tag.
74
+ * This function can't be used to read comment, CDATA, DOCTYPE.
75
+ * Eg <tag attr = ' some"' attr= ">" bool>
76
+ * @param {string} xmlDoc
77
+ * @param {number} startIndex starting index
78
+ * @returns tag expression includes tag name & attribute string
79
+ */
80
+ function readTagExp(parser) {
81
+ let inSingleQuotes = false;
82
+ let inDoubleQuotes = false;
83
+ let i;
84
+ let EOE = false;
85
+
86
+ for (i = 0; parser.source.canRead(i); i++) {
87
+ const char = parser.source.readChAt(i);
88
+
89
+ if (char === "'" && !inDoubleQuotes) {
90
+ inSingleQuotes = !inSingleQuotes;
91
+ } else if (char === '"' && !inSingleQuotes) {
92
+ inDoubleQuotes = !inDoubleQuotes;
93
+ } else if (char === '>' && !inSingleQuotes && !inDoubleQuotes) {
94
+ // If not inside quotes, stop reading at '>'
95
+ EOE = true;
96
+ break;
97
+ }
98
+
99
+ }
100
+ if(inSingleQuotes || inDoubleQuotes){
101
+ throw new Error("Invalid attribute expression. Quote is not properly closed");
102
+ }else if(!EOE) throw new Error("Unexpected closing of source. Waiting for '>'");
103
+
104
+
105
+ const exp = parser.source.readStr(i);
106
+ parser.source.updateBufferBoundary(i + 1);
107
+ return buildTagExpObj(exp, parser)
108
+ }
109
+
110
+ function readPiExp(parser) {
111
+ let inSingleQuotes = false;
112
+ let inDoubleQuotes = false;
113
+ let i;
114
+ let EOE = false;
115
+
116
+ for (i = 0; parser.source.canRead(i) ; i++) {
117
+ const currentChar = parser.source.readChAt(i);
118
+ const nextChar = parser.source.readChAt(i+1);
119
+
120
+ if (currentChar === "'" && !inDoubleQuotes) {
121
+ inSingleQuotes = !inSingleQuotes;
122
+ } else if (currentChar === '"' && !inSingleQuotes) {
123
+ inDoubleQuotes = !inDoubleQuotes;
124
+ }
125
+
126
+ if (!inSingleQuotes && !inDoubleQuotes) {
127
+ if (currentChar === '?' && nextChar === '>') {
128
+ EOE = true;
129
+ break; // Exit the loop when '?>' is found
130
+ }
131
+ }
132
+ }
133
+ if(inSingleQuotes || inDoubleQuotes){
134
+ throw new Error("Invalid attribute expression. Quote is not properly closed in PI tag expression");
135
+ }else if(!EOE) throw new Error("Unexpected closing of source. Waiting for '?>'");
136
+
137
+ if(!parser.options.attributes.ignore){
138
+ //TODO: use regex to verify attributes if not set to ignore
139
+ }
140
+
141
+ const exp = parser.source.readStr(i);
142
+ parser.source.updateBufferBoundary(i + 1);
143
+ return buildTagExpObj(exp, parser)
144
+ }
145
+
146
+ function buildTagExpObj(exp, parser){
147
+ const tagExp = {
148
+ tagName: "",
149
+ selfClosing: false
150
+ };
151
+ let attrsExp = "";
152
+
153
+ if(exp[exp.length -1] === "/") tagExp.selfClosing = true;
154
+
155
+ //separate tag name
156
+ let i = 0;
157
+ for (; i < exp.length; i++) {
158
+ const char = exp[i];
159
+ if(char === " "){
160
+ tagExp.tagName = exp.substring(0, i);
161
+ attrsExp = exp.substring(i + 1);
162
+ break;
163
+ }
164
+ }
165
+ //only tag
166
+ if(tagExp.tagName.length === 0 && i === exp.length)tagExp.tagName = exp;
167
+
168
+ tagExp.tagName = tagExp.tagName.trimEnd();
169
+
170
+ if(!parser.options.attributes.ignore && attrsExp.length > 0){
171
+ parseAttributesExp(attrsExp,parser)
172
+ }
173
+
174
+ return tagExp;
175
+ }
176
+
177
+ const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
178
+
179
+ function parseAttributesExp(attrStr, parser) {
180
+ const matches = getAllMatches(attrStr, attrsRegx);
181
+ const len = matches.length; //don't make it inline
182
+ for (let i = 0; i < len; i++) {
183
+ let attrName = parser.processAttrName(matches[i][1]);
184
+ let attrVal = parser.replaceEntities(matches[i][4] || true);
185
+
186
+ parser.outputBuilder.addAttribute(attrName, attrVal);
187
+ }
188
+ }
189
+
190
+
191
+ const getAllMatches = function(string, regex) {
192
+ const matches = [];
193
+ let match = regex.exec(string);
194
+ while (match) {
195
+ const allmatches = [];
196
+ allmatches.startIndex = regex.lastIndex - match[0].length;
197
+ const len = match.length;
198
+ for (let index = 0; index < len; index++) {
199
+ allmatches.push(match[index]);
200
+ }
201
+ matches.push(allmatches);
202
+ match = regex.exec(string);
203
+ }
204
+ return matches;
205
+ };
206
+
207
+ module.exports = {
208
+ readStopNode: readStopNode,
209
+ readClosingTagName: readClosingTagName,
210
+ readTagExp: readTagExp,
211
+ readPiExp: readPiExp,
212
+ }
@@ -0,0 +1,118 @@
1
+ const {readPiExp} = require("./XmlPartReader");
2
+
3
+ function readCdata(parser){
4
+ //<![ are already read till this point
5
+ let str = parser.source.readStr(6); //CDATA[
6
+ parser.source.updateBufferBoundary(6);
7
+
8
+ if(str !== "CDATA[") throw new Error(`Invalid CDATA expression at ${parser.source.line}:${parser.source.cols}`);
9
+
10
+ let text = parser.source.readUpto("]]>");
11
+ parser.outputBuilder.addCdata(text);
12
+ }
13
+ function readPiTag(parser){
14
+ //<? are already read till this point
15
+ let tagExp = readPiExp(parser, "?>");
16
+ if(!tagExp) throw new Error("Invalid Pi Tag expression.");
17
+
18
+ if (tagExp.tagName === "?xml") {//TODO: test if tagName is just xml
19
+ parser.outputBuilder.addDeclaration();
20
+ } else {
21
+ parser.outputBuilder.addPi("?"+tagExp.tagName);
22
+ }
23
+ }
24
+
25
+ function readComment(parser){
26
+ //<!- are already read till this point
27
+ let ch = parser.source.readCh();
28
+ if(ch !== "-") throw new Error(`Invalid comment expression at ${parser.source.line}:${parser.source.cols}`);
29
+
30
+ let text = parser.source.readUpto("-->");
31
+ parser.outputBuilder.addComment(text);
32
+ }
33
+
34
+ const DOCTYPE_tags = {
35
+ "EL":/^EMENT\s+([^\s>]+)\s+(ANY|EMPTY|\(.+\)\s*$)/m,
36
+ "AT":/^TLIST\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+$/m,
37
+ "NO":/^TATION.+$/m
38
+ }
39
+ function readDocType(parser){
40
+ //<!D are already read till this point
41
+ let str = parser.source.readStr(6); //OCTYPE
42
+ parser.source.updateBufferBoundary(6);
43
+
44
+ if(str !== "OCTYPE") throw new Error(`Invalid DOCTYPE expression at ${parser.source.line}:${parser.source.cols}`);
45
+
46
+ let hasBody = false, lastch = "";
47
+
48
+ while(parser.source.canRead()){
49
+ //TODO: use readChAt like used in partReader
50
+ let ch = parser.source.readCh();
51
+ if(hasBody){
52
+ if (ch === '<') { //Determine the tag type
53
+ let str = parser.source.readStr(2);
54
+ parser.source.updateBufferBoundary(2);
55
+ if(str === "EN"){ //ENTITY
56
+ let str = parser.source.readStr(4);
57
+ parser.source.updateBufferBoundary(4);
58
+ if(str !== "TITY") throw new Error("Invalid DOCTYPE ENTITY expression");
59
+
60
+ registerEntity(parser);
61
+ }else if(str === "!-") {//comment
62
+ readComment(parser);
63
+ }else{ //ELEMENT, ATTLIST, NOTATION
64
+ let dTagExp = parser.source.readUpto(">");
65
+ const regx = DOCTYPE_tags[str];
66
+ if(regx){
67
+ const match = dTagExp.match(regx);
68
+ if(!match) throw new Error("Invalid DOCTYPE");
69
+ }else throw new Error("Invalid DOCTYPE");
70
+ }
71
+ }else if( ch === '>' && lastch === "]"){//end of doctype
72
+ return;
73
+ }
74
+ }else if( ch === '>'){//end of doctype
75
+ return;
76
+ }else if( ch === '['){
77
+ hasBody = true;
78
+ }else{
79
+ lastch = ch;
80
+ }
81
+ }//End While loop
82
+
83
+ }
84
+
85
+ function registerEntity(parser){
86
+ //read Entity
87
+ let attrBoundary="";
88
+ let name ="", val ="";
89
+ while(source.canRead()){
90
+ let ch = source.readCh();
91
+
92
+ if(attrBoundary){
93
+ if (ch === attrBoundary){
94
+ val = text;
95
+ text = ""
96
+ }
97
+ }else if(ch === " " || ch === "\t"){
98
+ if(!name){
99
+ name = text.trimStart();
100
+ text = "";
101
+ }
102
+ }else if (ch === '"' || ch === "'") {//start of attrBoundary
103
+ attrBoundary = ch;
104
+ }else if(ch === ">"){
105
+ parser.entityParser.addExternalEntity(name,val);
106
+ return;
107
+ }else{
108
+ text+=ch;
109
+ }
110
+ }
111
+ }
112
+
113
+ module.exports = {
114
+ readCdata: readCdata,
115
+ readComment:readComment,
116
+ readDocType:readDocType,
117
+ readPiTag:readPiTag
118
+ }