@fgv/ts-web-extras 5.1.0-0 → 5.1.0-1

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 (332) hide show
  1. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +56 -33
  2. package/.rush/temp/chunked-rush-logs/ts-web-extras.test.chunks.jsonl +70 -0
  3. package/.rush/temp/operation/build/all.log +56 -33
  4. package/.rush/temp/operation/build/error.log +18 -0
  5. package/.rush/temp/operation/build/log-chunks.jsonl +56 -33
  6. package/.rush/temp/operation/build/state.json +1 -1
  7. package/.rush/temp/operation/test/all.log +70 -0
  8. package/.rush/temp/operation/test/error.log +16 -0
  9. package/.rush/temp/operation/test/log-chunks.jsonl +70 -0
  10. package/.rush/temp/operation/test/state.json +3 -0
  11. package/dist/packlets/file-tree/fileApiTreeAccessors.js +15 -0
  12. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  13. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +79 -10
  14. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  15. package/dist/packlets/file-tree/httpTreeAccessors.js +279 -0
  16. package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  17. package/dist/packlets/file-tree/index.js +1 -0
  18. package/dist/packlets/file-tree/index.js.map +1 -1
  19. package/dist/packlets/file-tree/localStorageTreeAccessors.js +51 -0
  20. package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  21. package/dist/test/unit/fileApiTreeAccessors.test.js +51 -0
  22. package/dist/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  23. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +265 -160
  24. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -1
  25. package/dist/test/unit/httpTreeAccessors.test.js +1000 -0
  26. package/dist/test/unit/httpTreeAccessors.test.js.map +1 -0
  27. package/dist/test/unit/localStorageTreeAccessors.test.js +218 -1
  28. package/dist/test/unit/localStorageTreeAccessors.test.js.map +1 -1
  29. package/dist/ts-web-extras.d.ts +124 -0
  30. package/docs/@fgv/namespaces/CryptoUtils/README.md +18 -0
  31. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserCryptoProvider.md +203 -0
  32. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserHashProvider.md +63 -0
  33. package/docs/@fgv/namespaces/CryptoUtils/functions/createBrowserCryptoProvider.md +18 -0
  34. package/docs/@fgv/namespaces/FileTreeHelpers/README.md +19 -0
  35. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileListMetadata.md +23 -0
  36. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileMetadata.md +23 -0
  37. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromDirectoryUpload.md +33 -0
  38. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromFileList.md +33 -0
  39. package/docs/@fgv/namespaces/FileTreeHelpers/functions/getOriginalFile.md +25 -0
  40. package/docs/@fgv/namespaces/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +11 -0
  41. package/docs/README.md +78 -0
  42. package/docs/classes/DirectoryHandleStore.md +116 -0
  43. package/docs/classes/FileApiTreeAccessors.md +286 -0
  44. package/docs/classes/FileSystemAccessTreeAccessors.md +557 -0
  45. package/docs/classes/HttpTreeAccessors.md +508 -0
  46. package/docs/classes/LocalStorageTreeAccessors.md +520 -0
  47. package/docs/functions/exportAsJson.md +23 -0
  48. package/docs/functions/exportUsingFileSystemAPI.md +26 -0
  49. package/docs/functions/extractDirectoryPath.md +23 -0
  50. package/docs/functions/isDirectoryHandle.md +23 -0
  51. package/docs/functions/isFileHandle.md +23 -0
  52. package/docs/functions/isFilePath.md +21 -0
  53. package/docs/functions/parseContextFilter.md +22 -0
  54. package/docs/functions/parseQualifierDefaults.md +22 -0
  55. package/docs/functions/parseResourceTypes.md +22 -0
  56. package/docs/functions/parseUrlParameters.md +15 -0
  57. package/docs/functions/safeShowDirectoryPicker.md +24 -0
  58. package/docs/functions/safeShowOpenFilePicker.md +24 -0
  59. package/docs/functions/safeShowSaveFilePicker.md +24 -0
  60. package/docs/functions/supportsFileSystemAccess.md +23 -0
  61. package/docs/interfaces/FilePickerAcceptType.md +16 -0
  62. package/docs/interfaces/FileSystemCreateWritableOptions.md +15 -0
  63. package/docs/interfaces/FileSystemDirectoryHandle.md +187 -0
  64. package/docs/interfaces/FileSystemFileHandle.md +106 -0
  65. package/docs/interfaces/FileSystemGetDirectoryOptions.md +15 -0
  66. package/docs/interfaces/FileSystemGetFileOptions.md +15 -0
  67. package/docs/interfaces/FileSystemHandle.md +69 -0
  68. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +15 -0
  69. package/docs/interfaces/FileSystemRemoveOptions.md +15 -0
  70. package/docs/interfaces/FileSystemWritableFileStream.md +127 -0
  71. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +17 -0
  72. package/docs/interfaces/IFileHandleTreeInitializer.md +16 -0
  73. package/docs/interfaces/IFileListTreeInitializer.md +15 -0
  74. package/docs/interfaces/IFileMetadata.md +19 -0
  75. package/docs/interfaces/IFileSystemAccessTreeParams.md +30 -0
  76. package/docs/interfaces/IFsAccessApis.md +57 -0
  77. package/docs/interfaces/IHttpTreeParams.md +32 -0
  78. package/docs/interfaces/ILocalStorageTreeParams.md +30 -0
  79. package/docs/interfaces/IUrlConfigOptions.md +27 -0
  80. package/docs/interfaces/ShowDirectoryPickerOptions.md +17 -0
  81. package/docs/interfaces/ShowOpenFilePickerOptions.md +19 -0
  82. package/docs/interfaces/ShowSaveFilePickerOptions.md +19 -0
  83. package/docs/type-aliases/TreeInitializer.md +11 -0
  84. package/docs/type-aliases/WellKnownDirectory.md +11 -0
  85. package/docs/type-aliases/WindowWithFsAccess.md +11 -0
  86. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +11 -0
  87. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +11 -0
  88. package/etc/ts-web-extras.api.md +33 -0
  89. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +9 -0
  90. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
  91. package/lib/packlets/file-tree/fileApiTreeAccessors.js +15 -0
  92. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  93. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts +17 -1
  94. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -1
  95. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +78 -9
  96. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  97. package/lib/packlets/file-tree/httpTreeAccessors.d.ts +88 -0
  98. package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -0
  99. package/lib/packlets/file-tree/httpTreeAccessors.js +283 -0
  100. package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  101. package/lib/packlets/file-tree/index.d.ts +1 -0
  102. package/lib/packlets/file-tree/index.d.ts.map +1 -1
  103. package/lib/packlets/file-tree/index.js +1 -0
  104. package/lib/packlets/file-tree/index.js.map +1 -1
  105. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts +12 -0
  106. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts.map +1 -1
  107. package/lib/packlets/file-tree/localStorageTreeAccessors.js +51 -0
  108. package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  109. package/lib/test/unit/fileApiTreeAccessors.test.js +51 -0
  110. package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  111. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +265 -160
  112. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -1
  113. package/lib/test/unit/httpTreeAccessors.test.d.ts +2 -0
  114. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +1 -0
  115. package/lib/test/unit/httpTreeAccessors.test.js +1002 -0
  116. package/lib/test/unit/httpTreeAccessors.test.js.map +1 -0
  117. package/lib/test/unit/localStorageTreeAccessors.test.js +218 -1
  118. package/lib/test/unit/localStorageTreeAccessors.test.js.map +1 -1
  119. package/package.json +25 -25
  120. package/rush-logs/ts-web-extras.build.cache.log +0 -3
  121. package/rush-logs/ts-web-extras.build.error.log +18 -0
  122. package/rush-logs/ts-web-extras.build.log +56 -33
  123. package/rush-logs/ts-web-extras.test.cache.log +1 -0
  124. package/rush-logs/ts-web-extras.test.error.log +16 -0
  125. package/rush-logs/ts-web-extras.test.log +70 -0
  126. package/src/packlets/file-tree/fileApiTreeAccessors.ts +18 -0
  127. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +100 -8
  128. package/src/packlets/file-tree/httpTreeAccessors.ts +381 -0
  129. package/src/packlets/file-tree/index.ts +1 -0
  130. package/src/packlets/file-tree/localStorageTreeAccessors.ts +53 -0
  131. package/src/test/unit/fileApiTreeAccessors.test.ts +69 -0
  132. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +341 -188
  133. package/src/test/unit/httpTreeAccessors.test.ts +1278 -0
  134. package/src/test/unit/localStorageTreeAccessors.test.ts +269 -1
  135. package/temp/build/typescript/ts_8nwakTlr.json +1 -1
  136. package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
  137. package/temp/coverage/crypto/index.html +116 -0
  138. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +1 -1
  139. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +1 -1
  140. package/temp/coverage/crypto-utils/index.html +1 -1
  141. package/temp/coverage/file-tree/directoryHandleStore.ts.html +1 -1
  142. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +60 -6
  143. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +410 -134
  144. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +1228 -0
  145. package/temp/coverage/file-tree/index.html +35 -20
  146. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +318 -159
  147. package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
  148. package/temp/coverage/helpers/index.html +1 -1
  149. package/temp/coverage/index.html +11 -11
  150. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
  151. package/temp/coverage/lcov-report/crypto/index.html +116 -0
  152. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +1 -1
  153. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +1 -1
  154. package/temp/coverage/lcov-report/crypto-utils/index.html +1 -1
  155. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +1 -1
  156. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +60 -6
  157. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +410 -134
  158. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +1228 -0
  159. package/temp/coverage/lcov-report/file-tree/index.html +35 -20
  160. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +318 -159
  161. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
  162. package/temp/coverage/lcov-report/helpers/index.html +1 -1
  163. package/temp/coverage/lcov-report/index.html +11 -11
  164. package/temp/coverage/lcov-report/url-utils/index.html +1 -1
  165. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
  166. package/temp/coverage/lcov.info +1920 -1196
  167. package/temp/coverage/url-utils/index.html +1 -1
  168. package/temp/coverage/url-utils/urlParams.ts.html +1 -1
  169. package/temp/test/jest/haste-map-b931e4e63102f86c5bd4949f7dced44f-9d713eb41149188b4e5c0ae3d86d0a57-2ad8e16b24e391b8cdbe50b55c137169 +0 -0
  170. package/temp/test/jest/perf-cache-b931e4e63102f86c5bd4949f7dced44f-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
  171. package/temp/ts-web-extras.api.json +1313 -354
  172. package/temp/ts-web-extras.api.md +33 -0
  173. package/.rush/temp/81e0881271ff236956b2f52e8ca99da6574c6e1e.tar.log +0 -223
  174. package/docs/index.md +0 -34
  175. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider._constructor_.md +0 -50
  176. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.decrypt.md +0 -104
  177. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.derivekey.md +0 -88
  178. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.encrypt.md +0 -72
  179. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.frombase64.md +0 -56
  180. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generatekey.md +0 -19
  181. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generaterandombytes.md +0 -56
  182. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.md +0 -169
  183. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.tobase64.md +0 -56
  184. package/docs/ts-web-extras.cryptoutils.browserhashprovider.hashparts.md +0 -88
  185. package/docs/ts-web-extras.cryptoutils.browserhashprovider.hashstring.md +0 -72
  186. package/docs/ts-web-extras.cryptoutils.browserhashprovider.md +0 -66
  187. package/docs/ts-web-extras.cryptoutils.createbrowsercryptoprovider.md +0 -19
  188. package/docs/ts-web-extras.cryptoutils.md +0 -71
  189. package/docs/ts-web-extras.exportasjson.md +0 -70
  190. package/docs/ts-web-extras.exportusingfilesystemapi.md +0 -104
  191. package/docs/ts-web-extras.extractdirectorypath.md +0 -52
  192. package/docs/ts-web-extras.fileapitreeaccessors.create.md +0 -72
  193. package/docs/ts-web-extras.fileapitreeaccessors.createfromlocalstorage.md +0 -74
  194. package/docs/ts-web-extras.fileapitreeaccessors.createpersistent.md +0 -76
  195. package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +0 -54
  196. package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +0 -72
  197. package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +0 -72
  198. package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +0 -72
  199. package/docs/ts-web-extras.fileapitreeaccessors.md +0 -146
  200. package/docs/ts-web-extras.filepickeraccepttype.accept.md +0 -11
  201. package/docs/ts-web-extras.filepickeraccepttype.description.md +0 -11
  202. package/docs/ts-web-extras.filepickeraccepttype.md +0 -75
  203. package/docs/ts-web-extras.filesystemaccesstreeaccessors._constructor_.md +0 -114
  204. package/docs/ts-web-extras.filesystemaccesstreeaccessors.fileismutable.md +0 -52
  205. package/docs/ts-web-extras.filesystemaccesstreeaccessors.fromdirectoryhandle.md +0 -72
  206. package/docs/ts-web-extras.filesystemaccesstreeaccessors.getdirtypaths.md +0 -17
  207. package/docs/ts-web-extras.filesystemaccesstreeaccessors.isdirty.md +0 -17
  208. package/docs/ts-web-extras.filesystemaccesstreeaccessors.md +0 -159
  209. package/docs/ts-web-extras.filesystemaccesstreeaccessors.savefilecontents.md +0 -66
  210. package/docs/ts-web-extras.filesystemaccesstreeaccessors.synctodisk.md +0 -17
  211. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +0 -11
  212. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +0 -58
  213. package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +0 -15
  214. package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +0 -15
  215. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +0 -66
  216. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +0 -66
  217. package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +0 -15
  218. package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +0 -11
  219. package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +0 -146
  220. package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +0 -66
  221. package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +0 -50
  222. package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +0 -15
  223. package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +0 -52
  224. package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +0 -15
  225. package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +0 -11
  226. package/docs/ts-web-extras.filesystemfilehandle_2.md +0 -92
  227. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +0 -11
  228. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +0 -58
  229. package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +0 -11
  230. package/docs/ts-web-extras.filesystemgetfileoptions_2.md +0 -58
  231. package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +0 -50
  232. package/docs/ts-web-extras.filesystemhandle_2.kind.md +0 -11
  233. package/docs/ts-web-extras.filesystemhandle_2.md +0 -119
  234. package/docs/ts-web-extras.filesystemhandle_2.name.md +0 -11
  235. package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +0 -52
  236. package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +0 -52
  237. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +0 -58
  238. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +0 -11
  239. package/docs/ts-web-extras.filesystemremoveoptions_2.md +0 -58
  240. package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +0 -11
  241. package/docs/ts-web-extras.filesystemwritablefilestream_2.md +0 -57
  242. package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +0 -50
  243. package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +0 -50
  244. package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +0 -50
  245. package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +0 -13
  246. package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +0 -56
  247. package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +0 -56
  248. package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +0 -76
  249. package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +0 -76
  250. package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +0 -72
  251. package/docs/ts-web-extras.filetreehelpers.md +0 -102
  252. package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +0 -11
  253. package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +0 -100
  254. package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +0 -11
  255. package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +0 -11
  256. package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +0 -11
  257. package/docs/ts-web-extras.ifilehandletreeinitializer.md +0 -79
  258. package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +0 -11
  259. package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +0 -11
  260. package/docs/ts-web-extras.ifilelisttreeinitializer.md +0 -58
  261. package/docs/ts-web-extras.ifilemetadata.lastmodified.md +0 -11
  262. package/docs/ts-web-extras.ifilemetadata.md +0 -124
  263. package/docs/ts-web-extras.ifilemetadata.name.md +0 -11
  264. package/docs/ts-web-extras.ifilemetadata.path.md +0 -11
  265. package/docs/ts-web-extras.ifilemetadata.size.md +0 -11
  266. package/docs/ts-web-extras.ifilemetadata.type.md +0 -11
  267. package/docs/ts-web-extras.ifilesystemaccesstreeparams.autosync.md +0 -13
  268. package/docs/ts-web-extras.ifilesystemaccesstreeparams.md +0 -78
  269. package/docs/ts-web-extras.ifilesystemaccesstreeparams.requirewritepermission.md +0 -13
  270. package/docs/ts-web-extras.ifsaccessapis.md +0 -56
  271. package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +0 -52
  272. package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +0 -52
  273. package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +0 -52
  274. package/docs/ts-web-extras.ilocalstoragetreeparams.autosync.md +0 -13
  275. package/docs/ts-web-extras.ilocalstoragetreeparams.md +0 -97
  276. package/docs/ts-web-extras.ilocalstoragetreeparams.pathtokeymap.md +0 -13
  277. package/docs/ts-web-extras.ilocalstoragetreeparams.storage.md +0 -13
  278. package/docs/ts-web-extras.isdirectoryhandle.md +0 -56
  279. package/docs/ts-web-extras.isfilehandle.md +0 -56
  280. package/docs/ts-web-extras.isfilepath.md +0 -52
  281. package/docs/ts-web-extras.iurlconfigoptions.config.md +0 -13
  282. package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +0 -13
  283. package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +0 -13
  284. package/docs/ts-web-extras.iurlconfigoptions.input.md +0 -13
  285. package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +0 -13
  286. package/docs/ts-web-extras.iurlconfigoptions.interactive.md +0 -13
  287. package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +0 -13
  288. package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +0 -13
  289. package/docs/ts-web-extras.iurlconfigoptions.md +0 -286
  290. package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +0 -13
  291. package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +0 -13
  292. package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +0 -13
  293. package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +0 -13
  294. package/docs/ts-web-extras.iurlconfigoptions.zippath.md +0 -13
  295. package/docs/ts-web-extras.localstoragetreeaccessors.fileismutable.md +0 -56
  296. package/docs/ts-web-extras.localstoragetreeaccessors.fromstorage.md +0 -56
  297. package/docs/ts-web-extras.localstoragetreeaccessors.getdirtypaths.md +0 -19
  298. package/docs/ts-web-extras.localstoragetreeaccessors.isdirty.md +0 -19
  299. package/docs/ts-web-extras.localstoragetreeaccessors.md +0 -131
  300. package/docs/ts-web-extras.localstoragetreeaccessors.savefilecontents.md +0 -72
  301. package/docs/ts-web-extras.localstoragetreeaccessors.synctodisk.md +0 -19
  302. package/docs/ts-web-extras.md +0 -558
  303. package/docs/ts-web-extras.parsecontextfilter.md +0 -52
  304. package/docs/ts-web-extras.parsequalifierdefaults.md +0 -52
  305. package/docs/ts-web-extras.parseresourcetypes.md +0 -52
  306. package/docs/ts-web-extras.parseurlparameters.md +0 -17
  307. package/docs/ts-web-extras.safeshowdirectorypicker.md +0 -72
  308. package/docs/ts-web-extras.safeshowopenfilepicker.md +0 -72
  309. package/docs/ts-web-extras.safeshowsavefilepicker.md +0 -72
  310. package/docs/ts-web-extras.showdirectorypickeroptions.id.md +0 -11
  311. package/docs/ts-web-extras.showdirectorypickeroptions.md +0 -96
  312. package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +0 -11
  313. package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +0 -11
  314. package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +0 -11
  315. package/docs/ts-web-extras.showopenfilepickeroptions.id.md +0 -11
  316. package/docs/ts-web-extras.showopenfilepickeroptions.md +0 -134
  317. package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +0 -11
  318. package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +0 -11
  319. package/docs/ts-web-extras.showopenfilepickeroptions.types.md +0 -11
  320. package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +0 -11
  321. package/docs/ts-web-extras.showsavefilepickeroptions.id.md +0 -11
  322. package/docs/ts-web-extras.showsavefilepickeroptions.md +0 -134
  323. package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +0 -11
  324. package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +0 -11
  325. package/docs/ts-web-extras.showsavefilepickeroptions.types.md +0 -11
  326. package/docs/ts-web-extras.supportsfilesystemaccess.md +0 -56
  327. package/docs/ts-web-extras.treeinitializer.md +0 -15
  328. package/docs/ts-web-extras.wellknowndirectory.md +0 -13
  329. package/docs/ts-web-extras.windowwithfsaccess.md +0 -15
  330. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  331. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
  332. /package/temp/test/jest/{jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/8d/package_8dcbedef69e4299f0f51fcda8f4f1c8e → jest-transform-cache-b931e4e63102f86c5bd4949f7dced44f-79ef2876fae7ca75eedb2aa53dc48338/b5/package_b5f57afc9ec2c011239b1608ee5bdfa5} +0 -0
