@fluidframework/local-driver 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

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.
Files changed (123) hide show
  1. package/.eslintrc.js +19 -22
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +127 -0
  4. package/README.md +38 -0
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +4 -0
  7. package/api-report/local-driver.api.md +129 -0
  8. package/dist/{auth.js → auth.cjs} +8 -6
  9. package/dist/auth.cjs.map +1 -0
  10. package/dist/auth.d.ts.map +1 -1
  11. package/dist/index.cjs +24 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.ts +7 -6
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/local-driver-alpha.d.ts +110 -0
  16. package/dist/local-driver-beta.d.ts +75 -0
  17. package/dist/local-driver-public.d.ts +75 -0
  18. package/dist/local-driver-untrimmed.d.ts +226 -0
  19. package/dist/localCreateDocument.cjs +28 -0
  20. package/dist/localCreateDocument.cjs.map +1 -0
  21. package/dist/localCreateDocument.d.ts +8 -0
  22. package/dist/localCreateDocument.d.ts.map +1 -0
  23. package/dist/{localDeltaStorageService.js → localDeltaStorageService.cjs} +3 -2
  24. package/dist/localDeltaStorageService.cjs.map +1 -0
  25. package/dist/localDeltaStorageService.d.ts +4 -3
  26. package/dist/localDeltaStorageService.d.ts.map +1 -1
  27. package/dist/{localDocumentDeltaConnection.js → localDocumentDeltaConnection.cjs} +9 -11
  28. package/dist/localDocumentDeltaConnection.cjs.map +1 -0
  29. package/dist/localDocumentDeltaConnection.d.ts +5 -4
  30. package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
  31. package/dist/{localDocumentService.js → localDocumentService.cjs} +15 -30
  32. package/dist/localDocumentService.cjs.map +1 -0
  33. package/dist/localDocumentService.d.ts +15 -11
  34. package/dist/localDocumentService.d.ts.map +1 -1
  35. package/dist/{localDocumentServiceFactory.js → localDocumentServiceFactory.cjs} +14 -31
  36. package/dist/localDocumentServiceFactory.cjs.map +1 -0
  37. package/dist/localDocumentServiceFactory.d.ts +3 -2
  38. package/dist/localDocumentServiceFactory.d.ts.map +1 -1
  39. package/dist/localDocumentStorageService.cjs +88 -0
  40. package/dist/localDocumentStorageService.cjs.map +1 -0
  41. package/dist/localDocumentStorageService.d.ts +30 -0
  42. package/dist/localDocumentStorageService.d.ts.map +1 -0
  43. package/dist/{localResolver.js → localResolver.cjs} +10 -6
  44. package/dist/localResolver.cjs.map +1 -0
  45. package/dist/localResolver.d.ts +5 -0
  46. package/dist/localResolver.d.ts.map +1 -1
  47. package/dist/{localSessionStorageDb.js → localSessionStorageDb.cjs} +26 -18
  48. package/dist/localSessionStorageDb.cjs.map +1 -0
  49. package/dist/localSessionStorageDb.d.ts +1 -1
  50. package/dist/localSessionStorageDb.d.ts.map +1 -1
  51. package/dist/tsdoc-metadata.json +11 -0
  52. package/lib/auth.d.mts +12 -0
  53. package/lib/auth.d.mts.map +1 -0
  54. package/lib/auth.mjs +40 -0
  55. package/lib/auth.mjs.map +1 -0
  56. package/lib/index.d.mts +12 -0
  57. package/lib/index.d.mts.map +1 -0
  58. package/lib/index.mjs +12 -0
  59. package/lib/index.mjs.map +1 -0
  60. package/lib/local-driver-alpha.d.mts +110 -0
  61. package/lib/local-driver-beta.d.mts +75 -0
  62. package/lib/local-driver-public.d.mts +75 -0
  63. package/lib/local-driver-untrimmed.d.mts +226 -0
  64. package/lib/localCreateDocument.d.mts +8 -0
  65. package/lib/localCreateDocument.d.mts.map +1 -0
  66. package/lib/localCreateDocument.mjs +24 -0
  67. package/lib/localCreateDocument.mjs.map +1 -0
  68. package/lib/localDeltaStorageService.d.mts +20 -0
  69. package/lib/localDeltaStorageService.d.mts.map +1 -0
  70. package/lib/localDeltaStorageService.mjs +32 -0
  71. package/lib/localDeltaStorageService.mjs.map +1 -0
  72. package/lib/localDocumentDeltaConnection.d.mts +48 -0
  73. package/lib/localDocumentDeltaConnection.d.mts.map +1 -0
  74. package/lib/localDocumentDeltaConnection.mjs +86 -0
  75. package/lib/localDocumentDeltaConnection.mjs.map +1 -0
  76. package/lib/localDocumentService.d.mts +56 -0
  77. package/lib/localDocumentService.d.mts.map +1 -0
  78. package/lib/localDocumentService.mjs +84 -0
  79. package/lib/localDocumentService.mjs.map +1 -0
  80. package/lib/localDocumentServiceFactory.d.mts +45 -0
  81. package/lib/localDocumentServiceFactory.d.mts.map +1 -0
  82. package/lib/localDocumentServiceFactory.mjs +80 -0
  83. package/lib/localDocumentServiceFactory.mjs.map +1 -0
  84. package/lib/localDocumentStorageService.d.mts +30 -0
  85. package/lib/localDocumentStorageService.d.mts.map +1 -0
  86. package/lib/localDocumentStorageService.mjs +84 -0
  87. package/lib/localDocumentStorageService.mjs.map +1 -0
  88. package/lib/localResolver.d.mts +31 -0
  89. package/lib/localResolver.d.mts.map +1 -0
  90. package/lib/localResolver.mjs +74 -0
  91. package/lib/localResolver.mjs.map +1 -0
  92. package/lib/localSessionStorageDb.d.mts +11 -0
  93. package/lib/localSessionStorageDb.d.mts.map +1 -0
  94. package/lib/localSessionStorageDb.mjs +292 -0
  95. package/lib/localSessionStorageDb.mjs.map +1 -0
  96. package/package.json +102 -59
  97. package/prettier.config.cjs +8 -0
  98. package/src/auth.ts +42 -33
  99. package/src/index.ts +7 -6
  100. package/src/localCreateDocument.ts +48 -0
  101. package/src/localDeltaStorageService.ts +28 -27
  102. package/src/localDocumentDeltaConnection.ts +91 -88
  103. package/src/localDocumentService.ts +117 -97
  104. package/src/localDocumentServiceFactory.ts +95 -123
  105. package/src/localDocumentStorageService.ts +131 -0
  106. package/src/localResolver.ts +57 -59
  107. package/src/localSessionStorageDb.ts +272 -265
  108. package/tsc-multi.test.json +4 -0
  109. package/tsconfig.json +11 -13
  110. package/dist/auth.js.map +0 -1
  111. package/dist/index.js +0 -23
  112. package/dist/index.js.map +0 -1
  113. package/dist/localDeltaStorageService.js.map +0 -1
  114. package/dist/localDocumentDeltaConnection.js.map +0 -1
  115. package/dist/localDocumentService.js.map +0 -1
  116. package/dist/localDocumentServiceFactory.js.map +0 -1
  117. package/dist/localResolver.js.map +0 -1
  118. package/dist/localSessionStorageDb.js.map +0 -1
  119. package/dist/packageVersion.d.ts +0 -9
  120. package/dist/packageVersion.d.ts.map +0 -1
  121. package/dist/packageVersion.js +0 -12
  122. package/dist/packageVersion.js.map +0 -1
  123. package/src/packageVersion.ts +0 -9
