@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,271 +0,0 @@
|
|
|
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
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
23
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
24
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
25
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
26
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
27
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
28
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
29
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
30
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
31
|
-
function fulfill(value) { resume("next", value); }
|
|
32
|
-
function reject(value) { resume("throw", value); }
|
|
33
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
34
|
-
};
|
|
35
|
-
import { createMockFile } from './testHelpers';
|
|
36
|
-
/**
|
|
37
|
-
* Mock implementation of FileSystemWritableFileStream
|
|
38
|
-
*/
|
|
39
|
-
export class MockFileSystemWritableFileStream {
|
|
40
|
-
constructor(onWrite, failOnWrite = false) {
|
|
41
|
-
this._content = '';
|
|
42
|
-
this._closed = false;
|
|
43
|
-
this._onWrite = onWrite;
|
|
44
|
-
this._failOnWrite = failOnWrite;
|
|
45
|
-
}
|
|
46
|
-
get locked() {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
async write(data) {
|
|
50
|
-
if (this._closed) {
|
|
51
|
-
throw new Error('Stream is closed');
|
|
52
|
-
}
|
|
53
|
-
if (this._failOnWrite) {
|
|
54
|
-
throw new Error('Write operation failed');
|
|
55
|
-
}
|
|
56
|
-
if (typeof data === 'string') {
|
|
57
|
-
this._content = data;
|
|
58
|
-
}
|
|
59
|
-
else if (data instanceof Blob) {
|
|
60
|
-
this._content = await data.text();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const decoder = new TextDecoder();
|
|
64
|
-
this._content = decoder.decode(data);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async seek(position) {
|
|
68
|
-
// Mock implementation - not used in our tests
|
|
69
|
-
}
|
|
70
|
-
async truncate(size) {
|
|
71
|
-
// Mock implementation - not used in our tests
|
|
72
|
-
}
|
|
73
|
-
async close() {
|
|
74
|
-
if (!this._closed) {
|
|
75
|
-
this._closed = true;
|
|
76
|
-
this._onWrite(this._content);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
async abort() {
|
|
80
|
-
this._closed = true;
|
|
81
|
-
}
|
|
82
|
-
getWriter() {
|
|
83
|
-
throw new Error('getWriter not implemented in mock');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Mock implementation of FileSystemFileHandle
|
|
88
|
-
*/
|
|
89
|
-
export function createMockFileHandle(name, data, onWrite, options = {}) {
|
|
90
|
-
let currentContent = data.content;
|
|
91
|
-
const { hasWritePermission = true, permissionStatus, requestGranted = true } = options;
|
|
92
|
-
const handle = {
|
|
93
|
-
kind: 'file',
|
|
94
|
-
name,
|
|
95
|
-
async getFile() {
|
|
96
|
-
if (data.failOnRead) {
|
|
97
|
-
throw new Error('Failed to read file');
|
|
98
|
-
}
|
|
99
|
-
return createMockFile({
|
|
100
|
-
name,
|
|
101
|
-
content: currentContent,
|
|
102
|
-
type: data.type
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
async createWritable() {
|
|
106
|
-
return new MockFileSystemWritableFileStream((content) => {
|
|
107
|
-
currentContent = content;
|
|
108
|
-
if (onWrite) {
|
|
109
|
-
onWrite(content);
|
|
110
|
-
}
|
|
111
|
-
}, data.failOnWrite);
|
|
112
|
-
},
|
|
113
|
-
async queryPermission(descriptor) {
|
|
114
|
-
if (permissionStatus) {
|
|
115
|
-
return permissionStatus;
|
|
116
|
-
}
|
|
117
|
-
if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.mode) === 'readwrite' && !hasWritePermission) {
|
|
118
|
-
return 'denied';
|
|
119
|
-
}
|
|
120
|
-
return 'granted';
|
|
121
|
-
},
|
|
122
|
-
async requestPermission(descriptor) {
|
|
123
|
-
if (permissionStatus === 'prompt') {
|
|
124
|
-
return requestGranted ? 'granted' : 'denied';
|
|
125
|
-
}
|
|
126
|
-
if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.mode) === 'readwrite' && !hasWritePermission) {
|
|
127
|
-
return 'denied';
|
|
128
|
-
}
|
|
129
|
-
return 'granted';
|
|
130
|
-
},
|
|
131
|
-
isSameEntry: async (other) => {
|
|
132
|
-
return other === handle;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
return handle;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Parse file structure into nested map
|
|
139
|
-
*/
|
|
140
|
-
function parseFileStructure(files) {
|
|
141
|
-
const root = new Map();
|
|
142
|
-
for (const [path, data] of Object.entries(files)) {
|
|
143
|
-
const parts = path.split('/').filter((p) => p.length > 0);
|
|
144
|
-
let current = root;
|
|
145
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
146
|
-
const part = parts[i];
|
|
147
|
-
if (!current.has(part)) {
|
|
148
|
-
current.set(part, new Map());
|
|
149
|
-
}
|
|
150
|
-
current = current.get(part);
|
|
151
|
-
}
|
|
152
|
-
const filename = parts[parts.length - 1];
|
|
153
|
-
current.set(filename, data);
|
|
154
|
-
}
|
|
155
|
-
return root;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Mock implementation of FileSystemDirectoryHandle
|
|
159
|
-
*/
|
|
160
|
-
export function createMockDirectoryHandle(name, files, options = {}) {
|
|
161
|
-
const { hasWritePermission = true, permissionError = false, permissionStatus, requestGranted = true } = options;
|
|
162
|
-
const structure = parseFileStructure(files);
|
|
163
|
-
const fileHandles = new Map();
|
|
164
|
-
const dirHandles = new Map();
|
|
165
|
-
// Create file handles for all files
|
|
166
|
-
for (const [path, data] of Object.entries(files)) {
|
|
167
|
-
const handle = createMockFileHandle(path.split('/').pop() || '', data, (content) => {
|
|
168
|
-
// Update the file content when written
|
|
169
|
-
files[path] = Object.assign(Object.assign({}, data), { content });
|
|
170
|
-
});
|
|
171
|
-
fileHandles.set(path, handle);
|
|
172
|
-
}
|
|
173
|
-
function createSubDirectoryHandle(dirName, subStructure, parentPath) {
|
|
174
|
-
// For root directory, currentPath should be empty string
|
|
175
|
-
const currentPath = dirName === '/' ? '' : parentPath ? `${parentPath}/${dirName}` : dirName;
|
|
176
|
-
const handle = {
|
|
177
|
-
kind: 'directory',
|
|
178
|
-
name: dirName,
|
|
179
|
-
entries() {
|
|
180
|
-
return __asyncGenerator(this, arguments, function* entries_1() {
|
|
181
|
-
for (const [itemName, item] of subStructure.entries()) {
|
|
182
|
-
if (item instanceof Map) {
|
|
183
|
-
const subDirHandle = createSubDirectoryHandle(itemName, item, currentPath);
|
|
184
|
-
yield yield __await([itemName, subDirHandle]);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
const filePath = currentPath ? `${currentPath}/${itemName}` : itemName;
|
|
188
|
-
const fileHandle = fileHandles.get(filePath);
|
|
189
|
-
if (fileHandle) {
|
|
190
|
-
yield yield __await([itemName, fileHandle]);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
async getFileHandle(fileName, options) {
|
|
197
|
-
const filePath = currentPath ? `${currentPath}/${fileName}` : fileName;
|
|
198
|
-
let handle = fileHandles.get(filePath);
|
|
199
|
-
if (!handle && (options === null || options === void 0 ? void 0 : options.create)) {
|
|
200
|
-
const newData = { content: '', type: 'text/plain' };
|
|
201
|
-
files[filePath] = newData;
|
|
202
|
-
handle = createMockFileHandle(fileName, newData, (content) => {
|
|
203
|
-
files[filePath] = Object.assign(Object.assign({}, newData), { content });
|
|
204
|
-
});
|
|
205
|
-
fileHandles.set(filePath, handle);
|
|
206
|
-
// Add to structure
|
|
207
|
-
subStructure.set(fileName, newData);
|
|
208
|
-
}
|
|
209
|
-
if (!handle) {
|
|
210
|
-
throw new Error(`File not found: ${fileName}`);
|
|
211
|
-
}
|
|
212
|
-
return handle;
|
|
213
|
-
},
|
|
214
|
-
async getDirectoryHandle(dirName, options) {
|
|
215
|
-
const dirPath = currentPath ? `${currentPath}/${dirName}` : dirName;
|
|
216
|
-
let dirHandle = dirHandles.get(dirPath);
|
|
217
|
-
if (!dirHandle) {
|
|
218
|
-
let subDir = subStructure.get(dirName);
|
|
219
|
-
if (!subDir && (options === null || options === void 0 ? void 0 : options.create)) {
|
|
220
|
-
subDir = new Map();
|
|
221
|
-
subStructure.set(dirName, subDir);
|
|
222
|
-
}
|
|
223
|
-
if (subDir instanceof Map) {
|
|
224
|
-
dirHandle = createSubDirectoryHandle(dirName, subDir, currentPath);
|
|
225
|
-
dirHandles.set(dirPath, dirHandle);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (!dirHandle) {
|
|
229
|
-
throw new Error(`Directory not found: ${dirName}`);
|
|
230
|
-
}
|
|
231
|
-
return dirHandle;
|
|
232
|
-
},
|
|
233
|
-
async removeEntry(name, options) {
|
|
234
|
-
subStructure.delete(name);
|
|
235
|
-
},
|
|
236
|
-
async queryPermission(descriptor) {
|
|
237
|
-
if (permissionError) {
|
|
238
|
-
throw new Error('Permission query failed');
|
|
239
|
-
}
|
|
240
|
-
if (permissionStatus) {
|
|
241
|
-
return permissionStatus;
|
|
242
|
-
}
|
|
243
|
-
if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.mode) === 'readwrite' && !hasWritePermission) {
|
|
244
|
-
return 'denied';
|
|
245
|
-
}
|
|
246
|
-
return 'granted';
|
|
247
|
-
},
|
|
248
|
-
async requestPermission(descriptor) {
|
|
249
|
-
if (permissionError) {
|
|
250
|
-
throw new Error('Permission request failed');
|
|
251
|
-
}
|
|
252
|
-
if (permissionStatus === 'prompt') {
|
|
253
|
-
return requestGranted ? 'granted' : 'denied';
|
|
254
|
-
}
|
|
255
|
-
if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.mode) === 'readwrite' && !hasWritePermission) {
|
|
256
|
-
return 'denied';
|
|
257
|
-
}
|
|
258
|
-
return 'granted';
|
|
259
|
-
},
|
|
260
|
-
async resolve(possibleDescendant) {
|
|
261
|
-
return null;
|
|
262
|
-
},
|
|
263
|
-
isSameEntry: async (other) => {
|
|
264
|
-
return other === handle;
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
return handle;
|
|
268
|
-
}
|
|
269
|
-
return createSubDirectoryHandle(name, structure, '');
|
|
270
|
-
}
|
|
271
|
-
//# sourceMappingURL=fileSystemAccessMocks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileSystemAccessMocks.js","sourceRoot":"","sources":["../../../src/test/utils/fileSystemAccessMocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAsB/C;;GAEG;AACH,MAAM,OAAO,gCAAgC;IAM3C,YAAY,OAAkC,EAAE,cAAuB,KAAK;QALpE,aAAQ,GAAW,EAAE,CAAC;QACtB,YAAO,GAAY,KAAK,CAAC;QAK/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAkC;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,OAAO,IAAI,KAAK,QAAQ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AAK,WAAW,IAAI,CAAC,kBAAkB,EAAE,CAAC;oBAC5D,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,KAAK,CAAC,iBAAiB,CAAC,UAA4C;gBAClE,IAAI,eAAe,EAAE,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;gBAC/C,CAAC;gBACD,IAAI,gBAAgB,KAAK,QAAQ,EAAE,CAAC;oBAClC,OAAO,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC/C,CAAC;gBACD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,MAAK,WAAW,IAAI,CAAC,kBAAkB,EAAE,CAAC;oBAC5D,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,KAAK,CAAC,OAAO,CAAC,kBAAoC;gBAChD,OAAO,IAAI,CAAC;YACd,CAAC;YAED,WAAW,EAAE,KAAK,EAAE,KAAgC,EAAoB,EAAE;gBACxE,OAAO,KAAK,KAAK,MAAM,CAAC;YAC1B,CAAC;SACF,CAAC;QAEF,OAAO,MAAmC,CAAC;IAC7C,CAAC;IAED,OAAO,wBAAwB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC","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 { FileSystemDirectoryHandle, FileSystemFileHandle } from '../../packlets/file-api-types';\nimport { createMockFile } from './testHelpers';\n\n/**\n * Mock file data for File System Access API\n */\nexport interface MockFileData {\n content: string;\n type: string;\n failOnRead?: boolean;\n failOnWrite?: boolean;\n}\n\n/**\n * Options for mock directory handle\n */\nexport interface MockDirectoryOptions {\n hasWritePermission?: boolean;\n permissionError?: boolean;\n permissionStatus?: PermissionState;\n requestGranted?: boolean;\n}\n\n/**\n * Mock implementation of FileSystemWritableFileStream\n */\nexport class MockFileSystemWritableFileStream {\n private _content: string = '';\n private _closed: boolean = false;\n private readonly _onWrite: (content: string) => void;\n private readonly _failOnWrite: boolean;\n\n constructor(onWrite: (content: string) => void, failOnWrite: boolean = false) {\n this._onWrite = onWrite;\n this._failOnWrite = failOnWrite;\n }\n\n get locked(): boolean {\n return false;\n }\n\n async write(data: string | BufferSource | Blob): Promise<void> {\n if (this._closed) {\n throw new Error('Stream is closed');\n }\n if (this._failOnWrite) {\n throw new Error('Write operation failed');\n }\n\n if (typeof data === 'string') {\n this._content = data;\n } else if (data instanceof Blob) {\n this._content = await data.text();\n } else {\n const decoder = new TextDecoder();\n this._content = decoder.decode(data as BufferSource);\n }\n }\n\n async seek(position: number): Promise<void> {\n // Mock implementation - not used in our tests\n }\n\n async truncate(size: number): Promise<void> {\n // Mock implementation - not used in our tests\n }\n\n async close(): Promise<void> {\n if (!this._closed) {\n this._closed = true;\n this._onWrite(this._content);\n }\n }\n\n async abort(): Promise<void> {\n this._closed = true;\n }\n\n getWriter(): WritableStreamDefaultWriter {\n throw new Error('getWriter not implemented in mock');\n }\n}\n\n/**\n * Options for mock file handle\n */\nexport interface MockFileHandleOptions {\n hasWritePermission?: boolean;\n permissionStatus?: PermissionState;\n requestGranted?: boolean;\n}\n\n/**\n * Mock implementation of FileSystemFileHandle\n */\nexport function createMockFileHandle(\n name: string,\n data: MockFileData,\n onWrite?: (content: string) => void,\n options: MockFileHandleOptions = {}\n): FileSystemFileHandle {\n let currentContent = data.content;\n const { hasWritePermission = true, permissionStatus, requestGranted = true } = options;\n\n const handle = {\n kind: 'file' as const,\n name,\n\n async getFile(): Promise<File> {\n if (data.failOnRead) {\n throw new Error('Failed to read file');\n }\n return createMockFile({\n name,\n content: currentContent,\n type: data.type\n });\n },\n\n async createWritable(): Promise<MockFileSystemWritableFileStream> {\n return new MockFileSystemWritableFileStream((content) => {\n currentContent = content;\n if (onWrite) {\n onWrite(content);\n }\n }, data.failOnWrite);\n },\n\n async queryPermission(descriptor?: { mode?: 'read' | 'readwrite' }): Promise<PermissionState> {\n if (permissionStatus) {\n return permissionStatus;\n }\n if (descriptor?.mode === 'readwrite' && !hasWritePermission) {\n return 'denied';\n }\n return 'granted';\n },\n\n async requestPermission(descriptor?: { mode?: 'read' | 'readwrite' }): Promise<PermissionState> {\n if (permissionStatus === 'prompt') {\n return requestGranted ? 'granted' : 'denied';\n }\n if (descriptor?.mode === 'readwrite' && !hasWritePermission) {\n return 'denied';\n }\n return 'granted';\n },\n\n isSameEntry: async (other: FileSystemFileHandle): Promise<boolean> => {\n return other === handle;\n }\n };\n\n return handle as FileSystemFileHandle;\n}\n\n/**\n * Parse file structure into nested map\n */\nfunction parseFileStructure(\n files: Record<string, MockFileData>\n): Map<string, Map<string, MockFileData> | MockFileData> {\n const root = new Map<string, Map<string, MockFileData> | MockFileData>();\n\n for (const [path, data] of Object.entries(files)) {\n const parts = path.split('/').filter((p) => p.length > 0);\n let current = root;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n if (!current.has(part)) {\n current.set(part, new Map<string, MockFileData>());\n }\n current = current.get(part) as Map<string, MockFileData>;\n }\n\n const filename = parts[parts.length - 1];\n current.set(filename, data);\n }\n\n return root;\n}\n\n/**\n * Mock implementation of FileSystemDirectoryHandle\n */\nexport function createMockDirectoryHandle(\n name: string,\n files: Record<string, MockFileData>,\n options: MockDirectoryOptions = {}\n): FileSystemDirectoryHandle {\n const {\n hasWritePermission = true,\n permissionError = false,\n permissionStatus,\n requestGranted = true\n } = options;\n const structure = parseFileStructure(files);\n const fileHandles = new Map<string, FileSystemFileHandle>();\n const dirHandles = new Map<string, FileSystemDirectoryHandle>();\n\n // Create file handles for all files\n for (const [path, data] of Object.entries(files)) {\n const handle = createMockFileHandle(path.split('/').pop() || '', data, (content) => {\n // Update the file content when written\n files[path] = { ...data, content };\n });\n fileHandles.set(path, handle);\n }\n\n function createSubDirectoryHandle(\n dirName: string,\n subStructure: Map<string, Map<string, MockFileData> | MockFileData>,\n parentPath: string\n ): FileSystemDirectoryHandle {\n // For root directory, currentPath should be empty string\n const currentPath = dirName === '/' ? '' : parentPath ? `${parentPath}/${dirName}` : dirName;\n\n const handle = {\n kind: 'directory' as const,\n name: dirName,\n\n async *entries(): AsyncIterableIterator<[string, FileSystemFileHandle | FileSystemDirectoryHandle]> {\n for (const [itemName, item] of subStructure.entries()) {\n if (item instanceof Map) {\n const subDirHandle = createSubDirectoryHandle(itemName, item, currentPath);\n yield [itemName, subDirHandle];\n } else {\n const filePath = currentPath ? `${currentPath}/${itemName}` : itemName;\n const fileHandle = fileHandles.get(filePath);\n if (fileHandle) {\n yield [itemName, fileHandle];\n }\n }\n }\n },\n\n async getFileHandle(fileName: string, options?: { create?: boolean }): Promise<FileSystemFileHandle> {\n const filePath = currentPath ? `${currentPath}/${fileName}` : fileName;\n let handle = fileHandles.get(filePath);\n\n if (!handle && options?.create) {\n const newData: MockFileData = { content: '', type: 'text/plain' };\n files[filePath] = newData;\n handle = createMockFileHandle(fileName, newData, (content) => {\n files[filePath] = { ...newData, content };\n });\n fileHandles.set(filePath, handle);\n\n // Add to structure\n subStructure.set(fileName, newData);\n }\n\n if (!handle) {\n throw new Error(`File not found: ${fileName}`);\n }\n\n return handle;\n },\n\n async getDirectoryHandle(\n dirName: string,\n options?: { create?: boolean }\n ): Promise<FileSystemDirectoryHandle> {\n const dirPath = currentPath ? `${currentPath}/${dirName}` : dirName;\n let dirHandle = dirHandles.get(dirPath);\n\n if (!dirHandle) {\n let subDir = subStructure.get(dirName);\n if (!subDir && options?.create) {\n subDir = new Map<string, MockFileData>();\n subStructure.set(dirName, subDir);\n }\n\n if (subDir instanceof Map) {\n dirHandle = createSubDirectoryHandle(dirName, subDir, currentPath);\n dirHandles.set(dirPath, dirHandle);\n }\n }\n\n if (!dirHandle) {\n throw new Error(`Directory not found: ${dirName}`);\n }\n\n return dirHandle;\n },\n\n async removeEntry(name: string, options?: { recursive?: boolean }): Promise<void> {\n subStructure.delete(name);\n },\n\n async queryPermission(descriptor?: { mode?: 'read' | 'readwrite' }): Promise<PermissionState> {\n if (permissionError) {\n throw new Error('Permission query failed');\n }\n if (permissionStatus) {\n return permissionStatus;\n }\n if (descriptor?.mode === 'readwrite' && !hasWritePermission) {\n return 'denied';\n }\n return 'granted';\n },\n\n async requestPermission(descriptor?: { mode?: 'read' | 'readwrite' }): Promise<PermissionState> {\n if (permissionError) {\n throw new Error('Permission request failed');\n }\n if (permissionStatus === 'prompt') {\n return requestGranted ? 'granted' : 'denied';\n }\n if (descriptor?.mode === 'readwrite' && !hasWritePermission) {\n return 'denied';\n }\n return 'granted';\n },\n\n async resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null> {\n return null;\n },\n\n isSameEntry: async (other: FileSystemDirectoryHandle): Promise<boolean> => {\n return other === handle;\n }\n };\n\n return handle as FileSystemDirectoryHandle;\n }\n\n return createSubDirectoryHandle(name, structure, '');\n}\n"]}
|
|
@@ -1,124 +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
|
-
* Create a mock File object with all necessary properties and methods
|
|
24
|
-
*/
|
|
25
|
-
export function createMockFile(data) {
|
|
26
|
-
const blob = new Blob([data.content], { type: data.type || 'text/plain' });
|
|
27
|
-
const file = new File([blob], data.name, {
|
|
28
|
-
type: data.type || 'text/plain',
|
|
29
|
-
lastModified: data.lastModified || Date.now()
|
|
30
|
-
});
|
|
31
|
-
// Add webkitRelativePath if provided (for directory uploads)
|
|
32
|
-
if (data.webkitRelativePath) {
|
|
33
|
-
Object.defineProperty(file, 'webkitRelativePath', {
|
|
34
|
-
value: data.webkitRelativePath,
|
|
35
|
-
writable: false,
|
|
36
|
-
configurable: true
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
// Ensure text() method works properly
|
|
40
|
-
if (!file.text || typeof file.text !== 'function') {
|
|
41
|
-
Object.defineProperty(file, 'text', {
|
|
42
|
-
value: () => Promise.resolve(data.content),
|
|
43
|
-
writable: false,
|
|
44
|
-
configurable: true
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return file;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a mock FileList using DataTransfer API
|
|
51
|
-
* This is the most reliable method for creating FileList objects in tests
|
|
52
|
-
*/
|
|
53
|
-
export function createMockFileList(files) {
|
|
54
|
-
// Use DataTransfer to create a proper FileList
|
|
55
|
-
const dt = new DataTransfer();
|
|
56
|
-
files.forEach((fileData) => {
|
|
57
|
-
const file = createMockFile(fileData);
|
|
58
|
-
dt.items.add(file);
|
|
59
|
-
});
|
|
60
|
-
return dt.files;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Create a mock FileList for directory upload simulation
|
|
64
|
-
* Includes webkitRelativePath for each file
|
|
65
|
-
*/
|
|
66
|
-
export function createMockDirectoryFileList(directoryStructure) {
|
|
67
|
-
const files = directoryStructure.map((item) => ({
|
|
68
|
-
name: item.path.split('/').pop() || '',
|
|
69
|
-
content: item.content,
|
|
70
|
-
type: item.type,
|
|
71
|
-
webkitRelativePath: item.path
|
|
72
|
-
}));
|
|
73
|
-
return createMockFileList(files);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Helper to create a promise that resolves after a delay
|
|
77
|
-
* Useful for testing async operations
|
|
78
|
-
*/
|
|
79
|
-
export function delay(ms) {
|
|
80
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Helper to verify File API text() method works correctly
|
|
84
|
-
* Since we're using Blob/File polyfills, this ensures they have the right methods
|
|
85
|
-
*/
|
|
86
|
-
export async function verifyFileAPI(file) {
|
|
87
|
-
try {
|
|
88
|
-
// Check if text() method exists and works
|
|
89
|
-
if (typeof file.text !== 'function') {
|
|
90
|
-
throw new Error('File.text() method not available');
|
|
91
|
-
}
|
|
92
|
-
const text = await file.text();
|
|
93
|
-
return typeof text === 'string';
|
|
94
|
-
}
|
|
95
|
-
catch (_a) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Mock Web Crypto digest result for testing
|
|
101
|
-
* Creates a deterministic hash-like ArrayBuffer
|
|
102
|
-
*/
|
|
103
|
-
export function createMockDigest(input, algorithm = 'SHA-256') {
|
|
104
|
-
// Create a deterministic "hash" based on input for testing
|
|
105
|
-
// This is not a real hash but good enough for testing
|
|
106
|
-
const hashLength = algorithm.includes('256') ? 32 : algorithm.includes('512') ? 64 : 20;
|
|
107
|
-
const buffer = new ArrayBuffer(hashLength);
|
|
108
|
-
const view = new Uint8Array(buffer);
|
|
109
|
-
// Fill with deterministic values based on input
|
|
110
|
-
for (let i = 0; i < hashLength; i++) {
|
|
111
|
-
view[i] = (input.charCodeAt(i % input.length) + i) % 256;
|
|
112
|
-
}
|
|
113
|
-
return buffer;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Convert ArrayBuffer to hex string for comparison in tests
|
|
117
|
-
*/
|
|
118
|
-
export function arrayBufferToHex(buffer) {
|
|
119
|
-
const view = new Uint8Array(buffer);
|
|
120
|
-
return Array.from(view)
|
|
121
|
-
.map((b) => b.toString(16).padStart(2, '0'))
|
|
122
|
-
.join('');
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=testHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testHelpers.js","sourceRoot":"","sources":["../../../src/test/utils/testHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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D;IAC3D,sDAAsD;IACtD,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxF,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAEpC,gDAAgD;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;IAC3D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;SACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,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 * Test utilities for mocking browser APIs\n */\n\n/**\n * Mock file data structure\n */\nexport interface MockFileData {\n name: string;\n content: string;\n type?: string;\n lastModified?: number;\n webkitRelativePath?: string;\n}\n\n/**\n * Create a mock File object with all necessary properties and methods\n */\nexport function createMockFile(data: MockFileData): File {\n const blob = new Blob([data.content], { type: data.type || 'text/plain' });\n const file = new File([blob], data.name, {\n type: data.type || 'text/plain',\n lastModified: data.lastModified || Date.now()\n });\n\n // Add webkitRelativePath if provided (for directory uploads)\n if (data.webkitRelativePath) {\n Object.defineProperty(file, 'webkitRelativePath', {\n value: data.webkitRelativePath,\n writable: false,\n configurable: true\n });\n }\n\n // Ensure text() method works properly\n if (!file.text || typeof file.text !== 'function') {\n Object.defineProperty(file, 'text', {\n value: () => Promise.resolve(data.content),\n writable: false,\n configurable: true\n });\n }\n\n return file;\n}\n\n/**\n * Create a mock FileList using DataTransfer API\n * This is the most reliable method for creating FileList objects in tests\n */\nexport function createMockFileList(files: MockFileData[]): FileList {\n // Use DataTransfer to create a proper FileList\n const dt = new DataTransfer();\n\n files.forEach((fileData) => {\n const file = createMockFile(fileData);\n dt.items.add(file);\n });\n\n return dt.files;\n}\n\n/**\n * Create a mock FileList for directory upload simulation\n * Includes webkitRelativePath for each file\n */\nexport function createMockDirectoryFileList(\n directoryStructure: Array<{ path: string; content: string; type?: string }>\n): FileList {\n const files = directoryStructure.map((item) => ({\n name: item.path.split('/').pop() || '',\n content: item.content,\n type: item.type,\n webkitRelativePath: item.path\n }));\n\n return createMockFileList(files);\n}\n\n/**\n * Helper to create a promise that resolves after a delay\n * Useful for testing async operations\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Helper to verify File API text() method works correctly\n * Since we're using Blob/File polyfills, this ensures they have the right methods\n */\nexport async function verifyFileAPI(file: File): Promise<boolean> {\n try {\n // Check if text() method exists and works\n if (typeof file.text !== 'function') {\n throw new Error('File.text() method not available');\n }\n\n const text = await file.text();\n return typeof text === 'string';\n } catch {\n return false;\n }\n}\n\n/**\n * Mock Web Crypto digest result for testing\n * Creates a deterministic hash-like ArrayBuffer\n */\nexport function createMockDigest(input: string, algorithm: string = 'SHA-256'): ArrayBuffer {\n // Create a deterministic \"hash\" based on input for testing\n // This is not a real hash but good enough for testing\n const hashLength = algorithm.includes('256') ? 32 : algorithm.includes('512') ? 64 : 20;\n const buffer = new ArrayBuffer(hashLength);\n const view = new Uint8Array(buffer);\n\n // Fill with deterministic values based on input\n for (let i = 0; i < hashLength; i++) {\n view[i] = (input.charCodeAt(i % input.length) + i) % 256;\n }\n\n return buffer;\n}\n\n/**\n * Convert ArrayBuffer to hex string for comparison in tests\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n const view = new Uint8Array(buffer);\n return Array.from(view)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
[**@fgv/ts-web-extras**](../../../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@fgv/ts-web-extras](../../../README.md) / CryptoUtils
|
|
6
|
-
|
|
7
|
-
# CryptoUtils
|
|
8
|
-
|
|
9
|
-
Browser-compatible cryptographic utilities using the Web Crypto API.
|
|
10
|
-
|
|
11
|
-
## Classes
|
|
12
|
-
|
|
13
|
-
- [BrowserCryptoProvider](classes/BrowserCryptoProvider.md)
|
|
14
|
-
- [BrowserHashProvider](classes/BrowserHashProvider.md)
|
|
15
|
-
|
|
16
|
-
## Functions
|
|
17
|
-
|
|
18
|
-
- [createBrowserCryptoProvider](functions/createBrowserCryptoProvider.md)
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
[**@fgv/ts-web-extras**](../../../../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@fgv/ts-web-extras](../../../../README.md) / [CryptoUtils](../README.md) / BrowserCryptoProvider
|
|
6
|
-
|
|
7
|
-
# Class: BrowserCryptoProvider
|
|
8
|
-
|
|
9
|
-
Browser implementation of `ICryptoProvider` using the Web Crypto API.
|
|
10
|
-
Uses AES-256-GCM for authenticated encryption.
|
|
11
|
-
|
|
12
|
-
Note: This provider requires a browser environment with Web Crypto API support.
|
|
13
|
-
In Node.js 15+, Web Crypto is available via globalThis.crypto or require('crypto').webcrypto.
|
|
14
|
-
|
|
15
|
-
## Implements
|
|
16
|
-
|
|
17
|
-
- [`ICryptoProvider`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-web-extras/docs)
|
|
18
|
-
|
|
19
|
-
## Constructors
|
|
20
|
-
|
|
21
|
-
### Constructor
|
|
22
|
-
|
|
23
|
-
> **new BrowserCryptoProvider**(`cryptoApi?`): `BrowserCryptoProvider`
|
|
24
|
-
|
|
25
|
-
Creates a new BrowserCryptoProvider.
|
|
26
|
-
|
|
27
|
-
#### Parameters
|
|
28
|
-
|
|
29
|
-
| Parameter | Type | Description |
|
|
30
|
-
| ------ | ------ | ------ |
|
|
31
|
-
| `cryptoApi?` | `Crypto` | Optional Crypto instance (defaults to globalThis.crypto) |
|
|
32
|
-
|
|
33
|
-
#### Returns
|
|
34
|
-
|
|
35
|
-
`BrowserCryptoProvider`
|
|
36
|
-
|
|
37
|
-
## Methods
|
|
38
|
-
|
|
39
|
-
### decrypt()
|
|
40
|
-
|
|
41
|
-
> **decrypt**(`encryptedData`, `key`, `iv`, `authTag`): `Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`string`\>\>
|
|
42
|
-
|
|
43
|
-
Decrypts ciphertext using AES-256-GCM.
|
|
44
|
-
|
|
45
|
-
#### Parameters
|
|
46
|
-
|
|
47
|
-
| Parameter | Type | Description |
|
|
48
|
-
| ------ | ------ | ------ |
|
|
49
|
-
| `encryptedData` | `Uint8Array` | Encrypted bytes |
|
|
50
|
-
| `key` | `Uint8Array` | 32-byte decryption key |
|
|
51
|
-
| `iv` | `Uint8Array` | Initialization vector (12 bytes) |
|
|
52
|
-
| `authTag` | `Uint8Array` | GCM authentication tag (16 bytes) |
|
|
53
|
-
|
|
54
|
-
#### Returns
|
|
55
|
-
|
|
56
|
-
`Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`string`\>\>
|
|
57
|
-
|
|
58
|
-
`Success` with decrypted UTF-8 string, or `Failure` with an error.
|
|
59
|
-
|
|
60
|
-
#### Implementation of
|
|
61
|
-
|
|
62
|
-
`ICryptoProvider.decrypt`
|
|
63
|
-
|
|
64
|
-
***
|
|
65
|
-
|
|
66
|
-
### deriveKey()
|
|
67
|
-
|
|
68
|
-
> **deriveKey**(`password`, `salt`, `iterations`): `Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>\>
|
|
69
|
-
|
|
70
|
-
Derives a key from a password using PBKDF2.
|
|
71
|
-
|
|
72
|
-
#### Parameters
|
|
73
|
-
|
|
74
|
-
| Parameter | Type | Description |
|
|
75
|
-
| ------ | ------ | ------ |
|
|
76
|
-
| `password` | `string` | Password string |
|
|
77
|
-
| `salt` | `Uint8Array` | Salt bytes (should be at least 16 bytes) |
|
|
78
|
-
| `iterations` | `number` | Number of iterations (recommend 100000+) |
|
|
79
|
-
|
|
80
|
-
#### Returns
|
|
81
|
-
|
|
82
|
-
`Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>\>
|
|
83
|
-
|
|
84
|
-
Success with derived 32-byte key, or Failure with error
|
|
85
|
-
|
|
86
|
-
#### Implementation of
|
|
87
|
-
|
|
88
|
-
`ICryptoProvider.deriveKey`
|
|
89
|
-
|
|
90
|
-
***
|
|
91
|
-
|
|
92
|
-
### encrypt()
|
|
93
|
-
|
|
94
|
-
> **encrypt**(`plaintext`, `key`): `Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<[`IEncryptionResult`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-extras/docs)\>\>
|
|
95
|
-
|
|
96
|
-
Encrypts plaintext using AES-256-GCM.
|
|
97
|
-
|
|
98
|
-
#### Parameters
|
|
99
|
-
|
|
100
|
-
| Parameter | Type | Description |
|
|
101
|
-
| ------ | ------ | ------ |
|
|
102
|
-
| `plaintext` | `string` | UTF-8 string to encrypt |
|
|
103
|
-
| `key` | `Uint8Array` | 32-byte encryption key |
|
|
104
|
-
|
|
105
|
-
#### Returns
|
|
106
|
-
|
|
107
|
-
`Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<[`IEncryptionResult`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-extras/docs)\>\>
|
|
108
|
-
|
|
109
|
-
`Success` with encryption result, or `Failure` with an error.
|
|
110
|
-
|
|
111
|
-
#### Implementation of
|
|
112
|
-
|
|
113
|
-
`ICryptoProvider.encrypt`
|
|
114
|
-
|
|
115
|
-
***
|
|
116
|
-
|
|
117
|
-
### fromBase64()
|
|
118
|
-
|
|
119
|
-
> **fromBase64**(`base64`): [`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>
|
|
120
|
-
|
|
121
|
-
Decodes base64 string to binary data.
|
|
122
|
-
|
|
123
|
-
#### Parameters
|
|
124
|
-
|
|
125
|
-
| Parameter | Type | Description |
|
|
126
|
-
| ------ | ------ | ------ |
|
|
127
|
-
| `base64` | `string` | Base64-encoded string |
|
|
128
|
-
|
|
129
|
-
#### Returns
|
|
130
|
-
|
|
131
|
-
[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>
|
|
132
|
-
|
|
133
|
-
Success with decoded bytes, or Failure if invalid base64
|
|
134
|
-
|
|
135
|
-
#### Implementation of
|
|
136
|
-
|
|
137
|
-
`ICryptoProvider.fromBase64`
|
|
138
|
-
|
|
139
|
-
***
|
|
140
|
-
|
|
141
|
-
### generateKey()
|
|
142
|
-
|
|
143
|
-
> **generateKey**(): `Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>\>
|
|
144
|
-
|
|
145
|
-
Generates a random 32-byte key suitable for AES-256.
|
|
146
|
-
|
|
147
|
-
#### Returns
|
|
148
|
-
|
|
149
|
-
`Promise`\<[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>\>
|
|
150
|
-
|
|
151
|
-
Success with generated key, or Failure with error
|
|
152
|
-
|
|
153
|
-
#### Implementation of
|
|
154
|
-
|
|
155
|
-
`ICryptoProvider.generateKey`
|
|
156
|
-
|
|
157
|
-
***
|
|
158
|
-
|
|
159
|
-
### generateRandomBytes()
|
|
160
|
-
|
|
161
|
-
> **generateRandomBytes**(`length`): [`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>
|
|
162
|
-
|
|
163
|
-
Generates cryptographically secure random bytes.
|
|
164
|
-
|
|
165
|
-
#### Parameters
|
|
166
|
-
|
|
167
|
-
| Parameter | Type | Description |
|
|
168
|
-
| ------ | ------ | ------ |
|
|
169
|
-
| `length` | `number` | Number of bytes to generate |
|
|
170
|
-
|
|
171
|
-
#### Returns
|
|
172
|
-
|
|
173
|
-
[`Result`](https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils/docs)\<`Uint8Array`\<`ArrayBufferLike`\>\>
|
|
174
|
-
|
|
175
|
-
Success with random bytes, or Failure with error
|
|
176
|
-
|
|
177
|
-
#### Implementation of
|
|
178
|
-
|
|
179
|
-
`ICryptoProvider.generateRandomBytes`
|
|
180
|
-
|
|
181
|
-
***
|
|
182
|
-
|
|
183
|
-
### toBase64()
|
|
184
|
-
|
|
185
|
-
> **toBase64**(`data`): `string`
|
|
186
|
-
|
|
187
|
-
Encodes binary data to base64 string.
|
|
188
|
-
|
|
189
|
-
#### Parameters
|
|
190
|
-
|
|
191
|
-
| Parameter | Type | Description |
|
|
192
|
-
| ------ | ------ | ------ |
|
|
193
|
-
| `data` | `Uint8Array` | Binary data to encode |
|
|
194
|
-
|
|
195
|
-
#### Returns
|
|
196
|
-
|
|
197
|
-
`string`
|
|
198
|
-
|
|
199
|
-
Base64-encoded string
|
|
200
|
-
|
|
201
|
-
#### Implementation of
|
|
202
|
-
|
|
203
|
-
`ICryptoProvider.toBase64`
|