@fgv/ts-web-extras 5.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.
Files changed (262) hide show
  1. package/.rush/temp/86c9c1ad46e237e0b957c2442bf0355cf39babba.tar.log +121 -0
  2. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +40 -0
  3. package/.rush/temp/operation/build/all.log +40 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +40 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +624 -0
  7. package/config/api-extractor.json +343 -0
  8. package/config/jest.config.json +16 -0
  9. package/config/rig.json +16 -0
  10. package/dist/ts-web-extras.d.ts +574 -0
  11. package/dist/tsdoc-metadata.json +11 -0
  12. package/docs/index.md +34 -0
  13. package/docs/ts-web-extras.browserhashprovider.hashparts.md +88 -0
  14. package/docs/ts-web-extras.browserhashprovider.hashstring.md +72 -0
  15. package/docs/ts-web-extras.browserhashprovider.md +66 -0
  16. package/docs/ts-web-extras.exportasjson.md +70 -0
  17. package/docs/ts-web-extras.exportusingfilesystemapi.md +104 -0
  18. package/docs/ts-web-extras.extractdirectorypath.md +52 -0
  19. package/docs/ts-web-extras.fileapitreeaccessors.create.md +72 -0
  20. package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +54 -0
  21. package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +72 -0
  22. package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +72 -0
  23. package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +72 -0
  24. package/docs/ts-web-extras.fileapitreeaccessors.md +114 -0
  25. package/docs/ts-web-extras.filepickeraccepttype.accept.md +11 -0
  26. package/docs/ts-web-extras.filepickeraccepttype.description.md +11 -0
  27. package/docs/ts-web-extras.filepickeraccepttype.md +75 -0
  28. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +11 -0
  29. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +58 -0
  30. package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +15 -0
  31. package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +15 -0
  32. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +66 -0
  33. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +66 -0
  34. package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +15 -0
  35. package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +11 -0
  36. package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +146 -0
  37. package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +66 -0
  38. package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +50 -0
  39. package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +15 -0
  40. package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +52 -0
  41. package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +15 -0
  42. package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +11 -0
  43. package/docs/ts-web-extras.filesystemfilehandle_2.md +92 -0
  44. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +11 -0
  45. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +58 -0
  46. package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +11 -0
  47. package/docs/ts-web-extras.filesystemgetfileoptions_2.md +58 -0
  48. package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +50 -0
  49. package/docs/ts-web-extras.filesystemhandle_2.kind.md +11 -0
  50. package/docs/ts-web-extras.filesystemhandle_2.md +119 -0
  51. package/docs/ts-web-extras.filesystemhandle_2.name.md +11 -0
  52. package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +52 -0
  53. package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +52 -0
  54. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +58 -0
  55. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +11 -0
  56. package/docs/ts-web-extras.filesystemremoveoptions_2.md +58 -0
  57. package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +11 -0
  58. package/docs/ts-web-extras.filesystemwritablefilestream_2.md +57 -0
  59. package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +50 -0
  60. package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +50 -0
  61. package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +50 -0
  62. package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +13 -0
  63. package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +56 -0
  64. package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +56 -0
  65. package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +76 -0
  66. package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +76 -0
  67. package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +72 -0
  68. package/docs/ts-web-extras.filetreehelpers.md +102 -0
  69. package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +11 -0
  70. package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +100 -0
  71. package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +11 -0
  72. package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +11 -0
  73. package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +11 -0
  74. package/docs/ts-web-extras.ifilehandletreeinitializer.md +79 -0
  75. package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +11 -0
  76. package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +11 -0
  77. package/docs/ts-web-extras.ifilelisttreeinitializer.md +58 -0
  78. package/docs/ts-web-extras.ifilemetadata.lastmodified.md +11 -0
  79. package/docs/ts-web-extras.ifilemetadata.md +124 -0
  80. package/docs/ts-web-extras.ifilemetadata.name.md +11 -0
  81. package/docs/ts-web-extras.ifilemetadata.path.md +11 -0
  82. package/docs/ts-web-extras.ifilemetadata.size.md +11 -0
  83. package/docs/ts-web-extras.ifilemetadata.type.md +11 -0
  84. package/docs/ts-web-extras.ifsaccessapis.md +56 -0
  85. package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +52 -0
  86. package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +52 -0
  87. package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +52 -0
  88. package/docs/ts-web-extras.isdirectoryhandle.md +56 -0
  89. package/docs/ts-web-extras.isfilehandle.md +56 -0
  90. package/docs/ts-web-extras.isfilepath.md +52 -0
  91. package/docs/ts-web-extras.iurlconfigoptions.config.md +13 -0
  92. package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +13 -0
  93. package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +13 -0
  94. package/docs/ts-web-extras.iurlconfigoptions.input.md +13 -0
  95. package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +13 -0
  96. package/docs/ts-web-extras.iurlconfigoptions.interactive.md +13 -0
  97. package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +13 -0
  98. package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +13 -0
  99. package/docs/ts-web-extras.iurlconfigoptions.md +286 -0
  100. package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +13 -0
  101. package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +13 -0
  102. package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +13 -0
  103. package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +13 -0
  104. package/docs/ts-web-extras.iurlconfigoptions.zippath.md +13 -0
  105. package/docs/ts-web-extras.md +512 -0
  106. package/docs/ts-web-extras.parsecontextfilter.md +52 -0
  107. package/docs/ts-web-extras.parsequalifierdefaults.md +52 -0
  108. package/docs/ts-web-extras.parseresourcetypes.md +52 -0
  109. package/docs/ts-web-extras.parseurlparameters.md +17 -0
  110. package/docs/ts-web-extras.safeshowdirectorypicker.md +72 -0
  111. package/docs/ts-web-extras.safeshowopenfilepicker.md +72 -0
  112. package/docs/ts-web-extras.safeshowsavefilepicker.md +72 -0
  113. package/docs/ts-web-extras.showdirectorypickeroptions.id.md +11 -0
  114. package/docs/ts-web-extras.showdirectorypickeroptions.md +96 -0
  115. package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +11 -0
  116. package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +11 -0
  117. package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +11 -0
  118. package/docs/ts-web-extras.showopenfilepickeroptions.id.md +11 -0
  119. package/docs/ts-web-extras.showopenfilepickeroptions.md +134 -0
  120. package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +11 -0
  121. package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +11 -0
  122. package/docs/ts-web-extras.showopenfilepickeroptions.types.md +11 -0
  123. package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +11 -0
  124. package/docs/ts-web-extras.showsavefilepickeroptions.id.md +11 -0
  125. package/docs/ts-web-extras.showsavefilepickeroptions.md +134 -0
  126. package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +11 -0
  127. package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +11 -0
  128. package/docs/ts-web-extras.showsavefilepickeroptions.types.md +11 -0
  129. package/docs/ts-web-extras.supportsfilesystemaccess.md +56 -0
  130. package/docs/ts-web-extras.treeinitializer.md +15 -0
  131. package/docs/ts-web-extras.wellknowndirectory.md +13 -0
  132. package/docs/ts-web-extras.windowwithfsaccess.md +15 -0
  133. package/etc/ts-web-extras.api.md +310 -0
  134. package/lib/index.d.ts +16 -0
  135. package/lib/index.d.ts.map +1 -0
  136. package/lib/index.js +58 -0
  137. package/lib/index.js.map +1 -0
  138. package/lib/packlets/crypto/browserHashProvider.d.ts +24 -0
  139. package/lib/packlets/crypto/browserHashProvider.d.ts.map +1 -0
  140. package/lib/packlets/crypto/browserHashProvider.js +70 -0
  141. package/lib/packlets/crypto/browserHashProvider.js.map +1 -0
  142. package/lib/packlets/crypto/index.d.ts +6 -0
  143. package/lib/packlets/crypto/index.d.ts.map +1 -0
  144. package/lib/packlets/crypto/index.js +43 -0
  145. package/lib/packlets/crypto/index.js.map +1 -0
  146. package/lib/packlets/file-api-types/index.d.ts +205 -0
  147. package/lib/packlets/file-api-types/index.d.ts.map +1 -0
  148. package/lib/packlets/file-api-types/index.js +166 -0
  149. package/lib/packlets/file-api-types/index.js.map +1 -0
  150. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +129 -0
  151. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -0
  152. package/lib/packlets/file-tree/fileApiTreeAccessors.js +334 -0
  153. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -0
  154. package/lib/packlets/file-tree/index.d.ts +6 -0
  155. package/lib/packlets/file-tree/index.d.ts.map +1 -0
  156. package/lib/packlets/file-tree/index.js +43 -0
  157. package/lib/packlets/file-tree/index.js.map +1 -0
  158. package/lib/packlets/helpers/fileTreeHelpers.d.ts +60 -0
  159. package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -0
  160. package/lib/packlets/helpers/fileTreeHelpers.js +102 -0
  161. package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -0
  162. package/lib/packlets/helpers/index.d.ts +6 -0
  163. package/lib/packlets/helpers/index.d.ts.map +1 -0
  164. package/lib/packlets/helpers/index.js +63 -0
  165. package/lib/packlets/helpers/index.js.map +1 -0
  166. package/lib/packlets/url-utils/index.d.ts +6 -0
  167. package/lib/packlets/url-utils/index.d.ts.map +1 -0
  168. package/lib/packlets/url-utils/index.js +43 -0
  169. package/lib/packlets/url-utils/index.js.map +1 -0
  170. package/lib/packlets/url-utils/urlParams.d.ts +94 -0
  171. package/lib/packlets/url-utils/urlParams.d.ts.map +1 -0
  172. package/lib/packlets/url-utils/urlParams.js +165 -0
  173. package/lib/packlets/url-utils/urlParams.js.map +1 -0
  174. package/lib/test/setupTests.d.ts +2 -0
  175. package/lib/test/setupTests.d.ts.map +1 -0
  176. package/lib/test/setupTests.js +76 -0
  177. package/lib/test/setupTests.js.map +1 -0
  178. package/lib/test/unit/browserHashProvider.test.d.ts +2 -0
  179. package/lib/test/unit/browserHashProvider.test.d.ts.map +1 -0
  180. package/lib/test/unit/browserHashProvider.test.js +142 -0
  181. package/lib/test/unit/browserHashProvider.test.js.map +1 -0
  182. package/lib/test/unit/fileApiTreeAccessors.test.d.ts +2 -0
  183. package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +1 -0
  184. package/lib/test/unit/fileApiTreeAccessors.test.js +1139 -0
  185. package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -0
  186. package/lib/test/unit/fileApiTypes.test.d.ts +2 -0
  187. package/lib/test/unit/fileApiTypes.test.d.ts.map +1 -0
  188. package/lib/test/unit/fileApiTypes.test.js +444 -0
  189. package/lib/test/unit/fileApiTypes.test.js.map +1 -0
  190. package/lib/test/unit/fileTreeHelpers.test.d.ts +2 -0
  191. package/lib/test/unit/fileTreeHelpers.test.d.ts.map +1 -0
  192. package/lib/test/unit/fileTreeHelpers.test.js +592 -0
  193. package/lib/test/unit/fileTreeHelpers.test.js.map +1 -0
  194. package/lib/test/unit/urlParams.test.d.ts +2 -0
  195. package/lib/test/unit/urlParams.test.d.ts.map +1 -0
  196. package/lib/test/unit/urlParams.test.js +395 -0
  197. package/lib/test/unit/urlParams.test.js.map +1 -0
  198. package/lib/test/utils/testHelpers.d.ts +51 -0
  199. package/lib/test/utils/testHelpers.d.ts.map +1 -0
  200. package/lib/test/utils/testHelpers.js +133 -0
  201. package/lib/test/utils/testHelpers.js.map +1 -0
  202. package/package.json +68 -0
  203. package/rush-logs/ts-web-extras.build.cache.log +3 -0
  204. package/rush-logs/ts-web-extras.build.log +40 -0
  205. package/src/index.ts +47 -0
  206. package/src/packlets/crypto/browserHashProvider.ts +73 -0
  207. package/src/packlets/crypto/index.ts +28 -0
  208. package/src/packlets/file-api-types/index.ts +345 -0
  209. package/src/packlets/file-tree/fileApiTreeAccessors.ts +420 -0
  210. package/src/packlets/file-tree/index.ts +28 -0
  211. package/src/packlets/helpers/fileTreeHelpers.ts +107 -0
  212. package/src/packlets/helpers/index.ts +28 -0
  213. package/src/packlets/url-utils/index.ts +28 -0
  214. package/src/packlets/url-utils/urlParams.ts +245 -0
  215. package/src/test/setupTests.ts +87 -0
  216. package/src/test/unit/browserHashProvider.test.ts +155 -0
  217. package/src/test/unit/browserHashProvider.test.ts.bak +376 -0
  218. package/src/test/unit/fileApiTreeAccessors.test.ts +1318 -0
  219. package/src/test/unit/fileApiTypes.test.ts +551 -0
  220. package/src/test/unit/fileTreeHelpers.test.ts +694 -0
  221. package/src/test/unit/urlParams.test.ts +464 -0
  222. package/src/test/utils/testHelpers.ts +155 -0
  223. package/temp/build/typescript/ts_l9Fw4VUO.json +1 -0
  224. package/temp/coverage/base.css +224 -0
  225. package/temp/coverage/block-navigation.js +87 -0
  226. package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
  227. package/temp/coverage/crypto/index.html +116 -0
  228. package/temp/coverage/favicon.png +0 -0
  229. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1345 -0
  230. package/temp/coverage/file-tree/index.html +116 -0
  231. package/temp/coverage/helpers/fileTreeHelpers.ts.html +406 -0
  232. package/temp/coverage/helpers/index.html +116 -0
  233. package/temp/coverage/index.html +161 -0
  234. package/temp/coverage/lcov-report/base.css +224 -0
  235. package/temp/coverage/lcov-report/block-navigation.js +87 -0
  236. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
  237. package/temp/coverage/lcov-report/crypto/index.html +116 -0
  238. package/temp/coverage/lcov-report/favicon.png +0 -0
  239. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1345 -0
  240. package/temp/coverage/lcov-report/file-tree/index.html +116 -0
  241. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +406 -0
  242. package/temp/coverage/lcov-report/helpers/index.html +116 -0
  243. package/temp/coverage/lcov-report/index.html +161 -0
  244. package/temp/coverage/lcov-report/prettify.css +1 -0
  245. package/temp/coverage/lcov-report/prettify.js +2 -0
  246. package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  247. package/temp/coverage/lcov-report/sorter.js +210 -0
  248. package/temp/coverage/lcov-report/url-utils/index.html +116 -0
  249. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +820 -0
  250. package/temp/coverage/lcov.info +1096 -0
  251. package/temp/coverage/prettify.css +1 -0
  252. package/temp/coverage/prettify.js +2 -0
  253. package/temp/coverage/sort-arrow-sprite.png +0 -0
  254. package/temp/coverage/sorter.js +210 -0
  255. package/temp/coverage/url-utils/index.html +116 -0
  256. package/temp/coverage/url-utils/urlParams.ts.html +820 -0
  257. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  258. package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/63/package_63a8257b0e4d0e7ff33f927d75f27a75 +53 -0
  259. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
  260. package/temp/ts-web-extras.api.json +5040 -0
  261. package/temp/ts-web-extras.api.md +310 -0
  262. package/tsconfig.json +7 -0