@@ -0,0 +1,70 @@
1
+ {"kind":"O","text":"Invoking: heft test --clean \n"}
2
+ {"kind":"O","text":" ---- build started ---- \n"}
3
+ {"kind":"O","text":"[build:clean] Deleted 0 files and 3 folders\n"}
4
+ {"kind":"O","text":"[build:typescript] The TypeScript compiler version 5.9.3 is newer than the latest version that was tested with Heft (5.8); it may not work correctly.\n"}
5
+ {"kind":"O","text":"[build:typescript] Using TypeScript version 5.9.3\n"}
6
+ {"kind":"O","text":"[build:api-extractor] Using API Extractor version 7.55.2\n"}
7
+ {"kind":"O","text":"[build:api-extractor] Analysis will use the bundled TypeScript version 5.8.2\n"}
8
+ {"kind":"O","text":"[build:api-extractor] *** The target project appears to use TypeScript 5.9.3 which is newer than the bundled compiler engine; consider upgrading API Extractor.\n"}
9
+ {"kind":"O","text":" ---- build finished (2.899s) ---- \n"}
10
+ {"kind":"O","text":" ---- test started ---- \n"}
11
+ {"kind":"O","text":"[test:clean] Deleted 0 files and 1 folder\n"}
12
+ {"kind":"O","text":"[test:jest] Using Jest version 29.5.0\n"}
13
+ {"kind":"O","text":"[test:jest] \n"}
14
+ {"kind":"O","text":"[test:jest] Run start. 8 test suites\n"}
15
+ {"kind":"O","text":"[test:jest] START lib/test/unit/fileApiTreeAccessors.test.js\n"}
16
+ {"kind":"O","text":"[test:jest] START lib/test/unit/fileTreeHelpers.test.js\n"}
17
+ {"kind":"O","text":"[test:jest] START lib/test/unit/fileSystemAccessTreeAccessors.test.js\n"}
18
+ {"kind":"O","text":"[test:jest] START lib/test/unit/localStorageTreeAccessors.test.js\n"}
19
+ {"kind":"O","text":"[test:jest] START lib/test/unit/fileApiTypes.test.js\n"}
20
+ {"kind":"O","text":"[test:jest] START lib/test/unit/urlParams.test.js\n"}
21
+ {"kind":"O","text":"[test:jest] START lib/test/unit/directoryHandleStore.test.js\n"}
22
+ {"kind":"O","text":"[test:jest] START lib/test/unit/browserHashProvider.test.js\n"}
23
+ {"kind":"E","text":"(node:35708) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
24
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
25
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/localStorageTreeAccessors.test.js (duration: 0.633s, 33 passed, 0 failed)\n"}
26
+ {"kind":"E","text":"(node:35707) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
27
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
28
+ {"kind":"E","text":"(node:35710) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
29
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
30
+ {"kind":"E","text":"(node:35711) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
31
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
32
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/directoryHandleStore.test.js (duration: 0.656s, 19 passed, 0 failed)\n"}
33
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/urlParams.test.js (duration: 0.661s, 60 passed, 0 failed)\n"}
34
+ {"kind":"E","text":"(node:35705) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
35
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
36
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/fileApiTreeAccessors.test.js (duration: 0.660s, 63 passed, 0 failed)\n"}
37
+ {"kind":"E","text":"(node:35709) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
38
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
39
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/fileApiTypes.test.js (duration: 0.676s, 36 passed, 0 failed)\n"}
40
+ {"kind":"E","text":"(node:35712) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
41
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
42
+ {"kind":"E","text":"(node:35706) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"}
43
+ {"kind":"E","text":"(Use `node --trace-deprecation ...` to show where the warning was created)\n"}
44
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/fileTreeHelpers.test.js (duration: 0.713s, 35 passed, 0 failed)\n"}
45
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/fileSystemAccessTreeAccessors.test.js (duration: 0.719s, 38 passed, 0 failed)\n"}
46
+ {"kind":"O","text":"[test:jest] PASS lib/test/unit/browserHashProvider.test.js (duration: 0.723s, 15 passed, 0 failed)\n"}
47
+ {"kind":"O","text":"[test:jest] \n"}
48
+ {"kind":"O","text":"[test:jest] Tests finished:\n"}
49
+ {"kind":"O","text":"[test:jest] Successes: 299\n"}
50
+ {"kind":"O","text":"[test:jest] Failures: 0\n"}
51
+ {"kind":"O","text":"[test:jest] Total: 300\n"}
52
+ {"kind":"O","text":"-----------------------------------|---------|----------|---------|---------|------------------------------------\n"}
53
+ {"kind":"O","text":"File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n"}
54
+ {"kind":"O","text":"-----------------------------------|---------|----------|---------|---------|------------------------------------\n"}
55
+ {"kind":"O","text":"All files | 100 | 95.68 | 100 | 100 | \n"}
56
+ {"kind":"O","text":" crypto-utils | 100 | 100 | 100 | 100 | \n"}
57
+ {"kind":"O","text":" browserCryptoProvider.ts | 100 | 100 | 100 | 100 | \n"}
58
+ {"kind":"O","text":" browserHashProvider.ts | 100 | 100 | 100 | 100 | \n"}
59
+ {"kind":"O","text":" file-tree | 100 | 94.9 | 100 | 100 | \n"}
60
+ {"kind":"O","text":" directoryHandleStore.ts | 100 | 100 | 100 | 100 | \n"}
61
+ {"kind":"O","text":" fileApiTreeAccessors.ts | 100 | 100 | 100 | 100 | \n"}
62
+ {"kind":"O","text":" fileSystemAccessTreeAccessors.ts | 100 | 93.06 | 100 | 100 | 90,152,160,169,176 \n"}
63
+ {"kind":"O","text":" localStorageTreeAccessors.ts | 100 | 88.6 | 100 | 100 | 92,107,163-164,196-197,210,245-249 \n"}
64
+ {"kind":"O","text":" helpers | 100 | 100 | 100 | 100 | \n"}
65
+ {"kind":"O","text":" fileTreeHelpers.ts | 100 | 100 | 100 | 100 | \n"}
66
+ {"kind":"O","text":" url-utils | 100 | 100 | 100 | 100 | \n"}
67
+ {"kind":"O","text":" urlParams.ts | 100 | 100 | 100 | 100 | \n"}
68
+ {"kind":"O","text":"-----------------------------------|---------|----------|---------|---------|------------------------------------\n"}
69
+ {"kind":"O","text":" ---- test finished (1.675s) ---- \n"}
70
+ {"kind":"O","text":"-------------------- Finished (4.577s) --------------------\n"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "nonCachedDurationMs": 4849.926584000001
3
+ }
@@ -31,6 +31,7 @@ import { succeed, fail } from '@fgv/ts-utils';
31
31
  import { FileTree } from '@fgv/ts-json-base';
32
32
  import { isFileHandle, isDirectoryHandle } from '../file-api-types';
33
33
  import { FileSystemAccessTreeAccessors } from './fileSystemAccessTreeAccessors';
34
+ import { HttpTreeAccessors } from './httpTreeAccessors';
34
35
  import { LocalStorageTreeAccessors } from './localStorageTreeAccessors';
35
36
  /**
36
37
  * Helper function to safely get webkitRelativePath from a File object.
@@ -67,6 +68,20 @@ export class FileApiTreeAccessors {
67
68
  }
68
69
  return FileTree.FileTree.create(accessorsResult.value);
69
70
  }
71
+ /**
72
+ * Create a persistent FileTree from an HTTP storage service.
73
+ *
74
+ * @param params - Configuration including API base URL, namespace, and optional autoSync
75
+ * @returns Promise resolving to a FileTree with persistence capability
76
+ * @public
77
+ */
78
+ static async createFromHttp(params) {
79
+ const accessorsResult = await HttpTreeAccessors.fromHttp(params);
80
+ if (accessorsResult.isFailure()) {
81
+ return fail(accessorsResult.message);
82
+ }
83
+ return FileTree.FileTree.create(accessorsResult.value);
84
+ }
70
85
  /**
71
86
  * Create a persistent FileTree from a single File System Access API file handle.
72
87
  * The tree contains exactly one file at `/<filename>`.
@@ -1 +1 @@
1
- {"version":3,"file":"fileApiTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileApiTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;AAEH,0EAA0E;AAC1E,OAAO,EAAU,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,6BAA6B,EAA+B,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,yBAAyB,EAA2B,MAAM,6BAA6B,CAAC;AAWjG;;;GAGG;AACH,SAAS,mBAAmB,CAAC,IAAU;IACrC,OAAQ,IAAuC,CAAC,kBAAkB,IAAI,IAAI,CAAC,IAAI,CAAC;AAClF,CAAC;AAkDD;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAClC,SAAoC,EACpC,MAAyC;QAEzC,MAAM,eAAe,GAAG,MAAM,6BAA6B,CAAC,mBAAmB,CAAM,SAAS,EAAE,MAAM,CAAC,CAAC;QACxG,IAAI,eAAe,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CAAC,+BAA+B,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,MAAc,EAAE,IAAY;QACxD,wEAAwE;QACxE,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,oFAAoF;QACpF,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpE,kEAAkE;QAClE,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;IACpE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// File System Access API types are imported via the file-api-types module\nimport { Result, succeed, fail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport {\n isFileHandle,\n isDirectoryHandle,\n FileSystemFileHandle,\n FileSystemDirectoryHandle\n} from '../file-api-types';\nimport { FileSystemAccessTreeAccessors, IFileSystemAccessTreeParams } from './fileSystemAccessTreeAccessors';\nimport { LocalStorageTreeAccessors, ILocalStorageTreeParams } from './localStorageTreeAccessors';\n\n/**\n * Interface for File objects that may have the webkitRelativePath property.\n * This property is added by browsers when using directory upload (webkitdirectory).\n * @internal\n */\ninterface IFileWithWebkitPath {\n readonly webkitRelativePath?: string;\n}\n\n/**\n * Helper function to safely get webkitRelativePath from a File object.\n * @internal\n */\nfunction getFileRelativePath(file: File): string {\n return (file as unknown as IFileWithWebkitPath).webkitRelativePath || file.name;\n}\n\n/**\n * Tree initializer for FileList objects (from File API).\n * @public\n */\nexport interface IFileListTreeInitializer {\n readonly fileList: FileList;\n}\n\n/**\n * Tree initializer for File System Access API file handles.\n * @public\n */\nexport interface IFileHandleTreeInitializer {\n readonly prefix?: string;\n readonly fileHandles: FileSystemFileHandle[];\n}\n\n/**\n * Tree initializer for File System Access API directory handles.\n * @public\n */\nexport interface IDirectoryHandleTreeInitializer {\n readonly prefix?: string;\n readonly dirHandles: FileSystemDirectoryHandle[];\n readonly nonRecursive?: boolean; // Default: false (recursive by default)\n}\n\n/**\n * Union type for all supported tree initializers.\n * @public\n */\nexport type TreeInitializer =\n | IFileListTreeInitializer\n | IFileHandleTreeInitializer\n | IDirectoryHandleTreeInitializer;\n\n/**\n * Interface for file metadata.\n * @public\n */\nexport interface IFileMetadata {\n path: string;\n name: string;\n size: number;\n type: string;\n lastModified: number;\n}\n\n/**\n * Helper class to create FileTree instances from various file sources.\n * Supports File API (FileList) and File System Access API handles.\n * @public\n */\nexport class FileApiTreeAccessors<TCT extends string = string> {\n /**\n * Create a persistent FileTree from a File System Access API directory handle.\n * Changes to files can be synced back to disk.\n *\n * @param dirHandle - FileSystemDirectoryHandle to load files from\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n *\n * @remarks\n * - Only works in browsers supporting File System Access API (Chrome, Edge, Opera)\n * - Requires 'readwrite' permission on the directory handle\n * - Falls back to read-only mode if permissions unavailable (unless requireWritePermission is true)\n *\n * @public\n */\n public static async createPersistent<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromDirectoryHandle<TCT>(dirHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from a single File System Access API file handle.\n * The tree contains exactly one file at `/<filename>`.\n * Changes can be synced back to the original file via `syncToDisk()`.\n *\n * @param fileHandle - FileSystemFileHandle to load\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createPersistentFromFile<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromFileHandle<TCT>(fileHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from browser localStorage.\n * Changes to files can be synced back to localStorage.\n *\n * @param params - Configuration including path-to-key mappings and optional autoSync\n * @returns Result containing a FileTree with persistence capability\n *\n * @remarks\n * - Works in all browsers with localStorage support\n * - Maps directory paths to localStorage keys\n * - Each key stores multiple collections as JSON\n * - Files are automatically discovered from storage\n *\n * @example\n * ```typescript\n * const tree = FileApiTreeAccessors.createFromLocalStorage({\n * pathToKeyMap: {\n * '/data/ingredients': 'myapp:ingredients:v1',\n * '/data/fillings': 'myapp:fillings:v1'\n * },\n * mutable: true,\n * autoSync: false\n * });\n * ```\n *\n * @public\n */\n public static createFromLocalStorage<TCT extends string = string>(\n params: ILocalStorageTreeParams<TCT>\n ): Result<FileTree.FileTree<TCT>> {\n const accessorsResult = LocalStorageTreeAccessors.fromStorage<TCT>(params);\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create FileTree from various file sources using TreeInitializer array.\n * @param initializers - Array of TreeInitializer objects specifying file sources\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async create<TCT extends string = string>(\n initializers: TreeInitializer[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n try {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const initializer of initializers) {\n const filesResult = await this._processInitializer<TCT>(initializer, params);\n if (filesResult.isFailure()) {\n return fail(filesResult.message);\n }\n allFiles.push(...filesResult.value);\n }\n\n return FileTree.inMemory<TCT>(allFiles, params);\n /* c8 ignore next 5 - defense in depth */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process initializers: ${message}`);\n }\n }\n\n /**\n * Create FileTree from FileList (e.g., from input[type=\"file\"]).\n * @param fileList - FileList from a file input element\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const path = this._normalizePath(params?.prefix || '', file.name);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${file.name}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Create FileTree from directory upload with webkitRelativePath.\n * @param fileList - FileList from a directory upload (input with webkitdirectory)\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromDirectoryUpload<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const relativePath = getFileRelativePath(file);\n const path = this._normalizePath(params?.prefix || '', relativePath);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Get the File object for a specific path from the original FileList.\n * This is useful for accessing the original File API object for operations\n * like getting file metadata, MIME type, etc.\n * @param fileList - The original FileList\n * @param targetPath - The path to find\n * @returns Result containing the File object if found\n */\n public static getOriginalFile(fileList: FileList, targetPath: string): Result<File> {\n for (const file of Array.from(fileList)) {\n const filePath = getFileRelativePath(file);\n if (filePath === targetPath) {\n return succeed(file);\n }\n }\n return fail(`File not found: ${targetPath}`);\n }\n\n /**\n * Extract file metadata from a File.\n * @param fileList - The File to extract metadata from\n * @returns The {@link IFileMetadata | file metadata}\n */\n public static extractFileMetadata(file: File): IFileMetadata {\n return {\n path: getFileRelativePath(file),\n name: file.name,\n size: file.size,\n type: file.type,\n lastModified: file.lastModified\n };\n }\n\n /**\n * Process a single TreeInitializer and return the resulting files.\n * @param initializer - The TreeInitializer to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processInitializer<TCT extends string = string>(\n initializer: TreeInitializer,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n if ('fileList' in initializer) {\n return this._processFileList<TCT>(initializer.fileList, params);\n } else if ('fileHandles' in initializer) {\n return this._processFileHandles<TCT>(initializer.fileHandles, params);\n } else if ('dirHandles' in initializer) {\n return this._processDirectoryHandles<TCT>(\n initializer.dirHandles,\n initializer.prefix ?? params?.prefix,\n !initializer.nonRecursive,\n params\n );\n } else {\n return fail('Unknown initializer type');\n }\n }\n\n /**\n * Process a FileList and return IInMemoryFile array.\n * @param fileList - The FileList to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const metadata = this.extractFileMetadata(file);\n const relativePath = metadata.path;\n const path = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemFileHandles and return IInMemoryFile array.\n * @internal\n */\n private static async _processFileHandles<TCT extends string = string>(\n handles: FileSystemFileHandle[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const handle of handles) {\n try {\n const file = await handle.getFile();\n const contents = await file.text();\n const metadata = this.extractFileMetadata(file);\n /* c8 ignore next 1 - defense in depth */\n const path = this._normalizePath(params?.prefix ?? '', handle.name);\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file handle ${handle.name}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemDirectoryHandles and return IInMemoryFile array.\n * @param handles - The FileSystemDirectoryHandle[] to process\n * @param prefix - The prefix to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandles<TCT extends string = string>(\n handles: FileSystemDirectoryHandle[],\n prefix?: string,\n recursive: boolean = true,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n prefix = prefix ?? params?.prefix;\n\n for (const handle of handles) {\n const dirPrefix = this._normalizePath(prefix ?? '', handle.name);\n const filesResult = await this._processDirectoryHandle<TCT>(handle, dirPrefix, recursive, params);\n if (filesResult.isFailure()) {\n return filesResult;\n }\n allFiles.push(...filesResult.value);\n }\n\n return succeed(allFiles);\n }\n\n /**\n * Process a single FileSystemDirectoryHandle recursively.\n * @param handle - The FileSystemDirectoryHandle to process\n * @param basePath - The base path to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandle<TCT extends string = string>(\n handle: FileSystemDirectoryHandle,\n basePath: string,\n recursive: boolean,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n try {\n for await (const entry of handle.values()) {\n if (isFileHandle(entry)) {\n const file = await entry.getFile();\n const contents = await file.text();\n const path = this._normalizePath(basePath, entry.name);\n const contentType = params?.inferContentType?.(path).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } else if (isDirectoryHandle(entry) && recursive) {\n const subDirPath = this._normalizePath(basePath, entry.name);\n const subdirResult = await this._processDirectoryHandle<TCT>(entry, subDirPath, recursive, params);\n if (subdirResult.isFailure()) {\n return subdirResult;\n }\n files.push(...subdirResult.value);\n }\n }\n\n return succeed(files);\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process directory ${handle.name}: ${message}`);\n }\n }\n\n private static _normalizePath(prefix: string, path: string): string {\n // Remove leading slash from prefix if it exists to avoid double slashes\n const cleanPrefix = prefix ? prefix.replace(/^\\/+/, '') : '';\n const combined = cleanPrefix ? `${cleanPrefix}/${path}` : path;\n // Normalize multiple slashes and ensure it starts with / for FileTree compatibility\n const normalized = combined.replace(/\\/+/g, '/').replace(/\\/$/, '');\n /* c8 ignore next 1 - tested but coverage intermittently missed */\n return normalized.startsWith('/') ? normalized : `/${normalized}`;\n }\n}\n"]}
1
+ {"version":3,"file":"fileApiTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileApiTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;AAEH,0EAA0E;AAC1E,OAAO,EAAU,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC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E,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,oFAAoF;QACpF,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpE,kEAAkE;QAClE,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;IACpE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// File System Access API types are imported via the file-api-types module\nimport { Result, succeed, fail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport {\n isFileHandle,\n isDirectoryHandle,\n FileSystemFileHandle,\n FileSystemDirectoryHandle\n} from '../file-api-types';\nimport { FileSystemAccessTreeAccessors, IFileSystemAccessTreeParams } from './fileSystemAccessTreeAccessors';\nimport { HttpTreeAccessors, IHttpTreeParams } from './httpTreeAccessors';\nimport { LocalStorageTreeAccessors, ILocalStorageTreeParams } from './localStorageTreeAccessors';\n\n/**\n * Interface for File objects that may have the webkitRelativePath property.\n * This property is added by browsers when using directory upload (webkitdirectory).\n * @internal\n */\ninterface IFileWithWebkitPath {\n readonly webkitRelativePath?: string;\n}\n\n/**\n * Helper function to safely get webkitRelativePath from a File object.\n * @internal\n */\nfunction getFileRelativePath(file: File): string {\n return (file as unknown as IFileWithWebkitPath).webkitRelativePath || file.name;\n}\n\n/**\n * Tree initializer for FileList objects (from File API).\n * @public\n */\nexport interface IFileListTreeInitializer {\n readonly fileList: FileList;\n}\n\n/**\n * Tree initializer for File System Access API file handles.\n * @public\n */\nexport interface IFileHandleTreeInitializer {\n readonly prefix?: string;\n readonly fileHandles: FileSystemFileHandle[];\n}\n\n/**\n * Tree initializer for File System Access API directory handles.\n * @public\n */\nexport interface IDirectoryHandleTreeInitializer {\n readonly prefix?: string;\n readonly dirHandles: FileSystemDirectoryHandle[];\n readonly nonRecursive?: boolean; // Default: false (recursive by default)\n}\n\n/**\n * Union type for all supported tree initializers.\n * @public\n */\nexport type TreeInitializer =\n | IFileListTreeInitializer\n | IFileHandleTreeInitializer\n | IDirectoryHandleTreeInitializer;\n\n/**\n * Interface for file metadata.\n * @public\n */\nexport interface IFileMetadata {\n path: string;\n name: string;\n size: number;\n type: string;\n lastModified: number;\n}\n\n/**\n * Helper class to create FileTree instances from various file sources.\n * Supports File API (FileList) and File System Access API handles.\n * @public\n */\nexport class FileApiTreeAccessors<TCT extends string = string> {\n /**\n * Create a persistent FileTree from a File System Access API directory handle.\n * Changes to files can be synced back to disk.\n *\n * @param dirHandle - FileSystemDirectoryHandle to load files from\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n *\n * @remarks\n * - Only works in browsers supporting File System Access API (Chrome, Edge, Opera)\n * - Requires 'readwrite' permission on the directory handle\n * - Falls back to read-only mode if permissions unavailable (unless requireWritePermission is true)\n *\n * @public\n */\n public static async createPersistent<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromDirectoryHandle<TCT>(dirHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from an HTTP storage service.\n *\n * @param params - Configuration including API base URL, namespace, and optional autoSync\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createFromHttp<TCT extends string = string>(\n params: IHttpTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await HttpTreeAccessors.fromHttp<TCT>(params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from a single File System Access API file handle.\n * The tree contains exactly one file at `/<filename>`.\n * Changes can be synced back to the original file via `syncToDisk()`.\n *\n * @param fileHandle - FileSystemFileHandle to load\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createPersistentFromFile<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromFileHandle<TCT>(fileHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from browser localStorage.\n * Changes to files can be synced back to localStorage.\n *\n * @param params - Configuration including path-to-key mappings and optional autoSync\n * @returns Result containing a FileTree with persistence capability\n *\n * @remarks\n * - Works in all browsers with localStorage support\n * - Maps directory paths to localStorage keys\n * - Each key stores multiple collections as JSON\n * - Files are automatically discovered from storage\n *\n * @example\n * ```typescript\n * const tree = FileApiTreeAccessors.createFromLocalStorage({\n * pathToKeyMap: {\n * '/data/ingredients': 'myapp:ingredients:v1',\n * '/data/fillings': 'myapp:fillings:v1'\n * },\n * mutable: true,\n * autoSync: false\n * });\n * ```\n *\n * @public\n */\n public static createFromLocalStorage<TCT extends string = string>(\n params: ILocalStorageTreeParams<TCT>\n ): Result<FileTree.FileTree<TCT>> {\n const accessorsResult = LocalStorageTreeAccessors.fromStorage<TCT>(params);\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create FileTree from various file sources using TreeInitializer array.\n * @param initializers - Array of TreeInitializer objects specifying file sources\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async create<TCT extends string = string>(\n initializers: TreeInitializer[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n try {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const initializer of initializers) {\n const filesResult = await this._processInitializer<TCT>(initializer, params);\n if (filesResult.isFailure()) {\n return fail(filesResult.message);\n }\n allFiles.push(...filesResult.value);\n }\n\n return FileTree.inMemory<TCT>(allFiles, params);\n /* c8 ignore next 5 - defense in depth */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process initializers: ${message}`);\n }\n }\n\n /**\n * Create FileTree from FileList (e.g., from input[type=\"file\"]).\n * @param fileList - FileList from a file input element\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const path = this._normalizePath(params?.prefix || '', file.name);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${file.name}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Create FileTree from directory upload with webkitRelativePath.\n * @param fileList - FileList from a directory upload (input with webkitdirectory)\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromDirectoryUpload<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const relativePath = getFileRelativePath(file);\n const path = this._normalizePath(params?.prefix || '', relativePath);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Get the File object for a specific path from the original FileList.\n * This is useful for accessing the original File API object for operations\n * like getting file metadata, MIME type, etc.\n * @param fileList - The original FileList\n * @param targetPath - The path to find\n * @returns Result containing the File object if found\n */\n public static getOriginalFile(fileList: FileList, targetPath: string): Result<File> {\n for (const file of Array.from(fileList)) {\n const filePath = getFileRelativePath(file);\n if (filePath === targetPath) {\n return succeed(file);\n }\n }\n return fail(`File not found: ${targetPath}`);\n }\n\n /**\n * Extract file metadata from a File.\n * @param fileList - The File to extract metadata from\n * @returns The {@link IFileMetadata | file metadata}\n */\n public static extractFileMetadata(file: File): IFileMetadata {\n return {\n path: getFileRelativePath(file),\n name: file.name,\n size: file.size,\n type: file.type,\n lastModified: file.lastModified\n };\n }\n\n /**\n * Process a single TreeInitializer and return the resulting files.\n * @param initializer - The TreeInitializer to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processInitializer<TCT extends string = string>(\n initializer: TreeInitializer,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n if ('fileList' in initializer) {\n return this._processFileList<TCT>(initializer.fileList, params);\n } else if ('fileHandles' in initializer) {\n return this._processFileHandles<TCT>(initializer.fileHandles, params);\n } else if ('dirHandles' in initializer) {\n return this._processDirectoryHandles<TCT>(\n initializer.dirHandles,\n initializer.prefix ?? params?.prefix,\n !initializer.nonRecursive,\n params\n );\n } else {\n return fail('Unknown initializer type');\n }\n }\n\n /**\n * Process a FileList and return IInMemoryFile array.\n * @param fileList - The FileList to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const metadata = this.extractFileMetadata(file);\n const relativePath = metadata.path;\n const path = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemFileHandles and return IInMemoryFile array.\n * @internal\n */\n private static async _processFileHandles<TCT extends string = string>(\n handles: FileSystemFileHandle[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const handle of handles) {\n try {\n const file = await handle.getFile();\n const contents = await file.text();\n const metadata = this.extractFileMetadata(file);\n /* c8 ignore next 1 - defense in depth */\n const path = this._normalizePath(params?.prefix ?? '', handle.name);\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file handle ${handle.name}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemDirectoryHandles and return IInMemoryFile array.\n * @param handles - The FileSystemDirectoryHandle[] to process\n * @param prefix - The prefix to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandles<TCT extends string = string>(\n handles: FileSystemDirectoryHandle[],\n prefix?: string,\n recursive: boolean = true,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n prefix = prefix ?? params?.prefix;\n\n for (const handle of handles) {\n const dirPrefix = this._normalizePath(prefix ?? '', handle.name);\n const filesResult = await this._processDirectoryHandle<TCT>(handle, dirPrefix, recursive, params);\n if (filesResult.isFailure()) {\n return filesResult;\n }\n allFiles.push(...filesResult.value);\n }\n\n return succeed(allFiles);\n }\n\n /**\n * Process a single FileSystemDirectoryHandle recursively.\n * @param handle - The FileSystemDirectoryHandle to process\n * @param basePath - The base path to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandle<TCT extends string = string>(\n handle: FileSystemDirectoryHandle,\n basePath: string,\n recursive: boolean,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n try {\n for await (const entry of handle.values()) {\n if (isFileHandle(entry)) {\n const file = await entry.getFile();\n const contents = await file.text();\n const path = this._normalizePath(basePath, entry.name);\n const contentType = params?.inferContentType?.(path).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } else if (isDirectoryHandle(entry) && recursive) {\n const subDirPath = this._normalizePath(basePath, entry.name);\n const subdirResult = await this._processDirectoryHandle<TCT>(entry, subDirPath, recursive, params);\n if (subdirResult.isFailure()) {\n return subdirResult;\n }\n files.push(...subdirResult.value);\n }\n }\n\n return succeed(files);\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process directory ${handle.name}: ${message}`);\n }\n }\n\n private static _normalizePath(prefix: string, path: string): string {\n // Remove leading slash from prefix if it exists to avoid double slashes\n const cleanPrefix = prefix ? prefix.replace(/^\\/+/, '') : '';\n const combined = cleanPrefix ? `${cleanPrefix}/${path}` : path;\n // Normalize multiple slashes and ensure it starts with / for FileTree compatibility\n const normalized = combined.replace(/\\/+/g, '/').replace(/\\/$/, '');\n /* c8 ignore next 1 - tested but coverage intermittently missed */\n return normalized.startsWith('/') ? normalized : `/${normalized}`;\n }\n}\n"]}
@@ -26,7 +26,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
26
26
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
27
27
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
28
28
  };
29
- import { succeed, fail, succeedWithDetail } from '@fgv/ts-utils';
29
+ import { succeed, fail, succeedWithDetail, Logging } from '@fgv/ts-utils';
30
30
  import { FileTree } from '@fgv/ts-json-base';
31
31
  /**
32
32
  * Implementation of `FileTree.IPersistentFileTreeAccessors` that uses the File System Access API
@@ -43,13 +43,27 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
43
43
  * @param hasWritePermission - Whether write permission was granted.
44
44
  */
45
45
  constructor(files, rootDir, handles, params, hasWritePermission) {
46
- var _a;
46
+ var _a, _b;
47
47
  super(files, params);
48
48
  this._rootDir = rootDir;
49
49
  this._handles = handles;
50
50
  this._dirtyFiles = new Set();
51
+ this._pendingDeletions = new Set();
52
+ /* c8 ignore next 3 - intermittent branch coverage: ?? fallback branches in constructor */
51
53
  this._autoSync = (_a = params === null || params === void 0 ? void 0 : params.autoSync) !== null && _a !== void 0 ? _a : false;
52
54
  this._hasWritePermission = hasWritePermission;
55
+ this._logger = (_b = params === null || params === void 0 ? void 0 : params.logger) !== null && _b !== void 0 ? _b : new Logging.LogReporter();
56
+ }
57
+ async _runAutoSyncTask(path, operation, action) {
58
+ try {
59
+ const result = await action();
60
+ if (result.isFailure()) {
61
+ this._logger.error(`Auto-${operation} failed for ${path}: ${result.message}`);
62
+ }
63
+ }
64
+ catch (err) {
65
+ this._logger.error(`Auto-${operation} threw for ${path}: ${String(err)}`);
66
+ }
53
67
  }
54
68
  /**
55
69
  * Creates a new FileSystemAccessTreeAccessors instance from a directory handle.
@@ -95,22 +109,27 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
95
109
  var _a, _b, _c;
96
110
  try {
97
111
  const hasWritePermission = await this._checkFileWritePermission(fileHandle);
112
+ /* c8 ignore next 1 - intermittent branch coverage: ?? true fallback */
98
113
  if (!hasWritePermission && ((_a = params === null || params === void 0 ? void 0 : params.requireWritePermission) !== null && _a !== void 0 ? _a : true)) {
99
114
  return fail('Write permission required but not granted');
100
115
  }
101
116
  const file = await fileHandle.getFile();
102
117
  const contents = await file.text();
103
118
  const path = (_b = params === null || params === void 0 ? void 0 : params.filePath) !== null && _b !== void 0 ? _b : `/${fileHandle.name}`;
119
+ /* c8 ignore next 3 - intermittent branch coverage: ternary for inferContentType */
104
120
  const contentType = (params === null || params === void 0 ? void 0 : params.inferContentType)
105
121
  ? params.inferContentType(path, file.type).orDefault()
106
122
  : undefined;
107
123
  const files = [{ path, contents, contentType }];
108
124
  const handles = new Map([[path, fileHandle]]);
109
125
  const dummyRoot = {};
110
- const effectiveParams = Object.assign(Object.assign({}, params), { mutable: hasWritePermission ? true : (_c = params === null || params === void 0 ? void 0 : params.mutable) !== null && _c !== void 0 ? _c : false });
126
+ const effectiveParams = Object.assign(Object.assign({}, params), {
127
+ /* c8 ignore next 1 - intermittent branch coverage: ?? false fallback */
128
+ mutable: hasWritePermission ? true : (_c = params === null || params === void 0 ? void 0 : params.mutable) !== null && _c !== void 0 ? _c : false });
111
129
  return succeed(new FileSystemAccessTreeAccessors(files, dummyRoot, handles, effectiveParams, hasWritePermission));
112
130
  }
113
131
  catch (error) {
132
+ /* c8 ignore next 1 - intermittent branch coverage: error instanceof Error false branch */
114
133
  const message = error instanceof Error ? error.message : String(error);
115
134
  return fail(`Failed to create FileSystemAccessTreeAccessors from file: ${message}`);
116
135
  }
@@ -228,6 +247,13 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
228
247
  return fail('Write permission not granted - cannot sync to disk');
229
248
  }
230
249
  const errors = [];
250
+ // Process pending deletions from disk
251
+ for (const path of this._pendingDeletions) {
252
+ const deleteResult = await this._deleteFileFromDisk(path);
253
+ if (deleteResult.isFailure()) {
254
+ errors.push(`delete ${path}: ${deleteResult.message}`);
255
+ }
256
+ }
231
257
  for (const path of this._dirtyFiles) {
232
258
  const syncResult = await this._syncFile(path);
233
259
  if (syncResult.isFailure()) {
@@ -237,6 +263,7 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
237
263
  if (errors.length > 0) {
238
264
  return fail(`Failed to sync ${errors.length} file(s):\n${errors.join('\n')}`);
239
265
  }
266
+ this._pendingDeletions.clear();
240
267
  this._dirtyFiles.clear();
241
268
  return succeed(undefined);
242
269
  }
@@ -244,13 +271,30 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
244
271
  * Implements `FileTree.IPersistentFileTreeAccessors.isDirty`
245
272
  */
246
273
  isDirty() {
247
- return this._dirtyFiles.size > 0;
274
+ return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;
248
275
  }
249
276
  /**
250
277
  * Implements `FileTree.IPersistentFileTreeAccessors.getDirtyPaths`
251
278
  */
252
279
  getDirtyPaths() {
253
- return Array.from(this._dirtyFiles);
280
+ return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];
281
+ }
282
+ /**
283
+ * Override deleteFile to track pending deletions for syncToDisk.
284
+ */
285
+ deleteFile(path) {
286
+ const result = super.deleteFile(path);
287
+ if (result.isSuccess()) {
288
+ this._dirtyFiles.delete(path);
289
+ this._handles.delete(path);
290
+ if (this._hasWritePermission) {
291
+ this._pendingDeletions.add(path);
292
+ if (this._autoSync) {
293
+ void this._runAutoSyncTask(path, 'delete', () => this._deleteFileFromDisk(path));
294
+ }
295
+ }
296
+ }
297
+ return result;
254
298
  }
255
299
  /**
256
300
  * Implements `FileTree.IMutableFileTreeAccessors.saveFileContents`
@@ -262,11 +306,8 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
262
306
  this._dirtyFiles.add(path);
263
307
  // Auto-sync if enabled
264
308
  if (this._autoSync) {
265
- // Fire and forget - errors logged but don't block
266
- this._syncFile(path).catch((err) => {
267
- /* c8 ignore next 1 - defensive: async auto-sync error logging */
268
- console.error(`Auto-sync failed for ${path}:`, err);
269
- });
309
+ // Fire and log-on-failure; don't block the save path.
310
+ void this._runAutoSyncTask(path, 'save', () => this._syncFile(path));
270
311
  }
271
312
  }
