@fgv/ts-web-extras 5.1.0-4 → 5.1.0-40
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/dist/packlets/crypto-utils/browserCryptoProvider.js +330 -18
- package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
- package/dist/packlets/crypto-utils/idbPrivateKeyStorage.js +238 -0
- package/dist/packlets/crypto-utils/idbPrivateKeyStorage.js.map +1 -0
- package/dist/packlets/crypto-utils/index.js +13 -0
- package/dist/packlets/crypto-utils/index.js.map +1 -1
- package/dist/packlets/file-tree/directoryHandleStore.js.map +1 -1
- package/dist/packlets/file-tree/fileApiTreeAccessors.js +1 -1
- package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
- package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +2 -2
- package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
- package/dist/packlets/file-tree/httpTreeAccessors.js +74 -44
- package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -1
- package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
- package/dist/packlets/helpers/fileTreeHelpers.js +1 -1
- package/dist/packlets/helpers/fileTreeHelpers.js.map +1 -1
- package/dist/ts-web-extras.d.ts +229 -10
- package/dist/tsdoc-metadata.json +1 -1
- package/eslint.config.js +32 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +115 -6
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.js +329 -17
- package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
- package/lib/packlets/crypto-utils/idbPrivateKeyStorage.d.ts +87 -0
- package/lib/packlets/crypto-utils/idbPrivateKeyStorage.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/idbPrivateKeyStorage.js +242 -0
- package/lib/packlets/crypto-utils/idbPrivateKeyStorage.js.map +1 -0
- package/lib/packlets/crypto-utils/index.d.ts +14 -0
- package/lib/packlets/crypto-utils/index.d.ts.map +1 -1
- package/lib/packlets/crypto-utils/index.js +14 -0
- package/lib/packlets/crypto-utils/index.js.map +1 -1
- package/lib/packlets/file-tree/directoryHandleStore.d.ts +2 -2
- package/lib/packlets/file-tree/directoryHandleStore.d.ts.map +1 -1
- package/lib/packlets/file-tree/directoryHandleStore.js.map +1 -1
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +2 -2
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
- package/lib/packlets/file-tree/fileApiTreeAccessors.js +1 -1
- package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -1
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +2 -2
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
- package/lib/packlets/file-tree/httpTreeAccessors.d.ts +6 -0
- package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -1
- package/lib/packlets/file-tree/httpTreeAccessors.js +74 -44
- package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -1
- package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
- package/lib/packlets/helpers/fileTreeHelpers.d.ts +1 -1
- package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -1
- package/lib/packlets/helpers/fileTreeHelpers.js +6 -6
- package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -1
- package/package.json +15 -14
- package/.rush/temp/44b0369e8112f3c6f4248af466a3f35ad626d9d7.tar.log +0 -237
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +0 -55
- package/.rush/temp/operation/build/all.log +0 -55
- package/.rush/temp/operation/build/log-chunks.jsonl +0 -55
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -692
- package/CHANGELOG.md +0 -23
- package/config/api-extractor.json +0 -343
- package/config/jest.config.json +0 -19
- package/config/rig.json +0 -16
- package/config/typedoc.json +0 -7
- package/dist/test/mocks/idb-keyval.js +0 -6
- package/dist/test/mocks/idb-keyval.js.map +0 -1
- package/dist/test/setupTests.js +0 -74
- package/dist/test/setupTests.js.map +0 -1
- package/dist/test/unit/browserHashProvider.test.js +0 -140
- package/dist/test/unit/browserHashProvider.test.js.map +0 -1
- package/dist/test/unit/directoryHandleStore.test.js +0 -190
- package/dist/test/unit/directoryHandleStore.test.js.map +0 -1
- package/dist/test/unit/fileApiTreeAccessors.test.js +0 -1188
- package/dist/test/unit/fileApiTreeAccessors.test.js.map +0 -1
- package/dist/test/unit/fileApiTypes.test.js +0 -472
- package/dist/test/unit/fileApiTypes.test.js.map +0 -1
- package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +0 -622
- package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
- package/dist/test/unit/fileTreeHelpers.test.js +0 -590
- package/dist/test/unit/fileTreeHelpers.test.js.map +0 -1
- package/dist/test/unit/httpTreeAccessors.test.js +0 -1229
- package/dist/test/unit/httpTreeAccessors.test.js.map +0 -1
- package/dist/test/unit/localStorageTreeAccessors.test.js +0 -812
- package/dist/test/unit/localStorageTreeAccessors.test.js.map +0 -1
- package/dist/test/unit/urlParams.test.js +0 -393
- package/dist/test/unit/urlParams.test.js.map +0 -1
- package/dist/test/utils/fileSystemAccessMocks.js +0 -271
- package/dist/test/utils/fileSystemAccessMocks.js.map +0 -1
- package/dist/test/utils/testHelpers.js +0 -124
- package/dist/test/utils/testHelpers.js.map +0 -1
- package/docs/CryptoUtils/README.md +0 -60
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.decrypt.md +0 -27
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.deriveKey.md +0 -26
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.encrypt.md +0 -25
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.fromBase64.md +0 -24
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateKey.md +0 -17
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateRandomBytes.md +0 -24
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.md +0 -151
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.toBase64.md +0 -24
- package/docs/CryptoUtils/classes/BrowserHashProvider.hashParts.md +0 -26
- package/docs/CryptoUtils/classes/BrowserHashProvider.hashString.md +0 -25
- package/docs/CryptoUtils/classes/BrowserHashProvider.md +0 -81
- package/docs/CryptoUtils/functions/createBrowserCryptoProvider.md +0 -12
- package/docs/FileTreeHelpers/README.md +0 -85
- package/docs/FileTreeHelpers/functions/extractFileListMetadata.md +0 -11
- package/docs/FileTreeHelpers/functions/extractFileMetadata.md +0 -11
- package/docs/FileTreeHelpers/functions/fromDirectoryUpload.md +0 -12
- package/docs/FileTreeHelpers/functions/fromFileList.md +0 -12
- package/docs/FileTreeHelpers/functions/getOriginalFile.md +0 -11
- package/docs/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +0 -9
- package/docs/README.md +0 -524
- package/docs/classes/BrowserCryptoProvider.decrypt.md +0 -27
- package/docs/classes/BrowserCryptoProvider.deriveKey.md +0 -26
- package/docs/classes/BrowserCryptoProvider.encrypt.md +0 -25
- package/docs/classes/BrowserCryptoProvider.fromBase64.md +0 -24
- package/docs/classes/BrowserCryptoProvider.generateKey.md +0 -17
- package/docs/classes/BrowserCryptoProvider.generateRandomBytes.md +0 -24
- package/docs/classes/BrowserCryptoProvider.md +0 -151
- package/docs/classes/BrowserCryptoProvider.toBase64.md +0 -24
- package/docs/classes/BrowserHashProvider.hashParts.md +0 -26
- package/docs/classes/BrowserHashProvider.hashString.md +0 -25
- package/docs/classes/BrowserHashProvider.md +0 -81
- package/docs/classes/DirectoryHandleStore.getAll.md +0 -17
- package/docs/classes/DirectoryHandleStore.getAllLabels.md +0 -17
- package/docs/classes/DirectoryHandleStore.load.md +0 -24
- package/docs/classes/DirectoryHandleStore.md +0 -120
- package/docs/classes/DirectoryHandleStore.remove.md +0 -24
- package/docs/classes/DirectoryHandleStore.save.md +0 -25
- package/docs/classes/FileApiTreeAccessors.create.md +0 -25
- package/docs/classes/FileApiTreeAccessors.createFromHttp.md +0 -24
- package/docs/classes/FileApiTreeAccessors.createFromLocalStorage.md +0 -25
- package/docs/classes/FileApiTreeAccessors.createPersistent.md +0 -26
- package/docs/classes/FileApiTreeAccessors.createPersistentFromFile.md +0 -27
- package/docs/classes/FileApiTreeAccessors.extractFileMetadata.md +0 -24
- package/docs/classes/FileApiTreeAccessors.fromDirectoryUpload.md +0 -25
- package/docs/classes/FileApiTreeAccessors.fromFileList.md +0 -25
- package/docs/classes/FileApiTreeAccessors.getOriginalFile.md +0 -27
- package/docs/classes/FileApiTreeAccessors.md +0 -172
- package/docs/classes/FileSystemAccessTreeAccessors.deleteFile.md +0 -22
- package/docs/classes/FileSystemAccessTreeAccessors.fileIsMutable.md +0 -22
- package/docs/classes/FileSystemAccessTreeAccessors.fromDirectoryHandle.md +0 -25
- package/docs/classes/FileSystemAccessTreeAccessors.fromFileHandle.md +0 -29
- package/docs/classes/FileSystemAccessTreeAccessors.getDirtyPaths.md +0 -15
- package/docs/classes/FileSystemAccessTreeAccessors.isDirty.md +0 -15
- package/docs/classes/FileSystemAccessTreeAccessors.md +0 -275
- package/docs/classes/FileSystemAccessTreeAccessors.saveFileContents.md +0 -23
- package/docs/classes/FileSystemAccessTreeAccessors.syncToDisk.md +0 -15
- package/docs/classes/HttpTreeAccessors.deleteFile.md +0 -22
- package/docs/classes/HttpTreeAccessors.fileIsMutable.md +0 -24
- package/docs/classes/HttpTreeAccessors.fromHttp.md +0 -24
- package/docs/classes/HttpTreeAccessors.getDirtyPaths.md +0 -17
- package/docs/classes/HttpTreeAccessors.isDirty.md +0 -17
- package/docs/classes/HttpTreeAccessors.md +0 -261
- package/docs/classes/HttpTreeAccessors.saveFileContents.md +0 -25
- package/docs/classes/HttpTreeAccessors.syncToDisk.md +0 -22
- package/docs/classes/LocalStorageTreeAccessors.deleteFile.md +0 -24
- package/docs/classes/LocalStorageTreeAccessors.fileIsMutable.md +0 -24
- package/docs/classes/LocalStorageTreeAccessors.fromStorage.md +0 -25
- package/docs/classes/LocalStorageTreeAccessors.getDirtyPaths.md +0 -17
- package/docs/classes/LocalStorageTreeAccessors.isDirty.md +0 -17
- package/docs/classes/LocalStorageTreeAccessors.md +0 -270
- package/docs/classes/LocalStorageTreeAccessors.saveFileContents.md +0 -25
- package/docs/classes/LocalStorageTreeAccessors.syncToDisk.md +0 -17
- package/docs/functions/createBrowserCryptoProvider.md +0 -12
- package/docs/functions/exportAsJson.md +0 -12
- package/docs/functions/exportUsingFileSystemAPI.md +0 -11
- package/docs/functions/extractDirectoryPath.md +0 -13
- package/docs/functions/extractFileListMetadata.md +0 -11
- package/docs/functions/extractFileMetadata.md +0 -11
- package/docs/functions/fromDirectoryUpload.md +0 -12
- package/docs/functions/fromFileList.md +0 -12
- package/docs/functions/getOriginalFile.md +0 -11
- package/docs/functions/isDirectoryHandle.md +0 -11
- package/docs/functions/isFileHandle.md +0 -11
- package/docs/functions/isFilePath.md +0 -11
- package/docs/functions/parseContextFilter.md +0 -12
- package/docs/functions/parseQualifierDefaults.md +0 -12
- package/docs/functions/parseResourceTypes.md +0 -12
- package/docs/functions/parseUrlParameters.md +0 -11
- package/docs/functions/safeShowDirectoryPicker.md +0 -11
- package/docs/functions/safeShowOpenFilePicker.md +0 -11
- package/docs/functions/safeShowSaveFilePicker.md +0 -11
- package/docs/functions/supportsFileSystemAccess.md +0 -11
- package/docs/interfaces/FilePickerAcceptType.accept.md +0 -9
- package/docs/interfaces/FilePickerAcceptType.description.md +0 -9
- package/docs/interfaces/FilePickerAcceptType.md +0 -61
- package/docs/interfaces/FileSystemCreateWritableOptions.keepExistingData.md +0 -9
- package/docs/interfaces/FileSystemCreateWritableOptions.md +0 -44
- package/docs/interfaces/FileSystemDirectoryHandle._asyncIterator_.md +0 -13
- package/docs/interfaces/FileSystemDirectoryHandle.entries.md +0 -13
- package/docs/interfaces/FileSystemDirectoryHandle.getDirectoryHandle.md +0 -21
- package/docs/interfaces/FileSystemDirectoryHandle.getFileHandle.md +0 -21
- package/docs/interfaces/FileSystemDirectoryHandle.keys.md +0 -13
- package/docs/interfaces/FileSystemDirectoryHandle.kind.md +0 -9
- package/docs/interfaces/FileSystemDirectoryHandle.md +0 -224
- package/docs/interfaces/FileSystemDirectoryHandle.removeEntry.md +0 -21
- package/docs/interfaces/FileSystemDirectoryHandle.resolve.md +0 -20
- package/docs/interfaces/FileSystemDirectoryHandle.values.md +0 -13
- package/docs/interfaces/FileSystemFileHandle.createWritable.md +0 -20
- package/docs/interfaces/FileSystemFileHandle.getFile.md +0 -13
- package/docs/interfaces/FileSystemFileHandle.kind.md +0 -9
- package/docs/interfaces/FileSystemFileHandle.md +0 -146
- package/docs/interfaces/FileSystemGetDirectoryOptions.create.md +0 -9
- package/docs/interfaces/FileSystemGetDirectoryOptions.md +0 -44
- package/docs/interfaces/FileSystemGetFileOptions.create.md +0 -9
- package/docs/interfaces/FileSystemGetFileOptions.md +0 -44
- package/docs/interfaces/FileSystemHandle.isSameEntry.md +0 -20
- package/docs/interfaces/FileSystemHandle.kind.md +0 -9
- package/docs/interfaces/FileSystemHandle.md +0 -118
- package/docs/interfaces/FileSystemHandle.name.md +0 -9
- package/docs/interfaces/FileSystemHandle.queryPermission.md +0 -20
- package/docs/interfaces/FileSystemHandle.requestPermission.md +0 -20
- package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +0 -44
- package/docs/interfaces/FileSystemHandlePermissionDescriptor.mode.md +0 -9
- package/docs/interfaces/FileSystemRemoveOptions.md +0 -44
- package/docs/interfaces/FileSystemRemoveOptions.recursive.md +0 -9
- package/docs/interfaces/FileSystemWritableFileStream.md +0 -142
- package/docs/interfaces/FileSystemWritableFileStream.seek.md +0 -20
- package/docs/interfaces/FileSystemWritableFileStream.truncate.md +0 -20
- package/docs/interfaces/FileSystemWritableFileStream.write.md +0 -20
- package/docs/interfaces/IDirectoryHandleTreeInitializer.dirHandles.md +0 -9
- package/docs/interfaces/IDirectoryHandleTreeInitializer.md +0 -78
- package/docs/interfaces/IDirectoryHandleTreeInitializer.nonRecursive.md +0 -9
- package/docs/interfaces/IDirectoryHandleTreeInitializer.prefix.md +0 -9
- package/docs/interfaces/IFileHandleTreeInitializer.fileHandles.md +0 -9
- package/docs/interfaces/IFileHandleTreeInitializer.md +0 -61
- package/docs/interfaces/IFileHandleTreeInitializer.prefix.md +0 -9
- package/docs/interfaces/IFileListTreeInitializer.fileList.md +0 -9
- package/docs/interfaces/IFileListTreeInitializer.md +0 -44
- package/docs/interfaces/IFileMetadata.lastModified.md +0 -9
- package/docs/interfaces/IFileMetadata.md +0 -112
- package/docs/interfaces/IFileMetadata.name.md +0 -9
- package/docs/interfaces/IFileMetadata.path.md +0 -9
- package/docs/interfaces/IFileMetadata.size.md +0 -9
- package/docs/interfaces/IFileMetadata.type.md +0 -9
- package/docs/interfaces/IFileSystemAccessTreeParams.autoSync.md +0 -12
- package/docs/interfaces/IFileSystemAccessTreeParams.filePath.md +0 -13
- package/docs/interfaces/IFileSystemAccessTreeParams.logger.md +0 -11
- package/docs/interfaces/IFileSystemAccessTreeParams.md +0 -148
- package/docs/interfaces/IFileSystemAccessTreeParams.requireWritePermission.md +0 -13
- package/docs/interfaces/IFsAccessApis.md +0 -62
- package/docs/interfaces/IFsAccessApis.showDirectoryPicker.md +0 -20
- package/docs/interfaces/IFsAccessApis.showOpenFilePicker.md +0 -20
- package/docs/interfaces/IFsAccessApis.showSaveFilePicker.md +0 -20
- package/docs/interfaces/IHttpTreeParams.autoSync.md +0 -9
- package/docs/interfaces/IHttpTreeParams.baseUrl.md +0 -9
- package/docs/interfaces/IHttpTreeParams.fetchImpl.md +0 -9
- package/docs/interfaces/IHttpTreeParams.logger.md +0 -9
- package/docs/interfaces/IHttpTreeParams.md +0 -182
- package/docs/interfaces/IHttpTreeParams.namespace.md +0 -9
- package/docs/interfaces/IHttpTreeParams.userId.md +0 -9
- package/docs/interfaces/ILocalStorageTreeParams.autoSync.md +0 -12
- package/docs/interfaces/ILocalStorageTreeParams.md +0 -131
- package/docs/interfaces/ILocalStorageTreeParams.pathToKeyMap.md +0 -13
- package/docs/interfaces/ILocalStorageTreeParams.storage.md +0 -12
- package/docs/interfaces/IUrlConfigOptions.config.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.configStartDir.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.contextFilter.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.input.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.inputStartDir.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.interactive.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.loadZip.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.maxDistance.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.md +0 -248
- package/docs/interfaces/IUrlConfigOptions.qualifierDefaults.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.reduceQualifiers.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.resourceTypes.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.zipFile.md +0 -11
- package/docs/interfaces/IUrlConfigOptions.zipPath.md +0 -11
- package/docs/interfaces/ShowDirectoryPickerOptions.id.md +0 -9
- package/docs/interfaces/ShowDirectoryPickerOptions.md +0 -78
- package/docs/interfaces/ShowDirectoryPickerOptions.mode.md +0 -9
- package/docs/interfaces/ShowDirectoryPickerOptions.startIn.md +0 -9
- package/docs/interfaces/ShowOpenFilePickerOptions.excludeAcceptAllOption.md +0 -9
- package/docs/interfaces/ShowOpenFilePickerOptions.id.md +0 -9
- package/docs/interfaces/ShowOpenFilePickerOptions.md +0 -112
- package/docs/interfaces/ShowOpenFilePickerOptions.multiple.md +0 -9
- package/docs/interfaces/ShowOpenFilePickerOptions.startIn.md +0 -9
- package/docs/interfaces/ShowOpenFilePickerOptions.types.md +0 -9
- package/docs/interfaces/ShowSaveFilePickerOptions.excludeAcceptAllOption.md +0 -9
- package/docs/interfaces/ShowSaveFilePickerOptions.id.md +0 -9
- package/docs/interfaces/ShowSaveFilePickerOptions.md +0 -112
- package/docs/interfaces/ShowSaveFilePickerOptions.startIn.md +0 -9
- package/docs/interfaces/ShowSaveFilePickerOptions.suggestedName.md +0 -9
- package/docs/interfaces/ShowSaveFilePickerOptions.types.md +0 -9
- package/docs/type-aliases/TreeInitializer.md +0 -11
- package/docs/type-aliases/WellKnownDirectory.md +0 -11
- package/docs/type-aliases/WindowWithFsAccess.md +0 -11
- package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +0 -9
- package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +0 -9
- package/docs/variables/defaultFileApiTreeInitParams.md +0 -9
- package/etc/ts-web-extras.api.md +0 -433
- package/lib/test/mocks/idb-keyval.d.ts +0 -6
- package/lib/test/mocks/idb-keyval.d.ts.map +0 -1
- package/lib/test/mocks/idb-keyval.js +0 -9
- package/lib/test/mocks/idb-keyval.js.map +0 -1
- package/lib/test/setupTests.d.ts +0 -2
- package/lib/test/setupTests.d.ts.map +0 -1
- package/lib/test/setupTests.js +0 -76
- package/lib/test/setupTests.js.map +0 -1
- package/lib/test/unit/browserHashProvider.test.d.ts +0 -2
- package/lib/test/unit/browserHashProvider.test.d.ts.map +0 -1
- package/lib/test/unit/browserHashProvider.test.js +0 -142
- package/lib/test/unit/browserHashProvider.test.js.map +0 -1
- package/lib/test/unit/directoryHandleStore.test.d.ts +0 -2
- package/lib/test/unit/directoryHandleStore.test.d.ts.map +0 -1
- package/lib/test/unit/directoryHandleStore.test.js +0 -192
- package/lib/test/unit/directoryHandleStore.test.js.map +0 -1
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts +0 -2
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +0 -1
- package/lib/test/unit/fileApiTreeAccessors.test.js +0 -1190
- package/lib/test/unit/fileApiTreeAccessors.test.js.map +0 -1
- package/lib/test/unit/fileApiTypes.test.d.ts +0 -2
- package/lib/test/unit/fileApiTypes.test.d.ts.map +0 -1
- package/lib/test/unit/fileApiTypes.test.js +0 -474
- package/lib/test/unit/fileApiTypes.test.js.map +0 -1
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +0 -2
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +0 -1
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +0 -624
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
- package/lib/test/unit/fileTreeHelpers.test.d.ts +0 -2
- package/lib/test/unit/fileTreeHelpers.test.d.ts.map +0 -1
- package/lib/test/unit/fileTreeHelpers.test.js +0 -592
- package/lib/test/unit/fileTreeHelpers.test.js.map +0 -1
- package/lib/test/unit/httpTreeAccessors.test.d.ts +0 -2
- package/lib/test/unit/httpTreeAccessors.test.d.ts.map +0 -1
- package/lib/test/unit/httpTreeAccessors.test.js +0 -1231
- package/lib/test/unit/httpTreeAccessors.test.js.map +0 -1
- package/lib/test/unit/localStorageTreeAccessors.test.d.ts +0 -2
- package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +0 -1
- package/lib/test/unit/localStorageTreeAccessors.test.js +0 -814
- package/lib/test/unit/localStorageTreeAccessors.test.js.map +0 -1
- package/lib/test/unit/urlParams.test.d.ts +0 -2
- package/lib/test/unit/urlParams.test.d.ts.map +0 -1
- package/lib/test/unit/urlParams.test.js +0 -395
- package/lib/test/unit/urlParams.test.js.map +0 -1
- package/lib/test/utils/fileSystemAccessMocks.d.ts +0 -53
- package/lib/test/utils/fileSystemAccessMocks.d.ts.map +0 -1
- package/lib/test/utils/fileSystemAccessMocks.js +0 -277
- package/lib/test/utils/fileSystemAccessMocks.js.map +0 -1
- package/lib/test/utils/testHelpers.d.ts +0 -51
- package/lib/test/utils/testHelpers.d.ts.map +0 -1
- package/lib/test/utils/testHelpers.js +0 -133
- package/lib/test/utils/testHelpers.js.map +0 -1
- package/rush-logs/ts-web-extras.build.cache.log +0 -3
- package/rush-logs/ts-web-extras.build.log +0 -55
- package/src/index.browser.ts +0 -24
- package/src/index.ts +0 -47
- package/src/packlets/crypto-utils/browserCryptoProvider.ts +0 -311
- package/src/packlets/crypto-utils/browserHashProvider.ts +0 -73
- package/src/packlets/crypto-utils/index.ts +0 -29
- package/src/packlets/file-api-types/index.ts +0 -366
- package/src/packlets/file-tree/directoryHandleStore.ts +0 -136
- package/src/packlets/file-tree/fileApiTreeAccessors.ts +0 -528
- package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +0 -519
- package/src/packlets/file-tree/httpTreeAccessors.ts +0 -448
- package/src/packlets/file-tree/index.ts +0 -32
- package/src/packlets/file-tree/localStorageTreeAccessors.ts +0 -430
- package/src/packlets/helpers/fileTreeHelpers.ts +0 -107
- package/src/packlets/helpers/index.ts +0 -28
- package/src/packlets/url-utils/index.ts +0 -28
- package/src/packlets/url-utils/urlParams.ts +0 -245
- package/src/test/mocks/idb-keyval.ts +0 -5
- package/src/test/setupTests.ts +0 -87
- package/src/test/unit/browserHashProvider.test.ts +0 -155
- package/src/test/unit/browserHashProvider.test.ts.bak +0 -376
- package/src/test/unit/directoryHandleStore.test.ts +0 -251
- package/src/test/unit/fileApiTreeAccessors.test.ts +0 -1387
- package/src/test/unit/fileApiTypes.test.ts +0 -587
- package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +0 -885
- package/src/test/unit/fileTreeHelpers.test.ts +0 -694
- package/src/test/unit/httpTreeAccessors.test.ts +0 -1571
- package/src/test/unit/localStorageTreeAccessors.test.ts +0 -1014
- package/src/test/unit/urlParams.test.ts +0 -464
- package/src/test/utils/fileSystemAccessMocks.ts +0 -353
- package/src/test/utils/testHelpers.ts +0 -155
- package/temp/build/typescript/ts_8nwakTlr.json +0 -1
- package/temp/coverage/base.css +0 -224
- package/temp/coverage/block-navigation.js +0 -87
- package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +0 -1018
- package/temp/coverage/crypto-utils/browserHashProvider.ts.html +0 -304
- package/temp/coverage/crypto-utils/index.html +0 -131
- package/temp/coverage/favicon.png +0 -0
- package/temp/coverage/file-tree/directoryHandleStore.ts.html +0 -493
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +0 -1669
- package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
- package/temp/coverage/file-tree/httpTreeAccessors.ts.html +0 -1429
- package/temp/coverage/file-tree/index.html +0 -176
- package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +0 -1375
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +0 -406
- package/temp/coverage/helpers/index.html +0 -116
- package/temp/coverage/index.html +0 -161
- package/temp/coverage/lcov-report/base.css +0 -224
- package/temp/coverage/lcov-report/block-navigation.js +0 -87
- package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +0 -1018
- package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +0 -304
- package/temp/coverage/lcov-report/crypto-utils/index.html +0 -131
- package/temp/coverage/lcov-report/favicon.png +0 -0
- package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +0 -493
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +0 -1669
- package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
- package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +0 -1429
- package/temp/coverage/lcov-report/file-tree/index.html +0 -176
- package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +0 -1375
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +0 -406
- package/temp/coverage/lcov-report/helpers/index.html +0 -116
- package/temp/coverage/lcov-report/index.html +0 -161
- package/temp/coverage/lcov-report/prettify.css +0 -1
- package/temp/coverage/lcov-report/prettify.js +0 -2
- package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/temp/coverage/lcov-report/sorter.js +0 -210
- package/temp/coverage/lcov-report/url-utils/index.html +0 -116
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +0 -820
- package/temp/coverage/lcov.info +0 -3597
- package/temp/coverage/prettify.css +0 -1
- package/temp/coverage/prettify.js +0 -2
- package/temp/coverage/sort-arrow-sprite.png +0 -0
- package/temp/coverage/sorter.js +0 -210
- package/temp/coverage/url-utils/index.html +0 -116
- package/temp/coverage/url-utils/urlParams.ts.html +0 -820
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/7c/package_7c16afc8299e635d80273763175c7a50 +0 -53
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
- package/temp/ts-web-extras.api.json +0 -8850
- package/temp/ts-web-extras.api.md +0 -433
- package/tsconfig.json +0 -7
|
@@ -0,0 +1,238 @@
|
|
|
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 { captureAsyncResult, captureResult, fail, succeed } from '@fgv/ts-utils';
|
|
23
|
+
const DEFAULT_DATABASE_NAME = 'fgv-keystore-private-keys';
|
|
24
|
+
const DEFAULT_STORE_NAME = 'privateKeys';
|
|
25
|
+
/**
|
|
26
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage | IPrivateKeyStorage}
|
|
27
|
+
* implementation backed by IndexedDB. Stores `CryptoKey` objects directly via
|
|
28
|
+
* IndexedDB's structured-clone serialization — no JWK round-trip — so it works
|
|
29
|
+
* with non-extractable keys.
|
|
30
|
+
*
|
|
31
|
+
* `supportsNonExtractable` is `true`: because the `CryptoKey` is stored by
|
|
32
|
+
* reference (structured clone) rather than exported, the keystore may generate
|
|
33
|
+
* `extractable: false` keys for maximum security on browsers that support it.
|
|
34
|
+
*
|
|
35
|
+
* The database is opened lazily on first use and cached. Each operation runs in
|
|
36
|
+
* its own transaction, relying on IndexedDB's default serialization. Multi-tab
|
|
37
|
+
* concurrency is a known limitation: two tabs writing the same id can race; this
|
|
38
|
+
* implementation targets single-tab use.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export class IdbPrivateKeyStorage {
|
|
43
|
+
constructor(factory, databaseName, storeName) {
|
|
44
|
+
/**
|
|
45
|
+
* `true` — IndexedDB stores `CryptoKey` objects directly, so non-extractable
|
|
46
|
+
* keys are supported.
|
|
47
|
+
*/
|
|
48
|
+
this.supportsNonExtractable = true;
|
|
49
|
+
this._factory = factory;
|
|
50
|
+
this._databaseName = databaseName;
|
|
51
|
+
this._storeName = storeName;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new {@link CryptoUtils.IdbPrivateKeyStorage}.
|
|
55
|
+
* @param params - Optional {@link CryptoUtils.IIdbPrivateKeyStorageCreateParams}.
|
|
56
|
+
* @returns `Success` with the new instance, or `Failure` if no IndexedDB
|
|
57
|
+
* factory is available.
|
|
58
|
+
*/
|
|
59
|
+
static create(params = {}) {
|
|
60
|
+
var _a, _b, _c;
|
|
61
|
+
const factory = (_a = params.indexedDB) !== null && _a !== void 0 ? _a : globalThis.indexedDB;
|
|
62
|
+
if (factory === undefined) {
|
|
63
|
+
return fail('IdbPrivateKeyStorage: no IndexedDB factory available (pass params.indexedDB)');
|
|
64
|
+
}
|
|
65
|
+
return succeed(new IdbPrivateKeyStorage(factory, (_b = params.databaseName) !== null && _b !== void 0 ? _b : DEFAULT_DATABASE_NAME, (_c = params.storeName) !== null && _c !== void 0 ? _c : DEFAULT_STORE_NAME));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Stores `key` under `id`.
|
|
69
|
+
* @param id - Storage handle to write under.
|
|
70
|
+
* @param key - The private `CryptoKey` to persist.
|
|
71
|
+
*/
|
|
72
|
+
async store(id, key) {
|
|
73
|
+
if (key.type !== 'private') {
|
|
74
|
+
return fail(`failed to store private key '${id}': expected a private key, got '${key.type}'`);
|
|
75
|
+
}
|
|
76
|
+
return (await this._withStore('readwrite', (store) => this._request(store.put(key, id))))
|
|
77
|
+
.withErrorFormat((msg) => `failed to store private key '${id}': ${msg}`)
|
|
78
|
+
.onSuccess(() => succeed(id));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Loads the private key stored under `id`.
|
|
82
|
+
* @param id - Storage handle to look up.
|
|
83
|
+
*/
|
|
84
|
+
async load(id) {
|
|
85
|
+
return (await this._getRaw(id))
|
|
86
|
+
.withErrorFormat((msg) => `failed to load private key '${id}': ${msg}`)
|
|
87
|
+
.onSuccess((key) => (key === undefined ? fail(`key not found: '${id}'`) : succeed(key)));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Deletes the entry stored under `id`. Missing ids fail, mirroring the
|
|
91
|
+
* encrypted-file backend. The existence check and the delete run in separate
|
|
92
|
+
* transactions (single-tab assumption).
|
|
93
|
+
* @param id - Storage handle to remove.
|
|
94
|
+
*/
|
|
95
|
+
async delete(id) {
|
|
96
|
+
const existingResult = await this._getRaw(id);
|
|
97
|
+
/* c8 ignore next 3 - defensive: the existence-check read only fails on an IndexedDB environment error */
|
|
98
|
+
if (existingResult.isFailure()) {
|
|
99
|
+
return fail(`failed to delete private key '${id}': ${existingResult.message}`);
|
|
100
|
+
}
|
|
101
|
+
if (existingResult.value === undefined) {
|
|
102
|
+
return fail(`key not found: '${id}'`);
|
|
103
|
+
}
|
|
104
|
+
return (await this._withStore('readwrite', (store) => this._request(store.delete(id))))
|
|
105
|
+
.withErrorFormat((msg) => `failed to delete private key '${id}': ${msg}`)
|
|
106
|
+
.onSuccess(() => succeed(id));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Lists every stored id.
|
|
110
|
+
*/
|
|
111
|
+
async list() {
|
|
112
|
+
return (await this._withStore('readonly', (store) => this._request(store.getAllKeys())))
|
|
113
|
+
.withErrorFormat((msg) => `failed to list private keys: ${msg}`)
|
|
114
|
+
.onSuccess((keys) => succeed(keys.map((key) => String(key))));
|
|
115
|
+
}
|
|
116
|
+
async _getRaw(id) {
|
|
117
|
+
return this._withStore('readonly', (store) => this._request(store.get(id)));
|
|
118
|
+
}
|
|
119
|
+
async _openDb() {
|
|
120
|
+
if (this._db !== undefined) {
|
|
121
|
+
return succeed(this._db);
|
|
122
|
+
}
|
|
123
|
+
const firstOpen = await this._open(undefined);
|
|
124
|
+
/* c8 ignore next 3 - defensive: database open only fails on a corrupted/blocked IndexedDB environment */
|
|
125
|
+
if (firstOpen.isFailure()) {
|
|
126
|
+
return firstOpen;
|
|
127
|
+
}
|
|
128
|
+
// The object store is created in `onupgradeneeded`, which only fires when
|
|
129
|
+
// the version changes. If a database at this name already existed at the
|
|
130
|
+
// current version but without our store (e.g. a different `storeName` than
|
|
131
|
+
// a prior instance used), the store is absent. Re-open at the next version
|
|
132
|
+
// to add it via a version-bump upgrade rather than failing later writes
|
|
133
|
+
// with NotFoundError.
|
|
134
|
+
let db = firstOpen.value;
|
|
135
|
+
if (!db.objectStoreNames.contains(this._storeName)) {
|
|
136
|
+
const nextVersion = db.version + 1;
|
|
137
|
+
db.close();
|
|
138
|
+
const reopen = await this._open(nextVersion);
|
|
139
|
+
/* c8 ignore next 3 - defensive: the version-bump re-open only fails on an IndexedDB environment fault */
|
|
140
|
+
if (reopen.isFailure()) {
|
|
141
|
+
return reopen;
|
|
142
|
+
}
|
|
143
|
+
db = reopen.value;
|
|
144
|
+
}
|
|
145
|
+
this._db = db;
|
|
146
|
+
return succeed(db);
|
|
147
|
+
}
|
|
148
|
+
async _open(version) {
|
|
149
|
+
return captureAsyncResult(() => new Promise((resolve, reject) => {
|
|
150
|
+
const request = version === undefined
|
|
151
|
+
? this._factory.open(this._databaseName)
|
|
152
|
+
: this._factory.open(this._databaseName, version);
|
|
153
|
+
request.onupgradeneeded = () => {
|
|
154
|
+
// Create our object store if absent. This fires on initial creation
|
|
155
|
+
// and on the version bump used to add a store to an existing
|
|
156
|
+
// database; future schema migrations extend this hook additively.
|
|
157
|
+
if (!request.result.objectStoreNames.contains(this._storeName)) {
|
|
158
|
+
request.result.createObjectStore(this._storeName);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
request.onsuccess = () => {
|
|
162
|
+
const db = request.result;
|
|
163
|
+
// If another connection (e.g. a sibling instance adding a store via
|
|
164
|
+
// version bump, or another tab) needs to upgrade, close this one so
|
|
165
|
+
// we don't block it. Clear the cached handle first so the next
|
|
166
|
+
// operation reopens rather than reusing the now-closed connection.
|
|
167
|
+
// Single-tab use is the documented assumption; this just prevents a
|
|
168
|
+
// deadlock when several instances share a db.
|
|
169
|
+
db.onversionchange = () => {
|
|
170
|
+
if (this._db === db) {
|
|
171
|
+
this._db = undefined;
|
|
172
|
+
}
|
|
173
|
+
db.close();
|
|
174
|
+
};
|
|
175
|
+
resolve(db);
|
|
176
|
+
};
|
|
177
|
+
/* c8 ignore next 2 - defensive: open errors require a corrupted/blocked IndexedDB environment */
|
|
178
|
+
request.onerror = () => { var _a; return reject((_a = request.error) !== null && _a !== void 0 ? _a : new Error('IndexedDB open failed')); };
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
async _withStore(mode, op) {
|
|
182
|
+
const dbResult = await this._openDb();
|
|
183
|
+
/* c8 ignore next 3 - defensive: database open only fails on a corrupted/blocked IndexedDB environment */
|
|
184
|
+
if (dbResult.isFailure()) {
|
|
185
|
+
return fail(dbResult.message);
|
|
186
|
+
}
|
|
187
|
+
const txnResult = captureResult(() => dbResult.value.transaction(this._storeName, mode));
|
|
188
|
+
/* c8 ignore next 3 - transaction creation only throws if the store was deleted out from under us */
|
|
189
|
+
if (txnResult.isFailure()) {
|
|
190
|
+
return fail(txnResult.message);
|
|
191
|
+
}
|
|
192
|
+
const transaction = txnResult.value;
|
|
193
|
+
// For writes, a successful request is not durable until the transaction
|
|
194
|
+
// commits (oncomplete); it can still abort afterwards. Attach the completion
|
|
195
|
+
// listener BEFORE issuing the request so no event is missed, and wait for it
|
|
196
|
+
// before reporting success. Reads need no such wait.
|
|
197
|
+
const completion = mode === 'readwrite' ? this._awaitCompletion(transaction) : undefined;
|
|
198
|
+
// `op` builds and issues the IDB request synchronously (e.g. `store.put`),
|
|
199
|
+
// which can throw before any Promise is created — DataCloneError on a
|
|
200
|
+
// non-cloneable value, or a transaction-state DOMException. Run it inside a
|
|
201
|
+
// capture boundary so those surface as Failure rather than a rejection,
|
|
202
|
+
// preserving the Result contract.
|
|
203
|
+
const opOuter = await captureAsyncResult(() => op(transaction.objectStore(this._storeName)));
|
|
204
|
+
/* c8 ignore next 3 - defensive: synchronous IDB throws (e.g. DataCloneError) are unreachable for the typed public surface (private CryptoKeys clone; reads pass a string id), but the capture preserves the Result contract */
|
|
205
|
+
if (opOuter.isFailure()) {
|
|
206
|
+
return fail(opOuter.message);
|
|
207
|
+
}
|
|
208
|
+
const opResult = opOuter.value;
|
|
209
|
+
/* c8 ignore next 3 - defensive: the request itself only fails on an IndexedDB environment fault */
|
|
210
|
+
if (opResult.isFailure()) {
|
|
211
|
+
return opResult;
|
|
212
|
+
}
|
|
213
|
+
if (completion !== undefined) {
|
|
214
|
+
const commitResult = await completion;
|
|
215
|
+
/* c8 ignore next 3 - defensive: a transaction abort after a successful request requires an IndexedDB environment fault */
|
|
216
|
+
if (commitResult.isFailure()) {
|
|
217
|
+
return fail(commitResult.message);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return opResult;
|
|
221
|
+
}
|
|
222
|
+
async _request(request) {
|
|
223
|
+
return captureAsyncResult(() => new Promise((resolve, reject) => {
|
|
224
|
+
request.onsuccess = () => resolve(request.result);
|
|
225
|
+
/* c8 ignore next 2 - defensive: per-request errors require a corrupted IndexedDB environment */
|
|
226
|
+
request.onerror = () => { var _a; return reject((_a = request.error) !== null && _a !== void 0 ? _a : new Error('IndexedDB request failed')); };
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
async _awaitCompletion(transaction) {
|
|
230
|
+
return captureAsyncResult(() => new Promise((resolve, reject) => {
|
|
231
|
+
transaction.oncomplete = () => resolve(true);
|
|
232
|
+
/* c8 ignore next 4 - defensive: abort/error after a successful write requires an IndexedDB environment fault */
|
|
233
|
+
transaction.onabort = () => { var _a; return reject((_a = transaction.error) !== null && _a !== void 0 ? _a : new Error('IndexedDB transaction aborted')); };
|
|
234
|
+
transaction.onerror = () => { var _a; return reject((_a = transaction.error) !== null && _a !== void 0 ? _a : new Error('IndexedDB transaction error')); };
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=idbPrivateKeyStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idbPrivateKeyStorage.js","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/idbPrivateKeyStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,IAAI,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AA0BzF,MAAM,qBAAqB,GAAW,2BAA2B,CAAC;AAClE,MAAM,kBAAkB,GAAW,aAAa,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,oBAAoB;IAY/B,YAAoB,OAAmB,EAAE,YAAoB,EAAE,SAAiB;QAXhF;;;WAGG;QACa,2BAAsB,GAAS,IAAI,CAAC;QAQlD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,SAA4C,EAAE;;QACjE,MAAM,OAAO,GAA2B,MAAA,MAAM,CAAC,SAAS,mCAAI,UAAU,CAAC,SAAS,CAAC;QACjF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC9F,CAAC;QACD,OAAO,OAAO,CACZ,IAAI,oBAAoB,CACtB,OAAO,EACP,MAAA,MAAM,CAAC,YAAY,mCAAI,qBAAqB,EAC5C,MAAA,MAAM,CAAC,SAAS,mCAAI,kBAAkB,CACvC,CACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAK,CAAC,EAAU,EAAE,GAAc;QAC3C,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAA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C,OAAO,EAAE,MAAM,EAAE,EAAE;YACjC,OAAO,CAAC,SAAS,GAAG,GAAS,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACxD,gGAAgG;YAChG,OAAO,CAAC,OAAO,GAAG,GAAS,EAAE,WAAC,OAAA,MAAM,CAAC,MAAA,OAAO,CAAC,KAAK,mCAAI,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAA,EAAA,CAAC;QAC/F,CAAC,CAAC,CACL,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,WAA2B;QACxD,OAAO,kBAAkB,CACvB,GAAG,EAAE,CACH,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpC,WAAW,CAAC,UAAU,GAAG,GAAS,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACnD,gHAAgH;YAChH,WAAW,CAAC,OAAO,GAAG,GAAS,EAAE,WAC/B,OAAA,MAAM,CAAC,MAAA,WAAW,CAAC,KAAK,mCAAI,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAA,EAAA,CAAC;YAC1E,WAAW,CAAC,OAAO,GAAG,GAAS,EAAE,WAC/B,OAAA,MAAM,CAAC,MAAA,WAAW,CAAC,KAAK,mCAAI,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAA,EAAA,CAAC;QAC1E,CAAC,CAAC,CACL,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureAsyncResult, captureResult, fail, Result, succeed } from '@fgv/ts-utils';\nimport { CryptoUtils } from '@fgv/ts-extras';\n\n/**\n * Parameters for {@link CryptoUtils.IdbPrivateKeyStorage.create}.\n * @public\n */\nexport interface IIdbPrivateKeyStorageCreateParams {\n /**\n * IndexedDB database name. Default: `'fgv-keystore-private-keys'`.\n */\n readonly databaseName?: string;\n\n /**\n * IndexedDB object-store name. Default: `'privateKeys'`.\n */\n readonly storeName?: string;\n\n /**\n * IndexedDB factory to use. Defaults to `globalThis.indexedDB`. Supplied\n * explicitly in tests (e.g. a `fake-indexeddb` factory) or to target a\n * non-default factory.\n */\n readonly indexedDB?: IDBFactory;\n}\n\nconst DEFAULT_DATABASE_NAME: string = 'fgv-keystore-private-keys';\nconst DEFAULT_STORE_NAME: string = 'privateKeys';\n\n/**\n * {@link CryptoUtils.KeyStore.IPrivateKeyStorage | IPrivateKeyStorage}\n * implementation backed by IndexedDB. Stores `CryptoKey` objects directly via\n * IndexedDB's structured-clone serialization — no JWK round-trip — so it works\n * with non-extractable keys.\n *\n * `supportsNonExtractable` is `true`: because the `CryptoKey` is stored by\n * reference (structured clone) rather than exported, the keystore may generate\n * `extractable: false` keys for maximum security on browsers that support it.\n *\n * The database is opened lazily on first use and cached. Each operation runs in\n * its own transaction, relying on IndexedDB's default serialization. Multi-tab\n * concurrency is a known limitation: two tabs writing the same id can race; this\n * implementation targets single-tab use.\n *\n * @public\n */\nexport class IdbPrivateKeyStorage implements CryptoUtils.KeyStore.IPrivateKeyStorage {\n /**\n * `true` — IndexedDB stores `CryptoKey` objects directly, so non-extractable\n * keys are supported.\n */\n public readonly supportsNonExtractable: true = true;\n\n private readonly _factory: IDBFactory;\n private readonly _databaseName: string;\n private readonly _storeName: string;\n private _db: IDBDatabase | undefined;\n\n private constructor(factory: IDBFactory, databaseName: string, storeName: string) {\n this._factory = factory;\n this._databaseName = databaseName;\n this._storeName = storeName;\n }\n\n /**\n * Creates a new {@link CryptoUtils.IdbPrivateKeyStorage}.\n * @param params - Optional {@link CryptoUtils.IIdbPrivateKeyStorageCreateParams}.\n * @returns `Success` with the new instance, or `Failure` if no IndexedDB\n * factory is available.\n */\n public static create(params: IIdbPrivateKeyStorageCreateParams = {}): Result<IdbPrivateKeyStorage> {\n const factory: IDBFactory | undefined = params.indexedDB ?? globalThis.indexedDB;\n if (factory === undefined) {\n return fail('IdbPrivateKeyStorage: no IndexedDB factory available (pass params.indexedDB)');\n }\n return succeed(\n new IdbPrivateKeyStorage(\n factory,\n params.databaseName ?? DEFAULT_DATABASE_NAME,\n params.storeName ?? DEFAULT_STORE_NAME\n )\n );\n }\n\n /**\n * Stores `key` under `id`.\n * @param id - Storage handle to write under.\n * @param key - The private `CryptoKey` to persist.\n */\n public async store(id: string, key: CryptoKey): Promise<Result<string>> {\n if (key.type !== 'private') {\n return fail(`failed to store private key '${id}': expected a private key, got '${key.type}'`);\n }\n return (await this._withStore('readwrite', (store) => this._request(store.put(key, id))))\n .withErrorFormat((msg) => `failed to store private key '${id}': ${msg}`)\n .onSuccess(() => succeed(id));\n }\n\n /**\n * Loads the private key stored under `id`.\n * @param id - Storage handle to look up.\n */\n public async load(id: string): Promise<Result<CryptoKey>> {\n return (await this._getRaw(id))\n .withErrorFormat((msg) => `failed to load private key '${id}': ${msg}`)\n .onSuccess((key) => (key === undefined ? fail(`key not found: '${id}'`) : succeed(key)));\n }\n\n /**\n * Deletes the entry stored under `id`. Missing ids fail, mirroring the\n * encrypted-file backend. The existence check and the delete run in separate\n * transactions (single-tab assumption).\n * @param id - Storage handle to remove.\n */\n public async delete(id: string): Promise<Result<string>> {\n const existingResult = await this._getRaw(id);\n /* c8 ignore next 3 - defensive: the existence-check read only fails on an IndexedDB environment error */\n if (existingResult.isFailure()) {\n return fail(`failed to delete private key '${id}': ${existingResult.message}`);\n }\n if (existingResult.value === undefined) {\n return fail(`key not found: '${id}'`);\n }\n return (await this._withStore('readwrite', (store) => this._request(store.delete(id))))\n .withErrorFormat((msg) => `failed to delete private key '${id}': ${msg}`)\n .onSuccess(() => succeed(id));\n }\n\n /**\n * Lists every stored id.\n */\n public async list(): Promise<Result<readonly string[]>> {\n return (await this._withStore('readonly', (store) => this._request<IDBValidKey[]>(store.getAllKeys())))\n .withErrorFormat((msg) => `failed to list private keys: ${msg}`)\n .onSuccess((keys) => succeed(keys.map((key) => String(key))));\n }\n\n private async _getRaw(id: string): Promise<Result<CryptoKey | undefined>> {\n return this._withStore('readonly', (store) => this._request<CryptoKey | undefined>(store.get(id)));\n }\n\n private async _openDb(): Promise<Result<IDBDatabase>> {\n if (this._db !== undefined) {\n return succeed(this._db);\n }\n const firstOpen = await this._open(undefined);\n /* c8 ignore next 3 - defensive: database open only fails on a corrupted/blocked IndexedDB environment */\n if (firstOpen.isFailure()) {\n return firstOpen;\n }\n // The object store is created in `onupgradeneeded`, which only fires when\n // the version changes. If a database at this name already existed at the\n // current version but without our store (e.g. a different `storeName` than\n // a prior instance used), the store is absent. Re-open at the next version\n // to add it via a version-bump upgrade rather than failing later writes\n // with NotFoundError.\n let db = firstOpen.value;\n if (!db.objectStoreNames.contains(this._storeName)) {\n const nextVersion = db.version + 1;\n db.close();\n const reopen = await this._open(nextVersion);\n /* c8 ignore next 3 - defensive: the version-bump re-open only fails on an IndexedDB environment fault */\n if (reopen.isFailure()) {\n return reopen;\n }\n db = reopen.value;\n }\n this._db = db;\n return succeed(db);\n }\n\n private async _open(version: number | undefined): Promise<Result<IDBDatabase>> {\n return captureAsyncResult<IDBDatabase>(\n () =>\n new Promise<IDBDatabase>((resolve, reject) => {\n const request =\n version === undefined\n ? this._factory.open(this._databaseName)\n : this._factory.open(this._databaseName, version);\n request.onupgradeneeded = (): void => {\n // Create our object store if absent. This fires on initial creation\n // and on the version bump used to add a store to an existing\n // database; future schema migrations extend this hook additively.\n if (!request.result.objectStoreNames.contains(this._storeName)) {\n request.result.createObjectStore(this._storeName);\n }\n };\n request.onsuccess = (): void => {\n const db = request.result;\n // If another connection (e.g. a sibling instance adding a store via\n // version bump, or another tab) needs to upgrade, close this one so\n // we don't block it. Clear the cached handle first so the next\n // operation reopens rather than reusing the now-closed connection.\n // Single-tab use is the documented assumption; this just prevents a\n // deadlock when several instances share a db.\n db.onversionchange = (): void => {\n if (this._db === db) {\n this._db = undefined;\n }\n db.close();\n };\n resolve(db);\n };\n /* c8 ignore next 2 - defensive: open errors require a corrupted/blocked IndexedDB environment */\n request.onerror = (): void => reject(request.error ?? new Error('IndexedDB open failed'));\n })\n );\n }\n\n private async _withStore<T>(\n mode: IDBTransactionMode,\n op: (store: IDBObjectStore) => Promise<Result<T>>\n ): Promise<Result<T>> {\n const dbResult = await this._openDb();\n /* c8 ignore next 3 - defensive: database open only fails on a corrupted/blocked IndexedDB environment */\n if (dbResult.isFailure()) {\n return fail(dbResult.message);\n }\n const txnResult = captureResult(() => dbResult.value.transaction(this._storeName, mode));\n /* c8 ignore next 3 - transaction creation only throws if the store was deleted out from under us */\n if (txnResult.isFailure()) {\n return fail(txnResult.message);\n }\n const transaction = txnResult.value;\n\n // For writes, a successful request is not durable until the transaction\n // commits (oncomplete); it can still abort afterwards. Attach the completion\n // listener BEFORE issuing the request so no event is missed, and wait for it\n // before reporting success. Reads need no such wait.\n const completion = mode === 'readwrite' ? this._awaitCompletion(transaction) : undefined;\n\n // `op` builds and issues the IDB request synchronously (e.g. `store.put`),\n // which can throw before any Promise is created — DataCloneError on a\n // non-cloneable value, or a transaction-state DOMException. Run it inside a\n // capture boundary so those surface as Failure rather than a rejection,\n // preserving the Result contract.\n const opOuter = await captureAsyncResult(() => op(transaction.objectStore(this._storeName)));\n /* c8 ignore next 3 - defensive: synchronous IDB throws (e.g. DataCloneError) are unreachable for the typed public surface (private CryptoKeys clone; reads pass a string id), but the capture preserves the Result contract */\n if (opOuter.isFailure()) {\n return fail(opOuter.message);\n }\n const opResult = opOuter.value;\n /* c8 ignore next 3 - defensive: the request itself only fails on an IndexedDB environment fault */\n if (opResult.isFailure()) {\n return opResult;\n }\n if (completion !== undefined) {\n const commitResult = await completion;\n /* c8 ignore next 3 - defensive: a transaction abort after a successful request requires an IndexedDB environment fault */\n if (commitResult.isFailure()) {\n return fail(commitResult.message);\n }\n }\n return opResult;\n }\n\n private async _request<T>(request: IDBRequest<T>): Promise<Result<T>> {\n return captureAsyncResult<T>(\n () =>\n new Promise<T>((resolve, reject) => {\n request.onsuccess = (): void => resolve(request.result);\n /* c8 ignore next 2 - defensive: per-request errors require a corrupted IndexedDB environment */\n request.onerror = (): void => reject(request.error ?? new Error('IndexedDB request failed'));\n })\n );\n }\n\n private async _awaitCompletion(transaction: IDBTransaction): Promise<Result<true>> {\n return captureAsyncResult<true>(\n () =>\n new Promise<true>((resolve, reject) => {\n transaction.oncomplete = (): void => resolve(true);\n /* c8 ignore next 4 - defensive: abort/error after a successful write requires an IndexedDB environment fault */\n transaction.onabort = (): void =>\n reject(transaction.error ?? new Error('IndexedDB transaction aborted'));\n transaction.onerror = (): void =>\n reject(transaction.error ?? new Error('IndexedDB transaction error'));\n })\n );\n }\n}\n"]}
|
|
@@ -25,4 +25,17 @@
|
|
|
25
25
|
*/
|
|
26
26
|
export * from './browserHashProvider';
|
|
27
27
|
export * from './browserCryptoProvider';
|
|
28
|
+
export * from './idbPrivateKeyStorage';
|
|
29
|
+
// HpkeProvider re-export: implementation lives in @fgv/ts-extras CryptoUtils packlet;
|
|
30
|
+
// re-exported here so browser callers can import from @fgv/ts-web-extras for this primitive.
|
|
31
|
+
// We import from the top-level namespace to avoid relying on package.json exports path
|
|
32
|
+
// resolution (which requires moduleResolution: node16 or bundler).
|
|
33
|
+
import { CryptoUtils } from '@fgv/ts-extras';
|
|
34
|
+
/**
|
|
35
|
+
* HPKE base mode (RFC 9180) — `DHKEM(X25519, HKDF-SHA256) + HKDF-SHA256 + AES-256-GCM`.
|
|
36
|
+
* Re-exported from `@fgv/ts-extras` for browser consumers.
|
|
37
|
+
* @see {@link CryptoUtils.HpkeProvider}
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export const HpkeProvider = CryptoUtils.HpkeProvider;
|
|
28
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Browser-compatible cryptographic utilities using the Web Crypto API.\n * @packageDocumentation\n */\n\nexport * from './browserHashProvider';\nexport * from './browserCryptoProvider';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AAEvC,sFAAsF;AACtF,6FAA6F;AAC7F,uFAAuF;AACvF,mEAAmE;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAoC,WAAW,CAAC,YAAY,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Browser-compatible cryptographic utilities using the Web Crypto API.\n * @packageDocumentation\n */\n\nexport * from './browserHashProvider';\nexport * from './browserCryptoProvider';\nexport * from './idbPrivateKeyStorage';\n\n// HpkeProvider re-export: implementation lives in @fgv/ts-extras CryptoUtils packlet;\n// re-exported here so browser callers can import from @fgv/ts-web-extras for this primitive.\n// We import from the top-level namespace to avoid relying on package.json exports path\n// resolution (which requires moduleResolution: node16 or bundler).\nimport { CryptoUtils } from '@fgv/ts-extras';\n\n/**\n * HPKE base mode (RFC 9180) — `DHKEM(X25519, HKDF-SHA256) + HKDF-SHA256 + AES-256-GCM`.\n * Re-exported from `@fgv/ts-extras` for browser consumers.\n * @see {@link CryptoUtils.HpkeProvider}\n * @public\n */\nexport const HpkeProvider: typeof CryptoUtils.HpkeProvider = CryptoUtils.HpkeProvider;\n\n/**\n * Output of `HpkeProvider.sealBase`. Re-exported from `@fgv/ts-extras`.\n * @public\n */\nexport type IHpkeSealResult = CryptoUtils.IHpkeSealResult;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directoryHandleStore.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/directoryHandleStore.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAG9D;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"directoryHandleStore.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/directoryHandleStore.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAG9D;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAW,uBAAuB,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAW,mBAAmB,CAAC;AAE1E;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAG/B,YACE,SAAiB,2BAA2B,EAC5C,YAAoB,8BAA8B;QAElD,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,MAAiC;QAChE,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACtC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,8BAA8B,KAAK,MAAM,MAAM,CAAC,CAAC,CAAC,EAAE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ED,MAAM,OAAO,GAAgE,EAAE,CAAC;QAChF,KAAK,MAAM,KAAK,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;YACvC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5C,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;YACD,IAAI,YAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACrC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\n/**\n * Persistent storage for FileSystemDirectoryHandle objects using IndexedDB.\n * Allows directory handles to survive page reloads without re-prompting the user.\n * @packageDocumentation\n */\n\nimport { fail, Result, succeed } from '@fgv/ts-utils';\nimport { createStore, del, get, keys, set } from 'idb-keyval';\nimport { FileSystemDirectoryHandle } from '../file-api-types';\n\n/**\n * Default IndexedDB database name for directory handles.\n * @public\n */\nexport const DEFAULT_DIRECTORY_HANDLE_DB: string = 'chocolate-lab-storage';\n\n/**\n * Default IndexedDB store name for directory handles.\n * @public\n */\nexport const DEFAULT_DIRECTORY_HANDLE_STORE: string = 'directory-handles';\n\n/**\n * Manages persistence of {@link FileSystemDirectoryHandle} objects in IndexedDB.\n * Keyed by a label (typically the directory name).\n * @public\n */\nexport class DirectoryHandleStore {\n private readonly _store: ReturnType<typeof createStore>;\n\n public constructor(\n dbName: string = DEFAULT_DIRECTORY_HANDLE_DB,\n storeName: string = DEFAULT_DIRECTORY_HANDLE_STORE\n ) {\n this._store = createStore(dbName, storeName);\n }\n\n /**\n * Saves a directory handle to IndexedDB under the given label.\n * @param label - Key to store the handle under (typically dirHandle.name)\n * @param handle - The FileSystemDirectoryHandle to persist\n * @returns Success or Failure\n */\n public async save(label: string, handle: FileSystemDirectoryHandle): Promise<Result<void>> {\n try {\n await set(label, handle, this._store);\n return succeed(undefined);\n } catch (e) {\n return fail(`DirectoryHandleStore.save \"${label}\": ${String(e)}`);\n }\n }\n\n /**\n * Retrieves a directory handle by label.\n * @param label - Key to look up\n * @returns Success with handle (or undefined if not found), or Failure on error\n */\n public async load(label: string): Promise<Result<FileSystemDirectoryHandle | undefined>> {\n try {\n const handle = await get<FileSystemDirectoryHandle>(label, this._store);\n return succeed(handle);\n } catch (e) {\n return fail(`DirectoryHandleStore.load \"${label}\": ${String(e)}`);\n }\n }\n\n /**\n * Removes a directory handle from IndexedDB.\n * @param label - Key to remove\n * @returns Success or Failure\n */\n public async remove(label: string): Promise<Result<void>> {\n try {\n await del(label, this._store);\n return succeed(undefined);\n } catch (e) {\n return fail(`DirectoryHandleStore.remove \"${label}\": ${String(e)}`);\n }\n }\n\n /**\n * Returns all stored labels (keys).\n * @returns Success with array of labels, or Failure\n */\n public async getAllLabels(): Promise<Result<string[]>> {\n try {\n const allKeys = await keys<string>(this._store);\n return succeed(allKeys);\n } catch (e) {\n return fail(`DirectoryHandleStore.getAllLabels: ${String(e)}`);\n }\n }\n\n /**\n * Returns all stored handles as label/handle pairs.\n * @returns Success with array of entries, or Failure\n */\n public async getAll(): Promise<Result<Array<{ label: string; handle: FileSystemDirectoryHandle }>>> {\n const labelsResult = await this.getAllLabels();\n if (labelsResult.isFailure()) {\n return fail(labelsResult.message);\n }\n\n const entries: Array<{ label: string; handle: FileSystemDirectoryHandle }> = [];\n for (const label of labelsResult.value) {\n const handleResult = await this.load(label);\n if (handleResult.isFailure()) {\n return fail(handleResult.message);\n }\n if (handleResult.value !== undefined) {\n entries.push({ label, handle: handleResult.value });\n }\n }\n return succeed(entries);\n }\n}\n"]}
|
|
@@ -236,7 +236,7 @@ export class FileApiTreeAccessors {
|
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
238
|
* Extract file metadata from a File.
|
|
239
|
-
* @param
|
|
239
|
+
* @param file - The File to extract metadata from
|
|
240
240
|
* @returns The {@link IFileMetadata | file metadata}
|
|
241
241
|
*/
|
|
242
242
|
static extractFileMetadata(file) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileApiTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileApiTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;AAEH,0EAA0E;AAC1E,OAAO,EAAU,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,6BAA6B,EAA+B,MAAM,iCAAiC,CAAC;AAC7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,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpE,kEAAkE;QAClE,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;IACpE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// File System Access API types are imported via the file-api-types module\nimport { Result, succeed, fail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport {\n isFileHandle,\n isDirectoryHandle,\n FileSystemFileHandle,\n FileSystemDirectoryHandle\n} from '../file-api-types';\nimport { FileSystemAccessTreeAccessors, IFileSystemAccessTreeParams } from './fileSystemAccessTreeAccessors';\nimport { HttpTreeAccessors, IHttpTreeParams } from './httpTreeAccessors';\nimport { LocalStorageTreeAccessors, ILocalStorageTreeParams } from './localStorageTreeAccessors';\n\n/**\n * Interface for File objects that may have the webkitRelativePath property.\n * This property is added by browsers when using directory upload (webkitdirectory).\n * @internal\n */\ninterface IFileWithWebkitPath {\n readonly webkitRelativePath?: string;\n}\n\n/**\n * Helper function to safely get webkitRelativePath from a File object.\n * @internal\n */\nfunction getFileRelativePath(file: File): string {\n return (file as unknown as IFileWithWebkitPath).webkitRelativePath || file.name;\n}\n\n/**\n * Tree initializer for FileList objects (from File API).\n * @public\n */\nexport interface IFileListTreeInitializer {\n readonly fileList: FileList;\n}\n\n/**\n * Tree initializer for File System Access API file handles.\n * @public\n */\nexport interface IFileHandleTreeInitializer {\n readonly prefix?: string;\n readonly fileHandles: FileSystemFileHandle[];\n}\n\n/**\n * Tree initializer for File System Access API directory handles.\n * @public\n */\nexport interface IDirectoryHandleTreeInitializer {\n readonly prefix?: string;\n readonly dirHandles: FileSystemDirectoryHandle[];\n readonly nonRecursive?: boolean; // Default: false (recursive by default)\n}\n\n/**\n * Union type for all supported tree initializers.\n * @public\n */\nexport type TreeInitializer =\n | IFileListTreeInitializer\n | IFileHandleTreeInitializer\n | IDirectoryHandleTreeInitializer;\n\n/**\n * Interface for file metadata.\n * @public\n */\nexport interface IFileMetadata {\n path: string;\n name: string;\n size: number;\n type: string;\n lastModified: number;\n}\n\n/**\n * Helper class to create FileTree instances from various file sources.\n * Supports File API (FileList) and File System Access API handles.\n * @public\n */\nexport class FileApiTreeAccessors<TCT extends string = string> {\n /**\n * Create a persistent FileTree from a File System Access API directory handle.\n * Changes to files can be synced back to disk.\n *\n * @param dirHandle - FileSystemDirectoryHandle to load files from\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n *\n * @remarks\n * - Only works in browsers supporting File System Access API (Chrome, Edge, Opera)\n * - Requires 'readwrite' permission on the directory handle\n * - Falls back to read-only mode if permissions unavailable (unless requireWritePermission is true)\n *\n * @public\n */\n public static async createPersistent<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromDirectoryHandle<TCT>(dirHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from an HTTP storage service.\n *\n * @param params - Configuration including API base URL, namespace, and optional autoSync\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createFromHttp<TCT extends string = string>(\n params: IHttpTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await HttpTreeAccessors.fromHttp<TCT>(params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from a single File System Access API file handle.\n * The tree contains exactly one file at `/<filename>`.\n * Changes can be synced back to the original file via `syncToDisk()`.\n *\n * @param fileHandle - FileSystemFileHandle to load\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createPersistentFromFile<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromFileHandle<TCT>(fileHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from browser localStorage.\n * Changes to files can be synced back to localStorage.\n *\n * @param params - Configuration including path-to-key mappings and optional autoSync\n * @returns Result containing a FileTree with persistence capability\n *\n * @remarks\n * - Works in all browsers with localStorage support\n * - Maps directory paths to localStorage keys\n * - Each key stores multiple collections as JSON\n * - Files are automatically discovered from storage\n *\n * @example\n * ```typescript\n * const tree = FileApiTreeAccessors.createFromLocalStorage({\n * pathToKeyMap: {\n * '/data/ingredients': 'myapp:ingredients:v1',\n * '/data/fillings': 'myapp:fillings:v1'\n * },\n * mutable: true,\n * autoSync: false\n * });\n * ```\n *\n * @public\n */\n public static createFromLocalStorage<TCT extends string = string>(\n params: ILocalStorageTreeParams<TCT>\n ): Result<FileTree.FileTree<TCT>> {\n const accessorsResult = LocalStorageTreeAccessors.fromStorage<TCT>(params);\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create FileTree from various file sources using TreeInitializer array.\n * @param initializers - Array of TreeInitializer objects specifying file sources\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async create<TCT extends string = string>(\n initializers: TreeInitializer[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n try {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const initializer of initializers) {\n const filesResult = await this._processInitializer<TCT>(initializer, params);\n if (filesResult.isFailure()) {\n return fail(filesResult.message);\n }\n allFiles.push(...filesResult.value);\n }\n\n return FileTree.inMemory<TCT>(allFiles, params);\n /* c8 ignore next 5 - defense in depth */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process initializers: ${message}`);\n }\n }\n\n /**\n * Create FileTree from FileList (e.g., from input[type=\"file\"]).\n * @param fileList - FileList from a file input element\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const path = this._normalizePath(params?.prefix || '', file.name);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${file.name}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Create FileTree from directory upload with webkitRelativePath.\n * @param fileList - FileList from a directory upload (input with webkitdirectory)\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromDirectoryUpload<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const relativePath = getFileRelativePath(file);\n const path = this._normalizePath(params?.prefix || '', relativePath);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Get the File object for a specific path from the original FileList.\n * This is useful for accessing the original File API object for operations\n * like getting file metadata, MIME type, etc.\n * @param fileList - The original FileList\n * @param targetPath - The path to find\n * @returns Result containing the File object if found\n */\n public static getOriginalFile(fileList: FileList, targetPath: string): Result<File> {\n for (const file of Array.from(fileList)) {\n const filePath = getFileRelativePath(file);\n if (filePath === targetPath) {\n return succeed(file);\n }\n }\n return fail(`File not found: ${targetPath}`);\n }\n\n /**\n * Extract file metadata from a File.\n * @param fileList - The File to extract metadata from\n * @returns The {@link IFileMetadata | file metadata}\n */\n public static extractFileMetadata(file: File): IFileMetadata {\n return {\n path: getFileRelativePath(file),\n name: file.name,\n size: file.size,\n type: file.type,\n lastModified: file.lastModified\n };\n }\n\n /**\n * Process a single TreeInitializer and return the resulting files.\n * @param initializer - The TreeInitializer to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processInitializer<TCT extends string = string>(\n initializer: TreeInitializer,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n if ('fileList' in initializer) {\n return this._processFileList<TCT>(initializer.fileList, params);\n } else if ('fileHandles' in initializer) {\n return this._processFileHandles<TCT>(initializer.fileHandles, params);\n } else if ('dirHandles' in initializer) {\n return this._processDirectoryHandles<TCT>(\n initializer.dirHandles,\n initializer.prefix ?? params?.prefix,\n !initializer.nonRecursive,\n params\n );\n } else {\n return fail('Unknown initializer type');\n }\n }\n\n /**\n * Process a FileList and return IInMemoryFile array.\n * @param fileList - The FileList to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const metadata = this.extractFileMetadata(file);\n const relativePath = metadata.path;\n const path = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemFileHandles and return IInMemoryFile array.\n * @internal\n */\n private static async _processFileHandles<TCT extends string = string>(\n handles: FileSystemFileHandle[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const handle of handles) {\n try {\n const file = await handle.getFile();\n const contents = await file.text();\n const metadata = this.extractFileMetadata(file);\n /* c8 ignore next 1 - defense in depth */\n const path = this._normalizePath(params?.prefix ?? '', handle.name);\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file handle ${handle.name}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemDirectoryHandles and return IInMemoryFile array.\n * @param handles - The FileSystemDirectoryHandle[] to process\n * @param prefix - The prefix to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandles<TCT extends string = string>(\n handles: FileSystemDirectoryHandle[],\n prefix?: string,\n recursive: boolean = true,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n prefix = prefix ?? params?.prefix;\n\n for (const handle of handles) {\n const dirPrefix = this._normalizePath(prefix ?? '', handle.name);\n const filesResult = await this._processDirectoryHandle<TCT>(handle, dirPrefix, recursive, params);\n if (filesResult.isFailure()) {\n return filesResult;\n }\n allFiles.push(...filesResult.value);\n }\n\n return succeed(allFiles);\n }\n\n /**\n * Process a single FileSystemDirectoryHandle recursively.\n * @param handle - The FileSystemDirectoryHandle to process\n * @param basePath - The base path to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandle<TCT extends string = string>(\n handle: FileSystemDirectoryHandle,\n basePath: string,\n recursive: boolean,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n try {\n for await (const entry of handle.values()) {\n if (isFileHandle(entry)) {\n const file = await entry.getFile();\n const contents = await file.text();\n const path = this._normalizePath(basePath, entry.name);\n const contentType = params?.inferContentType?.(path).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } else if (isDirectoryHandle(entry) && recursive) {\n const subDirPath = this._normalizePath(basePath, entry.name);\n const subdirResult = await this._processDirectoryHandle<TCT>(entry, subDirPath, recursive, params);\n if (subdirResult.isFailure()) {\n return subdirResult;\n }\n files.push(...subdirResult.value);\n }\n }\n\n return succeed(files);\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process directory ${handle.name}: ${message}`);\n }\n }\n\n private static _normalizePath(prefix: string, path: string): string {\n // Remove leading slash from prefix if it exists to avoid double slashes\n const cleanPrefix = prefix ? prefix.replace(/^\\/+/, '') : '';\n const combined = cleanPrefix ? `${cleanPrefix}/${path}` : path;\n // Normalize multiple slashes and ensure it starts with / for FileTree compatibility\n const normalized = combined.replace(/\\/+/g, '/').replace(/\\/$/, '');\n /* c8 ignore next 1 - tested but coverage intermittently missed */\n return normalized.startsWith('/') ? normalized : `/${normalized}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fileApiTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileApiTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;AAEH,0EAA0E;AAC1E,OAAO,EAAU,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB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7D,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,oFAAoF;QACpF,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpE,kEAAkE;QAClE,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;IACpE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// File System Access API types are imported via the file-api-types module\nimport { Result, succeed, fail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport {\n isFileHandle,\n isDirectoryHandle,\n FileSystemFileHandle,\n FileSystemDirectoryHandle\n} from '../file-api-types';\nimport { FileSystemAccessTreeAccessors, IFileSystemAccessTreeParams } from './fileSystemAccessTreeAccessors';\nimport { HttpTreeAccessors, IHttpTreeParams } from './httpTreeAccessors';\nimport { LocalStorageTreeAccessors, ILocalStorageTreeParams } from './localStorageTreeAccessors';\n\n/**\n * Interface for File objects that may have the webkitRelativePath property.\n * This property is added by browsers when using directory upload (webkitdirectory).\n * @internal\n */\ninterface IFileWithWebkitPath {\n readonly webkitRelativePath?: string;\n}\n\n/**\n * Helper function to safely get webkitRelativePath from a File object.\n * @internal\n */\nfunction getFileRelativePath(file: File): string {\n return (file as unknown as IFileWithWebkitPath).webkitRelativePath || file.name;\n}\n\n/**\n * Tree initializer for FileList objects (from File API).\n * @public\n */\nexport interface IFileListTreeInitializer {\n readonly fileList: FileList;\n}\n\n/**\n * Tree initializer for File System Access API file handles.\n * @public\n */\nexport interface IFileHandleTreeInitializer {\n readonly prefix?: string;\n readonly fileHandles: FileSystemFileHandle[];\n}\n\n/**\n * Tree initializer for File System Access API directory handles.\n * @public\n */\nexport interface IDirectoryHandleTreeInitializer {\n readonly prefix?: string;\n readonly dirHandles: FileSystemDirectoryHandle[];\n readonly nonRecursive?: boolean; // Default: false (recursive by default)\n}\n\n/**\n * Union type for all supported tree initializers.\n * @public\n */\nexport type TreeInitializer =\n | IFileListTreeInitializer\n | IFileHandleTreeInitializer\n | IDirectoryHandleTreeInitializer;\n\n/**\n * Interface for file metadata.\n * @public\n */\nexport interface IFileMetadata {\n path: string;\n name: string;\n size: number;\n type: string;\n lastModified: number;\n}\n\n/**\n * Helper class to create FileTree instances from various file sources.\n * Supports File API (FileList) and File System Access API handles.\n * @public\n */\nexport class FileApiTreeAccessors {\n /**\n * Create a persistent FileTree from a File System Access API directory handle.\n * Changes to files can be synced back to disk.\n *\n * @param dirHandle - FileSystemDirectoryHandle to load files from\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n *\n * @remarks\n * - Only works in browsers supporting File System Access API (Chrome, Edge, Opera)\n * - Requires 'readwrite' permission on the directory handle\n * - Falls back to read-only mode if permissions unavailable (unless requireWritePermission is true)\n *\n * @public\n */\n public static async createPersistent<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromDirectoryHandle<TCT>(dirHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from an HTTP storage service.\n *\n * @param params - Configuration including API base URL, namespace, and optional autoSync\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createFromHttp<TCT extends string = string>(\n params: IHttpTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await HttpTreeAccessors.fromHttp<TCT>(params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from a single File System Access API file handle.\n * The tree contains exactly one file at `/<filename>`.\n * Changes can be synced back to the original file via `syncToDisk()`.\n *\n * @param fileHandle - FileSystemFileHandle to load\n * @param params - Optional parameters including autoSync and permission settings\n * @returns Promise resolving to a FileTree with persistence capability\n * @public\n */\n public static async createPersistentFromFile<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const accessorsResult = await FileSystemAccessTreeAccessors.fromFileHandle<TCT>(fileHandle, params);\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create a persistent FileTree from browser localStorage.\n * Changes to files can be synced back to localStorage.\n *\n * @param params - Configuration including path-to-key mappings and optional autoSync\n * @returns Result containing a FileTree with persistence capability\n *\n * @remarks\n * - Works in all browsers with localStorage support\n * - Maps directory paths to localStorage keys\n * - Each key stores multiple collections as JSON\n * - Files are automatically discovered from storage\n *\n * @example\n * ```typescript\n * const tree = FileApiTreeAccessors.createFromLocalStorage({\n * pathToKeyMap: {\n * '/data/ingredients': 'myapp:ingredients:v1',\n * '/data/fillings': 'myapp:fillings:v1'\n * },\n * mutable: true,\n * autoSync: false\n * });\n * ```\n *\n * @public\n */\n public static createFromLocalStorage<TCT extends string = string>(\n params: ILocalStorageTreeParams<TCT>\n ): Result<FileTree.FileTree<TCT>> {\n const accessorsResult = LocalStorageTreeAccessors.fromStorage<TCT>(params);\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (accessorsResult.isFailure()) {\n return fail(accessorsResult.message);\n }\n\n return FileTree.FileTree.create<TCT>(accessorsResult.value);\n }\n\n /**\n * Create FileTree from various file sources using TreeInitializer array.\n * @param initializers - Array of TreeInitializer objects specifying file sources\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async create<TCT extends string = string>(\n initializers: TreeInitializer[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n try {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const initializer of initializers) {\n const filesResult = await this._processInitializer<TCT>(initializer, params);\n if (filesResult.isFailure()) {\n return fail(filesResult.message);\n }\n allFiles.push(...filesResult.value);\n }\n\n return FileTree.inMemory<TCT>(allFiles, params);\n /* c8 ignore next 5 - defense in depth */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process initializers: ${message}`);\n }\n }\n\n /**\n * Create FileTree from FileList (e.g., from input[type=\"file\"]).\n * @param fileList - FileList from a file input element\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const path = this._normalizePath(params?.prefix || '', file.name);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${file.name}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Create FileTree from directory upload with webkitRelativePath.\n * @param fileList - FileList from a directory upload (input with webkitdirectory)\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to a FileTree with all content pre-loaded\n */\n public static async fromDirectoryUpload<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.FileTree<TCT>>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const relativePath = getFileRelativePath(file);\n const path = this._normalizePath(params?.prefix || '', relativePath);\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, file.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return FileTree.inMemory<TCT>(files, params);\n }\n\n /**\n * Get the File object for a specific path from the original FileList.\n * This is useful for accessing the original File API object for operations\n * like getting file metadata, MIME type, etc.\n * @param fileList - The original FileList\n * @param targetPath - The path to find\n * @returns Result containing the File object if found\n */\n public static getOriginalFile(fileList: FileList, targetPath: string): Result<File> {\n for (const file of Array.from(fileList)) {\n const filePath = getFileRelativePath(file);\n if (filePath === targetPath) {\n return succeed(file);\n }\n }\n return fail(`File not found: ${targetPath}`);\n }\n\n /**\n * Extract file metadata from a File.\n * @param file - The File to extract metadata from\n * @returns The {@link IFileMetadata | file metadata}\n */\n public static extractFileMetadata(file: File): IFileMetadata {\n return {\n path: getFileRelativePath(file),\n name: file.name,\n size: file.size,\n type: file.type,\n lastModified: file.lastModified\n };\n }\n\n /**\n * Process a single TreeInitializer and return the resulting files.\n * @param initializer - The TreeInitializer to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processInitializer<TCT extends string = string>(\n initializer: TreeInitializer,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n if ('fileList' in initializer) {\n return this._processFileList<TCT>(initializer.fileList, params);\n } else if ('fileHandles' in initializer) {\n return this._processFileHandles<TCT>(initializer.fileHandles, params);\n } else if ('dirHandles' in initializer) {\n return this._processDirectoryHandles<TCT>(\n initializer.dirHandles,\n initializer.prefix ?? params?.prefix,\n !initializer.nonRecursive,\n params\n );\n } else {\n return fail('Unknown initializer type');\n }\n }\n\n /**\n * Process a FileList and return IInMemoryFile array.\n * @param fileList - The FileList to process\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processFileList<TCT extends string = string>(\n fileList: FileList,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (let i = 0; i < fileList.length; i++) {\n const file = fileList[i];\n const metadata = this.extractFileMetadata(file);\n const relativePath = metadata.path;\n const path = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;\n\n try {\n const contents = await file.text();\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file ${relativePath}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemFileHandles and return IInMemoryFile array.\n * @internal\n */\n private static async _processFileHandles<TCT extends string = string>(\n handles: FileSystemFileHandle[],\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const handle of handles) {\n try {\n const file = await handle.getFile();\n const contents = await file.text();\n const metadata = this.extractFileMetadata(file);\n /* c8 ignore next 1 - defense in depth */\n const path = this._normalizePath(params?.prefix ?? '', handle.name);\n const contentType = params?.inferContentType?.(path, metadata.type).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to read file handle ${handle.name}: ${message}`);\n }\n }\n\n return succeed(files);\n }\n\n /**\n * Process FileSystemDirectoryHandles and return IInMemoryFile array.\n * @param handles - The FileSystemDirectoryHandle[] to process\n * @param prefix - The prefix to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandles<TCT extends string = string>(\n handles: FileSystemDirectoryHandle[],\n prefix?: string,\n recursive: boolean = true,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n prefix = prefix ?? params?.prefix;\n\n for (const handle of handles) {\n const dirPrefix = this._normalizePath(prefix ?? '', handle.name);\n const filesResult = await this._processDirectoryHandle<TCT>(handle, dirPrefix, recursive, params);\n if (filesResult.isFailure()) {\n return filesResult;\n }\n allFiles.push(...filesResult.value);\n }\n\n return succeed(allFiles);\n }\n\n /**\n * Process a single FileSystemDirectoryHandle recursively.\n * @param handle - The FileSystemDirectoryHandle to process\n * @param basePath - The base path to use for the file paths\n * @param recursive - Whether to process the directory recursively\n * @param params - Optional `IFileTreeInitParams` for the file tree.\n * @returns Promise resolving to an array of `IInMemoryFile` objects\n * @internal\n */\n private static async _processDirectoryHandle<TCT extends string = string>(\n handle: FileSystemDirectoryHandle,\n basePath: string,\n recursive: boolean,\n params?: FileTree.IFileTreeInitParams<TCT>\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n try {\n for await (const entry of handle.values()) {\n if (isFileHandle(entry)) {\n const file = await entry.getFile();\n const contents = await file.text();\n const path = this._normalizePath(basePath, entry.name);\n const contentType = params?.inferContentType?.(path).orDefault();\n\n files.push({\n path,\n contents,\n contentType\n });\n } else if (isDirectoryHandle(entry) && recursive) {\n const subDirPath = this._normalizePath(basePath, entry.name);\n const subdirResult = await this._processDirectoryHandle<TCT>(entry, subDirPath, recursive, params);\n if (subdirResult.isFailure()) {\n return subdirResult;\n }\n files.push(...subdirResult.value);\n }\n }\n\n return succeed(files);\n } catch (error) {\n /* c8 ignore next 1 - defense in depth */\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to process directory ${handle.name}: ${message}`);\n }\n }\n\n private static _normalizePath(prefix: string, path: string): string {\n // Remove leading slash from prefix if it exists to avoid double slashes\n const cleanPrefix = prefix ? prefix.replace(/^\\/+/, '') : '';\n const combined = cleanPrefix ? `${cleanPrefix}/${path}` : path;\n // Normalize multiple slashes and ensure it starts with / for FileTree compatibility\n const normalized = combined.replace(/\\/+/g, '/').replace(/\\/$/, '');\n /* c8 ignore next 1 - tested but coverage intermittently missed */\n return normalized.startsWith('/') ? normalized : `/${normalized}`;\n }\n}\n"]}
|
|
@@ -290,7 +290,7 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
|
|
|
290
290
|
if (this._hasWritePermission) {
|
|
291
291
|
this._pendingDeletions.add(path);
|
|
292
292
|
if (this._autoSync) {
|
|
293
|
-
|
|
293
|
+
this._runAutoSyncTask(path, 'delete', () => this._deleteFileFromDisk(path)).catch(() => undefined);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
}
|
|
@@ -307,7 +307,7 @@ export class FileSystemAccessTreeAccessors extends FileTree.InMemoryTreeAccessor
|
|
|
307
307
|
// Auto-sync if enabled
|
|
308
308
|
if (this._autoSync) {
|
|
309
309
|
// Fire and log-on-failure; don't block the save path.
|
|
310
|
-
|
|
310
|
+
this._runAutoSyncTask(path, 'save', () => this._syncFile(path)).catch(() => undefined);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
return result;
|