@fluidframework/merge-tree 1.2.7 → 2.0.0-dev.1.3.0.96595

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 (244) hide show
  1. package/.mocharc.js +12 -0
  2. package/README.md +2 -2
  3. package/dist/MergeTreeTextHelper.d.ts +23 -0
  4. package/dist/MergeTreeTextHelper.d.ts.map +1 -0
  5. package/dist/MergeTreeTextHelper.js +133 -0
  6. package/dist/MergeTreeTextHelper.js.map +1 -0
  7. package/dist/base.d.ts +2 -26
  8. package/dist/base.d.ts.map +1 -1
  9. package/dist/base.js.map +1 -1
  10. package/dist/client.d.ts +27 -16
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +81 -101
  13. package/dist/client.js.map +1 -1
  14. package/dist/collections/heap.d.ts +28 -0
  15. package/dist/collections/heap.d.ts.map +1 -0
  16. package/dist/collections/heap.js +65 -0
  17. package/dist/collections/heap.js.map +1 -0
  18. package/dist/collections/index.d.ts +11 -0
  19. package/dist/collections/index.d.ts.map +1 -0
  20. package/dist/collections/index.js +23 -0
  21. package/dist/collections/index.js.map +1 -0
  22. package/dist/collections/intervalTree.d.ts +60 -0
  23. package/dist/collections/intervalTree.d.ts.map +1 -0
  24. package/dist/collections/intervalTree.js +99 -0
  25. package/dist/collections/intervalTree.js.map +1 -0
  26. package/dist/collections/list.d.ts +39 -0
  27. package/dist/collections/list.d.ts.map +1 -0
  28. package/dist/collections/list.js +155 -0
  29. package/dist/collections/list.js.map +1 -0
  30. package/dist/collections/rbTree.d.ts +154 -0
  31. package/dist/collections/rbTree.d.ts.map +1 -0
  32. package/dist/{collections.js → collections/rbTree.js} +15 -478
  33. package/dist/collections/rbTree.js.map +1 -0
  34. package/dist/collections/stack.d.ts +16 -0
  35. package/dist/collections/stack.d.ts.map +1 -0
  36. package/dist/collections/stack.js +30 -0
  37. package/dist/collections/stack.js.map +1 -0
  38. package/dist/collections/tst.d.ts +55 -0
  39. package/dist/collections/tst.d.ts.map +1 -0
  40. package/dist/collections/tst.js +171 -0
  41. package/dist/collections/tst.js.map +1 -0
  42. package/dist/index.d.ts +3 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +4 -2
  45. package/dist/index.js.map +1 -1
  46. package/dist/localReference.d.ts +48 -99
  47. package/dist/localReference.d.ts.map +1 -1
  48. package/dist/localReference.js +132 -169
  49. package/dist/localReference.js.map +1 -1
  50. package/dist/mergeTree.d.ts +71 -302
  51. package/dist/mergeTree.d.ts.map +1 -1
  52. package/dist/mergeTree.js +395 -642
  53. package/dist/mergeTree.js.map +1 -1
  54. package/dist/mergeTreeDeltaCallback.d.ts +1 -1
  55. package/dist/mergeTreeDeltaCallback.d.ts.map +1 -1
  56. package/dist/mergeTreeDeltaCallback.js.map +1 -1
  57. package/dist/mergeTreeNodes.d.ts +344 -0
  58. package/dist/mergeTreeNodes.d.ts.map +1 -0
  59. package/dist/mergeTreeNodes.js +383 -0
  60. package/dist/mergeTreeNodes.js.map +1 -0
  61. package/dist/mergeTreeTracking.d.ts +1 -1
  62. package/dist/mergeTreeTracking.d.ts.map +1 -1
  63. package/dist/mergeTreeTracking.js.map +1 -1
  64. package/dist/opBuilder.d.ts +1 -1
  65. package/dist/opBuilder.d.ts.map +1 -1
  66. package/dist/opBuilder.js.map +1 -1
  67. package/dist/partialLengths.d.ts +188 -18
  68. package/dist/partialLengths.d.ts.map +1 -1
  69. package/dist/partialLengths.js +495 -253
  70. package/dist/partialLengths.js.map +1 -1
  71. package/dist/properties.d.ts.map +1 -1
  72. package/dist/properties.js.map +1 -1
  73. package/dist/referencePositions.d.ts +6 -26
  74. package/dist/referencePositions.d.ts.map +1 -1
  75. package/dist/referencePositions.js +3 -20
  76. package/dist/referencePositions.js.map +1 -1
  77. package/dist/segmentGroupCollection.d.ts +3 -1
  78. package/dist/segmentGroupCollection.d.ts.map +1 -1
  79. package/dist/segmentGroupCollection.js +14 -1
  80. package/dist/segmentGroupCollection.js.map +1 -1
  81. package/dist/segmentPropertiesManager.d.ts +10 -1
  82. package/dist/segmentPropertiesManager.d.ts.map +1 -1
  83. package/dist/segmentPropertiesManager.js +42 -13
  84. package/dist/segmentPropertiesManager.js.map +1 -1
  85. package/dist/snapshotChunks.d.ts +2 -1
  86. package/dist/snapshotChunks.d.ts.map +1 -1
  87. package/dist/snapshotChunks.js.map +1 -1
  88. package/dist/snapshotLoader.d.ts.map +1 -1
  89. package/dist/snapshotLoader.js.map +1 -1
  90. package/dist/snapshotV1.d.ts +1 -1
  91. package/dist/snapshotV1.d.ts.map +1 -1
  92. package/dist/snapshotV1.js +1 -1
  93. package/dist/snapshotV1.js.map +1 -1
  94. package/dist/snapshotlegacy.d.ts +5 -1
  95. package/dist/snapshotlegacy.d.ts.map +1 -1
  96. package/dist/snapshotlegacy.js +4 -0
  97. package/dist/snapshotlegacy.js.map +1 -1
  98. package/dist/sortedSegmentSet.d.ts +1 -1
  99. package/dist/sortedSegmentSet.d.ts.map +1 -1
  100. package/dist/sortedSegmentSet.js.map +1 -1
  101. package/dist/textSegment.d.ts +7 -7
  102. package/dist/textSegment.d.ts.map +1 -1
  103. package/dist/textSegment.js +3 -125
  104. package/dist/textSegment.js.map +1 -1
  105. package/{DEV.md → docs/DEV.md} +2 -2
  106. package/docs/Obliterate.md +639 -0
  107. package/{REFERENCEPOSITIONS.md → docs/REFERENCEPOSITIONS.md} +2 -2
  108. package/lib/MergeTreeTextHelper.d.ts +23 -0
  109. package/lib/MergeTreeTextHelper.d.ts.map +1 -0
  110. package/lib/MergeTreeTextHelper.js +129 -0
  111. package/lib/MergeTreeTextHelper.js.map +1 -0
  112. package/lib/base.d.ts +2 -26
  113. package/lib/base.d.ts.map +1 -1
  114. package/lib/base.js.map +1 -1
  115. package/lib/client.d.ts +27 -16
  116. package/lib/client.d.ts.map +1 -1
  117. package/lib/client.js +79 -99
  118. package/lib/client.js.map +1 -1
  119. package/lib/collections/heap.d.ts +28 -0
  120. package/lib/collections/heap.d.ts.map +1 -0
  121. package/lib/collections/heap.js +61 -0
  122. package/lib/collections/heap.js.map +1 -0
  123. package/lib/collections/index.d.ts +11 -0
  124. package/lib/collections/index.d.ts.map +1 -0
  125. package/lib/collections/index.js +11 -0
  126. package/lib/collections/index.js.map +1 -0
  127. package/lib/collections/intervalTree.d.ts +60 -0
  128. package/lib/collections/intervalTree.d.ts.map +1 -0
  129. package/lib/collections/intervalTree.js +94 -0
  130. package/lib/collections/intervalTree.js.map +1 -0
  131. package/lib/collections/list.d.ts +39 -0
  132. package/lib/collections/list.d.ts.map +1 -0
  133. package/lib/collections/list.js +149 -0
  134. package/lib/collections/list.js.map +1 -0
  135. package/lib/collections/rbTree.d.ts +154 -0
  136. package/lib/collections/rbTree.d.ts.map +1 -0
  137. package/lib/{collections.js → collections/rbTree.js} +14 -469
  138. package/lib/collections/rbTree.js.map +1 -0
  139. package/lib/collections/stack.d.ts +16 -0
  140. package/lib/collections/stack.d.ts.map +1 -0
  141. package/lib/collections/stack.js +26 -0
  142. package/lib/collections/stack.js.map +1 -0
  143. package/lib/collections/tst.d.ts +55 -0
  144. package/lib/collections/tst.d.ts.map +1 -0
  145. package/lib/collections/tst.js +167 -0
  146. package/lib/collections/tst.js.map +1 -0
  147. package/lib/index.d.ts +3 -1
  148. package/lib/index.d.ts.map +1 -1
  149. package/lib/index.js +3 -1
  150. package/lib/index.js.map +1 -1
  151. package/lib/localReference.d.ts +48 -99
  152. package/lib/localReference.d.ts.map +1 -1
  153. package/lib/localReference.js +132 -170
  154. package/lib/localReference.js.map +1 -1
  155. package/lib/mergeTree.d.ts +71 -302
  156. package/lib/mergeTree.d.ts.map +1 -1
  157. package/lib/mergeTree.js +371 -607
  158. package/lib/mergeTree.js.map +1 -1
  159. package/lib/mergeTreeDeltaCallback.d.ts +1 -1
  160. package/lib/mergeTreeDeltaCallback.d.ts.map +1 -1
  161. package/lib/mergeTreeDeltaCallback.js.map +1 -1
  162. package/lib/mergeTreeNodes.d.ts +344 -0
  163. package/lib/mergeTreeNodes.d.ts.map +1 -0
  164. package/lib/mergeTreeNodes.js +369 -0
  165. package/lib/mergeTreeNodes.js.map +1 -0
  166. package/lib/mergeTreeTracking.d.ts +1 -1
  167. package/lib/mergeTreeTracking.d.ts.map +1 -1
  168. package/lib/mergeTreeTracking.js.map +1 -1
  169. package/lib/opBuilder.d.ts +1 -1
  170. package/lib/opBuilder.d.ts.map +1 -1
  171. package/lib/opBuilder.js.map +1 -1
  172. package/lib/partialLengths.d.ts +188 -18
  173. package/lib/partialLengths.d.ts.map +1 -1
  174. package/lib/partialLengths.js +491 -249
  175. package/lib/partialLengths.js.map +1 -1
  176. package/lib/properties.d.ts.map +1 -1
  177. package/lib/properties.js.map +1 -1
  178. package/lib/referencePositions.d.ts +6 -26
  179. package/lib/referencePositions.d.ts.map +1 -1
  180. package/lib/referencePositions.js +3 -20
  181. package/lib/referencePositions.js.map +1 -1
  182. package/lib/segmentGroupCollection.d.ts +3 -1
  183. package/lib/segmentGroupCollection.d.ts.map +1 -1
  184. package/lib/segmentGroupCollection.js +14 -1
  185. package/lib/segmentGroupCollection.js.map +1 -1
  186. package/lib/segmentPropertiesManager.d.ts +10 -1
  187. package/lib/segmentPropertiesManager.d.ts.map +1 -1
  188. package/lib/segmentPropertiesManager.js +42 -13
  189. package/lib/segmentPropertiesManager.js.map +1 -1
  190. package/lib/snapshotChunks.d.ts +2 -1
  191. package/lib/snapshotChunks.d.ts.map +1 -1
  192. package/lib/snapshotChunks.js.map +1 -1
  193. package/lib/snapshotLoader.d.ts.map +1 -1
  194. package/lib/snapshotLoader.js.map +1 -1
  195. package/lib/snapshotV1.d.ts +1 -1
  196. package/lib/snapshotV1.d.ts.map +1 -1
  197. package/lib/snapshotV1.js +1 -1
  198. package/lib/snapshotV1.js.map +1 -1
  199. package/lib/snapshotlegacy.d.ts +5 -1
  200. package/lib/snapshotlegacy.d.ts.map +1 -1
  201. package/lib/snapshotlegacy.js +4 -0
  202. package/lib/snapshotlegacy.js.map +1 -1
  203. package/lib/sortedSegmentSet.d.ts +1 -1
  204. package/lib/sortedSegmentSet.d.ts.map +1 -1
  205. package/lib/sortedSegmentSet.js.map +1 -1
  206. package/lib/textSegment.d.ts +7 -7
  207. package/lib/textSegment.d.ts.map +1 -1
  208. package/lib/textSegment.js +1 -122
  209. package/lib/textSegment.js.map +1 -1
  210. package/package.json +99 -20
  211. package/src/MergeTreeTextHelper.ts +170 -0
  212. package/src/base.ts +2 -35
  213. package/src/client.ts +91 -111
  214. package/src/collections/heap.ts +75 -0
  215. package/src/collections/index.ts +11 -0
  216. package/src/collections/intervalTree.ts +146 -0
  217. package/src/collections/list.ts +165 -0
  218. package/src/{collections.ts → collections/rbTree.ts} +84 -563
  219. package/src/collections/stack.ts +27 -0
  220. package/src/collections/tst.ts +212 -0
  221. package/src/index.ts +8 -2
  222. package/src/localReference.ts +152 -203
  223. package/src/mergeTree.ts +578 -996
  224. package/src/mergeTreeDeltaCallback.ts +1 -1
  225. package/src/mergeTreeNodes.ts +752 -0
  226. package/src/mergeTreeTracking.ts +1 -1
  227. package/src/opBuilder.ts +1 -1
  228. package/src/partialLengths.ts +631 -258
  229. package/src/properties.ts +1 -0
  230. package/src/referencePositions.ts +10 -44
  231. package/src/segmentGroupCollection.ts +17 -2
  232. package/src/segmentPropertiesManager.ts +46 -12
  233. package/src/snapshotChunks.ts +2 -1
  234. package/src/snapshotLoader.ts +2 -1
  235. package/src/snapshotV1.ts +3 -3
  236. package/src/snapshotlegacy.ts +6 -2
  237. package/src/sortedSegmentSet.ts +1 -1
  238. package/src/textSegment.ts +10 -157
  239. package/dist/collections.d.ts +0 -197
  240. package/dist/collections.d.ts.map +0 -1
  241. package/dist/collections.js.map +0 -1
  242. package/lib/collections.d.ts +0 -197
  243. package/lib/collections.d.ts.map +0 -1
  244. package/lib/collections.js.map +0 -1
