@fluidframework/merge-tree 2.82.0 → 2.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/attributionCollection.d.ts.map +1 -1
- package/dist/attributionCollection.js +1 -4
- package/dist/attributionCollection.js.map +1 -1
- package/dist/mergeTreeDeltaCallback.js.map +1 -1
- package/dist/mergeTreeNodeWalk.d.ts.map +1 -1
- package/dist/mergeTreeNodeWalk.js +0 -1
- package/dist/mergeTreeNodeWalk.js.map +1 -1
- package/dist/segmentPropertiesManager.d.ts.map +1 -1
- package/dist/segmentPropertiesManager.js +0 -1
- package/dist/segmentPropertiesManager.js.map +1 -1
- package/lib/attributionCollection.d.ts.map +1 -1
- package/lib/attributionCollection.js +1 -4
- package/lib/attributionCollection.js.map +1 -1
- package/lib/mergeTreeDeltaCallback.js.map +1 -1
- package/lib/mergeTreeNodeWalk.d.ts.map +1 -1
- package/lib/mergeTreeNodeWalk.js +0 -1
- package/lib/mergeTreeNodeWalk.js.map +1 -1
- package/lib/segmentPropertiesManager.d.ts.map +1 -1
- package/lib/segmentPropertiesManager.js +0 -1
- package/lib/segmentPropertiesManager.js.map +1 -1
- package/package.json +17 -17
- package/src/attributionCollection.ts +0 -2
- package/src/mergeTreeDeltaCallback.ts +1 -1
- package/src/mergeTreeNodeWalk.ts +0 -1
- package/src/segmentPropertiesManager.ts +0 -1
- package/api-extractor-lint.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributionCollection.d.ts","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,cAAc,EAGd,MAAM,8CAA8C,CAAC;AAGtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;OAWG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cAAc,GAAG,SAAS;IAUxE,oBAAoB,CAC1B,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GAChB;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,cAAc,CAAA;KAAE,EAAE;IACrC,oBAAoB,CAC1B,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GACd;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,cAAc,CAAA;KAAE,EAAE,GAAG,SAAS;IAsCxD,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,GAAG;IAKX,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB;IAsB3C,MAAM,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI;IA8B1C,MAAM,IAAI,0BAA0B,CAAC,cAAc,CAAC;IAoBpD,KAAK,IAAI,qBAAqB;IAc9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAkB7E;;OAEG;WACW,8BAA8B,CAC3C,QAAQ,EAAE,QAAQ,EAAE,EACpB,OAAO,EAAE,+BAA+B,GACtC,IAAI;IAmEP;;;;;OAKG;WACW,+BAA+B,CAC5C,QAAQ,EAAE,QAAQ,CAAC;QAClB,WAAW,CAAC,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;QACrD,YAAY,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,+BAA+B;CAiElC"}
|
|
@@ -210,10 +210,7 @@ class AttributionCollection {
|
|
|
210
210
|
*/
|
|
211
211
|
static populateAttributionCollections(segments, summary) {
|
|
212
212
|
const { channels } = summary;
|
|
213
|
-
(0, internal_1.assert)(
|
|
214
|
-
// Destructuring here would require renaming the variables, since seqs is declared below
|
|
215
|
-
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
216
|
-
summary.seqs.length === summary.posBreakpoints.length, 0x445 /* Invalid attribution summary blob provided */);
|
|
213
|
+
(0, internal_1.assert)(summary.seqs.length === summary.posBreakpoints.length, 0x445 /* Invalid attribution summary blob provided */);
|
|
217
214
|
const extractOntoSegments = ({ seqs, posBreakpoints }, assignToSegment) => {
|
|
218
215
|
if (seqs.length === 0) {
|
|
219
216
|
(0, internal_1.assert)(posBreakpoints.length === 0, 0x9e1 /* seqs and posBreakpoints length should match */);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributionCollection.js","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAM9E,uEAAsE;AAiItE,gDAAgD;AAChD,SAAgB,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,CAAC;IAED,gGAAgG;IAChG,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,CAAC,CAAC;YACX,OAAO,CAAC,CAAC,GAAG,KAAM,CAAsB,CAAC,GAAG,CAAC;QAC9C,CAAC;QACD,KAAK,UAAU,CAAC,CAAC,CAAC;YACjB,OAAO,CAAC,CAAC,EAAE,KAAM,CAA4B,CAAC,EAAE,CAAC;QAClD,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,IAAA,0BAAe,EAAC,CAAC,EAAE,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I,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;AAxWD,sDAwWC","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,kEAA8E;AAM9E,uEAAsE;AAiItE,gDAAgD;AAChD,SAAgB,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,CAAC;IAED,gGAAgG;IAChG,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,CAAC,CAAC;Y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,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;AAtWD,sDAsWC","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\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 +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-x/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-x/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
|
|
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-x/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-x/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\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeNodeWalk.d.ts","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGhF,eAAO,MAAM,UAAU;;CAEb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;AAEpD,eAAO,MAAM,UAAU;;;;CAKb,CAAC;AAGX,MAAM,MAAM,UAAU,GACnB,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,GAC5C,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,EAC7C,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,UAAU,EACtD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACtC,OAAO,GAAE,OAAc,GACrB,OAAO,
|
|
1
|
+
{"version":3,"file":"mergeTreeNodeWalk.d.ts","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGhF,eAAO,MAAM,UAAU;;CAEb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;AAEpD,eAAO,MAAM,UAAU;;;;CAKb,CAAC;AAGX,MAAM,MAAM,UAAU,GACnB,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,GAC5C,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,EAC7C,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,UAAU,EACtD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACtC,OAAO,GAAE,OAAc,GACrB,OAAO,CAwET;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,GAAG,SAAS,GACpD,OAAO,CAcT;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,GAAG,SAAS,GACpD,OAAO,CAeT;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,GAAG,SAAS,GAAG,IAAI,GAC/D,OAAO,CAqBT"}
|
|
@@ -35,7 +35,6 @@ function depthFirstNodeWalk(startBlock, startChild, downAction, leafActionOverri
|
|
|
35
35
|
let block = startBlock;
|
|
36
36
|
let childCount = block.childCount;
|
|
37
37
|
let start = startChild;
|
|
38
|
-
// eslint-disable-next-line no-constant-condition
|
|
39
38
|
while (true) {
|
|
40
39
|
// go down to the leaf level
|
|
41
40
|
let blockResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeNodeWalk.js","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,uDAAoD;AAEvC,QAAA,UAA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U,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACvE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,kBAAkB,CACxB,UAAU,EACV,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EACtB,SAAS,CAAC,IAAI,KAAK,CAAC;QACnB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,IAAI,EAAqB,EAAE,CAC5B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAU,CAAC,QAAQ,EACrE,UAAU,CACV,CAAC;AACH,CAAC;AAxBD,oDAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISegmentLeaf, MergeBlock, IMergeNode } from \"./mergeTreeNodes.js\";\nimport { isMergeNodeInfo } from \"./segmentInfos.js\";\n\nexport const LeafAction = {\n\tExit: false,\n} as const;\n\nexport type LeafAction = boolean | undefined | void;\n\nexport const NodeAction = {\n\tContinue: undefined,\n\t// exit is false to unify with leafActionOverride\n\tExit: LeafAction.Exit,\n\tSkip: 2,\n} as const;\n\n// we exclude true from, as we only want one continue value, undefined\nexport type NodeAction =\n\t| (typeof NodeAction)[keyof typeof NodeAction]\n\t| Exclude<LeafAction, true>;\n\n/**\n * Does a depth first walk of the tree from the specific start.\n *\n * @param startBlock - The block of the tree to start the walk from\n * @param startChild - The child of that block to start from\n * @param downAction - Called as we walk down the tree to the leaves.\n * @param leafActionOverride - Overrides downAction for leaves, generally used without downAction\n * @param upAction - Called after all the children of a block are walked.\n * @param forward - whether to walk forward or backward\n * @returns true if we naturally exit, false if exiting due to Exit action result\n */\nexport function depthFirstNodeWalk(\n\tstartBlock: MergeBlock,\n\tstartChild: IMergeNode | undefined,\n\tdownAction?: (node: IMergeNode) => NodeAction,\n\tleafActionOverride?: (seg: ISegmentLeaf) => LeafAction,\n\tupAction?: (block: MergeBlock) => void,\n\tforward: boolean = true,\n): boolean {\n\tconst increment = forward ? 1 : -1;\n\tconst leafAction = leafActionOverride ?? downAction;\n\tif (leafAction === undefined) {\n\t\treturn true;\n\t}\n\n\tlet block = startBlock;\n\tlet childCount = block.childCount;\n\tlet start: IMergeNode | undefined = startChild;\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\t// go down to the leaf level\n\t\tlet blockResult: NodeAction;\n\t\twhile (start?.isLeaf() === false) {\n\t\t\t// cast is safe due to isLeaf === false in while above\n\t\t\tblock = start as MergeBlock;\n\t\t\tchildCount = block.childCount;\n\t\t\tblockResult = downAction?.(block);\n\t\t\t// setting start undefined will skip the leaf walk\n\t\t\t// so if the block result isn't continue, set it\n\t\t\t// undefined\n\t\t\tstart =\n\t\t\t\tblockResult === NodeAction.Continue\n\t\t\t\t\t? block.children[forward ? 0 : childCount - 1]\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tlet exit = blockResult === NodeAction.Exit;\n\n\t\t// walk the leaves if we reached them\n\t\tif (start !== undefined) {\n\t\t\tfor (let i = start.index; i !== -1 && i !== childCount; i += increment) {\n\t\t\t\t// the above loop ensures start is a leaf or undefined, so all children\n\t\t\t\t// will be leaves if start exits, so the cast is safe\n\t\t\t\tif (leafAction(block.children[i] as ISegmentLeaf) === LeafAction.Exit) {\n\t\t\t\t\texit = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if there is no upAction, we don't need to walk up before exiting\n\t\tif (upAction === undefined && exit) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// since we already enumerated the children\n\t\t// we walk up to the next level until there is a sibling\n\t\t// or all the way up if exit is true\n\t\tlet nextIndex = -1;\n\t\tdo {\n\t\t\t// if the blockAction was exit or skip\n\t\t\t// we shouldn't process that block again,\n\t\t\t// if there are subsequent parents while walking up\n\t\t\t// we will process those.\n\t\t\tif (blockResult === NodeAction.Continue) {\n\t\t\t\tupAction?.(block);\n\t\t\t} else {\n\t\t\t\tblockResult = NodeAction.Continue;\n\t\t\t}\n\t\t\tif (block.parent === undefined) {\n\t\t\t\treturn !exit;\n\t\t\t}\n\t\t\tstart = block;\n\t\t\tblock = block.parent;\n\t\t\tchildCount = block.childCount;\n\t\t\tnextIndex = start.index + increment;\n\t\t} while (exit || nextIndex === -1 || nextIndex === childCount);\n\t\t// the above loop ensured that siblings are possible\n\t\tstart = block.children[nextIndex];\n\t}\n}\n\n/**\n * Visit segments starting from node's right/far/forward siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function forwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index + 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t);\n}\n\n/**\n * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function backwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index - 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t\tundefined /* upAction */,\n\t\tfalse /* forward */,\n\t);\n}\n\n/**\n * Walks all segments below the specific start block\n * @param startBlock - The block to start the walk at\n * @param leafAction - The action to perform on the leaves\n * @returns true if we naturally exit, false if exiting due to leaf action result\n */\nexport function walkAllChildSegments(\n\tstartBlock: MergeBlock,\n\tleafAction: (segment: ISegmentLeaf) => boolean | undefined | void,\n): boolean {\n\tif (startBlock.childCount === 0) {\n\t\treturn true;\n\t}\n\n\t// undefined shouldn't actually be added, but this allows subsequent check for `node.parent` to typecheck\n\t// without further runtime work.\n\tconst ancestors = new Set<MergeBlock | undefined>();\n\tfor (let cur = startBlock.parent; cur !== undefined; cur = cur.parent) {\n\t\tancestors.add(cur);\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartBlock,\n\t\tstartBlock.children[0],\n\t\tancestors.size === 0\n\t\t\t? undefined\n\t\t\t: (node): false | undefined =>\n\t\t\t\t\tancestors.has(node.parent) ? NodeAction.Exit : NodeAction.Continue,\n\t\tleafAction,\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mergeTreeNodeWalk.js","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,uDAAoD;AAEvC,QAAA,UAAU,GAAG;IACzB,IAAI,EAAE,KAAK;CACF,CAAC;AAIE,QAAA,UAAU,GAAG;IACzB,QAAQ,EAAE,SAAS;IACnB,iDAAiD;IACjD,IAAI,EAAE,kBAAU,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC;CACE,CAAC;AAOX;;;;;;;;;;GAUG;AACH,SAAgB,kBAAkB,CACjC,UAAsB,EACtB,UAAkC,EAClC,UAA6C,EAC7C,kBAAsD,EACtD,QAAsC,EACtC,UAAmB,IAAI;IAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,kBAAkB,IAAI,UAAU,CAAC;IACpD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,KAAK,GAAG,UAAU,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sD;IAEtD,IAAI,CAAC,IAAA,iCAAe,EAAC,SAAS,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,kBAAkB,CACxB,SAAS,CAAC,MAAM;IAChB,gDAAgD;IAChD,8CAA8C;IAC9C,qBAAqB;IACrB,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,EAC9C,SAAS,CAAC,gBAAgB,EAC1B,UAAU,EACV,SAAS,CAAC,cAAc,EACxB,KAAK,CAAC,aAAa,CACnB,CAAC;AACH,CAAC;AAlBD,8CAkBC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CACnC,UAAsB,EACtB,UAAiE;IAEjE,IAAI,UAAU,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,yGAAyG;IACzG,gCAAgC;IAChC,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IACpD,KAAK,IAAI,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACvE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,kBAAkB,CACxB,UAAU,EACV,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EACtB,SAAS,CAAC,IAAI,KAAK,CAAC;QACnB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,IAAI,EAAqB,EAAE,CAC5B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAU,CAAC,QAAQ,EACrE,UAAU,CACV,CAAC;AACH,CAAC;AAxBD,oDAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISegmentLeaf, MergeBlock, IMergeNode } from \"./mergeTreeNodes.js\";\nimport { isMergeNodeInfo } from \"./segmentInfos.js\";\n\nexport const LeafAction = {\n\tExit: false,\n} as const;\n\nexport type LeafAction = boolean | undefined | void;\n\nexport const NodeAction = {\n\tContinue: undefined,\n\t// exit is false to unify with leafActionOverride\n\tExit: LeafAction.Exit,\n\tSkip: 2,\n} as const;\n\n// we exclude true from, as we only want one continue value, undefined\nexport type NodeAction =\n\t| (typeof NodeAction)[keyof typeof NodeAction]\n\t| Exclude<LeafAction, true>;\n\n/**\n * Does a depth first walk of the tree from the specific start.\n *\n * @param startBlock - The block of the tree to start the walk from\n * @param startChild - The child of that block to start from\n * @param downAction - Called as we walk down the tree to the leaves.\n * @param leafActionOverride - Overrides downAction for leaves, generally used without downAction\n * @param upAction - Called after all the children of a block are walked.\n * @param forward - whether to walk forward or backward\n * @returns true if we naturally exit, false if exiting due to Exit action result\n */\nexport function depthFirstNodeWalk(\n\tstartBlock: MergeBlock,\n\tstartChild: IMergeNode | undefined,\n\tdownAction?: (node: IMergeNode) => NodeAction,\n\tleafActionOverride?: (seg: ISegmentLeaf) => LeafAction,\n\tupAction?: (block: MergeBlock) => void,\n\tforward: boolean = true,\n): boolean {\n\tconst increment = forward ? 1 : -1;\n\tconst leafAction = leafActionOverride ?? downAction;\n\tif (leafAction === undefined) {\n\t\treturn true;\n\t}\n\n\tlet block = startBlock;\n\tlet childCount = block.childCount;\n\tlet start: IMergeNode | undefined = startChild;\n\n\twhile (true) {\n\t\t// go down to the leaf level\n\t\tlet blockResult: NodeAction;\n\t\twhile (start?.isLeaf() === false) {\n\t\t\t// cast is safe due to isLeaf === false in while above\n\t\t\tblock = start as MergeBlock;\n\t\t\tchildCount = block.childCount;\n\t\t\tblockResult = downAction?.(block);\n\t\t\t// setting start undefined will skip the leaf walk\n\t\t\t// so if the block result isn't continue, set it\n\t\t\t// undefined\n\t\t\tstart =\n\t\t\t\tblockResult === NodeAction.Continue\n\t\t\t\t\t? block.children[forward ? 0 : childCount - 1]\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tlet exit = blockResult === NodeAction.Exit;\n\n\t\t// walk the leaves if we reached them\n\t\tif (start !== undefined) {\n\t\t\tfor (let i = start.index; i !== -1 && i !== childCount; i += increment) {\n\t\t\t\t// the above loop ensures start is a leaf or undefined, so all children\n\t\t\t\t// will be leaves if start exits, so the cast is safe\n\t\t\t\tif (leafAction(block.children[i] as ISegmentLeaf) === LeafAction.Exit) {\n\t\t\t\t\texit = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if there is no upAction, we don't need to walk up before exiting\n\t\tif (upAction === undefined && exit) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// since we already enumerated the children\n\t\t// we walk up to the next level until there is a sibling\n\t\t// or all the way up if exit is true\n\t\tlet nextIndex = -1;\n\t\tdo {\n\t\t\t// if the blockAction was exit or skip\n\t\t\t// we shouldn't process that block again,\n\t\t\t// if there are subsequent parents while walking up\n\t\t\t// we will process those.\n\t\t\tif (blockResult === NodeAction.Continue) {\n\t\t\t\tupAction?.(block);\n\t\t\t} else {\n\t\t\t\tblockResult = NodeAction.Continue;\n\t\t\t}\n\t\t\tif (block.parent === undefined) {\n\t\t\t\treturn !exit;\n\t\t\t}\n\t\t\tstart = block;\n\t\t\tblock = block.parent;\n\t\t\tchildCount = block.childCount;\n\t\t\tnextIndex = start.index + increment;\n\t\t} while (exit || nextIndex === -1 || nextIndex === childCount);\n\t\t// the above loop ensured that siblings are possible\n\t\tstart = block.children[nextIndex];\n\t}\n}\n\n/**\n * Visit segments starting from node's right/far/forward siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function forwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index + 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t);\n}\n\n/**\n * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function backwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index - 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t\tundefined /* upAction */,\n\t\tfalse /* forward */,\n\t);\n}\n\n/**\n * Walks all segments below the specific start block\n * @param startBlock - The block to start the walk at\n * @param leafAction - The action to perform on the leaves\n * @returns true if we naturally exit, false if exiting due to leaf action result\n */\nexport function walkAllChildSegments(\n\tstartBlock: MergeBlock,\n\tleafAction: (segment: ISegmentLeaf) => boolean | undefined | void,\n): boolean {\n\tif (startBlock.childCount === 0) {\n\t\treturn true;\n\t}\n\n\t// undefined shouldn't actually be added, but this allows subsequent check for `node.parent` to typecheck\n\t// without further runtime work.\n\tconst ancestors = new Set<MergeBlock | undefined>();\n\tfor (let cur = startBlock.parent; cur !== undefined; cur = cur.parent) {\n\t\tancestors.add(cur);\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartBlock,\n\t\tstartBlock.children[0],\n\t\tancestors.size === 0\n\t\t\t? undefined\n\t\t\t: (node): false | undefined =>\n\t\t\t\t\tancestors.has(node.parent) ? NodeAction.Exit : NodeAction.Continue,\n\t\tleafAction,\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentPropertiesManager.d.ts","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAEX,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,iBAAiB,CAAC;AAEnF;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE;IACP,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,EACD,WAAW,EAAE;IACZ,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,GACC,IAAI,CASN;AAsCD;;GAEG;AACH,MAAM,MAAM,aAAa,GACtB,IAAI,CAAC,2BAA2B,EAAE,OAAO,GAAG,QAAQ,CAAC,GACrD,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"segmentPropertiesManager.d.ts","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAEX,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,iBAAiB,CAAC;AAEnF;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE;IACP,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,EACD,WAAW,EAAE;IACZ,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,GACC,IAAI,CASN;AAsCD;;GAEG;AACH,MAAM,MAAM,aAAa,GACtB,IAAI,CAAC,2BAA2B,EAAE,OAAO,GAAG,QAAQ,CAAC,GACrD,IAAI,CAAC,qB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
|
|
51
51
|
const opToChanges = (op, seq) => [
|
|
52
52
|
...Object.entries(op.props ?? {})
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
54
53
|
.map(([k, raw]) => [k, { raw, seq }])
|
|
55
54
|
.filter(([_, v]) => v.raw !== undefined),
|
|
56
55
|
...Object.entries(op.adjust ?? {}).map(([k, adjust]) => [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentPropertiesManager.js","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAI6C;AAE7C,iDAAmF;AAMnF,mDAAmF;AAEnF;;;GAGG;AACH,SAAgB,wBAAwB,CACvC,MAGC,EACD,WAGC;IAED,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACvB,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YAC1C,WAAW,CAAC,UAAU,GAAG,IAAA,qBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,eAAe,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACxD,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;AACF,CAAC;AAlBD,4DAkBC;AAYD,SAAS,oBAAoB,CAC5B,SAAkB,EAClB,GAAG,OAAmC;IAEtC,IAAI,aAAa,GAAY,SAAS,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC3B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,aAAa,GAAG,GAAG,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACP,MAAM,QAAQ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CAAC,CAAC;aAC/E,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED;;;;;;;;;OASG;IACI,QAAQ,CACd,QAAsC,EACtC,cAAsB;QAEtB,MAAM,UAAU,GAAqB,EAAE,GAAG,QAAQ,EAAE,CAAC;QACrD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3C,UAAU,CAAC,GAAG,CAAC,GAAG,oBAAoB,CACrC,OAAO,CAAC,YAAY,EACpB,IAAA,iCAAsB,EAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,cAAc,CAAC,CACjF,CAAC;YACF,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC9B,gEAAgE;gBAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAkB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACzE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAzOD,8CAyOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tassert,\n\tDoublyLinkedList,\n\titerateListValuesWhile,\n} from \"@fluidframework/core-utils/internal\";\n\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport type {\n\tAdjustParams,\n\tIMergeTreeAnnotateAdjustMsg,\n\tIMergeTreeAnnotateMsg,\n} from \"./ops.js\";\nimport { type MapLike, type PropertySet, clone, createMap } from \"./properties.js\";\n\n/**\n * Minimally copies properties and the property manager from source to destination.\n * @internal\n */\nexport function copyPropertiesAndManager(\n\tsource: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n\tdestination: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n): void {\n\tif (source.properties) {\n\t\tif (source.propertyManager === undefined) {\n\t\t\tdestination.properties = clone(source.properties);\n\t\t} else {\n\t\t\tdestination.propertyManager ??= new PropertiesManager();\n\t\t\tsource.propertyManager.copyTo(source.properties, destination);\n\t\t}\n\t}\n}\n\ntype PropertyChange = {\n\tseq: number;\n} & ({ adjust: AdjustParams; raw?: undefined } | { raw: unknown; adjust?: undefined });\n\ninterface PropertyChanges {\n\tmsnConsensus: unknown;\n\tremote: DoublyLinkedList<PropertyChange>;\n\tlocal: DoublyLinkedList<PropertyChange>;\n}\n\nfunction computePropertyValue(\n\tconsensus: unknown,\n\t...changes: Iterable<PropertyChange>[]\n): unknown {\n\tlet computedValue: unknown = consensus;\n\tfor (const change of changes) {\n\t\tfor (const op of change) {\n\t\t\tconst { raw, adjust } = op;\n\t\t\tif (adjust === undefined) {\n\t\t\t\tcomputedValue = raw;\n\t\t\t} else {\n\t\t\t\tconst adjusted =\n\t\t\t\t\t(typeof computedValue === \"number\" ? computedValue : 0) + adjust.delta;\n\t\t\t\tif (adjust.max !== undefined && adjusted > adjust.max) {\n\t\t\t\t\tcomputedValue = adjust.max;\n\t\t\t\t} else if (adjust.min !== undefined && adjusted < adjust.min) {\n\t\t\t\t\tcomputedValue = adjust.min;\n\t\t\t\t} else {\n\t\t\t\t\tcomputedValue = adjusted;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn computedValue;\n}\n\n/**\n * @internal\n */\nexport type PropsOrAdjust =\n\t| Pick<IMergeTreeAnnotateAdjustMsg, \"props\" | \"adjust\">\n\t| Pick<IMergeTreeAnnotateMsg, \"props\" | \"adjust\">;\n\nconst opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [\n\t...Object.entries(op.props ?? {})\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])\n\t\t.filter(([_, v]) => v.raw !== undefined),\n\t...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [\n\t\tk,\n\t\t{ adjust, seq },\n\t]),\n];\n\nfunction applyChanges(\n\top: PropsOrAdjust,\n\tseg: { properties?: MapLike<unknown> },\n\tseq: number,\n\trun: (\n\t\tproperties: MapLike<unknown>,\n\t\tdeltas: MapLike<unknown>,\n\t\tkey: string,\n\t\tvalue: PropertyChange,\n\t) => void,\n): MapLike<unknown> {\n\tconst properties = (seg.properties ??= createMap<unknown>());\n\tconst deltas: MapLike<unknown> = {};\n\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\trun(properties, deltas, key, value);\n\t\tif (properties[key] === null) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete properties[key];\n\t\t}\n\t}\n\treturn deltas;\n}\n\n/**\n * The PropertiesManager class handles changes to properties, both remote and local.\n * It manages the lifecycle for local property changes, ensures all property changes are eventually consistent,\n * and provides methods to acknowledge changes, update the minimum sequence number (msn), and copy properties to another manager.\n * This class is essential for maintaining the integrity and consistency of property changes in collaborative environments.\n * @internal\n */\nexport class PropertiesManager {\n\tprivate readonly changes = new Map<string, PropertyChanges>();\n\n\t/**\n\t * Rolls back local property changes.\n\t * This method reverts property changes based on the provided operation and segment.\n\t * If the operation is part of a collaborative session, it ensures that the changes are consistent with the remote state.\n\t *\n\t * @param op - The operation containing property changes. This can be an adjustment or a set of properties.\n\t * @param seg - The segment containing properties. This object may have a properties map that will be modified.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @returns The deltas of the rolled-back properties. This is a map-like object representing the changes that were reverted.\n\t */\n\tpublic rollbackProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tcollaborating: boolean = false,\n\t): MapLike<unknown> {\n\t\treturn applyChanges(op, seg, UniversalSequenceNumber, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\n\t\t\tconst pending = this.changes.get(key);\n\t\t\tif (collaborating) {\n\t\t\t\tassert(\n\t\t\t\t\tpending !== undefined,\n\t\t\t\t\t0xa6f /* Pending changes must exist for rollback when collaborating */,\n\t\t\t\t);\n\t\t\t\tpending.local.pop();\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\t\tthis.changes.delete(key);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tpending === undefined,\n\t\t\t\t\t0xa70 /* Pending changes must not exist when not collaborating */,\n\t\t\t\t);\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t}\n\t\t\tdeltas[key] = previousValue;\n\t\t});\n\t}\n\n\t/**\n\t * Handles property changes.\n\t * This method applies property changes based on the provided operation, segment, sequence number, and collaboration state.\n\t * It also handles rolling back changes if specified.\n\t *\n\t * @param op - The operation containing property changes.\n\t * @param seg - The segment containing properties.\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.\n\t * @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.\n\t */\n\tpublic handleProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tseq: number,\n\t\tmsn: number,\n\t\tcollaborating: boolean = false,\n\t\trollback: boolean = false,\n\t): MapLike<unknown> {\n\t\tif (rollback) {\n\t\t\treturn this.rollbackProperties(op, seg, collaborating);\n\t\t}\n\t\tconst rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\t\t\tif (collaborating) {\n\t\t\t\tconst pending: PropertyChanges | undefined = this.changes.get(key) ?? {\n\t\t\t\t\tmsnConsensus: previousValue,\n\t\t\t\t\tremote: new DoublyLinkedList(),\n\t\t\t\t\tlocal: new DoublyLinkedList(),\n\t\t\t\t};\n\t\t\t\tthis.changes.set(key, pending);\n\t\t\t\tconst local = seq === UnassignedSequenceNumber;\n\t\t\t\tif (local) {\n\t\t\t\t\tpending.local.push(value);\n\t\t\t\t} else {\n\t\t\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\t\t\tif (value.raw !== undefined && pending.remote.empty) {\n\t\t\t\t\t\tpending.msnConsensus = computePropertyValue(pending.msnConsensus, [value]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpending.remote.push(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (local || pending.local.empty || properties[key] !== previousValue) {\n\t\t\t\t\tdeltas[key] = previousValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t\tdeltas[key] = previousValue;\n\t\t\t}\n\t\t});\n\t\tthis.updateMsn(msn);\n\t\treturn rtn;\n\t}\n\n\t/**\n\t * Acknowledges property changes.\n\t * This method acknowledges the property changes based on the provided sequence number and operation.\n\t *\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param op - The operation containing property changes.\n\t */\n\tpublic ack(seq: number, msn: number, op: PropsOrAdjust): void {\n\t\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\t\tconst change = this.changes.get(key);\n\t\t\tconst acked = change?.local?.shift();\n\t\t\tassert(\n\t\t\t\tchange !== undefined && acked !== undefined,\n\t\t\t\t0xa71 /* must have local change to ack */,\n\t\t\t);\n\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\tif (value.raw !== undefined && change.remote.empty) {\n\t\t\t\tchange.msnConsensus = computePropertyValue(change.msnConsensus, [value]);\n\t\t\t} else {\n\t\t\t\tchange.remote.push(value);\n\t\t\t}\n\t\t}\n\t\tthis.updateMsn(msn);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number (msn).\n\t * This method updates the minimum sequence number and removes any changes that have been acknowledged.\n\t *\n\t * @param msn - The minimum sequence number to update.\n\t */\n\tpublic updateMsn(msn: number): void {\n\t\tfor (const [key, pending] of this.changes) {\n\t\t\tpending.msnConsensus = computePropertyValue(\n\t\t\t\tpending.msnConsensus,\n\t\t\t\titerateListValuesWhile(pending.remote.first, (n) => {\n\t\t\t\t\tif (n.data.seq <= msn) {\n\t\t\t\t\t\tn.list?.remove(n);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\tthis.changes.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copies properties to another manager.\n\t * This method copies the properties and their changes from the current manager to the destination manager.\n\t *\n\t * @param oldProps - The old properties to be copied.\n\t * @param dest - The destination object containing properties and property manager.\n\t */\n\tpublic copyTo(\n\t\toldProps: PropertySet | undefined,\n\t\tdest: {\n\t\t\tproperties?: PropertySet;\n\t\t\tpropertyManager?: PropertiesManager;\n\t\t},\n\t): void {\n\t\tconst newManager = (dest.propertyManager ??= new PropertiesManager());\n\t\tdest.properties = clone(oldProps);\n\t\tfor (const [key, { local, remote, msnConsensus }] of this.changes.entries()) {\n\t\t\tnewManager.changes.set(key, {\n\t\t\t\tmsnConsensus,\n\t\t\t\tremote: new DoublyLinkedList(remote.empty ? undefined : remote.map((c) => c.data)),\n\t\t\t\tlocal: new DoublyLinkedList(local.empty ? undefined : local.map((c) => c.data)),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Gets properties at a specific sequence number.\n\t * This method retrieves the properties at the given sequence number.\n\t * This is only needed to support emitting snapshots in the legacy format.\n\t * If we remove the ability to emit the legacy format, we can remove this method, along with the need to track remote changes at all.\n\t *\n\t * @param oldProps - The old properties to be retrieved.\n\t * @param sequenceNumber - The sequence number to get properties at.\n\t * @returns The properties at the given sequence number.\n\t */\n\tpublic getAtSeq(\n\t\toldProps: MapLike<unknown> | undefined,\n\t\tsequenceNumber: number,\n\t): MapLike<unknown> {\n\t\tconst properties: MapLike<unknown> = { ...oldProps };\n\t\tfor (const [key, changes] of this.changes) {\n\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\tchanges.msnConsensus,\n\t\t\t\titerateListValuesWhile(changes.remote.first, (c) => c.data.seq <= sequenceNumber),\n\t\t\t);\n\t\t\tif (properties[key] === null) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete properties[key];\n\t\t\t}\n\t\t}\n\t\treturn properties;\n\t}\n\n\t/**\n\t * Determines if all of the defined properties in a given property set are pending.\n\t *\n\t * @param props - The properties to check.\n\t * @returns True if all the properties are pending, false otherwise.\n\t */\n\tpublic hasPendingProperties(props: PropertySet): boolean {\n\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\tif (value !== undefined && this.changes.get(key)?.local.empty !== false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"segmentPropertiesManager.js","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAI6C;AAE7C,iDAAmF;AAMnF,mDAAmF;AAEnF;;;GAGG;AACH,SAAgB,wBAAwB,CACvC,MAGC,EACD,WAGC;IAED,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACvB,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YAC1C,WAAW,CAAC,UAAU,GAAG,IAAA,qBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,eAAe,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACxD,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;AACF,CAAC;AAlBD,4DAkBC;AAYD,SAAS,oBAAoB,CAC5B,SAAkB,EAClB,GAAG,OAAmC;IAEtC,IAAI,aAAa,GAAY,SAAS,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC3B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,aAAa,GAAG,GAAG,CAAC;YACrB,CAAC;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CAAC,CAAC,IAAI,CAAC,CAAC;aAC/E,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED;;;;;;;;;OASG;IACI,QAAQ,CACd,QAAsC,EACtC,cAAsB;QAEtB,MAAM,UAAU,GAAqB,EAAE,GAAG,QAAQ,EAAE,CAAC;QACrD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3C,UAAU,CAAC,GAAG,CAAC,GAAG,oBAAoB,CACrC,OAAO,CAAC,YAAY,EACpB,IAAA,iCAAsB,EAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,cAAc,CAAC,CACjF,CAAC;YACF,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC9B,gEAAgE;gBAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAkB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACzE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAzOD,8CAyOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tassert,\n\tDoublyLinkedList,\n\titerateListValuesWhile,\n} from \"@fluidframework/core-utils/internal\";\n\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport type {\n\tAdjustParams,\n\tIMergeTreeAnnotateAdjustMsg,\n\tIMergeTreeAnnotateMsg,\n} from \"./ops.js\";\nimport { type MapLike, type PropertySet, clone, createMap } from \"./properties.js\";\n\n/**\n * Minimally copies properties and the property manager from source to destination.\n * @internal\n */\nexport function copyPropertiesAndManager(\n\tsource: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n\tdestination: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n): void {\n\tif (source.properties) {\n\t\tif (source.propertyManager === undefined) {\n\t\t\tdestination.properties = clone(source.properties);\n\t\t} else {\n\t\t\tdestination.propertyManager ??= new PropertiesManager();\n\t\t\tsource.propertyManager.copyTo(source.properties, destination);\n\t\t}\n\t}\n}\n\ntype PropertyChange = {\n\tseq: number;\n} & ({ adjust: AdjustParams; raw?: undefined } | { raw: unknown; adjust?: undefined });\n\ninterface PropertyChanges {\n\tmsnConsensus: unknown;\n\tremote: DoublyLinkedList<PropertyChange>;\n\tlocal: DoublyLinkedList<PropertyChange>;\n}\n\nfunction computePropertyValue(\n\tconsensus: unknown,\n\t...changes: Iterable<PropertyChange>[]\n): unknown {\n\tlet computedValue: unknown = consensus;\n\tfor (const change of changes) {\n\t\tfor (const op of change) {\n\t\t\tconst { raw, adjust } = op;\n\t\t\tif (adjust === undefined) {\n\t\t\t\tcomputedValue = raw;\n\t\t\t} else {\n\t\t\t\tconst adjusted =\n\t\t\t\t\t(typeof computedValue === \"number\" ? computedValue : 0) + adjust.delta;\n\t\t\t\tif (adjust.max !== undefined && adjusted > adjust.max) {\n\t\t\t\t\tcomputedValue = adjust.max;\n\t\t\t\t} else if (adjust.min !== undefined && adjusted < adjust.min) {\n\t\t\t\t\tcomputedValue = adjust.min;\n\t\t\t\t} else {\n\t\t\t\t\tcomputedValue = adjusted;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn computedValue;\n}\n\n/**\n * @internal\n */\nexport type PropsOrAdjust =\n\t| Pick<IMergeTreeAnnotateAdjustMsg, \"props\" | \"adjust\">\n\t| Pick<IMergeTreeAnnotateMsg, \"props\" | \"adjust\">;\n\nconst opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [\n\t...Object.entries(op.props ?? {})\n\t\t.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])\n\t\t.filter(([_, v]) => v.raw !== undefined),\n\t...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [\n\t\tk,\n\t\t{ adjust, seq },\n\t]),\n];\n\nfunction applyChanges(\n\top: PropsOrAdjust,\n\tseg: { properties?: MapLike<unknown> },\n\tseq: number,\n\trun: (\n\t\tproperties: MapLike<unknown>,\n\t\tdeltas: MapLike<unknown>,\n\t\tkey: string,\n\t\tvalue: PropertyChange,\n\t) => void,\n): MapLike<unknown> {\n\tconst properties = (seg.properties ??= createMap<unknown>());\n\tconst deltas: MapLike<unknown> = {};\n\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\trun(properties, deltas, key, value);\n\t\tif (properties[key] === null) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete properties[key];\n\t\t}\n\t}\n\treturn deltas;\n}\n\n/**\n * The PropertiesManager class handles changes to properties, both remote and local.\n * It manages the lifecycle for local property changes, ensures all property changes are eventually consistent,\n * and provides methods to acknowledge changes, update the minimum sequence number (msn), and copy properties to another manager.\n * This class is essential for maintaining the integrity and consistency of property changes in collaborative environments.\n * @internal\n */\nexport class PropertiesManager {\n\tprivate readonly changes = new Map<string, PropertyChanges>();\n\n\t/**\n\t * Rolls back local property changes.\n\t * This method reverts property changes based on the provided operation and segment.\n\t * If the operation is part of a collaborative session, it ensures that the changes are consistent with the remote state.\n\t *\n\t * @param op - The operation containing property changes. This can be an adjustment or a set of properties.\n\t * @param seg - The segment containing properties. This object may have a properties map that will be modified.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @returns The deltas of the rolled-back properties. This is a map-like object representing the changes that were reverted.\n\t */\n\tpublic rollbackProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tcollaborating: boolean = false,\n\t): MapLike<unknown> {\n\t\treturn applyChanges(op, seg, UniversalSequenceNumber, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\n\t\t\tconst pending = this.changes.get(key);\n\t\t\tif (collaborating) {\n\t\t\t\tassert(\n\t\t\t\t\tpending !== undefined,\n\t\t\t\t\t0xa6f /* Pending changes must exist for rollback when collaborating */,\n\t\t\t\t);\n\t\t\t\tpending.local.pop();\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\t\tthis.changes.delete(key);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tpending === undefined,\n\t\t\t\t\t0xa70 /* Pending changes must not exist when not collaborating */,\n\t\t\t\t);\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t}\n\t\t\tdeltas[key] = previousValue;\n\t\t});\n\t}\n\n\t/**\n\t * Handles property changes.\n\t * This method applies property changes based on the provided operation, segment, sequence number, and collaboration state.\n\t * It also handles rolling back changes if specified.\n\t *\n\t * @param op - The operation containing property changes.\n\t * @param seg - The segment containing properties.\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.\n\t * @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.\n\t */\n\tpublic handleProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tseq: number,\n\t\tmsn: number,\n\t\tcollaborating: boolean = false,\n\t\trollback: boolean = false,\n\t): MapLike<unknown> {\n\t\tif (rollback) {\n\t\t\treturn this.rollbackProperties(op, seg, collaborating);\n\t\t}\n\t\tconst rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\t\t\tif (collaborating) {\n\t\t\t\tconst pending: PropertyChanges | undefined = this.changes.get(key) ?? {\n\t\t\t\t\tmsnConsensus: previousValue,\n\t\t\t\t\tremote: new DoublyLinkedList(),\n\t\t\t\t\tlocal: new DoublyLinkedList(),\n\t\t\t\t};\n\t\t\t\tthis.changes.set(key, pending);\n\t\t\t\tconst local = seq === UnassignedSequenceNumber;\n\t\t\t\tif (local) {\n\t\t\t\t\tpending.local.push(value);\n\t\t\t\t} else {\n\t\t\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\t\t\tif (value.raw !== undefined && pending.remote.empty) {\n\t\t\t\t\t\tpending.msnConsensus = computePropertyValue(pending.msnConsensus, [value]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpending.remote.push(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (local || pending.local.empty || properties[key] !== previousValue) {\n\t\t\t\t\tdeltas[key] = previousValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t\tdeltas[key] = previousValue;\n\t\t\t}\n\t\t});\n\t\tthis.updateMsn(msn);\n\t\treturn rtn;\n\t}\n\n\t/**\n\t * Acknowledges property changes.\n\t * This method acknowledges the property changes based on the provided sequence number and operation.\n\t *\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param op - The operation containing property changes.\n\t */\n\tpublic ack(seq: number, msn: number, op: PropsOrAdjust): void {\n\t\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\t\tconst change = this.changes.get(key);\n\t\t\tconst acked = change?.local?.shift();\n\t\t\tassert(\n\t\t\t\tchange !== undefined && acked !== undefined,\n\t\t\t\t0xa71 /* must have local change to ack */,\n\t\t\t);\n\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\tif (value.raw !== undefined && change.remote.empty) {\n\t\t\t\tchange.msnConsensus = computePropertyValue(change.msnConsensus, [value]);\n\t\t\t} else {\n\t\t\t\tchange.remote.push(value);\n\t\t\t}\n\t\t}\n\t\tthis.updateMsn(msn);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number (msn).\n\t * This method updates the minimum sequence number and removes any changes that have been acknowledged.\n\t *\n\t * @param msn - The minimum sequence number to update.\n\t */\n\tpublic updateMsn(msn: number): void {\n\t\tfor (const [key, pending] of this.changes) {\n\t\t\tpending.msnConsensus = computePropertyValue(\n\t\t\t\tpending.msnConsensus,\n\t\t\t\titerateListValuesWhile(pending.remote.first, (n) => {\n\t\t\t\t\tif (n.data.seq <= msn) {\n\t\t\t\t\t\tn.list?.remove(n);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\tthis.changes.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copies properties to another manager.\n\t * This method copies the properties and their changes from the current manager to the destination manager.\n\t *\n\t * @param oldProps - The old properties to be copied.\n\t * @param dest - The destination object containing properties and property manager.\n\t */\n\tpublic copyTo(\n\t\toldProps: PropertySet | undefined,\n\t\tdest: {\n\t\t\tproperties?: PropertySet;\n\t\t\tpropertyManager?: PropertiesManager;\n\t\t},\n\t): void {\n\t\tconst newManager = (dest.propertyManager ??= new PropertiesManager());\n\t\tdest.properties = clone(oldProps);\n\t\tfor (const [key, { local, remote, msnConsensus }] of this.changes.entries()) {\n\t\t\tnewManager.changes.set(key, {\n\t\t\t\tmsnConsensus,\n\t\t\t\tremote: new DoublyLinkedList(remote.empty ? undefined : remote.map((c) => c.data)),\n\t\t\t\tlocal: new DoublyLinkedList(local.empty ? undefined : local.map((c) => c.data)),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Gets properties at a specific sequence number.\n\t * This method retrieves the properties at the given sequence number.\n\t * This is only needed to support emitting snapshots in the legacy format.\n\t * If we remove the ability to emit the legacy format, we can remove this method, along with the need to track remote changes at all.\n\t *\n\t * @param oldProps - The old properties to be retrieved.\n\t * @param sequenceNumber - The sequence number to get properties at.\n\t * @returns The properties at the given sequence number.\n\t */\n\tpublic getAtSeq(\n\t\toldProps: MapLike<unknown> | undefined,\n\t\tsequenceNumber: number,\n\t): MapLike<unknown> {\n\t\tconst properties: MapLike<unknown> = { ...oldProps };\n\t\tfor (const [key, changes] of this.changes) {\n\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\tchanges.msnConsensus,\n\t\t\t\titerateListValuesWhile(changes.remote.first, (c) => c.data.seq <= sequenceNumber),\n\t\t\t);\n\t\t\tif (properties[key] === null) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete properties[key];\n\t\t\t}\n\t\t}\n\t\treturn properties;\n\t}\n\n\t/**\n\t * Determines if all of the defined properties in a given property set are pending.\n\t *\n\t * @param props - The properties to check.\n\t * @returns True if all the properties are pending, false otherwise.\n\t */\n\tpublic hasPendingProperties(props: PropertySet): boolean {\n\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\tif (value !== undefined && this.changes.get(key)?.local.empty !== false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributionCollection.d.ts","sourceRoot":"","sources":["../src/attributionCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,cAAc,EAGd,MAAM,8CAA8C,CAAC;AAGtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;OAWG;IAEH,IAAI,EAAE,CAAC,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC,EAAE,CAAC;IACzC,cAAc,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,+BAAgC,SAAQ,eAAe;IACvE,QAAQ,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAC;IAE/C,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B,CAAC,CAAC;IAE5C,IAAI,EAAE,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAElD,QAAQ,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;IAC3E,MAAM,EAAE,MAAM,CAAC;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AAM,GAAG,SAAS,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAkB7E;;OAEG;WACW,8BAA8B,CAC3C,QAAQ,EAAE,QAAQ,EAAE,EACpB,OAAO,EAAE,+BAA+B,GACtC,IAAI;IAmEP;;;;;OAKG;WACW,+BAA+B,CAC5C,QAAQ,EAAE,QAAQ,CAAC;QAClB,WAAW,CAAC,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;QACrD,YAAY,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,+BAA+B;CAiElC"}
|
|
@@ -206,10 +206,7 @@ export class AttributionCollection {
|
|
|
206
206
|
*/
|
|
207
207
|
static populateAttributionCollections(segments, summary) {
|
|
208
208
|
const { channels } = summary;
|
|
209
|
-
assert(
|
|
210
|
-
// Destructuring here would require renaming the variables, since seqs is declared below
|
|
211
|
-
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
212
|
-
summary.seqs.length === summary.posBreakpoints.length, 0x445 /* Invalid attribution summary blob provided */);
|
|
209
|
+
assert(summary.seqs.length === summary.posBreakpoints.length, 0x445 /* Invalid attribution summary blob provided */);
|
|
213
210
|
const extractOntoSegments = ({ seqs, posBreakpoints }, assignToSegment) => {
|
|
214
211
|
if (seqs.length === 0) {
|
|
215
212
|
assert(posBreakpoints.length === 0, 0x9e1 /* seqs and posBreakpoints length should match */);
|
|
@@ -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,OAA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,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"]}
|
|
1
|
+
{"version":3,"file":"attributionCollection.js","sourceRo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CAAC,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;wBAC5C,2CAA2C;wBAC3C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,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\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeDeltaCallback.js","sourceRoot":"","sources":["../src/mergeTreeDeltaCallback.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,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-x/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-x/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
|
|
1
|
+
{"version":3,"file":"mergeTreeDeltaCallback.js","sourceRoot":"","sources":["../src/mergeTreeDeltaCallback.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,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-x/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-x/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\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeNodeWalk.d.ts","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGhF,eAAO,MAAM,UAAU;;CAEb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;AAEpD,eAAO,MAAM,UAAU;;;;CAKb,CAAC;AAGX,MAAM,MAAM,UAAU,GACnB,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,GAC5C,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,EAC7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,GACpD,OAAO,CAeT;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,GAAG,SAAS,GAAG,IAAI,GAC/D,OAAO,CAqBT"}
|
package/lib/mergeTreeNodeWalk.js
CHANGED
|
@@ -32,7 +32,6 @@ export function depthFirstNodeWalk(startBlock, startChild, downAction, leafActio
|
|
|
32
32
|
let block = startBlock;
|
|
33
33
|
let childCount = block.childCount;
|
|
34
34
|
let start = startChild;
|
|
35
|
-
// eslint-disable-next-line no-constant-condition
|
|
36
35
|
while (true) {
|
|
37
36
|
// go down to the leaf level
|
|
38
37
|
let blockResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeNodeWalk.js","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,IAAI,EAAE,KAAK;CACF,CAAC;AAIX,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,QAAQ,EAAE,SAAS;IACnB,iDAAiD;IACjD,IAAI,EAAE,UAAU,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC;CACE,CAAC;AAOX;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CACjC,UAAsB,EACtB,UAAkC,EAClC,UAA6C,EAC7C,kBAAsD,EACtD,QAAsC,EACtC,UAAmB,IAAI;IAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,kBAAkB,IAAI,UAAU,CAAC;IACpD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,KAAK,GAAG,UAAU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AC,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,kBAAkB,CACxB,SAAS,CAAC,MAAM;IAChB,gDAAgD;IAChD,8CAA8C;IAC9C,qBAAqB;IACrB,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,EAC9C,SAAS,CAAC,gBAAgB,EAC1B,UAAU,EACV,SAAS,CAAC,cAAc,EACxB,KAAK,CAAC,aAAa,CACnB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,UAAsB,EACtB,UAAiE;IAEjE,IAAI,UAAU,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,yGAAyG;IACzG,gCAAgC;IAChC,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IACpD,KAAK,IAAI,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACvE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,kBAAkB,CACxB,UAAU,EACV,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EACtB,SAAS,CAAC,IAAI,KAAK,CAAC;QACnB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,IAAI,EAAqB,EAAE,CAC5B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EACrE,UAAU,CACV,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISegmentLeaf, MergeBlock, IMergeNode } from \"./mergeTreeNodes.js\";\nimport { isMergeNodeInfo } from \"./segmentInfos.js\";\n\nexport const LeafAction = {\n\tExit: false,\n} as const;\n\nexport type LeafAction = boolean | undefined | void;\n\nexport const NodeAction = {\n\tContinue: undefined,\n\t// exit is false to unify with leafActionOverride\n\tExit: LeafAction.Exit,\n\tSkip: 2,\n} as const;\n\n// we exclude true from, as we only want one continue value, undefined\nexport type NodeAction =\n\t| (typeof NodeAction)[keyof typeof NodeAction]\n\t| Exclude<LeafAction, true>;\n\n/**\n * Does a depth first walk of the tree from the specific start.\n *\n * @param startBlock - The block of the tree to start the walk from\n * @param startChild - The child of that block to start from\n * @param downAction - Called as we walk down the tree to the leaves.\n * @param leafActionOverride - Overrides downAction for leaves, generally used without downAction\n * @param upAction - Called after all the children of a block are walked.\n * @param forward - whether to walk forward or backward\n * @returns true if we naturally exit, false if exiting due to Exit action result\n */\nexport function depthFirstNodeWalk(\n\tstartBlock: MergeBlock,\n\tstartChild: IMergeNode | undefined,\n\tdownAction?: (node: IMergeNode) => NodeAction,\n\tleafActionOverride?: (seg: ISegmentLeaf) => LeafAction,\n\tupAction?: (block: MergeBlock) => void,\n\tforward: boolean = true,\n): boolean {\n\tconst increment = forward ? 1 : -1;\n\tconst leafAction = leafActionOverride ?? downAction;\n\tif (leafAction === undefined) {\n\t\treturn true;\n\t}\n\n\tlet block = startBlock;\n\tlet childCount = block.childCount;\n\tlet start: IMergeNode | undefined = startChild;\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\t// go down to the leaf level\n\t\tlet blockResult: NodeAction;\n\t\twhile (start?.isLeaf() === false) {\n\t\t\t// cast is safe due to isLeaf === false in while above\n\t\t\tblock = start as MergeBlock;\n\t\t\tchildCount = block.childCount;\n\t\t\tblockResult = downAction?.(block);\n\t\t\t// setting start undefined will skip the leaf walk\n\t\t\t// so if the block result isn't continue, set it\n\t\t\t// undefined\n\t\t\tstart =\n\t\t\t\tblockResult === NodeAction.Continue\n\t\t\t\t\t? block.children[forward ? 0 : childCount - 1]\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tlet exit = blockResult === NodeAction.Exit;\n\n\t\t// walk the leaves if we reached them\n\t\tif (start !== undefined) {\n\t\t\tfor (let i = start.index; i !== -1 && i !== childCount; i += increment) {\n\t\t\t\t// the above loop ensures start is a leaf or undefined, so all children\n\t\t\t\t// will be leaves if start exits, so the cast is safe\n\t\t\t\tif (leafAction(block.children[i] as ISegmentLeaf) === LeafAction.Exit) {\n\t\t\t\t\texit = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if there is no upAction, we don't need to walk up before exiting\n\t\tif (upAction === undefined && exit) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// since we already enumerated the children\n\t\t// we walk up to the next level until there is a sibling\n\t\t// or all the way up if exit is true\n\t\tlet nextIndex = -1;\n\t\tdo {\n\t\t\t// if the blockAction was exit or skip\n\t\t\t// we shouldn't process that block again,\n\t\t\t// if there are subsequent parents while walking up\n\t\t\t// we will process those.\n\t\t\tif (blockResult === NodeAction.Continue) {\n\t\t\t\tupAction?.(block);\n\t\t\t} else {\n\t\t\t\tblockResult = NodeAction.Continue;\n\t\t\t}\n\t\t\tif (block.parent === undefined) {\n\t\t\t\treturn !exit;\n\t\t\t}\n\t\t\tstart = block;\n\t\t\tblock = block.parent;\n\t\t\tchildCount = block.childCount;\n\t\t\tnextIndex = start.index + increment;\n\t\t} while (exit || nextIndex === -1 || nextIndex === childCount);\n\t\t// the above loop ensured that siblings are possible\n\t\tstart = block.children[nextIndex];\n\t}\n}\n\n/**\n * Visit segments starting from node's right/far/forward siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function forwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index + 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t);\n}\n\n/**\n * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function backwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index - 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t\tundefined /* upAction */,\n\t\tfalse /* forward */,\n\t);\n}\n\n/**\n * Walks all segments below the specific start block\n * @param startBlock - The block to start the walk at\n * @param leafAction - The action to perform on the leaves\n * @returns true if we naturally exit, false if exiting due to leaf action result\n */\nexport function walkAllChildSegments(\n\tstartBlock: MergeBlock,\n\tleafAction: (segment: ISegmentLeaf) => boolean | undefined | void,\n): boolean {\n\tif (startBlock.childCount === 0) {\n\t\treturn true;\n\t}\n\n\t// undefined shouldn't actually be added, but this allows subsequent check for `node.parent` to typecheck\n\t// without further runtime work.\n\tconst ancestors = new Set<MergeBlock | undefined>();\n\tfor (let cur = startBlock.parent; cur !== undefined; cur = cur.parent) {\n\t\tancestors.add(cur);\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartBlock,\n\t\tstartBlock.children[0],\n\t\tancestors.size === 0\n\t\t\t? undefined\n\t\t\t: (node): false | undefined =>\n\t\t\t\t\tancestors.has(node.parent) ? NodeAction.Exit : NodeAction.Continue,\n\t\tleafAction,\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mergeTreeNodeWalk.js","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":"AAAA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AC;IACpD,KAAK,IAAI,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACvE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,kBAAkB,CACxB,UAAU,EACV,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EACtB,SAAS,CAAC,IAAI,KAAK,CAAC;QACnB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,IAAI,EAAqB,EAAE,CAC5B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EACrE,UAAU,CACV,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISegmentLeaf, MergeBlock, IMergeNode } from \"./mergeTreeNodes.js\";\nimport { isMergeNodeInfo } from \"./segmentInfos.js\";\n\nexport const LeafAction = {\n\tExit: false,\n} as const;\n\nexport type LeafAction = boolean | undefined | void;\n\nexport const NodeAction = {\n\tContinue: undefined,\n\t// exit is false to unify with leafActionOverride\n\tExit: LeafAction.Exit,\n\tSkip: 2,\n} as const;\n\n// we exclude true from, as we only want one continue value, undefined\nexport type NodeAction =\n\t| (typeof NodeAction)[keyof typeof NodeAction]\n\t| Exclude<LeafAction, true>;\n\n/**\n * Does a depth first walk of the tree from the specific start.\n *\n * @param startBlock - The block of the tree to start the walk from\n * @param startChild - The child of that block to start from\n * @param downAction - Called as we walk down the tree to the leaves.\n * @param leafActionOverride - Overrides downAction for leaves, generally used without downAction\n * @param upAction - Called after all the children of a block are walked.\n * @param forward - whether to walk forward or backward\n * @returns true if we naturally exit, false if exiting due to Exit action result\n */\nexport function depthFirstNodeWalk(\n\tstartBlock: MergeBlock,\n\tstartChild: IMergeNode | undefined,\n\tdownAction?: (node: IMergeNode) => NodeAction,\n\tleafActionOverride?: (seg: ISegmentLeaf) => LeafAction,\n\tupAction?: (block: MergeBlock) => void,\n\tforward: boolean = true,\n): boolean {\n\tconst increment = forward ? 1 : -1;\n\tconst leafAction = leafActionOverride ?? downAction;\n\tif (leafAction === undefined) {\n\t\treturn true;\n\t}\n\n\tlet block = startBlock;\n\tlet childCount = block.childCount;\n\tlet start: IMergeNode | undefined = startChild;\n\n\twhile (true) {\n\t\t// go down to the leaf level\n\t\tlet blockResult: NodeAction;\n\t\twhile (start?.isLeaf() === false) {\n\t\t\t// cast is safe due to isLeaf === false in while above\n\t\t\tblock = start as MergeBlock;\n\t\t\tchildCount = block.childCount;\n\t\t\tblockResult = downAction?.(block);\n\t\t\t// setting start undefined will skip the leaf walk\n\t\t\t// so if the block result isn't continue, set it\n\t\t\t// undefined\n\t\t\tstart =\n\t\t\t\tblockResult === NodeAction.Continue\n\t\t\t\t\t? block.children[forward ? 0 : childCount - 1]\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tlet exit = blockResult === NodeAction.Exit;\n\n\t\t// walk the leaves if we reached them\n\t\tif (start !== undefined) {\n\t\t\tfor (let i = start.index; i !== -1 && i !== childCount; i += increment) {\n\t\t\t\t// the above loop ensures start is a leaf or undefined, so all children\n\t\t\t\t// will be leaves if start exits, so the cast is safe\n\t\t\t\tif (leafAction(block.children[i] as ISegmentLeaf) === LeafAction.Exit) {\n\t\t\t\t\texit = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if there is no upAction, we don't need to walk up before exiting\n\t\tif (upAction === undefined && exit) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// since we already enumerated the children\n\t\t// we walk up to the next level until there is a sibling\n\t\t// or all the way up if exit is true\n\t\tlet nextIndex = -1;\n\t\tdo {\n\t\t\t// if the blockAction was exit or skip\n\t\t\t// we shouldn't process that block again,\n\t\t\t// if there are subsequent parents while walking up\n\t\t\t// we will process those.\n\t\t\tif (blockResult === NodeAction.Continue) {\n\t\t\t\tupAction?.(block);\n\t\t\t} else {\n\t\t\t\tblockResult = NodeAction.Continue;\n\t\t\t}\n\t\t\tif (block.parent === undefined) {\n\t\t\t\treturn !exit;\n\t\t\t}\n\t\t\tstart = block;\n\t\t\tblock = block.parent;\n\t\t\tchildCount = block.childCount;\n\t\t\tnextIndex = start.index + increment;\n\t\t} while (exit || nextIndex === -1 || nextIndex === childCount);\n\t\t// the above loop ensured that siblings are possible\n\t\tstart = block.children[nextIndex];\n\t}\n}\n\n/**\n * Visit segments starting from node's right/far/forward siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function forwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index + 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t);\n}\n\n/**\n * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function backwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index - 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t\tundefined /* upAction */,\n\t\tfalse /* forward */,\n\t);\n}\n\n/**\n * Walks all segments below the specific start block\n * @param startBlock - The block to start the walk at\n * @param leafAction - The action to perform on the leaves\n * @returns true if we naturally exit, false if exiting due to leaf action result\n */\nexport function walkAllChildSegments(\n\tstartBlock: MergeBlock,\n\tleafAction: (segment: ISegmentLeaf) => boolean | undefined | void,\n): boolean {\n\tif (startBlock.childCount === 0) {\n\t\treturn true;\n\t}\n\n\t// undefined shouldn't actually be added, but this allows subsequent check for `node.parent` to typecheck\n\t// without further runtime work.\n\tconst ancestors = new Set<MergeBlock | undefined>();\n\tfor (let cur = startBlock.parent; cur !== undefined; cur = cur.parent) {\n\t\tancestors.add(cur);\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartBlock,\n\t\tstartBlock.children[0],\n\t\tancestors.size === 0\n\t\t\t? undefined\n\t\t\t: (node): false | undefined =>\n\t\t\t\t\tancestors.has(node.parent) ? NodeAction.Exit : NodeAction.Continue,\n\t\tleafAction,\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentPropertiesManager.d.ts","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAEX,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,iBAAiB,CAAC;AAEnF;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE;IACP,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,EACD,WAAW,EAAE;IACZ,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,GACC,IAAI,CASN;AAsCD;;GAEG;AACH,MAAM,MAAM,aAAa,GACtB,IAAI,CAAC,2BAA2B,EAAE,OAAO,GAAG,QAAQ,CAAC,GACrD,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"seg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AE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,GAAG,IAAI;IAqB7D;;;;;OAKG;IACI,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAkBnC;;;;;;OAMG;IACI,MAAM,CACZ,QAAQ,EAAE,WAAW,GAAG,SAAS,EACjC,IAAI,EAAE;QACL,UAAU,CAAC,EAAE,WAAW,CAAC;QACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;KACpC,GACC,IAAI;IAYP;;;;;;;;;OASG;IACI,QAAQ,CACd,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,EACtC,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC;IAenB;;;;;OAKG;IACI,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;CAQxD"}
|
|
@@ -46,7 +46,6 @@ function computePropertyValue(consensus, ...changes) {
|
|
|
46
46
|
}
|
|
47
47
|
const opToChanges = (op, seq) => [
|
|
48
48
|
...Object.entries(op.props ?? {})
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
50
49
|
.map(([k, raw]) => [k, { raw, seq }])
|
|
51
50
|
.filter(([_, v]) => v.raw !== undefined),
|
|
52
51
|
...Object.entries(op.adjust ?? {}).map(([k, adjust]) => [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentPropertiesManager.js","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAMnF,OAAO,EAAkC,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEnF;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACvC,MAGC,EACD,WAG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AC9B,gEAAgE;gBAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAkB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACzE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tassert,\n\tDoublyLinkedList,\n\titerateListValuesWhile,\n} from \"@fluidframework/core-utils/internal\";\n\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport type {\n\tAdjustParams,\n\tIMergeTreeAnnotateAdjustMsg,\n\tIMergeTreeAnnotateMsg,\n} from \"./ops.js\";\nimport { type MapLike, type PropertySet, clone, createMap } from \"./properties.js\";\n\n/**\n * Minimally copies properties and the property manager from source to destination.\n * @internal\n */\nexport function copyPropertiesAndManager(\n\tsource: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n\tdestination: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n): void {\n\tif (source.properties) {\n\t\tif (source.propertyManager === undefined) {\n\t\t\tdestination.properties = clone(source.properties);\n\t\t} else {\n\t\t\tdestination.propertyManager ??= new PropertiesManager();\n\t\t\tsource.propertyManager.copyTo(source.properties, destination);\n\t\t}\n\t}\n}\n\ntype PropertyChange = {\n\tseq: number;\n} & ({ adjust: AdjustParams; raw?: undefined } | { raw: unknown; adjust?: undefined });\n\ninterface PropertyChanges {\n\tmsnConsensus: unknown;\n\tremote: DoublyLinkedList<PropertyChange>;\n\tlocal: DoublyLinkedList<PropertyChange>;\n}\n\nfunction computePropertyValue(\n\tconsensus: unknown,\n\t...changes: Iterable<PropertyChange>[]\n): unknown {\n\tlet computedValue: unknown = consensus;\n\tfor (const change of changes) {\n\t\tfor (const op of change) {\n\t\t\tconst { raw, adjust } = op;\n\t\t\tif (adjust === undefined) {\n\t\t\t\tcomputedValue = raw;\n\t\t\t} else {\n\t\t\t\tconst adjusted =\n\t\t\t\t\t(typeof computedValue === \"number\" ? computedValue : 0) + adjust.delta;\n\t\t\t\tif (adjust.max !== undefined && adjusted > adjust.max) {\n\t\t\t\t\tcomputedValue = adjust.max;\n\t\t\t\t} else if (adjust.min !== undefined && adjusted < adjust.min) {\n\t\t\t\t\tcomputedValue = adjust.min;\n\t\t\t\t} else {\n\t\t\t\t\tcomputedValue = adjusted;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn computedValue;\n}\n\n/**\n * @internal\n */\nexport type PropsOrAdjust =\n\t| Pick<IMergeTreeAnnotateAdjustMsg, \"props\" | \"adjust\">\n\t| Pick<IMergeTreeAnnotateMsg, \"props\" | \"adjust\">;\n\nconst opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [\n\t...Object.entries(op.props ?? {})\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])\n\t\t.filter(([_, v]) => v.raw !== undefined),\n\t...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [\n\t\tk,\n\t\t{ adjust, seq },\n\t]),\n];\n\nfunction applyChanges(\n\top: PropsOrAdjust,\n\tseg: { properties?: MapLike<unknown> },\n\tseq: number,\n\trun: (\n\t\tproperties: MapLike<unknown>,\n\t\tdeltas: MapLike<unknown>,\n\t\tkey: string,\n\t\tvalue: PropertyChange,\n\t) => void,\n): MapLike<unknown> {\n\tconst properties = (seg.properties ??= createMap<unknown>());\n\tconst deltas: MapLike<unknown> = {};\n\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\trun(properties, deltas, key, value);\n\t\tif (properties[key] === null) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete properties[key];\n\t\t}\n\t}\n\treturn deltas;\n}\n\n/**\n * The PropertiesManager class handles changes to properties, both remote and local.\n * It manages the lifecycle for local property changes, ensures all property changes are eventually consistent,\n * and provides methods to acknowledge changes, update the minimum sequence number (msn), and copy properties to another manager.\n * This class is essential for maintaining the integrity and consistency of property changes in collaborative environments.\n * @internal\n */\nexport class PropertiesManager {\n\tprivate readonly changes = new Map<string, PropertyChanges>();\n\n\t/**\n\t * Rolls back local property changes.\n\t * This method reverts property changes based on the provided operation and segment.\n\t * If the operation is part of a collaborative session, it ensures that the changes are consistent with the remote state.\n\t *\n\t * @param op - The operation containing property changes. This can be an adjustment or a set of properties.\n\t * @param seg - The segment containing properties. This object may have a properties map that will be modified.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @returns The deltas of the rolled-back properties. This is a map-like object representing the changes that were reverted.\n\t */\n\tpublic rollbackProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tcollaborating: boolean = false,\n\t): MapLike<unknown> {\n\t\treturn applyChanges(op, seg, UniversalSequenceNumber, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\n\t\t\tconst pending = this.changes.get(key);\n\t\t\tif (collaborating) {\n\t\t\t\tassert(\n\t\t\t\t\tpending !== undefined,\n\t\t\t\t\t0xa6f /* Pending changes must exist for rollback when collaborating */,\n\t\t\t\t);\n\t\t\t\tpending.local.pop();\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\t\tthis.changes.delete(key);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tpending === undefined,\n\t\t\t\t\t0xa70 /* Pending changes must not exist when not collaborating */,\n\t\t\t\t);\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t}\n\t\t\tdeltas[key] = previousValue;\n\t\t});\n\t}\n\n\t/**\n\t * Handles property changes.\n\t * This method applies property changes based on the provided operation, segment, sequence number, and collaboration state.\n\t * It also handles rolling back changes if specified.\n\t *\n\t * @param op - The operation containing property changes.\n\t * @param seg - The segment containing properties.\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.\n\t * @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.\n\t */\n\tpublic handleProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tseq: number,\n\t\tmsn: number,\n\t\tcollaborating: boolean = false,\n\t\trollback: boolean = false,\n\t): MapLike<unknown> {\n\t\tif (rollback) {\n\t\t\treturn this.rollbackProperties(op, seg, collaborating);\n\t\t}\n\t\tconst rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\t\t\tif (collaborating) {\n\t\t\t\tconst pending: PropertyChanges | undefined = this.changes.get(key) ?? {\n\t\t\t\t\tmsnConsensus: previousValue,\n\t\t\t\t\tremote: new DoublyLinkedList(),\n\t\t\t\t\tlocal: new DoublyLinkedList(),\n\t\t\t\t};\n\t\t\t\tthis.changes.set(key, pending);\n\t\t\t\tconst local = seq === UnassignedSequenceNumber;\n\t\t\t\tif (local) {\n\t\t\t\t\tpending.local.push(value);\n\t\t\t\t} else {\n\t\t\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\t\t\tif (value.raw !== undefined && pending.remote.empty) {\n\t\t\t\t\t\tpending.msnConsensus = computePropertyValue(pending.msnConsensus, [value]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpending.remote.push(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (local || pending.local.empty || properties[key] !== previousValue) {\n\t\t\t\t\tdeltas[key] = previousValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t\tdeltas[key] = previousValue;\n\t\t\t}\n\t\t});\n\t\tthis.updateMsn(msn);\n\t\treturn rtn;\n\t}\n\n\t/**\n\t * Acknowledges property changes.\n\t * This method acknowledges the property changes based on the provided sequence number and operation.\n\t *\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param op - The operation containing property changes.\n\t */\n\tpublic ack(seq: number, msn: number, op: PropsOrAdjust): void {\n\t\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\t\tconst change = this.changes.get(key);\n\t\t\tconst acked = change?.local?.shift();\n\t\t\tassert(\n\t\t\t\tchange !== undefined && acked !== undefined,\n\t\t\t\t0xa71 /* must have local change to ack */,\n\t\t\t);\n\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\tif (value.raw !== undefined && change.remote.empty) {\n\t\t\t\tchange.msnConsensus = computePropertyValue(change.msnConsensus, [value]);\n\t\t\t} else {\n\t\t\t\tchange.remote.push(value);\n\t\t\t}\n\t\t}\n\t\tthis.updateMsn(msn);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number (msn).\n\t * This method updates the minimum sequence number and removes any changes that have been acknowledged.\n\t *\n\t * @param msn - The minimum sequence number to update.\n\t */\n\tpublic updateMsn(msn: number): void {\n\t\tfor (const [key, pending] of this.changes) {\n\t\t\tpending.msnConsensus = computePropertyValue(\n\t\t\t\tpending.msnConsensus,\n\t\t\t\titerateListValuesWhile(pending.remote.first, (n) => {\n\t\t\t\t\tif (n.data.seq <= msn) {\n\t\t\t\t\t\tn.list?.remove(n);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\tthis.changes.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copies properties to another manager.\n\t * This method copies the properties and their changes from the current manager to the destination manager.\n\t *\n\t * @param oldProps - The old properties to be copied.\n\t * @param dest - The destination object containing properties and property manager.\n\t */\n\tpublic copyTo(\n\t\toldProps: PropertySet | undefined,\n\t\tdest: {\n\t\t\tproperties?: PropertySet;\n\t\t\tpropertyManager?: PropertiesManager;\n\t\t},\n\t): void {\n\t\tconst newManager = (dest.propertyManager ??= new PropertiesManager());\n\t\tdest.properties = clone(oldProps);\n\t\tfor (const [key, { local, remote, msnConsensus }] of this.changes.entries()) {\n\t\t\tnewManager.changes.set(key, {\n\t\t\t\tmsnConsensus,\n\t\t\t\tremote: new DoublyLinkedList(remote.empty ? undefined : remote.map((c) => c.data)),\n\t\t\t\tlocal: new DoublyLinkedList(local.empty ? undefined : local.map((c) => c.data)),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Gets properties at a specific sequence number.\n\t * This method retrieves the properties at the given sequence number.\n\t * This is only needed to support emitting snapshots in the legacy format.\n\t * If we remove the ability to emit the legacy format, we can remove this method, along with the need to track remote changes at all.\n\t *\n\t * @param oldProps - The old properties to be retrieved.\n\t * @param sequenceNumber - The sequence number to get properties at.\n\t * @returns The properties at the given sequence number.\n\t */\n\tpublic getAtSeq(\n\t\toldProps: MapLike<unknown> | undefined,\n\t\tsequenceNumber: number,\n\t): MapLike<unknown> {\n\t\tconst properties: MapLike<unknown> = { ...oldProps };\n\t\tfor (const [key, changes] of this.changes) {\n\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\tchanges.msnConsensus,\n\t\t\t\titerateListValuesWhile(changes.remote.first, (c) => c.data.seq <= sequenceNumber),\n\t\t\t);\n\t\t\tif (properties[key] === null) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete properties[key];\n\t\t\t}\n\t\t}\n\t\treturn properties;\n\t}\n\n\t/**\n\t * Determines if all of the defined properties in a given property set are pending.\n\t *\n\t * @param props - The properties to check.\n\t * @returns True if all the properties are pending, false otherwise.\n\t */\n\tpublic hasPendingProperties(props: PropertySet): boolean {\n\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\tif (value !== undefined && this.changes.get(key)?.local.empty !== false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"segmentPropertiesManager.js","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAMnF,O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,CAAC,GAAG,IAAI,cAAc,CAAC,CACjF,CAAC;YACF,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC9B,gEAAgE;gBAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAkB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACzE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tassert,\n\tDoublyLinkedList,\n\titerateListValuesWhile,\n} from \"@fluidframework/core-utils/internal\";\n\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport type {\n\tAdjustParams,\n\tIMergeTreeAnnotateAdjustMsg,\n\tIMergeTreeAnnotateMsg,\n} from \"./ops.js\";\nimport { type MapLike, type PropertySet, clone, createMap } from \"./properties.js\";\n\n/**\n * Minimally copies properties and the property manager from source to destination.\n * @internal\n */\nexport function copyPropertiesAndManager(\n\tsource: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n\tdestination: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n): void {\n\tif (source.properties) {\n\t\tif (source.propertyManager === undefined) {\n\t\t\tdestination.properties = clone(source.properties);\n\t\t} else {\n\t\t\tdestination.propertyManager ??= new PropertiesManager();\n\t\t\tsource.propertyManager.copyTo(source.properties, destination);\n\t\t}\n\t}\n}\n\ntype PropertyChange = {\n\tseq: number;\n} & ({ adjust: AdjustParams; raw?: undefined } | { raw: unknown; adjust?: undefined });\n\ninterface PropertyChanges {\n\tmsnConsensus: unknown;\n\tremote: DoublyLinkedList<PropertyChange>;\n\tlocal: DoublyLinkedList<PropertyChange>;\n}\n\nfunction computePropertyValue(\n\tconsensus: unknown,\n\t...changes: Iterable<PropertyChange>[]\n): unknown {\n\tlet computedValue: unknown = consensus;\n\tfor (const change of changes) {\n\t\tfor (const op of change) {\n\t\t\tconst { raw, adjust } = op;\n\t\t\tif (adjust === undefined) {\n\t\t\t\tcomputedValue = raw;\n\t\t\t} else {\n\t\t\t\tconst adjusted =\n\t\t\t\t\t(typeof computedValue === \"number\" ? computedValue : 0) + adjust.delta;\n\t\t\t\tif (adjust.max !== undefined && adjusted > adjust.max) {\n\t\t\t\t\tcomputedValue = adjust.max;\n\t\t\t\t} else if (adjust.min !== undefined && adjusted < adjust.min) {\n\t\t\t\t\tcomputedValue = adjust.min;\n\t\t\t\t} else {\n\t\t\t\t\tcomputedValue = adjusted;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn computedValue;\n}\n\n/**\n * @internal\n */\nexport type PropsOrAdjust =\n\t| Pick<IMergeTreeAnnotateAdjustMsg, \"props\" | \"adjust\">\n\t| Pick<IMergeTreeAnnotateMsg, \"props\" | \"adjust\">;\n\nconst opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [\n\t...Object.entries(op.props ?? {})\n\t\t.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])\n\t\t.filter(([_, v]) => v.raw !== undefined),\n\t...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [\n\t\tk,\n\t\t{ adjust, seq },\n\t]),\n];\n\nfunction applyChanges(\n\top: PropsOrAdjust,\n\tseg: { properties?: MapLike<unknown> },\n\tseq: number,\n\trun: (\n\t\tproperties: MapLike<unknown>,\n\t\tdeltas: MapLike<unknown>,\n\t\tkey: string,\n\t\tvalue: PropertyChange,\n\t) => void,\n): MapLike<unknown> {\n\tconst properties = (seg.properties ??= createMap<unknown>());\n\tconst deltas: MapLike<unknown> = {};\n\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\trun(properties, deltas, key, value);\n\t\tif (properties[key] === null) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete properties[key];\n\t\t}\n\t}\n\treturn deltas;\n}\n\n/**\n * The PropertiesManager class handles changes to properties, both remote and local.\n * It manages the lifecycle for local property changes, ensures all property changes are eventually consistent,\n * and provides methods to acknowledge changes, update the minimum sequence number (msn), and copy properties to another manager.\n * This class is essential for maintaining the integrity and consistency of property changes in collaborative environments.\n * @internal\n */\nexport class PropertiesManager {\n\tprivate readonly changes = new Map<string, PropertyChanges>();\n\n\t/**\n\t * Rolls back local property changes.\n\t * This method reverts property changes based on the provided operation and segment.\n\t * If the operation is part of a collaborative session, it ensures that the changes are consistent with the remote state.\n\t *\n\t * @param op - The operation containing property changes. This can be an adjustment or a set of properties.\n\t * @param seg - The segment containing properties. This object may have a properties map that will be modified.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @returns The deltas of the rolled-back properties. This is a map-like object representing the changes that were reverted.\n\t */\n\tpublic rollbackProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tcollaborating: boolean = false,\n\t): MapLike<unknown> {\n\t\treturn applyChanges(op, seg, UniversalSequenceNumber, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\n\t\t\tconst pending = this.changes.get(key);\n\t\t\tif (collaborating) {\n\t\t\t\tassert(\n\t\t\t\t\tpending !== undefined,\n\t\t\t\t\t0xa6f /* Pending changes must exist for rollback when collaborating */,\n\t\t\t\t);\n\t\t\t\tpending.local.pop();\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\t\tthis.changes.delete(key);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tpending === undefined,\n\t\t\t\t\t0xa70 /* Pending changes must not exist when not collaborating */,\n\t\t\t\t);\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t}\n\t\t\tdeltas[key] = previousValue;\n\t\t});\n\t}\n\n\t/**\n\t * Handles property changes.\n\t * This method applies property changes based on the provided operation, segment, sequence number, and collaboration state.\n\t * It also handles rolling back changes if specified.\n\t *\n\t * @param op - The operation containing property changes.\n\t * @param seg - The segment containing properties.\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.\n\t * @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.\n\t */\n\tpublic handleProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tseq: number,\n\t\tmsn: number,\n\t\tcollaborating: boolean = false,\n\t\trollback: boolean = false,\n\t): MapLike<unknown> {\n\t\tif (rollback) {\n\t\t\treturn this.rollbackProperties(op, seg, collaborating);\n\t\t}\n\t\tconst rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\t\t\tif (collaborating) {\n\t\t\t\tconst pending: PropertyChanges | undefined = this.changes.get(key) ?? {\n\t\t\t\t\tmsnConsensus: previousValue,\n\t\t\t\t\tremote: new DoublyLinkedList(),\n\t\t\t\t\tlocal: new DoublyLinkedList(),\n\t\t\t\t};\n\t\t\t\tthis.changes.set(key, pending);\n\t\t\t\tconst local = seq === UnassignedSequenceNumber;\n\t\t\t\tif (local) {\n\t\t\t\t\tpending.local.push(value);\n\t\t\t\t} else {\n\t\t\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\t\t\tif (value.raw !== undefined && pending.remote.empty) {\n\t\t\t\t\t\tpending.msnConsensus = computePropertyValue(pending.msnConsensus, [value]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpending.remote.push(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (local || pending.local.empty || properties[key] !== previousValue) {\n\t\t\t\t\tdeltas[key] = previousValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t\tdeltas[key] = previousValue;\n\t\t\t}\n\t\t});\n\t\tthis.updateMsn(msn);\n\t\treturn rtn;\n\t}\n\n\t/**\n\t * Acknowledges property changes.\n\t * This method acknowledges the property changes based on the provided sequence number and operation.\n\t *\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param op - The operation containing property changes.\n\t */\n\tpublic ack(seq: number, msn: number, op: PropsOrAdjust): void {\n\t\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\t\tconst change = this.changes.get(key);\n\t\t\tconst acked = change?.local?.shift();\n\t\t\tassert(\n\t\t\t\tchange !== undefined && acked !== undefined,\n\t\t\t\t0xa71 /* must have local change to ack */,\n\t\t\t);\n\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\tif (value.raw !== undefined && change.remote.empty) {\n\t\t\t\tchange.msnConsensus = computePropertyValue(change.msnConsensus, [value]);\n\t\t\t} else {\n\t\t\t\tchange.remote.push(value);\n\t\t\t}\n\t\t}\n\t\tthis.updateMsn(msn);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number (msn).\n\t * This method updates the minimum sequence number and removes any changes that have been acknowledged.\n\t *\n\t * @param msn - The minimum sequence number to update.\n\t */\n\tpublic updateMsn(msn: number): void {\n\t\tfor (const [key, pending] of this.changes) {\n\t\t\tpending.msnConsensus = computePropertyValue(\n\t\t\t\tpending.msnConsensus,\n\t\t\t\titerateListValuesWhile(pending.remote.first, (n) => {\n\t\t\t\t\tif (n.data.seq <= msn) {\n\t\t\t\t\t\tn.list?.remove(n);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\tthis.changes.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copies properties to another manager.\n\t * This method copies the properties and their changes from the current manager to the destination manager.\n\t *\n\t * @param oldProps - The old properties to be copied.\n\t * @param dest - The destination object containing properties and property manager.\n\t */\n\tpublic copyTo(\n\t\toldProps: PropertySet | undefined,\n\t\tdest: {\n\t\t\tproperties?: PropertySet;\n\t\t\tpropertyManager?: PropertiesManager;\n\t\t},\n\t): void {\n\t\tconst newManager = (dest.propertyManager ??= new PropertiesManager());\n\t\tdest.properties = clone(oldProps);\n\t\tfor (const [key, { local, remote, msnConsensus }] of this.changes.entries()) {\n\t\t\tnewManager.changes.set(key, {\n\t\t\t\tmsnConsensus,\n\t\t\t\tremote: new DoublyLinkedList(remote.empty ? undefined : remote.map((c) => c.data)),\n\t\t\t\tlocal: new DoublyLinkedList(local.empty ? undefined : local.map((c) => c.data)),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Gets properties at a specific sequence number.\n\t * This method retrieves the properties at the given sequence number.\n\t * This is only needed to support emitting snapshots in the legacy format.\n\t * If we remove the ability to emit the legacy format, we can remove this method, along with the need to track remote changes at all.\n\t *\n\t * @param oldProps - The old properties to be retrieved.\n\t * @param sequenceNumber - The sequence number to get properties at.\n\t * @returns The properties at the given sequence number.\n\t */\n\tpublic getAtSeq(\n\t\toldProps: MapLike<unknown> | undefined,\n\t\tsequenceNumber: number,\n\t): MapLike<unknown> {\n\t\tconst properties: MapLike<unknown> = { ...oldProps };\n\t\tfor (const [key, changes] of this.changes) {\n\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\tchanges.msnConsensus,\n\t\t\t\titerateListValuesWhile(changes.remote.first, (c) => c.data.seq <= sequenceNumber),\n\t\t\t);\n\t\t\tif (properties[key] === null) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete properties[key];\n\t\t\t}\n\t\t}\n\t\treturn properties;\n\t}\n\n\t/**\n\t * Determines if all of the defined properties in a given property set are pending.\n\t *\n\t * @param props - The properties to check.\n\t * @returns True if all the properties are pending, false otherwise.\n\t */\n\tpublic hasPendingProperties(props: PropertySet): boolean {\n\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\tif (value !== undefined && this.changes.get(key)?.local.empty !== false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/merge-tree",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.83.0",
|
|
4
4
|
"description": "Merge tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -81,30 +81,30 @@
|
|
|
81
81
|
"temp-directory": "nyc/.nyc_output"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@fluid-internal/client-utils": "~2.
|
|
85
|
-
"@fluidframework/container-definitions": "~2.
|
|
86
|
-
"@fluidframework/core-interfaces": "~2.
|
|
87
|
-
"@fluidframework/core-utils": "~2.
|
|
88
|
-
"@fluidframework/datastore-definitions": "~2.
|
|
89
|
-
"@fluidframework/driver-definitions": "~2.
|
|
90
|
-
"@fluidframework/runtime-definitions": "~2.
|
|
91
|
-
"@fluidframework/runtime-utils": "~2.
|
|
92
|
-
"@fluidframework/shared-object-base": "~2.
|
|
93
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
84
|
+
"@fluid-internal/client-utils": "~2.83.0",
|
|
85
|
+
"@fluidframework/container-definitions": "~2.83.0",
|
|
86
|
+
"@fluidframework/core-interfaces": "~2.83.0",
|
|
87
|
+
"@fluidframework/core-utils": "~2.83.0",
|
|
88
|
+
"@fluidframework/datastore-definitions": "~2.83.0",
|
|
89
|
+
"@fluidframework/driver-definitions": "~2.83.0",
|
|
90
|
+
"@fluidframework/runtime-definitions": "~2.83.0",
|
|
91
|
+
"@fluidframework/runtime-utils": "~2.83.0",
|
|
92
|
+
"@fluidframework/shared-object-base": "~2.83.0",
|
|
93
|
+
"@fluidframework/telemetry-utils": "~2.83.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
97
97
|
"@biomejs/biome": "~1.9.3",
|
|
98
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
99
|
-
"@fluid-private/stochastic-test-utils": "~2.
|
|
100
|
-
"@fluid-private/test-pairwise-generator": "~2.
|
|
98
|
+
"@fluid-internal/mocha-test-setup": "~2.83.0",
|
|
99
|
+
"@fluid-private/stochastic-test-utils": "~2.83.0",
|
|
100
|
+
"@fluid-private/test-pairwise-generator": "~2.83.0",
|
|
101
101
|
"@fluid-tools/benchmark": "^0.52.0",
|
|
102
102
|
"@fluid-tools/build-cli": "^0.63.0",
|
|
103
103
|
"@fluidframework/build-common": "^2.0.3",
|
|
104
104
|
"@fluidframework/build-tools": "^0.63.0",
|
|
105
|
-
"@fluidframework/eslint-config-fluid": "~2.
|
|
106
|
-
"@fluidframework/merge-tree-previous": "npm:@fluidframework/merge-tree@2.
|
|
107
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
105
|
+
"@fluidframework/eslint-config-fluid": "~2.83.0",
|
|
106
|
+
"@fluidframework/merge-tree-previous": "npm:@fluidframework/merge-tree@2.82.0",
|
|
107
|
+
"@fluidframework/test-runtime-utils": "~2.83.0",
|
|
108
108
|
"@microsoft/api-extractor": "7.52.11",
|
|
109
109
|
"@types/diff": "^3.5.1",
|
|
110
110
|
"@types/mocha": "^10.0.10",
|
|
@@ -392,8 +392,6 @@ export class AttributionCollection implements IAttributionCollection<Attribution
|
|
|
392
392
|
): void {
|
|
393
393
|
const { channels } = summary;
|
|
394
394
|
assert(
|
|
395
|
-
// Destructuring here would require renaming the variables, since seqs is declared below
|
|
396
|
-
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
397
395
|
summary.seqs.length === summary.posBreakpoints.length,
|
|
398
396
|
0x445 /* Invalid attribution summary blob provided */,
|
|
399
397
|
);
|
|
@@ -151,7 +151,7 @@ export type MergeTreeDeltaCallback = (
|
|
|
151
151
|
/**
|
|
152
152
|
* @legacy @beta
|
|
153
153
|
*/
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
155
155
|
export interface IMergeTreeMaintenanceCallbackArgs
|
|
156
156
|
extends IMergeTreeDeltaCallbackArgs<MergeTreeMaintenanceType> {}
|
|
157
157
|
|
package/src/mergeTreeNodeWalk.ts
CHANGED
|
@@ -53,7 +53,6 @@ export function depthFirstNodeWalk(
|
|
|
53
53
|
let childCount = block.childCount;
|
|
54
54
|
let start: IMergeNode | undefined = startChild;
|
|
55
55
|
|
|
56
|
-
// eslint-disable-next-line no-constant-condition
|
|
57
56
|
while (true) {
|
|
58
57
|
// go down to the leaf level
|
|
59
58
|
let blockResult: NodeAction;
|
|
@@ -86,7 +86,6 @@ export type PropsOrAdjust =
|
|
|
86
86
|
|
|
87
87
|
const opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [
|
|
88
88
|
...Object.entries(op.props ?? {})
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
90
89
|
.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])
|
|
91
90
|
.filter(([_, v]) => v.raw !== undefined),
|
|
92
91
|
...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [
|
package/api-extractor-lint.json
DELETED