@fluidframework/file-driver 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

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.
@@ -4,17 +4,20 @@
4
4
  */
5
5
 
6
6
  import { IDisposable } from "@fluidframework/common-definitions";
7
- import { IDocumentDeltaConnection, IDocumentDeltaConnectionEvents } from "@fluidframework/driver-definitions";
8
7
  import {
9
- ConnectionMode,
10
- IClientConfiguration,
11
- IConnected,
12
- IDocumentMessage,
13
- ISequencedDocumentMessage,
14
- ISignalClient,
15
- ISignalMessage,
16
- ITokenClaims,
17
- ScopeType,
8
+ IDocumentDeltaConnection,
9
+ IDocumentDeltaConnectionEvents,
10
+ } from "@fluidframework/driver-definitions";
11
+ import {
12
+ ConnectionMode,
13
+ IClientConfiguration,
14
+ IConnected,
15
+ IDocumentMessage,
16
+ ISequencedDocumentMessage,
17
+ ISignalClient,
18
+ ISignalMessage,
19
+ ITokenClaims,
20
+ ScopeType,
18
21
  } from "@fluidframework/protocol-definitions";
19
22
  import { TypedEventEmitter } from "@fluidframework/common-utils";
20
23
  import { FileDeltaStorageService } from "./fileDeltaStorageService";
@@ -29,174 +32,186 @@ const fileProtocolVersion = "^0.1.0";
29
32
  const replayDocumentId = "replayDocId";
30
33
 
31
34
  const Claims: ITokenClaims = {
32
- documentId: replayDocumentId,
33
- scopes: [ScopeType.DocRead],
34
- tenantId: "",
35
- user: {
36
- id: "",
37
- },
38
- iat: Math.round(new Date().getTime() / 1000),
39
- exp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration
40
- ver: "1.0",
35
+ documentId: replayDocumentId,
36
+ scopes: [ScopeType.DocRead],
37
+ tenantId: "",
38
+ user: {
39
+ id: "",
40
+ },
41
+ iat: Math.round(new Date().getTime() / 1000),
42
+ exp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration
43
+ ver: "1.0",
41
44
  };
42
45
 
43
46
  /**
44
47
  * Replay service used to play ops using the delta connection.
45
48
  */
46
49
  export class Replayer {
47
- private currentReplayOp = 0;
48
-
49
- constructor(
50
- private readonly deltaConnection: ReplayFileDeltaConnection,
51
- private readonly documentStorageService: FileDeltaStorageService) {
52
- }
53
-
54
- public get currentReplayedOp() {
55
- return this.currentReplayOp;
56
- }
57
-
58
- public set currentReplayedOp(op: number) {
59
- this.currentReplayOp = op;
60
- }
61
-
62
- public get ops(): readonly Readonly<ISequencedDocumentMessage>[] {
63
- return this.documentStorageService.ops;
64
- }
65
-
66
- /**
67
- * Replay the ops upto a certain number.
68
- * @param replayTo - The last op number to be replayed.
69
- */
70
- public replay(replayTo: number) {
71
- let totalReplayedOps = 0;
72
- let done: boolean;
73
- do {
74
- const fetchToBatch = this.currentReplayOp + MaxBatchDeltas;
75
- const fetchTo = Math.min(fetchToBatch, replayTo);
76
-
77
- const fetchedOps = this.documentStorageService.getFromWebSocket(this.currentReplayOp, fetchTo);
78
-
79
- if (fetchedOps.length <= 0) {
80
- break;
81
- } else {
82
- this.emit(fetchedOps);
83
- totalReplayedOps += fetchedOps.length;
84
- this.currentReplayOp += fetchedOps.length;
85
- done = this.isDoneFetch(replayTo);
86
- }
87
- } while (!done);
88
- return totalReplayedOps;
89
- }
90
-
91
- private isDoneFetch(replayTo: number) {
92
- if (replayTo >= 0) {
93
- return this.currentReplayOp >= replayTo;
94
- }
95
- return false;
96
- }
97
-
98
- private emit(ops: ISequencedDocumentMessage[]) {
99
- // Note: do not clone messages here!
100
- // If Replay Tool fails due to one container patching message in-place,
101
- // then same thing can happen in shipping product due to
102
- // socket reuse in ODSP between main and summarizer containers.
103
- this.deltaConnection.emit("op", replayDocumentId, ops);
104
- }
50
+ private currentReplayOp = 0;
51
+
52
+ constructor(
53
+ private readonly deltaConnection: ReplayFileDeltaConnection,
54
+ private readonly documentStorageService: FileDeltaStorageService,
55
+ ) {}
56
+
57
+ public get currentReplayedOp() {
58
+ return this.currentReplayOp;
59
+ }
60
+
61
+ public set currentReplayedOp(op: number) {
62
+ this.currentReplayOp = op;
63
+ }
64
+
65
+ public get ops(): readonly Readonly<ISequencedDocumentMessage>[] {
66
+ return this.documentStorageService.ops;
67
+ }
68
+
69
+ /**
70
+ * Replay the ops upto a certain number.
71
+ * @param replayTo - The last op number to be replayed.
72
+ */
73
+ public replay(replayTo: number) {
74
+ let totalReplayedOps = 0;
75
+ let done: boolean;
76
+ do {
77
+ const fetchToBatch = this.currentReplayOp + MaxBatchDeltas;
78
+ const fetchTo = Math.min(fetchToBatch, replayTo);
79
+
80
+ const fetchedOps = this.documentStorageService.getFromWebSocket(
81
+ this.currentReplayOp,
82
+ fetchTo,
83
+ );
84
+
85
+ if (fetchedOps.length <= 0) {
86
+ break;
87
+ } else {
88
+ this.emit(fetchedOps);
89
+ totalReplayedOps += fetchedOps.length;
90
+ this.currentReplayOp += fetchedOps.length;
91
+ done = this.isDoneFetch(replayTo);
92
+ }
93
+ } while (!done);
94
+ return totalReplayedOps;
95
+ }
96
+
97
+ private isDoneFetch(replayTo: number) {
98
+ if (replayTo >= 0) {
99
+ return this.currentReplayOp >= replayTo;
100
+ }
101
+ return false;
102
+ }
103
+
104
+ private emit(ops: ISequencedDocumentMessage[]) {
105
+ // Note: do not clone messages here!
106
+ // If Replay Tool fails due to one container patching message in-place,
107
+ // then same thing can happen in shipping product due to
108
+ // socket reuse in ODSP between main and summarizer containers.
109
+ this.deltaConnection.emit("op", replayDocumentId, ops);
110
+ }
105
111
  }