272
313
  return result;
@@ -309,6 +350,34 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
309
350
  return fail(`Failed to write file: ${message}`);
310
351
  }
311
352
  }
353
+ /**
354
+ * Delete a file from disk using the File System Access API.
355
+ * @param path - The path of the file to delete.
356
+ * @returns Promise resolving to success or failure.
357
+ * @internal
358
+ */
359
+ async _deleteFileFromDisk(path) {
360
+ try {
361
+ const absolutePath = this.resolveAbsolutePath(path);
362
+ const parts = absolutePath.split('/').filter((p) => p.length > 0);
363
+ const filename = parts.pop();
364
+ /* c8 ignore next 3 - defensive: invalid path */
365
+ if (!filename) {
366
+ return fail(`Invalid file path: ${path}`);
367
+ }
368
+ // Navigate to the parent directory
369
+ let currentDir = this._rootDir;
370
+ for (const part of parts) {
371
+ currentDir = await currentDir.getDirectoryHandle(part);
372
+ }
373
+ await currentDir.removeEntry(filename);
374
+ return succeed(undefined);
375
+ }
376
+ catch (error) {
377
+ const message = error instanceof Error ? error.message : String(error);
378
+ return fail(`Failed to delete file ${path}: ${message}`);
379
+ }
380
+ }
312
381
  /**
313
382
  * Create a new file and write its contents.
314
383
  * @param path - The path of the file to create.
@@ -1 +1 @@
1
- {"version":3,"file":"fileSystemAccessTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileSystemAccessTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;AAEH,OAAO,EAAU,OAAO,EAAE,IAAI,EAAiC,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAgC7C;;;;GAIG;AACH,MAAM,OAAO,6BACX,SAAQ,QAAQ,CAAC,qBAA0B;IAS3C;;;;;;;OAOG;IACH,YACE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,CAAC,CAAC;YAEpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC5B,qEAAqE;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO,IAAI,CAAC,yBAAyB,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, succeed, fail, captureResult, DetailedResult, succeedWithDetail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport { FileSystemDirectoryHandle, FileSystemFileHandle } from '../file-api-types';\n\n/**\n * Options for creating persistent file trees.\n * @public\n */\nexport interface IFileSystemAccessTreeParams<TCT extends string = string>\n extends FileTree.IFileTreeInitParams<TCT> {\n /**\n * Automatically sync changes to disk immediately after each save.\n * If false, changes are batched and written on explicit syncToDisk() call.\n * @defaultValue false\n */\n autoSync?: boolean;\n\n /**\n * Require write permission on the directory handle.\n * If true, fails if write permission cannot be obtained.\n * If false, falls back to read-only mode.\n * @defaultValue true\n */\n requireWritePermission?: boolean;\n\n /**\n * Override the path at which the file is stored in the tree (for fromFileHandle).\n * Must be an absolute path (e.g., '/data/confections/common.yaml').\n * If omitted, defaults to `/<filename>`.\n */\n filePath?: string;\n}\n\n/**\n * Implementation of `FileTree.IPersistentFileTreeAccessors` that uses the File System Access API\n * to provide persistent file editing in browsers.\n * @public\n */\nexport class FileSystemAccessTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _handles: Map<string, FileSystemFileHandle>;\n private readonly _rootDir: FileSystemDirectoryHandle;\n private readonly _dirtyFiles: Set<string>;\n private readonly _autoSync: boolean;\n private readonly _hasWritePermission: boolean;\n\n /**\n * Protected constructor for FileSystemAccessTreeAccessors.\n * @param files - An array of in-memory files to include in the tree.\n * @param rootDir - The root directory handle.\n * @param handles - Map of file paths to their handles.\n * @param params - Optional params for the tree.\n * @param hasWritePermission - Whether write permission was granted.\n */\n protected constructor(\n files: FileTree.IInMemoryFile<TCT>[],\n rootDir: FileSystemDirectoryHandle,\n handles: Map<string, FileSystemFileHandle>,\n params: IFileSystemAccessTreeParams<TCT> | undefined,\n hasWritePermission: boolean\n ) {\n super(files, params);\n this._rootDir = rootDir;\n this._handles = handles;\n this._dirtyFiles = new Set();\n this._autoSync = params?.autoSync ?? false;\n this._hasWritePermission = hasWritePermission;\n }\n\n /**\n * Creates a new FileSystemAccessTreeAccessors instance from a directory handle.\n * @param dirHandle - The FileSystemDirectoryHandle to load files from.\n * @param params - Optional parameters including autoSync and permission settings.\n * @returns Promise resolving to a FileSystemAccessTreeAccessors instance.\n * @public\n */\n public static async fromDirectoryHandle<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileSystemAccessTreeAccessors<TCT>>> {\n try {\n // Check write permission\n const hasWritePermission = await this._checkWritePermission(dirHandle);\n\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!hasWritePermission && (params?.requireWritePermission ?? true)) {\n return fail('Write permission required but not granted');\n }\n\n // Load all files from the directory (always use '/' as base, prefix is handled by parent)\n const { files, handles } = await this._loadDirectory<TCT>(dirHandle, '/', params);\n\n // Enable tree mutability when write permission is granted and caller didn't explicitly set mutable\n const effectiveParams: IFileSystemAccessTreeParams<TCT> = {\n ...params,\n mutable: params?.mutable ?? (hasWritePermission ? true : false)\n };\n\n return succeed(\n new FileSystemAccessTreeAccessors<TCT>(files, dirHandle, handles, effectiveParams, hasWritePermission)\n );\n /* c8 ignore next 4 - defensive: outer catch for unexpected errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create FileSystemAccessTreeAccessors: ${message}`);\n }\n }\n\n /**\n * Creates a new FileSystemAccessTreeAccessors instance from a single file handle.\n *\n * The resulting tree contains exactly one file at `/<filename>`.\n * `syncToDisk()` writes changes back to the original file via the File System Access API.\n * New file creation is not supported on this tree (no parent directory handle).\n *\n * @param fileHandle - The FileSystemFileHandle to load.\n * @param params - Optional parameters including autoSync and permission settings.\n * @returns Promise resolving to a FileSystemAccessTreeAccessors instance.\n * @public\n */\n public static async fromFileHandle<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileSystemAccessTreeAccessors<TCT>>> {\n try {\n const hasWritePermission = await this._checkFileWritePermission(fileHandle);\n\n if (!hasWritePermission && (params?.requireWritePermission ?? true)) {\n return fail('Write permission required but not granted');\n }\n\n const file = await fileHandle.getFile();\n const contents = await file.text();\n const path = params?.filePath ?? `/${fileHandle.name}`;\n const contentType = params?.inferContentType\n ? params.inferContentType(path, file.type).orDefault()\n : undefined;\n\n const files: FileTree.IInMemoryFile<TCT>[] = [{ path, contents, contentType }];\n const handles = new Map<string, FileSystemFileHandle>([[path, fileHandle]]);\n\n const dummyRoot = {} as FileSystemDirectoryHandle;\n const effectiveParams: IFileSystemAccessTreeParams<TCT> = {\n ...params,\n mutable: hasWritePermission ? true : params?.mutable ?? false\n };\n\n return succeed(\n new FileSystemAccessTreeAccessors<TCT>(files, dummyRoot, handles, effectiveParams, hasWritePermission)\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create FileSystemAccessTreeAccessors from file: ${message}`);\n }\n }\n\n /**\n * Check if the directory handle has write permission.\n * @param handle - The directory handle to check.\n * @returns Promise resolving to true if write permission is granted.\n * @internal\n */\n private static async _checkWritePermission(handle: FileSystemDirectoryHandle): Promise<boolean> {\n try {\n const permission = await handle.queryPermission({ mode: 'readwrite' });\n\n if (permission === 'granted') {\n return true;\n }\n\n if (permission === 'prompt') {\n const requested = await handle.requestPermission({ mode: 'readwrite' });\n return requested === 'granted';\n }\n\n return false;\n } catch (error) {\n // Permission API might not be available or might throw\n return false;\n }\n }\n\n /**\n * Check if the file handle has write permission.\n * @param handle - The file handle to check.\n * @returns Promise resolving to true if write permission is granted.\n * @internal\n */\n private static async _checkFileWritePermission(handle: FileSystemFileHandle): Promise<boolean> {\n try {\n const permission = await handle.queryPermission({ mode: 'readwrite' });\n\n if (permission === 'granted') {\n return true;\n }\n\n if (permission === 'prompt') {\n const requested = await handle.requestPermission({ mode: 'readwrite' });\n return requested === 'granted';\n }\n\n return false;\n } catch (error) {\n return false;\n }\n }\n\n /**\n * Load all files from a directory handle recursively.\n * @param dirHandle - The directory handle to load from.\n * @param basePath - The base path for files.\n * @param params - Optional parameters.\n * @returns Promise resolving to files and handles.\n * @internal\n */\n private static async _loadDirectory<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n basePath: string,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<{ files: FileTree.IInMemoryFile<TCT>[]; handles: Map<string, FileSystemFileHandle> }> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n const handles = new Map<string, FileSystemFileHandle>();\n\n for await (const [name, handle] of dirHandle.entries()) {\n if (handle.kind === 'file') {\n const fileHandle = handle as FileSystemFileHandle;\n const file = await fileHandle.getFile();\n const contents = await file.text();\n const path = this._joinPath(basePath, name);\n /* c8 ignore next 2 - coverage intermittently missed in full suite */\n const contentType = params?.inferContentType\n ? params.inferContentType(path, file.type).orDefault()\n : undefined;\n\n files.push({ path, contents, contentType });\n handles.set(path, fileHandle);\n } else if (handle.kind === 'directory') {\n const subDirHandle = handle as FileSystemDirectoryHandle;\n const subPath = this._joinPath(basePath, name);\n const subResult = await this._loadDirectory<TCT>(subDirHandle, subPath, params);\n files.push(...subResult.files);\n for (const [path, fileHandle] of subResult.handles) {\n handles.set(path, fileHandle);\n }\n }\n }\n\n return { files, handles };\n }\n\n /**\n * Join path segments.\n * @param base - The base path.\n * @param name - The name to append.\n * @returns The joined path.\n * @internal\n */\n private static _joinPath(base: string, name: string): string {\n const normalized = base.endsWith('/') ? base.slice(0, -1) : base;\n return `${normalized}/${name}`;\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.syncToDisk`\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (!this._hasWritePermission) {\n return fail('Write permission not granted - cannot sync to disk');\n }\n\n const errors: string[] = [];\n\n for (const path of this._dirtyFiles) {\n const syncResult = await this._syncFile(path);\n if (syncResult.isFailure()) {\n errors.push(`${path}: ${syncResult.message}`);\n }\n }\n\n if (errors.length > 0) {\n return fail(`Failed to sync ${errors.length} file(s):\\n${errors.join('\\n')}`);\n }\n\n this._dirtyFiles.clear();\n return succeed(undefined);\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.isDirty`\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0;\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.getDirtyPaths`\n */\n public getDirtyPaths(): string[] {\n return Array.from(this._dirtyFiles);\n }\n\n /**\n * Implements `FileTree.IMutableFileTreeAccessors.saveFileContents`\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n // Call parent to update in-memory state\n const result = super.saveFileContents(path, contents);\n\n if (result.isSuccess() && this._hasWritePermission) {\n this._dirtyFiles.add(path);\n\n // Auto-sync if enabled\n if (this._autoSync) {\n // Fire and forget - errors logged but don't block\n this._syncFile(path).catch((err) => {\n /* c8 ignore next 1 - defensive: async auto-sync error logging */\n console.error(`Auto-sync failed for ${path}:`, err);\n });\n }\n }\n\n return result;\n }\n\n /**\n * Implements `FileTree.IMutableFileTreeAccessors.fileIsMutable`\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const baseResult = super.fileIsMutable(path);\n\n if (baseResult.isSuccess() && baseResult.detail === 'transient' && this._hasWritePermission) {\n // Upgrade to 'persistent' if we have write permission\n return succeedWithDetail(true, 'persistent');\n }\n\n return baseResult;\n }\n\n /**\n * Sync a single file to disk.\n * @param path - The path of the file to sync.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _syncFile(path: string): Promise<Result<void>> {\n const handle = this._handles.get(path);\n if (!handle) {\n return this._createAndWriteFile(path);\n }\n\n const contents = this.getFileContents(path);\n if (contents.isFailure()) {\n return fail(contents.message);\n }\n\n try {\n const writable = await handle.createWritable();\n await writable.write(contents.value);\n await writable.close();\n return succeed(undefined);\n /* c8 ignore next 4 - coverage intermittently missed in full suite */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to write file: ${message}`);\n }\n }\n\n /**\n * Create a new file and write its contents.\n * @param path - The path of the file to create.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _createAndWriteFile(path: string): Promise<Result<void>> {\n try {\n // Parse path to get directory and filename\n const absolutePath = this.resolveAbsolutePath(path);\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n const filename = parts.pop();\n\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!filename) {\n return fail(`Invalid file path: ${path}`);\n }\n\n // Navigate/create directory structure\n let currentDir = this._rootDir;\n for (const part of parts) {\n currentDir = await currentDir.getDirectoryHandle(part, { create: true });\n }\n\n // Create file and write contents\n const fileHandle = await currentDir.getFileHandle(filename, { create: true });\n this._handles.set(path, fileHandle);\n\n return this._syncFile(path);\n /* c8 ignore next 4 - coverage intermittently missed in full suite */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create file ${path}: ${message}`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"fileSystemAccessTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileSystemAccessTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;AAEH,OAAO,EAEL,OAAO,EACP,IAAI,EAGJ,iBAAiB,EACjB,OAAO,EACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAmC7C;;;;GAIG;AACH,MAAM,OAAO,6BACX,SAAQ,QAAQ,CAAC,qBAA0B;IAW3C;;;;;;;OAOG;IACH,YACE,KAAoC,EACpC,OAAkC,EAClC,OAA0C,EAC1C,MAAoD,EACpD,kBAA2B;;QAE3B,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;QACnC,0FAA0F;QAC1F,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,mCAAI,KAAK,CAAC;QAC3C,IAAI,CAAC,mBAAmB,GAAG,kBA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EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO,IAAI,CAAC,yBAAyB,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n Result,\n succeed,\n fail,\n captureResult,\n DetailedResult,\n succeedWithDetail,\n Logging\n} from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport { FileSystemDirectoryHandle, FileSystemFileHandle } from '../file-api-types';\n\n/**\n * Options for creating persistent file trees.\n * @public\n */\nexport interface IFileSystemAccessTreeParams<TCT extends string = string>\n extends FileTree.IFileTreeInitParams<TCT> {\n /**\n * Automatically sync changes to disk immediately after each save.\n * If false, changes are batched and written on explicit syncToDisk() call.\n * @defaultValue false\n */\n autoSync?: boolean;\n\n /**\n * Require write permission on the directory handle.\n * If true, fails if write permission cannot be obtained.\n * If false, falls back to read-only mode.\n * @defaultValue true\n */\n requireWritePermission?: boolean;\n\n /**\n * Override the path at which the file is stored in the tree (for fromFileHandle).\n * Must be an absolute path (e.g., '/data/confections/common.yaml').\n * If omitted, defaults to `/<filename>`.\n */\n filePath?: string;\n\n /** Optional logger for auto-sync and persistence failures. */\n logger?: Logging.LogReporter<unknown>;\n}\n\n/**\n * Implementation of `FileTree.IPersistentFileTreeAccessors` that uses the File System Access API\n * to provide persistent file editing in browsers.\n * @public\n */\nexport class FileSystemAccessTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _handles: Map<string, FileSystemFileHandle>;\n private readonly _rootDir: FileSystemDirectoryHandle;\n private readonly _dirtyFiles: Set<string>;\n private readonly _pendingDeletions: Set<string>;\n private readonly _autoSync: boolean;\n private readonly _hasWritePermission: boolean;\n private readonly _logger: Logging.LogReporter<unknown>;\n\n /**\n * Protected constructor for FileSystemAccessTreeAccessors.\n * @param files - An array of in-memory files to include in the tree.\n * @param rootDir - The root directory handle.\n * @param handles - Map of file paths to their handles.\n * @param params - Optional params for the tree.\n * @param hasWritePermission - Whether write permission was granted.\n */\n protected constructor(\n files: FileTree.IInMemoryFile<TCT>[],\n rootDir: FileSystemDirectoryHandle,\n handles: Map<string, FileSystemFileHandle>,\n params: IFileSystemAccessTreeParams<TCT> | undefined,\n hasWritePermission: boolean\n ) {\n super(files, params);\n this._rootDir = rootDir;\n this._handles = handles;\n this._dirtyFiles = new Set();\n this._pendingDeletions = new Set();\n /* c8 ignore next 3 - intermittent branch coverage: ?? fallback branches in constructor */\n this._autoSync = params?.autoSync ?? false;\n this._hasWritePermission = hasWritePermission;\n this._logger = params?.logger ?? new Logging.LogReporter<unknown>();\n }\n\n private async _runAutoSyncTask(\n path: string,\n operation: 'save' | 'delete',\n action: () => Promise<Result<void>>\n ): Promise<void> {\n try {\n const result = await action();\n if (result.isFailure()) {\n this._logger.error(`Auto-${operation} failed for ${path}: ${result.message}`);\n }\n } catch (err) {\n this._logger.error(`Auto-${operation} threw for ${path}: ${String(err)}`);\n }\n }\n\n /**\n * Creates a new FileSystemAccessTreeAccessors instance from a directory handle.\n * @param dirHandle - The FileSystemDirectoryHandle to load files from.\n * @param params - Optional parameters including autoSync and permission settings.\n * @returns Promise resolving to a FileSystemAccessTreeAccessors instance.\n * @public\n */\n public static async fromDirectoryHandle<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileSystemAccessTreeAccessors<TCT>>> {\n try {\n // Check write permission\n const hasWritePermission = await this._checkWritePermission(dirHandle);\n\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!hasWritePermission && (params?.requireWritePermission ?? true)) {\n return fail('Write permission required but not granted');\n }\n\n // Load all files from the directory (always use '/' as base, prefix is handled by parent)\n const { files, handles } = await this._loadDirectory<TCT>(dirHandle, '/', params);\n\n // Enable tree mutability when write permission is granted and caller didn't explicitly set mutable\n const effectiveParams: IFileSystemAccessTreeParams<TCT> = {\n ...params,\n mutable: params?.mutable ?? (hasWritePermission ? true : false)\n };\n\n return succeed(\n new FileSystemAccessTreeAccessors<TCT>(files, dirHandle, handles, effectiveParams, hasWritePermission)\n );\n /* c8 ignore next 4 - defensive: outer catch for unexpected errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create FileSystemAccessTreeAccessors: ${message}`);\n }\n }\n\n /**\n * Creates a new FileSystemAccessTreeAccessors instance from a single file handle.\n *\n * The resulting tree contains exactly one file at `/<filename>`.\n * `syncToDisk()` writes changes back to the original file via the File System Access API.\n * New file creation is not supported on this tree (no parent directory handle).\n *\n * @param fileHandle - The FileSystemFileHandle to load.\n * @param params - Optional parameters including autoSync and permission settings.\n * @returns Promise resolving to a FileSystemAccessTreeAccessors instance.\n * @public\n */\n public static async fromFileHandle<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileSystemAccessTreeAccessors<TCT>>> {\n try {\n const hasWritePermission = await this._checkFileWritePermission(fileHandle);\n\n /* c8 ignore next 1 - intermittent branch coverage: ?? true fallback */\n if (!hasWritePermission && (params?.requireWritePermission ?? true)) {\n return fail('Write permission required but not granted');\n }\n\n const file = await fileHandle.getFile();\n const contents = await file.text();\n const path = params?.filePath ?? `/${fileHandle.name}`;\n /* c8 ignore next 3 - intermittent branch coverage: ternary for inferContentType */\n const contentType = params?.inferContentType\n ? params.inferContentType(path, file.type).orDefault()\n : undefined;\n\n const files: FileTree.IInMemoryFile<TCT>[] = [{ path, contents, contentType }];\n const handles = new Map<string, FileSystemFileHandle>([[path, fileHandle]]);\n\n const dummyRoot = {} as FileSystemDirectoryHandle;\n const effectiveParams: IFileSystemAccessTreeParams<TCT> = {\n ...params,\n /* c8 ignore next 1 - intermittent branch coverage: ?? false fallback */\n mutable: hasWritePermission ? true : params?.mutable ?? false\n };\n\n return succeed(\n new FileSystemAccessTreeAccessors<TCT>(files, dummyRoot, handles, effectiveParams, hasWritePermission)\n );\n } catch (error) {\n /* c8 ignore next 1 - intermittent branch coverage: error instanceof Error false branch */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create FileSystemAccessTreeAccessors from file: ${message}`);\n }\n }\n\n /**\n * Check if the directory handle has write permission.\n * @param handle - The directory handle to check.\n * @returns Promise resolving to true if write permission is granted.\n * @internal\n */\n private static async _checkWritePermission(handle: FileSystemDirectoryHandle): Promise<boolean> {\n try {\n const permission = await handle.queryPermission({ mode: 'readwrite' });\n\n if (permission === 'granted') {\n return true;\n }\n\n if (permission === 'prompt') {\n const requested = await handle.requestPermission({ mode: 'readwrite' });\n return requested === 'granted';\n }\n\n return false;\n } catch (error) {\n // Permission API might not be available or might throw\n return false;\n }\n }\n\n /**\n * Check if the file handle has write permission.\n * @param handle - The file handle to check.\n * @returns Promise resolving to true if write permission is granted.\n * @internal\n */\n private static async _checkFileWritePermission(handle: FileSystemFileHandle): Promise<boolean> {\n try {\n const permission = await handle.queryPermission({ mode: 'readwrite' });\n\n if (permission === 'granted') {\n return true;\n }\n\n if (permission === 'prompt') {\n const requested = await handle.requestPermission({ mode: 'readwrite' });\n return requested === 'granted';\n }\n\n return false;\n } catch (error) {\n return false;\n }\n }\n\n /**\n * Load all files from a directory handle recursively.\n * @param dirHandle - The directory handle to load from.\n * @param basePath - The base path for files.\n * @param params - Optional parameters.\n * @returns Promise resolving to files and handles.\n * @internal\n */\n private static async _loadDirectory<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n basePath: string,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<{ files: FileTree.IInMemoryFile<TCT>[]; handles: Map<string, FileSystemFileHandle> }> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n const handles = new Map<string, FileSystemFileHandle>();\n\n for await (const [name, handle] of dirHandle.entries()) {\n if (handle.kind === 'file') {\n const fileHandle = handle as FileSystemFileHandle;\n const file = await fileHandle.getFile();\n const contents = await file.text();\n const path = this._joinPath(basePath, name);\n /* c8 ignore next 2 - coverage intermittently missed in full suite */\n const contentType = params?.inferContentType\n ? params.inferContentType(path, file.type).orDefault()\n : undefined;\n\n files.push({ path, contents, contentType });\n handles.set(path, fileHandle);\n } else if (handle.kind === 'directory') {\n const subDirHandle = handle as FileSystemDirectoryHandle;\n const subPath = this._joinPath(basePath, name);\n const subResult = await this._loadDirectory<TCT>(subDirHandle, subPath, params);\n files.push(...subResult.files);\n for (const [path, fileHandle] of subResult.handles) {\n handles.set(path, fileHandle);\n }\n }\n }\n\n return { files, handles };\n }\n\n /**\n * Join path segments.\n * @param base - The base path.\n * @param name - The name to append.\n * @returns The joined path.\n * @internal\n */\n private static _joinPath(base: string, name: string): string {\n const normalized = base.endsWith('/') ? base.slice(0, -1) : base;\n return `${normalized}/${name}`;\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.syncToDisk`\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (!this._hasWritePermission) {\n return fail('Write permission not granted - cannot sync to disk');\n }\n\n const errors: string[] = [];\n\n // Process pending deletions from disk\n for (const path of this._pendingDeletions) {\n const deleteResult = await this._deleteFileFromDisk(path);\n if (deleteResult.isFailure()) {\n errors.push(`delete ${path}: ${deleteResult.message}`);\n }\n }\n\n for (const path of this._dirtyFiles) {\n const syncResult = await this._syncFile(path);\n if (syncResult.isFailure()) {\n errors.push(`${path}: ${syncResult.message}`);\n }\n }\n\n if (errors.length > 0) {\n return fail(`Failed to sync ${errors.length} file(s):\\n${errors.join('\\n')}`);\n }\n\n this._pendingDeletions.clear();\n this._dirtyFiles.clear();\n return succeed(undefined);\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.isDirty`\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.getDirtyPaths`\n */\n public getDirtyPaths(): string[] {\n return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];\n }\n\n /**\n * Override deleteFile to track pending deletions for syncToDisk.\n */\n public deleteFile(path: string): Result<boolean> {\n const result = super.deleteFile(path);\n if (result.isSuccess()) {\n this._dirtyFiles.delete(path);\n this._handles.delete(path);\n\n if (this._hasWritePermission) {\n this._pendingDeletions.add(path);\n\n if (this._autoSync) {\n void this._runAutoSyncTask(path, 'delete', () => this._deleteFileFromDisk(path));\n }\n }\n }\n return result;\n }\n\n /**\n * Implements `FileTree.IMutableFileTreeAccessors.saveFileContents`\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n // Call parent to update in-memory state\n const result = super.saveFileContents(path, contents);\n\n if (result.isSuccess() && this._hasWritePermission) {\n this._dirtyFiles.add(path);\n\n // Auto-sync if enabled\n if (this._autoSync) {\n // Fire and log-on-failure; don't block the save path.\n void this._runAutoSyncTask(path, 'save', () => this._syncFile(path));\n }\n }\n\n return result;\n }\n\n /**\n * Implements `FileTree.IMutableFileTreeAccessors.fileIsMutable`\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const baseResult = super.fileIsMutable(path);\n\n if (baseResult.isSuccess() && baseResult.detail === 'transient' && this._hasWritePermission) {\n // Upgrade to 'persistent' if we have write permission\n return succeedWithDetail(true, 'persistent');\n }\n\n return baseResult;\n }\n\n /**\n * Sync a single file to disk.\n * @param path - The path of the file to sync.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _syncFile(path: string): Promise<Result<void>> {\n const handle = this._handles.get(path);\n if (!handle) {\n return this._createAndWriteFile(path);\n }\n\n const contents = this.getFileContents(path);\n if (contents.isFailure()) {\n return fail(contents.message);\n }\n\n try {\n const writable = await handle.createWritable();\n await writable.write(contents.value);\n await writable.close();\n return succeed(undefined);\n /* c8 ignore next 4 - coverage intermittently missed in full suite */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to write file: ${message}`);\n }\n }\n\n /**\n * Delete a file from disk using the File System Access API.\n * @param path - The path of the file to delete.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _deleteFileFromDisk(path: string): Promise<Result<void>> {\n try {\n const absolutePath = this.resolveAbsolutePath(path);\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n const filename = parts.pop();\n\n /* c8 ignore next 3 - defensive: invalid path */\n if (!filename) {\n return fail(`Invalid file path: ${path}`);\n }\n\n // Navigate to the parent directory\n let currentDir = this._rootDir;\n for (const part of parts) {\n currentDir = await currentDir.getDirectoryHandle(part);\n }\n\n await currentDir.removeEntry(filename);\n return succeed(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to delete file ${path}: ${message}`);\n }\n }\n\n /**\n * Create a new file and write its contents.\n * @param path - The path of the file to create.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _createAndWriteFile(path: string): Promise<Result<void>> {\n try {\n // Parse path to get directory and filename\n const absolutePath = this.resolveAbsolutePath(path);\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n const filename = parts.pop();\n\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!filename) {\n return fail(`Invalid file path: ${path}`);\n }\n\n // Navigate/create directory structure\n let currentDir = this._rootDir;\n for (const part of parts) {\n currentDir = await currentDir.getDirectoryHandle(part, { create: true });\n }\n\n // Create file and write contents\n const fileHandle = await currentDir.getFileHandle(filename, { create: true });\n this._handles.set(path, fileHandle);\n\n return this._syncFile(path);\n /* c8 ignore next 4 - coverage intermittently missed in full suite */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create file ${path}: ${message}`);\n }\n }\n}\n"]}