@@ -0,0 +1,48 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { IResolvedUrl } from "@fluidframework/driver-definitions";
7
+ import {
8
+ getDocAttributesFromProtocolSummary,
9
+ getQuorumValuesFromProtocolSummary,
10
+ isCombinedAppAndProtocolSummary,
11
+ } from "@fluidframework/driver-utils";
12
+ import { ISummaryTree } from "@fluidframework/protocol-definitions";
13
+ import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
14
+ import { defaultHash } from "@fluidframework/server-services-client";
15
+
16
+ export async function createDocument(
17
+ localDeltaConnectionServer,
18
+ resolvedUrl: IResolvedUrl,
19
+ summary: ISummaryTree,
20
+ ) {
21
+ const pathName = new URL(resolvedUrl.url).pathname;
22
+ const pathArr = pathName.split("/");
23
+ const tenantId = pathArr[pathArr.length - 2];
24
+ const id = pathArr[pathArr.length - 1];
25
+ const documentStorage = (localDeltaConnectionServer as LocalDeltaConnectionServer)
26
+ .documentStorage;
27
+ if (!isCombinedAppAndProtocolSummary(summary)) {
28
+ throw new Error("Protocol and App Summary required in the full summary");
29
+ }
30
+ const protocolSummary = summary.tree[".protocol"];
31
+ const appSummary = summary.tree[".app"];
32
+ const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
33
+ const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);
34
+ const sequenceNumber = documentAttributes.sequenceNumber;
35
+ await documentStorage.createDocument(
36
+ tenantId,
37
+ id,
38
+ appSummary,
39
+ sequenceNumber,
40
+ defaultHash,
41
+ resolvedUrl.endpoints.ordererUrl ?? "",
42
+ resolvedUrl.endpoints.storageUrl ?? "",
43
+ resolvedUrl.endpoints.deltaStorageUrl ?? "",
44
+ quorumValues,
45
+ false /* enableDiscovery */,
46
+ false /* isEphemeralContainer */,
47
+ );
48
+ }
@@ -3,42 +3,43 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import * as api from "@fluidframework/driver-definitions";
6
+ import { IDocumentDeltaStorageService, IStream } from "@fluidframework/driver-definitions";
7
7
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
8
8
  import { IDatabaseManager } from "@fluidframework/server-services-core";
