@fluidframework/driver-utils 2.0.0-dev.3.1.0.125672 → 2.0.0-dev.4.2.0.153917

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.
Files changed (139) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +68 -1
  3. package/dist/fluidResolvedUrl.d.ts +8 -0
  4. package/dist/fluidResolvedUrl.d.ts.map +1 -1
  5. package/dist/fluidResolvedUrl.js +8 -0
  6. package/dist/fluidResolvedUrl.js.map +1 -1
  7. package/dist/index.d.ts +4 -11
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -21
  10. package/dist/index.js.map +1 -1
  11. package/dist/messageRecognition.d.ts +0 -20
  12. package/dist/messageRecognition.d.ts.map +1 -1
  13. package/dist/messageRecognition.js +1 -37
  14. package/dist/messageRecognition.js.map +1 -1
  15. package/dist/network.d.ts +0 -15
  16. package/dist/network.d.ts.map +1 -1
  17. package/dist/network.js.map +1 -1
  18. package/dist/networkUtils.d.ts +0 -10
  19. package/dist/networkUtils.d.ts.map +1 -1
  20. package/dist/networkUtils.js +1 -32
  21. package/dist/networkUtils.js.map +1 -1
  22. package/dist/packageVersion.d.ts +1 -1
  23. package/dist/packageVersion.js +1 -1
  24. package/dist/packageVersion.js.map +1 -1
  25. package/dist/parallelRequests.d.ts.map +1 -1
  26. package/dist/parallelRequests.js +45 -14
  27. package/dist/parallelRequests.js.map +1 -1
  28. package/dist/summaryForCreateNew.d.ts +21 -1
  29. package/dist/summaryForCreateNew.d.ts.map +1 -1
  30. package/dist/summaryForCreateNew.js +27 -5
  31. package/dist/summaryForCreateNew.js.map +1 -1
  32. package/dist/treeConversions.d.ts.map +1 -1
  33. package/dist/treeConversions.js +8 -9
  34. package/dist/treeConversions.js.map +1 -1
  35. package/lib/fluidResolvedUrl.d.ts +8 -0
  36. package/lib/fluidResolvedUrl.d.ts.map +1 -1
  37. package/lib/fluidResolvedUrl.js +8 -0
  38. package/lib/fluidResolvedUrl.js.map +1 -1
  39. package/lib/index.d.ts +4 -11
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +3 -10
  42. package/lib/index.js.map +1 -1
  43. package/lib/messageRecognition.d.ts +0 -20
  44. package/lib/messageRecognition.d.ts.map +1 -1
  45. package/lib/messageRecognition.js +0 -35
  46. package/lib/messageRecognition.js.map +1 -1
  47. package/lib/network.d.ts +0 -15
  48. package/lib/network.d.ts.map +1 -1
  49. package/lib/network.js.map +1 -1
  50. package/lib/networkUtils.d.ts +0 -10
  51. package/lib/networkUtils.d.ts.map +1 -1
  52. package/lib/networkUtils.js +0 -30
  53. package/lib/networkUtils.js.map +1 -1
  54. package/lib/packageVersion.d.ts +1 -1
  55. package/lib/packageVersion.js +1 -1
  56. package/lib/packageVersion.js.map +1 -1
  57. package/lib/parallelRequests.d.ts.map +1 -1
  58. package/lib/parallelRequests.js +46 -15
  59. package/lib/parallelRequests.js.map +1 -1
  60. package/lib/summaryForCreateNew.d.ts +21 -1
  61. package/lib/summaryForCreateNew.d.ts.map +1 -1
  62. package/lib/summaryForCreateNew.js +25 -4
  63. package/lib/summaryForCreateNew.js.map +1 -1
  64. package/lib/treeConversions.d.ts.map +1 -1
  65. package/lib/treeConversions.js +8 -9
  66. package/lib/treeConversions.js.map +1 -1
  67. package/package.json +52 -75
  68. package/src/fluidResolvedUrl.ts +8 -0
  69. package/src/index.ts +4 -19
  70. package/src/messageRecognition.ts +0 -36
  71. package/src/network.ts +0 -16
  72. package/src/networkUtils.ts +0 -32
  73. package/src/packageVersion.ts +1 -1
  74. package/src/parallelRequests.ts +54 -19
  75. package/src/summaryForCreateNew.ts +49 -5
  76. package/src/treeConversions.ts +8 -9
  77. package/dist/blobAggregationStorage.d.ts +0 -43
  78. package/dist/blobAggregationStorage.d.ts.map +0 -1
  79. package/dist/blobAggregationStorage.js +0 -323
  80. package/dist/blobAggregationStorage.js.map +0 -1
  81. package/dist/blobCacheStorageService.d.ts +0 -16
  82. package/dist/blobCacheStorageService.d.ts.map +0 -1
  83. package/dist/blobCacheStorageService.js +0 -29
  84. package/dist/blobCacheStorageService.js.map +0 -1
  85. package/dist/emptyDocumentDeltaStorageService.d.ts +0 -13
  86. package/dist/emptyDocumentDeltaStorageService.d.ts.map +0 -1
  87. package/dist/emptyDocumentDeltaStorageService.js +0 -20
  88. package/dist/emptyDocumentDeltaStorageService.js.map +0 -1
  89. package/dist/mapWithExpiration.d.ts +0 -34
  90. package/dist/mapWithExpiration.d.ts.map +0 -1
  91. package/dist/mapWithExpiration.js +0 -105
  92. package/dist/mapWithExpiration.js.map +0 -1
  93. package/dist/multiDocumentServiceFactory.d.ts +0 -16
  94. package/dist/multiDocumentServiceFactory.d.ts.map +0 -1
  95. package/dist/multiDocumentServiceFactory.js +0 -63
  96. package/dist/multiDocumentServiceFactory.js.map +0 -1
  97. package/dist/multiUrlResolver.d.ts +0 -20
  98. package/dist/multiUrlResolver.d.ts.map +0 -1
  99. package/dist/multiUrlResolver.js +0 -45
  100. package/dist/multiUrlResolver.js.map +0 -1
  101. package/dist/treeUtils.d.ts +0 -51
  102. package/dist/treeUtils.d.ts.map +0 -1
  103. package/dist/treeUtils.js +0 -85
  104. package/dist/treeUtils.js.map +0 -1
  105. package/lib/blobAggregationStorage.d.ts +0 -43
  106. package/lib/blobAggregationStorage.d.ts.map +0 -1
  107. package/lib/blobAggregationStorage.js +0 -318
  108. package/lib/blobAggregationStorage.js.map +0 -1
  109. package/lib/blobCacheStorageService.d.ts +0 -16
  110. package/lib/blobCacheStorageService.d.ts.map +0 -1
  111. package/lib/blobCacheStorageService.js +0 -25
  112. package/lib/blobCacheStorageService.js.map +0 -1
  113. package/lib/emptyDocumentDeltaStorageService.d.ts +0 -13
  114. package/lib/emptyDocumentDeltaStorageService.d.ts.map +0 -1
  115. package/lib/emptyDocumentDeltaStorageService.js +0 -16
  116. package/lib/emptyDocumentDeltaStorageService.js.map +0 -1
  117. package/lib/mapWithExpiration.d.ts +0 -34
  118. package/lib/mapWithExpiration.d.ts.map +0 -1
  119. package/lib/mapWithExpiration.js +0 -101
  120. package/lib/mapWithExpiration.js.map +0 -1
  121. package/lib/multiDocumentServiceFactory.d.ts +0 -16
  122. package/lib/multiDocumentServiceFactory.d.ts.map +0 -1
  123. package/lib/multiDocumentServiceFactory.js +0 -59
  124. package/lib/multiDocumentServiceFactory.js.map +0 -1
  125. package/lib/multiUrlResolver.d.ts +0 -20
  126. package/lib/multiUrlResolver.d.ts.map +0 -1
  127. package/lib/multiUrlResolver.js +0 -40
  128. package/lib/multiUrlResolver.js.map +0 -1
  129. package/lib/treeUtils.d.ts +0 -51
  130. package/lib/treeUtils.d.ts.map +0 -1
  131. package/lib/treeUtils.js +0 -80
  132. package/lib/treeUtils.js.map +0 -1
  133. package/src/blobAggregationStorage.ts +0 -420
  134. package/src/blobCacheStorageService.ts +0 -35
  135. package/src/emptyDocumentDeltaStorageService.ts +0 -25
  136. package/src/mapWithExpiration.ts +0 -124
  137. package/src/multiDocumentServiceFactory.ts +0 -91
  138. package/src/multiUrlResolver.ts +0 -48
  139. package/src/treeUtils.ts +0 -107
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { assert } from "@fluidframework/common-utils";
6
7
  import {
7
8
  ISummaryTree,
8
9
  SummaryType,
@@ -11,16 +12,61 @@ import {
11
12
  IDocumentAttributes,
12
13
  } from "@fluidframework/protocol-definitions";
13
14
 
15
+ /**
16
+ * Defines the current layout of an .app + .protocol summary tree
17
+ * this is used internally for create new, and single commit summary
18
+ * @internal
19
+ */
20
+ export interface CombinedAppAndProtocolSummary extends ISummaryTree {
21
+ tree: {
22
+ [".app"]: ISummaryTree;
23
+ [".protocol"]: ISummaryTree;
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Validates the current layout of an .app + .protocol summary tree
29
+ * this is used internally for create new, and single commit summary
30
+ * @internal
31
+ */
32
+ export function isCombinedAppAndProtocolSummary(
33
+ summary: ISummaryTree | undefined,
34
+ ): summary is CombinedAppAndProtocolSummary {
35
+ if (
36
+ summary?.tree === undefined ||
37
+ summary.tree?.[".app"]?.type !== SummaryType.Tree ||
38
+ summary.tree?.[".protocol"]?.type !== SummaryType.Tree
39
+ ) {
40
+ return false;
41
+ }
42
+ const treeKeys = Object.keys(summary.tree);
43
+ if (treeKeys.length !== 2) {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+
14
49
  /**
15
50
  * Combine the app summary and protocol summary in 1 tree.
16
51
  * @param appSummary - Summary of the app.
17
52
  * @param protocolSummary - Summary of the protocol.
53
+ * @internal
54
+ *
55
+ * @deprecated 2.0.0-internal.3.4.0 - Not intended for public use. Will be moved to container-loader and no longer exported in an upcoming release.
18
56
  */
19
57
  export function combineAppAndProtocolSummary(
20
58
  appSummary: ISummaryTree,
21
59
  protocolSummary: ISummaryTree,
22
- ): ISummaryTree {
23
- const createNewSummary: ISummaryTree = {
60
+ ): CombinedAppAndProtocolSummary {
61
+ assert(
62
+ !isCombinedAppAndProtocolSummary(appSummary),
63
+ 0x5a8 /* app summary is already a combined tree! */,
64
+ );
65
+ assert(
66
+ !isCombinedAppAndProtocolSummary(protocolSummary),
67
+ 0x5a9 /* protocol summary is already a combined tree! */,
68
+ );
69
+ const createNewSummary: CombinedAppAndProtocolSummary = {
24
70
  type: SummaryType.Tree,
25
71
  tree: {
26
72
  ".protocol": protocolSummary,
@@ -38,9 +84,7 @@ export function getDocAttributesFromProtocolSummary(
38
84
  protocolSummary: ISummaryTree,
39
85
  ): IDocumentAttributes {
40
86
  const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;
41
- const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;
42
- documentAttributes.term = documentAttributes.term ?? 1;
43
- return documentAttributes;
87
+ return JSON.parse(attributesBlob.content as string) as IDocumentAttributes;
44
88
  }
45
89
 
46
90
  /**
@@ -6,6 +6,7 @@
6
6
  import { Uint8ArrayToString, unreachableCase } from "@fluidframework/common-utils";
7
7
  import { AttachmentTreeEntry, BlobTreeEntry, TreeTreeEntry } from "@fluidframework/protocol-base";
8
8
  import { ISummaryTree, ITree, ITreeEntry, SummaryType } from "@fluidframework/protocol-definitions";
9
+ import { isCombinedAppAndProtocolSummary } from "./summaryForCreateNew";
9
10
 
10
11
  /**
11
12
  * Converts ISummaryTree to ITree format.
@@ -13,18 +14,16 @@ import { ISummaryTree, ITree, ITreeEntry, SummaryType } from "@fluidframework/pr
13
14
  */
14
15
  export function convertSummaryTreeToSnapshotITree(summaryTree: ISummaryTree): ITree {
15
16
  const entries: ITreeEntry[] = [];
16
- const protocolSummary = summaryTree.tree[".protocol"] as ISummaryTree;
17
- const appSummary = summaryTree.tree[".app"] as ISummaryTree;
18
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
19
- const adaptSumaryTree = protocolSummary && appSummary;
20
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
21
- const allSummaryEntries = adaptSumaryTree
22
- ? [...Object.entries(protocolSummary.tree), ...Object.entries(appSummary.tree)]
17
+ const adaptSummaryTree = isCombinedAppAndProtocolSummary(summaryTree);
18
+ const allSummaryEntries = adaptSummaryTree
19
+ ? [
20
+ ...Object.entries(summaryTree.tree[".protocol"].tree),
21
+ ...Object.entries(summaryTree.tree[".app"].tree),
22
+ ]
23
23
  : Object.entries(summaryTree.tree);
24
24
 
25
25
  for (const [key, value] of allSummaryEntries) {
26
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
27
- const k = adaptSumaryTree && ["attributes"].includes(key) ? `.${key}` : key;
26
+ const k = adaptSummaryTree && key === "attributes" ? ".attributes" : key;
28
27
  switch (value.type) {
29
28
  case SummaryType.Blob: {
30
29
  let parsedContent: string;
@@ -1,43 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { IDocumentStorageService, IDocumentStorageServicePolicies, ISummaryContext } from "@fluidframework/driver-definitions";
6
- import { ICreateBlobResponse, ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
7
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
8
- export declare abstract class SnapshotExtractor {
9
- protected readonly aggregatedBlobName = "__big";
10
- protected readonly virtualIdPrefix = "__";
11
- protected virtualIdCounter: number;
12
- protected getNextVirtualId(): string;
13
- abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;
14
- abstract setBlob(id: string, tree: ISnapshotTree, content: string): any;
15
- unpackSnapshotCore(snapshot: ISnapshotTree, level?: number): Promise<void>;
16
- }
17
- export declare class BlobAggregationStorage extends SnapshotExtractor implements IDocumentStorageService {
18
- private readonly storage;
19
- private readonly logger;
20
- private readonly allowPacking;
21
- private readonly packingLevel;
22
- private readonly blobCutOffSize?;
23
- static readonly fullDataStoreSummaries = true;
24
- protected loadedFromSummary: boolean;
25
- protected virtualBlobs: Map<string, ArrayBufferLike>;
26
- static wrap(storage: IDocumentStorageService, logger: ITelemetryLogger, allowPacking?: boolean, packingLevel?: number): BlobAggregationStorage;
27
- static unpackSnapshot(snapshot: ISnapshotTree): Promise<void>;
28
- get policies(): IDocumentStorageServicePolicies | undefined;
29
- unpackSnapshot(snapshot: ISnapshotTree): Promise<void>;
30
- protected constructor(storage: IDocumentStorageService, logger: ITelemetryLogger, allowPacking: boolean, packingLevel: number, blobCutOffSize?: number | undefined);
31
- setBlob(id: string, tree: ISnapshotTree, content: string): void;
32
- getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;
33
- get repositoryUrl(): string;
34
- getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
35
- downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree>;
36
- createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
37
- getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null>;
38
- readBlob(id: string): Promise<ArrayBufferLike>;
39
- uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
40
- private compressSmallBlobs;
41
- protected isRealStorageId(id: string): boolean;
42
- }
43
- //# sourceMappingURL=blobAggregationStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blobAggregationStorage.d.ts","sourceRoot":"","sources":["../src/blobAggregationStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,uBAAuB,EACvB,+BAA+B,EAC/B,eAAe,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EAER,MAAM,sCAAsC,CAAC;AAS9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AA0CtE,8BAAsB,iBAAiB;IACtC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,WAAW;IAChD,SAAS,CAAC,QAAQ,CAAC,eAAe,QAAQ;IAG1C,SAAS,CAAC,gBAAgB,SAAK;IAC/B,SAAS,CAAC,gBAAgB;IAI1B,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC;IAC3E,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM;IAEpD,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAsClF;AAoCD,qBAAa,sBAAuB,SAAQ,iBAAkB,YAAW,uBAAuB;IAiE9F,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IA1DjC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,QAAQ;IAE9C,SAAS,CAAC,iBAAi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yright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BlobAggregationStorage = exports.SnapshotExtractor = void 0;
8
- const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
9
- const common_utils_1 = require("@fluidframework/common-utils");
10
- const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
11
- /*
12
- * Work around for bufferToString having a bug - it can't consume IsoBuffer!
13
- * To be removed once bufferToString is fixed!
14
- */
15
- function bufferToString2(blob, encoding) {
16
- if (blob instanceof Uint8Array) {
17
- // IsoBuffer does not have ctor, so it's not in proto chain :(
18
- return (0, common_utils_1.Uint8ArrayToString)(blob, encoding);
19
- }
20
- return (0, common_utils_1.bufferToString)(blob, encoding);
21
- }
22
- /**
23
- * Class responsible for aggregating smaller blobs into one and unpacking it later on.
24
- */
25
- class BlobAggregator {
26
- constructor() {
27
- this.content = [];
28
- }
29
- addBlob(key, content) {
30
- this.content.push([key, content]);
31
- }
32
- getAggregatedBlobContent() {
33
- if (this.content.length === 0) {
34
- return undefined;
35
- }
36
- return JSON.stringify(this.content);
37
- }
38
- static load(input) {
39
- const data = bufferToString2(input, "utf-8");
40
- return JSON.parse(data);
41
- }
42
- }
43
- /*
44
- * Base class that deals with unpacking snapshots (in place) containing aggregated blobs
45
- * It relies on abstract methods for reads and storing unpacked blobs.
46
- */
47
- class SnapshotExtractor {
48
- constructor() {
49
- this.aggregatedBlobName = "__big";
50
- this.virtualIdPrefix = "__";
51
- // counter for generation of virtual storage IDs
52
- this.virtualIdCounter = 0;
53
- }
54
- getNextVirtualId() {
55
- return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;
56
- }
57
- async unpackSnapshotCore(snapshot, level = 0) {
58
- for (const key of Object.keys(snapshot.trees)) {
59
- const obj = snapshot.trees[key];
60
- await this.unpackSnapshotCore(obj, level + 1);
61
- }
62
- // For future proof, we will support multiple aggregated blobs with any name
63
- // that starts with this.aggregatedBlobName
64
- for (const key of Object.keys(snapshot.blobs)) {
65
- if (!key.startsWith(this.aggregatedBlobName)) {
66
- continue;
67
- }
68
- const blobId = snapshot.blobs[key];
69
- if (blobId !== undefined) {
70
- const blob = await this.getBlob(blobId, snapshot);
71
- for (const [path, value] of BlobAggregator.load(blob)) {
72
- const id = this.getNextVirtualId();
73
- this.setBlob(id, snapshot, value);
74
- const pathSplit = path.split("/");
75
- let subTree = snapshot;
76
- for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {
77
- if (subTree.trees[subPath] === undefined) {
78
- subTree.trees[subPath] = { blobs: {}, trees: {} };
79
- }
80
- subTree = subTree.trees[subPath];
81
- }
82
- const blobName = pathSplit[pathSplit.length - 1];
83
- (0, common_utils_1.assert)(subTree.blobs[blobName] === undefined, 0x0f6 /* "real blob ID exists" */);
84
- subTree.blobs[blobName] = id;
85
- }
86
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
87
- delete snapshot.blobs[this.aggregatedBlobName];
88
- }
89
- }
90
- }
91
- }
92
- exports.SnapshotExtractor = SnapshotExtractor;
93
- /*
94
- * Snapshot extractor class that works in place, i.e. patches snapshot that has
95
- * blob content in ISnapshotTree.blobs itself, not in storage.
96
- * As result, it implements reading and writing of blobs to/from snapshot itself.
97
- * It follows existing pattern that mixes concerns - ISnapshotTree.blobs is used for two
98
- * purposes:
99
- * 1. map path name to blob ID
100
- * 2. map blob ID to blob content
101
- * #2 is what storage (IDocumentStorageService) is for, but in places where we do not have it
102
- * (like loading serialized earlier draft content), blob content is put directly into snapshot.
103
- * Ideally this should be fixed by using BlobCacheStorageService or something similar and
104
- * fixing existing flows to allow switching of storage.
105
- */
106
- class SnapshotExtractorInPlace extends SnapshotExtractor {
107
- async getBlob(id, tree) {
108
- const blob = tree.blobs[id];
109
- (0, common_utils_1.assert)(blob !== undefined, 0x0f7 /* "aggregate blob missing" */);
110
- return (0, common_utils_1.stringToBuffer)(blob, "base64");
111
- }
112
- setBlob(id, tree, content) {
113
- (0, common_utils_1.assert)(tree.blobs[id] === undefined, 0x0f8 /* "blob from aggregate blob exists on its own" */);
114
- tree.blobs[id] = (0, common_utils_1.fromUtf8ToBase64)(content);
115
- }
116
- }
117
- /*
118
- * Snapshot packer and extractor.
119
- * When summary is written it will find and aggregate small blobs into bigger blobs
120
- * When snapshot is read, it will unpack aggregated blobs and provide them transparently to caller.
121
- */
122
- class BlobAggregationStorage extends SnapshotExtractor {
123
- constructor(storage, logger, allowPacking, packingLevel, blobCutOffSize) {
124
- super();
125
- this.storage = storage;
126
- this.logger = logger;
127
- this.allowPacking = allowPacking;
128
- this.packingLevel = packingLevel;
129
- this.blobCutOffSize = blobCutOffSize;
130
- this.loadedFromSummary = false;
131
- this.virtualBlobs = new Map();
132
- }
133
- static wrap(storage, logger, allowPacking, packingLevel = 2) {
134
- var _a, _b, _c;
135
- if (storage instanceof BlobAggregationStorage) {
136
- return storage;
137
- }
138
- const mc = (0, telemetry_utils_1.loggerToMonitoringContext)(logger);
139
- const realAllowPackaging = (_b = (_a = mc.config.getBoolean("FluidAggregateBlobs")) !== null && _a !== void 0 ? _a : allowPacking) !== null && _b !== void 0 ? _b : false;
140
- // Always create BlobAggregationStorage even if storage is not asking for packing.
141
- // This is mostly to avoid cases where future changes in policy would result in inability to
142
- // load old files that were created with aggregation on.
143
- const minBlobSize = (_c = storage.policies) === null || _c === void 0 ? void 0 : _c.minBlobSize;
144
- return new BlobAggregationStorage(storage, logger, realAllowPackaging, packingLevel, minBlobSize);
145
- }
146
- static async unpackSnapshot(snapshot) {
147
- const converter = new SnapshotExtractorInPlace();
148
- await converter.unpackSnapshotCore(snapshot);
149
- }
150
- get policies() {
151
- const policies = this.storage.policies;
152
- if (policies) {
153
- return Object.assign(Object.assign({}, policies), { minBlobSize: undefined });
154
- }
155
- }
156
- async unpackSnapshot(snapshot) {
157
- // SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false
158
- // (I assumed after file was created)
159
- // assert(!this.loadedFromSummary, "unpack without summary");
160
- this.loadedFromSummary = true;
161
- await this.unpackSnapshotCore(snapshot);
162
- }
163
- setBlob(id, tree, content) {
164
- this.virtualBlobs.set(id, (0, common_utils_1.stringToBuffer)(content, "utf-8"));
165
- }
166
- async getBlob(id, tree) {
167
- return this.readBlob(id).catch((error) => {
168
- this.logger.sendErrorEvent({ eventName: "BlobDedupNoAggregateBlob" }, error);
169
- throw error;
170
- });
171
- }
172
- get repositoryUrl() {
173
- return this.storage.repositoryUrl;
174
- }
175
- async getVersions(versionId, count) {
176
- return this.storage.getVersions(versionId, count);
177
- }
178
- async downloadSummary(handle) {
179
- throw new Error("NYI");
180
- }
181
- // for now we are not optimizing these blobs, with assumption that this API is used only
182
- // for big blobs (images)
183
- async createBlob(file) {
184
- return this.storage.createBlob(file);
185
- }
186
- async getSnapshotTree(version) {
187
- const tree = await this.storage.getSnapshotTree(version);
188
- if (tree) {
189
- await this.unpackSnapshot(tree);
190
- }
191
- return tree;
192
- }
193
- async readBlob(id) {
194
- if (this.isRealStorageId(id)) {
195
- return this.storage.readBlob(id);
196
- }
197
- // We support only reading blobs from the summary we loaded from.
198
- // This may need to be extended to any general summary in the future as runtime usage pattern
199
- // of storage changes (for example, data stores start to load from recent summary, not from original
200
- // summary whole container loaded from)
201
- // are there other ways we can get here? createFile is one flow, but we should not be reading blobs
202
- // in such flow
203
- (0, common_utils_1.assert)(this.loadedFromSummary, 0x0f9 /* "never read summary" */);
204
- const blob = this.virtualBlobs.get(id);
205
- (0, common_utils_1.assert)(blob !== undefined, 0x0fa /* "virtual blob not found" */);
206
- return blob;
207
- }
208
- async uploadSummaryWithContext(summary, context) {
209
- const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;
210
- return this.storage.uploadSummaryWithContext(summaryNew, context);
211
- }
212
- // For simplification, we assume that
213
- // - blob aggregation is done at data store level only for now
214
- // - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)
215
- // summary produced by data stores.
216
- // These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated
217
- // blob Or contain aggregated blob that stays relevant for that sub-tree)
218
- // Note:
219
- // From perf perspective, it makes sense to place aggregated blobs one level up in the tree not to create extra
220
- // tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at
221
- // incremental summary time - we would need to understand handles and parse them. In current design we can skip
222
- // that step because if data store is reused, the hole sub-tree is reused included aggregated blob embedded into it
223
- // and that means we can do nothing and be correct!
224
- async compressSmallBlobs(summary, path = "", level = 0, aggregatorArg) {
225
- if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {
226
- return summary;
227
- }
228
- let shouldCompress = false;
229
- let aggregator = aggregatorArg;
230
- // checking if this is a dataStore tree, since we only pack at data store level
231
- if (Object.keys(summary.tree).includes(".component")) {
232
- (0, common_utils_1.assert)(aggregator === undefined, 0x0fb /* "logic err with aggregator" */);
233
- (0, common_utils_1.assert)(level === this.packingLevel, 0x23b /* "we are not packing at the right level" */);
234
- aggregator = new BlobAggregator();
235
- shouldCompress = true;
236
- }
237
- else {
238
- (0, common_utils_1.assert)(level !== this.packingLevel, 0x23c /* "we are not packing at the right level" */);
239
- }
240
- const newSummary = Object.assign({}, summary);
241
- newSummary.tree = Object.assign({}, newSummary.tree);
242
- for (const key of Object.keys(summary.tree)) {
243
- const obj = summary.tree[key];
244
- // Get path relative to root of data store (where we do aggregation)
245
- const newPath = shouldCompress ? key : `${path}/${key}`;
246
- switch (obj.type) {
247
- case protocol_definitions_1.SummaryType.Tree:
248
- // If client created empty tree, keep it as is
249
- // Also do not package search blobs - they are part of storage contract
250
- if (obj.tree !== {} && key !== "__search") {
251
- const tree = await this.compressSmallBlobs(obj, newPath, level + 1, aggregator);
252
- newSummary.tree[key] = tree;
253
- if (tree.tree === {}) {
254
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
255
- delete newSummary.tree[key];
256
- }
257
- }
258
- break;
259
- case protocol_definitions_1.SummaryType.Blob:
260
- if (aggregator &&
261
- typeof obj.content == "string" &&
262
- obj.content.length < this.blobCutOffSize) {
263
- aggregator.addBlob(newPath, obj.content);
264
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
265
- delete newSummary.tree[key];
266
- }
267
- break;
268
- case protocol_definitions_1.SummaryType.Handle: {
269
- // Would be nice to:
270
- // Trees: expand the tree
271
- // Blobs: parse handle and ensure it points to real blob, not virtual blob.
272
- // We can avoid it for now given data store is the granularity of incremental summaries.
273
- let handlePath = obj.handle;
274
- if (handlePath.startsWith("/")) {
275
- handlePath = handlePath.substr(1);
276
- }
277
- // Ensure only whole data stores can be reused, no reusing at deeper level!
278
- (0, common_utils_1.assert)(level === 0, 0x0fc /* "tree reuse at lower level" */);
279
- (0, common_utils_1.assert)(!handlePath.includes("/"), 0x0fd /* "data stores are writing incremental summaries!" */);
280
- break;
281
- }
282
- case protocol_definitions_1.SummaryType.Attachment:
283
- (0, common_utils_1.assert)(this.isRealStorageId(obj.id), 0x0fe /* "attachment is aggregate blob" */);
284
- break;
285
- default:
286
- (0, common_utils_1.unreachableCase)(obj, `Unknown type: ${obj.type}`);
287
- }
288
- }
289
- (0, common_utils_1.assert)(newSummary.tree[this.aggregatedBlobName] === undefined, 0x0ff /* "duplicate aggregate blob" */);
290
- if (shouldCompress) {
291
- // Note: It would be great to add code here to unpack aggregate blob back to normal blobs
292
- // If only one blob made it into aggregate. Currently that does not happen as we always have
293
- // at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.
294
- // But it's possible that in future that would be great addition!
295
- // Good news - it's backward compatible change.
296
- (0, common_utils_1.assert)(aggregator !== undefined, 0x100 /* "logic error" */);
297
- const content = aggregator.getAggregatedBlobContent();
298
- if (content !== undefined) {
299
- newSummary.tree[this.aggregatedBlobName] = {
300
- type: protocol_definitions_1.SummaryType.Blob,
301
- content,
302
- };
303
- }
304
- }
305
- return newSummary;
306
- }
307
- isRealStorageId(id) {
308
- return !id.startsWith(this.virtualIdPrefix);
309
- }
310
- }
311
- exports.BlobAggregationStorage = BlobAggregationStorage;
312
- // Tells data store if it can use incremental summary (i.e. reuse DDSes from previous summary
313
- // when only one DDS changed).
314
- // The answer has to be know long before we enable actual packing. The reason for the is the following:
315
- // A the moment when we enable packing, we should assume that all clients out there wil already have bits
316
- // that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)
317
- // But we can still have clients where some of them already pack, and some do not. If one summary was
318
- // using packing, then it relies on non-incremental summaries going forward, even if next client who
319
- // produced summary is not packing!
320
- // This can have slight improvement by enabling it per file (based on "did summary we loaded from contain
321
- // aggregated blobs"), but that's harder to make reliable, so going for simplicity.
322
- BlobAggregationStorage.fullDataStoreSummaries = true;
323
- //# sourceMappingURL=blobAggregationStorage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blobAggregationStorage.js","sourceRoot":"","sources":["../src/blobAggregationStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,+EAO8C;AAC9C,+DAOsC;AAEtC,qEAA4E;AAE5E;;;GAGG;AACH,SAAS,eAAe,CAAC,IAAqB,EAAE,QAA4B;IAC3E,IAAI,IAAI,YAAY,UAAU,EAAE;QAC/B,8DAA8D;QAC9D,OAAO,IAAA,iCAAkB,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KAC1C;IACD,OAAO,IAAA,6BAAc,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,cAAc;IAApB;QACkB,YAAO,GAAuB,EAAE,CAAC;IAiBnD,CAAC;IAfO,OAAO,CAAC,GAAW,EAAE,OAAe;QAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IACnC,CAAC;IAEM,wBAAwB;QAC9B,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9B,OAAO,SAAS,CAAC;SACjB;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,MA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AAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC7C,CAAC;;AAvQF,wDAwQC;AAvQA,6FAA6F;AAC7F,8BAA8B;AAC9B,uGAAuG;AACvG,yGAAyG;AACzG,4FAA4F;AAC5F,qGAAqG;AACrG,oGAAoG;AACpG,mCAAmC;AACnC,yGAAyG;AACzG,mFAAmF;AACnE,6CAAsB,GAAG,IAAI,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n\tSummaryType,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tassert,\n\tbufferToString,\n\tstringToBuffer,\n\tunreachableCase,\n\tfromUtf8ToBase64,\n\tUint8ArrayToString,\n} from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { loggerToMonitoringContext } from \"@fluidframework/telemetry-utils\";\n\n/*\n * Work around for bufferToString having a bug - it can't consume IsoBuffer!\n * To be removed once bufferToString is fixed!\n */\nfunction bufferToString2(blob: ArrayBufferLike, encoding: \"utf-8\" | \"base64\"): string {\n\tif (blob instanceof Uint8Array) {\n\t\t// IsoBuffer does not have ctor, so it's not in proto chain :(\n\t\treturn Uint8ArrayToString(blob, encoding);\n\t}\n\treturn bufferToString(blob, encoding);\n}\n\n/**\n * Class responsible for aggregating smaller blobs into one and unpacking it later on.\n */\nclass BlobAggregator {\n\tprivate readonly content: [string, string][] = [];\n\n\tpublic addBlob(key: string, content: string) {\n\t\tthis.content.push([key, content]);\n\t}\n\n\tpublic getAggregatedBlobContent() {\n\t\tif (this.content.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn JSON.stringify(this.content);\n\t}\n\n\tstatic load(input: ArrayBufferLike) {\n\t\tconst data = bufferToString2(input, \"utf-8\");\n\t\treturn JSON.parse(data) as [string, string][];\n\t}\n}\n\n/*\n * Base class that deals with unpacking snapshots (in place) containing aggregated blobs\n * It relies on abstract methods for reads and storing unpacked blobs.\n */\nexport abstract class SnapshotExtractor {\n\tprotected readonly aggregatedBlobName = \"__big\";\n\tprotected readonly virtualIdPrefix = \"__\";\n\n\t// counter for generation of virtual storage IDs\n\tprotected virtualIdCounter = 0;\n\tprotected getNextVirtualId() {\n\t\treturn `${this.virtualIdPrefix}${++this.virtualIdCounter}`;\n\t}\n\n\tabstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;\n\tabstract setBlob(id: string, tree: ISnapshotTree, content: string);\n\n\tpublic async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {\n\t\tfor (const key of Object.keys(snapshot.trees)) {\n\t\t\tconst obj = snapshot.trees[key];\n\t\t\tawait this.unpackSnapshotCore(obj, level + 1);\n\t\t}\n\n\t\t// For future proof, we will support multiple aggregated blobs with any name\n\t\t// that starts with this.aggregatedBlobName\n\t\tfor (const key of Object.keys(snapshot.blobs)) {\n\t\t\tif (!key.startsWith(this.aggregatedBlobName)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst blobId = snapshot.blobs[key];\n\t\t\tif (blobId !== undefined) {\n\t\t\t\tconst blob = await this.getBlob(blobId, snapshot);\n\t\t\t\tfor (const [path, value] of BlobAggregator.load(blob)) {\n\t\t\t\t\tconst id = this.getNextVirtualId();\n\t\t\t\t\tthis.setBlob(id, snapshot, value);\n\t\t\t\t\tconst pathSplit = path.split(\"/\");\n\t\t\t\t\tlet subTree = snapshot;\n\t\t\t\t\tfor (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {\n\t\t\t\t\t\tif (subTree.trees[subPath] === undefined) {\n\t\t\t\t\t\t\tsubTree.trees[subPath] = { blobs: {}, trees: {} };\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsubTree = subTree.trees[subPath];\n\t\t\t\t\t}\n\t\t\t\t\tconst blobName = pathSplit[pathSplit.length - 1];\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsubTree.blobs[blobName] === undefined,\n\t\t\t\t\t\t0x0f6 /* \"real blob ID exists\" */,\n\t\t\t\t\t);\n\t\t\t\t\tsubTree.blobs[blobName] = id;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete snapshot.blobs[this.aggregatedBlobName];\n\t\t\t}\n\t\t}\n\t}\n}\n\n/*\n * Snapshot extractor class that works in place, i.e. patches snapshot that has\n * blob content in ISnapshotTree.blobs itself, not in storage.\n * As result, it implements reading and writing of blobs to/from snapshot itself.\n * It follows existing pattern that mixes concerns - ISnapshotTree.blobs is used for two\n * purposes:\n * 1. map path name to blob ID\n * 2. map blob ID to blob content\n * #2 is what storage (IDocumentStorageService) is for, but in places where we do not have it\n * (like loading serialized earlier draft content), blob content is put directly into snapshot.\n * Ideally this should be fixed by using BlobCacheStorageService or something similar and\n * fixing existing flows to allow switching of storage.\n */\nclass SnapshotExtractorInPlace extends SnapshotExtractor {\n\tpublic async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n\t\tconst blob = tree.blobs[id];\n\t\tassert(blob !== undefined, 0x0f7 /* \"aggregate blob missing\" */);\n\t\treturn stringToBuffer(blob, \"base64\");\n\t}\n\n\tpublic setBlob(id: string, tree: ISnapshotTree, content: string) {\n\t\tassert(\n\t\t\ttree.blobs[id] === undefined,\n\t\t\t0x0f8 /* \"blob from aggregate blob exists on its own\" */,\n\t\t);\n\t\ttree.blobs[id] = fromUtf8ToBase64(content);\n\t}\n}\n\n/*\n * Snapshot packer and extractor.\n * When summary is written it will find and aggregate small blobs into bigger blobs\n * When snapshot is read, it will unpack aggregated blobs and provide them transparently to caller.\n */\nexport class BlobAggregationStorage extends SnapshotExtractor implements IDocumentStorageService {\n\t// Tells data store if it can use incremental summary (i.e. reuse DDSes from previous summary\n\t// when only one DDS changed).\n\t// The answer has to be know long before we enable actual packing. The reason for the is the following:\n\t// A the moment when we enable packing, we should assume that all clients out there wil already have bits\n\t// that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)\n\t// But we can still have clients where some of them already pack, and some do not. If one summary was\n\t// using packing, then it relies on non-incremental summaries going forward, even if next client who\n\t// produced summary is not packing!\n\t// This can have slight improvement by enabling it per file (based on \"did summary we loaded from contain\n\t// aggregated blobs\"), but that's harder to make reliable, so going for simplicity.\n\tstatic readonly fullDataStoreSummaries = true;\n\n\tprotected loadedFromSummary = false;\n\n\tprotected virtualBlobs = new Map<string, ArrayBufferLike>();\n\n\tstatic wrap(\n\t\tstorage: IDocumentStorageService,\n\t\tlogger: ITelemetryLogger,\n\t\tallowPacking?: boolean,\n\t\tpackingLevel = 2,\n\t) {\n\t\tif (storage instanceof BlobAggregationStorage) {\n\t\t\treturn storage;\n\t\t}\n\t\tconst mc = loggerToMonitoringContext(logger);\n\t\tconst realAllowPackaging =\n\t\t\tmc.config.getBoolean(\"FluidAggregateBlobs\") ?? allowPacking ?? false;\n\n\t\t// Always create BlobAggregationStorage even if storage is not asking for packing.\n\t\t// This is mostly to avoid cases where future changes in policy would result in inability to\n\t\t// load old files that were created with aggregation on.\n\t\tconst minBlobSize = storage.policies?.minBlobSize;\n\t\treturn new BlobAggregationStorage(\n\t\t\tstorage,\n\t\t\tlogger,\n\t\t\trealAllowPackaging,\n\t\t\tpackingLevel,\n\t\t\tminBlobSize,\n\t\t);\n\t}\n\n\tstatic async unpackSnapshot(snapshot: ISnapshotTree) {\n\t\tconst converter = new SnapshotExtractorInPlace();\n\t\tawait converter.unpackSnapshotCore(snapshot);\n\t}\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tconst policies = this.storage.policies;\n\t\tif (policies) {\n\t\t\treturn { ...policies, minBlobSize: undefined };\n\t\t}\n\t}\n\n\tpublic async unpackSnapshot(snapshot: ISnapshotTree) {\n\t\t// SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false\n\t\t// (I assumed after file was created)\n\t\t// assert(!this.loadedFromSummary, \"unpack without summary\");\n\n\t\tthis.loadedFromSummary = true;\n\t\tawait this.unpackSnapshotCore(snapshot);\n\t}\n\n\tprotected constructor(\n\t\tprivate readonly storage: IDocumentStorageService,\n\t\tprivate readonly logger: ITelemetryLogger,\n\t\tprivate readonly allowPacking: boolean,\n\t\tprivate readonly packingLevel: number,\n\t\tprivate readonly blobCutOffSize?: number,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic setBlob(id: string, tree: ISnapshotTree, content: string) {\n\t\tthis.virtualBlobs.set(id, stringToBuffer(content, \"utf-8\"));\n\t}\n\n\tpublic async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n\t\treturn this.readBlob(id).catch((error) => {\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"BlobDedupNoAggregateBlob\" }, error);\n\t\t\tthrow error;\n\t\t});\n\t}\n\n\tpublic get repositoryUrl() {\n\t\treturn this.storage.repositoryUrl;\n\t}\n\tpublic async getVersions(versionId: string | null, count: number) {\n\t\treturn this.storage.getVersions(versionId, count);\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NYI\");\n\t}\n\n\t// for now we are not optimizing these blobs, with assumption that this API is used only\n\t// for big blobs (images)\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn this.storage.createBlob(file);\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tconst tree = await this.storage.getSnapshotTree(version);\n\t\tif (tree) {\n\t\t\tawait this.unpackSnapshot(tree);\n\t\t}\n\t\treturn tree;\n\t}\n\n\tpublic async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\tif (this.isRealStorageId(id)) {\n\t\t\treturn this.storage.readBlob(id);\n\t\t}\n\t\t// We support only reading blobs from the summary we loaded from.\n\t\t// This may need to be extended to any general summary in the future as runtime usage pattern\n\t\t// of storage changes (for example, data stores start to load from recent summary, not from original\n\t\t// summary whole container loaded from)\n\n\t\t// are there other ways we can get here? createFile is one flow, but we should not be reading blobs\n\t\t// in such flow\n\t\tassert(this.loadedFromSummary, 0x0f9 /* \"never read summary\" */);\n\t\tconst blob = this.virtualBlobs.get(id);\n\t\tassert(blob !== undefined, 0x0fa /* \"virtual blob not found\" */);\n\t\treturn blob;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;\n\t\treturn this.storage.uploadSummaryWithContext(summaryNew, context);\n\t}\n\n\t// For simplification, we assume that\n\t// - blob aggregation is done at data store level only for now\n\t// - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)\n\t// summary produced by data stores.\n\t// These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated\n\t// blob Or contain aggregated blob that stays relevant for that sub-tree)\n\t// Note:\n\t// From perf perspective, it makes sense to place aggregated blobs one level up in the tree not to create extra\n\t// tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at\n\t// incremental summary time - we would need to understand handles and parse them. In current design we can skip\n\t// that step because if data store is reused, the hole sub-tree is reused included aggregated blob embedded into it\n\t// and that means we can do nothing and be correct!\n\tprivate async compressSmallBlobs(\n\t\tsummary: ISummaryTree,\n\t\tpath = \"\",\n\t\tlevel = 0,\n\t\taggregatorArg?: BlobAggregator,\n\t): Promise<ISummaryTree> {\n\t\tif (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {\n\t\t\treturn summary;\n\t\t}\n\n\t\tlet shouldCompress: boolean = false;\n\n\t\tlet aggregator = aggregatorArg;\n\t\t// checking if this is a dataStore tree, since we only pack at data store level\n\t\tif (Object.keys(summary.tree).includes(\".component\")) {\n\t\t\tassert(aggregator === undefined, 0x0fb /* \"logic err with aggregator\" */);\n\t\t\tassert(\n\t\t\t\tlevel === this.packingLevel,\n\t\t\t\t0x23b /* \"we are not packing at the right level\" */,\n\t\t\t);\n\t\t\taggregator = new BlobAggregator();\n\t\t\tshouldCompress = true;\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tlevel !== this.packingLevel,\n\t\t\t\t0x23c /* \"we are not packing at the right level\" */,\n\t\t\t);\n\t\t}\n\n\t\tconst newSummary: ISummaryTree = { ...summary };\n\t\tnewSummary.tree = { ...newSummary.tree };\n\t\tfor (const key of Object.keys(summary.tree)) {\n\t\t\tconst obj = summary.tree[key];\n\t\t\t// Get path relative to root of data store (where we do aggregation)\n\t\t\tconst newPath = shouldCompress ? key : `${path}/${key}`;\n\t\t\tswitch (obj.type) {\n\t\t\t\tcase SummaryType.Tree:\n\t\t\t\t\t// If client created empty tree, keep it as is\n\t\t\t\t\t// Also do not package search blobs - they are part of storage contract\n\t\t\t\t\tif (obj.tree !== {} && key !== \"__search\") {\n\t\t\t\t\t\tconst tree = await this.compressSmallBlobs(\n\t\t\t\t\t\t\tobj,\n\t\t\t\t\t\t\tnewPath,\n\t\t\t\t\t\t\tlevel + 1,\n\t\t\t\t\t\t\taggregator,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tnewSummary.tree[key] = tree;\n\t\t\t\t\t\tif (tree.tree === {}) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\t\t\tdelete newSummary.tree[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase SummaryType.Blob:\n\t\t\t\t\tif (\n\t\t\t\t\t\taggregator &&\n\t\t\t\t\t\ttypeof obj.content == \"string\" &&\n\t\t\t\t\t\tobj.content.length < this.blobCutOffSize\n\t\t\t\t\t) {\n\t\t\t\t\t\taggregator.addBlob(newPath, obj.content);\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\t\tdelete newSummary.tree[key];\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase SummaryType.Handle: {\n\t\t\t\t\t// Would be nice to:\n\t\t\t\t\t// Trees: expand the tree\n\t\t\t\t\t// Blobs: parse handle and ensure it points to real blob, not virtual blob.\n\t\t\t\t\t// We can avoid it for now given data store is the granularity of incremental summaries.\n\t\t\t\t\tlet handlePath = obj.handle;\n\t\t\t\t\tif (handlePath.startsWith(\"/\")) {\n\t\t\t\t\t\thandlePath = handlePath.substr(1);\n\t\t\t\t\t}\n\t\t\t\t\t// Ensure only whole data stores can be reused, no reusing at deeper level!\n\t\t\t\t\tassert(level === 0, 0x0fc /* \"tree reuse at lower level\" */);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!handlePath.includes(\"/\"),\n\t\t\t\t\t\t0x0fd /* \"data stores are writing incremental summaries!\" */,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Attachment:\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.isRealStorageId(obj.id),\n\t\t\t\t\t\t0x0fe /* \"attachment is aggregate blob\" */,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(obj, `Unknown type: ${(obj as any).type}`);\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tnewSummary.tree[this.aggregatedBlobName] === undefined,\n\t\t\t0x0ff /* \"duplicate aggregate blob\" */,\n\t\t);\n\t\tif (shouldCompress) {\n\t\t\t// Note: It would be great to add code here to unpack aggregate blob back to normal blobs\n\t\t\t// If only one blob made it into aggregate. Currently that does not happen as we always have\n\t\t\t// at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.\n\t\t\t// But it's possible that in future that would be great addition!\n\t\t\t// Good news - it's backward compatible change.\n\t\t\tassert(aggregator !== undefined, 0x100 /* \"logic error\" */);\n\t\t\tconst content = aggregator.getAggregatedBlobContent();\n\t\t\tif (content !== undefined) {\n\t\t\t\tnewSummary.tree[this.aggregatedBlobName] = {\n\t\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\t\tcontent,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn newSummary;\n\t}\n\n\tprotected isRealStorageId(id: string): boolean {\n\t\treturn !id.startsWith(this.virtualIdPrefix);\n\t}\n}\n"]}
@@ -1,16 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { IDocumentStorageService, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
6
- import { DocumentStorageServiceProxy } from "./documentStorageServiceProxy";
7
- /**
8
- * IDocumentStorageService adapter with pre-cached blobs.
9
- */
10
- export declare class BlobCacheStorageService extends DocumentStorageServiceProxy {
11
- private readonly blobs;
12
- constructor(internalStorageService: IDocumentStorageService, blobs: Map<string, ArrayBufferLike>);
13
- get policies(): IDocumentStorageServicePolicies | undefined;
14
- readBlob(id: string): Promise<ArrayBufferLike>;
15
- }
16
- //# sourceMappingURL=blobCacheStorageService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blobCacheStorageService.d.ts","sourceRoot":"","sources":["../src/blobCacheStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,uBAAuB,EACvB,+BAA+B,EAC/B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,2BAA2B;IAGtE,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADtB,sBAAsB,EAAE,uBAAuB,EAC9B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;IAKrD,IAAW,QAAQ,IAAI,+BAA+B,GAAG,SAAS,CAEjE;IAEY,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAQ3D"}
@@ -1,29 +0,0 @@
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.BlobCacheStorageService = void 0;
8
- const documentStorageServiceProxy_1 = require("./documentStorageServiceProxy");
9
- /**
10
- * IDocumentStorageService adapter with pre-cached blobs.
11
- */
12
- class BlobCacheStorageService extends documentStorageServiceProxy_1.DocumentStorageServiceProxy {
13
- constructor(internalStorageService, blobs) {
14
- super(internalStorageService);
15
- this.blobs = blobs;
16
- }
17
- get policies() {
18
- return this.internalStorageService.policies;
19
- }
20
- async readBlob(id) {
21
- const blob = this.blobs.get(id);
22
- if (blob !== undefined) {
23
- return blob;
24
- }
25
- return this.internalStorageService.readBlob(id);
26
- }
27
- }
28
- exports.BlobCacheStorageService = BlobCacheStorageService;
29
- //# sourceMappingURL=blobCacheStorageService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blobCacheStorageService.js","sourceRoot":"","sources":["../src/blobCacheStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,+EAA4E;AAE5E;;GAEG;AACH,MAAa,uBAAwB,SAAQ,yDAA2B;IACvE,YACC,sBAA+C,EAC9B,KAAmC;QAEpD,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAFb,UAAK,GAAL,KAAK,CAA8B;IAGrD,CAAC;IAED,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,EAAU;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,IAAI,KAAK,SAAS,EAAE;YACvB,OAAO,IAAI,CAAC;SACZ;QAED,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;CACD;AApBD,0DAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport { DocumentStorageServiceProxy } from \"./documentStorageServiceProxy\";\n\n/**\n * IDocumentStorageService adapter with pre-cached blobs.\n */\nexport class BlobCacheStorageService extends DocumentStorageServiceProxy {\n\tconstructor(\n\t\tinternalStorageService: IDocumentStorageService,\n\t\tprivate readonly blobs: Map<string, ArrayBufferLike>,\n\t) {\n\t\tsuper(internalStorageService);\n\t}\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\treturn this.internalStorageService.policies;\n\t}\n\n\tpublic async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\tconst blob = this.blobs.get(id);\n\t\tif (blob !== undefined) {\n\t\t\treturn blob;\n\t\t}\n\n\t\treturn this.internalStorageService.readBlob(id);\n\t}\n}\n"]}
@@ -1,13 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { IDocumentDeltaStorageService, IStream } from "@fluidframework/driver-definitions";
6
- import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
- /**
8
- * Implementation of IDocumentDeltaStorageService that will always return an empty message queue when fetching messages
9
- */
10
- export declare class EmptyDocumentDeltaStorageService implements IDocumentDeltaStorageService {
11
- fetchMessages(from: number, _to: number | undefined, _abortSignal?: AbortSignal, _cachedOnly?: boolean, _fetchReason?: string): IStream<ISequencedDocumentMessage[]>;
12
- }
13
- //# sourceMappingURL=emptyDocumentDeltaStorageService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emptyDocumentDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/emptyDocumentDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,4BAA4B,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC3F,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAGjF;;GAEG;AACH,qBAAa,gCAAiC,YAAW,4BAA4B;IAC7E,aAAa,CACnB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,YAAY,CAAC,EAAE,WAAW,EAC1B,WAAW,CAAC,EAAE,OAAO,EACrB,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,yBAAyB,EAAE,CAAC;CAKvC"}
@@ -1,20 +0,0 @@
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.EmptyDocumentDeltaStorageService = void 0;
8
- const parallelRequests_1 = require("./parallelRequests");
9
- /**
10
- * Implementation of IDocumentDeltaStorageService that will always return an empty message queue when fetching messages
11
- */
12
- class EmptyDocumentDeltaStorageService {
13
- fetchMessages(from, _to, _abortSignal, _cachedOnly, _fetchReason) {
14
- const queue = new parallelRequests_1.Queue();
15
- queue.pushDone();
16
- return queue;
17
- }
18
- }
19
- exports.EmptyDocumentDeltaStorageService = EmptyDocumentDeltaStorageService;
20
- //# sourceMappingURL=emptyDocumentDeltaStorageService.js.map