@@ -0,0 +1,592 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ require("@fgv/ts-utils-jest");
25
+ const helpers_1 = require("../../packlets/helpers");
26
+ const testHelpers_1 = require("../utils/testHelpers");
27
+ describe('FileTreeHelpers', () => {
28
+ describe('fromFileList', () => {
29
+ test('creates FileTree from simple FileList', async () => {
30
+ const fileList = (0, testHelpers_1.createMockFileList)([
31
+ { name: 'file1.txt', content: 'content1' },
32
+ { name: 'file2.txt', content: 'content2' }
33
+ ]);
34
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
35
+ expect(result).toSucceedAndSatisfy((fileTree) => {
36
+ // Verify files are accessible with proper paths
37
+ expect(fileTree.getFile('/file1.txt')).toSucceed();
38
+ expect(fileTree.getFile('/file2.txt')).toSucceed();
39
+ // Verify content can be retrieved
40
+ const content1 = fileTree.hal.getFileContents('/file1.txt');
41
+ expect(content1).toSucceedWith('content1');
42
+ const content2 = fileTree.hal.getFileContents('/file2.txt');
43
+ expect(content2).toSucceedWith('content2');
44
+ });
45
+ });
46
+ test('creates FileTree from FileList with prefix', async () => {
47
+ const fileList = (0, testHelpers_1.createMockFileList)([{ name: 'test.txt', content: 'test content' }]);
48
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList, { prefix: '/upload' });
49
+ expect(result).toSucceed();
50
+ });
51
+ test('handles empty FileList', async () => {
52
+ const fileList = (0, testHelpers_1.createMockFileList)([]);
53
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
54
+ expect(result).toSucceed();
55
+ });
56
+ test('handles various file types', async () => {
57
+ const fileList = (0, testHelpers_1.createMockFileList)([
58
+ { name: 'data.json', content: '{"key": "value"}', type: 'application/json' },
59
+ { name: 'script.js', content: 'console.log("hello");', type: 'application/javascript' },
60
+ { name: 'style.css', content: 'body { margin: 0; }', type: 'text/css' },
61
+ { name: 'readme.txt', content: 'This is a readme', type: 'text/plain' }
62
+ ]);
63
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
64
+ expect(result).toSucceedAndSatisfy((fileTree) => {
65
+ expect(fileTree.getFile('/data.json')).toSucceed();
66
+ expect(fileTree.getFile('/script.js')).toSucceed();
67
+ expect(fileTree.getFile('/style.css')).toSucceed();
68
+ expect(fileTree.getFile('/readme.txt')).toSucceed();
69
+ });
70
+ });
71
+ test('automatically applies MIME types as contentType', async () => {
72
+ const fileList = (0, testHelpers_1.createMockFileList)([
73
+ { name: 'data.json', content: '{"key": "value"}', type: 'application/json' },
74
+ { name: 'script.js', content: 'console.log("hello");', type: 'application/javascript' },
75
+ { name: 'style.css', content: 'body { margin: 0; }', type: 'text/css' },
76
+ { name: 'readme.txt', content: 'This is a readme', type: 'text/plain' },
77
+ { name: 'image.png', content: 'PNG data', type: 'image/png' },
78
+ { name: 'document.pdf', content: 'PDF content', type: 'application/pdf' },
79
+ { name: 'archive.zip', content: 'ZIP data', type: 'application/zip' }
80
+ ]);
81
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
82
+ expect(result).toSucceedAndSatisfy((fileTree) => {
83
+ // Verify MIME types are automatically applied as contentType
84
+ expect(fileTree.getFile('/data.json')).toSucceedAndSatisfy((file) => {
85
+ expect(file.contentType).toBe('application/json');
86
+ });
87
+ expect(fileTree.getFile('/script.js')).toSucceedAndSatisfy((file) => {
88
+ expect(file.contentType).toBe('application/javascript');
89
+ });
90
+ expect(fileTree.getFile('/style.css')).toSucceedAndSatisfy((file) => {
91
+ expect(file.contentType).toBe('text/css');
92
+ });
93
+ expect(fileTree.getFile('/readme.txt')).toSucceedAndSatisfy((file) => {
94
+ expect(file.contentType).toBe('text/plain');
95
+ });
96
+ expect(fileTree.getFile('/image.png')).toSucceedAndSatisfy((file) => {
97
+ expect(file.contentType).toBe('image/png');
98
+ });
99
+ expect(fileTree.getFile('/document.pdf')).toSucceedAndSatisfy((file) => {
100
+ expect(file.contentType).toBe('application/pdf');
101
+ });
102
+ expect(fileTree.getFile('/archive.zip')).toSucceedAndSatisfy((file) => {
103
+ expect(file.contentType).toBe('application/zip');
104
+ });
105
+ });
106
+ });
107
+ test('handles files without MIME types', async () => {
108
+ const fileList = (0, testHelpers_1.createMockFileList)([
109
+ { name: 'no-type.txt', content: 'content without type' },
110
+ { name: 'empty-type.dat', content: 'empty type', type: '' },
111
+ { name: 'unknown.ext', content: 'unknown extension' }
112
+ ]);
113
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
114
+ expect(result).toSucceedAndSatisfy((fileTree) => {
115
+ // Files without MIME types should have undefined contentType
116
+ expect(fileTree.getFile('/no-type.txt')).toSucceedAndSatisfy((file) => {
117
+ expect(file.contentType).toBe('text/plain'); // Default from createMockFile
118
+ });
119
+ expect(fileTree.getFile('/empty-type.dat')).toSucceedAndSatisfy((file) => {
120
+ expect(file.contentType).toBe('text/plain'); // Browser defaults empty type to text/plain
121
+ });
122
+ expect(fileTree.getFile('/unknown.ext')).toSucceedAndSatisfy((file) => {
123
+ expect(file.contentType).toBe('text/plain'); // Default from createMockFile
124
+ });
125
+ });
126
+ });
127
+ test('forces content type to string (not templated)', async () => {
128
+ const fileList = (0, testHelpers_1.createMockFileList)([
129
+ { name: 'test.json', content: '{"test": true}', type: 'application/json' }
130
+ ]);
131
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
132
+ expect(result).toSucceedAndSatisfy((fileTree) => {
133
+ // Verify the return type is FileTree<string> not FileTree<T>
134
+ expect(fileTree.getFile('/test.json')).toSucceedAndSatisfy((file) => {
135
+ expect(typeof file.contentType).toBe('string');
136
+ expect(file.contentType).toBe('application/json');
137
+ });
138
+ });
139
+ });
140
+ test('propagates file reading errors', async () => {
141
+ const badFile = {
142
+ name: 'bad.txt',
143
+ size: 10,
144
+ type: 'text/plain',
145
+ lastModified: Date.now(),
146
+ text: () => Promise.reject(new Error('Read failed'))
147
+ };
148
+ const fileList = (0, testHelpers_1.createMockFileList)([{ name: 'good.txt', content: 'good content' }]);
149
+ // Create a FileList with just the bad file
150
+ const dt = new DataTransfer();
151
+ dt.items.add(badFile);
152
+ const badFileList = dt.files;
153
+ const result = await helpers_1.FileTreeHelpers.fromFileList(badFileList);
154
+ expect(result).toFailWith(/Failed to read file/);
155
+ });
156
+ test('maintains file accessibility through FileTree API', async () => {
157
+ const fileList = (0, testHelpers_1.createMockFileList)([{ name: 'test.json', content: '{"name": "test", "value": 42}' }]);
158
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
159
+ expect(result).toSucceedAndSatisfy((fileTree) => {
160
+ const file = fileTree.getFile('/test.json');
161
+ expect(file).toSucceedAndSatisfy((fileItem) => {
162
+ // Test JSON parsing through FileTree
163
+ const jsonResult = fileItem.getContents();
164
+ expect(jsonResult).toSucceedAndSatisfy((parsed) => {
165
+ expect(parsed).toEqual({ name: 'test', value: 42 });
166
+ });
167
+ // Test raw content access
168
+ const rawResult = fileItem.getRawContents();
169
+ expect(rawResult).toSucceedWith('{"name": "test", "value": 42}');
170
+ // Test file properties
171
+ expect(fileItem.name).toBe('test.json');
172
+ expect(fileItem.extension).toBe('.json');
173
+ expect(fileItem.baseName).toBe('test');
174
+ });
175
+ });
176
+ });
177
+ });
178
+ describe('fromDirectoryUpload', () => {
179
+ test('creates FileTree from directory structure', async () => {
180
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
181
+ { path: 'project/src/index.js', content: 'console.log("main");' },
182
+ { path: 'project/src/utils.js', content: 'export const helper = () => {};' },
183
+ { path: 'project/package.json', content: '{"name": "test-project"}' },
184
+ { path: 'project/README.md', content: '# Test Project' }
185
+ ]);
186
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
187
+ expect(result).toSucceedAndSatisfy((fileTree) => {
188
+ // Verify all files are accessible
189
+ expect(fileTree.getFile('/project/src/index.js')).toSucceed();
190
+ expect(fileTree.getFile('/project/src/utils.js')).toSucceed();
191
+ expect(fileTree.getFile('/project/package.json')).toSucceed();
192
+ expect(fileTree.getFile('/project/README.md')).toSucceed();
193
+ // Verify directory structure
194
+ expect(fileTree.getDirectory('/project')).toSucceed();
195
+ expect(fileTree.getDirectory('/project/src')).toSucceed();
196
+ // Verify content retrieval
197
+ const packageContent = fileTree.hal.getFileContents('/project/package.json');
198
+ expect(packageContent).toSucceedWith('{"name": "test-project"}');
199
+ });
200
+ });
201
+ test('creates FileTree from directory with prefix', async () => {
202
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
203
+ { path: 'app/config.json', content: '{"setting": "value"}' },
204
+ { path: 'app/main.js', content: 'console.log("app");' }
205
+ ]);
206
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList, { prefix: '/upload' });
207
+ expect(result).toSucceed();
208
+ });
209
+ test('preserves directory hierarchy', async () => {
210
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
211
+ { path: 'deep/nested/structure/file1.txt', content: 'content1' },
212
+ { path: 'deep/nested/structure/file2.txt', content: 'content2' },
213
+ { path: 'deep/other/branch/file3.txt', content: 'content3' },
214
+ { path: 'deep/file4.txt', content: 'content4' }
215
+ ]);
216
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
217
+ expect(result).toSucceedAndSatisfy((fileTree) => {
218
+ // Test all directory levels
219
+ expect(fileTree.getDirectory('/deep')).toSucceed();
220
+ expect(fileTree.getDirectory('/deep/nested')).toSucceed();
221
+ expect(fileTree.getDirectory('/deep/nested/structure')).toSucceed();
222
+ expect(fileTree.getDirectory('/deep/other')).toSucceed();
223
+ expect(fileTree.getDirectory('/deep/other/branch')).toSucceed();
224
+ // Test directory traversal
225
+ const deepDir = fileTree.getDirectory('/deep');
226
+ expect(deepDir).toSucceedAndSatisfy((dir) => {
227
+ const children = dir.getChildren();
228
+ expect(children).toSucceedAndSatisfy((items) => {
229
+ const names = items.map((item) => item.name).sort();
230
+ expect(names).toContain('nested');
231
+ expect(names).toContain('other');
232
+ expect(names).toContain('file4.txt');
233
+ });
234
+ });
235
+ });
236
+ });
237
+ test('handles webkitRelativePath correctly', async () => {
238
+ // Create files with explicit webkitRelativePath
239
+ const files = [
240
+ (0, testHelpers_1.createMockFile)({
241
+ name: 'index.html',
242
+ content: '<html></html>',
243
+ webkitRelativePath: 'website/index.html'
244
+ }),
245
+ (0, testHelpers_1.createMockFile)({
246
+ name: 'style.css',
247
+ content: 'body {}',
248
+ webkitRelativePath: 'website/css/style.css'
249
+ })
250
+ ];
251
+ // Create FileList manually to preserve webkitRelativePath
252
+ const dt = new DataTransfer();
253
+ files.forEach((file) => dt.items.add(file));
254
+ const fileList = dt.files;
255
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
256
+ expect(result).toSucceedAndSatisfy((fileTree) => {
257
+ expect(fileTree.getFile('/website/index.html')).toSucceed();
258
+ expect(fileTree.getFile('/website/css/style.css')).toSucceed();
259
+ expect(fileTree.getDirectory('/website')).toSucceed();
260
+ expect(fileTree.getDirectory('/website/css')).toSucceed();
261
+ });
262
+ });
263
+ test('handles single file in directory', async () => {
264
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([{ path: 'single/file.txt', content: 'lone file' }]);
265
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
266
+ expect(result).toSucceedAndSatisfy((fileTree) => {
267
+ expect(fileTree.getFile('/single/file.txt')).toSucceed();
268
+ expect(fileTree.getDirectory('/single')).toSucceed();
269
+ });
270
+ });
271
+ test('handles empty directory upload', async () => {
272
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([]);
273
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
274
+ expect(result).toSucceed();
275
+ });
276
+ test('automatically applies MIME types as contentType in directory upload', async () => {
277
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
278
+ { path: 'project/package.json', content: '{"name": "test"}', type: 'application/json' },
279
+ { path: 'project/src/index.js', content: 'console.log("main");', type: 'application/javascript' },
280
+ { path: 'project/src/styles.css', content: 'body { color: red; }', type: 'text/css' },
281
+ { path: 'project/README.md', content: '# Project', type: 'text/markdown' },
282
+ { path: 'project/data.xml', content: '<root></root>', type: 'application/xml' },
283
+ { path: 'project/assets/logo.svg', content: '<svg></svg>', type: 'image/svg+xml' },
284
+ { path: 'project/docs/manual.pdf', content: 'PDF content', type: 'application/pdf' }
285
+ ]);
286
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
287
+ expect(result).toSucceedAndSatisfy((fileTree) => {
288
+ // Verify MIME types are automatically applied as contentType
289
+ expect(fileTree.getFile('/project/package.json')).toSucceedAndSatisfy((file) => {
290
+ expect(file.contentType).toBe('application/json');
291
+ });
292
+ expect(fileTree.getFile('/project/src/index.js')).toSucceedAndSatisfy((file) => {
293
+ expect(file.contentType).toBe('application/javascript');
294
+ });
295
+ expect(fileTree.getFile('/project/src/styles.css')).toSucceedAndSatisfy((file) => {
296
+ expect(file.contentType).toBe('text/css');
297
+ });
298
+ expect(fileTree.getFile('/project/README.md')).toSucceedAndSatisfy((file) => {
299
+ expect(file.contentType).toBe('text/markdown');
300
+ });
301
+ expect(fileTree.getFile('/project/data.xml')).toSucceedAndSatisfy((file) => {
302
+ expect(file.contentType).toBe('application/xml');
303
+ });
304
+ expect(fileTree.getFile('/project/assets/logo.svg')).toSucceedAndSatisfy((file) => {
305
+ expect(file.contentType).toBe('image/svg+xml');
306
+ });
307
+ expect(fileTree.getFile('/project/docs/manual.pdf')).toSucceedAndSatisfy((file) => {
308
+ expect(file.contentType).toBe('application/pdf');
309
+ });
310
+ });
311
+ });
312
+ test('handles mixed MIME types and missing types in directory upload', async () => {
313
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
314
+ { path: 'mixed/typed.json', content: '{}', type: 'application/json' },
315
+ { path: 'mixed/untyped.txt', content: 'plain text' }, // No type specified
316
+ { path: 'mixed/empty-type.dat', content: 'data', type: '' }, // Empty type
317
+ { path: 'mixed/binary.bin', content: 'binary data', type: 'application/octet-stream' }
318
+ ]);
319
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
320
+ expect(result).toSucceedAndSatisfy((fileTree) => {
321
+ expect(fileTree.getFile('/mixed/typed.json')).toSucceedAndSatisfy((file) => {
322
+ expect(file.contentType).toBe('application/json');
323
+ });
324
+ expect(fileTree.getFile('/mixed/untyped.txt')).toSucceedAndSatisfy((file) => {
325
+ expect(file.contentType).toBe('text/plain'); // Default from createMockFile
326
+ });
327
+ expect(fileTree.getFile('/mixed/empty-type.dat')).toSucceedAndSatisfy((file) => {
328
+ expect(file.contentType).toBe('text/plain'); // Browser defaults empty type to text/plain
329
+ });
330
+ expect(fileTree.getFile('/mixed/binary.bin')).toSucceedAndSatisfy((file) => {
331
+ expect(file.contentType).toBe('application/octet-stream');
332
+ });
333
+ });
334
+ });
335
+ test('forces content type to string for directory upload (not templated)', async () => {
336
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
337
+ { path: 'app/config.json', content: '{"app": "test"}', type: 'application/json' }
338
+ ]);
339
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
340
+ expect(result).toSucceedAndSatisfy((fileTree) => {
341
+ // Verify the return type is FileTree<string> not FileTree<T>
342
+ expect(fileTree.getFile('/app/config.json')).toSucceedAndSatisfy((file) => {
343
+ expect(typeof file.contentType).toBe('string');
344
+ expect(file.contentType).toBe('application/json');
345
+ });
346
+ });
347
+ });
348
+ });
349
+ // Note: fromFileApiFiles method was deprecated and removed.
350
+ // The functionality has been replaced by the create() method in FileApiTreeAccessors
351
+ // which uses TreeInitializer[] instead of IFileApiFile[].
352
+ describe('getOriginalFile', () => {
353
+ test('retrieves original File object by path', () => {
354
+ const fileList = (0, testHelpers_1.createMockFileList)([
355
+ { name: 'target.txt', content: 'target content', type: 'text/plain' },
356
+ { name: 'other.txt', content: 'other content', type: 'text/plain' }
357
+ ]);
358
+ const result = helpers_1.FileTreeHelpers.getOriginalFile(fileList, 'target.txt');
359
+ expect(result).toSucceedAndSatisfy((file) => {
360
+ expect(file.name).toBe('target.txt');
361
+ expect(file.type).toBe('text/plain');
362
+ expect(file.size).toBeGreaterThan(0);
363
+ });
364
+ });
365
+ test('handles webkitRelativePath matching', () => {
366
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
367
+ { path: 'folder/subfolder/file.txt', content: 'content', type: 'text/plain' }
368
+ ]);
369
+ const result = helpers_1.FileTreeHelpers.getOriginalFile(fileList, 'folder/subfolder/file.txt');
370
+ expect(result).toSucceedAndSatisfy((file) => {
371
+ expect(file.name).toBe('file.txt');
372
+ expect(file.webkitRelativePath).toBe('folder/subfolder/file.txt');
373
+ });
374
+ });
375
+ test('fails gracefully for non-existent files', () => {
376
+ const fileList = (0, testHelpers_1.createMockFileList)([{ name: 'exists.txt', content: 'content' }]);
377
+ const result = helpers_1.FileTreeHelpers.getOriginalFile(fileList, 'missing.txt');
378
+ expect(result).toFailWith(/File not found: missing\.txt/);
379
+ });
380
+ test('handles empty FileList', () => {
381
+ const fileList = (0, testHelpers_1.createMockFileList)([]);
382
+ const result = helpers_1.FileTreeHelpers.getOriginalFile(fileList, 'any.txt');
383
+ expect(result).toFailWith(/File not found/);
384
+ });
385
+ test('prioritizes exact name match over webkitRelativePath', () => {
386
+ // Create files with both regular names and webkitRelativePath
387
+ const files = [
388
+ (0, testHelpers_1.createMockFile)({ name: 'file.txt', content: 'regular file' }),
389
+ (0, testHelpers_1.createMockFile)({
390
+ name: 'other.txt',
391
+ content: 'directory file',
392
+ webkitRelativePath: 'file.txt' // Same as first file's name
393
+ })
394
+ ];
395
+ const dt = new DataTransfer();
396
+ files.forEach((file) => dt.items.add(file));
397
+ const fileList = dt.files;
398
+ const result = helpers_1.FileTreeHelpers.getOriginalFile(fileList, 'file.txt');
399
+ expect(result).toSucceedAndSatisfy((file) => {
400
+ expect(file.name).toBe('file.txt');
401
+ expect(file.size).toBeGreaterThan(0);
402
+ });
403
+ });
404
+ });
405
+ describe('extractFileListMetadata', () => {
406
+ test('extracts complete metadata from FileList', () => {
407
+ const testTime = Date.now();
408
+ const fileList = (0, testHelpers_1.createMockFileList)([
409
+ {
410
+ name: 'document.pdf',
411
+ content: 'PDF content here',
412
+ type: 'application/pdf',
413
+ lastModified: testTime
414
+ },
415
+ {
416
+ name: 'image.png',
417
+ content: 'PNG data',
418
+ type: 'image/png',
419
+ lastModified: testTime + 1000
420
+ }
421
+ ]);
422
+ const metadata = helpers_1.FileTreeHelpers.extractFileListMetadata(fileList);
423
+ expect(metadata).toHaveLength(2);
424
+ const pdfMeta = metadata.find((m) => m.name === 'document.pdf');
425
+ expect(pdfMeta).toEqual({
426
+ path: 'document.pdf',
427
+ name: 'document.pdf',
428
+ size: expect.any(Number),
429
+ type: 'application/pdf',
430
+ lastModified: testTime
431
+ });
432
+ const pngMeta = metadata.find((m) => m.name === 'image.png');
433
+ expect(pngMeta).toEqual({
434
+ path: 'image.png',
435
+ name: 'image.png',
436
+ size: expect.any(Number),
437
+ type: 'image/png',
438
+ lastModified: testTime + 1000
439
+ });
440
+ });
441
+ test('includes webkitRelativePath in path field', () => {
442
+ var _a, _b;
443
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
444
+ { path: 'project/src/main.js', content: 'main code', type: 'application/javascript' },
445
+ { path: 'project/assets/logo.png', content: 'logo data', type: 'image/png' }
446
+ ]);
447
+ const metadata = helpers_1.FileTreeHelpers.extractFileListMetadata(fileList);
448
+ expect(metadata).toHaveLength(2);
449
+ expect((_a = metadata.find((m) => m.name === 'main.js')) === null || _a === void 0 ? void 0 : _a.path).toBe('project/src/main.js');
450
+ expect((_b = metadata.find((m) => m.name === 'logo.png')) === null || _b === void 0 ? void 0 : _b.path).toBe('project/assets/logo.png');
451
+ });
452
+ test('handles various file sizes correctly', () => {
453
+ const fileList = (0, testHelpers_1.createMockFileList)([
454
+ { name: 'tiny.txt', content: '' },
455
+ { name: 'small.txt', content: 'small' },
456
+ { name: 'large.txt', content: 'x'.repeat(10000) }
457
+ ]);
458
+ const metadata = helpers_1.FileTreeHelpers.extractFileListMetadata(fileList);
459
+ const sizes = metadata.map((m) => m.size);
460
+ expect(sizes[0]).toBe(0); // empty file
461
+ expect(sizes[1]).toBeGreaterThan(0); // small file
462
+ expect(sizes[2]).toBeGreaterThan(sizes[1]); // large file
463
+ });
464
+ test('returns empty array for empty FileList', () => {
465
+ const fileList = (0, testHelpers_1.createMockFileList)([]);
466
+ const metadata = helpers_1.FileTreeHelpers.extractFileListMetadata(fileList);
467
+ expect(metadata).toEqual([]);
468
+ });
469
+ test('preserves file order', () => {
470
+ const expectedOrder = ['first.txt', 'second.txt', 'third.txt'];
471
+ const fileList = (0, testHelpers_1.createMockFileList)(expectedOrder.map((name) => ({ name, content: 'content' })));
472
+ const metadata = helpers_1.FileTreeHelpers.extractFileListMetadata(fileList);
473
+ const actualOrder = metadata.map((m) => m.name);
474
+ expect(actualOrder).toEqual(expectedOrder);
475
+ });
476
+ });
477
+ describe('extractFileMetadata', () => {
478
+ test('extracts metadata from single file', () => {
479
+ const testTime = Date.now();
480
+ const file = (0, testHelpers_1.createMockFile)({
481
+ name: 'single.txt',
482
+ content: 'single file content',
483
+ type: 'text/plain',
484
+ lastModified: testTime
485
+ });
486
+ const metadata = helpers_1.FileTreeHelpers.extractFileMetadata(file);
487
+ expect(metadata).toEqual({
488
+ path: 'single.txt',
489
+ name: 'single.txt',
490
+ size: expect.any(Number),
491
+ type: 'text/plain',
492
+ lastModified: testTime
493
+ });
494
+ });
495
+ test('handles webkitRelativePath for single file', () => {
496
+ const file = (0, testHelpers_1.createMockFile)({
497
+ name: 'nested.txt',
498
+ content: 'nested content',
499
+ type: 'text/plain',
500
+ webkitRelativePath: 'folder/nested.txt'
501
+ });
502
+ const metadata = helpers_1.FileTreeHelpers.extractFileMetadata(file);
503
+ expect(metadata.path).toBe('folder/nested.txt');
504
+ expect(metadata.name).toBe('nested.txt');
505
+ });
506
+ });
507
+ describe('Error propagation', () => {
508
+ test('propagates errors from FileApiTreeAccessors.fromFileList', async () => {
509
+ const badFile = {
510
+ name: 'bad.txt',
511
+ size: 10,
512
+ type: 'text/plain',
513
+ lastModified: Date.now(),
514
+ text: () => Promise.reject(new Error('File system error'))
515
+ };
516
+ // Create a FileList with just the bad file
517
+ const dt = new DataTransfer();
518
+ dt.items.add(badFile);
519
+ const badFileList = dt.files;
520
+ const result = await helpers_1.FileTreeHelpers.fromFileList(badFileList);
521
+ expect(result).toFailWith(/Failed to read file/);
522
+ });
523
+ test('propagates errors from FileApiTreeAccessors.fromDirectoryUpload', async () => {
524
+ const badFile = {
525
+ name: 'bad.txt',
526
+ size: 10,
527
+ type: 'text/plain',
528
+ lastModified: Date.now(),
529
+ webkitRelativePath: 'folder/bad.txt',
530
+ text: () => Promise.reject(new Error('Directory read error'))
531
+ };
532
+ const dt = new DataTransfer();
533
+ dt.items.add(badFile);
534
+ const fileList = dt.files;
535
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
536
+ expect(result).toFailWith(/Failed to read file/);
537
+ });
538
+ test('propagates errors from FileApiTreeAccessors.create via fromFileList', async () => {
539
+ const badFile = {
540
+ name: 'bad.txt',
541
+ size: 10,
542
+ type: 'text/plain',
543
+ lastModified: Date.now(),
544
+ text: () => Promise.reject(new Error('API error'))
545
+ };
546
+ // Create FileList with the bad file
547
+ const dt = new DataTransfer();
548
+ dt.items.add(badFile);
549
+ const fileList = dt.files;
550
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList);
551
+ expect(result).toFailWith(/Failed to read file/);
552
+ });
553
+ });
554
+ describe('Integration scenarios', () => {
555
+ test('handles realistic file upload scenario', async () => {
556
+ const fileList = (0, testHelpers_1.createMockFileList)([
557
+ { name: 'photo1.jpg', content: 'JPEG data 1', type: 'image/jpeg' },
558
+ { name: 'photo2.jpg', content: 'JPEG data 2', type: 'image/jpeg' },
559
+ { name: 'metadata.txt', content: 'Photo metadata', type: 'text/plain' }
560
+ ]);
561
+ const result = await helpers_1.FileTreeHelpers.fromFileList(fileList, { prefix: '/uploads' });
562
+ expect(result).toSucceed();
563
+ });
564
+ test('handles realistic project upload scenario', async () => {
565
+ const fileList = (0, testHelpers_1.createMockDirectoryFileList)([
566
+ { path: 'my-app/package.json', content: '{"name": "my-app"}' },
567
+ { path: 'my-app/src/index.js', content: 'console.log("Hello");' },
568
+ { path: 'my-app/src/components/App.jsx', content: 'export default App;' },
569
+ { path: 'my-app/public/index.html', content: '<html></html>' },
570
+ { path: 'my-app/README.md', content: '# My App' }
571
+ ]);
572
+ const result = await helpers_1.FileTreeHelpers.fromDirectoryUpload(fileList);
573
+ expect(result).toSucceedAndSatisfy((fileTree) => {
574
+ // Verify complete project structure
575
+ expect(fileTree.getDirectory('/my-app')).toSucceed();
576
+ expect(fileTree.getDirectory('/my-app/src')).toSucceed();
577
+ expect(fileTree.getDirectory('/my-app/src/components')).toSucceed();
578
+ expect(fileTree.getDirectory('/my-app/public')).toSucceed();
579
+ // Verify all files
580
+ expect(fileTree.getFile('/my-app/package.json')).toSucceed();
581
+ expect(fileTree.getFile('/my-app/src/index.js')).toSucceed();
582
+ expect(fileTree.getFile('/my-app/src/components/App.jsx')).toSucceed();
583
+ expect(fileTree.getFile('/my-app/public/index.html')).toSucceed();
584
+ expect(fileTree.getFile('/my-app/README.md')).toSucceed();
585
+ // Verify content access
586
+ const packageContent = fileTree.hal.getFileContents('/my-app/package.json');
587
+ expect(packageContent).toSucceedWith('{"name": "my-app"}');
588
+ });
589
+ });
590
+ });
591
+ });
592
+ //# sourceMappingURL=fileTreeHelpers.test.js.map