9
9
  import { streamFromMessages } from "@fluidframework/driver-utils";
10
10
 
11
11
  /**
12
12
  * Provides access to the underlying delta storage on the server for local driver.
13
+ * @internal
13
14
  */
14
- export class LocalDeltaStorageService implements api.IDocumentDeltaStorageService {
15
- constructor(
16
- private readonly tenantId: string,
17
- private readonly id: string,
18
- private readonly databaseManager: IDatabaseManager) {
19
- }
15
+ export class LocalDeltaStorageService implements IDocumentDeltaStorageService {
16
+ constructor(
17
+ private readonly tenantId: string,
18
+ private readonly id: string,
19
+ private readonly databaseManager: IDatabaseManager,
20
+ ) {}
20
21
 
21
- public fetchMessages(
22
- from: number,
23
- to: number | undefined,
24
- abortSignal?: AbortSignal,
25
- cachedOnly?: boolean,
26
- ): api.IStream<ISequencedDocumentMessage[]> {
27
- return streamFromMessages(this.getCore(from, to));
28
- }
22
+ public fetchMessages(
23
+ from: number,
24
+ to: number | undefined,
25
+ abortSignal?: AbortSignal,
26
+ cachedOnly?: boolean,
27
+ ): IStream<ISequencedDocumentMessage[]> {
28
+ return streamFromMessages(this.getCore(from, to));
29
+ }
29
30
 
30
- private async getCore(from: number, to?: number) {
31
- const query = { documentId: this.id, tenantId: this.tenantId };
32
- query["operation.sequenceNumber"] = {};
33
- query["operation.sequenceNumber"].$gt = from - 1; // from is inclusive
31
+ private async getCore(from: number, to?: number) {
32
+ const query = { documentId: this.id, tenantId: this.tenantId };
33
+ query["operation.sequenceNumber"] = {};
34
+ query["operation.sequenceNumber"].$gt = from - 1; // from is inclusive
34
35
 
35
- // This looks like a bug. It used to work without setting $lt key. Now it does not
36
- // Need follow up
37
- query["operation.sequenceNumber"].$lt = to ?? Number.MAX_SAFE_INTEGER;
36
+ // This looks like a bug. It used to work without setting $lt key. Now it does not
37
+ // Need follow up
38
+ query["operation.sequenceNumber"].$lt = to ?? Number.MAX_SAFE_INTEGER;
38
39
 
39
- const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);
40
- const dbDeltas = await allDeltas.find(query, { "operation.sequenceNumber": 1 });
41
- const messages = dbDeltas.map((delta) => delta.operation);
42
- return messages;
43
- }
40
+ const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);
41
+ const dbDeltas = await allDeltas.find(query, { "operation.sequenceNumber": 1 });
42
+ const messages = dbDeltas.map((delta) => delta.operation);
43
+ return messages;
44
+ }
44
45
  }
