@fluidframework/routerlicious-driver 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

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 (365) hide show
  1. package/.eslintrc.js +10 -12
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +156 -0
  4. package/README.md +39 -1
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/routerlicious-driver.api.md +108 -0
  8. package/dist/cache.cjs +30 -0
  9. package/dist/cache.cjs.map +1 -0
  10. package/dist/cache.d.ts +7 -0
  11. package/dist/cache.d.ts.map +1 -1
  12. package/dist/{definitions.js → contracts.cjs} +1 -1
  13. package/dist/contracts.cjs.map +1 -0
  14. package/dist/contracts.d.ts +42 -0
  15. package/dist/contracts.d.ts.map +1 -0
  16. package/dist/{createNewUtils.js → createNewUtils.cjs} +7 -5
  17. package/dist/createNewUtils.cjs.map +1 -0
  18. package/dist/createNewUtils.d.ts +1 -1
  19. package/dist/createNewUtils.d.ts.map +1 -1
  20. package/dist/{defaultTokenProvider.js → defaultTokenProvider.cjs} +2 -1
  21. package/dist/defaultTokenProvider.cjs.map +1 -0
  22. package/dist/defaultTokenProvider.d.ts +1 -0
  23. package/dist/defaultTokenProvider.d.ts.map +1 -1
  24. package/dist/definitions.cjs +7 -0
  25. package/dist/definitions.cjs.map +1 -0
  26. package/dist/definitions.d.ts.map +1 -1
  27. package/dist/deltaStorageService.cjs +122 -0
  28. package/dist/deltaStorageService.cjs.map +1 -0
  29. package/dist/deltaStorageService.d.ts +7 -6
  30. package/dist/deltaStorageService.d.ts.map +1 -1
  31. package/dist/{documentDeltaConnection.js → documentDeltaConnection.cjs} +8 -13
  32. package/dist/documentDeltaConnection.cjs.map +1 -0
  33. package/dist/documentDeltaConnection.d.ts +3 -4
  34. package/dist/documentDeltaConnection.d.ts.map +1 -1
  35. package/dist/{documentService.js → documentService.cjs} +61 -64
  36. package/dist/documentService.cjs.map +1 -0
  37. package/dist/documentService.d.ts +12 -4
  38. package/dist/documentService.d.ts.map +1 -1
  39. package/dist/{documentServiceFactory.js → documentServiceFactory.cjs} +87 -33
  40. package/dist/documentServiceFactory.cjs.map +1 -0
  41. package/dist/documentServiceFactory.d.ts +5 -3
  42. package/dist/documentServiceFactory.d.ts.map +1 -1
  43. package/dist/{documentStorageService.js → documentStorageService.cjs} +18 -16
  44. package/dist/documentStorageService.cjs.map +1 -0
  45. package/dist/documentStorageService.d.ts +4 -3
  46. package/dist/documentStorageService.d.ts.map +1 -1
  47. package/dist/errorUtils.cjs +87 -0
  48. package/dist/errorUtils.cjs.map +1 -0
  49. package/dist/errorUtils.d.ts +56 -10
  50. package/dist/errorUtils.d.ts.map +1 -1
  51. package/dist/gitManager.cjs +46 -0
  52. package/dist/gitManager.cjs.map +1 -0
  53. package/dist/gitManager.d.ts +27 -0
  54. package/dist/gitManager.d.ts.map +1 -0
  55. package/dist/historian.cjs +72 -0
  56. package/dist/historian.cjs.map +1 -0
  57. package/dist/historian.d.ts +34 -0
  58. package/dist/historian.d.ts.map +1 -0
  59. package/dist/index.cjs +19 -0
  60. package/dist/index.cjs.map +1 -0
  61. package/dist/index.d.ts +5 -8
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/mapWithExpiration.cjs +105 -0
  64. package/dist/mapWithExpiration.cjs.map +1 -0
  65. package/dist/mapWithExpiration.d.ts +34 -0
  66. package/dist/mapWithExpiration.d.ts.map +1 -0
  67. package/dist/{nullBlobStorageService.js → nullBlobStorageService.cjs} +5 -5
  68. package/dist/nullBlobStorageService.cjs.map +1 -0
  69. package/dist/nullBlobStorageService.d.ts.map +1 -1
  70. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  71. package/dist/packageVersion.cjs.map +1 -0
  72. package/dist/packageVersion.d.ts +1 -1
  73. package/dist/packageVersion.d.ts.map +1 -1
  74. package/dist/{policies.js → policies.cjs} +1 -1
  75. package/dist/policies.cjs.map +1 -0
  76. package/dist/policies.d.ts +22 -9
  77. package/dist/policies.d.ts.map +1 -1
  78. package/dist/r11sSnapshotParser.cjs +73 -0
  79. package/dist/r11sSnapshotParser.cjs.map +1 -0
  80. package/dist/r11sSnapshotParser.d.ts +14 -0
  81. package/dist/r11sSnapshotParser.d.ts.map +1 -0
  82. package/dist/restWrapper.cjs +249 -0
  83. package/dist/restWrapper.cjs.map +1 -0
  84. package/dist/restWrapper.d.ts +32 -12
  85. package/dist/restWrapper.d.ts.map +1 -1
  86. package/dist/restWrapperBase.cjs +89 -0
  87. package/dist/restWrapperBase.cjs.map +1 -0
  88. package/dist/restWrapperBase.d.ts +26 -0
  89. package/dist/restWrapperBase.d.ts.map +1 -0
  90. package/dist/retriableGitManager.cjs +40 -0
  91. package/dist/retriableGitManager.cjs.map +1 -0
  92. package/dist/retriableGitManager.d.ts +13 -23
  93. package/dist/retriableGitManager.d.ts.map +1 -1
  94. package/dist/routerlicious-driver-alpha.d.ts +92 -0
  95. package/dist/routerlicious-driver-beta.d.ts +98 -0
  96. package/dist/routerlicious-driver-public.d.ts +98 -0
  97. package/dist/routerlicious-driver-untrimmed.d.ts +261 -0
  98. package/dist/{shreddedSummaryDocumentStorageService.js → shreddedSummaryDocumentStorageService.cjs} +41 -34
  99. package/dist/shreddedSummaryDocumentStorageService.cjs.map +1 -0
  100. package/dist/shreddedSummaryDocumentStorageService.d.ts +6 -5
  101. package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
  102. package/dist/storageContracts.cjs +7 -0
  103. package/dist/storageContracts.cjs.map +1 -0
  104. package/dist/storageContracts.d.ts +45 -0
  105. package/dist/storageContracts.d.ts.map +1 -0
  106. package/dist/summaryTreeUploadManager.cjs +110 -0
  107. package/dist/summaryTreeUploadManager.cjs.map +1 -0
  108. package/dist/summaryTreeUploadManager.d.ts +23 -0
  109. package/dist/summaryTreeUploadManager.d.ts.map +1 -0
  110. package/dist/{tokens.js → tokens.cjs} +1 -1
  111. package/dist/tokens.cjs.map +1 -0
  112. package/dist/tokens.d.ts +34 -5
  113. package/dist/tokens.d.ts.map +1 -1
  114. package/dist/treeUtils.cjs +107 -0
  115. package/dist/treeUtils.cjs.map +1 -0
  116. package/dist/treeUtils.d.ts +58 -0
  117. package/dist/treeUtils.d.ts.map +1 -0
  118. package/dist/tsdoc-metadata.json +11 -0
  119. package/dist/{urlUtils.js → urlUtils.cjs} +21 -25
  120. package/dist/urlUtils.cjs.map +1 -0
  121. package/dist/urlUtils.d.ts +2 -2
  122. package/dist/urlUtils.d.ts.map +1 -1
  123. package/dist/wholeSummaryDocumentStorageService.cjs +253 -0
  124. package/dist/wholeSummaryDocumentStorageService.cjs.map +1 -0
  125. package/dist/wholeSummaryDocumentStorageService.d.ts +10 -8
  126. package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
  127. package/dist/wholeSummaryUploadManager.cjs +37 -0
  128. package/dist/wholeSummaryUploadManager.cjs.map +1 -0
  129. package/dist/wholeSummaryUploadManager.d.ts +16 -0
  130. package/dist/wholeSummaryUploadManager.d.ts.map +1 -0
  131. package/lib/{cache.d.ts → cache.d.mts} +7 -0
  132. package/lib/cache.d.mts.map +1 -0
  133. package/lib/cache.mjs +25 -0
  134. package/lib/cache.mjs.map +1 -0
  135. package/lib/contracts.d.mts +42 -0
  136. package/lib/contracts.d.mts.map +1 -0
  137. package/lib/{definitions.js → contracts.mjs} +1 -1
  138. package/lib/contracts.mjs.map +1 -0
  139. package/lib/{createNewUtils.d.ts → createNewUtils.d.mts} +1 -1
  140. package/lib/{createNewUtils.d.ts.map → createNewUtils.d.mts.map} +1 -1
  141. package/lib/{createNewUtils.js → createNewUtils.mjs} +7 -5
  142. package/lib/createNewUtils.mjs.map +1 -0
  143. package/lib/{defaultTokenProvider.d.ts → defaultTokenProvider.d.mts} +2 -1
  144. package/lib/defaultTokenProvider.d.mts.map +1 -0
  145. package/lib/{defaultTokenProvider.js → defaultTokenProvider.mjs} +2 -1
  146. package/lib/defaultTokenProvider.mjs.map +1 -0
  147. package/lib/definitions.d.mts.map +1 -0
  148. package/lib/definitions.mjs +6 -0
  149. package/{dist/definitions.js.map → lib/definitions.mjs.map} +1 -1
  150. package/lib/{deltaStorageService.d.ts → deltaStorageService.d.mts} +8 -7
  151. package/lib/deltaStorageService.d.mts.map +1 -0
  152. package/lib/deltaStorageService.mjs +117 -0
  153. package/lib/deltaStorageService.mjs.map +1 -0
  154. package/lib/{documentDeltaConnection.d.ts → documentDeltaConnection.d.mts} +3 -4
  155. package/lib/documentDeltaConnection.d.mts.map +1 -0
  156. package/lib/{documentDeltaConnection.js → documentDeltaConnection.mjs} +8 -13
  157. package/lib/documentDeltaConnection.mjs.map +1 -0
  158. package/lib/{documentService.d.ts → documentService.d.mts} +16 -8
  159. package/lib/documentService.d.mts.map +1 -0
  160. package/lib/{documentService.js → documentService.mjs} +60 -44
  161. package/lib/documentService.mjs.map +1 -0
  162. package/lib/{documentServiceFactory.d.ts → documentServiceFactory.d.mts} +7 -5
  163. package/lib/documentServiceFactory.d.mts.map +1 -0
  164. package/lib/{documentServiceFactory.js → documentServiceFactory.mjs} +88 -34
  165. package/lib/documentServiceFactory.mjs.map +1 -0
  166. package/lib/{documentStorageService.d.ts → documentStorageService.d.mts} +7 -6
  167. package/lib/documentStorageService.d.mts.map +1 -0
  168. package/lib/{documentStorageService.js → documentStorageService.mjs} +19 -17
  169. package/lib/documentStorageService.mjs.map +1 -0
  170. package/lib/errorUtils.d.mts +93 -0
  171. package/lib/errorUtils.d.mts.map +1 -0
  172. package/lib/errorUtils.mjs +81 -0
  173. package/lib/errorUtils.mjs.map +1 -0
  174. package/lib/gitManager.d.mts +27 -0
  175. package/lib/gitManager.d.mts.map +1 -0
  176. package/lib/gitManager.mjs +42 -0
  177. package/lib/gitManager.mjs.map +1 -0
  178. package/lib/historian.d.mts +34 -0
  179. package/lib/historian.d.mts.map +1 -0
  180. package/lib/historian.mjs +67 -0
  181. package/lib/historian.mjs.map +1 -0
  182. package/lib/index.d.mts +10 -0
  183. package/lib/index.d.mts.map +1 -0
  184. package/lib/index.mjs +8 -0
  185. package/lib/index.mjs.map +1 -0
  186. package/lib/mapWithExpiration.d.mts +34 -0
  187. package/lib/mapWithExpiration.d.mts.map +1 -0
  188. package/lib/mapWithExpiration.mjs +101 -0
  189. package/lib/mapWithExpiration.mjs.map +1 -0
  190. package/lib/nullBlobStorageService.d.mts.map +1 -0
  191. package/lib/{nullBlobStorageService.js → nullBlobStorageService.mjs} +5 -5
  192. package/lib/nullBlobStorageService.mjs.map +1 -0
  193. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
  194. package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
  195. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  196. package/lib/packageVersion.mjs.map +1 -0
  197. package/lib/{policies.d.ts → policies.d.mts} +22 -9
  198. package/lib/policies.d.mts.map +1 -0
  199. package/lib/{policies.js → policies.mjs} +1 -1
  200. package/lib/policies.mjs.map +1 -0
  201. package/lib/r11sSnapshotParser.d.mts +14 -0
  202. package/lib/r11sSnapshotParser.d.mts.map +1 -0
  203. package/lib/r11sSnapshotParser.mjs +69 -0
  204. package/lib/r11sSnapshotParser.mjs.map +1 -0
  205. package/lib/restWrapper.d.mts +53 -0
  206. package/lib/restWrapper.d.mts.map +1 -0
  207. package/lib/restWrapper.mjs +236 -0
  208. package/lib/restWrapper.mjs.map +1 -0
  209. package/lib/restWrapperBase.d.mts +26 -0
  210. package/lib/restWrapperBase.d.mts.map +1 -0
  211. package/lib/restWrapperBase.mjs +84 -0
  212. package/lib/restWrapperBase.mjs.map +1 -0
  213. package/lib/retriableGitManager.d.mts +24 -0
  214. package/lib/retriableGitManager.d.mts.map +1 -0
  215. package/lib/retriableGitManager.mjs +36 -0
  216. package/lib/retriableGitManager.mjs.map +1 -0
  217. package/lib/routerlicious-driver-alpha.d.mts +92 -0
  218. package/lib/routerlicious-driver-beta.d.mts +98 -0
  219. package/lib/routerlicious-driver-public.d.mts +98 -0
  220. package/lib/routerlicious-driver-untrimmed.d.mts +261 -0
  221. package/lib/{shreddedSummaryDocumentStorageService.d.ts → shreddedSummaryDocumentStorageService.d.mts} +9 -8
  222. package/lib/shreddedSummaryDocumentStorageService.d.mts.map +1 -0
  223. package/lib/{shreddedSummaryDocumentStorageService.js → shreddedSummaryDocumentStorageService.mjs} +41 -34
  224. package/lib/shreddedSummaryDocumentStorageService.mjs.map +1 -0
  225. package/lib/storageContracts.d.mts +45 -0
  226. package/lib/storageContracts.d.mts.map +1 -0
  227. package/lib/storageContracts.mjs +6 -0
  228. package/lib/storageContracts.mjs.map +1 -0
  229. package/lib/summaryTreeUploadManager.d.mts +23 -0
  230. package/lib/summaryTreeUploadManager.d.mts.map +1 -0
  231. package/lib/summaryTreeUploadManager.mjs +106 -0
  232. package/lib/summaryTreeUploadManager.mjs.map +1 -0
  233. package/lib/{tokens.d.ts → tokens.d.mts} +34 -5
  234. package/lib/tokens.d.mts.map +1 -0
  235. package/lib/{tokens.js → tokens.mjs} +1 -1
  236. package/lib/tokens.mjs.map +1 -0
  237. package/lib/treeUtils.d.mts +58 -0
  238. package/lib/treeUtils.d.mts.map +1 -0
  239. package/lib/treeUtils.mjs +100 -0
  240. package/lib/treeUtils.mjs.map +1 -0
  241. package/lib/{urlUtils.d.ts → urlUtils.d.mts} +2 -2
  242. package/lib/urlUtils.d.mts.map +1 -0
  243. package/lib/urlUtils.mjs +38 -0
  244. package/lib/urlUtils.mjs.map +1 -0
  245. package/lib/{wholeSummaryDocumentStorageService.d.ts → wholeSummaryDocumentStorageService.d.mts} +12 -10
  246. package/lib/wholeSummaryDocumentStorageService.d.mts.map +1 -0
  247. package/lib/wholeSummaryDocumentStorageService.mjs +249 -0
  248. package/lib/wholeSummaryDocumentStorageService.mjs.map +1 -0
  249. package/lib/wholeSummaryUploadManager.d.mts +16 -0
  250. package/lib/wholeSummaryUploadManager.d.mts.map +1 -0
  251. package/lib/wholeSummaryUploadManager.mjs +33 -0
  252. package/lib/wholeSummaryUploadManager.mjs.map +1 -0
  253. package/package.json +104 -68
  254. package/prettier.config.cjs +8 -0
  255. package/src/cache.ts +25 -9
  256. package/src/contracts.ts +60 -0
  257. package/src/createNewUtils.ts +26 -24
  258. package/src/defaultTokenProvider.ts +14 -15
  259. package/src/definitions.ts +2 -2
  260. package/src/deltaStorageService.ts +145 -91
  261. package/src/documentDeltaConnection.ts +54 -52
  262. package/src/documentService.ts +272 -242
  263. package/src/documentServiceFactory.ts +338 -237
  264. package/src/documentStorageService.ts +92 -84
  265. package/src/errorUtils.ts +117 -79
  266. package/src/gitManager.ts +67 -0
  267. package/src/historian.ts +121 -0
  268. package/src/index.ts +15 -8
  269. package/src/mapWithExpiration.ts +124 -0
  270. package/src/nullBlobStorageService.ts +24 -21
  271. package/src/packageVersion.ts +1 -1
  272. package/src/policies.ts +51 -38
  273. package/src/r11sSnapshotParser.ts +82 -0
  274. package/src/restWrapper.ts +400 -216
  275. package/src/restWrapperBase.ts +146 -0
  276. package/src/retriableGitManager.ts +76 -153
  277. package/src/shreddedSummaryDocumentStorageService.ts +214 -195
  278. package/src/storageContracts.ts +63 -0
  279. package/src/summaryTreeUploadManager.ts +155 -0
  280. package/src/tokens.ts +74 -39
  281. package/src/treeUtils.ts +138 -0
  282. package/src/urlUtils.ts +27 -28
  283. package/src/wholeSummaryDocumentStorageService.ts +352 -252
  284. package/src/wholeSummaryUploadManager.ts +64 -0
  285. package/tsc-multi.test.json +4 -0
  286. package/tsconfig.json +10 -13
  287. package/dist/cache.js +0 -20
  288. package/dist/cache.js.map +0 -1
  289. package/dist/createNewUtils.js.map +0 -1
  290. package/dist/defaultTokenProvider.js.map +0 -1
  291. package/dist/deltaStorageService.js +0 -82
  292. package/dist/deltaStorageService.js.map +0 -1
  293. package/dist/documentDeltaConnection.js.map +0 -1
  294. package/dist/documentService.js.map +0 -1
  295. package/dist/documentServiceFactory.js.map +0 -1
  296. package/dist/documentStorageService.js.map +0 -1
  297. package/dist/errorUtils.js +0 -56
  298. package/dist/errorUtils.js.map +0 -1
  299. package/dist/index.js +0 -25
  300. package/dist/index.js.map +0 -1
  301. package/dist/nullBlobStorageService.js.map +0 -1
  302. package/dist/packageVersion.js.map +0 -1
  303. package/dist/policies.js.map +0 -1
  304. package/dist/restWrapper.js +0 -153
  305. package/dist/restWrapper.js.map +0 -1
  306. package/dist/retriableGitManager.js +0 -76
  307. package/dist/retriableGitManager.js.map +0 -1
  308. package/dist/shreddedSummaryDocumentStorageService.js.map +0 -1
  309. package/dist/tokens.js.map +0 -1
  310. package/dist/urlUtils.js.map +0 -1
  311. package/dist/wholeSummaryDocumentStorageService.js +0 -191
  312. package/dist/wholeSummaryDocumentStorageService.js.map +0 -1
  313. package/lib/cache.d.ts.map +0 -1
  314. package/lib/cache.js +0 -16
  315. package/lib/cache.js.map +0 -1
  316. package/lib/createNewUtils.js.map +0 -1
  317. package/lib/defaultTokenProvider.d.ts.map +0 -1
  318. package/lib/defaultTokenProvider.js.map +0 -1
  319. package/lib/definitions.d.ts.map +0 -1
  320. package/lib/definitions.js.map +0 -1
  321. package/lib/deltaStorageService.d.ts.map +0 -1
  322. package/lib/deltaStorageService.js +0 -77
  323. package/lib/deltaStorageService.js.map +0 -1
  324. package/lib/documentDeltaConnection.d.ts.map +0 -1
  325. package/lib/documentDeltaConnection.js.map +0 -1
  326. package/lib/documentService.d.ts.map +0 -1
  327. package/lib/documentService.js.map +0 -1
  328. package/lib/documentServiceFactory.d.ts.map +0 -1
  329. package/lib/documentServiceFactory.js.map +0 -1
  330. package/lib/documentStorageService.d.ts.map +0 -1
  331. package/lib/documentStorageService.js.map +0 -1
  332. package/lib/errorUtils.d.ts +0 -47
  333. package/lib/errorUtils.d.ts.map +0 -1
  334. package/lib/errorUtils.js +0 -50
  335. package/lib/errorUtils.js.map +0 -1
  336. package/lib/index.d.ts +0 -13
  337. package/lib/index.d.ts.map +0 -1
  338. package/lib/index.js +0 -13
  339. package/lib/index.js.map +0 -1
  340. package/lib/nullBlobStorageService.d.ts.map +0 -1
  341. package/lib/nullBlobStorageService.js.map +0 -1
  342. package/lib/packageVersion.js.map +0 -1
  343. package/lib/policies.d.ts.map +0 -1
  344. package/lib/policies.js.map +0 -1
  345. package/lib/restWrapper.d.ts +0 -33
  346. package/lib/restWrapper.d.ts.map +0 -1
  347. package/lib/restWrapper.js +0 -144
  348. package/lib/restWrapper.js.map +0 -1
  349. package/lib/retriableGitManager.d.ts +0 -34
  350. package/lib/retriableGitManager.d.ts.map +0 -1
  351. package/lib/retriableGitManager.js +0 -72
  352. package/lib/retriableGitManager.js.map +0 -1
  353. package/lib/shreddedSummaryDocumentStorageService.d.ts.map +0 -1
  354. package/lib/shreddedSummaryDocumentStorageService.js.map +0 -1
  355. package/lib/tokens.d.ts.map +0 -1
  356. package/lib/tokens.js.map +0 -1
  357. package/lib/urlUtils.d.ts.map +0 -1
  358. package/lib/urlUtils.js +0 -42
  359. package/lib/urlUtils.js.map +0 -1
  360. package/lib/wholeSummaryDocumentStorageService.d.ts.map +0 -1
  361. package/lib/wholeSummaryDocumentStorageService.js +0 -187
  362. package/lib/wholeSummaryDocumentStorageService.js.map +0 -1
  363. package/tsconfig.esnext.json +0 -7
  364. /package/lib/{definitions.d.ts → definitions.d.mts} +0 -0
  365. /package/lib/{nullBlobStorageService.d.ts → nullBlobStorageService.d.mts} +0 -0
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.validateBlobsAndTrees = exports.evalBlobsAndTrees = exports.convertSnapshotAndBlobsToSummaryTree = exports.SummaryTreeAssembler = void 0;
8
+ const client_utils_1 = require("@fluid-internal/client-utils");
9
+ const core_utils_1 = require("@fluidframework/core-utils");
10
+ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
11
+ /**
12
+ * Summary tree assembler (without stats collection).
13
+ */
14
+ class SummaryTreeAssembler {
15
+ constructor(props) {
16
+ this.props = props;
17
+ this.attachmentCounter = 0;
18
+ this.summaryTree = {};
19
+ }
20
+ /**
21
+ * Get final summary
22
+ */
23
+ get summary() {
24
+ return {
25
+ type: protocol_definitions_1.SummaryType.Tree,
26
+ tree: { ...this.summaryTree },
27
+ unreferenced: this.props?.unreferenced,
28
+ };
29
+ }
30
+ /**
31
+ * Add blob to summary
32
+ */
33
+ addBlob(key, content) {
34
+ this.summaryTree[key] = {
35
+ type: protocol_definitions_1.SummaryType.Blob,
36
+ content,
37
+ };
38
+ }
39
+ /**
40
+ * Add handle to summary
41
+ */
42
+ addHandle(key, handleType, handle) {
43
+ this.summaryTree[key] = {
44
+ type: protocol_definitions_1.SummaryType.Handle,
45
+ handleType,
46
+ handle,
47
+ };
48
+ }
49
+ /**
50
+ * Add tree to summary
51
+ */
52
+ addTree(key, summary) {
53
+ this.summaryTree[key] = summary;
54
+ }
55
+ /**
56
+ * Add attachment to summary
57
+ */
58
+ addAttachment(id) {
59
+ this.summaryTree[this.attachmentCounter++] = { id, type: protocol_definitions_1.SummaryType.Attachment };
60
+ }
61
+ }
62
+ exports.SummaryTreeAssembler = SummaryTreeAssembler;
63
+ /**
64
+ * Helper function that converts ISnapshotTree and blobs to ISummaryTree
65
+ * @param snapshot - Source snapshot tree
66
+ * @param blobs - Blobs cache
67
+ * @returns Converted snapshot in ISummaryTree format
68
+ */
69
+ function convertSnapshotAndBlobsToSummaryTree(snapshot, blobs) {
70
+ const assembler = new SummaryTreeAssembler({
71
+ unreferenced: snapshot.unreferenced,
72
+ });
73
+ for (const [path, id] of Object.entries(snapshot.blobs)) {
74
+ const blob = blobs.get(id);
75
+ (0, core_utils_1.assert)(blob !== undefined, 0x2dd /* "Cannot find blob for a given id" */);
76
+ assembler.addBlob(path, client_utils_1.IsoBuffer.from(blob).toString("utf-8"));
77
+ }
78
+ for (const [key, tree] of Object.entries(snapshot.trees)) {
79
+ const subtree = convertSnapshotAndBlobsToSummaryTree(tree, blobs);
80
+ assembler.addTree(key, subtree);
81
+ }
82
+ return assembler.summary;
83
+ }
84
+ exports.convertSnapshotAndBlobsToSummaryTree = convertSnapshotAndBlobsToSummaryTree;
85
+ function evalBlobsAndTrees(snapshot) {
86
+ const trees = countTreesInSnapshotTree(snapshot.snapshotTree);
87
+ const numBlobs = snapshot.blobs.size;
88
+ let encodedBlobsSize = 0;
89
+ for (const [_, blobContent] of snapshot.blobs) {
90
+ encodedBlobsSize += blobContent.byteLength;
91
+ }
92
+ return { trees, numBlobs, encodedBlobsSize };
93
+ }
94
+ exports.evalBlobsAndTrees = evalBlobsAndTrees;
95
+ function validateBlobsAndTrees(snapshot) {
96
+ (0, core_utils_1.assert)(snapshot.trees !== undefined, 0x5d0 /* Returned r11s snapshot is malformed. No trees! */);
97
+ (0, core_utils_1.assert)(snapshot.blobs !== undefined, 0x5d1 /* Returned r11s snapshot is malformed. No blobs! */);
98
+ }
99
+ exports.validateBlobsAndTrees = validateBlobsAndTrees;
100
+ function countTreesInSnapshotTree(snapshotTree) {
101
+ let numTrees = 0;
102
+ for (const [_, tree] of Object.entries(snapshotTree.trees)) {
103
+ numTrees += 1 + countTreesInSnapshotTree(tree);
104
+ }
105
+ return numTrees;
106
+ }
107
+ //# sourceMappingURL=treeUtils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeUtils.cjs","sourceRoot":"","sources":["../src/treeUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAyD;AACzD,2DAAoD;AACpD,+EAK8C;AAa9C;;GAEG;AACH,MAAa,oBAAoB;IAIhC,YAA6B,KAAkC;QAAlC,UAAK,GAAL,KAAK,CAA6B;QAHvD,sBAAiB,GAAW,CAAC,CAAC;QACrB,gBAAW,GAAsC,EAAE,CAAC;IAEH,CAAC;IAEnE;;OAEG;IACH,IAAW,OAAO;QACjB,OAAO;YACN,IAAI,EAAE,kCAAW,CAAC,IAAI;YACtB,IAAI,EAAE,EAAE,GA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AC,KAAK,CAAC,EAAE;QAC3D,QAAQ,IAAI,CAAC,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;KAC/C;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tSummaryType,\n\tISnapshotTree,\n\tISummaryTree,\n\tSummaryObject,\n} from \"@fluidframework/protocol-definitions\";\nimport { INormalizedWholeSnapshot } from \"./contracts\";\n\n/**\n * Summary tree assembler props\n */\nexport interface ISummaryTreeAssemblerProps {\n\t/**\n\t * Indicates that this tree is unreferenced. If this is not present, the tree is considered referenced.\n\t */\n\tunreferenced?: true;\n}\n\n/**\n * Summary tree assembler (without stats collection).\n */\nexport class SummaryTreeAssembler {\n\tprivate attachmentCounter: number = 0;\n\tprivate readonly summaryTree: { [path: string]: SummaryObject } = {};\n\n\tconstructor(private readonly props?: ISummaryTreeAssemblerProps) {}\n\n\t/**\n\t * Get final summary\n\t */\n\tpublic get summary(): ISummaryTree {\n\t\treturn {\n\t\t\ttype: SummaryType.Tree,\n\t\t\ttree: { ...this.summaryTree },\n\t\t\tunreferenced: this.props?.unreferenced,\n\t\t};\n\t}\n\n\t/**\n\t * Add blob to summary\n\t */\n\tpublic addBlob(key: string, content: string | Uint8Array): void {\n\t\tthis.summaryTree[key] = {\n\t\t\ttype: SummaryType.Blob,\n\t\t\tcontent,\n\t\t};\n\t}\n\n\t/**\n\t * Add handle to summary\n\t */\n\tpublic addHandle(\n\t\tkey: string,\n\t\thandleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment,\n\t\thandle: string,\n\t): void {\n\t\tthis.summaryTree[key] = {\n\t\t\ttype: SummaryType.Handle,\n\t\t\thandleType,\n\t\t\thandle,\n\t\t};\n\t}\n\n\t/**\n\t * Add tree to summary\n\t */\n\tpublic addTree(key: string, summary: ISummaryTree): void {\n\t\tthis.summaryTree[key] = summary;\n\t}\n\n\t/**\n\t * Add attachment to summary\n\t */\n\tpublic addAttachment(id: string) {\n\t\tthis.summaryTree[this.attachmentCounter++] = { id, type: SummaryType.Attachment };\n\t}\n}\n\n/**\n * Helper function that converts ISnapshotTree and blobs to ISummaryTree\n * @param snapshot - Source snapshot tree\n * @param blobs - Blobs cache\n * @returns Converted snapshot in ISummaryTree format\n */\nexport function convertSnapshotAndBlobsToSummaryTree(\n\tsnapshot: ISnapshotTree,\n\tblobs: Map<string, ArrayBuffer>,\n): ISummaryTree {\n\tconst assembler = new SummaryTreeAssembler({\n\t\tunreferenced: snapshot.unreferenced,\n\t});\n\tfor (const [path, id] of Object.entries(snapshot.blobs)) {\n\t\tconst blob = blobs.get(id);\n\t\tassert(blob !== undefined, 0x2dd /* \"Cannot find blob for a given id\" */);\n\t\tassembler.addBlob(path, IsoBuffer.from(blob).toString(\"utf-8\"));\n\t}\n\tfor (const [key, tree] of Object.entries(snapshot.trees)) {\n\t\tconst subtree = convertSnapshotAndBlobsToSummaryTree(tree, blobs);\n\t\tassembler.addTree(key, subtree);\n\t}\n\treturn assembler.summary;\n}\n\nexport function evalBlobsAndTrees(snapshot: INormalizedWholeSnapshot) {\n\tconst trees = countTreesInSnapshotTree(snapshot.snapshotTree);\n\tconst numBlobs = snapshot.blobs.size;\n\tlet encodedBlobsSize = 0;\n\tfor (const [_, blobContent] of snapshot.blobs) {\n\t\tencodedBlobsSize += blobContent.byteLength;\n\t}\n\treturn { trees, numBlobs, encodedBlobsSize };\n}\n\nexport function validateBlobsAndTrees(snapshot: ISnapshotTree) {\n\tassert(\n\t\tsnapshot.trees !== undefined,\n\t\t0x5d0 /* Returned r11s snapshot is malformed. No trees! */,\n\t);\n\tassert(\n\t\tsnapshot.blobs !== undefined,\n\t\t0x5d1 /* Returned r11s snapshot is malformed. No blobs! */,\n\t);\n}\n\nfunction countTreesInSnapshotTree(snapshotTree: ISnapshotTree): number {\n\tlet numTrees = 0;\n\tfor (const [_, tree] of Object.entries(snapshotTree.trees)) {\n\t\tnumTrees += 1 + countTreesInSnapshotTree(tree);\n\t}\n\treturn numTrees;\n}\n"]}
@@ -0,0 +1,58 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { SummaryType, ISnapshotTree, ISummaryTree } from "@fluidframework/protocol-definitions";
6
+ import { INormalizedWholeSnapshot } from "./contracts";
7
+ /**
8
+ * Summary tree assembler props
9
+ */
10
+ export interface ISummaryTreeAssemblerProps {
11
+ /**
12
+ * Indicates that this tree is unreferenced. If this is not present, the tree is considered referenced.
13
+ */
14
+ unreferenced?: true;
15
+ }
16
+ /**
17
+ * Summary tree assembler (without stats collection).
18
+ */
19
+ export declare class SummaryTreeAssembler {
20
+ private readonly props?;
21
+ private attachmentCounter;
22
+ private readonly summaryTree;
23
+ constructor(props?: ISummaryTreeAssemblerProps | undefined);
24
+ /**
25
+ * Get final summary
26
+ */
27
+ get summary(): ISummaryTree;
28
+ /**
29
+ * Add blob to summary
30
+ */
31
+ addBlob(key: string, content: string | Uint8Array): void;
32
+ /**
33
+ * Add handle to summary
34
+ */
35
+ addHandle(key: string, handleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment, handle: string): void;
36
+ /**
37
+ * Add tree to summary
38
+ */
39
+ addTree(key: string, summary: ISummaryTree): void;
40
+ /**
41
+ * Add attachment to summary
42
+ */
43
+ addAttachment(id: string): void;
44
+ }
45
+ /**
46
+ * Helper function that converts ISnapshotTree and blobs to ISummaryTree
47
+ * @param snapshot - Source snapshot tree
48
+ * @param blobs - Blobs cache
49
+ * @returns Converted snapshot in ISummaryTree format
50
+ */
51
+ export declare function convertSnapshotAndBlobsToSummaryTree(snapshot: ISnapshotTree, blobs: Map<string, ArrayBuffer>): ISummaryTree;
52
+ export declare function evalBlobsAndTrees(snapshot: INormalizedWholeSnapshot): {
53
+ trees: number;
54
+ numBlobs: number;
55
+ encodedBlobsSize: number;
56
+ };
57
+ export declare function validateBlobsAndTrees(snapshot: ISnapshotTree): void;
58
+ //# sourceMappingURL=treeUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeUtils.d.ts","sourceRoot":"","sources":["../src/treeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,WAAW,EACX,aAAa,EACb,YAAY,EAEZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAIpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IAHnC,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyC;gBAExC,KAAK,CAAC,wCAA4B;IAE/D;;OAEG;IACH,IAAW,OAAO,IAAI,YAAY,CAMjC;IAED;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAO/D;;OAEG;IACI,SAAS,CACf,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,UAAU,EACxE,MAAM,EAAE,MAAM,GACZ,IAAI;IAQP;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIxD;;OAEG;IACI,aAAa,CAAC,EAAE,EAAE,MAAM;CAG/B;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CACnD,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAC7B,YAAY,CAcd;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,wBAAwB;;;;EAQnE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,QAS5D"}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.38.3"
9
+ }
10
+ ]
11
+ }
@@ -22,30 +22,26 @@ exports.parseFluidUrl = parseFluidUrl;
22
22
  const replaceDocumentIdInPath = (urlPath, documentId) => urlPath.split("/").slice(0, -1).concat([documentId]).join("/");
