@fluidframework/merge-tree 0.59.2001 → 0.59.3000

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 (93) hide show
  1. package/.eslintrc.js +0 -1
  2. package/dist/client.d.ts +15 -4
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +60 -34
  5. package/dist/client.js.map +1 -1
  6. package/dist/collections.d.ts +7 -1
  7. package/dist/collections.d.ts.map +1 -1
  8. package/dist/collections.js +27 -1
  9. package/dist/collections.js.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/localReference.d.ts +104 -10
  15. package/dist/localReference.d.ts.map +1 -1
  16. package/dist/localReference.js +152 -96
  17. package/dist/localReference.js.map +1 -1
  18. package/dist/mergeTree.d.ts +28 -21
  19. package/dist/mergeTree.d.ts.map +1 -1
  20. package/dist/mergeTree.js +100 -88
  21. package/dist/mergeTree.js.map +1 -1
  22. package/dist/partialLengths.js +10 -10
  23. package/dist/partialLengths.js.map +1 -1
  24. package/dist/referencePositions.d.ts +55 -0
  25. package/dist/referencePositions.d.ts.map +1 -0
  26. package/dist/referencePositions.js +93 -0
  27. package/dist/referencePositions.js.map +1 -0
  28. package/dist/segmentGroupCollection.js +1 -1
  29. package/dist/segmentGroupCollection.js.map +1 -1
  30. package/dist/segmentPropertiesManager.js +5 -5
  31. package/dist/segmentPropertiesManager.js.map +1 -1
  32. package/dist/snapshotChunks.js.map +1 -1
  33. package/dist/snapshotLoader.d.ts.map +1 -1
  34. package/dist/snapshotLoader.js +9 -9
  35. package/dist/snapshotLoader.js.map +1 -1
  36. package/dist/snapshotV1.js +7 -7
  37. package/dist/snapshotV1.js.map +1 -1
  38. package/dist/snapshotlegacy.js +6 -6
  39. package/dist/snapshotlegacy.js.map +1 -1
  40. package/dist/sortedSegmentSet.d.ts.map +1 -1
  41. package/dist/sortedSegmentSet.js +1 -1
  42. package/dist/sortedSegmentSet.js.map +1 -1
  43. package/dist/textSegment.js +3 -2
  44. package/dist/textSegment.js.map +1 -1
  45. package/lib/client.d.ts +15 -4
  46. package/lib/client.d.ts.map +1 -1
  47. package/lib/client.js +31 -5
  48. package/lib/client.js.map +1 -1
  49. package/lib/collections.d.ts +7 -1
  50. package/lib/collections.d.ts.map +1 -1
  51. package/lib/collections.js +26 -1
  52. package/lib/collections.js.map +1 -1
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.d.ts.map +1 -1
  55. package/lib/index.js +1 -0
  56. package/lib/index.js.map +1 -1
  57. package/lib/localReference.d.ts +104 -10
  58. package/lib/localReference.d.ts.map +1 -1
  59. package/lib/localReference.js +146 -90
  60. package/lib/localReference.js.map +1 -1
  61. package/lib/mergeTree.d.ts +28 -21
  62. package/lib/mergeTree.d.ts.map +1 -1
  63. package/lib/mergeTree.js +67 -51
  64. package/lib/mergeTree.js.map +1 -1
  65. package/lib/referencePositions.d.ts +55 -0
  66. package/lib/referencePositions.d.ts.map +1 -0
  67. package/lib/referencePositions.js +80 -0
  68. package/lib/referencePositions.js.map +1 -0
  69. package/lib/segmentPropertiesManager.js.map +1 -1
  70. package/lib/snapshotChunks.js.map +1 -1
  71. package/lib/snapshotLoader.d.ts.map +1 -1
  72. package/lib/snapshotLoader.js.map +1 -1
  73. package/lib/snapshotV1.js.map +1 -1
  74. package/lib/snapshotlegacy.js +1 -1
  75. package/lib/snapshotlegacy.js.map +1 -1
  76. package/lib/sortedSegmentSet.d.ts.map +1 -1
  77. package/lib/sortedSegmentSet.js +1 -1
  78. package/lib/sortedSegmentSet.js.map +1 -1
  79. package/lib/textSegment.js +3 -2
  80. package/lib/textSegment.js.map +1 -1
  81. package/package.json +161 -14
  82. package/src/client.ts +45 -19
  83. package/src/collections.ts +55 -54
  84. package/src/index.ts +1 -0
  85. package/src/localReference.ts +190 -100
  86. package/src/mergeTree.ts +107 -99
  87. package/src/referencePositions.ts +126 -0
  88. package/src/snapshotChunks.ts +8 -8
  89. package/src/snapshotLoader.ts +4 -4
  90. package/src/snapshotV1.ts +1 -1
  91. package/src/snapshotlegacy.ts +2 -2
  92. package/src/sortedSegmentSet.ts +4 -4
  93. package/src/textSegment.ts +2 -2
@@ -6,79 +6,97 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.LocalReferenceCollection = exports.LocalReference = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
- const mergeTree_1 = require("./mergeTree");
9
+ const collections_1 = require("./collections");
10
10
  const ops_1 = require("./ops");
11
11
  const properties_1 = require("./properties");
