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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +38 -0
  3. package/dist/cache.js +2 -2
  4. package/dist/cache.js.map +1 -1
  5. package/dist/deltaStorageService.d.ts +1 -1
  6. package/dist/deltaStorageService.d.ts.map +1 -1
  7. package/dist/deltaStorageService.js +7 -4
  8. package/dist/deltaStorageService.js.map +1 -1
  9. package/dist/documentService.d.ts +4 -2
  10. package/dist/documentService.d.ts.map +1 -1
  11. package/dist/documentService.js +20 -12
  12. package/dist/documentService.js.map +1 -1
  13. package/dist/documentServiceFactory.d.ts +2 -2
  14. package/dist/documentServiceFactory.d.ts.map +1 -1
  15. package/dist/documentServiceFactory.js +21 -12
  16. package/dist/documentServiceFactory.js.map +1 -1
  17. package/dist/documentStorageService.d.ts +3 -2
  18. package/dist/documentStorageService.d.ts.map +1 -1
  19. package/dist/documentStorageService.js +4 -4
  20. package/dist/documentStorageService.js.map +1 -1
  21. package/dist/errorUtils.d.ts +9 -2
  22. package/dist/errorUtils.d.ts.map +1 -1
  23. package/dist/errorUtils.js +15 -8
  24. package/dist/errorUtils.js.map +1 -1
  25. package/dist/gitManager.d.ts +30 -0
  26. package/dist/gitManager.d.ts.map +1 -0
  27. package/dist/gitManager.js +89 -0
  28. package/dist/gitManager.js.map +1 -0
  29. package/dist/historian.d.ts +33 -0
  30. package/dist/historian.d.ts.map +1 -0
  31. package/dist/historian.js +65 -0
  32. package/dist/historian.js.map +1 -0
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +4 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/mapWithExpiration.d.ts +34 -0
  38. package/dist/mapWithExpiration.d.ts.map +1 -0
  39. package/dist/mapWithExpiration.js +105 -0
  40. package/dist/mapWithExpiration.js.map +1 -0
  41. package/dist/packageVersion.d.ts +1 -1
  42. package/dist/packageVersion.js +1 -1
  43. package/dist/packageVersion.js.map +1 -1
  44. package/dist/restWrapper.d.ts +21 -8
  45. package/dist/restWrapper.d.ts.map +1 -1
  46. package/dist/restWrapper.js +93 -25
  47. package/dist/restWrapper.js.map +1 -1
  48. package/dist/restWrapperBase.d.ts +26 -0
  49. package/dist/restWrapperBase.d.ts.map +1 -0
  50. package/dist/restWrapperBase.js +55 -0
  51. package/dist/restWrapperBase.js.map +1 -0
  52. package/dist/retriableGitManager.d.ts +10 -21
  53. package/dist/retriableGitManager.d.ts.map +1 -1
  54. package/dist/retriableGitManager.js +0 -36
  55. package/dist/retriableGitManager.js.map +1 -1
  56. package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
  57. package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
  58. package/dist/shreddedSummaryDocumentStorageService.js +6 -6
  59. package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
  60. package/dist/storageContracts.d.ts +44 -0
  61. package/dist/storageContracts.d.ts.map +1 -0
  62. package/dist/storageContracts.js +7 -0
  63. package/dist/storageContracts.js.map +1 -0
  64. package/dist/summaryTreeUploadManager.d.ts +23 -0
  65. package/dist/summaryTreeUploadManager.d.ts.map +1 -0
  66. package/dist/summaryTreeUploadManager.js +110 -0
  67. package/dist/summaryTreeUploadManager.js.map +1 -0
  68. package/dist/tokens.d.ts +24 -7
  69. package/dist/tokens.d.ts.map +1 -1
  70. package/dist/tokens.js.map +1 -1
  71. package/dist/treeUtils.d.ts +58 -0
  72. package/dist/treeUtils.d.ts.map +1 -0
  73. package/dist/treeUtils.js +107 -0
  74. package/dist/treeUtils.js.map +1 -0
  75. package/dist/wholeSummaryDocumentStorageService.d.ts +5 -4
  76. package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
  77. package/dist/wholeSummaryDocumentStorageService.js +70 -38
  78. package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
  79. package/dist/wholeSummaryUploadManager.d.ts +16 -0
  80. package/dist/wholeSummaryUploadManager.d.ts.map +1 -0
  81. package/dist/wholeSummaryUploadManager.js +38 -0
  82. package/dist/wholeSummaryUploadManager.js.map +1 -0
  83. package/lib/cache.js +1 -1
  84. package/lib/cache.js.map +1 -1
  85. package/lib/deltaStorageService.d.ts +1 -1
  86. package/lib/deltaStorageService.d.ts.map +1 -1
  87. package/lib/deltaStorageService.js +7 -4
  88. package/lib/deltaStorageService.js.map +1 -1
  89. package/lib/documentService.d.ts +4 -2
  90. package/lib/documentService.d.ts.map +1 -1
  91. package/lib/documentService.js +20 -12
  92. package/lib/documentService.js.map +1 -1
  93. package/lib/documentServiceFactory.d.ts +2 -2
  94. package/lib/documentServiceFactory.d.ts.map +1 -1
  95. package/lib/documentServiceFactory.js +22 -13
  96. package/lib/documentServiceFactory.js.map +1 -1
  97. package/lib/documentStorageService.d.ts +3 -2
  98. package/lib/documentStorageService.d.ts.map +1 -1
  99. package/lib/documentStorageService.js +4 -4
  100. package/lib/documentStorageService.js.map +1 -1
  101. package/lib/errorUtils.d.ts +9 -2
  102. package/lib/errorUtils.d.ts.map +1 -1
  103. package/lib/errorUtils.js +14 -7
  104. package/lib/errorUtils.js.map +1 -1
  105. package/lib/gitManager.d.ts +30 -0
  106. package/lib/gitManager.d.ts.map +1 -0
  107. package/lib/gitManager.js +85 -0
  108. package/lib/gitManager.js.map +1 -0
  109. package/lib/historian.d.ts +33 -0
  110. package/lib/historian.d.ts.map +1 -0
  111. package/lib/historian.js +60 -0
  112. package/lib/historian.js.map +1 -0
  113. package/lib/index.d.ts +1 -0
  114. package/lib/index.d.ts.map +1 -1
  115. package/lib/index.js +2 -0
  116. package/lib/index.js.map +1 -1
  117. package/lib/mapWithExpiration.d.ts +34 -0
  118. package/lib/mapWithExpiration.d.ts.map +1 -0
  119. package/lib/mapWithExpiration.js +101 -0
  120. package/lib/mapWithExpiration.js.map +1 -0
  121. package/lib/packageVersion.d.ts +1 -1
  122. package/lib/packageVersion.js +1 -1
  123. package/lib/packageVersion.js.map +1 -1
  124. package/lib/restWrapper.d.ts +21 -8
  125. package/lib/restWrapper.d.ts.map +1 -1
  126. package/lib/restWrapper.js +92 -26
  127. package/lib/restWrapper.js.map +1 -1
  128. package/lib/restWrapperBase.d.ts +26 -0
  129. package/lib/restWrapperBase.d.ts.map +1 -0
  130. package/lib/restWrapperBase.js +50 -0
  131. package/lib/restWrapperBase.js.map +1 -0
  132. package/lib/retriableGitManager.d.ts +10 -21
  133. package/lib/retriableGitManager.d.ts.map +1 -1
  134. package/lib/retriableGitManager.js +0 -36
  135. package/lib/retriableGitManager.js.map +1 -1
  136. package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
  137. package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
  138. package/lib/shreddedSummaryDocumentStorageService.js +5 -5
  139. package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
  140. package/lib/storageContracts.d.ts +44 -0
  141. package/lib/storageContracts.d.ts.map +1 -0
  142. package/lib/storageContracts.js +6 -0
  143. package/lib/storageContracts.js.map +1 -0
  144. package/lib/summaryTreeUploadManager.d.ts +23 -0
  145. package/lib/summaryTreeUploadManager.d.ts.map +1 -0
  146. package/lib/summaryTreeUploadManager.js +106 -0
  147. package/lib/summaryTreeUploadManager.js.map +1 -0
  148. package/lib/tokens.d.ts +24 -7
  149. package/lib/tokens.d.ts.map +1 -1
  150. package/lib/tokens.js.map +1 -1
  151. package/lib/treeUtils.d.ts +58 -0
  152. package/lib/treeUtils.d.ts.map +1 -0
  153. package/lib/treeUtils.js +100 -0
  154. package/lib/treeUtils.js.map +1 -0
  155. package/lib/wholeSummaryDocumentStorageService.d.ts +5 -4
  156. package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
  157. package/lib/wholeSummaryDocumentStorageService.js +70 -38
  158. package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
  159. package/lib/wholeSummaryUploadManager.d.ts +16 -0
  160. package/lib/wholeSummaryUploadManager.d.ts.map +1 -0
  161. package/lib/wholeSummaryUploadManager.js +34 -0
  162. package/lib/wholeSummaryUploadManager.js.map +1 -0
  163. package/package.json +52 -54
  164. package/src/cache.ts +1 -1
  165. package/src/deltaStorageService.ts +11 -3
  166. package/src/documentService.ts +37 -22
  167. package/src/documentServiceFactory.ts +40 -21
  168. package/src/documentStorageService.ts +8 -4
  169. package/src/errorUtils.ts +16 -4
  170. package/src/gitManager.ts +116 -0
  171. package/src/historian.ts +121 -0
  172. package/src/index.ts +3 -0
  173. package/src/mapWithExpiration.ts +124 -0
  174. package/src/packageVersion.ts +1 -1
  175. package/src/restWrapper.ts +114 -38
  176. package/src/restWrapperBase.ts +146 -0
  177. package/src/retriableGitManager.ts +17 -95
  178. package/src/shreddedSummaryDocumentStorageService.ts +7 -9
  179. package/src/storageContracts.ts +63 -0
  180. package/src/summaryTreeUploadManager.ts +160 -0
  181. package/src/tokens.ts +24 -7
  182. package/src/treeUtils.ts +137 -0
  183. package/src/wholeSummaryDocumentStorageService.ts +118 -46
  184. package/src/wholeSummaryUploadManager.ts +64 -0
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITokenClaims } from \"@fluidframework/protocol-definitions\";\n\n/**\n * The ITokenService abstracts the discovery of claims contained within a token\n */\nexport interface ITokenService {\n\textractClaims(token: string): ITokenClaims;\n}\n\nexport interface ITokenResponse {\n\t/**\n\t * {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} value.\n\t */\n\tjwt: string;\n\n\t/**\n\t * Flag indicating whether token was obtained from local cache.\n\t * Undefined indicates that the source of the token could not be determined.\n\t */\n\tfromCache?: boolean;\n}\n\n/**\n * Abstracts the token fetching mechanism for a hosting application.\n * The hosting application is responsible for providing an implementation.\n */\nexport interface ITokenProvider {\n\t/**\n\t * Fetches the orderer token from host.\n\t * @param tenantId - Tenant ID.\n\t * @param documentId - Optional. Document ID is only required for document-scoped requests.\n\t * @param refresh - Optional flag indicating whether token fetch must bypass local cache.\n\t * @returns TokenResponse object representing token value along with flag indicating\n\t * whether token came from cache.\n\t */\n\tfetchOrdererToken(\n\t\ttenantId: string,\n\t\tdocumentId?: string,\n\t\trefresh?: boolean,\n\t): Promise<ITokenResponse>;\n\n\t/**\n\t * Fetches the storage token from host.\n\t * @param tenantId - Tenant ID.\n\t * @param documentId - Document ID.\n\t * @param refresh - Optional flag indicating whether token fetch must bypass local cache.\n\t * @returns TokenResponse object representing token value along with flag indicating\n\t * whether token came from cache.\n\t */\n\tfetchStorageToken(\n\t\ttenantId: string,\n\t\tdocumentId: string,\n\t\trefresh?: boolean,\n\t): Promise<ITokenResponse>;\n\n\t/**\n\t * A callback triggered directly after creating the document. In this callback the client has the opportunity, to\n\t * verify against an authorization service, if the user who claims to create the document is the same user who\n\t * created it.\n\t *\n\t * @remarks Notes:\n\t * * Using the callback may have performance impact on the document creation process.\n\t * * Any exceptions thrown in the callback would fail the creation workflow\n\t * (see {@link RouterliciousDocumentServiceFactory.createContainer} for more details).\n\t *\n\t * @param documentId - Document ID.\n\t * @param creationToken - A special token that doesn't provide any kind of access, but it has the user's payload\n\t * and document id. It can be used to validate the identity of the document creator.\n\t */\n\tdocumentPostCreateCallback?(documentId: string, creationToken: string): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITokenClaims } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Abstracts the discovery of claims contained within a token.\n */\nexport interface ITokenService {\n\t/**\n\t * Extracts the {@link @fluidframework/protocol-definitions#ITokenClaims | token claims} from the provided\n\t * {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} string representation.\n\t */\n\textractClaims(token: string): ITokenClaims;\n}\n\nexport interface ITokenResponse {\n\t/**\n\t * {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} value.\n\t */\n\tjwt: string;\n\n\t/**\n\t * A flag indicating whether token was obtained from local cache.\n\t *\n\t * @remarks `undefined` indicates that the source of the token could not be determined.\n\t */\n\tfromCache?: boolean;\n}\n\n/**\n * Abstracts the token fetching mechanism for a hosting application.\n * The hosting application is responsible for providing an implementation.\n */\nexport interface ITokenProvider {\n\t/**\n\t * Fetches the orderer token from host.\n\t *\n\t * @param tenantId - Tenant ID.\n\t * @param documentId - Optional. Document ID is only required for document-scoped requests.\n\t * @param refresh - Optional flag indicating whether token fetch must bypass local cache.\n\t * This likely indicates that some previous request failed authorization due to an expired token,\n\t * and so a fresh token is required.\n\t *\n\t * Default: `false`.\n\t *\n\t * NOTE: This parameter will be made required in the future.\n\t */\n\tfetchOrdererToken(\n\t\ttenantId: string,\n\t\tdocumentId?: string,\n\t\trefresh?: boolean,\n\t): Promise<ITokenResponse>;\n\n\t/**\n\t * Fetches the storage token from host.\n\t *\n\t * @param tenantId - Tenant ID.\n\t * @param documentId - Document ID.\n\t * @param refresh - Optional flag indicating whether token fetch must bypass local cache.\n\t * This likely indicates that some previous request failed authorization due to an expired token,\n\t * and so a fresh token is required.\n\t *\n\t * Default: `false`.\n\t *\n\t * NOTE: This parameter will be made required in the future.\n\t */\n\tfetchStorageToken(\n\t\ttenantId: string,\n\t\tdocumentId: string,\n\t\trefresh?: boolean,\n\t): Promise<ITokenResponse>;\n\n\t/**\n\t * A callback triggered directly after creating the document. In this callback the client has the opportunity, to\n\t * verify against an authorization service, if the user who claims to create the document is the same user who\n\t * created it.\n\t *\n\t * @remarks Notes:\n\t *\n\t * * Using the callback may have performance impact on the document creation process.\n\t *\n\t * * Any exceptions thrown in the callback would fail the creation workflow\n\t * (see {@link RouterliciousDocumentServiceFactory.createContainer} for more details).\n\t *\n\t * @param documentId - Document ID.\n\t * @param creationToken - A special token that doesn't provide any kind of access, but it has the user's payload\n\t * and document id. It can be used to validate the identity of the document creator.\n\t */\n\tdocumentPostCreateCallback?(documentId: string, creationToken: string): Promise<void>;\n}\n"]}
@@ -0,0 +1,58 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { SummaryType, ISnapshotTree, ISummaryTree } from "@fluidframework/protocol-definitions";
6
+ import { INormalizedWholeSummary } from "@fluidframework/server-services-client";
7
+ /**
8
+ * Summary tree assembler props
9
+ */
10
+ export interface ISummaryTreeAssemblerProps {
11
+ /**
12
+ * Indicates that this tree is unreferenced. If this is not present, the tree is considered referenced.
13
+ */
14
+ unreferenced?: true;
15
+ }
16
+ /**
17
+ * Summary tree assembler (without stats collection).
18
+ */
19
+ export declare class SummaryTreeAssembler {
20
+ private readonly props?;
21
+ private attachmentCounter;
22
+ private readonly summaryTree;
23
+ constructor(props?: ISummaryTreeAssemblerProps | undefined);
24
+ /**
25
+ * Get final summary
26
+ */
27
+ get summary(): ISummaryTree;
28
+ /**
29
+ * Add blob to summary
30
+ */
31
+ addBlob(key: string, content: string | Uint8Array): void;
32
+ /**
33
+ * Add handle to summary
34
+ */
35
+ addHandle(key: string, handleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment, handle: string): void;
36
+ /**
37
+ * Add tree to summary
38
+ */
39
+ addTree(key: string, summary: ISummaryTree): void;
40
+ /**
41
+ * Add attachment to summary
42
+ */
43
+ addAttachment(id: string): void;
44
+ }
45
+ /**
46
+ * Helper function that converts ISnapshotTree and blobs to ISummaryTree
47
+ * @param snapshot - Source snapshot tree
48
+ * @param blobs - Blobs cache
49
+ * @returns Converted snapshot in ISummaryTree format
50
+ */
51
+ export declare function convertSnapshotAndBlobsToSummaryTree(snapshot: ISnapshotTree, blobs: Map<string, ArrayBuffer>): ISummaryTree;
52
+ export declare function evalBlobsAndTrees(snapshot: INormalizedWholeSummary): {
53
+ trees: number;
54
+ numBlobs: number;
55
+ encodedBlobsSize: number;
56
+ };
57
+ export declare function validateBlobsAndTrees(snapshot: ISnapshotTree): void;
58
+ //# sourceMappingURL=treeUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeUtils.d.ts","sourceRoot":"","sources":["../src/treeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,WAAW,EACX,aAAa,EACb,YAAY,EAEZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAIpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IAHnC,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyC;gBAExC,KAAK,CAAC,wCAA4B;IAE/D;;OAEG;IACH,IAAW,OAAO,IAAI,YAAY,CAMjC;IAED;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAO/D;;OAEG;IACI,SAAS,CACf,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,GAAG,WAAW,CAAC,UAAU,EACxE,MAAM,EAAE,MAAM,GACZ,IAAI;IAQP;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIxD;;OAEG;IACI,aAAa,CAAC,EAAE,EAAE,MAAM;CAG/B;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CACnD,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAC7B,YAAY,CAcd;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,uBAAuB;;;;EAQlE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,QAS5D"}
@@ -0,0 +1,107 @@
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.validateBlobsAndTrees = exports.evalBlobsAndTrees = exports.convertSnapshotAndBlobsToSummaryTree = exports.SummaryTreeAssembler = void 0;
8
+ const common_utils_1 = require("@fluidframework/common-utils");
9
+ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
10
+ /**
11
+ * Summary tree assembler (without stats collection).
12
+ */
13
+ class SummaryTreeAssembler {
14
+ constructor(props) {
15
+ this.props = props;
16
+ this.attachmentCounter = 0;
17
+ this.summaryTree = {};
18
+ }
19
+ /**
20
+ * Get final summary
21
+ */
22
+ get summary() {
23
+ var _a;
24
+ return {
25
+ type: protocol_definitions_1.SummaryType.Tree,
26
+ tree: Object.assign({}, this.summaryTree),
27
+ unreferenced: (_a = this.props) === null || _a === void 0 ? void 0 : _a.unreferenced,
28
+ };
29
+ }
30
+ /**
31
+ * Add blob to summary
32
+ */
33
+ addBlob(key, content) {
34
+ this.summaryTree[key] = {
35
+ type: protocol_definitions_1.SummaryType.Blob,
36
+ content,
37
+ };
38
+ }
39
+ /**
40
+ * Add handle to summary
41
+ */
42
+ addHandle(key, handleType, handle) {
43
+ this.summaryTree[key] = {
44
+ type: protocol_definitions_1.SummaryType.Handle,
45
+ handleType,
46
+ handle,
47
+ };
48
+ }
49
+ /**
50
+ * Add tree to summary
51
+ */
52
+ addTree(key, summary) {
53
+ this.summaryTree[key] = summary;
54
+ }
55
+ /**
56
+ * Add attachment to summary
57
+ */
58
+ addAttachment(id) {
59
+ this.summaryTree[this.attachmentCounter++] = { id, type: protocol_definitions_1.SummaryType.Attachment };
60
+ }
61
+ }
62
+ exports.SummaryTreeAssembler = SummaryTreeAssembler;
63
+ /**
64
+ * Helper function that converts ISnapshotTree and blobs to ISummaryTree
65
+ * @param snapshot - Source snapshot tree
66
+ * @param blobs - Blobs cache
67
+ * @returns Converted snapshot in ISummaryTree format
68
+ */
69
+ function convertSnapshotAndBlobsToSummaryTree(snapshot, blobs) {
70
+ const assembler = new SummaryTreeAssembler({
71
+ unreferenced: snapshot.unreferenced,
72
+ });
73
+ for (const [path, id] of Object.entries(snapshot.blobs)) {
74
+ const blob = blobs.get(id);
75
+ (0, common_utils_1.assert)(blob !== undefined, 0x2dd /* "Cannot find blob for a given id" */);
76
+ assembler.addBlob(path, common_utils_1.IsoBuffer.from(blob).toString("utf-8"));
77
+ }
78
+ for (const [key, tree] of Object.entries(snapshot.trees)) {
79
+ const subtree = convertSnapshotAndBlobsToSummaryTree(tree, blobs);
80
+ assembler.addTree(key, subtree);
81
+ }
82
+ return assembler.summary;
83
+ }
84
+ exports.convertSnapshotAndBlobsToSummaryTree = convertSnapshotAndBlobsToSummaryTree;
85
+ function evalBlobsAndTrees(snapshot) {
86
+ const trees = countTreesInSnapshotTree(snapshot.snapshotTree);
87
+ const numBlobs = snapshot.blobs.size;
88
+ let encodedBlobsSize = 0;
89
+ for (const [_, blobContent] of snapshot.blobs) {
90
+ encodedBlobsSize += blobContent.byteLength;
91
+ }
92
+ return { trees, numBlobs, encodedBlobsSize };
93
+ }
94
+ exports.evalBlobsAndTrees = evalBlobsAndTrees;
95
+ function validateBlobsAndTrees(snapshot) {
96
+ (0, common_utils_1.assert)(snapshot.trees !== undefined, 0x5d0 /* Returned r11s snapshot is malformed. No trees! */);
97
+ (0, common_utils_1.assert)(snapshot.blobs !== undefined, 0x5d1 /* Returned r11s snapshot is malformed. No blobs! */);
98
+ }
99
+ exports.validateBlobsAndTrees = validateBlobsAndTrees;
100
+ function countTreesInSnapshotTree(snapshotTree) {
101
+ let numTrees = 0;
102
+ for (const [_, tree] of Object.entries(snapshotTree.trees)) {
103
+ numTrees += 1 + countTreesInSnapshotTree(tree);
104
+ }
105
+ return numTrees;
106
+ }
107
+ //# sourceMappingURL=treeUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeUtils.js","sourceRoot":"","sources":["../src/treeUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,+EAK8C;AAa9C;;GAEG;AACH,MAAa,oBAAoB;IAIhC,YAA6B,KAAkC;QAAlC,UAAK,GAAL,KAAK,CAA6B;QAHvD,sBAAiB,GAAW,CAAC,CAAC;QACrB,gBAAW,GAAsC,EAAE,CAAC;IAEH,CAAC;IAEnE;;OAEG;IACH,IAAW,OAAO;;QACjB,OAAO;YACN,IAAI,EAAE,kCAAW,CAAC,IAAI;YACtB,IAAI,oBAAO,IAAI,CAAC,WAAW,CAAE;YAC7B,YAAY,EAAE,MAAA,IAAI,CAAC,KAAK,0CAAE,YAAY;SACtC,CAAC;IACH,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,GAAW,EAAE,OAA4B;QACvD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG;YACvB,IAAI,EAAE,kCAAW,CAAC,IAAI;YACtB,OAAO;SACP,CAAC;IACH,CAAC;IAED;;OAEG;IACI,SAAS,CACf,GAAW,EACX,UAAwE,EACxE,MAAc;QAEd,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG;YACvB,IAAI,EAAE,kCAAW,CAAC,MAAM;YACxB,UAAU;YACV,MAAM;SACN,CAAC;IACH,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,GAAW,EAAE,OAAqB;QAChD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,aAAa,CAAC,EAAU;QAC9B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI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AAI,WAAW,CAAC,UAAU,CAAC;KAC3C;IACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;AAC9C,CAAC;AARD,8CAQC;AAED,SAAgB,qBAAqB,CAAC,QAAuB;IAC5D,IAAA,qBAAM,EACL,QAAQ,CAAC,KAAK,KAAK,SAAS,EAC5B,KAAK,CAAC,oDAAoD,CAC1D,CAAC;IACF,IAAA,qBAAM,EACL,QAAQ,CAAC,KAAK,KAAK,SAAS,EAC5B,KAAK,CAAC,oDAAoD,CAC1D,CAAC;AACH,CAAC;AATD,sDASC;AAED,SAAS,wBAAwB,CAAC,YAA2B;IAC5D,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QAC3D,QAAQ,IAAI,CAAC,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;KAC/C;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, IsoBuffer } from \"@fluidframework/common-utils\";\nimport {\n\tSummaryType,\n\tISnapshotTree,\n\tISummaryTree,\n\tSummaryObject,\n} from \"@fluidframework/protocol-definitions\";\nimport { INormalizedWholeSummary } from \"@fluidframework/server-services-client\";\n\n/**\n * Summary tree assembler props\n */\nexport interface ISummaryTreeAssemblerProps {\n\t/**\n\t * Indicates that this tree is unreferenced. If this is not present, the tree is considered referenced.\n\t */\n\tunreferenced?: true;\n}\n\n/**\n * Summary tree assembler (without stats collection).\n */\nexport class SummaryTreeAssembler {\n\tprivate attachmentCounter: number = 0;\n\tprivate readonly summaryTree: { [path: string]: SummaryObject } = {};\n\n\tconstructor(private readonly props?: ISummaryTreeAssemblerProps) {}\n\n\t/**\n\t * Get final summary\n\t */\n\tpublic get summary(): ISummaryTree {\n\t\treturn {\n\t\t\ttype: SummaryType.Tree,\n\t\t\ttree: { ...this.summaryTree },\n\t\t\tunreferenced: this.props?.unreferenced,\n\t\t};\n\t}\n\n\t/**\n\t * Add blob to summary\n\t */\n\tpublic addBlob(key: string, content: string | Uint8Array): void {\n\t\tthis.summaryTree[key] = {\n\t\t\ttype: SummaryType.Blob,\n\t\t\tcontent,\n\t\t};\n\t}\n\n\t/**\n\t * Add handle to summary\n\t */\n\tpublic addHandle(\n\t\tkey: string,\n\t\thandleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment,\n\t\thandle: string,\n\t): void {\n\t\tthis.summaryTree[key] = {\n\t\t\ttype: SummaryType.Handle,\n\t\t\thandleType,\n\t\t\thandle,\n\t\t};\n\t}\n\n\t/**\n\t * Add tree to summary\n\t */\n\tpublic addTree(key: string, summary: ISummaryTree): void {\n\t\tthis.summaryTree[key] = summary;\n\t}\n\n\t/**\n\t * Add attachment to summary\n\t */\n\tpublic addAttachment(id: string) {\n\t\tthis.summaryTree[this.attachmentCounter++] = { id, type: SummaryType.Attachment };\n\t}\n}\n\n/**\n * Helper function that converts ISnapshotTree and blobs to ISummaryTree\n * @param snapshot - Source snapshot tree\n * @param blobs - Blobs cache\n * @returns Converted snapshot in ISummaryTree format\n */\nexport function convertSnapshotAndBlobsToSummaryTree(\n\tsnapshot: ISnapshotTree,\n\tblobs: Map<string, ArrayBuffer>,\n): ISummaryTree {\n\tconst assembler = new SummaryTreeAssembler({\n\t\tunreferenced: snapshot.unreferenced,\n\t});\n\tfor (const [path, id] of Object.entries(snapshot.blobs)) {\n\t\tconst blob = blobs.get(id);\n\t\tassert(blob !== undefined, 0x2dd /* \"Cannot find blob for a given id\" */);\n\t\tassembler.addBlob(path, IsoBuffer.from(blob).toString(\"utf-8\"));\n\t}\n\tfor (const [key, tree] of Object.entries(snapshot.trees)) {\n\t\tconst subtree = convertSnapshotAndBlobsToSummaryTree(tree, blobs);\n\t\tassembler.addTree(key, subtree);\n\t}\n\treturn assembler.summary;\n}\n\nexport function evalBlobsAndTrees(snapshot: INormalizedWholeSummary) {\n\tconst trees = countTreesInSnapshotTree(snapshot.snapshotTree);\n\tconst numBlobs = snapshot.blobs.size;\n\tlet encodedBlobsSize = 0;\n\tfor (const [_, blobContent] of snapshot.blobs) {\n\t\tencodedBlobsSize += blobContent.byteLength;\n\t}\n\treturn { trees, numBlobs, encodedBlobsSize };\n}\n\nexport function validateBlobsAndTrees(snapshot: ISnapshotTree) {\n\tassert(\n\t\tsnapshot.trees !== undefined,\n\t\t0x5d0 /* Returned r11s snapshot is malformed. No trees! */,\n\t);\n\tassert(\n\t\tsnapshot.blobs !== undefined,\n\t\t0x5d1 /* Returned r11s snapshot is malformed. No blobs! */,\n\t);\n}\n\nfunction countTreesInSnapshotTree(snapshotTree: ISnapshotTree): number {\n\tlet numTrees = 0;\n\tfor (const [_, tree] of Object.entries(snapshotTree.trees)) {\n\t\tnumTrees += 1 + countTreesInSnapshotTree(tree);\n\t}\n\treturn numTrees;\n}\n"]}
@@ -5,10 +5,10 @@
5
5
  import type { ITelemetryLogger } from "@fluidframework/common-definitions";
