@fluidframework/local-driver 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229
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 +2 -2
- package/api-extractor.json +4 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +2 -2
- package/dist/auth.js.map +1 -1
- package/dist/localCreateDocument.d.ts +8 -0
- package/dist/localCreateDocument.d.ts.map +1 -0
- package/dist/localCreateDocument.js +29 -0
- package/dist/localCreateDocument.js.map +1 -0
- package/dist/localDeltaStorageService.d.ts.map +1 -1
- package/dist/localDeltaStorageService.js.map +1 -1
- package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/localDocumentDeltaConnection.js.map +1 -1
- package/dist/localDocumentService.d.ts.map +1 -1
- package/dist/localDocumentService.js +4 -1
- package/dist/localDocumentService.js.map +1 -1
- package/dist/localDocumentServiceFactory.d.ts +0 -1
- package/dist/localDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localDocumentServiceFactory.js +4 -20
- package/dist/localDocumentServiceFactory.js.map +1 -1
- package/dist/localDocumentStorageService.d.ts +5 -2
- package/dist/localDocumentStorageService.d.ts.map +1 -1
- package/dist/localDocumentStorageService.js +18 -4
- package/dist/localDocumentStorageService.js.map +1 -1
- package/dist/localResolver.d.ts.map +1 -1
- package/dist/localResolver.js.map +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/localSessionStorageDb.js +3 -2
- 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/localCreateDocument.d.ts +8 -0
- package/lib/localCreateDocument.d.ts.map +1 -0
- package/lib/localCreateDocument.js +25 -0
- package/lib/localCreateDocument.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 +43 -0
- package/lib/localDocumentServiceFactory.d.ts.map +1 -0
- package/lib/localDocumentServiceFactory.js +81 -0
- package/lib/localDocumentServiceFactory.js.map +1 -0
- package/lib/localDocumentStorageService.d.ts +27 -0
- package/lib/localDocumentStorageService.d.ts.map +1 -0
- package/lib/localDocumentStorageService.js +85 -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 +59 -49
- package/prettier.config.cjs +1 -1
- package/src/auth.ts +35 -29
- package/src/localCreateDocument.ts +48 -0
- package/src/localDeltaStorageService.ts +26 -29
- package/src/localDocumentDeltaConnection.ts +89 -85
- package/src/localDocumentService.ts +108 -95
- package/src/localDocumentServiceFactory.ts +94 -122
- package/src/localDocumentStorageService.ts +35 -11
- package/src/localResolver.ts +55 -55
- package/src/localSessionStorageDb.ts +270 -263
- package/src/packageVersion.ts +1 -1
- package/tsconfig.esnext.json +7 -0
- package/tsconfig.json +9 -13
|
@@ -5,146 +5,118 @@
|
|
|
5
5
|
|
|
6
6
|
import { parse } from "url";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
IDocumentService,
|
|
9
|
+
IDocumentServiceFactory,
|
|
10
|
+
IDocumentServicePolicies,
|
|
11
|
+
IResolvedUrl,
|
|
12
12
|
} from "@fluidframework/driver-definitions";
|
|
13
13
|
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
|
|
14
14
|
import { DefaultTokenProvider } from "@fluidframework/routerlicious-driver";
|
|
15
|
-
import { ILocalDeltaConnectionServer
|
|
16
|
-
import {
|
|
17
|
-
ensureFluidResolvedUrl,
|
|
18
|
-
getDocAttributesFromProtocolSummary,
|
|
19
|
-
getQuorumValuesFromProtocolSummary,
|
|
20
|
-
} from "@fluidframework/driver-utils";
|
|
15
|
+
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
16
|
+
import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils";
|
|
21
17
|
import { ISummaryTree, NackErrorType } from "@fluidframework/protocol-definitions";
|
|
22
|
-
import { defaultHash } from "@fluidframework/server-services-client";
|
|
23
18
|
import { LocalDocumentDeltaConnection } from "./localDocumentDeltaConnection";
|
|
24
19
|
import { createLocalDocumentService } from "./localDocumentService";
|
|
20
|
+
import { createDocument } from "./localCreateDocument";
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* Implementation of document service factory for local use.
|
|
28
24
|
*/
|
|
29
25
|
export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> = new Map();
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @param localDeltaConnectionServer - delta connection server for ops
|
|
37
|
-
*/
|
|
38
|
-
constructor(
|
|
39
|
-
private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
|
|
40
|
-
private readonly policies?: IDocumentServicePolicies,
|
|
41
|
-
private readonly innerDocumentService?: IDocumentService) { }
|
|
26
|
+
// A map of clientId to LocalDocumentService.
|
|
27
|
+
private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> =
|
|
28
|
+
new Map();
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
52
|
-
}
|
|
53
|
-
const pathName = new URL(resolvedUrl.url).pathname;
|
|
54
|
-
const pathArr = pathName.split("/");
|
|
55
|
-
const tenantId = pathArr[pathArr.length - 2];
|
|
56
|
-
const id = pathArr[pathArr.length - 1];
|
|
57
|
-
if (!this.localDeltaConnectionServer) {
|
|
58
|
-
throw new Error("Provide the localDeltaConnectionServer!!");
|
|
59
|
-
}
|
|
60
|
-
const documentStorage = (this.localDeltaConnectionServer as LocalDeltaConnectionServer).documentStorage;
|
|
30
|
+
/**
|
|
31
|
+
* @param localDeltaConnectionServer - delta connection server for ops
|
|
32
|
+
*/
|
|
33
|
+
constructor(
|
|
34
|
+
private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
|
|
35
|
+
private readonly policies?: IDocumentServicePolicies,
|
|
36
|
+
private readonly innerDocumentService?: IDocumentService,
|
|
37
|
+
) {}
|
|
61
38
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
resolvedUrl.endpoints.ordererUrl ?? "",
|
|
78
|
-
resolvedUrl.endpoints.storageUrl ?? "",
|
|
79
|
-
resolvedUrl.endpoints.deltaStorageUrl ?? "",
|
|
80
|
-
quorumValues,
|
|
81
|
-
false, /* enableDiscovery */
|
|
82
|
-
);
|
|
83
|
-
return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
|
|
84
|
-
}
|
|
39
|
+
public async createContainer(
|
|
40
|
+
createNewSummary: ISummaryTree | undefined,
|
|
41
|
+
resolvedUrl: IResolvedUrl,
|
|
42
|
+
logger?: ITelemetryBaseLogger,
|
|
43
|
+
clientIsSummarizer?: boolean,
|
|
44
|
+
): Promise<IDocumentService> {
|
|
45
|
+
if (!this.localDeltaConnectionServer) {
|
|
46
|
+
throw new Error("Provide the localDeltaConnectionServer!!");
|
|
47
|
+
}
|
|
48
|
+
if (createNewSummary !== undefined) {
|
|
49
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
50
|
+
await createDocument(this.localDeltaConnectionServer, resolvedUrl, createNewSummary);
|
|
51
|
+
}
|
|
52
|
+
return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
|
|
53
|
+
}
|
|
85
54
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Creates and returns a document service for testing using the given resolved
|
|
57
|
+
* URL for the tenant ID, document ID, and token.
|
|
58
|
+
* @param resolvedUrl - resolved URL of document
|
|
59
|
+
*/
|
|
60
|
+
public async createDocumentService(
|
|
61
|
+
resolvedUrl: IResolvedUrl,
|
|
62
|
+
logger?: ITelemetryBaseLogger,
|
|
63
|
+
clientIsSummarizer?: boolean,
|
|
64
|
+
): Promise<IDocumentService> {
|
|
65
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
97
66
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
67
|
+
const parsedUrl = parse(resolvedUrl.url);
|
|
68
|
+
const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : [];
|
|
69
|
+
if (!documentId || !tenantId) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
103
74
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
75
|
+
const fluidResolvedUrl = resolvedUrl;
|
|
76
|
+
const jwtToken = fluidResolvedUrl.tokens.jwt;
|
|
77
|
+
if (!jwtToken) {
|
|
78
|
+
throw new Error(`Token was not provided.`);
|
|
79
|
+
}
|
|
109
80
|
|
|
110
|
-
|
|
81
|
+
const tokenProvider = new DefaultTokenProvider(jwtToken);
|
|
111
82
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
83
|
+
return createLocalDocumentService(
|
|
84
|
+
resolvedUrl,
|
|
85
|
+
this.localDeltaConnectionServer,
|
|
86
|
+
tokenProvider,
|
|
87
|
+
tenantId,
|
|
88
|
+
documentId,
|
|
89
|
+
this.documentDeltaConnectionsMap,
|
|
90
|
+
this.policies,
|
|
91
|
+
this.innerDocumentService,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
122
94
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Gets the document delta connection for the clientId and asks it to disconnect the client.
|
|
97
|
+
* @param clientId - The ID of the client to be disconnected.
|
|
98
|
+
* @param disconnectReason - The reason of the disconnection.
|
|
99
|
+
*/
|
|
100
|
+
public disconnectClient(clientId: string, disconnectReason: string) {
|
|
101
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
102
|
+
if (documentDeltaConnection === undefined) {
|
|
103
|
+
throw new Error(`No client with the id: ${clientId}`);
|
|
104
|
+
}
|
|
105
|
+
documentDeltaConnection.disconnectClient(disconnectReason);
|
|
106
|
+
}
|
|
135
107
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Gets the document delta connection for the clientId and asks it to nack the client.
|
|
110
|
+
* @param clientId - The ID of the client to be Nack'd.
|
|
111
|
+
* @param code - An error code number that represents the error. It will be a valid HTTP error code.
|
|
112
|
+
* @param type - Type of the Nack.
|
|
113
|
+
* @param message - A message about the nack for debugging/logging/telemetry purposes.
|
|
114
|
+
*/
|
|
115
|
+
public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {
|
|
116
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
117
|
+
if (documentDeltaConnection === undefined) {
|
|
118
|
+
throw new Error(`No client with the id: ${clientId}`);
|
|
119
|
+
}
|
|
120
|
+
documentDeltaConnection.nackClient(code, type, message);
|
|
121
|
+
}
|
|
150
122
|
}
|
|
@@ -7,6 +7,7 @@ import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils
|
|
|
7
7
|
import {
|
|
8
8
|
IDocumentStorageService,
|
|
9
9
|
IDocumentStorageServicePolicies,
|
|
10
|
+
IResolvedUrl,
|
|
10
11
|
ISummaryContext,
|
|
11
12
|
} from "@fluidframework/driver-definitions";
|
|
12
13
|
import {
|
|
@@ -17,7 +18,14 @@ import {
|
|
|
17
18
|
IVersion,
|
|
18
19
|
} from "@fluidframework/protocol-definitions";
|
|
19
20
|
import { buildHierarchy } from "@fluidframework/protocol-base";
|
|
20
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
GitManager,
|
|
23
|
+
ISummaryUploadManager,
|
|
24
|
+
SummaryTreeUploadManager,
|
|
25
|
+
} from "@fluidframework/server-services-client";
|
|
26
|
+
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
27
|
+
import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils";
|
|
28
|
+
import { createDocument } from "./localCreateDocument";
|
|
21
29
|
|
|
22
30
|
export class LocalDocumentStorageService implements IDocumentStorageService {
|
|
23
31
|
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
@@ -32,7 +40,9 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
|
|
|
32
40
|
constructor(
|
|
33
41
|
private readonly id: string,
|
|
34
42
|
private readonly manager: GitManager,
|
|
35
|
-
public readonly policies: IDocumentStorageServicePolicies
|
|
43
|
+
public readonly policies: IDocumentStorageServicePolicies,
|
|
44
|
+
private readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,
|
|
45
|
+
private readonly resolvedUrl?: IResolvedUrl,
|
|
36
46
|
) {
|
|
37
47
|
this.summaryTreeUploadManager = new SummaryTreeUploadManager(
|
|
38
48
|
manager,
|
|
@@ -74,7 +84,21 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
|
|
|
74
84
|
return bufferContent;
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
public async uploadSummaryWithContext(
|
|
87
|
+
public async uploadSummaryWithContext(
|
|
88
|
+
summary: ISummaryTree,
|
|
89
|
+
context: ISummaryContext,
|
|
90
|
+
): Promise<string> {
|
|
91
|
+
if (context.referenceSequenceNumber === 0) {
|
|
92
|
+
if (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required",
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
ensureFluidResolvedUrl(this.resolvedUrl);
|
|
98
|
+
await createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);
|
|
99
|
+
const version = await this.getVersions(this.id, 1);
|
|
100
|
+
return version[0].id;
|
|
101
|
+
}
|
|
78
102
|
return this.summaryTreeUploadManager.writeSummaryTree(
|
|
79
103
|
summary,
|
|
80
104
|
context.ackHandle ?? "",
|
|
@@ -84,24 +108,24 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
|
|
|
84
108
|
|
|
85
109
|
public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
|
|
86
110
|
const uint8ArrayFile = new Uint8Array(file);
|
|
87
|
-
return this.manager
|
|
88
|
-
Uint8ArrayToString(
|
|
89
|
-
|
|
90
|
-
"base64").then((r) => ({ id: r.sha, url: r.url }));
|
|
111
|
+
return this.manager
|
|
112
|
+
.createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
|
|
113
|
+
.then((r) => ({ id: r.sha, url: r.url }));
|
|
91
114
|
}
|
|
92
115
|
|
|
93
116
|
public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
|
|
94
117
|
throw new Error("NOT IMPLEMENTED!");
|
|
95
118
|
}
|
|
96
119
|
|
|
97
|
-
private async getPreviousFullSnapshot(
|
|
120
|
+
private async getPreviousFullSnapshot(
|
|
121
|
+
parentHandle: string,
|
|
122
|
+
): Promise<ISnapshotTreeEx | null | undefined> {
|
|
98
123
|
return parentHandle
|
|
99
|
-
? this.getVersions(parentHandle, 1)
|
|
100
|
-
.then(async (versions) => {
|
|
124
|
+
? this.getVersions(parentHandle, 1).then(async (versions) => {
|
|
101
125
|
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
102
126
|
this.blobsShaCache.clear();
|
|
103
127
|
return this.getSnapshotTree(versions[0]);
|
|
104
|
-
|
|
128
|
+
})
|
|
105
129
|
: undefined;
|
|
106
130
|
}
|
|
107
131
|
}
|
package/src/localResolver.ts
CHANGED
|
@@ -7,22 +7,22 @@ import { parse } from "url";
|
|
|
7
7
|
import { assert } from "@fluidframework/common-utils";
|
|
8
8
|
import { IRequest } from "@fluidframework/core-interfaces";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
IFluidResolvedUrl,
|
|
11
|
+
IResolvedUrl,
|
|
12
|
+
IUrlResolver,
|
|
13
|
+
DriverHeader,
|
|
14
14
|
} from "@fluidframework/driver-definitions";
|
|
15
15
|
import { ScopeType } from "@fluidframework/protocol-definitions";
|
|
16
16
|
import { generateToken } from "./auth";
|
|
17
17
|
|
|
18
18
|
export function createLocalResolverCreateNewRequest(documentId: string): IRequest {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const createNewRequest: IRequest = {
|
|
20
|
+
url: `http://localhost:3000/${documentId}`,
|
|
21
|
+
headers: {
|
|
22
|
+
[DriverHeader.createNew]: true,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return createNewRequest;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -30,55 +30,55 @@ export function createLocalResolverCreateNewRequest(documentId: string): IReques
|
|
|
30
30
|
* related local classes.
|
|
31
31
|
*/
|
|
32
32
|
export class LocalResolver implements IUrlResolver {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
private readonly tenantId = "tenantId";
|
|
34
|
+
private readonly tokenKey = "tokenKey";
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
constructor() {}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Resolves URL requests by providing fake URLs with an actually generated
|
|
40
|
+
* token from constant test strings. The root of the URL is fake, but the
|
|
41
|
+
* remaining relative URL can still be parsed.
|
|
42
|
+
* @param request - request to handle
|
|
43
|
+
*/
|
|
44
|
+
public async resolve(request: IRequest): Promise<IResolvedUrl> {
|
|
45
|
+
const parsedUrl = new URL(request.url);
|
|
46
|
+
const fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;
|
|
47
|
+
const documentId = fullPath.split("/")[0];
|
|
48
|
+
const scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];
|
|
49
|
+
const resolved: IFluidResolvedUrl = {
|
|
50
|
+
endpoints: {
|
|
51
|
+
deltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,
|
|
52
|
+
ordererUrl: "http://localhost:3000",
|
|
53
|
+
storageUrl: `http://localhost:3000/repos/${this.tenantId}`,
|
|
54
|
+
},
|
|
55
|
+
id: documentId,
|
|
56
|
+
tokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },
|
|
57
|
+
type: "fluid",
|
|
58
|
+
url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,
|
|
59
|
+
};
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
return resolved;
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
public async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {
|
|
65
|
+
let url = relativeUrl;
|
|
66
|
+
if (url.startsWith("/")) {
|
|
67
|
+
url = url.substr(1);
|
|
68
|
+
}
|
|
69
|
+
const fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
const parsedUrl = parse(fluidResolvedUrl.url);
|
|
72
|
+
if (parsedUrl.pathname === null) {
|
|
73
|
+
throw new Error("Url should contain tenant and docId!!");
|
|
74
|
+
}
|
|
75
|
+
const [, , documentId] = parsedUrl.pathname.split("/");
|
|
76
|
+
assert(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return `http://localhost:3000/${documentId}/${url}`;
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
public createCreateNewRequest(documentId: string): IRequest {
|
|
82
|
+
return createLocalResolverCreateNewRequest(documentId);
|
|
83
|
+
}
|
|
84
84
|
}
|