@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.
Files changed (263) hide show
  1. package/dist/packlets/crypto-utils/browserCryptoProvider.js +208 -18
  2. package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
  3. package/dist/packlets/file-tree/fileApiTreeAccessors.js +1 -1
  4. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  5. package/dist/packlets/file-tree/httpTreeAccessors.js +72 -42
  6. package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -1
  7. package/dist/ts-web-extras.d.ts +59 -7
  8. package/dist/tsdoc-metadata.json +1 -1
  9. package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +52 -5
  10. package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -1
  11. package/lib/packlets/crypto-utils/browserCryptoProvider.js +207 -17
  12. package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
  13. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +1 -1
  14. package/lib/packlets/file-tree/fileApiTreeAccessors.js +1 -1
  15. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  16. package/lib/packlets/file-tree/httpTreeAccessors.d.ts +6 -0
  17. package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -1
  18. package/lib/packlets/file-tree/httpTreeAccessors.js +72 -42
  19. package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -1
  20. package/package.json +27 -26
  21. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +0 -75
  22. package/.rush/temp/chunked-rush-logs/ts-web-extras.test.chunks.jsonl +0 -75
  23. package/.rush/temp/operation/build/all.log +0 -75
  24. package/.rush/temp/operation/build/error.log +0 -18
  25. package/.rush/temp/operation/build/log-chunks.jsonl +0 -75
  26. package/.rush/temp/operation/build/state.json +0 -3
  27. package/.rush/temp/operation/test/all.log +0 -75
  28. package/.rush/temp/operation/test/error.log +0 -18
  29. package/.rush/temp/operation/test/log-chunks.jsonl +0 -75
  30. package/.rush/temp/operation/test/state.json +0 -3
  31. package/.rush/temp/shrinkwrap-deps.json +0 -635
  32. package/CHANGELOG.md +0 -23
  33. package/config/api-extractor.json +0 -343
  34. package/config/jest.config.json +0 -19
  35. package/config/rig.json +0 -16
  36. package/config/typedoc.json +0 -6
  37. package/dist/test/mocks/idb-keyval.js +0 -6
  38. package/dist/test/mocks/idb-keyval.js.map +0 -1
  39. package/dist/test/setupTests.js +0 -74
  40. package/dist/test/setupTests.js.map +0 -1
  41. package/dist/test/unit/browserHashProvider.test.js +0 -140
  42. package/dist/test/unit/browserHashProvider.test.js.map +0 -1
  43. package/dist/test/unit/directoryHandleStore.test.js +0 -190
  44. package/dist/test/unit/directoryHandleStore.test.js.map +0 -1
  45. package/dist/test/unit/fileApiTreeAccessors.test.js +0 -1188
  46. package/dist/test/unit/fileApiTreeAccessors.test.js.map +0 -1
  47. package/dist/test/unit/fileApiTypes.test.js +0 -472
  48. package/dist/test/unit/fileApiTypes.test.js.map +0 -1
  49. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +0 -622
  50. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
  51. package/dist/test/unit/fileTreeHelpers.test.js +0 -590
  52. package/dist/test/unit/fileTreeHelpers.test.js.map +0 -1
  53. package/dist/test/unit/httpTreeAccessors.test.js +0 -1229
  54. package/dist/test/unit/httpTreeAccessors.test.js.map +0 -1
  55. package/dist/test/unit/localStorageTreeAccessors.test.js +0 -812
  56. package/dist/test/unit/localStorageTreeAccessors.test.js.map +0 -1
  57. package/dist/test/unit/urlParams.test.js +0 -393
  58. package/dist/test/unit/urlParams.test.js.map +0 -1
  59. package/dist/test/utils/fileSystemAccessMocks.js +0 -271
  60. package/dist/test/utils/fileSystemAccessMocks.js.map +0 -1
  61. package/dist/test/utils/testHelpers.js +0 -124
  62. package/dist/test/utils/testHelpers.js.map +0 -1
  63. package/docs/@fgv/namespaces/CryptoUtils/README.md +0 -18
  64. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserCryptoProvider.md +0 -203
  65. package/docs/@fgv/namespaces/CryptoUtils/classes/BrowserHashProvider.md +0 -63
  66. package/docs/@fgv/namespaces/CryptoUtils/functions/createBrowserCryptoProvider.md +0 -18
  67. package/docs/@fgv/namespaces/FileTreeHelpers/README.md +0 -19
  68. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileListMetadata.md +0 -23
  69. package/docs/@fgv/namespaces/FileTreeHelpers/functions/extractFileMetadata.md +0 -23
  70. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromDirectoryUpload.md +0 -33
  71. package/docs/@fgv/namespaces/FileTreeHelpers/functions/fromFileList.md +0 -33
  72. package/docs/@fgv/namespaces/FileTreeHelpers/functions/getOriginalFile.md +0 -25
  73. package/docs/@fgv/namespaces/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +0 -11
  74. package/docs/README.md +0 -78
  75. package/docs/classes/DirectoryHandleStore.md +0 -116
  76. package/docs/classes/FileApiTreeAccessors.md +0 -286
  77. package/docs/classes/FileSystemAccessTreeAccessors.md +0 -557
  78. package/docs/classes/HttpTreeAccessors.md +0 -508
  79. package/docs/classes/LocalStorageTreeAccessors.md +0 -520
  80. package/docs/functions/exportAsJson.md +0 -23
  81. package/docs/functions/exportUsingFileSystemAPI.md +0 -26
  82. package/docs/functions/extractDirectoryPath.md +0 -23
  83. package/docs/functions/isDirectoryHandle.md +0 -23
  84. package/docs/functions/isFileHandle.md +0 -23
  85. package/docs/functions/isFilePath.md +0 -21
  86. package/docs/functions/parseContextFilter.md +0 -22
  87. package/docs/functions/parseQualifierDefaults.md +0 -22
  88. package/docs/functions/parseResourceTypes.md +0 -22
  89. package/docs/functions/parseUrlParameters.md +0 -15
  90. package/docs/functions/safeShowDirectoryPicker.md +0 -24
  91. package/docs/functions/safeShowOpenFilePicker.md +0 -24
  92. package/docs/functions/safeShowSaveFilePicker.md +0 -24
  93. package/docs/functions/supportsFileSystemAccess.md +0 -23
  94. package/docs/interfaces/FilePickerAcceptType.md +0 -16
  95. package/docs/interfaces/FileSystemCreateWritableOptions.md +0 -15
  96. package/docs/interfaces/FileSystemDirectoryHandle.md +0 -187
  97. package/docs/interfaces/FileSystemFileHandle.md +0 -106
  98. package/docs/interfaces/FileSystemGetDirectoryOptions.md +0 -15
  99. package/docs/interfaces/FileSystemGetFileOptions.md +0 -15
  100. package/docs/interfaces/FileSystemHandle.md +0 -69
  101. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +0 -15
  102. package/docs/interfaces/FileSystemRemoveOptions.md +0 -15
  103. package/docs/interfaces/FileSystemWritableFileStream.md +0 -127
  104. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +0 -17
  105. package/docs/interfaces/IFileHandleTreeInitializer.md +0 -16
  106. package/docs/interfaces/IFileListTreeInitializer.md +0 -15
  107. package/docs/interfaces/IFileMetadata.md +0 -19
  108. package/docs/interfaces/IFileSystemAccessTreeParams.md +0 -30
  109. package/docs/interfaces/IFsAccessApis.md +0 -57
  110. package/docs/interfaces/IHttpTreeParams.md +0 -32
  111. package/docs/interfaces/ILocalStorageTreeParams.md +0 -30
  112. package/docs/interfaces/IUrlConfigOptions.md +0 -27
  113. package/docs/interfaces/ShowDirectoryPickerOptions.md +0 -17
  114. package/docs/interfaces/ShowOpenFilePickerOptions.md +0 -19
  115. package/docs/interfaces/ShowSaveFilePickerOptions.md +0 -19
  116. package/docs/type-aliases/TreeInitializer.md +0 -11
  117. package/docs/type-aliases/WellKnownDirectory.md +0 -11
  118. package/docs/type-aliases/WindowWithFsAccess.md +0 -11
  119. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +0 -11
  120. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +0 -11
  121. package/etc/ts-web-extras.api.md +0 -433
  122. package/lib/test/mocks/idb-keyval.d.ts +0 -6
  123. package/lib/test/mocks/idb-keyval.d.ts.map +0 -1
  124. package/lib/test/mocks/idb-keyval.js +0 -9
  125. package/lib/test/mocks/idb-keyval.js.map +0 -1
  126. package/lib/test/setupTests.d.ts +0 -2
  127. package/lib/test/setupTests.d.ts.map +0 -1
  128. package/lib/test/setupTests.js +0 -76
  129. package/lib/test/setupTests.js.map +0 -1
  130. package/lib/test/unit/browserHashProvider.test.d.ts +0 -2
  131. package/lib/test/unit/browserHashProvider.test.d.ts.map +0 -1
  132. package/lib/test/unit/browserHashProvider.test.js +0 -142
  133. package/lib/test/unit/browserHashProvider.test.js.map +0 -1
  134. package/lib/test/unit/directoryHandleStore.test.d.ts +0 -2
  135. package/lib/test/unit/directoryHandleStore.test.d.ts.map +0 -1
  136. package/lib/test/unit/directoryHandleStore.test.js +0 -192
  137. package/lib/test/unit/directoryHandleStore.test.js.map +0 -1
  138. package/lib/test/unit/fileApiTreeAccessors.test.d.ts +0 -2
  139. package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +0 -1
  140. package/lib/test/unit/fileApiTreeAccessors.test.js +0 -1190
  141. package/lib/test/unit/fileApiTreeAccessors.test.js.map +0 -1
  142. package/lib/test/unit/fileApiTypes.test.d.ts +0 -2
  143. package/lib/test/unit/fileApiTypes.test.d.ts.map +0 -1
  144. package/lib/test/unit/fileApiTypes.test.js +0 -474
  145. package/lib/test/unit/fileApiTypes.test.js.map +0 -1
  146. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +0 -2
  147. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +0 -1
  148. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +0 -624
  149. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
  150. package/lib/test/unit/fileTreeHelpers.test.d.ts +0 -2
  151. package/lib/test/unit/fileTreeHelpers.test.d.ts.map +0 -1
  152. package/lib/test/unit/fileTreeHelpers.test.js +0 -592
  153. package/lib/test/unit/fileTreeHelpers.test.js.map +0 -1
  154. package/lib/test/unit/httpTreeAccessors.test.d.ts +0 -2
  155. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +0 -1
  156. package/lib/test/unit/httpTreeAccessors.test.js +0 -1231
  157. package/lib/test/unit/httpTreeAccessors.test.js.map +0 -1
  158. package/lib/test/unit/localStorageTreeAccessors.test.d.ts +0 -2
  159. package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +0 -1
  160. package/lib/test/unit/localStorageTreeAccessors.test.js +0 -814
  161. package/lib/test/unit/localStorageTreeAccessors.test.js.map +0 -1
  162. package/lib/test/unit/urlParams.test.d.ts +0 -2
  163. package/lib/test/unit/urlParams.test.d.ts.map +0 -1
  164. package/lib/test/unit/urlParams.test.js +0 -395
  165. package/lib/test/unit/urlParams.test.js.map +0 -1
  166. package/lib/test/utils/fileSystemAccessMocks.d.ts +0 -53
  167. package/lib/test/utils/fileSystemAccessMocks.d.ts.map +0 -1
  168. package/lib/test/utils/fileSystemAccessMocks.js +0 -277
  169. package/lib/test/utils/fileSystemAccessMocks.js.map +0 -1
  170. package/lib/test/utils/testHelpers.d.ts +0 -51
  171. package/lib/test/utils/testHelpers.d.ts.map +0 -1
  172. package/lib/test/utils/testHelpers.js +0 -133
  173. package/lib/test/utils/testHelpers.js.map +0 -1
  174. package/rush-logs/ts-web-extras.build.cache.log +0 -0
  175. package/rush-logs/ts-web-extras.build.error.log +0 -18
  176. package/rush-logs/ts-web-extras.build.log +0 -75
  177. package/rush-logs/ts-web-extras.test.cache.log +0 -1
  178. package/rush-logs/ts-web-extras.test.error.log +0 -18
  179. package/rush-logs/ts-web-extras.test.log +0 -75
  180. package/src/index.browser.ts +0 -24
  181. package/src/index.ts +0 -47
  182. package/src/packlets/crypto-utils/browserCryptoProvider.ts +0 -311
  183. package/src/packlets/crypto-utils/browserHashProvider.ts +0 -73
  184. package/src/packlets/crypto-utils/index.ts +0 -29
  185. package/src/packlets/file-api-types/index.ts +0 -366
  186. package/src/packlets/file-tree/directoryHandleStore.ts +0 -136
  187. package/src/packlets/file-tree/fileApiTreeAccessors.ts +0 -528
  188. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +0 -519
  189. package/src/packlets/file-tree/httpTreeAccessors.ts +0 -448
  190. package/src/packlets/file-tree/index.ts +0 -32
  191. package/src/packlets/file-tree/localStorageTreeAccessors.ts +0 -430
  192. package/src/packlets/helpers/fileTreeHelpers.ts +0 -107
  193. package/src/packlets/helpers/index.ts +0 -28
  194. package/src/packlets/url-utils/index.ts +0 -28
  195. package/src/packlets/url-utils/urlParams.ts +0 -245
  196. package/src/test/mocks/idb-keyval.ts +0 -5
  197. package/src/test/setupTests.ts +0 -87
  198. package/src/test/unit/browserHashProvider.test.ts +0 -155
  199. package/src/test/unit/browserHashProvider.test.ts.bak +0 -376
  200. package/src/test/unit/directoryHandleStore.test.ts +0 -251
  201. package/src/test/unit/fileApiTreeAccessors.test.ts +0 -1387
  202. package/src/test/unit/fileApiTypes.test.ts +0 -587
  203. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +0 -885
  204. package/src/test/unit/fileTreeHelpers.test.ts +0 -694
  205. package/src/test/unit/httpTreeAccessors.test.ts +0 -1571
  206. package/src/test/unit/localStorageTreeAccessors.test.ts +0 -1014
  207. package/src/test/unit/urlParams.test.ts +0 -464
  208. package/src/test/utils/fileSystemAccessMocks.ts +0 -353
  209. package/src/test/utils/testHelpers.ts +0 -155
  210. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  211. package/temp/coverage/base.css +0 -224
  212. package/temp/coverage/block-navigation.js +0 -87
  213. package/temp/coverage/crypto/browserHashProvider.ts.html +0 -304
  214. package/temp/coverage/crypto/index.html +0 -116
  215. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +0 -1018
  216. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +0 -304
  217. package/temp/coverage/crypto-utils/index.html +0 -131
  218. package/temp/coverage/favicon.png +0 -0
  219. package/temp/coverage/file-tree/directoryHandleStore.ts.html +0 -493
  220. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +0 -1669
  221. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
  222. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +0 -1429
  223. package/temp/coverage/file-tree/index.html +0 -176
  224. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +0 -1375
  225. package/temp/coverage/helpers/fileTreeHelpers.ts.html +0 -406
  226. package/temp/coverage/helpers/index.html +0 -116
  227. package/temp/coverage/index.html +0 -161
  228. package/temp/coverage/lcov-report/base.css +0 -224
  229. package/temp/coverage/lcov-report/block-navigation.js +0 -87
  230. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +0 -304
  231. package/temp/coverage/lcov-report/crypto/index.html +0 -116
  232. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +0 -1018
  233. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +0 -304
  234. package/temp/coverage/lcov-report/crypto-utils/index.html +0 -131
  235. package/temp/coverage/lcov-report/favicon.png +0 -0
  236. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +0 -493
  237. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +0 -1669
  238. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
  239. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +0 -1429
  240. package/temp/coverage/lcov-report/file-tree/index.html +0 -176
  241. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +0 -1375
  242. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +0 -406
  243. package/temp/coverage/lcov-report/helpers/index.html +0 -116
  244. package/temp/coverage/lcov-report/index.html +0 -161
  245. package/temp/coverage/lcov-report/prettify.css +0 -1
  246. package/temp/coverage/lcov-report/prettify.js +0 -2
  247. package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  248. package/temp/coverage/lcov-report/sorter.js +0 -210
  249. package/temp/coverage/lcov-report/url-utils/index.html +0 -116
  250. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +0 -820
  251. package/temp/coverage/lcov.info +0 -3597
  252. package/temp/coverage/prettify.css +0 -1
  253. package/temp/coverage/prettify.js +0 -2
  254. package/temp/coverage/sort-arrow-sprite.png +0 -0
  255. package/temp/coverage/sorter.js +0 -210
  256. package/temp/coverage/url-utils/index.html +0 -116
  257. package/temp/coverage/url-utils/urlParams.ts.html +0 -820
  258. package/temp/test/jest/haste-map-b931e4e63102f86c5bd4949f7dced44f-9d713eb41149188b4e5c0ae3d86d0a57-2ad8e16b24e391b8cdbe50b55c137169 +0 -0
  259. package/temp/test/jest/jest-transform-cache-b931e4e63102f86c5bd4949f7dced44f-79ef2876fae7ca75eedb2aa53dc48338/b5/package_b5f57afc9ec2c011239b1608ee5bdfa5 +0 -53
  260. package/temp/test/jest/perf-cache-b931e4e63102f86c5bd4949f7dced44f-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
  261. package/temp/ts-web-extras.api.json +0 -8850
  262. package/temp/ts-web-extras.api.md +0 -433
  263. package/tsconfig.json +0 -7
