@fluidframework/container-runtime 2.0.0-dev.2.2.0.111723 → 2.0.0-dev.3.1.0.125672

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/.eslintrc.js +21 -10
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts +1 -2
  5. package/dist/batchTracker.d.ts.map +1 -1
  6. package/dist/batchTracker.js +2 -1
  7. package/dist/batchTracker.js.map +1 -1
  8. package/dist/blobManager.d.ts +62 -28
  9. package/dist/blobManager.d.ts.map +1 -1
  10. package/dist/blobManager.js +256 -102
  11. package/dist/blobManager.js.map +1 -1
  12. package/dist/connectionTelemetry.d.ts.map +1 -1
  13. package/dist/connectionTelemetry.js +11 -9
  14. package/dist/connectionTelemetry.js.map +1 -1
  15. package/dist/containerHandleContext.d.ts.map +1 -1
  16. package/dist/containerHandleContext.js +3 -1
  17. package/dist/containerHandleContext.js.map +1 -1
  18. package/dist/containerRuntime.d.ts +110 -78
  19. package/dist/containerRuntime.d.ts.map +1 -1
  20. package/dist/containerRuntime.js +336 -331
  21. package/dist/containerRuntime.js.map +1 -1
  22. package/dist/dataStore.d.ts.map +1 -1
  23. package/dist/dataStore.js +11 -9
  24. package/dist/dataStore.js.map +1 -1
  25. package/dist/dataStoreContext.d.ts +2 -1
  26. package/dist/dataStoreContext.d.ts.map +1 -1
  27. package/dist/dataStoreContext.js +40 -23
  28. package/dist/dataStoreContext.js.map +1 -1
  29. package/dist/dataStoreContexts.d.ts.map +1 -1
  30. package/dist/dataStoreContexts.js +7 -3
  31. package/dist/dataStoreContexts.js.map +1 -1
  32. package/dist/dataStoreRegistry.d.ts.map +1 -1
  33. package/dist/dataStoreRegistry.js +3 -1
  34. package/dist/dataStoreRegistry.js.map +1 -1
  35. package/dist/dataStores.d.ts +12 -9
  36. package/dist/dataStores.d.ts.map +1 -1
  37. package/dist/dataStores.js +69 -46
  38. package/dist/dataStores.js.map +1 -1
  39. package/dist/deltaScheduler.d.ts.map +1 -1
  40. package/dist/deltaScheduler.js +8 -3
  41. package/dist/deltaScheduler.js.map +1 -1
  42. package/dist/garbageCollection.d.ts +57 -42
  43. package/dist/garbageCollection.d.ts.map +1 -1
  44. package/dist/garbageCollection.js +371 -239
  45. package/dist/garbageCollection.js.map +1 -1
  46. package/dist/garbageCollectionConstants.d.ts +23 -0
  47. package/dist/garbageCollectionConstants.d.ts.map +1 -0
  48. package/dist/garbageCollectionConstants.js +36 -0
  49. package/dist/garbageCollectionConstants.js.map +1 -0
  50. package/dist/garbageCollectionHelpers.d.ts +15 -0
  51. package/dist/garbageCollectionHelpers.d.ts.map +1 -0
  52. package/dist/garbageCollectionHelpers.js +27 -0
  53. package/dist/garbageCollectionHelpers.js.map +1 -0
  54. package/dist/gcSweepReadyUsageDetection.d.ts +5 -5
  55. package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
  56. package/dist/gcSweepReadyUsageDetection.js +15 -11
  57. package/dist/gcSweepReadyUsageDetection.js.map +1 -1
  58. package/dist/index.d.ts +4 -3
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +5 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/opLifecycle/batchManager.d.ts +42 -0
  63. package/dist/opLifecycle/batchManager.d.ts.map +1 -0
  64. package/dist/opLifecycle/batchManager.js +124 -0
  65. package/dist/opLifecycle/batchManager.js.map +1 -0
  66. package/dist/opLifecycle/definitions.d.ts +64 -0
  67. package/dist/opLifecycle/definitions.d.ts.map +1 -0
  68. package/dist/opLifecycle/definitions.js +7 -0
  69. package/dist/opLifecycle/definitions.js.map +1 -0
  70. package/dist/opLifecycle/index.d.ts +12 -0
  71. package/dist/opLifecycle/index.d.ts.map +1 -0
  72. package/dist/opLifecycle/index.js +22 -0
  73. package/dist/opLifecycle/index.js.map +1 -0
  74. package/dist/{opCompressor.d.ts → opLifecycle/opCompressor.d.ts} +3 -3
  75. package/dist/opLifecycle/opCompressor.d.ts.map +1 -0
  76. package/dist/opLifecycle/opCompressor.js +67 -0
  77. package/dist/opLifecycle/opCompressor.js.map +1 -0
  78. package/dist/{opDecompressor.d.ts → opLifecycle/opDecompressor.d.ts} +2 -1
  79. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -0
  80. package/dist/{opDecompressor.js → opLifecycle/opDecompressor.js} +37 -21
  81. package/dist/opLifecycle/opDecompressor.js.map +1 -0
  82. package/dist/opLifecycle/opSplitter.d.ts +49 -0
  83. package/dist/opLifecycle/opSplitter.d.ts.map +1 -0
  84. package/dist/opLifecycle/opSplitter.js +173 -0
  85. package/dist/opLifecycle/opSplitter.js.map +1 -0
  86. package/dist/opLifecycle/outbox.d.ts +52 -0
  87. package/dist/opLifecycle/outbox.d.ts.map +1 -0
  88. package/dist/opLifecycle/outbox.js +164 -0
  89. package/dist/opLifecycle/outbox.js.map +1 -0
  90. package/dist/opLifecycle/remoteMessageProcessor.d.ts +26 -0
  91. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
  92. package/dist/opLifecycle/remoteMessageProcessor.js +96 -0
  93. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -0
  94. package/dist/opProperties.d.ts.map +1 -1
  95. package/dist/opProperties.js +1 -3
  96. package/dist/opProperties.js.map +1 -1
  97. package/dist/orderedClientElection.d.ts.map +1 -1
  98. package/dist/orderedClientElection.js +10 -4
  99. package/dist/orderedClientElection.js.map +1 -1
  100. package/dist/packageVersion.d.ts +1 -1
  101. package/dist/packageVersion.js +1 -1
  102. package/dist/packageVersion.js.map +1 -1
  103. package/dist/pendingStateManager.d.ts +4 -13
  104. package/dist/pendingStateManager.d.ts.map +1 -1
  105. package/dist/pendingStateManager.js +134 -161
  106. package/dist/pendingStateManager.js.map +1 -1
  107. package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
  108. package/dist/runWhileConnectedCoordinator.js.map +1 -1
  109. package/dist/runningSummarizer.d.ts.map +1 -1
  110. package/dist/runningSummarizer.js +34 -22
  111. package/dist/runningSummarizer.js.map +1 -1
  112. package/dist/scheduleManager.d.ts +0 -1
  113. package/dist/scheduleManager.d.ts.map +1 -1
  114. package/dist/scheduleManager.js +11 -21
  115. package/dist/scheduleManager.js.map +1 -1
  116. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  117. package/dist/serializedSnapshotStorage.js +3 -1
  118. package/dist/serializedSnapshotStorage.js.map +1 -1
  119. package/dist/summarizer.d.ts +2 -3
  120. package/dist/summarizer.d.ts.map +1 -1
  121. package/dist/summarizer.js +39 -18
  122. package/dist/summarizer.js.map +1 -1
  123. package/dist/summarizerClientElection.d.ts +1 -2
  124. package/dist/summarizerClientElection.d.ts.map +1 -1
  125. package/dist/summarizerClientElection.js +3 -30
  126. package/dist/summarizerClientElection.js.map +1 -1
  127. package/dist/summarizerHandle.d.ts.map +1 -1
  128. package/dist/summarizerHandle.js.map +1 -1
  129. package/dist/summarizerHeuristics.d.ts.map +1 -1
  130. package/dist/summarizerHeuristics.js +6 -9
  131. package/dist/summarizerHeuristics.js.map +1 -1
  132. package/dist/summarizerTypes.d.ts +22 -25
  133. package/dist/summarizerTypes.d.ts.map +1 -1
  134. package/dist/summarizerTypes.js.map +1 -1
  135. package/dist/summaryCollection.d.ts.map +1 -1
  136. package/dist/summaryCollection.js +18 -8
  137. package/dist/summaryCollection.js.map +1 -1
  138. package/dist/summaryFormat.d.ts.map +1 -1
  139. package/dist/summaryFormat.js +18 -11
  140. package/dist/summaryFormat.js.map +1 -1
  141. package/dist/summaryGenerator.d.ts.map +1 -1
  142. package/dist/summaryGenerator.js +32 -14
  143. package/dist/summaryGenerator.js.map +1 -1
  144. package/dist/summaryManager.d.ts.map +1 -1
  145. package/dist/summaryManager.js +21 -9
  146. package/dist/summaryManager.js.map +1 -1
  147. package/dist/throttler.d.ts +2 -2
  148. package/dist/throttler.d.ts.map +1 -1
  149. package/dist/throttler.js +4 -4
  150. package/dist/throttler.js.map +1 -1
  151. package/garbageCollection.md +15 -2
  152. package/lib/batchTracker.d.ts +1 -2
  153. package/lib/batchTracker.d.ts.map +1 -1
  154. package/lib/batchTracker.js +2 -1
  155. package/lib/batchTracker.js.map +1 -1
  156. package/lib/blobManager.d.ts +62 -28
  157. package/lib/blobManager.d.ts.map +1 -1
  158. package/lib/blobManager.js +259 -105
  159. package/lib/blobManager.js.map +1 -1
  160. package/lib/connectionTelemetry.d.ts.map +1 -1
  161. package/lib/connectionTelemetry.js +11 -9
  162. package/lib/connectionTelemetry.js.map +1 -1
  163. package/lib/containerHandleContext.d.ts.map +1 -1
  164. package/lib/containerHandleContext.js +3 -1
  165. package/lib/containerHandleContext.js.map +1 -1
  166. package/lib/containerRuntime.d.ts +110 -78
  167. package/lib/containerRuntime.d.ts.map +1 -1
  168. package/lib/containerRuntime.js +340 -334
  169. package/lib/containerRuntime.js.map +1 -1
  170. package/lib/dataStore.d.ts.map +1 -1
  171. package/lib/dataStore.js +11 -9
  172. package/lib/dataStore.js.map +1 -1
  173. package/lib/dataStoreContext.d.ts +2 -1
  174. package/lib/dataStoreContext.d.ts.map +1 -1
  175. package/lib/dataStoreContext.js +41 -24
  176. package/lib/dataStoreContext.js.map +1 -1
  177. package/lib/dataStoreContexts.d.ts.map +1 -1
  178. package/lib/dataStoreContexts.js +7 -3
  179. package/lib/dataStoreContexts.js.map +1 -1
  180. package/lib/dataStoreRegistry.d.ts.map +1 -1
  181. package/lib/dataStoreRegistry.js +3 -1
  182. package/lib/dataStoreRegistry.js.map +1 -1
  183. package/lib/dataStores.d.ts +12 -9
  184. package/lib/dataStores.d.ts.map +1 -1
  185. package/lib/dataStores.js +75 -52
  186. package/lib/dataStores.js.map +1 -1
  187. package/lib/deltaScheduler.d.ts.map +1 -1
  188. package/lib/deltaScheduler.js +9 -4
  189. package/lib/deltaScheduler.js.map +1 -1
  190. package/lib/garbageCollection.d.ts +57 -42
  191. package/lib/garbageCollection.d.ts.map +1 -1
  192. package/lib/garbageCollection.js +364 -232
  193. package/lib/garbageCollection.js.map +1 -1
  194. package/lib/garbageCollectionConstants.d.ts +23 -0
  195. package/lib/garbageCollectionConstants.d.ts.map +1 -0
  196. package/lib/garbageCollectionConstants.js +33 -0
  197. package/lib/garbageCollectionConstants.js.map +1 -0
  198. package/lib/garbageCollectionHelpers.d.ts +15 -0
  199. package/lib/garbageCollectionHelpers.d.ts.map +1 -0
  200. package/lib/garbageCollectionHelpers.js +23 -0
  201. package/lib/garbageCollectionHelpers.js.map +1 -0
  202. package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
  203. package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
  204. package/lib/gcSweepReadyUsageDetection.js +15 -11
  205. package/lib/gcSweepReadyUsageDetection.js.map +1 -1
  206. package/lib/index.d.ts +4 -3
  207. package/lib/index.d.ts.map +1 -1
  208. package/lib/index.js +3 -3
  209. package/lib/index.js.map +1 -1
  210. package/lib/opLifecycle/batchManager.d.ts +42 -0
  211. package/lib/opLifecycle/batchManager.d.ts.map +1 -0
  212. package/lib/opLifecycle/batchManager.js +120 -0
  213. package/lib/opLifecycle/batchManager.js.map +1 -0
  214. package/lib/opLifecycle/definitions.d.ts +64 -0
  215. package/lib/opLifecycle/definitions.d.ts.map +1 -0
  216. package/lib/opLifecycle/definitions.js +6 -0
  217. package/lib/opLifecycle/definitions.js.map +1 -0
  218. package/lib/opLifecycle/index.d.ts +12 -0
  219. package/lib/opLifecycle/index.d.ts.map +1 -0
  220. package/lib/opLifecycle/index.js +11 -0
  221. package/lib/opLifecycle/index.js.map +1 -0
  222. package/lib/{opCompressor.d.ts → opLifecycle/opCompressor.d.ts} +3 -3
  223. package/lib/opLifecycle/opCompressor.d.ts.map +1 -0
  224. package/lib/opLifecycle/opCompressor.js +63 -0
  225. package/lib/opLifecycle/opCompressor.js.map +1 -0
  226. package/lib/{opDecompressor.d.ts → opLifecycle/opDecompressor.d.ts} +2 -1
  227. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -0
  228. package/lib/{opDecompressor.js → opLifecycle/opDecompressor.js} +37 -21
  229. package/lib/opLifecycle/opDecompressor.js.map +1 -0
  230. package/lib/opLifecycle/opSplitter.d.ts +49 -0
  231. package/lib/opLifecycle/opSplitter.d.ts.map +1 -0
  232. package/lib/opLifecycle/opSplitter.js +168 -0
  233. package/lib/opLifecycle/opSplitter.js.map +1 -0
  234. package/lib/opLifecycle/outbox.d.ts +52 -0
  235. package/lib/opLifecycle/outbox.d.ts.map +1 -0
  236. package/lib/opLifecycle/outbox.js +160 -0
  237. package/lib/opLifecycle/outbox.js.map +1 -0
  238. package/lib/opLifecycle/remoteMessageProcessor.d.ts +26 -0
  239. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
  240. package/lib/opLifecycle/remoteMessageProcessor.js +91 -0
  241. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -0
  242. package/lib/opProperties.d.ts.map +1 -1
  243. package/lib/opProperties.js +1 -3
  244. package/lib/opProperties.js.map +1 -1
  245. package/lib/orderedClientElection.d.ts.map +1 -1
  246. package/lib/orderedClientElection.js +10 -4
  247. package/lib/orderedClientElection.js.map +1 -1
  248. package/lib/packageVersion.d.ts +1 -1
  249. package/lib/packageVersion.js +1 -1
  250. package/lib/packageVersion.js.map +1 -1
  251. package/lib/pendingStateManager.d.ts +4 -13
  252. package/lib/pendingStateManager.d.ts.map +1 -1
  253. package/lib/pendingStateManager.js +134 -161
  254. package/lib/pendingStateManager.js.map +1 -1
  255. package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
  256. package/lib/runWhileConnectedCoordinator.js.map +1 -1
  257. package/lib/runningSummarizer.d.ts.map +1 -1
  258. package/lib/runningSummarizer.js +35 -23
  259. package/lib/runningSummarizer.js.map +1 -1
  260. package/lib/scheduleManager.d.ts +0 -1
  261. package/lib/scheduleManager.d.ts.map +1 -1
  262. package/lib/scheduleManager.js +11 -21
  263. package/lib/scheduleManager.js.map +1 -1
  264. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  265. package/lib/serializedSnapshotStorage.js +3 -1
  266. package/lib/serializedSnapshotStorage.js.map +1 -1
  267. package/lib/summarizer.d.ts +2 -3
  268. package/lib/summarizer.d.ts.map +1 -1
  269. package/lib/summarizer.js +39 -18
  270. package/lib/summarizer.js.map +1 -1
  271. package/lib/summarizerClientElection.d.ts +1 -2
  272. package/lib/summarizerClientElection.d.ts.map +1 -1
  273. package/lib/summarizerClientElection.js +3 -30
  274. package/lib/summarizerClientElection.js.map +1 -1
  275. package/lib/summarizerHandle.d.ts.map +1 -1
  276. package/lib/summarizerHandle.js.map +1 -1
  277. package/lib/summarizerHeuristics.d.ts.map +1 -1
  278. package/lib/summarizerHeuristics.js +6 -9
  279. package/lib/summarizerHeuristics.js.map +1 -1
  280. package/lib/summarizerTypes.d.ts +22 -25
  281. package/lib/summarizerTypes.d.ts.map +1 -1
  282. package/lib/summarizerTypes.js.map +1 -1
  283. package/lib/summaryCollection.d.ts.map +1 -1
  284. package/lib/summaryCollection.js +18 -8
  285. package/lib/summaryCollection.js.map +1 -1
  286. package/lib/summaryFormat.d.ts.map +1 -1
  287. package/lib/summaryFormat.js +20 -13
  288. package/lib/summaryFormat.js.map +1 -1
  289. package/lib/summaryGenerator.d.ts.map +1 -1
  290. package/lib/summaryGenerator.js +32 -14
  291. package/lib/summaryGenerator.js.map +1 -1
  292. package/lib/summaryManager.d.ts.map +1 -1
  293. package/lib/summaryManager.js +21 -9
  294. package/lib/summaryManager.js.map +1 -1
  295. package/lib/throttler.d.ts +2 -2
  296. package/lib/throttler.d.ts.map +1 -1
  297. package/lib/throttler.js +4 -4
  298. package/lib/throttler.js.map +1 -1
  299. package/package.json +28 -38
  300. package/prettier.config.cjs +1 -1
  301. package/src/batchTracker.ts +55 -50
  302. package/src/blobManager.ts +802 -541
  303. package/src/connectionTelemetry.ts +280 -249
  304. package/src/containerHandleContext.ts +27 -29
  305. package/src/containerRuntime.ts +3125 -2982
  306. package/src/dataStore.ts +172 -159
  307. package/src/dataStoreContext.ts +1049 -992
  308. package/src/dataStoreContexts.ts +178 -161
  309. package/src/dataStoreRegistry.ts +25 -20
  310. package/src/dataStores.ts +785 -711
  311. package/src/deltaScheduler.ts +158 -150
  312. package/src/garbageCollection.ts +1797 -1558
  313. package/src/garbageCollectionConstants.ts +38 -0
  314. package/src/garbageCollectionHelpers.ts +37 -0
  315. package/src/gcSweepReadyUsageDetection.ts +90 -84
  316. package/src/index.ts +68 -69
  317. package/src/opLifecycle/batchManager.ts +167 -0
  318. package/src/opLifecycle/definitions.ts +70 -0
  319. package/src/opLifecycle/index.ts +18 -0
  320. package/src/opLifecycle/opCompressor.ts +82 -0
  321. package/src/opLifecycle/opDecompressor.ts +124 -0
  322. package/src/opLifecycle/opSplitter.ts +238 -0
  323. package/src/opLifecycle/outbox.ts +228 -0
  324. package/src/opLifecycle/remoteMessageProcessor.ts +106 -0
  325. package/src/opProperties.ts +11 -9
  326. package/src/orderedClientElection.ts +489 -457
  327. package/src/packageVersion.ts +1 -1
  328. package/src/pendingStateManager.ts +379 -381
  329. package/src/runWhileConnectedCoordinator.ts +78 -71
  330. package/src/runningSummarizer.ts +619 -582
  331. package/src/scheduleManager.ts +299 -280
  332. package/src/serializedSnapshotStorage.ts +116 -111
  333. package/src/summarizer.ts +417 -381
  334. package/src/summarizerClientElection.ts +107 -129
  335. package/src/summarizerHandle.ts +11 -9
  336. package/src/summarizerHeuristics.ts +183 -186
  337. package/src/summarizerTypes.ts +344 -333
  338. package/src/summaryCollection.ts +378 -349
  339. package/src/summaryFormat.ts +146 -127
  340. package/src/summaryGenerator.ts +464 -406
  341. package/src/summaryManager.ts +377 -348
  342. package/src/throttler.ts +131 -122
  343. package/tsconfig.esnext.json +6 -6
  344. package/tsconfig.json +9 -13
  345. package/dist/batchManager.d.ts +0 -42
  346. package/dist/batchManager.d.ts.map +0 -1
  347. package/dist/batchManager.js +0 -83
  348. package/dist/batchManager.js.map +0 -1
  349. package/dist/opCompressor.d.ts.map +0 -1
  350. package/dist/opCompressor.js +0 -50
  351. package/dist/opCompressor.js.map +0 -1
  352. package/dist/opDecompressor.d.ts.map +0 -1
  353. package/dist/opDecompressor.js.map +0 -1
  354. package/lib/batchManager.d.ts +0 -42
  355. package/lib/batchManager.d.ts.map +0 -1
  356. package/lib/batchManager.js +0 -79
  357. package/lib/batchManager.js.map +0 -1
  358. package/lib/opCompressor.d.ts.map +0 -1
  359. package/lib/opCompressor.js +0 -46
  360. package/lib/opCompressor.js.map +0 -1
  361. package/lib/opDecompressor.d.ts.map +0 -1
  362. package/lib/opDecompressor.js.map +0 -1
  363. package/src/batchManager.ts +0 -108
  364. package/src/opCompressor.ts +0 -59
  365. package/src/opDecompressor.ts +0 -82