@@ -3,112 +3,115 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { TelemetryNullLogger } from "@fluidframework/common-utils";
7
6
  import { DocumentDeltaConnection } from "@fluidframework/driver-base";
8
7
  import {
9
- IClient,
10
- IConnect,
11
- IDocumentMessage,
12
- NackErrorType,
8
+ IClient,
9
+ IConnect,
10
+ IDocumentMessage,
11
+ NackErrorType,
13
12
  } from "@fluidframework/protocol-definitions";
13
+ import { createChildLogger } from "@fluidframework/telemetry-utils";
14
14
  import { LocalWebSocketServer } from "@fluidframework/server-local-server";
15
- import * as core from "@fluidframework/server-services-core";
15
+ import { IWebSocketServer } from "@fluidframework/server-services-core";
16
16
  import type { Socket } from "socket.io-client";
17
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
17
18
 
18
19
  const testProtocolVersions = ["^0.3.0", "^0.2.0", "^0.1.0"];
19
20
 
20
21
  /**
21
22
  * Represents a connection to a stream of delta updates
23
+ * @internal
22
24
  */
23
25
  export class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
24
- /**
25
- * Create a LocalDocumentDeltaConnection
26
- * Handle initial messages, contents or signals if they were in queue
27
- *
28
- * @param tenantId - the ID of the tenant
29
- * @param id - document ID
30
- * @param token - authorization token for storage service
31
- * @param client - information about the client
32
- * @param webSocketServer - web socket server to create connection
33
- */
34
- public static async create(
35
- tenantId: string,
36
- id: string,
37
- token: string,
38
- client: IClient,
39
- webSocketServer: core.IWebSocketServer,
40
- timeoutMs = 60000,
41
- ): Promise<LocalDocumentDeltaConnection> {
42
- const socket = (webSocketServer as LocalWebSocketServer).createConnection();
26
+ /**
27
+ * Create a LocalDocumentDeltaConnection
28
+ * Handle initial messages, contents or signals if they were in queue
29
+ *
30
+ * @param tenantId - the ID of the tenant
31
+ * @param id - document ID
32
+ * @param token - authorization token for storage service
33
+ * @param client - information about the client
34
+ * @param webSocketServer - web socket server to create connection
35
+ */
36
+ public static async create(
37
+ tenantId: string,
38
+ id: string,
39
+ token: string,
40
+ client: IClient,
41
+ webSocketServer: IWebSocketServer,
42
+ timeoutMs = 60000,
43
+ logger?: ITelemetryBaseLogger,
44
+ ): Promise<LocalDocumentDeltaConnection> {
45
+ const socket = (webSocketServer as LocalWebSocketServer).createConnection();
43
46
 
44
- // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky
45
- // but should be fine because this delta connection is for local use only.
46
- const socketWithListener = socket as unknown as Socket;
47
+ // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky
48
+ // but should be fine because this delta connection is for local use only.
49
+ const socketWithListener = socket as unknown as Socket;
47
50
 
48
- const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id);
51
+ const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id, logger);
49
52
 
50
- const connectMessage: IConnect = {
51
- client,
52
- id,
53
- mode: client.mode,
54
- tenantId,
55
- token, // Token is going to indicate tenant level information, etc...
56
- versions: testProtocolVersions,
57
- };
58
- await deltaConnection.initialize(connectMessage, timeoutMs);
59
- return deltaConnection;
60
- }
53
+ const connectMessage: IConnect = {
54
+ client,
55
+ id,
56
+ mode: client.mode,
57
+ tenantId,
58
+ token, // Token is going to indicate tenant level information, etc...
59
+ versions: testProtocolVersions,
60
+ };
61
+ await deltaConnection.initialize(connectMessage, timeoutMs);
62
+ return deltaConnection;
63
+ }
61
64
 
