@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.
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +58 -25
- package/.rush/temp/chunked-rush-logs/ts-web-extras.test.chunks.jsonl +70 -0
- package/.rush/temp/operation/build/all.log +58 -25
- package/.rush/temp/operation/build/error.log +18 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +58 -25
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/operation/test/all.log +70 -0
- package/.rush/temp/operation/test/error.log +16 -0
- package/.rush/temp/operation/test/log-chunks.jsonl +70 -0
- package/.rush/temp/operation/test/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +175 -163
- package/config/jest.config.json +4 -1
- package/config/typedoc.json +6 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/packlets/crypto-utils/browserCryptoProvider.js +254 -0
- package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -0
- package/dist/packlets/crypto-utils/browserHashProvider.js.map +1 -0
- package/dist/packlets/{crypto → crypto-utils}/index.js +1 -0
- package/dist/packlets/crypto-utils/index.js.map +1 -0
- package/dist/packlets/file-api-types/index.js +27 -3
- package/dist/packlets/file-api-types/index.js.map +1 -1
- package/dist/packlets/file-tree/directoryHandleStore.js +124 -0
- package/dist/packlets/file-tree/directoryHandleStore.js.map +1 -0
- package/dist/packlets/file-tree/fileApiTreeAccessors.js +91 -0
- package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
- package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +414 -0
- package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -0
- package/dist/packlets/file-tree/httpTreeAccessors.js +279 -0
- package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -0
- package/dist/packlets/file-tree/index.js +4 -0
- package/dist/packlets/file-tree/index.js.map +1 -1
- package/dist/packlets/file-tree/localStorageTreeAccessors.js +359 -0
- package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -0
- package/dist/test/mocks/idb-keyval.js +6 -0
- package/dist/test/mocks/idb-keyval.js.map +1 -0
- package/dist/test/unit/browserHashProvider.test.js +1 -1
- package/dist/test/unit/browserHashProvider.test.js.map +1 -1
- package/dist/test/unit/directoryHandleStore.test.js +190 -0
- package/dist/test/unit/directoryHandleStore.test.js.map +1 -0
- package/dist/test/unit/fileApiTreeAccessors.test.js +51 -0
- package/dist/test/unit/fileApiTreeAccessors.test.js.map +1 -1
- package/dist/test/unit/fileApiTypes.test.js +30 -0
- package/dist/test/unit/fileApiTypes.test.js.map +1 -1
- package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +622 -0
- package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -0
- package/dist/test/unit/httpTreeAccessors.test.js +1000 -0
- package/dist/test/unit/httpTreeAccessors.test.js.map +1 -0
- package/dist/test/unit/localStorageTreeAccessors.test.js +812 -0
- package/dist/test/unit/localStorageTreeAccessors.test.js.map +1 -0
- package/dist/test/utils/fileSystemAccessMocks.js +271 -0
- package/dist/test/utils/fileSystemAccessMocks.js.map +1 -0
- package/dist/ts-web-extras.d.ts +584 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/docs/@fgv/namespaces/CryptoUtils/README.md +18 -0
- package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserCryptoProvider.md +203 -0
- package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserHashProvider.md +63 -0
- package/docs/@fgv/namespaces/CryptoUtils/functions/createBrowserCryptoProvider.md +18 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/README.md +19 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileListMetadata.md +23 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileMetadata.md +23 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromDirectoryUpload.md +33 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromFileList.md +33 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/getOriginalFile.md +25 -0
- package/docs/@fgv/namespaces/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +11 -0
- package/docs/README.md +78 -0
- package/docs/classes/DirectoryHandleStore.md +116 -0
- package/docs/classes/FileApiTreeAccessors.md +286 -0
- package/docs/classes/FileSystemAccessTreeAccessors.md +557 -0
- package/docs/classes/HttpTreeAccessors.md +508 -0
- package/docs/classes/LocalStorageTreeAccessors.md +520 -0
- package/docs/functions/exportAsJson.md +23 -0
- package/docs/functions/exportUsingFileSystemAPI.md +26 -0
- package/docs/functions/extractDirectoryPath.md +23 -0
- package/docs/functions/isDirectoryHandle.md +23 -0
- package/docs/functions/isFileHandle.md +23 -0
- package/docs/functions/isFilePath.md +21 -0
- package/docs/functions/parseContextFilter.md +22 -0
- package/docs/functions/parseQualifierDefaults.md +22 -0
- package/docs/functions/parseResourceTypes.md +22 -0
- package/docs/functions/parseUrlParameters.md +15 -0
- package/docs/functions/safeShowDirectoryPicker.md +24 -0
- package/docs/functions/safeShowOpenFilePicker.md +24 -0
- package/docs/functions/safeShowSaveFilePicker.md +24 -0
- package/docs/functions/supportsFileSystemAccess.md +23 -0
- package/docs/interfaces/FilePickerAcceptType.md +16 -0
- package/docs/interfaces/FileSystemCreateWritableOptions.md +15 -0
- package/docs/interfaces/FileSystemDirectoryHandle.md +187 -0
- package/docs/interfaces/FileSystemFileHandle.md +106 -0
- package/docs/interfaces/FileSystemGetDirectoryOptions.md +15 -0
- package/docs/interfaces/FileSystemGetFileOptions.md +15 -0
- package/docs/interfaces/FileSystemHandle.md +69 -0
- package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +15 -0
- package/docs/interfaces/FileSystemRemoveOptions.md +15 -0
- package/docs/interfaces/FileSystemWritableFileStream.md +127 -0
- package/docs/interfaces/IDirectoryHandleTreeInitializer.md +17 -0
- package/docs/interfaces/IFileHandleTreeInitializer.md +16 -0
- package/docs/interfaces/IFileListTreeInitializer.md +15 -0
- package/docs/interfaces/IFileMetadata.md +19 -0
- package/docs/interfaces/IFileSystemAccessTreeParams.md +30 -0
- package/docs/interfaces/IFsAccessApis.md +57 -0
- package/docs/interfaces/IHttpTreeParams.md +32 -0
- package/docs/interfaces/ILocalStorageTreeParams.md +30 -0
- package/docs/interfaces/IUrlConfigOptions.md +27 -0
- package/docs/interfaces/ShowDirectoryPickerOptions.md +17 -0
- package/docs/interfaces/ShowOpenFilePickerOptions.md +19 -0
- package/docs/interfaces/ShowSaveFilePickerOptions.md +19 -0
- package/docs/type-aliases/TreeInitializer.md +11 -0
- package/docs/type-aliases/WellKnownDirectory.md +11 -0
- package/docs/type-aliases/WindowWithFsAccess.md +11 -0
- package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +11 -0
- package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +11 -0
- package/etc/ts-web-extras.api.md +124 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -2
- package/lib/index.js.map +1 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +77 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.js +259 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -0
- package/lib/packlets/crypto-utils/browserHashProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/browserHashProvider.js.map +1 -0
- package/lib/packlets/{crypto → crypto-utils}/index.d.ts +1 -0
- package/lib/packlets/crypto-utils/index.d.ts.map +1 -0
- package/lib/packlets/{crypto → crypto-utils}/index.js +1 -0
- package/lib/packlets/crypto-utils/index.js.map +1 -0
- package/lib/packlets/file-api-types/index.d.ts.map +1 -1
- package/lib/packlets/file-api-types/index.js +27 -3
- package/lib/packlets/file-api-types/index.js.map +1 -1
- package/lib/packlets/file-tree/directoryHandleStore.d.ts +59 -0
- package/lib/packlets/file-tree/directoryHandleStore.d.ts.map +1 -0
- package/lib/packlets/file-tree/directoryHandleStore.js +128 -0
- package/lib/packlets/file-tree/directoryHandleStore.js.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +66 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
- package/lib/packlets/file-tree/fileApiTreeAccessors.js +91 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts +152 -0
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +418 -0
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/httpTreeAccessors.d.ts +88 -0
- package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/httpTreeAccessors.js +283 -0
- package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts +4 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -1
- package/lib/packlets/file-tree/index.js +4 -0
- package/lib/packlets/file-tree/index.js.map +1 -1
- package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts +141 -0
- package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/localStorageTreeAccessors.js +363 -0
- package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -0
- package/lib/test/mocks/idb-keyval.d.ts +6 -0
- package/lib/test/mocks/idb-keyval.d.ts.map +1 -0
- package/lib/test/mocks/idb-keyval.js +9 -0
- package/lib/test/mocks/idb-keyval.js.map +1 -0
- package/lib/test/unit/browserHashProvider.test.js +21 -21
- package/lib/test/unit/browserHashProvider.test.js.map +1 -1
- package/lib/test/unit/directoryHandleStore.test.d.ts +2 -0
- package/lib/test/unit/directoryHandleStore.test.d.ts.map +1 -0
- package/lib/test/unit/directoryHandleStore.test.js +192 -0
- package/lib/test/unit/directoryHandleStore.test.js.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js +51 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -1
- package/lib/test/unit/fileApiTypes.test.js +30 -0
- package/lib/test/unit/fileApiTypes.test.js.map +1 -1
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +624 -0
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -0
- package/lib/test/unit/httpTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/httpTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/httpTreeAccessors.test.js +1002 -0
- package/lib/test/unit/httpTreeAccessors.test.js.map +1 -0
- package/lib/test/unit/localStorageTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/localStorageTreeAccessors.test.js +814 -0
- package/lib/test/unit/localStorageTreeAccessors.test.js.map +1 -0
- package/lib/test/utils/fileSystemAccessMocks.d.ts +53 -0
- package/lib/test/utils/fileSystemAccessMocks.d.ts.map +1 -0
- package/lib/test/utils/fileSystemAccessMocks.js +277 -0
- package/lib/test/utils/fileSystemAccessMocks.js.map +1 -0
- package/package.json +41 -34
- package/rush-logs/ts-web-extras.build.cache.log +0 -1
- package/rush-logs/ts-web-extras.build.error.log +18 -0
- package/rush-logs/ts-web-extras.build.log +58 -25
- package/rush-logs/ts-web-extras.test.cache.log +1 -0
- package/rush-logs/ts-web-extras.test.error.log +16 -0
- package/rush-logs/ts-web-extras.test.log +70 -0
- package/src/index.ts +2 -2
- package/src/packlets/crypto-utils/browserCryptoProvider.ts +311 -0
- package/src/packlets/{crypto → crypto-utils}/index.ts +1 -0
- package/src/packlets/file-api-types/index.ts +24 -3
- package/src/packlets/file-tree/directoryHandleStore.ts +136 -0
- package/src/packlets/file-tree/fileApiTreeAccessors.ts +108 -0
- package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +519 -0
- package/src/packlets/file-tree/httpTreeAccessors.ts +381 -0
- package/src/packlets/file-tree/index.ts +4 -0
- package/src/packlets/file-tree/localStorageTreeAccessors.ts +430 -0
- package/src/test/mocks/idb-keyval.ts +5 -0
- package/src/test/unit/browserHashProvider.test.ts +1 -1
- package/src/test/unit/directoryHandleStore.test.ts +251 -0
- package/src/test/unit/fileApiTreeAccessors.test.ts +69 -0
- package/src/test/unit/fileApiTypes.test.ts +36 -0
- package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +885 -0
- package/src/test/unit/httpTreeAccessors.test.ts +1278 -0
- package/src/test/unit/localStorageTreeAccessors.test.ts +1014 -0
- package/src/test/utils/fileSystemAccessMocks.ts +353 -0
- package/temp/build/typescript/ts_8nwakTlr.json +1 -0
- package/temp/coverage/crypto/browserHashProvider.ts.html +1 -1
- package/temp/coverage/crypto/index.html +1 -1
- package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +1018 -0
- package/temp/coverage/crypto-utils/browserHashProvider.ts.html +304 -0
- package/temp/coverage/crypto-utils/index.html +131 -0
- package/temp/coverage/file-tree/directoryHandleStore.ts.html +493 -0
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +330 -6
- package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +1642 -0
- package/temp/coverage/file-tree/httpTreeAccessors.ts.html +1228 -0
- package/temp/coverage/file-tree/index.html +69 -9
- package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +1375 -0
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
- package/temp/coverage/helpers/index.html +1 -1
- package/temp/coverage/index.html +13 -13
- package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +1 -1
- package/temp/coverage/lcov-report/crypto/index.html +1 -1
- package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +1018 -0
- package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +304 -0
- package/temp/coverage/lcov-report/crypto-utils/index.html +131 -0
- package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +493 -0
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +330 -6
- package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +1642 -0
- package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +1228 -0
- package/temp/coverage/lcov-report/file-tree/index.html +69 -9
- package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +1375 -0
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
- package/temp/coverage/lcov-report/helpers/index.html +1 -1
- package/temp/coverage/lcov-report/index.html +13 -13
- package/temp/coverage/lcov-report/url-utils/index.html +1 -1
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
- package/temp/coverage/lcov.info +2829 -428
- package/temp/coverage/url-utils/index.html +1 -1
- package/temp/coverage/url-utils/urlParams.ts.html +1 -1
- package/temp/test/jest/haste-map-b931e4e63102f86c5bd4949f7dced44f-9d713eb41149188b4e5c0ae3d86d0a57-2ad8e16b24e391b8cdbe50b55c137169 +0 -0
- package/temp/test/jest/perf-cache-b931e4e63102f86c5bd4949f7dced44f-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
- package/temp/ts-web-extras.api.json +5282 -1472
- package/temp/ts-web-extras.api.md +124 -1
- package/dist/packlets/crypto/browserHashProvider.js.map +0 -1
- package/dist/packlets/crypto/index.js.map +0 -1
- package/docs/index.md +0 -34
- package/docs/ts-web-extras.browserhashprovider.hashparts.md +0 -88
- package/docs/ts-web-extras.browserhashprovider.hashstring.md +0 -72
- package/docs/ts-web-extras.browserhashprovider.md +0 -66
- package/docs/ts-web-extras.exportasjson.md +0 -70
- package/docs/ts-web-extras.exportusingfilesystemapi.md +0 -104
- package/docs/ts-web-extras.extractdirectorypath.md +0 -52
- package/docs/ts-web-extras.fileapitreeaccessors.create.md +0 -72
- package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +0 -54
- package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +0 -72
- package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +0 -72
- package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +0 -72
- package/docs/ts-web-extras.fileapitreeaccessors.md +0 -114
- package/docs/ts-web-extras.filepickeraccepttype.accept.md +0 -11
- package/docs/ts-web-extras.filepickeraccepttype.description.md +0 -11
- package/docs/ts-web-extras.filepickeraccepttype.md +0 -75
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +0 -11
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +0 -58
- package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +0 -15
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +0 -15
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +0 -66
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +0 -66
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +0 -15
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +0 -11
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +0 -146
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +0 -66
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +0 -50
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +0 -15
- package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +0 -52
- package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +0 -15
- package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +0 -11
- package/docs/ts-web-extras.filesystemfilehandle_2.md +0 -92
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +0 -11
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +0 -58
- package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +0 -11
- package/docs/ts-web-extras.filesystemgetfileoptions_2.md +0 -58
- package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +0 -50
- package/docs/ts-web-extras.filesystemhandle_2.kind.md +0 -11
- package/docs/ts-web-extras.filesystemhandle_2.md +0 -119
- package/docs/ts-web-extras.filesystemhandle_2.name.md +0 -11
- package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +0 -52
- package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +0 -52
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +0 -58
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +0 -11
- package/docs/ts-web-extras.filesystemremoveoptions_2.md +0 -58
- package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +0 -11
- package/docs/ts-web-extras.filesystemwritablefilestream_2.md +0 -57
- package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +0 -50
- package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +0 -50
- package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +0 -50
- package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +0 -13
- package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +0 -56
- package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +0 -56
- package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +0 -76
- package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +0 -76
- package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +0 -72
- package/docs/ts-web-extras.filetreehelpers.md +0 -102
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +0 -11
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +0 -100
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +0 -11
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +0 -11
- package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +0 -11
- package/docs/ts-web-extras.ifilehandletreeinitializer.md +0 -79
- package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +0 -11
- package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +0 -11
- package/docs/ts-web-extras.ifilelisttreeinitializer.md +0 -58
- package/docs/ts-web-extras.ifilemetadata.lastmodified.md +0 -11
- package/docs/ts-web-extras.ifilemetadata.md +0 -124
- package/docs/ts-web-extras.ifilemetadata.name.md +0 -11
- package/docs/ts-web-extras.ifilemetadata.path.md +0 -11
- package/docs/ts-web-extras.ifilemetadata.size.md +0 -11
- package/docs/ts-web-extras.ifilemetadata.type.md +0 -11
- package/docs/ts-web-extras.ifsaccessapis.md +0 -56
- package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +0 -52
- package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +0 -52
- package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +0 -52
- package/docs/ts-web-extras.isdirectoryhandle.md +0 -56
- package/docs/ts-web-extras.isfilehandle.md +0 -56
- package/docs/ts-web-extras.isfilepath.md +0 -52
- package/docs/ts-web-extras.iurlconfigoptions.config.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.input.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.interactive.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.md +0 -286
- package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +0 -13
- package/docs/ts-web-extras.iurlconfigoptions.zippath.md +0 -13
- package/docs/ts-web-extras.md +0 -512
- package/docs/ts-web-extras.parsecontextfilter.md +0 -52
- package/docs/ts-web-extras.parsequalifierdefaults.md +0 -52
- package/docs/ts-web-extras.parseresourcetypes.md +0 -52
- package/docs/ts-web-extras.parseurlparameters.md +0 -17
- package/docs/ts-web-extras.safeshowdirectorypicker.md +0 -72
- package/docs/ts-web-extras.safeshowopenfilepicker.md +0 -72
- package/docs/ts-web-extras.safeshowsavefilepicker.md +0 -72
- package/docs/ts-web-extras.showdirectorypickeroptions.id.md +0 -11
- package/docs/ts-web-extras.showdirectorypickeroptions.md +0 -96
- package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +0 -11
- package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +0 -11
- package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +0 -11
- package/docs/ts-web-extras.showopenfilepickeroptions.id.md +0 -11
- package/docs/ts-web-extras.showopenfilepickeroptions.md +0 -134
- package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +0 -11
- package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +0 -11
- package/docs/ts-web-extras.showopenfilepickeroptions.types.md +0 -11
- package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +0 -11
- package/docs/ts-web-extras.showsavefilepickeroptions.id.md +0 -11
- package/docs/ts-web-extras.showsavefilepickeroptions.md +0 -134
- package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +0 -11
- package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +0 -11
- package/docs/ts-web-extras.showsavefilepickeroptions.types.md +0 -11
- package/docs/ts-web-extras.supportsfilesystemaccess.md +0 -56
- package/docs/ts-web-extras.treeinitializer.md +0 -15
- package/docs/ts-web-extras.wellknowndirectory.md +0 -13
- package/docs/ts-web-extras.windowwithfsaccess.md +0 -15
- package/lib/packlets/crypto/browserHashProvider.d.ts.map +0 -1
- package/lib/packlets/crypto/browserHashProvider.js.map +0 -1
- package/lib/packlets/crypto/index.d.ts.map +0 -1
- package/lib/packlets/crypto/index.js.map +0 -1
- package/temp/build/typescript/ts_vnCx6LlY.json +0 -1
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
- /package/dist/packlets/{crypto → crypto-utils}/browserHashProvider.js +0 -0
- /package/lib/packlets/{crypto → crypto-utils}/browserHashProvider.d.ts +0 -0
- /package/lib/packlets/{crypto → crypto-utils}/browserHashProvider.js +0 -0
- /package/src/packlets/{crypto → crypto-utils}/browserHashProvider.ts +0 -0
- /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,1000 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import '@fgv/ts-utils-jest';
|
|
23
|
+
import { fail } from '@fgv/ts-utils';
|
|
24
|
+
import { HttpTreeAccessors } from '../../packlets/file-tree';
|
|
25
|
+
function makeMockResponse(options) {
|
|
26
|
+
const { ok, status = ok ? 200 : 400, jsonValue, textValue, throwOnJson, throwOnText } = options;
|
|
27
|
+
return {
|
|
28
|
+
ok,
|
|
29
|
+
status,
|
|
30
|
+
json: throwOnJson
|
|
31
|
+
? () => Promise.reject(new Error('JSON parse error'))
|
|
32
|
+
: () => Promise.resolve(jsonValue),
|
|
33
|
+
text: throwOnText
|
|
34
|
+
? () => Promise.reject(new Error('text error'))
|
|
35
|
+
: () => Promise.resolve(textValue !== null && textValue !== void 0 ? textValue : `HTTP ${status}`)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a mock fetch function that returns responses for each call in order.
|
|
40
|
+
* Each entry maps to one fetch() invocation in call order.
|
|
41
|
+
*/
|
|
42
|
+
function makeMockFetch(responses) {
|
|
43
|
+
const calls = [];
|
|
44
|
+
let callIndex = 0;
|
|
45
|
+
const fetchImpl = (url, init) => {
|
|
46
|
+
calls.push({ url: url.toString(), init });
|
|
47
|
+
const response = responses[callIndex++];
|
|
48
|
+
if (response === undefined) {
|
|
49
|
+
return Promise.reject(new Error(`Unexpected fetch call #${callIndex} to ${url.toString()}`));
|
|
50
|
+
}
|
|
51
|
+
return Promise.resolve(makeMockResponse(response));
|
|
52
|
+
};
|
|
53
|
+
return { fetchImpl: fetchImpl, calls };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a mock fetch function that throws a network error on every call.
|
|
57
|
+
*/
|
|
58
|
+
function makeThrowingFetch(message) {
|
|
59
|
+
return (_url, _init) => {
|
|
60
|
+
return Promise.reject(new Error(message));
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// ---- Shared test data builders ----
|
|
64
|
+
/** Minimal tree-children response for a single file at root. */
|
|
65
|
+
function rootWithOneFile(fileName = 'data.json') {
|
|
66
|
+
return {
|
|
67
|
+
path: '/',
|
|
68
|
+
children: [{ path: `/${fileName}`, name: fileName, type: 'file' }]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** File response for a JSON file. */
|
|
72
|
+
function fileResponse(path, contents, contentType) {
|
|
73
|
+
const response = { path, contents };
|
|
74
|
+
if (contentType !== undefined) {
|
|
75
|
+
response.contentType = contentType;
|
|
76
|
+
}
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
/** Root children response containing a subdirectory and a file. */
|
|
80
|
+
function rootWithDirAndFile() {
|
|
81
|
+
return {
|
|
82
|
+
path: '/',
|
|
83
|
+
children: [
|
|
84
|
+
{ path: '/subdir', name: 'subdir', type: 'directory' },
|
|
85
|
+
{ path: '/root.json', name: 'root.json', type: 'file' }
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Children response for /subdir containing one file. */
|
|
90
|
+
function subdirWithOneFile() {
|
|
91
|
+
return {
|
|
92
|
+
path: '/subdir',
|
|
93
|
+
children: [{ path: '/subdir/nested.json', name: 'nested.json', type: 'file' }]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// ---- Tests ----
|
|
97
|
+
describe('HttpTreeAccessors', () => {
|
|
98
|
+
describe('fromHttp()', () => {
|
|
99
|
+
test('succeeds with an empty directory (no children)', async () => {
|
|
100
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
101
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
102
|
+
baseUrl: 'http://localhost:3000',
|
|
103
|
+
fetchImpl
|
|
104
|
+
});
|
|
105
|
+
expect(result).toSucceedAndSatisfy((accessors) => {
|
|
106
|
+
expect(accessors).toBeInstanceOf(HttpTreeAccessors);
|
|
107
|
+
expect(accessors.isDirty()).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
test('succeeds and loads a single file at root', async () => {
|
|
111
|
+
const { fetchImpl } = makeMockFetch([
|
|
112
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
113
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{"items":{}}') }
|
|
114
|
+
]);
|
|
115
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
116
|
+
baseUrl: 'http://localhost:3000',
|
|
117
|
+
fetchImpl,
|
|
118
|
+
mutable: true
|
|
119
|
+
});
|
|
120
|
+
expect(result).toSucceedAndSatisfy((accessors) => {
|
|
121
|
+
expect(accessors.getFileContents('/data.json')).toSucceedWith('{"items":{}}');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
test('succeeds with multiple files at root', async () => {
|
|
125
|
+
const { fetchImpl } = makeMockFetch([
|
|
126
|
+
{
|
|
127
|
+
ok: true,
|
|
128
|
+
jsonValue: {
|
|
129
|
+
path: '/',
|
|
130
|
+
children: [
|
|
131
|
+
{ path: '/alpha.json', name: 'alpha.json', type: 'file' },
|
|
132
|
+
{ path: '/beta.json', name: 'beta.json', type: 'file' }
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{ ok: true, jsonValue: fileResponse('/alpha.json', '"alpha"') },
|
|
137
|
+
{ ok: true, jsonValue: fileResponse('/beta.json', '"beta"') }
|
|
138
|
+
]);
|
|
139
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
140
|
+
baseUrl: 'http://localhost:3000',
|
|
141
|
+
fetchImpl,
|
|
142
|
+
mutable: true
|
|
143
|
+
});
|
|
144
|
+
expect(result).toSucceedAndSatisfy((accessors) => {
|
|
145
|
+
expect(accessors.getFileContents('/alpha.json')).toSucceedWith('"alpha"');
|
|
146
|
+
expect(accessors.getFileContents('/beta.json')).toSucceedWith('"beta"');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
test('succeeds and recursively loads files in subdirectories', async () => {
|
|
150
|
+
const { fetchImpl } = makeMockFetch([
|
|
151
|
+
{ ok: true, jsonValue: rootWithDirAndFile() },
|
|
152
|
+
{ ok: true, jsonValue: subdirWithOneFile() },
|
|
153
|
+
{ ok: true, jsonValue: fileResponse('/subdir/nested.json', '"nested"') },
|
|
154
|
+
{ ok: true, jsonValue: fileResponse('/root.json', '"root"') }
|
|
155
|
+
]);
|
|
156
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
157
|
+
baseUrl: 'http://localhost:3000',
|
|
158
|
+
fetchImpl,
|
|
159
|
+
mutable: true
|
|
160
|
+
});
|
|
161
|
+
expect(result).toSucceedAndSatisfy((accessors) => {
|
|
162
|
+
expect(accessors.getFileContents('/subdir/nested.json')).toSucceedWith('"nested"');
|
|
163
|
+
expect(accessors.getFileContents('/root.json')).toSucceedWith('"root"');
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
test('strips trailing slash from baseUrl', async () => {
|
|
167
|
+
const { fetchImpl, calls } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
168
|
+
await HttpTreeAccessors.fromHttp({
|
|
169
|
+
baseUrl: 'http://localhost:3000/',
|
|
170
|
+
fetchImpl
|
|
171
|
+
});
|
|
172
|
+
// The URL should start with the base URL without a trailing slash, then /tree/children
|
|
173
|
+
expect(calls[0].url).toMatch(/^http:\/\/localhost:3000\/tree\/children/);
|
|
174
|
+
// There should be no double slash in the path portion (after the protocol)
|
|
175
|
+
const urlPath = calls[0].url.replace('http://', '');
|
|
176
|
+
expect(urlPath).not.toContain('//');
|
|
177
|
+
});
|
|
178
|
+
test('includes namespace in query parameters when provided', async () => {
|
|
179
|
+
const { fetchImpl, calls } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
180
|
+
await HttpTreeAccessors.fromHttp({
|
|
181
|
+
baseUrl: 'http://localhost:3000',
|
|
182
|
+
namespace: 'my-namespace',
|
|
183
|
+
fetchImpl
|
|
184
|
+
});
|
|
185
|
+
expect(calls[0].url).toContain('namespace=my-namespace');
|
|
186
|
+
});
|
|
187
|
+
test('omits namespace from query parameters when not provided', async () => {
|
|
188
|
+
const { fetchImpl, calls } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
189
|
+
await HttpTreeAccessors.fromHttp({
|
|
190
|
+
baseUrl: 'http://localhost:3000',
|
|
191
|
+
fetchImpl
|
|
192
|
+
});
|
|
193
|
+
expect(calls[0].url).not.toContain('namespace');
|
|
194
|
+
});
|
|
195
|
+
test('applies prefix parameter to loaded file paths', async () => {
|
|
196
|
+
const { fetchImpl } = makeMockFetch([
|
|
197
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
198
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{"items":{}}') }
|
|
199
|
+
]);
|
|
200
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
201
|
+
baseUrl: 'http://localhost:3000',
|
|
202
|
+
prefix: '/app',
|
|
203
|
+
fetchImpl,
|
|
204
|
+
mutable: true
|
|
205
|
+
});
|
|
206
|
+
expect(result).toSucceedAndSatisfy((accessors) => {
|
|
207
|
+
expect(accessors.getFileContents('/app/data.json')).toSucceedWith('{"items":{}}');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
test('fails when the initial children fetch fails with a network error', async () => {
|
|
211
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
212
|
+
baseUrl: 'http://localhost:3000',
|
|
213
|
+
fetchImpl: makeThrowingFetch('Network unreachable')
|
|
214
|
+
});
|
|
215
|
+
expect(result).toFailWith(/network unreachable/i);
|
|
216
|
+
});
|
|
217
|
+
test('fails when the children response is not ok', async () => {
|
|
218
|
+
const { fetchImpl } = makeMockFetch([{ ok: false, status: 404, textValue: 'Not Found' }]);
|
|
219
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
220
|
+
baseUrl: 'http://localhost:3000',
|
|
221
|
+
fetchImpl
|
|
222
|
+
});
|
|
223
|
+
expect(result).toFailWith(/not found/i);
|
|
224
|
+
});
|
|
225
|
+
test('fails when the children response contains invalid JSON', async () => {
|
|
226
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, throwOnJson: true }]);
|
|
227
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
228
|
+
baseUrl: 'http://localhost:3000',
|
|
229
|
+
fetchImpl
|
|
230
|
+
});
|
|
231
|
+
expect(result).toFailWith(/invalid json/i);
|
|
232
|
+
});
|
|
233
|
+
test('fails when a file fetch fails with a network error', async () => {
|
|
234
|
+
let callCount = 0;
|
|
235
|
+
const fetchImpl = (_url, _init) => {
|
|
236
|
+
callCount++;
|
|
237
|
+
if (callCount === 1) {
|
|
238
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
|
|
239
|
+
}
|
|
240
|
+
return Promise.reject(new Error('File fetch failed'));
|
|
241
|
+
};
|
|
242
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
243
|
+
baseUrl: 'http://localhost:3000',
|
|
244
|
+
fetchImpl
|
|
245
|
+
});
|
|
246
|
+
expect(result).toFailWith(/file fetch failed/i);
|
|
247
|
+
});
|
|
248
|
+
test('fails when a file response is not ok', async () => {
|
|
249
|
+
const { fetchImpl } = makeMockFetch([
|
|
250
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
251
|
+
{ ok: false, status: 403, textValue: 'Forbidden' }
|
|
252
|
+
]);
|
|
253
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
254
|
+
baseUrl: 'http://localhost:3000',
|
|
255
|
+
fetchImpl
|
|
256
|
+
});
|
|
257
|
+
expect(result).toFailWith(/forbidden/i);
|
|
258
|
+
});
|
|
259
|
+
test('fails when a file response contains invalid JSON', async () => {
|
|
260
|
+
const { fetchImpl } = makeMockFetch([
|
|
261
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
262
|
+
{ ok: true, throwOnJson: true }
|
|
263
|
+
]);
|
|
264
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
265
|
+
baseUrl: 'http://localhost:3000',
|
|
266
|
+
fetchImpl
|
|
267
|
+
});
|
|
268
|
+
expect(result).toFailWith(/invalid json/i);
|
|
269
|
+
});
|
|
270
|
+
test('fails when a nested directory fetch fails', async () => {
|
|
271
|
+
const { fetchImpl } = makeMockFetch([
|
|
272
|
+
{ ok: true, jsonValue: rootWithDirAndFile() },
|
|
273
|
+
{ ok: false, status: 500, textValue: 'Internal Server Error' }
|
|
274
|
+
]);
|
|
275
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
276
|
+
baseUrl: 'http://localhost:3000',
|
|
277
|
+
fetchImpl
|
|
278
|
+
});
|
|
279
|
+
expect(result).toFailWith(/internal server error/i);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
describe('isDirty() and getDirtyPaths()', () => {
|
|
283
|
+
test('starts not dirty after loading', async () => {
|
|
284
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
285
|
+
const accessors = (await HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl })).orThrow();
|
|
286
|
+
expect(accessors.isDirty()).toBe(false);
|
|
287
|
+
expect(accessors.getDirtyPaths()).toEqual([]);
|
|
288
|
+
});
|
|
289
|
+
test('becomes dirty after saveFileContents', async () => {
|
|
290
|
+
const { fetchImpl } = makeMockFetch([
|
|
291
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
292
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
293
|
+
]);
|
|
294
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
295
|
+
baseUrl: 'http://localhost:3000',
|
|
296
|
+
fetchImpl,
|
|
297
|
+
mutable: true
|
|
298
|
+
})).orThrow();
|
|
299
|
+
accessors.saveFileContents('/data.json', '{"modified":true}').orThrow();
|
|
300
|
+
expect(accessors.isDirty()).toBe(true);
|
|
301
|
+
expect(accessors.getDirtyPaths()).toContain('/data.json');
|
|
302
|
+
});
|
|
303
|
+
test('tracks multiple dirty files', async () => {
|
|
304
|
+
const { fetchImpl } = makeMockFetch([
|
|
305
|
+
{
|
|
306
|
+
ok: true,
|
|
307
|
+
jsonValue: {
|
|
308
|
+
path: '/',
|
|
309
|
+
children: [
|
|
310
|
+
{ path: '/a.json', name: 'a.json', type: 'file' },
|
|
311
|
+
{ path: '/b.json', name: 'b.json', type: 'file' }
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
{ ok: true, jsonValue: fileResponse('/a.json', '{}') },
|
|
316
|
+
{ ok: true, jsonValue: fileResponse('/b.json', '{}') }
|
|
317
|
+
]);
|
|
318
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
319
|
+
baseUrl: 'http://localhost:3000',
|
|
320
|
+
fetchImpl,
|
|
321
|
+
mutable: true
|
|
322
|
+
})).orThrow();
|
|
323
|
+
accessors.saveFileContents('/a.json', '"a"').orThrow();
|
|
324
|
+
accessors.saveFileContents('/b.json', '"b"').orThrow();
|
|
325
|
+
expect(accessors.getDirtyPaths()).toHaveLength(2);
|
|
326
|
+
expect(accessors.getDirtyPaths()).toContain('/a.json');
|
|
327
|
+
expect(accessors.getDirtyPaths()).toContain('/b.json');
|
|
328
|
+
});
|
|
329
|
+
test('tracks deleted files as pending dirty paths', async () => {
|
|
330
|
+
const { fetchImpl } = makeMockFetch([
|
|
331
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
332
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
333
|
+
]);
|
|
334
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
335
|
+
baseUrl: 'http://localhost:3000',
|
|
336
|
+
fetchImpl,
|
|
337
|
+
mutable: true
|
|
338
|
+
})).orThrow();
|
|
339
|
+
accessors.deleteFile('/data.json').orThrow();
|
|
340
|
+
expect(accessors.isDirty()).toBe(true);
|
|
341
|
+
expect(accessors.getDirtyPaths()).toContain('/data.json');
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
describe('saveFileContents()', () => {
|
|
345
|
+
test('fails when the file is not found (immutable tree has no matching path)', async () => {
|
|
346
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
347
|
+
const accessors = (await HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl })).orThrow();
|
|
348
|
+
// With mutable: false (default), saveFileContents should fail
|
|
349
|
+
const result = accessors.saveFileContents('/missing.json', '{}');
|
|
350
|
+
expect(result).toFail();
|
|
351
|
+
});
|
|
352
|
+
test('marks the file as dirty without autoSync', async () => {
|
|
353
|
+
const { fetchImpl } = makeMockFetch([
|
|
354
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
355
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
356
|
+
]);
|
|
357
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
358
|
+
baseUrl: 'http://localhost:3000',
|
|
359
|
+
fetchImpl,
|
|
360
|
+
mutable: true
|
|
361
|
+
})).orThrow();
|
|
362
|
+
const result = accessors.saveFileContents('/data.json', '{"updated":true}');
|
|
363
|
+
expect(result).toSucceedWith('{"updated":true}');
|
|
364
|
+
expect(accessors.isDirty()).toBe(true);
|
|
365
|
+
// No additional fetch calls should have occurred (no autoSync)
|
|
366
|
+
});
|
|
367
|
+
test('triggers fire-and-forget autoSync when autoSync is enabled', async () => {
|
|
368
|
+
const syncResponses = [
|
|
369
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
370
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
371
|
+
// PUT /file response for sync
|
|
372
|
+
{ ok: true, jsonValue: { path: '/data.json', contents: '{"auto":true}' } },
|
|
373
|
+
// POST /sync response
|
|
374
|
+
{ ok: true, jsonValue: { synced: 1 } }
|
|
375
|
+
];
|
|
376
|
+
const { fetchImpl, calls } = makeMockFetch(syncResponses);
|
|
377
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
378
|
+
baseUrl: 'http://localhost:3000',
|
|
379
|
+
fetchImpl,
|
|
380
|
+
mutable: true,
|
|
381
|
+
autoSync: true
|
|
382
|
+
})).orThrow();
|
|
383
|
+
const result = accessors.saveFileContents('/data.json', '{"auto":true}');
|
|
384
|
+
expect(result).toSucceedWith('{"auto":true}');
|
|
385
|
+
// autoSync fires-and-forgets; wait for microtasks to drain
|
|
386
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
387
|
+
// Verify that PUT + POST /sync were called
|
|
388
|
+
const methodCalls = calls.slice(2).map((c) => { var _a; return (_a = c.init) === null || _a === void 0 ? void 0 : _a.method; });
|
|
389
|
+
expect(methodCalls).toContain('PUT');
|
|
390
|
+
expect(methodCalls).toContain('POST');
|
|
391
|
+
});
|
|
392
|
+
test('logs when autoSync returns a failure Result', async () => {
|
|
393
|
+
const logger = {
|
|
394
|
+
detail: jest.fn(),
|
|
395
|
+
info: jest.fn(),
|
|
396
|
+
warn: jest.fn(),
|
|
397
|
+
error: jest.fn()
|
|
398
|
+
};
|
|
399
|
+
const { fetchImpl } = makeMockFetch([
|
|
400
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
401
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
402
|
+
]);
|
|
403
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
404
|
+
baseUrl: 'http://localhost:3000',
|
|
405
|
+
fetchImpl,
|
|
406
|
+
mutable: true,
|
|
407
|
+
autoSync: true,
|
|
408
|
+
logger
|
|
409
|
+
})).orThrow();
|
|
410
|
+
accessors.syncToDisk =
|
|
411
|
+
async () => fail('simulated sync failure');
|
|
412
|
+
accessors.saveFileContents('/data.json', '{"auto":true}').orThrow();
|
|
413
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
414
|
+
expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('simulated sync failure'));
|
|
415
|
+
});
|
|
416
|
+
test('logs when autoSync throws unexpectedly', async () => {
|
|
417
|
+
const logger = {
|
|
418
|
+
detail: jest.fn(),
|
|
419
|
+
info: jest.fn(),
|
|
420
|
+
warn: jest.fn(),
|
|
421
|
+
error: jest.fn()
|
|
422
|
+
};
|
|
423
|
+
const { fetchImpl } = makeMockFetch([
|
|
424
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
425
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
426
|
+
]);
|
|
427
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
428
|
+
baseUrl: 'http://localhost:3000',
|
|
429
|
+
fetchImpl,
|
|
430
|
+
mutable: true,
|
|
431
|
+
autoSync: true,
|
|
432
|
+
logger
|
|
433
|
+
})).orThrow();
|
|
434
|
+
accessors.syncToDisk = async () => {
|
|
435
|
+
throw new Error('simulated throw');
|
|
436
|
+
};
|
|
437
|
+
accessors.saveFileContents('/data.json', '{"auto":true}').orThrow();
|
|
438
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
439
|
+
expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('simulated throw'));
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
describe('fileIsMutable()', () => {
|
|
443
|
+
test('returns persistent detail when file exists and mutable is true', async () => {
|
|
444
|
+
const { fetchImpl } = makeMockFetch([
|
|
445
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
446
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
447
|
+
]);
|
|
448
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
449
|
+
baseUrl: 'http://localhost:3000',
|
|
450
|
+
fetchImpl,
|
|
451
|
+
mutable: true
|
|
452
|
+
})).orThrow();
|
|
453
|
+
const result = accessors.fileIsMutable('/data.json');
|
|
454
|
+
expect(result.isSuccess()).toBe(true);
|
|
455
|
+
if (result.isSuccess()) {
|
|
456
|
+
expect(result.value).toBe(true);
|
|
457
|
+
expect(result.detail).toBe('persistent');
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
test('returns not-mutable detail when mutable is false', async () => {
|
|
461
|
+
const { fetchImpl } = makeMockFetch([
|
|
462
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
463
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
464
|
+
]);
|
|
465
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
466
|
+
baseUrl: 'http://localhost:3000',
|
|
467
|
+
fetchImpl,
|
|
468
|
+
mutable: false
|
|
469
|
+
})).orThrow();
|
|
470
|
+
const result = accessors.fileIsMutable('/data.json');
|
|
471
|
+
expect(result.isFailure()).toBe(true);
|
|
472
|
+
if (result.isFailure()) {
|
|
473
|
+
expect(result.detail).toBe('not-mutable');
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
test('returns persistent detail for any path when mutable is true (no path existence check)', async () => {
|
|
477
|
+
// InMemoryTreeAccessors checks the mutable config, not path existence.
|
|
478
|
+
// HttpTreeAccessors layers "persistent" on top of a successful mutable check.
|
|
479
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
480
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
481
|
+
baseUrl: 'http://localhost:3000',
|
|
482
|
+
fetchImpl,
|
|
483
|
+
mutable: true
|
|
484
|
+
})).orThrow();
|
|
485
|
+
// Any path succeeds as "persistent" when mutable: true
|
|
486
|
+
const result = accessors.fileIsMutable('/nonexistent.json');
|
|
487
|
+
expect(result.isSuccess()).toBe(true);
|
|
488
|
+
if (result.isSuccess()) {
|
|
489
|
+
expect(result.value).toBe(true);
|
|
490
|
+
expect(result.detail).toBe('persistent');
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
describe('syncToDisk()', () => {
|
|
495
|
+
test('succeeds immediately with no dirty files', async () => {
|
|
496
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
497
|
+
const accessors = (await HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl })).orThrow();
|
|
498
|
+
const result = await accessors.syncToDisk();
|
|
499
|
+
expect(result).toSucceed();
|
|
500
|
+
});
|
|
501
|
+
test('PUTs each dirty file then POSTs /sync', async () => {
|
|
502
|
+
var _a, _b;
|
|
503
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
504
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
505
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
506
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{"new":1}') },
|
|
507
|
+
{ ok: true, jsonValue: { synced: 1 } }
|
|
508
|
+
]);
|
|
509
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
510
|
+
baseUrl: 'http://localhost:3000',
|
|
511
|
+
fetchImpl,
|
|
512
|
+
mutable: true
|
|
513
|
+
})).orThrow();
|
|
514
|
+
accessors.saveFileContents('/data.json', '{"new":1}').orThrow();
|
|
515
|
+
const result = await accessors.syncToDisk();
|
|
516
|
+
expect(result).toSucceed();
|
|
517
|
+
const syncCalls = calls.slice(2);
|
|
518
|
+
expect(syncCalls[0].url).toContain('/file');
|
|
519
|
+
expect((_a = syncCalls[0].init) === null || _a === void 0 ? void 0 : _a.method).toBe('PUT');
|
|
520
|
+
expect(syncCalls[1].url).toContain('/sync');
|
|
521
|
+
expect((_b = syncCalls[1].init) === null || _b === void 0 ? void 0 : _b.method).toBe('POST');
|
|
522
|
+
});
|
|
523
|
+
test('clears dirty state after successful sync', async () => {
|
|
524
|
+
const { fetchImpl } = makeMockFetch([
|
|
525
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
526
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
527
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '"updated"') },
|
|
528
|
+
{ ok: true, jsonValue: { synced: 1 } }
|
|
529
|
+
]);
|
|
530
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
531
|
+
baseUrl: 'http://localhost:3000',
|
|
532
|
+
fetchImpl,
|
|
533
|
+
mutable: true
|
|
534
|
+
})).orThrow();
|
|
535
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
536
|
+
expect(accessors.isDirty()).toBe(true);
|
|
537
|
+
await accessors.syncToDisk();
|
|
538
|
+
expect(accessors.isDirty()).toBe(false);
|
|
539
|
+
expect(accessors.getDirtyPaths()).toEqual([]);
|
|
540
|
+
});
|
|
541
|
+
test('includes namespace in PUT body and POST /sync body when provided', async () => {
|
|
542
|
+
var _a, _b;
|
|
543
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
544
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
545
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
546
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '"v2"') },
|
|
547
|
+
{ ok: true, jsonValue: { synced: 1 } }
|
|
548
|
+
]);
|
|
549
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
550
|
+
baseUrl: 'http://localhost:3000',
|
|
551
|
+
namespace: 'myns',
|
|
552
|
+
fetchImpl,
|
|
553
|
+
mutable: true
|
|
554
|
+
})).orThrow();
|
|
555
|
+
accessors.saveFileContents('/data.json', '"v2"').orThrow();
|
|
556
|
+
await accessors.syncToDisk();
|
|
557
|
+
const putBody = JSON.parse((_a = calls[2].init) === null || _a === void 0 ? void 0 : _a.body);
|
|
558
|
+
expect(putBody.namespace).toBe('myns');
|
|
559
|
+
const syncBody = JSON.parse((_b = calls[3].init) === null || _b === void 0 ? void 0 : _b.body);
|
|
560
|
+
expect(syncBody.namespace).toBe('myns');
|
|
561
|
+
});
|
|
562
|
+
test('omits namespace from PUT body and POST /sync body when not provided', async () => {
|
|
563
|
+
var _a, _b;
|
|
564
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
565
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
566
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
567
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '"v2"') },
|
|
568
|
+
{ ok: true, jsonValue: { synced: 1 } }
|
|
569
|
+
]);
|
|
570
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
571
|
+
baseUrl: 'http://localhost:3000',
|
|
572
|
+
fetchImpl,
|
|
573
|
+
mutable: true
|
|
574
|
+
})).orThrow();
|
|
575
|
+
accessors.saveFileContents('/data.json', '"v2"').orThrow();
|
|
576
|
+
await accessors.syncToDisk();
|
|
577
|
+
const putBody = JSON.parse((_a = calls[2].init) === null || _a === void 0 ? void 0 : _a.body);
|
|
578
|
+
expect(putBody.namespace).toBeUndefined();
|
|
579
|
+
const syncBody = JSON.parse((_b = calls[3].init) === null || _b === void 0 ? void 0 : _b.body);
|
|
580
|
+
expect(syncBody.namespace).toBeUndefined();
|
|
581
|
+
});
|
|
582
|
+
test('fails when PUT for a dirty file returns a non-ok response', async () => {
|
|
583
|
+
const { fetchImpl } = makeMockFetch([
|
|
584
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
585
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
586
|
+
{ ok: false, status: 500, textValue: 'Server Error' }
|
|
587
|
+
]);
|
|
588
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
589
|
+
baseUrl: 'http://localhost:3000',
|
|
590
|
+
fetchImpl,
|
|
591
|
+
mutable: true
|
|
592
|
+
})).orThrow();
|
|
593
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
594
|
+
const result = await accessors.syncToDisk();
|
|
595
|
+
expect(result).toFailWith(/sync.*data\.json.*server error/i);
|
|
596
|
+
});
|
|
597
|
+
test('fails when PUT for a dirty file encounters a network error', async () => {
|
|
598
|
+
let callCount = 0;
|
|
599
|
+
const fetchImpl = (_url, _init) => {
|
|
600
|
+
callCount++;
|
|
601
|
+
if (callCount === 1) {
|
|
602
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
|
|
603
|
+
}
|
|
604
|
+
if (callCount === 2) {
|
|
605
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
|
|
606
|
+
}
|
|
607
|
+
return Promise.reject(new Error('PUT network error'));
|
|
608
|
+
};
|
|
609
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
610
|
+
baseUrl: 'http://localhost:3000',
|
|
611
|
+
fetchImpl,
|
|
612
|
+
mutable: true
|
|
613
|
+
})).orThrow();
|
|
614
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
615
|
+
const result = await accessors.syncToDisk();
|
|
616
|
+
expect(result).toFailWith(/put network error/i);
|
|
617
|
+
});
|
|
618
|
+
test('fails when POST /sync returns a non-ok response', async () => {
|
|
619
|
+
const { fetchImpl } = makeMockFetch([
|
|
620
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
621
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
622
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '"v2"') },
|
|
623
|
+
{ ok: false, status: 503, textValue: 'Service Unavailable' }
|
|
624
|
+
]);
|
|
625
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
626
|
+
baseUrl: 'http://localhost:3000',
|
|
627
|
+
fetchImpl,
|
|
628
|
+
mutable: true
|
|
629
|
+
})).orThrow();
|
|
630
|
+
accessors.saveFileContents('/data.json', '"v2"').orThrow();
|
|
631
|
+
const result = await accessors.syncToDisk();
|
|
632
|
+
expect(result).toFailWith(/service unavailable/i);
|
|
633
|
+
});
|
|
634
|
+
test('fails when POST /sync encounters a network error', async () => {
|
|
635
|
+
let callCount = 0;
|
|
636
|
+
const fetchImpl = (_url, _init) => {
|
|
637
|
+
callCount++;
|
|
638
|
+
if (callCount === 1) {
|
|
639
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
|
|
640
|
+
}
|
|
641
|
+
if (callCount === 2) {
|
|
642
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
|
|
643
|
+
}
|
|
644
|
+
if (callCount === 3) {
|
|
645
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '"v2"') }));
|
|
646
|
+
}
|
|
647
|
+
return Promise.reject(new Error('POST network error'));
|
|
648
|
+
};
|
|
649
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
650
|
+
baseUrl: 'http://localhost:3000',
|
|
651
|
+
fetchImpl,
|
|
652
|
+
mutable: true
|
|
653
|
+
})).orThrow();
|
|
654
|
+
accessors.saveFileContents('/data.json', '"v2"').orThrow();
|
|
655
|
+
const result = await accessors.syncToDisk();
|
|
656
|
+
expect(result).toFailWith(/post network error/i);
|
|
657
|
+
});
|
|
658
|
+
test('syncs multiple dirty files in order', async () => {
|
|
659
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
660
|
+
{
|
|
661
|
+
ok: true,
|
|
662
|
+
jsonValue: {
|
|
663
|
+
path: '/',
|
|
664
|
+
children: [
|
|
665
|
+
{ path: '/a.json', name: 'a.json', type: 'file' },
|
|
666
|
+
{ path: '/b.json', name: 'b.json', type: 'file' }
|
|
667
|
+
]
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
{ ok: true, jsonValue: fileResponse('/a.json', '{}') },
|
|
671
|
+
{ ok: true, jsonValue: fileResponse('/b.json', '{}') },
|
|
672
|
+
{ ok: true, jsonValue: fileResponse('/a.json', '"a-updated"') },
|
|
673
|
+
{ ok: true, jsonValue: fileResponse('/b.json', '"b-updated"') },
|
|
674
|
+
{ ok: true, jsonValue: { synced: 2 } }
|
|
675
|
+
]);
|
|
676
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
677
|
+
baseUrl: 'http://localhost:3000',
|
|
678
|
+
fetchImpl,
|
|
679
|
+
mutable: true
|
|
680
|
+
})).orThrow();
|
|
681
|
+
accessors.saveFileContents('/a.json', '"a-updated"').orThrow();
|
|
682
|
+
accessors.saveFileContents('/b.json', '"b-updated"').orThrow();
|
|
683
|
+
const result = await accessors.syncToDisk();
|
|
684
|
+
expect(result).toSucceed();
|
|
685
|
+
// Verify 2 PUTs + 1 POST
|
|
686
|
+
const syncCalls = calls.slice(3);
|
|
687
|
+
const methods = syncCalls.map((c) => { var _a; return (_a = c.init) === null || _a === void 0 ? void 0 : _a.method; });
|
|
688
|
+
expect(methods.filter((m) => m === 'PUT')).toHaveLength(2);
|
|
689
|
+
expect(methods.filter((m) => m === 'POST')).toHaveLength(1);
|
|
690
|
+
});
|
|
691
|
+
test('DELETEs pending deletions before POST /sync', async () => {
|
|
692
|
+
var _a, _b;
|
|
693
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
694
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
695
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
696
|
+
{ ok: true, jsonValue: { deleted: true } },
|
|
697
|
+
{ ok: true, jsonValue: { synced: 0 } }
|
|
698
|
+
]);
|
|
699
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
700
|
+
baseUrl: 'http://localhost:3000',
|
|
701
|
+
fetchImpl,
|
|
702
|
+
mutable: true
|
|
703
|
+
})).orThrow();
|
|
704
|
+
accessors.deleteFile('/data.json').orThrow();
|
|
705
|
+
const result = await accessors.syncToDisk();
|
|
706
|
+
expect(result).toSucceed();
|
|
707
|
+
const syncCalls = calls.slice(2);
|
|
708
|
+
expect((_a = syncCalls[0].init) === null || _a === void 0 ? void 0 : _a.method).toBe('DELETE');
|
|
709
|
+
expect(syncCalls[0].url).toContain('/file?');
|
|
710
|
+
expect((_b = syncCalls[1].init) === null || _b === void 0 ? void 0 : _b.method).toBe('POST');
|
|
711
|
+
expect(accessors.isDirty()).toBe(false);
|
|
712
|
+
});
|
|
713
|
+
test('fails when DELETE for pending deletion returns non-ok response', async () => {
|
|
714
|
+
const { fetchImpl } = makeMockFetch([
|
|
715
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
716
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
717
|
+
{ ok: false, status: 500, textValue: 'Delete failed' }
|
|
718
|
+
]);
|
|
719
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
720
|
+
baseUrl: 'http://localhost:3000',
|
|
721
|
+
fetchImpl,
|
|
722
|
+
mutable: true
|
|
723
|
+
})).orThrow();
|
|
724
|
+
accessors.deleteFile('/data.json').orThrow();
|
|
725
|
+
const result = await accessors.syncToDisk();
|
|
726
|
+
expect(result).toFailWith(/delete.*data\.json.*delete failed/i);
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
describe('syncToDisk() - getFileContents failure', () => {
|
|
730
|
+
test('fails when getFileContents returns failure for a dirty file during sync', async () => {
|
|
731
|
+
// This covers lines 112-113: the contentsResult.isFailure() branch in syncToDisk.
|
|
732
|
+
// We load a file, mark it dirty, then sabotage getFileContents to fail.
|
|
733
|
+
const { fetchImpl } = makeMockFetch([
|
|
734
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
735
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') }
|
|
736
|
+
]);
|
|
737
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
738
|
+
baseUrl: 'http://localhost:3000',
|
|
739
|
+
fetchImpl,
|
|
740
|
+
mutable: true
|
|
741
|
+
})).orThrow();
|
|
742
|
+
accessors.saveFileContents('/data.json', '{"new":1}').orThrow();
|
|
743
|
+
// Sabotage the base getFileContents to simulate a failure
|
|
744
|
+
const originalGet = accessors.getFileContents.bind(accessors);
|
|
745
|
+
accessors.getFileContents = (path) => {
|
|
746
|
+
if (path === '/data.json') {
|
|
747
|
+
// eslint-disable-next-line import/no-internal-modules
|
|
748
|
+
const { fail: failResult } = require('@fgv/ts-utils');
|
|
749
|
+
return failResult('simulated get failure');
|
|
750
|
+
}
|
|
751
|
+
return originalGet(path);
|
|
752
|
+
};
|
|
753
|
+
const result = await accessors.syncToDisk();
|
|
754
|
+
expect(result).toFailWith(/simulated get failure/i);
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
describe('_request() invalid JSON during sync', () => {
|
|
758
|
+
test('fails when PUT /file returns invalid JSON', async () => {
|
|
759
|
+
// Covers lines 225-226: _request() returns fail('invalid JSON response')
|
|
760
|
+
// when response.json() throws during a sync PUT.
|
|
761
|
+
const { fetchImpl } = makeMockFetch([
|
|
762
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
763
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
764
|
+
// PUT response with ok=true but throwOnJson simulates invalid JSON body
|
|
765
|
+
{ ok: true, throwOnJson: true }
|
|
766
|
+
]);
|
|
767
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
768
|
+
baseUrl: 'http://localhost:3000',
|
|
769
|
+
fetchImpl,
|
|
770
|
+
mutable: true
|
|
771
|
+
})).orThrow();
|
|
772
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
773
|
+
const result = await accessors.syncToDisk();
|
|
774
|
+
expect(result).toFailWith(/invalid json/i);
|
|
775
|
+
});
|
|
776
|
+
});
|
|
777
|
+
describe('fromHttp() with inferContentType', () => {
|
|
778
|
+
test('calls inferContentType when provided and uses the result', async () => {
|
|
779
|
+
// Covers line 270: params.inferContentType?.(...).orDefault()
|
|
780
|
+
const { fetchImpl } = makeMockFetch([
|
|
781
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
782
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}', 'application/json') }
|
|
783
|
+
]);
|
|
784
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
785
|
+
baseUrl: 'http://localhost:3000',
|
|
786
|
+
fetchImpl,
|
|
787
|
+
inferContentType: (path, provided) => {
|
|
788
|
+
if (provided === 'application/json') {
|
|
789
|
+
const { succeed: s } = require('@fgv/ts-utils');
|
|
790
|
+
return s('json');
|
|
791
|
+
}
|
|
792
|
+
const { succeed: s } = require('@fgv/ts-utils');
|
|
793
|
+
return s(undefined);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
expect(result).toSucceed();
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
describe('_request() error handling', () => {
|
|
800
|
+
test('returns failure with error message for network error (Error instance throw) during sync', async () => {
|
|
801
|
+
// Covers line 214 true branch: response.err instanceof Error -> uses .message
|
|
802
|
+
let callCount = 0;
|
|
803
|
+
const fetchImpl = (_url, _init) => {
|
|
804
|
+
callCount++;
|
|
805
|
+
if (callCount === 1) {
|
|
806
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
|
|
807
|
+
}
|
|
808
|
+
if (callCount === 2) {
|
|
809
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
|
|
810
|
+
}
|
|
811
|
+
// PUT request throws an Error instance
|
|
812
|
+
return Promise.reject(new Error('real Error instance'));
|
|
813
|
+
};
|
|
814
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
815
|
+
baseUrl: 'http://localhost:3000',
|
|
816
|
+
fetchImpl,
|
|
817
|
+
mutable: true
|
|
818
|
+
})).orThrow();
|
|
819
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
820
|
+
const result = await accessors.syncToDisk();
|
|
821
|
+
expect(result).toFailWith(/real error instance/i);
|
|
822
|
+
});
|
|
823
|
+
test('returns failure with error message for non-Error throw during sync PUT', async () => {
|
|
824
|
+
// Covers line 214 false branch: thrown value is not an Error instance -> uses String(response.err)
|
|
825
|
+
// Must be triggered via syncToDisk() which uses the instance _request() method.
|
|
826
|
+
let callCount = 0;
|
|
827
|
+
const fetchImpl = (_url, _init) => {
|
|
828
|
+
callCount++;
|
|
829
|
+
if (callCount === 1) {
|
|
830
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
|
|
831
|
+
}
|
|
832
|
+
if (callCount === 2) {
|
|
833
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
|
|
834
|
+
}
|
|
835
|
+
// Non-Error throw (e.g., a plain string)
|
|
836
|
+
return Promise.reject('non-error string rejection');
|
|
837
|
+
};
|
|
838
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
839
|
+
baseUrl: 'http://localhost:3000',
|
|
840
|
+
fetchImpl,
|
|
841
|
+
mutable: true
|
|
842
|
+
})).orThrow();
|
|
843
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
844
|
+
const result = await accessors.syncToDisk();
|
|
845
|
+
expect(result).toFailWith(/non-error string rejection/i);
|
|
846
|
+
});
|
|
847
|
+
test('returns failure with HTTP status fallback when response.text() throws during sync', async () => {
|
|
848
|
+
// Covers the text() catch branch in _request(): uses `HTTP ${status}` fallback
|
|
849
|
+
let callCount = 0;
|
|
850
|
+
const fetchImpl = (_url, _init) => {
|
|
851
|
+
callCount++;
|
|
852
|
+
if (callCount === 1) {
|
|
853
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: rootWithOneFile('data.json') }));
|
|
854
|
+
}
|
|
855
|
+
if (callCount === 2) {
|
|
856
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: fileResponse('/data.json', '{}') }));
|
|
857
|
+
}
|
|
858
|
+
return Promise.resolve(makeMockResponse({ ok: false, status: 502, throwOnText: true }));
|
|
859
|
+
};
|
|
860
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
861
|
+
baseUrl: 'http://localhost:3000',
|
|
862
|
+
fetchImpl,
|
|
863
|
+
mutable: true
|
|
864
|
+
})).orThrow();
|
|
865
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
866
|
+
const result = await accessors.syncToDisk();
|
|
867
|
+
expect(result).toFailWith(/http 502/i);
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
describe('_requestWithParams() error handling', () => {
|
|
871
|
+
test('returns failure with error message for non-Error network throw during init', async () => {
|
|
872
|
+
// _requestWithParams is used for GET requests during fromHttp(); test non-Error throw branch
|
|
873
|
+
const fetchImpl = (_url, _init) => {
|
|
874
|
+
return Promise.reject(42);
|
|
875
|
+
};
|
|
876
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
877
|
+
baseUrl: 'http://localhost:3000',
|
|
878
|
+
fetchImpl
|
|
879
|
+
});
|
|
880
|
+
expect(result).toFailWith(/42/);
|
|
881
|
+
});
|
|
882
|
+
test('returns failure with HTTP status fallback when response.text() throws during init', async () => {
|
|
883
|
+
const fetchImpl = (_url, _init) => {
|
|
884
|
+
return Promise.resolve(makeMockResponse({ ok: false, status: 504, throwOnText: true }));
|
|
885
|
+
};
|
|
886
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
887
|
+
baseUrl: 'http://localhost:3000',
|
|
888
|
+
fetchImpl
|
|
889
|
+
});
|
|
890
|
+
expect(result).toFailWith(/http 504/i);
|
|
891
|
+
});
|
|
892
|
+
test('uses globalThis.fetch when no fetchImpl provided', async () => {
|
|
893
|
+
// Covers line 48: the `fetchImpl ?? globalThis.fetch` right-side branch.
|
|
894
|
+
// We temporarily replace globalThis.fetch with a mock that returns an empty tree.
|
|
895
|
+
const originalFetch = globalThis.fetch;
|
|
896
|
+
let fetchCallCount = 0;
|
|
897
|
+
globalThis.fetch = (_url, _init) => {
|
|
898
|
+
fetchCallCount++;
|
|
899
|
+
return Promise.resolve(makeMockResponse({ ok: true, jsonValue: { path: '/', children: [] } }));
|
|
900
|
+
};
|
|
901
|
+
try {
|
|
902
|
+
const result = await HttpTreeAccessors.fromHttp({
|
|
903
|
+
baseUrl: 'http://localhost:3000'
|
|
904
|
+
// No fetchImpl - should fall back to globalThis.fetch
|
|
905
|
+
});
|
|
906
|
+
expect(result).toSucceed();
|
|
907
|
+
expect(fetchCallCount).toBeGreaterThan(0);
|
|
908
|
+
}
|
|
909
|
+
finally {
|
|
910
|
+
globalThis.fetch = originalFetch;
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
});
|
|
914
|
+
describe('userId header in _request()', () => {
|
|
915
|
+
test('includes X-User-Id header in PUT /file and POST /sync requests when userId is set', async () => {
|
|
916
|
+
var _a;
|
|
917
|
+
// Covers line 259: the this._userId branch in _request()
|
|
918
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
919
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
920
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
921
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '"updated"') },
|
|
922
|
+
{ ok: true, jsonValue: { synced: 1 } }
|
|
923
|
+
]);
|
|
924
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
925
|
+
baseUrl: 'http://localhost:3000',
|
|
926
|
+
fetchImpl,
|
|
927
|
+
mutable: true,
|
|
928
|
+
userId: 'test-user-123'
|
|
929
|
+
})).orThrow();
|
|
930
|
+
accessors.saveFileContents('/data.json', '"updated"').orThrow();
|
|
931
|
+
const result = await accessors.syncToDisk();
|
|
932
|
+
expect(result).toSucceed();
|
|
933
|
+
// The PUT and POST requests should include the X-User-Id header
|
|
934
|
+
const syncCalls = calls.slice(2);
|
|
935
|
+
for (const call of syncCalls) {
|
|
936
|
+
const headers = (_a = call.init) === null || _a === void 0 ? void 0 : _a.headers;
|
|
937
|
+
expect(headers === null || headers === void 0 ? void 0 : headers['X-User-Id']).toBe('test-user-123');
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
});
|
|
941
|
+
describe('deleteFile()', () => {
|
|
942
|
+
test('fails when the underlying InMemoryTreeAccessors deleteFile fails (file not found)', async () => {
|
|
943
|
+
// Covers lines 200-201: result.isFailure() branch in deleteFile
|
|
944
|
+
const { fetchImpl } = makeMockFetch([{ ok: true, jsonValue: { path: '/', children: [] } }]);
|
|
945
|
+
const accessors = (await HttpTreeAccessors.fromHttp({ baseUrl: 'http://localhost:3000', fetchImpl, mutable: true })).orThrow();
|
|
946
|
+
// Delete a file that does not exist — super.deleteFile should fail
|
|
947
|
+
const result = accessors.deleteFile('/nonexistent.json');
|
|
948
|
+
expect(result).toFail();
|
|
949
|
+
});
|
|
950
|
+
test('includes namespace in DELETE query params when namespace is configured', async () => {
|
|
951
|
+
// Covers lines 131-132: the namespace branch in syncToDisk's pending-deletion loop
|
|
952
|
+
const { fetchImpl, calls } = makeMockFetch([
|
|
953
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
954
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
955
|
+
{ ok: true, jsonValue: { deleted: true } },
|
|
956
|
+
{ ok: true, jsonValue: { synced: 0 } }
|
|
957
|
+
]);
|
|
958
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
959
|
+
baseUrl: 'http://localhost:3000',
|
|
960
|
+
namespace: 'my-namespace',
|
|
961
|
+
fetchImpl,
|
|
962
|
+
mutable: true
|
|
963
|
+
})).orThrow();
|
|
964
|
+
accessors.deleteFile('/data.json').orThrow();
|
|
965
|
+
const result = await accessors.syncToDisk();
|
|
966
|
+
expect(result).toSucceed();
|
|
967
|
+
// The DELETE request URL should include namespace as a query parameter
|
|
968
|
+
const deleteCalls = calls.filter((c) => { var _a; return ((_a = c.init) === null || _a === void 0 ? void 0 : _a.method) === 'DELETE'; });
|
|
969
|
+
expect(deleteCalls).toHaveLength(1);
|
|
970
|
+
expect(deleteCalls[0].url).toContain('namespace=my-namespace');
|
|
971
|
+
});
|
|
972
|
+
test('triggers fire-and-forget autoSync after successful delete when autoSync is enabled', async () => {
|
|
973
|
+
// Covers lines 209-212: the autoSync branch in deleteFile
|
|
974
|
+
const syncResponses = [
|
|
975
|
+
{ ok: true, jsonValue: rootWithOneFile('data.json') },
|
|
976
|
+
{ ok: true, jsonValue: fileResponse('/data.json', '{}') },
|
|
977
|
+
// DELETE /file response for pending deletion
|
|
978
|
+
{ ok: true, jsonValue: { deleted: true } },
|
|
979
|
+
// POST /sync response
|
|
980
|
+
{ ok: true, jsonValue: { synced: 0 } }
|
|
981
|
+
];
|
|
982
|
+
const { fetchImpl, calls } = makeMockFetch(syncResponses);
|
|
983
|
+
const accessors = (await HttpTreeAccessors.fromHttp({
|
|
984
|
+
baseUrl: 'http://localhost:3000',
|
|
985
|
+
fetchImpl,
|
|
986
|
+
mutable: true,
|
|
987
|
+
autoSync: true
|
|
988
|
+
})).orThrow();
|
|
989
|
+
const result = accessors.deleteFile('/data.json');
|
|
990
|
+
expect(result).toSucceedWith(true);
|
|
991
|
+
// autoSync fires-and-forgets; wait for microtasks to drain
|
|
992
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
993
|
+
// Verify that DELETE + POST /sync were called
|
|
994
|
+
const methodCalls = calls.slice(2).map((c) => { var _a; return (_a = c.init) === null || _a === void 0 ? void 0 : _a.method; });
|
|
995
|
+
expect(methodCalls).toContain('DELETE');
|
|
996
|
+
expect(methodCalls).toContain('POST');
|
|
997
|
+
});
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
//# sourceMappingURL=httpTreeAccessors.test.js.map
|