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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +56 -33
  2. package/.rush/temp/chunked-rush-logs/ts-web-extras.test.chunks.jsonl +75 -0
  3. package/.rush/temp/operation/build/all.log +56 -33
  4. package/.rush/temp/operation/build/error.log +18 -0
  5. package/.rush/temp/operation/build/log-chunks.jsonl +56 -33
  6. package/.rush/temp/operation/build/state.json +1 -1
  7. package/.rush/temp/operation/test/all.log +75 -0
  8. package/.rush/temp/operation/test/error.log +18 -0
  9. package/.rush/temp/operation/test/log-chunks.jsonl +75 -0
  10. package/.rush/temp/operation/test/state.json +3 -0
  11. package/dist/packlets/file-tree/fileApiTreeAccessors.js +15 -0
  12. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  13. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +79 -10
  14. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  15. package/dist/packlets/file-tree/httpTreeAccessors.js +336 -0
  16. package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  17. package/dist/packlets/file-tree/index.js +1 -0
  18. package/dist/packlets/file-tree/index.js.map +1 -1
  19. package/dist/packlets/file-tree/localStorageTreeAccessors.js +51 -0
  20. package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  21. package/dist/test/unit/fileApiTreeAccessors.test.js +51 -0
  22. package/dist/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  23. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +265 -160
  24. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -1
  25. package/dist/test/unit/httpTreeAccessors.test.js +1229 -0
  26. package/dist/test/unit/httpTreeAccessors.test.js.map +1 -0
  27. package/dist/test/unit/localStorageTreeAccessors.test.js +218 -1
  28. package/dist/test/unit/localStorageTreeAccessors.test.js.map +1 -1
  29. package/dist/ts-web-extras.d.ts +138 -0
  30. package/docs/@fgv/namespaces/CryptoUtils/README.md +18 -0
  31. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserCryptoProvider.md +203 -0
  32. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserHashProvider.md +63 -0
  33. package/docs/@fgv/namespaces/CryptoUtils/functions/createBrowserCryptoProvider.md +18 -0
  34. package/docs/@fgv/namespaces/FileTreeHelpers/README.md +19 -0
  35. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileListMetadata.md +23 -0
  36. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileMetadata.md +23 -0
  37. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromDirectoryUpload.md +33 -0
  38. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromFileList.md +33 -0
  39. package/docs/@fgv/namespaces/FileTreeHelpers/functions/getOriginalFile.md +25 -0
  40. package/docs/@fgv/namespaces/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +11 -0
  41. package/docs/README.md +78 -0
  42. package/docs/classes/DirectoryHandleStore.md +116 -0
  43. package/docs/classes/FileApiTreeAccessors.md +286 -0
  44. package/docs/classes/FileSystemAccessTreeAccessors.md +557 -0
  45. package/docs/classes/HttpTreeAccessors.md +508 -0
  46. package/docs/classes/LocalStorageTreeAccessors.md +520 -0
  47. package/docs/functions/exportAsJson.md +23 -0
  48. package/docs/functions/exportUsingFileSystemAPI.md +26 -0
  49. package/docs/functions/extractDirectoryPath.md +23 -0
  50. package/docs/functions/isDirectoryHandle.md +23 -0
  51. package/docs/functions/isFileHandle.md +23 -0
  52. package/docs/functions/isFilePath.md +21 -0
  53. package/docs/functions/parseContextFilter.md +22 -0
  54. package/docs/functions/parseQualifierDefaults.md +22 -0
  55. package/docs/functions/parseResourceTypes.md +22 -0
  56. package/docs/functions/parseUrlParameters.md +15 -0
  57. package/docs/functions/safeShowDirectoryPicker.md +24 -0
  58. package/docs/functions/safeShowOpenFilePicker.md +24 -0
  59. package/docs/functions/safeShowSaveFilePicker.md +24 -0
  60. package/docs/functions/supportsFileSystemAccess.md +23 -0
  61. package/docs/interfaces/FilePickerAcceptType.md +16 -0
  62. package/docs/interfaces/FileSystemCreateWritableOptions.md +15 -0
  63. package/docs/interfaces/FileSystemDirectoryHandle.md +187 -0
  64. package/docs/interfaces/FileSystemFileHandle.md +106 -0
  65. package/docs/interfaces/FileSystemGetDirectoryOptions.md +15 -0
  66. package/docs/interfaces/FileSystemGetFileOptions.md +15 -0
  67. package/docs/interfaces/FileSystemHandle.md +69 -0
  68. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +15 -0
  69. package/docs/interfaces/FileSystemRemoveOptions.md +15 -0
  70. package/docs/interfaces/FileSystemWritableFileStream.md +127 -0
  71. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +17 -0
  72. package/docs/interfaces/IFileHandleTreeInitializer.md +16 -0
  73. package/docs/interfaces/IFileListTreeInitializer.md +15 -0
  74. package/docs/interfaces/IFileMetadata.md +19 -0
  75. package/docs/interfaces/IFileSystemAccessTreeParams.md +30 -0
  76. package/docs/interfaces/IFsAccessApis.md +57 -0
  77. package/docs/interfaces/IHttpTreeParams.md +32 -0
  78. package/docs/interfaces/ILocalStorageTreeParams.md +30 -0
  79. package/docs/interfaces/IUrlConfigOptions.md +27 -0
  80. package/docs/interfaces/ShowDirectoryPickerOptions.md +17 -0
  81. package/docs/interfaces/ShowOpenFilePickerOptions.md +19 -0
  82. package/docs/interfaces/ShowSaveFilePickerOptions.md +19 -0
  83. package/docs/type-aliases/TreeInitializer.md +11 -0
  84. package/docs/type-aliases/WellKnownDirectory.md +11 -0
  85. package/docs/type-aliases/WindowWithFsAccess.md +11 -0
  86. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +11 -0
  87. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +11 -0
  88. package/etc/ts-web-extras.api.md +33 -0
  89. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +9 -0
  90. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
  91. package/lib/packlets/file-tree/fileApiTreeAccessors.js +15 -0
  92. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  93. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts +17 -1
  94. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -1
  95. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +78 -9
  96. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  97. package/lib/packlets/file-tree/httpTreeAccessors.d.ts +102 -0
  98. package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -0
  99. package/lib/packlets/file-tree/httpTreeAccessors.js +340 -0
  100. package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -0
  101. package/lib/packlets/file-tree/index.d.ts +1 -0
  102. package/lib/packlets/file-tree/index.d.ts.map +1 -1
  103. package/lib/packlets/file-tree/index.js +1 -0
  104. package/lib/packlets/file-tree/index.js.map +1 -1
  105. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts +12 -0
  106. package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts.map +1 -1
  107. package/lib/packlets/file-tree/localStorageTreeAccessors.js +51 -0
  108. package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  109. package/lib/test/unit/fileApiTreeAccessors.test.js +51 -0
  110. package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -1
  111. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +265 -160
  112. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -1
  113. package/lib/test/unit/httpTreeAccessors.test.d.ts +2 -0
  114. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +1 -0
  115. package/lib/test/unit/httpTreeAccessors.test.js +1231 -0
  116. package/lib/test/unit/httpTreeAccessors.test.js.map +1 -0
  117. package/lib/test/unit/localStorageTreeAccessors.test.js +218 -1
  118. package/lib/test/unit/localStorageTreeAccessors.test.js.map +1 -1
  119. package/package.json +25 -25
  120. package/rush-logs/ts-web-extras.build.cache.log +0 -3
  121. package/rush-logs/ts-web-extras.build.error.log +18 -0
  122. package/rush-logs/ts-web-extras.build.log +56 -33
  123. package/rush-logs/ts-web-extras.test.cache.log +1 -0
  124. package/rush-logs/ts-web-extras.test.error.log +18 -0
  125. package/rush-logs/ts-web-extras.test.log +75 -0
  126. package/src/packlets/file-tree/fileApiTreeAccessors.ts +18 -0
  127. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +100 -8
  128. package/src/packlets/file-tree/httpTreeAccessors.ts +448 -0
  129. package/src/packlets/file-tree/index.ts +1 -0
  130. package/src/packlets/file-tree/localStorageTreeAccessors.ts +53 -0
  131. package/src/test/unit/fileApiTreeAccessors.test.ts +69 -0
  132. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +341 -188
  133. package/src/test/unit/httpTreeAccessors.test.ts +1571 -0
  134. package/src/test/unit/localStorageTreeAccessors.test.ts +269 -1
  135. package/temp/build/typescript/ts_8nwakTlr.json +1 -1
  136. package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
  137. package/temp/coverage/crypto/index.html +116 -0
  138. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +1 -1
  139. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +1 -1
  140. package/temp/coverage/crypto-utils/index.html +1 -1
  141. package/temp/coverage/file-tree/directoryHandleStore.ts.html +1 -1
  142. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +60 -6
  143. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +410 -134
  144. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +1429 -0
  145. package/temp/coverage/file-tree/index.html +35 -20
  146. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +318 -159
  147. package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
  148. package/temp/coverage/helpers/index.html +1 -1
  149. package/temp/coverage/index.html +11 -11
  150. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
  151. package/temp/coverage/lcov-report/crypto/index.html +116 -0
  152. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +1 -1
  153. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +1 -1
  154. package/temp/coverage/lcov-report/crypto-utils/index.html +1 -1
  155. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +1 -1
  156. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +60 -6
  157. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +410 -134
  158. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +1429 -0
  159. package/temp/coverage/lcov-report/file-tree/index.html +35 -20
  160. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +318 -159
  161. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
  162. package/temp/coverage/lcov-report/helpers/index.html +1 -1
  163. package/temp/coverage/lcov-report/index.html +11 -11
  164. package/temp/coverage/lcov-report/url-utils/index.html +1 -1
  165. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
  166. package/temp/coverage/lcov.info +2021 -1197
  167. package/temp/coverage/url-utils/index.html +1 -1
  168. package/temp/coverage/url-utils/urlParams.ts.html +1 -1
  169. package/temp/test/jest/haste-map-b931e4e63102f86c5bd4949f7dced44f-9d713eb41149188b4e5c0ae3d86d0a57-2ad8e16b24e391b8cdbe50b55c137169 +0 -0
  170. package/temp/test/jest/perf-cache-b931e4e63102f86c5bd4949f7dced44f-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
  171. package/temp/ts-web-extras.api.json +1313 -354
  172. package/temp/ts-web-extras.api.md +33 -0
  173. package/.rush/temp/81e0881271ff236956b2f52e8ca99da6574c6e1e.tar.log +0 -223
  174. package/docs/index.md +0 -34
  175. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider._constructor_.md +0 -50
  176. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.decrypt.md +0 -104
  177. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.derivekey.md +0 -88
  178. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.encrypt.md +0 -72
  179. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.frombase64.md +0 -56
  180. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generatekey.md +0 -19
  181. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generaterandombytes.md +0 -56
  182. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.md +0 -169
  183. package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.tobase64.md +0 -56
  184. package/docs/ts-web-extras.cryptoutils.browserhashprovider.hashparts.md +0 -88
  185. package/docs/ts-web-extras.cryptoutils.browserhashprovider.hashstring.md +0 -72
  186. package/docs/ts-web-extras.cryptoutils.browserhashprovider.md +0 -66
  187. package/docs/ts-web-extras.cryptoutils.createbrowsercryptoprovider.md +0 -19
  188. package/docs/ts-web-extras.cryptoutils.md +0 -71
  189. package/docs/ts-web-extras.exportasjson.md +0 -70
  190. package/docs/ts-web-extras.exportusingfilesystemapi.md +0 -104
  191. package/docs/ts-web-extras.extractdirectorypath.md +0 -52
  192. package/docs/ts-web-extras.fileapitreeaccessors.create.md +0 -72
  193. package/docs/ts-web-extras.fileapitreeaccessors.createfromlocalstorage.md +0 -74
  194. package/docs/ts-web-extras.fileapitreeaccessors.createpersistent.md +0 -76
  195. package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +0 -54
  196. package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +0 -72
  197. package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +0 -72
  198. package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +0 -72
  199. package/docs/ts-web-extras.fileapitreeaccessors.md +0 -146
  200. package/docs/ts-web-extras.filepickeraccepttype.accept.md +0 -11
  201. package/docs/ts-web-extras.filepickeraccepttype.description.md +0 -11
  202. package/docs/ts-web-extras.filepickeraccepttype.md +0 -75
  203. package/docs/ts-web-extras.filesystemaccesstreeaccessors._constructor_.md +0 -114
  204. package/docs/ts-web-extras.filesystemaccesstreeaccessors.fileismutable.md +0 -52
  205. package/docs/ts-web-extras.filesystemaccesstreeaccessors.fromdirectoryhandle.md +0 -72
  206. package/docs/ts-web-extras.filesystemaccesstreeaccessors.getdirtypaths.md +0 -17
  207. package/docs/ts-web-extras.filesystemaccesstreeaccessors.isdirty.md +0 -17
  208. package/docs/ts-web-extras.filesystemaccesstreeaccessors.md +0 -159
  209. package/docs/ts-web-extras.filesystemaccesstreeaccessors.savefilecontents.md +0 -66
  210. package/docs/ts-web-extras.filesystemaccesstreeaccessors.synctodisk.md +0 -17
  211. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +0 -11
  212. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +0 -58
  213. package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +0 -15
  214. package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +0 -15
  215. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +0 -66
  216. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +0 -66
  217. package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +0 -15
  218. package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +0 -11
  219. package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +0 -146
  220. package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +0 -66
  221. package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +0 -50
  222. package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +0 -15
  223. package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +0 -52
  224. package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +0 -15
  225. package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +0 -11
  226. package/docs/ts-web-extras.filesystemfilehandle_2.md +0 -92
  227. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +0 -11
  228. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +0 -58
  229. package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +0 -11
  230. package/docs/ts-web-extras.filesystemgetfileoptions_2.md +0 -58
  231. package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +0 -50
  232. package/docs/ts-web-extras.filesystemhandle_2.kind.md +0 -11
  233. package/docs/ts-web-extras.filesystemhandle_2.md +0 -119
  234. package/docs/ts-web-extras.filesystemhandle_2.name.md +0 -11
  235. package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +0 -52
  236. package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +0 -52
  237. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +0 -58
  238. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +0 -11
  239. package/docs/ts-web-extras.filesystemremoveoptions_2.md +0 -58
  240. package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +0 -11
  241. package/docs/ts-web-extras.filesystemwritablefilestream_2.md +0 -57
  242. package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +0 -50
  243. package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +0 -50
  244. package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +0 -50
  245. package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +0 -13
  246. package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +0 -56
  247. package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +0 -56
  248. package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +0 -76
  249. package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +0 -76
  250. package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +0 -72
  251. package/docs/ts-web-extras.filetreehelpers.md +0 -102
  252. package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +0 -11
  253. package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +0 -100
  254. package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +0 -11
  255. package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +0 -11
  256. package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +0 -11
  257. package/docs/ts-web-extras.ifilehandletreeinitializer.md +0 -79
  258. package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +0 -11
  259. package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +0 -11
  260. package/docs/ts-web-extras.ifilelisttreeinitializer.md +0 -58
  261. package/docs/ts-web-extras.ifilemetadata.lastmodified.md +0 -11
  262. package/docs/ts-web-extras.ifilemetadata.md +0 -124
  263. package/docs/ts-web-extras.ifilemetadata.name.md +0 -11
  264. package/docs/ts-web-extras.ifilemetadata.path.md +0 -11
  265. package/docs/ts-web-extras.ifilemetadata.size.md +0 -11
  266. package/docs/ts-web-extras.ifilemetadata.type.md +0 -11
  267. package/docs/ts-web-extras.ifilesystemaccesstreeparams.autosync.md +0 -13
  268. package/docs/ts-web-extras.ifilesystemaccesstreeparams.md +0 -78
  269. package/docs/ts-web-extras.ifilesystemaccesstreeparams.requirewritepermission.md +0 -13
  270. package/docs/ts-web-extras.ifsaccessapis.md +0 -56
  271. package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +0 -52
  272. package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +0 -52
  273. package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +0 -52
  274. package/docs/ts-web-extras.ilocalstoragetreeparams.autosync.md +0 -13
  275. package/docs/ts-web-extras.ilocalstoragetreeparams.md +0 -97
  276. package/docs/ts-web-extras.ilocalstoragetreeparams.pathtokeymap.md +0 -13
  277. package/docs/ts-web-extras.ilocalstoragetreeparams.storage.md +0 -13
  278. package/docs/ts-web-extras.isdirectoryhandle.md +0 -56
  279. package/docs/ts-web-extras.isfilehandle.md +0 -56
  280. package/docs/ts-web-extras.isfilepath.md +0 -52
  281. package/docs/ts-web-extras.iurlconfigoptions.config.md +0 -13
  282. package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +0 -13
  283. package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +0 -13
  284. package/docs/ts-web-extras.iurlconfigoptions.input.md +0 -13
  285. package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +0 -13
  286. package/docs/ts-web-extras.iurlconfigoptions.interactive.md +0 -13
  287. package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +0 -13
  288. package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +0 -13
  289. package/docs/ts-web-extras.iurlconfigoptions.md +0 -286
  290. package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +0 -13
  291. package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +0 -13
  292. package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +0 -13
  293. package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +0 -13
  294. package/docs/ts-web-extras.iurlconfigoptions.zippath.md +0 -13
  295. package/docs/ts-web-extras.localstoragetreeaccessors.fileismutable.md +0 -56
  296. package/docs/ts-web-extras.localstoragetreeaccessors.fromstorage.md +0 -56
  297. package/docs/ts-web-extras.localstoragetreeaccessors.getdirtypaths.md +0 -19
  298. package/docs/ts-web-extras.localstoragetreeaccessors.isdirty.md +0 -19
  299. package/docs/ts-web-extras.localstoragetreeaccessors.md +0 -131
  300. package/docs/ts-web-extras.localstoragetreeaccessors.savefilecontents.md +0 -72
  301. package/docs/ts-web-extras.localstoragetreeaccessors.synctodisk.md +0 -19
  302. package/docs/ts-web-extras.md +0 -558
  303. package/docs/ts-web-extras.parsecontextfilter.md +0 -52
  304. package/docs/ts-web-extras.parsequalifierdefaults.md +0 -52
  305. package/docs/ts-web-extras.parseresourcetypes.md +0 -52
  306. package/docs/ts-web-extras.parseurlparameters.md +0 -17
  307. package/docs/ts-web-extras.safeshowdirectorypicker.md +0 -72
  308. package/docs/ts-web-extras.safeshowopenfilepicker.md +0 -72
  309. package/docs/ts-web-extras.safeshowsavefilepicker.md +0 -72
  310. package/docs/ts-web-extras.showdirectorypickeroptions.id.md +0 -11
  311. package/docs/ts-web-extras.showdirectorypickeroptions.md +0 -96
  312. package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +0 -11
  313. package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +0 -11
  314. package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +0 -11
  315. package/docs/ts-web-extras.showopenfilepickeroptions.id.md +0 -11
  316. package/docs/ts-web-extras.showopenfilepickeroptions.md +0 -134
  317. package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +0 -11
  318. package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +0 -11
  319. package/docs/ts-web-extras.showopenfilepickeroptions.types.md +0 -11
  320. package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +0 -11
  321. package/docs/ts-web-extras.showsavefilepickeroptions.id.md +0 -11
  322. package/docs/ts-web-extras.showsavefilepickeroptions.md +0 -134
  323. package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +0 -11
  324. package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +0 -11
  325. package/docs/ts-web-extras.showsavefilepickeroptions.types.md +0 -11
  326. package/docs/ts-web-extras.supportsfilesystemaccess.md +0 -56
  327. package/docs/ts-web-extras.treeinitializer.md +0 -15
  328. package/docs/ts-web-extras.wellknowndirectory.md +0 -13
  329. package/docs/ts-web-extras.windowwithfsaccess.md +0 -15
  330. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  331. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
  332. /package/temp/test/jest/{jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/8d/package_8dcbedef69e4299f0f51fcda8f4f1c8e → jest-transform-cache-b931e4e63102f86c5bd4949f7dced44f-79ef2876fae7ca75eedb2aa53dc48338/b5/package_b5f57afc9ec2c011239b1608ee5bdfa5} +0 -0