@@ -0,0 +1,383 @@
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.internedSpaces = exports.compareStrings = exports.compareNumbers = exports.CollaborationWindow = exports.IncrementalMapState = exports.IncrementalExecOp = exports.Marker = exports.reservedMarkerSimpleTypeKey = exports.reservedMarkerIdKey = exports.BaseSegment = exports.MergeBlock = exports.MaxNodesInBlock = exports.ordinalToArray = exports.MergeNode = exports.toRemovalInfo = void 0;
8
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
9
+ /* eslint-disable @typescript-eslint/prefer-optional-chain, no-bitwise */
10
+ const common_utils_1 = require("@fluidframework/common-utils");
11
+ const constants_1 = require("./constants");
12
+ const mergeTreeTracking_1 = require("./mergeTreeTracking");
13
+ const ops_1 = require("./ops");
14
+ const properties_1 = require("./properties");
15
+ const referencePositions_1 = require("./referencePositions");
16
+ const segmentGroupCollection_1 = require("./segmentGroupCollection");
17
+ const segmentPropertiesManager_1 = require("./segmentPropertiesManager");
18
+ function toRemovalInfo(maybe) {
19
+ if ((maybe === null || maybe === void 0 ? void 0 : maybe.removedClientIds) !== undefined && (maybe === null || maybe === void 0 ? void 0 : maybe.removedSeq) !== undefined) {
20
+ return maybe;
21
+ }
22
+ (0, common_utils_1.assert)((maybe === null || maybe === void 0 ? void 0 : maybe.removedClientIds) === undefined && (maybe === null || maybe === void 0 ? void 0 : maybe.removedSeq) === undefined, 0x2bf /* "both removedClientIds and removedSeq should be set or not set" */);
23
+ }
24
+ exports.toRemovalInfo = toRemovalInfo;
25
+ class MergeNode {
26
+ constructor() {
27
+ this.index = 0;
28
+ this.ordinal = "";
29
+ this.cachedLength = 0;
30
+ }
31
+ isLeaf() {
32
+ return false;
33
+ }
34
+ }
35
+ exports.MergeNode = MergeNode;
36
+ function ordinalToArray(ord) {
37
+ const a = [];
38
+ if (ord) {
39
+ for (let i = 0, len = ord.length; i < len; i++) {
40
+ a.push(ord.charCodeAt(i));
41
+ }
42
+ }
43
+ return a;
44
+ }
45
+ exports.ordinalToArray = ordinalToArray;
46
+ // Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because
47
+ // the MergeTree always inserts first, then checks for overflow and splits if the child count equals
48
+ // `MaxNodesInBlock`. (i.e., `MaxNodesInBlock` contains 1 extra slot for temporary storage to
49
+ // facilitate splits.)
50
+ exports.MaxNodesInBlock = 8;
51
+ class MergeBlock extends MergeNode {
52
+ constructor(childCount) {
53
+ super();
54
+ this.childCount = childCount;
55
+ this.children = new Array(exports.MaxNodesInBlock);
56
+ }
57
+ hierBlock() {
58
+ return undefined;
59
+ }
60
+ setOrdinal(child, index) {
61
+ let childCount = this.childCount;
62
+ if (childCount === 8) {
63
+ childCount = 7;
64
+ }
65
+ (0, common_utils_1.assert)((childCount >= 1) && (childCount <= 7), 0x040 /* "Child count is not within [1,7] range!" */);
66
+ let localOrdinal;
67
+ const ordinalWidth = 1 << (exports.MaxNodesInBlock - (childCount + 1));
68
+ if (index === 0) {
69
+ localOrdinal = ordinalWidth - 1;
70
+ }
71
+ else {
72
+ const prevOrd = this.children[index - 1].ordinal;
73
+ const prevOrdCode = prevOrd.charCodeAt(prevOrd.length - 1);
74
+ localOrdinal = prevOrdCode + ordinalWidth;
75
+ }
76
+ child.ordinal = this.ordinal + String.fromCharCode(localOrdinal);
77
+ (0, common_utils_1.assert)(child.ordinal.length === (this.ordinal.length + 1), 0x041 /* "Unexpected child ordinal length!" */);
78
+ if (index > 0) {
79
+ (0, common_utils_1.assert)(child.ordinal > this.children[index - 1].ordinal, 0x042);
80
+ }
81
+ }
82
+ assignChild(child, index, updateOrdinal = true) {
83
+ child.parent = this;
84
+ child.index = index;
85
+ if (updateOrdinal) {
86
+ this.setOrdinal(child, index);
87
+ }
88
+ this.children[index] = child;
89
+ }
90
+ }
91
+ exports.MergeBlock = MergeBlock;
92
+ class BaseSegment extends MergeNode {
93
+ constructor() {
94
+ super(...arguments);
95
+ this.clientId = constants_1.LocalClientId;
96
+ this.seq = constants_1.UniversalSequenceNumber;
97
+ this.segmentGroups = new segmentGroupCollection_1.SegmentGroupCollection(this);
98
+ this.trackingCollection = new mergeTreeTracking_1.TrackingGroupCollection(this);
99
+ }
100
+ addProperties(newProps, op, seq, collabWindow, rollback = segmentPropertiesManager_1.PropertiesRollback.None) {
101
+ if (!this.propertyManager) {
102
+ this.propertyManager = new segmentPropertiesManager_1.PropertiesManager();
103
+ }
104
+ if (!this.properties) {
105
+ this.properties = (0, properties_1.createMap)();
106
+ }
107
+ return this.propertyManager.addProperties(this.properties, newProps, op, seq, collabWindow && collabWindow.collaborating, rollback);
108
+ }
109
+ hasProperty(key) {
110
+ return !!this.properties && (this.properties[key] !== undefined);
111
+ }
112
+ isLeaf() {
113
+ return true;
114
+ }
115
+ cloneInto(b) {
116
+ var _a;
117
+ b.clientId = this.clientId;
118
+ // TODO: deep clone properties
119
+ b.properties = (0, properties_1.clone)(this.properties);
120
+ b.removedClientIds = (_a = this.removedClientIds) === null || _a === void 0 ? void 0 : _a.slice();
121
+ // TODO: copy removed client overlap and branch removal info
122
+ b.removedSeq = this.removedSeq;
123
+ b.seq = this.seq;
124
+ }
125
+ canAppend(segment) {
126
+ return false;
127
+ }
128
+ addSerializedProps(jseg) {
129
+ if (this.properties) {
130
+ jseg.props = this.properties;
131
+ }
132
+ }
133
+ /**
134
+ * @deprecated for internal use only. public export will be removed.
135
+ * @internal
136
+ */
137
+ ack(segmentGroup, opArgs, mergeTree) {
138
+ const currentSegmentGroup = this.segmentGroups.dequeue();
139
+ (0, common_utils_1.assert)(currentSegmentGroup === segmentGroup, 0x043 /* "On ack, unexpected segmentGroup!" */);
140
+ switch (opArgs.op.type) {
141
+ case ops_1.MergeTreeDeltaType.ANNOTATE:
142
+ (0, common_utils_1.assert)(!!this.propertyManager, 0x044 /* "On annotate ack, missing segment property manager!" */);
143
+ this.propertyManager.ackPendingProperties(opArgs.op);
144
+ return true;
145
+ case ops_1.MergeTreeDeltaType.INSERT:
146
+ (0, common_utils_1.assert)(this.seq === constants_1.UnassignedSequenceNumber, 0x045 /* "On insert, seq number already assigned!" */);
147
+ this.seq = opArgs.sequencedMessage.sequenceNumber;
148
+ this.localSeq = undefined;
149
+ return true;
150
+ case ops_1.MergeTreeDeltaType.REMOVE:
151
+ const removalInfo = toRemovalInfo(this);
152
+ (0, common_utils_1.assert)(removalInfo !== undefined, 0x046 /* "On remove ack, missing removal info!" */);
153
+ this.localRemovedSeq = undefined;
154
+ if (removalInfo.removedSeq === constants_1.UnassignedSequenceNumber) {
155
+ removalInfo.removedSeq = opArgs.sequencedMessage.sequenceNumber;
156
+ return true;
157
+ }
158
+ return false;
159
+ default:
160
+ throw new Error(`${opArgs.op.type} is in unrecognized operation type`);
161
+ }
162
+ }
163
+ splitAt(pos) {
164
+ var _a;
165
+ if (pos > 0) {
166
+ const leafSegment = this.createSplitSegmentAt(pos);
167
+ if (leafSegment) {
168
+ this.copyPropertiesTo(leafSegment);
169
+ leafSegment.parent = this.parent;
170
+ // Give the leaf a temporary yet valid ordinal.
171
+ // when this segment is put in the tree, it will get its real ordinal,
172
+ // but this ordinal meets all the necessary invariants for now.
173
+ leafSegment.ordinal = this.ordinal + String.fromCharCode(0);
174
+ leafSegment.removedClientIds = (_a = this.removedClientIds) === null || _a === void 0 ? void 0 : _a.slice();
175
+ leafSegment.removedSeq = this.removedSeq;
176
+ leafSegment.localRemovedSeq = this.localRemovedSeq;
177
+ leafSegment.seq = this.seq;
178
+ leafSegment.localSeq = this.localSeq;
179
+ leafSegment.clientId = this.clientId;
180
+ this.segmentGroups.copyTo(leafSegment);
181
+ this.trackingCollection.copyTo(leafSegment);
182
+ if (this.localRefs) {
183
+ this.localRefs.split(pos, leafSegment);
184
+ }
185
+ }
186
+ return leafSegment;
187
+ }
188
+ }
189
+ copyPropertiesTo(other) {
190
+ if (this.propertyManager) {
191
+ if (this.properties) {
192
+ other.propertyManager = new segmentPropertiesManager_1.PropertiesManager();
193
+ other.properties = this.propertyManager.copyTo(this.properties, other.properties, other.propertyManager);
194
+ }
195
+ }
196
+ }
197
+ }
198
+ exports.BaseSegment = BaseSegment;
199
+ exports.reservedMarkerIdKey = "markerId";
200
+ exports.reservedMarkerSimpleTypeKey = "markerSimpleType";
201
+ class Marker extends BaseSegment {
202
+ constructor(refType) {
203
+ super();
204
+ this.refType = refType;
205
+ this.type = Marker.type;
206
+ this.cachedLength = 1;
207
+ }
208
+ static is(segment) {
209
+ return segment.type === Marker.type;
210
+ }
211
+ static make(refType, props) {
212
+ const marker = new Marker(refType);
213
+ if (props) {
214
+ marker.addProperties(props);
215
+ }
216
+ return marker;
217
+ }
218
+ toJSONObject() {
219
+ const obj = { marker: { refType: this.refType } };
220
+ super.addSerializedProps(obj);
221
+ return obj;
222
+ }
223
+ static fromJSONObject(spec) {
224
+ if (spec && typeof spec === "object" && "marker" in spec) {
225
+ return Marker.make(spec.marker.refType, spec.props);
226
+ }
227
+ return undefined;
228
+ }
229
+ clone() {
230
+ const b = Marker.make(this.refType, this.properties);
231
+ this.cloneInto(b);
232
+ return b;
233
+ }
234
+ getSegment() {
235
+ return this;
236
+ }
237
+ getOffset() {
238
+ return 0;
239
+ }
240
+ hasSimpleType(simpleTypeName) {
241
+ return !!this.properties &&
242
+ this.properties[exports.reservedMarkerSimpleTypeKey] === simpleTypeName;
243
+ }
244
+ getProperties() {
245
+ return this.properties;
246
+ }
247
+ getId() {
248
+ if (this.properties && this.properties[exports.reservedMarkerIdKey]) {
249
+ return this.properties[exports.reservedMarkerIdKey];
250
+ }
251
+ }
252
+ toString() {
253
+ let bbuf = "";
254
+ if ((0, referencePositions_1.refTypeIncludesFlag)(this, ops_1.ReferenceType.Tile)) {
255
+ bbuf += "Tile";
256
+ }
257
+ if ((0, referencePositions_1.refTypeIncludesFlag)(this, ops_1.ReferenceType.NestBegin)) {
258
+ if (bbuf.length > 0) {
259
+ bbuf += "; ";
260
+ }
261
+ bbuf += "RangeBegin";
262
+ }
263
+ if ((0, referencePositions_1.refTypeIncludesFlag)(this, ops_1.ReferenceType.NestEnd)) {
264
+ if (bbuf.length > 0) {
265
+ bbuf += "; ";
266
+ }
267
+ bbuf += "RangeEnd";
268
+ }
269
+ let lbuf = "";
270
+ const id = this.getId();
271
+ if (id) {
272
+ bbuf += ` (${id}) `;
273
+ }
274
+ const tileLabels = (0, referencePositions_1.refGetTileLabels)(this);
275
+ if (tileLabels) {
276
+ lbuf += "tile -- ";
277
+ for (let i = 0, len = tileLabels.length; i < len; i++) {
278
+ const tileLabel = tileLabels[i];
279
+ if (i > 0) {
280
+ lbuf += "; ";
281
+ }
282
+ lbuf += tileLabel;
283
+ }
284
+ }
285
+ const rangeLabels = (0, referencePositions_1.refGetRangeLabels)(this);
286
+ if (rangeLabels) {
287
+ let rangeKind = "begin";
288
+ if ((0, referencePositions_1.refTypeIncludesFlag)(this, ops_1.ReferenceType.NestEnd)) {
289
+ rangeKind = "end";
290
+ }
291
+ if (tileLabels) {
292
+ lbuf += " ";
293
+ }
294
+ lbuf += `range ${rangeKind} -- `;
295
+ const labels = rangeLabels;
296
+ for (let i = 0, len = labels.length; i < len; i++) {
297
+ const rangeLabel = labels[i];
298
+ if (i > 0) {
299
+ lbuf += "; ";
300
+ }
301
+ lbuf += rangeLabel;
302
+ }
303
+ }
304
+ let pbuf = "";
305
+ if (this.properties) {
306
+ pbuf += JSON.stringify(this.properties, (key, value) => {
307
+ // Avoid circular reference when stringifying makers containing handles.
308
+ // (Substitute a debug string instead.)
309
+ const handle = !!value && value.IFluidHandle;
310
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
311
+ return handle
312
+ ? `#Handle(${handle.routeContext.path}/${handle.path})`
313
+ : value;
314
+ });
315
+ }
316
+ return `M ${bbuf}: ${lbuf} ${pbuf}`;
317
+ }
318
+ createSplitSegmentAt(pos) {
319
+ return undefined;
320
+ }
321
+ canAppend(segment) {
322
+ return false;
323
+ }
324
+ append() { throw new Error("Can not append to marker"); }
325
+ }
326
+ exports.Marker = Marker;
327
+ Marker.type = "Marker";
328
+ var IncrementalExecOp;
329
+ (function (IncrementalExecOp) {
330
+ IncrementalExecOp[IncrementalExecOp["Go"] = 0] = "Go";
331
+ IncrementalExecOp[IncrementalExecOp["Stop"] = 1] = "Stop";
332
+ IncrementalExecOp[IncrementalExecOp["Yield"] = 2] = "Yield";
333
+ })(IncrementalExecOp = exports.IncrementalExecOp || (exports.IncrementalExecOp = {}));
334
+ class IncrementalMapState {
335
+ constructor(block, actions, pos, refSeq, clientId, context, start, end, childIndex = 0) {
336
+ this.block = block;
337
+ this.actions = actions;
338
+ this.pos = pos;
339
+ this.refSeq = refSeq;
340
+ this.clientId = clientId;
341
+ this.context = context;
342
+ this.start = start;
343
+ this.end = end;
344
+ this.childIndex = childIndex;
345
+ this.op = IncrementalExecOp.Go;
346
+ }
347
+ }
348
+ exports.IncrementalMapState = IncrementalMapState;
349
+ class CollaborationWindow {
350
+ constructor() {
351
+ this.clientId = constants_1.LocalClientId;
352
+ this.collaborating = false;
353
+ // Lowest-numbered segment in window; no client can reference a state before this one
354
+ this.minSeq = 0;
355
+ // Highest-numbered segment in window and current
356
+ // reference segment for this client
357
+ this.currentSeq = 0;
358
+ this.localSeq = 0;
359
+ }
360
+ loadFrom(a) {
361
+ this.clientId = a.clientId;
362
+ this.collaborating = a.collaborating;
363
+ this.minSeq = a.minSeq;
364
+ this.currentSeq = a.currentSeq;
365
+ }
366
+ }
367
+ exports.CollaborationWindow = CollaborationWindow;
368
+ const compareNumbers = (a, b) => a - b;
369
+ exports.compareNumbers = compareNumbers;
370
+ const compareStrings = (a, b) => a.localeCompare(b);
371
+ exports.compareStrings = compareStrings;
372
+ const indentStrings = ["", " ", " "];
373
+ function internedSpaces(n) {
374
+ if (indentStrings[n] === undefined) {
375
+ indentStrings[n] = "";
376
+ for (let i = 0; i < n; i++) {
377
+ indentStrings[n] += " ";
378
+ }
379
+ }
380
+ return indentStrings[n];
381
+ }
382
+ exports.internedSpaces = internedSpaces;
383
+ //# sourceMappingURL=mergeTreeNodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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iD;QACjD,oCAAoC;QACpC,eAAU,GAAG,CAAC,CAAC;QAEf,aAAQ,GAAG,CAAC,CAAC;IAQjB,CAAC;IANG,QAAQ,CAAC,CAAsB;QAC3B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;IACnC,CAAC;CACJ;AAjBD,kDAiBC;AAEM,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AAAjD,QAAA,cAAc,kBAAmC;AAEvD,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAA9D,QAAA,cAAc,kBAAgD;AAE3E,MAAM,aAAa,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACtC,SAAgB,cAAc,CAAC,CAAS;IACpC,IAAI,aAAa,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;QAChC,aAAa,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YACxB,aAAa,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;SAC3B;KACJ;IACD,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AARD,wCAQC","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\n/* eslint-disable @typescript-eslint/prefer-optional-chain, no-bitwise */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n LocalClientId,\n UnassignedSequenceNumber,\n UniversalSequenceNumber,\n} from \"./constants\";\nimport {\n LocalReferenceCollection,\n LocalReferencePosition,\n} from \"./localReference\";\nimport { MergeTree } from \"./mergeTree\";\nimport {\n IMergeTreeDeltaOpArgs,\n} from \"./mergeTreeDeltaCallback\";\nimport { TrackingGroupCollection } from \"./mergeTreeTracking\";\nimport {\n ICombiningOp,\n IJSONSegment,\n IMarkerDef,\n MergeTreeDeltaType,\n ReferenceType,\n} from \"./ops\";\nimport { PartialSequenceLengths } from \"./partialLengths\";\nimport {\n clone,\n createMap,\n MapLike,\n PropertySet,\n} from \"./properties\";\nimport {\n refTypeIncludesFlag,\n RangeStackMap,\n ReferencePosition,\n refGetRangeLabels,\n refGetTileLabels,\n } from \"./referencePositions\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection\";\nimport { PropertiesManager, PropertiesRollback } from \"./segmentPropertiesManager\";\n\n/**\n * Common properties for a node in a merge tree.\n */\nexport interface IMergeNodeCommon {\n parent?: IMergeBlock;\n /**\n * The length of the contents of the node.\n */\n cachedLength: number;\n /**\n * The index of this node in its parent's list of children.\n */\n index: number;\n /**\n * A string that can be used for comparing the location of this node to other `MergeNode`s in the same tree.\n * `a.ordinal < b.ordinal` if and only if `a` comes before `b` in a pre-order traversal of the tree.\n */\n ordinal: string;\n isLeaf(): this is ISegment;\n}\n\nexport type IMergeNode = IMergeBlock | ISegment;\n\n/**\n * Internal (i.e. non-leaf) node in a merge tree.\n */\nexport interface IMergeBlock extends IMergeNodeCommon {\n needsScour?: boolean;\n /**\n * Number of direct children of this node\n */\n childCount: number;\n /**\n * Array of child nodes.\n *\n * @remarks To avoid reallocation, this is always initialized to have maximum length as deemed by\n * the merge tree's branching factor. Use `childCount` to determine how many children this node actually has.\n */\n children: IMergeNode[];\n /**\n * Supports querying the total length of all descendants of this IMergeBlock from the perspective of any\n * (clientId, seq) within the collab window.\n *\n * @remarks This is only optional for implementation reasons (internal nodes can be created/moved without\n * immediately initializing the partial lengths). Aside from mid-update on tree operations, these lengths\n * objects are always defined.\n */\n partialLengths?: PartialSequenceLengths;\n hierBlock(): IHierBlock | undefined;\n assignChild(child: IMergeNode, index: number, updateOrdinal?: boolean): void;\n setOrdinal(child: IMergeNode, index: number): void;\n}\n\nexport interface IHierBlock extends IMergeBlock {\n hierToString(indentCount: number): string;\n /**\n * @deprecated for internal use only. public export will be removed.\n * @internal\n */\n addNodeReferences(mergeTree: MergeTree, node: IMergeNode): void;\n rightmostTiles: MapLike<ReferencePosition>;\n leftmostTiles: MapLike<ReferencePosition>;\n /**\n * @deprecated for internal use only. public export will be removed.\n * @internal\n */\n rangeStacks: RangeStackMap;\n}\n\n/**\n * Contains removal information associated to an {@link ISegment}.\n */\nexport interface IRemovalInfo {\n /**\n * Local seq at which this segment was removed, if the removal is yet-to-be acked.\n */\n localRemovedSeq?: number;\n /**\n * Seq at which this segment was removed.\n */\n removedSeq: number;\n /**\n * List of client IDs that have removed this segment.\n * The client that actually removed the segment (i.e. whose removal op was sequenced first) is stored as the first\n * client in this list. Other clients in the list have all issued concurrent ops to remove the segment.\n * @remarks When this list has length \\> 1, this is referred to as the \"overlapping remove\" case.\n */\n removedClientIds: number[];\n}\n\nexport function toRemovalInfo(maybe: Partial<IRemovalInfo> | undefined): IRemovalInfo | undefined {\n if (maybe?.removedClientIds !== undefined && maybe?.removedSeq !== undefined) {\n return maybe as IRemovalInfo;\n }\n assert(maybe?.removedClientIds === undefined && maybe?.removedSeq === undefined,\n 0x2bf /* \"both removedClientIds and removedSeq should be set or not set\" */);\n}\n\n/**\n * A segment representing a portion of the merge tree.\n * Segments are leaf nodes of the merge tree and contain data.\n */\nexport interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo> {\n readonly type: string;\n readonly segmentGroups: SegmentGroupCollection;\n readonly trackingCollection: TrackingGroupCollection;\n /**\n * Manages pending local state for properties on this segment.\n */\n propertyManager?: PropertiesManager;\n /**\n * Local seq at which this segment was inserted. If this is defined, `seq` will be UnassignedSequenceNumber.\n * Once the segment is acked, this field is cleared.\n */\n localSeq?: number;\n /**\n * Local seq at which this segment was removed. If this is defined, `removedSeq` will initially be set to\n * UnassignedSequenceNumber. However, if another client concurrently removes the same segment, `removedSeq`\n * will be updated to the seq at which that client removed this segment.\n *\n * Like `localSeq`, this field is cleared once the local removal of the segment is acked.\n */\n localRemovedSeq?: number;\n /**\n * Seq at which this segment was inserted.\n * If undefined, it is assumed the segment was inserted prior to the collab window's minimum sequence number.\n */\n seq?: number;\n /**\n * Short clientId for the client that inserted this segment.\n */\n clientId: number;\n /**\n * Local references added to this segment.\n */\n localRefs?: LocalReferenceCollection;\n /**\n * Properties that have been added to this segment via annotation.\n */\n properties?: PropertySet;\n addProperties(\n newProps: PropertySet,\n op?: ICombiningOp,\n seq?: number,\n collabWindow?: CollaborationWindow,\n rollback?: PropertiesRollback,\n ): PropertySet | undefined;\n clone(): ISegment;\n canAppend(segment: ISegment): boolean;\n append(segment: ISegment): void;\n splitAt(pos: number): ISegment | undefined;\n toJSONObject(): any;\n /**\n * Acks the current segment against the segment group, op, and merge tree.\n *\n * Throws error if the segment state doesn't match segment group or op.\n * E.g. Segment group not first is pending queue.\n * Inserted segment does not have unassigned sequence number.\n *\n * Returns true if the op modifies the segment, otherwise false.\n * The only current false case is overlapping remove, where a segment is removed\n * by a previously sequenced operation before the current operation is acked.\n *\n * @deprecated for internal use only. public export will be removed.\n * @internal\n */\n ack(segmentGroup: SegmentGroup, opArgs: IMergeTreeDeltaOpArgs, mergeTree: MergeTree): boolean;\n}\n\nexport interface IMarkerModifiedAction {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n (marker: Marker): void;\n}\n\nexport interface ISegmentAction<TClientData> {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n (segment: ISegment, pos: number, refSeq: number, clientId: number, start: number,\n end: number, accum: TClientData): boolean;\n}\n\nexport interface ISegmentChanges {\n next?: ISegment;\n replaceCurrent?: ISegment;\n}\n\nexport interface BlockAction<TClientData> {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n (\n block: IMergeBlock,\n pos: number,\n refSeq: number,\n clientId: number,\n start: number | undefined,\n end: number | undefined,\n accum: TClientData,\n ): boolean;\n}\n\nexport interface NodeAction<TClientData> {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n (\n node: IMergeNode,\n pos: number,\n refSeq: number,\n clientId: number,\n start: number | undefined,\n end: number | undefined,\n clientData: TClientData,\n ): boolean;\n}\n\nexport interface IncrementalSegmentAction<TContext> {\n (segment: ISegment, state: IncrementalMapState<TContext>);\n}\n\nexport interface IncrementalBlockAction<TContext> {\n (state: IncrementalMapState<TContext>);\n}\n\nexport interface BlockUpdateActions {\n child: (block: IMergeBlock, index: number) => void;\n}\n\nexport interface InsertContext {\n candidateSegment?: ISegment;\n prepareEvents?: boolean;\n structureChange?: boolean;\n leaf: (segment: ISegment | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n continuePredicate?: (continueFromBlock: IMergeBlock) => boolean;\n}\n\nexport interface SegmentActions<TClientData> {\n leaf?: ISegmentAction<TClientData>;\n shift?: NodeAction<TClientData>;\n contains?: NodeAction<TClientData>;\n pre?: BlockAction<TClientData>;\n post?: BlockAction<TClientData>;\n}\n\nexport interface IncrementalSegmentActions<TContext> {\n leaf: IncrementalSegmentAction<TContext>;\n pre?: IncrementalBlockAction<TContext>;\n post?: IncrementalBlockAction<TContext>;\n}\n\nexport interface SearchResult {\n text: string;\n pos: number;\n}\n\nexport interface MergeTreeStats {\n maxHeight: number;\n nodeCount: number;\n leafCount: number;\n removedLeafCount: number;\n liveCount: number;\n histo: number[];\n windowTime?: number;\n packTime?: number;\n ordTime?: number;\n maxOrdTime?: number;\n}\n\nexport interface SegmentGroup {\n segments: ISegment[];\n previousProps?: PropertySet[];\n removedReferences?: LocalReferencePosition[];\n localSeq: number;\n}\n\nexport class MergeNode implements IMergeNodeCommon {\n index: number = 0;\n ordinal: string = \"\";\n parent?: IMergeBlock;\n cachedLength: number = 0;\n\n isLeaf() {\n return false;\n }\n}\nexport function ordinalToArray(ord: string) {\n const a: number[] = [];\n if (ord) {\n for (let i = 0, len = ord.length; i < len; i++) {\n a.push(ord.charCodeAt(i));\n }\n }\n return a;\n}\n\n// Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because\n// the MergeTree always inserts first, then checks for overflow and splits if the child count equals\n// `MaxNodesInBlock`. (i.e., `MaxNodesInBlock` contains 1 extra slot for temporary storage to\n// facilitate splits.)\nexport const MaxNodesInBlock = 8;\n\nexport class MergeBlock extends MergeNode implements IMergeBlock {\n public children: IMergeNode[];\n public constructor(public childCount: number) {\n super();\n this.children = new Array<IMergeNode>(MaxNodesInBlock);\n }\n\n public hierBlock(): IHierBlock | undefined {\n return undefined;\n }\n\n public setOrdinal(child: IMergeNode, index: number) {\n let childCount = this.childCount;\n if (childCount === 8) {\n childCount = 7;\n }\n assert((childCount >= 1) && (childCount <= 7), 0x040 /* \"Child count is not within [1,7] range!\" */);\n let localOrdinal: number;\n const ordinalWidth = 1 << (MaxNodesInBlock - (childCount + 1));\n if (index === 0) {\n localOrdinal = ordinalWidth - 1;\n } else {\n const prevOrd = this.children[index - 1].ordinal;\n const prevOrdCode = prevOrd.charCodeAt(prevOrd.length - 1);\n localOrdinal = prevOrdCode + ordinalWidth;\n }\n child.ordinal = this.ordinal + String.fromCharCode(localOrdinal);\n assert(child.ordinal.length === (this.ordinal.length + 1), 0x041 /* \"Unexpected child ordinal length!\" */);\n if (index > 0) {\n assert(\n child.ordinal > this.children[index - 1].ordinal,\n 0x042, /* \"Child ordinal <= previous sibling ordinal!\" */\n );\n }\n }\n\n public assignChild(child: IMergeNode, index: number, updateOrdinal = true) {\n child.parent = this;\n child.index = index;\n if (updateOrdinal) {\n this.setOrdinal(child, index);\n }\n this.children[index] = child;\n }\n}\n\nexport abstract class BaseSegment extends MergeNode implements ISegment {\n public clientId: number = LocalClientId;\n public seq: number = UniversalSequenceNumber;\n public removedSeq?: number;\n public removedClientIds?: number[];\n public readonly segmentGroups: SegmentGroupCollection = new SegmentGroupCollection(this);\n public readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(this);\n public propertyManager?: PropertiesManager;\n public properties?: PropertySet;\n public localRefs?: LocalReferenceCollection;\n public abstract readonly type: string;\n public localSeq?: number;\n public localRemovedSeq?: number;\n\n public addProperties(newProps: PropertySet, op?: ICombiningOp, seq?: number,\n collabWindow?: CollaborationWindow, rollback: PropertiesRollback = PropertiesRollback.None) {\n if (!this.propertyManager) {\n this.propertyManager = new PropertiesManager();\n }\n if (!this.properties) {\n this.properties = createMap<any>();\n }\n return this.propertyManager.addProperties(\n this.properties,\n newProps,\n op,\n seq,\n collabWindow && collabWindow.collaborating,\n rollback,\n );\n }\n\n public hasProperty(key: string): boolean {\n return !!this.properties && (this.properties[key] !== undefined);\n }\n\n public isLeaf() {\n return true;\n }\n\n protected cloneInto(b: ISegment) {\n b.clientId = this.clientId;\n // TODO: deep clone properties\n b.properties = clone(this.properties);\n b.removedClientIds = this.removedClientIds?.slice();\n // TODO: copy removed client overlap and branch removal info\n b.removedSeq = this.removedSeq;\n b.seq = this.seq;\n }\n\n public canAppend(segment: ISegment): boolean {\n return false;\n }\n\n protected addSerializedProps(jseg: IJSONSegment) {\n if (this.properties) {\n jseg.props = this.properties;\n }\n }\n\n public abstract toJSONObject(): any;\n\n /**\n * @deprecated for internal use only. public export will be removed.\n * @internal\n */\n public ack(segmentGroup: SegmentGroup, opArgs: IMergeTreeDeltaOpArgs, mergeTree: MergeTree): boolean {\n const currentSegmentGroup = this.segmentGroups.dequeue();\n assert(currentSegmentGroup === segmentGroup, 0x043 /* \"On ack, unexpected segmentGroup!\" */);\n switch (opArgs.op.type) {\n case MergeTreeDeltaType.ANNOTATE:\n assert(!!this.propertyManager, 0x044 /* \"On annotate ack, missing segment property manager!\" */);\n this.propertyManager.ackPendingProperties(opArgs.op);\n return true;\n\n case MergeTreeDeltaType.INSERT:\n assert(this.seq === UnassignedSequenceNumber, 0x045 /* \"On insert, seq number already assigned!\" */);\n this.seq = opArgs.sequencedMessage!.sequenceNumber;\n this.localSeq = undefined;\n return true;\n\n case MergeTreeDeltaType.REMOVE:\n const removalInfo: IRemovalInfo | undefined = toRemovalInfo(this);\n assert(removalInfo !== undefined, 0x046 /* \"On remove ack, missing removal info!\" */);\n this.localRemovedSeq = undefined;\n if (removalInfo.removedSeq === UnassignedSequenceNumber) {\n removalInfo.removedSeq = opArgs.sequencedMessage!.sequenceNumber;\n return true;\n }\n return false;\n\n default:\n throw new Error(`${opArgs.op.type} is in unrecognized operation type`);\n }\n }\n\n public splitAt(pos: number): ISegment | undefined {\n if (pos > 0) {\n const leafSegment = this.createSplitSegmentAt(pos);\n if (leafSegment) {\n this.copyPropertiesTo(leafSegment);\n leafSegment.parent = this.parent;\n\n // Give the leaf a temporary yet valid ordinal.\n // when this segment is put in the tree, it will get its real ordinal,\n // but this ordinal meets all the necessary invariants for now.\n leafSegment.ordinal = this.ordinal + String.fromCharCode(0);\n\n leafSegment.removedClientIds = this.removedClientIds?.slice();\n leafSegment.removedSeq = this.removedSeq;\n leafSegment.localRemovedSeq = this.localRemovedSeq;\n leafSegment.seq = this.seq;\n leafSegment.localSeq = this.localSeq;\n leafSegment.clientId = this.clientId;\n this.segmentGroups.copyTo(leafSegment);\n this.trackingCollection.copyTo(leafSegment);\n if (this.localRefs) {\n this.localRefs.split(pos, leafSegment);\n }\n }\n return leafSegment;\n }\n }\n\n private copyPropertiesTo(other: ISegment) {\n if (this.propertyManager) {\n if (this.properties) {\n other.propertyManager = new PropertiesManager();\n other.properties = this.propertyManager.copyTo(\n this.properties,\n other.properties,\n other.propertyManager,\n );\n }\n }\n }\n\n public abstract clone(): ISegment;\n public abstract append(segment: ISegment): void;\n protected abstract createSplitSegmentAt(pos: number): BaseSegment | undefined;\n}\n\nexport const reservedMarkerIdKey = \"markerId\";\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\nexport interface IJSONMarkerSegment extends IJSONSegment {\n marker: IMarkerDef;\n}\n\nexport class Marker extends BaseSegment implements ReferencePosition {\n public static readonly type = \"Marker\";\n public static is(segment: ISegment): segment is Marker {\n return segment.type === Marker.type;\n }\n public readonly type = Marker.type;\n\n public static make(\n refType: ReferenceType, props?: PropertySet) {\n const marker = new Marker(refType);\n if (props) {\n marker.addProperties(props);\n }\n return marker;\n }\n\n constructor(public refType: ReferenceType) {\n super();\n this.cachedLength = 1;\n }\n\n toJSONObject() {\n const obj: IJSONMarkerSegment = { marker: { refType: this.refType } };\n super.addSerializedProps(obj);\n return obj;\n }\n\n static fromJSONObject(spec: any) {\n if (spec && typeof spec === \"object\" && \"marker\" in spec) {\n return Marker.make(\n spec.marker.refType,\n spec.props as PropertySet);\n }\n return undefined;\n }\n\n clone() {\n const b = Marker.make(this.refType, this.properties);\n this.cloneInto(b);\n return b;\n }\n\n getSegment() {\n return this;\n }\n\n getOffset() {\n return 0;\n }\n\n hasSimpleType(simpleTypeName: string) {\n return !!this.properties &&\n this.properties[reservedMarkerSimpleTypeKey] === simpleTypeName;\n }\n\n getProperties() {\n return this.properties;\n }\n\n getId(): string | undefined {\n if (this.properties && this.properties[reservedMarkerIdKey]) {\n return this.properties[reservedMarkerIdKey] as string;\n }\n }\n\n toString() {\n let bbuf = \"\";\n if (refTypeIncludesFlag(this, ReferenceType.Tile)) {\n bbuf += \"Tile\";\n }\n if (refTypeIncludesFlag(this, ReferenceType.NestBegin)) {\n if (bbuf.length > 0) {\n bbuf += \"; \";\n }\n bbuf += \"RangeBegin\";\n }\n if (refTypeIncludesFlag(this, ReferenceType.NestEnd)) {\n if (bbuf.length > 0) {\n bbuf += \"; \";\n }\n bbuf += \"RangeEnd\";\n }\n let lbuf = \"\";\n const id = this.getId();\n if (id) {\n bbuf += ` (${id}) `;\n }\n const tileLabels = refGetTileLabels(this);\n if (tileLabels) {\n lbuf += \"tile -- \";\n for (let i = 0, len = tileLabels.length; i < len; i++) {\n const tileLabel = tileLabels[i];\n if (i > 0) {\n lbuf += \"; \";\n }\n lbuf += tileLabel;\n }\n }\n const rangeLabels = refGetRangeLabels(this);\n if (rangeLabels) {\n let rangeKind = \"begin\";\n if (refTypeIncludesFlag(this, ReferenceType.NestEnd)) {\n rangeKind = \"end\";\n }\n if (tileLabels) {\n lbuf += \" \";\n }\n lbuf += `range ${rangeKind} -- `;\n const labels = rangeLabels;\n for (let i = 0, len = labels.length; i < len; i++) {\n const rangeLabel = labels[i];\n if (i > 0) {\n lbuf += \"; \";\n }\n lbuf += rangeLabel;\n }\n }\n let pbuf = \"\";\n if (this.properties) {\n pbuf += JSON.stringify(this.properties, (key, value) => {\n // Avoid circular reference when stringifying makers containing handles.\n // (Substitute a debug string instead.)\n const handle = !!value && value.IFluidHandle;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return handle\n ? `#Handle(${handle.routeContext.path}/${handle.path})`\n : value;\n });\n }\n return `M ${bbuf}: ${lbuf} ${pbuf}`;\n }\n\n protected createSplitSegmentAt(pos: number) {\n return undefined;\n }\n\n canAppend(segment: ISegment): boolean {\n return false;\n }\n\n append() { throw new Error(\"Can not append to marker\"); }\n}\n\nexport enum IncrementalExecOp {\n Go,\n Stop,\n Yield,\n}\n\nexport class IncrementalMapState<TContext> {\n op = IncrementalExecOp.Go;\n constructor(\n public block: IMergeBlock,\n public actions: IncrementalSegmentActions<TContext>,\n public pos: number,\n public refSeq: number,\n public clientId: number,\n public context: TContext,\n public start: number,\n public end: number,\n public childIndex = 0,\n ) {\n }\n}\n\nexport class CollaborationWindow {\n clientId = LocalClientId;\n collaborating = false;\n // Lowest-numbered segment in window; no client can reference a state before this one\n minSeq = 0;\n // Highest-numbered segment in window and current\n // reference segment for this client\n currentSeq = 0;\n\n localSeq = 0;\n\n loadFrom(a: CollaborationWindow) {\n this.clientId = a.clientId;\n this.collaborating = a.collaborating;\n this.minSeq = a.minSeq;\n this.currentSeq = a.currentSeq;\n }\n}\n\nexport const compareNumbers = (a: number, b: number) => a - b;\n\nexport const compareStrings = (a: string, b: string) => a.localeCompare(b);\n\nconst indentStrings = [\"\", \" \", \" \"];\nexport function internedSpaces(n: number) {\n if (indentStrings[n] === undefined) {\n indentStrings[n] = \"\";\n for (let i = 0; i < n; i++) {\n indentStrings[n] += \" \";\n }\n }\n return indentStrings[n];\n}\n\nexport interface IConsensusInfo {\n marker: Marker;\n callback: (m: Marker) => void;\n}\n\nexport interface SegmentAccumulator {\n segments: ISegment[];\n}\n\nexport interface MinListener {\n minRequired: number;\n onMinGE(minSeq: number): void;\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ISegment } from "./mergeTree";
5
+ import { ISegment } from "./mergeTreeNodes";
6
6
  export declare class TrackingGroup {
7
7
  private readonly segmentSet;
8
8
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeTracking.d.ts","sourceRoot":"","sources":["../src/mergeTreeTracking.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;;IAM9C,IAAW,QAAQ,IAAI,SAAS,QAAQ,EAAE,CAEzC;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAEM,GAAG,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAI/B,IAAI,CAAC,OAAO,EAAE,QAAQ;IAOtB,MAAM,CAAC,OAAO,EAAE,QAAQ;CAKlC;AAED,qBAAa,uBAAuB;IAGpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,SAAgB,cAAc,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;gBAEtB,OAAO,EAAE,QAAQ;IAIvC,IAAI,CAAC,aAAa,EAAE,aAAa;IAYjC,MAAM,CAAC,aAAa,EAAE,aAAa;IAOnC,MAAM,CAAC,OAAO,EAAE,QAAQ;IAK/B,IAAW,KAAK,IAAI,OAAO,CAE1B;IAEM,OAAO,CAAC,kBAAkB,EAAE,uBAAuB,GAAG,OAAO;CAYvE"}
1
+ {"version":3,"file":"mergeTreeTracking.d.ts","sourceRoot":"","sources":["../src/mergeTreeTracking.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;;IAM9C,IAAW,QAAQ,IAAI,SAAS,QAAQ,EAAE,CAEzC;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAEM,GAAG,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAI/B,IAAI,CAAC,OAAO,EAAE,QAAQ;IAOtB,MAAM,CAAC,OAAO,EAAE,QAAQ;CAKlC;AAED,qBAAa,uBAAuB;IAGpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,SAAgB,cAAc,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;gBAEtB,OAAO,EAAE,QAAQ;IAIvC,IAAI,CAAC,aAAa,EAAE,aAAa;IAYjC,MAAM,CAAC,aAAa,EAAE,aAAa;IAOnC,MAAM,CAAC,OAAO,EAAE,QAAQ;IAK/B,IAAW,KAAK,IAAI,OAAO,CAE1B;IAEM,OAAO,CAAC,kBAAkB,EAAE,uBAAuB,GAAG,OAAO;CAYvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeTracking.js","sourceRoot":"","sources":["../src/mergeTreeTracking.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yDAAsD;AAEtD,MAAa,aAAa;IAGtB;QACI,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAgB,EAAE,CAAC;IAC7C,CAAC;IAED,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,IAAW,IAAI;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SACtC;QACD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IAEM,MAAM,CAAC,OAAiB;QAC3B,IAAI,CAAC,cAAc,CAAC,OAAO,CACvB,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,CAAC;IAC1C,CAAC;IAEM,OAAO,CAAC,kBAA2C;QACtD,IAAI,CAAC,kBAAkB;eAChB,IAAI,CAAC,cAAc,CAAC,IAAI,KAAK,kBAAkB,CAAC,cAAc,CAAC,IAAI,EAAE;YACxE,OAAO,KAAK,CAAC;SAChB;QACD,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;gBAC5C,OAAO,KAAK,CAAC;aAChB;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA/CD,0DA+CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISegment } from \"./mergeTree\";\nimport { SortedSegmentSet } from \"./sortedSegmentSet\";\n\nexport class TrackingGroup {\n private readonly segmentSet: SortedSegmentSet;\n\n constructor() {\n this.segmentSet = new SortedSegmentSet();\n }\n\n public get segments(): readonly ISegment[] {\n return this.segmentSet.items;\n }\n\n public get size(): number {\n return this.segmentSet.size;\n }\n\n public has(segment: ISegment): boolean {\n return this.segmentSet.has(segment);\n }\n\n public link(segment: ISegment) {\n if (!this.segmentSet.has(segment)) {\n this.segmentSet.addOrUpdate(segment);\n segment.trackingCollection.link(this);\n }\n }\n\n public unlink(segment: ISegment) {\n if (this.segmentSet.remove(segment)) {\n segment.trackingCollection.unlink(this);\n }\n }\n}\n\nexport class TrackingGroupCollection {\n public readonly trackingGroups: Set<TrackingGroup>;\n\n constructor(private readonly segment: ISegment) {\n this.trackingGroups = new Set<TrackingGroup>();\n }\n\n public link(trackingGroup: TrackingGroup) {\n if (trackingGroup) {\n if (!this.trackingGroups.has(trackingGroup)) {\n this.trackingGroups.add(trackingGroup);\n }\n\n if (!trackingGroup.has(this.segment)) {\n trackingGroup.link(this.segment);\n }\n }\n }\n\n public unlink(trackingGroup: TrackingGroup) {\n if (trackingGroup.has(this.segment)) {\n trackingGroup.unlink(this.segment);\n }\n this.trackingGroups.delete(trackingGroup);\n }\n\n public copyTo(segment: ISegment) {\n this.trackingGroups.forEach(\n (sg) => segment.trackingCollection.link(sg));\n }\n\n public get empty(): boolean {\n return this.trackingGroups.size === 0;\n }\n\n public matches(trackingCollection: TrackingGroupCollection): boolean {\n if (!trackingCollection\n || this.trackingGroups.size !== trackingCollection.trackingGroups.size) {\n return false;\n }\n for (const tg of this.trackingGroups.values()) {\n if (!trackingCollection.trackingGroups.has(tg)) {\n return false;\n }\n }\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"mergeTreeTracking.js","sourceRoot":"","sources":["../src/mergeTreeTracking.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yDAAsD;AAEtD,MAAa,aAAa;IAGtB;QACI,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAgB,EAAE,CAAC;IAC7C,CAAC;IAED,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;IAEM,GAAG,CAAC,OAAiB;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAEM,IAAI,CAAC,OAAiB;QACzB,IAAI,CAAC,IAAI,CAAC,UAAU,CAA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CAAC,CAAC;IACrD,CAAC;IAED,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,CAAC;IAC1C,CAAC;IAEM,OAAO,CAAC,kBAA2C;QACtD,IAAI,CAAC,kBAAkB;eAChB,IAAI,CAAC,cAAc,CAAC,IAAI,KAAK,kBAAkB,CAAC,cAAc,CAAC,IAAI,EAAE;YACxE,OAAO,KAAK,CAAC;SAChB;QACD,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;gBAC5C,OAAO,KAAK,CAAC;aAChB;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA/CD,0DA+CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISegment } from \"./mergeTreeNodes\";\nimport { SortedSegmentSet } from \"./sortedSegmentSet\";\n\nexport class TrackingGroup {\n private readonly segmentSet: SortedSegmentSet;\n\n constructor() {\n this.segmentSet = new SortedSegmentSet();\n }\n\n public get segments(): readonly ISegment[] {\n return this.segmentSet.items;\n }\n\n public get size(): number {\n return this.segmentSet.size;\n }\n\n public has(segment: ISegment): boolean {\n return this.segmentSet.has(segment);\n }\n\n public link(segment: ISegment) {\n if (!this.segmentSet.has(segment)) {\n this.segmentSet.addOrUpdate(segment);\n segment.trackingCollection.link(this);\n }\n }\n\n public unlink(segment: ISegment) {\n if (this.segmentSet.remove(segment)) {\n segment.trackingCollection.unlink(this);\n }\n }\n}\n\nexport class TrackingGroupCollection {\n public readonly trackingGroups: Set<TrackingGroup>;\n\n constructor(private readonly segment: ISegment) {\n this.trackingGroups = new Set<TrackingGroup>();\n }\n\n public link(trackingGroup: TrackingGroup) {\n if (trackingGroup) {\n if (!this.trackingGroups.has(trackingGroup)) {\n this.trackingGroups.add(trackingGroup);\n }\n\n if (!trackingGroup.has(this.segment)) {\n trackingGroup.link(this.segment);\n }\n }\n }\n\n public unlink(trackingGroup: TrackingGroup) {\n if (trackingGroup.has(this.segment)) {\n trackingGroup.unlink(this.segment);\n }\n this.trackingGroups.delete(trackingGroup);\n }\n\n public copyTo(segment: ISegment) {\n this.trackingGroups.forEach(\n (sg) => segment.trackingCollection.link(sg));\n }\n\n public get empty(): boolean {\n return this.trackingGroups.size === 0;\n }\n\n public matches(trackingCollection: TrackingGroupCollection): boolean {\n if (!trackingCollection\n || this.trackingGroups.size !== trackingCollection.trackingGroups.size) {\n return false;\n }\n for (const tg of this.trackingGroups.values()) {\n if (!trackingCollection.trackingGroups.has(tg)) {\n return false;\n }\n }\n return true;\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ISegment, Marker } from "./mergeTree";
5
+ import { ISegment, Marker } from "./mergeTreeNodes";
6
6
  import { ICombiningOp, IMergeTreeAnnotateMsg, IMergeTreeGroupMsg, IMergeTreeInsertMsg, IMergeTreeRemoveMsg, IMergeTreeDeltaOp } from "./ops";
7
7
  import { PropertySet } from "./properties";
8
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"opBuilder.d.ts","sourceRoot":"","sources":["../src/opBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACH,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EAEnB,iBAAiB,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,YA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AO;QACH,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,wBAAkB,CAAC,MAAM;KAClC,CAAC;AACN,CAAC;AAND,kDAMC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,GAAW,EAAE,OAAiB;IAChE,OAAO,cAAc,CACjB,GAAG,EACH,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;AAChC,CAAC;AAJD,sDAIC;AAED,SAAgB,cAAc,CAAC,GAAW,EAAE,OAAY;IACpD,OAAO;QACH,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,wBAAkB,CAAC,MAAM;KAClC,CAAC;AACN,CAAC;AAND,wCAMC;AAED;;;GAGG;AACH,SAAgB,aAAa,CACzB,GAAG,GAAwB;IAC3B,OAAO;QACH,GAAG;QACH,IAAI,EAAE,wBAAkB,CAAC,KAAK;KACjC,CAAC;AACN,CAAC;AAND,sCAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISegment, Marker } from \"./mergeTree\";\nimport {\n ICombiningOp,\n IMergeTreeAnnotateMsg,\n IMergeTreeGroupMsg,\n IMergeTreeInsertMsg,\n IMergeTreeRemoveMsg,\n MergeTreeDeltaType,\n IMergeTreeDeltaOp,\n} from \"./ops\";\nimport { PropertySet } from \"./properties\";\n\n/**\n * Creates the op for annotating the markers with the provided properties\n * @param marker - The marker to annotate\n * @param props - The properties to annotate the marker with\n * @param combiningOp - Optional. Specifies how to combine values for the property, such as \"incr\" for increment.\n * @returns The annotate op\n */\nexport function createAnnotateMarkerOp(\n marker: Marker, props: PropertySet, combiningOp?: ICombiningOp): IMergeTreeAnnotateMsg | undefined {\n const id = marker.getId();\n if (!id) {\n return undefined;\n }\n\n return {\n combiningOp,\n props,\n relativePos1: { id, before: true },\n relativePos2: { id },\n type: MergeTreeDeltaType.ANNOTATE,\n };\n}\n\n/**\n * Creates the op for annotating the range with the provided properties\n * @param start - The inclusive start position of the range to annotate\n * @param end - The exclusive end position of the range to annotate\n * @param props - The properties to annotate the range with\n * @param combiningOp - Optional. Specifies how to combine values for the property, such as \"incr\" for increment.\n * @returns The annotate op\n */\nexport function createAnnotateRangeOp(\n start: number, end: number, props: PropertySet, combiningOp: ICombiningOp | undefined): IMergeTreeAnnotateMsg {\n return {\n combiningOp,\n pos1: start,\n pos2: end,\n props,\n type: MergeTreeDeltaType.ANNOTATE,\n };\n}\n\n/**\n * Creates the op to remove a range\n *\n * @param start - The inclusive start of the range to remove\n * @param end - The exclusive end of the range to remove\n */\nexport function createRemoveRangeOp(start: number, end: number): IMergeTreeRemoveMsg {\n return {\n pos1: start,\n pos2: end,\n type: MergeTreeDeltaType.REMOVE,\n };\n}\n\n/**\n *\n * @param pos - The position to insert the segment at\n * @param segment - The segment to insert\n */\nexport function createInsertSegmentOp(pos: number, segment: ISegment): IMergeTreeInsertMsg {\n return createInsertOp(\n pos,\n segment.toJSONObject());\n}\n\nexport function createInsertOp(pos: number, segSpec: any): IMergeTreeInsertMsg {\n return {\n pos1: pos,\n seg: segSpec,\n type: MergeTreeDeltaType.INSERT,\n };\n}\n\n/**\n *\n * @param ops - The ops to group\n */\nexport function createGroupOp(\n ...ops: IMergeTreeDeltaOp[]): IMergeTreeGroupMsg {\n return {\n ops,\n type: MergeTreeDeltaType.GROUP,\n };\n}\n"]}
1
+ {"version":3,"file":"opBuilder.js","sourceRoot":"","sources":["../src/opBuilder.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+BAQe;AAGf;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAClC,MAAc,EAAE,KAAkB,EAAE,WAA0B;IAC9D,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,IAAI,CAAC,EAAE,EAAE;QACL,OAAO,SAAS,CAAC;KACpB;IAED,OAAO;QACH,WAAW;QACX,KAAK;QACL,YAAY,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;QAClC,YAAY,EAAE,EAAE,EAAE,EAAE;QACpB,IAAI,EAAE,wBAAkB,CAAC,QAAQ;KACpC,CAAC;AACN,CAAC;AAdD,wDAcC;AAED;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACjC,KAAa,EAAE,GAAW,EAAE,KAAkB,EAAE,WAAqC;IACrF,OAAO;QACH,WAAW;QACX,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,GAAG;QACT,KAAK;QACL,IAAI,EAAE,wBAAkB,CAAC,QAAQ;KACpC,CAAC;AACN,CAAC;AATD,sDASC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa,EAAE,GAAW;IAC1D,OAAO;QACH,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,wBAAkB,CAAC,MAAM;KAClC,CAAC;AACN,CAAC;AAND,kDAMC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,GAAW,EAAE,OAAiB;IAChE,OAAO,cAAc,CACjB,GAAG,EACH,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;AAChC,CAAC;AAJD,sDAIC;AAED,SAAgB,cAAc,CAAC,GAAW,EAAE,OAAY;IACpD,OAAO;QACH,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,wBAAkB,CAAC,MAAM;KAClC,CAAC;AACN,CAAC;AAND,wCAMC;AAED;;;GAGG;AACH,SAAgB,aAAa,CACzB,GAAG,GAAwB;IAC3B,OAAO;QACH,GAAG;QACH,IAAI,EAAE,wBAAkB,CAAC,KAAK;KACjC,CAAC;AACN,CAAC;AAND,sCAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISegment, Marker } from \"./mergeTreeNodes\";\nimport {\n ICombiningOp,\n IMergeTreeAnnotateMsg,\n IMergeTreeGroupMsg,\n IMergeTreeInsertMsg,\n IMergeTreeRemoveMsg,\n MergeTreeDeltaType,\n IMergeTreeDeltaOp,\n} from \"./ops\";\nimport { PropertySet } from \"./properties\";\n\n/**\n * Creates the op for annotating the markers with the provided properties\n * @param marker - The marker to annotate\n * @param props - The properties to annotate the marker with\n * @param combiningOp - Optional. Specifies how to combine values for the property, such as \"incr\" for increment.\n * @returns The annotate op\n */\nexport function createAnnotateMarkerOp(\n marker: Marker, props: PropertySet, combiningOp?: ICombiningOp): IMergeTreeAnnotateMsg | undefined {\n const id = marker.getId();\n if (!id) {\n return undefined;\n }\n\n return {\n combiningOp,\n props,\n relativePos1: { id, before: true },\n relativePos2: { id },\n type: MergeTreeDeltaType.ANNOTATE,\n };\n}\n\n/**\n * Creates the op for annotating the range with the provided properties\n * @param start - The inclusive start position of the range to annotate\n * @param end - The exclusive end position of the range to annotate\n * @param props - The properties to annotate the range with\n * @param combiningOp - Optional. Specifies how to combine values for the property, such as \"incr\" for increment.\n * @returns The annotate op\n */\nexport function createAnnotateRangeOp(\n start: number, end: number, props: PropertySet, combiningOp: ICombiningOp | undefined): IMergeTreeAnnotateMsg {\n return {\n combiningOp,\n pos1: start,\n pos2: end,\n props,\n type: MergeTreeDeltaType.ANNOTATE,\n };\n}\n\n/**\n * Creates the op to remove a range\n *\n * @param start - The inclusive start of the range to remove\n * @param end - The exclusive end of the range to remove\n */\nexport function createRemoveRangeOp(start: number, end: number): IMergeTreeRemoveMsg {\n return {\n pos1: start,\n pos2: end,\n type: MergeTreeDeltaType.REMOVE,\n };\n}\n\n/**\n *\n * @param pos - The position to insert the segment at\n * @param segment - The segment to insert\n */\nexport function createInsertSegmentOp(pos: number, segment: ISegment): IMergeTreeInsertMsg {\n return createInsertOp(\n pos,\n segment.toJSONObject());\n}\n\nexport function createInsertOp(pos: number, segSpec: any): IMergeTreeInsertMsg {\n return {\n pos1: pos,\n seg: segSpec,\n type: MergeTreeDeltaType.INSERT,\n };\n}\n\n/**\n *\n * @param ops - The ops to group\n */\nexport function createGroupOp(\n ...ops: IMergeTreeDeltaOp[]): IMergeTreeGroupMsg {\n return {\n ops,\n type: MergeTreeDeltaType.GROUP,\n };\n}\n"]}