23
23
  exports.replaceDocumentIdInPath = replaceDocumentIdInPath;
24
24
  const getDiscoveredFluidResolvedUrl = (resolvedUrl, session) => {
25
- if (session) {
26
- const discoveredOrdererUrl = new url_parse_1.default(session.ordererUrl);
27
- const deltaStorageUrl = new url_parse_1.default(resolvedUrl.endpoints.deltaStorageUrl);
28
- deltaStorageUrl.set("host", discoveredOrdererUrl.host);
29
- const discoveredStorageUrl = new url_parse_1.default(session.historianUrl);
30
- const storageUrl = new url_parse_1.default(resolvedUrl.endpoints.storageUrl);
31
- storageUrl.set("host", discoveredStorageUrl.host);
32
- const parsedUrl = (0, exports.parseFluidUrl)(resolvedUrl.url);
33
- const discoveredResolvedUrl = {
34
- endpoints: {
35
- deltaStorageUrl: deltaStorageUrl.toString(),
36
- ordererUrl: session.ordererUrl,
37
- storageUrl: storageUrl.toString(),
38
- },
39
- id: resolvedUrl.id,
40
- tokens: resolvedUrl.tokens,
41
- type: resolvedUrl.type,
42
- url: new url_parse_1.default(`fluid://${discoveredOrdererUrl.host}${parsedUrl.pathname}`).toString(),
43
- };
44
- return discoveredResolvedUrl;
45
- }
46
- else {
47
- return resolvedUrl;
48
- }
25
+ const discoveredOrdererUrl = new url_parse_1.default(session.ordererUrl);
26
+ const deltaStorageUrl = new url_parse_1.default(resolvedUrl.endpoints.deltaStorageUrl);
27
+ deltaStorageUrl.set("host", discoveredOrdererUrl.host);
28
+ const discoveredStorageUrl = new url_parse_1.default(session.historianUrl);
29
+ const storageUrl = new url_parse_1.default(resolvedUrl.endpoints.storageUrl);
30
+ storageUrl.set("host", discoveredStorageUrl.host);
31
+ const parsedUrl = (0, exports.parseFluidUrl)(resolvedUrl.url);
32
+ const discoveredResolvedUrl = {
33
+ endpoints: {
34
+ deltaStorageUrl: deltaStorageUrl.toString(),
35
+ ordererUrl: session.ordererUrl,
36
+ deltaStreamUrl: session.deltaStreamUrl,
37
+ storageUrl: storageUrl.toString(),
38
+ },
39
+ id: resolvedUrl.id,
40
+ tokens: resolvedUrl.tokens,
41
+ type: resolvedUrl.type,
42
+ url: new url_parse_1.default(`fluid://${discoveredOrdererUrl.host}${parsedUrl.pathname}`).toString(),
43
+ };
44
+ return discoveredResolvedUrl;
49
45
  };