@@ -0,0 +1,1231 @@
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
+ require("@fgv/ts-utils-jest");
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const file_tree_1 = require("../../packlets/file-tree");
27
+ function makeMockResponse(options) {
28
+ const { ok, status = ok ? 200 : 400, jsonValue, textValue, throwOnJson, throwOnText } = options;
29
+ return {
30
+ ok,
31
+ status,
32
+ statusText: ok ? 'OK' : `Error ${status}`,
33
+ json: throwOnJson
34
+ ? () => Promise.reject(new Error('JSON parse error'))
35
+ : () => Promise.resolve(jsonValue),
36
+ text: throwOnText
37
+ ? () => Promise.reject(new Error('text error'))
38
+ : () => Promise.resolve(textValue !== null && textValue !== void 0 ? textValue : `HTTP ${status}`)
39
+ };
40
+ }
41
+ /**
42
+ * Creates a mock fetch function that returns responses for each call in order.
43
+ * Each entry maps to one fetch() invocation in call order.
44
+ */
45
+ function makeMockFetch(responses) {
46
+ const calls = [];
47
+ let callIndex = 0;
48
+ const fetchImpl = (url, init) => {
49
+ calls.push({ url: url.toString(), init });
50
+ const response = responses[callIndex++];
51
+ if (response === undefined) {
52
+ return Promise.reject(new Error(`Unexpected fetch call #${callIndex} to ${url.toString()}`));
53
+ }
54
+ return Promise.resolve(makeMockResponse(response));
55
+ };
56
+ return { fetchImpl: fetchImpl, calls };
57
+ }
58
+ /**
59
+ * Creates a mock fetch function that throws a network error on every call.
60
+ */
61
+ function makeThrowingFetch(message) {
62
+ return (_url, _init) => {
63
+ return Promise.reject(new Error(message));
64
+ };
65
+ }
66
+ // ---- Shared test data builders ----
67
+ /** Minimal tree-children response for a single file at root. */
68
+ function rootWithOneFile(fileName = 'data.json') {
69
+ return {
70
+ path: '/',
71
+ children: [{ path: `/${fileName}`, name: fileName, type: 'file' }]
72
+ };
73
+ }
74
+ /** File response for a JSON file. */
75
+ function fileResponse(path, contents, contentType) {
76
+ const response = { path, contents };
77
+ if (contentType !== undefined) {
78
+ response.contentType = contentType;
79
+ }
80
+ return response;
81
+ }
82
+ /** Root children response containing a subdirectory and a file. */
83
+ function rootWithDirAndFile() {
84
+ return {
85
+ path: '/',
86
+ children: [
87
+ { path: '/subdir', name: 'subdir', type: 'directory' },
88
+ { path: '/root.json', name: 'root.json', type: 'file' }
89
+ ]
90
+ };
91
+ }
92
+ /** Children response for /subdir containing one file. */
93
+ function subdirWithOneFile() {
94
+ return {
95
+ path: '/subdir',
96
+ children: [{ path: '/subdir/nested.json', name: 'nested.json', type: 'file' }]
97
+ };
98
+ }
99
+ // ---- Tests ----
100
+ describe('HttpTreeAccessors', () => {
101
+ describe('fromHttp()', () => {
102
+ test('succeeds with an empty directory (no children)', async () => {
103
+ const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
104
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
105
+ baseUrl: 'http://localhost:3000',
106
+ fetchImpl
107
+ });
108
+ expect(result).toSucceedAndSatisfy((accessors) => {
109
+ expect(accessors).toBeInstanceOf(file_tree_1.HttpTreeAccessors);
110
+ expect(accessors.isDirty()).toBe(false);
111
+ });
112
+ });
113
+ test('succeeds and loads a single file at root', async () => {
114
+ const { fetchImpl } = makeMockFetch([
115
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
116
+ { ok: true, jsonValue: fileResponse('/data.json', '{"items":{}}') }
117
+ ]);
118
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
119
+ baseUrl: 'http://localhost:3000',
120
+ fetchImpl,
121
+ mutable: true
122
+ });
123
+ expect(result).toSucceedAndSatisfy((accessors) => {
124
+ expect(accessors.getFileContents('/data.json')).toSucceedWith('{"items":{}}');
125
+ });
126
+ });
127
+ test('succeeds with multiple files at root', async () => {
128
+ const { fetchImpl } = makeMockFetch([
129
+ {
130
+ ok: true,
131
+ jsonValue: {
132
+ path: '/',
133
+ children: [
134
+ { path: '/alpha.json', name: 'alpha.json', type: 'file' },
135
+ { path: '/beta.json', name: 'beta.json', type: 'file' }
136
+ ]
137
+ }
138
+ },
139
+ { ok: true, jsonValue: fileResponse('/alpha.json', '"alpha"') },
140
+ { ok: true, jsonValue: fileResponse('/beta.json', '"beta"') }
141
+ ]);
142
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
143
+ baseUrl: 'http://localhost:3000',
144
+ fetchImpl,
145
+ mutable: true
146
+ });
147
+ expect(result).toSucceedAndSatisfy((accessors) => {
148
+ expect(accessors.getFileContents('/alpha.json')).toSucceedWith('"alpha"');
149
+ expect(accessors.getFileContents('/beta.json')).toSucceedWith('"beta"');
150
+ });
151
+ });
152
+ test('succeeds and recursively loads files in subdirectories', async () => {
153
+ const { fetchImpl } = makeMockFetch([
154
+ { ok: true, jsonValue: rootWithDirAndFile() },
155
+ { ok: true, jsonValue: subdirWithOneFile() },
156
+ { ok: true, jsonValue: fileResponse('/subdir/nested.json', '"nested"') },
157
+ { ok: true, jsonValue: fileResponse('/root.json', '"root"') }
158
+ ]);
159
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
160
+ baseUrl: 'http://localhost:3000',
161
+ fetchImpl,
162
+ mutable: true
163
+ });
164
+ expect(result).toSucceedAndSatisfy((accessors) => {
165
+ expect(accessors.getFileContents('/subdir/nested.json')).toSucceedWith('"nested"');
166
+ expect(accessors.getFileContents('/root.json')).toSucceedWith('"root"');
167
+ });
168
+ });
169
+ test('strips trailing slash from baseUrl', async () => {
170
+ const { fetchImpl, calls } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
171
+ await file_tree_1.HttpTreeAccessors.fromHttp({
172
+ baseUrl: 'http://localhost:3000/',
173
+ fetchImpl
174
+ });
175
+ // The URL should start with the base URL without a trailing slash, then /tree/children
176
+ expect(calls[0].url).toMatch(/^http:\/\/localhost:3000\/tree\/children/);
177
+ // There should be no double slash in the path portion (after the protocol)
178
+ const urlPath = calls[0].url.replace('http://', '');
179
+ expect(urlPath).not.toContain('//');
180
+ });
181
+ test('includes namespace in query parameters when provided', async () => {
182
+ const { fetchImpl, calls } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
183
+ await file_tree_1.HttpTreeAccessors.fromHttp({
184
+ baseUrl: 'http://localhost:3000',
185
+ namespace: 'my-namespace',
186
+ fetchImpl
187
+ });
188
+ expect(calls[0].url).toContain('namespace=my-namespace');
189
+ });
190
+ test('omits namespace from query parameters when not provided', async () => {
191
+ const { fetchImpl, calls } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
192
+ await file_tree_1.HttpTreeAccessors.fromHttp({
193
+ baseUrl: 'http://localhost:3000',
194
+ fetchImpl
195
+ });
196
+ expect(calls[0].url).not.toContain('namespace');
197
+ });
198
+ test('applies prefix parameter to loaded file paths', async () => {
199
+ const { fetchImpl } = makeMockFetch([
200
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
201
+ { ok: true, jsonValue: fileResponse('/data.json', '{"items":{}}') }
202
+ ]);
203
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
204
+ baseUrl: 'http://localhost:3000',
205
+ prefix: '/app',
206
+ fetchImpl,
207
+ mutable: true
208
+ });
209
+ expect(result).toSucceedAndSatisfy((accessors) => {
210
+ expect(accessors.getFileContents('/app/data.json')).toSucceedWith('{"items":{}}');
211
+ });
212
+ });
213
+ test('fails when the initial children fetch fails with a network error', async () => {
214
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
215
+ baseUrl: 'http://localhost:3000',
216
+ fetchImpl: makeThrowingFetch('Network unreachable')
217
+ });
218
+ expect(result).toFailWith(/network unreachable/i);
219
+ });
220
+ test('fails when the children response is not ok', async () => {
221
+ const { fetchImpl } = makeMockFetch([{ ok: false, status: 404, textValue: 'Not Found' }]);
222
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
223
+ baseUrl: 'http://localhost:3000',
224
+ fetchImpl
225
+ });
226
+ expect(result).toFailWith(/not found/i);
227
+ });
228
+ test('fails when the children response contains invalid JSON', async () => {
229
+ const { fetchImpl } = makeMockFetch([{ ok: true, throwOnJson: true }]);
230
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
231
+ baseUrl: 'http://localhost:3000',
232
+ fetchImpl
233
+ });
234
+ expect(result).toFailWith(/invalid json/i);
235
+ });
236
+ test('fails when a file fetch fails with a network error', async () => {
237
+ let callCount = 0;
238
+ const fetchImpl = (_url, _init) => {
239
+ callCount++;
240
+ if (callCount === 1) {
241
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
242
+ }
243
+ return Promise.reject(new Error('File fetch failed'));
244
+ };
245
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
246
+ baseUrl: 'http://localhost:3000',
247
+ fetchImpl
248
+ });
249
+ expect(result).toFailWith(/file fetch failed/i);
250
+ });
251
+ test('fails when a file response is not ok', async () => {
252
+ const { fetchImpl } = makeMockFetch([
253
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
254
+ { ok: false, status: 403, textValue: 'Forbidden' }
255
+ ]);
256
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
257
+ baseUrl: 'http://localhost:3000',
258
+ fetchImpl
259
+ });
260
+ expect(result).toFailWith(/forbidden/i);
261
+ });
262
+ test('fails when a file response contains invalid JSON', async () => {
263
+ const { fetchImpl } = makeMockFetch([
264
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
265
+ { ok: true, throwOnJson: true }
266
+ ]);
267
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
268
+ baseUrl: 'http://localhost:3000',
269
+ fetchImpl
270
+ });
271
+ expect(result).toFailWith(/invalid json/i);
272
+ });
273
+ test('fails when a nested directory fetch fails', async () => {
274
+ const { fetchImpl } = makeMockFetch([
275
+ { ok: true, jsonValue: rootWithDirAndFile() },
276
+ { ok: false, status: 500, textValue: 'Internal Server Error' }
277
+ ]);
278
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
279
+ baseUrl: 'http://localhost:3000',
280
+ fetchImpl
281
+ });
282
+ expect(result).toFailWith(/internal server error/i);
283
+ });
284
+ });
285
+ describe('isDirty() and getDirtyPaths()', () => {
286
+ test('starts not dirty after loading', async () => {
287
+ const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
288
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl })).orThrow();
289
+ expect(accessors.isDirty()).toBe(false);
290
+ expect(accessors.getDirtyPaths()).toEqual([]);
291
+ });
292
+ test('becomes dirty after saveFileContents', async () => {
293
+ const { fetchImpl } = makeMockFetch([
294
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
295
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
296
+ ]);
297
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
298
+ baseUrl: 'http://localhost:3000',
299
+ fetchImpl,
300
+ mutable: true
301
+ })).orThrow();
302
+ accessors.saveFileContents('/data.json', '{"modified":true}').orThrow();
303
+ expect(accessors.isDirty()).toBe(true);
304
+ expect(accessors.getDirtyPaths()).toContain('/data.json');
305
+ });
306
+ test('tracks multiple dirty files', async () => {
307
+ const { fetchImpl } = makeMockFetch([
308
+ {
309
+ ok: true,
310
+ jsonValue: {
311
+ path: '/',
312
+ children: [
313
+ { path: '/a.json', name: 'a.json', type: 'file' },
314
+ { path: '/b.json', name: 'b.json', type: 'file' }
315
+ ]
316
+ }
317
+ },
318
+ { ok: true, jsonValue: fileResponse('/a.json', '{}') },
319
+ { ok: true, jsonValue: fileResponse('/b.json', '{}') }
320
+ ]);
321
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
322
+ baseUrl: 'http://localhost:3000',
323
+ fetchImpl,
324
+ mutable: true
325
+ })).orThrow();
326
+ accessors.saveFileContents('/a.json', '"a"').orThrow();
327
+ accessors.saveFileContents('/b.json', '"b"').orThrow();
328
+ expect(accessors.getDirtyPaths()).toHaveLength(2);
329
+ expect(accessors.getDirtyPaths()).toContain('/a.json');
330
+ expect(accessors.getDirtyPaths()).toContain('/b.json');
331
+ });
332
+ test('tracks deleted files as pending dirty paths', async () => {
333
+ const { fetchImpl } = makeMockFetch([
334
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
335
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
336
+ ]);
337
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
338
+ baseUrl: 'http://localhost:3000',
339
+ fetchImpl,
340
+ mutable: true
341
+ })).orThrow();
342
+ accessors.deleteFile('/data.json').orThrow();
343
+ expect(accessors.isDirty()).toBe(true);
344
+ expect(accessors.getDirtyPaths()).toContain('/data.json');
345
+ });
346
+ });
347
+ describe('saveFileContents()', () => {
348
+ test('fails when the file is not found (immutable tree has no matching path)', async () => {
349
+ const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
350
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl })).orThrow();
351
+ // With mutable: false (default), saveFileContents should fail
352
+ const result = accessors.saveFileContents('/missing.json', '{}');
353
+ expect(result).toFail();
354
+ });
355
+ test('marks the file as dirty without autoSync', async () => {
356
+ const { fetchImpl } = makeMockFetch([
357
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
358
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
359
+ ]);
360
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
361
+ baseUrl: 'http://localhost:3000',
362
+ fetchImpl,
363
+ mutable: true
364
+ })).orThrow();
365
+ const result = accessors.saveFileContents('/data.json', '{"updated":true}');
366
+ expect(result).toSucceedWith('{"updated":true}');
367
+ expect(accessors.isDirty()).toBe(true);
368
+ // No additional fetch calls should have occurred (no autoSync)
369
+ });
370
+ test('triggers fire-and-forget autoSync when autoSync is enabled', async () => {
371
+ const syncResponses = [
372
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
373
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
374
+ // PUT /file response for sync
375
+ { ok: true, jsonValue: { path: '/data.json', contents: '{"auto":true}' } },
376
+ // POST /sync response
377
+ { ok: true, jsonValue: { synced: 1 } }
378
+ ];
379
+ const { fetchImpl, calls } = makeMockFetch(syncResponses);
380
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
381
+ baseUrl: 'http://localhost:3000',
382
+ fetchImpl,
383
+ mutable: true,
384
+ autoSync: true
385
+ })).orThrow();
386
+ const result = accessors.saveFileContents('/data.json', '{"auto":true}');
387
+ expect(result).toSucceedWith('{"auto":true}');
388
+ // autoSync fires-and-forgets; wait for microtasks to drain
389
+ await new Promise((resolve) => setTimeout(resolve, 0));
390
+ // Verify that PUT + POST /sync were called
391
+ const methodCalls = calls.slice(2).map((c) => { var _a; return (_a = c.init) === null || _a === void 0 ? void 0 : _a.method; });
392
+ expect(methodCalls).toContain('PUT');
393
+ expect(methodCalls).toContain('POST');
394
+ });
395
+ test('logs when autoSync returns a failure Result', async () => {
396
+ const logger = {
397
+ detail: jest.fn(),
398
+ info: jest.fn(),
399
+ warn: jest.fn(),
400
+ error: jest.fn()
401
+ };
402
+ const { fetchImpl } = makeMockFetch([
403
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
404
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
405
+ ]);
406
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
407
+ baseUrl: 'http://localhost:3000',
408
+ fetchImpl,
409
+ mutable: true,
410
+ autoSync: true,
411
+ logger
412
+ })).orThrow();
413
+ accessors.syncToDisk =
414
+ async () => (0, ts_utils_1.fail)('simulated sync failure');
415
+ accessors.saveFileContents('/data.json', '{"auto":true}').orThrow();
416
+ await new Promise((resolve) => setTimeout(resolve, 0));
417
+ expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('simulated sync failure'));
418
+ });
419
+ test('logs when autoSync throws unexpectedly', async () => {
420
+ const logger = {
421
+ detail: jest.fn(),
422
+ info: jest.fn(),
423
+ warn: jest.fn(),
424
+ error: jest.fn()
425
+ };
426
+ const { fetchImpl } = makeMockFetch([
427
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
428
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
429
+ ]);
430
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
431
+ baseUrl: 'http://localhost:3000',
432
+ fetchImpl,
433
+ mutable: true,
434
+ autoSync: true,
435
+ logger
436
+ })).orThrow();
437
+ accessors.syncToDisk = async () => {
438
+ throw new Error('simulated throw');
439
+ };
440
+ accessors.saveFileContents('/data.json', '{"auto":true}').orThrow();
441
+ await new Promise((resolve) => setTimeout(resolve, 0));
442
+ expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('simulated throw'));
443
+ });
444
+ });
445
+ describe('fileIsMutable()', () => {
446
+ test('returns persistent detail when file exists and mutable is true', async () => {
447
+ const { fetchImpl } = makeMockFetch([
448
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
449
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
450
+ ]);
451
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
452
+ baseUrl: 'http://localhost:3000',
453
+ fetchImpl,
454
+ mutable: true
455
+ })).orThrow();
456
+ const result = accessors.fileIsMutable('/data.json');
457
+ expect(result.isSuccess()).toBe(true);
458
+ if (result.isSuccess()) {
459
+ expect(result.value).toBe(true);
460
+ expect(result.detail).toBe('persistent');
461
+ }
462
+ });
463
+ test('returns not-mutable detail when mutable is false', async () => {
464
+ const { fetchImpl } = makeMockFetch([
465
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
466
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
467
+ ]);
468
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
469
+ baseUrl: 'http://localhost:3000',
470
+ fetchImpl,
471
+ mutable: false
472
+ })).orThrow();
473
+ const result = accessors.fileIsMutable('/data.json');
474
+ expect(result.isFailure()).toBe(true);
475
+ if (result.isFailure()) {
476
+ expect(result.detail).toBe('not-mutable');
477
+ }
478
+ });
479
+ test('returns persistent detail for any path when mutable is true (no path existence check)', async () => {
480
+ // InMemoryTreeAccessors checks the mutable config, not path existence.
481
+ // HttpTreeAccessors layers "persistent" on top of a successful mutable check.
482
+ const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
483
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
484
+ baseUrl: 'http://localhost:3000',
485
+ fetchImpl,
486
+ mutable: true
487
+ })).orThrow();
488
+ // Any path succeeds as "persistent" when mutable: true
489
+ const result = accessors.fileIsMutable('/nonexistent.json');
490
+ expect(result.isSuccess()).toBe(true);
491
+ if (result.isSuccess()) {
492
+ expect(result.value).toBe(true);
493
+ expect(result.detail).toBe('persistent');
494
+ }
495
+ });
496
+ });
497
+ describe('syncToDisk()', () => {
498
+ test('succeeds immediately with no dirty files', async () => {
499
+ const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
500
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl })).orThrow();
501
+ const result = await accessors.syncToDisk();
502
+ expect(result).toSucceed();
503
+ });
504
+ test('PUTs each dirty file then POSTs /sync', async () => {
505
+ var _a, _b;
506
+ const { fetchImpl, calls } = makeMockFetch([
507
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
508
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
509
+ { ok: true, jsonValue: fileResponse('/data.json', '{"new":1}') },
510
+ { ok: true, jsonValue: { synced: 1 } }
511
+ ]);
512
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
513
+ baseUrl: 'http://localhost:3000',
514
+ fetchImpl,
515
+ mutable: true
516
+ })).orThrow();
517
+ accessors.saveFileContents('/data.json', '{"new":1}').orThrow();
518
+ const result = await accessors.syncToDisk();
519
+ expect(result).toSucceed();
520
+ const syncCalls = calls.slice(2);
521
+ expect(syncCalls[0].url).toContain('/file');
522
+ expect((_a = syncCalls[0].init) === null || _a === void 0 ? void 0 : _a.method).toBe('PUT');
523
+ expect(syncCalls[1].url).toContain('/sync');
524
+ expect((_b = syncCalls[1].init) === null || _b === void 0 ? void 0 : _b.method).toBe('POST');
525
+ });
526
+ test('clears dirty state after successful sync', async () => {
527
+ const { fetchImpl } = makeMockFetch([
528
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
529
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
530
+ { ok: true, jsonValue: fileResponse('/data.json', '"updated"') },
531
+ { ok: true, jsonValue: { synced: 1 } }
532
+ ]);
533
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
534
+ baseUrl: 'http://localhost:3000',
535
+ fetchImpl,
536
+ mutable: true
537
+ })).orThrow();
538
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
539
+ expect(accessors.isDirty()).toBe(true);
540
+ await accessors.syncToDisk();
541
+ expect(accessors.isDirty()).toBe(false);
542
+ expect(accessors.getDirtyPaths()).toEqual([]);
543
+ });
544
+ test('includes namespace in PUT body and POST /sync body when provided', async () => {
545
+ var _a, _b;
546
+ const { fetchImpl, calls } = makeMockFetch([
547
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
548
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
549
+ { ok: true, jsonValue: fileResponse('/data.json', '"v2"') },
550
+ { ok: true, jsonValue: { synced: 1 } }
551
+ ]);
552
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
553
+ baseUrl: 'http://localhost:3000',
554
+ namespace: 'myns',
555
+ fetchImpl,
556
+ mutable: true
557
+ })).orThrow();
558
+ accessors.saveFileContents('/data.json', '"v2"').orThrow();
559
+ await accessors.syncToDisk();
560
+ const putBody = JSON.parse((_a = calls[2].init) === null || _a === void 0 ? void 0 : _a.body);
561
+ expect(putBody.namespace).toBe('myns');
562
+ const syncBody = JSON.parse((_b = calls[3].init) === null || _b === void 0 ? void 0 : _b.body);
563
+ expect(syncBody.namespace).toBe('myns');
564
+ });
565
+ test('omits namespace from PUT body and POST /sync body when not provided', async () => {
566
+ var _a, _b;
567
+ const { fetchImpl, calls } = makeMockFetch([
568
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
569
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
570
+ { ok: true, jsonValue: fileResponse('/data.json', '"v2"') },
571
+ { ok: true, jsonValue: { synced: 1 } }
572
+ ]);
573
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
574
+ baseUrl: 'http://localhost:3000',
575
+ fetchImpl,
576
+ mutable: true
577
+ })).orThrow();
578
+ accessors.saveFileContents('/data.json', '"v2"').orThrow();
579
+ await accessors.syncToDisk();
580
+ const putBody = JSON.parse((_a = calls[2].init) === null || _a === void 0 ? void 0 : _a.body);
581
+ expect(putBody.namespace).toBeUndefined();
582
+ const syncBody = JSON.parse((_b = calls[3].init) === null || _b === void 0 ? void 0 : _b.body);
583
+ expect(syncBody.namespace).toBeUndefined();
584
+ });
585
+ test('fails when PUT for a dirty file returns a non-ok response', async () => {
586
+ const { fetchImpl } = makeMockFetch([
587
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
588
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
589
+ { ok: false, status: 500, textValue: 'Server Error' }
590
+ ]);
591
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
592
+ baseUrl: 'http://localhost:3000',
593
+ fetchImpl,
594
+ mutable: true
595
+ })).orThrow();
596
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
597
+ const result = await accessors.syncToDisk();
598
+ expect(result).toFailWith(/sync.*data\.json.*server error/i);
599
+ });
600
+ test('fails when PUT for a dirty file encounters a network error', async () => {
601
+ jest.useFakeTimers();
602
+ try {
603
+ let callCount = 0;
604
+ const fetchImpl = (_url, _init) => {
605
+ callCount++;
606
+ if (callCount === 1) {
607
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
608
+ }
609
+ if (callCount === 2) {
610
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
611
+ }
612
+ return Promise.reject(new Error('PUT network error'));
613
+ };
614
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
615
+ baseUrl: 'http://localhost:3000',
616
+ fetchImpl,
617
+ mutable: true
618
+ })).orThrow();
619
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
620
+ const syncPromise = accessors.syncToDisk();
621
+ await jest.advanceTimersByTimeAsync(1500);
622
+ const result = await syncPromise;
623
+ expect(result).toFailWith(/put network error/i);
624
+ }
625
+ finally {
626
+ jest.useRealTimers();
627
+ }
628
+ });
629
+ test('fails when POST /sync returns a non-ok response', async () => {
630
+ jest.useFakeTimers();
631
+ try {
632
+ let callCount = 0;
633
+ const fetchImpl = (_url, _init) => {
634
+ callCount++;
635
+ if (callCount === 1) {
636
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
637
+ }
638
+ if (callCount === 2) {
639
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
640
+ }
641
+ if (callCount === 3) {
642
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '"v2"') }));
643
+ }
644
+ // All /sync attempts: persistent 503
645
+ return Promise.resolve(makeMockResponse({ ok: false, status: 503, textValue: 'Service Unavailable' }));
646
+ };
647
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
648
+ baseUrl: 'http://localhost:3000',
649
+ fetchImpl,
650
+ mutable: true
651
+ })).orThrow();
652
+ accessors.saveFileContents('/data.json', '"v2"').orThrow();
653
+ const syncPromise = accessors.syncToDisk();
654
+ // Advance past both backoff delays: 500ms + 1000ms
655
+ await jest.advanceTimersByTimeAsync(1500);
656
+ const result = await syncPromise;
657
+ expect(result).toFailWith(/service unavailable/i);
658
+ }
659
+ finally {
660
+ jest.useRealTimers();
661
+ }
662
+ });
663
+ test('fails when POST /sync encounters a network error', async () => {
664
+ jest.useFakeTimers();
665
+ try {
666
+ let callCount = 0;
667
+ const fetchImpl = (_url, _init) => {
668
+ callCount++;
669
+ if (callCount === 1) {
670
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
671
+ }
672
+ if (callCount === 2) {
673
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
674
+ }
675
+ if (callCount === 3) {
676
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '"v2"') }));
677
+ }
678
+ return Promise.reject(new Error('POST network error'));
679
+ };
680
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
681
+ baseUrl: 'http://localhost:3000',
682
+ fetchImpl,
683
+ mutable: true
684
+ })).orThrow();
685
+ accessors.saveFileContents('/data.json', '"v2"').orThrow();
686
+ const syncPromise = accessors.syncToDisk();
687
+ await jest.advanceTimersByTimeAsync(1500);
688
+ const result = await syncPromise;
689
+ expect(result).toFailWith(/post network error/i);
690
+ }
691
+ finally {
692
+ jest.useRealTimers();
693
+ }
694
+ });
695
+ test('syncs multiple dirty files in order', async () => {
696
+ const { fetchImpl, calls } = makeMockFetch([
697
+ {
698
+ ok: true,
699
+ jsonValue: {
700
+ path: '/',
701
+ children: [
702
+ { path: '/a.json', name: 'a.json', type: 'file' },
703
+ { path: '/b.json', name: 'b.json', type: 'file' }
704
+ ]
705
+ }
706
+ },
707
+ { ok: true, jsonValue: fileResponse('/a.json', '{}') },
708
+ { ok: true, jsonValue: fileResponse('/b.json', '{}') },
709
+ { ok: true, jsonValue: fileResponse('/a.json', '"a-updated"') },
710
+ { ok: true, jsonValue: fileResponse('/b.json', '"b-updated"') },
711
+ { ok: true, jsonValue: { synced: 2 } }
712
+ ]);
713
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
714
+ baseUrl: 'http://localhost:3000',
715
+ fetchImpl,
716
+ mutable: true
717
+ })).orThrow();
718
+ accessors.saveFileContents('/a.json', '"a-updated"').orThrow();
719
+ accessors.saveFileContents('/b.json', '"b-updated"').orThrow();
720
+ const result = await accessors.syncToDisk();
721
+ expect(result).toSucceed();
722
+ // Verify 2 PUTs + 1 POST
723
+ const syncCalls = calls.slice(3);
724
+ const methods = syncCalls.map((c) => { var _a; return (_a = c.init) === null || _a === void 0 ? void 0 : _a.method; });
725
+ expect(methods.filter((m) => m === 'PUT')).toHaveLength(2);
726
+ expect(methods.filter((m) => m === 'POST')).toHaveLength(1);
727
+ });
728
+ test('DELETEs pending deletions before POST /sync', async () => {
729
+ var _a, _b;
730
+ const { fetchImpl, calls } = makeMockFetch([
731
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
732
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
733
+ { ok: true, jsonValue: { deleted: true } },
734
+ { ok: true, jsonValue: { synced: 0 } }
735
+ ]);
736
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
737
+ baseUrl: 'http://localhost:3000',
738
+ fetchImpl,
739
+ mutable: true
740
+ })).orThrow();
741
+ accessors.deleteFile('/data.json').orThrow();
742
+ const result = await accessors.syncToDisk();
743
+ expect(result).toSucceed();
744
+ const syncCalls = calls.slice(2);
745
+ expect((_a = syncCalls[0].init) === null || _a === void 0 ? void 0 : _a.method).toBe('DELETE');
746
+ expect(syncCalls[0].url).toContain('/file?');
747
+ expect((_b = syncCalls[1].init) === null || _b === void 0 ? void 0 : _b.method).toBe('POST');
748
+ expect(accessors.isDirty()).toBe(false);
749
+ });
750
+ test('fails when DELETE for pending deletion returns non-ok response', async () => {
751
+ const { fetchImpl } = makeMockFetch([
752
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
753
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
754
+ { ok: false, status: 500, textValue: 'Delete failed' }
755
+ ]);
756
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
757
+ baseUrl: 'http://localhost:3000',
758
+ fetchImpl,
759
+ mutable: true
760
+ })).orThrow();
761
+ accessors.deleteFile('/data.json').orThrow();
762
+ const result = await accessors.syncToDisk();
763
+ expect(result).toFailWith(/delete.*data\.json.*delete failed/i);
764
+ });
765
+ });
766
+ describe('syncToDisk() - getFileContents failure', () => {
767
+ test('fails when getFileContents returns failure for a dirty file during sync', async () => {
768
+ // This covers lines 112-113: the contentsResult.isFailure() branch in syncToDisk.
769
+ // We load a file, mark it dirty, then sabotage getFileContents to fail.
770
+ const { fetchImpl } = makeMockFetch([
771
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
772
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') }
773
+ ]);
774
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
775
+ baseUrl: 'http://localhost:3000',
776
+ fetchImpl,
777
+ mutable: true
778
+ })).orThrow();
779
+ accessors.saveFileContents('/data.json', '{"new":1}').orThrow();
780
+ // Sabotage the base getFileContents to simulate a failure
781
+ const originalGet = accessors.getFileContents.bind(accessors);
782
+ accessors.getFileContents = (path) => {
783
+ if (path === '/data.json') {
784
+ // eslint-disable-next-line import/no-internal-modules
785
+ const { fail: failResult } = require('@fgv/ts-utils');
786
+ return failResult('simulated get failure');
787
+ }
788
+ return originalGet(path);
789
+ };
790
+ const result = await accessors.syncToDisk();
791
+ expect(result).toFailWith(/simulated get failure/i);
792
+ });
793
+ });
794
+ describe('_request() invalid JSON during sync', () => {
795
+ test('fails when PUT /file returns invalid JSON', async () => {
796
+ // Covers lines 225-226: _request() returns fail('invalid JSON response')
797
+ // when response.json() throws during a sync PUT.
798
+ const { fetchImpl } = makeMockFetch([
799
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
800
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
801
+ // PUT response with ok=true but throwOnJson simulates invalid JSON body
802
+ { ok: true, throwOnJson: true }
803
+ ]);
804
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
805
+ baseUrl: 'http://localhost:3000',
806
+ fetchImpl,
807
+ mutable: true
808
+ })).orThrow();
809
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
810
+ const result = await accessors.syncToDisk();
811
+ expect(result).toFailWith(/invalid json/i);
812
+ });
813
+ });
814
+ describe('fromHttp() with inferContentType', () => {
815
+ test('calls inferContentType when provided and uses the result', async () => {
816
+ // Covers line 270: params.inferContentType?.(...).orDefault()
817
+ const { fetchImpl } = makeMockFetch([
818
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
819
+ { ok: true, jsonValue: fileResponse('/data.json', '{}', 'application/json') }
820
+ ]);
821
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
822
+ baseUrl: 'http://localhost:3000',
823
+ fetchImpl,
824
+ inferContentType: (path, provided) => {
825
+ if (provided === 'application/json') {
826
+ const { succeed: s } = require('@fgv/ts-utils');
827
+ return s('json');
828
+ }
829
+ const { succeed: s } = require('@fgv/ts-utils');
830
+ return s(undefined);
831
+ }
832
+ });
833
+ expect(result).toSucceed();
834
+ });
835
+ });
836
+ describe('_request() error handling', () => {
837
+ test('returns failure with error message for network error (Error instance throw) during sync', async () => {
838
+ // Covers line 214 true branch: response.err instanceof Error -> uses .message
839
+ let callCount = 0;
840
+ const fetchImpl = (_url, _init) => {
841
+ callCount++;
842
+ if (callCount === 1) {
843
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
844
+ }
845
+ if (callCount === 2) {
846
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
847
+ }
848
+ // PUT request throws an Error instance
849
+ return Promise.reject(new Error('real Error instance'));
850
+ };
851
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
852
+ baseUrl: 'http://localhost:3000',
853
+ fetchImpl,
854
+ mutable: true
855
+ })).orThrow();
856
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
857
+ const result = await accessors.syncToDisk();
858
+ expect(result).toFailWith(/real error instance/i);
859
+ });
860
+ test('returns failure with error message for non-Error throw during sync PUT', async () => {
861
+ // Covers line 214 false branch: thrown value is not an Error instance -> uses String(response.err)
862
+ // Must be triggered via syncToDisk() which uses the instance _request() method.
863
+ let callCount = 0;
864
+ const fetchImpl = (_url, _init) => {
865
+ callCount++;
866
+ if (callCount === 1) {
867
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
868
+ }
869
+ if (callCount === 2) {
870
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
871
+ }
872
+ // Non-Error throw (e.g., a plain string)
873
+ return Promise.reject('non-error string rejection');
874
+ };
875
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
876
+ baseUrl: 'http://localhost:3000',
877
+ fetchImpl,
878
+ mutable: true
879
+ })).orThrow();
880
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
881
+ const result = await accessors.syncToDisk();
882
+ expect(result).toFailWith(/non-error string rejection/i);
883
+ });
884
+ test('returns failure with HTTP status fallback when response.text() throws during sync', async () => {
885
+ // Covers the text() catch branch in _request(): uses `HTTP ${status}` fallback
886
+ // 502 is transient so retries will be attempted; use fake timers to avoid real delays
887
+ jest.useFakeTimers();
888
+ try {
889
+ let callCount = 0;
890
+ const fetchImpl = (_url, _init) => {
891
+ callCount++;
892
+ if (callCount === 1) {
893
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
894
+ }
895
+ if (callCount === 2) {
896
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
897
+ }
898
+ return Promise.resolve(makeMockResponse({ ok: false, status: 502, throwOnText: true }));
899
+ };
900
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
901
+ baseUrl: 'http://localhost:3000',
902
+ fetchImpl,
903
+ mutable: true
904
+ })).orThrow();
905
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
906
+ const syncPromise = accessors.syncToDisk();
907
+ await jest.advanceTimersByTimeAsync(1500);
908
+ const result = await syncPromise;
909
+ expect(result).toFailWith(/http 502/i);
910
+ }
911
+ finally {
912
+ jest.useRealTimers();
913
+ }
914
+ });
915
+ });
916
+ describe('_requestWithParams() error handling', () => {
917
+ test('returns failure with error message for non-Error network throw during init', async () => {
918
+ // _requestWithParams is used for GET requests during fromHttp(); test non-Error throw branch
919
+ const fetchImpl = (_url, _init) => {
920
+ return Promise.reject(42);
921
+ };
922
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
923
+ baseUrl: 'http://localhost:3000',
924
+ fetchImpl
925
+ });
926
+ expect(result).toFailWith(/42/);
927
+ });
928
+ test('returns failure with HTTP status fallback when response.text() throws during init', async () => {
929
+ const fetchImpl = (_url, _init) => {
930
+ return Promise.resolve(makeMockResponse({ ok: false, status: 504, throwOnText: true }));
931
+ };
932
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
933
+ baseUrl: 'http://localhost:3000',
934
+ fetchImpl
935
+ });
936
+ expect(result).toFailWith(/http 504/i);
937
+ });
938
+ test('uses globalThis.fetch when no fetchImpl provided', async () => {
939
+ // Covers line 48: the `fetchImpl ?? globalThis.fetch` right-side branch.
940
+ // We temporarily replace globalThis.fetch with a mock that returns an empty tree.
941
+ const originalFetch = globalThis.fetch;
942
+ let fetchCallCount = 0;
943
+ globalThis.fetch = (_url, _init) => {
944
+ fetchCallCount++;
945
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: { path: '/', children: [] } }));
946
+ };
947
+ try {
948
+ const result = await file_tree_1.HttpTreeAccessors.fromHttp({
949
+ baseUrl: 'http://localhost:3000'
950
+ // No fetchImpl - should fall back to globalThis.fetch
951
+ });
952
+ expect(result).toSucceed();
953
+ expect(fetchCallCount).toBeGreaterThan(0);
954
+ }
955
+ finally {
956
+ globalThis.fetch = originalFetch;
957
+ }
958
+ });
959
+ });
960
+ describe('userId header in _request()', () => {
961
+ test('includes X-User-Id header in PUT /file and POST /sync requests when userId is set', async () => {
962
+ var _a;
963
+ // Covers line 259: the this._userId branch in _request()
964
+ const { fetchImpl, calls } = makeMockFetch([
965
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
966
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
967
+ { ok: true, jsonValue: fileResponse('/data.json', '"updated"') },
968
+ { ok: true, jsonValue: { synced: 1 } }
969
+ ]);
970
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
971
+ baseUrl: 'http://localhost:3000',
972
+ fetchImpl,
973
+ mutable: true,
974
+ userId: 'test-user-123'
975
+ })).orThrow();
976
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
977
+ const result = await accessors.syncToDisk();
978
+ expect(result).toSucceed();
979
+ // The PUT and POST requests should include the X-User-Id header
980
+ const syncCalls = calls.slice(2);
981
+ for (const call of syncCalls) {
982
+ const headers = (_a = call.init) === null || _a === void 0 ? void 0 : _a.headers;
983
+ expect(headers === null || headers === void 0 ? void 0 : headers['X-User-Id']).toBe('test-user-123');
984
+ }
985
+ });
986
+ });
987
+ describe('deleteFile()', () => {
988
+ test('fails when the underlying InMemoryTreeAccessors deleteFile fails (file not found)', async () => {
989
+ // Covers lines 200-201: result.isFailure() branch in deleteFile
990
+ const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
991
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl, mutable: true })).orThrow();
992
+ // Delete a file that does not exist — super.deleteFile should fail
993
+ const result = accessors.deleteFile('/nonexistent.json');
994
+ expect(result).toFail();
995
+ });
996
+ test('includes namespace in DELETE query params when namespace is configured', async () => {
997
+ // Covers lines 131-132: the namespace branch in syncToDisk's pending-deletion loop
998
+ const { fetchImpl, calls } = makeMockFetch([
999
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
1000
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
1001
+ { ok: true, jsonValue: { deleted: true } },
1002
+ { ok: true, jsonValue: { synced: 0 } }
1003
+ ]);
1004
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1005
+ baseUrl: 'http://localhost:3000',
1006
+ namespace: 'my-namespace',
1007
+ fetchImpl,
1008
+ mutable: true
1009
+ })).orThrow();
1010
+ accessors.deleteFile('/data.json').orThrow();
1011
+ const result = await accessors.syncToDisk();
1012
+ expect(result).toSucceed();
1013
+ // The DELETE request URL should include namespace as a query parameter
1014
+ const deleteCalls = calls.filter((c) => { var _a; return ((_a = c.init) === null || _a === void 0 ? void 0 : _a.method) === 'DELETE'; });
1015
+ expect(deleteCalls).toHaveLength(1);
1016
+ expect(deleteCalls[0].url).toContain('namespace=my-namespace');
1017
+ });
1018
+ test('triggers fire-and-forget autoSync after successful delete when autoSync is enabled', async () => {
1019
+ // Covers lines 209-212: the autoSync branch in deleteFile
1020
+ const syncResponses = [
1021
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
1022
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
1023
+ // DELETE /file response for pending deletion
1024
+ { ok: true, jsonValue: { deleted: true } },
1025
+ // POST /sync response
1026
+ { ok: true, jsonValue: { synced: 0 } }
1027
+ ];
1028
+ const { fetchImpl, calls } = makeMockFetch(syncResponses);
1029
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1030
+ baseUrl: 'http://localhost:3000',
1031
+ fetchImpl,
1032
+ mutable: true,
1033
+ autoSync: true
1034
+ })).orThrow();
1035
+ const result = accessors.deleteFile('/data.json');
1036
+ expect(result).toSucceedWith(true);
1037
+ // autoSync fires-and-forgets; wait for microtasks to drain
1038
+ await new Promise((resolve) => setTimeout(resolve, 0));
1039
+ // Verify that DELETE + POST /sync were called
1040
+ const methodCalls = calls.slice(2).map((c) => { var _a; return (_a = c.init) === null || _a === void 0 ? void 0 : _a.method; });
1041
+ expect(methodCalls).toContain('DELETE');
1042
+ expect(methodCalls).toContain('POST');
1043
+ });
1044
+ });
1045
+ describe('_requestWithRetry()', () => {
1046
+ test('succeeds on second attempt after a transient 503 error', async () => {
1047
+ jest.useFakeTimers();
1048
+ try {
1049
+ // Responses: init (GET tree/children), then PUT fails with 503, then PUT succeeds, then POST /sync succeeds
1050
+ let callCount = 0;
1051
+ const fetchImpl = (_url, _init) => {
1052
+ callCount++;
1053
+ if (callCount === 1) {
1054
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
1055
+ }
1056
+ if (callCount === 2) {
1057
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
1058
+ }
1059
+ // First PUT attempt: transient 503
1060
+ if (callCount === 3) {
1061
+ return Promise.resolve(makeMockResponse({ ok: false, status: 503, textValue: '503 Service Unavailable' }));
1062
+ }
1063
+ // Second PUT attempt: success
1064
+ if (callCount === 4) {
1065
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '"updated"') }));
1066
+ }
1067
+ // POST /sync
1068
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: { synced: 1 } }));
1069
+ };
1070
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1071
+ baseUrl: 'http://localhost:3000',
1072
+ fetchImpl,
1073
+ mutable: true
1074
+ })).orThrow();
1075
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
1076
+ const syncPromise = accessors.syncToDisk();
1077
+ // Advance past the 500ms backoff for the first retry
1078
+ await jest.advanceTimersByTimeAsync(500);
1079
+ const result = await syncPromise;
1080
+ expect(result).toSucceed();
1081
+ // Three PUT-related calls: init (2) + first PUT attempt (1) + retry PUT (1) + POST sync (1)
1082
+ expect(callCount).toBe(5);
1083
+ }
1084
+ finally {
1085
+ jest.useRealTimers();
1086
+ }
1087
+ });
1088
+ test('does not retry on a non-transient error (e.g. 404)', async () => {
1089
+ jest.useFakeTimers();
1090
+ try {
1091
+ let callCount = 0;
1092
+ const fetchImpl = (_url, _init) => {
1093
+ callCount++;
1094
+ if (callCount === 1) {
1095
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
1096
+ }
1097
+ if (callCount === 2) {
1098
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
1099
+ }
1100
+ // PUT attempt: non-transient 404
1101
+ return Promise.resolve(makeMockResponse({ ok: false, status: 404, textValue: 'Not Found' }));
1102
+ };
1103
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1104
+ baseUrl: 'http://localhost:3000',
1105
+ fetchImpl,
1106
+ mutable: true
1107
+ })).orThrow();
1108
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
1109
+ const result = await accessors.syncToDisk();
1110
+ // No timers should need advancing - non-transient errors return immediately
1111
+ expect(result).toFailWith(/not found/i);
1112
+ // Only 3 calls: 2 init + 1 PUT (no retries)
1113
+ expect(callCount).toBe(3);
1114
+ }
1115
+ finally {
1116
+ jest.useRealTimers();
1117
+ }
1118
+ });
1119
+ test('returns the last error after exhausting all retries on persistent transient errors', async () => {
1120
+ jest.useFakeTimers();
1121
+ try {
1122
+ let callCount = 0;
1123
+ const fetchImpl = (_url, _init) => {
1124
+ callCount++;
1125
+ if (callCount === 1) {
1126
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
1127
+ }
1128
+ if (callCount === 2) {
1129
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
1130
+ }
1131
+ // All PUT attempts: transient 502 every time
1132
+ return Promise.resolve(makeMockResponse({ ok: false, status: 502, textValue: '502 Bad Gateway' }));
1133
+ };
1134
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1135
+ baseUrl: 'http://localhost:3000',
1136
+ fetchImpl,
1137
+ mutable: true
1138
+ })).orThrow();
1139
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
1140
+ const syncPromise = accessors.syncToDisk();
1141
+ // Advance past both backoff delays: 500ms (attempt 1) + 1000ms (attempt 2)
1142
+ await jest.advanceTimersByTimeAsync(1500);
1143
+ const result = await syncPromise;
1144
+ expect(result).toFailWith(/502 bad gateway/i);
1145
+ // 2 init + 3 PUT attempts (maxAttempts = 3)
1146
+ expect(callCount).toBe(5);
1147
+ }
1148
+ finally {
1149
+ jest.useRealTimers();
1150
+ }
1151
+ });
1152
+ test('logs retry message with method name from init when retrying', async () => {
1153
+ jest.useFakeTimers();
1154
+ try {
1155
+ const logger = {
1156
+ detail: jest.fn(),
1157
+ info: jest.fn(),
1158
+ warn: jest.fn(),
1159
+ error: jest.fn()
1160
+ };
1161
+ let callCount = 0;
1162
+ const fetchImpl = (_url, _init) => {
1163
+ callCount++;
1164
+ if (callCount === 1) {
1165
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
1166
+ }
1167
+ if (callCount === 2) {
1168
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
1169
+ }
1170
+ // First PUT attempt: transient 503
1171
+ if (callCount === 3) {
1172
+ return Promise.resolve(makeMockResponse({ ok: false, status: 503, textValue: '503 Service Unavailable' }));
1173
+ }
1174
+ // Second PUT attempt: success
1175
+ if (callCount === 4) {
1176
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '"updated"') }));
1177
+ }
1178
+ // POST /sync
1179
+ return Promise.resolve(makeMockResponse({ ok: true, jsonValue: { synced: 1 } }));
1180
+ };
1181
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1182
+ baseUrl: 'http://localhost:3000',
1183
+ fetchImpl,
1184
+ mutable: true,
1185
+ logger
1186
+ })).orThrow();
1187
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
1188
+ const syncPromise = accessors.syncToDisk();
1189
+ await jest.advanceTimersByTimeAsync(500);
1190
+ await syncPromise;
1191
+ // The retry log message should include the method name (PUT) from init
1192
+ expect(logger.detail).toHaveBeenCalledWith(expect.stringContaining('PUT'));
1193
+ }
1194
+ finally {
1195
+ jest.useRealTimers();
1196
+ }
1197
+ });
1198
+ });
1199
+ describe('syncToDisk() concurrency guard', () => {
1200
+ test('concurrent syncToDisk calls share the same promise and only make one set of network calls', async () => {
1201
+ const { fetchImpl, calls } = makeMockFetch([
1202
+ { ok: true, jsonValue: rootWithOneFile('data.json') },
1203
+ { ok: true, jsonValue: fileResponse('/data.json', '{}') },
1204
+ // PUT /file for the single sync
1205
+ { ok: true, jsonValue: fileResponse('/data.json', '"updated"') },
1206
+ // POST /sync
1207
+ { ok: true, jsonValue: { synced: 1 } }
1208
+ ]);
1209
+ const accessors = (await file_tree_1.HttpTreeAccessors.fromHttp({
1210
+ baseUrl: 'http://localhost:3000',
1211
+ fetchImpl,
1212
+ mutable: true
1213
+ })).orThrow();
1214
+ accessors.saveFileContents('/data.json', '"updated"').orThrow();
1215
+ // Start two concurrent syncToDisk calls without awaiting the first
1216
+ const promise1 = accessors.syncToDisk();
1217
+ const promise2 = accessors.syncToDisk();
1218
+ const [result1, result2] = await Promise.all([promise1, promise2]);
1219
+ expect(result1).toSucceed();
1220
+ expect(result2).toSucceed();
1221
+ // Both promises should have resolved to the same underlying promise result.
1222
+ // Only one PUT and one POST /sync should have been issued (not doubled).
1223
+ const syncCalls = calls.slice(2);
1224
+ const putCalls = syncCalls.filter((c) => { var _a; return ((_a = c.init) === null || _a === void 0 ? void 0 : _a.method) === 'PUT'; });
1225
+ const postCalls = syncCalls.filter((c) => { var _a; return ((_a = c.init) === null || _a === void 0 ? void 0 : _a.method) === 'POST'; });
1226
+ expect(putCalls).toHaveLength(1);
1227
+ expect(postCalls).toHaveLength(1);
1228
+ });
1229
+ });
1230
+ });
1231
+ //# sourceMappingURL=httpTreeAccessors.test.js.map