@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.
- package/.eslintrc.js +19 -22
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +127 -0
- package/README.md +38 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/local-driver.api.md +129 -0
- package/dist/{auth.js → auth.cjs} +8 -6
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.cjs +24 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/local-driver-alpha.d.ts +110 -0
- package/dist/local-driver-beta.d.ts +75 -0
- package/dist/local-driver-public.d.ts +75 -0
- package/dist/local-driver-untrimmed.d.ts +226 -0
- package/dist/localCreateDocument.cjs +28 -0
- package/dist/localCreateDocument.cjs.map +1 -0
- package/dist/localCreateDocument.d.ts +8 -0
- package/dist/localCreateDocument.d.ts.map +1 -0
- package/dist/{localDeltaStorageService.js → localDeltaStorageService.cjs} +3 -2
- package/dist/localDeltaStorageService.cjs.map +1 -0
- package/dist/localDeltaStorageService.d.ts +4 -3
- package/dist/localDeltaStorageService.d.ts.map +1 -1
- package/dist/{localDocumentDeltaConnection.js → localDocumentDeltaConnection.cjs} +9 -11
- package/dist/localDocumentDeltaConnection.cjs.map +1 -0
- package/dist/localDocumentDeltaConnection.d.ts +5 -4
- package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/{localDocumentService.js → localDocumentService.cjs} +15 -30
- package/dist/localDocumentService.cjs.map +1 -0
- package/dist/localDocumentService.d.ts +15 -11
- package/dist/localDocumentService.d.ts.map +1 -1
- package/dist/{localDocumentServiceFactory.js → localDocumentServiceFactory.cjs} +14 -31
- package/dist/localDocumentServiceFactory.cjs.map +1 -0
- package/dist/localDocumentServiceFactory.d.ts +3 -2
- package/dist/localDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localDocumentStorageService.cjs +88 -0
- package/dist/localDocumentStorageService.cjs.map +1 -0
- package/dist/localDocumentStorageService.d.ts +30 -0
- package/dist/localDocumentStorageService.d.ts.map +1 -0
- package/dist/{localResolver.js → localResolver.cjs} +10 -6
- package/dist/localResolver.cjs.map +1 -0
- package/dist/localResolver.d.ts +5 -0
- package/dist/localResolver.d.ts.map +1 -1
- package/dist/{localSessionStorageDb.js → localSessionStorageDb.cjs} +26 -18
- package/dist/localSessionStorageDb.cjs.map +1 -0
- package/dist/localSessionStorageDb.d.ts +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/auth.d.mts +12 -0
- package/lib/auth.d.mts.map +1 -0
- package/lib/auth.mjs +40 -0
- package/lib/auth.mjs.map +1 -0
- package/lib/index.d.mts +12 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +12 -0
- package/lib/index.mjs.map +1 -0
- package/lib/local-driver-alpha.d.mts +110 -0
- package/lib/local-driver-beta.d.mts +75 -0
- package/lib/local-driver-public.d.mts +75 -0
- package/lib/local-driver-untrimmed.d.mts +226 -0
- package/lib/localCreateDocument.d.mts +8 -0
- package/lib/localCreateDocument.d.mts.map +1 -0
- package/lib/localCreateDocument.mjs +24 -0
- package/lib/localCreateDocument.mjs.map +1 -0
- package/lib/localDeltaStorageService.d.mts +20 -0
- package/lib/localDeltaStorageService.d.mts.map +1 -0
- package/lib/localDeltaStorageService.mjs +32 -0
- package/lib/localDeltaStorageService.mjs.map +1 -0
- package/lib/localDocumentDeltaConnection.d.mts +48 -0
- package/lib/localDocumentDeltaConnection.d.mts.map +1 -0
- package/lib/localDocumentDeltaConnection.mjs +86 -0
- package/lib/localDocumentDeltaConnection.mjs.map +1 -0
- package/lib/localDocumentService.d.mts +56 -0
- package/lib/localDocumentService.d.mts.map +1 -0
- package/lib/localDocumentService.mjs +84 -0
- package/lib/localDocumentService.mjs.map +1 -0
- package/lib/localDocumentServiceFactory.d.mts +45 -0
- package/lib/localDocumentServiceFactory.d.mts.map +1 -0
- package/lib/localDocumentServiceFactory.mjs +80 -0
- package/lib/localDocumentServiceFactory.mjs.map +1 -0
- package/lib/localDocumentStorageService.d.mts +30 -0
- package/lib/localDocumentStorageService.d.mts.map +1 -0
- package/lib/localDocumentStorageService.mjs +84 -0
- package/lib/localDocumentStorageService.mjs.map +1 -0
- package/lib/localResolver.d.mts +31 -0
- package/lib/localResolver.d.mts.map +1 -0
- package/lib/localResolver.mjs +74 -0
- package/lib/localResolver.mjs.map +1 -0
- package/lib/localSessionStorageDb.d.mts +11 -0
- package/lib/localSessionStorageDb.d.mts.map +1 -0
- package/lib/localSessionStorageDb.mjs +292 -0
- package/lib/localSessionStorageDb.mjs.map +1 -0
- package/package.json +102 -59
- package/prettier.config.cjs +8 -0
- package/src/auth.ts +42 -33
- package/src/index.ts +7 -6
- package/src/localCreateDocument.ts +48 -0
- package/src/localDeltaStorageService.ts +28 -27
- package/src/localDocumentDeltaConnection.ts +91 -88
- package/src/localDocumentService.ts +117 -97
- package/src/localDocumentServiceFactory.ts +95 -123
- package/src/localDocumentStorageService.ts +131 -0
- package/src/localResolver.ts +57 -59
- package/src/localSessionStorageDb.ts +272 -265
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +11 -13
- package/dist/auth.js.map +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/localDeltaStorageService.js.map +0 -1
- package/dist/localDocumentDeltaConnection.js.map +0 -1
- package/dist/localDocumentService.js.map +0 -1
- package/dist/localDocumentServiceFactory.js.map +0 -1
- package/dist/localResolver.js.map +0 -1
- package/dist/localSessionStorageDb.js.map +0 -1
- package/dist/packageVersion.d.ts +0 -9
- package/dist/packageVersion.d.ts.map +0 -1
- package/dist/packageVersion.js +0 -12
- package/dist/packageVersion.js.map +0 -1
- package/src/packageVersion.ts +0 -9
|
@@ -3,34 +3,16 @@
|
|
|
3
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
7
|
exports.createLocalDocumentService = exports.LocalDocumentService = void 0;
|
|
27
|
-
const socketStorage = __importStar(require("@fluidframework/routerlicious-driver"));
|
|
28
8
|
const server_services_client_1 = require("@fluidframework/server-services-client");
|
|
29
9
|
const server_test_utils_1 = require("@fluidframework/server-test-utils");
|
|
30
|
-
const
|
|
31
|
-
const
|
|
10
|
+
const localDocumentStorageService_1 = require("./localDocumentStorageService.cjs");
|
|
11
|
+
const localDocumentDeltaConnection_1 = require("./localDocumentDeltaConnection.cjs");
|
|
12
|
+
const localDeltaStorageService_1 = require("./localDeltaStorageService.cjs");
|
|
32
13
|
/**
|
|
33
14
|
* Basic implementation of a document service for local use.
|
|
15
|
+
* @internal
|
|
34
16
|
*/
|
|
35
17
|
class LocalDocumentService {
|
|
36
18
|
/**
|
|
@@ -39,7 +21,7 @@ class LocalDocumentService {
|
|
|
39
21
|
* @param tenantId - ID of tenant
|
|
40
22
|
* @param documentId - ID of document
|
|
41
23
|
*/
|
|
42
|
-
constructor(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies = {}, innerDocumentService) {
|
|
24
|
+
constructor(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies = {}, innerDocumentService, logger) {
|
|
43
25
|
this.resolvedUrl = resolvedUrl;
|
|
44
26
|
this.localDeltaConnectionServer = localDeltaConnectionServer;
|
|
45
27
|
this.tokenProvider = tokenProvider;
|
|
@@ -48,14 +30,16 @@ class LocalDocumentService {
|
|
|
48
30
|
this.documentDeltaConnectionsMap = documentDeltaConnectionsMap;
|
|
49
31
|
this.policies = policies;
|
|
50
32
|
this.innerDocumentService = innerDocumentService;
|
|
33
|
+
this.logger = logger;
|
|
51
34
|
}
|
|
52
35
|
dispose() { }
|
|
53
36
|
/**
|
|
54
37
|
* Creates and returns a document storage service for local use.
|
|
55
38
|
*/
|
|
56
39
|
async connectToStorage() {
|
|
57
|
-
return new
|
|
58
|
-
|
|
40
|
+
return new localDocumentStorageService_1.LocalDocumentStorageService(this.documentId, new server_services_client_1.GitManager(new server_test_utils_1.TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)), {
|
|
41
|
+
maximumCacheDurationMs: 432000000, // 5 days in ms. Not actually enforced but shouldn't matter for any local driver scenario
|
|
42
|
+
}, this.localDeltaConnectionServer, this.resolvedUrl);
|
|
59
43
|
}
|
|
60
44
|
/**
|
|
61
45
|
* Creates and returns a delta storage service for local use.
|
|
@@ -64,7 +48,7 @@ class LocalDocumentService {
|
|
|
64
48
|
if (this.innerDocumentService) {
|
|
65
49
|
return this.innerDocumentService.connectToDeltaStorage();
|
|
66
50
|
}
|
|
67
|
-
return new
|
|
51
|
+
return new localDeltaStorageService_1.LocalDeltaStorageService(this.tenantId, this.documentId, this.localDeltaConnectionServer.databaseManager);
|
|
68
52
|
}
|
|
69
53
|
/**
|
|
70
54
|
* Creates and returns a delta stream for local use.
|
|
@@ -78,7 +62,7 @@ class LocalDocumentService {
|
|
|
78
62
|
return this.innerDocumentService.connectToDeltaStream(client);
|
|
79
63
|
}
|
|
80
64
|
const ordererToken = await this.tokenProvider.fetchOrdererToken(this.tenantId, this.documentId);
|
|
81
|
-
const documentDeltaConnection = await
|
|
65
|
+
const documentDeltaConnection = await localDocumentDeltaConnection_1.LocalDocumentDeltaConnection.create(this.tenantId, this.documentId, ordererToken.jwt, client, this.localDeltaConnectionServer.webSocketServer, undefined, this.logger);
|
|
82
66
|
const clientId = documentDeltaConnection.clientId;
|
|
83
67
|
// Add this document service for the clientId in the document service factory.
|
|
84
68
|
this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);
|
|
@@ -96,9 +80,10 @@ exports.LocalDocumentService = LocalDocumentService;
|
|
|
96
80
|
* @param tokenProvider - token provider with a single token
|
|
97
81
|
* @param tenantId - ID of tenant
|
|
98
82
|
* @param documentId - ID of document
|
|
83
|
+
* @internal
|
|
99
84
|
*/
|
|
100
|
-
function createLocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService) {
|
|
101
|
-
return new LocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService);
|
|
85
|
+
function createLocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService, logger) {
|
|
86
|
+
return new LocalDocumentService(resolvedUrl, localDeltaConnectionServer, tokenProvider, tenantId, documentId, documentDeltaConnectionsMap, policies, innerDocumentService, logger);
|
|
102
87
|
}
|
|
103
88
|
exports.createLocalDocumentService = createLocalDocumentService;
|
|
104
|
-
//# sourceMappingURL=localDocumentService.
|
|
89
|
+
//# sourceMappingURL=localDocumentService.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentService.cjs","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,mFAAoE;AACpE,yEAAkE;AAGlE,mFAA4E;AAC5E,qFAA8E;AAC9E,6EAAsE;AAEtE;;;GAGG;AACH,MAAa,oBAAoB;IAChC;;;;;OAKG;IACH,YACiB,WAAyB,EACxB,0BAAuD,EACvD,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACvE,WAAqC,EAAE,EACtC,oBAAuC,EACvC,MAA6B;QAR9B,gBAAW,GAAX,WAAW,CAAc;QACxB,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,kBAAa,GAAb,aAAa,CAAgB;QAC7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAQ;QAClB,gCAA2B,GAA3B,2BAA2B,CAA2C;QACvE,aAAQ,GAAR,QAAQ,CAA+B;QACtC,yBAAoB,GAApB,oBAAoB,CAAmB;QACvC,WAAM,GAAN,MAAM,CAAuB;IAC5C,CAAC;IAEG,OAAO,KAAI,CAAC;IAEnB;;OAEG;IACI,KAAK,CAAC,gBAAgB;QAC5B,OAAO,IAAI,yDAA2B,CACrC,IAAI,CAAC,UAAU,EACf,IAAI,mCAAU,CACb,IAAI,iCAAa,CAAC,IAAI,CAAC,0BAA0B,CAAC,aAAa,CAAC,YAAY,CAAC,CAC7E,EACD;YACC,sBAAsB,EAAE,SAAW,EAAE,yFAAyF;SAC9H,EACD,IAAI,CAAC,0BAA0B,EAC/B,IAAI,CAAC,WAAW,CAChB,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,qBAAqB;QACjC,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC9B,OAAO,IAAI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BAAuD,EACvD,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACtE,QAAmC,EACnC,oBAAuC,EACvC,MAA6B;IAE7B,OAAO,IAAI,oBAAoB,CAC9B,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,QAAQ,EACR,UAAU,EACV,2BAA2B,EAC3B,QAAQ,EACR,oBAAoB,EACpB,MAAM,CACN,CAAC;AACH,CAAC;AAtBD,gEAsBC","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 { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { LocalDocumentStorageService } from \"./localDocumentStorageService\";\nimport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection\";\nimport { LocalDeltaStorageService } from \"./localDeltaStorageService\";\n\n/**\n * Basic implementation of a document service for local use.\n * @internal\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\tprivate readonly logger?: ITelemetryBaseLogger,\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\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\tthis.localDeltaConnectionServer,\n\t\t\tthis.resolvedUrl,\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\tundefined,\n\t\t\tthis.logger,\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 * @internal\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\tlogger?: ITelemetryBaseLogger,\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\tlogger,\n\t);\n}\n"]}
|
|
@@ -2,44 +2,47 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { IDocumentDeltaConnection, IDocumentDeltaStorageService, IDocumentService, IDocumentServicePolicies, IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
|
|
6
6
|
import { IClient } from "@fluidframework/protocol-definitions";
|
|
7
|
-
import
|
|
7
|
+
import { ITokenProvider } from "@fluidframework/routerlicious-driver";
|
|
8
8
|
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
9
|
-
import {
|
|
9
|
+
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
10
|
+
import { LocalDocumentDeltaConnection } from "./localDocumentDeltaConnection";
|
|
10
11
|
/**
|
|
11
12
|
* Basic implementation of a document service for local use.
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
|
-
export declare class LocalDocumentService implements
|
|
14
|
-
readonly resolvedUrl:
|
|
15
|
+
export declare class LocalDocumentService implements IDocumentService {
|
|
16
|
+
readonly resolvedUrl: IResolvedUrl;
|
|
15
17
|
private readonly localDeltaConnectionServer;
|
|
16
18
|
private readonly tokenProvider;
|
|
17
19
|
private readonly tenantId;
|
|
18
20
|
private readonly documentId;
|
|
19
21
|
private readonly documentDeltaConnectionsMap;
|
|
20
|
-
readonly policies:
|
|
22
|
+
readonly policies: IDocumentServicePolicies;
|
|
21
23
|
private readonly innerDocumentService?;
|
|
24
|
+
private readonly logger?;
|
|
22
25
|
/**
|
|
23
26
|
* @param localDeltaConnectionServer - delta connection server for ops
|
|
24
27
|
* @param tokenProvider - token provider
|
|
25
28
|
* @param tenantId - ID of tenant
|
|
26
29
|
* @param documentId - ID of document
|
|
27
30
|
*/
|
|
28
|
-
constructor(resolvedUrl:
|
|
31
|
+
constructor(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService | undefined, logger?: ITelemetryBaseLogger | undefined);
|
|
29
32
|
dispose(): void;
|
|
30
33
|
/**
|
|
31
34
|
* Creates and returns a document storage service for local use.
|
|
32
35
|
*/
|
|
33
|
-
connectToStorage(): Promise<
|
|
36
|
+
connectToStorage(): Promise<IDocumentStorageService>;
|
|
34
37
|
/**
|
|
35
38
|
* Creates and returns a delta storage service for local use.
|
|
36
39
|
*/
|
|
37
|
-
connectToDeltaStorage(): Promise<
|
|
40
|
+
connectToDeltaStorage(): Promise<IDocumentDeltaStorageService>;
|
|
38
41
|
/**
|
|
39
42
|
* Creates and returns a delta stream for local use.
|
|
40
43
|
* @param client - client data
|
|
41
44
|
*/
|
|
42
|
-
connectToDeltaStream(client: IClient): Promise<
|
|
45
|
+
connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection>;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Creates and returns a document service for local use.
|
|
@@ -47,6 +50,7 @@ export declare class LocalDocumentService implements api.IDocumentService {
|
|
|
47
50
|
* @param tokenProvider - token provider with a single token
|
|
48
51
|
* @param tenantId - ID of tenant
|
|
49
52
|
* @param documentId - ID of document
|
|
53
|
+
* @internal
|
|
50
54
|
*/
|
|
51
|
-
export declare function createLocalDocumentService(resolvedUrl:
|
|
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;
|
|
52
56
|
//# sourceMappingURL=localDocumentService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentService.d.ts","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"localDocumentService.d.ts","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,wBAAwB,EACxB,4BAA4B,EAC5B,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,YAAY,EACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO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A0B,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"}
|
|
@@ -7,47 +7,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.LocalDocumentServiceFactory = void 0;
|
|
8
8
|
const url_1 = require("url");
|
|
9
9
|
const routerlicious_driver_1 = require("@fluidframework/routerlicious-driver");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const localDocumentService_1 = require("./localDocumentService");
|
|
10
|
+
const localDocumentService_1 = require("./localDocumentService.cjs");
|
|
11
|
+
const localCreateDocument_1 = require("./localCreateDocument.cjs");
|
|
13
12
|
/**
|
|
14
13
|
* Implementation of document service factory for local use.
|
|
14
|
+
* @alpha
|
|
15
15
|
*/
|
|
16
16
|
class LocalDocumentServiceFactory {
|
|
17
17
|
/**
|
|
18
18
|
* @param localDeltaConnectionServer - delta connection server for ops
|
|
19
|
+
* @alpha
|
|
19
20
|
*/
|
|
20
21
|
constructor(localDeltaConnectionServer, policies, innerDocumentService) {
|
|
21
22
|
this.localDeltaConnectionServer = localDeltaConnectionServer;
|
|
22
23
|
this.policies = policies;
|
|
23
24
|
this.innerDocumentService = innerDocumentService;
|
|
24
|
-
this.protocolName = "fluid-test:";
|
|
25
25
|
// A map of clientId to LocalDocumentService.
|
|
26
26
|
this.documentDeltaConnectionsMap = new Map();
|
|
27
27
|
}
|
|
28
28
|
async createContainer(createNewSummary, resolvedUrl, logger, clientIsSummarizer) {
|
|
29
|
-
var _a, _b, _c;
|
|
30
|
-
(0, driver_utils_1.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
29
|
if (!this.localDeltaConnectionServer) {
|
|
39
30
|
throw new Error("Provide the localDeltaConnectionServer!!");
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const appSummary = createNewSummary.tree[".app"];
|
|
44
|
-
if (!(protocolSummary && appSummary)) {
|
|
45
|
-
throw new Error("Protocol and App Summary required in the full summary");
|
|
32
|
+
if (createNewSummary !== undefined) {
|
|
33
|
+
await (0, localCreateDocument_1.createDocument)(this.localDeltaConnectionServer, resolvedUrl, createNewSummary);
|
|
46
34
|
}
|
|
47
|
-
const documentAttributes = (0, driver_utils_1.getDocAttributesFromProtocolSummary)(protocolSummary);
|
|
48
|
-
const quorumValues = (0, driver_utils_1.getQuorumValuesFromProtocolSummary)(protocolSummary);
|
|
49
|
-
const sequenceNumber = documentAttributes.sequenceNumber;
|
|
50
|
-
await documentStorage.createDocument(tenantId, id, appSummary, sequenceNumber, (_a = documentAttributes.term) !== null && _a !== void 0 ? _a : 1, server_services_client_1.defaultHash, (_b = resolvedUrl.endpoints.ordererUrl) !== null && _b !== void 0 ? _b : "", (_c = resolvedUrl.endpoints.storageUrl) !== null && _c !== void 0 ? _c : "", quorumValues, false);
|
|
51
35
|
return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
|
|
52
36
|
}
|
|
53
37
|
/**
|
|
@@ -56,7 +40,6 @@ class LocalDocumentServiceFactory {
|
|
|
56
40
|
* @param resolvedUrl - resolved URL of document
|
|
57
41
|
*/
|
|
58
42
|
async createDocumentService(resolvedUrl, logger, clientIsSummarizer) {
|
|
59
|
-
(0, driver_utils_1.ensureFluidResolvedUrl)(resolvedUrl);
|
|
60
43
|
const parsedUrl = (0, url_1.parse)(resolvedUrl.url);
|
|
61
44
|
const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : [];
|
|
62
45
|
if (!documentId || !tenantId) {
|
|
@@ -68,7 +51,7 @@ class LocalDocumentServiceFactory {
|
|
|
68
51
|
throw new Error(`Token was not provided.`);
|
|
69
52
|
}
|
|
70
53
|
const tokenProvider = new routerlicious_driver_1.DefaultTokenProvider(jwtToken);
|
|
71
|
-
return (0, localDocumentService_1.createLocalDocumentService)(resolvedUrl, this.localDeltaConnectionServer, tokenProvider, tenantId, documentId, this.documentDeltaConnectionsMap, this.policies, this.innerDocumentService);
|
|
54
|
+
return (0, localDocumentService_1.createLocalDocumentService)(resolvedUrl, this.localDeltaConnectionServer, tokenProvider, tenantId, documentId, this.documentDeltaConnectionsMap, this.policies, this.innerDocumentService, logger);
|
|
72
55
|
}
|
|
73
56
|
/**
|
|
74
57
|
* Gets the document delta connection for the clientId and asks it to disconnect the client.
|
|
@@ -76,11 +59,11 @@ class LocalDocumentServiceFactory {
|
|
|
76
59
|
* @param disconnectReason - The reason of the disconnection.
|
|
77
60
|
*/
|
|
78
61
|
disconnectClient(clientId, disconnectReason) {
|
|
79
|
-
|
|
62
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
63
|
+
if (documentDeltaConnection === undefined) {
|
|
80
64
|
throw new Error(`No client with the id: ${clientId}`);
|
|
81
65
|
}
|
|
82
|
-
|
|
83
|
-
this.documentDeltaConnectionsMap.get(clientId).disconnectClient(disconnectReason);
|
|
66
|
+
documentDeltaConnection.disconnectClient(disconnectReason);
|
|
84
67
|
}
|
|
85
68
|
/**
|
|
86
69
|
* Gets the document delta connection for the clientId and asks it to nack the client.
|
|
@@ -90,12 +73,12 @@ class LocalDocumentServiceFactory {
|
|
|
90
73
|
* @param message - A message about the nack for debugging/logging/telemetry purposes.
|
|
91
74
|
*/
|
|
92
75
|
nackClient(clientId, code, type, message) {
|
|
93
|
-
|
|
76
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
77
|
+
if (documentDeltaConnection === undefined) {
|
|
94
78
|
throw new Error(`No client with the id: ${clientId}`);
|
|
95
79
|
}
|
|
96
|
-
|
|
97
|
-
this.documentDeltaConnectionsMap.get(clientId).nackClient(code, type, message);
|
|
80
|
+
documentDeltaConnection.nackClient(code, type, message);
|
|
98
81
|
}
|
|
99
82
|
}
|
|
100
83
|
exports.LocalDocumentServiceFactory = LocalDocumentServiceFactory;
|
|
101
|
-
//# sourceMappingURL=localDocumentServiceFactory.
|
|
84
|
+
//# sourceMappingURL=localDocumentServiceFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentServiceFactory.cjs","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAQ5B,+EAA4E;AAI5E,qEAAoE;AACpE,mEAAuD;AAEvD;;;GAGG;AACH,MAAa,2BAA2B;IAKvC;;;OAGG;IACH,YACkB,0BAAuD,EACvD,QAAmC,EACnC,oBAAuC;QAFvC,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,aAAQ,GAAR,QAAQ,CAA2B;QACnC,yBAAoB,GAApB,oBAAoB,CAAmB;QAXzD,6CAA6C;QAC5B,gCAA2B,GAC3C,IAAI,GAAG,EAAE,CAAC;IAUR,CAAC;IAEG,KAAK,CAAC,eAAe,CAC3B,gBAA0C,EAC1C,WAAyB,EACzB,MAA6B,EAC7B,kBAA4B;QAE5B,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC5D;QACD,IAAI,gBAAgB,KAAK,SAAS,EAAE;YACnC,MAAM,IAAA,oCAAc,EAAC,IAAI,CAAC,0BAA0B,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;SACrF;QACD,OAAO,IAAI,C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C,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;AAhGD,kEAgGC","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/core-interfaces\";\nimport { DefaultTokenProvider } from \"@fluidframework/routerlicious-driver\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport { ISummaryTree, NackErrorType } from \"@fluidframework/protocol-definitions\";\nimport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection\";\nimport { createLocalDocumentService } from \"./localDocumentService\";\nimport { createDocument } from \"./localCreateDocument\";\n\n/**\n * Implementation of document service factory for local use.\n * @alpha\n */\nexport class LocalDocumentServiceFactory implements IDocumentServiceFactory {\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 * @alpha\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\tif (!this.localDeltaConnectionServer) {\n\t\t\tthrow new Error(\"Provide the localDeltaConnectionServer!!\");\n\t\t}\n\t\tif (createNewSummary !== undefined) {\n\t\t\tawait createDocument(this.localDeltaConnectionServer, resolvedUrl, createNewSummary);\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\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\tlogger,\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"]}
|
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { IDocumentService, IDocumentServiceFactory, IDocumentServicePolicies, IResolvedUrl } from "@fluidframework/driver-definitions";
|
|
6
|
-
import { ITelemetryBaseLogger } from "@fluidframework/
|
|
6
|
+
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
7
7
|
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
8
8
|
import { ISummaryTree, NackErrorType } from "@fluidframework/protocol-definitions";
|
|
9
9
|
/**
|
|
10
10
|
* Implementation of document service factory for local use.
|
|
11
|
+
* @alpha
|
|
11
12
|
*/
|
|
12
13
|
export declare class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
13
14
|
private readonly localDeltaConnectionServer;
|
|
14
15
|
private readonly policies?;
|
|
15
16
|
private readonly innerDocumentService?;
|
|
16
|
-
readonly protocolName = "fluid-test:";
|
|
17
17
|
private readonly documentDeltaConnectionsMap;
|
|
18
18
|
/**
|
|
19
19
|
* @param localDeltaConnectionServer - delta connection server for ops
|
|
20
|
+
* @alpha
|
|
20
21
|
*/
|
|
21
22
|
constructor(localDeltaConnectionServer: ILocalDeltaConnectionServer, policies?: IDocumentServicePolicies | undefined, innerDocumentService?: IDocumentService | undefined);
|
|
22
23
|
createContainer(createNewSummary: ISummaryTree | undefined, resolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,
|
|
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,iCAAiC,CAAC;AAEvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAKnF;;;GAGG;AACH,qBAAa,2BAA4B,YAAW,uBAAuB;IAUzE,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IAVvC,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CACjC;IAEX;;;OAGG;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;IAU5B;;;;OAIG;IACU,qBAAqB,CACjC,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IA8B5B;;;;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,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LocalDocumentStorageService = void 0;
|
|
8
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
9
|
+
const protocol_base_1 = require("@fluidframework/protocol-base");
|
|
10
|
+
const server_services_client_1 = require("@fluidframework/server-services-client");
|
|
11
|
+
const localCreateDocument_1 = require("./localCreateDocument.cjs");
|
|
12
|
+
const minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
class LocalDocumentStorageService {
|
|
17
|
+
constructor(id, manager, policies, localDeltaConnectionServer, resolvedUrl) {
|
|
18
|
+
this.id = id;
|
|
19
|
+
this.manager = manager;
|
|
20
|
+
this.policies = policies;
|
|
21
|
+
this.localDeltaConnectionServer = localDeltaConnectionServer;
|
|
22
|
+
this.resolvedUrl = resolvedUrl;
|
|
23
|
+
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
24
|
+
// empty strings as values.
|
|
25
|
+
this.blobsShaCache = new Map();
|
|
26
|
+
this.repositoryUrl = "";
|
|
27
|
+
this.summaryTreeUploadManager = new server_services_client_1.SummaryTreeUploadManager(manager, this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
|
|
28
|
+
}
|
|
29
|
+
async getVersions(versionId, count) {
|
|
30
|
+
const id = versionId ? versionId : this.id;
|
|
31
|
+
const commits = await this.manager.getCommits(id, count);
|
|
32
|
+
return commits.map((commit) => ({
|
|
33
|
+
date: commit.commit.author.date,
|
|
34
|
+
id: commit.sha,
|
|
35
|
+
treeId: commit.commit.tree.sha,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
async getSnapshotTree(version) {
|
|
39
|
+
let requestVersion = version;
|
|
40
|
+
if (!requestVersion) {
|
|
41
|
+
const versions = await this.getVersions(this.id, 1);
|
|
42
|
+
if (versions.length === 0) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
requestVersion = versions[0];
|
|
46
|
+
}
|
|
47
|
+
const rawTree = await this.manager.getTree(requestVersion.treeId);
|
|
48
|
+
const tree = (0, protocol_base_1.buildGitTreeHierarchy)(rawTree, this.blobsShaCache, true);
|
|
49
|
+
return tree;
|
|
50
|
+
}
|
|
51
|
+
async readBlob(blobId) {
|
|
52
|
+
const blob = await this.manager.getBlob(blobId);
|
|
53
|
+
this.blobsShaCache.set(blob.sha, "");
|
|
54
|
+
const bufferContent = (0, client_utils_1.stringToBuffer)(blob.content, blob.encoding);
|
|
55
|
+
return bufferContent;
|
|
56
|
+
}
|
|
57
|
+
async uploadSummaryWithContext(summary, context) {
|
|
58
|
+
if (context.referenceSequenceNumber === 0) {
|
|
59
|
+
if (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {
|
|
60
|
+
throw new Error("Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required");
|
|
61
|
+
}
|
|
62
|
+
await (0, localCreateDocument_1.createDocument)(this.localDeltaConnectionServer, this.resolvedUrl, summary);
|
|
63
|
+
const version = await this.getVersions(this.id, 1);
|
|
64
|
+
return version[0].id;
|
|
65
|
+
}
|
|
66
|
+
return this.summaryTreeUploadManager.writeSummaryTree(summary, context.ackHandle ?? "", "channel");
|
|
67
|
+
}
|
|
68
|
+
async createBlob(file) {
|
|
69
|
+
const uint8ArrayFile = new Uint8Array(file);
|
|
70
|
+
return this.manager
|
|
71
|
+
.createBlob((0, client_utils_1.Uint8ArrayToString)(uint8ArrayFile, "base64"), "base64")
|
|
72
|
+
.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));
|
|
73
|
+
}
|
|
74
|
+
async downloadSummary(handle) {
|
|
75
|
+
throw new Error("NOT IMPLEMENTED!");
|
|
76
|
+
}
|
|
77
|
+
async getPreviousFullSnapshot(parentHandle) {
|
|
78
|
+
return parentHandle
|
|
79
|
+
? this.getVersions(parentHandle, 1).then(async (versions) => {
|
|
80
|
+
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
81
|
+
this.blobsShaCache.clear();
|
|
82
|
+
return this.getSnapshotTree(versions[0]);
|
|
83
|
+
})
|
|
84
|
+
: undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.LocalDocumentStorageService = LocalDocumentStorageService;
|
|
88
|
+
//# sourceMappingURL=localDocumentStorageService.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localDocumentStorageService.cjs","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkF;AAclF,iEAAsE;AACtE,mFAIgD;AAEhD,mEAAuD;AAEvD,MAAM,eAAe,GAAG,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,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,CACpD,OAAO,EACP,OAAO,CAAC,SAAS,IAAI,EAAE,EACvB,SAAS,CACT,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO;aACjB,UAAU,CAAC,IAAA,iCAAkB,EAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;aAClE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD;AAlGD,kEAkGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { stringToBuffer, Uint8ArrayToString } from \"@fluid-internal/client-utils\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport { createDocument } from \"./localCreateDocument\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\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 readonly repositoryUrl: string = \"\";\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\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 = buildGitTreeHierarchy(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\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\treturn version[0].id;\n\t\t}\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, minTTLInSeconds }));\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,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDocumentStorageService, IDocumentStorageServicePolicies, IResolvedUrl, 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
|
+
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class LocalDocumentStorageService implements IDocumentStorageService {
|
|
13
|
+
private readonly id;
|
|
14
|
+
private readonly manager;
|
|
15
|
+
readonly policies: IDocumentStorageServicePolicies;
|
|
16
|
+
private readonly localDeltaConnectionServer?;
|
|
17
|
+
private readonly resolvedUrl?;
|
|
18
|
+
protected readonly blobsShaCache: Map<string, string>;
|
|
19
|
+
private readonly summaryTreeUploadManager;
|
|
20
|
+
readonly repositoryUrl: string;
|
|
21
|
+
constructor(id: string, manager: GitManager, policies: IDocumentStorageServicePolicies, localDeltaConnectionServer?: ILocalDeltaConnectionServer | undefined, resolvedUrl?: IResolvedUrl | undefined);
|
|
22
|
+
getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
|
|
23
|
+
getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null>;
|
|
24
|
+
readBlob(blobId: string): Promise<ArrayBufferLike>;
|
|
25
|
+
uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
26
|
+
createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
|
|
27
|
+
downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree>;
|
|
28
|
+
private getPreviousFullSnapshot;
|
|
29
|
+
}
|
|
30
|
+
//# 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,YAAY,EACZ,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;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAIlF;;GAEG;AACH,qBAAa,2BAA4B,YAAW,uBAAuB;IASzE,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;aACR,QAAQ,EAAE,+BAA+B;IACzD,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAV9B,SAAS,CAAC,QAAQ,CAAC,aAAa,sBAA6B;IAC7D,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAwB;IAEjE,SAAgB,aAAa,EAAE,MAAM,CAAM;gBAGzB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,UAAU,EACpB,QAAQ,EAAE,+BAA+B,EACxC,0BAA0B,CAAC,yCAA6B,EACxD,WAAW,CAAC,0BAAc;IAS/B,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;IAkBL,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"}
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.LocalResolver = exports.createLocalResolverCreateNewRequest = void 0;
|
|
8
8
|
const url_1 = require("url");
|
|
9
|
-
const
|
|
9
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
10
10
|
const driver_definitions_1 = require("@fluidframework/driver-definitions");
|
|
11
11
|
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
12
|
-
const auth_1 = require("./auth");
|
|
12
|
+
const auth_1 = require("./auth.cjs");
|
|
13
|
+
/**
|
|
14
|
+
* @alpha
|
|
15
|
+
*/
|
|
13
16
|
function createLocalResolverCreateNewRequest(documentId) {
|
|
14
17
|
const createNewRequest = {
|
|
15
18
|
url: `http://localhost:3000/${documentId}`,
|
|
@@ -23,6 +26,7 @@ exports.createLocalResolverCreateNewRequest = createLocalResolverCreateNewReques
|
|
|
23
26
|
/**
|
|
24
27
|
* Resolves URLs by providing fake URLs which succeed with the other
|
|
25
28
|
* related local classes.
|
|
29
|
+
* @alpha
|
|
26
30
|
*/
|
|
27
31
|
class LocalResolver {
|
|
28
32
|
constructor() {
|
|
@@ -34,6 +38,7 @@ class LocalResolver {
|
|
|
34
38
|
* token from constant test strings. The root of the URL is fake, but the
|
|
35
39
|
* remaining relative URL can still be parsed.
|
|
36
40
|
* @param request - request to handle
|
|
41
|
+
* @alpha
|
|
37
42
|
*/
|
|
38
43
|
async resolve(request) {
|
|
39
44
|
const parsedUrl = new URL(request.url);
|
|
@@ -58,13 +63,12 @@ class LocalResolver {
|
|
|
58
63
|
if (url.startsWith("/")) {
|
|
59
64
|
url = url.substr(1);
|
|
60
65
|
}
|
|
61
|
-
const
|
|
62
|
-
const parsedUrl = (0, url_1.parse)(fluidResolvedUrl.url);
|
|
66
|
+
const parsedUrl = (0, url_1.parse)(resolvedUrl.url);
|
|
63
67
|
if (parsedUrl.pathname === null) {
|
|
64
68
|
throw new Error("Url should contain tenant and docId!!");
|
|
65
69
|
}
|
|
66
70
|
const [, , documentId] = parsedUrl.pathname.split("/");
|
|
67
|
-
(0,
|
|
71
|
+
(0, core_utils_1.assert)(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
|
|
68
72
|
return `http://localhost:3000/${documentId}/${url}`;
|
|
69
73
|
}
|
|
70
74
|
createCreateNewRequest(documentId) {
|
|
@@ -72,4 +76,4 @@ class LocalResolver {
|
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
exports.LocalResolver = LocalResolver;
|
|
75
|
-
//# sourceMappingURL=localResolver.
|
|
79
|
+
//# sourceMappingURL=localResolver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localResolver.cjs","sourceRoot":"","sources":["../src/localResolver.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAC5B,2DAAoD;AAEpD,2EAA8F;AAC9F,+EAAiE;AACjE,qCAAuC;AAEvC;;GAEG;AACH,SAAgB,mCAAmC,CAAC,UAAkB;IACrE,MAAM,gBAAgB,GAAa;QAClC,GAAG,EAAE,yBAAyB,UAAU,EAAE;QAC1C,OAAO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,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,SAAS,GAAG,IAAA,WAAK,EAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACzC,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,IAAA,mBAAM,EAAC,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;AAnDD,sCAmDC","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/core-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { IResolvedUrl, IUrlResolver, DriverHeader } from \"@fluidframework/driver-definitions\";\nimport { ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { generateToken } from \"./auth\";\n\n/**\n * @alpha\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 * @alpha\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 * @alpha\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: IResolvedUrl = {\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 parsedUrl = parse(resolvedUrl.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"]}
|
package/dist/localResolver.d.ts
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { IRequest } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { IResolvedUrl, IUrlResolver } from "@fluidframework/driver-definitions";
|
|
7
|
+
/**
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
7
10
|
export declare function createLocalResolverCreateNewRequest(documentId: string): IRequest;
|
|
8
11
|
/**
|
|
9
12
|
* Resolves URLs by providing fake URLs which succeed with the other
|
|
10
13
|
* related local classes.
|
|
14
|
+
* @alpha
|
|
11
15
|
*/
|
|
12
16
|
export declare class LocalResolver implements IUrlResolver {
|
|
13
17
|
private readonly tenantId;
|
|
@@ -18,6 +22,7 @@ export declare class LocalResolver implements IUrlResolver {
|
|
|
18
22
|
* token from constant test strings. The root of the URL is fake, but the
|
|
19
23
|
* remaining relative URL can still be parsed.
|
|
20
24
|
* @param request - request to handle
|
|
25
|
+
* @alpha
|
|
21
26
|
*/
|
|
22
27
|
resolve(request: IRequest): Promise<IResolvedUrl>;
|
|
23
28
|
getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string>;
|
|
@@ -1 +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,
|
|
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,EAAE,YAAY,EAAE,YAAY,EAAgB,MAAM,oCAAoC,CAAC;AAI9F;;GAEG;AACH,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAQhF;AAED;;;;GAIG;AACH,qBAAa,aAAc,YAAW,YAAY;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;;IAIvC;;;;;;OAMG;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;IAerF,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;CAG3D"}
|