@fluidframework/driver-utils 2.0.0-internal.5.1.1 → 2.0.0-internal.5.3.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.
Files changed (138) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/adapters/compression/compressionTypes.d.ts +17 -0
  3. package/dist/adapters/compression/compressionTypes.d.ts.map +1 -0
  4. package/dist/adapters/compression/compressionTypes.js +17 -0
  5. package/dist/adapters/compression/compressionTypes.js.map +1 -0
  6. package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts +13 -0
  7. package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -0
  8. package/dist/adapters/compression/documentServiceCompressionAdapter.js +23 -0
  9. package/dist/adapters/compression/documentServiceCompressionAdapter.js.map +1 -0
  10. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +16 -0
  11. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -0
  12. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js +36 -0
  13. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -0
  14. package/dist/adapters/compression/index.d.ts +8 -0
  15. package/dist/adapters/compression/index.d.ts.map +1 -0
  16. package/dist/adapters/compression/index.js +15 -0
  17. package/dist/adapters/compression/index.js.map +1 -0
  18. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +161 -0
  19. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -0
  20. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +365 -0
  21. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -0
  22. package/dist/adapters/compression/summaryblob/index.d.ts +6 -0
  23. package/dist/adapters/compression/summaryblob/index.d.ts.map +1 -0
  24. package/dist/adapters/compression/summaryblob/index.js +11 -0
  25. package/dist/adapters/compression/summaryblob/index.js.map +1 -0
  26. package/dist/adapters/index.d.ts +7 -0
  27. package/dist/adapters/index.d.ts.map +1 -0
  28. package/dist/adapters/index.js +14 -0
  29. package/dist/adapters/index.js.map +1 -0
  30. package/dist/adapters/predefinedAdapters.d.ts +20 -0
  31. package/dist/adapters/predefinedAdapters.d.ts.map +1 -0
  32. package/dist/adapters/predefinedAdapters.js +51 -0
  33. package/dist/adapters/predefinedAdapters.js.map +1 -0
  34. package/dist/documentServiceFactoryProxy.d.ts +19 -0
  35. package/dist/documentServiceFactoryProxy.d.ts.map +1 -0
  36. package/dist/documentServiceFactoryProxy.js +27 -0
  37. package/dist/documentServiceFactoryProxy.js.map +1 -0
  38. package/dist/documentServiceProxy.d.ts +21 -0
  39. package/dist/documentServiceProxy.d.ts.map +1 -0
  40. package/dist/documentServiceProxy.js +36 -0
  41. package/dist/documentServiceProxy.js.map +1 -0
  42. package/dist/documentStorageServiceProxy.d.ts.map +1 -1
  43. package/dist/documentStorageServiceProxy.js +1 -0
  44. package/dist/documentStorageServiceProxy.js.map +1 -1
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +4 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/network.d.ts +1 -1
  50. package/dist/network.d.ts.map +1 -1
  51. package/dist/network.js.map +1 -1
  52. package/dist/networkUtils.d.ts +1 -1
  53. package/dist/networkUtils.d.ts.map +1 -1
  54. package/dist/networkUtils.js.map +1 -1
  55. package/dist/packageVersion.d.ts +1 -1
  56. package/dist/packageVersion.js +1 -1
  57. package/dist/packageVersion.js.map +1 -1
  58. package/dist/parallelRequests.d.ts +1 -1
  59. package/dist/parallelRequests.d.ts.map +1 -1
  60. package/dist/parallelRequests.js +4 -3
  61. package/dist/parallelRequests.js.map +1 -1
  62. package/lib/adapters/compression/compressionTypes.d.ts +17 -0
  63. package/lib/adapters/compression/compressionTypes.d.ts.map +1 -0
  64. package/lib/adapters/compression/compressionTypes.js +14 -0
  65. package/lib/adapters/compression/compressionTypes.js.map +1 -0
  66. package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts +13 -0
  67. package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -0
  68. package/lib/adapters/compression/documentServiceCompressionAdapter.js +19 -0
  69. package/lib/adapters/compression/documentServiceCompressionAdapter.js.map +1 -0
  70. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +16 -0
  71. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -0
  72. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js +32 -0
  73. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -0
  74. package/lib/adapters/compression/index.d.ts +8 -0
  75. package/lib/adapters/compression/index.d.ts.map +1 -0
  76. package/lib/adapters/compression/index.js +8 -0
  77. package/lib/adapters/compression/index.js.map +1 -0
  78. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +161 -0
  79. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -0
  80. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +361 -0
  81. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -0
  82. package/lib/adapters/compression/summaryblob/index.d.ts +6 -0
  83. package/lib/adapters/compression/summaryblob/index.d.ts.map +1 -0
  84. package/lib/adapters/compression/summaryblob/index.js +6 -0
  85. package/lib/adapters/compression/summaryblob/index.js.map +1 -0
  86. package/lib/adapters/index.d.ts +7 -0
  87. package/lib/adapters/index.d.ts.map +1 -0
  88. package/lib/adapters/index.js +7 -0
  89. package/lib/adapters/index.js.map +1 -0
  90. package/lib/adapters/predefinedAdapters.d.ts +20 -0
  91. package/lib/adapters/predefinedAdapters.d.ts.map +1 -0
  92. package/lib/adapters/predefinedAdapters.js +46 -0
  93. package/lib/adapters/predefinedAdapters.js.map +1 -0
  94. package/lib/documentServiceFactoryProxy.d.ts +19 -0
  95. package/lib/documentServiceFactoryProxy.d.ts.map +1 -0
  96. package/lib/documentServiceFactoryProxy.js +23 -0
  97. package/lib/documentServiceFactoryProxy.js.map +1 -0
  98. package/lib/documentServiceProxy.d.ts +21 -0
  99. package/lib/documentServiceProxy.d.ts.map +1 -0
  100. package/lib/documentServiceProxy.js +32 -0
  101. package/lib/documentServiceProxy.js.map +1 -0
  102. package/lib/documentStorageServiceProxy.d.ts.map +1 -1
  103. package/lib/documentStorageServiceProxy.js +1 -0
  104. package/lib/documentStorageServiceProxy.js.map +1 -1
  105. package/lib/index.d.ts +1 -0
  106. package/lib/index.d.ts.map +1 -1
  107. package/lib/index.js +1 -0
  108. package/lib/index.js.map +1 -1
  109. package/lib/network.d.ts +1 -1
  110. package/lib/network.d.ts.map +1 -1
  111. package/lib/network.js.map +1 -1
  112. package/lib/networkUtils.d.ts +1 -1
  113. package/lib/networkUtils.d.ts.map +1 -1
  114. package/lib/networkUtils.js.map +1 -1
  115. package/lib/packageVersion.d.ts +1 -1
  116. package/lib/packageVersion.js +1 -1
  117. package/lib/packageVersion.js.map +1 -1
  118. package/lib/parallelRequests.d.ts +1 -1
  119. package/lib/parallelRequests.d.ts.map +1 -1
  120. package/lib/parallelRequests.js +4 -3
  121. package/lib/parallelRequests.js.map +1 -1
  122. package/package.json +11 -15
  123. package/src/adapters/compression/compressionTypes.ts +19 -0
  124. package/src/adapters/compression/documentServiceCompressionAdapter.ts +25 -0
  125. package/src/adapters/compression/documentServiceFactoryCompressionAdapter.ts +62 -0
  126. package/src/adapters/compression/index.ts +12 -0
  127. package/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts +446 -0
  128. package/src/adapters/compression/summaryblob/index.ts +9 -0
  129. package/src/adapters/index.ts +13 -0
  130. package/src/adapters/predefinedAdapters.ts +71 -0
  131. package/src/documentServiceFactoryProxy.ts +47 -0
  132. package/src/documentServiceProxy.ts +46 -0
  133. package/src/documentStorageServiceProxy.ts +1 -0
  134. package/src/index.ts +5 -0
  135. package/src/network.ts +1 -1
  136. package/src/networkUtils.ts +1 -1
  137. package/src/packageVersion.ts +1 -1
  138. package/src/parallelRequests.ts +5 -4
