@fgv/ts-web-extras 5.0.2 → 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 (383) hide show
  1. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +58 -25
  2. package/.rush/temp/chunked-rush-logs/ts-web-extras.test.chunks.jsonl +70 -0
  3. package/.rush/temp/operation/build/all.log +58 -25
  4. package/.rush/temp/operation/build/error.log +18 -0
  5. package/.rush/temp/operation/build/log-chunks.jsonl +58 -25
  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/.rush/temp/shrinkwrap-deps.json +175 -163
  12. package/config/jest.config.json +4 -1
  13. package/config/typedoc.json +6 -0
  14. package/dist/index.js +2 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/packlets/crypto-utils/browserCryptoProvider.js +254 -0
  17. package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -0
  18. package/dist/packlets/crypto-utils/browserHashProvider.js.map +1 -0
  19. package/dist/packlets/{crypto → crypto-utils}/index.js +1 -0
  20. package/dist/packlets/crypto-utils/index.js.map +1 -0
  21. package/dist/packlets/file-api-types/index.js +27 -3
  22. package/dist/packlets/file-api-types/index.js.map +1 -1
  23. package/dist/packlets/file-tree/directoryHandleStore.js +124 -0
  24. package/dist/packlets/file-tree/directoryHandleStore.js.map +1 -0
  25. package/dist/packlets/file-tree/fileApiTreeAccessors.js +91 -0
  26. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  27. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +414 -0
  28. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -0
  29. package/dist/packlets/file-tree/httpTreeAccessors.js +279 -0
  30. package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  31. package/dist/packlets/file-tree/index.js +4 -0
  32. package/dist/packlets/file-tree/index.js.map +1 -1
  33. package/dist/packlets/file-tree/localStorageTreeAccessors.js +359 -0
  34. package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -0
  35. package/dist/test/mocks/idb-keyval.js +6 -0
  36. package/dist/test/mocks/idb-keyval.js.map +1 -0
  37. package/dist/test/unit/browserHashProvider.test.js +1 -1
  38. package/dist/test/unit/browserHashProvider.test.js.map +1 -1
  39. package/dist/test/unit/directoryHandleStore.test.js +190 -0
  40. package/dist/test/unit/directoryHandleStore.test.js.map +1 -0
  41. package/dist/test/unit/fileApiTreeAccessors.test.js +51 -0
  42. package/dist/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  43. package/dist/test/unit/fileApiTypes.test.js +30 -0
  44. package/dist/test/unit/fileApiTypes.test.js.map +1 -1
  45. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +622 -0
  46. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -0
  47. package/dist/test/unit/httpTreeAccessors.test.js +1000 -0
  48. package/dist/test/unit/httpTreeAccessors.test.js.map +1 -0
  49. package/dist/test/unit/localStorageTreeAccessors.test.js +812 -0
  50. package/dist/test/unit/localStorageTreeAccessors.test.js.map +1 -0
  51. package/dist/test/utils/fileSystemAccessMocks.js +271 -0
  52. package/dist/test/utils/fileSystemAccessMocks.js.map +1 -0
  53. package/dist/ts-web-extras.d.ts +584 -1
  54. package/dist/tsdoc-metadata.json +1 -1
  55. package/docs/@fgv/namespaces/CryptoUtils/README.md +18 -0
  56. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserCryptoProvider.md +203 -0
  57. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserHashProvider.md +63 -0
  58. package/docs/@fgv/namespaces/CryptoUtils/functions/createBrowserCryptoProvider.md +18 -0
  59. package/docs/@fgv/namespaces/FileTreeHelpers/README.md +19 -0
  60. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileListMetadata.md +23 -0
  61. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileMetadata.md +23 -0
  62. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromDirectoryUpload.md +33 -0
  63. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromFileList.md +33 -0
  64. package/docs/@fgv/namespaces/FileTreeHelpers/functions/getOriginalFile.md +25 -0
  65. package/docs/@fgv/namespaces/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +11 -0
  66. package/docs/README.md +78 -0
  67. package/docs/classes/DirectoryHandleStore.md +116 -0
  68. package/docs/classes/FileApiTreeAccessors.md +286 -0
  69. package/docs/classes/FileSystemAccessTreeAccessors.md +557 -0
  70. package/docs/classes/HttpTreeAccessors.md +508 -0
  71. package/docs/classes/LocalStorageTreeAccessors.md +520 -0
  72. package/docs/functions/exportAsJson.md +23 -0
  73. package/docs/functions/exportUsingFileSystemAPI.md +26 -0
  74. package/docs/functions/extractDirectoryPath.md +23 -0
  75. package/docs/functions/isDirectoryHandle.md +23 -0
  76. package/docs/functions/isFileHandle.md +23 -0
  77. package/docs/functions/isFilePath.md +21 -0
  78. package/docs/functions/parseContextFilter.md +22 -0
  79. package/docs/functions/parseQualifierDefaults.md +22 -0
  80. package/docs/functions/parseResourceTypes.md +22 -0
  81. package/docs/functions/parseUrlParameters.md +15 -0
  82. package/docs/functions/safeShowDirectoryPicker.md +24 -0
  83. package/docs/functions/safeShowOpenFilePicker.md +24 -0
  84. package/docs/functions/safeShowSaveFilePicker.md +24 -0
  85. package/docs/functions/supportsFileSystemAccess.md +23 -0
  86. package/docs/interfaces/FilePickerAcceptType.md +16 -0
  87. package/docs/interfaces/FileSystemCreateWritableOptions.md +15 -0
  88. package/docs/interfaces/FileSystemDirectoryHandle.md +187 -0
  89. package/docs/interfaces/FileSystemFileHandle.md +106 -0
  90. package/docs/interfaces/FileSystemGetDirectoryOptions.md +15 -0
  91. package/docs/interfaces/FileSystemGetFileOptions.md +15 -0
  92. package/docs/interfaces/FileSystemHandle.md +69 -0
  93. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +15 -0
  94. package/docs/interfaces/FileSystemRemoveOptions.md +15 -0
  95. package/docs/interfaces/FileSystemWritableFileStream.md +127 -0
  96. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +17 -0
  97. package/docs/interfaces/IFileHandleTreeInitializer.md +16 -0
  98. package/docs/interfaces/IFileListTreeInitializer.md +15 -0
  99. package/docs/interfaces/IFileMetadata.md +19 -0
  100. package/docs/interfaces/IFileSystemAccessTreeParams.md +30 -0
  101. package/docs/interfaces/IFsAccessApis.md +57 -0
  102. package/docs/interfaces/IHttpTreeParams.md +32 -0
  103. package/docs/interfaces/ILocalStorageTreeParams.md +30 -0
  104. package/docs/interfaces/IUrlConfigOptions.md +27 -0
  105. package/docs/interfaces/ShowDirectoryPickerOptions.md +17 -0
  106. package/docs/interfaces/ShowOpenFilePickerOptions.md +19 -0
  107. package/docs/interfaces/ShowSaveFilePickerOptions.md +19 -0
  108. package/docs/type-aliases/TreeInitializer.md +11 -0
  109. package/docs/type-aliases/WellKnownDirectory.md +11 -0
  110. package/docs/type-aliases/WindowWithFsAccess.md +11 -0
  111. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +11 -0
  112. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +11 -0
  113. package/etc/ts-web-extras.api.md +124 -1
  114. package/lib/index.d.ts +2 -1
  115. package/lib/index.d.ts.map +1 -1
  116. package/lib/index.js +25 -2
  117. package/lib/index.js.map +1 -1
  118. package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +77 -0
  119. package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -0
  120. package/lib/packlets/crypto-utils/browserCryptoProvider.js +259 -0
  121. package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -0
  122. package/lib/packlets/crypto-utils/browserHashProvider.d.ts.map +1 -0
  123. package/lib/packlets/crypto-utils/browserHashProvider.js.map +1 -0
  124. package/lib/packlets/{crypto → crypto-utils}/index.d.ts +1 -0
  125. package/lib/packlets/crypto-utils/index.d.ts.map +1 -0
  126. package/lib/packlets/{crypto → crypto-utils}/index.js +1 -0
  127. package/lib/packlets/crypto-utils/index.js.map +1 -0
  128. package/lib/packlets/file-api-types/index.d.ts.map +1 -1
  129. package/lib/packlets/file-api-types/index.js +27 -3
  130. package/lib/packlets/file-api-types/index.js.map +1 -1
  131. package/lib/packlets/file-tree/directoryHandleStore.d.ts +59 -0
  132. package/lib/packlets/file-tree/directoryHandleStore.d.ts.map +1 -0
  133. package/lib/packlets/file-tree/directoryHandleStore.js +128 -0
  134. package/lib/packlets/file-tree/directoryHandleStore.js.map +1 -0
  135. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +66 -0
  136. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
  137. package/lib/packlets/file-tree/fileApiTreeAccessors.js +91 -0
  138. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  139. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts +152 -0
  140. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -0
  141. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +418 -0
  142. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -0
  143. package/lib/packlets/file-tree/httpTreeAccessors.d.ts +88 -0
  144. package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -0
  145. package/lib/packlets/file-tree/httpTreeAccessors.js +283 -0
  146. package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  147. package/lib/packlets/file-tree/index.d.ts +4 -0
  148. package/lib/packlets/file-tree/index.d.ts.map +1 -1
  149. package/lib/packlets/file-tree/index.js +4 -0
  150. package/lib/packlets/file-tree/index.js.map +1 -1
  151. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts +141 -0
  152. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts.map +1 -0
  153. package/lib/packlets/file-tree/localStorageTreeAccessors.js +363 -0
  154. package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -0
  155. package/lib/test/mocks/idb-keyval.d.ts +6 -0
  156. package/lib/test/mocks/idb-keyval.d.ts.map +1 -0
  157. package/lib/test/mocks/idb-keyval.js +9 -0
  158. package/lib/test/mocks/idb-keyval.js.map +1 -0
  159. package/lib/test/unit/browserHashProvider.test.js +21 -21
  160. package/lib/test/unit/browserHashProvider.test.js.map +1 -1
  161. package/lib/test/unit/directoryHandleStore.test.d.ts +2 -0
  162. package/lib/test/unit/directoryHandleStore.test.d.ts.map +1 -0
  163. package/lib/test/unit/directoryHandleStore.test.js +192 -0
  164. package/lib/test/unit/directoryHandleStore.test.js.map +1 -0
  165. package/lib/test/unit/fileApiTreeAccessors.test.js +51 -0
  166. package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  167. package/lib/test/unit/fileApiTypes.test.js +30 -0
  168. package/lib/test/unit/fileApiTypes.test.js.map +1 -1
  169. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +2 -0
  170. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +1 -0
  171. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +624 -0
  172. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -0
  173. package/lib/test/unit/httpTreeAccessors.test.d.ts +2 -0
  174. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +1 -0
  175. package/lib/test/unit/httpTreeAccessors.test.js +1002 -0
  176. package/lib/test/unit/httpTreeAccessors.test.js.map +1 -0
  177. package/lib/test/unit/localStorageTreeAccessors.test.d.ts +2 -0
  178. package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +1 -0
  179. package/lib/test/unit/localStorageTreeAccessors.test.js +814 -0
  180. package/lib/test/unit/localStorageTreeAccessors.test.js.map +1 -0
  181. package/lib/test/utils/fileSystemAccessMocks.d.ts +53 -0
  182. package/lib/test/utils/fileSystemAccessMocks.d.ts.map +1 -0
  183. package/lib/test/utils/fileSystemAccessMocks.js +277 -0
  184. package/lib/test/utils/fileSystemAccessMocks.js.map +1 -0
  185. package/package.json +41 -34
  186. package/rush-logs/ts-web-extras.build.cache.log +0 -1
  187. package/rush-logs/ts-web-extras.build.error.log +18 -0
  188. package/rush-logs/ts-web-extras.build.log +58 -25
  189. package/rush-logs/ts-web-extras.test.cache.log +1 -0
  190. package/rush-logs/ts-web-extras.test.error.log +16 -0
  191. package/rush-logs/ts-web-extras.test.log +70 -0
  192. package/src/index.ts +2 -2
  193. package/src/packlets/crypto-utils/browserCryptoProvider.ts +311 -0
  194. package/src/packlets/{crypto → crypto-utils}/index.ts +1 -0
  195. package/src/packlets/file-api-types/index.ts +24 -3
  196. package/src/packlets/file-tree/directoryHandleStore.ts +136 -0
  197. package/src/packlets/file-tree/fileApiTreeAccessors.ts +108 -0
  198. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +519 -0
  199. package/src/packlets/file-tree/httpTreeAccessors.ts +381 -0
  200. package/src/packlets/file-tree/index.ts +4 -0
  201. package/src/packlets/file-tree/localStorageTreeAccessors.ts +430 -0
  202. package/src/test/mocks/idb-keyval.ts +5 -0
  203. package/src/test/unit/browserHashProvider.test.ts +1 -1
  204. package/src/test/unit/directoryHandleStore.test.ts +251 -0
  205. package/src/test/unit/fileApiTreeAccessors.test.ts +69 -0
  206. package/src/test/unit/fileApiTypes.test.ts +36 -0
  207. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +885 -0
  208. package/src/test/unit/httpTreeAccessors.test.ts +1278 -0
  209. package/src/test/unit/localStorageTreeAccessors.test.ts +1014 -0
  210. package/src/test/utils/fileSystemAccessMocks.ts +353 -0
  211. package/temp/build/typescript/ts_8nwakTlr.json +1 -0
  212. package/temp/coverage/crypto/browserHashProvider.ts.html +1 -1
  213. package/temp/coverage/crypto/index.html +1 -1
  214. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +1018 -0
  215. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +304 -0
  216. package/temp/coverage/crypto-utils/index.html +131 -0
  217. package/temp/coverage/file-tree/directoryHandleStore.ts.html +493 -0
  218. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +330 -6
  219. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +1642 -0
  220. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +1228 -0
  221. package/temp/coverage/file-tree/index.html +69 -9
  222. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +1375 -0
  223. package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
  224. package/temp/coverage/helpers/index.html +1 -1
  225. package/temp/coverage/index.html +13 -13
  226. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +1 -1
  227. package/temp/coverage/lcov-report/crypto/index.html +1 -1
  228. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +1018 -0
  229. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +304 -0
  230. package/temp/coverage/lcov-report/crypto-utils/index.html +131 -0
  231. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +493 -0
  232. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +330 -6
  233. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +1642 -0
  234. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +1228 -0
  235. package/temp/coverage/lcov-report/file-tree/index.html +69 -9
  236. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +1375 -0
  237. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
  238. package/temp/coverage/lcov-report/helpers/index.html +1 -1
  239. package/temp/coverage/lcov-report/index.html +13 -13
  240. package/temp/coverage/lcov-report/url-utils/index.html +1 -1
  241. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
  242. package/temp/coverage/lcov.info +2829 -428
  243. package/temp/coverage/url-utils/index.html +1 -1
  244. package/temp/coverage/url-utils/urlParams.ts.html +1 -1
  245. package/temp/test/jest/haste-map-b931e4e63102f86c5bd4949f7dced44f-9d713eb41149188b4e5c0ae3d86d0a57-2ad8e16b24e391b8cdbe50b55c137169 +0 -0
  246. package/temp/test/jest/perf-cache-b931e4e63102f86c5bd4949f7dced44f-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
  247. package/temp/ts-web-extras.api.json +5282 -1472
  248. package/temp/ts-web-extras.api.md +124 -1
  249. package/dist/packlets/crypto/browserHashProvider.js.map +0 -1
  250. package/dist/packlets/crypto/index.js.map +0 -1
  251. package/docs/index.md +0 -34
  252. package/docs/ts-web-extras.browserhashprovider.hashparts.md +0 -88
  253. package/docs/ts-web-extras.browserhashprovider.hashstring.md +0 -72
  254. package/docs/ts-web-extras.browserhashprovider.md +0 -66
  255. package/docs/ts-web-extras.exportasjson.md +0 -70
  256. package/docs/ts-web-extras.exportusingfilesystemapi.md +0 -104
  257. package/docs/ts-web-extras.extractdirectorypath.md +0 -52
  258. package/docs/ts-web-extras.fileapitreeaccessors.create.md +0 -72
  259. package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +0 -54
  260. package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +0 -72
  261. package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +0 -72
  262. package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +0 -72
  263. package/docs/ts-web-extras.fileapitreeaccessors.md +0 -114
  264. package/docs/ts-web-extras.filepickeraccepttype.accept.md +0 -11
  265. package/docs/ts-web-extras.filepickeraccepttype.description.md +0 -11
  266. package/docs/ts-web-extras.filepickeraccepttype.md +0 -75
  267. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +0 -11
  268. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +0 -58
  269. package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +0 -15
  270. package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +0 -15
  271. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +0 -66
  272. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +0 -66
  273. package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +0 -15
  274. package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +0 -11
  275. package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +0 -146
  276. package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +0 -66
  277. package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +0 -50
  278. package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +0 -15
  279. package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +0 -52
  280. package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +0 -15
  281. package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +0 -11
  282. package/docs/ts-web-extras.filesystemfilehandle_2.md +0 -92
  283. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +0 -11
  284. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +0 -58
  285. package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +0 -11
  286. package/docs/ts-web-extras.filesystemgetfileoptions_2.md +0 -58
  287. package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +0 -50
  288. package/docs/ts-web-extras.filesystemhandle_2.kind.md +0 -11
  289. package/docs/ts-web-extras.filesystemhandle_2.md +0 -119
  290. package/docs/ts-web-extras.filesystemhandle_2.name.md +0 -11
  291. package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +0 -52
  292. package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +0 -52
  293. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +0 -58
  294. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +0 -11
  295. package/docs/ts-web-extras.filesystemremoveoptions_2.md +0 -58
  296. package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +0 -11
  297. package/docs/ts-web-extras.filesystemwritablefilestream_2.md +0 -57
  298. package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +0 -50
  299. package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +0 -50
  300. package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +0 -50
  301. package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +0 -13
  302. package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +0 -56
  303. package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +0 -56
  304. package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +0 -76
  305. package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +0 -76
  306. package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +0 -72
  307. package/docs/ts-web-extras.filetreehelpers.md +0 -102
  308. package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +0 -11
  309. package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +0 -100
  310. package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +0 -11
  311. package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +0 -11
  312. package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +0 -11
  313. package/docs/ts-web-extras.ifilehandletreeinitializer.md +0 -79
  314. package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +0 -11
  315. package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +0 -11
  316. package/docs/ts-web-extras.ifilelisttreeinitializer.md +0 -58
  317. package/docs/ts-web-extras.ifilemetadata.lastmodified.md +0 -11
  318. package/docs/ts-web-extras.ifilemetadata.md +0 -124
  319. package/docs/ts-web-extras.ifilemetadata.name.md +0 -11
  320. package/docs/ts-web-extras.ifilemetadata.path.md +0 -11
  321. package/docs/ts-web-extras.ifilemetadata.size.md +0 -11
  322. package/docs/ts-web-extras.ifilemetadata.type.md +0 -11
  323. package/docs/ts-web-extras.ifsaccessapis.md +0 -56
  324. package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +0 -52
  325. package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +0 -52
  326. package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +0 -52
  327. package/docs/ts-web-extras.isdirectoryhandle.md +0 -56
  328. package/docs/ts-web-extras.isfilehandle.md +0 -56
  329. package/docs/ts-web-extras.isfilepath.md +0 -52
  330. package/docs/ts-web-extras.iurlconfigoptions.config.md +0 -13
  331. package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +0 -13
  332. package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +0 -13
  333. package/docs/ts-web-extras.iurlconfigoptions.input.md +0 -13
  334. package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +0 -13
  335. package/docs/ts-web-extras.iurlconfigoptions.interactive.md +0 -13
  336. package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +0 -13
  337. package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +0 -13
  338. package/docs/ts-web-extras.iurlconfigoptions.md +0 -286
  339. package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +0 -13
  340. package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +0 -13
  341. package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +0 -13
  342. package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +0 -13
  343. package/docs/ts-web-extras.iurlconfigoptions.zippath.md +0 -13
  344. package/docs/ts-web-extras.md +0 -512
  345. package/docs/ts-web-extras.parsecontextfilter.md +0 -52
  346. package/docs/ts-web-extras.parsequalifierdefaults.md +0 -52
  347. package/docs/ts-web-extras.parseresourcetypes.md +0 -52
  348. package/docs/ts-web-extras.parseurlparameters.md +0 -17
  349. package/docs/ts-web-extras.safeshowdirectorypicker.md +0 -72
  350. package/docs/ts-web-extras.safeshowopenfilepicker.md +0 -72
  351. package/docs/ts-web-extras.safeshowsavefilepicker.md +0 -72
  352. package/docs/ts-web-extras.showdirectorypickeroptions.id.md +0 -11
  353. package/docs/ts-web-extras.showdirectorypickeroptions.md +0 -96
  354. package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +0 -11
  355. package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +0 -11
  356. package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +0 -11
  357. package/docs/ts-web-extras.showopenfilepickeroptions.id.md +0 -11
  358. package/docs/ts-web-extras.showopenfilepickeroptions.md +0 -134
  359. package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +0 -11
  360. package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +0 -11
  361. package/docs/ts-web-extras.showopenfilepickeroptions.types.md +0 -11
  362. package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +0 -11
  363. package/docs/ts-web-extras.showsavefilepickeroptions.id.md +0 -11
  364. package/docs/ts-web-extras.showsavefilepickeroptions.md +0 -134
  365. package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +0 -11
  366. package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +0 -11
  367. package/docs/ts-web-extras.showsavefilepickeroptions.types.md +0 -11
  368. package/docs/ts-web-extras.supportsfilesystemaccess.md +0 -56
  369. package/docs/ts-web-extras.treeinitializer.md +0 -15
  370. package/docs/ts-web-extras.wellknowndirectory.md +0 -13
  371. package/docs/ts-web-extras.windowwithfsaccess.md +0 -15
  372. package/lib/packlets/crypto/browserHashProvider.d.ts.map +0 -1
  373. package/lib/packlets/crypto/browserHashProvider.js.map +0 -1
  374. package/lib/packlets/crypto/index.d.ts.map +0 -1
  375. package/lib/packlets/crypto/index.js.map +0 -1
  376. package/temp/build/typescript/ts_vnCx6LlY.json +0 -1
  377. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  378. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
  379. /package/dist/packlets/{crypto → crypto-utils}/browserHashProvider.js +0 -0
  380. /package/lib/packlets/{crypto → crypto-utils}/browserHashProvider.d.ts +0 -0
  381. /package/lib/packlets/{crypto → crypto-utils}/browserHashProvider.js +0 -0
  382. /package/src/packlets/{crypto → crypto-utils}/browserHashProvider.ts +0 -0
  383. /package/temp/test/jest/{jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/0e/package_0eb6535f5987849d93ea51ef33a14cf6 → jest-transform-cache-b931e4e63102f86c5bd4949f7dced44f-79ef2876fae7ca75eedb2aa53dc48338/b5/package_b5f57afc9ec2c011239b1608ee5bdfa5} +0 -0