62
- constructor(socket: Socket, documentId: string) {
63
- super(socket, documentId, new TelemetryNullLogger());
64
- }
65
+ constructor(socket: Socket, documentId: string, logger?: ITelemetryBaseLogger) {
66
+ super(socket, documentId, createChildLogger({ logger }));
67
+ }
65
68
 
66
- protected submitCore(type: string, messages: IDocumentMessage[]) {
67
- this.emitMessages(type, [messages]);
68
- }
69
+ /**
70
+ * Submits a new delta operation to the server
71
+ */
72
+ public submit(messages: IDocumentMessage[]): void {
73
+ // We use a promise resolve to force a turn break given message processing is sync
74
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
75
+ Promise.resolve().then(() => {
76
+ this.emitMessages("submitOp", [messages]);
77
+ });
78
+ }
69
79
 
70
- /**
71
- * Submits a new delta operation to the server
72
- */
73
- public submit(messages: IDocumentMessage[]): void {
74
- // We use a promise resolve to force a turn break given message processing is sync
75
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
76
- Promise.resolve().then(() => {
77
- this.submitCore("submitOp", messages);
78
- });
79
- }
80
+ /**
81
+ * Submits a new signal to the server
82
+ */
83
+ public submitSignal(message: any): void {
84
+ this.emitMessages("submitSignal", [[message]]);
85
+ }
80
86
 
81
- /**
82
- * Submits a new signal to the server
83
- */
84
- public submitSignal(message: any): void {
85
- this.submitCore("submitSignal", [message]);
86
- }
87
+ /**
88
+ * Send a "disconnect" message on the socket.
89
+ * @param disconnectReason - The reason of the disconnection.
90
+ */
91
+ public disconnectClient(disconnectReason: string) {
92
+ this.socket.emit("disconnect", disconnectReason);
93
+ }
87
94
 
88
- /**
89
- * Send a "disconnect" message on the socket.
90
- * @param disconnectReason - The reason of the disconnection.
91
- */
92
- public disconnectClient(disconnectReason: string) {
93
- this.socket.emit("disconnect", disconnectReason);
94
- }
95
-
96
- /**
97
- * * Sends a "nack" message on the socket.
98
- * @param code - An error code number that represents the error. It will be a valid HTTP error code.
99
- * @param type - Type of the Nack.
100
- * @param message - A message about the nack for debugging/logging/telemetry purposes.
101
- */
102
- public nackClient(code: number = 400, type: NackErrorType = NackErrorType.ThrottlingError, message: any) {
103
- const nackMessage = {
104
- operation: undefined,
105
- sequenceNumber: -1,
106
- content: {
107
- code,
108
- type,
109
- message,
110
- },
111
- };
112
- this.socket.emit("nack", "", [nackMessage]);
113
- }
95
+ /**
96
+ * * Sends a "nack" message on the socket.
97
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
98
+ * @param type - Type of the Nack.
99
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
100
+ */
101
+ public nackClient(
102
+ code: number = 400,
103
+ type: NackErrorType = NackErrorType.ThrottlingError,
104
+ message: any,
105
+ ) {
106
+ const nackMessage = {
107
+ operation: undefined,
108
+ sequenceNumber: -1,
109
+ content: {
110
+ code,
111
+ type,
112
+ message,
113
+ },
114
+ };
115
+ this.socket.emit("nack", "", [nackMessage]);
116
+ }
114
117
  }
@@ -3,100 +3,116 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import * as api from "@fluidframework/driver-definitions";
6
+ import {
7
+ IDocumentDeltaConnection,
8
+ IDocumentDeltaStorageService,
9
+ IDocumentService,
10
+ IDocumentServicePolicies,
11
+ IDocumentStorageService,
12
+ IResolvedUrl,
13
+ } from "@fluidframework/driver-definitions";
7
14
  import { IClient } from "@fluidframework/protocol-definitions";
8
- import * as socketStorage from "@fluidframework/routerlicious-driver";
15
+ import { ITokenProvider } from "@fluidframework/routerlicious-driver";
9
16
  import { GitManager } from "@fluidframework/server-services-client";
10
17
  import { TestHistorian } from "@fluidframework/server-test-utils";
11
18
  import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
