@fluidframework/runtime-utils 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -7
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +191 -0
- package/README.md +68 -1
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/runtime-utils.api.md +201 -0
- package/dist/{dataStoreHandleContextUtils.js → dataStoreHandleContextUtils.cjs} +5 -2
- package/dist/dataStoreHandleContextUtils.cjs.map +1 -0
- package/dist/dataStoreHandleContextUtils.d.ts +1 -0
- package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
- package/dist/{dataStoreHelpers.js → dataStoreHelpers.cjs} +44 -25
- package/dist/dataStoreHelpers.cjs.map +1 -0
- package/dist/dataStoreHelpers.d.ts +23 -4
- package/dist/dataStoreHelpers.d.ts.map +1 -1
- package/dist/index.cjs +44 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/{objectstoragepartition.js → objectstoragepartition.cjs} +4 -3
- package/dist/objectstoragepartition.cjs.map +1 -0
- package/dist/objectstoragepartition.d.ts +1 -0
- package/dist/objectstoragepartition.d.ts.map +1 -1
- package/dist/{objectstorageutils.js → objectstorageutils.cjs} +11 -15
- package/dist/objectstorageutils.cjs.map +1 -0
- package/dist/objectstorageutils.d.ts +6 -0
- package/dist/objectstorageutils.d.ts.map +1 -1
- package/dist/{requestParser.js → requestParser.cjs} +7 -11
- package/dist/requestParser.cjs.map +1 -0
- package/dist/requestParser.d.ts +1 -0
- package/dist/requestParser.d.ts.map +1 -1
- package/dist/runtime-utils-alpha.d.ts +155 -0
- package/dist/runtime-utils-beta.d.ts +103 -0
- package/dist/runtime-utils-public.d.ts +103 -0
- package/dist/runtime-utils-untrimmed.d.ts +306 -0
- package/dist/{runtimeFactoryHelper.js → runtimeFactoryHelper.cjs} +11 -12
- package/dist/runtimeFactoryHelper.cjs.map +1 -0
- package/dist/runtimeFactoryHelper.d.ts +4 -1
- package/dist/runtimeFactoryHelper.d.ts.map +1 -1
- package/dist/{summaryUtils.js → summaryUtils.cjs} +138 -34
- package/dist/summaryUtils.cjs.map +1 -0
- package/dist/summaryUtils.d.ts +66 -4
- package/dist/summaryUtils.d.ts.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/unpackUsedRoutes.cjs +34 -0
- package/dist/unpackUsedRoutes.cjs.map +1 -0
- package/dist/unpackUsedRoutes.d.ts +12 -0
- package/dist/unpackUsedRoutes.d.ts.map +1 -0
- package/dist/{utils.js → utils.cjs} +2 -1
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +7 -2
- package/dist/utils.d.ts.map +1 -1
- package/lib/{dataStoreHandleContextUtils.d.ts → dataStoreHandleContextUtils.d.mts} +1 -0
- package/lib/dataStoreHandleContextUtils.d.mts.map +1 -0
- package/lib/{dataStoreHandleContextUtils.js → dataStoreHandleContextUtils.mjs} +5 -2
- package/lib/dataStoreHandleContextUtils.mjs.map +1 -0
- package/lib/{dataStoreHelpers.d.ts → dataStoreHelpers.d.mts} +23 -4
- package/lib/dataStoreHelpers.d.mts.map +1 -0
- package/lib/{dataStoreHelpers.js → dataStoreHelpers.mjs} +42 -22
- package/lib/dataStoreHelpers.mjs.map +1 -0
- package/lib/index.d.mts +14 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +14 -0
- package/lib/index.mjs.map +1 -0
- package/lib/{objectstoragepartition.d.ts → objectstoragepartition.d.mts} +1 -0
- package/lib/objectstoragepartition.d.mts.map +1 -0
- package/lib/{objectstoragepartition.js → objectstoragepartition.mjs} +3 -2
- package/lib/objectstoragepartition.mjs.map +1 -0
- package/lib/{objectstorageutils.d.ts → objectstorageutils.d.mts} +6 -0
- package/lib/objectstorageutils.d.mts.map +1 -0
- package/lib/{objectstorageutils.js → objectstorageutils.mjs} +11 -15
- package/lib/objectstorageutils.mjs.map +1 -0
- package/lib/{requestParser.d.ts → requestParser.d.mts} +1 -4
- package/lib/requestParser.d.mts.map +1 -0
- package/lib/{requestParser.js → requestParser.mjs} +7 -11
- package/lib/requestParser.mjs.map +1 -0
- package/lib/runtime-utils-alpha.d.mts +155 -0
- package/lib/runtime-utils-beta.d.mts +103 -0
- package/lib/runtime-utils-public.d.mts +103 -0
- package/lib/runtime-utils-untrimmed.d.mts +306 -0
- package/lib/{runtimeFactoryHelper.d.ts → runtimeFactoryHelper.d.mts} +4 -1
- package/lib/runtimeFactoryHelper.d.mts.map +1 -0
- package/lib/runtimeFactoryHelper.mjs +24 -0
- package/lib/runtimeFactoryHelper.mjs.map +1 -0
- package/lib/{summaryUtils.d.ts → summaryUtils.d.mts} +66 -4
- package/lib/summaryUtils.d.mts.map +1 -0
- package/lib/{summaryUtils.js → summaryUtils.mjs} +129 -26
- package/lib/summaryUtils.mjs.map +1 -0
- package/lib/unpackUsedRoutes.d.mts +12 -0
- package/lib/unpackUsedRoutes.d.mts.map +1 -0
- package/lib/unpackUsedRoutes.mjs +30 -0
- package/lib/unpackUsedRoutes.mjs.map +1 -0
- package/lib/{utils.d.ts → utils.d.mts} +7 -2
- package/lib/utils.d.mts.map +1 -0
- package/lib/{utils.js → utils.mjs} +2 -1
- package/lib/utils.mjs.map +1 -0
- package/package.json +102 -66
- package/prettier.config.cjs +8 -0
- package/src/dataStoreHandleContextUtils.ts +24 -16
- package/src/dataStoreHelpers.ts +106 -83
- package/src/index.ts +31 -9
- package/src/objectstoragepartition.ts +18 -14
- package/src/objectstorageutils.ts +37 -36
- package/src/requestParser.ts +81 -86
- package/src/runtimeFactoryHelper.ts +27 -26
- package/src/summaryUtils.ts +425 -299
- package/src/unpackUsedRoutes.ts +31 -0
- package/src/utils.ts +12 -7
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +10 -12
- package/dist/dataStoreHandleContextUtils.js.map +0 -1
- package/dist/dataStoreHelpers.js.map +0 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/objectstoragepartition.js.map +0 -1
- package/dist/objectstorageutils.js.map +0 -1
- package/dist/packageVersion.d.ts +0 -9
- package/dist/packageVersion.d.ts.map +0 -1
- package/dist/packageVersion.js +0 -12
- package/dist/packageVersion.js.map +0 -1
- package/dist/requestParser.js.map +0 -1
- package/dist/runtimeFactoryHelper.js.map +0 -1
- package/dist/summarizerNode/index.d.ts +0 -8
- package/dist/summarizerNode/index.d.ts.map +0 -1
- package/dist/summarizerNode/index.js +0 -12
- package/dist/summarizerNode/index.js.map +0 -1
- package/dist/summarizerNode/summarizerNode.d.ts +0 -139
- package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNode.js +0 -480
- package/dist/summarizerNode/summarizerNode.js.map +0 -1
- package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -161
- package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNodeUtils.js +0 -225
- package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -133
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNodeWithGc.js +0 -294
- package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
- package/dist/summaryUtils.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/lib/dataStoreHandleContextUtils.d.ts.map +0 -1
- package/lib/dataStoreHandleContextUtils.js.map +0 -1
- package/lib/dataStoreHelpers.d.ts.map +0 -1
- package/lib/dataStoreHelpers.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -14
- package/lib/index.js.map +0 -1
- package/lib/objectstoragepartition.d.ts.map +0 -1
- package/lib/objectstoragepartition.js.map +0 -1
- package/lib/objectstorageutils.d.ts.map +0 -1
- package/lib/objectstorageutils.js.map +0 -1
- package/lib/packageVersion.d.ts +0 -9
- package/lib/packageVersion.d.ts.map +0 -1
- package/lib/packageVersion.js +0 -9
- package/lib/packageVersion.js.map +0 -1
- package/lib/requestParser.d.ts.map +0 -1
- package/lib/requestParser.js.map +0 -1
- package/lib/runtimeFactoryHelper.d.ts.map +0 -1
- package/lib/runtimeFactoryHelper.js +0 -25
- package/lib/runtimeFactoryHelper.js.map +0 -1
- package/lib/summarizerNode/index.d.ts +0 -8
- package/lib/summarizerNode/index.d.ts.map +0 -1
- package/lib/summarizerNode/index.js +0 -7
- package/lib/summarizerNode/index.js.map +0 -1
- package/lib/summarizerNode/summarizerNode.d.ts +0 -139
- package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNode.js +0 -475
- package/lib/summarizerNode/summarizerNode.js.map +0 -1
- package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -161
- package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNodeUtils.js +0 -216
- package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -133
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNodeWithGc.js +0 -289
- package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
- package/lib/summaryUtils.d.ts.map +0 -1
- package/lib/summaryUtils.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/src/packageVersion.ts +0 -9
- package/src/summarizerNode/index.ts +0 -8
- package/src/summarizerNode/summarizerNode.ts +0 -662
- package/src/summarizerNode/summarizerNodeUtils.ts +0 -339
- package/src/summarizerNode/summarizerNodeWithGc.ts +0 -459
- package/tsconfig.esnext.json +0 -7
|
@@ -2,21 +2,44 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { TelemetryEventPropertyType } from "@fluidframework/
|
|
6
|
-
import { ITree, SummaryType, ISummaryTree, SummaryObject, ISummaryBlob
|
|
7
|
-
import { ISummaryStats, ISummarizeResult, ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
|
|
5
|
+
import { TelemetryEventPropertyType } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { ITree, SummaryType, ISummaryTree, SummaryObject, ISummaryBlob } from "@fluidframework/protocol-definitions";
|
|
7
|
+
import { ISummaryStats, ISummarizeResult, ISummaryTreeWithStats, ITelemetryContext, IGarbageCollectionData } from "@fluidframework/runtime-definitions";
|
|
8
|
+
import { ISnapshotTreeWithBlobContents } from "@fluidframework/container-definitions";
|
|
8
9
|
/**
|
|
9
10
|
* Combines summary stats by adding their totals together.
|
|
10
11
|
* Returns empty stats if called without args.
|
|
11
12
|
* @param stats - stats to merge
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
15
|
export declare function mergeStats(...stats: ISummaryStats[]): ISummaryStats;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
14
19
|
export declare function utf8ByteLength(str: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
15
23
|
export declare function getBlobSize(content: ISummaryBlob["content"]): number;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
16
27
|
export declare function calculateStats(summary: SummaryObject): ISummaryStats;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
17
31
|
export declare function addBlobToSummary(summary: ISummaryTreeWithStats, key: string, content: string | Uint8Array): void;
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
18
35
|
export declare function addTreeToSummary(summary: ISummaryTreeWithStats, key: string, summarizeResult: ISummarizeResult): void;
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
19
39
|
export declare function addSummarizeResultToSummary(summary: ISummaryTreeWithStats, key: string, summarizeResult: ISummarizeResult): void;
|
|
40
|
+
/**
|
|
41
|
+
* @alpha
|
|
42
|
+
*/
|
|
20
43
|
export declare class SummaryTreeBuilder implements ISummaryTreeWithStats {
|
|
21
44
|
private attachmentCounter;
|
|
22
45
|
get summary(): ISummaryTree;
|
|
@@ -34,31 +57,42 @@ export declare class SummaryTreeBuilder implements ISummaryTreeWithStats {
|
|
|
34
57
|
* Converts snapshot ITree to ISummaryTree format and tracks stats.
|
|
35
58
|
* @param snapshot - snapshot in ITree format
|
|
36
59
|
* @param fullTree - true to never use handles, even if id is specified
|
|
60
|
+
* @alpha
|
|
37
61
|
*/
|
|
38
62
|
export declare function convertToSummaryTreeWithStats(snapshot: ITree, fullTree?: boolean): ISummaryTreeWithStats;
|
|
39
63
|
/**
|
|
40
64
|
* Converts snapshot ITree to ISummaryTree format and tracks stats.
|
|
41
65
|
* @param snapshot - snapshot in ITree format
|
|
42
66
|
* @param fullTree - true to never use handles, even if id is specified
|
|
67
|
+
* @internal
|
|
43
68
|
*/
|
|
44
69
|
export declare function convertToSummaryTree(snapshot: ITree, fullTree?: boolean): ISummarizeResult;
|
|
45
70
|
/**
|
|
46
71
|
* Converts ISnapshotTree to ISummaryTree format and tracks stats. This snapshot tree was
|
|
47
72
|
* was taken by serialize api in detached container.
|
|
48
73
|
* @param snapshot - snapshot in ISnapshotTree format
|
|
74
|
+
* @internal
|
|
49
75
|
*/
|
|
50
|
-
export declare function convertSnapshotTreeToSummaryTree(snapshot:
|
|
76
|
+
export declare function convertSnapshotTreeToSummaryTree(snapshot: ISnapshotTreeWithBlobContents): ISummaryTreeWithStats;
|
|
51
77
|
/**
|
|
52
78
|
* Converts ISummaryTree to ITree format. This is needed for back-compat while we get rid of snapshot.
|
|
53
79
|
* @param summaryTree - summary tree in ISummaryTree format
|
|
80
|
+
* @internal
|
|
54
81
|
*/
|
|
55
82
|
export declare function convertSummaryTreeToITree(summaryTree: ISummaryTree): ITree;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
56
86
|
export declare class TelemetryContext implements ITelemetryContext {
|
|
57
87
|
private readonly telemetry;
|
|
58
88
|
/**
|
|
59
89
|
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.set}
|
|
60
90
|
*/
|
|
61
91
|
set(prefix: string, property: string, value: TelemetryEventPropertyType): void;
|
|
92
|
+
/**
|
|
93
|
+
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.setMultiple}
|
|
94
|
+
*/
|
|
95
|
+
setMultiple(prefix: string, property: string, values: Record<string, TelemetryEventPropertyType>): void;
|
|
62
96
|
/**
|
|
63
97
|
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.get}
|
|
64
98
|
*/
|
|
@@ -68,4 +102,32 @@ export declare class TelemetryContext implements ITelemetryContext {
|
|
|
68
102
|
*/
|
|
69
103
|
serialize(): string;
|
|
70
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Helper class to build the garbage collection data of a node by combining the data from multiple nodes.
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export declare class GCDataBuilder implements IGarbageCollectionData {
|
|
110
|
+
private readonly gcNodesSet;
|
|
111
|
+
get gcNodes(): {
|
|
112
|
+
[id: string]: string[];
|
|
113
|
+
};
|
|
114
|
+
addNode(id: string, outboundRoutes: string[]): void;
|
|
115
|
+
/**
|
|
116
|
+
* Adds the given GC nodes. It does the following:
|
|
117
|
+
* - Normalizes the ids of the given nodes.
|
|
118
|
+
* - Prefixes the given `prefixId` to the given nodes' ids.
|
|
119
|
+
* - Adds the outbound routes of the nodes against the normalized and prefixed id.
|
|
120
|
+
*/
|
|
121
|
+
prefixAndAddNodes(prefixId: string, gcNodes: {
|
|
122
|
+
[id: string]: string[];
|
|
123
|
+
}): void;
|
|
124
|
+
addNodes(gcNodes: {
|
|
125
|
+
[id: string]: string[];
|
|
126
|
+
}): void;
|
|
127
|
+
/**
|
|
128
|
+
* Adds the given outbound route to the outbound routes of all GC nodes.
|
|
129
|
+
*/
|
|
130
|
+
addRouteToAllNodes(outboundRoute: string): void;
|
|
131
|
+
getGCData(): IGarbageCollectionData;
|
|
132
|
+
}
|
|
71
133
|
//# sourceMappingURL=summaryUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summaryUtils.d.ts","sourceRoot":"","sources":["../src/summaryUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,0BAA0B,EAAE,MAAM,iCAAiC;OASrE,EACN,KAAK,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EAGZ,MAAM,sCAAsC;OACtC,EACN,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,qCAAqC;OACrC,EAAE,6BAA6B,EAAE,MAAM,uCAAuC;AAErF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,KAAK,EAAE,aAAa,EAAE,GAAG,aAAa,CAgBnE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAelD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,MAAM,CAEpE;AAyBD;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAIpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GAAG,UAAU,GAC1B,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,MAAM,EACX,eAAe,EAAE,gBAAgB,GAC/B,IAAI,CAGN;AAED;;GAEG;AACH,wBAAgB,2BAA2B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IACH,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,0BAA0B,GAAG,IAAI;IAI9E;;OAEG;IACH,WAAW,CACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,GAChD,IAAI;IAOP;;OAEG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,0BAA0B;IAIjE;;OAEG;IACH,SAAS,IAAI,MAAM;CAOnB;AAoBD;;;GAGG;AACH,qBAAa,aAAc,YAAW,sBAAsB;IAC3D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqC;IAChE,IAAW,OAAO,IAAI;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAM/C;IAEM,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE;IAInD;;;;;OAKG;IACI,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE;IAevE,QAAQ,CAAC,OAAO,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE;IAMnD;;OAEG;IACI,kBAAkB,CAAC,aAAa,EAAE,MAAM;IAMxC,SAAS,IAAI,sBAAsB;CAK1C"}
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { bufferToString, fromBase64ToUtf8, IsoBuffer, Uint8ArrayToString,
|
|
6
|
-
import {
|
|
5
|
+
import { bufferToString, fromBase64ToUtf8, IsoBuffer, Uint8ArrayToString, } from "@fluid-internal/client-utils";
|
|
6
|
+
import { unreachableCase } from "@fluidframework/core-utils";
|
|
7
|
+
import { AttachmentTreeEntry, BlobTreeEntry, TreeTreeEntry } from "@fluidframework/driver-utils";
|
|
7
8
|
import { SummaryType, TreeEntry, } from "@fluidframework/protocol-definitions";
|
|
8
9
|
/**
|
|
9
10
|
* Combines summary stats by adding their totals together.
|
|
10
11
|
* Returns empty stats if called without args.
|
|
11
12
|
* @param stats - stats to merge
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
15
|
export function mergeStats(...stats) {
|
|
14
16
|
const results = {
|
|
@@ -27,6 +29,9 @@ export function mergeStats(...stats) {
|
|
|
27
29
|
}
|
|
28
30
|
return results;
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
30
35
|
export function utf8ByteLength(str) {
|
|
31
36
|
// returns the byte length of an utf8 string
|
|
32
37
|
let s = str.length;
|
|
@@ -38,19 +43,17 @@ export function utf8ByteLength(str) {
|
|
|
38
43
|
else if (code > 0x7ff && code <= 0xffff) {
|
|
39
44
|
s += 2;
|
|
40
45
|
}
|
|
41
|
-
if (code >=
|
|
46
|
+
if (code >= 0xdc00 && code <= 0xdfff) {
|
|
42
47
|
i--; // trail surrogate
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
return s;
|
|
46
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
47
55
|
export function getBlobSize(content) {
|
|
48
|
-
|
|
49
|
-
return utf8ByteLength(content);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return content.byteLength;
|
|
53
|
-
}
|
|
56
|
+
return typeof content === "string" ? utf8ByteLength(content) : content.byteLength;
|
|
54
57
|
}
|
|
55
58
|
function calculateStatsCore(summaryObject, stats) {
|
|
56
59
|
switch (summaryObject.type) {
|
|
@@ -70,14 +73,21 @@ function calculateStatsCore(summaryObject, stats) {
|
|
|
70
73
|
stats.totalBlobSize += getBlobSize(summaryObject.content);
|
|
71
74
|
return;
|
|
72
75
|
}
|
|
73
|
-
default:
|
|
76
|
+
default:
|
|
77
|
+
return;
|
|
74
78
|
}
|
|
75
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
76
83
|
export function calculateStats(summary) {
|
|
77
84
|
const stats = mergeStats();
|
|
78
85
|
calculateStatsCore(summary, stats);
|
|
79
86
|
return stats;
|
|
80
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
81
91
|
export function addBlobToSummary(summary, key, content) {
|
|
82
92
|
const blob = {
|
|
83
93
|
type: SummaryType.Blob,
|
|
@@ -87,29 +97,38 @@ export function addBlobToSummary(summary, key, content) {
|
|
|
87
97
|
summary.stats.blobNodeCount++;
|
|
88
98
|
summary.stats.totalBlobSize += getBlobSize(content);
|
|
89
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
90
103
|
export function addTreeToSummary(summary, key, summarizeResult) {
|
|
91
104
|
summary.summary.tree[key] = summarizeResult.summary;
|
|
92
105
|
summary.stats = mergeStats(summary.stats, summarizeResult.stats);
|
|
93
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
94
110
|
export function addSummarizeResultToSummary(summary, key, summarizeResult) {
|
|
95
111
|
summary.summary.tree[key] = summarizeResult.summary;
|
|
96
112
|
summary.stats = mergeStats(summary.stats, summarizeResult.stats);
|
|
97
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* @alpha
|
|
116
|
+
*/
|
|
98
117
|
export class SummaryTreeBuilder {
|
|
99
|
-
constructor() {
|
|
100
|
-
this.attachmentCounter = 0;
|
|
101
|
-
this.summaryTree = {};
|
|
102
|
-
this.summaryStats = mergeStats();
|
|
103
|
-
this.summaryStats.treeNodeCount++;
|
|
104
|
-
}
|
|
105
118
|
get summary() {
|
|
106
119
|
return {
|
|
107
120
|
type: SummaryType.Tree,
|
|
108
|
-
tree:
|
|
121
|
+
tree: { ...this.summaryTree },
|
|
109
122
|
};
|
|
110
123
|
}
|
|
111
124
|
get stats() {
|
|
112
|
-
return
|
|
125
|
+
return { ...this.summaryStats };
|
|
126
|
+
}
|
|
127
|
+
constructor() {
|
|
128
|
+
this.attachmentCounter = 0;
|
|
129
|
+
this.summaryTree = {};
|
|
130
|
+
this.summaryStats = mergeStats();
|
|
131
|
+
this.summaryStats.treeNodeCount++;
|
|
113
132
|
}
|
|
114
133
|
addBlob(key, content) {
|
|
115
134
|
// Prevent cloning by directly referencing underlying private properties
|
|
@@ -144,6 +163,7 @@ export class SummaryTreeBuilder {
|
|
|
144
163
|
* Converts snapshot ITree to ISummaryTree format and tracks stats.
|
|
145
164
|
* @param snapshot - snapshot in ITree format
|
|
146
165
|
* @param fullTree - true to never use handles, even if id is specified
|
|
166
|
+
* @alpha
|
|
147
167
|
*/
|
|
148
168
|
export function convertToSummaryTreeWithStats(snapshot, fullTree = false) {
|
|
149
169
|
const builder = new SummaryTreeBuilder();
|
|
@@ -151,13 +171,9 @@ export function convertToSummaryTreeWithStats(snapshot, fullTree = false) {
|
|
|
151
171
|
switch (entry.type) {
|
|
152
172
|
case TreeEntry.Blob: {
|
|
153
173
|
const blob = entry.value;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
content = blob.contents;
|
|
160
|
-
}
|
|
174
|
+
const content = blob.encoding === "base64"
|
|
175
|
+
? IsoBuffer.from(blob.contents, "base64")
|
|
176
|
+
: blob.contents;
|
|
161
177
|
builder.addBlob(entry.path, content);
|
|
162
178
|
break;
|
|
163
179
|
}
|
|
@@ -183,6 +199,7 @@ export function convertToSummaryTreeWithStats(snapshot, fullTree = false) {
|
|
|
183
199
|
* Converts snapshot ITree to ISummaryTree format and tracks stats.
|
|
184
200
|
* @param snapshot - snapshot in ITree format
|
|
185
201
|
* @param fullTree - true to never use handles, even if id is specified
|
|
202
|
+
* @internal
|
|
186
203
|
*/
|
|
187
204
|
export function convertToSummaryTree(snapshot, fullTree = false) {
|
|
188
205
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
@@ -206,6 +223,7 @@ export function convertToSummaryTree(snapshot, fullTree = false) {
|
|
|
206
223
|
* Converts ISnapshotTree to ISummaryTree format and tracks stats. This snapshot tree was
|
|
207
224
|
* was taken by serialize api in detached container.
|
|
208
225
|
* @param snapshot - snapshot in ISnapshotTree format
|
|
226
|
+
* @internal
|
|
209
227
|
*/
|
|
210
228
|
export function convertSnapshotTreeToSummaryTree(snapshot) {
|
|
211
229
|
const builder = new SummaryTreeBuilder();
|
|
@@ -237,6 +255,7 @@ export function convertSnapshotTreeToSummaryTree(snapshot) {
|
|
|
237
255
|
/**
|
|
238
256
|
* Converts ISummaryTree to ITree format. This is needed for back-compat while we get rid of snapshot.
|
|
239
257
|
* @param summaryTree - summary tree in ISummaryTree format
|
|
258
|
+
* @internal
|
|
240
259
|
*/
|
|
241
260
|
export function convertSummaryTreeToITree(summaryTree) {
|
|
242
261
|
const entries = [];
|
|
@@ -275,6 +294,9 @@ export function convertSummaryTreeToITree(summaryTree) {
|
|
|
275
294
|
unreferenced: summaryTree.unreferenced,
|
|
276
295
|
};
|
|
277
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
278
300
|
export class TelemetryContext {
|
|
279
301
|
constructor() {
|
|
280
302
|
this.telemetry = new Map();
|
|
@@ -285,6 +307,15 @@ export class TelemetryContext {
|
|
|
285
307
|
set(prefix, property, value) {
|
|
286
308
|
this.telemetry.set(`${prefix}${property}`, value);
|
|
287
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.setMultiple}
|
|
312
|
+
*/
|
|
313
|
+
setMultiple(prefix, property, values) {
|
|
314
|
+
// Set the values individually so that they are logged as a flat list along with other properties.
|
|
315
|
+
for (const key of Object.keys(values)) {
|
|
316
|
+
this.set(prefix, `${property}_${key}`, values[key]);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
288
319
|
/**
|
|
289
320
|
* {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.get}
|
|
290
321
|
*/
|
|
@@ -302,4 +333,76 @@ export class TelemetryContext {
|
|
|
302
333
|
return JSON.stringify(jsonObject);
|
|
303
334
|
}
|
|
304
335
|
}
|
|
305
|
-
|
|
336
|
+
/**
|
|
337
|
+
* Trims the leading slashes from the given string.
|
|
338
|
+
* @param str - A string that may contain leading slashes.
|
|
339
|
+
* @returns A new string without leading slashes.
|
|
340
|
+
*/
|
|
341
|
+
function trimLeadingSlashes(str) {
|
|
342
|
+
return str.replace(/^\/+/g, "");
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Trims the trailing slashes from the given string.
|
|
346
|
+
* @param str - A string that may contain trailing slashes.
|
|
347
|
+
* @returns A new string without trailing slashes.
|
|
348
|
+
*/
|
|
349
|
+
function trimTrailingSlashes(str) {
|
|
350
|
+
return str.replace(/\/+$/g, "");
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Helper class to build the garbage collection data of a node by combining the data from multiple nodes.
|
|
354
|
+
* @internal
|
|
355
|
+
*/
|
|
356
|
+
export class GCDataBuilder {
|
|
357
|
+
constructor() {
|
|
358
|
+
this.gcNodesSet = {};
|
|
359
|
+
}
|
|
360
|
+
get gcNodes() {
|
|
361
|
+
const gcNodes = {};
|
|
362
|
+
for (const [nodeId, outboundRoutes] of Object.entries(this.gcNodesSet)) {
|
|
363
|
+
gcNodes[nodeId] = [...outboundRoutes];
|
|
364
|
+
}
|
|
365
|
+
return gcNodes;
|
|
366
|
+
}
|
|
367
|
+
addNode(id, outboundRoutes) {
|
|
368
|
+
this.gcNodesSet[id] = new Set(outboundRoutes);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Adds the given GC nodes. It does the following:
|
|
372
|
+
* - Normalizes the ids of the given nodes.
|
|
373
|
+
* - Prefixes the given `prefixId` to the given nodes' ids.
|
|
374
|
+
* - Adds the outbound routes of the nodes against the normalized and prefixed id.
|
|
375
|
+
*/
|
|
376
|
+
prefixAndAddNodes(prefixId, gcNodes) {
|
|
377
|
+
for (const [id, outboundRoutes] of Object.entries(gcNodes)) {
|
|
378
|
+
// Remove any leading slashes from the id.
|
|
379
|
+
let normalizedId = trimLeadingSlashes(id);
|
|
380
|
+
// Prefix the given id to the normalized id.
|
|
381
|
+
normalizedId = `/${prefixId}/${normalizedId}`;
|
|
382
|
+
// Remove any trailing slashes from the normalized id. Note that the trailing slashes are removed after
|
|
383
|
+
// adding the prefix for handling the special case where id is "/".
|
|
384
|
+
normalizedId = trimTrailingSlashes(normalizedId);
|
|
385
|
+
// Add the outbound routes against the normalized and prefixed id without duplicates.
|
|
386
|
+
this.gcNodesSet[normalizedId] = new Set(outboundRoutes);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
addNodes(gcNodes) {
|
|
390
|
+
for (const [id, outboundRoutes] of Object.entries(gcNodes)) {
|
|
391
|
+
this.gcNodesSet[id] = new Set(outboundRoutes);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Adds the given outbound route to the outbound routes of all GC nodes.
|
|
396
|
+
*/
|
|
397
|
+
addRouteToAllNodes(outboundRoute) {
|
|
398
|
+
for (const outboundRoutes of Object.values(this.gcNodesSet)) {
|
|
399
|
+
outboundRoutes.add(outboundRoute);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
getGCData() {
|
|
403
|
+
return {
|
|
404
|
+
gcNodes: this.gcNodes,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=summaryUtils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summaryUtils.mjs","sourceRoot":"","sources":["../src/summaryUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAGI,EACN,cAAc,E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,CAAC,EAAE,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3D,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;SAC9C;IACF,CAAC;IAED;;OAEG;IACI,kBAAkB,CAAC,aAAqB;QAC9C,KAAK,MAAM,cAAc,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YAC5D,cAAc,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;SAClC;IACF,CAAC;IAEM,SAAS;QACf,OAAO;YACN,OAAO,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TelemetryEventPropertyType } from \"@fluidframework/core-interfaces\";\nimport {\n\tbufferToString,\n\tfromBase64ToUtf8,\n\tIsoBuffer,\n\tUint8ArrayToString,\n} from \"@fluid-internal/client-utils\";\nimport { unreachableCase } from \"@fluidframework/core-utils\";\nimport { AttachmentTreeEntry, BlobTreeEntry, TreeTreeEntry } from \"@fluidframework/driver-utils\";\nimport {\n\tITree,\n\tSummaryType,\n\tISummaryTree,\n\tSummaryObject,\n\tISummaryBlob,\n\tTreeEntry,\n\tITreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tISummaryStats,\n\tISummarizeResult,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\tIGarbageCollectionData,\n} from \"@fluidframework/runtime-definitions\";\nimport { ISnapshotTreeWithBlobContents } from \"@fluidframework/container-definitions\";\n\n/**\n * Combines summary stats by adding their totals together.\n * Returns empty stats if called without args.\n * @param stats - stats to merge\n * @internal\n */\nexport function mergeStats(...stats: ISummaryStats[]): ISummaryStats {\n\tconst results = {\n\t\ttreeNodeCount: 0,\n\t\tblobNodeCount: 0,\n\t\thandleNodeCount: 0,\n\t\ttotalBlobSize: 0,\n\t\tunreferencedBlobSize: 0,\n\t};\n\tfor (const stat of stats) {\n\t\tresults.treeNodeCount += stat.treeNodeCount;\n\t\tresults.blobNodeCount += stat.blobNodeCount;\n\t\tresults.handleNodeCount += stat.handleNodeCount;\n\t\tresults.totalBlobSize += stat.totalBlobSize;\n\t\tresults.unreferencedBlobSize += stat.unreferencedBlobSize;\n\t}\n\treturn results;\n}\n\n/**\n * @internal\n */\nexport function utf8ByteLength(str: string): number {\n\t// returns the byte length of an utf8 string\n\tlet s = str.length;\n\tfor (let i = str.length - 1; i >= 0; i--) {\n\t\tconst code = str.charCodeAt(i);\n\t\tif (code > 0x7f && code <= 0x7ff) {\n\t\t\ts++;\n\t\t} else if (code > 0x7ff && code <= 0xffff) {\n\t\t\ts += 2;\n\t\t}\n\t\tif (code >= 0xdc00 && code <= 0xdfff) {\n\t\t\ti--; // trail surrogate\n\t\t}\n\t}\n\treturn s;\n}\n\n/**\n * @internal\n */\nexport function getBlobSize(content: ISummaryBlob[\"content\"]): number {\n\treturn typeof content === \"string\" ? utf8ByteLength(content) : content.byteLength;\n}\n\nfunction calculateStatsCore(summaryObject: SummaryObject, stats: ISummaryStats): void {\n\tswitch (summaryObject.type) {\n\t\tcase SummaryType.Tree: {\n\t\t\tstats.treeNodeCount++;\n\t\t\tfor (const value of Object.values(summaryObject.tree)) {\n\t\t\t\tcalculateStatsCore(value, stats);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase SummaryType.Handle: {\n\t\t\tstats.handleNodeCount++;\n\t\t\treturn;\n\t\t}\n\t\tcase SummaryType.Blob: {\n\t\t\tstats.blobNodeCount++;\n\t\t\tstats.totalBlobSize += getBlobSize(summaryObject.content);\n\t\t\treturn;\n\t\t}\n\t\tdefault:\n\t\t\treturn;\n\t}\n}\n\n/**\n * @internal\n */\nexport function calculateStats(summary: SummaryObject): ISummaryStats {\n\tconst stats = mergeStats();\n\tcalculateStatsCore(summary, stats);\n\treturn stats;\n}\n\n/**\n * @internal\n */\nexport function addBlobToSummary(\n\tsummary: ISummaryTreeWithStats,\n\tkey: string,\n\tcontent: string | Uint8Array,\n): void {\n\tconst blob: ISummaryBlob = {\n\t\ttype: SummaryType.Blob,\n\t\tcontent,\n\t};\n\tsummary.summary.tree[key] = blob;\n\tsummary.stats.blobNodeCount++;\n\tsummary.stats.totalBlobSize += getBlobSize(content);\n}\n\n/**\n * @internal\n */\nexport function addTreeToSummary(\n\tsummary: ISummaryTreeWithStats,\n\tkey: string,\n\tsummarizeResult: ISummarizeResult,\n): void {\n\tsummary.summary.tree[key] = summarizeResult.summary;\n\tsummary.stats = mergeStats(summary.stats, summarizeResult.stats);\n}\n\n/**\n * @internal\n */\nexport function addSummarizeResultToSummary(\n\tsummary: ISummaryTreeWithStats,\n\tkey: string,\n\tsummarizeResult: ISummarizeResult,\n): void {\n\tsummary.summary.tree[key] = summarizeResult.summary;\n\tsummary.stats = mergeStats(summary.stats, summarizeResult.stats);\n}\n\n/**\n * @alpha\n */\nexport class SummaryTreeBuilder implements ISummaryTreeWithStats {\n\tprivate attachmentCounter: number = 0;\n\n\tpublic get summary(): ISummaryTree {\n\t\treturn {\n\t\t\ttype: SummaryType.Tree,\n\t\t\ttree: { ...this.summaryTree },\n\t\t};\n\t}\n\n\tpublic get stats(): Readonly<ISummaryStats> {\n\t\treturn { ...this.summaryStats };\n\t}\n\n\tconstructor() {\n\t\tthis.summaryStats = mergeStats();\n\t\tthis.summaryStats.treeNodeCount++;\n\t}\n\n\tprivate readonly summaryTree: { [path: string]: SummaryObject } = {};\n\tprivate summaryStats: ISummaryStats;\n\n\tpublic addBlob(key: string, content: string | Uint8Array): void {\n\t\t// Prevent cloning by directly referencing underlying private properties\n\t\taddBlobToSummary(\n\t\t\t{\n\t\t\t\tsummary: {\n\t\t\t\t\ttype: SummaryType.Tree,\n\t\t\t\t\ttree: this.summaryTree,\n\t\t\t\t},\n\t\t\t\tstats: this.summaryStats,\n\t\t\t},\n\t\t\tkey,\n\t\t\tcontent,\n\t\t);\n\t}\n\n\tpublic addHandle(\n\t\tkey: string,\n\t\thandleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment,\n\t\thandle: string,\n\t): void {\n\t\tthis.summaryTree[key] = {\n\t\t\ttype: SummaryType.Handle,\n\t\t\thandleType,\n\t\t\thandle,\n\t\t};\n\t\tthis.summaryStats.handleNodeCount++;\n\t}\n\n\tpublic addWithStats(key: string, summarizeResult: ISummarizeResult): void {\n\t\tthis.summaryTree[key] = summarizeResult.summary;\n\t\tthis.summaryStats = mergeStats(this.summaryStats, summarizeResult.stats);\n\t}\n\n\tpublic addAttachment(id: string) {\n\t\tthis.summaryTree[this.attachmentCounter++] = { id, type: SummaryType.Attachment };\n\t}\n\n\tpublic getSummaryTree(): ISummaryTreeWithStats {\n\t\treturn { summary: this.summary, stats: this.stats };\n\t}\n}\n\n/**\n * Converts snapshot ITree to ISummaryTree format and tracks stats.\n * @param snapshot - snapshot in ITree format\n * @param fullTree - true to never use handles, even if id is specified\n * @alpha\n */\nexport function convertToSummaryTreeWithStats(\n\tsnapshot: ITree,\n\tfullTree: boolean = false,\n): ISummaryTreeWithStats {\n\tconst builder = new SummaryTreeBuilder();\n\tfor (const entry of snapshot.entries) {\n\t\tswitch (entry.type) {\n\t\t\tcase TreeEntry.Blob: {\n\t\t\t\tconst blob = entry.value;\n\t\t\t\tconst content =\n\t\t\t\t\tblob.encoding === \"base64\"\n\t\t\t\t\t\t? IsoBuffer.from(blob.contents, \"base64\")\n\t\t\t\t\t\t: blob.contents;\n\t\t\t\tbuilder.addBlob(entry.path, content);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase TreeEntry.Tree: {\n\t\t\t\tconst subtree = convertToSummaryTree(entry.value, fullTree);\n\t\t\t\tbuilder.addWithStats(entry.path, subtree);\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase TreeEntry.Attachment: {\n\t\t\t\tconst id = entry.value.id;\n\t\t\t\tbuilder.addAttachment(id);\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unexpected TreeEntry type\");\n\t\t}\n\t}\n\n\tconst summaryTree = builder.getSummaryTree();\n\tsummaryTree.summary.unreferenced = snapshot.unreferenced;\n\treturn summaryTree;\n}\n\n/**\n * Converts snapshot ITree to ISummaryTree format and tracks stats.\n * @param snapshot - snapshot in ITree format\n * @param fullTree - true to never use handles, even if id is specified\n * @internal\n */\nexport function convertToSummaryTree(snapshot: ITree, fullTree: boolean = false): ISummarizeResult {\n\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\tif (snapshot.id && !fullTree) {\n\t\tconst stats = mergeStats();\n\t\tstats.handleNodeCount++;\n\t\treturn {\n\t\t\tsummary: {\n\t\t\t\thandle: snapshot.id,\n\t\t\t\thandleType: SummaryType.Tree,\n\t\t\t\ttype: SummaryType.Handle,\n\t\t\t},\n\t\t\tstats,\n\t\t};\n\t} else {\n\t\treturn convertToSummaryTreeWithStats(snapshot, fullTree);\n\t}\n}\n\n/**\n * Converts ISnapshotTree to ISummaryTree format and tracks stats. This snapshot tree was\n * was taken by serialize api in detached container.\n * @param snapshot - snapshot in ISnapshotTree format\n * @internal\n */\nexport function convertSnapshotTreeToSummaryTree(\n\tsnapshot: ISnapshotTreeWithBlobContents,\n): ISummaryTreeWithStats {\n\tconst builder = new SummaryTreeBuilder();\n\tfor (const [path, id] of Object.entries(snapshot.blobs)) {\n\t\tlet decoded: string | undefined;\n\t\tif (snapshot.blobsContents !== undefined) {\n\t\t\tconst content: ArrayBufferLike = snapshot.blobsContents[id];\n\t\t\tif (content !== undefined) {\n\t\t\t\tdecoded = bufferToString(content, \"utf-8\");\n\t\t\t}\n\t\t\t// 0.44 back-compat We still put contents in same blob for back-compat so need to add blob\n\t\t\t// only for blobPath -> blobId mapping and not for blobId -> blob value contents.\n\t\t} else if (snapshot.blobs[id] !== undefined) {\n\t\t\tdecoded = fromBase64ToUtf8(snapshot.blobs[id]);\n\t\t}\n\t\tif (decoded !== undefined) {\n\t\t\tbuilder.addBlob(path, decoded);\n\t\t}\n\t}\n\n\tfor (const [key, tree] of Object.entries(snapshot.trees)) {\n\t\tconst subtree = convertSnapshotTreeToSummaryTree(tree);\n\t\tbuilder.addWithStats(key, subtree);\n\t}\n\n\tconst summaryTree = builder.getSummaryTree();\n\tsummaryTree.summary.unreferenced = snapshot.unreferenced;\n\treturn summaryTree;\n}\n\n/**\n * Converts ISummaryTree to ITree format. This is needed for back-compat while we get rid of snapshot.\n * @param summaryTree - summary tree in ISummaryTree format\n * @internal\n */\nexport function convertSummaryTreeToITree(summaryTree: ISummaryTree): ITree {\n\tconst entries: ITreeEntry[] = [];\n\tfor (const [key, value] of Object.entries(summaryTree.tree)) {\n\t\tswitch (value.type) {\n\t\t\tcase SummaryType.Blob: {\n\t\t\t\tlet parsedContent: string;\n\t\t\t\tlet encoding: \"utf-8\" | \"base64\" = \"utf-8\";\n\t\t\t\tif (typeof value.content === \"string\") {\n\t\t\t\t\tparsedContent = value.content;\n\t\t\t\t} else {\n\t\t\t\t\tparsedContent = Uint8ArrayToString(value.content, \"base64\");\n\t\t\t\t\tencoding = \"base64\";\n\t\t\t\t}\n\t\t\t\tentries.push(new BlobTreeEntry(key, parsedContent, encoding));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase SummaryType.Tree: {\n\t\t\t\tentries.push(new TreeTreeEntry(key, convertSummaryTreeToITree(value)));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase SummaryType.Attachment: {\n\t\t\t\tentries.push(new AttachmentTreeEntry(key, value.id));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase SummaryType.Handle: {\n\t\t\t\tthrow new Error(\"Should not have Handle type in summary tree\");\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tunreachableCase(value, \"Unexpected summary tree type\");\n\t\t}\n\t}\n\treturn {\n\t\tentries,\n\t\tunreferenced: summaryTree.unreferenced,\n\t};\n}\n\n/**\n * @internal\n */\nexport class TelemetryContext implements ITelemetryContext {\n\tprivate readonly telemetry = new Map<string, TelemetryEventPropertyType>();\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.set}\n\t */\n\tset(prefix: string, property: string, value: TelemetryEventPropertyType): void {\n\t\tthis.telemetry.set(`${prefix}${property}`, value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.setMultiple}\n\t */\n\tsetMultiple(\n\t\tprefix: string,\n\t\tproperty: string,\n\t\tvalues: Record<string, TelemetryEventPropertyType>,\n\t): void {\n\t\t// Set the values individually so that they are logged as a flat list along with other properties.\n\t\tfor (const key of Object.keys(values)) {\n\t\t\tthis.set(prefix, `${property}_${key}`, values[key]);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.get}\n\t */\n\tget(prefix: string, property: string): TelemetryEventPropertyType {\n\t\treturn this.telemetry.get(`${prefix}${property}`);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#ITelemetryContext.serialize}\n\t */\n\tserialize(): string {\n\t\tconst jsonObject = {};\n\t\tthis.telemetry.forEach((value, key) => {\n\t\t\tjsonObject[key] = value;\n\t\t});\n\t\treturn JSON.stringify(jsonObject);\n\t}\n}\n\n/**\n * Trims the leading slashes from the given string.\n * @param str - A string that may contain leading slashes.\n * @returns A new string without leading slashes.\n */\nfunction trimLeadingSlashes(str: string) {\n\treturn str.replace(/^\\/+/g, \"\");\n}\n\n/**\n * Trims the trailing slashes from the given string.\n * @param str - A string that may contain trailing slashes.\n * @returns A new string without trailing slashes.\n */\nfunction trimTrailingSlashes(str: string) {\n\treturn str.replace(/\\/+$/g, \"\");\n}\n\n/**\n * Helper class to build the garbage collection data of a node by combining the data from multiple nodes.\n * @internal\n */\nexport class GCDataBuilder implements IGarbageCollectionData {\n\tprivate readonly gcNodesSet: { [id: string]: Set<string> } = {};\n\tpublic get gcNodes(): { [id: string]: string[] } {\n\t\tconst gcNodes = {};\n\t\tfor (const [nodeId, outboundRoutes] of Object.entries(this.gcNodesSet)) {\n\t\t\tgcNodes[nodeId] = [...outboundRoutes];\n\t\t}\n\t\treturn gcNodes;\n\t}\n\n\tpublic addNode(id: string, outboundRoutes: string[]) {\n\t\tthis.gcNodesSet[id] = new Set(outboundRoutes);\n\t}\n\n\t/**\n\t * Adds the given GC nodes. It does the following:\n\t * - Normalizes the ids of the given nodes.\n\t * - Prefixes the given `prefixId` to the given nodes' ids.\n\t * - Adds the outbound routes of the nodes against the normalized and prefixed id.\n\t */\n\tpublic prefixAndAddNodes(prefixId: string, gcNodes: { [id: string]: string[] }) {\n\t\tfor (const [id, outboundRoutes] of Object.entries(gcNodes)) {\n\t\t\t// Remove any leading slashes from the id.\n\t\t\tlet normalizedId = trimLeadingSlashes(id);\n\t\t\t// Prefix the given id to the normalized id.\n\t\t\tnormalizedId = `/${prefixId}/${normalizedId}`;\n\t\t\t// Remove any trailing slashes from the normalized id. Note that the trailing slashes are removed after\n\t\t\t// adding the prefix for handling the special case where id is \"/\".\n\t\t\tnormalizedId = trimTrailingSlashes(normalizedId);\n\n\t\t\t// Add the outbound routes against the normalized and prefixed id without duplicates.\n\t\t\tthis.gcNodesSet[normalizedId] = new Set(outboundRoutes);\n\t\t}\n\t}\n\n\tpublic addNodes(gcNodes: { [id: string]: string[] }) {\n\t\tfor (const [id, outboundRoutes] of Object.entries(gcNodes)) {\n\t\t\tthis.gcNodesSet[id] = new Set(outboundRoutes);\n\t\t}\n\t}\n\n\t/**\n\t * Adds the given outbound route to the outbound routes of all GC nodes.\n\t */\n\tpublic addRouteToAllNodes(outboundRoute: string) {\n\t\tfor (const outboundRoutes of Object.values(this.gcNodesSet)) {\n\t\t\toutboundRoutes.add(outboundRoute);\n\t\t}\n\t}\n\n\tpublic getGCData(): IGarbageCollectionData {\n\t\treturn {\n\t\t\tgcNodes: this.gcNodes,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Helper function that unpacks the used routes of children from a given node's used routes.
|
|
7
|
+
* @param usedRoutes - The used routes of a node.
|
|
8
|
+
* @returns A map of used routes of each children of the the given node.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function unpackChildNodesUsedRoutes(usedRoutes: readonly string[]): Map<string, string[]>;
|
|
12
|
+
//# sourceMappingURL=unpackUsedRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpackUsedRoutes.d.ts","sourceRoot":"","sources":["../src/unpackUsedRoutes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,yBAiBvE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { assert } from "@fluidframework/core-utils";
|
|
6
|
+
/**
|
|
7
|
+
* Helper function that unpacks the used routes of children from a given node's used routes.
|
|
8
|
+
* @param usedRoutes - The used routes of a node.
|
|
9
|
+
* @returns A map of used routes of each children of the the given node.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function unpackChildNodesUsedRoutes(usedRoutes) {
|
|
13
|
+
// Remove the node's self used route, if any, and generate the children used routes.
|
|
14
|
+
const filteredUsedRoutes = usedRoutes.filter((route) => route !== "" && route !== "/");
|
|
15
|
+
const childUsedRoutesMap = new Map();
|
|
16
|
+
for (const route of filteredUsedRoutes) {
|
|
17
|
+
assert(route.startsWith("/"), 0x5e0 /* Used route should always be an absolute route */);
|
|
18
|
+
const childId = route.split("/")[1];
|
|
19
|
+
const childUsedRoute = route.slice(childId.length + 1);
|
|
20
|
+
const childUsedRoutes = childUsedRoutesMap.get(childId);
|
|
21
|
+
if (childUsedRoutes !== undefined) {
|
|
22
|
+
childUsedRoutes.push(childUsedRoute);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
childUsedRoutesMap.set(childId, [childUsedRoute]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return childUsedRoutesMap;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=unpackUsedRoutes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpackUsedRoutes.mjs","sourceRoot":"","sources":["../src/unpackUsedRoutes.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,MAAM,EAAE,MAAM,4BAA4B;AAEnD;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAA6B;IACvE,oFAAoF;IACpF,MAAM,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC;IACvF,MAAM,kBAAkB,GAA0B,IAAI,GAAG,EAAE,CAAC;IAC5D,KAAK,MAAM,KAAK,IAAI,kBAAkB,EAAE;QACvC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACzF,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEvD,MAAM,eAAe,GAAG,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,eAAe,KAAK,SAAS,EAAE;YAClC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACrC;aAAM;YACN,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;SAClD;KACD;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\n\n/**\n * Helper function that unpacks the used routes of children from a given node's used routes.\n * @param usedRoutes - The used routes of a node.\n * @returns A map of used routes of each children of the the given node.\n * @internal\n */\nexport function unpackChildNodesUsedRoutes(usedRoutes: readonly string[]) {\n\t// Remove the node's self used route, if any, and generate the children used routes.\n\tconst filteredUsedRoutes = usedRoutes.filter((route) => route !== \"\" && route !== \"/\");\n\tconst childUsedRoutesMap: Map<string, string[]> = new Map();\n\tfor (const route of filteredUsedRoutes) {\n\t\tassert(route.startsWith(\"/\"), 0x5e0 /* Used route should always be an absolute route */);\n\t\tconst childId = route.split(\"/\")[1];\n\t\tconst childUsedRoute = route.slice(childId.length + 1);\n\n\t\tconst childUsedRoutes = childUsedRoutesMap.get(childId);\n\t\tif (childUsedRoutes !== undefined) {\n\t\t\tchildUsedRoutes.push(childUsedRoute);\n\t\t} else {\n\t\t\tchildUsedRoutesMap.set(childId, [childUsedRoute]);\n\t\t}\n\t}\n\treturn childUsedRoutesMap;\n}\n"]}
|
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ISnapshotTree } from "@fluidframework/protocol-definitions";
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Reads a blob from storage and parses it from JSON.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export type ReadAndParseBlob = <T>(id: string) => Promise<T>;
|
|
8
12
|
/**
|
|
9
13
|
* Fetches the sequence number of the snapshot tree by examining the protocol.
|
|
10
14
|
* @param tree - snapshot tree to examine
|
|
11
15
|
* @param readAndParseBlob - function to read blob contents from storage
|
|
12
16
|
* and parse the result from JSON.
|
|
17
|
+
* @internal
|
|
13
18
|
*/
|
|
14
19
|
export declare function seqFromTree(tree: ISnapshotTree, readAndParseBlob: ReadAndParseBlob): Promise<number>;
|
|
15
20
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAuB,aAAa,EAAE,MAAM,sCAAsC;AAEzF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,aAAa,EACnB,gBAAgB,EAAE,gBAAgB,GAChC,OAAO,CAAC,MAAM,CAAC,CAIjB"}
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* @param tree - snapshot tree to examine
|
|
8
8
|
* @param readAndParseBlob - function to read blob contents from storage
|
|
9
9
|
* and parse the result from JSON.
|
|
10
|
+
* @internal
|
|
10
11
|
*/
|
|
11
12
|
export async function seqFromTree(tree, readAndParseBlob) {
|
|
12
13
|
const attributesHash = tree.trees[".protocol"].blobs.attributes;
|
|
13
14
|
const attrib = await readAndParseBlob(attributesHash);
|
|
14
15
|
return attrib.sequenceNumber;
|
|
15
16
|
}
|
|
16
|
-
//# sourceMappingURL=utils.
|
|
17
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,IAAmB,EACnB,gBAAkC;IAElC,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAsB,cAAc,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC,cAAc,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDocumentAttributes, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Reads a blob from storage and parses it from JSON.\n *\n * @internal\n */\nexport type ReadAndParseBlob = <T>(id: string) => Promise<T>;\n\n/**\n * Fetches the sequence number of the snapshot tree by examining the protocol.\n * @param tree - snapshot tree to examine\n * @param readAndParseBlob - function to read blob contents from storage\n * and parse the result from JSON.\n * @internal\n */\nexport async function seqFromTree(\n\ttree: ISnapshotTree,\n\treadAndParseBlob: ReadAndParseBlob,\n): Promise<number> {\n\tconst attributesHash = tree.trees[\".protocol\"].blobs.attributes;\n\tconst attrib = await readAndParseBlob<IDocumentAttributes>(attributesHash);\n\treturn attrib.sequenceNumber;\n}\n"]}
|