happy-dom 8.9.0 → 9.0.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.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (360) hide show
  1. package/README.md +2 -2
  2. package/lib/cookie/CookieJar.js +1 -1
  3. package/lib/cookie/CookieJar.js.map +1 -1
  4. package/lib/dom-token-list/DOMTokenList.js +24 -20
  5. package/lib/dom-token-list/DOMTokenList.js.map +1 -1
  6. package/lib/event/EventTarget.js +6 -3
  7. package/lib/event/EventTarget.js.map +1 -1
  8. package/lib/exception/DOMExceptionNameEnum.d.ts +5 -1
  9. package/lib/exception/DOMExceptionNameEnum.js +4 -0
  10. package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
  11. package/lib/fetch/AbortController.d.ts +19 -0
  12. package/lib/fetch/AbortController.js +30 -0
  13. package/lib/fetch/AbortController.js.map +1 -0
  14. package/lib/fetch/AbortSignal.d.ts +25 -0
  15. package/lib/fetch/AbortSignal.js +51 -0
  16. package/lib/fetch/AbortSignal.js.map +1 -0
  17. package/lib/fetch/Fetch.d.ts +117 -0
  18. package/lib/fetch/Fetch.js +530 -0
  19. package/lib/fetch/Fetch.js.map +1 -0
  20. package/lib/fetch/Headers.d.ts +81 -3
  21. package/lib/fetch/Headers.js +139 -24
  22. package/lib/fetch/Headers.js.map +1 -1
  23. package/lib/fetch/Request.d.ts +56 -32
  24. package/lib/fetch/Request.js +165 -110
  25. package/lib/fetch/Request.js.map +1 -1
  26. package/lib/fetch/{ResourceFetchHandler.d.ts → ResourceFetch.d.ts} +1 -1
  27. package/lib/fetch/{ResourceFetchHandler.js → ResourceFetch.js} +5 -5
  28. package/lib/fetch/ResourceFetch.js.map +1 -0
  29. package/lib/fetch/Response.d.ts +60 -26
  30. package/lib/fetch/Response.js +196 -104
  31. package/lib/fetch/Response.js.map +1 -1
  32. package/lib/fetch/data-uri/DataURIParser.d.ts +20 -0
  33. package/lib/fetch/data-uri/DataURIParser.js +60 -0
  34. package/lib/fetch/data-uri/DataURIParser.js.map +1 -0
  35. package/lib/fetch/multipart/MultipartFormDataParser.d.ts +40 -0
  36. package/lib/fetch/multipart/MultipartFormDataParser.js +81 -0
  37. package/lib/fetch/multipart/MultipartFormDataParser.js.map +1 -0
  38. package/lib/fetch/multipart/MultipartReader.d.ts +49 -0
  39. package/lib/fetch/multipart/MultipartReader.js +178 -0
  40. package/lib/fetch/multipart/MultipartReader.js.map +1 -0
  41. package/lib/fetch/types/IHeaders.d.ts +71 -0
  42. package/lib/fetch/{IHeaders.js.map → types/IHeaders.js.map} +1 -1
  43. package/lib/fetch/types/IHeadersInit.js.map +1 -0
  44. package/lib/fetch/types/IRequest.d.ts +60 -0
  45. package/lib/fetch/{IRequest.js.map → types/IRequest.js.map} +1 -1
  46. package/lib/fetch/types/IRequestBody.d.ts +7 -0
  47. package/lib/fetch/{IBody.js → types/IRequestBody.js} +1 -1
  48. package/lib/fetch/types/IRequestBody.js.map +1 -0
  49. package/lib/fetch/types/IRequestCredentials.d.ts +2 -0
  50. package/lib/fetch/types/IRequestCredentials.js +3 -0
  51. package/lib/fetch/types/IRequestCredentials.js.map +1 -0
  52. package/lib/fetch/{RequestInfo.d.ts → types/IRequestInfo.d.ts} +2 -2
  53. package/lib/fetch/types/IRequestInfo.js +3 -0
  54. package/lib/fetch/types/IRequestInfo.js.map +1 -0
  55. package/lib/fetch/types/IRequestInit.d.ts +21 -0
  56. package/lib/fetch/types/IRequestInit.js.map +1 -0
  57. package/lib/fetch/types/IRequestRedirect.d.ts +2 -0
  58. package/lib/fetch/types/IRequestRedirect.js +3 -0
  59. package/lib/fetch/types/IRequestRedirect.js.map +1 -0
  60. package/lib/fetch/types/IRequestReferrerPolicy.d.ts +2 -0
  61. package/lib/fetch/types/IRequestReferrerPolicy.js +3 -0
  62. package/lib/fetch/types/IRequestReferrerPolicy.js.map +1 -0
  63. package/lib/fetch/types/IResponse.d.ts +27 -0
  64. package/lib/fetch/{IResponse.js.map → types/IResponse.js.map} +1 -1
  65. package/lib/fetch/types/IResponseBody.d.ts +7 -0
  66. package/lib/fetch/types/IResponseBody.js +3 -0
  67. package/lib/fetch/types/IResponseBody.js.map +1 -0
  68. package/lib/fetch/types/IResponseInit.d.ts +9 -0
  69. package/lib/fetch/types/IResponseInit.js.map +1 -0
  70. package/lib/fetch/utilities/FetchBodyUtility.d.ts +44 -0
  71. package/lib/fetch/utilities/FetchBodyUtility.js +156 -0
  72. package/lib/fetch/utilities/FetchBodyUtility.js.map +1 -0
  73. package/lib/fetch/utilities/FetchCORSUtility.d.ts +12 -0
  74. package/lib/fetch/utilities/FetchCORSUtility.js +20 -0
  75. package/lib/fetch/utilities/FetchCORSUtility.js.map +1 -0
  76. package/lib/fetch/utilities/FetchRequestHeaderUtility.d.ts +12 -0
  77. package/lib/fetch/utilities/FetchRequestHeaderUtility.js +45 -0
  78. package/lib/fetch/utilities/FetchRequestHeaderUtility.js.map +1 -0
  79. package/lib/fetch/utilities/FetchRequestReferrerUtility.d.ts +55 -0
  80. package/lib/fetch/utilities/FetchRequestReferrerUtility.js +194 -0
  81. package/lib/fetch/utilities/FetchRequestReferrerUtility.js.map +1 -0
  82. package/lib/fetch/utilities/FetchRequestValidationUtility.d.ts +38 -0
  83. package/lib/fetch/utilities/FetchRequestValidationUtility.js +70 -0
  84. package/lib/fetch/utilities/FetchRequestValidationUtility.js.map +1 -0
  85. package/lib/file/Blob.d.ts +2 -2
  86. package/lib/file/Blob.js +1 -1
  87. package/lib/file/Blob.js.map +1 -1
  88. package/lib/file/File.d.ts +2 -1
  89. package/lib/file/File.js.map +1 -1
  90. package/lib/form-data/FormData.d.ts +98 -0
  91. package/lib/form-data/FormData.js +212 -0
  92. package/lib/form-data/FormData.js.map +1 -0
  93. package/lib/index.d.ts +14 -1
  94. package/lib/index.js +20 -2
  95. package/lib/index.js.map +1 -1
  96. package/lib/nodes/document/Document.d.ts +5 -17
  97. package/lib/nodes/document/Document.js +11 -54
  98. package/lib/nodes/document/Document.js.map +1 -1
  99. package/lib/nodes/document/IDocument.d.ts +1 -1
  100. package/lib/nodes/document-fragment/DocumentFragment.d.ts +3 -14
  101. package/lib/nodes/document-fragment/DocumentFragment.js +7 -51
  102. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  103. package/lib/nodes/document-fragment/IDocumentFragment.d.ts +2 -1
  104. package/lib/nodes/element/Element.d.ts +8 -8
  105. package/lib/nodes/element/Element.js +28 -45
  106. package/lib/nodes/element/Element.js.map +1 -1
  107. package/lib/nodes/element/ElementUtility.d.ts +32 -0
  108. package/lib/nodes/element/ElementUtility.js +105 -0
  109. package/lib/nodes/element/ElementUtility.js.map +1 -0
  110. package/lib/nodes/element/HTMLCollection.d.ts +26 -3
  111. package/lib/nodes/element/HTMLCollection.js +51 -0
  112. package/lib/nodes/element/HTMLCollection.js.map +1 -1
  113. package/lib/nodes/element/IHTMLCollection.d.ts +9 -2
  114. package/lib/nodes/html-anchor-element/HTMLAnchorElement.js +24 -24
  115. package/lib/nodes/html-anchor-element/HTMLAnchorElement.js.map +1 -1
  116. package/lib/nodes/html-base-element/HTMLBaseElement.js +4 -4
  117. package/lib/nodes/html-base-element/HTMLBaseElement.js.map +1 -1
  118. package/lib/nodes/html-button-element/HTMLButtonElement.d.ts +79 -3
  119. package/lib/nodes/html-button-element/HTMLButtonElement.js +158 -10
  120. package/lib/nodes/html-button-element/HTMLButtonElement.js.map +1 -1
  121. package/lib/nodes/html-button-element/IHTMLButtonElement.d.ts +28 -2
  122. package/lib/nodes/html-dialog-element/HTMLDialogElement.js +3 -3
  123. package/lib/nodes/html-dialog-element/HTMLDialogElement.js.map +1 -1
  124. package/lib/nodes/html-element/HTMLElement.js +12 -12
  125. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  126. package/lib/nodes/html-form-element/HTMLFormControlsCollection.d.ts +32 -0
  127. package/lib/nodes/html-form-element/HTMLFormControlsCollection.js +58 -0
  128. package/lib/nodes/html-form-element/HTMLFormControlsCollection.js.map +1 -0
  129. package/lib/nodes/html-form-element/HTMLFormElement.d.ts +37 -17
  130. package/lib/nodes/html-form-element/HTMLFormElement.js +128 -37
  131. package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
  132. package/lib/nodes/html-form-element/IHTMLFormControlsCollection.d.ts +25 -0
  133. package/lib/nodes/html-form-element/IHTMLFormControlsCollection.js +3 -0
  134. package/lib/nodes/html-form-element/IHTMLFormControlsCollection.js.map +1 -0
  135. package/lib/nodes/html-form-element/IHTMLFormElement.d.ts +16 -6
  136. package/lib/nodes/html-form-element/IRadioNodeList.d.ts +15 -0
  137. package/lib/nodes/html-form-element/IRadioNodeList.js +3 -0
  138. package/lib/nodes/html-form-element/IRadioNodeList.js.map +1 -0
  139. package/lib/nodes/html-form-element/RadioNodeList.d.ts +16 -0
  140. package/lib/nodes/html-form-element/RadioNodeList.js +28 -0
  141. package/lib/nodes/html-form-element/RadioNodeList.js.map +1 -0
  142. package/lib/nodes/html-image-element/HTMLImageElement.js +19 -19
  143. package/lib/nodes/html-image-element/HTMLImageElement.js.map +1 -1
  144. package/lib/nodes/html-input-element/HTMLInputElement.d.ts +43 -19
  145. package/lib/nodes/html-input-element/HTMLInputElement.js +206 -111
  146. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  147. package/lib/nodes/html-input-element/IHTMLInputElement.d.ts +14 -1
  148. package/lib/nodes/html-label-element/HTMLLabelElement.js +3 -7
  149. package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -1
  150. package/lib/nodes/html-link-element/HTMLLinkElement.js +21 -21
  151. package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
  152. package/lib/nodes/html-media-element/HTMLMediaElement.js +21 -21
  153. package/lib/nodes/html-media-element/HTMLMediaElement.js.map +1 -1
  154. package/lib/nodes/html-meta-element/HTMLMetaElement.js +8 -8
  155. package/lib/nodes/html-meta-element/HTMLMetaElement.js.map +1 -1
  156. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js +6 -6
  157. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js.map +1 -1
  158. package/lib/nodes/html-option-element/HTMLOptionElement.d.ts +3 -4
  159. package/lib/nodes/html-option-element/HTMLOptionElement.js +26 -29
  160. package/lib/nodes/html-option-element/HTMLOptionElement.js.map +1 -1
  161. package/lib/nodes/html-script-element/HTMLScriptElement.js +16 -16
  162. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  163. package/lib/nodes/html-script-element/ScriptUtility.js +5 -5
  164. package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
  165. package/lib/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.d.ts +5 -6
  166. package/lib/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.js.map +1 -1
  167. package/lib/nodes/html-select-element/HTMLSelectElement.d.ts +42 -41
  168. package/lib/nodes/html-select-element/HTMLSelectElement.js +134 -138
  169. package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -1
  170. package/lib/nodes/{html-option-element → html-select-element}/IHTMLOptionsCollection.d.ts +4 -5
  171. package/lib/nodes/html-select-element/IHTMLOptionsCollection.js.map +1 -0
  172. package/lib/nodes/html-select-element/IHTMLSelectElement.d.ts +22 -2
  173. package/lib/nodes/html-slot-element/HTMLSlotElement.js +2 -2
  174. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
  175. package/lib/nodes/html-style-element/HTMLStyleElement.js +7 -7
  176. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  177. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.d.ts +55 -2
  178. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +150 -40
  179. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
  180. package/lib/nodes/html-text-area-element/IHTMLTextAreaElement.d.ts +16 -0
  181. package/lib/nodes/node/Node.d.ts +12 -1
  182. package/lib/nodes/node/Node.js +50 -4
  183. package/lib/nodes/node/Node.js.map +1 -1
  184. package/lib/nodes/node/NodeList.d.ts +2 -3
  185. package/lib/nodes/node/NodeList.js.map +1 -1
  186. package/lib/nodes/parent-node/IParentNode.d.ts +4 -4
  187. package/lib/nodes/parent-node/ParentNodeUtility.d.ts +3 -3
  188. package/lib/nodes/parent-node/ParentNodeUtility.js +13 -11
  189. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  190. package/lib/nodes/text/Text.d.ts +13 -0
  191. package/lib/nodes/text/Text.js +30 -0
  192. package/lib/nodes/text/Text.js.map +1 -1
  193. package/lib/query-selector/QuerySelector.js +2 -2
  194. package/lib/query-selector/QuerySelector.js.map +1 -1
  195. package/lib/query-selector/SelectorItem.js +2 -0
  196. package/lib/query-selector/SelectorItem.js.map +1 -1
  197. package/lib/validity-state/ValidityState.d.ts +87 -0
  198. package/lib/validity-state/ValidityState.js +171 -0
  199. package/lib/validity-state/ValidityState.js.map +1 -0
  200. package/lib/window/GlobalWindow.d.ts +0 -8
  201. package/lib/window/GlobalWindow.js +0 -2
  202. package/lib/window/GlobalWindow.js.map +1 -1
  203. package/lib/window/INodeJSGlobal.d.ts +71 -0
  204. package/lib/window/INodeJSGlobal.js +2 -0
  205. package/lib/window/INodeJSGlobal.js.map +1 -0
  206. package/lib/window/IWindow.d.ts +30 -10
  207. package/lib/window/Window.d.ts +36 -20
  208. package/lib/window/Window.js +16 -9
  209. package/lib/window/Window.js.map +1 -1
  210. package/lib/xml-http-request/XMLHttpRequest.js +20 -12
  211. package/lib/xml-http-request/XMLHttpRequest.js.map +1 -1
  212. package/lib/xml-parser/XMLParser.js +1 -1
  213. package/lib/xml-parser/XMLParser.js.map +1 -1
  214. package/package.json +2 -3
  215. package/src/cookie/CookieJar.ts +1 -1
  216. package/src/dom-token-list/DOMTokenList.ts +24 -20
  217. package/src/event/EventTarget.ts +7 -3
  218. package/src/exception/DOMExceptionNameEnum.ts +5 -1
  219. package/src/fetch/AbortController.ts +26 -0
  220. package/src/fetch/AbortSignal.ts +44 -0
  221. package/src/fetch/Fetch.ts +666 -0
  222. package/src/fetch/Headers.ts +151 -3
  223. package/src/fetch/Request.ts +226 -94
  224. package/src/fetch/{ResourceFetchHandler.ts → ResourceFetch.ts} +3 -3
  225. package/src/fetch/Response.ts +252 -89
  226. package/src/fetch/data-uri/DataURIParser.ts +66 -0
  227. package/src/fetch/multipart/MultipartFormDataParser.ts +113 -0
  228. package/src/fetch/multipart/MultipartReader.ts +217 -0
  229. package/src/fetch/types/IHeaders.ts +80 -0
  230. package/src/fetch/types/IRequest.ts +65 -0
  231. package/src/fetch/types/IRequestBody.ts +15 -0
  232. package/src/fetch/types/IRequestCredentials.ts +2 -0
  233. package/src/fetch/types/IRequestInfo.ts +6 -0
  234. package/src/fetch/types/IRequestInit.ts +21 -0
  235. package/src/fetch/types/IRequestRedirect.ts +3 -0
  236. package/src/fetch/types/IRequestReferrerPolicy.ts +11 -0
  237. package/src/fetch/types/IResponse.ts +27 -0
  238. package/src/fetch/types/IResponseBody.ts +15 -0
  239. package/src/fetch/types/IResponseInit.ts +10 -0
  240. package/src/fetch/utilities/FetchBodyUtility.ts +175 -0
  241. package/src/fetch/utilities/FetchCORSUtility.ts +18 -0
  242. package/src/fetch/utilities/FetchRequestHeaderUtility.ts +47 -0
  243. package/src/fetch/utilities/FetchRequestReferrerUtility.ts +241 -0
  244. package/src/fetch/utilities/FetchRequestValidationUtility.ts +82 -0
  245. package/src/file/Blob.ts +2 -2
  246. package/src/file/File.ts +5 -1
  247. package/src/form-data/FormData.ts +237 -0
  248. package/src/index.ts +27 -1
  249. package/src/nodes/document/Document.ts +23 -64
  250. package/src/nodes/document/IDocument.ts +1 -1
  251. package/src/nodes/document-fragment/DocumentFragment.ts +9 -59
  252. package/src/nodes/document-fragment/IDocumentFragment.ts +2 -1
  253. package/src/nodes/element/Element.ts +43 -56
  254. package/src/nodes/element/ElementUtility.ts +137 -0
  255. package/src/nodes/element/HTMLCollection.ts +60 -3
  256. package/src/nodes/element/IHTMLCollection.ts +10 -2
  257. package/src/nodes/html-anchor-element/HTMLAnchorElement.ts +24 -24
  258. package/src/nodes/html-base-element/HTMLBaseElement.ts +4 -4
  259. package/src/nodes/html-button-element/HTMLButtonElement.ts +184 -10
  260. package/src/nodes/html-button-element/IHTMLButtonElement.ts +31 -2
  261. package/src/nodes/html-dialog-element/HTMLDialogElement.ts +3 -3
  262. package/src/nodes/html-element/HTMLElement.ts +12 -12
  263. package/src/nodes/html-form-element/HTMLFormControlsCollection.ts +76 -0
  264. package/src/nodes/html-form-element/HTMLFormElement.ts +147 -41
  265. package/src/nodes/html-form-element/IHTMLFormControlsCollection.ts +45 -0
  266. package/src/nodes/html-form-element/IHTMLFormElement.ts +17 -6
  267. package/src/nodes/html-form-element/IRadioNodeList.ts +16 -0
  268. package/src/nodes/html-form-element/RadioNodeList.ts +24 -0
  269. package/src/nodes/html-image-element/HTMLImageElement.ts +19 -19
  270. package/src/nodes/html-input-element/HTMLInputElement.ts +232 -113
  271. package/src/nodes/html-input-element/IHTMLInputElement.ts +20 -1
  272. package/src/nodes/html-label-element/HTMLLabelElement.ts +3 -7
  273. package/src/nodes/html-link-element/HTMLLinkElement.ts +21 -21
  274. package/src/nodes/html-media-element/HTMLMediaElement.ts +21 -21
  275. package/src/nodes/html-meta-element/HTMLMetaElement.ts +8 -8
  276. package/src/nodes/html-opt-group-element/HTMLOptGroupElement.ts +6 -6
  277. package/src/nodes/html-option-element/HTMLOptionElement.ts +29 -30
  278. package/src/nodes/html-script-element/HTMLScriptElement.ts +16 -16
  279. package/src/nodes/html-script-element/ScriptUtility.ts +5 -5
  280. package/src/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.ts +5 -9
  281. package/src/nodes/html-select-element/HTMLSelectElement.ts +159 -170
  282. package/src/nodes/{html-option-element → html-select-element}/IHTMLOptionsCollection.ts +4 -8
  283. package/src/nodes/html-select-element/IHTMLSelectElement.ts +25 -2
  284. package/src/nodes/html-slot-element/HTMLSlotElement.ts +2 -2
  285. package/src/nodes/html-style-element/HTMLStyleElement.ts +7 -7
  286. package/src/nodes/html-text-area-element/HTMLTextAreaElement.ts +174 -41
  287. package/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts +18 -0
  288. package/src/nodes/node/Node.ts +61 -6
  289. package/src/nodes/node/NodeList.ts +2 -3
  290. package/src/nodes/parent-node/IParentNode.ts +7 -4
  291. package/src/nodes/parent-node/ParentNodeUtility.ts +25 -15
  292. package/src/nodes/text/Text.ts +38 -0
  293. package/src/query-selector/QuerySelector.ts +2 -2
  294. package/src/query-selector/SelectorItem.ts +3 -0
  295. package/src/validity-state/ValidityState.ts +211 -0
  296. package/src/window/GlobalWindow.ts +0 -2
  297. package/src/window/INodeJSGlobal.ts +70 -0
  298. package/src/window/IWindow.ts +32 -10
  299. package/src/window/Window.ts +37 -20
  300. package/src/xml-http-request/XMLHttpRequest.ts +27 -26
  301. package/src/xml-parser/XMLParser.ts +1 -1
  302. package/lib/fetch/FetchHandler.d.ts +0 -18
  303. package/lib/fetch/FetchHandler.js +0 -83
  304. package/lib/fetch/FetchHandler.js.map +0 -1
  305. package/lib/fetch/IAbortSignal.d.ts +0 -16
  306. package/lib/fetch/IAbortSignal.js +0 -4
  307. package/lib/fetch/IAbortSignal.js.map +0 -1
  308. package/lib/fetch/IBody.d.ts +0 -17
  309. package/lib/fetch/IBody.js.map +0 -1
  310. package/lib/fetch/IHeaders.d.ts +0 -18
  311. package/lib/fetch/IHeadersInit.js.map +0 -1
  312. package/lib/fetch/IRequest.d.ts +0 -18
  313. package/lib/fetch/IRequestInit.d.ts +0 -16
  314. package/lib/fetch/IRequestInit.js.map +0 -1
  315. package/lib/fetch/IResponse.d.ts +0 -20
  316. package/lib/fetch/IResponseInit.d.ts +0 -9
  317. package/lib/fetch/IResponseInit.js.map +0 -1
  318. package/lib/fetch/RequestInfo.js +0 -3
  319. package/lib/fetch/RequestInfo.js.map +0 -1
  320. package/lib/fetch/ResourceFetchHandler.js.map +0 -1
  321. package/lib/form-data/IFormData.d.ts +0 -32
  322. package/lib/form-data/IFormData.js +0 -3
  323. package/lib/form-data/IFormData.js.map +0 -1
  324. package/lib/location/RelativeURL.d.ts +0 -15
  325. package/lib/location/RelativeURL.js +0 -19
  326. package/lib/location/RelativeURL.js.map +0 -1
  327. package/lib/nodes/element/HTMLCollectionFactory.d.ts +0 -21
  328. package/lib/nodes/element/HTMLCollectionFactory.js +0 -31
  329. package/lib/nodes/element/HTMLCollectionFactory.js.map +0 -1
  330. package/lib/nodes/html-option-element/IHTMLOptionsCollection.js.map +0 -1
  331. package/lib/nodes/node/NodeListFactory.d.ts +0 -21
  332. package/lib/nodes/node/NodeListFactory.js +0 -31
  333. package/lib/nodes/node/NodeListFactory.js.map +0 -1
  334. package/lib/nodes/validity-state/ValidityState.d.ts +0 -52
  335. package/lib/nodes/validity-state/ValidityState.js +0 -81
  336. package/lib/nodes/validity-state/ValidityState.js.map +0 -1
  337. package/src/fetch/FetchHandler.ts +0 -90
  338. package/src/fetch/IAbortSignal.ts +0 -34
  339. package/src/fetch/IBody.ts +0 -18
  340. package/src/fetch/IHeaders.ts +0 -18
  341. package/src/fetch/IRequest.ts +0 -59
  342. package/src/fetch/IRequestInit.ts +0 -41
  343. package/src/fetch/IResponse.ts +0 -22
  344. package/src/fetch/IResponseInit.ts +0 -10
  345. package/src/fetch/RequestInfo.ts +0 -6
  346. package/src/form-data/IFormData.ts +0 -33
  347. package/src/location/RelativeURL.ts +0 -17
  348. package/src/nodes/element/HTMLCollectionFactory.ts +0 -31
  349. package/src/nodes/node/NodeListFactory.ts +0 -31
  350. package/src/nodes/validity-state/ValidityState.ts +0 -84
  351. /package/lib/fetch/{IHeaders.js → types/IHeaders.js} +0 -0
  352. /package/lib/fetch/{IHeadersInit.d.ts → types/IHeadersInit.d.ts} +0 -0
  353. /package/lib/fetch/{IHeadersInit.js → types/IHeadersInit.js} +0 -0
  354. /package/lib/fetch/{IRequest.js → types/IRequest.js} +0 -0
  355. /package/lib/fetch/{IRequestInit.js → types/IRequestInit.js} +0 -0
  356. /package/lib/fetch/{IResponse.js → types/IResponse.js} +0 -0
  357. /package/lib/fetch/{IResponseInit.js → types/IResponseInit.js} +0 -0
  358. /package/lib/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.js +0 -0
  359. /package/lib/nodes/{html-option-element → html-select-element}/IHTMLOptionsCollection.js +0 -0
  360. /package/src/fetch/{IHeadersInit.ts → types/IHeadersInit.ts} +0 -0
