@fluidframework/sequence 2.0.0-rc.3.0.2 → 2.0.0-rc.3.0.4
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/.eslintrc.cjs +29 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +6 -1
- package/dist/sequence.js.map +1 -1
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +8 -2
- package/lib/sequence.js.map +1 -1
- package/lib/sharedString.d.ts.map +1 -1
- package/lib/sharedString.js.map +1 -1
- package/package.json +15 -15
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +9 -1
- package/src/sharedString.ts +2 -0
package/.eslintrc.cjs
CHANGED
|
@@ -15,4 +15,33 @@ module.exports = {
|
|
|
15
15
|
"@typescript-eslint/no-use-before-define": "off",
|
|
16
16
|
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
17
17
|
},
|
|
18
|
+
settings: {
|
|
19
|
+
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
|
|
20
|
+
"import/parsers": {
|
|
21
|
+
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
|
|
22
|
+
},
|
|
23
|
+
"import/resolver": {
|
|
24
|
+
typescript: {
|
|
25
|
+
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
|
|
26
|
+
conditionNames: [
|
|
27
|
+
"allow-ff-test-exports",
|
|
28
|
+
|
|
29
|
+
// Default condition names below, see https://www.npmjs.com/package/eslint-import-resolver-typescript#conditionnames
|
|
30
|
+
"types",
|
|
31
|
+
"import",
|
|
32
|
+
|
|
33
|
+
// APF: https://angular.io/guide/angular-package-format
|
|
34
|
+
"esm2020",
|
|
35
|
+
"es2020",
|
|
36
|
+
"es2015",
|
|
37
|
+
|
|
38
|
+
"require",
|
|
39
|
+
"node",
|
|
40
|
+
"node-addons",
|
|
41
|
+
"browser",
|
|
42
|
+
"default",
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
18
47
|
};
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/sequence";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-rc.3.0.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-rc.3.0.4";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/sequence";
|
|
11
|
-
exports.pkgVersion = "2.0.0-rc.3.0.
|
|
11
|
+
exports.pkgVersion = "2.0.0-rc.3.0.4";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,0BAA0B,CAAC;AACrC,QAAA,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-rc.3.0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,0BAA0B,CAAC;AACrC,QAAA,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-rc.3.0.4\";\n"]}
|
package/dist/sequence.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAU,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,MAAM,EACN,YAAY,
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAU,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,MAAM,EACN,YAAY,EAIZ,kBAAkB,EAKlB,iBAAiB,EACjB,QAAQ,EACR,cAAc,EACd,sBAAsB,EAEtB,yBAAyB,EACzB,WAAW,EACX,iBAAiB,EACjB,aAAa,EAGb,iBAAiB,EAQjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,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CHANGED
|
@@ -63,6 +63,7 @@ class SharedSegmentSequence extends internal_4.SharedObject {
|
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
case internal_2.MergeTreeDeltaType.OBLITERATE: {
|
|
66
|
+
// eslint-disable-next-line import/no-deprecated
|
|
66
67
|
const lastRem = ops[ops.length - 1];
|
|
67
68
|
if (lastRem?.pos1 === r.position) {
|
|
68
69
|
(0, internal_1.assert)(lastRem.pos2 !== undefined, 0x874 /* pos2 should not be undefined here */);
|
|
@@ -116,6 +117,7 @@ class SharedSegmentSequence extends internal_4.SharedObject {
|
|
|
116
117
|
/** `Deferred` that triggers once the object is loaded */
|
|
117
118
|
this.loadedDeferred = new internal_1.Deferred();
|
|
118
119
|
// cache out going ops created when partial loading
|
|
120
|
+
// eslint-disable-next-line import/no-deprecated
|
|
119
121
|
this.loadedDeferredOutgoingOps = [];
|
|
120
122
|
// cache incoming ops that arrive when partial loading
|
|
121
123
|
this.deferIncomingOps = true;
|
|
@@ -179,6 +181,7 @@ class SharedSegmentSequence extends internal_4.SharedObject {
|
|
|
179
181
|
* release, as group ops are redundant with the native batching capabilities
|
|
180
182
|
* of the runtime
|
|
181
183
|
*/
|
|
184
|
+
// eslint-disable-next-line import/no-deprecated
|
|
182
185
|
groupOperation(groupOp) {
|
|
183
186
|
this.guardReentrancy(() => this.client.localTransaction(groupOp));
|
|
184
187
|
}
|
|
@@ -413,7 +416,9 @@ class SharedSegmentSequence extends internal_4.SharedObject {
|
|
|
413
416
|
(0, internal_1.assert)(originalRefSeq !== undefined, 0x8bb /* Expected a recorded refSeq when resubmitting an op */);
|
|
414
417
|
this.useResubmitRefSeq(originalRefSeq, () => {
|
|
415
418
|
if (!this.intervalCollections.tryResubmitMessage(content, localOpMetadata)) {
|
|
416
|
-
this.submitSequenceMessage(this.client.regeneratePendingOp(content,
|
|
419
|
+
this.submitSequenceMessage(this.client.regeneratePendingOp(content,
|
|
420
|
+
// eslint-disable-next-line import/no-deprecated
|
|
421
|
+
localOpMetadata));
|
|
417
422
|
}
|
|
418
423
|
});
|
|
419
424
|
}
|
package/dist/sequence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+DAA8D;AAE9D,kEAAuE;AAMvE,kEA2B6C;AAC7C,+EAA8F;AAE9F,qEAAoG;AAEpG,0EAA2E;AAC3E,uEAA2F;AAC3F,4EAAuC;AAEvC,mEAAmG;AACnG,yEAAkF;AAGlF,mEAAuF;AAGvF,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,WAAW,GAAG,SAAS,CAAC;AAmD9B;;GAEG;AACH,MAAsB,qBACrB,SAAQ,uBAA0C;IAGlD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;IACpC,CAAC;IAgBO,MAAM,CAAC,kBAAkB,CAAC,KAAyB;QAC1D,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE;YAC7B,QAAQ,KAAK,CAAC,cAAc,EAAE;gBAC7B,KAAK,6BAAkB,CAAC,QAAQ,CAAC,CAAC;oBACjC,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAA0B,CAAC;oBAClE,MAAM,KAAK,GAAgB,EAAE,CAAC;oBAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE;wBAChD,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;qBACjD;oBACD,IACC,YAAY;wBACZ,YAAY,CAAC,IAAI,KAAK,CAAC,CAAC,QAAQ;wBAChC,IAAA,0BAAe,EAAC,YAAY,CAAC,KAAK,EAAE,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I,CAAC,qBAAqB,CAAC;QAC1D,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;QACpC,IAAI;YACH,QAAQ,EAAE,CAAC;SACX;gBAAS;YACT,IAAI,CAAC,qBAAqB,GAAG,sBAAsB,CAAC;SACpD;IACF,CAAC;CACD;AAh0BD,sDAg0BC;AAED,SAAS,wBAAwB,CAChC,YAAqC;IAErC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,SAAS,gBAAgB,CAAI,QAAiB;QAC7C,IAAI,KAAK,GAAG,CAAC,EAAE;YACd,YAAY,CAAC,KAAK,CAAC,CAAC;SACpB;QACD,KAAK,EAAE,CAAC;QACR,IAAI;YACH,OAAO,QAAQ,EAAE,CAAC;SAClB;gBAAS;YACT,KAAK,EAAE,CAAC;SACR;IACF,CAAC;IAED,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;GAEG;AACH,SAAgB,yBAAyB;IACxC,mBAAmB,GAAG,CAAC,CAAC;AACzB,CAAC;AAFD,8DAEC;AAED,MAAM,sBAAsB,GAAG,2CAA2C,CAAC;AAC3E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,EAAE;IACxD,MAAM,IAAI,uBAAY,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIChannelStorageService,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\tIMergeTreeGroupMsg,\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tLocalReferencePosition,\n\tMergeTreeDeltaType,\n\tMergeTreeRevertibleDriver,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\tSegmentGroup,\n\tSlidingPreference,\n\tcreateAnnotateRangeOp, // eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertOp,\n\tcreateObliterateRangeOp,\n\tcreateRemoveRangeOp,\n\tmatchProperties,\n} from \"@fluidframework/merge-tree/internal\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ISummaryTreeWithStats, ITelemetryContext } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\nimport { SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { LoggingError, createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\n\nimport { IIntervalCollection, SequenceIntervalCollectionValueType } from \"./intervalCollection.js\";\nimport { IMapOperation, IntervalCollectionMap } from \"./intervalCollectionMap.js\";\nimport { IMapMessageLocalMetadata, IValueChanged } from \"./intervalCollectionMapInterfaces.js\";\nimport { SequenceInterval } from \"./intervals/index.js\";\nimport { SequenceDeltaEvent, SequenceMaintenanceEvent } from \"./sequenceDeltaEvent.js\";\nimport { ISharedIntervalCollection } from \"./sharedIntervalCollection.js\";\n\nconst snapshotFileName = \"header\";\nconst contentPath = \"content\";\n\n/**\n * Events emitted in response to changes to the sequence data.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"sequenceDelta\"\n *\n * The sequenceDelta event is emitted when segments are inserted, annotated, or removed.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n *\n * ### \"maintenance\"\n *\n * The maintenance event is emitted when segments are modified during merge-tree maintenance.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n * @alpha\n */\nexport interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {\n\t(\n\t\tevent: \"createIntervalCollection\",\n\t\tlistener: (label: string, local: boolean, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"sequenceDelta\",\n\t\tlistener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n}\n\n/**\n * @alpha\n */\nexport abstract class SharedSegmentSequence<T extends ISegment>\n\textends SharedObject<ISharedSegmentSequenceEvents>\n\timplements ISharedIntervalCollection<SequenceInterval>, MergeTreeRevertibleDriver\n{\n\tget loaded(): Promise<void> {\n\t\treturn this.loadedDeferred.promise;\n\t}\n\n\t/**\n\t * This is a safeguard to avoid problematic reentrancy of local ops. This type of scenario occurs if the user of SharedString subscribes\n\t * to the `sequenceDelta` event and uses the callback for a local op to submit further local ops.\n\t * Historically (before 2.0.0-internal.6.1.0), doing so would result in eventual consistency issues or a corrupted document.\n\t * These issues were fixed in #16815 which makes such reentrancy no different from applying the ops in order but not from within the change events,\n\t * but there is still little test coverage for reentrant scenarios.\n\t * Additionally, applications submitting ops from inside change events need to take extreme care that their data models also support reentrancy.\n\t * Since this is likely not the case, by default SharedString throws when encountering reentrant ops.\n\t *\n\t * An application using SharedString which explicitly wants to opt in to allowing reentrancy anyway can set `sharedStringPreventReentrancy`\n\t * on the data store options to `false`.\n\t */\n\tprotected guardReentrancy: <TRet>(callback: () => TRet) => TRet;\n\n\tprivate static createOpsFromDelta(event: SequenceDeltaEvent): IMergeTreeDeltaOp[] {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfor (const r of event.ranges) {\n\t\t\tswitch (event.deltaOperation) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tconst lastAnnotate = ops[ops.length - 1] as IMergeTreeAnnotateMsg;\n\t\t\t\t\tconst props: PropertySet = {};\n\t\t\t\t\tfor (const key of Object.keys(r.propertyDeltas)) {\n\t\t\t\t\t\tprops[key] = r.segment.properties?.[key] ?? null;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastAnnotate &&\n\t\t\t\t\t\tlastAnnotate.pos2 === r.position &&\n\t\t\t\t\t\tmatchProperties(lastAnnotate.props, props)\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastAnnotate.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateAnnotateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tops.push(createInsertOp(r.position, r.segment.clone().toJSONObject()));\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeRemoveMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x3ff /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateRemoveRangeOp(r.position, r.position + r.segment.cachedLength),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x874 /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateObliterateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\treturn ops;\n\t}\n\n\t/**\n\t * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.\n\t * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process\n\t * incoming leave/join ops before putting an op that this DDS submits over the wire.\n\t *\n\t * E.g. SharedString submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime\n\t * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber\n\t * on the SharedString op is 11.\n\t *\n\t * The reference sequence numbers placed in this queue are also not accurate for stashed ops due to how the applyStashedOp\n\t * flow works at the runtime level. This is a legitimate bug, and AB#6602 tracks one way to fix it (stop reaching all the way\n\t * to deltaManager's lastSequenceNumber to obtain refSeq, instead leveraging some analogous notion on the container or datastore\n\t * runtime).\n\t */\n\tprivate readonly inFlightRefSeqs = new Deque<number>();\n\n\tprivate ongoingResubmitRefSeq: number | undefined;\n\n\t/**\n\t * Gets the reference sequence number (i.e. sequence number of the runtime's last processed op) for an op submitted\n\t * in the current context.\n\t *\n\t * This value can be optionally overridden using `useResubmitRefSeq`.\n\t * IntervalCollection's resubmit logic currently relies on preserving merge information from when the op was originally submitted,\n\t * even if the op is resubmitted more than once. Thus during resubmit, `inFlightRefSeqs` gets populated with the\n\t * original refSeq rather than the refSeq at the time of reconnection.\n\t *\n\t * @remarks - In some not fully understood cases, the runtime may process incoming ops before putting an op that this\n\t * DDS submits over the wire. See `inFlightRefSeqs` for more details.\n\t */\n\tprivate get currentRefSeq() {\n\t\treturn this.ongoingResubmitRefSeq ?? this.runtime.deltaManager.lastSequenceNumber;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprotected client: Client;\n\t/** `Deferred` that triggers once the object is loaded */\n\tprotected loadedDeferred = new Deferred<void>();\n\t// cache out going ops created when partial loading\n\tprivate readonly loadedDeferredOutgoingOps: [IMergeTreeOp, SegmentGroup | SegmentGroup[]][] =\n\t\t[];\n\t// cache incoming ops that arrive when partial loading\n\tprivate deferIncomingOps = true;\n\tprivate readonly loadedDeferredIncomingOps: ISequencedDocumentMessage[] = [];\n\n\tprivate messagesSinceMSNChange: ISequencedDocumentMessage[] = [];\n\tprivate readonly intervalCollections: IntervalCollectionMap<SequenceInterval>;\n\tconstructor(\n\t\tprivate readonly dataStoreRuntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly segmentFromSpec: (spec: IJSONSegment) => ISegment,\n\t) {\n\t\tsuper(id, dataStoreRuntime, attributes, \"fluid_sequence_\");\n\n\t\tconst getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);\n\t\tthis.guardReentrancy =\n\t\t\tdataStoreRuntime.options.sharedStringPreventReentrancy ?? true\n\t\t\t\t? ensureNoReentrancy\n\t\t\t\t: createReentrancyDetector((depth) => {\n\t\t\t\t\t\tif (totalReentrancyLogs > 0) {\n\t\t\t\t\t\t\ttotalReentrancyLogs--;\n\t\t\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t\t\t{ eventName: \"LocalOpReentry\", depth },\n\t\t\t\t\t\t\t\tnew LoggingError(reentrancyErrorMessage),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t });\n\n\t\tthis.loadedDeferred.promise.catch((error) => {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"SequenceLoadFailed\" }, error);\n\t\t});\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tthis.client = new Client(\n\t\t\tsegmentFromSpec,\n\t\t\tcreateChildLogger({\n\t\t\t\tlogger: this.logger,\n\t\t\t\tnamespace: \"SharedSegmentSequence.MergeTreeClient\",\n\t\t\t}),\n\t\t\tdataStoreRuntime.options,\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.client.prependListener(\"delta\", (opArgs, deltaArgs) => {\n\t\t\tconst event = new SequenceDeltaEvent(opArgs, deltaArgs, this.client);\n\t\t\tif (event.isLocal) {\n\t\t\t\tthis.submitSequenceMessage(opArgs.op);\n\t\t\t}\n\t\t\tthis.emit(\"sequenceDelta\", event, this);\n\t\t});\n\n\t\tthis.client.on(\"maintenance\", (args, opArgs) => {\n\t\t\tthis.emit(\"maintenance\", new SequenceMaintenanceEvent(opArgs, args, this.client), this);\n\t\t});\n\n\t\tthis.intervalCollections = new IntervalCollectionMap(\n\t\t\tthis.serializer,\n\t\t\tthis.handle,\n\t\t\t(op, localOpMetadata) => {\n\t\t\t\tif (!this.isAttached()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata);\n\t\t\t},\n\t\t\tnew SequenceIntervalCollectionValueType(),\n\t\t\tdataStoreRuntime.options,\n\t\t);\n\t}\n\n\t/**\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tpublic removeRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.removeRangeLocal(start, end));\n\t}\n\n\t/**\n\t * Obliterate is similar to remove, but differs in that segments concurrently\n\t * inserted into an obliterated range will also be removed\n\t *\n\t * @param start - The inclusive start of the range to obliterate\n\t * @param end - The exclusive end of the range to obliterate\n\t */\n\tpublic obliterateRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.obliterateRangeLocal(start, end));\n\t}\n\n\t/**\n\t * @deprecated The ability to create group ops will be removed in an upcoming\n\t * release, as group ops are redundant with the native batching capabilities\n\t * of the runtime\n\t */\n\tpublic groupOperation(groupOp: IMergeTreeGroupMsg) {\n\t\tthis.guardReentrancy(() => this.client.localTransaction(groupOp));\n\t}\n\n\t/**\n\t * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.\n\t * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.\n\t * @param pos - Character position (index) into the current local view of the SharedString.\n\t */\n\tpublic getContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\treturn this.client.getContainingSegment<T>(pos);\n\t}\n\n\t/**\n\t * Returns the length of the current sequence for the client\n\t */\n\tpublic getLength() {\n\t\treturn this.client.getLength();\n\t}\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this sequence\n\t * @param segment - The segment to get the position of\n\t */\n\tpublic getPosition(segment: ISegment): number {\n\t\treturn this.client.getPosition(segment);\n\t}\n\n\t/**\n\t * Annotates the range with the provided properties\n\t *\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t *\n\t */\n\tpublic annotateRange(start: number, end: number, props: PropertySet): void {\n\t\tthis.guardReentrancy(() => this.client.annotateRangeLocal(start, end, props));\n\t}\n\n\tpublic getPropertiesAtPosition(pos: number) {\n\t\treturn this.client.getPropertiesAtPosition(pos);\n\t}\n\n\tpublic getRangeExtentsOfPosition(pos: number) {\n\t\treturn this.client.getRangeExtentsOfPosition(pos);\n\t}\n\n\t/**\n\t * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include\n\t * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t */\n\tpublic createLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this.client.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of `ReferenceType`. To handle this case specifically, one may wish\n\t * to look at the segment returned by `ReferencePosition.getSegment`.\n\t */\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this.client.localReferencePositionToPosition(lref);\n\t}\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this SharedString.\n\t */\n\tpublic removeLocalReferencePosition(lref: LocalReferencePosition) {\n\t\treturn this.client.removeLocalReferencePosition(lref);\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\treturn this.client.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tremoteClientId,\n\t\t);\n\t}\n\n\tprivate submitSequenceMessage(message: IMergeTreeOp) {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\n\t\tconst metadata = this.client.peekPendingSegmentGroups(\n\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t);\n\n\t\t// if loading isn't complete, we need to cache\n\t\t// local ops until loading is complete, and then\n\t\t// they will be present\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\tthis.loadedDeferredOutgoingOps.push(metadata ? [message, metadata] : (message as any));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(message, metadata);\n\t\t}\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition) {\n\t\treturn this.client.posFromRelativePos(relativePos);\n\t}\n\n\t/**\n\t * Walk the underlying segments of the sequence.\n\t * The walked segments may extend beyond the range if the segments cross the\n\t * ranges start or end boundaries.\n\t *\n\t * Set split range to true to ensure only segments within the range are walked.\n\t *\n\t * @param handler - The function to handle each segment. Traversal ends if\n\t * this function returns true.\n\t * @param start - Optional. The start of range walk.\n\t * @param end - Optional. The end of range walk\n\t * @param accum - Optional. An object that will be passed to the handler for accumulation\n\t * @param splitRange - Optional. Splits boundary segments on the range boundaries\n\t */\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis.client.walkSegments(handler, start, end, accum as TClientData, splitRange);\n\t}\n\n\t/**\n\t * @returns The most recent sequence number which has been acked by the server and processed by this\n\t * SharedSegmentSequence.\n\t */\n\tpublic getCurrentSeq() {\n\t\treturn this.client.getCurrentSeq();\n\t}\n\n\t/**\n\t * Inserts a segment directly before a `ReferencePosition`.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertAtReferencePosition(pos: ReferencePosition, segment: T): void {\n\t\tthis.guardReentrancy(() => this.client.insertAtReferencePositionLocal(pos, segment));\n\t}\n\t/**\n\t * Inserts a segment\n\t * @param start - The position to insert the segment at\n\t * @param spec - The segment to inserts spec\n\t */\n\tpublic insertFromSpec(pos: number, spec: IJSONSegment): void {\n\t\tconst segment = this.segmentFromSpec(spec);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Retrieves the interval collection keyed on `label`. If no such interval collection exists,\n\t * creates one.\n\t */\n\tpublic getIntervalCollection(label: string): IIntervalCollection<SequenceInterval> {\n\t\treturn this.intervalCollections.get(label);\n\t}\n\n\t/**\n\t * @returns An iterable object that enumerates the IntervalCollection labels.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const iter = this.getIntervalCollectionKeys();\n\t * for (key of iter)\n\t * const collection = this.getIntervalCollection(key);\n\t * ...\n\t * ```\n\t */\n\tpublic getIntervalCollectionLabels(): IterableIterator<string> {\n\t\treturn this.intervalCollections.keys();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}\n\t */\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// conditionally write the interval collection blob\n\t\t// only if it has entries\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tbuilder.addBlob(snapshotFileName, this.intervalCollections.serialize(serializer));\n\t\t}\n\n\t\tbuilder.addWithStats(contentPath, this.summarizeMergeTree(serializer));\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer over the GC data for this SharedMatrix.\n\t * All the IFluidHandle's represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: IFluidSerializer) {\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tthis.intervalCollections.serialize(serializer);\n\t\t}\n\n\t\tthis.client.serializeGCData(this.handle, serializer);\n\t}\n\n\t/**\n\t * Replace the range specified from start to end with the provided segment\n\t * This is done by inserting the segment at the end of the range, followed\n\t * by removing the contents of the range\n\t * For a zero or reverse range (start \\>= end), insert at end do not remove anything\n\t * @param start - The start of the range to replace\n\t * @param end - The end of the range to replace\n\t * @param segment - The segment that will replace the range\n\t */\n\tprotected replaceRange(start: number, end: number, segment: ISegment): void {\n\t\t// Insert at the max end of the range when start > end, but still remove the range later\n\t\tconst insertIndex: number = Math.max(start, end);\n\n\t\t// Insert first, so local references can slide to the inserted seg if any\n\t\tconst insert = this.guardReentrancy(() =>\n\t\t\tthis.client.insertSegmentLocal(insertIndex, segment),\n\t\t);\n\n\t\tif (insert && start < end) {\n\t\t\tthis.removeRange(start, end);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n\t */\n\tprotected onConnect() {\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n\t */\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.shift();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0x8bb /* Expected a recorded refSeq when resubmitting an op */,\n\t\t);\n\t\tthis.useResubmitRefSeq(originalRefSeq, () => {\n\t\t\tif (\n\t\t\t\t!this.intervalCollections.tryResubmitMessage(\n\t\t\t\t\tcontent,\n\t\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.submitSequenceMessage(\n\t\t\t\t\tthis.client.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\tif (await storage.contains(snapshotFileName)) {\n\t\t\tconst blob = await storage.readBlob(snapshotFileName);\n\t\t\tconst header = bufferToString(blob, \"utf8\");\n\t\t\tthis.intervalCollections.populate(header);\n\t\t}\n\n\t\ttry {\n\t\t\t// this will load the header, and return a promise\n\t\t\t// that will resolve when the body is loaded\n\t\t\t// and the catchup ops are available.\n\t\t\tconst { catchupOpsP } = await this.client.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, contentPath),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\t// setup a promise to process the\n\t\t\t// catch up ops, and finishing the loading process\n\t\t\tconst loadCatchUpOps = catchupOpsP\n\t\t\t\t.then((msgs) => {\n\t\t\t\t\tmsgs.forEach((m) => {\n\t\t\t\t\t\tconst collabWindow = this.client.getCollabWindow();\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tm.minimumSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.referenceSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.sequenceNumber <= collabWindow.minSeq ||\n\t\t\t\t\t\t\t// sequenceNumber could be the same if messages are part of a grouped batch\n\t\t\t\t\t\t\tm.sequenceNumber < collabWindow.currentSeq\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Invalid catchup operations in snapshot: ${JSON.stringify({\n\t\t\t\t\t\t\t\t\top: {\n\t\t\t\t\t\t\t\t\t\tseq: m.sequenceNumber,\n\t\t\t\t\t\t\t\t\t\tminSeq: m.minimumSequenceNumber,\n\t\t\t\t\t\t\t\t\t\trefSeq: m.referenceSequenceNumber,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tcollabWindow: {\n\t\t\t\t\t\t\t\t\t\tseq: collabWindow.currentSeq,\n\t\t\t\t\t\t\t\t\t\tminSeq: collabWindow.minSeq,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t})}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.processMergeTreeMsg(m);\n\t\t\t\t\t});\n\t\t\t\t\tthis.loadFinished();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.loadFinished(error);\n\t\t\t\t});\n\t\t\tif (this.dataStoreRuntime.options.sequenceInitializeFromHeaderOnly !== true) {\n\t\t\t\t// if we not doing partial load, await the catch up ops,\n\t\t\t\t// and the finalization of the load\n\t\t\t\tawait loadCatchUpOps;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.loadFinished(error);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (local) {\n\t\t\tconst recordedRefSeq = this.inFlightRefSeqs.shift();\n\t\t\tassert(recordedRefSeq !== undefined, 0x8bc /* No pending recorded refSeq found */);\n\t\t\t// TODO: AB#7076: Some equivalent assert should be enabled. This fails some e2e stashed op tests because\n\t\t\t// the deltaManager may have seen more messages than the runtime has processed while amidst the stashed op\n\t\t\t// flow, so e.g. when `applyStashedOp` is called and the DDS is put in a state where it expects an ack for\n\t\t\t// one of its messages, the delta manager has actually already seen subsequent messages from collaborators\n\t\t\t// which the in-flight message is concurrent to.\n\t\t\t// See \"handles stashed ops created on top of sequenced local ops\" for one such test case.\n\t\t\t// assert(recordedRefSeq <= message.referenceSequenceNumber, \"RefSeq mismatch\");\n\t\t}\n\n\t\t// if loading isn't complete, we need to cache all\n\t\t// incoming ops to be applied after loading is complete\n\t\tif (this.deferIncomingOps) {\n\t\t\tassert(!local, 0x072 /* \"Unexpected local op when loading not finished\" */);\n\t\t\tthis.loadedDeferredIncomingOps.push(message);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tmessage.type === MessageType.Operation,\n\t\t\t\t0x073 /* \"Sequence message not operation\" */,\n\t\t\t);\n\n\t\t\tconst handled = this.intervalCollections.tryProcessMessage(\n\t\t\t\tmessage.contents as IMapOperation,\n\t\t\t\tlocal,\n\t\t\t\tmessage,\n\t\t\t\tlocalOpMetadata,\n\t\t\t);\n\n\t\t\tif (!handled) {\n\t\t\t\tthis.processMergeTreeMsg(message, local);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}\n\t */\n\tprotected didAttach() {\n\t\t// If we are not local, and we've attached we need to start generating and sending ops\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore() {\n\t\tsuper.initializeLocalCore();\n\t\tthis.loadFinished();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): void {\n\t\tif (!this.intervalCollections.tryApplyStashedOp(content)) {\n\t\t\tthis.client.applyStashedOp(content);\n\t\t}\n\t}\n\n\tprivate summarizeMergeTree(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Are we fully loaded? If not, things will go south\n\t\tassert(\n\t\t\tthis.loadedDeferred.isCompleted,\n\t\t\t0x074 /* \"Snapshot called when not fully loaded\" */,\n\t\t);\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tthis.processMinSequenceNumberChanged(minSeq);\n\n\t\tthis.messagesSinceMSNChange.forEach((m) => {\n\t\t\tm.minimumSequenceNumber = minSeq;\n\t\t});\n\n\t\treturn this.client.summarize(\n\t\t\tthis.runtime,\n\t\t\tthis.handle,\n\t\t\tserializer,\n\t\t\tthis.messagesSinceMSNChange,\n\t\t);\n\t}\n\n\t/**\n\t *\n\t * @param message - Message with decoded and hydrated handles\n\t */\n\tprivate processMergeTreeMsg(message: ISequencedDocumentMessage, local?: boolean) {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfunction transformOps(event: SequenceDeltaEvent) {\n\t\t\tops.push(...SharedSegmentSequence.createOpsFromDelta(event));\n\t\t}\n\t\tconst needsTransformation = message.referenceSequenceNumber !== message.sequenceNumber - 1;\n\t\tlet stashMessage: Readonly<ISequencedDocumentMessage> = message;\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.on(\"sequenceDelta\", transformOps);\n\t\t\t}\n\t\t}\n\n\t\tthis.client.applyMsg(message, local);\n\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.removeListener(\"sequenceDelta\", transformOps);\n\t\t\t\t// shallow clone the message as we only overwrite top level properties,\n\t\t\t\t// like referenceSequenceNumber and content only\n\t\t\t\tstashMessage = {\n\t\t\t\t\t...message,\n\t\t\t\t\treferenceSequenceNumber: stashMessage.sequenceNumber - 1,\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcontents: ops.length !== 1 ? createGroupOp(...ops) : ops[0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tthis.messagesSinceMSNChange.push(stashMessage);\n\n\t\t\t// Do GC every once in a while...\n\t\t\tif (\n\t\t\t\tthis.messagesSinceMSNChange.length > 20 &&\n\t\t\t\tthis.messagesSinceMSNChange[20].sequenceNumber < message.minimumSequenceNumber\n\t\t\t) {\n\t\t\t\tthis.processMinSequenceNumberChanged(message.minimumSequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate processMinSequenceNumberChanged(minSeq: number) {\n\t\tlet index = 0;\n\t\tfor (; index < this.messagesSinceMSNChange.length; index++) {\n\t\t\tif (this.messagesSinceMSNChange[index].sequenceNumber > minSeq) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index !== 0) {\n\t\t\tthis.messagesSinceMSNChange = this.messagesSinceMSNChange.slice(index);\n\t\t}\n\t}\n\n\tprivate loadFinished(error?: any) {\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\t// Initialize the interval collections\n\t\t\tthis.initializeIntervalCollections();\n\t\t\tif (error) {\n\t\t\t\tthis.loadedDeferred.reject(error);\n\t\t\t\tthrow error;\n\t\t\t} else {\n\t\t\t\t// it is important this series remains synchronous\n\t\t\t\t// first we stop deferring incoming ops, and apply then all\n\t\t\t\tthis.deferIncomingOps = false;\n\t\t\t\tfor (const message of this.loadedDeferredIncomingOps) {\n\t\t\t\t\tthis.processCore(message, false, undefined);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredIncomingOps.length = 0;\n\n\t\t\t\t// then resolve the loaded promise\n\t\t\t\t// and resubmit all the outstanding ops, as the snapshot\n\t\t\t\t// is fully loaded, and all outstanding ops are applied\n\t\t\t\tthis.loadedDeferred.resolve();\n\n\t\t\t\tfor (const [messageContent, opMetadata] of this.loadedDeferredOutgoingOps) {\n\t\t\t\t\tthis.reSubmitCore(messageContent, opMetadata);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredOutgoingOps.length = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate initializeIntervalCollections() {\n\t\t// Listen and initialize new SharedIntervalCollections\n\t\tthis.intervalCollections.eventEmitter.on(\n\t\t\t\"create\",\n\t\t\t({ key, previousValue }: IValueChanged, local: boolean) => {\n\t\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\t\tif (!intervalCollection.attached) {\n\t\t\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t\t\t}\n\t\t\t\tassert(\n\t\t\t\t\tpreviousValue === undefined,\n\t\t\t\t\t0x2c1 /* \"Creating an interval collection that already exists?\" */,\n\t\t\t\t);\n\t\t\t\tthis.emit(\"createIntervalCollection\", key, local, this);\n\t\t\t},\n\t\t);\n\n\t\t// Initialize existing SharedIntervalCollections\n\t\tfor (const key of this.intervalCollections.keys()) {\n\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"currently applicable reference sequence number\" for the duration of the callback.\n\t * See remarks on `currentRefSeq` for more context.\n\t */\n\tprivate useResubmitRefSeq(refSeq: number, callback: () => void) {\n\t\tconst previousResubmitRefSeq = this.ongoingResubmitRefSeq;\n\t\tthis.ongoingResubmitRefSeq = refSeq;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tthis.ongoingResubmitRefSeq = previousResubmitRefSeq;\n\t\t}\n\t}\n}\n\nfunction createReentrancyDetector(\n\tonReentrancy: (depth: number) => void,\n): <T>(callback: () => T) => T {\n\tlet depth = 0;\n\tfunction detectReentrancy<T>(callback: () => T): T {\n\t\tif (depth > 0) {\n\t\t\tonReentrancy(depth);\n\t\t}\n\t\tdepth++;\n\t\ttry {\n\t\t\treturn callback();\n\t\t} finally {\n\t\t\tdepth--;\n\t\t}\n\t}\n\n\treturn detectReentrancy;\n}\n\n/**\n * Apps which generate reentrant behavior may do so at a high frequency.\n * Logging even per-SharedSegmentSequence instance might be too noisy, and having a few logs from a session\n * is likely enough.\n */\nlet totalReentrancyLogs = 3;\n\n/**\n * Resets the reentrancy log counter. Test-only API.\n */\nexport function resetReentrancyLogCounter() {\n\ttotalReentrancyLogs = 3;\n}\n\nconst reentrancyErrorMessage = \"Reentrancy detected in sequence local ops\";\nconst ensureNoReentrancy = createReentrancyDetector(() => {\n\tthrow new LoggingError(reentrancyErrorMessage);\n});\n"]}
|
|
1
|
+
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,+DAA8D;AAE9D,kEAAuE;AAMvE,kEA+B6C;AAC7C,+EAA8F;AAE9F,qEAAoG;AAEpG,0EAA2E;AAC3E,uEAA2F;AAC3F,4EAAuC;AAEvC,mEAAmG;AACnG,yEAAkF;AAGlF,mEAAuF;AAGvF,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,WAAW,GAAG,SAAS,CAAC;AAmD9B;;GAEG;AACH,MAAsB,qBACrB,SAAQ,uBAA0C;IAGlD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;IACpC,CAAC;IAgBO,MAAM,CAAC,kBAAkB,CAAC,KAAyB;QAC1D,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE;YAC7B,QAAQ,KAAK,CAAC,cAAc,EAAE;gBAC7B,KAAK,6BAAkB,CAAC,QAAQ,CAAC,CAAC;oBACjC,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAA0B,CAAC;oBAClE,MAAM,KAAK,GAAgB,EAAE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,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIChannelStorageService,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeGroupMsg,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tLocalReferencePosition,\n\tMergeTreeDeltaType,\n\tMergeTreeRevertibleDriver,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\t// eslint-disable-next-line import/no-deprecated\n\tSegmentGroup,\n\tSlidingPreference,\n\tcreateAnnotateRangeOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertOp,\n\tcreateObliterateRangeOp,\n\tcreateRemoveRangeOp,\n\tmatchProperties,\n} from \"@fluidframework/merge-tree/internal\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ISummaryTreeWithStats, ITelemetryContext } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\nimport { SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { LoggingError, createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\n\nimport { IIntervalCollection, SequenceIntervalCollectionValueType } from \"./intervalCollection.js\";\nimport { IMapOperation, IntervalCollectionMap } from \"./intervalCollectionMap.js\";\nimport { IMapMessageLocalMetadata, IValueChanged } from \"./intervalCollectionMapInterfaces.js\";\nimport { SequenceInterval } from \"./intervals/index.js\";\nimport { SequenceDeltaEvent, SequenceMaintenanceEvent } from \"./sequenceDeltaEvent.js\";\nimport { ISharedIntervalCollection } from \"./sharedIntervalCollection.js\";\n\nconst snapshotFileName = \"header\";\nconst contentPath = \"content\";\n\n/**\n * Events emitted in response to changes to the sequence data.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"sequenceDelta\"\n *\n * The sequenceDelta event is emitted when segments are inserted, annotated, or removed.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n *\n * ### \"maintenance\"\n *\n * The maintenance event is emitted when segments are modified during merge-tree maintenance.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n * @alpha\n */\nexport interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {\n\t(\n\t\tevent: \"createIntervalCollection\",\n\t\tlistener: (label: string, local: boolean, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"sequenceDelta\",\n\t\tlistener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n}\n\n/**\n * @alpha\n */\nexport abstract class SharedSegmentSequence<T extends ISegment>\n\textends SharedObject<ISharedSegmentSequenceEvents>\n\timplements ISharedIntervalCollection<SequenceInterval>, MergeTreeRevertibleDriver\n{\n\tget loaded(): Promise<void> {\n\t\treturn this.loadedDeferred.promise;\n\t}\n\n\t/**\n\t * This is a safeguard to avoid problematic reentrancy of local ops. This type of scenario occurs if the user of SharedString subscribes\n\t * to the `sequenceDelta` event and uses the callback for a local op to submit further local ops.\n\t * Historically (before 2.0.0-internal.6.1.0), doing so would result in eventual consistency issues or a corrupted document.\n\t * These issues were fixed in #16815 which makes such reentrancy no different from applying the ops in order but not from within the change events,\n\t * but there is still little test coverage for reentrant scenarios.\n\t * Additionally, applications submitting ops from inside change events need to take extreme care that their data models also support reentrancy.\n\t * Since this is likely not the case, by default SharedString throws when encountering reentrant ops.\n\t *\n\t * An application using SharedString which explicitly wants to opt in to allowing reentrancy anyway can set `sharedStringPreventReentrancy`\n\t * on the data store options to `false`.\n\t */\n\tprotected guardReentrancy: <TRet>(callback: () => TRet) => TRet;\n\n\tprivate static createOpsFromDelta(event: SequenceDeltaEvent): IMergeTreeDeltaOp[] {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfor (const r of event.ranges) {\n\t\t\tswitch (event.deltaOperation) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tconst lastAnnotate = ops[ops.length - 1] as IMergeTreeAnnotateMsg;\n\t\t\t\t\tconst props: PropertySet = {};\n\t\t\t\t\tfor (const key of Object.keys(r.propertyDeltas)) {\n\t\t\t\t\t\tprops[key] = r.segment.properties?.[key] ?? null;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastAnnotate &&\n\t\t\t\t\t\tlastAnnotate.pos2 === r.position &&\n\t\t\t\t\t\tmatchProperties(lastAnnotate.props, props)\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastAnnotate.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateAnnotateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tops.push(createInsertOp(r.position, r.segment.clone().toJSONObject()));\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeRemoveMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x3ff /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateRemoveRangeOp(r.position, r.position + r.segment.cachedLength),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x874 /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateObliterateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\treturn ops;\n\t}\n\n\t/**\n\t * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.\n\t * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process\n\t * incoming leave/join ops before putting an op that this DDS submits over the wire.\n\t *\n\t * E.g. SharedString submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime\n\t * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber\n\t * on the SharedString op is 11.\n\t *\n\t * The reference sequence numbers placed in this queue are also not accurate for stashed ops due to how the applyStashedOp\n\t * flow works at the runtime level. This is a legitimate bug, and AB#6602 tracks one way to fix it (stop reaching all the way\n\t * to deltaManager's lastSequenceNumber to obtain refSeq, instead leveraging some analogous notion on the container or datastore\n\t * runtime).\n\t */\n\tprivate readonly inFlightRefSeqs = new Deque<number>();\n\n\tprivate ongoingResubmitRefSeq: number | undefined;\n\n\t/**\n\t * Gets the reference sequence number (i.e. sequence number of the runtime's last processed op) for an op submitted\n\t * in the current context.\n\t *\n\t * This value can be optionally overridden using `useResubmitRefSeq`.\n\t * IntervalCollection's resubmit logic currently relies on preserving merge information from when the op was originally submitted,\n\t * even if the op is resubmitted more than once. Thus during resubmit, `inFlightRefSeqs` gets populated with the\n\t * original refSeq rather than the refSeq at the time of reconnection.\n\t *\n\t * @remarks - In some not fully understood cases, the runtime may process incoming ops before putting an op that this\n\t * DDS submits over the wire. See `inFlightRefSeqs` for more details.\n\t */\n\tprivate get currentRefSeq() {\n\t\treturn this.ongoingResubmitRefSeq ?? this.runtime.deltaManager.lastSequenceNumber;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprotected client: Client;\n\t/** `Deferred` that triggers once the object is loaded */\n\tprotected loadedDeferred = new Deferred<void>();\n\t// cache out going ops created when partial loading\n\t// eslint-disable-next-line import/no-deprecated\n\tprivate readonly loadedDeferredOutgoingOps: [IMergeTreeOp, SegmentGroup | SegmentGroup[]][] =\n\t\t[];\n\t// cache incoming ops that arrive when partial loading\n\tprivate deferIncomingOps = true;\n\tprivate readonly loadedDeferredIncomingOps: ISequencedDocumentMessage[] = [];\n\n\tprivate messagesSinceMSNChange: ISequencedDocumentMessage[] = [];\n\tprivate readonly intervalCollections: IntervalCollectionMap<SequenceInterval>;\n\tconstructor(\n\t\tprivate readonly dataStoreRuntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly segmentFromSpec: (spec: IJSONSegment) => ISegment,\n\t) {\n\t\tsuper(id, dataStoreRuntime, attributes, \"fluid_sequence_\");\n\n\t\tconst getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);\n\t\tthis.guardReentrancy =\n\t\t\tdataStoreRuntime.options.sharedStringPreventReentrancy ?? true\n\t\t\t\t? ensureNoReentrancy\n\t\t\t\t: createReentrancyDetector((depth) => {\n\t\t\t\t\t\tif (totalReentrancyLogs > 0) {\n\t\t\t\t\t\t\ttotalReentrancyLogs--;\n\t\t\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t\t\t{ eventName: \"LocalOpReentry\", depth },\n\t\t\t\t\t\t\t\tnew LoggingError(reentrancyErrorMessage),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t });\n\n\t\tthis.loadedDeferred.promise.catch((error) => {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"SequenceLoadFailed\" }, error);\n\t\t});\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tthis.client = new Client(\n\t\t\tsegmentFromSpec,\n\t\t\tcreateChildLogger({\n\t\t\t\tlogger: this.logger,\n\t\t\t\tnamespace: \"SharedSegmentSequence.MergeTreeClient\",\n\t\t\t}),\n\t\t\tdataStoreRuntime.options,\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.client.prependListener(\"delta\", (opArgs, deltaArgs) => {\n\t\t\tconst event = new SequenceDeltaEvent(opArgs, deltaArgs, this.client);\n\t\t\tif (event.isLocal) {\n\t\t\t\tthis.submitSequenceMessage(opArgs.op);\n\t\t\t}\n\t\t\tthis.emit(\"sequenceDelta\", event, this);\n\t\t});\n\n\t\tthis.client.on(\"maintenance\", (args, opArgs) => {\n\t\t\tthis.emit(\"maintenance\", new SequenceMaintenanceEvent(opArgs, args, this.client), this);\n\t\t});\n\n\t\tthis.intervalCollections = new IntervalCollectionMap(\n\t\t\tthis.serializer,\n\t\t\tthis.handle,\n\t\t\t(op, localOpMetadata) => {\n\t\t\t\tif (!this.isAttached()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata);\n\t\t\t},\n\t\t\tnew SequenceIntervalCollectionValueType(),\n\t\t\tdataStoreRuntime.options,\n\t\t);\n\t}\n\n\t/**\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tpublic removeRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.removeRangeLocal(start, end));\n\t}\n\n\t/**\n\t * Obliterate is similar to remove, but differs in that segments concurrently\n\t * inserted into an obliterated range will also be removed\n\t *\n\t * @param start - The inclusive start of the range to obliterate\n\t * @param end - The exclusive end of the range to obliterate\n\t */\n\tpublic obliterateRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.obliterateRangeLocal(start, end));\n\t}\n\n\t/**\n\t * @deprecated The ability to create group ops will be removed in an upcoming\n\t * release, as group ops are redundant with the native batching capabilities\n\t * of the runtime\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic groupOperation(groupOp: IMergeTreeGroupMsg) {\n\t\tthis.guardReentrancy(() => this.client.localTransaction(groupOp));\n\t}\n\n\t/**\n\t * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.\n\t * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.\n\t * @param pos - Character position (index) into the current local view of the SharedString.\n\t */\n\tpublic getContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\treturn this.client.getContainingSegment<T>(pos);\n\t}\n\n\t/**\n\t * Returns the length of the current sequence for the client\n\t */\n\tpublic getLength() {\n\t\treturn this.client.getLength();\n\t}\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this sequence\n\t * @param segment - The segment to get the position of\n\t */\n\tpublic getPosition(segment: ISegment): number {\n\t\treturn this.client.getPosition(segment);\n\t}\n\n\t/**\n\t * Annotates the range with the provided properties\n\t *\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t *\n\t */\n\tpublic annotateRange(start: number, end: number, props: PropertySet): void {\n\t\tthis.guardReentrancy(() => this.client.annotateRangeLocal(start, end, props));\n\t}\n\n\tpublic getPropertiesAtPosition(pos: number) {\n\t\treturn this.client.getPropertiesAtPosition(pos);\n\t}\n\n\tpublic getRangeExtentsOfPosition(pos: number) {\n\t\treturn this.client.getRangeExtentsOfPosition(pos);\n\t}\n\n\t/**\n\t * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include\n\t * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t */\n\tpublic createLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this.client.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of `ReferenceType`. To handle this case specifically, one may wish\n\t * to look at the segment returned by `ReferencePosition.getSegment`.\n\t */\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this.client.localReferencePositionToPosition(lref);\n\t}\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this SharedString.\n\t */\n\tpublic removeLocalReferencePosition(lref: LocalReferencePosition) {\n\t\treturn this.client.removeLocalReferencePosition(lref);\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\treturn this.client.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tremoteClientId,\n\t\t);\n\t}\n\n\tprivate submitSequenceMessage(message: IMergeTreeOp) {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\n\t\tconst metadata = this.client.peekPendingSegmentGroups(\n\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t);\n\n\t\t// if loading isn't complete, we need to cache\n\t\t// local ops until loading is complete, and then\n\t\t// they will be present\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\tthis.loadedDeferredOutgoingOps.push(metadata ? [message, metadata] : (message as any));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(message, metadata);\n\t\t}\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition) {\n\t\treturn this.client.posFromRelativePos(relativePos);\n\t}\n\n\t/**\n\t * Walk the underlying segments of the sequence.\n\t * The walked segments may extend beyond the range if the segments cross the\n\t * ranges start or end boundaries.\n\t *\n\t * Set split range to true to ensure only segments within the range are walked.\n\t *\n\t * @param handler - The function to handle each segment. Traversal ends if\n\t * this function returns true.\n\t * @param start - Optional. The start of range walk.\n\t * @param end - Optional. The end of range walk\n\t * @param accum - Optional. An object that will be passed to the handler for accumulation\n\t * @param splitRange - Optional. Splits boundary segments on the range boundaries\n\t */\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis.client.walkSegments(handler, start, end, accum as TClientData, splitRange);\n\t}\n\n\t/**\n\t * @returns The most recent sequence number which has been acked by the server and processed by this\n\t * SharedSegmentSequence.\n\t */\n\tpublic getCurrentSeq() {\n\t\treturn this.client.getCurrentSeq();\n\t}\n\n\t/**\n\t * Inserts a segment directly before a `ReferencePosition`.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertAtReferencePosition(pos: ReferencePosition, segment: T): void {\n\t\tthis.guardReentrancy(() => this.client.insertAtReferencePositionLocal(pos, segment));\n\t}\n\t/**\n\t * Inserts a segment\n\t * @param start - The position to insert the segment at\n\t * @param spec - The segment to inserts spec\n\t */\n\tpublic insertFromSpec(pos: number, spec: IJSONSegment): void {\n\t\tconst segment = this.segmentFromSpec(spec);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Retrieves the interval collection keyed on `label`. If no such interval collection exists,\n\t * creates one.\n\t */\n\tpublic getIntervalCollection(label: string): IIntervalCollection<SequenceInterval> {\n\t\treturn this.intervalCollections.get(label);\n\t}\n\n\t/**\n\t * @returns An iterable object that enumerates the IntervalCollection labels.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const iter = this.getIntervalCollectionKeys();\n\t * for (key of iter)\n\t * const collection = this.getIntervalCollection(key);\n\t * ...\n\t * ```\n\t */\n\tpublic getIntervalCollectionLabels(): IterableIterator<string> {\n\t\treturn this.intervalCollections.keys();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}\n\t */\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// conditionally write the interval collection blob\n\t\t// only if it has entries\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tbuilder.addBlob(snapshotFileName, this.intervalCollections.serialize(serializer));\n\t\t}\n\n\t\tbuilder.addWithStats(contentPath, this.summarizeMergeTree(serializer));\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer over the GC data for this SharedMatrix.\n\t * All the IFluidHandle's represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: IFluidSerializer) {\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tthis.intervalCollections.serialize(serializer);\n\t\t}\n\n\t\tthis.client.serializeGCData(this.handle, serializer);\n\t}\n\n\t/**\n\t * Replace the range specified from start to end with the provided segment\n\t * This is done by inserting the segment at the end of the range, followed\n\t * by removing the contents of the range\n\t * For a zero or reverse range (start \\>= end), insert at end do not remove anything\n\t * @param start - The start of the range to replace\n\t * @param end - The end of the range to replace\n\t * @param segment - The segment that will replace the range\n\t */\n\tprotected replaceRange(start: number, end: number, segment: ISegment): void {\n\t\t// Insert at the max end of the range when start > end, but still remove the range later\n\t\tconst insertIndex: number = Math.max(start, end);\n\n\t\t// Insert first, so local references can slide to the inserted seg if any\n\t\tconst insert = this.guardReentrancy(() =>\n\t\t\tthis.client.insertSegmentLocal(insertIndex, segment),\n\t\t);\n\n\t\tif (insert && start < end) {\n\t\t\tthis.removeRange(start, end);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n\t */\n\tprotected onConnect() {\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n\t */\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.shift();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0x8bb /* Expected a recorded refSeq when resubmitting an op */,\n\t\t);\n\t\tthis.useResubmitRefSeq(originalRefSeq, () => {\n\t\t\tif (\n\t\t\t\t!this.intervalCollections.tryResubmitMessage(\n\t\t\t\t\tcontent,\n\t\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.submitSequenceMessage(\n\t\t\t\t\tthis.client.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\tif (await storage.contains(snapshotFileName)) {\n\t\t\tconst blob = await storage.readBlob(snapshotFileName);\n\t\t\tconst header = bufferToString(blob, \"utf8\");\n\t\t\tthis.intervalCollections.populate(header);\n\t\t}\n\n\t\ttry {\n\t\t\t// this will load the header, and return a promise\n\t\t\t// that will resolve when the body is loaded\n\t\t\t// and the catchup ops are available.\n\t\t\tconst { catchupOpsP } = await this.client.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, contentPath),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\t// setup a promise to process the\n\t\t\t// catch up ops, and finishing the loading process\n\t\t\tconst loadCatchUpOps = catchupOpsP\n\t\t\t\t.then((msgs) => {\n\t\t\t\t\tmsgs.forEach((m) => {\n\t\t\t\t\t\tconst collabWindow = this.client.getCollabWindow();\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tm.minimumSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.referenceSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.sequenceNumber <= collabWindow.minSeq ||\n\t\t\t\t\t\t\t// sequenceNumber could be the same if messages are part of a grouped batch\n\t\t\t\t\t\t\tm.sequenceNumber < collabWindow.currentSeq\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Invalid catchup operations in snapshot: ${JSON.stringify({\n\t\t\t\t\t\t\t\t\top: {\n\t\t\t\t\t\t\t\t\t\tseq: m.sequenceNumber,\n\t\t\t\t\t\t\t\t\t\tminSeq: m.minimumSequenceNumber,\n\t\t\t\t\t\t\t\t\t\trefSeq: m.referenceSequenceNumber,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tcollabWindow: {\n\t\t\t\t\t\t\t\t\t\tseq: collabWindow.currentSeq,\n\t\t\t\t\t\t\t\t\t\tminSeq: collabWindow.minSeq,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t})}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.processMergeTreeMsg(m);\n\t\t\t\t\t});\n\t\t\t\t\tthis.loadFinished();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.loadFinished(error);\n\t\t\t\t});\n\t\t\tif (this.dataStoreRuntime.options.sequenceInitializeFromHeaderOnly !== true) {\n\t\t\t\t// if we not doing partial load, await the catch up ops,\n\t\t\t\t// and the finalization of the load\n\t\t\t\tawait loadCatchUpOps;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.loadFinished(error);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (local) {\n\t\t\tconst recordedRefSeq = this.inFlightRefSeqs.shift();\n\t\t\tassert(recordedRefSeq !== undefined, 0x8bc /* No pending recorded refSeq found */);\n\t\t\t// TODO: AB#7076: Some equivalent assert should be enabled. This fails some e2e stashed op tests because\n\t\t\t// the deltaManager may have seen more messages than the runtime has processed while amidst the stashed op\n\t\t\t// flow, so e.g. when `applyStashedOp` is called and the DDS is put in a state where it expects an ack for\n\t\t\t// one of its messages, the delta manager has actually already seen subsequent messages from collaborators\n\t\t\t// which the in-flight message is concurrent to.\n\t\t\t// See \"handles stashed ops created on top of sequenced local ops\" for one such test case.\n\t\t\t// assert(recordedRefSeq <= message.referenceSequenceNumber, \"RefSeq mismatch\");\n\t\t}\n\n\t\t// if loading isn't complete, we need to cache all\n\t\t// incoming ops to be applied after loading is complete\n\t\tif (this.deferIncomingOps) {\n\t\t\tassert(!local, 0x072 /* \"Unexpected local op when loading not finished\" */);\n\t\t\tthis.loadedDeferredIncomingOps.push(message);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tmessage.type === MessageType.Operation,\n\t\t\t\t0x073 /* \"Sequence message not operation\" */,\n\t\t\t);\n\n\t\t\tconst handled = this.intervalCollections.tryProcessMessage(\n\t\t\t\tmessage.contents as IMapOperation,\n\t\t\t\tlocal,\n\t\t\t\tmessage,\n\t\t\t\tlocalOpMetadata,\n\t\t\t);\n\n\t\t\tif (!handled) {\n\t\t\t\tthis.processMergeTreeMsg(message, local);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}\n\t */\n\tprotected didAttach() {\n\t\t// If we are not local, and we've attached we need to start generating and sending ops\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore() {\n\t\tsuper.initializeLocalCore();\n\t\tthis.loadFinished();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): void {\n\t\tif (!this.intervalCollections.tryApplyStashedOp(content)) {\n\t\t\tthis.client.applyStashedOp(content);\n\t\t}\n\t}\n\n\tprivate summarizeMergeTree(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Are we fully loaded? If not, things will go south\n\t\tassert(\n\t\t\tthis.loadedDeferred.isCompleted,\n\t\t\t0x074 /* \"Snapshot called when not fully loaded\" */,\n\t\t);\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tthis.processMinSequenceNumberChanged(minSeq);\n\n\t\tthis.messagesSinceMSNChange.forEach((m) => {\n\t\t\tm.minimumSequenceNumber = minSeq;\n\t\t});\n\n\t\treturn this.client.summarize(\n\t\t\tthis.runtime,\n\t\t\tthis.handle,\n\t\t\tserializer,\n\t\t\tthis.messagesSinceMSNChange,\n\t\t);\n\t}\n\n\t/**\n\t *\n\t * @param message - Message with decoded and hydrated handles\n\t */\n\tprivate processMergeTreeMsg(message: ISequencedDocumentMessage, local?: boolean) {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfunction transformOps(event: SequenceDeltaEvent) {\n\t\t\tops.push(...SharedSegmentSequence.createOpsFromDelta(event));\n\t\t}\n\t\tconst needsTransformation = message.referenceSequenceNumber !== message.sequenceNumber - 1;\n\t\tlet stashMessage: Readonly<ISequencedDocumentMessage> = message;\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.on(\"sequenceDelta\", transformOps);\n\t\t\t}\n\t\t}\n\n\t\tthis.client.applyMsg(message, local);\n\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.removeListener(\"sequenceDelta\", transformOps);\n\t\t\t\t// shallow clone the message as we only overwrite top level properties,\n\t\t\t\t// like referenceSequenceNumber and content only\n\t\t\t\tstashMessage = {\n\t\t\t\t\t...message,\n\t\t\t\t\treferenceSequenceNumber: stashMessage.sequenceNumber - 1,\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcontents: ops.length !== 1 ? createGroupOp(...ops) : ops[0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tthis.messagesSinceMSNChange.push(stashMessage);\n\n\t\t\t// Do GC every once in a while...\n\t\t\tif (\n\t\t\t\tthis.messagesSinceMSNChange.length > 20 &&\n\t\t\t\tthis.messagesSinceMSNChange[20].sequenceNumber < message.minimumSequenceNumber\n\t\t\t) {\n\t\t\t\tthis.processMinSequenceNumberChanged(message.minimumSequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate processMinSequenceNumberChanged(minSeq: number) {\n\t\tlet index = 0;\n\t\tfor (; index < this.messagesSinceMSNChange.length; index++) {\n\t\t\tif (this.messagesSinceMSNChange[index].sequenceNumber > minSeq) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index !== 0) {\n\t\t\tthis.messagesSinceMSNChange = this.messagesSinceMSNChange.slice(index);\n\t\t}\n\t}\n\n\tprivate loadFinished(error?: any) {\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\t// Initialize the interval collections\n\t\t\tthis.initializeIntervalCollections();\n\t\t\tif (error) {\n\t\t\t\tthis.loadedDeferred.reject(error);\n\t\t\t\tthrow error;\n\t\t\t} else {\n\t\t\t\t// it is important this series remains synchronous\n\t\t\t\t// first we stop deferring incoming ops, and apply then all\n\t\t\t\tthis.deferIncomingOps = false;\n\t\t\t\tfor (const message of this.loadedDeferredIncomingOps) {\n\t\t\t\t\tthis.processCore(message, false, undefined);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredIncomingOps.length = 0;\n\n\t\t\t\t// then resolve the loaded promise\n\t\t\t\t// and resubmit all the outstanding ops, as the snapshot\n\t\t\t\t// is fully loaded, and all outstanding ops are applied\n\t\t\t\tthis.loadedDeferred.resolve();\n\n\t\t\t\tfor (const [messageContent, opMetadata] of this.loadedDeferredOutgoingOps) {\n\t\t\t\t\tthis.reSubmitCore(messageContent, opMetadata);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredOutgoingOps.length = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate initializeIntervalCollections() {\n\t\t// Listen and initialize new SharedIntervalCollections\n\t\tthis.intervalCollections.eventEmitter.on(\n\t\t\t\"create\",\n\t\t\t({ key, previousValue }: IValueChanged, local: boolean) => {\n\t\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\t\tif (!intervalCollection.attached) {\n\t\t\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t\t\t}\n\t\t\t\tassert(\n\t\t\t\t\tpreviousValue === undefined,\n\t\t\t\t\t0x2c1 /* \"Creating an interval collection that already exists?\" */,\n\t\t\t\t);\n\t\t\t\tthis.emit(\"createIntervalCollection\", key, local, this);\n\t\t\t},\n\t\t);\n\n\t\t// Initialize existing SharedIntervalCollections\n\t\tfor (const key of this.intervalCollections.keys()) {\n\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"currently applicable reference sequence number\" for the duration of the callback.\n\t * See remarks on `currentRefSeq` for more context.\n\t */\n\tprivate useResubmitRefSeq(refSeq: number, callback: () => void) {\n\t\tconst previousResubmitRefSeq = this.ongoingResubmitRefSeq;\n\t\tthis.ongoingResubmitRefSeq = refSeq;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tthis.ongoingResubmitRefSeq = previousResubmitRefSeq;\n\t\t}\n\t}\n}\n\nfunction createReentrancyDetector(\n\tonReentrancy: (depth: number) => void,\n): <T>(callback: () => T) => T {\n\tlet depth = 0;\n\tfunction detectReentrancy<T>(callback: () => T): T {\n\t\tif (depth > 0) {\n\t\t\tonReentrancy(depth);\n\t\t}\n\t\tdepth++;\n\t\ttry {\n\t\t\treturn callback();\n\t\t} finally {\n\t\t\tdepth--;\n\t\t}\n\t}\n\n\treturn detectReentrancy;\n}\n\n/**\n * Apps which generate reentrant behavior may do so at a high frequency.\n * Logging even per-SharedSegmentSequence instance might be too noisy, and having a few logs from a session\n * is likely enough.\n */\nlet totalReentrancyLogs = 3;\n\n/**\n * Resets the reentrancy log counter. Test-only API.\n */\nexport function resetReentrancyLogCounter() {\n\ttotalReentrancyLogs = 3;\n}\n\nconst reentrancyErrorMessage = \"Reentrancy detected in sequence local ops\";\nconst ensureNoReentrancy = createReentrancyDetector(() => {\n\tthrow new LoggingError(reentrancyErrorMessage);\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedString.d.ts","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACnG,OA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AS;IAIxD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;CAOhE;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACV;IACF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC1B,CAWA"}
|
package/dist/sharedString.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedString.js","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAU6C;AAE7C,+CAAsD;AACtD,6DAA2D;AAkC3D;;;;;;;;;GASG;AACH,MAAa,YACZ,SAAQ,mCAA0C;IAGlD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,wCAAmB,CAAC,IAAI,CAAiB,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,wCAAmB,EAAE,CAAC;IAClC,CAAC;IAED,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IAID,YACC,QAAgC,EACzB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,wCAAmB,CAAC,eAAsB,CAAC,CAAC;QAHrE,OAAE,GAAF,EAAE,CAAQ;QAIjB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAC1B,YAA+B,EAC/B,OAAsB,EACtB,KAAmB;QAEnB,MA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AW,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YACjF,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;SACpC;aAAM;YACN,MAAM,MAAM,GAAG,OAAiB,CAAC;YACjC,IAAI,IAAA,0BAAe,EAAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;gBAC3D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAC9C,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;aACtB;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IChannelAttributes, IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIMergeTreeTextHelper,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tMarker,\n\tPropertySet,\n\tReferenceType,\n\tTextSegment,\n\trefHasTileLabel,\n} from \"@fluidframework/merge-tree/internal\";\n\nimport { SharedSegmentSequence } from \"./sequence.js\";\nimport { SharedStringFactory } from \"./sequenceFactory.js\";\n\n/**\n * Fluid object interface describing access methods on a SharedString\n * @alpha\n */\nexport interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {\n\t/**\n\t * Inserts the text at the position.\n\t * @param pos - The position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of the text\n\t */\n\tinsertText(pos: number, text: string, props?: PropertySet): void;\n\n\t/**\n\t * Inserts a marker at the position.\n\t * @param pos - The position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tinsertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void;\n\n\t/**\n\t * {@inheritDoc SharedSegmentSequence.posFromRelativePos}\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n}\n\n/**\n * @alpha\n */\nexport type SharedStringSegment = TextSegment | Marker;\n\n/**\n * The Shared String is a specialized data structure for handling collaborative\n * text. It is based on a more general Sequence data structure but has\n * additional features that make working with text easier.\n *\n * In addition to text, a Shared String can also contain markers. Markers can be\n * used to store metadata at positions within the text, like the details of an\n * image or Fluid object that should be rendered with the text.\n * @alpha\n */\nexport class SharedString\n\textends SharedSegmentSequence<SharedStringSegment>\n\timplements ISharedString\n{\n\t/**\n\t * Create a new shared string.\n\t * @param runtime - data store runtime the new shared string belongs to\n\t * @param id - optional name of the shared string\n\t * @returns newly create shared string (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedStringFactory.Type) as SharedString;\n\t}\n\n\t/**\n\t * Get a factory for SharedString to register with the data store.\n\t * @returns a factory that creates and load SharedString\n\t */\n\tpublic static getFactory() {\n\t\treturn new SharedStringFactory();\n\t}\n\n\tpublic get ISharedString(): ISharedString {\n\t\treturn this;\n\t}\n\n\tprivate readonly mergeTreeTextHelper: IMergeTreeTextHelper;\n\n\tconstructor(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(document, id, attributes, SharedStringFactory.segmentFromSpec as any);\n\t\tthis.mergeTreeTextHelper = this.client.createTextHelper();\n\t}\n\n\t/**\n\t * Inserts a marker at a relative position.\n\t * @param relativePos1 - The relative position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tpublic insertMarkerRelative(\n\t\trelativePos1: IRelativePosition,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertMarker}\n\t */\n\tpublic insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Inserts the text at the position.\n\t * @param relativePos1 - The relative position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of text\n\t */\n\tpublic insertTextRelative(\n\t\trelativePos1: IRelativePosition,\n\t\ttext: string,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertText}\n\t */\n\tpublic insertText(pos: number, text: string, props?: PropertySet): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Replaces a range with the provided text.\n\t * @param start - The inclusive start of the range to replace\n\t * @param end - The exclusive end of the range to replace\n\t * @param text - The text to replace the range with\n\t * @param props - Optional. The properties of the replacement text\n\t */\n\tpublic replaceText(start: number, end: number, text: string, props?: PropertySet): void {\n\t\tthis.replaceRange(start, end, TextSegment.make(text, props));\n\t}\n\n\t/**\n\t * Removes the text in the given range.\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to replace\n\t * @returns the message sent.\n\t */\n\tpublic removeText(start: number, end: number): void {\n\t\tthis.removeRange(start, end);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t */\n\tpublic annotateMarker(marker: Marker, props: PropertySet) {\n\t\tthis.guardReentrancy(() => this.client.annotateMarker(marker, props));\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search.\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\treturn this.client.searchForMarker(startPos, markerLabel, forwards);\n\t}\n\n\t/**\n\t * Retrieve text from the SharedString in string format.\n\t * @param start - The starting index of the text to retrieve, or 0 if omitted.\n\t * @param end - The ending index of the text to retrieve, or the end of the string if omitted\n\t * @returns The requested text content as a string.\n\t */\n\tpublic getText(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Adds spaces for markers and handles, so that position calculations account for them.\n\t */\n\tpublic getTextWithPlaceholders(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\" \",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\tpublic getTextRangeWithMarkers(start: number, end: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"*\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided\n\t * id in this `SharedString`.\n\t */\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this.client.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tif (this.client.rollback !== undefined) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t}\n\t}\n}\n\ninterface ITextAndMarkerAccumulator {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n\tparallelMarkerLabel: string;\n\tplaceholder?: string;\n\ttagsInProgress: string[];\n\ttextSegment: TextSegment;\n}\n\n/**\n * Splits the text into regions ending with markers with the given `label`.\n * @param sharedString - String to retrieve text and markers from\n * @param label - label to split on\n * @returns Two parallel lists of text and markers, split by markers with the provided `label`.\n * For example:\n * ```typescript\n * // Say sharedstring has contents \"hello<paragraph marker 1>world<paragraph marker 2>missing\".\n * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, \"paragraph\");\n * // parallelText === [\"hello\", \"world\"]\n * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]\n * // Note parallelText does not include \"missing\".\n * ```\n * @internal\n */\nexport function getTextAndMarkers(\n\tsharedString: SharedString,\n\tlabel: string,\n\tstart?: number,\n\tend?: number,\n): {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n} {\n\tconst accum: ITextAndMarkerAccumulator = {\n\t\tparallelMarkerLabel: label,\n\t\tparallelMarkers: [],\n\t\tparallelText: [],\n\t\ttagsInProgress: [],\n\t\ttextSegment: new TextSegment(\"\"),\n\t};\n\n\tsharedString.walkSegments(gatherTextAndMarkers, start, end, accum);\n\treturn { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };\n}\n\nconst gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\taccumText: ITextAndMarkerAccumulator,\n) => {\n\tconst { placeholder, tagsInProgress, textSegment } = accumText;\n\tif (TextSegment.is(segment)) {\n\t\tlet beginTags = \"\";\n\t\tlet endTags = \"\";\n\t\t// TODO: let clients pass in function to get tag\n\t\tconst tags = [] as string[];\n\t\tconst initTags = [] as string[];\n\n\t\tif (segment.properties?.[\"font-weight\"]) {\n\t\t\ttags.push(\"b\");\n\t\t}\n\t\tif (segment.properties?.[\"text-decoration\"]) {\n\t\t\ttags.push(\"u\");\n\t\t}\n\t\tconst remTags = [] as string[];\n\t\tif (tags.length > 0) {\n\t\t\tfor (const tag of tags) {\n\t\t\t\tif (!tagsInProgress.includes(tag)) {\n\t\t\t\t\tbeginTags += `<${tag}>`;\n\t\t\t\t\tinitTags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tif (!tags.includes(accumTag)) {\n\t\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\t\tremTags.push(accumTag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const initTag of initTags.reverse()) {\n\t\t\t\ttagsInProgress.push(initTag);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\tremTags.push(accumTag);\n\t\t\t}\n\t\t}\n\t\tfor (const remTag of remTags) {\n\t\t\tconst remdex = tagsInProgress.indexOf(remTag);\n\t\t\tif (remdex >= 0) {\n\t\t\t\ttagsInProgress.splice(remdex, 1);\n\t\t\t}\n\t\t}\n\t\ttextSegment.text += endTags;\n\t\ttextSegment.text += beginTags;\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else {\n\t\tif (placeholder && placeholder.length > 0) {\n\t\t\tconst placeholderText =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\tplaceholder === \"*\" ? `\\n${segment}` : placeholder.repeat(segment.cachedLength);\n\t\t\ttextSegment.text += placeholderText;\n\t\t} else {\n\t\t\tconst marker = segment as Marker;\n\t\t\tif (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {\n\t\t\t\taccumText.parallelMarkers.push(marker);\n\t\t\t\taccumText.parallelText.push(textSegment.text);\n\t\t\t\ttextSegment.text = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"sharedString.js","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAW6C;AAE7C,+CAAsD;AACtD,6DAA2D;AAkC3D;;;;;;;;;GASG;AACH,MAAa,YACZ,SAAQ,mCAA0C;IAGlD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,wCAAmB,CAAC,IAAI,CAAiB,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,wCAAmB,EAAE,CAAC;IAClC,CAAC;IAED,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IAKD,YACC,QAAgC,EACzB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,wCAAmB,CAAC,eAAsB,CAAC,CAAC;QAHrE,OAAE,GAAF,EAAE,CAAQ;QAIjB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACI,oB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G,CAAC,EAAE;YAC1C,MAAM,eAAe;YACpB,gEAAgE;YAChE,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YACjF,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;SACpC;aAAM;YACN,MAAM,MAAM,GAAG,OAAiB,CAAC;YACjC,IAAI,IAAA,0BAAe,EAAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;gBAC3D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAC9C,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;aACtB;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IChannelAttributes, IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeTextHelper,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tMarker,\n\tPropertySet,\n\tReferenceType,\n\tTextSegment,\n\trefHasTileLabel,\n} from \"@fluidframework/merge-tree/internal\";\n\nimport { SharedSegmentSequence } from \"./sequence.js\";\nimport { SharedStringFactory } from \"./sequenceFactory.js\";\n\n/**\n * Fluid object interface describing access methods on a SharedString\n * @alpha\n */\nexport interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {\n\t/**\n\t * Inserts the text at the position.\n\t * @param pos - The position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of the text\n\t */\n\tinsertText(pos: number, text: string, props?: PropertySet): void;\n\n\t/**\n\t * Inserts a marker at the position.\n\t * @param pos - The position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tinsertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void;\n\n\t/**\n\t * {@inheritDoc SharedSegmentSequence.posFromRelativePos}\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n}\n\n/**\n * @alpha\n */\nexport type SharedStringSegment = TextSegment | Marker;\n\n/**\n * The Shared String is a specialized data structure for handling collaborative\n * text. It is based on a more general Sequence data structure but has\n * additional features that make working with text easier.\n *\n * In addition to text, a Shared String can also contain markers. Markers can be\n * used to store metadata at positions within the text, like the details of an\n * image or Fluid object that should be rendered with the text.\n * @alpha\n */\nexport class SharedString\n\textends SharedSegmentSequence<SharedStringSegment>\n\timplements ISharedString\n{\n\t/**\n\t * Create a new shared string.\n\t * @param runtime - data store runtime the new shared string belongs to\n\t * @param id - optional name of the shared string\n\t * @returns newly create shared string (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedStringFactory.Type) as SharedString;\n\t}\n\n\t/**\n\t * Get a factory for SharedString to register with the data store.\n\t * @returns a factory that creates and load SharedString\n\t */\n\tpublic static getFactory() {\n\t\treturn new SharedStringFactory();\n\t}\n\n\tpublic get ISharedString(): ISharedString {\n\t\treturn this;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprivate readonly mergeTreeTextHelper: IMergeTreeTextHelper;\n\n\tconstructor(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(document, id, attributes, SharedStringFactory.segmentFromSpec as any);\n\t\tthis.mergeTreeTextHelper = this.client.createTextHelper();\n\t}\n\n\t/**\n\t * Inserts a marker at a relative position.\n\t * @param relativePos1 - The relative position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tpublic insertMarkerRelative(\n\t\trelativePos1: IRelativePosition,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertMarker}\n\t */\n\tpublic insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Inserts the text at the position.\n\t * @param relativePos1 - The relative position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of text\n\t */\n\tpublic insertTextRelative(\n\t\trelativePos1: IRelativePosition,\n\t\ttext: string,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertText}\n\t */\n\tpublic insertText(pos: number, text: string, props?: PropertySet): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Replaces a range with the provided text.\n\t * @param start - The inclusive start of the range to replace\n\t * @param end - The exclusive end of the range to replace\n\t * @param text - The text to replace the range with\n\t * @param props - Optional. The properties of the replacement text\n\t */\n\tpublic replaceText(start: number, end: number, text: string, props?: PropertySet): void {\n\t\tthis.replaceRange(start, end, TextSegment.make(text, props));\n\t}\n\n\t/**\n\t * Removes the text in the given range.\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to replace\n\t * @returns the message sent.\n\t */\n\tpublic removeText(start: number, end: number): void {\n\t\tthis.removeRange(start, end);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t */\n\tpublic annotateMarker(marker: Marker, props: PropertySet) {\n\t\tthis.guardReentrancy(() => this.client.annotateMarker(marker, props));\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search.\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\treturn this.client.searchForMarker(startPos, markerLabel, forwards);\n\t}\n\n\t/**\n\t * Retrieve text from the SharedString in string format.\n\t * @param start - The starting index of the text to retrieve, or 0 if omitted.\n\t * @param end - The ending index of the text to retrieve, or the end of the string if omitted\n\t * @returns The requested text content as a string.\n\t */\n\tpublic getText(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Adds spaces for markers and handles, so that position calculations account for them.\n\t */\n\tpublic getTextWithPlaceholders(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\" \",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\tpublic getTextRangeWithMarkers(start: number, end: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"*\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided\n\t * id in this `SharedString`.\n\t */\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this.client.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tif (this.client.rollback !== undefined) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t}\n\t}\n}\n\ninterface ITextAndMarkerAccumulator {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n\tparallelMarkerLabel: string;\n\tplaceholder?: string;\n\ttagsInProgress: string[];\n\ttextSegment: TextSegment;\n}\n\n/**\n * Splits the text into regions ending with markers with the given `label`.\n * @param sharedString - String to retrieve text and markers from\n * @param label - label to split on\n * @returns Two parallel lists of text and markers, split by markers with the provided `label`.\n * For example:\n * ```typescript\n * // Say sharedstring has contents \"hello<paragraph marker 1>world<paragraph marker 2>missing\".\n * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, \"paragraph\");\n * // parallelText === [\"hello\", \"world\"]\n * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]\n * // Note parallelText does not include \"missing\".\n * ```\n * @internal\n */\nexport function getTextAndMarkers(\n\tsharedString: SharedString,\n\tlabel: string,\n\tstart?: number,\n\tend?: number,\n): {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n} {\n\tconst accum: ITextAndMarkerAccumulator = {\n\t\tparallelMarkerLabel: label,\n\t\tparallelMarkers: [],\n\t\tparallelText: [],\n\t\ttagsInProgress: [],\n\t\ttextSegment: new TextSegment(\"\"),\n\t};\n\n\tsharedString.walkSegments(gatherTextAndMarkers, start, end, accum);\n\treturn { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };\n}\n\nconst gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\taccumText: ITextAndMarkerAccumulator,\n) => {\n\tconst { placeholder, tagsInProgress, textSegment } = accumText;\n\tif (TextSegment.is(segment)) {\n\t\tlet beginTags = \"\";\n\t\tlet endTags = \"\";\n\t\t// TODO: let clients pass in function to get tag\n\t\tconst tags = [] as string[];\n\t\tconst initTags = [] as string[];\n\n\t\tif (segment.properties?.[\"font-weight\"]) {\n\t\t\ttags.push(\"b\");\n\t\t}\n\t\tif (segment.properties?.[\"text-decoration\"]) {\n\t\t\ttags.push(\"u\");\n\t\t}\n\t\tconst remTags = [] as string[];\n\t\tif (tags.length > 0) {\n\t\t\tfor (const tag of tags) {\n\t\t\t\tif (!tagsInProgress.includes(tag)) {\n\t\t\t\t\tbeginTags += `<${tag}>`;\n\t\t\t\t\tinitTags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tif (!tags.includes(accumTag)) {\n\t\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\t\tremTags.push(accumTag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const initTag of initTags.reverse()) {\n\t\t\t\ttagsInProgress.push(initTag);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\tremTags.push(accumTag);\n\t\t\t}\n\t\t}\n\t\tfor (const remTag of remTags) {\n\t\t\tconst remdex = tagsInProgress.indexOf(remTag);\n\t\t\tif (remdex >= 0) {\n\t\t\t\ttagsInProgress.splice(remdex, 1);\n\t\t\t}\n\t\t}\n\t\ttextSegment.text += endTags;\n\t\ttextSegment.text += beginTags;\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else {\n\t\tif (placeholder && placeholder.length > 0) {\n\t\t\tconst placeholderText =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\tplaceholder === \"*\" ? `\\n${segment}` : placeholder.repeat(segment.cachedLength);\n\t\t\ttextSegment.text += placeholderText;\n\t\t} else {\n\t\t\tconst marker = segment as Marker;\n\t\t\tif (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {\n\t\t\t\taccumText.parallelMarkers.push(marker);\n\t\t\t\taccumText.parallelText.push(textSegment.text);\n\t\t\t\ttextSegment.text = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n};\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/sequence";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-rc.3.0.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-rc.3.0.4";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-rc.3.0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-rc.3.0.4\";\n"]}
|
package/lib/sequence.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAU,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,MAAM,EACN,YAAY,
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAU,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,MAAM,EACN,YAAY,EAIZ,kBAAkB,EAKlB,iBAAiB,EACjB,QAAQ,EACR,cAAc,EACd,sBAAsB,EAEtB,yBAAy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;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CASzB;AA4BD;;GAEG;AACH,wBAAgB,yBAAyB,SAExC"}
|
package/lib/sequence.js
CHANGED
|
@@ -6,7 +6,8 @@ import { bufferToString } from "@fluid-internal/client-utils";
|
|
|
6
6
|
import { assert, Deferred } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import {
|
|
8
8
|
// eslint-disable-next-line import/no-deprecated
|
|
9
|
-
Client, MergeTreeDeltaType, createAnnotateRangeOp,
|
|
9
|
+
Client, MergeTreeDeltaType, createAnnotateRangeOp,
|
|
10
|
+
// eslint-disable-next-line import/no-deprecated
|
|
10
11
|
createGroupOp, createInsertOp, createObliterateRangeOp, createRemoveRangeOp, matchProperties, } from "@fluidframework/merge-tree/internal";
|
|
11
12
|
import { MessageType } from "@fluidframework/protocol-definitions";
|
|
12
13
|
import { ObjectStoragePartition, SummaryTreeBuilder } from "@fluidframework/runtime-utils/internal";
|
|
@@ -60,6 +61,7 @@ export class SharedSegmentSequence extends SharedObject {
|
|
|
60
61
|
break;
|
|
61
62
|
}
|
|
62
63
|
case MergeTreeDeltaType.OBLITERATE: {
|
|
64
|
+
// eslint-disable-next-line import/no-deprecated
|
|
63
65
|
const lastRem = ops[ops.length - 1];
|
|
64
66
|
if (lastRem?.pos1 === r.position) {
|
|
65
67
|
assert(lastRem.pos2 !== undefined, 0x874 /* pos2 should not be undefined here */);
|
|
@@ -113,6 +115,7 @@ export class SharedSegmentSequence extends SharedObject {
|
|
|
113
115
|
/** `Deferred` that triggers once the object is loaded */
|
|
114
116
|
this.loadedDeferred = new Deferred();
|
|
115
117
|
// cache out going ops created when partial loading
|
|
118
|
+
// eslint-disable-next-line import/no-deprecated
|
|
116
119
|
this.loadedDeferredOutgoingOps = [];
|
|
117
120
|
// cache incoming ops that arrive when partial loading
|
|
118
121
|
this.deferIncomingOps = true;
|
|
@@ -176,6 +179,7 @@ export class SharedSegmentSequence extends SharedObject {
|
|
|
176
179
|
* release, as group ops are redundant with the native batching capabilities
|
|
177
180
|
* of the runtime
|
|
178
181
|
*/
|
|
182
|
+
// eslint-disable-next-line import/no-deprecated
|
|
179
183
|
groupOperation(groupOp) {
|
|
180
184
|
this.guardReentrancy(() => this.client.localTransaction(groupOp));
|
|
181
185
|
}
|
|
@@ -410,7 +414,9 @@ export class SharedSegmentSequence extends SharedObject {
|
|
|
410
414
|
assert(originalRefSeq !== undefined, 0x8bb /* Expected a recorded refSeq when resubmitting an op */);
|
|
411
415
|
this.useResubmitRefSeq(originalRefSeq, () => {
|
|
412
416
|
if (!this.intervalCollections.tryResubmitMessage(content, localOpMetadata)) {
|
|
413
|
-
this.submitSequenceMessage(this.client.regeneratePendingOp(content,
|
|
417
|
+
this.submitSequenceMessage(this.client.regeneratePendingOp(content,
|
|
418
|
+
// eslint-disable-next-line import/no-deprecated
|
|
419
|
+
localOpMetadata));
|
|
414
420
|
}
|
|
415
421
|
});
|
|
416
422
|
}
|
package/lib/sequence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAMvE,OAAO;AACN,gDAAgD;AAChD,MAAM,EAYN,kBAAkB,EAOlB,qBAAqB,EAAE,gDAAgD;AACvE,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAE9F,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,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ACd,SAAS,gBAAgB,CAAI,QAAiB;QAC7C,IAAI,KAAK,GAAG,CAAC,EAAE;YACd,YAAY,CAAC,KAAK,CAAC,CAAC;SACpB;QACD,KAAK,EAAE,CAAC;QACR,IAAI;YACH,OAAO,QAAQ,EAAE,CAAC;SAClB;gBAAS;YACT,KAAK,EAAE,CAAC;SACR;IACF,CAAC;IAED,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,UAAU,yBAAyB;IACxC,mBAAmB,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,sBAAsB,GAAG,2CAA2C,CAAC;AAC3E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,EAAE;IACxD,MAAM,IAAI,YAAY,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIChannelStorageService,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\tIMergeTreeGroupMsg,\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tLocalReferencePosition,\n\tMergeTreeDeltaType,\n\tMergeTreeRevertibleDriver,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\tSegmentGroup,\n\tSlidingPreference,\n\tcreateAnnotateRangeOp, // eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertOp,\n\tcreateObliterateRangeOp,\n\tcreateRemoveRangeOp,\n\tmatchProperties,\n} from \"@fluidframework/merge-tree/internal\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ISummaryTreeWithStats, ITelemetryContext } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\nimport { SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { LoggingError, createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\n\nimport { IIntervalCollection, SequenceIntervalCollectionValueType } from \"./intervalCollection.js\";\nimport { IMapOperation, IntervalCollectionMap } from \"./intervalCollectionMap.js\";\nimport { IMapMessageLocalMetadata, IValueChanged } from \"./intervalCollectionMapInterfaces.js\";\nimport { SequenceInterval } from \"./intervals/index.js\";\nimport { SequenceDeltaEvent, SequenceMaintenanceEvent } from \"./sequenceDeltaEvent.js\";\nimport { ISharedIntervalCollection } from \"./sharedIntervalCollection.js\";\n\nconst snapshotFileName = \"header\";\nconst contentPath = \"content\";\n\n/**\n * Events emitted in response to changes to the sequence data.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"sequenceDelta\"\n *\n * The sequenceDelta event is emitted when segments are inserted, annotated, or removed.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n *\n * ### \"maintenance\"\n *\n * The maintenance event is emitted when segments are modified during merge-tree maintenance.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n * @alpha\n */\nexport interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {\n\t(\n\t\tevent: \"createIntervalCollection\",\n\t\tlistener: (label: string, local: boolean, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"sequenceDelta\",\n\t\tlistener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n}\n\n/**\n * @alpha\n */\nexport abstract class SharedSegmentSequence<T extends ISegment>\n\textends SharedObject<ISharedSegmentSequenceEvents>\n\timplements ISharedIntervalCollection<SequenceInterval>, MergeTreeRevertibleDriver\n{\n\tget loaded(): Promise<void> {\n\t\treturn this.loadedDeferred.promise;\n\t}\n\n\t/**\n\t * This is a safeguard to avoid problematic reentrancy of local ops. This type of scenario occurs if the user of SharedString subscribes\n\t * to the `sequenceDelta` event and uses the callback for a local op to submit further local ops.\n\t * Historically (before 2.0.0-internal.6.1.0), doing so would result in eventual consistency issues or a corrupted document.\n\t * These issues were fixed in #16815 which makes such reentrancy no different from applying the ops in order but not from within the change events,\n\t * but there is still little test coverage for reentrant scenarios.\n\t * Additionally, applications submitting ops from inside change events need to take extreme care that their data models also support reentrancy.\n\t * Since this is likely not the case, by default SharedString throws when encountering reentrant ops.\n\t *\n\t * An application using SharedString which explicitly wants to opt in to allowing reentrancy anyway can set `sharedStringPreventReentrancy`\n\t * on the data store options to `false`.\n\t */\n\tprotected guardReentrancy: <TRet>(callback: () => TRet) => TRet;\n\n\tprivate static createOpsFromDelta(event: SequenceDeltaEvent): IMergeTreeDeltaOp[] {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfor (const r of event.ranges) {\n\t\t\tswitch (event.deltaOperation) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tconst lastAnnotate = ops[ops.length - 1] as IMergeTreeAnnotateMsg;\n\t\t\t\t\tconst props: PropertySet = {};\n\t\t\t\t\tfor (const key of Object.keys(r.propertyDeltas)) {\n\t\t\t\t\t\tprops[key] = r.segment.properties?.[key] ?? null;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastAnnotate &&\n\t\t\t\t\t\tlastAnnotate.pos2 === r.position &&\n\t\t\t\t\t\tmatchProperties(lastAnnotate.props, props)\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastAnnotate.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateAnnotateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tops.push(createInsertOp(r.position, r.segment.clone().toJSONObject()));\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeRemoveMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x3ff /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateRemoveRangeOp(r.position, r.position + r.segment.cachedLength),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x874 /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateObliterateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\treturn ops;\n\t}\n\n\t/**\n\t * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.\n\t * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process\n\t * incoming leave/join ops before putting an op that this DDS submits over the wire.\n\t *\n\t * E.g. SharedString submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime\n\t * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber\n\t * on the SharedString op is 11.\n\t *\n\t * The reference sequence numbers placed in this queue are also not accurate for stashed ops due to how the applyStashedOp\n\t * flow works at the runtime level. This is a legitimate bug, and AB#6602 tracks one way to fix it (stop reaching all the way\n\t * to deltaManager's lastSequenceNumber to obtain refSeq, instead leveraging some analogous notion on the container or datastore\n\t * runtime).\n\t */\n\tprivate readonly inFlightRefSeqs = new Deque<number>();\n\n\tprivate ongoingResubmitRefSeq: number | undefined;\n\n\t/**\n\t * Gets the reference sequence number (i.e. sequence number of the runtime's last processed op) for an op submitted\n\t * in the current context.\n\t *\n\t * This value can be optionally overridden using `useResubmitRefSeq`.\n\t * IntervalCollection's resubmit logic currently relies on preserving merge information from when the op was originally submitted,\n\t * even if the op is resubmitted more than once. Thus during resubmit, `inFlightRefSeqs` gets populated with the\n\t * original refSeq rather than the refSeq at the time of reconnection.\n\t *\n\t * @remarks - In some not fully understood cases, the runtime may process incoming ops before putting an op that this\n\t * DDS submits over the wire. See `inFlightRefSeqs` for more details.\n\t */\n\tprivate get currentRefSeq() {\n\t\treturn this.ongoingResubmitRefSeq ?? this.runtime.deltaManager.lastSequenceNumber;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprotected client: Client;\n\t/** `Deferred` that triggers once the object is loaded */\n\tprotected loadedDeferred = new Deferred<void>();\n\t// cache out going ops created when partial loading\n\tprivate readonly loadedDeferredOutgoingOps: [IMergeTreeOp, SegmentGroup | SegmentGroup[]][] =\n\t\t[];\n\t// cache incoming ops that arrive when partial loading\n\tprivate deferIncomingOps = true;\n\tprivate readonly loadedDeferredIncomingOps: ISequencedDocumentMessage[] = [];\n\n\tprivate messagesSinceMSNChange: ISequencedDocumentMessage[] = [];\n\tprivate readonly intervalCollections: IntervalCollectionMap<SequenceInterval>;\n\tconstructor(\n\t\tprivate readonly dataStoreRuntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly segmentFromSpec: (spec: IJSONSegment) => ISegment,\n\t) {\n\t\tsuper(id, dataStoreRuntime, attributes, \"fluid_sequence_\");\n\n\t\tconst getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);\n\t\tthis.guardReentrancy =\n\t\t\tdataStoreRuntime.options.sharedStringPreventReentrancy ?? true\n\t\t\t\t? ensureNoReentrancy\n\t\t\t\t: createReentrancyDetector((depth) => {\n\t\t\t\t\t\tif (totalReentrancyLogs > 0) {\n\t\t\t\t\t\t\ttotalReentrancyLogs--;\n\t\t\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t\t\t{ eventName: \"LocalOpReentry\", depth },\n\t\t\t\t\t\t\t\tnew LoggingError(reentrancyErrorMessage),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t });\n\n\t\tthis.loadedDeferred.promise.catch((error) => {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"SequenceLoadFailed\" }, error);\n\t\t});\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tthis.client = new Client(\n\t\t\tsegmentFromSpec,\n\t\t\tcreateChildLogger({\n\t\t\t\tlogger: this.logger,\n\t\t\t\tnamespace: \"SharedSegmentSequence.MergeTreeClient\",\n\t\t\t}),\n\t\t\tdataStoreRuntime.options,\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.client.prependListener(\"delta\", (opArgs, deltaArgs) => {\n\t\t\tconst event = new SequenceDeltaEvent(opArgs, deltaArgs, this.client);\n\t\t\tif (event.isLocal) {\n\t\t\t\tthis.submitSequenceMessage(opArgs.op);\n\t\t\t}\n\t\t\tthis.emit(\"sequenceDelta\", event, this);\n\t\t});\n\n\t\tthis.client.on(\"maintenance\", (args, opArgs) => {\n\t\t\tthis.emit(\"maintenance\", new SequenceMaintenanceEvent(opArgs, args, this.client), this);\n\t\t});\n\n\t\tthis.intervalCollections = new IntervalCollectionMap(\n\t\t\tthis.serializer,\n\t\t\tthis.handle,\n\t\t\t(op, localOpMetadata) => {\n\t\t\t\tif (!this.isAttached()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata);\n\t\t\t},\n\t\t\tnew SequenceIntervalCollectionValueType(),\n\t\t\tdataStoreRuntime.options,\n\t\t);\n\t}\n\n\t/**\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tpublic removeRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.removeRangeLocal(start, end));\n\t}\n\n\t/**\n\t * Obliterate is similar to remove, but differs in that segments concurrently\n\t * inserted into an obliterated range will also be removed\n\t *\n\t * @param start - The inclusive start of the range to obliterate\n\t * @param end - The exclusive end of the range to obliterate\n\t */\n\tpublic obliterateRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.obliterateRangeLocal(start, end));\n\t}\n\n\t/**\n\t * @deprecated The ability to create group ops will be removed in an upcoming\n\t * release, as group ops are redundant with the native batching capabilities\n\t * of the runtime\n\t */\n\tpublic groupOperation(groupOp: IMergeTreeGroupMsg) {\n\t\tthis.guardReentrancy(() => this.client.localTransaction(groupOp));\n\t}\n\n\t/**\n\t * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.\n\t * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.\n\t * @param pos - Character position (index) into the current local view of the SharedString.\n\t */\n\tpublic getContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\treturn this.client.getContainingSegment<T>(pos);\n\t}\n\n\t/**\n\t * Returns the length of the current sequence for the client\n\t */\n\tpublic getLength() {\n\t\treturn this.client.getLength();\n\t}\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this sequence\n\t * @param segment - The segment to get the position of\n\t */\n\tpublic getPosition(segment: ISegment): number {\n\t\treturn this.client.getPosition(segment);\n\t}\n\n\t/**\n\t * Annotates the range with the provided properties\n\t *\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t *\n\t */\n\tpublic annotateRange(start: number, end: number, props: PropertySet): void {\n\t\tthis.guardReentrancy(() => this.client.annotateRangeLocal(start, end, props));\n\t}\n\n\tpublic getPropertiesAtPosition(pos: number) {\n\t\treturn this.client.getPropertiesAtPosition(pos);\n\t}\n\n\tpublic getRangeExtentsOfPosition(pos: number) {\n\t\treturn this.client.getRangeExtentsOfPosition(pos);\n\t}\n\n\t/**\n\t * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include\n\t * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t */\n\tpublic createLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this.client.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of `ReferenceType`. To handle this case specifically, one may wish\n\t * to look at the segment returned by `ReferencePosition.getSegment`.\n\t */\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this.client.localReferencePositionToPosition(lref);\n\t}\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this SharedString.\n\t */\n\tpublic removeLocalReferencePosition(lref: LocalReferencePosition) {\n\t\treturn this.client.removeLocalReferencePosition(lref);\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\treturn this.client.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tremoteClientId,\n\t\t);\n\t}\n\n\tprivate submitSequenceMessage(message: IMergeTreeOp) {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\n\t\tconst metadata = this.client.peekPendingSegmentGroups(\n\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t);\n\n\t\t// if loading isn't complete, we need to cache\n\t\t// local ops until loading is complete, and then\n\t\t// they will be present\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\tthis.loadedDeferredOutgoingOps.push(metadata ? [message, metadata] : (message as any));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(message, metadata);\n\t\t}\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition) {\n\t\treturn this.client.posFromRelativePos(relativePos);\n\t}\n\n\t/**\n\t * Walk the underlying segments of the sequence.\n\t * The walked segments may extend beyond the range if the segments cross the\n\t * ranges start or end boundaries.\n\t *\n\t * Set split range to true to ensure only segments within the range are walked.\n\t *\n\t * @param handler - The function to handle each segment. Traversal ends if\n\t * this function returns true.\n\t * @param start - Optional. The start of range walk.\n\t * @param end - Optional. The end of range walk\n\t * @param accum - Optional. An object that will be passed to the handler for accumulation\n\t * @param splitRange - Optional. Splits boundary segments on the range boundaries\n\t */\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis.client.walkSegments(handler, start, end, accum as TClientData, splitRange);\n\t}\n\n\t/**\n\t * @returns The most recent sequence number which has been acked by the server and processed by this\n\t * SharedSegmentSequence.\n\t */\n\tpublic getCurrentSeq() {\n\t\treturn this.client.getCurrentSeq();\n\t}\n\n\t/**\n\t * Inserts a segment directly before a `ReferencePosition`.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertAtReferencePosition(pos: ReferencePosition, segment: T): void {\n\t\tthis.guardReentrancy(() => this.client.insertAtReferencePositionLocal(pos, segment));\n\t}\n\t/**\n\t * Inserts a segment\n\t * @param start - The position to insert the segment at\n\t * @param spec - The segment to inserts spec\n\t */\n\tpublic insertFromSpec(pos: number, spec: IJSONSegment): void {\n\t\tconst segment = this.segmentFromSpec(spec);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Retrieves the interval collection keyed on `label`. If no such interval collection exists,\n\t * creates one.\n\t */\n\tpublic getIntervalCollection(label: string): IIntervalCollection<SequenceInterval> {\n\t\treturn this.intervalCollections.get(label);\n\t}\n\n\t/**\n\t * @returns An iterable object that enumerates the IntervalCollection labels.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const iter = this.getIntervalCollectionKeys();\n\t * for (key of iter)\n\t * const collection = this.getIntervalCollection(key);\n\t * ...\n\t * ```\n\t */\n\tpublic getIntervalCollectionLabels(): IterableIterator<string> {\n\t\treturn this.intervalCollections.keys();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}\n\t */\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// conditionally write the interval collection blob\n\t\t// only if it has entries\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tbuilder.addBlob(snapshotFileName, this.intervalCollections.serialize(serializer));\n\t\t}\n\n\t\tbuilder.addWithStats(contentPath, this.summarizeMergeTree(serializer));\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer over the GC data for this SharedMatrix.\n\t * All the IFluidHandle's represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: IFluidSerializer) {\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tthis.intervalCollections.serialize(serializer);\n\t\t}\n\n\t\tthis.client.serializeGCData(this.handle, serializer);\n\t}\n\n\t/**\n\t * Replace the range specified from start to end with the provided segment\n\t * This is done by inserting the segment at the end of the range, followed\n\t * by removing the contents of the range\n\t * For a zero or reverse range (start \\>= end), insert at end do not remove anything\n\t * @param start - The start of the range to replace\n\t * @param end - The end of the range to replace\n\t * @param segment - The segment that will replace the range\n\t */\n\tprotected replaceRange(start: number, end: number, segment: ISegment): void {\n\t\t// Insert at the max end of the range when start > end, but still remove the range later\n\t\tconst insertIndex: number = Math.max(start, end);\n\n\t\t// Insert first, so local references can slide to the inserted seg if any\n\t\tconst insert = this.guardReentrancy(() =>\n\t\t\tthis.client.insertSegmentLocal(insertIndex, segment),\n\t\t);\n\n\t\tif (insert && start < end) {\n\t\t\tthis.removeRange(start, end);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n\t */\n\tprotected onConnect() {\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n\t */\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.shift();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0x8bb /* Expected a recorded refSeq when resubmitting an op */,\n\t\t);\n\t\tthis.useResubmitRefSeq(originalRefSeq, () => {\n\t\t\tif (\n\t\t\t\t!this.intervalCollections.tryResubmitMessage(\n\t\t\t\t\tcontent,\n\t\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.submitSequenceMessage(\n\t\t\t\t\tthis.client.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\tif (await storage.contains(snapshotFileName)) {\n\t\t\tconst blob = await storage.readBlob(snapshotFileName);\n\t\t\tconst header = bufferToString(blob, \"utf8\");\n\t\t\tthis.intervalCollections.populate(header);\n\t\t}\n\n\t\ttry {\n\t\t\t// this will load the header, and return a promise\n\t\t\t// that will resolve when the body is loaded\n\t\t\t// and the catchup ops are available.\n\t\t\tconst { catchupOpsP } = await this.client.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, contentPath),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\t// setup a promise to process the\n\t\t\t// catch up ops, and finishing the loading process\n\t\t\tconst loadCatchUpOps = catchupOpsP\n\t\t\t\t.then((msgs) => {\n\t\t\t\t\tmsgs.forEach((m) => {\n\t\t\t\t\t\tconst collabWindow = this.client.getCollabWindow();\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tm.minimumSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.referenceSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.sequenceNumber <= collabWindow.minSeq ||\n\t\t\t\t\t\t\t// sequenceNumber could be the same if messages are part of a grouped batch\n\t\t\t\t\t\t\tm.sequenceNumber < collabWindow.currentSeq\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Invalid catchup operations in snapshot: ${JSON.stringify({\n\t\t\t\t\t\t\t\t\top: {\n\t\t\t\t\t\t\t\t\t\tseq: m.sequenceNumber,\n\t\t\t\t\t\t\t\t\t\tminSeq: m.minimumSequenceNumber,\n\t\t\t\t\t\t\t\t\t\trefSeq: m.referenceSequenceNumber,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tcollabWindow: {\n\t\t\t\t\t\t\t\t\t\tseq: collabWindow.currentSeq,\n\t\t\t\t\t\t\t\t\t\tminSeq: collabWindow.minSeq,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t})}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.processMergeTreeMsg(m);\n\t\t\t\t\t});\n\t\t\t\t\tthis.loadFinished();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.loadFinished(error);\n\t\t\t\t});\n\t\t\tif (this.dataStoreRuntime.options.sequenceInitializeFromHeaderOnly !== true) {\n\t\t\t\t// if we not doing partial load, await the catch up ops,\n\t\t\t\t// and the finalization of the load\n\t\t\t\tawait loadCatchUpOps;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.loadFinished(error);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (local) {\n\t\t\tconst recordedRefSeq = this.inFlightRefSeqs.shift();\n\t\t\tassert(recordedRefSeq !== undefined, 0x8bc /* No pending recorded refSeq found */);\n\t\t\t// TODO: AB#7076: Some equivalent assert should be enabled. This fails some e2e stashed op tests because\n\t\t\t// the deltaManager may have seen more messages than the runtime has processed while amidst the stashed op\n\t\t\t// flow, so e.g. when `applyStashedOp` is called and the DDS is put in a state where it expects an ack for\n\t\t\t// one of its messages, the delta manager has actually already seen subsequent messages from collaborators\n\t\t\t// which the in-flight message is concurrent to.\n\t\t\t// See \"handles stashed ops created on top of sequenced local ops\" for one such test case.\n\t\t\t// assert(recordedRefSeq <= message.referenceSequenceNumber, \"RefSeq mismatch\");\n\t\t}\n\n\t\t// if loading isn't complete, we need to cache all\n\t\t// incoming ops to be applied after loading is complete\n\t\tif (this.deferIncomingOps) {\n\t\t\tassert(!local, 0x072 /* \"Unexpected local op when loading not finished\" */);\n\t\t\tthis.loadedDeferredIncomingOps.push(message);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tmessage.type === MessageType.Operation,\n\t\t\t\t0x073 /* \"Sequence message not operation\" */,\n\t\t\t);\n\n\t\t\tconst handled = this.intervalCollections.tryProcessMessage(\n\t\t\t\tmessage.contents as IMapOperation,\n\t\t\t\tlocal,\n\t\t\t\tmessage,\n\t\t\t\tlocalOpMetadata,\n\t\t\t);\n\n\t\t\tif (!handled) {\n\t\t\t\tthis.processMergeTreeMsg(message, local);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}\n\t */\n\tprotected didAttach() {\n\t\t// If we are not local, and we've attached we need to start generating and sending ops\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore() {\n\t\tsuper.initializeLocalCore();\n\t\tthis.loadFinished();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): void {\n\t\tif (!this.intervalCollections.tryApplyStashedOp(content)) {\n\t\t\tthis.client.applyStashedOp(content);\n\t\t}\n\t}\n\n\tprivate summarizeMergeTree(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Are we fully loaded? If not, things will go south\n\t\tassert(\n\t\t\tthis.loadedDeferred.isCompleted,\n\t\t\t0x074 /* \"Snapshot called when not fully loaded\" */,\n\t\t);\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tthis.processMinSequenceNumberChanged(minSeq);\n\n\t\tthis.messagesSinceMSNChange.forEach((m) => {\n\t\t\tm.minimumSequenceNumber = minSeq;\n\t\t});\n\n\t\treturn this.client.summarize(\n\t\t\tthis.runtime,\n\t\t\tthis.handle,\n\t\t\tserializer,\n\t\t\tthis.messagesSinceMSNChange,\n\t\t);\n\t}\n\n\t/**\n\t *\n\t * @param message - Message with decoded and hydrated handles\n\t */\n\tprivate processMergeTreeMsg(message: ISequencedDocumentMessage, local?: boolean) {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfunction transformOps(event: SequenceDeltaEvent) {\n\t\t\tops.push(...SharedSegmentSequence.createOpsFromDelta(event));\n\t\t}\n\t\tconst needsTransformation = message.referenceSequenceNumber !== message.sequenceNumber - 1;\n\t\tlet stashMessage: Readonly<ISequencedDocumentMessage> = message;\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.on(\"sequenceDelta\", transformOps);\n\t\t\t}\n\t\t}\n\n\t\tthis.client.applyMsg(message, local);\n\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.removeListener(\"sequenceDelta\", transformOps);\n\t\t\t\t// shallow clone the message as we only overwrite top level properties,\n\t\t\t\t// like referenceSequenceNumber and content only\n\t\t\t\tstashMessage = {\n\t\t\t\t\t...message,\n\t\t\t\t\treferenceSequenceNumber: stashMessage.sequenceNumber - 1,\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcontents: ops.length !== 1 ? createGroupOp(...ops) : ops[0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tthis.messagesSinceMSNChange.push(stashMessage);\n\n\t\t\t// Do GC every once in a while...\n\t\t\tif (\n\t\t\t\tthis.messagesSinceMSNChange.length > 20 &&\n\t\t\t\tthis.messagesSinceMSNChange[20].sequenceNumber < message.minimumSequenceNumber\n\t\t\t) {\n\t\t\t\tthis.processMinSequenceNumberChanged(message.minimumSequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate processMinSequenceNumberChanged(minSeq: number) {\n\t\tlet index = 0;\n\t\tfor (; index < this.messagesSinceMSNChange.length; index++) {\n\t\t\tif (this.messagesSinceMSNChange[index].sequenceNumber > minSeq) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index !== 0) {\n\t\t\tthis.messagesSinceMSNChange = this.messagesSinceMSNChange.slice(index);\n\t\t}\n\t}\n\n\tprivate loadFinished(error?: any) {\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\t// Initialize the interval collections\n\t\t\tthis.initializeIntervalCollections();\n\t\t\tif (error) {\n\t\t\t\tthis.loadedDeferred.reject(error);\n\t\t\t\tthrow error;\n\t\t\t} else {\n\t\t\t\t// it is important this series remains synchronous\n\t\t\t\t// first we stop deferring incoming ops, and apply then all\n\t\t\t\tthis.deferIncomingOps = false;\n\t\t\t\tfor (const message of this.loadedDeferredIncomingOps) {\n\t\t\t\t\tthis.processCore(message, false, undefined);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredIncomingOps.length = 0;\n\n\t\t\t\t// then resolve the loaded promise\n\t\t\t\t// and resubmit all the outstanding ops, as the snapshot\n\t\t\t\t// is fully loaded, and all outstanding ops are applied\n\t\t\t\tthis.loadedDeferred.resolve();\n\n\t\t\t\tfor (const [messageContent, opMetadata] of this.loadedDeferredOutgoingOps) {\n\t\t\t\t\tthis.reSubmitCore(messageContent, opMetadata);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredOutgoingOps.length = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate initializeIntervalCollections() {\n\t\t// Listen and initialize new SharedIntervalCollections\n\t\tthis.intervalCollections.eventEmitter.on(\n\t\t\t\"create\",\n\t\t\t({ key, previousValue }: IValueChanged, local: boolean) => {\n\t\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\t\tif (!intervalCollection.attached) {\n\t\t\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t\t\t}\n\t\t\t\tassert(\n\t\t\t\t\tpreviousValue === undefined,\n\t\t\t\t\t0x2c1 /* \"Creating an interval collection that already exists?\" */,\n\t\t\t\t);\n\t\t\t\tthis.emit(\"createIntervalCollection\", key, local, this);\n\t\t\t},\n\t\t);\n\n\t\t// Initialize existing SharedIntervalCollections\n\t\tfor (const key of this.intervalCollections.keys()) {\n\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"currently applicable reference sequence number\" for the duration of the callback.\n\t * See remarks on `currentRefSeq` for more context.\n\t */\n\tprivate useResubmitRefSeq(refSeq: number, callback: () => void) {\n\t\tconst previousResubmitRefSeq = this.ongoingResubmitRefSeq;\n\t\tthis.ongoingResubmitRefSeq = refSeq;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tthis.ongoingResubmitRefSeq = previousResubmitRefSeq;\n\t\t}\n\t}\n}\n\nfunction createReentrancyDetector(\n\tonReentrancy: (depth: number) => void,\n): <T>(callback: () => T) => T {\n\tlet depth = 0;\n\tfunction detectReentrancy<T>(callback: () => T): T {\n\t\tif (depth > 0) {\n\t\t\tonReentrancy(depth);\n\t\t}\n\t\tdepth++;\n\t\ttry {\n\t\t\treturn callback();\n\t\t} finally {\n\t\t\tdepth--;\n\t\t}\n\t}\n\n\treturn detectReentrancy;\n}\n\n/**\n * Apps which generate reentrant behavior may do so at a high frequency.\n * Logging even per-SharedSegmentSequence instance might be too noisy, and having a few logs from a session\n * is likely enough.\n */\nlet totalReentrancyLogs = 3;\n\n/**\n * Resets the reentrancy log counter. Test-only API.\n */\nexport function resetReentrancyLogCounter() {\n\ttotalReentrancyLogs = 3;\n}\n\nconst reentrancyErrorMessage = \"Reentrancy detected in sequence local ops\";\nconst ensureNoReentrancy = createReentrancyDetector(() => {\n\tthrow new LoggingError(reentrancyErrorMessage);\n});\n"]}
|
|
1
|
+
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAMvE,OAAO;AACN,gDAAgD;AAChD,MAAM,EAcN,kBAAkB,EAQlB,qBAAqB;AACrB,gDAAgD;AAChD,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAE9F,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,KAAK,MAAM,oBAAoB,CAAC;AAEvC,OAAO,EAAuB,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAiB,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGlF,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAGvF,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,WAAW,GAAG,SAAS,CAAC;AAmD9B;;GAEG;AACH,MAAM,OAAgB,qBACrB,SAAQ,YAA0C;IAGlD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;IACpC,CAAC;IAgBO,MAAM,CAAC,kBAAkB,CAAC,KAAyB;Q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sB,GAAG,2CAA2C,CAAC;AAC3E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,EAAE;IACxD,MAAM,IAAI,YAAY,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IEventThisPlaceHolder } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIChannelStorageService,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tClient,\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeGroupMsg,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tLocalReferencePosition,\n\tMergeTreeDeltaType,\n\tMergeTreeRevertibleDriver,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\t// eslint-disable-next-line import/no-deprecated\n\tSegmentGroup,\n\tSlidingPreference,\n\tcreateAnnotateRangeOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertOp,\n\tcreateObliterateRangeOp,\n\tcreateRemoveRangeOp,\n\tmatchProperties,\n} from \"@fluidframework/merge-tree/internal\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ISummaryTreeWithStats, ITelemetryContext } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\nimport { SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { LoggingError, createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\n\nimport { IIntervalCollection, SequenceIntervalCollectionValueType } from \"./intervalCollection.js\";\nimport { IMapOperation, IntervalCollectionMap } from \"./intervalCollectionMap.js\";\nimport { IMapMessageLocalMetadata, IValueChanged } from \"./intervalCollectionMapInterfaces.js\";\nimport { SequenceInterval } from \"./intervals/index.js\";\nimport { SequenceDeltaEvent, SequenceMaintenanceEvent } from \"./sequenceDeltaEvent.js\";\nimport { ISharedIntervalCollection } from \"./sharedIntervalCollection.js\";\n\nconst snapshotFileName = \"header\";\nconst contentPath = \"content\";\n\n/**\n * Events emitted in response to changes to the sequence data.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"sequenceDelta\"\n *\n * The sequenceDelta event is emitted when segments are inserted, annotated, or removed.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n *\n * ### \"maintenance\"\n *\n * The maintenance event is emitted when segments are modified during merge-tree maintenance.\n *\n * #### Listener signature\n *\n * ```typescript\n * (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void\n * ```\n * - `event` - Various information on the segments that were modified.\n *\n * - `target` - The sequence itself.\n * @alpha\n */\nexport interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {\n\t(\n\t\tevent: \"createIntervalCollection\",\n\t\tlistener: (label: string, local: boolean, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"sequenceDelta\",\n\t\tlistener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void,\n\t): void;\n}\n\n/**\n * @alpha\n */\nexport abstract class SharedSegmentSequence<T extends ISegment>\n\textends SharedObject<ISharedSegmentSequenceEvents>\n\timplements ISharedIntervalCollection<SequenceInterval>, MergeTreeRevertibleDriver\n{\n\tget loaded(): Promise<void> {\n\t\treturn this.loadedDeferred.promise;\n\t}\n\n\t/**\n\t * This is a safeguard to avoid problematic reentrancy of local ops. This type of scenario occurs if the user of SharedString subscribes\n\t * to the `sequenceDelta` event and uses the callback for a local op to submit further local ops.\n\t * Historically (before 2.0.0-internal.6.1.0), doing so would result in eventual consistency issues or a corrupted document.\n\t * These issues were fixed in #16815 which makes such reentrancy no different from applying the ops in order but not from within the change events,\n\t * but there is still little test coverage for reentrant scenarios.\n\t * Additionally, applications submitting ops from inside change events need to take extreme care that their data models also support reentrancy.\n\t * Since this is likely not the case, by default SharedString throws when encountering reentrant ops.\n\t *\n\t * An application using SharedString which explicitly wants to opt in to allowing reentrancy anyway can set `sharedStringPreventReentrancy`\n\t * on the data store options to `false`.\n\t */\n\tprotected guardReentrancy: <TRet>(callback: () => TRet) => TRet;\n\n\tprivate static createOpsFromDelta(event: SequenceDeltaEvent): IMergeTreeDeltaOp[] {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfor (const r of event.ranges) {\n\t\t\tswitch (event.deltaOperation) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tconst lastAnnotate = ops[ops.length - 1] as IMergeTreeAnnotateMsg;\n\t\t\t\t\tconst props: PropertySet = {};\n\t\t\t\t\tfor (const key of Object.keys(r.propertyDeltas)) {\n\t\t\t\t\t\tprops[key] = r.segment.properties?.[key] ?? null;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tlastAnnotate &&\n\t\t\t\t\t\tlastAnnotate.pos2 === r.position &&\n\t\t\t\t\t\tmatchProperties(lastAnnotate.props, props)\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastAnnotate.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateAnnotateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tops.push(createInsertOp(r.position, r.segment.clone().toJSONObject()));\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeRemoveMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x3ff /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateRemoveRangeOp(r.position, r.position + r.segment.cachedLength),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tconst lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;\n\t\t\t\t\tif (lastRem?.pos1 === r.position) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tlastRem.pos2 !== undefined,\n\t\t\t\t\t\t\t0x874 /* pos2 should not be undefined here */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlastRem.pos2 += r.segment.cachedLength;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tops.push(\n\t\t\t\t\t\t\tcreateObliterateRangeOp(\n\t\t\t\t\t\t\t\tr.position,\n\t\t\t\t\t\t\t\tr.position + r.segment.cachedLength,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\treturn ops;\n\t}\n\n\t/**\n\t * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.\n\t * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process\n\t * incoming leave/join ops before putting an op that this DDS submits over the wire.\n\t *\n\t * E.g. SharedString submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime\n\t * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber\n\t * on the SharedString op is 11.\n\t *\n\t * The reference sequence numbers placed in this queue are also not accurate for stashed ops due to how the applyStashedOp\n\t * flow works at the runtime level. This is a legitimate bug, and AB#6602 tracks one way to fix it (stop reaching all the way\n\t * to deltaManager's lastSequenceNumber to obtain refSeq, instead leveraging some analogous notion on the container or datastore\n\t * runtime).\n\t */\n\tprivate readonly inFlightRefSeqs = new Deque<number>();\n\n\tprivate ongoingResubmitRefSeq: number | undefined;\n\n\t/**\n\t * Gets the reference sequence number (i.e. sequence number of the runtime's last processed op) for an op submitted\n\t * in the current context.\n\t *\n\t * This value can be optionally overridden using `useResubmitRefSeq`.\n\t * IntervalCollection's resubmit logic currently relies on preserving merge information from when the op was originally submitted,\n\t * even if the op is resubmitted more than once. Thus during resubmit, `inFlightRefSeqs` gets populated with the\n\t * original refSeq rather than the refSeq at the time of reconnection.\n\t *\n\t * @remarks - In some not fully understood cases, the runtime may process incoming ops before putting an op that this\n\t * DDS submits over the wire. See `inFlightRefSeqs` for more details.\n\t */\n\tprivate get currentRefSeq() {\n\t\treturn this.ongoingResubmitRefSeq ?? this.runtime.deltaManager.lastSequenceNumber;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprotected client: Client;\n\t/** `Deferred` that triggers once the object is loaded */\n\tprotected loadedDeferred = new Deferred<void>();\n\t// cache out going ops created when partial loading\n\t// eslint-disable-next-line import/no-deprecated\n\tprivate readonly loadedDeferredOutgoingOps: [IMergeTreeOp, SegmentGroup | SegmentGroup[]][] =\n\t\t[];\n\t// cache incoming ops that arrive when partial loading\n\tprivate deferIncomingOps = true;\n\tprivate readonly loadedDeferredIncomingOps: ISequencedDocumentMessage[] = [];\n\n\tprivate messagesSinceMSNChange: ISequencedDocumentMessage[] = [];\n\tprivate readonly intervalCollections: IntervalCollectionMap<SequenceInterval>;\n\tconstructor(\n\t\tprivate readonly dataStoreRuntime: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly segmentFromSpec: (spec: IJSONSegment) => ISegment,\n\t) {\n\t\tsuper(id, dataStoreRuntime, attributes, \"fluid_sequence_\");\n\n\t\tconst getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);\n\t\tthis.guardReentrancy =\n\t\t\tdataStoreRuntime.options.sharedStringPreventReentrancy ?? true\n\t\t\t\t? ensureNoReentrancy\n\t\t\t\t: createReentrancyDetector((depth) => {\n\t\t\t\t\t\tif (totalReentrancyLogs > 0) {\n\t\t\t\t\t\t\ttotalReentrancyLogs--;\n\t\t\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t\t\t{ eventName: \"LocalOpReentry\", depth },\n\t\t\t\t\t\t\t\tnew LoggingError(reentrancyErrorMessage),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t });\n\n\t\tthis.loadedDeferred.promise.catch((error) => {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"SequenceLoadFailed\" }, error);\n\t\t});\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tthis.client = new Client(\n\t\t\tsegmentFromSpec,\n\t\t\tcreateChildLogger({\n\t\t\t\tlogger: this.logger,\n\t\t\t\tnamespace: \"SharedSegmentSequence.MergeTreeClient\",\n\t\t\t}),\n\t\t\tdataStoreRuntime.options,\n\t\t\tgetMinInFlightRefSeq,\n\t\t);\n\n\t\tthis.client.prependListener(\"delta\", (opArgs, deltaArgs) => {\n\t\t\tconst event = new SequenceDeltaEvent(opArgs, deltaArgs, this.client);\n\t\t\tif (event.isLocal) {\n\t\t\t\tthis.submitSequenceMessage(opArgs.op);\n\t\t\t}\n\t\t\tthis.emit(\"sequenceDelta\", event, this);\n\t\t});\n\n\t\tthis.client.on(\"maintenance\", (args, opArgs) => {\n\t\t\tthis.emit(\"maintenance\", new SequenceMaintenanceEvent(opArgs, args, this.client), this);\n\t\t});\n\n\t\tthis.intervalCollections = new IntervalCollectionMap(\n\t\t\tthis.serializer,\n\t\t\tthis.handle,\n\t\t\t(op, localOpMetadata) => {\n\t\t\t\tif (!this.isAttached()) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata);\n\t\t\t},\n\t\t\tnew SequenceIntervalCollectionValueType(),\n\t\t\tdataStoreRuntime.options,\n\t\t);\n\t}\n\n\t/**\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tpublic removeRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.removeRangeLocal(start, end));\n\t}\n\n\t/**\n\t * Obliterate is similar to remove, but differs in that segments concurrently\n\t * inserted into an obliterated range will also be removed\n\t *\n\t * @param start - The inclusive start of the range to obliterate\n\t * @param end - The exclusive end of the range to obliterate\n\t */\n\tpublic obliterateRange(start: number, end: number): void {\n\t\tthis.guardReentrancy(() => this.client.obliterateRangeLocal(start, end));\n\t}\n\n\t/**\n\t * @deprecated The ability to create group ops will be removed in an upcoming\n\t * release, as group ops are redundant with the native batching capabilities\n\t * of the runtime\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic groupOperation(groupOp: IMergeTreeGroupMsg) {\n\t\tthis.guardReentrancy(() => this.client.localTransaction(groupOp));\n\t}\n\n\t/**\n\t * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.\n\t * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.\n\t * @param pos - Character position (index) into the current local view of the SharedString.\n\t */\n\tpublic getContainingSegment(pos: number): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\treturn this.client.getContainingSegment<T>(pos);\n\t}\n\n\t/**\n\t * Returns the length of the current sequence for the client\n\t */\n\tpublic getLength() {\n\t\treturn this.client.getLength();\n\t}\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this sequence\n\t * @param segment - The segment to get the position of\n\t */\n\tpublic getPosition(segment: ISegment): number {\n\t\treturn this.client.getPosition(segment);\n\t}\n\n\t/**\n\t * Annotates the range with the provided properties\n\t *\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t *\n\t */\n\tpublic annotateRange(start: number, end: number, props: PropertySet): void {\n\t\tthis.guardReentrancy(() => this.client.annotateRangeLocal(start, end, props));\n\t}\n\n\tpublic getPropertiesAtPosition(pos: number) {\n\t\treturn this.client.getPropertiesAtPosition(pos);\n\t}\n\n\tpublic getRangeExtentsOfPosition(pos: number) {\n\t\treturn this.client.getRangeExtentsOfPosition(pos);\n\t}\n\n\t/**\n\t * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include\n\t * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t */\n\tpublic createLocalReferencePosition(\n\t\tsegment: T,\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this.client.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of `ReferenceType`. To handle this case specifically, one may wish\n\t * to look at the segment returned by `ReferencePosition.getSegment`.\n\t */\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this.client.localReferencePositionToPosition(lref);\n\t}\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this SharedString.\n\t */\n\tpublic removeLocalReferencePosition(lref: LocalReferencePosition) {\n\t\treturn this.client.removeLocalReferencePosition(lref);\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence. The client ref seq must be above the minimum sequence number\n\t * or the return value will be undefined.\n\t * Generally this method is used in conjunction with signals which provide\n\t * point in time values for the below parameters, and is useful for things\n\t * like displaying user position. It should not be used with persisted values\n\t * as persisted values will quickly become invalid as the remoteClientRefSeq\n\t * moves below the minimum sequence number\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\treturn this.client.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tremoteClientId,\n\t\t);\n\t}\n\n\tprivate submitSequenceMessage(message: IMergeTreeOp) {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inFlightRefSeqs.push(this.currentRefSeq);\n\n\t\tconst metadata = this.client.peekPendingSegmentGroups(\n\t\t\tmessage.type === MergeTreeDeltaType.GROUP ? message.ops.length : 1,\n\t\t);\n\n\t\t// if loading isn't complete, we need to cache\n\t\t// local ops until loading is complete, and then\n\t\t// they will be present\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\tthis.loadedDeferredOutgoingOps.push(metadata ? [message, metadata] : (message as any));\n\t\t} else {\n\t\t\tthis.submitLocalMessage(message, metadata);\n\t\t}\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition) {\n\t\treturn this.client.posFromRelativePos(relativePos);\n\t}\n\n\t/**\n\t * Walk the underlying segments of the sequence.\n\t * The walked segments may extend beyond the range if the segments cross the\n\t * ranges start or end boundaries.\n\t *\n\t * Set split range to true to ensure only segments within the range are walked.\n\t *\n\t * @param handler - The function to handle each segment. Traversal ends if\n\t * this function returns true.\n\t * @param start - Optional. The start of range walk.\n\t * @param end - Optional. The end of range walk\n\t * @param accum - Optional. An object that will be passed to the handler for accumulation\n\t * @param splitRange - Optional. Splits boundary segments on the range boundaries\n\t */\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis.client.walkSegments(handler, start, end, accum as TClientData, splitRange);\n\t}\n\n\t/**\n\t * @returns The most recent sequence number which has been acked by the server and processed by this\n\t * SharedSegmentSequence.\n\t */\n\tpublic getCurrentSeq() {\n\t\treturn this.client.getCurrentSeq();\n\t}\n\n\t/**\n\t * Inserts a segment directly before a `ReferencePosition`.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertAtReferencePosition(pos: ReferencePosition, segment: T): void {\n\t\tthis.guardReentrancy(() => this.client.insertAtReferencePositionLocal(pos, segment));\n\t}\n\t/**\n\t * Inserts a segment\n\t * @param start - The position to insert the segment at\n\t * @param spec - The segment to inserts spec\n\t */\n\tpublic insertFromSpec(pos: number, spec: IJSONSegment): void {\n\t\tconst segment = this.segmentFromSpec(spec);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Retrieves the interval collection keyed on `label`. If no such interval collection exists,\n\t * creates one.\n\t */\n\tpublic getIntervalCollection(label: string): IIntervalCollection<SequenceInterval> {\n\t\treturn this.intervalCollections.get(label);\n\t}\n\n\t/**\n\t * @returns An iterable object that enumerates the IntervalCollection labels.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const iter = this.getIntervalCollectionKeys();\n\t * for (key of iter)\n\t * const collection = this.getIntervalCollection(key);\n\t * ...\n\t * ```\n\t */\n\tpublic getIntervalCollectionLabels(): IterableIterator<string> {\n\t\treturn this.intervalCollections.keys();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}\n\t */\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// conditionally write the interval collection blob\n\t\t// only if it has entries\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tbuilder.addBlob(snapshotFileName, this.intervalCollections.serialize(serializer));\n\t\t}\n\n\t\tbuilder.addWithStats(contentPath, this.summarizeMergeTree(serializer));\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Runs serializer over the GC data for this SharedMatrix.\n\t * All the IFluidHandle's represent routes to other objects.\n\t */\n\tprotected processGCDataCore(serializer: IFluidSerializer) {\n\t\tif (this.intervalCollections.size > 0) {\n\t\t\tthis.intervalCollections.serialize(serializer);\n\t\t}\n\n\t\tthis.client.serializeGCData(this.handle, serializer);\n\t}\n\n\t/**\n\t * Replace the range specified from start to end with the provided segment\n\t * This is done by inserting the segment at the end of the range, followed\n\t * by removing the contents of the range\n\t * For a zero or reverse range (start \\>= end), insert at end do not remove anything\n\t * @param start - The start of the range to replace\n\t * @param end - The end of the range to replace\n\t * @param segment - The segment that will replace the range\n\t */\n\tprotected replaceRange(start: number, end: number, segment: ISegment): void {\n\t\t// Insert at the max end of the range when start > end, but still remove the range later\n\t\tconst insertIndex: number = Math.max(start, end);\n\n\t\t// Insert first, so local references can slide to the inserted seg if any\n\t\tconst insert = this.guardReentrancy(() =>\n\t\t\tthis.client.insertSegmentLocal(insertIndex, segment),\n\t\t);\n\n\t\tif (insert && start < end) {\n\t\t\tthis.removeRange(start, end);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n\t */\n\tprotected onConnect() {\n\t\t// Update merge tree collaboration information with new client ID and then resend pending ops\n\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n\t */\n\tprotected onDisconnect() {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tconst originalRefSeq = this.inFlightRefSeqs.shift();\n\t\tassert(\n\t\t\toriginalRefSeq !== undefined,\n\t\t\t0x8bb /* Expected a recorded refSeq when resubmitting an op */,\n\t\t);\n\t\tthis.useResubmitRefSeq(originalRefSeq, () => {\n\t\t\tif (\n\t\t\t\t!this.intervalCollections.tryResubmitMessage(\n\t\t\t\t\tcontent,\n\t\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.submitSequenceMessage(\n\t\t\t\t\tthis.client.regeneratePendingOp(\n\t\t\t\t\t\tcontent as IMergeTreeOp,\n\t\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\t\tlocalOpMetadata as SegmentGroup | SegmentGroup[],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService) {\n\t\tif (await storage.contains(snapshotFileName)) {\n\t\t\tconst blob = await storage.readBlob(snapshotFileName);\n\t\t\tconst header = bufferToString(blob, \"utf8\");\n\t\t\tthis.intervalCollections.populate(header);\n\t\t}\n\n\t\ttry {\n\t\t\t// this will load the header, and return a promise\n\t\t\t// that will resolve when the body is loaded\n\t\t\t// and the catchup ops are available.\n\t\t\tconst { catchupOpsP } = await this.client.load(\n\t\t\t\tthis.runtime,\n\t\t\t\tnew ObjectStoragePartition(storage, contentPath),\n\t\t\t\tthis.serializer,\n\t\t\t);\n\n\t\t\t// setup a promise to process the\n\t\t\t// catch up ops, and finishing the loading process\n\t\t\tconst loadCatchUpOps = catchupOpsP\n\t\t\t\t.then((msgs) => {\n\t\t\t\t\tmsgs.forEach((m) => {\n\t\t\t\t\t\tconst collabWindow = this.client.getCollabWindow();\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tm.minimumSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.referenceSequenceNumber < collabWindow.minSeq ||\n\t\t\t\t\t\t\tm.sequenceNumber <= collabWindow.minSeq ||\n\t\t\t\t\t\t\t// sequenceNumber could be the same if messages are part of a grouped batch\n\t\t\t\t\t\t\tm.sequenceNumber < collabWindow.currentSeq\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Invalid catchup operations in snapshot: ${JSON.stringify({\n\t\t\t\t\t\t\t\t\top: {\n\t\t\t\t\t\t\t\t\t\tseq: m.sequenceNumber,\n\t\t\t\t\t\t\t\t\t\tminSeq: m.minimumSequenceNumber,\n\t\t\t\t\t\t\t\t\t\trefSeq: m.referenceSequenceNumber,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tcollabWindow: {\n\t\t\t\t\t\t\t\t\t\tseq: collabWindow.currentSeq,\n\t\t\t\t\t\t\t\t\t\tminSeq: collabWindow.minSeq,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t})}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.processMergeTreeMsg(m);\n\t\t\t\t\t});\n\t\t\t\t\tthis.loadFinished();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.loadFinished(error);\n\t\t\t\t});\n\t\t\tif (this.dataStoreRuntime.options.sequenceInitializeFromHeaderOnly !== true) {\n\t\t\t\t// if we not doing partial load, await the catch up ops,\n\t\t\t\t// and the finalization of the load\n\t\t\t\tawait loadCatchUpOps;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.loadFinished(error);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (local) {\n\t\t\tconst recordedRefSeq = this.inFlightRefSeqs.shift();\n\t\t\tassert(recordedRefSeq !== undefined, 0x8bc /* No pending recorded refSeq found */);\n\t\t\t// TODO: AB#7076: Some equivalent assert should be enabled. This fails some e2e stashed op tests because\n\t\t\t// the deltaManager may have seen more messages than the runtime has processed while amidst the stashed op\n\t\t\t// flow, so e.g. when `applyStashedOp` is called and the DDS is put in a state where it expects an ack for\n\t\t\t// one of its messages, the delta manager has actually already seen subsequent messages from collaborators\n\t\t\t// which the in-flight message is concurrent to.\n\t\t\t// See \"handles stashed ops created on top of sequenced local ops\" for one such test case.\n\t\t\t// assert(recordedRefSeq <= message.referenceSequenceNumber, \"RefSeq mismatch\");\n\t\t}\n\n\t\t// if loading isn't complete, we need to cache all\n\t\t// incoming ops to be applied after loading is complete\n\t\tif (this.deferIncomingOps) {\n\t\t\tassert(!local, 0x072 /* \"Unexpected local op when loading not finished\" */);\n\t\t\tthis.loadedDeferredIncomingOps.push(message);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tmessage.type === MessageType.Operation,\n\t\t\t\t0x073 /* \"Sequence message not operation\" */,\n\t\t\t);\n\n\t\t\tconst handled = this.intervalCollections.tryProcessMessage(\n\t\t\t\tmessage.contents as IMapOperation,\n\t\t\t\tlocal,\n\t\t\t\tmessage,\n\t\t\t\tlocalOpMetadata,\n\t\t\t);\n\n\t\t\tif (!handled) {\n\t\t\t\tthis.processMergeTreeMsg(message, local);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}\n\t */\n\tprotected didAttach() {\n\t\t// If we are not local, and we've attached we need to start generating and sending ops\n\t\t// so start collaboration and provide a default client id incase we are not connected\n\t\tif (this.isAttached()) {\n\t\t\tthis.client.startOrUpdateCollaboration(this.runtime.clientId ?? \"attached\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}\n\t */\n\tprotected initializeLocalCore() {\n\t\tsuper.initializeLocalCore();\n\t\tthis.loadFinished();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(content: any): void {\n\t\tif (!this.intervalCollections.tryApplyStashedOp(content)) {\n\t\t\tthis.client.applyStashedOp(content);\n\t\t}\n\t}\n\n\tprivate summarizeMergeTree(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Are we fully loaded? If not, things will go south\n\t\tassert(\n\t\t\tthis.loadedDeferred.isCompleted,\n\t\t\t0x074 /* \"Snapshot called when not fully loaded\" */,\n\t\t);\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\n\t\tthis.processMinSequenceNumberChanged(minSeq);\n\n\t\tthis.messagesSinceMSNChange.forEach((m) => {\n\t\t\tm.minimumSequenceNumber = minSeq;\n\t\t});\n\n\t\treturn this.client.summarize(\n\t\t\tthis.runtime,\n\t\t\tthis.handle,\n\t\t\tserializer,\n\t\t\tthis.messagesSinceMSNChange,\n\t\t);\n\t}\n\n\t/**\n\t *\n\t * @param message - Message with decoded and hydrated handles\n\t */\n\tprivate processMergeTreeMsg(message: ISequencedDocumentMessage, local?: boolean) {\n\t\tconst ops: IMergeTreeDeltaOp[] = [];\n\t\tfunction transformOps(event: SequenceDeltaEvent) {\n\t\t\tops.push(...SharedSegmentSequence.createOpsFromDelta(event));\n\t\t}\n\t\tconst needsTransformation = message.referenceSequenceNumber !== message.sequenceNumber - 1;\n\t\tlet stashMessage: Readonly<ISequencedDocumentMessage> = message;\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.on(\"sequenceDelta\", transformOps);\n\t\t\t}\n\t\t}\n\n\t\tthis.client.applyMsg(message, local);\n\n\t\tif (this.runtime.options.newMergeTreeSnapshotFormat !== true) {\n\t\t\tif (needsTransformation) {\n\t\t\t\tthis.removeListener(\"sequenceDelta\", transformOps);\n\t\t\t\t// shallow clone the message as we only overwrite top level properties,\n\t\t\t\t// like referenceSequenceNumber and content only\n\t\t\t\tstashMessage = {\n\t\t\t\t\t...message,\n\t\t\t\t\treferenceSequenceNumber: stashMessage.sequenceNumber - 1,\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcontents: ops.length !== 1 ? createGroupOp(...ops) : ops[0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tthis.messagesSinceMSNChange.push(stashMessage);\n\n\t\t\t// Do GC every once in a while...\n\t\t\tif (\n\t\t\t\tthis.messagesSinceMSNChange.length > 20 &&\n\t\t\t\tthis.messagesSinceMSNChange[20].sequenceNumber < message.minimumSequenceNumber\n\t\t\t) {\n\t\t\t\tthis.processMinSequenceNumberChanged(message.minimumSequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate processMinSequenceNumberChanged(minSeq: number) {\n\t\tlet index = 0;\n\t\tfor (; index < this.messagesSinceMSNChange.length; index++) {\n\t\t\tif (this.messagesSinceMSNChange[index].sequenceNumber > minSeq) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index !== 0) {\n\t\t\tthis.messagesSinceMSNChange = this.messagesSinceMSNChange.slice(index);\n\t\t}\n\t}\n\n\tprivate loadFinished(error?: any) {\n\t\tif (!this.loadedDeferred.isCompleted) {\n\t\t\t// Initialize the interval collections\n\t\t\tthis.initializeIntervalCollections();\n\t\t\tif (error) {\n\t\t\t\tthis.loadedDeferred.reject(error);\n\t\t\t\tthrow error;\n\t\t\t} else {\n\t\t\t\t// it is important this series remains synchronous\n\t\t\t\t// first we stop deferring incoming ops, and apply then all\n\t\t\t\tthis.deferIncomingOps = false;\n\t\t\t\tfor (const message of this.loadedDeferredIncomingOps) {\n\t\t\t\t\tthis.processCore(message, false, undefined);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredIncomingOps.length = 0;\n\n\t\t\t\t// then resolve the loaded promise\n\t\t\t\t// and resubmit all the outstanding ops, as the snapshot\n\t\t\t\t// is fully loaded, and all outstanding ops are applied\n\t\t\t\tthis.loadedDeferred.resolve();\n\n\t\t\t\tfor (const [messageContent, opMetadata] of this.loadedDeferredOutgoingOps) {\n\t\t\t\t\tthis.reSubmitCore(messageContent, opMetadata);\n\t\t\t\t}\n\t\t\t\tthis.loadedDeferredOutgoingOps.length = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate initializeIntervalCollections() {\n\t\t// Listen and initialize new SharedIntervalCollections\n\t\tthis.intervalCollections.eventEmitter.on(\n\t\t\t\"create\",\n\t\t\t({ key, previousValue }: IValueChanged, local: boolean) => {\n\t\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\t\tif (!intervalCollection.attached) {\n\t\t\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t\t\t}\n\t\t\t\tassert(\n\t\t\t\t\tpreviousValue === undefined,\n\t\t\t\t\t0x2c1 /* \"Creating an interval collection that already exists?\" */,\n\t\t\t\t);\n\t\t\t\tthis.emit(\"createIntervalCollection\", key, local, this);\n\t\t\t},\n\t\t);\n\n\t\t// Initialize existing SharedIntervalCollections\n\t\tfor (const key of this.intervalCollections.keys()) {\n\t\t\tconst intervalCollection = this.intervalCollections.get(key);\n\t\t\tintervalCollection.attachGraph(this.client, key);\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"currently applicable reference sequence number\" for the duration of the callback.\n\t * See remarks on `currentRefSeq` for more context.\n\t */\n\tprivate useResubmitRefSeq(refSeq: number, callback: () => void) {\n\t\tconst previousResubmitRefSeq = this.ongoingResubmitRefSeq;\n\t\tthis.ongoingResubmitRefSeq = refSeq;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tthis.ongoingResubmitRefSeq = previousResubmitRefSeq;\n\t\t}\n\t}\n}\n\nfunction createReentrancyDetector(\n\tonReentrancy: (depth: number) => void,\n): <T>(callback: () => T) => T {\n\tlet depth = 0;\n\tfunction detectReentrancy<T>(callback: () => T): T {\n\t\tif (depth > 0) {\n\t\t\tonReentrancy(depth);\n\t\t}\n\t\tdepth++;\n\t\ttry {\n\t\t\treturn callback();\n\t\t} finally {\n\t\t\tdepth--;\n\t\t}\n\t}\n\n\treturn detectReentrancy;\n}\n\n/**\n * Apps which generate reentrant behavior may do so at a high frequency.\n * Logging even per-SharedSegmentSequence instance might be too noisy, and having a few logs from a session\n * is likely enough.\n */\nlet totalReentrancyLogs = 3;\n\n/**\n * Resets the reentrancy log counter. Test-only API.\n */\nexport function resetReentrancyLogCounter() {\n\ttotalReentrancyLogs = 3;\n}\n\nconst reentrancyErrorMessage = \"Reentrancy detected in sequence local ops\";\nconst ensureNoReentrancy = createReentrancyDetector(() => {\n\tthrow new LoggingError(reentrancyErrorMessage);\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedString.d.ts","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,
|
|
1
|
+
{"version":3,"file":"sharedString.d.ts","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,EAGN,iBAAiB,EACjB,QAAQ,EAER,MAAM,EACN,WAAW,EACX,aAAa,EACb,WAAW,EAEX,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,qBAAqB,CAAC,mBAAmB,CAAC;IAChF;;;;;OAKG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAEjE;;;;;OAKG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE7E;;OAEG;IACH,kBAAkB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,MAAM,CAAC;AAEvD;;;;;;;;;GASG;AACH,qBAAa,YACZ,SAAQ,qBAAqB,CAAC,mBAAmB,CACjD,YAAW,aAAa;IA6BhB,EAAE,EAAE,MAAM;IA3BlB;;;;;OAKG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIjE;;;OAGG;WACW,UAAU;IAIxB,I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AE,MAAM;IAWpD,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAWzD;;;OAGG;IACI,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIxD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;CAOhE;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACV;IACF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC1B,CAWA"}
|
package/lib/sharedString.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedString.js","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAKN,MAAM,EAGN,WAAW,EACX,eAAe,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAkC3D;;;;;;;;;GASG;AACH,MAAM,OAAO,YACZ,SAAQ,qBAA0C;IAGlD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,CAAC,IAAI,CAAiB,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;IAED,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IAID,YACC,QAAgC,EACzB,EAAU,EACjB,UAA8B;QAE9B,KAAK,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,CAAC,CAAC,CAAC,GAAG,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzD;KACD;SAAM;QACN,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1C,MAAM,eAAe;YACpB,gEAAgE;YAChE,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YACjF,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;SACpC;aAAM;YACN,MAAM,MAAM,GAAG,OAAiB,CAAC;YACjC,IAAI,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;gBAC3D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAC9C,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;aACtB;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IChannelAttributes, IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIMergeTreeTextHelper,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tMarker,\n\tPropertySet,\n\tReferenceType,\n\tTextSegment,\n\trefHasTileLabel,\n} from \"@fluidframework/merge-tree/internal\";\n\nimport { SharedSegmentSequence } from \"./sequence.js\";\nimport { SharedStringFactory } from \"./sequenceFactory.js\";\n\n/**\n * Fluid object interface describing access methods on a SharedString\n * @alpha\n */\nexport interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {\n\t/**\n\t * Inserts the text at the position.\n\t * @param pos - The position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of the text\n\t */\n\tinsertText(pos: number, text: string, props?: PropertySet): void;\n\n\t/**\n\t * Inserts a marker at the position.\n\t * @param pos - The position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tinsertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void;\n\n\t/**\n\t * {@inheritDoc SharedSegmentSequence.posFromRelativePos}\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n}\n\n/**\n * @alpha\n */\nexport type SharedStringSegment = TextSegment | Marker;\n\n/**\n * The Shared String is a specialized data structure for handling collaborative\n * text. It is based on a more general Sequence data structure but has\n * additional features that make working with text easier.\n *\n * In addition to text, a Shared String can also contain markers. Markers can be\n * used to store metadata at positions within the text, like the details of an\n * image or Fluid object that should be rendered with the text.\n * @alpha\n */\nexport class SharedString\n\textends SharedSegmentSequence<SharedStringSegment>\n\timplements ISharedString\n{\n\t/**\n\t * Create a new shared string.\n\t * @param runtime - data store runtime the new shared string belongs to\n\t * @param id - optional name of the shared string\n\t * @returns newly create shared string (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedStringFactory.Type) as SharedString;\n\t}\n\n\t/**\n\t * Get a factory for SharedString to register with the data store.\n\t * @returns a factory that creates and load SharedString\n\t */\n\tpublic static getFactory() {\n\t\treturn new SharedStringFactory();\n\t}\n\n\tpublic get ISharedString(): ISharedString {\n\t\treturn this;\n\t}\n\n\tprivate readonly mergeTreeTextHelper: IMergeTreeTextHelper;\n\n\tconstructor(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(document, id, attributes, SharedStringFactory.segmentFromSpec as any);\n\t\tthis.mergeTreeTextHelper = this.client.createTextHelper();\n\t}\n\n\t/**\n\t * Inserts a marker at a relative position.\n\t * @param relativePos1 - The relative position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tpublic insertMarkerRelative(\n\t\trelativePos1: IRelativePosition,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertMarker}\n\t */\n\tpublic insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Inserts the text at the position.\n\t * @param relativePos1 - The relative position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of text\n\t */\n\tpublic insertTextRelative(\n\t\trelativePos1: IRelativePosition,\n\t\ttext: string,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertText}\n\t */\n\tpublic insertText(pos: number, text: string, props?: PropertySet): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Replaces a range with the provided text.\n\t * @param start - The inclusive start of the range to replace\n\t * @param end - The exclusive end of the range to replace\n\t * @param text - The text to replace the range with\n\t * @param props - Optional. The properties of the replacement text\n\t */\n\tpublic replaceText(start: number, end: number, text: string, props?: PropertySet): void {\n\t\tthis.replaceRange(start, end, TextSegment.make(text, props));\n\t}\n\n\t/**\n\t * Removes the text in the given range.\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to replace\n\t * @returns the message sent.\n\t */\n\tpublic removeText(start: number, end: number): void {\n\t\tthis.removeRange(start, end);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t */\n\tpublic annotateMarker(marker: Marker, props: PropertySet) {\n\t\tthis.guardReentrancy(() => this.client.annotateMarker(marker, props));\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search.\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\treturn this.client.searchForMarker(startPos, markerLabel, forwards);\n\t}\n\n\t/**\n\t * Retrieve text from the SharedString in string format.\n\t * @param start - The starting index of the text to retrieve, or 0 if omitted.\n\t * @param end - The ending index of the text to retrieve, or the end of the string if omitted\n\t * @returns The requested text content as a string.\n\t */\n\tpublic getText(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Adds spaces for markers and handles, so that position calculations account for them.\n\t */\n\tpublic getTextWithPlaceholders(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\" \",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\tpublic getTextRangeWithMarkers(start: number, end: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"*\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided\n\t * id in this `SharedString`.\n\t */\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this.client.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tif (this.client.rollback !== undefined) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t}\n\t}\n}\n\ninterface ITextAndMarkerAccumulator {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n\tparallelMarkerLabel: string;\n\tplaceholder?: string;\n\ttagsInProgress: string[];\n\ttextSegment: TextSegment;\n}\n\n/**\n * Splits the text into regions ending with markers with the given `label`.\n * @param sharedString - String to retrieve text and markers from\n * @param label - label to split on\n * @returns Two parallel lists of text and markers, split by markers with the provided `label`.\n * For example:\n * ```typescript\n * // Say sharedstring has contents \"hello<paragraph marker 1>world<paragraph marker 2>missing\".\n * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, \"paragraph\");\n * // parallelText === [\"hello\", \"world\"]\n * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]\n * // Note parallelText does not include \"missing\".\n * ```\n * @internal\n */\nexport function getTextAndMarkers(\n\tsharedString: SharedString,\n\tlabel: string,\n\tstart?: number,\n\tend?: number,\n): {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n} {\n\tconst accum: ITextAndMarkerAccumulator = {\n\t\tparallelMarkerLabel: label,\n\t\tparallelMarkers: [],\n\t\tparallelText: [],\n\t\ttagsInProgress: [],\n\t\ttextSegment: new TextSegment(\"\"),\n\t};\n\n\tsharedString.walkSegments(gatherTextAndMarkers, start, end, accum);\n\treturn { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };\n}\n\nconst gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\taccumText: ITextAndMarkerAccumulator,\n) => {\n\tconst { placeholder, tagsInProgress, textSegment } = accumText;\n\tif (TextSegment.is(segment)) {\n\t\tlet beginTags = \"\";\n\t\tlet endTags = \"\";\n\t\t// TODO: let clients pass in function to get tag\n\t\tconst tags = [] as string[];\n\t\tconst initTags = [] as string[];\n\n\t\tif (segment.properties?.[\"font-weight\"]) {\n\t\t\ttags.push(\"b\");\n\t\t}\n\t\tif (segment.properties?.[\"text-decoration\"]) {\n\t\t\ttags.push(\"u\");\n\t\t}\n\t\tconst remTags = [] as string[];\n\t\tif (tags.length > 0) {\n\t\t\tfor (const tag of tags) {\n\t\t\t\tif (!tagsInProgress.includes(tag)) {\n\t\t\t\t\tbeginTags += `<${tag}>`;\n\t\t\t\t\tinitTags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tif (!tags.includes(accumTag)) {\n\t\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\t\tremTags.push(accumTag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const initTag of initTags.reverse()) {\n\t\t\t\ttagsInProgress.push(initTag);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\tremTags.push(accumTag);\n\t\t\t}\n\t\t}\n\t\tfor (const remTag of remTags) {\n\t\t\tconst remdex = tagsInProgress.indexOf(remTag);\n\t\t\tif (remdex >= 0) {\n\t\t\t\ttagsInProgress.splice(remdex, 1);\n\t\t\t}\n\t\t}\n\t\ttextSegment.text += endTags;\n\t\ttextSegment.text += beginTags;\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else {\n\t\tif (placeholder && placeholder.length > 0) {\n\t\t\tconst placeholderText =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\tplaceholder === \"*\" ? `\\n${segment}` : placeholder.repeat(segment.cachedLength);\n\t\t\ttextSegment.text += placeholderText;\n\t\t} else {\n\t\t\tconst marker = segment as Marker;\n\t\t\tif (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {\n\t\t\t\taccumText.parallelMarkers.push(marker);\n\t\t\t\taccumText.parallelText.push(textSegment.text);\n\t\t\t\ttextSegment.text = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"sharedString.js","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAMN,MAAM,EAGN,WAAW,EACX,eAAe,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAkC3D;;;;;;;;;GASG;AACH,MAAM,OAAO,YACZ,SAAQ,qBAA0C;IAGlD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,CAAC,IAAI,CAAiB,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU;QACvB,O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M,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACrC,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzD;KACD;SAAM;QACN,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1C,MAAM,eAAe;YACpB,gEAAgE;YAChE,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YACjF,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;SACpC;aAAM;YACN,MAAM,MAAM,GAAG,OAAiB,CAAC;YACjC,IAAI,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;gBAC3D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAC9C,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;aACtB;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IChannelAttributes, IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeTextHelper,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tMarker,\n\tPropertySet,\n\tReferenceType,\n\tTextSegment,\n\trefHasTileLabel,\n} from \"@fluidframework/merge-tree/internal\";\n\nimport { SharedSegmentSequence } from \"./sequence.js\";\nimport { SharedStringFactory } from \"./sequenceFactory.js\";\n\n/**\n * Fluid object interface describing access methods on a SharedString\n * @alpha\n */\nexport interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {\n\t/**\n\t * Inserts the text at the position.\n\t * @param pos - The position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of the text\n\t */\n\tinsertText(pos: number, text: string, props?: PropertySet): void;\n\n\t/**\n\t * Inserts a marker at the position.\n\t * @param pos - The position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tinsertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void;\n\n\t/**\n\t * {@inheritDoc SharedSegmentSequence.posFromRelativePos}\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n}\n\n/**\n * @alpha\n */\nexport type SharedStringSegment = TextSegment | Marker;\n\n/**\n * The Shared String is a specialized data structure for handling collaborative\n * text. It is based on a more general Sequence data structure but has\n * additional features that make working with text easier.\n *\n * In addition to text, a Shared String can also contain markers. Markers can be\n * used to store metadata at positions within the text, like the details of an\n * image or Fluid object that should be rendered with the text.\n * @alpha\n */\nexport class SharedString\n\textends SharedSegmentSequence<SharedStringSegment>\n\timplements ISharedString\n{\n\t/**\n\t * Create a new shared string.\n\t * @param runtime - data store runtime the new shared string belongs to\n\t * @param id - optional name of the shared string\n\t * @returns newly create shared string (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedStringFactory.Type) as SharedString;\n\t}\n\n\t/**\n\t * Get a factory for SharedString to register with the data store.\n\t * @returns a factory that creates and load SharedString\n\t */\n\tpublic static getFactory() {\n\t\treturn new SharedStringFactory();\n\t}\n\n\tpublic get ISharedString(): ISharedString {\n\t\treturn this;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprivate readonly mergeTreeTextHelper: IMergeTreeTextHelper;\n\n\tconstructor(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(document, id, attributes, SharedStringFactory.segmentFromSpec as any);\n\t\tthis.mergeTreeTextHelper = this.client.createTextHelper();\n\t}\n\n\t/**\n\t * Inserts a marker at a relative position.\n\t * @param relativePos1 - The relative position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tpublic insertMarkerRelative(\n\t\trelativePos1: IRelativePosition,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertMarker}\n\t */\n\tpublic insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Inserts the text at the position.\n\t * @param relativePos1 - The relative position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of text\n\t */\n\tpublic insertTextRelative(\n\t\trelativePos1: IRelativePosition,\n\t\ttext: string,\n\t\tprops?: PropertySet,\n\t): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertText}\n\t */\n\tpublic insertText(pos: number, text: string, props?: PropertySet): void {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Replaces a range with the provided text.\n\t * @param start - The inclusive start of the range to replace\n\t * @param end - The exclusive end of the range to replace\n\t * @param text - The text to replace the range with\n\t * @param props - Optional. The properties of the replacement text\n\t */\n\tpublic replaceText(start: number, end: number, text: string, props?: PropertySet): void {\n\t\tthis.replaceRange(start, end, TextSegment.make(text, props));\n\t}\n\n\t/**\n\t * Removes the text in the given range.\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to replace\n\t * @returns the message sent.\n\t */\n\tpublic removeText(start: number, end: number): void {\n\t\tthis.removeRange(start, end);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t */\n\tpublic annotateMarker(marker: Marker, props: PropertySet) {\n\t\tthis.guardReentrancy(() => this.client.annotateMarker(marker, props));\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search.\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\treturn this.client.searchForMarker(startPos, markerLabel, forwards);\n\t}\n\n\t/**\n\t * Retrieve text from the SharedString in string format.\n\t * @param start - The starting index of the text to retrieve, or 0 if omitted.\n\t * @param end - The ending index of the text to retrieve, or the end of the string if omitted\n\t * @returns The requested text content as a string.\n\t */\n\tpublic getText(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Adds spaces for markers and handles, so that position calculations account for them.\n\t */\n\tpublic getTextWithPlaceholders(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\" \",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\tpublic getTextRangeWithMarkers(start: number, end: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"*\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided\n\t * id in this `SharedString`.\n\t */\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this.client.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tif (this.client.rollback !== undefined) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t}\n\t}\n}\n\ninterface ITextAndMarkerAccumulator {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n\tparallelMarkerLabel: string;\n\tplaceholder?: string;\n\ttagsInProgress: string[];\n\ttextSegment: TextSegment;\n}\n\n/**\n * Splits the text into regions ending with markers with the given `label`.\n * @param sharedString - String to retrieve text and markers from\n * @param label - label to split on\n * @returns Two parallel lists of text and markers, split by markers with the provided `label`.\n * For example:\n * ```typescript\n * // Say sharedstring has contents \"hello<paragraph marker 1>world<paragraph marker 2>missing\".\n * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, \"paragraph\");\n * // parallelText === [\"hello\", \"world\"]\n * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]\n * // Note parallelText does not include \"missing\".\n * ```\n * @internal\n */\nexport function getTextAndMarkers(\n\tsharedString: SharedString,\n\tlabel: string,\n\tstart?: number,\n\tend?: number,\n): {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n} {\n\tconst accum: ITextAndMarkerAccumulator = {\n\t\tparallelMarkerLabel: label,\n\t\tparallelMarkers: [],\n\t\tparallelText: [],\n\t\ttagsInProgress: [],\n\t\ttextSegment: new TextSegment(\"\"),\n\t};\n\n\tsharedString.walkSegments(gatherTextAndMarkers, start, end, accum);\n\treturn { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };\n}\n\nconst gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\taccumText: ITextAndMarkerAccumulator,\n) => {\n\tconst { placeholder, tagsInProgress, textSegment } = accumText;\n\tif (TextSegment.is(segment)) {\n\t\tlet beginTags = \"\";\n\t\tlet endTags = \"\";\n\t\t// TODO: let clients pass in function to get tag\n\t\tconst tags = [] as string[];\n\t\tconst initTags = [] as string[];\n\n\t\tif (segment.properties?.[\"font-weight\"]) {\n\t\t\ttags.push(\"b\");\n\t\t}\n\t\tif (segment.properties?.[\"text-decoration\"]) {\n\t\t\ttags.push(\"u\");\n\t\t}\n\t\tconst remTags = [] as string[];\n\t\tif (tags.length > 0) {\n\t\t\tfor (const tag of tags) {\n\t\t\t\tif (!tagsInProgress.includes(tag)) {\n\t\t\t\t\tbeginTags += `<${tag}>`;\n\t\t\t\t\tinitTags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tif (!tags.includes(accumTag)) {\n\t\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\t\tremTags.push(accumTag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const initTag of initTags.reverse()) {\n\t\t\t\ttagsInProgress.push(initTag);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\tremTags.push(accumTag);\n\t\t\t}\n\t\t}\n\t\tfor (const remTag of remTags) {\n\t\t\tconst remdex = tagsInProgress.indexOf(remTag);\n\t\t\tif (remdex >= 0) {\n\t\t\t\ttagsInProgress.splice(remdex, 1);\n\t\t\t}\n\t\t}\n\t\ttextSegment.text += endTags;\n\t\ttextSegment.text += beginTags;\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else {\n\t\tif (placeholder && placeholder.length > 0) {\n\t\t\tconst placeholderText =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\tplaceholder === \"*\" ? `\\n${segment}` : placeholder.repeat(segment.cachedLength);\n\t\t\ttextSegment.text += placeholderText;\n\t\t} else {\n\t\t\tconst marker = segment as Marker;\n\t\t\tif (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {\n\t\t\t\taccumText.parallelMarkers.push(marker);\n\t\t\t\taccumText.parallelText.push(textSegment.text);\n\t\t\t\ttextSegment.text = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/sequence",
|
|
3
|
-
"version": "2.0.0-rc.3.0.
|
|
3
|
+
"version": "2.0.0-rc.3.0.4",
|
|
4
4
|
"description": "Distributed sequence",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -87,33 +87,33 @@
|
|
|
87
87
|
"temp-directory": "nyc/.nyc_output"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@fluid-internal/client-utils": ">=2.0.0-rc.3.0.
|
|
91
|
-
"@fluidframework/core-interfaces": ">=2.0.0-rc.3.0.
|
|
92
|
-
"@fluidframework/core-utils": ">=2.0.0-rc.3.0.
|
|
93
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-rc.3.0.
|
|
94
|
-
"@fluidframework/merge-tree": ">=2.0.0-rc.3.0.
|
|
90
|
+
"@fluid-internal/client-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
91
|
+
"@fluidframework/core-interfaces": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
92
|
+
"@fluidframework/core-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
93
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
94
|
+
"@fluidframework/merge-tree": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
95
95
|
"@fluidframework/protocol-definitions": "^3.2.0",
|
|
96
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-rc.3.0.
|
|
97
|
-
"@fluidframework/runtime-utils": ">=2.0.0-rc.3.0.
|
|
98
|
-
"@fluidframework/shared-object-base": ">=2.0.0-rc.3.0.
|
|
99
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-rc.3.0.
|
|
96
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
97
|
+
"@fluidframework/runtime-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
98
|
+
"@fluidframework/shared-object-base": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
99
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
100
100
|
"double-ended-queue": "^2.1.0-0",
|
|
101
101
|
"uuid": "^9.0.0"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
105
105
|
"@biomejs/biome": "^1.6.2",
|
|
106
|
-
"@fluid-internal/mocha-test-setup": ">=2.0.0-rc.3.0.
|
|
107
|
-
"@fluid-private/stochastic-test-utils": ">=2.0.0-rc.3.0.
|
|
108
|
-
"@fluid-private/test-dds-utils": ">=2.0.0-rc.3.0.
|
|
106
|
+
"@fluid-internal/mocha-test-setup": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
107
|
+
"@fluid-private/stochastic-test-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
108
|
+
"@fluid-private/test-dds-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
109
109
|
"@fluid-tools/benchmark": "^0.48.0",
|
|
110
110
|
"@fluid-tools/build-cli": "^0.37.0",
|
|
111
111
|
"@fluidframework/build-common": "^2.0.3",
|
|
112
112
|
"@fluidframework/build-tools": "^0.37.0",
|
|
113
|
-
"@fluidframework/container-definitions": ">=2.0.0-rc.3.0.
|
|
113
|
+
"@fluidframework/container-definitions": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
114
114
|
"@fluidframework/eslint-config-fluid": "^5.1.0",
|
|
115
115
|
"@fluidframework/sequence-previous": "npm:@fluidframework/sequence@2.0.0-internal.8.0.0",
|
|
116
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-rc.3.0.
|
|
116
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-rc.3.0.4 <2.0.0-rc.3.1.0",
|
|
117
117
|
"@microsoft/api-extractor": "^7.42.3",
|
|
118
118
|
"@types/diff": "^3.5.1",
|
|
119
119
|
"@types/double-ended-queue": "^2.1.0",
|
package/src/packageVersion.ts
CHANGED
package/src/sequence.ts
CHANGED
|
@@ -17,7 +17,9 @@ import {
|
|
|
17
17
|
IJSONSegment,
|
|
18
18
|
IMergeTreeAnnotateMsg,
|
|
19
19
|
IMergeTreeDeltaOp,
|
|
20
|
+
// eslint-disable-next-line import/no-deprecated
|
|
20
21
|
IMergeTreeGroupMsg,
|
|
22
|
+
// eslint-disable-next-line import/no-deprecated
|
|
21
23
|
IMergeTreeObliterateMsg,
|
|
22
24
|
IMergeTreeOp,
|
|
23
25
|
IMergeTreeRemoveMsg,
|
|
@@ -30,9 +32,11 @@ import {
|
|
|
30
32
|
PropertySet,
|
|
31
33
|
ReferencePosition,
|
|
32
34
|
ReferenceType,
|
|
35
|
+
// eslint-disable-next-line import/no-deprecated
|
|
33
36
|
SegmentGroup,
|
|
34
37
|
SlidingPreference,
|
|
35
|
-
createAnnotateRangeOp,
|
|
38
|
+
createAnnotateRangeOp,
|
|
39
|
+
// eslint-disable-next-line import/no-deprecated
|
|
36
40
|
createGroupOp,
|
|
37
41
|
createInsertOp,
|
|
38
42
|
createObliterateRangeOp,
|
|
@@ -180,6 +184,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
case MergeTreeDeltaType.OBLITERATE: {
|
|
187
|
+
// eslint-disable-next-line import/no-deprecated
|
|
183
188
|
const lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;
|
|
184
189
|
if (lastRem?.pos1 === r.position) {
|
|
185
190
|
assert(
|
|
@@ -243,6 +248,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
243
248
|
/** `Deferred` that triggers once the object is loaded */
|
|
244
249
|
protected loadedDeferred = new Deferred<void>();
|
|
245
250
|
// cache out going ops created when partial loading
|
|
251
|
+
// eslint-disable-next-line import/no-deprecated
|
|
246
252
|
private readonly loadedDeferredOutgoingOps: [IMergeTreeOp, SegmentGroup | SegmentGroup[]][] =
|
|
247
253
|
[];
|
|
248
254
|
// cache incoming ops that arrive when partial loading
|
|
@@ -340,6 +346,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
340
346
|
* release, as group ops are redundant with the native batching capabilities
|
|
341
347
|
* of the runtime
|
|
342
348
|
*/
|
|
349
|
+
// eslint-disable-next-line import/no-deprecated
|
|
343
350
|
public groupOperation(groupOp: IMergeTreeGroupMsg) {
|
|
344
351
|
this.guardReentrancy(() => this.client.localTransaction(groupOp));
|
|
345
352
|
}
|
|
@@ -654,6 +661,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
654
661
|
this.submitSequenceMessage(
|
|
655
662
|
this.client.regeneratePendingOp(
|
|
656
663
|
content as IMergeTreeOp,
|
|
664
|
+
// eslint-disable-next-line import/no-deprecated
|
|
657
665
|
localOpMetadata as SegmentGroup | SegmentGroup[],
|
|
658
666
|
),
|
|
659
667
|
);
|
package/src/sharedString.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { IChannelAttributes, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
|
|
7
7
|
import {
|
|
8
|
+
// eslint-disable-next-line import/no-deprecated
|
|
8
9
|
IMergeTreeTextHelper,
|
|
9
10
|
IRelativePosition,
|
|
10
11
|
ISegment,
|
|
@@ -87,6 +88,7 @@ export class SharedString
|
|
|
87
88
|
return this;
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
// eslint-disable-next-line import/no-deprecated
|
|
90
92
|
private readonly mergeTreeTextHelper: IMergeTreeTextHelper;
|
|
91
93
|
|
|
92
94
|
constructor(
|