@fluidframework/matrix 0.54.3 → 0.55.2

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 (43) hide show
  1. package/.eslintrc.js +1 -1
  2. package/dist/handletable.d.ts +1 -1
  3. package/dist/handletable.d.ts.map +1 -1
  4. package/dist/handletable.js +1 -1
  5. package/dist/handletable.js.map +1 -1
  6. package/dist/matrix.d.ts +7 -8
  7. package/dist/matrix.d.ts.map +1 -1
  8. package/dist/matrix.js +12 -34
  9. package/dist/matrix.js.map +1 -1
  10. package/dist/packageVersion.d.ts +1 -1
  11. package/dist/packageVersion.js +1 -1
  12. package/dist/packageVersion.js.map +1 -1
  13. package/dist/permutationvector.d.ts +4 -3
  14. package/dist/permutationvector.d.ts.map +1 -1
  15. package/dist/permutationvector.js +8 -15
  16. package/dist/permutationvector.js.map +1 -1
  17. package/dist/serialization.d.ts +2 -1
  18. package/dist/serialization.d.ts.map +1 -1
  19. package/dist/serialization.js.map +1 -1
  20. package/lib/handletable.d.ts +1 -1
  21. package/lib/handletable.d.ts.map +1 -1
  22. package/lib/handletable.js +1 -1
  23. package/lib/handletable.js.map +1 -1
  24. package/lib/matrix.d.ts +7 -8
  25. package/lib/matrix.d.ts.map +1 -1
  26. package/lib/matrix.js +15 -37
  27. package/lib/matrix.js.map +1 -1
  28. package/lib/packageVersion.d.ts +1 -1
  29. package/lib/packageVersion.js +1 -1
  30. package/lib/packageVersion.js.map +1 -1
  31. package/lib/permutationvector.d.ts +4 -3
  32. package/lib/permutationvector.d.ts.map +1 -1
  33. package/lib/permutationvector.js +10 -17
  34. package/lib/permutationvector.js.map +1 -1
  35. package/lib/serialization.d.ts +2 -1
  36. package/lib/serialization.d.ts.map +1 -1
  37. package/lib/serialization.js.map +1 -1
  38. package/package.json +20 -19
  39. package/src/handletable.ts +1 -1
  40. package/src/matrix.ts +18 -53
  41. package/src/packageVersion.ts +1 -1
  42. package/src/permutationvector.ts +14 -18
  43. package/src/serialization.ts +2 -1
