@fluidframework/container-runtime 2.0.0-internal.3.0.1 → 2.0.0-internal.3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/.eslintrc.js +19 -19
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts.map +1 -1
  5. package/dist/batchTracker.js +2 -1
  6. package/dist/batchTracker.js.map +1 -1
  7. package/dist/blobManager.d.ts +9 -2
  8. package/dist/blobManager.d.ts.map +1 -1
  9. package/dist/blobManager.js +80 -33
  10. package/dist/blobManager.js.map +1 -1
  11. package/dist/connectionTelemetry.d.ts.map +1 -1
  12. package/dist/connectionTelemetry.js +11 -9
  13. package/dist/connectionTelemetry.js.map +1 -1
  14. package/dist/containerHandleContext.d.ts.map +1 -1
  15. package/dist/containerHandleContext.js +3 -1
  16. package/dist/containerHandleContext.js.map +1 -1
  17. package/dist/containerRuntime.d.ts +10 -0
  18. package/dist/containerRuntime.d.ts.map +1 -1
  19. package/dist/containerRuntime.js +140 -72
  20. package/dist/containerRuntime.js.map +1 -1
  21. package/dist/dataStore.d.ts.map +1 -1
  22. package/dist/dataStore.js +11 -9
  23. package/dist/dataStore.js.map +1 -1
  24. package/dist/dataStoreContext.d.ts +18 -1
  25. package/dist/dataStoreContext.d.ts.map +1 -1
  26. package/dist/dataStoreContext.js +66 -15
  27. package/dist/dataStoreContext.js.map +1 -1
  28. package/dist/dataStoreContexts.d.ts.map +1 -1
  29. package/dist/dataStoreContexts.js +7 -3
  30. package/dist/dataStoreContexts.js.map +1 -1
  31. package/dist/dataStoreRegistry.d.ts.map +1 -1
  32. package/dist/dataStoreRegistry.js +3 -1
  33. package/dist/dataStoreRegistry.js.map +1 -1
  34. package/dist/dataStores.d.ts +26 -1
  35. package/dist/dataStores.d.ts.map +1 -1
  36. package/dist/dataStores.js +103 -18
  37. package/dist/dataStores.js.map +1 -1
  38. package/dist/deltaScheduler.d.ts.map +1 -1
  39. package/dist/deltaScheduler.js +8 -3
  40. package/dist/deltaScheduler.js.map +1 -1
  41. package/dist/garbageCollection.d.ts +34 -14
  42. package/dist/garbageCollection.d.ts.map +1 -1
  43. package/dist/garbageCollection.js +188 -93
  44. package/dist/garbageCollection.js.map +1 -1
  45. package/dist/garbageCollectionConstants.d.ts +3 -0
  46. package/dist/garbageCollectionConstants.d.ts.map +1 -1
  47. package/dist/garbageCollectionConstants.js +6 -1
  48. package/dist/garbageCollectionConstants.js.map +1 -1
  49. package/dist/garbageCollectionHelpers.d.ts +26 -0
  50. package/dist/garbageCollectionHelpers.d.ts.map +1 -0
  51. package/dist/garbageCollectionHelpers.js +45 -0
  52. package/dist/garbageCollectionHelpers.js.map +1 -0
  53. package/dist/gcSweepReadyUsageDetection.d.ts +5 -5
  54. package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
  55. package/dist/gcSweepReadyUsageDetection.js +14 -10
  56. package/dist/gcSweepReadyUsageDetection.js.map +1 -1
  57. package/dist/index.d.ts +2 -2
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/opLifecycle/batchManager.d.ts +5 -5
  61. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  62. package/dist/opLifecycle/batchManager.js +19 -12
  63. package/dist/opLifecycle/batchManager.js.map +1 -1
  64. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  65. package/dist/opLifecycle/definitions.js.map +1 -1
  66. package/dist/opLifecycle/index.d.ts.map +1 -1
  67. package/dist/opLifecycle/index.js.map +1 -1
  68. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  69. package/dist/opLifecycle/opCompressor.js.map +1 -1
  70. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  71. package/dist/opLifecycle/opDecompressor.js +5 -2
  72. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  73. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  74. package/dist/opLifecycle/opSplitter.js +4 -1
  75. package/dist/opLifecycle/opSplitter.js.map +1 -1
  76. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  77. package/dist/opLifecycle/outbox.js +19 -17
  78. package/dist/opLifecycle/outbox.js.map +1 -1
  79. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  80. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  81. package/dist/opProperties.d.ts.map +1 -1
  82. package/dist/opProperties.js +1 -3
  83. package/dist/opProperties.js.map +1 -1
  84. package/dist/orderedClientElection.d.ts.map +1 -1
  85. package/dist/orderedClientElection.js +10 -4
  86. package/dist/orderedClientElection.js.map +1 -1
  87. package/dist/packageVersion.d.ts +1 -1
  88. package/dist/packageVersion.js +1 -1
  89. package/dist/packageVersion.js.map +1 -1
  90. package/dist/pendingStateManager.d.ts +7 -0
  91. package/dist/pendingStateManager.d.ts.map +1 -1
  92. package/dist/pendingStateManager.js +7 -4
  93. package/dist/pendingStateManager.js.map +1 -1
  94. package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
  95. package/dist/runWhileConnectedCoordinator.js.map +1 -1
  96. package/dist/runningSummarizer.d.ts.map +1 -1
  97. package/dist/runningSummarizer.js +34 -21
  98. package/dist/runningSummarizer.js.map +1 -1
  99. package/dist/scheduleManager.d.ts.map +1 -1
  100. package/dist/scheduleManager.js +3 -2
  101. package/dist/scheduleManager.js.map +1 -1
  102. package/dist/serializedSnapshotStorage.d.ts +2 -2
  103. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  104. package/dist/serializedSnapshotStorage.js +5 -3
  105. package/dist/serializedSnapshotStorage.js.map +1 -1
  106. package/dist/summarizer.d.ts +2 -2
  107. package/dist/summarizer.d.ts.map +1 -1
  108. package/dist/summarizer.js +37 -17
  109. package/dist/summarizer.js.map +1 -1
  110. package/dist/summarizerClientElection.d.ts.map +1 -1
  111. package/dist/summarizerClientElection.js.map +1 -1
  112. package/dist/summarizerHandle.d.ts.map +1 -1
  113. package/dist/summarizerHandle.js.map +1 -1
  114. package/dist/summarizerHeuristics.d.ts.map +1 -1
  115. package/dist/summarizerHeuristics.js +6 -9
  116. package/dist/summarizerHeuristics.js.map +1 -1
  117. package/dist/summarizerTypes.d.ts +21 -21
  118. package/dist/summarizerTypes.d.ts.map +1 -1
  119. package/dist/summarizerTypes.js.map +1 -1
  120. package/dist/summaryCollection.d.ts.map +1 -1
  121. package/dist/summaryCollection.js +18 -8
  122. package/dist/summaryCollection.js.map +1 -1
  123. package/dist/summaryFormat.d.ts +22 -0
  124. package/dist/summaryFormat.d.ts.map +1 -1
  125. package/dist/summaryFormat.js +18 -10
  126. package/dist/summaryFormat.js.map +1 -1
  127. package/dist/summaryGenerator.d.ts.map +1 -1
  128. package/dist/summaryGenerator.js +34 -15
  129. package/dist/summaryGenerator.js.map +1 -1
  130. package/dist/summaryManager.d.ts.map +1 -1
  131. package/dist/summaryManager.js +21 -9
  132. package/dist/summaryManager.js.map +1 -1
  133. package/dist/throttler.d.ts +2 -2
  134. package/dist/throttler.d.ts.map +1 -1
  135. package/dist/throttler.js +4 -4
  136. package/dist/throttler.js.map +1 -1
  137. package/garbageCollection.md +15 -2
  138. package/lib/batchTracker.d.ts.map +1 -1
  139. package/lib/batchTracker.js +2 -1
  140. package/lib/batchTracker.js.map +1 -1
  141. package/lib/blobManager.d.ts +9 -2
  142. package/lib/blobManager.d.ts.map +1 -1
  143. package/lib/blobManager.js +82 -35
  144. package/lib/blobManager.js.map +1 -1
  145. package/lib/connectionTelemetry.d.ts.map +1 -1
  146. package/lib/connectionTelemetry.js +11 -9
  147. package/lib/connectionTelemetry.js.map +1 -1
  148. package/lib/containerHandleContext.d.ts.map +1 -1
  149. package/lib/containerHandleContext.js +3 -1
  150. package/lib/containerHandleContext.js.map +1 -1
  151. package/lib/containerRuntime.d.ts +10 -0
  152. package/lib/containerRuntime.d.ts.map +1 -1
  153. package/lib/containerRuntime.js +146 -78
  154. package/lib/containerRuntime.js.map +1 -1
  155. package/lib/dataStore.d.ts.map +1 -1
  156. package/lib/dataStore.js +11 -9
  157. package/lib/dataStore.js.map +1 -1
  158. package/lib/dataStoreContext.d.ts +18 -1
  159. package/lib/dataStoreContext.d.ts.map +1 -1
  160. package/lib/dataStoreContext.js +68 -17
  161. package/lib/dataStoreContext.js.map +1 -1
  162. package/lib/dataStoreContexts.d.ts.map +1 -1
  163. package/lib/dataStoreContexts.js +7 -3
  164. package/lib/dataStoreContexts.js.map +1 -1
  165. package/lib/dataStoreRegistry.d.ts.map +1 -1
  166. package/lib/dataStoreRegistry.js +3 -1
  167. package/lib/dataStoreRegistry.js.map +1 -1
  168. package/lib/dataStores.d.ts +26 -1
  169. package/lib/dataStores.d.ts.map +1 -1
  170. package/lib/dataStores.js +109 -24
  171. package/lib/dataStores.js.map +1 -1
  172. package/lib/deltaScheduler.d.ts.map +1 -1
  173. package/lib/deltaScheduler.js +9 -4
  174. package/lib/deltaScheduler.js.map +1 -1
  175. package/lib/garbageCollection.d.ts +34 -14
  176. package/lib/garbageCollection.d.ts.map +1 -1
  177. package/lib/garbageCollection.js +190 -95
  178. package/lib/garbageCollection.js.map +1 -1
  179. package/lib/garbageCollectionConstants.d.ts +3 -0
  180. package/lib/garbageCollectionConstants.d.ts.map +1 -1
  181. package/lib/garbageCollectionConstants.js +5 -0
  182. package/lib/garbageCollectionConstants.js.map +1 -1
  183. package/lib/garbageCollectionHelpers.d.ts +26 -0
  184. package/lib/garbageCollectionHelpers.d.ts.map +1 -0
  185. package/lib/garbageCollectionHelpers.js +40 -0
  186. package/lib/garbageCollectionHelpers.js.map +1 -0
  187. package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
  188. package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
  189. package/lib/gcSweepReadyUsageDetection.js +14 -10
  190. package/lib/gcSweepReadyUsageDetection.js.map +1 -1
  191. package/lib/index.d.ts +2 -2
  192. package/lib/index.d.ts.map +1 -1
  193. package/lib/index.js +1 -1
  194. package/lib/index.js.map +1 -1
  195. package/lib/opLifecycle/batchManager.d.ts +5 -5
  196. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  197. package/lib/opLifecycle/batchManager.js +19 -12
  198. package/lib/opLifecycle/batchManager.js.map +1 -1
  199. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  200. package/lib/opLifecycle/definitions.js.map +1 -1
  201. package/lib/opLifecycle/index.d.ts.map +1 -1
  202. package/lib/opLifecycle/index.js.map +1 -1
  203. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  204. package/lib/opLifecycle/opCompressor.js.map +1 -1
  205. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  206. package/lib/opLifecycle/opDecompressor.js +5 -2
  207. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  208. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  209. package/lib/opLifecycle/opSplitter.js +5 -2
  210. package/lib/opLifecycle/opSplitter.js.map +1 -1
  211. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  212. package/lib/opLifecycle/outbox.js +19 -17
  213. package/lib/opLifecycle/outbox.js.map +1 -1
  214. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  215. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  216. package/lib/opProperties.d.ts.map +1 -1
  217. package/lib/opProperties.js +1 -3
  218. package/lib/opProperties.js.map +1 -1
  219. package/lib/orderedClientElection.d.ts.map +1 -1
  220. package/lib/orderedClientElection.js +10 -4
  221. package/lib/orderedClientElection.js.map +1 -1
  222. package/lib/packageVersion.d.ts +1 -1
  223. package/lib/packageVersion.js +1 -1
  224. package/lib/packageVersion.js.map +1 -1
  225. package/lib/pendingStateManager.d.ts +7 -0
  226. package/lib/pendingStateManager.d.ts.map +1 -1
  227. package/lib/pendingStateManager.js +7 -4
  228. package/lib/pendingStateManager.js.map +1 -1
  229. package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
  230. package/lib/runWhileConnectedCoordinator.js.map +1 -1
  231. package/lib/runningSummarizer.d.ts.map +1 -1
  232. package/lib/runningSummarizer.js +35 -22
  233. package/lib/runningSummarizer.js.map +1 -1
  234. package/lib/scheduleManager.d.ts.map +1 -1
  235. package/lib/scheduleManager.js +3 -2
  236. package/lib/scheduleManager.js.map +1 -1
  237. package/lib/serializedSnapshotStorage.d.ts +2 -2
  238. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  239. package/lib/serializedSnapshotStorage.js +5 -3
  240. package/lib/serializedSnapshotStorage.js.map +1 -1
  241. package/lib/summarizer.d.ts +2 -2
  242. package/lib/summarizer.d.ts.map +1 -1
  243. package/lib/summarizer.js +37 -17
  244. package/lib/summarizer.js.map +1 -1
  245. package/lib/summarizerClientElection.d.ts.map +1 -1
  246. package/lib/summarizerClientElection.js.map +1 -1
  247. package/lib/summarizerHandle.d.ts.map +1 -1
  248. package/lib/summarizerHandle.js.map +1 -1
  249. package/lib/summarizerHeuristics.d.ts.map +1 -1
  250. package/lib/summarizerHeuristics.js +6 -9
  251. package/lib/summarizerHeuristics.js.map +1 -1
  252. package/lib/summarizerTypes.d.ts +21 -21
  253. package/lib/summarizerTypes.d.ts.map +1 -1
  254. package/lib/summarizerTypes.js.map +1 -1
  255. package/lib/summaryCollection.d.ts.map +1 -1
  256. package/lib/summaryCollection.js +18 -8
  257. package/lib/summaryCollection.js.map +1 -1
  258. package/lib/summaryFormat.d.ts +22 -0
  259. package/lib/summaryFormat.d.ts.map +1 -1
  260. package/lib/summaryFormat.js +20 -12
  261. package/lib/summaryFormat.js.map +1 -1
  262. package/lib/summaryGenerator.d.ts.map +1 -1
  263. package/lib/summaryGenerator.js +34 -15
  264. package/lib/summaryGenerator.js.map +1 -1
  265. package/lib/summaryManager.d.ts.map +1 -1
  266. package/lib/summaryManager.js +21 -9
  267. package/lib/summaryManager.js.map +1 -1
  268. package/lib/throttler.d.ts +2 -2
  269. package/lib/throttler.d.ts.map +1 -1
  270. package/lib/throttler.js +4 -4
  271. package/lib/throttler.js.map +1 -1
  272. package/package.json +121 -149
  273. package/prettier.config.cjs +1 -1
  274. package/src/batchTracker.ts +54 -49
  275. package/src/blobManager.ts +793 -672
  276. package/src/connectionTelemetry.ts +280 -249
  277. package/src/containerHandleContext.ts +27 -29
  278. package/src/containerRuntime.ts +3168 -2940
  279. package/src/dataStore.ts +172 -159
  280. package/src/dataStoreContext.ts +1098 -996
  281. package/src/dataStoreContexts.ts +178 -161
  282. package/src/dataStoreRegistry.ts +25 -20
  283. package/src/dataStores.ts +884 -728
  284. package/src/deltaScheduler.ts +158 -150
  285. package/src/garbageCollection.ts +1883 -1692
  286. package/src/garbageCollectionConstants.ts +6 -0
  287. package/src/garbageCollectionHelpers.ts +61 -0
  288. package/src/gcSweepReadyUsageDetection.ts +89 -83
  289. package/src/index.ts +67 -66
  290. package/src/opLifecycle/README.md +152 -0
  291. package/src/opLifecycle/batchManager.ts +145 -141
  292. package/src/opLifecycle/definitions.ts +29 -29
  293. package/src/opLifecycle/index.ts +5 -5
  294. package/src/opLifecycle/opCompressor.ts +54 -53
  295. package/src/opLifecycle/opDecompressor.ts +100 -81
  296. package/src/opLifecycle/opSplitter.ts +214 -188
  297. package/src/opLifecycle/outbox.ts +204 -194
  298. package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
  299. package/src/opProperties.ts +11 -9
  300. package/src/orderedClientElection.ts +489 -457
  301. package/src/packageVersion.ts +1 -1
  302. package/src/pendingStateManager.ts +384 -338
  303. package/src/runWhileConnectedCoordinator.ts +78 -71
  304. package/src/runningSummarizer.ts +619 -581
  305. package/src/scheduleManager.ts +299 -269
  306. package/src/serializedSnapshotStorage.ts +126 -112
  307. package/src/summarizer.ts +417 -381
  308. package/src/summarizerClientElection.ts +107 -100
  309. package/src/summarizerHandle.ts +11 -9
  310. package/src/summarizerHeuristics.ts +183 -186
  311. package/src/summarizerTypes.ts +344 -330
  312. package/src/summaryCollection.ts +378 -349
  313. package/src/summaryFormat.ts +170 -126
  314. package/src/summaryGenerator.ts +465 -406
  315. package/src/summaryManager.ts +377 -348
  316. package/src/throttler.ts +131 -122
  317. package/tsconfig.esnext.json +6 -6
  318. package/tsconfig.json +9 -13
  319. package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
  320. package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  321. package/dist/garbageCollectionTombstoneUtils.js +0 -23
  322. package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
  323. package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
  324. package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  325. package/lib/garbageCollectionTombstoneUtils.js +0 -19
  326. package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
  327. package/src/garbageCollectionTombstoneUtils.ts +0 -28
