@fluidframework/merge-tree 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258
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.
- package/CHANGELOG.md +115 -0
- package/README.md +4 -3
- package/dist/MergeTreeTextHelper.d.ts.map +1 -1
- package/dist/MergeTreeTextHelper.js +3 -2
- package/dist/MergeTreeTextHelper.js.map +1 -1
- package/dist/attributionCollection.d.ts +5 -2
- package/dist/attributionCollection.d.ts.map +1 -1
- package/dist/attributionCollection.js +18 -25
- package/dist/attributionCollection.js.map +1 -1
- package/dist/attributionPolicy.d.ts +3 -2
- package/dist/attributionPolicy.d.ts.map +1 -1
- package/dist/attributionPolicy.js +11 -12
- package/dist/attributionPolicy.js.map +1 -1
- package/dist/client.d.ts +19 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +85 -66
- package/dist/client.js.map +1 -1
- package/dist/collections/list.d.ts +3 -0
- package/dist/collections/list.d.ts.map +1 -1
- package/dist/collections/list.js +42 -5
- package/dist/collections/list.js.map +1 -1
- package/dist/endOfTreeSegment.d.ts +1 -1
- package/dist/endOfTreeSegment.d.ts.map +1 -1
- package/dist/endOfTreeSegment.js +4 -5
- package/dist/endOfTreeSegment.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/localReference.js +38 -47
- package/dist/localReference.js.map +1 -1
- package/dist/mergeTree.d.ts +45 -28
- package/dist/mergeTree.d.ts.map +1 -1
- package/dist/mergeTree.js +225 -328
- package/dist/mergeTree.js.map +1 -1
- package/dist/mergeTreeDeltaCallback.d.ts +4 -0
- package/dist/mergeTreeDeltaCallback.d.ts.map +1 -1
- package/dist/mergeTreeDeltaCallback.js +0 -4
- package/dist/mergeTreeDeltaCallback.js.map +1 -1
- package/dist/mergeTreeNodeWalk.js +4 -4
- package/dist/mergeTreeNodeWalk.js.map +1 -1
- package/dist/mergeTreeNodes.d.ts +69 -12
- package/dist/mergeTreeNodes.d.ts.map +1 -1
- package/dist/mergeTreeNodes.js +38 -42
- package/dist/mergeTreeNodes.js.map +1 -1
- package/dist/mergeTreeTracking.d.ts +0 -6
- package/dist/mergeTreeTracking.d.ts.map +1 -1
- package/dist/mergeTreeTracking.js +0 -9
- package/dist/mergeTreeTracking.js.map +1 -1
- package/dist/opBuilder.d.ts +2 -0
- package/dist/opBuilder.d.ts.map +1 -1
- package/dist/opBuilder.js +3 -0
- package/dist/opBuilder.js.map +1 -1
- package/dist/ops.d.ts +12 -0
- package/dist/ops.d.ts.map +1 -1
- package/dist/ops.js +9 -0
- package/dist/ops.js.map +1 -1
- package/dist/ordinal.js +2 -2
- package/dist/ordinal.js.map +1 -1
- package/dist/partialLengths.js +37 -40
- package/dist/partialLengths.js.map +1 -1
- package/dist/properties.js +3 -3
- package/dist/properties.js.map +1 -1
- package/dist/referencePositions.d.ts +4 -2
- package/dist/referencePositions.d.ts.map +1 -1
- package/dist/referencePositions.js +2 -16
- package/dist/referencePositions.js.map +1 -1
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +34 -42
- package/dist/revertibles.js.map +1 -1
- package/dist/segmentGroupCollection.d.ts +0 -4
- package/dist/segmentGroupCollection.d.ts.map +1 -1
- package/dist/segmentGroupCollection.js +2 -12
- package/dist/segmentGroupCollection.js.map +1 -1
- package/dist/segmentPropertiesManager.d.ts.map +1 -1
- package/dist/segmentPropertiesManager.js +9 -15
- package/dist/segmentPropertiesManager.js.map +1 -1
- package/dist/snapshotChunks.d.ts +0 -5
- package/dist/snapshotChunks.d.ts.map +1 -1
- package/dist/snapshotChunks.js +4 -4
- package/dist/snapshotChunks.js.map +1 -1
- package/dist/snapshotLoader.d.ts.map +1 -1
- package/dist/snapshotLoader.js +25 -25
- package/dist/snapshotLoader.js.map +1 -1
- package/dist/snapshotV1.d.ts.map +1 -1
- package/dist/snapshotV1.js +15 -15
- package/dist/snapshotV1.js.map +1 -1
- package/dist/snapshotlegacy.d.ts.map +1 -1
- package/dist/snapshotlegacy.js +11 -14
- package/dist/snapshotlegacy.js.map +1 -1
- package/dist/sortedSegmentSet.js +2 -3
- package/dist/sortedSegmentSet.js.map +1 -1
- package/dist/sortedSet.d.ts.map +1 -1
- package/dist/sortedSet.js +1 -3
- package/dist/sortedSet.js.map +1 -1
- package/dist/textSegment.js +2 -2
- package/dist/textSegment.js.map +1 -1
- package/dist/zamboni.js +45 -56
- package/dist/zamboni.js.map +1 -1
- package/lib/MergeTreeTextHelper.d.ts.map +1 -1
- package/lib/MergeTreeTextHelper.js +3 -2
- package/lib/MergeTreeTextHelper.js.map +1 -1
- package/lib/attributionCollection.d.ts +5 -2
- package/lib/attributionCollection.d.ts.map +1 -1
- package/lib/attributionCollection.js +14 -21
- package/lib/attributionCollection.js.map +1 -1
- package/lib/attributionPolicy.d.ts +3 -2
- package/lib/attributionPolicy.d.ts.map +1 -1
- package/lib/attributionPolicy.js +10 -11
- package/lib/attributionPolicy.js.map +1 -1
- package/lib/client.d.ts +19 -15
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +70 -49
- package/lib/client.js.map +1 -1
- package/lib/collections/list.d.ts +3 -0
- package/lib/collections/list.d.ts.map +1 -1
- package/lib/collections/list.js +40 -3
- package/lib/collections/list.js.map +1 -1
- package/lib/endOfTreeSegment.d.ts +1 -1
- package/lib/endOfTreeSegment.d.ts.map +1 -1
- package/lib/endOfTreeSegment.js +3 -4
- package/lib/endOfTreeSegment.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/localReference.js +33 -42
- package/lib/localReference.js.map +1 -1
- package/lib/mergeTree.d.ts +45 -28
- package/lib/mergeTree.d.ts.map +1 -1
- package/lib/mergeTree.js +207 -311
- package/lib/mergeTree.js.map +1 -1
- package/lib/mergeTreeDeltaCallback.d.ts +4 -0
- package/lib/mergeTreeDeltaCallback.d.ts.map +1 -1
- package/lib/mergeTreeDeltaCallback.js +0 -4
- package/lib/mergeTreeDeltaCallback.js.map +1 -1
- package/lib/mergeTreeNodeWalk.js +4 -4
- package/lib/mergeTreeNodeWalk.js.map +1 -1
- package/lib/mergeTreeNodes.d.ts +69 -12
- package/lib/mergeTreeNodes.d.ts.map +1 -1
- package/lib/mergeTreeNodes.js +30 -33
- package/lib/mergeTreeNodes.js.map +1 -1
- package/lib/mergeTreeTracking.d.ts +0 -6
- package/lib/mergeTreeTracking.d.ts.map +1 -1
- package/lib/mergeTreeTracking.js +0 -9
- package/lib/mergeTreeTracking.js.map +1 -1
- package/lib/opBuilder.d.ts +2 -0
- package/lib/opBuilder.d.ts.map +1 -1
- package/lib/opBuilder.js +3 -0
- package/lib/opBuilder.js.map +1 -1
- package/lib/ops.d.ts +12 -0
- package/lib/ops.d.ts.map +1 -1
- package/lib/ops.js +9 -0
- package/lib/ops.js.map +1 -1
- package/lib/ordinal.js +1 -1
- package/lib/ordinal.js.map +1 -1
- package/lib/partialLengths.js +28 -31
- package/lib/partialLengths.js.map +1 -1
- package/lib/properties.js +3 -3
- package/lib/properties.js.map +1 -1
- package/lib/referencePositions.d.ts +4 -2
- package/lib/referencePositions.d.ts.map +1 -1
- package/lib/referencePositions.js +2 -16
- package/lib/referencePositions.js.map +1 -1
- package/lib/revertibles.d.ts.map +1 -1
- package/lib/revertibles.js +25 -33
- package/lib/revertibles.js.map +1 -1
- package/lib/segmentGroupCollection.d.ts +0 -4
- package/lib/segmentGroupCollection.d.ts.map +1 -1
- package/lib/segmentGroupCollection.js +2 -12
- package/lib/segmentGroupCollection.js.map +1 -1
- package/lib/segmentPropertiesManager.d.ts.map +1 -1
- package/lib/segmentPropertiesManager.js +8 -14
- package/lib/segmentPropertiesManager.js.map +1 -1
- package/lib/snapshotChunks.d.ts +0 -5
- package/lib/snapshotChunks.d.ts.map +1 -1
- package/lib/snapshotChunks.js +4 -4
- package/lib/snapshotChunks.js.map +1 -1
- package/lib/snapshotLoader.d.ts.map +1 -1
- package/lib/snapshotLoader.js +16 -16
- package/lib/snapshotLoader.js.map +1 -1
- package/lib/snapshotV1.d.ts.map +1 -1
- package/lib/snapshotV1.js +12 -12
- package/lib/snapshotV1.js.map +1 -1
- package/lib/snapshotlegacy.d.ts.map +1 -1
- package/lib/snapshotlegacy.js +8 -11
- package/lib/snapshotlegacy.js.map +1 -1
- package/lib/sortedSegmentSet.js +2 -3
- package/lib/sortedSegmentSet.js.map +1 -1
- package/lib/sortedSet.d.ts.map +1 -1
- package/lib/sortedSet.js +1 -3
- package/lib/sortedSet.js.map +1 -1
- package/lib/textSegment.js +1 -1
- package/lib/textSegment.js.map +1 -1
- package/lib/zamboni.js +45 -56
- package/lib/zamboni.js.map +1 -1
- package/package.json +27 -31
- package/src/MergeTreeTextHelper.ts +3 -0
- package/src/attributionCollection.ts +6 -3
- package/src/attributionPolicy.ts +4 -3
- package/src/client.ts +75 -39
- package/src/collections/list.ts +47 -4
- package/src/endOfTreeSegment.ts +5 -4
- package/src/index.ts +6 -20
- package/src/localReference.ts +2 -2
- package/src/mergeTree.ts +233 -294
- package/src/mergeTreeDeltaCallback.ts +7 -1
- package/src/mergeTreeNodes.ts +77 -45
- package/src/mergeTreeTracking.ts +0 -10
- package/src/opBuilder.ts +3 -0
- package/src/ops.ts +12 -0
- package/src/ordinal.ts +1 -1
- package/src/partialLengths.ts +1 -1
- package/src/referencePositions.ts +6 -18
- package/src/revertibles.ts +7 -5
- package/src/segmentGroupCollection.ts +0 -9
- package/src/segmentPropertiesManager.ts +3 -5
- package/src/snapshotChunks.ts +0 -5
- package/src/snapshotLoader.ts +14 -7
- package/src/snapshotV1.ts +8 -5
- package/src/snapshotlegacy.ts +3 -3
- package/src/sortedSet.ts +1 -3
- package/src/textSegment.ts +1 -1
- package/src/zamboni.ts +55 -59
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,120 @@
|
|
|
1
1
|
# @fluidframework/merge-tree
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.6.3.0
|
|
4
|
+
|
|
5
|
+
Dependency updates only.
|
|
6
|
+
|
|
7
|
+
## 2.0.0-internal.6.2.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- Deprecate getStackContext and associated NestBegin/End ([#16877](https://github.com/microsoft/FluidFramework/issues/16877)) [8e743fe1dd](https://github.com/microsoft/FluidFramework/commits/8e743fe1dde9adb3a1240971987d3abd51ab2fbe)
|
|
12
|
+
|
|
13
|
+
Deprecate SharedSegmentSequence.getStackContext and Client.getStackContext (and the enums ReferenceType.NestBegin and NestEnd they use).
|
|
14
|
+
This functionality is unused, poorly tested, and incurs performance overhead.
|
|
15
|
+
|
|
16
|
+
- Remove use of @fluidframework/common-definitions ([#16638](https://github.com/microsoft/FluidFramework/issues/16638)) [a8c81509c9](https://github.com/microsoft/FluidFramework/commits/a8c81509c9bf09cfb2092ebcf7265205f9eb6dbf)
|
|
17
|
+
|
|
18
|
+
The **@fluidframework/common-definitions** package is being deprecated, so the following interfaces and types are now
|
|
19
|
+
imported from the **@fluidframework/core-interfaces** package:
|
|
20
|
+
|
|
21
|
+
- interface IDisposable
|
|
22
|
+
- interface IErrorEvent
|
|
23
|
+
- interface IErrorEvent
|
|
24
|
+
- interface IEvent
|
|
25
|
+
- interface IEventProvider
|
|
26
|
+
- interface ILoggingError
|
|
27
|
+
- interface ITaggedTelemetryPropertyType
|
|
28
|
+
- interface ITelemetryBaseEvent
|
|
29
|
+
- interface ITelemetryBaseLogger
|
|
30
|
+
- interface ITelemetryErrorEvent
|
|
31
|
+
- interface ITelemetryGenericEvent
|
|
32
|
+
- interface ITelemetryLogger
|
|
33
|
+
- interface ITelemetryPerformanceEvent
|
|
34
|
+
- interface ITelemetryProperties
|
|
35
|
+
- type ExtendEventProvider
|
|
36
|
+
- type IEventThisPlaceHolder
|
|
37
|
+
- type IEventTransformer
|
|
38
|
+
- type ReplaceIEventThisPlaceHolder
|
|
39
|
+
- type ReplaceIEventThisPlaceHolder
|
|
40
|
+
- type TelemetryEventCategory
|
|
41
|
+
- type TelemetryEventPropertyType
|
|
42
|
+
|
|
43
|
+
- Deprecation of findTile in favor of searchForMarker, which uses depthFirstNodeWalk to locate the nearest marker. ([#16517](https://github.com/microsoft/FluidFramework/issues/16517)) [e928b1f185](https://github.com/microsoft/FluidFramework/commits/e928b1f185ca32123eff9d4bfc5bce28ba1b95c1)
|
|
44
|
+
|
|
45
|
+
findTile has a decent amount of buggy behavior, which leads partners who want to use it to implement workarounds for the odd behavior. searchForMarker is being introduced as a replacement. It performs the same basic functionality of searching for the nearest marker to a given start position in the indicated direction. However, it includes the start position as one of the nodes to search, so markers at the start position will be returned as the nearest marker to that position. Notably, positions 0 and length-1 will be included in the search as well, so searching forwards from position 0 or backwards from position length-1 would allow the entire string to be searched.
|
|
46
|
+
|
|
47
|
+
## 2.0.0-internal.6.1.0
|
|
48
|
+
|
|
49
|
+
Dependency updates only.
|
|
50
|
+
|
|
51
|
+
## 2.0.0-internal.6.0.0
|
|
52
|
+
|
|
53
|
+
### Major Changes
|
|
54
|
+
|
|
55
|
+
- Client.getSlideToSegment removed [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
56
|
+
|
|
57
|
+
Client.getSlideToSegment was deprecated in 2.0.0-internal.5.3.0 and has been removed. Use getSlideToSegoff function instead.
|
|
58
|
+
|
|
59
|
+
- Remove ISegment.parent [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
60
|
+
|
|
61
|
+
This change removed the parent property on the ISegment interface. The property will still exist, but should not generally be used by outside consumers.
|
|
62
|
+
|
|
63
|
+
There are some circumstances where a consumer may wish to know if a segment is still in the underlying tree and were using the parent property to determine that.
|
|
64
|
+
|
|
65
|
+
Please change those checks to use the following `"parent" in segment && segment.parent !== undefined`
|
|
66
|
+
|
|
67
|
+
- merge-tree now has new length calculations by default [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
68
|
+
|
|
69
|
+
The merge-tree now enables new length calculations by default and resolves some related performance bugs by making cached segment length
|
|
70
|
+
nullable.
|
|
71
|
+
|
|
72
|
+
Hierarchy cached segment length is `undefined` if the length of all child nodes is `undefined`.
|
|
73
|
+
|
|
74
|
+
- Segments Property Removed from TrackingGroup [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
75
|
+
|
|
76
|
+
Tracking groups can contain more than just segments, so the deprecated segments property has been removed. Use the tracked property instead to see all tracked objects.
|
|
77
|
+
|
|
78
|
+
- Remove unnecessary exports [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
79
|
+
|
|
80
|
+
This change removes a number of interfaces in the merge tree package that are not used in the exported apis surface and therefore should not be used.
|
|
81
|
+
|
|
82
|
+
- Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
83
|
+
|
|
84
|
+
Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
|
|
85
|
+
|
|
86
|
+
## 2.0.0-internal.5.4.0
|
|
87
|
+
|
|
88
|
+
Dependency updates only.
|
|
89
|
+
|
|
90
|
+
## 2.0.0-internal.5.3.0
|
|
91
|
+
|
|
92
|
+
Dependency updates only.
|
|
93
|
+
|
|
94
|
+
## 2.0.0-internal.5.2.0
|
|
95
|
+
|
|
96
|
+
### Minor Changes
|
|
97
|
+
|
|
98
|
+
- Deprecate unnecessary exports ([#16097](https://github.com/microsoft/FluidFramework/issues/16097)) [9486bec0ea](https://github.com/microsoft/FluidFramework/commits/9486bec0ea2f9f1dd3e40fc3b4c42af6b6a44697)
|
|
99
|
+
|
|
100
|
+
This change deprecates a number of interfaces in the merge tree package that are not used in the exported apis surface and therefore should not be used.
|
|
101
|
+
|
|
102
|
+
- Deprecate ISegment.parent ([#16097](https://github.com/microsoft/FluidFramework/issues/16097)) [9486bec0ea](https://github.com/microsoft/FluidFramework/commits/9486bec0ea2f9f1dd3e40fc3b4c42af6b6a44697)
|
|
103
|
+
|
|
104
|
+
This change deprecates the parent property on the ISegment interface. The property will still exist, but should not generally be used by outside consumers.
|
|
105
|
+
|
|
106
|
+
There are some circumstances where a consumer may wish to know if a segment is still in the underlying tree and were using the parent property to determine that.
|
|
107
|
+
|
|
108
|
+
Please change those checks to use the following `"parent" in segment && segment.parent !== undefined`
|
|
109
|
+
|
|
110
|
+
## 2.0.0-internal.5.1.0
|
|
111
|
+
|
|
112
|
+
### Minor Changes
|
|
113
|
+
|
|
114
|
+
- New APIs for interval querying by range ([#15837](https://github.com/microsoft/FluidFramework/issues/15837)) [2a4242e1b5](https://github.com/microsoft/FluidFramework/commits/2a4242e1b5f15442b13ae413124ec76315a4cc52)
|
|
115
|
+
|
|
116
|
+
SharedString now supports querying intervals whose start/end-points fall in a specified range.
|
|
117
|
+
|
|
3
118
|
## 2.0.0-internal.5.0.0
|
|
4
119
|
|
|
5
120
|
Dependency updates only.
|
package/README.md
CHANGED
|
@@ -16,9 +16,10 @@ When taking a dependency on a Fluid Framework library, we recommend using a `^`
|
|
|
16
16
|
While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
|
|
17
17
|
library consumers should always prefer `^`.
|
|
18
18
|
|
|
19
|
-
Note that when depending on a library version of the form 2.0.0-internal.x.y.z
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
|
|
20
|
+
you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
|
|
21
|
+
Standard `^` and `~` ranges will not work as expected.
|
|
22
|
+
See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
|
|
22
23
|
package for more information including tools to convert between version schemes.
|
|
23
24
|
|
|
24
25
|
<!-- prettier-ignore-end -->
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MergeTreeTextHelper.d.ts","sourceRoot":"","sources":["../src/MergeTreeTextHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"MergeTreeTextHelper.d.ts","sourceRoot":"","sources":["../src/MergeTreeTextHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAe,MAAM,eAAe,CAAC;AAQlE,qBAAa,mBAAoB,YAAW,oBAAoB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAE1C,OAAO,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,SAAK,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM;IAiBb,OAAO,CAAC,aAAa;CAcrB"}
|
|
@@ -17,9 +17,10 @@ class MergeTreeTextHelper {
|
|
|
17
17
|
return accum.textSegment.text;
|
|
18
18
|
}
|
|
19
19
|
getValidRange(start, end, refSeq, clientId) {
|
|
20
|
+
// eslint-disable-next-line import/no-deprecated
|
|
20
21
|
const range = {
|
|
21
|
-
end: end
|
|
22
|
-
start: start
|
|
22
|
+
end: end ?? this.mergeTree.getLength(refSeq, clientId),
|
|
23
|
+
start: start ?? 0,
|
|
23
24
|
};
|
|
24
25
|
return range;
|
|
25
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MergeTreeTextHelper.js","sourceRoot":"","sources":["../src/MergeTreeTextHelper.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"MergeTreeTextHelper.js","sourceRoot":"","sources":["../src/MergeTreeTextHelper.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,+CAAkE;AAQlE,MAAa,mBAAmB;IAC/B,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE9C,OAAO,CACb,MAAc,EACd,QAAgB,EAChB,WAAW,GAAG,EAAE,EAChB,KAAc,EACd,GAAY;QAEZ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QAE/D,MAAM,KAAK,GAAqB,EAAE,WAAW,EAAE,IAAI,yBAAW,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC;QAElF,IAAI,CAAC,SAAS,CAAC,QAAQ,CACtB,UAAU,EACV,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,GAAG,CACT,CAAC;QACF,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAEO,aAAa,CACpB,KAAyB,EACzB,GAAuB,EACvB,MAAc,EACd,QAAgB;QAGhB,gDAAgD;QAChD,MAAM,KAAK,GAAkB;YAC5B,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;YACtD,KAAK,EAAE,KAAK,IAAI,CAAC;SACjB,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAvCD,kDAuCC;AAED,SAAS,UAAU,CAClB,OAAiB,EACjB,GAAW,EACX,MAAc,EACd,QAAgB,EAChB,KAAa,EACb,GAAW,EACX,EAAE,WAAW,EAAE,WAAW,EAAoB;IAE9C,IAAI,yBAAW,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;QAC5B,IAAI,KAAK,IAAI,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;YAC7C,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;SACjC;aAAM;YACN,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;YACnC,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACrC,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzD;KACD;SAAM,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QACjD,MAAM,eAAe,GACpB,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACjF,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;KACpC;IAED,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line import/no-deprecated\nimport { IIntegerRange } from \"./base\";\nimport { ISegment } from \"./mergeTreeNodes\";\nimport { MergeTree } from \"./mergeTree\";\nimport { IMergeTreeTextHelper, TextSegment } from \"./textSegment\";\n\ninterface ITextAccumulator {\n\ttextSegment: TextSegment;\n\tplaceholder?: string;\n\tparallelArrays?: boolean;\n}\n\nexport class MergeTreeTextHelper implements IMergeTreeTextHelper {\n\tconstructor(private readonly mergeTree: MergeTree) {}\n\n\tpublic getText(\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tplaceholder = \"\",\n\t\tstart?: number,\n\t\tend?: number,\n\t) {\n\t\tconst range = this.getValidRange(start, end, refSeq, clientId);\n\n\t\tconst accum: ITextAccumulator = { textSegment: new TextSegment(\"\"), placeholder };\n\n\t\tthis.mergeTree.mapRange<ITextAccumulator>(\n\t\t\tgatherText,\n\t\t\trefSeq,\n\t\t\tclientId,\n\t\t\taccum,\n\t\t\trange.start,\n\t\t\trange.end,\n\t\t);\n\t\treturn accum.textSegment.text;\n\t}\n\n\tprivate getValidRange(\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t): IIntegerRange {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tconst range: IIntegerRange = {\n\t\t\tend: end ?? this.mergeTree.getLength(refSeq, clientId),\n\t\t\tstart: start ?? 0,\n\t\t};\n\t\treturn range;\n\t}\n}\n\nfunction gatherText(\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\t{ textSegment, placeholder }: ITextAccumulator,\n): boolean {\n\tif (TextSegment.is(segment)) {\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else if (placeholder && placeholder.length > 0) {\n\t\tconst placeholderText =\n\t\t\tplaceholder === \"*\" ? `\\n${segment}` : placeholder.repeat(segment.cachedLength);\n\t\ttextSegment.text += placeholderText;\n\t}\n\n\treturn true;\n}\n"]}
|
|
@@ -10,11 +10,14 @@ import { ISegment } from "./mergeTreeNodes";
|
|
|
10
10
|
export interface SequenceOffsets {
|
|
11
11
|
/**
|
|
12
12
|
* Parallel array with posBreakpoints which tracks the seq of insertion.
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* If seqs is [45, 46] and posBreakpoints is [0, 3], the section of the string
|
|
14
17
|
* between offsets 0 and 3 was inserted at seq 45 and the section of the string between
|
|
15
18
|
* 3 and the length of the string was inserted at seq 46.
|
|
16
19
|
*
|
|
17
|
-
* @remarks
|
|
20
|
+
* @remarks We use null here rather than undefined as round-tripping through JSON converts
|
|
18
21
|
* undefineds to null anyway
|
|
19
22
|
*/
|
|
20
23
|
seqs: (number | AttributionKey | null)[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributionCollection.d.ts","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,cAAc,EAGd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B
|
|
1
|
+
{"version":3,"file":"attributionCollection.d.ts","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,cAAc,EAGd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,CAAC,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC,EAAE,CAAC;IACzC,cAAc,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,+BAAgC,SAAQ,eAAe;IACvE,QAAQ,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAC;IAE/C,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MA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GACtC,IAAI;IAuDP;;;;;OAKG;WACW,+BAA+B,CAC5C,QAAQ,EAAE,QAAQ,CAAC;QAClB,WAAW,CAAC,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;QACrD,YAAY,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,+BAA+B;CA8DlC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.AttributionCollection = exports.areEqualAttributionKeys = void 0;
|
|
8
|
-
const
|
|
8
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
9
|
// note: treats null and undefined as equivalent
|
|
10
10
|
function areEqualAttributionKeys(a, b) {
|
|
11
11
|
if (!a && !b) {
|
|
@@ -26,7 +26,7 @@ function areEqualAttributionKeys(a, b) {
|
|
|
26
26
|
case "local":
|
|
27
27
|
return true;
|
|
28
28
|
default:
|
|
29
|
-
(0,
|
|
29
|
+
(0, core_utils_1.unreachableCase)(a, "Unhandled AttributionKey type");
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.areEqualAttributionKeys = areEqualAttributionKeys;
|
|
@@ -41,20 +41,17 @@ class AttributionCollection {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
get channelEntries() {
|
|
44
|
-
|
|
45
|
-
return Object.entries((_a = this.channels) !== null && _a !== void 0 ? _a : {});
|
|
44
|
+
return Object.entries(this.channels ?? {});
|
|
46
45
|
}
|
|
47
46
|
get channelNames() {
|
|
48
|
-
|
|
49
|
-
return Object.keys((_a = this.channels) !== null && _a !== void 0 ? _a : {});
|
|
47
|
+
return Object.keys(this.channels ?? {});
|
|
50
48
|
}
|
|
51
49
|
getAtOffset(offset, channel) {
|
|
52
|
-
var _a;
|
|
53
50
|
if (channel !== undefined) {
|
|
54
|
-
const subCollection =
|
|
55
|
-
return subCollection
|
|
51
|
+
const subCollection = this.channels?.[channel];
|
|
52
|
+
return subCollection?.getAtOffset(offset);
|
|
56
53
|
}
|
|
57
|
-
(0,
|
|
54
|
+
(0, core_utils_1.assert)(offset >= 0 && offset < this._length, 0x443 /* Requested offset should be valid */);
|
|
58
55
|
return this.get(this.findIndex(offset));
|
|
59
56
|
}
|
|
60
57
|
findIndex(offset) {
|
|
@@ -97,8 +94,7 @@ class AttributionCollection {
|
|
|
97
94
|
return splitCollection;
|
|
98
95
|
}
|
|
99
96
|
append(other) {
|
|
100
|
-
var _a
|
|
101
|
-
var _d;
|
|
97
|
+
var _a;
|
|
102
98
|
const lastEntry = this.keys[this.keys.length - 1];
|
|
103
99
|
for (let i = 0; i < other.keys.length; i++) {
|
|
104
100
|
if (i !== 0 || !areEqualAttributionKeys(lastEntry, other.keys[i])) {
|
|
@@ -107,13 +103,13 @@ class AttributionCollection {
|
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
if (other.channels !== undefined || this.channels !== undefined) {
|
|
110
|
-
|
|
106
|
+
this.channels ?? (this.channels = {});
|
|
111
107
|
for (const [key, collection] of other.channelEntries) {
|
|
112
|
-
const thisCollection = ((
|
|
108
|
+
const thisCollection = ((_a = this.channels)[key] ?? (_a[key] = new AttributionCollection(this.length, null)));
|
|
113
109
|
thisCollection.append(collection);
|
|
114
110
|
}
|
|
115
111
|
for (const [key, collection] of this.channelEntries) {
|
|
116
|
-
if (
|
|
112
|
+
if (other.channels?.[key] === undefined) {
|
|
117
113
|
collection.append(new AttributionCollection(other.length, null));
|
|
118
114
|
}
|
|
119
115
|
}
|
|
@@ -151,14 +147,13 @@ class AttributionCollection {
|
|
|
151
147
|
return copy;
|
|
152
148
|
}
|
|
153
149
|
update(name, channel) {
|
|
154
|
-
|
|
155
|
-
(0, common_utils_1.assert)(channel.length === this.length, 0x5c0 /* AttributionCollection channel update should have consistent segment length */);
|
|
150
|
+
(0, core_utils_1.assert)(channel.length === this.length, 0x5c0 /* AttributionCollection channel update should have consistent segment length */);
|
|
156
151
|
if (name === undefined) {
|
|
157
152
|
this.offsets = [...channel.offsets];
|
|
158
153
|
this.keys = [...channel.keys];
|
|
159
154
|
}
|
|
160
155
|
else {
|
|
161
|
-
|
|
156
|
+
this.channels ?? (this.channels = {});
|
|
162
157
|
if (this.channels[name] !== undefined) {
|
|
163
158
|
this.channels[name].update(undefined, channel);
|
|
164
159
|
}
|
|
@@ -172,7 +167,7 @@ class AttributionCollection {
|
|
|
172
167
|
*/
|
|
173
168
|
static populateAttributionCollections(segments, summary) {
|
|
174
169
|
const { channels } = summary;
|
|
175
|
-
(0,
|
|
170
|
+
(0, core_utils_1.assert)(summary.seqs.length === summary.posBreakpoints.length, 0x445 /* Invalid attribution summary blob provided */);
|
|
176
171
|
const extractOntoSegments = ({ seqs, posBreakpoints }, assignToSegment) => {
|
|
177
172
|
let curIndex = 0;
|
|
178
173
|
let cumulativeSegPos = 0;
|
|
@@ -204,9 +199,8 @@ class AttributionCollection {
|
|
|
204
199
|
for (const [name, collectionSpec] of Object.entries(channels)) {
|
|
205
200
|
extractOntoSegments(collectionSpec, (collection, segment) => {
|
|
206
201
|
var _a;
|
|
207
|
-
var _b;
|
|
208
202
|
// Cast is valid as we just assigned this field above
|
|
209
|
-
((_a =
|
|
203
|
+
((_a = segment.attribution).channels ?? (_a.channels = {}))[name] =
|
|
210
204
|
collection;
|
|
211
205
|
});
|
|
212
206
|
}
|
|
@@ -219,11 +213,10 @@ class AttributionCollection {
|
|
|
219
213
|
* where only some segments have attribution defined.
|
|
220
214
|
*/
|
|
221
215
|
static serializeAttributionCollections(segments) {
|
|
222
|
-
var _a;
|
|
223
216
|
const allCollectionSpecs = [];
|
|
224
217
|
const allChannelNames = new Set();
|
|
225
218
|
for (const segment of segments) {
|
|
226
|
-
const collection =
|
|
219
|
+
const collection = segment.attribution ?? new AttributionCollection(segment.cachedLength, null);
|
|
227
220
|
const spec = collection.getAll();
|
|
228
221
|
allCollectionSpecs.push(spec);
|
|
229
222
|
if (spec.channels) {
|
|
@@ -239,7 +232,7 @@ class AttributionCollection {
|
|
|
239
232
|
let cumulativePos = 0;
|
|
240
233
|
for (const spec of allCollectionSpecs) {
|
|
241
234
|
for (const { offset, key } of getSpecEntries(spec)) {
|
|
242
|
-
(0,
|
|
235
|
+
(0, core_utils_1.assert)(key?.type !== "local", 0x5c1 /* local attribution keys should never be put in summaries */);
|
|
243
236
|
if (mostRecentAttributionKey === undefined ||
|
|
244
237
|
!areEqualAttributionKeys(key, mostRecentAttributionKey)) {
|
|
245
238
|
posBreakpoints.push(offset + cumulativePos);
|
|
@@ -255,7 +248,7 @@ class AttributionCollection {
|
|
|
255
248
|
if (allChannelNames.size > 0) {
|
|
256
249
|
const channels = {};
|
|
257
250
|
for (const name of allChannelNames) {
|
|
258
|
-
const { posBreakpoints, seqs } = extractSequenceOffsets((spec) =>
|
|
251
|
+
const { posBreakpoints, seqs } = extractSequenceOffsets((spec) => spec.channels?.[name] ?? [{ offset: 0, key: null }]);
|
|
259
252
|
channels[name] = { posBreakpoints, seqs };
|
|
260
253
|
}
|
|
261
254
|
blobContents.channels = channels;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributionCollection.js","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAuE;AAkHvE,gDAAgD;AAChD,SAAgB,uBAAuB,CACtC,CAAoC,EACpC,CAAoC;IAEpC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;QACb,OAAO,IAAI,CAAC;KACZ;IAED,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;QACb,OAAO,KAAK,CAAC;KACb;IAED,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE;QACtB,OAAO,KAAK,CAAC;KACb;IAED,gGAAgG;IAChG,QAAQ,CAAC,CAAC,IAAI,EAAE;QACf,KAAK,IAAI;YACR,OAAO,CAAC,CAAC,GAAG,KAAM,CAAsB,CAAC,GAAG,CAAC;QAC9C,KAAK,UAAU;YACd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,CAAC;aAC7B;YAED,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;QACxD,CAAC,CAAC;QAEF,MAAM,YAAY,GAAG,sBAAsB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,IAAI,eAAe,CAAC,IAAI,GAAG,CAAC,EAAE;YAC7B,MAAM,QAAQ,GAAwC,EAAE,CAAC;YACzD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE;gBACnC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,sBAAsB,CACtD,CAAC,IAAI,EAAE,EAAE,eAAC,OAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAG,IAAI,CAAC,mCAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA,EAAA,CAC7D,CAAC;gBACF,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;aAC1C;YACD,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;SACjC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;CACD;AAlSD,sDAkSC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/common-utils\";\nimport {\n\tAttributionKey,\n\tOpAttributionKey,\n\tDetachedAttributionKey,\n} from \"@fluidframework/runtime-definitions\";\nimport { ISegment } from \"./mergeTreeNodes\";\n\n/**\n * @internal\n */\nexport interface SequenceOffsets {\n\t/**\n\t * Parallel array with posBreakpoints which tracks the seq of insertion.\n\t * Ex: if seqs is [45, 46] and posBreakpoints is [0, 3], the section of the string\n\t * between offsets 0 and 3 was inserted at seq 45 and the section of the string between\n\t * 3 and the length of the string was inserted at seq 46.\n\t *\n\t * @remarks - We use null here rather than undefined as round-tripping through JSON converts\n\t * undefineds to null anyway\n\t */\n\tseqs: (number | AttributionKey | null)[];\n\tposBreakpoints: number[];\n}\n\n/**\n * @internal\n */\nexport interface SerializedAttributionCollection extends SequenceOffsets {\n\tchannels?: { [name: string]: SequenceOffsets };\n\t/* Total length; only necessary for validation */\n\tlength: number;\n}\n\n/**\n * @internal\n */\nexport interface IAttributionCollectionSpec<T> {\n\troot: Iterable<{ offset: number; key: T | null }>;\n\tchannels?: { [name: string]: Iterable<{ offset: number; key: T | null }> };\n\tlength: number;\n}\n\n/**\n * @internal\n * @sealed\n */\nexport interface IAttributionCollectionSerializer {\n\t/**\n\t * @internal\n\t */\n\tserializeAttributionCollections(\n\t\tsegments: Iterable<{\n\t\t\tattribution?: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}>,\n\t): SerializedAttributionCollection;\n\n\t/**\n\t * Populates attribution information on segments using the provided summary.\n\t * @internal\n\t */\n\tpopulateAttributionCollections(\n\t\tsegments: Iterable<ISegment>,\n\t\tsummary: SerializedAttributionCollection,\n\t): void;\n}\n\n/**\n * @alpha\n */\nexport interface IAttributionCollection<T> {\n\t/**\n\t * Retrieves the attribution key associated with the provided offset.\n\t * @param channel - When specified, gets an attribution key associated with a particular channel.\n\t */\n\tgetAtOffset(offset: number, channel?: string): AttributionKey | undefined;\n\n\t/**\n\t * Total length of all attribution keys in this collection.\n\t */\n\treadonly length: number;\n\n\treadonly channelNames: Iterable<string>;\n\n\t/**\n\t * Retrieve all key/offset pairs stored on this segment. Entries should be ordered by offset, such that\n\t * the `i`th result's attribution key applies to offsets in the open range between the `i`th offset and the\n\t * `i+1`th offset.\n\t * The last entry's key applies to the open interval from the last entry's offset to this collection's length.\n\t * @internal\n\t */\n\tgetAll(): IAttributionCollectionSpec<T>;\n\n\t/** @internal */\n\tsplitAt(pos: number): IAttributionCollection<T>;\n\n\t/** @internal */\n\tappend(other: IAttributionCollection<T>): void;\n\n\t/** @internal */\n\tclone(): IAttributionCollection<T>;\n\n\t/**\n\t * Updates this collection with new attribution data.\n\t * @param name - Name of the channel that requires an update. Undefined signifies the root channel.\n\t * Updates apply only to the individual channel (i.e. if an attribution policy needs to update the root\n\t * channel and 4 other channels, it should call `.update` 5 times).\n\t * @param channel - Updated collection for that channel.\n\t * @internal\n\t */\n\tupdate(name: string | undefined, channel: IAttributionCollection<T>);\n}\n\n// note: treats null and undefined as equivalent\nexport function areEqualAttributionKeys(\n\ta: AttributionKey | null | undefined,\n\tb: AttributionKey | null | undefined,\n): boolean {\n\tif (!a && !b) {\n\t\treturn true;\n\t}\n\n\tif (!a || !b) {\n\t\treturn false;\n\t}\n\n\tif (a.type !== b.type) {\n\t\treturn false;\n\t}\n\n\t// Note: TS can't narrow the type of b inside this switch statement, hence the need for casting.\n\tswitch (a.type) {\n\t\tcase \"op\":\n\t\t\treturn a.seq === (b as OpAttributionKey).seq;\n\t\tcase \"detached\":\n\t\t\treturn a.id === (b as DetachedAttributionKey).id;\n\t\tcase \"local\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\tunreachableCase(a, \"Unhandled AttributionKey type\");\n\t}\n}\n\nexport class AttributionCollection implements IAttributionCollection<AttributionKey> {\n\tprivate offsets: number[] = [];\n\tprivate keys: (AttributionKey | null)[] = [];\n\n\tprivate channels?: { [name: string]: AttributionCollection };\n\n\tprivate get channelEntries(): [string, AttributionCollection][] {\n\t\treturn Object.entries(this.channels ?? {});\n\t}\n\n\tpublic constructor(private _length: number, baseEntry?: AttributionKey | null) {\n\t\tif (baseEntry !== undefined) {\n\t\t\tthis.offsets.push(0);\n\t\t\tthis.keys.push(baseEntry);\n\t\t}\n\t}\n\n\tpublic get channelNames(): string[] {\n\t\treturn Object.keys(this.channels ?? {});\n\t}\n\n\tpublic getAtOffset(offset: number): AttributionKey;\n\tpublic getAtOffset(offset: number, channel: string): AttributionKey | undefined;\n\tpublic getAtOffset(offset: number, channel?: string): AttributionKey | undefined {\n\t\tif (channel !== undefined) {\n\t\t\tconst subCollection = this.channels?.[channel];\n\t\t\treturn subCollection?.getAtOffset(offset);\n\t\t}\n\t\tassert(offset >= 0 && offset < this._length, 0x443 /* Requested offset should be valid */);\n\t\treturn this.get(this.findIndex(offset));\n\t}\n\n\tprivate findIndex(offset: number): number {\n\t\t// Note: maximum length here is 256 for text segments. Perf testing shows that linear scan beats binary search\n\t\t// for attribution collections with under ~64 entries, and even at maximum size (which would require a maximum\n\t\t// length segment with every offset having different attribution), getAtOffset is on the order of 100ns.\n\t\tlet i = 0;\n\t\twhile (i < this.offsets.length && offset > this.offsets[i]) {\n\t\t\ti++;\n\t\t}\n\t\treturn this.offsets[i] === offset ? i : i - 1;\n\t}\n\n\tprivate get(index: number): AttributionKey | undefined {\n\t\tconst key = this.keys[index];\n\t\treturn key !== null ? key : undefined;\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._length;\n\t}\n\n\t/**\n\t * Splits this attribution collection into two with entries for [0, pos) and [pos, length).\n\t */\n\tpublic splitAt(pos: number): AttributionCollection {\n\t\tconst splitIndex = this.findIndex(pos);\n\t\tconst splitCollection = new AttributionCollection(this.length - pos);\n\t\tfor (let i = splitIndex; i < this.keys.length; i++) {\n\t\t\tsplitCollection.offsets.push(Math.max(this.offsets[i] - pos, 0));\n\t\t\tsplitCollection.keys.push(this.keys[i]);\n\t\t}\n\n\t\tif (this.channels) {\n\t\t\tsplitCollection.channels = {};\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tsplitCollection.channels[key] = collection.splitAt(pos);\n\t\t\t}\n\t\t}\n\n\t\tconst spliceIndex = this.offsets[splitIndex] === pos ? splitIndex : splitIndex + 1;\n\t\tthis.keys.splice(spliceIndex);\n\t\tthis.offsets.splice(spliceIndex);\n\t\tthis._length = pos;\n\t\treturn splitCollection;\n\t}\n\n\tpublic append(other: AttributionCollection): void {\n\t\tconst lastEntry = this.keys[this.keys.length - 1];\n\t\tfor (let i = 0; i < other.keys.length; i++) {\n\t\t\tif (i !== 0 || !areEqualAttributionKeys(lastEntry, other.keys[i])) {\n\t\t\t\tthis.offsets.push(other.offsets[i] + this.length);\n\t\t\t\tthis.keys.push(other.keys[i]);\n\t\t\t}\n\t\t}\n\n\t\tif (other.channels !== undefined || this.channels !== undefined) {\n\t\t\tthis.channels ??= {};\n\t\t\tfor (const [key, collection] of other.channelEntries) {\n\t\t\t\tconst thisCollection = (this.channels[key] ??= new AttributionCollection(\n\t\t\t\t\tthis.length,\n\t\t\t\t\tnull,\n\t\t\t\t));\n\t\t\t\tthisCollection.append(collection);\n\t\t\t}\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tif (other.channels?.[key] === undefined) {\n\t\t\t\t\tcollection.append(new AttributionCollection(other.length, null));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis._length += other.length;\n\t}\n\n\tpublic getAll(): IAttributionCollectionSpec<AttributionKey> {\n\t\tconst root: IAttributionCollectionSpec<AttributionKey>[\"root\"] = new Array(\n\t\t\tthis.keys.length,\n\t\t);\n\t\tfor (let i = 0; i < this.keys.length; i++) {\n\t\t\troot[i] = { offset: this.offsets[i], key: this.keys[i] };\n\t\t}\n\t\tconst result: IAttributionCollectionSpec<AttributionKey> = {\n\t\t\troot,\n\t\t\tlength: this.length,\n\t\t};\n\t\tif (this.channels !== undefined) {\n\t\t\tresult.channels = {};\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tresult.channels[key] = collection.getAll().root;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic clone(): AttributionCollection {\n\t\tconst copy = new AttributionCollection(this.length);\n\t\tcopy.keys = this.keys.slice();\n\t\tcopy.offsets = this.offsets.slice();\n\t\tif (this.channels !== undefined) {\n\t\t\tconst channelsCopy = {};\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tchannelsCopy[key] = collection.clone();\n\t\t\t}\n\t\t\tcopy.channels = channelsCopy;\n\t\t}\n\t\treturn copy;\n\t}\n\n\tpublic update(name: string | undefined, channel: AttributionCollection) {\n\t\tassert(\n\t\t\tchannel.length === this.length,\n\t\t\t0x5c0 /* AttributionCollection channel update should have consistent segment length */,\n\t\t);\n\t\tif (name === undefined) {\n\t\t\tthis.offsets = [...channel.offsets];\n\t\t\tthis.keys = [...channel.keys];\n\t\t} else {\n\t\t\tthis.channels ??= {};\n\t\t\tif (this.channels[name] !== undefined) {\n\t\t\t\tthis.channels[name].update(undefined, channel);\n\t\t\t} else {\n\t\t\t\tthis.channels[name] = channel;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Rehydrates attribution information from its serialized form into the provided iterable of consecutive segments.\n\t */\n\tpublic static populateAttributionCollections(\n\t\tsegments: ISegment[],\n\t\tsummary: SerializedAttributionCollection,\n\t): void {\n\t\tconst { channels } = summary;\n\t\tassert(\n\t\t\tsummary.seqs.length === summary.posBreakpoints.length,\n\t\t\t0x445 /* Invalid attribution summary blob provided */,\n\t\t);\n\n\t\tconst extractOntoSegments = (\n\t\t\t{ seqs, posBreakpoints }: SequenceOffsets,\n\t\t\tassignToSegment: (collection: AttributionCollection, segment: ISegment) => void,\n\t\t) => {\n\t\t\tlet curIndex = 0;\n\t\t\tlet cumulativeSegPos = 0;\n\n\t\t\tfor (const segment of segments) {\n\t\t\t\tconst attribution = new AttributionCollection(segment.cachedLength);\n\t\t\t\tconst pushEntry = (offset: number, seq: AttributionKey | number | null) => {\n\t\t\t\t\tattribution.offsets.push(offset);\n\t\t\t\t\tattribution.keys.push(\n\t\t\t\t\t\tseq === null ? null : typeof seq === \"object\" ? seq : { type: \"op\", seq },\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tif (posBreakpoints[curIndex] > cumulativeSegPos) {\n\t\t\t\t\tcurIndex--;\n\t\t\t\t}\n\n\t\t\t\twhile (posBreakpoints[curIndex] < cumulativeSegPos + segment.cachedLength) {\n\t\t\t\t\tconst nextOffset = Math.max(posBreakpoints[curIndex] - cumulativeSegPos, 0);\n\t\t\t\t\tpushEntry(nextOffset, seqs[curIndex]);\n\t\t\t\t\tcurIndex++;\n\t\t\t\t}\n\n\t\t\t\tif (attribution.offsets.length === 0) {\n\t\t\t\t\tpushEntry(0, seqs[curIndex - 1]);\n\t\t\t\t}\n\n\t\t\t\tassignToSegment(attribution, segment);\n\t\t\t\tcumulativeSegPos += segment.cachedLength;\n\t\t\t}\n\t\t};\n\n\t\textractOntoSegments(summary, (collection, segment) => {\n\t\t\tsegment.attribution = collection;\n\t\t});\n\t\tif (channels) {\n\t\t\tfor (const [name, collectionSpec] of Object.entries(channels)) {\n\t\t\t\textractOntoSegments(collectionSpec, (collection, segment) => {\n\t\t\t\t\t// Cast is valid as we just assigned this field above\n\t\t\t\t\t((segment.attribution as AttributionCollection).channels ??= {})[name] =\n\t\t\t\t\t\tcollection;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Condenses attribution information on consecutive segments into a `SerializedAttributionCollection`\n\t *\n\t * Note: this operates on segments rather than attribution collections directly so that it can handle cases\n\t * where only some segments have attribution defined.\n\t */\n\tpublic static serializeAttributionCollections(\n\t\tsegments: Iterable<{\n\t\t\tattribution?: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}>,\n\t): SerializedAttributionCollection {\n\t\tconst allCollectionSpecs: IAttributionCollectionSpec<AttributionKey>[] = [];\n\n\t\tconst allChannelNames = new Set<string>();\n\t\tfor (const segment of segments) {\n\t\t\tconst collection =\n\t\t\t\tsegment.attribution ?? new AttributionCollection(segment.cachedLength, null);\n\t\t\tconst spec = collection.getAll();\n\t\t\tallCollectionSpecs.push(spec);\n\t\t\tif (spec.channels) {\n\t\t\t\tfor (const name of Object.keys(spec.channels)) {\n\t\t\t\t\tallChannelNames.add(name);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst extractSequenceOffsets = (\n\t\t\tgetSpecEntries: (\n\t\t\t\tspec: IAttributionCollectionSpec<AttributionKey>,\n\t\t\t) => Iterable<{ offset: number; key: AttributionKey | null }>,\n\t\t): SerializedAttributionCollection => {\n\t\t\tconst posBreakpoints: number[] = [];\n\t\t\tconst seqs: (number | AttributionKey | null)[] = [];\n\t\t\tlet mostRecentAttributionKey: AttributionKey | null | undefined;\n\t\t\tlet cumulativePos = 0;\n\n\t\t\tfor (const spec of allCollectionSpecs) {\n\t\t\t\tfor (const { offset, key } of getSpecEntries(spec)) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tkey?.type !== \"local\",\n\t\t\t\t\t\t0x5c1 /* local attribution keys should never be put in summaries */,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tmostRecentAttributionKey === undefined ||\n\t\t\t\t\t\t!areEqualAttributionKeys(key, mostRecentAttributionKey)\n\t\t\t\t\t) {\n\t\t\t\t\t\tposBreakpoints.push(offset + cumulativePos);\n\t\t\t\t\t\tseqs.push(!key ? null : key.type === \"op\" ? key.seq : key);\n\t\t\t\t\t}\n\t\t\t\t\tmostRecentAttributionKey = key;\n\t\t\t\t}\n\n\t\t\t\tcumulativePos += spec.length;\n\t\t\t}\n\n\t\t\treturn { seqs, posBreakpoints, length: cumulativePos };\n\t\t};\n\n\t\tconst blobContents = extractSequenceOffsets((spec) => spec.root);\n\t\tif (allChannelNames.size > 0) {\n\t\t\tconst channels: { [name: string]: SequenceOffsets } = {};\n\t\t\tfor (const name of allChannelNames) {\n\t\t\t\tconst { posBreakpoints, seqs } = extractSequenceOffsets(\n\t\t\t\t\t(spec) => spec.channels?.[name] ?? [{ offset: 0, key: null }],\n\t\t\t\t);\n\t\t\t\tchannels[name] = { posBreakpoints, seqs };\n\t\t\t}\n\t\t\tblobContents.channels = channels;\n\t\t}\n\n\t\treturn blobContents;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"attributionCollection.js","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAqE;AAqHrE,gDAAgD;AAChD,SAAgB,uBAAuB,CACtC,CAAoC,EACpC,CAAoC;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CAAC;wBAC5C,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;qBAC3D;oBACD,wBAAwB,GAAG,GAAG,CAAC;iBAC/B;gBAED,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC;aAC7B;YAED,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;QACxD,CAAC,CAAC;QAEF,MAAM,YAAY,GAAG,sBAAsB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,IAAI,eAAe,CAAC,IAAI,GAAG,CAAC,EAAE;YAC7B,MAAM,QAAQ,GAAwC,EAAE,CAAC;YACzD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE;gBACnC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,sBAAsB,CACtD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAC7D,CAAC;gBACF,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;aAC1C;YACD,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;SACjC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;CACD;AAlSD,sDAkSC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils\";\nimport {\n\tAttributionKey,\n\tOpAttributionKey,\n\tDetachedAttributionKey,\n} from \"@fluidframework/runtime-definitions\";\nimport { ISegment } from \"./mergeTreeNodes\";\n\n/**\n * @internal\n */\nexport interface SequenceOffsets {\n\t/**\n\t * Parallel array with posBreakpoints which tracks the seq of insertion.\n\t *\n\t * @example\n\t *\n\t * If seqs is [45, 46] and posBreakpoints is [0, 3], the section of the string\n\t * between offsets 0 and 3 was inserted at seq 45 and the section of the string between\n\t * 3 and the length of the string was inserted at seq 46.\n\t *\n\t * @remarks We use null here rather than undefined as round-tripping through JSON converts\n\t * undefineds to null anyway\n\t */\n\tseqs: (number | AttributionKey | null)[];\n\tposBreakpoints: number[];\n}\n\n/**\n * @internal\n */\nexport interface SerializedAttributionCollection extends SequenceOffsets {\n\tchannels?: { [name: string]: SequenceOffsets };\n\t/* Total length; only necessary for validation */\n\tlength: number;\n}\n\n/**\n * @internal\n */\nexport interface IAttributionCollectionSpec<T> {\n\troot: Iterable<{ offset: number; key: T | null }>;\n\tchannels?: { [name: string]: Iterable<{ offset: number; key: T | null }> };\n\tlength: number;\n}\n\n/**\n * @internal\n * @sealed\n */\nexport interface IAttributionCollectionSerializer {\n\t/**\n\t * @internal\n\t */\n\tserializeAttributionCollections(\n\t\tsegments: Iterable<{\n\t\t\tattribution?: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}>,\n\t): SerializedAttributionCollection;\n\n\t/**\n\t * Populates attribution information on segments using the provided summary.\n\t * @internal\n\t */\n\tpopulateAttributionCollections(\n\t\tsegments: Iterable<ISegment>,\n\t\tsummary: SerializedAttributionCollection,\n\t): void;\n}\n\n/**\n * @alpha\n */\nexport interface IAttributionCollection<T> {\n\t/**\n\t * Retrieves the attribution key associated with the provided offset.\n\t * @param channel - When specified, gets an attribution key associated with a particular channel.\n\t */\n\tgetAtOffset(offset: number, channel?: string): AttributionKey | undefined;\n\n\t/**\n\t * Total length of all attribution keys in this collection.\n\t */\n\treadonly length: number;\n\n\treadonly channelNames: Iterable<string>;\n\n\t/**\n\t * Retrieve all key/offset pairs stored on this segment. Entries should be ordered by offset, such that\n\t * the `i`th result's attribution key applies to offsets in the open range between the `i`th offset and the\n\t * `i+1`th offset.\n\t * The last entry's key applies to the open interval from the last entry's offset to this collection's length.\n\t * @internal\n\t */\n\tgetAll(): IAttributionCollectionSpec<T>;\n\n\t/** @internal */\n\tsplitAt(pos: number): IAttributionCollection<T>;\n\n\t/** @internal */\n\tappend(other: IAttributionCollection<T>): void;\n\n\t/** @internal */\n\tclone(): IAttributionCollection<T>;\n\n\t/**\n\t * Updates this collection with new attribution data.\n\t * @param name - Name of the channel that requires an update. Undefined signifies the root channel.\n\t * Updates apply only to the individual channel (i.e. if an attribution policy needs to update the root\n\t * channel and 4 other channels, it should call `.update` 5 times).\n\t * @param channel - Updated collection for that channel.\n\t * @internal\n\t */\n\tupdate(name: string | undefined, channel: IAttributionCollection<T>);\n}\n\n// note: treats null and undefined as equivalent\nexport function areEqualAttributionKeys(\n\ta: AttributionKey | null | undefined,\n\tb: AttributionKey | null | undefined,\n): boolean {\n\tif (!a && !b) {\n\t\treturn true;\n\t}\n\n\tif (!a || !b) {\n\t\treturn false;\n\t}\n\n\tif (a.type !== b.type) {\n\t\treturn false;\n\t}\n\n\t// Note: TS can't narrow the type of b inside this switch statement, hence the need for casting.\n\tswitch (a.type) {\n\t\tcase \"op\":\n\t\t\treturn a.seq === (b as OpAttributionKey).seq;\n\t\tcase \"detached\":\n\t\t\treturn a.id === (b as DetachedAttributionKey).id;\n\t\tcase \"local\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\tunreachableCase(a, \"Unhandled AttributionKey type\");\n\t}\n}\n\nexport class AttributionCollection implements IAttributionCollection<AttributionKey> {\n\tprivate offsets: number[] = [];\n\tprivate keys: (AttributionKey | null)[] = [];\n\n\tprivate channels?: { [name: string]: AttributionCollection };\n\n\tprivate get channelEntries(): [string, AttributionCollection][] {\n\t\treturn Object.entries(this.channels ?? {});\n\t}\n\n\tpublic constructor(private _length: number, baseEntry?: AttributionKey | null) {\n\t\tif (baseEntry !== undefined) {\n\t\t\tthis.offsets.push(0);\n\t\t\tthis.keys.push(baseEntry);\n\t\t}\n\t}\n\n\tpublic get channelNames(): string[] {\n\t\treturn Object.keys(this.channels ?? {});\n\t}\n\n\tpublic getAtOffset(offset: number): AttributionKey;\n\tpublic getAtOffset(offset: number, channel: string): AttributionKey | undefined;\n\tpublic getAtOffset(offset: number, channel?: string): AttributionKey | undefined {\n\t\tif (channel !== undefined) {\n\t\t\tconst subCollection = this.channels?.[channel];\n\t\t\treturn subCollection?.getAtOffset(offset);\n\t\t}\n\t\tassert(offset >= 0 && offset < this._length, 0x443 /* Requested offset should be valid */);\n\t\treturn this.get(this.findIndex(offset));\n\t}\n\n\tprivate findIndex(offset: number): number {\n\t\t// Note: maximum length here is 256 for text segments. Perf testing shows that linear scan beats binary search\n\t\t// for attribution collections with under ~64 entries, and even at maximum size (which would require a maximum\n\t\t// length segment with every offset having different attribution), getAtOffset is on the order of 100ns.\n\t\tlet i = 0;\n\t\twhile (i < this.offsets.length && offset > this.offsets[i]) {\n\t\t\ti++;\n\t\t}\n\t\treturn this.offsets[i] === offset ? i : i - 1;\n\t}\n\n\tprivate get(index: number): AttributionKey | undefined {\n\t\tconst key = this.keys[index];\n\t\treturn key !== null ? key : undefined;\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._length;\n\t}\n\n\t/**\n\t * Splits this attribution collection into two with entries for [0, pos) and [pos, length).\n\t */\n\tpublic splitAt(pos: number): AttributionCollection {\n\t\tconst splitIndex = this.findIndex(pos);\n\t\tconst splitCollection = new AttributionCollection(this.length - pos);\n\t\tfor (let i = splitIndex; i < this.keys.length; i++) {\n\t\t\tsplitCollection.offsets.push(Math.max(this.offsets[i] - pos, 0));\n\t\t\tsplitCollection.keys.push(this.keys[i]);\n\t\t}\n\n\t\tif (this.channels) {\n\t\t\tsplitCollection.channels = {};\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tsplitCollection.channels[key] = collection.splitAt(pos);\n\t\t\t}\n\t\t}\n\n\t\tconst spliceIndex = this.offsets[splitIndex] === pos ? splitIndex : splitIndex + 1;\n\t\tthis.keys.splice(spliceIndex);\n\t\tthis.offsets.splice(spliceIndex);\n\t\tthis._length = pos;\n\t\treturn splitCollection;\n\t}\n\n\tpublic append(other: AttributionCollection): void {\n\t\tconst lastEntry = this.keys[this.keys.length - 1];\n\t\tfor (let i = 0; i < other.keys.length; i++) {\n\t\t\tif (i !== 0 || !areEqualAttributionKeys(lastEntry, other.keys[i])) {\n\t\t\t\tthis.offsets.push(other.offsets[i] + this.length);\n\t\t\t\tthis.keys.push(other.keys[i]);\n\t\t\t}\n\t\t}\n\n\t\tif (other.channels !== undefined || this.channels !== undefined) {\n\t\t\tthis.channels ??= {};\n\t\t\tfor (const [key, collection] of other.channelEntries) {\n\t\t\t\tconst thisCollection = (this.channels[key] ??= new AttributionCollection(\n\t\t\t\t\tthis.length,\n\t\t\t\t\tnull,\n\t\t\t\t));\n\t\t\t\tthisCollection.append(collection);\n\t\t\t}\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tif (other.channels?.[key] === undefined) {\n\t\t\t\t\tcollection.append(new AttributionCollection(other.length, null));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis._length += other.length;\n\t}\n\n\tpublic getAll(): IAttributionCollectionSpec<AttributionKey> {\n\t\tconst root: IAttributionCollectionSpec<AttributionKey>[\"root\"] = new Array(\n\t\t\tthis.keys.length,\n\t\t);\n\t\tfor (let i = 0; i < this.keys.length; i++) {\n\t\t\troot[i] = { offset: this.offsets[i], key: this.keys[i] };\n\t\t}\n\t\tconst result: IAttributionCollectionSpec<AttributionKey> = {\n\t\t\troot,\n\t\t\tlength: this.length,\n\t\t};\n\t\tif (this.channels !== undefined) {\n\t\t\tresult.channels = {};\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tresult.channels[key] = collection.getAll().root;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic clone(): AttributionCollection {\n\t\tconst copy = new AttributionCollection(this.length);\n\t\tcopy.keys = this.keys.slice();\n\t\tcopy.offsets = this.offsets.slice();\n\t\tif (this.channels !== undefined) {\n\t\t\tconst channelsCopy = {};\n\t\t\tfor (const [key, collection] of this.channelEntries) {\n\t\t\t\tchannelsCopy[key] = collection.clone();\n\t\t\t}\n\t\t\tcopy.channels = channelsCopy;\n\t\t}\n\t\treturn copy;\n\t}\n\n\tpublic update(name: string | undefined, channel: AttributionCollection) {\n\t\tassert(\n\t\t\tchannel.length === this.length,\n\t\t\t0x5c0 /* AttributionCollection channel update should have consistent segment length */,\n\t\t);\n\t\tif (name === undefined) {\n\t\t\tthis.offsets = [...channel.offsets];\n\t\t\tthis.keys = [...channel.keys];\n\t\t} else {\n\t\t\tthis.channels ??= {};\n\t\t\tif (this.channels[name] !== undefined) {\n\t\t\t\tthis.channels[name].update(undefined, channel);\n\t\t\t} else {\n\t\t\t\tthis.channels[name] = channel;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Rehydrates attribution information from its serialized form into the provided iterable of consecutive segments.\n\t */\n\tpublic static populateAttributionCollections(\n\t\tsegments: ISegment[],\n\t\tsummary: SerializedAttributionCollection,\n\t): void {\n\t\tconst { channels } = summary;\n\t\tassert(\n\t\t\tsummary.seqs.length === summary.posBreakpoints.length,\n\t\t\t0x445 /* Invalid attribution summary blob provided */,\n\t\t);\n\n\t\tconst extractOntoSegments = (\n\t\t\t{ seqs, posBreakpoints }: SequenceOffsets,\n\t\t\tassignToSegment: (collection: AttributionCollection, segment: ISegment) => void,\n\t\t) => {\n\t\t\tlet curIndex = 0;\n\t\t\tlet cumulativeSegPos = 0;\n\n\t\t\tfor (const segment of segments) {\n\t\t\t\tconst attribution = new AttributionCollection(segment.cachedLength);\n\t\t\t\tconst pushEntry = (offset: number, seq: AttributionKey | number | null) => {\n\t\t\t\t\tattribution.offsets.push(offset);\n\t\t\t\t\tattribution.keys.push(\n\t\t\t\t\t\tseq === null ? null : typeof seq === \"object\" ? seq : { type: \"op\", seq },\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tif (posBreakpoints[curIndex] > cumulativeSegPos) {\n\t\t\t\t\tcurIndex--;\n\t\t\t\t}\n\n\t\t\t\twhile (posBreakpoints[curIndex] < cumulativeSegPos + segment.cachedLength) {\n\t\t\t\t\tconst nextOffset = Math.max(posBreakpoints[curIndex] - cumulativeSegPos, 0);\n\t\t\t\t\tpushEntry(nextOffset, seqs[curIndex]);\n\t\t\t\t\tcurIndex++;\n\t\t\t\t}\n\n\t\t\t\tif (attribution.offsets.length === 0) {\n\t\t\t\t\tpushEntry(0, seqs[curIndex - 1]);\n\t\t\t\t}\n\n\t\t\t\tassignToSegment(attribution, segment);\n\t\t\t\tcumulativeSegPos += segment.cachedLength;\n\t\t\t}\n\t\t};\n\n\t\textractOntoSegments(summary, (collection, segment) => {\n\t\t\tsegment.attribution = collection;\n\t\t});\n\t\tif (channels) {\n\t\t\tfor (const [name, collectionSpec] of Object.entries(channels)) {\n\t\t\t\textractOntoSegments(collectionSpec, (collection, segment) => {\n\t\t\t\t\t// Cast is valid as we just assigned this field above\n\t\t\t\t\t((segment.attribution as AttributionCollection).channels ??= {})[name] =\n\t\t\t\t\t\tcollection;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Condenses attribution information on consecutive segments into a `SerializedAttributionCollection`\n\t *\n\t * Note: this operates on segments rather than attribution collections directly so that it can handle cases\n\t * where only some segments have attribution defined.\n\t */\n\tpublic static serializeAttributionCollections(\n\t\tsegments: Iterable<{\n\t\t\tattribution?: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}>,\n\t): SerializedAttributionCollection {\n\t\tconst allCollectionSpecs: IAttributionCollectionSpec<AttributionKey>[] = [];\n\n\t\tconst allChannelNames = new Set<string>();\n\t\tfor (const segment of segments) {\n\t\t\tconst collection =\n\t\t\t\tsegment.attribution ?? new AttributionCollection(segment.cachedLength, null);\n\t\t\tconst spec = collection.getAll();\n\t\t\tallCollectionSpecs.push(spec);\n\t\t\tif (spec.channels) {\n\t\t\t\tfor (const name of Object.keys(spec.channels)) {\n\t\t\t\t\tallChannelNames.add(name);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst extractSequenceOffsets = (\n\t\t\tgetSpecEntries: (\n\t\t\t\tspec: IAttributionCollectionSpec<AttributionKey>,\n\t\t\t) => Iterable<{ offset: number; key: AttributionKey | null }>,\n\t\t): SerializedAttributionCollection => {\n\t\t\tconst posBreakpoints: number[] = [];\n\t\t\tconst seqs: (number | AttributionKey | null)[] = [];\n\t\t\tlet mostRecentAttributionKey: AttributionKey | null | undefined;\n\t\t\tlet cumulativePos = 0;\n\n\t\t\tfor (const spec of allCollectionSpecs) {\n\t\t\t\tfor (const { offset, key } of getSpecEntries(spec)) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tkey?.type !== \"local\",\n\t\t\t\t\t\t0x5c1 /* local attribution keys should never be put in summaries */,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tmostRecentAttributionKey === undefined ||\n\t\t\t\t\t\t!areEqualAttributionKeys(key, mostRecentAttributionKey)\n\t\t\t\t\t) {\n\t\t\t\t\t\tposBreakpoints.push(offset + cumulativePos);\n\t\t\t\t\t\tseqs.push(!key ? null : key.type === \"op\" ? key.seq : key);\n\t\t\t\t\t}\n\t\t\t\t\tmostRecentAttributionKey = key;\n\t\t\t\t}\n\n\t\t\t\tcumulativePos += spec.length;\n\t\t\t}\n\n\t\t\treturn { seqs, posBreakpoints, length: cumulativePos };\n\t\t};\n\n\t\tconst blobContents = extractSequenceOffsets((spec) => spec.root);\n\t\tif (allChannelNames.size > 0) {\n\t\t\tconst channels: { [name: string]: SequenceOffsets } = {};\n\t\t\tfor (const name of allChannelNames) {\n\t\t\t\tconst { posBreakpoints, seqs } = extractSequenceOffsets(\n\t\t\t\t\t(spec) => spec.channels?.[name] ?? [{ offset: 0, key: null }],\n\t\t\t\t);\n\t\t\t\tchannels[name] = { posBreakpoints, seqs };\n\t\t\t}\n\t\t\tblobContents.channels = channels;\n\t\t}\n\n\t\treturn blobContents;\n\t}\n}\n"]}
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { AttributionPolicy } from "./mergeTree";
|
|
6
6
|
/**
|
|
7
|
+
* @returns An {@link AttributionPolicy} which tracks only insertion of content.
|
|
8
|
+
*
|
|
7
9
|
* @alpha
|
|
8
|
-
* @returns - An {@link AttributionPolicy} which tracks only insertion of content.
|
|
9
10
|
*/
|
|
10
11
|
export declare function createInsertOnlyAttributionPolicy(): AttributionPolicy;
|
|
11
12
|
/**
|
|
12
13
|
* @param propNames - List of property names for which attribution should be tracked.
|
|
13
|
-
* @returns
|
|
14
|
+
* @returns A policy which only attributes annotation of the properties specified.
|
|
14
15
|
* Keys for each property are stored under attribution channels of the same name--see example below.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributionPolicy.d.ts","sourceRoot":"","sources":["../src/attributionPolicy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAsLhD
|
|
1
|
+
{"version":3,"file":"attributionPolicy.d.ts","sourceRoot":"","sources":["../src/attributionPolicy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAsLhD;;;;GAIG;AACH,wBAAgB,iCAAiC,IAAI,iBAAiB,CAOrE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,8CAA8C,CAC7D,GAAG,SAAS,EAAE,MAAM,EAAE,GACpB,MAAM,iBAAiB,CAQzB;AAED;;;;;GAKG;AACH,wBAAgB,0DAA0D,CACzE,GAAG,SAAS,EAAE,MAAM,EAAE,GACpB,MAAM,iBAAiB,CASzB"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.createPropertyTrackingAndInsertionAttributionPolicyFactory = exports.createPropertyTrackingAttributionPolicyFactory = exports.createInsertOnlyAttributionPolicy = void 0;
|
|
8
|
-
const
|
|
8
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
9
|
const mergeTreeDeltaCallback_1 = require("./mergeTreeDeltaCallback");
|
|
10
10
|
const ops_1 = require("./ops");
|
|
11
11
|
const attributionCollection_1 = require("./attributionCollection");
|
|
@@ -13,7 +13,7 @@ function createAttributionPolicyFromCallbacks({ delta, maintenance, }) {
|
|
|
13
13
|
let unsubscribe;
|
|
14
14
|
return {
|
|
15
15
|
attach: (client) => {
|
|
16
|
-
(0,
|
|
16
|
+
(0, core_utils_1.assert)(unsubscribe === undefined, 0x557 /* cannot attach to multiple clients at once */);
|
|
17
17
|
const deltaSubscribed = (opArgs, deltaArgs) => delta(opArgs, deltaArgs, client);
|
|
18
18
|
const maintenanceSubscribed = (args, opArgs) => maintenance(args, opArgs, client);
|
|
19
19
|
client.on("delta", deltaSubscribed);
|
|
@@ -24,7 +24,7 @@ function createAttributionPolicyFromCallbacks({ delta, maintenance, }) {
|
|
|
24
24
|
};
|
|
25
25
|
},
|
|
26
26
|
detach: () => {
|
|
27
|
-
unsubscribe
|
|
27
|
+
unsubscribe?.();
|
|
28
28
|
unsubscribe = undefined;
|
|
29
29
|
},
|
|
30
30
|
get isAttached() {
|
|
@@ -51,10 +51,9 @@ const getAttributionKey = (client, msg) => {
|
|
|
51
51
|
return collabWindow.collaborating ? { type: "local" } : { type: "detached", id: 0 };
|
|
52
52
|
};
|
|
53
53
|
const attributeInsertionOnSegments = (deltaSegments, key) => {
|
|
54
|
-
var _a;
|
|
55
54
|
for (const { segment } of deltaSegments) {
|
|
56
55
|
if (segment.seq !== undefined) {
|
|
57
|
-
|
|
56
|
+
segment.attribution?.update(undefined, new attributionCollection_1.AttributionCollection(segment.cachedLength, key));
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
};
|
|
@@ -66,7 +65,7 @@ const insertOnlyAttributionPolicyCallbacks = {
|
|
|
66
65
|
},
|
|
67
66
|
maintenance: ({ deltaSegments, operation }, opArgs, client) => {
|
|
68
67
|
if (operation === mergeTreeDeltaCallback_1.MergeTreeMaintenanceType.ACKNOWLEDGED &&
|
|
69
|
-
|
|
68
|
+
opArgs?.op.type === ops_1.MergeTreeDeltaType.INSERT) {
|
|
70
69
|
attributeInsertionOnSegments(deltaSegments, getAttributionKey(client, opArgs.sequencedMessage));
|
|
71
70
|
}
|
|
72
71
|
},
|
|
@@ -74,11 +73,10 @@ const insertOnlyAttributionPolicyCallbacks = {
|
|
|
74
73
|
function createPropertyTrackingMergeTreeCallbacks(...propNames) {
|
|
75
74
|
const toTrack = propNames.map((entry) => ({ propName: entry, channelName: entry }));
|
|
76
75
|
const attributeAnnotateOnSegments = (deltaSegments, { op, sequencedMessage }, key) => {
|
|
77
|
-
var _a, _b, _c;
|
|
78
76
|
for (const { segment } of deltaSegments) {
|
|
79
77
|
for (const { propName, channelName } of toTrack) {
|
|
80
78
|
const shouldAttributeInsert = op.type === ops_1.MergeTreeDeltaType.INSERT &&
|
|
81
|
-
|
|
79
|
+
segment.properties?.[propName] !== undefined;
|
|
82
80
|
const isLocal = sequencedMessage === undefined;
|
|
83
81
|
const shouldAttributeAnnotate = op.type === ops_1.MergeTreeDeltaType.ANNOTATE &&
|
|
84
82
|
// Only attribute annotations which change the tracked property
|
|
@@ -86,9 +84,9 @@ function createPropertyTrackingMergeTreeCallbacks(...propNames) {
|
|
|
86
84
|
// Local changes to the tracked property always take effect
|
|
87
85
|
(isLocal ||
|
|
88
86
|
// Acked changes only take effect if there isn't a pending local change
|
|
89
|
-
(!isLocal && !
|
|
87
|
+
(!isLocal && !segment.propertyManager?.hasPendingProperty(propName)));
|
|
90
88
|
if (shouldAttributeInsert || shouldAttributeAnnotate) {
|
|
91
|
-
|
|
89
|
+
segment.attribution?.update(channelName, new attributionCollection_1.AttributionCollection(segment.cachedLength, key));
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}
|
|
@@ -114,8 +112,9 @@ function combineMergeTreeCallbacks(callbacks) {
|
|
|
114
112
|
};
|
|
115
113
|
}
|
|
116
114
|
/**
|
|
115
|
+
* @returns An {@link AttributionPolicy} which tracks only insertion of content.
|
|
116
|
+
*
|
|
117
117
|
* @alpha
|
|
118
|
-
* @returns - An {@link AttributionPolicy} which tracks only insertion of content.
|
|
119
118
|
*/
|
|
120
119
|
function createInsertOnlyAttributionPolicy() {
|
|
121
120
|
return createAttributionPolicyFromCallbacks(combineMergeTreeCallbacks([
|
|
@@ -126,7 +125,7 @@ function createInsertOnlyAttributionPolicy() {
|
|
|
126
125
|
exports.createInsertOnlyAttributionPolicy = createInsertOnlyAttributionPolicy;
|
|
127
126
|
/**
|
|
128
127
|
* @param propNames - List of property names for which attribution should be tracked.
|
|
129
|
-
* @returns
|
|
128
|
+
* @returns A policy which only attributes annotation of the properties specified.
|
|
130
129
|
* Keys for each property are stored under attribution channels of the same name--see example below.
|
|
131
130
|
*
|
|
132
131
|
* @example
|