@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,226 @@
1
+ import { DocumentDeltaConnection } from '@fluidframework/driver-base';
2
+ import { GitManager } from '@fluidframework/server-services-client';
3
+ import { IClient } from '@fluidframework/protocol-definitions';
4
+ import { ICreateBlobResponse } from '@fluidframework/protocol-definitions';
5
+ import { IDatabaseManager } from '@fluidframework/server-services-core';
6
+ import { IDb } from '@fluidframework/server-services-core';
7
+ import { IDocumentDeltaConnection } from '@fluidframework/driver-definitions';
8
+ import { IDocumentDeltaStorageService } from '@fluidframework/driver-definitions';
9
+ import { IDocumentMessage } from '@fluidframework/protocol-definitions';
10
+ import { IDocumentService } from '@fluidframework/driver-definitions';
11
+ import { IDocumentServiceFactory } from '@fluidframework/driver-definitions';
12
+ import { IDocumentServicePolicies } from '@fluidframework/driver-definitions';
13
+ import { IDocumentStorageService } from '@fluidframework/driver-definitions';
14
+ import { IDocumentStorageServicePolicies } from '@fluidframework/driver-definitions';
15
+ import { ILocalDeltaConnectionServer } from '@fluidframework/server-local-server';
16
+ import { IRequest } from '@fluidframework/core-interfaces';
17
+ import { IResolvedUrl } from '@fluidframework/driver-definitions';
18
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
19
+ import { ISnapshotTreeEx } from '@fluidframework/protocol-definitions';
20
+ import { IStream } from '@fluidframework/driver-definitions';
21
+ import { ISummaryContext } from '@fluidframework/driver-definitions';
22
+ import { ISummaryHandle } from '@fluidframework/protocol-definitions';
23
+ import { ISummaryTree } from '@fluidframework/protocol-definitions';
24
+ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
25
+ import { ITestDbFactory } from '@fluidframework/server-test-utils';
26
+ import { ITokenProvider } from '@fluidframework/routerlicious-driver';
27
+ import { IUrlResolver } from '@fluidframework/driver-definitions';
28
+ import { IVersion } from '@fluidframework/protocol-definitions';
29
+ import { IWebSocketServer } from '@fluidframework/server-services-core';
30
+ import { NackErrorType } from '@fluidframework/protocol-definitions';
31
+ import type { Socket } from 'socket.io-client';
32
+
33
+ /**
34
+ * Creates and returns a document service for local use.
35
+ * @param localDeltaConnectionServer - delta connection server for ops
36
+ * @param tokenProvider - token provider with a single token
37
+ * @param tenantId - ID of tenant
38
+ * @param documentId - ID of document
39
+ * @internal
40
+ */
41
+ export declare function createLocalDocumentService(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService, logger?: ITelemetryBaseLogger): IDocumentService;
42
+
43
+ /**
44
+ * @alpha
45
+ */
46
+ export declare function createLocalResolverCreateNewRequest(documentId: string): IRequest;
47
+
48
+ /**
49
+ * Provides access to the underlying delta storage on the server for local driver.
50
+ * @internal
51
+ */
52
+ export declare class LocalDeltaStorageService implements IDocumentDeltaStorageService {
53
+ private readonly tenantId;
54
+ private readonly id;
55
+ private readonly databaseManager;
56
+ constructor(tenantId: string, id: string, databaseManager: IDatabaseManager);
57
+ fetchMessages(from: number, to: number | undefined, abortSignal?: AbortSignal, cachedOnly?: boolean): IStream<ISequencedDocumentMessage[]>;
58
+ private getCore;
59
+ }
60
+
61
+ /**
62
+ * Represents a connection to a stream of delta updates
63
+ * @internal
64
+ */
65
+ export declare class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
66
+ /**
67
+ * Create a LocalDocumentDeltaConnection
68
+ * Handle initial messages, contents or signals if they were in queue
69
+ *
70
+ * @param tenantId - the ID of the tenant
71
+ * @param id - document ID
72
+ * @param token - authorization token for storage service
73
+ * @param client - information about the client
74
+ * @param webSocketServer - web socket server to create connection
75
+ */
76
+ static create(tenantId: string, id: string, token: string, client: IClient, webSocketServer: IWebSocketServer, timeoutMs?: number, logger?: ITelemetryBaseLogger): Promise<LocalDocumentDeltaConnection>;
77
+ constructor(socket: Socket, documentId: string, logger?: ITelemetryBaseLogger);
78
+ /**
79
+ * Submits a new delta operation to the server
80
+ */
81
+ submit(messages: IDocumentMessage[]): void;
82
+ /**
83
+ * Submits a new signal to the server
84
+ */
85
+ submitSignal(message: any): void;
86
+ /**
87
+ * Send a "disconnect" message on the socket.
88
+ * @param disconnectReason - The reason of the disconnection.
89
+ */
90
+ disconnectClient(disconnectReason: string): void;
91
+ /**
92
+ * * Sends a "nack" message on the socket.
93
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
94
+ * @param type - Type of the Nack.
95
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
96
+ */
97
+ nackClient(code: number | undefined, type: NackErrorType | undefined, message: any): void;
98
+ }
99
+
100
+ /**
101
+ * Basic implementation of a document service for local use.
102
+ * @internal
103
+ */
104
+ export declare class LocalDocumentService implements IDocumentService {
105
+ readonly resolvedUrl: IResolvedUrl;
106
+ private readonly localDeltaConnectionServer;
107
+ private readonly tokenProvider;
108
+ private readonly tenantId;
109
+ private readonly documentId;
110
+ private readonly documentDeltaConnectionsMap;
111
+ readonly policies: IDocumentServicePolicies;
112
+ private readonly innerDocumentService?;
113
+ private readonly logger?;
114
+ /**
115
+ * @param localDeltaConnectionServer - delta connection server for ops
116
+ * @param tokenProvider - token provider
117
+ * @param tenantId - ID of tenant
118
+ * @param documentId - ID of document
119
+ */
120
+ constructor(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService | undefined, logger?: ITelemetryBaseLogger | undefined);
121
+ dispose(): void;
122
+ /**
123
+ * Creates and returns a document storage service for local use.
124
+ */
125
+ connectToStorage(): Promise<IDocumentStorageService>;
126
+ /**
127
+ * Creates and returns a delta storage service for local use.
128
+ */
129
+ connectToDeltaStorage(): Promise<IDocumentDeltaStorageService>;
130
+ /**
131
+ * Creates and returns a delta stream for local use.
132
+ * @param client - client data
133
+ */
134
+ connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection>;
135
+ }
136
+
137
+ /**
138
+ * Implementation of document service factory for local use.
139
+ * @alpha
140
+ */
141
+ export declare class LocalDocumentServiceFactory implements IDocumentServiceFactory {
142
+ private readonly localDeltaConnectionServer;
143
+ private readonly policies?;
144
+ private readonly innerDocumentService?;
145
+ private readonly documentDeltaConnectionsMap;
146
+ /**
147
+ * @param localDeltaConnectionServer - delta connection server for ops
148
+ * @alpha
149
+ */
150
+ constructor(localDeltaConnectionServer: ILocalDeltaConnectionServer, policies?: IDocumentServicePolicies | undefined, innerDocumentService?: IDocumentService | undefined);
151
+ createContainer(createNewSummary: ISummaryTree | undefined, resolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
152
+ /**
153
+ * Creates and returns a document service for testing using the given resolved
154
+ * URL for the tenant ID, document ID, and token.
155
+ * @param resolvedUrl - resolved URL of document
156
+ */
157
+ createDocumentService(resolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
158
+ /**
159
+ * Gets the document delta connection for the clientId and asks it to disconnect the client.
160
+ * @param clientId - The ID of the client to be disconnected.
161
+ * @param disconnectReason - The reason of the disconnection.
162
+ */
163
+ disconnectClient(clientId: string, disconnectReason: string): void;
164
+ /**
165
+ * Gets the document delta connection for the clientId and asks it to nack the client.
166
+ * @param clientId - The ID of the client to be Nack'd.
167
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
168
+ * @param type - Type of the Nack.
169
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
170
+ */
171
+ nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any): void;
172
+ }
173
+
174
+ /**
175
+ * @internal
176
+ */
177
+ export declare class LocalDocumentStorageService implements IDocumentStorageService {
178
+ private readonly id;
179
+ private readonly manager;
180
+ readonly policies: IDocumentStorageServicePolicies;
181
+ private readonly localDeltaConnectionServer?;
182
+ private readonly resolvedUrl?;
183
+ protected readonly blobsShaCache: Map<string, string>;
184
+ private readonly summaryTreeUploadManager;
185
+ readonly repositoryUrl: string;
186
+ constructor(id: string, manager: GitManager, policies: IDocumentStorageServicePolicies, localDeltaConnectionServer?: ILocalDeltaConnectionServer | undefined, resolvedUrl?: IResolvedUrl | undefined);
187
+ getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
188
+ getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null>;
189
+ readBlob(blobId: string): Promise<ArrayBufferLike>;
190
+ uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
191
+ createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
192
+ downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree>;
193
+ private getPreviousFullSnapshot;
194
+ }
195
+
196
+ /**
197
+ * Resolves URLs by providing fake URLs which succeed with the other
198
+ * related local classes.
199
+ * @alpha
200
+ */
201
+ export declare class LocalResolver implements IUrlResolver {
202
+ private readonly tenantId;
203
+ private readonly tokenKey;
204
+ constructor();
205
+ /**
206
+ * Resolves URL requests by providing fake URLs with an actually generated
207
+ * token from constant test strings. The root of the URL is fake, but the
208
+ * remaining relative URL can still be parsed.
209
+ * @param request - request to handle
210
+ * @alpha
211
+ */
212
+ resolve(request: IRequest): Promise<IResolvedUrl>;
213
+ getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string>;
214
+ createCreateNewRequest(documentId: string): IRequest;
215
+ }
216
+
217
+ /**
218
+ * A database factory for testing that stores data in the browsers session storage
219
+ * @internal
220
+ */
221
+ export declare class LocalSessionStorageDbFactory implements ITestDbFactory {
222
+ readonly testDatabase: IDb;
223
+ connect(): Promise<IDb>;
224
+ }
225
+
226
+ export { }
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IResolvedUrl } from "@fluidframework/driver-definitions";
6
+ import { ISummaryTree } from "@fluidframework/protocol-definitions";
7
+ export declare function createDocument(localDeltaConnectionServer: any, resolvedUrl: IResolvedUrl, summary: ISummaryTree): Promise<void>;
8
+ //# sourceMappingURL=localCreateDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localCreateDocument.d.ts","sourceRoot":"","sources":["../src/localCreateDocument.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,YAAY,EAAE,MAAM,oCAAoC;OAM1D,EAAE,YAAY,EAAE,MAAM,sCAAsC;AAInE,wBAAsB,cAAc,CACnC,0BAA0B,KAAA,EAC1B,WAAW,EAAE,YAAY,EACzB,OAAO,EAAE,YAAY,iBA6BrB"}
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { getDocAttributesFromProtocolSummary, getQuorumValuesFromProtocolSummary, isCombinedAppAndProtocolSummary, } from "@fluidframework/driver-utils";
6
+ import { defaultHash } from "@fluidframework/server-services-client";
7
+ export async function createDocument(localDeltaConnectionServer, resolvedUrl, summary) {
8
+ const pathName = new URL(resolvedUrl.url).pathname;
9
+ const pathArr = pathName.split("/");
10
+ const tenantId = pathArr[pathArr.length - 2];
11
+ const id = pathArr[pathArr.length - 1];
12
+ const documentStorage = localDeltaConnectionServer
13
+ .documentStorage;
14
+ if (!isCombinedAppAndProtocolSummary(summary)) {
15
+ throw new Error("Protocol and App Summary required in the full summary");
16
+ }
17
+ const protocolSummary = summary.tree[".protocol"];
18
+ const appSummary = summary.tree[".app"];
19
+ const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
20
+ const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);
21
+ const sequenceNumber = documentAttributes.sequenceNumber;
22
+ await documentStorage.createDocument(tenantId, id, appSummary, sequenceNumber, defaultHash, resolvedUrl.endpoints.ordererUrl ?? "", resolvedUrl.endpoints.storageUrl ?? "", resolvedUrl.endpoints.deltaStorageUrl ?? "", quorumValues, false /* enableDiscovery */, false /* isEphemeralContainer */);
23
+ }
24
+ //# sourceMappingURL=localCreateDocument.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localCreateDocument.mjs","sourceRoot":"","sources":["../src/localCreateDocument.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAGI,EACN,mCAAmC,EACnC,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,8BAA8B;OAG9B,EAAE,WAAW,EAAE,MAAM,wCAAwC;AAEpE,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,0BAA0B,EAC1B,WAAyB,EACzB,OAAqB;IAErB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACnD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvC,MAAM,eAAe,GAAI,0BAAyD;SAChF,eAAe,CAAC;IAClB,IAAI,CAAC,+BAA+B,CAAC,OAAO,CAAC,EAAE;QAC9C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;KACzE;IACD,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC,eAAe,CAAC,CAAC;IAChF,MAAM,YAAY,GAAG,kCAAkC,CAAC,eAAe,CAAC,CAAC;IACzE,MAAM,cAAc,GAAG,kBAAkB,CAAC,cAAc,CAAC;IACzD,MAAM,eAAe,CAAC,cAAc,CACnC,QAAQ,EACR,EAAE,EACF,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,CAAC,SAAS,CAAC,UAAU,IAAI,EAAE,EACtC,WAAW,CAAC,SAAS,CAAC,UAAU,IAAI,EAAE,EACtC,WAAW,CAAC,SAAS,CAAC,eAAe,IAAI,EAAE,EAC3C,YAAY,EACZ,KAAK,CAAC,qBAAqB,EAC3B,KAAK,CAAC,0BAA0B,CAChC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport {\n\tgetDocAttributesFromProtocolSummary,\n\tgetQuorumValuesFromProtocolSummary,\n\tisCombinedAppAndProtocolSummary,\n} from \"@fluidframework/driver-utils\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport { LocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport { defaultHash } from \"@fluidframework/server-services-client\";\n\nexport async function createDocument(\n\tlocalDeltaConnectionServer,\n\tresolvedUrl: IResolvedUrl,\n\tsummary: ISummaryTree,\n) {\n\tconst pathName = new URL(resolvedUrl.url).pathname;\n\tconst pathArr = pathName.split(\"/\");\n\tconst tenantId = pathArr[pathArr.length - 2];\n\tconst id = pathArr[pathArr.length - 1];\n\tconst documentStorage = (localDeltaConnectionServer as LocalDeltaConnectionServer)\n\t\t.documentStorage;\n\tif (!isCombinedAppAndProtocolSummary(summary)) {\n\t\tthrow new Error(\"Protocol and App Summary required in the full summary\");\n\t}\n\tconst protocolSummary = summary.tree[\".protocol\"];\n\tconst appSummary = summary.tree[\".app\"];\n\tconst documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n\tconst quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);\n\tconst sequenceNumber = documentAttributes.sequenceNumber;\n\tawait documentStorage.createDocument(\n\t\ttenantId,\n\t\tid,\n\t\tappSummary,\n\t\tsequenceNumber,\n\t\tdefaultHash,\n\t\tresolvedUrl.endpoints.ordererUrl ?? \"\",\n\t\tresolvedUrl.endpoints.storageUrl ?? \"\",\n\t\tresolvedUrl.endpoints.deltaStorageUrl ?? \"\",\n\t\tquorumValues,\n\t\tfalse /* enableDiscovery */,\n\t\tfalse /* isEphemeralContainer */,\n\t);\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentDeltaStorageService, IStream } from "@fluidframework/driver-definitions";
6
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
+ import { IDatabaseManager } from "@fluidframework/server-services-core";
8
+ /**
9
+ * Provides access to the underlying delta storage on the server for local driver.
10
+ * @internal
11
+ */
12
+ export declare class LocalDeltaStorageService implements IDocumentDeltaStorageService {
13
+ private readonly tenantId;
14
+ private readonly id;
15
+ private readonly databaseManager;
16
+ constructor(tenantId: string, id: string, databaseManager: IDatabaseManager);
17
+ fetchMessages(from: number, to: number | undefined, abortSignal?: AbortSignal, cachedOnly?: boolean): IStream<ISequencedDocumentMessage[]>;
18
+ private getCore;
19
+ }
20
+ //# sourceMappingURL=localDeltaStorageService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,4BAA4B,EAAE,OAAO,EAAE,MAAM,oCAAoC;OACnF,EAAE,yBAAyB,EAAE,MAAM,sCAAsC;OACzE,EAAE,gBAAgB,EAAE,MAAM,sCAAsC;AAGvE;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,4BAA4B;IAE3E,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAFf,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,eAAe,EAAE,gBAAgB;IAG5C,aAAa,CACnB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,EAAE,CAAC;YAIzB,OAAO;CAcrB"}
@@ -0,0 +1,32 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { streamFromMessages } from "@fluidframework/driver-utils";
6
+ /**
7
+ * Provides access to the underlying delta storage on the server for local driver.
8
+ * @internal
9
+ */
10
+ export class LocalDeltaStorageService {
11
+ constructor(tenantId, id, databaseManager) {
12
+ this.tenantId = tenantId;
13
+ this.id = id;
14
+ this.databaseManager = databaseManager;
15
+ }
16
+ fetchMessages(from, to, abortSignal, cachedOnly) {
17
+ return streamFromMessages(this.getCore(from, to));
18
+ }
19
+ async getCore(from, to) {
20
+ const query = { documentId: this.id, tenantId: this.tenantId };
21
+ query["operation.sequenceNumber"] = {};
22
+ query["operation.sequenceNumber"].$gt = from - 1; // from is inclusive
23
+ // This looks like a bug. It used to work without setting $lt key. Now it does not
24
+ // Need follow up
25
+ query["operation.sequenceNumber"].$lt = to ?? Number.MAX_SAFE_INTEGER;
26
+ const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);
27
+ const dbDeltas = await allDeltas.find(query, { "operation.sequenceNumber": 1 });
28
+ const messages = dbDeltas.map((delta) => delta.operation);
29
+ return messages;
30
+ }
31
+ }
32
+ //# sourceMappingURL=localDeltaStorageService.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localDeltaStorageService.mjs","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAKI,EAAE,kBAAkB,EAAE,MAAM,8BAA8B;AAEjE;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IACpC,YACkB,QAAgB,EAChB,EAAU,EACV,eAAiC;QAFjC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,OAAE,GAAF,EAAE,CAAQ;QACV,oBAAe,GAAf,eAAe,CAAkB;IAChD,CAAC;IAEG,aAAa,CACnB,IAAY,EACZ,EAAsB,EACtB,WAAyB,EACzB,UAAoB;QAEpB,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IACnD,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,EAAW;QAC9C,MAAM,KAAK,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC/D,KAAK,CAAC,0BAA0B,CAAC,GAAG,EAAE,CAAC;QACvC,KAAK,CAAC,0BAA0B,CAAC,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,oBAAoB;QAEtE,kFAAkF;QAClF,iBAAiB;QACjB,KAAK,CAAC,0BAA0B,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,MAAM,CAAC,gBAAgB,CAAC;QAEtE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACxF,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,0BAA0B,EAAE,CAAC,EAAE,CAAC,CAAC;QAChF,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC1D,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDocumentDeltaStorageService, IStream } from \"@fluidframework/driver-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { IDatabaseManager } from \"@fluidframework/server-services-core\";\nimport { streamFromMessages } from \"@fluidframework/driver-utils\";\n\n/**\n * Provides access to the underlying delta storage on the server for local driver.\n * @internal\n */\nexport class LocalDeltaStorageService implements IDocumentDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly id: string,\n\t\tprivate readonly databaseManager: IDatabaseManager,\n\t) {}\n\n\tpublic fetchMessages(\n\t\tfrom: number,\n\t\tto: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t): IStream<ISequencedDocumentMessage[]> {\n\t\treturn streamFromMessages(this.getCore(from, to));\n\t}\n\n\tprivate async getCore(from: number, to?: number) {\n\t\tconst query = { documentId: this.id, tenantId: this.tenantId };\n\t\tquery[\"operation.sequenceNumber\"] = {};\n\t\tquery[\"operation.sequenceNumber\"].$gt = from - 1; // from is inclusive\n\n\t\t// This looks like a bug. It used to work without setting $lt key. Now it does not\n\t\t// Need follow up\n\t\tquery[\"operation.sequenceNumber\"].$lt = to ?? Number.MAX_SAFE_INTEGER;\n\n\t\tconst allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);\n\t\tconst dbDeltas = await allDeltas.find(query, { \"operation.sequenceNumber\": 1 });\n\t\tconst messages = dbDeltas.map((delta) => delta.operation);\n\t\treturn messages;\n\t}\n}\n"]}
@@ -0,0 +1,48 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { DocumentDeltaConnection } from "@fluidframework/driver-base";
6
+ import { IClient, IDocumentMessage, NackErrorType } from "@fluidframework/protocol-definitions";
7
+ import { IWebSocketServer } from "@fluidframework/server-services-core";
8
+ import type { Socket } from "socket.io-client";
9
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
10
+ /**
11
+ * Represents a connection to a stream of delta updates
12
+ * @internal
13
+ */
14
+ export declare class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
15
+ /**
16
+ * Create a LocalDocumentDeltaConnection
17
+ * Handle initial messages, contents or signals if they were in queue
18
+ *
19
+ * @param tenantId - the ID of the tenant
20
+ * @param id - document ID
21
+ * @param token - authorization token for storage service
22
+ * @param client - information about the client
23
+ * @param webSocketServer - web socket server to create connection
24
+ */
25
+ static create(tenantId: string, id: string, token: string, client: IClient, webSocketServer: IWebSocketServer, timeoutMs?: number, logger?: ITelemetryBaseLogger): Promise<LocalDocumentDeltaConnection>;
26
+ constructor(socket: Socket, documentId: string, logger?: ITelemetryBaseLogger);
27
+ /**
28
+ * Submits a new delta operation to the server
29
+ */
30
+ submit(messages: IDocumentMessage[]): void;
31
+ /**
32
+ * Submits a new signal to the server
33
+ */
34
+ submitSignal(message: any): void;
35
+ /**
36
+ * Send a "disconnect" message on the socket.
37
+ * @param disconnectReason - The reason of the disconnection.
38
+ */
39
+ disconnectClient(disconnectReason: string): void;
40
+ /**
41
+ * * Sends a "nack" message on the socket.
42
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
43
+ * @param type - Type of the Nack.
44
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
45
+ */
46
+ nackClient(code: number | undefined, type: NackErrorType | undefined, message: any): void;
47
+ }
48
+ //# sourceMappingURL=localDocumentDeltaConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localDocumentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/localDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,uBAAuB,EAAE,MAAM,6BAA6B;OAC9D,EACN,OAAO,EAEP,gBAAgB,EAChB,aAAa,EACb,MAAM,sCAAsC;OAGtC,EAAE,gBAAgB,EAAE,MAAM,sCAAsC;OAChE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB;OACvC,EAAE,oBAAoB,EAAE,MAAM,iCAAiC;AAItE;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,uBAAuB;IACxE;;;;;;;;;OASG;WACiB,MAAM,CACzB,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,gBAAgB,EACjC,SAAS,SAAQ,EACjB,MAAM,CAAC,EAAE,oBAAoB,GAC3B,OAAO,CAAC,4BAA4B,CAAC;gBAqB5B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,oBAAoB;IAI7E;;OAEG;IACI,MAAM,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI;IAQjD;;OAEG;IACI,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAIvC;;;OAGG;IACI,gBAAgB,CAAC,gBAAgB,EAAE,MAAM;IAIhD;;;;;OAKG;IACI,UAAU,CAChB,IAAI,oBAAc,EAClB,IAAI,2BAA+C,EACnD,OAAO,EAAE,GAAG;CAab"}
@@ -0,0 +1,86 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { DocumentDeltaConnection } from "@fluidframework/driver-base";
6
+ import { NackErrorType, } from "@fluidframework/protocol-definitions";
7
+ import { createChildLogger } from "@fluidframework/telemetry-utils";
8
+ const testProtocolVersions = ["^0.3.0", "^0.2.0", "^0.1.0"];
9
+ /**
10
+ * Represents a connection to a stream of delta updates
11
+ * @internal
12
+ */
13
+ export class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
14
+ /**
15
+ * Create a LocalDocumentDeltaConnection
16
+ * Handle initial messages, contents or signals if they were in queue
17
+ *
18
+ * @param tenantId - the ID of the tenant
19
+ * @param id - document ID
20
+ * @param token - authorization token for storage service
21
+ * @param client - information about the client
22
+ * @param webSocketServer - web socket server to create connection
23
+ */
24
+ static async create(tenantId, id, token, client, webSocketServer, timeoutMs = 60000, logger) {
25
+ const socket = webSocketServer.createConnection();
26
+ // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky
27
+ // but should be fine because this delta connection is for local use only.
28
+ const socketWithListener = socket;
29
+ const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id, logger);
30
+ const connectMessage = {
31
+ client,
32
+ id,
33
+ mode: client.mode,
34
+ tenantId,
35
+ token,
36
+ versions: testProtocolVersions,
37
+ };
38
+ await deltaConnection.initialize(connectMessage, timeoutMs);
39
+ return deltaConnection;
40
+ }
41
+ constructor(socket, documentId, logger) {
42
+ super(socket, documentId, createChildLogger({ logger }));
43
+ }
44
+ /**
45
+ * Submits a new delta operation to the server
46
+ */
47
+ submit(messages) {
48
+ // We use a promise resolve to force a turn break given message processing is sync
49
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
50
+ Promise.resolve().then(() => {
51
+ this.emitMessages("submitOp", [messages]);
52
+ });
53
+ }
54
+ /**
55
+ * Submits a new signal to the server
56
+ */
57
+ submitSignal(message) {
58
+ this.emitMessages("submitSignal", [[message]]);
59
+ }
60
+ /**
61
+ * Send a "disconnect" message on the socket.
62
+ * @param disconnectReason - The reason of the disconnection.
63
+ */
64
+ disconnectClient(disconnectReason) {
65
+ this.socket.emit("disconnect", disconnectReason);
66
+ }
67
+ /**
68
+ * * Sends a "nack" message on the socket.
69
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
70
+ * @param type - Type of the Nack.
71
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
72
+ */
73
+ nackClient(code = 400, type = NackErrorType.ThrottlingError, message) {
74
+ const nackMessage = {
75
+ operation: undefined,
76
+ sequenceNumber: -1,
77
+ content: {
78
+ code,
79
+ type,
80
+ message,
81
+ },
82
+ };
83
+ this.socket.emit("nack", "", [nackMessage]);
84
+ }
85
+ }
86
+ //# sourceMappingURL=localDocumentDeltaConnection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localDocumentDeltaConnection.mjs","sourceRoot":"","sources":["../src/localDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,uBAAuB,EAAE,MAAM,6BAA6B;OAC9D,EAIN,aAAa,GACb,MAAM,sCAAsC;OACtC,EAAE,iBAAiB,EAAE,MAAM,iCAAiC;AAMnE,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,OAAO,4BAA6B,SAAQ,uBAAuB;IACxE;;;;;;;;;OASG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CACzB,QAAgB,EAChB,EAAU,EACV,KAAa,EACb,MAAe,EACf,eAAiC,EACjC,SAAS,GAAG,KAAK,EACjB,MAA6B;QAE7B,MAAM,MAAM,GAAI,eAAwC,CAAC,gBAAgB,EAAE,CAAC;QAE5E,4GAA4G;QAC5G,0EAA0E;QAC1E,MAAM,kBAAkB,GAAG,MAA2B,CAAC;QAEvD,MAAM,eAAe,GAAG,IAAI,4BAA4B,CAAC,kBAAkB,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAEzF,MAAM,cAAc,GAAa;YAChC,MAAM;YACN,EAAE;YACF,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,QAAQ;YACR,KAAK;YACL,QAAQ,EAAE,oBAAoB;SAC9B,CAAC;QACF,MAAM,eAAe,CAAC,UAAU,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QAC5D,OAAO,eAAe,CAAC;IACxB,CAAC;IAED,YAAY,MAAc,EAAE,UAAkB,EAAE,MAA6B;QAC5E,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAA4B;QACzC,kFAAkF;QAClF,mEAAmE;QACnE,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,OAAY;QAC/B,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAC,gBAAwB;QAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAChB,OAAe,GAAG,EAClB,OAAsB,aAAa,CAAC,eAAe,EACnD,OAAY;QAEZ,MAAM,WAAW,GAAG;YACnB,SAAS,EAAE,SAAS;YACpB,cAAc,EAAE,CAAC,CAAC;YAClB,OAAO,EAAE;gBACR,IAAI;gBACJ,IAAI;gBACJ,OAAO;aACP;SACD,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { DocumentDeltaConnection } from \"@fluidframework/driver-base\";\nimport {\n\tIClient,\n\tIConnect,\n\tIDocumentMessage,\n\tNackErrorType,\n} from \"@fluidframework/protocol-definitions\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { LocalWebSocketServer } from \"@fluidframework/server-local-server\";\nimport { IWebSocketServer } from \"@fluidframework/server-services-core\";\nimport type { Socket } from \"socket.io-client\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\n\nconst testProtocolVersions = [\"^0.3.0\", \"^0.2.0\", \"^0.1.0\"];\n\n/**\n * Represents a connection to a stream of delta updates\n * @internal\n */\nexport class LocalDocumentDeltaConnection extends DocumentDeltaConnection {\n\t/**\n\t * Create a LocalDocumentDeltaConnection\n\t * Handle initial messages, contents or signals if they were in queue\n\t *\n\t * @param tenantId - the ID of the tenant\n\t * @param id - document ID\n\t * @param token - authorization token for storage service\n\t * @param client - information about the client\n\t * @param webSocketServer - web socket server to create connection\n\t */\n\tpublic static async create(\n\t\ttenantId: string,\n\t\tid: string,\n\t\ttoken: string,\n\t\tclient: IClient,\n\t\twebSocketServer: IWebSocketServer,\n\t\ttimeoutMs = 60000,\n\t\tlogger?: ITelemetryBaseLogger,\n\t): Promise<LocalDocumentDeltaConnection> {\n\t\tconst socket = (webSocketServer as LocalWebSocketServer).createConnection();\n\n\t\t// Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky\n\t\t// but should be fine because this delta connection is for local use only.\n\t\tconst socketWithListener = socket as unknown as Socket;\n\n\t\tconst deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id, logger);\n\n\t\tconst connectMessage: IConnect = {\n\t\t\tclient,\n\t\t\tid,\n\t\t\tmode: client.mode,\n\t\t\ttenantId,\n\t\t\ttoken, // Token is going to indicate tenant level information, etc...\n\t\t\tversions: testProtocolVersions,\n\t\t};\n\t\tawait deltaConnection.initialize(connectMessage, timeoutMs);\n\t\treturn deltaConnection;\n\t}\n\n\tconstructor(socket: Socket, documentId: string, logger?: ITelemetryBaseLogger) {\n\t\tsuper(socket, documentId, createChildLogger({ logger }));\n\t}\n\n\t/**\n\t * Submits a new delta operation to the server\n\t */\n\tpublic submit(messages: IDocumentMessage[]): void {\n\t\t// We use a promise resolve to force a turn break given message processing is sync\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tPromise.resolve().then(() => {\n\t\t\tthis.emitMessages(\"submitOp\", [messages]);\n\t\t});\n\t}\n\n\t/**\n\t * Submits a new signal to the server\n\t */\n\tpublic submitSignal(message: any): void {\n\t\tthis.emitMessages(\"submitSignal\", [[message]]);\n\t}\n\n\t/**\n\t * Send a \"disconnect\" message on the socket.\n\t * @param disconnectReason - The reason of the disconnection.\n\t */\n\tpublic disconnectClient(disconnectReason: string) {\n\t\tthis.socket.emit(\"disconnect\", disconnectReason);\n\t}\n\n\t/**\n\t * * Sends a \"nack\" message on the socket.\n\t * @param code - An error code number that represents the error. It will be a valid HTTP error code.\n\t * @param type - Type of the Nack.\n\t * @param message - A message about the nack for debugging/logging/telemetry purposes.\n\t */\n\tpublic nackClient(\n\t\tcode: number = 400,\n\t\ttype: NackErrorType = NackErrorType.ThrottlingError,\n\t\tmessage: any,\n\t) {\n\t\tconst nackMessage = {\n\t\t\toperation: undefined,\n\t\t\tsequenceNumber: -1,\n\t\t\tcontent: {\n\t\t\t\tcode,\n\t\t\t\ttype,\n\t\t\t\tmessage,\n\t\t\t},\n\t\t};\n\t\tthis.socket.emit(\"nack\", \"\", [nackMessage]);\n\t}\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentDeltaConnection, IDocumentDeltaStorageService, IDocumentService, IDocumentServicePolicies, IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
6
+ import { IClient } from "@fluidframework/protocol-definitions";
7
+ import { ITokenProvider } from "@fluidframework/routerlicious-driver";
8
+ import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
9
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
10
+ import { LocalDocumentDeltaConnection } from "./localDocumentDeltaConnection.mjs";
11
+ /**
12
+ * Basic implementation of a document service for local use.
13
+ * @internal
14
+ */
15
+ export declare class LocalDocumentService implements IDocumentService {
16
+ readonly resolvedUrl: IResolvedUrl;
17
+ private readonly localDeltaConnectionServer;
18
+ private readonly tokenProvider;
19
+ private readonly tenantId;
20
+ private readonly documentId;
21
+ private readonly documentDeltaConnectionsMap;
22
+ readonly policies: IDocumentServicePolicies;
23
+ private readonly innerDocumentService?;
24
+ private readonly logger?;
25
+ /**
26
+ * @param localDeltaConnectionServer - delta connection server for ops
27
+ * @param tokenProvider - token provider
28
+ * @param tenantId - ID of tenant
29
+ * @param documentId - ID of document
30
+ */
31
+ constructor(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService | undefined, logger?: ITelemetryBaseLogger | undefined);
32
+ dispose(): void;
33
+ /**
34
+ * Creates and returns a document storage service for local use.
35
+ */
36
+ connectToStorage(): Promise<IDocumentStorageService>;
37
+ /**
38
+ * Creates and returns a delta storage service for local use.
39
+ */
40
+ connectToDeltaStorage(): Promise<IDocumentDeltaStorageService>;
41
+ /**
42
+ * Creates and returns a delta stream for local use.
43
+ * @param client - client data
44
+ */
45
+ connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection>;
46
+ }
47
+ /**
48
+ * Creates and returns a document service for local use.
49
+ * @param localDeltaConnectionServer - delta connection server for ops
50
+ * @param tokenProvider - token provider with a single token
51
+ * @param tenantId - ID of tenant
52
+ * @param documentId - ID of document
53
+ * @internal
54
+ */
55
+ export declare function createLocalDocumentService(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService, logger?: ITelemetryBaseLogger): IDocumentService;
56
+ //# sourceMappingURL=localDocumentService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localDocumentService.d.ts","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EACN,wBAAwB,EACxB,4BAA4B,EAC5B,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,YAAY,EACZ,MAAM,oCAAoC;OACpC,EAAE,OAAO,EAAE,MAAM,sCAAsC;OACvD,EAAE,cAAc,EAAE,MAAM,sCAAsC;OAG9D,EAAE,2BAA2B,EAAE,MAAM,qCAAqC;OAC1E,EAAE,oBAAoB,EAAE,MAAM,iCAAiC;OAE/D,EAAE,4BAA4B,EAAE;AAGvC;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,gBAAgB;aAQ3C,WAAW,EAAE,YAAY;IACzC,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,2BAA2B;aAC5B,QAAQ,EAAE,wBAAwB;IAClD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAfzB;;;;;OAKG;gBAEc,WAAW,EAAE,YAAY,EACxB,0BAA0B,EAAE,2BAA2B,EACvD,aAAa,EAAE,cAAc,EAC7B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,4BAA4B,CAAC,EACvE,QAAQ,GAAE,wBAA6B,EACtC,oBAAoB,CAAC,8BAAkB,EACvC,MAAM,CAAC,kCAAsB;IAGxC,OAAO;IAEd;;OAEG;IACU,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAcjE;;OAEG;IACU,qBAAqB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAW3E;;;OAGG;IACU,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAgCrF;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACzC,WAAW,EAAE,YAAY,EACzB,0BAA0B,EAAE,2BAA2B,EACvD,aAAa,EAAE,cAAc,EAC7B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,4BAA4B,CAAC,EACtE,QAAQ,CAAC,EAAE,wBAAwB,EACnC,oBAAoB,CAAC,EAAE,gBAAgB,EACvC,MAAM,CAAC,EAAE,oBAAoB,GAC3B,gBAAgB,CAYlB"}
@@ -0,0 +1,84 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { GitManager } from "@fluidframework/server-services-client";
6
+ import { TestHistorian } from "@fluidframework/server-test-utils";
7
+ import { LocalDocumentStorageService } from "./localDocumentStorageService.mjs";
8
+ import { LocalDocumentDeltaConnection } from "./localDocumentDeltaConnection.mjs";
9
+ import { LocalDeltaStorageService } from "./localDeltaStorageService.mjs";
10
+ /**
11
+ * Basic implementation of a document service for local use.
12
+ * @internal
13
+ */
14
+ export class LocalDocumentService {
15
+ /**
16
+ * @param localDeltaConnectionServer - delta connection server for ops
17
+ * @param tokenProvider - token provider
18
+ * @param tenantId - ID of tenant
19
+ * @param documentId - ID of document
20
+ */
21
+ constructor(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies = {}, innerDocumentService, logger) {
22
+ this.resolvedUrl = resolvedUrl;
23
+ this.localDeltaConnectionServer = localDeltaConnectionServer;
24
+ this.tokenProvider = tokenProvider;
25
+ this.tenantId = tenantId;
26
+ this.documentId = documentId;
27
+ this.documentDeltaConnectionsMap = documentDeltaConnectionsMap;
28
+ this.policies = policies;
29
+ this.innerDocumentService = innerDocumentService;
30
+ this.logger = logger;
31
+ }
32
+ dispose() { }
33
+ /**
34
+ * Creates and returns a document storage service for local use.
35
+ */
36
+ async connectToStorage() {
37
+ return new LocalDocumentStorageService(this.documentId, new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)), {
38
+ maximumCacheDurationMs: 432000000, // 5 days in ms. Not actually enforced but shouldn't matter for any local driver scenario
39
+ }, this.localDeltaConnectionServer, this.resolvedUrl);
40
+ }
41
+ /**
42
+ * Creates and returns a delta storage service for local use.
43
+ */
44
+ async connectToDeltaStorage() {
45
+ if (this.innerDocumentService) {
46
+ return this.innerDocumentService.connectToDeltaStorage();
47
+ }
48
+ return new LocalDeltaStorageService(this.tenantId, this.documentId, this.localDeltaConnectionServer.databaseManager);
49
+ }
50
+ /**
51
+ * Creates and returns a delta stream for local use.
52
+ * @param client - client data
53
+ */
54
+ async connectToDeltaStream(client) {
55
+ if (this.policies.storageOnly === true) {
56
+ throw new Error("can't connect to delta stream in storage-only mode");
57
+ }
58
+ if (this.innerDocumentService) {
59
+ return this.innerDocumentService.connectToDeltaStream(client);
60
+ }
61
+ const ordererToken = await this.tokenProvider.fetchOrdererToken(this.tenantId, this.documentId);
62
+ const documentDeltaConnection = await LocalDocumentDeltaConnection.create(this.tenantId, this.documentId, ordererToken.jwt, client, this.localDeltaConnectionServer.webSocketServer, undefined, this.logger);
63
+ const clientId = documentDeltaConnection.clientId;
64
+ // Add this document service for the clientId in the document service factory.
65
+ this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);
66
+ // Add a listener to remove this document service when the client is disconnected.
67
+ documentDeltaConnection.on("disconnect", () => {
68
+ this.documentDeltaConnectionsMap.delete(clientId);
69
+ });
70
+ return documentDeltaConnection;
71
+ }
72
+ }
73
+ /**
74
+ * Creates and returns a document service for local use.
75
+ * @param localDeltaConnectionServer - delta connection server for ops
76
+ * @param tokenProvider - token provider with a single token
77
+ * @param tenantId - ID of tenant
78
+ * @param documentId - ID of document
79
+ * @internal
80
+ */
81
+ export function createLocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService, logger) {
82
+ return new LocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService, logger);
83
+ }
84
+ //# sourceMappingURL=localDocumentService.mjs.map