12
+ const referencePositions_1 = require("./referencePositions");
13
+ /**
14
+ * @deprecated - Use ReferencePosition
15
+ */
12
16
  class LocalReference {
13
- constructor(client, initSegment, offset = 0, refType = ops_1.ReferenceType.Simple) {
17
+ /**
18
+ * @deprecated - use createReferencePosition
19
+ */
20
+ constructor(client, initSegment,
21
+ /**
22
+ * @deprecated - use getOffset
23
+ */
24
+ offset = 0, refType = ops_1.ReferenceType.Simple, properties) {
14
25
  this.client = client;
15
26
  this.offset = offset;
16
27
  this.refType = refType;
17
28
  this.segment = initSegment;
29
+ this.properties = properties;
18
30
  }
31
+ /**
32
+ * @deprecated - use minReferencePosition
33
+ */
19
34
  min(b) {
20
- if (this.compare(b) < 0) {
21
- return this;
22
- }
23
- else {
24
- return b;
25
- }
35
+ return (0, referencePositions_1.minReferencePosition)(this, b);
26
36
  }
37
+ /**
38
+ * @deprecated - use maxReferencePosition
39
+ */
27
40
  max(b) {
28
- if (this.compare(b) > 0) {
29
- return this;
30
- }
31
- else {
32
- return b;
33
- }
41
+ return (0, referencePositions_1.maxReferencePosition)(this, b);
34
42
  }
43
+ /**
44
+ * @deprecated - use compareReferencePositions
45
+ */
35
46
  compare(b) {
36
- if (this.segment === b.segment) {
37
- return this.offset - b.offset;
38
- }
39
- else {
40
- if (this.segment === undefined
41
- || (b.segment !== undefined &&
42
- this.segment.ordinal < b.segment.ordinal)) {
43
- return -1;
44
- }
45
- else {
46
- return 1;
47
- }
48
- }
47
+ return (0, referencePositions_1.compareReferencePositions)(this, b);
49
48
  }
49
+ /**
50
+ * @deprecated - use getLocalReferencePosition
51
+ */
50
52
  toPosition() {
51
- if (this.segment && this.segment.parent) {
52
- return this.getOffset() + this.client.getPosition(this.segment);
53
- }
54
- else {
55
- return LocalReference.DetachedPosition;
56
- }
53
+ return this.getClient().localReferencePositionToPosition(this);
57
54
  }
55
+ /**
56
+ * @deprecated - use refHasTileLabels
57
+ */
58
58
  hasTileLabels() {
59
- return !!this.getTileLabels();
59
+ return (0, referencePositions_1.refHasTileLabels)(this);
60
60
  }
61
+ /**
62
+ * @deprecated - use refHasRangeLabels
63
+ */
61
64
  hasRangeLabels() {
62
- return !!this.getRangeLabels();
65
+ return (0, referencePositions_1.refHasRangeLabels)(this);
63
66
  }
67
+ /**
68
+ * @deprecated - use refHasTileLabel
69
+ */
64
70
  hasTileLabel(label) {
65
- return mergeTree_1.refHasTileLabel(this, label);
71
+ return (0, referencePositions_1.refHasTileLabel)(this, label);
66
72
  }
73
+ /**
74
+ * @deprecated - use refHasRangeLabel
75
+ */
67
76
  hasRangeLabel(label) {
68
- return mergeTree_1.refHasRangeLabel(this, label);
77
+ return (0, referencePositions_1.refHasRangeLabel)(this, label);
69
78
  }
79
+ /**
80
+ * @deprecated - use refGetTileLabels
81
+ */
70
82
  getTileLabels() {
71
- return mergeTree_1.refGetTileLabels(this);
83
+ return (0, referencePositions_1.refGetTileLabels)(this);
72
84
  }
85
+ /**
86
+ * @deprecated - use refGetRangeLabels
87
+ */
73
88
  getRangeLabels() {
74
- return mergeTree_1.refGetRangeLabels(this);
89
+ return (0, referencePositions_1.refGetRangeLabels)(this);
75
90
  }
76
91
  isLeaf() {
77
92
  return false;
78
93
  }
79
94
  addProperties(newProps, op) {
80
- this.properties = properties_1.addProperties(this.properties, newProps, op);
95
+ this.properties = (0, properties_1.addProperties)(this.properties, newProps, op);
81
96
  }
97
+ /**
98
+ * @deprecated - no longer supported
99
+ */
82
100
  getClient() {
83
101
  return this.client;
84
102
  }
@@ -97,15 +115,29 @@ class LocalReference {
97
115
  }
98
116
  }
99
117
  exports.LocalReference = LocalReference;
118
+ /**
119
+ * @deprecated - use DetachedReferencePosition
120
+ */
100
121
  LocalReference.DetachedPosition = -1;
122
+ function assertLocalReferences(lref) {
123
+ (0, common_utils_1.assert)(lref instanceof LocalReference, 0x2e0 /* "lref not a Local Reference" */);
124
+ }
101
125
  /**
102
- * Represents a collection of {@link LocalReference}s associated with one segment in a merge-tree.
126
+ * Represents a collection of {@link ReferencePosition}s associated with one segment in a merge-tree.
103
127
  */
104
128
  class LocalReferenceCollection {
129
+ /**
130
+ *
131
+ * @internal - this method should only be called by mergeTree
132
+ */
105
133
  constructor(
106
134
  /** Segment this `LocalReferenceCollection` is associated to. */
107
135
  segment, initialRefsByfOffset = new Array(segment.cachedLength)) {
108
136
  this.segment = segment;
137
+ /**
138
+ *
139
+ * @internal - this method should only be called by mergeTree
140
+ */
109
141
  this.hierRefCount = 0;
110
142
  this.refCount = 0;
111
143
  // Since javascript arrays are sparse the above won't populate any of the
@@ -118,7 +150,7 @@ class LocalReferenceCollection {
118
150
  if (!seg1.localRefs) {
119
151
  seg1.localRefs = new LocalReferenceCollection(seg1);
120
152
  }
121
- common_utils_1.assert(seg1.localRefs.refsByOffset.length === seg1.cachedLength, 0x2be /* "LocalReferences array contains a gap" */);
153
+ (0, common_utils_1.assert)(seg1.localRefs.refsByOffset.length === seg1.cachedLength, 0x2be /* "LocalReferences array contains a gap" */);
122
154
  seg1.localRefs.append(seg2.localRefs);
123
155
  }
124
156
  else if (seg1.localRefs) {
@@ -127,6 +159,10 @@ class LocalReferenceCollection {
127
159
  seg1.localRefs.refsByOffset.length += seg2.cachedLength;
128
160
  }
129
161
  }
162
+ /**
163
+ *
164
+ * @internal - this method should only be called by mergeTree
165
+ */
130
166
  [Symbol.iterator]() {
131
167
  const subiterators = [];
132
168
  for (const refs of this.refsByOffset) {
@@ -161,16 +197,20 @@ class LocalReferenceCollection {
161
197
  };
162
198
  return iterator;
163
199
  }
200
+ /**
201
+ *
202
+ * @internal - this method should only be called by mergeTree
203
+ */
164
204
  clear() {
165
205
  this.refCount = 0;
166
206
  this.hierRefCount = 0;
167
207
  const detachSegments = (refs) => {
168
208
  if (refs) {
169
- refs.forEach((r) => {
209
+ for (const r of refs) {
170
210
  if (r.segment === this.segment) {
171
211
  r.segment = undefined;
172
212
  }
173
- });
213
+ }
174
214
  }
175
215
  };
176
216
  for (let i = 0; i < this.refsByOffset.length; i++) {
@@ -183,40 +223,62 @@ class LocalReferenceCollection {
183
223
  }
184
224
  }
185
225
  }
226
+ /**
227
+ *
228
+ * @internal - this method should only be called by mergeTree
229
+ */
186
230
  get empty() {
187
231
  return this.refCount === 0;
188
232
  }
189
- addLocalRef(lref) {
190
- const refsAtOffset = this.refsByOffset[lref.offset];
191
- if (refsAtOffset === undefined) {
192
- this.refsByOffset[lref.offset] = {
193
- at: [lref],
194
- };
195
- }
196
- else if (refsAtOffset.at === undefined) {
197
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
198
- this.refsByOffset[lref.offset].at = [lref];
199
- }
200
- else {
201
- refsAtOffset.at.push(lref);
233
+ /**
234
+ *
235
+ * @internal - this method should only be called by mergeTree
236
+ */
237
+ createLocalRef(offset, refType, properties, client) {
238
+ const ref = new LocalReference(client, this.segment, offset, refType, properties);
239
+ if (!(0, referencePositions_1.refTypeIncludesFlag)(ref, ops_1.ReferenceType.Transient)) {
240
+ this.addLocalRef(ref);
202
241
  }
203
- if (lref.hasRangeLabels() || lref.hasTileLabels()) {
242
+ return ref;
243
+ }
244
+ /**
245
+ *
246
+ * @internal - this method should only be called by mergeTree
247
+ */
248
+ addLocalRef(lref) {
249
+ var _a, _b;
250
+ (0, common_utils_1.assert)(!(0, referencePositions_1.refTypeIncludesFlag)(lref, ops_1.ReferenceType.Transient), 0x2df /* "transient references cannot be bound to segments" */);
251
+ assertLocalReferences(lref);
252
+ const refsAtOffset = this.refsByOffset[lref.getOffset()] =
253
+ (_a = this.refsByOffset[lref.getOffset()]) !== null && _a !== void 0 ? _a : { at: (0, collections_1.ListMakeHead)() };
254
+ const atRefs = refsAtOffset.at =
255
+ (_b = refsAtOffset.at) !== null && _b !== void 0 ? _b : (0, collections_1.ListMakeHead)();
256
+ atRefs.enqueue(lref);
257
+ if ((0, referencePositions_1.refHasRangeLabels)(lref) || (0, referencePositions_1.refHasTileLabels)(lref)) {
204
258
  this.hierRefCount++;
205
259
  }
206
260
  this.refCount++;
207
261
  }
262
+ /**
263
+ *
264
+ * @internal - this method should only be called by mergeTree
265
+ */
208
266
  removeLocalRef(lref) {
267
+ assertLocalReferences(lref);
209
268
  const tryRemoveRef = (refs) => {
210
269
  if (refs) {
211
- const index = refs.indexOf(lref);
212
- if (index >= 0) {
213
- refs.splice(index, 1);
214
- if (lref.hasRangeLabels() || lref.hasTileLabels()) {
215
- this.hierRefCount--;
270
+ let node = refs;
271
+ do {
272
+ node = node.next;
273
+ if (node.data === lref) {
274
+ (0, collections_1.ListRemoveEntry)(node);
275
+ if ((0, referencePositions_1.refHasRangeLabels)(lref) || (0, referencePositions_1.refHasTileLabels)(lref)) {
276
+ this.hierRefCount--;
277
+ }
278
+ this.refCount--;
279
+ return lref;
216
280
  }
217
- this.refCount--;
218
- return lref;
219
- }
281
+ } while (!node.isHead);
220
282
  }
221
283
  };
222
284
  const refAtOffset = this.refsByOffset[lref.offset];
@@ -236,6 +298,8 @@ class LocalReferenceCollection {
236
298
  }
237
299
  }
238
300
  /**
301
+ * @internal - this method should only be called by mergeTree
302
+ *
239
303
  * Called by 'append()' implementations to append local refs from the given 'other' segment to the
240
304
  * end of 'this' segment.
241
305
  *
@@ -257,6 +321,8 @@ class LocalReferenceCollection {
257
321
  this.refsByOffset.push(...other.refsByOffset);
258
322
  }
259
323
  /**
324
+ * @internal - this method should only be called by mergeTree
325
+ *
260
326
  * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).
261
327
  * Local references in the former half of this split will remain associated with the segment used on construction.
262
328
  * Local references in the latter half of this split will be transferred to `splitSeg`,
@@ -272,7 +338,7 @@ class LocalReferenceCollection {
272
338
  for (const lref of localRefs) {
273
339
  lref.segment = splitSeg;
274
340
  lref.offset -= offset;
275
- if (lref.hasRangeLabels() || lref.hasTileLabels()) {
341
+ if ((0, referencePositions_1.refHasRangeLabels)(lref) || (0, referencePositions_1.refHasTileLabels)(lref)) {
276
342
  this.hierRefCount--;
277
343
  localRefs.hierRefCount++;
278
344
  }
@@ -286,15 +352,16 @@ class LocalReferenceCollection {
286
352
  }
287
353
  }
288
354
  addBeforeTombstones(...refs) {
289
- const beforeRefs = [];
355
+ var _a, _b, _c, _d, _e;
356
+ const beforeRefs = (_b = (_a = this.refsByOffset[0]) === null || _a === void 0 ? void 0 : _a.before) !== null && _b !== void 0 ? _b : (0, collections_1.ListMakeHead)();
290
357
  for (const iterable of refs) {
291
358
  for (const lref of iterable) {
292
- // eslint-disable-next-line no-bitwise
293
- if (lref.refType & ops_1.ReferenceType.SlideOnRemove) {
359
+ assertLocalReferences(lref);
360
+ if ((0, referencePositions_1.refTypeIncludesFlag)(lref, ops_1.ReferenceType.SlideOnRemove)) {
294
361
  beforeRefs.push(lref);
295
362
  lref.segment = this.segment;
296
363
  lref.offset = 0;
297
- if (lref.hasRangeLabels() || lref.hasTileLabels()) {
364
+ if ((0, referencePositions_1.refHasRangeLabels)(lref) || (0, referencePositions_1.refHasTileLabels)(lref)) {
298
365
  this.hierRefCount++;
299
366
  }
300
367
  this.refCount++;
@@ -304,28 +371,24 @@ class LocalReferenceCollection {
304
371
  }
305
372
  }
306
373
  }
307
- if (beforeRefs.length > 0) {
308
- if (this.refsByOffset[0] === undefined) {
309
- this.refsByOffset[0] = { before: beforeRefs };
310
- }
311
- else if (this.refsByOffset[0].before === undefined) {
312
- this.refsByOffset[0].before = beforeRefs;
313
- }
314
- else {
315
- this.refsByOffset[0].before.unshift(...beforeRefs);
316
- }
374
+ if (!beforeRefs.empty() && ((_c = this.refsByOffset[0]) === null || _c === void 0 ? void 0 : _c.before) === undefined) {
375
+ const refsAtOffset = this.refsByOffset[0] =
376
+ (_d = this.refsByOffset[0]) !== null && _d !== void 0 ? _d : { before: beforeRefs };
377
+ refsAtOffset.before = (_e = refsAtOffset.before) !== null && _e !== void 0 ? _e : beforeRefs;
317
378
  }
318
379
  }
319
380
  addAfterTombstones(...refs) {
320
- const afterRefs = [];
381
+ var _a, _b, _c, _d, _e;
382
+ const lastOffset = this.refsByOffset.length - 1;
383
+ const afterRefs = (_b = (_a = this.refsByOffset[lastOffset]) === null || _a === void 0 ? void 0 : _a.after) !== null && _b !== void 0 ? _b : (0, collections_1.ListMakeHead)();
321
384
  for (const iterable of refs) {
322
385
  for (const lref of iterable) {
323
- // eslint-disable-next-line no-bitwise
324
- if (lref.refType & ops_1.ReferenceType.SlideOnRemove) {
386
+ assertLocalReferences(lref);
387
+ if ((0, referencePositions_1.refTypeIncludesFlag)(lref, ops_1.ReferenceType.SlideOnRemove)) {
325
388
  afterRefs.push(lref);
326
389
  lref.segment = this.segment;
327
390
  lref.offset = this.segment.cachedLength - 1;
328
- if (lref.hasRangeLabels() || lref.hasTileLabels()) {
391
+ if ((0, referencePositions_1.refHasRangeLabels)(lref) || (0, referencePositions_1.refHasTileLabels)(lref)) {
329
392
  this.hierRefCount++;
330
393
  }
331
394
  this.refCount++;
@@ -335,17 +398,10 @@ class LocalReferenceCollection {
335
398
  }
336
399
  }
337
400
  }
338
- if (afterRefs.length > 0) {
339
- const refsAtOffset = this.refsByOffset[this.segment.cachedLength - 1];
340
- if (refsAtOffset === undefined) {
341
- this.refsByOffset[this.segment.cachedLength - 1] = { after: afterRefs };
342
- }
343
- else if (refsAtOffset.after === undefined) {
344
- refsAtOffset.after = afterRefs;
345
- }
346
- else {
347
- refsAtOffset.after.push(...afterRefs);
348
- }
401
+ if (!afterRefs.empty() && ((_c = this.refsByOffset[lastOffset]) === null || _c === void 0 ? void 0 : _c.after) === undefined) {
402
+ const refsAtOffset = this.refsByOffset[lastOffset] =
403
+ (_d = this.refsByOffset[lastOffset]) !== null && _d !== void 0 ? _d : { after: afterRefs };
404
+ refsAtOffset.after = (_e = refsAtOffset.after) !== null && _e !== void 0 ? _e : afterRefs;
349
405
  }
350
406
  }
351
407
  }
@@ -1 +1 @@
1
- {"version":3,"file":"localReference.js","sourceRoot":"","sources":["../src/localReference.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD,2CAOqB;AACrB,+BAAoD;AACpD,6CAA0D;AAE1D,MAAa,cAAc;IAOvB,YACqB,MAAc,EAC/B,WAAqB,EACd,SAAS,CAAC,EACV,UAAU,mBAAa,CAAC,MAAM;QAHpB,WAAM,GAAN,MAAM,CAAQ;QAExB,WAAM,GAAN,MAAM,CAAI;QACV,YAAO,GAAP,OAAO,CAAuB;QAErC,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;IAC/B,CAAC;IAEM,GAAG,CAAC,CAAiB;QACxB,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,CAAC,CAAC;SACZ;IACL,CAAC;IAEM,GAAG,CAAC,CAAiB;QACxB,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,CAAC,CAAC;SACZ;IACL,CAAC;IAEM,OAAO,CAAC,CAAiB;QAC5B,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,EAAE;YAC5B,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;SACjC;aAAM;YACH,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;mBACvB,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS;oBACvB,IAA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G,mBAAa,CAAC,aAAa,EAAE;oBAC5C,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACrB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;oBAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC,CAAC;oBAC5C,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;wBAC/C,IAAI,CAAC,YAAY,EAAE,CAAC;qBACvB;oBACD,IAAI,CAAC,QAAQ,EAAE,CAAC;iBACnB;qBAAM;oBACH,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;iBAC5B;aACJ;SACJ;QACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;YACtB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;YACtE,IAAI,YAAY,KAAK,SAAS,EAAE;gBAC5B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;aAC3E;iBAAM,IAAI,YAAY,CAAC,KAAK,KAAK,SAAS,EAAE;gBACzC,YAAY,CAAC,KAAK,GAAG,SAAS,CAAC;aAClC;iBAAM;gBACH,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;aACzC;SACJ;IACL,CAAC;CACJ;AAtQD,4DAsQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { Client } from \"./client\";\nimport {\n ISegment,\n ReferencePosition,\n refGetRangeLabels,\n refGetTileLabels,\n refHasRangeLabel,\n refHasTileLabel,\n} from \"./mergeTree\";\nimport { ICombiningOp, ReferenceType } from \"./ops\";\nimport { addProperties, PropertySet } from \"./properties\";\n\nexport class LocalReference implements ReferencePosition {\n public static readonly DetachedPosition: number = -1;\n\n public properties: PropertySet | undefined;\n public pairedRef?: LocalReference;\n public segment: ISegment | undefined;\n\n constructor(\n private readonly client: Client,\n initSegment: ISegment,\n public offset = 0,\n public refType = ReferenceType.Simple,\n ) {\n this.segment = initSegment;\n }\n\n public min(b: LocalReference) {\n if (this.compare(b) < 0) {\n return this;\n } else {\n return b;\n }\n }\n\n public max(b: LocalReference) {\n if (this.compare(b) > 0) {\n return this;\n } else {\n return b;\n }\n }\n\n public compare(b: LocalReference) {\n if (this.segment === b.segment) {\n return this.offset - b.offset;\n } else {\n if (this.segment === undefined\n || (b.segment !== undefined &&\n this.segment.ordinal < b.segment.ordinal)) {\n return -1;\n } else {\n return 1;\n }\n }\n }\n\n public toPosition() {\n if (this.segment && this.segment.parent) {\n return this.getOffset() + this.client.getPosition(this.segment);\n } else {\n return LocalReference.DetachedPosition;\n }\n }\n\n public hasTileLabels() {\n return !!this.getTileLabels();\n }\n\n public hasRangeLabels() {\n return !!this.getRangeLabels();\n }\n\n public hasTileLabel(label: string): boolean {\n return refHasTileLabel(this, label);\n }\n\n public hasRangeLabel(label: string): boolean {\n return refHasRangeLabel(this, label);\n }\n\n public getTileLabels(): string[] | undefined {\n return refGetTileLabels(this);\n }\n\n public getRangeLabels(): string[] | undefined {\n return refGetRangeLabels(this);\n }\n\n public isLeaf() {\n return false;\n }\n\n public addProperties(newProps: PropertySet, op?: ICombiningOp) {\n this.properties = addProperties(this.properties, newProps, op);\n }\n\n public getClient() {\n return this.client;\n }\n\n public getSegment() {\n return this.segment;\n }\n\n public getOffset() {\n if (this.segment?.removedSeq) {\n return 0;\n }\n return this.offset;\n }\n\n public getProperties() {\n return this.properties;\n }\n}\n\ninterface IRefsAtOffset {\n before?: LocalReference[];\n at?: LocalReference[];\n after?: LocalReference[];\n}\n\n/**\n * Represents a collection of {@link LocalReference}s associated with one segment in a merge-tree.\n */\nexport class LocalReferenceCollection {\n public static append(seg1: ISegment, seg2: ISegment) {\n if (seg2.localRefs && !seg2.localRefs.empty) {\n if (!seg1.localRefs) {\n seg1.localRefs = new LocalReferenceCollection(seg1);\n }\n assert(seg1.localRefs.refsByOffset.length === seg1.cachedLength,\n 0x2be /* \"LocalReferences array contains a gap\" */);\n seg1.localRefs.append(seg2.localRefs);\n }\n else if (seg1.localRefs) {\n // Since creating the LocalReferenceCollection, we may have appended\n // segments that had no local references. Account for them now by padding the array.\n seg1.localRefs.refsByOffset.length += seg2.cachedLength;\n }\n }\n\n public hierRefCount: number = 0;\n private readonly refsByOffset: (IRefsAtOffset | undefined)[];\n private refCount: number = 0;\n\n constructor(\n /** Segment this `LocalReferenceCollection` is associated to. */\n private readonly segment: ISegment,\n initialRefsByfOffset = new Array<IRefsAtOffset | undefined>(segment.cachedLength)) {\n // Since javascript arrays are sparse the above won't populate any of the\n // indices, but it will ensure the length property of the array matches\n // the length of the segment.\n this.refsByOffset = initialRefsByfOffset;\n }\n\n public [Symbol.iterator]() {\n const subiterators: IterableIterator<LocalReference>[] = [];\n for (const refs of this.refsByOffset) {\n if (refs) {\n if (refs.before) {\n subiterators.push(refs.before[Symbol.iterator]());\n }\n if (refs.at) {\n subiterators.push(refs.at[Symbol.iterator]());\n }\n if (refs.after) {\n subiterators.push(refs.after[Symbol.iterator]());\n }\n }\n }\n\n const iterator = {\n next(): IteratorResult<LocalReference> {\n while (subiterators.length > 0) {\n const next = subiterators[0].next();\n if (next.done === true) {\n subiterators.shift();\n } else {\n return next;\n }\n }\n\n return { value: undefined, done: true };\n },\n [Symbol.iterator]() {\n return this;\n },\n };\n return iterator;\n }\n\n public clear() {\n this.refCount = 0;\n this.hierRefCount = 0;\n const detachSegments = (refs: LocalReference[] | undefined) => {\n if (refs) {\n refs.forEach((r) => {\n if (r.segment === this.segment) {\n r.segment = undefined;\n }\n });\n }\n };\n for (let i = 0; i < this.refsByOffset.length; i++) {\n const refsAtOffset = this.refsByOffset[i];\n if (refsAtOffset) {\n detachSegments(refsAtOffset.before);\n detachSegments(refsAtOffset.at);\n detachSegments(refsAtOffset.before);\n this.refsByOffset[i] = undefined;\n }\n }\n }\n\n public get empty() {\n return this.refCount === 0;\n }\n\n public addLocalRef(lref: LocalReference) {\n const refsAtOffset = this.refsByOffset[lref.offset];\n if (refsAtOffset === undefined) {\n this.refsByOffset[lref.offset] = {\n at: [lref],\n };\n } else if (refsAtOffset.at === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.refsByOffset[lref.offset]!.at = [lref];\n } else {\n refsAtOffset.at.push(lref);\n }\n\n if (lref.hasRangeLabels() || lref.hasTileLabels()) {\n this.hierRefCount++;\n }\n this.refCount++;\n }\n\n public removeLocalRef(lref: LocalReference) {\n const tryRemoveRef = (refs: LocalReference[] | undefined) => {\n if (refs) {\n const index = refs.indexOf(lref);\n if (index >= 0) {\n refs.splice(index, 1);\n if (lref.hasRangeLabels() || lref.hasTileLabels()) {\n this.hierRefCount--;\n }\n this.refCount--;\n return lref;\n }\n }\n };\n const refAtOffset = this.refsByOffset[lref.offset];\n if (refAtOffset !== undefined) {\n let ref = tryRemoveRef(refAtOffset.before);\n if (ref) {\n return ref;\n }\n\n ref = tryRemoveRef(refAtOffset.at);\n if (ref) {\n return ref;\n }\n\n ref = tryRemoveRef(refAtOffset.after);\n if (ref) {\n return ref;\n }\n }\n }\n\n /**\n * Called by 'append()' implementations to append local refs from the given 'other' segment to the\n * end of 'this' segment.\n *\n * Note: This method should be invoked after the caller has ensured that segments can be merged,\n * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs\n * will be incorrect.\n */\n public append(other: LocalReferenceCollection) {\n if (!other || other.empty) {\n return;\n }\n this.hierRefCount += other.hierRefCount;\n this.refCount += other.refCount;\n other.hierRefCount = 0;\n for (const lref of other) {\n lref.segment = this.segment;\n lref.offset += this.refsByOffset.length;\n }\n\n this.refsByOffset.push(...other.refsByOffset);\n }\n\n /**\n * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).\n * Local references in the former half of this split will remain associated with the segment used on construction.\n * Local references in the latter half of this split will be transferred to `splitSeg`,\n * and its `localRefs` field will be set.\n * @param offset - Offset into the original segment at which the collection should be split\n * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)\n * before splitting.\n */\n public split(offset: number, splitSeg: ISegment) {\n if (!this.empty) {\n const localRefs =\n new LocalReferenceCollection(\n splitSeg,\n this.refsByOffset.splice(offset, this.refsByOffset.length - offset));\n\n splitSeg.localRefs = localRefs;\n for (const lref of localRefs) {\n lref.segment = splitSeg;\n lref.offset -= offset;\n if (lref.hasRangeLabels() || lref.hasTileLabels()) {\n this.hierRefCount--;\n localRefs.hierRefCount++;\n }\n this.refCount--;\n localRefs.refCount++;\n }\n } else {\n // shrink the offset array when empty and splitting\n this.refsByOffset.length = offset;\n }\n }\n\n public addBeforeTombstones(...refs: Iterable<LocalReference>[]) {\n const beforeRefs: LocalReference[] = [];\n\n for (const iterable of refs) {\n for (const lref of iterable) {\n // eslint-disable-next-line no-bitwise\n if (lref.refType & ReferenceType.SlideOnRemove) {\n beforeRefs.push(lref);\n lref.segment = this.segment;\n lref.offset = 0;\n if (lref.hasRangeLabels() || lref.hasTileLabels()) {\n this.hierRefCount++;\n }\n this.refCount++;\n } else {\n lref.segment = undefined;\n }\n }\n }\n if (beforeRefs.length > 0) {\n if (this.refsByOffset[0] === undefined) {\n this.refsByOffset[0] = { before: beforeRefs };\n } else if (this.refsByOffset[0].before === undefined) {\n this.refsByOffset[0].before = beforeRefs;\n } else {\n this.refsByOffset[0].before.unshift(...beforeRefs);\n }\n }\n }\n\n public addAfterTombstones(...refs: Iterable<LocalReference>[]) {\n const afterRefs: LocalReference[] = [];\n\n for (const iterable of refs) {\n for (const lref of iterable) {\n // eslint-disable-next-line no-bitwise\n if (lref.refType & ReferenceType.SlideOnRemove) {\n afterRefs.push(lref);\n lref.segment = this.segment;\n lref.offset = this.segment.cachedLength - 1;\n if (lref.hasRangeLabels() || lref.hasTileLabels()) {\n this.hierRefCount++;\n }\n this.refCount++;\n } else {\n lref.segment = undefined;\n }\n }\n }\n if (afterRefs.length > 0) {\n const refsAtOffset = this.refsByOffset[this.segment.cachedLength - 1];\n if (refsAtOffset === undefined) {\n this.refsByOffset[this.segment.cachedLength - 1] = { after: afterRefs };\n } else if (refsAtOffset.after === undefined) {\n refsAtOffset.after = afterRefs;\n } else {\n refsAtOffset.after.push(...afterRefs);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"localReference.js","sourceRoot":"","sources":["../src/localReference.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD,+CAAoE;AAIpE,+BAAoD;AACpD,6CAA0D;AAC1D,6DAY8B;AAE9B;;GAEG;AACH,MAAa,cAAc;IAgBvB;;OAEG;IACH,YACqB,MAAc,EAC/B,WAAqB;IACrB;;OAEG;IACI,SAAiB,CAAC,EAClB,UAAU,mBAAa,CAAC,MAAM,EACrC,UAAwB;QAPP,WAAM,GAAN,MAAM,CAAQ;QAKxB,WAAM,GAAN,MAAM,CAAY;QAClB,YAAO,GAAP,OAAO,CAAuB;QAGrC,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,CAAiB;QACxB,OAAO,IAAA,yCAAoB,EAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IACD;;OAEG;IACI,GAAG,CAAC,CAAiB;QACxB,OAAO,IAAA,yCAAoB,EAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IACD;;OAEG;IACI,OAAO,CAAC,CAAiB;QAC5B,OAAO,IAAA,8CAAyB,EAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,UAAU;QACb,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,gCAAgC,CAA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,CAAC,YAAY,CAAC,UAAU,CAAC,0CAAE,KAAK,MAAK,SAAS,EAAE;YAC1E,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;gBAC9C,MAAA,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,mCAC1B,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YAC5B,YAAY,CAAC,KAAK,GAAG,MAAA,YAAY,CAAC,KAAK,mCAAI,SAAS,CAAC;SACxD;IACL,CAAC;CACJ;AA3TD,4DA2TC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { Client } from \"./client\";\nimport { List, ListMakeHead, ListRemoveEntry } from \"./collections\";\nimport {\n ISegment,\n} from \"./mergeTree\";\nimport { ICombiningOp, ReferenceType } from \"./ops\";\nimport { addProperties, PropertySet } from \"./properties\";\nimport {\n minReferencePosition,\n maxReferencePosition,\n compareReferencePositions,\n refHasTileLabels,\n refHasRangeLabels,\n ReferencePosition,\n refGetRangeLabels,\n refGetTileLabels,\n refHasRangeLabel,\n refHasTileLabel,\n refTypeIncludesFlag,\n} from \"./referencePositions\";\n\n/**\n * @deprecated - Use ReferencePosition\n */\nexport class LocalReference implements ReferencePosition {\n /**\n * @deprecated - use DetachedReferencePosition\n */\n public static readonly DetachedPosition: number = -1;\n\n public properties: PropertySet | undefined;\n /**\n * @deprecated - use properties to store pair\n */\n public pairedRef?: LocalReference;\n /**\n * @deprecated - use getSegment\n */\n public segment: ISegment | undefined;\n\n /**\n * @deprecated - use createReferencePosition\n */\n constructor(\n private readonly client: Client,\n initSegment: ISegment,\n /**\n * @deprecated - use getOffset\n */\n public offset: number = 0,\n public refType = ReferenceType.Simple,\n properties?: PropertySet,\n ) {\n this.segment = initSegment;\n this.properties = properties;\n }\n\n /**\n * @deprecated - use minReferencePosition\n */\n public min(b: LocalReference) {\n return minReferencePosition(this, b);\n }\n /**\n * @deprecated - use maxReferencePosition\n */\n public max(b: LocalReference) {\n return maxReferencePosition(this, b);\n }\n /**\n * @deprecated - use compareReferencePositions\n */\n public compare(b: LocalReference) {\n return compareReferencePositions(this, b);\n }\n\n /**\n * @deprecated - use getLocalReferencePosition\n */\n public toPosition() {\n return this.getClient().localReferencePositionToPosition(this);\n }\n\n /**\n * @deprecated - use refHasTileLabels\n */\n public hasTileLabels(): boolean {\n return refHasTileLabels(this);\n }\n /**\n * @deprecated - use refHasRangeLabels\n */\n public hasRangeLabels(): boolean {\n return refHasRangeLabels(this);\n }\n /**\n * @deprecated - use refHasTileLabel\n */\n public hasTileLabel(label: string): boolean {\n return refHasTileLabel(this, label);\n }\n /**\n * @deprecated - use refHasRangeLabel\n */\n public hasRangeLabel(label: string): boolean {\n return refHasRangeLabel(this, label);\n }\n /**\n * @deprecated - use refGetTileLabels\n */\n public getTileLabels(): string[] | undefined {\n return refGetTileLabels(this);\n }\n /**\n * @deprecated - use refGetRangeLabels\n */\n public getRangeLabels(): string[] | undefined {\n return refGetRangeLabels(this);\n }\n\n public isLeaf() {\n return false;\n }\n\n public addProperties(newProps: PropertySet, op?: ICombiningOp) {\n this.properties = addProperties(this.properties, newProps, op);\n }\n\n /**\n * @deprecated - no longer supported\n */\n public getClient() {\n return this.client;\n }\n\n public getSegment() {\n return this.segment;\n }\n\n public getOffset() {\n if (this.segment?.removedSeq) {\n return 0;\n }\n return this.offset;\n }\n\n public getProperties() {\n return this.properties;\n }\n}\n\ninterface IRefsAtOffset {\n before?: List<LocalReference>;\n at?: List<LocalReference>;\n after?: List<LocalReference>;\n}\n\nfunction assertLocalReferences(lref: ReferencePosition | LocalReference): asserts lref is LocalReference {\n assert(lref instanceof LocalReference, 0x2e0 /* \"lref not a Local Reference\" */);\n}\n\n/**\n * Represents a collection of {@link ReferencePosition}s associated with one segment in a merge-tree.\n */\nexport class LocalReferenceCollection {\n public static append(seg1: ISegment, seg2: ISegment) {\n if (seg2.localRefs && !seg2.localRefs.empty) {\n if (!seg1.localRefs) {\n seg1.localRefs = new LocalReferenceCollection(seg1);\n }\n assert(seg1.localRefs.refsByOffset.length === seg1.cachedLength,\n 0x2be /* \"LocalReferences array contains a gap\" */);\n seg1.localRefs.append(seg2.localRefs);\n } else if (seg1.localRefs) {\n // Since creating the LocalReferenceCollection, we may have appended\n // segments that had no local references. Account for them now by padding the array.\n seg1.localRefs.refsByOffset.length += seg2.cachedLength;\n }\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public hierRefCount: number = 0;\n private readonly refsByOffset: (IRefsAtOffset | undefined)[];\n private refCount: number = 0;\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n constructor(\n /** Segment this `LocalReferenceCollection` is associated to. */\n private readonly segment: ISegment,\n initialRefsByfOffset = new Array<IRefsAtOffset | undefined>(segment.cachedLength)) {\n // Since javascript arrays are sparse the above won't populate any of the\n // indices, but it will ensure the length property of the array matches\n // the length of the segment.\n this.refsByOffset = initialRefsByfOffset;\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public [Symbol.iterator]() {\n const subiterators: IterableIterator<LocalReference>[] = [];\n for (const refs of this.refsByOffset) {\n if (refs) {\n if (refs.before) {\n subiterators.push(refs.before[Symbol.iterator]());\n }\n if (refs.at) {\n subiterators.push(refs.at[Symbol.iterator]());\n }\n if (refs.after) {\n subiterators.push(refs.after[Symbol.iterator]());\n }\n }\n }\n\n const iterator = {\n next(): IteratorResult<LocalReference> {\n while (subiterators.length > 0) {\n const next = subiterators[0].next();\n if (next.done === true) {\n subiterators.shift();\n } else {\n return next;\n }\n }\n\n return { value: undefined, done: true };\n },\n [Symbol.iterator]() {\n return this;\n },\n };\n return iterator;\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public clear() {\n this.refCount = 0;\n this.hierRefCount = 0;\n const detachSegments = (refs: List<LocalReference> | undefined) => {\n if (refs) {\n for (const r of refs) {\n if (r.segment === this.segment) {\n r.segment = undefined;\n }\n }\n }\n };\n for (let i = 0; i < this.refsByOffset.length; i++) {\n const refsAtOffset = this.refsByOffset[i];\n if (refsAtOffset) {\n detachSegments(refsAtOffset.before);\n detachSegments(refsAtOffset.at);\n detachSegments(refsAtOffset.before);\n this.refsByOffset[i] = undefined;\n }\n }\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public get empty() {\n return this.refCount === 0;\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public createLocalRef(\n offset: number,\n refType: ReferenceType,\n properties: PropertySet | undefined,\n client: Client): ReferencePosition {\n const ref = new LocalReference(\n client,\n this.segment,\n offset,\n refType,\n properties,\n );\n if (!refTypeIncludesFlag(ref, ReferenceType.Transient)) {\n this.addLocalRef(ref);\n }\n return ref;\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public addLocalRef(lref: LocalReference | ReferencePosition) {\n assert(\n !refTypeIncludesFlag(lref, ReferenceType.Transient),\n 0x2df /* \"transient references cannot be bound to segments\" */);\n assertLocalReferences(lref);\n const refsAtOffset = this.refsByOffset[lref.getOffset()] =\n this.refsByOffset[lref.getOffset()]\n ?? { at: ListMakeHead() };\n const atRefs = refsAtOffset.at =\n refsAtOffset.at\n ?? ListMakeHead();\n\n atRefs.enqueue(lref);\n\n if (refHasRangeLabels(lref) || refHasTileLabels(lref)) {\n this.hierRefCount++;\n }\n this.refCount++;\n }\n\n /**\n *\n * @internal - this method should only be called by mergeTree\n */\n public removeLocalRef(lref: LocalReference | ReferencePosition) {\n assertLocalReferences(lref);\n const tryRemoveRef = (refs: List<LocalReference> | undefined) => {\n if (refs) {\n let node = refs;\n do {\n node = node.next;\n if (node.data === lref) {\n ListRemoveEntry(node);\n if (refHasRangeLabels(lref) || refHasTileLabels(lref)) {\n this.hierRefCount--;\n }\n this.refCount--;\n return lref;\n }\n } while (!node.isHead);\n }\n };\n const refAtOffset = this.refsByOffset[lref.offset];\n if (refAtOffset !== undefined) {\n let ref = tryRemoveRef(refAtOffset.before);\n if (ref) {\n return ref;\n }\n\n ref = tryRemoveRef(refAtOffset.at);\n if (ref) {\n return ref;\n }\n\n ref = tryRemoveRef(refAtOffset.after);\n if (ref) {\n return ref;\n }\n }\n }\n\n /**\n * @internal - this method should only be called by mergeTree\n *\n * Called by 'append()' implementations to append local refs from the given 'other' segment to the\n * end of 'this' segment.\n *\n * Note: This method should be invoked after the caller has ensured that segments can be merged,\n * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs\n * will be incorrect.\n */\n public append(other: LocalReferenceCollection) {\n if (!other || other.empty) {\n return;\n }\n this.hierRefCount += other.hierRefCount;\n this.refCount += other.refCount;\n other.hierRefCount = 0;\n for (const lref of other) {\n lref.segment = this.segment;\n lref.offset += this.refsByOffset.length;\n }\n\n this.refsByOffset.push(...other.refsByOffset);\n }\n\n /**\n * @internal - this method should only be called by mergeTree\n *\n * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).\n * Local references in the former half of this split will remain associated with the segment used on construction.\n * Local references in the latter half of this split will be transferred to `splitSeg`,\n * and its `localRefs` field will be set.\n * @param offset - Offset into the original segment at which the collection should be split\n * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)\n * before splitting.\n */\n public split(offset: number, splitSeg: ISegment) {\n if (!this.empty) {\n const localRefs =\n new LocalReferenceCollection(\n splitSeg,\n this.refsByOffset.splice(offset, this.refsByOffset.length - offset));\n\n splitSeg.localRefs = localRefs;\n for (const lref of localRefs) {\n lref.segment = splitSeg;\n lref.offset -= offset;\n if (refHasRangeLabels(lref) || refHasTileLabels(lref)) {\n this.hierRefCount--;\n localRefs.hierRefCount++;\n }\n this.refCount--;\n localRefs.refCount++;\n }\n } else {\n // shrink the offset array when empty and splitting\n this.refsByOffset.length = offset;\n }\n }\n\n public addBeforeTombstones(...refs: Iterable<LocalReference | ReferencePosition>[]) {\n const beforeRefs = this.refsByOffset[0]?.before ?? ListMakeHead();\n\n for (const iterable of refs) {\n for (const lref of iterable) {\n assertLocalReferences(lref);\n if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n beforeRefs.push(lref);\n lref.segment = this.segment;\n lref.offset = 0;\n if (refHasRangeLabels(lref) || refHasTileLabels(lref)) {\n this.hierRefCount++;\n }\n this.refCount++;\n } else {\n lref.segment = undefined;\n }\n }\n }\n if (!beforeRefs.empty() && this.refsByOffset[0]?.before === undefined) {\n const refsAtOffset = this.refsByOffset[0] =\n this.refsByOffset[0]\n ?? { before: beforeRefs };\n refsAtOffset.before = refsAtOffset.before ?? beforeRefs;\n }\n }\n\n public addAfterTombstones(...refs: Iterable<LocalReference | ReferencePosition>[]) {\n const lastOffset = this.refsByOffset.length - 1;\n const afterRefs =\n this.refsByOffset[lastOffset]?.after ?? ListMakeHead();\n\n for (const iterable of refs) {\n for (const lref of iterable) {\n assertLocalReferences(lref);\n if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n afterRefs.push(lref);\n lref.segment = this.segment;\n lref.offset = this.segment.cachedLength - 1;\n if (refHasRangeLabels(lref) || refHasTileLabels(lref)) {\n this.hierRefCount++;\n }\n this.refCount++;\n } else {\n lref.segment = undefined;\n }\n }\n }\n if (!afterRefs.empty() && this.refsByOffset[lastOffset]?.after === undefined) {\n const refsAtOffset = this.refsByOffset[lastOffset] =\n this.refsByOffset[lastOffset]\n ?? { after: afterRefs };\n refsAtOffset.after = refsAtOffset.after ?? afterRefs;\n }\n }\n}\n"]}
@@ -9,23 +9,10 @@ import { TrackingGroupCollection } from "./mergeTreeTracking";
9
9
  import { ICombiningOp, IJSONSegment, IMarkerDef, IRelativePosition, ReferenceType } from "./ops";
10
10
  import { PartialSequenceLengths } from "./partialLengths";
11
11
  import { MapLike, PropertySet } from "./properties";
12
+ import { RangeStackMap, ReferencePosition } from "./referencePositions";
12
13
  import { SegmentGroupCollection } from "./segmentGroupCollection";
13
14
  import { PropertiesManager } from "./segmentPropertiesManager";
14
- export interface ReferencePosition {
15
- properties?: PropertySet;
16
- refType: ReferenceType;
17
- isLeaf(): boolean;
18
- getSegment(): ISegment | undefined;
19
- getOffset(): number;
20
- addProperties(newProps: PropertySet, op?: ICombiningOp): void;
21
- hasTileLabels(): boolean;
22
- hasRangeLabels(): boolean;
23
- hasTileLabel(label: string): boolean;
24
- hasRangeLabel(label: string): boolean;
25
- getTileLabels(): string[] | undefined;
26
- getRangeLabels(): string[] | undefined;
27
- }
28
- export declare type RangeStackMap = MapLike<Stack<ReferencePosition>>;
15
+ import { Client } from "./client";
29
16
  export interface IMergeNodeCommon {
30
17
  parent?: IMergeBlock;
31
18
  /**
@@ -208,14 +195,8 @@ export declare abstract class BaseSegment extends MergeNode implements ISegment
208
195
  abstract append(segment: ISegment): void;
209
196
  protected abstract createSplitSegmentAt(pos: number): BaseSegment | undefined;
210
197
  }
211
- export declare const reservedTileLabelsKey = "referenceTileLabels";
212
- export declare const reservedRangeLabelsKey = "referenceRangeLabels";
213
198
  export declare const reservedMarkerIdKey = "markerId";
214
199
  export declare const reservedMarkerSimpleTypeKey = "markerSimpleType";
215
- export declare const refGetTileLabels: (refPos: ReferencePosition) => string[] | undefined;
216
- export declare const refGetRangeLabels: (refPos: ReferencePosition) => string[] | undefined;
217
- export declare function refHasTileLabel(refPos: ReferencePosition, label: string): boolean;
218
- export declare function refHasRangeLabel(refPos: ReferencePosition, label: string): boolean;
219
200
  export interface IJSONMarkerSegment extends IJSONSegment {
220
201
  marker: IMarkerDef;
221
202
  }
@@ -234,11 +215,29 @@ export declare class Marker extends BaseSegment implements ReferencePosition {
234
215
  hasSimpleType(simpleTypeName: string): boolean;
235
216
  getProperties(): PropertySet | undefined;
236
217
  getId(): string | undefined;
218
+ /**
219
+ * @deprecated - use refHasTileLabels
220
+ */
237
221
  hasTileLabels(): boolean;
222
+ /**
223
+ * @deprecated - use refHasRangeLabels
224
+ */
238
225
  hasRangeLabels(): boolean;
226
+ /**
227
+ * @deprecated - use refHasTileLabel
228
+ */
239
229
  hasTileLabel(label: string): boolean;
230
+ /**
231
+ * @deprecated - use refHasRangeLabel
232
+ */
240
233
  hasRangeLabel(label: string): boolean;
234
+ /**
235
+ * @deprecated - use refGetTileLabels
236
+ */
241
237
  getTileLabels(): string[] | undefined;
238
+ /**
239
+ * @deprecated - use refGetRangeLabels
240
+ */
242
241
  getRangeLabels(): string[] | undefined;
243
242
  toString(): string;
244
243
  protected createSplitSegmentAt(pos: number): undefined;
@@ -413,7 +412,15 @@ export declare class MergeTree {
413
412
  annotateRange(start: number, end: number, props: PropertySet, combiningOp: ICombiningOp | undefined, refSeq: number, clientId: number, seq: number, opArgs: IMergeTreeDeltaOpArgs): void;
414
413
  markRangeRemoved(start: number, end: number, refSeq: number, clientId: number, seq: number, overwrite: boolean | undefined, opArgs: IMergeTreeDeltaOpArgs): void;
415
414
  private nodeUpdateLengthNewStructure;
415
+ removeLocalReferencePosition(lref: ReferencePosition): ReferencePosition | undefined;
416
+ createLocalReferencePosition(segment: ISegment, offset: number, refType: ReferenceType, properties: PropertySet | undefined, client: Client): ReferencePosition;
417
+ /**
418
+ * @deprecated - use removeLocalReferencePosition
419
+ */
416
420
  removeLocalReference(segment: ISegment, lref: LocalReference): void;
421
+ /**
422
+ * @deprecated - use createLocalReference
423
+ */
417
424
  addLocalReference(lref: LocalReference): void;
418
425
  private blockUpdate;
419
426
  private blockUpdatePathLengths;