package/src/dataStore.ts CHANGED
@@ -7,13 +7,12 @@ import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
7
  import { assert, unreachableCase } from "@fluidframework/common-utils";
8
8
  import { AttachState } from "@fluidframework/container-definitions";
9
9
  import { UsageError } from "@fluidframework/container-utils";
10
+ import { FluidObject, IFluidHandle, IRequest, IResponse } from "@fluidframework/core-interfaces";
10
11
  import {
11
- FluidObject,
12
- IFluidHandle,
13
- IRequest,
14
- IResponse,
15
- } from "@fluidframework/core-interfaces";
16
- import { AliasResult, IDataStore, IFluidDataStoreChannel } from "@fluidframework/runtime-definitions";
12
+ AliasResult,
13
+ IDataStore,
14
+ IFluidDataStoreChannel,
15
+ } from "@fluidframework/runtime-definitions";
17
16
  import { TelemetryDataTag } from "@fluidframework/telemetry-utils";
18
17
  import { ContainerRuntime } from "./containerRuntime";
19
18
  import { DataStores } from "./dataStores";
@@ -23,10 +22,10 @@ import { DataStores } from "./dataStores";
23
22
  * alias to a datastore
24
23
  */
25
24
  export interface IDataStoreAliasMessage {
26
- /** The internal id of the datastore */
27
- readonly internalId: string;
28
- /** The alias name to be assigned to the datastore */
29
- readonly alias: string;
25
+ /** The internal id of the datastore */
26
+ readonly internalId: string;
27
+ /** The alias name to be assigned to the datastore */
28
+ readonly alias: string;
30
29
  }
