@fgv/ts-web-extras 5.1.0-2 → 5.1.0-21
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 +208 -18
- package/dist/packlets/crypto-utils/browserCryptoProvider.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/httpTreeAccessors.js +72 -42
- package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -1
- package/dist/ts-web-extras.d.ts +59 -7
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +52 -5
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.js +207 -17
- package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +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/httpTreeAccessors.d.ts +6 -0
- package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -1
- package/lib/packlets/file-tree/httpTreeAccessors.js +72 -42
- package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -1
- package/package.json +27 -26
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +0 -75
- package/.rush/temp/chunked-rush-logs/ts-web-extras.test.chunks.jsonl +0 -75
- package/.rush/temp/operation/build/all.log +0 -75
- package/.rush/temp/operation/build/error.log +0 -18
- package/.rush/temp/operation/build/log-chunks.jsonl +0 -75
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/operation/test/all.log +0 -75
- package/.rush/temp/operation/test/error.log +0 -18
- package/.rush/temp/operation/test/log-chunks.jsonl +0 -75
- package/.rush/temp/operation/test/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -635
- 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 -6
- 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/@fgv/namespaces/CryptoUtils/README.md +0 -18
- package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserCryptoProvider.md +0 -203
- package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserHashProvider.md +0 -63
- package/docs/@fgv/namespaces/CryptoUtils/functions/createBrowserCryptoProvider.md +0 -18
- package/docs/@fgv/namespaces/FileTreeHelpers/README.md +0 -19
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileListMetadata.md +0 -23
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileMetadata.md +0 -23
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromDirectoryUpload.md +0 -33
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromFileList.md +0 -33
- package/docs/@fgv/namespaces/FileTreeHelpers/functions/getOriginalFile.md +0 -25
- package/docs/@fgv/namespaces/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +0 -11
- package/docs/README.md +0 -78
- package/docs/classes/DirectoryHandleStore.md +0 -116
- package/docs/classes/FileApiTreeAccessors.md +0 -286
- package/docs/classes/FileSystemAccessTreeAccessors.md +0 -557
- package/docs/classes/HttpTreeAccessors.md +0 -508
- package/docs/classes/LocalStorageTreeAccessors.md +0 -520
- package/docs/functions/exportAsJson.md +0 -23
- package/docs/functions/exportUsingFileSystemAPI.md +0 -26
- package/docs/functions/extractDirectoryPath.md +0 -23
- package/docs/functions/isDirectoryHandle.md +0 -23
- package/docs/functions/isFileHandle.md +0 -23
- package/docs/functions/isFilePath.md +0 -21
- package/docs/functions/parseContextFilter.md +0 -22
- package/docs/functions/parseQualifierDefaults.md +0 -22
- package/docs/functions/parseResourceTypes.md +0 -22
- package/docs/functions/parseUrlParameters.md +0 -15
- package/docs/functions/safeShowDirectoryPicker.md +0 -24
- package/docs/functions/safeShowOpenFilePicker.md +0 -24
- package/docs/functions/safeShowSaveFilePicker.md +0 -24
- package/docs/functions/supportsFileSystemAccess.md +0 -23
- package/docs/interfaces/FilePickerAcceptType.md +0 -16
- package/docs/interfaces/FileSystemCreateWritableOptions.md +0 -15
- package/docs/interfaces/FileSystemDirectoryHandle.md +0 -187
- package/docs/interfaces/FileSystemFileHandle.md +0 -106
- package/docs/interfaces/FileSystemGetDirectoryOptions.md +0 -15
- package/docs/interfaces/FileSystemGetFileOptions.md +0 -15
- package/docs/interfaces/FileSystemHandle.md +0 -69
- package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +0 -15
- package/docs/interfaces/FileSystemRemoveOptions.md +0 -15
- package/docs/interfaces/FileSystemWritableFileStream.md +0 -127
- package/docs/interfaces/IDirectoryHandleTreeInitializer.md +0 -17
- package/docs/interfaces/IFileHandleTreeInitializer.md +0 -16
- package/docs/interfaces/IFileListTreeInitializer.md +0 -15
- package/docs/interfaces/IFileMetadata.md +0 -19
- package/docs/interfaces/IFileSystemAccessTreeParams.md +0 -30
- package/docs/interfaces/IFsAccessApis.md +0 -57
- package/docs/interfaces/IHttpTreeParams.md +0 -32
- package/docs/interfaces/ILocalStorageTreeParams.md +0 -30
- package/docs/interfaces/IUrlConfigOptions.md +0 -27
- package/docs/interfaces/ShowDirectoryPickerOptions.md +0 -17
- package/docs/interfaces/ShowOpenFilePickerOptions.md +0 -19
- package/docs/interfaces/ShowSaveFilePickerOptions.md +0 -19
- 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 -11
- package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +0 -11
- 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 -0
- package/rush-logs/ts-web-extras.build.error.log +0 -18
- package/rush-logs/ts-web-extras.build.log +0 -75
- package/rush-logs/ts-web-extras.test.cache.log +0 -1
- package/rush-logs/ts-web-extras.test.error.log +0 -18
- package/rush-logs/ts-web-extras.test.log +0 -75
- 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/browserHashProvider.ts.html +0 -304
- package/temp/coverage/crypto/index.html +0 -116
- 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/browserHashProvider.ts.html +0 -304
- package/temp/coverage/lcov-report/crypto/index.html +0 -116
- 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-b931e4e63102f86c5bd4949f7dced44f-9d713eb41149188b4e5c0ae3d86d0a57-2ad8e16b24e391b8cdbe50b55c137169 +0 -0
- package/temp/test/jest/jest-transform-cache-b931e4e63102f86c5bd4949f7dced44f-79ef2876fae7ca75eedb2aa53dc48338/b5/package_b5f57afc9ec2c011239b1608ee5bdfa5 +0 -53
- package/temp/test/jest/perf-cache-b931e4e63102f86c5bd4949f7dced44f-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
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { Result, succeed, fail } from '@fgv/ts-utils';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Browser-compatible hash provider using the Web Crypto API.
|
|
27
|
-
* Supports common hash algorithms available in browsers.
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export class BrowserHashProvider {
|
|
31
|
-
/**
|
|
32
|
-
* Hash a string using the specified algorithm.
|
|
33
|
-
* @param data - The string to hash
|
|
34
|
-
* @param algorithm - The hash algorithm to use
|
|
35
|
-
* @returns Promise resolving to the hex-encoded hash
|
|
36
|
-
*/
|
|
37
|
-
public static async hashString(data: string, algorithm: string = 'SHA-256'): Promise<Result<string>> {
|
|
38
|
-
try {
|
|
39
|
-
/* c8 ignore next 3 - defense in depth */
|
|
40
|
-
if (!crypto.subtle) {
|
|
41
|
-
return fail('Web Crypto API not available in this environment');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const encoder = new TextEncoder();
|
|
45
|
-
const dataBuffer = encoder.encode(data);
|
|
46
|
-
const hashBuffer = await crypto.subtle.digest(algorithm, dataBuffer);
|
|
47
|
-
const hashArray = new Uint8Array(hashBuffer);
|
|
48
|
-
const hashHex = Array.from(hashArray)
|
|
49
|
-
.map((b) => b.toString(16).padStart(2, '0'))
|
|
50
|
-
.join('');
|
|
51
|
-
|
|
52
|
-
return succeed(hashHex);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
return fail(`Hash computation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Hash multiple strings concatenated with a separator.
|
|
60
|
-
* @param parts - Array of strings to concatenate and hash
|
|
61
|
-
* @param algorithm - The hash algorithm to use
|
|
62
|
-
* @param separator - Separator to use between parts (default: '|')
|
|
63
|
-
* @returns Promise resolving to the hex-encoded hash
|
|
64
|
-
*/
|
|
65
|
-
public static async hashParts(
|
|
66
|
-
parts: string[],
|
|
67
|
-
algorithm: string = 'SHA-256',
|
|
68
|
-
separator: string = '|'
|
|
69
|
-
): Promise<Result<string>> {
|
|
70
|
-
const combined = parts.join(separator);
|
|
71
|
-
return this.hashString(combined, algorithm);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Browser-compatible cryptographic utilities using the Web Crypto API.
|
|
25
|
-
* @packageDocumentation
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export * from './browserHashProvider';
|
|
29
|
-
export * from './browserCryptoProvider';
|
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* File System Access API type definitions and utilities for browser compatibility.
|
|
25
|
-
* @packageDocumentation
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
// Local type definitions for File System Access API
|
|
29
|
-
// Based on https://wicg.github.io/file-system-access/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* File System Access API methods available on Window
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
export interface IFsAccessApis {
|
|
36
|
-
showDirectoryPicker(options?: ShowDirectoryPickerOptions): Promise<FileSystemDirectoryHandle>;
|
|
37
|
-
showOpenFilePicker(options?: ShowOpenFilePickerOptions): Promise<FileSystemFileHandle[]>;
|
|
38
|
-
showSaveFilePicker(options?: ShowSaveFilePickerOptions): Promise<FileSystemFileHandle>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Window interface extended with File System Access API
|
|
43
|
-
* @public
|
|
44
|
-
*/
|
|
45
|
-
export type WindowWithFsAccess = Window & IFsAccessApis;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Base interface for file system handles
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
export interface FileSystemHandle {
|
|
52
|
-
readonly kind: 'file' | 'directory';
|
|
53
|
-
readonly name: string;
|
|
54
|
-
isSameEntry(other: FileSystemHandle): Promise<boolean>;
|
|
55
|
-
queryPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;
|
|
56
|
-
requestPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* File handle interface
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
export interface FileSystemFileHandle extends FileSystemHandle {
|
|
64
|
-
readonly kind: 'file';
|
|
65
|
-
getFile(): Promise<File>;
|
|
66
|
-
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Directory handle interface
|
|
71
|
-
* @public
|
|
72
|
-
*/
|
|
73
|
-
export interface FileSystemDirectoryHandle extends FileSystemHandle {
|
|
74
|
-
readonly kind: 'directory';
|
|
75
|
-
getDirectoryHandle(
|
|
76
|
-
name: string,
|
|
77
|
-
options?: FileSystemGetDirectoryOptions
|
|
78
|
-
): Promise<FileSystemDirectoryHandle>;
|
|
79
|
-
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>;
|
|
80
|
-
removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<void>;
|
|
81
|
-
resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
|
|
82
|
-
keys(): AsyncIterableIterator<string>;
|
|
83
|
-
values(): AsyncIterableIterator<FileSystemHandle>;
|
|
84
|
-
entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
85
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Permission descriptor for file system handles
|
|
90
|
-
* @public
|
|
91
|
-
*/
|
|
92
|
-
export interface FileSystemHandlePermissionDescriptor {
|
|
93
|
-
mode?: 'read' | 'readwrite';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Options for creating writable file streams
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
export interface FileSystemCreateWritableOptions {
|
|
101
|
-
keepExistingData?: boolean;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Options for getting directory handles
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
export interface FileSystemGetDirectoryOptions {
|
|
109
|
-
create?: boolean;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Options for getting file handles
|
|
114
|
-
* @public
|
|
115
|
-
*/
|
|
116
|
-
export interface FileSystemGetFileOptions {
|
|
117
|
-
create?: boolean;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Options for removing entries
|
|
122
|
-
* @public
|
|
123
|
-
*/
|
|
124
|
-
export interface FileSystemRemoveOptions {
|
|
125
|
-
recursive?: boolean;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Writable file stream interface
|
|
130
|
-
* @public
|
|
131
|
-
*/
|
|
132
|
-
export interface FileSystemWritableFileStream extends WritableStream {
|
|
133
|
-
write(data: BufferSource | Blob | string): Promise<void>;
|
|
134
|
-
seek(position: number): Promise<void>;
|
|
135
|
-
truncate(size: number): Promise<void>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Directory picker options
|
|
140
|
-
* @public
|
|
141
|
-
*/
|
|
142
|
-
export interface ShowDirectoryPickerOptions {
|
|
143
|
-
id?: string;
|
|
144
|
-
mode?: 'read' | 'readwrite';
|
|
145
|
-
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* File picker options
|
|
150
|
-
* @public
|
|
151
|
-
*/
|
|
152
|
-
export interface ShowOpenFilePickerOptions {
|
|
153
|
-
multiple?: boolean;
|
|
154
|
-
excludeAcceptAllOption?: boolean;
|
|
155
|
-
id?: string;
|
|
156
|
-
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
157
|
-
types?: FilePickerAcceptType[];
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Save file picker options
|
|
162
|
-
* @public
|
|
163
|
-
*/
|
|
164
|
-
export interface ShowSaveFilePickerOptions {
|
|
165
|
-
excludeAcceptAllOption?: boolean;
|
|
166
|
-
id?: string;
|
|
167
|
-
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
168
|
-
suggestedName?: string;
|
|
169
|
-
types?: FilePickerAcceptType[];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* File picker accept type
|
|
174
|
-
* @public
|
|
175
|
-
*/
|
|
176
|
-
export interface FilePickerAcceptType {
|
|
177
|
-
description?: string;
|
|
178
|
-
accept: Record<string, string | string[]>;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Well-known directory type
|
|
183
|
-
* @public
|
|
184
|
-
*/
|
|
185
|
-
export type WellKnownDirectory = 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos';
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Type guard to check if the browser supports the File System Access API
|
|
189
|
-
* @param window - The window object to check
|
|
190
|
-
* @returns True if the window supports File System Access API
|
|
191
|
-
* @public
|
|
192
|
-
*/
|
|
193
|
-
export function supportsFileSystemAccess(window: Window): window is WindowWithFsAccess {
|
|
194
|
-
return 'showOpenFilePicker' in window && 'showSaveFilePicker' in window && 'showDirectoryPicker' in window;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Type guard to check if a FileSystemHandle is a file handle
|
|
199
|
-
* @param handle - The handle to check
|
|
200
|
-
* @returns True if the handle is a FileSystemFileHandle
|
|
201
|
-
* @public
|
|
202
|
-
*/
|
|
203
|
-
export function isFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle {
|
|
204
|
-
return handle.kind === 'file';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Type guard to check if a FileSystemHandle is a directory handle
|
|
209
|
-
* @param handle - The handle to check
|
|
210
|
-
* @returns True if the handle is a FileSystemDirectoryHandle
|
|
211
|
-
* @public
|
|
212
|
-
*/
|
|
213
|
-
export function isDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle {
|
|
214
|
-
return handle.kind === 'directory';
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Safely access showOpenFilePicker with proper type checking
|
|
219
|
-
* @param window - The window object
|
|
220
|
-
* @param options - Options for the file picker
|
|
221
|
-
* @returns Promise with file handles or null if not supported
|
|
222
|
-
* @public
|
|
223
|
-
*/
|
|
224
|
-
export async function safeShowOpenFilePicker(
|
|
225
|
-
window: Window,
|
|
226
|
-
options?: ShowOpenFilePickerOptions
|
|
227
|
-
): Promise<FileSystemFileHandle[] | null> {
|
|
228
|
-
if (supportsFileSystemAccess(window)) {
|
|
229
|
-
try {
|
|
230
|
-
return await window.showOpenFilePicker(options);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
throw error;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Safely access showSaveFilePicker with proper type checking
|
|
243
|
-
* @param window - The window object
|
|
244
|
-
* @param options - Options for the file picker
|
|
245
|
-
* @returns Promise with file handle or null if not supported
|
|
246
|
-
* @public
|
|
247
|
-
*/
|
|
248
|
-
export async function safeShowSaveFilePicker(
|
|
249
|
-
window: Window,
|
|
250
|
-
options?: ShowSaveFilePickerOptions
|
|
251
|
-
): Promise<FileSystemFileHandle | null> {
|
|
252
|
-
if (supportsFileSystemAccess(window)) {
|
|
253
|
-
try {
|
|
254
|
-
return await window.showSaveFilePicker(options);
|
|
255
|
-
} catch (error) {
|
|
256
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
throw error;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Safely access showDirectoryPicker with proper type checking
|
|
267
|
-
* @param window - The window object
|
|
268
|
-
* @param options - Options for the directory picker
|
|
269
|
-
* @returns Promise with directory handle or null if not supported
|
|
270
|
-
* @public
|
|
271
|
-
*/
|
|
272
|
-
export async function safeShowDirectoryPicker(
|
|
273
|
-
window: Window,
|
|
274
|
-
options?: ShowDirectoryPickerOptions
|
|
275
|
-
): Promise<FileSystemDirectoryHandle | null> {
|
|
276
|
-
if (supportsFileSystemAccess(window)) {
|
|
277
|
-
try {
|
|
278
|
-
return await window.showDirectoryPicker(options);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Export data as JSON file using legacy blob download method.
|
|
291
|
-
* Creates a temporary download link and triggers file download.
|
|
292
|
-
* @param data - Data to export as JSON
|
|
293
|
-
* @param filename - Name for the downloaded file
|
|
294
|
-
* @public
|
|
295
|
-
*/
|
|
296
|
-
export function exportAsJson(data: unknown, filename: string): void {
|
|
297
|
-
const json = JSON.stringify(data, null, 2);
|
|
298
|
-
const blob = new Blob([json], { type: 'application/json' });
|
|
299
|
-
const url = URL.createObjectURL(blob);
|
|
300
|
-
|
|
301
|
-
const a = document.createElement('a');
|
|
302
|
-
a.href = url;
|
|
303
|
-
a.download = filename;
|
|
304
|
-
document.body.appendChild(a);
|
|
305
|
-
a.click();
|
|
306
|
-
document.body.removeChild(a);
|
|
307
|
-
URL.revokeObjectURL(url);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Export data using File System Access API with fallback to blob download.
|
|
312
|
-
* @param data - Data to export as JSON
|
|
313
|
-
* @param suggestedName - Suggested filename for the save dialog
|
|
314
|
-
* @param description - Description for file type filter (default: 'JSON files')
|
|
315
|
-
* @param window - Window object for API access (default: globalThis.window)
|
|
316
|
-
* @returns Promise resolving to true if saved via File System Access API, false if fallback used
|
|
317
|
-
* @public
|
|
318
|
-
*/
|
|
319
|
-
export async function exportUsingFileSystemAPI(
|
|
320
|
-
data: unknown,
|
|
321
|
-
suggestedName: string,
|
|
322
|
-
description: string = 'JSON files',
|
|
323
|
-
window: Window = globalThis.window
|
|
324
|
-
): Promise<boolean> {
|
|
325
|
-
if (!supportsFileSystemAccess(window)) {
|
|
326
|
-
// Fallback to blob download
|
|
327
|
-
exportAsJson(data, suggestedName);
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
const fileHandle = await safeShowSaveFilePicker(window, {
|
|
333
|
-
suggestedName,
|
|
334
|
-
types: [
|
|
335
|
-
{
|
|
336
|
-
description,
|
|
337
|
-
accept: {
|
|
338
|
-
'application/json': ['.json']
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
]
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
if (!fileHandle) {
|
|
345
|
-
// User cancelled - fallback to blob download
|
|
346
|
-
exportAsJson(data, suggestedName);
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const json = JSON.stringify(data, null, 2);
|
|
351
|
-
const writable = await fileHandle.createWritable();
|
|
352
|
-
await writable.write(json);
|
|
353
|
-
await writable.close();
|
|
354
|
-
|
|
355
|
-
return true;
|
|
356
|
-
} catch (error) {
|
|
357
|
-
// Handle errors by falling back to blob download
|
|
358
|
-
if ((error as Error).name === 'AbortError') {
|
|
359
|
-
// User cancelled - fallback
|
|
360
|
-
exportAsJson(data, suggestedName);
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
// Other errors - re-throw as they indicate a real problem
|
|
364
|
-
throw error;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2026 Erik Fortune
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
// copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
-
// SOFTWARE.
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Persistent storage for FileSystemDirectoryHandle objects using IndexedDB.
|
|
23
|
-
* Allows directory handles to survive page reloads without re-prompting the user.
|
|
24
|
-
* @packageDocumentation
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { fail, Result, succeed } from '@fgv/ts-utils';
|
|
28
|
-
import { createStore, del, get, keys, set } from 'idb-keyval';
|
|
29
|
-
import { FileSystemDirectoryHandle } from '../file-api-types';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Default IndexedDB database name for directory handles.
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
export const DEFAULT_DIRECTORY_HANDLE_DB = 'chocolate-lab-storage';
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Default IndexedDB store name for directory handles.
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
export const DEFAULT_DIRECTORY_HANDLE_STORE = 'directory-handles';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Manages persistence of {@link FileSystemDirectoryHandle} objects in IndexedDB.
|
|
45
|
-
* Keyed by a label (typically the directory name).
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
export class DirectoryHandleStore {
|
|
49
|
-
private readonly _store: ReturnType<typeof createStore>;
|
|
50
|
-
|
|
51
|
-
public constructor(
|
|
52
|
-
dbName: string = DEFAULT_DIRECTORY_HANDLE_DB,
|
|
53
|
-
storeName: string = DEFAULT_DIRECTORY_HANDLE_STORE
|
|
54
|
-
) {
|
|
55
|
-
this._store = createStore(dbName, storeName);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Saves a directory handle to IndexedDB under the given label.
|
|
60
|
-
* @param label - Key to store the handle under (typically dirHandle.name)
|
|
61
|
-
* @param handle - The FileSystemDirectoryHandle to persist
|
|
62
|
-
* @returns Success or Failure
|
|
63
|
-
*/
|
|
64
|
-
public async save(label: string, handle: FileSystemDirectoryHandle): Promise<Result<void>> {
|
|
65
|
-
try {
|
|
66
|
-
await set(label, handle, this._store);
|
|
67
|
-
return succeed(undefined);
|
|
68
|
-
} catch (e) {
|
|
69
|
-
return fail(`DirectoryHandleStore.save "${label}": ${String(e)}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Retrieves a directory handle by label.
|
|
75
|
-
* @param label - Key to look up
|
|
76
|
-
* @returns Success with handle (or undefined if not found), or Failure on error
|
|
77
|
-
*/
|
|
78
|
-
public async load(label: string): Promise<Result<FileSystemDirectoryHandle | undefined>> {
|
|
79
|
-
try {
|
|
80
|
-
const handle = await get<FileSystemDirectoryHandle>(label, this._store);
|
|
81
|
-
return succeed(handle);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
return fail(`DirectoryHandleStore.load "${label}": ${String(e)}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Removes a directory handle from IndexedDB.
|
|
89
|
-
* @param label - Key to remove
|
|
90
|
-
* @returns Success or Failure
|
|
91
|
-
*/
|
|
92
|
-
public async remove(label: string): Promise<Result<void>> {
|
|
93
|
-
try {
|
|
94
|
-
await del(label, this._store);
|
|
95
|
-
return succeed(undefined);
|
|
96
|
-
} catch (e) {
|
|
97
|
-
return fail(`DirectoryHandleStore.remove "${label}": ${String(e)}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Returns all stored labels (keys).
|
|
103
|
-
* @returns Success with array of labels, or Failure
|
|
104
|
-
*/
|
|
105
|
-
public async getAllLabels(): Promise<Result<string[]>> {
|
|
106
|
-
try {
|
|
107
|
-
const allKeys = await keys<string>(this._store);
|
|
108
|
-
return succeed(allKeys);
|
|
109
|
-
} catch (e) {
|
|
110
|
-
return fail(`DirectoryHandleStore.getAllLabels: ${String(e)}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Returns all stored handles as label/handle pairs.
|
|
116
|
-
* @returns Success with array of entries, or Failure
|
|
117
|
-
*/
|
|
118
|
-
public async getAll(): Promise<Result<Array<{ label: string; handle: FileSystemDirectoryHandle }>>> {
|
|
119
|
-
const labelsResult = await this.getAllLabels();
|
|
120
|
-
if (labelsResult.isFailure()) {
|
|
121
|
-
return fail(labelsResult.message);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const entries: Array<{ label: string; handle: FileSystemDirectoryHandle }> = [];
|
|
125
|
-
for (const label of labelsResult.value) {
|
|
126
|
-
const handleResult = await this.load(label);
|
|
127
|
-
if (handleResult.isFailure()) {
|
|
128
|
-
return fail(handleResult.message);
|
|
129
|
-
}
|
|
130
|
-
if (handleResult.value !== undefined) {
|
|
131
|
-
entries.push({ label, handle: handleResult.value });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return succeed(entries);
|
|
135
|
-
}
|
|
136
|
-
}
|