@fluidframework/merge-tree 2.12.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (307) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/api-report/merge-tree.legacy.alpha.api.md +0 -108
  3. package/dist/MergeTreeTextHelper.d.ts.map +1 -1
  4. package/dist/MergeTreeTextHelper.js +0 -2
  5. package/dist/MergeTreeTextHelper.js.map +1 -1
  6. package/dist/attributionPolicy.d.ts.map +1 -1
  7. package/dist/attributionPolicy.js +6 -16
  8. package/dist/attributionPolicy.js.map +1 -1
  9. package/dist/client.d.ts +3 -4
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/client.js +39 -28
  12. package/dist/client.js.map +1 -1
  13. package/dist/endOfTreeSegment.d.ts +2 -1
  14. package/dist/endOfTreeSegment.d.ts.map +1 -1
  15. package/dist/endOfTreeSegment.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -4
  19. package/dist/index.js.map +1 -1
  20. package/dist/legacy.d.ts +0 -4
  21. package/dist/localReference.d.ts +5 -7
  22. package/dist/localReference.d.ts.map +1 -1
  23. package/dist/localReference.js +1 -3
  24. package/dist/localReference.js.map +1 -1
  25. package/dist/mergeTree.d.ts +8 -7
  26. package/dist/mergeTree.d.ts.map +1 -1
  27. package/dist/mergeTree.js +187 -228
  28. package/dist/mergeTree.js.map +1 -1
  29. package/dist/mergeTreeNodeWalk.d.ts.map +1 -1
  30. package/dist/mergeTreeNodeWalk.js +3 -2
  31. package/dist/mergeTreeNodeWalk.js.map +1 -1
  32. package/dist/mergeTreeNodes.d.ts +65 -325
  33. package/dist/mergeTreeNodes.d.ts.map +1 -1
  34. package/dist/mergeTreeNodes.js +96 -130
  35. package/dist/mergeTreeNodes.js.map +1 -1
  36. package/dist/mergeTreeTracking.d.ts.map +1 -1
  37. package/dist/mergeTreeTracking.js +0 -2
  38. package/dist/mergeTreeTracking.js.map +1 -1
  39. package/dist/opBuilder.d.ts +0 -5
  40. package/dist/opBuilder.d.ts.map +1 -1
  41. package/dist/opBuilder.js +0 -5
  42. package/dist/opBuilder.js.map +1 -1
  43. package/dist/package.json +2 -1
  44. package/dist/partialLengths.d.ts +2 -2
  45. package/dist/partialLengths.d.ts.map +1 -1
  46. package/dist/partialLengths.js +29 -31
  47. package/dist/partialLengths.js.map +1 -1
  48. package/dist/perspective.d.ts +3 -2
  49. package/dist/perspective.d.ts.map +1 -1
  50. package/dist/perspective.js +5 -2
  51. package/dist/perspective.js.map +1 -1
  52. package/dist/referencePositions.d.ts.map +1 -1
  53. package/dist/referencePositions.js +4 -1
  54. package/dist/referencePositions.js.map +1 -1
  55. package/dist/revertibles.d.ts.map +1 -1
  56. package/dist/revertibles.js +10 -14
  57. package/dist/revertibles.js.map +1 -1
  58. package/dist/segmentGroupCollection.d.ts +4 -4
  59. package/dist/segmentGroupCollection.d.ts.map +1 -1
  60. package/dist/segmentGroupCollection.js +0 -6
  61. package/dist/segmentGroupCollection.js.map +1 -1
  62. package/dist/segmentInfos.d.ts +251 -0
  63. package/dist/segmentInfos.d.ts.map +1 -0
  64. package/dist/segmentInfos.js +166 -0
  65. package/dist/segmentInfos.js.map +1 -0
  66. package/dist/snapshotLoader.d.ts.map +1 -1
  67. package/dist/snapshotLoader.js +36 -44
  68. package/dist/snapshotLoader.js.map +1 -1
  69. package/dist/snapshotV1.d.ts.map +1 -1
  70. package/dist/snapshotV1.js +9 -12
  71. package/dist/snapshotV1.js.map +1 -1
  72. package/dist/snapshotlegacy.d.ts +2 -2
  73. package/dist/snapshotlegacy.d.ts.map +1 -1
  74. package/dist/snapshotlegacy.js +5 -3
  75. package/dist/snapshotlegacy.js.map +1 -1
  76. package/dist/sortedSegmentSet.d.ts.map +1 -1
  77. package/dist/sortedSegmentSet.js +5 -8
  78. package/dist/sortedSegmentSet.js.map +1 -1
  79. package/dist/test/beastTest.spec.d.ts +0 -2
  80. package/dist/test/beastTest.spec.d.ts.map +1 -1
  81. package/dist/test/beastTest.spec.js +1 -5
  82. package/dist/test/beastTest.spec.js.map +1 -1
  83. package/dist/test/client.annotateMarker.spec.js.map +1 -1
  84. package/dist/test/client.applyMsg.spec.js +15 -12
  85. package/dist/test/client.applyMsg.spec.js.map +1 -1
  86. package/dist/test/client.attributionFarm.spec.js.map +1 -1
  87. package/dist/test/client.getPosition.spec.js +3 -2
  88. package/dist/test/client.getPosition.spec.js.map +1 -1
  89. package/dist/test/client.localReference.spec.js +6 -6
  90. package/dist/test/client.localReference.spec.js.map +1 -1
  91. package/dist/test/client.localReferenceFarm.spec.js.map +1 -1
  92. package/dist/test/client.rollback.spec.js.map +1 -1
  93. package/dist/test/dirname.cjs +0 -1
  94. package/dist/test/dirname.cjs.map +1 -1
  95. package/dist/test/index.d.ts +1 -1
  96. package/dist/test/index.d.ts.map +1 -1
  97. package/dist/test/index.js +2 -4
  98. package/dist/test/index.js.map +1 -1
  99. package/dist/test/mergeTree.annotate.spec.js +3 -0
  100. package/dist/test/mergeTree.annotate.spec.js.map +1 -1
  101. package/dist/test/mergeTree.insertingWalk.spec.js +1 -1
  102. package/dist/test/mergeTree.insertingWalk.spec.js.map +1 -1
  103. package/dist/test/mergeTree.markRangeRemoved.spec.js +2 -0
  104. package/dist/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
  105. package/dist/test/mergeTree.walk.spec.js.map +1 -1
  106. package/dist/test/mergeTreeOperationRunner.d.ts.map +1 -1
  107. package/dist/test/mergeTreeOperationRunner.js +2 -3
  108. package/dist/test/mergeTreeOperationRunner.js.map +1 -1
  109. package/dist/test/obliterate.spec.js.map +1 -1
  110. package/dist/test/propertyManager.spec.js.map +1 -1
  111. package/dist/test/reconnectHelper.d.ts +2 -1
  112. package/dist/test/reconnectHelper.d.ts.map +1 -1
  113. package/dist/test/reconnectHelper.js.map +1 -1
  114. package/dist/test/resetPendingSegmentsToOp.spec.js.map +1 -1
  115. package/dist/test/revertibleFarm.spec.js.map +1 -1
  116. package/dist/test/segmentGroupCollection.spec.js +15 -3
  117. package/dist/test/segmentGroupCollection.spec.js.map +1 -1
  118. package/dist/test/snapshot.utils.d.ts +2 -2
  119. package/dist/test/snapshot.utils.d.ts.map +1 -1
  120. package/dist/test/snapshot.utils.js.map +1 -1
  121. package/dist/test/sortedSegmentSet.spec.js +4 -3
  122. package/dist/test/sortedSegmentSet.spec.js.map +1 -1
  123. package/dist/test/testClient.d.ts +8 -6
  124. package/dist/test/testClient.d.ts.map +1 -1
  125. package/dist/test/testClient.js +28 -27
  126. package/dist/test/testClient.js.map +1 -1
  127. package/dist/test/testClientLogger.d.ts.map +1 -1
  128. package/dist/test/testClientLogger.js +6 -4
  129. package/dist/test/testClientLogger.js.map +1 -1
  130. package/dist/test/testUtils.d.ts +2 -2
  131. package/dist/test/testUtils.d.ts.map +1 -1
  132. package/dist/test/testUtils.js +32 -8
  133. package/dist/test/testUtils.js.map +1 -1
  134. package/dist/test/text.d.ts +2 -2
  135. package/dist/test/text.d.ts.map +1 -1
  136. package/dist/test/text.js +12 -6
  137. package/dist/test/text.js.map +1 -1
  138. package/dist/test/tracking.spec.js.map +1 -1
  139. package/dist/test/wordUnitTests.spec.js +1 -1
  140. package/dist/test/wordUnitTests.spec.js.map +1 -1
  141. package/dist/zamboni.d.ts.map +1 -1
  142. package/dist/zamboni.js +8 -7
  143. package/dist/zamboni.js.map +1 -1
  144. package/lib/MergeTreeTextHelper.d.ts.map +1 -1
  145. package/lib/MergeTreeTextHelper.js +0 -2
  146. package/lib/MergeTreeTextHelper.js.map +1 -1
  147. package/lib/attributionPolicy.d.ts.map +1 -1
  148. package/lib/attributionPolicy.js +6 -16
  149. package/lib/attributionPolicy.js.map +1 -1
  150. package/lib/client.d.ts +3 -4
  151. package/lib/client.d.ts.map +1 -1
  152. package/lib/client.js +40 -29
  153. package/lib/client.js.map +1 -1
  154. package/lib/endOfTreeSegment.d.ts +2 -1
  155. package/lib/endOfTreeSegment.d.ts.map +1 -1
  156. package/lib/endOfTreeSegment.js.map +1 -1
  157. package/lib/index.d.ts +1 -1
  158. package/lib/index.d.ts.map +1 -1
  159. package/lib/index.js +1 -1
  160. package/lib/index.js.map +1 -1
  161. package/lib/legacy.d.ts +0 -4
  162. package/lib/localReference.d.ts +5 -7
  163. package/lib/localReference.d.ts.map +1 -1
  164. package/lib/localReference.js +1 -3
  165. package/lib/localReference.js.map +1 -1
  166. package/lib/mergeTree.d.ts +8 -7
  167. package/lib/mergeTree.d.ts.map +1 -1
  168. package/lib/mergeTree.js +175 -220
  169. package/lib/mergeTree.js.map +1 -1
  170. package/lib/mergeTreeNodeWalk.d.ts.map +1 -1
  171. package/lib/mergeTreeNodeWalk.js +3 -2
  172. package/lib/mergeTreeNodeWalk.js.map +1 -1
  173. package/lib/mergeTreeNodes.d.ts +65 -325
  174. package/lib/mergeTreeNodes.d.ts.map +1 -1
  175. package/lib/mergeTreeNodes.js +92 -127
  176. package/lib/mergeTreeNodes.js.map +1 -1
  177. package/lib/mergeTreeTracking.d.ts.map +1 -1
  178. package/lib/mergeTreeTracking.js +0 -2
  179. package/lib/mergeTreeTracking.js.map +1 -1
  180. package/lib/opBuilder.d.ts +0 -5
  181. package/lib/opBuilder.d.ts.map +1 -1
  182. package/lib/opBuilder.js +0 -5
  183. package/lib/opBuilder.js.map +1 -1
  184. package/lib/partialLengths.d.ts +2 -2
  185. package/lib/partialLengths.d.ts.map +1 -1
  186. package/lib/partialLengths.js +26 -28
  187. package/lib/partialLengths.js.map +1 -1
  188. package/lib/perspective.d.ts +3 -2
  189. package/lib/perspective.d.ts.map +1 -1
  190. package/lib/perspective.js +5 -2
  191. package/lib/perspective.js.map +1 -1
  192. package/lib/referencePositions.d.ts.map +1 -1
  193. package/lib/referencePositions.js +4 -1
  194. package/lib/referencePositions.js.map +1 -1
  195. package/lib/revertibles.d.ts.map +1 -1
  196. package/lib/revertibles.js +8 -12
  197. package/lib/revertibles.js.map +1 -1
  198. package/lib/segmentGroupCollection.d.ts +4 -4
  199. package/lib/segmentGroupCollection.d.ts.map +1 -1
  200. package/lib/segmentGroupCollection.js +0 -6
  201. package/lib/segmentGroupCollection.js.map +1 -1
  202. package/lib/segmentInfos.d.ts +251 -0
  203. package/lib/segmentInfos.d.ts.map +1 -0
  204. package/lib/segmentInfos.js +145 -0
  205. package/lib/segmentInfos.js.map +1 -0
  206. package/lib/snapshotLoader.d.ts.map +1 -1
  207. package/lib/snapshotLoader.js +36 -44
  208. package/lib/snapshotLoader.js.map +1 -1
  209. package/lib/snapshotV1.d.ts.map +1 -1
  210. package/lib/snapshotV1.js +9 -12
  211. package/lib/snapshotV1.js.map +1 -1
  212. package/lib/snapshotlegacy.d.ts +2 -2
  213. package/lib/snapshotlegacy.d.ts.map +1 -1
  214. package/lib/snapshotlegacy.js +5 -3
  215. package/lib/snapshotlegacy.js.map +1 -1
  216. package/lib/sortedSegmentSet.d.ts.map +1 -1
  217. package/lib/sortedSegmentSet.js +5 -8
  218. package/lib/sortedSegmentSet.js.map +1 -1
  219. package/lib/test/beastTest.spec.d.ts +0 -2
  220. package/lib/test/beastTest.spec.d.ts.map +1 -1
  221. package/lib/test/beastTest.spec.js +0 -3
  222. package/lib/test/beastTest.spec.js.map +1 -1
  223. package/lib/test/client.annotateMarker.spec.js.map +1 -1
  224. package/lib/test/client.applyMsg.spec.js +15 -12
  225. package/lib/test/client.applyMsg.spec.js.map +1 -1
  226. package/lib/test/client.attributionFarm.spec.js.map +1 -1
  227. package/lib/test/client.getPosition.spec.js +3 -2
  228. package/lib/test/client.getPosition.spec.js.map +1 -1
  229. package/lib/test/client.localReference.spec.js +1 -1
  230. package/lib/test/client.localReference.spec.js.map +1 -1
  231. package/lib/test/client.localReferenceFarm.spec.js.map +1 -1
  232. package/lib/test/client.rollback.spec.js +1 -1
  233. package/lib/test/client.rollback.spec.js.map +1 -1
  234. package/lib/test/dirname.cjs +0 -1
  235. package/lib/test/dirname.cjs.map +1 -1
  236. package/lib/test/index.d.ts +1 -1
  237. package/lib/test/index.d.ts.map +1 -1
  238. package/lib/test/index.js +1 -1
  239. package/lib/test/index.js.map +1 -1
  240. package/lib/test/mergeTree.annotate.spec.js +3 -0
  241. package/lib/test/mergeTree.annotate.spec.js.map +1 -1
  242. package/lib/test/mergeTree.insertingWalk.spec.js +2 -2
  243. package/lib/test/mergeTree.insertingWalk.spec.js.map +1 -1
  244. package/lib/test/mergeTree.markRangeRemoved.spec.js +2 -0
  245. package/lib/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
  246. package/lib/test/mergeTree.walk.spec.js.map +1 -1
  247. package/lib/test/mergeTreeOperationRunner.d.ts.map +1 -1
  248. package/lib/test/mergeTreeOperationRunner.js +1 -2
  249. package/lib/test/mergeTreeOperationRunner.js.map +1 -1
  250. package/lib/test/obliterate.spec.js.map +1 -1
  251. package/lib/test/propertyManager.spec.js.map +1 -1
  252. package/lib/test/reconnectHelper.d.ts +2 -1
  253. package/lib/test/reconnectHelper.d.ts.map +1 -1
  254. package/lib/test/reconnectHelper.js.map +1 -1
  255. package/lib/test/resetPendingSegmentsToOp.spec.js.map +1 -1
  256. package/lib/test/revertibleFarm.spec.js.map +1 -1
  257. package/lib/test/segmentGroupCollection.spec.js +15 -3
  258. package/lib/test/segmentGroupCollection.spec.js.map +1 -1
  259. package/lib/test/snapshot.utils.d.ts +2 -2
  260. package/lib/test/snapshot.utils.d.ts.map +1 -1
  261. package/lib/test/snapshot.utils.js.map +1 -1
  262. package/lib/test/sortedSegmentSet.spec.js +4 -3
  263. package/lib/test/sortedSegmentSet.spec.js.map +1 -1
  264. package/lib/test/testClient.d.ts +8 -6
  265. package/lib/test/testClient.d.ts.map +1 -1
  266. package/lib/test/testClient.js +29 -28
  267. package/lib/test/testClient.js.map +1 -1
  268. package/lib/test/testClientLogger.d.ts.map +1 -1
  269. package/lib/test/testClientLogger.js +5 -3
  270. package/lib/test/testClientLogger.js.map +1 -1
  271. package/lib/test/testUtils.d.ts +2 -2
  272. package/lib/test/testUtils.d.ts.map +1 -1
  273. package/lib/test/testUtils.js +9 -8
  274. package/lib/test/testUtils.js.map +1 -1
  275. package/lib/test/text.d.ts +2 -2
  276. package/lib/test/text.d.ts.map +1 -1
  277. package/lib/test/text.js +12 -6
  278. package/lib/test/text.js.map +1 -1
  279. package/lib/test/tracking.spec.js.map +1 -1
  280. package/lib/test/wordUnitTests.spec.js +1 -1
  281. package/lib/test/wordUnitTests.spec.js.map +1 -1
  282. package/lib/zamboni.d.ts.map +1 -1
  283. package/lib/zamboni.js +7 -6
  284. package/lib/zamboni.js.map +1 -1
  285. package/package.json +77 -19
  286. package/src/MergeTreeTextHelper.ts +2 -4
  287. package/src/attributionPolicy.ts +5 -13
  288. package/src/client.ts +55 -44
  289. package/src/endOfTreeSegment.ts +3 -5
  290. package/src/index.ts +0 -7
  291. package/src/localReference.ts +6 -8
  292. package/src/mergeTree.ts +233 -290
  293. package/src/mergeTreeNodeWalk.ts +3 -2
  294. package/src/mergeTreeNodes.ts +160 -490
  295. package/src/mergeTreeTracking.ts +0 -3
  296. package/src/opBuilder.ts +0 -5
  297. package/src/partialLengths.ts +40 -29
  298. package/src/perspective.ts +23 -4
  299. package/src/referencePositions.ts +4 -1
  300. package/src/revertibles.ts +19 -16
  301. package/src/segmentGroupCollection.ts +7 -18
  302. package/src/segmentInfos.ts +371 -0
  303. package/src/snapshotLoader.ts +56 -57
  304. package/src/snapshotV1.ts +14 -16
  305. package/src/snapshotlegacy.ts +12 -17
  306. package/src/sortedSegmentSet.ts +6 -8
  307. package/src/zamboni.ts +10 -12
