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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. package/.eslintrc.js +9 -11
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +449 -0
  4. package/README.md +364 -183
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/sequence.api.md +741 -0
  8. package/dist/{defaultMap.js → defaultMap.cjs} +29 -22
  9. package/dist/defaultMap.cjs.map +1 -0
  10. package/dist/defaultMap.d.ts +7 -6
  11. package/dist/defaultMap.d.ts.map +1 -1
  12. package/dist/defaultMapInterfaces.cjs +7 -0
  13. package/dist/defaultMapInterfaces.cjs.map +1 -0
  14. package/dist/defaultMapInterfaces.d.ts +44 -12
  15. package/dist/defaultMapInterfaces.d.ts.map +1 -1
  16. package/dist/index.cjs +60 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +14 -12
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/intervalCollection.cjs +1159 -0
  21. package/dist/intervalCollection.cjs.map +1 -0
  22. package/dist/intervalCollection.d.ts +461 -162
  23. package/dist/intervalCollection.d.ts.map +1 -1
  24. package/dist/intervalIndex/endpointInRangeIndex.cjs +66 -0
  25. package/dist/intervalIndex/endpointInRangeIndex.cjs.map +1 -0
  26. package/dist/intervalIndex/endpointInRangeIndex.d.ts +34 -0
  27. package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -0
  28. package/dist/intervalIndex/endpointIndex.cjs +47 -0
  29. package/dist/intervalIndex/endpointIndex.cjs.map +1 -0
  30. package/dist/intervalIndex/endpointIndex.d.ts +38 -0
  31. package/dist/intervalIndex/endpointIndex.d.ts.map +1 -0
  32. package/dist/intervalIndex/idIntervalIndex.cjs +44 -0
  33. package/dist/intervalIndex/idIntervalIndex.cjs.map +1 -0
  34. package/dist/intervalIndex/idIntervalIndex.d.ts +18 -0
  35. package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -0
  36. package/dist/intervalIndex/index.cjs +24 -0
  37. package/dist/intervalIndex/index.cjs.map +1 -0
  38. package/dist/intervalIndex/index.d.ts +13 -0
  39. package/dist/intervalIndex/index.d.ts.map +1 -0
  40. package/dist/{defaultMapInterfaces.js → intervalIndex/intervalIndex.cjs} +1 -1
  41. package/dist/intervalIndex/intervalIndex.cjs.map +1 -0
  42. package/dist/intervalIndex/intervalIndex.d.ts +30 -0
  43. package/dist/intervalIndex/intervalIndex.d.ts.map +1 -0
  44. package/dist/intervalIndex/intervalIndexUtils.cjs +22 -0
  45. package/dist/intervalIndex/intervalIndexUtils.cjs.map +1 -0
  46. package/dist/intervalIndex/intervalIndexUtils.d.ts +17 -0
  47. package/dist/intervalIndex/intervalIndexUtils.d.ts.map +1 -0
  48. package/dist/intervalIndex/overlappingIntervalsIndex.cjs +116 -0
  49. package/dist/intervalIndex/overlappingIntervalsIndex.cjs.map +1 -0
  50. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +44 -0
  51. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
  52. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.cjs +41 -0
  53. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.cjs.map +1 -0
  54. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +11 -0
  55. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
  56. package/dist/intervalIndex/sequenceIntervalIndexes.cjs +7 -0
  57. package/dist/intervalIndex/sequenceIntervalIndexes.cjs.map +1 -0
  58. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +35 -0
  59. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
  60. package/dist/intervalIndex/startpointInRangeIndex.cjs +66 -0
  61. package/dist/intervalIndex/startpointInRangeIndex.cjs.map +1 -0
  62. package/dist/intervalIndex/startpointInRangeIndex.d.ts +34 -0
  63. package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -0
  64. package/dist/intervalTree.cjs +80 -0
  65. package/dist/intervalTree.cjs.map +1 -0
  66. package/dist/intervalTree.d.ts +24 -0
  67. package/dist/intervalTree.d.ts.map +1 -0
  68. package/dist/intervals/index.cjs +23 -0
  69. package/dist/intervals/index.cjs.map +1 -0
  70. package/dist/intervals/index.d.ts +8 -0
  71. package/dist/intervals/index.d.ts.map +1 -0
  72. package/dist/intervals/interval.cjs +181 -0
  73. package/dist/intervals/interval.cjs.map +1 -0
  74. package/dist/intervals/interval.d.ts +84 -0
  75. package/dist/intervals/interval.d.ts.map +1 -0
  76. package/dist/intervals/intervalUtils.cjs +83 -0
  77. package/dist/intervals/intervalUtils.cjs.map +1 -0
  78. package/dist/intervals/intervalUtils.d.ts +230 -0
  79. package/dist/intervals/intervalUtils.d.ts.map +1 -0
  80. package/dist/intervals/sequenceInterval.cjs +378 -0
  81. package/dist/intervals/sequenceInterval.cjs.map +1 -0
  82. package/dist/intervals/sequenceInterval.d.ts +137 -0
  83. package/dist/intervals/sequenceInterval.d.ts.map +1 -0
  84. package/dist/{localValues.js → localValues.cjs} +1 -1
  85. package/dist/localValues.cjs.map +1 -0
  86. package/dist/localValues.d.ts +2 -1
  87. package/dist/localValues.d.ts.map +1 -1
  88. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  89. package/dist/packageVersion.cjs.map +1 -0
  90. package/dist/packageVersion.d.ts +1 -1
  91. package/dist/packageVersion.d.ts.map +1 -1
  92. package/dist/revertibles.cjs +425 -0
  93. package/dist/revertibles.cjs.map +1 -0
  94. package/dist/revertibles.d.ts +86 -0
  95. package/dist/revertibles.d.ts.map +1 -0
  96. package/dist/sequence-alpha.d.ts +1315 -0
  97. package/dist/sequence-beta.d.ts +244 -0
  98. package/dist/sequence-public.d.ts +244 -0
  99. package/dist/sequence-untrimmed.d.ts +1803 -0
  100. package/dist/{sequence.js → sequence.cjs} +226 -156
  101. package/dist/sequence.cjs.map +1 -0
  102. package/dist/sequence.d.ts +125 -48
  103. package/dist/sequence.d.ts.map +1 -1
  104. package/dist/{sequenceDeltaEvent.js → sequenceDeltaEvent.cjs} +18 -8
  105. package/dist/sequenceDeltaEvent.cjs.map +1 -0
  106. package/dist/sequenceDeltaEvent.d.ts +24 -7
  107. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  108. package/dist/sequenceFactory.cjs +55 -0
  109. package/dist/sequenceFactory.cjs.map +1 -0
  110. package/dist/sequenceFactory.d.ts +3 -89
  111. package/dist/sequenceFactory.d.ts.map +1 -1
  112. package/dist/{sharedIntervalCollection.js → sharedIntervalCollection.cjs} +17 -22
  113. package/dist/sharedIntervalCollection.cjs.map +1 -0
  114. package/dist/sharedIntervalCollection.d.ts +12 -12
  115. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  116. package/dist/{sharedSequence.js → sharedSequence.cjs} +29 -22
  117. package/dist/sharedSequence.cjs.map +1 -0
  118. package/dist/sharedSequence.d.ts +14 -2
  119. package/dist/sharedSequence.d.ts.map +1 -1
  120. package/dist/sharedString.cjs +286 -0
  121. package/dist/sharedString.cjs.map +1 -0
  122. package/dist/sharedString.d.ts +58 -22
  123. package/dist/sharedString.d.ts.map +1 -1
  124. package/dist/tsdoc-metadata.json +11 -0
  125. package/lib/{defaultMap.d.ts → defaultMap.d.mts} +7 -6
  126. package/lib/defaultMap.d.mts.map +1 -0
  127. package/lib/{defaultMap.js → defaultMap.mjs} +28 -21
  128. package/lib/defaultMap.mjs.map +1 -0
  129. package/lib/{defaultMapInterfaces.d.ts → defaultMapInterfaces.d.mts} +44 -12
  130. package/lib/defaultMapInterfaces.d.mts.map +1 -0
  131. package/lib/defaultMapInterfaces.mjs +6 -0
  132. package/lib/defaultMapInterfaces.mjs.map +1 -0
  133. package/lib/index.d.mts +17 -0
  134. package/lib/index.d.mts.map +1 -0
  135. package/lib/index.mjs +16 -0
  136. package/lib/index.mjs.map +1 -0
  137. package/lib/intervalCollection.d.mts +569 -0
  138. package/lib/intervalCollection.d.mts.map +1 -0
  139. package/lib/intervalCollection.mjs +1144 -0
  140. package/lib/intervalCollection.mjs.map +1 -0
  141. package/lib/intervalIndex/endpointInRangeIndex.d.mts +34 -0
  142. package/lib/intervalIndex/endpointInRangeIndex.d.mts.map +1 -0
  143. package/lib/intervalIndex/endpointInRangeIndex.mjs +61 -0
  144. package/lib/intervalIndex/endpointInRangeIndex.mjs.map +1 -0
  145. package/lib/intervalIndex/endpointIndex.d.mts +38 -0
  146. package/lib/intervalIndex/endpointIndex.d.mts.map +1 -0
  147. package/lib/intervalIndex/endpointIndex.mjs +42 -0
  148. package/lib/intervalIndex/endpointIndex.mjs.map +1 -0
  149. package/lib/intervalIndex/idIntervalIndex.d.mts +18 -0
  150. package/lib/intervalIndex/idIntervalIndex.d.mts.map +1 -0
  151. package/lib/intervalIndex/idIntervalIndex.mjs +40 -0
  152. package/lib/intervalIndex/idIntervalIndex.mjs.map +1 -0
  153. package/lib/intervalIndex/index.d.mts +13 -0
  154. package/lib/intervalIndex/index.d.mts.map +1 -0
  155. package/lib/intervalIndex/index.mjs +11 -0
  156. package/lib/intervalIndex/index.mjs.map +1 -0
  157. package/lib/intervalIndex/intervalIndex.d.mts +30 -0
  158. package/lib/intervalIndex/intervalIndex.d.mts.map +1 -0
  159. package/lib/{defaultMapInterfaces.js → intervalIndex/intervalIndex.mjs} +1 -1
  160. package/lib/intervalIndex/intervalIndex.mjs.map +1 -0
  161. package/lib/intervalIndex/intervalIndexUtils.d.mts +17 -0
  162. package/lib/intervalIndex/intervalIndexUtils.d.mts.map +1 -0
  163. package/lib/intervalIndex/intervalIndexUtils.mjs +18 -0
  164. package/lib/intervalIndex/intervalIndexUtils.mjs.map +1 -0
  165. package/lib/intervalIndex/overlappingIntervalsIndex.d.mts +44 -0
  166. package/lib/intervalIndex/overlappingIntervalsIndex.d.mts.map +1 -0
  167. package/lib/intervalIndex/overlappingIntervalsIndex.mjs +111 -0
  168. package/lib/intervalIndex/overlappingIntervalsIndex.mjs.map +1 -0
  169. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts +11 -0
  170. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts.map +1 -0
  171. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs +37 -0
  172. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs.map +1 -0
  173. package/lib/intervalIndex/sequenceIntervalIndexes.d.mts +35 -0
  174. package/lib/intervalIndex/sequenceIntervalIndexes.d.mts.map +1 -0
  175. package/lib/intervalIndex/sequenceIntervalIndexes.mjs +6 -0
  176. package/lib/intervalIndex/sequenceIntervalIndexes.mjs.map +1 -0
  177. package/lib/intervalIndex/startpointInRangeIndex.d.mts +34 -0
  178. package/lib/intervalIndex/startpointInRangeIndex.d.mts.map +1 -0
  179. package/lib/intervalIndex/startpointInRangeIndex.mjs +61 -0
  180. package/lib/intervalIndex/startpointInRangeIndex.mjs.map +1 -0
  181. package/lib/intervalTree.d.mts +24 -0
  182. package/lib/intervalTree.d.mts.map +1 -0
  183. package/lib/intervalTree.mjs +76 -0
  184. package/lib/intervalTree.mjs.map +1 -0
  185. package/lib/intervals/index.d.mts +8 -0
  186. package/lib/intervals/index.d.mts.map +1 -0
  187. package/lib/intervals/index.mjs +8 -0
  188. package/lib/intervals/index.mjs.map +1 -0
  189. package/lib/intervals/interval.d.mts +84 -0
  190. package/lib/intervals/interval.d.mts.map +1 -0
  191. package/lib/intervals/interval.mjs +176 -0
  192. package/lib/intervals/interval.mjs.map +1 -0
  193. package/lib/intervals/intervalUtils.d.mts +230 -0
  194. package/lib/intervals/intervalUtils.d.mts.map +1 -0
  195. package/lib/intervals/intervalUtils.mjs +77 -0
  196. package/lib/intervals/intervalUtils.mjs.map +1 -0
  197. package/lib/intervals/sequenceInterval.d.mts +137 -0
  198. package/lib/intervals/sequenceInterval.d.mts.map +1 -0
  199. package/lib/intervals/sequenceInterval.mjs +370 -0
  200. package/lib/intervals/sequenceInterval.mjs.map +1 -0
  201. package/lib/{localValues.d.ts → localValues.d.mts} +3 -2
  202. package/lib/localValues.d.mts.map +1 -0
  203. package/lib/{localValues.js → localValues.mjs} +2 -2
  204. package/lib/localValues.mjs.map +1 -0
  205. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
  206. package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
  207. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  208. package/lib/packageVersion.mjs.map +1 -0
  209. package/lib/revertibles.d.mts +86 -0
  210. package/lib/revertibles.d.mts.map +1 -0
  211. package/lib/revertibles.mjs +416 -0
  212. package/lib/revertibles.mjs.map +1 -0
  213. package/lib/sequence-alpha.d.mts +1315 -0
  214. package/lib/sequence-beta.d.mts +244 -0
  215. package/lib/sequence-public.d.mts +244 -0
  216. package/lib/sequence-untrimmed.d.mts +1803 -0
  217. package/lib/{sequence.d.ts → sequence.d.mts} +127 -50
  218. package/lib/sequence.d.mts.map +1 -0
  219. package/lib/{sequence.js → sequence.mjs} +225 -152
  220. package/lib/sequence.mjs.map +1 -0
  221. package/lib/{sequenceDeltaEvent.d.ts → sequenceDeltaEvent.d.mts} +24 -7
  222. package/lib/sequenceDeltaEvent.d.mts.map +1 -0
  223. package/lib/{sequenceDeltaEvent.js → sequenceDeltaEvent.mjs} +20 -8
  224. package/lib/sequenceDeltaEvent.mjs.map +1 -0
  225. package/lib/sequenceFactory.d.mts +22 -0
  226. package/lib/sequenceFactory.d.mts.map +1 -0
  227. package/lib/sequenceFactory.mjs +51 -0
  228. package/lib/sequenceFactory.mjs.map +1 -0
  229. package/lib/{sharedIntervalCollection.d.ts → sharedIntervalCollection.d.mts} +12 -12
  230. package/lib/sharedIntervalCollection.d.mts.map +1 -0
  231. package/lib/{sharedIntervalCollection.js → sharedIntervalCollection.mjs} +16 -21
  232. package/lib/sharedIntervalCollection.mjs.map +1 -0
  233. package/lib/{sharedSequence.d.ts → sharedSequence.d.mts} +15 -3
  234. package/lib/sharedSequence.d.mts.map +1 -0
  235. package/lib/{sharedSequence.js → sharedSequence.mjs} +30 -23
  236. package/lib/sharedSequence.mjs.map +1 -0
  237. package/lib/{sharedString.d.ts → sharedString.d.mts} +60 -24
  238. package/lib/sharedString.d.mts.map +1 -0
  239. package/lib/sharedString.mjs +281 -0
  240. package/lib/sharedString.mjs.map +1 -0
  241. package/package.json +146 -75
  242. package/prettier.config.cjs +8 -0
  243. package/sequence.test-files.tar +0 -0
  244. package/src/defaultMap.ts +417 -403
  245. package/src/defaultMapInterfaces.ts +157 -117
  246. package/src/index.ts +86 -26
  247. package/src/intervalCollection.ts +2043 -1563
  248. package/src/intervalIndex/endpointInRangeIndex.ts +116 -0
  249. package/src/intervalIndex/endpointIndex.ts +91 -0
  250. package/src/intervalIndex/idIntervalIndex.ts +64 -0
  251. package/src/intervalIndex/index.ts +25 -0
  252. package/src/intervalIndex/intervalIndex.ts +32 -0
  253. package/src/intervalIndex/intervalIndexUtils.ts +27 -0
  254. package/src/intervalIndex/overlappingIntervalsIndex.ts +187 -0
  255. package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +80 -0
  256. package/src/intervalIndex/sequenceIntervalIndexes.ts +34 -0
  257. package/src/intervalIndex/startpointInRangeIndex.ts +114 -0
  258. package/src/intervalTree.ts +98 -0
  259. package/src/intervals/index.ts +25 -0
  260. package/src/intervals/interval.ts +238 -0
  261. package/src/intervals/intervalUtils.ts +288 -0
  262. package/src/intervals/sequenceInterval.ts +616 -0
  263. package/src/localValues.ts +68 -73
  264. package/src/packageVersion.ts +1 -1
  265. package/src/revertibles.ts +693 -0
  266. package/src/sequence.ts +845 -690
  267. package/src/sequenceDeltaEvent.ts +164 -131
  268. package/src/sequenceFactory.ts +58 -214
  269. package/src/sharedIntervalCollection.ts +161 -152
  270. package/src/sharedSequence.ts +181 -167
  271. package/src/sharedString.ts +390 -234
  272. package/tsc-multi.test.json +10 -0
  273. package/tsconfig.json +11 -13
  274. package/.editorconfig +0 -7
  275. package/.vscode/launch.json +0 -15
  276. package/dist/defaultMap.js.map +0 -1
  277. package/dist/defaultMapInterfaces.js.map +0 -1
  278. package/dist/index.js +0 -44
  279. package/dist/index.js.map +0 -1
  280. package/dist/intervalCollection.js +0 -1250
  281. package/dist/intervalCollection.js.map +0 -1
  282. package/dist/localValues.js.map +0 -1
  283. package/dist/packageVersion.js.map +0 -1
  284. package/dist/sequence.js.map +0 -1
  285. package/dist/sequenceDeltaEvent.js.map +0 -1
  286. package/dist/sequenceFactory.js +0 -192
  287. package/dist/sequenceFactory.js.map +0 -1
  288. package/dist/sharedIntervalCollection.js.map +0 -1
  289. package/dist/sharedNumberSequence.d.ts +0 -50
  290. package/dist/sharedNumberSequence.d.ts.map +0 -1
  291. package/dist/sharedNumberSequence.js +0 -61
  292. package/dist/sharedNumberSequence.js.map +0 -1
  293. package/dist/sharedObjectSequence.d.ts +0 -50
  294. package/dist/sharedObjectSequence.d.ts.map +0 -1
  295. package/dist/sharedObjectSequence.js +0 -61
  296. package/dist/sharedObjectSequence.js.map +0 -1
  297. package/dist/sharedSequence.js.map +0 -1
  298. package/dist/sharedString.js +0 -187
  299. package/dist/sharedString.js.map +0 -1
  300. package/dist/sparsematrix.d.ts +0 -139
  301. package/dist/sparsematrix.d.ts.map +0 -1
  302. package/dist/sparsematrix.js +0 -332
  303. package/dist/sparsematrix.js.map +0 -1
  304. package/lib/defaultMap.d.ts.map +0 -1
  305. package/lib/defaultMap.js.map +0 -1
  306. package/lib/defaultMapInterfaces.d.ts.map +0 -1
  307. package/lib/defaultMapInterfaces.js.map +0 -1
  308. package/lib/index.d.ts +0 -27
  309. package/lib/index.d.ts.map +0 -1
  310. package/lib/index.js +0 -26
  311. package/lib/index.js.map +0 -1
  312. package/lib/intervalCollection.d.ts +0 -270
  313. package/lib/intervalCollection.d.ts.map +0 -1
  314. package/lib/intervalCollection.js +0 -1238
  315. package/lib/intervalCollection.js.map +0 -1
  316. package/lib/localValues.d.ts.map +0 -1
  317. package/lib/localValues.js.map +0 -1
  318. package/lib/packageVersion.js.map +0 -1
  319. package/lib/sequence.d.ts.map +0 -1
  320. package/lib/sequence.js.map +0 -1
  321. package/lib/sequenceDeltaEvent.d.ts.map +0 -1
  322. package/lib/sequenceDeltaEvent.js.map +0 -1
  323. package/lib/sequenceFactory.d.ts +0 -108
  324. package/lib/sequenceFactory.d.ts.map +0 -1
  325. package/lib/sequenceFactory.js +0 -186
  326. package/lib/sequenceFactory.js.map +0 -1
  327. package/lib/sharedIntervalCollection.d.ts.map +0 -1
  328. package/lib/sharedIntervalCollection.js.map +0 -1
  329. package/lib/sharedNumberSequence.d.ts +0 -50
  330. package/lib/sharedNumberSequence.d.ts.map +0 -1
  331. package/lib/sharedNumberSequence.js +0 -57
  332. package/lib/sharedNumberSequence.js.map +0 -1
  333. package/lib/sharedObjectSequence.d.ts +0 -50
  334. package/lib/sharedObjectSequence.d.ts.map +0 -1
  335. package/lib/sharedObjectSequence.js +0 -57
  336. package/lib/sharedObjectSequence.js.map +0 -1
  337. package/lib/sharedSequence.d.ts.map +0 -1
  338. package/lib/sharedSequence.js.map +0 -1
  339. package/lib/sharedString.d.ts.map +0 -1
  340. package/lib/sharedString.js +0 -183
  341. package/lib/sharedString.js.map +0 -1
  342. package/lib/sparsematrix.d.ts +0 -139
  343. package/lib/sparsematrix.d.ts.map +0 -1
  344. package/lib/sparsematrix.js +0 -323
  345. package/lib/sparsematrix.js.map +0 -1
  346. package/src/sharedNumberSequence.ts +0 -62
  347. package/src/sharedObjectSequence.ts +0 -62
  348. package/src/sparsematrix.ts +0 -421
  349. package/tsconfig.esnext.json +0 -7
