@fluidframework/driver-utils 2.90.0-378676 → 2.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +1 -1
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -1
- package/dist/adapters/predefinedAdapters.d.ts.map +1 -1
- package/dist/adapters/predefinedAdapters.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +1 -1
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -1
- package/lib/adapters/predefinedAdapters.d.ts.map +1 -1
- package/lib/adapters/predefinedAdapters.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +12 -12
- package/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts +1 -1
- package/src/adapters/predefinedAdapters.ts +0 -2
- package/src/packageVersion.ts +1 -1
package/CHANGELOG.md
CHANGED
package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js
CHANGED
|
@@ -149,7 +149,7 @@ class DocumentStorageServiceCompressionAdapter extends documentStorageServicePro
|
|
|
149
149
|
decompressed = originalBlob;
|
|
150
150
|
}
|
|
151
151
|
else if (algorithm === compressionTypes_js_1.SummaryCompressionAlgorithm.LZ4) {
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
153
153
|
decompressed = (0, lz4js_1.decompress)(originalBlob);
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentStorageServiceSummaryBlobCompressionAdapter.js","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsE;AACtE,kEAA6D;AAC7D,2EAM4C;AAO5C,iCAA6C;AAE7C,4FAAsF;AACtF,gEAGgC;AAEhC;;GAEG;AACU,QAAA,mBAAmB,GAAG,uBAAuB,CAAC;AAC3D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,MAAa,wCAAyC,SAAQ,4DAA2B;IAGxF,YACC,OAAgC,EACf,OAAkC;QAEnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAFE,YAAO,GAAP,OAAO,CAA2B;QAJ5C,0BAAqB,GAAY,KAAK,CAAC;IAO/C,CAAC;IAED,IAAW,OAAO;QACjB,OAAO,IAAI,CAAC,sBAAsB,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,SAAS,CAAC,IAAqB;QAC7C,MAAM,SAAS,GAAG,wBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,sCAAsC;QACtC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;IACpC,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,qBAAqB,CAAC,IAAqB;QACzD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC1B,CAAC,CAAC,sCAAsC;gBACvC,wBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;YAC/B,CAAC,CAAC,iDAA2B,CAAC,IAAI,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,oBAAoB,CAClC,IAAqB,EACrB,S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C,CAAC;QAC/D,MAAM,cAAc,GAAG;YACtB,IAAI,EAAE,gCAAW,CAAC,IAAI;YACtB,OAAO,EAAE,wBAAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClC,CAAC;QACF,OAAO,cAAc,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,AAhBkC,CAgBjC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type Buffer, IsoBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype ISummaryBlob,\n\ttype ISummaryHandle,\n\ttype ISummaryTree,\n\ttype SummaryObject,\n\tSummaryType,\n} from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { compress, decompress } from \"lz4js\";\n\nimport { DocumentStorageServiceProxy } from \"../../../documentStorageServiceProxy.js\";\nimport {\n\tSummaryCompressionAlgorithm,\n\ttype ICompressionStorageConfig,\n} from \"../compressionTypes.js\";\n\n/**\n * @internal\n */\nexport const blobHeadersBlobName = \".metadata.blobHeaders\";\nconst metadataBlobName = \".metadata\";\n\n/**\n * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.\n * The identification of the compressed blobs is done by adding a compression markup blob to the summary.\n * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,\n * which is compressed also contain the compression algorithm enumerated value from the\n * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not\n * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .\n * In case, the markup blob is present, it is expected that the first byte of the markup blob\n * will contain the info about the compression. If the first byte is not present, it is assumed\n * that the compression is not enabled and no first prefix byte is present in the blobs.\n * @public\n */\nexport class DocumentStorageServiceCompressionAdapter extends DocumentStorageServiceProxy {\n\tprivate _isCompressionEnabled: boolean = false;\n\n\tconstructor(\n\t\tservice: IDocumentStorageService,\n\t\tprivate readonly _config: ICompressionStorageConfig,\n\t) {\n\t\tsuper(service);\n\t}\n\n\tpublic get service(): IDocumentStorageService {\n\t\treturn this.internalStorageService;\n\t}\n\n\t/**\n\t * This method returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t * @param blob - The blob to compress.\n\t * @returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t */\n\tprivate static hasPrefix(blob: ArrayBufferLike): boolean {\n\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn (firstByte & 0xf0) === 0xb0;\n\t}\n\n\t/**\n\t * This method reads the first byte from the given blob and maps that byte to the compression algorithm.\n\t * @param blob - The maybe compressed blob.\n\t */\n\tprivate static readAlgorithmFromBlob(blob: ArrayBufferLike): number {\n\t\treturn this.hasPrefix(blob)\n\t\t\t? // eslint-disable-next-line no-bitwise\n\t\t\t\tIsoBuffer.from(blob)[0] & 0x0f\n\t\t\t: SummaryCompressionAlgorithm.None;\n\t}\n\n\t/**\n\t * This method writes the given algorithm to the blob as the first byte.\n\t * @param blob - The blob to write the algorithm to.\n\t * @param algorithm - The algorithm to write.\n\t * @returns The blob with the algorithm as the first byte.\n\t */\n\tprivate static writeAlgorithmToBlob(\n\t\tblob: ArrayBufferLike,\n\t\talgorithm: number,\n\t): ArrayBufferLike | Buffer {\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tif ((firstByte & 0xf0) !== 0xb0) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t}\n\t\tassert(algorithm < 0x10, 0x6f5 /* Algorithm should be less than 0x10 */);\n\t\tconst blobView = new Uint8Array(blob);\n\t\tconst blobLength = blobView.length;\n\t\tconst newBlob = new Uint8Array(blobLength + 1);\n\t\t// eslint-disable-next-line no-bitwise\n\t\tconst prefix = 0xb0 | algorithm;\n\t\tnewBlob[0] = prefix;\n\t\tnewBlob.set(blobView, 1);\n\t\treturn IsoBuffer.from(newBlob);\n\t}\n\n\t/**\n\t * This method removes the algorithm markup prefix from the blob (1 byte)\n\t * @param blob - The blob to remove the prefix from.\n\t * @returns The blob without the prefix.\n\t */\n\tprivate static removePrefixFromBlobIfPresent(\n\t\tblob: ArrayBufferLike,\n\t): ArrayBufferLike | Buffer {\n\t\tconst blobView = new Uint8Array(blob);\n\t\treturn this.hasPrefix(blob) ? IsoBuffer.from(blobView.subarray(1)) : blob;\n\t}\n\n\t/**\n\t * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,\n\t * it is just returned as is. If the parameter is string, it is converted to Uint8Array using\n\t * TextEncoder.\n\t * @param input - The input to convert to Uint8Array.\n\t * @returns The Uint8Array representation of the input.\n\t */\n\tprivate static toBinaryArray(input: string | Uint8Array): Uint8Array {\n\t\treturn typeof input === \"string\" ? new TextEncoder().encode(input) : input;\n\t}\n\n\t/**\n\t * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config\n\t * containing the compression algorithm.\n\t * @param input - The summary object to encode.\n\t * @param config - The config containing the compression algorithm.\n\t * @returns The summary object with the encoded blob.\n\t */\n\tprivate static readonly blobEncoder = (\n\t\tinput: SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.encodeBlob(\n\t\t\t\toriginal,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method decodes the blob inside the given summary object of the SummaryType.Blob type.\n\t * @param input - The summary object to decode.\n\t * @returns The summary object with the decoded blob.\n\t */\n\tprivate static readonly blobDecoder = (input: SummaryObject): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: Uint8Array = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(original);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method encodes the given blob according to the given config.\n\t * @param file - The blob to encode.\n\t * @param config - The config to use for encoding.\n\t * @returns The encoded blob.\n\t */\n\tprivate static encodeBlob(\n\t\tfile: ArrayBufferLike,\n\t\tconfig: ICompressionStorageConfig,\n\t): ArrayBufferLike {\n\t\tlet maybeCompressed: ArrayBufferLike;\n\t\tlet algorithm = config.algorithm;\n\t\tif (new Uint8Array(file).length < config.minSizeToCompress) {\n\t\t\tmaybeCompressed = file;\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tmaybeCompressed = file;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\tconst compressed = compress(file as Uint8Array) as ArrayBufferLike;\n\t\t\tmaybeCompressed = compressed;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${config.algorithm}`);\n\t\t}\n\t\tmaybeCompressed = DocumentStorageServiceCompressionAdapter.writeAlgorithmToBlob(\n\t\t\tmaybeCompressed,\n\t\t\talgorithm,\n\t\t);\n\t\treturn maybeCompressed;\n\t}\n\n\t/**\n\t * This method decodes the given blob.\n\t * @param file - The blob to decode.\n\t * @returns The decoded blob.\n\t */\n\tprivate static decodeBlob(file: ArrayBufferLike): ArrayBufferLike {\n\t\tlet decompressed: ArrayBufferLike;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type\n\t\tlet originalBlob: any;\n\t\tlet algorithm: SummaryCompressionAlgorithm;\n\t\tif (this.hasPrefix(file)) {\n\t\t\talgorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);\n\t\t\toriginalBlob = this.removePrefixFromBlobIfPresent(file);\n\t\t} else {\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t\toriginalBlob = file;\n\t\t}\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tdecompressed = originalBlob;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment\n\t\t\tdecompressed = decompress(originalBlob) as ArrayBufferLike;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${algorithm}`);\n\t\t}\n\t\treturn decompressed;\n\t}\n\n\t/**\n\t * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,\n\t * it applies encoding/decoding on it according to the given isEncode flag.\n\t * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.\n\t * @param input - The summary object to traverse.\n\t * @param encoder - The encoder function to use.\n\t * @param decoder - The decoder function to use.\n\t * @param config - The config to use for encoding.\n\t * @param context - The summary context.\n\t * @returns The summary object with the encoded/decoded blob.\n\t */\n\tprivate static recursivelyReplace(\n\t\tisEncode: boolean,\n\t\tinput: SummaryObject,\n\t\tencoder: (input: SummaryObject, config: ICompressionStorageConfig) => SummaryObject,\n\t\tdecoder: (input: SummaryObject) => SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t\tcontext?: ISummaryContext,\n\t): SummaryObject {\n\t\tassert(typeof input === \"object\", 0x6f6 /* input must be a non-null object */);\n\t\tconst maybeReplaced = isEncode ? encoder(input, config) : decoder(input);\n\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst value: SummaryObject = input[key];\n\n\t\t\tif (Boolean(value) && typeof value === \"object\") {\n\t\t\t\tconst replaced = this.recursivelyReplace(\n\t\t\t\t\tisEncode,\n\t\t\t\t\tvalue,\n\t\t\t\t\tencoder,\n\t\t\t\t\tdecoder,\n\t\t\t\t\tconfig,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\t\t\t\t\tclone[key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (clone ?? input) as SummaryObject;\n\t}\n\n\t/**\n\t * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it returns the summary tree containing that blob.\n\t *\n\t * @param summary - The summary tree to traverse.\n\t * @returns The summary tree containing the metadata blob.\n\t */\n\tprivate static findMetadataHolderSummary(summary: ISummaryTree): ISummaryTree | undefined {\n\t\tassert(typeof summary === \"object\", 0x6f7 /* summary must be a non-null object */);\n\t\tfor (const [key, value] of Object.entries(summary.tree)) {\n\t\t\tif (Boolean(value) && value.type === SummaryType.Tree) {\n\t\t\t\tconst found = this.findMetadataHolderSummary(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Boolean(value) && key === metadataBlobName && value.type === SummaryType.Blob) {\n\t\t\t\treturn summary;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * This method obtains the summary tree containing the metadata blob. It returns the content\n\t * of the tree atribute.\n\t * @param summary - The summary tree to traverse.\n\t * @returns The content of the tree attribute of the summary tree containing the metadata blob.\n\t */\n\tprivate static getMetadataHolderTree(summary: ISummaryTree): {\n\t\t[path: string]: SummaryObject;\n\t} {\n\t\tconst metadataHolder = this.findMetadataHolderSummary(summary);\n\t\tassert(metadataHolder !== undefined, 0x6f8 /* metadataHolder must be a non-null object */);\n\t\tconst metadataHolderTree = metadataHolder.tree;\n\t\treturn metadataHolderTree;\n\t}\n\n\t/**\n\t * This method adds the compression markup blob to the nested summary tree containing the metadata blob.\n\t * @param summary - The top summary tree to put the compression markup blob into.\n\t */\n\tprivate static putCompressionMarkup(summary: ISummaryTree): void {\n\t\tconst metadataHolderTree =\n\t\t\tDocumentStorageServiceCompressionAdapter.getMetadataHolderTree(summary);\n\t\tmetadataHolderTree[blobHeadersBlobName] = {\n\t\t\ttype: 2,\n\t\t\tcontent: \"\",\n\t\t};\n\t}\n\n\t/**\n\t * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,\n\t * it returns true, otherwise false.\n\t * @param snapshot - The snapshot tree to traverse.\n\t * @returns True if the compression markup blob is found, otherwise false.\n\t */\n\tprivate static hasCompressionMarkup(snapshot: ISnapshotTree): boolean {\n\t\tassert(typeof snapshot === \"object\", 0x6f9 /* snapshot must be a non-null object */);\n\t\tfor (const key of Object.keys(snapshot.blobs)) {\n\t\t\tif (key === metadataBlobName) {\n\t\t\t\tconst value = snapshot.blobs[blobHeadersBlobName];\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of Object.keys(snapshot.trees)) {\n\t\t\tconst value = snapshot[key] as ISnapshotTree;\n\t\t\tif (value !== undefined) {\n\t\t\t\tconst found = this.hasCompressionMarkup(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This method performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to compress.\n\t * @param config - The compression config.\n\t * @returns The compressed summary tree.\n\t */\n\tpublic static compressSummary(\n\t\tsummary: ISummaryTree,\n\t\tconfig: ICompressionStorageConfig,\n\t): ISummaryTree {\n\t\tthis.putCompressionMarkup(summary);\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\ttrue,\n\t\t\tsummary,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\tconfig,\n\t\t) as ISummaryTree;\n\t\t//\tconsole.log(`Miso summary-blob Summary Upload: ${JSON.stringify(prep).length}`);\n\t\treturn prep;\n\t}\n\n\t/**\n\t * This method read blob from the storage and decompresses it if it is compressed.\n\t * @param id - The id of the blob to read.\n\t * @returns The decompressed blob.\n\t */\n\tpublic override async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\tconst originalBlob = await super.readBlob(id);\n\t\tif (this._isCompressionEnabled) {\n\t\t\tconst decompressedBlob =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);\n\t\t\t//\t\t\tconsole.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);\n\t\t\treturn decompressedBlob;\n\t\t} else {\n\t\t\treturn originalBlob;\n\t\t}\n\t}\n\n\t/**\n\t * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present\n\t * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain\n\t * algorithm byte prefix and store them.\n\t * @param version - The version of the snapshot tree to load.\n\t * @param scenarioName - The scenario name of the snapshot tree to load.\n\t * @returns The snapshot tree.\n\t */\n\tpublic override async getSnapshotTree(\n\t\tversion?: IVersion | undefined,\n\t\tscenarioName?: string | undefined,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t): Promise<ISnapshotTree | null> {\n\t\tconst snapshotTree = await super.getSnapshotTree(version, scenarioName);\n\t\tthis._isCompressionEnabled =\n\t\t\tsnapshotTree !== undefined &&\n\t\t\tsnapshotTree !== null &&\n\t\t\tDocumentStorageServiceCompressionAdapter.hasCompressionMarkup(snapshotTree);\n\t\treturn snapshotTree;\n\t}\n\n\t/**\n\t * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to upload.\n\t * @param context - The summary context.\n\t * @returns The ID of the uploaded summary.\n\t */\n\tpublic override async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.compressSummary(\n\t\t\tsummary,\n\t\t\tthis._config,\n\t\t);\n\t\treturn super.uploadSummaryWithContext(prep, context);\n\t}\n\n\t/**\n\t * This method downloads the summary from the storage and then applies decompression on the compressed blobs.\n\t * @param id - The ID of the summary to be downloaded\n\t * @returns The summary with decompressed blobs\n\t */\n\tpublic override async downloadSummary(id: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst summary = await super.downloadSummary(id);\n\t\treturn this._isCompressionEnabled\n\t\t\t? (DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\t\t\tfalse,\n\t\t\t\t\tsummary,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\t\t\tthis._config,\n\t\t\t\t) as ISummaryTree)\n\t\t\t: summary;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentStorageServiceSummaryBlobCompressionAdapter.js","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsE;AACtE,kEAA6D;AAC7D,2EA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(c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type Buffer, IsoBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype ISummaryBlob,\n\ttype ISummaryHandle,\n\ttype ISummaryTree,\n\ttype SummaryObject,\n\tSummaryType,\n} from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { compress, decompress } from \"lz4js\";\n\nimport { DocumentStorageServiceProxy } from \"../../../documentStorageServiceProxy.js\";\nimport {\n\tSummaryCompressionAlgorithm,\n\ttype ICompressionStorageConfig,\n} from \"../compressionTypes.js\";\n\n/**\n * @internal\n */\nexport const blobHeadersBlobName = \".metadata.blobHeaders\";\nconst metadataBlobName = \".metadata\";\n\n/**\n * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.\n * The identification of the compressed blobs is done by adding a compression markup blob to the summary.\n * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,\n * which is compressed also contain the compression algorithm enumerated value from the\n * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not\n * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .\n * In case, the markup blob is present, it is expected that the first byte of the markup blob\n * will contain the info about the compression. If the first byte is not present, it is assumed\n * that the compression is not enabled and no first prefix byte is present in the blobs.\n * @public\n */\nexport class DocumentStorageServiceCompressionAdapter extends DocumentStorageServiceProxy {\n\tprivate _isCompressionEnabled: boolean = false;\n\n\tconstructor(\n\t\tservice: IDocumentStorageService,\n\t\tprivate readonly _config: ICompressionStorageConfig,\n\t) {\n\t\tsuper(service);\n\t}\n\n\tpublic get service(): IDocumentStorageService {\n\t\treturn this.internalStorageService;\n\t}\n\n\t/**\n\t * This method returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t * @param blob - The blob to compress.\n\t * @returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t */\n\tprivate static hasPrefix(blob: ArrayBufferLike): boolean {\n\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn (firstByte & 0xf0) === 0xb0;\n\t}\n\n\t/**\n\t * This method reads the first byte from the given blob and maps that byte to the compression algorithm.\n\t * @param blob - The maybe compressed blob.\n\t */\n\tprivate static readAlgorithmFromBlob(blob: ArrayBufferLike): number {\n\t\treturn this.hasPrefix(blob)\n\t\t\t? // eslint-disable-next-line no-bitwise\n\t\t\t\tIsoBuffer.from(blob)[0] & 0x0f\n\t\t\t: SummaryCompressionAlgorithm.None;\n\t}\n\n\t/**\n\t * This method writes the given algorithm to the blob as the first byte.\n\t * @param blob - The blob to write the algorithm to.\n\t * @param algorithm - The algorithm to write.\n\t * @returns The blob with the algorithm as the first byte.\n\t */\n\tprivate static writeAlgorithmToBlob(\n\t\tblob: ArrayBufferLike,\n\t\talgorithm: number,\n\t): ArrayBufferLike | Buffer {\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tif ((firstByte & 0xf0) !== 0xb0) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t}\n\t\tassert(algorithm < 0x10, 0x6f5 /* Algorithm should be less than 0x10 */);\n\t\tconst blobView = new Uint8Array(blob);\n\t\tconst blobLength = blobView.length;\n\t\tconst newBlob = new Uint8Array(blobLength + 1);\n\t\t// eslint-disable-next-line no-bitwise\n\t\tconst prefix = 0xb0 | algorithm;\n\t\tnewBlob[0] = prefix;\n\t\tnewBlob.set(blobView, 1);\n\t\treturn IsoBuffer.from(newBlob);\n\t}\n\n\t/**\n\t * This method removes the algorithm markup prefix from the blob (1 byte)\n\t * @param blob - The blob to remove the prefix from.\n\t * @returns The blob without the prefix.\n\t */\n\tprivate static removePrefixFromBlobIfPresent(\n\t\tblob: ArrayBufferLike,\n\t): ArrayBufferLike | Buffer {\n\t\tconst blobView = new Uint8Array(blob);\n\t\treturn this.hasPrefix(blob) ? IsoBuffer.from(blobView.subarray(1)) : blob;\n\t}\n\n\t/**\n\t * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,\n\t * it is just returned as is. If the parameter is string, it is converted to Uint8Array using\n\t * TextEncoder.\n\t * @param input - The input to convert to Uint8Array.\n\t * @returns The Uint8Array representation of the input.\n\t */\n\tprivate static toBinaryArray(input: string | Uint8Array): Uint8Array {\n\t\treturn typeof input === \"string\" ? new TextEncoder().encode(input) : input;\n\t}\n\n\t/**\n\t * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config\n\t * containing the compression algorithm.\n\t * @param input - The summary object to encode.\n\t * @param config - The config containing the compression algorithm.\n\t * @returns The summary object with the encoded blob.\n\t */\n\tprivate static readonly blobEncoder = (\n\t\tinput: SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.encodeBlob(\n\t\t\t\toriginal,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method decodes the blob inside the given summary object of the SummaryType.Blob type.\n\t * @param input - The summary object to decode.\n\t * @returns The summary object with the decoded blob.\n\t */\n\tprivate static readonly blobDecoder = (input: SummaryObject): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: Uint8Array = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(original);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method encodes the given blob according to the given config.\n\t * @param file - The blob to encode.\n\t * @param config - The config to use for encoding.\n\t * @returns The encoded blob.\n\t */\n\tprivate static encodeBlob(\n\t\tfile: ArrayBufferLike,\n\t\tconfig: ICompressionStorageConfig,\n\t): ArrayBufferLike {\n\t\tlet maybeCompressed: ArrayBufferLike;\n\t\tlet algorithm = config.algorithm;\n\t\tif (new Uint8Array(file).length < config.minSizeToCompress) {\n\t\t\tmaybeCompressed = file;\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tmaybeCompressed = file;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\tconst compressed = compress(file as Uint8Array) as ArrayBufferLike;\n\t\t\tmaybeCompressed = compressed;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${config.algorithm}`);\n\t\t}\n\t\tmaybeCompressed = DocumentStorageServiceCompressionAdapter.writeAlgorithmToBlob(\n\t\t\tmaybeCompressed,\n\t\t\talgorithm,\n\t\t);\n\t\treturn maybeCompressed;\n\t}\n\n\t/**\n\t * This method decodes the given blob.\n\t * @param file - The blob to decode.\n\t * @returns The decoded blob.\n\t */\n\tprivate static decodeBlob(file: ArrayBufferLike): ArrayBufferLike {\n\t\tlet decompressed: ArrayBufferLike;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type\n\t\tlet originalBlob: any;\n\t\tlet algorithm: SummaryCompressionAlgorithm;\n\t\tif (this.hasPrefix(file)) {\n\t\t\talgorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);\n\t\t\toriginalBlob = this.removePrefixFromBlobIfPresent(file);\n\t\t} else {\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t\toriginalBlob = file;\n\t\t}\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tdecompressed = originalBlob;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tdecompressed = decompress(originalBlob) as ArrayBufferLike;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${algorithm}`);\n\t\t}\n\t\treturn decompressed;\n\t}\n\n\t/**\n\t * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,\n\t * it applies encoding/decoding on it according to the given isEncode flag.\n\t * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.\n\t * @param input - The summary object to traverse.\n\t * @param encoder - The encoder function to use.\n\t * @param decoder - The decoder function to use.\n\t * @param config - The config to use for encoding.\n\t * @param context - The summary context.\n\t * @returns The summary object with the encoded/decoded blob.\n\t */\n\tprivate static recursivelyReplace(\n\t\tisEncode: boolean,\n\t\tinput: SummaryObject,\n\t\tencoder: (input: SummaryObject, config: ICompressionStorageConfig) => SummaryObject,\n\t\tdecoder: (input: SummaryObject) => SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t\tcontext?: ISummaryContext,\n\t): SummaryObject {\n\t\tassert(typeof input === \"object\", 0x6f6 /* input must be a non-null object */);\n\t\tconst maybeReplaced = isEncode ? encoder(input, config) : decoder(input);\n\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst value: SummaryObject = input[key];\n\n\t\t\tif (Boolean(value) && typeof value === \"object\") {\n\t\t\t\tconst replaced = this.recursivelyReplace(\n\t\t\t\t\tisEncode,\n\t\t\t\t\tvalue,\n\t\t\t\t\tencoder,\n\t\t\t\t\tdecoder,\n\t\t\t\t\tconfig,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\t\t\t\t\tclone[key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (clone ?? input) as SummaryObject;\n\t}\n\n\t/**\n\t * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it returns the summary tree containing that blob.\n\t *\n\t * @param summary - The summary tree to traverse.\n\t * @returns The summary tree containing the metadata blob.\n\t */\n\tprivate static findMetadataHolderSummary(summary: ISummaryTree): ISummaryTree | undefined {\n\t\tassert(typeof summary === \"object\", 0x6f7 /* summary must be a non-null object */);\n\t\tfor (const [key, value] of Object.entries(summary.tree)) {\n\t\t\tif (Boolean(value) && value.type === SummaryType.Tree) {\n\t\t\t\tconst found = this.findMetadataHolderSummary(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Boolean(value) && key === metadataBlobName && value.type === SummaryType.Blob) {\n\t\t\t\treturn summary;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * This method obtains the summary tree containing the metadata blob. It returns the content\n\t * of the tree atribute.\n\t * @param summary - The summary tree to traverse.\n\t * @returns The content of the tree attribute of the summary tree containing the metadata blob.\n\t */\n\tprivate static getMetadataHolderTree(summary: ISummaryTree): {\n\t\t[path: string]: SummaryObject;\n\t} {\n\t\tconst metadataHolder = this.findMetadataHolderSummary(summary);\n\t\tassert(metadataHolder !== undefined, 0x6f8 /* metadataHolder must be a non-null object */);\n\t\tconst metadataHolderTree = metadataHolder.tree;\n\t\treturn metadataHolderTree;\n\t}\n\n\t/**\n\t * This method adds the compression markup blob to the nested summary tree containing the metadata blob.\n\t * @param summary - The top summary tree to put the compression markup blob into.\n\t */\n\tprivate static putCompressionMarkup(summary: ISummaryTree): void {\n\t\tconst metadataHolderTree =\n\t\t\tDocumentStorageServiceCompressionAdapter.getMetadataHolderTree(summary);\n\t\tmetadataHolderTree[blobHeadersBlobName] = {\n\t\t\ttype: 2,\n\t\t\tcontent: \"\",\n\t\t};\n\t}\n\n\t/**\n\t * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,\n\t * it returns true, otherwise false.\n\t * @param snapshot - The snapshot tree to traverse.\n\t * @returns True if the compression markup blob is found, otherwise false.\n\t */\n\tprivate static hasCompressionMarkup(snapshot: ISnapshotTree): boolean {\n\t\tassert(typeof snapshot === \"object\", 0x6f9 /* snapshot must be a non-null object */);\n\t\tfor (const key of Object.keys(snapshot.blobs)) {\n\t\t\tif (key === metadataBlobName) {\n\t\t\t\tconst value = snapshot.blobs[blobHeadersBlobName];\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of Object.keys(snapshot.trees)) {\n\t\t\tconst value = snapshot[key] as ISnapshotTree;\n\t\t\tif (value !== undefined) {\n\t\t\t\tconst found = this.hasCompressionMarkup(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This method performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to compress.\n\t * @param config - The compression config.\n\t * @returns The compressed summary tree.\n\t */\n\tpublic static compressSummary(\n\t\tsummary: ISummaryTree,\n\t\tconfig: ICompressionStorageConfig,\n\t): ISummaryTree {\n\t\tthis.putCompressionMarkup(summary);\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\ttrue,\n\t\t\tsummary,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\tconfig,\n\t\t) as ISummaryTree;\n\t\t//\tconsole.log(`Miso summary-blob Summary Upload: ${JSON.stringify(prep).length}`);\n\t\treturn prep;\n\t}\n\n\t/**\n\t * This method read blob from the storage and decompresses it if it is compressed.\n\t * @param id - The id of the blob to read.\n\t * @returns The decompressed blob.\n\t */\n\tpublic override async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\tconst originalBlob = await super.readBlob(id);\n\t\tif (this._isCompressionEnabled) {\n\t\t\tconst decompressedBlob =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);\n\t\t\t//\t\t\tconsole.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);\n\t\t\treturn decompressedBlob;\n\t\t} else {\n\t\t\treturn originalBlob;\n\t\t}\n\t}\n\n\t/**\n\t * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present\n\t * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain\n\t * algorithm byte prefix and store them.\n\t * @param version - The version of the snapshot tree to load.\n\t * @param scenarioName - The scenario name of the snapshot tree to load.\n\t * @returns The snapshot tree.\n\t */\n\tpublic override async getSnapshotTree(\n\t\tversion?: IVersion | undefined,\n\t\tscenarioName?: string | undefined,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t): Promise<ISnapshotTree | null> {\n\t\tconst snapshotTree = await super.getSnapshotTree(version, scenarioName);\n\t\tthis._isCompressionEnabled =\n\t\t\tsnapshotTree !== undefined &&\n\t\t\tsnapshotTree !== null &&\n\t\t\tDocumentStorageServiceCompressionAdapter.hasCompressionMarkup(snapshotTree);\n\t\treturn snapshotTree;\n\t}\n\n\t/**\n\t * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to upload.\n\t * @param context - The summary context.\n\t * @returns The ID of the uploaded summary.\n\t */\n\tpublic override async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.compressSummary(\n\t\t\tsummary,\n\t\t\tthis._config,\n\t\t);\n\t\treturn super.uploadSummaryWithContext(prep, context);\n\t}\n\n\t/**\n\t * This method downloads the summary from the storage and then applies decompression on the compressed blobs.\n\t * @param id - The ID of the summary to be downloaded\n\t * @returns The summary with decompressed blobs\n\t */\n\tpublic override async downloadSummary(id: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst summary = await super.downloadSummary(id);\n\t\treturn this._isCompressionEnabled\n\t\t\t? (DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\t\t\tfalse,\n\t\t\t\t\tsummary,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\t\t\tthis._config,\n\t\t\t\t) as ISummaryTree)\n\t\t\t: summary;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefinedAdapters.d.ts","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAE3F,OAAO,EAGN,KAAK,yBAAyB,EAC9B,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,sBAAsB,EAAE,uBAAuB,EAC/C,MAAM,CAAC,EAAE,yBAAyB,GAAG,OAAO,GAC1C,uBAAuB,CAgBzB;
|
|
1
|
+
{"version":3,"file":"predefinedAdapters.d.ts","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAE3F,OAAO,EAGN,KAAK,yBAAyB,EAC9B,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,sBAAsB,EAAE,uBAAuB,EAC/C,MAAM,CAAC,EAAE,yBAAyB,GAAG,OAAO,GAC1C,uBAAuB,CAgBzB;AAsBD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,yBAAyB,CAQxF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefinedAdapters.js","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAG7D,qDAIgC;AAEhC;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACtC,sBAA+C,EAC/C,MAA4C;IAE5C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QAC9C,OAAO,sBAAsB,CAAC;IAC/B,CAAC;SAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CACrC,mDAAwC,EACxC,sBAAsB,CACtB,CAAC;IACH,CAAC;SAAM,CAAC;QACP,IAAA,iBAAM,EAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC5E,OAAO,+BAA+B,CACrC,mDAAwC,EACxC,sBAAsB,EACtB,MAAM,CACN,CAAC;IACH,CAAC;AACF,CAAC;AAnBD,0DAmBC;AAED;;;;;GAKG;AACH,SAAS,+BAA+B,CACvC,
|
|
1
|
+
{"version":3,"file":"predefinedAdapters.js","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAG7D,qDAIgC;AAEhC;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACtC,sBAA+C,EAC/C,MAA4C;IAE5C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QAC9C,OAAO,sBAAsB,CAAC;IAC/B,CAAC;SAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CACrC,mDAAwC,EACxC,sBAAsB,CACtB,CAAC;IACH,CAAC;SAAM,CAAC;QACP,IAAA,iBAAM,EAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC5E,OAAO,+BAA+B,CACrC,mDAAwC,EACxC,sBAAsB,EACtB,MAAM,CACN,CAAC;IACH,CAAC;AACF,CAAC;AAnBD,0DAmBC;AAED;;;;;GAKG;AACH,SAAS,+BAA+B,CACvC,WAG4B,EAC5B,sBAA+C,EAC/C,SAAoC,0CAA+B;IAEnE,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,WAAW,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,MAAe;IAClD,OAAO,CACN,MAAM,KAAK,SAAS;QACpB,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,CAAE,MAA6C,CAAC,SAAS,KAAK,SAAS;YACrE,MAA6C,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAChF,CAAC;AACH,CAAC;AARD,kDAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IDocumentServiceFactory } from \"@fluidframework/driver-definitions/internal\";\n\nimport {\n\tDefaultCompressionStorageConfig,\n\tDocumentServiceFactoryCompressionAdapter,\n\ttype ICompressionStorageConfig,\n} from \"./compression/index.js\";\n\n/**\n * This method optionally applies compression to the given document service factory. The compression\n * must be enabled by setting the config to true or by passing a compression config object.\n * @param documentServiceFactory - The document service factory to apply compression to.\n * @param config - The compression configuration.\n * @returns The document service factory possibly with compression applied.\n * @internal\n */\nexport function applyStorageCompression(\n\tdocumentServiceFactory: IDocumentServiceFactory,\n\tconfig?: ICompressionStorageConfig | boolean,\n): IDocumentServiceFactory {\n\tif (config === undefined || config === false) {\n\t\treturn documentServiceFactory;\n\t} else if (config === true) {\n\t\treturn applyStorageCompressionInternal(\n\t\t\tDocumentServiceFactoryCompressionAdapter,\n\t\t\tdocumentServiceFactory,\n\t\t);\n\t} else {\n\t\tassert(isCompressionConfig(config), 0x6f4 /* Invalid compression config */);\n\t\treturn applyStorageCompressionInternal(\n\t\t\tDocumentServiceFactoryCompressionAdapter,\n\t\t\tdocumentServiceFactory,\n\t\t\tconfig,\n\t\t);\n\t}\n}\n\n/**\n * This method applies compression to the given document service factory.\n * @param documentServiceFactory - The document service factory to apply compression to.\n * @param config - The compression configuration.\n * @returns The document service factory with compression applied.\n */\nfunction applyStorageCompressionInternal(\n\tconstructor: new (\n\t\tdocumentServiceFactory: IDocumentServiceFactory,\n\t\tconfig: ICompressionStorageConfig,\n\t) => IDocumentServiceFactory,\n\tdocumentServiceFactory: IDocumentServiceFactory,\n\tconfig: ICompressionStorageConfig = DefaultCompressionStorageConfig,\n): IDocumentServiceFactory {\n\tif (config.algorithm === undefined) {\n\t\treturn documentServiceFactory;\n\t}\n\treturn new constructor(documentServiceFactory, config);\n}\n\n/**\n * This method checks whether given objects contains\n * a properties expected for the interface ICompressionStorageConfig.\n */\nexport function isCompressionConfig(config: unknown): config is ICompressionStorageConfig {\n\treturn (\n\t\tconfig !== undefined &&\n\t\ttypeof config === \"object\" &&\n\t\tconfig !== null &&\n\t\t((config as Partial<ICompressionStorageConfig>).algorithm !== undefined ||\n\t\t\t(config as Partial<ICompressionStorageConfig>).minSizeToCompress !== undefined)\n\t);\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/driver-utils";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.91.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/driver-utils";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.91.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,
|
|
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,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"2.91.0\";\n"]}
|
package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js
CHANGED
|
@@ -146,7 +146,7 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
|
|
|
146
146
|
decompressed = originalBlob;
|
|
147
147
|
}
|
|
148
148
|
else if (algorithm === SummaryCompressionAlgorithm.LZ4) {
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
150
150
|
decompressed = decompress(originalBlob);
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentStorageServiceSummaryBlobCompressionAdapter.js","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAKN,WAAW,GACX,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EACN,2BAA2B,GAE3B,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAC3D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC;;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C;QACrC,MAAM,WAAW,GAAiB,KAAK,CAAC;QACxC,MAAM,QAAQ,GAAoB,wCAAwC,CAAC,aAAa,CACvF,WAAW,CAAC,OAAO,CACnB,CAAC;QACF,MAAM,SAAS,GAAoB,wCAAwC,CAAC,UAAU,CACrF,QAAQ,EACR,MAAM,CACN,CAAC;QACF,MAAM,cAAc,GAAG;YACtB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClC,CAAC;QACF,OAAO,cAAc,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,AArBkC,CAqBjC;AAEF;;;;GAIG;AACqB,oDAAW,GAAG,CAAC,KAAoB,EAAiB,EAAE;IAC7E,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QACrC,MAAM,WAAW,GAAiB,KAAK,CAAC;QACxC,MAAM,QAAQ,GAAe,wCAAwC,CAAC,aAAa,CAClF,WAAW,CAAC,OAAO,CACnB,CAAC;QACF,MAAM,SAAS,GACd,wCAAwC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/D,MAAM,cAAc,GAAG;YACtB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClC,CAAC;QACF,OAAO,cAAc,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,AAhBkC,CAgBjC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type Buffer, IsoBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype ISummaryBlob,\n\ttype ISummaryHandle,\n\ttype ISummaryTree,\n\ttype SummaryObject,\n\tSummaryType,\n} from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { compress, decompress } from \"lz4js\";\n\nimport { DocumentStorageServiceProxy } from \"../../../documentStorageServiceProxy.js\";\nimport {\n\tSummaryCompressionAlgorithm,\n\ttype ICompressionStorageConfig,\n} from \"../compressionTypes.js\";\n\n/**\n * @internal\n */\nexport const blobHeadersBlobName = \".metadata.blobHeaders\";\nconst metadataBlobName = \".metadata\";\n\n/**\n * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.\n * The identification of the compressed blobs is done by adding a compression markup blob to the summary.\n * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,\n * which is compressed also contain the compression algorithm enumerated value from the\n * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not\n * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .\n * In case, the markup blob is present, it is expected that the first byte of the markup blob\n * will contain the info about the compression. If the first byte is not present, it is assumed\n * that the compression is not enabled and no first prefix byte is present in the blobs.\n * @public\n */\nexport class DocumentStorageServiceCompressionAdapter extends DocumentStorageServiceProxy {\n\tprivate _isCompressionEnabled: boolean = false;\n\n\tconstructor(\n\t\tservice: IDocumentStorageService,\n\t\tprivate readonly _config: ICompressionStorageConfig,\n\t) {\n\t\tsuper(service);\n\t}\n\n\tpublic get service(): IDocumentStorageService {\n\t\treturn this.internalStorageService;\n\t}\n\n\t/**\n\t * This method returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t * @param blob - The blob to compress.\n\t * @returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t */\n\tprivate static hasPrefix(blob: ArrayBufferLike): boolean {\n\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn (firstByte & 0xf0) === 0xb0;\n\t}\n\n\t/**\n\t * This method reads the first byte from the given blob and maps that byte to the compression algorithm.\n\t * @param blob - The maybe compressed blob.\n\t */\n\tprivate static readAlgorithmFromBlob(blob: ArrayBufferLike): number {\n\t\treturn this.hasPrefix(blob)\n\t\t\t? // eslint-disable-next-line no-bitwise\n\t\t\t\tIsoBuffer.from(blob)[0] & 0x0f\n\t\t\t: SummaryCompressionAlgorithm.None;\n\t}\n\n\t/**\n\t * This method writes the given algorithm to the blob as the first byte.\n\t * @param blob - The blob to write the algorithm to.\n\t * @param algorithm - The algorithm to write.\n\t * @returns The blob with the algorithm as the first byte.\n\t */\n\tprivate static writeAlgorithmToBlob(\n\t\tblob: ArrayBufferLike,\n\t\talgorithm: number,\n\t): ArrayBufferLike | Buffer {\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tif ((firstByte & 0xf0) !== 0xb0) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t}\n\t\tassert(algorithm < 0x10, 0x6f5 /* Algorithm should be less than 0x10 */);\n\t\tconst blobView = new Uint8Array(blob);\n\t\tconst blobLength = blobView.length;\n\t\tconst newBlob = new Uint8Array(blobLength + 1);\n\t\t// eslint-disable-next-line no-bitwise\n\t\tconst prefix = 0xb0 | algorithm;\n\t\tnewBlob[0] = prefix;\n\t\tnewBlob.set(blobView, 1);\n\t\treturn IsoBuffer.from(newBlob);\n\t}\n\n\t/**\n\t * This method removes the algorithm markup prefix from the blob (1 byte)\n\t * @param blob - The blob to remove the prefix from.\n\t * @returns The blob without the prefix.\n\t */\n\tprivate static removePrefixFromBlobIfPresent(\n\t\tblob: ArrayBufferLike,\n\t): ArrayBufferLike | Buffer {\n\t\tconst blobView = new Uint8Array(blob);\n\t\treturn this.hasPrefix(blob) ? IsoBuffer.from(blobView.subarray(1)) : blob;\n\t}\n\n\t/**\n\t * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,\n\t * it is just returned as is. If the parameter is string, it is converted to Uint8Array using\n\t * TextEncoder.\n\t * @param input - The input to convert to Uint8Array.\n\t * @returns The Uint8Array representation of the input.\n\t */\n\tprivate static toBinaryArray(input: string | Uint8Array): Uint8Array {\n\t\treturn typeof input === \"string\" ? new TextEncoder().encode(input) : input;\n\t}\n\n\t/**\n\t * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config\n\t * containing the compression algorithm.\n\t * @param input - The summary object to encode.\n\t * @param config - The config containing the compression algorithm.\n\t * @returns The summary object with the encoded blob.\n\t */\n\tprivate static readonly blobEncoder = (\n\t\tinput: SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.encodeBlob(\n\t\t\t\toriginal,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method decodes the blob inside the given summary object of the SummaryType.Blob type.\n\t * @param input - The summary object to decode.\n\t * @returns The summary object with the decoded blob.\n\t */\n\tprivate static readonly blobDecoder = (input: SummaryObject): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: Uint8Array = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(original);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method encodes the given blob according to the given config.\n\t * @param file - The blob to encode.\n\t * @param config - The config to use for encoding.\n\t * @returns The encoded blob.\n\t */\n\tprivate static encodeBlob(\n\t\tfile: ArrayBufferLike,\n\t\tconfig: ICompressionStorageConfig,\n\t): ArrayBufferLike {\n\t\tlet maybeCompressed: ArrayBufferLike;\n\t\tlet algorithm = config.algorithm;\n\t\tif (new Uint8Array(file).length < config.minSizeToCompress) {\n\t\t\tmaybeCompressed = file;\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tmaybeCompressed = file;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\tconst compressed = compress(file as Uint8Array) as ArrayBufferLike;\n\t\t\tmaybeCompressed = compressed;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${config.algorithm}`);\n\t\t}\n\t\tmaybeCompressed = DocumentStorageServiceCompressionAdapter.writeAlgorithmToBlob(\n\t\t\tmaybeCompressed,\n\t\t\talgorithm,\n\t\t);\n\t\treturn maybeCompressed;\n\t}\n\n\t/**\n\t * This method decodes the given blob.\n\t * @param file - The blob to decode.\n\t * @returns The decoded blob.\n\t */\n\tprivate static decodeBlob(file: ArrayBufferLike): ArrayBufferLike {\n\t\tlet decompressed: ArrayBufferLike;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type\n\t\tlet originalBlob: any;\n\t\tlet algorithm: SummaryCompressionAlgorithm;\n\t\tif (this.hasPrefix(file)) {\n\t\t\talgorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);\n\t\t\toriginalBlob = this.removePrefixFromBlobIfPresent(file);\n\t\t} else {\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t\toriginalBlob = file;\n\t\t}\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tdecompressed = originalBlob;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment\n\t\t\tdecompressed = decompress(originalBlob) as ArrayBufferLike;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${algorithm}`);\n\t\t}\n\t\treturn decompressed;\n\t}\n\n\t/**\n\t * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,\n\t * it applies encoding/decoding on it according to the given isEncode flag.\n\t * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.\n\t * @param input - The summary object to traverse.\n\t * @param encoder - The encoder function to use.\n\t * @param decoder - The decoder function to use.\n\t * @param config - The config to use for encoding.\n\t * @param context - The summary context.\n\t * @returns The summary object with the encoded/decoded blob.\n\t */\n\tprivate static recursivelyReplace(\n\t\tisEncode: boolean,\n\t\tinput: SummaryObject,\n\t\tencoder: (input: SummaryObject, config: ICompressionStorageConfig) => SummaryObject,\n\t\tdecoder: (input: SummaryObject) => SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t\tcontext?: ISummaryContext,\n\t): SummaryObject {\n\t\tassert(typeof input === \"object\", 0x6f6 /* input must be a non-null object */);\n\t\tconst maybeReplaced = isEncode ? encoder(input, config) : decoder(input);\n\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst value: SummaryObject = input[key];\n\n\t\t\tif (Boolean(value) && typeof value === \"object\") {\n\t\t\t\tconst replaced = this.recursivelyReplace(\n\t\t\t\t\tisEncode,\n\t\t\t\t\tvalue,\n\t\t\t\t\tencoder,\n\t\t\t\t\tdecoder,\n\t\t\t\t\tconfig,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\t\t\t\t\tclone[key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (clone ?? input) as SummaryObject;\n\t}\n\n\t/**\n\t * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it returns the summary tree containing that blob.\n\t *\n\t * @param summary - The summary tree to traverse.\n\t * @returns The summary tree containing the metadata blob.\n\t */\n\tprivate static findMetadataHolderSummary(summary: ISummaryTree): ISummaryTree | undefined {\n\t\tassert(typeof summary === \"object\", 0x6f7 /* summary must be a non-null object */);\n\t\tfor (const [key, value] of Object.entries(summary.tree)) {\n\t\t\tif (Boolean(value) && value.type === SummaryType.Tree) {\n\t\t\t\tconst found = this.findMetadataHolderSummary(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Boolean(value) && key === metadataBlobName && value.type === SummaryType.Blob) {\n\t\t\t\treturn summary;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * This method obtains the summary tree containing the metadata blob. It returns the content\n\t * of the tree atribute.\n\t * @param summary - The summary tree to traverse.\n\t * @returns The content of the tree attribute of the summary tree containing the metadata blob.\n\t */\n\tprivate static getMetadataHolderTree(summary: ISummaryTree): {\n\t\t[path: string]: SummaryObject;\n\t} {\n\t\tconst metadataHolder = this.findMetadataHolderSummary(summary);\n\t\tassert(metadataHolder !== undefined, 0x6f8 /* metadataHolder must be a non-null object */);\n\t\tconst metadataHolderTree = metadataHolder.tree;\n\t\treturn metadataHolderTree;\n\t}\n\n\t/**\n\t * This method adds the compression markup blob to the nested summary tree containing the metadata blob.\n\t * @param summary - The top summary tree to put the compression markup blob into.\n\t */\n\tprivate static putCompressionMarkup(summary: ISummaryTree): void {\n\t\tconst metadataHolderTree =\n\t\t\tDocumentStorageServiceCompressionAdapter.getMetadataHolderTree(summary);\n\t\tmetadataHolderTree[blobHeadersBlobName] = {\n\t\t\ttype: 2,\n\t\t\tcontent: \"\",\n\t\t};\n\t}\n\n\t/**\n\t * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,\n\t * it returns true, otherwise false.\n\t * @param snapshot - The snapshot tree to traverse.\n\t * @returns True if the compression markup blob is found, otherwise false.\n\t */\n\tprivate static hasCompressionMarkup(snapshot: ISnapshotTree): boolean {\n\t\tassert(typeof snapshot === \"object\", 0x6f9 /* snapshot must be a non-null object */);\n\t\tfor (const key of Object.keys(snapshot.blobs)) {\n\t\t\tif (key === metadataBlobName) {\n\t\t\t\tconst value = snapshot.blobs[blobHeadersBlobName];\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of Object.keys(snapshot.trees)) {\n\t\t\tconst value = snapshot[key] as ISnapshotTree;\n\t\t\tif (value !== undefined) {\n\t\t\t\tconst found = this.hasCompressionMarkup(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This method performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to compress.\n\t * @param config - The compression config.\n\t * @returns The compressed summary tree.\n\t */\n\tpublic static compressSummary(\n\t\tsummary: ISummaryTree,\n\t\tconfig: ICompressionStorageConfig,\n\t): ISummaryTree {\n\t\tthis.putCompressionMarkup(summary);\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\ttrue,\n\t\t\tsummary,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\tconfig,\n\t\t) as ISummaryTree;\n\t\t//\tconsole.log(`Miso summary-blob Summary Upload: ${JSON.stringify(prep).length}`);\n\t\treturn prep;\n\t}\n\n\t/**\n\t * This method read blob from the storage and decompresses it if it is compressed.\n\t * @param id - The id of the blob to read.\n\t * @returns The decompressed blob.\n\t */\n\tpublic override async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\tconst originalBlob = await super.readBlob(id);\n\t\tif (this._isCompressionEnabled) {\n\t\t\tconst decompressedBlob =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);\n\t\t\t//\t\t\tconsole.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);\n\t\t\treturn decompressedBlob;\n\t\t} else {\n\t\t\treturn originalBlob;\n\t\t}\n\t}\n\n\t/**\n\t * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present\n\t * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain\n\t * algorithm byte prefix and store them.\n\t * @param version - The version of the snapshot tree to load.\n\t * @param scenarioName - The scenario name of the snapshot tree to load.\n\t * @returns The snapshot tree.\n\t */\n\tpublic override async getSnapshotTree(\n\t\tversion?: IVersion | undefined,\n\t\tscenarioName?: string | undefined,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t): Promise<ISnapshotTree | null> {\n\t\tconst snapshotTree = await super.getSnapshotTree(version, scenarioName);\n\t\tthis._isCompressionEnabled =\n\t\t\tsnapshotTree !== undefined &&\n\t\t\tsnapshotTree !== null &&\n\t\t\tDocumentStorageServiceCompressionAdapter.hasCompressionMarkup(snapshotTree);\n\t\treturn snapshotTree;\n\t}\n\n\t/**\n\t * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to upload.\n\t * @param context - The summary context.\n\t * @returns The ID of the uploaded summary.\n\t */\n\tpublic override async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.compressSummary(\n\t\t\tsummary,\n\t\t\tthis._config,\n\t\t);\n\t\treturn super.uploadSummaryWithContext(prep, context);\n\t}\n\n\t/**\n\t * This method downloads the summary from the storage and then applies decompression on the compressed blobs.\n\t * @param id - The ID of the summary to be downloaded\n\t * @returns The summary with decompressed blobs\n\t */\n\tpublic override async downloadSummary(id: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst summary = await super.downloadSummary(id);\n\t\treturn this._isCompressionEnabled\n\t\t\t? (DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\t\t\tfalse,\n\t\t\t\t\tsummary,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\t\t\tthis._config,\n\t\t\t\t) as ISummaryTree)\n\t\t\t: summary;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentStorageServiceSummaryBlobCompressionAdapter.js","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAKN,WAAW,GACX,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EACN,2BAA2B,GAE3B,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAC3D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,wCAAyC,SAAQ,2BAA2B;IAGxF,YACC,OAAgC,EACf,OAAkC;QAEnD,KAAK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C,OAAO,CACnB,CAAC;QACF,MAAM,SAAS,GAAoB,wCAAwC,CAAC,UAAU,CACrF,QAAQ,EACR,MAAM,CACN,CAAC;QACF,MAAM,cAAc,GAAG;YACtB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClC,CAAC;QACF,OAAO,cAAc,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,AArBkC,CAqBjC;AAEF;;;;GAIG;AACqB,oDAAW,GAAG,CAAC,KAAoB,EAAiB,EAAE;IAC7E,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QACrC,MAAM,WAAW,GAAiB,KAAK,CAAC;QACxC,MAAM,QAAQ,GAAe,wCAAwC,CAAC,aAAa,CAClF,WAAW,CAAC,OAAO,CACnB,CAAC;QACF,MAAM,SAAS,GACd,wCAAwC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/D,MAAM,cAAc,GAAG;YACtB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClC,CAAC;QACF,OAAO,cAAc,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,AAhBkC,CAgBjC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type Buffer, IsoBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype ISummaryBlob,\n\ttype ISummaryHandle,\n\ttype ISummaryTree,\n\ttype SummaryObject,\n\tSummaryType,\n} from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { compress, decompress } from \"lz4js\";\n\nimport { DocumentStorageServiceProxy } from \"../../../documentStorageServiceProxy.js\";\nimport {\n\tSummaryCompressionAlgorithm,\n\ttype ICompressionStorageConfig,\n} from \"../compressionTypes.js\";\n\n/**\n * @internal\n */\nexport const blobHeadersBlobName = \".metadata.blobHeaders\";\nconst metadataBlobName = \".metadata\";\n\n/**\n * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.\n * The identification of the compressed blobs is done by adding a compression markup blob to the summary.\n * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,\n * which is compressed also contain the compression algorithm enumerated value from the\n * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not\n * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .\n * In case, the markup blob is present, it is expected that the first byte of the markup blob\n * will contain the info about the compression. If the first byte is not present, it is assumed\n * that the compression is not enabled and no first prefix byte is present in the blobs.\n * @public\n */\nexport class DocumentStorageServiceCompressionAdapter extends DocumentStorageServiceProxy {\n\tprivate _isCompressionEnabled: boolean = false;\n\n\tconstructor(\n\t\tservice: IDocumentStorageService,\n\t\tprivate readonly _config: ICompressionStorageConfig,\n\t) {\n\t\tsuper(service);\n\t}\n\n\tpublic get service(): IDocumentStorageService {\n\t\treturn this.internalStorageService;\n\t}\n\n\t/**\n\t * This method returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t * @param blob - The blob to compress.\n\t * @returns `true` if there is a compression markup byte in the blob, otherwise `false`.\n\t */\n\tprivate static hasPrefix(blob: ArrayBufferLike): boolean {\n\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn (firstByte & 0xf0) === 0xb0;\n\t}\n\n\t/**\n\t * This method reads the first byte from the given blob and maps that byte to the compression algorithm.\n\t * @param blob - The maybe compressed blob.\n\t */\n\tprivate static readAlgorithmFromBlob(blob: ArrayBufferLike): number {\n\t\treturn this.hasPrefix(blob)\n\t\t\t? // eslint-disable-next-line no-bitwise\n\t\t\t\tIsoBuffer.from(blob)[0] & 0x0f\n\t\t\t: SummaryCompressionAlgorithm.None;\n\t}\n\n\t/**\n\t * This method writes the given algorithm to the blob as the first byte.\n\t * @param blob - The blob to write the algorithm to.\n\t * @param algorithm - The algorithm to write.\n\t * @returns The blob with the algorithm as the first byte.\n\t */\n\tprivate static writeAlgorithmToBlob(\n\t\tblob: ArrayBufferLike,\n\t\talgorithm: number,\n\t): ArrayBufferLike | Buffer {\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tconst firstByte = IsoBuffer.from(blob)[0];\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tif ((firstByte & 0xf0) !== 0xb0) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t}\n\t\tassert(algorithm < 0x10, 0x6f5 /* Algorithm should be less than 0x10 */);\n\t\tconst blobView = new Uint8Array(blob);\n\t\tconst blobLength = blobView.length;\n\t\tconst newBlob = new Uint8Array(blobLength + 1);\n\t\t// eslint-disable-next-line no-bitwise\n\t\tconst prefix = 0xb0 | algorithm;\n\t\tnewBlob[0] = prefix;\n\t\tnewBlob.set(blobView, 1);\n\t\treturn IsoBuffer.from(newBlob);\n\t}\n\n\t/**\n\t * This method removes the algorithm markup prefix from the blob (1 byte)\n\t * @param blob - The blob to remove the prefix from.\n\t * @returns The blob without the prefix.\n\t */\n\tprivate static removePrefixFromBlobIfPresent(\n\t\tblob: ArrayBufferLike,\n\t): ArrayBufferLike | Buffer {\n\t\tconst blobView = new Uint8Array(blob);\n\t\treturn this.hasPrefix(blob) ? IsoBuffer.from(blobView.subarray(1)) : blob;\n\t}\n\n\t/**\n\t * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,\n\t * it is just returned as is. If the parameter is string, it is converted to Uint8Array using\n\t * TextEncoder.\n\t * @param input - The input to convert to Uint8Array.\n\t * @returns The Uint8Array representation of the input.\n\t */\n\tprivate static toBinaryArray(input: string | Uint8Array): Uint8Array {\n\t\treturn typeof input === \"string\" ? new TextEncoder().encode(input) : input;\n\t}\n\n\t/**\n\t * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config\n\t * containing the compression algorithm.\n\t * @param input - The summary object to encode.\n\t * @param config - The config containing the compression algorithm.\n\t * @returns The summary object with the encoded blob.\n\t */\n\tprivate static readonly blobEncoder = (\n\t\tinput: SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike = DocumentStorageServiceCompressionAdapter.encodeBlob(\n\t\t\t\toriginal,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method decodes the blob inside the given summary object of the SummaryType.Blob type.\n\t * @param input - The summary object to decode.\n\t * @returns The summary object with the decoded blob.\n\t */\n\tprivate static readonly blobDecoder = (input: SummaryObject): SummaryObject => {\n\t\tif (input.type === SummaryType.Blob) {\n\t\t\tconst summaryBlob: ISummaryBlob = input;\n\t\t\tconst original: Uint8Array = DocumentStorageServiceCompressionAdapter.toBinaryArray(\n\t\t\t\tsummaryBlob.content,\n\t\t\t);\n\t\t\tconst processed: ArrayBufferLike =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(original);\n\t\t\tconst newSummaryBlob = {\n\t\t\t\ttype: SummaryType.Blob,\n\t\t\t\tcontent: IsoBuffer.from(processed),\n\t\t\t};\n\t\t\treturn newSummaryBlob;\n\t\t} else {\n\t\t\treturn input;\n\t\t}\n\t};\n\n\t/**\n\t * This method encodes the given blob according to the given config.\n\t * @param file - The blob to encode.\n\t * @param config - The config to use for encoding.\n\t * @returns The encoded blob.\n\t */\n\tprivate static encodeBlob(\n\t\tfile: ArrayBufferLike,\n\t\tconfig: ICompressionStorageConfig,\n\t): ArrayBufferLike {\n\t\tlet maybeCompressed: ArrayBufferLike;\n\t\tlet algorithm = config.algorithm;\n\t\tif (new Uint8Array(file).length < config.minSizeToCompress) {\n\t\t\tmaybeCompressed = file;\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\tmaybeCompressed = file;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\tconst compressed = compress(file as Uint8Array) as ArrayBufferLike;\n\t\t\tmaybeCompressed = compressed;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${config.algorithm}`);\n\t\t}\n\t\tmaybeCompressed = DocumentStorageServiceCompressionAdapter.writeAlgorithmToBlob(\n\t\t\tmaybeCompressed,\n\t\t\talgorithm,\n\t\t);\n\t\treturn maybeCompressed;\n\t}\n\n\t/**\n\t * This method decodes the given blob.\n\t * @param file - The blob to decode.\n\t * @returns The decoded blob.\n\t */\n\tprivate static decodeBlob(file: ArrayBufferLike): ArrayBufferLike {\n\t\tlet decompressed: ArrayBufferLike;\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type\n\t\tlet originalBlob: any;\n\t\tlet algorithm: SummaryCompressionAlgorithm;\n\t\tif (this.hasPrefix(file)) {\n\t\t\talgorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);\n\t\t\toriginalBlob = this.removePrefixFromBlobIfPresent(file);\n\t\t} else {\n\t\t\talgorithm = SummaryCompressionAlgorithm.None;\n\t\t\toriginalBlob = file;\n\t\t}\n\t\tif (algorithm === SummaryCompressionAlgorithm.None) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tdecompressed = originalBlob;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tdecompressed = decompress(originalBlob) as ArrayBufferLike;\n\t\t} else {\n\t\t\tthrow new Error(`Unknown Algorithm ${algorithm}`);\n\t\t}\n\t\treturn decompressed;\n\t}\n\n\t/**\n\t * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,\n\t * it applies encoding/decoding on it according to the given isEncode flag.\n\t * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.\n\t * @param input - The summary object to traverse.\n\t * @param encoder - The encoder function to use.\n\t * @param decoder - The decoder function to use.\n\t * @param config - The config to use for encoding.\n\t * @param context - The summary context.\n\t * @returns The summary object with the encoded/decoded blob.\n\t */\n\tprivate static recursivelyReplace(\n\t\tisEncode: boolean,\n\t\tinput: SummaryObject,\n\t\tencoder: (input: SummaryObject, config: ICompressionStorageConfig) => SummaryObject,\n\t\tdecoder: (input: SummaryObject) => SummaryObject,\n\t\tconfig: ICompressionStorageConfig,\n\t\tcontext?: ISummaryContext,\n\t): SummaryObject {\n\t\tassert(typeof input === \"object\", 0x6f6 /* input must be a non-null object */);\n\t\tconst maybeReplaced = isEncode ? encoder(input, config) : decoder(input);\n\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst value: SummaryObject = input[key];\n\n\t\t\tif (Boolean(value) && typeof value === \"object\") {\n\t\t\t\tconst replaced = this.recursivelyReplace(\n\t\t\t\t\tisEncode,\n\t\t\t\t\tvalue,\n\t\t\t\t\tencoder,\n\t\t\t\t\tdecoder,\n\t\t\t\t\tconfig,\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\t\t\t\t\tclone[key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (clone ?? input) as SummaryObject;\n\t}\n\n\t/**\n\t * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it returns the summary tree containing that blob.\n\t *\n\t * @param summary - The summary tree to traverse.\n\t * @returns The summary tree containing the metadata blob.\n\t */\n\tprivate static findMetadataHolderSummary(summary: ISummaryTree): ISummaryTree | undefined {\n\t\tassert(typeof summary === \"object\", 0x6f7 /* summary must be a non-null object */);\n\t\tfor (const [key, value] of Object.entries(summary.tree)) {\n\t\t\tif (Boolean(value) && value.type === SummaryType.Tree) {\n\t\t\t\tconst found = this.findMetadataHolderSummary(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Boolean(value) && key === metadataBlobName && value.type === SummaryType.Blob) {\n\t\t\t\treturn summary;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * This method obtains the summary tree containing the metadata blob. It returns the content\n\t * of the tree atribute.\n\t * @param summary - The summary tree to traverse.\n\t * @returns The content of the tree attribute of the summary tree containing the metadata blob.\n\t */\n\tprivate static getMetadataHolderTree(summary: ISummaryTree): {\n\t\t[path: string]: SummaryObject;\n\t} {\n\t\tconst metadataHolder = this.findMetadataHolderSummary(summary);\n\t\tassert(metadataHolder !== undefined, 0x6f8 /* metadataHolder must be a non-null object */);\n\t\tconst metadataHolderTree = metadataHolder.tree;\n\t\treturn metadataHolderTree;\n\t}\n\n\t/**\n\t * This method adds the compression markup blob to the nested summary tree containing the metadata blob.\n\t * @param summary - The top summary tree to put the compression markup blob into.\n\t */\n\tprivate static putCompressionMarkup(summary: ISummaryTree): void {\n\t\tconst metadataHolderTree =\n\t\t\tDocumentStorageServiceCompressionAdapter.getMetadataHolderTree(summary);\n\t\tmetadataHolderTree[blobHeadersBlobName] = {\n\t\t\ttype: 2,\n\t\t\tcontent: \"\",\n\t\t};\n\t}\n\n\t/**\n\t * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',\n\t * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,\n\t * it returns true, otherwise false.\n\t * @param snapshot - The snapshot tree to traverse.\n\t * @returns True if the compression markup blob is found, otherwise false.\n\t */\n\tprivate static hasCompressionMarkup(snapshot: ISnapshotTree): boolean {\n\t\tassert(typeof snapshot === \"object\", 0x6f9 /* snapshot must be a non-null object */);\n\t\tfor (const key of Object.keys(snapshot.blobs)) {\n\t\t\tif (key === metadataBlobName) {\n\t\t\t\tconst value = snapshot.blobs[blobHeadersBlobName];\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of Object.keys(snapshot.trees)) {\n\t\t\tconst value = snapshot[key] as ISnapshotTree;\n\t\t\tif (value !== undefined) {\n\t\t\t\tconst found = this.hasCompressionMarkup(value);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This method performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to compress.\n\t * @param config - The compression config.\n\t * @returns The compressed summary tree.\n\t */\n\tpublic static compressSummary(\n\t\tsummary: ISummaryTree,\n\t\tconfig: ICompressionStorageConfig,\n\t): ISummaryTree {\n\t\tthis.putCompressionMarkup(summary);\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\ttrue,\n\t\t\tsummary,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\tconfig,\n\t\t) as ISummaryTree;\n\t\t//\tconsole.log(`Miso summary-blob Summary Upload: ${JSON.stringify(prep).length}`);\n\t\treturn prep;\n\t}\n\n\t/**\n\t * This method read blob from the storage and decompresses it if it is compressed.\n\t * @param id - The id of the blob to read.\n\t * @returns The decompressed blob.\n\t */\n\tpublic override async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\tconst originalBlob = await super.readBlob(id);\n\t\tif (this._isCompressionEnabled) {\n\t\t\tconst decompressedBlob =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);\n\t\t\t//\t\t\tconsole.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);\n\t\t\treturn decompressedBlob;\n\t\t} else {\n\t\t\treturn originalBlob;\n\t\t}\n\t}\n\n\t/**\n\t * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present\n\t * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain\n\t * algorithm byte prefix and store them.\n\t * @param version - The version of the snapshot tree to load.\n\t * @param scenarioName - The scenario name of the snapshot tree to load.\n\t * @returns The snapshot tree.\n\t */\n\tpublic override async getSnapshotTree(\n\t\tversion?: IVersion | undefined,\n\t\tscenarioName?: string | undefined,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t): Promise<ISnapshotTree | null> {\n\t\tconst snapshotTree = await super.getSnapshotTree(version, scenarioName);\n\t\tthis._isCompressionEnabled =\n\t\t\tsnapshotTree !== undefined &&\n\t\t\tsnapshotTree !== null &&\n\t\t\tDocumentStorageServiceCompressionAdapter.hasCompressionMarkup(snapshotTree);\n\t\treturn snapshotTree;\n\t}\n\n\t/**\n\t * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.\n\t * @param summary - The summary tree to upload.\n\t * @param context - The summary context.\n\t * @returns The ID of the uploaded summary.\n\t */\n\tpublic override async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst prep = DocumentStorageServiceCompressionAdapter.compressSummary(\n\t\t\tsummary,\n\t\t\tthis._config,\n\t\t);\n\t\treturn super.uploadSummaryWithContext(prep, context);\n\t}\n\n\t/**\n\t * This method downloads the summary from the storage and then applies decompression on the compressed blobs.\n\t * @param id - The ID of the summary to be downloaded\n\t * @returns The summary with decompressed blobs\n\t */\n\tpublic override async downloadSummary(id: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst summary = await super.downloadSummary(id);\n\t\treturn this._isCompressionEnabled\n\t\t\t? (DocumentStorageServiceCompressionAdapter.recursivelyReplace(\n\t\t\t\t\tfalse,\n\t\t\t\t\tsummary,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobEncoder,\n\t\t\t\t\tDocumentStorageServiceCompressionAdapter.blobDecoder,\n\t\t\t\t\tthis._config,\n\t\t\t\t) as ISummaryTree)\n\t\t\t: summary;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefinedAdapters.d.ts","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAE3F,OAAO,EAGN,KAAK,yBAAyB,EAC9B,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,sBAAsB,EAAE,uBAAuB,EAC/C,MAAM,CAAC,EAAE,yBAAyB,GAAG,OAAO,GAC1C,uBAAuB,CAgBzB;
|
|
1
|
+
{"version":3,"file":"predefinedAdapters.d.ts","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAE3F,OAAO,EAGN,KAAK,yBAAyB,EAC9B,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,sBAAsB,EAAE,uBAAuB,EAC/C,MAAM,CAAC,EAAE,yBAAyB,GAAG,OAAO,GAC1C,uBAAuB,CAgBzB;AAsBD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,yBAAyB,CAQxF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefinedAdapters.js","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAG7D,OAAO,EACN,+BAA+B,EAC/B,wCAAwC,GAExC,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACtC,sBAA+C,EAC/C,MAA4C;IAE5C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QAC9C,OAAO,sBAAsB,CAAC;IAC/B,CAAC;SAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CACrC,wCAAwC,EACxC,sBAAsB,CACtB,CAAC;IACH,CAAC;SAAM,CAAC;QACP,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC5E,OAAO,+BAA+B,CACrC,wCAAwC,EACxC,sBAAsB,EACtB,MAAM,CACN,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,SAAS,+BAA+B,CACvC,
|
|
1
|
+
{"version":3,"file":"predefinedAdapters.js","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAG7D,OAAO,EACN,+BAA+B,EAC/B,wCAAwC,GAExC,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACtC,sBAA+C,EAC/C,MAA4C;IAE5C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QAC9C,OAAO,sBAAsB,CAAC;IAC/B,CAAC;SAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CACrC,wCAAwC,EACxC,sBAAsB,CACtB,CAAC;IACH,CAAC;SAAM,CAAC;QACP,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC5E,OAAO,+BAA+B,CACrC,wCAAwC,EACxC,sBAAsB,EACtB,MAAM,CACN,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,SAAS,+BAA+B,CACvC,WAG4B,EAC5B,sBAA+C,EAC/C,SAAoC,+BAA+B;IAEnE,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,WAAW,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAe;IAClD,OAAO,CACN,MAAM,KAAK,SAAS;QACpB,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,CAAE,MAA6C,CAAC,SAAS,KAAK,SAAS;YACrE,MAA6C,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAChF,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IDocumentServiceFactory } from \"@fluidframework/driver-definitions/internal\";\n\nimport {\n\tDefaultCompressionStorageConfig,\n\tDocumentServiceFactoryCompressionAdapter,\n\ttype ICompressionStorageConfig,\n} from \"./compression/index.js\";\n\n/**\n * This method optionally applies compression to the given document service factory. The compression\n * must be enabled by setting the config to true or by passing a compression config object.\n * @param documentServiceFactory - The document service factory to apply compression to.\n * @param config - The compression configuration.\n * @returns The document service factory possibly with compression applied.\n * @internal\n */\nexport function applyStorageCompression(\n\tdocumentServiceFactory: IDocumentServiceFactory,\n\tconfig?: ICompressionStorageConfig | boolean,\n): IDocumentServiceFactory {\n\tif (config === undefined || config === false) {\n\t\treturn documentServiceFactory;\n\t} else if (config === true) {\n\t\treturn applyStorageCompressionInternal(\n\t\t\tDocumentServiceFactoryCompressionAdapter,\n\t\t\tdocumentServiceFactory,\n\t\t);\n\t} else {\n\t\tassert(isCompressionConfig(config), 0x6f4 /* Invalid compression config */);\n\t\treturn applyStorageCompressionInternal(\n\t\t\tDocumentServiceFactoryCompressionAdapter,\n\t\t\tdocumentServiceFactory,\n\t\t\tconfig,\n\t\t);\n\t}\n}\n\n/**\n * This method applies compression to the given document service factory.\n * @param documentServiceFactory - The document service factory to apply compression to.\n * @param config - The compression configuration.\n * @returns The document service factory with compression applied.\n */\nfunction applyStorageCompressionInternal(\n\tconstructor: new (\n\t\tdocumentServiceFactory: IDocumentServiceFactory,\n\t\tconfig: ICompressionStorageConfig,\n\t) => IDocumentServiceFactory,\n\tdocumentServiceFactory: IDocumentServiceFactory,\n\tconfig: ICompressionStorageConfig = DefaultCompressionStorageConfig,\n): IDocumentServiceFactory {\n\tif (config.algorithm === undefined) {\n\t\treturn documentServiceFactory;\n\t}\n\treturn new constructor(documentServiceFactory, config);\n}\n\n/**\n * This method checks whether given objects contains\n * a properties expected for the interface ICompressionStorageConfig.\n */\nexport function isCompressionConfig(config: unknown): config is ICompressionStorageConfig {\n\treturn (\n\t\tconfig !== undefined &&\n\t\ttypeof config === \"object\" &&\n\t\tconfig !== null &&\n\t\t((config as Partial<ICompressionStorageConfig>).algorithm !== undefined ||\n\t\t\t(config as Partial<ICompressionStorageConfig>).minSizeToCompress !== undefined)\n\t);\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/driver-utils";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.91.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -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,
|
|
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,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"2.91.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/driver-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.91.0",
|
|
4
4
|
"description": "Collection of utility functions for Fluid drivers",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,23 +69,23 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluid-internal/client-utils": "2.
|
|
73
|
-
"@fluidframework/core-interfaces": "2.
|
|
74
|
-
"@fluidframework/core-utils": "2.
|
|
75
|
-
"@fluidframework/driver-definitions": "2.
|
|
76
|
-
"@fluidframework/telemetry-utils": "2.
|
|
72
|
+
"@fluid-internal/client-utils": "~2.91.0",
|
|
73
|
+
"@fluidframework/core-interfaces": "~2.91.0",
|
|
74
|
+
"@fluidframework/core-utils": "~2.91.0",
|
|
75
|
+
"@fluidframework/driver-definitions": "~2.91.0",
|
|
76
|
+
"@fluidframework/telemetry-utils": "~2.91.0",
|
|
77
77
|
"lz4js": "^0.2.0",
|
|
78
78
|
"uuid": "^11.1.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
82
|
-
"@biomejs/biome": "~
|
|
83
|
-
"@fluid-internal/mocha-test-setup": "2.
|
|
82
|
+
"@biomejs/biome": "~2.4.5",
|
|
83
|
+
"@fluid-internal/mocha-test-setup": "~2.91.0",
|
|
84
84
|
"@fluid-tools/build-cli": "^0.63.0",
|
|
85
85
|
"@fluidframework/build-common": "^2.0.3",
|
|
86
86
|
"@fluidframework/build-tools": "^0.63.0",
|
|
87
|
-
"@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.
|
|
88
|
-
"@fluidframework/eslint-config-fluid": "2.
|
|
87
|
+
"@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.83.0",
|
|
88
|
+
"@fluidframework/eslint-config-fluid": "~2.91.0",
|
|
89
89
|
"@microsoft/api-extractor": "7.52.11",
|
|
90
90
|
"@types/lz4js": "^0.2.0",
|
|
91
91
|
"@types/mocha": "^10.0.10",
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
"cross-env": "^10.1.0",
|
|
98
98
|
"eslint": "~9.39.1",
|
|
99
99
|
"jiti": "^2.6.1",
|
|
100
|
-
"mocha": "^
|
|
100
|
+
"mocha": "^11.7.5",
|
|
101
101
|
"mocha-multi-reporters": "^1.5.1",
|
|
102
|
-
"rimraf": "^6.1.
|
|
102
|
+
"rimraf": "^6.1.3",
|
|
103
103
|
"sinon": "^18.0.1",
|
|
104
104
|
"typescript": "~5.4.5"
|
|
105
105
|
},
|
package/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts
CHANGED
|
@@ -235,7 +235,7 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
|
|
|
235
235
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
236
236
|
decompressed = originalBlob;
|
|
237
237
|
} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
238
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
239
239
|
decompressed = decompress(originalBlob) as ArrayBufferLike;
|
|
240
240
|
} else {
|
|
241
241
|
throw new Error(`Unknown Algorithm ${algorithm}`);
|
|
@@ -49,9 +49,7 @@ export function applyStorageCompression(
|
|
|
49
49
|
*/
|
|
50
50
|
function applyStorageCompressionInternal(
|
|
51
51
|
constructor: new (
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
53
52
|
documentServiceFactory: IDocumentServiceFactory,
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
55
53
|
config: ICompressionStorageConfig,
|
|
56
54
|
) => IDocumentServiceFactory,
|
|
57
55
|
documentServiceFactory: IDocumentServiceFactory,
|
package/src/packageVersion.ts
CHANGED