@@ -5,8 +5,9 @@
5
5
  import { IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions";
6
6
  import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
7
7
  import { BaseSegment, ISegment, Client } from "@fluidframework/merge-tree";
8
- import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
9
- import { ITree } from "@fluidframework/protocol-definitions";
8
+ import { IFluidHandle } from "@fluidframework/core-interfaces";
9
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
10
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
10
11
  import { Handle } from "./handletable";
11
12
  import { HandleCache } from "./handlecache";
12
13
  import { VectorUndoProvider } from "./undoprovider";
@@ -50,7 +51,7 @@ export declare class PermutationVector extends Client {
50
51
  getAllocatedHandle(pos: number): Handle;
51
52
  adjustPosition(pos: number, fromSeq: number, clientId: number): number | undefined;
52
53
  handleToPosition(handle: Handle, localSeq?: number): number;
53
- snapshot(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer): ITree;
54
+ summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer): ISummaryTreeWithStats;
54
55
  load(runtime: IFluidDataStoreRuntime, storage: IChannelStorageService, serializer: IFluidSerializer): Promise<{
55
56
  catchupOpsP: Promise<import("@fluidframework/protocol-definitions").ISequencedDocumentMessage[]>;
56
57
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"permutationvector.d.ts","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EACH,WAAW,EACX,QAAQ,EAER,MAAM,EAQT,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,gBAAgB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CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMpC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM;;;;IAWhD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAIpC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAMnC,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAsBvC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAc7D,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAuC;IA2DhF,SAAS,CAAC,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,GAChG,qBAAqB;IAOZ,IAAI,CACb,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,gBAAgB;;;IAShC,OAAO,CAAC,QAAQ,CAAC,OAAO,CA2DtB;IAEF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAyB5B;IAEK,QAAQ;CAUlB"}
@@ -5,10 +5,9 @@
5
5
  import { assert } from "@fluidframework/common-utils";
6
6
  import { ChildLogger } from "@fluidframework/telemetry-utils";
7
7
  import { BaseSegment, LocalReferenceCollection, Client, LocalReference, ReferenceType, } from "@fluidframework/merge-tree";
8
- import { FileMode, TreeEntry } from "@fluidframework/protocol-definitions";
9
- import { ObjectStoragePartition } from "@fluidframework/runtime-utils";
8
+ import { ObjectStoragePartition, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
10
9
  import { HandleTable, isHandleValid } from "./handletable";
11
- import { serializeBlob, deserializeBlob } from "./serialization";
10
+ import { deserializeBlob } from "./serialization";
12
11
  import { HandleCache } from "./handlecache";
13
12
  export class PermutationSegment extends BaseSegment {
14
13
  constructor(length, start = -2147483648 /* unallocated */) {
@@ -257,22 +256,16 @@ export class PermutationVector extends Client {
257
256
  // Once we know the current position of the handle, we can use the MergeTree to get the segment
258
257
  // containing this position and use 'findReconnectionPosition' to adjust for the local ops that
259
258
  // have not yet been submitted.
260
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
259
+ // eslint-disable-next-line max-len
260
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
261
261
  return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset;
262
262
  }
263
- // Constructs an ITreeEntry for the cell data.
264
- snapshot(runtime, handle, serializer) {
265
- return {
266
- entries: [
267
- {
268
- mode: FileMode.Directory,
269
- path: "segments" /* segments */,
270
- type: TreeEntry.Tree,
271
- value: super.snapshot(runtime, handle, serializer, /* catchUpMsgs: */ []),
272
- },
273
- serializeBlob(handle, "handleTable" /* handleTable */, this.handleTable.snapshot(), serializer),
274
- ],
275
- };
263
+ // Constructs an ISummaryTreeWithStats for the cell data.
264
+ summarize(runtime, handle, serializer) {
265
+ const builder = new SummaryTreeBuilder();
266
+ builder.addWithStats("segments" /* segments */, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */ []));
267
+ builder.addBlob("handleTable" /* handleTable */, serializer.stringify(this.handleTable.getSummaryContent(), handle));
268
+ return builder.getSummaryTree();
276
269
  }
277
270
  async load(runtime, storage, serializer) {
278
271
  const handleTableData = await deserializeBlob(storage, "handleTable" /* handleTable */, serializer);
@@ -1 +1 @@
1
- {"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,EACH,WAAW,EAEX,wBAAwB,EACxB,MAAM,EAMN,cAAc,EACd,aAAa,GAChB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAS,M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B,OAA+B,EAC/B,UAA4B;QAE5B,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,OAAO,mCAA4B,UAAU,CAAC,CAAC;QAE7F,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,IAAI,CAAQ,eAAe,CAAC,CAAC;QAE5D,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,sBAAsB,CAAC,OAAO,4BAAwB,EAAE,UAAU,CAAC,CAAC;IACvG,CAAC;IA0FM,QAAQ;QACX,MAAM,CAAC,GAAa,EAAE,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { IFluidDataStoreRuntime, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n BaseSegment,\n ISegment,\n LocalReferenceCollection,\n Client,\n IMergeTreeDeltaOpArgs,\n IMergeTreeDeltaCallbackArgs,\n MergeTreeDeltaType,\n IMergeTreeMaintenanceCallbackArgs,\n MergeTreeMaintenanceType,\n LocalReference,\n ReferenceType,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport { FileMode, TreeEntry, ITree } from \"@fluidframework/protocol-definitions\";\nimport { ObjectStoragePartition } from \"@fluidframework/runtime-utils\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { serializeBlob, deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n segments = \"segments\",\n handleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n public static readonly typeString: string = \"PermutationSegment\";\n private _start = Handle.unallocated;\n\n public static fromJSONObject(spec: any) {\n const [length, start] = spec as PermutationSegmentSpec;\n return new PermutationSegment(length, start);\n }\n\n public readonly type = PermutationSegment.typeString;\n\n constructor(length: number, start = Handle.unallocated) {\n super();\n this._start = start;\n this.cachedLength = length;\n }\n\n public get start() { return this._start; }\n public set start(value: Handle) {\n assert(this._start === Handle.unallocated, 0x024 /* \"Start of PermutationSegment already allocated!\" */);\n assert(isHandleValid(value), 0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */);\n\n this._start = value;\n }\n\n /**\n * Invoked by '_undoRow/ColRemove' to prepare the newly inserted destination\n * segment to serve as the replacement for this removed segment. This moves handle\n * allocations from this segment to the replacement as well as maintains tracking\n * groups for the undo/redo stack.\n */\n public transferToReplacement(destination: PermutationSegment) {\n // When this segment was removed, it may have been split from a larger original\n // segment. In this case, it will have been added to an undo/redo tracking group\n // that associates all of the fragments from the original insertion.\n //\n // Move this association from the this removed segment to its replacement so that\n // it is included if the undo stack continues to unwind to the original insertion.\n //\n // Out of paranoia we link and unlink in separate loops to avoid mutating the underlying\n // set during enumeration. In pratice, this is unlikely to matter since there should be\n // exactly 0 or 1 items in the enumeration.\n for (const group of this.trackingCollection.trackingGroups) {\n group.link(destination);\n }\n for (const group of this.trackingCollection.trackingGroups) {\n group.unlink(this);\n }\n\n // Move handle allocations from this segment to its replacement.\n destination._start = this._start;\n this.reset();\n }\n\n public reset() {\n this._start = Handle.unallocated;\n }\n\n public toJSONObject() {\n return [this.cachedLength, this.start];\n }\n\n public clone(start = 0, end = this.cachedLength) {\n const b = new PermutationSegment(\n /* length: */ end - start,\n /* start: */ this.start + start);\n this.cloneInto(b);\n return b;\n }\n\n public canAppend(segment: ISegment) {\n const asPerm = segment as PermutationSegment;\n\n return this.start === Handle.unallocated\n ? asPerm.start === Handle.unallocated\n : asPerm.start === this.start + this.cachedLength;\n }\n\n public append(segment: ISegment) {\n // Note: Must call 'LocalReferenceCollection.append(..)' before modifying this segment's length as\n // 'this.cachedLength' is used to adjust the offsets of the local refs.\n LocalReferenceCollection.append(this, segment);\n\n this.cachedLength += segment.cachedLength;\n }\n\n protected createSplitSegmentAt(pos: number) {\n assert(0 < pos && pos < this.cachedLength, 0x026 /* \"Trying to split segment at out-of-bounds position!\" */);\n\n const leafSegment = new PermutationSegment(\n /* length: */ this.cachedLength - pos,\n /* start: */ this.start === Handle.unallocated\n ? Handle.unallocated\n : this.start + pos);\n\n this.cachedLength = pos;\n\n return leafSegment;\n }\n\n public toString() {\n return this.start === Handle.unallocated\n ? `<${this.cachedLength} empty>`\n : `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n }\n}\n\nexport class PermutationVector extends Client {\n private handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n public readonly handleCache = new HandleCache(this);\n public undo: VectorUndoProvider | undefined;\n\n constructor(\n path: string,\n logger: ITelemetryBaseLogger,\n runtime: IFluidDataStoreRuntime,\n private readonly deltaCallback: (position: number, numRemoved: number, numInserted: number) => void,\n private readonly handlesRecycledCallback: (handles: Handle[]) => void,\n ) {\n super(\n PermutationSegment.fromJSONObject,\n ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`), {\n ...runtime.options,\n newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n }); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n this.mergeTreeDeltaCallback = this.onDelta;\n this.mergeTreeMaintenanceCallback = this.onMaintenance;\n }\n\n public insert(start: number, length: number) {\n return this.insertSegmentLocal(\n start,\n new PermutationSegment(length));\n }\n\n public insertRelative(segment: ISegment, length: number) {\n const inserted = new PermutationSegment(length);\n\n return {\n op: this.insertAtReferencePositionLocal(\n new LocalReference(this, segment, /* offset: */ 0, ReferenceType.Transient),\n inserted),\n inserted,\n };\n }\n\n public remove(start: number, length: number) {\n return this.removeRangeLocal(start, start + length);\n }\n\n public getMaybeHandle(pos: number): Handle {\n assert(0 <= pos && pos < this.getLength(), 0x027 /* \"Trying to get handle of out-of-bounds position!\" */);\n\n return this.handleCache.getHandle(pos);\n }\n\n public getAllocatedHandle(pos: number): Handle {\n let handle = this.getMaybeHandle(pos);\n if (isHandleValid(handle)) {\n return handle;\n }\n\n this.walkSegments(\n (segment) => {\n const asPerm = segment as PermutationSegment;\n asPerm.start = handle = this.handleTable.allocate();\n return true;\n },\n pos,\n pos + 1,\n /* accum: */ undefined,\n /* splitRange: */ true);\n\n this.handleCache.addHandle(pos, handle);\n\n return handle;\n }\n\n public adjustPosition(pos: number, fromSeq: number, clientId: number) {\n const { segment, offset } = this.mergeTree.getContainingSegment(pos, fromSeq, clientId);\n\n // Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n // a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n // by checking for the presence of 'removedSeq'.\n if (segment === undefined || segment.removedSeq !== undefined) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.getPosition(segment) + offset!;\n }\n\n public handleToPosition(handle: Handle, localSeq = this.mergeTree.collabWindow.localSeq) {\n assert(localSeq <= this.mergeTree.collabWindow.localSeq,\n 0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */);\n\n // TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n // the original operation to the current position for resubmitting. This is probably the\n // ideal solution, as we would no longer need to store row/col handles in the op metadata.\n //\n // Failing that, we could avoid the O(n) search below by building a temporary map in the\n // opposite direction from the handle to either it's current position or segment + offset\n // and reuse it for the duration of resubmission. (Ideally, we would know when resubmission\n // ended so we could discard this map.)\n //\n // If we find that we frequently need a reverse handle -> position lookup, we could maintain\n // one using the Tiny-Calc adjust tree.\n let containingSegment!: PermutationSegment;\n let containingOffset: number;\n\n this.mergeTree.walkAllSegments(\n this.mergeTree.root,\n (segment) => {\n const { start, cachedLength } = segment as PermutationSegment;\n\n // If the segment is unallocated, skip it.\n if (!isHandleValid(start)) {\n return true;\n }\n\n const end = start + cachedLength;\n\n if (start <= handle && handle < end) {\n containingSegment = segment as PermutationSegment;\n containingOffset = handle - start;\n return false;\n }\n\n return true;\n });\n\n // We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n // row/col has been removed, because handles are not recycled until the containing segment\n // is unlinked from the MergeTree.\n //\n // Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n // ops that reference the stale handle, or the removal is unACKed, in which case the handle\n // has not yet been recycled.\n\n assert(isHandleValid(containingSegment.start), 0x029 /* \"Invalid handle at start of containing segment!\" */);\n\n // Once we know the current position of the handle, we can use the MergeTree to get the segment\n // containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n // have not yet been submitted.\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset!;\n }\n\n // Constructs an ITreeEntry for the cell data.\n public snapshot(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer): ITree {\n return {\n entries: [\n {\n mode: FileMode.Directory,\n path: SnapshotPath.segments,\n type: TreeEntry.Tree,\n value: super.snapshot(runtime, handle, serializer, /* catchUpMsgs: */[]),\n },\n serializeBlob(handle, SnapshotPath.handleTable, this.handleTable.snapshot(), serializer),\n ],\n };\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n storage: IChannelStorageService,\n serializer: IFluidSerializer,\n ) {\n const handleTableData = await deserializeBlob(storage, SnapshotPath.handleTable, serializer);\n\n this.handleTable = HandleTable.load<never>(handleTableData);\n\n return super.load(runtime, new ObjectStoragePartition(storage, SnapshotPath.segments), serializer);\n }\n\n private readonly onDelta = (\n opArgs: IMergeTreeDeltaOpArgs,\n { operation, deltaSegments }: IMergeTreeDeltaCallbackArgs,\n ) => {\n // Apply deltas in descending order to prevent positions from shifting.\n const ranges = deltaSegments\n .map(({ segment }) => ({\n segment: segment as PermutationSegment,\n position: this.getPosition(segment),\n }))\n .sort((left, right) => left.position - right.position);\n\n const isLocal = opArgs.sequencedMessage === undefined;\n\n // Notify the undo provider, if any is attached.\n if (this.undo !== undefined && isLocal) {\n this.undo.record(operation, ranges);\n }\n\n switch (operation) {\n case MergeTreeDeltaType.INSERT:\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n // HACK: We need to include the allocated handle in the segment's JSON reperesntation\n // for snapshots, but need to ignore the remote client's handle allocations when\n // processing remote ops.\n segment.reset();\n\n this.handleCache.itemsChanged(\n position,\n /* deleteCount: */ 0,\n /* insertCount: */ segment.cachedLength);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ 0, /* numInserted: */ segment.cachedLength);\n }\n break;\n\n case MergeTreeDeltaType.REMOVE: {\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n this.handleCache.itemsChanged(\n position, /* deleteCount: */\n segment.cachedLength,\n /* insertCount: */ 0);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ segment.cachedLength, /* numInsert: */ 0);\n }\n break;\n }\n\n default:\n throw new Error(\"Unhandled MergeTreeDeltaType\");\n }\n };\n\n private readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n if (args.operation === MergeTreeMaintenanceType.UNLINK) {\n let freed: number[] = [];\n\n for (const { segment } of args.deltaSegments) {\n const asPerm = segment as PermutationSegment;\n if (isHandleValid(asPerm.start)) {\n // Note: Using the spread operator with `.splice()` can exhaust the stack.\n freed = freed.concat(\n new Array(asPerm.cachedLength)\n .fill(0)\n .map((value, index) => index + asPerm.start),\n );\n }\n }\n\n // Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n // the rows/cols prior to free to ensure recycled row/cols are initially empty.\n this.handlesRecycledCallback(freed);\n\n // Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n for (const handle of freed) {\n this.handleTable.free(handle);\n }\n }\n };\n\n public toString() {\n const s: string[] = [];\n\n this.walkSegments((segment) => {\n s.push(`${segment}`);\n return true;\n });\n\n return s.join(\"\");\n }\n}\n"]}
1
+ {"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,EACH,WAAW,EAEX,wBAAwB,EACxB,MAAM,EAMN,cAAc,EACd,aAAa,GAChB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAW/C,YAAY,MAAc,EAAE,KAAK,gCAAqB;QAClD,KAAK,EAAE,CAAC;QAVJ,WAAM,iCAAsB;QAOpB,SAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC;QAIjD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC/B,CAAC;IAXM,MAAM,CAAC,cAAc,CAAC,IAAS;QAClC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAAC,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* Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { IFluidDataStoreRuntime, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n BaseSegment,\n ISegment,\n LocalReferenceCollection,\n Client,\n IMergeTreeDeltaOpArgs,\n IMergeTreeDeltaCallbackArgs,\n MergeTreeDeltaType,\n IMergeTreeMaintenanceCallbackArgs,\n MergeTreeMaintenanceType,\n LocalReference,\n ReferenceType,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n segments = \"segments\",\n handleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n public static readonly typeString: string = \"PermutationSegment\";\n private _start = Handle.unallocated;\n\n public static fromJSONObject(spec: any) {\n const [length, start] = spec as PermutationSegmentSpec;\n return new PermutationSegment(length, start);\n }\n\n public readonly type = PermutationSegment.typeString;\n\n constructor(length: number, start = Handle.unallocated) {\n super();\n this._start = start;\n this.cachedLength = length;\n }\n\n public get start() { return this._start; }\n public set start(value: Handle) {\n assert(this._start === Handle.unallocated, 0x024 /* \"Start of PermutationSegment already allocated!\" */);\n assert(isHandleValid(value), 0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */);\n\n this._start = value;\n }\n\n /**\n * Invoked by '_undoRow/ColRemove' to prepare the newly inserted destination\n * segment to serve as the replacement for this removed segment. This moves handle\n * allocations from this segment to the replacement as well as maintains tracking\n * groups for the undo/redo stack.\n */\n public transferToReplacement(destination: PermutationSegment) {\n // When this segment was removed, it may have been split from a larger original\n // segment. In this case, it will have been added to an undo/redo tracking group\n // that associates all of the fragments from the original insertion.\n //\n // Move this association from the this removed segment to its replacement so that\n // it is included if the undo stack continues to unwind to the original insertion.\n //\n // Out of paranoia we link and unlink in separate loops to avoid mutating the underlying\n // set during enumeration. In pratice, this is unlikely to matter since there should be\n // exactly 0 or 1 items in the enumeration.\n for (const group of this.trackingCollection.trackingGroups) {\n group.link(destination);\n }\n for (const group of this.trackingCollection.trackingGroups) {\n group.unlink(this);\n }\n\n // Move handle allocations from this segment to its replacement.\n destination._start = this._start;\n this.reset();\n }\n\n public reset() {\n this._start = Handle.unallocated;\n }\n\n public toJSONObject() {\n return [this.cachedLength, this.start];\n }\n\n public clone(start = 0, end = this.cachedLength) {\n const b = new PermutationSegment(\n /* length: */ end - start,\n /* start: */ this.start + start);\n this.cloneInto(b);\n return b;\n }\n\n public canAppend(segment: ISegment) {\n const asPerm = segment as PermutationSegment;\n\n return this.start === Handle.unallocated\n ? asPerm.start === Handle.unallocated\n : asPerm.start === this.start + this.cachedLength;\n }\n\n public append(segment: ISegment) {\n // Note: Must call 'LocalReferenceCollection.append(..)' before modifying this segment's length as\n // 'this.cachedLength' is used to adjust the offsets of the local refs.\n LocalReferenceCollection.append(this, segment);\n\n this.cachedLength += segment.cachedLength;\n }\n\n protected createSplitSegmentAt(pos: number) {\n assert(0 < pos && pos < this.cachedLength, 0x026 /* \"Trying to split segment at out-of-bounds position!\" */);\n\n const leafSegment = new PermutationSegment(\n /* length: */ this.cachedLength - pos,\n /* start: */ this.start === Handle.unallocated\n ? Handle.unallocated\n : this.start + pos);\n\n this.cachedLength = pos;\n\n return leafSegment;\n }\n\n public toString() {\n return this.start === Handle.unallocated\n ? `<${this.cachedLength} empty>`\n : `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n }\n}\n\nexport class PermutationVector extends Client {\n private handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n public readonly handleCache = new HandleCache(this);\n public undo: VectorUndoProvider | undefined;\n\n constructor(\n path: string,\n logger: ITelemetryBaseLogger,\n runtime: IFluidDataStoreRuntime,\n private readonly deltaCallback: (position: number, numRemoved: number, numInserted: number) => void,\n private readonly handlesRecycledCallback: (handles: Handle[]) => void,\n ) {\n super(\n PermutationSegment.fromJSONObject,\n ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`), {\n ...runtime.options,\n newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n }); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n this.mergeTreeDeltaCallback = this.onDelta;\n this.mergeTreeMaintenanceCallback = this.onMaintenance;\n }\n\n public insert(start: number, length: number) {\n return this.insertSegmentLocal(\n start,\n new PermutationSegment(length));\n }\n\n public insertRelative(segment: ISegment, length: number) {\n const inserted = new PermutationSegment(length);\n\n return {\n op: this.insertAtReferencePositionLocal(\n new LocalReference(this, segment, /* offset: */ 0, ReferenceType.Transient),\n inserted),\n inserted,\n };\n }\n\n public remove(start: number, length: number) {\n return this.removeRangeLocal(start, start + length);\n }\n\n public getMaybeHandle(pos: number): Handle {\n assert(0 <= pos && pos < this.getLength(), 0x027 /* \"Trying to get handle of out-of-bounds position!\" */);\n\n return this.handleCache.getHandle(pos);\n }\n\n public getAllocatedHandle(pos: number): Handle {\n let handle = this.getMaybeHandle(pos);\n if (isHandleValid(handle)) {\n return handle;\n }\n\n this.walkSegments(\n (segment) => {\n const asPerm = segment as PermutationSegment;\n asPerm.start = handle = this.handleTable.allocate();\n return true;\n },\n pos,\n pos + 1,\n /* accum: */ undefined,\n /* splitRange: */ true);\n\n this.handleCache.addHandle(pos, handle);\n\n return handle;\n }\n\n public adjustPosition(pos: number, fromSeq: number, clientId: number) {\n const { segment, offset } = this.mergeTree.getContainingSegment(pos, fromSeq, clientId);\n\n // Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n // a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n // by checking for the presence of 'removedSeq'.\n if (segment === undefined || segment.removedSeq !== undefined) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.getPosition(segment) + offset!;\n }\n\n public handleToPosition(handle: Handle, localSeq = this.mergeTree.collabWindow.localSeq) {\n assert(localSeq <= this.mergeTree.collabWindow.localSeq,\n 0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */);\n\n // TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n // the original operation to the current position for resubmitting. This is probably the\n // ideal solution, as we would no longer need to store row/col handles in the op metadata.\n //\n // Failing that, we could avoid the O(n) search below by building a temporary map in the\n // opposite direction from the handle to either it's current position or segment + offset\n // and reuse it for the duration of resubmission. (Ideally, we would know when resubmission\n // ended so we could discard this map.)\n //\n // If we find that we frequently need a reverse handle -> position lookup, we could maintain\n // one using the Tiny-Calc adjust tree.\n let containingSegment!: PermutationSegment;\n let containingOffset: number;\n\n this.mergeTree.walkAllSegments(\n this.mergeTree.root,\n (segment) => {\n const { start, cachedLength } = segment as PermutationSegment;\n\n // If the segment is unallocated, skip it.\n if (!isHandleValid(start)) {\n return true;\n }\n\n const end = start + cachedLength;\n\n if (start <= handle && handle < end) {\n containingSegment = segment as PermutationSegment;\n containingOffset = handle - start;\n return false;\n }\n\n return true;\n });\n\n // We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n // row/col has been removed, because handles are not recycled until the containing segment\n // is unlinked from the MergeTree.\n //\n // Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n // ops that reference the stale handle, or the removal is unACKed, in which case the handle\n // has not yet been recycled.\n\n assert(isHandleValid(containingSegment.start), 0x029 /* \"Invalid handle at start of containing segment!\" */);\n\n // Once we know the current position of the handle, we can use the MergeTree to get the segment\n // containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n // have not yet been submitted.\n\n // eslint-disable-next-line max-len\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion\n return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset!;\n }\n\n // Constructs an ISummaryTreeWithStats for the cell data.\n public summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer):\n ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.segments, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */[]));\n builder.addBlob(SnapshotPath.handleTable, serializer.stringify(this.handleTable.getSummaryContent(), handle));\n return builder.getSummaryTree();\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n storage: IChannelStorageService,\n serializer: IFluidSerializer,\n ) {\n const handleTableData = await deserializeBlob(storage, SnapshotPath.handleTable, serializer);\n\n this.handleTable = HandleTable.load<never>(handleTableData);\n\n return super.load(runtime, new ObjectStoragePartition(storage, SnapshotPath.segments), serializer);\n }\n\n private readonly onDelta = (\n opArgs: IMergeTreeDeltaOpArgs,\n { operation, deltaSegments }: IMergeTreeDeltaCallbackArgs,\n ) => {\n // Apply deltas in descending order to prevent positions from shifting.\n const ranges = deltaSegments\n .map(({ segment }) => ({\n segment: segment as PermutationSegment,\n position: this.getPosition(segment),\n }))\n .sort((left, right) => left.position - right.position);\n\n const isLocal = opArgs.sequencedMessage === undefined;\n\n // Notify the undo provider, if any is attached.\n if (this.undo !== undefined && isLocal) {\n this.undo.record(operation, ranges);\n }\n\n switch (operation) {\n case MergeTreeDeltaType.INSERT:\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n // HACK: We need to include the allocated handle in the segment's JSON reperesntation\n // for snapshots, but need to ignore the remote client's handle allocations when\n // processing remote ops.\n segment.reset();\n\n this.handleCache.itemsChanged(\n position,\n /* deleteCount: */ 0,\n /* insertCount: */ segment.cachedLength);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ 0, /* numInserted: */ segment.cachedLength);\n }\n break;\n\n case MergeTreeDeltaType.REMOVE: {\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n this.handleCache.itemsChanged(\n position, /* deleteCount: */\n segment.cachedLength,\n /* insertCount: */ 0);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ segment.cachedLength, /* numInsert: */ 0);\n }\n break;\n }\n\n default:\n throw new Error(\"Unhandled MergeTreeDeltaType\");\n }\n };\n\n private readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n if (args.operation === MergeTreeMaintenanceType.UNLINK) {\n let freed: number[] = [];\n\n for (const { segment } of args.deltaSegments) {\n const asPerm = segment as PermutationSegment;\n if (isHandleValid(asPerm.start)) {\n // Note: Using the spread operator with `.splice()` can exhaust the stack.\n freed = freed.concat(\n new Array(asPerm.cachedLength)\n .fill(0)\n .map((value, index) => index + asPerm.start),\n );\n }\n }\n\n // Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n // the rows/cols prior to free to ensure recycled row/cols are initially empty.\n this.handlesRecycledCallback(freed);\n\n // Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n for (const handle of freed) {\n this.handleTable.free(handle);\n }\n }\n };\n\n public toString() {\n const s: string[] = [];\n\n this.walkSegments((segment) => {\n s.push(`${segment}`);\n return true;\n });\n\n return s.join(\"\");\n }\n}\n"]}
@@ -4,7 +4,8 @@
4
4
  */
5
5
  import { Serializable, IChannelStorageService } from "@fluidframework/datastore-definitions";
6
6
  import { BlobTreeEntry } from "@fluidframework/protocol-base";
7
- import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
7
+ import { IFluidHandle } from "@fluidframework/core-interfaces";
8
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
8
9
  export declare const serializeBlob: (handle: IFluidHandle, path: string, snapshot: Serializable, serializer: IFluidSerializer) => BlobTreeEntry;
9
10
  export declare function deserializeBlob(storage: IChannelStorageService, path: string, serializer: IFluidSerializer): Promise<any>;
10
11
  //# sourceMappingURL=serialization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGjF,eAAO,MAAM,aAAa,WACd,YAAY,QACd,MAAM,YACF,YAAY,cACV,gBAAgB,kBACoC,CAAC;AAErE,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,gBAKhH"}
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAGtE,eAAO,MAAM,aAAa,WACd,YAAY,QACd,MAAM,YACF,YAAY,cACV,gBAAgB,kBACoC,CAAC;AAErE,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,gBAKhH"}
@@ -1 +1 @@
1
- {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,CAAC,MAAM,aAAa,GAAG,CACzB,MAAoB,EACpB,IAAY,EACZ,QAAsB,EACtB,UAA4B,EAC9B,EAAE,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AAErE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA+B,EAAE,IAAY,EAAE,UAA4B;IAC7G,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,+DAA+D;IAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Serializable, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { BlobTreeEntry } from \"@fluidframework/protocol-base\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport { bufferToString } from \"@fluidframework/common-utils\";\n\nexport const serializeBlob = (\n handle: IFluidHandle,\n path: string,\n snapshot: Serializable,\n serializer: IFluidSerializer,\n) => new BlobTreeEntry(path, serializer.stringify(snapshot, handle));\n\nexport async function deserializeBlob(storage: IChannelStorageService, path: string, serializer: IFluidSerializer) {\n const blob = await storage.readBlob(path);\n const utf8 = bufferToString(blob, \"utf8\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(utf8);\n}\n"]}
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,CAAC,MAAM,aAAa,GAAG,CACzB,MAAoB,EACpB,IAAY,EACZ,QAAsB,EACtB,UAA4B,EAC9B,EAAE,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AAErE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA+B,EAAE,IAAY,EAAE,UAA4B;IAC7G,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,+DAA+D;IAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Serializable, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { BlobTreeEntry } from \"@fluidframework/protocol-base\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { bufferToString } from \"@fluidframework/common-utils\";\n\nexport const serializeBlob = (\n handle: IFluidHandle,\n path: string,\n snapshot: Serializable,\n serializer: IFluidSerializer,\n) => new BlobTreeEntry(path, serializer.stringify(snapshot, handle));\n\nexport async function deserializeBlob(storage: IChannelStorageService, path: string, serializer: IFluidSerializer) {\n const blob = await storage.readBlob(path);\n const utf8 = bufferToString(blob, \"utf8\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(utf8);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/matrix",
3
- "version": "0.54.3",
3
+ "version": "0.55.2",
4
4
  "description": "Distributed matrix",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": "https://github.com/microsoft/FluidFramework",
@@ -25,7 +25,7 @@
25
25
  "ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
26
26
  "clean": "rimraf dist lib bench/dist *.tsbuildinfo *.build.log",
27
27
  "eslint": "eslint --format stylish src",
28
- "eslint:fix": "eslint --format stylish src --fix",
28
+ "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
29
29
  "lint": "npm run eslint",
30
30
  "lint:fix": "npm run eslint:fix",
31
31
  "stress": "mocha --recursive dist/test/**/*.spec.js --exit -r node_modules/@fluidframework/mocha-test-setup --unhandled-rejections=strict --fgrep stress-loop",
@@ -57,39 +57,40 @@
57
57
  "@fluidframework/common-definitions": "^0.20.1",
58
58
  "@fluidframework/common-utils": "^0.32.1",
59
59
  "@fluidframework/core-interfaces": "^0.41.0",
60
- "@fluidframework/datastore-definitions": "^0.54.3",
61
- "@fluidframework/merge-tree": "^0.54.3",
60
+ "@fluidframework/datastore-definitions": "^0.55.2",
61
+ "@fluidframework/merge-tree": "^0.55.2",
62
62
  "@fluidframework/protocol-base": "^0.1034.0",
63
63
  "@fluidframework/protocol-definitions": "^0.1026.0",
64
- "@fluidframework/runtime-definitions": "^0.54.3",
65
- "@fluidframework/runtime-utils": "^0.54.3",
66
- "@fluidframework/shared-object-base": "^0.54.3",
67
- "@fluidframework/telemetry-utils": "^0.54.3",
64
+ "@fluidframework/runtime-definitions": "^0.55.2",
65
+ "@fluidframework/runtime-utils": "^0.55.2",
66
+ "@fluidframework/shared-object-base": "^0.55.2",
67
+ "@fluidframework/telemetry-utils": "^0.55.2",
68
68
  "@tiny-calc/nano": "0.0.0-alpha.5",
69
69
  "tslib": "^1.10.0"
70
70
  },
71
71
  "devDependencies": {
72
- "@fluid-internal/test-dds-utils": "^0.54.3",
72
+ "@fluid-internal/test-dds-utils": "^0.55.2",
73
73
  "@fluidframework/build-common": "^0.23.0",
74
- "@fluidframework/eslint-config-fluid": "^0.24.0",
75
- "@fluidframework/mocha-test-setup": "^0.54.3",
76
- "@fluidframework/test-runtime-utils": "^0.54.3",
74
+ "@fluidframework/eslint-config-fluid": "^0.25.0",
75
+ "@fluidframework/mocha-test-setup": "^0.55.2",
76
+ "@fluidframework/test-runtime-utils": "^0.55.2",
77
77
  "@microsoft/api-extractor": "^7.16.1",
78
+ "@rushstack/eslint-config": "^2.5.1",
78
79
  "@tiny-calc/micro": "0.0.0-alpha.5",
79
80
  "@types/mocha": "^8.2.2",
80
- "@typescript-eslint/eslint-plugin": "~4.14.0",
81
- "@typescript-eslint/parser": "~4.14.0",
81
+ "@typescript-eslint/eslint-plugin": "~5.9.0",
82
+ "@typescript-eslint/parser": "~5.9.0",
82
83
  "best-random": "^1.0.0",
83
84
  "concurrently": "^6.2.0",
84
85
  "copyfiles": "^2.1.0",
85
86
  "cross-env": "^7.0.2",
86
- "eslint": "~7.18.0",
87
+ "eslint": "~8.6.0",
88
+ "eslint-plugin-editorconfig": "~3.2.0",
87
89
  "eslint-plugin-eslint-comments": "~3.2.0",
88
- "eslint-plugin-import": "~2.22.1",
90
+ "eslint-plugin-import": "~2.25.4",
89
91
  "eslint-plugin-no-null": "~1.0.2",
90
- "eslint-plugin-prefer-arrow": "~1.2.2",
91
- "eslint-plugin-react": "~7.22.0",
92
- "eslint-plugin-unicorn": "~26.0.1",
92
+ "eslint-plugin-react": "~7.28.0",
93
+ "eslint-plugin-unicorn": "~40.0.0",
93
94
  "hotloop": "^1.2.0",
94
95
  "mocha": "^8.4.0",
95
96
  "nyc": "^15.0.0",
@@ -77,7 +77,7 @@ export class HandleTable<T> {
77
77
  private get next() { return this.handles[0] as Handle; }
78
78
  private set next(handle: Handle) { this.handles[0] = handle; }
79
79
 
80
- public snapshot() {
80
+ public getSummaryContent() {
81
81
  return this.handles;
82
82
  }
83
83
 
package/src/matrix.ts CHANGED
@@ -4,13 +4,7 @@
4
4
  */
5
5
 
6
6
  import { assert } from "@fluidframework/common-utils";
7
- import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
8
- import {
9
- FileMode,
10
- ISequencedDocumentMessage,
11
- ITree,
12
- TreeEntry,
13
- } from "@fluidframework/protocol-definitions";
7
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
14
8
  import {
15
9
  IFluidDataStoreRuntime,
16
10
  IChannelStorageService,
@@ -18,13 +12,14 @@ import {
18
12
  IChannelAttributes,
19
13
  } from "@fluidframework/datastore-definitions";
20
14
  import {
15
+ IFluidSerializer,
21
16
  makeHandlesSerializable,
22
17
  parseHandles,
23
18
  SharedObject,
24
19
  SummarySerializer,
25
20
  } from "@fluidframework/shared-object-base";
26
- import { IGarbageCollectionData } from "@fluidframework/runtime-definitions";
27
- import { ObjectStoragePartition } from "@fluidframework/runtime-utils";
21
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
22
+ import { ObjectStoragePartition, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
28
23
  import {
29
24
  IMatrixProducer,
30
25
  IMatrixConsumer,
@@ -37,7 +32,7 @@ import { PermutationVector, PermutationSegment } from "./permutationvector";
37
32
  import { SparseArray2D } from "./sparsearray2d";
38
33
  import { SharedMatrixFactory } from "./runtime";
39
34
  import { Handle, isHandleValid } from "./handletable";
40
- import { deserializeBlob, serializeBlob } from "./serialization";
35
+ import { deserializeBlob } from "./serialization";
41
36
  import { ensureRange } from "./range";
42
37
  import { IUndoConsumer } from "./types";
43
38
  import { MatrixUndoProvider } from "./undoprovider";
@@ -429,58 +424,28 @@ export class SharedMatrix<T = any>
429
424
  }
430
425
  }
431
426
 
432
- protected snapshotCore(serializer: IFluidSerializer): ITree {
433
- const tree: ITree = {
434
- entries: [
435
- {
436
- mode: FileMode.Directory,
437
- path: SnapshotPath.rows,
438
- type: TreeEntry.Tree,
439
- value: this.rows.snapshot(this.runtime, this.handle, serializer),
440
- },
441
- {
442
- mode: FileMode.Directory,
443
- path: SnapshotPath.cols,
444
- type: TreeEntry.Tree,
445
- value: this.cols.snapshot(this.runtime, this.handle, serializer),
446
- },
447
- serializeBlob(
448
- this.handle,
449
- SnapshotPath.cells,
450
- [
451
- this.cells.snapshot(),
452
- this.pending.snapshot(),
453
- ],
454
- serializer),
455
- ],
456
- };
457
-
458
- return tree;
427
+ protected summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats {
428
+ const builder = new SummaryTreeBuilder();
429
+ builder.addWithStats(SnapshotPath.rows, this.rows.summarize(this.runtime, this.handle, serializer));
430
+ builder.addWithStats(SnapshotPath.cols, this.cols.summarize(this.runtime, this.handle, serializer));
431
+ builder.addBlob(SnapshotPath.cells,
432
+ serializer.stringify([
433
+ this.cells.snapshot(),
434
+ this.pending.snapshot(),
435
+ ], this.handle));
436
+ return builder.getSummaryTree();
459
437
  }
460
438
 
461
439
  /**
462
- * Returns the GC data for this SharedMatrix. All the IFluidHandle's stored in the cells represent routes to other
463
- * objects.
440
+ * Runs serializer on the GC data for this SharedMatrix.
441
+ * All the IFluidHandle's stored in the cells represent routes to other objects.
464
442
  */
465
- protected getGCDataCore(): IGarbageCollectionData {
466
- // Create a SummarySerializer and use it to serialize all the cells. It keeps track of all IFluidHandles that it
467
- // serializes.
468
- const serializer = new SummarySerializer(
469
- this.runtime.channelsRoutingContext,
470
- (handle: IFluidHandle) => this.handleDecoded(handle),
471
- );
472
-
443
+ protected processGCDataCore(serializer: SummarySerializer) {
473
444
  for (let row = 0; row < this.rowCount; row++) {
474
445
  for (let col = 0; col < this.colCount; col++) {
475
446
  serializer.stringify(this.getCell(row, col), this.handle);
476
447
  }
477
448
  }
478
-
479
- return {
480
- gcNodes:{
481
- ["/"]: serializer.getSerializedRoutes(),
482
- },
483
- };
484
449
  }
485
450
 
486
451
  /**
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/matrix";
9
- export const pkgVersion = "0.54.3";
9
+ export const pkgVersion = "0.55.2";
@@ -20,11 +20,12 @@ import {
20
20
  LocalReference,
21
21
  ReferenceType,
22
22
  } from "@fluidframework/merge-tree";
23
- import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
24
- import { FileMode, TreeEntry, ITree } from "@fluidframework/protocol-definitions";
25
- import { ObjectStoragePartition } from "@fluidframework/runtime-utils";
23
+ import { IFluidHandle } from "@fluidframework/core-interfaces";
24
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
25
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
26
+ import { ObjectStoragePartition, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
26
27
  import { HandleTable, Handle, isHandleValid } from "./handletable";
27
- import { serializeBlob, deserializeBlob } from "./serialization";
28
+ import { deserializeBlob } from "./serialization";
28
29
  import { HandleCache } from "./handlecache";
29
30
  import { VectorUndoProvider } from "./undoprovider";
30
31
 
@@ -281,23 +282,18 @@ export class PermutationVector extends Client {
281
282
  // containing this position and use 'findReconnectionPosition' to adjust for the local ops that
282
283
  // have not yet been submitted.
283
284
 
284
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
285
+ // eslint-disable-next-line max-len
286
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
285
287
  return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset!;
286
288
  }
287
289
 
288
- // Constructs an ITreeEntry for the cell data.
289
- public snapshot(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer): ITree {
290
- return {
291
- entries: [
292
- {
293
- mode: FileMode.Directory,
294
- path: SnapshotPath.segments,
295
- type: TreeEntry.Tree,
296
- value: super.snapshot(runtime, handle, serializer, /* catchUpMsgs: */[]),
297
- },
298
- serializeBlob(handle, SnapshotPath.handleTable, this.handleTable.snapshot(), serializer),
299
- ],
300
- };
290
+ // Constructs an ISummaryTreeWithStats for the cell data.
291
+ public summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer):
292
+ ISummaryTreeWithStats {
293
+ const builder = new SummaryTreeBuilder();
294
+ builder.addWithStats(SnapshotPath.segments, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */[]));
295
+ builder.addBlob(SnapshotPath.handleTable, serializer.stringify(this.handleTable.getSummaryContent(), handle));
296
+ return builder.getSummaryTree();
301
297
  }
302
298
 
303
299
  public async load(
@@ -5,7 +5,8 @@
5
5
 
6
6
  import { Serializable, IChannelStorageService } from "@fluidframework/datastore-definitions";
7
7
  import { BlobTreeEntry } from "@fluidframework/protocol-base";
8
- import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
8
+ import { IFluidHandle } from "@fluidframework/core-interfaces";
9
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
9
10
  import { bufferToString } from "@fluidframework/common-utils";
10
11
 
11
12
  export const serializeBlob = (