@fluidframework/replay-driver 2.1.0-276985 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +84 -2
- package/dist/public.d.ts +1 -1
- package/dist/replayDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/replayDocumentDeltaConnection.js +8 -0
- package/dist/replayDocumentDeltaConnection.js.map +1 -1
- package/internal.d.ts +1 -1
- package/lib/public.d.ts +1 -1
- package/lib/replayDocumentDeltaConnection.d.ts.map +1 -1
- package/lib/replayDocumentDeltaConnection.js +8 -0
- package/lib/replayDocumentDeltaConnection.js.map +1 -1
- package/package.json +13 -13
- package/src/replayDocumentDeltaConnection.ts +12 -4
- package/tsconfig.json +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This is an implementation of a driver which provides a DocumentService which uses the DocumentService provided to it to fetch ops and then replay those ops
|
|
4
4
|
to mimic the web socket connection.
|
|
5
5
|
|
|
6
|
-
<!-- AUTO-GENERATED-CONTENT:START (
|
|
6
|
+
<!-- AUTO-GENERATED-CONTENT:START (LIBRARY_PACKAGE_README_HEADER) -->
|
|
7
7
|
|
|
8
8
|
<!-- prettier-ignore-start -->
|
|
9
9
|
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
@@ -16,15 +16,97 @@ library consumers should always prefer `^`.
|
|
|
16
16
|
|
|
17
17
|
If using any of Fluid Framework's unstable APIs (for example, its `beta` APIs), we recommend using a more constrained version range, such as `~`.
|
|
18
18
|
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
To get started, install the package by running the following command:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm i @fluidframework/replay-driver
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API Documentation
|
|
28
|
+
|
|
29
|
+
API documentation for **@fluidframework/replay-driver** is available at <https://fluidframework.com/docs/apis/replay-driver>.
|
|
30
|
+
|
|
19
31
|
<!-- prettier-ignore-end -->
|
|
20
32
|
|
|
21
33
|
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
22
34
|
|
|
23
|
-
<!-- AUTO-GENERATED-CONTENT:START (
|
|
35
|
+
<!-- AUTO-GENERATED-CONTENT:START (LIBRARY_PACKAGE_README_FOOTER) -->
|
|
24
36
|
|
|
25
37
|
<!-- prettier-ignore-start -->
|
|
26
38
|
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
27
39
|
|
|
40
|
+
## Minimum Client Requirements
|
|
41
|
+
|
|
42
|
+
These are the platform requirements for the current version of Fluid Framework Client Packages.
|
|
43
|
+
These requirements err on the side of being too strict since within a major version they can be relaxed over time, but not made stricter.
|
|
44
|
+
For Long Term Support (LTS) versions this can require supporting these platforms for several years.
|
|
45
|
+
|
|
46
|
+
It is likely that other configurations will work, but they are not supported: if they stop working, we do not consider that a bug.
|
|
47
|
+
If you would benefit from support for something not listed here, file an issue and the product team will evaluate your request.
|
|
48
|
+
When making such a request please include if the configuration already works (and thus the request is just that it becomes officially supported), or if changes are required to get it working.
|
|
49
|
+
|
|
50
|
+
### Supported Runtimes
|
|
51
|
+
|
|
52
|
+
- NodeJs ^20.10.0 except that we will drop support for it [when NodeJs 20 loses its upstream support on 2026-04-30](https://github.com/nodejs/release#release-schedule), and will support a newer LTS version of NodeJS (22) at least 1 year before 20 is end-of-life. This same policy applies to NodeJS 22 when it is end of life (2027-04-30).
|
|
53
|
+
- Modern browsers supporting the es2022 standard library: in response to asks we can add explicit support for using babel to polyfill to target specific standards or runtimes (meaning we can avoid/remove use of things that don't polyfill robustly, but otherwise target modern standards).
|
|
54
|
+
|
|
55
|
+
### Supported Tools
|
|
56
|
+
|
|
57
|
+
- TypeScript 5.4:
|
|
58
|
+
- All [`strict`](https://www.typescriptlang.org/tsconfig) options are supported.
|
|
59
|
+
- [`strictNullChecks`](https://www.typescriptlang.org/tsconfig) is required.
|
|
60
|
+
- [Configuration options deprecated in 5.0](https://github.com/microsoft/TypeScript/issues/51909) are not supported.
|
|
61
|
+
- `exactOptionalPropertyTypes` is currently not fully supported.
|
|
62
|
+
If used, narrowing members of Fluid Framework types types using `in`, `Reflect.has`, `Object.hasOwn` or `Object.prototype.hasOwnProperty` should be avoided as they may incorrectly exclude `undefined` from the possible values in some cases.
|
|
63
|
+
- [webpack](https://webpack.js.org/) 5
|
|
64
|
+
- We are not intending to be prescriptive about what bundler to use.
|
|
65
|
+
Other bundlers which can handle ES Modules should work, but webpack is the only one we actively test.
|
|
66
|
+
|
|
67
|
+
### Module Resolution
|
|
68
|
+
|
|
69
|
+
[`Node16`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) resolution should be used with TypeScript compilerOptions to follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
|
|
70
|
+
Node10 resolution is not supported as it does not support Fluid Framework's API structuring pattern that is used to distinguish stable APIs from those that are in development.
|
|
71
|
+
|
|
72
|
+
### Module Formats
|
|
73
|
+
|
|
74
|
+
- ES Modules:
|
|
75
|
+
ES Modules are the preferred way to consume our client packages (including in NodeJs) and consuming our client packages from ES Modules is fully supported.
|
|
76
|
+
- CommonJs:
|
|
77
|
+
Consuming our client packages as CommonJs is supported only in NodeJS and only for the cases listed below.
|
|
78
|
+
This is done to accommodate some workflows without good ES Module support.
|
|
79
|
+
If you have a workflow you would like included in this list, file an issue.
|
|
80
|
+
Once this list of workflows motivating CommonJS support is empty, we may drop support for CommonJS one year after notice of the change is posted here.
|
|
81
|
+
|
|
82
|
+
- Testing with Jest (which lacks [stable ESM support](https://jestjs.io/docs/ecmascript-modules) due to [unstable APIs in NodeJs](https://github.com/nodejs/node/issues/37648))
|
|
83
|
+
|
|
84
|
+
## Contribution Guidelines
|
|
85
|
+
|
|
86
|
+
There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
|
|
87
|
+
|
|
88
|
+
- Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
89
|
+
- [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
|
|
90
|
+
- Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
91
|
+
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
92
|
+
|
|
93
|
+
Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
|
|
94
|
+
|
|
95
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
96
|
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
97
|
+
|
|
98
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
99
|
+
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
100
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
101
|
+
|
|
102
|
+
## Help
|
|
103
|
+
|
|
104
|
+
Not finding what you're looking for in this README? Check out [fluidframework.com](https://fluidframework.com/docs/).
|
|
105
|
+
|
|
106
|
+
Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
|
|
107
|
+
|
|
108
|
+
Thank you!
|
|
109
|
+
|
|
28
110
|
## Trademark
|
|
29
111
|
|
|
30
112
|
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
package/dist/public.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replayDocumentDeltaConnection.d.ts","sourceRo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E,GAAG;IAEtC,OAAO,CAAC,SAAS,CAAS;IAC1B,IAAW,QAAQ,YAElB;IACM,OAAO;IAId;;OAEG;YACW,eAAe;CA6C7B"}
|
|
@@ -68,6 +68,8 @@ class ReplayControllerStatic extends replayController_js_1.ReplayController {
|
|
|
68
68
|
}
|
|
69
69
|
if (this.unitIsTime === true) {
|
|
70
70
|
for (let i = 0; i < fetchedOps.length; i += 1) {
|
|
71
|
+
// Non null asserting here because we are iterating over fetchedOps
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
71
73
|
const timeStamp = fetchedOps[i].timestamp;
|
|
72
74
|
if (timeStamp !== undefined) {
|
|
73
75
|
if (this.firstTimeStamp === undefined) {
|
|
@@ -90,6 +92,8 @@ class ReplayControllerStatic extends replayController_js_1.ReplayController {
|
|
|
90
92
|
const replayNextOps = () => {
|
|
91
93
|
// Emit the ops from replay to the end every "deltainterval" milliseconds
|
|
92
94
|
// to simulate the socket stream
|
|
95
|
+
// TODO Why are we non null asserting here
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
93
97
|
const currentOp = fetchedOps[current];
|
|
94
98
|
const playbackOps = [currentOp];
|
|
95
99
|
let nextInterval = ReplayControllerStatic.DelayInterval;
|
|
@@ -99,6 +103,8 @@ class ReplayControllerStatic extends replayController_js_1.ReplayController {
|
|
|
99
103
|
if (currentTimeStamp !== undefined) {
|
|
100
104
|
// Emit more ops that is in the ReplayResolution window
|
|
101
105
|
while (current < fetchedOps.length) {
|
|
106
|
+
// TODO Why are we non null asserting here
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
102
108
|
const op = fetchedOps[current];
|
|
103
109
|
if (op.timestamp === undefined) {
|
|
104
110
|
// Missing timestamp, just delay the standard amount of time
|
|
@@ -242,6 +248,8 @@ class ReplayDocumentDeltaConnection extends client_utils_1.TypedEventEmitter {
|
|
|
242
248
|
replayPromiseChain = replayPromiseChain.then(async () => controller.replay((ops) => this.emit("op", ReplayDocumentId, ops), messages));
|
|
243
249
|
const messages = result.value;
|
|
244
250
|
currentOp += messages.length;
|
|
251
|
+
// TODO Why are we non null asserting here
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
245
253
|
done = controller.isDoneFetch(currentOp, messages[messages.length - 1].timestamp);
|
|
246
254
|
} while (!done);
|
|
247
255
|
abortController.abort();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replayDocumentDeltaConnection.js","sourceRoot":"","sources":["../src/replayDocumentDeltaConnection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AAEjE,kEAA4D;AAE5D,0EAcqD;AAErD,+DAAyD;AAEzD,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,MAAa,sBAAuB,SAAQ,sCAAgB;IAM3D,gDAAgD;IAEhD;;;;;;OAMG;IACH,YACiB,UAAkB,EAClB,QAAgB,EAChB,UAAoB;QAEpC,KAAK,EAAE,CAAC;QAJQ,eAAU,GAAV,UAAU,CAAQ;QAClB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAU;QAb7B,kBAAa,GAAG,CAAC,CAAC;QAgBzB,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACzB,qFAAqF;YACrF,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QACnB,CAAC;IACF,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,eAAiC;QACzD,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,SAAwB,EAAE,KAAa;QAC/D,OAAO,EAAE,CAAC;IACX,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,OAAkB;QAC9C,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACxE,CAAC;IAE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C,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,oBAAoB;IAC5E,GAAG,EAAE,KAAK;CACV,AAV6B,CAU5B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { delay } from \"@fluidframework/core-utils/internal\";\nimport { ConnectionMode } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaConnectionEvents,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIClientConfiguration,\n\tIConnected,\n\tIDocumentMessage,\n\tISignalClient,\n\tITokenClaims,\n\tIVersion,\n\tScopeType,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport { ReplayController } from \"./replayController.js\";\n\nconst ReplayDocumentId = \"documentId\";\n\nexport class ReplayControllerStatic extends ReplayController {\n\tprivate static readonly DelayInterval = 50;\n\tprivate static readonly ReplayResolution = 15;\n\n\tprivate firstTimeStamp: number | undefined;\n\tprivate replayCurrent = 0;\n\t// Simulated delay interval for emitting the ops\n\n\t/**\n\t * Helper class\n\t *\n\t * @param replayFrom - First op to be played on socket.\n\t * @param replayTo - Last op number to be played on socket.\n\t * @param unitIsTime - True is user want to play ops that are within a replay resolution window.\n\t */\n\tpublic constructor(\n\t\tpublic readonly replayFrom: number,\n\t\tpublic readonly replayTo: number,\n\t\tpublic readonly unitIsTime?: boolean,\n\t) {\n\t\tsuper();\n\t\tif (unitIsTime !== true) {\n\t\t\t// There is no code in here to start with snapshot, thus we have to start with op #0.\n\t\t\tthis.replayTo = 0;\n\t\t}\n\t}\n\n\tpublic async initStorage(documentService: IDocumentService) {\n\t\treturn true;\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\treturn [];\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion) {\n\t\treturn version ? Promise.reject(new Error(\"Invalid operation\")) : null;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tthrow new Error(\"Invalid operation\");\n\t}\n\n\tpublic async getStartingOpSequence(): Promise<number> {\n\t\treturn 0;\n\t}\n\n\tpublic fetchTo(currentOp: number) {\n\t\tif (!(this.unitIsTime !== true && this.replayTo >= 0)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.replayTo;\n\t}\n\n\tpublic isDoneFetch(currentOp: number, lastTimeStamp?: number) {\n\t\tif (this.replayTo >= 0) {\n\t\t\tif (this.unitIsTime === true) {\n\t\t\t\treturn (\n\t\t\t\t\tlastTimeStamp !== undefined &&\n\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\tlastTimeStamp - this.firstTimeStamp >= this.replayTo\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn currentOp >= this.replayTo;\n\t\t}\n\t\treturn lastTimeStamp === undefined; // No more ops\n\t}\n\n\tpublic skipToIndex(fetchedOps: ISequencedDocumentMessage[]) {\n\t\tif (this.replayFrom <= 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (this.unitIsTime === true) {\n\t\t\tfor (let i = 0; i < fetchedOps.length; i += 1) {\n\t\t\t\tconst timeStamp = fetchedOps[i].timestamp;\n\t\t\t\tif (timeStamp !== undefined) {\n\t\t\t\t\tif (this.firstTimeStamp === undefined) {\n\t\t\t\t\t\tthis.firstTimeStamp = timeStamp;\n\t\t\t\t\t}\n\t\t\t\t\tif (timeStamp - this.firstTimeStamp >= this.replayFrom) {\n\t\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.replayFrom > this.replayCurrent) {\n\t\t\treturn this.replayFrom - this.replayCurrent;\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic async replay(\n\t\temitter: (op: ISequencedDocumentMessage[]) => void,\n\t\tfetchedOps: ISequencedDocumentMessage[],\n\t): Promise<void> {\n\t\tlet current = this.skipToIndex(fetchedOps);\n\n\t\treturn new Promise((resolve) => {\n\t\t\tconst replayNextOps = () => {\n\t\t\t\t// Emit the ops from replay to the end every \"deltainterval\" milliseconds\n\t\t\t\t// to simulate the socket stream\n\t\t\t\tconst currentOp = fetchedOps[current];\n\t\t\t\tconst playbackOps = [currentOp];\n\t\t\t\tlet nextInterval = ReplayControllerStatic.DelayInterval;\n\t\t\t\tcurrent += 1;\n\n\t\t\t\tif (this.unitIsTime === true) {\n\t\t\t\t\tconst currentTimeStamp = currentOp.timestamp;\n\t\t\t\t\tif (currentTimeStamp !== undefined) {\n\t\t\t\t\t\t// Emit more ops that is in the ReplayResolution window\n\n\t\t\t\t\t\twhile (current < fetchedOps.length) {\n\t\t\t\t\t\t\tconst op = fetchedOps[current];\n\t\t\t\t\t\t\tif (op.timestamp === undefined) {\n\t\t\t\t\t\t\t\t// Missing timestamp, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst timeDiff = op.timestamp - currentTimeStamp;\n\t\t\t\t\t\t\tif (timeDiff >= ReplayControllerStatic.ReplayResolution) {\n\t\t\t\t\t\t\t\t// Time exceeded the resolution window, break out the loop\n\t\t\t\t\t\t\t\t// and delay for the time difference.\n\t\t\t\t\t\t\t\tnextInterval = timeDiff;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (timeDiff < 0) {\n\t\t\t\t\t\t\t\t// Time have regressed, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// The op is within the ReplayResolution emit it now\n\t\t\t\t\t\t\tplaybackOps.push(op);\n\t\t\t\t\t\t\tcurrent += 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\t\t\tthis.replayTo >= 0 &&\n\t\t\t\t\t\t\tcurrentTimeStamp + nextInterval - this.firstTimeStamp > this.replayTo\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnextInterval = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tscheduleNext(nextInterval);\n\t\t\t\temitter(playbackOps);\n\t\t\t};\n\t\t\tconst scheduleNext = (nextInterval: number) => {\n\t\t\t\tif (nextInterval >= 0 && current < fetchedOps.length) {\n\t\t\t\t\tsetTimeout(replayNextOps, nextInterval);\n\t\t\t\t} else {\n\t\t\t\t\tthis.replayCurrent += current;\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\tscheduleNext(ReplayControllerStatic.DelayInterval);\n\t\t});\n\t}\n}\n\nexport class ReplayDocumentDeltaConnection\n\textends TypedEventEmitter<IDocumentDeltaConnectionEvents>\n\timplements IDocumentDeltaConnection, IDisposable\n{\n\t/**\n\t * Creates a new delta connection and mimics the delta connection to replay ops on it.\n\t * @param documentService - The document service to be used to get underlying endpoints.\n\t */\n\tpublic static create(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): IDocumentDeltaConnection {\n\t\tconst connection: IConnected = {\n\t\t\tclaims: ReplayDocumentDeltaConnection.claims,\n\t\t\tclientId: \"PseudoClientId\",\n\t\t\texisting: true,\n\t\t\tinitialMessages: [],\n\t\t\tinitialSignals: [],\n\t\t\tinitialClients: [],\n\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\tmode: \"read\",\n\t\t\tserviceConfiguration: {\n\t\t\t\tblockSize: 64436,\n\t\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\t},\n\t\t\tsupportedVersions: [ReplayDocumentDeltaConnection.replayProtocolVersion],\n\t\t\tversion: ReplayDocumentDeltaConnection.replayProtocolVersion,\n\t\t};\n\t\tconst deltaConnection = new ReplayDocumentDeltaConnection(connection);\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tdeltaConnection.fetchAndEmitOps(documentStorageService, controller);\n\n\t\treturn deltaConnection;\n\t}\n\n\tprivate static readonly replayProtocolVersion = \"^0.1.0\";\n\t// Since the replay service never actually sends messages the size below is arbitrary\n\tprivate static readonly ReplayMaxMessageSize = 16 * 1024;\n\n\tprivate static readonly claims: ITokenClaims = {\n\t\tdocumentId: ReplayDocumentId,\n\t\tscopes: [ScopeType.DocRead],\n\t\ttenantId: \"\",\n\t\tuser: {\n\t\t\tid: \"\",\n\t\t},\n\t\tiat: Math.round(new Date().getTime() / 1000),\n\t\texp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration\n\t\tver: \"1.0\",\n\t};\n\n\tpublic get clientId(): string {\n\t\treturn this.details.clientId;\n\t}\n\n\tpublic get mode(): ConnectionMode {\n\t\treturn this.details.mode;\n\t}\n\n\tpublic get claims(): ITokenClaims {\n\t\treturn this.details.claims;\n\t}\n\n\tpublic get existing(): boolean {\n\t\treturn this.details.existing;\n\t}\n\n\tpublic get version(): string {\n\t\treturn this.details.version;\n\t}\n\n\tpublic get initialMessages(): ISequencedDocumentMessage[] {\n\t\treturn this.details.initialMessages;\n\t}\n\n\tpublic get initialSignals(): ISignalMessage[] {\n\t\treturn this.details.initialSignals;\n\t}\n\n\tpublic get initialClients(): ISignalClient[] {\n\t\treturn this.details.initialClients;\n\t}\n\n\tpublic get serviceConfiguration(): IClientConfiguration {\n\t\treturn this.details.serviceConfiguration;\n\t}\n\n\tpublic readonly maxMessageSize = ReplayDocumentDeltaConnection.ReplayMaxMessageSize;\n\n\tconstructor(public details: IConnected) {\n\t\tsuper();\n\t}\n\n\tpublic submit(documentMessage: IDocumentMessage[]): void {\n\t\t// ReplayDocumentDeltaConnection.submit() can't be called - client never sees its own join on,\n\t\t// and thus can never move to sending ops.\n\t\tthrow new Error(\"ReplayDocumentDeltaConnection.submit() can't be called\");\n\t}\n\n\tpublic async submitSignal(message: any) {}\n\n\tprivate _disposed = false;\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\t/**\n\t * This gets the specified ops from the delta storage endpoint and replays them in the replayer.\n\t */\n\tprivate async fetchAndEmitOps(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): Promise<void> {\n\t\tlet done;\n\t\tlet replayPromiseChain = Promise.resolve();\n\n\t\tlet currentOp = await controller.getStartingOpSequence();\n\n\t\tdo {\n\t\t\tconst fetchTo = controller.fetchTo(currentOp);\n\n\t\t\tconst abortController = new AbortController();\n\t\t\tconst stream = documentStorageService.fetchMessages(\n\t\t\t\tcurrentOp + 1,\n\t\t\t\tfetchTo,\n\t\t\t\tabortController.signal,\n\t\t\t);\n\t\t\tdo {\n\t\t\t\tconst result = await stream.read();\n\n\t\t\t\tif (result.done) {\n\t\t\t\t\t// No more ops. But, they can show up later, either because document was just created,\n\t\t\t\t\t// or because another client keeps submitting new ops.\n\t\t\t\t\tdone = controller.isDoneFetch(currentOp, undefined);\n\t\t\t\t\tif (!done) {\n\t\t\t\t\t\tawait delay(2000);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\treplayPromiseChain = replayPromiseChain.then(async () =>\n\t\t\t\t\tcontroller.replay((ops) => this.emit(\"op\", ReplayDocumentId, ops), messages),\n\t\t\t\t);\n\n\t\t\t\tconst messages = result.value;\n\t\t\t\tcurrentOp += messages.length;\n\t\t\t\tdone = controller.isDoneFetch(currentOp, messages[messages.length - 1].timestamp);\n\t\t\t} while (!done);\n\n\t\t\tabortController.abort();\n\t\t} while (!done);\n\t\treturn replayPromiseChain;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"replayDocum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["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { delay } from \"@fluidframework/core-utils/internal\";\nimport { ConnectionMode } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaConnectionEvents,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIClientConfiguration,\n\tIConnected,\n\tIDocumentMessage,\n\tISignalClient,\n\tITokenClaims,\n\tIVersion,\n\tScopeType,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport { ReplayController } from \"./replayController.js\";\n\nconst ReplayDocumentId = \"documentId\";\n\nexport class ReplayControllerStatic extends ReplayController {\n\tprivate static readonly DelayInterval = 50;\n\tprivate static readonly ReplayResolution = 15;\n\n\tprivate firstTimeStamp: number | undefined;\n\tprivate replayCurrent = 0;\n\t// Simulated delay interval for emitting the ops\n\n\t/**\n\t * Helper class\n\t *\n\t * @param replayFrom - First op to be played on socket.\n\t * @param replayTo - Last op number to be played on socket.\n\t * @param unitIsTime - True is user want to play ops that are within a replay resolution window.\n\t */\n\tpublic constructor(\n\t\tpublic readonly replayFrom: number,\n\t\tpublic readonly replayTo: number,\n\t\tpublic readonly unitIsTime?: boolean,\n\t) {\n\t\tsuper();\n\t\tif (unitIsTime !== true) {\n\t\t\t// There is no code in here to start with snapshot, thus we have to start with op #0.\n\t\t\tthis.replayTo = 0;\n\t\t}\n\t}\n\n\tpublic async initStorage(documentService: IDocumentService) {\n\t\treturn true;\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\treturn [];\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion) {\n\t\treturn version ? Promise.reject(new Error(\"Invalid operation\")) : null;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tthrow new Error(\"Invalid operation\");\n\t}\n\n\tpublic async getStartingOpSequence(): Promise<number> {\n\t\treturn 0;\n\t}\n\n\tpublic fetchTo(currentOp: number) {\n\t\tif (!(this.unitIsTime !== true && this.replayTo >= 0)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.replayTo;\n\t}\n\n\tpublic isDoneFetch(currentOp: number, lastTimeStamp?: number) {\n\t\tif (this.replayTo >= 0) {\n\t\t\tif (this.unitIsTime === true) {\n\t\t\t\treturn (\n\t\t\t\t\tlastTimeStamp !== undefined &&\n\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\tlastTimeStamp - this.firstTimeStamp >= this.replayTo\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn currentOp >= this.replayTo;\n\t\t}\n\t\treturn lastTimeStamp === undefined; // No more ops\n\t}\n\n\tpublic skipToIndex(fetchedOps: ISequencedDocumentMessage[]) {\n\t\tif (this.replayFrom <= 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (this.unitIsTime === true) {\n\t\t\tfor (let i = 0; i < fetchedOps.length; i += 1) {\n\t\t\t\t// Non null asserting here because we are iterating over fetchedOps\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst timeStamp = fetchedOps[i]!.timestamp;\n\t\t\t\tif (timeStamp !== undefined) {\n\t\t\t\t\tif (this.firstTimeStamp === undefined) {\n\t\t\t\t\t\tthis.firstTimeStamp = timeStamp;\n\t\t\t\t\t}\n\t\t\t\t\tif (timeStamp - this.firstTimeStamp >= this.replayFrom) {\n\t\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.replayFrom > this.replayCurrent) {\n\t\t\treturn this.replayFrom - this.replayCurrent;\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic async replay(\n\t\temitter: (op: ISequencedDocumentMessage[]) => void,\n\t\tfetchedOps: ISequencedDocumentMessage[],\n\t): Promise<void> {\n\t\tlet current = this.skipToIndex(fetchedOps);\n\n\t\treturn new Promise((resolve) => {\n\t\t\tconst replayNextOps = () => {\n\t\t\t\t// Emit the ops from replay to the end every \"deltainterval\" milliseconds\n\t\t\t\t// to simulate the socket stream\n\t\t\t\t// TODO Why are we non null asserting here\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst currentOp = fetchedOps[current]!;\n\t\t\t\tconst playbackOps = [currentOp];\n\t\t\t\tlet nextInterval = ReplayControllerStatic.DelayInterval;\n\t\t\t\tcurrent += 1;\n\n\t\t\t\tif (this.unitIsTime === true) {\n\t\t\t\t\tconst currentTimeStamp = currentOp.timestamp;\n\t\t\t\t\tif (currentTimeStamp !== undefined) {\n\t\t\t\t\t\t// Emit more ops that is in the ReplayResolution window\n\n\t\t\t\t\t\twhile (current < fetchedOps.length) {\n\t\t\t\t\t\t\t// TODO Why are we non null asserting here\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\tconst op = fetchedOps[current]!;\n\t\t\t\t\t\t\tif (op.timestamp === undefined) {\n\t\t\t\t\t\t\t\t// Missing timestamp, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst timeDiff = op.timestamp - currentTimeStamp;\n\t\t\t\t\t\t\tif (timeDiff >= ReplayControllerStatic.ReplayResolution) {\n\t\t\t\t\t\t\t\t// Time exceeded the resolution window, break out the loop\n\t\t\t\t\t\t\t\t// and delay for the time difference.\n\t\t\t\t\t\t\t\tnextInterval = timeDiff;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (timeDiff < 0) {\n\t\t\t\t\t\t\t\t// Time have regressed, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// The op is within the ReplayResolution emit it now\n\t\t\t\t\t\t\tplaybackOps.push(op);\n\t\t\t\t\t\t\tcurrent += 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\t\t\tthis.replayTo >= 0 &&\n\t\t\t\t\t\t\tcurrentTimeStamp + nextInterval - this.firstTimeStamp > this.replayTo\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnextInterval = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tscheduleNext(nextInterval);\n\t\t\t\temitter(playbackOps);\n\t\t\t};\n\t\t\tconst scheduleNext = (nextInterval: number) => {\n\t\t\t\tif (nextInterval >= 0 && current < fetchedOps.length) {\n\t\t\t\t\tsetTimeout(replayNextOps, nextInterval);\n\t\t\t\t} else {\n\t\t\t\t\tthis.replayCurrent += current;\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\tscheduleNext(ReplayControllerStatic.DelayInterval);\n\t\t});\n\t}\n}\n\nexport class ReplayDocumentDeltaConnection\n\textends TypedEventEmitter<IDocumentDeltaConnectionEvents>\n\timplements IDocumentDeltaConnection, IDisposable\n{\n\t/**\n\t * Creates a new delta connection and mimics the delta connection to replay ops on it.\n\t * @param documentService - The document service to be used to get underlying endpoints.\n\t */\n\tpublic static create(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): IDocumentDeltaConnection {\n\t\tconst connection: IConnected = {\n\t\t\tclaims: ReplayDocumentDeltaConnection.claims,\n\t\t\tclientId: \"PseudoClientId\",\n\t\t\texisting: true,\n\t\t\tinitialMessages: [],\n\t\t\tinitialSignals: [],\n\t\t\tinitialClients: [],\n\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\tmode: \"read\",\n\t\t\tserviceConfiguration: {\n\t\t\t\tblockSize: 64436,\n\t\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\t},\n\t\t\tsupportedVersions: [ReplayDocumentDeltaConnection.replayProtocolVersion],\n\t\t\tversion: ReplayDocumentDeltaConnection.replayProtocolVersion,\n\t\t};\n\t\tconst deltaConnection = new ReplayDocumentDeltaConnection(connection);\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tdeltaConnection.fetchAndEmitOps(documentStorageService, controller);\n\n\t\treturn deltaConnection;\n\t}\n\n\tprivate static readonly replayProtocolVersion = \"^0.1.0\";\n\t// Since the replay service never actually sends messages the size below is arbitrary\n\tprivate static readonly ReplayMaxMessageSize = 16 * 1024;\n\n\tprivate static readonly claims: ITokenClaims = {\n\t\tdocumentId: ReplayDocumentId,\n\t\tscopes: [ScopeType.DocRead],\n\t\ttenantId: \"\",\n\t\tuser: {\n\t\t\tid: \"\",\n\t\t},\n\t\tiat: Math.round(new Date().getTime() / 1000),\n\t\texp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration\n\t\tver: \"1.0\",\n\t};\n\n\tpublic get clientId(): string {\n\t\treturn this.details.clientId;\n\t}\n\n\tpublic get mode(): ConnectionMode {\n\t\treturn this.details.mode;\n\t}\n\n\tpublic get claims(): ITokenClaims {\n\t\treturn this.details.claims;\n\t}\n\n\tpublic get existing(): boolean {\n\t\treturn this.details.existing;\n\t}\n\n\tpublic get version(): string {\n\t\treturn this.details.version;\n\t}\n\n\tpublic get initialMessages(): ISequencedDocumentMessage[] {\n\t\treturn this.details.initialMessages;\n\t}\n\n\tpublic get initialSignals(): ISignalMessage[] {\n\t\treturn this.details.initialSignals;\n\t}\n\n\tpublic get initialClients(): ISignalClient[] {\n\t\treturn this.details.initialClients;\n\t}\n\n\tpublic get serviceConfiguration(): IClientConfiguration {\n\t\treturn this.details.serviceConfiguration;\n\t}\n\n\tpublic readonly maxMessageSize = ReplayDocumentDeltaConnection.ReplayMaxMessageSize;\n\n\tconstructor(public details: IConnected) {\n\t\tsuper();\n\t}\n\n\tpublic submit(documentMessage: IDocumentMessage[]): void {\n\t\t// ReplayDocumentDeltaConnection.submit() can't be called - client never sees its own join on,\n\t\t// and thus can never move to sending ops.\n\t\tthrow new Error(\"ReplayDocumentDeltaConnection.submit() can't be called\");\n\t}\n\n\tpublic async submitSignal(message: any) {}\n\n\tprivate _disposed = false;\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\t/**\n\t * This gets the specified ops from the delta storage endpoint and replays them in the replayer.\n\t */\n\tprivate async fetchAndEmitOps(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): Promise<void> {\n\t\tlet done;\n\t\tlet replayPromiseChain = Promise.resolve();\n\n\t\tlet currentOp = await controller.getStartingOpSequence();\n\n\t\tdo {\n\t\t\tconst fetchTo = controller.fetchTo(currentOp);\n\n\t\t\tconst abortController = new AbortController();\n\t\t\tconst stream = documentStorageService.fetchMessages(\n\t\t\t\tcurrentOp + 1,\n\t\t\t\tfetchTo,\n\t\t\t\tabortController.signal,\n\t\t\t);\n\t\t\tdo {\n\t\t\t\tconst result = await stream.read();\n\n\t\t\t\tif (result.done) {\n\t\t\t\t\t// No more ops. But, they can show up later, either because document was just created,\n\t\t\t\t\t// or because another client keeps submitting new ops.\n\t\t\t\t\tdone = controller.isDoneFetch(currentOp, undefined);\n\t\t\t\t\tif (!done) {\n\t\t\t\t\t\tawait delay(2000);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\treplayPromiseChain = replayPromiseChain.then(async () =>\n\t\t\t\t\tcontroller.replay((ops) => this.emit(\"op\", ReplayDocumentId, ops), messages),\n\t\t\t\t);\n\n\t\t\t\tconst messages = result.value;\n\t\t\t\tcurrentOp += messages.length;\n\t\t\t\t// TODO Why are we non null asserting here\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tdone = controller.isDoneFetch(currentOp, messages[messages.length - 1]!.timestamp);\n\t\t\t} while (!done);\n\n\t\t\tabortController.abort();\n\t\t} while (!done);\n\t\treturn replayPromiseChain;\n\t}\n}\n"]}
|
package/internal.d.ts
CHANGED
package/lib/public.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replayDocumentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/replayDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EACN,wBAAwB,EACxB,8BAA8B,EAC9B,4BAA4B,EAC5B,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,QAAQ,EAER,yBAAyB,EACzB,cAAc,EACd,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,qBAAa,sBAAuB,SAAQ,gBAAgB;aAgB1C,UAAU,EAAE,MAAM;aAClB,QAAQ,EAAE,MAAM;aAChB,UAAU,CAAC;IAjB5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAM;IAC3C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAM;IAE9C,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,aAAa,CAAK;IAG1B;;;;;;OAMG;gBAEc,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,qBAAS;IASxB,WAAW,CAAC,eAAe,EAAE,gBAAgB;IAI7C,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,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c,EAAE,CAE5C;IAED,IAAW,cAAc,IAAI,aAAa,EAAE,CAE3C;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAEtD;IAED,SAAgB,cAAc,SAAsD;gBAEjE,OAAO,EAAE,UAAU;IAI/B,MAAM,CAAC,eAAe,EAAE,gBAAgB,EAAE,GAAG,IAAI;IAM3C,YAAY,CAAC,OAAO,EAAE,GAAG;IAEtC,OAAO,CAAC,SAAS,CAAS;IAC1B,IAAW,QAAQ,YAElB;IACM,OAAO;IAId;;OAEG;YACW,eAAe;CA6C7B"}
|
|
@@ -65,6 +65,8 @@ export class ReplayControllerStatic extends ReplayController {
|
|
|
65
65
|
}
|
|
66
66
|
if (this.unitIsTime === true) {
|
|
67
67
|
for (let i = 0; i < fetchedOps.length; i += 1) {
|
|
68
|
+
// Non null asserting here because we are iterating over fetchedOps
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
68
70
|
const timeStamp = fetchedOps[i].timestamp;
|
|
69
71
|
if (timeStamp !== undefined) {
|
|
70
72
|
if (this.firstTimeStamp === undefined) {
|
|
@@ -87,6 +89,8 @@ export class ReplayControllerStatic extends ReplayController {
|
|
|
87
89
|
const replayNextOps = () => {
|
|
88
90
|
// Emit the ops from replay to the end every "deltainterval" milliseconds
|
|
89
91
|
// to simulate the socket stream
|
|
92
|
+
// TODO Why are we non null asserting here
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
90
94
|
const currentOp = fetchedOps[current];
|
|
91
95
|
const playbackOps = [currentOp];
|
|
92
96
|
let nextInterval = ReplayControllerStatic.DelayInterval;
|
|
@@ -96,6 +100,8 @@ export class ReplayControllerStatic extends ReplayController {
|
|
|
96
100
|
if (currentTimeStamp !== undefined) {
|
|
97
101
|
// Emit more ops that is in the ReplayResolution window
|
|
98
102
|
while (current < fetchedOps.length) {
|
|
103
|
+
// TODO Why are we non null asserting here
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
99
105
|
const op = fetchedOps[current];
|
|
100
106
|
if (op.timestamp === undefined) {
|
|
101
107
|
// Missing timestamp, just delay the standard amount of time
|
|
@@ -238,6 +244,8 @@ export class ReplayDocumentDeltaConnection extends TypedEventEmitter {
|
|
|
238
244
|
replayPromiseChain = replayPromiseChain.then(async () => controller.replay((ops) => this.emit("op", ReplayDocumentId, ops), messages));
|
|
239
245
|
const messages = result.value;
|
|
240
246
|
currentOp += messages.length;
|
|
247
|
+
// TODO Why are we non null asserting here
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
241
249
|
done = controller.isDoneFetch(currentOp, messages[messages.length - 1].timestamp);
|
|
242
250
|
} while (!done);
|
|
243
251
|
abortController.abort();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replayDocumentDeltaConnection.js","sourceRoot":"","sources":["../src/replayDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAC;AAE5D,OAAO,EAWN,SAAS,GAGT,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,MAAM,OAAO,sBAAuB,SAAQ,gBAAgB;IAM3D,gDAAgD;IAEhD;;;;;;OAMG;IACH,YACiB,UAAkB,EAClB,QAAgB,EAChB,UAAoB;QAEpC,KAAK,EAAE,CAAC;QAJQ,eAAU,GAAV,UAAU,CAAQ;QAClB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAU;QAb7B,kBAAa,GAAG,CAAC,CAAC;QAgBzB,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACzB,qFAAqF;YACrF,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QACnB,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AAC7D,kDAAoB,GAAG,EAAE,GAAG,IAAI,AAAZ,CAAa;AAEjC,oCAAM,GAAiB;IAC9C,UAAU,EAAE,gBAAgB;IAC5B,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;IAC3B,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE;QACL,EAAE,EAAE,EAAE;KACN;IACD,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,oBAAoB;IAC5E,GAAG,EAAE,KAAK;CACV,AAV6B,CAU5B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { delay } from \"@fluidframework/core-utils/internal\";\nimport { ConnectionMode } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaConnectionEvents,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIClientConfiguration,\n\tIConnected,\n\tIDocumentMessage,\n\tISignalClient,\n\tITokenClaims,\n\tIVersion,\n\tScopeType,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport { ReplayController } from \"./replayController.js\";\n\nconst ReplayDocumentId = \"documentId\";\n\nexport class ReplayControllerStatic extends ReplayController {\n\tprivate static readonly DelayInterval = 50;\n\tprivate static readonly ReplayResolution = 15;\n\n\tprivate firstTimeStamp: number | undefined;\n\tprivate replayCurrent = 0;\n\t// Simulated delay interval for emitting the ops\n\n\t/**\n\t * Helper class\n\t *\n\t * @param replayFrom - First op to be played on socket.\n\t * @param replayTo - Last op number to be played on socket.\n\t * @param unitIsTime - True is user want to play ops that are within a replay resolution window.\n\t */\n\tpublic constructor(\n\t\tpublic readonly replayFrom: number,\n\t\tpublic readonly replayTo: number,\n\t\tpublic readonly unitIsTime?: boolean,\n\t) {\n\t\tsuper();\n\t\tif (unitIsTime !== true) {\n\t\t\t// There is no code in here to start with snapshot, thus we have to start with op #0.\n\t\t\tthis.replayTo = 0;\n\t\t}\n\t}\n\n\tpublic async initStorage(documentService: IDocumentService) {\n\t\treturn true;\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\treturn [];\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion) {\n\t\treturn version ? Promise.reject(new Error(\"Invalid operation\")) : null;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tthrow new Error(\"Invalid operation\");\n\t}\n\n\tpublic async getStartingOpSequence(): Promise<number> {\n\t\treturn 0;\n\t}\n\n\tpublic fetchTo(currentOp: number) {\n\t\tif (!(this.unitIsTime !== true && this.replayTo >= 0)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.replayTo;\n\t}\n\n\tpublic isDoneFetch(currentOp: number, lastTimeStamp?: number) {\n\t\tif (this.replayTo >= 0) {\n\t\t\tif (this.unitIsTime === true) {\n\t\t\t\treturn (\n\t\t\t\t\tlastTimeStamp !== undefined &&\n\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\tlastTimeStamp - this.firstTimeStamp >= this.replayTo\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn currentOp >= this.replayTo;\n\t\t}\n\t\treturn lastTimeStamp === undefined; // No more ops\n\t}\n\n\tpublic skipToIndex(fetchedOps: ISequencedDocumentMessage[]) {\n\t\tif (this.replayFrom <= 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (this.unitIsTime === true) {\n\t\t\tfor (let i = 0; i < fetchedOps.length; i += 1) {\n\t\t\t\tconst timeStamp = fetchedOps[i].timestamp;\n\t\t\t\tif (timeStamp !== undefined) {\n\t\t\t\t\tif (this.firstTimeStamp === undefined) {\n\t\t\t\t\t\tthis.firstTimeStamp = timeStamp;\n\t\t\t\t\t}\n\t\t\t\t\tif (timeStamp - this.firstTimeStamp >= this.replayFrom) {\n\t\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.replayFrom > this.replayCurrent) {\n\t\t\treturn this.replayFrom - this.replayCurrent;\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic async replay(\n\t\temitter: (op: ISequencedDocumentMessage[]) => void,\n\t\tfetchedOps: ISequencedDocumentMessage[],\n\t): Promise<void> {\n\t\tlet current = this.skipToIndex(fetchedOps);\n\n\t\treturn new Promise((resolve) => {\n\t\t\tconst replayNextOps = () => {\n\t\t\t\t// Emit the ops from replay to the end every \"deltainterval\" milliseconds\n\t\t\t\t// to simulate the socket stream\n\t\t\t\tconst currentOp = fetchedOps[current];\n\t\t\t\tconst playbackOps = [currentOp];\n\t\t\t\tlet nextInterval = ReplayControllerStatic.DelayInterval;\n\t\t\t\tcurrent += 1;\n\n\t\t\t\tif (this.unitIsTime === true) {\n\t\t\t\t\tconst currentTimeStamp = currentOp.timestamp;\n\t\t\t\t\tif (currentTimeStamp !== undefined) {\n\t\t\t\t\t\t// Emit more ops that is in the ReplayResolution window\n\n\t\t\t\t\t\twhile (current < fetchedOps.length) {\n\t\t\t\t\t\t\tconst op = fetchedOps[current];\n\t\t\t\t\t\t\tif (op.timestamp === undefined) {\n\t\t\t\t\t\t\t\t// Missing timestamp, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst timeDiff = op.timestamp - currentTimeStamp;\n\t\t\t\t\t\t\tif (timeDiff >= ReplayControllerStatic.ReplayResolution) {\n\t\t\t\t\t\t\t\t// Time exceeded the resolution window, break out the loop\n\t\t\t\t\t\t\t\t// and delay for the time difference.\n\t\t\t\t\t\t\t\tnextInterval = timeDiff;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (timeDiff < 0) {\n\t\t\t\t\t\t\t\t// Time have regressed, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// The op is within the ReplayResolution emit it now\n\t\t\t\t\t\t\tplaybackOps.push(op);\n\t\t\t\t\t\t\tcurrent += 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\t\t\tthis.replayTo >= 0 &&\n\t\t\t\t\t\t\tcurrentTimeStamp + nextInterval - this.firstTimeStamp > this.replayTo\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnextInterval = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tscheduleNext(nextInterval);\n\t\t\t\temitter(playbackOps);\n\t\t\t};\n\t\t\tconst scheduleNext = (nextInterval: number) => {\n\t\t\t\tif (nextInterval >= 0 && current < fetchedOps.length) {\n\t\t\t\t\tsetTimeout(replayNextOps, nextInterval);\n\t\t\t\t} else {\n\t\t\t\t\tthis.replayCurrent += current;\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\tscheduleNext(ReplayControllerStatic.DelayInterval);\n\t\t});\n\t}\n}\n\nexport class ReplayDocumentDeltaConnection\n\textends TypedEventEmitter<IDocumentDeltaConnectionEvents>\n\timplements IDocumentDeltaConnection, IDisposable\n{\n\t/**\n\t * Creates a new delta connection and mimics the delta connection to replay ops on it.\n\t * @param documentService - The document service to be used to get underlying endpoints.\n\t */\n\tpublic static create(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): IDocumentDeltaConnection {\n\t\tconst connection: IConnected = {\n\t\t\tclaims: ReplayDocumentDeltaConnection.claims,\n\t\t\tclientId: \"PseudoClientId\",\n\t\t\texisting: true,\n\t\t\tinitialMessages: [],\n\t\t\tinitialSignals: [],\n\t\t\tinitialClients: [],\n\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\tmode: \"read\",\n\t\t\tserviceConfiguration: {\n\t\t\t\tblockSize: 64436,\n\t\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\t},\n\t\t\tsupportedVersions: [ReplayDocumentDeltaConnection.replayProtocolVersion],\n\t\t\tversion: ReplayDocumentDeltaConnection.replayProtocolVersion,\n\t\t};\n\t\tconst deltaConnection = new ReplayDocumentDeltaConnection(connection);\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tdeltaConnection.fetchAndEmitOps(documentStorageService, controller);\n\n\t\treturn deltaConnection;\n\t}\n\n\tprivate static readonly replayProtocolVersion = \"^0.1.0\";\n\t// Since the replay service never actually sends messages the size below is arbitrary\n\tprivate static readonly ReplayMaxMessageSize = 16 * 1024;\n\n\tprivate static readonly claims: ITokenClaims = {\n\t\tdocumentId: ReplayDocumentId,\n\t\tscopes: [ScopeType.DocRead],\n\t\ttenantId: \"\",\n\t\tuser: {\n\t\t\tid: \"\",\n\t\t},\n\t\tiat: Math.round(new Date().getTime() / 1000),\n\t\texp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration\n\t\tver: \"1.0\",\n\t};\n\n\tpublic get clientId(): string {\n\t\treturn this.details.clientId;\n\t}\n\n\tpublic get mode(): ConnectionMode {\n\t\treturn this.details.mode;\n\t}\n\n\tpublic get claims(): ITokenClaims {\n\t\treturn this.details.claims;\n\t}\n\n\tpublic get existing(): boolean {\n\t\treturn this.details.existing;\n\t}\n\n\tpublic get version(): string {\n\t\treturn this.details.version;\n\t}\n\n\tpublic get initialMessages(): ISequencedDocumentMessage[] {\n\t\treturn this.details.initialMessages;\n\t}\n\n\tpublic get initialSignals(): ISignalMessage[] {\n\t\treturn this.details.initialSignals;\n\t}\n\n\tpublic get initialClients(): ISignalClient[] {\n\t\treturn this.details.initialClients;\n\t}\n\n\tpublic get serviceConfiguration(): IClientConfiguration {\n\t\treturn this.details.serviceConfiguration;\n\t}\n\n\tpublic readonly maxMessageSize = ReplayDocumentDeltaConnection.ReplayMaxMessageSize;\n\n\tconstructor(public details: IConnected) {\n\t\tsuper();\n\t}\n\n\tpublic submit(documentMessage: IDocumentMessage[]): void {\n\t\t// ReplayDocumentDeltaConnection.submit() can't be called - client never sees its own join on,\n\t\t// and thus can never move to sending ops.\n\t\tthrow new Error(\"ReplayDocumentDeltaConnection.submit() can't be called\");\n\t}\n\n\tpublic async submitSignal(message: any) {}\n\n\tprivate _disposed = false;\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\t/**\n\t * This gets the specified ops from the delta storage endpoint and replays them in the replayer.\n\t */\n\tprivate async fetchAndEmitOps(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): Promise<void> {\n\t\tlet done;\n\t\tlet replayPromiseChain = Promise.resolve();\n\n\t\tlet currentOp = await controller.getStartingOpSequence();\n\n\t\tdo {\n\t\t\tconst fetchTo = controller.fetchTo(currentOp);\n\n\t\t\tconst abortController = new AbortController();\n\t\t\tconst stream = documentStorageService.fetchMessages(\n\t\t\t\tcurrentOp + 1,\n\t\t\t\tfetchTo,\n\t\t\t\tabortController.signal,\n\t\t\t);\n\t\t\tdo {\n\t\t\t\tconst result = await stream.read();\n\n\t\t\t\tif (result.done) {\n\t\t\t\t\t// No more ops. But, they can show up later, either because document was just created,\n\t\t\t\t\t// or because another client keeps submitting new ops.\n\t\t\t\t\tdone = controller.isDoneFetch(currentOp, undefined);\n\t\t\t\t\tif (!done) {\n\t\t\t\t\t\tawait delay(2000);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\treplayPromiseChain = replayPromiseChain.then(async () =>\n\t\t\t\t\tcontroller.replay((ops) => this.emit(\"op\", ReplayDocumentId, ops), messages),\n\t\t\t\t);\n\n\t\t\t\tconst messages = result.value;\n\t\t\t\tcurrentOp += messages.length;\n\t\t\t\tdone = controller.isDoneFetch(currentOp, messages[messages.length - 1].timestamp);\n\t\t\t} while (!done);\n\n\t\t\tabortController.abort();\n\t\t} while (!done);\n\t\treturn replayPromiseChain;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"replayDocumentDeltaConnection.js","sourceRoot":"","sources":["../src/replayDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAC;AAE5D,OAAO,EAWN,SAAS,GAGT,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,MAAM,OAAO,sBAAuB,SAAQ,gBAAgB;IAM3D,gDAAgD;IAEhD;;;;;;OAMG;IACH,YACiB,UAAkB,EAClB,QAAgB,EAChB,UAAoB;QAEpC,KAAK,EAAE,CAAC;QAJQ,eAAU,GAAV,UAAU,CAAQ;QAClB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAU;QAb7B,kBAAa,GAAG,CAAC,CAAC;QAgBzB,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACzB,qFAAqF;YACrF,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QACnB,CAAC;IACF,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,eAAiC;QACzD,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,SAAwB,EAAE,KAAa;QAC/D,OAAO,EAAE,CAAC;IACX,CAAC;IAEM,KAAK,CAAC,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M,GAAiB;IAC9C,UAAU,EAAE,gBAAgB;IAC5B,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;IAC3B,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE;QACL,EAAE,EAAE,EAAE;KACN;IACD,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,oBAAoB;IAC5E,GAAG,EAAE,KAAK;CACV,AAV6B,CAU5B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { delay } from \"@fluidframework/core-utils/internal\";\nimport { ConnectionMode } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaConnectionEvents,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIClientConfiguration,\n\tIConnected,\n\tIDocumentMessage,\n\tISignalClient,\n\tITokenClaims,\n\tIVersion,\n\tScopeType,\n\tISequencedDocumentMessage,\n\tISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport { ReplayController } from \"./replayController.js\";\n\nconst ReplayDocumentId = \"documentId\";\n\nexport class ReplayControllerStatic extends ReplayController {\n\tprivate static readonly DelayInterval = 50;\n\tprivate static readonly ReplayResolution = 15;\n\n\tprivate firstTimeStamp: number | undefined;\n\tprivate replayCurrent = 0;\n\t// Simulated delay interval for emitting the ops\n\n\t/**\n\t * Helper class\n\t *\n\t * @param replayFrom - First op to be played on socket.\n\t * @param replayTo - Last op number to be played on socket.\n\t * @param unitIsTime - True is user want to play ops that are within a replay resolution window.\n\t */\n\tpublic constructor(\n\t\tpublic readonly replayFrom: number,\n\t\tpublic readonly replayTo: number,\n\t\tpublic readonly unitIsTime?: boolean,\n\t) {\n\t\tsuper();\n\t\tif (unitIsTime !== true) {\n\t\t\t// There is no code in here to start with snapshot, thus we have to start with op #0.\n\t\t\tthis.replayTo = 0;\n\t\t}\n\t}\n\n\tpublic async initStorage(documentService: IDocumentService) {\n\t\treturn true;\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\treturn [];\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion) {\n\t\treturn version ? Promise.reject(new Error(\"Invalid operation\")) : null;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tthrow new Error(\"Invalid operation\");\n\t}\n\n\tpublic async getStartingOpSequence(): Promise<number> {\n\t\treturn 0;\n\t}\n\n\tpublic fetchTo(currentOp: number) {\n\t\tif (!(this.unitIsTime !== true && this.replayTo >= 0)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.replayTo;\n\t}\n\n\tpublic isDoneFetch(currentOp: number, lastTimeStamp?: number) {\n\t\tif (this.replayTo >= 0) {\n\t\t\tif (this.unitIsTime === true) {\n\t\t\t\treturn (\n\t\t\t\t\tlastTimeStamp !== undefined &&\n\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\tlastTimeStamp - this.firstTimeStamp >= this.replayTo\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn currentOp >= this.replayTo;\n\t\t}\n\t\treturn lastTimeStamp === undefined; // No more ops\n\t}\n\n\tpublic skipToIndex(fetchedOps: ISequencedDocumentMessage[]) {\n\t\tif (this.replayFrom <= 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (this.unitIsTime === true) {\n\t\t\tfor (let i = 0; i < fetchedOps.length; i += 1) {\n\t\t\t\t// Non null asserting here because we are iterating over fetchedOps\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst timeStamp = fetchedOps[i]!.timestamp;\n\t\t\t\tif (timeStamp !== undefined) {\n\t\t\t\t\tif (this.firstTimeStamp === undefined) {\n\t\t\t\t\t\tthis.firstTimeStamp = timeStamp;\n\t\t\t\t\t}\n\t\t\t\t\tif (timeStamp - this.firstTimeStamp >= this.replayFrom) {\n\t\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.replayFrom > this.replayCurrent) {\n\t\t\treturn this.replayFrom - this.replayCurrent;\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic async replay(\n\t\temitter: (op: ISequencedDocumentMessage[]) => void,\n\t\tfetchedOps: ISequencedDocumentMessage[],\n\t): Promise<void> {\n\t\tlet current = this.skipToIndex(fetchedOps);\n\n\t\treturn new Promise((resolve) => {\n\t\t\tconst replayNextOps = () => {\n\t\t\t\t// Emit the ops from replay to the end every \"deltainterval\" milliseconds\n\t\t\t\t// to simulate the socket stream\n\t\t\t\t// TODO Why are we non null asserting here\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst currentOp = fetchedOps[current]!;\n\t\t\t\tconst playbackOps = [currentOp];\n\t\t\t\tlet nextInterval = ReplayControllerStatic.DelayInterval;\n\t\t\t\tcurrent += 1;\n\n\t\t\t\tif (this.unitIsTime === true) {\n\t\t\t\t\tconst currentTimeStamp = currentOp.timestamp;\n\t\t\t\t\tif (currentTimeStamp !== undefined) {\n\t\t\t\t\t\t// Emit more ops that is in the ReplayResolution window\n\n\t\t\t\t\t\twhile (current < fetchedOps.length) {\n\t\t\t\t\t\t\t// TODO Why are we non null asserting here\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\tconst op = fetchedOps[current]!;\n\t\t\t\t\t\t\tif (op.timestamp === undefined) {\n\t\t\t\t\t\t\t\t// Missing timestamp, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst timeDiff = op.timestamp - currentTimeStamp;\n\t\t\t\t\t\t\tif (timeDiff >= ReplayControllerStatic.ReplayResolution) {\n\t\t\t\t\t\t\t\t// Time exceeded the resolution window, break out the loop\n\t\t\t\t\t\t\t\t// and delay for the time difference.\n\t\t\t\t\t\t\t\tnextInterval = timeDiff;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (timeDiff < 0) {\n\t\t\t\t\t\t\t\t// Time have regressed, just delay the standard amount of time\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// The op is within the ReplayResolution emit it now\n\t\t\t\t\t\t\tplaybackOps.push(op);\n\t\t\t\t\t\t\tcurrent += 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis.firstTimeStamp !== undefined &&\n\t\t\t\t\t\t\tthis.replayTo >= 0 &&\n\t\t\t\t\t\t\tcurrentTimeStamp + nextInterval - this.firstTimeStamp > this.replayTo\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnextInterval = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tscheduleNext(nextInterval);\n\t\t\t\temitter(playbackOps);\n\t\t\t};\n\t\t\tconst scheduleNext = (nextInterval: number) => {\n\t\t\t\tif (nextInterval >= 0 && current < fetchedOps.length) {\n\t\t\t\t\tsetTimeout(replayNextOps, nextInterval);\n\t\t\t\t} else {\n\t\t\t\t\tthis.replayCurrent += current;\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\tscheduleNext(ReplayControllerStatic.DelayInterval);\n\t\t});\n\t}\n}\n\nexport class ReplayDocumentDeltaConnection\n\textends TypedEventEmitter<IDocumentDeltaConnectionEvents>\n\timplements IDocumentDeltaConnection, IDisposable\n{\n\t/**\n\t * Creates a new delta connection and mimics the delta connection to replay ops on it.\n\t * @param documentService - The document service to be used to get underlying endpoints.\n\t */\n\tpublic static create(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): IDocumentDeltaConnection {\n\t\tconst connection: IConnected = {\n\t\t\tclaims: ReplayDocumentDeltaConnection.claims,\n\t\t\tclientId: \"PseudoClientId\",\n\t\t\texisting: true,\n\t\t\tinitialMessages: [],\n\t\t\tinitialSignals: [],\n\t\t\tinitialClients: [],\n\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\tmode: \"read\",\n\t\t\tserviceConfiguration: {\n\t\t\t\tblockSize: 64436,\n\t\t\t\tmaxMessageSize: ReplayDocumentDeltaConnection.ReplayMaxMessageSize,\n\t\t\t},\n\t\t\tsupportedVersions: [ReplayDocumentDeltaConnection.replayProtocolVersion],\n\t\t\tversion: ReplayDocumentDeltaConnection.replayProtocolVersion,\n\t\t};\n\t\tconst deltaConnection = new ReplayDocumentDeltaConnection(connection);\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tdeltaConnection.fetchAndEmitOps(documentStorageService, controller);\n\n\t\treturn deltaConnection;\n\t}\n\n\tprivate static readonly replayProtocolVersion = \"^0.1.0\";\n\t// Since the replay service never actually sends messages the size below is arbitrary\n\tprivate static readonly ReplayMaxMessageSize = 16 * 1024;\n\n\tprivate static readonly claims: ITokenClaims = {\n\t\tdocumentId: ReplayDocumentId,\n\t\tscopes: [ScopeType.DocRead],\n\t\ttenantId: \"\",\n\t\tuser: {\n\t\t\tid: \"\",\n\t\t},\n\t\tiat: Math.round(new Date().getTime() / 1000),\n\t\texp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration\n\t\tver: \"1.0\",\n\t};\n\n\tpublic get clientId(): string {\n\t\treturn this.details.clientId;\n\t}\n\n\tpublic get mode(): ConnectionMode {\n\t\treturn this.details.mode;\n\t}\n\n\tpublic get claims(): ITokenClaims {\n\t\treturn this.details.claims;\n\t}\n\n\tpublic get existing(): boolean {\n\t\treturn this.details.existing;\n\t}\n\n\tpublic get version(): string {\n\t\treturn this.details.version;\n\t}\n\n\tpublic get initialMessages(): ISequencedDocumentMessage[] {\n\t\treturn this.details.initialMessages;\n\t}\n\n\tpublic get initialSignals(): ISignalMessage[] {\n\t\treturn this.details.initialSignals;\n\t}\n\n\tpublic get initialClients(): ISignalClient[] {\n\t\treturn this.details.initialClients;\n\t}\n\n\tpublic get serviceConfiguration(): IClientConfiguration {\n\t\treturn this.details.serviceConfiguration;\n\t}\n\n\tpublic readonly maxMessageSize = ReplayDocumentDeltaConnection.ReplayMaxMessageSize;\n\n\tconstructor(public details: IConnected) {\n\t\tsuper();\n\t}\n\n\tpublic submit(documentMessage: IDocumentMessage[]): void {\n\t\t// ReplayDocumentDeltaConnection.submit() can't be called - client never sees its own join on,\n\t\t// and thus can never move to sending ops.\n\t\tthrow new Error(\"ReplayDocumentDeltaConnection.submit() can't be called\");\n\t}\n\n\tpublic async submitSignal(message: any) {}\n\n\tprivate _disposed = false;\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\t/**\n\t * This gets the specified ops from the delta storage endpoint and replays them in the replayer.\n\t */\n\tprivate async fetchAndEmitOps(\n\t\tdocumentStorageService: IDocumentDeltaStorageService,\n\t\tcontroller: ReplayController,\n\t): Promise<void> {\n\t\tlet done;\n\t\tlet replayPromiseChain = Promise.resolve();\n\n\t\tlet currentOp = await controller.getStartingOpSequence();\n\n\t\tdo {\n\t\t\tconst fetchTo = controller.fetchTo(currentOp);\n\n\t\t\tconst abortController = new AbortController();\n\t\t\tconst stream = documentStorageService.fetchMessages(\n\t\t\t\tcurrentOp + 1,\n\t\t\t\tfetchTo,\n\t\t\t\tabortController.signal,\n\t\t\t);\n\t\t\tdo {\n\t\t\t\tconst result = await stream.read();\n\n\t\t\t\tif (result.done) {\n\t\t\t\t\t// No more ops. But, they can show up later, either because document was just created,\n\t\t\t\t\t// or because another client keeps submitting new ops.\n\t\t\t\t\tdone = controller.isDoneFetch(currentOp, undefined);\n\t\t\t\t\tif (!done) {\n\t\t\t\t\t\tawait delay(2000);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\treplayPromiseChain = replayPromiseChain.then(async () =>\n\t\t\t\t\tcontroller.replay((ops) => this.emit(\"op\", ReplayDocumentId, ops), messages),\n\t\t\t\t);\n\n\t\t\t\tconst messages = result.value;\n\t\t\t\tcurrentOp += messages.length;\n\t\t\t\t// TODO Why are we non null asserting here\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tdone = controller.isDoneFetch(currentOp, messages[messages.length - 1]!.timestamp);\n\t\t\t} while (!done);\n\n\t\t\tabortController.abort();\n\t\t} while (!done);\n\t\treturn replayPromiseChain;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/replay-driver",
|
|
3
|
-
"version": "2.1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Document replay version of Socket.IO implementation",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,21 +37,21 @@
|
|
|
37
37
|
"main": "lib/index.js",
|
|
38
38
|
"types": "lib/public.d.ts",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@fluid-internal/client-utils": "2.1.0
|
|
41
|
-
"@fluidframework/core-interfaces": "2.1.0
|
|
42
|
-
"@fluidframework/core-utils": "2.1.0
|
|
43
|
-
"@fluidframework/driver-definitions": "2.1.0
|
|
44
|
-
"@fluidframework/driver-utils": "2.1.0
|
|
45
|
-
"@fluidframework/telemetry-utils": "2.1.0
|
|
40
|
+
"@fluid-internal/client-utils": "~2.1.0",
|
|
41
|
+
"@fluidframework/core-interfaces": "~2.1.0",
|
|
42
|
+
"@fluidframework/core-utils": "~2.1.0",
|
|
43
|
+
"@fluidframework/driver-definitions": "~2.1.0",
|
|
44
|
+
"@fluidframework/driver-utils": "~2.1.0",
|
|
45
|
+
"@fluidframework/telemetry-utils": "~2.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
49
|
-
"@biomejs/biome": "
|
|
50
|
-
"@fluid-tools/build-cli": "^0.
|
|
49
|
+
"@biomejs/biome": "~1.8.3",
|
|
50
|
+
"@fluid-tools/build-cli": "^0.41.0",
|
|
51
51
|
"@fluidframework/build-common": "^2.0.3",
|
|
52
|
-
"@fluidframework/build-tools": "^0.
|
|
52
|
+
"@fluidframework/build-tools": "^0.41.0",
|
|
53
53
|
"@fluidframework/eslint-config-fluid": "^5.3.0",
|
|
54
|
-
"@fluidframework/replay-driver-previous": "npm:@fluidframework/replay-driver@2.0.0
|
|
54
|
+
"@fluidframework/replay-driver-previous": "npm:@fluidframework/replay-driver@2.0.0",
|
|
55
55
|
"@microsoft/api-extractor": "^7.45.1",
|
|
56
56
|
"@types/nock": "^9.3.0",
|
|
57
57
|
"@types/node": "^18.19.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"build:docs": "api-extractor run --local",
|
|
83
83
|
"build:esnext": "tsc --project ./tsconfig.json",
|
|
84
84
|
"check:are-the-types-wrong": "attw --pack .",
|
|
85
|
-
"check:biome": "biome check .
|
|
85
|
+
"check:biome": "biome check .",
|
|
86
86
|
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
87
87
|
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
88
88
|
"check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"eslint": "eslint --format stylish src",
|
|
95
95
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
96
96
|
"format": "npm run format:biome",
|
|
97
|
-
"format:biome": "biome check . --
|
|
97
|
+
"format:biome": "biome check . --write",
|
|
98
98
|
"format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
|
|
99
99
|
"lint": "fluid-build . --task lint",
|
|
100
100
|
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
|
@@ -101,7 +101,9 @@ export class ReplayControllerStatic extends ReplayController {
|
|
|
101
101
|
}
|
|
102
102
|
if (this.unitIsTime === true) {
|
|
103
103
|
for (let i = 0; i < fetchedOps.length; i += 1) {
|
|
104
|
-
|
|
104
|
+
// Non null asserting here because we are iterating over fetchedOps
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
106
|
+
const timeStamp = fetchedOps[i]!.timestamp;
|
|
105
107
|
if (timeStamp !== undefined) {
|
|
106
108
|
if (this.firstTimeStamp === undefined) {
|
|
107
109
|
this.firstTimeStamp = timeStamp;
|
|
@@ -127,7 +129,9 @@ export class ReplayControllerStatic extends ReplayController {
|
|
|
127
129
|
const replayNextOps = () => {
|
|
128
130
|
// Emit the ops from replay to the end every "deltainterval" milliseconds
|
|
129
131
|
// to simulate the socket stream
|
|
130
|
-
|
|
132
|
+
// TODO Why are we non null asserting here
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
134
|
+
const currentOp = fetchedOps[current]!;
|
|
131
135
|
const playbackOps = [currentOp];
|
|
132
136
|
let nextInterval = ReplayControllerStatic.DelayInterval;
|
|
133
137
|
current += 1;
|
|
@@ -138,7 +142,9 @@ export class ReplayControllerStatic extends ReplayController {
|
|
|
138
142
|
// Emit more ops that is in the ReplayResolution window
|
|
139
143
|
|
|
140
144
|
while (current < fetchedOps.length) {
|
|
141
|
-
|
|
145
|
+
// TODO Why are we non null asserting here
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
147
|
+
const op = fetchedOps[current]!;
|
|
142
148
|
if (op.timestamp === undefined) {
|
|
143
149
|
// Missing timestamp, just delay the standard amount of time
|
|
144
150
|
break;
|
|
@@ -333,7 +339,9 @@ export class ReplayDocumentDeltaConnection
|
|
|
333
339
|
|
|
334
340
|
const messages = result.value;
|
|
335
341
|
currentOp += messages.length;
|
|
336
|
-
|
|
342
|
+
// TODO Why are we non null asserting here
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
344
|
+
done = controller.isDoneFetch(currentOp, messages[messages.length - 1]!.timestamp);
|
|
337
345
|
} while (!done);
|
|
338
346
|
|
|
339
347
|
abortController.abort();
|