@fluidframework/odsp-driver 2.0.0-dev-rc.1.0.0.232845 → 2.0.0-dev-rc.2.0.0.246488

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 (617) hide show
  1. package/.eslintrc.cjs +18 -3
  2. package/{.mocharc.js → .mocharc.cjs} +1 -1
  3. package/CHANGELOG.md +44 -0
  4. package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
  5. package/api-extractor-lint.json +1 -1
  6. package/api-extractor.json +1 -1
  7. package/api-report/odsp-driver.api.md +11 -12
  8. package/dist/ReadBufferUtils.d.ts.map +1 -1
  9. package/dist/ReadBufferUtils.js.map +1 -1
  10. package/dist/WriteBufferUtils.d.ts +1 -1
  11. package/dist/WriteBufferUtils.d.ts.map +1 -1
  12. package/dist/WriteBufferUtils.js +12 -12
  13. package/dist/WriteBufferUtils.js.map +1 -1
  14. package/dist/checkUrl.d.ts.map +1 -1
  15. package/dist/checkUrl.js +5 -3
  16. package/dist/checkUrl.js.map +1 -1
  17. package/dist/compactSnapshotParser.d.ts.map +1 -1
  18. package/dist/compactSnapshotParser.js +87 -69
  19. package/dist/compactSnapshotParser.js.map +1 -1
  20. package/dist/compactSnapshotWriter.d.ts.map +1 -1
  21. package/dist/compactSnapshotWriter.js +25 -19
  22. package/dist/compactSnapshotWriter.js.map +1 -1
  23. package/dist/contracts.d.ts +10 -4
  24. package/dist/contracts.d.ts.map +1 -1
  25. package/dist/contracts.js.map +1 -1
  26. package/dist/createFile.d.ts +3 -3
  27. package/dist/createFile.d.ts.map +1 -1
  28. package/dist/createFile.js +30 -27
  29. package/dist/createFile.js.map +1 -1
  30. package/dist/createNewContainerOnExistingFile.d.ts +2 -2
  31. package/dist/createNewContainerOnExistingFile.d.ts.map +1 -1
  32. package/dist/createNewContainerOnExistingFile.js +14 -14
  33. package/dist/createNewContainerOnExistingFile.js.map +1 -1
  34. package/dist/createNewModule.d.ts +2 -2
  35. package/dist/createNewModule.d.ts.map +1 -1
  36. package/dist/createNewModule.js +4 -4
  37. package/dist/createNewModule.js.map +1 -1
  38. package/dist/createNewUtils.d.ts +2 -2
  39. package/dist/createNewUtils.d.ts.map +1 -1
  40. package/dist/createNewUtils.js +12 -8
  41. package/dist/createNewUtils.js.map +1 -1
  42. package/dist/createOdspCreateContainerRequest.d.ts.map +1 -1
  43. package/dist/createOdspCreateContainerRequest.js +6 -2
  44. package/dist/createOdspCreateContainerRequest.js.map +1 -1
  45. package/dist/createOdspUrl.d.ts +1 -1
  46. package/dist/createOdspUrl.d.ts.map +1 -1
  47. package/dist/createOdspUrl.js.map +1 -1
  48. package/dist/epochTracker.d.ts +10 -9
  49. package/dist/epochTracker.d.ts.map +1 -1
  50. package/dist/epochTracker.js +66 -43
  51. package/dist/epochTracker.js.map +1 -1
  52. package/dist/fetchSnapshot.d.ts +11 -8
  53. package/dist/fetchSnapshot.d.ts.map +1 -1
  54. package/dist/fetchSnapshot.js +79 -58
  55. package/dist/fetchSnapshot.js.map +1 -1
  56. package/dist/getFileLink.d.ts.map +1 -1
  57. package/dist/getFileLink.js +24 -17
  58. package/dist/getFileLink.js.map +1 -1
  59. package/dist/getQueryString.d.ts.map +1 -1
  60. package/dist/getQueryString.js +6 -0
  61. package/dist/getQueryString.js.map +1 -1
  62. package/dist/index.d.ts +19 -19
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +44 -44
  65. package/dist/index.js.map +1 -1
  66. package/dist/localOdspDriver/localOdspDocumentService.d.ts +1 -1
  67. package/dist/localOdspDriver/localOdspDocumentService.d.ts.map +1 -1
  68. package/dist/localOdspDriver/localOdspDocumentService.js +5 -5
  69. package/dist/localOdspDriver/localOdspDocumentService.js.map +1 -1
  70. package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts +8 -6
  71. package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -1
  72. package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +10 -9
  73. package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -1
  74. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts +1 -1
  75. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -1
  76. package/dist/localOdspDriver/localOdspDocumentStorageManager.js +6 -6
  77. package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -1
  78. package/dist/odsp-driver-alpha.d.ts +27 -12
  79. package/dist/odsp-driver-beta.d.ts +1 -2
  80. package/dist/odsp-driver-public.d.ts +1 -2
  81. package/dist/odsp-driver-untrimmed.d.ts +29 -12
  82. package/dist/odspCache.d.ts +3 -3
  83. package/dist/odspCache.d.ts.map +1 -1
  84. package/dist/odspCache.js +3 -4
  85. package/dist/odspCache.js.map +1 -1
  86. package/dist/odspDelayLoadedDeltaStream.d.ts +7 -5
  87. package/dist/odspDelayLoadedDeltaStream.d.ts.map +1 -1
  88. package/dist/odspDelayLoadedDeltaStream.js +41 -28
  89. package/dist/odspDelayLoadedDeltaStream.js.map +1 -1
  90. package/dist/odspDeltaStorageService.d.ts +7 -7
  91. package/dist/odspDeltaStorageService.d.ts.map +1 -1
  92. package/dist/odspDeltaStorageService.js +5 -5
  93. package/dist/odspDeltaStorageService.js.map +1 -1
  94. package/dist/odspDocumentDeltaConnection.d.ts +1 -1
  95. package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
  96. package/dist/odspDocumentDeltaConnection.js +41 -23
  97. package/dist/odspDocumentDeltaConnection.js.map +1 -1
  98. package/dist/odspDocumentService.d.ts +6 -4
  99. package/dist/odspDocumentService.d.ts.map +1 -1
  100. package/dist/odspDocumentService.js +19 -16
  101. package/dist/odspDocumentService.js.map +1 -1
  102. package/dist/odspDocumentServiceFactory.d.ts +6 -1
  103. package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
  104. package/dist/odspDocumentServiceFactory.js +9 -4
  105. package/dist/odspDocumentServiceFactory.js.map +1 -1
  106. package/dist/odspDocumentServiceFactoryCore.d.ts +4 -4
  107. package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  108. package/dist/odspDocumentServiceFactoryCore.js +26 -22
  109. package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
  110. package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts +1 -1
  111. package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +1 -1
  112. package/dist/odspDocumentServiceFactoryWithCodeSplit.js +2 -2
  113. package/dist/odspDocumentServiceFactoryWithCodeSplit.js.map +1 -1
  114. package/dist/odspDocumentStorageManager.d.ts +15 -9
  115. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  116. package/dist/odspDocumentStorageManager.js +219 -181
  117. package/dist/odspDocumentStorageManager.js.map +1 -1
  118. package/dist/odspDocumentStorageServiceBase.d.ts +2 -4
  119. package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -1
  120. package/dist/odspDocumentStorageServiceBase.js +32 -29
  121. package/dist/odspDocumentStorageServiceBase.js.map +1 -1
  122. package/dist/odspDriverUrlResolver.d.ts +5 -1
  123. package/dist/odspDriverUrlResolver.d.ts.map +1 -1
  124. package/dist/odspDriverUrlResolver.js +27 -24
  125. package/dist/odspDriverUrlResolver.js.map +1 -1
  126. package/dist/odspDriverUrlResolverForShareLink.d.ts +17 -6
  127. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  128. package/dist/odspDriverUrlResolverForShareLink.js +49 -39
  129. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  130. package/dist/odspError.d.ts +1 -1
  131. package/dist/odspError.d.ts.map +1 -1
  132. package/dist/odspError.js +5 -5
  133. package/dist/odspError.js.map +1 -1
  134. package/dist/odspFluidFileLink.d.ts +1 -1
  135. package/dist/odspFluidFileLink.d.ts.map +1 -1
  136. package/dist/odspFluidFileLink.js +2 -2
  137. package/dist/odspFluidFileLink.js.map +1 -1
  138. package/dist/odspLocationRedirection.js +2 -2
  139. package/dist/odspLocationRedirection.js.map +1 -1
  140. package/dist/odspPublicUtils.d.ts +3 -0
  141. package/dist/odspPublicUtils.d.ts.map +1 -1
  142. package/dist/odspPublicUtils.js +3 -0
  143. package/dist/odspPublicUtils.js.map +1 -1
  144. package/dist/odspSnapshotParser.d.ts +1 -1
  145. package/dist/odspSnapshotParser.d.ts.map +1 -1
  146. package/dist/odspSnapshotParser.js +3 -2
  147. package/dist/odspSnapshotParser.js.map +1 -1
  148. package/dist/odspSummaryUploadManager.d.ts +1 -1
  149. package/dist/odspSummaryUploadManager.d.ts.map +1 -1
  150. package/dist/odspSummaryUploadManager.js +9 -6
  151. package/dist/odspSummaryUploadManager.js.map +1 -1
  152. package/dist/odspUrlHelper.d.ts.map +1 -1
  153. package/dist/odspUrlHelper.js +1 -2
  154. package/dist/odspUrlHelper.js.map +1 -1
  155. package/dist/odspUtils.d.ts +19 -7
  156. package/dist/odspUtils.d.ts.map +1 -1
  157. package/dist/odspUtils.js +61 -31
  158. package/dist/odspUtils.js.map +1 -1
  159. package/dist/opsCaching.d.ts +1 -1
  160. package/dist/opsCaching.d.ts.map +1 -1
  161. package/dist/opsCaching.js +2 -1
  162. package/dist/opsCaching.js.map +1 -1
  163. package/dist/package.json +3 -0
  164. package/dist/packageVersion.d.ts +1 -1
  165. package/dist/packageVersion.js +1 -1
  166. package/dist/packageVersion.js.map +1 -1
  167. package/dist/prefetchLatestSnapshot.d.ts +2 -2
  168. package/dist/prefetchLatestSnapshot.d.ts.map +1 -1
  169. package/dist/prefetchLatestSnapshot.js +17 -12
  170. package/dist/prefetchLatestSnapshot.js.map +1 -1
  171. package/dist/retryErrorsStorageAdapter.d.ts +0 -1
  172. package/dist/retryErrorsStorageAdapter.d.ts.map +1 -1
  173. package/dist/retryErrorsStorageAdapter.js +2 -5
  174. package/dist/retryErrorsStorageAdapter.js.map +1 -1
  175. package/dist/retryUtils.d.ts.map +1 -1
  176. package/dist/retryUtils.js +6 -2
  177. package/dist/retryUtils.js.map +1 -1
  178. package/dist/socketModule.d.ts.map +1 -1
  179. package/dist/socketModule.js +2 -0
  180. package/dist/socketModule.js.map +1 -1
  181. package/dist/tsdoc-metadata.json +1 -1
  182. package/dist/vroom.d.ts +2 -2
  183. package/dist/vroom.d.ts.map +1 -1
  184. package/dist/vroom.js +5 -5
  185. package/dist/vroom.js.map +1 -1
  186. package/dist/zipItDataRepresentationUtils.d.ts +1 -1
  187. package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
  188. package/dist/zipItDataRepresentationUtils.js +15 -11
  189. package/dist/zipItDataRepresentationUtils.js.map +1 -1
  190. package/lib/{ReadBufferUtils.d.mts → ReadBufferUtils.d.ts} +1 -1
  191. package/lib/ReadBufferUtils.d.ts.map +1 -0
  192. package/lib/{ReadBufferUtils.mjs → ReadBufferUtils.js} +1 -1
  193. package/lib/ReadBufferUtils.js.map +1 -0
  194. package/lib/{WriteBufferUtils.d.mts → WriteBufferUtils.d.ts} +2 -2
  195. package/lib/WriteBufferUtils.d.ts.map +1 -0
  196. package/lib/{WriteBufferUtils.mjs → WriteBufferUtils.js} +2 -2
  197. package/lib/WriteBufferUtils.js.map +1 -0
  198. package/lib/{checkUrl.d.mts → checkUrl.d.ts} +1 -1
  199. package/lib/checkUrl.d.ts.map +1 -0
  200. package/lib/{checkUrl.mjs → checkUrl.js} +5 -3
  201. package/lib/checkUrl.js.map +1 -0
  202. package/lib/{compactSnapshotParser.d.mts → compactSnapshotParser.d.ts} +1 -1
  203. package/lib/compactSnapshotParser.d.ts.map +1 -0
  204. package/lib/{compactSnapshotParser.mjs → compactSnapshotParser.js} +61 -43
  205. package/lib/compactSnapshotParser.js.map +1 -0
  206. package/lib/{compactSnapshotWriter.d.mts → compactSnapshotWriter.d.ts} +1 -1
  207. package/lib/compactSnapshotWriter.d.ts.map +1 -0
  208. package/lib/{compactSnapshotWriter.mjs → compactSnapshotWriter.js} +13 -7
  209. package/lib/compactSnapshotWriter.js.map +1 -0
  210. package/lib/{constants.d.mts → constants.d.ts} +1 -1
  211. package/lib/constants.d.ts.map +1 -0
  212. package/lib/{constants.mjs → constants.js} +1 -1
  213. package/lib/constants.js.map +1 -0
  214. package/lib/{contracts.d.mts → contracts.d.ts} +11 -5
  215. package/lib/contracts.d.ts.map +1 -0
  216. package/lib/{contracts.mjs → contracts.js} +1 -1
  217. package/lib/contracts.js.map +1 -0
  218. package/lib/{contractsPublic.d.mts → contractsPublic.d.ts} +1 -1
  219. package/lib/contractsPublic.d.ts.map +1 -0
  220. package/lib/{contractsPublic.mjs → contractsPublic.js} +1 -1
  221. package/lib/contractsPublic.js.map +1 -0
  222. package/lib/{createFile.d.mts → createFile.d.ts} +4 -4
  223. package/lib/createFile.d.ts.map +1 -0
  224. package/lib/{createFile.mjs → createFile.js} +15 -12
  225. package/lib/createFile.js.map +1 -0
  226. package/lib/{createNewContainerOnExistingFile.d.mts → createNewContainerOnExistingFile.d.ts} +3 -3
  227. package/lib/createNewContainerOnExistingFile.d.ts.map +1 -0
  228. package/lib/{createNewContainerOnExistingFile.mjs → createNewContainerOnExistingFile.js} +7 -7
  229. package/lib/createNewContainerOnExistingFile.js.map +1 -0
  230. package/lib/{createNewModule.mjs → createNewModule.d.ts} +3 -3
  231. package/lib/createNewModule.d.ts.map +1 -0
  232. package/lib/{createNewModule.d.mts → createNewModule.js} +3 -3
  233. package/lib/createNewModule.js.map +1 -0
  234. package/lib/{createNewUtils.d.mts → createNewUtils.d.ts} +3 -3
  235. package/lib/createNewUtils.d.ts.map +1 -0
  236. package/lib/{createNewUtils.mjs → createNewUtils.js} +9 -5
  237. package/lib/createNewUtils.js.map +1 -0
  238. package/lib/{createOdspCreateContainerRequest.d.mts → createOdspCreateContainerRequest.d.ts} +5 -1
  239. package/lib/createOdspCreateContainerRequest.d.ts.map +1 -0
  240. package/lib/{createOdspCreateContainerRequest.mjs → createOdspCreateContainerRequest.js} +6 -2
  241. package/lib/createOdspCreateContainerRequest.js.map +1 -0
  242. package/lib/{createOdspUrl.d.mts → createOdspUrl.d.ts} +2 -2
  243. package/lib/createOdspUrl.d.ts.map +1 -0
  244. package/lib/{createOdspUrl.mjs → createOdspUrl.js} +1 -1
  245. package/lib/createOdspUrl.js.map +1 -0
  246. package/lib/{epochTracker.d.mts → epochTracker.d.ts} +11 -10
  247. package/lib/epochTracker.d.ts.map +1 -0
  248. package/lib/{epochTracker.mjs → epochTracker.js} +56 -33
  249. package/lib/epochTracker.js.map +1 -0
  250. package/lib/{fetch.d.mts → fetch.d.ts} +1 -1
  251. package/lib/fetch.d.ts.map +1 -0
  252. package/lib/{fetch.mjs → fetch.js} +1 -1
  253. package/lib/fetch.js.map +1 -0
  254. package/lib/{fetchSnapshot.d.mts → fetchSnapshot.d.ts} +12 -9
  255. package/lib/fetchSnapshot.d.ts.map +1 -0
  256. package/lib/{fetchSnapshot.mjs → fetchSnapshot.js} +61 -40
  257. package/lib/fetchSnapshot.js.map +1 -0
  258. package/lib/{getFileLink.d.mts → getFileLink.d.ts} +1 -1
  259. package/lib/getFileLink.d.ts.map +1 -0
  260. package/lib/{getFileLink.mjs → getFileLink.js} +14 -7
  261. package/lib/getFileLink.js.map +1 -0
  262. package/lib/{getQueryString.d.mts → getQueryString.d.ts} +5 -1
  263. package/lib/getQueryString.d.ts.map +1 -0
  264. package/lib/{getQueryString.mjs → getQueryString.js} +7 -1
  265. package/lib/getQueryString.js.map +1 -0
  266. package/lib/{getUrlAndHeadersWithAuth.d.mts → getUrlAndHeadersWithAuth.d.ts} +1 -1
  267. package/lib/getUrlAndHeadersWithAuth.d.ts.map +1 -0
  268. package/lib/{getUrlAndHeadersWithAuth.mjs → getUrlAndHeadersWithAuth.js} +1 -1
  269. package/lib/getUrlAndHeadersWithAuth.js.map +1 -0
  270. package/lib/{index.d.mts → index.d.ts} +20 -20
  271. package/lib/index.d.ts.map +1 -0
  272. package/lib/index.js +29 -0
  273. package/lib/index.js.map +1 -0
  274. package/lib/localOdspDriver/{localOdspDeltaStorageService.d.mts → localOdspDeltaStorageService.d.ts} +1 -1
  275. package/lib/localOdspDriver/localOdspDeltaStorageService.d.ts.map +1 -0
  276. package/lib/localOdspDriver/{localOdspDeltaStorageService.mjs → localOdspDeltaStorageService.js} +1 -1
  277. package/lib/localOdspDriver/localOdspDeltaStorageService.js.map +1 -0
  278. package/lib/localOdspDriver/{localOdspDocumentService.d.mts → localOdspDocumentService.d.ts} +2 -2
  279. package/lib/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
  280. package/lib/localOdspDriver/{localOdspDocumentService.mjs → localOdspDocumentService.js} +4 -4
  281. package/lib/localOdspDriver/localOdspDocumentService.js.map +1 -0
  282. package/lib/localOdspDriver/{localOdspDocumentServiceFactory.d.mts → localOdspDocumentServiceFactory.d.ts} +9 -7
  283. package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
  284. package/lib/localOdspDriver/{localOdspDocumentServiceFactory.mjs → localOdspDocumentServiceFactory.js} +9 -8
  285. package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
  286. package/lib/localOdspDriver/{localOdspDocumentStorageManager.d.mts → localOdspDocumentStorageManager.d.ts} +2 -2
  287. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
  288. package/lib/localOdspDriver/{localOdspDocumentStorageManager.mjs → localOdspDocumentStorageManager.js} +4 -4
  289. package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
  290. package/lib/{odsp-driver-alpha.d.mts → odsp-driver-alpha.d.ts} +27 -12
  291. package/lib/{odsp-driver-public.d.mts → odsp-driver-beta.d.ts} +1 -2
  292. package/lib/{odsp-driver-beta.d.mts → odsp-driver-public.d.ts} +1 -2
  293. package/lib/{odsp-driver-untrimmed.d.mts → odsp-driver-untrimmed.d.ts} +29 -12
  294. package/lib/{odspCache.d.mts → odspCache.d.ts} +8 -4
  295. package/lib/odspCache.d.ts.map +1 -0
  296. package/lib/{odspCache.mjs → odspCache.js} +6 -3
  297. package/lib/odspCache.js.map +1 -0
  298. package/lib/{odspDelayLoadedDeltaStream.d.mts → odspDelayLoadedDeltaStream.d.ts} +8 -6
  299. package/lib/odspDelayLoadedDeltaStream.d.ts.map +1 -0
  300. package/lib/{odspDelayLoadedDeltaStream.mjs → odspDelayLoadedDeltaStream.js} +33 -20
  301. package/lib/odspDelayLoadedDeltaStream.js.map +1 -0
  302. package/lib/{odspDeltaStorageService.d.mts → odspDeltaStorageService.d.ts} +8 -8
  303. package/lib/odspDeltaStorageService.d.ts.map +1 -0
  304. package/lib/{odspDeltaStorageService.mjs → odspDeltaStorageService.js} +5 -5
  305. package/lib/odspDeltaStorageService.js.map +1 -0
  306. package/lib/{odspDocumentDeltaConnection.d.mts → odspDocumentDeltaConnection.d.ts} +2 -2
  307. package/lib/odspDocumentDeltaConnection.d.ts.map +1 -0
  308. package/lib/{odspDocumentDeltaConnection.mjs → odspDocumentDeltaConnection.js} +34 -16
  309. package/lib/odspDocumentDeltaConnection.js.map +1 -0
  310. package/lib/{odspDocumentService.d.mts → odspDocumentService.d.ts} +7 -5
  311. package/lib/odspDocumentService.d.ts.map +1 -0
  312. package/lib/{odspDocumentService.mjs → odspDocumentService.js} +16 -11
  313. package/lib/odspDocumentService.js.map +1 -0
  314. package/lib/{odspDocumentServiceFactory.d.mts → odspDocumentServiceFactory.d.ts} +7 -2
  315. package/lib/odspDocumentServiceFactory.d.ts.map +1 -0
  316. package/lib/{odspDocumentServiceFactory.mjs → odspDocumentServiceFactory.js} +9 -3
  317. package/lib/odspDocumentServiceFactory.js.map +1 -0
  318. package/lib/{odspDocumentServiceFactoryCore.d.mts → odspDocumentServiceFactoryCore.d.ts} +5 -5
  319. package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -0
  320. package/lib/{odspDocumentServiceFactoryCore.mjs → odspDocumentServiceFactoryCore.js} +23 -17
  321. package/lib/odspDocumentServiceFactoryCore.js.map +1 -0
  322. package/lib/{odspDocumentServiceFactoryWithCodeSplit.d.mts → odspDocumentServiceFactoryWithCodeSplit.d.ts} +2 -2
  323. package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +1 -0
  324. package/lib/{odspDocumentServiceFactoryWithCodeSplit.mjs → odspDocumentServiceFactoryWithCodeSplit.js} +2 -2
  325. package/lib/odspDocumentServiceFactoryWithCodeSplit.js.map +1 -0
  326. package/lib/{odspDocumentStorageManager.d.mts → odspDocumentStorageManager.d.ts} +16 -10
  327. package/lib/odspDocumentStorageManager.d.ts.map +1 -0
  328. package/lib/{odspDocumentStorageManager.mjs → odspDocumentStorageManager.js} +207 -167
  329. package/lib/odspDocumentStorageManager.js.map +1 -0
  330. package/lib/{odspDocumentStorageServiceBase.d.mts → odspDocumentStorageServiceBase.d.ts} +3 -5
  331. package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -0
  332. package/lib/{odspDocumentStorageServiceBase.mjs → odspDocumentStorageServiceBase.js} +32 -29
  333. package/lib/odspDocumentStorageServiceBase.js.map +1 -0
  334. package/lib/{odspDriverUrlResolver.d.mts → odspDriverUrlResolver.d.ts} +6 -2
  335. package/lib/odspDriverUrlResolver.d.ts.map +1 -0
  336. package/lib/{odspDriverUrlResolver.mjs → odspDriverUrlResolver.js} +24 -17
  337. package/lib/odspDriverUrlResolver.js.map +1 -0
  338. package/lib/{odspDriverUrlResolverForShareLink.d.mts → odspDriverUrlResolverForShareLink.d.ts} +18 -7
  339. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -0
  340. package/lib/{odspDriverUrlResolverForShareLink.mjs → odspDriverUrlResolverForShareLink.js} +41 -27
  341. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -0
  342. package/lib/{odspError.d.mts → odspError.d.ts} +2 -2
  343. package/lib/odspError.d.ts.map +1 -0
  344. package/lib/{odspError.mjs → odspError.js} +4 -4
  345. package/lib/odspError.js.map +1 -0
  346. package/lib/{odspFluidFileLink.d.mts → odspFluidFileLink.d.ts} +2 -2
  347. package/lib/odspFluidFileLink.d.ts.map +1 -0
  348. package/lib/{odspFluidFileLink.mjs → odspFluidFileLink.js} +2 -2
  349. package/lib/odspFluidFileLink.js.map +1 -0
  350. package/lib/{odspLocationRedirection.d.mts → odspLocationRedirection.d.ts} +1 -1
  351. package/lib/odspLocationRedirection.d.ts.map +1 -0
  352. package/lib/{odspLocationRedirection.mjs → odspLocationRedirection.js} +2 -2
  353. package/lib/odspLocationRedirection.js.map +1 -0
  354. package/lib/{odspPublicUtils.d.mts → odspPublicUtils.d.ts} +4 -1
  355. package/lib/odspPublicUtils.d.ts.map +1 -0
  356. package/lib/{odspPublicUtils.mjs → odspPublicUtils.js} +4 -1
  357. package/lib/odspPublicUtils.js.map +1 -0
  358. package/lib/{odspSnapshotParser.d.mts → odspSnapshotParser.d.ts} +2 -2
  359. package/lib/odspSnapshotParser.d.ts.map +1 -0
  360. package/lib/{odspSnapshotParser.mjs → odspSnapshotParser.js} +4 -3
  361. package/lib/odspSnapshotParser.js.map +1 -0
  362. package/lib/{odspSummaryUploadManager.d.mts → odspSummaryUploadManager.d.ts} +2 -2
  363. package/lib/odspSummaryUploadManager.d.ts.map +1 -0
  364. package/lib/{odspSummaryUploadManager.mjs → odspSummaryUploadManager.js} +8 -5
  365. package/lib/odspSummaryUploadManager.js.map +1 -0
  366. package/lib/{odspUrlHelper.d.mts → odspUrlHelper.d.ts} +1 -1
  367. package/lib/odspUrlHelper.d.ts.map +1 -0
  368. package/lib/{odspUrlHelper.mjs → odspUrlHelper.js} +2 -3
  369. package/lib/odspUrlHelper.js.map +1 -0
  370. package/lib/{odspUtils.d.mts → odspUtils.d.ts} +20 -8
  371. package/lib/odspUtils.d.ts.map +1 -0
  372. package/lib/{odspUtils.mjs → odspUtils.js} +45 -17
  373. package/lib/odspUtils.js.map +1 -0
  374. package/lib/{opsCaching.d.mts → opsCaching.d.ts} +2 -2
  375. package/lib/opsCaching.d.ts.map +1 -0
  376. package/lib/{opsCaching.mjs → opsCaching.js} +3 -2
  377. package/lib/opsCaching.js.map +1 -0
  378. package/lib/{packageVersion.d.mts → packageVersion.d.ts} +2 -2
  379. package/lib/packageVersion.d.ts.map +1 -0
  380. package/lib/{packageVersion.mjs → packageVersion.js} +2 -2
  381. package/lib/packageVersion.js.map +1 -0
  382. package/lib/{prefetchLatestSnapshot.d.mts → prefetchLatestSnapshot.d.ts} +3 -3
  383. package/lib/prefetchLatestSnapshot.d.ts.map +1 -0
  384. package/lib/{prefetchLatestSnapshot.mjs → prefetchLatestSnapshot.js} +16 -11
  385. package/lib/prefetchLatestSnapshot.js.map +1 -0
  386. package/lib/{retryErrorsStorageAdapter.d.mts → retryErrorsStorageAdapter.d.ts} +1 -2
  387. package/lib/retryErrorsStorageAdapter.d.ts.map +1 -0
  388. package/lib/{retryErrorsStorageAdapter.mjs → retryErrorsStorageAdapter.js} +2 -5
  389. package/lib/retryErrorsStorageAdapter.js.map +1 -0
  390. package/lib/{retryUtils.d.mts → retryUtils.d.ts} +1 -1
  391. package/lib/retryUtils.d.ts.map +1 -0
  392. package/lib/{retryUtils.mjs → retryUtils.js} +6 -2
  393. package/lib/retryUtils.js.map +1 -0
  394. package/lib/{socketModule.d.mts → socketModule.d.ts} +1 -1
  395. package/lib/socketModule.d.ts.map +1 -0
  396. package/lib/{socketModule.mjs → socketModule.js} +3 -1
  397. package/lib/socketModule.js.map +1 -0
  398. package/lib/test/buildOdspShareLinkReqParams.spec.js +25 -0
  399. package/lib/test/buildOdspShareLinkReqParams.spec.js.map +1 -0
  400. package/lib/test/createNewUtilsTests.spec.js +221 -0
  401. package/lib/test/createNewUtilsTests.spec.js.map +1 -0
  402. package/lib/test/deltaStorageService.spec.js +176 -0
  403. package/lib/test/deltaStorageService.spec.js.map +1 -0
  404. package/lib/test/epochTests.spec.js +340 -0
  405. package/lib/test/epochTests.spec.js.map +1 -0
  406. package/lib/test/epochTestsWithRedemption.spec.js +119 -0
  407. package/lib/test/epochTestsWithRedemption.spec.js.map +1 -0
  408. package/lib/test/fetchSnapshot.spec.js +412 -0
  409. package/lib/test/fetchSnapshot.spec.js.map +1 -0
  410. package/lib/test/getFileLink.spec.js +62 -0
  411. package/lib/test/getFileLink.spec.js.map +1 -0
  412. package/lib/test/getUrlAndHeadersWithAuth.spec.js +66 -0
  413. package/lib/test/getUrlAndHeadersWithAuth.spec.js.map +1 -0
  414. package/lib/test/getVersions.spec.js +284 -0
  415. package/lib/test/getVersions.spec.js.map +1 -0
  416. package/lib/test/joinSessionCacheTests.spec.js +53 -0
  417. package/lib/test/joinSessionCacheTests.spec.js.map +1 -0
  418. package/lib/test/joinSessionPeriodicCall.spec.js +158 -0
  419. package/lib/test/joinSessionPeriodicCall.spec.js.map +1 -0
  420. package/lib/test/jsonSnapshotFormatTests.spec.js +107 -0
  421. package/lib/test/jsonSnapshotFormatTests.spec.js.map +1 -0
  422. package/lib/test/localOdspDriver.spec.js +177 -0
  423. package/lib/test/localOdspDriver.spec.js.map +1 -0
  424. package/lib/test/mockFetch.js +61 -0
  425. package/lib/test/mockFetch.js.map +1 -0
  426. package/lib/test/odspCreateContainer.spec.js +116 -0
  427. package/lib/test/odspCreateContainer.spec.js.map +1 -0
  428. package/lib/test/odspDriverResolverTest.spec.js +289 -0
  429. package/lib/test/odspDriverResolverTest.spec.js.map +1 -0
  430. package/lib/test/odspDriverUrlResolverForShareLink.spec.js +287 -0
  431. package/lib/test/odspDriverUrlResolverForShareLink.spec.js.map +1 -0
  432. package/lib/test/odspError.spec.js +299 -0
  433. package/lib/test/odspError.spec.js.map +1 -0
  434. package/lib/test/opsCaching.spec.js +357 -0
  435. package/lib/test/opsCaching.spec.js.map +1 -0
  436. package/lib/test/prefetchSnapshotTests.spec.js +420 -0
  437. package/lib/test/prefetchSnapshotTests.spec.js.map +1 -0
  438. package/lib/test/snapshotFormatTests.spec.js +218 -0
  439. package/lib/test/snapshotFormatTests.spec.js.map +1 -0
  440. package/lib/test/socketTests/deltaConnectionUpdateTests.spec.js +152 -0
  441. package/lib/test/socketTests/deltaConnectionUpdateTests.spec.js.map +1 -0
  442. package/lib/test/socketTests/socketMock.js +109 -0
  443. package/lib/test/socketTests/socketMock.js.map +1 -0
  444. package/lib/test/socketTests/socketTests.spec.js +256 -0
  445. package/lib/test/socketTests/socketTests.spec.js.map +1 -0
  446. package/lib/test/tokenFetch.spec.js +39 -0
  447. package/lib/test/tokenFetch.spec.js.map +1 -0
  448. package/lib/test/types/validateOdspDriverPrevious.generated.js +96 -0
  449. package/lib/test/types/validateOdspDriverPrevious.generated.js.map +1 -0
  450. package/lib/test/zipItDataRepresentationTests.spec.js +207 -0
  451. package/lib/test/zipItDataRepresentationTests.spec.js.map +1 -0
  452. package/lib/{vroom.d.mts → vroom.d.ts} +3 -3
  453. package/lib/vroom.d.ts.map +1 -0
  454. package/lib/{vroom.mjs → vroom.js} +4 -4
  455. package/lib/vroom.js.map +1 -0
  456. package/lib/{zipItDataRepresentationUtils.d.mts → zipItDataRepresentationUtils.d.ts} +2 -2
  457. package/lib/zipItDataRepresentationUtils.d.ts.map +1 -0
  458. package/lib/{zipItDataRepresentationUtils.mjs → zipItDataRepresentationUtils.js} +17 -9
  459. package/lib/zipItDataRepresentationUtils.js.map +1 -0
  460. package/package.json +90 -31
  461. package/src/ReadBufferUtils.ts +7 -7
  462. package/src/WriteBufferUtils.ts +13 -9
  463. package/src/checkUrl.ts +4 -2
  464. package/src/compactSnapshotParser.ts +87 -52
  465. package/src/compactSnapshotWriter.ts +19 -12
  466. package/src/contracts.ts +16 -4
  467. package/src/createFile.ts +16 -13
  468. package/src/createNewContainerOnExistingFile.ts +8 -8
  469. package/src/createNewModule.ts +2 -2
  470. package/src/createNewUtils.ts +19 -9
  471. package/src/createOdspCreateContainerRequest.ts +2 -1
  472. package/src/createOdspUrl.ts +1 -1
  473. package/src/epochTracker.ts +90 -55
  474. package/src/fetchSnapshot.ts +104 -47
  475. package/src/getFileLink.ts +21 -13
  476. package/src/getQueryString.ts +3 -0
  477. package/src/index.ts +27 -19
  478. package/src/localOdspDriver/localOdspDocumentService.ts +3 -3
  479. package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +12 -11
  480. package/src/localOdspDriver/localOdspDocumentStorageManager.ts +5 -5
  481. package/src/odspCache.ts +13 -9
  482. package/src/odspDelayLoadedDeltaStream.ts +54 -33
  483. package/src/odspDeltaStorageService.ts +17 -16
  484. package/src/odspDocumentDeltaConnection.ts +52 -34
  485. package/src/odspDocumentService.ts +23 -20
  486. package/src/odspDocumentServiceFactory.ts +7 -2
  487. package/src/odspDocumentServiceFactoryCore.ts +25 -18
  488. package/src/odspDocumentServiceFactoryWithCodeSplit.ts +1 -1
  489. package/src/odspDocumentStorageManager.ts +276 -216
  490. package/src/odspDocumentStorageServiceBase.ts +45 -43
  491. package/src/odspDriverUrlResolver.ts +39 -24
  492. package/src/odspDriverUrlResolverForShareLink.ts +51 -31
  493. package/src/odspError.ts +4 -4
  494. package/src/odspFluidFileLink.ts +3 -3
  495. package/src/odspLocationRedirection.ts +1 -1
  496. package/src/odspPublicUtils.ts +3 -0
  497. package/src/odspSnapshotParser.ts +4 -3
  498. package/src/odspSummaryUploadManager.ts +21 -9
  499. package/src/odspUrlHelper.ts +2 -3
  500. package/src/odspUtils.ts +73 -30
  501. package/src/opsCaching.ts +13 -12
  502. package/src/packageVersion.ts +1 -1
  503. package/src/prefetchLatestSnapshot.ts +24 -15
  504. package/src/retryErrorsStorageAdapter.ts +4 -8
  505. package/src/retryUtils.ts +6 -2
  506. package/src/socketModule.ts +2 -0
  507. package/src/vroom.ts +6 -6
  508. package/src/zipItDataRepresentationUtils.ts +63 -35
  509. package/tsconfig.cjs.json +7 -0
  510. package/tsconfig.json +2 -5
  511. package/lib/ReadBufferUtils.d.mts.map +0 -1
  512. package/lib/ReadBufferUtils.mjs.map +0 -1
  513. package/lib/WriteBufferUtils.d.mts.map +0 -1
  514. package/lib/WriteBufferUtils.mjs.map +0 -1
  515. package/lib/checkUrl.d.mts.map +0 -1
  516. package/lib/checkUrl.mjs.map +0 -1
  517. package/lib/compactSnapshotParser.d.mts.map +0 -1
  518. package/lib/compactSnapshotParser.mjs.map +0 -1
  519. package/lib/compactSnapshotWriter.d.mts.map +0 -1
  520. package/lib/compactSnapshotWriter.mjs.map +0 -1
  521. package/lib/constants.d.mts.map +0 -1
  522. package/lib/constants.mjs.map +0 -1
  523. package/lib/contracts.d.mts.map +0 -1
  524. package/lib/contracts.mjs.map +0 -1
  525. package/lib/contractsPublic.d.mts.map +0 -1
  526. package/lib/contractsPublic.mjs.map +0 -1
  527. package/lib/createFile.d.mts.map +0 -1
  528. package/lib/createFile.mjs.map +0 -1
  529. package/lib/createNewContainerOnExistingFile.d.mts.map +0 -1
  530. package/lib/createNewContainerOnExistingFile.mjs.map +0 -1
  531. package/lib/createNewModule.d.mts.map +0 -1
  532. package/lib/createNewModule.mjs.map +0 -1
  533. package/lib/createNewUtils.d.mts.map +0 -1
  534. package/lib/createNewUtils.mjs.map +0 -1
  535. package/lib/createOdspCreateContainerRequest.d.mts.map +0 -1
  536. package/lib/createOdspCreateContainerRequest.mjs.map +0 -1
  537. package/lib/createOdspUrl.d.mts.map +0 -1
  538. package/lib/createOdspUrl.mjs.map +0 -1
  539. package/lib/epochTracker.d.mts.map +0 -1
  540. package/lib/epochTracker.mjs.map +0 -1
  541. package/lib/fetch.d.mts.map +0 -1
  542. package/lib/fetch.mjs.map +0 -1
  543. package/lib/fetchSnapshot.d.mts.map +0 -1
  544. package/lib/fetchSnapshot.mjs.map +0 -1
  545. package/lib/getFileLink.d.mts.map +0 -1
  546. package/lib/getFileLink.mjs.map +0 -1
  547. package/lib/getQueryString.d.mts.map +0 -1
  548. package/lib/getQueryString.mjs.map +0 -1
  549. package/lib/getUrlAndHeadersWithAuth.d.mts.map +0 -1
  550. package/lib/getUrlAndHeadersWithAuth.mjs.map +0 -1
  551. package/lib/index.d.mts.map +0 -1
  552. package/lib/index.mjs +0 -22
  553. package/lib/index.mjs.map +0 -1
  554. package/lib/localOdspDriver/localOdspDeltaStorageService.d.mts.map +0 -1
  555. package/lib/localOdspDriver/localOdspDeltaStorageService.mjs.map +0 -1
  556. package/lib/localOdspDriver/localOdspDocumentService.d.mts.map +0 -1
  557. package/lib/localOdspDriver/localOdspDocumentService.mjs.map +0 -1
  558. package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.mts.map +0 -1
  559. package/lib/localOdspDriver/localOdspDocumentServiceFactory.mjs.map +0 -1
  560. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.mts.map +0 -1
  561. package/lib/localOdspDriver/localOdspDocumentStorageManager.mjs.map +0 -1
  562. package/lib/odspCache.d.mts.map +0 -1
  563. package/lib/odspCache.mjs.map +0 -1
  564. package/lib/odspDelayLoadedDeltaStream.d.mts.map +0 -1
  565. package/lib/odspDelayLoadedDeltaStream.mjs.map +0 -1
  566. package/lib/odspDeltaStorageService.d.mts.map +0 -1
  567. package/lib/odspDeltaStorageService.mjs.map +0 -1
  568. package/lib/odspDocumentDeltaConnection.d.mts.map +0 -1
  569. package/lib/odspDocumentDeltaConnection.mjs.map +0 -1
  570. package/lib/odspDocumentService.d.mts.map +0 -1
  571. package/lib/odspDocumentService.mjs.map +0 -1
  572. package/lib/odspDocumentServiceFactory.d.mts.map +0 -1
  573. package/lib/odspDocumentServiceFactory.mjs.map +0 -1
  574. package/lib/odspDocumentServiceFactoryCore.d.mts.map +0 -1
  575. package/lib/odspDocumentServiceFactoryCore.mjs.map +0 -1
  576. package/lib/odspDocumentServiceFactoryWithCodeSplit.d.mts.map +0 -1
  577. package/lib/odspDocumentServiceFactoryWithCodeSplit.mjs.map +0 -1
  578. package/lib/odspDocumentStorageManager.d.mts.map +0 -1
  579. package/lib/odspDocumentStorageManager.mjs.map +0 -1
  580. package/lib/odspDocumentStorageServiceBase.d.mts.map +0 -1
  581. package/lib/odspDocumentStorageServiceBase.mjs.map +0 -1
  582. package/lib/odspDriverUrlResolver.d.mts.map +0 -1
  583. package/lib/odspDriverUrlResolver.mjs.map +0 -1
  584. package/lib/odspDriverUrlResolverForShareLink.d.mts.map +0 -1
  585. package/lib/odspDriverUrlResolverForShareLink.mjs.map +0 -1
  586. package/lib/odspError.d.mts.map +0 -1
  587. package/lib/odspError.mjs.map +0 -1
  588. package/lib/odspFluidFileLink.d.mts.map +0 -1
  589. package/lib/odspFluidFileLink.mjs.map +0 -1
  590. package/lib/odspLocationRedirection.d.mts.map +0 -1
  591. package/lib/odspLocationRedirection.mjs.map +0 -1
  592. package/lib/odspPublicUtils.d.mts.map +0 -1
  593. package/lib/odspPublicUtils.mjs.map +0 -1
  594. package/lib/odspSnapshotParser.d.mts.map +0 -1
  595. package/lib/odspSnapshotParser.mjs.map +0 -1
  596. package/lib/odspSummaryUploadManager.d.mts.map +0 -1
  597. package/lib/odspSummaryUploadManager.mjs.map +0 -1
  598. package/lib/odspUrlHelper.d.mts.map +0 -1
  599. package/lib/odspUrlHelper.mjs.map +0 -1
  600. package/lib/odspUtils.d.mts.map +0 -1
  601. package/lib/odspUtils.mjs.map +0 -1
  602. package/lib/opsCaching.d.mts.map +0 -1
  603. package/lib/opsCaching.mjs.map +0 -1
  604. package/lib/packageVersion.d.mts.map +0 -1
  605. package/lib/packageVersion.mjs.map +0 -1
  606. package/lib/prefetchLatestSnapshot.d.mts.map +0 -1
  607. package/lib/prefetchLatestSnapshot.mjs.map +0 -1
  608. package/lib/retryErrorsStorageAdapter.d.mts.map +0 -1
  609. package/lib/retryErrorsStorageAdapter.mjs.map +0 -1
  610. package/lib/retryUtils.d.mts.map +0 -1
  611. package/lib/retryUtils.mjs.map +0 -1
  612. package/lib/socketModule.d.mts.map +0 -1
  613. package/lib/socketModule.mjs.map +0 -1
  614. package/lib/vroom.d.mts.map +0 -1
  615. package/lib/vroom.mjs.map +0 -1
  616. package/lib/zipItDataRepresentationUtils.d.mts.map +0 -1
  617. package/lib/zipItDataRepresentationUtils.mjs.map +0 -1
