@fluidframework/merge-tree 2.70.0-361092 → 2.70.0-361788

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.
@@ -81,7 +81,7 @@ export interface IMergeTreeSegmentDelta {
81
81
  /**
82
82
  * A property set containing changes to properties on this segment.
83
83
  *
84
- * @remarks - Deleting a property is represented using `null` as the value.
84
+ * @remarks Deleting a property is represented using `null` as the value.
85
85
  * @example
86
86
  *
87
87
  * An annotation change which deleted the property "foo" and set "bar" to 5 would be represented as:
@@ -101,7 +101,7 @@ export interface IMergeTreeDeltaOpArgs {
101
101
  /**
102
102
  * The {@link IMergeTreeOp} corresponding to the delta.
103
103
  *
104
- * @remarks - This is useful for determining the type of change (see {@link (MergeTreeDeltaType:type)}).
104
+ * @remarks This is useful for determining the type of change (see {@link (MergeTreeDeltaType:type)}).
105
105
  */
106
106
  readonly op: IMergeTreeOp;
107
107
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeDeltaCallback.js","sourceRoot":"","sources":["../src/mergeTreeDeltaCallback.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAkBH;;;;;;GAMG;AACU,QAAA,wBAAwB,GAAG;IACvC;;;;;;OAMG;IACH,MAAM,EAAE,CAAC,CAAC;IACV;;;OAGG;IACH,KAAK,EAAE,CAAC,CAAC;IACT;;;;;OAKG;IACH,MAAM,EAAE,CAAC,CAAC;IACV;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC;CACP,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\n\nimport type { ISegment } from \"./mergeTreeNodes.js\";\n// eslint-disable-next-line import/no-deprecated\nimport type { IMergeTreeGroupMsg, IMergeTreeOp, MergeTreeDeltaType } from \"./ops.js\";\nimport type { PropertySet } from \"./properties.js\";\n\n/**\n * @legacy @beta\n */\nexport type MergeTreeDeltaOperationType =\n\t| typeof MergeTreeDeltaType.ANNOTATE\n\t| typeof MergeTreeDeltaType.INSERT\n\t| typeof MergeTreeDeltaType.REMOVE\n\t| typeof MergeTreeDeltaType.OBLITERATE;\n\n/**\n * Enum-like constant defining the types of \"maintenance\" events on a merge tree.\n * Maintenance events correspond to structural segment changes or acks of pending segments.\n *\n * Note: these values are assigned negative integers to avoid clashing with `MergeTreeDeltaType`.\n * @legacy @beta\n */\nexport const MergeTreeMaintenanceType = {\n\t/**\n\t * Notification that a segment \"append\" has occurred, i.e. two adjacent segments have been merged.\n\t * BEWARE: `deltaSegments` on the corresponding event will contain both the merged segment and the latter\n\t * segment, pre-merge.\n\t * For example, if the merge tree originally had two adjacent segments [A][B] and called A.append(B) to get\n\t * segment [AB], `deltaSegments` would contain [AB] and [B].\n\t */\n\tAPPEND: -1,\n\t/**\n\t * Notification that a segment has been split in two.\n\t * `deltaSegments` on the corresponding event will contain the resulting two segments.\n\t */\n\tSPLIT: -2,\n\t/**\n\t * Notification that a segment has been unlinked (i.e. removed) from the MergeTree.\n\t * This occurs on leaf segments during Zamboni when the segment's tracking collection is empty\n\t * (e.g., not being tracked for undo/redo).\n\t * It also occurs on internal merge tree segments when re-packing children to maintain tree balancing invariants.\n\t */\n\tUNLINK: -3,\n\t/**\n\t * Notification that a local change has been acknowledged by the server.\n\t * This means that it has made the round trip to the server and has had a sequence number assigned.\n\t */\n\tACKNOWLEDGED: -4,\n} as const;\n/**\n * @legacy @beta\n */\nexport type MergeTreeMaintenanceType =\n\t(typeof MergeTreeMaintenanceType)[keyof typeof MergeTreeMaintenanceType];\n\n/**\n * @legacy @beta\n */\nexport type MergeTreeDeltaOperationTypes =\n\t| MergeTreeDeltaOperationType\n\t| MergeTreeMaintenanceType;\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeDeltaCallbackArgs<\n\tTOperationType extends MergeTreeDeltaOperationTypes = MergeTreeDeltaOperationType,\n> {\n\t/**\n\t * The type of operation that affected segments in the merge-tree.\n\t * The affected segments can be accessed via {@link IMergeTreeDeltaCallbackArgs.deltaSegments|deltaSegments}.\n\t *\n\t * See {@link MergeTreeDeltaOperationType} and {@link (MergeTreeMaintenanceType:type)} for possible values.\n\t */\n\treadonly operation: TOperationType;\n\n\t/**\n\t * A list of deltas describing actions taken on segments.\n\t *\n\t * Deltas are not guaranteed to be in any particular order.\n\t */\n\treadonly deltaSegments: IMergeTreeSegmentDelta[];\n}\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeSegmentDelta {\n\t/**\n\t * The segment this delta affected.\n\t */\n\tsegment: ISegment;\n\n\t/**\n\t * A property set containing changes to properties on this segment.\n\t *\n\t * @remarks - Deleting a property is represented using `null` as the value.\n\t * @example\n\t *\n\t * An annotation change which deleted the property \"foo\" and set \"bar\" to 5 would be represented as:\n\t * `{ foo: null, bar: 5 }`.\n\t */\n\tpropertyDeltas?: PropertySet;\n}\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeDeltaOpArgs {\n\t/**\n\t * The group op which contains the operation\n\t * if there operation is part of a group op.\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\treadonly groupOp?: IMergeTreeGroupMsg;\n\n\t/**\n\t * The {@link IMergeTreeOp} corresponding to the delta.\n\t *\n\t * @remarks - This is useful for determining the type of change (see {@link (MergeTreeDeltaType:type)}).\n\t */\n\treadonly op: IMergeTreeOp;\n\n\t/**\n\t * The {@link @fluidframework/protocol-definitions#ISequencedDocumentMessage} corresponding to this acknowledged change.\n\t *\n\t * This field is omitted for deltas corresponding to unacknowledged changes.\n\t */\n\treadonly sequencedMessage?: ISequencedDocumentMessage;\n\n\t/**\n\t * Set to true if this delta is being performed as part of a rollback of unsent local changes.\n\t */\n\treadonly rollback?: true;\n}\n\n/**\n * @internal\n */\nexport type MergeTreeDeltaCallback = (\n\topArgs: IMergeTreeDeltaOpArgs,\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n) => void;\n\n/**\n * @legacy @beta\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-empty-interface\nexport interface IMergeTreeMaintenanceCallbackArgs\n\textends IMergeTreeDeltaCallbackArgs<MergeTreeMaintenanceType> {}\n\n/**\n * @internal\n */\nexport type MergeTreeMaintenanceCallback = (\n\tMaintenanceArgs: IMergeTreeMaintenanceCallbackArgs,\n\topArgs: IMergeTreeDeltaOpArgs | undefined,\n) => void;\n"]}
1
+ {"version":3,"file":"mergeTreeDeltaCallback.js","sourceRoot":"","sources":["../src/mergeTreeDeltaCallback.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAkBH;;;;;;GAMG;AACU,QAAA,wBAAwB,GAAG;IACvC;;;;;;OAMG;IACH,MAAM,EAAE,CAAC,CAAC;IACV;;;OAGG;IACH,KAAK,EAAE,CAAC,CAAC;IACT;;;;;OAKG;IACH,MAAM,EAAE,CAAC,CAAC;IACV;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC;CACP,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\n\nimport type { ISegment } from \"./mergeTreeNodes.js\";\n// eslint-disable-next-line import/no-deprecated\nimport type { IMergeTreeGroupMsg, IMergeTreeOp, MergeTreeDeltaType } from \"./ops.js\";\nimport type { PropertySet } from \"./properties.js\";\n\n/**\n * @legacy @beta\n */\nexport type MergeTreeDeltaOperationType =\n\t| typeof MergeTreeDeltaType.ANNOTATE\n\t| typeof MergeTreeDeltaType.INSERT\n\t| typeof MergeTreeDeltaType.REMOVE\n\t| typeof MergeTreeDeltaType.OBLITERATE;\n\n/**\n * Enum-like constant defining the types of \"maintenance\" events on a merge tree.\n * Maintenance events correspond to structural segment changes or acks of pending segments.\n *\n * Note: these values are assigned negative integers to avoid clashing with `MergeTreeDeltaType`.\n * @legacy @beta\n */\nexport const MergeTreeMaintenanceType = {\n\t/**\n\t * Notification that a segment \"append\" has occurred, i.e. two adjacent segments have been merged.\n\t * BEWARE: `deltaSegments` on the corresponding event will contain both the merged segment and the latter\n\t * segment, pre-merge.\n\t * For example, if the merge tree originally had two adjacent segments [A][B] and called A.append(B) to get\n\t * segment [AB], `deltaSegments` would contain [AB] and [B].\n\t */\n\tAPPEND: -1,\n\t/**\n\t * Notification that a segment has been split in two.\n\t * `deltaSegments` on the corresponding event will contain the resulting two segments.\n\t */\n\tSPLIT: -2,\n\t/**\n\t * Notification that a segment has been unlinked (i.e. removed) from the MergeTree.\n\t * This occurs on leaf segments during Zamboni when the segment's tracking collection is empty\n\t * (e.g., not being tracked for undo/redo).\n\t * It also occurs on internal merge tree segments when re-packing children to maintain tree balancing invariants.\n\t */\n\tUNLINK: -3,\n\t/**\n\t * Notification that a local change has been acknowledged by the server.\n\t * This means that it has made the round trip to the server and has had a sequence number assigned.\n\t */\n\tACKNOWLEDGED: -4,\n} as const;\n/**\n * @legacy @beta\n */\nexport type MergeTreeMaintenanceType =\n\t(typeof MergeTreeMaintenanceType)[keyof typeof MergeTreeMaintenanceType];\n\n/**\n * @legacy @beta\n */\nexport type MergeTreeDeltaOperationTypes =\n\t| MergeTreeDeltaOperationType\n\t| MergeTreeMaintenanceType;\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeDeltaCallbackArgs<\n\tTOperationType extends MergeTreeDeltaOperationTypes = MergeTreeDeltaOperationType,\n> {\n\t/**\n\t * The type of operation that affected segments in the merge-tree.\n\t * The affected segments can be accessed via {@link IMergeTreeDeltaCallbackArgs.deltaSegments|deltaSegments}.\n\t *\n\t * See {@link MergeTreeDeltaOperationType} and {@link (MergeTreeMaintenanceType:type)} for possible values.\n\t */\n\treadonly operation: TOperationType;\n\n\t/**\n\t * A list of deltas describing actions taken on segments.\n\t *\n\t * Deltas are not guaranteed to be in any particular order.\n\t */\n\treadonly deltaSegments: IMergeTreeSegmentDelta[];\n}\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeSegmentDelta {\n\t/**\n\t * The segment this delta affected.\n\t */\n\tsegment: ISegment;\n\n\t/**\n\t * A property set containing changes to properties on this segment.\n\t *\n\t * @remarks Deleting a property is represented using `null` as the value.\n\t * @example\n\t *\n\t * An annotation change which deleted the property \"foo\" and set \"bar\" to 5 would be represented as:\n\t * `{ foo: null, bar: 5 }`.\n\t */\n\tpropertyDeltas?: PropertySet;\n}\n\n/**\n * @legacy @beta\n */\nexport interface IMergeTreeDeltaOpArgs {\n\t/**\n\t * The group op which contains the operation\n\t * if there operation is part of a group op.\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\treadonly groupOp?: IMergeTreeGroupMsg;\n\n\t/**\n\t * The {@link IMergeTreeOp} corresponding to the delta.\n\t *\n\t * @remarks This is useful for determining the type of change (see {@link (MergeTreeDeltaType:type)}).\n\t */\n\treadonly op: IMergeTreeOp;\n\n\t/**\n\t * The {@link @fluidframework/protocol-definitions#ISequencedDocumentMessage} corresponding to this acknowledged change.\n\t *\n\t * This field is omitted for deltas corresponding to unacknowledged changes.\n\t */\n\treadonly sequencedMessage?: ISequencedDocumentMessage;\n\n\t/**\n\t * Set to true if this delta is being performed as part of a rollback of unsent local changes.\n\t */\n\treadonly rollback?: true;\n}\n\n/**\n * @internal\n */\nexport type MergeTreeDeltaCallback = (\n\topArgs: IMergeTreeDeltaOpArgs,\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n) => void;\n\n/**\n * @legacy @beta\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-empty-interface\nexport interface IMergeTreeMaintenanceCallbackArgs\n\textends IMergeTreeDeltaCallbackArgs<MergeTreeMaintenanceType> {}\n\n/**\n * @internal\n */\nexport type MergeTreeMaintenanceCallback = (\n\tMaintenanceArgs: IMergeTreeMaintenanceCallbackArgs,\n\topArgs: IMergeTreeDeltaOpArgs | undefined,\n) => void;\n"]}
@@ -340,7 +340,7 @@ export declare class CollaborationWindow {
340
340
  * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
341
341
  * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
342
342
  *
343
- * @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
343
+ * @remarks This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
344
344
  * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
345
345
  *
346
346
  * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
@@ -318,7 +318,7 @@ class CollaborationWindow {
318
318
  * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
319
319
  * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
320
320
  *
321
- * @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
321
+ * @remarks This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
322
322
  * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
323
323
  *
324
324
  * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,iDAKwB;AACxB,2DAA4F;AAC5F,iEAAsF;AAEtF,6CAA0D;AAE1D,qDAA+F;AAC/F,mDAAmF;AAGnF,uDAY2B;AAyD3B;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAA+B,EAAE,CAClF,IAAA,4BAAU,EAAC,WAAW,CAAC,IAAI,IAAA,iCAAW,EAAC,WAAW,CAAC,CAAC;AADxC,QAAA,aAAa,iBAC2B;AAErD;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAA4B,EAAE,CAC/E,IAAA,qBAAa,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAA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BAAwD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { AttributionKey } from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { IAttributionCollection } from \"./attributionCollection.js\";\nimport {\n\tLocalClientId,\n\tNonCollabClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\nimport { LocalReferenceCollection, type LocalReferencePosition } from \"./localReference.js\";\nimport { TrackingGroupCollection, type ITrackingGroup } from \"./mergeTreeTracking.js\";\nimport type { IJSONSegment, IMarkerDef, ReferenceType } from \"./ops.js\";\nimport { computeHierarchicalOrdinal } from \"./ordinal.js\";\nimport type { PartialSequenceLengths } from \"./partialLengths.js\";\nimport { LocalDefaultPerspective, PriorPerspective, type Perspective } from \"./perspective.js\";\nimport { type PropertySet, clone, createMap, type MapLike } from \"./properties.js\";\nimport type { ReferencePosition } from \"./referencePositions.js\";\nimport type { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\thasProp,\n\tisInserted,\n\tisMergeNodeInfo as isMergeNode,\n\tisRemoved,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype IMergeNodeInfo,\n\ttype IHasRemovalInfo,\n\ttype SegmentWithInfo,\n\ttype ISegmentInsideObliterateInfo,\n\tisInsideObliterate,\n} from \"./segmentInfos.js\";\nimport type { PropertiesManager } from \"./segmentPropertiesManager.js\";\nimport type { Side } from \"./sequencePlace.js\";\nimport type { OperationStamp, SliceRemoveOperationStamp } from \"./stamps.js\";\n\n/**\n * This interface exposes internal things to dds that leverage merge tree,\n * like sequence and matrix.\n *\n * We use tiered interface to control visibility of segment properties.\n * This sits between ISegment and ISegmentPrivate. It should only expose\n * things tagged internal.\n *\n * Everything added here beyond ISegment should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * @internal\n */\nexport interface ISegmentInternal extends ISegment {\n\tlocalRefs?: LocalReferenceCollection;\n\t/**\n\t * Whether or not this segment is a special segment denoting the start or\n\t * end of the tree\n\t *\n\t * Endpoint segments are imaginary segments positioned immediately before or\n\t * after the tree. These segments cannot be referenced by regular operations\n\t * and exist primarily as a bucket for local references to slide onto during\n\t * deletion of regular segments.\n\t */\n\treadonly endpointType?: \"start\" | \"end\";\n}\n\n/**\n * We use tiered interface to control visibility of segment properties.\n * This is the lowest interface and is not exported, it site below ISegment and ISegmentInternal.\n * It should only expose unexported things.\n *\n * Everything added here beyond ISegmentInternal should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * someday we may split tree leaves from segments, but for now they are the same\n * this is just a convenience type that makes it clear that we need something that is both a segment and a leaf node\n */\nexport interface ISegmentPrivate extends ISegmentInternal {\n\tsegmentGroups?: SegmentGroupCollection;\n\tpropertyManager?: PropertiesManager;\n}\n/**\n * Segment leafs are segments that have both IMergeNodeInfo and IHasInsertionInfo. This means they\n * are inserted at a position, and bound via their parent MergeBlock to the merge tree. MergeBlocks'\n * children are either a segment leaf, or another merge block for interior nodes of the tree. When working\n * within the tree it is generally unnecessary to use type coercions methods common to the infos, and segment\n * leafs, as the children of MergeBlocks are already well typed. However, when segments come from outside the\n * merge tree, like via client's public methods, it becomes necessary to use the type coercions methods\n * to ensure the passed in segment objects are correctly bound to the merge tree.\n */\nexport type ISegmentLeaf = SegmentWithInfo<IMergeNodeInfo & IHasInsertionInfo>;\n/**\n * A type-guard which determines if the segment has segment leaf, and\n * returns true if it does, along with applying strong typing.\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment is a segment leaf, otherwise false.\n */\nexport const isSegmentLeaf = (segmentLike: unknown): segmentLike is ISegmentLeaf =>\n\tisInserted(segmentLike) && isMergeNode(segmentLike);\n\n/**\n * Converts a segment-like object to a segment leaf object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The segment leaf if the conversion is possible, otherwise undefined.\n */\nexport const toSegmentLeaf = (segmentLike: unknown): ISegmentLeaf | undefined =>\n\tisSegmentLeaf(segmentLike) ? segmentLike : undefined;\n/**\n * Asserts that the segment is a segment leaf. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment is not a segment leaf.\n */\nexport const assertSegmentLeaf: (segmentLike: unknown) => asserts segmentLike is ISegmentLeaf =\n\t(segmentLike) => assert(isSegmentLeaf(segmentLike), 0xaab /* must be segment leaf */);\n/**\n * This type is used for building MergeBlocks from segments and other MergeBlocks. We need this\n * type as segments may not yet be bound to the tree, so lack merge node info which is required for\n * segment leafs.\n */\nexport type IMergeNodeBuilder = MergeBlock | SegmentWithInfo<IHasInsertionInfo>;\n\n/**\n * This type is used by MergeBlocks to define their children, which are either segments or other\n * MergeBlocks.\n */\nexport type IMergeNode = MergeBlock | ISegmentLeaf;\n\n/**\n * A segment representing a portion of the merge tree.\n * Segments are leaf nodes of the merge tree and contain data.\n * @legacy @beta\n */\nexport interface ISegment {\n\treadonly type: string;\n\n\treadonly trackingCollection: TrackingGroupCollection;\n\n\t/**\n\t * The length of the contents of the node.\n\t */\n\tcachedLength: number;\n\t/**\n\t * Stores attribution keys associated with offsets of this segment.\n\t * This data is only persisted if MergeTree's `attributions.track` flag is set to true.\n\t * Pending segments (i.e. ones that only exist locally and haven't been acked by the server) also have\n\t * `attribution === undefined` until ack.\n\t *\n\t * Keys can be used opaquely with an IAttributor or a container runtime that provides attribution.\n\t * @remarks There are plans to make the shape of the data stored extensible in a couple ways:\n\t *\n\t * 1. Injection of custom attribution information associated with the segment (ex: copy-paste of\n\t * content but keeping the old attribution information).\n\t *\n\t * 2. Storage of multiple \"channels\" of information (ex: track property changes separately from insertion,\n\t * or only attribute certain property modifications, etc.)\n\t */\n\tattribution?: IAttributionCollection<AttributionKey>;\n\n\t/**\n\t * Properties that have been added to this segment via annotation.\n\t */\n\tproperties?: PropertySet;\n\n\tclone(): ISegment;\n\tcanAppend(segment: ISegment): boolean;\n\tappend(segment: ISegment): void;\n\tsplitAt(pos: number): ISegment | undefined;\n\t// Changing this to something other than any would break consumers.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\ttoJSONObject(): any;\n\tisLeaf(): this is ISegment;\n}\n\n/**\n * Determine if a segment has been removed.\n * @legacy @beta\n */\nexport function segmentIsRemoved(segment: ISegment): boolean {\n\treturn isRemoved(segment);\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISegmentAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tsegment: ISegment,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number,\n\t\tend: number,\n\t\taccum: TClientData,\n\t): boolean;\n}\nexport interface ISegmentChanges {\n\tnext?: SegmentWithInfo<IHasInsertionInfo>;\n\treplaceCurrent?: SegmentWithInfo<IHasInsertionInfo>;\n}\n\nexport interface InsertContext {\n\tcandidateSegment?: SegmentWithInfo<IHasInsertionInfo>;\n\tleaf: (segment: ISegmentLeaf | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: MergeBlock) => boolean;\n}\n\nexport interface ObliterateInfo {\n\tstart: LocalReferencePosition;\n\tstartSide: Side;\n\tend: LocalReferencePosition;\n\tendSide: Side;\n\trefSeq: number;\n\tstamp: SliceRemoveOperationStamp;\n\tsegmentGroup: SegmentGroup | undefined;\n\t/**\n\t * Defined only for unacked obliterates.\n\t *\n\t * Contains all segments inserted into the range this obliterate affects where at the time of insertion,\n\t * this obliterate was the newest concurrent obliterate that overlapped the insertion point (this information\n\t * is relevant for the tiebreak policy of allowing last-obliterater to insert).\n\t *\n\t * We need to keep this around for unacked ops because on reconnect, outstanding local obliterates may have set `obliteratePrecedingInsertion`\n\t * (tiebreak) on segments they no longer apply to, since the reissued obliterate may affect a smaller range than the original one when content\n\t * near the obliterate's endpoints was removed by another client between the time of the original obliterate and reissuing.\n\t */\n\ttiebreakTrackingGroup: ITrackingGroup | undefined;\n}\n\nexport interface SegmentGroup {\n\tsegments: ISegmentLeaf[];\n\tpreviousProps?: PropertySet[];\n\tlocalSeq?: number;\n\trefSeq: number;\n\tobliterateInfo?: ObliterateInfo;\n}\n\n/**\n * Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because\n * the MergeTree always inserts first, then checks for overflow and splits if the child count equals\n * `MaxNodesInBlock`. (i.e., `MaxNodesInBlock` contains 1 extra slot for temporary storage to\n * facilitate splits.)\n */\nexport const MaxNodesInBlock = 8;\nexport class MergeBlock implements Partial<IMergeNodeInfo> {\n\tpublic children: IMergeNode[];\n\tpublic needsScour?: boolean;\n\tpublic parent?: MergeBlock;\n\tpublic index: number = 0;\n\tpublic ordinal: string = \"\";\n\tpublic cachedLength: number | undefined = 0;\n\n\t/**\n\t * Maps each tile label in this block to the rightmost (i.e. furthest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic rightmostTiles: Readonly<MapLike<Marker>>;\n\t/**\n\t * Maps each tile label in this block to the leftmost (i.e. nearest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic leftmostTiles: Readonly<MapLike<Marker>>;\n\n\tisLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\n\t/**\n\t * Supports querying the total length of all descendants of this IMergeBlock from the perspective of any\n\t * (clientId, seq) within the collab window.\n\t *\n\t * @remarks This is only optional for implementation reasons (internal nodes can be created/moved without\n\t * immediately initializing the partial lengths). Aside from mid-update on tree operations, these lengths\n\t * objects are always defined.\n\t */\n\tpartialLengths?: PartialSequenceLengths;\n\n\tpublic constructor(public childCount: number) {\n\t\t// Suppression needed due to the way the merge tree children are initialized - we\n\t\t// allocate 8 children blocks, but any unused blocks are not counted in the childCount.\n\t\t// Using Array.from leads to unused children being undefined, which are counted in childCount.\n\t\t// eslint-disable-next-line unicorn/no-new-array\n\t\tthis.children = new Array<IMergeNode>(MaxNodesInBlock);\n\t\tthis.rightmostTiles = createMap<Marker>();\n\t\tthis.leftmostTiles = createMap<Marker>();\n\t}\n\n\tpublic setOrdinal(child: IMergeNode, index: number): void {\n\t\tconst childCount = this.childCount;\n\t\tassert(\n\t\t\tchildCount >= 1 && childCount <= MaxNodesInBlock,\n\t\t\t0x040 /* \"Child count is not within [1,8] range!\" */,\n\t\t);\n\t\tchild.ordinal = computeHierarchicalOrdinal(\n\t\t\tMaxNodesInBlock,\n\t\t\tchildCount,\n\t\t\tthis.ordinal,\n\t\t\tindex === 0 ? undefined : this.children[index - 1]?.ordinal,\n\t\t);\n\t}\n}\nexport function assignChild<C extends IMergeNodeBuilder>(\n\tparent: MergeBlock,\n\tchild: C,\n\tindex: number,\n\tupdateOrdinal = true,\n): asserts child is C & IMergeNodeInfo {\n\tconst node = Object.assign<C, IMergeNodeInfo>(child, {\n\t\tparent,\n\t\tindex,\n\t\tordinal: hasProp(child, \"ordinal\", \"string\") ? child.ordinal : \"\",\n\t});\n\tif (updateOrdinal) {\n\t\tparent.setOrdinal(node, index);\n\t}\n\tparent.children[index] = node;\n}\n\nexport function seqLTE(seq: number, minOrRefSeq: number): boolean {\n\treturn seq !== UnassignedSequenceNumber && seq <= minOrRefSeq;\n}\n\n/**\n * @legacy @beta\n */\nexport abstract class BaseSegment implements ISegment {\n\tpublic cachedLength: number = 0;\n\n\tpublic readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(\n\t\tthis,\n\t);\n\t/***/\n\tpublic attribution?: IAttributionCollection<AttributionKey>;\n\n\tpublic properties?: PropertySet;\n\tpublic abstract readonly type: string;\n\tpublic constructor(properties?: PropertySet) {\n\t\tif (properties !== undefined) {\n\t\t\tthis.properties = clone(properties);\n\t\t}\n\t}\n\n\tpublic hasProperty(key: string): boolean {\n\t\treturn !!this.properties && this.properties[key] !== undefined;\n\t}\n\n\tpublic isLeaf(): this is ISegment {\n\t\treturn true;\n\t}\n\n\tprotected cloneInto(b: ISegment): void {\n\t\tconst seg: ISegmentPrivate = b;\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IHasInsertionInfo>(seg, {\n\t\t\t\tinsert: this.insert,\n\t\t\t});\n\t\t}\n\t\t// TODO: deep clone properties\n\t\tseg.properties = clone(this.properties);\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IHasRemovalInfo>(seg, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\n\t\tseg.attribution = this.attribution?.clone();\n\t}\n\n\tpublic canAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tprotected addSerializedProps(jseg: IJSONSegment): void {\n\t\tif (this.properties) {\n\t\t\tjseg.props = { ...this.properties };\n\t\t}\n\t}\n\t// This has to return any type because the return type is different for different segment types.\n\t// TODO: If possible, change the return type to match what should be returned for each segment type.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic abstract toJSONObject(): any;\n\n\tpublic splitAt(pos: number): ISegment | undefined {\n\t\tif (pos <= 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst leafSegment: ISegmentPrivate | undefined = this.createSplitSegmentAt(pos);\n\n\t\tif (!leafSegment) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (isMergeNode(this)) {\n\t\t\toverwriteInfo<IMergeNodeInfo>(leafSegment, {\n\t\t\t\tindex: this.index + 1,\n\t\t\t\t// Give the leaf a temporary yet valid ordinal.\n\t\t\t\t// when this segment is put in the tree, it will get its real ordinal,\n\t\t\t\t// but this ordinal meets all the necessary invariants for now.\n\t\t\t\t// Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.\n\t\t\t\t// The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-code-point\n\t\t\t\tordinal: this.ordinal + String.fromCharCode(0),\n\t\t\t\tparent: this.parent,\n\t\t\t});\n\t\t}\n\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IHasInsertionInfo>(leafSegment, { insert: this.insert });\n\t\t}\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IHasRemovalInfo>(leafSegment, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\t\tif (isInsideObliterate(this)) {\n\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(leafSegment, {\n\t\t\t\tobliteratePrecedingInsertion: this.obliteratePrecedingInsertion,\n\t\t\t\tinsertionRefSeqStamp: this.insertionRefSeqStamp,\n\t\t\t});\n\t\t}\n\n\t\tthis.trackingCollection.copyTo(leafSegment);\n\t\tif (this.attribution) {\n\t\t\tleafSegment.attribution = this.attribution.splitAt(pos);\n\t\t}\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic abstract clone(): ISegment;\n\n\tpublic append(other: ISegment): void {\n\t\t// Note: Must call 'appendLocalRefs' before modifying this segment's length as\n\t\t// 'this.cachedLength' is used to adjust the offsets of the local refs.\n\t\tLocalReferenceCollection.append(this, other);\n\t\tif (this.attribution) {\n\t\t\tassert(\n\t\t\t\tother.attribution !== undefined,\n\t\t\t\t0x4bd /* attribution should be set on appendee */,\n\t\t\t);\n\t\t\tthis.attribution.append(other.attribution);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tother.attribution === undefined,\n\t\t\t\t0x4be /* attribution should not be set on appendee */,\n\t\t\t);\n\t\t}\n\n\t\tthis.cachedLength ??= 0;\n\t\tthis.cachedLength += other.cachedLength;\n\t}\n\n\tprotected abstract createSplitSegmentAt(pos: number): BaseSegment | undefined;\n}\n\n/**\n * The special-cased property key that tracks the id of a {@link Marker}.\n *\n * @remarks In general, marker ids should be accessed using the inherent method\n * {@link Marker.getId}. Marker ids should not be updated after creation.\n * @legacy @beta\n */\nexport const reservedMarkerIdKey = \"markerId\";\n\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @legacy @beta\n */\nexport interface IJSONMarkerSegment extends IJSONSegment {\n\tmarker: IMarkerDef;\n}\n\n/**\n * Markers are a special kind of segment that do not hold any content.\n *\n * Markers with a reference type of {@link ReferenceType.Tile} support spatially\n * accelerated queries for finding the next marker to the left or right of it in\n * sub-linear time. This is useful, for example, in the case of jumping from the\n * start of a paragraph to the end, assuming a paragraph is bound by markers at\n * the start and end.\n *\n * @legacy @beta\n */\nexport class Marker extends BaseSegment implements ReferencePosition, ISegment {\n\tpublic static readonly type = \"Marker\";\n\tpublic static is(segment: ISegment): segment is Marker {\n\t\treturn segment.type === Marker.type;\n\t}\n\tpublic readonly type = Marker.type;\n\n\tpublic static make(refType: ReferenceType, props?: PropertySet): Marker {\n\t\treturn new Marker(refType, props);\n\t}\n\n\tconstructor(\n\t\tpublic refType: ReferenceType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tsuper(props);\n\t\tthis.cachedLength = 1;\n\t}\n\n\ttoJSONObject(): IJSONMarkerSegment {\n\t\tconst obj: IJSONMarkerSegment = { marker: { refType: this.refType } };\n\t\tsuper.addSerializedProps(obj);\n\t\treturn obj;\n\t}\n\n\tstatic fromJSONObject(spec: IJSONSegment): Marker | undefined {\n\t\tif (spec && typeof spec === \"object\" && \"marker\" in spec) {\n\t\t\treturn Marker.make((spec.marker as Marker).refType, spec.props as PropertySet);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tclone(): Marker {\n\t\tconst b = Marker.make(this.refType, this.properties);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tgetSegment(): Marker {\n\t\treturn this;\n\t}\n\n\tgetOffset(): number {\n\t\treturn 0;\n\t}\n\n\tgetProperties(): PropertySet | undefined {\n\t\treturn this.properties;\n\t}\n\n\tgetId(): string | undefined {\n\t\treturn this.properties?.[reservedMarkerIdKey] as string;\n\t}\n\n\ttoString(): string {\n\t\treturn `M${this.getId()}`;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number): undefined {\n\t\treturn undefined;\n\t}\n\n\tcanAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tappend(): void {\n\t\tthrow new Error(\"Can not append to marker\");\n\t}\n}\n\n/**\n * Returns a stamp that occurs at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqStamp(collabWindow: CollaborationWindow): OperationStamp {\n\treturn { seq: collabWindow.minSeq, clientId: NonCollabClient };\n}\n\n/**\n * Returns a perspective representing a readonly client's view of the tree at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqPerspective(collabWindow: CollaborationWindow): Perspective {\n\treturn new PriorPerspective(collabWindow.minSeq, NonCollabClient);\n}\n\n/**\n * This class is used to track facts about the current window of collaboration. This window is defined by the server\n * specified minimum sequence number to the last sequence number seen. Additionally, it track state for outstanding\n * local operations.\n * @internal\n */\nexport class CollaborationWindow {\n\tclientId = LocalClientId;\n\tcollaborating = false;\n\n\t/**\n\t * Lowest-numbered segment in window; no client can reference a state before this one\n\t */\n\tminSeq = 0;\n\t/**\n\t * Highest-numbered segment in window and current reference sequence number for this client.\n\t */\n\tcurrentSeq = 0;\n\n\t/**\n\t * Highest-numbered localSeq used for a pending segment.\n\t * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:\n\t * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.\n\t *\n\t * @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree\n\t * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.\n\t *\n\t * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from\n\t * the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.\n\t *\n\t * For example, imagine a client with initial state \"123456\" submits some ops to create the text \"123456ABC\".\n\t * If they insert the \"C\" first, then \"B\", then \"A\", their local segment state might look like this:\n\t * ```js\n\t * [\n\t * { seq: 0, text: \"1234\" },\n\t * { seq: 5, text: \"56\" },\n\t * { localSeq: 3, seq: UnassignedSequenceNumber, text: \"A\" },\n\t * { localSeq: 2, seq: UnassignedSequenceNumber, text: \"B\" },\n\t * { localSeq: 1, seq: UnassignedSequenceNumber, text: \"C\" },\n\t * ]\n\t * ```\n\t * (note that localSeq tracks the localSeq at which a segment was inserted)\n\t *\n\t * Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate\n\t * that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.\n\t *\n\t * It will generate the ops\n\t * 1. \\{ pos: 6, text: \"C\" \\}\n\t * 2. \\{ pos: 6, text: \"B\" \\}\n\t * 3. \\{ pos: 6, text: \"A\" \\}\n\t *\n\t * since when submitting the first op, remote clients don't know that this client is about to submit the \"A\" and \"B\".\n\t *\n\t * On the other hand, imagine if the client had originally submitted the ops in the order \"A\", \"B\", \"C\"\n\t * such that the segments' local state was instead:\n\t *\n\t * ```js\n\t * [\n\t * { seq: 0, text: \"1234\" },\n\t * { seq: 5, text: \"56\" },\n\t * { localSeq: 1, seq: UnassignedSequenceNumber, text: \"A\" },\n\t * { localSeq: 2, seq: UnassignedSequenceNumber, text: \"B\" },\n\t * { localSeq: 3, seq: UnassignedSequenceNumber, text: \"C\" },\n\t * ]\n\t * ```\n\t *\n\t * The resubmitted ops should instead be:\n\t * 1. \\{ pos: 6, text: \"A\" \\}\n\t * 2. \\{ pos: 7, text: \"B\" \\}\n\t * 3. \\{ pos: 8, text: \"C\" \\}\n\t *\n\t * since remote clients will have seen the \"A\" when processing the \"B\" as well as both the \"A\" and \"B\" when processing the \"C\".\n\t * As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing\n\t * in `localSeq`.\n\t *\n\t * This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client\n\t * was disconnected, the resubmitted ops end up matching the original ops exactly.\n\t * However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked\n\t * and local information as appropriate.\n\t * Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible\n\t * from a given (seq, localSeq) perspective.\n\t */\n\tlocalSeq = 0;\n\n\tpublic localPerspective: Perspective = new LocalDefaultPerspective(this.clientId);\n\n\tpublic loadFrom(a: CollaborationWindow): void {\n\t\tthis.clientId = a.clientId;\n\t\tthis.collaborating = a.collaborating;\n\t\tthis.minSeq = a.minSeq;\n\t\tthis.currentSeq = a.currentSeq;\n\t}\n\n\tpublic mintNextLocalOperationStamp(): OperationStamp {\n\t\tif (this.collaborating) {\n\t\t\tthis.localSeq++;\n\t\t}\n\n\t\treturn {\n\t\t\tseq: this.collaborating ? UnassignedSequenceNumber : UniversalSequenceNumber,\n\t\t\tclientId: this.clientId,\n\t\t\tlocalSeq: this.localSeq,\n\t\t};\n\t}\n}\n\n/**\n * Compares two numbers.\n */\nexport const compareNumbers = (a: number, b: number): number => a - b;\n\n/**\n * Compares two strings.\n */\nexport const compareStrings = (a: string, b: string): number => a.localeCompare(b);\n"]}