@@ -0,0 +1,1144 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
+ import { assert } from "@fluidframework/core-utils";
7
+ import { addProperties, createMap, getSlideToSegoff, MergeTreeDeltaType, ReferenceType, refTypeIncludesFlag, reservedRangeLabelsKey, UnassignedSequenceNumber, DetachedReferencePosition, UniversalSequenceNumber, SlidingPreference, } from "@fluidframework/merge-tree";
8
+ import { LoggingError, UsageError } from "@fluidframework/telemetry-utils";
9
+ import { v4 as uuid } from "uuid";
10
+ import { IntervalOpType, IntervalStickiness, IntervalType, SequenceInterval, createPositionReferenceFromSegoff, endReferenceSlidingPreference, startReferenceSlidingPreference, sequenceIntervalHelpers, createInterval, } from "./intervals/index.mjs";
11
+ import { EndpointIndex, OverlappingIntervalsIndex, createIdIntervalIndex, } from "./intervalIndex/index.mjs";
12
+ /**
13
+ * Defines a side relative to a character in a sequence.
14
+ *
15
+ * @remarks See {@link SequencePlace} for additional context on usage.
16
+ * @alpha
17
+ */
18
+ export var Side;
19
+ (function (Side) {
20
+ Side[Side["Before"] = 0] = "Before";
21
+ Side[Side["After"] = 1] = "After";
22
+ })(Side || (Side = {}));
23
+ const reservedIntervalIdKey = "intervalId";
24
+ export function sidesFromStickiness(stickiness) {
25
+ const startSide = (stickiness & IntervalStickiness.START) !== 0 ? Side.After : Side.Before;
26
+ const endSide = (stickiness & IntervalStickiness.END) !== 0 ? Side.Before : Side.After;
27
+ return { startSide, endSide };
28
+ }
29
+ /**
30
+ * Decompress an interval after loading a summary from JSON. The exact format
31
+ * of this compression is unspecified and subject to change
32
+ */
33
+ function decompressInterval(interval, label) {
34
+ const stickiness = interval[5] ?? IntervalStickiness.END;
35
+ const { startSide, endSide } = sidesFromStickiness(stickiness);
36
+ return {
37
+ start: interval[0],
38
+ end: interval[1],
39
+ sequenceNumber: interval[2],
40
+ intervalType: interval[3],
41
+ properties: { ...interval[4], [reservedRangeLabelsKey]: [label] },
42
+ stickiness,
43
+ startSide,
44
+ endSide,
45
+ };
46
+ }
47
+ /**
48
+ * Compress an interval prior to serialization as JSON. The exact format of this
49
+ * compression is unspecified and subject to change
50
+ */
51
+ function compressInterval(interval) {
52
+ const { start, end, sequenceNumber, intervalType, properties } = interval;
53
+ let base = [
54
+ start,
55
+ end,
56
+ sequenceNumber,
57
+ intervalType,
58
+ // remove the `referenceRangeLabels` property as it is already stored
59
+ // in the `label` field of the summary
60
+ { ...properties, [reservedRangeLabelsKey]: undefined },
61
+ ];
62
+ if (interval.stickiness !== undefined && interval.stickiness !== IntervalStickiness.END) {
63
+ // reassignment to make it easier for typescript to reason about types
64
+ base = [...base, interval.stickiness];
65
+ }
66
+ return base;
67
+ }
68
+ export function endpointPosAndSide(start, end) {
69
+ const startIsPlainEndpoint = typeof start === "number" || start === "start" || start === "end";
70
+ const endIsPlainEndpoint = typeof end === "number" || end === "start" || end === "end";
71
+ const startSide = startIsPlainEndpoint ? Side.Before : start?.side;
72
+ const endSide = endIsPlainEndpoint ? Side.Before : end?.side;
73
+ const startPos = startIsPlainEndpoint ? start : start?.pos;
74
+ const endPos = endIsPlainEndpoint ? end : end?.pos;
75
+ return {
76
+ startSide,
77
+ endSide,
78
+ startPos,
79
+ endPos,
80
+ };
81
+ }
82
+ function toSequencePlace(pos, side) {
83
+ return typeof pos === "number" ? { pos, side } : pos;
84
+ }
85
+ function toOptionalSequencePlace(pos, side = Side.Before) {
86
+ return typeof pos === "number" ? { pos, side } : pos;
87
+ }
88
+ export function computeStickinessFromSide(startPos = -1, startSide = Side.Before, endPos = -1, endSide = Side.Before) {
89
+ let stickiness = IntervalStickiness.NONE;
90
+ if (startSide === Side.After || startPos === "start") {
91
+ stickiness |= IntervalStickiness.START;
92
+ }
93
+ if (endSide === Side.Before || endPos === "end") {
94
+ stickiness |= IntervalStickiness.END;
95
+ }
96
+ return stickiness;
97
+ }
98
+ export function createIntervalIndex() {
99
+ const helpers = {
100
+ create: createInterval,
101
+ };
102
+ const lc = new LocalIntervalCollection(undefined, "", helpers, {});
103
+ return lc;
104
+ }
105
+ export class LocalIntervalCollection {
106
+ constructor(client, label, helpers, options,
107
+ /** Callback invoked each time one of the endpoints of an interval slides. */
108
+ onPositionChange) {
109
+ this.client = client;
110
+ this.label = label;
111
+ this.helpers = helpers;
112
+ this.options = options;
113
+ this.onPositionChange = onPositionChange;
114
+ this.overlappingIntervalsIndex = new OverlappingIntervalsIndex(client, helpers);
115
+ this.idIntervalIndex = createIdIntervalIndex();
116
+ this.endIntervalIndex = new EndpointIndex(client, helpers);
117
+ this.indexes = new Set([
118
+ this.overlappingIntervalsIndex,
119
+ this.idIntervalIndex,
120
+ this.endIntervalIndex,
121
+ ]);
122
+ }
123
+ createLegacyId(start, end) {
124
+ // Create a non-unique ID based on start and end to be used on intervals that come from legacy clients
125
+ // without ID's.
126
+ return `${LocalIntervalCollection.legacyIdPrefix}${start}-${end}`;
127
+ }
128
+ /**
129
+ * Validates that a serialized interval has the ID property. Creates an ID
130
+ * if one does not already exist
131
+ *
132
+ * @param serializedInterval - The interval to be checked
133
+ * @returns The interval's existing or newly created id
134
+ */
135
+ ensureSerializedId(serializedInterval) {
136
+ let id = serializedInterval.properties?.[reservedIntervalIdKey];
137
+ if (id === undefined) {
138
+ // Back-compat: 0.39 and earlier did not have IDs on intervals. If an interval from such a client
139
+ // comes over the wire, create a non-unique one based on start/end.
140
+ // This will allow all clients to refer to this interval consistently.
141
+ id = this.createLegacyId(serializedInterval.start, serializedInterval.end);
142
+ const newProps = {
143
+ [reservedIntervalIdKey]: id,
144
+ };
145
+ serializedInterval.properties = addProperties(serializedInterval.properties, newProps);
146
+ }
147
+ // Make the ID immutable for safety's sake.
148
+ Object.defineProperty(serializedInterval.properties, reservedIntervalIdKey, {
149
+ configurable: false,
150
+ enumerable: true,
151
+ writable: false,
152
+ });
153
+ return id;
154
+ }
155
+ removeIntervalFromIndexes(interval) {
156
+ for (const index of this.indexes) {
157
+ index.remove(interval);
158
+ }
159
+ }
160
+ appendIndex(index) {
161
+ this.indexes.add(index);
162
+ }
163
+ removeIndex(index) {
164
+ return this.indexes.delete(index);
165
+ }
166
+ removeExistingInterval(interval) {
167
+ this.removeIntervalFromIndexes(interval);
168
+ this.removeIntervalListeners(interval);
169
+ }
170
+ createInterval(start, end, intervalType, op) {
171
+ return this.helpers.create(this.label, start, end, this.client, intervalType, op, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint);
172
+ }
173
+ addInterval(start, end, intervalType, props, op) {
174
+ var _a;
175
+ const interval = this.createInterval(start, end, intervalType, op);
176
+ if (interval) {
177
+ if (!interval.properties) {
178
+ interval.properties = createMap();
179
+ }
180
+ if (props) {
181
+ // This check is intended to prevent scenarios where a random interval is created and then
182
+ // inserted into a collection. The aim is to ensure that the collection is created first
183
+ // then the user can create/add intervals based on the collection
184
+ if (props[reservedRangeLabelsKey] !== undefined &&
185
+ props[reservedRangeLabelsKey][0] !== this.label) {
186
+ throw new LoggingError("Adding an interval that belongs to another interval collection is not permitted");
187
+ }
188
+ interval.addProperties(props);
189
+ }
190
+ (_a = interval.properties)[reservedIntervalIdKey] ?? (_a[reservedIntervalIdKey] = uuid());
191
+ this.add(interval);
192
+ }
193
+ return interval;
194
+ }
195
+ linkEndpointsToInterval(interval) {
196
+ if (interval instanceof SequenceInterval) {
197
+ interval.start.addProperties({ interval });
198
+ interval.end.addProperties({ interval });
199
+ }
200
+ }
201
+ addIntervalToIndexes(interval) {
202
+ for (const index of this.indexes) {
203
+ index.add(interval);
204
+ }
205
+ }
206
+ add(interval) {
207
+ this.linkEndpointsToInterval(interval);
208
+ this.addIntervalToIndexes(interval);
209
+ this.addIntervalListeners(interval);
210
+ }
211
+ changeInterval(interval, start, end, op, localSeq) {
212
+ const newInterval = interval.modify(this.label, start, end, op, localSeq, this.options.mergeTreeReferencesCanSlideToEndpoint);
213
+ if (newInterval) {
214
+ this.removeExistingInterval(interval);
215
+ this.add(newInterval);
216
+ }
217
+ return newInterval;
218
+ }
219
+ serialize() {
220
+ return {
221
+ label: this.label,
222
+ intervals: Array.from(this.idIntervalIndex, (interval) => compressInterval(interval.serialize())),
223
+ version: 2,
224
+ };
225
+ }
226
+ addIntervalListeners(interval) {
227
+ const cloneRef = (ref) => {
228
+ const segment = ref.getSegment();
229
+ if (segment === undefined) {
230
+ // Cloning is unnecessary: refs which have slid off the string entirely
231
+ // never get slid back on. Creation code for refs doesn't accept undefined segment
232
+ // either, so this must be special-cased.
233
+ return ref;
234
+ }
235
+ return this.client.createLocalReferencePosition(segment, ref.getOffset(), ReferenceType.Transient, ref.properties, ref.slidingPreference, ref.canSlideToEndpoint);
236
+ };
237
+ if (interval instanceof SequenceInterval) {
238
+ let previousInterval;
239
+ let pendingChanges = 0;
240
+ interval.addPositionChangeListeners(() => {
241
+ pendingChanges++;
242
+ // Note: both start and end can change and invoke beforeSlide on each endpoint before afterSlide.
243
+ if (!previousInterval) {
244
+ previousInterval = interval.clone();
245
+ previousInterval.start = cloneRef(previousInterval.start);
246
+ previousInterval.end = cloneRef(previousInterval.end);
247
+ this.removeIntervalFromIndexes(interval);
248
+ }
249
+ }, () => {
250
+ assert(previousInterval !== undefined, 0x3fa /* Invalid interleaving of before/after slide */);
251
+ pendingChanges--;
252
+ if (pendingChanges === 0) {
253
+ this.addIntervalToIndexes(interval);
254
+ this.onPositionChange?.(interval, previousInterval);
255
+ previousInterval = undefined;
256
+ }
257
+ });
258
+ }
259
+ }
260
+ removeIntervalListeners(interval) {
261
+ if (interval instanceof SequenceInterval) {
262
+ interval.removePositionChangeListeners();
263
+ }
264
+ }
265
+ }
266
+ LocalIntervalCollection.legacyIdPrefix = "legacy";
267
+ class SequenceIntervalCollectionFactory {
268
+ load(emitter, raw = [], options) {
269
+ return new IntervalCollection(sequenceIntervalHelpers, true, emitter, raw, options);
270
+ }
271
+ store(value) {
272
+ return value.serializeInternal();
273
+ }
274
+ }
275
+ export class SequenceIntervalCollectionValueType {
276
+ get name() {
277
+ return SequenceIntervalCollectionValueType.Name;
278
+ }
279
+ get factory() {
280
+ return SequenceIntervalCollectionValueType._factory;
281
+ }
282
+ get ops() {
283
+ return SequenceIntervalCollectionValueType._ops;
284
+ }
285
+ }
286
+ SequenceIntervalCollectionValueType.Name = "sharedStringIntervalCollection";
287
+ SequenceIntervalCollectionValueType._factory = new SequenceIntervalCollectionFactory();
288
+ SequenceIntervalCollectionValueType._ops = makeOpsMap();
289
+ class IntervalCollectionFactory {
290
+ load(emitter, raw = [], options) {
291
+ const helpers = {
292
+ create: createInterval,
293
+ };
294
+ const collection = new IntervalCollection(helpers, false, emitter, raw, options);
295
+ collection.attachGraph(undefined, "");
296
+ return collection;
297
+ }
298
+ store(value) {
299
+ return value.serializeInternal();
300
+ }
301
+ }
302
+ export class IntervalCollectionValueType {
303
+ get name() {
304
+ return IntervalCollectionValueType.Name;
305
+ }
306
+ get factory() {
307
+ return IntervalCollectionValueType._factory;
308
+ }
309
+ get ops() {
310
+ return IntervalCollectionValueType._ops;
311
+ }
312
+ }
313
+ IntervalCollectionValueType.Name = "sharedIntervalCollection";
314
+ IntervalCollectionValueType._factory = new IntervalCollectionFactory();
315
+ IntervalCollectionValueType._ops = makeOpsMap();
316
+ export function makeOpsMap() {
317
+ const rebase = (collection, op, localOpMetadata) => {
318
+ const { localSeq } = localOpMetadata;
319
+ const rebasedValue = collection.rebaseLocalInterval(op.opName, op.value, localSeq);
320
+ if (rebasedValue === undefined) {
321
+ return undefined;
322
+ }
323
+ const rebasedOp = { ...op, value: rebasedValue };
324
+ return { rebasedOp, rebasedLocalOpMetadata: localOpMetadata };
325
+ };
326
+ return new Map([
327
+ [
328
+ IntervalOpType.ADD,
329
+ {
330
+ process: (collection, params, local, op, localOpMetadata) => {
331
+ // if params is undefined, the interval was deleted during
332
+ // rebasing
333
+ if (!params) {
334
+ return;
335
+ }
336
+ assert(op !== undefined, 0x3fb /* op should exist here */);
337
+ collection.ackAdd(params, local, op, localOpMetadata);
338
+ },
339
+ rebase,
340
+ },
341
+ ],
342
+ [
343
+ IntervalOpType.DELETE,
344
+ {
345
+ process: (collection, params, local, op) => {
346
+ assert(op !== undefined, 0x3fc /* op should exist here */);
347
+ collection.ackDelete(params, local, op);
348
+ },
349
+ rebase: (collection, op, localOpMetadata) => {
350
+ // Deletion of intervals is based on id, so requires no rebasing.
351
+ return { rebasedOp: op, rebasedLocalOpMetadata: localOpMetadata };
352
+ },
353
+ },
354
+ ],
355
+ [
356
+ IntervalOpType.CHANGE,
357
+ {
358
+ process: (collection, params, local, op, localOpMetadata) => {
359
+ // if params is undefined, the interval was deleted during
360
+ // rebasing
361
+ if (!params) {
362
+ return;
363
+ }
364
+ assert(op !== undefined, 0x3fd /* op should exist here */);
365
+ collection.ackChange(params, local, op, localOpMetadata);
366
+ },
367
+ rebase,
368
+ },
369
+ ],
370
+ ]);
371
+ }
372
+ class IntervalCollectionIterator {
373
+ constructor(collection, iteratesForward = true, start, end) {
374
+ this.results = [];
375
+ this.index = 0;
376
+ collection.gatherIterationResults(this.results, iteratesForward, start, end);
377
+ }
378
+ next() {
379
+ if (this.index < this.results.length) {
380
+ return {
381
+ value: this.results[this.index++],
382
+ done: false,
383
+ };
384
+ }
385
+ return {
386
+ value: undefined,
387
+ done: true,
388
+ };
389
+ }
390
+ }
391
+ // solely for type checking in the implementation of add - will be removed once
392
+ // deprecated signatures are removed
393
+ const isSequencePlace = (place) => {
394
+ return typeof place === "number" || typeof place === "string" || place.pos !== undefined;
395
+ };
396
+ /**
397
+ * {@inheritdoc IIntervalCollection}
398
+ */
399
+ export class IntervalCollection extends TypedEventEmitter {
400
+ get attached() {
401
+ return !!this.localCollection;
402
+ }
403
+ /** @internal */
404
+ constructor(helpers, requiresClient, emitter, serializedIntervals, options = {}) {
405
+ super();
406
+ this.helpers = helpers;
407
+ this.requiresClient = requiresClient;
408
+ this.emitter = emitter;
409
+ this.options = options;
410
+ this.localSeqToSerializedInterval = new Map();
411
+ this.localSeqToRebasedInterval = new Map();
412
+ this.pendingChangesStart = new Map();
413
+ this.pendingChangesEnd = new Map();
414
+ this.savedSerializedIntervals = Array.isArray(serializedIntervals)
415
+ ? serializedIntervals
416
+ : serializedIntervals.intervals.map((i) => decompressInterval(i, serializedIntervals.label));
417
+ }
418
+ /**
419
+ * {@inheritdoc IIntervalCollection.attachIndex}
420
+ */
421
+ attachIndex(index) {
422
+ if (!this.attached) {
423
+ throw new LoggingError("The local interval collection must exist");
424
+ }
425
+ for (const interval of this) {
426
+ index.add(interval);
427
+ }
428
+ this.localCollection?.appendIndex(index);
429
+ }
430
+ /**
431
+ * {@inheritdoc IIntervalCollection.detachIndex}
432
+ */
433
+ detachIndex(index) {
434
+ if (!this.attached) {
435
+ throw new LoggingError("The local interval collection must exist");
436
+ }
437
+ // Avoid removing intervals if the index does not exist
438
+ if (!this.localCollection?.removeIndex(index)) {
439
+ return false;
440
+ }
441
+ for (const interval of this) {
442
+ index.remove(interval);
443
+ }
444
+ return true;
445
+ }
446
+ rebasePositionWithSegmentSlide(pos, seqNumberFrom, localSeq) {
447
+ if (!this.client) {
448
+ throw new LoggingError("mergeTree client must exist");
449
+ }
450
+ if (pos === "start" || pos === "end") {
451
+ return pos;
452
+ }
453
+ const { clientId } = this.client.getCollabWindow();
454
+ const { segment, offset } = this.client.getContainingSegment(pos, {
455
+ referenceSequenceNumber: seqNumberFrom,
456
+ clientId: this.client.getLongClientId(clientId),
457
+ }, localSeq);
458
+ // if segment is undefined, it slid off the string
459
+ assert(segment !== undefined, 0x54e /* No segment found */);
460
+ const segoff = getSlideToSegoff({ segment, offset }, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint) ?? segment;
461
+ // case happens when rebasing op, but concurrently entire string has been deleted
462
+ if (segoff.segment === undefined || segoff.offset === undefined) {
463
+ return DetachedReferencePosition;
464
+ }
465
+ assert(offset !== undefined && 0 <= offset && offset < segment.cachedLength, 0x54f /* Invalid offset */);
466
+ return this.client.findReconnectionPosition(segoff.segment, localSeq) + segoff.offset;
467
+ }
468
+ computeRebasedPositions(localSeq) {
469
+ assert(this.client !== undefined, 0x550 /* Client should be defined when computing rebased position */);
470
+ const original = this.localSeqToSerializedInterval.get(localSeq);
471
+ assert(original !== undefined, 0x551 /* Failed to store pending serialized interval info for this localSeq. */);
472
+ const rebased = { ...original };
473
+ const { start, end, sequenceNumber } = original;
474
+ if (start !== undefined) {
475
+ rebased.start = this.rebasePositionWithSegmentSlide(start, sequenceNumber, localSeq);
476
+ }
477
+ if (end !== undefined) {
478
+ rebased.end = this.rebasePositionWithSegmentSlide(end, sequenceNumber, localSeq);
479
+ }
480
+ return rebased;
481
+ }
482
+ /** @internal */
483
+ attachGraph(client, label) {
484
+ if (this.attached) {
485
+ throw new LoggingError("Only supports one Sequence attach");
486
+ }
487
+ if (client === undefined && this.requiresClient) {
488
+ throw new LoggingError("Client required for this collection");
489
+ }
490
+ // Instantiate the local interval collection based on the saved intervals
491
+ this.client = client;
492
+ if (client) {
493
+ client.on("normalize", () => {
494
+ for (const localSeq of this.localSeqToSerializedInterval.keys()) {
495
+ this.localSeqToRebasedInterval.set(localSeq, this.computeRebasedPositions(localSeq));
496
+ }
497
+ });
498
+ }
499
+ this.localCollection = new LocalIntervalCollection(client, label, this.helpers, this.options, (interval, previousInterval) => this.emitChange(interval, previousInterval, true, true));
500
+ if (this.savedSerializedIntervals) {
501
+ for (const serializedInterval of this.savedSerializedIntervals) {
502
+ this.localCollection.ensureSerializedId(serializedInterval);
503
+ const { start: startPos, end: endPos, intervalType, properties, startSide, endSide, } = serializedInterval;
504
+ const start = typeof startPos === "number" && startSide !== undefined
505
+ ? { pos: startPos, side: startSide }
506
+ : startPos;
507
+ const end = typeof endPos === "number" && endSide !== undefined
508
+ ? { pos: endPos, side: endSide }
509
+ : endPos;
510
+ const interval = this.helpers.create(label, start, end, client, intervalType, undefined, true, this.options.mergeTreeReferencesCanSlideToEndpoint);
511
+ if (properties) {
512
+ interval.addProperties(properties);
513
+ }
514
+ this.localCollection.add(interval);
515
+ }
516
+ }
517
+ this.savedSerializedIntervals = undefined;
518
+ }
519
+ /**
520
+ * Gets the next local sequence number, modifying this client's collab window in doing so.
521
+ */
522
+ getNextLocalSeq() {
523
+ if (this.client) {
524
+ return ++this.client.getCollabWindow().localSeq;
525
+ }
526
+ return 0;
527
+ }
528
+ emitChange(interval, previousInterval, local, slide, op) {
529
+ // Temporarily make references transient so that positional queries work (non-transient refs
530
+ // on resolve to DetachedPosition on any segments that don't contain them). The original refType
531
+ // is restored as single-endpoint changes re-use previous references.
532
+ let startRefType;
533
+ let endRefType;
534
+ if (previousInterval instanceof SequenceInterval) {
535
+ startRefType = previousInterval.start.refType;
536
+ endRefType = previousInterval.end.refType;
537
+ previousInterval.start.refType = ReferenceType.Transient;
538
+ previousInterval.end.refType = ReferenceType.Transient;
539
+ this.emit("changeInterval", interval, previousInterval, local, op, slide);
540
+ previousInterval.start.refType = startRefType;
541
+ previousInterval.end.refType = endRefType;
542
+ }
543
+ else {
544
+ this.emit("changeInterval", interval, previousInterval, local, op, slide);
545
+ }
546
+ }
547
+ /**
548
+ * {@inheritdoc IIntervalCollection.getIntervalById}
549
+ */
550
+ getIntervalById(id) {
551
+ if (!this.localCollection) {
552
+ throw new LoggingError("attach must be called before accessing intervals");
553
+ }
554
+ return this.localCollection.idIntervalIndex.getIntervalById(id);
555
+ }
556
+ assertStickinessEnabled(start, end) {
557
+ if (!(typeof start === "number" && typeof end === "number") &&
558
+ !this.options.intervalStickinessEnabled) {
559
+ throw new UsageError("attempted to set interval stickiness without enabling `intervalStickinessEnabled` feature flag");
560
+ }
561
+ }
562
+ add(start, end, intervalType, props) {
563
+ let intStart;
564
+ let intEnd;
565
+ let type;
566
+ let properties;
567
+ if (isSequencePlace(start)) {
568
+ intStart = start;
569
+ assert(end !== undefined, 0x7c0 /* end must be defined */);
570
+ intEnd = end;
571
+ assert(intervalType !== undefined, 0x7c1 /* intervalType must be defined */);
572
+ type = intervalType;
573
+ properties = props;
574
+ }
575
+ else {
576
+ intStart = start.start;
577
+ intEnd = start.end;
578
+ type = IntervalType.SlideOnRemove;
579
+ properties = start.props;
580
+ }
581
+ if (!this.localCollection) {
582
+ throw new LoggingError("attach must be called prior to adding intervals");
583
+ }
584
+ if (type & IntervalType.Transient) {
585
+ throw new LoggingError("Can not add transient intervals");
586
+ }
587
+ const { startSide, endSide, startPos, endPos } = endpointPosAndSide(intStart, intEnd);
588
+ assert(startPos !== undefined &&
589
+ endPos !== undefined &&
590
+ startSide !== undefined &&
591
+ endSide !== undefined, 0x793 /* start and end cannot be undefined because they were not passed in as undefined */);
592
+ const stickiness = computeStickinessFromSide(startPos, startSide, endPos, endSide);
593
+ this.assertStickinessEnabled(intStart, intEnd);
594
+ const interval = this.localCollection.addInterval(toSequencePlace(startPos, startSide), toSequencePlace(endPos, endSide), type, properties);
595
+ if (interval) {
596
+ if (!this.isCollaborating && interval instanceof SequenceInterval) {
597
+ setSlideOnRemove(interval.start);
598
+ setSlideOnRemove(interval.end);
599
+ }
600
+ const serializedInterval = {
601
+ start: startPos,
602
+ end: endPos,
603
+ intervalType: type,
604
+ properties: interval.properties,
605
+ sequenceNumber: this.client?.getCurrentSeq() ?? 0,
606
+ stickiness,
607
+ startSide,
608
+ endSide,
609
+ };
610
+ const localSeq = this.getNextLocalSeq();
611
+ this.localSeqToSerializedInterval.set(localSeq, serializedInterval);
612
+ // Local ops get submitted to the server. Remote ops have the deserializer run.
613
+ this.emitter.emit("add", undefined, serializedInterval, { localSeq });
614
+ }
615
+ this.emit("addInterval", interval, true, undefined);
616
+ return interval;
617
+ }
618
+ deleteExistingInterval(interval, local, op) {
619
+ if (!this.localCollection) {
620
+ throw new LoggingError("Attach must be called before accessing intervals");
621
+ }
622
+ // The given interval is known to exist in the collection.
623
+ this.localCollection.removeExistingInterval(interval);
624
+ if (interval) {
625
+ // Local ops get submitted to the server. Remote ops have the deserializer run.
626
+ if (local) {
627
+ this.emitter.emit("delete", undefined, interval.serialize(), {
628
+ localSeq: this.getNextLocalSeq(),
629
+ });
630
+ }
631
+ else {
632
+ if (this.onDeserialize) {
633
+ this.onDeserialize(interval);
634
+ }
635
+ }
636
+ }
637
+ this.emit("deleteInterval", interval, local, op);
638
+ }
639
+ /**
640
+ * {@inheritdoc IIntervalCollection.removeIntervalById}
641
+ */
642
+ removeIntervalById(id) {
643
+ if (!this.localCollection) {
644
+ throw new LoggingError("Attach must be called before accessing intervals");
645
+ }
646
+ const interval = this.localCollection.idIntervalIndex.getIntervalById(id);
647
+ if (interval) {
648
+ this.deleteExistingInterval(interval, true, undefined);
649
+ }
650
+ return interval;
651
+ }
652
+ /**
653
+ * {@inheritdoc IIntervalCollection.changeProperties}
654
+ * @deprecated - call change with the id and an object containing the new props values
655
+ */
656
+ changeProperties(id, props) {
657
+ this.change(id, { props });
658
+ }
659
+ change(arg1, arg2, arg3) {
660
+ const id = arg1;
661
+ let start;
662
+ let end;
663
+ let props;
664
+ if (isSequencePlace(arg2)) {
665
+ start = arg2;
666
+ end = arg3;
667
+ }
668
+ else {
669
+ start = arg2.start;
670
+ end = arg2.end;
671
+ props = arg2.props;
672
+ }
673
+ if (!this.localCollection) {
674
+ throw new LoggingError("Attach must be called before accessing intervals");
675
+ }
676
+ // Force id to be a string.
677
+ if (typeof id !== "string") {
678
+ throw new UsageError("Change API requires an ID that is a string");
679
+ }
680
+ // Ensure that both start and end are defined or both are undefined.
681
+ if ((start === undefined) !== (end === undefined)) {
682
+ throw new UsageError("Change API requires both start and end to be defined or undefined");
683
+ }
684
+ // prevent the overwriting of an interval label, it should remain unchanged
685
+ // once it has been inserted into the collection.
686
+ if (props?.[reservedRangeLabelsKey] !== undefined) {
687
+ throw new UsageError("The label property should not be modified once inserted to the collection");
688
+ }
689
+ const interval = this.getIntervalById(id);
690
+ if (interval) {
691
+ let deltaProps;
692
+ let newInterval;
693
+ if (props !== undefined) {
694
+ deltaProps = interval.addProperties(props, true, this.isCollaborating ? UnassignedSequenceNumber : UniversalSequenceNumber);
695
+ }
696
+ if (start !== undefined && end !== undefined) {
697
+ newInterval = this.localCollection.changeInterval(interval, start, end);
698
+ if (!this.isCollaborating && newInterval instanceof SequenceInterval) {
699
+ setSlideOnRemove(newInterval.start);
700
+ setSlideOnRemove(newInterval.end);
701
+ }
702
+ }
703
+ const serializedInterval = interval.serialize();
704
+ const { startPos, startSide, endPos, endSide } = endpointPosAndSide(start, end);
705
+ const stickiness = computeStickinessFromSide(startPos, startSide, endPos, endSide);
706
+ serializedInterval.start = startPos;
707
+ serializedInterval.end = endPos;
708
+ serializedInterval.startSide = startSide;
709
+ serializedInterval.endSide = endSide;
710
+ serializedInterval.stickiness = stickiness;
711
+ // Emit a property bag containing the ID and the other (if any) properties changed
712
+ serializedInterval.properties = {
713
+ [reservedIntervalIdKey]: interval.getIntervalId(),
714
+ ...props,
715
+ };
716
+ const localSeq = this.getNextLocalSeq();
717
+ this.localSeqToSerializedInterval.set(localSeq, serializedInterval);
718
+ this.emitter.emit("change", undefined, serializedInterval, { localSeq });
719
+ if (deltaProps !== undefined) {
720
+ this.emit("propertyChanged", interval, deltaProps, true, undefined);
721
+ }
722
+ if (newInterval) {
723
+ this.addPendingChange(id, serializedInterval);
724
+ this.emitChange(newInterval, interval, true, false);
725
+ }
726
+ return newInterval;
727
+ }
728
+ // No interval to change
729
+ return undefined;
730
+ }
731
+ get isCollaborating() {
732
+ return this.client?.getCollabWindow().collaborating ?? false;
733
+ }
734
+ addPendingChange(id, serializedInterval) {
735
+ if (!this.isCollaborating) {
736
+ return;
737
+ }
738
+ if (serializedInterval.start !== undefined) {
739
+ this.addPendingChangeHelper(id, this.pendingChangesStart, serializedInterval);
740
+ }
741
+ if (serializedInterval.end !== undefined) {
742
+ this.addPendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);
743
+ }
744
+ }
745
+ addPendingChangeHelper(id, pendingChanges, serializedInterval) {
746
+ let entries = pendingChanges.get(id);
747
+ if (!entries) {
748
+ entries = [];
749
+ pendingChanges.set(id, entries);
750
+ }
751
+ entries.push(serializedInterval);
752
+ }
753
+ removePendingChange(serializedInterval) {
754
+ // Change ops always have an ID.
755
+ const id = serializedInterval.properties?.[reservedIntervalIdKey];
756
+ if (serializedInterval.start !== undefined) {
757
+ this.removePendingChangeHelper(id, this.pendingChangesStart, serializedInterval);
758
+ }
759
+ if (serializedInterval.end !== undefined) {
760
+ this.removePendingChangeHelper(id, this.pendingChangesEnd, serializedInterval);
761
+ }
762
+ }
763
+ removePendingChangeHelper(id, pendingChanges, serializedInterval) {
764
+ const entries = pendingChanges.get(id);
765
+ if (entries) {
766
+ const pendingChange = entries.shift();
767
+ if (entries.length === 0) {
768
+ pendingChanges.delete(id);
769
+ }
770
+ if (pendingChange?.start !== serializedInterval.start ||
771
+ pendingChange?.end !== serializedInterval.end) {
772
+ throw new LoggingError("Mismatch in pending changes");
773
+ }
774
+ }
775
+ }
776
+ hasPendingChangeStart(id) {
777
+ const entries = this.pendingChangesStart.get(id);
778
+ return entries && entries.length !== 0;
779
+ }
780
+ hasPendingChangeEnd(id) {
781
+ const entries = this.pendingChangesEnd.get(id);
782
+ return entries && entries.length !== 0;
783
+ }
784
+ /** @internal */
785
+ ackChange(serializedInterval, local, op, localOpMetadata) {
786
+ if (!this.localCollection) {
787
+ throw new LoggingError("Attach must be called before accessing intervals");
788
+ }
789
+ if (local) {
790
+ assert(localOpMetadata !== undefined, 0x552 /* op metadata should be defined for local op */);
791
+ this.localSeqToSerializedInterval.delete(localOpMetadata?.localSeq);
792
+ // This is an ack from the server. Remove the pending change.
793
+ this.removePendingChange(serializedInterval);
794
+ }
795
+ // Note that the ID is in the property bag only to allow us to find the interval.
796
+ // This API cannot change the ID, and writing to the ID property will result in an exception. So we
797
+ // strip it out of the properties here.
798
+ const { [reservedIntervalIdKey]: id, ...newProps } = serializedInterval.properties ?? {};
799
+ assert(id !== undefined, 0x3fe /* id must exist on the interval */);
800
+ const interval = this.getIntervalById(id);
801
+ if (!interval) {
802
+ // The interval has been removed locally; no-op.
803
+ return;
804
+ }
805
+ if (local) {
806
+ // Let the propertyManager prune its pending change-properties set.
807
+ interval.propertyManager?.ackPendingProperties({
808
+ type: MergeTreeDeltaType.ANNOTATE,
809
+ props: serializedInterval.properties ?? {},
810
+ });
811
+ this.ackInterval(interval, op);
812
+ }
813
+ else {
814
+ // If there are pending changes with this ID, don't apply the remote start/end change, as the local ack
815
+ // should be the winning change.
816
+ let start;
817
+ let end;
818
+ // Track pending start/end independently of one another.
819
+ if (!this.hasPendingChangeStart(id)) {
820
+ start = serializedInterval.start;
821
+ }
822
+ if (!this.hasPendingChangeEnd(id)) {
823
+ end = serializedInterval.end;
824
+ }
825
+ let newInterval = interval;
826
+ if (start !== undefined || end !== undefined) {
827
+ // If changeInterval gives us a new interval, work with that one. Otherwise keep working with
828
+ // the one we originally found in the tree.
829
+ newInterval =
830
+ this.localCollection.changeInterval(interval, toOptionalSequencePlace(start, serializedInterval.startSide), toOptionalSequencePlace(end, serializedInterval.endSide), op) ?? interval;
831
+ }
832
+ const deltaProps = newInterval.addProperties(newProps, true, op.sequenceNumber);
833
+ if (this.onDeserialize) {
834
+ this.onDeserialize(newInterval);
835
+ }
836
+ if (newInterval !== interval) {
837
+ this.emitChange(newInterval, interval, local, false, op);
838
+ }
839
+ const changedProperties = Object.keys(newProps).length > 0;
840
+ if (changedProperties) {
841
+ this.emit("propertyChanged", interval, deltaProps, local, op);
842
+ }
843
+ }
844
+ }
845
+ /**
846
+ * {@inheritdoc IIntervalCollection.attachDeserializer}
847
+ */
848
+ attachDeserializer(onDeserialize) {
849
+ // If no deserializer is specified can skip all processing work
850
+ if (!onDeserialize) {
851
+ return;
852
+ }
853
+ // Start by storing the callbacks so that any subsequent modifications make use of them
854
+ this.onDeserialize = onDeserialize;
855
+ // Trigger the async prepare work across all values in the collection
856
+ if (this.attached) {
857
+ this.map(onDeserialize);
858
+ }
859
+ }
860
+ /**
861
+ * Returns new interval after rebasing. If undefined, the interval was
862
+ * deleted as a result of rebasing. This can occur if the interval applies
863
+ * to a range that no longer exists, and the interval was unable to slide.
864
+ *
865
+ * @internal
866
+ */
867
+ rebaseLocalInterval(opName, serializedInterval, localSeq) {
868
+ if (!this.client) {
869
+ // If there's no associated mergeTree client, the originally submitted op is still correct.
870
+ return serializedInterval;
871
+ }
872
+ if (!this.attached) {
873
+ throw new LoggingError("attachSequence must be called");
874
+ }
875
+ const { intervalType, properties, stickiness, startSide, endSide } = serializedInterval;
876
+ const { start: startRebased, end: endRebased } = this.localSeqToRebasedInterval.get(localSeq) ?? this.computeRebasedPositions(localSeq);
877
+ const intervalId = properties?.[reservedIntervalIdKey];
878
+ const localInterval = this.localCollection?.idIntervalIndex.getIntervalById(intervalId);
879
+ const rebased = {
880
+ start: startRebased,
881
+ end: endRebased,
882
+ intervalType,
883
+ sequenceNumber: this.client?.getCurrentSeq() ?? 0,
884
+ properties,
885
+ stickiness,
886
+ startSide,
887
+ endSide,
888
+ };
889
+ if (opName === "change" &&
890
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- ?? is not logically equivalent when .hasPendingChangeStart returns false.
891
+ (this.hasPendingChangeStart(intervalId) || this.hasPendingChangeEnd(intervalId))) {
892
+ this.removePendingChange(serializedInterval);
893
+ this.addPendingChange(intervalId, rebased);
894
+ }
895
+ // if the interval slid off the string, rebase the op to be a noop and delete the interval.
896
+ if (startRebased === DetachedReferencePosition ||
897
+ endRebased === DetachedReferencePosition) {
898
+ if (localInterval) {
899
+ this.localCollection?.removeExistingInterval(localInterval);
900
+ }
901
+ return undefined;
902
+ }
903
+ if (localInterval !== undefined) {
904
+ // we know we must be using `SequenceInterval` because `this.client` exists
905
+ assert(localInterval instanceof SequenceInterval, 0x3a0 /* localInterval must be `SequenceInterval` when used with client */);
906
+ // The rebased op may place this interval's endpoints on different segments. Calling `changeInterval` here
907
+ // updates the local client's state to be consistent with the emitted op.
908
+ this.localCollection?.changeInterval(localInterval, toOptionalSequencePlace(startRebased, startSide), toOptionalSequencePlace(endRebased, endSide), undefined, localSeq);
909
+ }
910
+ return rebased;
911
+ }
912
+ getSlideToSegment(lref) {
913
+ if (!this.client) {
914
+ throw new LoggingError("client does not exist");
915
+ }
916
+ const segoff = { segment: lref.getSegment(), offset: lref.getOffset() };
917
+ if (segoff.segment?.localRefs?.has(lref) !== true) {
918
+ return undefined;
919
+ }
920
+ const newSegoff = getSlideToSegoff(segoff, undefined, this.options.mergeTreeReferencesCanSlideToEndpoint);
921
+ const value = segoff.segment === newSegoff.segment && segoff.offset === newSegoff.offset
922
+ ? undefined
923
+ : newSegoff;
924
+ return value;
925
+ }
926
+ ackInterval(interval, op) {
927
+ // Only SequenceIntervals need potential sliding
928
+ if (!(interval instanceof SequenceInterval)) {
929
+ return;
930
+ }
931
+ if (!refTypeIncludesFlag(interval.start, ReferenceType.StayOnRemove) &&
932
+ !refTypeIncludesFlag(interval.end, ReferenceType.StayOnRemove)) {
933
+ return;
934
+ }
935
+ const newStart = this.getSlideToSegment(interval.start);
936
+ const newEnd = this.getSlideToSegment(interval.end);
937
+ const id = interval.properties[reservedIntervalIdKey];
938
+ const hasPendingStartChange = this.hasPendingChangeStart(id);
939
+ const hasPendingEndChange = this.hasPendingChangeEnd(id);
940
+ if (!hasPendingStartChange) {
941
+ setSlideOnRemove(interval.start);
942
+ }
943
+ if (!hasPendingEndChange) {
944
+ setSlideOnRemove(interval.end);
945
+ }
946
+ const needsStartUpdate = newStart !== undefined && !hasPendingStartChange;
947
+ const needsEndUpdate = newEnd !== undefined && !hasPendingEndChange;
948
+ if (needsStartUpdate || needsEndUpdate) {
949
+ if (!this.localCollection) {
950
+ throw new LoggingError("Attach must be called before accessing intervals");
951
+ }
952
+ // `interval`'s endpoints will get modified in-place, so clone it prior to doing so for event emission.
953
+ const oldInterval = interval.clone();
954
+ // In this case, where we change the start or end of an interval,
955
+ // it is necessary to remove and re-add the interval listeners.
956
+ // This ensures that the correct listeners are added to the LocalReferencePosition.
957
+ this.localCollection.removeExistingInterval(interval);
958
+ if (!this.client) {
959
+ throw new LoggingError("client does not exist");
960
+ }
961
+ if (needsStartUpdate) {
962
+ const props = interval.start.properties;
963
+ interval.start = createPositionReferenceFromSegoff(this.client, newStart, interval.start.refType, op, undefined, undefined, startReferenceSlidingPreference(interval.stickiness), startReferenceSlidingPreference(interval.stickiness) ===
964
+ SlidingPreference.BACKWARD);
965
+ if (props) {
966
+ interval.start.addProperties(props);
967
+ }
968
+ const oldSeg = oldInterval.start.getSegment();
969
+ // remove and rebuild start interval as transient for event
970
+ this.client.removeLocalReferencePosition(oldInterval.start);
971
+ oldInterval.start.refType = ReferenceType.Transient;
972
+ oldSeg?.localRefs?.addLocalRef(oldInterval.start, oldInterval.start.getOffset());
973
+ }
974
+ if (needsEndUpdate) {
975
+ const props = interval.end.properties;
976
+ interval.end = createPositionReferenceFromSegoff(this.client, newEnd, interval.end.refType, op, undefined, undefined, endReferenceSlidingPreference(interval.stickiness), endReferenceSlidingPreference(interval.stickiness) ===
977
+ SlidingPreference.FORWARD);
978
+ if (props) {
979
+ interval.end.addProperties(props);
980
+ }
981
+ // remove and rebuild end interval as transient for event
982
+ const oldSeg = oldInterval.end.getSegment();
983
+ this.client.removeLocalReferencePosition(oldInterval.end);
984
+ oldInterval.end.refType = ReferenceType.Transient;
985
+ oldSeg?.localRefs?.addLocalRef(oldInterval.end, oldInterval.end.getOffset());
986
+ }
987
+ this.localCollection.add(interval);
988
+ this.emitChange(interval, oldInterval, true, true, op);
989
+ }
990
+ }
991
+ /** @internal */
992
+ ackAdd(serializedInterval, local, op, localOpMetadata) {
993
+ if (local) {
994
+ assert(localOpMetadata !== undefined, 0x553 /* op metadata should be defined for local op */);
995
+ this.localSeqToSerializedInterval.delete(localOpMetadata.localSeq);
996
+ const id = serializedInterval.properties?.[reservedIntervalIdKey];
997
+ const localInterval = this.getIntervalById(id);
998
+ if (localInterval) {
999
+ this.ackInterval(localInterval, op);
1000
+ }
1001
+ return;
1002
+ }
1003
+ if (!this.localCollection) {
1004
+ throw new LoggingError("attachSequence must be called");
1005
+ }
1006
+ this.localCollection.ensureSerializedId(serializedInterval);
1007
+ const interval = this.localCollection.addInterval(toSequencePlace(serializedInterval.start, serializedInterval.startSide ?? Side.Before), toSequencePlace(serializedInterval.end, serializedInterval.endSide ?? Side.Before), serializedInterval.intervalType, serializedInterval.properties, op);
1008
+ if (interval) {
1009
+ if (this.onDeserialize) {
1010
+ this.onDeserialize(interval);
1011
+ }
1012
+ }
1013
+ this.emit("addInterval", interval, local, op);
1014
+ return interval;
1015
+ }
1016
+ /** @internal */
1017
+ ackDelete(serializedInterval, local, op) {
1018
+ if (local) {
1019
+ // Local ops were applied when the message was created and there's no "pending delete"
1020
+ // state to book keep: remote operation application takes into account possibility of
1021
+ // locally deleted interval whenever a lookup happens.
1022
+ return;
1023
+ }
1024
+ if (!this.localCollection) {
1025
+ throw new LoggingError("attach must be called prior to deleting intervals");
1026
+ }
1027
+ const id = this.localCollection.ensureSerializedId(serializedInterval);
1028
+ const interval = this.localCollection.idIntervalIndex.getIntervalById(id);
1029
+ if (interval) {
1030
+ this.deleteExistingInterval(interval, local, op);
1031
+ }
1032
+ }
1033
+ /**
1034
+ * @internal
1035
+ */
1036
+ serializeInternal() {
1037
+ if (!this.localCollection) {
1038
+ throw new LoggingError("attachSequence must be called");
1039
+ }
1040
+ return this.localCollection.serialize();
1041
+ }
1042
+ /**
1043
+ * @returns an iterator over all intervals in this collection.
1044
+ */
1045
+ [Symbol.iterator]() {
1046
+ const iterator = new IntervalCollectionIterator(this);
1047
+ return iterator;
1048
+ }
1049
+ /**
1050
+ * {@inheritdoc IIntervalCollection.CreateForwardIteratorWithStartPosition}
1051
+ */
1052
+ CreateForwardIteratorWithStartPosition(startPosition) {
1053
+ const iterator = new IntervalCollectionIterator(this, true, startPosition);
1054
+ return iterator;
1055
+ }
1056
+ /**
1057
+ * {@inheritdoc IIntervalCollection.CreateBackwardIteratorWithStartPosition}
1058
+ */
1059
+ CreateBackwardIteratorWithStartPosition(startPosition) {
1060
+ const iterator = new IntervalCollectionIterator(this, false, startPosition);
1061
+ return iterator;
1062
+ }
1063
+ /**
1064
+ * {@inheritdoc IIntervalCollection.CreateForwardIteratorWithEndPosition}
1065
+ */
1066
+ CreateForwardIteratorWithEndPosition(endPosition) {
1067
+ const iterator = new IntervalCollectionIterator(this, true, undefined, endPosition);
1068
+ return iterator;
1069
+ }
1070
+ /**
1071
+ * {@inheritdoc IIntervalCollection.CreateBackwardIteratorWithEndPosition}
1072
+ */
1073
+ CreateBackwardIteratorWithEndPosition(endPosition) {
1074
+ const iterator = new IntervalCollectionIterator(this, false, undefined, endPosition);
1075
+ return iterator;
1076
+ }
1077
+ /**
1078
+ * {@inheritdoc IIntervalCollection.gatherIterationResults}
1079
+ */
1080
+ gatherIterationResults(results, iteratesForward, start, end) {
1081
+ if (!this.localCollection) {
1082
+ return;
1083
+ }
1084
+ this.localCollection.overlappingIntervalsIndex.gatherIterationResults(results, iteratesForward, start, end);
1085
+ }
1086
+ /**
1087
+ * {@inheritdoc IIntervalCollection.findOverlappingIntervals}
1088
+ */
1089
+ findOverlappingIntervals(startPosition, endPosition) {
1090
+ if (!this.localCollection) {
1091
+ throw new LoggingError("attachSequence must be called");
1092
+ }
1093
+ return this.localCollection.overlappingIntervalsIndex.findOverlappingIntervals(startPosition, endPosition);
1094
+ }
1095
+ /**
1096
+ * {@inheritdoc IIntervalCollection.map}
1097
+ */
1098
+ map(fn) {
1099
+ if (!this.localCollection) {
1100
+ throw new LoggingError("attachSequence must be called");
1101
+ }
1102
+ for (const interval of this.localCollection.idIntervalIndex) {
1103
+ fn(interval);
1104
+ }
1105
+ }
1106
+ /**
1107
+ * {@inheritdoc IIntervalCollection.previousInterval}
1108
+ */
1109
+ previousInterval(pos) {
1110
+ if (!this.localCollection) {
1111
+ throw new LoggingError("attachSequence must be called");
1112
+ }
1113
+ return this.localCollection.endIntervalIndex.previousInterval(pos);
1114
+ }
1115
+ /**
1116
+ * {@inheritdoc IIntervalCollection.nextInterval}
1117
+ */
1118
+ nextInterval(pos) {
1119
+ if (!this.localCollection) {
1120
+ throw new LoggingError("attachSequence must be called");
1121
+ }
1122
+ return this.localCollection.endIntervalIndex.nextInterval(pos);
1123
+ }
1124
+ }
1125
+ function setSlideOnRemove(lref) {
1126
+ let refType = lref.refType;
1127
+ refType = refType & ~ReferenceType.StayOnRemove;
1128
+ refType = refType | ReferenceType.SlideOnRemove;
1129
+ lref.refType = refType;
1130
+ }
1131
+ /**
1132
+ * Returns an object that can be used to find the interval a given LocalReferencePosition belongs to.
1133
+ * @returns undefined if the reference position is not the endpoint of any interval (e.g. it was created
1134
+ * on the merge tree directly by app code), otherwise an {@link IntervalLocator} for the interval this
1135
+ * endpoint is a part of.
1136
+ * @internal
1137
+ */
1138
+ export function intervalLocatorFromEndpoint(potentialEndpoint) {
1139
+ const { interval, [reservedRangeLabelsKey]: collectionNameArray } = potentialEndpoint.properties ?? {};
1140
+ return interval && collectionNameArray?.length === 1
1141
+ ? { label: collectionNameArray[0], interval }
1142
+ : undefined;
1143
+ }
1144
+ //# sourceMappingURL=intervalCollection.mjs.map