50
46
  exports.getDiscoveredFluidResolvedUrl = getDiscoveredFluidResolvedUrl;
51
- //# sourceMappingURL=urlUtils.js.map
47
+ //# sourceMappingURL=urlUtils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlUtils.cjs","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,0DAAiC;AAG1B,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAY,EAAE;IAC3D,OAAO,IAAI,mBAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB;AAEF;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,UAAkB,EAAU,EAAE,CACtF,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AADnD,QA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MIT License.\n */\n\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport URLParse from \"url-parse\";\nimport { ISession } from \"@fluidframework/server-services-client\";\n\nexport const parseFluidUrl = (fluidUrl: string): URLParse => {\n\treturn new URLParse(fluidUrl, true);\n};\n\n/**\n * Assume documentId is at end of url path.\n * This is true for Routerlicious' and Tinylicious' documentUrl and deltaStorageUrl.\n * Routerlicious and Tinylicious do not use documentId in storageUrl nor ordererUrl.\n * TODO: Ideally we would be able to regenerate the resolvedUrl, rather than patching the current one.\n */\nexport const replaceDocumentIdInPath = (urlPath: string, documentId: string): string =>\n\turlPath.split(\"/\").slice(0, -1).concat([documentId]).join(\"/\");\n\nexport const getDiscoveredFluidResolvedUrl = (\n\tresolvedUrl: IResolvedUrl,\n\tsession: ISession,\n): IResolvedUrl => {\n\tconst discoveredOrdererUrl = new URLParse(session.ordererUrl);\n\tconst deltaStorageUrl = new URLParse(resolvedUrl.endpoints.deltaStorageUrl);\n\tdeltaStorageUrl.set(\"host\", discoveredOrdererUrl.host);\n\n\tconst discoveredStorageUrl = new URLParse(session.historianUrl);\n\tconst storageUrl = new URLParse(resolvedUrl.endpoints.storageUrl);\n\tstorageUrl.set(\"host\", discoveredStorageUrl.host);\n\n\tconst parsedUrl = parseFluidUrl(resolvedUrl.url);\n\tconst discoveredResolvedUrl: IResolvedUrl = {\n\t\tendpoints: {\n\t\t\tdeltaStorageUrl: deltaStorageUrl.toString(),\n\t\t\tordererUrl: session.ordererUrl,\n\t\t\tdeltaStreamUrl: session.deltaStreamUrl,\n\t\t\tstorageUrl: storageUrl.toString(),\n\t\t},\n\t\tid: resolvedUrl.id,\n\t\ttokens: resolvedUrl.tokens,\n\t\ttype: resolvedUrl.type,\n\t\turl: new URLParse(`fluid://${discoveredOrdererUrl.host}${parsedUrl.pathname}`).toString(),\n\t};\n\treturn discoveredResolvedUrl;\n};\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidResolvedUrl } from "@fluidframework/driver-definitions";
5
+ import { IResolvedUrl } from "@fluidframework/driver-definitions";
6
6
  import URLParse from "url-parse";
