@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
@@ -30,6 +30,7 @@ import {
30
30
  FileSystemDirectoryHandle
31
31
  } from '../file-api-types';
32
32
  import { FileSystemAccessTreeAccessors, IFileSystemAccessTreeParams } from './fileSystemAccessTreeAccessors';
33
+ import { HttpTreeAccessors, IHttpTreeParams } from './httpTreeAccessors';
33
34
  import { LocalStorageTreeAccessors, ILocalStorageTreeParams } from './localStorageTreeAccessors';
34
35
 
35
36
  /**
@@ -130,6 +131,23 @@ export class FileApiTreeAccessors<TCT extends string = string> {
130
131
  return FileTree.FileTree.create<TCT>(accessorsResult.value);
131
132
  }
132
133
 
134
+ /**
135
+ * Create a persistent FileTree from an HTTP storage service.
136
+ *
137
+ * @param params - Configuration including API base URL, namespace, and optional autoSync
138
+ * @returns Promise resolving to a FileTree with persistence capability
139
+ * @public
140
+ */
141
+ public static async createFromHttp<TCT extends string = string>(
142
+ params: IHttpTreeParams<TCT>
143
+ ): Promise<Result<FileTree.FileTree<TCT>>> {
144
+ const accessorsResult = await HttpTreeAccessors.fromHttp<TCT>(params);
145
+ if (accessorsResult.isFailure()) {
146
+ return fail(accessorsResult.message);
147
+ }
148
+ return FileTree.FileTree.create<TCT>(accessorsResult.value);
149
+ }
150
+
133
151
  /**
134
152
  * Create a persistent FileTree from a single File System Access API file handle.
135
153
  * The tree contains exactly one file at `/<filename>`.
@@ -20,7 +20,15 @@
20
20
  * SOFTWARE.
21
21
  */
22
22
 
23
- import { Result, succeed, fail, captureResult, DetailedResult, succeedWithDetail } from '@fgv/ts-utils';
23
+ import {
24
+ Result,
25
+ succeed,
26
+ fail,
27
+ captureResult,
28
+ DetailedResult,
29
+ succeedWithDetail,
30
+ Logging
31
+ } from '@fgv/ts-utils';
24
32
  import { FileTree } from '@fgv/ts-json-base';
25
33
  import { FileSystemDirectoryHandle, FileSystemFileHandle } from '../file-api-types';
26
34
 
@@ -51,6 +59,9 @@ export interface IFileSystemAccessTreeParams<TCT extends string = string>
51
59
  * If omitted, defaults to `/<filename>`.
52
60
  */
53
61
  filePath?: string;
62
+
63
+ /** Optional logger for auto-sync and persistence failures. */
64
+ logger?: Logging.LogReporter<unknown>;
54
65
  }
55
66
 
56
67
  /**
@@ -65,8 +76,10 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
65
76
  private readonly _handles: Map<string, FileSystemFileHandle>;
66
77
  private readonly _rootDir: FileSystemDirectoryHandle;
67
78
  private readonly _dirtyFiles: Set<string>;
79
+ private readonly _pendingDeletions: Set<string>;
68
80
  private readonly _autoSync: boolean;
69
81
  private readonly _hasWritePermission: boolean;
82
+ private readonly _logger: Logging.LogReporter<unknown>;
70
83
 
71
84
  /**
72
85
  * Protected constructor for FileSystemAccessTreeAccessors.
@@ -87,8 +100,26 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
87
100
  this._rootDir = rootDir;
88
101
  this._handles = handles;
89
102
  this._dirtyFiles = new Set();
103
+ this._pendingDeletions = new Set();
104
+ /* c8 ignore next 3 - intermittent branch coverage: ?? fallback branches in constructor */
90
105
  this._autoSync = params?.autoSync ?? false;
91
106
  this._hasWritePermission = hasWritePermission;
