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

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 (462) hide show
  1. package/.rush/temp/{81e0881271ff236956b2f52e8ca99da6574c6e1e.tar.log → 662cc3506cc3ef5cddbcdc44d137af1d16679cbe.tar.log} +17 -3
  2. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +37 -34
  3. package/.rush/temp/operation/build/all.log +37 -34
  4. package/.rush/temp/operation/build/log-chunks.jsonl +37 -34
  5. package/.rush/temp/operation/build/state.json +1 -1
  6. package/.rush/temp/shrinkwrap-deps.json +690 -633
  7. package/config/typedoc.json +2 -1
  8. package/dist/packlets/file-tree/fileApiTreeAccessors.js +15 -0
  9. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  10. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +79 -10
  11. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  12. package/dist/packlets/file-tree/httpTreeAccessors.js +366 -0
  13. package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  14. package/dist/packlets/file-tree/index.js +1 -0
  15. package/dist/packlets/file-tree/index.js.map +1 -1
  16. package/dist/packlets/file-tree/localStorageTreeAccessors.js +51 -0
  17. package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  18. package/dist/test/unit/fileApiTreeAccessors.test.js +51 -0
  19. package/dist/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  20. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +265 -160
  21. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -1
  22. package/dist/test/unit/httpTreeAccessors.test.js +1364 -0
  23. package/dist/test/unit/httpTreeAccessors.test.js.map +1 -0
  24. package/dist/test/unit/localStorageTreeAccessors.test.js +218 -1
  25. package/dist/test/unit/localStorageTreeAccessors.test.js.map +1 -1
  26. package/dist/ts-web-extras.d.ts +144 -0
  27. package/dist/tsdoc-metadata.json +1 -1
  28. package/docs/CryptoUtils/README.md +60 -0
  29. package/docs/CryptoUtils/classes/BrowserCryptoProvider.decrypt.md +27 -0
  30. package/docs/CryptoUtils/classes/BrowserCryptoProvider.deriveKey.md +26 -0
  31. package/docs/CryptoUtils/classes/BrowserCryptoProvider.encrypt.md +25 -0
  32. package/docs/CryptoUtils/classes/BrowserCryptoProvider.fromBase64.md +24 -0
  33. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateKey.md +17 -0
  34. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateRandomBytes.md +24 -0
  35. package/docs/CryptoUtils/classes/BrowserCryptoProvider.md +151 -0
  36. package/docs/CryptoUtils/classes/BrowserCryptoProvider.toBase64.md +24 -0
  37. package/docs/CryptoUtils/classes/BrowserHashProvider.hashParts.md +26 -0
  38. package/docs/CryptoUtils/classes/BrowserHashProvider.hashString.md +25 -0
  39. package/docs/CryptoUtils/classes/BrowserHashProvider.md +81 -0
  40. package/docs/CryptoUtils/functions/createBrowserCryptoProvider.md +12 -0
  41. package/docs/FileTreeHelpers/README.md +85 -0
  42. package/docs/FileTreeHelpers/functions/extractFileListMetadata.md +11 -0
  43. package/docs/FileTreeHelpers/functions/extractFileMetadata.md +11 -0
  44. package/docs/FileTreeHelpers/functions/fromDirectoryUpload.md +12 -0
  45. package/docs/FileTreeHelpers/functions/fromFileList.md +12 -0
  46. package/docs/FileTreeHelpers/functions/getOriginalFile.md +11 -0
  47. package/docs/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +9 -0
  48. package/docs/README.md +524 -0
  49. package/docs/classes/BrowserCryptoProvider.decrypt.md +27 -0
  50. package/docs/classes/BrowserCryptoProvider.deriveKey.md +26 -0
  51. package/docs/classes/BrowserCryptoProvider.encrypt.md +25 -0
  52. package/docs/classes/BrowserCryptoProvider.fromBase64.md +24 -0
  53. package/docs/classes/BrowserCryptoProvider.generateKey.md +17 -0
  54. package/docs/classes/BrowserCryptoProvider.generateRandomBytes.md +24 -0
  55. package/docs/classes/BrowserCryptoProvider.md +151 -0
  56. package/docs/classes/BrowserCryptoProvider.toBase64.md +24 -0
  57. package/docs/classes/BrowserHashProvider.hashParts.md +26 -0
  58. package/docs/classes/BrowserHashProvider.hashString.md +25 -0
  59. package/docs/classes/BrowserHashProvider.md +81 -0
  60. package/docs/classes/DirectoryHandleStore.getAll.md +17 -0
  61. package/docs/classes/DirectoryHandleStore.getAllLabels.md +17 -0
  62. package/docs/classes/DirectoryHandleStore.load.md +24 -0
  63. package/docs/classes/DirectoryHandleStore.md +120 -0
  64. package/docs/classes/DirectoryHandleStore.remove.md +24 -0
  65. package/docs/classes/DirectoryHandleStore.save.md +25 -0
  66. package/docs/classes/FileApiTreeAccessors.create.md +25 -0
  67. package/docs/classes/FileApiTreeAccessors.createFromHttp.md +24 -0
  68. package/docs/classes/FileApiTreeAccessors.createFromLocalStorage.md +25 -0
  69. package/docs/classes/FileApiTreeAccessors.createPersistent.md +26 -0
  70. package/docs/classes/FileApiTreeAccessors.createPersistentFromFile.md +27 -0
  71. package/docs/classes/FileApiTreeAccessors.extractFileMetadata.md +24 -0
  72. package/docs/classes/FileApiTreeAccessors.fromDirectoryUpload.md +25 -0
  73. package/docs/classes/FileApiTreeAccessors.fromFileList.md +25 -0
  74. package/docs/classes/FileApiTreeAccessors.getOriginalFile.md +27 -0
  75. package/docs/classes/FileApiTreeAccessors.md +172 -0
  76. package/docs/classes/FileSystemAccessTreeAccessors.deleteFile.md +22 -0
  77. package/docs/classes/FileSystemAccessTreeAccessors.fileIsMutable.md +22 -0
  78. package/docs/classes/FileSystemAccessTreeAccessors.fromDirectoryHandle.md +25 -0
  79. package/docs/classes/FileSystemAccessTreeAccessors.fromFileHandle.md +29 -0
  80. package/docs/classes/FileSystemAccessTreeAccessors.getDirtyPaths.md +15 -0
  81. package/docs/classes/FileSystemAccessTreeAccessors.isDirty.md +15 -0
  82. package/docs/classes/FileSystemAccessTreeAccessors.md +275 -0
  83. package/docs/classes/FileSystemAccessTreeAccessors.saveFileContents.md +23 -0
  84. package/docs/classes/FileSystemAccessTreeAccessors.syncToDisk.md +15 -0
  85. package/docs/classes/HttpTreeAccessors.deleteFile.md +22 -0
  86. package/docs/classes/HttpTreeAccessors.fileIsMutable.md +24 -0
  87. package/docs/classes/HttpTreeAccessors.fromHttp.md +24 -0
  88. package/docs/classes/HttpTreeAccessors.getDirtyPaths.md +17 -0
  89. package/docs/classes/HttpTreeAccessors.isDirty.md +17 -0
  90. package/docs/classes/HttpTreeAccessors.md +261 -0
  91. package/docs/classes/HttpTreeAccessors.saveFileContents.md +25 -0
  92. package/docs/classes/HttpTreeAccessors.syncToDisk.md +22 -0
  93. package/docs/classes/LocalStorageTreeAccessors.deleteFile.md +24 -0
  94. package/docs/classes/LocalStorageTreeAccessors.fileIsMutable.md +24 -0
  95. package/docs/classes/LocalStorageTreeAccessors.fromStorage.md +25 -0
  96. package/docs/classes/LocalStorageTreeAccessors.getDirtyPaths.md +17 -0
  97. package/docs/classes/LocalStorageTreeAccessors.isDirty.md +17 -0
  98. package/docs/classes/LocalStorageTreeAccessors.md +270 -0
  99. package/docs/classes/LocalStorageTreeAccessors.saveFileContents.md +25 -0
  100. package/docs/classes/LocalStorageTreeAccessors.syncToDisk.md +17 -0
  101. package/docs/functions/createBrowserCryptoProvider.md +12 -0
  102. package/docs/functions/exportAsJson.md +12 -0
  103. package/docs/functions/exportUsingFileSystemAPI.md +11 -0
  104. package/docs/functions/extractDirectoryPath.md +13 -0
  105. package/docs/functions/extractFileListMetadata.md +11 -0
  106. package/docs/functions/extractFileMetadata.md +11 -0
  107. package/docs/functions/fromDirectoryUpload.md +12 -0
  108. package/docs/functions/fromFileList.md +12 -0
  109. package/docs/functions/getOriginalFile.md +11 -0
  110. package/docs/functions/isDirectoryHandle.md +11 -0
  111. package/docs/functions/isFileHandle.md +11 -0
  112. package/docs/functions/isFilePath.md +11 -0
  113. package/docs/functions/parseContextFilter.md +12 -0
  114. package/docs/functions/parseQualifierDefaults.md +12 -0
  115. package/docs/functions/parseResourceTypes.md +12 -0
  116. package/docs/functions/parseUrlParameters.md +11 -0
  117. package/docs/functions/safeShowDirectoryPicker.md +11 -0
  118. package/docs/functions/safeShowOpenFilePicker.md +11 -0
  119. package/docs/functions/safeShowSaveFilePicker.md +11 -0
  120. package/docs/functions/supportsFileSystemAccess.md +11 -0
  121. package/docs/interfaces/FilePickerAcceptType.accept.md +9 -0
  122. package/docs/interfaces/FilePickerAcceptType.description.md +9 -0
  123. package/docs/interfaces/FilePickerAcceptType.md +61 -0
  124. package/docs/interfaces/FileSystemCreateWritableOptions.keepExistingData.md +9 -0
  125. package/docs/interfaces/FileSystemCreateWritableOptions.md +44 -0
  126. package/docs/interfaces/FileSystemDirectoryHandle._asyncIterator_.md +13 -0
  127. package/docs/interfaces/FileSystemDirectoryHandle.entries.md +13 -0
  128. package/docs/interfaces/FileSystemDirectoryHandle.getDirectoryHandle.md +21 -0
  129. package/docs/interfaces/FileSystemDirectoryHandle.getFileHandle.md +21 -0
  130. package/docs/interfaces/FileSystemDirectoryHandle.keys.md +13 -0
  131. package/docs/interfaces/FileSystemDirectoryHandle.kind.md +9 -0
  132. package/docs/interfaces/FileSystemDirectoryHandle.md +224 -0
  133. package/docs/interfaces/FileSystemDirectoryHandle.removeEntry.md +21 -0
  134. package/docs/interfaces/FileSystemDirectoryHandle.resolve.md +20 -0
  135. package/docs/interfaces/FileSystemDirectoryHandle.values.md +13 -0
  136. package/docs/interfaces/FileSystemFileHandle.createWritable.md +20 -0
  137. package/docs/interfaces/FileSystemFileHandle.getFile.md +13 -0
  138. package/docs/interfaces/FileSystemFileHandle.kind.md +9 -0
  139. package/docs/interfaces/FileSystemFileHandle.md +146 -0
  140. package/docs/interfaces/FileSystemGetDirectoryOptions.create.md +9 -0
  141. package/docs/interfaces/FileSystemGetDirectoryOptions.md +44 -0
  142. package/docs/interfaces/FileSystemGetFileOptions.create.md +9 -0
  143. package/docs/interfaces/FileSystemGetFileOptions.md +44 -0
  144. package/docs/interfaces/FileSystemHandle.isSameEntry.md +20 -0
  145. package/docs/interfaces/FileSystemHandle.kind.md +9 -0
  146. package/docs/interfaces/FileSystemHandle.md +118 -0
  147. package/docs/interfaces/FileSystemHandle.name.md +9 -0
  148. package/docs/interfaces/FileSystemHandle.queryPermission.md +20 -0
  149. package/docs/interfaces/FileSystemHandle.requestPermission.md +20 -0
  150. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +44 -0
  151. package/docs/interfaces/FileSystemHandlePermissionDescriptor.mode.md +9 -0
  152. package/docs/interfaces/FileSystemRemoveOptions.md +44 -0
  153. package/docs/interfaces/FileSystemRemoveOptions.recursive.md +9 -0
  154. package/docs/interfaces/FileSystemWritableFileStream.md +142 -0
  155. package/docs/interfaces/FileSystemWritableFileStream.seek.md +20 -0
  156. package/docs/interfaces/FileSystemWritableFileStream.truncate.md +20 -0
  157. package/docs/interfaces/FileSystemWritableFileStream.write.md +20 -0
  158. package/docs/interfaces/IDirectoryHandleTreeInitializer.dirHandles.md +9 -0
  159. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +78 -0
  160. package/docs/interfaces/IDirectoryHandleTreeInitializer.nonRecursive.md +9 -0
  161. package/docs/interfaces/IDirectoryHandleTreeInitializer.prefix.md +9 -0
  162. package/docs/interfaces/IFileHandleTreeInitializer.fileHandles.md +9 -0
  163. package/docs/interfaces/IFileHandleTreeInitializer.md +61 -0
  164. package/docs/interfaces/IFileHandleTreeInitializer.prefix.md +9 -0
  165. package/docs/interfaces/IFileListTreeInitializer.fileList.md +9 -0
  166. package/docs/interfaces/IFileListTreeInitializer.md +44 -0
  167. package/docs/interfaces/IFileMetadata.lastModified.md +9 -0
  168. package/docs/interfaces/IFileMetadata.md +112 -0
  169. package/docs/interfaces/IFileMetadata.name.md +9 -0
  170. package/docs/interfaces/IFileMetadata.path.md +9 -0
  171. package/docs/interfaces/IFileMetadata.size.md +9 -0
  172. package/docs/interfaces/IFileMetadata.type.md +9 -0
  173. package/docs/interfaces/IFileSystemAccessTreeParams.autoSync.md +12 -0
  174. package/docs/interfaces/IFileSystemAccessTreeParams.filePath.md +13 -0
  175. package/docs/interfaces/IFileSystemAccessTreeParams.logger.md +11 -0
  176. package/docs/interfaces/IFileSystemAccessTreeParams.md +148 -0
  177. package/docs/interfaces/IFileSystemAccessTreeParams.requireWritePermission.md +13 -0
  178. package/docs/interfaces/IFsAccessApis.md +62 -0
  179. package/docs/interfaces/IFsAccessApis.showDirectoryPicker.md +20 -0
  180. package/docs/interfaces/IFsAccessApis.showOpenFilePicker.md +20 -0
  181. package/docs/interfaces/IFsAccessApis.showSaveFilePicker.md +20 -0
  182. package/docs/interfaces/IHttpTreeParams.autoSync.md +9 -0
  183. package/docs/interfaces/IHttpTreeParams.baseUrl.md +9 -0
  184. package/docs/interfaces/IHttpTreeParams.fetchImpl.md +9 -0
  185. package/docs/interfaces/IHttpTreeParams.logger.md +9 -0
  186. package/docs/interfaces/IHttpTreeParams.md +182 -0
  187. package/docs/interfaces/IHttpTreeParams.namespace.md +9 -0
  188. package/docs/interfaces/IHttpTreeParams.userId.md +9 -0
  189. package/docs/interfaces/ILocalStorageTreeParams.autoSync.md +12 -0
  190. package/docs/interfaces/ILocalStorageTreeParams.md +131 -0
  191. package/docs/interfaces/ILocalStorageTreeParams.pathToKeyMap.md +13 -0
  192. package/docs/interfaces/ILocalStorageTreeParams.storage.md +12 -0
  193. package/docs/interfaces/IUrlConfigOptions.config.md +11 -0
  194. package/docs/interfaces/IUrlConfigOptions.configStartDir.md +11 -0
  195. package/docs/interfaces/IUrlConfigOptions.contextFilter.md +11 -0
  196. package/docs/interfaces/IUrlConfigOptions.input.md +11 -0
  197. package/docs/interfaces/IUrlConfigOptions.inputStartDir.md +11 -0
  198. package/docs/interfaces/IUrlConfigOptions.interactive.md +11 -0
  199. package/docs/interfaces/IUrlConfigOptions.loadZip.md +11 -0
  200. package/docs/interfaces/IUrlConfigOptions.maxDistance.md +11 -0
  201. package/docs/interfaces/IUrlConfigOptions.md +248 -0
  202. package/docs/interfaces/IUrlConfigOptions.qualifierDefaults.md +11 -0
  203. package/docs/interfaces/IUrlConfigOptions.reduceQualifiers.md +11 -0
  204. package/docs/interfaces/IUrlConfigOptions.resourceTypes.md +11 -0
  205. package/docs/interfaces/IUrlConfigOptions.zipFile.md +11 -0
  206. package/docs/interfaces/IUrlConfigOptions.zipPath.md +11 -0
  207. package/docs/interfaces/ShowDirectoryPickerOptions.id.md +9 -0
  208. package/docs/interfaces/ShowDirectoryPickerOptions.md +78 -0
  209. package/docs/interfaces/ShowDirectoryPickerOptions.mode.md +9 -0
  210. package/docs/interfaces/ShowDirectoryPickerOptions.startIn.md +9 -0
  211. package/docs/interfaces/ShowOpenFilePickerOptions.excludeAcceptAllOption.md +9 -0
  212. package/docs/interfaces/ShowOpenFilePickerOptions.id.md +9 -0
  213. package/docs/interfaces/ShowOpenFilePickerOptions.md +112 -0
  214. package/docs/interfaces/ShowOpenFilePickerOptions.multiple.md +9 -0
  215. package/docs/interfaces/ShowOpenFilePickerOptions.startIn.md +9 -0
  216. package/docs/interfaces/ShowOpenFilePickerOptions.types.md +9 -0
  217. package/docs/interfaces/ShowSaveFilePickerOptions.excludeAcceptAllOption.md +9 -0
  218. package/docs/interfaces/ShowSaveFilePickerOptions.id.md +9 -0
  219. package/docs/interfaces/ShowSaveFilePickerOptions.md +112 -0
  220. package/docs/interfaces/ShowSaveFilePickerOptions.startIn.md +9 -0
  221. package/docs/interfaces/ShowSaveFilePickerOptions.suggestedName.md +9 -0
  222. package/docs/interfaces/ShowSaveFilePickerOptions.types.md +9 -0
  223. package/docs/type-aliases/TreeInitializer.md +11 -0
  224. package/docs/type-aliases/WellKnownDirectory.md +11 -0
  225. package/docs/type-aliases/WindowWithFsAccess.md +11 -0
  226. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +9 -0
  227. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +9 -0
  228. package/docs/variables/defaultFileApiTreeInitParams.md +9 -0
  229. package/etc/ts-web-extras.api.md +33 -0
  230. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +9 -0
  231. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
  232. package/lib/packlets/file-tree/fileApiTreeAccessors.js +15 -0
  233. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  234. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts +17 -1
  235. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -1
  236. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +78 -9
  237. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  238. package/lib/packlets/file-tree/httpTreeAccessors.d.ts +108 -0
  239. package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -0
  240. package/lib/packlets/file-tree/httpTreeAccessors.js +370 -0
  241. package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  242. package/lib/packlets/file-tree/index.d.ts +1 -0
  243. package/lib/packlets/file-tree/index.d.ts.map +1 -1
  244. package/lib/packlets/file-tree/index.js +1 -0
  245. package/lib/packlets/file-tree/index.js.map +1 -1
  246. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts +12 -0
  247. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts.map +1 -1
  248. package/lib/packlets/file-tree/localStorageTreeAccessors.js +51 -0
  249. package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  250. package/lib/test/unit/fileApiTreeAccessors.test.js +51 -0
  251. package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  252. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +265 -160
  253. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -1
  254. package/lib/test/unit/httpTreeAccessors.test.d.ts +2 -0
  255. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +1 -0
  256. package/lib/test/unit/httpTreeAccessors.test.js +1366 -0
  257. package/lib/test/unit/httpTreeAccessors.test.js.map +1 -0
  258. package/lib/test/unit/localStorageTreeAccessors.test.js +218 -1
  259. package/lib/test/unit/localStorageTreeAccessors.test.js.map +1 -1
  260. package/package.json +13 -12
  261. package/rush-logs/ts-web-extras.build.cache.log +1 -1
  262. package/rush-logs/ts-web-extras.build.log +37 -34
  263. package/src/packlets/file-tree/fileApiTreeAccessors.ts +18 -0
  264. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +100 -8
  265. package/src/packlets/file-tree/httpTreeAccessors.ts +478 -0
  266. package/src/packlets/file-tree/index.ts +1 -0
  267. package/src/packlets/file-tree/localStorageTreeAccessors.ts +53 -0
  268. package/src/test/unit/fileApiTreeAccessors.test.ts +69 -0
  269. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +341 -188
  270. package/src/test/unit/httpTreeAccessors.test.ts +1750 -0
  271. package/src/test/unit/localStorageTreeAccessors.test.ts +269 -1
  272. package/temp/build/typescript/ts_8nwakTlr.json +1 -1
  273. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +1 -1
  274. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +1 -1
  275. package/temp/coverage/crypto-utils/index.html +1 -1
  276. package/temp/coverage/file-tree/directoryHandleStore.ts.html +1 -1
  277. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +60 -6
  278. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +410 -134
  279. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +1519 -0
  280. package/temp/coverage/file-tree/index.html +35 -20
  281. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +318 -159
  282. package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
  283. package/temp/coverage/helpers/index.html +1 -1
  284. package/temp/coverage/index.html +11 -11
  285. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +1 -1
  286. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +1 -1
  287. package/temp/coverage/lcov-report/crypto-utils/index.html +1 -1
  288. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +1 -1
  289. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +60 -6
  290. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +410 -134
  291. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +1519 -0
  292. package/temp/coverage/lcov-report/file-tree/index.html +35 -20
  293. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +318 -159
  294. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
  295. package/temp/coverage/lcov-report/helpers/index.html +1 -1
  296. package/temp/coverage/lcov-report/index.html +11 -11
  297. package/temp/coverage/lcov-report/url-utils/index.html +1 -1
  298. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
  299. package/temp/coverage/lcov.info +2052 -1195
  300. package/temp/coverage/url-utils/index.html +1 -1
  301. package/temp/coverage/url-utils/urlParams.ts.html +1 -1
  302. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  303. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -1
  304. package/temp/ts-web-extras.api.json +1314 -355
  305. package/temp/ts-web-extras.api.md +33 -0
  306. package/docs/index.md +0 -34
  307. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider._constructor_.md +0 -50
  308. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.decrypt.md +0 -104
  309. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.derivekey.md +0 -88
  310. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.encrypt.md +0 -72
  311. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.frombase64.md +0 -56
  312. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generatekey.md +0 -19
  313. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generaterandombytes.md +0 -56
  314. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.md +0 -169
  315. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.tobase64.md +0 -56
  316. package/docs/ts-web-extras.cryptoutils.browserhashprovider.hashparts.md +0 -88
  317. package/docs/ts-web-extras.cryptoutils.browserhashprovider.hashstring.md +0 -72
  318. package/docs/ts-web-extras.cryptoutils.browserhashprovider.md +0 -66
  319. package/docs/ts-web-extras.cryptoutils.createbrowsercryptoprovider.md +0 -19
  320. package/docs/ts-web-extras.cryptoutils.md +0 -71
  321. package/docs/ts-web-extras.exportasjson.md +0 -70
  322. package/docs/ts-web-extras.exportusingfilesystemapi.md +0 -104
  323. package/docs/ts-web-extras.extractdirectorypath.md +0 -52
  324. package/docs/ts-web-extras.fileapitreeaccessors.create.md +0 -72
  325. package/docs/ts-web-extras.fileapitreeaccessors.createfromlocalstorage.md +0 -74
  326. package/docs/ts-web-extras.fileapitreeaccessors.createpersistent.md +0 -76
  327. package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +0 -54
  328. package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +0 -72
  329. package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +0 -72
  330. package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +0 -72
  331. package/docs/ts-web-extras.fileapitreeaccessors.md +0 -146
  332. package/docs/ts-web-extras.filepickeraccepttype.accept.md +0 -11
  333. package/docs/ts-web-extras.filepickeraccepttype.description.md +0 -11
  334. package/docs/ts-web-extras.filepickeraccepttype.md +0 -75
  335. package/docs/ts-web-extras.filesystemaccesstreeaccessors._constructor_.md +0 -114
  336. package/docs/ts-web-extras.filesystemaccesstreeaccessors.fileismutable.md +0 -52
  337. package/docs/ts-web-extras.filesystemaccesstreeaccessors.fromdirectoryhandle.md +0 -72
  338. package/docs/ts-web-extras.filesystemaccesstreeaccessors.getdirtypaths.md +0 -17
  339. package/docs/ts-web-extras.filesystemaccesstreeaccessors.isdirty.md +0 -17
  340. package/docs/ts-web-extras.filesystemaccesstreeaccessors.md +0 -159
  341. package/docs/ts-web-extras.filesystemaccesstreeaccessors.savefilecontents.md +0 -66
  342. package/docs/ts-web-extras.filesystemaccesstreeaccessors.synctodisk.md +0 -17
  343. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +0 -11
  344. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +0 -58
  345. package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +0 -15
  346. package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +0 -15
  347. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +0 -66
  348. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +0 -66
  349. package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +0 -15
  350. package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +0 -11
  351. package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +0 -146
  352. package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +0 -66
  353. package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +0 -50
  354. package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +0 -15
  355. package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +0 -52
  356. package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +0 -15
  357. package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +0 -11
  358. package/docs/ts-web-extras.filesystemfilehandle_2.md +0 -92
  359. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +0 -11
  360. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +0 -58
  361. package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +0 -11
  362. package/docs/ts-web-extras.filesystemgetfileoptions_2.md +0 -58
  363. package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +0 -50
  364. package/docs/ts-web-extras.filesystemhandle_2.kind.md +0 -11
  365. package/docs/ts-web-extras.filesystemhandle_2.md +0 -119
  366. package/docs/ts-web-extras.filesystemhandle_2.name.md +0 -11
  367. package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +0 -52
  368. package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +0 -52
  369. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +0 -58
  370. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +0 -11
  371. package/docs/ts-web-extras.filesystemremoveoptions_2.md +0 -58
  372. package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +0 -11
  373. package/docs/ts-web-extras.filesystemwritablefilestream_2.md +0 -57
  374. package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +0 -50
  375. package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +0 -50
  376. package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +0 -50
  377. package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +0 -13
  378. package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +0 -56
  379. package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +0 -56
  380. package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +0 -76
  381. package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +0 -76
  382. package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +0 -72
  383. package/docs/ts-web-extras.filetreehelpers.md +0 -102
  384. package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +0 -11
  385. package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +0 -100
  386. package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +0 -11
  387. package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +0 -11
  388. package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +0 -11
  389. package/docs/ts-web-extras.ifilehandletreeinitializer.md +0 -79
  390. package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +0 -11
  391. package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +0 -11
  392. package/docs/ts-web-extras.ifilelisttreeinitializer.md +0 -58
  393. package/docs/ts-web-extras.ifilemetadata.lastmodified.md +0 -11
  394. package/docs/ts-web-extras.ifilemetadata.md +0 -124
  395. package/docs/ts-web-extras.ifilemetadata.name.md +0 -11
  396. package/docs/ts-web-extras.ifilemetadata.path.md +0 -11
  397. package/docs/ts-web-extras.ifilemetadata.size.md +0 -11
  398. package/docs/ts-web-extras.ifilemetadata.type.md +0 -11
  399. package/docs/ts-web-extras.ifilesystemaccesstreeparams.autosync.md +0 -13
  400. package/docs/ts-web-extras.ifilesystemaccesstreeparams.md +0 -78
  401. package/docs/ts-web-extras.ifilesystemaccesstreeparams.requirewritepermission.md +0 -13
  402. package/docs/ts-web-extras.ifsaccessapis.md +0 -56
  403. package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +0 -52
  404. package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +0 -52
  405. package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +0 -52
  406. package/docs/ts-web-extras.ilocalstoragetreeparams.autosync.md +0 -13
  407. package/docs/ts-web-extras.ilocalstoragetreeparams.md +0 -97
  408. package/docs/ts-web-extras.ilocalstoragetreeparams.pathtokeymap.md +0 -13
  409. package/docs/ts-web-extras.ilocalstoragetreeparams.storage.md +0 -13
  410. package/docs/ts-web-extras.isdirectoryhandle.md +0 -56
  411. package/docs/ts-web-extras.isfilehandle.md +0 -56
  412. package/docs/ts-web-extras.isfilepath.md +0 -52
  413. package/docs/ts-web-extras.iurlconfigoptions.config.md +0 -13
  414. package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +0 -13
  415. package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +0 -13
  416. package/docs/ts-web-extras.iurlconfigoptions.input.md +0 -13
  417. package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +0 -13
  418. package/docs/ts-web-extras.iurlconfigoptions.interactive.md +0 -13
  419. package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +0 -13
  420. package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +0 -13
  421. package/docs/ts-web-extras.iurlconfigoptions.md +0 -286
  422. package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +0 -13
  423. package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +0 -13
  424. package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +0 -13
  425. package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +0 -13
  426. package/docs/ts-web-extras.iurlconfigoptions.zippath.md +0 -13
  427. package/docs/ts-web-extras.localstoragetreeaccessors.fileismutable.md +0 -56
  428. package/docs/ts-web-extras.localstoragetreeaccessors.fromstorage.md +0 -56
  429. package/docs/ts-web-extras.localstoragetreeaccessors.getdirtypaths.md +0 -19
  430. package/docs/ts-web-extras.localstoragetreeaccessors.isdirty.md +0 -19
  431. package/docs/ts-web-extras.localstoragetreeaccessors.md +0 -131
  432. package/docs/ts-web-extras.localstoragetreeaccessors.savefilecontents.md +0 -72
  433. package/docs/ts-web-extras.localstoragetreeaccessors.synctodisk.md +0 -19
  434. package/docs/ts-web-extras.md +0 -558
  435. package/docs/ts-web-extras.parsecontextfilter.md +0 -52
  436. package/docs/ts-web-extras.parsequalifierdefaults.md +0 -52
  437. package/docs/ts-web-extras.parseresourcetypes.md +0 -52
  438. package/docs/ts-web-extras.parseurlparameters.md +0 -17
  439. package/docs/ts-web-extras.safeshowdirectorypicker.md +0 -72
  440. package/docs/ts-web-extras.safeshowopenfilepicker.md +0 -72
  441. package/docs/ts-web-extras.safeshowsavefilepicker.md +0 -72
  442. package/docs/ts-web-extras.showdirectorypickeroptions.id.md +0 -11
  443. package/docs/ts-web-extras.showdirectorypickeroptions.md +0 -96
  444. package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +0 -11
  445. package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +0 -11
  446. package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +0 -11
  447. package/docs/ts-web-extras.showopenfilepickeroptions.id.md +0 -11
  448. package/docs/ts-web-extras.showopenfilepickeroptions.md +0 -134
  449. package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +0 -11
  450. package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +0 -11
  451. package/docs/ts-web-extras.showopenfilepickeroptions.types.md +0 -11
  452. package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +0 -11
  453. package/docs/ts-web-extras.showsavefilepickeroptions.id.md +0 -11
  454. package/docs/ts-web-extras.showsavefilepickeroptions.md +0 -134
  455. package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +0 -11
  456. package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +0 -11
  457. package/docs/ts-web-extras.showsavefilepickeroptions.types.md +0 -11
  458. package/docs/ts-web-extras.supportsfilesystemaccess.md +0 -56
  459. package/docs/ts-web-extras.treeinitializer.md +0 -15
  460. package/docs/ts-web-extras.wellknowndirectory.md +0 -13
  461. package/docs/ts-web-extras.windowwithfsaccess.md +0 -15
  462. /package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/{8d/package_8dcbedef69e4299f0f51fcda8f4f1c8e → 7c/package_7c16afc8299e635d80273763175c7a50} +0 -0