7
7
  import { ISession } from "@fluidframework/server-services-client";
8
8
  export declare const parseFluidUrl: (fluidUrl: string) => URLParse;
@@ -13,5 +13,5 @@ export declare const parseFluidUrl: (fluidUrl: string) => URLParse;
13
13
  * TODO: Ideally we would be able to regenerate the resolvedUrl, rather than patching the current one.
14
14
  */
15
15
  export declare const replaceDocumentIdInPath: (urlPath: string, documentId: string) => string;
16
- export declare const getDiscoveredFluidResolvedUrl: (resolvedUrl: IFluidResolvedUrl, session: ISession) => IFluidResolvedUrl;
16
+ export declare const getDiscoveredFluidResolvedUrl: (resolvedUrl: IResolvedUrl, session: ISession) => IResolvedUrl;
17
17
  //# sourceMappingURL=urlUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAElE,eAAO,MAAM,aAAa,aAAc,MAAM,KAAG,QAEhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,YAAa,MAAM,cAAc,MAAM,KAAG,MACZ,CAAC;AAEnE,eAAO,MAAM,6BAA6B,gBAAiB,iBAAiB,WAAW,QAAQ,KAAG,iBA2BjG,CAAC"}
1
+ {"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAElE,eAAO,MAAM,aAAa,aAAc,MAAM,KAAG,QAEhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,YAAa,MAAM,cAAc,MAAM,KAAG,MACf,CAAC;AAEhE,eAAO,MAAM,6BAA6B,gBAC5B,YAAY,WAChB,QAAQ,KACf,YAuBF,CAAC"}
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.WholeSummaryDocumentStorageService = void 0;
8
+ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
9
+ const client_utils_1 = require("@fluid-internal/client-utils");
10
+ const core_utils_1 = require("@fluidframework/core-utils");
11
+ const driver_base_1 = require("@fluidframework/driver-base");
12
+ const cache_1 = require("./cache.cjs");
13
+ const treeUtils_1 = require("./treeUtils.cjs");
14
+ const wholeSummaryUploadManager_1 = require("./wholeSummaryUploadManager.cjs");
15
+ const r11sSnapshotParser_1 = require("./r11sSnapshotParser.cjs");
16
+ const latestSnapshotId = "latest";
17
+ class WholeSummaryDocumentStorageService {
18
+ async getSummaryUploadManager() {
19
+ const manager = await this.getStorageManager();
20
+ return new wholeSummaryUploadManager_1.WholeSummaryUploadManager(manager);
21
+ }
22
+ constructor(id, manager, logger, policies, driverPolicies, blobCache = new cache_1.InMemoryCache(), snapshotTreeCache = new cache_1.InMemoryCache(), noCacheGitManager, getStorageManager = async (disableCache) => disableCache && this.noCacheGitManager !== undefined
23
+ ? this.noCacheGitManager
24
+ : this.manager) {
25
+ this.id = id;
26
+ this.manager = manager;
27
+ this.logger = logger;
28
+ this.policies = policies;
29
+ this.driverPolicies = driverPolicies;
30
+ this.blobCache = blobCache;
31
+ this.snapshotTreeCache = snapshotTreeCache;
32
+ this.noCacheGitManager = noCacheGitManager;
33
+ this.getStorageManager = getStorageManager;
34
+ this.firstVersionsCall = true;
35
+ this.repositoryUrl = "";
36
+ this.mc = (0, telemetry_utils_1.createChildMonitoringContext)({
37
+ logger,
38
+ });
39
+ }
40
+ // eslint-disable-next-line @rushstack/no-new-null
41
+ async getVersions(versionId, count) {
42
+ if (versionId !== this.id && versionId !== null) {
43
+ // Blobs/Trees in this scenario will never have multiple versions, so return versionId as is
44
+ return [
45
+ {
46
+ id: versionId,
47
+ treeId: undefined,
48
+ },
49
+ ];
50
+ }
51
+ // If this is the first versions call for the document, we know we will want the latest summary.
52
+ // Fetch latest summary, cache it, and return its id.
53
+ if (this.firstVersionsCall && count === 1) {
54
+ const normalizedSnapshotContents = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
55
+ eventName: "ObtainSnapshot",
56
+ versionId: versionId ?? undefined,
57
+ count,
58
+ enableDiscovery: this.driverPolicies?.enableDiscovery,
59
+ }, async (event) => {
60
+ let method;
61
+ const cachedSnapshotP = this.snapshotTreeCache.get(this.getCacheKey(latestSnapshotId));
62
+ const networkSnapshotP = !this.driverPolicies?.enableDiscovery
63
+ ? this.fetchSnapshotTree(latestSnapshotId, false, "getVersions")
64
+ : this.fetchSnapshotTree(latestSnapshotId, true, "getVersions");
65
+ const promiseRaceWinner = await (0, driver_base_1.promiseRaceWithWinner)([
66
+ cachedSnapshotP.catch(() => undefined),
67
+ networkSnapshotP.catch(() => undefined),
68
+ ]);
69
+ let retrievedSnapshot = promiseRaceWinner.value;
70
+ method = promiseRaceWinner.index === 0 ? "cache" : "network";
71
+ if (retrievedSnapshot === undefined) {
72
+ // if network failed -> wait for cache ( then return network failure)
73
+ // If cache returned empty or failed -> wait for network (success of failure)
74
+ if (promiseRaceWinner.index === 1) {
75
+ retrievedSnapshot = await cachedSnapshotP;
76
+ method = "cache";
77
+ }
78
+ if (retrievedSnapshot === undefined) {
79
+ retrievedSnapshot = await networkSnapshotP;
80
+ method = "network";
81
+ }
82
+ }
83
+ event.end({
84
+ method,
85
+ });
86
+ return retrievedSnapshot;
87
+ });
88
+ const _id = await this.initializeFromSnapshot(normalizedSnapshotContents);
89
+ this.firstVersionsCall = false;
90
+ return [
91
+ {
92
+ id: _id,
93
+ treeId: normalizedSnapshotContents.snapshotTree.id,
94
+ },
95
+ ];
96
+ }
97
+ // Otherwise, get the latest version of the document as normal.
98
+ const id = versionId ? versionId : this.id;
99
+ const commits = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
100
+ eventName: "getVersions",
101
+ versionId: id,
102
+ count,
103
+ }, async () => {
104
+ const manager = await this.getStorageManager();
105
+ return (await manager.getCommits(id, count)).content;
106
+ });
107
+ return commits.map((commit) => ({
108
+ date: commit.commit.author.date,
109
+ id: commit.sha,
110
+ treeId: commit.commit.tree.sha,
111
+ }));
112
+ }
113
+ // eslint-disable-next-line @rushstack/no-new-null
114
+ async getSnapshotTree(version) {
115
+ let requestVersion = version;
116
+ if (!requestVersion) {
117
+ const versions = await this.getVersions(this.id, 1);
118
+ if (versions.length === 0) {
119
+ return null;
120
+ }
121
+ requestVersion = versions[0];
122
+ }
123
+ let normalizedWholeSnapshot = await this.snapshotTreeCache.get(this.getCacheKey(requestVersion.id));
124
+ if (normalizedWholeSnapshot !== undefined) {
125
+ return normalizedWholeSnapshot.snapshotTree;
126
+ }
127
+ normalizedWholeSnapshot = await this.fetchSnapshotTree(requestVersion.id, undefined, "getSnapshotTree");
128
+ // Currently retrieving blobs from network is not supported by AFR for WholeSummaryDocumentStorageService
129
+ // Blobs are expected to be put in the cache
130
+ await this.updateBlobsCache(normalizedWholeSnapshot.blobs);
131
+ return normalizedWholeSnapshot.snapshotTree;
132
+ }
133
+ async readBlob(blobId) {
134
+ const cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));
135
+ if (cachedBlob !== undefined) {
136
+ return cachedBlob;
137
+ }
138
+ // Note: AFR does not support readBlobs, but potentially other r11s like servers do
139
+ const blob = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
140
+ eventName: "readBlob",
141
+ blobId,
142
+ }, async (event) => {
143
+ const manager = await this.getStorageManager();
144
+ const response = (await manager.getBlob(blobId)).content;
145
+ event.end({
146
+ size: response.size,
147
+ });
148
+ return response;
149
+ }, undefined, // workers
150
+ undefined, // recordHeapSize
151
+ this.mc.config.getNumber("Fluid.Driver.ReadBlobTelemetrySampling"));
152
+ const bufferValue = (0, client_utils_1.stringToBuffer)(blob.content, blob.encoding);
153
+ await this.blobCache.put(this.getCacheKey(blob.sha), bufferValue);
154
+ return bufferValue;
155
+ }
156
+ async uploadSummaryWithContext(summary, context) {
157
+ const summaryHandle = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
158
+ eventName: "uploadSummaryWithContext",
159
+ proposalHandle: context.proposalHandle,
160
+ ackHandle: context.ackHandle,
161
+ referenceSequenceNumber: context.referenceSequenceNumber,
162
+ }, async () => {
163
+ const summaryUploadManager = await this.getSummaryUploadManager();
164
+ return summaryUploadManager.writeSummaryTree(summary, context.ackHandle ?? "", "channel");
165
+ });
166
+ return summaryHandle;
167
+ }
168
+ async downloadSummary(summaryHandle) {
169
+ const wholeFlatSnapshot = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
170
+ eventName: "getWholeFlatSummary",
171
+ treeId: summaryHandle.handle,
172
+ }, async (event) => {
173
+ const manager = await this.getStorageManager();
174
+ const response = await manager.getSnapshot(summaryHandle.handle);
175
+ event.end({
176
+ size: response.content.trees[0]?.entries.length,
177
+ });
178
+ return response.content;
179
+ });
180
+ const { blobs, snapshotTree } = (0, r11sSnapshotParser_1.convertWholeFlatSnapshotToSnapshotTreeAndBlobs)(wholeFlatSnapshot, "");
181
+ return (0, treeUtils_1.convertSnapshotAndBlobsToSummaryTree)(snapshotTree, blobs);
182
+ }
183
+ async createBlob(file) {
184
+ const uint8ArrayFile = new Uint8Array(file);
185
+ return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
186
+ eventName: "createBlob",
187
+ size: uint8ArrayFile.length,
188
+ }, async (event) => {
189
+ const manager = await this.getStorageManager();
190
+ const response = await manager
191
+ .createBlob((0, client_utils_1.Uint8ArrayToString)(uint8ArrayFile, "base64"), "base64")
192
+ .then((r) => ({ id: r.content.sha, url: r.content.url }));
193
+ event.end({
194
+ blobId: response.id,
195
+ });
196
+ return response;
197
+ });
198
+ }
199
+ async fetchSnapshotTree(versionId, disableCache, scenarioName) {
200
+ const normalizedWholeSummary = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
201
+ eventName: "getWholeFlatSummary",
202
+ treeId: versionId,
203
+ scenarioName,
204
+ }, async (event) => {
205
+ const manager = await this.getStorageManager(disableCache);
206
+ const response = await manager.getSnapshot(versionId);
207
+ const start = client_utils_1.performance.now();
208
+ const snapshot = (0, r11sSnapshotParser_1.convertWholeFlatSnapshotToSnapshotTreeAndBlobs)(response.content);
209
+ const snapshotConversionTime = client_utils_1.performance.now() - start;
210
+ (0, treeUtils_1.validateBlobsAndTrees)(snapshot.snapshotTree);
211
+ const { trees, numBlobs, encodedBlobsSize } = (0, treeUtils_1.evalBlobsAndTrees)(snapshot);
212
+ event.end({
213
+ size: response.content.trees[0]?.entries.length,
214
+ trees,
215
+ blobs: numBlobs,
216
+ encodedBlobsSize,
217
+ sequenceNumber: snapshot.sequenceNumber,
218
+ ...response.propsToLog,
219
+ snapshotConversionTime,
220
+ ...(0, driver_base_1.getW3CData)(response.requestUrl, "xmlhttprequest"),
221
+ });
222
+ return snapshot;
223
+ });
224
+ // Also add the result into the cache.
225
+ await this.snapshotTreeCache
226
+ .put(this.getCacheKey(versionId), normalizedWholeSummary)
227
+ .catch(() => undefined);
228
+ return normalizedWholeSummary;
229
+ }
230
+ async initializeFromSnapshot(normalizedWholeSummary) {
231
+ const snapshotId = normalizedWholeSummary.id;
232
+ (0, core_utils_1.assert)(snapshotId !== undefined, 0x275 /* "Root tree should contain the id" */);
233
+ const cachePs = [
234
+ this.snapshotTreeCache.put(this.getCacheKey(snapshotId), normalizedWholeSummary),
235
+ this.updateBlobsCache(normalizedWholeSummary.blobs),
236
+ ];
237
+ await Promise.all(cachePs);
238
+ return snapshotId;
239
+ }
240
+ async updateBlobsCache(blobs) {
241
+ const blobCachePutPs = [];
242
+ blobs.forEach((value, id) => {
243
+ const cacheKey = this.getCacheKey(id);
244
+ blobCachePutPs.push(this.blobCache.put(cacheKey, value));
245
+ });
246
+ await Promise.all(blobCachePutPs);
247
+ }
248
+ getCacheKey(blobId) {
249
+ return `${this.id}:${blobId}`;
250
+ }
251
+ }
252
+ exports.WholeSummaryDocumentStorageService = WholeSummaryDocumentStorageService;
253
+ //# sourceMappingURL=wholeSummaryDocumentStorageService.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wholeSummaryDocumentStorageService.cjs","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAKyC;AACzC,+DAA+F;AAC/F,2DAAoD;AACpD,6DAAgF;AAahF,uCAAgD;AAEhD,+CAIqB;AAErB,+EAAwE;AAIxE,iEAAsF;AAEtF,MAAM,gBAAgB,GAAW,QAAQ,CAAC;AAE1C,MAAa,kCAAkC;IAMtC,KAAK,CAAC,uBAAuB;QACpC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC/C,OAAO,IAAI,qDAAyB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,YACoB,EAAU,EACV,OAAmB,EACnB,MAA2B,EAC9B,QAAyC,EACxC,cAA6C,EAC7C,YAAqC,IAAI,qBAAa,EAAE,EACxD,oBAAsD,IAAI,qBAAa,EAAE,EACzE,iBAA8B,EAC9B,oBAEU,KAAK,EAAE,YAAY,EAAE,EAAE,CACjD,YAAY,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS;QACnD,CAAC,CAAC,IAAI,CAAC,iBAAiB;QACxB,CAAC,CAAC,IAAI,CAAC,OAAO;QAbG,OAAE,GAAF,EAAE,CAAQ;QACV,YAA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AAC;QAChF,MAAM,OAAO,GAAmB;YAC/B,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,sBAAsB,CAAC;YAChF,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,KAAK,CAAC;SACnD,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3B,OAAO,UAAU,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,KAA+B;QAC7D,MAAM,cAAc,GAAoB,EAAE,CAAC;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACtC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD;AAtUD,gFAsUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils\";\nimport { performance, stringToBuffer, Uint8ArrayToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { getW3CData, promiseRaceWithWinner } from \"@fluidframework/driver-base\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport {\n\tconvertSnapshotAndBlobsToSummaryTree,\n\tevalBlobsAndTrees,\n\tvalidateBlobsAndTrees,\n} from \"./treeUtils\";\nimport { GitManager } from \"./gitManager\";\nimport { WholeSummaryUploadManager } from \"./wholeSummaryUploadManager\";\nimport { ISummaryUploadManager } from \"./storageContracts\";\nimport { IR11sResponse } from \"./restWrapper\";\nimport { INormalizedWholeSnapshot, IWholeFlatSnapshot } from \"./contracts\";\nimport { convertWholeFlatSnapshotToSnapshotTreeAndBlobs } from \"./r11sSnapshotParser\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate readonly mc: MonitoringContext;\n\tprivate firstVersionsCall: boolean = true;\n\n\tpublic readonly repositoryUrl = \"\";\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new WholeSummaryUploadManager(manager);\n\t}\n\n\tconstructor(\n\t\tprotected readonly id: string,\n\t\tprotected readonly manager: GitManager,\n\t\tprotected readonly logger: ITelemetryLoggerExt,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies?: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),\n\t\tprivate readonly snapshotTreeCache: ICache<INormalizedWholeSnapshot> = new InMemoryCache(),\n\t\tprivate readonly noCacheGitManager?: GitManager,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async (disableCache) =>\n\t\t\tdisableCache && this.noCacheGitManager !== undefined\n\t\t\t\t? this.noCacheGitManager\n\t\t\t\t: this.manager,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger,\n\t\t});\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId !== this.id && versionId !== null) {\n\t\t\t// Blobs/Trees in this scenario will never have multiple versions, so return versionId as is\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: undefined!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\t// If this is the first versions call for the document, we know we will want the latest summary.\n\t\t// Fetch latest summary, cache it, and return its id.\n\t\tif (this.firstVersionsCall && count === 1) {\n\t\t\tconst normalizedSnapshotContents = await PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"ObtainSnapshot\",\n\t\t\t\t\tversionId: versionId ?? undefined,\n\t\t\t\t\tcount,\n\t\t\t\t\tenableDiscovery: this.driverPolicies?.enableDiscovery,\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tlet method: string;\n\t\t\t\t\tconst cachedSnapshotP = this.snapshotTreeCache.get(\n\t\t\t\t\t\tthis.getCacheKey(latestSnapshotId),\n\t\t\t\t\t);\n\n\t\t\t\t\tconst networkSnapshotP = !this.driverPolicies?.enableDiscovery\n\t\t\t\t\t\t? this.fetchSnapshotTree(latestSnapshotId, false, \"getVersions\")\n\t\t\t\t\t\t: this.fetchSnapshotTree(latestSnapshotId, true, \"getVersions\");\n\n\t\t\t\t\tconst promiseRaceWinner = await promiseRaceWithWinner([\n\t\t\t\t\t\tcachedSnapshotP.catch(() => undefined),\n\t\t\t\t\t\tnetworkSnapshotP.catch(() => undefined),\n\t\t\t\t\t]);\n\n\t\t\t\t\tlet retrievedSnapshot = promiseRaceWinner.value;\n\t\t\t\t\tmethod = promiseRaceWinner.index === 0 ? \"cache\" : \"network\";\n\n\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t// if network failed -> wait for cache ( then return network failure)\n\t\t\t\t\t\t// If cache returned empty or failed -> wait for network (success of failure)\n\t\t\t\t\t\tif (promiseRaceWinner.index === 1) {\n\t\t\t\t\t\t\tretrievedSnapshot = await cachedSnapshotP;\n\t\t\t\t\t\t\tmethod = \"cache\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t\tretrievedSnapshot = await networkSnapshotP;\n\t\t\t\t\t\t\tmethod = \"network\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t});\n\t\t\t\t\treturn retrievedSnapshot;\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconst _id = await this.initializeFromSnapshot(normalizedSnapshotContents);\n\t\t\tthis.firstVersionsCall = false;\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: _id,\n\t\t\t\t\ttreeId: normalizedSnapshotContents.snapshotTree.id!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// Otherwise, get the latest version of the document as normal.\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getVersions\",\n\t\t\t\tversionId: id,\n\t\t\t\tcount,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\treturn (await manager.getCommits(id, count)).content;\n\t\t\t},\n\t\t);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tlet normalizedWholeSnapshot = await this.snapshotTreeCache.get(\n\t\t\tthis.getCacheKey(requestVersion.id),\n\t\t);\n\t\tif (normalizedWholeSnapshot !== undefined) {\n\t\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t\t}\n\n\t\tnormalizedWholeSnapshot = await this.fetchSnapshotTree(\n\t\t\trequestVersion.id,\n\t\t\tundefined,\n\t\t\t\"getSnapshotTree\",\n\t\t);\n\n\t\t// Currently retrieving blobs from network is not supported by AFR for WholeSummaryDocumentStorageService\n\t\t// Blobs are expected to be put in the cache\n\t\tawait this.updateBlobsCache(normalizedWholeSnapshot.blobs);\n\n\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));\n\t\tif (cachedBlob !== undefined) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\t// Note: AFR does not support readBlobs, but potentially other r11s like servers do\n\t\tconst blob = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"readBlob\",\n\t\t\t\tblobId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = (await manager.getBlob(blobId)).content;\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.size,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\tundefined, // workers\n\t\t\tundefined, // recordHeapSize\n\t\t\tthis.mc.config.getNumber(\"Fluid.Driver.ReadBlobTelemetrySampling\"),\n\t\t);\n\t\tconst bufferValue = stringToBuffer(blob.content, blob.encoding);\n\n\t\tawait this.blobCache.put(this.getCacheKey(blob.sha), bufferValue);\n\n\t\treturn bufferValue;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst summaryHandle = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"uploadSummaryWithContext\",\n\t\t\t\tproposalHandle: context.proposalHandle,\n\t\t\t\tackHandle: context.ackHandle,\n\t\t\t\treferenceSequenceNumber: context.referenceSequenceNumber,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryUploadManager = await this.getSummaryUploadManager();\n\t\t\t\treturn summaryUploadManager.writeSummaryTree(\n\t\t\t\t\tsummary,\n\t\t\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\t\t\"channel\",\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t\treturn summaryHandle;\n\t}\n\n\tpublic async downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst wholeFlatSnapshot = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: summaryHandle.handle,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager.getSnapshot(summaryHandle.handle);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\n\t\tconst { blobs, snapshotTree } = convertWholeFlatSnapshotToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSnapshot,\n\t\t\t\"\",\n\t\t);\n\t\treturn convertSnapshotAndBlobsToSummaryTree(snapshotTree, blobs);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"createBlob\",\n\t\t\t\tsize: uint8ArrayFile.length,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager\n\t\t\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t\t\t.then((r) => ({ id: r.content.sha, url: r.content.url }));\n\t\t\t\tevent.end({\n\t\t\t\t\tblobId: response.id,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async fetchSnapshotTree(\n\t\tversionId: string,\n\t\tdisableCache?: boolean,\n\t\tscenarioName?: string,\n\t): Promise<INormalizedWholeSnapshot> {\n\t\tconst normalizedWholeSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: versionId,\n\t\t\t\tscenarioName,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager(disableCache);\n\t\t\t\tconst response: IR11sResponse<IWholeFlatSnapshot> =\n\t\t\t\t\tawait manager.getSnapshot(versionId);\n\t\t\t\tconst start = performance.now();\n\t\t\t\tconst snapshot: INormalizedWholeSnapshot =\n\t\t\t\t\tconvertWholeFlatSnapshotToSnapshotTreeAndBlobs(response.content);\n\t\t\t\tconst snapshotConversionTime = performance.now() - start;\n\t\t\t\tvalidateBlobsAndTrees(snapshot.snapshotTree);\n\t\t\t\tconst { trees, numBlobs, encodedBlobsSize } = evalBlobsAndTrees(snapshot);\n\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t\ttrees,\n\t\t\t\t\tblobs: numBlobs,\n\t\t\t\t\tencodedBlobsSize,\n\t\t\t\t\tsequenceNumber: snapshot.sequenceNumber,\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\tsnapshotConversionTime,\n\t\t\t\t\t...getW3CData(response.requestUrl, \"xmlhttprequest\"),\n\t\t\t\t});\n\t\t\t\treturn snapshot;\n\t\t\t},\n\t\t);\n\n\t\t// Also add the result into the cache.\n\t\tawait this.snapshotTreeCache\n\t\t\t.put(this.getCacheKey(versionId), normalizedWholeSummary)\n\t\t\t.catch(() => undefined);\n\t\treturn normalizedWholeSummary;\n\t}\n\n\tprivate async initializeFromSnapshot(\n\t\tnormalizedWholeSummary: INormalizedWholeSnapshot,\n\t): Promise<string> {\n\t\tconst snapshotId = normalizedWholeSummary.id;\n\t\tassert(snapshotId !== undefined, 0x275 /* \"Root tree should contain the id\" */);\n\t\tconst cachePs: Promise<any>[] = [\n\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(snapshotId), normalizedWholeSummary),\n\t\t\tthis.updateBlobsCache(normalizedWholeSummary.blobs),\n\t\t];\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn snapshotId;\n\t}\n\n\tprivate async updateBlobsCache(blobs: Map<string, ArrayBuffer>): Promise<void> {\n\t\tconst blobCachePutPs: Promise<void>[] = [];\n\t\tblobs.forEach((value, id) => {\n\t\t\tconst cacheKey = this.getCacheKey(id);\n\t\t\tblobCachePutPs.push(this.blobCache.put(cacheKey, value));\n\t\t});\n\t\tawait Promise.all(blobCachePutPs);\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\n\t}\n}\n"]}
@@ -2,35 +2,37 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { ITelemetryLogger } from "@fluidframework/common-definitions";
5
+ import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
6
6
  import { IDocumentStorageService, ISummaryContext, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
7
7
  import { ICreateBlobResponse, ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
8
- import { GitManager } from "@fluidframework/server-services-client";
9
8
  import { ICache } from "./cache";
10
- import { ISnapshotTreeVersion } from "./definitions";
11
9
  import { IRouterliciousDriverPolicies } from "./policies";
10
+ import { GitManager } from "./gitManager";
11
+ import { INormalizedWholeSnapshot } from "./contracts";
12
12
  export declare class WholeSummaryDocumentStorageService implements IDocumentStorageService {
13
13
  protected readonly id: string;
14
14
  protected readonly manager: GitManager;
15
- protected readonly logger: ITelemetryLogger;
15
+ protected readonly logger: ITelemetryLoggerExt;
16
16
  readonly policies: IDocumentStorageServicePolicies;
17
17
  private readonly driverPolicies?;
18
18
  private readonly blobCache;
19
19
  private readonly snapshotTreeCache;
20
20
  private readonly noCacheGitManager?;
21
21
  private readonly getStorageManager;
22
+ private readonly mc;
22
23
  private firstVersionsCall;
23
- get repositoryUrl(): string;
24
+ readonly repositoryUrl = "";
24
25
  private getSummaryUploadManager;
25
- constructor(id: string, manager: GitManager, logger: ITelemetryLogger, policies?: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies | undefined, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<ISnapshotTreeVersion>, noCacheGitManager?: GitManager | undefined, getStorageManager?: (disableCache?: boolean) => Promise<GitManager>);
26
+ constructor(id: string, manager: GitManager, logger: ITelemetryLoggerExt, policies: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies | undefined, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<INormalizedWholeSnapshot>, noCacheGitManager?: GitManager | undefined, getStorageManager?: (disableCache?: boolean) => Promise<GitManager>);
26
27
  getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
27
28
  getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null>;
28
29
  readBlob(blobId: string): Promise<ArrayBufferLike>;
29
30
  uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
30
31
  downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree>;
31
32
  createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
32
- private fetchAndCacheSnapshotTree;
33
- private initBlobCache;
33
+ private fetchSnapshotTree;
34
+ private initializeFromSnapshot;
35
+ private updateBlobsCache;
34
36
  private getCacheKey;
35
37
  }
36
38
  //# sourceMappingURL=wholeSummaryDocumentStorageService.d.ts.map