@fluidframework/container-runtime 2.0.0-dev.5.3.2.178189 → 2.0.0-dev.6.4.0.191457

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 (526) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/README.md +4 -3
  3. package/dist/batchTracker.d.ts +3 -2
  4. package/dist/batchTracker.d.ts.map +1 -1
  5. package/dist/batchTracker.js +6 -5
  6. package/dist/batchTracker.js.map +1 -1
  7. package/dist/blobManager.d.ts +10 -16
  8. package/dist/blobManager.d.ts.map +1 -1
  9. package/dist/blobManager.js +184 -172
  10. package/dist/blobManager.js.map +1 -1
  11. package/dist/connectionTelemetry.d.ts.map +1 -1
  12. package/dist/connectionTelemetry.js +25 -16
  13. package/dist/connectionTelemetry.js.map +1 -1
  14. package/dist/containerRuntime.d.ts +161 -35
  15. package/dist/containerRuntime.d.ts.map +1 -1
  16. package/dist/containerRuntime.js +697 -449
  17. package/dist/containerRuntime.js.map +1 -1
  18. package/dist/dataStore.d.ts.map +1 -1
  19. package/dist/dataStore.js +15 -7
  20. package/dist/dataStore.js.map +1 -1
  21. package/dist/dataStoreContext.d.ts +3 -2
  22. package/dist/dataStoreContext.d.ts.map +1 -1
  23. package/dist/dataStoreContext.js +83 -87
  24. package/dist/dataStoreContext.js.map +1 -1
  25. package/dist/dataStoreContexts.d.ts +1 -2
  26. package/dist/dataStoreContexts.d.ts.map +1 -1
  27. package/dist/dataStoreContexts.js +8 -9
  28. package/dist/dataStoreContexts.js.map +1 -1
  29. package/dist/dataStoreRegistry.js +2 -2
  30. package/dist/dataStoreRegistry.js.map +1 -1
  31. package/dist/dataStores.d.ts +22 -6
  32. package/dist/dataStores.d.ts.map +1 -1
  33. package/dist/dataStores.js +123 -81
  34. package/dist/dataStores.js.map +1 -1
  35. package/dist/deltaManagerProxyBase.d.ts +35 -0
  36. package/dist/deltaManagerProxyBase.d.ts.map +1 -0
  37. package/dist/deltaManagerProxyBase.js +77 -0
  38. package/dist/deltaManagerProxyBase.js.map +1 -0
  39. package/dist/deltaManagerSummarizerProxy.d.ts +1 -1
  40. package/dist/deltaManagerSummarizerProxy.d.ts.map +1 -1
  41. package/dist/deltaManagerSummarizerProxy.js +4 -2
  42. package/dist/deltaManagerSummarizerProxy.js.map +1 -1
  43. package/dist/deltaScheduler.d.ts.map +1 -1
  44. package/dist/deltaScheduler.js +10 -10
  45. package/dist/deltaScheduler.js.map +1 -1
  46. package/dist/error.d.ts +14 -0
  47. package/dist/error.d.ts.map +1 -0
  48. package/dist/error.js +21 -0
  49. package/dist/error.js.map +1 -0
  50. package/dist/gc/garbageCollection.d.ts +10 -9
  51. package/dist/gc/garbageCollection.d.ts.map +1 -1
  52. package/dist/gc/garbageCollection.js +61 -53
  53. package/dist/gc/garbageCollection.js.map +1 -1
  54. package/dist/gc/gcConfigs.d.ts.map +1 -1
  55. package/dist/gc/gcConfigs.js +18 -14
  56. package/dist/gc/gcConfigs.js.map +1 -1
  57. package/dist/gc/gcDefinitions.d.ts +17 -4
  58. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  59. package/dist/gc/gcDefinitions.js +14 -15
  60. package/dist/gc/gcDefinitions.js.map +1 -1
  61. package/dist/gc/gcHelpers.d.ts +0 -8
  62. package/dist/gc/gcHelpers.d.ts.map +1 -1
  63. package/dist/gc/gcHelpers.js +11 -24
  64. package/dist/gc/gcHelpers.js.map +1 -1
  65. package/dist/gc/gcSummaryStateTracker.d.ts +4 -7
  66. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
  67. package/dist/gc/gcSummaryStateTracker.js +19 -58
  68. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  69. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  70. package/dist/gc/gcTelemetry.js +45 -35
  71. package/dist/gc/gcTelemetry.js.map +1 -1
  72. package/dist/gc/gcUnreferencedStateTracker.js +4 -4
  73. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -1
  74. package/dist/gc/index.d.ts +2 -2
  75. package/dist/gc/index.d.ts.map +1 -1
  76. package/dist/gc/index.js +3 -5
  77. package/dist/gc/index.js.map +1 -1
  78. package/dist/id-compressor/appendOnlySortedMap.d.ts +8 -30
  79. package/dist/id-compressor/appendOnlySortedMap.d.ts.map +1 -1
  80. package/dist/id-compressor/appendOnlySortedMap.js +26 -68
  81. package/dist/id-compressor/appendOnlySortedMap.js.map +1 -1
  82. package/dist/id-compressor/finalSpace.d.ts +29 -0
  83. package/dist/id-compressor/finalSpace.d.ts.map +1 -0
  84. package/dist/id-compressor/finalSpace.js +62 -0
  85. package/dist/id-compressor/finalSpace.js.map +1 -0
  86. package/dist/id-compressor/idCompressor.d.ts +25 -250
  87. package/dist/id-compressor/idCompressor.d.ts.map +1 -1
  88. package/dist/id-compressor/idCompressor.js +390 -1153
  89. package/dist/id-compressor/idCompressor.js.map +1 -1
  90. package/dist/id-compressor/identifiers.d.ts +32 -0
  91. package/dist/id-compressor/identifiers.d.ts.map +1 -0
  92. package/dist/id-compressor/identifiers.js +15 -0
  93. package/dist/id-compressor/identifiers.js.map +1 -0
  94. package/dist/id-compressor/index.d.ts +5 -6
  95. package/dist/id-compressor/index.d.ts.map +1 -1
  96. package/dist/id-compressor/index.js +20 -26
  97. package/dist/id-compressor/index.js.map +1 -1
  98. package/dist/id-compressor/persistanceUtilities.d.ts +22 -0
  99. package/dist/id-compressor/persistanceUtilities.d.ts.map +1 -0
  100. package/dist/id-compressor/persistanceUtilities.js +43 -0
  101. package/dist/id-compressor/persistanceUtilities.js.map +1 -0
  102. package/dist/id-compressor/sessionSpaceNormalizer.d.ts +46 -0
  103. package/dist/id-compressor/sessionSpaceNormalizer.d.ts.map +1 -0
  104. package/dist/id-compressor/sessionSpaceNormalizer.js +80 -0
  105. package/dist/id-compressor/sessionSpaceNormalizer.js.map +1 -0
  106. package/dist/id-compressor/sessions.d.ts +115 -0
  107. package/dist/id-compressor/sessions.d.ts.map +1 -0
  108. package/dist/id-compressor/sessions.js +305 -0
  109. package/dist/id-compressor/sessions.js.map +1 -0
  110. package/dist/id-compressor/utilities.d.ts +49 -0
  111. package/dist/id-compressor/utilities.d.ts.map +1 -0
  112. package/dist/id-compressor/utilities.js +166 -0
  113. package/dist/id-compressor/utilities.js.map +1 -0
  114. package/dist/index.d.ts +3 -3
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +6 -4
  117. package/dist/index.js.map +1 -1
  118. package/dist/opLifecycle/batchManager.js +10 -6
  119. package/dist/opLifecycle/batchManager.js.map +1 -1
  120. package/dist/opLifecycle/opCompressor.d.ts +2 -2
  121. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  122. package/dist/opLifecycle/opCompressor.js +12 -7
  123. package/dist/opLifecycle/opCompressor.js.map +1 -1
  124. package/dist/opLifecycle/opDecompressor.d.ts +2 -2
  125. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  126. package/dist/opLifecycle/opDecompressor.js +23 -20
  127. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  128. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  129. package/dist/opLifecycle/opGroupingManager.js +19 -9
  130. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  131. package/dist/opLifecycle/opSplitter.d.ts +2 -2
  132. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  133. package/dist/opLifecycle/opSplitter.js +22 -19
  134. package/dist/opLifecycle/opSplitter.js.map +1 -1
  135. package/dist/opLifecycle/outbox.d.ts +7 -5
  136. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  137. package/dist/opLifecycle/outbox.js +22 -31
  138. package/dist/opLifecycle/outbox.js.map +1 -1
  139. package/dist/opLifecycle/remoteMessageProcessor.d.ts +6 -1
  140. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  141. package/dist/opLifecycle/remoteMessageProcessor.js +19 -7
  142. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  143. package/dist/opProperties.js +1 -2
  144. package/dist/opProperties.js.map +1 -1
  145. package/dist/packageVersion.d.ts +1 -1
  146. package/dist/packageVersion.js +1 -1
  147. package/dist/packageVersion.js.map +1 -1
  148. package/dist/pendingStateManager.d.ts +18 -8
  149. package/dist/pendingStateManager.d.ts.map +1 -1
  150. package/dist/pendingStateManager.js +73 -51
  151. package/dist/pendingStateManager.js.map +1 -1
  152. package/dist/scheduleManager.d.ts.map +1 -1
  153. package/dist/scheduleManager.js +36 -32
  154. package/dist/scheduleManager.js.map +1 -1
  155. package/dist/summary/index.d.ts +3 -3
  156. package/dist/summary/index.d.ts.map +1 -1
  157. package/dist/summary/index.js +2 -1
  158. package/dist/summary/index.js.map +1 -1
  159. package/dist/summary/orderedClientElection.d.ts +3 -3
  160. package/dist/summary/orderedClientElection.d.ts.map +1 -1
  161. package/dist/summary/orderedClientElection.js +26 -27
  162. package/dist/summary/orderedClientElection.js.map +1 -1
  163. package/dist/summary/runWhileConnectedCoordinator.js +3 -3
  164. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
  165. package/dist/summary/runningSummarizer.d.ts +31 -10
  166. package/dist/summary/runningSummarizer.d.ts.map +1 -1
  167. package/dist/summary/runningSummarizer.js +271 -139
  168. package/dist/summary/runningSummarizer.js.map +1 -1
  169. package/dist/summary/summarizer.d.ts +8 -7
  170. package/dist/summary/summarizer.d.ts.map +1 -1
  171. package/dist/summary/summarizer.js +79 -78
  172. package/dist/summary/summarizer.js.map +1 -1
  173. package/dist/summary/summarizerClientElection.d.ts +2 -2
  174. package/dist/summary/summarizerClientElection.d.ts.map +1 -1
  175. package/dist/summary/summarizerClientElection.js +7 -11
  176. package/dist/summary/summarizerClientElection.js.map +1 -1
  177. package/dist/summary/summarizerHeuristics.js +10 -14
  178. package/dist/summary/summarizerHeuristics.js.map +1 -1
  179. package/dist/summary/summarizerNode/index.d.ts +1 -1
  180. package/dist/summary/summarizerNode/index.d.ts.map +1 -1
  181. package/dist/summary/summarizerNode/index.js.map +1 -1
  182. package/dist/summary/summarizerNode/summarizerNode.d.ts +10 -19
  183. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  184. package/dist/summary/summarizerNode/summarizerNode.js +57 -130
  185. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  186. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +6 -30
  187. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  188. package/dist/summary/summarizerNode/summarizerNodeUtils.js +2 -4
  189. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  190. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +4 -14
  191. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  192. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +15 -101
  193. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  194. package/dist/summary/summarizerTypes.d.ts +38 -25
  195. package/dist/summary/summarizerTypes.d.ts.map +1 -1
  196. package/dist/summary/summarizerTypes.js.map +1 -1
  197. package/dist/summary/summaryCollection.d.ts +2 -3
  198. package/dist/summary/summaryCollection.d.ts.map +1 -1
  199. package/dist/summary/summaryCollection.js +12 -13
  200. package/dist/summary/summaryCollection.js.map +1 -1
  201. package/dist/summary/summaryFormat.d.ts +3 -0
  202. package/dist/summary/summaryFormat.d.ts.map +1 -1
  203. package/dist/summary/summaryFormat.js +6 -4
  204. package/dist/summary/summaryFormat.js.map +1 -1
  205. package/dist/summary/summaryGenerator.d.ts +10 -4
  206. package/dist/summary/summaryGenerator.d.ts.map +1 -1
  207. package/dist/summary/summaryGenerator.js +106 -57
  208. package/dist/summary/summaryGenerator.js.map +1 -1
  209. package/dist/summary/summaryManager.d.ts +8 -8
  210. package/dist/summary/summaryManager.d.ts.map +1 -1
  211. package/dist/summary/summaryManager.js +38 -28
  212. package/dist/summary/summaryManager.js.map +1 -1
  213. package/lib/batchTracker.d.ts +3 -2
  214. package/lib/batchTracker.d.ts.map +1 -1
  215. package/lib/batchTracker.js +5 -4
  216. package/lib/batchTracker.js.map +1 -1
  217. package/lib/blobManager.d.ts +10 -16
  218. package/lib/blobManager.d.ts.map +1 -1
  219. package/lib/blobManager.js +159 -147
  220. package/lib/blobManager.js.map +1 -1
  221. package/lib/connectionTelemetry.d.ts.map +1 -1
  222. package/lib/connectionTelemetry.js +15 -6
  223. package/lib/connectionTelemetry.js.map +1 -1
  224. package/lib/containerRuntime.d.ts +161 -35
  225. package/lib/containerRuntime.d.ts.map +1 -1
  226. package/lib/containerRuntime.js +651 -402
  227. package/lib/containerRuntime.js.map +1 -1
  228. package/lib/dataStore.d.ts.map +1 -1
  229. package/lib/dataStore.js +13 -5
  230. package/lib/dataStore.js.map +1 -1
  231. package/lib/dataStoreContext.d.ts +3 -2
  232. package/lib/dataStoreContext.d.ts.map +1 -1
  233. package/lib/dataStoreContext.js +47 -51
  234. package/lib/dataStoreContext.js.map +1 -1
  235. package/lib/dataStoreContexts.d.ts +1 -2
  236. package/lib/dataStoreContexts.d.ts.map +1 -1
  237. package/lib/dataStoreContexts.js +3 -4
  238. package/lib/dataStoreContexts.js.map +1 -1
  239. package/lib/dataStoreRegistry.js +1 -1
  240. package/lib/dataStoreRegistry.js.map +1 -1
  241. package/lib/dataStores.d.ts +22 -6
  242. package/lib/dataStores.d.ts.map +1 -1
  243. package/lib/dataStores.js +107 -65
  244. package/lib/dataStores.js.map +1 -1
  245. package/lib/deltaManagerProxyBase.d.ts +35 -0
  246. package/lib/deltaManagerProxyBase.d.ts.map +1 -0
  247. package/lib/deltaManagerProxyBase.js +73 -0
  248. package/lib/deltaManagerProxyBase.js.map +1 -0
  249. package/lib/deltaManagerSummarizerProxy.d.ts +1 -1
  250. package/lib/deltaManagerSummarizerProxy.d.ts.map +1 -1
  251. package/lib/deltaManagerSummarizerProxy.js +3 -1
  252. package/lib/deltaManagerSummarizerProxy.js.map +1 -1
  253. package/lib/deltaScheduler.d.ts.map +1 -1
  254. package/lib/deltaScheduler.js +7 -7
  255. package/lib/deltaScheduler.js.map +1 -1
  256. package/lib/error.d.ts +14 -0
  257. package/lib/error.d.ts.map +1 -0
  258. package/lib/error.js +17 -0
  259. package/lib/error.js.map +1 -0
  260. package/lib/gc/garbageCollection.d.ts +10 -9
  261. package/lib/gc/garbageCollection.d.ts.map +1 -1
  262. package/lib/gc/garbageCollection.js +61 -53
  263. package/lib/gc/garbageCollection.js.map +1 -1
  264. package/lib/gc/gcConfigs.d.ts.map +1 -1
  265. package/lib/gc/gcConfigs.js +16 -12
  266. package/lib/gc/gcConfigs.js.map +1 -1
  267. package/lib/gc/gcDefinitions.d.ts +17 -4
  268. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  269. package/lib/gc/gcDefinitions.js +13 -14
  270. package/lib/gc/gcDefinitions.js.map +1 -1
  271. package/lib/gc/gcHelpers.d.ts +0 -8
  272. package/lib/gc/gcHelpers.d.ts.map +1 -1
  273. package/lib/gc/gcHelpers.js +5 -17
  274. package/lib/gc/gcHelpers.js.map +1 -1
  275. package/lib/gc/gcSummaryStateTracker.d.ts +4 -7
  276. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
  277. package/lib/gc/gcSummaryStateTracker.js +20 -59
  278. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  279. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  280. package/lib/gc/gcTelemetry.js +46 -36
  281. package/lib/gc/gcTelemetry.js.map +1 -1
  282. package/lib/gc/gcUnreferencedStateTracker.js +1 -1
  283. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -1
  284. package/lib/gc/index.d.ts +2 -2
  285. package/lib/gc/index.d.ts.map +1 -1
  286. package/lib/gc/index.js +2 -2
  287. package/lib/gc/index.js.map +1 -1
  288. package/lib/id-compressor/appendOnlySortedMap.d.ts +8 -30
  289. package/lib/id-compressor/appendOnlySortedMap.d.ts.map +1 -1
  290. package/lib/id-compressor/appendOnlySortedMap.js +25 -66
  291. package/lib/id-compressor/appendOnlySortedMap.js.map +1 -1
  292. package/lib/id-compressor/finalSpace.d.ts +29 -0
  293. package/lib/id-compressor/finalSpace.d.ts.map +1 -0
  294. package/lib/id-compressor/finalSpace.js +58 -0
  295. package/lib/id-compressor/finalSpace.js.map +1 -0
  296. package/lib/id-compressor/idCompressor.d.ts +25 -250
  297. package/lib/id-compressor/idCompressor.d.ts.map +1 -1
  298. package/lib/id-compressor/idCompressor.js +385 -1142
  299. package/lib/id-compressor/idCompressor.js.map +1 -1
  300. package/lib/id-compressor/identifiers.d.ts +32 -0
  301. package/lib/id-compressor/identifiers.d.ts.map +1 -0
  302. package/lib/id-compressor/identifiers.js +11 -0
  303. package/lib/id-compressor/identifiers.js.map +1 -0
  304. package/lib/id-compressor/index.d.ts +5 -6
  305. package/lib/id-compressor/index.d.ts.map +1 -1
  306. package/lib/id-compressor/index.js +5 -6
  307. package/lib/id-compressor/index.js.map +1 -1
  308. package/lib/id-compressor/persistanceUtilities.d.ts +22 -0
  309. package/lib/id-compressor/persistanceUtilities.d.ts.map +1 -0
  310. package/lib/id-compressor/persistanceUtilities.js +34 -0
  311. package/lib/id-compressor/persistanceUtilities.js.map +1 -0
  312. package/lib/id-compressor/sessionSpaceNormalizer.d.ts +46 -0
  313. package/lib/id-compressor/sessionSpaceNormalizer.d.ts.map +1 -0
  314. package/lib/id-compressor/sessionSpaceNormalizer.js +76 -0
  315. package/lib/id-compressor/sessionSpaceNormalizer.js.map +1 -0
  316. package/lib/id-compressor/sessions.d.ts +115 -0
  317. package/lib/id-compressor/sessions.d.ts.map +1 -0
  318. package/lib/id-compressor/sessions.js +290 -0
  319. package/lib/id-compressor/sessions.js.map +1 -0
  320. package/lib/id-compressor/utilities.d.ts +49 -0
  321. package/lib/id-compressor/utilities.d.ts.map +1 -0
  322. package/lib/id-compressor/utilities.js +148 -0
  323. package/lib/id-compressor/utilities.js.map +1 -0
  324. package/lib/index.d.ts +3 -3
  325. package/lib/index.d.ts.map +1 -1
  326. package/lib/index.js +2 -2
  327. package/lib/index.js.map +1 -1
  328. package/lib/opLifecycle/batchManager.js +10 -6
  329. package/lib/opLifecycle/batchManager.js.map +1 -1
  330. package/lib/opLifecycle/opCompressor.d.ts +2 -2
  331. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  332. package/lib/opLifecycle/opCompressor.js +10 -5
  333. package/lib/opLifecycle/opCompressor.js.map +1 -1
  334. package/lib/opLifecycle/opDecompressor.d.ts +2 -2
  335. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  336. package/lib/opLifecycle/opDecompressor.js +15 -12
  337. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  338. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  339. package/lib/opLifecycle/opGroupingManager.js +17 -7
  340. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  341. package/lib/opLifecycle/opSplitter.d.ts +2 -2
  342. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  343. package/lib/opLifecycle/opSplitter.js +13 -10
  344. package/lib/opLifecycle/opSplitter.js.map +1 -1
  345. package/lib/opLifecycle/outbox.d.ts +7 -5
  346. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  347. package/lib/opLifecycle/outbox.js +13 -22
  348. package/lib/opLifecycle/outbox.js.map +1 -1
  349. package/lib/opLifecycle/remoteMessageProcessor.d.ts +6 -1
  350. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  351. package/lib/opLifecycle/remoteMessageProcessor.js +20 -8
  352. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  353. package/lib/opProperties.js +1 -2
  354. package/lib/opProperties.js.map +1 -1
  355. package/lib/packageVersion.d.ts +1 -1
  356. package/lib/packageVersion.js +1 -1
  357. package/lib/packageVersion.js.map +1 -1
  358. package/lib/pendingStateManager.d.ts +18 -8
  359. package/lib/pendingStateManager.d.ts.map +1 -1
  360. package/lib/pendingStateManager.js +62 -40
  361. package/lib/pendingStateManager.js.map +1 -1
  362. package/lib/scheduleManager.d.ts.map +1 -1
  363. package/lib/scheduleManager.js +18 -14
  364. package/lib/scheduleManager.js.map +1 -1
  365. package/lib/summary/index.d.ts +3 -3
  366. package/lib/summary/index.d.ts.map +1 -1
  367. package/lib/summary/index.js +1 -1
  368. package/lib/summary/index.js.map +1 -1
  369. package/lib/summary/orderedClientElection.d.ts +3 -3
  370. package/lib/summary/orderedClientElection.d.ts.map +1 -1
  371. package/lib/summary/orderedClientElection.js +21 -22
  372. package/lib/summary/orderedClientElection.js.map +1 -1
  373. package/lib/summary/runWhileConnectedCoordinator.js +1 -1
  374. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
  375. package/lib/summary/runningSummarizer.d.ts +31 -10
  376. package/lib/summary/runningSummarizer.d.ts.map +1 -1
  377. package/lib/summary/runningSummarizer.js +265 -133
  378. package/lib/summary/runningSummarizer.js.map +1 -1
  379. package/lib/summary/summarizer.d.ts +8 -7
  380. package/lib/summary/summarizer.d.ts.map +1 -1
  381. package/lib/summary/summarizer.js +75 -74
  382. package/lib/summary/summarizer.js.map +1 -1
  383. package/lib/summary/summarizerClientElection.d.ts +2 -2
  384. package/lib/summary/summarizerClientElection.d.ts.map +1 -1
  385. package/lib/summary/summarizerClientElection.js +6 -10
  386. package/lib/summary/summarizerClientElection.js.map +1 -1
  387. package/lib/summary/summarizerHeuristics.js +9 -13
  388. package/lib/summary/summarizerHeuristics.js.map +1 -1
  389. package/lib/summary/summarizerNode/index.d.ts +1 -1
  390. package/lib/summary/summarizerNode/index.d.ts.map +1 -1
  391. package/lib/summary/summarizerNode/index.js.map +1 -1
  392. package/lib/summary/summarizerNode/summarizerNode.d.ts +10 -19
  393. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  394. package/lib/summary/summarizerNode/summarizerNode.js +42 -115
  395. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  396. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +6 -30
  397. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  398. package/lib/summary/summarizerNode/summarizerNodeUtils.js +2 -4
  399. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  400. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +4 -14
  401. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  402. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +14 -100
  403. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  404. package/lib/summary/summarizerTypes.d.ts +38 -25
  405. package/lib/summary/summarizerTypes.d.ts.map +1 -1
  406. package/lib/summary/summarizerTypes.js.map +1 -1
  407. package/lib/summary/summaryCollection.d.ts +2 -3
  408. package/lib/summary/summaryCollection.d.ts.map +1 -1
  409. package/lib/summary/summaryCollection.js +5 -6
  410. package/lib/summary/summaryCollection.js.map +1 -1
  411. package/lib/summary/summaryFormat.d.ts +3 -0
  412. package/lib/summary/summaryFormat.d.ts.map +1 -1
  413. package/lib/summary/summaryFormat.js +5 -3
  414. package/lib/summary/summaryFormat.js.map +1 -1
  415. package/lib/summary/summaryGenerator.d.ts +10 -4
  416. package/lib/summary/summaryGenerator.d.ts.map +1 -1
  417. package/lib/summary/summaryGenerator.js +100 -51
  418. package/lib/summary/summaryGenerator.js.map +1 -1
  419. package/lib/summary/summaryManager.d.ts +8 -8
  420. package/lib/summary/summaryManager.d.ts.map +1 -1
  421. package/lib/summary/summaryManager.js +35 -25
  422. package/lib/summary/summaryManager.js.map +1 -1
  423. package/package.json +28 -31
  424. package/src/batchTracker.ts +7 -5
  425. package/src/blobManager.ts +188 -166
  426. package/src/connectionTelemetry.ts +9 -4
  427. package/src/containerRuntime.ts +806 -441
  428. package/src/dataStore.ts +12 -4
  429. package/src/dataStoreContext.ts +39 -43
  430. package/src/dataStoreContexts.ts +4 -6
  431. package/src/dataStoreRegistry.ts +1 -1
  432. package/src/dataStores.ts +114 -80
  433. package/src/deltaManagerProxyBase.ts +111 -0
  434. package/src/deltaManagerSummarizerProxy.ts +4 -1
  435. package/src/deltaScheduler.ts +7 -11
  436. package/src/error.ts +18 -0
  437. package/src/gc/garbageCollection.md +53 -5
  438. package/src/gc/garbageCollection.ts +58 -52
  439. package/src/gc/gcConfigs.ts +4 -2
  440. package/src/gc/gcDefinitions.ts +17 -20
  441. package/src/gc/gcEarlyAdoption.md +145 -0
  442. package/src/gc/gcHelpers.ts +1 -12
  443. package/src/gc/gcSummaryStateTracker.ts +19 -65
  444. package/src/gc/gcTelemetry.ts +14 -12
  445. package/src/gc/gcUnreferencedStateTracker.ts +1 -1
  446. package/src/gc/index.ts +2 -4
  447. package/src/id-compressor/appendOnlySortedMap.ts +26 -87
  448. package/src/id-compressor/finalSpace.ts +67 -0
  449. package/src/id-compressor/idCompressor.ts +458 -1682
  450. package/src/id-compressor/identifiers.ts +42 -0
  451. package/src/id-compressor/index.ts +11 -20
  452. package/src/id-compressor/persistanceUtilities.ts +58 -0
  453. package/src/id-compressor/sessionSpaceNormalizer.ts +83 -0
  454. package/src/id-compressor/sessions.ts +405 -0
  455. package/src/id-compressor/utilities.ts +187 -0
  456. package/src/index.ts +7 -2
  457. package/src/opLifecycle/opCompressor.ts +6 -5
  458. package/src/opLifecycle/opDecompressor.ts +6 -4
  459. package/src/opLifecycle/opGroupingManager.ts +9 -6
  460. package/src/opLifecycle/opSplitter.ts +7 -6
  461. package/src/opLifecycle/outbox.ts +23 -32
  462. package/src/opLifecycle/remoteMessageProcessor.ts +27 -8
  463. package/src/packageVersion.ts +1 -1
  464. package/src/pendingStateManager.ts +72 -42
  465. package/src/scheduleManager.ts +7 -5
  466. package/src/summary/index.ts +4 -3
  467. package/src/summary/orderedClientElection.ts +10 -6
  468. package/src/summary/runWhileConnectedCoordinator.ts +1 -1
  469. package/src/summary/runningSummarizer.ts +291 -163
  470. package/src/summary/summarizer.ts +27 -16
  471. package/src/summary/summarizerClientElection.ts +2 -2
  472. package/src/summary/summarizerHeuristics.ts +1 -1
  473. package/src/summary/summarizerNode/index.ts +1 -2
  474. package/src/summary/summarizerNode/summarizerNode.ts +36 -160
  475. package/src/summary/summarizerNode/summarizerNodeUtils.ts +7 -38
  476. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +11 -130
  477. package/src/summary/summarizerTypes.ts +40 -25
  478. package/src/summary/summaryCollection.ts +3 -3
  479. package/src/summary/summaryFormat.ts +4 -1
  480. package/src/summary/summaryGenerator.ts +52 -52
  481. package/src/summary/summaryManager.ts +44 -17
  482. package/dist/id-compressor/idRange.d.ts +0 -11
  483. package/dist/id-compressor/idRange.d.ts.map +0 -1
  484. package/dist/id-compressor/idRange.js +0 -29
  485. package/dist/id-compressor/idRange.js.map +0 -1
  486. package/dist/id-compressor/numericUuid.d.ts +0 -59
  487. package/dist/id-compressor/numericUuid.d.ts.map +0 -1
  488. package/dist/id-compressor/numericUuid.js +0 -325
  489. package/dist/id-compressor/numericUuid.js.map +0 -1
  490. package/dist/id-compressor/sessionIdNormalizer.d.ts +0 -138
  491. package/dist/id-compressor/sessionIdNormalizer.d.ts.map +0 -1
  492. package/dist/id-compressor/sessionIdNormalizer.js +0 -488
  493. package/dist/id-compressor/sessionIdNormalizer.js.map +0 -1
  494. package/dist/id-compressor/utils.d.ts +0 -57
  495. package/dist/id-compressor/utils.d.ts.map +0 -1
  496. package/dist/id-compressor/utils.js +0 -90
  497. package/dist/id-compressor/utils.js.map +0 -1
  498. package/dist/id-compressor/uuidUtilities.d.ts +0 -28
  499. package/dist/id-compressor/uuidUtilities.d.ts.map +0 -1
  500. package/dist/id-compressor/uuidUtilities.js +0 -104
  501. package/dist/id-compressor/uuidUtilities.js.map +0 -1
  502. package/lib/id-compressor/idRange.d.ts +0 -11
  503. package/lib/id-compressor/idRange.d.ts.map +0 -1
  504. package/lib/id-compressor/idRange.js +0 -25
  505. package/lib/id-compressor/idRange.js.map +0 -1
  506. package/lib/id-compressor/numericUuid.d.ts +0 -59
  507. package/lib/id-compressor/numericUuid.d.ts.map +0 -1
  508. package/lib/id-compressor/numericUuid.js +0 -315
  509. package/lib/id-compressor/numericUuid.js.map +0 -1
  510. package/lib/id-compressor/sessionIdNormalizer.d.ts +0 -138
  511. package/lib/id-compressor/sessionIdNormalizer.d.ts.map +0 -1
  512. package/lib/id-compressor/sessionIdNormalizer.js +0 -484
  513. package/lib/id-compressor/sessionIdNormalizer.js.map +0 -1
  514. package/lib/id-compressor/utils.d.ts +0 -57
  515. package/lib/id-compressor/utils.d.ts.map +0 -1
  516. package/lib/id-compressor/utils.js +0 -79
  517. package/lib/id-compressor/utils.js.map +0 -1
  518. package/lib/id-compressor/uuidUtilities.d.ts +0 -28
  519. package/lib/id-compressor/uuidUtilities.d.ts.map +0 -1
  520. package/lib/id-compressor/uuidUtilities.js +0 -96
  521. package/lib/id-compressor/uuidUtilities.js.map +0 -1
  522. package/src/id-compressor/idRange.ts +0 -35
  523. package/src/id-compressor/numericUuid.ts +0 -383
  524. package/src/id-compressor/sessionIdNormalizer.ts +0 -609
  525. package/src/id-compressor/utils.ts +0 -114
  526. package/src/id-compressor/uuidUtilities.ts +0 -120