31
30
 
32
31
  /**
@@ -36,163 +35,177 @@ export interface IDataStoreAliasMessage {
36
35
  * @returns True if the {@link IDataStoreAliasMessage} is fully implemented, false otherwise
37
36
  */
38
37
  export const isDataStoreAliasMessage = (
39
- maybeDataStoreAliasMessage: any,
38
+ maybeDataStoreAliasMessage: any,
40
39
  ): maybeDataStoreAliasMessage is IDataStoreAliasMessage => {
41
- return typeof maybeDataStoreAliasMessage?.internalId === "string"
42
- && typeof maybeDataStoreAliasMessage?.alias === "string";
40
+ return (
41
+ typeof maybeDataStoreAliasMessage?.internalId === "string" &&
42
+ typeof maybeDataStoreAliasMessage?.alias === "string"
43
+ );
43
44
  };
44
45
 
45
46
  export const channelToDataStore = (
46
- fluidDataStoreChannel: IFluidDataStoreChannel,
47
- internalId: string,
48
- runtime: ContainerRuntime,
49
- datastores: DataStores,
50
- logger: ITelemetryLogger,
47
+ fluidDataStoreChannel: IFluidDataStoreChannel,
48
+ internalId: string,
49
+ runtime: ContainerRuntime,
50
+ datastores: DataStores,
51
+ logger: ITelemetryLogger,
51
52
  ): IDataStore => new DataStore(fluidDataStoreChannel, internalId, runtime, datastores, logger);