107
+ this._logger = params?.logger ?? new Logging.LogReporter<unknown>();
108
+ }
109
+
110
+ private async _runAutoSyncTask(
111
+ path: string,
112
+ operation: 'save' | 'delete',
113
+ action: () => Promise<Result<void>>
114
+ ): Promise<void> {
115
+ try {
116
+ const result = await action();
117
+ if (result.isFailure()) {
118
+ this._logger.error(`Auto-${operation} failed for ${path}: ${result.message}`);
119
+ }
120
+ } catch (err) {
121
+ this._logger.error(`Auto-${operation} threw for ${path}: ${String(err)}`);
122
+ }
92
123
  }
93
124
 
94
125
  /**
@@ -149,6 +180,7 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
149
180
  try {
150
181
  const hasWritePermission = await this._checkFileWritePermission(fileHandle);
151
182
 
183
+ /* c8 ignore next 1 - intermittent branch coverage: ?? true fallback */
152
184
  if (!hasWritePermission && (params?.requireWritePermission ?? true)) {
153
185
  return fail('Write permission required but not granted');
154
186
  }
@@ -156,6 +188,7 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
156
188
  const file = await fileHandle.getFile();
157
189
  const contents = await file.text();
158
190
  const path = params?.filePath ?? `/${fileHandle.name}`;
191
+ /* c8 ignore next 3 - intermittent branch coverage: ternary for inferContentType */
159
192
  const contentType = params?.inferContentType
160
193
  ? params.inferContentType(path, file.type).orDefault()
161
194
  : undefined;
@@ -166,6 +199,7 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
166
199
  const dummyRoot = {} as FileSystemDirectoryHandle;
167
200
  const effectiveParams: IFileSystemAccessTreeParams<TCT> = {
168
201
  ...params,
202
+ /* c8 ignore next 1 - intermittent branch coverage: ?? false fallback */
169
203
  mutable: hasWritePermission ? true : params?.mutable ?? false
170
204
  };
171
205
 
@@ -173,6 +207,7 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
173
207
  new FileSystemAccessTreeAccessors<TCT>(files, dummyRoot, handles, effectiveParams, hasWritePermission)
174
208
  );
175
209
  } catch (error) {
210
+ /* c8 ignore next 1 - intermittent branch coverage: error instanceof Error false branch */
176
211
  const message = error instanceof Error ? error.message : String(error);
177
212
  return fail(`Failed to create FileSystemAccessTreeAccessors from file: ${message}`);
178
213
  }
@@ -294,6 +329,14 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
294
329
 
295
330
  const errors: string[] = [];
296
331
 
332
+ // Process pending deletions from disk
333
+ for (const path of this._pendingDeletions) {
334
+ const deleteResult = await this._deleteFileFromDisk(path);
335
+ if (deleteResult.isFailure()) {
336
+ errors.push(`delete ${path}: ${deleteResult.message}`);
337
+ }
338
+ }
339
+
297
340
  for (const path of this._dirtyFiles) {
298
341
  const syncResult = await this._syncFile(path);
299
342
  if (syncResult.isFailure()) {
@@ -305,6 +348,7 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
305
348
  return fail(`Failed to sync ${errors.length} file(s):\n${errors.join('\n')}`);
306
349
  }
307
350
 
351
+ this._pendingDeletions.clear();
308
352
  this._dirtyFiles.clear();
309
353
  return succeed(undefined);
310
354
  }
@@ -313,14 +357,34 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
313
357
  * Implements `FileTree.IPersistentFileTreeAccessors.isDirty`
314
358
  */
315
359
  public isDirty(): boolean {
316
- return this._dirtyFiles.size > 0;
360
+ return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;
317
361
  }
318
362
 
319
363
  /**
320
364
  * Implements `FileTree.IPersistentFileTreeAccessors.getDirtyPaths`
321
365
  */
322
366
  public getDirtyPaths(): string[] {
323
- return Array.from(this._dirtyFiles);
367
+ return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];
368
+ }
369
+
370
+ /**
371
+ * Override deleteFile to track pending deletions for syncToDisk.
372
+ */
373
+ public deleteFile(path: string): Result<boolean> {
374
+ const result = super.deleteFile(path);
375
+ if (result.isSuccess()) {
376
+ this._dirtyFiles.delete(path);
377
+ this._handles.delete(path);
378
+
379
+ if (this._hasWritePermission) {
380
+ this._pendingDeletions.add(path);
381
+
382
+ if (this._autoSync) {
383
+ void this._runAutoSyncTask(path, 'delete', () => this._deleteFileFromDisk(path));
384
+ }
385
+ }
386
+ }
387
+ return result;
324
388
  }