@@ -3,18 +3,32 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
7
- import { IDisposable } from "@fluidframework/core-interfaces";
8
- import { assert } from "@fluidframework/common-utils";
9
6
  import {
10
- ChildLogger,
7
+ IDisposable,
8
+ IEvent,
9
+ IEventProvider,
10
+ ITelemetryBaseLogger,
11
+ } from "@fluidframework/core-interfaces";
12
+ import { assert } from "@fluidframework/core-utils";
13
+ import { TypedEventEmitter } from "@fluid-internal/client-utils";
14
+ import {
15
+ createChildLogger,
11
16
  ITelemetryLoggerExt,
12
17
  PerformanceEvent,
13
18
  } from "@fluidframework/telemetry-utils";
14
- import { DriverErrorType } from "@fluidframework/driver-definitions";
19
+ import { DriverErrorTypes } from "@fluidframework/driver-definitions";
15
20
  import { IThrottler } from "../throttler";
16
21
  import { ISummarizerClientElection } from "./summarizerClientElection";
17
- import { ISummarizer, SummarizerStopReason } from "./summarizerTypes";
22
+ import {
23
+ EnqueueSummarizeResult,
24
+ IEnqueueSummarizeOptions,
25
+ IOnDemandSummarizeOptions,
26
+ ISummarizeEventProps,
27
+ ISummarizeResults,
28
+ ISummarizer,
29
+ ISummarizerEvents,
30
+ SummarizerStopReason,
31
+ } from "./summarizerTypes";
18
32
  import { SummaryCollection } from "./summaryCollection";