@@ -1,7 +1,155 @@
1
- import * as NodeFetch from 'node-fetch';
2
- import IHeaders from './IHeaders';
1
+ import DOMException from '../exception/DOMException';
2
+ import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum';
3
+ import IHeaders from './types/IHeaders';
4
+ import IHeadersInit from './types/IHeadersInit';
3
5
 
4
6
  /**
5
7
  * Fetch headers.
8
+ *
9
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
6
10
  */
7
- export default class Headers extends NodeFetch.Headers implements IHeaders {}
11
+ export default class Headers implements IHeaders {
12
+ public _entries: { [k: string]: { name: string; value: string } } = {};
13
+
14
+ /**
15
+ * Constructor.
16
+ *
17
+ * @param init Headers init.
18
+ */
19
+ constructor(init?: IHeadersInit) {
20
+ if (init) {
21
+ if (init instanceof Headers) {
22
+ this._entries = JSON.parse(JSON.stringify(init._entries));
23
+ } else if (Array.isArray(init)) {
24
+ for (const entry of init) {
25
+ if (entry.length !== 2) {
26
+ throw new DOMException(
27
+ 'Failed to construct "Headers": The provided init is not a valid array.',
28
+ DOMExceptionNameEnum.invalidStateError
29
+ );
30
+ }
31
+ this.append(entry[0], entry[1]);
32
+ }
33
+ } else {
34
+ for (const name of Object.keys(init)) {
35
+ this.set(name, init[name]);
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist.
43
+ *
44
+ * @param name Name.
45
+ * @param value Value.
46
+ */
47
+ public append(name: string, value: string): void {
48
+ const lowerName = name.toLowerCase();
49
+ if (this._entries[lowerName]) {
50
+ this._entries[lowerName].value += `, ${value}`;
51
+ } else {
52
+ this._entries[lowerName] = {
53
+ name,
54
+ value
55
+ };
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Removes an header.
61
+ *
62
+ * @param name Name.
63
+ */
64
+ public delete(name: string): void {
65
+ delete this._entries[name.toLowerCase()];
66
+ }
67
+
68
+ /**
69
+ * Returns header value.
70
+ *
71
+ * @param name Name.
72
+ * @returns Value.
73
+ */
74
+ public get(name: string): string | null {
75
+ return this._entries[name.toLowerCase()]?.value || null;
76
+ }
77
+
78
+ /**
79
+ * Sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist.
80
+ *
81
+ * @param name Name.
82
+ * @param value Value.
83
+ */
84
+ public set(name: string, value: string): void {
85
+ this._entries[name.toLowerCase()] = {
86
+ name,
87
+ value
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Returns whether an Headers object contains a certain key.
93
+ *
94
+ * @param name Name.
95
+ * @returns "true" if the Headers object contains the key.
96
+ */
97
+ public has(name: string): boolean {
98
+ return !!this._entries[name.toLowerCase()];
99
+ }
100
+
101
+ /**
102
+ * Executes a callback function once per each key/value pair in the Headers object.
103
+ *
104
+ * @param callback Callback.
105
+ */
106
+ public forEach(callback: (name: string, value: string, thisArg: IHeaders) => void): void {
107
+ for (const key of Object.keys(this._entries)) {
108
+ callback(this._entries[key].value, this._entries[key].name, this);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Returns an iterator, allowing you to go through all keys of the key/value pairs contained in this object.
114
+ *
115
+ * @returns Iterator.
116
+ */
117
+ public *keys(): IterableIterator<string> {
118
+ for (const header of Object.values(this._entries)) {
119
+ yield header.name;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Returns an iterator, allowing you to go through all values of the key/value pairs contained in this object.
125
+ *
126
+ * @returns Iterator.
127
+ */
128
+ public *values(): IterableIterator<string> {
129
+ for (const header of Object.values(this._entries)) {
130
+ yield header.value;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Returns an iterator, allowing you to go through all key/value pairs contained in this object.
136
+ *
137
+ * @returns Iterator.
138
+ */
139
+ public *entries(): IterableIterator<[string, string]> {
140
+ for (const header of Object.values(this._entries)) {
141
+ yield [header.name, header.value];
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Iterator.
147
+ *
148
+ * @returns Iterator.
149
+ */
150
+ public *[Symbol.iterator](): IterableIterator<[string, string]> {
151
+ for (const header of Object.values(this._entries)) {
152
+ yield [header.name, header.value];
153
+ }
154
+ }
155
+ }
@@ -1,159 +1,291 @@
1
- import * as NodeFetch from 'node-fetch';
2
- import IRequest from './IRequest';
3
1
  import IBlob from '../file/IBlob';
4
2
  import IDocument from '../nodes/document/IDocument';
3
+ import IRequestInit from './types/IRequestInit';
4
+ import { URL } from 'url';
5
+ import DOMException from '../exception/DOMException';
6
+ import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum';
7
+ import IRequestInfo from './types/IRequestInfo';
8
+ import IRequest from './types/IRequest';
9
+ import Headers from './Headers';
10
+ import FetchBodyUtility from './utilities/FetchBodyUtility';
11
+ import AbortSignal from './AbortSignal';
12
+ import Stream from 'stream';
13
+ import Blob from '../file/Blob';
14
+ import { TextDecoder } from 'util';
15
+ import FetchRequestValidationUtility from './utilities/FetchRequestValidationUtility';
16
+ import IRequestReferrerPolicy from './types/IRequestReferrerPolicy';
17
+ import IRequestRedirect from './types/IRequestRedirect';
18
+ import FetchRequestReferrerUtility from './utilities/FetchRequestReferrerUtility';
19
+ import FetchRequestHeaderUtility from './utilities/FetchRequestHeaderUtility';
20
+ import IRequestCredentials from './types/IRequestCredentials';
5
21
 
6
22
  /**
7
23
  * Fetch request.
24
+ *
25
+ * Based on:
26
+ * https://github.com/node-fetch/node-fetch/blob/main/src/request.js
27
+ *
28
+ * @see https://fetch.spec.whatwg.org/#request-class
8
29
  */
9
- export default class Request extends NodeFetch.Request implements IRequest {
30
+ export default class Request implements IRequest {
10
31
  // Owner document is set by a sub-class in the Window constructor
11
32
  public static _ownerDocument: IDocument = null;
12
33
  public readonly _ownerDocument: IDocument = null;
13
34
 
35
+ // Public properties
36
+ public readonly method: string;
37
+ public readonly body: Stream.Readable | null;
38
+ public readonly headers: Headers;
39
+ public readonly redirect: IRequestRedirect;
40
+ public readonly referrerPolicy: IRequestReferrerPolicy;
41
+ public readonly signal: AbortSignal;
42
+ public readonly bodyUsed: boolean = false;
43
+ public readonly credentials: IRequestCredentials;
44
+
45
+ // Internal properties
46
+ public readonly _contentLength: number | null = null;
47
+ public readonly _contentType: string | null = null;
48
+ public _referrer: '' | 'no-referrer' | 'client' | URL = 'client';
49
+ public readonly _url: URL;
50
+ public readonly _bodyBuffer: Buffer | null;
51
+
14
52
  /**
15
53
  * Constructor.
16
54
  *
17
55
  * @param input Input.
18
56
  * @param [init] Init.
19
57
  */
20
- constructor(input: NodeFetch.RequestInfo, init?: NodeFetch.RequestInit) {
21
- super(input, init);
58
+ constructor(input: IRequestInfo, init?: IRequestInit) {
22
59
  this._ownerDocument = (<typeof Request>this.constructor)._ownerDocument;
60
+
61
+ if (!input) {
62
+ throw new TypeError(`Failed to contruct 'Request': 1 argument required, only 0 present.`);
63
+ }
64
+
65
+ this.method = (init?.method || (<Request>input).method || 'GET').toUpperCase();
66
+
67
+ const { stream, buffer, contentType, contentLength } = FetchBodyUtility.getBodyStream(
68
+ input instanceof Request && (input._bodyBuffer || input.body)
69
+ ? input._bodyBuffer || FetchBodyUtility.cloneRequestBodyStream(input)
70
+ : init?.body
71
+ );
72
+
73
+ this._bodyBuffer = buffer;
74
+ this.body = stream;
75
+ this.credentials = init?.credentials || (<Request>input).credentials || 'same-origin';
76
+ this.headers = new Headers(init?.headers || (<Request>input).headers || {});
77
+
78
+ FetchRequestHeaderUtility.removeForbiddenHeaders(this.headers);
79
+
80
+ if (contentLength) {
81
+ this._contentLength = contentLength;
82
+ } else if (!this.body && (this.method === 'POST' || this.method === 'PUT')) {
83
+ this._contentLength = 0;
84
+ }
85
+
86
+ if (contentType) {
87
+ this._contentType = contentType;
88
+ } else if (input instanceof Request && input._contentType) {
89
+ this._contentType = input._contentType;
90
+ }
91
+
92
+ this.redirect = init?.redirect || (<Request>input).redirect || 'follow';
93
+ this.referrerPolicy = <IRequestReferrerPolicy>(
94
+ (init?.referrerPolicy || (<Request>input).referrerPolicy || '').toLowerCase()
95
+ );
96
+ this.signal = init?.signal || (<Request>input).signal || new AbortSignal();
97
+ this._referrer = FetchRequestReferrerUtility.getInitialReferrer(
98
+ this._ownerDocument,
99
+ init?.referrer !== null && init?.referrer !== undefined
100
+ ? init?.referrer
101
+ : (<Request>input).referrer
102
+ );
103
+
104
+ if (input instanceof URL) {
105
+ this._url = input;
106
+ } else {
107
+ try {
108
+ if (input instanceof Request && input.url) {
109
+ this._url = new URL(input.url, this._ownerDocument.location);
110
+ } else {
111
+ this._url = new URL(<string>input, this._ownerDocument.location);
112
+ }
113
+ } catch (error) {
114
+ throw new DOMException(
115
+ `Failed to construct 'Request. Invalid URL "${input}" on document location '${
116
+ this._ownerDocument.location
117
+ }'.${
118
+ this._ownerDocument.location.origin === 'null'
119
+ ? ' Relative URLs are not permitted on current document location.'
120
+ : ''
121
+ }`,
122
+ DOMExceptionNameEnum.notSupportedError
123
+ );
124
+ }
125
+ }
126
+
127
+ FetchRequestValidationUtility.validateBody(this);
128
+ FetchRequestValidationUtility.validateURL(this._url);
129
+ FetchRequestValidationUtility.validateReferrerPolicy(this.referrerPolicy);
130
+ FetchRequestValidationUtility.validateRedirect(this.redirect);
23
131
  }
24
132
 
25
133
  /**
26
- * Returns array buffer.
134
+ * Returns referrer.
27
135
  *
28
- * @returns Array buffer.
136
+ * @returns Referrer.
29
137
  */
30
- public arrayBuffer(): Promise<ArrayBuffer> {
31
- return new Promise((resolve, reject) => {
32
- const taskID = this._handlePromiseStart();
33
- super
34
- .arrayBuffer()
35
- .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
36
- .catch(this._handlePromiseError.bind(this, reject));
37
- });
138
+ public get referrer(): string {
139
+ if (!this._referrer || this._referrer === 'no-referrer') {
140
+ return '';
141
+ }
142
+
143
+ if (this._referrer === 'client') {
144
+ return 'about:client';
145
+ }
146
+
147
+ return this._referrer.toString();
38
148
  }
39
149
 
40
150
  /**
41
- * Returns blob.
151
+ * Returns URL.
42
152
  *
43
- * @returns Blob.
153
+ * @returns URL.
44
154
  */
45
- public blob(): Promise<IBlob> {
46
- return new Promise((resolve, reject) => {
47
- const taskID = this._handlePromiseStart();
48
- super
49
- .blob()
50
- .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
51
- .catch(this._handlePromiseError.bind(this, reject));
52
- });
155
+ public get url(): string {
156
+ return this._url.href;
53
157
  }
54
158
 
55
159
  /**
56
- * Returns buffer.
160
+ * Returns string tag.
57
161
  *
58
- * @returns Buffer.
162
+ * @returns String tag.
59
163
  */
60
- public buffer(): Promise<Buffer> {
61
- return new Promise((resolve, reject) => {
62
- const taskID = this._handlePromiseStart();
63
- super
64
- .buffer()
65
- .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
66
- .catch(this._handlePromiseError.bind(this, reject));
67
- });
164
+ public get [Symbol.toStringTag](): string {
165
+ return 'Request';
68
166
  }
69
167
 
70
168
  /**
71
- * Returns json.
169
+ * Returns array buffer.
72
170
  *
73
- * @returns JSON.
171
+ * @returns Array buffer.
74
172
  */
75
- public json(): Promise<unknown> {
76
- return new Promise((resolve, reject) => {
77
- const taskID = this._handlePromiseStart();
78
- super
79
- .json()
80
- .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
81
- .catch(this._handlePromiseError.bind(this, reject));
82
- });
173
+ public async arrayBuffer(): Promise<ArrayBuffer> {
174
+ if (this.bodyUsed) {
175
+ throw new DOMException(
176
+ `Body has already been used for "${this.url}".`,
177
+ DOMExceptionNameEnum.invalidStateError
178
+ );
179
+ }
180
+
181
+ (<boolean>this.bodyUsed) = true;
182
+
183
+ const taskManager = this._ownerDocument.defaultView.happyDOM.asyncTaskManager;
184
+ const taskID = taskManager.startTask(() => this.signal._abort());
185
+ let buffer: Buffer;
186
+
187
+ try {
188
+ buffer = await FetchBodyUtility.consumeBodyStream(this.body);
189
+ } catch (error) {
190
+ taskManager.endTask(taskID);
191
+ throw error;
192
+ }
193
+
194
+ taskManager.endTask(taskID);
195
+
196
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
83
197
  }
84
198
 
85
199
  /**
86
- * Returns json.
200
+ * Returns blob.
87
201
  *
88
- * @returns JSON.
202
+ * @returns Blob.
89
203
  */
90
- public text(): Promise<string> {
91
- return new Promise((resolve, reject) => {
92
- const taskID = this._handlePromiseStart();
93
- super
94
- .text()
95
- .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
96
- .catch(this._handlePromiseError.bind(this, reject));
97
- });
204
+ public async blob(): Promise<IBlob> {
205
+ const type = this.headers.get('content-type') || '';
206
+ const buffer = await this.arrayBuffer();
207
+
208
+ return new Blob([buffer], { type });
98
209
  }
99
210
 
100
211
  /**
101
- * Returns json.
212
+ * Returns buffer.
102
213
  *
103
- * @returns JSON.
214
+ * @returns Buffer.
104
215
  */
105
- public textConverted(): Promise<string> {
106
- return new Promise((resolve, reject) => {
107
- const taskID = this._handlePromiseStart();
108
- super
109
- .textConverted()
110
- .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
111
- .catch(this._handlePromiseError.bind(this, reject));
112
- });
216
+ public async buffer(): Promise<Buffer> {
217
+ if (this.bodyUsed) {
218
+ throw new DOMException(
219
+ `Body has already been used for "${this.url}".`,
220
+ DOMExceptionNameEnum.invalidStateError
221
+ );
222
+ }
223
+
224
+ (<boolean>this.bodyUsed) = true;
225
+
226
+ const taskManager = this._ownerDocument.defaultView.happyDOM.asyncTaskManager;
227
+ const taskID = taskManager.startTask(() => this.signal._abort());
228
+ let buffer: Buffer;
229
+
230
+ try {
231
+ buffer = await FetchBodyUtility.consumeBodyStream(this.body);
232
+ } catch (error) {
233
+ taskManager.endTask(taskID);
234
+ throw error;
235
+ }
236
+
237
+ taskManager.endTask(taskID);
238
+
239
+ return buffer;
113
240
  }
114
241
 
115
242
  /**
116
- * Handles promise start.
243
+ * Returns text.
117
244
  *
118
- * @returns Task ID.
245
+ * @returns Text.
119
246
  */
120
- private _handlePromiseStart(): number {
247
+ public async text(): Promise<string> {
248
+ if (this.bodyUsed) {
249
+ throw new DOMException(
250
+ `Body has already been used for "${this.url}".`,
251
+ DOMExceptionNameEnum.invalidStateError
252
+ );
253
+ }
254
+
255
+ (<boolean>this.bodyUsed) = true;
256
+
121
257
  const taskManager = this._ownerDocument.defaultView.happyDOM.asyncTaskManager;
122
- return taskManager.startTask();
258
+ const taskID = taskManager.startTask(() => this.signal._abort());
259
+ let buffer: Buffer;
260
+
261
+ try {
262
+ buffer = await FetchBodyUtility.consumeBodyStream(this.body);
263
+ } catch (error) {
264
+ taskManager.endTask(taskID);
265
+ throw error;
266
+ }
267
+
268
+ taskManager.endTask(taskID);
269
+
270
+ return new TextDecoder().decode(buffer);
123
271
  }
124
272
 
125
273
  /**
126
- * Handles promise end.
274
+ * Returns json.
127
275
  *
128
- * @param resolve Resolve.
129
- * @param reject Reject.
130
- * @param taskID Task ID.
131
- * @param response Response.
276
+ * @returns JSON.
132
277
  */
133
- private _handlePromiseEnd(
134
- resolve: (response: unknown) => void,
135
- reject: (error: Error) => void,
136
- taskID: number,
137
- response: unknown
138
- ): void {
139
- const taskManager = this._ownerDocument.defaultView.happyDOM.asyncTaskManager;
140
- if (taskManager.getTaskCount() === 0) {
141
- reject(new Error('Failed to complete fetch request. Task was canceled.'));
142
- } else {
143
- resolve(response);
144
- taskManager.endTask(taskID);
145
- }
278
+ public async json(): Promise<string> {
279
+ const text = await this.text();
280
+ return JSON.parse(text);
146
281
  }
147
282
 
148
283
  /**
149
- * Handles promise error.
284
+ * Clones request.
150
285
  *
151
- * @param error
152
- * @param reject
286
+ * @returns Clone.
153
287
  */
154
- private _handlePromiseError(reject: (error: Error) => void, error: Error): void {
155
- const taskManager = this._ownerDocument.defaultView.happyDOM.asyncTaskManager;
156
- reject(error);
157
- taskManager.cancelAll(error);
288
+ public clone(): IRequest {
289
+ return <IRequest>new Request(this);
158
290
  }
159
291
  }
@@ -1,11 +1,11 @@
1
- import RelativeURL from '../location/RelativeURL';
2
1
  import DOMException from '../exception/DOMException';
3
2
  import IDocument from '../nodes/document/IDocument';
3
+ import { URL } from 'url';
4
4
 
5
5
  /**
6
6
  * Helper class for performing fetch of resources.
7
7
  */
8
- export default class ResourceFetchHandler {
8
+ export default class ResourceFetch {
9
9
  /**
10
10
  * Returns resource data asynchronously.
11
11
  *
@@ -32,7 +32,7 @@ export default class ResourceFetchHandler {
32
32
  */
33
33
  public static fetchSync(document: IDocument, url: string): string {
34
34
  // We want to only load SyncRequest when it is needed to improve performance and not have direct dependencies to server side packages.
35
- const absoluteURL = RelativeURL.getAbsoluteURL(document.defaultView.location, url).href;
35
+ const absoluteURL = new URL(url, document.defaultView.location).href;
36
36
 
37
37
  const xhr = new document.defaultView.XMLHttpRequest();
38
38
  xhr.open('GET', absoluteURL, false);