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