@@ -0,0 +1,430 @@
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, Result, succeed, succeedWithDetail } from '@fgv/ts-utils';
24
+ import { FileTree } from '@fgv/ts-json-base';
25
+ import { isJsonObject, type JsonObject } from '@fgv/ts-json-base';
26
+
27
+ /**
28
+ * Configuration for LocalStorageTreeAccessors.
29
+ * @public
30
+ */
31
+ export interface ILocalStorageTreeParams<TCT extends string = string>
32
+ extends FileTree.IFileTreeInitParams<TCT> {
33
+ /**
34
+ * Map of directory path prefixes to localStorage keys.
35
+ * Files under each prefix are stored in the corresponding localStorage key.
36
+ * Example: \{ '/data/ingredients': 'myapp:ingredients:v1' \}
37
+ */
38
+ pathToKeyMap: Record<string, string>;
39
+
40
+ /**
41
+ * Storage instance to use. Defaults to window.localStorage.
42
+ * Can be overridden for testing with mock storage.
43
+ */
44
+ storage?: Storage;
45
+
46
+ /**
47
+ * If true, automatically sync changes to localStorage on every modification.
48
+ * If false (default), changes are only synced when syncToDisk() is called.
49
+ */
50
+ autoSync?: boolean;
51
+ }
52
+
53
+ /**
54
+ * Browser localStorage-backed file tree accessors with persistence support.
55
+ *
56
+ * Maps filesystem-like directory paths to localStorage keys, where each key stores
57
+ * multiple collections as a JSON object. This provides a general-purpose implementation
58
+ * for browser-based file tree persistence without requiring File System Access API.
59
+ *
60
+ * Storage format per key: `{ "collection-id": "<raw file content>" }`
61
+ * File paths map as: `/data/ingredients/collection-id.yaml` → stored in key for `/data/ingredients`
62
+ *
63
+ * Legacy format (v1): `{ "collection-id": { ...parsedJsonObject } }` is auto-migrated on load.
64
+ *
65
+ * @public
66
+ */
67
+ export class LocalStorageTreeAccessors<TCT extends string = string>
68
+ extends FileTree.InMemoryTreeAccessors<TCT>
69
+ implements FileTree.IPersistentFileTreeAccessors<TCT>
70
+ {
71
+ private readonly _storage: Storage;
72
+ private readonly _pathToKeyMap: Map<string, string>;
73
+ private readonly _keyToPathMap: Map<string, string>;
74
+ private readonly _dirtyFiles: Set<string>;
75
+ private readonly _autoSync: boolean;
76
+
77
+ /**
78
+ * Private constructor. Use fromStorage() factory method instead.
79
+ * @internal
80
+ */
81
+ private constructor(
82
+ files: FileTree.IInMemoryFile<TCT>[],
83
+ storage: Storage,
84
+ pathToKeyMap: Map<string, string>,
85
+ params?: ILocalStorageTreeParams<TCT>
86
+ ) {
87
+ super(files, params);
88
+ this._storage = storage;
89
+ this._pathToKeyMap = pathToKeyMap;
90
+ this._keyToPathMap = new Map(Array.from(pathToKeyMap.entries()).map(([k, v]) => [v, k]));
91
+ this._dirtyFiles = new Set();
92
+ /* c8 ignore next 1 - intermittent branch coverage: ?? false branch when params is undefined */
93
+ this._autoSync = params?.autoSync ?? false;
94
+ }
95
+
96
+ /**
97
+ * Create LocalStorageTreeAccessors from browser localStorage.
98
+ * Loads all collections from the configured storage keys.
99
+ *
100
+ * @param params - Configuration including path-to-key mappings
101
+ * @returns Result containing the accessors or an error
102
+ * @public
103
+ */
104
+ public static fromStorage<TCT extends string = string>(
105
+ params: ILocalStorageTreeParams<TCT>
106
+ ): Result<LocalStorageTreeAccessors<TCT>> {
107
+ try {
108
+ /* c8 ignore next 1 - intermittent branch coverage: window.localStorage branch when params.storage is undefined */
109
+ const storage = params.storage ?? (typeof window !== 'undefined' ? window.localStorage : undefined);
110
+ if (!storage) {
111
+ return fail('localStorage is not available');
112
+ }
113
+
114
+ const pathToKeyMap = new Map(Object.entries(params.pathToKeyMap));
115
+ const files = this._loadFromStorage<TCT>(storage, pathToKeyMap, params);
116
+
117
+ return succeed(new LocalStorageTreeAccessors<TCT>(files, storage, pathToKeyMap, params));
118
+ /* c8 ignore next 4 - defensive: outer catch for unexpected errors */
119
+ } catch (error) {
120
+ const message = error instanceof Error ? error.message : String(error);
121
+ return fail(`Failed to create LocalStorageTreeAccessors: ${message}`);
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Load all files from localStorage based on path-to-key mappings.
127
+ * @internal
128
+ */
129
+ private static _loadFromStorage<TCT extends string = string>(
130
+ storage: Storage,
131
+ pathToKeyMap: Map<string, string>,
132
+ params?: ILocalStorageTreeParams<TCT>
133
+ ): FileTree.IInMemoryFile<TCT>[] {
134
+ const files: FileTree.IInMemoryFile<TCT>[] = [];
135
+
136
+ for (const [dataPath, storageKey] of pathToKeyMap.entries()) {
137
+ const rawJson = storage.getItem(storageKey);
138
+ if (!rawJson) {
139
+ continue;
140
+ }
141
+
142
+ try {
143
+ const parsed: unknown = JSON.parse(rawJson);
144
+ if (!isJsonObject(parsed)) {
145
+ continue;
146
+ }
147
+
148
+ for (const [collectionId, contents] of Object.entries(parsed)) {
149
+ // Support both new format (string values) and legacy format (JsonObject values)
150
+ let rawContent: string;
151
+ let extension: string;
152
+ if (typeof contents === 'string') {
153
+ rawContent = contents;
154
+ // Infer extension: if content looks like JSON, use .json; otherwise .yaml
155
+ extension = this._looksLikeJson(contents) ? '.json' : '.yaml';
156
+ } else if (isJsonObject(contents)) {
157
+ // Legacy format: migrate by stringifying
158
+ rawContent = JSON.stringify(contents);
159
+ extension = '.json';
160
+ } else {
161
+ continue;
162
+ }
163
+
164
+ const filePath = this._joinPath(dataPath, `${collectionId}${extension}`);
165
+ /* c8 ignore next 3 - intermittent branch coverage: ternary branches in tight loop */
166
+ const contentType = params?.inferContentType
167
+ ? params.inferContentType(filePath, undefined).orDefault()
168
+ : undefined;
169
+
170
+ files.push({
171
+ path: filePath,
172
+ contents: rawContent,
173
+ contentType
174
+ });
175
+ }
176
+ } catch {
177
+ // Skip corrupted data
178
+ continue;
179
+ }
180
+ }
181
+
182
+ return files;
183
+ }
184
+
185
+ /**
186
+ * Heuristic check: does the content look like JSON?
187
+ * @internal
188
+ */
189
+ private static _looksLikeJson(content: string): boolean {
190
+ const trimmed = content.trimStart();
191
+ return trimmed.startsWith('{') || trimmed.startsWith('[');
192
+ }
193
+
194
+ /**
195
+ * Join path components, handling leading/trailing slashes.
196
+ * @internal
197
+ */
198
+ private static _joinPath(base: string, name: string): string {
199
+ /* c8 ignore next 2 - intermittent branch coverage: slash-trimming edge cases */
200
+ const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;
201
+ const cleanName = name.startsWith('/') ? name.slice(1) : name;
202
+ return `${cleanBase}/${cleanName}`;
203
+ }
204
+
205
+ /**
206
+ * Get the storage key for a given file path.
207
+ * @internal
208
+ */
209
+ private _getStorageKeyForPath(path: string): string | undefined {
210
+ // Find the longest matching prefix
211
+ let bestMatch: { prefix: string; key: string } | undefined;
212
+ for (const [prefix, key] of this._pathToKeyMap.entries()) {
213
+ if (path.startsWith(prefix)) {
214
+ /* c8 ignore next 1 - intermittent: overlapping-prefix branch requires two matching prefixes in iteration order */
215
+ if (!bestMatch || prefix.length > bestMatch.prefix.length) {
216
+ bestMatch = { prefix, key };
217
+ }
218
+ }
219
+ }
220
+ return bestMatch?.key;
221
+ }
222
+
223
+ /**
224
+ * Get the data path prefix for a given file path.
225
+ * @internal
226
+ */
227
+ private _getDataPathForPath(path: string): string | undefined {
228
+ for (const prefix of this._pathToKeyMap.keys()) {
229
+ if (path.startsWith(prefix)) {
230
+ return prefix;
231
+ }
232
+ }
233
+ /* c8 ignore next 2 - coverage intermittently missed in full suite */
234
+ return undefined;
235
+ }
236
+
237
+ /**
238
+ * Extract collection ID from a file path.
239
+ * Example: '/data/ingredients/my-collection.yaml' → 'my-collection'
240
+ * @internal
241
+ */
242
+ private _getCollectionIdFromPath(path: string): string {
243
+ const dataPath = this._getDataPathForPath(path);
244
+ /* c8 ignore next 3 - coverage intermittently missed in full suite */
245
+ if (!dataPath) {
246
+ return path;
247
+ }
248
+
249
+ const relativePath = path.slice(dataPath.length);
250
+ /* c8 ignore next 1 - defensive: relativePath always starts with / when paths are absolute */
251
+ const cleanPath = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;
252
+
253
+ // Remove any file extension
254
+ const dotIndex = cleanPath.lastIndexOf('.');
255
+ return dotIndex > 0 ? cleanPath.slice(0, dotIndex) : cleanPath;
256
+ }
257
+
258
+ /**
259
+ * Remove a file's entry from its localStorage key.
260
+ * @internal
261
+ */
262
+ private _deleteFileFromStorage(path: string): void {
263
+ const storageKey = this._getStorageKeyForPath(path);
264
+ if (!storageKey) {
265
+ return;
266
+ }
267
+
268
+ const collectionId = this._getCollectionIdFromPath(path);
269
+ const existingJson = this._storage.getItem(storageKey);
270
+ if (!existingJson) {
271
+ return;
272
+ }
273
+
274
+ try {
275
+ const parsed = JSON.parse(existingJson);
276
+ if (isJsonObject(parsed)) {
277
+ const existing = parsed as Record<string, unknown>;
278
+ delete existing[collectionId];
279
+ if (Object.keys(existing).length > 0) {
280
+ this._storage.setItem(storageKey, JSON.stringify(existing));
281
+ } else {
282
+ this._storage.removeItem(storageKey);
283
+ }
284
+ }
285
+ } catch {
286
+ // Storage is corrupted — nothing to clean up
287
+ }
288
+ }
289
+
290
+ /**
291
+ * Sync a single dirty file to localStorage.
292
+ * @internal
293
+ */
294
+ private _syncFile(path: string): Result<void> {
295
+ const storageKey = this._getStorageKeyForPath(path);
296
+ if (!storageKey) {
297
+ return fail(`No storage key configured for path: ${path}`);
298
+ }
299
+
300
+ const collectionId = this._getCollectionIdFromPath(path);
301
+ const contentsResult = this.getFileContents(path);
302
+ if (contentsResult.isFailure()) {
303
+ return fail(`Failed to get file contents for ${path}: ${contentsResult.message}`);
304
+ }
305
+
306
+ try {
307
+ const contents = contentsResult.value;
308
+
309
+ // Load existing data from storage
310
+ const existingJson = this._storage.getItem(storageKey);
311
+ let existing: Record<string, unknown> = {};
312
+ if (existingJson) {
313
+ try {
314
+ const parsed = JSON.parse(existingJson);
315
+ if (isJsonObject(parsed)) {
316
+ existing = parsed as Record<string, unknown>;
317
+ }
318
+ } catch {
319
+ // Start fresh if corrupted
320
+ }
321
+ }
322
+
323
+ // Store raw content string (content-agnostic: JSON, YAML, etc.)
324
+ existing[collectionId] = contents;
325
+ this._storage.setItem(storageKey, JSON.stringify(existing));
326
+
327
+ return succeed(undefined);
328
+ /* c8 ignore next 4 - defensive: only triggers on storage quota or similar runtime errors */
329
+ } catch (error) {
330
+ const message = error instanceof Error ? error.message : String(error);
331
+ return fail(`Failed to sync file ${path}: ${message}`);
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Sync all dirty files to localStorage.
337
+ * @returns Result indicating success or failure
338
+ * @public
339
+ */
340
+ public async syncToDisk(): Promise<Result<void>> {
341
+ if (this._dirtyFiles.size === 0) {
342
+ return succeed(undefined);
343
+ }
344
+
345
+ const errors: string[] = [];
346
+ for (const path of this._dirtyFiles) {
347
+ const result = this._syncFile(path);
348
+ if (result.isFailure()) {
349
+ errors.push(result.message);
350
+ }
351
+ }
352
+
353
+ if (errors.length > 0) {
354
+ return fail(`Failed to sync ${errors.length} file(s): ${errors.join('; ')}`);
355
+ }
356
+
357
+ this._dirtyFiles.clear();
358
+ return succeed(undefined);
359
+ }
360
+
361
+ /**
362
+ * Check if there are unsaved changes.
363
+ * @returns True if there are dirty files
364
+ * @public
365
+ */
366
+ public isDirty(): boolean {
367
+ return this._dirtyFiles.size > 0;
368
+ }
369
+
370
+ /**
371
+ * Get list of file paths with unsaved changes.
372
+ * @returns Array of dirty file paths
373
+ * @public
374
+ */
375
+ public getDirtyPaths(): string[] {
376
+ return Array.from(this._dirtyFiles);
377
+ }
378
+
379
+ /**
380
+ * Delete a file and remove it from localStorage.
381
+ * @param path - File path to delete
382
+ * @returns Result with true if deleted, or error
383
+ * @public
384
+ */
385
+ public deleteFile(path: string): Result<boolean> {
386
+ const result = super.deleteFile(path);
387
+ if (result.isSuccess()) {
388
+ this._dirtyFiles.delete(path);
389
+ this._deleteFileFromStorage(path);
390
+ }
391
+ return result;
392
+ }
393
+
394
+ /**
395
+ * Save file contents. Marks file as dirty and optionally auto-syncs.
396
+ * @param path - File path
397
+ * @param contents - New file contents
398
+ * @returns Result with the saved contents or error
399
+ * @public
400
+ */
401
+ public saveFileContents(path: string, contents: string): Result<string> {
402
+ const result = super.saveFileContents(path, contents);
403
+ if (result.isSuccess()) {
404
+ this._dirtyFiles.add(path);
405
+ if (this._autoSync) {
406
+ const syncResult = this._syncFile(path);
407
+ if (syncResult.isSuccess()) {
408
+ this._dirtyFiles.delete(path);
409
+ } else {
410
+ return fail(syncResult.message);
411
+ }
412
+ }
413
+ }
414
+ return result;
415
+ }
416
+
417
+ /**
418
+ * Check if a file is mutable and return persistence detail.
419
+ * @param path - File path to check
420
+ * @returns DetailedResult with mutability status and 'persistent' detail if mutable
421
+ * @public
422
+ */
423
+ public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {
424
+ const baseResult = super.fileIsMutable(path);
425
+ if (baseResult.isSuccess() && baseResult.value === true) {
426
+ return succeedWithDetail(true, 'persistent');
427
+ }
428
+ return baseResult;
429
+ }
430
+ }
@@ -0,0 +1,5 @@
1
+ export const createStore = jest.fn(() => ({}));
2
+ export const get = jest.fn();
3
+ export const set = jest.fn();
4
+ export const del = jest.fn();
5
+ export const keys = jest.fn();
@@ -21,7 +21,7 @@
21
21
  */
22
22
 
23
23
  import '@fgv/ts-utils-jest';
24
- import { BrowserHashProvider } from '../../packlets/crypto';
24
+ import { BrowserHashProvider } from '../../packlets/crypto-utils';
25
25
 
26
26
  describe('BrowserHashProvider', () => {
27
27
  describe('hashString', () => {
@@ -0,0 +1,251 @@
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 '@fgv/ts-utils-jest';
24
+ import {
25
+ DirectoryHandleStore,
26
+ DEFAULT_DIRECTORY_HANDLE_DB,
27
+ DEFAULT_DIRECTORY_HANDLE_STORE
28
+ } from '../../packlets/file-tree/directoryHandleStore';
29
+ import type { FileSystemDirectoryHandle } from '../../packlets/file-api-types';
30
+
31
+ import { get, set, del, keys, createStore } from 'idb-keyval';
32
+
33
+ const mockGet = jest.mocked(get);
34
+ const mockSet = jest.mocked(set);
35
+ const mockDel = jest.mocked(del);
36
+ const mockKeys = jest.mocked(keys);
37
+ const mockCreateStore = jest.mocked(createStore);
38
+
39
+ function makeMockHandle(name: string): FileSystemDirectoryHandle {
40
+ return {
41
+ kind: 'directory',
42
+ name,
43
+ isSameEntry: jest.fn(),
44
+ queryPermission: jest.fn(),
45
+ requestPermission: jest.fn(),
46
+ getDirectoryHandle: jest.fn(),
47
+ getFileHandle: jest.fn(),
48
+ removeEntry: jest.fn(),
49
+ resolve: jest.fn(),
50
+ keys: jest.fn(),
51
+ values: jest.fn(),
52
+ entries: jest.fn(),
53
+ [Symbol.asyncIterator]: jest.fn()
54
+ } as FileSystemDirectoryHandle;
55
+ }
56
+
57
+ describe('DirectoryHandleStore', () => {
58
+ beforeEach(() => {
59
+ jest.clearAllMocks();
60
+ });
61
+
62
+ describe('constants', () => {
63
+ test('DEFAULT_DIRECTORY_HANDLE_DB has expected value', () => {
64
+ expect(DEFAULT_DIRECTORY_HANDLE_DB).toBe('chocolate-lab-storage');
65
+ });
66
+
67
+ test('DEFAULT_DIRECTORY_HANDLE_STORE has expected value', () => {
68
+ expect(DEFAULT_DIRECTORY_HANDLE_STORE).toBe('directory-handles');
69
+ });
70
+ });
71
+
72
+ describe('constructor', () => {
73
+ test('uses default db and store names', () => {
74
+ new DirectoryHandleStore();
75
+ expect(mockCreateStore).toHaveBeenCalledWith(
76
+ DEFAULT_DIRECTORY_HANDLE_DB,
77
+ DEFAULT_DIRECTORY_HANDLE_STORE
78
+ );
79
+ });
80
+
81
+ test('uses custom db and store names', () => {
82
+ new DirectoryHandleStore('custom-db', 'custom-store');
83
+ expect(mockCreateStore).toHaveBeenCalledWith('custom-db', 'custom-store');
84
+ });
85
+ });
86
+
87
+ describe('save', () => {
88
+ test('saves a handle successfully', async () => {
89
+ mockSet.mockResolvedValue(undefined);
90
+ const store = new DirectoryHandleStore();
91
+ const handle = makeMockHandle('my-dir');
92
+
93
+ const result = await store.save('my-dir', handle);
94
+
95
+ expect(result).toSucceed();
96
+ expect(mockSet).toHaveBeenCalledWith('my-dir', handle, expect.anything());
97
+ });
98
+
99
+ test('returns failure when set throws', async () => {
100
+ mockSet.mockRejectedValue(new Error('IndexedDB unavailable'));
101
+ const store = new DirectoryHandleStore();
102
+ const handle = makeMockHandle('my-dir');
103
+
104
+ const result = await store.save('my-dir', handle);
105
+
106
+ expect(result).toFailWith(/IndexedDB unavailable/);
107
+ });
108
+ });
109
+
110
+ describe('load', () => {
111
+ test('returns the handle when found', async () => {
112
+ const handle = makeMockHandle('my-dir');
113
+ mockGet.mockResolvedValue(handle);
114
+ const store = new DirectoryHandleStore();
115
+
116
+ const result = await store.load('my-dir');
117
+
118
+ expect(result).toSucceedWith(handle);
119
+ expect(mockGet).toHaveBeenCalledWith('my-dir', expect.anything());
120
+ });
121
+
122
+ test('returns undefined when not found', async () => {
123
+ mockGet.mockResolvedValue(undefined);
124
+ const store = new DirectoryHandleStore();
125
+
126
+ const result = await store.load('missing');
127
+
128
+ expect(result).toSucceedWith(undefined);
129
+ });
130
+
131
+ test('returns failure when get throws', async () => {
132
+ mockGet.mockRejectedValue(new Error('read error'));
133
+ const store = new DirectoryHandleStore();
134
+
135
+ const result = await store.load('my-dir');
136
+
137
+ expect(result).toFailWith(/read error/);
138
+ });
139
+ });
140
+
141
+ describe('remove', () => {
142
+ test('removes a handle successfully', async () => {
143
+ mockDel.mockResolvedValue(undefined);
144
+ const store = new DirectoryHandleStore();
145
+
146
+ const result = await store.remove('my-dir');
147
+
148
+ expect(result).toSucceed();
149
+ expect(mockDel).toHaveBeenCalledWith('my-dir', expect.anything());
150
+ });
151
+
152
+ test('returns failure when del throws', async () => {
153
+ mockDel.mockRejectedValue(new Error('delete error'));
154
+ const store = new DirectoryHandleStore();
155
+
156
+ const result = await store.remove('my-dir');
157
+
158
+ expect(result).toFailWith(/delete error/);
159
+ });
160
+ });
161
+
162
+ describe('getAllLabels', () => {
163
+ test('returns all keys', async () => {
164
+ mockKeys.mockResolvedValue(['dir-a', 'dir-b']);
165
+ const store = new DirectoryHandleStore();
166
+
167
+ const result = await store.getAllLabels();
168
+
169
+ expect(result).toSucceedWith(['dir-a', 'dir-b']);
170
+ expect(mockKeys).toHaveBeenCalledWith(expect.anything());
171
+ });
172
+
173
+ test('returns empty array when no keys', async () => {
174
+ mockKeys.mockResolvedValue([]);
175
+ const store = new DirectoryHandleStore();
176
+
177
+ const result = await store.getAllLabels();
178
+
179
+ expect(result).toSucceedWith([]);
180
+ });
181
+
182
+ test('returns failure when keys throws', async () => {
183
+ mockKeys.mockRejectedValue(new Error('keys error'));
184
+ const store = new DirectoryHandleStore();
185
+
186
+ const result = await store.getAllLabels();
187
+
188
+ expect(result).toFailWith(/keys error/);
189
+ });
190
+ });
191
+
192
+ describe('getAll', () => {
193
+ test('returns all label/handle pairs', async () => {
194
+ const handleA = makeMockHandle('dir-a');
195
+ const handleB = makeMockHandle('dir-b');
196
+ mockKeys.mockResolvedValue(['dir-a', 'dir-b']);
197
+ mockGet.mockResolvedValueOnce(handleA).mockResolvedValueOnce(handleB);
198
+ const store = new DirectoryHandleStore();
199
+
200
+ const result = await store.getAll();
201
+
202
+ expect(result).toSucceedAndSatisfy((entries) => {
203
+ expect(entries).toHaveLength(2);
204
+ expect(entries[0]).toEqual({ label: 'dir-a', handle: handleA });
205
+ expect(entries[1]).toEqual({ label: 'dir-b', handle: handleB });
206
+ });
207
+ });
208
+
209
+ test('returns empty array when no handles stored', async () => {
210
+ mockKeys.mockResolvedValue([]);
211
+ const store = new DirectoryHandleStore();
212
+
213
+ const result = await store.getAll();
214
+
215
+ expect(result).toSucceedWith([]);
216
+ });
217
+
218
+ test('skips entries where handle is undefined', async () => {
219
+ const handleA = makeMockHandle('dir-a');
220
+ mockKeys.mockResolvedValue(['dir-a', 'dir-b']);
221
+ mockGet.mockResolvedValueOnce(handleA).mockResolvedValueOnce(undefined);
222
+ const store = new DirectoryHandleStore();
223
+
224
+ const result = await store.getAll();
225
+
226
+ expect(result).toSucceedAndSatisfy((entries) => {
227
+ expect(entries).toHaveLength(1);
228
+ expect(entries[0]).toEqual({ label: 'dir-a', handle: handleA });
229
+ });
230
+ });
231
+
232
+ test('returns failure when getAllLabels fails', async () => {
233
+ mockKeys.mockRejectedValue(new Error('keys error'));
234
+ const store = new DirectoryHandleStore();
235
+
236
+ const result = await store.getAll();
237
+
238
+ expect(result).toFailWith(/keys error/);
239
+ });
240
+
241
+ test('returns failure when load fails for a key', async () => {
242
+ mockKeys.mockResolvedValue(['dir-a']);
243
+ mockGet.mockRejectedValue(new Error('load error'));
244
+ const store = new DirectoryHandleStore();
245
+
246
+ const result = await store.getAll();
247
+
248
+ expect(result).toFailWith(/load error/);
249
+ });
250
+ });
251
+ });