52
53
 
53
54
  enum AliasState {
54
- Aliased = "Aliased",
55
- Aliasing = "Aliasing",
56
- None = "None",
55
+ Aliased = "Aliased",
56
+ Aliasing = "Aliasing",
57
+ None = "None",
57
58
  }
58
59
 
59
60
  class DataStore implements IDataStore {
60
- private aliasState: AliasState = AliasState.None;
61
- private alias: string | undefined;
62
- private readonly pendingAliases: Map<string, Promise<AliasResult>>;
63
- private aliasResult: Promise<AliasResult> | undefined;
64
-
65
- async trySetAlias(alias: string): Promise<AliasResult> {
66
- if (alias.includes("/")) {
67
- throw new UsageError(`The alias cannot contain slashes: '${alias}'`);
68
- }
69
-
70
- switch (this.aliasState) {
71
- // If we're already aliasing, check if it's for the same value and return
72
- // the stored promise, otherwise return 'AlreadyAliased'
73
- case AliasState.Aliasing:
74
- assert(this.aliasResult !== undefined,
75
- 0x316 /* There should be a cached promise of in-progress aliasing */);
76
- await this.aliasResult;
77
- return this.alias === alias ? "Success" : "AlreadyAliased";
78
-
79
- // If this datastore is already aliased, return true only if this
80
- // is a repeated call for the same alias
81
- case AliasState.Aliased:
82
- return this.alias === alias ? "Success" : "AlreadyAliased";
83
-
84
- case AliasState.None: {
85
- const existingAlias = this.pendingAliases.get(alias);
86
- if (existingAlias !== undefined) {
87
- // There is already another datastore which will be aliased
88
- // to the same name
89
- return "Conflict";
90
- }
91
-
92
- // There is no current or past alias operation for this datastore,
93
- // or for this alias, so it is safe to continue execution
94
- break;
95
- }
96
-
97
- default: unreachableCase(this.aliasState);
98
- }
99
-
100
- this.aliasState = AliasState.Aliasing;
101
- this.aliasResult = this.trySetAliasInternal(alias);
102
- this.pendingAliases.set(alias, this.aliasResult);
103
- return this.aliasResult;
104
- }
105
-
106
- async trySetAliasInternal(alias: string): Promise<AliasResult> {
107
- const message: IDataStoreAliasMessage = {
108
- internalId: this.internalId,
109
- alias,
110
- };
111
-
112
- this.fluidDataStoreChannel.makeVisibleAndAttachGraph();
113
-
114
- if (this.runtime.attachState === AttachState.Detached) {
115
- const localResult = this.datastores.processAliasMessageCore(message);
116
- // Explicitly lock-out future attempts of aliasing,
117
- // regardless of result
118
- this.aliasState = AliasState.Aliased;
119
- return localResult ? "Success" : "Conflict";
120
- }
121
-
122
- const aliased = await this
123
- .ackBasedPromise<boolean>((resolve) => {
124
- this.runtime.submitDataStoreAliasOp(message, resolve);
125
- })
126
- .catch((error) => {
127
- this.logger.sendErrorEvent({
128
- eventName: "AliasingException",
129
- alias: {
130
- value: alias,
131
- tag: TelemetryDataTag.UserData,
132
- },
133
- internalId: {
134
- value: this.internalId,
135
- tag: TelemetryDataTag.CodeArtifact,
136
- },
137
- }, error);
138
-
139
- return false;
140
- }).finally(() => {
141
- this.pendingAliases.delete(alias);
142
- });
143
-
144
- if (!aliased) {
145
- this.aliasState = AliasState.None;
146
- this.aliasResult = undefined;
147
- return "Conflict";
148
- }
149
-
150
- this.alias = alias;
151
- this.aliasState = AliasState.Aliased;
152
- return "Success";
153
- }
154
-
155
- async request(request: IRequest): Promise<IResponse> {
156
- return this.fluidDataStoreChannel.request(request);
157
- }
158
-
159
- /**
160
- * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.entryPoint}
161
- */
162
- get entryPoint(): IFluidHandle<FluidObject> | undefined {
163
- return this.fluidDataStoreChannel.entryPoint;
164
- }
165
-
166
- constructor(
167
- private readonly fluidDataStoreChannel: IFluidDataStoreChannel,
168
- private readonly internalId: string,
169
- private readonly runtime: ContainerRuntime,
170
- private readonly datastores: DataStores,
171
- private readonly logger: ITelemetryLogger,
172
- ) {
173
- this.pendingAliases = datastores.pendingAliases;
174
- }
175
-
176
- public get IFluidRouter() { return this.fluidDataStoreChannel; }
177
-
178
- private async ackBasedPromise<T>(
179
- executor: (resolve: (value: T | PromiseLike<T>) => void,
180
- reject: (reason?: any) => void) => void,
181
- ): Promise<T> {
182
- let rejectBecauseDispose: () => void;
183
- return new Promise<T>((resolve, reject) => {
184
- rejectBecauseDispose =
185
- () => reject(new Error("ContainerRuntime disposed while this ack-based Promise was pending"));
186
-
187
- if (this.runtime.disposed) {
188
- rejectBecauseDispose();
189
- return;
190
- }
191
-
192
- this.runtime.on("dispose", rejectBecauseDispose);
193
- executor(resolve, reject);
194
- }).finally(() => {
195
- this.runtime.off("dispose", rejectBecauseDispose);
196
- });
197
- }
61
+ private aliasState: AliasState = AliasState.None;
62
+ private alias: string | undefined;
63
+ private readonly pendingAliases: Map<string, Promise<AliasResult>>;
64
+ private aliasResult: Promise<AliasResult> | undefined;
65
+
66
+ async trySetAlias(alias: string): Promise<AliasResult> {
67
+ if (alias.includes("/")) {
68
+ throw new UsageError(`The alias cannot contain slashes: '${alias}'`);
69
+ }
70
+
71
+ switch (this.aliasState) {
72
+ // If we're already aliasing, check if it's for the same value and return
73
+ // the stored promise, otherwise return 'AlreadyAliased'
74
+ case AliasState.Aliasing:
75
+ assert(
76
+ this.aliasResult !== undefined,
77
+ 0x316 /* There should be a cached promise of in-progress aliasing */,
78
+ );
79
+ await this.aliasResult;
80
+ return this.alias === alias ? "Success" : "AlreadyAliased";
81
+
82
+ // If this datastore is already aliased, return true only if this
83
+ // is a repeated call for the same alias
84
+ case AliasState.Aliased:
85
+ return this.alias === alias ? "Success" : "AlreadyAliased";
86
+
87
+ case AliasState.None: {
88
+ const existingAlias = this.pendingAliases.get(alias);
89
+ if (existingAlias !== undefined) {
90
+ // There is already another datastore which will be aliased
91
+ // to the same name
92
+ return "Conflict";
93
+ }
94
+
95
+ // There is no current or past alias operation for this datastore,
96
+ // or for this alias, so it is safe to continue execution
97
+ break;
98
+ }
99
+
100
+ default:
101
+ unreachableCase(this.aliasState);
102
+ }
103
+
104
+ this.aliasState = AliasState.Aliasing;
105
+ this.aliasResult = this.trySetAliasInternal(alias);
106
+ this.pendingAliases.set(alias, this.aliasResult);
107
+ return this.aliasResult;
108
+ }
109
+
110
+ async trySetAliasInternal(alias: string): Promise<AliasResult> {
111
+ const message: IDataStoreAliasMessage = {
112
+ internalId: this.internalId,
113
+ alias,
114
+ };
115
+
116
+ this.fluidDataStoreChannel.makeVisibleAndAttachGraph();
117
+
118
+ if (this.runtime.attachState === AttachState.Detached) {
119
+ const localResult = this.datastores.processAliasMessageCore(message);
120
+ // Explicitly lock-out future attempts of aliasing,
121
+ // regardless of result
122
+ this.aliasState = AliasState.Aliased;
123
+ return localResult ? "Success" : "Conflict";
124
+ }
125
+
126
+ const aliased = await this.ackBasedPromise<boolean>((resolve) => {
127
+ this.runtime.submitDataStoreAliasOp(message, resolve);
128
+ })
129
+ .catch((error) => {
130
+ this.logger.sendErrorEvent(
131
+ {
132
+ eventName: "AliasingException",
133
+ alias: {
134
+ value: alias,
135
+ tag: TelemetryDataTag.UserData,
136
+ },
137
+ internalId: {
138
+ value: this.internalId,
139
+ tag: TelemetryDataTag.CodeArtifact,
140
+ },
141
+ },
142
+ error,
143
+ );
144
+
145
+ return false;
146
+ })
147
+ .finally(() => {
148
+ this.pendingAliases.delete(alias);
149
+ });
150
+
151
+ if (!aliased) {
152
+ this.aliasState = AliasState.None;
153
+ this.aliasResult = undefined;
154
+ return "Conflict";
155
+ }
156
+
157
+ this.alias = alias;
158
+ this.aliasState = AliasState.Aliased;
159
+ return "Success";
160
+ }
161
+
162
+ async request(request: IRequest): Promise<IResponse> {
163
+ return this.fluidDataStoreChannel.request(request);
164
+ }
165
+
166
+ /**
167
+ * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.entryPoint}
168
+ */
169
+ get entryPoint(): IFluidHandle<FluidObject> | undefined {
170
+ return this.fluidDataStoreChannel.entryPoint;
171
+ }
172
+
173
+ constructor(
174
+ private readonly fluidDataStoreChannel: IFluidDataStoreChannel,
175
+ private readonly internalId: string,
176
+ private readonly runtime: ContainerRuntime,
177
+ private readonly datastores: DataStores,
178
+ private readonly logger: ITelemetryLogger,
179
+ ) {
180
+ this.pendingAliases = datastores.pendingAliases;
181
+ }
182
+
183
+ public get IFluidRouter() {
184
+ return this.fluidDataStoreChannel;
185
+ }
186
+
187
+ private async ackBasedPromise<T>(
188
+ executor: (
189
+ resolve: (value: T | PromiseLike<T>) => void,
190
+ reject: (reason?: any) => void,
191
+ ) => void,
192
+ ): Promise<T> {
193
+ let rejectBecauseDispose: () => void;
194
+ return new Promise<T>((resolve, reject) => {
195
+ rejectBecauseDispose = () =>
196
+ reject(
197
+ new Error("ContainerRuntime disposed while this ack-based Promise was pending"),
198
+ );
199
+
200
+ if (this.runtime.disposed) {
201
+ rejectBecauseDispose();
202
+ return;
203
+ }
204
+
205
+ this.runtime.on("dispose", rejectBecauseDispose);
206
+ executor(resolve, reject);
207
+ }).finally(() => {
208
+ this.runtime.off("dispose", rejectBecauseDispose);
209
+ });
210
+ }
198
211
  }