@fluid-experimental/ot 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @fluid-experimental/ot
2
2
 
3
+ ## 2.0.0-rc.3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Packages now use package.json "exports" and require modern module resolution [97d68aa06b](https://github.com/microsoft/FluidFramework/commit/97d68aa06bd5c022ecb026655814aea222a062ae)
8
+
9
+ Fluid Framework packages have been updated to use the [package.json "exports"
10
+ field](https://nodejs.org/docs/latest-v18.x/api/packages.html#exports) to define explicit entry points for both
11
+ TypeScript types and implementation code.
12
+
13
+ This means that using Fluid Framework packages require the following TypeScript settings in tsconfig.json:
14
+
15
+ - `"moduleResolution": "Node16"` with `"module": "Node16"`
16
+ - `"moduleResolution": "Bundler"` with `"module": "ESNext"`
17
+
18
+ We recommend using Node16/Node16 unless absolutely necessary. That will produce transpiled JavaScript that is suitable
19
+ for use with modern versions of Node.js _and_ Bundlers.
20
+ [See the TypeScript documentation](https://www.typescriptlang.org/tsconfig#moduleResolution) for more information
21
+ regarding the module and moduleResolution options.
22
+
23
+ **Node10 moduleResolution is not supported; it does not support Fluid Framework's API structuring pattern that is used
24
+ to distinguish stable APIs from those that are in development.**
25
+
3
26
  ## 2.0.0-rc.2.0.0
4
27
 
5
28
  Dependency updates only.
@@ -10,7 +10,7 @@ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
10
10
  import { IFluidSerializer } from '@fluidframework/shared-object-base';
11
11
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
12
12
  import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
13
- import { SharedObject } from '@fluidframework/shared-object-base';
13
+ import { SharedObject } from '@fluidframework/shared-object-base/internal';
14
14
 
15
15
  // @internal (undocumented)
16
16
  export abstract class SharedOT<TState, TOp> extends SharedObject {
package/dist/ot.d.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { IChannelAttributes, IChannelStorageService, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
5
6
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
6
- import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions";
7
7
  import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
8
- import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
8
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
9
+ import { SharedObject } from "@fluidframework/shared-object-base/internal";
9
10
  /**
10
11
  * @internal
11
12
  */
package/dist/ot.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ot.d.ts","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAEN,gBAAgB,EAChB,YAAY,EACZ,MAAM,oCAAoC,CAAC;AAQ5C;;GAEG;AACH,8BAAsB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAE,SAAQ,YAAY;IAC/D;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA+B;IAE5D;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC,sEAAsE;IACtE,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAS;gBAG1B,EAAE,EAAE,MAAM,EACV,OAAO,EAA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sE;IACtE,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAS;gBAG1B,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB,EAC9B,YAAY,EAAE,MAAM;IAOrB,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG;IAavB;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,MAAM;IAE5D;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,GAAG;IAE7D,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;cAS5D,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE,SAAS,CAAC,YAAY;IAEtB,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO;IAkDxE,SAAS,KAAK,KAAK,WAclB;IAED,SAAS,CAAC,cAAc,IAAI,IAAI;CAGhC"}
package/dist/ot.js CHANGED
@@ -5,13 +5,13 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SharedOT = void 0;
8
- const core_utils_1 = require("@fluidframework/core-utils");
9
8
  const client_utils_1 = require("@fluid-internal/client-utils");
10
- const shared_object_base_1 = require("@fluidframework/shared-object-base");
9
+ const internal_1 = require("@fluidframework/core-utils/internal");
10
+ const internal_2 = require("@fluidframework/shared-object-base/internal");
11
11
  /**
12
12
  * @internal
13
13
  */
14
- class SharedOT extends shared_object_base_1.SharedObject {
14
+ class SharedOT extends internal_2.SharedObject {
15
15
  constructor(id, runtime, attributes, initialValue) {
16
16
  super(id, runtime, attributes, "fluid_ot_");
17
17
  /**
@@ -40,8 +40,8 @@ class SharedOT extends shared_object_base_1.SharedObject {
40
40
  this.submitLocalMessage(op);
41
41
  }
42
42
  summarizeCore(serializer) {
43
- (0, core_utils_1.assert)(this.pendingOps.length === 0, 0x5f6 /* Summarizer must not have locally pending changes. */);
44
- return (0, shared_object_base_1.createSingleBlobSummary)("header", serializer.stringify(this.global, this.handle));
43
+ (0, internal_1.assert)(this.pendingOps.length === 0, 0x5f6 /* Summarizer must not have locally pending changes. */);
44
+ return (0, internal_2.createSingleBlobSummary)("header", serializer.stringify(this.global, this.handle));
45
45
  }
46
46
  async loadCore(storage) {
47
47
  const blob = await storage.readBlob("header");
package/dist/ot.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ot.js","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AACpD,+DAA8D;AAQ9D,2EAI4C;AAQ5C;;GAEG;AACH,MAAsB,QAAsB,SAAQ,iCAAY;IAyB/D,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EAC9B,YAAoB;QAEpB,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QA9B7C;;;;WAIG;QACc,iBAAY,GAA4B,EAAE,CAAC;QAE5D;;;;WAIG;QACc,eAAU,GAAU,EAAE,CAAC;QAUhC,eAAU,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;IACzC,CAAC;IAES,KAAK,CAAC,EAAO;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAE5C,+CAA+C;QAC/C,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;YACzB,OAAO;SACP;QAED,IAAI,CAA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CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;YAED,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACxB;QAED,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAjJD,4BAiJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport {\n\tcreateSingleBlobSummary,\n\tIFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\n\ninterface ISequencedOpInfo<TOp> {\n\tclient: string;\n\tseq: number;\n\top: TOp;\n}\n\n/**\n * @internal\n */\nexport abstract class SharedOT<TState, TOp> extends SharedObject {\n\t/**\n\t * Queue of sequenced ops that are above minSeq. Used by 'processCore' to\n\t * adjust incoming ops to account for prior ops that the sender didn't know about\n\t * at the time they submitted their op.\n\t */\n\tprivate readonly sequencedOps: ISequencedOpInfo<TOp>[] = [];\n\n\t/**\n\t * Queue of local pending ops that have not yet been ACKed by the service. Used\n\t * to lazily rebuild the \"local\" state cache when it is invalidated by interleaved\n\t * remote ops.\n\t */\n\tprivate readonly pendingOps: TOp[] = [];\n\n\t/** The \"global\" state is the result of applying all sequenced ops. */\n\tprivate global: TState;\n\n\t/**\n\t * Lazily cached result of optimistically applying pendingOps on top of the current\n\t * \"global\" state.\n\t */\n\tprivate local: TState;\n\tprivate localDirty = false;\n\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tinitialValue: TState,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_ot_\");\n\n\t\tthis.global = this.local = initialValue;\n\t}\n\n\tprotected apply(op: TOp) {\n\t\tthis.local = this.applyCore(this.state, op);\n\n\t\t// If we are not attached, don't submit the op.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.global = this.local;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingOps.push(op);\n\t\tthis.submitLocalMessage(op);\n\t}\n\n\t/**\n\t * Apply the given 'op' to the provided 'state', producing a new instance of state.\n\t */\n\tprotected abstract applyCore(state: TState, op: TOp): TState;\n\n\t/**\n\t * Transform the 'input' op to adjust for the earlier 'transform' op.\n\t */\n\tprotected abstract transform(input: TOp, transform: TOp): TOp;\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tassert(\n\t\t\tthis.pendingOps.length === 0,\n\t\t\t0x5f6 /* Summarizer must not have locally pending changes. */,\n\t\t);\n\n\t\treturn createSingleBlobSummary(\"header\", serializer.stringify(this.global, this.handle));\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst blob = await storage.readBlob(\"header\");\n\t\tconst rawContent = bufferToString(blob, \"utf8\");\n\t\tthis.global = this.local = this.serializer.parse(rawContent);\n\t}\n\n\tprotected onDisconnect() {}\n\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean) {\n\t\t// Discard any sequenced ops that are now below the minimum sequence number.\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\t\twhile (this.sequencedOps[0]?.seq < minSeq) {\n\t\t\tthis.sequencedOps.shift();\n\t\t}\n\n\t\tlet remoteOp = message.contents;\n\t\tconst messageSeq = message.sequenceNumber;\n\t\tconst remoteRefSeq = message.referenceSequenceNumber;\n\t\tconst remoteClient = message.clientId;\n\n\t\t// Adjust the incoming sequenced op to account for prior sequenced ops that the\n\t\t// sender hadn't yet seen at the time they sent the op.\n\t\tfor (const { op, seq, client } of this.sequencedOps) {\n\t\t\tif (remoteRefSeq < seq && remoteClient !== client) {\n\t\t\t\tremoteOp = this.transform(remoteOp as TOp, op);\n\t\t\t}\n\t\t}\n\n\t\t// Retain the adjusted op in order to adjust future remote ops.\n\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\tthis.sequencedOps.push({\n\t\t\tseq: messageSeq,\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tclient: remoteClient as string,\n\t\t\top: remoteOp as TOp,\n\t\t});\n\n\t\t// The incoming sequenced op is now part of the \"global\" state. Apply it to \"this.global\"\n\t\t// now.\n\t\t//\n\t\t// TODO: If the op is local, we could defer applying the remoteOp and wait and see if\n\t\t// the global state catches up with our local state.\n\t\tthis.global = this.applyCore(this.global, remoteOp as TOp);\n\n\t\tif (local) {\n\t\t\tthis.pendingOps.shift();\n\t\t} else {\n\t\t\t// Our optimistic local cache (if any) did not account for the incoming op.\n\t\t\tthis.localDirty = true;\n\n\t\t\t// Adjust our queue of locally pending ops to account for the incoming op so that they\n\t\t\t// may be reapplied to the global state if needed.\n\t\t\tfor (let i = 0; i < this.pendingOps.length; i++) {\n\t\t\t\tthis.pendingOps[i] = this.transform(this.pendingOps[i], remoteOp as TOp);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected get state() {\n\t\t// If the locally cached state is dirty, reset it to the global state and reapply our\n\t\t// pending ops to bring it up to date.\n\t\tif (this.localDirty) {\n\t\t\tthis.local = this.global;\n\n\t\t\tfor (const op of this.pendingOps) {\n\t\t\t\tthis.local = this.applyCore(this.local, op);\n\t\t\t}\n\n\t\t\tthis.localDirty = false;\n\t\t}\n\n\t\treturn this.local;\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"ot.js","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAE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EAAE,QAAe,CAAC,CAAC;QAE3D,IAAI,KAAK,EAAE;YACV,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;SACxB;aAAM;YACN,2EAA2E;YAC3E,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YAEvB,sFAAsF;YACtF,kDAAkD;YAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAChD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAe,CAAC,CAAC;aACzE;SACD;IACF,CAAC;IAED,IAAc,KAAK;QAClB,qFAAqF;QACrF,sCAAsC;QACtC,IAAI,IAAI,CAAC,UAAU,EAAE;YACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;YAEzB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;YAED,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACxB;QAED,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAjJD,4BAiJC","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 { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIChannelStorageService,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { SharedObject, createSingleBlobSummary } from \"@fluidframework/shared-object-base/internal\";\n\ninterface ISequencedOpInfo<TOp> {\n\tclient: string;\n\tseq: number;\n\top: TOp;\n}\n\n/**\n * @internal\n */\nexport abstract class SharedOT<TState, TOp> extends SharedObject {\n\t/**\n\t * Queue of sequenced ops that are above minSeq. Used by 'processCore' to\n\t * adjust incoming ops to account for prior ops that the sender didn't know about\n\t * at the time they submitted their op.\n\t */\n\tprivate readonly sequencedOps: ISequencedOpInfo<TOp>[] = [];\n\n\t/**\n\t * Queue of local pending ops that have not yet been ACKed by the service. Used\n\t * to lazily rebuild the \"local\" state cache when it is invalidated by interleaved\n\t * remote ops.\n\t */\n\tprivate readonly pendingOps: TOp[] = [];\n\n\t/** The \"global\" state is the result of applying all sequenced ops. */\n\tprivate global: TState;\n\n\t/**\n\t * Lazily cached result of optimistically applying pendingOps on top of the current\n\t * \"global\" state.\n\t */\n\tprivate local: TState;\n\tprivate localDirty = false;\n\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tinitialValue: TState,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_ot_\");\n\n\t\tthis.global = this.local = initialValue;\n\t}\n\n\tprotected apply(op: TOp) {\n\t\tthis.local = this.applyCore(this.state, op);\n\n\t\t// If we are not attached, don't submit the op.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.global = this.local;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingOps.push(op);\n\t\tthis.submitLocalMessage(op);\n\t}\n\n\t/**\n\t * Apply the given 'op' to the provided 'state', producing a new instance of state.\n\t */\n\tprotected abstract applyCore(state: TState, op: TOp): TState;\n\n\t/**\n\t * Transform the 'input' op to adjust for the earlier 'transform' op.\n\t */\n\tprotected abstract transform(input: TOp, transform: TOp): TOp;\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tassert(\n\t\t\tthis.pendingOps.length === 0,\n\t\t\t0x5f6 /* Summarizer must not have locally pending changes. */,\n\t\t);\n\n\t\treturn createSingleBlobSummary(\"header\", serializer.stringify(this.global, this.handle));\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst blob = await storage.readBlob(\"header\");\n\t\tconst rawContent = bufferToString(blob, \"utf8\");\n\t\tthis.global = this.local = this.serializer.parse(rawContent);\n\t}\n\n\tprotected onDisconnect() {}\n\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean) {\n\t\t// Discard any sequenced ops that are now below the minimum sequence number.\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\t\twhile (this.sequencedOps[0]?.seq < minSeq) {\n\t\t\tthis.sequencedOps.shift();\n\t\t}\n\n\t\tlet remoteOp = message.contents;\n\t\tconst messageSeq = message.sequenceNumber;\n\t\tconst remoteRefSeq = message.referenceSequenceNumber;\n\t\tconst remoteClient = message.clientId;\n\n\t\t// Adjust the incoming sequenced op to account for prior sequenced ops that the\n\t\t// sender hadn't yet seen at the time they sent the op.\n\t\tfor (const { op, seq, client } of this.sequencedOps) {\n\t\t\tif (remoteRefSeq < seq && remoteClient !== client) {\n\t\t\t\tremoteOp = this.transform(remoteOp as TOp, op);\n\t\t\t}\n\t\t}\n\n\t\t// Retain the adjusted op in order to adjust future remote ops.\n\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\tthis.sequencedOps.push({\n\t\t\tseq: messageSeq,\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tclient: remoteClient as string,\n\t\t\top: remoteOp as TOp,\n\t\t});\n\n\t\t// The incoming sequenced op is now part of the \"global\" state. Apply it to \"this.global\"\n\t\t// now.\n\t\t//\n\t\t// TODO: If the op is local, we could defer applying the remoteOp and wait and see if\n\t\t// the global state catches up with our local state.\n\t\tthis.global = this.applyCore(this.global, remoteOp as TOp);\n\n\t\tif (local) {\n\t\t\tthis.pendingOps.shift();\n\t\t} else {\n\t\t\t// Our optimistic local cache (if any) did not account for the incoming op.\n\t\t\tthis.localDirty = true;\n\n\t\t\t// Adjust our queue of locally pending ops to account for the incoming op so that they\n\t\t\t// may be reapplied to the global state if needed.\n\t\t\tfor (let i = 0; i < this.pendingOps.length; i++) {\n\t\t\t\tthis.pendingOps[i] = this.transform(this.pendingOps[i], remoteOp as TOp);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected get state() {\n\t\t// If the locally cached state is dirty, reset it to the global state and reapply our\n\t\t// pending ops to bring it up to date.\n\t\tif (this.localDirty) {\n\t\t\tthis.local = this.global;\n\n\t\t\tfor (const op of this.pendingOps) {\n\t\t\t\tthis.local = this.applyCore(this.local, op);\n\t\t\t}\n\n\t\t\tthis.localDirty = false;\n\t\t}\n\n\t\treturn this.local;\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
@@ -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 = "@fluid-experimental/ot";
8
- export declare const pkgVersion = "2.0.0-rc.2.0.2";
8
+ export declare const pkgVersion = "2.0.0-rc.3.0.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluid-experimental/ot";
11
- exports.pkgVersion = "2.0.0-rc.2.0.2";
11
+ exports.pkgVersion = "2.0.0-rc.3.0.0";
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,wBAAwB,CAAC;AACnC,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 = \"@fluid-experimental/ot\";\nexport const pkgVersion = \"2.0.0-rc.2.0.2\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,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 = \"@fluid-experimental/ot\";\nexport const pkgVersion = \"2.0.0-rc.3.0.0\";\n"]}
package/lib/ot.d.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { IChannelAttributes, IChannelStorageService, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
5
6
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
6
- import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions";
7
7
  import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
8
- import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
8
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
9
+ import { SharedObject } from "@fluidframework/shared-object-base/internal";
9
10
  /**
10
11
  * @internal
11
12
  */
package/lib/ot.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ot.d.ts","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,E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CAAC,YAAY;IAEtB,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO;IAkDxE,SAAS,KAAK,KAAK,WAclB;IAED,SAAS,CAAC,cAAc,IAAI,IAAI;CAGhC"}
package/lib/ot.js CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert } from "@fluidframework/core-utils";
6
5
  import { bufferToString } from "@fluid-internal/client-utils";
7
- import { createSingleBlobSummary, SharedObject, } from "@fluidframework/shared-object-base";
6
+ import { assert } from "@fluidframework/core-utils/internal";
7
+ import { SharedObject, createSingleBlobSummary } from "@fluidframework/shared-object-base/internal";
8
8
  /**
9
9
  * @internal
10
10
  */
package/lib/ot.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ot.js","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAQ9D,OAAO,EACN,uBAAuB,EAEvB,YAAY,GACZ,MAAM,oCAAoC,CAAC;AAQ5C;;GAEG;AACH,MAAM,OAAgB,QAAsB,SAAQ,YAAY;IAyB/D,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EAC9B,YAAoB;QAEpB,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QA9B7C;;;;WAIG;QACc,iBAAY,GAA4B,EAAE,CAAC;QAE5D;;;;WAIG;QACc,eAAU,GAAU,EAAE,CAAC;QAUhC,eAAU,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;IACzC,CAAC;IAES,KAAK,CAAC,EAAO;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,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,IAAI,IAAI,CAAC,UAAU,EAAE;YACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;YAEzB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;YAED,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;SACxB;QAED,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport {\n\tcreateSingleBlobSummary,\n\tIFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\n\ninterface ISequencedOpInfo<TOp> {\n\tclient: string;\n\tseq: number;\n\top: TOp;\n}\n\n/**\n * @internal\n */\nexport abstract class SharedOT<TState, TOp> extends SharedObject {\n\t/**\n\t * Queue of sequenced ops that are above minSeq. Used by 'processCore' to\n\t * adjust incoming ops to account for prior ops that the sender didn't know about\n\t * at the time they submitted their op.\n\t */\n\tprivate readonly sequencedOps: ISequencedOpInfo<TOp>[] = [];\n\n\t/**\n\t * Queue of local pending ops that have not yet been ACKed by the service. Used\n\t * to lazily rebuild the \"local\" state cache when it is invalidated by interleaved\n\t * remote ops.\n\t */\n\tprivate readonly pendingOps: TOp[] = [];\n\n\t/** The \"global\" state is the result of applying all sequenced ops. */\n\tprivate global: TState;\n\n\t/**\n\t * Lazily cached result of optimistically applying pendingOps on top of the current\n\t * \"global\" state.\n\t */\n\tprivate local: TState;\n\tprivate localDirty = false;\n\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tinitialValue: TState,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_ot_\");\n\n\t\tthis.global = this.local = initialValue;\n\t}\n\n\tprotected apply(op: TOp) {\n\t\tthis.local = this.applyCore(this.state, op);\n\n\t\t// If we are not attached, don't submit the op.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.global = this.local;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingOps.push(op);\n\t\tthis.submitLocalMessage(op);\n\t}\n\n\t/**\n\t * Apply the given 'op' to the provided 'state', producing a new instance of state.\n\t */\n\tprotected abstract applyCore(state: TState, op: TOp): TState;\n\n\t/**\n\t * Transform the 'input' op to adjust for the earlier 'transform' op.\n\t */\n\tprotected abstract transform(input: TOp, transform: TOp): TOp;\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tassert(\n\t\t\tthis.pendingOps.length === 0,\n\t\t\t0x5f6 /* Summarizer must not have locally pending changes. */,\n\t\t);\n\n\t\treturn createSingleBlobSummary(\"header\", serializer.stringify(this.global, this.handle));\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst blob = await storage.readBlob(\"header\");\n\t\tconst rawContent = bufferToString(blob, \"utf8\");\n\t\tthis.global = this.local = this.serializer.parse(rawContent);\n\t}\n\n\tprotected onDisconnect() {}\n\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean) {\n\t\t// Discard any sequenced ops that are now below the minimum sequence number.\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\t\twhile (this.sequencedOps[0]?.seq < minSeq) {\n\t\t\tthis.sequencedOps.shift();\n\t\t}\n\n\t\tlet remoteOp = message.contents;\n\t\tconst messageSeq = message.sequenceNumber;\n\t\tconst remoteRefSeq = message.referenceSequenceNumber;\n\t\tconst remoteClient = message.clientId;\n\n\t\t// Adjust the incoming sequenced op to account for prior sequenced ops that the\n\t\t// sender hadn't yet seen at the time they sent the op.\n\t\tfor (const { op, seq, client } of this.sequencedOps) {\n\t\t\tif (remoteRefSeq < seq && remoteClient !== client) {\n\t\t\t\tremoteOp = this.transform(remoteOp as TOp, op);\n\t\t\t}\n\t\t}\n\n\t\t// Retain the adjusted op in order to adjust future remote ops.\n\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\tthis.sequencedOps.push({\n\t\t\tseq: messageSeq,\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tclient: remoteClient as string,\n\t\t\top: remoteOp as TOp,\n\t\t});\n\n\t\t// The incoming sequenced op is now part of the \"global\" state. Apply it to \"this.global\"\n\t\t// now.\n\t\t//\n\t\t// TODO: If the op is local, we could defer applying the remoteOp and wait and see if\n\t\t// the global state catches up with our local state.\n\t\tthis.global = this.applyCore(this.global, remoteOp as TOp);\n\n\t\tif (local) {\n\t\t\tthis.pendingOps.shift();\n\t\t} else {\n\t\t\t// Our optimistic local cache (if any) did not account for the incoming op.\n\t\t\tthis.localDirty = true;\n\n\t\t\t// Adjust our queue of locally pending ops to account for the incoming op so that they\n\t\t\t// may be reapplied to the global state if needed.\n\t\t\tfor (let i = 0; i < this.pendingOps.length; i++) {\n\t\t\t\tthis.pendingOps[i] = this.transform(this.pendingOps[i], remoteOp as TOp);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected get state() {\n\t\t// If the locally cached state is dirty, reset it to the global state and reapply our\n\t\t// pending ops to bring it up to date.\n\t\tif (this.localDirty) {\n\t\t\tthis.local = this.global;\n\n\t\t\tfor (const op of this.pendingOps) {\n\t\t\t\tthis.local = this.applyCore(this.local, op);\n\t\t\t}\n\n\t\t\tthis.localDirty = false;\n\t\t}\n\n\t\treturn this.local;\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"ot.js","sourceRoot":"","sources":["../src/ot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAS7D,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAQpG;;GAEG;AACH,MAAM,OAAgB,QAAsB,SAAQ,YAAY;IAyB/D,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EAC9B,YAAoB;QAEpB,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QA9B7C;;;;WAIG;QACc,iBAAY,GAA4B,EAAE,CAAC;QAE5D;;;;WAIG;QACc,eAAU,GAAU,EAAE,CAAC;QAUhC,eAAU,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;IACzC,CAAC;IAES,KAAK,CAAC,EAAO;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAE5C,+CAA+C;QAC/C,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;YACzB,OAAO;SACP;QAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAYS,aAAa,CAAC,UAA4B;QACnD,MAAM,CACL,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAC5B,KAAK,CAAC,uDAAuD,CAC7D,CAAC;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microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIChannelStorageService,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { SharedObject, createSingleBlobSummary } from \"@fluidframework/shared-object-base/internal\";\n\ninterface ISequencedOpInfo<TOp> {\n\tclient: string;\n\tseq: number;\n\top: TOp;\n}\n\n/**\n * @internal\n */\nexport abstract class SharedOT<TState, TOp> extends SharedObject {\n\t/**\n\t * Queue of sequenced ops that are above minSeq. Used by 'processCore' to\n\t * adjust incoming ops to account for prior ops that the sender didn't know about\n\t * at the time they submitted their op.\n\t */\n\tprivate readonly sequencedOps: ISequencedOpInfo<TOp>[] = [];\n\n\t/**\n\t * Queue of local pending ops that have not yet been ACKed by the service. Used\n\t * to lazily rebuild the \"local\" state cache when it is invalidated by interleaved\n\t * remote ops.\n\t */\n\tprivate readonly pendingOps: TOp[] = [];\n\n\t/** The \"global\" state is the result of applying all sequenced ops. */\n\tprivate global: TState;\n\n\t/**\n\t * Lazily cached result of optimistically applying pendingOps on top of the current\n\t * \"global\" state.\n\t */\n\tprivate local: TState;\n\tprivate localDirty = false;\n\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tinitialValue: TState,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_ot_\");\n\n\t\tthis.global = this.local = initialValue;\n\t}\n\n\tprotected apply(op: TOp) {\n\t\tthis.local = this.applyCore(this.state, op);\n\n\t\t// If we are not attached, don't submit the op.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.global = this.local;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingOps.push(op);\n\t\tthis.submitLocalMessage(op);\n\t}\n\n\t/**\n\t * Apply the given 'op' to the provided 'state', producing a new instance of state.\n\t */\n\tprotected abstract applyCore(state: TState, op: TOp): TState;\n\n\t/**\n\t * Transform the 'input' op to adjust for the earlier 'transform' op.\n\t */\n\tprotected abstract transform(input: TOp, transform: TOp): TOp;\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tassert(\n\t\t\tthis.pendingOps.length === 0,\n\t\t\t0x5f6 /* Summarizer must not have locally pending changes. */,\n\t\t);\n\n\t\treturn createSingleBlobSummary(\"header\", serializer.stringify(this.global, this.handle));\n\t}\n\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst blob = await storage.readBlob(\"header\");\n\t\tconst rawContent = bufferToString(blob, \"utf8\");\n\t\tthis.global = this.local = this.serializer.parse(rawContent);\n\t}\n\n\tprotected onDisconnect() {}\n\n\tprotected processCore(message: ISequencedDocumentMessage, local: boolean) {\n\t\t// Discard any sequenced ops that are now below the minimum sequence number.\n\t\tconst minSeq = this.runtime.deltaManager.minimumSequenceNumber;\n\t\twhile (this.sequencedOps[0]?.seq < minSeq) {\n\t\t\tthis.sequencedOps.shift();\n\t\t}\n\n\t\tlet remoteOp = message.contents;\n\t\tconst messageSeq = message.sequenceNumber;\n\t\tconst remoteRefSeq = message.referenceSequenceNumber;\n\t\tconst remoteClient = message.clientId;\n\n\t\t// Adjust the incoming sequenced op to account for prior sequenced ops that the\n\t\t// sender hadn't yet seen at the time they sent the op.\n\t\tfor (const { op, seq, client } of this.sequencedOps) {\n\t\t\tif (remoteRefSeq < seq && remoteClient !== client) {\n\t\t\t\tremoteOp = this.transform(remoteOp as TOp, op);\n\t\t\t}\n\t\t}\n\n\t\t// Retain the adjusted op in order to adjust future remote ops.\n\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\tthis.sequencedOps.push({\n\t\t\tseq: messageSeq,\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tclient: remoteClient as string,\n\t\t\top: remoteOp as TOp,\n\t\t});\n\n\t\t// The incoming sequenced op is now part of the \"global\" state. Apply it to \"this.global\"\n\t\t// now.\n\t\t//\n\t\t// TODO: If the op is local, we could defer applying the remoteOp and wait and see if\n\t\t// the global state catches up with our local state.\n\t\tthis.global = this.applyCore(this.global, remoteOp as TOp);\n\n\t\tif (local) {\n\t\t\tthis.pendingOps.shift();\n\t\t} else {\n\t\t\t// Our optimistic local cache (if any) did not account for the incoming op.\n\t\t\tthis.localDirty = true;\n\n\t\t\t// Adjust our queue of locally pending ops to account for the incoming op so that they\n\t\t\t// may be reapplied to the global state if needed.\n\t\t\tfor (let i = 0; i < this.pendingOps.length; i++) {\n\t\t\t\tthis.pendingOps[i] = this.transform(this.pendingOps[i], remoteOp as TOp);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected get state() {\n\t\t// If the locally cached state is dirty, reset it to the global state and reapply our\n\t\t// pending ops to bring it up to date.\n\t\tif (this.localDirty) {\n\t\t\tthis.local = this.global;\n\n\t\t\tfor (const op of this.pendingOps) {\n\t\t\t\tthis.local = this.applyCore(this.local, op);\n\t\t\t}\n\n\t\t\tthis.localDirty = false;\n\t\t}\n\n\t\treturn this.local;\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
@@ -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 = "@fluid-experimental/ot";
8
- export declare const pkgVersion = "2.0.0-rc.2.0.2";
8
+ export declare const pkgVersion = "2.0.0-rc.3.0.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluid-experimental/ot";
8
- export const pkgVersion = "2.0.0-rc.2.0.2";
8
+ export const pkgVersion = "2.0.0-rc.3.0.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,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 = \"@fluid-experimental/ot\";\nexport const pkgVersion = \"2.0.0-rc.2.0.2\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,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 = \"@fluid-experimental/ot\";\nexport const pkgVersion = \"2.0.0-rc.3.0.0\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-experimental/ot",
3
- "version": "2.0.0-rc.2.0.2",
3
+ "version": "2.0.0-rc.3.0.0",
4
4
  "description": "Distributed data structure for hosting ottypes",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -22,30 +22,10 @@
22
22
  "types": "./dist/index.d.ts",
23
23
  "default": "./dist/index.js"
24
24
  }
25
- },
26
- "./public": {
27
- "import": {
28
- "types": "./lib/ot-public.d.ts",
29
- "default": "./lib/index.js"
30
- },
31
- "require": {
32
- "types": "./dist/ot-public.d.ts",
33
- "default": "./dist/index.js"
34
- }
35
- },
36
- "./internal": {
37
- "import": {
38
- "types": "./lib/index.d.ts",
39
- "default": "./lib/index.js"
40
- },
41
- "require": {
42
- "types": "./dist/index.d.ts",
43
- "default": "./dist/index.js"
44
- }
45
25
  }
46
26
  },
47
- "main": "dist/index.js",
48
- "types": "dist/index.d.ts",
27
+ "main": "lib/index.js",
28
+ "types": "lib/index.d.ts",
49
29
  "c8": {
50
30
  "all": true,
51
31
  "cache-dir": "nyc/.cache",
@@ -67,22 +47,24 @@
67
47
  "temp-directory": "nyc/.nyc_output"
68
48
  },
69
49
  "dependencies": {
70
- "@fluid-internal/client-utils": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
71
- "@fluidframework/core-interfaces": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
72
- "@fluidframework/core-utils": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
73
- "@fluidframework/datastore-definitions": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
50
+ "@fluid-internal/client-utils": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
51
+ "@fluidframework/core-interfaces": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
52
+ "@fluidframework/core-utils": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
53
+ "@fluidframework/datastore-definitions": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
74
54
  "@fluidframework/protocol-definitions": "^3.2.0",
75
- "@fluidframework/runtime-definitions": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
76
- "@fluidframework/shared-object-base": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0"
55
+ "@fluidframework/runtime-definitions": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
56
+ "@fluidframework/shared-object-base": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0"
77
57
  },
78
58
  "devDependencies": {
79
- "@arethetypeswrong/cli": "^0.13.3",
80
- "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
81
- "@fluid-private/test-dds-utils": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
59
+ "@arethetypeswrong/cli": "^0.15.2",
60
+ "@biomejs/biome": "^1.6.2",
61
+ "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
62
+ "@fluid-private/test-dds-utils": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
63
+ "@fluid-tools/build-cli": "^0.37.0",
82
64
  "@fluidframework/build-common": "^2.0.3",
83
- "@fluidframework/build-tools": "^0.34.0",
84
- "@fluidframework/eslint-config-fluid": "^4.0.0",
85
- "@fluidframework/test-runtime-utils": ">=2.0.0-rc.2.0.2 <2.0.0-rc.2.1.0",
65
+ "@fluidframework/build-tools": "^0.37.0",
66
+ "@fluidframework/eslint-config-fluid": "^5.1.0",
67
+ "@fluidframework/test-runtime-utils": ">=2.0.0-rc.3.0.0 <2.0.0-rc.3.1.0",
86
68
  "@microsoft/api-extractor": "^7.42.3",
87
69
  "@types/mocha": "^9.1.1",
88
70
  "@types/node": "^18.19.0",
@@ -100,46 +82,31 @@
100
82
  "rimraf": "^4.4.0",
101
83
  "typescript": "~5.1.6"
102
84
  },
103
- "fluidBuild": {
104
- "tasks": {
105
- "build:docs": {
106
- "dependsOn": [
107
- "...",
108
- "api-extractor:commonjs",
109
- "api-extractor:esnext"
110
- ],
111
- "script": false
112
- }
113
- }
114
- },
115
85
  "typeValidation": {
116
86
  "disabled": true,
117
87
  "broken": {}
118
88
  },
119
89
  "scripts": {
120
- "api": "fluid-build . --task api",
121
- "api-extractor:commonjs": "api-extractor run --config ./api-extractor-cjs.json",
122
- "api-extractor:esnext": "api-extractor run --local",
123
90
  "build": "fluid-build . --task build",
124
91
  "build:commonjs": "fluid-build . --task commonjs",
125
92
  "build:compile": "fluid-build . --task compile",
126
- "build:docs": "fluid-build . --task api",
93
+ "build:docs": "api-extractor run --local",
127
94
  "build:esnext": "tsc --project ./tsconfig.json",
128
95
  "build:genver": "gen-version",
129
96
  "build:test": "npm run build:test:esm && npm run build:test:cjs",
130
97
  "build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
131
98
  "build:test:esm": "tsc --project ./src/test/tsconfig.json",
132
- "check:are-the-types-wrong": "attw --pack . --entrypoints .",
99
+ "check:are-the-types-wrong": "attw --pack .",
100
+ "check:prettier": "prettier --check . --cache --ignore-path ../../../../.prettierignore",
133
101
  "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
134
102
  "ci:build:docs": "api-extractor run",
135
103
  "clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
136
104
  "eslint": "eslint --format stylish src",
137
105
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
138
- "format": "npm run prettier:fix",
139
- "lint": "npm run prettier && npm run check:release-tags && npm run eslint",
140
- "lint:fix": "npm run prettier:fix && npm run eslint:fix",
141
- "prettier": "prettier --check . --cache --ignore-path ../../../../.prettierignore",
142
- "prettier:fix": "prettier --write . --cache --ignore-path ../../../../.prettierignore",
106
+ "format": "fluid-build --task format .",
107
+ "format:prettier": "prettier --write . --cache --ignore-path ../../../../.prettierignore",
108
+ "lint": "fluid-build . --task lint",
109
+ "lint:fix": "fluid-build . --task eslint:fix --task format",
143
110
  "test": "npm run test:mocha",
144
111
  "test:coverage": "c8 npm test",
145
112
  "test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
package/src/ot.ts CHANGED
@@ -3,20 +3,17 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert } from "@fluidframework/core-utils";
7
6
  import { bufferToString } from "@fluid-internal/client-utils";
8
- import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
+ import { assert } from "@fluidframework/core-utils/internal";
9
8
  import {
10
9
  IChannelAttributes,
11
- IFluidDataStoreRuntime,
12
10
  IChannelStorageService,
11
+ IFluidDataStoreRuntime,
13
12
  } from "@fluidframework/datastore-definitions";
13
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
14
14
  import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
15
- import {
16
- createSingleBlobSummary,
17
- IFluidSerializer,
18
- SharedObject,
19
- } from "@fluidframework/shared-object-base";
15
+ import { IFluidSerializer } from "@fluidframework/shared-object-base";
16
+ import { SharedObject, createSingleBlobSummary } from "@fluidframework/shared-object-base/internal";
20
17
 
21
18
  interface ISequencedOpInfo<TOp> {
22
19
  client: string;
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluid-experimental/ot";
9
- export const pkgVersion = "2.0.0-rc.2.0.2";
9
+ export const pkgVersion = "2.0.0-rc.3.0.0";
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "../../../../common/build/build-common/api-extractor-base.cjs.primary.json",
4
- // CJS is actually secondary; so, no report.
5
- "apiReport": {
6
- "enabled": false
7
- }
8
- }
@@ -1,11 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /* Excluded from this release type: SharedOT */
10
-
11
- export { }
package/dist/ot-beta.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /* Excluded from this release type: SharedObject */
10
-
11
- /* Excluded from this release type: SharedOT */
12
-
13
- export { }
@@ -1,13 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /* Excluded from this release type: SharedObject */
10
-
11
- /* Excluded from this release type: SharedOT */
12
-
13
- export { }
@@ -1,51 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /**
10
- * @internal
11
- */
12
- export declare abstract class SharedOT<TState, TOp> extends SharedObject {
13
- /**
14
- * Queue of sequenced ops that are above minSeq. Used by 'processCore' to
15
- * adjust incoming ops to account for prior ops that the sender didn't know about
16
- * at the time they submitted their op.
17
- */
18
- private readonly sequencedOps;
19
- /**
20
- * Queue of local pending ops that have not yet been ACKed by the service. Used
21
- * to lazily rebuild the "local" state cache when it is invalidated by interleaved
22
- * remote ops.
23
- */
24
- private readonly pendingOps;
25
- /** The "global" state is the result of applying all sequenced ops. */
26
- private global;
27
- /**
28
- * Lazily cached result of optimistically applying pendingOps on top of the current
29
- * "global" state.
30
- */
31
- private local;
32
- private localDirty;
33
- constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, initialValue: TState);
34
- protected apply(op: TOp): void;
35
- /**
36
- * Apply the given 'op' to the provided 'state', producing a new instance of state.
37
- */
38
- protected abstract applyCore(state: TState, op: TOp): TState;
39
- /**
40
- * Transform the 'input' op to adjust for the earlier 'transform' op.
41
- */
42
- protected abstract transform(input: TOp, transform: TOp): TOp;
43
- protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
44
- protected loadCore(storage: IChannelStorageService): Promise<void>;
45
- protected onDisconnect(): void;
46
- protected processCore(message: ISequencedDocumentMessage, local: boolean): void;
47
- protected get state(): TState;
48
- protected applyStashedOp(): void;
49
- }
50
-
51
- export { }
package/lib/ot-alpha.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /* Excluded from this release type: SharedOT */
10
-
11
- export { }
package/lib/ot-beta.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /* Excluded from this release type: SharedObject */
10
-
11
- /* Excluded from this release type: SharedOT */
12
-
13
- export { }
@@ -1,13 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /* Excluded from this release type: SharedObject */
10
-
11
- /* Excluded from this release type: SharedOT */
12
-
13
- export { }
@@ -1,51 +0,0 @@
1
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
2
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
3
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
4
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
5
- import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
6
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
7
- import { SharedObject } from '@fluidframework/shared-object-base';
8
-
9
- /**
10
- * @internal
11
- */
12
- export declare abstract class SharedOT<TState, TOp> extends SharedObject {
13
- /**
14
- * Queue of sequenced ops that are above minSeq. Used by 'processCore' to
15
- * adjust incoming ops to account for prior ops that the sender didn't know about
16
- * at the time they submitted their op.
17
- */
18
- private readonly sequencedOps;
19
- /**
20
- * Queue of local pending ops that have not yet been ACKed by the service. Used
21
- * to lazily rebuild the "local" state cache when it is invalidated by interleaved
22
- * remote ops.
23
- */
24
- private readonly pendingOps;
25
- /** The "global" state is the result of applying all sequenced ops. */
26
- private global;
27
- /**
28
- * Lazily cached result of optimistically applying pendingOps on top of the current
29
- * "global" state.
30
- */
31
- private local;
32
- private localDirty;
33
- constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, initialValue: TState);
34
- protected apply(op: TOp): void;
35
- /**
36
- * Apply the given 'op' to the provided 'state', producing a new instance of state.
37
- */
38
- protected abstract applyCore(state: TState, op: TOp): TState;
39
- /**
40
- * Transform the 'input' op to adjust for the earlier 'transform' op.
41
- */
42
- protected abstract transform(input: TOp, transform: TOp): TOp;
43
- protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
44
- protected loadCore(storage: IChannelStorageService): Promise<void>;
45
- protected onDisconnect(): void;
46
- protected processCore(message: ISequencedDocumentMessage, local: boolean): void;
47
- protected get state(): TState;
48
- protected applyStashedOp(): void;
49
- }
50
-
51
- export { }
package/lib/test/delta.js DELETED
@@ -1,68 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import Delta from "quill-delta";
6
- import { SharedOT } from "../index.js";
7
- export class SharedDelta extends SharedOT {
8
- static create(runtime, id) {
9
- return runtime.createChannel(id, DeltaFactory.Type);
10
- }
11
- static getFactory() {
12
- return new DeltaFactory();
13
- }
14
- constructor(id, runtime, attributes) {
15
- super(id, runtime, attributes, /* initialValue: */ new Delta());
16
- }
17
- get delta() {
18
- return this.state;
19
- }
20
- get text() {
21
- return this.state.reduce((s, delta) => {
22
- return `${s}${delta.insert?.toString()}`;
23
- }, "");
24
- }
25
- get length() {
26
- return this.text.length;
27
- }
28
- transform(input, transform) {
29
- return new Delta(transform).transform(input, false);
30
- }
31
- applyCore(state, op) {
32
- return state.compose(op);
33
- }
34
- insert(position, text) {
35
- this.apply(new Delta().retain(position).insert(text));
36
- }
37
- delete(start, end) {
38
- this.apply(new Delta().retain(start).delete(end - start));
39
- }
40
- }
41
- export class DeltaFactory {
42
- get type() {
43
- return DeltaFactory.Type;
44
- }
45
- get attributes() {
46
- return DeltaFactory.Attributes;
47
- }
48
- /**
49
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
50
- */
51
- async load(runtime, id, services, attributes) {
52
- const instance = new SharedDelta(id, runtime, attributes);
53
- await instance.load(services);
54
- return instance;
55
- }
56
- create(runtime, id) {
57
- const instance = new SharedDelta(id, runtime, this.attributes);
58
- instance.initializeLocal();
59
- return instance;
60
- }
61
- }
62
- DeltaFactory.Type = "@test/delta-factory";
63
- DeltaFactory.Attributes = {
64
- type: DeltaFactory.Type,
65
- snapshotFormatVersion: "test",
66
- packageVersion: "test",
67
- };
68
- //# sourceMappingURL=delta.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"delta.js","sourceRoot":"","sources":["../../src/test/delta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,OAAO,WAAY,SAAQ,QAAsB;IAC/C,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,IAAI,CAAgB,CAAC;IACpE,CAAC;IAEM,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,YAAY,EAAE,CAAC;IAC3B,CAAC;IAED,YAAY,EAAU,EAAE,OAA+B,EAAE,UAA8B;QACtF,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YACrC,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC1C,CAAC,EAAE,EAAE,CA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,CAAC,UAAU,CAAC,CAAC;QAC/D,QAAQ,CAAC,eAAe,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC;IACjB,CAAC;;AAjCa,iBAAI,GAAG,qBAAqB,CAAC;AAEpB,uBAAU,GAAuB;IACvD,IAAI,EAAE,YAAY,CAAC,IAAI;IACvB,qBAAqB,EAAE,MAAM;IAC7B,cAAc,EAAE,MAAM;CACtB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport Delta from \"quill-delta\";\nimport { SharedOT } from \"../index.js\";\n\nexport class SharedDelta extends SharedOT<Delta, Delta> {\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): SharedDelta {\n\t\treturn runtime.createChannel(id, DeltaFactory.Type) as SharedDelta;\n\t}\n\n\tpublic static getFactory() {\n\t\treturn new DeltaFactory();\n\t}\n\n\tconstructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n\t\tsuper(id, runtime, attributes, /* initialValue: */ new Delta());\n\t}\n\n\tpublic get delta(): Delta {\n\t\treturn this.state;\n\t}\n\n\tpublic get text() {\n\t\treturn this.state.reduce((s, delta) => {\n\t\t\treturn `${s}${delta.insert?.toString()}`;\n\t\t}, \"\");\n\t}\n\n\tpublic get length() {\n\t\treturn this.text.length;\n\t}\n\n\tprotected transform(input: Delta, transform: Delta): Delta {\n\t\treturn new Delta(transform).transform(input, false);\n\t}\n\n\tprotected applyCore(state: Delta, op: Delta): Delta {\n\t\treturn state.compose(op);\n\t}\n\n\tpublic insert(position: number, text: string) {\n\t\tthis.apply(new Delta().retain(position).insert(text));\n\t}\n\n\tpublic delete(start: number, end: number) {\n\t\tthis.apply(new Delta().retain(start).delete(end - start));\n\t}\n}\n\nexport class DeltaFactory implements IChannelFactory {\n\tpublic static Type = \"@test/delta-factory\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: DeltaFactory.Type,\n\t\tsnapshotFormatVersion: \"test\",\n\t\tpackageVersion: \"test\",\n\t};\n\n\tpublic get type() {\n\t\treturn DeltaFactory.Type;\n\t}\n\tpublic get attributes() {\n\t\treturn DeltaFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tconst instance = new SharedDelta(id, runtime, attributes);\n\t\tawait instance.load(services);\n\t\treturn instance;\n\t}\n\n\tpublic create(runtime: IFluidDataStoreRuntime, id: string) {\n\t\tconst instance = new SharedDelta(id, runtime, this.attributes);\n\t\tinstance.initializeLocal();\n\t\treturn instance;\n\t}\n}\n"]}
@@ -1,143 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { strict as assert } from "assert";
6
- import { MockContainerRuntimeFactory, MockFluidDataStoreRuntime, MockStorage, } from "@fluidframework/test-runtime-utils";
7
- import { SharedDelta, DeltaFactory } from "./delta.js";
8
- const createLocalOT = (id) => {
9
- const factory = SharedDelta.getFactory();
10
- return factory.create(new MockFluidDataStoreRuntime(), id);
11
- };
12
- function createConnectedOT(id, runtimeFactory) {
13
- // Create and connect a second SharedCell.
14
- const dataStoreRuntime = new MockFluidDataStoreRuntime();
15
- runtimeFactory.createContainerRuntime(dataStoreRuntime);
16
- const services = {
17
- deltaConnection: dataStoreRuntime.createDeltaConnection(),
18
- objectStorage: new MockStorage(),
19
- };
20
- const ot = new SharedDelta(id, dataStoreRuntime, DeltaFactory.Attributes);
21
- ot.connect(services);
22
- return ot;
23
- }
24
- describe("SharedDelta", () => {
25
- describe("Local state", () => {
26
- let delta;
27
- beforeEach(() => {
28
- delta = createLocalOT("OT");
29
- });
30
- const expect = (expected) => {
31
- assert.deepEqual(delta.text, expected);
32
- };
33
- describe("APIs", () => {
34
- describe("insert", () => {
35
- it("beginning", () => {
36
- delta.insert(0, "1");
37
- expect("1");
38
- delta.insert(0, "0");
39
- expect("01");
40
- });
41
- it("middle", () => {
42
- delta.insert(0, "02");
43
- expect("02");
44
- delta.insert(1, "1");
45
- expect("012");
46
- });
47
- it("end", () => {
48
- delta.insert(0, "01");
49
- expect("01");
50
- delta.insert(2, "2");
51
- expect("012");
52
- });
53
- });
54
- describe("delete", () => {
55
- it("beginning", () => {
56
- delta.insert(0, "01");
57
- expect("01");
58
- delta.delete(0, 1);
59
- expect("1");
60
- });
61
- it("middle", () => {
62
- delta.insert(0, "012");
63
- expect("012");
64
- delta.delete(1, 2);
65
- expect("02");
66
- });
67
- it("end", () => {
68
- delta.insert(0, "01");
69
- expect("01");
70
- delta.delete(1, 2);
71
- expect("0");
72
- });
73
- });
74
- });
75
- });
76
- describe("Connected state", () => {
77
- let doc1;
78
- let doc2;
79
- let containerRuntimeFactory;
80
- describe("APIs", () => {
81
- beforeEach(() => {
82
- containerRuntimeFactory = new MockContainerRuntimeFactory();
83
- doc1 = createConnectedOT("OT1", containerRuntimeFactory);
84
- doc2 = createConnectedOT("OT2", containerRuntimeFactory);
85
- });
86
- afterEach(() => {
87
- expect();
88
- });
89
- const expect = (expected) => {
90
- containerRuntimeFactory.processAllMessages();
91
- const actual1 = doc1.text;
92
- const actual2 = doc2.text;
93
- assert.deepEqual(actual1, actual2, `doc.text must converge (doc1: '${actual1}', doc2: '${actual2}'${expected !== undefined ? ` expected: '${expected}'` : ""})`);
94
- assert.deepEqual(doc1.delta, doc2.delta, `doc.delta must converge (doc1: '${JSON.stringify(doc1.delta)}', doc2: '${JSON.stringify(doc2.delta)})`);
95
- if (expected !== undefined) {
96
- assert.deepEqual(actual1, expected, `doc.text must match expected (expected '${expected}', but got '${actual1}')`);
97
- }
98
- };
99
- it("insertion race 2 before 1", () => {
100
- doc1.insert(0, "03");
101
- expect("03");
102
- doc1.insert(1, "2");
103
- doc2.insert(1, "1");
104
- expect("0123");
105
- });
106
- it("insertion race 1 before 2", () => {
107
- doc1.insert(0, "03");
108
- expect("03");
109
- doc2.insert(1, "2");
110
- doc1.insert(1, "1");
111
- expect("0123");
112
- });
113
- it("insertion race with adjacent insert", () => {
114
- doc1.insert(/* position: */ 0, /* text: */ "1");
115
- doc2.insert(/* position: */ 0, /* text: */ "0");
116
- doc2.insert(/* position: */ 1, /* text: */ "2");
117
- expect("012");
118
- });
119
- it("insert vs. delete conflict", () => {
120
- doc1.insert(0, "023");
121
- expect("023");
122
- doc1.insert(1, "1");
123
- doc2.delete(1, 2);
124
- expect("013");
125
- });
126
- it("delete vs. insert conflict", () => {
127
- doc1.insert(0, "023");
128
- expect("023");
129
- doc1.delete(1, 2);
130
- doc2.insert(1, "1");
131
- expect("013");
132
- });
133
- it("overlapping delete", () => {
134
- doc1.insert(0, "0123");
135
- expect("0123");
136
- doc1.delete(1, 3);
137
- doc2.delete(2, 3);
138
- expect("03");
139
- });
140
- });
141
- });
142
- });
143
- //# sourceMappingURL=ot.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ot.spec.js","sourceRoot":"","sources":["../../src/test/ot.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACN,2BAA2B,EAC3B,yBAAyB,EACzB,WAAW,GACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,aAAa,GAAG,CAAC,EAAU,EAAE,EAAE;IACpC,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC;IACzC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,yBAAyB,EAAE,EAAE,EAAE,CAAC,CAAC;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A4B,EAAE,GAAG,EAAE;gBACrC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACtB,MAAM,CAAC,KAAK,CAAC,CAAC;gBAEd,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClB,MAAM,CAAC,KAAK,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;gBACrC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACtB,MAAM,CAAC,KAAK,CAAC,CAAC;gBAEd,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClB,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;gBACpB,MAAM,CAAC,KAAK,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;gBAC7B,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBACvB,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEf,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClB,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClB,MAAM,CAAC,IAAI,CAAC,CAAC;YACd,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport {\n\tMockContainerRuntimeFactory,\n\tMockFluidDataStoreRuntime,\n\tMockStorage,\n} from \"@fluidframework/test-runtime-utils\";\nimport { SharedDelta, DeltaFactory } from \"./delta.js\";\n\nconst createLocalOT = (id: string) => {\n\tconst factory = SharedDelta.getFactory();\n\treturn factory.create(new MockFluidDataStoreRuntime(), id);\n};\n\nfunction createConnectedOT(id: string, runtimeFactory: MockContainerRuntimeFactory) {\n\t// Create and connect a second SharedCell.\n\tconst dataStoreRuntime = new MockFluidDataStoreRuntime();\n\truntimeFactory.createContainerRuntime(dataStoreRuntime);\n\tconst services = {\n\t\tdeltaConnection: dataStoreRuntime.createDeltaConnection(),\n\t\tobjectStorage: new MockStorage(),\n\t};\n\n\tconst ot = new SharedDelta(id, dataStoreRuntime, DeltaFactory.Attributes);\n\tot.connect(services);\n\treturn ot;\n}\n\ndescribe(\"SharedDelta\", () => {\n\tdescribe(\"Local state\", () => {\n\t\tlet delta: SharedDelta;\n\n\t\tbeforeEach(() => {\n\t\t\tdelta = createLocalOT(\"OT\");\n\t\t});\n\n\t\tconst expect = (expected: string) => {\n\t\t\tassert.deepEqual(delta.text, expected);\n\t\t};\n\n\t\tdescribe(\"APIs\", () => {\n\t\t\tdescribe(\"insert\", () => {\n\t\t\t\tit(\"beginning\", () => {\n\t\t\t\t\tdelta.insert(0, \"1\");\n\t\t\t\t\texpect(\"1\");\n\n\t\t\t\t\tdelta.insert(0, \"0\");\n\t\t\t\t\texpect(\"01\");\n\t\t\t\t});\n\n\t\t\t\tit(\"middle\", () => {\n\t\t\t\t\tdelta.insert(0, \"02\");\n\t\t\t\t\texpect(\"02\");\n\n\t\t\t\t\tdelta.insert(1, \"1\");\n\t\t\t\t\texpect(\"012\");\n\t\t\t\t});\n\n\t\t\t\tit(\"end\", () => {\n\t\t\t\t\tdelta.insert(0, \"01\");\n\t\t\t\t\texpect(\"01\");\n\n\t\t\t\t\tdelta.insert(2, \"2\");\n\t\t\t\t\texpect(\"012\");\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tdescribe(\"delete\", () => {\n\t\t\t\tit(\"beginning\", () => {\n\t\t\t\t\tdelta.insert(0, \"01\");\n\t\t\t\t\texpect(\"01\");\n\n\t\t\t\t\tdelta.delete(0, 1);\n\t\t\t\t\texpect(\"1\");\n\t\t\t\t});\n\n\t\t\t\tit(\"middle\", () => {\n\t\t\t\t\tdelta.insert(0, \"012\");\n\t\t\t\t\texpect(\"012\");\n\n\t\t\t\t\tdelta.delete(1, 2);\n\t\t\t\t\texpect(\"02\");\n\t\t\t\t});\n\n\t\t\t\tit(\"end\", () => {\n\t\t\t\t\tdelta.insert(0, \"01\");\n\t\t\t\t\texpect(\"01\");\n\n\t\t\t\t\tdelta.delete(1, 2);\n\t\t\t\t\texpect(\"0\");\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe(\"Connected state\", () => {\n\t\tlet doc1: SharedDelta;\n\t\tlet doc2: SharedDelta;\n\t\tlet containerRuntimeFactory: MockContainerRuntimeFactory;\n\n\t\tdescribe(\"APIs\", () => {\n\t\t\tbeforeEach(() => {\n\t\t\t\tcontainerRuntimeFactory = new MockContainerRuntimeFactory();\n\t\t\t\tdoc1 = createConnectedOT(\"OT1\", containerRuntimeFactory);\n\t\t\t\tdoc2 = createConnectedOT(\"OT2\", containerRuntimeFactory);\n\t\t\t});\n\n\t\t\tafterEach(() => {\n\t\t\t\texpect();\n\t\t\t});\n\n\t\t\tconst expect = (expected?: string) => {\n\t\t\t\tcontainerRuntimeFactory.processAllMessages();\n\n\t\t\t\tconst actual1 = doc1.text;\n\t\t\t\tconst actual2 = doc2.text;\n\n\t\t\t\tassert.deepEqual(\n\t\t\t\t\tactual1,\n\t\t\t\t\tactual2,\n\t\t\t\t\t`doc.text must converge (doc1: '${actual1}', doc2: '${actual2}'${\n\t\t\t\t\t\texpected !== undefined ? ` expected: '${expected}'` : \"\"\n\t\t\t\t\t})`,\n\t\t\t\t);\n\n\t\t\t\tassert.deepEqual(\n\t\t\t\t\tdoc1.delta,\n\t\t\t\t\tdoc2.delta,\n\t\t\t\t\t`doc.delta must converge (doc1: '${JSON.stringify(\n\t\t\t\t\t\tdoc1.delta,\n\t\t\t\t\t)}', doc2: '${JSON.stringify(doc2.delta)})`,\n\t\t\t\t);\n\n\t\t\t\tif (expected !== undefined) {\n\t\t\t\t\tassert.deepEqual(\n\t\t\t\t\t\tactual1,\n\t\t\t\t\t\texpected,\n\t\t\t\t\t\t`doc.text must match expected (expected '${expected}', but got '${actual1}')`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tit(\"insertion race 2 before 1\", () => {\n\t\t\t\tdoc1.insert(0, \"03\");\n\t\t\t\texpect(\"03\");\n\n\t\t\t\tdoc1.insert(1, \"2\");\n\t\t\t\tdoc2.insert(1, \"1\");\n\t\t\t\texpect(\"0123\");\n\t\t\t});\n\n\t\t\tit(\"insertion race 1 before 2\", () => {\n\t\t\t\tdoc1.insert(0, \"03\");\n\t\t\t\texpect(\"03\");\n\n\t\t\t\tdoc2.insert(1, \"2\");\n\t\t\t\tdoc1.insert(1, \"1\");\n\t\t\t\texpect(\"0123\");\n\t\t\t});\n\n\t\t\tit(\"insertion race with adjacent insert\", () => {\n\t\t\t\tdoc1.insert(/* position: */ 0, /* text: */ \"1\");\n\t\t\t\tdoc2.insert(/* position: */ 0, /* text: */ \"0\");\n\t\t\t\tdoc2.insert(/* position: */ 1, /* text: */ \"2\");\n\t\t\t\texpect(\"012\");\n\t\t\t});\n\n\t\t\tit(\"insert vs. delete conflict\", () => {\n\t\t\t\tdoc1.insert(0, \"023\");\n\t\t\t\texpect(\"023\");\n\n\t\t\t\tdoc1.insert(1, \"1\");\n\t\t\t\tdoc2.delete(1, 2);\n\t\t\t\texpect(\"013\");\n\t\t\t});\n\n\t\t\tit(\"delete vs. insert conflict\", () => {\n\t\t\t\tdoc1.insert(0, \"023\");\n\t\t\t\texpect(\"023\");\n\n\t\t\t\tdoc1.delete(1, 2);\n\t\t\t\tdoc2.insert(1, \"1\");\n\t\t\t\texpect(\"013\");\n\t\t\t});\n\n\t\t\tit(\"overlapping delete\", () => {\n\t\t\t\tdoc1.insert(0, \"0123\");\n\t\t\t\texpect(\"0123\");\n\n\t\t\t\tdoc1.delete(1, 3);\n\t\t\t\tdoc2.delete(2, 3);\n\t\t\t\texpect(\"03\");\n\t\t\t});\n\t\t});\n\t});\n});\n"]}
@@ -1,208 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { strict as assert } from "assert";
6
- import { Random } from "best-random";
7
- import { MockFluidDataStoreRuntime, MockStorage, MockContainerRuntimeFactoryForReconnection, } from "@fluidframework/test-runtime-utils";
8
- import { SharedDelta } from "./delta.js";
9
- describe("SharedOT", () => {
10
- describe("stress", () => {
11
- let containerRuntimeFactory;
12
- let docs; // Array of docs under test
13
- let runtimes = [];
14
- let trace; // Repro steps to be printed if a failure is encountered.
15
- const extract = (doc) => {
16
- return doc.text;
17
- };
18
- /**
19
- * Drains the queue of pending ops for each client and vets that all docs converged on the same state.
20
- */
21
- const expect = async () => {
22
- // Reconnect any disconnected clients before processing pending ops.
23
- {
24
- for (let i = 0; i < runtimes.length; i++) {
25
- const runtime = runtimes[i];
26
- if (!runtime.connected) {
27
- trace?.push(`containerRuntime${i + 1}.connected = true;`);
28
- runtime.connected = true;
29
- }
30
- }
31
- }
32
- // Broadcast and process all pending messages across all docs.
33
- trace?.push("await expect();");
34
- containerRuntimeFactory.processAllMessages();
35
- // Verify that all docs have converged on the same final state.
36
- const doc0 = docs[0];
37
- const actual0 = extract(doc0);
38
- {
39
- for (let i = 1; i < docs.length; i++) {
40
- const docN = docs[i];
41
- const actualN = extract(docN);
42
- assert.deepEqual(actual0, actualN);
43
- }
44
- }
45
- };
46
- /**
47
- * Performs a stress run using the given parameters.
48
- *
49
- * 'syncProbability' is the probability that the clients will drain their queue of incoming messages
50
- * and check for convergence.
51
- *
52
- * 'disconnectProbability' is the probability that a client will disconnect, forcing it to regenerate
53
- * and resubmit any pending local operations on the next sync.
54
- *
55
- * 'seed' is the 32-bit integer used to seed the PRNG.
56
- */
57
- async function stress(numClients, numOps, syncProbability, disconnectProbability, seed) {
58
- try {
59
- docs = [];
60
- runtimes = [];
61
- trace = [];
62
- containerRuntimeFactory = new MockContainerRuntimeFactoryForReconnection();
63
- // Create docs for this stress run.
64
- for (let i = 0; i < numClients; i++) {
65
- const dataStoreRuntimeN = new MockFluidDataStoreRuntime();
66
- const containerRuntimeN = containerRuntimeFactory.createContainerRuntime(dataStoreRuntimeN);
67
- const servicesN = {
68
- deltaConnection: dataStoreRuntimeN.createDeltaConnection(),
69
- objectStorage: new MockStorage(),
70
- };
71
- const docN = SharedDelta.getFactory().create(dataStoreRuntimeN, `doc-${i}`);
72
- docN.connect(servicesN);
73
- docs.push(docN);
74
- runtimes.push(containerRuntimeN);
75
- }
76
- // Initialize PRNG with given seed.
77
- const float64 = new Random(seed).float64;
78
- // Returns a pseudorandom 32b integer in the range [0 .. max).
79
- // eslint-disable-next-line no-bitwise
80
- const int32 = (max = 0x7fffffff) => (float64() * max) | 0;
81
- const randomText = () => `${float64().toString(36).substr(0, int32(12))}`;
82
- const insert = (docIndex, position, text) => {
83
- trace?.push(`doc${docIndex + 1}.insert(/* position: */ ${position}, /* text: */ ${JSON.stringify(text)});`);
84
- docs[docIndex].insert(position, text);
85
- };
86
- const del = (docIndex, start, end) => {
87
- trace?.push(`doc${docIndex + 1}.delete(/* start: */ ${start}, /* end: */ ${end});`);
88
- docs[docIndex].delete(start, end);
89
- };
90
- // Loop for the prescribed number of iterations, randomly mutating one of documents with one
91
- // of the following operations:
92
- //
93
- // * insert text
94
- // * delete a range of text
95
- //
96
- // Following each operation, there is a `syncProbability` chance that clients will exchange
97
- // ops and vet convergence.
98
- for (let i = 0; i < numOps; i++) {
99
- // Choose a client to perform the operation.
100
- const docIndex = int32(docs.length);
101
- const doc = docs[docIndex];
102
- const { length } = doc;
103
- switch (int32(4)) {
104
- case 0: {
105
- if (length > 0) {
106
- const start = int32(length);
107
- const end = int32(start - length + 1) + start;
108
- del(docIndex, start, end);
109
- }
110
- break;
111
- }
112
- default:
113
- insert(docIndex, int32(length + 1), randomText());
114
- break;
115
- }
116
- if (runtimes[docIndex].connected && float64() < disconnectProbability) {
117
- trace?.push(`containerRuntime${docIndex + 1}.connected = false;`);
118
- runtimes[docIndex].connected = false;
119
- }
120
- // Clients periodically exchanging ops, at which point we verify they have converged
121
- // on the same state.
122
- if (float64() < syncProbability) {
123
- await expect();
124
- }
125
- }
126
- // Test is finished. Drain pending ops and vet that clients converged.
127
- await expect();
128
- }
129
- catch (error) {
130
- // If an error occurs, dump the repro instructions.
131
- for (const s of trace) {
132
- console.log(s);
133
- }
134
- // Also dump the current state of the docs.
135
- for (const m of docs) {
136
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
137
- console.log(m.toString());
138
- }
139
- // Finally, rethrow the original error.
140
- throw error;
141
- }
142
- }
143
- for (const { numClients, numOps, syncProbability, disconnectProbability, seed } of [
144
- {
145
- numClients: 2,
146
- numOps: 1000,
147
- syncProbability: 0.3,
148
- disconnectProbability: 0,
149
- seed: 0x84d43a0a,
150
- },
151
- {
152
- numClients: 3,
153
- numOps: 1000,
154
- syncProbability: 0.1,
155
- disconnectProbability: 0,
156
- seed: 0x655c763b,
157
- },
158
- {
159
- numClients: 5,
160
- numOps: 200,
161
- syncProbability: 0.0,
162
- disconnectProbability: 0,
163
- seed: 0x2f98736d,
164
- },
165
- {
166
- numClients: 2,
167
- numOps: 1000,
168
- syncProbability: 0.3,
169
- disconnectProbability: 0.25,
170
- seed: 0x84d43a0a,
171
- },
172
- ]) {
173
- it(`Stress (numClients=${numClients} numOps=${numOps} syncProbability=${syncProbability} disconnectProbability=${disconnectProbability} seed=0x${seed
174
- .toString(16)
175
- .padStart(8, "0")})`, async function () {
176
- // Note: Must use 'function' rather than arrow '() => { .. }' in order to set 'this.timeout(..)'
177
- this.timeout(20000);
178
- await stress(numClients, numOps, syncProbability, disconnectProbability, seed);
179
- });
180
- }
181
- it.skip("stress-loop", async function () {
182
- // Note: Must use 'function' rather than arrow '() => { .. }' in order to set 'this.timeout(..)'
183
- this.timeout(0); // Disable timeouts for stress loop
184
- let iterations = 0;
185
- const start = Date.now();
186
- let lastStatus = start;
187
- // eslint-disable-next-line no-constant-condition
188
- while (true) {
189
- await stress(
190
- /* numClients: */ 2,
191
- /* numOps: */ 1000,
192
- /* syncProbability: */ 0.1,
193
- /* disconnectProbability: */ 0,
194
- // eslint-disable-next-line no-bitwise
195
- /* seed: */ (Math.random() * 0x100000000) >>> 0);
196
- // console.log(docs[0].toString());
197
- ++iterations;
198
- const now = Date.now();
199
- if (now - lastStatus > 5000) {
200
- process.stdout.write(`Stress loop: ${iterations} iterations completed - Total Elapsed: ${((Date.now() - start) /
201
- 1000).toFixed(2)}s\n`);
202
- lastStatus = now;
203
- }
204
- }
205
- });
206
- });
207
- });
208
- //# sourceMappingURL=ot.stress.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ot.stress.spec.js","sourceRoot":"","sources":["../../src/test/ot.stress.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACN,yBAAyB,EACzB,WAAW,EACX,0CAA0C,GAE1C,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACzB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACvB,IAAI,uBAAmE,CAAC;QACxE,IAAI,IAAmB,CAAC,CAAC,2BAA2B;QACpD,IAAI,QAAQ,GAA0C,EAAE,CAAC;QACzD,IAAI,KAAe,CAAC,CAAC,yDAAyD;QAE9E,MAAM,OAAO,GAAG,CAAC,GAAgB,EAAE,EAAE;YACpC,OAAO,GAAG,CAAC,IAAI,CAAC;QACjB,CAAC,CAAC;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I,EAAE;oBAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CACnB,gBAAgB,UAAU,0CAA0C,CACnE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;wBACpB,IAAI,CACJ,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CACjB,CAAC;oBACF,UAAU,GAAG,GAAG,CAAC;iBACjB;aACD;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport { Random } from \"best-random\";\nimport { IChannelServices } from \"@fluidframework/datastore-definitions\";\nimport {\n\tMockFluidDataStoreRuntime,\n\tMockStorage,\n\tMockContainerRuntimeFactoryForReconnection,\n\tMockContainerRuntimeForReconnection,\n} from \"@fluidframework/test-runtime-utils\";\nimport { SharedDelta } from \"./delta.js\";\n\ndescribe(\"SharedOT\", () => {\n\tdescribe(\"stress\", () => {\n\t\tlet containerRuntimeFactory: MockContainerRuntimeFactoryForReconnection;\n\t\tlet docs: SharedDelta[]; // Array of docs under test\n\t\tlet runtimes: MockContainerRuntimeForReconnection[] = [];\n\t\tlet trace: string[]; // Repro steps to be printed if a failure is encountered.\n\n\t\tconst extract = (doc: SharedDelta) => {\n\t\t\treturn doc.text;\n\t\t};\n\n\t\t/**\n\t\t * Drains the queue of pending ops for each client and vets that all docs converged on the same state.\n\t\t */\n\t\tconst expect = async () => {\n\t\t\t// Reconnect any disconnected clients before processing pending ops.\n\t\t\t{\n\t\t\t\tfor (let i = 0; i < runtimes.length; i++) {\n\t\t\t\t\tconst runtime = runtimes[i];\n\t\t\t\t\tif (!runtime.connected) {\n\t\t\t\t\t\ttrace?.push(`containerRuntime${i + 1}.connected = true;`);\n\t\t\t\t\t\truntime.connected = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Broadcast and process all pending messages across all docs.\n\t\t\ttrace?.push(\"await expect();\");\n\t\t\tcontainerRuntimeFactory.processAllMessages();\n\n\t\t\t// Verify that all docs have converged on the same final state.\n\t\t\tconst doc0 = docs[0];\n\t\t\tconst actual0 = extract(doc0);\n\n\t\t\t{\n\t\t\t\tfor (let i = 1; i < docs.length; i++) {\n\t\t\t\t\tconst docN = docs[i];\n\t\t\t\t\tconst actualN = extract(docN);\n\t\t\t\t\tassert.deepEqual(actual0, actualN);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * Performs a stress run using the given parameters.\n\t\t *\n\t\t * 'syncProbability' is the probability that the clients will drain their queue of incoming messages\n\t\t * and check for convergence.\n\t\t *\n\t\t * 'disconnectProbability' is the probability that a client will disconnect, forcing it to regenerate\n\t\t * and resubmit any pending local operations on the next sync.\n\t\t *\n\t\t * 'seed' is the 32-bit integer used to seed the PRNG.\n\t\t */\n\t\tasync function stress(\n\t\t\tnumClients: number,\n\t\t\tnumOps: number,\n\t\t\tsyncProbability: number,\n\t\t\tdisconnectProbability: number,\n\t\t\tseed: number,\n\t\t) {\n\t\t\ttry {\n\t\t\t\tdocs = [];\n\t\t\t\truntimes = [];\n\t\t\t\ttrace = [];\n\n\t\t\t\tcontainerRuntimeFactory = new MockContainerRuntimeFactoryForReconnection();\n\n\t\t\t\t// Create docs for this stress run.\n\t\t\t\tfor (let i = 0; i < numClients; i++) {\n\t\t\t\t\tconst dataStoreRuntimeN = new MockFluidDataStoreRuntime();\n\t\t\t\t\tconst containerRuntimeN =\n\t\t\t\t\t\tcontainerRuntimeFactory.createContainerRuntime(dataStoreRuntimeN);\n\t\t\t\t\tconst servicesN: IChannelServices = {\n\t\t\t\t\t\tdeltaConnection: dataStoreRuntimeN.createDeltaConnection(),\n\t\t\t\t\t\tobjectStorage: new MockStorage(),\n\t\t\t\t\t};\n\n\t\t\t\t\tconst docN = SharedDelta.getFactory().create(dataStoreRuntimeN, `doc-${i}`);\n\t\t\t\t\tdocN.connect(servicesN);\n\n\t\t\t\t\tdocs.push(docN);\n\t\t\t\t\truntimes.push(containerRuntimeN);\n\t\t\t\t}\n\n\t\t\t\t// Initialize PRNG with given seed.\n\t\t\t\tconst float64 = new Random(seed).float64;\n\n\t\t\t\t// Returns a pseudorandom 32b integer in the range [0 .. max).\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tconst int32 = (max = 0x7fffffff) => (float64() * max) | 0;\n\n\t\t\t\tconst randomText = () => `${float64().toString(36).substr(0, int32(12))}`;\n\n\t\t\t\tconst insert = (docIndex: number, position: number, text: string) => {\n\t\t\t\t\ttrace?.push(\n\t\t\t\t\t\t`doc${\n\t\t\t\t\t\t\tdocIndex + 1\n\t\t\t\t\t\t}.insert(/* position: */ ${position}, /* text: */ ${JSON.stringify(\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t)});`,\n\t\t\t\t\t);\n\t\t\t\t\tdocs[docIndex].insert(position, text);\n\t\t\t\t};\n\n\t\t\t\tconst del = (docIndex: number, start: number, end: number) => {\n\t\t\t\t\ttrace?.push(\n\t\t\t\t\t\t`doc${docIndex + 1}.delete(/* start: */ ${start}, /* end: */ ${end});`,\n\t\t\t\t\t);\n\t\t\t\t\tdocs[docIndex].delete(start, end);\n\t\t\t\t};\n\n\t\t\t\t// Loop for the prescribed number of iterations, randomly mutating one of documents with one\n\t\t\t\t// of the following operations:\n\t\t\t\t//\n\t\t\t\t// * insert text\n\t\t\t\t// * delete a range of text\n\t\t\t\t//\n\t\t\t\t// Following each operation, there is a `syncProbability` chance that clients will exchange\n\t\t\t\t// ops and vet convergence.\n\t\t\t\tfor (let i = 0; i < numOps; i++) {\n\t\t\t\t\t// Choose a client to perform the operation.\n\t\t\t\t\tconst docIndex = int32(docs.length);\n\t\t\t\t\tconst doc = docs[docIndex];\n\n\t\t\t\t\tconst { length } = doc;\n\n\t\t\t\t\tswitch (int32(4)) {\n\t\t\t\t\t\tcase 0: {\n\t\t\t\t\t\t\tif (length > 0) {\n\t\t\t\t\t\t\t\tconst start = int32(length);\n\t\t\t\t\t\t\t\tconst end = int32(start - length + 1) + start;\n\t\t\t\t\t\t\t\tdel(docIndex, start, end);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tinsert(docIndex, int32(length + 1), randomText());\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (runtimes[docIndex].connected && float64() < disconnectProbability) {\n\t\t\t\t\t\ttrace?.push(`containerRuntime${docIndex + 1}.connected = false;`);\n\n\t\t\t\t\t\truntimes[docIndex].connected = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Clients periodically exchanging ops, at which point we verify they have converged\n\t\t\t\t\t// on the same state.\n\t\t\t\t\tif (float64() < syncProbability) {\n\t\t\t\t\t\tawait expect();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Test is finished. Drain pending ops and vet that clients converged.\n\t\t\t\tawait expect();\n\t\t\t} catch (error) {\n\t\t\t\t// If an error occurs, dump the repro instructions.\n\t\t\t\tfor (const s of trace) {\n\t\t\t\t\tconsole.log(s);\n\t\t\t\t}\n\n\t\t\t\t// Also dump the current state of the docs.\n\t\t\t\tfor (const m of docs) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\tconsole.log(m.toString());\n\t\t\t\t}\n\n\t\t\t\t// Finally, rethrow the original error.\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tfor (const { numClients, numOps, syncProbability, disconnectProbability, seed } of [\n\t\t\t{\n\t\t\t\tnumClients: 2,\n\t\t\t\tnumOps: 1000,\n\t\t\t\tsyncProbability: 0.3,\n\t\t\t\tdisconnectProbability: 0,\n\t\t\t\tseed: 0x84d43a0a,\n\t\t\t},\n\t\t\t{\n\t\t\t\tnumClients: 3,\n\t\t\t\tnumOps: 1000,\n\t\t\t\tsyncProbability: 0.1,\n\t\t\t\tdisconnectProbability: 0,\n\t\t\t\tseed: 0x655c763b,\n\t\t\t},\n\t\t\t{\n\t\t\t\tnumClients: 5,\n\t\t\t\tnumOps: 200,\n\t\t\t\tsyncProbability: 0.0,\n\t\t\t\tdisconnectProbability: 0,\n\t\t\t\tseed: 0x2f98736d,\n\t\t\t},\n\t\t\t{\n\t\t\t\tnumClients: 2,\n\t\t\t\tnumOps: 1000,\n\t\t\t\tsyncProbability: 0.3,\n\t\t\t\tdisconnectProbability: 0.25,\n\t\t\t\tseed: 0x84d43a0a,\n\t\t\t},\n\t\t]) {\n\t\t\tit(`Stress (numClients=${numClients} numOps=${numOps} syncProbability=${syncProbability} disconnectProbability=${disconnectProbability} seed=0x${seed\n\t\t\t\t.toString(16)\n\t\t\t\t.padStart(8, \"0\")})`, async function () {\n\t\t\t\t// Note: Must use 'function' rather than arrow '() => { .. }' in order to set 'this.timeout(..)'\n\t\t\t\tthis.timeout(20000);\n\n\t\t\t\tawait stress(numClients, numOps, syncProbability, disconnectProbability, seed);\n\t\t\t});\n\t\t}\n\n\t\tit.skip(\"stress-loop\", async function () {\n\t\t\t// Note: Must use 'function' rather than arrow '() => { .. }' in order to set 'this.timeout(..)'\n\t\t\tthis.timeout(0); // Disable timeouts for stress loop\n\n\t\t\tlet iterations = 0;\n\t\t\tconst start = Date.now();\n\t\t\tlet lastStatus = start;\n\n\t\t\t// eslint-disable-next-line no-constant-condition\n\t\t\twhile (true) {\n\t\t\t\tawait stress(\n\t\t\t\t\t/* numClients: */ 2,\n\t\t\t\t\t/* numOps: */ 1000,\n\t\t\t\t\t/* syncProbability: */ 0.1,\n\t\t\t\t\t/* disconnectProbability: */ 0,\n\t\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\t\t/* seed: */ (Math.random() * 0x100000000) >>> 0,\n\t\t\t\t);\n\n\t\t\t\t// console.log(docs[0].toString());\n\n\t\t\t\t++iterations;\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - lastStatus > 5000) {\n\t\t\t\t\tprocess.stdout.write(\n\t\t\t\t\t\t`Stress loop: ${iterations} iterations completed - Total Elapsed: ${(\n\t\t\t\t\t\t\t(Date.now() - start) /\n\t\t\t\t\t\t\t1000\n\t\t\t\t\t\t).toFixed(2)}s\\n`,\n\t\t\t\t\t);\n\t\t\t\t\tlastStatus = now;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t});\n});\n"]}
File without changes