@fluid-experimental/tree 2.0.0-internal.2.1.1 → 2.0.0-internal.2.2.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.
Files changed (33) hide show
  1. package/dist/EditLog.d.ts +1 -1
  2. package/dist/EditLog.d.ts.map +1 -1
  3. package/dist/EditLog.js +12 -6
  4. package/dist/EditLog.js.map +1 -1
  5. package/dist/HistoryEditFactory.d.ts.map +1 -1
  6. package/dist/HistoryEditFactory.js +4 -2
  7. package/dist/HistoryEditFactory.js.map +1 -1
  8. package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
  9. package/dist/id-compressor/IdCompressor.js +23 -14
  10. package/dist/id-compressor/IdCompressor.js.map +1 -1
  11. package/lib/EditLog.d.ts +1 -1
  12. package/lib/EditLog.d.ts.map +1 -1
  13. package/lib/EditLog.js +12 -6
  14. package/lib/EditLog.js.map +1 -1
  15. package/lib/HistoryEditFactory.d.ts.map +1 -1
  16. package/lib/HistoryEditFactory.js +5 -3
  17. package/lib/HistoryEditFactory.js.map +1 -1
  18. package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
  19. package/lib/id-compressor/IdCompressor.js +23 -14
  20. package/lib/id-compressor/IdCompressor.js.map +1 -1
  21. package/lib/test/EditLog.perf.tests.js +11 -0
  22. package/lib/test/EditLog.perf.tests.js.map +1 -1
  23. package/lib/test/IdCompressor.tests.js +198 -0
  24. package/lib/test/IdCompressor.tests.js.map +1 -1
  25. package/lib/test/utilities/IdCompressorTestUtilities.d.ts +2 -1
  26. package/lib/test/utilities/IdCompressorTestUtilities.d.ts.map +1 -1
  27. package/lib/test/utilities/IdCompressorTestUtilities.js +2 -2
  28. package/lib/test/utilities/IdCompressorTestUtilities.js.map +1 -1
  29. package/package.json +21 -21
  30. package/prettier.config.cjs +8 -0
  31. package/src/EditLog.ts +16 -5
  32. package/src/HistoryEditFactory.ts +5 -2
  33. package/src/id-compressor/IdCompressor.ts +21 -11
package/dist/EditLog.d.ts CHANGED
@@ -175,7 +175,7 @@ export declare class EditLog<TChange = unknown> extends TypedEventEmitter<IEditL
175
175
  private readonly targetLength;
176
176
  private readonly evictionFrequency;
177
177
  private localEditSequence;
178
- private readonly sequenceNumberToIndex;
178
+ private readonly sequenceNumberToIndex?;
179
179
  private _minSequenceNumber;
180
180
  private readonly sequencedEdits;
181
181
  private readonly localEdits;
