@fluidframework/routerlicious-driver 0.51.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createNewUtils.js +4 -3
- package/dist/createNewUtils.js.map +1 -1
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +4 -261
- package/dist/documentStorageService.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/shreddedSummaryDocumentStorageService.d.ts +36 -0
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -0
- package/dist/shreddedSummaryDocumentStorageService.js +143 -0
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -0
- package/dist/wholeSummaryDocumentStorageService.d.ts +31 -0
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -0
- package/dist/wholeSummaryDocumentStorageService.js +157 -0
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -0
- package/lib/createNewUtils.js +4 -3
- package/lib/createNewUtils.js.map +1 -1
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +3 -260
- package/lib/documentStorageService.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/shreddedSummaryDocumentStorageService.d.ts +36 -0
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -0
- package/lib/shreddedSummaryDocumentStorageService.js +139 -0
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -0
- package/lib/wholeSummaryDocumentStorageService.d.ts +31 -0
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -0
- package/lib/wholeSummaryDocumentStorageService.js +153 -0
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -0
- package/package.json +11 -11
- package/src/documentStorageService.ts +20 -374
- package/src/packageVersion.ts +1 -1
- package/src/shreddedSummaryDocumentStorageService.ts +213 -0
- package/src/wholeSummaryDocumentStorageService.ts +231 -0
package/dist/createNewUtils.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.convertSummaryToCreateNewSummary = void 0;
|
|
8
8
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
9
10
|
/**
|
|
10
11
|
* Utility api to convert ISummaryTree to a summary tree where blob contents are only utf8 strings.
|
|
11
12
|
* @param summary - Summary supplied by the runtime to upload.
|
|
@@ -16,16 +17,16 @@ function convertSummaryToCreateNewSummary(summary) {
|
|
|
16
17
|
for (const key of keys) {
|
|
17
18
|
const summaryObject = summary.tree[key];
|
|
18
19
|
switch (summaryObject.type) {
|
|
19
|
-
case
|
|
20
|
+
case protocol_definitions_1.SummaryType.Tree: {
|
|
20
21
|
summary.tree[key] = convertSummaryToCreateNewSummary(summaryObject);
|
|
21
22
|
break;
|
|
22
23
|
}
|
|
23
|
-
case
|
|
24
|
+
case protocol_definitions_1.SummaryType.Blob: {
|
|
24
25
|
summaryObject.content = typeof summaryObject.content === "string" ?
|
|
25
26
|
summaryObject.content : common_utils_1.Uint8ArrayToString(summaryObject.content, "utf8");
|
|
26
27
|
break;
|
|
27
28
|
}
|
|
28
|
-
case
|
|
29
|
+
case protocol_definitions_1.SummaryType.Handle: {
|
|
29
30
|
throw new Error("No handle should be present for first summary!!");
|
|
30
31
|
}
|
|
31
32
|
default: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNewUtils.js","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkE;
|
|
1
|
+
{"version":3,"file":"createNewUtils.js","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkE;AAClE,+EAAiF;AAEjF;;;;GAIG;AACH,SAAgB,gCAAgC,CAAC,OAAqB;IAClE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACpB,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAExC,QAAQ,aAAa,CAAC,IAAI,EAAE;YACxB,KAAK,kCAAW,CAAC,IAAI,CAAC,CAAC;gBACnB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,gCAAgC,CAAC,aAAa,CAAC,CAAC;gBACpE,MAAM;aACT;YACD,KAAK,kCAAW,CAAC,IAAI,CAAC,CAAC;gBACnB,aAAa,CAAC,OAAO,GAAG,OAAO,aAAa,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;oBAC/D,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,iCAAkB,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC9E,MAAM;aACT;YACD,KAAK,kCAAW,CAAC,MAAM,CAAC,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;aACtE;YACD,OAAO,CAAC,CAAC;gBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aAC9D;SACJ;KACJ;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAzBD,4EAyBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport { ISummaryTree, SummaryType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Utility api to convert ISummaryTree to a summary tree where blob contents are only utf8 strings.\n * @param summary - Summary supplied by the runtime to upload.\n * @returns - Modified summary tree where the blob contents could be utf8 string only.\n */\nexport function convertSummaryToCreateNewSummary(summary: ISummaryTree): ISummaryTree {\n const keys = Object.keys(summary.tree);\n for (const key of keys) {\n const summaryObject = summary.tree[key];\n\n switch (summaryObject.type) {\n case SummaryType.Tree: {\n summary.tree[key] = convertSummaryToCreateNewSummary(summaryObject);\n break;\n }\n case SummaryType.Blob: {\n summaryObject.content = typeof summaryObject.content === \"string\" ?\n summaryObject.content : Uint8ArrayToString(summaryObject.content, \"utf8\");\n break;\n }\n case SummaryType.Handle: {\n throw new Error(\"No handle should be present for first summary!!\");\n }\n default: {\n throw new Error(`Unknown tree type ${summaryObject.type}`);\n }\n }\n }\n\n return summary;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentStorageService.d.ts","sourceRoot":"","sources":["../src/documentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"documentStorageService.d.ts","sourceRoot":"","sources":["../src/documentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAEH,+BAA+B,EAEjC,MAAM,oCAAoC,CAAC;AAC7C,OAAO,EACH,aAAa,EACb,QAAQ,EACX,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACH,UAAU,EACb,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAkC,MAAM,8BAA8B,CAAC;AAC3G,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAIjC,qBAAa,sBAAuB,SAAQ,2BAA2B;aAyC/C,EAAE,EAAE,MAAM;IACnB,OAAO,EAAE,UAAU;IAzC9B,OAAO,CAAC,WAAW,CAAiC;IAEpD,IAAW,UAAU,IAAI,MAAM,GAAG,SAAS,CAE1C;IAED,OAAO,CAAC,MAAM,CAAC,kCAAkC;gBAkC7B,EAAE,EAAE,MAAM,EACnB,OAAO,EAAE,UAAU,EAC1B,MAAM,EAAE,gBAAgB,EACxB,QAAQ,GAAE,+BAAoC,EAC9C,cAAc,CAAC,EAAE,4BAA4B,EAC7C,SAAS,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,EACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC;IAYhC,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;CAOlF"}
|
|
@@ -5,267 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.DocumentStorageService = void 0;
|
|
8
|
-
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
8
|
const driver_definitions_1 = require("@fluidframework/driver-definitions");
|
|
10
|
-
const protocol_base_1 = require("@fluidframework/protocol-base");
|
|
11
|
-
const server_services_client_1 = require("@fluidframework/server-services-client");
|
|
12
|
-
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
13
9
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
/**
|
|
17
|
-
* Document access to underlying storage for routerlicious driver.
|
|
18
|
-
* Uploads summaries piece-by-piece traversing the tree recursively.
|
|
19
|
-
* Downloads summaries
|
|
20
|
-
*/
|
|
21
|
-
class ShreddedSummaryDocumentStorageService {
|
|
22
|
-
constructor(id, manager, logger, policies = {}) {
|
|
23
|
-
this.id = id;
|
|
24
|
-
this.manager = manager;
|
|
25
|
-
this.logger = logger;
|
|
26
|
-
this.policies = policies;
|
|
27
|
-
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
28
|
-
// empty strings as values.
|
|
29
|
-
this.blobsShaCache = new Map();
|
|
30
|
-
this.summaryUploadManager = new server_services_client_1.SummaryTreeUploadManager(new retriableGitManager_1.RetriableGitManager(manager, logger), this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
|
|
31
|
-
}
|
|
32
|
-
get repositoryUrl() {
|
|
33
|
-
return "";
|
|
34
|
-
}
|
|
35
|
-
async getVersions(versionId, count) {
|
|
36
|
-
const id = versionId ? versionId : this.id;
|
|
37
|
-
const commits = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
38
|
-
eventName: "getVersions",
|
|
39
|
-
versionId: id,
|
|
40
|
-
count,
|
|
41
|
-
}, async () => this.manager.getCommits(id, count));
|
|
42
|
-
return commits.map((commit) => ({
|
|
43
|
-
date: commit.commit.author.date,
|
|
44
|
-
id: commit.sha,
|
|
45
|
-
treeId: commit.commit.tree.sha,
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
async getSnapshotTree(version) {
|
|
49
|
-
let requestVersion = version;
|
|
50
|
-
if (!requestVersion) {
|
|
51
|
-
const versions = await this.getVersions(this.id, 1);
|
|
52
|
-
if (versions.length === 0) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
requestVersion = versions[0];
|
|
56
|
-
}
|
|
57
|
-
const rawTree = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
58
|
-
eventName: "getSnapshotTree",
|
|
59
|
-
treeId: requestVersion.treeId,
|
|
60
|
-
}, async (event) => {
|
|
61
|
-
const response = await this.manager.getTree(requestVersion.treeId);
|
|
62
|
-
event.end({
|
|
63
|
-
size: response.tree.length,
|
|
64
|
-
});
|
|
65
|
-
return response;
|
|
66
|
-
});
|
|
67
|
-
const tree = protocol_base_1.buildHierarchy(rawTree, this.blobsShaCache, true);
|
|
68
|
-
return tree;
|
|
69
|
-
}
|
|
70
|
-
async readBlob(blobId) {
|
|
71
|
-
const value = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
72
|
-
eventName: "readBlob",
|
|
73
|
-
blobId,
|
|
74
|
-
}, async (event) => {
|
|
75
|
-
const response = await this.manager.getBlob(blobId);
|
|
76
|
-
event.end({
|
|
77
|
-
size: response.size,
|
|
78
|
-
});
|
|
79
|
-
return response;
|
|
80
|
-
});
|
|
81
|
-
this.blobsShaCache.set(value.sha, "");
|
|
82
|
-
return common_utils_1.stringToBuffer(value.content, value.encoding);
|
|
83
|
-
}
|
|
84
|
-
async write(tree, parents, message, ref) {
|
|
85
|
-
const branch = ref ? `datastores/${this.id}/${ref}` : this.id;
|
|
86
|
-
const commit = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
87
|
-
eventName: "write",
|
|
88
|
-
id: branch,
|
|
89
|
-
}, async () => this.manager.write(branch, tree, parents, message));
|
|
90
|
-
return { date: commit.committer.date, id: commit.sha, treeId: commit.tree.sha };
|
|
91
|
-
}
|
|
92
|
-
async uploadSummaryWithContext(summary, context) {
|
|
93
|
-
const summaryHandle = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
94
|
-
eventName: "uploadSummaryWithContext",
|
|
95
|
-
}, async () => { var _a; return this.summaryUploadManager.writeSummaryTree(summary, (_a = context.ackHandle) !== null && _a !== void 0 ? _a : "", "channel"); });
|
|
96
|
-
return summaryHandle;
|
|
97
|
-
}
|
|
98
|
-
async downloadSummary(handle) {
|
|
99
|
-
throw new Error("NOT IMPLEMENTED!");
|
|
100
|
-
}
|
|
101
|
-
async createBlob(file) {
|
|
102
|
-
const uint8ArrayFile = new Uint8Array(file);
|
|
103
|
-
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
104
|
-
eventName: "createBlob",
|
|
105
|
-
size: uint8ArrayFile.length,
|
|
106
|
-
}, async (event) => {
|
|
107
|
-
const response = await this.manager.createBlob(common_utils_1.Uint8ArrayToString(uint8ArrayFile, "base64"), "base64").then((r) => ({ id: r.sha, url: r.url }));
|
|
108
|
-
event.end({
|
|
109
|
-
blobId: response.id,
|
|
110
|
-
});
|
|
111
|
-
return response;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
async getPreviousFullSnapshot(parentHandle) {
|
|
115
|
-
return parentHandle
|
|
116
|
-
? this.getVersions(parentHandle, 1)
|
|
117
|
-
.then(async (versions) => {
|
|
118
|
-
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
119
|
-
this.blobsShaCache.clear();
|
|
120
|
-
return this.getSnapshotTree(versions[0]);
|
|
121
|
-
})
|
|
122
|
-
: undefined;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const latestSnapshotId = "latest";
|
|
126
|
-
class WholeSummaryDocumentStorageService {
|
|
127
|
-
constructor(id, manager, logger, policies = {}, blobCache = new cache_1.InMemoryCache(), snapshotTreeCache = new cache_1.InMemoryCache()) {
|
|
128
|
-
this.id = id;
|
|
129
|
-
this.manager = manager;
|
|
130
|
-
this.logger = logger;
|
|
131
|
-
this.policies = policies;
|
|
132
|
-
this.blobCache = blobCache;
|
|
133
|
-
this.snapshotTreeCache = snapshotTreeCache;
|
|
134
|
-
this.firstVersionsCall = true;
|
|
135
|
-
this.summaryUploadManager = new server_services_client_1.WholeSummaryUploadManager(manager);
|
|
136
|
-
}
|
|
137
|
-
get repositoryUrl() {
|
|
138
|
-
return "";
|
|
139
|
-
}
|
|
140
|
-
async getVersions(versionId, count) {
|
|
141
|
-
if (versionId !== this.id && versionId !== null) {
|
|
142
|
-
// Blobs in this scenario will never have multiple versions, so return blobId as is
|
|
143
|
-
return [{
|
|
144
|
-
id: versionId,
|
|
145
|
-
treeId: undefined,
|
|
146
|
-
}];
|
|
147
|
-
}
|
|
148
|
-
// If this is the first versions call for the document, we know we will want the latest summary.
|
|
149
|
-
// Fetch latest summary, cache it, and return its id.
|
|
150
|
-
if (this.firstVersionsCall && count === 1) {
|
|
151
|
-
this.firstVersionsCall = false;
|
|
152
|
-
return [{
|
|
153
|
-
id: (await this.fetchAndCacheSnapshotTree(latestSnapshotId)).id,
|
|
154
|
-
treeId: undefined,
|
|
155
|
-
}];
|
|
156
|
-
}
|
|
157
|
-
// Otherwise, get the latest version of the document as normal.
|
|
158
|
-
const id = versionId ? versionId : this.id;
|
|
159
|
-
const commits = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
160
|
-
eventName: "getVersions",
|
|
161
|
-
versionId: id,
|
|
162
|
-
count,
|
|
163
|
-
}, async () => this.manager.getCommits(id, count));
|
|
164
|
-
return commits.map((commit) => ({
|
|
165
|
-
date: commit.commit.author.date,
|
|
166
|
-
id: commit.sha,
|
|
167
|
-
treeId: undefined,
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
170
|
-
async getSnapshotTree(version) {
|
|
171
|
-
let requestVersion = version;
|
|
172
|
-
if (!requestVersion) {
|
|
173
|
-
const versions = await this.getVersions(this.id, 1);
|
|
174
|
-
if (versions.length === 0) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
requestVersion = versions[0];
|
|
178
|
-
}
|
|
179
|
-
return (await this.fetchAndCacheSnapshotTree(requestVersion.id)).snapshotTree;
|
|
180
|
-
}
|
|
181
|
-
async readBlob(blobId) {
|
|
182
|
-
const cachedBlob = await this.blobCache.get(blobId);
|
|
183
|
-
if (cachedBlob !== undefined) {
|
|
184
|
-
return cachedBlob;
|
|
185
|
-
}
|
|
186
|
-
const blob = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
187
|
-
eventName: "readBlob",
|
|
188
|
-
blobId,
|
|
189
|
-
}, async (event) => {
|
|
190
|
-
const response = await this.manager.getBlob(blobId);
|
|
191
|
-
event.end({
|
|
192
|
-
size: response.size,
|
|
193
|
-
});
|
|
194
|
-
return response;
|
|
195
|
-
});
|
|
196
|
-
const bufferValue = common_utils_1.stringToBuffer(blob.content, blob.encoding);
|
|
197
|
-
await this.blobCache.put(blob.sha, bufferValue);
|
|
198
|
-
return bufferValue;
|
|
199
|
-
}
|
|
200
|
-
async uploadSummaryWithContext(summary, context) {
|
|
201
|
-
const summaryHandle = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
202
|
-
eventName: "uploadSummaryWithContext",
|
|
203
|
-
}, async () => { var _a; return this.summaryUploadManager.writeSummaryTree(summary, (_a = context.ackHandle) !== null && _a !== void 0 ? _a : "", "channel"); });
|
|
204
|
-
return summaryHandle;
|
|
205
|
-
}
|
|
206
|
-
async downloadSummary(handle) {
|
|
207
|
-
throw new Error("NOT IMPLEMENTED!");
|
|
208
|
-
}
|
|
209
|
-
async write(tree, parents, message, ref) {
|
|
210
|
-
throw new Error("NOT IMPLEMENTED!");
|
|
211
|
-
}
|
|
212
|
-
async createBlob(file) {
|
|
213
|
-
const uint8ArrayFile = new Uint8Array(file);
|
|
214
|
-
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
215
|
-
eventName: "createBlob",
|
|
216
|
-
size: uint8ArrayFile.length,
|
|
217
|
-
}, async (event) => {
|
|
218
|
-
const response = await this.manager.createBlob(common_utils_1.Uint8ArrayToString(uint8ArrayFile, "base64"), "base64").then((r) => ({ id: r.sha, url: r.url }));
|
|
219
|
-
event.end({
|
|
220
|
-
blobId: response.id,
|
|
221
|
-
});
|
|
222
|
-
return response;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
async fetchAndCacheSnapshotTree(versionId) {
|
|
226
|
-
const cachedSnapshotTree = await this.snapshotTreeCache.get(versionId);
|
|
227
|
-
if (cachedSnapshotTree !== undefined) {
|
|
228
|
-
return { id: versionId, snapshotTree: cachedSnapshotTree };
|
|
229
|
-
}
|
|
230
|
-
const wholeFlatSummary = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
231
|
-
eventName: "getWholeFlatSummary",
|
|
232
|
-
treeId: versionId,
|
|
233
|
-
}, async (event) => {
|
|
234
|
-
var _a;
|
|
235
|
-
const response = await this.manager.getSummary(versionId);
|
|
236
|
-
event.end({
|
|
237
|
-
size: (_a = response.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length,
|
|
238
|
-
});
|
|
239
|
-
return response;
|
|
240
|
-
});
|
|
241
|
-
const normalizedWholeSummary = server_services_client_1.convertWholeFlatSummaryToSnapshotTreeAndBlobs(wholeFlatSummary);
|
|
242
|
-
const snapshotId = normalizedWholeSummary.snapshotTree.id;
|
|
243
|
-
common_utils_1.assert(snapshotId !== undefined, 0x275 /* "Root tree should contain the id" */);
|
|
244
|
-
const cachePs = [
|
|
245
|
-
this.snapshotTreeCache.put(snapshotId, normalizedWholeSummary.snapshotTree),
|
|
246
|
-
this.initBlobCache(normalizedWholeSummary.blobs),
|
|
247
|
-
];
|
|
248
|
-
if (snapshotId !== versionId) {
|
|
249
|
-
// versionId could be "latest". When summarizer checks cache for "latest", we want it to be available.
|
|
250
|
-
// TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,
|
|
251
|
-
// However, for something like Redis, this will cache the same value twice. Alternatively, could we simply
|
|
252
|
-
// cache with versionId?
|
|
253
|
-
cachePs.push(this.snapshotTreeCache.put(versionId, normalizedWholeSummary.snapshotTree));
|
|
254
|
-
}
|
|
255
|
-
await Promise.all([
|
|
256
|
-
this.snapshotTreeCache.put(snapshotId, normalizedWholeSummary.snapshotTree),
|
|
257
|
-
this.initBlobCache(normalizedWholeSummary.blobs),
|
|
258
|
-
]);
|
|
259
|
-
return { id: snapshotId, snapshotTree: normalizedWholeSummary.snapshotTree };
|
|
260
|
-
}
|
|
261
|
-
async initBlobCache(blobs) {
|
|
262
|
-
const blobCachePutPs = [];
|
|
263
|
-
blobs.forEach((value, id) => {
|
|
264
|
-
blobCachePutPs.push(this.blobCache.put(id, value));
|
|
265
|
-
});
|
|
266
|
-
await Promise.all(blobCachePutPs);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
10
|
+
const wholeSummaryDocumentStorageService_1 = require("./wholeSummaryDocumentStorageService");
|
|
11
|
+
const shreddedSummaryDocumentStorageService_1 = require("./shreddedSummaryDocumentStorageService");
|
|
269
12
|
class DocumentStorageService extends driver_utils_1.DocumentStorageServiceProxy {
|
|
270
13
|
constructor(id, manager, logger, policies = {}, driverPolicies, blobCache, snapshotTreeCache) {
|
|
271
14
|
super(DocumentStorageService.loadInternalDocumentStorageService(id, manager, logger, policies, driverPolicies, blobCache, snapshotTreeCache));
|
|
@@ -278,8 +21,8 @@ class DocumentStorageService extends driver_utils_1.DocumentStorageServiceProxy
|
|
|
278
21
|
}
|
|
279
22
|
static loadInternalDocumentStorageService(id, manager, logger, policies, driverPolicies, blobCache, snapshotTreeCache) {
|
|
280
23
|
const storageService = (driverPolicies === null || driverPolicies === void 0 ? void 0 : driverPolicies.enableWholeSummaryUpload) ?
|
|
281
|
-
new WholeSummaryDocumentStorageService(id, manager, logger, policies, blobCache, snapshotTreeCache) :
|
|
282
|
-
new ShreddedSummaryDocumentStorageService(id, manager, logger, policies);
|
|
24
|
+
new wholeSummaryDocumentStorageService_1.WholeSummaryDocumentStorageService(id, manager, logger, policies, blobCache, snapshotTreeCache) :
|
|
25
|
+
new shreddedSummaryDocumentStorageService_1.ShreddedSummaryDocumentStorageService(id, manager, logger, policies, driverPolicies, blobCache, snapshotTreeCache);
|
|
283
26
|
// TODO: worth prefetching latest summary making version + snapshot call with WholeSummary storage?
|
|
284
27
|
if (!(driverPolicies === null || driverPolicies === void 0 ? void 0 : driverPolicies.enableWholeSummaryUpload) && policies.caching === driver_definitions_1.LoaderCachingPolicy.Prefetch) {
|
|
285
28
|
return new driver_utils_1.PrefetchDocumentStorageService(storageService);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentStorageService.js","sourceRoot":"","sources":["../src/documentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAIsC;AACtC,2EAK6C;AAC7C,iEAA+D;AAU/D,mFAMgD;AAChD,qEAAmE;AACnE,+DAA2G;AAC3G,+DAA4D;AAE5D,mCAAgD;AAEhD;;;;GAIG;AACH,MAAM,qCAAqC;IAUvC,YACuB,EAAU,EACV,OAAmB,EACnB,MAAwB,EAC3B,WAA4C,EAAE;QAH3C,OAAE,GAAF,EAAE,CAA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* Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n assert,\n stringToBuffer,\n Uint8ArrayToString,\n} from \"@fluidframework/common-utils\";\nimport {\n IDocumentStorageService,\n ISummaryContext,\n IDocumentStorageServicePolicies,\n LoaderCachingPolicy,\n } from \"@fluidframework/driver-definitions\";\nimport { buildHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n ICreateBlobResponse,\n ISnapshotTree,\n ISnapshotTreeEx,\n ISummaryHandle,\n ISummaryTree,\n ITree,\n IVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n convertWholeFlatSummaryToSnapshotTreeAndBlobs,\n GitManager,\n ISummaryUploadManager,\n SummaryTreeUploadManager,\n WholeSummaryUploadManager,\n} from \"@fluidframework/server-services-client\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DocumentStorageServiceProxy, PrefetchDocumentStorageService } from \"@fluidframework/driver-utils\";\nimport { RetriableGitManager } from \"./retriableGitManager\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport { ICache, InMemoryCache } from \"./cache\";\n\n/**\n * Document access to underlying storage for routerlicious driver.\n * Uploads summaries piece-by-piece traversing the tree recursively.\n * Downloads summaries\n */\nclass ShreddedSummaryDocumentStorageService implements IDocumentStorageService {\n // The values of this cache is useless. We only need the keys. So we are always putting\n // empty strings as values.\n protected readonly blobsShaCache = new Map<string, string>();\n private readonly summaryUploadManager: ISummaryUploadManager;\n\n public get repositoryUrl(): string {\n return \"\";\n }\n\n constructor(\n protected readonly id: string,\n protected readonly manager: GitManager,\n protected readonly logger: ITelemetryLogger,\n public readonly policies: IDocumentStorageServicePolicies = {}) {\n this.summaryUploadManager = new SummaryTreeUploadManager(\n new RetriableGitManager(manager, logger),\n this.blobsShaCache,\n this.getPreviousFullSnapshot.bind(this),\n );\n }\n\n public async getVersions(versionId: string, count: number): Promise<IVersion[]> {\n const id = versionId ? versionId : this.id;\n const commits = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"getVersions\",\n versionId: id,\n count,\n },\n async () => this.manager.getCommits(id, count),\n );\n return commits.map((commit) => ({\n date: commit.commit.author.date,\n id: commit.sha,\n treeId: commit.commit.tree.sha,\n }));\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n let requestVersion = version;\n if (!requestVersion) {\n const versions = await this.getVersions(this.id, 1);\n if (versions.length === 0) {\n return null;\n }\n\n requestVersion = versions[0];\n }\n\n const rawTree = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"getSnapshotTree\",\n treeId: requestVersion.treeId,\n },\n async (event) => {\n const response = await this.manager.getTree(requestVersion!.treeId);\n event.end({\n size: response.tree.length,\n });\n return response;\n },\n );\n const tree = buildHierarchy(rawTree, this.blobsShaCache, true);\n return tree;\n }\n\n public async readBlob(blobId: string): Promise<ArrayBufferLike> {\n const value = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"readBlob\",\n blobId,\n },\n async (event) => {\n const response = await this.manager.getBlob(blobId);\n event.end({\n size: response.size,\n });\n return response;\n },\n );\n this.blobsShaCache.set(value.sha, \"\");\n return stringToBuffer(value.content, value.encoding);\n }\n\n public async write(tree: ITree, parents: string[], message: string, ref: string): Promise<IVersion> {\n const branch = ref ? `datastores/${this.id}/${ref}` : this.id;\n const commit = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"write\",\n id: branch,\n },\n async () => this.manager.write(branch, tree, parents, message),\n );\n return { date: commit.committer.date, id: commit.sha, treeId: commit.tree.sha };\n }\n\n public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {\n const summaryHandle = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"uploadSummaryWithContext\",\n },\n async () => this.summaryUploadManager.writeSummaryTree(summary, context.ackHandle ?? \"\", \"channel\"),\n );\n return summaryHandle;\n }\n\n public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n throw new Error(\"NOT IMPLEMENTED!\");\n }\n\n public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n const uint8ArrayFile = new Uint8Array(file);\n return PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"createBlob\",\n size: uint8ArrayFile.length,\n },\n async (event) => {\n const response = await this.manager.createBlob(\n Uint8ArrayToString(\n uint8ArrayFile, \"base64\"),\n \"base64\").then((r) => ({ id: r.sha, url: r.url }));\n event.end({\n blobId: response.id,\n });\n return response;\n },\n );\n }\n\n private async getPreviousFullSnapshot(parentHandle: string): Promise<ISnapshotTreeEx | null | undefined> {\n return parentHandle\n ? this.getVersions(parentHandle, 1)\n .then(async (versions) => {\n // Clear the cache as the getSnapshotTree call will fill the cache.\n this.blobsShaCache.clear();\n return this.getSnapshotTree(versions[0]);\n })\n : undefined;\n }\n}\n\nconst latestSnapshotId: string = \"latest\";\n\nclass WholeSummaryDocumentStorageService implements IDocumentStorageService {\n private readonly summaryUploadManager: ISummaryUploadManager;\n private firstVersionsCall: boolean = true;\n\n public get repositoryUrl(): string {\n return \"\";\n }\n\n constructor(\n protected readonly id: string,\n protected readonly manager: GitManager,\n protected readonly logger: ITelemetryLogger,\n public readonly policies: IDocumentStorageServicePolicies = {},\n private readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),\n private readonly snapshotTreeCache: ICache<ISnapshotTree> = new InMemoryCache()) {\n this.summaryUploadManager = new WholeSummaryUploadManager(manager);\n }\n\n public async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n if (versionId !== this.id && versionId !== null) {\n // Blobs in this scenario will never have multiple versions, so return blobId as is\n return [{\n id: versionId,\n treeId: undefined!,\n }];\n }\n // If this is the first versions call for the document, we know we will want the latest summary.\n // Fetch latest summary, cache it, and return its id.\n if (this.firstVersionsCall && count === 1) {\n this.firstVersionsCall = false;\n return [{\n id: (await this.fetchAndCacheSnapshotTree(latestSnapshotId)).id,\n treeId: undefined!,\n }];\n }\n\n // Otherwise, get the latest version of the document as normal.\n const id = versionId ? versionId : this.id;\n const commits = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"getVersions\",\n versionId: id,\n count,\n },\n async () => this.manager.getCommits(id, count),\n );\n return commits.map((commit) => ({\n date: commit.commit.author.date,\n id: commit.sha,\n treeId: undefined!,\n }));\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n let requestVersion = version;\n if (!requestVersion) {\n const versions = await this.getVersions(this.id, 1);\n if (versions.length === 0) {\n return null;\n }\n\n requestVersion = versions[0];\n }\n\n return (await this.fetchAndCacheSnapshotTree(requestVersion.id)).snapshotTree;\n }\n\n public async readBlob(blobId: string): Promise<ArrayBufferLike> {\n const cachedBlob = await this.blobCache.get(blobId);\n if (cachedBlob !== undefined) {\n return cachedBlob;\n }\n\n const blob = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"readBlob\",\n blobId,\n },\n async (event) => {\n const response = await this.manager.getBlob(blobId);\n event.end({\n size: response.size,\n });\n return response;\n },\n );\n const bufferValue = stringToBuffer(blob.content, blob.encoding);\n\n await this.blobCache.put(blob.sha, bufferValue);\n\n return bufferValue;\n }\n\n public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {\n const summaryHandle = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"uploadSummaryWithContext\",\n },\n async () => this.summaryUploadManager.writeSummaryTree(summary, context.ackHandle ?? \"\", \"channel\"),\n );\n return summaryHandle;\n }\n\n public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n throw new Error(\"NOT IMPLEMENTED!\");\n }\n\n public async write(tree: ITree, parents: string[], message: string, ref: string): Promise<IVersion> {\n throw new Error(\"NOT IMPLEMENTED!\");\n }\n\n public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n const uint8ArrayFile = new Uint8Array(file);\n return PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"createBlob\",\n size: uint8ArrayFile.length,\n },\n async (event) => {\n const response = await this.manager.createBlob(\n Uint8ArrayToString(\n uint8ArrayFile, \"base64\"),\n \"base64\").then((r) => ({ id: r.sha, url: r.url }));\n event.end({\n blobId: response.id,\n });\n return response;\n },\n );\n }\n\n private async fetchAndCacheSnapshotTree(versionId: string): Promise<{ id: string, snapshotTree: ISnapshotTree }> {\n const cachedSnapshotTree = await this.snapshotTreeCache.get(versionId);\n if (cachedSnapshotTree !== undefined) {\n return { id: versionId, snapshotTree: cachedSnapshotTree };\n }\n\n const wholeFlatSummary = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"getWholeFlatSummary\",\n treeId: versionId,\n },\n async (event) => {\n const response = await this.manager.getSummary(versionId);\n event.end({\n size: response.trees[0]?.entries.length,\n });\n return response;\n },\n );\n const normalizedWholeSummary = convertWholeFlatSummaryToSnapshotTreeAndBlobs(wholeFlatSummary);\n const snapshotId = normalizedWholeSummary.snapshotTree.id;\n assert(snapshotId !== undefined, 0x275 /* \"Root tree should contain the id\" */);\n\n const cachePs: Promise<any>[] = [\n this.snapshotTreeCache.put(\n snapshotId,\n normalizedWholeSummary.snapshotTree,\n ),\n this.initBlobCache(normalizedWholeSummary.blobs),\n ];\n if (snapshotId !== versionId) {\n // versionId could be \"latest\". When summarizer checks cache for \"latest\", we want it to be available.\n // TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,\n // However, for something like Redis, this will cache the same value twice. Alternatively, could we simply\n // cache with versionId?\n cachePs.push(this.snapshotTreeCache.put(\n versionId,\n normalizedWholeSummary.snapshotTree,\n ));\n }\n\n await Promise.all([\n this.snapshotTreeCache.put(\n snapshotId,\n normalizedWholeSummary.snapshotTree,\n ),\n this.initBlobCache(normalizedWholeSummary.blobs),\n ]);\n\n return { id: snapshotId, snapshotTree: normalizedWholeSummary.snapshotTree};\n }\n\n private async initBlobCache(blobs: Map<string, ArrayBuffer>): Promise<void> {\n const blobCachePutPs: Promise<void>[] = [];\n blobs.forEach((value, id) => {\n blobCachePutPs.push(this.blobCache.put(id, value));\n });\n await Promise.all(blobCachePutPs);\n }\n}\n\nexport class DocumentStorageService extends DocumentStorageServiceProxy {\n private _logTailSha: string | undefined = undefined;\n\n public get logTailSha(): string | undefined {\n return this._logTailSha;\n }\n\n private static loadInternalDocumentStorageService(\n id: string,\n manager: GitManager,\n logger: ITelemetryLogger,\n policies: IDocumentStorageServicePolicies,\n driverPolicies?: IRouterliciousDriverPolicies,\n blobCache?: ICache<ArrayBufferLike>,\n snapshotTreeCache?: ICache<ISnapshotTree>): IDocumentStorageService {\n const storageService = driverPolicies?.enableWholeSummaryUpload ?\n new WholeSummaryDocumentStorageService(id, manager, logger, policies, blobCache, snapshotTreeCache) :\n new ShreddedSummaryDocumentStorageService(id, manager, logger, policies);\n // TODO: worth prefetching latest summary making version + snapshot call with WholeSummary storage?\n if (!driverPolicies?.enableWholeSummaryUpload && policies.caching === LoaderCachingPolicy.Prefetch) {\n return new PrefetchDocumentStorageService(storageService);\n }\n return storageService;\n }\n\n constructor(\n public readonly id: string,\n public manager: GitManager,\n logger: ITelemetryLogger,\n policies: IDocumentStorageServicePolicies = {},\n driverPolicies?: IRouterliciousDriverPolicies,\n blobCache?: ICache<ArrayBufferLike>,\n snapshotTreeCache?: ICache<ISnapshotTree>) {\n super(DocumentStorageService.loadInternalDocumentStorageService(\n id,\n manager,\n logger,\n policies,\n driverPolicies,\n blobCache,\n snapshotTreeCache,\n ));\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n const tree = await this.internalStorageService.getSnapshotTree(version);\n if (tree !== null) {\n this._logTailSha = \".logTail\" in tree.trees ? tree.trees[\".logTail\"].blobs.logTail : undefined;\n }\n return tree;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentStorageService.js","sourceRoot":"","sources":["../src/documentStorageService.ts"],"names":[],"mappings":";AAAA;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CAAC,OAAkB;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACxE,IAAI,IAAI,KAAK,IAAI,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;SAClG;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAlED,wDAkEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n IDocumentStorageService,\n IDocumentStorageServicePolicies,\n LoaderCachingPolicy,\n } from \"@fluidframework/driver-definitions\";\nimport {\n ISnapshotTree,\n IVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n GitManager,\n} from \"@fluidframework/server-services-client\";\nimport { DocumentStorageServiceProxy, PrefetchDocumentStorageService } from \"@fluidframework/driver-utils\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport { ICache } from \"./cache\";\nimport { WholeSummaryDocumentStorageService } from \"./wholeSummaryDocumentStorageService\";\nimport { ShreddedSummaryDocumentStorageService } from \"./shreddedSummaryDocumentStorageService\";\n\nexport class DocumentStorageService extends DocumentStorageServiceProxy {\n private _logTailSha: string | undefined = undefined;\n\n public get logTailSha(): string | undefined {\n return this._logTailSha;\n }\n\n private static loadInternalDocumentStorageService(\n id: string,\n manager: GitManager,\n logger: ITelemetryLogger,\n policies: IDocumentStorageServicePolicies,\n driverPolicies?: IRouterliciousDriverPolicies,\n blobCache?: ICache<ArrayBufferLike>,\n snapshotTreeCache?: ICache<ISnapshotTree>): IDocumentStorageService {\n const storageService = driverPolicies?.enableWholeSummaryUpload ?\n new WholeSummaryDocumentStorageService(\n id,\n manager,\n logger,\n policies,\n blobCache,\n snapshotTreeCache,\n ) :\n new ShreddedSummaryDocumentStorageService(\n id,\n manager,\n logger,\n policies,\n driverPolicies,\n blobCache,\n snapshotTreeCache,\n );\n // TODO: worth prefetching latest summary making version + snapshot call with WholeSummary storage?\n if (!driverPolicies?.enableWholeSummaryUpload && policies.caching === LoaderCachingPolicy.Prefetch) {\n return new PrefetchDocumentStorageService(storageService);\n }\n return storageService;\n }\n\n constructor(\n public readonly id: string,\n public manager: GitManager,\n logger: ITelemetryLogger,\n policies: IDocumentStorageServicePolicies = {},\n driverPolicies?: IRouterliciousDriverPolicies,\n blobCache?: ICache<ArrayBufferLike>,\n snapshotTreeCache?: ICache<ISnapshotTree>) {\n super(DocumentStorageService.loadInternalDocumentStorageService(\n id,\n manager,\n logger,\n policies,\n driverPolicies,\n blobCache,\n snapshotTreeCache,\n ));\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n const tree = await this.internalStorageService.getSnapshotTree(version);\n if (tree !== null) {\n this._logTailSha = \".logTail\" in tree.trees ? tree.trees[\".logTail\"].blobs.logTail : undefined;\n }\n return tree;\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/routerlicious-driver";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.52.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/routerlicious-driver";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.52.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sCAAsC,CAAC;AACjD,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/routerlicious-driver\";\nexport const pkgVersion = \"0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sCAAsC,CAAC;AACjD,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/routerlicious-driver\";\nexport const pkgVersion = \"0.52.0\";\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
6
|
+
import { IDocumentStorageService, ISummaryContext, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
|
|
7
|
+
import { ICreateBlobResponse, ISnapshotTree, ISnapshotTreeEx, ISummaryHandle, ISummaryTree, ITree, IVersion } from "@fluidframework/protocol-definitions";
|
|
8
|
+
import { GitManager } from "@fluidframework/server-services-client";
|
|
9
|
+
import { IRouterliciousDriverPolicies } from "./policies";
|
|
10
|
+
import { ICache } from "./cache";
|
|
11
|
+
/**
|
|
12
|
+
* Document access to underlying storage for routerlicious driver.
|
|
13
|
+
* Uploads summaries piece-by-piece traversing the tree recursively.
|
|
14
|
+
* Downloads summaries piece-by-piece on-demand, or up-front when prefetch is enabled.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ShreddedSummaryDocumentStorageService implements IDocumentStorageService {
|
|
17
|
+
protected readonly id: string;
|
|
18
|
+
protected readonly manager: GitManager;
|
|
19
|
+
protected readonly logger: ITelemetryLogger;
|
|
20
|
+
readonly policies: IDocumentStorageServicePolicies;
|
|
21
|
+
protected readonly blobsShaCache: Map<string, string>;
|
|
22
|
+
private readonly blobCache;
|
|
23
|
+
private readonly snapshotTreeCache;
|
|
24
|
+
private readonly summaryUploadManager;
|
|
25
|
+
get repositoryUrl(): string;
|
|
26
|
+
constructor(id: string, manager: GitManager, logger: ITelemetryLogger, policies?: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<ISnapshotTree>);
|
|
27
|
+
getVersions(versionId: string, count: number): Promise<IVersion[]>;
|
|
28
|
+
getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null>;
|
|
29
|
+
readBlob(blobId: string): Promise<ArrayBufferLike>;
|
|
30
|
+
write(tree: ITree, parents: string[], message: string, ref: string): Promise<IVersion>;
|
|
31
|
+
uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
32
|
+
downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree>;
|
|
33
|
+
createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
|
|
34
|
+
private getPreviousFullSnapshot;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=shreddedSummaryDocumentStorageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shreddedSummaryDocumentStorageService.d.ts","sourceRoot":"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AAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAkBlE,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAmCpE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA0BlD,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAatF,wBAAwB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAW1F,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAI9D,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAqB9D,uBAAuB;CAUxC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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.ShreddedSummaryDocumentStorageService = void 0;
|
|
8
|
+
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
|
+
const protocol_base_1 = require("@fluidframework/protocol-base");
|
|
10
|
+
const server_services_client_1 = require("@fluidframework/server-services-client");
|
|
11
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
12
|
+
const cache_1 = require("./cache");
|
|
13
|
+
const retriableGitManager_1 = require("./retriableGitManager");
|
|
14
|
+
// eslint-disable-next-line no-new-func,@typescript-eslint/no-implied-eval
|
|
15
|
+
const isNode = (new Function("try {return this===global;}catch(e){ return false;}"))();
|
|
16
|
+
/**
|
|
17
|
+
* Document access to underlying storage for routerlicious driver.
|
|
18
|
+
* Uploads summaries piece-by-piece traversing the tree recursively.
|
|
19
|
+
* Downloads summaries piece-by-piece on-demand, or up-front when prefetch is enabled.
|
|
20
|
+
*/
|
|
21
|
+
class ShreddedSummaryDocumentStorageService {
|
|
22
|
+
constructor(id, manager, logger, policies = {}, driverPolicies, blobCache, snapshotTreeCache) {
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.manager = manager;
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
this.policies = policies;
|
|
27
|
+
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
28
|
+
// empty strings as values.
|
|
29
|
+
this.blobsShaCache = new Map();
|
|
30
|
+
this.summaryUploadManager = new server_services_client_1.SummaryTreeUploadManager(new retriableGitManager_1.RetriableGitManager(manager, logger), this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
|
|
31
|
+
if ((driverPolicies === null || driverPolicies === void 0 ? void 0 : driverPolicies.enableRestLess) === true || isNode) {
|
|
32
|
+
this.blobCache = blobCache !== null && blobCache !== void 0 ? blobCache : new cache_1.InMemoryCache();
|
|
33
|
+
this.snapshotTreeCache = (snapshotTreeCache !== null && snapshotTreeCache !== void 0 ? snapshotTreeCache : new cache_1.InMemoryCache());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get repositoryUrl() {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
async getVersions(versionId, count) {
|
|
40
|
+
const id = versionId ? versionId : this.id;
|
|
41
|
+
const commits = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
42
|
+
eventName: "getVersions",
|
|
43
|
+
versionId: id,
|
|
44
|
+
count,
|
|
45
|
+
}, async () => this.manager.getCommits(id, count));
|
|
46
|
+
return commits.map((commit) => ({
|
|
47
|
+
date: commit.commit.author.date,
|
|
48
|
+
id: commit.sha,
|
|
49
|
+
treeId: commit.commit.tree.sha,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
async getSnapshotTree(version) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
let requestVersion = version;
|
|
55
|
+
if (!requestVersion) {
|
|
56
|
+
const versions = await this.getVersions(this.id, 1);
|
|
57
|
+
if (versions.length === 0) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
requestVersion = versions[0];
|
|
61
|
+
}
|
|
62
|
+
const cachedSnapshotTree = await ((_a = this.snapshotTreeCache) === null || _a === void 0 ? void 0 : _a.get(requestVersion.treeId));
|
|
63
|
+
if (cachedSnapshotTree) {
|
|
64
|
+
return cachedSnapshotTree;
|
|
65
|
+
}
|
|
66
|
+
const rawTree = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
67
|
+
eventName: "getSnapshotTree",
|
|
68
|
+
treeId: requestVersion.treeId,
|
|
69
|
+
}, async (event) => {
|
|
70
|
+
const response = await this.manager.getTree(requestVersion.treeId);
|
|
71
|
+
event.end({
|
|
72
|
+
size: response.tree.length,
|
|
73
|
+
});
|
|
74
|
+
return response;
|
|
75
|
+
});
|
|
76
|
+
const tree = protocol_base_1.buildHierarchy(rawTree, this.blobsShaCache, true);
|
|
77
|
+
await ((_b = this.snapshotTreeCache) === null || _b === void 0 ? void 0 : _b.put(tree.id, tree));
|
|
78
|
+
return tree;
|
|
79
|
+
}
|
|
80
|
+
async readBlob(blobId) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const cachedBlob = await ((_a = this.blobCache) === null || _a === void 0 ? void 0 : _a.get(blobId));
|
|
83
|
+
if (cachedBlob) {
|
|
84
|
+
return cachedBlob;
|
|
85
|
+
}
|
|
86
|
+
const value = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
87
|
+
eventName: "readBlob",
|
|
88
|
+
blobId,
|
|
89
|
+
}, async (event) => {
|
|
90
|
+
const response = await this.manager.getBlob(blobId);
|
|
91
|
+
event.end({
|
|
92
|
+
size: response.size,
|
|
93
|
+
});
|
|
94
|
+
return response;
|
|
95
|
+
});
|
|
96
|
+
this.blobsShaCache.set(value.sha, "");
|
|
97
|
+
const bufferContent = common_utils_1.stringToBuffer(value.content, value.encoding);
|
|
98
|
+
await ((_b = this.blobCache) === null || _b === void 0 ? void 0 : _b.put(value.sha, bufferContent));
|
|
99
|
+
return bufferContent;
|
|
100
|
+
}
|
|
101
|
+
async write(tree, parents, message, ref) {
|
|
102
|
+
const branch = ref ? `datastores/${this.id}/${ref}` : this.id;
|
|
103
|
+
const commit = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
104
|
+
eventName: "write",
|
|
105
|
+
id: branch,
|
|
106
|
+
}, async () => this.manager.write(branch, tree, parents, message));
|
|
107
|
+
return { date: commit.committer.date, id: commit.sha, treeId: commit.tree.sha };
|
|
108
|
+
}
|
|
109
|
+
async uploadSummaryWithContext(summary, context) {
|
|
110
|
+
const summaryHandle = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
111
|
+
eventName: "uploadSummaryWithContext",
|
|
112
|
+
}, async () => { var _a; return this.summaryUploadManager.writeSummaryTree(summary, (_a = context.ackHandle) !== null && _a !== void 0 ? _a : "", "channel"); });
|
|
113
|
+
return summaryHandle;
|
|
114
|
+
}
|
|
115
|
+
async downloadSummary(handle) {
|
|
116
|
+
throw new Error("NOT IMPLEMENTED!");
|
|
117
|
+
}
|
|
118
|
+
async createBlob(file) {
|
|
119
|
+
const uint8ArrayFile = new Uint8Array(file);
|
|
120
|
+
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
121
|
+
eventName: "createBlob",
|
|
122
|
+
size: uint8ArrayFile.length,
|
|
123
|
+
}, async (event) => {
|
|
124
|
+
const response = await this.manager.createBlob(common_utils_1.Uint8ArrayToString(uint8ArrayFile, "base64"), "base64").then((r) => ({ id: r.sha, url: r.url }));
|
|
125
|
+
event.end({
|
|
126
|
+
blobId: response.id,
|
|
127
|
+
});
|
|
128
|
+
return response;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async getPreviousFullSnapshot(parentHandle) {
|
|
132
|
+
return parentHandle
|
|
133
|
+
? this.getVersions(parentHandle, 1)
|
|
134
|
+
.then(async (versions) => {
|
|
135
|
+
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
136
|
+
this.blobsShaCache.clear();
|
|
137
|
+
return this.getSnapshotTree(versions[0]);
|
|
138
|
+
})
|
|
139
|
+
: undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.ShreddedSummaryDocumentStorageService = ShreddedSummaryDocumentStorageService;
|
|
143
|
+
//# sourceMappingURL=shreddedSummaryDocumentStorageService.js.map
|