@@ -77,6 +77,8 @@ export class HttpTreeAccessors extends FileTree.InMemoryTreeAccessors {
77
77
  */
78
78
  async syncToDisk() {
79
79
  if (this._syncPromise) {
80
+ // Wait for the in-flight sync — it drains the queue in a loop,
81
+ // so any items added before it finishes will be included.
80
82
  return this._syncPromise;
81
83
  }
82
84
  this._syncPromise = this._doSync().finally(() => {
@@ -85,57 +87,85 @@ export class HttpTreeAccessors extends FileTree.InMemoryTreeAccessors {
85
87
  return this._syncPromise;
86
88
  }
87
89
  async _doSync() {
88
- if (this._dirtyFiles.size === 0 && this._pendingDeletions.size === 0) {
89
- return succeed(undefined);
90
- }
91
- // Snapshot and clear dirty sets so that changes arriving during
92
- // the async sync are not dropped when we finish.
93
- const deletions = new Set(this._pendingDeletions);
94
- const dirty = new Set(this._dirtyFiles);
95
- this._pendingDeletions.clear();
96
- this._dirtyFiles.clear();
97
- for (const path of deletions) {
98
- const query = new URLSearchParams();
99
- query.set('path', path);
100
- if (this._namespace) {
101
- query.set('namespace', this._namespace);
90
+ // Drain loop: keep processing as long as new items arrive.
91
+ // This is critical for bulk operations (e.g. reset) where many
92
+ // deleteFile/saveFileContents calls happen synchronously — only
93
+ // the first may be in the set when we snapshot, but the rest
94
+ // arrive during the async gaps and must be picked up before
95
+ // we return.
96
+ let didWork = false;
97
+ while (this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0) {
98
+ didWork = true;
99
+ // Snapshot and clear so that changes arriving during the async
100
+ // requests land in the live sets for the next iteration.
101
+ const deletions = new Set(this._pendingDeletions);
102
+ const dirty = new Set(this._dirtyFiles);
103
+ this._pendingDeletions.clear();
104
+ this._dirtyFiles.clear();
105
+ for (const path of deletions) {
106
+ const query = new URLSearchParams();
107
+ query.set('path', path);
108
+ if (this._namespace) {
109
+ query.set('namespace', this._namespace);
110
+ }
111
+ const deleteResult = await this._requestWithRetry(`/file?${query.toString()}`, {
112
+ method: 'DELETE'
113
+ });
114
+ if (deleteResult.isFailure()) {
115
+ this._restoreUnsynced(deletions, dirty);
116
+ return fail(`delete ${path}: ${deleteResult.message}`);
117
+ }
102
118
  }
103
- const deleteResult = await this._requestWithRetry(`/file?${query.toString()}`, {
104
- method: 'DELETE'
105
- });
106
- if (deleteResult.isFailure()) {
107
- return fail(`delete ${path}: ${deleteResult.message}`);
119
+ for (const path of dirty) {
120
+ const contentsResult = this.getFileContents(path);
121
+ if (contentsResult.isFailure()) {
122
+ this._restoreUnsynced(deletions, dirty);
123
+ return fail(`${path}: ${contentsResult.message}`);
124
+ }
125
+ const body = {
126
+ path,
127
+ contents: contentsResult.value
128
+ };
129
+ if (this._namespace) {
130
+ body.namespace = this._namespace;
131
+ }
132
+ const saveResult = await this._requestWithRetry('/file', {
133
+ method: 'PUT',
134
+ body: JSON.stringify(body)
135
+ });
136
+ if (saveResult.isFailure()) {
137
+ this._restoreUnsynced(deletions, dirty);
138
+ return fail(`sync ${path}: ${saveResult.message}`);
139
+ }
108
140
  }
109
141
  }
110
- for (const path of dirty) {
111
- const contentsResult = this.getFileContents(path);
112
- if (contentsResult.isFailure()) {
113
- return fail(`${path}: ${contentsResult.message}`);
114
- }
115
- const body = {
116
- path,
117
- contents: contentsResult.value
118
- };
142
+ if (didWork) {
143
+ const syncBody = {};
119
144
  if (this._namespace) {
120
- body.namespace = this._namespace;
145
+ syncBody.namespace = this._namespace;
121
146
  }
122
- const saveResult = await this._requestWithRetry('/file', {
123
- method: 'PUT',
124
- body: JSON.stringify(body)
147
+ const syncResult = await this._requestWithRetry('/sync', {
148
+ method: 'POST',
149
+ body: JSON.stringify(syncBody)
125
150
  });
126
- if (saveResult.isFailure()) {
127
- return fail(`sync ${path}: ${saveResult.message}`);
151
+ if (syncResult.isFailure()) {
152
+ return fail(syncResult.message);
128
153
  }
129
154
  }
130
- const syncBody = {};
131
- if (this._namespace) {
132
- syncBody.namespace = this._namespace;
155
+ return succeed(undefined);
156
+ }
157
+ /**
158
+ * Restores snapshotted items back into the live dirty sets so they
159
+ * are retried on the next sync attempt. Items that were added to
160
+ * the live sets while the sync was in flight are preserved.
161
+ */
162
+ _restoreUnsynced(deletions, dirty) {
163
+ for (const path of deletions) {
164
+ this._pendingDeletions.add(path);
165
+ }
166
+ for (const path of dirty) {
167
+ this._dirtyFiles.add(path);
133
168
  }
134
- const syncResult = await this._requestWithRetry('/sync', {
135
- method: 'POST',
136
- body: JSON.stringify(syncBody)
137
- });
138
- return syncResult.isFailure() ? fail(syncResult.message) : succeed(undefined);
139
169
  }
140
170
  /**
141
171
  * Checks if there are any dirty files that need synchronization.
@@ -1 +1 @@
1
- {"version":3,"file":"httpTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/httpTreeAccessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAkB,IAAI,EAAe,OAAO,EAAE,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AQ,EAAE,EAAE,EAC1E,aAAa,CACd,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAY,CAAA,CAAC,CAAC;QAE9C,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC5F,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,OAAO,GAAG,IAAI;gBAClB,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,IAAI,EAAE;gBACpC,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,OAAO,CAAC,IAAS,CAAC,CAAC;IAC5B,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult, fail, type Result, succeed, succeedWithDetail, Logging } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\n\ninterface IHttpStorageTreeItem {\n readonly path: string;\n readonly name: string;\n readonly type: 'file' | 'directory';\n}\n\ninterface IHttpStorageTreeChildrenResponse {\n readonly path: string;\n readonly children: ReadonlyArray<IHttpStorageTreeItem>;\n}\n\ninterface IHttpStorageFileResponse {\n readonly path: string;\n readonly contents: string;\n readonly contentType?: string;\n}\n\ninterface IHttpStorageSyncResponse {\n readonly synced: number;\n}\n\nfunction normalizeFetch(fetchImpl?: typeof fetch): typeof fetch {\n const resolved = fetchImpl ?? globalThis.fetch;\n return resolved.bind(globalThis) as typeof fetch;\n}\n\n/**\n * Configuration for creating HTTP-backed tree accessors.\n * @public\n */\nexport interface IHttpTreeParams<TCT extends string = string> extends FileTree.IFileTreeInitParams<TCT> {\n readonly baseUrl: string;\n readonly namespace?: string;\n readonly autoSync?: boolean;\n readonly fetchImpl?: typeof fetch;\n readonly userId?: string;\n readonly logger?: Logging.LogReporter<unknown>;\n}\n\n/**\n * HTTP-backed file tree accessors that cache data in memory and persist via REST API.\n * @public\n */\nexport class HttpTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _baseUrl: string;\n private readonly _namespace: string | undefined;\n private readonly _fetchImpl: typeof fetch;\n private readonly _dirtyFiles: Set<string> = new Set();\n private readonly _pendingDeletions: Set<string> = new Set();\n private readonly _autoSync: boolean;\n private readonly _userId: string | undefined;\n private readonly _logger: Logging.LogReporter<unknown>;\n\n /** Guards against concurrent syncToDisk calls (thundering herd from autoSync). */\n private _syncPromise: Promise<Result<void>> | undefined;\n\n private constructor(files: FileTree.IInMemoryFile<TCT>[], params: IHttpTreeParams<TCT>) {\n super(files, params);\n this._baseUrl = params.baseUrl.replace(/\\/$/, '');\n this._namespace = params.namespace;\n this._fetchImpl = normalizeFetch(params.fetchImpl);\n this._autoSync = params.autoSync ?? false;\n this._userId = params.userId;\n this._logger = params.logger ?? new Logging.LogReporter<unknown>();\n }\n\n private async _runAutoSyncTask(path: string): Promise<void> {\n try {\n const result = await this.syncToDisk();\n if (result.isFailure()) {\n this._logger.error(`Auto-sync failed for ${path}: ${result.message}`);\n }\n } catch (err) {\n this._logger.error(`Auto-sync threw for ${path}: ${String(err)}`);\n }\n }\n\n /**\n * Creates a new HttpTreeAccessors instance from an HTTP backend.\n * @param params - Configuration parameters for the HTTP tree accessors.\n * @returns A promise that resolves to a result containing the new HttpTreeAccessors instance or an error message.\n */\n public static async fromHttp<TCT extends string = string>(\n params: IHttpTreeParams<TCT>\n ): Promise<Result<HttpTreeAccessors<TCT>>> {\n const filesResult = await this._loadFiles<TCT>(params, '/');\n if (filesResult.isFailure()) {\n return fail(filesResult.message);\n }\n return succeed(new HttpTreeAccessors<TCT>(filesResult.value, params));\n }\n\n /**\n * Synchronizes all dirty files to the HTTP backend.\n *\n * Uses a concurrency guard: if a sync is already in progress, callers\n * await the existing operation rather than starting a parallel one.\n * This prevents the thundering herd that occurs when autoSync fires\n * for every file written during a bulk operation (e.g. restore).\n *\n * @returns A promise that resolves to a result indicating success or failure.\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (this._syncPromise) {\n return this._syncPromise;\n }\n\n this._syncPromise = this._doSync().finally(() => {\n this._syncPromise = undefined;\n });\n return this._syncPromise;\n }\n\n private async _doSync(): Promise<Result<void>> {\n if (this._dirtyFiles.size === 0 && this._pendingDeletions.size === 0) {\n return succeed(undefined);\n }\n\n // Snapshot and clear dirty sets so that changes arriving during\n // the async sync are not dropped when we finish.\n const deletions = new Set(this._pendingDeletions);\n const dirty = new Set(this._dirtyFiles);\n this._pendingDeletions.clear();\n this._dirtyFiles.clear();\n\n for (const path of deletions) {\n const query = new URLSearchParams();\n query.set('path', path);\n if (this._namespace) {\n query.set('namespace', this._namespace);\n }\n\n const deleteResult = await this._requestWithRetry<{ deleted: boolean }>(`/file?${query.toString()}`, {\n method: 'DELETE'\n });\n if (deleteResult.isFailure()) {\n return fail(`delete ${path}: ${deleteResult.message}`);\n }\n }\n\n for (const path of dirty) {\n const contentsResult = this.getFileContents(path);\n if (contentsResult.isFailure()) {\n return fail(`${path}: ${contentsResult.message}`);\n }\n\n const body: Record<string, unknown> = {\n path,\n contents: contentsResult.value\n };\n if (this._namespace) {\n body.namespace = this._namespace;\n }\n\n const saveResult = await this._requestWithRetry<IHttpStorageFileResponse>('/file', {\n method: 'PUT',\n body: JSON.stringify(body)\n });\n if (saveResult.isFailure()) {\n return fail(`sync ${path}: ${saveResult.message}`);\n }\n }\n\n const syncBody: Record<string, unknown> = {};\n if (this._namespace) {\n syncBody.namespace = this._namespace;\n }\n\n const syncResult = await this._requestWithRetry<IHttpStorageSyncResponse>('/sync', {\n method: 'POST',\n body: JSON.stringify(syncBody)\n });\n\n return syncResult.isFailure() ? fail(syncResult.message) : succeed(undefined);\n }\n\n /**\n * Checks if there are any dirty files that need synchronization.\n * @returns True if there are dirty files, false otherwise.\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;\n }\n\n /**\n * Gets the list of paths for all dirty files.\n * @returns An array of file paths that have been modified but not yet synchronized.\n */\n public getDirtyPaths(): string[] {\n return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];\n }\n\n public deleteFile(path: string): Result<boolean> {\n const result = super.deleteFile(path);\n if (result.isFailure()) {\n return result;\n }\n\n this._dirtyFiles.delete(path);\n this._pendingDeletions.add(path);\n\n if (!this._autoSync) {\n return result;\n }\n\n void this._runAutoSyncTask(path);\n return result;\n }\n\n /**\n * Saves file contents and marks the file as dirty for synchronization.\n * @param path - The path to the file.\n * @param contents - The new contents of the file.\n * @returns A result indicating success or failure.\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n const result = super.saveFileContents(path, contents);\n if (result.isFailure()) {\n return result;\n }\n\n this._dirtyFiles.add(path);\n if (!this._autoSync) {\n return result;\n }\n\n // fire-and-log-on-failure automatic sync for immediate persistence workflow\n void this._runAutoSyncTask(path);\n return result;\n }\n\n /**\n * Checks if a file is mutable (can be modified).\n * @param path - The path to the file.\n * @returns A detailed result indicating if the file is mutable and the reason.\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const result = super.fileIsMutable(path);\n if (result.isSuccess() && result.value === true) {\n return succeedWithDetail(true, 'persistent');\n }\n return result;\n }\n\n /**\n * Makes an HTTP request to the specified resource path.\n * @param resourcePath - The path to the resource.\n * @param init - Optional request initialization options.\n * @returns A promise that resolves to a result containing the response data or an error message.\n */\n private async _request<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {\n const response = await this._fetchImpl(`${this._baseUrl}${resourcePath}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(this._userId ? { 'X-User-Id': this._userId } : {}),\n /* c8 ignore next 1 - defensive coding: init.headers is never set by current callers */\n ...(init?.headers ?? {})\n },\n ...init\n }).catch((err: unknown) => ({ err } as const));\n\n if ('err' in response) {\n const message = response.err instanceof Error ? response.err.message : String(response.err);\n return fail(message);\n }\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n const message = body\n ? `HTTP ${response.status}: ${body}`\n : `HTTP ${response.status} ${response.statusText}`;\n return fail(message);\n }\n\n const json = await response.json().catch(() => undefined);\n if (json === undefined) {\n return fail('invalid JSON response');\n }\n return succeed(json as T);\n }\n\n /**\n * Wraps `_request` with retry logic for transient failures\n * (network errors, 503 service unavailable, etc.).\n */\n private async _requestWithRetry<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {\n const maxAttempts = 3;\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n const result = await this._request<T>(resourcePath, init);\n if (result.isSuccess() || attempt === maxAttempts) {\n return result;\n }\n // Retry on transient-looking errors\n const msg = result.message;\n const lowerMsg = msg.toLowerCase();\n const isTransient =\n msg.includes('503') ||\n msg.includes('502') ||\n msg.includes('429') ||\n lowerMsg.includes('disconnect') ||\n lowerMsg.includes('econnreset') ||\n lowerMsg.includes('failed to fetch') ||\n lowerMsg.includes('network');\n if (!isTransient) {\n return result;\n }\n // Exponential backoff: 500ms, 1000ms\n const delayMs = 500 * Math.pow(2, attempt - 1);\n this._logger.detail(\n `Retrying ${\n init?.method ?? 'GET'\n } ${resourcePath} after ${delayMs}ms (attempt ${attempt}/${maxAttempts})`\n );\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n /* c8 ignore next 1 - defensive coding: loop always returns */\n return fail('retry loop exited unexpectedly');\n }\n\n /**\n * Loads files from the HTTP backend for the specified directory path.\n * @param params - Configuration parameters for the HTTP tree accessors.\n * @param directoryPath - The path to the directory to load files from.\n * @returns A promise that resolves to a result containing the loaded files or an error message.\n */\n private static async _loadFiles<TCT extends string = string>(\n params: IHttpTreeParams<TCT>,\n directoryPath: string\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const childrenResult = await this._requestWithParams<IHttpStorageTreeChildrenResponse>(\n params,\n '/tree/children',\n {\n path: directoryPath,\n namespace: params.namespace\n }\n );\n if (childrenResult.isFailure()) {\n return fail(childrenResult.message);\n }\n\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const item of childrenResult.value.children) {\n if (item.type === 'directory') {\n const nestedResult = await this._loadFiles(params, item.path);\n if (nestedResult.isFailure()) {\n return fail(nestedResult.message);\n }\n allFiles.push(...nestedResult.value);\n } else {\n const fileResult = await this._requestWithParams<IHttpStorageFileResponse>(params, '/file', {\n path: item.path,\n namespace: params.namespace\n });\n if (fileResult.isFailure()) {\n return fail(fileResult.message);\n }\n\n const contentType = params.inferContentType?.(item.path, fileResult.value.contentType).orDefault();\n allFiles.push({\n path: item.path,\n contents: fileResult.value.contents,\n contentType\n });\n }\n }\n\n return succeed(allFiles);\n }\n\n /**\n * Makes an HTTP request with query parameters to the specified resource path.\n * @param params - Configuration parameters for the HTTP tree accessors.\n * @param resourcePath - The path to the resource.\n * @param query - Query parameters to include in the request.\n * @returns A promise that resolves to a result containing the response data or an error message.\n */\n private static async _requestWithParams<T>(\n params: IHttpTreeParams,\n resourcePath: string,\n query: Record<string, string | undefined>\n ): Promise<Result<T>> {\n const search = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) {\n search.set(key, value);\n }\n }\n\n const fetchImpl = normalizeFetch(params.fetchImpl);\n const userIdHeaders: RequestInit | undefined = /* c8 ignore next */ params.userId\n ? { headers: { 'X-User-Id': params.userId } }\n : undefined;\n const response = await fetchImpl(\n `${params.baseUrl.replace(/\\/$/, '')}${resourcePath}?${search.toString()}`,\n userIdHeaders\n ).catch((err: unknown) => ({ err } as const));\n\n if ('err' in response) {\n const message = response.err instanceof Error ? response.err.message : String(response.err);\n return fail(message);\n }\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n const message = body\n ? `HTTP ${response.status}: ${body}`\n : `HTTP ${response.status} ${response.statusText}`;\n return fail(message);\n }\n\n const json = await response.json().catch(() => undefined);\n if (json === undefined) {\n return fail('invalid JSON response');\n }\n\n return succeed(json as T);\n }\n}\n"]}
1
+ {"version":3,"file":"httpTreeAccessors.js","sourceRoot":"","sources":["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AC;QACvB,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,OAAO,GAAG,IAAI;gBAClB,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,IAAI,EAAE;gBACpC,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,OAAO,CAAC,IAAS,CAAC,CAAC;IAC5B,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult, fail, type Result, succeed, succeedWithDetail, Logging } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\n\ninterface IHttpStorageTreeItem {\n readonly path: string;\n readonly name: string;\n readonly type: 'file' | 'directory';\n}\n\ninterface IHttpStorageTreeChildrenResponse {\n readonly path: string;\n readonly children: ReadonlyArray<IHttpStorageTreeItem>;\n}\n\ninterface IHttpStorageFileResponse {\n readonly path: string;\n readonly contents: string;\n readonly contentType?: string;\n}\n\ninterface IHttpStorageSyncResponse {\n readonly synced: number;\n}\n\nfunction normalizeFetch(fetchImpl?: typeof fetch): typeof fetch {\n const resolved = fetchImpl ?? globalThis.fetch;\n return resolved.bind(globalThis) as typeof fetch;\n}\n\n/**\n * Configuration for creating HTTP-backed tree accessors.\n * @public\n */\nexport interface IHttpTreeParams<TCT extends string = string> extends FileTree.IFileTreeInitParams<TCT> {\n readonly baseUrl: string;\n readonly namespace?: string;\n readonly autoSync?: boolean;\n readonly fetchImpl?: typeof fetch;\n readonly userId?: string;\n readonly logger?: Logging.LogReporter<unknown>;\n}\n\n/**\n * HTTP-backed file tree accessors that cache data in memory and persist via REST API.\n * @public\n */\nexport class HttpTreeAccessors<TCT extends string = string>\n extends FileTree.InMemoryTreeAccessors<TCT>\n implements FileTree.IPersistentFileTreeAccessors<TCT>\n{\n private readonly _baseUrl: string;\n private readonly _namespace: string | undefined;\n private readonly _fetchImpl: typeof fetch;\n private readonly _dirtyFiles: Set<string> = new Set();\n private readonly _pendingDeletions: Set<string> = new Set();\n private readonly _autoSync: boolean;\n private readonly _userId: string | undefined;\n private readonly _logger: Logging.LogReporter<unknown>;\n\n /** Guards against concurrent syncToDisk calls (thundering herd from autoSync). */\n private _syncPromise: Promise<Result<void>> | undefined;\n\n private constructor(files: FileTree.IInMemoryFile<TCT>[], params: IHttpTreeParams<TCT>) {\n super(files, params);\n this._baseUrl = params.baseUrl.replace(/\\/$/, '');\n this._namespace = params.namespace;\n this._fetchImpl = normalizeFetch(params.fetchImpl);\n this._autoSync = params.autoSync ?? false;\n this._userId = params.userId;\n this._logger = params.logger ?? new Logging.LogReporter<unknown>();\n }\n\n private async _runAutoSyncTask(path: string): Promise<void> {\n try {\n const result = await this.syncToDisk();\n if (result.isFailure()) {\n this._logger.error(`Auto-sync failed for ${path}: ${result.message}`);\n }\n } catch (err) {\n this._logger.error(`Auto-sync threw for ${path}: ${String(err)}`);\n }\n }\n\n /**\n * Creates a new HttpTreeAccessors instance from an HTTP backend.\n * @param params - Configuration parameters for the HTTP tree accessors.\n * @returns A promise that resolves to a result containing the new HttpTreeAccessors instance or an error message.\n */\n public static async fromHttp<TCT extends string = string>(\n params: IHttpTreeParams<TCT>\n ): Promise<Result<HttpTreeAccessors<TCT>>> {\n const filesResult = await this._loadFiles<TCT>(params, '/');\n if (filesResult.isFailure()) {\n return fail(filesResult.message);\n }\n return succeed(new HttpTreeAccessors<TCT>(filesResult.value, params));\n }\n\n /**\n * Synchronizes all dirty files to the HTTP backend.\n *\n * Uses a concurrency guard: if a sync is already in progress, callers\n * await the existing operation rather than starting a parallel one.\n * This prevents the thundering herd that occurs when autoSync fires\n * for every file written during a bulk operation (e.g. restore).\n *\n * @returns A promise that resolves to a result indicating success or failure.\n */\n public async syncToDisk(): Promise<Result<void>> {\n if (this._syncPromise) {\n // Wait for the in-flight sync — it drains the queue in a loop,\n // so any items added before it finishes will be included.\n return this._syncPromise;\n }\n\n this._syncPromise = this._doSync().finally(() => {\n this._syncPromise = undefined;\n });\n return this._syncPromise;\n }\n\n private async _doSync(): Promise<Result<void>> {\n // Drain loop: keep processing as long as new items arrive.\n // This is critical for bulk operations (e.g. reset) where many\n // deleteFile/saveFileContents calls happen synchronously — only\n // the first may be in the set when we snapshot, but the rest\n // arrive during the async gaps and must be picked up before\n // we return.\n let didWork = false;\n while (this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0) {\n didWork = true;\n // Snapshot and clear so that changes arriving during the async\n // requests land in the live sets for the next iteration.\n const deletions = new Set(this._pendingDeletions);\n const dirty = new Set(this._dirtyFiles);\n this._pendingDeletions.clear();\n this._dirtyFiles.clear();\n\n for (const path of deletions) {\n const query = new URLSearchParams();\n query.set('path', path);\n if (this._namespace) {\n query.set('namespace', this._namespace);\n }\n\n const deleteResult = await this._requestWithRetry<{ deleted: boolean }>(`/file?${query.toString()}`, {\n method: 'DELETE'\n });\n if (deleteResult.isFailure()) {\n this._restoreUnsynced(deletions, dirty);\n return fail(`delete ${path}: ${deleteResult.message}`);\n }\n }\n\n for (const path of dirty) {\n const contentsResult = this.getFileContents(path);\n if (contentsResult.isFailure()) {\n this._restoreUnsynced(deletions, dirty);\n return fail(`${path}: ${contentsResult.message}`);\n }\n\n const body: Record<string, unknown> = {\n path,\n contents: contentsResult.value\n };\n if (this._namespace) {\n body.namespace = this._namespace;\n }\n\n const saveResult = await this._requestWithRetry<IHttpStorageFileResponse>('/file', {\n method: 'PUT',\n body: JSON.stringify(body)\n });\n if (saveResult.isFailure()) {\n this._restoreUnsynced(deletions, dirty);\n return fail(`sync ${path}: ${saveResult.message}`);\n }\n }\n }\n\n if (didWork) {\n const syncBody: Record<string, unknown> = {};\n if (this._namespace) {\n syncBody.namespace = this._namespace;\n }\n\n const syncResult = await this._requestWithRetry<IHttpStorageSyncResponse>('/sync', {\n method: 'POST',\n body: JSON.stringify(syncBody)\n });\n\n if (syncResult.isFailure()) {\n return fail(syncResult.message);\n }\n }\n return succeed(undefined);\n }\n\n /**\n * Restores snapshotted items back into the live dirty sets so they\n * are retried on the next sync attempt. Items that were added to\n * the live sets while the sync was in flight are preserved.\n */\n private _restoreUnsynced(deletions: Set<string>, dirty: Set<string>): void {\n for (const path of deletions) {\n this._pendingDeletions.add(path);\n }\n for (const path of dirty) {\n this._dirtyFiles.add(path);\n }\n }\n\n /**\n * Checks if there are any dirty files that need synchronization.\n * @returns True if there are dirty files, false otherwise.\n */\n public isDirty(): boolean {\n return this._dirtyFiles.size > 0 || this._pendingDeletions.size > 0;\n }\n\n /**\n * Gets the list of paths for all dirty files.\n * @returns An array of file paths that have been modified but not yet synchronized.\n */\n public getDirtyPaths(): string[] {\n return [...Array.from(this._dirtyFiles), ...Array.from(this._pendingDeletions)];\n }\n\n public deleteFile(path: string): Result<boolean> {\n const result = super.deleteFile(path);\n if (result.isFailure()) {\n return result;\n }\n\n this._dirtyFiles.delete(path);\n this._pendingDeletions.add(path);\n\n if (!this._autoSync) {\n return result;\n }\n\n void this._runAutoSyncTask(path);\n return result;\n }\n\n /**\n * Saves file contents and marks the file as dirty for synchronization.\n * @param path - The path to the file.\n * @param contents - The new contents of the file.\n * @returns A result indicating success or failure.\n */\n public saveFileContents(path: string, contents: string): Result<string> {\n const result = super.saveFileContents(path, contents);\n if (result.isFailure()) {\n return result;\n }\n\n this._dirtyFiles.add(path);\n if (!this._autoSync) {\n return result;\n }\n\n // fire-and-log-on-failure automatic sync for immediate persistence workflow\n void this._runAutoSyncTask(path);\n return result;\n }\n\n /**\n * Checks if a file is mutable (can be modified).\n * @param path - The path to the file.\n * @returns A detailed result indicating if the file is mutable and the reason.\n */\n public fileIsMutable(path: string): DetailedResult<boolean, FileTree.SaveDetail> {\n const result = super.fileIsMutable(path);\n if (result.isSuccess() && result.value === true) {\n return succeedWithDetail(true, 'persistent');\n }\n return result;\n }\n\n /**\n * Makes an HTTP request to the specified resource path.\n * @param resourcePath - The path to the resource.\n * @param init - Optional request initialization options.\n * @returns A promise that resolves to a result containing the response data or an error message.\n */\n private async _request<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {\n const response = await this._fetchImpl(`${this._baseUrl}${resourcePath}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(this._userId ? { 'X-User-Id': this._userId } : {}),\n /* c8 ignore next 1 - defensive coding: init.headers is never set by current callers */\n ...(init?.headers ?? {})\n },\n ...init\n }).catch((err: unknown) => ({ err } as const));\n\n if ('err' in response) {\n const message = response.err instanceof Error ? response.err.message : String(response.err);\n return fail(message);\n }\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n const message = body\n ? `HTTP ${response.status}: ${body}`\n : `HTTP ${response.status} ${response.statusText}`;\n return fail(message);\n }\n\n const json = await response.json().catch(() => undefined);\n if (json === undefined) {\n return fail('invalid JSON response');\n }\n return succeed(json as T);\n }\n\n /**\n * Wraps `_request` with retry logic for transient failures\n * (network errors, 503 service unavailable, etc.).\n */\n private async _requestWithRetry<T>(resourcePath: string, init?: RequestInit): Promise<Result<T>> {\n const maxAttempts = 3;\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n const result = await this._request<T>(resourcePath, init);\n if (result.isSuccess() || attempt === maxAttempts) {\n return result;\n }\n // Retry on transient-looking errors\n const msg = result.message;\n const lowerMsg = msg.toLowerCase();\n const isTransient =\n msg.includes('503') ||\n msg.includes('502') ||\n msg.includes('429') ||\n lowerMsg.includes('disconnect') ||\n lowerMsg.includes('econnreset') ||\n lowerMsg.includes('failed to fetch') ||\n lowerMsg.includes('network');\n if (!isTransient) {\n return result;\n }\n // Exponential backoff: 500ms, 1000ms\n const delayMs = 500 * Math.pow(2, attempt - 1);\n this._logger.detail(\n `Retrying ${\n init?.method ?? 'GET'\n } ${resourcePath} after ${delayMs}ms (attempt ${attempt}/${maxAttempts})`\n );\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n /* c8 ignore next 1 - defensive coding: loop always returns */\n return fail('retry loop exited unexpectedly');\n }\n\n /**\n * Loads files from the HTTP backend for the specified directory path.\n * @param params - Configuration parameters for the HTTP tree accessors.\n * @param directoryPath - The path to the directory to load files from.\n * @returns A promise that resolves to a result containing the loaded files or an error message.\n */\n private static async _loadFiles<TCT extends string = string>(\n params: IHttpTreeParams<TCT>,\n directoryPath: string\n ): Promise<Result<FileTree.IInMemoryFile<TCT>[]>> {\n const childrenResult = await this._requestWithParams<IHttpStorageTreeChildrenResponse>(\n params,\n '/tree/children',\n {\n path: directoryPath,\n namespace: params.namespace\n }\n );\n if (childrenResult.isFailure()) {\n return fail(childrenResult.message);\n }\n\n const allFiles: FileTree.IInMemoryFile<TCT>[] = [];\n\n for (const item of childrenResult.value.children) {\n if (item.type === 'directory') {\n const nestedResult = await this._loadFiles(params, item.path);\n if (nestedResult.isFailure()) {\n return fail(nestedResult.message);\n }\n allFiles.push(...nestedResult.value);\n } else {\n const fileResult = await this._requestWithParams<IHttpStorageFileResponse>(params, '/file', {\n path: item.path,\n namespace: params.namespace\n });\n if (fileResult.isFailure()) {\n return fail(fileResult.message);\n }\n\n const contentType = params.inferContentType?.(item.path, fileResult.value.contentType).orDefault();\n allFiles.push({\n path: item.path,\n contents: fileResult.value.contents,\n contentType\n });\n }\n }\n\n return succeed(allFiles);\n }\n\n /**\n * Makes an HTTP request with query parameters to the specified resource path.\n * @param params - Configuration parameters for the HTTP tree accessors.\n * @param resourcePath - The path to the resource.\n * @param query - Query parameters to include in the request.\n * @returns A promise that resolves to a result containing the response data or an error message.\n */\n private static async _requestWithParams<T>(\n params: IHttpTreeParams,\n resourcePath: string,\n query: Record<string, string | undefined>\n ): Promise<Result<T>> {\n const search = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) {\n search.set(key, value);\n }\n }\n\n const fetchImpl = normalizeFetch(params.fetchImpl);\n const userIdHeaders: RequestInit | undefined = /* c8 ignore next */ params.userId\n ? { headers: { 'X-User-Id': params.userId } }\n : undefined;\n const response = await fetchImpl(\n `${params.baseUrl.replace(/\\/$/, '')}${resourcePath}?${search.toString()}`,\n userIdHeaders\n ).catch((err: unknown) => ({ err } as const));\n\n if ('err' in response) {\n const message = response.err instanceof Error ? response.err.message : String(response.err);\n return fail(message);\n }\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n const message = body\n ? `HTTP ${response.status}: ${body}`\n : `HTTP ${response.status} ${response.statusText}`;\n return fail(message);\n }\n\n const json = await response.json().catch(() => undefined);\n if (json === undefined) {\n return fail('invalid JSON response');\n }\n\n return succeed(json as T);\n }\n}\n"]}
@@ -24,7 +24,7 @@ import { Result } from '@fgv/ts-utils';
24
24
  *
25
25
  * @public
26
26
  */
27
- declare class BrowserCryptoProvider implements ICryptoProvider {
27
+ declare class BrowserCryptoProvider implements CryptoUtils_2.ICryptoProvider {
28
28
  private readonly _crypto;
29
29
  /**
30
30
  * Creates a new {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider}.
@@ -37,7 +37,7 @@ declare class BrowserCryptoProvider implements ICryptoProvider {
37
37
  * @param key - 32-byte encryption key
38
38
  * @returns `Success` with encryption result, or `Failure` with an error.
39
39
  */
40
- encrypt(plaintext: string, key: Uint8Array): Promise<Result<IEncryptionResult>>;
40
+ encrypt(plaintext: string, key: Uint8Array): Promise<Result<CryptoUtils_2.IEncryptionResult>>;
41
41
  /**
42
42
  * Decrypts ciphertext using AES-256-GCM.
43
43
  * @param encryptedData - Encrypted bytes
@@ -60,6 +60,12 @@ declare class BrowserCryptoProvider implements ICryptoProvider {
60
60
  * @returns Success with derived 32-byte key, or Failure with error
61
61
  */
62
62
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
63
+ /**
64
+ * Computes a SHA-256 hash of the given data.
65
+ * @param data - UTF-8 string to hash
66
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
67
+ */
68
+ sha256(data: string): Promise<Result<string>>;
63
69
  /**
64
70
  * Generates cryptographically secure random bytes.
65
71
  * @param length - Number of bytes to generate
@@ -78,6 +84,50 @@ declare class BrowserCryptoProvider implements ICryptoProvider {
78
84
  * @returns Success with decoded bytes, or Failure if invalid base64
79
85
  */
80
86
  fromBase64(base64: string): Result<Uint8Array>;
87
+ /**
88
+ * Generates a new asymmetric keypair via Web Crypto.
89
+ * @param algorithm - The algorithm to use.
90
+ * @param extractable - Whether the resulting keys may be exported.
91
+ * @returns `Success` with the generated `CryptoKeyPair`, or `Failure` with an error.
92
+ */
93
+ generateKeyPair(algorithm: CryptoUtils_2.KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
94
+ /**
95
+ * Exports a public `CryptoKey` as a JSON Web Key.
96
+ * @remarks
97
+ * Rejects non-public keys at runtime. WebCrypto's `exportKey('jwk', ...)`
98
+ * does not enforce public-vs-private; without this guard a caller that
99
+ * passed an extractable private key would receive its private fields
100
+ * (`d`, `p`, `q`, ...) as JWK, defeating the method's name.
101
+ * @param publicKey - Extractable public key to export.
102
+ * @returns `Success` with the JWK, or `Failure` if not a public key or if export fails.
103
+ */
104
+ exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
105
+ /**
106
+ * Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
107
+ * @param jwk - The JSON Web Key produced by a prior export.
108
+ * @param algorithm - The algorithm the key was generated for.
109
+ * @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
110
+ */
111
+ importPublicKeyJwk(jwk: JsonWebKey, algorithm: CryptoUtils_2.KeyPairAlgorithm): Promise<Result<CryptoKey>>;
112
+ /**
113
+ * Wraps `plaintext` for the holder of `recipientPublicKey` using
114
+ * ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
115
+ * {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
116
+ * @param plaintext - The bytes to wrap.
117
+ * @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
118
+ * @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
119
+ * @returns `Success` with the wrapped payload, or `Failure` with an error.
120
+ */
121
+ wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: CryptoUtils_2.IWrapBytesOptions): Promise<Result<CryptoUtils_2.IWrappedBytes>>;
122
+ /**
123
+ * Unwraps a payload produced by `wrapBytes` using the recipient's private
124
+ * key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
125
+ * @param wrapped - The wrapped payload.
126
+ * @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
127
+ * @param options - HKDF salt and info matching the wrap call.
128
+ * @returns `Success` with the original `plaintext`, or `Failure` with an error.
129
+ */
130
+ unwrapBytes(wrapped: CryptoUtils_2.IWrappedBytes, recipientPrivateKey: CryptoKey, options: CryptoUtils_2.IWrapBytesOptions): Promise<Result<Uint8Array>>;
81
131
  }
82
132
 
83
133
  /**
@@ -325,7 +375,7 @@ declare function extractFileListMetadata(fileList: FileList): Array<IFileMetadat
325
375
  static getOriginalFile(fileList: FileList, targetPath: string): Result<File>;
326
376
  /**
327
377
  * Extract file metadata from a File.
328
- * @param fileList - The File to extract metadata from
378
+ * @param file - The File to extract metadata from
329
379
  * @returns The {@link IFileMetadata | file metadata}
330
380
  */
331
381
  static extractFileMetadata(file: File): IFileMetadata;
@@ -686,6 +736,12 @@ declare function extractFileListMetadata(fileList: FileList): Array<IFileMetadat
686
736
  */
687
737
  syncToDisk(): Promise<Result<void>>;
688
738
  private _doSync;
739
+ /**
740
+ * Restores snapshotted items back into the live dirty sets so they
741
+ * are retried on the next sync attempt. Items that were added to
742
+ * the live sets while the sync was in flight are preserved.
743
+ */
744
+ private _restoreUnsynced;
689
745
  /**
690
746
  * Checks if there are any dirty files that need synchronization.
691
747
  * @returns True if there are dirty files, false otherwise.
@@ -739,8 +795,6 @@ declare function extractFileListMetadata(fileList: FileList): Array<IFileMetadat
739
795
  private static _requestWithParams;
740
796
  }
741
797
 
742
- declare type ICryptoProvider = CryptoUtils_2.ICryptoProvider;
743
-
744
798
  /**
745
799
  * Tree initializer for File System Access API directory handles.
746
800
  * @public
@@ -751,8 +805,6 @@ declare function extractFileListMetadata(fileList: FileList): Array<IFileMetadat
751
805
  readonly nonRecursive?: boolean;
752
806
  }
753
807
 
754
- declare type IEncryptionResult = CryptoUtils_2.IEncryptionResult;
755
-
756
808
  /**
757
809
  * Tree initializer for File System Access API file handles.
758
810
  * @public
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.57.6"
8
+ "packageVersion": "7.57.7"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,7 +1,5 @@
1
1
  import { Result } from '@fgv/ts-utils';
2
2
  import { CryptoUtils } from '@fgv/ts-extras';
3
- type ICryptoProvider = CryptoUtils.ICryptoProvider;
4
- type IEncryptionResult = CryptoUtils.IEncryptionResult;
5
3
  /**
6
4
  * Browser implementation of `ICryptoProvider` using the Web Crypto API.
7
5
  * Uses AES-256-GCM for authenticated encryption.
@@ -11,7 +9,7 @@ type IEncryptionResult = CryptoUtils.IEncryptionResult;
11
9
  *
12
10
  * @public
13
11
  */
14
- export declare class BrowserCryptoProvider implements ICryptoProvider {
12
+ export declare class BrowserCryptoProvider implements CryptoUtils.ICryptoProvider {
15
13
  private readonly _crypto;
16
14
  /**
17
15
  * Creates a new {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider}.
@@ -24,7 +22,7 @@ export declare class BrowserCryptoProvider implements ICryptoProvider {
24
22
  * @param key - 32-byte encryption key
25
23
  * @returns `Success` with encryption result, or `Failure` with an error.
26
24
  */
27
- encrypt(plaintext: string, key: Uint8Array): Promise<Result<IEncryptionResult>>;
25
+ encrypt(plaintext: string, key: Uint8Array): Promise<Result<CryptoUtils.IEncryptionResult>>;
28
26
  /**
29
27
  * Decrypts ciphertext using AES-256-GCM.
30
28
  * @param encryptedData - Encrypted bytes
@@ -47,6 +45,12 @@ export declare class BrowserCryptoProvider implements ICryptoProvider {
47
45
  * @returns Success with derived 32-byte key, or Failure with error
48
46
  */
49
47
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
48
+ /**
49
+ * Computes a SHA-256 hash of the given data.
50
+ * @param data - UTF-8 string to hash
51
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
52
+ */
53
+ sha256(data: string): Promise<Result<string>>;
50
54
  /**
51
55
  * Generates cryptographically secure random bytes.
52
56
  * @param length - Number of bytes to generate
@@ -65,6 +69,50 @@ export declare class BrowserCryptoProvider implements ICryptoProvider {
65
69
  * @returns Success with decoded bytes, or Failure if invalid base64
66
70
  */
67
71
  fromBase64(base64: string): Result<Uint8Array>;
72
+ /**
73
+ * Generates a new asymmetric keypair via Web Crypto.
74
+ * @param algorithm - The algorithm to use.
75
+ * @param extractable - Whether the resulting keys may be exported.
76
+ * @returns `Success` with the generated `CryptoKeyPair`, or `Failure` with an error.
77
+ */
78
+ generateKeyPair(algorithm: CryptoUtils.KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
79
+ /**
80
+ * Exports a public `CryptoKey` as a JSON Web Key.
81
+ * @remarks
82
+ * Rejects non-public keys at runtime. WebCrypto's `exportKey('jwk', ...)`
83
+ * does not enforce public-vs-private; without this guard a caller that
84
+ * passed an extractable private key would receive its private fields
85
+ * (`d`, `p`, `q`, ...) as JWK, defeating the method's name.
86
+ * @param publicKey - Extractable public key to export.
87
+ * @returns `Success` with the JWK, or `Failure` if not a public key or if export fails.
88
+ */
89
+ exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
90
+ /**
91
+ * Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
92
+ * @param jwk - The JSON Web Key produced by a prior export.
93
+ * @param algorithm - The algorithm the key was generated for.
94
+ * @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
95
+ */
96
+ importPublicKeyJwk(jwk: JsonWebKey, algorithm: CryptoUtils.KeyPairAlgorithm): Promise<Result<CryptoKey>>;
97
+ /**
98
+ * Wraps `plaintext` for the holder of `recipientPublicKey` using
99
+ * ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
100
+ * {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
101
+ * @param plaintext - The bytes to wrap.
102
+ * @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
103
+ * @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
104
+ * @returns `Success` with the wrapped payload, or `Failure` with an error.
105
+ */
106
+ wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: CryptoUtils.IWrapBytesOptions): Promise<Result<CryptoUtils.IWrappedBytes>>;
107
+ /**
108
+ * Unwraps a payload produced by `wrapBytes` using the recipient's private
109
+ * key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
110
+ * @param wrapped - The wrapped payload.
111
+ * @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
112
+ * @param options - HKDF salt and info matching the wrap call.
113
+ * @returns `Success` with the original `plaintext`, or `Failure` with an error.
114
+ */
115
+ unwrapBytes(wrapped: CryptoUtils.IWrappedBytes, recipientPrivateKey: CryptoKey, options: CryptoUtils.IWrapBytesOptions): Promise<Result<Uint8Array>>;
68
116
  }
69
117
  /**
70
118
  * Creates a {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider} if Web
@@ -73,5 +121,4 @@ export declare class BrowserCryptoProvider implements ICryptoProvider {
73
121
  * @public
74
122
  */
75
123
  export declare function createBrowserCryptoProvider(): Result<BrowserCryptoProvider>;
76
- export {};
77
124
  //# sourceMappingURL=browserCryptoProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"browserCryptoProvider.d.ts","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/browserCryptoProvider.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA0B,MAAM,EAAW,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,KAAK,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACnD,KAAK,iBAAiB,GAAG,WAAW,CAAC,iBAAiB,CAAC;AAevD;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,OAAO,C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