@fluidframework/driver-utils 0.51.0-43124 → 0.52.0-44610

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.
@@ -5,6 +5,7 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.BlobAggregationStorage = exports.SnapshotExtractor = void 0;
8
+ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
8
9
  const common_utils_1 = require("@fluidframework/common-utils");
9
10
  // Gate that when flipped, instructs to compress small blobs.
10
11
  // We have to first ship with this gate off, such that we can get to saturation bits
@@ -261,7 +262,7 @@ class BlobAggregationStorage extends SnapshotExtractor {
261
262
  // Get path relative to root of data store (where we do aggregation)
262
263
  const newPath = shouldCompress ? key : `${path}/${key}`;
263
264
  switch (obj.type) {
264
- case 1 /* Tree */:
265
+ case protocol_definitions_1.SummaryType.Tree:
265
266
  // If client created empty tree, keep it as is
266
267
  // Also do not package search blobs - they are part of storage contract
267
268
  if (obj.tree !== {} && key !== "__search") {
@@ -273,14 +274,14 @@ class BlobAggregationStorage extends SnapshotExtractor {
273
274
  }
274
275
  }
275
276
  break;
276
- case 2 /* Blob */:
277
+ case protocol_definitions_1.SummaryType.Blob:
277
278
  if (aggregator && typeof obj.content == "string" && obj.content.length < this.blobCutOffSize) {
278
279
  aggregator.addBlob(newPath, obj.content);
279
280
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
280
281
  delete newSummary.tree[key];
281
282
  }
282
283
  break;
283
- case 3 /* Handle */: {
284
+ case protocol_definitions_1.SummaryType.Handle: {
284
285
  // Would be nice to:
285
286
  // Trees: expand the tree
286
287
  // Blobs: parse handle and ensure it points to real blob, not virtual blob.
@@ -294,7 +295,7 @@ class BlobAggregationStorage extends SnapshotExtractor {
294
295
  common_utils_1.assert(handlePath.indexOf("/") === -1, 0x0fd /* "data stores are writing incremental summaries!" */);
295
296
  break;
296
297
  }
297
- case 4 /* Attachment */:
298
+ case protocol_definitions_1.SummaryType.Attachment:
298
299
  common_utils_1.assert(this.isRealStorageId(obj.id), 0x0fe /* "attachment is aggregate blob" */);
299
300
  break;
300
301
  default:
@@ -312,7 +313,7 @@ class BlobAggregationStorage extends SnapshotExtractor {
312
313
  const content = aggregator.getAggregatedBlobContent();
313
314
  if (content !== undefined) {
314
315
  newSummary.tree[this.aggregatedBlobName] = {
315
- type: 2 /* Blob */,
316
+ type: protocol_definitions_1.SummaryType.Blob,
316
317
  content,
317
318
  };
318
319
  }
@@ -1 +1 @@
1
- {"version":3,"file":"blobAggregationStorage.js","sourceRoot":"","sources":["../src/blobAggregationStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgBH,+DAOuC;AAGvC,6DAA6D;AAC7D,oFAAoF;AACpF,sEAAsE;AACtE,SAAS,iBAAiB;IACtB,IAAI;QACA,sCAAsC;QACtC,2CAA2C;QAC3C,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI,EAAE;YAC3D,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,IAAI,CAAC;aACf;YACD,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,KAAK,CAAC;aAChB;SACJ;KACJ;IAAC,OAAO,CAAC,EAAE,GAAE;IAEd,4BAA4B;IAC5B,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;EAGE;AACF,SAAS,eAAe,CAAC,IAAqB,EAAE,QAA4B;IACxE,IAAI,IAAI,YAAY,UAAU,EAAE,EAAE,8DAA8D;QAC5F,OAAO,iCAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KAC7C;IACD,OAAO,6BAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAEA;;GAEG;AACJ,MAAM,cAAc;IAApB;QACqB,YAAO,GAAsB,EAAE,CAAC;IAiBrD,CAAC;IAfU,OAAO,CAAC,GAAW,EAAE,OAAe;QAC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C,IAAI,CAAC,kBAAkB,CAAC,GAAG;oBACvC,IAAI,cAAkB;oBACtB,OAAO;iBACV,CAAC;aACL;SACJ;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;IAES,eAAe,CAAC,EAAU;QAChC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;;AAtOL,wDAuOC;AAtOG,4FAA4F;AAC5F,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 IDocumentStorageService,\n IDocumentStorageServicePolicies,\n ISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n ICreateBlobResponse,\n ISnapshotTree,\n ISummaryHandle,\n ISummaryTree,\n IVersion,\n SummaryType,\n ITree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n assert,\n bufferToString,\n stringToBuffer,\n unreachableCase,\n fromUtf8ToBase64,\n Uint8ArrayToString,\n } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\n\n// Gate that when flipped, instructs to compress small blobs.\n// We have to first ship with this gate off, such that we can get to saturation bits\n// that can understand compressed format. And only after that flip it.\nfunction gatesAllowPacking() {\n try {\n // Leave override for testing purposes\n // eslint-disable-next-line no-null/no-null\n if (typeof localStorage === \"object\" && localStorage !== null) {\n if (localStorage.FluidAggregateBlobs === \"1\") {\n return true;\n }\n if (localStorage.FluidAggregateBlobs === \"0\") {\n return false;\n }\n }\n } catch (e) {}\n\n // We are starting disabled.\n return false;\n}\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 if (blob instanceof Uint8Array) { // IsoBuffer does not have ctor, so it's not in proto chain :(\n return Uint8ArrayToString(blob, encoding);\n }\n return bufferToString(blob, encoding);\n}\n\n /**\n * Class responsible for aggregating smaller blobs into one and unpacking it later on.\n */\nclass BlobAggregator {\n private readonly content: [string, string][]= [];\n\n public addBlob(key: string, content: string) {\n this.content.push([key, content]);\n }\n\n public getAggregatedBlobContent() {\n if (this.content.length === 0) {\n return undefined;\n }\n return JSON.stringify(this.content);\n }\n\n static load(input: ArrayBufferLike) {\n const data = bufferToString2(input, \"utf-8\");\n return JSON.parse(data) as [string, string][];\n }\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 protected readonly aggregatedBlobName = \"__big\";\n protected readonly virtualIdPrefix = \"__\";\n\n // counter for generation of virtual storage IDs\n protected virtualIdCounter = 0;\n protected getNextVirtualId() {\n return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;\n }\n\n abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;\n abstract setBlob(id: string, tree: ISnapshotTree, content: string);\n\n public async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {\n for (const key of Object.keys(snapshot.trees)) {\n const obj = snapshot.trees[key];\n await this.unpackSnapshotCore(obj, level + 1);\n }\n\n // For future proof, we will support multiple aggregated blobs with any name\n // that starts with this.aggregatedBlobName\n for (const key of Object.keys(snapshot.blobs)) {\n if (!key.startsWith(this.aggregatedBlobName)) { continue; }\n const blobId = snapshot.blobs[key];\n if (blobId !== undefined) {\n const blob = await this.getBlob(blobId, snapshot);\n for (const [path, value] of BlobAggregator.load(blob)) {\n const id = this.getNextVirtualId();\n this.setBlob(id, snapshot, value);\n const pathSplit = path.split(\"/\");\n let subTree = snapshot;\n for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {\n if (subTree.trees[subPath] === undefined) {\n subTree.trees[subPath] = { blobs: {}, commits: {}, trees: {}};\n }\n subTree = subTree.trees[subPath];\n }\n const blobName = pathSplit[pathSplit.length - 1];\n assert(subTree.blobs[blobName] === undefined, 0x0f6 /* \"real blob ID exists\" */);\n subTree.blobs[blobName] = id;\n }\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete snapshot.blobs[this.aggregatedBlobName];\n }\n }\n }\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 public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n const blob = tree.blobs[id];\n assert(blob !== undefined, 0x0f7 /* \"aggregate blob missing\" */);\n return stringToBuffer(blob, \"base64\");\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n assert(tree.blobs[id] === undefined, 0x0f8 /* \"blob from aggregate blob exists on its own\" */);\n tree.blobs[id] = fromUtf8ToBase64(content);\n }\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 // Tells data store if it can use incremental summary (i.e. reuse DDSs from previous summary\n // when only one DDS changed).\n // The answer has to be know long before we enable actual packing. The reason for the is the following:\n // A the moment when we enable packing, we should assume that all clients out there wil already have bits\n // that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)\n // But we can still have clients where some of them already pack, and some do not. If one summary was\n // using packing, then it relies on non-incremental summaries going forward, even if next client who\n // produced summary is not packing!\n // This can have slight improvement by enabling it per file (based on \"did summary we loaded from contain\n // aggregated blobs\"), but that's harder to make reliable, so going for simplicity.\n static readonly fullDataStoreSummaries = true;\n\n protected loadedFromSummary = false;\n\n protected virtualBlobs = new Map<string, ArrayBufferLike>();\n\n static wrap(\n storage: IDocumentStorageService,\n logger: ITelemetryLogger,\n allowPacking = gatesAllowPacking(),\n packingLevel = 2,\n ) {\n if (storage instanceof BlobAggregationStorage) {\n return storage;\n }\n // Always create BlobAggregationStorage even if storage is not asking for packing.\n // This is mostly to avoid cases where future changes in policy would result in inability to\n // load old files that were created with aggregation on.\n const minBlobSize = storage.policies?.minBlobSize;\n return new BlobAggregationStorage(storage, logger, allowPacking, packingLevel, minBlobSize);\n }\n\n static async unpackSnapshot(snapshot: ISnapshotTree) {\n const converter = new SnapshotExtractorInPlace();\n await converter.unpackSnapshotCore(snapshot);\n }\n\n public get policies(): IDocumentStorageServicePolicies | undefined {\n const policies = this.storage.policies;\n if (policies) {\n return { ...policies, minBlobSize: undefined };\n }\n }\n\n public async unpackSnapshot(snapshot: ISnapshotTree) {\n // SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false\n // (I assumed after file was created)\n // assert(!this.loadedFromSummary, \"unpack without summary\");\n\n this.loadedFromSummary = true;\n await this.unpackSnapshotCore(snapshot);\n }\n\n protected constructor(\n private readonly storage: IDocumentStorageService,\n private readonly logger: ITelemetryLogger,\n private readonly allowPacking: boolean,\n private readonly packingLevel: number,\n private readonly blobCutOffSize?: number)\n {\n super();\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n this.virtualBlobs.set(id, stringToBuffer(content, \"utf-8\"));\n }\n\n public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n return this.readBlob(id).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"BlobDedupNoAggregateBlob\" }, error);\n throw error;\n });\n }\n\n public get repositoryUrl() { return this.storage.repositoryUrl; }\n public async getVersions(versionId: string | null, count: number) {\n return this.storage.getVersions(versionId, count);\n }\n\n public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n throw new Error(\"NYI\");\n }\n\n // This is only used through Container.snapshot() for testing purposes\n public async write(root: ITree, parents: string[], message: string, ref: string) {\n return this.storage.write(root, parents, message, ref);\n }\n\n // for now we are not optimizing these blobs, with assumption that this API is used only\n // for big blobs (images)\n public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n return this.storage.createBlob(file);\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n const tree = await this.storage.getSnapshotTree(version);\n if (tree) {\n await this.unpackSnapshot(tree);\n }\n return tree;\n }\n\n public async readBlob(id: string): Promise<ArrayBufferLike> {\n if (this.isRealStorageId(id)) {\n return this.storage.readBlob(id);\n }\n // We support only reading blobs from the summary we loaded from.\n // This may need to be extended to any general summary in the future as runtime usage pattern\n // of storage changes (for example, data stores start to load from recent summary, not from original\n // summary whole container loaded from)\n\n // are there other ways we can get here? createFile is one flow, but we should not be reading blobs\n // in such flow\n assert(this.loadedFromSummary, 0x0f9 /* \"never read summary\" */);\n const blob = this.virtualBlobs.get(id);\n assert(blob !== undefined, 0x0fa /* \"virtual blob not found\" */);\n return blob;\n }\n\n public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {\n const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;\n return this.storage.uploadSummaryWithContext(summaryNew, context);\n }\n\n // For simplification, we assume that\n // - blob aggregation is done at data store level only for now\n // - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)\n // summary produced by data stores.\n // These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated\n // blob Or contain aggregated blob that stays relevant for that sub-tree)\n // Note:\n // From perf perspective, it makes sense to place aggregated blobs one level up in the tree not to create extra\n // tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at\n // incremental summary time - we would need to understand handles and parse them. In current design we can skip\n // that step because if data store is reused, the hole sub-tree is reused included aggregated blob embedded into it\n // and that means we can do nothing and be correct!\n private async compressSmallBlobs(\n summary: ISummaryTree,\n path = \"\",\n level = 0,\n aggregatorArg?: BlobAggregator): Promise<ISummaryTree>\n {\n if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {\n return summary;\n }\n\n let shouldCompress: boolean = false;\n\n let aggregator = aggregatorArg;\n // checking if this is a dataStore tree, since we only pack at data store level\n if (Object.keys(summary.tree).includes(\".component\")) {\n assert(aggregator === undefined, 0x0fb /* \"logic err with aggregator\" */);\n assert(level === this.packingLevel, 0x23b /* \"we are not packing at the right level\" */);\n aggregator = new BlobAggregator();\n shouldCompress = true;\n } else {\n assert(level !== this.packingLevel, 0x23c /* \"we are not packing at the right level\" */);\n }\n\n const newSummary: ISummaryTree = {...summary};\n newSummary.tree = { ...newSummary.tree};\n for (const key of Object.keys(summary.tree)) {\n const obj = summary.tree[key];\n // Get path relative to root of data store (where we do aggregation)\n const newPath = shouldCompress ? key : `${path}/${key}`;\n switch (obj.type) {\n case SummaryType.Tree:\n // If client created empty tree, keep it as is\n // Also do not package search blobs - they are part of storage contract\n if (obj.tree !== {} && key !== \"__search\") {\n const tree = await this.compressSmallBlobs(obj, newPath, level + 1, aggregator);\n newSummary.tree[key] = tree;\n if (tree.tree === {}) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n }\n break;\n case SummaryType.Blob:\n if (aggregator && typeof obj.content == \"string\" && obj.content.length < this.blobCutOffSize) {\n aggregator.addBlob(newPath, obj.content);\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n break;\n case SummaryType.Handle: {\n // Would be nice to:\n // Trees: expand the tree\n // Blobs: parse handle and ensure it points to real blob, not virtual blob.\n // We can avoid it for now given data store is the granularity of incremental summaries.\n let handlePath = obj.handle;\n if (handlePath.startsWith(\"/\")) {\n handlePath = handlePath.substr(1);\n }\n // Ensure only whole data stores can be reused, no reusing at deeper level!\n assert(level === 0, 0x0fc /* \"tree reuse at lower level\" */);\n assert(handlePath.indexOf(\"/\") === -1,\n 0x0fd /* \"data stores are writing incremental summaries!\" */);\n break;\n }\n case SummaryType.Attachment:\n assert(this.isRealStorageId(obj.id), 0x0fe /* \"attachment is aggregate blob\" */);\n break;\n default:\n unreachableCase(obj, `Unknown type: ${(obj as any).type}`);\n }\n }\n\n assert(newSummary.tree[this.aggregatedBlobName] === undefined, 0x0ff /* \"duplicate aggregate blob\" */);\n if (shouldCompress) {\n // Note: It would be great to add code here to unpack aggregate blob back to normal blobs\n // If only one blob made it into aggregate. Currently that does not happen as we always have\n // at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.\n // But it's possible that in future that would be great addition!\n // Good news - it's backward compatible change.\n assert(aggregator !== undefined, 0x100 /* \"logic error\" */);\n const content = aggregator.getAggregatedBlobContent();\n if (content !== undefined) {\n newSummary.tree[this.aggregatedBlobName] = {\n type: SummaryType.Blob,\n content,\n };\n }\n }\n return newSummary;\n }\n\n protected isRealStorageId(id: string): boolean {\n return !id.startsWith(this.virtualIdPrefix);\n }\n}\n"]}
1
+ {"version":3,"file":"blobAggregationStorage.js","sourceRoot":"","sources":["../src/blobAggregationStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,+EAQ8C;AAC9C,+DAOuC;AAGvC,6DAA6D;AAC7D,oFAAoF;AACpF,sEAAsE;AACtE,SAAS,iBAAiB;IACtB,IAAI;QACA,sCAAsC;QACtC,2CAA2C;QAC3C,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI,EAAE;YAC3D,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,IAAI,CAAC;aACf;YACD,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,KAAK,C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C,EAAE,KAAK,CAAC,oCAAoC,CAAC,CAAC;oBACjF,MAAM;gBACV;oBACI,8BAAe,CAAC,GAAG,EAAE,iBAAkB,GAAW,CAAC,IAAI,EAAE,CAAC,CAAC;aAClE;SACJ;QAED,qBAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,SAAS,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACvG,IAAI,cAAc,EAAE;YAChB,yFAAyF;YACzF,4FAA4F;YAC5F,qGAAqG;YACrG,iEAAiE;YACjE,+CAA+C;YAC/C,qBAAM,CAAC,UAAU,KAAK,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC5D,MAAM,OAAO,GAAG,UAAU,CAAC,wBAAwB,EAAE,CAAC;YACtD,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG;oBACvC,IAAI,EAAE,kCAAW,CAAC,IAAI;oBACtB,OAAO;iBACV,CAAC;aACL;SACJ;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;IAES,eAAe,CAAC,EAAU;QAChC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;;AAtOL,wDAuOC;AAtOG,4FAA4F;AAC5F,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 IDocumentStorageService,\n IDocumentStorageServicePolicies,\n ISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n ICreateBlobResponse,\n ISnapshotTree,\n ISummaryHandle,\n ISummaryTree,\n IVersion,\n SummaryType,\n ITree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n assert,\n bufferToString,\n stringToBuffer,\n unreachableCase,\n fromUtf8ToBase64,\n Uint8ArrayToString,\n } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\n\n// Gate that when flipped, instructs to compress small blobs.\n// We have to first ship with this gate off, such that we can get to saturation bits\n// that can understand compressed format. And only after that flip it.\nfunction gatesAllowPacking() {\n try {\n // Leave override for testing purposes\n // eslint-disable-next-line no-null/no-null\n if (typeof localStorage === \"object\" && localStorage !== null) {\n if (localStorage.FluidAggregateBlobs === \"1\") {\n return true;\n }\n if (localStorage.FluidAggregateBlobs === \"0\") {\n return false;\n }\n }\n } catch (e) {}\n\n // We are starting disabled.\n return false;\n}\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 if (blob instanceof Uint8Array) { // IsoBuffer does not have ctor, so it's not in proto chain :(\n return Uint8ArrayToString(blob, encoding);\n }\n return bufferToString(blob, encoding);\n}\n\n /**\n * Class responsible for aggregating smaller blobs into one and unpacking it later on.\n */\nclass BlobAggregator {\n private readonly content: [string, string][]= [];\n\n public addBlob(key: string, content: string) {\n this.content.push([key, content]);\n }\n\n public getAggregatedBlobContent() {\n if (this.content.length === 0) {\n return undefined;\n }\n return JSON.stringify(this.content);\n }\n\n static load(input: ArrayBufferLike) {\n const data = bufferToString2(input, \"utf-8\");\n return JSON.parse(data) as [string, string][];\n }\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 protected readonly aggregatedBlobName = \"__big\";\n protected readonly virtualIdPrefix = \"__\";\n\n // counter for generation of virtual storage IDs\n protected virtualIdCounter = 0;\n protected getNextVirtualId() {\n return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;\n }\n\n abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;\n abstract setBlob(id: string, tree: ISnapshotTree, content: string);\n\n public async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {\n for (const key of Object.keys(snapshot.trees)) {\n const obj = snapshot.trees[key];\n await this.unpackSnapshotCore(obj, level + 1);\n }\n\n // For future proof, we will support multiple aggregated blobs with any name\n // that starts with this.aggregatedBlobName\n for (const key of Object.keys(snapshot.blobs)) {\n if (!key.startsWith(this.aggregatedBlobName)) { continue; }\n const blobId = snapshot.blobs[key];\n if (blobId !== undefined) {\n const blob = await this.getBlob(blobId, snapshot);\n for (const [path, value] of BlobAggregator.load(blob)) {\n const id = this.getNextVirtualId();\n this.setBlob(id, snapshot, value);\n const pathSplit = path.split(\"/\");\n let subTree = snapshot;\n for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {\n if (subTree.trees[subPath] === undefined) {\n subTree.trees[subPath] = { blobs: {}, commits: {}, trees: {}};\n }\n subTree = subTree.trees[subPath];\n }\n const blobName = pathSplit[pathSplit.length - 1];\n assert(subTree.blobs[blobName] === undefined, 0x0f6 /* \"real blob ID exists\" */);\n subTree.blobs[blobName] = id;\n }\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete snapshot.blobs[this.aggregatedBlobName];\n }\n }\n }\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 public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n const blob = tree.blobs[id];\n assert(blob !== undefined, 0x0f7 /* \"aggregate blob missing\" */);\n return stringToBuffer(blob, \"base64\");\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n assert(tree.blobs[id] === undefined, 0x0f8 /* \"blob from aggregate blob exists on its own\" */);\n tree.blobs[id] = fromUtf8ToBase64(content);\n }\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 // Tells data store if it can use incremental summary (i.e. reuse DDSs from previous summary\n // when only one DDS changed).\n // The answer has to be know long before we enable actual packing. The reason for the is the following:\n // A the moment when we enable packing, we should assume that all clients out there wil already have bits\n // that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)\n // But we can still have clients where some of them already pack, and some do not. If one summary was\n // using packing, then it relies on non-incremental summaries going forward, even if next client who\n // produced summary is not packing!\n // This can have slight improvement by enabling it per file (based on \"did summary we loaded from contain\n // aggregated blobs\"), but that's harder to make reliable, so going for simplicity.\n static readonly fullDataStoreSummaries = true;\n\n protected loadedFromSummary = false;\n\n protected virtualBlobs = new Map<string, ArrayBufferLike>();\n\n static wrap(\n storage: IDocumentStorageService,\n logger: ITelemetryLogger,\n allowPacking = gatesAllowPacking(),\n packingLevel = 2,\n ) {\n if (storage instanceof BlobAggregationStorage) {\n return storage;\n }\n // Always create BlobAggregationStorage even if storage is not asking for packing.\n // This is mostly to avoid cases where future changes in policy would result in inability to\n // load old files that were created with aggregation on.\n const minBlobSize = storage.policies?.minBlobSize;\n return new BlobAggregationStorage(storage, logger, allowPacking, packingLevel, minBlobSize);\n }\n\n static async unpackSnapshot(snapshot: ISnapshotTree) {\n const converter = new SnapshotExtractorInPlace();\n await converter.unpackSnapshotCore(snapshot);\n }\n\n public get policies(): IDocumentStorageServicePolicies | undefined {\n const policies = this.storage.policies;\n if (policies) {\n return { ...policies, minBlobSize: undefined };\n }\n }\n\n public async unpackSnapshot(snapshot: ISnapshotTree) {\n // SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false\n // (I assumed after file was created)\n // assert(!this.loadedFromSummary, \"unpack without summary\");\n\n this.loadedFromSummary = true;\n await this.unpackSnapshotCore(snapshot);\n }\n\n protected constructor(\n private readonly storage: IDocumentStorageService,\n private readonly logger: ITelemetryLogger,\n private readonly allowPacking: boolean,\n private readonly packingLevel: number,\n private readonly blobCutOffSize?: number)\n {\n super();\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n this.virtualBlobs.set(id, stringToBuffer(content, \"utf-8\"));\n }\n\n public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n return this.readBlob(id).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"BlobDedupNoAggregateBlob\" }, error);\n throw error;\n });\n }\n\n public get repositoryUrl() { return this.storage.repositoryUrl; }\n public async getVersions(versionId: string | null, count: number) {\n return this.storage.getVersions(versionId, count);\n }\n\n public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n throw new Error(\"NYI\");\n }\n\n // This is only used through Container.snapshot() for testing purposes\n public async write(root: ITree, parents: string[], message: string, ref: string) {\n return this.storage.write(root, parents, message, ref);\n }\n\n // for now we are not optimizing these blobs, with assumption that this API is used only\n // for big blobs (images)\n public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n return this.storage.createBlob(file);\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n const tree = await this.storage.getSnapshotTree(version);\n if (tree) {\n await this.unpackSnapshot(tree);\n }\n return tree;\n }\n\n public async readBlob(id: string): Promise<ArrayBufferLike> {\n if (this.isRealStorageId(id)) {\n return this.storage.readBlob(id);\n }\n // We support only reading blobs from the summary we loaded from.\n // This may need to be extended to any general summary in the future as runtime usage pattern\n // of storage changes (for example, data stores start to load from recent summary, not from original\n // summary whole container loaded from)\n\n // are there other ways we can get here? createFile is one flow, but we should not be reading blobs\n // in such flow\n assert(this.loadedFromSummary, 0x0f9 /* \"never read summary\" */);\n const blob = this.virtualBlobs.get(id);\n assert(blob !== undefined, 0x0fa /* \"virtual blob not found\" */);\n return blob;\n }\n\n public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {\n const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;\n return this.storage.uploadSummaryWithContext(summaryNew, context);\n }\n\n // For simplification, we assume that\n // - blob aggregation is done at data store level only for now\n // - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)\n // summary produced by data stores.\n // These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated\n // blob Or contain aggregated blob that stays relevant for that sub-tree)\n // Note:\n // From perf perspective, it makes sense to place aggregated blobs one level up in the tree not to create extra\n // tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at\n // incremental summary time - we would need to understand handles and parse them. In current design we can skip\n // that step because if data store is reused, the hole sub-tree is reused included aggregated blob embedded into it\n // and that means we can do nothing and be correct!\n private async compressSmallBlobs(\n summary: ISummaryTree,\n path = \"\",\n level = 0,\n aggregatorArg?: BlobAggregator): Promise<ISummaryTree>\n {\n if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {\n return summary;\n }\n\n let shouldCompress: boolean = false;\n\n let aggregator = aggregatorArg;\n // checking if this is a dataStore tree, since we only pack at data store level\n if (Object.keys(summary.tree).includes(\".component\")) {\n assert(aggregator === undefined, 0x0fb /* \"logic err with aggregator\" */);\n assert(level === this.packingLevel, 0x23b /* \"we are not packing at the right level\" */);\n aggregator = new BlobAggregator();\n shouldCompress = true;\n } else {\n assert(level !== this.packingLevel, 0x23c /* \"we are not packing at the right level\" */);\n }\n\n const newSummary: ISummaryTree = {...summary};\n newSummary.tree = { ...newSummary.tree};\n for (const key of Object.keys(summary.tree)) {\n const obj = summary.tree[key];\n // Get path relative to root of data store (where we do aggregation)\n const newPath = shouldCompress ? key : `${path}/${key}`;\n switch (obj.type) {\n case SummaryType.Tree:\n // If client created empty tree, keep it as is\n // Also do not package search blobs - they are part of storage contract\n if (obj.tree !== {} && key !== \"__search\") {\n const tree = await this.compressSmallBlobs(obj, newPath, level + 1, aggregator);\n newSummary.tree[key] = tree;\n if (tree.tree === {}) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n }\n break;\n case SummaryType.Blob:\n if (aggregator && typeof obj.content == \"string\" && obj.content.length < this.blobCutOffSize) {\n aggregator.addBlob(newPath, obj.content);\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n break;\n case SummaryType.Handle: {\n // Would be nice to:\n // Trees: expand the tree\n // Blobs: parse handle and ensure it points to real blob, not virtual blob.\n // We can avoid it for now given data store is the granularity of incremental summaries.\n let handlePath = obj.handle;\n if (handlePath.startsWith(\"/\")) {\n handlePath = handlePath.substr(1);\n }\n // Ensure only whole data stores can be reused, no reusing at deeper level!\n assert(level === 0, 0x0fc /* \"tree reuse at lower level\" */);\n assert(handlePath.indexOf(\"/\") === -1,\n 0x0fd /* \"data stores are writing incremental summaries!\" */);\n break;\n }\n case SummaryType.Attachment:\n assert(this.isRealStorageId(obj.id), 0x0fe /* \"attachment is aggregate blob\" */);\n break;\n default:\n unreachableCase(obj, `Unknown type: ${(obj as any).type}`);\n }\n }\n\n assert(newSummary.tree[this.aggregatedBlobName] === undefined, 0x0ff /* \"duplicate aggregate blob\" */);\n if (shouldCompress) {\n // Note: It would be great to add code here to unpack aggregate blob back to normal blobs\n // If only one blob made it into aggregate. Currently that does not happen as we always have\n // at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.\n // But it's possible that in future that would be great addition!\n // Good news - it's backward compatible change.\n assert(aggregator !== undefined, 0x100 /* \"logic error\" */);\n const content = aggregator.getAggregatedBlobContent();\n if (content !== undefined) {\n newSummary.tree[this.aggregatedBlobName] = {\n type: SummaryType.Blob,\n content,\n };\n }\n }\n return newSummary;\n }\n\n protected isRealStorageId(id: string): boolean {\n return !id.startsWith(this.virtualIdPrefix);\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/driver-utils";
8
- export declare const pkgVersion = "0.51.0-43124";
8
+ export declare const pkgVersion = "0.52.0-44610";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/driver-utils";
11
- exports.pkgVersion = "0.51.0-43124";
11
+ exports.pkgVersion = "0.52.0-44610";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"0.51.0-43124\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"0.52.0-44610\";\n"]}
@@ -5,6 +5,7 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.getQuorumValuesFromProtocolSummary = exports.getDocAttributesFromProtocolSummary = exports.combineAppAndProtocolSummary = void 0;
8
+ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
8
9
  /**
9
10
  * Combine the app summary and protocol summary in 1 tree.
10
11
  * @param appSummary - Summary of the app.
@@ -12,7 +13,7 @@ exports.getQuorumValuesFromProtocolSummary = exports.getDocAttributesFromProtoco
12
13
  */
13
14
  function combineAppAndProtocolSummary(appSummary, protocolSummary) {
14
15
  const createNewSummary = {
15
- type: 1 /* Tree */,
16
+ type: protocol_definitions_1.SummaryType.Tree,
16
17
  tree: {
17
18
  ".protocol": protocolSummary,
18
19
  ".app": appSummary,
@@ -1 +1 @@
1
- {"version":3,"file":"summaryForCreateNew.js","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH;;;;GAIG;AACH,SAAgB,4BAA4B,CACxC,UAAwB,EACxB,eAA6B;IAE7B,MAAM,gBAAgB,GAAiB;QACnC,IAAI,cAAkB;QACtB,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,MAAM,EAAE,UAAU;SACrB;KACJ,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAZD,oEAYC;AAED;;;GAGG;AACH,SAAgB,mCAAmC,CAC/C,eAA6B;;IAE7B,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC;IACvE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAiB,CAAwB,CAAC;IAC/F,kBAAkB,CAAC,IAAI,SAAG,kBAAkB,CAAC,IAAI,mCAAI,CAAC,CAAC;IACvD,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAPD,kFAOC;AAED;;;GAGG;AACH,SAAgB,kCAAkC,CAC9C,eAA6B;IAE7B,MAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,YAA4B,CAAC;IAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAiB,CAAmC,CAAC;IACtG,OAAO,YAAY,CAAC;AACxB,CAAC;AAND,gFAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ISummaryTree,\n SummaryType,\n ISummaryBlob,\n ICommittedProposal,\n IDocumentAttributes,\n} from \"@fluidframework/protocol-definitions\";\n\n/**\n * Combine the app summary and protocol summary in 1 tree.\n * @param appSummary - Summary of the app.\n * @param protocolSummary - Summary of the protocol.\n */\nexport function combineAppAndProtocolSummary(\n appSummary: ISummaryTree,\n protocolSummary: ISummaryTree,\n): ISummaryTree {\n const createNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n return createNewSummary;\n}\n\n/**\n * Extract the attributes from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getDocAttributesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): IDocumentAttributes {\n const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;\n const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;\n documentAttributes.term = documentAttributes.term ?? 1;\n return documentAttributes;\n}\n\n/**\n * Extract quorum values from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getQuorumValuesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): [string, ICommittedProposal][] {\n const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;\n const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [string, ICommittedProposal][];\n return quorumValues;\n}\n"]}
1
+ {"version":3,"file":"summaryForCreateNew.js","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+EAM8C;AAE9C;;;;GAIG;AACH,SAAgB,4BAA4B,CACxC,UAAwB,EACxB,eAA6B;IAE7B,MAAM,gBAAgB,GAAiB;QACnC,IAAI,EAAE,kCAAW,CAAC,IAAI;QACtB,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,MAAM,EAAE,UAAU;SACrB;KACJ,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAZD,oEAYC;AAED;;;GAGG;AACH,SAAgB,mCAAmC,CAC/C,eAA6B;;IAE7B,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC;IACvE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAiB,CAAwB,CAAC;IAC/F,kBAAkB,CAAC,IAAI,SAAG,kBAAkB,CAAC,IAAI,mCAAI,CAAC,CAAC;IACvD,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAPD,kFAOC;AAED;;;GAGG;AACH,SAAgB,kCAAkC,CAC9C,eAA6B;IAE7B,MAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,YAA4B,CAAC;IAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAiB,CAAmC,CAAC;IACtG,OAAO,YAAY,CAAC;AACxB,CAAC;AAND,gFAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ISummaryTree,\n SummaryType,\n ISummaryBlob,\n ICommittedProposal,\n IDocumentAttributes,\n} from \"@fluidframework/protocol-definitions\";\n\n/**\n * Combine the app summary and protocol summary in 1 tree.\n * @param appSummary - Summary of the app.\n * @param protocolSummary - Summary of the protocol.\n */\nexport function combineAppAndProtocolSummary(\n appSummary: ISummaryTree,\n protocolSummary: ISummaryTree,\n): ISummaryTree {\n const createNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n return createNewSummary;\n}\n\n/**\n * Extract the attributes from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getDocAttributesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): IDocumentAttributes {\n const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;\n const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;\n documentAttributes.term = documentAttributes.term ?? 1;\n return documentAttributes;\n}\n\n/**\n * Extract quorum values from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getQuorumValuesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): [string, ICommittedProposal][] {\n const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;\n const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [string, ICommittedProposal][];\n return quorumValues;\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { SummaryType, } from "@fluidframework/protocol-definitions";
5
6
  import { assert, bufferToString, stringToBuffer, unreachableCase, fromUtf8ToBase64, Uint8ArrayToString, } from "@fluidframework/common-utils";
6
7
  // Gate that when flipped, instructs to compress small blobs.
7
8
  // We have to first ship with this gate off, such that we can get to saturation bits
@@ -257,7 +258,7 @@ export class BlobAggregationStorage extends SnapshotExtractor {
257
258
  // Get path relative to root of data store (where we do aggregation)
258
259
  const newPath = shouldCompress ? key : `${path}/${key}`;
259
260
  switch (obj.type) {
260
- case 1 /* Tree */:
261
+ case SummaryType.Tree:
261
262
  // If client created empty tree, keep it as is
262
263
  // Also do not package search blobs - they are part of storage contract
263
264
  if (obj.tree !== {} && key !== "__search") {
@@ -269,14 +270,14 @@ export class BlobAggregationStorage extends SnapshotExtractor {
269
270
  }
270
271
  }
271
272
  break;
272
- case 2 /* Blob */:
273
+ case SummaryType.Blob:
273
274
  if (aggregator && typeof obj.content == "string" && obj.content.length < this.blobCutOffSize) {
274
275
  aggregator.addBlob(newPath, obj.content);
275
276
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
276
277
  delete newSummary.tree[key];
277
278
  }
278
279
  break;
279
- case 3 /* Handle */: {
280
+ case SummaryType.Handle: {
280
281
  // Would be nice to:
281
282
  // Trees: expand the tree
282
283
  // Blobs: parse handle and ensure it points to real blob, not virtual blob.
@@ -290,7 +291,7 @@ export class BlobAggregationStorage extends SnapshotExtractor {
290
291
  assert(handlePath.indexOf("/") === -1, 0x0fd /* "data stores are writing incremental summaries!" */);
291
292
  break;
292
293
  }
293
- case 4 /* Attachment */:
294
+ case SummaryType.Attachment:
294
295
  assert(this.isRealStorageId(obj.id), 0x0fe /* "attachment is aggregate blob" */);
295
296
  break;
296
297
  default:
@@ -308,7 +309,7 @@ export class BlobAggregationStorage extends SnapshotExtractor {
308
309
  const content = aggregator.getAggregatedBlobContent();
309
310
  if (content !== undefined) {
310
311
  newSummary.tree[this.aggregatedBlobName] = {
311
- type: 2 /* Blob */,
312
+ type: SummaryType.Blob,
312
313
  content,
313
314
  };
314
315
  }
@@ -1 +1 @@
1
- {"version":3,"file":"blobAggregationStorage.js","sourceRoot":"","sources":["../src/blobAggregationStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,OAAO,EACH,MAAM,EACN,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACpB,MAAM,8BAA8B,CAAC;AAGvC,6DAA6D;AAC7D,oFAAoF;AACpF,sEAAsE;AACtE,SAAS,iBAAiB;IACtB,IAAI;QACA,sCAAsC;QACtC,2CAA2C;QAC3C,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI,EAAE;YAC3D,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,IAAI,CAA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C;oBACjF,MAAM;gBACV;oBACI,eAAe,CAAC,GAAG,EAAE,iBAAkB,GAAW,CAAC,IAAI,EAAE,CAAC,CAAC;aAClE;SACJ;QAED,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,SAAS,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACvG,IAAI,cAAc,EAAE;YAChB,yFAAyF;YACzF,4FAA4F;YAC5F,qGAAqG;YACrG,iEAAiE;YACjE,+CAA+C;YAC/C,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC5D,MAAM,OAAO,GAAG,UAAU,CAAC,wBAAwB,EAAE,CAAC;YACtD,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG;oBACvC,IAAI,cAAkB;oBACtB,OAAO;iBACV,CAAC;aACL;SACJ;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;IAES,eAAe,CAAC,EAAU;QAChC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;;AArOD,4FAA4F;AAC5F,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 IDocumentStorageService,\n IDocumentStorageServicePolicies,\n ISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n ICreateBlobResponse,\n ISnapshotTree,\n ISummaryHandle,\n ISummaryTree,\n IVersion,\n SummaryType,\n ITree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n assert,\n bufferToString,\n stringToBuffer,\n unreachableCase,\n fromUtf8ToBase64,\n Uint8ArrayToString,\n } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\n\n// Gate that when flipped, instructs to compress small blobs.\n// We have to first ship with this gate off, such that we can get to saturation bits\n// that can understand compressed format. And only after that flip it.\nfunction gatesAllowPacking() {\n try {\n // Leave override for testing purposes\n // eslint-disable-next-line no-null/no-null\n if (typeof localStorage === \"object\" && localStorage !== null) {\n if (localStorage.FluidAggregateBlobs === \"1\") {\n return true;\n }\n if (localStorage.FluidAggregateBlobs === \"0\") {\n return false;\n }\n }\n } catch (e) {}\n\n // We are starting disabled.\n return false;\n}\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 if (blob instanceof Uint8Array) { // IsoBuffer does not have ctor, so it's not in proto chain :(\n return Uint8ArrayToString(blob, encoding);\n }\n return bufferToString(blob, encoding);\n}\n\n /**\n * Class responsible for aggregating smaller blobs into one and unpacking it later on.\n */\nclass BlobAggregator {\n private readonly content: [string, string][]= [];\n\n public addBlob(key: string, content: string) {\n this.content.push([key, content]);\n }\n\n public getAggregatedBlobContent() {\n if (this.content.length === 0) {\n return undefined;\n }\n return JSON.stringify(this.content);\n }\n\n static load(input: ArrayBufferLike) {\n const data = bufferToString2(input, \"utf-8\");\n return JSON.parse(data) as [string, string][];\n }\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 protected readonly aggregatedBlobName = \"__big\";\n protected readonly virtualIdPrefix = \"__\";\n\n // counter for generation of virtual storage IDs\n protected virtualIdCounter = 0;\n protected getNextVirtualId() {\n return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;\n }\n\n abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;\n abstract setBlob(id: string, tree: ISnapshotTree, content: string);\n\n public async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {\n for (const key of Object.keys(snapshot.trees)) {\n const obj = snapshot.trees[key];\n await this.unpackSnapshotCore(obj, level + 1);\n }\n\n // For future proof, we will support multiple aggregated blobs with any name\n // that starts with this.aggregatedBlobName\n for (const key of Object.keys(snapshot.blobs)) {\n if (!key.startsWith(this.aggregatedBlobName)) { continue; }\n const blobId = snapshot.blobs[key];\n if (blobId !== undefined) {\n const blob = await this.getBlob(blobId, snapshot);\n for (const [path, value] of BlobAggregator.load(blob)) {\n const id = this.getNextVirtualId();\n this.setBlob(id, snapshot, value);\n const pathSplit = path.split(\"/\");\n let subTree = snapshot;\n for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {\n if (subTree.trees[subPath] === undefined) {\n subTree.trees[subPath] = { blobs: {}, commits: {}, trees: {}};\n }\n subTree = subTree.trees[subPath];\n }\n const blobName = pathSplit[pathSplit.length - 1];\n assert(subTree.blobs[blobName] === undefined, 0x0f6 /* \"real blob ID exists\" */);\n subTree.blobs[blobName] = id;\n }\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete snapshot.blobs[this.aggregatedBlobName];\n }\n }\n }\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 public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n const blob = tree.blobs[id];\n assert(blob !== undefined, 0x0f7 /* \"aggregate blob missing\" */);\n return stringToBuffer(blob, \"base64\");\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n assert(tree.blobs[id] === undefined, 0x0f8 /* \"blob from aggregate blob exists on its own\" */);\n tree.blobs[id] = fromUtf8ToBase64(content);\n }\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 // Tells data store if it can use incremental summary (i.e. reuse DDSs from previous summary\n // when only one DDS changed).\n // The answer has to be know long before we enable actual packing. The reason for the is the following:\n // A the moment when we enable packing, we should assume that all clients out there wil already have bits\n // that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)\n // But we can still have clients where some of them already pack, and some do not. If one summary was\n // using packing, then it relies on non-incremental summaries going forward, even if next client who\n // produced summary is not packing!\n // This can have slight improvement by enabling it per file (based on \"did summary we loaded from contain\n // aggregated blobs\"), but that's harder to make reliable, so going for simplicity.\n static readonly fullDataStoreSummaries = true;\n\n protected loadedFromSummary = false;\n\n protected virtualBlobs = new Map<string, ArrayBufferLike>();\n\n static wrap(\n storage: IDocumentStorageService,\n logger: ITelemetryLogger,\n allowPacking = gatesAllowPacking(),\n packingLevel = 2,\n ) {\n if (storage instanceof BlobAggregationStorage) {\n return storage;\n }\n // Always create BlobAggregationStorage even if storage is not asking for packing.\n // This is mostly to avoid cases where future changes in policy would result in inability to\n // load old files that were created with aggregation on.\n const minBlobSize = storage.policies?.minBlobSize;\n return new BlobAggregationStorage(storage, logger, allowPacking, packingLevel, minBlobSize);\n }\n\n static async unpackSnapshot(snapshot: ISnapshotTree) {\n const converter = new SnapshotExtractorInPlace();\n await converter.unpackSnapshotCore(snapshot);\n }\n\n public get policies(): IDocumentStorageServicePolicies | undefined {\n const policies = this.storage.policies;\n if (policies) {\n return { ...policies, minBlobSize: undefined };\n }\n }\n\n public async unpackSnapshot(snapshot: ISnapshotTree) {\n // SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false\n // (I assumed after file was created)\n // assert(!this.loadedFromSummary, \"unpack without summary\");\n\n this.loadedFromSummary = true;\n await this.unpackSnapshotCore(snapshot);\n }\n\n protected constructor(\n private readonly storage: IDocumentStorageService,\n private readonly logger: ITelemetryLogger,\n private readonly allowPacking: boolean,\n private readonly packingLevel: number,\n private readonly blobCutOffSize?: number)\n {\n super();\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n this.virtualBlobs.set(id, stringToBuffer(content, \"utf-8\"));\n }\n\n public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n return this.readBlob(id).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"BlobDedupNoAggregateBlob\" }, error);\n throw error;\n });\n }\n\n public get repositoryUrl() { return this.storage.repositoryUrl; }\n public async getVersions(versionId: string | null, count: number) {\n return this.storage.getVersions(versionId, count);\n }\n\n public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n throw new Error(\"NYI\");\n }\n\n // This is only used through Container.snapshot() for testing purposes\n public async write(root: ITree, parents: string[], message: string, ref: string) {\n return this.storage.write(root, parents, message, ref);\n }\n\n // for now we are not optimizing these blobs, with assumption that this API is used only\n // for big blobs (images)\n public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n return this.storage.createBlob(file);\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n const tree = await this.storage.getSnapshotTree(version);\n if (tree) {\n await this.unpackSnapshot(tree);\n }\n return tree;\n }\n\n public async readBlob(id: string): Promise<ArrayBufferLike> {\n if (this.isRealStorageId(id)) {\n return this.storage.readBlob(id);\n }\n // We support only reading blobs from the summary we loaded from.\n // This may need to be extended to any general summary in the future as runtime usage pattern\n // of storage changes (for example, data stores start to load from recent summary, not from original\n // summary whole container loaded from)\n\n // are there other ways we can get here? createFile is one flow, but we should not be reading blobs\n // in such flow\n assert(this.loadedFromSummary, 0x0f9 /* \"never read summary\" */);\n const blob = this.virtualBlobs.get(id);\n assert(blob !== undefined, 0x0fa /* \"virtual blob not found\" */);\n return blob;\n }\n\n public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {\n const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;\n return this.storage.uploadSummaryWithContext(summaryNew, context);\n }\n\n // For simplification, we assume that\n // - blob aggregation is done at data store level only for now\n // - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)\n // summary produced by data stores.\n // These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated\n // blob Or contain aggregated blob that stays relevant for that sub-tree)\n // Note:\n // From perf perspective, it makes sense to place aggregated blobs one level up in the tree not to create extra\n // tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at\n // incremental summary time - we would need to understand handles and parse them. In current design we can skip\n // that step because if data store is reused, the hole sub-tree is reused included aggregated blob embedded into it\n // and that means we can do nothing and be correct!\n private async compressSmallBlobs(\n summary: ISummaryTree,\n path = \"\",\n level = 0,\n aggregatorArg?: BlobAggregator): Promise<ISummaryTree>\n {\n if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {\n return summary;\n }\n\n let shouldCompress: boolean = false;\n\n let aggregator = aggregatorArg;\n // checking if this is a dataStore tree, since we only pack at data store level\n if (Object.keys(summary.tree).includes(\".component\")) {\n assert(aggregator === undefined, 0x0fb /* \"logic err with aggregator\" */);\n assert(level === this.packingLevel, 0x23b /* \"we are not packing at the right level\" */);\n aggregator = new BlobAggregator();\n shouldCompress = true;\n } else {\n assert(level !== this.packingLevel, 0x23c /* \"we are not packing at the right level\" */);\n }\n\n const newSummary: ISummaryTree = {...summary};\n newSummary.tree = { ...newSummary.tree};\n for (const key of Object.keys(summary.tree)) {\n const obj = summary.tree[key];\n // Get path relative to root of data store (where we do aggregation)\n const newPath = shouldCompress ? key : `${path}/${key}`;\n switch (obj.type) {\n case SummaryType.Tree:\n // If client created empty tree, keep it as is\n // Also do not package search blobs - they are part of storage contract\n if (obj.tree !== {} && key !== \"__search\") {\n const tree = await this.compressSmallBlobs(obj, newPath, level + 1, aggregator);\n newSummary.tree[key] = tree;\n if (tree.tree === {}) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n }\n break;\n case SummaryType.Blob:\n if (aggregator && typeof obj.content == \"string\" && obj.content.length < this.blobCutOffSize) {\n aggregator.addBlob(newPath, obj.content);\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n break;\n case SummaryType.Handle: {\n // Would be nice to:\n // Trees: expand the tree\n // Blobs: parse handle and ensure it points to real blob, not virtual blob.\n // We can avoid it for now given data store is the granularity of incremental summaries.\n let handlePath = obj.handle;\n if (handlePath.startsWith(\"/\")) {\n handlePath = handlePath.substr(1);\n }\n // Ensure only whole data stores can be reused, no reusing at deeper level!\n assert(level === 0, 0x0fc /* \"tree reuse at lower level\" */);\n assert(handlePath.indexOf(\"/\") === -1,\n 0x0fd /* \"data stores are writing incremental summaries!\" */);\n break;\n }\n case SummaryType.Attachment:\n assert(this.isRealStorageId(obj.id), 0x0fe /* \"attachment is aggregate blob\" */);\n break;\n default:\n unreachableCase(obj, `Unknown type: ${(obj as any).type}`);\n }\n }\n\n assert(newSummary.tree[this.aggregatedBlobName] === undefined, 0x0ff /* \"duplicate aggregate blob\" */);\n if (shouldCompress) {\n // Note: It would be great to add code here to unpack aggregate blob back to normal blobs\n // If only one blob made it into aggregate. Currently that does not happen as we always have\n // at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.\n // But it's possible that in future that would be great addition!\n // Good news - it's backward compatible change.\n assert(aggregator !== undefined, 0x100 /* \"logic error\" */);\n const content = aggregator.getAggregatedBlobContent();\n if (content !== undefined) {\n newSummary.tree[this.aggregatedBlobName] = {\n type: SummaryType.Blob,\n content,\n };\n }\n }\n return newSummary;\n }\n\n protected isRealStorageId(id: string): boolean {\n return !id.startsWith(this.virtualIdPrefix);\n }\n}\n"]}
1
+ {"version":3,"file":"blobAggregationStorage.js","sourceRoot":"","sources":["../src/blobAggregationStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAMH,WAAW,GAEd,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACH,MAAM,EACN,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACpB,MAAM,8BAA8B,CAAC;AAGvC,6DAA6D;AAC7D,oFAAoF;AACpF,sEAAsE;AACtE,SAAS,iBAAiB;IACtB,IAAI;QACA,sCAAsC;QACtC,2CAA2C;QAC3C,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI,EAAE;YAC3D,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,IAAI,CAAC;aACf;YACD,IAAK,YAAY,CAAC,mBAAmB,KAAK,GAAG,EAAE;gBAC3C,OAAO,KAAK,CAAC;aAChB;SACJ;KACJ;IAAC,OAAO,CAAC,EAAE,GAAE;IAEd,4BAA4B;IAC5B,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;EAGE;AACF,SAAS,eAAe,CAAC,IAAqB,EAAE,QAA4B;IACxE,IAAI,IAAI,YAAY,UAAU,EAAE,EAAE,8DAA8D;QAC5F,OAAO,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KAC7C;IACD,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAEA;;GAEG;AACJ,MAAM,cAAc;IAApB;QACqB,YAAO,GAAsB,EAAE,CAAC;IAiBrD,CAAC;IAfU,OAAO,CAAC,GAAW,EAAE,OAAe;QACvC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IACtC,CAAC;IAEM,wBAAwB;QAC3B,IAAI,IAAI,CAAC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C,IAAI;oBACtB,OAAO;iBACV,CAAC;aACL;SACJ;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;IAES,eAAe,CAAC,EAAU;QAChC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;;AArOD,4FAA4F;AAC5F,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 IDocumentStorageService,\n IDocumentStorageServicePolicies,\n ISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n ICreateBlobResponse,\n ISnapshotTree,\n ISummaryHandle,\n ISummaryTree,\n IVersion,\n SummaryType,\n ITree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n assert,\n bufferToString,\n stringToBuffer,\n unreachableCase,\n fromUtf8ToBase64,\n Uint8ArrayToString,\n } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\n\n// Gate that when flipped, instructs to compress small blobs.\n// We have to first ship with this gate off, such that we can get to saturation bits\n// that can understand compressed format. And only after that flip it.\nfunction gatesAllowPacking() {\n try {\n // Leave override for testing purposes\n // eslint-disable-next-line no-null/no-null\n if (typeof localStorage === \"object\" && localStorage !== null) {\n if (localStorage.FluidAggregateBlobs === \"1\") {\n return true;\n }\n if (localStorage.FluidAggregateBlobs === \"0\") {\n return false;\n }\n }\n } catch (e) {}\n\n // We are starting disabled.\n return false;\n}\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 if (blob instanceof Uint8Array) { // IsoBuffer does not have ctor, so it's not in proto chain :(\n return Uint8ArrayToString(blob, encoding);\n }\n return bufferToString(blob, encoding);\n}\n\n /**\n * Class responsible for aggregating smaller blobs into one and unpacking it later on.\n */\nclass BlobAggregator {\n private readonly content: [string, string][]= [];\n\n public addBlob(key: string, content: string) {\n this.content.push([key, content]);\n }\n\n public getAggregatedBlobContent() {\n if (this.content.length === 0) {\n return undefined;\n }\n return JSON.stringify(this.content);\n }\n\n static load(input: ArrayBufferLike) {\n const data = bufferToString2(input, \"utf-8\");\n return JSON.parse(data) as [string, string][];\n }\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 protected readonly aggregatedBlobName = \"__big\";\n protected readonly virtualIdPrefix = \"__\";\n\n // counter for generation of virtual storage IDs\n protected virtualIdCounter = 0;\n protected getNextVirtualId() {\n return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;\n }\n\n abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;\n abstract setBlob(id: string, tree: ISnapshotTree, content: string);\n\n public async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {\n for (const key of Object.keys(snapshot.trees)) {\n const obj = snapshot.trees[key];\n await this.unpackSnapshotCore(obj, level + 1);\n }\n\n // For future proof, we will support multiple aggregated blobs with any name\n // that starts with this.aggregatedBlobName\n for (const key of Object.keys(snapshot.blobs)) {\n if (!key.startsWith(this.aggregatedBlobName)) { continue; }\n const blobId = snapshot.blobs[key];\n if (blobId !== undefined) {\n const blob = await this.getBlob(blobId, snapshot);\n for (const [path, value] of BlobAggregator.load(blob)) {\n const id = this.getNextVirtualId();\n this.setBlob(id, snapshot, value);\n const pathSplit = path.split(\"/\");\n let subTree = snapshot;\n for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {\n if (subTree.trees[subPath] === undefined) {\n subTree.trees[subPath] = { blobs: {}, commits: {}, trees: {}};\n }\n subTree = subTree.trees[subPath];\n }\n const blobName = pathSplit[pathSplit.length - 1];\n assert(subTree.blobs[blobName] === undefined, 0x0f6 /* \"real blob ID exists\" */);\n subTree.blobs[blobName] = id;\n }\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete snapshot.blobs[this.aggregatedBlobName];\n }\n }\n }\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 public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n const blob = tree.blobs[id];\n assert(blob !== undefined, 0x0f7 /* \"aggregate blob missing\" */);\n return stringToBuffer(blob, \"base64\");\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n assert(tree.blobs[id] === undefined, 0x0f8 /* \"blob from aggregate blob exists on its own\" */);\n tree.blobs[id] = fromUtf8ToBase64(content);\n }\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 // Tells data store if it can use incremental summary (i.e. reuse DDSs from previous summary\n // when only one DDS changed).\n // The answer has to be know long before we enable actual packing. The reason for the is the following:\n // A the moment when we enable packing, we should assume that all clients out there wil already have bits\n // that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)\n // But we can still have clients where some of them already pack, and some do not. If one summary was\n // using packing, then it relies on non-incremental summaries going forward, even if next client who\n // produced summary is not packing!\n // This can have slight improvement by enabling it per file (based on \"did summary we loaded from contain\n // aggregated blobs\"), but that's harder to make reliable, so going for simplicity.\n static readonly fullDataStoreSummaries = true;\n\n protected loadedFromSummary = false;\n\n protected virtualBlobs = new Map<string, ArrayBufferLike>();\n\n static wrap(\n storage: IDocumentStorageService,\n logger: ITelemetryLogger,\n allowPacking = gatesAllowPacking(),\n packingLevel = 2,\n ) {\n if (storage instanceof BlobAggregationStorage) {\n return storage;\n }\n // Always create BlobAggregationStorage even if storage is not asking for packing.\n // This is mostly to avoid cases where future changes in policy would result in inability to\n // load old files that were created with aggregation on.\n const minBlobSize = storage.policies?.minBlobSize;\n return new BlobAggregationStorage(storage, logger, allowPacking, packingLevel, minBlobSize);\n }\n\n static async unpackSnapshot(snapshot: ISnapshotTree) {\n const converter = new SnapshotExtractorInPlace();\n await converter.unpackSnapshotCore(snapshot);\n }\n\n public get policies(): IDocumentStorageServicePolicies | undefined {\n const policies = this.storage.policies;\n if (policies) {\n return { ...policies, minBlobSize: undefined };\n }\n }\n\n public async unpackSnapshot(snapshot: ISnapshotTree) {\n // SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false\n // (I assumed after file was created)\n // assert(!this.loadedFromSummary, \"unpack without summary\");\n\n this.loadedFromSummary = true;\n await this.unpackSnapshotCore(snapshot);\n }\n\n protected constructor(\n private readonly storage: IDocumentStorageService,\n private readonly logger: ITelemetryLogger,\n private readonly allowPacking: boolean,\n private readonly packingLevel: number,\n private readonly blobCutOffSize?: number)\n {\n super();\n }\n\n public setBlob(id: string, tree: ISnapshotTree, content: string) {\n this.virtualBlobs.set(id, stringToBuffer(content, \"utf-8\"));\n }\n\n public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {\n return this.readBlob(id).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"BlobDedupNoAggregateBlob\" }, error);\n throw error;\n });\n }\n\n public get repositoryUrl() { return this.storage.repositoryUrl; }\n public async getVersions(versionId: string | null, count: number) {\n return this.storage.getVersions(versionId, count);\n }\n\n public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n throw new Error(\"NYI\");\n }\n\n // This is only used through Container.snapshot() for testing purposes\n public async write(root: ITree, parents: string[], message: string, ref: string) {\n return this.storage.write(root, parents, message, ref);\n }\n\n // for now we are not optimizing these blobs, with assumption that this API is used only\n // for big blobs (images)\n public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n return this.storage.createBlob(file);\n }\n\n public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n const tree = await this.storage.getSnapshotTree(version);\n if (tree) {\n await this.unpackSnapshot(tree);\n }\n return tree;\n }\n\n public async readBlob(id: string): Promise<ArrayBufferLike> {\n if (this.isRealStorageId(id)) {\n return this.storage.readBlob(id);\n }\n // We support only reading blobs from the summary we loaded from.\n // This may need to be extended to any general summary in the future as runtime usage pattern\n // of storage changes (for example, data stores start to load from recent summary, not from original\n // summary whole container loaded from)\n\n // are there other ways we can get here? createFile is one flow, but we should not be reading blobs\n // in such flow\n assert(this.loadedFromSummary, 0x0f9 /* \"never read summary\" */);\n const blob = this.virtualBlobs.get(id);\n assert(blob !== undefined, 0x0fa /* \"virtual blob not found\" */);\n return blob;\n }\n\n public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {\n const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;\n return this.storage.uploadSummaryWithContext(summaryNew, context);\n }\n\n // For simplification, we assume that\n // - blob aggregation is done at data store level only for now\n // - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)\n // summary produced by data stores.\n // These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated\n // blob Or contain aggregated blob that stays relevant for that sub-tree)\n // Note:\n // From perf perspective, it makes sense to place aggregated blobs one level up in the tree not to create extra\n // tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at\n // incremental summary time - we would need to understand handles and parse them. In current design we can skip\n // that step because if data store is reused, the hole sub-tree is reused included aggregated blob embedded into it\n // and that means we can do nothing and be correct!\n private async compressSmallBlobs(\n summary: ISummaryTree,\n path = \"\",\n level = 0,\n aggregatorArg?: BlobAggregator): Promise<ISummaryTree>\n {\n if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {\n return summary;\n }\n\n let shouldCompress: boolean = false;\n\n let aggregator = aggregatorArg;\n // checking if this is a dataStore tree, since we only pack at data store level\n if (Object.keys(summary.tree).includes(\".component\")) {\n assert(aggregator === undefined, 0x0fb /* \"logic err with aggregator\" */);\n assert(level === this.packingLevel, 0x23b /* \"we are not packing at the right level\" */);\n aggregator = new BlobAggregator();\n shouldCompress = true;\n } else {\n assert(level !== this.packingLevel, 0x23c /* \"we are not packing at the right level\" */);\n }\n\n const newSummary: ISummaryTree = {...summary};\n newSummary.tree = { ...newSummary.tree};\n for (const key of Object.keys(summary.tree)) {\n const obj = summary.tree[key];\n // Get path relative to root of data store (where we do aggregation)\n const newPath = shouldCompress ? key : `${path}/${key}`;\n switch (obj.type) {\n case SummaryType.Tree:\n // If client created empty tree, keep it as is\n // Also do not package search blobs - they are part of storage contract\n if (obj.tree !== {} && key !== \"__search\") {\n const tree = await this.compressSmallBlobs(obj, newPath, level + 1, aggregator);\n newSummary.tree[key] = tree;\n if (tree.tree === {}) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n }\n break;\n case SummaryType.Blob:\n if (aggregator && typeof obj.content == \"string\" && obj.content.length < this.blobCutOffSize) {\n aggregator.addBlob(newPath, obj.content);\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete newSummary.tree[key];\n }\n break;\n case SummaryType.Handle: {\n // Would be nice to:\n // Trees: expand the tree\n // Blobs: parse handle and ensure it points to real blob, not virtual blob.\n // We can avoid it for now given data store is the granularity of incremental summaries.\n let handlePath = obj.handle;\n if (handlePath.startsWith(\"/\")) {\n handlePath = handlePath.substr(1);\n }\n // Ensure only whole data stores can be reused, no reusing at deeper level!\n assert(level === 0, 0x0fc /* \"tree reuse at lower level\" */);\n assert(handlePath.indexOf(\"/\") === -1,\n 0x0fd /* \"data stores are writing incremental summaries!\" */);\n break;\n }\n case SummaryType.Attachment:\n assert(this.isRealStorageId(obj.id), 0x0fe /* \"attachment is aggregate blob\" */);\n break;\n default:\n unreachableCase(obj, `Unknown type: ${(obj as any).type}`);\n }\n }\n\n assert(newSummary.tree[this.aggregatedBlobName] === undefined, 0x0ff /* \"duplicate aggregate blob\" */);\n if (shouldCompress) {\n // Note: It would be great to add code here to unpack aggregate blob back to normal blobs\n // If only one blob made it into aggregate. Currently that does not happen as we always have\n // at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.\n // But it's possible that in future that would be great addition!\n // Good news - it's backward compatible change.\n assert(aggregator !== undefined, 0x100 /* \"logic error\" */);\n const content = aggregator.getAggregatedBlobContent();\n if (content !== undefined) {\n newSummary.tree[this.aggregatedBlobName] = {\n type: SummaryType.Blob,\n content,\n };\n }\n }\n return newSummary;\n }\n\n protected isRealStorageId(id: string): boolean {\n return !id.startsWith(this.virtualIdPrefix);\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/driver-utils";
8
- export declare const pkgVersion = "0.51.0-43124";
8
+ export declare const pkgVersion = "0.52.0-44610";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/driver-utils";
8
- export const pkgVersion = "0.51.0-43124";
8
+ export const pkgVersion = "0.52.0-44610";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"0.51.0-43124\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"0.52.0-44610\";\n"]}
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { SummaryType, } from "@fluidframework/protocol-definitions";
5
6
  /**
6
7
  * Combine the app summary and protocol summary in 1 tree.
7
8
  * @param appSummary - Summary of the app.
@@ -9,7 +10,7 @@
9
10
  */
10
11
  export function combineAppAndProtocolSummary(appSummary, protocolSummary) {
11
12
  const createNewSummary = {
12
- type: 1 /* Tree */,
13
+ type: SummaryType.Tree,
13
14
  tree: {
14
15
  ".protocol": protocolSummary,
15
16
  ".app": appSummary,
@@ -1 +1 @@
1
- {"version":3,"file":"summaryForCreateNew.js","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CACxC,UAAwB,EACxB,eAA6B;IAE7B,MAAM,gBAAgB,GAAiB;QACnC,IAAI,cAAkB;QACtB,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,MAAM,EAAE,UAAU;SACrB;KACJ,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CAC/C,eAA6B;;IAE7B,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC;IACvE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAiB,CAAwB,CAAC;IAC/F,kBAAkB,CAAC,IAAI,SAAG,kBAAkB,CAAC,IAAI,mCAAI,CAAC,CAAC;IACvD,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAC9C,eAA6B;IAE7B,MAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,YAA4B,CAAC;IAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAiB,CAAmC,CAAC;IACtG,OAAO,YAAY,CAAC;AACxB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ISummaryTree,\n SummaryType,\n ISummaryBlob,\n ICommittedProposal,\n IDocumentAttributes,\n} from \"@fluidframework/protocol-definitions\";\n\n/**\n * Combine the app summary and protocol summary in 1 tree.\n * @param appSummary - Summary of the app.\n * @param protocolSummary - Summary of the protocol.\n */\nexport function combineAppAndProtocolSummary(\n appSummary: ISummaryTree,\n protocolSummary: ISummaryTree,\n): ISummaryTree {\n const createNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n return createNewSummary;\n}\n\n/**\n * Extract the attributes from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getDocAttributesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): IDocumentAttributes {\n const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;\n const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;\n documentAttributes.term = documentAttributes.term ?? 1;\n return documentAttributes;\n}\n\n/**\n * Extract quorum values from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getQuorumValuesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): [string, ICommittedProposal][] {\n const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;\n const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [string, ICommittedProposal][];\n return quorumValues;\n}\n"]}
1
+ {"version":3,"file":"summaryForCreateNew.js","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,WAAW,GAId,MAAM,sCAAsC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CACxC,UAAwB,EACxB,eAA6B;IAE7B,MAAM,gBAAgB,GAAiB;QACnC,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,MAAM,EAAE,UAAU;SACrB;KACJ,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CAC/C,eAA6B;;IAE7B,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC;IACvE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAiB,CAAwB,CAAC;IAC/F,kBAAkB,CAAC,IAAI,SAAG,kBAAkB,CAAC,IAAI,mCAAI,CAAC,CAAC;IACvD,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAC9C,eAA6B;IAE7B,MAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,YAA4B,CAAC;IAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAiB,CAAmC,CAAC;IACtG,OAAO,YAAY,CAAC;AACxB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ISummaryTree,\n SummaryType,\n ISummaryBlob,\n ICommittedProposal,\n IDocumentAttributes,\n} from \"@fluidframework/protocol-definitions\";\n\n/**\n * Combine the app summary and protocol summary in 1 tree.\n * @param appSummary - Summary of the app.\n * @param protocolSummary - Summary of the protocol.\n */\nexport function combineAppAndProtocolSummary(\n appSummary: ISummaryTree,\n protocolSummary: ISummaryTree,\n): ISummaryTree {\n const createNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n return createNewSummary;\n}\n\n/**\n * Extract the attributes from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getDocAttributesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): IDocumentAttributes {\n const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;\n const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;\n documentAttributes.term = documentAttributes.term ?? 1;\n return documentAttributes;\n}\n\n/**\n * Extract quorum values from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getQuorumValuesFromProtocolSummary(\n protocolSummary: ISummaryTree,\n): [string, ICommittedProposal][] {\n const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;\n const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [string, ICommittedProposal][];\n return quorumValues;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/driver-utils",
3
- "version": "0.51.0-43124",
3
+ "version": "0.52.0-44610",
4
4
  "description": "Collection of utility functions for Fluid drivers",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": "https://github.com/microsoft/FluidFramework",
@@ -57,20 +57,20 @@
57
57
  "dependencies": {
58
58
  "@fluidframework/common-definitions": "^0.20.1",
59
59
  "@fluidframework/common-utils": "^0.32.1",
60
- "@fluidframework/core-interfaces": "^0.40.0",
61
- "@fluidframework/driver-definitions": "^0.41.0",
62
- "@fluidframework/gitresources": "^0.1033.0",
63
- "@fluidframework/protocol-base": "^0.1033.0",
64
- "@fluidframework/protocol-definitions": "^0.1025.0",
65
- "@fluidframework/telemetry-utils": "0.51.0-43124",
66
- "axios": "^0.21.1",
60
+ "@fluidframework/core-interfaces": "^0.41.0-0",
61
+ "@fluidframework/driver-definitions": "^0.42.0-0",
62
+ "@fluidframework/gitresources": "^0.1034.0-0",
63
+ "@fluidframework/protocol-base": "^0.1034.0-0",
64
+ "@fluidframework/protocol-definitions": "^0.1026.0-0",
65
+ "@fluidframework/telemetry-utils": "0.52.0-44610",
66
+ "axios": "^0.21.2",
67
67
  "uuid": "^8.3.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@fluidframework/build-common": "^0.23.0",
71
71
  "@fluidframework/eslint-config-fluid": "^0.24.0",
72
- "@fluidframework/mocha-test-setup": "0.51.0-43124",
73
- "@fluidframework/runtime-utils": "0.51.0-43124",
72
+ "@fluidframework/mocha-test-setup": "0.52.0-44610",
73
+ "@fluidframework/runtime-utils": "0.52.0-44610",
74
74
  "@microsoft/api-extractor": "^7.16.1",
75
75
  "@types/mocha": "^8.2.2",
76
76
  "@types/node": "^12.19.0",
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/driver-utils";
9
- export const pkgVersion = "0.51.0-43124";
9
+ export const pkgVersion = "0.52.0-44610";