@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,19 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { DocumentServiceProxy } from "../../documentServiceProxy";
6
+ import { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from "./summaryblob";
7
+ export class DocumentServiceCompressionAdapter extends DocumentServiceProxy {
8
+ constructor(service, _config) {
9
+ super(service);
10
+ this._config = _config;
11
+ }
12
+ async connectToStorage() {
13
+ const storage = await super.connectToStorage();
14
+ const wrapped = new DocumentStorageServiceSummaryBlobCompressionAdapter(storage, this._config);
15
+ await wrapped.getSnapshotTree();
16
+ return wrapped;
17
+ }
18
+ }
19
+ //# sourceMappingURL=documentServiceCompressionAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentServiceCompressionAdapter.js","sourceRoot":"","sources":["../../../src/adapters/compression/documentServiceCompressionAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,wCAAwC,IAAI,mDAAmD,EAAE,MAAM,eAAe,CAAC;AAGhI,MAAM,OAAO,iCAAkC,SAAQ,oBAAoB;IAC1E,YAAY,OAAyB,EAAmB,OAAkC;QACzF,KAAK,CAAC,OAAO,CAAC,CAAC;QADwC,YAAO,GAAP,OAAO,CAA2B;IAE1F,CAAC;IAEM,KAAK,CAAC,gBAAgB;QAC5B,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,IAAI,mDAAmD,CACtE,OAAO,EACP,IAAI,CAAC,OAAO,CACZ,CAAC;QACF,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDocumentService, IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { DocumentServiceProxy } from \"../../documentServiceProxy\";\nimport { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from \"./summaryblob\";\nimport { ICompressionStorageConfig } from \"./compressionTypes\";\n\nexport class DocumentServiceCompressionAdapter extends DocumentServiceProxy {\n\tconstructor(service: IDocumentService, private readonly _config: ICompressionStorageConfig) {\n\t\tsuper(service);\n\t}\n\n\tpublic async connectToStorage(): Promise<IDocumentStorageService> {\n\t\tconst storage = await super.connectToStorage();\n\t\tconst wrapped = new DocumentStorageServiceSummaryBlobCompressionAdapter(\n\t\t\tstorage,\n\t\t\tthis._config,\n\t\t);\n\t\tawait wrapped.getSnapshotTree();\n\t\treturn wrapped;\n\t}\n}\n"]}
@@ -0,0 +1,16 @@
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
+ import { DocumentServiceFactoryProxy } from "../../documentServiceFactoryProxy";
9
+ import { ICompressionStorageConfig } from "..";
10
+ export declare class DocumentServiceFactoryCompressionAdapter extends DocumentServiceFactoryProxy {
11
+ private readonly _config;
12
+ constructor(serviceFactory: IDocumentServiceFactory, _config: ICompressionStorageConfig);
13
+ createContainer(createNewSummary: ISummaryTree | undefined, createNewResolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, clientIsSummarizer?: boolean): Promise<IDocumentService>;
14
+ createDocumentService(resolvedUrl: IResolvedUrl): Promise<IDocumentService>;
15
+ }
16
+ //# sourceMappingURL=documentServiceFactoryCompressionAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentServiceFactoryCompressionAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/compression/documentServiceFactoryCompressionAdapter.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;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,IAAI,CAAC;AAI/C,qBAAa,wCAAyC,SAAQ,2BAA2B;IAGvF,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADxB,cAAc,EAAE,uBAAuB,EACtB,OAAO,EAAE,yBAAyB;IAKvC,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;IA2Bf,qBAAqB,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAIxF"}
@@ -0,0 +1,32 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { DocumentServiceFactoryProxy } from "../../documentServiceFactoryProxy";
6
+ import { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from "./summaryblob";
7
+ import { DocumentServiceCompressionAdapter } from "./documentServiceCompressionAdapter";
8
+ export class DocumentServiceFactoryCompressionAdapter extends DocumentServiceFactoryProxy {
9
+ constructor(serviceFactory, _config) {
10
+ super(serviceFactory);
11
+ this._config = _config;
12
+ }
13
+ async createContainer(createNewSummary, createNewResolvedUrl, logger, clientIsSummarizer) {
14
+ if (createNewSummary !== undefined) {
15
+ // TODO : this is a hack to make sure that the initial summary is not compressed
16
+ // We must prevent the initial summary from being compressed because
17
+ // of the hack at packages/drivers/routerlicious-driver/src/createNewUtils.ts
18
+ // where the binary blob is converted to a string using UTF-8 encoding
19
+ // which is producing incorrect results for compressed data.
20
+ const configForInitial = Object.assign(Object.assign({}, this._config), { minSizeToCompress: Number.POSITIVE_INFINITY });
21
+ const newAppSumary = DocumentStorageServiceSummaryBlobCompressionAdapter.compressSummary(createNewSummary.tree[".app"], configForInitial);
22
+ createNewSummary.tree[".app"] = newAppSumary;
23
+ }
24
+ const service = await this.serviceFactory.createContainer(createNewSummary, createNewResolvedUrl, logger, clientIsSummarizer);
25
+ return new DocumentServiceCompressionAdapter(service, this._config);
26
+ }
27
+ async createDocumentService(resolvedUrl) {
28
+ const service = await this.serviceFactory.createDocumentService(resolvedUrl);
29
+ return new DocumentServiceCompressionAdapter(service, this._config);
30
+ }
31
+ }
32
+ //# sourceMappingURL=documentServiceFactoryCompressionAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentServiceFactoryCompressionAdapter.js","sourceRoot":"","sources":["../../../src/adapters/compression/documentServiceFactoryCompressionAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAEhF,OAAO,EAAE,wCAAwC,IAAI,mDAAmD,EAAE,MAAM,eAAe,CAAC;AAChI,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,MAAM,OAAO,wCAAyC,SAAQ,2BAA2B;IACxF,YACC,cAAuC,EACtB,OAAkC;QAEnD,KAAK,CAAC,cAAc,CAAC,CAAC;QAFL,YAAO,GAAP,OAAO,CAA2B;IAGpD,CAAC;IAEM,KAAK,CAAC,eAAe,CAC3B,gBAA0C,EAC1C,oBAAkC,EAClC,MAA6B,EAC7B,kBAA4B;QAE5B,IAAI,gBAAgB,KAAK,SAAS,EAAE;YACnC,gFAAgF;YAChF,oEAAoE;YACpE,6EAA6E;YAC7E,sEAAsE;YACtE,4DAA4D;YAC5D,MAAM,gBAAgB,mCAClB,IAAI,CAAC,OAAO,KACf,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,GAC3C,CAAC;YACF,MAAM,YAAY,GACjB,mDAAmD,CAAC,eAAe,CAClE,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAiB,EAC7C,gBAAgB,CAChB,CAAC;YACH,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;SAC7C;QACD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CACxD,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,EACN,kBAAkB,CAClB,CAAC;QACF,OAAO,IAAI,iCAAiC,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,WAAyB;QAC3D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QAC7E,OAAO,IAAI,iCAAiC,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;CACD","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\";\nimport { DocumentServiceFactoryProxy } from \"../../documentServiceFactoryProxy\";\nimport { ICompressionStorageConfig } from \"..\";\nimport { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from \"./summaryblob\";\nimport { DocumentServiceCompressionAdapter } from \"./documentServiceCompressionAdapter\";\n\nexport class DocumentServiceFactoryCompressionAdapter extends DocumentServiceFactoryProxy {\n\tconstructor(\n\t\tserviceFactory: IDocumentServiceFactory,\n\t\tprivate readonly _config: ICompressionStorageConfig,\n\t) {\n\t\tsuper(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\tif (createNewSummary !== undefined) {\n\t\t\t// TODO : this is a hack to make sure that the initial summary is not compressed\n\t\t\t// We must prevent the initial summary from being compressed because\n\t\t\t// of the hack at packages/drivers/routerlicious-driver/src/createNewUtils.ts\n\t\t\t// where the binary blob is converted to a string using UTF-8 encoding\n\t\t\t// which is producing incorrect results for compressed data.\n\t\t\tconst configForInitial = {\n\t\t\t\t...this._config,\n\t\t\t\tminSizeToCompress: Number.POSITIVE_INFINITY,\n\t\t\t};\n\t\t\tconst newAppSumary =\n\t\t\t\tDocumentStorageServiceSummaryBlobCompressionAdapter.compressSummary(\n\t\t\t\t\tcreateNewSummary.tree[\".app\"] as ISummaryTree,\n\t\t\t\t\tconfigForInitial,\n\t\t\t\t);\n\t\t\tcreateNewSummary.tree[\".app\"] = newAppSumary;\n\t\t}\n\t\tconst service = await this.serviceFactory.createContainer(\n\t\t\tcreateNewSummary,\n\t\t\tcreateNewResolvedUrl,\n\t\t\tlogger,\n\t\t\tclientIsSummarizer,\n\t\t);\n\t\treturn new DocumentServiceCompressionAdapter(service, this._config);\n\t}\n\n\tpublic async createDocumentService(resolvedUrl: IResolvedUrl): Promise<IDocumentService> {\n\t\tconst service = await this.serviceFactory.createDocumentService(resolvedUrl);\n\t\treturn new DocumentServiceCompressionAdapter(service, this._config);\n\t}\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { SummaryCompressionAlgorithm, ICompressionStorageConfig, DefaultCompressionStorageConfig, } from "./compressionTypes";
6
+ export { DocumentServiceFactoryCompressionAdapter } from "./documentServiceFactoryCompressionAdapter";
7
+ export { blobHeadersBlobName } from "./summaryblob";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/compression/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,2BAA2B,EAC3B,yBAAyB,EACzB,+BAA+B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAC;AACtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { SummaryCompressionAlgorithm, DefaultCompressionStorageConfig, } from "./compressionTypes";
6
+ export { DocumentServiceFactoryCompressionAdapter } from "./documentServiceFactoryCompressionAdapter";
7
+ export { blobHeadersBlobName } from "./summaryblob";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/compression/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,2BAA2B,EAE3B,+BAA+B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAC;AACtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC","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} from \"./compressionTypes\";\nexport { DocumentServiceFactoryCompressionAdapter } from \"./documentServiceFactoryCompressionAdapter\";\nexport { blobHeadersBlobName } from \"./summaryblob\";\n"]}
@@ -0,0 +1,161 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentStorageService, ISummaryContext } from "@fluidframework/driver-definitions";
6
+ import { ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
7
+ import { DocumentStorageServiceProxy } from "../../../documentStorageServiceProxy";
8
+ import { ICompressionStorageConfig } from "../";
9
+ export declare const blobHeadersBlobName = ".metadata.blobHeaders";
10
+ /**
11
+ * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.
12
+ * The identification of the compressed blobs is done by adding a compression markup blob to the summary.
13
+ * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,
14
+ * which is compressed also contain the compression algorithm enumerated value from the
15
+ * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not
16
+ * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .
17
+ * In case, the markup blob is present, it is expected that the first byte of the markup blob
18
+ * will contain the info about the compression. If the first byte is not present, it is assumed
19
+ * that the compression is not enabled and no first prefix byte is present in the blobs.
20
+ */
21
+ export declare class DocumentStorageServiceCompressionAdapter extends DocumentStorageServiceProxy {
22
+ private readonly _config;
23
+ private _isCompressionEnabled;
24
+ constructor(service: IDocumentStorageService, _config: ICompressionStorageConfig);
25
+ get service(): IDocumentStorageService;
26
+ /**
27
+ * This method returns true if there is a compression markup byte in the blob, otherwise false.
28
+ * @param blob - The blob to compress.
29
+ * @returns - True if there is a compression markup byte in the blob, otherwise false.
30
+ */
31
+ private static hasPrefix;
32
+ /**
33
+ * This method reads the first byte from the given blob and maps that byte to the compression algorithm.
34
+ * @param blob - The maybe compressed blob.
35
+ */
36
+ private static readAlgorithmFromBlob;
37
+ /**
38
+ * This method writes the given algorithm to the blob as the first byte.
39
+ * @param blob - The blob to write the algorithm to.
40
+ * @param algorithm - The algorithm to write.
41
+ * @returns - The blob with the algorithm as the first byte.
42
+ */
43
+ private static writeAlgorithmToBlob;
44
+ /**
45
+ * This method removes the algorithm markup prefix from the blob (1 byte)
46
+ * @param blob - The blob to remove the prefix from.
47
+ * @returns - The blob without the prefix.
48
+ */
49
+ private static removePrefixFromBlobIfPresent;
50
+ /**
51
+ * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,
52
+ * it is just returned as is. If the parameter is string, it is converted to Uint8Array using
53
+ * TextEncoder.
54
+ * @param input - The input to convert to Uint8Array.
55
+ * @returns - The Uint8Array representation of the input.
56
+ */
57
+ private static toBinaryArray;
58
+ /**
59
+ * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config
60
+ * containing the compression algorithm.
61
+ * @param input - The summary object to encode.
62
+ * @param config - The config containing the compression algorithm.
63
+ * @returns - The summary object with the encoded blob.
64
+ */
65
+ private static readonly blobEncoder;
66
+ /**
67
+ * This method decodes the blob inside the given summary object of the SummaryType.Blob type.
68
+ * @param input - The summary object to decode.
69
+ * @returns - The summary object with the decoded blob.
70
+ */
71
+ private static readonly blobDecoder;
72
+ /**
73
+ * This method encodes the given blob according to the given config.
74
+ * @param file - The blob to encode.
75
+ * @param config - The config to use for encoding.
76
+ * @returns - The encoded blob.
77
+ */
78
+ private static encodeBlob;
79
+ /**
80
+ * This method decodes the given blob.
81
+ * @param file - The blob to decode.
82
+ * @returns - The decoded blob.
83
+ */
84
+ private static decodeBlob;
85
+ /**
86
+ * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,
87
+ * it applies encoding/decoding on it according to the given isEncode flag.
88
+ * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.
89
+ * @param input - The summary object to traverse.
90
+ * @param encoder - The encoder function to use.
91
+ * @param decoder - The decoder function to use.
92
+ * @param config - The config to use for encoding.
93
+ * @param context - The summary context.
94
+ * @returns - The summary object with the encoded/decoded blob.
95
+ */
96
+ private static recursivelyReplace;
97
+ /**
98
+ * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',
99
+ * it returns the summary tree containing that blob.
100
+ *
101
+ * @param summary - The summary tree to traverse.
102
+ * @returns - The summary tree containing the metadata blob.
103
+ */
104
+ private static findMetadataHolderSummary;
105
+ /**
106
+ * This method obtains the summary tree containing the metadata blob. It returns the content
107
+ * of the tree atribute.
108
+ * @param summary - The summary tree to traverse.
109
+ * @returns - The content of the tree attribute of the summary tree containing the metadata blob.
110
+ */
111
+ private static getMetadataHolderTree;
112
+ /**
113
+ * This method adds the compression markup blob to the nested summary tree containing the metadata blob.
114
+ * @param summary - The top summary tree to put the compression markup blob into.
115
+ */
116
+ private static putCompressionMarkup;
117
+ /**
118
+ * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',
119
+ * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,
120
+ * it returns true, otherwise false.
121
+ * @param snapshot - The snapshot tree to traverse.
122
+ * @returns - True if the compression markup blob is found, otherwise false.
123
+ */
124
+ private static hasCompressionMarkup;
125
+ /**
126
+ * This method performs compression of the blobs in the summary tree.
127
+ * @param summary - The summary tree to compress.
128
+ * @param config - The compression config.
129
+ * @returns - The compressed summary tree.
130
+ */
131
+ static compressSummary(summary: ISummaryTree, config: ICompressionStorageConfig): ISummaryTree;
132
+ /**
133
+ * This method read blob from the storage and decompresses it if it is compressed.
134
+ * @param id - The id of the blob to read.
135
+ * @returns - The decompressed blob.
136
+ */
137
+ readBlob(id: string): Promise<ArrayBufferLike>;
138
+ /**
139
+ * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present
140
+ * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain
141
+ * algorithm byte prefix and store them.
142
+ * @param version - The version of the snapshot tree to load.
143
+ * @param scenarioName - The scenario name of the snapshot tree to load.
144
+ * @returns - The snapshot tree.
145
+ */
146
+ getSnapshotTree(version?: IVersion | undefined, scenarioName?: string | undefined): Promise<ISnapshotTree | null>;
147
+ /**
148
+ * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.
149
+ * @param summary - The summary tree to upload.
150
+ * @param context - The summary context.
151
+ * @returns - The ID of the uploaded summary.
152
+ */
153
+ uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
154
+ /**
155
+ * This method downloads the summary from the storage and then applies decompression on the compressed blobs.
156
+ * @param id - The ID of the summary to be downloaded
157
+ * @returns - The summary with decompressed blobs
158
+ */
159
+ downloadSummary(id: ISummaryHandle): Promise<ISummaryTree>;
160
+ }
161
+ //# sourceMappingURL=documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentStorageServiceSummaryBlobCompressionAdapter.d.ts","sourceRoot":"","sources":["../../../../src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EACN,aAAa,EAEb,cAAc,EACd,YAAY,EACZ,QAAQ,EAGR,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAA+B,MAAM,KAAK,CAAC;AAE7E,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAG3D;;;;;;;;;;GAUG;AACH,qBAAa,wCAAyC,SAAQ,2BAA2B;IAKvF,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJzB,OAAO,CAAC,qBAAqB,CAAkB;gBAG9C,OAAO,EAAE,uBAAuB,EACf,OAAO,EAAE,yBAAyB;IAKpD,IAAW,OAAO,IAAI,uBAAuB,CAE5C;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAMxB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAOpC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAmBnC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAK5C;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAI5B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAoBjC;IAEF;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAgBjC;IAEF;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAwBzB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAqBzB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAoCjC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAkBxC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAOpC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IASnC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAsBnC;;;;;OAKG;WACW,eAAe,CAC5B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,yBAAyB,GAC/B,YAAY;IAaf;;;;OAIG;IACmB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAYpE;;;;;;;OAOG;IACmB,eAAe,CACpC,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,EAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,GAE/B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAShC;;;;;OAKG;IACmB,wBAAwB,CAC7C,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IAQlB;;;;OAIG;IACmB,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;CAYhF"}
@@ -0,0 +1,361 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IsoBuffer, assert } from "@fluidframework/common-utils";
6
+ import { SummaryType, } from "@fluidframework/protocol-definitions";
7
+ import { compress, decompress } from "lz4js";
8
+ import { DocumentStorageServiceProxy } from "../../../documentStorageServiceProxy";
9
+ import { SummaryCompressionAlgorithm } from "../";
10
+ export const blobHeadersBlobName = ".metadata.blobHeaders";
11
+ const metadataBlobName = ".metadata";
12
+ /**
13
+ * This class is a proxy for the IDocumentStorageService that compresses and decompresses blobs in the summary.
14
+ * The identification of the compressed blobs is done by adding a compression markup blob to the summary.
15
+ * Even if the markup blob is present, it does not mean that all blobs are compressed. The blob,
16
+ * which is compressed also contain the compression algorithm enumerated value from the
17
+ * SummaryCompressionAlgorithm enumeration in the first byte . If the blob is not
18
+ * commpressed, it contains the first byte equals to SummaryCompressionAlgorithm.None .
19
+ * In case, the markup blob is present, it is expected that the first byte of the markup blob
20
+ * will contain the info about the compression. If the first byte is not present, it is assumed
21
+ * that the compression is not enabled and no first prefix byte is present in the blobs.
22
+ */
23
+ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageServiceProxy {
24
+ constructor(service, _config) {
25
+ super(service);
26
+ this._config = _config;
27
+ this._isCompressionEnabled = false;
28
+ }
29
+ get service() {
30
+ return this.internalStorageService;
31
+ }
32
+ /**
33
+ * This method returns true if there is a compression markup byte in the blob, otherwise false.
34
+ * @param blob - The blob to compress.
35
+ * @returns - True if there is a compression markup byte in the blob, otherwise false.
36
+ */
37
+ static hasPrefix(blob) {
38
+ const firstByte = IsoBuffer.from(blob)[0];
39
+ // eslint-disable-next-line no-bitwise
40
+ return (firstByte & 0xf0) === 0xb0;
41
+ }
42
+ /**
43
+ * This method reads the first byte from the given blob and maps that byte to the compression algorithm.
44
+ * @param blob - The maybe compressed blob.
45
+ */
46
+ static readAlgorithmFromBlob(blob) {
47
+ return !this.hasPrefix(blob)
48
+ ? SummaryCompressionAlgorithm.None
49
+ : // eslint-disable-next-line no-bitwise
50
+ IsoBuffer.from(blob)[0] & 0x0f;
51
+ }
52
+ /**
53
+ * This method writes the given algorithm to the blob as the first byte.
54
+ * @param blob - The blob to write the algorithm to.
55
+ * @param algorithm - The algorithm to write.
56
+ * @returns - The blob with the algorithm as the first byte.
57
+ */
58
+ static writeAlgorithmToBlob(blob, algorithm) {
59
+ if (algorithm === SummaryCompressionAlgorithm.None) {
60
+ const firstByte = IsoBuffer.from(blob)[0];
61
+ // eslint-disable-next-line no-bitwise
62
+ if ((firstByte & 0xf0) !== 0xb0) {
63
+ return blob;
64
+ }
65
+ }
66
+ assert(algorithm < 0x10, 0x6f5 /* Algorithm should be less than 0x10 */);
67
+ const blobView = new Uint8Array(blob);
68
+ const blobLength = blobView.length;
69
+ const newBlob = new Uint8Array(blobLength + 1);
70
+ // eslint-disable-next-line no-bitwise
71
+ const prefix = 0xb0 | algorithm;
72
+ newBlob[0] = prefix;
73
+ newBlob.set(blobView, 1);
74
+ return IsoBuffer.from(newBlob);
75
+ }
76
+ /**
77
+ * This method removes the algorithm markup prefix from the blob (1 byte)
78
+ * @param blob - The blob to remove the prefix from.
79
+ * @returns - The blob without the prefix.
80
+ */
81
+ static removePrefixFromBlobIfPresent(blob) {
82
+ const blobView = new Uint8Array(blob);
83
+ return this.hasPrefix(blob) ? IsoBuffer.from(blobView.subarray(1)) : blob;
84
+ }
85
+ /**
86
+ * This method converts the given argument to Uint8Array. If the parameter is already Uint8Array,
87
+ * it is just returned as is. If the parameter is string, it is converted to Uint8Array using
88
+ * TextEncoder.
89
+ * @param input - The input to convert to Uint8Array.
90
+ * @returns - The Uint8Array representation of the input.
91
+ */
92
+ static toBinaryArray(input) {
93
+ return typeof input === "string" ? new TextEncoder().encode(input) : input;
94
+ }
95
+ /**
96
+ * This method encodes the given blob according to the given config.
97
+ * @param file - The blob to encode.
98
+ * @param config - The config to use for encoding.
99
+ * @returns - The encoded blob.
100
+ */
101
+ static encodeBlob(file, config) {
102
+ let maybeCompressed;
103
+ let algorithm = config.algorithm;
104
+ if (new Uint8Array(file).length < config.minSizeToCompress) {
105
+ maybeCompressed = file;
106
+ algorithm = SummaryCompressionAlgorithm.None;
107
+ }
108
+ else if (algorithm === SummaryCompressionAlgorithm.None) {
109
+ maybeCompressed = file;
110
+ }
111
+ else if (algorithm === SummaryCompressionAlgorithm.LZ4) {
112
+ const compressed = compress(file);
113
+ maybeCompressed = compressed;
114
+ }
115
+ else {
116
+ throw new Error(`Unknown Algorithm ${config.algorithm}`);
117
+ }
118
+ maybeCompressed = DocumentStorageServiceCompressionAdapter.writeAlgorithmToBlob(maybeCompressed, algorithm);
119
+ return maybeCompressed;
120
+ }
121
+ /**
122
+ * This method decodes the given blob.
123
+ * @param file - The blob to decode.
124
+ * @returns - The decoded blob.
125
+ */
126
+ static decodeBlob(file) {
127
+ let decompressed;
128
+ let originalBlob;
129
+ let algorithm;
130
+ if (this.hasPrefix(file)) {
131
+ algorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);
132
+ originalBlob = this.removePrefixFromBlobIfPresent(file);
133
+ }
134
+ else {
135
+ algorithm = SummaryCompressionAlgorithm.None;
136
+ originalBlob = file;
137
+ }
138
+ if (algorithm === SummaryCompressionAlgorithm.None) {
139
+ decompressed = originalBlob;
140
+ }
141
+ else if (algorithm === SummaryCompressionAlgorithm.LZ4) {
142
+ decompressed = decompress(originalBlob);
143
+ }
144
+ else {
145
+ throw new Error(`Unknown Algorithm ${algorithm}`);
146
+ }
147
+ return decompressed;
148
+ }
149
+ /**
150
+ * This method traverses the SummaryObject recursively. If it finds the ISummaryBlob object,
151
+ * it applies encoding/decoding on it according to the given isEncode flag.
152
+ * @param isEncode - True if the encoding should be applied, false if the decoding should be applied.
153
+ * @param input - The summary object to traverse.
154
+ * @param encoder - The encoder function to use.
155
+ * @param decoder - The decoder function to use.
156
+ * @param config - The config to use for encoding.
157
+ * @param context - The summary context.
158
+ * @returns - The summary object with the encoded/decoded blob.
159
+ */
160
+ static recursivelyReplace(isEncode, input, encoder, decoder, config, context) {
161
+ assert(typeof input === "object", 0x6f6 /* input must be a non-null object */);
162
+ const maybeReplaced = isEncode ? encoder(input, config) : decoder(input);
163
+ if (maybeReplaced !== input) {
164
+ return maybeReplaced;
165
+ }
166
+ let clone;
167
+ for (const key of Object.keys(input)) {
168
+ const value = input[key];
169
+ if (Boolean(value) && typeof value === "object") {
170
+ const replaced = this.recursivelyReplace(isEncode, value, encoder, decoder, config, context);
171
+ if (replaced !== value) {
172
+ clone = clone !== null && clone !== void 0 ? clone : (Array.isArray(input) ? [...input] : Object.assign({}, input));
173
+ clone[key] = replaced;
174
+ }
175
+ }
176
+ }
177
+ return (clone !== null && clone !== void 0 ? clone : input);
178
+ }
179
+ /**
180
+ * This method traverses the SummaryTree recursively. If it finds the ISummaryBlob object with the key '.metadata',
181
+ * it returns the summary tree containing that blob.
182
+ *
183
+ * @param summary - The summary tree to traverse.
184
+ * @returns - The summary tree containing the metadata blob.
185
+ */
186
+ static findMetadataHolderSummary(summary) {
187
+ assert(typeof summary === "object", 0x6f7 /* summary must be a non-null object */);
188
+ for (const key of Object.keys(summary.tree)) {
189
+ const value = summary.tree[key];
190
+ if (Boolean(value) && value.type === SummaryType.Tree) {
191
+ const found = this.findMetadataHolderSummary(value);
192
+ if (found) {
193
+ return found;
194
+ }
195
+ }
196
+ if (Boolean(value) && key === metadataBlobName && value.type === SummaryType.Blob) {
197
+ return summary;
198
+ }
199
+ }
200
+ return undefined;
201
+ }
202
+ /**
203
+ * This method obtains the summary tree containing the metadata blob. It returns the content
204
+ * of the tree atribute.
205
+ * @param summary - The summary tree to traverse.
206
+ * @returns - The content of the tree attribute of the summary tree containing the metadata blob.
207
+ */
208
+ static getMetadataHolderTree(summary) {
209
+ const metadataHolder = this.findMetadataHolderSummary(summary);
210
+ assert(metadataHolder !== undefined, 0x6f8 /* metadataHolder must be a non-null object */);
211
+ const metadataHolderTree = metadataHolder.tree;
212
+ return metadataHolderTree;
213
+ }
214
+ /**
215
+ * This method adds the compression markup blob to the nested summary tree containing the metadata blob.
216
+ * @param summary - The top summary tree to put the compression markup blob into.
217
+ */
218
+ static putCompressionMarkup(summary) {
219
+ const metadataHolderTree = DocumentStorageServiceCompressionAdapter.getMetadataHolderTree(summary);
220
+ metadataHolderTree[blobHeadersBlobName] = {
221
+ type: 2,
222
+ content: "",
223
+ };
224
+ }
225
+ /**
226
+ * This method traverses the SnapshotTree recursively. If it finds the ISummaryBlob object with the key '.metadata',
227
+ * it checks, if the SummaryTree holder of that object also contains the compression markup blob. If it is found,
228
+ * it returns true, otherwise false.
229
+ * @param snapshot - The snapshot tree to traverse.
230
+ * @returns - True if the compression markup blob is found, otherwise false.
231
+ */
232
+ static hasCompressionMarkup(snapshot) {
233
+ assert(typeof snapshot === "object", 0x6f9 /* snapshot must be a non-null object */);
234
+ for (const key of Object.keys(snapshot.blobs)) {
235
+ if (key === metadataBlobName) {
236
+ const value = snapshot.blobs[blobHeadersBlobName];
237
+ if (value !== undefined) {
238
+ return true;
239
+ }
240
+ }
241
+ }
242
+ for (const key of Object.keys(snapshot.trees)) {
243
+ const value = snapshot[key];
244
+ if (value !== undefined) {
245
+ const found = this.hasCompressionMarkup(value);
246
+ if (found) {
247
+ return found;
248
+ }
249
+ }
250
+ }
251
+ return false;
252
+ }
253
+ /**
254
+ * This method performs compression of the blobs in the summary tree.
255
+ * @param summary - The summary tree to compress.
256
+ * @param config - The compression config.
257
+ * @returns - The compressed summary tree.
258
+ */
259
+ static compressSummary(summary, config) {
260
+ this.putCompressionMarkup(summary);
261
+ const prep = DocumentStorageServiceCompressionAdapter.recursivelyReplace(true, summary, DocumentStorageServiceCompressionAdapter.blobEncoder, DocumentStorageServiceCompressionAdapter.blobDecoder, config);
262
+ // console.log(`Miso summary-blob Summary Upload: ${JSON.stringify(prep).length}`);
263
+ return prep;
264
+ }
265
+ /**
266
+ * This method read blob from the storage and decompresses it if it is compressed.
267
+ * @param id - The id of the blob to read.
268
+ * @returns - The decompressed blob.
269
+ */
270
+ async readBlob(id) {
271
+ const originalBlob = await super.readBlob(id);
272
+ if (!this._isCompressionEnabled) {
273
+ return originalBlob;
274
+ }
275
+ else {
276
+ const decompressedBlob = DocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);
277
+ // console.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);
278
+ return decompressedBlob;
279
+ }
280
+ }
281
+ /**
282
+ * This method loads the snapshot tree from the server. It also checks, if the compression markup blob is present
283
+ * and setups the compression flag accordingly. It also identifies the blobs that are not compressed and do not contain
284
+ * algorithm byte prefix and store them.
285
+ * @param version - The version of the snapshot tree to load.
286
+ * @param scenarioName - The scenario name of the snapshot tree to load.
287
+ * @returns - The snapshot tree.
288
+ */
289
+ async getSnapshotTree(version, scenarioName) {
290
+ const snapshotTree = await super.getSnapshotTree(version, scenarioName);
291
+ this._isCompressionEnabled =
292
+ snapshotTree !== undefined &&
293
+ snapshotTree !== null &&
294
+ DocumentStorageServiceCompressionAdapter.hasCompressionMarkup(snapshotTree);
295
+ return snapshotTree;
296
+ }
297
+ /**
298
+ * This method uploads the summary to the storage. It performs compression of the blobs in the summary tree.
299
+ * @param summary - The summary tree to upload.
300
+ * @param context - The summary context.
301
+ * @returns - The ID of the uploaded summary.
302
+ */
303
+ async uploadSummaryWithContext(summary, context) {
304
+ const prep = DocumentStorageServiceCompressionAdapter.compressSummary(summary, this._config);
305
+ return super.uploadSummaryWithContext(prep, context);
306
+ }
307
+ /**
308
+ * This method downloads the summary from the storage and then applies decompression on the compressed blobs.
309
+ * @param id - The ID of the summary to be downloaded
310
+ * @returns - The summary with decompressed blobs
311
+ */
312
+ async downloadSummary(id) {
313
+ const summary = await super.downloadSummary(id);
314
+ return !this._isCompressionEnabled
315
+ ? summary
316
+ : DocumentStorageServiceCompressionAdapter.recursivelyReplace(false, summary, DocumentStorageServiceCompressionAdapter.blobEncoder, DocumentStorageServiceCompressionAdapter.blobDecoder, this._config);
317
+ }
318
+ }
319
+ /**
320
+ * This method encodes the blob inside the given summary object of the SummaryType.Blob type using the given config
321
+ * containing the compression algorithm.
322
+ * @param input - The summary object to encode.
323
+ * @param config - The config containing the compression algorithm.
324
+ * @returns - The summary object with the encoded blob.
325
+ */
326
+ DocumentStorageServiceCompressionAdapter.blobEncoder = (input, config) => {
327
+ if (input.type === SummaryType.Blob) {
328
+ const summaryBlob = input;
329
+ const original = DocumentStorageServiceCompressionAdapter.toBinaryArray(summaryBlob.content);
330
+ const processed = DocumentStorageServiceCompressionAdapter.encodeBlob(original, config);
331
+ const newSummaryBlob = {
332
+ type: SummaryType.Blob,
333
+ content: IsoBuffer.from(processed),
334
+ };
335
+ return newSummaryBlob;
336
+ }
337
+ else {
338
+ return input;
339
+ }
340
+ };
341
+ /**
342
+ * This method decodes the blob inside the given summary object of the SummaryType.Blob type.
343
+ * @param input - The summary object to decode.
344
+ * @returns - The summary object with the decoded blob.
345
+ */
346
+ DocumentStorageServiceCompressionAdapter.blobDecoder = (input) => {
347
+ if (input.type === SummaryType.Blob) {
348
+ const summaryBlob = input;
349
+ const original = DocumentStorageServiceCompressionAdapter.toBinaryArray(summaryBlob.content);
350
+ const processed = DocumentStorageServiceCompressionAdapter.decodeBlob(original);
351
+ const newSummaryBlob = {
352
+ type: SummaryType.Blob,
353
+ content: IsoBuffer.from(processed),
354
+ };
355
+ return newSummaryBlob;
356
+ }
357
+ else {
358
+ return input;
359
+ }
360
+ };
361
+ //# sourceMappingURL=documentStorageServiceSummaryBlobCompressionAdapter.js.map