@fluidframework/merge-tree 2.43.0 → 2.50.0-345060

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 (89) hide show
  1. package/dist/client.d.ts.map +1 -1
  2. package/dist/client.js.map +1 -1
  3. package/dist/collections/index.d.ts +0 -1
  4. package/dist/collections/index.d.ts.map +1 -1
  5. package/dist/collections/index.js +1 -5
  6. package/dist/collections/index.js.map +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/localReference.js +10 -10
  12. package/dist/localReference.js.map +1 -1
  13. package/dist/mergeTree.d.ts +1 -2
  14. package/dist/mergeTree.d.ts.map +1 -1
  15. package/dist/mergeTree.js +4 -5
  16. package/dist/mergeTree.js.map +1 -1
  17. package/dist/revertibles.d.ts.map +1 -1
  18. package/dist/revertibles.js +2 -3
  19. package/dist/revertibles.js.map +1 -1
  20. package/dist/segmentGroupCollection.d.ts.map +1 -1
  21. package/dist/segmentGroupCollection.js +3 -3
  22. package/dist/segmentGroupCollection.js.map +1 -1
  23. package/dist/segmentPropertiesManager.d.ts.map +1 -1
  24. package/dist/segmentPropertiesManager.js +6 -7
  25. package/dist/segmentPropertiesManager.js.map +1 -1
  26. package/dist/test/testClient.d.ts +1 -1
  27. package/dist/test/testClient.d.ts.map +1 -1
  28. package/dist/test/testClient.js +11 -11
  29. package/dist/test/testClient.js.map +1 -1
  30. package/dist/test/testClientLogger.js +4 -4
  31. package/dist/test/testClientLogger.js.map +1 -1
  32. package/lib/client.d.ts.map +1 -1
  33. package/lib/client.js +1 -1
  34. package/lib/client.js.map +1 -1
  35. package/lib/collections/index.d.ts +0 -1
  36. package/lib/collections/index.d.ts.map +1 -1
  37. package/lib/collections/index.js +0 -1
  38. package/lib/collections/index.js.map +1 -1
  39. package/lib/index.d.ts +1 -1
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +1 -1
  42. package/lib/index.js.map +1 -1
  43. package/lib/localReference.js +1 -1
  44. package/lib/localReference.js.map +1 -1
  45. package/lib/mergeTree.d.ts +1 -2
  46. package/lib/mergeTree.d.ts.map +1 -1
  47. package/lib/mergeTree.js +1 -2
  48. package/lib/mergeTree.js.map +1 -1
  49. package/lib/revertibles.d.ts.map +1 -1
  50. package/lib/revertibles.js +1 -2
  51. package/lib/revertibles.js.map +1 -1
  52. package/lib/segmentGroupCollection.d.ts.map +1 -1
  53. package/lib/segmentGroupCollection.js +1 -1
  54. package/lib/segmentGroupCollection.js.map +1 -1
  55. package/lib/segmentPropertiesManager.d.ts.map +1 -1
  56. package/lib/segmentPropertiesManager.js +1 -2
  57. package/lib/segmentPropertiesManager.js.map +1 -1
  58. package/lib/test/testClient.d.ts +1 -1
  59. package/lib/test/testClient.d.ts.map +1 -1
  60. package/lib/test/testClient.js +1 -1
  61. package/lib/test/testClient.js.map +1 -1
  62. package/lib/test/testClientLogger.js +1 -1
  63. package/lib/test/testClientLogger.js.map +1 -1
  64. package/package.json +16 -16
  65. package/src/client.ts +7 -2
  66. package/src/collections/index.ts +0 -7
  67. package/src/index.ts +0 -3
  68. package/src/localReference.ts +1 -1
  69. package/src/mergeTree.ts +7 -2
  70. package/src/revertibles.ts +5 -2
  71. package/src/segmentGroupCollection.ts +2 -1
  72. package/src/segmentPropertiesManager.ts +5 -2
  73. package/dist/collections/list.d.ts +0 -146
  74. package/dist/collections/list.d.ts.map +0 -1
  75. package/dist/collections/list.js +0 -317
  76. package/dist/collections/list.js.map +0 -1
  77. package/dist/test/collections.list.spec.d.ts +0 -6
  78. package/dist/test/collections.list.spec.d.ts.map +0 -1
  79. package/dist/test/collections.list.spec.js +0 -84
  80. package/dist/test/collections.list.spec.js.map +0 -1
  81. package/lib/collections/list.d.ts +0 -146
  82. package/lib/collections/list.d.ts.map +0 -1
  83. package/lib/collections/list.js +0 -311
  84. package/lib/collections/list.js.map +0 -1
  85. package/lib/test/collections.list.spec.d.ts +0 -6
  86. package/lib/test/collections.list.spec.d.ts.map +0 -1
  87. package/lib/test/collections.list.spec.js +0 -82
  88. package/lib/test/collections.list.spec.js.map +0 -1
  89. package/src/collections/list.ts +0 -400