@@ -0,0 +1,365 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DocumentStorageServiceCompressionAdapter = exports.blobHeadersBlobName = void 0;
8
+ const common_utils_1 = require("@fluidframework/common-utils");
9
+ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
10
+ const lz4js_1 = require("lz4js");
11
+ const documentStorageServiceProxy_1 = require("../../../documentStorageServiceProxy");
12
+ const __1 = require("../");
13
+ exports.blobHeadersBlobName = ".metadata.blobHeaders";
14
+ const metadataBlobName = ".metadata";
15
+ /**
16
+ * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.
17
+ * The identification of the compressed blobs is done by adding a compression markup blob to the summary.
18
+ * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,
19
+ * which is compressed also contain the compression algorithm enumerated value from the
20
+ * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not
21
+ * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .
22
+ * In case, the markup blob is present, it is expected that the first byte of the markup blob
23
+ * will contain the info about the compression. If the first byte is not present, it is assumed
24
+ * that the compression is not enabled and no first prefix byte is present in the blobs.
25
+ */
26
+ class DocumentStorageServiceCompressionAdapter extends documentStorageServiceProxy_1.DocumentStorageServiceProxy {
27
+ constructor(service, _config) {
28
+ super(service);
29
+ this._config = _config;
30
+ this._isCompressionEnabled = false;
31
+ }
32
+ get service() {
33
+ return this.internalStorageService;
34
+ }
35
+ /**
36
+ * This method returns true if there is a compression markup byte in the blob, otherwise false.
37
+ * @param blob - The blob to compress.
38
+ * @returns - True if there is a compression markup byte in the blob, otherwise false.
39
+ */
40
+ static hasPrefix(blob) {
41
+ const firstByte = common_utils_1.IsoBuffer.from(blob)[0];
42
+ // eslint-disable-next-line no-bitwise
43
+ return (firstByte & 0xf0) === 0xb0;
44
+ }
45
+ /**
46
+ * This method reads the first byte from the given blob and maps that byte to the compression algorithm.
47
+ * @param blob - The maybe compressed blob.
48
+ */
49
+ static readAlgorithmFromBlob(blob) {
50
+ return !this.hasPrefix(blob)
51
+ ? __1.SummaryCompressionAlgorithm.None
52
+ : // eslint-disable-next-line no-bitwise
53
+ common_utils_1.IsoBuffer.from(blob)[0] & 0x0f;
54
+ }
55
+ /**
56
+ * This method writes the given algorithm to the blob as the first byte.
57
+ * @param blob - The blob to write the algorithm to.
58
+ * @param algorithm - The algorithm to write.
59
+ * @returns - The blob with the algorithm as the first byte.
60
+ */
61
+ static writeAlgorithmToBlob(blob, algorithm) {
62
+ if (algorithm === __1.SummaryCompressionAlgorithm.None) {
63
+ const firstByte = common_utils_1.IsoBuffer.from(blob)[0];
64
+ // eslint-disable-next-line no-bitwise
65
+ if ((firstByte & 0xf0) !== 0xb0) {
66
+ return blob;
67
+ }
68
+ }
69
+ (0, common_utils_1.assert)(algorithm < 0x10, 0x6f5 /* Algorithm should be less than 0x10 */);
70
+ const blobView = new Uint8Array(blob);
71
+ const blobLength = blobView.length;
72
+ const newBlob = new Uint8Array(blobLength + 1);
73
+ // eslint-disable-next-line no-bitwise
74
+ const prefix = 0xb0 | algorithm;
75
+ newBlob[0] = prefix;
76
+ newBlob.set(blobView, 1);
77
+ return common_utils_1.IsoBuffer.from(newBlob);
78
+ }
79
+ /**
80
+ * This method removes the algorithm markup prefix from the blob (1 byte)
81
+ * @param blob - The blob to remove the prefix from.
82
+ * @returns - The blob without the prefix.
83
+ */
84
+ static removePrefixFromBlobIfPresent(blob) {
85
+ const blobView = new Uint8Array(blob);
86
+ return this.hasPrefix(blob) ? common_utils_1.IsoBuffer.from(blobView.subarray(1)) : blob;
87
+ }
88
+ /**
89
+ * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,
90
+ * it is just returned as is. If the parameter is string, it is converted to Uint8Array using
91
+ * TextEncoder.
92
+ * @param input - The input to convert to Uint8Array.
93
+ * @returns - The Uint8Array representation of the input.
94
+ */
95
+ static toBinaryArray(input) {
96
+ return typeof input === "string" ? new TextEncoder().encode(input) : input;
97
+ }
98
+ /**
99
+ * This method encodes the given blob according to the given config.
100
+ * @param file - The blob to encode.
101
+ * @param config - The config to use for encoding.
102
+ * @returns - The encoded blob.
103
+ */
104
+ static encodeBlob(file, config) {
105
+ let maybeCompressed;
106
+ let algorithm = config.algorithm;
107
+ if (new Uint8Array(file).length < config.minSizeToCompress) {
108
+ maybeCompressed = file;
109
+ algorithm = __1.SummaryCompressionAlgorithm.None;
110
+ }
111
+ else if (algorithm === __1.SummaryCompressionAlgorithm.None) {
112
+ maybeCompressed = file;
113
+ }
114
+ else if (algorithm === __1.SummaryCompressionAlgorithm.LZ4) {
115
+ const compressed = (0, lz4js_1.compress)(file);
116
+ maybeCompressed = compressed;
117
+ }
118
+ else {
119
+ throw new Error(`Unknown Algorithm ${config.algorithm}`);
120
+ }
121
+ maybeCompressed = DocumentStorageServiceCompressionAdapter.writeAlgorithmToBlob(maybeCompressed, algorithm);
122
+ return maybeCompressed;
123
+ }
124
+ /**
125
+ * This method decodes the given blob.
126
+ * @param file - The blob to decode.
127
+ * @returns - The decoded blob.
128
+ */
129
+ static decodeBlob(file) {
130
+ let decompressed;
131
+ let originalBlob;
132
+ let algorithm;
133
+ if (this.hasPrefix(file)) {
134
+ algorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);
135
+ originalBlob = this.removePrefixFromBlobIfPresent(file);
136
+ }
137
+ else {
138
+ algorithm = __1.SummaryCompressionAlgorithm.None;
139
+ originalBlob = file;
140
+ }
141
+ if (algorithm === __1.SummaryCompressionAlgorithm.None) {
142
+ decompressed = originalBlob;
143
+ }
144
+ else if (algorithm === __1.SummaryCompressionAlgorithm.LZ4) {
145
+ decompressed = (0, lz4js_1.decompress)(originalBlob);
146
+ }
147
+ else {
148
+ throw new Error(`Unknown Algorithm ${algorithm}`);
149
+ }
150
+ return decompressed;
151
+ }
152
+ /**
153
+ * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,
154
+ * it applies encoding/decoding on it according to the given isEncode flag.
155
+ * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.
156
+ * @param input - The summary object to traverse.
157
+ * @param encoder - The encoder function to use.
158
+ * @param decoder - The decoder function to use.
159
+ * @param config - The config to use for encoding.
160
+ * @param context - The summary context.
161
+ * @returns - The summary object with the encoded/decoded blob.
162
+ */
163
+ static recursivelyReplace(isEncode, input, encoder, decoder, config, context) {
164
+ (0, common_utils_1.assert)(typeof input === "object", 0x6f6 /* input must be a non-null object */);
165
+ const maybeReplaced = isEncode ? encoder(input, config) : decoder(input);
166
+ if (maybeReplaced !== input) {
167
+ return maybeReplaced;
168
+ }
169
+ let clone;
170
+ for (const key of Object.keys(input)) {
171
+ const value = input[key];
172
+ if (Boolean(value) && typeof value === "object") {
173
+ const replaced = this.recursivelyReplace(isEncode, value, encoder, decoder, config, context);
174
+ if (replaced !== value) {
175
+ clone = clone !== null && clone !== void 0 ? clone : (Array.isArray(input) ? [...input] : Object.assign({}, input));
176
+ clone[key] = replaced;
177
+ }
178
+ }
179
+ }
180
+ return (clone !== null && clone !== void 0 ? clone : input);
181
+ }
182
+ /**
183
+ * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',
184
+ * it returns the summary tree containing that blob.
185
+ *
186
+ * @param summary - The summary tree to traverse.
187
+ * @returns - The summary tree containing the metadata blob.
188
+ */
189
+ static findMetadataHolderSummary(summary) {
190
+ (0, common_utils_1.assert)(typeof summary === "object", 0x6f7 /* summary must be a non-null object */);
191
+ for (const key of Object.keys(summary.tree)) {
192
+ const value = summary.tree[key];
193
+ if (Boolean(value) && value.type === protocol_definitions_1.SummaryType.Tree) {
194
+ const found = this.findMetadataHolderSummary(value);
195
+ if (found) {
196
+ return found;
197
+ }
198
+ }
199
+ if (Boolean(value) && key === metadataBlobName && value.type === protocol_definitions_1.SummaryType.Blob) {
200
+ return summary;
201
+ }
202
+ }
203
+ return undefined;
204
+ }
205
+ /**
206
+ * This method obtains the summary tree containing the metadata blob. It returns the content
207
+ * of the tree atribute.
208
+ * @param summary - The summary tree to traverse.
209
+ * @returns - The content of the tree attribute of the summary tree containing the metadata blob.
210
+ */
211
+ static getMetadataHolderTree(summary) {
212
+ const metadataHolder = this.findMetadataHolderSummary(summary);
213
+ (0, common_utils_1.assert)(metadataHolder !== undefined, 0x6f8 /* metadataHolder must be a non-null object */);
214
+ const metadataHolderTree = metadataHolder.tree;
215
+ return metadataHolderTree;
216
+ }
217
+ /**
218
+ * This method adds the compression markup blob to the nested summary tree containing the metadata blob.
219
+ * @param summary - The top summary tree to put the compression markup blob into.
220
+ */
221
+ static putCompressionMarkup(summary) {
222
+ const metadataHolderTree = DocumentStorageServiceCompressionAdapter.getMetadataHolderTree(summary);
223
+ metadataHolderTree[exports.blobHeadersBlobName] = {
224
+ type: 2,
225
+ content: "",
226
+ };
227
+ }
228
+ /**
229
+ * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',
230
+ * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,
231
+ * it returns true, otherwise false.
232
+ * @param snapshot - The snapshot tree to traverse.
233
+ * @returns - True if the compression markup blob is found, otherwise false.
234
+ */
235
+ static hasCompressionMarkup(snapshot) {
236
+ (0, common_utils_1.assert)(typeof snapshot === "object", 0x6f9 /* snapshot must be a non-null object */);
237
+ for (const key of Object.keys(snapshot.blobs)) {
238
+ if (key === metadataBlobName) {
239
+ const value = snapshot.blobs[exports.blobHeadersBlobName];
240
+ if (value !== undefined) {
241
+ return true;
242
+ }
243
+ }
244
+ }
245
+ for (const key of Object.keys(snapshot.trees)) {
246
+ const value = snapshot[key];
247
+ if (value !== undefined) {
248
+ const found = this.hasCompressionMarkup(value);
249
+ if (found) {
250
+ return found;
251
+ }
252
+ }
253
+ }
254
+ return false;
255
+ }
256
+ /**
257
+ * This method performs compression of the blobs in the summary tree.
258
+ * @param summary - The summary tree to compress.
259
+ * @param config - The compression config.
260
+ * @returns - The compressed summary tree.
261
+ */
262
+ static compressSummary(summary, config) {
263
+ this.putCompressionMarkup(summary);
264
+ const prep = DocumentStorageServiceCompressionAdapter.recursivelyReplace(true, summary, DocumentStorageServiceCompressionAdapter.blobEncoder, DocumentStorageServiceCompressionAdapter.blobDecoder, config);
265
+ // console.log(`Miso summary-blob Summary Upload: ${JSON.stringify(prep).length}`);
266
+ return prep;
267
+ }
268
+ /**
269
+ * This method read blob from the storage and decompresses it if it is compressed.
270
+ * @param id - The id of the blob to read.
271
+ * @returns - The decompressed blob.
272
+ */
273
+ async readBlob(id) {
274
+ const originalBlob = await super.readBlob(id);
275
+ if (!this._isCompressionEnabled) {
276
+ return originalBlob;
277
+ }
278
+ else {
279
+ const decompressedBlob = DocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);
280
+ // console.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);
281
+ return decompressedBlob;
282
+ }
283
+ }
284
+ /**
285
+ * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present
286
+ * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain
287
+ * algorithm byte prefix and store them.
288
+ * @param version - The version of the snapshot tree to load.
289
+ * @param scenarioName - The scenario name of the snapshot tree to load.
290
+ * @returns - The snapshot tree.
291
+ */
292
+ async getSnapshotTree(version, scenarioName) {
293
+ const snapshotTree = await super.getSnapshotTree(version, scenarioName);
294
+ this._isCompressionEnabled =
295
+ snapshotTree !== undefined &&
296
+ snapshotTree !== null &&
297
+ DocumentStorageServiceCompressionAdapter.hasCompressionMarkup(snapshotTree);
298
+ return snapshotTree;
299
+ }
300
+ /**
301
+ * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.
302
+ * @param summary - The summary tree to upload.
303
+ * @param context - The summary context.
304
+ * @returns - The ID of the uploaded summary.
305
+ */
306
+ async uploadSummaryWithContext(summary, context) {
307
+ const prep = DocumentStorageServiceCompressionAdapter.compressSummary(summary, this._config);
308
+ return super.uploadSummaryWithContext(prep, context);
309
+ }
310
+ /**
311
+ * This method downloads the summary from the storage and then applies decompression on the compressed blobs.
312
+ * @param id - The ID of the summary to be downloaded
313
+ * @returns - The summary with decompressed blobs
314
+ */
315
+ async downloadSummary(id) {
316
+ const summary = await super.downloadSummary(id);
317
+ return !this._isCompressionEnabled
318
+ ? summary
319
+ : DocumentStorageServiceCompressionAdapter.recursivelyReplace(false, summary, DocumentStorageServiceCompressionAdapter.blobEncoder, DocumentStorageServiceCompressionAdapter.blobDecoder, this._config);
320
+ }
321
+ }
322
+ exports.DocumentStorageServiceCompressionAdapter = DocumentStorageServiceCompressionAdapter;
323
+ /**
324
+ * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config
325
+ * containing the compression algorithm.
326
+ * @param input - The summary object to encode.
327
+ * @param config - The config containing the compression algorithm.
328
+ * @returns - The summary object with the encoded blob.
329
+ */
330
+ DocumentStorageServiceCompressionAdapter.blobEncoder = (input, config) => {
331
+ if (input.type === protocol_definitions_1.SummaryType.Blob) {
332
+ const summaryBlob = input;
333
+ const original = DocumentStorageServiceCompressionAdapter.toBinaryArray(summaryBlob.content);
334
+ const processed = DocumentStorageServiceCompressionAdapter.encodeBlob(original, config);
335
+ const newSummaryBlob = {
336
+ type: protocol_definitions_1.SummaryType.Blob,
337
+ content: common_utils_1.IsoBuffer.from(processed),
338
+ };
339
+ return newSummaryBlob;
340
+ }
341
+ else {
342
+ return input;
343
+ }
344
+ };
345
+ /**
346
+ * This method decodes the blob inside the given summary object of the SummaryType.Blob type.
347
+ * @param input - The summary object to decode.
348
+ * @returns - The summary object with the decoded blob.
349
+ */
350
+ DocumentStorageServiceCompressionAdapter.blobDecoder = (input) => {
351
+ if (input.type === protocol_definitions_1.SummaryType.Blob) {
352
+ const summaryBlob = input;
353
+ const original = DocumentStorageServiceCompressionAdapter.toBinaryArray(summaryBlob.content);
354
+ const processed = DocumentStorageServiceCompressionAdapter.decodeBlob(original);
355
+ const newSummaryBlob = {
356
+ type: protocol_definitions_1.SummaryType.Blob,
357
+ content: common_utils_1.IsoBuffer.from(processed),
358
+ };
359
+ return newSummaryBlob;
360
+ }
361
+ else {
362
+ return input;
363
+ }
364
+ };
365
+ //# sourceMappingURL=documentStorageServiceSummaryBlobCompressionAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentStorageServiceSummaryBlobCompressionAdapter.js","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AAEjE,+EAQ8C;AAC9C,iCAA6C;AAC7C,sFAAmF;AACnF,2BAA6E;AAEhE,QAAA,mBAAmB,GAAG,uBAAuB,CAAC;AAC3D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC;;;;;;;;;;GAUG;AACH,MAAa,wCAAyC,SAAQ,yDAA2B;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,CAAC,IAAI,CAAC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AAS,CAAC,IAAI,CAAC,SAAS,CAAC;SAClC,CAAC;QACF,OAAO,cAAc,CAAC;KACtB;SAAM;QACN,OAAO,KAAK,CAAC;KACb;AACF,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer, assert } from \"@fluidframework/common-utils\";\nimport { IDocumentStorageService, ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport {\n\tISnapshotTree,\n\tISummaryBlob,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n\tSummaryObject,\n\tSummaryType,\n} from \"@fluidframework/protocol-definitions\";\nimport { compress, decompress } from \"lz4js\";\nimport { DocumentStorageServiceProxy } from \"../../../documentStorageServiceProxy\";\nimport { ICompressionStorageConfig, SummaryCompressionAlgorithm } from \"../\";\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 */\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? SummaryCompressionAlgorithm.None\n\t\t\t: // eslint-disable-next-line no-bitwise\n\t\t\t IsoBuffer.from(blob)[0] & 0x0f;\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(blob: ArrayBufferLike, algorithm: number): ArrayBufferLike {\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(blob: ArrayBufferLike): ArrayBufferLike {\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 =\n\t\t\t\tDocumentStorageServiceCompressionAdapter.toBinaryArray(summaryBlob.content);\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 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\tlet originalBlob;\n\t\tlet algorithm;\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\tdecompressed = originalBlob;\n\t\t} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {\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\tconst value = 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 as SummaryObject,\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 of Object.keys(summary.tree)) {\n\t\t\tconst value = summary.tree[key];\n\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\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\treturn originalBlob;\n\t\t} else {\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}\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? summary\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 ) as ISummaryTree);\n\t}\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { DocumentStorageServiceCompressionAdapter, blobHeadersBlobName, } from "./documentStorageServiceSummaryBlobCompressionAdapter";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,wCAAwC,EACxC,mBAAmB,GACnB,MAAM,uDAAuD,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.blobHeadersBlobName = exports.DocumentStorageServiceCompressionAdapter = void 0;
8
+ var documentStorageServiceSummaryBlobCompressionAdapter_1 = require("./documentStorageServiceSummaryBlobCompressionAdapter");
9
+ Object.defineProperty(exports, "DocumentStorageServiceCompressionAdapter", { enumerable: true, get: function () { return documentStorageServiceSummaryBlobCompressionAdapter_1.DocumentStorageServiceCompressionAdapter; } });
10
+ Object.defineProperty(exports, "blobHeadersBlobName", { enumerable: true, get: function () { return documentStorageServiceSummaryBlobCompressionAdapter_1.blobHeadersBlobName; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6HAG+D;AAF9D,+KAAA,wCAAwC,OAAA;AACxC,0JAAA,mBAAmB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tDocumentStorageServiceCompressionAdapter,\n\tblobHeadersBlobName,\n} from \"./documentStorageServiceSummaryBlobCompressionAdapter\";\n"]}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { SummaryCompressionAlgorithm, ICompressionStorageConfig, DefaultCompressionStorageConfig, blobHeadersBlobName, } from "./compression";
6
+ export { applyStorageCompression } from "./predefinedAdapters";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,2BAA2B,EAC3B,yBAAyB,EACzB,+BAA+B,EAC/B,mBAAmB,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.applyStorageCompression = exports.blobHeadersBlobName = exports.DefaultCompressionStorageConfig = exports.SummaryCompressionAlgorithm = void 0;
8
+ var compression_1 = require("./compression");
9
+ Object.defineProperty(exports, "SummaryCompressionAlgorithm", { enumerable: true, get: function () { return compression_1.SummaryCompressionAlgorithm; } });
10
+ Object.defineProperty(exports, "DefaultCompressionStorageConfig", { enumerable: true, get: function () { return compression_1.DefaultCompressionStorageConfig; } });
11
+ Object.defineProperty(exports, "blobHeadersBlobName", { enumerable: true, get: function () { return compression_1.blobHeadersBlobName; } });
12
+ var predefinedAdapters_1 = require("./predefinedAdapters");
13
+ Object.defineProperty(exports, "applyStorageCompression", { enumerable: true, get: function () { return predefinedAdapters_1.applyStorageCompression; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6CAKuB;AAJtB,0HAAA,2BAA2B,OAAA;AAE3B,8HAAA,+BAA+B,OAAA;AAC/B,kHAAA,mBAAmB,OAAA;AAGpB,2DAA+D;AAAtD,6HAAA,uBAAuB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tSummaryCompressionAlgorithm,\n\tICompressionStorageConfig,\n\tDefaultCompressionStorageConfig,\n\tblobHeadersBlobName,\n} from \"./compression\";\n\nexport { applyStorageCompression } from \"./predefinedAdapters\";\n"]}
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentServiceFactory } from "@fluidframework/driver-definitions";
6
+ import { ICompressionStorageConfig } from "./compression";
7
+ /**
8
+ * This method optionally applies compression to the given document service factory. The compression
9
+ * must be enabled by setting the config to true or by passing a compression config object.
10
+ * @param documentServiceFactory - The document service factory to apply compression to.
11
+ * @param config - The compression configuration.
12
+ * @returns - The document service factory possibly with compression applied.
13
+ */
14
+ export declare function applyStorageCompression(documentServiceFactory: IDocumentServiceFactory, config?: ICompressionStorageConfig | boolean): IDocumentServiceFactory;
15
+ /**
16
+ * This method checks whether given objects contains
17
+ * a properties expected for the interface ICompressionStorageConfig.
18
+ */
19
+ export declare function isCompressionConfig(config: any): config is ICompressionStorageConfig;
20
+ //# sourceMappingURL=predefinedAdapters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predefinedAdapters.d.ts","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAEN,yBAAyB,EAEzB,MAAM,eAAe,CAAC;AAEvB;;;;;;GAMG;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,GAAG,GAAG,MAAM,IAAI,yBAAyB,CAKpF"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isCompressionConfig = exports.applyStorageCompression = void 0;
8
+ const common_utils_1 = require("@fluidframework/common-utils");
9
+ const compression_1 = require("./compression");
10
+ /**
11
+ * This method optionally applies compression to the given document service factory. The compression
12
+ * must be enabled by setting the config to true or by passing a compression config object.
13
+ * @param documentServiceFactory - The document service factory to apply compression to.
14
+ * @param config - The compression configuration.
15
+ * @returns - The document service factory possibly with compression applied.
16
+ */
17
+ function applyStorageCompression(documentServiceFactory, config) {
18
+ if (config === undefined || config === false) {
19
+ return documentServiceFactory;
20
+ }
21
+ else if (config === true) {
22
+ return applyStorageCompressionInternal(compression_1.DocumentServiceFactoryCompressionAdapter, documentServiceFactory);
23
+ }
24
+ else {
25
+ (0, common_utils_1.assert)(isCompressionConfig(config), 0x6f4 /* Invalid compression config */);
26
+ return applyStorageCompressionInternal(compression_1.DocumentServiceFactoryCompressionAdapter, documentServiceFactory, config);
27
+ }
28
+ }
29
+ exports.applyStorageCompression = applyStorageCompression;
30
+ /**
31
+ * This method applies compression to the given document service factory.
32
+ * @param documentServiceFactory - The document service factory to apply compression to.
33
+ * @param config - The compression configuration.
34
+ * @returns - The document service factory with compression applied.
35
+ */
36
+ function applyStorageCompressionInternal(constructor, documentServiceFactory, config = compression_1.DefaultCompressionStorageConfig) {
37
+ if (config.algorithm === undefined) {
38
+ return documentServiceFactory;
39
+ }
40
+ return new constructor(documentServiceFactory, config);
41
+ }
42
+ /**
43
+ * This method checks whether given objects contains
44
+ * a properties expected for the interface ICompressionStorageConfig.
45
+ */
46
+ function isCompressionConfig(config) {
47
+ return (config !== undefined &&
48
+ (config.algorithm !== undefined || config.minSizeToCompress !== undefined));
49
+ }
50
+ exports.isCompressionConfig = isCompressionConfig;
51
+ //# sourceMappingURL=predefinedAdapters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predefinedAdapters.js","sourceRoot":"","sources":["../../src/adapters/predefinedAdapters.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD,+CAIuB;AAEvB;;;;;;GAMG;AACH,SAAgB,uBAAuB,CACtC,sBAA+C,EAC/C,MAA4C;IAE5C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,EAAE;QAC7C,OAAO,sBAAsB,CAAC;KAC9B;SAAM,IAAI,MAAM,KAAK,IAAI,EAAE;QAC3B,OAAO,+BAA+B,CACrC,sDAAwC,EACxC,sBAAsB,CACtB,CAAC;KACF;SAAM;QACN,IAAA,qBAAM,EAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC5E,OAAO,+BAA+B,CACrC,sDAAwC,EACxC,sBAAsB,EACtB,MAAM,CACN,CAAC;KACF;AACF,CAAC;AAnBD,0DAmBC;AAED;;;;;GAKG;AACH,SAAS,+BAA+B,CACvC,WAG4B,EAC5B,sBAA+C,EAC/C,SAAoC,6CAA+B;IAEnE,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE;QACnC,OAAO,sBAAsB,CAAC;KAC9B;IACD,OAAO,IAAI,WAAW,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,MAAW;IAC9C,OAAO,CACN,MAAM,KAAK,SAAS;QACpB,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,MAAM,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAC1E,CAAC;AACH,CAAC;AALD,kDAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IDocumentServiceFactory } from \"@fluidframework/driver-definitions\";\nimport {\n\tDocumentServiceFactoryCompressionAdapter,\n\tICompressionStorageConfig,\n\tDefaultCompressionStorageConfig,\n} from \"./compression\";\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 */\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: any): config is ICompressionStorageConfig {\n\treturn (\n\t\tconfig !== undefined &&\n\t\t(config.algorithm !== undefined || config.minSizeToCompress !== undefined)\n\t);\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
+ import { IDocumentService, IDocumentServiceFactory, IResolvedUrl } from "@fluidframework/driver-definitions";
7
+ import { ISummaryTree } from "@fluidframework/protocol-definitions";
8
+ /**
9
+ * This abstract class implements IDocumentServiceFactory interface. It uses delegation pattern.
10
+ * It delegates all calls to IDocumentServiceFactory implementation passed to constructor.
11
+ */
12
+ export declare abstract class DocumentServiceFactoryProxy implements IDocumentServiceFactory {
13
+ private readonly _serviceFactory;
14
+ constructor(_serviceFactory: IDocumentServiceFactory);
15
+ get serviceFactory(): IDocumentServiceFactory;
16
+ createContainer(createNewSummary: ISummaryTree | undefined, createNewResolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
17
+ createDocumentService(resolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
18
+ }
19
+ //# sourceMappingURL=documentServiceFactoryProxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentServiceFactoryProxy.d.ts","sourceRoot":"","sources":["../src/documentServiceFactoryProxy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpE;;;GAGG;AAEH,8BAAsB,2BAA4B,YAAW,uBAAuB;IACvE,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,uBAAuB;IAErE,IAAW,cAAc,IAAI,uBAAuB,CAEnD;IAEY,eAAe,CAC3B,gBAAgB,EAAE,YAAY,GAAG,SAAS,EAC1C,oBAAoB,EAAE,YAAY,EAClC,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IASf,qBAAqB,CACjC,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC;CAG5B"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DocumentServiceFactoryProxy = void 0;
8
+ /**
9
+ * This abstract class implements IDocumentServiceFactory interface. It uses delegation pattern.
10
+ * It delegates all calls to IDocumentServiceFactory implementation passed to constructor.
11
+ */
12
+ class DocumentServiceFactoryProxy {
13
+ constructor(_serviceFactory) {
14
+ this._serviceFactory = _serviceFactory;
15
+ }
16
+ get serviceFactory() {
17
+ return this._serviceFactory;
18
+ }
19
+ async createContainer(createNewSummary, createNewResolvedUrl, logger, clientIsSummarizer) {
20
+ return this.serviceFactory.createContainer(createNewSummary, createNewResolvedUrl, logger, clientIsSummarizer);
21
+ }
22
+ async createDocumentService(resolvedUrl, logger, clientIsSummarizer) {
23
+ return this.serviceFactory.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
24
+ }
25
+ }
26
+ exports.DocumentServiceFactoryProxy = DocumentServiceFactoryProxy;
27
+ //# sourceMappingURL=documentServiceFactoryProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentServiceFactoryProxy.js","sourceRoot":"","sources":["../src/documentServiceFactoryProxy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH;;;GAGG;AAEH,MAAsB,2BAA2B;IAChD,YAA6B,eAAwC;QAAxC,oBAAe,GAAf,eAAe,CAAyB;IAAG,CAAC;IAEzE,IAAW,cAAc;QACxB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,eAAe,CAC3B,gBAA0C,EAC1C,oBAAkC,EAClC,MAA6B,EAC7B,kBAA4B;QAE5B,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CACzC,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,EACN,kBAAkB,CAClB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB,CACjC,WAAyB,EACzB,MAA6B,EAC7B,kBAA4B;QAE5B,OAAO,IAAI,CAAC,cAAc,CAAC,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC3F,CAAC;CACD;AA5BD,kEA4BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport {\n\tIDocumentService,\n\tIDocumentServiceFactory,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\n\n/**\n * This abstract class implements IDocumentServiceFactory interface. It uses delegation pattern.\n * It delegates all calls to IDocumentServiceFactory implementation passed to constructor.\n */\n\nexport abstract class DocumentServiceFactoryProxy implements IDocumentServiceFactory {\n\tconstructor(private readonly _serviceFactory: IDocumentServiceFactory) {}\n\n\tpublic get serviceFactory(): IDocumentServiceFactory {\n\t\treturn this._serviceFactory;\n\t}\n\n\tpublic async createContainer(\n\t\tcreateNewSummary: ISummaryTree | undefined,\n\t\tcreateNewResolvedUrl: IResolvedUrl,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService> {\n\t\treturn this.serviceFactory.createContainer(\n\t\t\tcreateNewSummary,\n\t\t\tcreateNewResolvedUrl,\n\t\t\tlogger,\n\t\t\tclientIsSummarizer,\n\t\t);\n\t}\n\n\tpublic async createDocumentService(\n\t\tresolvedUrl: IResolvedUrl,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService> {\n\t\treturn this.serviceFactory.createDocumentService(resolvedUrl, logger, clientIsSummarizer);\n\t}\n}\n"]}