1
+ {"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,iDAKwB;AACxB,2DAA4F;AAC5F,iEAAsF;AAEtF,6CAA0D;AAE1D,qDAA+F;AAC/F,mDAAmF;AAGnF,uDAY2B;AAyD3B;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAA+B,EAAE,CAClF,IAAA,4BAA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AAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AAAzD,QAAA,cAAc,kBAA2C;AAEtE;;GAEG;AACI,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAAtE,QAAA,cAAc,kBAAwD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { AttributionKey } from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { IAttributionCollection } from \"./attributionCollection.js\";\nimport {\n\tLocalClientId,\n\tNonCollabClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\nimport { LocalReferenceCollection, type LocalReferencePosition } from \"./localReference.js\";\nimport { TrackingGroupCollection, type ITrackingGroup } from \"./mergeTreeTracking.js\";\nimport type { IJSONSegment, IMarkerDef, ReferenceType } from \"./ops.js\";\nimport { computeHierarchicalOrdinal } from \"./ordinal.js\";\nimport type { PartialSequenceLengths } from \"./partialLengths.js\";\nimport { LocalDefaultPerspective, PriorPerspective, type Perspective } from \"./perspective.js\";\nimport { type PropertySet, clone, createMap, type MapLike } from \"./properties.js\";\nimport type { ReferencePosition } from \"./referencePositions.js\";\nimport type { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\thasProp,\n\tisInserted,\n\tisMergeNodeInfo as isMergeNode,\n\tisRemoved,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype IMergeNodeInfo,\n\ttype IHasRemovalInfo,\n\ttype SegmentWithInfo,\n\ttype ISegmentInsideObliterateInfo,\n\tisInsideObliterate,\n} from \"./segmentInfos.js\";\nimport type { PropertiesManager } from \"./segmentPropertiesManager.js\";\nimport type { Side } from \"./sequencePlace.js\";\nimport type { OperationStamp, SliceRemoveOperationStamp } from \"./stamps.js\";\n\n/**\n * This interface exposes internal things to dds that leverage merge tree,\n * like sequence and matrix.\n *\n * We use tiered interface to control visibility of segment properties.\n * This sits between ISegment and ISegmentPrivate. It should only expose\n * things tagged internal.\n *\n * Everything added here beyond ISegment should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * @internal\n */\nexport interface ISegmentInternal extends ISegment {\n\tlocalRefs?: LocalReferenceCollection;\n\t/**\n\t * Whether or not this segment is a special segment denoting the start or\n\t * end of the tree\n\t *\n\t * Endpoint segments are imaginary segments positioned immediately before or\n\t * after the tree. These segments cannot be referenced by regular operations\n\t * and exist primarily as a bucket for local references to slide onto during\n\t * deletion of regular segments.\n\t */\n\treadonly endpointType?: \"start\" | \"end\";\n}\n\n/**\n * We use tiered interface to control visibility of segment properties.\n * This is the lowest interface and is not exported, it site below ISegment and ISegmentInternal.\n * It should only expose unexported things.\n *\n * Everything added here beyond ISegmentInternal should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * someday we may split tree leaves from segments, but for now they are the same\n * this is just a convenience type that makes it clear that we need something that is both a segment and a leaf node\n */\nexport interface ISegmentPrivate extends ISegmentInternal {\n\tsegmentGroups?: SegmentGroupCollection;\n\tpropertyManager?: PropertiesManager;\n}\n/**\n * Segment leafs are segments that have both IMergeNodeInfo and IHasInsertionInfo. This means they\n * are inserted at a position, and bound via their parent MergeBlock to the merge tree. MergeBlocks'\n * children are either a segment leaf, or another merge block for interior nodes of the tree. When working\n * within the tree it is generally unnecessary to use type coercions methods common to the infos, and segment\n * leafs, as the children of MergeBlocks are already well typed. However, when segments come from outside the\n * merge tree, like via client's public methods, it becomes necessary to use the type coercions methods\n * to ensure the passed in segment objects are correctly bound to the merge tree.\n */\nexport type ISegmentLeaf = SegmentWithInfo<IMergeNodeInfo & IHasInsertionInfo>;\n/**\n * A type-guard which determines if the segment has segment leaf, and\n * returns true if it does, along with applying strong typing.\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment is a segment leaf, otherwise false.\n */\nexport const isSegmentLeaf = (segmentLike: unknown): segmentLike is ISegmentLeaf =>\n\tisInserted(segmentLike) && isMergeNode(segmentLike);\n\n/**\n * Converts a segment-like object to a segment leaf object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The segment leaf if the conversion is possible, otherwise undefined.\n */\nexport const toSegmentLeaf = (segmentLike: unknown): ISegmentLeaf | undefined =>\n\tisSegmentLeaf(segmentLike) ? segmentLike : undefined;\n/**\n * Asserts that the segment is a segment leaf. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment is not a segment leaf.\n */\nexport const assertSegmentLeaf: (segmentLike: unknown) => asserts segmentLike is ISegmentLeaf =\n\t(segmentLike) => assert(isSegmentLeaf(segmentLike), 0xaab /* must be segment leaf */);\n/**\n * This type is used for building MergeBlocks from segments and other MergeBlocks. We need this\n * type as segments may not yet be bound to the tree, so lack merge node info which is required for\n * segment leafs.\n */\nexport type IMergeNodeBuilder = MergeBlock | SegmentWithInfo<IHasInsertionInfo>;\n\n/**\n * This type is used by MergeBlocks to define their children, which are either segments or other\n * MergeBlocks.\n */\nexport type IMergeNode = MergeBlock | ISegmentLeaf;\n\n/**\n * A segment representing a portion of the merge tree.\n * Segments are leaf nodes of the merge tree and contain data.\n * @legacy @beta\n */\nexport interface ISegment {\n\treadonly type: string;\n\n\treadonly trackingCollection: TrackingGroupCollection;\n\n\t/**\n\t * The length of the contents of the node.\n\t */\n\tcachedLength: number;\n\t/**\n\t * Stores attribution keys associated with offsets of this segment.\n\t * This data is only persisted if MergeTree's `attributions.track` flag is set to true.\n\t * Pending segments (i.e. ones that only exist locally and haven't been acked by the server) also have\n\t * `attribution === undefined` until ack.\n\t *\n\t * Keys can be used opaquely with an IAttributor or a container runtime that provides attribution.\n\t * @remarks There are plans to make the shape of the data stored extensible in a couple ways:\n\t *\n\t * 1. Injection of custom attribution information associated with the segment (ex: copy-paste of\n\t * content but keeping the old attribution information).\n\t *\n\t * 2. Storage of multiple \"channels\" of information (ex: track property changes separately from insertion,\n\t * or only attribute certain property modifications, etc.)\n\t */\n\tattribution?: IAttributionCollection<AttributionKey>;\n\n\t/**\n\t * Properties that have been added to this segment via annotation.\n\t */\n\tproperties?: PropertySet;\n\n\tclone(): ISegment;\n\tcanAppend(segment: ISegment): boolean;\n\tappend(segment: ISegment): void;\n\tsplitAt(pos: number): ISegment | undefined;\n\t// Changing this to something other than any would break consumers.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\ttoJSONObject(): any;\n\tisLeaf(): this is ISegment;\n}\n\n/**\n * Determine if a segment has been removed.\n * @legacy @beta\n */\nexport function segmentIsRemoved(segment: ISegment): boolean {\n\treturn isRemoved(segment);\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISegmentAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tsegment: ISegment,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number,\n\t\tend: number,\n\t\taccum: TClientData,\n\t): boolean;\n}\nexport interface ISegmentChanges {\n\tnext?: SegmentWithInfo<IHasInsertionInfo>;\n\treplaceCurrent?: SegmentWithInfo<IHasInsertionInfo>;\n}\n\nexport interface InsertContext {\n\tcandidateSegment?: SegmentWithInfo<IHasInsertionInfo>;\n\tleaf: (segment: ISegmentLeaf | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: MergeBlock) => boolean;\n}\n\nexport interface ObliterateInfo {\n\tstart: LocalReferencePosition;\n\tstartSide: Side;\n\tend: LocalReferencePosition;\n\tendSide: Side;\n\trefSeq: number;\n\tstamp: SliceRemoveOperationStamp;\n\tsegmentGroup: SegmentGroup | undefined;\n\t/**\n\t * Defined only for unacked obliterates.\n\t *\n\t * Contains all segments inserted into the range this obliterate affects where at the time of insertion,\n\t * this obliterate was the newest concurrent obliterate that overlapped the insertion point (this information\n\t * is relevant for the tiebreak policy of allowing last-obliterater to insert).\n\t *\n\t * We need to keep this around for unacked ops because on reconnect, outstanding local obliterates may have set `obliteratePrecedingInsertion`\n\t * (tiebreak) on segments they no longer apply to, since the reissued obliterate may affect a smaller range than the original one when content\n\t * near the obliterate's endpoints was removed by another client between the time of the original obliterate and reissuing.\n\t */\n\ttiebreakTrackingGroup: ITrackingGroup | undefined;\n}\n\nexport interface SegmentGroup {\n\tsegments: ISegmentLeaf[];\n\tpreviousProps?: PropertySet[];\n\tlocalSeq?: number;\n\trefSeq: number;\n\tobliterateInfo?: ObliterateInfo;\n}\n\n/**\n * Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because\n * the MergeTree always inserts first, then checks for overflow and splits if the child count equals\n * `MaxNodesInBlock`. (i.e., `MaxNodesInBlock` contains 1 extra slot for temporary storage to\n * facilitate splits.)\n */\nexport const MaxNodesInBlock = 8;\nexport class MergeBlock implements Partial<IMergeNodeInfo> {\n\tpublic children: IMergeNode[];\n\tpublic needsScour?: boolean;\n\tpublic parent?: MergeBlock;\n\tpublic index: number = 0;\n\tpublic ordinal: string = \"\";\n\tpublic cachedLength: number | undefined = 0;\n\n\t/**\n\t * Maps each tile label in this block to the rightmost (i.e. furthest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic rightmostTiles: Readonly<MapLike<Marker>>;\n\t/**\n\t * Maps each tile label in this block to the leftmost (i.e. nearest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic leftmostTiles: Readonly<MapLike<Marker>>;\n\n\tisLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\n\t/**\n\t * Supports querying the total length of all descendants of this IMergeBlock from the perspective of any\n\t * (clientId, seq) within the collab window.\n\t *\n\t * @remarks This is only optional for implementation reasons (internal nodes can be created/moved without\n\t * immediately initializing the partial lengths). Aside from mid-update on tree operations, these lengths\n\t * objects are always defined.\n\t */\n\tpartialLengths?: PartialSequenceLengths;\n\n\tpublic constructor(public childCount: number) {\n\t\t// Suppression needed due to the way the merge tree children are initialized - we\n\t\t// allocate 8 children blocks, but any unused blocks are not counted in the childCount.\n\t\t// Using Array.from leads to unused children being undefined, which are counted in childCount.\n\t\t// eslint-disable-next-line unicorn/no-new-array\n\t\tthis.children = new Array<IMergeNode>(MaxNodesInBlock);\n\t\tthis.rightmostTiles = createMap<Marker>();\n\t\tthis.leftmostTiles = createMap<Marker>();\n\t}\n\n\tpublic setOrdinal(child: IMergeNode, index: number): void {\n\t\tconst childCount = this.childCount;\n\t\tassert(\n\t\t\tchildCount >= 1 && childCount <= MaxNodesInBlock,\n\t\t\t0x040 /* \"Child count is not within [1,8] range!\" */,\n\t\t);\n\t\tchild.ordinal = computeHierarchicalOrdinal(\n\t\t\tMaxNodesInBlock,\n\t\t\tchildCount,\n\t\t\tthis.ordinal,\n\t\t\tindex === 0 ? undefined : this.children[index - 1]?.ordinal,\n\t\t);\n\t}\n}\nexport function assignChild<C extends IMergeNodeBuilder>(\n\tparent: MergeBlock,\n\tchild: C,\n\tindex: number,\n\tupdateOrdinal = true,\n): asserts child is C & IMergeNodeInfo {\n\tconst node = Object.assign<C, IMergeNodeInfo>(child, {\n\t\tparent,\n\t\tindex,\n\t\tordinal: hasProp(child, \"ordinal\", \"string\") ? child.ordinal : \"\",\n\t});\n\tif (updateOrdinal) {\n\t\tparent.setOrdinal(node, index);\n\t}\n\tparent.children[index] = node;\n}\n\nexport function seqLTE(seq: number, minOrRefSeq: number): boolean {\n\treturn seq !== UnassignedSequenceNumber && seq <= minOrRefSeq;\n}\n\n/**\n * @legacy @beta\n */\nexport abstract class BaseSegment implements ISegment {\n\tpublic cachedLength: number = 0;\n\n\tpublic readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(\n\t\tthis,\n\t);\n\t/***/\n\tpublic attribution?: IAttributionCollection<AttributionKey>;\n\n\tpublic properties?: PropertySet;\n\tpublic abstract readonly type: string;\n\tpublic constructor(properties?: PropertySet) {\n\t\tif (properties !== undefined) {\n\t\t\tthis.properties = clone(properties);\n\t\t}\n\t}\n\n\tpublic hasProperty(key: string): boolean {\n\t\treturn !!this.properties && this.properties[key] !== undefined;\n\t}\n\n\tpublic isLeaf(): this is ISegment {\n\t\treturn true;\n\t}\n\n\tprotected cloneInto(b: ISegment): void {\n\t\tconst seg: ISegmentPrivate = b;\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IHasInsertionInfo>(seg, {\n\t\t\t\tinsert: this.insert,\n\t\t\t});\n\t\t}\n\t\t// TODO: deep clone properties\n\t\tseg.properties = clone(this.properties);\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IHasRemovalInfo>(seg, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\n\t\tseg.attribution = this.attribution?.clone();\n\t}\n\n\tpublic canAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tprotected addSerializedProps(jseg: IJSONSegment): void {\n\t\tif (this.properties) {\n\t\t\tjseg.props = { ...this.properties };\n\t\t}\n\t}\n\t// This has to return any type because the return type is different for different segment types.\n\t// TODO: If possible, change the return type to match what should be returned for each segment type.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic abstract toJSONObject(): any;\n\n\tpublic splitAt(pos: number): ISegment | undefined {\n\t\tif (pos <= 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst leafSegment: ISegmentPrivate | undefined = this.createSplitSegmentAt(pos);\n\n\t\tif (!leafSegment) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (isMergeNode(this)) {\n\t\t\toverwriteInfo<IMergeNodeInfo>(leafSegment, {\n\t\t\t\tindex: this.index + 1,\n\t\t\t\t// Give the leaf a temporary yet valid ordinal.\n\t\t\t\t// when this segment is put in the tree, it will get its real ordinal,\n\t\t\t\t// but this ordinal meets all the necessary invariants for now.\n\t\t\t\t// Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.\n\t\t\t\t// The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-code-point\n\t\t\t\tordinal: this.ordinal + String.fromCharCode(0),\n\t\t\t\tparent: this.parent,\n\t\t\t});\n\t\t}\n\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IHasInsertionInfo>(leafSegment, { insert: this.insert });\n\t\t}\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IHasRemovalInfo>(leafSegment, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\t\tif (isInsideObliterate(this)) {\n\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(leafSegment, {\n\t\t\t\tobliteratePrecedingInsertion: this.obliteratePrecedingInsertion,\n\t\t\t\tinsertionRefSeqStamp: this.insertionRefSeqStamp,\n\t\t\t});\n\t\t}\n\n\t\tthis.trackingCollection.copyTo(leafSegment);\n\t\tif (this.attribution) {\n\t\t\tleafSegment.attribution = this.attribution.splitAt(pos);\n\t\t}\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic abstract clone(): ISegment;\n\n\tpublic append(other: ISegment): void {\n\t\t// Note: Must call 'appendLocalRefs' before modifying this segment's length as\n\t\t// 'this.cachedLength' is used to adjust the offsets of the local refs.\n\t\tLocalReferenceCollection.append(this, other);\n\t\tif (this.attribution) {\n\t\t\tassert(\n\t\t\t\tother.attribution !== undefined,\n\t\t\t\t0x4bd /* attribution should be set on appendee */,\n\t\t\t);\n\t\t\tthis.attribution.append(other.attribution);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tother.attribution === undefined,\n\t\t\t\t0x4be /* attribution should not be set on appendee */,\n\t\t\t);\n\t\t}\n\n\t\tthis.cachedLength ??= 0;\n\t\tthis.cachedLength += other.cachedLength;\n\t}\n\n\tprotected abstract createSplitSegmentAt(pos: number): BaseSegment | undefined;\n}\n\n/**\n * The special-cased property key that tracks the id of a {@link Marker}.\n *\n * @remarks In general, marker ids should be accessed using the inherent method\n * {@link Marker.getId}. Marker ids should not be updated after creation.\n * @legacy @beta\n */\nexport const reservedMarkerIdKey = \"markerId\";\n\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @legacy @beta\n */\nexport interface IJSONMarkerSegment extends IJSONSegment {\n\tmarker: IMarkerDef;\n}\n\n/**\n * Markers are a special kind of segment that do not hold any content.\n *\n * Markers with a reference type of {@link ReferenceType.Tile} support spatially\n * accelerated queries for finding the next marker to the left or right of it in\n * sub-linear time. This is useful, for example, in the case of jumping from the\n * start of a paragraph to the end, assuming a paragraph is bound by markers at\n * the start and end.\n *\n * @legacy @beta\n */\nexport class Marker extends BaseSegment implements ReferencePosition, ISegment {\n\tpublic static readonly type = \"Marker\";\n\tpublic static is(segment: ISegment): segment is Marker {\n\t\treturn segment.type === Marker.type;\n\t}\n\tpublic readonly type = Marker.type;\n\n\tpublic static make(refType: ReferenceType, props?: PropertySet): Marker {\n\t\treturn new Marker(refType, props);\n\t}\n\n\tconstructor(\n\t\tpublic refType: ReferenceType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tsuper(props);\n\t\tthis.cachedLength = 1;\n\t}\n\n\ttoJSONObject(): IJSONMarkerSegment {\n\t\tconst obj: IJSONMarkerSegment = { marker: { refType: this.refType } };\n\t\tsuper.addSerializedProps(obj);\n\t\treturn obj;\n\t}\n\n\tstatic fromJSONObject(spec: IJSONSegment): Marker | undefined {\n\t\tif (spec && typeof spec === \"object\" && \"marker\" in spec) {\n\t\t\treturn Marker.make((spec.marker as Marker).refType, spec.props as PropertySet);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tclone(): Marker {\n\t\tconst b = Marker.make(this.refType, this.properties);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tgetSegment(): Marker {\n\t\treturn this;\n\t}\n\n\tgetOffset(): number {\n\t\treturn 0;\n\t}\n\n\tgetProperties(): PropertySet | undefined {\n\t\treturn this.properties;\n\t}\n\n\tgetId(): string | undefined {\n\t\treturn this.properties?.[reservedMarkerIdKey] as string;\n\t}\n\n\ttoString(): string {\n\t\treturn `M${this.getId()}`;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number): undefined {\n\t\treturn undefined;\n\t}\n\n\tcanAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tappend(): void {\n\t\tthrow new Error(\"Can not append to marker\");\n\t}\n}\n\n/**\n * Returns a stamp that occurs at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqStamp(collabWindow: CollaborationWindow): OperationStamp {\n\treturn { seq: collabWindow.minSeq, clientId: NonCollabClient };\n}\n\n/**\n * Returns a perspective representing a readonly client's view of the tree at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqPerspective(collabWindow: CollaborationWindow): Perspective {\n\treturn new PriorPerspective(collabWindow.minSeq, NonCollabClient);\n}\n\n/**\n * This class is used to track facts about the current window of collaboration. This window is defined by the server\n * specified minimum sequence number to the last sequence number seen. Additionally, it track state for outstanding\n * local operations.\n * @internal\n */\nexport class CollaborationWindow {\n\tclientId = LocalClientId;\n\tcollaborating = false;\n\n\t/**\n\t * Lowest-numbered segment in window; no client can reference a state before this one\n\t */\n\tminSeq = 0;\n\t/**\n\t * Highest-numbered segment in window and current reference sequence number for this client.\n\t */\n\tcurrentSeq = 0;\n\n\t/**\n\t * Highest-numbered localSeq used for a pending segment.\n\t * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:\n\t * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.\n\t *\n\t * @remarks This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree\n\t * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.\n\t *\n\t * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from\n\t * the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.\n\t *\n\t * For example, imagine a client with initial state \"123456\" submits some ops to create the text \"123456ABC\".\n\t * If they insert the \"C\" first, then \"B\", then \"A\", their local segment state might look like this:\n\t * ```js\n\t * [\n\t * { seq: 0, text: \"1234\" },\n\t * { seq: 5, text: \"56\" },\n\t * { localSeq: 3, seq: UnassignedSequenceNumber, text: \"A\" },\n\t * { localSeq: 2, seq: UnassignedSequenceNumber, text: \"B\" },\n\t * { localSeq: 1, seq: UnassignedSequenceNumber, text: \"C\" },\n\t * ]\n\t * ```\n\t * (note that localSeq tracks the localSeq at which a segment was inserted)\n\t *\n\t * Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate\n\t * that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.\n\t *\n\t * It will generate the ops\n\t * 1. \\{ pos: 6, text: \"C\" \\}\n\t * 2. \\{ pos: 6, text: \"B\" \\}\n\t * 3. \\{ pos: 6, text: \"A\" \\}\n\t *\n\t * since when submitting the first op, remote clients don't know that this client is about to submit the \"A\" and \"B\".\n\t *\n\t * On the other hand, imagine if the client had originally submitted the ops in the order \"A\", \"B\", \"C\"\n\t * such that the segments' local state was instead:\n\t *\n\t * ```js\n\t * [\n\t * { seq: 0, text: \"1234\" },\n\t * { seq: 5, text: \"56\" },\n\t * { localSeq: 1, seq: UnassignedSequenceNumber, text: \"A\" },\n\t * { localSeq: 2, seq: UnassignedSequenceNumber, text: \"B\" },\n\t * { localSeq: 3, seq: UnassignedSequenceNumber, text: \"C\" },\n\t * ]\n\t * ```\n\t *\n\t * The resubmitted ops should instead be:\n\t * 1. \\{ pos: 6, text: \"A\" \\}\n\t * 2. \\{ pos: 7, text: \"B\" \\}\n\t * 3. \\{ pos: 8, text: \"C\" \\}\n\t *\n\t * since remote clients will have seen the \"A\" when processing the \"B\" as well as both the \"A\" and \"B\" when processing the \"C\".\n\t * As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing\n\t * in `localSeq`.\n\t *\n\t * This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client\n\t * was disconnected, the resubmitted ops end up matching the original ops exactly.\n\t * However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked\n\t * and local information as appropriate.\n\t * Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible\n\t * from a given (seq, localSeq) perspective.\n\t */\n\tlocalSeq = 0;\n\n\tpublic localPerspective: Perspective = new LocalDefaultPerspective(this.clientId);\n\n\tpublic loadFrom(a: CollaborationWindow): void {\n\t\tthis.clientId = a.clientId;\n\t\tthis.collaborating = a.collaborating;\n\t\tthis.minSeq = a.minSeq;\n\t\tthis.currentSeq = a.currentSeq;\n\t}\n\n\tpublic mintNextLocalOperationStamp(): OperationStamp {\n\t\tif (this.collaborating) {\n\t\t\tthis.localSeq++;\n\t\t}\n\n\t\treturn {\n\t\t\tseq: this.collaborating ? UnassignedSequenceNumber : UniversalSequenceNumber,\n\t\t\tclientId: this.clientId,\n\t\t\tlocalSeq: this.localSeq,\n\t\t};\n\t}\n}\n\n/**\n * Compares two numbers.\n */\nexport const compareNumbers = (a: number, b: number): number => a - b;\n\n/**\n * Compares two strings.\n */\nexport const compareStrings = (a: string, b: string): number => a.localeCompare(b);\n"]}
package/dist/stamps.d.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * from alternative perspectives: a remote client will have seen all of its own previous operations as well as
15
15
  * those at or below the op's reference sequence number.