@@ -0,0 +1,166 @@
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.overwriteInfo = exports.assertMoved = exports.isMoved = exports.toMoveInfo = exports.removeRemovalInfo = exports.assertRemoved = exports.isRemoved = exports.toRemovalInfo = exports.removeMergeNodeInfo = exports.assertMergeNode = exports.isMergeNodeInfo = exports.toMergeNodeInfo = exports.assertInserted = exports.isInserted = exports.toInsertionInfo = exports.propInstanceOf = exports.hasProp = exports.propExists = void 0;
8
+ const internal_1 = require("@fluidframework/core-utils/internal");
9
+ const mergeTreeNodes_js_1 = require("./mergeTreeNodes.js");
10
+ function propExists(thing, prop) {
11
+ return (0, internal_1.isObject)(thing) && prop in thing;
12
+ }
13
+ exports.propExists = propExists;
14
+ function hasProp(thing, prop, type) {
15
+ return (propExists(thing, prop) &&
16
+ (type === "array" ? Array.isArray(thing[prop]) : typeof thing[prop] === type));
17
+ }
18
+ exports.hasProp = hasProp;
19
+ function propInstanceOf(thing, prop, type) {
20
+ return propExists(thing, prop) && thing[prop] instanceof type;
21
+ }
22
+ exports.propInstanceOf = propInstanceOf;
23
+ /**
24
+ * Converts a segment-like object to an insertion info object if possible.
25
+ *
26
+ * @param segmentLike - The segment-like object to convert.
27
+ * @returns The insertion info object if the conversion is possible, otherwise undefined.
28
+ */
29
+ const toInsertionInfo = (segmentLike) => hasProp(segmentLike, "clientId", "number") && hasProp(segmentLike, "seq", "number")
30
+ ? segmentLike
31
+ : undefined;
32
+ exports.toInsertionInfo = toInsertionInfo;
33
+ /**
34
+ * A type-guard which determines if the segment has insertion info, and
35
+ * returns true if it does, along with applying strong typing.
36
+ *
37
+ * @param segmentLike - The segment-like object to check.
38
+ * @returns True if the segment has insertion info, otherwise false.
39
+ */
40
+ const isInserted = (segmentLike) => (0, exports.toInsertionInfo)(segmentLike) !== undefined;
41
+ exports.isInserted = isInserted;
42
+ /**
43
+ * Asserts that the segment has insertion info. Usage of this function should not produce a user facing error.
44
+ *
45
+ * @param segmentLike - The segment-like object to check.
46
+ * @throws Will throw an error if the segment does not have insertion info.
47
+ */
48
+ const assertInserted = (segmentLike) => (0, internal_1.assert)(segmentLike === undefined || (0, exports.isInserted)(segmentLike), 0xaa0 /* must be insertionInfo */);
49
+ exports.assertInserted = assertInserted;
50
+ /**
51
+ * Converts a segment-like object to a merge node info object if possible.
52
+ *
53
+ * @param segmentLike - The segment-like object to convert.
54
+ * @returns The merge node info object if the conversion is possible, otherwise undefined.
55
+ */
56
+ const toMergeNodeInfo = (nodeLike) => propInstanceOf(nodeLike, "parent", mergeTreeNodes_js_1.MergeBlock) &&
57
+ hasProp(nodeLike, "ordinal", "string") &&
58
+ hasProp(nodeLike, "index", "number")
59
+ ? nodeLike
60
+ : undefined;
61
+ exports.toMergeNodeInfo = toMergeNodeInfo;
62
+ /**
63
+ * A type-guard which determines if the segment has merge node info, and
64
+ * returns true if it does, along with applying strong typing.
65
+ *
66
+ * @param nodeLike - The segment-like object to check.
67
+ * @returns True if the segment has merge node info, otherwise false.
68
+ */
69
+ const isMergeNodeInfo = (nodeLike) => (0, exports.toMergeNodeInfo)(nodeLike) !== undefined;
70
+ exports.isMergeNodeInfo = isMergeNodeInfo;
71
+ /**
72
+ * Asserts that the segment has merge node info. Usage of this function should not produce a user facing error.
73
+ *
74
+ * @param segmentLike - The segment-like object to check.
75
+ * @throws Will throw an error if the segment does not have merge node info.
76
+ */
77
+ const assertMergeNode = (segmentLike) => (0, internal_1.assert)(segmentLike === undefined || (0, exports.isMergeNodeInfo)(segmentLike), 0xaa1 /* must be MergeNodeInfo */);
78
+ exports.assertMergeNode = assertMergeNode;
79
+ /**
80
+ * Removes the merge node info. This is used to remove nodes from the merge-tree.
81
+ * @param segmentLike - The segment-like object to check.
82
+ * @returns This function will change the type of the provided node like to never via an assertion. This
83
+ * ensures no further usage of the removed merge node info is allowed. if continued use is required other
84
+ * type coercion methods should be used to correctly re-type the variable.
85
+ */
86
+ const removeMergeNodeInfo = (nodeLike) => Object.assign(nodeLike, {
87
+ parent: undefined,
88
+ index: undefined,
89
+ ordinal: undefined,
90
+ });
91
+ exports.removeMergeNodeInfo = removeMergeNodeInfo;
92
+ /**
93
+ * Converts a segment-like object to a removal info object if possible.
94
+ *
95
+ * @param segmentLike - The segment-like object to convert.
96
+ * @returns The removal info object if the conversion is possible, otherwise undefined.
97
+ */
98
+ const toRemovalInfo = (segmentLike) => hasProp(segmentLike, "removedClientIds", "array") &&
99
+ hasProp(segmentLike, "removedSeq", "number")
100
+ ? segmentLike
101
+ : undefined;
102
+ exports.toRemovalInfo = toRemovalInfo;
103
+ /**
104
+ * A type-guard which determines if the segment has removal info, and
105
+ * returns true if it does, along with applying strong typing.
106
+ *
107
+ * @param segmentLike - The segment-like object to check.
108
+ * @returns True if the segment has removal info, otherwise false.
109
+ */
110
+ const isRemoved = (segmentLike) => (0, exports.toRemovalInfo)(segmentLike) !== undefined;
111
+ exports.isRemoved = isRemoved;
112
+ /**
113
+ * Asserts that the segment has removal info. Usage of this function should not produce a user facing error.
114
+ *
115
+ * @param segmentLike - The segment-like object to check.
116
+ * @throws Will throw an error if the segment does not have removal info.
117
+ */
118
+ const assertRemoved = (segmentLike) => (0, internal_1.assert)(segmentLike === undefined || (0, exports.isRemoved)(segmentLike), 0xaa2 /* must be removalInfo */);
119
+ exports.assertRemoved = assertRemoved;
120
+ /**
121
+ * Removes the removal info. This is used in rollback.
122
+ * @param segmentLike - The segment-like object to check.
123
+ * @returns This function will change the type of the provided node like to never via an assertion. This
124
+ * ensures no further usage of the removed removal info is allowed. if continued use is required other
125
+ * type coercion methods should be use to correctly re-type the variable.
126
+ */
127
+ const removeRemovalInfo = (nodeLike) => Object.assign(nodeLike, {
128
+ localRemovedSeq: undefined,
129
+ removedClientIds: undefined,
130
+ removedSeq: undefined,
131
+ });
132
+ exports.removeRemovalInfo = removeRemovalInfo;
133
+ const toMoveInfo = (segmentLike) => hasProp(segmentLike, "movedClientIds", "array") &&
134
+ hasProp(segmentLike, "movedSeq", "number") &&
135
+ hasProp(segmentLike, "movedSeqs", "array") &&
136
+ hasProp(segmentLike, "wasMovedOnInsert", "boolean")
137
+ ? segmentLike
138
+ : undefined;
139
+ exports.toMoveInfo = toMoveInfo;
140
+ /**
141
+ * A type-guard which determines if the segment has move info, and
142
+ * returns true if it does, along with applying strong typing.
143
+ *
144
+ * @param segmentLike - The segment-like object to check.
145
+ * @returns True if the segment has move info, otherwise false.
146
+ */
147
+ const isMoved = (segmentLike) => (0, exports.toMoveInfo)(segmentLike) !== undefined;
148
+ exports.isMoved = isMoved;
149
+ /**
150
+ * Asserts that the segment has move info. Usage of this function should not produce a user facing error.
151
+ *
152
+ * @param segmentLike - The segment-like object to check.
153
+ * @throws Will throw an error if the segment does not have move info.
154
+ */
155
+ const assertMoved = (segmentLike) => (0, internal_1.assert)(segmentLike === undefined || (0, exports.isMoved)(segmentLike), 0xaa3 /* must be moveInfo */);
156
+ exports.assertMoved = assertMoved;
157
+ /**
158
+ * Overwrites the segment info on a segment-like object.
159
+ *
160
+ * @param segmentLike - The segment-like object to set the info on.
161
+ * @param info - The segment info to overwrite.
162
+ * @returns The segment-like object with the info set.
163
+ */
164
+ const overwriteInfo = (segmentLike, info) => Object.assign(segmentLike, info);
165
+ exports.overwriteInfo = overwriteInfo;
166
+ //# sourceMappingURL=segmentInfos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segmentInfos.js","sourceRoot":"","sources":["../src/segmentInfos.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAuE;AAEvE,2DAAoF;AAWpF,SAAgB,UAAU,CACzB,KAAc,EACd,IAAO;IAEP,OAAO,IAAA,mBAAQ,EAAC,KAAK,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC;AACzC,CAAC;AALD,gCAKC;AAED,SAAgB,OAAO,CACtB,KAAc,EACd,IAAO,EACP,IAAO;IAEP,OAAO,CACN,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;QACvB,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAC7E,CAAC;AACH,CAAC;AATD,0BASC;AAED,SAAgB,cA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E,SAAS;IAC3B,UAAU,EAAE,SAAS;CACrB,CAAC,CAAC;AAPS,QAAA,iBAAiB,qBAO1B;AAkEG,MAAM,UAAU,GAAG,CAAC,WAAoB,EAAyB,EAAE,CACzE,OAAO,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,CAAC;IAC/C,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,QAAQ,CAAC;IAC1C,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC;IAC1C,OAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,SAAS,CAAC;IAClD,CAAC,CAAC,WAAW;IACb,CAAC,CAAC,SAAS,CAAC;AAND,QAAA,UAAU,cAMT;AAEd;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAC,WAAoB,EAA4B,EAAE,CACzE,IAAA,kBAAU,EAAC,WAAW,CAAC,KAAK,SAAS,CAAC;AAD1B,QAAA,OAAO,WACmB;AAEvC;;;;;GAKG;AACI,MAAM,WAAW,GAEiD,CAAC,WAAW,EAAE,EAAE,CACxF,IAAA,iBAAM,EAAC,WAAW,KAAK,SAAS,IAAI,IAAA,eAAO,EAAC,WAAW,CAAC,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAH5E,QAAA,WAAW,eAGiE;AAezF;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,CAI5B,WAAc,EACd,IAAO,EACiB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AANhD,QAAA,aAAa,iBAMmC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, isObject } from \"@fluidframework/core-utils/internal\";\n\nimport { ISegmentInternal, ISegmentPrivate, MergeBlock } from \"./mergeTreeNodes.js\";\nimport type { ReferencePosition } from \"./referencePositions.js\";\n\nexport interface StringToType {\n\t\"string\": string;\n\t\"number\": number;\n\t\"object\": object;\n\t\"array\": [];\n\t\"boolean\": boolean;\n}\n\nexport function propExists<P extends string>(\n\tthing: unknown,\n\tprop: P,\n): thing is Record<P, unknown> {\n\treturn isObject(thing) && prop in thing;\n}\n\nexport function hasProp<P extends string, T extends keyof StringToType>(\n\tthing: unknown,\n\tprop: P,\n\ttype: T,\n): thing is Record<P, StringToType[typeof type]> {\n\treturn (\n\t\tpropExists(thing, prop) &&\n\t\t(type === \"array\" ? Array.isArray(thing[prop]) : typeof thing[prop] === type)\n\t);\n}\n\nexport function propInstanceOf<P extends string, T>(\n\tthing: unknown,\n\tprop: P,\n\ttype: new (...args: any[]) => T,\n): thing is Record<P, T> {\n\treturn propExists(thing, prop) && thing[prop] instanceof type;\n}\n\n/**\n * Contains insertion information associated to an {@link ISegment}.\n */\nexport interface IInsertionInfo {\n\t/**\n\t * Short clientId for the client that inserted this segment.\n\t */\n\tclientId: number;\n\t/**\n\t * Local seq at which this segment was inserted.\n\t * This is defined if and only if the insertion of the segment is pending ack, i.e. `seq` is UnassignedSequenceNumber.\n\t * Once the segment is acked, this field is cleared.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\tlocalSeq?: number;\n\t/**\n\t * Seq at which this segment was inserted.\n\t * If undefined, it is assumed the segment was inserted prior to the collab window's minimum sequence number.\n\t */\n\tseq: number;\n}\n\n/**\n * Converts a segment-like object to an insertion info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The insertion info object if the conversion is possible, otherwise undefined.\n */\nexport const toInsertionInfo = (segmentLike: unknown): IInsertionInfo | undefined =>\n\thasProp(segmentLike, \"clientId\", \"number\") && hasProp(segmentLike, \"seq\", \"number\")\n\t\t? segmentLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has insertion info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has insertion info, otherwise false.\n */\nexport const isInserted = (segmentLike: unknown): segmentLike is IInsertionInfo =>\n\ttoInsertionInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has insertion info. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment does not have insertion info.\n */\nexport const assertInserted: <T extends Partial<IInsertionInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IInsertionInfo> | T,\n) => asserts segmentLike is IInsertionInfo | Exclude<T, Partial<IInsertionInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(\n\t\tsegmentLike === undefined || isInserted(segmentLike),\n\t\t0xaa0 /* must be insertionInfo */,\n\t);\n\n/**\n * Common properties for a node in a merge tree.\n */\nexport interface IMergeNodeInfo {\n\t/**\n\t * The parent merge block if the node is parented\n\t */\n\tparent: MergeBlock;\n\n\t/**\n\t * The index of this node in its parent's list of children.\n\t */\n\tindex: number;\n\n\t/**\n\t * A string that can be used for comparing the location of this node to other `MergeNode`s in the same tree.\n\t * `a.ordinal < b.ordinal` if and only if `a` comes before `b` in a pre-order traversal of the tree.\n\t */\n\tordinal: string;\n}\n\n/**\n * Converts a segment-like object to a merge node info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The merge node info object if the conversion is possible, otherwise undefined.\n */\nexport const toMergeNodeInfo = (nodeLike: unknown): IMergeNodeInfo | undefined =>\n\tpropInstanceOf(nodeLike, \"parent\", MergeBlock) &&\n\thasProp(nodeLike, \"ordinal\", \"string\") &&\n\thasProp(nodeLike, \"index\", \"number\")\n\t\t? nodeLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has merge node info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment has merge node info, otherwise false.\n */\nexport const isMergeNodeInfo = (nodeLike: unknown): nodeLike is IMergeNodeInfo =>\n\ttoMergeNodeInfo(nodeLike) !== undefined;\n\n/**\n * Asserts that the segment has merge node info. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment does not have merge node info.\n */\nexport const assertMergeNode: <T extends Partial<IMergeNodeInfo> | undefined>(\n\tnodeLike: ISegmentInternal | ISegmentPrivate | Partial<IMergeNodeInfo> | T,\n) => asserts nodeLike is IMergeNodeInfo | Exclude<T, Partial<IMergeNodeInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(\n\t\tsegmentLike === undefined || isMergeNodeInfo(segmentLike),\n\t\t0xaa1 /* must be MergeNodeInfo */,\n\t);\n\n/**\n * Removes the merge node info. This is used to remove nodes from the merge-tree.\n * @param segmentLike - The segment-like object to check.\n * @returns This function will change the type of the provided node like to never via an assertion. This\n * ensures no further usage of the removed merge node info is allowed. if continued use is required other\n * type coercion methods should be used to correctly re-type the variable.\n */\nexport const removeMergeNodeInfo: (nodeLike: IMergeNodeInfo) => asserts nodeLike is never = (\n\tnodeLike,\n) =>\n\tObject.assign<IMergeNodeInfo, Record<keyof IMergeNodeInfo, undefined>>(nodeLike, {\n\t\tparent: undefined,\n\t\tindex: undefined,\n\t\tordinal: undefined,\n\t});\n\n/**\n * Contains removal information associated to an {@link ISegment}.\n */\nexport interface IRemovalInfo {\n\t/**\n\t * Local seq at which this segment was removed, if the removal is yet-to-be acked.\n\t */\n\tlocalRemovedSeq?: number;\n\t/**\n\t * Seq at which this segment was removed.\n\t */\n\tremovedSeq: number;\n\t/**\n\t * List of client IDs that have removed this segment.\n\t * The client that actually removed the segment (i.e. whose removal op was sequenced first) is stored as the first\n\t * client in this list. Other clients in the list have all issued concurrent ops to remove the segment.\n\t * @remarks When this list has length \\> 1, this is referred to as the \"overlapping remove\" case.\n\t */\n\tremovedClientIds: number[];\n}\n\n/**\n * Converts a segment-like object to a removal info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The removal info object if the conversion is possible, otherwise undefined.\n */\nexport const toRemovalInfo = (segmentLike: unknown): IRemovalInfo | undefined =>\n\thasProp(segmentLike, \"removedClientIds\", \"array\") &&\n\thasProp(segmentLike, \"removedSeq\", \"number\")\n\t\t? segmentLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has removal info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has removal info, otherwise false.\n */\nexport const isRemoved = (segmentLike: unknown): segmentLike is IRemovalInfo =>\n\ttoRemovalInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has removal info. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment does not have removal info.\n */\nexport const assertRemoved: <T extends Partial<IRemovalInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IRemovalInfo> | T,\n) => asserts segmentLike is IRemovalInfo | Exclude<T, Partial<IRemovalInfo>> = (segmentLike) =>\n\tassert(segmentLike === undefined || isRemoved(segmentLike), 0xaa2 /* must be removalInfo */);\n\n/**\n * Removes the removal info. This is used in rollback.\n * @param segmentLike - The segment-like object to check.\n * @returns This function will change the type of the provided node like to never via an assertion. This\n * ensures no further usage of the removed removal info is allowed. if continued use is required other\n * type coercion methods should be use to correctly re-type the variable.\n */\nexport const removeRemovalInfo: (nodeLike: IRemovalInfo) => asserts nodeLike is never = (\n\tnodeLike,\n) =>\n\tObject.assign<IRemovalInfo, Record<keyof IRemovalInfo, undefined>>(nodeLike, {\n\t\tlocalRemovedSeq: undefined,\n\t\tremovedClientIds: undefined,\n\t\tremovedSeq: undefined,\n\t});\n\n/**\n * Tracks information about when and where this segment was moved to.\n *\n * Note that merge-tree does not currently support moving and only supports\n * obliterate. The fields below include \"move\" in their names to avoid renaming\n * in the future, when moves _are_ supported.\n */\nexport interface IMoveInfo {\n\t/**\n\t * Local seq at which this segment was moved if the move is yet-to-be\n\t * acked.\n\t */\n\tlocalMovedSeq?: number;\n\n\t/**\n\t * The first seq at which this segment was moved.\n\t */\n\tmovedSeq: number;\n\n\t/**\n\t * All seqs at which this segment was moved. In the case of overlapping,\n\t * concurrent moves this array will contain multiple seqs.\n\t *\n\t * The seq at `movedSeqs[i]` corresponds to the client id at `movedClientIds[i]`.\n\t *\n\t * The first element corresponds to the seq of the first move\n\t */\n\tmovedSeqs: number[];\n\n\t/**\n\t * A reference to the inserted destination segment corresponding to this\n\t * segment's move.\n\t *\n\t * If undefined, the move was an obliterate.\n\t *\n\t * Currently this field is unused, as we only support obliterate operations\n\t */\n\tmoveDst?: ReferencePosition;\n\n\t/**\n\t * List of client IDs that have moved this segment.\n\t *\n\t * The client that actually moved the segment (i.e. whose move op was sequenced\n\t * first) is stored as the first client in this list. Other clients in the\n\t * list have all issued concurrent ops to move the segment.\n\t */\n\tmovedClientIds: number[];\n\n\t/**\n\t * If this segment was inserted into a concurrently moved range and\n\t * the move op was sequenced before the insertion op. In this case,\n\t * the segment is visible only to the inserting client\n\t *\n\t * `wasMovedOnInsert` only applies for acked obliterates. That is, if\n\t * a segment inserted by a remote client is moved on insertion by a local\n\t * and unacked obliterate, we do not consider it as having been moved\n\t * on insert\n\t *\n\t * If a segment is moved on insertion, its length is only ever visible to\n\t * the client that inserted the segment. This is relevant in partial length\n\t * calculations\n\t */\n\twasMovedOnInsert: boolean;\n}\nexport const toMoveInfo = (segmentLike: unknown): IMoveInfo | undefined =>\n\thasProp(segmentLike, \"movedClientIds\", \"array\") &&\n\thasProp(segmentLike, \"movedSeq\", \"number\") &&\n\thasProp(segmentLike, \"movedSeqs\", \"array\") &&\n\thasProp(segmentLike, \"wasMovedOnInsert\", \"boolean\")\n\t\t? segmentLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has move info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has move info, otherwise false.\n */\nexport const isMoved = (segmentLike: unknown): segmentLike is IMoveInfo =>\n\ttoMoveInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has move info. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment does not have move info.\n */\nexport const assertMoved: <T extends Partial<IMoveInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IMoveInfo> | T,\n) => asserts segmentLike is IMoveInfo | Exclude<T, Partial<IMoveInfo>> = (segmentLike) =>\n\tassert(segmentLike === undefined || isMoved(segmentLike), 0xaa3 /* must be moveInfo */);\n\n/**\n * A union type representing any segment info.\n */\nexport type SegmentInfo = IMergeNodeInfo | IInsertionInfo | IMoveInfo | IRemovalInfo;\n\n/**\n * A type representing a segment with additional info.\n */\nexport type SegmentWithInfo<\n\tT extends SegmentInfo,\n\tS extends ISegmentPrivate = ISegmentPrivate,\n> = S & T;\n\n/**\n * Overwrites the segment info on a segment-like object.\n *\n * @param segmentLike - The segment-like object to set the info on.\n * @param info - The segment info to overwrite.\n * @returns The segment-like object with the info set.\n */\nexport const overwriteInfo = <\n\tT extends SegmentInfo,\n\tS extends ISegmentPrivate = ISegmentPrivate,\n>(\n\tsegmentLike: S,\n\tinfo: T,\n): SegmentWithInfo<T, S> => Object.assign(segmentLike, info);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotLoader.d.ts","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EACN,mBAAmB,EAGnB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAW3C,qBAAa,cAAc;IAIzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAR5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BAAgB;IAKjC,UAAU,CACtB,QAAQ,EAAE,sBAAsB,GAC9B,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAAA;KAAE,CAAC;YAiBnD,qBAAqB;IA2BnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAmD5B;IAEF,OAAO,CAAC,UAAU;YAsCJ,QAAQ;IAwFtB,OAAO,CAAC,kBAAkB;IAsB1B;;;;;OAKG;YACW,cAAc;CAQ5B"}
@@ -11,62 +11,55 @@ const container_definitions_1 = require("@fluidframework/container-definitions")
11
11
  const internal_1 = require("@fluidframework/core-utils/internal");
