@fluidframework/matrix 2.42.0 → 2.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/handlecache.js +1 -1
- package/dist/handlecache.js.map +1 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +1 -1
- package/dist/matrix.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/permutationvector.d.ts.map +1 -1
- package/dist/permutationvector.js +4 -3
- package/dist/permutationvector.js.map +1 -1
- package/lib/handlecache.js +1 -1
- package/lib/handlecache.js.map +1 -1
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +1 -1
- package/lib/matrix.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/permutationvector.d.ts.map +1 -1
- package/lib/permutationvector.js +4 -3
- package/lib/permutationvector.js.map +1 -1
- package/package.json +20 -20
- package/src/handlecache.ts +3 -3
- package/src/matrix.ts +1 -4
- package/src/packageVersion.ts +1 -1
- package/src/permutationvector.ts +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permutationvector.d.ts","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAErF,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EACN,WAAW,EACX,MAAM,EACN,YAAY,EAIZ,QAAQ,EAIR,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,M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,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IASnC,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAuBvC,cAAc,CACpB,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,yBAAyB,GAC3B;QAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IA6CvC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAkC,GAAG,MAAM;IA6DpF,SAAS,CACf,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,gBAAgB,GAC1B,qBAAqB;IAaX,IAAI,CAChB,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,gBAAgB,GAC1B,OAAO,CAAC;QACV,WAAW,EAAE,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAAC;KAClD,CAAC;IAiBF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAuEtB;IAEF,OAAO,CAAC,QAAQ,CAAC,aAAa,CA0B5B;IAEK,QAAQ,IAAI,MAAM;CAWzB;AAED,wBAAgB,yBAAyB,CACxC,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,YAAY,GAChB;IACF,EAAE,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACpC,QAAQ,EAAE,kBAAkB,CAAC;CAC7B,CAqBA"}
|
package/lib/permutationvector.js
CHANGED
|
@@ -179,11 +179,12 @@ export class PermutationVector extends Client {
|
|
|
179
179
|
return handle;
|
|
180
180
|
}
|
|
181
181
|
adjustPosition(posToAdjust, op) {
|
|
182
|
-
const
|
|
182
|
+
const segOff = this.getContainingSegment(posToAdjust, {
|
|
183
183
|
referenceSequenceNumber: op.referenceSequenceNumber,
|
|
184
184
|
clientId: op.clientId,
|
|
185
185
|
});
|
|
186
|
-
assert(
|
|
186
|
+
assert(segOff !== undefined, 0xbac /* segment must be available for operations in the collab window */);
|
|
187
|
+
const { segment, offset } = segOff;
|
|
187
188
|
if (segmentIsRemoved(segment)) {
|
|
188
189
|
// this case is tricky. the segment which the row or column data is remove
|
|
189
190
|
// but an op before that remove references a cell. we still want to apply
|
|
@@ -280,7 +281,7 @@ export function reinsertSegmentIntoVector(vector, pos, spec) {
|
|
|
280
281
|
const original = PermutationSegment.fromJSONObject(spec);
|
|
281
282
|
// (Re)insert the removed number of rows at the original position.
|
|
282
283
|
const op = vector.insertSegmentLocal(pos, original);
|
|
283
|
-
const inserted = vector.getContainingSegment(pos)
|
|
284
|
+
const inserted = vector.getContainingSegment(pos)?.segment;
|
|
284
285
|
// we reuse the original handle here
|
|
285
286
|
// so if cells exist, they can be found, and re-inserted
|
|
286
287
|
if (isHandleValid(original.start)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EACN,WAAW,EACX,MAAM,EAMN,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,GAGhB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACN,sBAAsB,EACtB,kBAAkB,GAClB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAU,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAUrD,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAI3C,MAAM,CAAC,cAAc,CAAC,IAAkB;QAC9C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAk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AC,OAAO,yCAAwB,EAC1D,UAAU,CACV,CAAC;IACH,CAAC;IAuGM,QAAQ;QACd,MAAM,CAAC,GAAa,EAAE,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,gEAAgE;YAChE,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QACb,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;CACD;AAED,MAAM,UAAU,yBAAyB,CACxC,MAAyB,EACzB,GAAW,EACX,IAAkB;IAKlB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEzD,kEAAkE;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,OAA6B,CAAC;IAEhF,oCAAoC;IACpC,wDAAwD;IACxD,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,CAAC,WAAW,CAAC,YAAY,CAC9B,GAAG;IACH,mBAAmB,CAAC,CAAC;IACrB,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAC1C,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tBaseSegment,\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeDeltaCallbackArgs,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeMaintenanceCallbackArgs,\n\tISegment,\n\tMergeTreeDeltaType,\n\tMergeTreeMaintenanceType,\n\tsegmentIsRemoved,\n\ttype IMergeTreeInsertMsg,\n\ttype IMergeTreeRemoveMsg,\n} from \"@fluidframework/merge-tree/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tObjectStoragePartition,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { HandleCache } from \"./handlecache.js\";\nimport { Handle, HandleTable, isHandleValid } from \"./handletable.js\";\nimport { deserializeBlob } from \"./serialization.js\";\nimport { VectorUndoProvider } from \"./undoprovider.js\";\n\nconst enum SnapshotPath {\n\tsegments = \"segments\",\n\thandleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n\tpublic static readonly typeString: string = \"PermutationSegment\";\n\tprivate _start = Handle.unallocated;\n\n\tpublic static fromJSONObject(spec: IJSONSegment): PermutationSegment {\n\t\tconst [length, start] = spec as PermutationSegmentSpec;\n\t\treturn new PermutationSegment(length, start);\n\t}\n\n\tpublic readonly type = PermutationSegment.typeString;\n\n\tconstructor(length: number, start = Handle.unallocated) {\n\t\tsuper();\n\t\tthis._start = start;\n\t\tthis.cachedLength = length;\n\t}\n\n\tpublic get start(): Handle {\n\t\treturn this._start;\n\t}\n\tpublic set start(value: Handle) {\n\t\tassert(\n\t\t\tthis._start === Handle.unallocated,\n\t\t\t0x024 /* \"Start of PermutationSegment already allocated!\" */,\n\t\t);\n\t\tassert(\n\t\t\tisHandleValid(value),\n\t\t\t0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */,\n\t\t);\n\n\t\tthis._start = value;\n\t}\n\n\tpublic reset(): void {\n\t\tthis._start = Handle.unallocated;\n\t}\n\n\tpublic toJSONObject(): number[] {\n\t\treturn [this.cachedLength, this.start];\n\t}\n\n\tpublic clone(start = 0, end = this.cachedLength): PermutationSegment {\n\t\tconst b = new PermutationSegment(\n\t\t\t/* length: */ end - start,\n\t\t\t/* start: */ this.start + start,\n\t\t);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tpublic canAppend(segment: ISegment): boolean {\n\t\tconst asPerm = segment as PermutationSegment;\n\n\t\treturn this.start === Handle.unallocated\n\t\t\t? asPerm.start === Handle.unallocated\n\t\t\t: asPerm.start === this.start + this.cachedLength;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number): PermutationSegment {\n\t\tassert(\n\t\t\t0 < pos && pos < this.cachedLength,\n\t\t\t0x026 /* \"Trying to split segment at out-of-bounds position!\" */,\n\t\t);\n\n\t\tconst leafSegment = new PermutationSegment(\n\t\t\t/* length: */ this.cachedLength - pos,\n\t\t\t/* start: */ this.start === Handle.unallocated ? Handle.unallocated : this.start + pos,\n\t\t);\n\n\t\tthis.cachedLength = pos;\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic toString(): string {\n\t\treturn this.start === Handle.unallocated\n\t\t\t? `<${this.cachedLength} empty>`\n\t\t\t: `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n\t}\n}\n\n// eslint-disable-next-line import/no-deprecated\nexport class PermutationVector extends Client {\n\tprivate handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n\tpublic readonly handleCache = new HandleCache(this);\n\tpublic undo: VectorUndoProvider | undefined;\n\n\tconstructor(\n\t\tpath: string,\n\t\tlogger: ITelemetryBaseLogger,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tprivate readonly deltaCallback: (\n\t\t\tposition: number,\n\t\t\tnumRemoved: number,\n\t\t\tnumInserted: number,\n\t\t) => void,\n\t\tprivate readonly handlesRecycledCallback: (handles: Handle[]) => void,\n\t\tgetMinInFlightRefSeq: () => number | undefined,\n\t) {\n\t\tsuper(\n\t\t\tPermutationSegment.fromJSONObject,\n\t\t\tcreateChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),\n\t\t\t{\n\t\t\t\t...runtime.options,\n\t\t\t\tnewMergeTreeSnapshotFormat: true, // Force new snapshot format as it's generally more efficient for matrices.\n\t\t\t},\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.on(\"delta\", this.onDelta);\n\t\tthis.on(\"maintenance\", this.onMaintenance);\n\t}\n\n\tpublic insert(start: number, length: number): IMergeTreeInsertMsg | undefined {\n\t\treturn this.insertSegmentLocal(start, new PermutationSegment(length));\n\t}\n\n\tpublic remove(start: number, length: number): IMergeTreeRemoveMsg {\n\t\treturn this.removeRangeLocal(start, start + length);\n\t}\n\n\tpublic getMaybeHandle(pos: number): Handle {\n\t\tassert(\n\t\t\t0 <= pos && pos < this.getLength(),\n\t\t\t0x027 /* \"Trying to get handle of out-of-bounds position!\" */,\n\t\t);\n\n\t\treturn this.handleCache.getHandle(pos);\n\t}\n\n\tpublic getAllocatedHandle(pos: number): Handle {\n\t\tlet handle = this.getMaybeHandle(pos);\n\t\tif (isHandleValid(handle)) {\n\t\t\treturn handle;\n\t\t}\n\n\t\tthis.walkSegments(\n\t\t\t(segment) => {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tpos,\n\t\t\tpos + 1,\n\t\t\t/* accum: */ undefined,\n\t\t\t/* splitRange: */ true,\n\t\t);\n\n\t\tthis.handleCache.addHandle(pos, handle);\n\n\t\treturn handle;\n\t}\n\n\tpublic adjustPosition(\n\t\tposToAdjust: number,\n\t\top: ISequencedDocumentMessage,\n\t): { pos: number | undefined; handle: Handle } {\n\t\tconst { segment, offset } = this.getContainingSegment<PermutationSegment>(posToAdjust, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\n\t\tassert(\n\t\t\tsegment !== undefined && offset !== undefined,\n\t\t\t0xbac /* segment must be available for operations in the collab window */,\n\t\t);\n\n\t\tif (segmentIsRemoved(segment)) {\n\t\t\t// this case is tricky. the segment which the row or column data is remove\n\t\t\t// but an op before that remove references a cell. we still want to apply\n\t\t\t// the op, as the row/col could become active again in the case where\n\t\t\t// the remove was local and it get's rolled back. so we allocate a handle\n\t\t\t// for the row/col if not allocated, but don't put it in the cache\n\t\t\t// as the cache can only contain live positions.\n\t\t\tlet handle = segment.start;\n\t\t\tif (!isHandleValid(handle)) {\n\t\t\t\tthis.walkSegments(\n\t\t\t\t\t(s) => {\n\t\t\t\t\t\tconst asPerm = s as PermutationSegment;\n\t\t\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t\tposToAdjust,\n\t\t\t\t\tposToAdjust + 1,\n\t\t\t\t\t/* accum: */ undefined,\n\t\t\t\t\t/* splitRange: */ true,\n\t\t\t\t\top,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn { handle, pos: undefined };\n\t\t} else {\n\t\t\tconst pos = this.getPosition(segment) + offset;\n\t\t\treturn {\n\t\t\t\tpos,\n\t\t\t\thandle: this.getAllocatedHandle(pos),\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic handleToPosition(handle: Handle, localSeq = this.getCollabWindow().localSeq): number {\n\t\tassert(\n\t\t\tlocalSeq <= this.getCollabWindow().localSeq,\n\t\t\t0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */,\n\t\t);\n\n\t\t// TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n\t\t// the original operation to the current position for undo/redo scenarios. This is probably the\n\t\t// ideal solution, as we would no longer need to store row/col handles in the op metadata.\n\t\t//\n\t\t// Failing that, we could avoid the O(n) search below by building a temporary map in the\n\t\t// opposite direction from the handle to either it's current position or segment + offset\n\t\t// and reuse it for the duration of undo/redo. (Ideally, we would know when the undo/redo\n\t\t// ended so we could discard this map.)\n\t\t//\n\t\t// If we find that we frequently need a reverse handle -> position lookup, we could maintain\n\t\t// one using the Tiny-Calc adjust tree.\n\t\tlet containingSegment!: PermutationSegment;\n\t\tlet containingOffset: number;\n\n\t\tthis.walkAllSegments((segment) => {\n\t\t\tconst { start, cachedLength } = segment as PermutationSegment;\n\n\t\t\t// If the segment is unallocated, skip it.\n\t\t\tif (!isHandleValid(start)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst end = start + cachedLength;\n\n\t\t\tif (start <= handle && handle < end) {\n\t\t\t\tcontainingSegment = segment as PermutationSegment;\n\t\t\t\tcontainingOffset = handle - start;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\t// We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n\t\t// row/col has been removed, because handles are not recycled until the containing segment\n\t\t// is unlinked from the MergeTree.\n\t\t//\n\t\t// Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n\t\t// ops that reference the stale handle, or the removal is unACKed, in which case the handle\n\t\t// has not yet been recycled.\n\n\t\tassert(\n\t\t\tisHandleValid(containingSegment.start),\n\t\t\t0x029 /* \"Invalid handle at start of containing segment!\" */,\n\t\t);\n\n\t\t// Once we know the current position of the handle, we can use the MergeTree to get the segment\n\t\t// containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n\t\t// have not yet been submitted.\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n\t}\n\n\t// Constructs an ISummaryTreeWithStats for the cell data.\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.segments,\n\t\t\tsuper.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer.stringify(this.handleTable.getSummaryContent(), handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t): Promise<{\n\t\tcatchupOpsP: Promise<ISequencedDocumentMessage[]>;\n\t}> {\n\t\tconst handleTableData = (await deserializeBlob(\n\t\t\tstorage,\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer,\n\t\t\t// Cast is needed since the (de)serializer returns content of type `any`.\n\t\t)) as Handle[];\n\n\t\tthis.handleTable = HandleTable.load<never>(handleTableData);\n\n\t\treturn super.load(\n\t\t\truntime,\n\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.segments),\n\t\t\tserializer,\n\t\t);\n\t}\n\n\tprivate readonly onDelta = (\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t): void => {\n\t\t// Apply deltas in descending order to prevent positions from shifting.\n\t\tconst ranges = deltaArgs.deltaSegments\n\t\t\t.map(({ segment }) => ({\n\t\t\t\tsegment: segment as PermutationSegment,\n\t\t\t\tposition: this.getPosition(segment),\n\t\t\t}))\n\t\t\t.sort((left, right) => left.position - right.position);\n\n\t\tconst isLocal = opArgs.sequencedMessage === undefined;\n\n\t\t// Notify the undo provider, if any is attached.\n\t\tif (this.undo !== undefined && isLocal) {\n\t\t\tthis.undo.record(deltaArgs);\n\t\t}\n\n\t\tswitch (deltaArgs.operation) {\n\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tif (opArgs.rollback !== true) {\n\t\t\t\t\t\t// HACK: We need to include the allocated handle in the segment's JSON representation\n\t\t\t\t\t\t// for snapshots, but need to ignore the remote client's handle allocations when\n\t\t\t\t\t\t// processing remote ops.\n\t\t\t\t\t\tsegment.reset();\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* deleteCount: */ 0,\n\t\t\t\t\t\t/* insertCount: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ 0,\n\t\t\t\t\t\t/* numInserted: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition /* deleteCount: */,\n\t\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\t\t/* insertCount: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ segment.cachedLength,\n\t\t\t\t\t\t/* numInsert: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(\"Unhandled MergeTreeDeltaType\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs): void => {\n\t\tif (args.operation === MergeTreeMaintenanceType.UNLINK) {\n\t\t\tlet freed: number[] = [];\n\n\t\t\tfor (const { segment } of args.deltaSegments) {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tif (isHandleValid(asPerm.start)) {\n\t\t\t\t\t// Note: Using the spread operator with `.splice()` can exhaust the stack.\n\t\t\t\t\t// eslint-disable-next-line unicorn/prefer-spread\n\t\t\t\t\tfreed = freed.concat(\n\t\t\t\t\t\tArray.from({ length: asPerm.cachedLength })\n\t\t\t\t\t\t\t.fill(0)\n\t\t\t\t\t\t\t.map((value, index) => index + asPerm.start),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n\t\t\t// the rows/cols prior to free to ensure recycled row/cols are initially empty.\n\t\t\tthis.handlesRecycledCallback(freed);\n\n\t\t\t// Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n\t\t\tfor (const handle of freed) {\n\t\t\t\tthis.handleTable.free(handle);\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic toString(): string {\n\t\tconst s: string[] = [];\n\n\t\tthis.walkSegments((segment) => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\ts.push(`${segment}`);\n\t\t\treturn true;\n\t\t});\n\n\t\treturn s.join(\"\");\n\t}\n}\n\nexport function reinsertSegmentIntoVector(\n\tvector: PermutationVector,\n\tpos: number,\n\tspec: IJSONSegment,\n): {\n\top: IMergeTreeInsertMsg | undefined;\n\tinserted: PermutationSegment;\n} {\n\tconst original = PermutationSegment.fromJSONObject(spec);\n\n\t// (Re)insert the removed number of rows at the original position.\n\tconst op = vector.insertSegmentLocal(pos, original);\n\tconst inserted = vector.getContainingSegment(pos).segment as PermutationSegment;\n\n\t// we reuse the original handle here\n\t// so if cells exist, they can be found, and re-inserted\n\tif (isHandleValid(original.start)) {\n\t\tinserted.start = original.start;\n\t}\n\n\t// Invalidate the handleCache in case it was populated during the 'rowsChanged'\n\t// callback, which occurs before the handle span is populated.\n\tvector.handleCache.itemsChanged(\n\t\tpos,\n\t\t/* removedCount: */ 0,\n\t\t/* insertedCount: */ inserted.cachedLength,\n\t);\n\treturn { op, inserted };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EACN,WAAW,EACX,MAAM,EAMN,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,GAGhB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACN,sBAAsB,EACtB,kBAAkB,GAClB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAU,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAUrD,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAI3C,MAAM,CAAC,cAAc,CAAC,IAAkB;QAC9C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAID,YAAY,MAAc,EAAE,KAAK,uCAAqB;QACrD,KAAK,EAAE,CAAC;QAVD,WAAM,wCAAsB;QAOpB,SAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC;QAIpD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,Y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;YACrB,OAAO,IAAI,CAAC;QACb,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;CACD;AAED,MAAM,UAAU,yBAAyB,CACxC,MAAyB,EACzB,GAAW,EACX,IAAkB;IAKlB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEzD,kEAAkE;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,OAA6B,CAAC;IAEjF,oCAAoC;IACpC,wDAAwD;IACxD,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,+EAA+E;IAC/E,8DAA8D;IAC9D,MAAM,CAAC,WAAW,CAAC,YAAY,CAC9B,GAAG;IACH,mBAAmB,CAAC,CAAC;IACrB,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAC1C,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACzB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tBaseSegment,\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeDeltaCallbackArgs,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeMaintenanceCallbackArgs,\n\tISegment,\n\tMergeTreeDeltaType,\n\tMergeTreeMaintenanceType,\n\tsegmentIsRemoved,\n\ttype IMergeTreeInsertMsg,\n\ttype IMergeTreeRemoveMsg,\n} from \"@fluidframework/merge-tree/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tObjectStoragePartition,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { HandleCache } from \"./handlecache.js\";\nimport { Handle, HandleTable, isHandleValid } from \"./handletable.js\";\nimport { deserializeBlob } from \"./serialization.js\";\nimport { VectorUndoProvider } from \"./undoprovider.js\";\n\nconst enum SnapshotPath {\n\tsegments = \"segments\",\n\thandleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n\tpublic static readonly typeString: string = \"PermutationSegment\";\n\tprivate _start = Handle.unallocated;\n\n\tpublic static fromJSONObject(spec: IJSONSegment): PermutationSegment {\n\t\tconst [length, start] = spec as PermutationSegmentSpec;\n\t\treturn new PermutationSegment(length, start);\n\t}\n\n\tpublic readonly type = PermutationSegment.typeString;\n\n\tconstructor(length: number, start = Handle.unallocated) {\n\t\tsuper();\n\t\tthis._start = start;\n\t\tthis.cachedLength = length;\n\t}\n\n\tpublic get start(): Handle {\n\t\treturn this._start;\n\t}\n\tpublic set start(value: Handle) {\n\t\tassert(\n\t\t\tthis._start === Handle.unallocated,\n\t\t\t0x024 /* \"Start of PermutationSegment already allocated!\" */,\n\t\t);\n\t\tassert(\n\t\t\tisHandleValid(value),\n\t\t\t0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */,\n\t\t);\n\n\t\tthis._start = value;\n\t}\n\n\tpublic reset(): void {\n\t\tthis._start = Handle.unallocated;\n\t}\n\n\tpublic toJSONObject(): number[] {\n\t\treturn [this.cachedLength, this.start];\n\t}\n\n\tpublic clone(start = 0, end = this.cachedLength): PermutationSegment {\n\t\tconst b = new PermutationSegment(\n\t\t\t/* length: */ end - start,\n\t\t\t/* start: */ this.start + start,\n\t\t);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tpublic canAppend(segment: ISegment): boolean {\n\t\tconst asPerm = segment as PermutationSegment;\n\n\t\treturn this.start === Handle.unallocated\n\t\t\t? asPerm.start === Handle.unallocated\n\t\t\t: asPerm.start === this.start + this.cachedLength;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number): PermutationSegment {\n\t\tassert(\n\t\t\t0 < pos && pos < this.cachedLength,\n\t\t\t0x026 /* \"Trying to split segment at out-of-bounds position!\" */,\n\t\t);\n\n\t\tconst leafSegment = new PermutationSegment(\n\t\t\t/* length: */ this.cachedLength - pos,\n\t\t\t/* start: */ this.start === Handle.unallocated ? Handle.unallocated : this.start + pos,\n\t\t);\n\n\t\tthis.cachedLength = pos;\n\n\t\treturn leafSegment;\n\t}\n\n\tpublic toString(): string {\n\t\treturn this.start === Handle.unallocated\n\t\t\t? `<${this.cachedLength} empty>`\n\t\t\t: `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n\t}\n}\n\n// eslint-disable-next-line import/no-deprecated\nexport class PermutationVector extends Client {\n\tprivate handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n\tpublic readonly handleCache = new HandleCache(this);\n\tpublic undo: VectorUndoProvider | undefined;\n\n\tconstructor(\n\t\tpath: string,\n\t\tlogger: ITelemetryBaseLogger,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tprivate readonly deltaCallback: (\n\t\t\tposition: number,\n\t\t\tnumRemoved: number,\n\t\t\tnumInserted: number,\n\t\t) => void,\n\t\tprivate readonly handlesRecycledCallback: (handles: Handle[]) => void,\n\t\tgetMinInFlightRefSeq: () => number | undefined,\n\t) {\n\t\tsuper(\n\t\t\tPermutationSegment.fromJSONObject,\n\t\t\tcreateChildLogger({ logger, namespace: `Matrix.${path}.MergeTreeClient` }),\n\t\t\t{\n\t\t\t\t...runtime.options,\n\t\t\t\tnewMergeTreeSnapshotFormat: true, // Force new snapshot format as it's generally more efficient for matrices.\n\t\t\t},\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.on(\"delta\", this.onDelta);\n\t\tthis.on(\"maintenance\", this.onMaintenance);\n\t}\n\n\tpublic insert(start: number, length: number): IMergeTreeInsertMsg | undefined {\n\t\treturn this.insertSegmentLocal(start, new PermutationSegment(length));\n\t}\n\n\tpublic remove(start: number, length: number): IMergeTreeRemoveMsg {\n\t\treturn this.removeRangeLocal(start, start + length);\n\t}\n\n\tpublic getMaybeHandle(pos: number): Handle {\n\t\tassert(\n\t\t\t0 <= pos && pos < this.getLength(),\n\t\t\t0x027 /* \"Trying to get handle of out-of-bounds position!\" */,\n\t\t);\n\n\t\treturn this.handleCache.getHandle(pos);\n\t}\n\n\tpublic getAllocatedHandle(pos: number): Handle {\n\t\tlet handle = this.getMaybeHandle(pos);\n\t\tif (isHandleValid(handle)) {\n\t\t\treturn handle;\n\t\t}\n\n\t\tthis.walkSegments(\n\t\t\t(segment) => {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tpos,\n\t\t\tpos + 1,\n\t\t\t/* accum: */ undefined,\n\t\t\t/* splitRange: */ true,\n\t\t);\n\n\t\tthis.handleCache.addHandle(pos, handle);\n\n\t\treturn handle;\n\t}\n\n\tpublic adjustPosition(\n\t\tposToAdjust: number,\n\t\top: ISequencedDocumentMessage,\n\t): { pos: number | undefined; handle: Handle } {\n\t\tconst segOff = this.getContainingSegment<PermutationSegment>(posToAdjust, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\n\t\tassert(\n\t\t\tsegOff !== undefined,\n\t\t\t0xbac /* segment must be available for operations in the collab window */,\n\t\t);\n\t\tconst { segment, offset } = segOff;\n\n\t\tif (segmentIsRemoved(segment)) {\n\t\t\t// this case is tricky. the segment which the row or column data is remove\n\t\t\t// but an op before that remove references a cell. we still want to apply\n\t\t\t// the op, as the row/col could become active again in the case where\n\t\t\t// the remove was local and it get's rolled back. so we allocate a handle\n\t\t\t// for the row/col if not allocated, but don't put it in the cache\n\t\t\t// as the cache can only contain live positions.\n\t\t\tlet handle = segment.start;\n\t\t\tif (!isHandleValid(handle)) {\n\t\t\t\tthis.walkSegments(\n\t\t\t\t\t(s) => {\n\t\t\t\t\t\tconst asPerm = s as PermutationSegment;\n\t\t\t\t\t\tasPerm.start = handle = this.handleTable.allocate();\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t\tposToAdjust,\n\t\t\t\t\tposToAdjust + 1,\n\t\t\t\t\t/* accum: */ undefined,\n\t\t\t\t\t/* splitRange: */ true,\n\t\t\t\t\top,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn { handle, pos: undefined };\n\t\t} else {\n\t\t\tconst pos = this.getPosition(segment) + offset;\n\t\t\treturn {\n\t\t\t\tpos,\n\t\t\t\thandle: this.getAllocatedHandle(pos),\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic handleToPosition(handle: Handle, localSeq = this.getCollabWindow().localSeq): number {\n\t\tassert(\n\t\t\tlocalSeq <= this.getCollabWindow().localSeq,\n\t\t\t0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */,\n\t\t);\n\n\t\t// TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n\t\t// the original operation to the current position for undo/redo scenarios. This is probably the\n\t\t// ideal solution, as we would no longer need to store row/col handles in the op metadata.\n\t\t//\n\t\t// Failing that, we could avoid the O(n) search below by building a temporary map in the\n\t\t// opposite direction from the handle to either it's current position or segment + offset\n\t\t// and reuse it for the duration of undo/redo. (Ideally, we would know when the undo/redo\n\t\t// ended so we could discard this map.)\n\t\t//\n\t\t// If we find that we frequently need a reverse handle -> position lookup, we could maintain\n\t\t// one using the Tiny-Calc adjust tree.\n\t\tlet containingSegment!: PermutationSegment;\n\t\tlet containingOffset: number;\n\n\t\tthis.walkAllSegments((segment) => {\n\t\t\tconst { start, cachedLength } = segment as PermutationSegment;\n\n\t\t\t// If the segment is unallocated, skip it.\n\t\t\tif (!isHandleValid(start)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst end = start + cachedLength;\n\n\t\t\tif (start <= handle && handle < end) {\n\t\t\t\tcontainingSegment = segment as PermutationSegment;\n\t\t\t\tcontainingOffset = handle - start;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\n\t\t// We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n\t\t// row/col has been removed, because handles are not recycled until the containing segment\n\t\t// is unlinked from the MergeTree.\n\t\t//\n\t\t// Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n\t\t// ops that reference the stale handle, or the removal is unACKed, in which case the handle\n\t\t// has not yet been recycled.\n\n\t\tassert(\n\t\t\tisHandleValid(containingSegment.start),\n\t\t\t0x029 /* \"Invalid handle at start of containing segment!\" */,\n\t\t);\n\n\t\t// Once we know the current position of the handle, we can use the MergeTree to get the segment\n\t\t// containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n\t\t// have not yet been submitted.\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n\t}\n\n\t// Constructs an ISummaryTreeWithStats for the cell data.\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addWithStats(\n\t\t\tSnapshotPath.segments,\n\t\t\tsuper.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []),\n\t\t);\n\t\tbuilder.addBlob(\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer.stringify(this.handleTable.getSummaryContent(), handle),\n\t\t);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t): Promise<{\n\t\tcatchupOpsP: Promise<ISequencedDocumentMessage[]>;\n\t}> {\n\t\tconst handleTableData = (await deserializeBlob(\n\t\t\tstorage,\n\t\t\tSnapshotPath.handleTable,\n\t\t\tserializer,\n\t\t\t// Cast is needed since the (de)serializer returns content of type `any`.\n\t\t)) as Handle[];\n\n\t\tthis.handleTable = HandleTable.load<never>(handleTableData);\n\n\t\treturn super.load(\n\t\t\truntime,\n\t\t\tnew ObjectStoragePartition(storage, SnapshotPath.segments),\n\t\t\tserializer,\n\t\t);\n\t}\n\n\tprivate readonly onDelta = (\n\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t): void => {\n\t\t// Apply deltas in descending order to prevent positions from shifting.\n\t\tconst ranges = deltaArgs.deltaSegments\n\t\t\t.map(({ segment }) => ({\n\t\t\t\tsegment: segment as PermutationSegment,\n\t\t\t\tposition: this.getPosition(segment),\n\t\t\t}))\n\t\t\t.sort((left, right) => left.position - right.position);\n\n\t\tconst isLocal = opArgs.sequencedMessage === undefined;\n\n\t\t// Notify the undo provider, if any is attached.\n\t\tif (this.undo !== undefined && isLocal) {\n\t\t\tthis.undo.record(deltaArgs);\n\t\t}\n\n\t\tswitch (deltaArgs.operation) {\n\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tif (opArgs.rollback !== true) {\n\t\t\t\t\t\t// HACK: We need to include the allocated handle in the segment's JSON representation\n\t\t\t\t\t\t// for snapshots, but need to ignore the remote client's handle allocations when\n\t\t\t\t\t\t// processing remote ops.\n\t\t\t\t\t\tsegment.reset();\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* deleteCount: */ 0,\n\t\t\t\t\t\t/* insertCount: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ 0,\n\t\t\t\t\t\t/* numInserted: */ segment.cachedLength,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t// Pass 1: Perform any internal maintenance first to avoid reentrancy.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.handleCache.itemsChanged(\n\t\t\t\t\t\tposition /* deleteCount: */,\n\t\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\t\t/* insertCount: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n\t\t\t\tfor (const { segment, position } of ranges) {\n\t\t\t\t\tthis.deltaCallback(\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\t/* numRemoved: */ segment.cachedLength,\n\t\t\t\t\t\t/* numInsert: */ 0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(\"Unhandled MergeTreeDeltaType\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs): void => {\n\t\tif (args.operation === MergeTreeMaintenanceType.UNLINK) {\n\t\t\tlet freed: number[] = [];\n\n\t\t\tfor (const { segment } of args.deltaSegments) {\n\t\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\t\tif (isHandleValid(asPerm.start)) {\n\t\t\t\t\t// Note: Using the spread operator with `.splice()` can exhaust the stack.\n\t\t\t\t\t// eslint-disable-next-line unicorn/prefer-spread\n\t\t\t\t\tfreed = freed.concat(\n\t\t\t\t\t\tArray.from({ length: asPerm.cachedLength })\n\t\t\t\t\t\t\t.fill(0)\n\t\t\t\t\t\t\t.map((value, index) => index + asPerm.start),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n\t\t\t// the rows/cols prior to free to ensure recycled row/cols are initially empty.\n\t\t\tthis.handlesRecycledCallback(freed);\n\n\t\t\t// Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n\t\t\tfor (const handle of freed) {\n\t\t\t\tthis.handleTable.free(handle);\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic toString(): string {\n\t\tconst s: string[] = [];\n\n\t\tthis.walkSegments((segment) => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\ts.push(`${segment}`);\n\t\t\treturn true;\n\t\t});\n\n\t\treturn s.join(\"\");\n\t}\n}\n\nexport function reinsertSegmentIntoVector(\n\tvector: PermutationVector,\n\tpos: number,\n\tspec: IJSONSegment,\n): {\n\top: IMergeTreeInsertMsg | undefined;\n\tinserted: PermutationSegment;\n} {\n\tconst original = PermutationSegment.fromJSONObject(spec);\n\n\t// (Re)insert the removed number of rows at the original position.\n\tconst op = vector.insertSegmentLocal(pos, original);\n\tconst inserted = vector.getContainingSegment(pos)?.segment as PermutationSegment;\n\n\t// we reuse the original handle here\n\t// so if cells exist, they can be found, and re-inserted\n\tif (isHandleValid(original.start)) {\n\t\tinserted.start = original.start;\n\t}\n\n\t// Invalidate the handleCache in case it was populated during the 'rowsChanged'\n\t// callback, which occurs before the handle span is populated.\n\tvector.handleCache.itemsChanged(\n\t\tpos,\n\t\t/* removedCount: */ 0,\n\t\t/* insertedCount: */ inserted.cachedLength,\n\t);\n\treturn { op, inserted };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/matrix",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.43.0",
|
|
4
4
|
"description": "Distributed matrix",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -81,17 +81,17 @@
|
|
|
81
81
|
"temp-directory": "nyc/.nyc_output"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@fluid-internal/client-utils": "~2.
|
|
85
|
-
"@fluidframework/core-interfaces": "~2.
|
|
86
|
-
"@fluidframework/core-utils": "~2.
|
|
87
|
-
"@fluidframework/datastore-definitions": "~2.
|
|
88
|
-
"@fluidframework/driver-definitions": "~2.
|
|
89
|
-
"@fluidframework/driver-utils": "~2.
|
|
90
|
-
"@fluidframework/merge-tree": "~2.
|
|
91
|
-
"@fluidframework/runtime-definitions": "~2.
|
|
92
|
-
"@fluidframework/runtime-utils": "~2.
|
|
93
|
-
"@fluidframework/shared-object-base": "~2.
|
|
94
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
84
|
+
"@fluid-internal/client-utils": "~2.43.0",
|
|
85
|
+
"@fluidframework/core-interfaces": "~2.43.0",
|
|
86
|
+
"@fluidframework/core-utils": "~2.43.0",
|
|
87
|
+
"@fluidframework/datastore-definitions": "~2.43.0",
|
|
88
|
+
"@fluidframework/driver-definitions": "~2.43.0",
|
|
89
|
+
"@fluidframework/driver-utils": "~2.43.0",
|
|
90
|
+
"@fluidframework/merge-tree": "~2.43.0",
|
|
91
|
+
"@fluidframework/runtime-definitions": "~2.43.0",
|
|
92
|
+
"@fluidframework/runtime-utils": "~2.43.0",
|
|
93
|
+
"@fluidframework/shared-object-base": "~2.43.0",
|
|
94
|
+
"@fluidframework/telemetry-utils": "~2.43.0",
|
|
95
95
|
"@tiny-calc/nano": "0.0.0-alpha.5",
|
|
96
96
|
"double-ended-queue": "^2.1.0-0",
|
|
97
97
|
"tslib": "^1.10.0"
|
|
@@ -99,17 +99,17 @@
|
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
101
101
|
"@biomejs/biome": "~1.9.3",
|
|
102
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
103
|
-
"@fluid-private/stochastic-test-utils": "~2.
|
|
104
|
-
"@fluid-private/test-dds-utils": "~2.
|
|
102
|
+
"@fluid-internal/mocha-test-setup": "~2.43.0",
|
|
103
|
+
"@fluid-private/stochastic-test-utils": "~2.43.0",
|
|
104
|
+
"@fluid-private/test-dds-utils": "~2.43.0",
|
|
105
105
|
"@fluid-tools/benchmark": "^0.51.0",
|
|
106
|
-
"@fluid-tools/build-cli": "^0.
|
|
106
|
+
"@fluid-tools/build-cli": "^0.56.0",
|
|
107
107
|
"@fluidframework/build-common": "^2.0.3",
|
|
108
|
-
"@fluidframework/build-tools": "^0.
|
|
109
|
-
"@fluidframework/container-definitions": "~2.
|
|
108
|
+
"@fluidframework/build-tools": "^0.56.0",
|
|
109
|
+
"@fluidframework/container-definitions": "~2.43.0",
|
|
110
110
|
"@fluidframework/eslint-config-fluid": "^5.7.4",
|
|
111
|
-
"@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.
|
|
112
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
111
|
+
"@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.42.0",
|
|
112
|
+
"@fluidframework/test-runtime-utils": "~2.43.0",
|
|
113
113
|
"@microsoft/api-extractor": "7.52.8",
|
|
114
114
|
"@tiny-calc/micro": "0.0.0-alpha.5",
|
|
115
115
|
"@types/double-ended-queue": "^2.1.0",
|
package/src/handlecache.ts
CHANGED
|
@@ -82,10 +82,10 @@ export class HandleCache implements IVectorConsumer<Handle> {
|
|
|
82
82
|
const { vector } = this;
|
|
83
83
|
|
|
84
84
|
for (let pos = start; pos < end; pos++) {
|
|
85
|
-
const { segment, offset } = vector.getContainingSegment(pos);
|
|
86
|
-
const asPerm = segment as PermutationSegment;
|
|
87
85
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
88
|
-
|
|
86
|
+
const { segment, offset } = vector.getContainingSegment(pos)!;
|
|
87
|
+
const asPerm = segment as PermutationSegment;
|
|
88
|
+
handles.push(asPerm.start + offset);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
package/src/matrix.ts
CHANGED
|
@@ -465,10 +465,7 @@ export class SharedMatrix<T = any>
|
|
|
465
465
|
localSeq: number,
|
|
466
466
|
): LocalReferencePosition {
|
|
467
467
|
const segoff = vector.getContainingSegment(pos, undefined, localSeq);
|
|
468
|
-
assert(
|
|
469
|
-
segoff.segment !== undefined && segoff.offset !== undefined,
|
|
470
|
-
0x8b3 /* expected valid position */,
|
|
471
|
-
);
|
|
468
|
+
assert(segoff !== undefined, 0x8b3 /* expected valid position */);
|
|
472
469
|
return vector.createLocalReferencePosition(
|
|
473
470
|
segoff.segment,
|
|
474
471
|
segoff.offset,
|
package/src/packageVersion.ts
CHANGED
package/src/permutationvector.ts
CHANGED
|
@@ -201,15 +201,16 @@ export class PermutationVector extends Client {
|
|
|
201
201
|
posToAdjust: number,
|
|
202
202
|
op: ISequencedDocumentMessage,
|
|
203
203
|
): { pos: number | undefined; handle: Handle } {
|
|
204
|
-
const
|
|
204
|
+
const segOff = this.getContainingSegment<PermutationSegment>(posToAdjust, {
|
|
205
205
|
referenceSequenceNumber: op.referenceSequenceNumber,
|
|
206
206
|
clientId: op.clientId,
|
|
207
207
|
});
|
|
208
208
|
|
|
209
209
|
assert(
|
|
210
|
-
|
|
210
|
+
segOff !== undefined,
|
|
211
211
|
0xbac /* segment must be available for operations in the collab window */,
|
|
212
212
|
);
|
|
213
|
+
const { segment, offset } = segOff;
|
|
213
214
|
|
|
214
215
|
if (segmentIsRemoved(segment)) {
|
|
215
216
|
// this case is tricky. the segment which the row or column data is remove
|
|
@@ -471,7 +472,7 @@ export function reinsertSegmentIntoVector(
|
|
|
471
472
|
|
|
472
473
|
// (Re)insert the removed number of rows at the original position.
|
|
473
474
|
const op = vector.insertSegmentLocal(pos, original);
|
|
474
|
-
const inserted = vector.getContainingSegment(pos)
|
|
475
|
+
const inserted = vector.getContainingSegment(pos)?.segment as PermutationSegment;
|
|
475
476
|
|
|
476
477
|
// we reuse the original handle here
|
|
477
478
|
// so if cells exist, they can be found, and re-inserted
|