16
16
  *
17
- * @remarks - As the `readonly` identifies suggest, these stamps should be treated as immutable.
17
+ * @remarks As the `readonly` identifies suggest, these stamps should be treated as immutable.
18
18
  * New operations applied to a merge-tree should create new stamps rather than modify existing ones (e.g. when
19
19
  * a change's ack happens).
20
20
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"stamps.js","sourceRoot":"","sources":["../src/stamps.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAIwB;AA6ExB,SAAgB,QAAQ,CAAC,CAAiB,EAAE,CAAiB;IAC5D,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,oEAAoE;QACpE,OAAO,CAAC,CAAC,GAAG,KAAK,uCAAwB,IAAI,CAAC,CAAC,QAAS,GAAG,CAAC,CAAC,QAAS,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;AACtB,CAAC;AAXD,4BAWC;AAED,SAAgB,GAAG,CAAC,CAAiB,EAAE,CAAiB;IACvD,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC;AAFD,kBAEC;AAED,SAAgB,WAAW,CAAC,CAAiB,EAAE,CAAiB;IAC/D,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,oEAAoE;QACpE,OAAO,CAAC,CAAC,GAAG,KAAK,uCAAwB,IAAI,CAAC,CAAC,QAAS,GAAG,CAAC,CAAC,QAAS,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,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AE,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7B,OAAO;YACR,CAAC;QACF,CAAC;QAED,6DAA6D;QAC7D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACF,CAAC;AAdD,wCAcC;AAED,SAAgB,oBAAoB,CAAC,IAAsB;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC;AAFD,oDAEC;AAED,SAAgB,OAAO,CAAC,CAAiB,EAAE,CAAiB;IAC3D,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,CAAC;IACV,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACV,CAAC;AACF,CAAC;AARD,0BAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tSquashClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\n\n/**\n * A stamp that identifies provenance of an operation performed on the MergeTree.\n *\n * Stamps identify a point in time (`seq`/`localSeq`) as well as the source (`clientId`) for the operation.\n * This provides enough information to linearize all known applied operations: acked operations happen before\n * local+unacked ones, with acked operations ordered by their sequence numbers and local+unacked operations\n * ordered by their localSeq.\n *\n * By including `clientId`, it also provides enough information to resolve whether segments are visible\n * from alternative perspectives: a remote client will have seen all of its own previous operations as well as\n * those at or below the op's reference sequence number.\n *\n * @remarks - As the `readonly` identifies suggest, these stamps should be treated as immutable.\n * New operations applied to a merge-tree should create new stamps rather than modify existing ones (e.g. when\n * a change's ack happens).\n * @internal\n */\nexport interface OperationStamp {\n\t/**\n\t * The sequence number at which this operation was applied.\n\t */\n\treadonly seq: number;\n\n\t/**\n\t * Short clientId for the client that performed this operation.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * Local seq at which this operation was applied.\n\t * This is defined if and only if the operation is pending an ack, i.e. `seq` is UnassignedSequenceNumber.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\treadonly localSeq?: number;\n}\n\n/**\n * {@link OperationStamp} for an 'insert' operation.\n */\nexport interface InsertOperationStamp extends OperationStamp {\n\treadonly type: \"insert\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `markRangeRemoved` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect only the *set* of nodes that were\n * specified at the time the local client issued the remove, and not any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SetRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"setRemove\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `obliterateRange` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect the *slice* of nodes between the\n * start and end point specified by the local client, which includes any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SliceRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"sliceRemove\";\n}\n\nexport type RemoveOperationStamp = SetRemoveOperationStamp | SliceRemoveOperationStamp;\n\nexport function lessThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq === UnassignedSequenceNumber && a.localSeq! < b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn true;\n\t}\n\n\treturn a.seq < b.seq;\n}\n\nexport function gte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !lessThan(a, b);\n}\n\nexport function greaterThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq !== UnassignedSequenceNumber || a.localSeq! > b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\treturn a.seq > b.seq;\n}\n\nexport function lte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !greaterThan(a, b);\n}\n\nexport function equal(a: OperationStamp, b: OperationStamp): boolean {\n\treturn a.seq === b.seq && a.clientId === b.clientId && a.localSeq === b.localSeq;\n}\n\nexport function isLocal(a: OperationStamp): boolean {\n\treturn a.seq === UnassignedSequenceNumber;\n}\n\nexport function isSquashedOp(a: OperationStamp): boolean {\n\treturn a.clientId === SquashClient && a.seq === UniversalSequenceNumber;\n}\n\nexport function isAcked(a: OperationStamp): boolean {\n\treturn a.seq !== UnassignedSequenceNumber;\n}\n\n/**\n * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.\n *\n * Beware that this uses Array.splice, thus requires asymptotics considerations.\n * If inserting a variable number of timestamps, consider just pushing them and sorting the list\n * after using {@link compare} instead.\n */\nexport function spliceIntoList(list: OperationStamp[], stamp: OperationStamp): void {\n\tif (isLocal(stamp) || list.length === 0) {\n\t\tlist.push(stamp);\n\t} else {\n\t\tfor (let i = list.length - 1; i >= 0; i--) {\n\t\t\tif (greaterThan(stamp, list[i])) {\n\t\t\t\tlist.splice(i + 1, 0, stamp);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Less than all stamps in the list: put it at the beginning.\n\t\tlist.unshift(stamp);\n\t}\n}\n\nexport function hasAnyAckedOperation(list: OperationStamp[]): boolean {\n\treturn list.some((ts) => isAcked(ts));\n}\n\nexport function compare(a: OperationStamp, b: OperationStamp): number {\n\tif (greaterThan(a, b)) {\n\t\treturn 1;\n\t} else if (lessThan(a, b)) {\n\t\treturn -1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n"]}
1
+ {"version":3,"file":"stamps.js","sourceRoot":"","sources":["../src/stamps.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAIwB;AA6ExB,SAAgB,QAAQ,CAAC,CAAiB,EAAE,CAAiB;IAC5D,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,oEAAoE;QACpE,OAAO,CAAC,CAAC,GAAG,KAAK,uCAAwB,IAAI,CAAC,CAAC,QAAS,GAAG,CAAC,CAAC,QAAS,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;AACtB,CAAC;AAXD,4BAWC;AAED,SAAgB,GAAG,CAAC,CAAiB,EAAE,CAAiB;IACvD,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC;AAFD,kBAEC;AAED,SAAgB,WAAW,CAAC,CAAiB,EAAE,CAAiB;IAC/D,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,oEAAoE;QACpE,OAAO,CAAC,CAAC,GAAG,KAAK,uCAAwB,IAAI,CAAC,CAAC,QAAS,GAAG,CAAC,CAAC,QAAS,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,CAAC,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AC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7B,OAAO;YACR,CAAC;QACF,CAAC;QAED,6DAA6D;QAC7D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACF,CAAC;AAdD,wCAcC;AAED,SAAgB,oBAAoB,CAAC,IAAsB;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC;AAFD,oDAEC;AAED,SAAgB,OAAO,CAAC,CAAiB,EAAE,CAAiB;IAC3D,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,CAAC;IACV,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACV,CAAC;AACF,CAAC;AARD,0BAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tSquashClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\n\n/**\n * A stamp that identifies provenance of an operation performed on the MergeTree.\n *\n * Stamps identify a point in time (`seq`/`localSeq`) as well as the source (`clientId`) for the operation.\n * This provides enough information to linearize all known applied operations: acked operations happen before\n * local+unacked ones, with acked operations ordered by their sequence numbers and local+unacked operations\n * ordered by their localSeq.\n *\n * By including `clientId`, it also provides enough information to resolve whether segments are visible\n * from alternative perspectives: a remote client will have seen all of its own previous operations as well as\n * those at or below the op's reference sequence number.\n *\n * @remarks As the `readonly` identifies suggest, these stamps should be treated as immutable.\n * New operations applied to a merge-tree should create new stamps rather than modify existing ones (e.g. when\n * a change's ack happens).\n * @internal\n */\nexport interface OperationStamp {\n\t/**\n\t * The sequence number at which this operation was applied.\n\t */\n\treadonly seq: number;\n\n\t/**\n\t * Short clientId for the client that performed this operation.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * Local seq at which this operation was applied.\n\t * This is defined if and only if the operation is pending an ack, i.e. `seq` is UnassignedSequenceNumber.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\treadonly localSeq?: number;\n}\n\n/**\n * {@link OperationStamp} for an 'insert' operation.\n */\nexport interface InsertOperationStamp extends OperationStamp {\n\treadonly type: \"insert\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `markRangeRemoved` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect only the *set* of nodes that were\n * specified at the time the local client issued the remove, and not any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SetRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"setRemove\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `obliterateRange` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect the *slice* of nodes between the\n * start and end point specified by the local client, which includes any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SliceRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"sliceRemove\";\n}\n\nexport type RemoveOperationStamp = SetRemoveOperationStamp | SliceRemoveOperationStamp;\n\nexport function lessThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq === UnassignedSequenceNumber && a.localSeq! < b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn true;\n\t}\n\n\treturn a.seq < b.seq;\n}\n\nexport function gte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !lessThan(a, b);\n}\n\nexport function greaterThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq !== UnassignedSequenceNumber || a.localSeq! > b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\treturn a.seq > b.seq;\n}\n\nexport function lte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !greaterThan(a, b);\n}\n\nexport function equal(a: OperationStamp, b: OperationStamp): boolean {\n\treturn a.seq === b.seq && a.clientId === b.clientId && a.localSeq === b.localSeq;\n}\n\nexport function isLocal(a: OperationStamp): boolean {\n\treturn a.seq === UnassignedSequenceNumber;\n}\n\nexport function isSquashedOp(a: OperationStamp): boolean {\n\treturn a.clientId === SquashClient && a.seq === UniversalSequenceNumber;\n}\n\nexport function isAcked(a: OperationStamp): boolean {\n\treturn a.seq !== UnassignedSequenceNumber;\n}\n\n/**\n * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.\n *\n * Beware that this uses Array.splice, thus requires asymptotics considerations.\n * If inserting a variable number of timestamps, consider just pushing them and sorting the list\n * after using {@link compare} instead.\n */\nexport function spliceIntoList(list: OperationStamp[], stamp: OperationStamp): void {\n\tif (isLocal(stamp) || list.length === 0) {\n\t\tlist.push(stamp);\n\t} else {\n\t\tfor (let i = list.length - 1; i >= 0; i--) {\n\t\t\tif (greaterThan(stamp, list[i])) {\n\t\t\t\tlist.splice(i + 1, 0, stamp);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Less than all stamps in the list: put it at the beginning.\n\t\tlist.unshift(stamp);\n\t}\n}\n\nexport function hasAnyAckedOperation(list: OperationStamp[]): boolean {\n\treturn list.some((ts) => isAcked(ts));\n}\n\nexport function compare(a: OperationStamp, b: OperationStamp): number {\n\tif (greaterThan(a, b)) {\n\t\treturn 1;\n\t} else if (lessThan(a, b)) {\n\t\treturn -1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n"]}
@@ -81,7 +81,7 @@ export interface IAttributionCollection<T> {
81
81
  * Example: If the Attribution Offsets in the segment is [0, 10, 20, 30, 40] and request is for (startOffset: 5, endOffset: 25),
82
82
  * then result would be [(offset: 0, key: key1), (offset:10, key: key2), (offset:20, key: key3)].
83
83
  * @param channel - When specified, gets attribution keys associated with a particular channel.
84
- * @returns - undefined if the provided channel is not found or list of attribution keys along with
84
+ * @returns undefined if the provided channel is not found or list of attribution keys along with
85
85
  * the corresponding offset start boundary.
86
86
  */
87
87
  getKeysInOffsetRange(startOffset: number, endOffset?: number, channel?: string): {
@@ -1 +1 @@
1
- {"version":3,"file":"attributionCollection.js","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAM9E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAiItE,gDAAgD;AAChD,MAAM,UAAU,uBAAuB;AACtC,kDAAkD;AAClD,CAAoC;AACpC,kDAAkD;AAClD,CAAoC;IAEpC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACd,CAA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IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,IAAI,eAAe,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,QAAQ,GAAwC,EAAE,CAAC;YACzD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;gBACpC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,sBAAsB;gBACtD,2CAA2C;gBAC3C,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;YAC3C,CAAC;YACD,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAClC,CAAC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;CACD","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/internal\";\nimport type {\n\tAttributionKey,\n\tDetachedAttributionKey,\n\tOpAttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ISegment } from \"./mergeTreeNodes.js\";\n\n/**\n * @legacy @beta\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\t// eslint-disable-next-line @rushstack/no-new-null\n\tseqs: (number | AttributionKey | null)[];\n\tposBreakpoints: number[];\n}\n\n/**\n * @legacy @beta\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 * @legacy @beta\n */\nexport interface IAttributionCollectionSpec<T> {\n\t// eslint-disable-next-line @rushstack/no-new-null\n\troot: Iterable<{ offset: number; key: T | null }>;\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tchannels?: { [name: string]: Iterable<{ offset: number; key: T | null }> };\n\tlength: number;\n}\n\n/**\n * @legacy @beta\n * @sealed\n */\nexport interface IAttributionCollectionSerializer {\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 */\n\tpopulateAttributionCollections(\n\t\tsegments: Iterable<ISegment>,\n\t\tsummary: SerializedAttributionCollection,\n\t): void;\n}\n\n/**\n * @legacy @beta\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 * Retrieves all the [Offset, Attribution key] pairs for the provided offset range. Note:\n\t * The returned array is sorted by offset.\n\t * The first offset in response could be lower than the startOffset as the Attribution Key for the startOffset\n\t * could start at a lower offset than the startOffset in case where Attribution key offset boundaries don't\n\t * align exactly with startOffset.\n\t * Example: If the Attribution Offsets in the segment is [0, 10, 20, 30, 40] and request is for (startOffset: 5, endOffset: 25),\n\t * then result would be [(offset: 0, key: key1), (offset:10, key: key2), (offset:20, key: key3)].\n\t * @param channel - When specified, gets attribution keys associated with a particular channel.\n\t * @returns - undefined if the provided channel is not found or list of attribution keys along with\n\t * the corresponding offset start boundary.\n\t */\n\tgetKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t\tchannel?: string,\n\t): { offset: number; key: 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 */\n\tgetAll(): IAttributionCollectionSpec<T>;\n\n\t/***/\n\tsplitAt(pos: number): IAttributionCollection<T>;\n\n\t/***/\n\tappend(other: IAttributionCollection<T>): void;\n\n\t/***/\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 */\n\tupdate(name: string | undefined, channel: IAttributionCollection<T>): void;\n}\n\n// note: treats null and undefined as equivalent\nexport function areEqualAttributionKeys(\n\t// eslint-disable-next-line @rushstack/no-new-null\n\ta: AttributionKey | null | undefined,\n\t// eslint-disable-next-line @rushstack/no-new-null\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\t}\n\t\tcase \"detached\": {\n\t\t\treturn a.id === (b as DetachedAttributionKey).id;\n\t\t}\n\t\tcase \"local\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\tunreachableCase(a, \"Unhandled AttributionKey type\");\n\t\t}\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(\n\t\tprivate _length: number,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tbaseEntry?: AttributionKey | null,\n\t) {\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\tpublic getKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t): { offset: number; key: AttributionKey }[];\n\tpublic getKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t\tchannel?: string,\n\t): { offset: number; key: AttributionKey }[] | undefined;\n\tpublic getKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t\tchannel?: string,\n\t): { offset: number; key: AttributionKey }[] | undefined {\n\t\tif (startOffset < 0 || startOffset >= this._length) {\n\t\t\tthrow new UsageError(\"startOffset should be valid and in range\");\n\t\t}\n\t\tif (\n\t\t\tendOffset !== undefined &&\n\t\t\t(endOffset < 0 || endOffset >= this._length || startOffset > endOffset)\n\t\t) {\n\t\t\tthrow new UsageError(\"endOffset should be valid and in range\");\n\t\t}\n\n\t\tif (channel !== undefined) {\n\t\t\tconst subCollection = this.channels?.[channel];\n\t\t\treturn subCollection?.getKeysInOffsetRange(startOffset, endOffset);\n\t\t}\n\t\tconst result: { offset: number; key: AttributionKey }[] = [];\n\t\tlet index = this.findIndex(startOffset);\n\t\tlet attributionKey = this.get(index);\n\t\tif (attributionKey !== undefined) {\n\t\t\tresult.push({ offset: this.offsets[index], key: attributionKey });\n\t\t}\n\t\tindex++;\n\t\tconst endOffsetVal = endOffset ?? Number.MAX_SAFE_INTEGER;\n\t\twhile (index < this.offsets.length && endOffsetVal >= this.offsets[index]) {\n\t\t\tattributionKey = this.get(index);\n\t\t\tif (attributionKey !== undefined) {\n\t\t\t\tresult.push({ offset: this.offsets[index], key: attributionKey });\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\treturn result;\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 ?? 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\t// Null is needed as null and undefined have different meanings in the context of attribution collections.\n\t\t\t\t\t// eslint-disable-next-line unicorn/no-null\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\t// eslint-disable-next-line unicorn/no-null\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\ttype ExtractGeneric<T> = T extends Iterable<infer Q> ? Q : unknown;\n\t\tconst root: ExtractGeneric<IAttributionCollectionSpec<AttributionKey>[\"root\"]>[] =\n\t\t\tArray.from({ length: this.keys.length });\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];\n\t\tcopy.offsets = [...this.offsets];\n\t\tif (this.channels !== undefined) {\n\t\t\tconst channelsCopy: Record<string, AttributionCollection> = {};\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): void {\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] = channel;\n\t\t\t} else {\n\t\t\t\tthis.channels[name]?.update(undefined, 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\t// Destructuring here would require renaming the variables, since seqs is declared below\n\t\t\t// eslint-disable-next-line unicorn/consistent-destructuring\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): void => {\n\t\t\tif (seqs.length === 0) {\n\t\t\t\tassert(\n\t\t\t\t\tposBreakpoints.length === 0,\n\t\t\t\t\t0x9e1 /* seqs and posBreakpoints length should match */,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\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\t// This function is defined here to allow for the creation of a new collection for each segment.\n\t\t\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\t\t\tconst pushEntry = (offset: number, seq: AttributionKey | number | null): void => {\n\t\t\t\t\tattribution.offsets.push(offset);\n\t\t\t\t\tattribution.keys.push(\n\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-null\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\tif (segment.attribution !== undefined) {\n\t\t\t\t\t\t// Cast is valid as we just assigned this field above\n\t\t\t\t\t\t((segment.attribution as AttributionCollection).channels ??= {})[name] =\n\t\t\t\t\t\t\tcollection;\n\t\t\t\t\t}\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\t// eslint-disable-next-line unicorn/no-null\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\t// eslint-disable-next-line unicorn/no-null\n\t\t\t\t\t\tseqs.push(key ? (key.type === \"op\" ? key.seq : key) : null);\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// eslint-disable-next-line unicorn/no-null\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,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAM9E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAiItE,gDAAgD;AAChD,MAAM,UAAU,uBAAuB;AACtC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C,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;oBAC7D,CAAC;oBACD,wBAAwB,GAAG,GAAG,CAAC;gBAChC,CAAC;gBAED,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC;YAC9B,CAAC;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,CAAC;YAC9B,MAAM,QAAQ,GAAwC,EAAE,CAAC;YACzD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;gBACpC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,sBAAsB;gBACtD,2CAA2C;gBAC3C,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;YAC3C,CAAC;YACD,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAClC,CAAC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;CACD","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/internal\";\nimport type {\n\tAttributionKey,\n\tDetachedAttributionKey,\n\tOpAttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ISegment } from \"./mergeTreeNodes.js\";\n\n/**\n * @legacy @beta\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\t// eslint-disable-next-line @rushstack/no-new-null\n\tseqs: (number | AttributionKey | null)[];\n\tposBreakpoints: number[];\n}\n\n/**\n * @legacy @beta\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 * @legacy @beta\n */\nexport interface IAttributionCollectionSpec<T> {\n\t// eslint-disable-next-line @rushstack/no-new-null\n\troot: Iterable<{ offset: number; key: T | null }>;\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tchannels?: { [name: string]: Iterable<{ offset: number; key: T | null }> };\n\tlength: number;\n}\n\n/**\n * @legacy @beta\n * @sealed\n */\nexport interface IAttributionCollectionSerializer {\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 */\n\tpopulateAttributionCollections(\n\t\tsegments: Iterable<ISegment>,\n\t\tsummary: SerializedAttributionCollection,\n\t): void;\n}\n\n/**\n * @legacy @beta\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 * Retrieves all the [Offset, Attribution key] pairs for the provided offset range. Note:\n\t * The returned array is sorted by offset.\n\t * The first offset in response could be lower than the startOffset as the Attribution Key for the startOffset\n\t * could start at a lower offset than the startOffset in case where Attribution key offset boundaries don't\n\t * align exactly with startOffset.\n\t * Example: If the Attribution Offsets in the segment is [0, 10, 20, 30, 40] and request is for (startOffset: 5, endOffset: 25),\n\t * then result would be [(offset: 0, key: key1), (offset:10, key: key2), (offset:20, key: key3)].\n\t * @param channel - When specified, gets attribution keys associated with a particular channel.\n\t * @returns undefined if the provided channel is not found or list of attribution keys along with\n\t * the corresponding offset start boundary.\n\t */\n\tgetKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t\tchannel?: string,\n\t): { offset: number; key: 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 */\n\tgetAll(): IAttributionCollectionSpec<T>;\n\n\t/***/\n\tsplitAt(pos: number): IAttributionCollection<T>;\n\n\t/***/\n\tappend(other: IAttributionCollection<T>): void;\n\n\t/***/\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 */\n\tupdate(name: string | undefined, channel: IAttributionCollection<T>): void;\n}\n\n// note: treats null and undefined as equivalent\nexport function areEqualAttributionKeys(\n\t// eslint-disable-next-line @rushstack/no-new-null\n\ta: AttributionKey | null | undefined,\n\t// eslint-disable-next-line @rushstack/no-new-null\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\t}\n\t\tcase \"detached\": {\n\t\t\treturn a.id === (b as DetachedAttributionKey).id;\n\t\t}\n\t\tcase \"local\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\tunreachableCase(a, \"Unhandled AttributionKey type\");\n\t\t}\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(\n\t\tprivate _length: number,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tbaseEntry?: AttributionKey | null,\n\t) {\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\tpublic getKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t): { offset: number; key: AttributionKey }[];\n\tpublic getKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t\tchannel?: string,\n\t): { offset: number; key: AttributionKey }[] | undefined;\n\tpublic getKeysInOffsetRange(\n\t\tstartOffset: number,\n\t\tendOffset?: number,\n\t\tchannel?: string,\n\t): { offset: number; key: AttributionKey }[] | undefined {\n\t\tif (startOffset < 0 || startOffset >= this._length) {\n\t\t\tthrow new UsageError(\"startOffset should be valid and in range\");\n\t\t}\n\t\tif (\n\t\t\tendOffset !== undefined &&\n\t\t\t(endOffset < 0 || endOffset >= this._length || startOffset > endOffset)\n\t\t) {\n\t\t\tthrow new UsageError(\"endOffset should be valid and in range\");\n\t\t}\n\n\t\tif (channel !== undefined) {\n\t\t\tconst subCollection = this.channels?.[channel];\n\t\t\treturn subCollection?.getKeysInOffsetRange(startOffset, endOffset);\n\t\t}\n\t\tconst result: { offset: number; key: AttributionKey }[] = [];\n\t\tlet index = this.findIndex(startOffset);\n\t\tlet attributionKey = this.get(index);\n\t\tif (attributionKey !== undefined) {\n\t\t\tresult.push({ offset: this.offsets[index], key: attributionKey });\n\t\t}\n\t\tindex++;\n\t\tconst endOffsetVal = endOffset ?? Number.MAX_SAFE_INTEGER;\n\t\twhile (index < this.offsets.length && endOffsetVal >= this.offsets[index]) {\n\t\t\tattributionKey = this.get(index);\n\t\t\tif (attributionKey !== undefined) {\n\t\t\t\tresult.push({ offset: this.offsets[index], key: attributionKey });\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\treturn result;\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 ?? 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\t// Null is needed as null and undefined have different meanings in the context of attribution collections.\n\t\t\t\t\t// eslint-disable-next-line unicorn/no-null\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\t// eslint-disable-next-line unicorn/no-null\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\ttype ExtractGeneric<T> = T extends Iterable<infer Q> ? Q : unknown;\n\t\tconst root: ExtractGeneric<IAttributionCollectionSpec<AttributionKey>[\"root\"]>[] =\n\t\t\tArray.from({ length: this.keys.length });\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];\n\t\tcopy.offsets = [...this.offsets];\n\t\tif (this.channels !== undefined) {\n\t\t\tconst channelsCopy: Record<string, AttributionCollection> = {};\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): void {\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] = channel;\n\t\t\t} else {\n\t\t\t\tthis.channels[name]?.update(undefined, 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\t// Destructuring here would require renaming the variables, since seqs is declared below\n\t\t\t// eslint-disable-next-line unicorn/consistent-destructuring\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): void => {\n\t\t\tif (seqs.length === 0) {\n\t\t\t\tassert(\n\t\t\t\t\tposBreakpoints.length === 0,\n\t\t\t\t\t0x9e1 /* seqs and posBreakpoints length should match */,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\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\t// This function is defined here to allow for the creation of a new collection for each segment.\n\t\t\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\t\t\tconst pushEntry = (offset: number, seq: AttributionKey | number | null): void => {\n\t\t\t\t\tattribution.offsets.push(offset);\n\t\t\t\t\tattribution.keys.push(\n\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-null\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\tif (segment.attribution !== undefined) {\n\t\t\t\t\t\t// Cast is valid as we just assigned this field above\n\t\t\t\t\t\t((segment.attribution as AttributionCollection).channels ??= {})[name] =\n\t\t\t\t\t\t\tcollection;\n\t\t\t\t\t}\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\t// eslint-disable-next-line unicorn/no-null\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\t// eslint-disable-next-line unicorn/no-null\n\t\t\t\t\t\tseqs.push(key ? (key.type === \"op\" ? key.seq : key) : null);\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// eslint-disable-next-line unicorn/no-null\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"]}
@@ -205,7 +205,7 @@ export declare class MergeTree {
205
205
  makeBlock(childCount: number): MergeBlock;
206
206
  /**
207
207
  * Compute the net length of this segment leaf from some perspective.
208
- * @returns - Undefined if the segment has been removed and its removal is common knowledge to all collaborators (and therefore
208
+ * @returns Undefined if the segment has been removed and its removal is common knowledge to all collaborators (and therefore
209
209
  * may not even be present on clients that have loaded from a summary beyond this point). Otherwise, the length of the segment.
210
210
  */
211
211
  leafLength(segment: ISegmentLeaf, perspective?: Perspective): number | undefined;
package/lib/mergeTree.js CHANGED
@@ -355,7 +355,7 @@ export class MergeTree {
355
355
  }
356
356
  /**
357
357
  * Compute the net length of this segment leaf from some perspective.
358
- * @returns - Undefined if the segment has been removed and its removal is common knowledge to all collaborators (and therefore
358
+ * @returns Undefined if the segment has been removed and its removal is common knowledge to all collaborators (and therefore
359
359
  * may not even be present on clients that have loaded from a summary beyond this point). Otherwise, the length of the segment.
360
360
  */
361
361
  leafLength(segment, perspective = this.localPerspective) {