@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,363 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.LocalStorageTreeAccessors = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const ts_json_base_1 = require("@fgv/ts-json-base");
27
+ const ts_json_base_2 = require("@fgv/ts-json-base");
28
+ /**
29
+ * Browser localStorage-backed file tree accessors with persistence support.
30
+ *
31
+ * Maps filesystem-like directory paths to localStorage keys, where each key stores
32
+ * multiple collections as a JSON object. This provides a general-purpose implementation
33
+ * for browser-based file tree persistence without requiring File System Access API.
34
+ *
35
+ * Storage format per key: `{ "collection-id": "<raw file content>" }`
36
+ * File paths map as: `/data/ingredients/collection-id.yaml` → stored in key for `/data/ingredients`
37
+ *
38
+ * Legacy format (v1): `{ "collection-id": { ...parsedJsonObject } }` is auto-migrated on load.
39
+ *
40
+ * @public
41
+ */
42
+ class LocalStorageTreeAccessors extends ts_json_base_1.FileTree.InMemoryTreeAccessors {
43
+ /**
44
+ * Private constructor. Use fromStorage() factory method instead.
45
+ * @internal
46
+ */
47
+ constructor(files, storage, pathToKeyMap, params) {
48
+ var _a;
49
+ super(files, params);
50
+ this._storage = storage;
51
+ this._pathToKeyMap = pathToKeyMap;
52
+ this._keyToPathMap = new Map(Array.from(pathToKeyMap.entries()).map(([k, v]) => [v, k]));
53
+ this._dirtyFiles = new Set();
54
+ /* c8 ignore next 1 - intermittent branch coverage: ?? false branch when params is undefined */
55
+ this._autoSync = (_a = params === null || params === void 0 ? void 0 : params.autoSync) !== null && _a !== void 0 ? _a : false;
56
+ }
57
+ /**
58
+ * Create LocalStorageTreeAccessors from browser localStorage.
59
+ * Loads all collections from the configured storage keys.
60
+ *
61
+ * @param params - Configuration including path-to-key mappings
62
+ * @returns Result containing the accessors or an error
63
+ * @public
64
+ */
65
+ static fromStorage(params) {
66
+ var _a;
67
+ try {
68
+ /* c8 ignore next 1 - intermittent branch coverage: window.localStorage branch when params.storage is undefined */
69
+ const storage = (_a = params.storage) !== null && _a !== void 0 ? _a : (typeof window !== 'undefined' ? window.localStorage : undefined);
70
+ if (!storage) {
71
+ return (0, ts_utils_1.fail)('localStorage is not available');
72
+ }
73
+ const pathToKeyMap = new Map(Object.entries(params.pathToKeyMap));
74
+ const files = this._loadFromStorage(storage, pathToKeyMap, params);
75
+ return (0, ts_utils_1.succeed)(new LocalStorageTreeAccessors(files, storage, pathToKeyMap, params));
76
+ /* c8 ignore next 4 - defensive: outer catch for unexpected errors */
77
+ }
78
+ catch (error) {
79
+ const message = error instanceof Error ? error.message : String(error);
80
+ return (0, ts_utils_1.fail)(`Failed to create LocalStorageTreeAccessors: ${message}`);
81
+ }
82
+ }
83
+ /**
84
+ * Load all files from localStorage based on path-to-key mappings.
85
+ * @internal
86
+ */
87
+ static _loadFromStorage(storage, pathToKeyMap, params) {
88
+ const files = [];
89
+ for (const [dataPath, storageKey] of pathToKeyMap.entries()) {
90
+ const rawJson = storage.getItem(storageKey);
91
+ if (!rawJson) {
92
+ continue;
93
+ }
94
+ try {
95
+ const parsed = JSON.parse(rawJson);
96
+ if (!(0, ts_json_base_2.isJsonObject)(parsed)) {
97
+ continue;
98
+ }
99
+ for (const [collectionId, contents] of Object.entries(parsed)) {
100
+ // Support both new format (string values) and legacy format (JsonObject values)
101
+ let rawContent;
102
+ let extension;
103
+ if (typeof contents === 'string') {
104
+ rawContent = contents;
105
+ // Infer extension: if content looks like JSON, use .json; otherwise .yaml
106
+ extension = this._looksLikeJson(contents) ? '.json' : '.yaml';
107
+ }
108
+ else if ((0, ts_json_base_2.isJsonObject)(contents)) {
109
+ // Legacy format: migrate by stringifying
110
+ rawContent = JSON.stringify(contents);
111
+ extension = '.json';
112
+ }
113
+ else {
114
+ continue;
115
+ }
116
+ const filePath = this._joinPath(dataPath, `${collectionId}${extension}`);
117
+ /* c8 ignore next 3 - intermittent branch coverage: ternary branches in tight loop */
118
+ const contentType = (params === null || params === void 0 ? void 0 : params.inferContentType)
119
+ ? params.inferContentType(filePath, undefined).orDefault()
120
+ : undefined;
121
+ files.push({
122
+ path: filePath,
123
+ contents: rawContent,
124
+ contentType
125
+ });
126
+ }
127
+ }
128
+ catch (_a) {
129
+ // Skip corrupted data
130
+ continue;
131
+ }
132
+ }
133
+ return files;
134
+ }
135
+ /**
136
+ * Heuristic check: does the content look like JSON?
137
+ * @internal
138
+ */
139
+ static _looksLikeJson(content) {
140
+ const trimmed = content.trimStart();
141
+ return trimmed.startsWith('{') || trimmed.startsWith('[');
142
+ }
143
+ /**
144
+ * Join path components, handling leading/trailing slashes.
145
+ * @internal
146
+ */
147
+ static _joinPath(base, name) {
148
+ /* c8 ignore next 2 - intermittent branch coverage: slash-trimming edge cases */
149
+ const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;
150
+ const cleanName = name.startsWith('/') ? name.slice(1) : name;
151
+ return `${cleanBase}/${cleanName}`;
152
+ }
153
+ /**
154
+ * Get the storage key for a given file path.
155
+ * @internal
156
+ */
157
+ _getStorageKeyForPath(path) {
158
+ // Find the longest matching prefix
159
+ let bestMatch;
160
+ for (const [prefix, key] of this._pathToKeyMap.entries()) {
161
+ if (path.startsWith(prefix)) {
162
+ /* c8 ignore next 1 - intermittent: overlapping-prefix branch requires two matching prefixes in iteration order */
163
+ if (!bestMatch || prefix.length > bestMatch.prefix.length) {
164
+ bestMatch = { prefix, key };
165
+ }
166
+ }
167
+ }
168
+ return bestMatch === null || bestMatch === void 0 ? void 0 : bestMatch.key;
169
+ }
170
+ /**
171
+ * Get the data path prefix for a given file path.
172
+ * @internal
173
+ */
174
+ _getDataPathForPath(path) {
175
+ for (const prefix of this._pathToKeyMap.keys()) {
176
+ if (path.startsWith(prefix)) {
177
+ return prefix;
178
+ }
179
+ }
180
+ /* c8 ignore next 2 - coverage intermittently missed in full suite */
181
+ return undefined;
182
+ }
183
+ /**
184
+ * Extract collection ID from a file path.
185
+ * Example: '/data/ingredients/my-collection.yaml' → 'my-collection'
186
+ * @internal
187
+ */
188
+ _getCollectionIdFromPath(path) {
189
+ const dataPath = this._getDataPathForPath(path);
190
+ /* c8 ignore next 3 - coverage intermittently missed in full suite */
191
+ if (!dataPath) {
192
+ return path;
193
+ }
194
+ const relativePath = path.slice(dataPath.length);
195
+ /* c8 ignore next 1 - defensive: relativePath always starts with / when paths are absolute */
196
+ const cleanPath = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;
197
+ // Remove any file extension
198
+ const dotIndex = cleanPath.lastIndexOf('.');
199
+ return dotIndex > 0 ? cleanPath.slice(0, dotIndex) : cleanPath;
200
+ }
201
+ /**
202
+ * Remove a file's entry from its localStorage key.
203
+ * @internal
204
+ */
205
+ _deleteFileFromStorage(path) {
206
+ const storageKey = this._getStorageKeyForPath(path);
207
+ if (!storageKey) {
208
+ return;
209
+ }
210
+ const collectionId = this._getCollectionIdFromPath(path);
211
+ const existingJson = this._storage.getItem(storageKey);
212
+ if (!existingJson) {
213
+ return;
214
+ }
215
+ try {
216
+ const parsed = JSON.parse(existingJson);
217
+ if ((0, ts_json_base_2.isJsonObject)(parsed)) {
218
+ const existing = parsed;
219
+ delete existing[collectionId];
220
+ if (Object.keys(existing).length > 0) {
221
+ this._storage.setItem(storageKey, JSON.stringify(existing));
222
+ }
223
+ else {
224
+ this._storage.removeItem(storageKey);
225
+ }
226
+ }
227
+ }
228
+ catch (_a) {
229
+ // Storage is corrupted — nothing to clean up
230
+ }
231
+ }
232
+ /**
233
+ * Sync a single dirty file to localStorage.
234
+ * @internal
235
+ */
236
+ _syncFile(path) {
237
+ const storageKey = this._getStorageKeyForPath(path);
238
+ if (!storageKey) {
239
+ return (0, ts_utils_1.fail)(`No storage key configured for path: ${path}`);
240
+ }
241
+ const collectionId = this._getCollectionIdFromPath(path);
242
+ const contentsResult = this.getFileContents(path);
243
+ if (contentsResult.isFailure()) {
244
+ return (0, ts_utils_1.fail)(`Failed to get file contents for ${path}: ${contentsResult.message}`);
245
+ }
246
+ try {
247
+ const contents = contentsResult.value;
248
+ // Load existing data from storage
249
+ const existingJson = this._storage.getItem(storageKey);
250
+ let existing = {};
251
+ if (existingJson) {
252
+ try {
253
+ const parsed = JSON.parse(existingJson);
254
+ if ((0, ts_json_base_2.isJsonObject)(parsed)) {
255
+ existing = parsed;
256
+ }
257
+ }
258
+ catch (_a) {
259
+ // Start fresh if corrupted
260
+ }
261
+ }
262
+ // Store raw content string (content-agnostic: JSON, YAML, etc.)
263
+ existing[collectionId] = contents;
264
+ this._storage.setItem(storageKey, JSON.stringify(existing));
265
+ return (0, ts_utils_1.succeed)(undefined);
266
+ /* c8 ignore next 4 - defensive: only triggers on storage quota or similar runtime errors */
267
+ }
268
+ catch (error) {
269
+ const message = error instanceof Error ? error.message : String(error);
270
+ return (0, ts_utils_1.fail)(`Failed to sync file ${path}: ${message}`);
271
+ }
272
+ }
273
+ /**
274
+ * Sync all dirty files to localStorage.
275
+ * @returns Result indicating success or failure
276
+ * @public
277
+ */
278
+ async syncToDisk() {
279
+ if (this._dirtyFiles.size === 0) {
280
+ return (0, ts_utils_1.succeed)(undefined);
281
+ }
282
+ const errors = [];
283
+ for (const path of this._dirtyFiles) {
284
+ const result = this._syncFile(path);
285
+ if (result.isFailure()) {
286
+ errors.push(result.message);
287
+ }
288
+ }
289
+ if (errors.length > 0) {
290
+ return (0, ts_utils_1.fail)(`Failed to sync ${errors.length} file(s): ${errors.join('; ')}`);
291
+ }
292
+ this._dirtyFiles.clear();
293
+ return (0, ts_utils_1.succeed)(undefined);
294
+ }
295
+ /**
296
+ * Check if there are unsaved changes.
297
+ * @returns True if there are dirty files
298
+ * @public
299
+ */
300
+ isDirty() {
301
+ return this._dirtyFiles.size > 0;
302
+ }
303
+ /**
304
+ * Get list of file paths with unsaved changes.
305
+ * @returns Array of dirty file paths
306
+ * @public
307
+ */
308
+ getDirtyPaths() {
309
+ return Array.from(this._dirtyFiles);
310
+ }
311
+ /**
312
+ * Delete a file and remove it from localStorage.
313
+ * @param path - File path to delete
314
+ * @returns Result with true if deleted, or error
315
+ * @public
316
+ */
317
+ deleteFile(path) {
318
+ const result = super.deleteFile(path);
319
+ if (result.isSuccess()) {
320
+ this._dirtyFiles.delete(path);
321
+ this._deleteFileFromStorage(path);
322
+ }
323
+ return result;
324
+ }
325
+ /**
326
+ * Save file contents. Marks file as dirty and optionally auto-syncs.
327
+ * @param path - File path
328
+ * @param contents - New file contents
329
+ * @returns Result with the saved contents or error
330
+ * @public
331
+ */
332
+ saveFileContents(path, contents) {
333
+ const result = super.saveFileContents(path, contents);
334
+ if (result.isSuccess()) {
335
+ this._dirtyFiles.add(path);
336
+ if (this._autoSync) {
337
+ const syncResult = this._syncFile(path);
338
+ if (syncResult.isSuccess()) {
339
+ this._dirtyFiles.delete(path);
340
+ }
341
+ else {
342
+ return (0, ts_utils_1.fail)(syncResult.message);
343
+ }
344
+ }
345
+ }
346
+ return result;
347
+ }
348
+ /**
349
+ * Check if a file is mutable and return persistence detail.
350
+ * @param path - File path to check
351
+ * @returns DetailedResult with mutability status and 'persistent' detail if mutable
352
+ * @public
353
+ */
354
+ fileIsMutable(path) {
355
+ const baseResult = super.fileIsMutable(path);
356
+ if (baseResult.isSuccess() && baseResult.value === true) {
357
+ return (0, ts_utils_1.succeedWithDetail)(true, 'persistent');
358
+ }
359
+ return baseResult;
360
+ }
361
+ }
362
+ exports.LocalStorageTreeAccessors = LocalStorageTreeAccessors;
363
+ //# sourceMappingURL=localStorageTreeAccessors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localStorageTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/localStorageTreeAccessors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAyF;AACzF,oDAA6C;AAC7C,oDAAkE;AA4BlE;;;;;;;;;;;;;GAaG;AACH,MAAa,yBACX,SAAQ,uBAAQ,CAAC,qBAA0B;IAS3C;;;OAGG;IACH,YACE,KAAoC,EACpC,OAAgB,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C,IAAI,EAAE,YAAY,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AA3WD,8DA2WC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult, fail, Result, succeed, succeedWithDetail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport { isJsonObject, type JsonObject } from '@fgv/ts-json-base';\n\n/**\n * Configuration for LocalStorageTreeAccessors.\n * @public\n */\nexport interface ILocalStorageTreeParams<TCT extends string = string>\n extends FileTree.IFileTreeInitParams<TCT> {\n /**\n * Map of directory path prefixes to localStorage keys.\n * Files under each prefix are stored in the corresponding localStorage key.\n * Example: \\{ '/data/ingredients': 'myapp:ingredients:v1' \\}\n */\n pathToKeyMap: Record<string, string>;\n\n /**\n * Storage instance to use. Defaults to window.localStorage.\n * Can be overridden for testing with mock storage.\n */\n storage?: Storage;\n\n /**\n * If true, automatically sync changes to localStorage on every modification.\n * If false (default), changes are only synced when syncToDisk() is called.\n */\n autoSync?: boolean;\n}\n\n/**\n * Browser localStorage-backed file tree accessors with persistence support.\n *\n * Maps filesystem-like directory paths to localStorage keys, where each key stores\n * multiple collections as a JSON object. This provides a general-purpose implementation\n * for browser-based file tree persistence without requiring File System Access API.\n *\n * Storage format per key: `{ \"collection-id\": \"<raw file content>\" }`\n * File paths map as: `/data/ingredients/collection-id.yaml` → stored in key for `/data/ingredients`\n *\n * Legacy format (v1): `{ \"collection-id\": { ...parsedJsonObject } }` is auto-migrated on load.\n *\n * @public\n */\nexport class LocalStorageTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _storage: Storage;\n private readonly _pathToKeyMap: Map<string, string>;\n private readonly _keyToPathMap: Map<string, string>;\n private readonly _dirtyFiles: Set<string>;\n private readonly _autoSync: boolean;\n\n /**\n * Private constructor. Use fromStorage() factory method instead.\n * @internal\n */\n private constructor(\n files: FileTree.IInMemoryFile<TCT>[],\n storage: Storage,\n pathToKeyMap: Map<string, string>,\n params?: ILocalStorageTreeParams<TCT>\n ) {\n super(files, params);\n this._storage = storage;\n this._pathToKeyMap = pathToKeyMap;\n this._keyToPathMap = new Map(Array.from(pathToKeyMap.entries()).map(([k, v]) => [v, k]));\n this._dirtyFiles = new Set();\n /* c8 ignore next 1 - intermittent branch coverage: ?? false branch when params is undefined */\n this._autoSync = params?.autoSync ?? false;\n }\n\n /**\n * Create LocalStorageTreeAccessors from browser localStorage.\n * Loads all collections from the configured storage keys.\n *\n * @param params - Configuration including path-to-key mappings\n * @returns Result containing the accessors or an error\n * @public\n */\n public static fromStorage<TCT extends string = string>(\n params: ILocalStorageTreeParams<TCT>\n ): Result<LocalStorageTreeAccessors<TCT>> {\n try {\n /* c8 ignore next 1 - intermittent branch coverage: window.localStorage branch when params.storage is undefined */\n const storage = params.storage ?? (typeof window !== 'undefined' ? window.localStorage : undefined);\n if (!storage) {\n return fail('localStorage is not available');\n }\n\n const pathToKeyMap = new Map(Object.entries(params.pathToKeyMap));\n const files = this._loadFromStorage<TCT>(storage, pathToKeyMap, params);\n\n return succeed(new LocalStorageTreeAccessors<TCT>(files, storage, pathToKeyMap, params));\n /* c8 ignore next 4 - defensive: outer catch for unexpected errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create LocalStorageTreeAccessors: ${message}`);\n }\n }\n\n /**\n * Load all files from localStorage based on path-to-key mappings.\n * @internal\n */\n private static _loadFromStorage<TCT extends string = string>(\n storage: Storage,\n pathToKeyMap: Map<string, string>,\n params?: ILocalStorageTreeParams<TCT>\n ): FileTree.IInMemoryFile<TCT>[] {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const [dataPath, storageKey] of pathToKeyMap.entries()) {\n const rawJson = storage.getItem(storageKey);\n if (!rawJson) {\n continue;\n }\n\n try {\n const parsed: unknown = JSON.parse(rawJson);\n if (!isJsonObject(parsed)) {\n continue;\n }\n\n for (const [collectionId, contents] of Object.entries(parsed)) {\n // Support both new format (string values) and legacy format (JsonObject values)\n let rawContent: string;\n let extension: string;\n if (typeof contents === 'string') {\n rawContent = contents;\n // Infer extension: if content looks like JSON, use .json; otherwise .yaml\n extension = this._looksLikeJson(contents) ? '.json' : '.yaml';\n } else if (isJsonObject(contents)) {\n // Legacy format: migrate by stringifying\n rawContent = JSON.stringify(contents);\n extension = '.json';\n } else {\n continue;\n }\n\n const filePath = this._joinPath(dataPath, `${collectionId}${extension}`);\n /* c8 ignore next 3 - intermittent branch coverage: ternary branches in tight loop */\n const contentType = params?.inferContentType\n ? params.inferContentType(filePath, undefined).orDefault()\n : undefined;\n\n files.push({\n path: filePath,\n contents: rawContent,\n contentType\n });\n }\n } catch {\n // Skip corrupted data\n continue;\n }\n }\n\n return files;\n }\n\n /**\n * Heuristic check: does the content look like JSON?\n * @internal\n */\n private static _looksLikeJson(content: string): boolean {\n const trimmed = content.trimStart();\n return trimmed.startsWith('{') || trimmed.startsWith('[');\n }\n\n /**\n * Join path components, handling leading/trailing slashes.\n * @internal\n */\n private static _joinPath(base: string, name: string): string {\n /* c8 ignore next 2 - intermittent branch coverage: slash-trimming edge cases */\n const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;\n const cleanName = name.startsWith('/') ? name.slice(1) : name;\n return `${cleanBase}/${cleanName}`;\n }\n\n /**\n * Get the storage key for a given file path.\n * @internal\n */\n private _getStorageKeyForPath(path: string): string | undefined {\n // Find the longest matching prefix\n let bestMatch: { prefix: string; key: string } | undefined;\n for (const [prefix, key] of this._pathToKeyMap.entries()) {\n if (path.startsWith(prefix)) {\n /* c8 ignore next 1 - intermittent: overlapping-prefix branch requires two matching prefixes in iteration order */\n if (!bestMatch || prefix.length > bestMatch.prefix.length) {\n bestMatch = { prefix, key };\n }\n }\n }\n return bestMatch?.key;\n }\n\n /**\n * Get the data path prefix for a given file path.\n * @internal\n */\n private _getDataPathForPath(path: string): string | undefined {\n for (const prefix of this._pathToKeyMap.keys()) {\n if (path.startsWith(prefix)) {\n return prefix;\n }\n }\n /* c8 ignore next 2 - coverage intermittently missed in full suite */\n return undefined;\n }\n\n /**\n * Extract collection ID from a file path.\n * Example: '/data/ingredients/my-collection.yaml' → 'my-collection'\n * @internal\n */\n private _getCollectionIdFromPath(path: string): string {\n const dataPath = this._getDataPathForPath(path);\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!dataPath) {\n return path;\n }\n\n const relativePath = path.slice(dataPath.length);\n /* c8 ignore next 1 - defensive: relativePath always starts with / when paths are absolute */\n const cleanPath = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;\n\n // Remove any file extension\n const dotIndex = cleanPath.lastIndexOf('.');\n return dotIndex > 0 ? cleanPath.slice(0, dotIndex) : cleanPath;\n }\n\n /**\n * Remove a file's entry from its localStorage key.\n * @internal\n */\n private _deleteFileFromStorage(path: string): void {\n const storageKey = this._getStorageKeyForPath(path);\n if (!storageKey) {\n return;\n }\n\n const collectionId = this._getCollectionIdFromPath(path);\n const existingJson = this._storage.getItem(storageKey);\n if (!existingJson) {\n return;\n }\n\n try {\n const parsed = JSON.parse(existingJson);\n if (isJsonObject(parsed)) {\n const existing = parsed as Record<string, unknown>;\n delete existing[collectionId];\n if (Object.keys(existing).length > 0) {\n this._storage.setItem(storageKey, JSON.stringify(existing));\n } else {\n this._storage.removeItem(storageKey);\n }\n }\n } catch {\n // Storage is corrupted — nothing to clean up\n }\n }\n\n /**\n * Sync a single dirty file to localStorage.\n * @internal\n */\n private _syncFile(path: string): Result<void> {\n const storageKey = this._getStorageKeyForPath(path);\n if (!storageKey) {\n return fail(`No storage key configured for path: ${path}`);\n }\n\n const collectionId = this._getCollectionIdFromPath(path);\n const contentsResult = this.getFileContents(path);\n if (contentsResult.isFailure()) {\n return fail(`Failed to get file contents for ${path}: ${contentsResult.message}`);\n }\n\n try {\n const contents = contentsResult.value;\n\n // Load existing data from storage\n const existingJson = this._storage.getItem(storageKey);\n let existing: Record<string, unknown> = {};\n if (existingJson) {\n try {\n const parsed = JSON.parse(existingJson);\n if (isJsonObject(parsed)) {\n existing = parsed as Record<string, unknown>;\n }\n } catch {\n // Start fresh if corrupted\n }\n }\n\n // Store raw content string (content-agnostic: JSON, YAML, etc.)\n existing[collectionId] = contents;\n this._storage.setItem(storageKey, JSON.stringify(existing));\n\n return succeed(undefined);\n /* c8 ignore next 4 - defensive: only triggers on storage quota or similar runtime errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to sync file ${path}: ${message}`);\n }\n }\n\n /**\n * Sync all dirty files to localStorage.\n * @returns Result indicating success or failure\n * @public\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (this._dirtyFiles.size === 0) {\n return succeed(undefined);\n }\n\n const errors: string[] = [];\n for (const path of this._dirtyFiles) {\n const result = this._syncFile(path);\n if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n return fail(`Failed to sync ${errors.length} file(s): ${errors.join('; ')}`);\n }\n\n this._dirtyFiles.clear();\n return succeed(undefined);\n }\n\n /**\n * Check if there are unsaved changes.\n * @returns True if there are dirty files\n * @public\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0;\n }\n\n /**\n * Get list of file paths with unsaved changes.\n * @returns Array of dirty file paths\n * @public\n */\n public getDirtyPaths(): string[] {\n return Array.from(this._dirtyFiles);\n }\n\n /**\n * Delete a file and remove it from localStorage.\n * @param path - File path to delete\n * @returns Result with true if deleted, or error\n * @public\n */\n public deleteFile(path: string): Result<boolean> {\n const result = super.deleteFile(path);\n if (result.isSuccess()) {\n this._dirtyFiles.delete(path);\n this._deleteFileFromStorage(path);\n }\n return result;\n }\n\n /**\n * Save file contents. Marks file as dirty and optionally auto-syncs.\n * @param path - File path\n * @param contents - New file contents\n * @returns Result with the saved contents or error\n * @public\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n const result = super.saveFileContents(path, contents);\n if (result.isSuccess()) {\n this._dirtyFiles.add(path);\n if (this._autoSync) {\n const syncResult = this._syncFile(path);\n if (syncResult.isSuccess()) {\n this._dirtyFiles.delete(path);\n } else {\n return fail(syncResult.message);\n }\n }\n }\n return result;\n }\n\n /**\n * Check if a file is mutable and return persistence detail.\n * @param path - File path to check\n * @returns DetailedResult with mutability status and 'persistent' detail if mutable\n * @public\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const baseResult = super.fileIsMutable(path);\n if (baseResult.isSuccess() && baseResult.value === true) {\n return succeedWithDetail(true, 'persistent');\n }\n return baseResult;\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const createStore: jest.Mock<{}, [], any>;
2
+ export declare const get: jest.Mock<any, any, any>;
3
+ export declare const set: jest.Mock<any, any, any>;
4
+ export declare const del: jest.Mock<any, any, any>;
5
+ export declare const keys: jest.Mock<any, any, any>;
6
+ //# sourceMappingURL=idb-keyval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idb-keyval.d.ts","sourceRoot":"","sources":["../../../src/test/mocks/idb-keyval.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,wBAAsB,CAAC;AAC/C,eAAO,MAAM,GAAG,0BAAY,CAAC;AAC7B,eAAO,MAAM,GAAG,0BAAY,CAAC;AAC7B,eAAO,MAAM,GAAG,0BAAY,CAAC;AAC7B,eAAO,MAAM,IAAI,0BAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keys = exports.del = exports.set = exports.get = exports.createStore = void 0;
4
+ exports.createStore = jest.fn(() => ({}));
5
+ exports.get = jest.fn();
6
+ exports.set = jest.fn();
7
+ exports.del = jest.fn();
8
+ exports.keys = jest.fn();
9
+ //# sourceMappingURL=idb-keyval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idb-keyval.js","sourceRoot":"","sources":["../../../src/test/mocks/idb-keyval.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAClC,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChB,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChB,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChB,QAAA,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC","sourcesContent":["export const createStore = jest.fn(() => ({}));\nexport const get = jest.fn();\nexport const set = jest.fn();\nexport const del = jest.fn();\nexport const keys = jest.fn();\n"]}
@@ -22,40 +22,40 @@
22
22
  */
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  require("@fgv/ts-utils-jest");
25
- const crypto_1 = require("../../packlets/crypto");
25
+ const crypto_utils_1 = require("../../packlets/crypto-utils");
26
26
  describe('BrowserHashProvider', () => {
27
27
  describe('hashString', () => {
28
28
  test('successfully hashes a string with SHA-256', async () => {
29
- const result = await crypto_1.BrowserHashProvider.hashString('test data', 'SHA-256');
29
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('test data', 'SHA-256');
30
30
  expect(result).toSucceedAndSatisfy((hash) => {
31
31
  expect(typeof hash).toBe('string');
32
32
  expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters
33
33
  });
34
34
  });
35
35
  test('successfully hashes a string with SHA-1', async () => {
36
- const result = await crypto_1.BrowserHashProvider.hashString('test data', 'SHA-1');
36
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('test data', 'SHA-1');
37
37
  expect(result).toSucceedAndSatisfy((hash) => {
38
38
  expect(typeof hash).toBe('string');
39
39
  expect(hash).toMatch(/^[a-f0-9]{40}$/); // SHA-1 produces 40 hex characters
40
40
  });
41
41
  });
42
42
  test('successfully hashes a string with SHA-512', async () => {
43
- const result = await crypto_1.BrowserHashProvider.hashString('test data', 'SHA-512');
43
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('test data', 'SHA-512');
44
44
  expect(result).toSucceedAndSatisfy((hash) => {
45
45
  expect(typeof hash).toBe('string');
46
46
  expect(hash).toMatch(/^[a-f0-9]{128}$/); // SHA-512 produces 128 hex characters
47
47
  });
48
48
  });
49
49
  test('uses SHA-256 as default algorithm', async () => {
50
- const result = await crypto_1.BrowserHashProvider.hashString('test data');
50
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('test data');
51
51
  expect(result).toSucceedAndSatisfy((hash) => {
52
52
  expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters
53
53
  });
54
54
  });
55
55
  test('produces consistent hash for same input', async () => {
56
56
  const input = 'consistent input';
57
- const result1 = await crypto_1.BrowserHashProvider.hashString(input);
58
- const result2 = await crypto_1.BrowserHashProvider.hashString(input);
57
+ const result1 = await crypto_utils_1.BrowserHashProvider.hashString(input);
58
+ const result2 = await crypto_utils_1.BrowserHashProvider.hashString(input);
59
59
  expect(result1).toSucceed();
60
60
  expect(result2).toSucceed();
61
61
  if (result1.isSuccess() && result2.isSuccess()) {
@@ -63,8 +63,8 @@ describe('BrowserHashProvider', () => {
63
63
  }
64
64
  });
65
65
  test('produces different hashes for different inputs', async () => {
66
- const result1 = await crypto_1.BrowserHashProvider.hashString('input1');
67
- const result2 = await crypto_1.BrowserHashProvider.hashString('input2');
66
+ const result1 = await crypto_utils_1.BrowserHashProvider.hashString('input1');
67
+ const result2 = await crypto_utils_1.BrowserHashProvider.hashString('input2');
68
68
  expect(result1).toSucceed();
69
69
  expect(result2).toSucceed();
70
70
  if (result1.isSuccess() && result2.isSuccess()) {
@@ -72,11 +72,11 @@ describe('BrowserHashProvider', () => {
72
72
  }
73
73
  });
74
74
  test('handles empty string input', async () => {
75
- const result = await crypto_1.BrowserHashProvider.hashString('');
75
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('');
76
76
  expect(result).toSucceed();
77
77
  });
78
78
  test('handles unicode input', async () => {
79
- const result = await crypto_1.BrowserHashProvider.hashString('🚀 Unicode test 测试');
79
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('🚀 Unicode test 测试');
80
80
  expect(result).toSucceedAndSatisfy((hash) => {
81
81
  expect(hash).toMatch(/^[a-f0-9]{64}$/);
82
82
  });
@@ -85,27 +85,27 @@ describe('BrowserHashProvider', () => {
85
85
  const originalCrypto = global.crypto;
86
86
  // @ts-ignore - Intentionally removing crypto for test
87
87
  delete global.crypto;
88
- const result = await crypto_1.BrowserHashProvider.hashString('test');
88
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('test');
89
89
  expect(result).toFailWith(/Hash computation failed/);
90
90
  global.crypto = originalCrypto;
91
91
  });
92
92
  test('handles invalid algorithm gracefully', async () => {
93
- const result = await crypto_1.BrowserHashProvider.hashString('test', 'INVALID-ALG');
93
+ const result = await crypto_utils_1.BrowserHashProvider.hashString('test', 'INVALID-ALG');
94
94
  expect(result).toFailWith(/Hash computation failed/);
95
95
  });
96
96
  });
97
97
  describe('hashParts', () => {
98
98
  test('hashes multiple parts with default separator', async () => {
99
99
  const parts = ['part1', 'part2', 'part3'];
100
- const result = await crypto_1.BrowserHashProvider.hashParts(parts);
100
+ const result = await crypto_utils_1.BrowserHashProvider.hashParts(parts);
101
101
  expect(result).toSucceedAndSatisfy((hash) => {
102
102
  expect(hash).toMatch(/^[a-f0-9]{64}$/);
103
103
  });
104
104
  });
105
105
  test('hashes multiple parts with custom separator', async () => {
106
106
  const parts = ['part1', 'part2', 'part3'];
107
- const result1 = await crypto_1.BrowserHashProvider.hashParts(parts, 'SHA-256', '|');
108
- const result2 = await crypto_1.BrowserHashProvider.hashParts(parts, 'SHA-256', ',');
107
+ const result1 = await crypto_utils_1.BrowserHashProvider.hashParts(parts, 'SHA-256', '|');
108
+ const result2 = await crypto_utils_1.BrowserHashProvider.hashParts(parts, 'SHA-256', ',');
109
109
  expect(result1).toSucceed();
110
110
  expect(result2).toSucceed();
111
111
  if (result1.isSuccess() && result2.isSuccess()) {
@@ -116,8 +116,8 @@ describe('BrowserHashProvider', () => {
116
116
  const parts = ['a', 'b', 'c'];
117
117
  const separator = '-';
118
118
  const joined = parts.join(separator);
119
- const partsResult = await crypto_1.BrowserHashProvider.hashParts(parts, 'SHA-256', separator);
120
- const stringResult = await crypto_1.BrowserHashProvider.hashString(joined);
119
+ const partsResult = await crypto_utils_1.BrowserHashProvider.hashParts(parts, 'SHA-256', separator);
120
+ const stringResult = await crypto_utils_1.BrowserHashProvider.hashString(joined);
121
121
  expect(partsResult).toSucceed();
122
122
  expect(stringResult).toSucceed();
123
123
  if (partsResult.isSuccess() && stringResult.isSuccess()) {
@@ -125,12 +125,12 @@ describe('BrowserHashProvider', () => {
125
125
  }
126
126
  });
127
127
  test('handles empty array', async () => {
128
- const result = await crypto_1.BrowserHashProvider.hashParts([]);
128
+ const result = await crypto_utils_1.BrowserHashProvider.hashParts([]);
129
129
  expect(result).toSucceed();
130
130
  });
131
131
  test('handles single part', async () => {
132
- const result = await crypto_1.BrowserHashProvider.hashParts(['single']);
133
- const stringResult = await crypto_1.BrowserHashProvider.hashString('single');
132
+ const result = await crypto_utils_1.BrowserHashProvider.hashParts(['single']);
133
+ const stringResult = await crypto_utils_1.BrowserHashProvider.hashString('single');
134
134
  expect(result).toSucceed();
135
135
  expect(stringResult).toSucceed();
136
136
  if (result.isSuccess() && stringResult.isSuccess()) {
@@ -1 +1 @@
1
- {"version":3,"file":"browserHashProvider.test.js","sourceRoot":"","sources":["../../../src/test/unit/browserHashProvider.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAEH,8BAA4B;AAC5B,kDAA4D;AAE5D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,IAAI,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,MAAM,GAAG,MAAM,4BAAmB,CAAC,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YAC5E,MAAM,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC1C,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACnC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,qCAAqC;YAC/E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACzD,MAAM,MAAM,GAAG,MAAM,4BAAmB,CAAC,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC1C,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,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AAC;QAEH,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;YACrC,MAAM,MAAM,GAAG,MAAM,4BAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACvD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;YACrC,MAAM,MAAM,GAAG,MAAM,4BAAmB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/D,MAAM,YAAY,GAAG,MAAM,4BAAmB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACpE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;YAC3B,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC;gBACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport '@fgv/ts-utils-jest';\nimport { BrowserHashProvider } from '../../packlets/crypto';\n\ndescribe('BrowserHashProvider', () => {\n describe('hashString', () => {\n test('successfully hashes a string with SHA-256', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-256');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters\n });\n });\n\n test('successfully hashes a string with SHA-1', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-1');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{40}$/); // SHA-1 produces 40 hex characters\n });\n });\n\n test('successfully hashes a string with SHA-512', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-512');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{128}$/); // SHA-512 produces 128 hex characters\n });\n });\n\n test('uses SHA-256 as default algorithm', async () => {\n const result = await BrowserHashProvider.hashString('test data');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters\n });\n });\n\n test('produces consistent hash for same input', async () => {\n const input = 'consistent input';\n const result1 = await BrowserHashProvider.hashString(input);\n const result2 = await BrowserHashProvider.hashString(input);\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).toBe(result2.value);\n }\n });\n\n test('produces different hashes for different inputs', async () => {\n const result1 = await BrowserHashProvider.hashString('input1');\n const result2 = await BrowserHashProvider.hashString('input2');\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).not.toBe(result2.value);\n }\n });\n\n test('handles empty string input', async () => {\n const result = await BrowserHashProvider.hashString('');\n expect(result).toSucceed();\n });\n\n test('handles unicode input', async () => {\n const result = await BrowserHashProvider.hashString('🚀 Unicode test 测试');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n test('fails when crypto.subtle is unavailable', async () => {\n const originalCrypto = global.crypto;\n // @ts-ignore - Intentionally removing crypto for test\n delete global.crypto;\n const result = await BrowserHashProvider.hashString('test');\n expect(result).toFailWith(/Hash computation failed/);\n global.crypto = originalCrypto;\n });\n\n test('handles invalid algorithm gracefully', async () => {\n const result = await BrowserHashProvider.hashString('test', 'INVALID-ALG');\n expect(result).toFailWith(/Hash computation failed/);\n });\n });\n\n describe('hashParts', () => {\n test('hashes multiple parts with default separator', async () => {\n const parts = ['part1', 'part2', 'part3'];\n const result = await BrowserHashProvider.hashParts(parts);\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n test('hashes multiple parts with custom separator', async () => {\n const parts = ['part1', 'part2', 'part3'];\n const result1 = await BrowserHashProvider.hashParts(parts, 'SHA-256', '|');\n const result2 = await BrowserHashProvider.hashParts(parts, 'SHA-256', ',');\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).not.toBe(result2.value);\n }\n });\n\n test('produces same hash as hashString for joined parts', async () => {\n const parts = ['a', 'b', 'c'];\n const separator = '-';\n const joined = parts.join(separator);\n const partsResult = await BrowserHashProvider.hashParts(parts, 'SHA-256', separator);\n const stringResult = await BrowserHashProvider.hashString(joined);\n expect(partsResult).toSucceed();\n expect(stringResult).toSucceed();\n if (partsResult.isSuccess() && stringResult.isSuccess()) {\n expect(partsResult.value).toBe(stringResult.value);\n }\n });\n\n test('handles empty array', async () => {\n const result = await BrowserHashProvider.hashParts([]);\n expect(result).toSucceed();\n });\n\n test('handles single part', async () => {\n const result = await BrowserHashProvider.hashParts(['single']);\n const stringResult = await BrowserHashProvider.hashString('single');\n expect(result).toSucceed();\n expect(stringResult).toSucceed();\n if (result.isSuccess() && stringResult.isSuccess()) {\n expect(result.value).toBe(stringResult.value);\n }\n });\n });\n});\n"]}
1
+ {"version":3,"file":"browserHashProvider.test.js","sourceRoot":"","sources":["../../../src/test/unit/browserHashProvider.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAEH,8BAA4B;AAC5B,8DAAkE;AAElE,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,IAAI,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,MAAM,GAAG,MAAM,kCAAmB,CAAC,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YAC5E,MAAM,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC1C,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACnC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,qCAAqC;YAC/E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACzD,MAAM,MAAM,GAAG,MAAM,kCAAmB,CAAC,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC1C,MAAM,CAAC,OAAO,IA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AAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;YACrC,MAAM,MAAM,GAAG,MAAM,kCAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACvD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;YACrC,MAAM,MAAM,GAAG,MAAM,kCAAmB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/D,MAAM,YAAY,GAAG,MAAM,kCAAmB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACpE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;YAC3B,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC;gBACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport '@fgv/ts-utils-jest';\nimport { BrowserHashProvider } from '../../packlets/crypto-utils';\n\ndescribe('BrowserHashProvider', () => {\n describe('hashString', () => {\n test('successfully hashes a string with SHA-256', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-256');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters\n });\n });\n\n test('successfully hashes a string with SHA-1', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-1');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{40}$/); // SHA-1 produces 40 hex characters\n });\n });\n\n test('successfully hashes a string with SHA-512', async () => {\n const result = await BrowserHashProvider.hashString('test data', 'SHA-512');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(typeof hash).toBe('string');\n expect(hash).toMatch(/^[a-f0-9]{128}$/); // SHA-512 produces 128 hex characters\n });\n });\n\n test('uses SHA-256 as default algorithm', async () => {\n const result = await BrowserHashProvider.hashString('test data');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/); // SHA-256 produces 64 hex characters\n });\n });\n\n test('produces consistent hash for same input', async () => {\n const input = 'consistent input';\n const result1 = await BrowserHashProvider.hashString(input);\n const result2 = await BrowserHashProvider.hashString(input);\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).toBe(result2.value);\n }\n });\n\n test('produces different hashes for different inputs', async () => {\n const result1 = await BrowserHashProvider.hashString('input1');\n const result2 = await BrowserHashProvider.hashString('input2');\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).not.toBe(result2.value);\n }\n });\n\n test('handles empty string input', async () => {\n const result = await BrowserHashProvider.hashString('');\n expect(result).toSucceed();\n });\n\n test('handles unicode input', async () => {\n const result = await BrowserHashProvider.hashString('🚀 Unicode test 测试');\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n test('fails when crypto.subtle is unavailable', async () => {\n const originalCrypto = global.crypto;\n // @ts-ignore - Intentionally removing crypto for test\n delete global.crypto;\n const result = await BrowserHashProvider.hashString('test');\n expect(result).toFailWith(/Hash computation failed/);\n global.crypto = originalCrypto;\n });\n\n test('handles invalid algorithm gracefully', async () => {\n const result = await BrowserHashProvider.hashString('test', 'INVALID-ALG');\n expect(result).toFailWith(/Hash computation failed/);\n });\n });\n\n describe('hashParts', () => {\n test('hashes multiple parts with default separator', async () => {\n const parts = ['part1', 'part2', 'part3'];\n const result = await BrowserHashProvider.hashParts(parts);\n expect(result).toSucceedAndSatisfy((hash) => {\n expect(hash).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n test('hashes multiple parts with custom separator', async () => {\n const parts = ['part1', 'part2', 'part3'];\n const result1 = await BrowserHashProvider.hashParts(parts, 'SHA-256', '|');\n const result2 = await BrowserHashProvider.hashParts(parts, 'SHA-256', ',');\n expect(result1).toSucceed();\n expect(result2).toSucceed();\n if (result1.isSuccess() && result2.isSuccess()) {\n expect(result1.value).not.toBe(result2.value);\n }\n });\n\n test('produces same hash as hashString for joined parts', async () => {\n const parts = ['a', 'b', 'c'];\n const separator = '-';\n const joined = parts.join(separator);\n const partsResult = await BrowserHashProvider.hashParts(parts, 'SHA-256', separator);\n const stringResult = await BrowserHashProvider.hashString(joined);\n expect(partsResult).toSucceed();\n expect(stringResult).toSucceed();\n if (partsResult.isSuccess() && stringResult.isSuccess()) {\n expect(partsResult.value).toBe(stringResult.value);\n }\n });\n\n test('handles empty array', async () => {\n const result = await BrowserHashProvider.hashParts([]);\n expect(result).toSucceed();\n });\n\n test('handles single part', async () => {\n const result = await BrowserHashProvider.hashParts(['single']);\n const stringResult = await BrowserHashProvider.hashString('single');\n expect(result).toSucceed();\n expect(stringResult).toSucceed();\n if (result.isSuccess() && stringResult.isSuccess()) {\n expect(result.value).toBe(stringResult.value);\n }\n });\n });\n});\n"]}
@@ -0,0 +1,2 @@
1
+ import '@fgv/ts-utils-jest';
2
+ //# sourceMappingURL=directoryHandleStore.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directoryHandleStore.test.d.ts","sourceRoot":"","sources":["../../../src/test/unit/directoryHandleStore.test.ts"],"names":[],"mappings":"AAsBA,OAAO,oBAAoB,CAAC"}