@@ -1,400 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
-
8
- /**
9
- * Represents a node in a doubly linked list.
10
- * @internal
11
- */
12
- export interface ListNode<T> {
13
- /**
14
- * The list this node belongs to, or undefined if not attached.
15
- */
16
- readonly list: DoublyLinkedList<T> | undefined;
17
- /**
18
- * The data value stored in this node.
19
- */
20
- readonly data: T;
21
- /**
22
- * The next node in the list, or undefined if this is the last node.
23
- */
24
- readonly next: ListNode<T> | undefined;
25
- /**
26
- * The previous node in the list, or undefined if this is the first node.
27
- */
28
- readonly prev: ListNode<T> | undefined;
29
- /**
30
- * Removes this node from its list.
31
- * @returns The removed node, or undefined if not in a list.
32
- */
33
- remove(): ListNode<T> | undefined;
34
- }
35
-
36
- /**
37
- * Represents a range of nodes in a doubly linked list.
38
- * @internal
39
- */
40
- export interface ListNodeRange<T> {
41
- /**
42
- * The first node in the range.
43
- */
44
- first: ListNode<T>;
45
- /**
46
- * The last node in the range.
47
- */
48
- last: ListNode<T>;
49
- }
50
-
51
- class HeadNode<T> {
52
- public _next: HeadNode<T> | DataNode<T> = this;
53
- public _prev: HeadNode<T> | DataNode<T> = this;
54
- public headNode: HeadNode<T> = this;
55
- private readonly _list?: DoublyLinkedList<T>;
56
- constructor(list: DoublyLinkedList<T> | undefined) {
57
- if (list) {
58
- this._list = list;
59
- }
60
- }
61
- public get next(): DataNode<T> | undefined {
62
- return this._next === this.headNode ? undefined : (this._next as DataNode<T>);
63
- }
64
- public get prev(): DataNode<T> | undefined {
65
- return this._prev === this.headNode ? undefined : (this._prev as DataNode<T>);
66
- }
67
- public get list(): DoublyLinkedList<T> | undefined {
68
- return this.headNode._list;
69
- }
70
- }
71
-
72
- // The any is needed for use in the remove function, where the nodes are defined with a generic type.
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
- const DeadHead = new HeadNode<any>(undefined);
75
-
76
- class DataNode<T> extends HeadNode<T> implements ListNode<T> {
77
- constructor(
78
- headNode: HeadNode<T>,
79
- public readonly data: T,
80
- ) {
81
- super(undefined);
82
- this.headNode = headNode;
83
- }
84
- remove(): ListNode<T> | undefined {
85
- return this.list?.remove(this);
86
- }
87
- }
88
-
89
- function insertAfter<T>(node: DataNode<T> | HeadNode<T>, items: T[]): ListNodeRange<T> {
90
- let previousNode = node;
91
- const oldNext = previousNode._next;
92
- let newRange: ListNodeRange<T> | undefined;
93
- for (const n of items) {
94
- const newNode = new DataNode<T>(node.headNode, n);
95
- if (newRange === undefined) {
96
- newRange = { first: newNode, last: newNode };
97
- } else {
98
- newRange.last = newNode;
99
- }
100
- newNode._prev = previousNode;
101
- previousNode._next = newNode;
102
- previousNode = newNode;
103
- }
104
- oldNext._prev = previousNode;
105
- previousNode._next = oldNext;
106
- // explicitly prevent newRange from being undefined without casting,
107
- // and without additional conditionals, as this is used in some perf critical areas.
108
- // i could have just asserted, but that throws a non-user friendly error,
109
- // so i went with a more user-friendly error, which describes the
110
- // only condition that could lead to this being undefined in the current code.
111
- if (newRange === undefined) {
112
- throw new UsageError("items must not be empty");
113
- }
114
- return newRange;
115
- }
116
-
117
- /**
118
- * A doubly linked list implementation with array-like methods and node access.
119
- * @typeParam T - The type of data stored in the list nodes.
120
- * @internal
121
- */
122
- export class DoublyLinkedList<T>
123
- implements
124
- Iterable<ListNode<T>>,
125
- Partial<ListNodeRange<T>>,
126
- // try to match array signature and semantics where possible
127
- Pick<ListNode<T>[], "pop" | "shift" | "length" | "includes">
128
- {
129
- /**
130
- * Creates a new doubly linked list optionally initialized with values.
131
- * @param values - Optional iterable of values to populate the list.
132
- */
133
- constructor(values?: Iterable<T>) {
134
- if (values !== undefined) {
135
- this.push(...values);
136
- }
137
- }
138
-
139
- /**
140
- * Finds the first node matching the predicate.
141
- * @param predicate - Function to test each node.
142
- * @returns The first matching node, or undefined if none found.
143
- */
144
- find(
145
- predicate: (value: ListNode<T>, obj: DoublyLinkedList<T>) => unknown,
146
- ): ListNode<T> | undefined {
147
- let found: ListNode<T> | undefined;
148
- walkList(this, (node) => {
149
- if (predicate(node, this)) {
150
- found = node;
151
- return false;
152
- }
153
- });
154
- return found;
155
- }
156
-
157
- /**
158
- * Returns an iterable that maps each node to a new value.
159
- * @param callbackfn - Function to produce a new value for each node.
160
- */
161
- map<U>(callbackfn: (value: ListNode<T>) => U): Iterable<U> {
162
- let node = this.first;
163
- const iterator: IterableIterator<U> = {
164
- next(): IteratorResult<U> {
165
- if (node === undefined) {
166
- return { done: true, value: undefined };
167
- }
168
- const rtn = { value: callbackfn(node), done: false };
169
- node = node.next;
170
- return rtn;
171
- },
172
- [Symbol.iterator]() {
173
- return this;
174
- },
175
- };
176
- return iterator;
177
- }
178
-
179
- /**
180
- * Inserts items after the specified node.
181
- * @param preceding - The node to insert after.
182
- * @param items - Items to insert.
183
- * @returns The range of newly inserted nodes.
184
- */
185
- insertAfter(preceding: ListNode<T>, ...items: T[]): ListNodeRange<T> {
186
- if (!this._includes(preceding)) {
187
- throw new Error("preceding not in list");
188
- }
189
- this._len += items.length;
190
- return insertAfter(preceding, items);
191
- }
192
-
193
- /**
194
- * Removes and returns the last node in the list.
195
- * @returns The removed node, or undefined if the list is empty.
196
- */
197
- pop(): ListNode<T> | undefined {
198
- return this.remove(this.last);
199
- }
200
-
201
- /**
202
- * Appends items to the end of the list.
203
- * @param items - Items to append.
204
- * @returns The range of newly inserted nodes.
205
- */
206
- push(...items: T[]): ListNodeRange<T> {
207
- this._len += items.length;
208
- const start = this.headNode._prev;
209
- return insertAfter(start, items);
210
- }
211
-
212
- /**
213
- * Removes and returns the first node in the list.
214
- * @returns The removed node, or undefined if the list is empty.
215
- */
216
- shift(): ListNode<T> | undefined {
217
- return this.remove(this.first);
218
- }
219
-
220
- /**
221
- * Inserts items at the start of the list.
222
- * @param items - Items to insert.
223
- * @returns The range of newly inserted nodes.
224
- */
225
- unshift(...items: T[]): ListNodeRange<T> {
226
- this._len += items.length;
227
- return insertAfter(this.headNode, items);
228
- }
229
-
230
- /**
231
- * Removes nodes starting at `start` until `end` or `count` is reached.
232
- * @param start - The node to start removing from.
233
- * @param countOrEnd - The number of nodes to remove or the end node.
234
- * @returns A new list containing the removed nodes.
235
- */
236
- splice(start: ListNode<T>, countOrEnd?: ListNode<T> | number): DoublyLinkedList<T> {
237
- const newList = new DoublyLinkedList<T>();
238
- walkList(
239
- this,
240
- (node) => {
241
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
242
- const removedNode = this._remove(node)!;
243
- // whats special here is we preserve the node
244
- // this allow looking up the old node in the new list
245
- // when something preserves a reference
246
- removedNode.headNode = newList.headNode;
247
- removedNode._next = newList.headNode;
248
- removedNode._prev = newList.headNode._prev;
249
- newList.headNode._prev._next = removedNode;
250
- newList.headNode._prev = removedNode;
251
- newList._len++;
252
- if (node === countOrEnd || newList.length === countOrEnd) {
253
- return false;
254
- }
255
- },
256
- start,
257
- );
258
- return newList;
259
- }
260
-
261
- /**
262
- * Checks if the node is in this list.
263
- * @param node - The node to check.
264
- * @returns True if the node is in the list.
265
- */
266
- public includes(node: ListNode<T> | undefined): node is ListNode<T> {
267
- return this._includes(node);
268
- }
269
-
270
- private _includes(node: ListNode<T> | undefined): node is DataNode<T> {
271
- return node instanceof DataNode && node.headNode === this.headNode;
272
- }
273
-
274
- private _remove(node: ListNode<T> | undefined): DataNode<T> | undefined {
275
- if (this._includes(node)) {
276
- node._prev._next = node._next;
277
- node._next._prev = node._prev;
278
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
279
- node.headNode = node._next = node._prev = DeadHead;
280
- this._len--;
281
- return node;
282
- }
283
- return undefined;
284
- }
285
-
286
- /**
287
- * Removes the specified node from the list.
288
- * @param node - The node to remove.
289
- * @returns The removed node, or undefined if not in the list.
290
- */
291
- public remove(node: ListNode<T> | undefined): ListNode<T> | undefined {
292
- return this._remove(node);
293
- }
294
-
295
- public [Symbol.iterator](): IterableIterator<ListNode<T>> {
296
- let value = this.first;
297
- const iterator: IterableIterator<ListNode<T>> = {
298
- next(): IteratorResult<ListNode<T>> {
299
- if (value !== undefined) {
300
- const rtn = { value, done: false };
301
- value = value.next;
302
- return rtn;
303
- }
304
- return { value: undefined, done: true };
305
- },
306
- [Symbol.iterator]() {
307
- return this;
308
- },
309
- };
310
- return iterator;
311
- }
312
-
313
- private _len: number = 0;
314
- private readonly headNode: HeadNode<T> | DataNode<T> = new HeadNode(this);
315
-
316
- /**
317
- * The number of nodes in the list.
318
- */
319
- public get length(): number {
320
- return this._len;
321
- }
322
-
323
- /**
324
- * Whether the list is empty.
325
- */
326
- public get empty(): boolean {
327
- return this._len === 0;
328
- }
329
-
330
- /**
331
- * The first node in the list, or undefined if empty.
332
- */
333
- public get first(): ListNode<T> | undefined {
334
- return this.headNode.next;
335
- }
336
-
337
- /**
338
- * The last node in the list, or undefined if empty.
339
- */
340
- public get last(): ListNode<T> | undefined {
341
- return this.headNode.prev;
342
- }
343
- }
344
-
345
- export function walkList<T>(
346
- list: DoublyLinkedList<T>,
347
- visitor: (node: ListNode<T>) => boolean | void,
348
- start?: ListNode<T>,
349
- forward: boolean = true,
350
- ): boolean {
351
- let current: ListNode<T> | undefined;
352
- if (start) {
353
- if (!list.includes(start)) {
354
- throw new UsageError("start must be in the provided list");
355
- }
356
- current = start;
357
- } else {
358
- current = forward ? list.first : list.last;
359
- }
360
- // cache the next node, incase the visitor mutates the list
361
- // need this to support splice
362
- let next = forward ? current?.next : current?.prev;
363
- while (current !== undefined) {
364
- if (visitor(current) === false) {
365
- return false;
366
- }
367
- current = next;
368
- next = forward ? next?.next : next?.prev;
369
- }
370
- return true;
371
- }
372
-
373
- /**
374
- * Creates a lazily evaluated iterable which returns values while the predicate returns true,
375
- * and stops iterating at the first value where the predicate is false.
376
- * @param start - the node to start the iteration from
377
- * @param includePredicate - determine if the current value be included in the iteration or stop if iteration
378
- */
379
- export function iterateListValuesWhile<T>(
380
- start: ListNode<T> | undefined,
381
- includePredicate: (n: ListNode<T>) => boolean,
382
- ): Iterable<T> {
383
- let next: ListNode<T> | undefined = start;
384
- const iterator: IterableIterator<T> = {
385
- next: (): IteratorResult<T> => {
386
- if (next !== undefined) {
387
- const current = next;
388
- next = current.next;
389
- if (includePredicate(current) === true) {
390
- return { value: current.data, done: false };
391
- }
392
- }
393
- return { done: true, value: undefined };
394
- },
395
- [Symbol.iterator]() {
396
- return this;
397
- },
398
- };
399
- return iterator;
400
- }