@@ -3,169 +3,186 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IDisposable, ITelemetryBaseLogger, ITelemetryLogger } from "@fluidframework/common-definitions";
6
+ import {
7
+ IDisposable,
8
+ ITelemetryBaseLogger,
9
+ ITelemetryLogger,
10
+ } from "@fluidframework/common-definitions";
7
11
  import { assert, Deferred, Lazy } from "@fluidframework/common-utils";
8
12
  import { ChildLogger } from "@fluidframework/telemetry-utils";
9
13
  import { FluidDataStoreContext, LocalFluidDataStoreContext } from "./dataStoreContext";
10
14
 
11
- export class DataStoreContexts implements Iterable<[string, FluidDataStoreContext]>, IDisposable {
12
- private readonly notBoundContexts = new Set<string>();
13
-
14
- /** Attached and loaded context proxies */
15
- private readonly _contexts = new Map<string, FluidDataStoreContext>();
16
-
17
- /**
18
- * List of pending context waiting either to be bound or to arrive from another client.
19
- * This covers the case where a local context has been created but not yet bound,
20
- * or the case where a client knows a store will exist and is waiting on its creation,
21
- * so that a caller may await the deferred's promise until such a time as the context is fully ready.
22
- * This is a superset of _contexts, since contexts remain here once the Deferred resolves.
23
- */
24
- private readonly deferredContexts = new Map<string, Deferred<FluidDataStoreContext>>();
25
-
26
- private readonly disposeOnce = new Lazy<void>(() => {
27
- // close/stop all store contexts
28
- for (const [fluidDataStoreId, contextD] of this.deferredContexts) {
29
- contextD.promise.then((context) => {
30
- context.dispose();
31
- }).catch((contextError) => {
32
- this._logger.sendErrorEvent({
33
- eventName: "FluidDataStoreContextDisposeError",
34
- fluidDataStoreId,
35
- },
36
- contextError);
37
- });
38
- }
39
- });
40
-
41
- private readonly _logger: ITelemetryLogger;
42
-
43
- constructor(baseLogger: ITelemetryBaseLogger) {
44
- this._logger = ChildLogger.create(baseLogger);
45
- }
46
-
47
- [Symbol.iterator](): Iterator<[string, FluidDataStoreContext]> {
48
- return this._contexts.entries();
49
- }
50
-
51
- public get size(): number {
52
- return this._contexts.size;
53
- }
54
-
55
- public get disposed() { return this.disposeOnce.evaluated; }
56
- public readonly dispose = () => this.disposeOnce.value;
57
-
58
- public notBoundLength() {
59
- return this.notBoundContexts.size;
60
- }
61
-
62
- public isNotBound(id: string) {
63
- return this.notBoundContexts.has(id);
64
- }
65
-
66
- public has(id: string) {
67
- return this._contexts.has(id);
68
- }
69
-
70
- public get(id: string): FluidDataStoreContext | undefined {
71
- return this._contexts.get(id);
72
- }
73
-
74
- public delete(id: string): boolean {
75
- this.deferredContexts.delete(id);
76
- this.notBoundContexts.delete(id);
77
- return this._contexts.delete(id);
78
- }
79
-
80
- /**
81
- * Return the unbound local context with the given id,
82
- * or undefined if it's not found or not unbound.
83
- */
84
- public getUnbound(id: string): LocalFluidDataStoreContext | undefined {
85
- const context = this._contexts.get(id);
86
- if (context === undefined || !this.notBoundContexts.has(id)) {
87
- return undefined;
88
- }
89
-
90
- return context as LocalFluidDataStoreContext;
91
- }
92
-
93
- /**
94
- * Add the given context, marking it as to-be-bound
95
- */
96
- public addUnbound(context: LocalFluidDataStoreContext) {
97
- const id = context.id;
98
- assert(!this._contexts.has(id), 0x158 /* "Creating store with existing ID" */);
99
-
100
- this._contexts.set(id, context);
101
-
102
- this.notBoundContexts.add(id);
103
- this.ensureDeferred(id);
104
- }
105
-
106
- /**
107
- * Get the context with the given id, once it exists locally and is attached.
108
- * e.g. If created locally, it must be bound, or if created remotely then it's fine as soon as it's sync'd in.
109
- * @param id - The id of the context to get
110
- * @param wait - If false, return undefined if the context isn't present and ready now. Otherwise, wait for it.
111
- */
112
- public async getBoundOrRemoted(id: string, wait: boolean): Promise<FluidDataStoreContext | undefined> {
113
- const deferredContext = this.ensureDeferred(id);
114
-
115
- if (!wait && !deferredContext.isCompleted) {
116
- return undefined;
117
- }
118
-
119
- return deferredContext.promise;
120
- }
121
-
122
- private ensureDeferred(id: string): Deferred<FluidDataStoreContext> {
123
- const deferred = this.deferredContexts.get(id);
124
- if (deferred) { return deferred; }
125
-
126
- const newDeferred = new Deferred<FluidDataStoreContext>();
127
- this.deferredContexts.set(id, newDeferred);
128
- return newDeferred;
129
- }
130
-
131
- /**
132
- * Update this context as bound
133
- */
134
- public bind(id: string) {
135
- const removed: boolean = this.notBoundContexts.delete(id);
136
- assert(removed, 0x159 /* "The given id was not found in notBoundContexts to delete" */);
137
-
138
- this.resolveDeferred(id);
139
- }
140
-
141
- /**
142
- * Triggers the deferred to resolve, indicating the context is not local-only
143
- * @param id - The id of the context to resolve to
144
- */
145
- private resolveDeferred(id: string) {
146
- const context = this._contexts.get(id);
147
- assert(!!context, 0x15a /* "Cannot find context to resolve to" */);
148
- assert(!this.notBoundContexts.has(id),
149
- 0x15b /* "Expected this id to already be removed from notBoundContexts" */);
150
-
151
- const deferred = this.deferredContexts.get(id);
152
- assert(!!deferred, 0x15c /* "Cannot find deferred to resolve" */);
153
- deferred.resolve(context);
154
- }
155
-
156
- /**
157
- * Add the given context, marking it as not local-only.
158
- * This could be because it's a local context that's been bound, or because it's a remote context.
159
- * @param context - The context to add
160
- */
161
- public addBoundOrRemoted(context: FluidDataStoreContext) {
162
- const id = context.id;
163
- assert(!this._contexts.has(id), 0x15d /* "Creating store with existing ID" */);
164
-
165
- this._contexts.set(id, context);
166
-
167
- // Resolve the deferred immediately since this context is not unbound
168
- this.ensureDeferred(id);
169
- this.resolveDeferred(id);
170
- }
15
+ export class DataStoreContexts implements Iterable<[string, FluidDataStoreContext]>, IDisposable {
16
+ private readonly notBoundContexts = new Set<string>();
17
+
18
+ /** Attached and loaded context proxies */
19
+ private readonly _contexts = new Map<string, FluidDataStoreContext>();
20
+
21
+ /**
22
+ * List of pending context waiting either to be bound or to arrive from another client.
23
+ * This covers the case where a local context has been created but not yet bound,
24
+ * or the case where a client knows a store will exist and is waiting on its creation,
25
+ * so that a caller may await the deferred's promise until such a time as the context is fully ready.
26
+ * This is a superset of _contexts, since contexts remain here once the Deferred resolves.
27
+ */
28
+ private readonly deferredContexts = new Map<string, Deferred<FluidDataStoreContext>>();
29
+
30
+ private readonly disposeOnce = new Lazy<void>(() => {
31
+ // close/stop all store contexts
32
+ for (const [fluidDataStoreId, contextD] of this.deferredContexts) {
33
+ contextD.promise
34
+ .then((context) => {
35
+ context.dispose();
36
+ })
37
+ .catch((contextError) => {
38
+ this._logger.sendErrorEvent(
39
+ {
40
+ eventName: "FluidDataStoreContextDisposeError",
41
+ fluidDataStoreId,
42
+ },
43
+ contextError,
44
+ );
45
+ });
46
+ }
47
+ });
48
+
49
+ private readonly _logger: ITelemetryLogger;
50
+
51
+ constructor(baseLogger: ITelemetryBaseLogger) {
52
+ this._logger = ChildLogger.create(baseLogger);
53
+ }
54
+
55
+ [Symbol.iterator](): Iterator<[string, FluidDataStoreContext]> {
56
+ return this._contexts.entries();
57
+ }
58
+
59
+ public get size(): number {
60
+ return this._contexts.size;
61
+ }
62
+
63
+ public get disposed() {
64
+ return this.disposeOnce.evaluated;
65
+ }
66
+ public readonly dispose = () => this.disposeOnce.value;
67
+
68
+ public notBoundLength() {
69
+ return this.notBoundContexts.size;
70
+ }
71
+
72
+ public isNotBound(id: string) {
73
+ return this.notBoundContexts.has(id);
74
+ }
75
+
76
+ public has(id: string) {
77
+ return this._contexts.has(id);
78
+ }
79
+
80
+ public get(id: string): FluidDataStoreContext | undefined {
81
+ return this._contexts.get(id);
82
+ }
83
+
84
+ public delete(id: string): boolean {
85
+ this.deferredContexts.delete(id);
86
+ this.notBoundContexts.delete(id);
87
+ return this._contexts.delete(id);
88
+ }
89
+
90
+ /**
91
+ * Return the unbound local context with the given id,
92
+ * or undefined if it's not found or not unbound.
93
+ */
94
+ public getUnbound(id: string): LocalFluidDataStoreContext | undefined {
95
+ const context = this._contexts.get(id);
96
+ if (context === undefined || !this.notBoundContexts.has(id)) {
97
+ return undefined;
98
+ }
99
+
100
+ return context as LocalFluidDataStoreContext;
101
+ }
102
+
103
+ /**
104
+ * Add the given context, marking it as to-be-bound
105
+ */
106
+ public addUnbound(context: LocalFluidDataStoreContext) {
107
+ const id = context.id;
108
+ assert(!this._contexts.has(id), 0x158 /* "Creating store with existing ID" */);
109
+
110
+ this._contexts.set(id, context);
111
+
112
+ this.notBoundContexts.add(id);
113
+ this.ensureDeferred(id);
114
+ }
115
+
116
+ /**
117
+ * Get the context with the given id, once it exists locally and is attached.
118
+ * e.g. If created locally, it must be bound, or if created remotely then it's fine as soon as it's sync'd in.
119
+ * @param id - The id of the context to get
120
+ * @param wait - If false, return undefined if the context isn't present and ready now. Otherwise, wait for it.
121
+ */
122
+ public async getBoundOrRemoted(
123
+ id: string,
124
+ wait: boolean,
125
+ ): Promise<FluidDataStoreContext | undefined> {
126
+ const deferredContext = this.ensureDeferred(id);
127
+
128
+ if (!wait && !deferredContext.isCompleted) {
129
+ return undefined;
130
+ }
131
+
132
+ return deferredContext.promise;
133
+ }
134
+
135
+ private ensureDeferred(id: string): Deferred<FluidDataStoreContext> {
136
+ const deferred = this.deferredContexts.get(id);
137
+ if (deferred) {
138
+ return deferred;
139
+ }
140
+
141
+ const newDeferred = new Deferred<FluidDataStoreContext>();
142
+ this.deferredContexts.set(id, newDeferred);
143
+ return newDeferred;
144
+ }
145
+
146
+ /**
147
+ * Update this context as bound
148
+ */
149
+ public bind(id: string) {
150
+ const removed: boolean = this.notBoundContexts.delete(id);
151
+ assert(removed, 0x159 /* "The given id was not found in notBoundContexts to delete" */);
152
+
153
+ this.resolveDeferred(id);
154
+ }
155
+
156
+ /**
157
+ * Triggers the deferred to resolve, indicating the context is not local-only
158
+ * @param id - The id of the context to resolve to
159
+ */
160
+ private resolveDeferred(id: string) {
161
+ const context = this._contexts.get(id);
162
+ assert(!!context, 0x15a /* "Cannot find context to resolve to" */);
163
+ assert(
164
+ !this.notBoundContexts.has(id),
165
+ 0x15b /* "Expected this id to already be removed from notBoundContexts" */,
166
+ );
167
+
168
+ const deferred = this.deferredContexts.get(id);
169
+ assert(!!deferred, 0x15c /* "Cannot find deferred to resolve" */);
170
+ deferred.resolve(context);
171
+ }
172
+
173
+ /**
174
+ * Add the given context, marking it as not local-only.
175
+ * This could be because it's a local context that's been bound, or because it's a remote context.
176
+ * @param context - The context to add
177
+ */
178
+ public addBoundOrRemoted(context: FluidDataStoreContext) {
179
+ const id = context.id;
180
+ assert(!this._contexts.has(id), 0x15d /* "Creating store with existing ID" */);
181
+
182
+ this._contexts.set(id, context);
183
+
184
+ // Resolve the deferred immediately since this context is not unbound
185
+ this.ensureDeferred(id);
186
+ this.resolveDeferred(id);
187
+ }
171
188
  }
@@ -4,31 +4,36 @@
4
4
  */
5
5
  import { UsageError } from "@fluidframework/container-utils";
6
6
  import {
7
- FluidDataStoreRegistryEntry,
8
- IFluidDataStoreRegistry,
9
- NamedFluidDataStoreRegistryEntries,
7
+ FluidDataStoreRegistryEntry,
8
+ IFluidDataStoreRegistry,
9
+ NamedFluidDataStoreRegistryEntries,
10
10
  } from "@fluidframework/runtime-definitions";
11
11
 
12
12
  export class FluidDataStoreRegistry implements IFluidDataStoreRegistry {
13
- private readonly map: Map<string, FluidDataStoreRegistryEntry | Promise<FluidDataStoreRegistryEntry>>;
13
+ private readonly map: Map<
14
+ string,
15
+ FluidDataStoreRegistryEntry | Promise<FluidDataStoreRegistryEntry>
16
+ >;
14
17
 
15
- public get IFluidDataStoreRegistry() { return this; }
18
+ public get IFluidDataStoreRegistry() {
19
+ return this;
20
+ }
16
21
 
17
- constructor(namedEntries: NamedFluidDataStoreRegistryEntries) {
18
- this.map = new Map();
19
- for (const entry of namedEntries) {
20
- if (this.map.has(entry[0])) {
21
- throw new UsageError("Duplicate entry names exist");
22
- }
23
- this.map.set(entry[0], entry[1]);
24
- }
25
- }
22
+ constructor(namedEntries: NamedFluidDataStoreRegistryEntries) {
23
+ this.map = new Map();
24
+ for (const entry of namedEntries) {
25
+ if (this.map.has(entry[0])) {
26
+ throw new UsageError("Duplicate entry names exist");
27
+ }
28
+ this.map.set(entry[0], entry[1]);
29
+ }
30
+ }
26
31
 
27
- public async get(name: string): Promise<FluidDataStoreRegistryEntry | undefined> {
28
- if (this.map.has(name)) {
29
- return this.map.get(name);
30
- }
32
+ public async get(name: string): Promise<FluidDataStoreRegistryEntry | undefined> {
33
+ if (this.map.has(name)) {
34
+ return this.map.get(name);
35
+ }
31
36
 
32
- return undefined;
33
- }
37
+ return undefined;
38
+ }
34
39
  }