@fluid-experimental/property-dds 0.47.0 → 0.48.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/dist/propertyTree.d.ts.map +1 -1
- package/dist/propertyTree.js +20 -16
- package/dist/propertyTree.js.map +1 -1
- package/lib/propertyTree.d.ts.map +1 -1
- package/lib/propertyTree.js +20 -16
- package/lib/propertyTree.js.map +1 -1
- package/package.json +13 -13
- package/src/propertyTree.ts +22 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyTree.d.ts","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"propertyTree.d.ts","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EACN,yBAAyB,EACzB,KAAK,EAKL,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAQnE,OAAO,EAAiC,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAMtG,oBAAY,mBAAmB,GAAG,GAAG,CAAC;AAEtC,oBAAY,QAAQ,GAAG,GAAG,CAAC;AAK3B,0BAAkB,MAAM;IAEvB,SAAS,IAAI;CACb;AAED,MAAM,WAAW,oBAAoB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,qBAAqB,CA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W,YAAY,IAAI,oBAAoB,CAMjD;IACD,IAAW,IAAI,IAAI,YAAY,CAE9B;IAEM,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,iBAAiB,CAAC,EAAE,OAAO;IAgB9D,OAAO,CAAC,cAAc;IA6BtB,gBAAgB,CAAC,IAAI,EAAE,OAAO;IAS9B;;;OAGG;IACI,0BAA0B;IAUjC;;;OAGG;IACI,yBAAyB;IAQhC;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;WAepF,KAAK,CAClB,qBAAqB,EAAE,MAAM,EAC7B,aAAa,EAAE,oBAAoB,EAAE,EACrC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC;;;;;IA+E5D,YAAY;IAYZ,YAAY,CAAC,UAAU,EAAE,gBAAgB,GAAG,KAAK;cAoExC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiHxE,SAAS,CAAC,YAAY;IACtB,SAAS,CAAC,YAAY;IAEtB,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,qBAAqB;IAsC7B,kBAAkB,CAAC,IAAI,EAAE,MAAM;IAI/B,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IASrD,OAAO,CAAC,kBAAkB;IA2E1B,SAAS,CAAC,cAAc;CAGxB"}
|
package/dist/propertyTree.js
CHANGED
|
@@ -8,13 +8,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SharedPropertyTree = void 0;
|
|
11
|
+
/* eslint-disable import/no-internal-modules */
|
|
12
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
13
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
14
|
+
const findIndex_1 = __importDefault(require("lodash/findIndex"));
|
|
15
|
+
const range_1 = __importDefault(require("lodash/range"));
|
|
11
16
|
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
12
17
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
13
18
|
const shared_object_base_1 = require("@fluidframework/shared-object-base");
|
|
14
19
|
const property_changeset_1 = require("@fluid-experimental/property-changeset");
|
|
15
20
|
const property_properties_1 = require("@fluid-experimental/property-properties");
|
|
16
21
|
const uuid_1 = require("uuid");
|
|
17
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
18
22
|
const axios_1 = __importDefault(require("axios"));
|
|
19
23
|
const propertyTreeFactory_1 = require("./propertyTreeFactory");
|
|
20
24
|
/**
|
|
@@ -84,7 +88,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
84
88
|
_reportDirtinessToView() {
|
|
85
89
|
const changes = this._root._serialize(true, false, property_properties_1.BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);
|
|
86
90
|
const _changeSet = new property_changeset_1.ChangeSet(changes);
|
|
87
|
-
if (!
|
|
91
|
+
if (!isEmpty_1.default(_changeSet.getSerializedChangeSet())) {
|
|
88
92
|
this.emit("localModification", _changeSet);
|
|
89
93
|
}
|
|
90
94
|
this._root.cleanDirty(property_properties_1.BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);
|
|
@@ -111,7 +115,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
111
115
|
if (submitEmptyChange === undefined) {
|
|
112
116
|
doSubmit = metadata !== undefined;
|
|
113
117
|
}
|
|
114
|
-
if (doSubmit || !
|
|
118
|
+
if (doSubmit || !isEmpty_1.default(changes)) {
|
|
115
119
|
this.applyChangeSet(changes, metadata || {});
|
|
116
120
|
this.root.cleanDirty();
|
|
117
121
|
}
|
|
@@ -135,7 +139,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
135
139
|
this._applyLocalChangeSet(change);
|
|
136
140
|
// Queue the op for transmission to the Fluid service.
|
|
137
141
|
if (this.transmissionsHaveBeenStopped) {
|
|
138
|
-
this.enqueuedMessages.push(
|
|
142
|
+
this.enqueuedMessages.push(cloneDeep_1.default(change));
|
|
139
143
|
}
|
|
140
144
|
else {
|
|
141
145
|
this.submitLocalMessage(change);
|
|
@@ -188,7 +192,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
188
192
|
case 0 /* ChangeSet */:
|
|
189
193
|
// If the op originated locally from this client, we've already accounted for it
|
|
190
194
|
// by advancing the state. Otherwise, advance the PRNG now.
|
|
191
|
-
this._applyRemoteChangeSet(
|
|
195
|
+
this._applyRemoteChangeSet(cloneDeep_1.default(content));
|
|
192
196
|
break;
|
|
193
197
|
default:
|
|
194
198
|
break;
|
|
@@ -336,10 +340,10 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
336
340
|
try {
|
|
337
341
|
if (!snapshot.useMH) {
|
|
338
342
|
// We load all chunks
|
|
339
|
-
const chunks = await Promise.all(
|
|
343
|
+
const chunks = await Promise.all(range_1.default(snapshot.numChunks).map(async (i) => {
|
|
340
344
|
return common_utils_1.bufferToString(await storage.readBlob(`summaryChunk_${i}`), "utf8");
|
|
341
345
|
}));
|
|
342
|
-
const serializedSummary =
|
|
346
|
+
const serializedSummary = chunks.reduce((a, b) => a + b, "");
|
|
343
347
|
const snapshotSummary = serializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);
|
|
344
348
|
if (snapshotSummary.remoteChanges === undefined ||
|
|
345
349
|
snapshotSummary.remoteTipView === undefined ||
|
|
@@ -353,7 +357,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
353
357
|
if (isPartialCheckoutActive && this.options.paths) {
|
|
354
358
|
this.remoteTipView = property_changeset_1.Utils.getFilteredChangeSetByPaths(this.remoteTipView, this.options.paths);
|
|
355
359
|
}
|
|
356
|
-
this.tipView =
|
|
360
|
+
this.tipView = cloneDeep_1.default(this.remoteTipView);
|
|
357
361
|
this.skipSequenceNumber = 0;
|
|
358
362
|
}
|
|
359
363
|
else {
|
|
@@ -367,7 +371,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
367
371
|
materializedView = property_changeset_1.Utils.getFilteredChangeSetByPaths(materializedView, this.options.paths);
|
|
368
372
|
}
|
|
369
373
|
this.tipView = materializedView;
|
|
370
|
-
this.remoteTipView =
|
|
374
|
+
this.remoteTipView = cloneDeep_1.default(this.tipView);
|
|
371
375
|
this.remoteChanges = [];
|
|
372
376
|
let missingDeltas = [];
|
|
373
377
|
const firstDelta = Math.min(commitMetadata.minimumSequenceNumber, summaryMinimumSequenceNumber);
|
|
@@ -414,7 +418,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
414
418
|
this.localChanges.push(change);
|
|
415
419
|
}
|
|
416
420
|
_applyRemoteChangeSet(change) {
|
|
417
|
-
this.unrebasedRemoteChanges[change.guid] =
|
|
421
|
+
this.unrebasedRemoteChanges[change.guid] = cloneDeep_1.default(change);
|
|
418
422
|
// This is the first message in the history of the document.
|
|
419
423
|
if (this.remoteChanges.length !== 0) {
|
|
420
424
|
property_changeset_1.rebaseToRemoteChanges(change, this.getUnrebasedChange.bind(this), this.getRebasedChanges.bind(this));
|
|
@@ -443,15 +447,15 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
443
447
|
return this.unrebasedRemoteChanges[guid];
|
|
444
448
|
}
|
|
445
449
|
getRebasedChanges(startGuid, endGuid) {
|
|
446
|
-
const startIndex =
|
|
447
|
-
if (endGuid) {
|
|
448
|
-
const endIndex =
|
|
450
|
+
const startIndex = findIndex_1.default(this.remoteChanges, (c) => c.guid === startGuid);
|
|
451
|
+
if (endGuid !== undefined) {
|
|
452
|
+
const endIndex = findIndex_1.default(this.remoteChanges, (c) => c.guid === endGuid);
|
|
449
453
|
return this.remoteChanges.slice(startIndex + 1, endIndex + 1);
|
|
450
454
|
}
|
|
451
455
|
return this.remoteChanges.slice(startIndex + 1);
|
|
452
456
|
}
|
|
453
457
|
rebaseLocalChanges(change, pendingChanges, newTipDelta) {
|
|
454
|
-
let rebaseBaseChangeSet =
|
|
458
|
+
let rebaseBaseChangeSet = cloneDeep_1.default(change.changeSet);
|
|
455
459
|
const accumulatedChanges = {};
|
|
456
460
|
const conflicts = [];
|
|
457
461
|
if (this.localChanges.length > 0 && this.localChanges[0].guid === change.guid) {
|
|
@@ -469,7 +473,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
469
473
|
// Make sure we never receive changes out of order
|
|
470
474
|
console.assert(this.localChanges[i].guid !== change.guid);
|
|
471
475
|
const rebaseMetaInformation = new Map();
|
|
472
|
-
const copiedChangeSet = new property_changeset_1.ChangeSet(
|
|
476
|
+
const copiedChangeSet = new property_changeset_1.ChangeSet(cloneDeep_1.default(this.localChanges[i].changeSet));
|
|
473
477
|
new property_changeset_1.ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {
|
|
474
478
|
applyAfterMetaInformation: rebaseMetaInformation,
|
|
475
479
|
});
|
|
@@ -498,7 +502,7 @@ class SharedPropertyTree extends shared_object_base_1.SharedObject {
|
|
|
498
502
|
});
|
|
499
503
|
// Update the tip view
|
|
500
504
|
if (!this.tipView) {
|
|
501
|
-
this.tipView =
|
|
505
|
+
this.tipView = cloneDeep_1.default(this.remoteTipView);
|
|
502
506
|
const changeSet = new property_changeset_1.ChangeSet(this.tipView);
|
|
503
507
|
changeSet.applyChangeSet(accumulatedChanges);
|
|
504
508
|
}
|
package/dist/propertyTree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyTree.js","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+EAO8C;AAQ9C,+DAAsE;AACtE,2EAAkE;AAGlE,+EAIgD;AAEhD,iF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,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;SAC3D;QAEP,OAAO,IAAI,CAAC;IACb,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AA/lBD,gDA+lBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISequencedDocumentMessage,\n\tITree,\n\tMessageType,\n\tFileMode,\n\tTreeEntry,\n\tITreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\n\nimport { bufferToString, assert } from \"@fluidframework/common-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\n\nimport {\n\tChangeSet,\n\tUtils as ChangeSetUtils,\n rebaseToRemoteChanges,\n} from \"@fluid-experimental/property-changeset\";\n\nimport { PropertyFactory, BaseProperty, NodeProperty } from \"@fluid-experimental/property-properties\";\n\nimport { v4 as uuidv4 } from \"uuid\";\nimport _ from \"lodash\";\nimport axios from \"axios\";\nimport { PropertyTreeFactory } from \"./propertyTreeFactory\";\n\nexport type SerializedChangeSet = any;\n\nexport type Metadata = any;\n\ntype FetchUnrebasedChangeFn = (guid: string) => IRemotePropertyTreeMessage;\ntype FetchRebasedChangesFn = (startGuid: string, endGuid?: string) => IPropertyTreeMessage[];\n\nexport const enum OpKind {\n\t// eslint-disable-next-line @typescript-eslint/no-shadow\n\tChangeSet = 0,\n}\n\nexport interface IPropertyTreeMessage {\n\top: OpKind;\n\tchangeSet: SerializedChangeSet;\n\tmetadata: Metadata;\n\tguid: string;\n\treferenceGuid: string;\n\tremoteHeadGuid: string;\n\tlocalBranchStart: string | undefined;\n\trebaseMetaInformation?: Map<any, any>;\n\tuseMH?: boolean;\n}\n\nexport interface IRemotePropertyTreeMessage extends IPropertyTreeMessage {\n\tsequenceNumber: number;\n}\ninterface ISnapshot {\n\tbranchGuid: string;\n\tsummaryMinimumSequenceNumber: number;\n\tuseMH: boolean;\n\tnumChunks: number;\n}\ninterface ISnapshotSummary {\n\tremoteTipView?: SerializedChangeSet;\n\tremoteChanges?: IPropertyTreeMessage[];\n\tunrebasedRemoteChanges?: Record<string, IRemotePropertyTreeMessage>;\n}\n\nexport interface SharedPropertyTreeOptions {\n\tpaths?: string[];\n\tclientFiltering?: boolean;\n\tuseMH?: boolean;\n}\n\n/**\n * Silly DDS example that models a six sided die.\n *\n * Unlike the typical 'Dice Roller' example where clients clobber each other's last roll in a\n * SharedMap, this 'SharedDie' DDS works by advancing an internal PRNG each time it sees a 'roll'\n * operation.\n *\n * Because all clients are using the same PRNG starting in the same state, they arrive at\n * consensus by simply applying the same number of rolls. (A fun addition would be logging\n * who received which roll, which would need to change as clients learn how races are resolved\n * in the total order)\n */\nexport class SharedPropertyTree extends SharedObject {\n\ttipView: SerializedChangeSet = {};\n\tremoteTipView: SerializedChangeSet = {};\n\tlocalChanges: IPropertyTreeMessage[] = [];\n\tremoteChanges: IPropertyTreeMessage[] = [];\n\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\ttransmissionsHaveBeenStopped = false;\n\tenqueuedMessages: IPropertyTreeMessage[] = [];\n\tnotificationDelayScope: number = 0;\n\t_root: any = PropertyFactory.create(\"NodeProperty\");\n\toptions: SharedPropertyTreeOptions;\n\tskipSequenceNumber: number = -1;\n\theadCommitGuid: string = \"\";\n\tuseMH: boolean = false;\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\toptions: SharedPropertyTreeOptions,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis.options = options;\n\t\t// Quick hack to let the root be aware of the DDS hosting it.\n\t\tthis._root._tree = this;\n\n\t\t// By default, we currently don't use the MH\n\t\tthis.useMH = options.useMH ?? false;\n\t}\n\n\t/**\n\t * Create a new shared cell\n\t *\n\t * @param runtime - data store runtime the new shared map belongs to\n\t * @param id - optional name of the shared map\n\t * @returns newly create shared map (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string, queryString?: string) {\n\t\treturn runtime.createChannel(id, PropertyTreeFactory.Type) as SharedPropertyTree;\n\t}\n\n\t/**\n\t * Get a factory for SharedDie to register with the data store.\n\t *\n\t * @returns a factory that creates and load SharedDie\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PropertyTreeFactory();\n\t}\n\n\t/**\n\t * in case of partial checkout we want to send the paths we are interested in once we are connected\n\t */\n\tprotected onConnect() {\n\t\t// on connect we scope all deltas such that we only get relevant changes\n\t\t// since we know the paths already at constuction time this is okay\n\t\tthis.scopeFutureDeltasToPaths(this.options.paths);\n\t}\n\n\tprivate scopeFutureDeltasToPaths(paths?: string[]) {\n\t\tconst socket = (this.runtime.deltaManager as any).deltaManager.connection.socket;\n\t\tsocket.emit(\"partial_checkout\", { paths });\n\t}\n\n\tpublic _reportDirtinessToView() {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t\tconst _changeSet = new ChangeSet(changes);\n\t\tif (!_.isEmpty(_changeSet.getSerializedChangeSet())) {\n\t\t\tthis.emit(\"localModification\", _changeSet);\n\t\t}\n\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t}\n\n\tpublic get changeSet(): SerializedChangeSet {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.tipView;\n\t}\n\n public get activeCommit(): IPropertyTreeMessage {\n if(this.localChanges.length > 0) {\n return this.localChanges[this.localChanges.length - 1];\n } else {\n return this.remoteChanges[this.remoteChanges.length - 1];\n }\n\t}\n\tpublic get root(): NodeProperty {\n\t\treturn this._root as NodeProperty;\n\t}\n\n\tpublic commit(metadata?: Metadata, submitEmptyChange?: boolean) {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\n let doSubmit = !!submitEmptyChange;\n\n // if no override provided dont submit unless metadata are provided\n if (submitEmptyChange === undefined) {\n doSubmit = metadata !== undefined;\n }\n\n if (doSubmit || !_.isEmpty(changes)) {\n this.applyChangeSet(changes, metadata || {});\n this.root.cleanDirty();\n }\n\t}\n\n\tprivate applyChangeSet(changeSet: SerializedChangeSet, metadata: Metadata) {\n\t\tconst _changeSet = new ChangeSet(changeSet);\n\t\t_changeSet._toReversibleChangeSet(this.tipView);\n\n\t\tconst remoteHeadGuid =\n\t\t\tthis.remoteChanges.length > 0\n\t\t\t\t? this.remoteChanges[this.remoteChanges.length - 1].guid\n\t\t\t\t: this.headCommitGuid;\n\t\tconst change = {\n\t\t\top: OpKind.ChangeSet,\n\t\t\tchangeSet,\n\t\t\tmetadata,\n\t\t\tguid: uuidv4(),\n\t\t\tremoteHeadGuid,\n\t\t\treferenceGuid:\n\t\t\t\tthis.localChanges.length > 0 ? this.localChanges[this.localChanges.length - 1].guid : remoteHeadGuid,\n\t\t\tlocalBranchStart: this.localChanges.length > 0 ? this.localChanges[0].guid : undefined,\n\t\t\tuseMH: this.useMH,\n\t\t};\n\t\tthis._applyLocalChangeSet(change);\n\n\t\t// Queue the op for transmission to the Fluid service.\n\t\tif (this.transmissionsHaveBeenStopped) {\n\t\t\tthis.enqueuedMessages.push(_.cloneDeep(change));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(change);\n\t\t}\n\t}\n\n\tstopTransmission(stop: boolean) {\n\t\tthis.transmissionsHaveBeenStopped = stop;\n\t\tif (stop === false) {\n\t\t\tfor (const message of this.enqueuedMessages) {\n\t\t\t\tthis.submitLocalMessage(message);\n\t\t\t}\n\t\t\tthis.enqueuedMessages = [];\n\t\t}\n\t}\n\t/**\n\t * Delays notifications until popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic pushNotificationDelayScope() {\n\t\t// set the scope counter\n\t\tthis.notificationDelayScope++;\n\n\t\t// If we reach 0, we have to report unreported changes\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tthis._root._reportDirtinessToView();\n\t\t}\n\t}\n\n\t/**\n\t * Re-enables notifications when popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic popNotificationDelayScope() {\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tconsole.error(\"Unbalanced push/pop calls.\");\n\t\t}\n\t\tthis.notificationDelayScope--;\n\t\tthis._root._reportDirtinessToView();\n\t}\n\n\t/**\n\t * Process an operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tif (message.type === MessageType.Operation && message.sequenceNumber > this.skipSequenceNumber) {\n\t\t\tconst content: IRemotePropertyTreeMessage = { ...message.contents, sequenceNumber: message.sequenceNumber };\n\t\t\tswitch (content.op) {\n\t\t\t\tcase OpKind.ChangeSet:\n\t\t\t\t\t// If the op originated locally from this client, we've already accounted for it\n\t\t\t\t\t// by advancing the state. Otherwise, advance the PRNG now.\n\t\t\t\t\tthis._applyRemoteChangeSet(_.cloneDeep(content));\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static prune(\n\t\tminimumSequenceNumber: number,\n\t\tremoteChanges: IPropertyTreeMessage[],\n\t\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage>,\n\t) {\n\t\t// for faster lookup of remote change guids\n\t\tconst remoteChangeMap = new Map<string, number>();\n\t\tremoteChanges.forEach((change, index) => {\n\t\t\tremoteChangeMap.set(change.guid, index);\n\t\t});\n\n\t\t// we will track visited nodes\n\t\tconst visitedUnrebasedRemoteChanges = new Set<string>();\n\t\tconst visitedRemoteChanges = new Set<string>();\n\n\t\tfor (const id of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tconst unrebasedChange = unrebasedRemoteChanges[id];\n\n\t\t\t// we are only interested in changes that are newer than the sequence number\n\t\t\t// and that were not yet visited previously\n\t\t\tif (\n\t\t\t\tunrebasedChange.sequenceNumber >= minimumSequenceNumber &&\n\t\t\t\t!visitedUnrebasedRemoteChanges.has(unrebasedChange.guid)\n\t\t\t) {\n\t\t\t\t// we visited that unrebased change and mark it as visited\n\t\t\t\tvisitedUnrebasedRemoteChanges.add(unrebasedChange.guid);\n\n\t\t\t\tlet visitor = unrebasedChange;\n\t\t\t\t// we will walk along the commit chain until we hit a remote change or a visited unrebased commit\n\t\t\t\t// at that point we can skip since we already traced the rest of the commit chain\n\t\t\t\twhile (\n\t\t\t\t\tvisitor.remoteHeadGuid !== visitor.referenceGuid ||\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.has(visitor.referenceGuid)\n\t\t\t\t) {\n\t\t\t\t\tconst guid = visitor.referenceGuid;\n\t\t\t\t\tif (guid === \"\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// since the change is not in remote it must be in unrebased\n\t\t\t\t\tvisitor = unrebasedRemoteChanges[visitor.referenceGuid];\n\t\t\t\t\tif (!visitor) {\n\t\t\t\t\t\tthrow new Error(`no visitor found for guid \"${guid}\"`);\n\t\t\t\t\t}\n\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.add(visitor.guid);\n\t\t\t\t}\n\t\t\t\t// if we exited the loop because we hit a remote change than add it as visited\n\t\t\t\tif (visitor.remoteHeadGuid === visitor.referenceGuid && remoteChangeMap.has(visitor.referenceGuid)) {\n\t\t\t\t\tvisitedRemoteChanges.add(visitor.referenceGuid);\n\t\t\t\t}\n\n // If we have a change that refers to the start of the history (remoteHeadGuid === \"\"), we have to\n // keep all remote Changes until this change has been processed\n if (visitor.remoteHeadGuid === \"\") {\n visitedRemoteChanges.add(remoteChanges[0].guid);\n }\n\t\t\t}\n\t\t}\n\t\tlet pruned = 0;\n\t\t// we can now filter the unrebased changes by removing any changes\n\t\t// we have not visited at all during our traversal\n\t\tconst prunedUnrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\t\tfor (const key of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tif (visitedUnrebasedRemoteChanges.has(key)) {\n\t\t\t\tprunedUnrebasedRemoteChanges[key] = unrebasedRemoteChanges[key];\n\t\t\t} else {\n\t\t\t\tpruned++;\n\t\t\t}\n\t\t}\n\n\t\t// find minimum index\n\t\tconst minIndex = Math.min(...[...visitedRemoteChanges].map((key) => remoteChangeMap.get(key) as number));\n\n\t\tconst prunedRemoteChanges = remoteChanges.slice(minIndex);\n\t\tpruned += minIndex;\n\n\t\treturn {\n\t\t\tremoteChanges: prunedRemoteChanges,\n\t\t\tunrebasedRemoteChanges: prunedUnrebasedRemoteChanges,\n\t\t\tprunedCount: pruned,\n\t\t};\n\t}\n\tpublic pruneHistory() {\n\t\tconst msn = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tconst { remoteChanges, unrebasedRemoteChanges } = SharedPropertyTree.prune(\n\t\t\tmsn,\n\t\t\tthis.remoteChanges,\n\t\t\tthis.unrebasedRemoteChanges,\n\t\t);\n\n\t\tthis.remoteChanges = remoteChanges;\n\t\tthis.unrebasedRemoteChanges = unrebasedRemoteChanges;\n\t}\n\tpublic snapshotCore(serializer: IFluidSerializer): ITree {\n\t\tthis.pruneHistory();\n\t\tconst snapshot: ISnapshot = {\n\t\t\tbranchGuid: this.handle.absolutePath.split(\"/\").pop() as string,\n\t\t\tsummaryMinimumSequenceNumber: this.runtime.deltaManager.minimumSequenceNumber,\n\t\t\tuseMH: this.useMH,\n\t\t\tnumChunks: 0,\n\t\t};\n\n\t\tconst chunks: ITreeEntry[] = [];\n\t\tif (!this.useMH) {\n\t\t\t// If the MH is not used, we have to include the tip view, the remote changes and the received\n\t\t\t// deltas to the summary\n\t\t\tconst summary: ISnapshotSummary = {\n\t\t\t\tremoteTipView: this.remoteTipView,\n\t\t\t\tremoteChanges: this.remoteChanges,\n\t\t\t\tunrebasedRemoteChanges: this.unrebasedRemoteChanges,\n\t\t\t};\n\t\t\tconst chunkSize = 5000 * 1024; // Default limit seems to be 5MB\n\t\t\tlet serializedSummary =\n\t\t\t\tserializer !== undefined ? serializer.stringify(summary, this.handle) : JSON.stringify(summary);\n\n\t\t\t// JSON.stringify does not escape unicode characters. As a consequence,\n\t\t\t// the chunking code below could create chunks which are bigger than the\n\t\t\t// allowed limit after encoding the JSON via UTF8 encoding. To make sure\n\t\t\t// the encoded string stays within the size limit, we replace unicode characters\n\t\t\t// with the cooresponding escapes. This way, it won't change size when encoded as\n\t\t\t// utf8\n\t\t\tserializedSummary = serializedSummary.replace(\n\t\t\t\t/[\\u007F-\\uFFFF]/g,\n\t\t\t\t// eslint-disable-next-line prefer-template\n\t\t\t\t(c) => `\\\\u${(\"0000\" + c.charCodeAt(0).toString(16)).substr(-4)}`,\n\t\t\t);\n\n\t\t\tfor (let pos = 0, i = 0; pos < serializedSummary.length; pos += chunkSize, i++) {\n\t\t\t\tchunks.push({\n\t\t\t\t\tpath: `summaryChunk_${i}`,\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents: serializedSummary.substr(pos, chunkSize),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tsnapshot.numChunks = chunks.length;\n\t\t}\n\n\t\treturn {\n\t\t\tentries: [\n\t\t\t\t{\n\t\t\t\t\tpath: \"properties\",\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents:\n\t\t\t\t\t\t\tserializer !== undefined\n\t\t\t\t\t\t\t\t? serializer.stringify(snapshot, this.handle)\n\t\t\t\t\t\t\t\t: JSON.stringify(snapshot),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...chunks,\n\t\t\t],\n\t\t\tid: undefined,\n\t\t};\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst runtime = this.runtime;\n\t\tconst handleTableChunk = await storage.readBlob(\"properties\");\n\t\tconst utf8 = bufferToString(handleTableChunk, \"utf8\");\n\n\t\tconst serializer = runtime.IFluidSerializer;\n\t\tconst snapshot: ISnapshot = serializer !== undefined ? serializer.parse(utf8) : JSON.parse(utf8);\n\t\tthis.useMH = snapshot.useMH;\n\n\t\ttry {\n\t\t\tif (!snapshot.useMH) {\n\t\t\t\t// We load all chunks\n\t\t\t\tconst chunks = await Promise.all(\n\t\t\t\t\t_.range(snapshot.numChunks).map(async (i) => {\n\t\t\t\t\t\treturn bufferToString(await storage.readBlob(`summaryChunk_${i}`), \"utf8\");\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst serializedSummary = _.reduce(chunks, (a, b) => a + b, \"\");\n\t\t\t\tconst snapshotSummary: ISnapshotSummary =\n\t\t\t\t\tserializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);\n\t\t\t\tif (\n\t\t\t\t\tsnapshotSummary.remoteChanges === undefined ||\n\t\t\t\t\tsnapshotSummary.remoteTipView === undefined ||\n\t\t\t\t\tsnapshotSummary.unrebasedRemoteChanges === undefined\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\"Invalid Snapshot.\");\n\t\t\t\t}\n\n\t\t\t\tthis.remoteTipView = snapshotSummary.remoteTipView;\n\t\t\t\tthis.remoteChanges = snapshotSummary.remoteChanges;\n\t\t\t\tthis.unrebasedRemoteChanges = snapshotSummary.unrebasedRemoteChanges;\n\n\t\t\t\tconst isPartialCheckoutActive = !!(this.options.clientFiltering && this.options.paths);\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tthis.remoteTipView = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\tthis.remoteTipView,\n\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.tipView = _.cloneDeep(this.remoteTipView);\n\n\t\t\t\tthis.skipSequenceNumber = 0;\n\t\t\t} else {\n\t\t\t\tconst { branchGuid, summaryMinimumSequenceNumber } = snapshot;\n\t\t\t\tconst branchResponse = await axios.get(`http://localhost:3000/branch/${branchGuid}`);\n\t\t\t\tthis.headCommitGuid = branchResponse.data.headCommitGuid;\n\t\t\t\tconst {\n\t\t\t\t\tcommit: { meta: commitMetadata },\n\t\t\t\t} = (await axios.get(`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}`)).data;\n\t\t\t\tlet { changeSet: materializedView } = (\n\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}/materializedView`,\n\t\t\t\t\t)\n\t\t\t\t).data;\n\n\t\t\t\tconst isPartialCheckoutActive = this.options.clientFiltering && this.options.paths;\n\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tmaterializedView = ChangeSetUtils.getFilteredChangeSetByPaths(materializedView, this.options.paths);\n\t\t\t\t}\n\n\t\t\t\tthis.tipView = materializedView;\n\t\t\t\tthis.remoteTipView = _.cloneDeep(this.tipView);\n\t\t\t\tthis.remoteChanges = [];\n\n\t\t\t\tlet missingDeltas: ISequencedDocumentMessage[] = [];\n\t\t\t\tconst firstDelta = Math.min(commitMetadata.minimumSequenceNumber, summaryMinimumSequenceNumber);\n\t\t\t\tconst lastDelta = commitMetadata.sequenceNumber;\n\n\t\t\t\tconst dm = (this.runtime.deltaManager as any).deltaManager;\n\t\t\t\tawait dm.getDeltas(\"DocumentOpen\", firstDelta, lastDelta, (messages: ISequencedDocumentMessage[]) => {\n\t\t\t\t\tmissingDeltas = messages.filter((x) => x.type === \"op\");\n\t\t\t\t});\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\t\t\tfor (let i = 0; i < missingDeltas.length; i++) {\n\t\t\t\t\tif (missingDeltas[i].sequenceNumber < commitMetadata.sequenceNumber) {\n\t\t\t\t\t\tconst remoteChange: IPropertyTreeMessage\n\t\t\t\t\t\t\t= JSON.parse(missingDeltas[i].contents).contents.contents.content.contents;\n\t\t\t\t\t\tconst { changeSet } = (\n\t\t\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${remoteChange.guid}/changeSet`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t).data;\n\t\t\t\t\t\tremoteChange.changeSet = changeSet;\n\n\t\t\t\t\t\tif (remoteChange) {\n\t\t\t\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\t\t\t\tremoteChange.changeSet = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\t\t\t\tremoteChange.changeSet,\n\t\t\t\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.remoteChanges.push(remoteChange);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.processCore(missingDeltas[i], false, {});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.skipSequenceNumber = lastDelta ?? -1;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.tipView = {};\n\t\t\tthis.remoteTipView = {};\n\t\t\tthis.remoteChanges = [];\n\t\t} finally {\n\t\t\tthis._root.deserialize(this.tipView);\n\t\t\tthis.root.cleanDirty();\n\t\t}\n\t}\n\n\tprotected registerCore() { }\n\tprotected onDisconnect() { }\n\n\tprivate _applyLocalChangeSet(change: IPropertyTreeMessage) {\n\t\tconst changeSetWrapper = new ChangeSet(this.tipView);\n\t\tchangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\tthis.localChanges.push(change);\n\t}\n\n\tprivate _applyRemoteChangeSet(change: IRemotePropertyTreeMessage) {\n\t\tthis.unrebasedRemoteChanges[change.guid] = _.cloneDeep(change);\n\n\t\t// This is the first message in the history of the document.\n\t\tif (this.remoteChanges.length !== 0) {\n\t\t\trebaseToRemoteChanges(\n\t\t\t\tchange,\n\t\t\t\tthis.getUnrebasedChange.bind(this),\n\t\t\t\tthis.getRebasedChanges.bind(this),\n\t\t\t);\n\t\t}\n\n\t\tthis.remoteChanges.push(change);\n\n\t\t// Apply the remote change set to the remote tip view\n\t\tconst remoteChangeSetWrapper = new ChangeSet(this.remoteTipView);\n\t\tremoteChangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\t// Rebase the local changes\n\t\tconst pendingChanges = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\tnew ChangeSet(pendingChanges)._toReversibleChangeSet(this.tipView);\n\n\t\tconst changesToTip: SerializedChangeSet = {};\n\t\tconst changesNeeded = this.rebaseLocalChanges(change, pendingChanges, changesToTip);\n\n\t\tif (changesNeeded) {\n\t\t\tthis.pushNotificationDelayScope();\n\t\t\t// Checkout the new tip\n\t\t\tthis._root.applyChangeSet(changesToTip);\n\t\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\t\tthis._root.applyChangeSet(pendingChanges);\n\t\t\tthis.popNotificationDelayScope();\n\t\t}\n\n\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t// assert(JSON.stringify(this.root.serialize()) === JSON.stringify(this.tipView));\n\t}\n\n\tgetUnrebasedChange(guid: string) {\n\t\treturn this.unrebasedRemoteChanges[guid];\n\t}\n\n\tgetRebasedChanges(startGuid: string, endGuid?: string) {\n\t\tconst startIndex = _.findIndex(this.remoteChanges, (c) => c.guid === startGuid);\n\t\tif (endGuid) {\n\t\t\tconst endIndex = _.findIndex(this.remoteChanges, (c) => c.guid === endGuid);\n\t\t\treturn this.remoteChanges.slice(startIndex + 1, endIndex + 1);\n\t\t}\n\t\treturn this.remoteChanges.slice(startIndex + 1);\n\t}\n\n\tprivate rebaseLocalChanges(\n\t\tchange: IPropertyTreeMessage,\n\t\tpendingChanges: SerializedChangeSet,\n\t\tnewTipDelta: SerializedChangeSet,\n\t): boolean {\n\t\tlet rebaseBaseChangeSet = _.cloneDeep(change.changeSet);\n\n\t\tconst accumulatedChanges: SerializedChangeSet = {};\n\t\tconst conflicts = [] as any[];\n\n\t\tif (this.localChanges.length > 0 && this.localChanges[0].guid === change.guid) {\n\t\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t\t// assert(JSON.stringify(this.localChanges[0].changeSet) === JSON.stringify(change.changeSet),\n\t\t\t// \"Local change different than rebased remote change.\");\n\n\t\t\t// If we got a confirmation of the commit on the tip of the localChanges array,\n\t\t\t// there will be no update of the tip view at all. We just move it from local changes\n\t\t\t// to remote changes\n\t\t\tthis.localChanges.shift();\n\n\t\t\treturn false;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\tfor (let i = 0; i < this.localChanges.length; i++) {\n\t\t\t// Make sure we never receive changes out of order\n\t\t\tconsole.assert(this.localChanges[i].guid !== change.guid);\n\n\t\t\tconst rebaseMetaInformation = new Map();\n\n\t\t\tconst copiedChangeSet = new ChangeSet(_.cloneDeep(this.localChanges[i].changeSet));\n\t\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\n\t\t\tcopiedChangeSet.toInverseChangeSet();\n\t\t\tcopiedChangeSet.applyChangeSet(rebaseBaseChangeSet);\n\t\t\tcopiedChangeSet.applyChangeSet(this.localChanges[i].changeSet, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\t\t\trebaseBaseChangeSet = copiedChangeSet.getSerializedChangeSet();\n\n\t\t\tnew ChangeSet(accumulatedChanges).applyChangeSet(this.localChanges[i].changeSet);\n\t\t}\n\n\t\t// Compute the inverse of the pending changes and store the result in newTipDelta\n\t\tconst pendingChangesRebaseMetaInformation = new Map();\n\t\tconst deltaToTipCS = new ChangeSet(newTipDelta);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges);\n\t\tdeltaToTipCS.toInverseChangeSet();\n\n\t\t// Perform a rebase of the pending changes\n\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(pendingChanges, conflicts, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Compute the delta between the old tip (including pending changes)\n\t\t// and the new tip (not including the rebased pending changes)\n\t\tdeltaToTipCS.applyChangeSet(rebaseBaseChangeSet);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Update the tip view\n\t\tif (!this.tipView) {\n this.tipView = _.cloneDeep(this.remoteTipView);\n const changeSet = new ChangeSet(this.tipView);\n changeSet.applyChangeSet(accumulatedChanges);\n } else {\n new ChangeSet(this.tipView).applyChangeSet(newTipDelta);\n }\n\n\t\treturn true;\n\t}\n\n\tprotected applyStashedOp() {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"propertyTree.js","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+CAA+C;AAC/C,6DAAqC;AACrC,iEAAyC;AACzC,iEAAyC;AACzC,yDAAiC;AAEjC,+EAO8C;AAQ9C,+DAAsE;AACtE,2EAAkE;AAGlE,+EAIgD;AAEhD,iFAAsG;AAEtG,+BAAoC;AACpC,kDAA0B;AAC1B,+DAA4D;AA+C5D;;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ights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable import/no-internal-modules */\nimport isEmpty from \"lodash/isEmpty\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport findIndex from \"lodash/findIndex\";\nimport range from \"lodash/range\";\n\nimport {\n\tISequencedDocumentMessage,\n\tITree,\n\tMessageType,\n\tFileMode,\n\tTreeEntry,\n\tITreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\n\nimport { bufferToString, assert } from \"@fluidframework/common-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\n\nimport {\n\tChangeSet,\n\tUtils as ChangeSetUtils,\n rebaseToRemoteChanges,\n} from \"@fluid-experimental/property-changeset\";\n\nimport { PropertyFactory, BaseProperty, NodeProperty } from \"@fluid-experimental/property-properties\";\n\nimport { v4 as uuidv4 } from \"uuid\";\nimport axios from \"axios\";\nimport { PropertyTreeFactory } from \"./propertyTreeFactory\";\n\nexport type SerializedChangeSet = any;\n\nexport type Metadata = any;\n\ntype FetchUnrebasedChangeFn = (guid: string) => IRemotePropertyTreeMessage;\ntype FetchRebasedChangesFn = (startGuid: string, endGuid?: string) => IPropertyTreeMessage[];\n\nexport const enum OpKind {\n\t// eslint-disable-next-line @typescript-eslint/no-shadow\n\tChangeSet = 0,\n}\n\nexport interface IPropertyTreeMessage {\n\top: OpKind;\n\tchangeSet: SerializedChangeSet;\n\tmetadata: Metadata;\n\tguid: string;\n\treferenceGuid: string;\n\tremoteHeadGuid: string;\n\tlocalBranchStart: string | undefined;\n\trebaseMetaInformation?: Map<any, any>;\n\tuseMH?: boolean;\n}\n\nexport interface IRemotePropertyTreeMessage extends IPropertyTreeMessage {\n\tsequenceNumber: number;\n}\ninterface ISnapshot {\n\tbranchGuid: string;\n\tsummaryMinimumSequenceNumber: number;\n\tuseMH: boolean;\n\tnumChunks: number;\n}\ninterface ISnapshotSummary {\n\tremoteTipView?: SerializedChangeSet;\n\tremoteChanges?: IPropertyTreeMessage[];\n\tunrebasedRemoteChanges?: Record<string, IRemotePropertyTreeMessage>;\n}\n\nexport interface SharedPropertyTreeOptions {\n\tpaths?: string[];\n\tclientFiltering?: boolean;\n\tuseMH?: boolean;\n}\n\n/**\n * Silly DDS example that models a six sided die.\n *\n * Unlike the typical 'Dice Roller' example where clients clobber each other's last roll in a\n * SharedMap, this 'SharedDie' DDS works by advancing an internal PRNG each time it sees a 'roll'\n * operation.\n *\n * Because all clients are using the same PRNG starting in the same state, they arrive at\n * consensus by simply applying the same number of rolls. (A fun addition would be logging\n * who received which roll, which would need to change as clients learn how races are resolved\n * in the total order)\n */\nexport class SharedPropertyTree extends SharedObject {\n\ttipView: SerializedChangeSet = {};\n\tremoteTipView: SerializedChangeSet = {};\n\tlocalChanges: IPropertyTreeMessage[] = [];\n\tremoteChanges: IPropertyTreeMessage[] = [];\n\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\ttransmissionsHaveBeenStopped = false;\n\tenqueuedMessages: IPropertyTreeMessage[] = [];\n\tnotificationDelayScope: number = 0;\n\t_root: any = PropertyFactory.create(\"NodeProperty\");\n\toptions: SharedPropertyTreeOptions;\n\tskipSequenceNumber: number = -1;\n\theadCommitGuid: string = \"\";\n\tuseMH: boolean = false;\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\toptions: SharedPropertyTreeOptions,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis.options = options;\n\t\t// Quick hack to let the root be aware of the DDS hosting it.\n\t\tthis._root._tree = this;\n\n\t\t// By default, we currently don't use the MH\n\t\tthis.useMH = options.useMH ?? false;\n\t}\n\n\t/**\n\t * Create a new shared cell\n\t *\n\t * @param runtime - data store runtime the new shared map belongs to\n\t * @param id - optional name of the shared map\n\t * @returns newly create shared map (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string, queryString?: string) {\n\t\treturn runtime.createChannel(id, PropertyTreeFactory.Type) as SharedPropertyTree;\n\t}\n\n\t/**\n\t * Get a factory for SharedDie to register with the data store.\n\t *\n\t * @returns a factory that creates and load SharedDie\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PropertyTreeFactory();\n\t}\n\n\t/**\n\t * in case of partial checkout we want to send the paths we are interested in once we are connected\n\t */\n\tprotected onConnect() {\n\t\t// on connect we scope all deltas such that we only get relevant changes\n\t\t// since we know the paths already at constuction time this is okay\n\t\tthis.scopeFutureDeltasToPaths(this.options.paths);\n\t}\n\n\tprivate scopeFutureDeltasToPaths(paths?: string[]) {\n\t\tconst socket = (this.runtime.deltaManager as any).deltaManager.connection.socket;\n\t\tsocket.emit(\"partial_checkout\", { paths });\n\t}\n\n\tpublic _reportDirtinessToView() {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t\tconst _changeSet = new ChangeSet(changes);\n\t\tif (!isEmpty(_changeSet.getSerializedChangeSet())) {\n\t\t\tthis.emit(\"localModification\", _changeSet);\n\t\t}\n\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t}\n\n\tpublic get changeSet(): SerializedChangeSet {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.tipView;\n\t}\n\n public get activeCommit(): IPropertyTreeMessage {\n if(this.localChanges.length > 0) {\n return this.localChanges[this.localChanges.length - 1];\n } else {\n return this.remoteChanges[this.remoteChanges.length - 1];\n }\n\t}\n\tpublic get root(): NodeProperty {\n\t\treturn this._root as NodeProperty;\n\t}\n\n\tpublic commit(metadata?: Metadata, submitEmptyChange?: boolean) {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\n let doSubmit = !!submitEmptyChange;\n\n // if no override provided dont submit unless metadata are provided\n if (submitEmptyChange === undefined) {\n doSubmit = metadata !== undefined;\n }\n\n if (doSubmit || !isEmpty(changes)) {\n this.applyChangeSet(changes, metadata || {});\n this.root.cleanDirty();\n }\n\t}\n\n\tprivate applyChangeSet(changeSet: SerializedChangeSet, metadata: Metadata) {\n\t\tconst _changeSet = new ChangeSet(changeSet);\n\t\t_changeSet._toReversibleChangeSet(this.tipView);\n\n\t\tconst remoteHeadGuid =\n\t\t\tthis.remoteChanges.length > 0\n\t\t\t\t? this.remoteChanges[this.remoteChanges.length - 1].guid\n\t\t\t\t: this.headCommitGuid;\n\t\tconst change = {\n\t\t\top: OpKind.ChangeSet,\n\t\t\tchangeSet,\n\t\t\tmetadata,\n\t\t\tguid: uuidv4(),\n\t\t\tremoteHeadGuid,\n\t\t\treferenceGuid:\n\t\t\t\tthis.localChanges.length > 0 ? this.localChanges[this.localChanges.length - 1].guid : remoteHeadGuid,\n\t\t\tlocalBranchStart: this.localChanges.length > 0 ? this.localChanges[0].guid : undefined,\n\t\t\tuseMH: this.useMH,\n\t\t};\n\t\tthis._applyLocalChangeSet(change);\n\n\t\t// Queue the op for transmission to the Fluid service.\n\t\tif (this.transmissionsHaveBeenStopped) {\n\t\t\tthis.enqueuedMessages.push(cloneDeep(change));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(change);\n\t\t}\n\t}\n\n\tstopTransmission(stop: boolean) {\n\t\tthis.transmissionsHaveBeenStopped = stop;\n\t\tif (stop === false) {\n\t\t\tfor (const message of this.enqueuedMessages) {\n\t\t\t\tthis.submitLocalMessage(message);\n\t\t\t}\n\t\t\tthis.enqueuedMessages = [];\n\t\t}\n\t}\n\t/**\n\t * Delays notifications until popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic pushNotificationDelayScope() {\n\t\t// set the scope counter\n\t\tthis.notificationDelayScope++;\n\n\t\t// If we reach 0, we have to report unreported changes\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tthis._root._reportDirtinessToView();\n\t\t}\n\t}\n\n\t/**\n\t * Re-enables notifications when popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic popNotificationDelayScope() {\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tconsole.error(\"Unbalanced push/pop calls.\");\n\t\t}\n\t\tthis.notificationDelayScope--;\n\t\tthis._root._reportDirtinessToView();\n\t}\n\n\t/**\n\t * Process an operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tif (message.type === MessageType.Operation && message.sequenceNumber > this.skipSequenceNumber) {\n\t\t\tconst content: IRemotePropertyTreeMessage = { ...message.contents, sequenceNumber: message.sequenceNumber };\n\t\t\tswitch (content.op) {\n\t\t\t\tcase OpKind.ChangeSet:\n\t\t\t\t\t// If the op originated locally from this client, we've already accounted for it\n\t\t\t\t\t// by advancing the state. Otherwise, advance the PRNG now.\n\t\t\t\t\tthis._applyRemoteChangeSet(cloneDeep(content));\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static prune(\n\t\tminimumSequenceNumber: number,\n\t\tremoteChanges: IPropertyTreeMessage[],\n\t\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage>,\n\t) {\n\t\t// for faster lookup of remote change guids\n\t\tconst remoteChangeMap = new Map<string, number>();\n\t\tremoteChanges.forEach((change, index) => {\n\t\t\tremoteChangeMap.set(change.guid, index);\n\t\t});\n\n\t\t// we will track visited nodes\n\t\tconst visitedUnrebasedRemoteChanges = new Set<string>();\n\t\tconst visitedRemoteChanges = new Set<string>();\n\n\t\tfor (const id of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tconst unrebasedChange = unrebasedRemoteChanges[id];\n\n\t\t\t// we are only interested in changes that are newer than the sequence number\n\t\t\t// and that were not yet visited previously\n\t\t\tif (\n\t\t\t\tunrebasedChange.sequenceNumber >= minimumSequenceNumber &&\n\t\t\t\t!visitedUnrebasedRemoteChanges.has(unrebasedChange.guid)\n\t\t\t) {\n\t\t\t\t// we visited that unrebased change and mark it as visited\n\t\t\t\tvisitedUnrebasedRemoteChanges.add(unrebasedChange.guid);\n\n\t\t\t\tlet visitor = unrebasedChange;\n\t\t\t\t// we will walk along the commit chain until we hit a remote change or a visited unrebased commit\n\t\t\t\t// at that point we can skip since we already traced the rest of the commit chain\n\t\t\t\twhile (\n\t\t\t\t\tvisitor.remoteHeadGuid !== visitor.referenceGuid ||\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.has(visitor.referenceGuid)\n\t\t\t\t) {\n\t\t\t\t\tconst guid = visitor.referenceGuid;\n\t\t\t\t\tif (guid === \"\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// since the change is not in remote it must be in unrebased\n\t\t\t\t\tvisitor = unrebasedRemoteChanges[visitor.referenceGuid];\n\t\t\t\t\tif (!visitor) {\n\t\t\t\t\t\tthrow new Error(`no visitor found for guid \"${guid}\"`);\n\t\t\t\t\t}\n\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.add(visitor.guid);\n\t\t\t\t}\n\t\t\t\t// if we exited the loop because we hit a remote change than add it as visited\n\t\t\t\tif (visitor.remoteHeadGuid === visitor.referenceGuid && remoteChangeMap.has(visitor.referenceGuid)) {\n\t\t\t\t\tvisitedRemoteChanges.add(visitor.referenceGuid);\n\t\t\t\t}\n\n // If we have a change that refers to the start of the history (remoteHeadGuid === \"\"), we have to\n // keep all remote Changes until this change has been processed\n if (visitor.remoteHeadGuid === \"\") {\n visitedRemoteChanges.add(remoteChanges[0].guid);\n }\n\t\t\t}\n\t\t}\n\t\tlet pruned = 0;\n\t\t// we can now filter the unrebased changes by removing any changes\n\t\t// we have not visited at all during our traversal\n\t\tconst prunedUnrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\t\tfor (const key of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tif (visitedUnrebasedRemoteChanges.has(key)) {\n\t\t\t\tprunedUnrebasedRemoteChanges[key] = unrebasedRemoteChanges[key];\n\t\t\t} else {\n\t\t\t\tpruned++;\n\t\t\t}\n\t\t}\n\n\t\t// find minimum index\n\t\tconst minIndex = Math.min(...[...visitedRemoteChanges].map((key) => remoteChangeMap.get(key) as number));\n\n\t\tconst prunedRemoteChanges = remoteChanges.slice(minIndex);\n\t\tpruned += minIndex;\n\n\t\treturn {\n\t\t\tremoteChanges: prunedRemoteChanges,\n\t\t\tunrebasedRemoteChanges: prunedUnrebasedRemoteChanges,\n\t\t\tprunedCount: pruned,\n\t\t};\n\t}\n\tpublic pruneHistory() {\n\t\tconst msn = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tconst { remoteChanges, unrebasedRemoteChanges } = SharedPropertyTree.prune(\n\t\t\tmsn,\n\t\t\tthis.remoteChanges,\n\t\t\tthis.unrebasedRemoteChanges,\n\t\t);\n\n\t\tthis.remoteChanges = remoteChanges;\n\t\tthis.unrebasedRemoteChanges = unrebasedRemoteChanges;\n\t}\n\tpublic snapshotCore(serializer: IFluidSerializer): ITree {\n\t\tthis.pruneHistory();\n\t\tconst snapshot: ISnapshot = {\n\t\t\tbranchGuid: this.handle.absolutePath.split(\"/\").pop() as string,\n\t\t\tsummaryMinimumSequenceNumber: this.runtime.deltaManager.minimumSequenceNumber,\n\t\t\tuseMH: this.useMH,\n\t\t\tnumChunks: 0,\n\t\t};\n\n\t\tconst chunks: ITreeEntry[] = [];\n\t\tif (!this.useMH) {\n\t\t\t// If the MH is not used, we have to include the tip view, the remote changes and the received\n\t\t\t// deltas to the summary\n\t\t\tconst summary: ISnapshotSummary = {\n\t\t\t\tremoteTipView: this.remoteTipView,\n\t\t\t\tremoteChanges: this.remoteChanges,\n\t\t\t\tunrebasedRemoteChanges: this.unrebasedRemoteChanges,\n\t\t\t};\n\t\t\tconst chunkSize = 5000 * 1024; // Default limit seems to be 5MB\n\t\t\tlet serializedSummary =\n\t\t\t\tserializer !== undefined ? serializer.stringify(summary, this.handle) : JSON.stringify(summary);\n\n\t\t\t// JSON.stringify does not escape unicode characters. As a consequence,\n\t\t\t// the chunking code below could create chunks which are bigger than the\n\t\t\t// allowed limit after encoding the JSON via UTF8 encoding. To make sure\n\t\t\t// the encoded string stays within the size limit, we replace unicode characters\n\t\t\t// with the cooresponding escapes. This way, it won't change size when encoded as\n\t\t\t// utf8\n\t\t\tserializedSummary = serializedSummary.replace(\n\t\t\t\t/[\\u007F-\\uFFFF]/g,\n\t\t\t\t// eslint-disable-next-line prefer-template\n\t\t\t\t(c) => `\\\\u${(\"0000\" + c.charCodeAt(0).toString(16)).substr(-4)}`,\n\t\t\t);\n\n\t\t\tfor (let pos = 0, i = 0; pos < serializedSummary.length; pos += chunkSize, i++) {\n\t\t\t\tchunks.push({\n\t\t\t\t\tpath: `summaryChunk_${i}`,\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents: serializedSummary.substr(pos, chunkSize),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tsnapshot.numChunks = chunks.length;\n\t\t}\n\n\t\treturn {\n\t\t\tentries: [\n\t\t\t\t{\n\t\t\t\t\tpath: \"properties\",\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents:\n\t\t\t\t\t\t\tserializer !== undefined\n\t\t\t\t\t\t\t\t? serializer.stringify(snapshot, this.handle)\n\t\t\t\t\t\t\t\t: JSON.stringify(snapshot),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...chunks,\n\t\t\t],\n\t\t\tid: undefined,\n\t\t};\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst runtime = this.runtime;\n\t\tconst handleTableChunk = await storage.readBlob(\"properties\");\n\t\tconst utf8 = bufferToString(handleTableChunk, \"utf8\");\n\n\t\tconst serializer = runtime.IFluidSerializer;\n\t\tconst snapshot: ISnapshot = serializer !== undefined ? serializer.parse(utf8) : JSON.parse(utf8);\n\t\tthis.useMH = snapshot.useMH;\n\n\t\ttry {\n\t\t\tif (!snapshot.useMH) {\n\t\t\t\t// We load all chunks\n\t\t\t\tconst chunks: string[] = await Promise.all(\n\t\t\t\t\trange(snapshot.numChunks).map(async (i) => {\n\t\t\t\t\t\treturn bufferToString(await storage.readBlob(`summaryChunk_${i}`), \"utf8\");\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst serializedSummary = chunks.reduce((a, b) => a + b, \"\");\n\t\t\t\tconst snapshotSummary: ISnapshotSummary =\n\t\t\t\t\tserializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);\n\t\t\t\tif (\n\t\t\t\t\tsnapshotSummary.remoteChanges === undefined ||\n\t\t\t\t\tsnapshotSummary.remoteTipView === undefined ||\n\t\t\t\t\tsnapshotSummary.unrebasedRemoteChanges === undefined\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\"Invalid Snapshot.\");\n\t\t\t\t}\n\n\t\t\t\tthis.remoteTipView = snapshotSummary.remoteTipView;\n\t\t\t\tthis.remoteChanges = snapshotSummary.remoteChanges;\n\t\t\t\tthis.unrebasedRemoteChanges = snapshotSummary.unrebasedRemoteChanges;\n\n\t\t\t\tconst isPartialCheckoutActive = !!(this.options.clientFiltering && this.options.paths);\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tthis.remoteTipView = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\tthis.remoteTipView,\n\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.tipView = cloneDeep(this.remoteTipView);\n\n\t\t\t\tthis.skipSequenceNumber = 0;\n\t\t\t} else {\n\t\t\t\tconst { branchGuid, summaryMinimumSequenceNumber } = snapshot;\n\t\t\t\tconst branchResponse = await axios.get(`http://localhost:3000/branch/${branchGuid}`);\n\t\t\t\tthis.headCommitGuid = branchResponse.data.headCommitGuid;\n\t\t\t\tconst {\n\t\t\t\t\tcommit: { meta: commitMetadata },\n\t\t\t\t} = (await axios.get(`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}`)).data;\n\t\t\t\tlet { changeSet: materializedView } = (\n\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}/materializedView`,\n\t\t\t\t\t)\n\t\t\t\t).data;\n\n\t\t\t\tconst isPartialCheckoutActive = this.options.clientFiltering && this.options.paths;\n\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tmaterializedView = ChangeSetUtils.getFilteredChangeSetByPaths(materializedView, this.options.paths);\n\t\t\t\t}\n\n\t\t\t\tthis.tipView = materializedView;\n\t\t\t\tthis.remoteTipView = cloneDeep(this.tipView);\n\t\t\t\tthis.remoteChanges = [];\n\n\t\t\t\tlet missingDeltas: ISequencedDocumentMessage[] = [];\n\t\t\t\tconst firstDelta = Math.min(commitMetadata.minimumSequenceNumber, summaryMinimumSequenceNumber);\n\t\t\t\tconst lastDelta = commitMetadata.sequenceNumber;\n\n\t\t\t\tconst dm = (this.runtime.deltaManager as any).deltaManager;\n\t\t\t\tawait dm.getDeltas(\"DocumentOpen\", firstDelta, lastDelta, (messages: ISequencedDocumentMessage[]) => {\n\t\t\t\t\tmissingDeltas = messages.filter((x) => x.type === \"op\");\n\t\t\t\t});\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\t\t\tfor (let i = 0; i < missingDeltas.length; i++) {\n\t\t\t\t\tif (missingDeltas[i].sequenceNumber < commitMetadata.sequenceNumber) {\n\t\t\t\t\t\tconst remoteChange: IPropertyTreeMessage\n\t\t\t\t\t\t\t= JSON.parse(missingDeltas[i].contents).contents.contents.content.contents;\n\t\t\t\t\t\tconst { changeSet } = (\n\t\t\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${remoteChange.guid}/changeSet`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t).data;\n\t\t\t\t\t\tremoteChange.changeSet = changeSet;\n\n\t\t\t\t\t\tif (remoteChange) {\n\t\t\t\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\t\t\t\tremoteChange.changeSet = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\t\t\t\tremoteChange.changeSet,\n\t\t\t\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.remoteChanges.push(remoteChange);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.processCore(missingDeltas[i], false, {});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.skipSequenceNumber = lastDelta ?? -1;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.tipView = {};\n\t\t\tthis.remoteTipView = {};\n\t\t\tthis.remoteChanges = [];\n\t\t} finally {\n\t\t\tthis._root.deserialize(this.tipView);\n\t\t\tthis.root.cleanDirty();\n\t\t}\n\t}\n\n\tprotected registerCore() { }\n\tprotected onDisconnect() { }\n\n\tprivate _applyLocalChangeSet(change: IPropertyTreeMessage) {\n\t\tconst changeSetWrapper = new ChangeSet(this.tipView);\n\t\tchangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\tthis.localChanges.push(change);\n\t}\n\n\tprivate _applyRemoteChangeSet(change: IRemotePropertyTreeMessage) {\n\t\tthis.unrebasedRemoteChanges[change.guid] = cloneDeep(change);\n\n\t\t// This is the first message in the history of the document.\n\t\tif (this.remoteChanges.length !== 0) {\n\t\t\trebaseToRemoteChanges(\n\t\t\t\tchange,\n\t\t\t\tthis.getUnrebasedChange.bind(this),\n\t\t\t\tthis.getRebasedChanges.bind(this),\n\t\t\t);\n\t\t}\n\n\t\tthis.remoteChanges.push(change);\n\n\t\t// Apply the remote change set to the remote tip view\n\t\tconst remoteChangeSetWrapper = new ChangeSet(this.remoteTipView);\n\t\tremoteChangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\t// Rebase the local changes\n\t\tconst pendingChanges = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\tnew ChangeSet(pendingChanges)._toReversibleChangeSet(this.tipView);\n\n\t\tconst changesToTip: SerializedChangeSet = {};\n\t\tconst changesNeeded = this.rebaseLocalChanges(change, pendingChanges, changesToTip);\n\n\t\tif (changesNeeded) {\n\t\t\tthis.pushNotificationDelayScope();\n\t\t\t// Checkout the new tip\n\t\t\tthis._root.applyChangeSet(changesToTip);\n\t\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\t\tthis._root.applyChangeSet(pendingChanges);\n\t\t\tthis.popNotificationDelayScope();\n\t\t}\n\n\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t// assert(JSON.stringify(this.root.serialize()) === JSON.stringify(this.tipView));\n\t}\n\n\tgetUnrebasedChange(guid: string) {\n\t\treturn this.unrebasedRemoteChanges[guid];\n\t}\n\n\tgetRebasedChanges(startGuid: string, endGuid?: string) {\n\t\tconst startIndex = findIndex(this.remoteChanges, (c) => c.guid === startGuid);\n if (endGuid !== undefined) {\n const endIndex = findIndex(this.remoteChanges, (c) => c.guid === endGuid);\n\t\t\treturn this.remoteChanges.slice(startIndex + 1, endIndex + 1);\n\t\t}\n\t\treturn this.remoteChanges.slice(startIndex + 1);\n\t}\n\n\tprivate rebaseLocalChanges(\n\t\tchange: IPropertyTreeMessage,\n\t\tpendingChanges: SerializedChangeSet,\n\t\tnewTipDelta: SerializedChangeSet,\n\t): boolean {\n\t\tlet rebaseBaseChangeSet = cloneDeep(change.changeSet);\n\n\t\tconst accumulatedChanges: SerializedChangeSet = {};\n\t\tconst conflicts = [] as any[];\n\n\t\tif (this.localChanges.length > 0 && this.localChanges[0].guid === change.guid) {\n\t\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t\t// assert(JSON.stringify(this.localChanges[0].changeSet) === JSON.stringify(change.changeSet),\n\t\t\t// \"Local change different than rebased remote change.\");\n\n\t\t\t// If we got a confirmation of the commit on the tip of the localChanges array,\n\t\t\t// there will be no update of the tip view at all. We just move it from local changes\n\t\t\t// to remote changes\n\t\t\tthis.localChanges.shift();\n\n\t\t\treturn false;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\tfor (let i = 0; i < this.localChanges.length; i++) {\n\t\t\t// Make sure we never receive changes out of order\n\t\t\tconsole.assert(this.localChanges[i].guid !== change.guid);\n\n\t\t\tconst rebaseMetaInformation = new Map();\n\n\t\t\tconst copiedChangeSet = new ChangeSet(cloneDeep(this.localChanges[i].changeSet));\n\t\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\n\t\t\tcopiedChangeSet.toInverseChangeSet();\n\t\t\tcopiedChangeSet.applyChangeSet(rebaseBaseChangeSet);\n\t\t\tcopiedChangeSet.applyChangeSet(this.localChanges[i].changeSet, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\t\t\trebaseBaseChangeSet = copiedChangeSet.getSerializedChangeSet();\n\n\t\t\tnew ChangeSet(accumulatedChanges).applyChangeSet(this.localChanges[i].changeSet);\n\t\t}\n\n\t\t// Compute the inverse of the pending changes and store the result in newTipDelta\n\t\tconst pendingChangesRebaseMetaInformation = new Map();\n\t\tconst deltaToTipCS = new ChangeSet(newTipDelta);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges);\n\t\tdeltaToTipCS.toInverseChangeSet();\n\n\t\t// Perform a rebase of the pending changes\n\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(pendingChanges, conflicts, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Compute the delta between the old tip (including pending changes)\n\t\t// and the new tip (not including the rebased pending changes)\n\t\tdeltaToTipCS.applyChangeSet(rebaseBaseChangeSet);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Update the tip view\n\t\tif (!this.tipView) {\n this.tipView = cloneDeep(this.remoteTipView);\n const changeSet = new ChangeSet(this.tipView);\n changeSet.applyChangeSet(accumulatedChanges);\n } else {\n new ChangeSet(this.tipView).applyChangeSet(newTipDelta);\n }\n\n\t\treturn true;\n\t}\n\n\tprotected applyStashedOp() {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyTree.d.ts","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"propertyTree.d.ts","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EACN,yBAAyB,EACzB,KAAK,EAKL,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iC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7B,kBAAkB,CAAC,IAAI,EAAE,MAAM;IAI/B,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IASrD,OAAO,CAAC,kBAAkB;IA2E1B,SAAS,CAAC,cAAc;CAGxB"}
|
package/lib/propertyTree.js
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
/* eslint-disable import/no-internal-modules */
|
|
6
|
+
import isEmpty from "lodash/isEmpty";
|
|
7
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
8
|
+
import findIndex from "lodash/findIndex";
|
|
9
|
+
import range from "lodash/range";
|
|
5
10
|
import { MessageType, FileMode, TreeEntry, } from "@fluidframework/protocol-definitions";
|
|
6
11
|
import { bufferToString } from "@fluidframework/common-utils";
|
|
7
12
|
import { SharedObject } from "@fluidframework/shared-object-base";
|
|
8
13
|
import { ChangeSet, Utils as ChangeSetUtils, rebaseToRemoteChanges, } from "@fluid-experimental/property-changeset";
|
|
9
14
|
import { PropertyFactory, BaseProperty } from "@fluid-experimental/property-properties";
|
|
10
15
|
import { v4 as uuidv4 } from "uuid";
|
|
11
|
-
import _ from "lodash";
|
|
12
16
|
import axios from "axios";
|
|
13
17
|
import { PropertyTreeFactory } from "./propertyTreeFactory";
|
|
14
18
|
/**
|
|
@@ -78,7 +82,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
78
82
|
_reportDirtinessToView() {
|
|
79
83
|
const changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);
|
|
80
84
|
const _changeSet = new ChangeSet(changes);
|
|
81
|
-
if (!
|
|
85
|
+
if (!isEmpty(_changeSet.getSerializedChangeSet())) {
|
|
82
86
|
this.emit("localModification", _changeSet);
|
|
83
87
|
}
|
|
84
88
|
this._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);
|
|
@@ -105,7 +109,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
105
109
|
if (submitEmptyChange === undefined) {
|
|
106
110
|
doSubmit = metadata !== undefined;
|
|
107
111
|
}
|
|
108
|
-
if (doSubmit || !
|
|
112
|
+
if (doSubmit || !isEmpty(changes)) {
|
|
109
113
|
this.applyChangeSet(changes, metadata || {});
|
|
110
114
|
this.root.cleanDirty();
|
|
111
115
|
}
|
|
@@ -129,7 +133,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
129
133
|
this._applyLocalChangeSet(change);
|
|
130
134
|
// Queue the op for transmission to the Fluid service.
|
|
131
135
|
if (this.transmissionsHaveBeenStopped) {
|
|
132
|
-
this.enqueuedMessages.push(
|
|
136
|
+
this.enqueuedMessages.push(cloneDeep(change));
|
|
133
137
|
}
|
|
134
138
|
else {
|
|
135
139
|
this.submitLocalMessage(change);
|
|
@@ -182,7 +186,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
182
186
|
case 0 /* ChangeSet */:
|
|
183
187
|
// If the op originated locally from this client, we've already accounted for it
|
|
184
188
|
// by advancing the state. Otherwise, advance the PRNG now.
|
|
185
|
-
this._applyRemoteChangeSet(
|
|
189
|
+
this._applyRemoteChangeSet(cloneDeep(content));
|
|
186
190
|
break;
|
|
187
191
|
default:
|
|
188
192
|
break;
|
|
@@ -330,10 +334,10 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
330
334
|
try {
|
|
331
335
|
if (!snapshot.useMH) {
|
|
332
336
|
// We load all chunks
|
|
333
|
-
const chunks = await Promise.all(
|
|
337
|
+
const chunks = await Promise.all(range(snapshot.numChunks).map(async (i) => {
|
|
334
338
|
return bufferToString(await storage.readBlob(`summaryChunk_${i}`), "utf8");
|
|
335
339
|
}));
|
|
336
|
-
const serializedSummary =
|
|
340
|
+
const serializedSummary = chunks.reduce((a, b) => a + b, "");
|
|
337
341
|
const snapshotSummary = serializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);
|
|
338
342
|
if (snapshotSummary.remoteChanges === undefined ||
|
|
339
343
|
snapshotSummary.remoteTipView === undefined ||
|
|
@@ -347,7 +351,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
347
351
|
if (isPartialCheckoutActive && this.options.paths) {
|
|
348
352
|
this.remoteTipView = ChangeSetUtils.getFilteredChangeSetByPaths(this.remoteTipView, this.options.paths);
|
|
349
353
|
}
|
|
350
|
-
this.tipView =
|
|
354
|
+
this.tipView = cloneDeep(this.remoteTipView);
|
|
351
355
|
this.skipSequenceNumber = 0;
|
|
352
356
|
}
|
|
353
357
|
else {
|
|
@@ -361,7 +365,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
361
365
|
materializedView = ChangeSetUtils.getFilteredChangeSetByPaths(materializedView, this.options.paths);
|
|
362
366
|
}
|
|
363
367
|
this.tipView = materializedView;
|
|
364
|
-
this.remoteTipView =
|
|
368
|
+
this.remoteTipView = cloneDeep(this.tipView);
|
|
365
369
|
this.remoteChanges = [];
|
|
366
370
|
let missingDeltas = [];
|
|
367
371
|
const firstDelta = Math.min(commitMetadata.minimumSequenceNumber, summaryMinimumSequenceNumber);
|
|
@@ -408,7 +412,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
408
412
|
this.localChanges.push(change);
|
|
409
413
|
}
|
|
410
414
|
_applyRemoteChangeSet(change) {
|
|
411
|
-
this.unrebasedRemoteChanges[change.guid] =
|
|
415
|
+
this.unrebasedRemoteChanges[change.guid] = cloneDeep(change);
|
|
412
416
|
// This is the first message in the history of the document.
|
|
413
417
|
if (this.remoteChanges.length !== 0) {
|
|
414
418
|
rebaseToRemoteChanges(change, this.getUnrebasedChange.bind(this), this.getRebasedChanges.bind(this));
|
|
@@ -437,15 +441,15 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
437
441
|
return this.unrebasedRemoteChanges[guid];
|
|
438
442
|
}
|
|
439
443
|
getRebasedChanges(startGuid, endGuid) {
|
|
440
|
-
const startIndex =
|
|
441
|
-
if (endGuid) {
|
|
442
|
-
const endIndex =
|
|
444
|
+
const startIndex = findIndex(this.remoteChanges, (c) => c.guid === startGuid);
|
|
445
|
+
if (endGuid !== undefined) {
|
|
446
|
+
const endIndex = findIndex(this.remoteChanges, (c) => c.guid === endGuid);
|
|
443
447
|
return this.remoteChanges.slice(startIndex + 1, endIndex + 1);
|
|
444
448
|
}
|
|
445
449
|
return this.remoteChanges.slice(startIndex + 1);
|
|
446
450
|
}
|
|
447
451
|
rebaseLocalChanges(change, pendingChanges, newTipDelta) {
|
|
448
|
-
let rebaseBaseChangeSet =
|
|
452
|
+
let rebaseBaseChangeSet = cloneDeep(change.changeSet);
|
|
449
453
|
const accumulatedChanges = {};
|
|
450
454
|
const conflicts = [];
|
|
451
455
|
if (this.localChanges.length > 0 && this.localChanges[0].guid === change.guid) {
|
|
@@ -463,7 +467,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
463
467
|
// Make sure we never receive changes out of order
|
|
464
468
|
console.assert(this.localChanges[i].guid !== change.guid);
|
|
465
469
|
const rebaseMetaInformation = new Map();
|
|
466
|
-
const copiedChangeSet = new ChangeSet(
|
|
470
|
+
const copiedChangeSet = new ChangeSet(cloneDeep(this.localChanges[i].changeSet));
|
|
467
471
|
new ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {
|
|
468
472
|
applyAfterMetaInformation: rebaseMetaInformation,
|
|
469
473
|
});
|
|
@@ -492,7 +496,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
492
496
|
});
|
|
493
497
|
// Update the tip view
|
|
494
498
|
if (!this.tipView) {
|
|
495
|
-
this.tipView =
|
|
499
|
+
this.tipView = cloneDeep(this.remoteTipView);
|
|
496
500
|
const changeSet = new ChangeSet(this.tipView);
|
|
497
501
|
changeSet.applyChangeSet(accumulatedChanges);
|
|
498
502
|
}
|
package/lib/propertyTree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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oEAAoE;QACpE,8DAA8D;QAC9D,YAAY,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;QACjD,YAAY,CAAC,cAAc,CAAC,cAAc,EAAE;YAC3C,yBAAyB,EAAE,mCAAmC;SAC9D,CAAC,CAAC;QAEH,sBAAsB;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACT,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC/C,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,SAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;SAChD;aAAM;YACH,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;SAC3D;QAEP,OAAO,IAAI,CAAC;IACb,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISequencedDocumentMessage,\n\tITree,\n\tMessageType,\n\tFileMode,\n\tTreeEntry,\n\tITreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\n\nimport { bufferToString, assert } from \"@fluidframework/common-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\n\nimport {\n\tChangeSet,\n\tUtils as ChangeSetUtils,\n rebaseToRemoteChanges,\n} from \"@fluid-experimental/property-changeset\";\n\nimport { PropertyFactory, BaseProperty, NodeProperty } from \"@fluid-experimental/property-properties\";\n\nimport { v4 as uuidv4 } from \"uuid\";\nimport _ from \"lodash\";\nimport axios from \"axios\";\nimport { PropertyTreeFactory } from \"./propertyTreeFactory\";\n\nexport type SerializedChangeSet = any;\n\nexport type Metadata = any;\n\ntype FetchUnrebasedChangeFn = (guid: string) => IRemotePropertyTreeMessage;\ntype FetchRebasedChangesFn = (startGuid: string, endGuid?: string) => IPropertyTreeMessage[];\n\nexport const enum OpKind {\n\t// eslint-disable-next-line @typescript-eslint/no-shadow\n\tChangeSet = 0,\n}\n\nexport interface IPropertyTreeMessage {\n\top: OpKind;\n\tchangeSet: SerializedChangeSet;\n\tmetadata: Metadata;\n\tguid: string;\n\treferenceGuid: string;\n\tremoteHeadGuid: string;\n\tlocalBranchStart: string | undefined;\n\trebaseMetaInformation?: Map<any, any>;\n\tuseMH?: boolean;\n}\n\nexport interface IRemotePropertyTreeMessage extends IPropertyTreeMessage {\n\tsequenceNumber: number;\n}\ninterface ISnapshot {\n\tbranchGuid: string;\n\tsummaryMinimumSequenceNumber: number;\n\tuseMH: boolean;\n\tnumChunks: number;\n}\ninterface ISnapshotSummary {\n\tremoteTipView?: SerializedChangeSet;\n\tremoteChanges?: IPropertyTreeMessage[];\n\tunrebasedRemoteChanges?: Record<string, IRemotePropertyTreeMessage>;\n}\n\nexport interface SharedPropertyTreeOptions {\n\tpaths?: string[];\n\tclientFiltering?: boolean;\n\tuseMH?: boolean;\n}\n\n/**\n * Silly DDS example that models a six sided die.\n *\n * Unlike the typical 'Dice Roller' example where clients clobber each other's last roll in a\n * SharedMap, this 'SharedDie' DDS works by advancing an internal PRNG each time it sees a 'roll'\n * operation.\n *\n * Because all clients are using the same PRNG starting in the same state, they arrive at\n * consensus by simply applying the same number of rolls. (A fun addition would be logging\n * who received which roll, which would need to change as clients learn how races are resolved\n * in the total order)\n */\nexport class SharedPropertyTree extends SharedObject {\n\ttipView: SerializedChangeSet = {};\n\tremoteTipView: SerializedChangeSet = {};\n\tlocalChanges: IPropertyTreeMessage[] = [];\n\tremoteChanges: IPropertyTreeMessage[] = [];\n\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\ttransmissionsHaveBeenStopped = false;\n\tenqueuedMessages: IPropertyTreeMessage[] = [];\n\tnotificationDelayScope: number = 0;\n\t_root: any = PropertyFactory.create(\"NodeProperty\");\n\toptions: SharedPropertyTreeOptions;\n\tskipSequenceNumber: number = -1;\n\theadCommitGuid: string = \"\";\n\tuseMH: boolean = false;\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\toptions: SharedPropertyTreeOptions,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis.options = options;\n\t\t// Quick hack to let the root be aware of the DDS hosting it.\n\t\tthis._root._tree = this;\n\n\t\t// By default, we currently don't use the MH\n\t\tthis.useMH = options.useMH ?? false;\n\t}\n\n\t/**\n\t * Create a new shared cell\n\t *\n\t * @param runtime - data store runtime the new shared map belongs to\n\t * @param id - optional name of the shared map\n\t * @returns newly create shared map (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string, queryString?: string) {\n\t\treturn runtime.createChannel(id, PropertyTreeFactory.Type) as SharedPropertyTree;\n\t}\n\n\t/**\n\t * Get a factory for SharedDie to register with the data store.\n\t *\n\t * @returns a factory that creates and load SharedDie\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PropertyTreeFactory();\n\t}\n\n\t/**\n\t * in case of partial checkout we want to send the paths we are interested in once we are connected\n\t */\n\tprotected onConnect() {\n\t\t// on connect we scope all deltas such that we only get relevant changes\n\t\t// since we know the paths already at constuction time this is okay\n\t\tthis.scopeFutureDeltasToPaths(this.options.paths);\n\t}\n\n\tprivate scopeFutureDeltasToPaths(paths?: string[]) {\n\t\tconst socket = (this.runtime.deltaManager as any).deltaManager.connection.socket;\n\t\tsocket.emit(\"partial_checkout\", { paths });\n\t}\n\n\tpublic _reportDirtinessToView() {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t\tconst _changeSet = new ChangeSet(changes);\n\t\tif (!_.isEmpty(_changeSet.getSerializedChangeSet())) {\n\t\t\tthis.emit(\"localModification\", _changeSet);\n\t\t}\n\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t}\n\n\tpublic get changeSet(): SerializedChangeSet {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.tipView;\n\t}\n\n public get activeCommit(): IPropertyTreeMessage {\n if(this.localChanges.length > 0) {\n return this.localChanges[this.localChanges.length - 1];\n } else {\n return this.remoteChanges[this.remoteChanges.length - 1];\n }\n\t}\n\tpublic get root(): NodeProperty {\n\t\treturn this._root as NodeProperty;\n\t}\n\n\tpublic commit(metadata?: Metadata, submitEmptyChange?: boolean) {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\n let doSubmit = !!submitEmptyChange;\n\n // if no override provided dont submit unless metadata are provided\n if (submitEmptyChange === undefined) {\n doSubmit = metadata !== undefined;\n }\n\n if (doSubmit || !_.isEmpty(changes)) {\n this.applyChangeSet(changes, metadata || {});\n this.root.cleanDirty();\n }\n\t}\n\n\tprivate applyChangeSet(changeSet: SerializedChangeSet, metadata: Metadata) {\n\t\tconst _changeSet = new ChangeSet(changeSet);\n\t\t_changeSet._toReversibleChangeSet(this.tipView);\n\n\t\tconst remoteHeadGuid =\n\t\t\tthis.remoteChanges.length > 0\n\t\t\t\t? this.remoteChanges[this.remoteChanges.length - 1].guid\n\t\t\t\t: this.headCommitGuid;\n\t\tconst change = {\n\t\t\top: OpKind.ChangeSet,\n\t\t\tchangeSet,\n\t\t\tmetadata,\n\t\t\tguid: uuidv4(),\n\t\t\tremoteHeadGuid,\n\t\t\treferenceGuid:\n\t\t\t\tthis.localChanges.length > 0 ? this.localChanges[this.localChanges.length - 1].guid : remoteHeadGuid,\n\t\t\tlocalBranchStart: this.localChanges.length > 0 ? this.localChanges[0].guid : undefined,\n\t\t\tuseMH: this.useMH,\n\t\t};\n\t\tthis._applyLocalChangeSet(change);\n\n\t\t// Queue the op for transmission to the Fluid service.\n\t\tif (this.transmissionsHaveBeenStopped) {\n\t\t\tthis.enqueuedMessages.push(_.cloneDeep(change));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(change);\n\t\t}\n\t}\n\n\tstopTransmission(stop: boolean) {\n\t\tthis.transmissionsHaveBeenStopped = stop;\n\t\tif (stop === false) {\n\t\t\tfor (const message of this.enqueuedMessages) {\n\t\t\t\tthis.submitLocalMessage(message);\n\t\t\t}\n\t\t\tthis.enqueuedMessages = [];\n\t\t}\n\t}\n\t/**\n\t * Delays notifications until popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic pushNotificationDelayScope() {\n\t\t// set the scope counter\n\t\tthis.notificationDelayScope++;\n\n\t\t// If we reach 0, we have to report unreported changes\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tthis._root._reportDirtinessToView();\n\t\t}\n\t}\n\n\t/**\n\t * Re-enables notifications when popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic popNotificationDelayScope() {\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tconsole.error(\"Unbalanced push/pop calls.\");\n\t\t}\n\t\tthis.notificationDelayScope--;\n\t\tthis._root._reportDirtinessToView();\n\t}\n\n\t/**\n\t * Process an operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tif (message.type === MessageType.Operation && message.sequenceNumber > this.skipSequenceNumber) {\n\t\t\tconst content: IRemotePropertyTreeMessage = { ...message.contents, sequenceNumber: message.sequenceNumber };\n\t\t\tswitch (content.op) {\n\t\t\t\tcase OpKind.ChangeSet:\n\t\t\t\t\t// If the op originated locally from this client, we've already accounted for it\n\t\t\t\t\t// by advancing the state. Otherwise, advance the PRNG now.\n\t\t\t\t\tthis._applyRemoteChangeSet(_.cloneDeep(content));\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static prune(\n\t\tminimumSequenceNumber: number,\n\t\tremoteChanges: IPropertyTreeMessage[],\n\t\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage>,\n\t) {\n\t\t// for faster lookup of remote change guids\n\t\tconst remoteChangeMap = new Map<string, number>();\n\t\tremoteChanges.forEach((change, index) => {\n\t\t\tremoteChangeMap.set(change.guid, index);\n\t\t});\n\n\t\t// we will track visited nodes\n\t\tconst visitedUnrebasedRemoteChanges = new Set<string>();\n\t\tconst visitedRemoteChanges = new Set<string>();\n\n\t\tfor (const id of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tconst unrebasedChange = unrebasedRemoteChanges[id];\n\n\t\t\t// we are only interested in changes that are newer than the sequence number\n\t\t\t// and that were not yet visited previously\n\t\t\tif (\n\t\t\t\tunrebasedChange.sequenceNumber >= minimumSequenceNumber &&\n\t\t\t\t!visitedUnrebasedRemoteChanges.has(unrebasedChange.guid)\n\t\t\t) {\n\t\t\t\t// we visited that unrebased change and mark it as visited\n\t\t\t\tvisitedUnrebasedRemoteChanges.add(unrebasedChange.guid);\n\n\t\t\t\tlet visitor = unrebasedChange;\n\t\t\t\t// we will walk along the commit chain until we hit a remote change or a visited unrebased commit\n\t\t\t\t// at that point we can skip since we already traced the rest of the commit chain\n\t\t\t\twhile (\n\t\t\t\t\tvisitor.remoteHeadGuid !== visitor.referenceGuid ||\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.has(visitor.referenceGuid)\n\t\t\t\t) {\n\t\t\t\t\tconst guid = visitor.referenceGuid;\n\t\t\t\t\tif (guid === \"\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// since the change is not in remote it must be in unrebased\n\t\t\t\t\tvisitor = unrebasedRemoteChanges[visitor.referenceGuid];\n\t\t\t\t\tif (!visitor) {\n\t\t\t\t\t\tthrow new Error(`no visitor found for guid \"${guid}\"`);\n\t\t\t\t\t}\n\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.add(visitor.guid);\n\t\t\t\t}\n\t\t\t\t// if we exited the loop because we hit a remote change than add it as visited\n\t\t\t\tif (visitor.remoteHeadGuid === visitor.referenceGuid && remoteChangeMap.has(visitor.referenceGuid)) {\n\t\t\t\t\tvisitedRemoteChanges.add(visitor.referenceGuid);\n\t\t\t\t}\n\n // If we have a change that refers to the start of the history (remoteHeadGuid === \"\"), we have to\n // keep all remote Changes until this change has been processed\n if (visitor.remoteHeadGuid === \"\") {\n visitedRemoteChanges.add(remoteChanges[0].guid);\n }\n\t\t\t}\n\t\t}\n\t\tlet pruned = 0;\n\t\t// we can now filter the unrebased changes by removing any changes\n\t\t// we have not visited at all during our traversal\n\t\tconst prunedUnrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\t\tfor (const key of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tif (visitedUnrebasedRemoteChanges.has(key)) {\n\t\t\t\tprunedUnrebasedRemoteChanges[key] = unrebasedRemoteChanges[key];\n\t\t\t} else {\n\t\t\t\tpruned++;\n\t\t\t}\n\t\t}\n\n\t\t// find minimum index\n\t\tconst minIndex = Math.min(...[...visitedRemoteChanges].map((key) => remoteChangeMap.get(key) as number));\n\n\t\tconst prunedRemoteChanges = remoteChanges.slice(minIndex);\n\t\tpruned += minIndex;\n\n\t\treturn {\n\t\t\tremoteChanges: prunedRemoteChanges,\n\t\t\tunrebasedRemoteChanges: prunedUnrebasedRemoteChanges,\n\t\t\tprunedCount: pruned,\n\t\t};\n\t}\n\tpublic pruneHistory() {\n\t\tconst msn = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tconst { remoteChanges, unrebasedRemoteChanges } = SharedPropertyTree.prune(\n\t\t\tmsn,\n\t\t\tthis.remoteChanges,\n\t\t\tthis.unrebasedRemoteChanges,\n\t\t);\n\n\t\tthis.remoteChanges = remoteChanges;\n\t\tthis.unrebasedRemoteChanges = unrebasedRemoteChanges;\n\t}\n\tpublic snapshotCore(serializer: IFluidSerializer): ITree {\n\t\tthis.pruneHistory();\n\t\tconst snapshot: ISnapshot = {\n\t\t\tbranchGuid: this.handle.absolutePath.split(\"/\").pop() as string,\n\t\t\tsummaryMinimumSequenceNumber: this.runtime.deltaManager.minimumSequenceNumber,\n\t\t\tuseMH: this.useMH,\n\t\t\tnumChunks: 0,\n\t\t};\n\n\t\tconst chunks: ITreeEntry[] = [];\n\t\tif (!this.useMH) {\n\t\t\t// If the MH is not used, we have to include the tip view, the remote changes and the received\n\t\t\t// deltas to the summary\n\t\t\tconst summary: ISnapshotSummary = {\n\t\t\t\tremoteTipView: this.remoteTipView,\n\t\t\t\tremoteChanges: this.remoteChanges,\n\t\t\t\tunrebasedRemoteChanges: this.unrebasedRemoteChanges,\n\t\t\t};\n\t\t\tconst chunkSize = 5000 * 1024; // Default limit seems to be 5MB\n\t\t\tlet serializedSummary =\n\t\t\t\tserializer !== undefined ? serializer.stringify(summary, this.handle) : JSON.stringify(summary);\n\n\t\t\t// JSON.stringify does not escape unicode characters. As a consequence,\n\t\t\t// the chunking code below could create chunks which are bigger than the\n\t\t\t// allowed limit after encoding the JSON via UTF8 encoding. To make sure\n\t\t\t// the encoded string stays within the size limit, we replace unicode characters\n\t\t\t// with the cooresponding escapes. This way, it won't change size when encoded as\n\t\t\t// utf8\n\t\t\tserializedSummary = serializedSummary.replace(\n\t\t\t\t/[\\u007F-\\uFFFF]/g,\n\t\t\t\t// eslint-disable-next-line prefer-template\n\t\t\t\t(c) => `\\\\u${(\"0000\" + c.charCodeAt(0).toString(16)).substr(-4)}`,\n\t\t\t);\n\n\t\t\tfor (let pos = 0, i = 0; pos < serializedSummary.length; pos += chunkSize, i++) {\n\t\t\t\tchunks.push({\n\t\t\t\t\tpath: `summaryChunk_${i}`,\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents: serializedSummary.substr(pos, chunkSize),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tsnapshot.numChunks = chunks.length;\n\t\t}\n\n\t\treturn {\n\t\t\tentries: [\n\t\t\t\t{\n\t\t\t\t\tpath: \"properties\",\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents:\n\t\t\t\t\t\t\tserializer !== undefined\n\t\t\t\t\t\t\t\t? serializer.stringify(snapshot, this.handle)\n\t\t\t\t\t\t\t\t: JSON.stringify(snapshot),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...chunks,\n\t\t\t],\n\t\t\tid: undefined,\n\t\t};\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst runtime = this.runtime;\n\t\tconst handleTableChunk = await storage.readBlob(\"properties\");\n\t\tconst utf8 = bufferToString(handleTableChunk, \"utf8\");\n\n\t\tconst serializer = runtime.IFluidSerializer;\n\t\tconst snapshot: ISnapshot = serializer !== undefined ? serializer.parse(utf8) : JSON.parse(utf8);\n\t\tthis.useMH = snapshot.useMH;\n\n\t\ttry {\n\t\t\tif (!snapshot.useMH) {\n\t\t\t\t// We load all chunks\n\t\t\t\tconst chunks = await Promise.all(\n\t\t\t\t\t_.range(snapshot.numChunks).map(async (i) => {\n\t\t\t\t\t\treturn bufferToString(await storage.readBlob(`summaryChunk_${i}`), \"utf8\");\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst serializedSummary = _.reduce(chunks, (a, b) => a + b, \"\");\n\t\t\t\tconst snapshotSummary: ISnapshotSummary =\n\t\t\t\t\tserializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);\n\t\t\t\tif (\n\t\t\t\t\tsnapshotSummary.remoteChanges === undefined ||\n\t\t\t\t\tsnapshotSummary.remoteTipView === undefined ||\n\t\t\t\t\tsnapshotSummary.unrebasedRemoteChanges === undefined\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\"Invalid Snapshot.\");\n\t\t\t\t}\n\n\t\t\t\tthis.remoteTipView = snapshotSummary.remoteTipView;\n\t\t\t\tthis.remoteChanges = snapshotSummary.remoteChanges;\n\t\t\t\tthis.unrebasedRemoteChanges = snapshotSummary.unrebasedRemoteChanges;\n\n\t\t\t\tconst isPartialCheckoutActive = !!(this.options.clientFiltering && this.options.paths);\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tthis.remoteTipView = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\tthis.remoteTipView,\n\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.tipView = _.cloneDeep(this.remoteTipView);\n\n\t\t\t\tthis.skipSequenceNumber = 0;\n\t\t\t} else {\n\t\t\t\tconst { branchGuid, summaryMinimumSequenceNumber } = snapshot;\n\t\t\t\tconst branchResponse = await axios.get(`http://localhost:3000/branch/${branchGuid}`);\n\t\t\t\tthis.headCommitGuid = branchResponse.data.headCommitGuid;\n\t\t\t\tconst {\n\t\t\t\t\tcommit: { meta: commitMetadata },\n\t\t\t\t} = (await axios.get(`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}`)).data;\n\t\t\t\tlet { changeSet: materializedView } = (\n\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}/materializedView`,\n\t\t\t\t\t)\n\t\t\t\t).data;\n\n\t\t\t\tconst isPartialCheckoutActive = this.options.clientFiltering && this.options.paths;\n\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tmaterializedView = ChangeSetUtils.getFilteredChangeSetByPaths(materializedView, this.options.paths);\n\t\t\t\t}\n\n\t\t\t\tthis.tipView = materializedView;\n\t\t\t\tthis.remoteTipView = _.cloneDeep(this.tipView);\n\t\t\t\tthis.remoteChanges = [];\n\n\t\t\t\tlet missingDeltas: ISequencedDocumentMessage[] = [];\n\t\t\t\tconst firstDelta = Math.min(commitMetadata.minimumSequenceNumber, summaryMinimumSequenceNumber);\n\t\t\t\tconst lastDelta = commitMetadata.sequenceNumber;\n\n\t\t\t\tconst dm = (this.runtime.deltaManager as any).deltaManager;\n\t\t\t\tawait dm.getDeltas(\"DocumentOpen\", firstDelta, lastDelta, (messages: ISequencedDocumentMessage[]) => {\n\t\t\t\t\tmissingDeltas = messages.filter((x) => x.type === \"op\");\n\t\t\t\t});\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\t\t\tfor (let i = 0; i < missingDeltas.length; i++) {\n\t\t\t\t\tif (missingDeltas[i].sequenceNumber < commitMetadata.sequenceNumber) {\n\t\t\t\t\t\tconst remoteChange: IPropertyTreeMessage\n\t\t\t\t\t\t\t= JSON.parse(missingDeltas[i].contents).contents.contents.content.contents;\n\t\t\t\t\t\tconst { changeSet } = (\n\t\t\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${remoteChange.guid}/changeSet`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t).data;\n\t\t\t\t\t\tremoteChange.changeSet = changeSet;\n\n\t\t\t\t\t\tif (remoteChange) {\n\t\t\t\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\t\t\t\tremoteChange.changeSet = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\t\t\t\tremoteChange.changeSet,\n\t\t\t\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.remoteChanges.push(remoteChange);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.processCore(missingDeltas[i], false, {});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.skipSequenceNumber = lastDelta ?? -1;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.tipView = {};\n\t\t\tthis.remoteTipView = {};\n\t\t\tthis.remoteChanges = [];\n\t\t} finally {\n\t\t\tthis._root.deserialize(this.tipView);\n\t\t\tthis.root.cleanDirty();\n\t\t}\n\t}\n\n\tprotected registerCore() { }\n\tprotected onDisconnect() { }\n\n\tprivate _applyLocalChangeSet(change: IPropertyTreeMessage) {\n\t\tconst changeSetWrapper = new ChangeSet(this.tipView);\n\t\tchangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\tthis.localChanges.push(change);\n\t}\n\n\tprivate _applyRemoteChangeSet(change: IRemotePropertyTreeMessage) {\n\t\tthis.unrebasedRemoteChanges[change.guid] = _.cloneDeep(change);\n\n\t\t// This is the first message in the history of the document.\n\t\tif (this.remoteChanges.length !== 0) {\n\t\t\trebaseToRemoteChanges(\n\t\t\t\tchange,\n\t\t\t\tthis.getUnrebasedChange.bind(this),\n\t\t\t\tthis.getRebasedChanges.bind(this),\n\t\t\t);\n\t\t}\n\n\t\tthis.remoteChanges.push(change);\n\n\t\t// Apply the remote change set to the remote tip view\n\t\tconst remoteChangeSetWrapper = new ChangeSet(this.remoteTipView);\n\t\tremoteChangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\t// Rebase the local changes\n\t\tconst pendingChanges = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\tnew ChangeSet(pendingChanges)._toReversibleChangeSet(this.tipView);\n\n\t\tconst changesToTip: SerializedChangeSet = {};\n\t\tconst changesNeeded = this.rebaseLocalChanges(change, pendingChanges, changesToTip);\n\n\t\tif (changesNeeded) {\n\t\t\tthis.pushNotificationDelayScope();\n\t\t\t// Checkout the new tip\n\t\t\tthis._root.applyChangeSet(changesToTip);\n\t\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\t\tthis._root.applyChangeSet(pendingChanges);\n\t\t\tthis.popNotificationDelayScope();\n\t\t}\n\n\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t// assert(JSON.stringify(this.root.serialize()) === JSON.stringify(this.tipView));\n\t}\n\n\tgetUnrebasedChange(guid: string) {\n\t\treturn this.unrebasedRemoteChanges[guid];\n\t}\n\n\tgetRebasedChanges(startGuid: string, endGuid?: string) {\n\t\tconst startIndex = _.findIndex(this.remoteChanges, (c) => c.guid === startGuid);\n\t\tif (endGuid) {\n\t\t\tconst endIndex = _.findIndex(this.remoteChanges, (c) => c.guid === endGuid);\n\t\t\treturn this.remoteChanges.slice(startIndex + 1, endIndex + 1);\n\t\t}\n\t\treturn this.remoteChanges.slice(startIndex + 1);\n\t}\n\n\tprivate rebaseLocalChanges(\n\t\tchange: IPropertyTreeMessage,\n\t\tpendingChanges: SerializedChangeSet,\n\t\tnewTipDelta: SerializedChangeSet,\n\t): boolean {\n\t\tlet rebaseBaseChangeSet = _.cloneDeep(change.changeSet);\n\n\t\tconst accumulatedChanges: SerializedChangeSet = {};\n\t\tconst conflicts = [] as any[];\n\n\t\tif (this.localChanges.length > 0 && this.localChanges[0].guid === change.guid) {\n\t\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t\t// assert(JSON.stringify(this.localChanges[0].changeSet) === JSON.stringify(change.changeSet),\n\t\t\t// \"Local change different than rebased remote change.\");\n\n\t\t\t// If we got a confirmation of the commit on the tip of the localChanges array,\n\t\t\t// there will be no update of the tip view at all. We just move it from local changes\n\t\t\t// to remote changes\n\t\t\tthis.localChanges.shift();\n\n\t\t\treturn false;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\tfor (let i = 0; i < this.localChanges.length; i++) {\n\t\t\t// Make sure we never receive changes out of order\n\t\t\tconsole.assert(this.localChanges[i].guid !== change.guid);\n\n\t\t\tconst rebaseMetaInformation = new Map();\n\n\t\t\tconst copiedChangeSet = new ChangeSet(_.cloneDeep(this.localChanges[i].changeSet));\n\t\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\n\t\t\tcopiedChangeSet.toInverseChangeSet();\n\t\t\tcopiedChangeSet.applyChangeSet(rebaseBaseChangeSet);\n\t\t\tcopiedChangeSet.applyChangeSet(this.localChanges[i].changeSet, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\t\t\trebaseBaseChangeSet = copiedChangeSet.getSerializedChangeSet();\n\n\t\t\tnew ChangeSet(accumulatedChanges).applyChangeSet(this.localChanges[i].changeSet);\n\t\t}\n\n\t\t// Compute the inverse of the pending changes and store the result in newTipDelta\n\t\tconst pendingChangesRebaseMetaInformation = new Map();\n\t\tconst deltaToTipCS = new ChangeSet(newTipDelta);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges);\n\t\tdeltaToTipCS.toInverseChangeSet();\n\n\t\t// Perform a rebase of the pending changes\n\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(pendingChanges, conflicts, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Compute the delta between the old tip (including pending changes)\n\t\t// and the new tip (not including the rebased pending changes)\n\t\tdeltaToTipCS.applyChangeSet(rebaseBaseChangeSet);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Update the tip view\n\t\tif (!this.tipView) {\n this.tipView = _.cloneDeep(this.remoteTipView);\n const changeSet = new ChangeSet(this.tipView);\n changeSet.applyChangeSet(accumulatedChanges);\n } else {\n new ChangeSet(this.tipView).applyChangeSet(newTipDelta);\n }\n\n\t\treturn true;\n\t}\n\n\tprotected applyStashedOp() {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"propertyTree.js","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+CAA+C;AAC/C,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,MAAM,cAAc,CAAC;AAEjC,OAAO,EAGN,WAAW,EACX,QAAQ,EACR,SAAS,GAET,MAAM,sCAAsC,CAAC;AAQ9C,OAAO,EAAE,cAAc,EAAU,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGlE,OAAO,EACN,SAAS,EACT,KAAK,IAAI,cAAc,EACpB,qBAAqB,GACxB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAgB,MAAM,yCAAyC,CAAC;AAEtG,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AA+C5D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAenD,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EAC9B,OAAkC;;QAElC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QApBhC,YAAO,GAAwB,EAAE,CAAC;QAClC,kBAAa,GAAwB,EAAE,CAAC;QACxC,iBAAY,GAA2B,EAAE,CAAC;QAC1C,kBAAa,GAA2B,EAAE,CAAC;QAC3C,2BAAsB,GAA+C,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AE,CAAC;QAElC,0CAA0C;QAC1C,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC,gBAAgB,CAAC,cAAc,EAAE,SAAS,EAAE;YAC9E,yBAAyB,EAAE,mCAAmC;SAC9D,CAAC,CAAC;QAEH,oEAAoE;QACpE,8DAA8D;QAC9D,YAAY,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;QACjD,YAAY,CAAC,cAAc,CAAC,cAAc,EAAE;YAC3C,yBAAyB,EAAE,mCAAmC;SAC9D,CAAC,CAAC;QAEH,sBAAsB;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACT,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC7C,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,SAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;SAChD;aAAM;YACH,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;SAC3D;QAEP,OAAO,IAAI,CAAC;IACb,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable import/no-internal-modules */\nimport isEmpty from \"lodash/isEmpty\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport findIndex from \"lodash/findIndex\";\nimport range from \"lodash/range\";\n\nimport {\n\tISequencedDocumentMessage,\n\tITree,\n\tMessageType,\n\tFileMode,\n\tTreeEntry,\n\tITreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\n\nimport { bufferToString, assert } from \"@fluidframework/common-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\n\nimport {\n\tChangeSet,\n\tUtils as ChangeSetUtils,\n rebaseToRemoteChanges,\n} from \"@fluid-experimental/property-changeset\";\n\nimport { PropertyFactory, BaseProperty, NodeProperty } from \"@fluid-experimental/property-properties\";\n\nimport { v4 as uuidv4 } from \"uuid\";\nimport axios from \"axios\";\nimport { PropertyTreeFactory } from \"./propertyTreeFactory\";\n\nexport type SerializedChangeSet = any;\n\nexport type Metadata = any;\n\ntype FetchUnrebasedChangeFn = (guid: string) => IRemotePropertyTreeMessage;\ntype FetchRebasedChangesFn = (startGuid: string, endGuid?: string) => IPropertyTreeMessage[];\n\nexport const enum OpKind {\n\t// eslint-disable-next-line @typescript-eslint/no-shadow\n\tChangeSet = 0,\n}\n\nexport interface IPropertyTreeMessage {\n\top: OpKind;\n\tchangeSet: SerializedChangeSet;\n\tmetadata: Metadata;\n\tguid: string;\n\treferenceGuid: string;\n\tremoteHeadGuid: string;\n\tlocalBranchStart: string | undefined;\n\trebaseMetaInformation?: Map<any, any>;\n\tuseMH?: boolean;\n}\n\nexport interface IRemotePropertyTreeMessage extends IPropertyTreeMessage {\n\tsequenceNumber: number;\n}\ninterface ISnapshot {\n\tbranchGuid: string;\n\tsummaryMinimumSequenceNumber: number;\n\tuseMH: boolean;\n\tnumChunks: number;\n}\ninterface ISnapshotSummary {\n\tremoteTipView?: SerializedChangeSet;\n\tremoteChanges?: IPropertyTreeMessage[];\n\tunrebasedRemoteChanges?: Record<string, IRemotePropertyTreeMessage>;\n}\n\nexport interface SharedPropertyTreeOptions {\n\tpaths?: string[];\n\tclientFiltering?: boolean;\n\tuseMH?: boolean;\n}\n\n/**\n * Silly DDS example that models a six sided die.\n *\n * Unlike the typical 'Dice Roller' example where clients clobber each other's last roll in a\n * SharedMap, this 'SharedDie' DDS works by advancing an internal PRNG each time it sees a 'roll'\n * operation.\n *\n * Because all clients are using the same PRNG starting in the same state, they arrive at\n * consensus by simply applying the same number of rolls. (A fun addition would be logging\n * who received which roll, which would need to change as clients learn how races are resolved\n * in the total order)\n */\nexport class SharedPropertyTree extends SharedObject {\n\ttipView: SerializedChangeSet = {};\n\tremoteTipView: SerializedChangeSet = {};\n\tlocalChanges: IPropertyTreeMessage[] = [];\n\tremoteChanges: IPropertyTreeMessage[] = [];\n\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\ttransmissionsHaveBeenStopped = false;\n\tenqueuedMessages: IPropertyTreeMessage[] = [];\n\tnotificationDelayScope: number = 0;\n\t_root: any = PropertyFactory.create(\"NodeProperty\");\n\toptions: SharedPropertyTreeOptions;\n\tskipSequenceNumber: number = -1;\n\theadCommitGuid: string = \"\";\n\tuseMH: boolean = false;\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\toptions: SharedPropertyTreeOptions,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis.options = options;\n\t\t// Quick hack to let the root be aware of the DDS hosting it.\n\t\tthis._root._tree = this;\n\n\t\t// By default, we currently don't use the MH\n\t\tthis.useMH = options.useMH ?? false;\n\t}\n\n\t/**\n\t * Create a new shared cell\n\t *\n\t * @param runtime - data store runtime the new shared map belongs to\n\t * @param id - optional name of the shared map\n\t * @returns newly create shared map (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string, queryString?: string) {\n\t\treturn runtime.createChannel(id, PropertyTreeFactory.Type) as SharedPropertyTree;\n\t}\n\n\t/**\n\t * Get a factory for SharedDie to register with the data store.\n\t *\n\t * @returns a factory that creates and load SharedDie\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PropertyTreeFactory();\n\t}\n\n\t/**\n\t * in case of partial checkout we want to send the paths we are interested in once we are connected\n\t */\n\tprotected onConnect() {\n\t\t// on connect we scope all deltas such that we only get relevant changes\n\t\t// since we know the paths already at constuction time this is okay\n\t\tthis.scopeFutureDeltasToPaths(this.options.paths);\n\t}\n\n\tprivate scopeFutureDeltasToPaths(paths?: string[]) {\n\t\tconst socket = (this.runtime.deltaManager as any).deltaManager.connection.socket;\n\t\tsocket.emit(\"partial_checkout\", { paths });\n\t}\n\n\tpublic _reportDirtinessToView() {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t\tconst _changeSet = new ChangeSet(changes);\n\t\tif (!isEmpty(_changeSet.getSerializedChangeSet())) {\n\t\t\tthis.emit(\"localModification\", _changeSet);\n\t\t}\n\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);\n\t}\n\n\tpublic get changeSet(): SerializedChangeSet {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.tipView;\n\t}\n\n public get activeCommit(): IPropertyTreeMessage {\n if(this.localChanges.length > 0) {\n return this.localChanges[this.localChanges.length - 1];\n } else {\n return this.remoteChanges[this.remoteChanges.length - 1];\n }\n\t}\n\tpublic get root(): NodeProperty {\n\t\treturn this._root as NodeProperty;\n\t}\n\n\tpublic commit(metadata?: Metadata, submitEmptyChange?: boolean) {\n\t\tconst changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\n let doSubmit = !!submitEmptyChange;\n\n // if no override provided dont submit unless metadata are provided\n if (submitEmptyChange === undefined) {\n doSubmit = metadata !== undefined;\n }\n\n if (doSubmit || !isEmpty(changes)) {\n this.applyChangeSet(changes, metadata || {});\n this.root.cleanDirty();\n }\n\t}\n\n\tprivate applyChangeSet(changeSet: SerializedChangeSet, metadata: Metadata) {\n\t\tconst _changeSet = new ChangeSet(changeSet);\n\t\t_changeSet._toReversibleChangeSet(this.tipView);\n\n\t\tconst remoteHeadGuid =\n\t\t\tthis.remoteChanges.length > 0\n\t\t\t\t? this.remoteChanges[this.remoteChanges.length - 1].guid\n\t\t\t\t: this.headCommitGuid;\n\t\tconst change = {\n\t\t\top: OpKind.ChangeSet,\n\t\t\tchangeSet,\n\t\t\tmetadata,\n\t\t\tguid: uuidv4(),\n\t\t\tremoteHeadGuid,\n\t\t\treferenceGuid:\n\t\t\t\tthis.localChanges.length > 0 ? this.localChanges[this.localChanges.length - 1].guid : remoteHeadGuid,\n\t\t\tlocalBranchStart: this.localChanges.length > 0 ? this.localChanges[0].guid : undefined,\n\t\t\tuseMH: this.useMH,\n\t\t};\n\t\tthis._applyLocalChangeSet(change);\n\n\t\t// Queue the op for transmission to the Fluid service.\n\t\tif (this.transmissionsHaveBeenStopped) {\n\t\t\tthis.enqueuedMessages.push(cloneDeep(change));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(change);\n\t\t}\n\t}\n\n\tstopTransmission(stop: boolean) {\n\t\tthis.transmissionsHaveBeenStopped = stop;\n\t\tif (stop === false) {\n\t\t\tfor (const message of this.enqueuedMessages) {\n\t\t\t\tthis.submitLocalMessage(message);\n\t\t\t}\n\t\t\tthis.enqueuedMessages = [];\n\t\t}\n\t}\n\t/**\n\t * Delays notifications until popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic pushNotificationDelayScope() {\n\t\t// set the scope counter\n\t\tthis.notificationDelayScope++;\n\n\t\t// If we reach 0, we have to report unreported changes\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tthis._root._reportDirtinessToView();\n\t\t}\n\t}\n\n\t/**\n\t * Re-enables notifications when popNotificationDelayScope has been called the same number of times as\n\t * pushNotificationDelayScope.\n\t */\n\tpublic popNotificationDelayScope() {\n\t\tif (this.notificationDelayScope === 0) {\n\t\t\tconsole.error(\"Unbalanced push/pop calls.\");\n\t\t}\n\t\tthis.notificationDelayScope--;\n\t\tthis._root._reportDirtinessToView();\n\t}\n\n\t/**\n\t * Process an operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tif (message.type === MessageType.Operation && message.sequenceNumber > this.skipSequenceNumber) {\n\t\t\tconst content: IRemotePropertyTreeMessage = { ...message.contents, sequenceNumber: message.sequenceNumber };\n\t\t\tswitch (content.op) {\n\t\t\t\tcase OpKind.ChangeSet:\n\t\t\t\t\t// If the op originated locally from this client, we've already accounted for it\n\t\t\t\t\t// by advancing the state. Otherwise, advance the PRNG now.\n\t\t\t\t\tthis._applyRemoteChangeSet(cloneDeep(content));\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static prune(\n\t\tminimumSequenceNumber: number,\n\t\tremoteChanges: IPropertyTreeMessage[],\n\t\tunrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage>,\n\t) {\n\t\t// for faster lookup of remote change guids\n\t\tconst remoteChangeMap = new Map<string, number>();\n\t\tremoteChanges.forEach((change, index) => {\n\t\t\tremoteChangeMap.set(change.guid, index);\n\t\t});\n\n\t\t// we will track visited nodes\n\t\tconst visitedUnrebasedRemoteChanges = new Set<string>();\n\t\tconst visitedRemoteChanges = new Set<string>();\n\n\t\tfor (const id of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tconst unrebasedChange = unrebasedRemoteChanges[id];\n\n\t\t\t// we are only interested in changes that are newer than the sequence number\n\t\t\t// and that were not yet visited previously\n\t\t\tif (\n\t\t\t\tunrebasedChange.sequenceNumber >= minimumSequenceNumber &&\n\t\t\t\t!visitedUnrebasedRemoteChanges.has(unrebasedChange.guid)\n\t\t\t) {\n\t\t\t\t// we visited that unrebased change and mark it as visited\n\t\t\t\tvisitedUnrebasedRemoteChanges.add(unrebasedChange.guid);\n\n\t\t\t\tlet visitor = unrebasedChange;\n\t\t\t\t// we will walk along the commit chain until we hit a remote change or a visited unrebased commit\n\t\t\t\t// at that point we can skip since we already traced the rest of the commit chain\n\t\t\t\twhile (\n\t\t\t\t\tvisitor.remoteHeadGuid !== visitor.referenceGuid ||\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.has(visitor.referenceGuid)\n\t\t\t\t) {\n\t\t\t\t\tconst guid = visitor.referenceGuid;\n\t\t\t\t\tif (guid === \"\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// since the change is not in remote it must be in unrebased\n\t\t\t\t\tvisitor = unrebasedRemoteChanges[visitor.referenceGuid];\n\t\t\t\t\tif (!visitor) {\n\t\t\t\t\t\tthrow new Error(`no visitor found for guid \"${guid}\"`);\n\t\t\t\t\t}\n\n\t\t\t\t\tvisitedUnrebasedRemoteChanges.add(visitor.guid);\n\t\t\t\t}\n\t\t\t\t// if we exited the loop because we hit a remote change than add it as visited\n\t\t\t\tif (visitor.remoteHeadGuid === visitor.referenceGuid && remoteChangeMap.has(visitor.referenceGuid)) {\n\t\t\t\t\tvisitedRemoteChanges.add(visitor.referenceGuid);\n\t\t\t\t}\n\n // If we have a change that refers to the start of the history (remoteHeadGuid === \"\"), we have to\n // keep all remote Changes until this change has been processed\n if (visitor.remoteHeadGuid === \"\") {\n visitedRemoteChanges.add(remoteChanges[0].guid);\n }\n\t\t\t}\n\t\t}\n\t\tlet pruned = 0;\n\t\t// we can now filter the unrebased changes by removing any changes\n\t\t// we have not visited at all during our traversal\n\t\tconst prunedUnrebasedRemoteChanges: Record<string, IRemotePropertyTreeMessage> = {};\n\t\tfor (const key of Object.keys(unrebasedRemoteChanges)) {\n\t\t\tif (visitedUnrebasedRemoteChanges.has(key)) {\n\t\t\t\tprunedUnrebasedRemoteChanges[key] = unrebasedRemoteChanges[key];\n\t\t\t} else {\n\t\t\t\tpruned++;\n\t\t\t}\n\t\t}\n\n\t\t// find minimum index\n\t\tconst minIndex = Math.min(...[...visitedRemoteChanges].map((key) => remoteChangeMap.get(key) as number));\n\n\t\tconst prunedRemoteChanges = remoteChanges.slice(minIndex);\n\t\tpruned += minIndex;\n\n\t\treturn {\n\t\t\tremoteChanges: prunedRemoteChanges,\n\t\t\tunrebasedRemoteChanges: prunedUnrebasedRemoteChanges,\n\t\t\tprunedCount: pruned,\n\t\t};\n\t}\n\tpublic pruneHistory() {\n\t\tconst msn = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tconst { remoteChanges, unrebasedRemoteChanges } = SharedPropertyTree.prune(\n\t\t\tmsn,\n\t\t\tthis.remoteChanges,\n\t\t\tthis.unrebasedRemoteChanges,\n\t\t);\n\n\t\tthis.remoteChanges = remoteChanges;\n\t\tthis.unrebasedRemoteChanges = unrebasedRemoteChanges;\n\t}\n\tpublic snapshotCore(serializer: IFluidSerializer): ITree {\n\t\tthis.pruneHistory();\n\t\tconst snapshot: ISnapshot = {\n\t\t\tbranchGuid: this.handle.absolutePath.split(\"/\").pop() as string,\n\t\t\tsummaryMinimumSequenceNumber: this.runtime.deltaManager.minimumSequenceNumber,\n\t\t\tuseMH: this.useMH,\n\t\t\tnumChunks: 0,\n\t\t};\n\n\t\tconst chunks: ITreeEntry[] = [];\n\t\tif (!this.useMH) {\n\t\t\t// If the MH is not used, we have to include the tip view, the remote changes and the received\n\t\t\t// deltas to the summary\n\t\t\tconst summary: ISnapshotSummary = {\n\t\t\t\tremoteTipView: this.remoteTipView,\n\t\t\t\tremoteChanges: this.remoteChanges,\n\t\t\t\tunrebasedRemoteChanges: this.unrebasedRemoteChanges,\n\t\t\t};\n\t\t\tconst chunkSize = 5000 * 1024; // Default limit seems to be 5MB\n\t\t\tlet serializedSummary =\n\t\t\t\tserializer !== undefined ? serializer.stringify(summary, this.handle) : JSON.stringify(summary);\n\n\t\t\t// JSON.stringify does not escape unicode characters. As a consequence,\n\t\t\t// the chunking code below could create chunks which are bigger than the\n\t\t\t// allowed limit after encoding the JSON via UTF8 encoding. To make sure\n\t\t\t// the encoded string stays within the size limit, we replace unicode characters\n\t\t\t// with the cooresponding escapes. This way, it won't change size when encoded as\n\t\t\t// utf8\n\t\t\tserializedSummary = serializedSummary.replace(\n\t\t\t\t/[\\u007F-\\uFFFF]/g,\n\t\t\t\t// eslint-disable-next-line prefer-template\n\t\t\t\t(c) => `\\\\u${(\"0000\" + c.charCodeAt(0).toString(16)).substr(-4)}`,\n\t\t\t);\n\n\t\t\tfor (let pos = 0, i = 0; pos < serializedSummary.length; pos += chunkSize, i++) {\n\t\t\t\tchunks.push({\n\t\t\t\t\tpath: `summaryChunk_${i}`,\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents: serializedSummary.substr(pos, chunkSize),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tsnapshot.numChunks = chunks.length;\n\t\t}\n\n\t\treturn {\n\t\t\tentries: [\n\t\t\t\t{\n\t\t\t\t\tpath: \"properties\",\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tcontents:\n\t\t\t\t\t\t\tserializer !== undefined\n\t\t\t\t\t\t\t\t? serializer.stringify(snapshot, this.handle)\n\t\t\t\t\t\t\t\t: JSON.stringify(snapshot),\n\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...chunks,\n\t\t\t],\n\t\t\tid: undefined,\n\t\t};\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst runtime = this.runtime;\n\t\tconst handleTableChunk = await storage.readBlob(\"properties\");\n\t\tconst utf8 = bufferToString(handleTableChunk, \"utf8\");\n\n\t\tconst serializer = runtime.IFluidSerializer;\n\t\tconst snapshot: ISnapshot = serializer !== undefined ? serializer.parse(utf8) : JSON.parse(utf8);\n\t\tthis.useMH = snapshot.useMH;\n\n\t\ttry {\n\t\t\tif (!snapshot.useMH) {\n\t\t\t\t// We load all chunks\n\t\t\t\tconst chunks: string[] = await Promise.all(\n\t\t\t\t\trange(snapshot.numChunks).map(async (i) => {\n\t\t\t\t\t\treturn bufferToString(await storage.readBlob(`summaryChunk_${i}`), \"utf8\");\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst serializedSummary = chunks.reduce((a, b) => a + b, \"\");\n\t\t\t\tconst snapshotSummary: ISnapshotSummary =\n\t\t\t\t\tserializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);\n\t\t\t\tif (\n\t\t\t\t\tsnapshotSummary.remoteChanges === undefined ||\n\t\t\t\t\tsnapshotSummary.remoteTipView === undefined ||\n\t\t\t\t\tsnapshotSummary.unrebasedRemoteChanges === undefined\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\"Invalid Snapshot.\");\n\t\t\t\t}\n\n\t\t\t\tthis.remoteTipView = snapshotSummary.remoteTipView;\n\t\t\t\tthis.remoteChanges = snapshotSummary.remoteChanges;\n\t\t\t\tthis.unrebasedRemoteChanges = snapshotSummary.unrebasedRemoteChanges;\n\n\t\t\t\tconst isPartialCheckoutActive = !!(this.options.clientFiltering && this.options.paths);\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tthis.remoteTipView = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\tthis.remoteTipView,\n\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.tipView = cloneDeep(this.remoteTipView);\n\n\t\t\t\tthis.skipSequenceNumber = 0;\n\t\t\t} else {\n\t\t\t\tconst { branchGuid, summaryMinimumSequenceNumber } = snapshot;\n\t\t\t\tconst branchResponse = await axios.get(`http://localhost:3000/branch/${branchGuid}`);\n\t\t\t\tthis.headCommitGuid = branchResponse.data.headCommitGuid;\n\t\t\t\tconst {\n\t\t\t\t\tcommit: { meta: commitMetadata },\n\t\t\t\t} = (await axios.get(`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}`)).data;\n\t\t\t\tlet { changeSet: materializedView } = (\n\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${this.headCommitGuid}/materializedView`,\n\t\t\t\t\t)\n\t\t\t\t).data;\n\n\t\t\t\tconst isPartialCheckoutActive = this.options.clientFiltering && this.options.paths;\n\n\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\tmaterializedView = ChangeSetUtils.getFilteredChangeSetByPaths(materializedView, this.options.paths);\n\t\t\t\t}\n\n\t\t\t\tthis.tipView = materializedView;\n\t\t\t\tthis.remoteTipView = cloneDeep(this.tipView);\n\t\t\t\tthis.remoteChanges = [];\n\n\t\t\t\tlet missingDeltas: ISequencedDocumentMessage[] = [];\n\t\t\t\tconst firstDelta = Math.min(commitMetadata.minimumSequenceNumber, summaryMinimumSequenceNumber);\n\t\t\t\tconst lastDelta = commitMetadata.sequenceNumber;\n\n\t\t\t\tconst dm = (this.runtime.deltaManager as any).deltaManager;\n\t\t\t\tawait dm.getDeltas(\"DocumentOpen\", firstDelta, lastDelta, (messages: ISequencedDocumentMessage[]) => {\n\t\t\t\t\tmissingDeltas = messages.filter((x) => x.type === \"op\");\n\t\t\t\t});\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\t\t\tfor (let i = 0; i < missingDeltas.length; i++) {\n\t\t\t\t\tif (missingDeltas[i].sequenceNumber < commitMetadata.sequenceNumber) {\n\t\t\t\t\t\tconst remoteChange: IPropertyTreeMessage\n\t\t\t\t\t\t\t= JSON.parse(missingDeltas[i].contents).contents.contents.content.contents;\n\t\t\t\t\t\tconst { changeSet } = (\n\t\t\t\t\t\t\tawait axios.get(\n\t\t\t\t\t\t\t\t`http://localhost:3000/branch/${branchGuid}/commit/${remoteChange.guid}/changeSet`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t).data;\n\t\t\t\t\t\tremoteChange.changeSet = changeSet;\n\n\t\t\t\t\t\tif (remoteChange) {\n\t\t\t\t\t\t\tif (isPartialCheckoutActive && this.options.paths) {\n\t\t\t\t\t\t\t\tremoteChange.changeSet = ChangeSetUtils.getFilteredChangeSetByPaths(\n\t\t\t\t\t\t\t\t\tremoteChange.changeSet,\n\t\t\t\t\t\t\t\t\tthis.options.paths,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.remoteChanges.push(remoteChange);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.processCore(missingDeltas[i], false, {});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.skipSequenceNumber = lastDelta ?? -1;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tthis.tipView = {};\n\t\t\tthis.remoteTipView = {};\n\t\t\tthis.remoteChanges = [];\n\t\t} finally {\n\t\t\tthis._root.deserialize(this.tipView);\n\t\t\tthis.root.cleanDirty();\n\t\t}\n\t}\n\n\tprotected registerCore() { }\n\tprotected onDisconnect() { }\n\n\tprivate _applyLocalChangeSet(change: IPropertyTreeMessage) {\n\t\tconst changeSetWrapper = new ChangeSet(this.tipView);\n\t\tchangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\tthis.localChanges.push(change);\n\t}\n\n\tprivate _applyRemoteChangeSet(change: IRemotePropertyTreeMessage) {\n\t\tthis.unrebasedRemoteChanges[change.guid] = cloneDeep(change);\n\n\t\t// This is the first message in the history of the document.\n\t\tif (this.remoteChanges.length !== 0) {\n\t\t\trebaseToRemoteChanges(\n\t\t\t\tchange,\n\t\t\t\tthis.getUnrebasedChange.bind(this),\n\t\t\t\tthis.getRebasedChanges.bind(this),\n\t\t\t);\n\t\t}\n\n\t\tthis.remoteChanges.push(change);\n\n\t\t// Apply the remote change set to the remote tip view\n\t\tconst remoteChangeSetWrapper = new ChangeSet(this.remoteTipView);\n\t\tremoteChangeSetWrapper.applyChangeSet(change.changeSet);\n\n\t\t// Rebase the local changes\n\t\tconst pendingChanges = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\tnew ChangeSet(pendingChanges)._toReversibleChangeSet(this.tipView);\n\n\t\tconst changesToTip: SerializedChangeSet = {};\n\t\tconst changesNeeded = this.rebaseLocalChanges(change, pendingChanges, changesToTip);\n\n\t\tif (changesNeeded) {\n\t\t\tthis.pushNotificationDelayScope();\n\t\t\t// Checkout the new tip\n\t\t\tthis._root.applyChangeSet(changesToTip);\n\t\t\tthis._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);\n\t\t\tthis._root.applyChangeSet(pendingChanges);\n\t\t\tthis.popNotificationDelayScope();\n\t\t}\n\n\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t// assert(JSON.stringify(this.root.serialize()) === JSON.stringify(this.tipView));\n\t}\n\n\tgetUnrebasedChange(guid: string) {\n\t\treturn this.unrebasedRemoteChanges[guid];\n\t}\n\n\tgetRebasedChanges(startGuid: string, endGuid?: string) {\n\t\tconst startIndex = findIndex(this.remoteChanges, (c) => c.guid === startGuid);\n if (endGuid !== undefined) {\n const endIndex = findIndex(this.remoteChanges, (c) => c.guid === endGuid);\n\t\t\treturn this.remoteChanges.slice(startIndex + 1, endIndex + 1);\n\t\t}\n\t\treturn this.remoteChanges.slice(startIndex + 1);\n\t}\n\n\tprivate rebaseLocalChanges(\n\t\tchange: IPropertyTreeMessage,\n\t\tpendingChanges: SerializedChangeSet,\n\t\tnewTipDelta: SerializedChangeSet,\n\t): boolean {\n\t\tlet rebaseBaseChangeSet = cloneDeep(change.changeSet);\n\n\t\tconst accumulatedChanges: SerializedChangeSet = {};\n\t\tconst conflicts = [] as any[];\n\n\t\tif (this.localChanges.length > 0 && this.localChanges[0].guid === change.guid) {\n\t\t\t// This is disabled for performance reasons. Only used during debugging\n\t\t\t// assert(JSON.stringify(this.localChanges[0].changeSet) === JSON.stringify(change.changeSet),\n\t\t\t// \"Local change different than rebased remote change.\");\n\n\t\t\t// If we got a confirmation of the commit on the tip of the localChanges array,\n\t\t\t// there will be no update of the tip view at all. We just move it from local changes\n\t\t\t// to remote changes\n\t\t\tthis.localChanges.shift();\n\n\t\t\treturn false;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\t\tfor (let i = 0; i < this.localChanges.length; i++) {\n\t\t\t// Make sure we never receive changes out of order\n\t\t\tconsole.assert(this.localChanges[i].guid !== change.guid);\n\n\t\t\tconst rebaseMetaInformation = new Map();\n\n\t\t\tconst copiedChangeSet = new ChangeSet(cloneDeep(this.localChanges[i].changeSet));\n\t\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\n\t\t\tcopiedChangeSet.toInverseChangeSet();\n\t\t\tcopiedChangeSet.applyChangeSet(rebaseBaseChangeSet);\n\t\t\tcopiedChangeSet.applyChangeSet(this.localChanges[i].changeSet, {\n\t\t\t\tapplyAfterMetaInformation: rebaseMetaInformation,\n\t\t\t});\n\t\t\trebaseBaseChangeSet = copiedChangeSet.getSerializedChangeSet();\n\n\t\t\tnew ChangeSet(accumulatedChanges).applyChangeSet(this.localChanges[i].changeSet);\n\t\t}\n\n\t\t// Compute the inverse of the pending changes and store the result in newTipDelta\n\t\tconst pendingChangesRebaseMetaInformation = new Map();\n\t\tconst deltaToTipCS = new ChangeSet(newTipDelta);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges);\n\t\tdeltaToTipCS.toInverseChangeSet();\n\n\t\t// Perform a rebase of the pending changes\n\t\tnew ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(pendingChanges, conflicts, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Compute the delta between the old tip (including pending changes)\n\t\t// and the new tip (not including the rebased pending changes)\n\t\tdeltaToTipCS.applyChangeSet(rebaseBaseChangeSet);\n\t\tdeltaToTipCS.applyChangeSet(pendingChanges, {\n\t\t\tapplyAfterMetaInformation: pendingChangesRebaseMetaInformation,\n\t\t});\n\n\t\t// Update the tip view\n\t\tif (!this.tipView) {\n this.tipView = cloneDeep(this.remoteTipView);\n const changeSet = new ChangeSet(this.tipView);\n changeSet.applyChangeSet(accumulatedChanges);\n } else {\n new ChangeSet(this.tipView).applyChangeSet(newTipDelta);\n }\n\n\t\treturn true;\n\t}\n\n\tprotected applyStashedOp() {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/property-dds",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "definition of the property distributed data store",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -31,30 +31,30 @@
|
|
|
31
31
|
"tsc": "tsc"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@fluid-experimental/property-changeset": "^0.
|
|
35
|
-
"@fluid-experimental/property-properties": "^0.
|
|
34
|
+
"@fluid-experimental/property-changeset": "^0.48.0",
|
|
35
|
+
"@fluid-experimental/property-properties": "^0.48.0",
|
|
36
36
|
"@fluidframework/common-utils": "^0.32.1",
|
|
37
37
|
"@fluidframework/core-interfaces": "^0.39.7",
|
|
38
|
-
"@fluidframework/datastore-definitions": "^0.
|
|
38
|
+
"@fluidframework/datastore-definitions": "^0.48.0",
|
|
39
39
|
"@fluidframework/protocol-definitions": "^0.1024.0",
|
|
40
|
-
"@fluidframework/shared-object-base": "^0.
|
|
40
|
+
"@fluidframework/shared-object-base": "^0.48.0",
|
|
41
41
|
"axios": "^0.21.1",
|
|
42
42
|
"lodash": "^4.17.21",
|
|
43
43
|
"uuid": "^8.3.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@fluid-experimental/property-common": "^0.
|
|
46
|
+
"@fluid-experimental/property-common": "^0.48.0",
|
|
47
47
|
"@fluidframework/build-common": "^0.23.0",
|
|
48
48
|
"@fluidframework/container-definitions": "^0.39.8",
|
|
49
49
|
"@fluidframework/driver-definitions": "^0.39.6",
|
|
50
50
|
"@fluidframework/eslint-config-fluid": "^0.23.0",
|
|
51
|
-
"@fluidframework/local-driver": "^0.
|
|
52
|
-
"@fluidframework/mocha-test-setup": "^0.
|
|
53
|
-
"@fluidframework/runtime-utils": "^0.
|
|
54
|
-
"@fluidframework/sequence": "^0.
|
|
55
|
-
"@fluidframework/server-local-server": "^0.
|
|
56
|
-
"@fluidframework/test-runtime-utils": "^0.
|
|
57
|
-
"@fluidframework/test-utils": "^0.
|
|
51
|
+
"@fluidframework/local-driver": "^0.48.0",
|
|
52
|
+
"@fluidframework/mocha-test-setup": "^0.48.0",
|
|
53
|
+
"@fluidframework/runtime-utils": "^0.48.0",
|
|
54
|
+
"@fluidframework/sequence": "^0.48.0",
|
|
55
|
+
"@fluidframework/server-local-server": "^0.1031.0-37526",
|
|
56
|
+
"@fluidframework/test-runtime-utils": "^0.48.0",
|
|
57
|
+
"@fluidframework/test-utils": "^0.48.0",
|
|
58
58
|
"@microsoft/api-extractor": "^7.16.1",
|
|
59
59
|
"@types/mocha": "^8.2.2",
|
|
60
60
|
"@typescript-eslint/eslint-plugin": "~4.14.0",
|
package/src/propertyTree.ts
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/* eslint-disable import/no-internal-modules */
|
|
7
|
+
import isEmpty from "lodash/isEmpty";
|
|
8
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
9
|
+
import findIndex from "lodash/findIndex";
|
|
10
|
+
import range from "lodash/range";
|
|
11
|
+
|
|
6
12
|
import {
|
|
7
13
|
ISequencedDocumentMessage,
|
|
8
14
|
ITree,
|
|
@@ -31,7 +37,6 @@ import {
|
|
|
31
37
|
import { PropertyFactory, BaseProperty, NodeProperty } from "@fluid-experimental/property-properties";
|
|
32
38
|
|
|
33
39
|
import { v4 as uuidv4 } from "uuid";
|
|
34
|
-
import _ from "lodash";
|
|
35
40
|
import axios from "axios";
|
|
36
41
|
import { PropertyTreeFactory } from "./propertyTreeFactory";
|
|
37
42
|
|
|
@@ -160,7 +165,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
160
165
|
public _reportDirtinessToView() {
|
|
161
166
|
const changes = this._root._serialize(true, false, BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);
|
|
162
167
|
const _changeSet = new ChangeSet(changes);
|
|
163
|
-
if (!
|
|
168
|
+
if (!isEmpty(_changeSet.getSerializedChangeSet())) {
|
|
164
169
|
this.emit("localModification", _changeSet);
|
|
165
170
|
}
|
|
166
171
|
this._root.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY);
|
|
@@ -192,7 +197,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
192
197
|
doSubmit = metadata !== undefined;
|
|
193
198
|
}
|
|
194
199
|
|
|
195
|
-
if (doSubmit || !
|
|
200
|
+
if (doSubmit || !isEmpty(changes)) {
|
|
196
201
|
this.applyChangeSet(changes, metadata || {});
|
|
197
202
|
this.root.cleanDirty();
|
|
198
203
|
}
|
|
@@ -221,7 +226,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
221
226
|
|
|
222
227
|
// Queue the op for transmission to the Fluid service.
|
|
223
228
|
if (this.transmissionsHaveBeenStopped) {
|
|
224
|
-
this.enqueuedMessages.push(
|
|
229
|
+
this.enqueuedMessages.push(cloneDeep(change));
|
|
225
230
|
} else {
|
|
226
231
|
this.submitLocalMessage(change);
|
|
227
232
|
}
|
|
@@ -277,7 +282,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
277
282
|
case OpKind.ChangeSet:
|
|
278
283
|
// If the op originated locally from this client, we've already accounted for it
|
|
279
284
|
// by advancing the state. Otherwise, advance the PRNG now.
|
|
280
|
-
this._applyRemoteChangeSet(
|
|
285
|
+
this._applyRemoteChangeSet(cloneDeep(content));
|
|
281
286
|
break;
|
|
282
287
|
default:
|
|
283
288
|
break;
|
|
@@ -459,13 +464,13 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
459
464
|
try {
|
|
460
465
|
if (!snapshot.useMH) {
|
|
461
466
|
// We load all chunks
|
|
462
|
-
const chunks = await Promise.all(
|
|
463
|
-
|
|
467
|
+
const chunks: string[] = await Promise.all(
|
|
468
|
+
range(snapshot.numChunks).map(async (i) => {
|
|
464
469
|
return bufferToString(await storage.readBlob(`summaryChunk_${i}`), "utf8");
|
|
465
470
|
}),
|
|
466
471
|
);
|
|
467
472
|
|
|
468
|
-
const serializedSummary =
|
|
473
|
+
const serializedSummary = chunks.reduce((a, b) => a + b, "");
|
|
469
474
|
const snapshotSummary: ISnapshotSummary =
|
|
470
475
|
serializer !== undefined ? serializer.parse(serializedSummary) : JSON.parse(serializedSummary);
|
|
471
476
|
if (
|
|
@@ -487,7 +492,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
487
492
|
this.options.paths,
|
|
488
493
|
);
|
|
489
494
|
}
|
|
490
|
-
this.tipView =
|
|
495
|
+
this.tipView = cloneDeep(this.remoteTipView);
|
|
491
496
|
|
|
492
497
|
this.skipSequenceNumber = 0;
|
|
493
498
|
} else {
|
|
@@ -510,7 +515,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
510
515
|
}
|
|
511
516
|
|
|
512
517
|
this.tipView = materializedView;
|
|
513
|
-
this.remoteTipView =
|
|
518
|
+
this.remoteTipView = cloneDeep(this.tipView);
|
|
514
519
|
this.remoteChanges = [];
|
|
515
520
|
|
|
516
521
|
let missingDeltas: ISequencedDocumentMessage[] = [];
|
|
@@ -571,7 +576,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
571
576
|
}
|
|
572
577
|
|
|
573
578
|
private _applyRemoteChangeSet(change: IRemotePropertyTreeMessage) {
|
|
574
|
-
this.unrebasedRemoteChanges[change.guid] =
|
|
579
|
+
this.unrebasedRemoteChanges[change.guid] = cloneDeep(change);
|
|
575
580
|
|
|
576
581
|
// This is the first message in the history of the document.
|
|
577
582
|
if (this.remoteChanges.length !== 0) {
|
|
@@ -613,9 +618,9 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
613
618
|
}
|
|
614
619
|
|
|
615
620
|
getRebasedChanges(startGuid: string, endGuid?: string) {
|
|
616
|
-
const startIndex =
|
|
617
|
-
|
|
618
|
-
|
|
621
|
+
const startIndex = findIndex(this.remoteChanges, (c) => c.guid === startGuid);
|
|
622
|
+
if (endGuid !== undefined) {
|
|
623
|
+
const endIndex = findIndex(this.remoteChanges, (c) => c.guid === endGuid);
|
|
619
624
|
return this.remoteChanges.slice(startIndex + 1, endIndex + 1);
|
|
620
625
|
}
|
|
621
626
|
return this.remoteChanges.slice(startIndex + 1);
|
|
@@ -626,7 +631,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
626
631
|
pendingChanges: SerializedChangeSet,
|
|
627
632
|
newTipDelta: SerializedChangeSet,
|
|
628
633
|
): boolean {
|
|
629
|
-
let rebaseBaseChangeSet =
|
|
634
|
+
let rebaseBaseChangeSet = cloneDeep(change.changeSet);
|
|
630
635
|
|
|
631
636
|
const accumulatedChanges: SerializedChangeSet = {};
|
|
632
637
|
const conflicts = [] as any[];
|
|
@@ -651,7 +656,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
651
656
|
|
|
652
657
|
const rebaseMetaInformation = new Map();
|
|
653
658
|
|
|
654
|
-
const copiedChangeSet = new ChangeSet(
|
|
659
|
+
const copiedChangeSet = new ChangeSet(cloneDeep(this.localChanges[i].changeSet));
|
|
655
660
|
new ChangeSet(rebaseBaseChangeSet)._rebaseChangeSet(this.localChanges[i].changeSet, conflicts, {
|
|
656
661
|
applyAfterMetaInformation: rebaseMetaInformation,
|
|
657
662
|
});
|
|
@@ -686,7 +691,7 @@ export class SharedPropertyTree extends SharedObject {
|
|
|
686
691
|
|
|
687
692
|
// Update the tip view
|
|
688
693
|
if (!this.tipView) {
|
|
689
|
-
this.tipView =
|
|
694
|
+
this.tipView = cloneDeep(this.remoteTipView);
|
|
690
695
|
const changeSet = new ChangeSet(this.tipView);
|
|
691
696
|
changeSet.applyChangeSet(accumulatedChanges);
|
|
692
697
|
} else {
|