325
389
 
326
390
  /**
@@ -335,11 +399,8 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
335
399
 
336
400
  // Auto-sync if enabled
337
401
  if (this._autoSync) {
338
- // Fire and forget - errors logged but don't block
339
- this._syncFile(path).catch((err) => {
340
- /* c8 ignore next 1 - defensive: async auto-sync error logging */
341
- console.error(`Auto-sync failed for ${path}:`, err);
342
- });
402
+ // Fire and log-on-failure; don't block the save path.
403
+ void this._runAutoSyncTask(path, 'save', () => this._syncFile(path));
343
404
  }
344
405
  }
345
406
 
@@ -389,6 +450,37 @@ export class FileSystemAccessTreeAccessors<TCT extends string = string>
389
450
  }
390
451
  }
391
452
 
453
+ /**
454
+ * Delete a file from disk using the File System Access API.
455
+ * @param path - The path of the file to delete.
456
+ * @returns Promise resolving to success or failure.
457
+ * @internal
458
+ */
459
+ private async _deleteFileFromDisk(path: string): Promise<Result<void>> {
460
+ try {
461
+ const absolutePath = this.resolveAbsolutePath(path);
462
+ const parts = absolutePath.split('/').filter((p) => p.length > 0);
463
+ const filename = parts.pop();
464
+
465
+ /* c8 ignore next 3 - defensive: invalid path */
466
+ if (!filename) {
467
+ return fail(`Invalid file path: ${path}`);
468
+ }
469
+
470
+ // Navigate to the parent directory
471
+ let currentDir = this._rootDir;
472
+ for (const part of parts) {
473
+ currentDir = await currentDir.getDirectoryHandle(part);
474
+ }
475
+
476
+ await currentDir.removeEntry(filename);
477
+ return succeed(undefined);
478
+ } catch (error) {
479
+ const message = error instanceof Error ? error.message : String(error);
480
+ return fail(`Failed to delete file ${path}: ${message}`);
481
+ }
482
+ }
483
+
392
484
  /**
393
485
  * Create a new file and write its contents.
394
486
  * @param path - The path of the file to create.
@@ -0,0 +1,381 @@
1
+ /*
2
+ * Copyright (c) 2026 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import { DetailedResult, fail, type Result, succeed, succeedWithDetail, Logging } from '@fgv/ts-utils';
24
+ import { FileTree } from '@fgv/ts-json-base';
25
+
26
+ interface IHttpStorageTreeItem {
27
+ readonly path: string;
28
+ readonly name: string;
29
+ readonly type: 'file' | 'directory';
30
+ }
31
+
32
+ interface IHttpStorageTreeChildrenResponse {
33
+ readonly path: string;
34
+ readonly children: ReadonlyArray<IHttpStorageTreeItem>;
35
+ }
36
+
37
+ interface IHttpStorageFileResponse {
38
+ readonly path: string;
39
+ readonly contents: string;
40
+ readonly contentType?: string;
41
+ }
42
+
43
+ interface IHttpStorageSyncResponse {
44
+ readonly synced: number;
45
+ }
46
+
47
+ function normalizeFetch(fetchImpl?: typeof fetch): typeof fetch {
48
+ const resolved = fetchImpl ?? globalThis.fetch;
49
+ return resolved.bind(globalThis) as typeof fetch;
50
+ }
51
+
52
+ /**
53
+ * Configuration for creating HTTP-backed tree accessors.
54
+ * @public
55
+ */
56
+ export interface IHttpTreeParams<TCT extends string = string> extends FileTree.IFileTreeInitParams<TCT> {
57
+ readonly baseUrl: string;
58
+ readonly namespace?: string;
59
+ readonly autoSync?: boolean;
60
+ readonly fetchImpl?: typeof fetch;
61
+ readonly userId?: string;
62
+ readonly logger?: Logging.LogReporter<unknown>;
63
+ }
64
+
65
+ /**
66
+ * HTTP-backed file tree accessors that cache data in memory and persist via REST API.
67
+ * @public
68
+ */
69
+ export class HttpTreeAccessors<TCT extends string = string>
70
+ extends FileTree.InMemoryTreeAccessors<TCT>
71
+ implements FileTree.IPersistentFileTreeAccessors<TCT>
72
+ {
73
+ private readonly _baseUrl: string;
74
+ private readonly _namespace: string | undefined;
75
+ private readonly _fetchImpl: typeof fetch;
76
+ private readonly _dirtyFiles: Set<string> = new Set();
77
+ private readonly _pendingDeletions: Set<string> = new Set();
78
+ private readonly _autoSync: boolean;
79
+ private readonly _userId: string | undefined;
80
+ private readonly _logger: Logging.LogReporter<unknown>;
81
+
82
+ private constructor(files: FileTree.IInMemoryFile<TCT>[], params: IHttpTreeParams<TCT>) {
83
+ super(files, params);
84
+ this._baseUrl = params.baseUrl.replace(/\/$/, '');
85
+ this._namespace = params.namespace;
86
+ this._fetchImpl = normalizeFetch(params.fetchImpl);
87
+ this._autoSync = params.autoSync ?? false;
88
+ this._userId = params.userId;
89
+ this._logger = params.logger ?? new Logging.LogReporter<unknown>();
90
+ }
91
+
92
+ private async _runAutoSyncTask(path: string): Promise<void> {
93
+ try {
94
+ const result = await this.syncToDisk();
95
+ if (result.isFailure()) {
96
+ this._logger.error(`Auto-sync failed for ${path}: ${result.message}`);
97
+ }
98
+ } catch (err) {
99
+ this._logger.error(`Auto-sync threw for ${path}: ${String(err)}`);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Creates a new HttpTreeAccessors instance from an HTTP backend.
105
+ * @param params - Configuration parameters for the HTTP tree accessors.
106
+ * @returns A promise that resolves to a result containing the new HttpTreeAccessors instance or an error message.
107
+ */
108
+ public static async fromHttp<TCT extends string = string>(
109
+ params: IHttpTreeParams<TCT>
110
+ ): Promise<Result<HttpTreeAccessors<TCT>>> {
111
+ const filesResult = await this._loadFiles<TCT>(params, '/');
112
+ if (filesResult.isFailure()) {
113
+ return fail(filesResult.message);
114
+ }
115
+ return succeed(new HttpTreeAccessors<TCT>(filesResult.value, params));
116
+ }
117
+
118
+ /**
119
+ * Synchronizes all dirty files to the HTTP backend.
120
+ * @returns A promise that resolves to a result indicating success or failure.
121
+ */
122
+ public async syncToDisk(): Promise<Result<void>> {
123
+ if (this._dirtyFiles.size === 0 && this._pendingDeletions.size === 0) {
124
+ return succeed(undefined);
125
+ }
126
+
127
+ for (const path of this._pendingDeletions) {
128
+ const query = new URLSearchParams();
129
+ query.set('path', path);
130
+ if (this._namespace) {
131
+ query.set('namespace', this._namespace);
132
+ }
133
+
134
+ const deleteResult = await this._request<{ deleted: boolean }>(`/file?${query.toString()}`, {
135
+ method: 'DELETE'
136
+ });
137
+ if (deleteResult.isFailure()) {
138
+ return fail(`delete ${path}: ${deleteResult.message}`);
139
+ }
140
+ }
141
+
142
+ for (const path of this._dirtyFiles) {
143
+ const contentsResult = this.getFileContents(path);
144
+ if (contentsResult.isFailure()) {
145
+ return fail(`${path}: ${contentsResult.message}`);
146
+ }
147
+
148
+ const body: Record<string, unknown> = {
149
+ path,
150
+ contents: contentsResult.value
151
+ };
152
+ if (this._namespace) {
153
+ body.namespace = this._namespace;
154
+ }
155
+
156
+ const saveResult = await this._request<IHttpStorageFileResponse>('/file', {
157
+ method: 'PUT',
158
+ body: JSON.stringify(body)
159
+ });
160
+ if (saveResult.isFailure()) {
161
+ return fail(`sync ${path}: ${saveResult.message}`);
162
+ }
163
+ }
164
+
165
+ this._pendingDeletions.clear();
166
+ this._dirtyFiles.clear();
167
+
168
+ const syncBody: Record<string, unknown> = {};
169
+ if (this._namespace) {
170
+ syncBody.namespace = this._namespace;
171
+ }
172
+
173
+ const syncResult = await this._request<IHttpStorageSyncResponse>('/sync', {
174
+ method: 'POST',
175
+ body: JSON.stringify(syncBody)
176
+ });
177
+
178
+ return syncResult.isFailure() ? fail(syncResult.message) : succeed(undefined);
179
+ }
180
+
181
+ /**
182
+ * Checks if there are any dirty files that need synchronization.
183
+ * @returns True if there are dirty files, false otherwise.
184
+ */
185
+ public isDirty(): boolean {
186
+ return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;
187
+ }
188
+
189
+ /**
190
+ * Gets the list of paths for all dirty files.
191
+ * @returns An array of file paths that have been modified but not yet synchronized.
192
+ */
193
+ public getDirtyPaths(): string[] {
194
+ return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];
195
+ }
196
+
197
+ public deleteFile(path: string): Result<boolean> {
198
+ const result = super.deleteFile(path);
199
+ if (result.isFailure()) {
200
+ return result;
201
+ }
202
+
203
+ this._dirtyFiles.delete(path);
204
+ this._pendingDeletions.add(path);
205
+
206
+ if (!this._autoSync) {
207
+ return result;
208
+ }
209
+
210
+ void this._runAutoSyncTask(path);
211
+ return result;
212
+ }
213
+
214
+ /**
215
+ * Saves file contents and marks the file as dirty for synchronization.
216
+ * @param path - The path to the file.
217
+ * @param contents - The new contents of the file.
218
+ * @returns A result indicating success or failure.
219
+ */
220
+ public saveFileContents(path: string, contents: string): Result<string> {
221
+ const result = super.saveFileContents(path, contents);
222
+ if (result.isFailure()) {
223
+ return result;
224
+ }
225
+
226
+ this._dirtyFiles.add(path);
227
+ if (!this._autoSync) {
228
+ return result;
229
+ }
230
+
231
+ // fire-and-log-on-failure automatic sync for immediate persistence workflow
232
+ void this._runAutoSyncTask(path);
233
+ return result;
234
+ }
235
+
236
+ /**
237
+ * Checks if a file is mutable (can be modified).
238
+ * @param path - The path to the file.
239
+ * @returns A detailed result indicating if the file is mutable and the reason.
240
+ */
241
+ public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {
242
+ const result = super.fileIsMutable(path);
243
+ if (result.isSuccess() && result.value === true) {
244
+ return succeedWithDetail(true, 'persistent');
245
+ }
246
+ return result;
247
+ }
248
+
249
+ /**
250
+ * Makes an HTTP request to the specified resource path.
251
+ * @param resourcePath - The path to the resource.
252
+ * @param init - Optional request initialization options.
253
+ * @returns A promise that resolves to a result containing the response data or an error message.
254
+ */
255
+ private async _request<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {
256
+ const response = await this._fetchImpl(`${this._baseUrl}${resourcePath}`, {
257
+ headers: {
258
+ 'Content-Type': 'application/json',
259
+ ...(this._userId ? { 'X-User-Id': this._userId } : {}),
260
+ /* c8 ignore next 1 - defensive coding: init.headers is never set by current callers */
261
+ ...(init?.headers ?? {})
262
+ },
263
+ ...init
264
+ }).catch((err: unknown) => ({ err } as const));
265
+
266
+ if ('err' in response) {
267
+ const message = response.err instanceof Error ? response.err.message : String(response.err);
268
+ return fail(message);
269
+ }
270
+
271
+ if (!response.ok) {
272
+ const message = await response.text().catch(() => `HTTP ${response.status}`);
273
+ return fail(message);
274
+ }
275
+
276
+ const json = await response.json().catch(() => undefined);
277
+ if (json === undefined) {
278
+ return fail('invalid JSON response');
279
+ }
280
+ return succeed(json as T);
281
+ }
282
+
283
+ /**
284
+ * Loads files from the HTTP backend for the specified directory path.
285
+ * @param params - Configuration parameters for the HTTP tree accessors.
286
+ * @param directoryPath - The path to the directory to load files from.
287
+ * @returns A promise that resolves to a result containing the loaded files or an error message.
288
+ */
289
+ private static async _loadFiles<TCT extends string = string>(
290
+ params: IHttpTreeParams<TCT>,
291
+ directoryPath: string
292
+ ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {
293
+ const childrenResult = await this._requestWithParams<IHttpStorageTreeChildrenResponse>(
294
+ params,
295
+ '/tree/children',
296
+ {
297
+ path: directoryPath,
298
+ namespace: params.namespace
299
+ }
300
+ );
301
+ if (childrenResult.isFailure()) {
302
+ return fail(childrenResult.message);
303
+ }
304
+
305
+ const allFiles: FileTree.IInMemoryFile<TCT>[] = [];
306
+
307
+ for (const item of childrenResult.value.children) {
308
+ if (item.type === 'directory') {
309
+ const nestedResult = await this._loadFiles(params, item.path);
310
+ if (nestedResult.isFailure()) {
311
+ return fail(nestedResult.message);
312
+ }
313
+ allFiles.push(...nestedResult.value);
314
+ } else {
315
+ const fileResult = await this._requestWithParams<IHttpStorageFileResponse>(params, '/file', {
316
+ path: item.path,
317
+ namespace: params.namespace
318
+ });
319
+ if (fileResult.isFailure()) {
320
+ return fail(fileResult.message);
321
+ }
322
+
323
+ const contentType = params.inferContentType?.(item.path, fileResult.value.contentType).orDefault();
324
+ allFiles.push({
325
+ path: item.path,
326
+ contents: fileResult.value.contents,
327
+ contentType
328
+ });
329
+ }
330
+ }
331
+
332
+ return succeed(allFiles);
333
+ }
334
+
335
+ /**
336
+ * Makes an HTTP request with query parameters to the specified resource path.
337
+ * @param params - Configuration parameters for the HTTP tree accessors.
338
+ * @param resourcePath - The path to the resource.
339
+ * @param query - Query parameters to include in the request.
340
+ * @returns A promise that resolves to a result containing the response data or an error message.
341
+ */
342
+ private static async _requestWithParams<T>(
343
+ params: IHttpTreeParams,
344
+ resourcePath: string,
345
+ query: Record<string, string | undefined>
346
+ ): Promise<Result<T>> {
347
+ const search = new URLSearchParams();
348
+ for (const [key, value] of Object.entries(query)) {
349
+ if (value !== undefined) {
350
+ search.set(key, value);
351
+ }
352
+ }
353
+
354
+ const fetchImpl = normalizeFetch(params.fetchImpl);
355
+ /* c8 ignore next 3 - userId header in static _requestWithParams; covered by userId tests via fromHttp */
356
+ const userIdHeaders: RequestInit | undefined = params.userId
357
+ ? { headers: { 'X-User-Id': params.userId } }
358
+ : undefined;
359
+ const response = await fetchImpl(
360
+ `${params.baseUrl.replace(/\/$/, '')}${resourcePath}?${search.toString()}`,
361
+ userIdHeaders
362
+ ).catch((err: unknown) => ({ err } as const));
363
+
364
+ if ('err' in response) {
365
+ const message = response.err instanceof Error ? response.err.message : String(response.err);
366
+ return fail(message);
367
+ }
368
+
369
+ if (!response.ok) {
370
+ const message = await response.text().catch(() => `HTTP ${response.status}`);
371
+ return fail(message);
372
+ }
373
+
374
+ const json = await response.json().catch(() => undefined);
375
+ if (json === undefined) {
376
+ return fail('invalid JSON response');
377
+ }
378
+
379
+ return succeed(json as T);
380
+ }
381
+ }
@@ -28,4 +28,5 @@
28
28
  export * from './directoryHandleStore';
29
29
  export * from './fileApiTreeAccessors';
30
30
  export * from './fileSystemAccessTreeAccessors';
31
+ export * from './httpTreeAccessors';
31
32
  export * from './localStorageTreeAccessors';