@gusto/baerly-storage 0.5.0 → 0.7.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.
Files changed (215) hide show
  1. package/README.md +47 -124
  2. package/dist/API.md +161 -511
  3. package/dist/CHANGELOG.md +1148 -307
  4. package/dist/RECIPES.md +398 -80
  5. package/dist/THIRD-PARTY-LICENSES.txt +5 -26
  6. package/dist/{app-config-DyiFK3_k.d.ts → app-config-C6qW7m8S.d.ts} +119 -111
  7. package/dist/app-config.d.ts +31 -1
  8. package/dist/app-config.js +1 -2
  9. package/dist/app-config.js.map +1 -1
  10. package/dist/auth.d.ts +33 -28
  11. package/dist/auth.js +549 -985
  12. package/dist/auth.js.map +1 -1
  13. package/dist/baerly.js +130 -138
  14. package/dist/baerly.js.map +1 -1
  15. package/dist/baerly.spec.json +97 -22
  16. package/dist/capacity-warning-header-BlVopyiI.js +16 -0
  17. package/dist/capacity-warning-header-BlVopyiI.js.map +1 -0
  18. package/dist/{client-Fe8CwB73.d.ts → client-CHQTXpef.d.ts} +121 -36
  19. package/dist/client-react.d.ts +67 -20
  20. package/dist/client-react.js +240 -54
  21. package/dist/client-react.js.map +1 -1
  22. package/dist/client.d.ts +5 -4
  23. package/dist/client.js +51 -16
  24. package/dist/client.js.map +1 -1
  25. package/dist/{cloudflare-DzKBrUlg.js → cloudflare-CKHYXccw.js} +504 -124
  26. package/dist/cloudflare-CKHYXccw.js.map +1 -0
  27. package/dist/cloudflare.d.ts +106 -71
  28. package/dist/cloudflare.js +334 -271
  29. package/dist/cloudflare.js.map +1 -1
  30. package/dist/code-resolution-CL_7L0wS.js +22 -0
  31. package/dist/code-resolution-CL_7L0wS.js.map +1 -0
  32. package/dist/collection-api-DbyhLAY8.d.ts +1001 -0
  33. package/dist/config-DEzInG6M.js +4035 -0
  34. package/dist/config-DEzInG6M.js.map +1 -0
  35. package/dist/constants-D3GSH3tc.js +469 -0
  36. package/dist/constants-D3GSH3tc.js.map +1 -0
  37. package/dist/{context-DRZ3tZ5l.js → context-rlpSnHFA.js} +17 -17
  38. package/dist/context-rlpSnHFA.js.map +1 -0
  39. package/dist/cost-B52llVDx.js +330 -0
  40. package/dist/cost-B52llVDx.js.map +1 -0
  41. package/dist/{current-json-C6nhPOm1.js → current-json-CC6lE4Aj.js} +115 -32
  42. package/dist/current-json-CC6lE4Aj.js.map +1 -0
  43. package/dist/db-plFUNTSF.d.ts +130 -0
  44. package/dist/db-read-seams-BSs0m1z1.js +3261 -0
  45. package/dist/db-read-seams-BSs0m1z1.js.map +1 -0
  46. package/dist/{deploy-DonTr-CV.js → deploy-Obj4nE-Z.js} +12 -16
  47. package/dist/deploy-Obj4nE-Z.js.map +1 -0
  48. package/dist/{dev-banner-CWHIk8tH.d.ts → dev-banner-B5AUHmu1.d.ts} +1 -4
  49. package/dist/dev-landing-BI5UdmOb.d.ts +32 -0
  50. package/dist/dev-landing-CD-si4dW.js +50 -0
  51. package/dist/dev-landing-CD-si4dW.js.map +1 -0
  52. package/dist/dev-vite.d.ts +38 -39
  53. package/dist/dev-vite.js +67 -36
  54. package/dist/dev-vite.js.map +1 -1
  55. package/dist/dev.d.ts +3 -2
  56. package/dist/dev.js +2 -1
  57. package/dist/doctor-BA0i-YAN.js +270 -0
  58. package/dist/doctor-BA0i-YAN.js.map +1 -0
  59. package/dist/dump-D1vX8ozg.js +133 -0
  60. package/dist/dump-D1vX8ozg.js.map +1 -0
  61. package/dist/errors-7Rk1HGCE.js +160 -0
  62. package/dist/errors-7Rk1HGCE.js.map +1 -0
  63. package/dist/{validate-DtljsCh1.js → export-BVL2EvYE.js} +409 -19
  64. package/dist/export-BVL2EvYE.js.map +1 -0
  65. package/dist/fsck-BWkPgov4.js +145 -0
  66. package/dist/fsck-BWkPgov4.js.map +1 -0
  67. package/dist/gcs-admin-Dso1HWQj.d.ts +127 -0
  68. package/dist/gcs.d.ts +30 -0
  69. package/dist/gcs.js +1 -0
  70. package/dist/goog4-signer-CeLIABoE.js +331 -0
  71. package/dist/goog4-signer-CeLIABoE.js.map +1 -0
  72. package/dist/{http-DGd5tbNs.js → http-Z5rZyYMX.js} +898 -271
  73. package/dist/http-Z5rZyYMX.js.map +1 -0
  74. package/dist/http-transport-DNUM8kU-.js +1299 -0
  75. package/dist/http-transport-DNUM8kU-.js.map +1 -0
  76. package/dist/http.d.ts +366 -294
  77. package/dist/http.js +2 -2
  78. package/dist/index-JJrIu1pO.d.ts +135 -0
  79. package/dist/index-LEgHN0qJ.d.ts +50 -0
  80. package/dist/{index-CuA9Mi3K.d.ts → index-RiEYj8t0.d.ts} +291 -78
  81. package/dist/index.d.ts +27 -6
  82. package/dist/index.js +3 -5
  83. package/dist/inspect-BTsVYZKd.js +196 -0
  84. package/dist/inspect-BTsVYZKd.js.map +1 -0
  85. package/dist/{key-Di6yyxFu.js → key-C4FPZ9Io.js} +3 -4
  86. package/dist/{key-Di6yyxFu.js.map → key-C4FPZ9Io.js.map} +1 -1
  87. package/dist/ledger-Dj_bGgo0.js +192 -0
  88. package/dist/ledger-Dj_bGgo0.js.map +1 -0
  89. package/dist/legacy-names-DgZBtgOh.js +47 -0
  90. package/dist/legacy-names-DgZBtgOh.js.map +1 -0
  91. package/dist/log-C9W15Dfo.d.ts +94 -0
  92. package/dist/log-tail-DWJbneBF.js +142 -0
  93. package/dist/log-tail-DWJbneBF.js.map +1 -0
  94. package/dist/log-walk-C-vA-WGJ.js +111 -0
  95. package/dist/log-walk-C-vA-WGJ.js.map +1 -0
  96. package/dist/maintenance-Dd-Yakqj.js +1709 -0
  97. package/dist/maintenance-Dd-Yakqj.js.map +1 -0
  98. package/dist/maintenance-DevB6z4e.js +2237 -0
  99. package/dist/maintenance-DevB6z4e.js.map +1 -0
  100. package/dist/maintenance.d.ts +100 -3
  101. package/dist/maintenance.js +1 -3
  102. package/dist/node.d.ts +130 -142
  103. package/dist/node.js +4 -3
  104. package/dist/{observability-BmflLCdF.js → observability-C-ISCCLE.js} +1275 -332
  105. package/dist/observability-C-ISCCLE.js.map +1 -0
  106. package/dist/observability.d.ts +27 -3
  107. package/dist/observability.js +3 -3
  108. package/dist/path-segment-DBXG26PW.js +363 -0
  109. package/dist/path-segment-DBXG26PW.js.map +1 -0
  110. package/dist/{plan-a7PJHBCy.js → plan-BvQbaNMe.js} +19 -11
  111. package/dist/plan-BvQbaNMe.js.map +1 -0
  112. package/dist/request-CRWiTrza.js +272 -0
  113. package/dist/request-CRWiTrza.js.map +1 -0
  114. package/dist/restore-U6Im8V1V.js +1467 -0
  115. package/dist/restore-U6Im8V1V.js.map +1 -0
  116. package/dist/retry-OBtLB2GC.js +126 -0
  117. package/dist/retry-OBtLB2GC.js.map +1 -0
  118. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  119. package/dist/{runtime-spec-Dsw2-n8S.js → runtime-spec-B5mg3pHF.js} +189 -28
  120. package/dist/runtime-spec-B5mg3pHF.js.map +1 -0
  121. package/dist/{s3-http-B-z8th6O.d.ts → s3-http-DBC_wiCL.d.ts} +18 -10
  122. package/dist/s3.d.ts +20 -7
  123. package/dist/s3.js +4 -5
  124. package/dist/s3.js.map +1 -1
  125. package/dist/sha256-4FfGQNPw.js +22 -0
  126. package/dist/sha256-4FfGQNPw.js.map +1 -0
  127. package/dist/{shared-secret-DgEicd3x.js → shared-secret-Vkur-8r0.js} +27 -15
  128. package/dist/shared-secret-Vkur-8r0.js.map +1 -0
  129. package/dist/sigv4-sign-5IUflUD_.js +507 -0
  130. package/dist/sigv4-sign-5IUflUD_.js.map +1 -0
  131. package/dist/snapshot-CknzkDM0.js +148 -0
  132. package/dist/snapshot-CknzkDM0.js.map +1 -0
  133. package/dist/{src-BL_JoPTn.js → src-Actga-bO.js} +1004 -378
  134. package/dist/src-Actga-bO.js.map +1 -0
  135. package/dist/src-D0MQfvOp.js +812 -0
  136. package/dist/src-D0MQfvOp.js.map +1 -0
  137. package/dist/src-Dr9uo3dc.js +501 -0
  138. package/dist/src-Dr9uo3dc.js.map +1 -0
  139. package/dist/{subcommand-DoDA-K7d.js → subcommand-BLoF66dG.js} +89 -16
  140. package/dist/subcommand-BLoF66dG.js.map +1 -0
  141. package/dist/{time-DUqvFMHq.js → time-DRxTP9iv.js} +15 -34
  142. package/dist/time-DRxTP9iv.js.map +1 -0
  143. package/dist/types-suVbsEWS.d.ts +116 -0
  144. package/dist/{usage-DBV1eQHC.js → usage-CPzVhrQr.js} +40 -45
  145. package/dist/usage-CPzVhrQr.js.map +1 -0
  146. package/dist/uuid-BuT_c404.js +333 -0
  147. package/dist/uuid-BuT_c404.js.map +1 -0
  148. package/dist/verifier-Bmlmndzo.d.ts +95 -0
  149. package/dist/{wire-izfGZDvr.js → wire-DndvKU-K.js} +2 -3
  150. package/dist/wire-DndvKU-K.js.map +1 -0
  151. package/package.json +96 -69
  152. package/dist/aws4fetch.esm-p7eEzLCs.js +0 -1702
  153. package/dist/aws4fetch.esm-p7eEzLCs.js.map +0 -1
  154. package/dist/bytes-BXdamO3L.js +0 -11
  155. package/dist/bytes-BXdamO3L.js.map +0 -1
  156. package/dist/cloudflare-DzKBrUlg.js.map +0 -1
  157. package/dist/config-1tv0-Yzm.js +0 -2693
  158. package/dist/config-1tv0-Yzm.js.map +0 -1
  159. package/dist/constants-CfeMWQWk.js +0 -222
  160. package/dist/constants-CfeMWQWk.js.map +0 -1
  161. package/dist/context-DRZ3tZ5l.js.map +0 -1
  162. package/dist/cost-DSMIVqzL.js +0 -203
  163. package/dist/cost-DSMIVqzL.js.map +0 -1
  164. package/dist/current-json-C6nhPOm1.js.map +0 -1
  165. package/dist/db-DsPkOVEH.d.ts +0 -254
  166. package/dist/deploy-DonTr-CV.js.map +0 -1
  167. package/dist/doctor-DSIyCDg_.js +0 -346
  168. package/dist/doctor-DSIyCDg_.js.map +0 -1
  169. package/dist/dump-Bh5k26VQ.js +0 -94
  170. package/dist/dump-Bh5k26VQ.js.map +0 -1
  171. package/dist/errors-Dfa3p78c.js +0 -78
  172. package/dist/errors-Dfa3p78c.js.map +0 -1
  173. package/dist/export-DtF5tDIM.js +0 -401
  174. package/dist/export-DtF5tDIM.js.map +0 -1
  175. package/dist/fsck-D_djMO5D.js +0 -279
  176. package/dist/fsck-D_djMO5D.js.map +0 -1
  177. package/dist/http-DGd5tbNs.js.map +0 -1
  178. package/dist/index-0rZcMBwy.d.ts +0 -115
  179. package/dist/index-BNRh23K9.d.ts +0 -162
  180. package/dist/index-BYk9oCNf.d.ts +0 -1112
  181. package/dist/indexes-Dn9hbGQG.d.ts +0 -22
  182. package/dist/inspect-6WZ-pC7-.js +0 -133
  183. package/dist/inspect-6WZ-pC7-.js.map +0 -1
  184. package/dist/log-tail-D98U1JBo.js +0 -522
  185. package/dist/log-tail-D98U1JBo.js.map +0 -1
  186. package/dist/maintenance-B4Dki6Ig.js +0 -2157
  187. package/dist/maintenance-B4Dki6Ig.js.map +0 -1
  188. package/dist/maintenance-B_e0T99L.d.ts +0 -537
  189. package/dist/maintenance-C7coQp4c.js +0 -1418
  190. package/dist/maintenance-C7coQp4c.js.map +0 -1
  191. package/dist/normalize-rjnZLwS4.js +0 -133
  192. package/dist/normalize-rjnZLwS4.js.map +0 -1
  193. package/dist/observability-BmflLCdF.js.map +0 -1
  194. package/dist/plan-a7PJHBCy.js.map +0 -1
  195. package/dist/query-rAtXNQQB.js +0 -1773
  196. package/dist/query-rAtXNQQB.js.map +0 -1
  197. package/dist/rebuild-index-BVzQSZlm.js +0 -81
  198. package/dist/rebuild-index-BVzQSZlm.js.map +0 -1
  199. package/dist/request-u0M51mhJ.js +0 -72
  200. package/dist/request-u0M51mhJ.js.map +0 -1
  201. package/dist/restore-R-4rbciV.js +0 -778
  202. package/dist/restore-R-4rbciV.js.map +0 -1
  203. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  204. package/dist/runtime-spec-Dsw2-n8S.js.map +0 -1
  205. package/dist/shared-secret-DgEicd3x.js.map +0 -1
  206. package/dist/src-BL_JoPTn.js.map +0 -1
  207. package/dist/src-CYHFDrKz.js +0 -536
  208. package/dist/src-CYHFDrKz.js.map +0 -1
  209. package/dist/src-DYZ4H1aF.js +0 -392
  210. package/dist/src-DYZ4H1aF.js.map +0 -1
  211. package/dist/subcommand-DoDA-K7d.js.map +0 -1
  212. package/dist/time-DUqvFMHq.js.map +0 -1
  213. package/dist/usage-DBV1eQHC.js.map +0 -1
  214. package/dist/validate-DtljsCh1.js.map +0 -1
  215. package/dist/wire-izfGZDvr.js.map +0 -1