19
33
  import { Summarizer } from "./summarizer";
20
34
 
@@ -73,7 +87,7 @@ export interface ISummaryManagerConfig {
73
87
  * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or
74
88
  * stopping existing summarizer client.
75
89
  */
76
- export class SummaryManager implements IDisposable {
90
+ export class SummaryManager extends TypedEventEmitter<ISummarizerEvents> implements IDisposable {
77
91
  private readonly logger: ITelemetryLoggerExt;
78
92
  private readonly opsToBypassInitialDelay: number;
79
93
  private readonly initialDelayMs: number;
@@ -97,7 +111,7 @@ export class SummaryManager implements IDisposable {
97
111
  SummaryCollection,
98
112
  "opsSinceLastAck" | "addOpListener" | "removeOpListener"
99
113
  >,
100
- parentLogger: ITelemetryLoggerExt,
114
+ parentLogger: ITelemetryBaseLogger,
101
115
  /** Creates summarizer by asking interactive container to spawn summarizing container and
102
116
  * get back its Summarizer instance. */
103
117
  private readonly requestSummarizerFn: () => Promise<ISummarizer>,
@@ -108,8 +122,14 @@ export class SummaryManager implements IDisposable {
108
122
  }: Readonly<Partial<ISummaryManagerConfig>> = {},
109
123
  private readonly disableHeuristics?: boolean,
110
124
  ) {
111
- this.logger = ChildLogger.create(parentLogger, "SummaryManager", {
112
- all: { clientId: () => this.latestClientId },
125
+ super();
126
+
127
+ this.logger = createChildLogger({
128
+ logger: parentLogger,
129
+ namespace: "SummaryManager",
130
+ properties: {
131
+ all: { clientId: () => this.latestClientId },
132
+ },
113
133
  });
114
134
 
115
135
  this.connectedState.on("connected", this.handleConnected);
@@ -141,6 +161,10 @@ export class SummaryManager implements IDisposable {
141
161
  this.refreshSummarizer();
142
162
  };
143
163
 
164
+ private readonly handleSummarizeEvent = (eventProps: ISummarizeEventProps) => {
165
+ this.emit("summarize", eventProps);
166
+ };
167
+
144
168
  private static readonly isStartingOrRunning = (state: SummaryManagerState) =>
145
169
  state === SummaryManagerState.Starting || state === SummaryManagerState.Running;
146
170
 
@@ -242,6 +266,7 @@ export class SummaryManager implements IDisposable {
242
266
 
243
267
  const summarizer = await this.requestSummarizerFn();
244
268
  this.summarizer = summarizer;
269
+ this.summarizer.on("summarize", this.handleSummarizeEvent);
245
270
 
246
271
  // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore
247
272
  // If we can't run the LastSummary, simply return as to avoid paying the cost of launching
@@ -304,7 +329,7 @@ export class SummaryManager implements IDisposable {
304
329
  // If failure happened on container load, we may not yet realized that socket disconnected, so check
305
330
  // offlineError.
306
331
  const category =
307
- error?.errorType === DriverErrorType.offlineError ? "generic" : "error";
332
+ error?.errorType === DriverErrorTypes.offlineError ? "generic" : "error";
308
333
  this.logger.sendTelemetryEvent(
309
334
  {
310
335
  eventName: "SummarizerException",
@@ -318,6 +343,7 @@ export class SummaryManager implements IDisposable {
318
343
  assert(this.state !== SummaryManagerState.Off, 0x264 /* "Expected: Not Off" */);
319
344
  this.state = SummaryManagerState.Off;
320
345
 
346
+ this.summarizer?.off("summarize", this.handleSummarizeEvent);
321
347
  this.summarizer?.close();
322
348
  this.summarizer = undefined;
323
349
 
@@ -400,26 +426,27 @@ export class SummaryManager implements IDisposable {
400
426
  return startWithInitialDelay;
401
427
  }
402
428
 
403
- public readonly summarizeOnDemand: ISummarizer["summarizeOnDemand"] = (...args) => {
429
+ public summarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults {
404
430
  if (this.summarizer === undefined) {
405
431
  throw Error("No running summarizer client");
406
432
  // TODO: could spawn a summarizer client temporarily.
407
433
  }
408
- return this.summarizer.summarizeOnDemand(...args);
409
- };
434
+ return this.summarizer.summarizeOnDemand(options);
435
+ }
410
436
 
411
- public readonly enqueueSummarize: ISummarizer["enqueueSummarize"] = (...args) => {
437
+ public enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {
412
438
  if (this.summarizer === undefined) {
413
439
  throw Error("No running summarizer client");
414
440
  // TODO: could spawn a summarizer client temporarily.
415
441
  }
416
- return this.summarizer.enqueueSummarize(...args);
417
- };
442
+ return this.summarizer.enqueueSummarize(options);
443
+ }
418
444
 
419
445
  public dispose() {
420
446
  this.clientElection.off("electedSummarizerChanged", this.refreshSummarizer);
421
447
  this.connectedState.off("connected", this.handleConnected);
422
448
  this.connectedState.off("disconnected", this.handleDisconnected);
449
+ this.summarizer?.off("summarize", this.handleSummarizeEvent);
423
450
  this._disposed = true;
424
451
  }
425
452
  }
@@ -1,11 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import type { IdCreationRange, UnackedLocalId } from "@fluidframework/runtime-definitions";
6
- export declare function getIds(range: IdCreationRange): {
7
- first: UnackedLocalId;
8
- last: UnackedLocalId;
9
- overrides?: IdCreationRange.Overrides;
10
- } | undefined;
11
- //# sourceMappingURL=idRange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idRange.d.ts","sourceRoot":"","sources":["../../src/id-compressor/idRange.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAE3F,wBAAgB,MAAM,CACrB,KAAK,EAAE,eAAe,GAEpB;IAAE,KAAK,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,cAAc,CAAC;IAAC,SAAS,CAAC,EAAE,eAAe,CAAC,SAAS,CAAA;CAAE,GACtF,SAAS,CAsBX"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.getIds = void 0;
8
- const common_utils_1 = require("@fluidframework/common-utils");
9
- function getIds(range) {
10
- const { ids } = range;
11
- if (ids === undefined) {
12
- return undefined;
13
- }
14
- let first = ids.first;
15
- let last = ids.last;
16
- const overrides = ids;
17
- if (overrides.overrides !== undefined) {
18
- first !== null && first !== void 0 ? first : (first = overrides.overrides[0][0]);
19
- last !== null && last !== void 0 ? last : (last = overrides.overrides[overrides.overrides.length - 1][0]);
20
- }
21
- (0, common_utils_1.assert)(first !== undefined && last !== undefined, 0x49b /* malformed IdCreationRange */);
22
- return {
23
- first,
24
- last,
25
- overrides: overrides.overrides,
26
- };
27
- }
28
- exports.getIds = getIds;
29
- //# sourceMappingURL=idRange.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idRange.js","sourceRoot":"","sources":["../../src/id-compressor/idRange.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAGtD,SAAgB,MAAM,CACrB,KAAsB;IAItB,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IACtB,IAAI,GAAG,KAAK,SAAS,EAAE;QACtB,OAAO,SAAS,CAAC;KACjB;IAED,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IACtB,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAEpB,MAAM,SAAS,GAAG,GAA4C,CAAC;IAC/D,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE;QACtC,KAAK,aAAL,KAAK,cAAL,KAAK,IAAL,KAAK,GAAK,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;QACpC,IAAI,aAAJ,IAAI,cAAJ,IAAI,IAAJ,IAAI,GAAK,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;KAChE;IAED,IAAA,qBAAM,EAAC,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEzF,OAAO;QACN,KAAK;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,CAAC,SAAS;KAC9B,CAAC;AACH,CAAC;AA1BD,wBA0BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport type { IdCreationRange, UnackedLocalId } from \"@fluidframework/runtime-definitions\";\n\nexport function getIds(\n\trange: IdCreationRange,\n):\n\t| { first: UnackedLocalId; last: UnackedLocalId; overrides?: IdCreationRange.Overrides }\n\t| undefined {\n\tconst { ids } = range;\n\tif (ids === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet first = ids.first;\n\tlet last = ids.last;\n\n\tconst overrides = ids as Partial<IdCreationRange.HasOverrides>;\n\tif (overrides.overrides !== undefined) {\n\t\tfirst ??= overrides.overrides[0][0];\n\t\tlast ??= overrides.overrides[overrides.overrides.length - 1][0];\n\t}\n\n\tassert(first !== undefined && last !== undefined, 0x49b /* malformed IdCreationRange */);\n\n\treturn {\n\t\tfirst,\n\t\tlast,\n\t\toverrides: overrides.overrides,\n\t};\n}\n"]}
@@ -1,59 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { SessionId, StableId } from "@fluidframework/runtime-definitions";
6
- /**
7
- * A UUID (128 bit identifier) optimized for use as a 128 bit unsigned integer with fast addition and toString operations.
8
- * The string entry is the upper 76 bits of the uuid and the integer entry holds the lower 52 bits:
9
- *
10
- * ```
11
- * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid
12
- * SSSSSSSS-SSSS-SSSS-SSS - array[0]: string
13
- * N NNNNNNNNNNNN - array[1]: integer
14
- * ```
15
- *
16
- * The integer keeps the common case cost of incrementing and computing deltas very low.
17
- * The string optimizes toString by caching the the majority of the resulting string.
18
- */
19
- export declare type NumericUuid = readonly [string, number] & {
20
- readonly NumericUuid: "9132ea20-a811-4756-85f8-aa6da5ca90f8";
21
- };
22
- /**
23
- * Calculates the numeric delta between a and b (i.e. a - b).
24
- * @param a - an uuid
25
- * @param b - an other uuid
26
- * @param maxDelta - the maximum integer delta (inclusive) to tolerate.
27
- * @returns undefined if the delta is negative or greater than `maxDelta`
28
- */
29
- export declare function getPositiveDelta(a: NumericUuid, b: NumericUuid, maxDelta: number): number | undefined;
30
- /**
31
- * @param offset - an optional offset to increment the returned StableId
32
- * @returns the string representation of a `NumericUuid`.
33
- */
34
- export declare function stableIdFromNumericUuid(uuid: NumericUuid, offset?: number): StableId;
35
- /**
36
- * @param stableId - a minimal uuid string
37
- * @returns a numeric representation of `stableId`.
38
- */
39
- export declare function numericUuidFromStableId(stableId: StableId): NumericUuid;
40
- /**
41
- * Creates a session base ID.
42
- * This method (rather than standard uuid generation methods) should be used to generate session IDs.
43
- */
44
- export declare function createSessionId(): SessionId;
45
- /**
46
- * Compares numeric uuids for equality.
47
- */
48
- export declare function numericUuidEquals(a: NumericUuid, b: NumericUuid): boolean;
49
- /**
50
- * Increments the uuid. `amount` must be a positive integer.
51
- * @returns the result of incrementing the uuid by `amount`.
52
- */
53
- export declare function incrementUuid(uuid: NumericUuid, amount: number): NumericUuid;
54
- /**
55
- * Any session uuid with all of its highish bits set is in danger of overflowing after fewer than 2^53 increments.
56
- * By zeroing one of those bits at random, potential overflow is prevented.
57
- */
58
- export declare function ensureSessionUuid(uuid: StableId): SessionId;
59
- //# sourceMappingURL=numericUuid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numericUuid.d.ts","sourceRoot":"","sources":["../../src/id-compressor/numericUuid.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAI1E;;;;;;;;;;;;GAYG;AACH,oBAAY,WAAW,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IACrD,QAAQ,CAAC,WAAW,EAAE,sCAAsC,CAAC;CAC7D,CAAC;AAQF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,CAAC,EAAE,WAAW,EACd,CAAC,EAAE,WAAW,EACd,QAAQ,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAgDpB;AAaD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,SAAI,GAAG,QAAQ,CAW/E;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAKvE;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAEzE;AAQD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAoD5E;AAiJD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAoB3D"}
@@ -1,325 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ensureSessionUuid = exports.incrementUuid = exports.numericUuidEquals = exports.createSessionId = exports.numericUuidFromStableId = exports.stableIdFromNumericUuid = exports.getPositiveDelta = void 0;
8
- /* eslint-disable no-bitwise */
9
- /* eslint-disable @typescript-eslint/no-namespace */
10
- const common_utils_1 = require("@fluidframework/common-utils");
11
- const utils_1 = require("./utils");
12
- const uuidUtilities_1 = require("./uuidUtilities");
13
- const bitsInNumericUuidInteger = 52; // Not tunable. Do not change.
14
- const nibblesInNumericUuidInteger = bitsInNumericUuidInteger / 4;
15
- const stringEntryLength = 22;
16
- const maxNumericUuidInteger = 2 ** bitsInNumericUuidInteger - 1;
17
- const fiftyThirdBit = 2 ** 52;
18
- /**
19
- * Calculates the numeric delta between a and b (i.e. a - b).
20
- * @param a - an uuid
21
- * @param b - an other uuid
22
- * @param maxDelta - the maximum integer delta (inclusive) to tolerate.
23
- * @returns undefined if the delta is negative or greater than `maxDelta`
24
- */
25
- function getPositiveDelta(a, b, maxDelta) {
26
- const [stringEntryA, lowNumberA] = a;
27
- const [stringEntryB, lowNumberB] = b;
28
- if (stringEntryA === stringEntryB) {
29
- const difference = lowNumberA - lowNumberB;
30
- if (difference >= 0 && difference <= maxDelta) {
31
- return difference;
32
- }
33
- return undefined;
34
- }
35
- const highNumberA = Number.parseInt(ChunkMath.Upper.parse(stringEntryA), 16);
36
- const highNumberB = Number.parseInt(ChunkMath.Upper.parse(stringEntryB), 16);
37
- let subtractHigh = highNumberA - highNumberB;
38
- if (Math.abs(subtractHigh) > 1) {
39
- // If the high bits differ by more than 1, then there is no chance that any lower bits could compensate
40
- return undefined;
41
- }
42
- let midNumberA = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryA));
43
- const midNumberB = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryB));
44
- let subtractLow = lowNumberA - lowNumberB;
45
- if (subtractLow < 0) {
46
- midNumberA -= 1;
47
- subtractLow += fiftyThirdBit;
48
- }
49
- let subtractMid = midNumberA - midNumberB;
50
- if (subtractMid < 0) {
51
- subtractHigh -= 1;
52
- subtractMid += ChunkMath.twentyThirdBit;
53
- }
54
- if (subtractHigh !== 0) {
55
- // a < b, no positive delta, or
56
- // a > b by much more than MAX_SAFE_INTEGER
57
- return undefined;
58
- }
59
- if (subtractMid > 1) {
60
- return undefined;
61
- }
62
- else {
63
- const trueDelta = fiftyThirdBit * subtractMid + subtractLow;
64
- return trueDelta > maxDelta ? undefined : trueDelta;
65
- }
66
- }
67
- exports.getPositiveDelta = getPositiveDelta;
68
- // Pre-allocated array of strings of zeros.
69
- // Used to pad hex strings up to 52 bits
70
- const zeros = [];
71
- for (let i = 0; i < nibblesInNumericUuidInteger; i++) {
72
- zeros.push("0".repeat(i));
73
- }
74
- function padToLengthWithZeros(str, count) {
75
- return str.length === count ? str : zeros[count - str.length] + str;
76
- }
77
- /**
78
- * @param offset - an optional offset to increment the returned StableId
79
- * @returns the string representation of a `NumericUuid`.
80
- */
81
- function stableIdFromNumericUuid(uuid, offset = 0) {
82
- const lowerAdd = uuid[1] + offset;
83
- // Common fast-path
84
- if (lowerAdd <= maxNumericUuidInteger) {
85
- const lowerString = padToLengthWithZeros(lowerAdd.toString(16), nibblesInNumericUuidInteger);
86
- return `${uuid[0] + lowerString.slice(0, 1)}-${lowerString.slice(1)}`;
87
- }
88
- return stableIdFromNumericUuid(incrementUuid(uuid, offset));
89
- }
90
- exports.stableIdFromNumericUuid = stableIdFromNumericUuid;
91
- /**
92
- * @param stableId - a minimal uuid string
93
- * @returns a numeric representation of `stableId`.
94
- */
95
- function numericUuidFromStableId(stableId) {
96
- const uuid = new Array(2);
97
- uuid[0] = stableId.slice(0, stringEntryLength);
98
- uuid[1] = Number.parseInt(ChunkMath.Lower.parse(stableId), 16);
99
- return uuid;
100
- }
101
- exports.numericUuidFromStableId = numericUuidFromStableId;
102
- /**
103
- * Creates a session base ID.
104
- * This method (rather than standard uuid generation methods) should be used to generate session IDs.
105
- */
106
- function createSessionId() {
107
- return ensureSessionUuid((0, uuidUtilities_1.generateStableId)());
108
- }
109
- exports.createSessionId = createSessionId;
110
- /**
111
- * Compares numeric uuids for equality.
112
- */
113
- function numericUuidEquals(a, b) {
114
- return a[0] === b[0] && a[1] === b[1];
115
- }
116
- exports.numericUuidEquals = numericUuidEquals;
117
- /**
118
- * The maximum value that can be contained in the upper string region of a numeric UUID (i.e. the string region excluding the version
119
- * nibble and the variant chunk)
120
- */
121
- const maxUpperNumber = 2 ** 48 - 1;
122
- /**
123
- * Increments the uuid. `amount` must be a positive integer.
124
- * @returns the result of incrementing the uuid by `amount`.
125
- */
126
- function incrementUuid(uuid, amount) {
127
- /*
128
- * UUIDs incremented beyond the max UUID "ffffffff-ffff-4fff-bfff-ffffffffffff" will cause a failure.
129
- * Also, some reserved bits of the v4 UUID must be treated as immutable (e.g. the version and
130
- * variant bits) and thus must not be incremented.
131
- */
132
- let newUuid;
133
- const result = uuid[1] + amount;
134
- if (result <= maxNumericUuidInteger) {
135
- // The new number still fits within the number region of a numeric UUID.
136
- // Incrementing is usually done with small amounts, so this is the dominantly common case.
137
- newUuid = [uuid[0], result];
138
- }
139
- else {
140
- // The numeric UUID's number region has overflowed. We will need to carry the overflow into the variant chunk (see `VariantChunk`).
141
- /** The amount left over after filling up the rest of the uuid's number region with the increment amount */
142
- const remainder = amount - (maxNumericUuidInteger - uuid[1]) - 1;
143
- const stringEntry = uuid[0];
144
- const [newVariantChunkString, carried] = ChunkMath.increment(stringEntry);
145
- if (carried) {
146
- // The variant chunk itself also overflowed. We'll need to carry the overflow further, into the upper string region of the UUID.
147
- const upperString = ChunkMath.Upper.parse(stringEntry);
148
- const upperNumber = Number.parseInt(upperString, 16);
149
- (0, common_utils_1.assert)(upperNumber <= maxUpperNumber, 0x49c /* Unexpectedly large upper number when incrementing UUID */);
150
- const newUpperNumber = upperNumber + 1;
151
- if (newUpperNumber > maxUpperNumber) {
152
- (0, utils_1.fail)("Exceeded maximum numeric UUID");
153
- }
154
- else {
155
- // The variant chunk overflowed but the upper string region did not. Splice in the incremented string region.
156
- const newUpperChunk = padToLengthWithZeros(newUpperNumber.toString(16), 12);
157
- newUuid = [
158
- `${ChunkMath.Upper.hyphenate(newUpperChunk)}-4${ChunkMath.Variant.hyphenate(newVariantChunkString)}`,
159
- remainder,
160
- ];
161
- }
162
- }
163
- else {
164
- // The variant chunk did not overflow, so just splice it back in.
165
- newUuid = [
166
- `${ChunkMath.Upper.slice(stringEntry)}-4${ChunkMath.Variant.hyphenate(newVariantChunkString)}`,
167
- remainder,
168
- ];
169
- }
170
- }
171
- return newUuid;
172
- }
173
- exports.incrementUuid = incrementUuid;
174
- var ChunkMath;
175
- (function (ChunkMath) {
176
- /*
177
- * Recall the UUID diagram from the top of this file which describes the layout of a Numeric UUID. To implement addition, we define
178
- * another region called the "variant chunk" which overlaps with the "string" region. Note that it is just beneath the required v4 uuid
179
- * version identifier (the 13th nibble 'V' which is always '4' in a v4 UUID) and just above the "number" region of the layout. It
180
- * contains inside of it the v4 UUID variant identifier bits as well (see https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.1).
181
- *
182
- * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid
183
- * SSSSSSSS SSSS SSSS SSS - array[0]: string
184
- * N NNNNNNNNNNNN - array[1]: integer
185
- * VVV-VVV - the variant chunk
186
- *
187
- * By defining the variant chunk in this way it is simple to splice in the v4 UUID version identifier ('V') just above it and any
188
- * "bit math" required due to the fact that the variant identifier bits ('v') do not fill up an entire nibble is handled within it.
189
- * The variant chunk is made up of 6 nibbles. Note the "vv" which denotes the two bits used for the v4 UUID variant identifier:
190
- *
191
- * AAAA BBBB CCCC vvDD EEEE FFFF
192
- *
193
- * Since we'll be needing to "skip" the variant bits ("vv") when doing addition, we define a a few masks which will be used below to
194
- * separate the variant chunk into pieces before recombining it:
195
- */
196
- // AAAA BBBB CCCC vvDD EEEE FFFF
197
- const upperVariantChunkMask = 0xfff000; // XXXX XXXX XXXX
198
- const variantBitMask = 0x800; // XX
199
- const middleVariantChunkMask = 0x300; // XX
200
- const lowerVariantChunkMask = 0xff; // XXXX XXXX
201
- /** The maximum numeric value that can be represented by the numerically relevant bits in the variant chunk */
202
- const maxVariantNumber = 2 ** 22 - 1;
203
- ChunkMath.twentyThirdBit = 2 ** 22;
204
- /**
205
- * The upper chunk, denoted by 'U's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL
206
- */
207
- let Upper;
208
- (function (Upper) {
209
- function parse(stringEntry) {
210
- return stringEntry.slice(0, 8) + stringEntry.slice(9, 13);
211
- }
212
- Upper.parse = parse;
213
- function hyphenate(upperChunk) {
214
- return `${upperChunk.slice(0, 8)}-${upperChunk.slice(8)}`;
215
- }
216
- Upper.hyphenate = hyphenate;
217
- function slice(stringEntry) {
218
- return stringEntry.slice(0, 13);
219
- }
220
- Upper.slice = slice;
221
- })(Upper = ChunkMath.Upper || (ChunkMath.Upper = {}));
222
- /**
223
- * The variant chunk, denoted by 'V's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL
224
- */
225
- let Variant;
226
- (function (Variant) {
227
- function parse(stringEntry) {
228
- return stringEntry.slice(15, 18) + stringEntry.slice(19, 22);
229
- }
230
- Variant.parse = parse;
231
- function hyphenate(variantChunk) {
232
- return `${variantChunk.slice(0, 3)}-${variantChunk.slice(3)}`;
233
- }
234
- Variant.hyphenate = hyphenate;
235
- })(Variant = ChunkMath.Variant || (ChunkMath.Variant = {}));
236
- /**
237
- * The lower chunk, denoted by 'L's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL
238
- */
239
- let Lower;
240
- (function (Lower) {
241
- function parse(stableId) {
242
- return (stableId.slice(stringEntryLength, stringEntryLength + 1) +
243
- stableId.slice(stringEntryLength + 2));
244
- }
245
- Lower.parse = parse;
246
- function hyphenate(lowerChunk) {
247
- return `${lowerChunk.slice(0, 1)}-${lowerChunk.slice(1)}`;
248
- }
249
- Lower.hyphenate = hyphenate;
250
- })(Lower = ChunkMath.Lower || (ChunkMath.Lower = {}));
251
- /**
252
- * Returns the number representation of the given bits corresponding to the variant chunk. The value is derived by
253
- * parsing all bits except for reserved bits (i.e. the variant bits).
254
- * @param variantChunk - the variantChunk
255
- */
256
- function getNumericValue(variantChunk) {
257
- const variantChunkBits = Number.parseInt(variantChunk, 16);
258
- const upperVariantBits = (variantChunkBits & upperVariantChunkMask) >> 2;
259
- const middleVariantBits = variantChunkBits & middleVariantChunkMask;
260
- const lowerVariantBits = variantChunkBits & lowerVariantChunkMask;
261
- return upperVariantBits + middleVariantBits + lowerVariantBits;
262
- }
263
- ChunkMath.getNumericValue = getNumericValue;
264
- /**
265
- * Given the string portion of a numeric uuid, add one to it.
266
- * @returns the resulting hex string and whether or not the new value overflowed, i.e. it exceeds `maxVariantNumber`. In this case,
267
- * the resulting hex string will wrap around to its minimum value '000b00'
268
- */
269
- function increment(stringEntry) {
270
- // To implement addition, the variant identifier bits are extracted from the variant chunk, the chunk is interpreted as a number,
271
- // that number is incremented by 1, and then the variant identifier bits are returned as we convert the number back into a hex
272
- // string.
273
- // This diagram may be helpful for seeing how the nibbles line up before and after the variant identifier bits are extracted. The
274
- // letters used for each nibble ("AAAA", "BBBB") etc. are arbitrary and are simply there to differentiate the nibbles as they shift.
275
- // --------------------------------
276
- // 1. AAAA BBBB CCCC vvDD EEEE FFFF
277
- // 2. AA AABB BBCC CCDD EEEE FFFF
278
- // 3. AA AABB BBCC CCDD EEEE FFFF
279
- // + 1
280
- // = GG GGHH HHII IIJJ JJKK KKLL
281
- // 4. GGGG HHHH IIII vvJJ JJKK KKLL
282
- // 1. The variant chunk is given as a 6 character (6 nibble) hex string, where the fourth nibble contains the variant bits
283
- // 2. The numerically important bits (i.e. not the variant identifier bits vv which are constant) are extracted into a single number
284
- const variantChunk = Variant.parse(stringEntry);
285
- const variantNumber = getNumericValue(variantChunk);
286
- (0, common_utils_1.assert)(variantNumber <= maxVariantNumber, 0x49d /* Unexpectedly large variant number when incrementing UUID */);
287
- // 3. Add one to the variant number to produce our new variant number.
288
- const newVariantNumber = variantNumber + 1;
289
- // 4. The variant identifier bits are added back into the number, which is then turned back into a hex string
290
- const newUpperVariantBits = (newVariantNumber & (upperVariantChunkMask >> 2)) << 2;
291
- const newMiddleVariantBits = (newVariantNumber & middleVariantChunkMask) | variantBitMask; // Add the variant bits back in
292
- const newLowerVariantBits = newVariantNumber & lowerVariantChunkMask;
293
- const newVariantChunkBits = newUpperVariantBits + newMiddleVariantBits + newLowerVariantBits;
294
- const newVariantChunk = padToLengthWithZeros(newVariantChunkBits.toString(16), variantChunk.length);
295
- return [newVariantChunk, newVariantNumber > maxVariantNumber];
296
- }
297
- ChunkMath.increment = increment;
298
- })(ChunkMath || (ChunkMath = {}));
299
- const maxUpperUuid = "ffffffff-ffff-4fff-bf";
300
- const maxNibbleCount = [...maxUpperUuid].filter((n) => n === "f").length;
301
- const newNibbles = ["7", "b", "d", "e"];
302
- function isMaxUpperNibble(index) {
303
- return maxUpperUuid.charAt(index) === "f";
304
- }
305
- /**
306
- * Any session uuid with all of its highish bits set is in danger of overflowing after fewer than 2^53 increments.
307
- * By zeroing one of those bits at random, potential overflow is prevented.
308
- */
309
- function ensureSessionUuid(uuid) {
310
- if (uuid.startsWith(maxUpperUuid)) {
311
- const targetNibble = Math.floor(Math.random() * maxNibbleCount);
312
- let actualIndex = 0;
313
- for (let nibbleIndex = 0; nibbleIndex < targetNibble && !isMaxUpperNibble(actualIndex); actualIndex += 1) {
314
- if (isMaxUpperNibble(actualIndex)) {
315
- nibbleIndex++;
316
- }
317
- }
318
- const newNibble = newNibbles[Math.floor(Math.random() * newNibbles.length)]; // Randomly choose a bit to zero
319
- const newUuid = uuid.slice(0, actualIndex) + newNibble + uuid.slice(actualIndex + 1);
320
- return newUuid;
321
- }
322
- return uuid;
323
- }
324
- exports.ensureSessionUuid = ensureSessionUuid;
325
- //# sourceMappingURL=numericUuid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numericUuid.js","sourceRoot":"","sources":["../../src/id-compressor/numericUuid.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAC/B,oDAAoD;AAEpD,+DAAsD;AAEtD,mCAA+B;AAC/B,mDAAmD;AAmBnD,MAAM,wBAAwB,GAAG,EAAE,CAAC,CAAC,8BAA8B;AACnE,MAAM,2BAA2B,GAAG,wBAAwB,GAAG,CAAC,CAAC;AACjE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,qBAAqB,GAAG,CAAC,IAAI,wBAAwB,GAAG,CAAC,CAAC;AAChE,MAAM,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ApBD,8CAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n/* eslint-disable @typescript-eslint/no-namespace */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { SessionId, StableId } from \"@fluidframework/runtime-definitions\";\nimport { fail } from \"./utils\";\nimport { generateStableId } from \"./uuidUtilities\";\n\n/**\n * A UUID (128 bit identifier) optimized for use as a 128 bit unsigned integer with fast addition and toString operations.\n * The string entry is the upper 76 bits of the uuid and the integer entry holds the lower 52 bits:\n *\n * ```\n * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid\n * SSSSSSSS-SSSS-SSSS-SSS - array[0]: string\n * N NNNNNNNNNNNN - array[1]: integer\n * ```\n *\n * The integer keeps the common case cost of incrementing and computing deltas very low.\n * The string optimizes toString by caching the the majority of the resulting string.\n */\nexport type NumericUuid = readonly [string, number] & {\n\treadonly NumericUuid: \"9132ea20-a811-4756-85f8-aa6da5ca90f8\";\n};\n\nconst bitsInNumericUuidInteger = 52; // Not tunable. Do not change.\nconst nibblesInNumericUuidInteger = bitsInNumericUuidInteger / 4;\nconst stringEntryLength = 22;\nconst maxNumericUuidInteger = 2 ** bitsInNumericUuidInteger - 1;\nconst fiftyThirdBit = 2 ** 52;\n\n/**\n * Calculates the numeric delta between a and b (i.e. a - b).\n * @param a - an uuid\n * @param b - an other uuid\n * @param maxDelta - the maximum integer delta (inclusive) to tolerate.\n * @returns undefined if the delta is negative or greater than `maxDelta`\n */\nexport function getPositiveDelta(\n\ta: NumericUuid,\n\tb: NumericUuid,\n\tmaxDelta: number,\n): number | undefined {\n\tconst [stringEntryA, lowNumberA] = a;\n\tconst [stringEntryB, lowNumberB] = b;\n\n\tif (stringEntryA === stringEntryB) {\n\t\tconst difference = lowNumberA - lowNumberB;\n\t\tif (difference >= 0 && difference <= maxDelta) {\n\t\t\treturn difference;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tconst highNumberA = Number.parseInt(ChunkMath.Upper.parse(stringEntryA), 16);\n\tconst highNumberB = Number.parseInt(ChunkMath.Upper.parse(stringEntryB), 16);\n\n\tlet subtractHigh = highNumberA - highNumberB;\n\tif (Math.abs(subtractHigh) > 1) {\n\t\t// If the high bits differ by more than 1, then there is no chance that any lower bits could compensate\n\t\treturn undefined;\n\t}\n\n\tlet midNumberA = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryA));\n\tconst midNumberB = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryB));\n\n\tlet subtractLow = lowNumberA - lowNumberB;\n\tif (subtractLow < 0) {\n\t\tmidNumberA -= 1;\n\t\tsubtractLow += fiftyThirdBit;\n\t}\n\n\tlet subtractMid = midNumberA - midNumberB;\n\tif (subtractMid < 0) {\n\t\tsubtractHigh -= 1;\n\t\tsubtractMid += ChunkMath.twentyThirdBit;\n\t}\n\n\tif (subtractHigh !== 0) {\n\t\t// a < b, no positive delta, or\n\t\t// a > b by much more than MAX_SAFE_INTEGER\n\t\treturn undefined;\n\t}\n\n\tif (subtractMid > 1) {\n\t\treturn undefined;\n\t} else {\n\t\tconst trueDelta = fiftyThirdBit * subtractMid + subtractLow;\n\t\treturn trueDelta > maxDelta ? undefined : trueDelta;\n\t}\n}\n\n// Pre-allocated array of strings of zeros.\n// Used to pad hex strings up to 52 bits\nconst zeros: string[] = [];\nfor (let i = 0; i < nibblesInNumericUuidInteger; i++) {\n\tzeros.push(\"0\".repeat(i));\n}\n\nfunction padToLengthWithZeros(str: string, count: number): string {\n\treturn str.length === count ? str : zeros[count - str.length] + str;\n}\n\n/**\n * @param offset - an optional offset to increment the returned StableId\n * @returns the string representation of a `NumericUuid`.\n */\nexport function stableIdFromNumericUuid(uuid: NumericUuid, offset = 0): StableId {\n\tconst lowerAdd = uuid[1] + offset;\n\t// Common fast-path\n\tif (lowerAdd <= maxNumericUuidInteger) {\n\t\tconst lowerString = padToLengthWithZeros(\n\t\t\tlowerAdd.toString(16),\n\t\t\tnibblesInNumericUuidInteger,\n\t\t);\n\t\treturn `${uuid[0] + lowerString.slice(0, 1)}-${lowerString.slice(1)}` as StableId;\n\t}\n\treturn stableIdFromNumericUuid(incrementUuid(uuid, offset));\n}\n\n/**\n * @param stableId - a minimal uuid string\n * @returns a numeric representation of `stableId`.\n */\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuid: (string | number)[] = new Array(2);\n\tuuid[0] = stableId.slice(0, stringEntryLength);\n\tuuid[1] = Number.parseInt(ChunkMath.Lower.parse(stableId), 16);\n\treturn uuid as readonly (number | string)[] as NumericUuid;\n}\n\n/**\n * Creates a session base ID.\n * This method (rather than standard uuid generation methods) should be used to generate session IDs.\n */\nexport function createSessionId(): SessionId {\n\treturn ensureSessionUuid(generateStableId());\n}\n\n/**\n * Compares numeric uuids for equality.\n */\nexport function numericUuidEquals(a: NumericUuid, b: NumericUuid): boolean {\n\treturn a[0] === b[0] && a[1] === b[1];\n}\n\n/**\n * The maximum value that can be contained in the upper string region of a numeric UUID (i.e. the string region excluding the version\n * nibble and the variant chunk)\n */\nconst maxUpperNumber = 2 ** 48 - 1;\n\n/**\n * Increments the uuid. `amount` must be a positive integer.\n * @returns the result of incrementing the uuid by `amount`.\n */\nexport function incrementUuid(uuid: NumericUuid, amount: number): NumericUuid {\n\t/*\n\t * UUIDs incremented beyond the max UUID \"ffffffff-ffff-4fff-bfff-ffffffffffff\" will cause a failure.\n\t * Also, some reserved bits of the v4 UUID must be treated as immutable (e.g. the version and\n\t * variant bits) and thus must not be incremented.\n\t */\n\tlet newUuid: [string, number];\n\tconst result = uuid[1] + amount;\n\tif (result <= maxNumericUuidInteger) {\n\t\t// The new number still fits within the number region of a numeric UUID.\n\t\t// Incrementing is usually done with small amounts, so this is the dominantly common case.\n\t\tnewUuid = [uuid[0], result];\n\t} else {\n\t\t// The numeric UUID's number region has overflowed. We will need to carry the overflow into the variant chunk (see `VariantChunk`).\n\t\t/** The amount left over after filling up the rest of the uuid's number region with the increment amount */\n\t\tconst remainder = amount - (maxNumericUuidInteger - uuid[1]) - 1;\n\t\tconst stringEntry = uuid[0];\n\t\tconst [newVariantChunkString, carried] = ChunkMath.increment(stringEntry);\n\n\t\tif (carried) {\n\t\t\t// The variant chunk itself also overflowed. We'll need to carry the overflow further, into the upper string region of the UUID.\n\t\t\tconst upperString = ChunkMath.Upper.parse(stringEntry);\n\t\t\tconst upperNumber = Number.parseInt(upperString, 16);\n\t\t\tassert(\n\t\t\t\tupperNumber <= maxUpperNumber,\n\t\t\t\t0x49c /* Unexpectedly large upper number when incrementing UUID */,\n\t\t\t);\n\t\t\tconst newUpperNumber = upperNumber + 1;\n\t\t\tif (newUpperNumber > maxUpperNumber) {\n\t\t\t\tfail(\"Exceeded maximum numeric UUID\");\n\t\t\t} else {\n\t\t\t\t// The variant chunk overflowed but the upper string region did not. Splice in the incremented string region.\n\t\t\t\tconst newUpperChunk = padToLengthWithZeros(newUpperNumber.toString(16), 12);\n\t\t\t\tnewUuid = [\n\t\t\t\t\t`${ChunkMath.Upper.hyphenate(newUpperChunk)}-4${ChunkMath.Variant.hyphenate(\n\t\t\t\t\t\tnewVariantChunkString,\n\t\t\t\t\t)}`,\n\t\t\t\t\tremainder,\n\t\t\t\t];\n\t\t\t}\n\t\t} else {\n\t\t\t// The variant chunk did not overflow, so just splice it back in.\n\t\t\tnewUuid = [\n\t\t\t\t`${ChunkMath.Upper.slice(stringEntry)}-4${ChunkMath.Variant.hyphenate(\n\t\t\t\t\tnewVariantChunkString,\n\t\t\t\t)}`,\n\t\t\t\tremainder,\n\t\t\t];\n\t\t}\n\t}\n\n\treturn newUuid as readonly [string, number] as NumericUuid;\n}\n\nnamespace ChunkMath {\n\t/*\n\t * Recall the UUID diagram from the top of this file which describes the layout of a Numeric UUID. To implement addition, we define\n\t * another region called the \"variant chunk\" which overlaps with the \"string\" region. Note that it is just beneath the required v4 uuid\n\t * version identifier (the 13th nibble 'V' which is always '4' in a v4 UUID) and just above the \"number\" region of the layout. It\n\t * contains inside of it the v4 UUID variant identifier bits as well (see https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.1).\n\t *\n\t * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid\n\t * SSSSSSSS SSSS SSSS SSS - array[0]: string\n\t * N NNNNNNNNNNNN - array[1]: integer\n\t * VVV-VVV - the variant chunk\n\t *\n\t * By defining the variant chunk in this way it is simple to splice in the v4 UUID version identifier ('V') just above it and any\n\t * \"bit math\" required due to the fact that the variant identifier bits ('v') do not fill up an entire nibble is handled within it.\n\t * The variant chunk is made up of 6 nibbles. Note the \"vv\" which denotes the two bits used for the v4 UUID variant identifier:\n\t *\n\t * AAAA BBBB CCCC vvDD EEEE FFFF\n\t *\n\t * Since we'll be needing to \"skip\" the variant bits (\"vv\") when doing addition, we define a a few masks which will be used below to\n\t * separate the variant chunk into pieces before recombining it:\n\t */\n\n\t// AAAA BBBB CCCC vvDD EEEE FFFF\n\tconst upperVariantChunkMask = 0xfff000; // XXXX XXXX XXXX\n\tconst variantBitMask = 0x800; // XX\n\tconst middleVariantChunkMask = 0x300; // XX\n\tconst lowerVariantChunkMask = 0xff; // XXXX XXXX\n\n\t/** The maximum numeric value that can be represented by the numerically relevant bits in the variant chunk */\n\tconst maxVariantNumber = 2 ** 22 - 1;\n\n\texport const twentyThirdBit = 2 ** 22;\n\n\t/**\n\t * The upper chunk, denoted by 'U's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL\n\t */\n\texport namespace Upper {\n\t\texport function parse(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(0, 8) + stringEntry.slice(9, 13);\n\t\t}\n\n\t\texport function hyphenate(upperChunk: string): string {\n\t\t\treturn `${upperChunk.slice(0, 8)}-${upperChunk.slice(8)}`;\n\t\t}\n\n\t\texport function slice(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(0, 13);\n\t\t}\n\t}\n\n\t/**\n\t * The variant chunk, denoted by 'V's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL\n\t */\n\texport namespace Variant {\n\t\texport function parse(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(15, 18) + stringEntry.slice(19, 22);\n\t\t}\n\n\t\texport function hyphenate(variantChunk: string): string {\n\t\t\treturn `${variantChunk.slice(0, 3)}-${variantChunk.slice(3)}`;\n\t\t}\n\t}\n\n\t/**\n\t * The lower chunk, denoted by 'L's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL\n\t */\n\texport namespace Lower {\n\t\texport function parse(stableId: StableId): string {\n\t\t\treturn (\n\t\t\t\tstableId.slice(stringEntryLength, stringEntryLength + 1) +\n\t\t\t\tstableId.slice(stringEntryLength + 2)\n\t\t\t);\n\t\t}\n\n\t\texport function hyphenate(lowerChunk: string): string {\n\t\t\treturn `${lowerChunk.slice(0, 1)}-${lowerChunk.slice(1)}`;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the number representation of the given bits corresponding to the variant chunk. The value is derived by\n\t * parsing all bits except for reserved bits (i.e. the variant bits).\n\t * @param variantChunk - the variantChunk\n\t */\n\texport function getNumericValue(variantChunk: string): number {\n\t\tconst variantChunkBits = Number.parseInt(variantChunk, 16);\n\t\tconst upperVariantBits = (variantChunkBits & upperVariantChunkMask) >> 2;\n\t\tconst middleVariantBits = variantChunkBits & middleVariantChunkMask;\n\t\tconst lowerVariantBits = variantChunkBits & lowerVariantChunkMask;\n\t\treturn upperVariantBits + middleVariantBits + lowerVariantBits;\n\t}\n\n\t/**\n\t * Given the string portion of a numeric uuid, add one to it.\n\t * @returns the resulting hex string and whether or not the new value overflowed, i.e. it exceeds `maxVariantNumber`. In this case,\n\t * the resulting hex string will wrap around to its minimum value '000b00'\n\t */\n\texport function increment(stringEntry: string): [newVariantChunk: string, overflowed: boolean] {\n\t\t// To implement addition, the variant identifier bits are extracted from the variant chunk, the chunk is interpreted as a number,\n\t\t// that number is incremented by 1, and then the variant identifier bits are returned as we convert the number back into a hex\n\t\t// string.\n\n\t\t// This diagram may be helpful for seeing how the nibbles line up before and after the variant identifier bits are extracted. The\n\t\t// letters used for each nibble (\"AAAA\", \"BBBB\") etc. are arbitrary and are simply there to differentiate the nibbles as they shift.\n\t\t// --------------------------------\n\t\t// 1. AAAA BBBB CCCC vvDD EEEE FFFF\n\t\t// 2. AA AABB BBCC CCDD EEEE FFFF\n\t\t// 3. AA AABB BBCC CCDD EEEE FFFF\n\t\t// + 1\n\t\t// = GG GGHH HHII IIJJ JJKK KKLL\n\t\t// 4. GGGG HHHH IIII vvJJ JJKK KKLL\n\n\t\t// 1. The variant chunk is given as a 6 character (6 nibble) hex string, where the fourth nibble contains the variant bits\n\t\t// 2. The numerically important bits (i.e. not the variant identifier bits vv which are constant) are extracted into a single number\n\t\tconst variantChunk = Variant.parse(stringEntry);\n\t\tconst variantNumber = getNumericValue(variantChunk);\n\t\tassert(\n\t\t\tvariantNumber <= maxVariantNumber,\n\t\t\t0x49d /* Unexpectedly large variant number when incrementing UUID */,\n\t\t);\n\t\t// 3. Add one to the variant number to produce our new variant number.\n\t\tconst newVariantNumber = variantNumber + 1;\n\t\t// 4. The variant identifier bits are added back into the number, which is then turned back into a hex string\n\t\tconst newUpperVariantBits = (newVariantNumber & (upperVariantChunkMask >> 2)) << 2;\n\t\tconst newMiddleVariantBits = (newVariantNumber & middleVariantChunkMask) | variantBitMask; // Add the variant bits back in\n\t\tconst newLowerVariantBits = newVariantNumber & lowerVariantChunkMask;\n\t\tconst newVariantChunkBits =\n\t\t\tnewUpperVariantBits + newMiddleVariantBits + newLowerVariantBits;\n\t\tconst newVariantChunk = padToLengthWithZeros(\n\t\t\tnewVariantChunkBits.toString(16),\n\t\t\tvariantChunk.length,\n\t\t);\n\t\treturn [newVariantChunk, newVariantNumber > maxVariantNumber];\n\t}\n}\n\nconst maxUpperUuid = \"ffffffff-ffff-4fff-bf\";\nconst maxNibbleCount = [...maxUpperUuid].filter((n) => n === \"f\").length;\nconst newNibbles = [\"7\", \"b\", \"d\", \"e\"];\nfunction isMaxUpperNibble(index: number): boolean {\n\treturn maxUpperUuid.charAt(index) === \"f\";\n}\n\n/**\n * Any session uuid with all of its highish bits set is in danger of overflowing after fewer than 2^53 increments.\n * By zeroing one of those bits at random, potential overflow is prevented.\n */\nexport function ensureSessionUuid(uuid: StableId): SessionId {\n\tif (uuid.startsWith(maxUpperUuid)) {\n\t\tconst targetNibble = Math.floor(Math.random() * maxNibbleCount);\n\t\tlet actualIndex = 0;\n\t\tfor (\n\t\t\tlet nibbleIndex = 0;\n\t\t\tnibbleIndex < targetNibble && !isMaxUpperNibble(actualIndex);\n\t\t\tactualIndex += 1\n\t\t) {\n\t\t\tif (isMaxUpperNibble(actualIndex)) {\n\t\t\t\tnibbleIndex++;\n\t\t\t}\n\t\t}\n\n\t\tconst newNibble = newNibbles[Math.floor(Math.random() * newNibbles.length)]; // Randomly choose a bit to zero\n\t\tconst newUuid = uuid.slice(0, actualIndex) + newNibble + uuid.slice(actualIndex + 1);\n\t\treturn newUuid as SessionId;\n\t}\n\n\treturn uuid as SessionId;\n}\n"]}