@fgv/ts-web-extras 5.0.2 → 5.1.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/81e0881271ff236956b2f52e8ca99da6574c6e1e.tar.log +223 -0
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +35 -25
- package/.rush/temp/operation/build/all.log +35 -25
- package/.rush/temp/operation/build/log-chunks.jsonl +35 -25
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/shrinkwrap-deps.json +175 -163
- package/config/jest.config.json +4 -1
- package/config/typedoc.json +6 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/packlets/crypto-utils/browserCryptoProvider.js +254 -0
- package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -0
- package/dist/packlets/crypto-utils/browserHashProvider.js.map +1 -0
- package/dist/packlets/{crypto → crypto-utils}/index.js +1 -0
- package/dist/packlets/crypto-utils/index.js.map +1 -0
- package/dist/packlets/file-api-types/index.js +27 -3
- package/dist/packlets/file-api-types/index.js.map +1 -1
- package/dist/packlets/file-tree/directoryHandleStore.js +124 -0
- package/dist/packlets/file-tree/directoryHandleStore.js.map +1 -0
- package/dist/packlets/file-tree/fileApiTreeAccessors.js +76 -0
- package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
- package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +345 -0
- package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -0
- package/dist/packlets/file-tree/index.js +3 -0
- package/dist/packlets/file-tree/index.js.map +1 -1
- package/dist/packlets/file-tree/localStorageTreeAccessors.js +308 -0
- package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -0
- package/dist/test/mocks/idb-keyval.js +6 -0
- package/dist/test/mocks/idb-keyval.js.map +1 -0
- package/dist/test/unit/browserHashProvider.test.js +1 -1
- package/dist/test/unit/browserHashProvider.test.js.map +1 -1
- package/dist/test/unit/directoryHandleStore.test.js +190 -0
- package/dist/test/unit/directoryHandleStore.test.js.map +1 -0
- package/dist/test/unit/fileApiTypes.test.js +30 -0
- package/dist/test/unit/fileApiTypes.test.js.map +1 -1
- package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +517 -0
- package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -0
- package/dist/test/unit/localStorageTreeAccessors.test.js +595 -0
- package/dist/test/unit/localStorageTreeAccessors.test.js.map +1 -0
- package/dist/test/utils/fileSystemAccessMocks.js +271 -0
- package/dist/test/utils/fileSystemAccessMocks.js.map +1 -0
- package/dist/ts-web-extras.d.ts +460 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider._constructor_.md +50 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.decrypt.md +104 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.derivekey.md +88 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.encrypt.md +72 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.frombase64.md +56 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generatekey.md +19 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.generaterandombytes.md +56 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.md +169 -0
- package/docs/ts-web-extras.cryptoutils.browsercryptoprovider.tobase64.md +56 -0
- package/docs/{ts-web-extras.browserhashprovider.hashparts.md → ts-web-extras.cryptoutils.browserhashprovider.hashparts.md} +2 -2
- package/docs/{ts-web-extras.browserhashprovider.hashstring.md → ts-web-extras.cryptoutils.browserhashprovider.hashstring.md} +2 -2
- package/docs/{ts-web-extras.browserhashprovider.md → ts-web-extras.cryptoutils.browserhashprovider.md} +4 -4
- package/docs/ts-web-extras.cryptoutils.createbrowsercryptoprovider.md +19 -0
- package/docs/ts-web-extras.cryptoutils.md +71 -0
- package/docs/ts-web-extras.fileapitreeaccessors.createfromlocalstorage.md +74 -0
- package/docs/ts-web-extras.fileapitreeaccessors.createpersistent.md +76 -0
- package/docs/ts-web-extras.fileapitreeaccessors.md +32 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors._constructor_.md +114 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.fileismutable.md +52 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.fromdirectoryhandle.md +72 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.getdirtypaths.md +17 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.isdirty.md +17 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.md +159 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.savefilecontents.md +66 -0
- package/docs/ts-web-extras.filesystemaccesstreeaccessors.synctodisk.md +17 -0
- package/docs/ts-web-extras.ifilesystemaccesstreeparams.autosync.md +13 -0
- package/docs/ts-web-extras.ifilesystemaccesstreeparams.md +78 -0
- package/docs/ts-web-extras.ifilesystemaccesstreeparams.requirewritepermission.md +13 -0
- package/docs/ts-web-extras.ilocalstoragetreeparams.autosync.md +13 -0
- package/docs/ts-web-extras.ilocalstoragetreeparams.md +97 -0
- package/docs/ts-web-extras.ilocalstoragetreeparams.pathtokeymap.md +13 -0
- package/docs/ts-web-extras.ilocalstoragetreeparams.storage.md +13 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.fileismutable.md +56 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.fromstorage.md +56 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.getdirtypaths.md +19 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.isdirty.md +19 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.md +131 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.savefilecontents.md +72 -0
- package/docs/ts-web-extras.localstoragetreeaccessors.synctodisk.md +19 -0
- package/docs/ts-web-extras.md +50 -4
- package/etc/ts-web-extras.api.md +91 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -2
- package/lib/index.js.map +1 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +77 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.js +259 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -0
- package/lib/packlets/crypto-utils/browserHashProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/browserHashProvider.js.map +1 -0
- package/lib/packlets/{crypto → crypto-utils}/index.d.ts +1 -0
- package/lib/packlets/crypto-utils/index.d.ts.map +1 -0
- package/lib/packlets/{crypto → crypto-utils}/index.js +1 -0
- package/lib/packlets/crypto-utils/index.js.map +1 -0
- package/lib/packlets/file-api-types/index.d.ts.map +1 -1
- package/lib/packlets/file-api-types/index.js +27 -3
- package/lib/packlets/file-api-types/index.js.map +1 -1
- package/lib/packlets/file-tree/directoryHandleStore.d.ts +59 -0
- package/lib/packlets/file-tree/directoryHandleStore.d.ts.map +1 -0
- package/lib/packlets/file-tree/directoryHandleStore.js +128 -0
- package/lib/packlets/file-tree/directoryHandleStore.js.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +57 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
- package/lib/packlets/file-tree/fileApiTreeAccessors.js +76 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts +136 -0
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +349 -0
- package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts +3 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -1
- package/lib/packlets/file-tree/index.js +3 -0
- package/lib/packlets/file-tree/index.js.map +1 -1
- package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts +129 -0
- package/lib/packlets/file-tree/localStorageTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/localStorageTreeAccessors.js +312 -0
- package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -0
- package/lib/test/mocks/idb-keyval.d.ts +6 -0
- package/lib/test/mocks/idb-keyval.d.ts.map +1 -0
- package/lib/test/mocks/idb-keyval.js +9 -0
- package/lib/test/mocks/idb-keyval.js.map +1 -0
- package/lib/test/unit/browserHashProvider.test.js +21 -21
- package/lib/test/unit/browserHashProvider.test.js.map +1 -1
- package/lib/test/unit/directoryHandleStore.test.d.ts +2 -0
- package/lib/test/unit/directoryHandleStore.test.d.ts.map +1 -0
- package/lib/test/unit/directoryHandleStore.test.js +192 -0
- package/lib/test/unit/directoryHandleStore.test.js.map +1 -0
- package/lib/test/unit/fileApiTypes.test.js +30 -0
- package/lib/test/unit/fileApiTypes.test.js.map +1 -1
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +519 -0
- package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +1 -0
- package/lib/test/unit/localStorageTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/localStorageTreeAccessors.test.js +597 -0
- package/lib/test/unit/localStorageTreeAccessors.test.js.map +1 -0
- package/lib/test/utils/fileSystemAccessMocks.d.ts +53 -0
- package/lib/test/utils/fileSystemAccessMocks.d.ts.map +1 -0
- package/lib/test/utils/fileSystemAccessMocks.js +277 -0
- package/lib/test/utils/fileSystemAccessMocks.js.map +1 -0
- package/package.json +27 -20
- package/rush-logs/ts-web-extras.build.cache.log +3 -1
- package/rush-logs/ts-web-extras.build.log +35 -25
- package/src/index.ts +2 -2
- package/src/packlets/crypto-utils/browserCryptoProvider.ts +311 -0
- package/src/packlets/{crypto → crypto-utils}/index.ts +1 -0
- package/src/packlets/file-api-types/index.ts +24 -3
- package/src/packlets/file-tree/directoryHandleStore.ts +136 -0
- package/src/packlets/file-tree/fileApiTreeAccessors.ts +90 -0
- package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +427 -0
- package/src/packlets/file-tree/index.ts +3 -0
- package/src/packlets/file-tree/localStorageTreeAccessors.ts +377 -0
- package/src/test/mocks/idb-keyval.ts +5 -0
- package/src/test/unit/browserHashProvider.test.ts +1 -1
- package/src/test/unit/directoryHandleStore.test.ts +251 -0
- package/src/test/unit/fileApiTypes.test.ts +36 -0
- package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +732 -0
- package/src/test/unit/localStorageTreeAccessors.test.ts +746 -0
- package/src/test/utils/fileSystemAccessMocks.ts +353 -0
- package/temp/build/typescript/ts_8nwakTlr.json +1 -0
- package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +1018 -0
- package/temp/coverage/{crypto → crypto-utils}/browserHashProvider.ts.html +3 -3
- package/temp/coverage/{lcov-report/crypto → crypto-utils}/index.html +21 -6
- package/temp/coverage/file-tree/directoryHandleStore.ts.html +493 -0
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +276 -6
- package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +1366 -0
- package/temp/coverage/file-tree/index.html +55 -10
- package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +1216 -0
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
- package/temp/coverage/helpers/index.html +1 -1
- package/temp/coverage/index.html +15 -15
- package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +1018 -0
- package/temp/coverage/lcov-report/{crypto → crypto-utils}/browserHashProvider.ts.html +3 -3
- package/temp/coverage/{crypto → lcov-report/crypto-utils}/index.html +21 -6
- package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +493 -0
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +276 -6
- package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +1366 -0
- package/temp/coverage/lcov-report/file-tree/index.html +55 -10
- package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +1216 -0
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
- package/temp/coverage/lcov-report/helpers/index.html +1 -1
- package/temp/coverage/lcov-report/index.html +15 -15
- package/temp/coverage/lcov-report/url-utils/index.html +1 -1
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
- package/temp/coverage/lcov.info +2128 -451
- package/temp/coverage/url-utils/index.html +1 -1
- package/temp/coverage/url-utils/urlParams.ts.html +1 -1
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -1
- package/temp/ts-web-extras.api.json +3236 -385
- package/temp/ts-web-extras.api.md +91 -1
- package/dist/packlets/crypto/browserHashProvider.js.map +0 -1
- package/dist/packlets/crypto/index.js.map +0 -1
- package/lib/packlets/crypto/browserHashProvider.d.ts.map +0 -1
- package/lib/packlets/crypto/browserHashProvider.js.map +0 -1
- package/lib/packlets/crypto/index.d.ts.map +0 -1
- package/lib/packlets/crypto/index.js.map +0 -1
- package/temp/build/typescript/ts_vnCx6LlY.json +0 -1
- /package/dist/packlets/{crypto → crypto-utils}/browserHashProvider.js +0 -0
- /package/lib/packlets/{crypto → crypto-utils}/browserHashProvider.d.ts +0 -0
- /package/lib/packlets/{crypto → crypto-utils}/browserHashProvider.js +0 -0
- /package/src/packlets/{crypto → crypto-utils}/browserHashProvider.ts +0 -0
- /package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/{0e/package_0eb6535f5987849d93ea51ef33a14cf6 → 8d/package_8dcbedef69e4299f0f51fcda8f4f1c8e} +0 -0
|
@@ -2,41 +2,51 @@ Invoking: heft test --clean
|
|
|
2
2
|
---- build started ----
|
|
3
3
|
[build:typescript] The TypeScript compiler version 5.9.3 is newer than the latest version that was tested with Heft (5.8); it may not work correctly.
|
|
4
4
|
[build:typescript] Using TypeScript version 5.9.3
|
|
5
|
-
[build:api-extractor] Using API Extractor version 7.
|
|
5
|
+
[build:api-extractor] Using API Extractor version 7.57.6
|
|
6
6
|
[build:api-extractor] Analysis will use the bundled TypeScript version 5.8.2
|
|
7
7
|
[build:api-extractor] *** The target project appears to use TypeScript 5.9.3 which is newer than the bundled compiler engine; consider upgrading API Extractor.
|
|
8
|
-
---- build finished (
|
|
8
|
+
---- build finished (18.627s) ----
|
|
9
9
|
---- test started ----
|
|
10
10
|
[test:jest] Using Jest version 29.5.0
|
|
11
11
|
[test:jest]
|
|
12
|
-
[test:jest] Run start.
|
|
12
|
+
[test:jest] Run start. 8 test suites
|
|
13
13
|
[test:jest] START lib/test/unit/fileApiTreeAccessors.test.js
|
|
14
14
|
[test:jest] START lib/test/unit/fileTreeHelpers.test.js
|
|
15
|
+
[test:jest] START lib/test/unit/fileSystemAccessTreeAccessors.test.js
|
|
16
|
+
[test:jest] START lib/test/unit/localStorageTreeAccessors.test.js
|
|
17
|
+
[test:jest] PASS lib/test/unit/fileApiTreeAccessors.test.js (duration: 2.344s, 63 passed, 0 failed)
|
|
15
18
|
[test:jest] START lib/test/unit/fileApiTypes.test.js
|
|
19
|
+
[test:jest] PASS lib/test/unit/fileTreeHelpers.test.js (duration: 2.029s, 35 passed, 0 failed)
|
|
16
20
|
[test:jest] START lib/test/unit/urlParams.test.js
|
|
17
|
-
[test:jest] PASS lib/test/unit/
|
|
21
|
+
[test:jest] PASS lib/test/unit/fileSystemAccessTreeAccessors.test.js (duration: 2.580s, 38 passed, 0 failed)
|
|
22
|
+
[test:jest] START lib/test/unit/directoryHandleStore.test.js
|
|
23
|
+
[test:jest] PASS lib/test/unit/localStorageTreeAccessors.test.js (duration: 1.053s, 33 passed, 0 failed)
|
|
18
24
|
[test:jest] START lib/test/unit/browserHashProvider.test.js
|
|
19
|
-
[test:jest] PASS lib/test/unit/fileApiTypes.test.js (duration:
|
|
20
|
-
[test:jest] PASS lib/test/unit/
|
|
21
|
-
[test:jest] PASS lib/test/unit/
|
|
22
|
-
[test:jest] PASS lib/test/unit/browserHashProvider.test.js (duration: 1.
|
|
25
|
+
[test:jest] PASS lib/test/unit/fileApiTypes.test.js (duration: 1.302s, 36 passed, 0 failed)
|
|
26
|
+
[test:jest] PASS lib/test/unit/urlParams.test.js (duration: 1.269s, 60 passed, 0 failed)
|
|
27
|
+
[test:jest] PASS lib/test/unit/directoryHandleStore.test.js (duration: 1.234s, 19 passed, 0 failed)
|
|
28
|
+
[test:jest] PASS lib/test/unit/browserHashProvider.test.js (duration: 1.305s, 15 passed, 0 failed)
|
|
23
29
|
[test:jest]
|
|
24
30
|
[test:jest] Tests finished:
|
|
25
|
-
[test:jest] Successes:
|
|
31
|
+
[test:jest] Successes: 299
|
|
26
32
|
[test:jest] Failures: 0
|
|
27
|
-
[test:jest] Total:
|
|
28
|
-
|
|
29
|
-
File
|
|
30
|
-
|
|
31
|
-
All files
|
|
32
|
-
crypto
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
[test:jest] Total: 300
|
|
34
|
+
-----------------------------------|---------|----------|---------|---------|------------------------------------
|
|
35
|
+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
36
|
+
-----------------------------------|---------|----------|---------|---------|------------------------------------
|
|
37
|
+
All files | 100 | 95.68 | 100 | 100 |
|
|
38
|
+
crypto-utils | 100 | 100 | 100 | 100 |
|
|
39
|
+
browserCryptoProvider.ts | 100 | 100 | 100 | 100 |
|
|
40
|
+
browserHashProvider.ts | 100 | 100 | 100 | 100 |
|
|
41
|
+
file-tree | 100 | 94.9 | 100 | 100 |
|
|
42
|
+
directoryHandleStore.ts | 100 | 100 | 100 | 100 |
|
|
43
|
+
fileApiTreeAccessors.ts | 100 | 100 | 100 | 100 |
|
|
44
|
+
fileSystemAccessTreeAccessors.ts | 100 | 93.06 | 100 | 100 | 90,152,160,169,176
|
|
45
|
+
localStorageTreeAccessors.ts | 100 | 88.6 | 100 | 100 | 92,107,163-164,196-197,210,245-249
|
|
46
|
+
helpers | 100 | 100 | 100 | 100 |
|
|
47
|
+
fileTreeHelpers.ts | 100 | 100 | 100 | 100 |
|
|
48
|
+
url-utils | 100 | 100 | 100 | 100 |
|
|
49
|
+
urlParams.ts | 100 | 100 | 100 | 100 |
|
|
50
|
+
-----------------------------------|---------|----------|---------|---------|------------------------------------
|
|
51
|
+
---- test finished (7.440s) ----
|
|
52
|
+
-------------------- Finished (26.073s) --------------------
|
package/src/index.ts
CHANGED
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
* @packageDocumentation
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
export
|
|
34
|
+
import * as CryptoUtils from './packlets/crypto-utils';
|
|
35
|
+
export { CryptoUtils };
|
|
36
36
|
|
|
37
37
|
// Export file tree functionality
|
|
38
38
|
export * from './packlets/file-tree';
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Copyright (c) 2024 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
|
+
/* c8 ignore start - Browser-only implementation cannot be tested in Node.js environment */
|
|
22
|
+
import { captureResult, Failure, Result, Success } from '@fgv/ts-utils';
|
|
23
|
+
import { CryptoUtils } from '@fgv/ts-extras';
|
|
24
|
+
|
|
25
|
+
type ICryptoProvider = CryptoUtils.ICryptoProvider;
|
|
26
|
+
type IEncryptionResult = CryptoUtils.IEncryptionResult;
|
|
27
|
+
const CryptoConstants = CryptoUtils.Constants;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Extracts an `ArrayBuffer` from a Uint8Array, handling the potential SharedArrayBuffer case.
|
|
31
|
+
* @param arr - The Uint8Array to extract from
|
|
32
|
+
* @returns An `ArrayBuffer` containing a copy of the data.
|
|
33
|
+
*/
|
|
34
|
+
function toArrayBuffer(arr: Uint8Array): ArrayBuffer {
|
|
35
|
+
// Create a new ArrayBuffer and copy the data - this handles both ArrayBuffer and SharedArrayBuffer
|
|
36
|
+
const buffer = new ArrayBuffer(arr.byteLength);
|
|
37
|
+
new Uint8Array(buffer).set(arr);
|
|
38
|
+
return buffer;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Browser implementation of `ICryptoProvider` using the Web Crypto API.
|
|
43
|
+
* Uses AES-256-GCM for authenticated encryption.
|
|
44
|
+
*
|
|
45
|
+
* Note: This provider requires a browser environment with Web Crypto API support.
|
|
46
|
+
* In Node.js 15+, Web Crypto is available via globalThis.crypto or require('crypto').webcrypto.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export class BrowserCryptoProvider implements ICryptoProvider {
|
|
51
|
+
private readonly _crypto: Crypto;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider}.
|
|
55
|
+
* @param cryptoApi - Optional Crypto instance (defaults to globalThis.crypto)
|
|
56
|
+
*/
|
|
57
|
+
public constructor(cryptoApi?: Crypto) {
|
|
58
|
+
if (cryptoApi) {
|
|
59
|
+
this._crypto = cryptoApi;
|
|
60
|
+
} else if (typeof globalThis !== 'undefined' && globalThis.crypto) {
|
|
61
|
+
this._crypto = globalThis.crypto;
|
|
62
|
+
} else if (typeof window !== 'undefined' && window.crypto) {
|
|
63
|
+
this._crypto = window.crypto;
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error('Web Crypto API not available');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Encrypts plaintext using AES-256-GCM.
|
|
71
|
+
* @param plaintext - UTF-8 string to encrypt
|
|
72
|
+
* @param key - 32-byte encryption key
|
|
73
|
+
* @returns `Success` with encryption result, or `Failure` with an error.
|
|
74
|
+
*/
|
|
75
|
+
public async encrypt(plaintext: string, key: Uint8Array): Promise<Result<IEncryptionResult>> {
|
|
76
|
+
if (key.length !== CryptoConstants.AES_256_KEY_SIZE) {
|
|
77
|
+
return Failure.with(`Key must be ${CryptoConstants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
// Generate random IV
|
|
82
|
+
const iv = this._crypto.getRandomValues(new Uint8Array(CryptoConstants.GCM_IV_SIZE));
|
|
83
|
+
|
|
84
|
+
// Import the key
|
|
85
|
+
const cryptoKey = await this._crypto.subtle.importKey(
|
|
86
|
+
'raw',
|
|
87
|
+
toArrayBuffer(key),
|
|
88
|
+
{ name: 'AES-GCM' },
|
|
89
|
+
false,
|
|
90
|
+
['encrypt']
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Encode plaintext to bytes
|
|
94
|
+
const encoder = new TextEncoder();
|
|
95
|
+
const plaintextBytes = encoder.encode(plaintext);
|
|
96
|
+
|
|
97
|
+
// Encrypt (Web Crypto appends auth tag to ciphertext)
|
|
98
|
+
const encryptedWithTag = await this._crypto.subtle.encrypt(
|
|
99
|
+
{
|
|
100
|
+
name: 'AES-GCM',
|
|
101
|
+
iv: iv,
|
|
102
|
+
tagLength: CryptoConstants.GCM_AUTH_TAG_SIZE * 8 // bits
|
|
103
|
+
},
|
|
104
|
+
cryptoKey,
|
|
105
|
+
plaintextBytes
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// Split ciphertext and auth tag (auth tag is last 16 bytes)
|
|
109
|
+
const encryptedArray = new Uint8Array(encryptedWithTag);
|
|
110
|
+
const encryptedData = encryptedArray.slice(
|
|
111
|
+
0,
|
|
112
|
+
encryptedArray.length - CryptoConstants.GCM_AUTH_TAG_SIZE
|
|
113
|
+
);
|
|
114
|
+
const authTag = encryptedArray.slice(encryptedArray.length - CryptoConstants.GCM_AUTH_TAG_SIZE);
|
|
115
|
+
return Success.with({
|
|
116
|
+
iv,
|
|
117
|
+
authTag,
|
|
118
|
+
encryptedData
|
|
119
|
+
});
|
|
120
|
+
} catch (e) {
|
|
121
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
122
|
+
return Failure.with(`Encryption failed: ${message}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Decrypts ciphertext using AES-256-GCM.
|
|
128
|
+
* @param encryptedData - Encrypted bytes
|
|
129
|
+
* @param key - 32-byte decryption key
|
|
130
|
+
* @param iv - Initialization vector (12 bytes)
|
|
131
|
+
* @param authTag - GCM authentication tag (16 bytes)
|
|
132
|
+
* @returns `Success` with decrypted UTF-8 string, or `Failure` with an error.
|
|
133
|
+
*/
|
|
134
|
+
public async decrypt(
|
|
135
|
+
encryptedData: Uint8Array,
|
|
136
|
+
key: Uint8Array,
|
|
137
|
+
iv: Uint8Array,
|
|
138
|
+
authTag: Uint8Array
|
|
139
|
+
): Promise<Result<string>> {
|
|
140
|
+
if (key.length !== CryptoConstants.AES_256_KEY_SIZE) {
|
|
141
|
+
return Failure.with(`Key must be ${CryptoConstants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
|
|
142
|
+
}
|
|
143
|
+
if (iv.length !== CryptoConstants.GCM_IV_SIZE) {
|
|
144
|
+
return Failure.with(`IV must be ${CryptoConstants.GCM_IV_SIZE} bytes, got ${iv.length}`);
|
|
145
|
+
}
|
|
146
|
+
if (authTag.length !== CryptoConstants.GCM_AUTH_TAG_SIZE) {
|
|
147
|
+
return Failure.with(
|
|
148
|
+
`Auth tag must be ${CryptoConstants.GCM_AUTH_TAG_SIZE} bytes, got ${authTag.length}`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
// Import the key
|
|
154
|
+
const cryptoKey = await this._crypto.subtle.importKey(
|
|
155
|
+
'raw',
|
|
156
|
+
toArrayBuffer(key),
|
|
157
|
+
{ name: 'AES-GCM' },
|
|
158
|
+
false,
|
|
159
|
+
['decrypt']
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// Web Crypto expects ciphertext + auth tag concatenated
|
|
163
|
+
const encryptedWithTag = new Uint8Array(encryptedData.length + authTag.length);
|
|
164
|
+
encryptedWithTag.set(encryptedData);
|
|
165
|
+
encryptedWithTag.set(authTag, encryptedData.length);
|
|
166
|
+
|
|
167
|
+
// Decrypt
|
|
168
|
+
const decrypted = await this._crypto.subtle.decrypt(
|
|
169
|
+
{
|
|
170
|
+
name: 'AES-GCM',
|
|
171
|
+
iv: toArrayBuffer(iv),
|
|
172
|
+
tagLength: CryptoConstants.GCM_AUTH_TAG_SIZE * 8 // bits
|
|
173
|
+
},
|
|
174
|
+
cryptoKey,
|
|
175
|
+
encryptedWithTag
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Decode to string
|
|
179
|
+
const decoder = new TextDecoder();
|
|
180
|
+
return Success.with(decoder.decode(decrypted));
|
|
181
|
+
} catch (e) {
|
|
182
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
183
|
+
return Failure.with(`Decryption failed: ${message}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Generates a random 32-byte key suitable for AES-256.
|
|
189
|
+
* @returns Success with generated key, or Failure with error
|
|
190
|
+
*/
|
|
191
|
+
public async generateKey(): Promise<Result<Uint8Array>> {
|
|
192
|
+
try {
|
|
193
|
+
return Success.with(this._crypto.getRandomValues(new Uint8Array(CryptoConstants.AES_256_KEY_SIZE)));
|
|
194
|
+
} catch (e) {
|
|
195
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
196
|
+
return Failure.with(`Key generation failed: ${message}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Derives a key from a password using PBKDF2.
|
|
202
|
+
* @param password - Password string
|
|
203
|
+
* @param salt - Salt bytes (should be at least 16 bytes)
|
|
204
|
+
* @param iterations - Number of iterations (recommend 100000+)
|
|
205
|
+
* @returns Success with derived 32-byte key, or Failure with error
|
|
206
|
+
*/
|
|
207
|
+
public async deriveKey(
|
|
208
|
+
password: string,
|
|
209
|
+
salt: Uint8Array,
|
|
210
|
+
iterations: number
|
|
211
|
+
): Promise<Result<Uint8Array>> {
|
|
212
|
+
if (iterations < 1) {
|
|
213
|
+
return Failure.with('Iterations must be at least 1');
|
|
214
|
+
}
|
|
215
|
+
if (salt.length < 8) {
|
|
216
|
+
return Failure.with('Salt should be at least 8 bytes');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
// Encode password
|
|
221
|
+
const encoder = new TextEncoder();
|
|
222
|
+
const passwordBytes = encoder.encode(password);
|
|
223
|
+
|
|
224
|
+
// Import password as key material
|
|
225
|
+
const keyMaterial = await this._crypto.subtle.importKey('raw', passwordBytes, 'PBKDF2', false, [
|
|
226
|
+
'deriveBits'
|
|
227
|
+
]);
|
|
228
|
+
|
|
229
|
+
// Derive key bits
|
|
230
|
+
const derivedBits = await this._crypto.subtle.deriveBits(
|
|
231
|
+
{
|
|
232
|
+
name: 'PBKDF2',
|
|
233
|
+
salt: toArrayBuffer(salt),
|
|
234
|
+
iterations: iterations,
|
|
235
|
+
hash: 'SHA-256'
|
|
236
|
+
},
|
|
237
|
+
keyMaterial,
|
|
238
|
+
CryptoConstants.AES_256_KEY_SIZE * 8 // bits
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
return Success.with(new Uint8Array(derivedBits));
|
|
242
|
+
} catch (e) {
|
|
243
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
244
|
+
return Failure.with(`Key derivation failed: ${message}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ============================================================================
|
|
249
|
+
// Platform Utility Methods
|
|
250
|
+
// ============================================================================
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Generates cryptographically secure random bytes.
|
|
254
|
+
* @param length - Number of bytes to generate
|
|
255
|
+
* @returns Success with random bytes, or Failure with error
|
|
256
|
+
*/
|
|
257
|
+
public generateRandomBytes(length: number): Result<Uint8Array> {
|
|
258
|
+
if (length < 1) {
|
|
259
|
+
return Failure.with('Length must be at least 1');
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
return Success.with(this._crypto.getRandomValues(new Uint8Array(length)));
|
|
263
|
+
} catch (e) {
|
|
264
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
265
|
+
return Failure.with(`Random bytes generation failed: ${message}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Encodes binary data to base64 string.
|
|
271
|
+
* @param data - Binary data to encode
|
|
272
|
+
* @returns Base64-encoded string
|
|
273
|
+
*/
|
|
274
|
+
public toBase64(data: Uint8Array): string {
|
|
275
|
+
// Convert Uint8Array to binary string, then to base64
|
|
276
|
+
let binary = '';
|
|
277
|
+
for (let i = 0; i < data.length; i++) {
|
|
278
|
+
binary += String.fromCharCode(data[i]);
|
|
279
|
+
}
|
|
280
|
+
return btoa(binary);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Decodes base64 string to binary data.
|
|
285
|
+
* @param base64 - Base64-encoded string
|
|
286
|
+
* @returns Success with decoded bytes, or Failure if invalid base64
|
|
287
|
+
*/
|
|
288
|
+
public fromBase64(base64: string): Result<Uint8Array> {
|
|
289
|
+
try {
|
|
290
|
+
const binary = atob(base64);
|
|
291
|
+
const bytes = new Uint8Array(binary.length);
|
|
292
|
+
for (let i = 0; i < binary.length; i++) {
|
|
293
|
+
bytes[i] = binary.charCodeAt(i);
|
|
294
|
+
}
|
|
295
|
+
return Success.with(bytes);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
return Failure.with('Invalid base64 string');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Creates a {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider} if Web
|
|
304
|
+
* Crypto API is available.
|
|
305
|
+
* @returns `Success` with provider, or `Failure` if not available
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
export function createBrowserCryptoProvider(): Result<BrowserCryptoProvider> {
|
|
309
|
+
return captureResult(() => new BrowserCryptoProvider());
|
|
310
|
+
}
|
|
311
|
+
/* c8 ignore stop */
|
|
@@ -226,7 +226,14 @@ export async function safeShowOpenFilePicker(
|
|
|
226
226
|
options?: ShowOpenFilePickerOptions
|
|
227
227
|
): Promise<FileSystemFileHandle[] | null> {
|
|
228
228
|
if (supportsFileSystemAccess(window)) {
|
|
229
|
-
|
|
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
|
+
}
|
|
230
237
|
}
|
|
231
238
|
return null;
|
|
232
239
|
}
|
|
@@ -243,7 +250,14 @@ export async function safeShowSaveFilePicker(
|
|
|
243
250
|
options?: ShowSaveFilePickerOptions
|
|
244
251
|
): Promise<FileSystemFileHandle | null> {
|
|
245
252
|
if (supportsFileSystemAccess(window)) {
|
|
246
|
-
|
|
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
|
+
}
|
|
247
261
|
}
|
|
248
262
|
return null;
|
|
249
263
|
}
|
|
@@ -260,7 +274,14 @@ export async function safeShowDirectoryPicker(
|
|
|
260
274
|
options?: ShowDirectoryPickerOptions
|
|
261
275
|
): Promise<FileSystemDirectoryHandle | null> {
|
|
262
276
|
if (supportsFileSystemAccess(window)) {
|
|
263
|
-
|
|
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
|
+
}
|
|
264
285
|
}
|
|
265
286
|
return null;
|
|
266
287
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
}
|