12
12
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
13
13
  const constants_js_1 = require("./constants.js");
14
+ const segmentInfos_js_1 = require("./segmentInfos.js");
14
15
  const snapshotChunks_js_1 = require("./snapshotChunks.js");
15
16
  const snapshotV1_js_1 = require("./snapshotV1.js");
16
17
  const snapshotlegacy_js_1 = require("./snapshotlegacy.js");
17
18
  class SnapshotLoader {
18
- constructor(runtime,
19
- // eslint-disable-next-line import/no-deprecated
20
- client, mergeTree, logger, serializer) {
19
+ constructor(runtime, client, mergeTree, logger, serializer) {
21
20
  this.runtime = runtime;
22
21
  this.client = client;
23
22
  this.mergeTree = mergeTree;
24
23
  this.serializer = serializer;
25
24
  this.specToSegment = (spec) => {
26
- let seg;
27
25
  if ((0, snapshotChunks_js_1.hasMergeInfo)(spec)) {
28
- seg = this.client.specToSegment(spec.json);
29
- // `specToSegment()` initializes `seg` with the LocalClientId. Overwrite this with
30
- // the `spec` client (if specified). Otherwise overwrite with `NonCollabClient`.
31
- seg.clientId =
32
- spec.client === undefined
26
+ const seg = (0, segmentInfos_js_1.overwriteInfo)(this.client.specToSegment(spec.json), {
27
+ clientId: spec.client === undefined
33
28
  ? constants_js_1.NonCollabClient
34
- : this.client.getOrAddShortClientId(spec.client);
35
- seg.seq = spec.seq ?? constants_js_1.UniversalSequenceNumber;
29
+ : this.client.getOrAddShortClientId(spec.client),
30
+ seq: spec.seq ?? constants_js_1.UniversalSequenceNumber,
31
+ });
36
32
  if (spec.removedSeq !== undefined) {
37
- seg.removedSeq = spec.removedSeq;
33
+ // this format had a bug where it didn't store all the overlap clients
34
+ // this is for back compat, so we change the singular id to an array
35
+ // this will only cause problems if there is an overlapping delete
36
+ // spanning the snapshot, which should be rare
37
+ const specAsBuggyFormat = spec;
38
+ if (specAsBuggyFormat.removedClient !== undefined) {
39
+ spec.removedClientIds ?? (spec.removedClientIds = [specAsBuggyFormat.removedClient]);
40
+ }
41
+ (0, internal_1.assert)(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);
42
+ (0, segmentInfos_js_1.overwriteInfo)(seg, {
43
+ removedSeq: spec.removedSeq,
44
+ removedClientIds: spec.removedClientIds.map((id) => this.client.getOrAddShortClientId(id)),
45
+ });
38
46
  }
39
47
  if (spec.movedSeq !== undefined) {
40
- seg.movedSeq = spec.movedSeq;
48
+ (0, internal_1.assert)(spec.movedClientIds !== undefined && spec.movedSeqs !== undefined, 0xaa5 /* must have movedIds ids */);
49
+ (0, segmentInfos_js_1.overwriteInfo)(seg, {
50
+ movedSeq: spec.movedSeq,
51
+ movedSeqs: spec.movedSeqs,
52
+ movedClientIds: spec.movedClientIds.map((id) => this.client.getOrAddShortClientId(id)),
53
+ // BUG? This isn't persisted
54
+ wasMovedOnInsert: false,
55
+ });
41
56
  }
42
- if (spec.movedSeqs !== undefined) {
43
- seg.movedSeqs = spec.movedSeqs;
44
- }
45
- // this format had a bug where it didn't store all the overlap clients
46
- // this is for back compat, so we change the singular id to an array
47
- // this will only cause problems if there is an overlapping delete
48
- // spanning the snapshot, which should be rare
49
- const specAsBuggyFormat = spec;
50
- if (specAsBuggyFormat.removedClient !== undefined) {
51
- seg.removedClientIds = [
52
- this.client.getOrAddShortClientId(specAsBuggyFormat.removedClient),
53
- ];
54
- }
55
- if (spec.removedClientIds !== undefined) {
56
- seg.removedClientIds = spec.removedClientIds?.map((sid) => this.client.getOrAddShortClientId(sid));
57
- }
58
- if (spec.movedClientIds !== undefined) {
59
- seg.movedClientIds = spec.movedClientIds?.map((sid) => this.client.getOrAddShortClientId(sid));
60
- }
61
- }
62
- else {
63
- seg = this.client.specToSegment(spec);
64
- seg.seq = constants_js_1.UniversalSequenceNumber;
65
- // `specToSegment()` initializes `seg` with the LocalClientId. We must overwrite this with
66
- // `NonCollabClient`.
67
- seg.clientId = constants_js_1.NonCollabClient;
57
+ return seg;
68
58
  }
69
- return seg;
59
+ return (0, segmentInfos_js_1.overwriteInfo)(this.client.specToSegment(spec), {
60
+ seq: constants_js_1.UniversalSequenceNumber,
61
+ clientId: constants_js_1.NonCollabClient,
62
+ });
70
63
  };
71
64
  this.logger = (0, internal_2.createChildLogger)({ logger, namespace: "SnapshotLoader" });
72
65
  }
@@ -162,16 +155,15 @@ class SnapshotLoader {
162
155
  }
163
156
  };
164
157
  for (const seg of segs) {
165
- const cli = seg.clientId;
166
- const seq = seg.seq;
158
+ const { clientId, seq } = seg;
167
159
  // If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush
168
160
  // any batched segments and then insert the current segment individually.
169
- if (cli === constants_js_1.NonCollabClient && seq === constants_js_1.UniversalSequenceNumber) {
161
+ if (clientId === constants_js_1.NonCollabClient && seq === constants_js_1.UniversalSequenceNumber) {
170
162
  batch.push(seg);
171
163
  }
172
164
  else {
173
165
  flushBatch();
174
- append([seg], cli, seq);
166
+ append([seg], clientId, seq);
175
167
  }
176
168
  }
177
169
  flushBatch();
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAA6D;AAE7D,+DAA8D;AAC9D,iFAAoE;AACpE,kEAA6D;AAO7D,uEAIkD;AAIlD,iDAA0E;AAI1E,2DAI6B;AAC7B,mDAA6C;AAC7C,2DAAqD;AAErD,MAAa,cAAc;IAG1B,YACkB,OAA+B;IAChD,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wCA0RC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\n// eslint-disable-next-line import/no-deprecated\nimport { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { ISegmentLeaf } from \"./mergeTreeNodes.js\";\nimport { IJSONSegment } from \"./ops.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tMergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\n\nexport class SnapshotLoader {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tprivate readonly client: Client,\n\t\tprivate readonly mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly serializer: IFluidSerializer,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"SnapshotLoader\" });\n\t}\n\n\tpublic async initialize(\n\t\tservices: IChannelStorageService,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst headerLoadedP = services.readBlob(SnapshotLegacy.header).then((header) => {\n\t\t\tassert(!!header, 0x05f /* \"Missing blob header on legacy snapshot!\" */);\n\t\t\treturn this.loadHeader(bufferToString(header, \"utf8\"));\n\t\t});\n\n\t\tconst catchupOpsP = this.loadBodyAndCatchupOps(headerLoadedP, services);\n\n\t\tcatchupOpsP.catch((error) =>\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"CatchupOpsLoadFailure\" }, error),\n\t\t);\n\n\t\tawait headerLoadedP;\n\n\t\treturn { catchupOpsP };\n\t}\n\n\tprivate async loadBodyAndCatchupOps(\n\t\theaderChunkP: Promise<MergeTreeChunkV1>,\n\t\tservices: IChannelStorageService,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\tconst blobsP = services.list(\"\");\n\t\tconst headerChunk = await headerChunkP;\n\n\t\t// TODO we shouldn't need to wait on the body being complete to finish initialization.\n\t\t// To fully support this we need to be able to process inbound ops for pending segments.\n\t\tawait this.loadBody(headerChunk, services);\n\n\t\tconst blobs = await blobsP;\n\t\tif (blobs.length === headerChunk.headerMetadata!.orderedChunkMetadata.length + 1) {\n\t\t\tfor (const md of headerChunk.headerMetadata!.orderedChunkMetadata)\n\t\t\t\tblobs.splice(blobs.indexOf(md.id), 1);\n\t\t\tassert(blobs.length === 1, 0x060 /* There should be only one blob with catch up ops */);\n\n\t\t\t// TODO: The 'Snapshot.catchupOps' tree entry is purely for backwards compatibility.\n\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\t\treturn this.loadCatchupOps(services.readBlob(blobs[0]), this.serializer);\n\t\t} else if (blobs.length !== headerChunk.headerMetadata!.orderedChunkMetadata.length) {\n\t\t\tthrow new Error(\"Unexpected blobs in snapshot\");\n\t\t}\n\t\treturn [];\n\t}\n\n\tprivate readonly specToSegment = (\n\t\tspec: IJSONSegment | IJSONSegmentWithMergeInfo,\n\t): ISegmentLeaf => {\n\t\tlet seg: ISegmentLeaf;\n\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tseg = this.client.specToSegment(spec.json);\n\n\t\t\t// `specToSegment()` initializes `seg` with the LocalClientId. Overwrite this with\n\t\t\t// the `spec` client (if specified). Otherwise overwrite with `NonCollabClient`.\n\t\t\tseg.clientId =\n\t\t\t\tspec.client === undefined\n\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client);\n\n\t\t\tseg.seq = spec.seq ?? UniversalSequenceNumber;\n\n\t\t\tif (spec.removedSeq !== undefined) {\n\t\t\t\tseg.removedSeq = spec.removedSeq;\n\t\t\t}\n\t\t\tif (spec.movedSeq !== undefined) {\n\t\t\t\tseg.movedSeq = spec.movedSeq;\n\t\t\t}\n\t\t\tif (spec.movedSeqs !== undefined) {\n\t\t\t\tseg.movedSeqs = spec.movedSeqs;\n\t\t\t}\n\t\t\t// this format had a bug where it didn't store all the overlap clients\n\t\t\t// this is for back compat, so we change the singular id to an array\n\t\t\t// this will only cause problems if there is an overlapping delete\n\t\t\t// spanning the snapshot, which should be rare\n\t\t\tconst specAsBuggyFormat: IJSONSegmentWithMergeInfo & { removedClient?: string } = spec;\n\t\t\tif (specAsBuggyFormat.removedClient !== undefined) {\n\t\t\t\tseg.removedClientIds = [\n\t\t\t\t\tthis.client.getOrAddShortClientId(specAsBuggyFormat.removedClient),\n\t\t\t\t];\n\t\t\t}\n\t\t\tif (spec.removedClientIds !== undefined) {\n\t\t\t\tseg.removedClientIds = spec.removedClientIds?.map((sid) =>\n\t\t\t\t\tthis.client.getOrAddShortClientId(sid),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (spec.movedClientIds !== undefined) {\n\t\t\t\tseg.movedClientIds = spec.movedClientIds?.map((sid) =>\n\t\t\t\t\tthis.client.getOrAddShortClientId(sid),\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tseg = this.client.specToSegment(spec);\n\t\t\tseg.seq = UniversalSequenceNumber;\n\n\t\t\t// `specToSegment()` initializes `seg` with the LocalClientId. We must overwrite this with\n\t\t\t// `NonCollabClient`.\n\t\t\tseg.clientId = NonCollabClient;\n\t\t}\n\n\t\treturn seg;\n\t};\n\n\tprivate loadHeader(header: string): MergeTreeChunkV1 {\n\t\tconst chunk = SnapshotV1.processChunk(\n\t\t\tSnapshotLegacy.header,\n\t\t\theader,\n\t\t\tthis.logger,\n\t\t\tthis.mergeTree.options,\n\t\t\tthis.serializer,\n\t\t);\n\t\tconst segs = chunk.segments.map((element) => this.specToSegment(element));\n\t\tthis.extractAttribution(segs, chunk);\n\n\t\tthis.mergeTree.reloadFromSegments(segs);\n\n\t\tif (chunk.headerMetadata === undefined) {\n\t\t\tthrow new Error(\"header metadata not available\");\n\t\t}\n\t\t// If we load a detached container from snapshot, then we don't supply a default clientId\n\t\t// because we don't want to start collaboration.\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t// specify a default client id, \"snapshot\" here as we\n\t\t\t// should enter collaboration/op sending mode if we load\n\t\t\t// a snapshot in any case (summary or attach message)\n\t\t\t// once we get a client id this will be called with that\n\t\t\t// clientId in the connected event\n\t\t\tthis.client.startOrUpdateCollaboration(\n\t\t\t\tthis.runtime.clientId ?? \"snapshot\",\n\n\t\t\t\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\t\t\t/* minSeq: */ chunk.headerMetadata.minSequenceNumber ??\n\t\t\t\t\tchunk.headerMetadata.sequenceNumber,\n\t\t\t\t/* currentSeq: */ chunk.headerMetadata.sequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\treturn chunk;\n\t}\n\n\tprivate async loadBody(\n\t\tchunk1: MergeTreeChunkV1,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\tconst headerMetadata = chunk1.headerMetadata!;\n\t\tassert(chunk1.length <= headerMetadata.totalLength, 0x061 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount <= headerMetadata.totalSegmentCount,\n\t\t\t0x062 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (chunk1.segmentCount === headerMetadata.totalSegmentCount) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet chunksWithAttribution = chunk1.attribution === undefined ? 0 : 1;\n\t\tconst segs: ISegmentLeaf[] = [];\n\t\tlet lengthSofar = chunk1.length;\n\t\tfor (\n\t\t\tlet chunkIndex = 1;\n\t\t\tchunkIndex < headerMetadata.orderedChunkMetadata.length;\n\t\t\tchunkIndex++\n\t\t) {\n\t\t\tconst chunk = await SnapshotV1.loadChunk(\n\t\t\t\tservices,\n\t\t\t\theaderMetadata.orderedChunkMetadata[chunkIndex].id,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tlengthSofar += chunk.length;\n\t\t\t// Deserialize each chunk segment and append it to the end of the MergeTree.\n\t\t\tconst newSegs = chunk.segments.map((element) => this.specToSegment(element));\n\t\t\tthis.extractAttribution(newSegs, chunk);\n\t\t\tchunksWithAttribution += chunk.attribution === undefined ? 0 : 1;\n\t\t\tsegs.push(...newSegs);\n\t\t}\n\n\t\tassert(\n\t\t\tchunksWithAttribution === 0 ||\n\t\t\t\tchunksWithAttribution === headerMetadata.orderedChunkMetadata.length,\n\t\t\t0x4c0 /* all or no chunks should have attribution information */,\n\t\t);\n\n\t\tassert(lengthSofar === headerMetadata.totalLength, 0x063 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount,\n\t\t\t0x064 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\t// Helper to insert segments at the end of the MergeTree.\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst append = (segments: ISegmentLeaf[], cli: number, seq: number): void => {\n\t\t\tmergeTree.insertSegments(\n\t\t\t\tmergeTree.root.cachedLength ?? 0,\n\t\t\t\tsegments,\n\t\t\t\t/* refSeq: */ UniversalSequenceNumber,\n\t\t\t\tcli,\n\t\t\t\tseq,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\t// Helpers to batch-insert segments that are below the min seq\n\t\tconst batch: ISegmentLeaf[] = [];\n\t\tconst flushBatch = (): void => {\n\t\t\tif (batch.length > 0) {\n\t\t\t\tappend(batch, NonCollabClient, UniversalSequenceNumber);\n\t\t\t}\n\t\t};\n\n\t\tfor (const seg of segs) {\n\t\t\tconst cli = seg.clientId;\n\t\t\tconst seq = seg.seq;\n\n\t\t\t// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush\n\t\t\t// any batched segments and then insert the current segment individually.\n\t\t\tif (cli === NonCollabClient && seq === UniversalSequenceNumber) {\n\t\t\t\tbatch.push(seg);\n\t\t\t} else {\n\t\t\t\tflushBatch();\n\t\t\t\tappend([seg], cli, seq!);\n\t\t\t}\n\t\t}\n\n\t\tflushBatch();\n\t}\n\n\tprivate extractAttribution(segments: ISegmentLeaf[], chunk: MergeTreeChunkV1): void {\n\t\tif (chunk.attribution) {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when loading a document with attribution information.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { isAttached, attach, serializer } = attributionPolicy;\n\t\t\tif (!isAttached) {\n\t\t\t\tattach(this.client);\n\t\t\t}\n\t\t\tserializer.populateAttributionCollections(segments, chunk.attribution);\n\t\t} else {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy?.isAttached) {\n\t\t\t\tattributionPolicy?.detach();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If loading from a snapshot, get the catchup messages.\n\t * @param rawMessages - The messages in original encoding\n\t * @returns The decoded messages with parsed+hydrated handles. Matches the format that will be passed in\n\t * SharedObject.processCore.\n\t */\n\tprivate async loadCatchupOps(\n\t\trawMessages: Promise<ArrayBufferLike>,\n\t\tserializer: IFluidSerializer,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\treturn serializer.parse(\n\t\t\tbufferToString(await rawMessages, \"utf8\"),\n\t\t) as ISequencedDocumentMessage[];\n\t}\n}\n"]}
1
+ {"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAA6D;AAE7D,+DAA8D;AAC9D,iFAAoE;AACpE,kEAA6D;AAO7D,uEAIkD;AAGlD,iDAA0E;AAI1E,uDAM2B;AAC3B,2DAI6B;AAC7B,mDAA6C;AAC7C,2DAAqD;AAErD,MAAa,cAAc;IAG1B,YACkB,OAA+B,EAE/B,MAAc,EACd,SAAoB,EACrC,MAA2B,EACV,UAA4B;QAL5B,YAAO,GAAP,OAAO,CAAwB;QAE/B,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAW;QAEpB,eAAU,GAAV,UAAU,CAAkB;QAmD7B,kBAAa,GAAG,CAChC,IAA8C,EACZ,EAAE;YACpC,IAAI,IAAA,gCAAY,EAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,MAAM,GAAG,GAAG,IAAA,+BAAa,EAAiB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBAC/E,QAAQ,EACP,IAAI,CAAC,MAAM,KAAK,SAAS;wBACxB,CAAC,CAAC,8BAAe;wBACjB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC;oBAClD,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,sCAAuB;iBACxC,CAAC,CAAC;gBAEH,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;oBACnC,sEAAsE;oBACtE,oEAAoE;oBACpE,kEAAkE;oBAClE,8CAA8C;oBAC9C,MAAM,iBAAiB,GAA2D,IAAI,CAAC;oBACvF,IAAI,iBAAiB,CAAC,aAAa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GAAG,IAAI,CAAC,SAAS,CAAC;YAC7C,IAAI,iBAAiB,EAAE,UAAU,EAAE,CAAC;gBACnC,iBAAiB,EAAE,MAAM,EAAE,CAAC;YAC7B,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAC3B,WAAqC,EACrC,UAA4B;QAE5B,OAAO,UAAU,CAAC,KAAK,CACtB,IAAA,6BAAc,EAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CACV,CAAC;IAClC,CAAC;CACD;AAnRD,wCAmRC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { IJSONSegment } from \"./ops.js\";\nimport {\n\tIRemovalInfo,\n\toverwriteInfo,\n\ttype IInsertionInfo,\n\ttype IMoveInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tMergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\n\nexport class SnapshotLoader {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\n\t\tprivate readonly client: Client,\n\t\tprivate readonly mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly serializer: IFluidSerializer,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"SnapshotLoader\" });\n\t}\n\n\tpublic async initialize(\n\t\tservices: IChannelStorageService,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst headerLoadedP = services.readBlob(SnapshotLegacy.header).then((header) => {\n\t\t\tassert(!!header, 0x05f /* \"Missing blob header on legacy snapshot!\" */);\n\t\t\treturn this.loadHeader(bufferToString(header, \"utf8\"));\n\t\t});\n\n\t\tconst catchupOpsP = this.loadBodyAndCatchupOps(headerLoadedP, services);\n\n\t\tcatchupOpsP.catch((error) =>\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"CatchupOpsLoadFailure\" }, error),\n\t\t);\n\n\t\tawait headerLoadedP;\n\n\t\treturn { catchupOpsP };\n\t}\n\n\tprivate async loadBodyAndCatchupOps(\n\t\theaderChunkP: Promise<MergeTreeChunkV1>,\n\t\tservices: IChannelStorageService,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\tconst blobsP = services.list(\"\");\n\t\tconst headerChunk = await headerChunkP;\n\n\t\t// TODO we shouldn't need to wait on the body being complete to finish initialization.\n\t\t// To fully support this we need to be able to process inbound ops for pending segments.\n\t\tawait this.loadBody(headerChunk, services);\n\n\t\tconst blobs = await blobsP;\n\t\tif (blobs.length === headerChunk.headerMetadata!.orderedChunkMetadata.length + 1) {\n\t\t\tfor (const md of headerChunk.headerMetadata!.orderedChunkMetadata)\n\t\t\t\tblobs.splice(blobs.indexOf(md.id), 1);\n\t\t\tassert(blobs.length === 1, 0x060 /* There should be only one blob with catch up ops */);\n\n\t\t\t// TODO: The 'Snapshot.catchupOps' tree entry is purely for backwards compatibility.\n\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\t\treturn this.loadCatchupOps(services.readBlob(blobs[0]), this.serializer);\n\t\t} else if (blobs.length !== headerChunk.headerMetadata!.orderedChunkMetadata.length) {\n\t\t\tthrow new Error(\"Unexpected blobs in snapshot\");\n\t\t}\n\t\treturn [];\n\t}\n\n\tprivate readonly specToSegment = (\n\t\tspec: IJSONSegment | IJSONSegmentWithMergeInfo,\n\t): SegmentWithInfo<IInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tclientId:\n\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t});\n\n\t\t\tif (spec.removedSeq !== undefined) {\n\t\t\t\t// this format had a bug where it didn't store all the overlap clients\n\t\t\t\t// this is for back compat, so we change the singular id to an array\n\t\t\t\t// this will only cause problems if there is an overlapping delete\n\t\t\t\t// spanning the snapshot, which should be rare\n\t\t\t\tconst specAsBuggyFormat: IJSONSegmentWithMergeInfo & { removedClient?: string } = spec;\n\t\t\t\tif (specAsBuggyFormat.removedClient !== undefined) {\n\t\t\t\t\tspec.removedClientIds ??= [specAsBuggyFormat.removedClient];\n\t\t\t\t}\n\t\t\t\tassert(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);\n\t\t\t\toverwriteInfo<IRemovalInfo>(seg, {\n\t\t\t\t\tremovedSeq: spec.removedSeq,\n\t\t\t\t\tremovedClientIds: spec.removedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (spec.movedSeq !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds !== undefined && spec.movedSeqs !== undefined,\n\t\t\t\t\t0xaa5 /* must have movedIds ids */,\n\t\t\t\t);\n\t\t\t\toverwriteInfo<IMoveInfo>(seg, {\n\t\t\t\t\tmovedSeq: spec.movedSeq,\n\t\t\t\t\tmovedSeqs: spec.movedSeqs,\n\t\t\t\t\tmovedClientIds: spec.movedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\n\t\t\t\t\t// BUG? This isn't persisted\n\t\t\t\t\twasMovedOnInsert: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tseq: UniversalSequenceNumber,\n\t\t\tclientId: NonCollabClient,\n\t\t});\n\t};\n\n\tprivate loadHeader(header: string): MergeTreeChunkV1 {\n\t\tconst chunk = SnapshotV1.processChunk(\n\t\t\tSnapshotLegacy.header,\n\t\t\theader,\n\t\t\tthis.logger,\n\t\t\tthis.mergeTree.options,\n\t\t\tthis.serializer,\n\t\t);\n\t\tconst segs = chunk.segments.map((element) => this.specToSegment(element));\n\t\tthis.extractAttribution(segs, chunk);\n\n\t\tthis.mergeTree.reloadFromSegments(segs);\n\n\t\tif (chunk.headerMetadata === undefined) {\n\t\t\tthrow new Error(\"header metadata not available\");\n\t\t}\n\t\t// If we load a detached container from snapshot, then we don't supply a default clientId\n\t\t// because we don't want to start collaboration.\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t// specify a default client id, \"snapshot\" here as we\n\t\t\t// should enter collaboration/op sending mode if we load\n\t\t\t// a snapshot in any case (summary or attach message)\n\t\t\t// once we get a client id this will be called with that\n\t\t\t// clientId in the connected event\n\t\t\tthis.client.startOrUpdateCollaboration(\n\t\t\t\tthis.runtime.clientId ?? \"snapshot\",\n\n\t\t\t\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\t\t\t/* minSeq: */ chunk.headerMetadata.minSequenceNumber ??\n\t\t\t\t\tchunk.headerMetadata.sequenceNumber,\n\t\t\t\t/* currentSeq: */ chunk.headerMetadata.sequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\treturn chunk;\n\t}\n\n\tprivate async loadBody(\n\t\tchunk1: MergeTreeChunkV1,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\tconst headerMetadata = chunk1.headerMetadata!;\n\t\tassert(chunk1.length <= headerMetadata.totalLength, 0x061 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount <= headerMetadata.totalSegmentCount,\n\t\t\t0x062 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (chunk1.segmentCount === headerMetadata.totalSegmentCount) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet chunksWithAttribution = chunk1.attribution === undefined ? 0 : 1;\n\t\tconst segs: SegmentWithInfo<IInsertionInfo>[] = [];\n\t\tlet lengthSofar = chunk1.length;\n\t\tfor (\n\t\t\tlet chunkIndex = 1;\n\t\t\tchunkIndex < headerMetadata.orderedChunkMetadata.length;\n\t\t\tchunkIndex++\n\t\t) {\n\t\t\tconst chunk = await SnapshotV1.loadChunk(\n\t\t\t\tservices,\n\t\t\t\theaderMetadata.orderedChunkMetadata[chunkIndex].id,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tlengthSofar += chunk.length;\n\t\t\t// Deserialize each chunk segment and append it to the end of the MergeTree.\n\t\t\tconst newSegs = chunk.segments.map((element) => this.specToSegment(element));\n\t\t\tthis.extractAttribution(newSegs, chunk);\n\t\t\tchunksWithAttribution += chunk.attribution === undefined ? 0 : 1;\n\t\t\tsegs.push(...newSegs);\n\t\t}\n\n\t\tassert(\n\t\t\tchunksWithAttribution === 0 ||\n\t\t\t\tchunksWithAttribution === headerMetadata.orderedChunkMetadata.length,\n\t\t\t0x4c0 /* all or no chunks should have attribution information */,\n\t\t);\n\n\t\tassert(lengthSofar === headerMetadata.totalLength, 0x063 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount,\n\t\t\t0x064 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\t// Helper to insert segments at the end of the MergeTree.\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst append = (segments: ISegmentPrivate[], cli: number, seq: number): void => {\n\t\t\tmergeTree.insertSegments(\n\t\t\t\tmergeTree.root.cachedLength ?? 0,\n\t\t\t\tsegments,\n\t\t\t\t/* refSeq: */ UniversalSequenceNumber,\n\t\t\t\tcli,\n\t\t\t\tseq,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\t// Helpers to batch-insert segments that are below the min seq\n\t\tconst batch: SegmentWithInfo<IInsertionInfo>[] = [];\n\t\tconst flushBatch = (): void => {\n\t\t\tif (batch.length > 0) {\n\t\t\t\tappend(batch, NonCollabClient, UniversalSequenceNumber);\n\t\t\t}\n\t\t};\n\n\t\tfor (const seg of segs) {\n\t\t\tconst { clientId, seq } = seg;\n\t\t\t// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush\n\t\t\t// any batched segments and then insert the current segment individually.\n\t\t\tif (clientId === NonCollabClient && seq === UniversalSequenceNumber) {\n\t\t\t\tbatch.push(seg);\n\t\t\t} else {\n\t\t\t\tflushBatch();\n\t\t\t\tappend([seg], clientId, seq);\n\t\t\t}\n\t\t}\n\n\t\tflushBatch();\n\t}\n\n\tprivate extractAttribution(segments: ISegmentPrivate[], chunk: MergeTreeChunkV1): void {\n\t\tif (chunk.attribution) {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when loading a document with attribution information.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { isAttached, attach, serializer } = attributionPolicy;\n\t\t\tif (!isAttached) {\n\t\t\t\tattach(this.client);\n\t\t\t}\n\t\t\tserializer.populateAttributionCollections(segments, chunk.attribution);\n\t\t} else {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy?.isAttached) {\n\t\t\t\tattributionPolicy?.detach();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If loading from a snapshot, get the catchup messages.\n\t * @param rawMessages - The messages in original encoding\n\t * @returns The decoded messages with parsed+hydrated handles. Matches the format that will be passed in\n\t * SharedObject.processCore.\n\t */\n\tprivate async loadCatchupOps(\n\t\trawMessages: Promise<ArrayBufferLike>,\n\t\tserializer: IFluidSerializer,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\treturn serializer.parse(\n\t\t\tbufferToString(await rawMessages, \"utf8\"),\n\t\t) as ISequencedDocumentMessage[];\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotV1.d.ts","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EACN,qBAAqB,EAErB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAIlD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAEN,gBAAgB,EAChB,gBAAgB,EAKhB,MAAM,qBAAqB,CAAC;AAG7B,qBAAa,UAAU;IAiBd,SAAS,EAAE,SAAS;IAE3B,OAAO,CAAC,QAAQ,CAAC,eAAe;IACzB,QAAQ,CAAC;IACT,YAAY,CAAC,SAAQ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ChC,UAAU,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,gBAAgB,CAAC;WAMd,YAAY,CACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,WAAW,GAAG,SAAS,EAChC,UAAU,CAAC,EAAE,gBAAgB,GAC3B,gBAAgB;CAMnB"}
@@ -12,6 +12,7 @@ const internal_3 = require("@fluidframework/telemetry-utils/internal");
12
12
  const constants_js_1 = require("./constants.js");
13
13
  const mergeTreeNodeWalk_js_1 = require("./mergeTreeNodeWalk.js");
14
14
  const properties_js_1 = require("./properties.js");
15
+ const segmentInfos_js_1 = require("./segmentInfos.js");
15
16
  const snapshotChunks_js_1 = require("./snapshotChunks.js");
16
17
  const snapshotlegacy_js_1 = require("./snapshotlegacy.js");
17
18
  class SnapshotV1 {
@@ -127,6 +128,7 @@ class SnapshotV1 {
127
128
  };
128
129
  let prev;
129
130
  const extractSegment = (segment) => {
131
+ (0, segmentInfos_js_1.assertInserted)(segment);
130
132
  // Elide segments that do not need to be included in the snapshot. A segment may be elided if
131
133
  // either condition is true:
132
134
  // a) The segment has not yet been ACKed. We do not need to snapshot unACKed segments because
@@ -134,10 +136,8 @@ class SnapshotV1 {
134
136
  // b) The segment was removed at or below the MSN. Pending ops can no longer reference this
135
137
  // segment, and therefore we can discard it.
136
138
  if (segment.seq === constants_js_1.UnassignedSequenceNumber ||
137
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
138
- segment.removedSeq <= minSeq ||
139
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
140
- segment.movedSeq <= minSeq) {
139
+ ((0, segmentInfos_js_1.isRemoved)(segment) && segment.removedSeq <= minSeq) ||
140
+ ((0, segmentInfos_js_1.isMoved)(segment) && segment.movedSeq <= minSeq)) {
141
141
  if (segment.seq !== constants_js_1.UnassignedSequenceNumber) {
142
142
  originalSegments += 1;
143
143
  }
@@ -147,12 +147,10 @@ class SnapshotV1 {
147
147
  // Next determine if the snapshot needs to preserve information required for merging the segment
148
148
  // (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't
149
149
  // have a pending remove.)
150
- if (
151
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
152
- segment.seq <= minSeq && // Segment is below the MSN, and...
153
- (segment.removedSeq === undefined || // .. Segment has not been removed, or...
150
+ if (segment.seq <= minSeq && // Segment is below the MSN, and...
151
+ (!(0, segmentInfos_js_1.isRemoved)(segment) || // .. Segment has not been removed, or...
154
152
  segment.removedSeq === constants_js_1.UnassignedSequenceNumber) && // .. Removal op to be delivered on reconnect
155
- (segment.movedSeq === undefined || segment.movedSeq === constants_js_1.UnassignedSequenceNumber)) {
153
+ (!(0, segmentInfos_js_1.isMoved)(segment) || segment.movedSeq === constants_js_1.UnassignedSequenceNumber)) {
156
154
  // This segment is below the MSN, which means that future ops will not reference it. Attempt to
157
155
  // coalesce the new segment with the previous (if any).
158
156
  if (!prev) {
@@ -185,14 +183,13 @@ class SnapshotV1 {
185
183
  json: segment.toJSONObject(),
186
184
  };
187
185
  // If the segment insertion is above the MSN, record the insertion merge info.
188
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
189
186
  if (segment.seq > minSeq) {
190
187
  raw.seq = segment.seq;
191
188
  raw.client = this.getLongClientId(segment.clientId);
192
189
  }
193
190
  // We have already dispensed with removed segments below the MSN and removed segments with unassigned
194
191
  // sequence numbers. Any remaining removal info should be preserved.
195
- if (segment.removedSeq !== undefined) {
192
+ if ((0, segmentInfos_js_1.isRemoved)(segment)) {
196
193
  (0, internal_1.assert)(segment.removedSeq !== constants_js_1.UnassignedSequenceNumber && segment.removedSeq > minSeq, 0x065 /* "On removal info preservation, segment has invalid removed sequence number!" */);
197
194
  raw.removedSeq = segment.removedSeq;
198
195
  // back compat for when we split overlap and removed client
@@ -202,7 +199,7 @@ class SnapshotV1 {
202
199
  : this.getLongClientId(segment.removedClientIds[0]);
203
200
  raw.removedClientIds = segment.removedClientIds?.map((id) => this.getLongClientId(id));
204
201
  }
205
- if (segment.movedSeq !== undefined) {
202
+ if ((0, segmentInfos_js_1.isMoved)(segment)) {
206
203
  (0, internal_1.assert)(segment.movedSeq !== constants_js_1.UnassignedSequenceNumber && segment.movedSeq > minSeq, 0x873 /* On move info preservation, segment has invalid moved sequence number! */);
207
204
  raw.movedSeq = segment.movedSeq;
208
205
  raw.movedSeqs = segment.movedSeqs;