@fluidframework/runtime-utils 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1
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 +5 -7
- package/.mocharc.js +2 -2
- package/api-extractor.json +2 -2
- package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/dist/dataStoreHandleContextUtils.js +3 -1
- package/dist/dataStoreHandleContextUtils.js.map +1 -1
- package/dist/dataStoreHelpers.d.ts.map +1 -1
- package/dist/dataStoreHelpers.js +23 -7
- package/dist/dataStoreHelpers.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/objectstoragepartition.d.ts.map +1 -1
- package/dist/objectstoragepartition.js.map +1 -1
- package/dist/objectstorageutils.d.ts.map +1 -1
- package/dist/objectstorageutils.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/requestParser.d.ts.map +1 -1
- package/dist/requestParser.js.map +1 -1
- package/dist/runtimeFactoryHelper.d.ts.map +1 -1
- package/dist/runtimeFactoryHelper.js +6 -2
- package/dist/runtimeFactoryHelper.js.map +1 -1
- package/dist/summarizerNode/summarizerNode.d.ts +1 -1
- package/dist/summarizerNode/summarizerNode.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNode.js +12 -9
- package/dist/summarizerNode/summarizerNode.js.map +1 -1
- package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/dist/summarizerNode/summarizerNodeWithGc.js +24 -16
- package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/dist/summaryUtils.d.ts +0 -4
- package/dist/summaryUtils.d.ts.map +1 -1
- package/dist/summaryUtils.js +3 -11
- package/dist/summaryUtils.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/lib/dataStoreHandleContextUtils.js +3 -1
- package/lib/dataStoreHandleContextUtils.js.map +1 -1
- package/lib/dataStoreHelpers.d.ts.map +1 -1
- package/lib/dataStoreHelpers.js +23 -7
- package/lib/dataStoreHelpers.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/objectstoragepartition.d.ts.map +1 -1
- package/lib/objectstoragepartition.js.map +1 -1
- package/lib/objectstorageutils.d.ts.map +1 -1
- package/lib/objectstorageutils.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/requestParser.d.ts.map +1 -1
- package/lib/requestParser.js.map +1 -1
- package/lib/runtimeFactoryHelper.d.ts.map +1 -1
- package/lib/runtimeFactoryHelper.js +6 -2
- package/lib/runtimeFactoryHelper.js.map +1 -1
- package/lib/summarizerNode/summarizerNode.d.ts +1 -1
- package/lib/summarizerNode/summarizerNode.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNode.js +12 -9
- package/lib/summarizerNode/summarizerNode.js.map +1 -1
- package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/lib/summarizerNode/summarizerNodeWithGc.js +25 -17
- package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/lib/summaryUtils.d.ts +0 -4
- package/lib/summaryUtils.d.ts.map +1 -1
- package/lib/summaryUtils.js +3 -11
- package/lib/summaryUtils.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +110 -112
- package/prettier.config.cjs +1 -1
- package/src/dataStoreHandleContextUtils.ts +23 -16
- package/src/dataStoreHelpers.ts +104 -86
- package/src/index.ts +2 -2
- package/src/objectstoragepartition.ts +13 -13
- package/src/objectstorageutils.ts +31 -28
- package/src/packageVersion.ts +1 -1
- package/src/requestParser.ts +80 -82
- package/src/runtimeFactoryHelper.ts +24 -17
- package/src/summarizerNode/summarizerNode.ts +602 -574
- package/src/summarizerNode/summarizerNodeUtils.ts +154 -151
- package/src/summarizerNode/summarizerNodeWithGc.ts +508 -472
- package/src/summaryUtils.ts +299 -305
- package/src/utils.ts +6 -6
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
package/src/summaryUtils.ts
CHANGED
|
@@ -5,28 +5,28 @@
|
|
|
5
5
|
|
|
6
6
|
import { TelemetryEventPropertyType } from "@fluidframework/common-definitions";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
bufferToString,
|
|
9
|
+
fromBase64ToUtf8,
|
|
10
|
+
IsoBuffer,
|
|
11
|
+
Uint8ArrayToString,
|
|
12
|
+
unreachableCase,
|
|
13
13
|
} from "@fluidframework/common-utils";
|
|
14
14
|
import { AttachmentTreeEntry, BlobTreeEntry, TreeTreeEntry } from "@fluidframework/protocol-base";
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
ITree,
|
|
17
|
+
SummaryType,
|
|
18
|
+
ISummaryTree,
|
|
19
|
+
SummaryObject,
|
|
20
|
+
ISummaryBlob,
|
|
21
|
+
TreeEntry,
|
|
22
|
+
ITreeEntry,
|
|
23
|
+
ISnapshotTree,
|
|
24
24
|
} from "@fluidframework/protocol-definitions";
|
|
25
25
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
ISummaryStats,
|
|
27
|
+
ISummarizeResult,
|
|
28
|
+
ISummaryTreeWithStats,
|
|
29
|
+
ITelemetryContext,
|
|
30
30
|
} from "@fluidframework/runtime-definitions";
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -35,153 +35,167 @@ import {
|
|
|
35
35
|
* @param stats - stats to merge
|
|
36
36
|
*/
|
|
37
37
|
export function mergeStats(...stats: ISummaryStats[]): ISummaryStats {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
const results = {
|
|
39
|
+
treeNodeCount: 0,
|
|
40
|
+
blobNodeCount: 0,
|
|
41
|
+
handleNodeCount: 0,
|
|
42
|
+
totalBlobSize: 0,
|
|
43
|
+
unreferencedBlobSize: 0,
|
|
44
|
+
};
|
|
45
|
+
for (const stat of stats) {
|
|
46
|
+
results.treeNodeCount += stat.treeNodeCount;
|
|
47
|
+
results.blobNodeCount += stat.blobNodeCount;
|
|
48
|
+
results.handleNodeCount += stat.handleNodeCount;
|
|
49
|
+
results.totalBlobSize += stat.totalBlobSize;
|
|
50
|
+
results.unreferencedBlobSize += stat.unreferencedBlobSize;
|
|
51
|
+
}
|
|
52
|
+
return results;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export function utf8ByteLength(str: string): number {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
// returns the byte length of an utf8 string
|
|
57
|
+
let s = str.length;
|
|
58
|
+
for (let i = str.length - 1; i >= 0; i--) {
|
|
59
|
+
const code = str.charCodeAt(i);
|
|
60
|
+
if (code > 0x7f && code <= 0x7ff) {
|
|
61
|
+
s++;
|
|
62
|
+
} else if (code > 0x7ff && code <= 0xffff) {
|
|
63
|
+
s += 2;
|
|
64
|
+
}
|
|
65
|
+
if (code >= 0xdc00 && code <= 0xdfff) {
|
|
66
|
+
i--; // trail surrogate
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return s;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export function getBlobSize(content: ISummaryBlob["content"]): number {
|
|
73
|
-
|
|
73
|
+
return typeof content === "string" ? utf8ByteLength(content) : content.byteLength;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
function calculateStatsCore(summaryObject: SummaryObject, stats: ISummaryStats): void {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
switch (summaryObject.type) {
|
|
78
|
+
case SummaryType.Tree: {
|
|
79
|
+
stats.treeNodeCount++;
|
|
80
|
+
for (const value of Object.values(summaryObject.tree)) {
|
|
81
|
+
calculateStatsCore(value, stats);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
case SummaryType.Handle: {
|
|
86
|
+
stats.handleNodeCount++;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
case SummaryType.Blob: {
|
|
90
|
+
stats.blobNodeCount++;
|
|
91
|
+
stats.totalBlobSize += getBlobSize(summaryObject.content);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
export function calculateStats(summary: SummaryObject): ISummaryStats {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const stats = mergeStats();
|
|
101
|
+
calculateStatsCore(summary, stats);
|
|
102
|
+
return stats;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
export function addBlobToSummary(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
export function addBlobToSummary(
|
|
106
|
+
summary: ISummaryTreeWithStats,
|
|
107
|
+
key: string,
|
|
108
|
+
content: string | Uint8Array,
|
|
109
|
+
): void {
|
|
110
|
+
const blob: ISummaryBlob = {
|
|
111
|
+
type: SummaryType.Blob,
|
|
112
|
+
content,
|
|
113
|
+
};
|
|
114
|
+
summary.summary.tree[key] = blob;
|
|
115
|
+
summary.stats.blobNodeCount++;
|
|
116
|
+
summary.stats.totalBlobSize += getBlobSize(content);
|
|
112
117
|
}
|
|
113
118
|
|
|
114
|
-
export function addTreeToSummary(
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
export function addTreeToSummary(
|
|
120
|
+
summary: ISummaryTreeWithStats,
|
|
121
|
+
key: string,
|
|
122
|
+
summarizeResult: ISummarizeResult,
|
|
123
|
+
): void {
|
|
124
|
+
summary.summary.tree[key] = summarizeResult.summary;
|
|
125
|
+
summary.stats = mergeStats(summary.stats, summarizeResult.stats);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
export function addSummarizeResultToSummary(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
summary: ISummaryTreeWithStats,
|
|
130
|
+
key: string,
|
|
131
|
+
summarizeResult: ISummarizeResult,
|
|
123
132
|
): void {
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
summary.summary.tree[key] = summarizeResult.summary;
|
|
134
|
+
summary.stats = mergeStats(summary.stats, summarizeResult.stats);
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
export class SummaryTreeBuilder implements ISummaryTreeWithStats {
|
|
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
|
-
|
|
138
|
+
private attachmentCounter: number = 0;
|
|
139
|
+
|
|
140
|
+
public get summary(): ISummaryTree {
|
|
141
|
+
return {
|
|
142
|
+
type: SummaryType.Tree,
|
|
143
|
+
tree: { ...this.summaryTree },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public get stats(): Readonly<ISummaryStats> {
|
|
148
|
+
return { ...this.summaryStats };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
constructor() {
|
|
152
|
+
this.summaryStats = mergeStats();
|
|
153
|
+
this.summaryStats.treeNodeCount++;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private readonly summaryTree: { [path: string]: SummaryObject } = {};
|
|
157
|
+
private summaryStats: ISummaryStats;
|
|
158
|
+
|
|
159
|
+
public addBlob(key: string, content: string | Uint8Array): void {
|
|
160
|
+
// Prevent cloning by directly referencing underlying private properties
|
|
161
|
+
addBlobToSummary(
|
|
162
|
+
{
|
|
163
|
+
summary: {
|
|
164
|
+
type: SummaryType.Tree,
|
|
165
|
+
tree: this.summaryTree,
|
|
166
|
+
},
|
|
167
|
+
stats: this.summaryStats,
|
|
168
|
+
},
|
|
169
|
+
key,
|
|
170
|
+
content,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public addHandle(
|
|
175
|
+
key: string,
|
|
176
|
+
handleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment,
|
|
177
|
+
handle: string,
|
|
178
|
+
): void {
|
|
179
|
+
this.summaryTree[key] = {
|
|
180
|
+
type: SummaryType.Handle,
|
|
181
|
+
handleType,
|
|
182
|
+
handle,
|
|
183
|
+
};
|
|
184
|
+
this.summaryStats.handleNodeCount++;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public addWithStats(key: string, summarizeResult: ISummarizeResult): void {
|
|
188
|
+
this.summaryTree[key] = summarizeResult.summary;
|
|
189
|
+
this.summaryStats = mergeStats(this.summaryStats, summarizeResult.stats);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public addAttachment(id: string) {
|
|
193
|
+
this.summaryTree[this.attachmentCounter++] = { id, type: SummaryType.Attachment };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public getSummaryTree(): ISummaryTreeWithStats {
|
|
197
|
+
return { summary: this.summary, stats: this.stats };
|
|
198
|
+
}
|
|
185
199
|
}
|
|
186
200
|
|
|
187
201
|
/**
|
|
@@ -190,45 +204,44 @@ export class SummaryTreeBuilder implements ISummaryTreeWithStats {
|
|
|
190
204
|
* @param fullTree - true to never use handles, even if id is specified
|
|
191
205
|
*/
|
|
192
206
|
export function convertToSummaryTreeWithStats(
|
|
193
|
-
|
|
194
|
-
|
|
207
|
+
snapshot: ITree,
|
|
208
|
+
fullTree: boolean = false,
|
|
195
209
|
): ISummaryTreeWithStats {
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return summaryTree;
|
|
210
|
+
const builder = new SummaryTreeBuilder();
|
|
211
|
+
for (const entry of snapshot.entries) {
|
|
212
|
+
switch (entry.type) {
|
|
213
|
+
case TreeEntry.Blob: {
|
|
214
|
+
const blob = entry.value;
|
|
215
|
+
const content =
|
|
216
|
+
blob.encoding === "base64"
|
|
217
|
+
? IsoBuffer.from(blob.contents, "base64")
|
|
218
|
+
: blob.contents;
|
|
219
|
+
builder.addBlob(entry.path, content);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
case TreeEntry.Tree: {
|
|
224
|
+
const subtree = convertToSummaryTree(entry.value, fullTree);
|
|
225
|
+
builder.addWithStats(entry.path, subtree);
|
|
226
|
+
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
case TreeEntry.Attachment: {
|
|
231
|
+
const id = entry.value.id;
|
|
232
|
+
builder.addAttachment(id);
|
|
233
|
+
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
default:
|
|
238
|
+
throw new Error("Unexpected TreeEntry type");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const summaryTree = builder.getSummaryTree();
|
|
243
|
+
summaryTree.summary.unreferenced = snapshot.unreferenced;
|
|
244
|
+
return summaryTree;
|
|
232
245
|
}
|
|
233
246
|
|
|
234
247
|
/**
|
|
@@ -236,25 +249,22 @@ export function convertToSummaryTreeWithStats(
|
|
|
236
249
|
* @param snapshot - snapshot in ITree format
|
|
237
250
|
* @param fullTree - true to never use handles, even if id is specified
|
|
238
251
|
*/
|
|
239
|
-
export function convertToSummaryTree(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
} else {
|
|
256
|
-
return convertToSummaryTreeWithStats(snapshot, fullTree);
|
|
257
|
-
}
|
|
252
|
+
export function convertToSummaryTree(snapshot: ITree, fullTree: boolean = false): ISummarizeResult {
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
254
|
+
if (snapshot.id && !fullTree) {
|
|
255
|
+
const stats = mergeStats();
|
|
256
|
+
stats.handleNodeCount++;
|
|
257
|
+
return {
|
|
258
|
+
summary: {
|
|
259
|
+
handle: snapshot.id,
|
|
260
|
+
handleType: SummaryType.Tree,
|
|
261
|
+
type: SummaryType.Handle,
|
|
262
|
+
},
|
|
263
|
+
stats,
|
|
264
|
+
};
|
|
265
|
+
} else {
|
|
266
|
+
return convertToSummaryTreeWithStats(snapshot, fullTree);
|
|
267
|
+
}
|
|
258
268
|
}
|
|
259
269
|
|
|
260
270
|
/**
|
|
@@ -262,35 +272,33 @@ export function convertToSummaryTree(
|
|
|
262
272
|
* was taken by serialize api in detached container.
|
|
263
273
|
* @param snapshot - snapshot in ISnapshotTree format
|
|
264
274
|
*/
|
|
265
|
-
export function convertSnapshotTreeToSummaryTree(
|
|
266
|
-
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
summaryTree.summary.unreferenced = snapshot.unreferenced;
|
|
293
|
-
return summaryTree;
|
|
275
|
+
export function convertSnapshotTreeToSummaryTree(snapshot: ISnapshotTree): ISummaryTreeWithStats {
|
|
276
|
+
const builder = new SummaryTreeBuilder();
|
|
277
|
+
for (const [path, id] of Object.entries(snapshot.blobs)) {
|
|
278
|
+
let decoded: string | undefined;
|
|
279
|
+
if ((snapshot as any).blobsContents !== undefined) {
|
|
280
|
+
const content: ArrayBufferLike = (snapshot as any).blobsContents[id];
|
|
281
|
+
if (content !== undefined) {
|
|
282
|
+
decoded = bufferToString(content, "utf-8");
|
|
283
|
+
}
|
|
284
|
+
// 0.44 back-compat We still put contents in same blob for back-compat so need to add blob
|
|
285
|
+
// only for blobPath -> blobId mapping and not for blobId -> blob value contents.
|
|
286
|
+
} else if (snapshot.blobs[id] !== undefined) {
|
|
287
|
+
decoded = fromBase64ToUtf8(snapshot.blobs[id]);
|
|
288
|
+
}
|
|
289
|
+
if (decoded !== undefined) {
|
|
290
|
+
builder.addBlob(path, decoded);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
for (const [key, tree] of Object.entries(snapshot.trees)) {
|
|
295
|
+
const subtree = convertSnapshotTreeToSummaryTree(tree);
|
|
296
|
+
builder.addWithStats(key, subtree);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const summaryTree = builder.getSummaryTree();
|
|
300
|
+
summaryTree.summary.unreferenced = snapshot.unreferenced;
|
|
301
|
+
return summaryTree;
|
|
294
302
|
}
|
|
295
303
|
|
|
296
304
|
/**
|
|
@@ -298,85 +306,71 @@ export function convertSnapshotTreeToSummaryTree(
|
|
|
298
306
|
* @param summaryTree - summary tree in ISummaryTree format
|
|
299
307
|
*/
|
|
300
308
|
export function convertSummaryTreeToITree(summaryTree: ISummaryTree): ITree {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
309
|
+
const entries: ITreeEntry[] = [];
|
|
310
|
+
for (const [key, value] of Object.entries(summaryTree.tree)) {
|
|
311
|
+
switch (value.type) {
|
|
312
|
+
case SummaryType.Blob: {
|
|
313
|
+
let parsedContent: string;
|
|
314
|
+
let encoding: "utf-8" | "base64" = "utf-8";
|
|
315
|
+
if (typeof value.content === "string") {
|
|
316
|
+
parsedContent = value.content;
|
|
317
|
+
} else {
|
|
318
|
+
parsedContent = Uint8ArrayToString(value.content, "base64");
|
|
319
|
+
encoding = "base64";
|
|
320
|
+
}
|
|
321
|
+
entries.push(new BlobTreeEntry(key, parsedContent, encoding));
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
case SummaryType.Tree: {
|
|
326
|
+
entries.push(new TreeTreeEntry(key, convertSummaryTreeToITree(value)));
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
case SummaryType.Attachment: {
|
|
331
|
+
entries.push(new AttachmentTreeEntry(key, value.id));
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
case SummaryType.Handle: {
|
|
336
|
+
throw new Error("Should not have Handle type in summary tree");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
default:
|
|
340
|
+
unreachableCase(value, "Unexpected summary tree type");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
entries,
|
|
345
|
+
unreferenced: summaryTree.unreferenced,
|
|
346
|
+
};
|
|
339
347
|
}
|
|
340
348
|
|
|
341
349
|
export class TelemetryContext implements ITelemetryContext {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
get(prefix: string, property: string): TelemetryEventPropertyType {
|
|
369
|
-
return this.telemetry.get(`${prefix}${property}`);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.serialize}
|
|
374
|
-
*/
|
|
375
|
-
serialize(): string {
|
|
376
|
-
const jsonObject = {};
|
|
377
|
-
this.telemetry.forEach((value, key) => {
|
|
378
|
-
jsonObject[key] = value;
|
|
379
|
-
});
|
|
380
|
-
return JSON.stringify(jsonObject);
|
|
381
|
-
}
|
|
350
|
+
private readonly telemetry = new Map<string, TelemetryEventPropertyType>();
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.set}
|
|
354
|
+
*/
|
|
355
|
+
set(prefix: string, property: string, value: TelemetryEventPropertyType): void {
|
|
356
|
+
this.telemetry.set(`${prefix}${property}`, value);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.get}
|
|
361
|
+
*/
|
|
362
|
+
get(prefix: string, property: string): TelemetryEventPropertyType {
|
|
363
|
+
return this.telemetry.get(`${prefix}${property}`);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.serialize}
|
|
368
|
+
*/
|
|
369
|
+
serialize(): string {
|
|
370
|
+
const jsonObject = {};
|
|
371
|
+
this.telemetry.forEach((value, key) => {
|
|
372
|
+
jsonObject[key] = value;
|
|
373
|
+
});
|
|
374
|
+
return JSON.stringify(jsonObject);
|
|
375
|
+
}
|
|
382
376
|
}
|