12
- import { TelemetryNullLogger } from "@fluidframework/common-utils";
13
- import { LocalDeltaStorageService, LocalDocumentDeltaConnection } from ".";
19
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
20
+ import { LocalDocumentStorageService } from "./localDocumentStorageService";
21
+ import { LocalDocumentDeltaConnection } from "./localDocumentDeltaConnection";
22
+ import { LocalDeltaStorageService } from "./localDeltaStorageService";
14
23
 
15
24
  /**
16
25
  * Basic implementation of a document service for local use.
26
+ * @internal
17
27
  */
18
- export class LocalDocumentService implements api.IDocumentService {
19
- /**
20
- * @param localDeltaConnectionServer - delta connection server for ops
21
- * @param tokenProvider - token provider
22
- * @param tenantId - ID of tenant
23
- * @param documentId - ID of document
24
- */
25
- constructor(
26
- public readonly resolvedUrl: api.IResolvedUrl,
27
- private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
28
- private readonly tokenProvider: socketStorage.ITokenProvider,
29
- private readonly tenantId: string,
30
- private readonly documentId: string,
31
- private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
32
- public readonly policies: api.IDocumentServicePolicies = {},
33
- private readonly innerDocumentService?: api.IDocumentService,
34
- ) { }
28
+ export class LocalDocumentService implements IDocumentService {
29
+ /**
30
+ * @param localDeltaConnectionServer - delta connection server for ops
31
+ * @param tokenProvider - token provider
32
+ * @param tenantId - ID of tenant
33
+ * @param documentId - ID of document
34
+ */
35
+ constructor(
36
+ public readonly resolvedUrl: IResolvedUrl,
37
+ private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
38
+ private readonly tokenProvider: ITokenProvider,
39
+ private readonly tenantId: string,
40
+ private readonly documentId: string,
41
+ private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
42
+ public readonly policies: IDocumentServicePolicies = {},
43
+ private readonly innerDocumentService?: IDocumentService,
44
+ private readonly logger?: ITelemetryBaseLogger,
45
+ ) {}
35
46
 
36
- public dispose() { }
47
+ public dispose() {}
37
48
 
38
- /**
39
- * Creates and returns a document storage service for local use.
40
- */
41
- public async connectToStorage(): Promise<api.IDocumentStorageService> {
42
- return new socketStorage.DocumentStorageService(
43
- this.documentId,
44
- new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)),
45
- new TelemetryNullLogger(),
46
- { minBlobSize: 2048 }, // Test blob aggregation.
47
- undefined,
48
- undefined,
49
- undefined,
50
- new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)));
51
- }
49
+ /**
50
+ * Creates and returns a document storage service for local use.
51
+ */
52
+ public async connectToStorage(): Promise<IDocumentStorageService> {
53
+ return new LocalDocumentStorageService(
54
+ this.documentId,
55
+ new GitManager(
56
+ new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase),
57
+ ),
58
+ {
59
+ maximumCacheDurationMs: 432_000_000, // 5 days in ms. Not actually enforced but shouldn't matter for any local driver scenario
60
+ },
61
+ this.localDeltaConnectionServer,
62
+ this.resolvedUrl,
63
+ );
64
+ }
52
65
 
53
- /**
54
- * Creates and returns a delta storage service for local use.
55
- */
56
- public async connectToDeltaStorage(): Promise<api.IDocumentDeltaStorageService> {
57
- if (this.innerDocumentService) {
58
- return this.innerDocumentService.connectToDeltaStorage();
59
- }
60
- return new LocalDeltaStorageService(
61
- this.tenantId,
62
- this.documentId,
63
- this.localDeltaConnectionServer.databaseManager);
64
- }
66
+ /**
67
+ * Creates and returns a delta storage service for local use.
68
+ */
69
+ public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {
70
+ if (this.innerDocumentService) {
71
+ return this.innerDocumentService.connectToDeltaStorage();
72
+ }
73
+ return new LocalDeltaStorageService(
74
+ this.tenantId,
75
+ this.documentId,
76
+ this.localDeltaConnectionServer.databaseManager,
77
+ );
78
+ }
65
79
 
