@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSystemAccessTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileSystemAccessTreeAccessors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;AAEH,4CAAwG;AACxG,oDAA6C;AAgC7C;;;;GAIG;AACH,MAAa,6BACX,SAAQ,uBAAQ,CAAC,qBAA0B;IAS3C;;;;;;;OAOG;IACH,YACE,KAAoC,EACpC,OAAkC,EAClC,OAA0C,EAC1C,MAAoD,EACpD,kBAA2B;;QAE3B,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,mCAAI,KAAK,CAAC;QAC3C,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAC;IAChD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,mBAAmB,CACrC,SAAoC,EACpC,MAAyC;;QAEzC,IAAI,CAAC;YACH,yBAAyB;YACzB,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;YAEvE,qEAAqE;YACrE,IAAI,CAAC,kBAAkB,IAAI,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,sBAAsB,mCAAI,IAAI,CAAC,EAAE,CAAC;gBACpE,OAAO,IAAA,eAAI,EAAC,2CAA2C,CAAC,CAAC;YAC3D,CAAC;YAED,0FAA0F;YAC1F,MAAM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,OAAO,IAAA,eAAI,EAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;YAC5C,CAAC;YAED,sCAAsC;YACtC,IAAI,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC;YAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,UAAU,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3E,CAAC;YAED,iCAAiC;YACjC,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAEpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC5B,qEAAqE;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO,IAAA,eAAI,EAAC,yBAAyB,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF;AA9WD,sEA8WC","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 { Result, succeed, fail, captureResult, DetailedResult, succeedWithDetail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport { FileSystemDirectoryHandle, FileSystemFileHandle } from '../file-api-types';\n\n/**\n * Options for creating persistent file trees.\n * @public\n */\nexport interface IFileSystemAccessTreeParams<TCT extends string = string>\n extends FileTree.IFileTreeInitParams<TCT> {\n /**\n * Automatically sync changes to disk immediately after each save.\n * If false, changes are batched and written on explicit syncToDisk() call.\n * @defaultValue false\n */\n autoSync?: boolean;\n\n /**\n * Require write permission on the directory handle.\n * If true, fails if write permission cannot be obtained.\n * If false, falls back to read-only mode.\n * @defaultValue true\n */\n requireWritePermission?: boolean;\n\n /**\n * Override the path at which the file is stored in the tree (for fromFileHandle).\n * Must be an absolute path (e.g., '/data/confections/common.yaml').\n * If omitted, defaults to `/<filename>`.\n */\n filePath?: string;\n}\n\n/**\n * Implementation of `FileTree.IPersistentFileTreeAccessors` that uses the File System Access API\n * to provide persistent file editing in browsers.\n * @public\n */\nexport class FileSystemAccessTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _handles: Map<string, FileSystemFileHandle>;\n private readonly _rootDir: FileSystemDirectoryHandle;\n private readonly _dirtyFiles: Set<string>;\n private readonly _autoSync: boolean;\n private readonly _hasWritePermission: boolean;\n\n /**\n * Protected constructor for FileSystemAccessTreeAccessors.\n * @param files - An array of in-memory files to include in the tree.\n * @param rootDir - The root directory handle.\n * @param handles - Map of file paths to their handles.\n * @param params - Optional params for the tree.\n * @param hasWritePermission - Whether write permission was granted.\n */\n protected constructor(\n files: FileTree.IInMemoryFile<TCT>[],\n rootDir: FileSystemDirectoryHandle,\n handles: Map<string, FileSystemFileHandle>,\n params: IFileSystemAccessTreeParams<TCT> | undefined,\n hasWritePermission: boolean\n ) {\n super(files, params);\n this._rootDir = rootDir;\n this._handles = handles;\n this._dirtyFiles = new Set();\n this._autoSync = params?.autoSync ?? false;\n this._hasWritePermission = hasWritePermission;\n }\n\n /**\n * Creates a new FileSystemAccessTreeAccessors instance from a directory handle.\n * @param dirHandle - The FileSystemDirectoryHandle to load files from.\n * @param params - Optional parameters including autoSync and permission settings.\n * @returns Promise resolving to a FileSystemAccessTreeAccessors instance.\n * @public\n */\n public static async fromDirectoryHandle<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileSystemAccessTreeAccessors<TCT>>> {\n try {\n // Check write permission\n const hasWritePermission = await this._checkWritePermission(dirHandle);\n\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!hasWritePermission && (params?.requireWritePermission ?? true)) {\n return fail('Write permission required but not granted');\n }\n\n // Load all files from the directory (always use '/' as base, prefix is handled by parent)\n const { files, handles } = await this._loadDirectory<TCT>(dirHandle, '/', params);\n\n // Enable tree mutability when write permission is granted and caller didn't explicitly set mutable\n const effectiveParams: IFileSystemAccessTreeParams<TCT> = {\n ...params,\n mutable: params?.mutable ?? (hasWritePermission ? true : false)\n };\n\n return succeed(\n new FileSystemAccessTreeAccessors<TCT>(files, dirHandle, handles, effectiveParams, hasWritePermission)\n );\n /* c8 ignore next 4 - defensive: outer catch for unexpected errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create FileSystemAccessTreeAccessors: ${message}`);\n }\n }\n\n /**\n * Creates a new FileSystemAccessTreeAccessors instance from a single file handle.\n *\n * The resulting tree contains exactly one file at `/<filename>`.\n * `syncToDisk()` writes changes back to the original file via the File System Access API.\n * New file creation is not supported on this tree (no parent directory handle).\n *\n * @param fileHandle - The FileSystemFileHandle to load.\n * @param params - Optional parameters including autoSync and permission settings.\n * @returns Promise resolving to a FileSystemAccessTreeAccessors instance.\n * @public\n */\n public static async fromFileHandle<TCT extends string = string>(\n fileHandle: FileSystemFileHandle,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<Result<FileSystemAccessTreeAccessors<TCT>>> {\n try {\n const hasWritePermission = await this._checkFileWritePermission(fileHandle);\n\n if (!hasWritePermission && (params?.requireWritePermission ?? true)) {\n return fail('Write permission required but not granted');\n }\n\n const file = await fileHandle.getFile();\n const contents = await file.text();\n const path = params?.filePath ?? `/${fileHandle.name}`;\n const contentType = params?.inferContentType\n ? params.inferContentType(path, file.type).orDefault()\n : undefined;\n\n const files: FileTree.IInMemoryFile<TCT>[] = [{ path, contents, contentType }];\n const handles = new Map<string, FileSystemFileHandle>([[path, fileHandle]]);\n\n const dummyRoot = {} as FileSystemDirectoryHandle;\n const effectiveParams: IFileSystemAccessTreeParams<TCT> = {\n ...params,\n mutable: hasWritePermission ? true : params?.mutable ?? false\n };\n\n return succeed(\n new FileSystemAccessTreeAccessors<TCT>(files, dummyRoot, handles, effectiveParams, hasWritePermission)\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create FileSystemAccessTreeAccessors from file: ${message}`);\n }\n }\n\n /**\n * Check if the directory handle has write permission.\n * @param handle - The directory handle to check.\n * @returns Promise resolving to true if write permission is granted.\n * @internal\n */\n private static async _checkWritePermission(handle: FileSystemDirectoryHandle): Promise<boolean> {\n try {\n const permission = await handle.queryPermission({ mode: 'readwrite' });\n\n if (permission === 'granted') {\n return true;\n }\n\n if (permission === 'prompt') {\n const requested = await handle.requestPermission({ mode: 'readwrite' });\n return requested === 'granted';\n }\n\n return false;\n } catch (error) {\n // Permission API might not be available or might throw\n return false;\n }\n }\n\n /**\n * Check if the file handle has write permission.\n * @param handle - The file handle to check.\n * @returns Promise resolving to true if write permission is granted.\n * @internal\n */\n private static async _checkFileWritePermission(handle: FileSystemFileHandle): Promise<boolean> {\n try {\n const permission = await handle.queryPermission({ mode: 'readwrite' });\n\n if (permission === 'granted') {\n return true;\n }\n\n if (permission === 'prompt') {\n const requested = await handle.requestPermission({ mode: 'readwrite' });\n return requested === 'granted';\n }\n\n return false;\n } catch (error) {\n return false;\n }\n }\n\n /**\n * Load all files from a directory handle recursively.\n * @param dirHandle - The directory handle to load from.\n * @param basePath - The base path for files.\n * @param params - Optional parameters.\n * @returns Promise resolving to files and handles.\n * @internal\n */\n private static async _loadDirectory<TCT extends string = string>(\n dirHandle: FileSystemDirectoryHandle,\n basePath: string,\n params?: IFileSystemAccessTreeParams<TCT>\n ): Promise<{ files: FileTree.IInMemoryFile<TCT>[]; handles: Map<string, FileSystemFileHandle> }> {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n const handles = new Map<string, FileSystemFileHandle>();\n\n for await (const [name, handle] of dirHandle.entries()) {\n if (handle.kind === 'file') {\n const fileHandle = handle as FileSystemFileHandle;\n const file = await fileHandle.getFile();\n const contents = await file.text();\n const path = this._joinPath(basePath, name);\n /* c8 ignore next 2 - coverage intermittently missed in full suite */\n const contentType = params?.inferContentType\n ? params.inferContentType(path, file.type).orDefault()\n : undefined;\n\n files.push({ path, contents, contentType });\n handles.set(path, fileHandle);\n } else if (handle.kind === 'directory') {\n const subDirHandle = handle as FileSystemDirectoryHandle;\n const subPath = this._joinPath(basePath, name);\n const subResult = await this._loadDirectory<TCT>(subDirHandle, subPath, params);\n files.push(...subResult.files);\n for (const [path, fileHandle] of subResult.handles) {\n handles.set(path, fileHandle);\n }\n }\n }\n\n return { files, handles };\n }\n\n /**\n * Join path segments.\n * @param base - The base path.\n * @param name - The name to append.\n * @returns The joined path.\n * @internal\n */\n private static _joinPath(base: string, name: string): string {\n const normalized = base.endsWith('/') ? base.slice(0, -1) : base;\n return `${normalized}/${name}`;\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.syncToDisk`\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (!this._hasWritePermission) {\n return fail('Write permission not granted - cannot sync to disk');\n }\n\n const errors: string[] = [];\n\n for (const path of this._dirtyFiles) {\n const syncResult = await this._syncFile(path);\n if (syncResult.isFailure()) {\n errors.push(`${path}: ${syncResult.message}`);\n }\n }\n\n if (errors.length > 0) {\n return fail(`Failed to sync ${errors.length} file(s):\\n${errors.join('\\n')}`);\n }\n\n this._dirtyFiles.clear();\n return succeed(undefined);\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.isDirty`\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0;\n }\n\n /**\n * Implements `FileTree.IPersistentFileTreeAccessors.getDirtyPaths`\n */\n public getDirtyPaths(): string[] {\n return Array.from(this._dirtyFiles);\n }\n\n /**\n * Implements `FileTree.IMutableFileTreeAccessors.saveFileContents`\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n // Call parent to update in-memory state\n const result = super.saveFileContents(path, contents);\n\n if (result.isSuccess() && this._hasWritePermission) {\n this._dirtyFiles.add(path);\n\n // Auto-sync if enabled\n if (this._autoSync) {\n // Fire and forget - errors logged but don't block\n this._syncFile(path).catch((err) => {\n /* c8 ignore next 1 - defensive: async auto-sync error logging */\n console.error(`Auto-sync failed for ${path}:`, err);\n });\n }\n }\n\n return result;\n }\n\n /**\n * Implements `FileTree.IMutableFileTreeAccessors.fileIsMutable`\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const baseResult = super.fileIsMutable(path);\n\n if (baseResult.isSuccess() && baseResult.detail === 'transient' && this._hasWritePermission) {\n // Upgrade to 'persistent' if we have write permission\n return succeedWithDetail(true, 'persistent');\n }\n\n return baseResult;\n }\n\n /**\n * Sync a single file to disk.\n * @param path - The path of the file to sync.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _syncFile(path: string): Promise<Result<void>> {\n const handle = this._handles.get(path);\n if (!handle) {\n return this._createAndWriteFile(path);\n }\n\n const contents = this.getFileContents(path);\n if (contents.isFailure()) {\n return fail(contents.message);\n }\n\n try {\n const writable = await handle.createWritable();\n await writable.write(contents.value);\n await writable.close();\n return succeed(undefined);\n /* c8 ignore next 4 - coverage intermittently missed in full suite */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to write file: ${message}`);\n }\n }\n\n /**\n * Create a new file and write its contents.\n * @param path - The path of the file to create.\n * @returns Promise resolving to success or failure.\n * @internal\n */\n private async _createAndWriteFile(path: string): Promise<Result<void>> {\n try {\n // Parse path to get directory and filename\n const absolutePath = this.resolveAbsolutePath(path);\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n const filename = parts.pop();\n\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!filename) {\n return fail(`Invalid file path: ${path}`);\n }\n\n // Navigate/create directory structure\n let currentDir = this._rootDir;\n for (const part of parts) {\n currentDir = await currentDir.getDirectoryHandle(part, { create: true });\n }\n\n // Create file and write contents\n const fileHandle = await currentDir.getFileHandle(filename, { create: true });\n this._handles.set(path, fileHandle);\n\n return this._syncFile(path);\n /* c8 ignore next 4 - coverage intermittently missed in full suite */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create file ${path}: ${message}`);\n }\n }\n}\n"]}
|
|
@@ -2,5 +2,8 @@
|
|
|
2
2
|
* Browser-compatible FileTree implementations using the File API.
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
|
+
export * from './directoryHandleStore';
|
|
5
6
|
export * from './fileApiTreeAccessors';
|
|
7
|
+
export * from './fileSystemAccessTreeAccessors';
|
|
8
|
+
export * from './localStorageTreeAccessors';
|
|
6
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC"}
|
|
@@ -39,5 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
* Browser-compatible FileTree implementations using the File API.
|
|
40
40
|
* @packageDocumentation
|
|
41
41
|
*/
|
|
42
|
+
__exportStar(require("./directoryHandleStore"), exports);
|
|
42
43
|
__exportStar(require("./fileApiTreeAccessors"), exports);
|
|
44
|
+
__exportStar(require("./fileSystemAccessTreeAccessors"), exports);
|
|
45
|
+
__exportStar(require("./localStorageTreeAccessors"), exports);
|
|
43
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH;;;GAGG;AAEH,yDAAuC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Browser-compatible FileTree implementations using the File API.\n * @packageDocumentation\n */\n\nexport * from './fileApiTreeAccessors';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH;;;GAGG;AAEH,yDAAuC;AACvC,yDAAuC;AACvC,kEAAgD;AAChD,8DAA4C","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Browser-compatible FileTree implementations using the File API.\n * @packageDocumentation\n */\n\nexport * from './directoryHandleStore';\nexport * from './fileApiTreeAccessors';\nexport * from './fileSystemAccessTreeAccessors';\nexport * from './localStorageTreeAccessors';\n"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { DetailedResult, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { FileTree } from '@fgv/ts-json-base';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for LocalStorageTreeAccessors.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface ILocalStorageTreeParams<TCT extends string = string> extends FileTree.IFileTreeInitParams<TCT> {
|
|
8
|
+
/**
|
|
9
|
+
* Map of directory path prefixes to localStorage keys.
|
|
10
|
+
* Files under each prefix are stored in the corresponding localStorage key.
|
|
11
|
+
* Example: \{ '/data/ingredients': 'myapp:ingredients:v1' \}
|
|
12
|
+
*/
|
|
13
|
+
pathToKeyMap: Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Storage instance to use. Defaults to window.localStorage.
|
|
16
|
+
* Can be overridden for testing with mock storage.
|
|
17
|
+
*/
|
|
18
|
+
storage?: Storage;
|
|
19
|
+
/**
|
|
20
|
+
* If true, automatically sync changes to localStorage on every modification.
|
|
21
|
+
* If false (default), changes are only synced when syncToDisk() is called.
|
|
22
|
+
*/
|
|
23
|
+
autoSync?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Browser localStorage-backed file tree accessors with persistence support.
|
|
27
|
+
*
|
|
28
|
+
* Maps filesystem-like directory paths to localStorage keys, where each key stores
|
|
29
|
+
* multiple collections as a JSON object. This provides a general-purpose implementation
|
|
30
|
+
* for browser-based file tree persistence without requiring File System Access API.
|
|
31
|
+
*
|
|
32
|
+
* Storage format per key: `{ "collection-id": "<raw file content>" }`
|
|
33
|
+
* File paths map as: `/data/ingredients/collection-id.yaml` → stored in key for `/data/ingredients`
|
|
34
|
+
*
|
|
35
|
+
* Legacy format (v1): `{ "collection-id": { ...parsedJsonObject } }` is auto-migrated on load.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare class LocalStorageTreeAccessors<TCT extends string = string> extends FileTree.InMemoryTreeAccessors<TCT> implements FileTree.IPersistentFileTreeAccessors<TCT> {
|
|
40
|
+
private readonly _storage;
|
|
41
|
+
private readonly _pathToKeyMap;
|
|
42
|
+
private readonly _keyToPathMap;
|
|
43
|
+
private readonly _dirtyFiles;
|
|
44
|
+
private readonly _autoSync;
|
|
45
|
+
/**
|
|
46
|
+
* Private constructor. Use fromStorage() factory method instead.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
private constructor();
|
|
50
|
+
/**
|
|
51
|
+
* Create LocalStorageTreeAccessors from browser localStorage.
|
|
52
|
+
* Loads all collections from the configured storage keys.
|
|
53
|
+
*
|
|
54
|
+
* @param params - Configuration including path-to-key mappings
|
|
55
|
+
* @returns Result containing the accessors or an error
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
static fromStorage<TCT extends string = string>(params: ILocalStorageTreeParams<TCT>): Result<LocalStorageTreeAccessors<TCT>>;
|
|
59
|
+
/**
|
|
60
|
+
* Load all files from localStorage based on path-to-key mappings.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
private static _loadFromStorage;
|
|
64
|
+
/**
|
|
65
|
+
* Heuristic check: does the content look like JSON?
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
private static _looksLikeJson;
|
|
69
|
+
/**
|
|
70
|
+
* Join path components, handling leading/trailing slashes.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
private static _joinPath;
|
|
74
|
+
/**
|
|
75
|
+
* Get the storage key for a given file path.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
private _getStorageKeyForPath;
|
|
79
|
+
/**
|
|
80
|
+
* Get the data path prefix for a given file path.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
private _getDataPathForPath;
|
|
84
|
+
/**
|
|
85
|
+
* Extract collection ID from a file path.
|
|
86
|
+
* Example: '/data/ingredients/my-collection.yaml' → 'my-collection'
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
private _getCollectionIdFromPath;
|
|
90
|
+
/**
|
|
91
|
+
* Sync a single dirty file to localStorage.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
private _syncFile;
|
|
95
|
+
/**
|
|
96
|
+
* Sync all dirty files to localStorage.
|
|
97
|
+
* @returns Result indicating success or failure
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
syncToDisk(): Promise<Result<void>>;
|
|
101
|
+
/**
|
|
102
|
+
* Check if there are unsaved changes.
|
|
103
|
+
* @returns True if there are dirty files
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
isDirty(): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Get list of file paths with unsaved changes.
|
|
109
|
+
* @returns Array of dirty file paths
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
getDirtyPaths(): string[];
|
|
113
|
+
/**
|
|
114
|
+
* Save file contents. Marks file as dirty and optionally auto-syncs.
|
|
115
|
+
* @param path - File path
|
|
116
|
+
* @param contents - New file contents
|
|
117
|
+
* @returns Result with the saved contents or error
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
saveFileContents(path: string, contents: string): Result<string>;
|
|
121
|
+
/**
|
|
122
|
+
* Check if a file is mutable and return persistence detail.
|
|
123
|
+
* @param path - File path to check
|
|
124
|
+
* @returns DetailedResult with mutability status and 'persistent' detail if mutable
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail>;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=localStorageTreeAccessors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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OAGG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAMxB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAa7B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAehC;;;OAGG;IACH,OAAO,CAAC,SAAS;IAyCjB;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAqBhD;;;;OAIG;IACI,OAAO,IAAI,OAAO;IAIzB;;;;OAIG;IACI,aAAa,IAAI,MAAM,EAAE;IAIhC;;;;;;OAMG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAgBvE;;;;;OAKG;IACI,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC;CAOjF"}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2026 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.LocalStorageTreeAccessors = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
27
|
+
const ts_json_base_2 = require("@fgv/ts-json-base");
|
|
28
|
+
/**
|
|
29
|
+
* Browser localStorage-backed file tree accessors with persistence support.
|
|
30
|
+
*
|
|
31
|
+
* Maps filesystem-like directory paths to localStorage keys, where each key stores
|
|
32
|
+
* multiple collections as a JSON object. This provides a general-purpose implementation
|
|
33
|
+
* for browser-based file tree persistence without requiring File System Access API.
|
|
34
|
+
*
|
|
35
|
+
* Storage format per key: `{ "collection-id": "<raw file content>" }`
|
|
36
|
+
* File paths map as: `/data/ingredients/collection-id.yaml` → stored in key for `/data/ingredients`
|
|
37
|
+
*
|
|
38
|
+
* Legacy format (v1): `{ "collection-id": { ...parsedJsonObject } }` is auto-migrated on load.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
class LocalStorageTreeAccessors extends ts_json_base_1.FileTree.InMemoryTreeAccessors {
|
|
43
|
+
/**
|
|
44
|
+
* Private constructor. Use fromStorage() factory method instead.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
constructor(files, storage, pathToKeyMap, params) {
|
|
48
|
+
var _a;
|
|
49
|
+
super(files, params);
|
|
50
|
+
this._storage = storage;
|
|
51
|
+
this._pathToKeyMap = pathToKeyMap;
|
|
52
|
+
this._keyToPathMap = new Map(Array.from(pathToKeyMap.entries()).map(([k, v]) => [v, k]));
|
|
53
|
+
this._dirtyFiles = new Set();
|
|
54
|
+
this._autoSync = (_a = params === null || params === void 0 ? void 0 : params.autoSync) !== null && _a !== void 0 ? _a : false;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create LocalStorageTreeAccessors from browser localStorage.
|
|
58
|
+
* Loads all collections from the configured storage keys.
|
|
59
|
+
*
|
|
60
|
+
* @param params - Configuration including path-to-key mappings
|
|
61
|
+
* @returns Result containing the accessors or an error
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
static fromStorage(params) {
|
|
65
|
+
var _a;
|
|
66
|
+
try {
|
|
67
|
+
const storage = (_a = params.storage) !== null && _a !== void 0 ? _a : (typeof window !== 'undefined' ? window.localStorage : undefined);
|
|
68
|
+
if (!storage) {
|
|
69
|
+
return (0, ts_utils_1.fail)('localStorage is not available');
|
|
70
|
+
}
|
|
71
|
+
const pathToKeyMap = new Map(Object.entries(params.pathToKeyMap));
|
|
72
|
+
const files = this._loadFromStorage(storage, pathToKeyMap, params);
|
|
73
|
+
return (0, ts_utils_1.succeed)(new LocalStorageTreeAccessors(files, storage, pathToKeyMap, params));
|
|
74
|
+
/* c8 ignore next 4 - defensive: outer catch for unexpected errors */
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
78
|
+
return (0, ts_utils_1.fail)(`Failed to create LocalStorageTreeAccessors: ${message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Load all files from localStorage based on path-to-key mappings.
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
static _loadFromStorage(storage, pathToKeyMap, params) {
|
|
86
|
+
const files = [];
|
|
87
|
+
for (const [dataPath, storageKey] of pathToKeyMap.entries()) {
|
|
88
|
+
const rawJson = storage.getItem(storageKey);
|
|
89
|
+
if (!rawJson) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const parsed = JSON.parse(rawJson);
|
|
94
|
+
if (!(0, ts_json_base_2.isJsonObject)(parsed)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
for (const [collectionId, contents] of Object.entries(parsed)) {
|
|
98
|
+
// Support both new format (string values) and legacy format (JsonObject values)
|
|
99
|
+
let rawContent;
|
|
100
|
+
let extension;
|
|
101
|
+
if (typeof contents === 'string') {
|
|
102
|
+
rawContent = contents;
|
|
103
|
+
// Infer extension: if content looks like JSON, use .json; otherwise .yaml
|
|
104
|
+
extension = this._looksLikeJson(contents) ? '.json' : '.yaml';
|
|
105
|
+
}
|
|
106
|
+
else if ((0, ts_json_base_2.isJsonObject)(contents)) {
|
|
107
|
+
// Legacy format: migrate by stringifying
|
|
108
|
+
rawContent = JSON.stringify(contents);
|
|
109
|
+
extension = '.json';
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const filePath = this._joinPath(dataPath, `${collectionId}${extension}`);
|
|
115
|
+
const contentType = (params === null || params === void 0 ? void 0 : params.inferContentType)
|
|
116
|
+
? params.inferContentType(filePath, undefined).orDefault()
|
|
117
|
+
: undefined;
|
|
118
|
+
files.push({
|
|
119
|
+
path: filePath,
|
|
120
|
+
contents: rawContent,
|
|
121
|
+
contentType
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (_a) {
|
|
126
|
+
// Skip corrupted data
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return files;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Heuristic check: does the content look like JSON?
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
static _looksLikeJson(content) {
|
|
137
|
+
const trimmed = content.trimStart();
|
|
138
|
+
return trimmed.startsWith('{') || trimmed.startsWith('[');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Join path components, handling leading/trailing slashes.
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
static _joinPath(base, name) {
|
|
145
|
+
const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
146
|
+
const cleanName = name.startsWith('/') ? name.slice(1) : name;
|
|
147
|
+
return `${cleanBase}/${cleanName}`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get the storage key for a given file path.
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
_getStorageKeyForPath(path) {
|
|
154
|
+
// Find the longest matching prefix
|
|
155
|
+
let bestMatch;
|
|
156
|
+
for (const [prefix, key] of this._pathToKeyMap.entries()) {
|
|
157
|
+
if (path.startsWith(prefix)) {
|
|
158
|
+
if (!bestMatch || prefix.length > bestMatch.prefix.length) {
|
|
159
|
+
bestMatch = { prefix, key };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return bestMatch === null || bestMatch === void 0 ? void 0 : bestMatch.key;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Get the data path prefix for a given file path.
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
_getDataPathForPath(path) {
|
|
170
|
+
for (const prefix of this._pathToKeyMap.keys()) {
|
|
171
|
+
if (path.startsWith(prefix)) {
|
|
172
|
+
return prefix;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/* c8 ignore next 2 - coverage intermittently missed in full suite */
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Extract collection ID from a file path.
|
|
180
|
+
* Example: '/data/ingredients/my-collection.yaml' → 'my-collection'
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
_getCollectionIdFromPath(path) {
|
|
184
|
+
const dataPath = this._getDataPathForPath(path);
|
|
185
|
+
/* c8 ignore next 3 - coverage intermittently missed in full suite */
|
|
186
|
+
if (!dataPath) {
|
|
187
|
+
return path;
|
|
188
|
+
}
|
|
189
|
+
const relativePath = path.slice(dataPath.length);
|
|
190
|
+
const cleanPath = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;
|
|
191
|
+
// Remove any file extension
|
|
192
|
+
const dotIndex = cleanPath.lastIndexOf('.');
|
|
193
|
+
return dotIndex > 0 ? cleanPath.slice(0, dotIndex) : cleanPath;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Sync a single dirty file to localStorage.
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
_syncFile(path) {
|
|
200
|
+
const storageKey = this._getStorageKeyForPath(path);
|
|
201
|
+
if (!storageKey) {
|
|
202
|
+
return (0, ts_utils_1.fail)(`No storage key configured for path: ${path}`);
|
|
203
|
+
}
|
|
204
|
+
const collectionId = this._getCollectionIdFromPath(path);
|
|
205
|
+
const contentsResult = this.getFileContents(path);
|
|
206
|
+
if (contentsResult.isFailure()) {
|
|
207
|
+
return (0, ts_utils_1.fail)(`Failed to get file contents for ${path}: ${contentsResult.message}`);
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const contents = contentsResult.value;
|
|
211
|
+
// Load existing data from storage
|
|
212
|
+
const existingJson = this._storage.getItem(storageKey);
|
|
213
|
+
let existing = {};
|
|
214
|
+
if (existingJson) {
|
|
215
|
+
try {
|
|
216
|
+
const parsed = JSON.parse(existingJson);
|
|
217
|
+
if ((0, ts_json_base_2.isJsonObject)(parsed)) {
|
|
218
|
+
existing = parsed;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (_a) {
|
|
222
|
+
// Start fresh if corrupted
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Store raw content string (content-agnostic: JSON, YAML, etc.)
|
|
226
|
+
existing[collectionId] = contents;
|
|
227
|
+
this._storage.setItem(storageKey, JSON.stringify(existing));
|
|
228
|
+
return (0, ts_utils_1.succeed)(undefined);
|
|
229
|
+
/* c8 ignore next 4 - defensive: only triggers on storage quota or similar runtime errors */
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
233
|
+
return (0, ts_utils_1.fail)(`Failed to sync file ${path}: ${message}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Sync all dirty files to localStorage.
|
|
238
|
+
* @returns Result indicating success or failure
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
async syncToDisk() {
|
|
242
|
+
if (this._dirtyFiles.size === 0) {
|
|
243
|
+
return (0, ts_utils_1.succeed)(undefined);
|
|
244
|
+
}
|
|
245
|
+
const errors = [];
|
|
246
|
+
for (const path of this._dirtyFiles) {
|
|
247
|
+
const result = this._syncFile(path);
|
|
248
|
+
if (result.isFailure()) {
|
|
249
|
+
errors.push(result.message);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (errors.length > 0) {
|
|
253
|
+
return (0, ts_utils_1.fail)(`Failed to sync ${errors.length} file(s): ${errors.join('; ')}`);
|
|
254
|
+
}
|
|
255
|
+
this._dirtyFiles.clear();
|
|
256
|
+
return (0, ts_utils_1.succeed)(undefined);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Check if there are unsaved changes.
|
|
260
|
+
* @returns True if there are dirty files
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
isDirty() {
|
|
264
|
+
return this._dirtyFiles.size > 0;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get list of file paths with unsaved changes.
|
|
268
|
+
* @returns Array of dirty file paths
|
|
269
|
+
* @public
|
|
270
|
+
*/
|
|
271
|
+
getDirtyPaths() {
|
|
272
|
+
return Array.from(this._dirtyFiles);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Save file contents. Marks file as dirty and optionally auto-syncs.
|
|
276
|
+
* @param path - File path
|
|
277
|
+
* @param contents - New file contents
|
|
278
|
+
* @returns Result with the saved contents or error
|
|
279
|
+
* @public
|
|
280
|
+
*/
|
|
281
|
+
saveFileContents(path, contents) {
|
|
282
|
+
const result = super.saveFileContents(path, contents);
|
|
283
|
+
if (result.isSuccess()) {
|
|
284
|
+
this._dirtyFiles.add(path);
|
|
285
|
+
if (this._autoSync) {
|
|
286
|
+
const syncResult = this._syncFile(path);
|
|
287
|
+
if (syncResult.isSuccess()) {
|
|
288
|
+
this._dirtyFiles.delete(path);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
return (0, ts_utils_1.fail)(syncResult.message);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Check if a file is mutable and return persistence detail.
|
|
299
|
+
* @param path - File path to check
|
|
300
|
+
* @returns DetailedResult with mutability status and 'persistent' detail if mutable
|
|
301
|
+
* @public
|
|
302
|
+
*/
|
|
303
|
+
fileIsMutable(path) {
|
|
304
|
+
const baseResult = super.fileIsMutable(path);
|
|
305
|
+
if (baseResult.isSuccess() && baseResult.value === true) {
|
|
306
|
+
return (0, ts_utils_1.succeedWithDetail)(true, 'persistent');
|
|
307
|
+
}
|
|
308
|
+
return baseResult;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.LocalStorageTreeAccessors = LocalStorageTreeAccessors;
|
|
312
|
+
//# sourceMappingURL=localStorageTreeAccessors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localStorageTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/localStorageTreeAccessors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAyF;AACzF,oDAA6C;AAC7C,oDAAkE;AA4BlE;;;;;;;;;;;;;GAaG;AACH,MAAa,yBACX,SAAQ,uB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B,CAAC;CACF;AAtTD,8DAsTC","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 { DetailedResult, fail, Result, succeed, succeedWithDetail } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport { isJsonObject, type JsonObject } from '@fgv/ts-json-base';\n\n/**\n * Configuration for LocalStorageTreeAccessors.\n * @public\n */\nexport interface ILocalStorageTreeParams<TCT extends string = string>\n extends FileTree.IFileTreeInitParams<TCT> {\n /**\n * Map of directory path prefixes to localStorage keys.\n * Files under each prefix are stored in the corresponding localStorage key.\n * Example: \\{ '/data/ingredients': 'myapp:ingredients:v1' \\}\n */\n pathToKeyMap: Record<string, string>;\n\n /**\n * Storage instance to use. Defaults to window.localStorage.\n * Can be overridden for testing with mock storage.\n */\n storage?: Storage;\n\n /**\n * If true, automatically sync changes to localStorage on every modification.\n * If false (default), changes are only synced when syncToDisk() is called.\n */\n autoSync?: boolean;\n}\n\n/**\n * Browser localStorage-backed file tree accessors with persistence support.\n *\n * Maps filesystem-like directory paths to localStorage keys, where each key stores\n * multiple collections as a JSON object. This provides a general-purpose implementation\n * for browser-based file tree persistence without requiring File System Access API.\n *\n * Storage format per key: `{ \"collection-id\": \"<raw file content>\" }`\n * File paths map as: `/data/ingredients/collection-id.yaml` → stored in key for `/data/ingredients`\n *\n * Legacy format (v1): `{ \"collection-id\": { ...parsedJsonObject } }` is auto-migrated on load.\n *\n * @public\n */\nexport class LocalStorageTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _storage: Storage;\n private readonly _pathToKeyMap: Map<string, string>;\n private readonly _keyToPathMap: Map<string, string>;\n private readonly _dirtyFiles: Set<string>;\n private readonly _autoSync: boolean;\n\n /**\n * Private constructor. Use fromStorage() factory method instead.\n * @internal\n */\n private constructor(\n files: FileTree.IInMemoryFile<TCT>[],\n storage: Storage,\n pathToKeyMap: Map<string, string>,\n params?: ILocalStorageTreeParams<TCT>\n ) {\n super(files, params);\n this._storage = storage;\n this._pathToKeyMap = pathToKeyMap;\n this._keyToPathMap = new Map(Array.from(pathToKeyMap.entries()).map(([k, v]) => [v, k]));\n this._dirtyFiles = new Set();\n this._autoSync = params?.autoSync ?? false;\n }\n\n /**\n * Create LocalStorageTreeAccessors from browser localStorage.\n * Loads all collections from the configured storage keys.\n *\n * @param params - Configuration including path-to-key mappings\n * @returns Result containing the accessors or an error\n * @public\n */\n public static fromStorage<TCT extends string = string>(\n params: ILocalStorageTreeParams<TCT>\n ): Result<LocalStorageTreeAccessors<TCT>> {\n try {\n const storage = params.storage ?? (typeof window !== 'undefined' ? window.localStorage : undefined);\n if (!storage) {\n return fail('localStorage is not available');\n }\n\n const pathToKeyMap = new Map(Object.entries(params.pathToKeyMap));\n const files = this._loadFromStorage<TCT>(storage, pathToKeyMap, params);\n\n return succeed(new LocalStorageTreeAccessors<TCT>(files, storage, pathToKeyMap, params));\n /* c8 ignore next 4 - defensive: outer catch for unexpected errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to create LocalStorageTreeAccessors: ${message}`);\n }\n }\n\n /**\n * Load all files from localStorage based on path-to-key mappings.\n * @internal\n */\n private static _loadFromStorage<TCT extends string = string>(\n storage: Storage,\n pathToKeyMap: Map<string, string>,\n params?: ILocalStorageTreeParams<TCT>\n ): FileTree.IInMemoryFile<TCT>[] {\n const files: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const [dataPath, storageKey] of pathToKeyMap.entries()) {\n const rawJson = storage.getItem(storageKey);\n if (!rawJson) {\n continue;\n }\n\n try {\n const parsed: unknown = JSON.parse(rawJson);\n if (!isJsonObject(parsed)) {\n continue;\n }\n\n for (const [collectionId, contents] of Object.entries(parsed)) {\n // Support both new format (string values) and legacy format (JsonObject values)\n let rawContent: string;\n let extension: string;\n if (typeof contents === 'string') {\n rawContent = contents;\n // Infer extension: if content looks like JSON, use .json; otherwise .yaml\n extension = this._looksLikeJson(contents) ? '.json' : '.yaml';\n } else if (isJsonObject(contents)) {\n // Legacy format: migrate by stringifying\n rawContent = JSON.stringify(contents);\n extension = '.json';\n } else {\n continue;\n }\n\n const filePath = this._joinPath(dataPath, `${collectionId}${extension}`);\n const contentType = params?.inferContentType\n ? params.inferContentType(filePath, undefined).orDefault()\n : undefined;\n\n files.push({\n path: filePath,\n contents: rawContent,\n contentType\n });\n }\n } catch {\n // Skip corrupted data\n continue;\n }\n }\n\n return files;\n }\n\n /**\n * Heuristic check: does the content look like JSON?\n * @internal\n */\n private static _looksLikeJson(content: string): boolean {\n const trimmed = content.trimStart();\n return trimmed.startsWith('{') || trimmed.startsWith('[');\n }\n\n /**\n * Join path components, handling leading/trailing slashes.\n * @internal\n */\n private static _joinPath(base: string, name: string): string {\n const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;\n const cleanName = name.startsWith('/') ? name.slice(1) : name;\n return `${cleanBase}/${cleanName}`;\n }\n\n /**\n * Get the storage key for a given file path.\n * @internal\n */\n private _getStorageKeyForPath(path: string): string | undefined {\n // Find the longest matching prefix\n let bestMatch: { prefix: string; key: string } | undefined;\n for (const [prefix, key] of this._pathToKeyMap.entries()) {\n if (path.startsWith(prefix)) {\n if (!bestMatch || prefix.length > bestMatch.prefix.length) {\n bestMatch = { prefix, key };\n }\n }\n }\n return bestMatch?.key;\n }\n\n /**\n * Get the data path prefix for a given file path.\n * @internal\n */\n private _getDataPathForPath(path: string): string | undefined {\n for (const prefix of this._pathToKeyMap.keys()) {\n if (path.startsWith(prefix)) {\n return prefix;\n }\n }\n /* c8 ignore next 2 - coverage intermittently missed in full suite */\n return undefined;\n }\n\n /**\n * Extract collection ID from a file path.\n * Example: '/data/ingredients/my-collection.yaml' → 'my-collection'\n * @internal\n */\n private _getCollectionIdFromPath(path: string): string {\n const dataPath = this._getDataPathForPath(path);\n /* c8 ignore next 3 - coverage intermittently missed in full suite */\n if (!dataPath) {\n return path;\n }\n\n const relativePath = path.slice(dataPath.length);\n const cleanPath = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;\n\n // Remove any file extension\n const dotIndex = cleanPath.lastIndexOf('.');\n return dotIndex > 0 ? cleanPath.slice(0, dotIndex) : cleanPath;\n }\n\n /**\n * Sync a single dirty file to localStorage.\n * @internal\n */\n private _syncFile(path: string): Result<void> {\n const storageKey = this._getStorageKeyForPath(path);\n if (!storageKey) {\n return fail(`No storage key configured for path: ${path}`);\n }\n\n const collectionId = this._getCollectionIdFromPath(path);\n const contentsResult = this.getFileContents(path);\n if (contentsResult.isFailure()) {\n return fail(`Failed to get file contents for ${path}: ${contentsResult.message}`);\n }\n\n try {\n const contents = contentsResult.value;\n\n // Load existing data from storage\n const existingJson = this._storage.getItem(storageKey);\n let existing: Record<string, unknown> = {};\n if (existingJson) {\n try {\n const parsed = JSON.parse(existingJson);\n if (isJsonObject(parsed)) {\n existing = parsed as Record<string, unknown>;\n }\n } catch {\n // Start fresh if corrupted\n }\n }\n\n // Store raw content string (content-agnostic: JSON, YAML, etc.)\n existing[collectionId] = contents;\n this._storage.setItem(storageKey, JSON.stringify(existing));\n\n return succeed(undefined);\n /* c8 ignore next 4 - defensive: only triggers on storage quota or similar runtime errors */\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return fail(`Failed to sync file ${path}: ${message}`);\n }\n }\n\n /**\n * Sync all dirty files to localStorage.\n * @returns Result indicating success or failure\n * @public\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (this._dirtyFiles.size === 0) {\n return succeed(undefined);\n }\n\n const errors: string[] = [];\n for (const path of this._dirtyFiles) {\n const result = this._syncFile(path);\n if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n return fail(`Failed to sync ${errors.length} file(s): ${errors.join('; ')}`);\n }\n\n this._dirtyFiles.clear();\n return succeed(undefined);\n }\n\n /**\n * Check if there are unsaved changes.\n * @returns True if there are dirty files\n * @public\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0;\n }\n\n /**\n * Get list of file paths with unsaved changes.\n * @returns Array of dirty file paths\n * @public\n */\n public getDirtyPaths(): string[] {\n return Array.from(this._dirtyFiles);\n }\n\n /**\n * Save file contents. Marks file as dirty and optionally auto-syncs.\n * @param path - File path\n * @param contents - New file contents\n * @returns Result with the saved contents or error\n * @public\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n const result = super.saveFileContents(path, contents);\n if (result.isSuccess()) {\n this._dirtyFiles.add(path);\n if (this._autoSync) {\n const syncResult = this._syncFile(path);\n if (syncResult.isSuccess()) {\n this._dirtyFiles.delete(path);\n } else {\n return fail(syncResult.message);\n }\n }\n }\n return result;\n }\n\n /**\n * Check if a file is mutable and return persistence detail.\n * @param path - File path to check\n * @returns DetailedResult with mutability status and 'persistent' detail if mutable\n * @public\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const baseResult = super.fileIsMutable(path);\n if (baseResult.isSuccess() && baseResult.value === true) {\n return succeedWithDetail(true, 'persistent');\n }\n return baseResult;\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const createStore: jest.Mock<{}, [], any>;
|
|
2
|
+
export declare const get: jest.Mock<any, any, any>;
|
|
3
|
+
export declare const set: jest.Mock<any, any, any>;
|
|
4
|
+
export declare const del: jest.Mock<any, any, any>;
|
|
5
|
+
export declare const keys: jest.Mock<any, any, any>;
|
|
6
|
+
//# sourceMappingURL=idb-keyval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idb-keyval.d.ts","sourceRoot":"","sources":["../../../src/test/mocks/idb-keyval.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,wBAAsB,CAAC;AAC/C,eAAO,MAAM,GAAG,0BAAY,CAAC;AAC7B,eAAO,MAAM,GAAG,0BAAY,CAAC;AAC7B,eAAO,MAAM,GAAG,0BAAY,CAAC;AAC7B,eAAO,MAAM,IAAI,0BAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keys = exports.del = exports.set = exports.get = exports.createStore = void 0;
|
|
4
|
+
exports.createStore = jest.fn(() => ({}));
|
|
5
|
+
exports.get = jest.fn();
|
|
6
|
+
exports.set = jest.fn();
|
|
7
|
+
exports.del = jest.fn();
|
|
8
|
+
exports.keys = jest.fn();
|
|
9
|
+
//# sourceMappingURL=idb-keyval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idb-keyval.js","sourceRoot":"","sources":["../../../src/test/mocks/idb-keyval.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAClC,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChB,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChB,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChB,QAAA,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC","sourcesContent":["export const createStore = jest.fn(() => ({}));\nexport const get = jest.fn();\nexport const set = jest.fn();\nexport const del = jest.fn();\nexport const keys = jest.fn();\n"]}
|