106
112
 
107
113
  export class ReplayFileDeltaConnection
108
- extends TypedEventEmitter<IDocumentDeltaConnectionEvents>
109
- implements IDocumentDeltaConnection, IDisposable {
110
- /**
111
- * Mimic the delta connection to replay ops on it.
112
- *
113
- * @param documentDeltaStorageService - The delta storage service to get ops from.
114
- * @returns Document delta connection.
115
- */
116
- public static async create(
117
- documentDeltaStorageService: FileDeltaStorageService): Promise<ReplayFileDeltaConnection> {
118
- const mode: ConnectionMode = "read";
119
- const connection = {
120
- claims: Claims,
121
- clientId: "PseudoClientId",
122
- existing: true,
123
- initialMessages: [],
124
- initialSignals: [],
125
- initialClients: [],
126
- maxMessageSize: ReplayMaxMessageSize,
127
- mode,
128
- serviceConfiguration: {
129
- blockSize: 64436,
130
- maxMessageSize: ReplayMaxMessageSize,
131
- },
132
- supportedVersions: [fileProtocolVersion],
133
- user: null,
134
- version: fileProtocolVersion,
135
- };
136
- const deltaConnection = new ReplayFileDeltaConnection(connection, documentDeltaStorageService);
137
- return deltaConnection;
138
- }
139
-
140
- public readonly maxMessageSize = ReplayMaxMessageSize;
141
- private readonly replayer: Replayer;
142
-
143
- public constructor(public details: IConnected, documentDeltaStorageService: FileDeltaStorageService) {
144
- super();
145
- this.replayer = new Replayer(
146
- this,
147
- documentDeltaStorageService);
148
- }
149
-
150
- public getReplayer() {
151
- return this.replayer;
152
- }
153
-
154
- public get clientId(): string {
155
- return this.details.clientId;
156
- }
157
-
158
- public get mode(): ConnectionMode {
159
- return this.details.mode;
160
- }
161
-
162
- public get claims(): ITokenClaims {
163
- return this.details.claims;
164
- }
165
-
166
- public get existing(): boolean {
167
- return this.details.existing;
168
- }
169
-
170
- public get version(): string {
171
- return this.details.version;
172
- }
173
-
174
- public get initialMessages(): ISequencedDocumentMessage[] {
175
- return this.details.initialMessages;
176
- }
177
-
178
- public get initialSignals(): ISignalMessage[] {
179
- return this.details.initialSignals;
180
- }
181
-
182
- public get initialClients(): ISignalClient[] {
183
- return this.details.initialClients;
184
- }
185
-
186
- public get serviceConfiguration(): IClientConfiguration {
187
- return this.details.serviceConfiguration;
188
- }
189
-
190
- public submit(documentMessages: IDocumentMessage[]): void {
191
- // ReplayFileDeltaConnection.submit() can't be called - client never sees its own join on,
192
- // and thus can never move to sending ops.
193
- throw new Error("ReplayFileDeltaConnection.submit() can't be called");
194
- }
195
-
196
- public async submitSignal(message: any) {
197
- }
198
-
199
- private _disposed = false;
200
- public get disposed() { return this._disposed; }
201
- public dispose() { this._disposed = true; }
114
+ extends TypedEventEmitter<IDocumentDeltaConnectionEvents>
115
+ implements IDocumentDeltaConnection, IDisposable
116
+ {
117
+ /**
118
+ * Mimic the delta connection to replay ops on it.
119
+ *
120
+ * @param documentDeltaStorageService - The delta storage service to get ops from.
121
+ * @returns Document delta connection.
122
+ */
123
+ public static async create(
124
+ documentDeltaStorageService: FileDeltaStorageService,
125
+ ): Promise<ReplayFileDeltaConnection> {
126
+ const mode: ConnectionMode = "read";
127
+ const connection = {
128
+ claims: Claims,
129
+ clientId: "PseudoClientId",
130
+ existing: true,
131
+ initialMessages: [],
132
+ initialSignals: [],
133
+ initialClients: [],
134
+ maxMessageSize: ReplayMaxMessageSize,
135
+ mode,
136
+ serviceConfiguration: {
137
+ blockSize: 64436,
138
+ maxMessageSize: ReplayMaxMessageSize,
139
+ },
140
+ supportedVersions: [fileProtocolVersion],
141
+ user: null,
142
+ version: fileProtocolVersion,
143
+ };
144
+ const deltaConnection = new ReplayFileDeltaConnection(
145
+ connection,
146
+ documentDeltaStorageService,
147
+ );
148
+ return deltaConnection;
149
+ }
150
+
151
+ public readonly maxMessageSize = ReplayMaxMessageSize;
152
+ private readonly replayer: Replayer;
153
+
154
+ public constructor(
155
+ public details: IConnected,
156
+ documentDeltaStorageService: FileDeltaStorageService,
157
+ ) {
158
+ super();
159
+ this.replayer = new Replayer(this, documentDeltaStorageService);
160
+ }
161
+
162
+ public getReplayer() {
163
+ return this.replayer;
164
+ }
165
+
166
+ public get clientId(): string {
167
+ return this.details.clientId;
168
+ }
169
+
170
+ public get mode(): ConnectionMode {
171
+ return this.details.mode;
172
+ }
173
+
174
+ public get claims(): ITokenClaims {
175
+ return this.details.claims;
176
+ }
177
+
178
+ public get existing(): boolean {
179
+ return this.details.existing;
180
+ }
181
+
182
+ public get version(): string {
183
+ return this.details.version;
184
+ }
185
+
186
+ public get initialMessages(): ISequencedDocumentMessage[] {
187
+ return this.details.initialMessages;
188
+ }
189
+
190
+ public get initialSignals(): ISignalMessage[] {
191
+ return this.details.initialSignals;
192
+ }
193
+
194
+ public get initialClients(): ISignalClient[] {
195
+ return this.details.initialClients;
196
+ }
197
+
198
+ public get serviceConfiguration(): IClientConfiguration {
199
+ return this.details.serviceConfiguration;
200
+ }
201
+
202
+ public submit(documentMessages: IDocumentMessage[]): void {
203
+ // ReplayFileDeltaConnection.submit() can't be called - client never sees its own join on,
204
+ // and thus can never move to sending ops.
205
+ throw new Error("ReplayFileDeltaConnection.submit() can't be called");
206
+ }
207
+
208
+ public async submitSignal(message: any) {}
209
+
210
+ private _disposed = false;
211
+ public get disposed() {
212
+ return this._disposed;
213
+ }
214
+ public dispose() {
215
+ this._disposed = true;
216
+ }
202
217
  }
@@ -13,36 +13,35 @@ import { FileDeltaStorageService } from "./fileDeltaStorageService";
13
13
  */
14
14
  // eslint-disable-next-line import/namespace
15
15
  export class FileDocumentService implements api.IDocumentService {
16
- constructor(
17
- private readonly storage: api.IDocumentStorageService,
18
- private readonly deltaStorage: FileDeltaStorageService,
19
- private readonly deltaConnection: api.IDocumentDeltaConnection) {
20
- }
16
+ constructor(
17
+ private readonly storage: api.IDocumentStorageService,
18
+ private readonly deltaStorage: FileDeltaStorageService,
19
+ private readonly deltaConnection: api.IDocumentDeltaConnection,
20
+ ) {}
21
21
 
22
- public dispose() {}
22
+ public dispose() {}
23
23
 
24
- // TODO: Issue-2109 Implement detach container api or put appropriate comment.
25
- public get resolvedUrl(): api.IResolvedUrl {
26
- throw new Error("Not implemented");
27
- }
24
+ // TODO: Issue-2109 Implement detach container api or put appropriate comment.
25
+ public get resolvedUrl(): api.IResolvedUrl {
26
+ throw new Error("Not implemented");
27
+ }
28
28
 
29
- public async connectToStorage(): Promise<api.IDocumentStorageService> {
30
- return this.storage;
31
- }
29
+ public async connectToStorage(): Promise<api.IDocumentStorageService> {
30
+ return this.storage;
31
+ }
32
32
 
33
- public async connectToDeltaStorage(): Promise<api.IDocumentDeltaStorageService> {
34
- return this.deltaStorage;
35
- }
33
+ public async connectToDeltaStorage(): Promise<api.IDocumentDeltaStorageService> {
34
+ return this.deltaStorage;
35
+ }
36
36
 
37
- /**
38
- * Connects to a delta storage endpoint of provided documentService to get ops and then replaying
39
- * them so as to mimic a delta stream endpoint.
40
- *
41
- * @param client - Client that connects to socket.
42
- * @returns returns the delta stream service.
43
- */
44
- public async connectToDeltaStream(
45
- client: IClient): Promise<api.IDocumentDeltaConnection> {
46
- return this.deltaConnection;
47
- }
37
+ /**
38
+ * Connects to a delta storage endpoint of provided documentService to get ops and then replaying
39
+ * them so as to mimic a delta stream endpoint.
40
+ *
41
+ * @param client - Client that connects to socket.
42
+ * @returns returns the delta stream service.
43
+ */
44
+ public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {
45
+ return this.deltaConnection;
46
+ }
48
47
  }
@@ -4,11 +4,11 @@
4
4
  */
5
5
 
6
6
  import {
7
- IDocumentDeltaConnection,
8
- IDocumentService,
9
- IDocumentServiceFactory,
10
- IDocumentStorageService,
11
- IResolvedUrl,
7
+ IDocumentDeltaConnection,
8
+ IDocumentService,
9
+ IDocumentServiceFactory,
10
+ IDocumentStorageService,
11
+ IResolvedUrl,
12
12
  } from "@fluidframework/driver-definitions";
13
13
  import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
14
14
  import { ISummaryTree } from "@fluidframework/protocol-definitions";
@@ -20,34 +20,34 @@ import { FileDocumentService } from "./fileDocumentService";
20
20
  * use the local file storage as underlying storage.
21
21
  */
22
22
  export class FileDocumentServiceFactory implements IDocumentServiceFactory {
23
- public readonly protocolName = "fluid-file:";
24
- constructor(
25
- private readonly storage: IDocumentStorageService,
26
- private readonly deltaStorage: FileDeltaStorageService,
27
- private readonly deltaConnection: IDocumentDeltaConnection) {
28
- }
23
+ public readonly protocolName = "fluid-file:";
24
+ constructor(
25
+ private readonly storage: IDocumentStorageService,
26
+ private readonly deltaStorage: FileDeltaStorageService,
27
+ private readonly deltaConnection: IDocumentDeltaConnection,
28
+ ) {}
29
29
 
30
- /**
31
- * Creates the file document service if the path exists.
32
- *
33
- * @param fileURL - Path of directory containing ops/snapshots.
34
- * @returns file document service.
35
- */
36
- public async createDocumentService(
37
- fileURL: IResolvedUrl,
38
- logger?: ITelemetryBaseLogger,
39
- clientIsSummarizer?: boolean,
40
- ): Promise<IDocumentService> {
41
- return new FileDocumentService(this.storage, this.deltaStorage, this.deltaConnection);
42
- }
30
+ /**
31
+ * Creates the file document service if the path exists.
32
+ *
33
+ * @param fileURL - Path of directory containing ops/snapshots.
34
+ * @returns file document service.
35
+ */
36
+ public async createDocumentService(
37
+ fileURL: IResolvedUrl,
38
+ logger?: ITelemetryBaseLogger,
39
+ clientIsSummarizer?: boolean,
40
+ ): Promise<IDocumentService> {
41
+ return new FileDocumentService(this.storage, this.deltaStorage, this.deltaConnection);
42
+ }
43
43
 
44
- // TODO: Issue-2109 Implement detach container api or put appropriate comment.
45
- public async createContainer(
46
- createNewSummary: ISummaryTree,
47
- resolvedUrl: IResolvedUrl,
48
- logger?: ITelemetryBaseLogger,
49
- clientIsSummarizer?: boolean,
50
- ): Promise<IDocumentService> {
51
- throw new Error("Not implemented");
52
- }
44
+ // TODO: Issue-2109 Implement detach container api or put appropriate comment.
45
+ public async createContainer(
46
+ createNewSummary: ISummaryTree,
47
+ resolvedUrl: IResolvedUrl,
48
+ logger?: ITelemetryBaseLogger,
49
+ clientIsSummarizer?: boolean,
50
+ ): Promise<IDocumentService> {
51
+ throw new Error("Not implemented");
52
+ }
53
53
  }