@@ -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,478 @@
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
+ /** Guards against concurrent syncToDisk calls (thundering herd from autoSync). */
83
+ private _syncPromise: Promise<Result<void>> | undefined;
84
+
85
+ private constructor(files: FileTree.IInMemoryFile<TCT>[], params: IHttpTreeParams<TCT>) {
86
+ super(files, params);
87
+ this._baseUrl = params.baseUrl.replace(/\/$/, '');
88
+ this._namespace = params.namespace;
89
+ this._fetchImpl = normalizeFetch(params.fetchImpl);
90
+ this._autoSync = params.autoSync ?? false;
91
+ this._userId = params.userId;
92
+ this._logger = params.logger ?? new Logging.LogReporter<unknown>();
93
+ }
94
+
95
+ private async _runAutoSyncTask(path: string): Promise<void> {
96
+ try {
97
+ const result = await this.syncToDisk();
98
+ if (result.isFailure()) {
99
+ this._logger.error(`Auto-sync failed for ${path}: ${result.message}`);
100
+ }
101
+ } catch (err) {
102
+ this._logger.error(`Auto-sync threw for ${path}: ${String(err)}`);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Creates a new HttpTreeAccessors instance from an HTTP backend.
108
+ * @param params - Configuration parameters for the HTTP tree accessors.
109
+ * @returns A promise that resolves to a result containing the new HttpTreeAccessors instance or an error message.
110
+ */
111
+ public static async fromHttp<TCT extends string = string>(
112
+ params: IHttpTreeParams<TCT>
113
+ ): Promise<Result<HttpTreeAccessors<TCT>>> {
114
+ const filesResult = await this._loadFiles<TCT>(params, '/');
115
+ if (filesResult.isFailure()) {
116
+ return fail(filesResult.message);
117
+ }
118
+ return succeed(new HttpTreeAccessors<TCT>(filesResult.value, params));
119
+ }
120
+
121
+ /**
122
+ * Synchronizes all dirty files to the HTTP backend.
123
+ *
124
+ * Uses a concurrency guard: if a sync is already in progress, callers
125
+ * await the existing operation rather than starting a parallel one.
126
+ * This prevents the thundering herd that occurs when autoSync fires
127
+ * for every file written during a bulk operation (e.g. restore).
128
+ *
129
+ * @returns A promise that resolves to a result indicating success or failure.
130
+ */
131
+ public async syncToDisk(): Promise<Result<void>> {
132
+ if (this._syncPromise) {
133
+ // Wait for the in-flight sync — it drains the queue in a loop,
134
+ // so any items added before it finishes will be included.
135
+ return this._syncPromise;
136
+ }
137
+
138
+ this._syncPromise = this._doSync().finally(() => {
139
+ this._syncPromise = undefined;
140
+ });
141
+ return this._syncPromise;
142
+ }
143
+
144
+ private async _doSync(): Promise<Result<void>> {
145
+ // Drain loop: keep processing as long as new items arrive.
146
+ // This is critical for bulk operations (e.g. reset) where many
147
+ // deleteFile/saveFileContents calls happen synchronously — only
148
+ // the first may be in the set when we snapshot, but the rest
149
+ // arrive during the async gaps and must be picked up before
150
+ // we return.
151
+ let didWork = false;
152
+ while (this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0) {
153
+ didWork = true;
154
+ // Snapshot and clear so that changes arriving during the async
155
+ // requests land in the live sets for the next iteration.
156
+ const deletions = new Set(this._pendingDeletions);
157
+ const dirty = new Set(this._dirtyFiles);
158
+ this._pendingDeletions.clear();
159
+ this._dirtyFiles.clear();
160
+
161
+ for (const path of deletions) {
162
+ const query = new URLSearchParams();
163
+ query.set('path', path);
164
+ if (this._namespace) {
165
+ query.set('namespace', this._namespace);
166
+ }
167
+
168
+ const deleteResult = await this._requestWithRetry<{ deleted: boolean }>(`/file?${query.toString()}`, {
169
+ method: 'DELETE'
170
+ });
171
+ if (deleteResult.isFailure()) {
172
+ this._restoreUnsynced(deletions, dirty);
173
+ return fail(`delete ${path}: ${deleteResult.message}`);
174
+ }
175
+ }
176
+
177
+ for (const path of dirty) {
178
+ const contentsResult = this.getFileContents(path);
179
+ if (contentsResult.isFailure()) {
180
+ this._restoreUnsynced(deletions, dirty);
181
+ return fail(`${path}: ${contentsResult.message}`);
182
+ }
183
+
184
+ const body: Record<string, unknown> = {
185
+ path,
186
+ contents: contentsResult.value
187
+ };
188
+ if (this._namespace) {
189
+ body.namespace = this._namespace;
190
+ }
191
+
192
+ const saveResult = await this._requestWithRetry<IHttpStorageFileResponse>('/file', {
193
+ method: 'PUT',
194
+ body: JSON.stringify(body)
195
+ });
196
+ if (saveResult.isFailure()) {
197
+ this._restoreUnsynced(deletions, dirty);
198
+ return fail(`sync ${path}: ${saveResult.message}`);
199
+ }
200
+ }
201
+ }
202
+
203
+ if (didWork) {
204
+ const syncBody: Record<string, unknown> = {};
205
+ if (this._namespace) {
206
+ syncBody.namespace = this._namespace;
207
+ }
208
+
209
+ const syncResult = await this._requestWithRetry<IHttpStorageSyncResponse>('/sync', {
210
+ method: 'POST',
211
+ body: JSON.stringify(syncBody)
212
+ });
213
+
214
+ if (syncResult.isFailure()) {
215
+ return fail(syncResult.message);
216
+ }
217
+ }
218
+ return succeed(undefined);
219
+ }
220
+
221
+ /**
222
+ * Restores snapshotted items back into the live dirty sets so they
223
+ * are retried on the next sync attempt. Items that were added to
224
+ * the live sets while the sync was in flight are preserved.
225
+ */
226
+ private _restoreUnsynced(deletions: Set<string>, dirty: Set<string>): void {
227
+ for (const path of deletions) {
228
+ this._pendingDeletions.add(path);
229
+ }
230
+ for (const path of dirty) {
231
+ this._dirtyFiles.add(path);
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Checks if there are any dirty files that need synchronization.
237
+ * @returns True if there are dirty files, false otherwise.
238
+ */
239
+ public isDirty(): boolean {
240
+ return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;
241
+ }
242
+
243
+ /**
244
+ * Gets the list of paths for all dirty files.
245
+ * @returns An array of file paths that have been modified but not yet synchronized.
246
+ */
247
+ public getDirtyPaths(): string[] {
248
+ return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];
249
+ }
250
+
251
+ public deleteFile(path: string): Result<boolean> {
252
+ const result = super.deleteFile(path);
253
+ if (result.isFailure()) {
254
+ return result;
255
+ }
256
+
257
+ this._dirtyFiles.delete(path);
258
+ this._pendingDeletions.add(path);
259
+
260
+ if (!this._autoSync) {
261
+ return result;
262
+ }
263
+
264
+ void this._runAutoSyncTask(path);
265
+ return result;
266
+ }
267
+
268
+ /**
269
+ * Saves file contents and marks the file as dirty for synchronization.
270
+ * @param path - The path to the file.
271
+ * @param contents - The new contents of the file.
272
+ * @returns A result indicating success or failure.
273
+ */
274
+ public saveFileContents(path: string, contents: string): Result<string> {
275
+ const result = super.saveFileContents(path, contents);
276
+ if (result.isFailure()) {
277
+ return result;
278
+ }
279
+
280
+ this._dirtyFiles.add(path);
281
+ if (!this._autoSync) {
282
+ return result;
283
+ }
284
+
285
+ // fire-and-log-on-failure automatic sync for immediate persistence workflow
286
+ void this._runAutoSyncTask(path);
287
+ return result;
288
+ }
289
+
290
+ /**
291
+ * Checks if a file is mutable (can be modified).
292
+ * @param path - The path to the file.
293
+ * @returns A detailed result indicating if the file is mutable and the reason.
294
+ */
295
+ public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {
296
+ const result = super.fileIsMutable(path);
297
+ if (result.isSuccess() && result.value === true) {
298
+ return succeedWithDetail(true, 'persistent');
299
+ }
300
+ return result;
301
+ }
302
+
303
+ /**
304
+ * Makes an HTTP request to the specified resource path.
305
+ * @param resourcePath - The path to the resource.
306
+ * @param init - Optional request initialization options.
307
+ * @returns A promise that resolves to a result containing the response data or an error message.
308
+ */
309
+ private async _request<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {
310
+ const response = await this._fetchImpl(`${this._baseUrl}${resourcePath}`, {
311
+ headers: {
312
+ 'Content-Type': 'application/json',
313
+ ...(this._userId ? { 'X-User-Id': this._userId } : {}),
314
+ /* c8 ignore next 1 - defensive coding: init.headers is never set by current callers */
315
+ ...(init?.headers ?? {})
316
+ },
317
+ ...init
318
+ }).catch((err: unknown) => ({ err } as const));
319
+
320
+ if ('err' in response) {
321
+ const message = response.err instanceof Error ? response.err.message : String(response.err);
322
+ return fail(message);
323
+ }
324
+
325
+ if (!response.ok) {
326
+ const body = await response.text().catch(() => '');
327
+ const message = body
328
+ ? `HTTP ${response.status}: ${body}`
329
+ : `HTTP ${response.status} ${response.statusText}`;
330
+ return fail(message);
331
+ }
332
+
333
+ const json = await response.json().catch(() => undefined);
334
+ if (json === undefined) {
335
+ return fail('invalid JSON response');
336
+ }
337
+ return succeed(json as T);
338
+ }
339
+
340
+ /**
341
+ * Wraps `_request` with retry logic for transient failures
342
+ * (network errors, 503 service unavailable, etc.).
343
+ */
344
+ private async _requestWithRetry<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {
345
+ const maxAttempts = 3;
346
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
347
+ const result = await this._request<T>(resourcePath, init);
348
+ if (result.isSuccess() || attempt === maxAttempts) {
349
+ return result;
350
+ }
351
+ // Retry on transient-looking errors
352
+ const msg = result.message;
353
+ const lowerMsg = msg.toLowerCase();
354
+ const isTransient =
355
+ msg.includes('503') ||
356
+ msg.includes('502') ||
357
+ msg.includes('429') ||
358
+ lowerMsg.includes('disconnect') ||
359
+ lowerMsg.includes('econnreset') ||
360
+ lowerMsg.includes('failed to fetch') ||
361
+ lowerMsg.includes('network');
362
+ if (!isTransient) {
363
+ return result;
364
+ }
365
+ // Exponential backoff: 500ms, 1000ms
366
+ const delayMs = 500 * Math.pow(2, attempt - 1);
367
+ this._logger.detail(
368
+ `Retrying ${
369
+ init?.method ?? 'GET'
370
+ } ${resourcePath} after ${delayMs}ms (attempt ${attempt}/${maxAttempts})`
371
+ );
372
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
373
+ }
374
+ /* c8 ignore next 1 - defensive coding: loop always returns */
375
+ return fail('retry loop exited unexpectedly');
376
+ }
377
+
378
+ /**
379
+ * Loads files from the HTTP backend for the specified directory path.
380
+ * @param params - Configuration parameters for the HTTP tree accessors.
381
+ * @param directoryPath - The path to the directory to load files from.
382
+ * @returns A promise that resolves to a result containing the loaded files or an error message.
383
+ */
384
+ private static async _loadFiles<TCT extends string = string>(
385
+ params: IHttpTreeParams<TCT>,
386
+ directoryPath: string
387
+ ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {
388
+ const childrenResult = await this._requestWithParams<IHttpStorageTreeChildrenResponse>(
389
+ params,
390
+ '/tree/children',
391
+ {
392
+ path: directoryPath,
393
+ namespace: params.namespace
394
+ }
395
+ );
396
+ if (childrenResult.isFailure()) {
397
+ return fail(childrenResult.message);
398
+ }
399
+
400
+ const allFiles: FileTree.IInMemoryFile<TCT>[] = [];
401
+
402
+ for (const item of childrenResult.value.children) {
403
+ if (item.type === 'directory') {
404
+ const nestedResult = await this._loadFiles(params, item.path);
405
+ if (nestedResult.isFailure()) {
406
+ return fail(nestedResult.message);
407
+ }
408
+ allFiles.push(...nestedResult.value);
409
+ } else {
410
+ const fileResult = await this._requestWithParams<IHttpStorageFileResponse>(params, '/file', {
411
+ path: item.path,
412
+ namespace: params.namespace
413
+ });
414
+ if (fileResult.isFailure()) {
415
+ return fail(fileResult.message);
416
+ }
417
+
418
+ const contentType = params.inferContentType?.(item.path, fileResult.value.contentType).orDefault();
419
+ allFiles.push({
420
+ path: item.path,
421
+ contents: fileResult.value.contents,
422
+ contentType
423
+ });
424
+ }
425
+ }
426
+
427
+ return succeed(allFiles);
428
+ }
429
+
430
+ /**
431
+ * Makes an HTTP request with query parameters to the specified resource path.
432
+ * @param params - Configuration parameters for the HTTP tree accessors.
433
+ * @param resourcePath - The path to the resource.
434
+ * @param query - Query parameters to include in the request.
435
+ * @returns A promise that resolves to a result containing the response data or an error message.
436
+ */
437
+ private static async _requestWithParams<T>(
438
+ params: IHttpTreeParams,
439
+ resourcePath: string,
440
+ query: Record<string, string | undefined>
441
+ ): Promise<Result<T>> {
442
+ const search = new URLSearchParams();
443
+ for (const [key, value] of Object.entries(query)) {
444
+ if (value !== undefined) {
445
+ search.set(key, value);
446
+ }
447
+ }
448
+
449
+ const fetchImpl = normalizeFetch(params.fetchImpl);
450
+ const userIdHeaders: RequestInit | undefined = /* c8 ignore next */ params.userId
451
+ ? { headers: { 'X-User-Id': params.userId } }
452
+ : undefined;
453
+ const response = await fetchImpl(
454
+ `${params.baseUrl.replace(/\/$/, '')}${resourcePath}?${search.toString()}`,
455
+ userIdHeaders
456
+ ).catch((err: unknown) => ({ err } as const));
457
+
458
+ if ('err' in response) {
459
+ const message = response.err instanceof Error ? response.err.message : String(response.err);
460
+ return fail(message);
461
+ }
462
+
463
+ if (!response.ok) {
464
+ const body = await response.text().catch(() => '');
465
+ const message = body
466
+ ? `HTTP ${response.status}: ${body}`
467
+ : `HTTP ${response.status} ${response.statusText}`;
468
+ return fail(message);
469
+ }
470
+
471
+ const json = await response.json().catch(() => undefined);
472
+ if (json === undefined) {
473
+ return fail('invalid JSON response');
474
+ }
475
+
476
+ return succeed(json as T);
477
+ }
478
+ }
@@ -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';