6
6
  import { IDocumentStorageService, ISummaryContext, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
7
7
  import { ICreateBlobResponse, ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
8
- import { GitManager } from "@fluidframework/server-services-client";
8
+ import { INormalizedWholeSummary } from "@fluidframework/server-services-client";
9
9
  import { ICache } from "./cache";
10
- import { ISnapshotTreeVersion } from "./definitions";
11
10
  import { IRouterliciousDriverPolicies } from "./policies";
11
+ import { GitManager } from "./gitManager";
12
12
  export declare class WholeSummaryDocumentStorageService implements IDocumentStorageService {
13
13
  protected readonly id: string;
14
14
  protected readonly manager: GitManager;
@@ -22,14 +22,15 @@ export declare class WholeSummaryDocumentStorageService implements IDocumentStor
22
22
  private firstVersionsCall;
23
23
  get repositoryUrl(): string;
24
24
  private getSummaryUploadManager;
25
- constructor(id: string, manager: GitManager, logger: ITelemetryLogger, policies: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies | undefined, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<ISnapshotTreeVersion>, noCacheGitManager?: GitManager | undefined, getStorageManager?: (disableCache?: boolean) => Promise<GitManager>);
25
+ constructor(id: string, manager: GitManager, logger: ITelemetryLogger, policies: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies | undefined, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<INormalizedWholeSummary>, noCacheGitManager?: GitManager | undefined, getStorageManager?: (disableCache?: boolean) => Promise<GitManager>);
26
26
  getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
27
27
  getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null>;
28
28
  readBlob(blobId: string): Promise<ArrayBufferLike>;
29
29
  uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
30
30
  downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree>;
31
31
  createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
32
- private fetchAndCacheSnapshotTree;
32
+ private fetchSnapshotTree;
33
+ private initializeFromSnapshot;
33
34
  private initBlobCache;
34
35
  private getCacheKey;
35
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wholeSummaryDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,OAAO,EACN,uBAAuB,EACvB,eAAe,EACf,+BAA+B,EAC/B,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEN,UAAU,EAGV,MAAM,wCAAwC,CAA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ClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IApBnC,OAAO,CAAC,iBAAiB,CAAiB;IAE1C,IAAW,aAAa,IAAI,MAAM,CAEjC;YAEa,uBAAuB;gBAMjB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,+BAA+B,EACxC,cAAc,CAAC,0CAA8B,EAC7C,SAAS,GAAE,MAAM,CAAC,eAAe,CAAuB,EACxD,iBAAiB,GAAE,MAAM,CAAC,uBAAuB,CAAuB,EACxE,iBAAiB,CAAC,wBAAY,EAC9B,iBAAiB,GAAE,CACnC,YAAY,CAAC,EAAE,OAAO,KAClB,OAAO,CAAC,UAAU,CAGP;IAGJ,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IA4FzE,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAoBlE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA4BlD,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IAqBL,eAAe,CAAC,aAAa,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAwBrE,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAqB9D,iBAAiB;YAsCjB,sBAAsB;YA4BtB,aAAa;IAS3B,OAAO,CAAC,WAAW;CAGnB"}
@@ -6,10 +6,12 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.WholeSummaryDocumentStorageService = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
- const driver_utils_1 = require("@fluidframework/driver-utils");
9
+ const driver_base_1 = require("@fluidframework/driver-base");
10
10
  const server_services_client_1 = require("@fluidframework/server-services-client");
11
11
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
12
12
  const cache_1 = require("./cache");
13
+ const treeUtils_1 = require("./treeUtils");
14
+ const wholeSummaryUploadManager_1 = require("./wholeSummaryUploadManager");
13
15
  const latestSnapshotId = "latest";
14
16
  class WholeSummaryDocumentStorageService {
15
17
  constructor(id, manager, logger, policies, driverPolicies, blobCache = new cache_1.InMemoryCache(), snapshotTreeCache = new cache_1.InMemoryCache(), noCacheGitManager, getStorageManager = async (disableCache) => disableCache && this.noCacheGitManager !== undefined
@@ -31,7 +33,7 @@ class WholeSummaryDocumentStorageService {
31
33
  }
32
34
  async getSummaryUploadManager() {
33
35
  const manager = await this.getStorageManager();
34
- return new server_services_client_1.WholeSummaryUploadManager(manager);
36
+ return new wholeSummaryUploadManager_1.WholeSummaryUploadManager(manager);
35
37
  }
36
38
  async getVersions(versionId, count) {
37
39
  var _a;
@@ -47,14 +49,47 @@ class WholeSummaryDocumentStorageService {
47
49
  // If this is the first versions call for the document, we know we will want the latest summary.
48
50
  // Fetch latest summary, cache it, and return its id.
49
51
  if (this.firstVersionsCall && count === 1) {
52
+ const normalizedSnapshotContents = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
53
+ eventName: "ObtainSnapshot",
54
+ versionId: versionId !== null && versionId !== void 0 ? versionId : undefined,
55
+ count,
56
+ enableDiscovery: (_a = this.driverPolicies) === null || _a === void 0 ? void 0 : _a.enableDiscovery,
57
+ }, async (event) => {
58
+ var _a;
59
+ let method;
60
+ const cachedSnapshotP = this.snapshotTreeCache.get(this.getCacheKey(latestSnapshotId));
61
+ const networkSnapshotP = !((_a = this.driverPolicies) === null || _a === void 0 ? void 0 : _a.enableDiscovery)
62
+ ? this.fetchSnapshotTree(latestSnapshotId, false)
63
+ : this.fetchSnapshotTree(latestSnapshotId, true);
64
+ const promiseRaceWinner = await (0, driver_base_1.promiseRaceWithWinner)([
65
+ cachedSnapshotP.catch(() => undefined),
66
+ networkSnapshotP.catch(() => undefined),
67
+ ]);
68
+ let retrievedSnapshot = promiseRaceWinner.value;
69
+ method = promiseRaceWinner.index === 0 ? "cache" : "network";
70
+ if (retrievedSnapshot === undefined) {
71
+ // if network failed -> wait for cache ( then return network failure)
72
+ // If cache returned empty or failed -> wait for network (success of failure)
73
+ if (promiseRaceWinner.index === 1) {
74
+ retrievedSnapshot = await cachedSnapshotP;
75
+ method = "cache";
76
+ }
77
+ if (retrievedSnapshot === undefined) {
78
+ retrievedSnapshot = await networkSnapshotP;
79
+ method = "network";
80
+ }
81
+ }
82
+ event.end({
83
+ method,
84
+ });
85
+ return retrievedSnapshot;
86
+ });
87
+ const _id = await this.initializeFromSnapshot(normalizedSnapshotContents, latestSnapshotId);
50
88
  this.firstVersionsCall = false;
51
- const { id: _id, snapshotTree } = !((_a = this.driverPolicies) === null || _a === void 0 ? void 0 : _a.enableDiscovery)
52
- ? await this.fetchAndCacheSnapshotTree(latestSnapshotId, false)
53
- : await this.fetchAndCacheSnapshotTree(latestSnapshotId, true);
54
89
  return [
55
90
  {
56
91
  id: _id,
57
- treeId: snapshotTree.id,
92
+ treeId: normalizedSnapshotContents.snapshotTree.id,
58
93
  },
59
94
  ];
60
95
  }
@@ -66,7 +101,7 @@ class WholeSummaryDocumentStorageService {
66
101
  count,
67
102
  }, async () => {
68
103
  const manager = await this.getStorageManager();
69
- return manager.getCommits(id, count);
104
+ return (await manager.getCommits(id, count)).content;
70
105
  });
71
106
  return commits.map((commit) => ({
72
107
  date: commit.commit.author.date,
@@ -83,7 +118,11 @@ class WholeSummaryDocumentStorageService {
83
118
  }
84
119
  requestVersion = versions[0];
85
120
  }
86
- return (await this.fetchAndCacheSnapshotTree(requestVersion.id)).snapshotTree;
121
+ const normalizedWholeSnapshot = await this.snapshotTreeCache.get(this.getCacheKey(requestVersion.id));
122
+ if (normalizedWholeSnapshot !== undefined) {
123
+ return normalizedWholeSnapshot.snapshotTree;
124
+ }
125
+ return (await this.fetchSnapshotTree(requestVersion.id)).snapshotTree;
87
126
  }
88
127
  async readBlob(blobId) {
89
128
  const cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));
@@ -95,7 +134,7 @@ class WholeSummaryDocumentStorageService {
95
134
  blobId,
96
135
  }, async (event) => {
97
136
  const manager = await this.getStorageManager();
98
- const response = await manager.getBlob(blobId);
137
+ const response = (await manager.getBlob(blobId)).content;
99
138
  event.end({
100
139
  size: response.size,
101
140
  });
@@ -127,12 +166,12 @@ class WholeSummaryDocumentStorageService {
127
166
  const manager = await this.getStorageManager();
128
167
  const response = await manager.getSummary(summaryHandle.handle);
129
168
  event.end({
130
- size: (_a = response.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length,
169
+ size: (_a = response.content.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length,
131
170
  });
132
- return response;
171
+ return response.content;
133
172
  });
134
173
  const { blobs, snapshotTree } = (0, server_services_client_1.convertWholeFlatSummaryToSnapshotTreeAndBlobs)(wholeFlatSummary, "");
135
- return (0, driver_utils_1.convertSnapshotAndBlobsToSummaryTree)(snapshotTree, blobs);
174
+ return (0, treeUtils_1.convertSnapshotAndBlobsToSummaryTree)(snapshotTree, blobs);
136
175
  }
137
176
  async createBlob(file) {
138
177
  const uint8ArrayFile = new Uint8Array(file);
@@ -143,54 +182,47 @@ class WholeSummaryDocumentStorageService {
143
182
  const manager = await this.getStorageManager();
144
183
  const response = await manager
145
184
  .createBlob((0, common_utils_1.Uint8ArrayToString)(uint8ArrayFile, "base64"), "base64")
146
- .then((r) => ({ id: r.sha, url: r.url }));
185
+ .then((r) => ({ id: r.content.sha, url: r.content.url }));
147
186
  event.end({
148
187
  blobId: response.id,
149
188
  });
150
189
  return response;
151
190
  });
152
191
  }
153
- async fetchAndCacheSnapshotTree(versionId, disableCache) {
154
- const cachedSnapshotTreeVersion = await this.snapshotTreeCache.get(this.getCacheKey(versionId));
155
- if (cachedSnapshotTreeVersion !== undefined) {
156
- return {
157
- id: cachedSnapshotTreeVersion.id,
158
- snapshotTree: cachedSnapshotTreeVersion.snapshotTree,
159
- };
160
- }
161
- const wholeFlatSummary = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
192
+ async fetchSnapshotTree(versionId, disableCache) {
193
+ const normalizedWholeSummary = await telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
162
194
  eventName: "getWholeFlatSummary",
163
195
  treeId: versionId,
164
196
  }, async (event) => {
165
197
  var _a;
166
198
  const manager = await this.getStorageManager(disableCache);
167
199
  const response = await manager.getSummary(versionId);
168
- event.end({
169
- size: (_a = response.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length,
170
- });
171
- return response;
200
+ const start = common_utils_1.performance.now();
201
+ const snapshot = (0, server_services_client_1.convertWholeFlatSummaryToSnapshotTreeAndBlobs)(response.content);
202
+ const snapshotConversionTime = common_utils_1.performance.now() - start;
203
+ (0, treeUtils_1.validateBlobsAndTrees)(snapshot.snapshotTree);
204
+ const { trees, numBlobs, encodedBlobsSize } = (0, treeUtils_1.evalBlobsAndTrees)(snapshot);
205
+ event.end(Object.assign(Object.assign(Object.assign({ size: (_a = response.content.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length, trees, blobs: numBlobs, encodedBlobsSize }, response.propsToLog), { snapshotConversionTime }), (0, driver_base_1.getW3CData)(response.requestUrl, "xmlhttprequest")));
206
+ return snapshot;
172
207
  });
173
- const normalizedWholeSummary = (0, server_services_client_1.convertWholeFlatSummaryToSnapshotTreeAndBlobs)(wholeFlatSummary);
174
- const wholeFlatSummaryId = wholeFlatSummary.id;
175
- const snapshotTreeId = normalizedWholeSummary.snapshotTree.id;
176
- (0, common_utils_1.assert)(snapshotTreeId !== undefined, 0x275 /* "Root tree should contain the id" */);
177
- const snapshotTreeVersion = {
178
- id: wholeFlatSummaryId,
179
- snapshotTree: normalizedWholeSummary.snapshotTree,
180
- };
208
+ return normalizedWholeSummary;
209
+ }
210
+ async initializeFromSnapshot(normalizedWholeSummary, versionId) {
211
+ const wholeFlatSummaryId = normalizedWholeSummary.snapshotTree.id;
212
+ (0, common_utils_1.assert)(wholeFlatSummaryId !== undefined, 0x275 /* "Root tree should contain the id" */);
181
213
  const cachePs = [
182
- this.snapshotTreeCache.put(this.getCacheKey(snapshotTreeId), snapshotTreeVersion),
214
+ this.snapshotTreeCache.put(this.getCacheKey(wholeFlatSummaryId), normalizedWholeSummary),
183
215
  this.initBlobCache(normalizedWholeSummary.blobs),
184
216
  ];
185
- if (snapshotTreeId !== versionId) {
217
+ if (wholeFlatSummaryId !== versionId && versionId !== null) {
186
218
  // versionId could be "latest". When summarizer checks cache for "latest", we want it to be available.
187
219
  // TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,
188
220
  // However, for something like Redis, this will cache the same value twice. Alternatively, could we simply
189
221
  // cache with versionId?
190
- cachePs.push(this.snapshotTreeCache.put(this.getCacheKey(versionId), snapshotTreeVersion));
222
+ cachePs.push(this.snapshotTreeCache.put(this.getCacheKey(versionId), normalizedWholeSummary));
191
223
  }
192
224
  await Promise.all(cachePs);
193
- return snapshotTreeVersion;
225
+ return wholeFlatSummaryId;
194
226
  }
195
227
  async initBlobCache(blobs) {
196
228
  const blobCachePutPs = [];
@@ -1 +1 @@
1
- {"version":3,"file":"wholeSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA0F;AAM1F,+DAAoF;AAQpF,mFAKgD;AAChD,qEAAmE;AACnE,mCAAgD;AAIhD,MAAM,gBAAgB,GAAW,QAAQ,CAAC;AAE1C,MAAa,kCAAkC;IAY9C,YACoB,EAAU,EACV,OAAmB,EACnB,MAAwB,EAC3B,QAAyC,EACxC,cAA6C,EAC7C,YAAqC,IAAI,qBAAa,EAAE,EACxD,oBAAkD,IAAI,qBAAa,EAAE,EAC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AAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACtC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD;AAhQD,gFAgQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, stringToBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport { convertSnapshotAndBlobsToSummaryTree } from \"@fluidframework/driver-utils\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs,\n\tGitManager,\n\tISummaryUploadManager,\n\tWholeSummaryUploadManager,\n} from \"@fluidframework/server-services-client\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { ISnapshotTreeVersion } from \"./definitions\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate firstVersionsCall: boolean = true;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new WholeSummaryUploadManager(manager);\n\t}\n\n\tconstructor(\n\t\tprotected readonly id: string,\n\t\tprotected readonly manager: GitManager,\n\t\tprotected readonly logger: ITelemetryLogger,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies?: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),\n\t\tprivate readonly snapshotTreeCache: ICache<ISnapshotTreeVersion> = new InMemoryCache(),\n\t\tprivate readonly noCacheGitManager?: GitManager,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async (disableCache) =>\n\t\t\tdisableCache && this.noCacheGitManager !== undefined\n\t\t\t\t? this.noCacheGitManager\n\t\t\t\t: this.manager,\n\t) {}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId !== this.id && versionId !== null) {\n\t\t\t// Blobs/Trees in this scenario will never have multiple versions, so return versionId as is\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: undefined!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\t// If this is the first versions call for the document, we know we will want the latest summary.\n\t\t// Fetch latest summary, cache it, and return its id.\n\t\tif (this.firstVersionsCall && count === 1) {\n\t\t\tthis.firstVersionsCall = false;\n\t\t\tconst { id: _id, snapshotTree } = !this.driverPolicies?.enableDiscovery\n\t\t\t\t? await this.fetchAndCacheSnapshotTree(latestSnapshotId, false)\n\t\t\t\t: await this.fetchAndCacheSnapshotTree(latestSnapshotId, true);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: _id,\n\t\t\t\t\ttreeId: snapshotTree.id!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// Otherwise, get the latest version of the document as normal.\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getVersions\",\n\t\t\t\tversionId: id,\n\t\t\t\tcount,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\treturn manager.getCommits(id, count);\n\t\t\t},\n\t\t);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\treturn (await this.fetchAndCacheSnapshotTree(requestVersion.id)).snapshotTree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));\n\t\tif (cachedBlob !== undefined) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\tconst blob = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"readBlob\",\n\t\t\t\tblobId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager.getBlob(blobId);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.size,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t\tconst bufferValue = stringToBuffer(blob.content, blob.encoding);\n\n\t\tawait this.blobCache.put(this.getCacheKey(blob.sha), bufferValue);\n\n\t\treturn bufferValue;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst summaryHandle = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"uploadSummaryWithContext\",\n\t\t\t\tproposalHandle: context.proposalHandle,\n\t\t\t\tackHandle: context.ackHandle,\n\t\t\t\treferenceSequenceNumber: context.referenceSequenceNumber,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryUploadManager = await this.getSummaryUploadManager();\n\t\t\t\treturn summaryUploadManager.writeSummaryTree(\n\t\t\t\t\tsummary,\n\t\t\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\t\t\"channel\",\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t\treturn summaryHandle;\n\t}\n\n\tpublic async downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst wholeFlatSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: summaryHandle.handle,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager.getSummary(summaryHandle.handle);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\n\t\tconst { blobs, snapshotTree } = convertWholeFlatSummaryToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSummary,\n\t\t\t\"\",\n\t\t);\n\t\treturn convertSnapshotAndBlobsToSummaryTree(snapshotTree, blobs);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"createBlob\",\n\t\t\t\tsize: uint8ArrayFile.length,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager\n\t\t\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t\t\t.then((r) => ({ id: r.sha, url: r.url }));\n\t\t\t\tevent.end({\n\t\t\t\t\tblobId: response.id,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async fetchAndCacheSnapshotTree(\n\t\tversionId: string,\n\t\tdisableCache?: boolean,\n\t): Promise<ISnapshotTreeVersion> {\n\t\tconst cachedSnapshotTreeVersion = await this.snapshotTreeCache.get(\n\t\t\tthis.getCacheKey(versionId),\n\t\t);\n\t\tif (cachedSnapshotTreeVersion !== undefined) {\n\t\t\treturn {\n\t\t\t\tid: cachedSnapshotTreeVersion.id,\n\t\t\t\tsnapshotTree: cachedSnapshotTreeVersion.snapshotTree,\n\t\t\t};\n\t\t}\n\n\t\tconst wholeFlatSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: versionId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager(disableCache);\n\t\t\t\tconst response = await manager.getSummary(versionId);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t\tconst normalizedWholeSummary =\n\t\t\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs(wholeFlatSummary);\n\t\tconst wholeFlatSummaryId: string = wholeFlatSummary.id;\n\t\tconst snapshotTreeId = normalizedWholeSummary.snapshotTree.id;\n\t\tassert(snapshotTreeId !== undefined, 0x275 /* \"Root tree should contain the id\" */);\n\t\tconst snapshotTreeVersion = {\n\t\t\tid: wholeFlatSummaryId,\n\t\t\tsnapshotTree: normalizedWholeSummary.snapshotTree,\n\t\t};\n\n\t\tconst cachePs: Promise<any>[] = [\n\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(snapshotTreeId), snapshotTreeVersion),\n\t\t\tthis.initBlobCache(normalizedWholeSummary.blobs),\n\t\t];\n\t\tif (snapshotTreeId !== versionId) {\n\t\t\t// versionId could be \"latest\". When summarizer checks cache for \"latest\", we want it to be available.\n\t\t\t// TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,\n\t\t\t// However, for something like Redis, this will cache the same value twice. Alternatively, could we simply\n\t\t\t// cache with versionId?\n\t\t\tcachePs.push(\n\t\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(versionId), snapshotTreeVersion),\n\t\t\t);\n\t\t}\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn snapshotTreeVersion;\n\t}\n\n\tprivate async initBlobCache(blobs: Map<string, ArrayBuffer>): Promise<void> {\n\t\tconst blobCachePutPs: Promise<void>[] = [];\n\t\tblobs.forEach((value, id) => {\n\t\t\tconst cacheKey = this.getCacheKey(id);\n\t\t\tblobCachePutPs.push(this.blobCache.put(cacheKey, value));\n\t\t});\n\t\tawait Promise.all(blobCachePutPs);\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"wholeSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAKsC;AACtC,6DAAgF;AAahF,mFAIgD;AAChD,qEAAmE;AACnE,mCAAgD;AAEhD,2CAIqB;AAErB,2EAAwE;AAIxE,MAAM,gBAAgB,GAAW,QAAQ,CAAC;AAE1C,MAAa,kCAAkC;IAY9C,YACoB,EAAU,EACV,OAAmB,EACnB,MAAwB,EAC3B,QAAyC,EACxC,cAA6C,EAC7C,YAAqC,IAAI,qBAAa,EAAE,EACxD,oBAAqD,IAAI,qBAAa,EAAE,EACxE,iBAA8B,EAC9B,oBAEU,KAAK,EAAE,YAAY,E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AAkB,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE;YAC3D,sGAAsG;YACtG,4GAA4G;YAC5G,0GAA0G;YAC1G,wBAAwB;YACxB,OAAO,CAAC,IAAI,CACX,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAC,CAC/E,CAAC;SACF;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3B,OAAO,kBAAkB,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,KAA+B;QAC1D,MAAM,cAAc,GAAoB,EAAE,CAAC;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACtC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD;AA5TD,gFA4TC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n\tassert,\n\tperformance,\n\tstringToBuffer,\n\tUint8ArrayToString,\n} from \"@fluidframework/common-utils\";\nimport { getW3CData, promiseRaceWithWinner } from \"@fluidframework/driver-base\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs,\n\tINormalizedWholeSummary,\n\tIWholeFlatSummary,\n} from \"@fluidframework/server-services-client\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport {\n\tconvertSnapshotAndBlobsToSummaryTree,\n\tevalBlobsAndTrees,\n\tvalidateBlobsAndTrees,\n} from \"./treeUtils\";\nimport { GitManager } from \"./gitManager\";\nimport { WholeSummaryUploadManager } from \"./wholeSummaryUploadManager\";\nimport { ISummaryUploadManager } from \"./storageContracts\";\nimport { IR11sResponse } from \"./restWrapper\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate firstVersionsCall: boolean = true;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new WholeSummaryUploadManager(manager);\n\t}\n\n\tconstructor(\n\t\tprotected readonly id: string,\n\t\tprotected readonly manager: GitManager,\n\t\tprotected readonly logger: ITelemetryLogger,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies?: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),\n\t\tprivate readonly snapshotTreeCache: ICache<INormalizedWholeSummary> = new InMemoryCache(),\n\t\tprivate readonly noCacheGitManager?: GitManager,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async (disableCache) =>\n\t\t\tdisableCache && this.noCacheGitManager !== undefined\n\t\t\t\t? this.noCacheGitManager\n\t\t\t\t: this.manager,\n\t) {}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId !== this.id && versionId !== null) {\n\t\t\t// Blobs/Trees in this scenario will never have multiple versions, so return versionId as is\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: undefined!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\t// If this is the first versions call for the document, we know we will want the latest summary.\n\t\t// Fetch latest summary, cache it, and return its id.\n\t\tif (this.firstVersionsCall && count === 1) {\n\t\t\tconst normalizedSnapshotContents = await PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"ObtainSnapshot\",\n\t\t\t\t\tversionId: versionId ?? undefined,\n\t\t\t\t\tcount,\n\t\t\t\t\tenableDiscovery: this.driverPolicies?.enableDiscovery,\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tlet method: string;\n\t\t\t\t\tconst cachedSnapshotP = this.snapshotTreeCache.get(\n\t\t\t\t\t\tthis.getCacheKey(latestSnapshotId),\n\t\t\t\t\t);\n\n\t\t\t\t\tconst networkSnapshotP = !this.driverPolicies?.enableDiscovery\n\t\t\t\t\t\t? this.fetchSnapshotTree(latestSnapshotId, false)\n\t\t\t\t\t\t: this.fetchSnapshotTree(latestSnapshotId, true);\n\n\t\t\t\t\tconst promiseRaceWinner = await promiseRaceWithWinner([\n\t\t\t\t\t\tcachedSnapshotP.catch(() => undefined),\n\t\t\t\t\t\tnetworkSnapshotP.catch(() => undefined),\n\t\t\t\t\t]);\n\n\t\t\t\t\tlet retrievedSnapshot = promiseRaceWinner.value;\n\t\t\t\t\tmethod = promiseRaceWinner.index === 0 ? \"cache\" : \"network\";\n\n\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t// if network failed -> wait for cache ( then return network failure)\n\t\t\t\t\t\t// If cache returned empty or failed -> wait for network (success of failure)\n\t\t\t\t\t\tif (promiseRaceWinner.index === 1) {\n\t\t\t\t\t\t\tretrievedSnapshot = await cachedSnapshotP;\n\t\t\t\t\t\t\tmethod = \"cache\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t\tretrievedSnapshot = await networkSnapshotP;\n\t\t\t\t\t\t\tmethod = \"network\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t});\n\t\t\t\t\treturn retrievedSnapshot;\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconst _id = await this.initializeFromSnapshot(\n\t\t\t\tnormalizedSnapshotContents,\n\t\t\t\tlatestSnapshotId,\n\t\t\t);\n\t\t\tthis.firstVersionsCall = false;\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: _id,\n\t\t\t\t\ttreeId: normalizedSnapshotContents.snapshotTree.id!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// Otherwise, get the latest version of the document as normal.\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getVersions\",\n\t\t\t\tversionId: id,\n\t\t\t\tcount,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\treturn (await manager.getCommits(id, count)).content;\n\t\t\t},\n\t\t);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst normalizedWholeSnapshot = await this.snapshotTreeCache.get(\n\t\t\tthis.getCacheKey(requestVersion.id),\n\t\t);\n\t\tif (normalizedWholeSnapshot !== undefined) {\n\t\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t\t}\n\t\treturn (await this.fetchSnapshotTree(requestVersion.id)).snapshotTree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));\n\t\tif (cachedBlob !== undefined) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\tconst blob = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"readBlob\",\n\t\t\t\tblobId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = (await manager.getBlob(blobId)).content;\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.size,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t\tconst bufferValue = stringToBuffer(blob.content, blob.encoding);\n\n\t\tawait this.blobCache.put(this.getCacheKey(blob.sha), bufferValue);\n\n\t\treturn bufferValue;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst summaryHandle = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"uploadSummaryWithContext\",\n\t\t\t\tproposalHandle: context.proposalHandle,\n\t\t\t\tackHandle: context.ackHandle,\n\t\t\t\treferenceSequenceNumber: context.referenceSequenceNumber,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryUploadManager = await this.getSummaryUploadManager();\n\t\t\t\treturn summaryUploadManager.writeSummaryTree(\n\t\t\t\t\tsummary,\n\t\t\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\t\t\"channel\",\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t\treturn summaryHandle;\n\t}\n\n\tpublic async downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst wholeFlatSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: summaryHandle.handle,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager.getSummary(summaryHandle.handle);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\n\t\tconst { blobs, snapshotTree } = convertWholeFlatSummaryToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSummary,\n\t\t\t\"\",\n\t\t);\n\t\treturn convertSnapshotAndBlobsToSummaryTree(snapshotTree, blobs);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"createBlob\",\n\t\t\t\tsize: uint8ArrayFile.length,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager\n\t\t\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t\t\t.then((r) => ({ id: r.content.sha, url: r.content.url }));\n\t\t\t\tevent.end({\n\t\t\t\t\tblobId: response.id,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async fetchSnapshotTree(\n\t\tversionId: string,\n\t\tdisableCache?: boolean,\n\t): Promise<INormalizedWholeSummary> {\n\t\tconst normalizedWholeSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: versionId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager(disableCache);\n\t\t\t\tconst response: IR11sResponse<IWholeFlatSummary> = await manager.getSummary(\n\t\t\t\t\tversionId,\n\t\t\t\t);\n\t\t\t\tconst start = performance.now();\n\t\t\t\tconst snapshot: INormalizedWholeSummary =\n\t\t\t\t\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs(response.content);\n\t\t\t\tconst snapshotConversionTime = performance.now() - start;\n\t\t\t\tvalidateBlobsAndTrees(snapshot.snapshotTree);\n\t\t\t\tconst { trees, numBlobs, encodedBlobsSize } = evalBlobsAndTrees(snapshot);\n\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t\ttrees,\n\t\t\t\t\tblobs: numBlobs,\n\t\t\t\t\tencodedBlobsSize,\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\tsnapshotConversionTime,\n\t\t\t\t\t...getW3CData(response.requestUrl, \"xmlhttprequest\"),\n\t\t\t\t});\n\t\t\t\treturn snapshot;\n\t\t\t},\n\t\t);\n\n\t\treturn normalizedWholeSummary;\n\t}\n\n\tprivate async initializeFromSnapshot(\n\t\tnormalizedWholeSummary: INormalizedWholeSummary,\n\t\tversionId: string | null,\n\t): Promise<string> {\n\t\tconst wholeFlatSummaryId = normalizedWholeSummary.snapshotTree.id;\n\t\tassert(wholeFlatSummaryId !== undefined, 0x275 /* \"Root tree should contain the id\" */);\n\t\tconst cachePs: Promise<any>[] = [\n\t\t\tthis.snapshotTreeCache.put(\n\t\t\t\tthis.getCacheKey(wholeFlatSummaryId),\n\t\t\t\tnormalizedWholeSummary,\n\t\t\t),\n\t\t\tthis.initBlobCache(normalizedWholeSummary.blobs),\n\t\t];\n\t\tif (wholeFlatSummaryId !== versionId && versionId !== null) {\n\t\t\t// versionId could be \"latest\". When summarizer checks cache for \"latest\", we want it to be available.\n\t\t\t// TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,\n\t\t\t// However, for something like Redis, this will cache the same value twice. Alternatively, could we simply\n\t\t\t// cache with versionId?\n\t\t\tcachePs.push(\n\t\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(versionId), normalizedWholeSummary),\n\t\t\t);\n\t\t}\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn wholeFlatSummaryId;\n\t}\n\n\tprivate async initBlobCache(blobs: Map<string, ArrayBuffer>): Promise<void> {\n\t\tconst blobCachePutPs: Promise<void>[] = [];\n\t\tblobs.forEach((value, id) => {\n\t\t\tconst cacheKey = this.getCacheKey(id);\n\t\t\tblobCachePutPs.push(this.blobCache.put(cacheKey, value));\n\t\t});\n\t\tawait Promise.all(blobCachePutPs);\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\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 { ISummaryTree, IWholeSummaryPayloadType } from "@fluidframework/server-services-client";
6
+ import { IGitManager, ISummaryUploadManager } from "./storageContracts";
7
+ /**
8
+ * Converts summary to snapshot tree and uploads with single snaphot tree payload.
9
+ */
10
+ export declare class WholeSummaryUploadManager implements ISummaryUploadManager {
11
+ private readonly manager;
12
+ constructor(manager: IGitManager);
13
+ writeSummaryTree(summaryTree: ISummaryTree, parentHandle: string | undefined, summaryType: IWholeSummaryPayloadType, sequenceNumber?: number, initial?: boolean): Promise<string>;
14
+ private writeSummaryTreeCore;
15
+ }
16
+ //# sourceMappingURL=wholeSummaryUploadManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wholeSummaryUploadManager.d.ts","sourceRoot":"","sources":["../src/wholeSummaryUploadManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,YAAY,EAEZ,wBAAwB,EAExB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAExE;;GAEG;AACH,qBAAa,yBAA0B,YAAW,qBAAqB;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW;IAEpC,gBAAgB,CAC5B,WAAW,EAAE,YAAY,EACzB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,WAAW,EAAE,wBAAwB,EACrC,cAAc,GAAE,MAAU,EAC1B,OAAO,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,CAAC;YAcJ,oBAAoB;CAwBlC"}
@@ -0,0 +1,38 @@
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.WholeSummaryUploadManager = void 0;
8
+ const server_services_client_1 = require("@fluidframework/server-services-client");
9
+ /**
10
+ * Converts summary to snapshot tree and uploads with single snaphot tree payload.
11
+ */
12
+ class WholeSummaryUploadManager {
13
+ constructor(manager) {
14
+ this.manager = manager;
15
+ }
16
+ async writeSummaryTree(summaryTree, parentHandle, summaryType, sequenceNumber = 0, initial = false) {
17
+ const id = await this.writeSummaryTreeCore(parentHandle, summaryTree, summaryType, sequenceNumber, initial);
18
+ if (!id) {
19
+ throw new Error(`Failed to write summary tree`);
20
+ }
21
+ return id;
22
+ }
23
+ async writeSummaryTreeCore(parentHandle, tree, type, sequenceNumber, initial) {
24
+ var _a;
25
+ const snapshotTree = (0, server_services_client_1.convertSummaryTreeToWholeSummaryTree)(parentHandle, tree, "", type === "channel" ? ".app" : "");
26
+ const snapshotPayload = {
27
+ entries: (_a = snapshotTree.entries) !== null && _a !== void 0 ? _a : [],
28
+ message: "",
29
+ sequenceNumber,
30
+ type,
31
+ };
32
+ return this.manager
33
+ .createSummary(snapshotPayload, initial)
34
+ .then((response) => response.content.id);
35
+ }
36
+ }
37
+ exports.WholeSummaryUploadManager = WholeSummaryUploadManager;
38
+ //# sourceMappingURL=wholeSummaryUploadManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wholeSummaryUploadManager.js","sourceRoot":"","sources":["../src/wholeSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mFAKgD;AAGhD;;GAEG;AACH,MAAa,yBAAyB;IACrC,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE9C,KAAK,CAAC,gBAAgB,CAC5B,WAAyB,EACzB,YAAgC,EAChC,WAAqC,EACrC,iBAAyB,CAAC,EAC1B,UAAmB,KAAK;QAExB,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,oBAAoB,CACzC,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,OAAO,CACP,CAAC;QACF,IAAI,CAAC,EAAE,EAAE;YACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SAChD;QACD,OAAO,EAAE,CAAC;IACX,CAAC;IAEO,KAAK,CAAC,oBAAoB,CACjC,YAAgC,EAChC,IAAkB,EAClB,IAA8B,EAC9B,cAAsB,EACtB,OAAgB;;QAEhB,MAAM,YAAY,GAAG,IAAA,6DAAoC,EACxD,YAAY,EACZ,IAAI,EACJ,EAAE,EACF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAChC,CAAC;QACF,MAAM,eAAe,GAAyB;YAC7C,OAAO,EAAE,MAAA,YAAY,CAAC,OAAO,mCAAI,EAAE;YACnC,OAAO,EAAE,EAAE;YACX,cAAc;YACd,IAAI;SACJ,CAAC;QAEF,OAAO,IAAI,CAAC,OAAO;aACjB,aAAa,CAAC,eAAe,EAAE,OAAO,CAAC;aACvC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;CACD;AA/CD,8DA+CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISummaryTree,\n\tIWholeSummaryPayload,\n\tIWholeSummaryPayloadType,\n\tconvertSummaryTreeToWholeSummaryTree,\n} from \"@fluidframework/server-services-client\";\nimport { IGitManager, ISummaryUploadManager } from \"./storageContracts\";\n\n/**\n * Converts summary to snapshot tree and uploads with single snaphot tree payload.\n */\nexport class WholeSummaryUploadManager implements ISummaryUploadManager {\n\tconstructor(private readonly manager: IGitManager) {}\n\n\tpublic async writeSummaryTree(\n\t\tsummaryTree: ISummaryTree,\n\t\tparentHandle: string | undefined,\n\t\tsummaryType: IWholeSummaryPayloadType,\n\t\tsequenceNumber: number = 0,\n\t\tinitial: boolean = false,\n\t): Promise<string> {\n\t\tconst id = await this.writeSummaryTreeCore(\n\t\t\tparentHandle,\n\t\t\tsummaryTree,\n\t\t\tsummaryType,\n\t\t\tsequenceNumber,\n\t\t\tinitial,\n\t\t);\n\t\tif (!id) {\n\t\t\tthrow new Error(`Failed to write summary tree`);\n\t\t}\n\t\treturn id;\n\t}\n\n\tprivate async writeSummaryTreeCore(\n\t\tparentHandle: string | undefined,\n\t\ttree: ISummaryTree,\n\t\ttype: IWholeSummaryPayloadType,\n\t\tsequenceNumber: number,\n\t\tinitial: boolean,\n\t): Promise<string> {\n\t\tconst snapshotTree = convertSummaryTreeToWholeSummaryTree(\n\t\t\tparentHandle,\n\t\t\ttree,\n\t\t\t\"\",\n\t\t\ttype === \"channel\" ? \".app\" : \"\",\n\t\t);\n\t\tconst snapshotPayload: IWholeSummaryPayload = {\n\t\t\tentries: snapshotTree.entries ?? [],\n\t\t\tmessage: \"\",\n\t\t\tsequenceNumber,\n\t\t\ttype,\n\t\t};\n\n\t\treturn this.manager\n\t\t\t.createSummary(snapshotPayload, initial)\n\t\t\t.then((response) => response.content.id);\n\t}\n}\n"]}
package/lib/cache.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { MapWithExpiration } from "@fluidframework/driver-utils";
5
+ import { MapWithExpiration } from "./mapWithExpiration";
6
6
  /** A basic in-memory cache that optionally supports expiring entries after a period of inactivity */
7
7
  export class InMemoryCache {
8
8
  constructor(expirationMs) {
package/lib/cache.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAOjE,qGAAqG;AACrG,MAAM,OAAO,aAAa;IAGzB,YAAY,YAAqB;QAChC,IAAI,CAAC,KAAK,GAAG,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;IAC3F,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAQ;QACrC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACD;AAED,yEAAyE;AACzE,MAAM,OAAO,SAAS;IACd,KAAK,CAAC,GAAG,CAAC,GAAW;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAQ,IAAkB,CAAC;CACzD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { MapWithExpiration } from \"@fluidframework/driver-utils\";\n\nexport interface ICache<T> {\n\tget(key: string): Promise<T | undefined>;\n\tput(key: string, value: T): Promise<void>;\n}\n\n/** A basic in-memory cache that optionally supports expiring entries after a period of inactivity */\nexport class InMemoryCache<T> implements ICache<T> {\n\tprivate readonly cache: Map<string, T>;\n\n\tconstructor(expirationMs?: number) {\n\t\tthis.cache = expirationMs !== undefined ? new MapWithExpiration(expirationMs) : new Map();\n\t}\n\n\tpublic async get(key: string): Promise<T | undefined> {\n\t\treturn this.cache.get(key);\n\t}\n\n\tpublic async put(key: string, value: T): Promise<void> {\n\t\tthis.cache.set(key, value);\n\t}\n}\n\n/** This \"cache\" does nothing on put, and get always returns undefined */\nexport class NullCache<T> implements ICache<T> {\n\tpublic async get(key: string): Promise<T | undefined> {\n\t\treturn undefined;\n\t}\n\n\tpublic async put(key: string, value: T): Promise<void> {}\n}\n"]}
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAOxD,qGAAqG;AACrG,MAAM,OAAO,aAAa;IAGzB,YAAY,YAAqB;QAChC,IAAI,CAAC,KAAK,GAAG,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;IAC3F,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAQ;QACrC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACD;AAED,yEAAyE;AACzE,MAAM,OAAO,SAAS;IACd,KAAK,CAAC,GAAG,CAAC,GAAW;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAQ,IAAkB,CAAC;CACzD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { MapWithExpiration } from \"./mapWithExpiration\";\n\nexport interface ICache<T> {\n\tget(key: string): Promise<T | undefined>;\n\tput(key: string, value: T): Promise<void>;\n}\n\n/** A basic in-memory cache that optionally supports expiring entries after a period of inactivity */\nexport class InMemoryCache<T> implements ICache<T> {\n\tprivate readonly cache: Map<string, T>;\n\n\tconstructor(expirationMs?: number) {\n\t\tthis.cache = expirationMs !== undefined ? new MapWithExpiration(expirationMs) : new Map();\n\t}\n\n\tpublic async get(key: string): Promise<T | undefined> {\n\t\treturn this.cache.get(key);\n\t}\n\n\tpublic async put(key: string, value: T): Promise<void> {\n\t\tthis.cache.set(key, value);\n\t}\n}\n\n/** This \"cache\" does nothing on put, and get always returns undefined */\nexport class NullCache<T> implements ICache<T> {\n\tpublic async get(key: string): Promise<T | undefined> {\n\t\treturn undefined;\n\t}\n\n\tpublic async put(key: string, value: T): Promise<void> {}\n}\n"]}