@@ -1 +1 @@
1
- {"version":3,"file":"EditLog.d.ts","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,GAAG,OAAO;IAChD;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAEpC;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEpC;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEpD;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE5D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AAC,OAAO;IAMf,OAAO,CAAC,UAAU;IAgClB;;OAEG;IACI,MAAM,CAAC,yBAAyB,EAAE,KAAK,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,OAAO;IAM5F;;;OAGG;IACI,iBAAiB,IAAI,cAAc,CAAC,OAAO,EAAE,eAAe,CAAC;IACpE;;;;OAIG;IACI,iBAAiB,CAAC,iBAAiB,EACzC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC,GAC9F,cAAc,CAAC,iBAAiB,EAAE,eAAe,CAAC;IAmCrD;;OAEG;IACU,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAK3E;;OAEG;IACU,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAIlE;;OAEG;IACI,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;CAG5D"}
package/dist/EditLog.js CHANGED
@@ -64,7 +64,6 @@ class EditLog extends common_utils_1.TypedEventEmitter {
64
64
  this.targetLength = targetLength;
65
65
  this.evictionFrequency = evictionFrequency;
66
66
  this.localEditSequence = 0;
67
- this.sequenceNumberToIndex = new sorted_btree_1.default([[0, 0]]);
68
67
  this._minSequenceNumber = 0;
69
68
  this.sequencedEdits = [];
70
69
  this.localEdits = [];
@@ -76,8 +75,14 @@ class EditLog extends common_utils_1.TypedEventEmitter {
76
75
  for (const handler of editAddedHandlers) {
77
76
  this.registerEditAddedHandler(handler);
78
77
  }
79
- for (const handler of editEvictionHandlers) {
80
- this.registerEditEvictionHandler(handler);
78
+ if (targetLength !== Infinity) {
79
+ if (targetLength < 0 || evictionFrequency < 0) {
80
+ (0, Common_1.fail)('targetLength and evictionFrequency should not be negative');
81
+ }
82
+ this.sequenceNumberToIndex = new sorted_btree_1.default([[0, 0]]);
83
+ for (const handler of editEvictionHandlers) {
84
+ this.registerEditEvictionHandler(handler);
85
+ }
81
86
  }
82
87
  editChunks.forEach((editChunkOrHandle) => {
83
88
  var _a;
@@ -266,7 +271,7 @@ class EditLog extends common_utils_1.TypedEventEmitter {
266
271
  * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.
267
272
  */
268
273
  addSequencedEditInternal(edit, info, minSequenceNumber = 0) {
269
- var _a, _b;
274
+ var _a, _b, _c;
270
275
  (0, Common_1.assert)(minSequenceNumber >= this._minSequenceNumber, 'Sequenced edits should carry a monotonically increasing min number');
271
276
  this._minSequenceNumber = minSequenceNumber;
272
277
  const { id } = edit;
@@ -289,11 +294,11 @@ class EditLog extends common_utils_1.TypedEventEmitter {
289
294
  };
290
295
  this.allEditIds.set(id, sequencedEditId);
291
296
  if (info !== undefined) {
292
- this.sequenceNumberToIndex.set(info.sequenceNumber, index);
297
+ (_c = this.sequenceNumberToIndex) === null || _c === void 0 ? void 0 : _c.set(info.sequenceNumber, index);
293
298
  }
294
299
  this.emitAdd(edit, false, encounteredEditId !== undefined);
295
300
  // Check if any edits need to be evicted due to this addition
296
- if (this.numberOfSequencedEdits >= this.evictionFrequency) {
301
+ if (this.sequenceNumberToIndex !== undefined && this.numberOfSequencedEdits >= this.evictionFrequency) {
297
302
  this.evictEdits();
298
303
  }
299
304
  }
@@ -314,6 +319,7 @@ class EditLog extends common_utils_1.TypedEventEmitter {
314
319
  }
315
320
  evictEdits() {
316
321
  var _a, _b;
322
+ (0, Common_1.assert)(this.sequenceNumberToIndex !== undefined, 'Edits should never be evicted if the target length is set to infinity');
317
323
  const minSequenceIndex = (_b = (_a = this.sequenceNumberToIndex.getPairOrNextHigher(this._minSequenceNumber)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : (0, Common_1.fail)('No index associated with that sequence number.');
318
324
  // Exclude any edits in the collab window from being evicted
319
325
  const numberOfEvictableEdits = minSequenceIndex - this.earliestAvailableEditIndex;
@@ -1 +1 @@
1
- {"version":3,"file":"EditLog.js","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,gEAAiC;AACjC,+DAAiE;AAEjE,qCAAuD;AAkJvD;;GAEG;AACH,SAAgB,iBAAiB,CAAU,IAAmB;IAI7D,MAAM,aAAa,mCAAQ,IAAI,KAAE,EAAE,EAAE,SAAS,GAAE,CAAC;IACjD,OAAO,aAAa,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC;AAPD,8CAOC;AAED;;;;GAIG;AACH,SAAgB,oCAAoC,CAAC,OAAyC;IAC7F,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE/B,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1B,eAAe,EAAE,CAAC;SAClB;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AACxB,CAAC;AAXD,oFAWC;AAwBD;;;;;;GAMG;AACH,MAAa,OAA2B,SAAQ,gCAAiC;IA6BhF;;;;;;;;;;;;;OAaG;IACH,YACC,UAAwD,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,EACtE,MAAyB,EAC1C,oBAA0D,EAAE,EAC3C,eAAe,QAAQ,EACvB,oBAAoB,YAAY,GAAG,CAAC,EACrD,uBAAuD,EAAE;QAEzD,KAAK,EAAE,CAAC;QANS,WAAM,GAAN,MAAM,CAAmB;QAEzB,iBAAY,GAAZ,YAAY,CAAW;QACvB,sBAAiB,GAAjB,iBAAiB,CAAmB;QA/C9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AC,gBAAgB,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACI,uBAAuB,CAAC,KAAa;;QAC3C,OAAO,MAAA,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,mCAAI,IAAA,aAAI,EAAC,gBAAgB,CAAC,CAAC;IAChE,CAAC;CACD;AApaD,0BAoaC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport type { IEvent, ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { assert, compareArrays, fail } from './Common';\nimport type { EditId } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport { Edit, EditLogSummary, EditWithoutId, FluidEditHandle } from './persisted-types';\nimport type { ChangeCompressor } from './ChangeCompression';\n\n/**\n * An ordered set of Edits associated with a SharedTree.\n * Supports fast lookup of edits by ID and enforces idempotence.\n * @public\n * @sealed\n */\nexport interface OrderedEditSet<TChange = unknown> {\n\t/**\n\t * The length of this `OrderedEditSet`.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The edit IDs of all edits in the log.\n\t */\n\treadonly editIds: readonly EditId[];\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`.\n\t */\n\tgetIndexOfId(editId: EditId): number;\n\n\t/**\n\t * @returns the id of the edit at the given index within this 'OrderedEditSet'.\n\t */\n\tgetIdAtIndex(index: number): EditId;\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.\n\t */\n\ttryGetIndexOfId(editId: EditId): number | undefined;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t */\n\ttryGetEditAtIndex(index: number): Edit<TChange> | undefined;\n\n\t/**\n\t * @returns the edit with the given identifier within this `OrderedEditSet`.\n\t */\n\ttryGetEditFromId(editId: EditId): Edit<TChange> | undefined;\n\n\t/**\n\t * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\ttryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs.\n\t */\n\tgetEditAtIndex(index: number): Promise<Edit<TChange>>;\n\n\t/**\n\t * @returns the edit at the given index. Must have been added to the log during the current session.\n\t * @deprecated this will be removed in favor of {@link OrderedEditSet.tryGetEditAtIndex}\n\t */\n\tgetEditInSessionAtIndex(index: number): Edit<TChange>;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface EditSequencingInfo {\n\t/**\n\t * The server-assigned sequence number of the op.\n\t */\n\treadonly sequenceNumber: number;\n\t/**\n\t * Last known sequenced edit at the time this op was issued.\n\t */\n\treadonly referenceSequenceNumber: number;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface MessageSequencingInfo extends EditSequencingInfo {\n\t/**\n\t * Last sequenced edit that all clients are guaranteed to be aware of.\n\t * If not specified, then some clients have not seen any edits yet.\n\t */\n\treadonly minimumSequenceNumber?: number;\n}\n\n/**\n * Metadata for a sequenced edit.\n */\nexport interface SequencedOrderedEditId {\n\treadonly isLocal: false;\n\treadonly index: number;\n\t/**\n\t * Information about the edit's relationship to other sequenced edits.\n\t * Undefined iff the edit was loaded from a summary.\n\t */\n\treadonly sequenceInfo?: EditSequencingInfo;\n}\n\n/**\n * Metadata for a local edit.\n */\nexport interface LocalOrderedEditId {\n\treadonly isLocal: true;\n\treadonly localSequence: number;\n}\n\n/**\n * Metadata for an edit.\n */\nexport type OrderedEditId = SequencedOrderedEditId | LocalOrderedEditId;\n\n/**\n * Compressor+interner pair used for encoding an {@link EditLog} into a summary.\n * @internal\n */\nexport interface EditLogEncoder {\n\tcompressor: ChangeCompressor;\n\tinterner: StringInterner;\n}\n\n/**\n * A sequence of edits that may or may not need to be downloaded into the EditLog from an external service\n * @deprecated Edit virtualization is no longer supported.\n */\nexport interface EditChunk<TChange> {\n\thandle?: EditHandle<TChange>;\n\tedits?: EditWithoutId<TChange>[];\n}\n/**\n * EditHandles are used to load edit chunks stored outside of the EditLog.\n * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.\n * @deprecated Edit virtualization is no longer supported.\n * @public\n */\nexport interface EditHandle<TChange> {\n\treadonly get: () => Promise<EditWithoutId<TChange>[]>;\n\treadonly baseHandle: FluidEditHandle;\n}\n\n/**\n * Returns an object that separates an Edit into two fields, id and editWithoutId.\n */\nexport function separateEditAndId<TChange>(edit: Edit<TChange>): {\n\tid: EditId;\n\teditWithoutId: EditWithoutId<TChange>;\n} {\n\tconst editWithoutId = { ...edit, id: undefined };\n\tdelete editWithoutId.id;\n\treturn { id: edit.id, editWithoutId };\n}\n\n/**\n * @param summary - The edit log summary to parse.\n * @returns the number of handles saved to the provided edit log summary.\n * @deprecated Edit virtualization is no longer supported.\n */\nexport function getNumberOfHandlesFromEditLogSummary(summary: EditLogSummary<unknown, unknown>): number {\n\tconst { editChunks } = summary;\n\n\tlet numberOfHandles = 0;\n\teditChunks.forEach(({ chunk }) => {\n\t\tif (!Array.isArray(chunk)) {\n\t\t\tnumberOfHandles++;\n\t\t}\n\t});\n\n\treturn numberOfHandles;\n}\n\n/**\n * Event fired when an edit is added to an `EditLog`.\n * @param edit - The edit that was added to the log\n * @param isLocal - true iff this edit was generated locally\n */\nexport type EditAddedHandler<TChange> = (edit: Edit<TChange>, isLocal: boolean, wasLocal: boolean) => void;\n\n/**\n * Event fired before edits are evicted from the edit log. It takes in a count of the number of edits to evict\n * starting from the oldest in memory edit. To get the edit itself, call {@link EditLog.getEditAtIndex}.\n * The edit index corresponds to the count + {@link EditLog.earliestAvailableEditIndex}.\n */\nexport type EditEvictionHandler = (editsToEvict: number) => void;\n\n/**\n * Events which may be emitted by {@link EditLog}\n * @public\n */\nexport interface IEditLogEvents extends IEvent {\n\t(event: 'unexpectedHistoryChunk', listener: () => void);\n}\n\n/**\n * The edit history log for SharedTree.\n * Contains only completed edits (no in-progress edits).\n * Ordered first by locality (acked or local), then by time of insertion.\n * May not contain more than one edit with the same ID.\n * @sealed\n */\nexport class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents> implements OrderedEditSet<TChange> {\n\tprivate localEditSequence = 0;\n\n\tprivate readonly sequenceNumberToIndex: BTree<number, number> = new BTree([[0, 0]]);\n\tprivate _minSequenceNumber = 0;\n\n\tprivate readonly sequencedEdits: Edit<TChange>[] = [];\n\tprivate readonly localEdits: Edit<TChange>[] = [];\n\n\tprivate readonly allEditIds: Map<EditId, OrderedEditId> = new Map();\n\tprivate _earliestAvailableEditIndex = 0;\n\tprivate readonly _editAddedHandlers: Set<EditAddedHandler<TChange>> = new Set();\n\tprivate readonly _editEvictionHandlers: Set<EditEvictionHandler> = new Set();\n\n\t/**\n\t * @returns The index of the earliest edit stored in this log.\n\t * Edit indices are unique and strictly increasing within the session.\n\t */\n\tpublic get earliestAvailableEditIndex(): number {\n\t\treturn this._earliestAvailableEditIndex;\n\t}\n\n\t/**\n\t * @returns The sequence number of the latest edit known by all nodes.\n\t */\n\tpublic get minSequenceNumber(): number {\n\t\treturn this._minSequenceNumber;\n\t}\n\n\t/**\n\t * Construct an `EditLog` using the given options.\n\t * @param summary - An edit log summary used to populate the edit log.\n\t * @param logger - An optional logger to record telemetry/errors\n\t * @param editAddedHandlers - Optional handlers that are called when edits are added.\n\t * @param targetLength - The target number of sequenced edits that the log will try to store in memory.\n\t * Depending on eviction frequency and the collaboration window, there can be more edits in memory at a given time.\n\t * Edits greater than or equal to the `minSequenceNumber` (aka in the collaboration window) are not evicted.\n\t * @param evictionFrequency - The rate at which edits are evicted from memory. This is a factor of the editLogSize.\n\t * For example, with the default frequency of inMemoryHistorySize * 2 and a size of 10, the log will evict once it reaches 20 sequenced edits\n\t * down to 10 edits, also keeping any that are still in the collaboration window.\n\t * @param editEvictionHandlers - Handlers that are called before edits are evicted from memory. This provides a chance for\n\t * callers to work with the edits before they are lost.\n\t */\n\tpublic constructor(\n\t\tsummary: EditLogSummary<TChange, EditHandle<TChange>> = { editIds: [], editChunks: [] },\n\t\tprivate readonly logger?: ITelemetryLogger,\n\t\teditAddedHandlers: readonly EditAddedHandler<TChange>[] = [],\n\t\tprivate readonly targetLength = Infinity,\n\t\tprivate readonly evictionFrequency = targetLength * 2,\n\t\teditEvictionHandlers: readonly EditEvictionHandler[] = []\n\t) {\n\t\tsuper();\n\t\tconst { editChunks, editIds } = summary;\n\n\t\tfor (const handler of editAddedHandlers) {\n\t\t\tthis.registerEditAddedHandler(handler);\n\t\t}\n\n\t\tfor (const handler of editEvictionHandlers) {\n\t\t\tthis.registerEditEvictionHandler(handler);\n\t\t}\n\n\t\teditChunks.forEach((editChunkOrHandle) => {\n\t\t\tconst { startRevision, chunk } = editChunkOrHandle;\n\n\t\t\tif (Array.isArray(chunk)) {\n\t\t\t\tfor (const [index, edit] of chunk.entries()) {\n\t\t\t\t\tconst editIndex = startRevision + index;\n\t\t\t\t\tconst id = editIds[editIndex];\n\t\t\t\t\tthis.sequencedEdits.push({ id, ...edit });\n\t\t\t\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\t\t\t\tassert(encounteredEditId === undefined, 'Duplicate acked edit.');\n\t\t\t\t\tthis.allEditIds.set(id, { isLocal: false, index: editIndex });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Ignore any edit handles, these edits are now unrecoverable.\n\t\t\t\t// This should instead download the edit chunk and store them but history is not\n\t\t\t\t// being used so we're going with the simpler solution.\n\t\t\t\tthis.logger?.sendErrorEvent({ eventName: 'UnexpectedEditHandleInSummary' });\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Registers a handler for when an edit is added to this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditAddedHandler(handler: EditAddedHandler<TChange>): () => void {\n\t\tthis._editAddedHandlers.add(handler);\n\t\treturn () => this._editAddedHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditAddedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editAddedHandlers(): readonly EditAddedHandler<TChange>[] {\n\t\treturn Array.from(this._editAddedHandlers);\n\t}\n\n\t/**\n\t * Registers a handler that is called before an edit is evicted from this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditEvictionHandler(handler: EditEvictionHandler): () => void {\n\t\tthis._editEvictionHandlers.add(handler);\n\t\treturn () => this._editEvictionHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditEvictedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editEvictedHandlers(): readonly EditEvictionHandler[] {\n\t\treturn Array.from(this._editEvictionHandlers);\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.length}\n\t */\n\tpublic get length(): number {\n\t\treturn this.numberOfSequencedEdits + this.numberOfLocalEdits;\n\t}\n\n\t/**\n\t * The number of sequenced (acked) edits in the log.\n\t */\n\tpublic get numberOfSequencedEdits(): number {\n\t\treturn this.sequencedEdits.length;\n\t}\n\n\t/**\n\t * The number of local (unacked) edits in the log.\n\t */\n\tpublic get numberOfLocalEdits(): number {\n\t\treturn this.localEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.editIds}\n\t */\n\tpublic get editIds(): EditId[] {\n\t\treturn this.sequencedEdits.map(({ id }) => id).concat(this.localEdits.map(({ id }) => id));\n\t}\n\n\t/**\n\t * @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).\n\t */\n\tpublic isLocalEdit(editId: EditId): boolean {\n\t\tconst entry = this.allEditIds.get(editId);\n\t\treturn entry?.isLocal ?? false;\n\t}\n\n\t/**\n\t * @returns true iff the revision is a sequenced revision (not local).\n\t */\n\tpublic isSequencedRevision(revision: number): boolean {\n\t\treturn revision <= this.sequencedEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetIndexOfId}\n\t */\n\tpublic tryGetIndexOfId(editId: EditId): number | undefined {\n\t\tconst orderedEdit = this.allEditIds.get(editId);\n\t\tif (orderedEdit === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (orderedEdit.isLocal) {\n\t\t\tconst firstLocal = this.allEditIds.get(this.localEdits[0].id) ?? fail('edit not found');\n\t\t\tassert(firstLocal.isLocal);\n\t\t\treturn (\n\t\t\t\tthis._earliestAvailableEditIndex +\n\t\t\t\tthis.numberOfSequencedEdits +\n\t\t\t\torderedEdit.localSequence -\n\t\t\t\tfirstLocal.localSequence\n\t\t\t);\n\t\t}\n\t\treturn orderedEdit.index;\n\t}\n\n\t/**\n\t * @returns Edit metadata for the edit with the given `editId`.\n\t */\n\tpublic getOrderedEditId(editId: EditId): OrderedEditId {\n\t\treturn this.allEditIds.get(editId) ?? fail('All edits should exist in this map');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIndexOfId}\n\t */\n\tpublic getIndexOfId(editId: EditId): number {\n\t\treturn this.tryGetIndexOfId(editId) ?? fail('edit not found');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIdAtIndex}\n\t */\n\tpublic getIdAtIndex(index: number): EditId {\n\t\tif (this._earliestAvailableEditIndex + this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits].id;\n\t\t}\n\n\t\treturn this.sequencedEdits[index - this._earliestAvailableEditIndex].id;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEditAtIndex}\n\t */\n\tpublic tryGetEditAtIndex(index: number): Edit<TChange> | undefined {\n\t\tif (this._earliestAvailableEditIndex + this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t\t}\n\n\t\treturn this.sequencedEdits[index - this._earliestAvailableEditIndex];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEditFromId}\n\t */\n\tpublic tryGetEditFromId(editId: EditId): Edit<TChange> | undefined {\n\t\tconst index = this.tryGetIndexOfId(editId);\n\t\treturn index !== undefined ? this.tryGetEditAtIndex(index) : undefined;\n\t}\n\n\t/**\n\t * Sequences all local edits.\n\t */\n\tpublic sequenceLocalEdits(): void {\n\t\tthis.localEdits.slice().forEach((edit) => this.addSequencedEditInternal(edit));\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t *\n\t */\n\tpublic addSequencedEdit(edit: Edit<TChange>, message: MessageSequencingInfo): void {\n\t\tthis.addSequencedEditInternal(edit, message, message.minimumSequenceNumber);\n\t}\n\n\t/**\n\t * Returns all local edits from this EditLog\n\t * This is useful for op format upgrades, which might warrant re-submission of these ops using the new format.\n\t * See the breaking change documentation for more information.\n\t */\n\tpublic *getLocalEdits(): Iterable<Edit<TChange>> {\n\t\tfor (const edit of this.localEdits) {\n\t\t\tyield edit;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t */\n\tprivate addSequencedEditInternal(\n\t\tedit: Edit<TChange>,\n\t\tinfo?: EditSequencingInfo,\n\t\tminSequenceNumber: number = 0\n\t): void {\n\t\tassert(\n\t\t\tminSequenceNumber >= this._minSequenceNumber,\n\t\t\t'Sequenced edits should carry a monotonically increasing min number'\n\t\t);\n\t\tthis._minSequenceNumber = minSequenceNumber;\n\n\t\tconst { id } = edit;\n\t\t// The index of the sequenced edit to add\n\t\tconst index = this._earliestAvailableEditIndex + this.numberOfSequencedEdits;\n\n\t\t// Remove the edit from local edits if it exists.\n\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\tif (encounteredEditId !== undefined) {\n\t\t\t// New edit already exits: it must have been a local edit.\n\t\t\tassert(encounteredEditId.isLocal, 'Duplicate acked edit.');\n\t\t\t// Remove it from localEdits. Due to ordering requirements, it must be first.\n\t\t\tconst oldLocalEditId = this.localEdits.shift()?.id ?? fail('Local edit should exist');\n\t\t\tassert(oldLocalEditId === id, 'Causal ordering should be upheld');\n\t\t}\n\n\t\tthis.sequencedEdits.push(edit);\n\n\t\tconst sequencedEditId: SequencedOrderedEditId = {\n\t\t\tindex,\n\t\t\tisLocal: false,\n\t\t\tsequenceInfo: info,\n\t\t};\n\t\tthis.allEditIds.set(id, sequencedEditId);\n\t\tif (info !== undefined) {\n\t\t\tthis.sequenceNumberToIndex.set(info.sequenceNumber, index);\n\t\t}\n\t\tthis.emitAdd(edit, false, encounteredEditId !== undefined);\n\n\t\t// Check if any edits need to be evicted due to this addition\n\t\tif (this.numberOfSequencedEdits >= this.evictionFrequency) {\n\t\t\tthis.evictEdits();\n\t\t}\n\t}\n\n\t/**\n\t * Adds a non-sequenced (local) edit to the edit log.\n\t * Duplicate edits are ignored.\n\t */\n\tpublic addLocalEdit(edit: Edit<TChange>): void {\n\t\tthis.localEdits.push(edit);\n\t\tconst localEditId: LocalOrderedEditId = { localSequence: this.localEditSequence++, isLocal: true };\n\t\tthis.allEditIds.set(edit.id, localEditId);\n\t\tthis.emitAdd(edit, true, false);\n\t}\n\n\tprivate emitAdd(editAdded: Edit<TChange>, isLocal: boolean, wasLocal: boolean): void {\n\t\tfor (const handler of this._editAddedHandlers) {\n\t\t\thandler(editAdded, isLocal, wasLocal);\n\t\t}\n\t}\n\n\tprivate evictEdits(): void {\n\t\tconst minSequenceIndex =\n\t\t\tthis.sequenceNumberToIndex.getPairOrNextHigher(this._minSequenceNumber)?.[1] ??\n\t\t\tfail('No index associated with that sequence number.');\n\t\t// Exclude any edits in the collab window from being evicted\n\t\tconst numberOfEvictableEdits = minSequenceIndex - this.earliestAvailableEditIndex;\n\n\t\tif (numberOfEvictableEdits > 0) {\n\t\t\t// Evict either all but the target log size or the number of evictable edits, whichever is smaller\n\t\t\tconst numberOfDesiredEditsToEvict = this.numberOfSequencedEdits - this.targetLength;\n\t\t\tconst numberOfEditsToEvict = Math.min(numberOfEvictableEdits, numberOfDesiredEditsToEvict);\n\t\t\tfor (const handler of this._editEvictionHandlers) {\n\t\t\t\thandler(numberOfEditsToEvict);\n\t\t\t}\n\n\t\t\t// Remove the edits and move up the earliest available index\n\t\t\tconst removedEdits = this.sequencedEdits.splice(0, numberOfEditsToEvict);\n\t\t\tthis._earliestAvailableEditIndex += numberOfEditsToEvict;\n\n\t\t\t// On eviction, we need to remove the IDs of edits that have been evicted\n\t\t\tremovedEdits.forEach((edit) => this.allEditIds.delete(edit.id));\n\n\t\t\t// The minSequenceNumber is strictly increasing so we can clear sequence numbers before it\n\t\t\tthis.sequenceNumberToIndex.deleteRange(0, this._minSequenceNumber, false);\n\t\t}\n\t}\n\n\t/**\n\t * @returns true iff this `EditLog` and `other` are equivalent, regardless of locality.\n\t */\n\tpublic equals<TOtherChangeTypesInternal>(other: EditLog<TOtherChangeTypesInternal>): boolean {\n\t\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\t\treturn compareArrays(this.editIds, other.editIds);\n\t}\n\n\t/**\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary(): EditLogSummary<TChange, FluidEditHandle>;\n\t/**\n\t * @param compressEdit - a function which compresses edits\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TCompressedChange, FluidEditHandle>;\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit?: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TChange, FluidEditHandle> | EditLogSummary<TCompressedChange, FluidEditHandle> {\n\t\tconst editIds = this.sequencedEdits.map(({ id }) => id);\n\t\treturn compressEdit !== undefined\n\t\t\t? {\n\t\t\t\t\teditChunks:\n\t\t\t\t\t\tthis.sequencedEdits.length === 0\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// Store all edits within a single \"chunk\"\n\t\t\t\t\t\t\t\t\t\tstartRevision: 0,\n\t\t\t\t\t\t\t\t\t\tchunk: this.sequencedEdits.map((edit) => compressEdit(edit)),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ],\n\t\t\t\t\teditIds,\n\t\t\t }\n\t\t\t: {\n\t\t\t\t\teditChunks:\n\t\t\t\t\t\tthis.sequencedEdits.length === 0\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// Store all edits within a single \"chunk\"\n\t\t\t\t\t\t\t\t\t\tstartRevision: 0,\n\t\t\t\t\t\t\t\t\t\tchunk: this.sequencedEdits.map(({ changes }) => ({ changes })),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ],\n\t\t\t\t\teditIds,\n\t\t\t };\n\t}\n\n\t// APIS DEPRECATED DUE TO HISTORY'S PEACEFUL DEATH\n\t/**\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\tpublic async tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined> {\n\t\tconst index = this.tryGetIndexOfId(editId);\n\t\treturn index !== undefined ? this.tryGetEditAtIndex(index) : undefined;\n\t}\n\n\t/**\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\tpublic async getEditAtIndex(index: number): Promise<Edit<TChange>> {\n\t\treturn this.tryGetEditAtIndex(index) ?? fail('Edit not found');\n\t}\n\n\t/**\n\t * @deprecated Edit virtualization is no longer supported. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\tpublic getEditInSessionAtIndex(index: number): Edit<TChange> {\n\t\treturn this.tryGetEditAtIndex(index) ?? fail('Edit not found');\n\t}\n}\n"]}
1
+ {"version":3,"file":"EditLog.js","sourceRoot":"","sources":["../src/EditLog.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,gEAAiC;AACjC,+DAAiE;AAEjE,qCAAuD;AAkJvD;;GAEG;AACH,SAAgB,iBAAiB,CAAU,IAAmB;IAI7D,MAAM,aAAa,mCAAQ,IAAI,KAAE,EAAE,EAAE,SAAS,GAAE,CAAC;IACjD,OAAO,aAAa,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC;AAPD,8CAOC;AAED;;;;GAIG;AACH,SAAgB,oCAAoC,CAAC,OAAyC;IAC7F,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE/B,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1B,eAAe,EAAE,CAAC;SAClB;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AACxB,CAAC;AAXD,oFAWC;AAwBD;;;;;;GAMG;AACH,MAAa,OAA2B,SAAQ,gCAAiC;IA6BhF;;;;;;;;;;;;;OAaG;IACH,YACC,UAAwD,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,EACtE,MAAyB,EAC1C,oBAA0D,EAAE,EAC3C,eAAe,QAAQ,EACvB,oBAAoB,YAAY,GAAG,CAAC,EACrD,uBAAu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AAC;yBAC9D;qBACA;gBACL,OAAO;aACN,CAAC;IACN,CAAC;IAED,kDAAkD;IAClD;;OAEG;IACI,KAAK,CAAC,UAAU,CAAC,MAAc;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3C,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,cAAc,CAAC,KAAa;;QACxC,OAAO,MAAA,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,mCAAI,IAAA,aAAI,EAAC,gBAAgB,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACI,uBAAuB,CAAC,KAAa;;QAC3C,OAAO,MAAA,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,mCAAI,IAAA,aAAI,EAAC,gBAAgB,CAAC,CAAC;IAChE,CAAC;CACD;AA/aD,0BA+aC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport BTree from 'sorted-btree';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport type { IEvent, ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { assert, compareArrays, fail } from './Common';\nimport type { EditId } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport { Edit, EditLogSummary, EditWithoutId, FluidEditHandle } from './persisted-types';\nimport type { ChangeCompressor } from './ChangeCompression';\n\n/**\n * An ordered set of Edits associated with a SharedTree.\n * Supports fast lookup of edits by ID and enforces idempotence.\n * @public\n * @sealed\n */\nexport interface OrderedEditSet<TChange = unknown> {\n\t/**\n\t * The length of this `OrderedEditSet`.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The edit IDs of all edits in the log.\n\t */\n\treadonly editIds: readonly EditId[];\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`.\n\t */\n\tgetIndexOfId(editId: EditId): number;\n\n\t/**\n\t * @returns the id of the edit at the given index within this 'OrderedEditSet'.\n\t */\n\tgetIdAtIndex(index: number): EditId;\n\n\t/**\n\t * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.\n\t */\n\ttryGetIndexOfId(editId: EditId): number | undefined;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t */\n\ttryGetEditAtIndex(index: number): Edit<TChange> | undefined;\n\n\t/**\n\t * @returns the edit with the given identifier within this `OrderedEditSet`.\n\t */\n\ttryGetEditFromId(editId: EditId): Edit<TChange> | undefined;\n\n\t/**\n\t * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\ttryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;\n\n\t/**\n\t * @returns the edit at the given index within this `OrderedEditSet`.\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs.\n\t */\n\tgetEditAtIndex(index: number): Promise<Edit<TChange>>;\n\n\t/**\n\t * @returns the edit at the given index. Must have been added to the log during the current session.\n\t * @deprecated this will be removed in favor of {@link OrderedEditSet.tryGetEditAtIndex}\n\t */\n\tgetEditInSessionAtIndex(index: number): Edit<TChange>;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface EditSequencingInfo {\n\t/**\n\t * The server-assigned sequence number of the op.\n\t */\n\treadonly sequenceNumber: number;\n\t/**\n\t * Last known sequenced edit at the time this op was issued.\n\t */\n\treadonly referenceSequenceNumber: number;\n}\n\n/**\n * Server-provided metadata for edits that have been sequenced.\n */\nexport interface MessageSequencingInfo extends EditSequencingInfo {\n\t/**\n\t * Last sequenced edit that all clients are guaranteed to be aware of.\n\t * If not specified, then some clients have not seen any edits yet.\n\t */\n\treadonly minimumSequenceNumber?: number;\n}\n\n/**\n * Metadata for a sequenced edit.\n */\nexport interface SequencedOrderedEditId {\n\treadonly isLocal: false;\n\treadonly index: number;\n\t/**\n\t * Information about the edit's relationship to other sequenced edits.\n\t * Undefined iff the edit was loaded from a summary.\n\t */\n\treadonly sequenceInfo?: EditSequencingInfo;\n}\n\n/**\n * Metadata for a local edit.\n */\nexport interface LocalOrderedEditId {\n\treadonly isLocal: true;\n\treadonly localSequence: number;\n}\n\n/**\n * Metadata for an edit.\n */\nexport type OrderedEditId = SequencedOrderedEditId | LocalOrderedEditId;\n\n/**\n * Compressor+interner pair used for encoding an {@link EditLog} into a summary.\n * @internal\n */\nexport interface EditLogEncoder {\n\tcompressor: ChangeCompressor;\n\tinterner: StringInterner;\n}\n\n/**\n * A sequence of edits that may or may not need to be downloaded into the EditLog from an external service\n * @deprecated Edit virtualization is no longer supported.\n */\nexport interface EditChunk<TChange> {\n\thandle?: EditHandle<TChange>;\n\tedits?: EditWithoutId<TChange>[];\n}\n/**\n * EditHandles are used to load edit chunks stored outside of the EditLog.\n * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.\n * @deprecated Edit virtualization is no longer supported.\n * @public\n */\nexport interface EditHandle<TChange> {\n\treadonly get: () => Promise<EditWithoutId<TChange>[]>;\n\treadonly baseHandle: FluidEditHandle;\n}\n\n/**\n * Returns an object that separates an Edit into two fields, id and editWithoutId.\n */\nexport function separateEditAndId<TChange>(edit: Edit<TChange>): {\n\tid: EditId;\n\teditWithoutId: EditWithoutId<TChange>;\n} {\n\tconst editWithoutId = { ...edit, id: undefined };\n\tdelete editWithoutId.id;\n\treturn { id: edit.id, editWithoutId };\n}\n\n/**\n * @param summary - The edit log summary to parse.\n * @returns the number of handles saved to the provided edit log summary.\n * @deprecated Edit virtualization is no longer supported.\n */\nexport function getNumberOfHandlesFromEditLogSummary(summary: EditLogSummary<unknown, unknown>): number {\n\tconst { editChunks } = summary;\n\n\tlet numberOfHandles = 0;\n\teditChunks.forEach(({ chunk }) => {\n\t\tif (!Array.isArray(chunk)) {\n\t\t\tnumberOfHandles++;\n\t\t}\n\t});\n\n\treturn numberOfHandles;\n}\n\n/**\n * Event fired when an edit is added to an `EditLog`.\n * @param edit - The edit that was added to the log\n * @param isLocal - true iff this edit was generated locally\n */\nexport type EditAddedHandler<TChange> = (edit: Edit<TChange>, isLocal: boolean, wasLocal: boolean) => void;\n\n/**\n * Event fired before edits are evicted from the edit log. It takes in a count of the number of edits to evict\n * starting from the oldest in memory edit. To get the edit itself, call {@link EditLog.getEditAtIndex}.\n * The edit index corresponds to the count + {@link EditLog.earliestAvailableEditIndex}.\n */\nexport type EditEvictionHandler = (editsToEvict: number) => void;\n\n/**\n * Events which may be emitted by {@link EditLog}\n * @public\n */\nexport interface IEditLogEvents extends IEvent {\n\t(event: 'unexpectedHistoryChunk', listener: () => void);\n}\n\n/**\n * The edit history log for SharedTree.\n * Contains only completed edits (no in-progress edits).\n * Ordered first by locality (acked or local), then by time of insertion.\n * May not contain more than one edit with the same ID.\n * @sealed\n */\nexport class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents> implements OrderedEditSet<TChange> {\n\tprivate localEditSequence = 0;\n\n\tprivate readonly sequenceNumberToIndex?: BTree<number, number>;\n\tprivate _minSequenceNumber = 0;\n\n\tprivate readonly sequencedEdits: Edit<TChange>[] = [];\n\tprivate readonly localEdits: Edit<TChange>[] = [];\n\n\tprivate readonly allEditIds: Map<EditId, OrderedEditId> = new Map();\n\tprivate _earliestAvailableEditIndex = 0;\n\tprivate readonly _editAddedHandlers: Set<EditAddedHandler<TChange>> = new Set();\n\tprivate readonly _editEvictionHandlers: Set<EditEvictionHandler> = new Set();\n\n\t/**\n\t * @returns The index of the earliest edit stored in this log.\n\t * Edit indices are unique and strictly increasing within the session.\n\t */\n\tpublic get earliestAvailableEditIndex(): number {\n\t\treturn this._earliestAvailableEditIndex;\n\t}\n\n\t/**\n\t * @returns The sequence number of the latest edit known by all nodes.\n\t */\n\tpublic get minSequenceNumber(): number {\n\t\treturn this._minSequenceNumber;\n\t}\n\n\t/**\n\t * Construct an `EditLog` using the given options.\n\t * @param summary - An edit log summary used to populate the edit log.\n\t * @param logger - An optional logger to record telemetry/errors\n\t * @param editAddedHandlers - Optional handlers that are called when edits are added.\n\t * @param targetLength - The target number of sequenced edits that the log will try to store in memory.\n\t * Depending on eviction frequency and the collaboration window, there can be more edits in memory at a given time.\n\t * Edits greater than or equal to the `minSequenceNumber` (aka in the collaboration window) are not evicted.\n\t * @param evictionFrequency - The rate at which edits are evicted from memory. This is a factor of the editLogSize.\n\t * For example, with the default frequency of inMemoryHistorySize * 2 and a size of 10, the log will evict once it reaches 20 sequenced edits\n\t * down to 10 edits, also keeping any that are still in the collaboration window.\n\t * @param editEvictionHandlers - Handlers that are called before edits are evicted from memory. This provides a chance for\n\t * callers to work with the edits before they are lost.\n\t */\n\tpublic constructor(\n\t\tsummary: EditLogSummary<TChange, EditHandle<TChange>> = { editIds: [], editChunks: [] },\n\t\tprivate readonly logger?: ITelemetryLogger,\n\t\teditAddedHandlers: readonly EditAddedHandler<TChange>[] = [],\n\t\tprivate readonly targetLength = Infinity,\n\t\tprivate readonly evictionFrequency = targetLength * 2,\n\t\teditEvictionHandlers: readonly EditEvictionHandler[] = []\n\t) {\n\t\tsuper();\n\t\tconst { editChunks, editIds } = summary;\n\n\t\tfor (const handler of editAddedHandlers) {\n\t\t\tthis.registerEditAddedHandler(handler);\n\t\t}\n\n\t\tif (targetLength !== Infinity) {\n\t\t\tif (targetLength < 0 || evictionFrequency < 0) {\n\t\t\t\tfail('targetLength and evictionFrequency should not be negative');\n\t\t\t}\n\t\t\tthis.sequenceNumberToIndex = new BTree([[0, 0]]);\n\t\t\tfor (const handler of editEvictionHandlers) {\n\t\t\t\tthis.registerEditEvictionHandler(handler);\n\t\t\t}\n\t\t}\n\n\t\teditChunks.forEach((editChunkOrHandle) => {\n\t\t\tconst { startRevision, chunk } = editChunkOrHandle;\n\n\t\t\tif (Array.isArray(chunk)) {\n\t\t\t\tfor (const [index, edit] of chunk.entries()) {\n\t\t\t\t\tconst editIndex = startRevision + index;\n\t\t\t\t\tconst id = editIds[editIndex];\n\t\t\t\t\tthis.sequencedEdits.push({ id, ...edit });\n\t\t\t\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\t\t\t\tassert(encounteredEditId === undefined, 'Duplicate acked edit.');\n\t\t\t\t\tthis.allEditIds.set(id, { isLocal: false, index: editIndex });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Ignore any edit handles, these edits are now unrecoverable.\n\t\t\t\t// This should instead download the edit chunk and store them but history is not\n\t\t\t\t// being used so we're going with the simpler solution.\n\t\t\t\tthis.logger?.sendErrorEvent({ eventName: 'UnexpectedEditHandleInSummary' });\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Registers a handler for when an edit is added to this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditAddedHandler(handler: EditAddedHandler<TChange>): () => void {\n\t\tthis._editAddedHandlers.add(handler);\n\t\treturn () => this._editAddedHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditAddedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editAddedHandlers(): readonly EditAddedHandler<TChange>[] {\n\t\treturn Array.from(this._editAddedHandlers);\n\t}\n\n\t/**\n\t * Registers a handler that is called before an edit is evicted from this `EditLog`.\n\t * @returns A callback which can be invoked to unregister this handler.\n\t */\n\tpublic registerEditEvictionHandler(handler: EditEvictionHandler): () => void {\n\t\tthis._editEvictionHandlers.add(handler);\n\t\treturn () => this._editEvictionHandlers.delete(handler);\n\t}\n\n\t/**\n\t * @returns the `EditEvictedHandler`s registered on this `EditLog`.\n\t */\n\tpublic get editEvictedHandlers(): readonly EditEvictionHandler[] {\n\t\treturn Array.from(this._editEvictionHandlers);\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.length}\n\t */\n\tpublic get length(): number {\n\t\treturn this.numberOfSequencedEdits + this.numberOfLocalEdits;\n\t}\n\n\t/**\n\t * The number of sequenced (acked) edits in the log.\n\t */\n\tpublic get numberOfSequencedEdits(): number {\n\t\treturn this.sequencedEdits.length;\n\t}\n\n\t/**\n\t * The number of local (unacked) edits in the log.\n\t */\n\tpublic get numberOfLocalEdits(): number {\n\t\treturn this.localEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.editIds}\n\t */\n\tpublic get editIds(): EditId[] {\n\t\treturn this.sequencedEdits.map(({ id }) => id).concat(this.localEdits.map(({ id }) => id));\n\t}\n\n\t/**\n\t * @returns true iff the edit is contained in this 'EditLog' and it is a local edit (not sequenced).\n\t */\n\tpublic isLocalEdit(editId: EditId): boolean {\n\t\tconst entry = this.allEditIds.get(editId);\n\t\treturn entry?.isLocal ?? false;\n\t}\n\n\t/**\n\t * @returns true iff the revision is a sequenced revision (not local).\n\t */\n\tpublic isSequencedRevision(revision: number): boolean {\n\t\treturn revision <= this.sequencedEdits.length;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetIndexOfId}\n\t */\n\tpublic tryGetIndexOfId(editId: EditId): number | undefined {\n\t\tconst orderedEdit = this.allEditIds.get(editId);\n\t\tif (orderedEdit === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (orderedEdit.isLocal) {\n\t\t\tconst firstLocal = this.allEditIds.get(this.localEdits[0].id) ?? fail('edit not found');\n\t\t\tassert(firstLocal.isLocal);\n\t\t\treturn (\n\t\t\t\tthis._earliestAvailableEditIndex +\n\t\t\t\tthis.numberOfSequencedEdits +\n\t\t\t\torderedEdit.localSequence -\n\t\t\t\tfirstLocal.localSequence\n\t\t\t);\n\t\t}\n\t\treturn orderedEdit.index;\n\t}\n\n\t/**\n\t * @returns Edit metadata for the edit with the given `editId`.\n\t */\n\tpublic getOrderedEditId(editId: EditId): OrderedEditId {\n\t\treturn this.allEditIds.get(editId) ?? fail('All edits should exist in this map');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIndexOfId}\n\t */\n\tpublic getIndexOfId(editId: EditId): number {\n\t\treturn this.tryGetIndexOfId(editId) ?? fail('edit not found');\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.getIdAtIndex}\n\t */\n\tpublic getIdAtIndex(index: number): EditId {\n\t\tif (this._earliestAvailableEditIndex + this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits].id;\n\t\t}\n\n\t\treturn this.sequencedEdits[index - this._earliestAvailableEditIndex].id;\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEditAtIndex}\n\t */\n\tpublic tryGetEditAtIndex(index: number): Edit<TChange> | undefined {\n\t\tif (this._earliestAvailableEditIndex + this.numberOfSequencedEdits <= index) {\n\t\t\treturn this.localEdits[index - this.numberOfSequencedEdits];\n\t\t}\n\n\t\treturn this.sequencedEdits[index - this._earliestAvailableEditIndex];\n\t}\n\n\t/**\n\t * {@inheritDoc OrderedEditSet.tryGetEditFromId}\n\t */\n\tpublic tryGetEditFromId(editId: EditId): Edit<TChange> | undefined {\n\t\tconst index = this.tryGetIndexOfId(editId);\n\t\treturn index !== undefined ? this.tryGetEditAtIndex(index) : undefined;\n\t}\n\n\t/**\n\t * Sequences all local edits.\n\t */\n\tpublic sequenceLocalEdits(): void {\n\t\tthis.localEdits.slice().forEach((edit) => this.addSequencedEditInternal(edit));\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t *\n\t */\n\tpublic addSequencedEdit(edit: Edit<TChange>, message: MessageSequencingInfo): void {\n\t\tthis.addSequencedEditInternal(edit, message, message.minimumSequenceNumber);\n\t}\n\n\t/**\n\t * Returns all local edits from this EditLog\n\t * This is useful for op format upgrades, which might warrant re-submission of these ops using the new format.\n\t * See the breaking change documentation for more information.\n\t */\n\tpublic *getLocalEdits(): Iterable<Edit<TChange>> {\n\t\tfor (const edit of this.localEdits) {\n\t\t\tyield edit;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a sequenced (non-local) edit to the edit log.\n\t * If the id of the supplied edit matches a local edit already present in the log, the local edit will be replaced.\n\t */\n\tprivate addSequencedEditInternal(\n\t\tedit: Edit<TChange>,\n\t\tinfo?: EditSequencingInfo,\n\t\tminSequenceNumber: number = 0\n\t): void {\n\t\tassert(\n\t\t\tminSequenceNumber >= this._minSequenceNumber,\n\t\t\t'Sequenced edits should carry a monotonically increasing min number'\n\t\t);\n\t\tthis._minSequenceNumber = minSequenceNumber;\n\n\t\tconst { id } = edit;\n\t\t// The index of the sequenced edit to add\n\t\tconst index = this._earliestAvailableEditIndex + this.numberOfSequencedEdits;\n\n\t\t// Remove the edit from local edits if it exists.\n\t\tconst encounteredEditId = this.allEditIds.get(id);\n\t\tif (encounteredEditId !== undefined) {\n\t\t\t// New edit already exits: it must have been a local edit.\n\t\t\tassert(encounteredEditId.isLocal, 'Duplicate acked edit.');\n\t\t\t// Remove it from localEdits. Due to ordering requirements, it must be first.\n\t\t\tconst oldLocalEditId = this.localEdits.shift()?.id ?? fail('Local edit should exist');\n\t\t\tassert(oldLocalEditId === id, 'Causal ordering should be upheld');\n\t\t}\n\n\t\tthis.sequencedEdits.push(edit);\n\n\t\tconst sequencedEditId: SequencedOrderedEditId = {\n\t\t\tindex,\n\t\t\tisLocal: false,\n\t\t\tsequenceInfo: info,\n\t\t};\n\t\tthis.allEditIds.set(id, sequencedEditId);\n\t\tif (info !== undefined) {\n\t\t\tthis.sequenceNumberToIndex?.set(info.sequenceNumber, index);\n\t\t}\n\t\tthis.emitAdd(edit, false, encounteredEditId !== undefined);\n\n\t\t// Check if any edits need to be evicted due to this addition\n\t\tif (this.sequenceNumberToIndex !== undefined && this.numberOfSequencedEdits >= this.evictionFrequency) {\n\t\t\tthis.evictEdits();\n\t\t}\n\t}\n\n\t/**\n\t * Adds a non-sequenced (local) edit to the edit log.\n\t * Duplicate edits are ignored.\n\t */\n\tpublic addLocalEdit(edit: Edit<TChange>): void {\n\t\tthis.localEdits.push(edit);\n\t\tconst localEditId: LocalOrderedEditId = { localSequence: this.localEditSequence++, isLocal: true };\n\t\tthis.allEditIds.set(edit.id, localEditId);\n\t\tthis.emitAdd(edit, true, false);\n\t}\n\n\tprivate emitAdd(editAdded: Edit<TChange>, isLocal: boolean, wasLocal: boolean): void {\n\t\tfor (const handler of this._editAddedHandlers) {\n\t\t\thandler(editAdded, isLocal, wasLocal);\n\t\t}\n\t}\n\n\tprivate evictEdits(): void {\n\t\tassert(\n\t\t\tthis.sequenceNumberToIndex !== undefined,\n\t\t\t'Edits should never be evicted if the target length is set to infinity'\n\t\t);\n\n\t\tconst minSequenceIndex =\n\t\t\tthis.sequenceNumberToIndex.getPairOrNextHigher(this._minSequenceNumber)?.[1] ??\n\t\t\tfail('No index associated with that sequence number.');\n\t\t// Exclude any edits in the collab window from being evicted\n\t\tconst numberOfEvictableEdits = minSequenceIndex - this.earliestAvailableEditIndex;\n\n\t\tif (numberOfEvictableEdits > 0) {\n\t\t\t// Evict either all but the target log size or the number of evictable edits, whichever is smaller\n\t\t\tconst numberOfDesiredEditsToEvict = this.numberOfSequencedEdits - this.targetLength;\n\t\t\tconst numberOfEditsToEvict = Math.min(numberOfEvictableEdits, numberOfDesiredEditsToEvict);\n\t\t\tfor (const handler of this._editEvictionHandlers) {\n\t\t\t\thandler(numberOfEditsToEvict);\n\t\t\t}\n\n\t\t\t// Remove the edits and move up the earliest available index\n\t\t\tconst removedEdits = this.sequencedEdits.splice(0, numberOfEditsToEvict);\n\t\t\tthis._earliestAvailableEditIndex += numberOfEditsToEvict;\n\n\t\t\t// On eviction, we need to remove the IDs of edits that have been evicted\n\t\t\tremovedEdits.forEach((edit) => this.allEditIds.delete(edit.id));\n\n\t\t\t// The minSequenceNumber is strictly increasing so we can clear sequence numbers before it\n\t\t\tthis.sequenceNumberToIndex.deleteRange(0, this._minSequenceNumber, false);\n\t\t}\n\t}\n\n\t/**\n\t * @returns true iff this `EditLog` and `other` are equivalent, regardless of locality.\n\t */\n\tpublic equals<TOtherChangeTypesInternal>(other: EditLog<TOtherChangeTypesInternal>): boolean {\n\t\t// TODO #45414: We should also be deep comparing the list of changes in the edit. This is not straightforward.\n\t\t// We can use our edit validation code when we write it since it will need to do deep walks of the changes.\n\t\treturn compareArrays(this.editIds, other.editIds);\n\t}\n\n\t/**\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary(): EditLogSummary<TChange, FluidEditHandle>;\n\t/**\n\t * @param compressEdit - a function which compresses edits\n\t * @returns the summary of this `OrderedEditSet` that can be used to reconstruct the edit set.\n\t * @internal\n\t */\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TCompressedChange, FluidEditHandle>;\n\tpublic getEditLogSummary<TCompressedChange>(\n\t\tcompressEdit?: (edit: Pick<Edit<TChange>, 'changes'>) => Pick<Edit<TCompressedChange>, 'changes'>\n\t): EditLogSummary<TChange, FluidEditHandle> | EditLogSummary<TCompressedChange, FluidEditHandle> {\n\t\tconst editIds = this.sequencedEdits.map(({ id }) => id);\n\t\treturn compressEdit !== undefined\n\t\t\t? {\n\t\t\t\t\teditChunks:\n\t\t\t\t\t\tthis.sequencedEdits.length === 0\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// Store all edits within a single \"chunk\"\n\t\t\t\t\t\t\t\t\t\tstartRevision: 0,\n\t\t\t\t\t\t\t\t\t\tchunk: this.sequencedEdits.map((edit) => compressEdit(edit)),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ],\n\t\t\t\t\teditIds,\n\t\t\t }\n\t\t\t: {\n\t\t\t\t\teditChunks:\n\t\t\t\t\t\tthis.sequencedEdits.length === 0\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// Store all edits within a single \"chunk\"\n\t\t\t\t\t\t\t\t\t\tstartRevision: 0,\n\t\t\t\t\t\t\t\t\t\tchunk: this.sequencedEdits.map(({ changes }) => ({ changes })),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ],\n\t\t\t\t\teditIds,\n\t\t\t };\n\t}\n\n\t// APIS DEPRECATED DUE TO HISTORY'S PEACEFUL DEATH\n\t/**\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\tpublic async tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined> {\n\t\tconst index = this.tryGetIndexOfId(editId);\n\t\treturn index !== undefined ? this.tryGetEditAtIndex(index) : undefined;\n\t}\n\n\t/**\n\t * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\tpublic async getEditAtIndex(index: number): Promise<Edit<TChange>> {\n\t\treturn this.tryGetEditAtIndex(index) ?? fail('Edit not found');\n\t}\n\n\t/**\n\t * @deprecated Edit virtualization is no longer supported. Instead, use {@link OrderedEditSet.tryGetEditFromId}.\n\t */\n\tpublic getEditInSessionAtIndex(index: number): Edit<TChange> {\n\t\treturn this.tryGetEditAtIndex(index) ?? fail('Edit not found');\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"HistoryEditFactory.d.ts","sourceRoot":"","sources":["../src/HistoryEditFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAItE,OAAO,EACN,cAAc,EAQd,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C;;GAEG;AACH,oBAAY,wBAAwB;IACnC,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;CAC7B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACrB,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,gBAAgB,EACzB,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACrD,cAAc,EAAE,GAAG,SAAS,CA0H9B"}
1
+ {"version":3,"file":"HistoryEditFactory.d.ts","sourceRoot":"","sources":["../src/HistoryEditFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAItE,OAAO,EACN,cAAc,EASd,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C;;GAEG;AACH,oBAAY,wBAAwB;IACnC,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;CAC7B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACrB,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,gBAAgB,EACzB,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACrD,cAAc,EAAE,GAAG,SAAS,CA4H9B"}
@@ -142,8 +142,10 @@ function revert(changes, before, logger, emit) {
142
142
  default:
143
143
  (0, Common_1.fail)('Revert does not support the change type.');
144
144
  }
145
- // Update the revision
146
- editor.applyChange(change);
145
+ // Abort the entire revert if this change can't be applied successfully.
146
+ if (editor.applyChange(change).status !== persisted_types_1.EditStatus.Applied) {
147
+ return undefined;
148
+ }
147
149
  }
148
150
  editor.close();
149
151
  return result;
@@ -1 +1 @@
1
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,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,QAA0B,EAAE,gBAA0B;IACrF,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IAC3D,IAAI,IAAI,KAAK,SAAS,EAAE;QACvB,oFAAoF;QACpF,OAAO,SAAS,CAAC;KACjB;IAED,+EAA+E;IAC/E,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE;QAC1B,OAAO,CAAC,gCAAc,CAAC,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC/D;IACD,OAAO,CAAC,gCAAc,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { DetachedSequenceId, isDetachedSequenceId, NodeId } from './Identifiers';\nimport { assert, fail } from './Common';\nimport { rangeFromStableRange } from './TreeViewUtilities';\nimport {\n\tChangeInternal,\n\tChangeTypeInternal,\n\tDetachInternal,\n\tSetValueInternal,\n\tInsertInternal,\n\tBuildNodeInternal,\n\tSide,\n\tStableRangeInternal,\n} from './persisted-types';\nimport { TransactionInternal } from './TransactionInternal';\nimport { RangeValidationResultKind, validateStableRange } from './EditUtilities';\nimport { StablePlace } from './ChangeTypes';\nimport { RevisionView } from './RevisionView';\nimport { TreeView } from './TreeView';\nimport { getChangeNodeFromViewNode } from './SerializationUtilities';\n\n/**\n * Events emitted from the history edit factory\n */\nexport enum HistoryEditFactoryEvents {\n\tMalformedEdit = 'malformedEdit',\n\tMissingNodes = 'missingNodes',\n}\n\n/**\n * Given a sequence of changes, produces an inverse sequence of changes, i.e. the minimal changes required to revert the given changes\n * @param changes - the changes for which to produce an inverse.\n * @param before - a view of the tree state before `changes` are/were applied - used as a basis for generating the inverse.\n * @param logger - an optional logger for logging telemetry coming from the revert operation\n * @param emit - an optional event emitter to emit events from the revert operation and to allow clients to respond to them\n * @returns if the changes could be reverted, a sequence of changes _r_ that will produce `before` if applied to a view _A_, where _A_ is the result of\n * applying `changes` to `before`. Note that the size of the array of reverted changes may not be the same as the input array, and may even be empty in cases where\n * the view did not change. Applying _r_ to views other than _A_ is legal but may cause the changes to fail to apply or may not be a true semantic inverse.\n * If the changes could not be reverted given the state of `before`, returns undefined.\n *\n * TODO: what should this do if `changes` fails to apply to `before`?\n * TODO:#68574: Pass a view that corresponds to the appropriate Fluid reference sequence number rather than the view just before\n * @internal\n */\nexport function revert(\n\tchanges: readonly ChangeInternal[],\n\tbefore: RevisionView,\n\tlogger?: ITelemetryLogger,\n\temit?: (event: string | symbol, ...args: any[]) => void\n): ChangeInternal[] | undefined {\n\tconst result: ChangeInternal[] = [];\n\n\tconst builtNodes = new Map<DetachedSequenceId, NodeId[]>();\n\tconst detachedNodes = new Map<DetachedSequenceId, NodeId[]>();\n\n\t// Open edit on revision to update it as changes are walked through\n\tconst editor = TransactionInternal.factory(before);\n\t// Apply `edit`, generating an inverse as we go.\n\tfor (const change of changes) {\n\t\t// Generate an inverse of each change\n\t\tswitch (change.type) {\n\t\t\tcase ChangeTypeInternal.Build: {\n\t\t\t\t// Save nodes added to the detached state for use in future changes\n\t\t\t\tconst { destination, source } = change;\n\t\t\t\tassert(!builtNodes.has(destination), `Cannot revert Build: destination is already used by a Build`);\n\t\t\t\tassert(!detachedNodes.has(destination), `Cannot revert Build: destination is already used by a Detach`);\n\t\t\t\tbuiltNodes.set(\n\t\t\t\t\tdestination,\n\t\t\t\t\tsource.reduce((ids: NodeId[], curr: BuildNodeInternal) => {\n\t\t\t\t\t\tif (isDetachedSequenceId(curr)) {\n\t\t\t\t\t\t\tconst nodesForDetachedSequence =\n\t\t\t\t\t\t\t\tbuiltNodes.get(curr) ?? fail('detached sequence must have associated built nodes');\n\n\t\t\t\t\t\t\tids.push(...nodesForDetachedSequence);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tids.push(curr.identifier);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn ids;\n\t\t\t\t\t}, [])\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.Insert: {\n\t\t\t\tconst { source } = change;\n\t\t\t\tconst nodesBuilt = builtNodes.get(source);\n\t\t\t\tconst nodesDetached = detachedNodes.get(source);\n\n\t\t\t\tif (nodesBuilt !== undefined) {\n\t\t\t\t\tif (nodesBuilt.length === 0) {\n\t\t\t\t\t\tbuiltNodes.delete(source);\n\t\t\t\t\t\tlogger?.sendTelemetryEvent({ eventName: 'reverting insertion of empty traits' });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tresult.unshift(createInvertedInsert(change, nodesBuilt));\n\t\t\t\t\tbuiltNodes.delete(source);\n\t\t\t\t} else if (nodesDetached !== undefined) {\n\t\t\t\t\tif (nodesDetached.length === 0) {\n\t\t\t\t\t\tdetachedNodes.delete(source);\n\t\t\t\t\t\tlogger?.sendTelemetryEvent({ eventName: 'reverting insertion of empty traits' });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tresult.unshift(createInvertedInsert(change, nodesDetached, true));\n\t\t\t\t\tdetachedNodes.delete(source);\n\t\t\t\t} else {\n\t\t\t\t\t// Cannot revert an insert whose source is no longer available for inserting (i.e. not just built, and not detached)\n\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\temit(HistoryEditFactoryEvents.MissingNodes, change, changes);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.Detach: {\n\t\t\t\tconst { destination } = change;\n\t\t\t\tconst invert = createInvertedDetach(change, editor.view);\n\t\t\t\tif (invert === undefined) {\n\t\t\t\t\t// Cannot revert a detach whose source does not exist in the tree\n\t\t\t\t\t// TODO:68574: May not be possible once associated todo in `createInvertedDetach` is addressed\n\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\temit(HistoryEditFactoryEvents.MissingNodes, change, changes);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tconst { invertedDetach, detachedNodeIds } = invert;\n\n\t\t\t\tif (detachedNodeIds.length === 0) {\n\t\t\t\t\tlogger?.sendTelemetryEvent({ eventName: 'reverting detachment of empty traits' });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (destination !== undefined) {\n\t\t\t\t\tif (builtNodes.has(destination) || detachedNodes.has(destination)) {\n\t\t\t\t\t\t// Malformed: destination was already used by a prior build or detach\n\t\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\t\temit(HistoryEditFactoryEvents.MalformedEdit, change, changes);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tdetachedNodes.set(destination, detachedNodeIds);\n\t\t\t\t}\n\n\t\t\t\tresult.unshift(...invertedDetach);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.SetValue: {\n\t\t\t\tconst invert = createInvertedSetValue(change, editor.view);\n\t\t\t\tif (invert === undefined) {\n\t\t\t\t\t// Cannot revert a set for a node that does not exist in the tree\n\t\t\t\t\t// TODO:68574: May not be possible once associated todo in `createInvertedSetValue` is addressed\n\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\temit(HistoryEditFactoryEvents.MissingNodes, change, changes);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tresult.unshift(...invert);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.Constraint:\n\t\t\t\t// TODO:#46759: Support Constraint in reverts\n\t\t\t\tfail('Revert currently does not support Constraints');\n\t\t\tdefault:\n\t\t\t\tfail('Revert does not support the change type.');\n\t\t}\n\n\t\t// Update the revision\n\t\teditor.applyChange(change);\n\t}\n\n\teditor.close();\n\treturn result;\n}\n\n/**\n * The inverse of an Insert is a Detach that starts before the leftmost node inserted and ends after the rightmost.\n */\nfunction createInvertedInsert(\n\tinsert: InsertInternal,\n\tnodesInserted: readonly NodeId[],\n\tsaveDetached = false\n): ChangeInternal {\n\tconst leftmostNode = nodesInserted[0];\n\tconst rightmostNode = nodesInserted[nodesInserted.length - 1];\n\n\tconst source: StableRangeInternal = {\n\t\tstart: {\n\t\t\treferenceSibling: leftmostNode,\n\t\t\tside: Side.Before,\n\t\t},\n\t\tend: {\n\t\t\treferenceSibling: rightmostNode,\n\t\t\tside: Side.After,\n\t\t},\n\t};\n\n\treturn ChangeInternal.detach(source, saveDetached ? insert.source : undefined);\n}\n\n/**\n * If a detach does not include a destination, its inverse is a build and insert. Otherwise, it is just an insert.\n * Information on the nodes that were detached is obtained by going to the revision before the detach.\n *\n * The anchor for the resulting Insert is chosen in the following order:\n *\n * ```markdown\n * 1. If detach.source.start.side is After: detach.source.start\n *\n * ex: For nodes A B [C..F] G H where [C..F] represents the detached nodes,\n * if detach.source.start is \"After B\", the anchor for the resulting Insert will also be \"After B\".\n *\n * For nodes [A..F] G H where [A..F] represents the detached nodes,\n * if detach.source.start is \"After start of trait\", the anchor for the resulting Insert will also be\n * \"After start of trait\".\n *\n * 2. Else if detach.source.end.side is Before: detach.source.end\n *\n * ex: For nodes A B [C..F] G H where [C..F] represents the detached nodes,\n * if detach.source.start is \"Before C\" and detach.source.end is \"Before G\",\n * the anchor for the resulting Insert will be \"Before G\".\n *\n * 3. Else: After the node directly to the left of the originally detached nodes\n *\n * ex: For nodes A B [C..F] G H where [C..F] represents the detached nodes,\n * if detach.source.start is \"Before C\" and detach.source.end is \"After F\",\n * the anchor for the resulting Insert will be \"After B\".\n * ```\n *\n * When choosing the anchor, the existing anchors on detach.source are preferred when they have a valid sibling.\n * Otherwise, the valid anchor to the left of the originally detached nodes is chosen.\n */\nfunction createInvertedDetach(\n\tdetach: DetachInternal,\n\tviewBeforeChange: TreeView\n): { invertedDetach: ChangeInternal[]; detachedNodeIds: NodeId[] } | undefined {\n\tconst validatedSource = validateStableRange(viewBeforeChange, detach.source);\n\tif (validatedSource.result !== RangeValidationResultKind.Valid) {\n\t\t// TODO:#68574: having the reference view would potentially allow us to revert some detaches that currently conflict\n\t\treturn undefined;\n\t}\n\n\tconst { start, end } = rangeFromStableRange(viewBeforeChange, validatedSource);\n\tconst { trait: referenceTrait } = start;\n\tconst nodes = viewBeforeChange.getTrait(referenceTrait);\n\n\tconst startIndex = viewBeforeChange.findIndexWithinTrait(start);\n\tconst endIndex = viewBeforeChange.findIndexWithinTrait(end);\n\tconst detachedNodeIds: NodeId[] = nodes.slice(startIndex, endIndex);\n\n\tconst leftOfDetached = nodes.slice(0, startIndex);\n\n\tlet insertDestination: StablePlace;\n\n\tif (start.side === Side.After) {\n\t\tinsertDestination =\n\t\t\tstart.sibling === undefined\n\t\t\t\t? { side: Side.After, referenceTrait }\n\t\t\t\t: { side: Side.After, referenceSibling: start.sibling };\n\t} else if (end.side === Side.Before) {\n\t\tinsertDestination =\n\t\t\tend.sibling === undefined\n\t\t\t\t? { side: Side.Before, referenceTrait }\n\t\t\t\t: { side: Side.Before, referenceSibling: end.sibling };\n\t} else {\n\t\tconst referenceSibling = leftOfDetached.pop();\n\t\tinsertDestination = {\n\t\t\tside: Side.After,\n\t\t\treferenceSibling,\n\t\t\treferenceTrait: referenceSibling === undefined ? referenceTrait : undefined,\n\t\t};\n\t}\n\n\tif (detach.destination !== undefined) {\n\t\treturn {\n\t\t\tinvertedDetach: [ChangeInternal.insert(detach.destination, insertDestination)],\n\t\t\tdetachedNodeIds,\n\t\t};\n\t}\n\n\tconst detachedSequenceId = 0 as DetachedSequenceId;\n\treturn {\n\t\tinvertedDetach: [\n\t\t\tChangeInternal.build(\n\t\t\t\tdetachedNodeIds.map((id) => getChangeNodeFromViewNode(viewBeforeChange, id)),\n\t\t\t\tdetachedSequenceId\n\t\t\t),\n\t\t\tChangeInternal.insert(detachedSequenceId, insertDestination),\n\t\t],\n\t\tdetachedNodeIds,\n\t};\n}\n\n/**\n * The inverse of a SetValue is a SetValue that sets the value to what it was prior to the change.\n */\nfunction createInvertedSetValue(setValue: SetValueInternal, viewBeforeChange: TreeView): ChangeInternal[] | undefined {\n\tconst { nodeToModify } = setValue;\n\tconst node = viewBeforeChange.tryGetViewNode(nodeToModify);\n\tif (node === undefined) {\n\t\t// TODO:68574: With a reference view, may be able to better resolve conflicting sets\n\t\treturn undefined;\n\t}\n\n\t// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface)\n\tif (node.payload !== null) {\n\t\treturn [ChangeInternal.setPayload(nodeToModify, node.payload)];\n\t}\n\treturn [ChangeInternal.clearPayload(nodeToModify)];\n}\n"]}
1
+ {"version":3,"file":"HistoryEditFactory.js","sourceRoot":"","sources":["../src/HistoryEditFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+CAAiF;AACjF,qCAAwC;AACxC,2DAA2D;AAC3D,uDAU2B;AAC3B,+DAA4D;AAC5D,mDAAiF;AAIjF,qEAAqE;AAErE;;GAEG;AACH,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IACnC,2DAA+B,CAAA;IAC/B,yDAA6B,CAAA;AAC9B,CAAC,EAHW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAGnC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,MAAM,CACrB,OAAkC,EAClC,MAAoB,EACpB,MAAyB,EACzB,IAAuD;IAEvD,MAAM,MAAM,GAAqB,EAAE,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC3D,MAAM,aAAa,GAAG,IAAI,GAAG,EAAgC,CAAC;IAE9D,mEAAmE;IACnE,MAAM,MAAM,GAAG,yCAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;I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I,CAAC,KAAK;YAChB,gBAAgB;YAChB,cAAc,EAAE,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;SAC3E,CAAC;KACF;IAED,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,EAAE;QACrC,OAAO;YACN,cAAc,EAAE,CAAC,gCAAc,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;YAC9E,eAAe;SACf,CAAC;KACF;IAED,MAAM,kBAAkB,GAAG,CAAuB,CAAC;IACnD,OAAO;QACN,cAAc,EAAE;YACf,gCAAc,CAAC,KAAK,CACnB,eAAe,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAA,kDAAyB,EAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,EAC5E,kBAAkB,CAClB;YACD,gCAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;SAC5D;QACD,eAAe;KACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,QAA0B,EAAE,gBAA0B;IACrF,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IAC3D,IAAI,IAAI,KAAK,SAAS,EAAE;QACvB,oFAAoF;QACpF,OAAO,SAAS,CAAC;KACjB;IAED,+EAA+E;IAC/E,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE;QAC1B,OAAO,CAAC,gCAAc,CAAC,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC/D;IACD,OAAO,CAAC,gCAAc,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from '@fluidframework/common-definitions';\nimport { DetachedSequenceId, isDetachedSequenceId, NodeId } from './Identifiers';\nimport { assert, fail } from './Common';\nimport { rangeFromStableRange } from './TreeViewUtilities';\nimport {\n\tChangeInternal,\n\tChangeTypeInternal,\n\tDetachInternal,\n\tSetValueInternal,\n\tInsertInternal,\n\tBuildNodeInternal,\n\tSide,\n\tStableRangeInternal,\n\tEditStatus,\n} from './persisted-types';\nimport { TransactionInternal } from './TransactionInternal';\nimport { RangeValidationResultKind, validateStableRange } from './EditUtilities';\nimport { StablePlace } from './ChangeTypes';\nimport { RevisionView } from './RevisionView';\nimport { TreeView } from './TreeView';\nimport { getChangeNodeFromViewNode } from './SerializationUtilities';\n\n/**\n * Events emitted from the history edit factory\n */\nexport enum HistoryEditFactoryEvents {\n\tMalformedEdit = 'malformedEdit',\n\tMissingNodes = 'missingNodes',\n}\n\n/**\n * Given a sequence of changes, produces an inverse sequence of changes, i.e. the minimal changes required to revert the given changes\n * @param changes - the changes for which to produce an inverse.\n * @param before - a view of the tree state before `changes` are/were applied - used as a basis for generating the inverse.\n * @param logger - an optional logger for logging telemetry coming from the revert operation\n * @param emit - an optional event emitter to emit events from the revert operation and to allow clients to respond to them\n * @returns if the changes could be reverted, a sequence of changes _r_ that will produce `before` if applied to a view _A_, where _A_ is the result of\n * applying `changes` to `before`. Note that the size of the array of reverted changes may not be the same as the input array, and may even be empty in cases where\n * the view did not change. Applying _r_ to views other than _A_ is legal but may cause the changes to fail to apply or may not be a true semantic inverse.\n * If the changes could not be reverted given the state of `before`, returns undefined.\n *\n * TODO: what should this do if `changes` fails to apply to `before`?\n * TODO:#68574: Pass a view that corresponds to the appropriate Fluid reference sequence number rather than the view just before\n * @internal\n */\nexport function revert(\n\tchanges: readonly ChangeInternal[],\n\tbefore: RevisionView,\n\tlogger?: ITelemetryLogger,\n\temit?: (event: string | symbol, ...args: any[]) => void\n): ChangeInternal[] | undefined {\n\tconst result: ChangeInternal[] = [];\n\n\tconst builtNodes = new Map<DetachedSequenceId, NodeId[]>();\n\tconst detachedNodes = new Map<DetachedSequenceId, NodeId[]>();\n\n\t// Open edit on revision to update it as changes are walked through\n\tconst editor = TransactionInternal.factory(before);\n\t// Apply `edit`, generating an inverse as we go.\n\tfor (const change of changes) {\n\t\t// Generate an inverse of each change\n\t\tswitch (change.type) {\n\t\t\tcase ChangeTypeInternal.Build: {\n\t\t\t\t// Save nodes added to the detached state for use in future changes\n\t\t\t\tconst { destination, source } = change;\n\t\t\t\tassert(!builtNodes.has(destination), `Cannot revert Build: destination is already used by a Build`);\n\t\t\t\tassert(!detachedNodes.has(destination), `Cannot revert Build: destination is already used by a Detach`);\n\t\t\t\tbuiltNodes.set(\n\t\t\t\t\tdestination,\n\t\t\t\t\tsource.reduce((ids: NodeId[], curr: BuildNodeInternal) => {\n\t\t\t\t\t\tif (isDetachedSequenceId(curr)) {\n\t\t\t\t\t\t\tconst nodesForDetachedSequence =\n\t\t\t\t\t\t\t\tbuiltNodes.get(curr) ?? fail('detached sequence must have associated built nodes');\n\n\t\t\t\t\t\t\tids.push(...nodesForDetachedSequence);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tids.push(curr.identifier);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn ids;\n\t\t\t\t\t}, [])\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.Insert: {\n\t\t\t\tconst { source } = change;\n\t\t\t\tconst nodesBuilt = builtNodes.get(source);\n\t\t\t\tconst nodesDetached = detachedNodes.get(source);\n\n\t\t\t\tif (nodesBuilt !== undefined) {\n\t\t\t\t\tif (nodesBuilt.length === 0) {\n\t\t\t\t\t\tbuiltNodes.delete(source);\n\t\t\t\t\t\tlogger?.sendTelemetryEvent({ eventName: 'reverting insertion of empty traits' });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tresult.unshift(createInvertedInsert(change, nodesBuilt));\n\t\t\t\t\tbuiltNodes.delete(source);\n\t\t\t\t} else if (nodesDetached !== undefined) {\n\t\t\t\t\tif (nodesDetached.length === 0) {\n\t\t\t\t\t\tdetachedNodes.delete(source);\n\t\t\t\t\t\tlogger?.sendTelemetryEvent({ eventName: 'reverting insertion of empty traits' });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tresult.unshift(createInvertedInsert(change, nodesDetached, true));\n\t\t\t\t\tdetachedNodes.delete(source);\n\t\t\t\t} else {\n\t\t\t\t\t// Cannot revert an insert whose source is no longer available for inserting (i.e. not just built, and not detached)\n\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\temit(HistoryEditFactoryEvents.MissingNodes, change, changes);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.Detach: {\n\t\t\t\tconst { destination } = change;\n\t\t\t\tconst invert = createInvertedDetach(change, editor.view);\n\t\t\t\tif (invert === undefined) {\n\t\t\t\t\t// Cannot revert a detach whose source does not exist in the tree\n\t\t\t\t\t// TODO:68574: May not be possible once associated todo in `createInvertedDetach` is addressed\n\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\temit(HistoryEditFactoryEvents.MissingNodes, change, changes);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tconst { invertedDetach, detachedNodeIds } = invert;\n\n\t\t\t\tif (detachedNodeIds.length === 0) {\n\t\t\t\t\tlogger?.sendTelemetryEvent({ eventName: 'reverting detachment of empty traits' });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (destination !== undefined) {\n\t\t\t\t\tif (builtNodes.has(destination) || detachedNodes.has(destination)) {\n\t\t\t\t\t\t// Malformed: destination was already used by a prior build or detach\n\t\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\t\temit(HistoryEditFactoryEvents.MalformedEdit, change, changes);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tdetachedNodes.set(destination, detachedNodeIds);\n\t\t\t\t}\n\n\t\t\t\tresult.unshift(...invertedDetach);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.SetValue: {\n\t\t\t\tconst invert = createInvertedSetValue(change, editor.view);\n\t\t\t\tif (invert === undefined) {\n\t\t\t\t\t// Cannot revert a set for a node that does not exist in the tree\n\t\t\t\t\t// TODO:68574: May not be possible once associated todo in `createInvertedSetValue` is addressed\n\t\t\t\t\tif (emit !== undefined) {\n\t\t\t\t\t\temit(HistoryEditFactoryEvents.MissingNodes, change, changes);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tresult.unshift(...invert);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ChangeTypeInternal.Constraint:\n\t\t\t\t// TODO:#46759: Support Constraint in reverts\n\t\t\t\tfail('Revert currently does not support Constraints');\n\t\t\tdefault:\n\t\t\t\tfail('Revert does not support the change type.');\n\t\t}\n\n\t\t// Abort the entire revert if this change can't be applied successfully.\n\t\tif (editor.applyChange(change).status !== EditStatus.Applied) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\teditor.close();\n\treturn result;\n}\n\n/**\n * The inverse of an Insert is a Detach that starts before the leftmost node inserted and ends after the rightmost.\n */\nfunction createInvertedInsert(\n\tinsert: InsertInternal,\n\tnodesInserted: readonly NodeId[],\n\tsaveDetached = false\n): ChangeInternal {\n\tconst leftmostNode = nodesInserted[0];\n\tconst rightmostNode = nodesInserted[nodesInserted.length - 1];\n\n\tconst source: StableRangeInternal = {\n\t\tstart: {\n\t\t\treferenceSibling: leftmostNode,\n\t\t\tside: Side.Before,\n\t\t},\n\t\tend: {\n\t\t\treferenceSibling: rightmostNode,\n\t\t\tside: Side.After,\n\t\t},\n\t};\n\n\treturn ChangeInternal.detach(source, saveDetached ? insert.source : undefined);\n}\n\n/**\n * If a detach does not include a destination, its inverse is a build and insert. Otherwise, it is just an insert.\n * Information on the nodes that were detached is obtained by going to the revision before the detach.\n *\n * The anchor for the resulting Insert is chosen in the following order:\n *\n * ```markdown\n * 1. If detach.source.start.side is After: detach.source.start\n *\n * ex: For nodes A B [C..F] G H where [C..F] represents the detached nodes,\n * if detach.source.start is \"After B\", the anchor for the resulting Insert will also be \"After B\".\n *\n * For nodes [A..F] G H where [A..F] represents the detached nodes,\n * if detach.source.start is \"After start of trait\", the anchor for the resulting Insert will also be\n * \"After start of trait\".\n *\n * 2. Else if detach.source.end.side is Before: detach.source.end\n *\n * ex: For nodes A B [C..F] G H where [C..F] represents the detached nodes,\n * if detach.source.start is \"Before C\" and detach.source.end is \"Before G\",\n * the anchor for the resulting Insert will be \"Before G\".\n *\n * 3. Else: After the node directly to the left of the originally detached nodes\n *\n * ex: For nodes A B [C..F] G H where [C..F] represents the detached nodes,\n * if detach.source.start is \"Before C\" and detach.source.end is \"After F\",\n * the anchor for the resulting Insert will be \"After B\".\n * ```\n *\n * When choosing the anchor, the existing anchors on detach.source are preferred when they have a valid sibling.\n * Otherwise, the valid anchor to the left of the originally detached nodes is chosen.\n */\nfunction createInvertedDetach(\n\tdetach: DetachInternal,\n\tviewBeforeChange: TreeView\n): { invertedDetach: ChangeInternal[]; detachedNodeIds: NodeId[] } | undefined {\n\tconst validatedSource = validateStableRange(viewBeforeChange, detach.source);\n\tif (validatedSource.result !== RangeValidationResultKind.Valid) {\n\t\t// TODO:#68574: having the reference view would potentially allow us to revert some detaches that currently conflict\n\t\treturn undefined;\n\t}\n\n\tconst { start, end } = rangeFromStableRange(viewBeforeChange, validatedSource);\n\tconst { trait: referenceTrait } = start;\n\tconst nodes = viewBeforeChange.getTrait(referenceTrait);\n\n\tconst startIndex = viewBeforeChange.findIndexWithinTrait(start);\n\tconst endIndex = viewBeforeChange.findIndexWithinTrait(end);\n\tconst detachedNodeIds: NodeId[] = nodes.slice(startIndex, endIndex);\n\n\tconst leftOfDetached = nodes.slice(0, startIndex);\n\n\tlet insertDestination: StablePlace;\n\n\tif (start.side === Side.After) {\n\t\tinsertDestination =\n\t\t\tstart.sibling === undefined\n\t\t\t\t? { side: Side.After, referenceTrait }\n\t\t\t\t: { side: Side.After, referenceSibling: start.sibling };\n\t} else if (end.side === Side.Before) {\n\t\tinsertDestination =\n\t\t\tend.sibling === undefined\n\t\t\t\t? { side: Side.Before, referenceTrait }\n\t\t\t\t: { side: Side.Before, referenceSibling: end.sibling };\n\t} else {\n\t\tconst referenceSibling = leftOfDetached.pop();\n\t\tinsertDestination = {\n\t\t\tside: Side.After,\n\t\t\treferenceSibling,\n\t\t\treferenceTrait: referenceSibling === undefined ? referenceTrait : undefined,\n\t\t};\n\t}\n\n\tif (detach.destination !== undefined) {\n\t\treturn {\n\t\t\tinvertedDetach: [ChangeInternal.insert(detach.destination, insertDestination)],\n\t\t\tdetachedNodeIds,\n\t\t};\n\t}\n\n\tconst detachedSequenceId = 0 as DetachedSequenceId;\n\treturn {\n\t\tinvertedDetach: [\n\t\t\tChangeInternal.build(\n\t\t\t\tdetachedNodeIds.map((id) => getChangeNodeFromViewNode(viewBeforeChange, id)),\n\t\t\t\tdetachedSequenceId\n\t\t\t),\n\t\t\tChangeInternal.insert(detachedSequenceId, insertDestination),\n\t\t],\n\t\tdetachedNodeIds,\n\t};\n}\n\n/**\n * The inverse of a SetValue is a SetValue that sets the value to what it was prior to the change.\n */\nfunction createInvertedSetValue(setValue: SetValueInternal, viewBeforeChange: TreeView): ChangeInternal[] | undefined {\n\tconst { nodeToModify } = setValue;\n\tconst node = viewBeforeChange.tryGetViewNode(nodeToModify);\n\tif (node === undefined) {\n\t\t// TODO:68574: With a reference view, may be able to better resolve conflicting sets\n\t\treturn undefined;\n\t}\n\n\t// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface)\n\tif (node.payload !== null) {\n\t\treturn [ChangeInternal.setPayload(nodeToModify, node.payload)];\n\t}\n\treturn [ChangeInternal.clearPayload(nodeToModify)];\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E,EAAE,iBAAiB,GAAG,wBAAwB;IAoC/E;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAYlC,OAAO,CAAC,oBAAoB;IAc5B;;;OAGG;IACI,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,OAAO,GAAG,OAAO;IAmHvE,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA4B/B,OAAO,CAAC,MAAM,CAAC,eAAe;IAuC9B;;;OAGG;IACI,SAAS,CACf,WAAW,EAAE,OAAO,GAClB,wCAAwC,GAAG,mCAAmC;IAEjF;;;OAGG;IACI,SAAS,CAAC,WAAW,EAAE,IAAI,GAAG,wCAAwC;IAE7E;;;OAGG;IACI,SAAS,CAAC,WAAW,EAAE,KAAK,GAAG,mCAAmC;IA4GzE;;OAEG;WACW,WAAW,CAAC,UAAU,EAAE,wCAAwC,GAAG,YAAY;IAE7F;;;;;OAKG;WACW,WAAW,CACxB,UAAU,EAAE,mCAAmC,EAC/C,YAAY,EAAE,SAAS,EACvB,aAAa,CAAC,EAAE,aAAa,GAC3B,YAAY;IAmLf;;;;OAIG;WACW,uBAAuB,CACpC,oBAAoB,EAAE,+BAA+B,EACrD,UAAU,EAAE,KAAK,GACf,mCAAmC;IAEtC;;;;OAIG;WACW,uBAAuB,CACpC,oBAAoB,EAAE,+BAA+B,EACrD,UAAU,EAAE,IAAI,GACd,wCAAwC;CAe3C;AAOD;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,UAAU,EAAE,mCAAmC,GAAG,wCAAwC,GACxF,UAAU,IAAI,wCAAwC,CAExD"}
@@ -335,7 +335,7 @@ class IdCompressor {
335
335
  * @param range - the range of session-local IDs to finalize.
336
336
  */
337
337
  finalizeCreationRange(range) {
338
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
338
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
339
339
  const { sessionId, attributionId } = range;
340
340
  const isLocal = sessionId === this.localSessionId;
341
341
  const session = (_a = this.sessions.get(sessionId)) !== null && _a !== void 0 ? _a : this.createSession(sessionId, attributionId);
@@ -367,7 +367,6 @@ class IdCompressor {
367
367
  Math.min(currentCluster.count + finalizeCount, currentCluster.capacity) -
368
368
  1);
369
369
  if (lastFinalInCluster > lastKnownFinal) {
370
- eagerFinalIdCount = lastFinalInCluster - (lastKnownFinal + 1);
371
370
  this.sessionIdNormalizer.addFinalIds((lastKnownFinal + 1), lastFinalInCluster, currentCluster);
372
371
  }
373
372
  }
@@ -377,6 +376,7 @@ class IdCompressor {
377
376
  const hasRoom = overflow <= 0;
378
377
  if (hasRoom || currentBaseFinalId === this.finalIdToCluster.maxKey()) {
379
378
  currentCluster.count += remainingCount;
379
+ eagerFinalIdCount = remainingCount;
380
380
  remainingCount = 0;
381
381
  // The common case is that there is room in the cluster, and the new final IDs can simply be added to it
382
382
  if (!hasRoom) {
@@ -418,7 +418,7 @@ class IdCompressor {
418
418
  // the finalization of the ranges.
419
419
  this.sessionIdNormalizer.addFinalIds(finalPivot, newLastFinal, currentCluster);
420
420
  (_d = this.logger) === null || _d === void 0 ? void 0 : _d.sendTelemetryEvent({
421
- eventName: 'IdCompressor:ClusterExpansion',
421
+ eventName: 'SharedTreeIdCompressor:ClusterExpansion',
422
422
  sessionId: this.localSessionId,
423
423
  previousCapacity,
424
424
  newCapacity: currentCluster.capacity,
@@ -432,9 +432,10 @@ class IdCompressor {
432
432
  // form a new one by incrementing the previous baseUuid
433
433
  newBaseUuid = (0, NumericUuid_1.incrementUuid)(currentCluster.baseUuid, currentCluster.capacity);
434
434
  currentCluster.count += remainingCapacity;
435
+ eagerFinalIdCount = remainingCapacity;
435
436
  remainingCount -= remainingCapacity;
436
437
  (_e = this.logger) === null || _e === void 0 ? void 0 : _e.sendTelemetryEvent({
437
- eventName: 'IdCompressor:OverfilledCluster',
438
+ eventName: 'SharedTreeIdCompressor:OverfilledCluster',
438
439
  sessionId: this.localSessionId,
439
440
  });
440
441
  }
@@ -442,10 +443,12 @@ class IdCompressor {
442
443
  else {
443
444
  // Session has never made a cluster, form a new one with the session UUID as the baseUuid
444
445
  newBaseUuid = session.sessionUuid;
445
- (_f = this.logger) === null || _f === void 0 ? void 0 : _f.sendTelemetryEvent({
446
- eventName: 'IdCompressor:FirstCluster',
447
- sessionId: this.localSessionId,
448
- });
446
+ if (isLocal) {
447
+ (_f = this.logger) === null || _f === void 0 ? void 0 : _f.sendTelemetryEvent({
448
+ eventName: 'SharedTreeIdCompressor:FirstCluster',
449
+ sessionId: this.localSessionId,
450
+ });
451
+ }
449
452
  }
450
453
  // Finalizing a range results in one of three cases:
451
454
  // 1. All local IDs are finalized into a new cluster (because there was either never a cluster for that session, or the current
@@ -477,7 +480,7 @@ class IdCompressor {
477
480
  localIdPivot = (newFirstFinalizedLocal - usedCapacity);
478
481
  if (isLocal) {
479
482
  (_g = this.logger) === null || _g === void 0 ? void 0 : _g.sendTelemetryEvent({
480
- eventName: 'IdCompressor:NewCluster',
483
+ eventName: 'SharedTreeIdCompressor:NewCluster',
481
484
  sessionId: this.localSessionId,
482
485
  clusterCapacity: newCapacity,
483
486
  clusterCount: remainingCount,
@@ -589,10 +592,10 @@ class IdCompressor {
589
592
  }
590
593
  if (isLocal) {
591
594
  (_j = this.logger) === null || _j === void 0 ? void 0 : _j.sendTelemetryEvent({
592
- eventName: 'IdCompressor:IdCompressorStatus',
593
- eagerFinalIdCount,
594
- localIdCount: remainingCount,
595
- overridesCount: (_k = overrides === null || overrides === void 0 ? void 0 : overrides.length) !== null && _k !== void 0 ? _k : 0,
595
+ eventName: 'SharedTreeIdCompressor:IdCompressorStatus',
596
+ eagerFinalIdCount: eagerFinalIdCount - ((_k = overrides === null || overrides === void 0 ? void 0 : overrides.length) !== null && _k !== void 0 ? _k : 0),
597
+ localIdCount: remainingCount + ((_l = overrides === null || overrides === void 0 ? void 0 : overrides.length) !== null && _l !== void 0 ? _l : 0),
598
+ overridesCount: (_m = overrides === null || overrides === void 0 ? void 0 : overrides.length) !== null && _m !== void 0 ? _m : 0,
596
599
  sessionId: this.localSessionId,
597
600
  });
598
601
  }
@@ -1148,7 +1151,7 @@ class IdCompressor {
1148
1151
  return areEqual;
1149
1152
  }
1150
1153
  serialize(withSession) {
1151
- var _a;
1154
+ var _a, _b;
1152
1155
  const serializedSessions = [];
1153
1156
  const sessionIdToSessionIndex = new Map();
1154
1157
  const attributionIdToAttributionIndex = new Map();
@@ -1224,6 +1227,12 @@ class IdCompressor {
1224
1227
  }
1225
1228
  return serializedWithSession;
1226
1229
  }
1230
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.sendTelemetryEvent({
1231
+ eventName: 'SharedTreeIdCompressor:SerializedIdCompressorSize',
1232
+ size: JSON.stringify(serializedIdCompressor).length,
1233
+ clusterCount: serializedIdCompressor.clusters.length,
1234
+ sessionCount: serializedIdCompressor.sessions.length,
1235
+ });
1227
1236
  return serializedIdCompressor;
1228
1237
  }
1229
1238
  static deserialize(...args) {