@fluidframework/local-driver 2.0.0-internal.3.2.2 → 2.0.0-internal.3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-extractor.json +4 -0
- package/dist/localDocumentServiceFactory.d.ts +3 -0
- package/dist/localDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localDocumentServiceFactory.js +3 -0
- package/dist/localDocumentServiceFactory.js.map +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/localSessionStorageDb.js +3 -0
- package/dist/localSessionStorageDb.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/auth.d.ts +12 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +38 -0
- package/lib/auth.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/lib/localDeltaStorageService.d.ts +19 -0
- package/lib/localDeltaStorageService.d.ts.map +1 -0
- package/lib/localDeltaStorageService.js +31 -0
- package/lib/localDeltaStorageService.js.map +1 -0
- package/lib/localDocumentDeltaConnection.d.ts +47 -0
- package/lib/localDocumentDeltaConnection.d.ts.map +1 -0
- package/lib/localDocumentDeltaConnection.js +88 -0
- package/lib/localDocumentDeltaConnection.js.map +1 -0
- package/lib/localDocumentService.d.ts +52 -0
- package/lib/localDocumentService.d.ts.map +1 -0
- package/lib/localDocumentService.js +80 -0
- package/lib/localDocumentService.js.map +1 -0
- package/lib/localDocumentServiceFactory.d.ts +47 -0
- package/lib/localDocumentServiceFactory.d.ts.map +1 -0
- package/lib/localDocumentServiceFactory.js +101 -0
- package/lib/localDocumentServiceFactory.js.map +1 -0
- package/lib/localDocumentStorageService.d.ts +24 -0
- package/lib/localDocumentStorageService.d.ts.map +1 -0
- package/lib/localDocumentStorageService.js +72 -0
- package/lib/localDocumentStorageService.js.map +1 -0
- package/lib/localResolver.d.ts +26 -0
- package/lib/localResolver.d.ts.map +1 -0
- package/lib/localResolver.js +70 -0
- package/lib/localResolver.js.map +1 -0
- package/lib/localSessionStorageDb.d.ts +10 -0
- package/lib/localSessionStorageDb.d.ts.map +1 -0
- package/lib/localSessionStorageDb.js +295 -0
- package/lib/localSessionStorageDb.js.map +1 -0
- package/lib/packageVersion.d.ts +9 -0
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/packageVersion.js +9 -0
- package/lib/packageVersion.js.map +1 -0
- package/package.json +26 -22
- package/src/localDocumentServiceFactory.ts +3 -0
- package/src/localSessionStorageDb.ts +3 -0
- package/src/packageVersion.ts +1 -1
- package/tsconfig.esnext.json +7 -0
|
@@ -0,0 +1,80 @@
|
|
|
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 { LocalDeltaStorageService, LocalDocumentDeltaConnection, LocalDocumentStorageService, } from ".";
|
|
8
|
+
/**
|
|
9
|
+
* Basic implementation of a document service for local use.
|
|
10
|
+
*/
|
|
11
|
+
export class LocalDocumentService {
|
|
12
|
+
/**
|
|
13
|
+
* @param localDeltaConnectionServer - delta connection server for ops
|
|
14
|
+
* @param tokenProvider - token provider
|
|
15
|
+
* @param tenantId - ID of tenant
|
|
16
|
+
* @param documentId - ID of document
|
|
17
|
+
*/
|
|
18
|
+
constructor(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies = {}, innerDocumentService) {
|
|
19
|
+
this.resolvedUrl = resolvedUrl;
|
|
20
|
+
this.localDeltaConnectionServer = localDeltaConnectionServer;
|
|
21
|
+
this.tokenProvider = tokenProvider;
|
|
22
|
+
this.tenantId = tenantId;
|
|
23
|
+
this.documentId = documentId;
|
|
24
|
+
this.documentDeltaConnectionsMap = documentDeltaConnectionsMap;
|
|
25
|
+
this.policies = policies;
|
|
26
|
+
this.innerDocumentService = innerDocumentService;
|
|
27
|
+
}
|
|
28
|
+
dispose() { }
|
|
29
|
+
/**
|
|
30
|
+
* Creates and returns a document storage service for local use.
|
|
31
|
+
*/
|
|
32
|
+
async connectToStorage() {
|
|
33
|
+
return new LocalDocumentStorageService(this.documentId, new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)), {
|
|
34
|
+
minBlobSize: 2048,
|
|
35
|
+
maximumCacheDurationMs: 432000000, // 5 days in ms. Not actually enforced but shouldn't matter for any local driver scenario
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates and returns a delta storage service for local use.
|
|
40
|
+
*/
|
|
41
|
+
async connectToDeltaStorage() {
|
|
42
|
+
if (this.innerDocumentService) {
|
|
43
|
+
return this.innerDocumentService.connectToDeltaStorage();
|
|
44
|
+
}
|
|
45
|
+
return new LocalDeltaStorageService(this.tenantId, this.documentId, this.localDeltaConnectionServer.databaseManager);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates and returns a delta stream for local use.
|
|
49
|
+
* @param client - client data
|
|
50
|
+
*/
|
|
51
|
+
async connectToDeltaStream(client) {
|
|
52
|
+
if (this.policies.storageOnly === true) {
|
|
53
|
+
throw new Error("can't connect to delta stream in storage-only mode");
|
|
54
|
+
}
|
|
55
|
+
if (this.innerDocumentService) {
|
|
56
|
+
return this.innerDocumentService.connectToDeltaStream(client);
|
|
57
|
+
}
|
|
58
|
+
const ordererToken = await this.tokenProvider.fetchOrdererToken(this.tenantId, this.documentId);
|
|
59
|
+
const documentDeltaConnection = await LocalDocumentDeltaConnection.create(this.tenantId, this.documentId, ordererToken.jwt, client, this.localDeltaConnectionServer.webSocketServer);
|
|
60
|
+
const clientId = documentDeltaConnection.clientId;
|
|
61
|
+
// Add this document service for the clientId in the document service factory.
|
|
62
|
+
this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);
|
|
63
|
+
// Add a listener to remove this document service when the client is disconnected.
|
|
64
|
+
documentDeltaConnection.on("disconnect", () => {
|
|
65
|
+
this.documentDeltaConnectionsMap.delete(clientId);
|
|
66
|
+
});
|
|
67
|
+
return documentDeltaConnection;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates and returns a document service for local use.
|
|
72
|
+
* @param localDeltaConnectionServer - delta connection server for ops
|
|
73
|
+
* @param tokenProvider - token provider with a single token
|
|
74
|
+
* @param tenantId - ID of tenant
|
|
75
|
+
* @param documentId - ID of document
|
|
76
|
+
*/
|
|
77
|
+
export function createLocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService) {
|
|
78
|
+
return new LocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=localDocumentService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentService.js","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,EACN,wBAAwB,EACxB,4BAA4B,EAC5B,2BAA2B,GAC3B,MAAM,GAAG,CAAC;AACX;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;;;;OAKG;IACH,YACiB,WAAyB,EACxB,0BAAuD,EACvD,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACvE,WAAqC,EAAE,EACtC,oBAAuC;QAPxC,gBAAW,GAAX,WAAW,CAAc;QACxB,+BAA0B,GA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QACF,MAAM,uBAAuB,GAAG,MAAM,4BAA4B,CAAC,MAAM,CACxE,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,UAAU,EACf,YAAY,CAAC,GAAG,EAChB,MAAM,EACN,IAAI,CAAC,0BAA0B,CAAC,eAAe,CAC/C,CAAC;QACF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QAElD,8EAA8E;QAC9E,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;QAExE,kFAAkF;QAClF,uBAAuB,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;YAC7C,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,OAAO,uBAAuB,CAAC;IAChC,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACzC,WAAyB,EACzB,0BAAuD,EACvD,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACtE,QAAmC,EACnC,oBAAuC;IAEvC,OAAO,IAAI,oBAAoB,CAC9B,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,QAAQ,EACR,UAAU,EACV,2BAA2B,EAC3B,QAAQ,EACR,oBAAoB,CACpB,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIDocumentServicePolicies,\n\tIDocumentStorageService,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport { ITokenProvider } from \"@fluidframework/routerlicious-driver\";\nimport { GitManager } from \"@fluidframework/server-services-client\";\nimport { TestHistorian } from \"@fluidframework/server-test-utils\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tLocalDeltaStorageService,\n\tLocalDocumentDeltaConnection,\n\tLocalDocumentStorageService,\n} from \".\";\n/**\n * Basic implementation of a document service for local use.\n */\nexport class LocalDocumentService implements IDocumentService {\n\t/**\n\t * @param localDeltaConnectionServer - delta connection server for ops\n\t * @param tokenProvider - token provider\n\t * @param tenantId - ID of tenant\n\t * @param documentId - ID of document\n\t */\n\tconstructor(\n\t\tpublic readonly resolvedUrl: IResolvedUrl,\n\t\tprivate readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n\t\tprivate readonly tokenProvider: ITokenProvider,\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly documentId: string,\n\t\tprivate readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,\n\t\tpublic readonly policies: IDocumentServicePolicies = {},\n\t\tprivate readonly innerDocumentService?: IDocumentService,\n\t) {}\n\n\tpublic dispose() {}\n\n\t/**\n\t * Creates and returns a document storage service for local use.\n\t */\n\tpublic async connectToStorage(): Promise<IDocumentStorageService> {\n\t\treturn new LocalDocumentStorageService(\n\t\t\tthis.documentId,\n\t\t\tnew GitManager(\n\t\t\t\tnew TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase),\n\t\t\t),\n\t\t\t{\n\t\t\t\tminBlobSize: 2048, // Test blob aggregation\n\t\t\t\tmaximumCacheDurationMs: 432_000_000, // 5 days in ms. Not actually enforced but shouldn't matter for any local driver scenario\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Creates and returns a delta storage service for local use.\n\t */\n\tpublic async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n\t\tif (this.innerDocumentService) {\n\t\t\treturn this.innerDocumentService.connectToDeltaStorage();\n\t\t}\n\t\treturn new LocalDeltaStorageService(\n\t\t\tthis.tenantId,\n\t\t\tthis.documentId,\n\t\t\tthis.localDeltaConnectionServer.databaseManager,\n\t\t);\n\t}\n\n\t/**\n\t * Creates and returns a delta stream for local use.\n\t * @param client - client data\n\t */\n\tpublic async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n\t\tif (this.policies.storageOnly === true) {\n\t\t\tthrow new Error(\"can't connect to delta stream in storage-only mode\");\n\t\t}\n\t\tif (this.innerDocumentService) {\n\t\t\treturn this.innerDocumentService.connectToDeltaStream(client);\n\t\t}\n\t\tconst ordererToken = await this.tokenProvider.fetchOrdererToken(\n\t\t\tthis.tenantId,\n\t\t\tthis.documentId,\n\t\t);\n\t\tconst documentDeltaConnection = await LocalDocumentDeltaConnection.create(\n\t\t\tthis.tenantId,\n\t\t\tthis.documentId,\n\t\t\tordererToken.jwt,\n\t\t\tclient,\n\t\t\tthis.localDeltaConnectionServer.webSocketServer,\n\t\t);\n\t\tconst clientId = documentDeltaConnection.clientId;\n\n\t\t// Add this document service for the clientId in the document service factory.\n\t\tthis.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);\n\n\t\t// Add a listener to remove this document service when the client is disconnected.\n\t\tdocumentDeltaConnection.on(\"disconnect\", () => {\n\t\t\tthis.documentDeltaConnectionsMap.delete(clientId);\n\t\t});\n\n\t\treturn documentDeltaConnection;\n\t}\n}\n\n/**\n * Creates and returns a document service for local use.\n * @param localDeltaConnectionServer - delta connection server for ops\n * @param tokenProvider - token provider with a single token\n * @param tenantId - ID of tenant\n * @param documentId - ID of document\n */\nexport function createLocalDocumentService(\n\tresolvedUrl: IResolvedUrl,\n\tlocalDeltaConnectionServer: ILocalDeltaConnectionServer,\n\ttokenProvider: ITokenProvider,\n\ttenantId: string,\n\tdocumentId: string,\n\tdocumentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,\n\tpolicies?: IDocumentServicePolicies,\n\tinnerDocumentService?: IDocumentService,\n): IDocumentService {\n\treturn new LocalDocumentService(\n\t\tresolvedUrl,\n\t\tlocalDeltaConnectionServer,\n\t\ttokenProvider,\n\t\ttenantId,\n\t\tdocumentId,\n\t\tdocumentDeltaConnectionsMap,\n\t\tpolicies,\n\t\tinnerDocumentService,\n\t);\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDocumentService, IDocumentServiceFactory, IDocumentServicePolicies, IResolvedUrl } from "@fluidframework/driver-definitions";
|
|
6
|
+
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
|
|
7
|
+
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
8
|
+
import { ISummaryTree, NackErrorType } from "@fluidframework/protocol-definitions";
|
|
9
|
+
/**
|
|
10
|
+
* Implementation of document service factory for local use.
|
|
11
|
+
*/
|
|
12
|
+
export declare class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
13
|
+
private readonly localDeltaConnectionServer;
|
|
14
|
+
private readonly policies?;
|
|
15
|
+
private readonly innerDocumentService?;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated 2.0.0-internal.3.3.0 Document service factories should not be distinguished by unique non-standard protocols. To be removed in an upcoming release.
|
|
18
|
+
*/
|
|
19
|
+
readonly protocolName = "fluid-test:";
|
|
20
|
+
private readonly documentDeltaConnectionsMap;
|
|
21
|
+
/**
|
|
22
|
+
* @param localDeltaConnectionServer - delta connection server for ops
|
|
23
|
+
*/
|
|
24
|
+
constructor(localDeltaConnectionServer: ILocalDeltaConnectionServer, policies?: IDocumentServicePolicies | undefined, innerDocumentService?: IDocumentService | undefined);
|
|
25
|
+
createContainer(createNewSummary: ISummaryTree | undefined, resolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates and returns a document service for testing using the given resolved
|
|
28
|
+
* URL for the tenant ID, document ID, and token.
|
|
29
|
+
* @param resolvedUrl - resolved URL of document
|
|
30
|
+
*/
|
|
31
|
+
createDocumentService(resolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the document delta connection for the clientId and asks it to disconnect the client.
|
|
34
|
+
* @param clientId - The ID of the client to be disconnected.
|
|
35
|
+
* @param disconnectReason - The reason of the disconnection.
|
|
36
|
+
*/
|
|
37
|
+
disconnectClient(clientId: string, disconnectReason: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the document delta connection for the clientId and asks it to nack the client.
|
|
40
|
+
* @param clientId - The ID of the client to be Nack'd.
|
|
41
|
+
* @param code - An error code number that represents the error. It will be a valid HTTP error code.
|
|
42
|
+
* @param type - Type of the Nack.
|
|
43
|
+
* @param message - A message about the nack for debugging/logging/telemetry purposes.
|
|
44
|
+
*/
|
|
45
|
+
nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any): void;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=localDocumentServiceFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EACN,2BAA2B,EAE3B,MAAM,qCAAqC,CAAC;AAM7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAKnF;;GAEG;AACH,qBAAa,2BAA4B,YAAW,uBAAuB;IAczE,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IAfvC;;OAEG;IACH,SAAgB,YAAY,iBAAiB;IAG7C,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CACjC;IAEX;;OAEG;gBAEe,0BAA0B,EAAE,2BAA2B,EACvD,QAAQ,CAAC,sCAA0B,EACnC,oBAAoB,CAAC,8BAAkB;IAG5C,eAAe,CAC3B,gBAAgB,EAAE,YAAY,GAAG,SAAS,EAC1C,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IAuC5B;;;;OAIG;IACU,qBAAqB,CACjC,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IA+B5B;;;;OAIG;IACI,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM;IAQlE;;;;;;OAMG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,GAAG;CAOtF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { parse } from "url";
|
|
6
|
+
import { DefaultTokenProvider } from "@fluidframework/routerlicious-driver";
|
|
7
|
+
import { ensureFluidResolvedUrl, getDocAttributesFromProtocolSummary, getQuorumValuesFromProtocolSummary, } from "@fluidframework/driver-utils";
|
|
8
|
+
import { defaultHash } from "@fluidframework/server-services-client";
|
|
9
|
+
import { createLocalDocumentService } from "./localDocumentService";
|
|
10
|
+
/**
|
|
11
|
+
* Implementation of document service factory for local use.
|
|
12
|
+
*/
|
|
13
|
+
export class LocalDocumentServiceFactory {
|
|
14
|
+
/**
|
|
15
|
+
* @param localDeltaConnectionServer - delta connection server for ops
|
|
16
|
+
*/
|
|
17
|
+
constructor(localDeltaConnectionServer, policies, innerDocumentService) {
|
|
18
|
+
this.localDeltaConnectionServer = localDeltaConnectionServer;
|
|
19
|
+
this.policies = policies;
|
|
20
|
+
this.innerDocumentService = innerDocumentService;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated 2.0.0-internal.3.3.0 Document service factories should not be distinguished by unique non-standard protocols. To be removed in an upcoming release.
|
|
23
|
+
*/
|
|
24
|
+
this.protocolName = "fluid-test:";
|
|
25
|
+
// A map of clientId to LocalDocumentService.
|
|
26
|
+
this.documentDeltaConnectionsMap = new Map();
|
|
27
|
+
}
|
|
28
|
+
async createContainer(createNewSummary, resolvedUrl, logger, clientIsSummarizer) {
|
|
29
|
+
var _a, _b, _c, _d;
|
|
30
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
31
|
+
if (createNewSummary === undefined) {
|
|
32
|
+
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
33
|
+
}
|
|
34
|
+
const pathName = new URL(resolvedUrl.url).pathname;
|
|
35
|
+
const pathArr = pathName.split("/");
|
|
36
|
+
const tenantId = pathArr[pathArr.length - 2];
|
|
37
|
+
const id = pathArr[pathArr.length - 1];
|
|
38
|
+
if (!this.localDeltaConnectionServer) {
|
|
39
|
+
throw new Error("Provide the localDeltaConnectionServer!!");
|
|
40
|
+
}
|
|
41
|
+
const documentStorage = this.localDeltaConnectionServer
|
|
42
|
+
.documentStorage;
|
|
43
|
+
const protocolSummary = createNewSummary.tree[".protocol"];
|
|
44
|
+
const appSummary = createNewSummary.tree[".app"];
|
|
45
|
+
if (!(protocolSummary && appSummary)) {
|
|
46
|
+
throw new Error("Protocol and App Summary required in the full summary");
|
|
47
|
+
}
|
|
48
|
+
const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
|
|
49
|
+
const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);
|
|
50
|
+
const sequenceNumber = documentAttributes.sequenceNumber;
|
|
51
|
+
await documentStorage.createDocument(tenantId, id, appSummary, sequenceNumber, (_a = documentAttributes.term) !== null && _a !== void 0 ? _a : 1, defaultHash, (_b = resolvedUrl.endpoints.ordererUrl) !== null && _b !== void 0 ? _b : "", (_c = resolvedUrl.endpoints.storageUrl) !== null && _c !== void 0 ? _c : "", (_d = resolvedUrl.endpoints.deltaStorageUrl) !== null && _d !== void 0 ? _d : "", quorumValues, false /* enableDiscovery */);
|
|
52
|
+
return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates and returns a document service for testing using the given resolved
|
|
56
|
+
* URL for the tenant ID, document ID, and token.
|
|
57
|
+
* @param resolvedUrl - resolved URL of document
|
|
58
|
+
*/
|
|
59
|
+
async createDocumentService(resolvedUrl, logger, clientIsSummarizer) {
|
|
60
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
61
|
+
const parsedUrl = parse(resolvedUrl.url);
|
|
62
|
+
const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : [];
|
|
63
|
+
if (!documentId || !tenantId) {
|
|
64
|
+
throw new Error(`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`);
|
|
65
|
+
}
|
|
66
|
+
const fluidResolvedUrl = resolvedUrl;
|
|
67
|
+
const jwtToken = fluidResolvedUrl.tokens.jwt;
|
|
68
|
+
if (!jwtToken) {
|
|
69
|
+
throw new Error(`Token was not provided.`);
|
|
70
|
+
}
|
|
71
|
+
const tokenProvider = new DefaultTokenProvider(jwtToken);
|
|
72
|
+
return createLocalDocumentService(resolvedUrl, this.localDeltaConnectionServer, tokenProvider, tenantId, documentId, this.documentDeltaConnectionsMap, this.policies, this.innerDocumentService);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets the document delta connection for the clientId and asks it to disconnect the client.
|
|
76
|
+
* @param clientId - The ID of the client to be disconnected.
|
|
77
|
+
* @param disconnectReason - The reason of the disconnection.
|
|
78
|
+
*/
|
|
79
|
+
disconnectClient(clientId, disconnectReason) {
|
|
80
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
81
|
+
if (documentDeltaConnection === undefined) {
|
|
82
|
+
throw new Error(`No client with the id: ${clientId}`);
|
|
83
|
+
}
|
|
84
|
+
documentDeltaConnection.disconnectClient(disconnectReason);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Gets the document delta connection for the clientId and asks it to nack the client.
|
|
88
|
+
* @param clientId - The ID of the client to be Nack'd.
|
|
89
|
+
* @param code - An error code number that represents the error. It will be a valid HTTP error code.
|
|
90
|
+
* @param type - Type of the Nack.
|
|
91
|
+
* @param message - A message about the nack for debugging/logging/telemetry purposes.
|
|
92
|
+
*/
|
|
93
|
+
nackClient(clientId, code, type, message) {
|
|
94
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
95
|
+
if (documentDeltaConnection === undefined) {
|
|
96
|
+
throw new Error(`No client with the id: ${clientId}`);
|
|
97
|
+
}
|
|
98
|
+
documentDeltaConnection.nackClient(code, type, message);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=localDocumentServiceFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentServiceFactory.js","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAQ5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAK5E,OAAO,EACN,sBAAsB,EACtB,mCAAmC,EACnC,kCAAkC,GAClC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAErE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAU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;YACd,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC3C;QAED,MAAM,aAAa,GAAG,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAEzD,OAAO,0BAA0B,CAChC,WAAW,EACX,IAAI,CAAC,0BAA0B,EAC/B,aAAa,EACb,QAAQ,EACR,UAAU,EACV,IAAI,CAAC,2BAA2B,EAChC,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,oBAAoB,CACzB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,QAAgB,EAAE,gBAAwB;QACjE,MAAM,uBAAuB,GAAG,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/E,IAAI,uBAAuB,KAAK,SAAS,EAAE;YAC1C,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;SACtD;QACD,uBAAuB,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;OAMG;IACI,UAAU,CAAC,QAAgB,EAAE,IAAa,EAAE,IAAoB,EAAE,OAAa;QACrF,MAAM,uBAAuB,GAAG,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/E,IAAI,uBAAuB,KAAK,SAAS,EAAE;YAC1C,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;SACtD;QACD,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport {\n\tIDocumentService,\n\tIDocumentServiceFactory,\n\tIDocumentServicePolicies,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { DefaultTokenProvider } from \"@fluidframework/routerlicious-driver\";\nimport {\n\tILocalDeltaConnectionServer,\n\tLocalDeltaConnectionServer,\n} from \"@fluidframework/server-local-server\";\nimport {\n\tensureFluidResolvedUrl,\n\tgetDocAttributesFromProtocolSummary,\n\tgetQuorumValuesFromProtocolSummary,\n} from \"@fluidframework/driver-utils\";\nimport { ISummaryTree, NackErrorType } from \"@fluidframework/protocol-definitions\";\nimport { defaultHash } from \"@fluidframework/server-services-client\";\nimport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection\";\nimport { createLocalDocumentService } from \"./localDocumentService\";\n\n/**\n * Implementation of document service factory for local use.\n */\nexport class LocalDocumentServiceFactory implements IDocumentServiceFactory {\n\t/**\n\t * @deprecated 2.0.0-internal.3.3.0 Document service factories should not be distinguished by unique non-standard protocols. To be removed in an upcoming release.\n\t */\n\tpublic readonly protocolName = \"fluid-test:\";\n\n\t// A map of clientId to LocalDocumentService.\n\tprivate readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> =\n\t\tnew Map();\n\n\t/**\n\t * @param localDeltaConnectionServer - delta connection server for ops\n\t */\n\tconstructor(\n\t\tprivate readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n\t\tprivate readonly policies?: IDocumentServicePolicies,\n\t\tprivate readonly innerDocumentService?: IDocumentService,\n\t) {}\n\n\tpublic async createContainer(\n\t\tcreateNewSummary: ISummaryTree | undefined,\n\t\tresolvedUrl: IResolvedUrl,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService> {\n\t\tensureFluidResolvedUrl(resolvedUrl);\n\t\tif (createNewSummary === undefined) {\n\t\t\tthrow new Error(\"Empty file summary creation isn't supported in this driver.\");\n\t\t}\n\t\tconst pathName = new URL(resolvedUrl.url).pathname;\n\t\tconst pathArr = pathName.split(\"/\");\n\t\tconst tenantId = pathArr[pathArr.length - 2];\n\t\tconst id = pathArr[pathArr.length - 1];\n\t\tif (!this.localDeltaConnectionServer) {\n\t\t\tthrow new Error(\"Provide the localDeltaConnectionServer!!\");\n\t\t}\n\t\tconst documentStorage = (this.localDeltaConnectionServer as LocalDeltaConnectionServer)\n\t\t\t.documentStorage;\n\n\t\tconst protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n\t\tconst appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n\t\tif (!(protocolSummary && appSummary)) {\n\t\t\tthrow new Error(\"Protocol and App Summary required in the full summary\");\n\t\t}\n\t\tconst documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n\t\tconst quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);\n\t\tconst sequenceNumber = documentAttributes.sequenceNumber;\n\t\tawait documentStorage.createDocument(\n\t\t\ttenantId,\n\t\t\tid,\n\t\t\tappSummary,\n\t\t\tsequenceNumber,\n\t\t\tdocumentAttributes.term ?? 1,\n\t\t\tdefaultHash,\n\t\t\tresolvedUrl.endpoints.ordererUrl ?? \"\",\n\t\t\tresolvedUrl.endpoints.storageUrl ?? \"\",\n\t\t\tresolvedUrl.endpoints.deltaStorageUrl ?? \"\",\n\t\t\tquorumValues,\n\t\t\tfalse /* enableDiscovery */,\n\t\t);\n\t\treturn this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);\n\t}\n\n\t/**\n\t * Creates and returns a document service for testing using the given resolved\n\t * URL for the tenant ID, document ID, and token.\n\t * @param resolvedUrl - resolved URL of document\n\t */\n\tpublic async createDocumentService(\n\t\tresolvedUrl: IResolvedUrl,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService> {\n\t\tensureFluidResolvedUrl(resolvedUrl);\n\n\t\tconst parsedUrl = parse(resolvedUrl.url);\n\t\tconst [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split(\"/\") : [];\n\t\tif (!documentId || !tenantId) {\n\t\t\tthrow new Error(\n\t\t\t\t`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`,\n\t\t\t);\n\t\t}\n\n\t\tconst fluidResolvedUrl = resolvedUrl;\n\t\tconst jwtToken = fluidResolvedUrl.tokens.jwt;\n\t\tif (!jwtToken) {\n\t\t\tthrow new Error(`Token was not provided.`);\n\t\t}\n\n\t\tconst tokenProvider = new DefaultTokenProvider(jwtToken);\n\n\t\treturn createLocalDocumentService(\n\t\t\tresolvedUrl,\n\t\t\tthis.localDeltaConnectionServer,\n\t\t\ttokenProvider,\n\t\t\ttenantId,\n\t\t\tdocumentId,\n\t\t\tthis.documentDeltaConnectionsMap,\n\t\t\tthis.policies,\n\t\t\tthis.innerDocumentService,\n\t\t);\n\t}\n\n\t/**\n\t * Gets the document delta connection for the clientId and asks it to disconnect the client.\n\t * @param clientId - The ID of the client to be disconnected.\n\t * @param disconnectReason - The reason of the disconnection.\n\t */\n\tpublic disconnectClient(clientId: string, disconnectReason: string) {\n\t\tconst documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);\n\t\tif (documentDeltaConnection === undefined) {\n\t\t\tthrow new Error(`No client with the id: ${clientId}`);\n\t\t}\n\t\tdocumentDeltaConnection.disconnectClient(disconnectReason);\n\t}\n\n\t/**\n\t * Gets the document delta connection for the clientId and asks it to nack the client.\n\t * @param clientId - The ID of the client to be Nack'd.\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(clientId: string, code?: number, type?: NackErrorType, message?: any) {\n\t\tconst documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);\n\t\tif (documentDeltaConnection === undefined) {\n\t\t\tthrow new Error(`No client with the id: ${clientId}`);\n\t\t}\n\t\tdocumentDeltaConnection.nackClient(code, type, message);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDocumentStorageService, IDocumentStorageServicePolicies, ISummaryContext } from "@fluidframework/driver-definitions";
|
|
6
|
+
import { ICreateBlobResponse, ISnapshotTreeEx, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
|
|
7
|
+
import { GitManager } from "@fluidframework/server-services-client";
|
|
8
|
+
export declare class LocalDocumentStorageService implements IDocumentStorageService {
|
|
9
|
+
private readonly id;
|
|
10
|
+
private readonly manager;
|
|
11
|
+
readonly policies: IDocumentStorageServicePolicies;
|
|
12
|
+
protected readonly blobsShaCache: Map<string, string>;
|
|
13
|
+
private readonly summaryTreeUploadManager;
|
|
14
|
+
get repositoryUrl(): string;
|
|
15
|
+
constructor(id: string, manager: GitManager, policies: IDocumentStorageServicePolicies);
|
|
16
|
+
getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
|
|
17
|
+
getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null>;
|
|
18
|
+
readBlob(blobId: string): Promise<ArrayBufferLike>;
|
|
19
|
+
uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
20
|
+
createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
|
|
21
|
+
downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree>;
|
|
22
|
+
private getPreviousFullSnapshot;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=localDocumentStorageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,uBAAuB,EACvB,+BAA+B,EAC/B,eAAe,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACN,UAAU,EAGV,MAAM,wCAAwC,CAAC;AAEhD,qBAAa,2BAA4B,YAAW,uBAAuB;IAWzE,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;aACR,QAAQ,EAAE,+BAA+B;IAV1D,SAAS,CAAC,QAAQ,CAAC,aAAa,sBAA6B;IAC7D,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAwB;IAEjE,IAAW,aAAa,IAAI,MAAM,CAEjC;gBAGiB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,UAAU,EACpB,QAAQ,EAAE,+BAA+B;IAS7C,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUzE,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAgBpE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAOlD,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IAQL,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO/D,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;YAI7D,uBAAuB;CAWrC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils";
|
|
6
|
+
import { buildHierarchy } from "@fluidframework/protocol-base";
|
|
7
|
+
import { SummaryTreeUploadManager, } from "@fluidframework/server-services-client";
|
|
8
|
+
export class LocalDocumentStorageService {
|
|
9
|
+
constructor(id, manager, policies) {
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.manager = manager;
|
|
12
|
+
this.policies = policies;
|
|
13
|
+
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
14
|
+
// empty strings as values.
|
|
15
|
+
this.blobsShaCache = new Map();
|
|
16
|
+
this.summaryTreeUploadManager = new SummaryTreeUploadManager(manager, this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
|
|
17
|
+
}
|
|
18
|
+
get repositoryUrl() {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
async getVersions(versionId, count) {
|
|
22
|
+
const id = versionId ? versionId : this.id;
|
|
23
|
+
const commits = await this.manager.getCommits(id, count);
|
|
24
|
+
return commits.map((commit) => ({
|
|
25
|
+
date: commit.commit.author.date,
|
|
26
|
+
id: commit.sha,
|
|
27
|
+
treeId: commit.commit.tree.sha,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
async getSnapshotTree(version) {
|
|
31
|
+
let requestVersion = version;
|
|
32
|
+
if (!requestVersion) {
|
|
33
|
+
const versions = await this.getVersions(this.id, 1);
|
|
34
|
+
if (versions.length === 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
requestVersion = versions[0];
|
|
38
|
+
}
|
|
39
|
+
const rawTree = await this.manager.getTree(requestVersion.treeId);
|
|
40
|
+
const tree = buildHierarchy(rawTree, this.blobsShaCache, true);
|
|
41
|
+
return tree;
|
|
42
|
+
}
|
|
43
|
+
async readBlob(blobId) {
|
|
44
|
+
const blob = await this.manager.getBlob(blobId);
|
|
45
|
+
this.blobsShaCache.set(blob.sha, "");
|
|
46
|
+
const bufferContent = stringToBuffer(blob.content, blob.encoding);
|
|
47
|
+
return bufferContent;
|
|
48
|
+
}
|
|
49
|
+
async uploadSummaryWithContext(summary, context) {
|
|
50
|
+
var _a;
|
|
51
|
+
return this.summaryTreeUploadManager.writeSummaryTree(summary, (_a = context.ackHandle) !== null && _a !== void 0 ? _a : "", "channel");
|
|
52
|
+
}
|
|
53
|
+
async createBlob(file) {
|
|
54
|
+
const uint8ArrayFile = new Uint8Array(file);
|
|
55
|
+
return this.manager
|
|
56
|
+
.createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
|
|
57
|
+
.then((r) => ({ id: r.sha, url: r.url }));
|
|
58
|
+
}
|
|
59
|
+
async downloadSummary(handle) {
|
|
60
|
+
throw new Error("NOT IMPLEMENTED!");
|
|
61
|
+
}
|
|
62
|
+
async getPreviousFullSnapshot(parentHandle) {
|
|
63
|
+
return parentHandle
|
|
64
|
+
? this.getVersions(parentHandle, 1).then(async (versions) => {
|
|
65
|
+
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
66
|
+
this.blobsShaCache.clear();
|
|
67
|
+
return this.getSnapshotTree(versions[0]);
|
|
68
|
+
})
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=localDocumentStorageService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAalF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAGN,wBAAwB,GACxB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,OAAO,2BAA2B;IAUvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC;QAFxC,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAiC;QAZ1D,uFAAuF;QACvF,2BAA2B;QACR,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QAY5D,IAAI,CAAC,wBAAwB,GAAG,IAAI,wBAAwB,CAC3D,OAAO,EACP,IAAI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,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { stringToBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { buildHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildHierarchy(rawTree, this.blobsShaCache, true);\n\t\treturn tree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IRequest } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { IResolvedUrl, IUrlResolver } from "@fluidframework/driver-definitions";
|
|
7
|
+
export declare function createLocalResolverCreateNewRequest(documentId: string): IRequest;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves URLs by providing fake URLs which succeed with the other
|
|
10
|
+
* related local classes.
|
|
11
|
+
*/
|
|
12
|
+
export declare class LocalResolver implements IUrlResolver {
|
|
13
|
+
private readonly tenantId;
|
|
14
|
+
private readonly tokenKey;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Resolves URL requests by providing fake URLs with an actually generated
|
|
18
|
+
* token from constant test strings. The root of the URL is fake, but the
|
|
19
|
+
* remaining relative URL can still be parsed.
|
|
20
|
+
* @param request - request to handle
|
|
21
|
+
*/
|
|
22
|
+
resolve(request: IRequest): Promise<IResolvedUrl>;
|
|
23
|
+
getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string>;
|
|
24
|
+
createCreateNewRequest(documentId: string): IRequest;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=localResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localResolver.d.ts","sourceRoot":"","sources":["../src/localResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAEN,YAAY,EACZ,YAAY,EAEZ,MAAM,oCAAoC,CAAC;AAI5C,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAQhF;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,YAAY;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;;IAIvC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBjD,cAAc,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBrF,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;CAG3D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { parse } from "url";
|
|
6
|
+
import { assert } from "@fluidframework/common-utils";
|
|
7
|
+
import { DriverHeader, } from "@fluidframework/driver-definitions";
|
|
8
|
+
import { ScopeType } from "@fluidframework/protocol-definitions";
|
|
9
|
+
import { generateToken } from "./auth";
|
|
10
|
+
export function createLocalResolverCreateNewRequest(documentId) {
|
|
11
|
+
const createNewRequest = {
|
|
12
|
+
url: `http://localhost:3000/${documentId}`,
|
|
13
|
+
headers: {
|
|
14
|
+
[DriverHeader.createNew]: true,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
return createNewRequest;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves URLs by providing fake URLs which succeed with the other
|
|
21
|
+
* related local classes.
|
|
22
|
+
*/
|
|
23
|
+
export class LocalResolver {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.tenantId = "tenantId";
|
|
26
|
+
this.tokenKey = "tokenKey";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolves URL requests by providing fake URLs with an actually generated
|
|
30
|
+
* token from constant test strings. The root of the URL is fake, but the
|
|
31
|
+
* remaining relative URL can still be parsed.
|
|
32
|
+
* @param request - request to handle
|
|
33
|
+
*/
|
|
34
|
+
async resolve(request) {
|
|
35
|
+
const parsedUrl = new URL(request.url);
|
|
36
|
+
const fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;
|
|
37
|
+
const documentId = fullPath.split("/")[0];
|
|
38
|
+
const scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];
|
|
39
|
+
const resolved = {
|
|
40
|
+
endpoints: {
|
|
41
|
+
deltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,
|
|
42
|
+
ordererUrl: "http://localhost:3000",
|
|
43
|
+
storageUrl: `http://localhost:3000/repos/${this.tenantId}`,
|
|
44
|
+
},
|
|
45
|
+
id: documentId,
|
|
46
|
+
tokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },
|
|
47
|
+
type: "fluid",
|
|
48
|
+
url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,
|
|
49
|
+
};
|
|
50
|
+
return resolved;
|
|
51
|
+
}
|
|
52
|
+
async getAbsoluteUrl(resolvedUrl, relativeUrl) {
|
|
53
|
+
let url = relativeUrl;
|
|
54
|
+
if (url.startsWith("/")) {
|
|
55
|
+
url = url.substr(1);
|
|
56
|
+
}
|
|
57
|
+
const fluidResolvedUrl = resolvedUrl;
|
|
58
|
+
const parsedUrl = parse(fluidResolvedUrl.url);
|
|
59
|
+
if (parsedUrl.pathname === null) {
|
|
60
|
+
throw new Error("Url should contain tenant and docId!!");
|
|
61
|
+
}
|
|
62
|
+
const [, , documentId] = parsedUrl.pathname.split("/");
|
|
63
|
+
assert(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
|
|
64
|
+
return `http://localhost:3000/${documentId}/${url}`;
|
|
65
|
+
}
|
|
66
|
+
createCreateNewRequest(documentId) {
|
|
67
|
+
return createLocalResolverCreateNewRequest(documentId);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=localResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localResolver.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AuB;gBACnC,UAAU,EAAE,+BAA+B,IAAI,CAAC,QAAQ,EAAE;aAC1D;YACD,EAAE,EAAE,UAAU;YACd,MAAM,EAAE,EAAE,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;YAChF,IAAI,EAAE,OAAO;YACb,GAAG,EAAE,+BAA+B,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE;SAC/D,CAAC;QAEF,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,WAAyB,EAAE,WAAmB;QACzE,IAAI,GAAG,GAAG,WAAW,CAAC;QACtB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACxB,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACpB;QACD,MAAM,gBAAgB,GAAG,WAAgC,CAAC;QAE1D,MAAM,SAAS,GAAG,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,QAAQ,KAAK,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;SACzD;QACD,MAAM,CAAC,EAAE,AAAD,EAAG,UAAU,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,+DAA+D,CAAC,CAAC;QAE5F,OAAO,yBAAyB,UAAU,IAAI,GAAG,EAAE,CAAC;IACrD,CAAC;IAEM,sBAAsB,CAAC,UAAkB;QAC/C,OAAO,mCAAmC,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tIFluidResolvedUrl,\n\tIResolvedUrl,\n\tIUrlResolver,\n\tDriverHeader,\n} from \"@fluidframework/driver-definitions\";\nimport { ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { generateToken } from \"./auth\";\n\nexport function createLocalResolverCreateNewRequest(documentId: string): IRequest {\n\tconst createNewRequest: IRequest = {\n\t\turl: `http://localhost:3000/${documentId}`,\n\t\theaders: {\n\t\t\t[DriverHeader.createNew]: true,\n\t\t},\n\t};\n\treturn createNewRequest;\n}\n\n/**\n * Resolves URLs by providing fake URLs which succeed with the other\n * related local classes.\n */\nexport class LocalResolver implements IUrlResolver {\n\tprivate readonly tenantId = \"tenantId\";\n\tprivate readonly tokenKey = \"tokenKey\";\n\n\tconstructor() {}\n\n\t/**\n\t * Resolves URL requests by providing fake URLs with an actually generated\n\t * token from constant test strings. The root of the URL is fake, but the\n\t * remaining relative URL can still be parsed.\n\t * @param request - request to handle\n\t */\n\tpublic async resolve(request: IRequest): Promise<IResolvedUrl> {\n\t\tconst parsedUrl = new URL(request.url);\n\t\tconst fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;\n\t\tconst documentId = fullPath.split(\"/\")[0];\n\t\tconst scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];\n\t\tconst resolved: IFluidResolvedUrl = {\n\t\t\tendpoints: {\n\t\t\t\tdeltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,\n\t\t\t\tordererUrl: \"http://localhost:3000\",\n\t\t\t\tstorageUrl: `http://localhost:3000/repos/${this.tenantId}`,\n\t\t\t},\n\t\t\tid: documentId,\n\t\t\ttokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },\n\t\t\ttype: \"fluid\",\n\t\t\turl: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,\n\t\t};\n\n\t\treturn resolved;\n\t}\n\n\tpublic async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {\n\t\tlet url = relativeUrl;\n\t\tif (url.startsWith(\"/\")) {\n\t\t\turl = url.substr(1);\n\t\t}\n\t\tconst fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;\n\n\t\tconst parsedUrl = parse(fluidResolvedUrl.url);\n\t\tif (parsedUrl.pathname === null) {\n\t\t\tthrow new Error(\"Url should contain tenant and docId!!\");\n\t\t}\n\t\tconst [, , documentId] = parsedUrl.pathname.split(\"/\");\n\t\tassert(!!documentId, 0x09a /* \"'documentId' must be a defined, non-zero length string.\" */);\n\n\t\treturn `http://localhost:3000/${documentId}/${url}`;\n\t}\n\n\tpublic createCreateNewRequest(documentId: string): IRequest {\n\t\treturn createLocalResolverCreateNewRequest(documentId);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IDb } from "@fluidframework/server-services-core";
|
|
2
|
+
import { ITestDbFactory } from "@fluidframework/server-test-utils";
|
|
3
|
+
/**
|
|
4
|
+
* A database factory for testing that stores data in the browsers session storage
|
|
5
|
+
*/
|
|
6
|
+
export declare class LocalSessionStorageDbFactory implements ITestDbFactory {
|
|
7
|
+
readonly testDatabase: IDb;
|
|
8
|
+
connect(): Promise<IDb>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=localSessionStorageDb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAgTnE;;GAEG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAClE,SAAgB,YAAY,EAAE,GAAG,CAA+B;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGpC"}
|