@fluidframework/routerlicious-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 +10 -12
- package/.mocharc.js +2 -2
- package/README.md +1 -1
- package/api-extractor.json +2 -2
- package/dist/cache.d.ts +3 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +6 -4
- package/dist/cache.js.map +1 -1
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +4 -2
- package/dist/createNewUtils.js.map +1 -1
- package/dist/defaultTokenProvider.d.ts.map +1 -1
- package/dist/defaultTokenProvider.js.map +1 -1
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js.map +1 -1
- package/dist/deltaStorageService.d.ts.map +1 -1
- package/dist/deltaStorageService.js +4 -1
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentDeltaConnection.d.ts.map +1 -1
- package/dist/documentDeltaConnection.js.map +1 -1
- package/dist/documentService.d.ts +4 -2
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +28 -41
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts +0 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +26 -13
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +1 -1
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +8 -6
- package/dist/documentStorageService.js.map +1 -1
- package/dist/errorUtils.d.ts +11 -3
- package/dist/errorUtils.d.ts.map +1 -1
- package/dist/errorUtils.js +19 -6
- package/dist/errorUtils.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/mapWithExpiration.d.ts +34 -0
- package/dist/mapWithExpiration.d.ts.map +1 -0
- package/dist/mapWithExpiration.js +105 -0
- package/dist/mapWithExpiration.js.map +1 -0
- package/dist/nullBlobStorageService.d.ts.map +1 -1
- package/dist/nullBlobStorageService.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/dist/policies.d.ts.map +1 -1
- package/dist/policies.js.map +1 -1
- package/dist/restWrapper.d.ts +8 -5
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +38 -44
- package/dist/restWrapper.js.map +1 -1
- package/dist/retriableGitManager.d.ts.map +1 -1
- package/dist/retriableGitManager.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +9 -5
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/tokens.d.ts +24 -7
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js.map +1 -1
- package/dist/treeUtils.d.ts +51 -0
- package/dist/treeUtils.d.ts.map +1 -0
- package/dist/treeUtils.js +85 -0
- package/dist/treeUtils.js.map +1 -0
- package/dist/urlUtils.d.ts.map +1 -1
- package/dist/urlUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +30 -17
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/cache.d.ts +3 -0
- package/lib/cache.d.ts.map +1 -1
- package/lib/cache.js +6 -4
- package/lib/cache.js.map +1 -1
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +4 -2
- package/lib/createNewUtils.js.map +1 -1
- package/lib/defaultTokenProvider.d.ts.map +1 -1
- package/lib/defaultTokenProvider.js.map +1 -1
- package/lib/definitions.d.ts.map +1 -1
- package/lib/definitions.js.map +1 -1
- package/lib/deltaStorageService.d.ts.map +1 -1
- package/lib/deltaStorageService.js +4 -1
- package/lib/deltaStorageService.js.map +1 -1
- package/lib/documentDeltaConnection.d.ts.map +1 -1
- package/lib/documentDeltaConnection.js.map +1 -1
- package/lib/documentService.d.ts +4 -2
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +30 -24
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts +0 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +27 -14
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts +1 -1
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +9 -7
- package/lib/documentStorageService.js.map +1 -1
- package/lib/errorUtils.d.ts +11 -3
- package/lib/errorUtils.d.ts.map +1 -1
- package/lib/errorUtils.js +18 -5
- package/lib/errorUtils.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/mapWithExpiration.d.ts +34 -0
- package/lib/mapWithExpiration.d.ts.map +1 -0
- package/lib/mapWithExpiration.js +101 -0
- package/lib/mapWithExpiration.js.map +1 -0
- package/lib/nullBlobStorageService.d.ts.map +1 -1
- package/lib/nullBlobStorageService.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/policies.d.ts.map +1 -1
- package/lib/policies.js.map +1 -1
- package/lib/restWrapper.d.ts +8 -5
- package/lib/restWrapper.d.ts.map +1 -1
- package/lib/restWrapper.js +38 -44
- package/lib/restWrapper.js.map +1 -1
- package/lib/retriableGitManager.d.ts.map +1 -1
- package/lib/retriableGitManager.js.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +10 -6
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/tokens.d.ts +24 -7
- package/lib/tokens.d.ts.map +1 -1
- package/lib/tokens.js.map +1 -1
- package/lib/treeUtils.d.ts +51 -0
- package/lib/treeUtils.d.ts.map +1 -0
- package/lib/treeUtils.js +80 -0
- package/lib/treeUtils.js.map +1 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +30 -17
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +55 -52
- package/prettier.config.cjs +1 -1
- package/src/cache.ts +21 -14
- package/src/createNewUtils.ts +24 -22
- package/src/defaultTokenProvider.ts +13 -15
- package/src/definitions.ts +2 -2
- package/src/deltaStorageService.ts +99 -95
- package/src/documentDeltaConnection.ts +53 -47
- package/src/documentService.ts +260 -241
- package/src/documentServiceFactory.ts +268 -237
- package/src/documentStorageService.ts +87 -83
- package/src/errorUtils.ts +91 -76
- package/src/index.ts +7 -1
- package/src/mapWithExpiration.ts +124 -0
- package/src/nullBlobStorageService.ts +24 -21
- package/src/packageVersion.ts +1 -1
- package/src/policies.ts +44 -44
- package/src/restWrapper.ts +270 -208
- package/src/retriableGitManager.ts +152 -151
- package/src/shreddedSummaryDocumentStorageService.ts +202 -194
- package/src/tokens.ts +69 -44
- package/src/treeUtils.ts +107 -0
- package/src/urlUtils.ts +26 -23
- package/src/wholeSummaryDocumentStorageService.ts +248 -228
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
|
@@ -4,27 +4,24 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
|
+
import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
IDocumentStorageService,
|
|
13
|
-
ISummaryContext,
|
|
14
|
-
IDocumentStorageServicePolicies,
|
|
9
|
+
IDocumentStorageService,
|
|
10
|
+
ISummaryContext,
|
|
11
|
+
IDocumentStorageServicePolicies,
|
|
15
12
|
} from "@fluidframework/driver-definitions";
|
|
16
13
|
import { buildHierarchy } from "@fluidframework/protocol-base";
|
|
17
14
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
ICreateBlobResponse,
|
|
16
|
+
ISnapshotTreeEx,
|
|
17
|
+
ISummaryHandle,
|
|
18
|
+
ISummaryTree,
|
|
19
|
+
IVersion,
|
|
23
20
|
} from "@fluidframework/protocol-definitions";
|
|
24
21
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
GitManager,
|
|
23
|
+
ISummaryUploadManager,
|
|
24
|
+
SummaryTreeUploadManager,
|
|
28
25
|
} from "@fluidframework/server-services-client";
|
|
29
26
|
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
30
27
|
import { IRouterliciousDriverPolicies } from "./policies";
|
|
@@ -40,183 +37,194 @@ const isNode = typeof window === "undefined";
|
|
|
40
37
|
* Downloads summaries piece-by-piece on-demand, or up-front when prefetch is enabled.
|
|
41
38
|
*/
|
|
42
39
|
export class ShreddedSummaryDocumentStorageService implements IDocumentStorageService {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
40
|
+
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
41
|
+
// empty strings as values.
|
|
42
|
+
protected readonly blobsShaCache = new Map<string, string>();
|
|
43
|
+
private readonly blobCache: ICache<ArrayBufferLike> | undefined;
|
|
44
|
+
private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion> | undefined;
|
|
45
|
+
|
|
46
|
+
public get repositoryUrl(): string {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private async getSummaryUploadManager(): Promise<ISummaryUploadManager> {
|
|
51
|
+
const manager = await this.getStorageManager();
|
|
52
|
+
return new SummaryTreeUploadManager(
|
|
53
|
+
new RetriableGitManager(manager, this.logger),
|
|
54
|
+
this.blobsShaCache,
|
|
55
|
+
this.getPreviousFullSnapshot.bind(this),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
protected readonly id: string,
|
|
61
|
+
protected readonly manager: GitManager,
|
|
62
|
+
protected readonly logger: ITelemetryLogger,
|
|
63
|
+
public readonly policies: IDocumentStorageServicePolicies,
|
|
64
|
+
driverPolicies?: IRouterliciousDriverPolicies,
|
|
65
|
+
blobCache?: ICache<ArrayBufferLike>,
|
|
66
|
+
snapshotTreeCache?: ICache<ISnapshotTreeVersion>,
|
|
67
|
+
private readonly getStorageManager: (
|
|
68
|
+
disableCache?: boolean,
|
|
69
|
+
) => Promise<GitManager> = async () => this.manager,
|
|
70
|
+
) {
|
|
71
|
+
if (driverPolicies?.enableRestLess === true || isNode) {
|
|
72
|
+
this.blobCache = blobCache ?? new InMemoryCache();
|
|
73
|
+
this.snapshotTreeCache = snapshotTreeCache ?? new InMemoryCache();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {
|
|
78
|
+
const id = versionId ? versionId : this.id;
|
|
79
|
+
const commits = await PerformanceEvent.timedExecAsync(
|
|
80
|
+
this.logger,
|
|
81
|
+
{
|
|
82
|
+
eventName: "getVersions",
|
|
83
|
+
versionId: id,
|
|
84
|
+
count,
|
|
85
|
+
},
|
|
86
|
+
async () => {
|
|
87
|
+
const manager = await this.getStorageManager();
|
|
88
|
+
return manager.getCommits(id, count);
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
return commits.map((commit) => ({
|
|
92
|
+
date: commit.commit.author.date,
|
|
93
|
+
id: commit.sha,
|
|
94
|
+
treeId: commit.commit.tree.sha,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {
|
|
99
|
+
let requestVersion = version;
|
|
100
|
+
if (!requestVersion) {
|
|
101
|
+
const versions = await this.getVersions(this.id, 1);
|
|
102
|
+
if (versions.length === 0) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
requestVersion = versions[0];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const cachedSnapshotTree = await this.snapshotTreeCache?.get(
|
|
110
|
+
this.getCacheKey(requestVersion.treeId),
|
|
111
|
+
);
|
|
112
|
+
if (cachedSnapshotTree) {
|
|
113
|
+
return cachedSnapshotTree.snapshotTree as ISnapshotTreeEx;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const rawTree = await PerformanceEvent.timedExecAsync(
|
|
117
|
+
this.logger,
|
|
118
|
+
{
|
|
119
|
+
eventName: "getSnapshotTree",
|
|
120
|
+
treeId: requestVersion.treeId,
|
|
121
|
+
},
|
|
122
|
+
async (event) => {
|
|
123
|
+
const manager = await this.getStorageManager();
|
|
124
|
+
const response = await manager.getTree(requestVersion!.treeId);
|
|
125
|
+
event.end({
|
|
126
|
+
size: response.tree.length,
|
|
127
|
+
});
|
|
128
|
+
return response;
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
const tree = buildHierarchy(rawTree, this.blobsShaCache, true);
|
|
132
|
+
await this.snapshotTreeCache?.put(this.getCacheKey(tree.id), {
|
|
133
|
+
id: requestVersion.id,
|
|
134
|
+
snapshotTree: tree,
|
|
135
|
+
});
|
|
136
|
+
return tree;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async readBlob(blobId: string): Promise<ArrayBufferLike> {
|
|
140
|
+
const cachedBlob = await this.blobCache?.get(this.getCacheKey(blobId));
|
|
141
|
+
if (cachedBlob) {
|
|
142
|
+
return cachedBlob;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const value = await PerformanceEvent.timedExecAsync(
|
|
146
|
+
this.logger,
|
|
147
|
+
{
|
|
148
|
+
eventName: "readBlob",
|
|
149
|
+
blobId,
|
|
150
|
+
},
|
|
151
|
+
async (event) => {
|
|
152
|
+
const manager = await this.getStorageManager();
|
|
153
|
+
const response = await manager.getBlob(blobId);
|
|
154
|
+
event.end({
|
|
155
|
+
size: response.size,
|
|
156
|
+
});
|
|
157
|
+
return response;
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
this.blobsShaCache.set(value.sha, "");
|
|
161
|
+
const bufferContent = stringToBuffer(value.content, value.encoding);
|
|
162
|
+
await this.blobCache?.put(this.getCacheKey(value.sha), bufferContent);
|
|
163
|
+
return bufferContent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public async uploadSummaryWithContext(
|
|
167
|
+
summary: ISummaryTree,
|
|
168
|
+
context: ISummaryContext,
|
|
169
|
+
): Promise<string> {
|
|
170
|
+
const summaryHandle = await PerformanceEvent.timedExecAsync(
|
|
171
|
+
this.logger,
|
|
172
|
+
{
|
|
173
|
+
eventName: "uploadSummaryWithContext",
|
|
174
|
+
proposalHandle: context.proposalHandle,
|
|
175
|
+
ackHandle: context.ackHandle,
|
|
176
|
+
referenceSequenceNumber: context.referenceSequenceNumber,
|
|
177
|
+
},
|
|
178
|
+
async () => {
|
|
179
|
+
const summaryUploadManager = await this.getSummaryUploadManager();
|
|
180
|
+
return summaryUploadManager.writeSummaryTree(
|
|
181
|
+
summary,
|
|
182
|
+
context.ackHandle ?? "",
|
|
183
|
+
"channel",
|
|
184
|
+
);
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
return summaryHandle;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
|
|
191
|
+
throw new Error("NOT IMPLEMENTED!");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
|
|
195
|
+
const uint8ArrayFile = new Uint8Array(file);
|
|
196
|
+
return PerformanceEvent.timedExecAsync(
|
|
197
|
+
this.logger,
|
|
198
|
+
{
|
|
199
|
+
eventName: "createBlob",
|
|
200
|
+
size: uint8ArrayFile.length,
|
|
201
|
+
},
|
|
202
|
+
async (event) => {
|
|
203
|
+
const manager = await this.getStorageManager();
|
|
204
|
+
const response = await manager
|
|
205
|
+
.createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
|
|
206
|
+
.then((r) => ({ id: r.sha, url: r.url }));
|
|
207
|
+
event.end({
|
|
208
|
+
blobId: response.id,
|
|
209
|
+
});
|
|
210
|
+
return response;
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private async getPreviousFullSnapshot(
|
|
216
|
+
parentHandle: string,
|
|
217
|
+
): Promise<ISnapshotTreeEx | null | undefined> {
|
|
218
|
+
return parentHandle
|
|
219
|
+
? this.getVersions(parentHandle, 1).then(async (versions) => {
|
|
220
|
+
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
221
|
+
this.blobsShaCache.clear();
|
|
222
|
+
return this.getSnapshotTree(versions[0]);
|
|
223
|
+
})
|
|
224
|
+
: undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private getCacheKey(blobId: string): string {
|
|
228
|
+
return `${this.id}:${blobId}`;
|
|
229
|
+
}
|
|
222
230
|
}
|
package/src/tokens.ts
CHANGED
|
@@ -6,23 +6,28 @@
|
|
|
6
6
|
import { ITokenClaims } from "@fluidframework/protocol-definitions";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Abstracts the discovery of claims contained within a token.
|
|
10
10
|
*/
|
|
11
11
|
export interface ITokenService {
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the {@link @fluidframework/protocol-definitions#ITokenClaims | token claims} from the provided
|
|
14
|
+
* {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} string representation.
|
|
15
|
+
*/
|
|
16
|
+
extractClaims(token: string): ITokenClaims;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export interface ITokenResponse {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} value.
|
|
22
|
+
*/
|
|
23
|
+
jwt: string;
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* A flag indicating whether token was obtained from local cache.
|
|
27
|
+
*
|
|
28
|
+
* @remarks `undefined` indicates that the source of the token could not be determined.
|
|
29
|
+
*/
|
|
30
|
+
fromCache?: boolean;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -30,39 +35,59 @@ export interface ITokenResponse {
|
|
|
30
35
|
* The hosting application is responsible for providing an implementation.
|
|
31
36
|
*/
|
|
32
37
|
export interface ITokenProvider {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Fetches the orderer token from host.
|
|
40
|
+
*
|
|
41
|
+
* @param tenantId - Tenant ID.
|
|
42
|
+
* @param documentId - Optional. Document ID is only required for document-scoped requests.
|
|
43
|
+
* @param refresh - Optional flag indicating whether token fetch must bypass local cache.
|
|
44
|
+
* This likely indicates that some previous request failed authorization due to an expired token,
|
|
45
|
+
* and so a fresh token is required.
|
|
46
|
+
*
|
|
47
|
+
* Default: `false`.
|
|
48
|
+
*
|
|
49
|
+
* NOTE: This parameter will be made required in the future.
|
|
50
|
+
*/
|
|
51
|
+
fetchOrdererToken(
|
|
52
|
+
tenantId: string,
|
|
53
|
+
documentId?: string,
|
|
54
|
+
refresh?: boolean,
|
|
55
|
+
): Promise<ITokenResponse>;
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Fetches the storage token from host.
|
|
59
|
+
*
|
|
60
|
+
* @param tenantId - Tenant ID.
|
|
61
|
+
* @param documentId - Document ID.
|
|
62
|
+
* @param refresh - Optional flag indicating whether token fetch must bypass local cache.
|
|
63
|
+
* This likely indicates that some previous request failed authorization due to an expired token,
|
|
64
|
+
* and so a fresh token is required.
|
|
65
|
+
*
|
|
66
|
+
* Default: `false`.
|
|
67
|
+
*
|
|
68
|
+
* NOTE: This parameter will be made required in the future.
|
|
69
|
+
*/
|
|
70
|
+
fetchStorageToken(
|
|
71
|
+
tenantId: string,
|
|
72
|
+
documentId: string,
|
|
73
|
+
refresh?: boolean,
|
|
74
|
+
): Promise<ITokenResponse>;
|
|
52
75
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
/**
|
|
77
|
+
* A callback triggered directly after creating the document. In this callback the client has the opportunity, to
|
|
78
|
+
* verify against an authorization service, if the user who claims to create the document is the same user who
|
|
79
|
+
* created it.
|
|
80
|
+
*
|
|
81
|
+
* @remarks Notes:
|
|
82
|
+
*
|
|
83
|
+
* * Using the callback may have performance impact on the document creation process.
|
|
84
|
+
*
|
|
85
|
+
* * Any exceptions thrown in the callback would fail the creation workflow
|
|
86
|
+
* (see {@link RouterliciousDocumentServiceFactory.createContainer} for more details).
|
|
87
|
+
*
|
|
88
|
+
* @param documentId - Document ID.
|
|
89
|
+
* @param creationToken - A special token that doesn't provide any kind of access, but it has the user's payload
|
|
90
|
+
* and document id. It can be used to validate the identity of the document creator.
|
|
91
|
+
*/
|
|
92
|
+
documentPostCreateCallback?(documentId: string, creationToken: string): Promise<void>;
|
|
68
93
|
}
|
package/src/treeUtils.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { assert, IsoBuffer } from "@fluidframework/common-utils";
|
|
7
|
+
import {
|
|
8
|
+
SummaryType,
|
|
9
|
+
ISnapshotTree,
|
|
10
|
+
ISummaryTree,
|
|
11
|
+
SummaryObject,
|
|
12
|
+
} from "@fluidframework/protocol-definitions";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Summary tree assembler props
|
|
16
|
+
*/
|
|
17
|
+
export interface ISummaryTreeAssemblerProps {
|
|
18
|
+
/**
|
|
19
|
+
* Indicates that this tree is unreferenced. If this is not present, the tree is considered referenced.
|
|
20
|
+
*/
|
|
21
|
+
unreferenced?: true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Summary tree assembler (without stats collection).
|
|
26
|
+
*/
|
|
27
|
+
export class SummaryTreeAssembler {
|
|
28
|
+
private attachmentCounter: number = 0;
|
|
29
|
+
private readonly summaryTree: { [path: string]: SummaryObject } = {};
|
|
30
|
+
|
|
31
|
+
constructor(private readonly props?: ISummaryTreeAssemblerProps) {}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get final summary
|
|
35
|
+
*/
|
|
36
|
+
public get summary(): ISummaryTree {
|
|
37
|
+
return {
|
|
38
|
+
type: SummaryType.Tree,
|
|
39
|
+
tree: { ...this.summaryTree },
|
|
40
|
+
unreferenced: this.props?.unreferenced,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Add blob to summary
|
|
46
|
+
*/
|
|
47
|
+
public addBlob(key: string, content: string | Uint8Array): void {
|
|
48
|
+
this.summaryTree[key] = {
|
|
49
|
+
type: SummaryType.Blob,
|
|
50
|
+
content,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Add handle to summary
|
|
56
|
+
*/
|
|
57
|
+
public addHandle(
|
|
58
|
+
key: string,
|
|
59
|
+
handleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment,
|
|
60
|
+
handle: string,
|
|
61
|
+
): void {
|
|
62
|
+
this.summaryTree[key] = {
|
|
63
|
+
type: SummaryType.Handle,
|
|
64
|
+
handleType,
|
|
65
|
+
handle,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Add tree to summary
|
|
71
|
+
*/
|
|
72
|
+
public addTree(key: string, summary: ISummaryTree): void {
|
|
73
|
+
this.summaryTree[key] = summary;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Add attachment to summary
|
|
78
|
+
*/
|
|
79
|
+
public addAttachment(id: string) {
|
|
80
|
+
this.summaryTree[this.attachmentCounter++] = { id, type: SummaryType.Attachment };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Helper function that converts ISnapshotTree and blobs to ISummaryTree
|
|
86
|
+
* @param snapshot - Source snapshot tree
|
|
87
|
+
* @param blobs - Blobs cache
|
|
88
|
+
* @returns Converted snapshot in ISummaryTree format
|
|
89
|
+
*/
|
|
90
|
+
export function convertSnapshotAndBlobsToSummaryTree(
|
|
91
|
+
snapshot: ISnapshotTree,
|
|
92
|
+
blobs: Map<string, ArrayBuffer>,
|
|
93
|
+
): ISummaryTree {
|
|
94
|
+
const assembler = new SummaryTreeAssembler({
|
|
95
|
+
unreferenced: snapshot.unreferenced,
|
|
96
|
+
});
|
|
97
|
+
for (const [path, id] of Object.entries(snapshot.blobs)) {
|
|
98
|
+
const blob = blobs.get(id);
|
|
99
|
+
assert(blob !== undefined, 0x2dd /* "Cannot find blob for a given id" */);
|
|
100
|
+
assembler.addBlob(path, IsoBuffer.from(blob).toString("utf-8"));
|
|
101
|
+
}
|
|
102
|
+
for (const [key, tree] of Object.entries(snapshot.trees)) {
|
|
103
|
+
const subtree = convertSnapshotAndBlobsToSummaryTree(tree, blobs);
|
|
104
|
+
assembler.addTree(key, subtree);
|
|
105
|
+
}
|
|
106
|
+
return assembler.summary;
|
|
107
|
+
}
|