@@ -10,12 +10,12 @@ const core_utils_1 = require("@fluidframework/core-utils");
10
10
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
11
11
  const driver_utils_1 = require("@fluidframework/driver-utils");
12
12
  const odsp_driver_definitions_1 = require("@fluidframework/odsp-driver-definitions");
13
- const odsp_doclib_utils_1 = require("@fluidframework/odsp-doclib-utils");
14
- const odspDocumentDeltaConnection_1 = require("./odspDocumentDeltaConnection");
15
- const odspUtils_1 = require("./odspUtils");
16
- const vroom_1 = require("./vroom");
17
- const packageVersion_1 = require("./packageVersion");
18
- const contracts_1 = require("./contracts");
13
+ const internal_1 = require("@fluidframework/odsp-doclib-utils/internal");
14
+ const odspDocumentDeltaConnection_js_1 = require("./odspDocumentDeltaConnection.js");
15
+ const odspUtils_js_1 = require("./odspUtils.js");
16
+ const vroom_js_1 = require("./vroom.js");
17
+ const packageVersion_js_1 = require("./packageVersion.js");
18
+ const contracts_js_1 = require("./contracts.js");
19
19
  /**
20
20
  * This OdspDelayLoadedDeltaStream is used by OdspDocumentService.ts to delay load the delta connection
21
21
  * as they are not on critical path of loading a container.
@@ -55,7 +55,7 @@ class OdspDelayLoadedDeltaStream {
55
55
  this.labelUpdateTimestamp = -1;
56
56
  this.signalHandler = (signalsArg) => {
57
57
  const signals = Array.isArray(signalsArg) ? signalsArg : [signalsArg];
58
- signals.forEach((signal) => {
58
+ for (const signal of signals) {
59
59
  // Make sure it is not for a specific client as `PolicyLabelsUpdate` is meant for all clients.
60
60
  if (signal.clientId === null) {
61
61
  // We could have some issues/irregularities in parsing signals, so put it in try/catch block
@@ -64,16 +64,18 @@ class OdspDelayLoadedDeltaStream {
64
64
  try {
65
65
  envelope = JSON.parse(signal.content);
66
66
  }
67
- catch (err) { }
68
- if (envelope?.contents?.type === contracts_1.policyLabelsUpdatesSignalType) {
67
+ catch {
68
+ // Drop error
69
+ }
70
+ if (envelope?.contents?.type === contracts_js_1.policyLabelsUpdatesSignalType) {
69
71
  this.emitMetaDataUpdateEvent({
70
72
  sensitivityLabelsInfo: JSON.stringify(envelope.contents.content),
71
73
  });
72
74
  }
73
75
  }
74
- });
76
+ }
75
77
  };
76
- this.joinSessionKey = (0, odspUtils_1.getJoinSessionCacheKey)(this.odspResolvedUrl);
78
+ this.joinSessionKey = (0, odspUtils_js_1.getJoinSessionCacheKey)(this.odspResolvedUrl);
77
79
  }
78
80
  get resolvedUrl() {
79
81
  return this.odspResolvedUrl;
@@ -84,7 +86,9 @@ class OdspDelayLoadedDeltaStream {
84
86
  get relayServiceTenantAndSessionId() {
85
87
  return this._relayServiceTenantAndSessionId;
86
88
  }
87
- /** Annotate the given error indicating which connection step failed */
89
+ /**
90
+ * Annotate the given error indicating which connection step failed
91
+ */
88
92
  annotateConnectionError(error, failedConnectionStep, separateTokenRequest) {
89
93
  return (0, telemetry_utils_1.normalizeError)(error, {
90
94
  props: {
@@ -101,12 +105,13 @@ class OdspDelayLoadedDeltaStream {
101
105
  async connectToDeltaStream(client) {
102
106
  (0, core_utils_1.assert)(this.currentConnection === undefined, 0x4ad /* Should not be called when connection is already present! */);
103
107
  // Attempt to connect twice, in case we used expired token.
104
- return (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
108
+ return (0, odspUtils_js_1.getWithRetryForTokenRefresh)(async (options) => {
105
109
  // Presence of getWebsocketToken callback dictates whether callback is used for fetching
106
110
  // websocket token or whether it is returned with joinSession response payload
107
111
  const requestWebsocketTokenFromJoinSession = this.getWebsocketToken === undefined;
108
112
  const websocketTokenPromise = requestWebsocketTokenFromJoinSession
109
- ? Promise.resolve(null)
113
+ ? // eslint-disable-next-line unicorn/no-null
114
+ Promise.resolve(null)
110
115
  : this.getWebsocketToken(options);
111
116
  const annotateAndRethrowConnectionError = (step) => (error) => {
112
117
  throw this.annotateConnectionError(error, step, !requestWebsocketTokenFromJoinSession);
@@ -116,9 +121,10 @@ class OdspDelayLoadedDeltaStream {
116
121
  joinSessionPromise.catch(annotateAndRethrowConnectionError("joinSession")),
117
122
  websocketTokenPromise.catch(annotateAndRethrowConnectionError("getWebsocketToken")),
118
123
  ]);
124
+ // eslint-disable-next-line unicorn/no-null
119
125
  const finalWebsocketToken = websocketToken ?? websocketEndpoint.socketToken ?? null;
120
126
  if (finalWebsocketToken === null) {
121
- throw this.annotateConnectionError(new driver_utils_1.NonRetryableError("Websocket token is null", odsp_driver_definitions_1.OdspErrorTypes.fetchTokenError, { driverVersion: packageVersion_1.pkgVersion }), "getWebsocketToken", !requestWebsocketTokenFromJoinSession);
127
+ throw this.annotateConnectionError(new driver_utils_1.NonRetryableError("Websocket token is null", odsp_driver_definitions_1.OdspErrorTypes.fetchTokenError, { driverVersion: packageVersion_js_1.pkgVersion }), "getWebsocketToken", !requestWebsocketTokenFromJoinSession);
122
128
  }
123
129
  if (websocketEndpoint.sensitivityLabelsInfo !== undefined) {
124
130
  this.emitMetaDataUpdateEvent({
@@ -140,7 +146,8 @@ class OdspDelayLoadedDeltaStream {
140
146
  this.clearJoinSessionTimer();
141
147
  if (typeof error === "object" &&
142
148
  error !== null &&
143
- error.errorType === odsp_driver_definitions_1.OdspErrorTypes.authorizationError) {
149
+ error.errorType ===
150
+ odsp_driver_definitions_1.OdspErrorTypes.authorizationError) {
144
151
  this.cache.sessionJoinCache.remove(this.joinSessionKey);
145
152
  }
146
153
  // If we hit this assert, it means that "disconnect" event is emitted before the connection went through
@@ -173,18 +180,22 @@ class OdspDelayLoadedDeltaStream {
173
180
  async scheduleJoinSessionRefresh(delta, requestSocketToken, clientId) {
174
181
  if (this.joinSessionRefreshTimer !== undefined) {
175
182
  this.clearJoinSessionTimer();
183
+ // TODO: use a stronger type
184
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
176
185
  const originalStackTraceLimit = Error.stackTraceLimit;
186
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
177
187
  Error.stackTraceLimit = 50;
178
188
  this.mc.logger.sendTelemetryEvent({
179
189
  eventName: "DuplicateJoinSessionRefresh",
180
190
  }, new Error("DuplicateJoinSessionRefresh"));
191
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
181
192
  Error.stackTraceLimit = originalStackTraceLimit;
182
193
  }
183
194
  await new Promise((resolve, reject) => {
184
195
  this.joinSessionRefreshTimer = setTimeout(() => {
185
196
  this.clearJoinSessionTimer();
186
197
  // Clear the timer as it is going to be scheduled again as part of refreshing join session.
187
- (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
198
+ (0, odspUtils_js_1.getWithRetryForTokenRefresh)(async (options) => {
188
199
  await this.joinSession(requestSocketToken, options, true /* isRefreshingJoinSession */, clientId);
189
200
  resolve();
190
201
  }).catch((error) => {
@@ -203,34 +214,36 @@ class OdspDelayLoadedDeltaStream {
203
214
  (clientId !== undefined && this.currentConnection.clientId !== clientId))) {
204
215
  this.clearJoinSessionTimer();
205
216
  throw new driver_utils_1.NonRetryableError("JoinSessionRefreshTimerNotCancelled", odsp_driver_definitions_1.OdspErrorTypes.genericError, {
206
- driverVersion: packageVersion_1.pkgVersion,
217
+ driverVersion: packageVersion_js_1.pkgVersion,
207
218
  details: JSON.stringify({
208
219
  schedulerClientId: clientId,
209
220
  currentClientId: this.currentConnection?.clientId,
210
221
  }),
211
222
  });
212
223
  }
213
- const response = await this.joinSessionCore(requestSocketToken, options, isRefreshingJoinSession).catch((e) => {
214
- if ((0, odsp_doclib_utils_1.hasFacetCodes)(e) && e.facetCodes !== undefined) {
215
- for (const code of e.facetCodes) {
224
+ const response = await this.joinSessionCore(requestSocketToken, options, isRefreshingJoinSession).catch((error) => {
225
+ if ((0, internal_1.hasFacetCodes)(error) && error.facetCodes !== undefined) {
226
+ for (const code of error.facetCodes) {
216
227
  switch (code) {
217
228
  case "sessionForbidden":
218
229
  case "sessionForbiddenOnPreservedFiles":
219
230
  case "sessionForbiddenOnModerationEnabledLibrary":
220
231
  case "sessionForbiddenOnRequireCheckout":
221
232
  case "sessionForbiddenOnCheckoutFile":
222
- case "sessionForbiddenOnInvisibleMinorVersion":
233
+ case "sessionForbiddenOnInvisibleMinorVersion": {
223
234
  // This document can only be opened in storage-only mode.
224
235
  // DeltaManager will recognize this error
225
236
  // and load without a delta stream connection.
226
237
  this.policies = { ...this.policies, storageOnly: true };
227
- throw new driver_utils_1.DeltaStreamConnectionForbiddenError(`Storage-only due to ${code}`, { driverVersion: packageVersion_1.pkgVersion }, code);
228
- default:
238
+ throw new driver_utils_1.DeltaStreamConnectionForbiddenError(`Storage-only due to ${code}`, { driverVersion: packageVersion_js_1.pkgVersion }, code);
239
+ }
240
+ default: {
229
241
  continue;
242
+ }
230
243
  }
231
244
  }
232
245
  }
233
- throw e;
246
+ throw error;
234
247
  });
235
248
  this._relayServiceTenantAndSessionId = `${response.tenantId}/${response.id}`;
236
249
  return response;
@@ -238,7 +251,7 @@ class OdspDelayLoadedDeltaStream {
238
251
  async joinSessionCore(requestSocketToken, options, isRefreshingJoinSession) {
239
252
  const disableJoinSessionRefresh = this.mc.config.getBoolean("Fluid.Driver.Odsp.disableJoinSessionRefresh");
240
253
  const executeFetch = async () => {
241
- const joinSessionResponse = await (0, vroom_1.fetchJoinSession)(this.odspResolvedUrl, "opStream/joinSession", "POST", this.mc.logger, this.getStorageToken, this.epochTracker, requestSocketToken, options, disableJoinSessionRefresh, isRefreshingJoinSession, this.hostPolicy.sessionOptions?.unauthenticatedUserDisplayName);
254
+ const joinSessionResponse = await (0, vroom_js_1.fetchJoinSession)(this.odspResolvedUrl, "opStream/joinSession", "POST", this.mc.logger, this.getStorageToken, this.epochTracker, requestSocketToken, options, disableJoinSessionRefresh, isRefreshingJoinSession, this.hostPolicy.sessionOptions?.unauthenticatedUserDisplayName);
242
255
  // Emit event only in case it is fetched from the network.
243
256
  if (joinSessionResponse.sensitivityLabelsInfo !== undefined) {
244
257
  this.emitMetaDataUpdateEvent({
@@ -296,7 +309,7 @@ class OdspDelayLoadedDeltaStream {
296
309
  emitMetaDataUpdateEvent(metadata) {
297
310
  const label = JSON.parse(metadata.sensitivityLabelsInfo);
298
311
  const time = label.timestamp;
299
- (0, core_utils_1.assert)(time > 0, "time should be positive");
312
+ (0, core_utils_1.assert)(time > 0, 0x8e0 /* time should be positive */);
300
313
  if (time > this.labelUpdateTimestamp) {
301
314
  this.labelUpdateTimestamp = time;
302
315
  this.metadataUpdateHandler({
@@ -319,7 +332,7 @@ class OdspDelayLoadedDeltaStream {
319
332
  */
320
333
  async createDeltaConnection(tenantId, documentId, token, client, webSocketUrl) {
321
334
  const startTime = client_utils_1.performance.now();
322
- const connection = await odspDocumentDeltaConnection_1.OdspDocumentDeltaConnection.create(tenantId, documentId, token, client, webSocketUrl, this.mc.logger, 60000, this.epochTracker, this.socketReferenceKeyPrefix);
335
+ const connection = await odspDocumentDeltaConnection_js_1.OdspDocumentDeltaConnection.create(tenantId, documentId, token, client, webSocketUrl, this.mc.logger, 60000, this.epochTracker, this.socketReferenceKeyPrefix);
323
336
  const duration = client_utils_1.performance.now() - startTime;
324
337
  // This event happens rather often, so it adds up to cost of telemetry.
325
338
  // Given that most reconnects result in reusing socket and happen very quickly,
@@ -1 +1 @@
1
- {"version":3,"file":"odspDelayLoadedDeltaStream.js","sourceRoot":"","sources":["../src/odspDelayLoadedDeltaStream.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAE3D,2DAAoD;AACpD,qEAIyC;AAMzC,+DAGsC;AAMtC,qFAOiD;AACjD,yEAAkE;AAElE,+EAA4E;AAC5E,2CAIqB;AACrB,mCAA2C;AAE3C,qDAA+D;AAC/D,2CAA4D;AAE5D;;;GAGG;AACH,MAAa,0BAA0B;IAgBtC;;;;;;;;;;;;;;OAcG;IACH,YACiB,eAAiC,EAC1C,QAAkC,EACxB,eAAgD,EAChD,iBAEL,EACK,EAAqB,EACrB,KAAiB,EACjB,UAA6B,EAC7B,YAA0B,EAC1B,WAAuD,EACvD,qBAAiE,EACjE,wBAAiC;QAZlC,oBAAe,GAAf,eAAe,CAAkB;QAC1C,aAAQ,GAAR,QAAQ,CAA0B;QACxB,oBAAe,GAAf,eAAe,CAAiC;QAChD,sBAAiB,GAAjB,iBAAiB,CAEt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C;IACnB,CAAC;IAEM,OAAO,CAAC,KAAW;QACzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,IAAI,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAC;QAClC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;IACpC,CAAC;CACD;AAndD,gEAmdC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ISignalEnvelope } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tIFluidErrorBase,\n\tMonitoringContext,\n\tnormalizeError,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tIDocumentDeltaConnection,\n\tIResolvedUrl,\n\tIDocumentServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tDeltaStreamConnectionForbiddenError,\n\tNonRetryableError,\n} from \"@fluidframework/driver-utils\";\nimport {\n\tIClient,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOdspResolvedUrl,\n\tTokenFetchOptions,\n\tHostStoragePolicy,\n\tInstrumentedStorageTokenFetcher,\n\tISocketStorageDiscovery,\n\tOdspErrorTypes,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { hasFacetCodes } from \"@fluidframework/odsp-doclib-utils\";\nimport { IOdspCache } from \"./odspCache\";\nimport { OdspDocumentDeltaConnection } from \"./odspDocumentDeltaConnection\";\nimport {\n\tgetJoinSessionCacheKey,\n\tgetWithRetryForTokenRefresh,\n\tTokenFetchOptionsEx,\n} from \"./odspUtils\";\nimport { fetchJoinSession } from \"./vroom\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { policyLabelsUpdatesSignalType } from \"./contracts\";\n\n/**\n * This OdspDelayLoadedDeltaStream is used by OdspDocumentService.ts to delay load the delta connection\n * as they are not on critical path of loading a container.\n */\nexport class OdspDelayLoadedDeltaStream {\n\t// Timer which runs and executes the join session call after intervals.\n\tprivate joinSessionRefreshTimer: ReturnType<typeof setTimeout> | undefined;\n\n\tprivate readonly joinSessionKey: string;\n\n\tprivate currentConnection?: OdspDocumentDeltaConnection;\n\n\tprivate _relayServiceTenantAndSessionId: string | undefined;\n\n\t// Tracks the time at which the Policy Labels were updated the last time. This is used to resolve race conditions\n\t// between label updates from the join session and the Fluid signals and they could have same or different timestamps.\n\t// So this timestamp is updated with timestamp from the service/signals with the most recent timestamp. We could also\n\t// receive stale data from join session as that call is made at intervals, so we need to update with only most recent data.\n\tprivate labelUpdateTimestamp: number = -1;\n\n\t/**\n\t * @param odspResolvedUrl - resolved url identifying document that will be managed by this service instance.\n\t * @param policies - Document service policies.\n\t * @param getStorageToken - function that can provide the storage token. This is is also referred to as\n\t * the \"Vroom\" token in SPO.\n\t * @param getWebsocketToken - function that can provide a token for accessing the web socket. This is also referred\n\t * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n\t * response payload.\n\t * @param mc - a logger that can capture performance and diagnostic information\n\t * @param cache - This caches response for joinSession.\n\t * @param hostPolicy - host constructed policy which customizes service behavior.\n\t * @param epochTracker - This helper class which adds epoch to backend calls made by this service instance.\n\t * @param opsReceived - To register the ops received through socket.\n\t * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n\t */\n\tpublic constructor(\n\t\tpublic readonly odspResolvedUrl: IOdspResolvedUrl,\n\t\tpublic policies: IDocumentServicePolicies,\n\t\tprivate readonly getStorageToken: InstrumentedStorageTokenFetcher,\n\t\tprivate readonly getWebsocketToken:\n\t\t\t| ((options: TokenFetchOptions) => Promise<string | null>)\n\t\t\t| undefined,\n\t\tprivate readonly mc: MonitoringContext,\n\t\tprivate readonly cache: IOdspCache,\n\t\tprivate readonly hostPolicy: HostStoragePolicy,\n\t\tprivate readonly epochTracker: EpochTracker,\n\t\tprivate readonly opsReceived: (ops: ISequencedDocumentMessage[]) => void,\n\t\tprivate readonly metadataUpdateHandler: (metadata: Record<string, string>) => void,\n\t\tprivate readonly socketReferenceKeyPrefix?: string,\n\t) {\n\t\tthis.joinSessionKey = getJoinSessionCacheKey(this.odspResolvedUrl);\n\t}\n\n\tpublic get resolvedUrl(): IResolvedUrl {\n\t\treturn this.odspResolvedUrl;\n\t}\n\n\tpublic get currentDeltaConnection(): OdspDocumentDeltaConnection | undefined {\n\t\treturn this.currentConnection;\n\t}\n\n\tpublic get relayServiceTenantAndSessionId(): string | undefined {\n\t\treturn this._relayServiceTenantAndSessionId;\n\t}\n\n\t/** Annotate the given error indicating which connection step failed */\n\tprivate annotateConnectionError(\n\t\terror: any,\n\t\tfailedConnectionStep: string,\n\t\tseparateTokenRequest: boolean,\n\t): IFluidErrorBase {\n\t\treturn normalizeError(error, {\n\t\t\tprops: {\n\t\t\t\tfailedConnectionStep,\n\t\t\t\tseparateTokenRequest,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Connects to a delta stream endpoint for emitting ops.\n\t *\n\t * @returns returns the document delta stream service for onedrive/sharepoint driver.\n\t */\n\tpublic async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n\t\tassert(\n\t\t\tthis.currentConnection === undefined,\n\t\t\t0x4ad /* Should not be called when connection is already present! */,\n\t\t);\n\t\t// Attempt to connect twice, in case we used expired token.\n\t\treturn getWithRetryForTokenRefresh<IDocumentDeltaConnection>(async (options) => {\n\t\t\t// Presence of getWebsocketToken callback dictates whether callback is used for fetching\n\t\t\t// websocket token or whether it is returned with joinSession response payload\n\t\t\tconst requestWebsocketTokenFromJoinSession = this.getWebsocketToken === undefined;\n\t\t\tconst websocketTokenPromise = requestWebsocketTokenFromJoinSession\n\t\t\t\t? Promise.resolve(null)\n\t\t\t\t: this.getWebsocketToken!(options);\n\n\t\t\tconst annotateAndRethrowConnectionError = (step: string) => (error: any) => {\n\t\t\t\tthrow this.annotateConnectionError(\n\t\t\t\t\terror,\n\t\t\t\t\tstep,\n\t\t\t\t\t!requestWebsocketTokenFromJoinSession,\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tconst joinSessionPromise = this.joinSession(\n\t\t\t\trequestWebsocketTokenFromJoinSession,\n\t\t\t\toptions,\n\t\t\t\tfalse /* isRefreshingJoinSession */,\n\t\t\t);\n\t\t\tconst [websocketEndpoint, websocketToken] = await Promise.all([\n\t\t\t\tjoinSessionPromise.catch(annotateAndRethrowConnectionError(\"joinSession\")),\n\t\t\t\twebsocketTokenPromise.catch(annotateAndRethrowConnectionError(\"getWebsocketToken\")),\n\t\t\t]);\n\n\t\t\tconst finalWebsocketToken = websocketToken ?? websocketEndpoint.socketToken ?? null;\n\t\t\tif (finalWebsocketToken === null) {\n\t\t\t\tthrow this.annotateConnectionError(\n\t\t\t\t\tnew NonRetryableError(\n\t\t\t\t\t\t\"Websocket token is null\",\n\t\t\t\t\t\tOdspErrorTypes.fetchTokenError,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t),\n\t\t\t\t\t\"getWebsocketToken\",\n\t\t\t\t\t!requestWebsocketTokenFromJoinSession,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (websocketEndpoint.sensitivityLabelsInfo !== undefined) {\n\t\t\t\tthis.emitMetaDataUpdateEvent({\n\t\t\t\t\tsensitivityLabelsInfo: websocketEndpoint.sensitivityLabelsInfo,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst connection = await this.createDeltaConnection(\n\t\t\t\t\twebsocketEndpoint.tenantId,\n\t\t\t\t\twebsocketEndpoint.id,\n\t\t\t\t\tfinalWebsocketToken,\n\t\t\t\t\tclient,\n\t\t\t\t\twebsocketEndpoint.deltaStreamSocketUrl,\n\t\t\t\t);\n\t\t\t\tconnection.on(\"op\", (documentId, ops: ISequencedDocumentMessage[]) => {\n\t\t\t\t\tthis.opsReceived(ops);\n\t\t\t\t});\n\t\t\t\tconnection.on(\"signal\", this.signalHandler);\n\t\t\t\t// Also process the initial signals\n\t\t\t\tthis.signalHandler(connection.initialSignals);\n\t\t\t\t// On disconnect with 401/403 error code, we can just clear the joinSession cache as we will again\n\t\t\t\t// get the auth error on reconnecting and face latency.\n\t\t\t\tconnection.once(\"disconnect\", (error: any) => {\n\t\t\t\t\t// Clear the join session refresh timer so that it can be restarted on reconnection.\n\t\t\t\t\tthis.clearJoinSessionTimer();\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof error === \"object\" &&\n\t\t\t\t\t\terror !== null &&\n\t\t\t\t\t\terror.errorType === OdspErrorTypes.authorizationError\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.cache.sessionJoinCache.remove(this.joinSessionKey);\n\t\t\t\t\t}\n\t\t\t\t\t// If we hit this assert, it means that \"disconnect\" event is emitted before the connection went through\n\t\t\t\t\t// dispose flow which is not correct and could lead to a bunch of errors.\n\t\t\t\t\tassert(connection.disposed, 0x4ae /* Connection should be disposed by now */);\n\t\t\t\t\tthis.currentConnection = undefined;\n\t\t\t\t});\n\t\t\t\tthis.currentConnection = connection;\n\t\t\t\treturn connection;\n\t\t\t} catch (error) {\n\t\t\t\tthis.clearJoinSessionTimer();\n\t\t\t\tthis.cache.sessionJoinCache.remove(this.joinSessionKey);\n\n\t\t\t\tconst normalizedError = this.annotateConnectionError(\n\t\t\t\t\terror,\n\t\t\t\t\t\"createDeltaConnection\",\n\t\t\t\t\t!requestWebsocketTokenFromJoinSession,\n\t\t\t\t);\n\t\t\t\tif (typeof error === \"object\" && error !== null) {\n\t\t\t\t\tnormalizedError.addTelemetryProperties({\n\t\t\t\t\t\tsocketDocumentId: websocketEndpoint.id,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow normalizedError;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate readonly signalHandler = (signalsArg: ISignalMessage | ISignalMessage[]) => {\n\t\tconst signals = Array.isArray(signalsArg) ? signalsArg : [signalsArg];\n\t\tsignals.forEach((signal: ISignalMessage) => {\n\t\t\t// Make sure it is not for a specific client as `PolicyLabelsUpdate` is meant for all clients.\n\t\t\tif (signal.clientId === null) {\n\t\t\t\t// We could have some issues/irregularities in parsing signals, so put it in try/catch block\n\t\t\t\t// and ignore the error as we can have labels update later on through join session response.\n\t\t\t\tlet envelope: ISignalEnvelope | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tenvelope = JSON.parse(signal.content as string) as ISignalEnvelope;\n\t\t\t\t} catch (err) {}\n\t\t\t\tif (envelope?.contents?.type === policyLabelsUpdatesSignalType) {\n\t\t\t\t\tthis.emitMetaDataUpdateEvent({\n\t\t\t\t\t\tsensitivityLabelsInfo: JSON.stringify(envelope.contents.content),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\n\tprivate clearJoinSessionTimer() {\n\t\tif (this.joinSessionRefreshTimer !== undefined) {\n\t\t\tclearTimeout(this.joinSessionRefreshTimer);\n\t\t\tthis.joinSessionRefreshTimer = undefined;\n\t\t}\n\t}\n\n\tprivate async scheduleJoinSessionRefresh(\n\t\tdelta: number,\n\t\trequestSocketToken: boolean,\n\t\tclientId: string | undefined,\n\t) {\n\t\tif (this.joinSessionRefreshTimer !== undefined) {\n\t\t\tthis.clearJoinSessionTimer();\n\t\t\tconst originalStackTraceLimit = (Error as any).stackTraceLimit;\n\t\t\t(Error as any).stackTraceLimit = 50;\n\t\t\tthis.mc.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"DuplicateJoinSessionRefresh\",\n\t\t\t\t},\n\t\t\t\tnew Error(\"DuplicateJoinSessionRefresh\"),\n\t\t\t);\n\t\t\t(Error as any).stackTraceLimit = originalStackTraceLimit;\n\t\t}\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.joinSessionRefreshTimer = setTimeout(() => {\n\t\t\t\tthis.clearJoinSessionTimer();\n\t\t\t\t// Clear the timer as it is going to be scheduled again as part of refreshing join session.\n\t\t\t\tgetWithRetryForTokenRefresh(async (options) => {\n\t\t\t\t\tawait this.joinSession(\n\t\t\t\t\t\trequestSocketToken,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\ttrue /* isRefreshingJoinSession */,\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t);\n\t\t\t\t\tresolve();\n\t\t\t\t}).catch((error) => {\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t\t}, delta);\n\t\t});\n\t}\n\n\tprivate async joinSession(\n\t\trequestSocketToken: boolean,\n\t\toptions: TokenFetchOptionsEx,\n\t\tisRefreshingJoinSession: boolean,\n\t\tclientId?: string,\n\t) {\n\t\t// If this call is to refresh the join session for the current connection but we are already disconnected in\n\t\t// the meantime or disconnected and then reconnected then do not make the call. However, we should not have\n\t\t// come here if that is the case because timer should have been disposed, but due to race condition with the\n\t\t// timer we should not make the call and throw error.\n\t\tif (\n\t\t\tisRefreshingJoinSession &&\n\t\t\t(this.currentConnection === undefined ||\n\t\t\t\t(clientId !== undefined && this.currentConnection.clientId !== clientId))\n\t\t) {\n\t\t\tthis.clearJoinSessionTimer();\n\t\t\tthrow new NonRetryableError(\n\t\t\t\t\"JoinSessionRefreshTimerNotCancelled\",\n\t\t\t\tOdspErrorTypes.genericError,\n\t\t\t\t{\n\t\t\t\t\tdriverVersion,\n\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\tschedulerClientId: clientId,\n\t\t\t\t\t\tcurrentClientId: this.currentConnection?.clientId,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tconst response = await this.joinSessionCore(\n\t\t\trequestSocketToken,\n\t\t\toptions,\n\t\t\tisRefreshingJoinSession,\n\t\t).catch((e) => {\n\t\t\tif (hasFacetCodes(e) && e.facetCodes !== undefined) {\n\t\t\t\tfor (const code of e.facetCodes) {\n\t\t\t\t\tswitch (code) {\n\t\t\t\t\t\tcase \"sessionForbidden\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnPreservedFiles\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnModerationEnabledLibrary\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnRequireCheckout\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnCheckoutFile\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnInvisibleMinorVersion\":\n\t\t\t\t\t\t\t// This document can only be opened in storage-only mode.\n\t\t\t\t\t\t\t// DeltaManager will recognize this error\n\t\t\t\t\t\t\t// and load without a delta stream connection.\n\t\t\t\t\t\t\tthis.policies = { ...this.policies, storageOnly: true };\n\t\t\t\t\t\t\tthrow new DeltaStreamConnectionForbiddenError(\n\t\t\t\t\t\t\t\t`Storage-only due to ${code}`,\n\t\t\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow e;\n\t\t});\n\t\tthis._relayServiceTenantAndSessionId = `${response.tenantId}/${response.id}`;\n\t\treturn response;\n\t}\n\n\tprivate async joinSessionCore(\n\t\trequestSocketToken: boolean,\n\t\toptions: TokenFetchOptionsEx,\n\t\tisRefreshingJoinSession: boolean,\n\t): Promise<ISocketStorageDiscovery> {\n\t\tconst disableJoinSessionRefresh = this.mc.config.getBoolean(\n\t\t\t\"Fluid.Driver.Odsp.disableJoinSessionRefresh\",\n\t\t);\n\t\tconst executeFetch = async () => {\n\t\t\tconst joinSessionResponse = await fetchJoinSession(\n\t\t\t\tthis.odspResolvedUrl,\n\t\t\t\t\"opStream/joinSession\",\n\t\t\t\t\"POST\",\n\t\t\t\tthis.mc.logger,\n\t\t\t\tthis.getStorageToken,\n\t\t\t\tthis.epochTracker,\n\t\t\t\trequestSocketToken,\n\t\t\t\toptions,\n\t\t\t\tdisableJoinSessionRefresh,\n\t\t\t\tisRefreshingJoinSession,\n\t\t\t\tthis.hostPolicy.sessionOptions?.unauthenticatedUserDisplayName,\n\t\t\t);\n\t\t\t// Emit event only in case it is fetched from the network.\n\t\t\tif (joinSessionResponse.sensitivityLabelsInfo !== undefined) {\n\t\t\t\tthis.emitMetaDataUpdateEvent({\n\t\t\t\t\tsensitivityLabelsInfo: joinSessionResponse.sensitivityLabelsInfo,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryTime: Date.now(),\n\t\t\t\tjoinSessionResponse,\n\t\t\t};\n\t\t};\n\n\t\tconst getResponseAndRefreshAfterDeltaMs = async () => {\n\t\t\tconst _response = await this.cache.sessionJoinCache.addOrGet(\n\t\t\t\tthis.joinSessionKey,\n\t\t\t\texecuteFetch,\n\t\t\t);\n\t\t\t// If the response does not contain refreshSessionDurationSeconds, then treat it as old flow and let the\n\t\t\t// cache entry to be treated as expired after 1 hour.\n\t\t\t_response.joinSessionResponse.refreshSessionDurationSeconds =\n\t\t\t\t_response.joinSessionResponse.refreshSessionDurationSeconds ?? 3600;\n\t\t\treturn {\n\t\t\t\t..._response,\n\t\t\t\trefreshAfterDeltaMs: this.calculateJoinSessionRefreshDelta(\n\t\t\t\t\t_response.entryTime,\n\t\t\t\t\t_response.joinSessionResponse.refreshSessionDurationSeconds,\n\t\t\t\t),\n\t\t\t};\n\t\t};\n\t\tlet response = await getResponseAndRefreshAfterDeltaMs();\n\t\t// This means that the cached entry has expired(This should not be possible if the response is fetched\n\t\t// from the network call). In this case we remove the cached entry and fetch the new response.\n\t\tif (response.refreshAfterDeltaMs <= 0) {\n\t\t\tthis.cache.sessionJoinCache.remove(this.joinSessionKey);\n\t\t\tresponse = await getResponseAndRefreshAfterDeltaMs();\n\t\t}\n\t\tif (!disableJoinSessionRefresh) {\n\t\t\tconst props = {\n\t\t\t\tentryTime: response.entryTime,\n\t\t\t\trefreshSessionDurationSeconds:\n\t\t\t\t\tresponse.joinSessionResponse.refreshSessionDurationSeconds,\n\t\t\t\trefreshAfterDeltaMs: response.refreshAfterDeltaMs,\n\t\t\t};\n\t\t\tif (response.refreshAfterDeltaMs > 0) {\n\t\t\t\tthis.scheduleJoinSessionRefresh(\n\t\t\t\t\tresponse.refreshAfterDeltaMs,\n\t\t\t\t\trequestSocketToken,\n\t\t\t\t\tthis.currentConnection?.clientId,\n\t\t\t\t).catch((error) => {\n\t\t\t\t\t// Log the error and do nothing as the reconnection would fetch the join session.\n\t\t\t\t\tthis.mc.logger.sendTelemetryEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"JoinSessionRefreshError\",\n\t\t\t\t\t\t\tdetails: JSON.stringify(props),\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\t// Logging just for informational purposes to help with debugging as this is a new feature.\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"JoinSessionRefreshNotScheduled\",\n\t\t\t\t\tdetails: JSON.stringify(props),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn response.joinSessionResponse;\n\t}\n\n\tprivate emitMetaDataUpdateEvent(metadata: Record<string, string>) {\n\t\tconst label = JSON.parse(metadata.sensitivityLabelsInfo) as {\n\t\t\tlabels: unknown;\n\t\t\ttimestamp: number;\n\t\t};\n\t\tconst time = label.timestamp;\n\t\tassert(time > 0, \"time should be positive\");\n\t\tif (time > this.labelUpdateTimestamp) {\n\t\t\tthis.labelUpdateTimestamp = time;\n\t\t\tthis.metadataUpdateHandler({\n\t\t\t\tsensitivityLabelsInfo: metadata.sensitivityLabelsInfo,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate calculateJoinSessionRefreshDelta(\n\t\tresponseFetchTime: number,\n\t\trefreshSessionDurationSeconds: number,\n\t) {\n\t\t// 30 seconds is buffer time to refresh the session.\n\t\treturn responseFetchTime + (refreshSessionDurationSeconds * 1000 - 30000) - Date.now();\n\t}\n\n\t/**\n\t * Creates a connection to the given delta stream endpoint\n\t *\n\t * @param tenantId - the ID of the tenant\n\t * @param documentId - document ID\n\t * @param token - authorization token for delta service\n\t * @param client - information about the client\n\t * @param webSocketUrl - websocket URL\n\t */\n\tprivate async createDeltaConnection(\n\t\ttenantId: string,\n\t\tdocumentId: string,\n\t\ttoken: string | null,\n\t\tclient: IClient,\n\t\twebSocketUrl: string,\n\t): Promise<OdspDocumentDeltaConnection> {\n\t\tconst startTime = performance.now();\n\t\tconst connection = await OdspDocumentDeltaConnection.create(\n\t\t\ttenantId,\n\t\t\tdocumentId,\n\t\t\ttoken,\n\t\t\tclient,\n\t\t\twebSocketUrl,\n\t\t\tthis.mc.logger,\n\t\t\t60000,\n\t\t\tthis.epochTracker,\n\t\t\tthis.socketReferenceKeyPrefix,\n\t\t);\n\t\tconst duration = performance.now() - startTime;\n\t\t// This event happens rather often, so it adds up to cost of telemetry.\n\t\t// Given that most reconnects result in reusing socket and happen very quickly,\n\t\t// report event only if it took longer than threshold.\n\t\tif (duration >= 2000) {\n\t\t\tthis.mc.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"ConnectionSuccess\",\n\t\t\t\tduration,\n\t\t\t});\n\t\t}\n\t\treturn connection;\n\t}\n\n\tpublic dispose(error?: any) {\n\t\tthis.clearJoinSessionTimer();\n\t\tthis.currentConnection?.dispose();\n\t\tthis.currentConnection = undefined;\n\t}\n}\n"]}
1
+ {"version":3,"file":"odspDelayLoadedDeltaStream.js","sourceRoot":"","sources":["../src/odspDelayLoadedDeltaStream.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAE3D,2DAAoD;AACpD,qEAIyC;AAMzC,+DAGsC;AAMtC,qFAQiD;AACjD,yEAA2E;AAE3E,qFAA+E;AAC/E,iDAIwB;AACxB,yCAA8C;AAE9C,2DAAkE;AAClE,iDAA+D;AAE/D;;;GAGG;AACH,MAAa,0BAA0B;IAgBtC;;;;;;;;;;;;;;OAcG;IACH,YACiB,eAAiC,EAC1C,QAAkC,EACxB,eAAgD,EAChD,iBAEL,EACK,EAAqB,EACrB,KAAiB,EACjB,UA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C,wBAAwB,CAC7B,CAAC;QACF,MAAM,QAAQ,GAAG,0BAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QAC/C,uEAAuE;QACvE,+EAA+E;QAC/E,sDAAsD;QACtD,IAAI,QAAQ,IAAI,IAAI,EAAE;YACrB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBACnC,SAAS,EAAE,mBAAmB;gBAC9B,QAAQ;aACR,CAAC,CAAC;SACH;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAEM,OAAO,CAAC,KAAe;QAC7B,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,IAAI,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAC;QAClC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;IACpC,CAAC;CACD;AAveD,gEAueC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ISignalEnvelope } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tIFluidErrorBase,\n\tMonitoringContext,\n\tnormalizeError,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tIDocumentDeltaConnection,\n\tIResolvedUrl,\n\tIDocumentServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tDeltaStreamConnectionForbiddenError,\n\tNonRetryableError,\n} from \"@fluidframework/driver-utils\";\nimport {\n\tIClient,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOdspResolvedUrl,\n\tTokenFetchOptions,\n\tHostStoragePolicy,\n\tInstrumentedStorageTokenFetcher,\n\tISocketStorageDiscovery,\n\tOdspErrorTypes,\n\ttype IOdspError,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { hasFacetCodes } from \"@fluidframework/odsp-doclib-utils/internal\";\nimport { IOdspCache } from \"./odspCache.js\";\nimport { OdspDocumentDeltaConnection } from \"./odspDocumentDeltaConnection.js\";\nimport {\n\tgetJoinSessionCacheKey,\n\tgetWithRetryForTokenRefresh,\n\tTokenFetchOptionsEx,\n} from \"./odspUtils.js\";\nimport { fetchJoinSession } from \"./vroom.js\";\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { policyLabelsUpdatesSignalType } from \"./contracts.js\";\n\n/**\n * This OdspDelayLoadedDeltaStream is used by OdspDocumentService.ts to delay load the delta connection\n * as they are not on critical path of loading a container.\n */\nexport class OdspDelayLoadedDeltaStream {\n\t// Timer which runs and executes the join session call after intervals.\n\tprivate joinSessionRefreshTimer: ReturnType<typeof setTimeout> | undefined;\n\n\tprivate readonly joinSessionKey: string;\n\n\tprivate currentConnection?: OdspDocumentDeltaConnection;\n\n\tprivate _relayServiceTenantAndSessionId: string | undefined;\n\n\t// Tracks the time at which the Policy Labels were updated the last time. This is used to resolve race conditions\n\t// between label updates from the join session and the Fluid signals and they could have same or different timestamps.\n\t// So this timestamp is updated with timestamp from the service/signals with the most recent timestamp. We could also\n\t// receive stale data from join session as that call is made at intervals, so we need to update with only most recent data.\n\tprivate labelUpdateTimestamp: number = -1;\n\n\t/**\n\t * @param odspResolvedUrl - resolved url identifying document that will be managed by this service instance.\n\t * @param policies - Document service policies.\n\t * @param getStorageToken - function that can provide the storage token. This is is also referred to as\n\t * the \"Vroom\" token in SPO.\n\t * @param getWebsocketToken - function that can provide a token for accessing the web socket. This is also referred\n\t * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n\t * response payload.\n\t * @param mc - a logger that can capture performance and diagnostic information\n\t * @param cache - This caches response for joinSession.\n\t * @param hostPolicy - host constructed policy which customizes service behavior.\n\t * @param epochTracker - This helper class which adds epoch to backend calls made by this service instance.\n\t * @param opsReceived - To register the ops received through socket.\n\t * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n\t */\n\tpublic constructor(\n\t\tpublic readonly odspResolvedUrl: IOdspResolvedUrl,\n\t\tpublic policies: IDocumentServicePolicies,\n\t\tprivate readonly getStorageToken: InstrumentedStorageTokenFetcher,\n\t\tprivate readonly getWebsocketToken:\n\t\t\t| ((options: TokenFetchOptions) => Promise<string | null>)\n\t\t\t| undefined,\n\t\tprivate readonly mc: MonitoringContext,\n\t\tprivate readonly cache: IOdspCache,\n\t\tprivate readonly hostPolicy: HostStoragePolicy,\n\t\tprivate readonly epochTracker: EpochTracker,\n\t\tprivate readonly opsReceived: (ops: ISequencedDocumentMessage[]) => void,\n\t\tprivate readonly metadataUpdateHandler: (metadata: Record<string, string>) => void,\n\t\tprivate readonly socketReferenceKeyPrefix?: string,\n\t) {\n\t\tthis.joinSessionKey = getJoinSessionCacheKey(this.odspResolvedUrl);\n\t}\n\n\tpublic get resolvedUrl(): IResolvedUrl {\n\t\treturn this.odspResolvedUrl;\n\t}\n\n\tpublic get currentDeltaConnection(): OdspDocumentDeltaConnection | undefined {\n\t\treturn this.currentConnection;\n\t}\n\n\tpublic get relayServiceTenantAndSessionId(): string | undefined {\n\t\treturn this._relayServiceTenantAndSessionId;\n\t}\n\n\t/**\n\t * Annotate the given error indicating which connection step failed\n\t */\n\tprivate annotateConnectionError(\n\t\terror: unknown,\n\t\tfailedConnectionStep: string,\n\t\tseparateTokenRequest: boolean,\n\t): IFluidErrorBase {\n\t\treturn normalizeError(error, {\n\t\t\tprops: {\n\t\t\t\tfailedConnectionStep,\n\t\t\t\tseparateTokenRequest,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Connects to a delta stream endpoint for emitting ops.\n\t *\n\t * @returns returns the document delta stream service for onedrive/sharepoint driver.\n\t */\n\tpublic async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n\t\tassert(\n\t\t\tthis.currentConnection === undefined,\n\t\t\t0x4ad /* Should not be called when connection is already present! */,\n\t\t);\n\t\t// Attempt to connect twice, in case we used expired token.\n\t\treturn getWithRetryForTokenRefresh<IDocumentDeltaConnection>(async (options) => {\n\t\t\t// Presence of getWebsocketToken callback dictates whether callback is used for fetching\n\t\t\t// websocket token or whether it is returned with joinSession response payload\n\t\t\tconst requestWebsocketTokenFromJoinSession = this.getWebsocketToken === undefined;\n\t\t\tconst websocketTokenPromise = requestWebsocketTokenFromJoinSession\n\t\t\t\t? // eslint-disable-next-line unicorn/no-null\n\t\t\t\t Promise.resolve(null)\n\t\t\t\t: this.getWebsocketToken!(options);\n\n\t\t\tconst annotateAndRethrowConnectionError = (step: string) => (error: unknown) => {\n\t\t\t\tthrow this.annotateConnectionError(\n\t\t\t\t\terror,\n\t\t\t\t\tstep,\n\t\t\t\t\t!requestWebsocketTokenFromJoinSession,\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tconst joinSessionPromise = this.joinSession(\n\t\t\t\trequestWebsocketTokenFromJoinSession,\n\t\t\t\toptions,\n\t\t\t\tfalse /* isRefreshingJoinSession */,\n\t\t\t);\n\t\t\tconst [websocketEndpoint, websocketToken] = await Promise.all([\n\t\t\t\tjoinSessionPromise.catch(annotateAndRethrowConnectionError(\"joinSession\")),\n\t\t\t\twebsocketTokenPromise.catch(annotateAndRethrowConnectionError(\"getWebsocketToken\")),\n\t\t\t]);\n\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst finalWebsocketToken = websocketToken ?? websocketEndpoint.socketToken ?? null;\n\t\t\tif (finalWebsocketToken === null) {\n\t\t\t\tthrow this.annotateConnectionError(\n\t\t\t\t\tnew NonRetryableError(\n\t\t\t\t\t\t\"Websocket token is null\",\n\t\t\t\t\t\tOdspErrorTypes.fetchTokenError,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t),\n\t\t\t\t\t\"getWebsocketToken\",\n\t\t\t\t\t!requestWebsocketTokenFromJoinSession,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (websocketEndpoint.sensitivityLabelsInfo !== undefined) {\n\t\t\t\tthis.emitMetaDataUpdateEvent({\n\t\t\t\t\tsensitivityLabelsInfo: websocketEndpoint.sensitivityLabelsInfo,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst connection = await this.createDeltaConnection(\n\t\t\t\t\twebsocketEndpoint.tenantId,\n\t\t\t\t\twebsocketEndpoint.id,\n\t\t\t\t\tfinalWebsocketToken,\n\t\t\t\t\tclient,\n\t\t\t\t\twebsocketEndpoint.deltaStreamSocketUrl,\n\t\t\t\t);\n\t\t\t\tconnection.on(\"op\", (documentId, ops: ISequencedDocumentMessage[]) => {\n\t\t\t\t\tthis.opsReceived(ops);\n\t\t\t\t});\n\t\t\t\tconnection.on(\"signal\", this.signalHandler);\n\t\t\t\t// Also process the initial signals\n\t\t\t\tthis.signalHandler(connection.initialSignals);\n\t\t\t\t// On disconnect with 401/403 error code, we can just clear the joinSession cache as we will again\n\t\t\t\t// get the auth error on reconnecting and face latency.\n\t\t\t\tconnection.once(\"disconnect\", (error: unknown) => {\n\t\t\t\t\t// Clear the join session refresh timer so that it can be restarted on reconnection.\n\t\t\t\t\tthis.clearJoinSessionTimer();\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof error === \"object\" &&\n\t\t\t\t\t\terror !== null &&\n\t\t\t\t\t\t(error as Partial<IOdspError>).errorType ===\n\t\t\t\t\t\t\tOdspErrorTypes.authorizationError\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.cache.sessionJoinCache.remove(this.joinSessionKey);\n\t\t\t\t\t}\n\t\t\t\t\t// If we hit this assert, it means that \"disconnect\" event is emitted before the connection went through\n\t\t\t\t\t// dispose flow which is not correct and could lead to a bunch of errors.\n\t\t\t\t\tassert(connection.disposed, 0x4ae /* Connection should be disposed by now */);\n\t\t\t\t\tthis.currentConnection = undefined;\n\t\t\t\t});\n\t\t\t\tthis.currentConnection = connection;\n\t\t\t\treturn connection;\n\t\t\t} catch (error) {\n\t\t\t\tthis.clearJoinSessionTimer();\n\t\t\t\tthis.cache.sessionJoinCache.remove(this.joinSessionKey);\n\n\t\t\t\tconst normalizedError = this.annotateConnectionError(\n\t\t\t\t\terror,\n\t\t\t\t\t\"createDeltaConnection\",\n\t\t\t\t\t!requestWebsocketTokenFromJoinSession,\n\t\t\t\t);\n\t\t\t\tif (typeof error === \"object\" && error !== null) {\n\t\t\t\t\tnormalizedError.addTelemetryProperties({\n\t\t\t\t\t\tsocketDocumentId: websocketEndpoint.id,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow normalizedError;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate readonly signalHandler = (signalsArg: ISignalMessage | ISignalMessage[]): void => {\n\t\tconst signals = Array.isArray(signalsArg) ? signalsArg : [signalsArg];\n\t\tfor (const signal of signals) {\n\t\t\t// Make sure it is not for a specific client as `PolicyLabelsUpdate` is meant for all clients.\n\t\t\tif (signal.clientId === null) {\n\t\t\t\t// We could have some issues/irregularities in parsing signals, so put it in try/catch block\n\t\t\t\t// and ignore the error as we can have labels update later on through join session response.\n\t\t\t\tlet envelope: ISignalEnvelope | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tenvelope = JSON.parse(signal.content as string) as ISignalEnvelope;\n\t\t\t\t} catch {\n\t\t\t\t\t// Drop error\n\t\t\t\t}\n\t\t\t\tif (envelope?.contents?.type === policyLabelsUpdatesSignalType) {\n\t\t\t\t\tthis.emitMetaDataUpdateEvent({\n\t\t\t\t\t\tsensitivityLabelsInfo: JSON.stringify(envelope.contents.content),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate clearJoinSessionTimer(): void {\n\t\tif (this.joinSessionRefreshTimer !== undefined) {\n\t\t\tclearTimeout(this.joinSessionRefreshTimer);\n\t\t\tthis.joinSessionRefreshTimer = undefined;\n\t\t}\n\t}\n\n\tprivate async scheduleJoinSessionRefresh(\n\t\tdelta: number,\n\t\trequestSocketToken: boolean,\n\t\tclientId: string | undefined,\n\t): Promise<void> {\n\t\tif (this.joinSessionRefreshTimer !== undefined) {\n\t\t\tthis.clearJoinSessionTimer();\n\t\t\t// TODO: use a stronger type\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t\tconst originalStackTraceLimit = (Error as any).stackTraceLimit;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t\t(Error as any).stackTraceLimit = 50;\n\t\t\tthis.mc.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"DuplicateJoinSessionRefresh\",\n\t\t\t\t},\n\t\t\t\tnew Error(\"DuplicateJoinSessionRefresh\"),\n\t\t\t);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t\t(Error as any).stackTraceLimit = originalStackTraceLimit;\n\t\t}\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.joinSessionRefreshTimer = setTimeout(() => {\n\t\t\t\tthis.clearJoinSessionTimer();\n\t\t\t\t// Clear the timer as it is going to be scheduled again as part of refreshing join session.\n\t\t\t\tgetWithRetryForTokenRefresh(async (options) => {\n\t\t\t\t\tawait this.joinSession(\n\t\t\t\t\t\trequestSocketToken,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\ttrue /* isRefreshingJoinSession */,\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t);\n\t\t\t\t\tresolve();\n\t\t\t\t}).catch((error) => {\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t\t}, delta);\n\t\t});\n\t}\n\n\tprivate async joinSession(\n\t\trequestSocketToken: boolean,\n\t\toptions: TokenFetchOptionsEx,\n\t\tisRefreshingJoinSession: boolean,\n\t\tclientId?: string,\n\t): Promise<ISocketStorageDiscovery> {\n\t\t// If this call is to refresh the join session for the current connection but we are already disconnected in\n\t\t// the meantime or disconnected and then reconnected then do not make the call. However, we should not have\n\t\t// come here if that is the case because timer should have been disposed, but due to race condition with the\n\t\t// timer we should not make the call and throw error.\n\t\tif (\n\t\t\tisRefreshingJoinSession &&\n\t\t\t(this.currentConnection === undefined ||\n\t\t\t\t(clientId !== undefined && this.currentConnection.clientId !== clientId))\n\t\t) {\n\t\t\tthis.clearJoinSessionTimer();\n\t\t\tthrow new NonRetryableError(\n\t\t\t\t\"JoinSessionRefreshTimerNotCancelled\",\n\t\t\t\tOdspErrorTypes.genericError,\n\t\t\t\t{\n\t\t\t\t\tdriverVersion,\n\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\tschedulerClientId: clientId,\n\t\t\t\t\t\tcurrentClientId: this.currentConnection?.clientId,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tconst response = await this.joinSessionCore(\n\t\t\trequestSocketToken,\n\t\t\toptions,\n\t\t\tisRefreshingJoinSession,\n\t\t).catch((error) => {\n\t\t\tif (hasFacetCodes(error) && error.facetCodes !== undefined) {\n\t\t\t\tfor (const code of error.facetCodes) {\n\t\t\t\t\tswitch (code) {\n\t\t\t\t\t\tcase \"sessionForbidden\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnPreservedFiles\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnModerationEnabledLibrary\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnRequireCheckout\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnCheckoutFile\":\n\t\t\t\t\t\tcase \"sessionForbiddenOnInvisibleMinorVersion\": {\n\t\t\t\t\t\t\t// This document can only be opened in storage-only mode.\n\t\t\t\t\t\t\t// DeltaManager will recognize this error\n\t\t\t\t\t\t\t// and load without a delta stream connection.\n\t\t\t\t\t\t\tthis.policies = { ...this.policies, storageOnly: true };\n\t\t\t\t\t\t\tthrow new DeltaStreamConnectionForbiddenError(\n\t\t\t\t\t\t\t\t`Storage-only due to ${code}`,\n\t\t\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\t\tthis._relayServiceTenantAndSessionId = `${response.tenantId}/${response.id}`;\n\t\treturn response;\n\t}\n\n\tprivate async joinSessionCore(\n\t\trequestSocketToken: boolean,\n\t\toptions: TokenFetchOptionsEx,\n\t\tisRefreshingJoinSession: boolean,\n\t): Promise<ISocketStorageDiscovery> {\n\t\tconst disableJoinSessionRefresh = this.mc.config.getBoolean(\n\t\t\t\"Fluid.Driver.Odsp.disableJoinSessionRefresh\",\n\t\t);\n\t\tconst executeFetch = async (): Promise<{\n\t\t\tentryTime: number;\n\t\t\tjoinSessionResponse: ISocketStorageDiscovery;\n\t\t}> => {\n\t\t\tconst joinSessionResponse = await fetchJoinSession(\n\t\t\t\tthis.odspResolvedUrl,\n\t\t\t\t\"opStream/joinSession\",\n\t\t\t\t\"POST\",\n\t\t\t\tthis.mc.logger,\n\t\t\t\tthis.getStorageToken,\n\t\t\t\tthis.epochTracker,\n\t\t\t\trequestSocketToken,\n\t\t\t\toptions,\n\t\t\t\tdisableJoinSessionRefresh,\n\t\t\t\tisRefreshingJoinSession,\n\t\t\t\tthis.hostPolicy.sessionOptions?.unauthenticatedUserDisplayName,\n\t\t\t);\n\t\t\t// Emit event only in case it is fetched from the network.\n\t\t\tif (joinSessionResponse.sensitivityLabelsInfo !== undefined) {\n\t\t\t\tthis.emitMetaDataUpdateEvent({\n\t\t\t\t\tsensitivityLabelsInfo: joinSessionResponse.sensitivityLabelsInfo,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryTime: Date.now(),\n\t\t\t\tjoinSessionResponse,\n\t\t\t};\n\t\t};\n\n\t\tconst getResponseAndRefreshAfterDeltaMs = async (): Promise<{\n\t\t\trefreshAfterDeltaMs: number;\n\t\t\tentryTime: number;\n\t\t\tjoinSessionResponse: ISocketStorageDiscovery;\n\t\t}> => {\n\t\t\tconst _response = await this.cache.sessionJoinCache.addOrGet(\n\t\t\t\tthis.joinSessionKey,\n\t\t\t\texecuteFetch,\n\t\t\t);\n\t\t\t// If the response does not contain refreshSessionDurationSeconds, then treat it as old flow and let the\n\t\t\t// cache entry to be treated as expired after 1 hour.\n\t\t\t_response.joinSessionResponse.refreshSessionDurationSeconds =\n\t\t\t\t_response.joinSessionResponse.refreshSessionDurationSeconds ?? 3600;\n\t\t\treturn {\n\t\t\t\t..._response,\n\t\t\t\trefreshAfterDeltaMs: this.calculateJoinSessionRefreshDelta(\n\t\t\t\t\t_response.entryTime,\n\t\t\t\t\t_response.joinSessionResponse.refreshSessionDurationSeconds,\n\t\t\t\t),\n\t\t\t};\n\t\t};\n\t\tlet response = await getResponseAndRefreshAfterDeltaMs();\n\t\t// This means that the cached entry has expired(This should not be possible if the response is fetched\n\t\t// from the network call). In this case we remove the cached entry and fetch the new response.\n\t\tif (response.refreshAfterDeltaMs <= 0) {\n\t\t\tthis.cache.sessionJoinCache.remove(this.joinSessionKey);\n\t\t\tresponse = await getResponseAndRefreshAfterDeltaMs();\n\t\t}\n\t\tif (!disableJoinSessionRefresh) {\n\t\t\tconst props = {\n\t\t\t\tentryTime: response.entryTime,\n\t\t\t\trefreshSessionDurationSeconds:\n\t\t\t\t\tresponse.joinSessionResponse.refreshSessionDurationSeconds,\n\t\t\t\trefreshAfterDeltaMs: response.refreshAfterDeltaMs,\n\t\t\t};\n\t\t\tif (response.refreshAfterDeltaMs > 0) {\n\t\t\t\tthis.scheduleJoinSessionRefresh(\n\t\t\t\t\tresponse.refreshAfterDeltaMs,\n\t\t\t\t\trequestSocketToken,\n\t\t\t\t\tthis.currentConnection?.clientId,\n\t\t\t\t).catch((error) => {\n\t\t\t\t\t// Log the error and do nothing as the reconnection would fetch the join session.\n\t\t\t\t\tthis.mc.logger.sendTelemetryEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"JoinSessionRefreshError\",\n\t\t\t\t\t\t\tdetails: JSON.stringify(props),\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\t// Logging just for informational purposes to help with debugging as this is a new feature.\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"JoinSessionRefreshNotScheduled\",\n\t\t\t\t\tdetails: JSON.stringify(props),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn response.joinSessionResponse;\n\t}\n\n\tprivate emitMetaDataUpdateEvent(metadata: Record<string, string>): void {\n\t\tconst label = JSON.parse(metadata.sensitivityLabelsInfo) as {\n\t\t\tlabels: unknown;\n\t\t\ttimestamp: number;\n\t\t};\n\t\tconst time = label.timestamp;\n\t\tassert(time > 0, 0x8e0 /* time should be positive */);\n\t\tif (time > this.labelUpdateTimestamp) {\n\t\t\tthis.labelUpdateTimestamp = time;\n\t\t\tthis.metadataUpdateHandler({\n\t\t\t\tsensitivityLabelsInfo: metadata.sensitivityLabelsInfo,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate calculateJoinSessionRefreshDelta(\n\t\tresponseFetchTime: number,\n\t\trefreshSessionDurationSeconds: number,\n\t): number {\n\t\t// 30 seconds is buffer time to refresh the session.\n\t\treturn responseFetchTime + (refreshSessionDurationSeconds * 1000 - 30000) - Date.now();\n\t}\n\n\t/**\n\t * Creates a connection to the given delta stream endpoint\n\t *\n\t * @param tenantId - the ID of the tenant\n\t * @param documentId - document ID\n\t * @param token - authorization token for delta service\n\t * @param client - information about the client\n\t * @param webSocketUrl - websocket URL\n\t */\n\tprivate async createDeltaConnection(\n\t\ttenantId: string,\n\t\tdocumentId: string,\n\t\ttoken: string | null,\n\t\tclient: IClient,\n\t\twebSocketUrl: string,\n\t): Promise<OdspDocumentDeltaConnection> {\n\t\tconst startTime = performance.now();\n\t\tconst connection = await OdspDocumentDeltaConnection.create(\n\t\t\ttenantId,\n\t\t\tdocumentId,\n\t\t\ttoken,\n\t\t\tclient,\n\t\t\twebSocketUrl,\n\t\t\tthis.mc.logger,\n\t\t\t60000,\n\t\t\tthis.epochTracker,\n\t\t\tthis.socketReferenceKeyPrefix,\n\t\t);\n\t\tconst duration = performance.now() - startTime;\n\t\t// This event happens rather often, so it adds up to cost of telemetry.\n\t\t// Given that most reconnects result in reusing socket and happen very quickly,\n\t\t// report event only if it took longer than threshold.\n\t\tif (duration >= 2000) {\n\t\t\tthis.mc.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"ConnectionSuccess\",\n\t\t\t\tduration,\n\t\t\t});\n\t\t}\n\t\treturn connection;\n\t}\n\n\tpublic dispose(error?: unknown): void {\n\t\tthis.clearJoinSessionTimer();\n\t\tthis.currentConnection?.dispose();\n\t\tthis.currentConnection = undefined;\n\t}\n}\n"]}
@@ -2,13 +2,13 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryProperties } from "@fluidframework/core-interfaces";
5
+ import { ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
6
6
  import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
7
7
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
8
8
  import { InstrumentedStorageTokenFetcher } from "@fluidframework/odsp-driver-definitions";
9
- import { IDeltasFetchResult, IDocumentDeltaStorageService } from "@fluidframework/driver-definitions";
10
- import { EpochTracker } from "./epochTracker";
11
- import { OdspDocumentStorageService } from "./odspDocumentStorageManager";
9
+ import { IDeltasFetchResult, IDocumentDeltaStorageService, type IStream } from "@fluidframework/driver-definitions";
10
+ import { EpochTracker } from "./epochTracker.js";
11
+ import { OdspDocumentStorageService } from "./odspDocumentStorageManager.js";
12
12
  /**
13
13
  * Provides access to the underlying delta storage on the server for sharepoint driver.
14
14
  */
@@ -26,7 +26,7 @@ export declare class OdspDeltaStorageService {
26
26
  * @param scenarioName - reason for fetching ops
27
27
  * @returns ops retrieved & info if result was partial (i.e. more is available)
28
28
  */
29
- get(from: number, to: number, telemetryProps: ITelemetryProperties, scenarioName?: string): Promise<IDeltasFetchResult>;
29
+ get(from: number, to: number, telemetryProps: ITelemetryBaseProperties, scenarioName?: string): Promise<IDeltasFetchResult>;
30
30
  buildUrl(from: number, to: number): string;
31
31
  }
32
32
  export declare class OdspDeltaStorageWithCache implements IDocumentDeltaStorageService {
@@ -40,7 +40,7 @@ export declare class OdspDeltaStorageWithCache implements IDocumentDeltaStorageS
40
40
  private readonly opsReceived;
41
41
  private readonly storageManagerGetter;
42
42
  private useCacheForOps;
43
- constructor(snapshotOps: ISequencedDocumentMessage[] | undefined, logger: ITelemetryLoggerExt, batchSize: number, concurrency: number, getFromStorage: (from: number, to: number, telemetryProps: ITelemetryProperties, fetchReason?: string) => Promise<IDeltasFetchResult>, getCached: (from: number, to: number) => Promise<ISequencedDocumentMessage[]>, requestFromSocket: (from: number, to: number) => void, opsReceived: (ops: ISequencedDocumentMessage[]) => void, storageManagerGetter: () => OdspDocumentStorageService | undefined);
44
- fetchMessages(fromTotal: number, toTotal: number | undefined, abortSignal?: AbortSignal, cachedOnly?: boolean, fetchReason?: string): import("@fluidframework/driver-definitions").IStream<ISequencedDocumentMessage[]>;
43
+ constructor(snapshotOps: ISequencedDocumentMessage[] | undefined, logger: ITelemetryLoggerExt, batchSize: number, concurrency: number, getFromStorage: (from: number, to: number, telemetryProps: ITelemetryBaseProperties, fetchReason?: string) => Promise<IDeltasFetchResult>, getCached: (from: number, to: number) => Promise<ISequencedDocumentMessage[]>, requestFromSocket: (from: number, to: number) => void, opsReceived: (ops: ISequencedDocumentMessage[]) => void, storageManagerGetter: () => OdspDocumentStorageService | undefined);
44
+ fetchMessages(fromTotal: number, toTotal: number | undefined, abortSignal?: AbortSignal, cachedOnly?: boolean, fetchReason?: string): IStream<ISequencedDocumentMessage[]>;
45
45
  }
46
46
  //# sourceMappingURL=odspDeltaStorageService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"odspDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/odspDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAoB,MAAM,iCAAiC,CAAC;AAExF,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EACN,kBAAkB,EAClB,4BAA4B,EAC5B,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,qBAAa,uBAAuB;IAElC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAHN,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,+BAA+B,EAChD,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,mBAAmB;IAG7C;;;;;;;OAOG;IACU,GAAG,CACf,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,oBAAoB,EACpC,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,kBAAkB,CAAC;IA0EvB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAOxC;AAED,qBAAa,yBAA0B,YAAW,4BAA4B;IAI5E,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAA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BAAyB,EAAE,GAAG,SAAS,EAC3C,MAAM,EAAE,mBAAmB,EAC3B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,CAChC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,wBAAwB,EACxC,WAAW,CAAC,EAAE,MAAM,KAChB,OAAO,CAAC,kBAAkB,CAAC,EACf,SAAS,EAAE,CAC3B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,KACN,OAAO,CAAC,yBAAyB,EAAE,CAAC,EACxB,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,EACrD,WAAW,EAAE,CAAC,GAAG,EAAE,yBAAyB,EAAE,KAAK,IAAI,EACvD,oBAAoB,EAAE,MAAM,0BAA0B,GAAG,SAAS;IAG7E,aAAa,CACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,EACpB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,yBAAyB,EAAE,CAAC;CA8FvC"}
@@ -10,7 +10,7 @@ const driver_base_1 = require("@fluidframework/driver-base");
10
10
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
11
11
  const core_utils_1 = require("@fluidframework/core-utils");
12
12
  const driver_utils_1 = require("@fluidframework/driver-utils");
13
- const odspUtils_1 = require("./odspUtils");
13
+ const odspUtils_js_1 = require("./odspUtils.js");
14
14
  /**
15
15
  * Provides access to the underlying delta storage on the server for sharepoint driver.
16
16
  */
@@ -30,7 +30,7 @@ class OdspDeltaStorageService {
30
30
  * @returns ops retrieved & info if result was partial (i.e. more is available)
31
31
  */
32
32
  async get(from, to, telemetryProps, scenarioName) {
33
- return (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
33
+ return (0, odspUtils_js_1.getWithRetryForTokenRefresh)(async (options) => {
34
34
  // Note - this call ends up in getSocketStorageDiscovery() and can refresh token
35
35
  // Thus it needs to be done before we call getStorageToken() to reduce extra calls
36
36
  const baseUrl = this.buildUrl(from, to);
@@ -72,7 +72,7 @@ class OdspDeltaStorageService {
72
72
  ? deltaStorageResponse.value.map((operation) => operation.op)
73
73
  : deltaStorageResponse.value;
74
74
  event.end({
75
- headers: Object.keys(headers).length !== 0 ? true : undefined,
75
+ headers: Object.keys(headers).length > 0 ? true : undefined,
76
76
  length: messages.length,
77
77
  ...response.propsToLog,
78
78
  });
@@ -116,7 +116,7 @@ class OdspDeltaStorageWithCache {
116
116
  let opsFromCache = 0;
117
117
  let opsFromStorage = 0;
118
118
  const requestCallback = async (from, to, telemetryProps) => {
119
- if (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {
119
+ if (this.snapshotOps !== undefined && this.snapshotOps.length > 0) {
120
120
  const messages = this.snapshotOps.filter((op) => op.sequenceNumber >= from && op.sequenceNumber < to);
121
121
  (0, driver_base_1.validateMessages)("cached", messages, from, this.logger);
122
122
  if (messages.length > 0 && messages[0].sequenceNumber === from) {
@@ -136,7 +136,7 @@ class OdspDeltaStorageWithCache {
136
136
  // Set the firstCacheMiss as true in case we didn't get all the ops.
137
137
  // This will save an extra cache read on "DocumentOpen" or "PostDocumentOpen".
138
138
  this.useCacheForOps = from + messagesFromCache.length >= to;
139
- if (messagesFromCache.length !== 0) {
139
+ if (messagesFromCache.length > 0) {
140
140
  opsFromCache += messagesFromCache.length;
141
141
  return {
142
142
  messages: messagesFromCache,
@@ -1 +1 @@
1
- {"version":3,"file":"odspDeltaStorageService.js","sourceRoot":"","sources":["../src/odspDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,6DAA+D;AAC/D,qEAAwF;AACxF,2DAAoD;AAOpD,+DAA0E;AAG1E,2CAA0D;AAG1D;;GAEG;AACH,MAAa,uBAAuB;IACnC,YACkB,YAAoB,E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,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACxC,IAAI,MAAM,CAAC,IAAI,IAAI,eAAe,GAAG,YAAY,GAAG,cAAc,KAAK,CAAC,EAAE;gBACzE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;oBAChC,SAAS,EAAE,mBAAmB;oBAC9B,eAAe;oBACf,YAAY;oBACZ,cAAc;oBACd,MAAM,EAAE,WAAW;iBACnB,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AA3HD,8DA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryProperties } from \"@fluidframework/core-interfaces\";\nimport { validateMessages } from \"@fluidframework/driver-base\";\nimport { ITelemetryLoggerExt, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport {\n\tIDeltasFetchResult,\n\tIDocumentDeltaStorageService,\n} from \"@fluidframework/driver-definitions\";\nimport { requestOps, streamObserver } from \"@fluidframework/driver-utils\";\nimport { IDeltaStorageGetResponse, ISequencedDeltaOpMessage } from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\nimport { OdspDocumentStorageService } from \"./odspDocumentStorageManager\";\n\n/**\n * Provides access to the underlying delta storage on the server for sharepoint driver.\n */\nexport class OdspDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly deltaFeedUrl: string,\n\t\tprivate readonly getStorageToken: InstrumentedStorageTokenFetcher,\n\t\tprivate readonly epochTracker: EpochTracker,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {}\n\n\t/**\n\t * Retrieves ops from storage\n\t * @param from - inclusive\n\t * @param to - exclusive\n\t * @param telemetryProps - properties to add when issuing telemetry events\n\t * @param scenarioName - reason for fetching ops\n\t * @returns ops retrieved & info if result was partial (i.e. more is available)\n\t */\n\tpublic async get(\n\t\tfrom: number,\n\t\tto: number,\n\t\ttelemetryProps: ITelemetryProperties,\n\t\tscenarioName?: string,\n\t): Promise<IDeltasFetchResult> {\n\t\treturn getWithRetryForTokenRefresh(async (options) => {\n\t\t\t// Note - this call ends up in getSocketStorageDiscovery() and can refresh token\n\t\t\t// Thus it needs to be done before we call getStorageToken() to reduce extra calls\n\t\t\tconst baseUrl = this.buildUrl(from, to);\n\t\t\tconst storageToken = await this.getStorageToken(options, \"DeltaStorage\");\n\n\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"OpsFetch\",\n\t\t\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\t\t\tfrom,\n\t\t\t\t\tto,\n\t\t\t\t\t...telemetryProps,\n\t\t\t\t\treason: scenarioName,\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tconst formBoundary = uuid();\n\t\t\t\t\tlet postBody = `--${formBoundary}\\r\\n`;\n\t\t\t\t\tpostBody += `Authorization: Bearer ${storageToken}\\r\\n`;\n\t\t\t\t\tpostBody += `X-HTTP-Method-Override: GET\\r\\n`;\n\n\t\t\t\t\tpostBody += `_post: 1\\r\\n`;\n\t\t\t\t\tpostBody += `\\r\\n--${formBoundary}--`;\n\t\t\t\t\tconst headers: { [index: string]: any } = {\n\t\t\t\t\t\t\"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n\t\t\t\t\t};\n\n\t\t\t\t\t// Some request take a long time (1-2 minutes) to complete, where telemetry shows very small amount\n\t\t\t\t\t// of time spent on server, and usually small payload sizes. I.e. all the time is spent somewhere in\n\t\t\t\t\t// networking. Even bigger problem - a lot of requests timeout (based on cursory look - after 1-2 minutes)\n\t\t\t\t\t// So adding some timeout to ensure we retry again in hope of faster success.\n\t\t\t\t\t// Please see https://github.com/microsoft/FluidFramework/issues/6997 for details.\n\t\t\t\t\tconst abort = new AbortController();\n\t\t\t\t\tconst timer = setTimeout(() => abort.abort(), 30000);\n\n\t\t\t\t\tconst response =\n\t\t\t\t\t\tawait this.epochTracker.fetchAndParseAsJSON<IDeltaStorageGetResponse>(\n\t\t\t\t\t\t\tbaseUrl,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\t\tbody: postBody,\n\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\tsignal: abort.signal,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"ops\",\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\tscenarioName,\n\t\t\t\t\t\t);\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tconst deltaStorageResponse = response.content;\n\t\t\t\t\tconst messages =\n\t\t\t\t\t\tdeltaStorageResponse.value.length > 0 &&\n\t\t\t\t\t\t\"op\" in deltaStorageResponse.value[0]\n\t\t\t\t\t\t\t? (deltaStorageResponse.value as ISequencedDeltaOpMessage[]).map(\n\t\t\t\t\t\t\t\t\t(operation) => operation.op,\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: (deltaStorageResponse.value as ISequencedDocumentMessage[]);\n\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\theaders: Object.keys(headers).length !== 0 ? true : undefined,\n\t\t\t\t\t\tlength: messages.length,\n\t\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\t});\n\n\t\t\t\t\t// It is assumed that server always returns all the ops that it has in the range that was requested.\n\t\t\t\t\t// This may change in the future, if so, we need to adjust and receive \"end\" value from server in such case.\n\t\t\t\t\treturn { messages, partialResult: false };\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tpublic buildUrl(from: number, to: number) {\n\t\tconst filter = encodeURIComponent(\n\t\t\t`sequenceNumber ge ${from} and sequenceNumber le ${to - 1}`,\n\t\t);\n\t\tconst queryString = `?ump=1&filter=${filter}`;\n\t\treturn `${this.deltaFeedUrl}${queryString}`;\n\t}\n}\n\nexport class OdspDeltaStorageWithCache implements IDocumentDeltaStorageService {\n\tprivate useCacheForOps = true;\n\n\tpublic constructor(\n\t\tprivate snapshotOps: ISequencedDocumentMessage[] | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly batchSize: number,\n\t\tprivate readonly concurrency: number,\n\t\tprivate readonly getFromStorage: (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\ttelemetryProps: ITelemetryProperties,\n\t\t\tfetchReason?: string,\n\t\t) => Promise<IDeltasFetchResult>,\n\t\tprivate readonly getCached: (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t) => Promise<ISequencedDocumentMessage[]>,\n\t\tprivate readonly requestFromSocket: (from: number, to: number) => void,\n\t\tprivate readonly opsReceived: (ops: ISequencedDocumentMessage[]) => void,\n\t\tprivate readonly storageManagerGetter: () => OdspDocumentStorageService | undefined,\n\t) {}\n\n\tpublic fetchMessages(\n\t\tfromTotal: number,\n\t\ttoTotal: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t\tfetchReason?: string,\n\t) {\n\t\t// We do not control what's in the cache. Current API assumes that fetchMessages() keeps banging on\n\t\t// storage / cache until it gets ops it needs. This would result in deadlock if fixed range is asked from\n\t\t// cache and it's not there.\n\t\t// Better implementation would be to return only what we have in cache, but that also breaks API\n\t\tassert(!cachedOnly || toTotal === undefined, 0x1e3);\n\n\t\t// Don't use cache for ops is snapshot is fetched from network or if it was not fetched at all.\n\t\tthis.useCacheForOps =\n\t\t\tthis.useCacheForOps &&\n\t\t\tthis.storageManagerGetter()?.isFirstSnapshotFromNetwork === false;\n\t\tlet opsFromSnapshot = 0;\n\t\tlet opsFromCache = 0;\n\t\tlet opsFromStorage = 0;\n\n\t\tconst requestCallback = async (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\ttelemetryProps: ITelemetryProperties,\n\t\t) => {\n\t\t\tif (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {\n\t\t\t\tconst messages = this.snapshotOps.filter(\n\t\t\t\t\t(op) => op.sequenceNumber >= from && op.sequenceNumber < to,\n\t\t\t\t);\n\t\t\t\tvalidateMessages(\"cached\", messages, from, this.logger);\n\t\t\t\tif (messages.length > 0 && messages[0].sequenceNumber === from) {\n\t\t\t\t\tthis.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);\n\t\t\t\t\topsFromSnapshot += messages.length;\n\t\t\t\t\treturn { messages, partialResult: true };\n\t\t\t\t}\n\t\t\t\tthis.snapshotOps = undefined;\n\t\t\t}\n\n\t\t\t// Kick out request to PUSH for ops if it has them\n\t\t\tthis.requestFromSocket(from, to);\n\n\t\t\t// Cache in normal flow is continuous. Once there is a miss, stop consulting cache.\n\t\t\t// This saves a bit of processing time.\n\t\t\tif (this.useCacheForOps) {\n\t\t\t\tconst messagesFromCache = await this.getCached(from, to);\n\t\t\t\tvalidateMessages(\"cached\", messagesFromCache, from, this.logger);\n\t\t\t\t// Set the firstCacheMiss as true in case we didn't get all the ops.\n\t\t\t\t// This will save an extra cache read on \"DocumentOpen\" or \"PostDocumentOpen\".\n\t\t\t\tthis.useCacheForOps = from + messagesFromCache.length >= to;\n\t\t\t\tif (messagesFromCache.length !== 0) {\n\t\t\t\t\topsFromCache += messagesFromCache.length;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmessages: messagesFromCache,\n\t\t\t\t\t\tpartialResult: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (cachedOnly) {\n\t\t\t\treturn { messages: [], partialResult: false };\n\t\t\t}\n\n\t\t\tconst ops = await this.getFromStorage(from, to, telemetryProps, fetchReason);\n\t\t\tvalidateMessages(\"storage\", ops.messages, from, this.logger);\n\t\t\topsFromStorage += ops.messages.length;\n\t\t\tthis.opsReceived(ops.messages);\n\t\t\treturn ops;\n\t\t};\n\n\t\tconst stream = requestOps(\n\t\t\tasync (from: number, to: number, telemetryProps: ITelemetryProperties) => {\n\t\t\t\tconst result = await requestCallback(from, to, telemetryProps);\n\t\t\t\t// Catch all case, just in case\n\t\t\t\tvalidateMessages(\"catch all\", result.messages, from, this.logger);\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\t// Staging: starting with no concurrency, listening for feedback first.\n\t\t\t// In future releases we will switch to actual concurrency\n\t\t\tthis.concurrency,\n\t\t\tfromTotal, // inclusive\n\t\t\ttoTotal, // exclusive\n\t\t\tthis.batchSize,\n\t\t\tthis.logger,\n\t\t\tabortSignal,\n\t\t\tfetchReason,\n\t\t);\n\n\t\treturn streamObserver(stream, (result) => {\n\t\t\tif (result.done && opsFromSnapshot + opsFromCache + opsFromStorage !== 0) {\n\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"CacheOpsRetrieved\",\n\t\t\t\t\topsFromSnapshot,\n\t\t\t\t\topsFromCache,\n\t\t\t\t\topsFromStorage,\n\t\t\t\t\treason: fetchReason,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"odspDeltaStorageService.js","sourceRoot":"","sources":["../src/odspDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,6DAA+D;AAC/D,qEAAwF;AACxF,2DAAoD;AAQpD,+DAA0E;AAG1E,iDAA6D;AAG7D;;GAEG;AACH,MAAa,uBAAuB;IACnC,YACkB,YAAoB,EACpB,eAAgD,EAChD,YAA0B,EAC1B,MAA2B;QAH3B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,oBAAe,GAAf,eAAe,CAAiC;QAChD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAqB;IAC1C,CAAC;IAEJ;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAY,EACZ,EAAU,EAC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,WAAW;iBACnB,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AA3HD,8DA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { validateMessages } from \"@fluidframework/driver-base\";\nimport { ITelemetryLoggerExt, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport {\n\tIDeltasFetchResult,\n\tIDocumentDeltaStorageService,\n\ttype IStream,\n} from \"@fluidframework/driver-definitions\";\nimport { requestOps, streamObserver } from \"@fluidframework/driver-utils\";\nimport { IDeltaStorageGetResponse, ISequencedDeltaOpMessage } from \"./contracts.js\";\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils.js\";\nimport { OdspDocumentStorageService } from \"./odspDocumentStorageManager.js\";\n\n/**\n * Provides access to the underlying delta storage on the server for sharepoint driver.\n */\nexport class OdspDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly deltaFeedUrl: string,\n\t\tprivate readonly getStorageToken: InstrumentedStorageTokenFetcher,\n\t\tprivate readonly epochTracker: EpochTracker,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {}\n\n\t/**\n\t * Retrieves ops from storage\n\t * @param from - inclusive\n\t * @param to - exclusive\n\t * @param telemetryProps - properties to add when issuing telemetry events\n\t * @param scenarioName - reason for fetching ops\n\t * @returns ops retrieved & info if result was partial (i.e. more is available)\n\t */\n\tpublic async get(\n\t\tfrom: number,\n\t\tto: number,\n\t\ttelemetryProps: ITelemetryBaseProperties,\n\t\tscenarioName?: string,\n\t): Promise<IDeltasFetchResult> {\n\t\treturn getWithRetryForTokenRefresh(async (options) => {\n\t\t\t// Note - this call ends up in getSocketStorageDiscovery() and can refresh token\n\t\t\t// Thus it needs to be done before we call getStorageToken() to reduce extra calls\n\t\t\tconst baseUrl = this.buildUrl(from, to);\n\t\t\tconst storageToken = await this.getStorageToken(options, \"DeltaStorage\");\n\n\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"OpsFetch\",\n\t\t\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\t\t\tfrom,\n\t\t\t\t\tto,\n\t\t\t\t\t...telemetryProps,\n\t\t\t\t\treason: scenarioName,\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tconst formBoundary = uuid();\n\t\t\t\t\tlet postBody = `--${formBoundary}\\r\\n`;\n\t\t\t\t\tpostBody += `Authorization: Bearer ${storageToken}\\r\\n`;\n\t\t\t\t\tpostBody += `X-HTTP-Method-Override: GET\\r\\n`;\n\n\t\t\t\t\tpostBody += `_post: 1\\r\\n`;\n\t\t\t\t\tpostBody += `\\r\\n--${formBoundary}--`;\n\t\t\t\t\tconst headers: { [index: string]: string } = {\n\t\t\t\t\t\t\"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n\t\t\t\t\t};\n\n\t\t\t\t\t// Some request take a long time (1-2 minutes) to complete, where telemetry shows very small amount\n\t\t\t\t\t// of time spent on server, and usually small payload sizes. I.e. all the time is spent somewhere in\n\t\t\t\t\t// networking. Even bigger problem - a lot of requests timeout (based on cursory look - after 1-2 minutes)\n\t\t\t\t\t// So adding some timeout to ensure we retry again in hope of faster success.\n\t\t\t\t\t// Please see https://github.com/microsoft/FluidFramework/issues/6997 for details.\n\t\t\t\t\tconst abort = new AbortController();\n\t\t\t\t\tconst timer = setTimeout(() => abort.abort(), 30000);\n\n\t\t\t\t\tconst response =\n\t\t\t\t\t\tawait this.epochTracker.fetchAndParseAsJSON<IDeltaStorageGetResponse>(\n\t\t\t\t\t\t\tbaseUrl,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\t\tbody: postBody,\n\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\tsignal: abort.signal,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"ops\",\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\tscenarioName,\n\t\t\t\t\t\t);\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tconst deltaStorageResponse = response.content;\n\t\t\t\t\tconst messages =\n\t\t\t\t\t\tdeltaStorageResponse.value.length > 0 &&\n\t\t\t\t\t\t\"op\" in deltaStorageResponse.value[0]\n\t\t\t\t\t\t\t? (deltaStorageResponse.value as ISequencedDeltaOpMessage[]).map(\n\t\t\t\t\t\t\t\t\t(operation) => operation.op,\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: (deltaStorageResponse.value as ISequencedDocumentMessage[]);\n\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\theaders: Object.keys(headers).length > 0 ? true : undefined,\n\t\t\t\t\t\tlength: messages.length,\n\t\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\t});\n\n\t\t\t\t\t// It is assumed that server always returns all the ops that it has in the range that was requested.\n\t\t\t\t\t// This may change in the future, if so, we need to adjust and receive \"end\" value from server in such case.\n\t\t\t\t\treturn { messages, partialResult: false };\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tpublic buildUrl(from: number, to: number): string {\n\t\tconst filter = encodeURIComponent(\n\t\t\t`sequenceNumber ge ${from} and sequenceNumber le ${to - 1}`,\n\t\t);\n\t\tconst queryString = `?ump=1&filter=${filter}`;\n\t\treturn `${this.deltaFeedUrl}${queryString}`;\n\t}\n}\n\nexport class OdspDeltaStorageWithCache implements IDocumentDeltaStorageService {\n\tprivate useCacheForOps = true;\n\n\tpublic constructor(\n\t\tprivate snapshotOps: ISequencedDocumentMessage[] | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly batchSize: number,\n\t\tprivate readonly concurrency: number,\n\t\tprivate readonly getFromStorage: (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\ttelemetryProps: ITelemetryBaseProperties,\n\t\t\tfetchReason?: string,\n\t\t) => Promise<IDeltasFetchResult>,\n\t\tprivate readonly getCached: (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t) => Promise<ISequencedDocumentMessage[]>,\n\t\tprivate readonly requestFromSocket: (from: number, to: number) => void,\n\t\tprivate readonly opsReceived: (ops: ISequencedDocumentMessage[]) => void,\n\t\tprivate readonly storageManagerGetter: () => OdspDocumentStorageService | undefined,\n\t) {}\n\n\tpublic fetchMessages(\n\t\tfromTotal: number,\n\t\ttoTotal: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t\tfetchReason?: string,\n\t): IStream<ISequencedDocumentMessage[]> {\n\t\t// We do not control what's in the cache. Current API assumes that fetchMessages() keeps banging on\n\t\t// storage / cache until it gets ops it needs. This would result in deadlock if fixed range is asked from\n\t\t// cache and it's not there.\n\t\t// Better implementation would be to return only what we have in cache, but that also breaks API\n\t\tassert(!cachedOnly || toTotal === undefined, 0x1e3);\n\n\t\t// Don't use cache for ops is snapshot is fetched from network or if it was not fetched at all.\n\t\tthis.useCacheForOps =\n\t\t\tthis.useCacheForOps &&\n\t\t\tthis.storageManagerGetter()?.isFirstSnapshotFromNetwork === false;\n\t\tlet opsFromSnapshot = 0;\n\t\tlet opsFromCache = 0;\n\t\tlet opsFromStorage = 0;\n\n\t\tconst requestCallback = async (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\ttelemetryProps: ITelemetryBaseProperties,\n\t\t): Promise<IDeltasFetchResult> => {\n\t\t\tif (this.snapshotOps !== undefined && this.snapshotOps.length > 0) {\n\t\t\t\tconst messages = this.snapshotOps.filter(\n\t\t\t\t\t(op) => op.sequenceNumber >= from && op.sequenceNumber < to,\n\t\t\t\t);\n\t\t\t\tvalidateMessages(\"cached\", messages, from, this.logger);\n\t\t\t\tif (messages.length > 0 && messages[0].sequenceNumber === from) {\n\t\t\t\t\tthis.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);\n\t\t\t\t\topsFromSnapshot += messages.length;\n\t\t\t\t\treturn { messages, partialResult: true };\n\t\t\t\t}\n\t\t\t\tthis.snapshotOps = undefined;\n\t\t\t}\n\n\t\t\t// Kick out request to PUSH for ops if it has them\n\t\t\tthis.requestFromSocket(from, to);\n\n\t\t\t// Cache in normal flow is continuous. Once there is a miss, stop consulting cache.\n\t\t\t// This saves a bit of processing time.\n\t\t\tif (this.useCacheForOps) {\n\t\t\t\tconst messagesFromCache = await this.getCached(from, to);\n\t\t\t\tvalidateMessages(\"cached\", messagesFromCache, from, this.logger);\n\t\t\t\t// Set the firstCacheMiss as true in case we didn't get all the ops.\n\t\t\t\t// This will save an extra cache read on \"DocumentOpen\" or \"PostDocumentOpen\".\n\t\t\t\tthis.useCacheForOps = from + messagesFromCache.length >= to;\n\t\t\t\tif (messagesFromCache.length > 0) {\n\t\t\t\t\topsFromCache += messagesFromCache.length;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmessages: messagesFromCache,\n\t\t\t\t\t\tpartialResult: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (cachedOnly) {\n\t\t\t\treturn { messages: [], partialResult: false };\n\t\t\t}\n\n\t\t\tconst ops = await this.getFromStorage(from, to, telemetryProps, fetchReason);\n\t\t\tvalidateMessages(\"storage\", ops.messages, from, this.logger);\n\t\t\topsFromStorage += ops.messages.length;\n\t\t\tthis.opsReceived(ops.messages);\n\t\t\treturn ops;\n\t\t};\n\n\t\tconst stream = requestOps(\n\t\t\tasync (from: number, to: number, telemetryProps: ITelemetryBaseProperties) => {\n\t\t\t\tconst result = await requestCallback(from, to, telemetryProps);\n\t\t\t\t// Catch all case, just in case\n\t\t\t\tvalidateMessages(\"catch all\", result.messages, from, this.logger);\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\t// Staging: starting with no concurrency, listening for feedback first.\n\t\t\t// In future releases we will switch to actual concurrency\n\t\t\tthis.concurrency,\n\t\t\tfromTotal, // inclusive\n\t\t\ttoTotal, // exclusive\n\t\t\tthis.batchSize,\n\t\t\tthis.logger,\n\t\t\tabortSignal,\n\t\t\tfetchReason,\n\t\t);\n\n\t\treturn streamObserver(stream, (result) => {\n\t\t\tif (result.done && opsFromSnapshot + opsFromCache + opsFromStorage !== 0) {\n\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"CacheOpsRetrieved\",\n\t\t\t\t\topsFromSnapshot,\n\t\t\t\t\topsFromCache,\n\t\t\t\t\topsFromStorage,\n\t\t\t\t\treason: fetchReason,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
@@ -7,7 +7,7 @@ import { DocumentDeltaConnection } from "@fluidframework/driver-base";
7
7
  import { IAnyDriverError } from "@fluidframework/driver-definitions";
8
8
  import { OdspError } from "@fluidframework/odsp-driver-definitions";
9
9
  import { IClient, IConnect, IDocumentMessage } from "@fluidframework/protocol-definitions";
10
- import { EpochTracker } from "./epochTracker";
10
+ import { EpochTracker } from "./epochTracker.js";
11
11
  export interface FlushResult {
12
12
  lastPersistedSequenceNumber?: number;
13
13
  retryAfter?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"odspDocumentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/odspDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,mBAAmB,EACnB,eAAe,EAEf,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EACN,OAAO,EAC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