@@ -0,0 +1,1299 @@
1
+ import { t as BaerlyError } from "./errors-7Rk1HGCE.js";
2
+ // node_modules/.pnpm/@rgrove+parse-xml@5.2.0/node_modules/@rgrove/parse-xml/dist/browser.js
3
+ /*! @rgrove/parse-xml v5.2.0 | ISC License | Copyright Ryan Grove */
4
+ var emptyString = "";
5
+ var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
6
+ var StringScanner = class {
7
+ constructor(string) {
8
+ this.o = this.u(string, true);
9
+ this.d = 0;
10
+ this.length = string.length;
11
+ this.p = this.o !== this.length;
12
+ this.h = string;
13
+ if (this.p) {
14
+ let charsToBytes = [];
15
+ for (let byteIndex = 0, charIndex = 0; charIndex <= this.o; ++charIndex) {
16
+ charsToBytes[charIndex] = byteIndex;
17
+ byteIndex += string.codePointAt(byteIndex) > 65535 ? 2 : 1;
18
+ }
19
+ this.C = charsToBytes;
20
+ }
21
+ }
22
+ /**
23
+ * Whether the current character index is at the end of the input string.
24
+ */
25
+ get D() {
26
+ return this.d >= this.o;
27
+ }
28
+ /**
29
+ * Returns the number of characters in the given string, which may differ from
30
+ * the byte length if the string contains multibyte characters.
31
+ */
32
+ u(string, multiByteSafe = this.p) {
33
+ return multiByteSafe ? string.replace(surrogatePair, "_").length : string.length;
34
+ }
35
+ /**
36
+ * Advances the scanner by the given number of characters, stopping if the end
37
+ * of the string is reached.
38
+ */
39
+ l(count = 1) {
40
+ this.d = Math.min(this.o, this.d + count);
41
+ }
42
+ /**
43
+ * Returns the byte index of the given character index in the string. The two
44
+ * may differ in strings that contain multibyte characters.
45
+ */
46
+ f(charIndex = this.d) {
47
+ var _a;
48
+ return this.p ? (_a = this.C[charIndex]) != null ? _a : 1e400 : charIndex;
49
+ }
50
+ /**
51
+ * Consumes and returns the given number of characters if possible, advancing
52
+ * the scanner and stopping if the end of the string is reached.
53
+ *
54
+ * If no characters could be consumed, an empty string will be returned.
55
+ */
56
+ G(charCount = 1) {
57
+ let chars = this.i(charCount);
58
+ this.l(charCount);
59
+ return chars;
60
+ }
61
+ /**
62
+ * Consumes and returns the given number of bytes if possible, advancing the
63
+ * scanner and stopping if the end of the string is reached.
64
+ *
65
+ * It's up to the caller to ensure that the given byte count doesn't split a
66
+ * multibyte character.
67
+ *
68
+ * If no bytes could be consumed, an empty string will be returned.
69
+ */
70
+ v(byteCount) {
71
+ let byteIndex = this.f();
72
+ let result = this.h.slice(byteIndex, byteIndex + byteCount);
73
+ this.l(this.u(result));
74
+ return result;
75
+ }
76
+ /**
77
+ * Consumes and returns all characters for which the given function returns
78
+ * `true`, stopping when `false` is returned or the end of the input is
79
+ * reached.
80
+ */
81
+ w(fn) {
82
+ let { length, p: multiByteMode, h: string } = this;
83
+ let startByteIndex = this.f();
84
+ let endByteIndex = startByteIndex;
85
+ if (multiByteMode) while (endByteIndex < length) {
86
+ let char = string[endByteIndex];
87
+ let isSurrogatePair = char >= "\ud800" && char <= "\udbff";
88
+ if (isSurrogatePair) char += string[endByteIndex + 1];
89
+ if (!fn(char)) break;
90
+ endByteIndex += isSurrogatePair ? 2 : 1;
91
+ }
92
+ else while (endByteIndex < length && fn(string[endByteIndex])) ++endByteIndex;
93
+ return this.v(endByteIndex - startByteIndex);
94
+ }
95
+ /**
96
+ * Consumes the given string if it exists at the current character index, and
97
+ * advances the scanner.
98
+ *
99
+ * If the given string doesn't exist at the current character index, an empty
100
+ * string will be returned and the scanner will not be advanced.
101
+ */
102
+ b(stringToConsume) {
103
+ let { length } = stringToConsume;
104
+ let byteIndex = this.f();
105
+ if (stringToConsume === this.h.slice(byteIndex, byteIndex + length)) {
106
+ this.l(length === 1 ? 1 : this.u(stringToConsume));
107
+ return stringToConsume;
108
+ }
109
+ return emptyString;
110
+ }
111
+ /**
112
+ * Consumes characters until the given global regex is matched, advancing the
113
+ * scanner up to (but not beyond) the beginning of the match. If the regex
114
+ * doesn't match, nothing will be consumed.
115
+ *
116
+ * Returns the consumed string, or an empty string if nothing was consumed.
117
+ */
118
+ x(regex) {
119
+ let matchByteIndex = this.h.slice(this.f()).search(regex);
120
+ return matchByteIndex > 0 ? this.v(matchByteIndex) : emptyString;
121
+ }
122
+ /**
123
+ * Consumes characters until the given string is found, advancing the scanner
124
+ * up to (but not beyond) that point. If the string is never found, nothing
125
+ * will be consumed.
126
+ *
127
+ * Returns the consumed string, or an empty string if nothing was consumed.
128
+ */
129
+ s(searchString) {
130
+ let byteIndex = this.f();
131
+ let matchByteIndex = this.h.indexOf(searchString, byteIndex);
132
+ return matchByteIndex > 0 ? this.v(matchByteIndex - byteIndex) : emptyString;
133
+ }
134
+ /**
135
+ * Returns the given number of characters starting at the current character
136
+ * index, without advancing the scanner and without exceeding the end of the
137
+ * input string.
138
+ */
139
+ i(count = 1) {
140
+ let { d: charIndex, h: string } = this;
141
+ return this.p ? string.slice(this.f(charIndex), this.f(charIndex + count)) : string.slice(charIndex, charIndex + count);
142
+ }
143
+ /**
144
+ * Resets the scanner position to the given character _index_, or to the start
145
+ * of the input string if no index is given.
146
+ *
147
+ * If _index_ is negative, the scanner position will be moved backward by that
148
+ * many characters, stopping if the beginning of the string is reached.
149
+ */
150
+ j(index = 0) {
151
+ this.d = index >= 0 ? Math.min(this.o, index) : Math.max(0, this.d + index);
152
+ }
153
+ };
154
+ var attValueCharDoubleQuote = /["&<]/;
155
+ var attValueCharSingleQuote = /['&<]/;
156
+ var attValueNormalizedWhitespace = /\r\n|[\n\r\t]/g;
157
+ var endCharData = /<|&|]]>/;
158
+ var lineBreakToNormalize = /\r\n?/g;
159
+ var markupDeclarationDelimiter = /["'<>\]]|$/;
160
+ var predefinedEntities = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), {
161
+ amp: "&",
162
+ apos: "'",
163
+ gt: ">",
164
+ lt: "<",
165
+ quot: "\""
166
+ }));
167
+ function isNameChar(char) {
168
+ let cp = char.codePointAt(0);
169
+ return cp >= 97 && cp <= 122 || cp >= 65 && cp <= 90 || cp >= 48 && cp <= 57 || cp === 45 || cp === 46 || cp === 183 || cp >= 768 && cp <= 879 || cp === 8255 || cp === 8256 || isNameStartChar(char, cp);
170
+ }
171
+ function isNameStartChar(char, cp = char.codePointAt(0)) {
172
+ return cp >= 97 && cp <= 122 || cp >= 65 && cp <= 90 || cp === 58 || cp === 95 || cp >= 192 && cp <= 214 || cp >= 216 && cp <= 246 || cp >= 248 && cp <= 767 || cp >= 880 && cp <= 893 || cp >= 895 && cp <= 8191 || cp === 8204 || cp === 8205 || cp >= 8304 && cp <= 8591 || cp >= 11264 && cp <= 12271 || cp >= 12289 && cp <= 55295 || cp >= 63744 && cp <= 64975 || cp >= 65008 && cp <= 65533 || cp >= 65536 && cp <= 983039;
173
+ }
174
+ function isReferenceChar(char) {
175
+ return char === "#" || isNameChar(char);
176
+ }
177
+ function isWhitespace(char) {
178
+ let cp = char.codePointAt(0);
179
+ return cp === 32 || cp === 9 || cp === 10 || cp === 13;
180
+ }
181
+ function isXmlCodePoint(cp) {
182
+ return cp >= 32 && cp <= 55295 || cp === 10 || cp === 9 || cp === 13 || cp >= 57344 && cp <= 65533 || cp >= 65536 && cp <= 1114111;
183
+ }
184
+ var _XmlNode = class _XmlNode {
185
+ constructor() {
186
+ /**
187
+ * Parent node of this node, or `null` if this node has no parent.
188
+ */
189
+ this.parent = null;
190
+ /**
191
+ * Starting byte offset of this node in the original XML string, or `-1` if
192
+ * the offset is unknown.
193
+ */
194
+ this.start = -1;
195
+ /**
196
+ * Ending byte offset of this node in the original XML string, or `-1` if the
197
+ * offset is unknown.
198
+ */
199
+ this.end = -1;
200
+ }
201
+ /**
202
+ * Document that contains this node, or `null` if this node is not associated
203
+ * with a document.
204
+ */
205
+ get document() {
206
+ let node = this.parent;
207
+ while (node !== null) {
208
+ if (node.type === _XmlNode.TYPE_DOCUMENT) return node;
209
+ node = node.parent;
210
+ }
211
+ return null;
212
+ }
213
+ /**
214
+ * Whether this node is the root node of the document (also known as the
215
+ * document element).
216
+ */
217
+ get isRootNode() {
218
+ var _a;
219
+ return ((_a = this.parent) == null ? void 0 : _a.type) === _XmlNode.TYPE_DOCUMENT && this.type === _XmlNode.TYPE_ELEMENT;
220
+ }
221
+ /**
222
+ * Whether whitespace should be preserved in the content of this element and
223
+ * its children.
224
+ *
225
+ * This is influenced by the value of the special `xml:space` attribute, and
226
+ * will be `true` for any node whose `xml:space` attribute is set to
227
+ * "preserve". If a node has no such attribute, it will inherit the value of
228
+ * the nearest ancestor that does (if any).
229
+ *
230
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space
231
+ */
232
+ get preserveWhitespace() {
233
+ var _a;
234
+ return !!((_a = this.parent) == null ? void 0 : _a.preserveWhitespace);
235
+ }
236
+ /**
237
+ * Type of this node.
238
+ *
239
+ * The value of this property is a string that matches one of the static
240
+ * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,
241
+ * `TYPE_TEXT`, etc.).
242
+ *
243
+ * The `XmlNode` class itself is a base class and doesn't have its own type
244
+ * name.
245
+ */
246
+ get type() {
247
+ return "";
248
+ }
249
+ /**
250
+ * Returns a JSON-serializable object representing this node, minus properties
251
+ * that could result in circular references.
252
+ */
253
+ toJSON() {
254
+ let json = { type: this.type };
255
+ if (this.isRootNode) json.isRootNode = true;
256
+ if (this.preserveWhitespace) json.preserveWhitespace = true;
257
+ if (this.start !== -1) {
258
+ json.start = this.start;
259
+ json.end = this.end;
260
+ }
261
+ return json;
262
+ }
263
+ };
264
+ /**
265
+ * Type value for an `XmlCdata` node.
266
+ */
267
+ _XmlNode.TYPE_CDATA = "cdata";
268
+ /**
269
+ * Type value for an `XmlComment` node.
270
+ */
271
+ _XmlNode.TYPE_COMMENT = "comment";
272
+ /**
273
+ * Type value for an `XmlDocument` node.
274
+ */
275
+ _XmlNode.TYPE_DOCUMENT = "document";
276
+ /**
277
+ * Type value for an `XmlDocumentType` node.
278
+ */
279
+ _XmlNode.TYPE_DOCUMENT_TYPE = "doctype";
280
+ /**
281
+ * Type value for an `XmlElement` node.
282
+ */
283
+ _XmlNode.TYPE_ELEMENT = "element";
284
+ /**
285
+ * Type value for an `XmlProcessingInstruction` node.
286
+ */
287
+ _XmlNode.TYPE_PROCESSING_INSTRUCTION = "pi";
288
+ /**
289
+ * Type value for an `XmlText` node.
290
+ */
291
+ _XmlNode.TYPE_TEXT = "text";
292
+ /**
293
+ * Type value for an `XmlDeclaration` node.
294
+ */
295
+ _XmlNode.TYPE_XML_DECLARATION = "xmldecl";
296
+ var XmlNode = _XmlNode;
297
+ var XmlText = class extends XmlNode {
298
+ constructor(text = "") {
299
+ super();
300
+ this.text = text;
301
+ }
302
+ get type() {
303
+ return XmlNode.TYPE_TEXT;
304
+ }
305
+ toJSON() {
306
+ return Object.assign(XmlNode.prototype.toJSON.call(this), { text: this.text });
307
+ }
308
+ };
309
+ var XmlCdata = class extends XmlText {
310
+ get type() {
311
+ return XmlNode.TYPE_CDATA;
312
+ }
313
+ };
314
+ var XmlComment = class extends XmlNode {
315
+ constructor(content = "") {
316
+ super();
317
+ this.content = content;
318
+ }
319
+ get type() {
320
+ return XmlNode.TYPE_COMMENT;
321
+ }
322
+ toJSON() {
323
+ return Object.assign(XmlNode.prototype.toJSON.call(this), { content: this.content });
324
+ }
325
+ };
326
+ var XmlDeclaration = class extends XmlNode {
327
+ constructor(version, encoding, standalone) {
328
+ super();
329
+ this.version = version;
330
+ this.encoding = encoding != null ? encoding : null;
331
+ this.standalone = standalone != null ? standalone : null;
332
+ }
333
+ get type() {
334
+ return XmlNode.TYPE_XML_DECLARATION;
335
+ }
336
+ toJSON() {
337
+ let json = XmlNode.prototype.toJSON.call(this);
338
+ json.version = this.version;
339
+ for (let key of ["encoding", "standalone"]) if (this[key] !== null) json[key] = this[key];
340
+ return json;
341
+ }
342
+ };
343
+ var XmlElement = class _XmlElement extends XmlNode {
344
+ constructor(name, attributes = /* @__PURE__ */ Object.create(null), children = []) {
345
+ super();
346
+ this.name = name;
347
+ this.attributes = attributes;
348
+ this.children = children;
349
+ }
350
+ /**
351
+ * Whether this element is empty (meaning it has no children).
352
+ */
353
+ get isEmpty() {
354
+ return this.children.length === 0;
355
+ }
356
+ get preserveWhitespace() {
357
+ let node = this;
358
+ while (node instanceof _XmlElement) {
359
+ if ("xml:space" in node.attributes) return node.attributes["xml:space"] === "preserve";
360
+ node = node.parent;
361
+ }
362
+ return false;
363
+ }
364
+ /**
365
+ * Text content of this element and all its descendants.
366
+ */
367
+ get text() {
368
+ return this.children.map((child) => "text" in child ? child.text : "").join("");
369
+ }
370
+ get type() {
371
+ return XmlNode.TYPE_ELEMENT;
372
+ }
373
+ toJSON() {
374
+ return Object.assign(XmlNode.prototype.toJSON.call(this), {
375
+ name: this.name,
376
+ attributes: this.attributes,
377
+ children: this.children.map((child) => child.toJSON())
378
+ });
379
+ }
380
+ };
381
+ var XmlDocument = class extends XmlNode {
382
+ constructor(children = []) {
383
+ super();
384
+ this.children = children;
385
+ }
386
+ get document() {
387
+ return this;
388
+ }
389
+ /**
390
+ * Root element of this document, or `null` if this document is empty.
391
+ */
392
+ get root() {
393
+ for (let child of this.children) if (child instanceof XmlElement) return child;
394
+ return null;
395
+ }
396
+ /**
397
+ * Text content of this document and all its descendants.
398
+ */
399
+ get text() {
400
+ return this.children.map((child) => "text" in child ? child.text : "").join("");
401
+ }
402
+ get type() {
403
+ return XmlNode.TYPE_DOCUMENT;
404
+ }
405
+ toJSON() {
406
+ return Object.assign(XmlNode.prototype.toJSON.call(this), { children: this.children.map((child) => child.toJSON()) });
407
+ }
408
+ };
409
+ var XmlDocumentType = class extends XmlNode {
410
+ constructor(name, publicId, systemId, internalSubset) {
411
+ super();
412
+ this.name = name;
413
+ this.publicId = publicId != null ? publicId : null;
414
+ this.systemId = systemId != null ? systemId : null;
415
+ this.internalSubset = internalSubset != null ? internalSubset : null;
416
+ }
417
+ get type() {
418
+ return XmlNode.TYPE_DOCUMENT_TYPE;
419
+ }
420
+ toJSON() {
421
+ let json = XmlNode.prototype.toJSON.call(this);
422
+ json.name = this.name;
423
+ for (let key of [
424
+ "publicId",
425
+ "systemId",
426
+ "internalSubset"
427
+ ]) if (this[key] !== null) json[key] = this[key];
428
+ return json;
429
+ }
430
+ };
431
+ var XmlError = class extends Error {
432
+ constructor(message, charIndex, xml) {
433
+ let column = 1;
434
+ let excerpt = "";
435
+ let line = 1;
436
+ for (let i = 0; i < charIndex; ++i) {
437
+ let char = xml[i];
438
+ if (char === "\n") {
439
+ column = 1;
440
+ excerpt = "";
441
+ line += 1;
442
+ } else {
443
+ column += 1;
444
+ excerpt += char;
445
+ }
446
+ }
447
+ let eol = xml.indexOf("\n", charIndex);
448
+ excerpt += eol === -1 ? xml.slice(charIndex) : xml.slice(charIndex, eol);
449
+ let excerptStart = 0;
450
+ if (excerpt.length > 50) {
451
+ if (column < 40) excerpt = excerpt.slice(0, 50);
452
+ else {
453
+ excerptStart = column - 20;
454
+ excerpt = excerpt.slice(excerptStart, column + 30);
455
+ }
456
+ }
457
+ super(`${message} (line ${line}, column ${column})
458
+ ${excerpt}
459
+ ` + " ".repeat(column - excerptStart + 1) + "^\n");
460
+ this.column = column;
461
+ this.excerpt = excerpt;
462
+ this.line = line;
463
+ this.name = "XmlError";
464
+ this.pos = charIndex;
465
+ }
466
+ };
467
+ var XmlProcessingInstruction = class extends XmlNode {
468
+ constructor(name, content = "") {
469
+ super();
470
+ this.name = name;
471
+ this.content = content;
472
+ }
473
+ get type() {
474
+ return XmlNode.TYPE_PROCESSING_INSTRUCTION;
475
+ }
476
+ toJSON() {
477
+ return Object.assign(XmlNode.prototype.toJSON.call(this), {
478
+ name: this.name,
479
+ content: this.content
480
+ });
481
+ }
482
+ };
483
+ var defaultMaxElementDepth = 256;
484
+ var emptyString2 = "";
485
+ var Parser = class {
486
+ /**
487
+ * @param xml XML string to parse.
488
+ * @param options Parser options.
489
+ */
490
+ constructor(xml, options = {}) {
491
+ this.depth = 0;
492
+ var _a;
493
+ let doc = this.document = new XmlDocument();
494
+ this.m = doc;
495
+ this.maxElementDepth = (_a = options.maxElementDepth) != null ? _a : defaultMaxElementDepth;
496
+ this.g = options;
497
+ this.c = new StringScanner(xml);
498
+ if (this.g.includeOffsets) {
499
+ doc.start = 0;
500
+ doc.end = xml.length;
501
+ }
502
+ this.parse();
503
+ }
504
+ /**
505
+ * Adds the given `XmlNode` as a child of `this.currentNode`.
506
+ */
507
+ k(node, charIndex) {
508
+ node.parent = this.m;
509
+ if (this.g.includeOffsets) {
510
+ node.start = this.c.f(charIndex);
511
+ node.end = this.c.f();
512
+ }
513
+ this.m.children.push(node);
514
+ return true;
515
+ }
516
+ /**
517
+ * Adds the given _text_ to the document, either by appending it to a
518
+ * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.
519
+ *
520
+ * When _normalize_ is `true` (the default), line breaks in _text_ are
521
+ * normalized per section 2.11 of the XML spec. This must be `false` for text
522
+ * that comes from a character or entity reference, since references aren't
523
+ * subject to line break normalization.
524
+ */
525
+ y(text, charIndex, normalize = true) {
526
+ let { children } = this.m;
527
+ let { length } = children;
528
+ if (normalize) text = normalizeLineBreaks(text);
529
+ if (length > 0) {
530
+ let prevNode = children[length - 1];
531
+ if ((prevNode == null ? void 0 : prevNode.type) === XmlNode.TYPE_TEXT) {
532
+ let textNode = prevNode;
533
+ textNode.text += text;
534
+ if (this.g.includeOffsets) textNode.end = this.c.f();
535
+ return true;
536
+ }
537
+ }
538
+ return this.k(new XmlText(text), charIndex);
539
+ }
540
+ /**
541
+ * Consumes element attributes.
542
+ *
543
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags
544
+ */
545
+ H() {
546
+ let attributes = /* @__PURE__ */ Object.create(null);
547
+ while (this.e()) {
548
+ let attrName = this.q();
549
+ if (!attrName) break;
550
+ let attrValue = this.t() && this.I();
551
+ if (attrValue === false) throw this.a("Attribute value expected");
552
+ if (attrName in attributes) throw this.a(`Duplicate attribute: ${attrName}`);
553
+ if (attrName === "xml:space" && attrValue !== "default" && attrValue !== "preserve") throw this.a("Value of the `xml:space` attribute must be \"default\" or \"preserve\"");
554
+ attributes[attrName] = attrValue;
555
+ }
556
+ if (this.g.sortAttributes) {
557
+ let attrNames = Object.keys(attributes).sort();
558
+ let sortedAttributes = /* @__PURE__ */ Object.create(null);
559
+ for (let i = 0; i < attrNames.length; ++i) {
560
+ let attrName = attrNames[i];
561
+ sortedAttributes[attrName] = attributes[attrName];
562
+ }
563
+ attributes = sortedAttributes;
564
+ }
565
+ return attributes;
566
+ }
567
+ /**
568
+ * Consumes an `AttValue` (attribute value) if possible.
569
+ *
570
+ * @returns
571
+ * Contents of the `AttValue` minus quotes, or `false` if nothing was
572
+ * consumed. An empty string indicates that an `AttValue` was consumed but
573
+ * was empty.
574
+ *
575
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
576
+ */
577
+ I() {
578
+ let { c: scanner } = this;
579
+ let quote = scanner.i();
580
+ if (quote !== "\"" && quote !== "'") return false;
581
+ scanner.l();
582
+ let chars;
583
+ let isClosed = false;
584
+ let value = emptyString2;
585
+ let regex = quote === "\"" ? attValueCharDoubleQuote : attValueCharSingleQuote;
586
+ matchLoop: while (!scanner.D) {
587
+ chars = scanner.x(regex);
588
+ if (chars) {
589
+ this.n(chars);
590
+ value += chars.replace(attValueNormalizedWhitespace, " ");
591
+ }
592
+ switch (scanner.i()) {
593
+ case quote:
594
+ isClosed = true;
595
+ break matchLoop;
596
+ case "&":
597
+ value += this.E();
598
+ continue;
599
+ case "<": throw this.a("Unescaped `<` is not allowed in an attribute value");
600
+ default: break matchLoop;
601
+ }
602
+ }
603
+ if (!isClosed) throw this.a("Unclosed attribute");
604
+ scanner.l();
605
+ return value;
606
+ }
607
+ /**
608
+ * Consumes a CDATA section if possible.
609
+ *
610
+ * @returns Whether a CDATA section was consumed.
611
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect
612
+ */
613
+ J() {
614
+ let { c: scanner } = this;
615
+ let startIndex = scanner.d;
616
+ if (!scanner.b("<![CDATA[")) return false;
617
+ let text = scanner.s("]]>");
618
+ this.n(text);
619
+ if (!scanner.b("]]>")) throw this.a("Unclosed CDATA section");
620
+ return this.g.preserveCdata ? this.k(new XmlCdata(normalizeLineBreaks(text)), startIndex) : this.y(text, startIndex);
621
+ }
622
+ /**
623
+ * Consumes character data if possible.
624
+ *
625
+ * @returns Whether character data was consumed.
626
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata
627
+ */
628
+ K() {
629
+ let { c: scanner } = this;
630
+ let startIndex = scanner.d;
631
+ let charData = scanner.x(endCharData);
632
+ if (!charData) return false;
633
+ this.n(charData);
634
+ if (scanner.i(3) === "]]>") throw this.a("Element content may not contain the CDATA section close delimiter `]]>`");
635
+ return this.y(charData, startIndex);
636
+ }
637
+ /**
638
+ * Consumes a comment if possible.
639
+ *
640
+ * @param addToDocument
641
+ * Whether the comment may be added to the document (subject to the
642
+ * `preserveComments` option). This should be `false` for comments inside a
643
+ * DTD internal subset.
644
+ *
645
+ * @returns Whether a comment was consumed.
646
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment
647
+ */
648
+ z(addToDocument = true) {
649
+ let { c: scanner } = this;
650
+ let startIndex = scanner.d;
651
+ if (!scanner.b("<!--")) return false;
652
+ let content = scanner.s("--");
653
+ this.n(content);
654
+ if (!scanner.b("-->")) {
655
+ if (scanner.i(2) === "--") throw this.a("The string `--` isn't allowed inside a comment");
656
+ throw this.a("Unclosed comment");
657
+ }
658
+ return addToDocument && this.g.preserveComments ? this.k(new XmlComment(normalizeLineBreaks(content)), startIndex) : true;
659
+ }
660
+ /**
661
+ * Consumes a reference in a content context if possible.
662
+ *
663
+ * This differs from `consumeReference()` in that a consumed reference will be
664
+ * added to the document as a text node instead of returned.
665
+ *
666
+ * @returns Whether a reference was consumed.
667
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc
668
+ */
669
+ L() {
670
+ let startIndex = this.c.d;
671
+ let ref = this.E();
672
+ return ref ? this.y(ref, startIndex, false) : false;
673
+ }
674
+ /**
675
+ * Consumes a doctype declaration if possible.
676
+ *
677
+ * This is a loose implementation since DTDs are otherwise ignored. The
678
+ * internal subset is only scanned closely enough to find where it ends.
679
+ *
680
+ * @returns Whether a doctype declaration was consumed.
681
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd
682
+ */
683
+ M() {
684
+ let { c: scanner } = this;
685
+ let startIndex = scanner.d;
686
+ if (!scanner.b("<!DOCTYPE")) return false;
687
+ let name = this.e() && this.q();
688
+ if (!name) throw this.a("Expected a name");
689
+ let publicId;
690
+ let systemId;
691
+ if (this.e()) {
692
+ if (scanner.b("PUBLIC")) {
693
+ publicId = this.e() && this.N();
694
+ if (publicId === false) throw this.a("Expected a public identifier");
695
+ }
696
+ if (publicId !== void 0 || scanner.b("SYSTEM")) {
697
+ systemId = this.e() && this.r();
698
+ if (systemId === false) throw this.a("Expected a system identifier");
699
+ this.e();
700
+ }
701
+ }
702
+ let internalSubset;
703
+ if (scanner.b("[")) {
704
+ internalSubset = this.O();
705
+ if (!scanner.b("]")) throw this.a("Unclosed internal subset");
706
+ this.e();
707
+ }
708
+ if (!scanner.b(">")) throw this.a("Unclosed doctype declaration");
709
+ return this.g.preserveDocumentType ? this.k(new XmlDocumentType(name, publicId, systemId, internalSubset), startIndex) : true;
710
+ }
711
+ /**
712
+ * Consumes an element if possible.
713
+ *
714
+ * @returns Whether an element was consumed.
715
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element
716
+ */
717
+ F() {
718
+ let { c: scanner } = this;
719
+ let startIndex = scanner.d;
720
+ if (!scanner.b("<")) return false;
721
+ let name = this.q();
722
+ if (!name) {
723
+ scanner.j(startIndex);
724
+ return false;
725
+ }
726
+ if (!(this.depth < this.maxElementDepth)) {
727
+ scanner.j(startIndex);
728
+ throw this.a(`Maximum element depth of ${this.maxElementDepth} exceeded (see the \`maxElementDepth\` option)`);
729
+ }
730
+ let attributes = this.H();
731
+ let isEmpty = !!scanner.b("/>");
732
+ let element = new XmlElement(name, attributes);
733
+ element.parent = this.m;
734
+ if (!isEmpty) {
735
+ if (!scanner.b(">")) throw this.a(`Unclosed start tag for element \`${name}\``);
736
+ this.m = element;
737
+ this.depth += 1;
738
+ do
739
+ this.K();
740
+ while (this.F() || this.L() || this.J() || this.A() || this.z());
741
+ let endTagMark = scanner.d;
742
+ let endTagName;
743
+ if (!scanner.b("</") || !(endTagName = this.q()) || endTagName !== name) {
744
+ scanner.j(endTagMark);
745
+ throw this.a(`Missing end tag for element ${name}`);
746
+ }
747
+ this.e();
748
+ if (!scanner.b(">")) throw this.a(`Unclosed end tag for element ${name}`);
749
+ this.m = element.parent;
750
+ this.depth -= 1;
751
+ }
752
+ return this.k(element, startIndex);
753
+ }
754
+ /**
755
+ * Consumes an `Eq` production if possible.
756
+ *
757
+ * @returns Whether an `Eq` production was consumed.
758
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq
759
+ */
760
+ t() {
761
+ this.e();
762
+ if (this.c.b("=")) {
763
+ this.e();
764
+ return true;
765
+ }
766
+ return false;
767
+ }
768
+ /**
769
+ * Consumes the contents of a DTD internal subset, stopping before the closing
770
+ * `]` or at the first content that isn't allowed in an internal subset.
771
+ *
772
+ * The end of the internal subset is the first `]` that isn't inside a
773
+ * comment, processing instruction, or quoted literal, all of which may
774
+ * legally contain `]>`. Since DTDs are otherwise ignored, markup declarations
775
+ * are only scanned closely enough to find where they end.
776
+ *
777
+ * @returns Raw text of the internal subset.
778
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-intSubset
779
+ */
780
+ O() {
781
+ let { c: scanner } = this;
782
+ let startByteIndex = scanner.f();
783
+ while (this.e() || this.z(false) || this.A(false) || this.P() || this.Q());
784
+ return scanner.h.slice(startByteIndex, scanner.f());
785
+ }
786
+ /**
787
+ * Consumes an element, attribute-list, entity, or notation declaration in a
788
+ * DTD internal subset if possible.
789
+ *
790
+ * The declaration isn't fully parsed. Quoted literals are skipped as opaque
791
+ * units, and the declaration ends at the first `>` outside a literal.
792
+ *
793
+ * @returns Whether a markup declaration was consumed.
794
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-markupdecl
795
+ */
796
+ P() {
797
+ let { c: scanner } = this;
798
+ let startIndex = scanner.d;
799
+ if (scanner.b("<!ATTLIST")) {
800
+ if (this.g.rejectAttributeListDeclarations) {
801
+ scanner.j(startIndex);
802
+ throw this.a("Attribute-list declarations aren't allowed when `rejectAttributeListDeclarations` is enabled");
803
+ }
804
+ } else if (!scanner.b("<!ELEMENT") && !scanner.b("<!ENTITY") && !scanner.b("<!NOTATION")) return false;
805
+ for (;;) {
806
+ this.n(scanner.x(markupDeclarationDelimiter));
807
+ let char = scanner.i();
808
+ if (char === ">") {
809
+ scanner.l();
810
+ return true;
811
+ }
812
+ if (char === "\"" || char === "'") {
813
+ this.r();
814
+ continue;
815
+ }
816
+ throw this.a("Unclosed markup declaration");
817
+ }
818
+ }
819
+ /**
820
+ * Consumes `Misc` content if possible.
821
+ *
822
+ * @returns Whether anything was consumed.
823
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc
824
+ */
825
+ B() {
826
+ return this.z() || this.A() || this.e();
827
+ }
828
+ /**
829
+ * Consumes one or more `Name` characters if possible.
830
+ *
831
+ * @returns `Name` characters, or an empty string if none were consumed.
832
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name
833
+ */
834
+ q() {
835
+ return isNameStartChar(this.c.i()) ? this.c.w(isNameChar) : emptyString2;
836
+ }
837
+ /**
838
+ * Consumes a parameter entity reference in a DTD internal subset if possible.
839
+ *
840
+ * Since parse-xml doesn't expand parameter entities, a reference is rejected
841
+ * when `rejectAttributeListDeclarations` is enabled, because its replacement
842
+ * text could contain an attribute-list declaration.
843
+ *
844
+ * @returns Whether a parameter entity reference was consumed.
845
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-PEReference
846
+ */
847
+ Q() {
848
+ let { c: scanner } = this;
849
+ if (scanner.i() !== "%") return false;
850
+ if (this.g.rejectAttributeListDeclarations) throw this.a("Parameter entity references aren't allowed when `rejectAttributeListDeclarations` is enabled");
851
+ scanner.l();
852
+ if (!this.q() || !scanner.b(";")) throw this.a("Invalid parameter entity reference");
853
+ return true;
854
+ }
855
+ /**
856
+ * Consumes a processing instruction if possible.
857
+ *
858
+ * @param addToDocument
859
+ * Whether to add the processing instruction to the document. This should be
860
+ * `false` for processing instructions inside a DTD internal subset.
861
+ *
862
+ * @returns Whether a processing instruction was consumed.
863
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi
864
+ */
865
+ A(addToDocument = true) {
866
+ let { c: scanner } = this;
867
+ let startIndex = scanner.d;
868
+ if (!scanner.b("<?")) return false;
869
+ let name = this.q();
870
+ if (name) {
871
+ if (name.toLowerCase() === "xml") {
872
+ scanner.j(startIndex);
873
+ throw this.a("XML declaration isn't allowed here");
874
+ }
875
+ } else throw this.a("Invalid processing instruction");
876
+ if (!this.e()) {
877
+ if (scanner.b("?>")) return addToDocument ? this.k(new XmlProcessingInstruction(name), startIndex) : true;
878
+ throw this.a("Whitespace is required after a processing instruction name");
879
+ }
880
+ let content = scanner.s("?>");
881
+ this.n(content);
882
+ if (!scanner.b("?>")) throw this.a("Unterminated processing instruction");
883
+ return addToDocument ? this.k(new XmlProcessingInstruction(name, normalizeLineBreaks(content)), startIndex) : true;
884
+ }
885
+ /**
886
+ * Consumes a prolog if possible.
887
+ *
888
+ * @returns Whether a prolog was consumed.
889
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd
890
+ */
891
+ R() {
892
+ let { c: scanner } = this;
893
+ let startIndex = scanner.d;
894
+ this.S();
895
+ while (this.B());
896
+ if (this.M()) while (this.B());
897
+ return startIndex < scanner.d;
898
+ }
899
+ /**
900
+ * Consumes a public identifier literal if possible.
901
+ *
902
+ * @returns
903
+ * Value of the public identifier literal minus quotes, or `false` if
904
+ * nothing was consumed. An empty string indicates that a public id literal
905
+ * was consumed but was empty.
906
+ *
907
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-PubidLiteral
908
+ */
909
+ N() {
910
+ let startIndex = this.c.d;
911
+ let value = this.r();
912
+ if (value !== false && !/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(value)) {
913
+ this.c.j(startIndex);
914
+ throw this.a("Invalid character in public identifier");
915
+ }
916
+ return value;
917
+ }
918
+ /**
919
+ * Consumes a reference if possible.
920
+ *
921
+ * This differs from `consumeContentReference()` in that a consumed reference
922
+ * will be returned rather than added to the document.
923
+ *
924
+ * @returns
925
+ * Parsed reference value, or `false` if nothing was consumed (to
926
+ * distinguish from a reference that resolves to an empty string).
927
+ *
928
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference
929
+ */
930
+ E() {
931
+ let { c: scanner } = this;
932
+ if (!scanner.b("&")) return false;
933
+ let ref = scanner.w(isReferenceChar);
934
+ if (scanner.G() !== ";") throw this.a("Unterminated reference (a reference must end with `;`)");
935
+ let parsedValue;
936
+ if (ref[0] === "#") {
937
+ let codePoint = ref[1] === "x" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
938
+ if (isNaN(codePoint) || !/^#(?:x[0-9A-Fa-f]+|[0-9]+)$/.test(ref)) throw this.a("Invalid character reference");
939
+ if (!isXmlCodePoint(codePoint)) throw this.a("Character reference resolves to an invalid character");
940
+ parsedValue = String.fromCodePoint(codePoint);
941
+ } else {
942
+ parsedValue = predefinedEntities[ref];
943
+ if (parsedValue === void 0) {
944
+ let { ignoreUndefinedEntities, resolveUndefinedEntity } = this.g;
945
+ let wrappedRef = `&${ref};`;
946
+ if (resolveUndefinedEntity) {
947
+ let resolvedValue = resolveUndefinedEntity(wrappedRef);
948
+ if (resolvedValue !== null && resolvedValue !== void 0) {
949
+ let type = typeof resolvedValue;
950
+ if (type !== "string") throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${type}`);
951
+ return resolvedValue;
952
+ }
953
+ }
954
+ if (ignoreUndefinedEntities) return wrappedRef;
955
+ scanner.j(-wrappedRef.length);
956
+ throw this.a(`Named entity isn't defined: ${wrappedRef}`);
957
+ }
958
+ }
959
+ return parsedValue;
960
+ }
961
+ /**
962
+ * Consumes a `SystemLiteral` if possible.
963
+ *
964
+ * A `SystemLiteral` is similar to an attribute value, but allows the
965
+ * characters `<` and `&` and doesn't replace references.
966
+ *
967
+ * @returns
968
+ * Value of the `SystemLiteral` minus quotes, or `false` if nothing was
969
+ * consumed. An empty string indicates that a `SystemLiteral` was consumed
970
+ * but was empty.
971
+ *
972
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral
973
+ */
974
+ r() {
975
+ let { c: scanner } = this;
976
+ let quote = scanner.b("\"") || scanner.b("'");
977
+ if (!quote) return false;
978
+ let value = scanner.s(quote);
979
+ this.n(value);
980
+ if (!scanner.b(quote)) throw this.a("Missing end quote");
981
+ return value;
982
+ }
983
+ /**
984
+ * Consumes one or more whitespace characters if possible.
985
+ *
986
+ * @returns Whether any whitespace characters were consumed.
987
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
988
+ */
989
+ e() {
990
+ return !!this.c.w(isWhitespace);
991
+ }
992
+ /**
993
+ * Consumes an XML declaration if possible.
994
+ *
995
+ * @returns Whether an XML declaration was consumed.
996
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl
997
+ */
998
+ S() {
999
+ let { c: scanner } = this;
1000
+ let startIndex = scanner.d;
1001
+ if (!scanner.b("<?xml")) return false;
1002
+ if (isNameChar(scanner.i())) {
1003
+ scanner.j(startIndex);
1004
+ return false;
1005
+ }
1006
+ if (!this.e()) throw this.a("Invalid XML declaration");
1007
+ let version = !!scanner.b("version") && this.t() && this.r();
1008
+ if (version === false) throw this.a("XML version is missing or invalid");
1009
+ else if (!/^1\.[0-9]+$/.test(version)) throw this.a("Invalid character in version number");
1010
+ let encoding;
1011
+ let standalone;
1012
+ let hasWhitespace = this.e();
1013
+ if (hasWhitespace && scanner.b("encoding")) {
1014
+ let value = this.t() && this.r();
1015
+ if (value === false) throw this.a("Invalid or unclosed XML declaration");
1016
+ else if (!/^[A-Za-z][\w.-]*$/.test(value)) throw this.a("Invalid character in encoding name");
1017
+ encoding = value;
1018
+ hasWhitespace = this.e();
1019
+ }
1020
+ if (hasWhitespace && scanner.b("standalone")) {
1021
+ let value = this.t() && this.r();
1022
+ if (value === false) throw this.a("Invalid or unclosed XML declaration");
1023
+ else if (value !== "yes" && value !== "no") throw this.a("Only \"yes\" and \"no\" are permitted as values of `standalone`");
1024
+ standalone = value;
1025
+ this.e();
1026
+ }
1027
+ if (!scanner.b("?>")) throw this.a("Invalid or unclosed XML declaration");
1028
+ return this.g.preserveXmlDeclaration ? this.k(new XmlDeclaration(version, encoding, standalone), startIndex) : true;
1029
+ }
1030
+ /**
1031
+ * Returns an `XmlError` for the current scanner position.
1032
+ */
1033
+ a(message) {
1034
+ let { c: scanner } = this;
1035
+ return new XmlError(message, scanner.d, scanner.h);
1036
+ }
1037
+ /**
1038
+ * Parses the XML input.
1039
+ */
1040
+ parse() {
1041
+ this.c.b("");
1042
+ this.R();
1043
+ if (!this.F()) throw this.a("Root element is missing or invalid");
1044
+ while (this.B());
1045
+ if (!this.c.D) throw this.a("Extra content at the end of the document");
1046
+ }
1047
+ /**
1048
+ * Throws an invalid character error if any character in the given _string_
1049
+ * isn't a valid XML character.
1050
+ */
1051
+ n(string) {
1052
+ let { length } = string;
1053
+ for (let i = 0; i < length; ++i) {
1054
+ let cp = string.codePointAt(i);
1055
+ if (!isXmlCodePoint(cp)) {
1056
+ this.c.j(-[...string.slice(i)].length);
1057
+ throw this.a("Invalid character");
1058
+ }
1059
+ if (cp > 65535) i += 1;
1060
+ }
1061
+ }
1062
+ };
1063
+ function normalizeLineBreaks(text) {
1064
+ return text.includes("\r") ? text.replace(lineBreakToNormalize, "\n") : text;
1065
+ }
1066
+ function parseXml(xml, options) {
1067
+ return new Parser(xml, options).document;
1068
+ }
1069
+ // packages/adapter-node/src/xml.ts
1070
+ const localName = (name) => name.includes(":") ? name.split(":")[1] : name;
1071
+ const isElement = (node) => node.type === "element";
1072
+ const isText = (node) => node.type === "text";
1073
+ const child = (el, name) => {
1074
+ for (const node of el.children) if (isElement(node) && localName(node.name) === name) return node;
1075
+ };
1076
+ const textOf = (el) => {
1077
+ if (el === void 0) return;
1078
+ let result = "";
1079
+ for (const node of el.children) if (isText(node)) result += node.text;
1080
+ return result === "" ? void 0 : result;
1081
+ };
1082
+ const docRoot = (doc) => doc.root ?? void 0;
1083
+ const xmlVal = (el, name) => {
1084
+ const v = el !== void 0 ? textOf(child(el, name)) : void 0;
1085
+ if (v === void 0 || v === "") return;
1086
+ try {
1087
+ return decodeURIComponent(v.replace(/\+/g, " "));
1088
+ } catch {
1089
+ throw new BaerlyError("InvalidResponse", `Malformed percent-escape in S3 <${name}>: ${v}`);
1090
+ }
1091
+ };
1092
+ const rawXmlVal = (el, name) => {
1093
+ return el !== void 0 ? textOf(child(el, name)) : void 0;
1094
+ };
1095
+ /**
1096
+ * Build a {@link ParsedS3Error} from the element that directly carries
1097
+ * the `<Code>` / `<Message>` children — `<Error>` for S3, the inner
1098
+ * `<Error>` for STS. Returns `undefined` when neither child is present
1099
+ * so callers can fall back to the raw status. Shared by
1100
+ * {@link parseS3Error} and {@link parseStsError}, which differ only in
1101
+ * how they locate that element.
1102
+ */
1103
+ const codeMessageFrom = (el) => {
1104
+ const code = rawXmlVal(el, "Code");
1105
+ const message = rawXmlVal(el, "Message");
1106
+ if (code === void 0 && message === void 0) return;
1107
+ return {
1108
+ ...code !== void 0 && { Code: code },
1109
+ ...message !== void 0 && { Message: message }
1110
+ };
1111
+ };
1112
+ /**
1113
+ * Parse an S3 `<Error><Code>…</Code><Message>…</Message></Error>`
1114
+ * body. Returns `undefined` when the body is not a recognizable S3
1115
+ * error document (empty, HTML, a success payload, or a DTD), so
1116
+ * callers can fall back to the raw response text. This never throws:
1117
+ * it runs on a path that is already reporting an error.
1118
+ */
1119
+ const parseS3Error = (xml) => {
1120
+ if (!/<Error\b/i.test(xml) || /<!DOCTYPE\b/i.test(xml)) return;
1121
+ let root;
1122
+ try {
1123
+ root = docRoot(parseXml(xml));
1124
+ } catch {
1125
+ return;
1126
+ }
1127
+ if (root === void 0) return;
1128
+ if (localName(root.name) !== "Error") return;
1129
+ return codeMessageFrom(root);
1130
+ };
1131
+ /**
1132
+ * Parse an STS `<ErrorResponse><Error><Code>…</Code><Message>…</Message>
1133
+ * </Error></ErrorResponse>` body (the shape STS returns on a failed
1134
+ * `AssumeRoleWithWebIdentity` — e.g. `InvalidIdentityToken`,
1135
+ * `ExpiredTokenException`, `AccessDenied`). Returns `undefined` when the body
1136
+ * is not a recognizable STS error document (empty, HTML, a success payload, or
1137
+ * a DTD), so callers can fall back to the bare status. Like {@link parseS3Error}
1138
+ * this never throws — it runs on a path that is already reporting an error.
1139
+ *
1140
+ * Note the nesting differs from S3: STS wraps `<Error>` inside `<ErrorResponse>`.
1141
+ */
1142
+ const parseStsError = (xml) => {
1143
+ if (!/<Error\b/i.test(xml) || /<!DOCTYPE\b/i.test(xml)) return;
1144
+ let root;
1145
+ try {
1146
+ root = docRoot(parseXml(xml));
1147
+ } catch {
1148
+ return;
1149
+ }
1150
+ if (root === void 0) return;
1151
+ const errorEl = child(root, "Error");
1152
+ if (errorEl === void 0) return;
1153
+ return codeMessageFrom(errorEl);
1154
+ };
1155
+ /**
1156
+ * Parse an STS `AssumeRoleWithWebIdentity` success body, returning the
1157
+ * `<Credentials>` block. Reuses the hardened, DTD-guarded parser;
1158
+ * throws `InvalidResponse` on a DTD or unparseable XML. Missing fields come
1159
+ * back `undefined` so the caller can map them to its own `InvalidResponse`.
1160
+ *
1161
+ * Unlike {@link parseListObjectsV2CommandOutput}, the error on unparseable
1162
+ * XML must NOT echo the body: a success-shaped STS body carries the plaintext
1163
+ * `SecretAccessKey`/`SessionToken`, so folding it into a thrown-then-logged
1164
+ * error would leak live credentials.
1165
+ */
1166
+ const parseAssumeRoleWithWebIdentity = (xml) => {
1167
+ if (/<!DOCTYPE\b/i.test(xml)) throw new BaerlyError("InvalidResponse", "DTD not allowed in STS XML responses");
1168
+ let root;
1169
+ try {
1170
+ root = docRoot(parseXml(xml));
1171
+ } catch {
1172
+ throw new BaerlyError("InvalidResponse", "unparseable STS credentials response");
1173
+ }
1174
+ const resultEl = root !== void 0 ? child(root, "AssumeRoleWithWebIdentityResult") : void 0;
1175
+ const credsEl = resultEl !== void 0 ? child(resultEl, "Credentials") : void 0;
1176
+ return {
1177
+ AccessKeyId: rawXmlVal(credsEl, "AccessKeyId"),
1178
+ SecretAccessKey: rawXmlVal(credsEl, "SecretAccessKey"),
1179
+ SessionToken: rawXmlVal(credsEl, "SessionToken"),
1180
+ Expiration: rawXmlVal(credsEl, "Expiration")
1181
+ };
1182
+ };
1183
+ const parseLastModified = (lm) => {
1184
+ if (lm === void 0) return;
1185
+ const d = new Date(lm);
1186
+ return Number.isNaN(d.getTime()) ? void 0 : d;
1187
+ };
1188
+ const parseListObjectsV2CommandOutput = (xml) => {
1189
+ if (/<!DOCTYPE\b/i.test(xml)) throw new BaerlyError("InvalidResponse", "DTD not allowed in S3 XML responses");
1190
+ let root;
1191
+ try {
1192
+ root = docRoot(parseXml(xml));
1193
+ } catch {
1194
+ throw new BaerlyError("InvalidResponse", `Invalid XML: ${xml}`);
1195
+ }
1196
+ if (root === void 0) return {};
1197
+ if (localName(root.name) !== "ListBucketResult") return {};
1198
+ return {
1199
+ Contents: root.children.filter(isElement).filter((c) => localName(c.name) === "Contents").map((contentEl) => {
1200
+ return {
1201
+ ETag: rawXmlVal(contentEl, "ETag"),
1202
+ Key: xmlVal(contentEl, "Key"),
1203
+ LastModified: parseLastModified(rawXmlVal(contentEl, "LastModified")),
1204
+ Generation: rawXmlVal(contentEl, "Generation")
1205
+ };
1206
+ }),
1207
+ NextContinuationToken: rawXmlVal(root, "NextContinuationToken")
1208
+ };
1209
+ };
1210
+ // packages/adapter-node/src/http-transport.ts
1211
+ /**
1212
+ * Parse an HTTP `Retry-After` header into a non-negative seconds value,
1213
+ * clamped to {@link RETRY_AFTER_MAX_SECONDS}. Returns `undefined` if
1214
+ * the header is absent, malformed, or whitespace.
1215
+ *
1216
+ * RFC 7231 §7.1.3 admits two forms: delta-seconds (non-negative
1217
+ * integer) and HTTP-date. Both are accepted; dates in the past return
1218
+ * `0`. Fractional seconds, negatives, and arbitrary strings reject.
1219
+ *
1220
+ * The `now` injection point exists for the unit test; production
1221
+ * callers should pass nothing.
1222
+ */
1223
+ function parseRetryAfter(header, now = Date.now) {
1224
+ if (header === null) return;
1225
+ const trimmed = header.trim();
1226
+ if (trimmed === "") return;
1227
+ if (/^\d+$/.test(trimmed)) {
1228
+ const n = Number.parseInt(trimmed, 10);
1229
+ return Number.isFinite(n) ? Math.min(n, 60) : void 0;
1230
+ }
1231
+ if (!/[a-z]/i.test(trimmed)) return;
1232
+ const t = Date.parse(trimmed);
1233
+ if (Number.isNaN(t)) return;
1234
+ const seconds = Math.max(0, Math.ceil((t - now()) / 1e3));
1235
+ return Math.min(seconds, 60);
1236
+ }
1237
+ const retryAfterCause = (res) => {
1238
+ const hint = parseRetryAfter(res.headers.get("Retry-After"));
1239
+ return hint !== void 0 ? { retryAfterSeconds: hint } : {};
1240
+ };
1241
+ const xmlErrorDetail = (status, body) => {
1242
+ const parsed = parseS3Error(body);
1243
+ if (parsed !== void 0) {
1244
+ const code = parsed.Code ?? "UnknownError";
1245
+ return parsed.Message !== void 0 ? `${status} ${code}: ${parsed.Message}` : `${status} ${code}`;
1246
+ }
1247
+ return `${status} ${body}`;
1248
+ };
1249
+ /**
1250
+ * Shared status→{@link BaerlyError} mapping for the S3/GCS XML adapters, so
1251
+ * the retryable set (`429`/`≥500`) can't drift between them. Store-specific
1252
+ * statuses (GCS `412`; S3 `409`/`404`-with-`If-Match`) are handled inline
1253
+ * first; the rest route here: `403`→AccessDenied (permanent), `429`/`≥500`→
1254
+ * retryable NetworkError carrying `{status, retryAfterSeconds?}`, else
1255
+ * InvalidResponse. Callers `throw` the result; consumes `res.text()` on the
1256
+ * non-`403` paths. A throttle (`429`, or S3's `503 SlowDown`) also carries
1257
+ * `throttled: true`: the store refused the request without applying it.
1258
+ */
1259
+ const mapStorageError = async (res, verb, key) => {
1260
+ if (res.status === 403) return new BaerlyError("AccessDenied", `${verb} ${key}: 403`);
1261
+ if (res.status === 429 || res.status >= 500) {
1262
+ const body = await res.text();
1263
+ return new BaerlyError("NetworkError", `${verb} ${key}: ${res.status} ${body}`, { cause: {
1264
+ status: res.status,
1265
+ ...retryAfterCause(res),
1266
+ ...isThrottle(res.status, body) && { throttled: true }
1267
+ } });
1268
+ }
1269
+ return new BaerlyError("InvalidResponse", `${verb} ${key}: ${xmlErrorDetail(res.status, await res.text())}`);
1270
+ };
1271
+ const isThrottle = (status, body) => status === 429 || status === 503 && parseS3Error(body)?.Code === "SlowDown";
1272
+ /**
1273
+ * S3 error codes for an expired STS session token. S3 answers these with
1274
+ * HTTP 400, not 403; AWS SDKs treat them as a signal to refresh credentials.
1275
+ */
1276
+ const EXPIRED_TOKEN_CODES = /* @__PURE__ */ new Set(["ExpiredToken", "TokenRefreshRequired"]);
1277
+ /**
1278
+ * Read the S3 expired-token code from a `400` response, or `undefined` for
1279
+ * any other response. Reads a clone, so `res` stays readable for
1280
+ * {@link mapS3StorageError}.
1281
+ */
1282
+ const s3ExpiredTokenCode = async (res) => {
1283
+ if (res.status !== 400) return;
1284
+ const code = parseS3Error(await res.clone().text())?.Code;
1285
+ return code !== void 0 && EXPIRED_TOKEN_CODES.has(code) ? code : void 0;
1286
+ };
1287
+ /**
1288
+ * {@link mapStorageError} for the S3 adapter: a `400` carrying an
1289
+ * expired-token code is a credentials failure, so it maps to the permanent
1290
+ * `AccessDenied` whose message carries the S3 code, the state and the remedy;
1291
+ * every other response maps as {@link mapStorageError} does.
1292
+ */
1293
+ const mapS3StorageError = async (res, verb, key) => {
1294
+ if (await s3ExpiredTokenCode(res) !== void 0) return new BaerlyError("AccessDenied", `${verb} ${key}: ${xmlErrorDetail(400, await res.text())} — the credentials provider returned expired credentials even after a refresh; it should return fresh credentials with an accurate \`expiration\`.`, { resolution: "Return fresh credentials with an accurate `expiration` from the credentials provider; static session credentials must be replaced." });
1295
+ return mapStorageError(res, verb, key);
1296
+ };
1297
+ export { parseAssumeRoleWithWebIdentity as a, s3ExpiredTokenCode as i, mapStorageError as n, parseListObjectsV2CommandOutput as o, retryAfterCause as r, parseStsError as s, mapS3StorageError as t };
1298
+
1299
+ //# sourceMappingURL=http-transport-DNUM8kU-.js.map