66
- /**
67
- * Creates and returns a delta stream for local use.
68
- * @param client - client data
69
- */
70
- public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {
71
- if (this.policies.storageOnly === true) {
72
- throw new Error("can't connect to delta stream in storage-only mode");
73
- }
74
- if (this.innerDocumentService) {
75
- return this.innerDocumentService.connectToDeltaStream(client);
76
- }
77
- const ordererToken = await this.tokenProvider.fetchOrdererToken(
78
- this.tenantId,
79
- this.documentId,
80
- );
81
- const documentDeltaConnection = await LocalDocumentDeltaConnection.create(
82
- this.tenantId,
83
- this.documentId,
84
- ordererToken.jwt,
85
- client,
86
- this.localDeltaConnectionServer.webSocketServer,
87
- );
88
- const clientId = documentDeltaConnection.clientId;
80
+ /**
81
+ * Creates and returns a delta stream for local use.
82
+ * @param client - client data
83
+ */
84
+ public async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {
85
+ if (this.policies.storageOnly === true) {
86
+ throw new Error("can't connect to delta stream in storage-only mode");
87
+ }
88
+ if (this.innerDocumentService) {
89
+ return this.innerDocumentService.connectToDeltaStream(client);
90
+ }
91
+ const ordererToken = await this.tokenProvider.fetchOrdererToken(
92
+ this.tenantId,
93
+ this.documentId,
94
+ );
95
+ const documentDeltaConnection = await LocalDocumentDeltaConnection.create(
96
+ this.tenantId,
97
+ this.documentId,
98
+ ordererToken.jwt,
99
+ client,
100
+ this.localDeltaConnectionServer.webSocketServer,
101
+ undefined,
102
+ this.logger,
103
+ );
104
+ const clientId = documentDeltaConnection.clientId;
89
105
 
90
- // Add this document service for the clientId in the document service factory.
91
- this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);
106
+ // Add this document service for the clientId in the document service factory.
107
+ this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);
92
108
 
93
- // Add a listener to remove this document service when the client is disconnected.
94
- documentDeltaConnection.on("disconnect", () => {
95
- this.documentDeltaConnectionsMap.delete(clientId);
96
- });
109
+ // Add a listener to remove this document service when the client is disconnected.
110
+ documentDeltaConnection.on("disconnect", () => {
111
+ this.documentDeltaConnectionsMap.delete(clientId);
112
+ });
97
113
 
98
- return documentDeltaConnection;
99
- }
114
+ return documentDeltaConnection;
115
+ }
100
116
  }
101
117
 
102
118
  /**
@@ -105,24 +121,28 @@ export class LocalDocumentService implements api.IDocumentService {
105
121
  * @param tokenProvider - token provider with a single token
106
122
  * @param tenantId - ID of tenant
107
123
  * @param documentId - ID of document
124
+ * @internal
108
125
  */
109
126
  export function createLocalDocumentService(
110
- resolvedUrl: api.IResolvedUrl,
111
- localDeltaConnectionServer: ILocalDeltaConnectionServer,
112
- tokenProvider: socketStorage.ITokenProvider,
113
- tenantId: string,
114
- documentId: string,
115
- documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
116
- policies?: api.IDocumentServicePolicies,
117
- innerDocumentService?: api.IDocumentService): api.IDocumentService {
118
- return new LocalDocumentService(
119
- resolvedUrl,
120
- localDeltaConnectionServer,
121
- tokenProvider,
122
- tenantId,
123
- documentId,
124
- documentDeltaConnectionsMap,
125
- policies,
126
- innerDocumentService,
127
- );
127
+ resolvedUrl: IResolvedUrl,
128
+ localDeltaConnectionServer: ILocalDeltaConnectionServer,
129
+ tokenProvider: ITokenProvider,
130
+ tenantId: string,
131
+ documentId: string,
132
+ documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
133
+ policies?: IDocumentServicePolicies,
134
+ innerDocumentService?: IDocumentService,
135
+ logger?: ITelemetryBaseLogger,
136
+ ): IDocumentService {
137
+ return new LocalDocumentService(
138
+ resolvedUrl,
139
+ localDeltaConnectionServer,
140
+ tokenProvider,
141
+ tenantId,
142
+ documentId,
143
+ documentDeltaConnectionsMap,
144
+ policies,
145
+ innerDocumentService,
146
+ logger,
147
+ );
128
148
  }