@fluidframework/container-loader 2.118.0 → 3.0.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 (213) hide show
  1. package/CHANGELOG.md +74 -4
  2. package/README.md +53 -50
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
  4. package/api-report/container-loader.legacy.alpha.api.md +4 -3
  5. package/dist/attachment.d.ts.map +1 -1
  6. package/dist/audience.js +3 -2
  7. package/dist/audience.js.map +1 -1
  8. package/dist/captureReferencedContents.js +9 -9
  9. package/dist/captureReferencedContents.js.map +1 -1
  10. package/dist/catchUpMonitor.js +11 -8
  11. package/dist/catchUpMonitor.js.map +1 -1
  12. package/dist/connectionManager.d.ts.map +1 -1
  13. package/dist/connectionManager.js +86 -51
  14. package/dist/connectionManager.js.map +1 -1
  15. package/dist/connectionStateHandler.js +40 -14
  16. package/dist/connectionStateHandler.js.map +1 -1
  17. package/dist/container.d.ts +1 -1
  18. package/dist/container.d.ts.map +1 -1
  19. package/dist/container.js +193 -143
  20. package/dist/container.js.map +1 -1
  21. package/dist/containerContext.js +48 -11
  22. package/dist/containerContext.js.map +1 -1
  23. package/dist/containerStorageAdapter.js +25 -17
  24. package/dist/containerStorageAdapter.js.map +1 -1
  25. package/dist/contracts.d.ts.map +1 -1
  26. package/dist/createAndLoadContainerUtils.d.ts +34 -13
  27. package/dist/createAndLoadContainerUtils.d.ts.map +1 -1
  28. package/dist/createAndLoadContainerUtils.js +97 -37
  29. package/dist/createAndLoadContainerUtils.js.map +1 -1
  30. package/dist/debugLogger.d.ts +7 -22
  31. package/dist/debugLogger.d.ts.map +1 -1
  32. package/dist/debugLogger.js +34 -34
  33. package/dist/debugLogger.js.map +1 -1
  34. package/dist/deltaManager.d.ts +16 -4
  35. package/dist/deltaManager.d.ts.map +1 -1
  36. package/dist/deltaManager.js +73 -48
  37. package/dist/deltaManager.js.map +1 -1
  38. package/dist/deltaManagerFactory.d.ts +23 -0
  39. package/dist/deltaManagerFactory.d.ts.map +1 -0
  40. package/dist/deltaManagerFactory.js +17 -0
  41. package/dist/deltaManagerFactory.js.map +1 -0
  42. package/dist/deltaQueue.js +14 -7
  43. package/dist/deltaQueue.js.map +1 -1
  44. package/dist/disposal.js +1 -2
  45. package/dist/disposal.js.map +1 -1
  46. package/dist/error.js +5 -4
  47. package/dist/error.js.map +1 -1
  48. package/dist/frozenServices.d.ts +2 -2
  49. package/dist/frozenServices.d.ts.map +1 -1
  50. package/dist/frozenServices.js +52 -34
  51. package/dist/frozenServices.js.map +1 -1
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +2 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/loadContainerToSequenceNumber.js +1 -2
  57. package/dist/loadContainerToSequenceNumber.js.map +1 -1
  58. package/dist/loadPaused.js +1 -2
  59. package/dist/loadPaused.js.map +1 -1
  60. package/dist/loader.js +5 -1
  61. package/dist/loader.js.map +1 -1
  62. package/dist/loaderLayerCompatState.d.ts +25 -1
  63. package/dist/loaderLayerCompatState.d.ts.map +1 -1
  64. package/dist/loaderLayerCompatState.js +79 -11
  65. package/dist/loaderLayerCompatState.js.map +1 -1
  66. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js +2 -3
  67. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  68. package/dist/memoryBlobStorage.js +2 -3
  69. package/dist/memoryBlobStorage.js.map +1 -1
  70. package/dist/noopHeuristic.js +3 -1
  71. package/dist/noopHeuristic.js.map +1 -1
  72. package/dist/packageVersion.d.ts +1 -1
  73. package/dist/packageVersion.d.ts.map +1 -1
  74. package/dist/packageVersion.js +1 -1
  75. package/dist/packageVersion.js.map +1 -1
  76. package/dist/pendingLocalStateStore.d.ts +4 -3
  77. package/dist/pendingLocalStateStore.d.ts.map +1 -1
  78. package/dist/pendingLocalStateStore.js +26 -37
  79. package/dist/pendingLocalStateStore.js.map +1 -1
  80. package/dist/pointInTimeServices.js +4 -2
  81. package/dist/pointInTimeServices.js.map +1 -1
  82. package/dist/protocol/protocol.js +3 -0
  83. package/dist/protocol/protocol.js.map +1 -1
  84. package/dist/protocol/quorum.js +26 -5
  85. package/dist/protocol/quorum.js.map +1 -1
  86. package/dist/protocol.js +5 -3
  87. package/dist/protocol.js.map +1 -1
  88. package/dist/protocolTreeDocumentStorageService.js +10 -0
  89. package/dist/protocolTreeDocumentStorageService.js.map +1 -1
  90. package/dist/quorum.js +1 -2
  91. package/dist/quorum.js.map +1 -1
  92. package/dist/retriableDocumentStorageService.d.ts.map +1 -1
  93. package/dist/retriableDocumentStorageService.js +5 -1
  94. package/dist/retriableDocumentStorageService.js.map +1 -1
  95. package/dist/serializedStateManager.d.ts +6 -0
  96. package/dist/serializedStateManager.d.ts.map +1 -1
  97. package/dist/serializedStateManager.js +19 -24
  98. package/dist/serializedStateManager.js.map +1 -1
  99. package/dist/snapshotRefresher.js +31 -36
  100. package/dist/snapshotRefresher.js.map +1 -1
  101. package/dist/utils.d.ts +1 -1
  102. package/dist/utils.d.ts.map +1 -1
  103. package/dist/utils.js +13 -13
  104. package/dist/utils.js.map +1 -1
  105. package/lib/attachment.d.ts.map +1 -1
  106. package/lib/audience.js +3 -2
  107. package/lib/audience.js.map +1 -1
  108. package/lib/catchUpMonitor.js +11 -8
  109. package/lib/catchUpMonitor.js.map +1 -1
  110. package/lib/connectionManager.d.ts.map +1 -1
  111. package/lib/connectionManager.js +86 -51
  112. package/lib/connectionManager.js.map +1 -1
  113. package/lib/connectionStateHandler.js +37 -11
  114. package/lib/connectionStateHandler.js.map +1 -1
  115. package/lib/container.d.ts +1 -1
  116. package/lib/container.d.ts.map +1 -1
  117. package/lib/container.js +191 -141
  118. package/lib/container.js.map +1 -1
  119. package/lib/containerContext.js +48 -11
  120. package/lib/containerContext.js.map +1 -1
  121. package/lib/containerStorageAdapter.js +22 -14
  122. package/lib/containerStorageAdapter.js.map +1 -1
  123. package/lib/contracts.d.ts.map +1 -1
  124. package/lib/createAndLoadContainerUtils.d.ts +34 -13
  125. package/lib/createAndLoadContainerUtils.d.ts.map +1 -1
  126. package/lib/createAndLoadContainerUtils.js +93 -32
  127. package/lib/createAndLoadContainerUtils.js.map +1 -1
  128. package/lib/debugLogger.d.ts +7 -22
  129. package/lib/debugLogger.d.ts.map +1 -1
  130. package/lib/debugLogger.js +34 -33
  131. package/lib/debugLogger.js.map +1 -1
  132. package/lib/deltaManager.d.ts +16 -4
  133. package/lib/deltaManager.d.ts.map +1 -1
  134. package/lib/deltaManager.js +73 -48
  135. package/lib/deltaManager.js.map +1 -1
  136. package/lib/deltaManagerFactory.d.ts +23 -0
  137. package/lib/deltaManagerFactory.d.ts.map +1 -0
  138. package/lib/deltaManagerFactory.js +14 -0
  139. package/lib/deltaManagerFactory.js.map +1 -0
  140. package/lib/deltaQueue.js +14 -7
  141. package/lib/deltaQueue.js.map +1 -1
  142. package/lib/error.js +5 -4
  143. package/lib/error.js.map +1 -1
  144. package/lib/frozenServices.d.ts +2 -2
  145. package/lib/frozenServices.d.ts.map +1 -1
  146. package/lib/frozenServices.js +48 -30
  147. package/lib/frozenServices.js.map +1 -1
  148. package/lib/index.d.ts +1 -1
  149. package/lib/index.d.ts.map +1 -1
  150. package/lib/index.js +1 -1
  151. package/lib/index.js.map +1 -1
  152. package/lib/legacy.d.ts +1 -1
  153. package/lib/legacyAlpha.d.ts +1 -1
  154. package/lib/loader.js +6 -2
  155. package/lib/loader.js.map +1 -1
  156. package/lib/loaderLayerCompatState.d.ts +25 -1
  157. package/lib/loaderLayerCompatState.d.ts.map +1 -1
  158. package/lib/loaderLayerCompatState.js +76 -9
  159. package/lib/loaderLayerCompatState.js.map +1 -1
  160. package/lib/noopHeuristic.js +3 -1
  161. package/lib/noopHeuristic.js.map +1 -1
  162. package/lib/packageVersion.d.ts +1 -1
  163. package/lib/packageVersion.d.ts.map +1 -1
  164. package/lib/packageVersion.js +1 -1
  165. package/lib/packageVersion.js.map +1 -1
  166. package/lib/pendingLocalStateStore.d.ts +4 -3
  167. package/lib/pendingLocalStateStore.d.ts.map +1 -1
  168. package/lib/pendingLocalStateStore.js +26 -37
  169. package/lib/pendingLocalStateStore.js.map +1 -1
  170. package/lib/pointInTimeServices.js +2 -0
  171. package/lib/pointInTimeServices.js.map +1 -1
  172. package/lib/protocol/protocol.js +3 -0
  173. package/lib/protocol/protocol.js.map +1 -1
  174. package/lib/protocol/quorum.js +26 -5
  175. package/lib/protocol/quorum.js.map +1 -1
  176. package/lib/protocol.js +2 -0
  177. package/lib/protocol.js.map +1 -1
  178. package/lib/protocolTreeDocumentStorageService.js +10 -0
  179. package/lib/protocolTreeDocumentStorageService.js.map +1 -1
  180. package/lib/public.d.ts +1 -1
  181. package/lib/retriableDocumentStorageService.d.ts.map +1 -1
  182. package/lib/retriableDocumentStorageService.js +5 -1
  183. package/lib/retriableDocumentStorageService.js.map +1 -1
  184. package/lib/serializedStateManager.d.ts +6 -0
  185. package/lib/serializedStateManager.d.ts.map +1 -1
  186. package/lib/serializedStateManager.js +15 -20
  187. package/lib/serializedStateManager.js.map +1 -1
  188. package/lib/snapshotRefresher.js +31 -36
  189. package/lib/snapshotRefresher.js.map +1 -1
  190. package/lib/utils.d.ts +1 -1
  191. package/lib/utils.d.ts.map +1 -1
  192. package/lib/utils.js +3 -3
  193. package/lib/utils.js.map +1 -1
  194. package/package.json +44 -106
  195. package/src/container.ts +35 -22
  196. package/src/createAndLoadContainerUtils.ts +131 -46
  197. package/src/debugLogger.ts +39 -40
  198. package/src/deltaManager.ts +16 -4
  199. package/src/deltaManagerFactory.ts +53 -0
  200. package/src/frozenServices.ts +6 -7
  201. package/src/index.ts +1 -0
  202. package/src/loader.ts +2 -2
  203. package/src/loaderLayerCompatState.ts +85 -20
  204. package/src/packageVersion.ts +1 -1
  205. package/src/pendingLocalStateStore.ts +7 -3
  206. package/src/serializedStateManager.ts +6 -0
  207. package/src/utils.ts +3 -3
  208. package/tsconfig.json +1 -1
  209. package/internal.d.ts +0 -11
  210. package/legacy/alpha.d.ts +0 -11
  211. package/legacy.d.ts +0 -11
  212. /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
  213. /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"pendingLocalStateStore.js","sourceRoot":"","sources":["../src/pendingLocalStateStore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;AAGH,uEAAsE;AAMtE,yCAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,sBAAsB;IAAnC;QACC,mDAA8B;QACrB,gDAAiB,IAAI,GAAG,EAAgC,EAAC;QACzD,2CAAuD,EAAE,EAAC;QAC1D,wCAAiC,EAAE,EAAC;QACpC,kDAA2C,EAAE,EAAC;QAC9C,gDAAyD,EAAE,EAAC;IAyHtE,CAAC;IAvHA;;OAEG;IACH,KAAK;QACJ,OAAO,uBAAA,IAAI,6CAAe,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAS;QACf,OAAO,uBAAA,IAAI,6CAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAS;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,uBAAA,IAAI,6CAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAS;QACZ,OAAO,uBAAA,IAAI,6CAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,GAAS,EAAE,iBAAyB;QACvC,MAAM,KAAK,GAAG,IAAA,2DAAgD,EAAC,iBAAiB,CAAC,CAAC;QAClF,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,sBAAsB,EAAE,sBA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AO,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;CACD;AA/HD,wDA+HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type {\n\tIPendingContainerState,\n\tSerializedSnapshotInfo,\n} from \"./serializedStateManager.js\";\nimport { getAttachedContainerStateFromSerializedContainer } from \"./utils.js\";\n\n/**\n * A Map-like store for managing pending local container states from attached containers.\n * Optimizes storage by deduplicating shared resources across stored states.\n *\n * @example\n * ```typescript\n * const store = new PendingLocalStateStore<string>();\n *\n * // Store pending state\n * const pendingState = await attachedContainer.getPendingLocalState();\n * store.set(\"session1\", pendingState);\n *\n * // Load from stored state\n * const restored = store.get(\"session1\");\n * const newContainer = await loadFrozenContainerFromPendingState({\n * pendingLocalState: restored,\n * // ... other loader options\n * });\n * ```\n *\n * @remarks\n * Only use with attached containers from the same URL. Only store strings\n * returned by `container.getPendingLocalState()`.\n *\n * @typeParam TKey - The type of keys used to identify stored states\n *\n * @legacy @alpha\n */\nexport class PendingLocalStateStore<TKey> {\n\t#firstUrl: string | undefined;\n\treadonly #pendingStates = new Map<TKey, IPendingContainerState>();\n\treadonly #savedOps: Record<number, ISequencedDocumentMessage> = {};\n\treadonly #blobs: Record<string, string> = {};\n\treadonly #attachmentBlobs: Record<string, string> = {};\n\treadonly #loadingGroups: Record<string, SerializedSnapshotInfo> = {};\n\n\t/**\n\t * Removes all stored pending states.\n\t */\n\tclear(): void {\n\t\treturn this.#pendingStates.clear();\n\t}\n\n\t/**\n\t * Removes the pending state for the specified key.\n\t *\n\t * @param key - The key to remove\n\t * @returns `true` if the state existed and was removed, `false` otherwise\n\t */\n\tdelete(key: TKey): boolean {\n\t\treturn this.#pendingStates.delete(key);\n\t}\n\n\t/**\n\t * Retrieves the serialized pending state for the specified key.\n\t *\n\t * @param key - The key to retrieve\n\t * @returns The serialized state as a JSON string, or `undefined` if not found\n\t */\n\tget(key: TKey): string | undefined {\n\t\treturn JSON.stringify(this.#pendingStates.get(key));\n\t}\n\n\t/**\n\t * Checks whether a pending state exists for the specified key.\n\t */\n\thas(key: TKey): boolean {\n\t\treturn this.#pendingStates.has(key);\n\t}\n\n\t/**\n\t * Stores a pending state from `container.getPendingLocalState()`.\n\t *\n\t * @param key - The key to associate with the state\n\t * @param pendingLocalState - String returned by `getPendingLocalState()` from an attached container\n\t * @returns This store instance for method chaining\n\t *\n\t * @throws When storing states from different container URLs\n\t */\n\tset(key: TKey, pendingLocalState: string): this {\n\t\tconst state = getAttachedContainerStateFromSerializedContainer(pendingLocalState);\n\t\tconst { savedOps, snapshotBlobs, attachmentBlobContents, loadedGroupIdSnapshots, url } =\n\t\t\tstate;\n\n\t\t// Normalize URL by removing trailing slash for comparison\n\t\tconst normalizedUrl = url.replace(/\\/$/, \"\");\n\t\tconst normalizedFirstUrl = this.#firstUrl?.replace(/\\/$/, \"\");\n\t\tthis.#firstUrl ??= url;\n\t\tif (normalizedFirstUrl !== undefined && normalizedFirstUrl !== normalizedUrl) {\n\t\t\tthrow new UsageError(\"PendingLocalStateStore can only be used with a single container.\");\n\t\t}\n\n\t\tfor (let i = 0; i < savedOps.length; i++) {\n\t\t\tsavedOps[i] = this.#savedOps[savedOps[i].sequenceNumber] ??= savedOps[i];\n\t\t}\n\t\tfor (const [id, blob] of Object.entries(snapshotBlobs)) {\n\t\t\tsnapshotBlobs[id] = this.#blobs[id] ??= blob;\n\t\t}\n\t\tif (attachmentBlobContents !== undefined) {\n\t\t\tfor (const [id, blob] of Object.entries(attachmentBlobContents)) {\n\t\t\t\tattachmentBlobContents[id] = this.#attachmentBlobs[id] ??= blob;\n\t\t\t}\n\t\t}\n\t\tif (loadedGroupIdSnapshots !== undefined) {\n\t\t\tfor (const [id, lg] of Object.entries(loadedGroupIdSnapshots)) {\n\t\t\t\tif (\n\t\t\t\t\tthis.#loadingGroups[id] === undefined ||\n\t\t\t\t\tlg.snapshotSequenceNumber < this.#loadingGroups[id].snapshotSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\tloadedGroupIdSnapshots[id] = this.#loadingGroups[id] = lg;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.#pendingStates.set(key, state);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Gets the number of stored pending states.\n\t */\n\tget size(): number {\n\t\treturn this.#pendingStates.size;\n\t}\n\n\t/**\n\t * Returns an iterator over [key, serializedState] pairs.\n\t */\n\tentries(): Iterator<[TKey, string]> {\n\t\tconst iterator = this.#pendingStates.entries();\n\t\treturn {\n\t\t\tnext: (): IteratorResult<[TKey, string]> => {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst { done, value } = iterator.next();\n\t\t\t\tif (done === true) {\n\t\t\t\t\treturn { done, value: undefined };\n\t\t\t\t}\n\t\t\t\treturn { done, value: [value[0], JSON.stringify(value[1])] };\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Returns an iterator over the stored keys.\n\t */\n\tkeys(): IterableIterator<TKey> {\n\t\treturn this.#pendingStates.keys();\n\t}\n\n\t/**\n\t * Makes the store iterable with `for...of` loops.\n\t */\n\t[Symbol.iterator](): Iterator<[TKey, string]> {\n\t\treturn this.entries();\n\t}\n}\n"]}
1
+ {"version":3,"file":"pendingLocalStateStore.js","sourceRoot":"","sources":["../src/pendingLocalStateStore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,uEAAsE;AAMtE,yCAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,sBAAsB;IAClC,SAAS,CAAqB;IACrB,cAAc,GAAG,IAAI,GAAG,EAAgC,CAAC;IACzD,SAAS,GAA8C,EAAE,CAAC;IAC1D,MAAM,GAA2B,EAAE,CAAC;IACpC,gBAAgB,GAA2B,EAAE,CAAC;IAC9C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AO;QACN,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC/C,OAAO;YACN,IAAI,EAAE,GAAmC,EAAE;gBAC1C,mEAAmE;gBACnE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACxC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;oBACnB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;gBACnC,CAAC;gBACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9D,CAAC;YACD,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAChB,OAAO,IAAI,CAAC;YACb,CAAC;SACD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;CACD;AAlID,wDAkIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { FluidIterableIterator } from \"@fluidframework/core-interfaces\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type {\n\tIPendingContainerState,\n\tSerializedSnapshotInfo,\n} from \"./serializedStateManager.js\";\nimport { getAttachedContainerStateFromSerializedContainer } from \"./utils.js\";\n\n/**\n * A Map-like store for managing pending local container states from attached containers.\n * Optimizes storage by deduplicating shared resources across stored states.\n *\n * @example\n * ```typescript\n * const store = new PendingLocalStateStore<string>();\n *\n * // Store pending state\n * const pendingState = await attachedContainer.getPendingLocalState();\n * store.set(\"session1\", pendingState);\n *\n * // Load from stored state\n * const restored = store.get(\"session1\");\n * const newContainer = await loadFrozenContainerFromPendingState({\n * pendingLocalState: restored,\n * // ... other loader options\n * });\n * ```\n *\n * @remarks\n * Only use with attached containers from the same URL. Only store strings\n * returned by `container.getPendingLocalState()`.\n *\n * @typeParam TKey - The type of keys used to identify stored states\n *\n * @legacy @alpha\n */\nexport class PendingLocalStateStore<TKey> {\n\t#firstUrl: string | undefined;\n\treadonly #pendingStates = new Map<TKey, IPendingContainerState>();\n\treadonly #savedOps: Record<number, ISequencedDocumentMessage> = {};\n\treadonly #blobs: Record<string, string> = {};\n\treadonly #attachmentBlobs: Record<string, string> = {};\n\treadonly #loadingGroups: Record<string, SerializedSnapshotInfo> = {};\n\n\t/**\n\t * Removes all stored pending states.\n\t */\n\tclear(): void {\n\t\treturn this.#pendingStates.clear();\n\t}\n\n\t/**\n\t * Removes the pending state for the specified key.\n\t *\n\t * @param key - The key to remove\n\t * @returns `true` if the state existed and was removed, `false` otherwise\n\t */\n\tdelete(key: TKey): boolean {\n\t\treturn this.#pendingStates.delete(key);\n\t}\n\n\t/**\n\t * Retrieves the serialized pending state for the specified key.\n\t *\n\t * @param key - The key to retrieve\n\t * @returns The serialized state as a JSON string, or `undefined` if not found\n\t */\n\tget(key: TKey): string | undefined {\n\t\treturn JSON.stringify(this.#pendingStates.get(key));\n\t}\n\n\t/**\n\t * Checks whether a pending state exists for the specified key.\n\t */\n\thas(key: TKey): boolean {\n\t\treturn this.#pendingStates.has(key);\n\t}\n\n\t/**\n\t * Stores a pending state from `container.getPendingLocalState()`.\n\t *\n\t * @param key - The key to associate with the state\n\t * @param pendingLocalState - String returned by `getPendingLocalState()` from an attached container\n\t * @returns This store instance for method chaining\n\t *\n\t * @throws When storing states from different container URLs\n\t */\n\tset(key: TKey, pendingLocalState: string): this {\n\t\tconst state = getAttachedContainerStateFromSerializedContainer(pendingLocalState);\n\t\tconst { savedOps, snapshotBlobs, attachmentBlobContents, loadedGroupIdSnapshots, url } =\n\t\t\tstate;\n\n\t\t// Normalize URL by removing trailing slash for comparison\n\t\tconst normalizedUrl = url.replace(/\\/$/, \"\");\n\t\tconst normalizedFirstUrl = this.#firstUrl?.replace(/\\/$/, \"\");\n\t\tthis.#firstUrl ??= url;\n\t\tif (normalizedFirstUrl !== undefined && normalizedFirstUrl !== normalizedUrl) {\n\t\t\tthrow new UsageError(\"PendingLocalStateStore can only be used with a single container.\");\n\t\t}\n\n\t\tfor (let i = 0; i < savedOps.length; i++) {\n\t\t\tsavedOps[i] = this.#savedOps[savedOps[i].sequenceNumber] ??= savedOps[i];\n\t\t}\n\t\tfor (const [id, blob] of Object.entries(snapshotBlobs)) {\n\t\t\tsnapshotBlobs[id] = this.#blobs[id] ??= blob;\n\t\t}\n\t\tif (attachmentBlobContents !== undefined) {\n\t\t\tfor (const [id, blob] of Object.entries(attachmentBlobContents)) {\n\t\t\t\tattachmentBlobContents[id] = this.#attachmentBlobs[id] ??= blob;\n\t\t\t}\n\t\t}\n\t\tif (loadedGroupIdSnapshots !== undefined) {\n\t\t\tfor (const [id, lg] of Object.entries(loadedGroupIdSnapshots)) {\n\t\t\t\tif (\n\t\t\t\t\tthis.#loadingGroups[id] === undefined ||\n\t\t\t\t\tlg.snapshotSequenceNumber < this.#loadingGroups[id].snapshotSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\tloadedGroupIdSnapshots[id] = this.#loadingGroups[id] = lg;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.#pendingStates.set(key, state);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Gets the number of stored pending states.\n\t */\n\tget size(): number {\n\t\treturn this.#pendingStates.size;\n\t}\n\n\t/**\n\t * Returns an iterator over [key, serializedState] pairs.\n\t */\n\tentries(): FluidIterableIterator<[TKey, string]> {\n\t\tconst iterator = this.#pendingStates.entries();\n\t\treturn {\n\t\t\tnext: (): IteratorResult<[TKey, string]> => {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst { done, value } = iterator.next();\n\t\t\t\tif (done === true) {\n\t\t\t\t\treturn { done, value: undefined };\n\t\t\t\t}\n\t\t\t\treturn { done, value: [value[0], JSON.stringify(value[1])] };\n\t\t\t},\n\t\t\t[Symbol.iterator](): FluidIterableIterator<[TKey, string]> {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Returns an iterator over the stored keys.\n\t */\n\tkeys(): FluidIterableIterator<TKey> {\n\t\treturn this.#pendingStates.keys();\n\t}\n\n\t/**\n\t * Makes the store iterable with `for...of` loops.\n\t */\n\t[Symbol.iterator](): FluidIterableIterator<[TKey, string]> {\n\t\treturn this.entries();\n\t}\n}\n"]}
@@ -4,7 +4,8 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.PointInTimeDocumentServiceFactory = exports.asPointInTimeCapableFactory = void 0;
7
+ exports.PointInTimeDocumentServiceFactory = void 0;
8
+ exports.asPointInTimeCapableFactory = asPointInTimeCapableFactory;
8
9
  const internal_1 = require("@fluidframework/driver-utils/internal");
9
10
  /**
10
11
  * Returns the factory typed as point-in-time capable if it implements
@@ -16,7 +17,6 @@ function asPointInTimeCapableFactory(factory) {
16
17
  ? factory
17
18
  : undefined;
18
19
  }
19
- exports.asPointInTimeCapableFactory = asPointInTimeCapableFactory;
20
20
  /**
21
21
  * Adapts a point-in-time capable factory to a plain {@link IDocumentServiceFactory} that always
22
22
  * materializes the configured target sequence number.
@@ -28,6 +28,8 @@ exports.asPointInTimeCapableFactory = asPointInTimeCapableFactory;
28
28
  * {@link loadContainerToSequenceNumber}) - they never build or pass a decorated factory themselves.
29
29
  */
30
30
  class PointInTimeDocumentServiceFactory {
31
+ inner;
32
+ targetSequenceNumber;
31
33
  constructor(inner, targetSequenceNumber) {
32
34
  this.inner = inner;
33
35
  this.targetSequenceNumber = targetSequenceNumber;
@@ -1 +1 @@
1
- {"version":3,"file":"pointInTimeServices.js","sourceRoot":"","sources":["../src/pointInTimeServices.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,oEAAmE;AAyBnE;;;GAGG;AACH,SAAgB,2BAA2B,CAC1C,OAAgC;IAEhC,OAAO,OAAQ,OAA8D;SAC3E,gCAAgC,KAAK,UAAU;QAChD,CAAC,CAAE,OAA+E;QAClF,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAPD,kEAOC;AAED;;;;;;;;;GASG;AACH,MAAa,iCAAiC;IAC7C,YACkB,KAAgD,EAChD,oBAA4B;QAD5B,UAAK,GAAL,KAAK,CAA2C;QAChD,yBAAoB,GAApB,oBAAoB,CAAQ;IAC3C,CAAC;IAEG,KAAK,CAAC,qBAAqB,CACjC,WAAyB,EACzB,MAA6B,EAC7B,kBAA4B;QAE5B,OAAO,IAAI,CAAC,KAAK,CAAC,gCAAgC,CACjD,WAAW,EACX,IAAI,CAAC,oBAAoB,EACzB,MAAM,EACN,kBAAkB,CAClB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,eAAe;QAC3B,MAAM,IAAI,qBAAU,CACnB,+EAA+E,CAC/E,CAAC;IACH,CAAC;CACD;AAxBD,8EAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport type {\n\tIDocumentService,\n\tIDocumentServiceFactory,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\n\n/**\n * A document service factory that can materialize a document at a specific sequence number.\n *\n * @remarks\n * This is a capability a driver's {@link IDocumentServiceFactory} may additionally implement. The\n * loader detects it (see {@link asPointInTimeCapableFactory}) so that\n * {@link loadContainerToSequenceNumber} can drive point-in-time loading without the caller having to\n * wrap or decorate their factory. The driver owns selecting a snapshot at or before the target and\n * replaying the remaining ops on top of it.\n */\ninterface IPointInTimeCapableDocumentServiceFactory {\n\t/**\n\t * Creates a read-only document service materialized at `targetSequenceNumber`: storage serves a\n\t * snapshot at or before the target and delta storage supplies the ops needed to advance to it.\n\t */\n\tcreatePointInTimeDocumentService(\n\t\tresolvedUrl: IResolvedUrl,\n\t\ttargetSequenceNumber: number,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService>;\n}\n\n/**\n * Returns the factory typed as point-in-time capable if it implements\n * {@link IPointInTimeCapableDocumentServiceFactory}, otherwise `undefined`.\n */\nexport function asPointInTimeCapableFactory(\n\tfactory: IDocumentServiceFactory,\n): (IDocumentServiceFactory & IPointInTimeCapableDocumentServiceFactory) | undefined {\n\treturn typeof (factory as Partial<IPointInTimeCapableDocumentServiceFactory>)\n\t\t.createPointInTimeDocumentService === \"function\"\n\t\t? (factory as IDocumentServiceFactory & IPointInTimeCapableDocumentServiceFactory)\n\t\t: undefined;\n}\n\n/**\n * Adapts a point-in-time capable factory to a plain {@link IDocumentServiceFactory} that always\n * materializes the configured target sequence number.\n *\n * @remarks\n * The loader plumbs the caller's target through this adapter so the container's normal\n * `createDocumentService(resolvedUrl)` call routes to `createPointInTimeDocumentService`. This keeps\n * point-in-time loading a single-call experience for the caller (see\n * {@link loadContainerToSequenceNumber}) - they never build or pass a decorated factory themselves.\n */\nexport class PointInTimeDocumentServiceFactory implements IDocumentServiceFactory {\n\tpublic constructor(\n\t\tprivate readonly inner: IPointInTimeCapableDocumentServiceFactory,\n\t\tprivate readonly targetSequenceNumber: number,\n\t) {}\n\n\tpublic async createDocumentService(\n\t\tresolvedUrl: IResolvedUrl,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService> {\n\t\treturn this.inner.createPointInTimeDocumentService(\n\t\t\tresolvedUrl,\n\t\t\tthis.targetSequenceNumber,\n\t\t\tlogger,\n\t\t\tclientIsSummarizer,\n\t\t);\n\t}\n\n\tpublic async createContainer(): Promise<IDocumentService> {\n\t\tthrow new UsageError(\n\t\t\t\"A point-in-time document service factory cannot be used to create containers.\",\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"pointInTimeServices.js","sourceRoot":"","sources":["../src/pointInTimeServices.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAqCH,kEAOC;AApCD,oEAAmE;AAyBnE;;;GAGG;AACH,SAAgB,2BAA2B,CAC1C,OAAgC;IAEhC,OAAO,OAAQ,OAA8D;SAC3E,gCAAgC,KAAK,UAAU;QAChD,CAAC,CAAE,OAA+E;QAClF,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED;;;;;;;;;GASG;AACH,MAAa,iCAAiC;IAE3B;IACA;IAFlB,YACkB,KAAgD,EAChD,oBAA4B;QAD5B,UAAK,GAAL,KAAK,CAA2C;QAChD,yBAAoB,GAApB,oBAAoB,CAAQ;IAC3C,CAAC;IAEG,KAAK,CAAC,qBAAqB,CACjC,WAAyB,EACzB,MAA6B,EAC7B,kBAA4B;QAE5B,OAAO,IAAI,CAAC,KAAK,CAAC,gCAAgC,CACjD,WAAW,EACX,IAAI,CAAC,oBAAoB,EACzB,MAAM,EACN,kBAAkB,CAClB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,eAAe;QAC3B,MAAM,IAAI,qBAAU,CACnB,+EAA+E,CAC/E,CAAC;IACH,CAAC;CACD;AAxBD,8EAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport type {\n\tIDocumentService,\n\tIDocumentServiceFactory,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\n\n/**\n * A document service factory that can materialize a document at a specific sequence number.\n *\n * @remarks\n * This is a capability a driver's {@link IDocumentServiceFactory} may additionally implement. The\n * loader detects it (see {@link asPointInTimeCapableFactory}) so that\n * {@link loadContainerToSequenceNumber} can drive point-in-time loading without the caller having to\n * wrap or decorate their factory. The driver owns selecting a snapshot at or before the target and\n * replaying the remaining ops on top of it.\n */\ninterface IPointInTimeCapableDocumentServiceFactory {\n\t/**\n\t * Creates a read-only document service materialized at `targetSequenceNumber`: storage serves a\n\t * snapshot at or before the target and delta storage supplies the ops needed to advance to it.\n\t */\n\tcreatePointInTimeDocumentService(\n\t\tresolvedUrl: IResolvedUrl,\n\t\ttargetSequenceNumber: number,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService>;\n}\n\n/**\n * Returns the factory typed as point-in-time capable if it implements\n * {@link IPointInTimeCapableDocumentServiceFactory}, otherwise `undefined`.\n */\nexport function asPointInTimeCapableFactory(\n\tfactory: IDocumentServiceFactory,\n): (IDocumentServiceFactory & IPointInTimeCapableDocumentServiceFactory) | undefined {\n\treturn typeof (factory as Partial<IPointInTimeCapableDocumentServiceFactory>)\n\t\t.createPointInTimeDocumentService === \"function\"\n\t\t? (factory as IDocumentServiceFactory & IPointInTimeCapableDocumentServiceFactory)\n\t\t: undefined;\n}\n\n/**\n * Adapts a point-in-time capable factory to a plain {@link IDocumentServiceFactory} that always\n * materializes the configured target sequence number.\n *\n * @remarks\n * The loader plumbs the caller's target through this adapter so the container's normal\n * `createDocumentService(resolvedUrl)` call routes to `createPointInTimeDocumentService`. This keeps\n * point-in-time loading a single-call experience for the caller (see\n * {@link loadContainerToSequenceNumber}) - they never build or pass a decorated factory themselves.\n */\nexport class PointInTimeDocumentServiceFactory implements IDocumentServiceFactory {\n\tpublic constructor(\n\t\tprivate readonly inner: IPointInTimeCapableDocumentServiceFactory,\n\t\tprivate readonly targetSequenceNumber: number,\n\t) {}\n\n\tpublic async createDocumentService(\n\t\tresolvedUrl: IResolvedUrl,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tclientIsSummarizer?: boolean,\n\t): Promise<IDocumentService> {\n\t\treturn this.inner.createPointInTimeDocumentService(\n\t\t\tresolvedUrl,\n\t\t\tthis.targetSequenceNumber,\n\t\t\tlogger,\n\t\t\tclientIsSummarizer,\n\t\t);\n\t}\n\n\tpublic async createContainer(): Promise<IDocumentService> {\n\t\tthrow new UsageError(\n\t\t\t\"A point-in-time document service factory cannot be used to create containers.\",\n\t\t);\n\t}\n}\n"]}
@@ -12,6 +12,9 @@ const quorum_js_1 = require("./quorum.js");
12
12
  * @internal
13
13
  */
14
14
  class ProtocolOpHandler {
15
+ minimumSequenceNumber;
16
+ sequenceNumber;
17
+ _quorum;
15
18
  get quorum() {
16
19
  return this._quorum;
17
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,0EAWqD;AAErD,2CAA2D;AA4B3D;;;GAGG;AACH,MAAa,iBAAiB;IAE7B,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,YACQ,qBAA6B,EAC7B,cAAsB,EAC7B,OAAqC,EACrC,SAAmD,EACnD,MAAsC,EACtC,YAAqD;QAL9C,0BAAqB,GAArB,qBAAqB,CAAQ;QAC7B,mBAAc,GAAd,cAAc,CAAQ;QAM7B,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAM,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IACrE,CAAC;IAED,IAAW,UAAU;QACpB,OAAO;YACN,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC;IACH,CAAC;IAED,kBAAkB,CAAC,SAAkB,EAAE,QAA4B;QAClE,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,QAAQ;QACP,OA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QAED,OAAO;YACN,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,GAAG,QAAQ;SACX,CAAC;IACH,CAAC;CACD;AArID,8CAqIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\ttype ISequencedDocumentMessage,\n\ttype IDocumentAttributes,\n\ttype IClientJoin,\n\ttype ICommittedProposal,\n\ttype IProcessMessageResult,\n\ttype IProposal,\n\ttype IQuorum,\n\ttype ISequencedDocumentSystemMessage,\n\ttype ISequencedProposal,\n\tMessageType,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport { type IQuorumSnapshot, Quorum } from \"./quorum.js\";\n\n/**\n * @legacy @beta\n */\nexport interface IScribeProtocolState {\n\tsequenceNumber: number;\n\tminimumSequenceNumber: number;\n\tmembers: [string, ISequencedClient][];\n\tproposals: [number, ISequencedProposal, string[]][];\n\tvalues: [string, ICommittedProposal][];\n}\n\n/**\n * @legacy @beta\n */\nexport interface IProtocolHandler {\n\treadonly quorum: IQuorum;\n\treadonly attributes: IDocumentAttributes;\n\n\tsetConnectionState(connected: boolean, clientId: string | undefined);\n\tsnapshot(): IQuorumSnapshot;\n\n\tclose(): void;\n\tprocessMessage(message: ISequencedDocumentMessage, local: boolean): IProcessMessageResult;\n\tgetProtocolState(): IScribeProtocolState;\n}\n\n/**\n * Handles protocol specific ops.\n * @internal\n */\nexport class ProtocolOpHandler implements IProtocolHandler {\n\tprivate readonly _quorum: Quorum;\n\tpublic get quorum(): Quorum {\n\t\treturn this._quorum;\n\t}\n\n\tconstructor(\n\t\tpublic minimumSequenceNumber: number,\n\t\tpublic sequenceNumber: number,\n\t\tmembers: [string, ISequencedClient][],\n\t\tproposals: [number, ISequencedProposal, string[]][],\n\t\tvalues: [string, ICommittedProposal][],\n\t\tsendProposal: (key: string, value: unknown) => number,\n\t) {\n\t\tthis._quorum = new Quorum(members, proposals, values, sendProposal);\n\t}\n\n\tpublic get attributes(): IDocumentAttributes {\n\t\treturn {\n\t\t\tminimumSequenceNumber: this.minimumSequenceNumber,\n\t\t\tsequenceNumber: this.sequenceNumber,\n\t\t};\n\t}\n\n\tsetConnectionState(connected: boolean, clientId: string | undefined): void {\n\t\tthis._quorum.setConnectionState(connected, clientId);\n\t}\n\n\tsnapshot(): IQuorumSnapshot {\n\t\treturn this._quorum.snapshot();\n\t}\n\n\tpublic close(): void {\n\t\tthis._quorum.close();\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// verify it's moving sequentially\n\t\tif (message.sequenceNumber !== this.sequenceNumber + 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Protocol state is not moving sequentially. ` +\n\t\t\t\t\t`Current is ${this.sequenceNumber}. Next is ${message.sequenceNumber}`,\n\t\t\t);\n\t\t}\n\n\t\t// Update tracked sequence numbers\n\t\tthis.sequenceNumber = message.sequenceNumber;\n\t\tthis.minimumSequenceNumber = message.minimumSequenceNumber;\n\n\t\tlet immediateNoOp = false;\n\n\t\tswitch (message.type) {\n\t\t\tcase MessageType.ClientJoin: {\n\t\t\t\tconst systemJoinMessage = message as ISequencedDocumentSystemMessage;\n\t\t\t\tconst join = JSON.parse(systemJoinMessage.data) as IClientJoin;\n\t\t\t\tconst member: ISequencedClient = {\n\t\t\t\t\tclient: join.detail,\n\t\t\t\t\tsequenceNumber: systemJoinMessage.sequenceNumber,\n\t\t\t\t};\n\t\t\t\tthis._quorum.addMember(join.clientId, member);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MessageType.ClientLeave: {\n\t\t\t\tconst systemLeaveMessage = message as ISequencedDocumentSystemMessage;\n\t\t\t\tconst clientId = JSON.parse(systemLeaveMessage.data) as string;\n\t\t\t\tthis._quorum.removeMember(clientId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MessageType.Propose: {\n\t\t\t\t// DeltaManager is no longer parsing the contents, so we expect this to be a string here\n\t\t\t\t// (However, switching this to an assert caused some tests to fail, apparently due to the same\n\t\t\t\t// message object being processed multiple times - So we will retain the typeof check for now)\n\t\t\t\tif (typeof message.contents === \"string\") {\n\t\t\t\t\tmessage.contents = JSON.parse(message.contents);\n\t\t\t\t}\n\t\t\t\tconst proposal = message.contents as IProposal;\n\t\t\t\tthis._quorum.addProposal(\n\t\t\t\t\tproposal.key,\n\t\t\t\t\tproposal.value,\n\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\tlocal,\n\t\t\t\t\tmessage.clientSequenceNumber,\n\t\t\t\t);\n\n\t\t\t\t// On a quorum proposal, immediately send a response to expedite the approval.\n\t\t\t\timmediateNoOp = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t}\n\n\t\t// Notify the quorum of the MSN from the message. We rely on it to handle duplicate values but may\n\t\t// want to move that logic to this class.\n\t\tthis._quorum.updateMinimumSequenceNumber(message);\n\n\t\treturn { immediateNoOp };\n\t}\n\n\t/**\n\t * Gets the scribe protocol state\n\t * @param scrubUserData - whether to remove all user data from the quorum members. CAUTION: this will corrupt the quorum if used in a summary.\n\t */\n\tpublic getProtocolState(scrubUserData = false): IScribeProtocolState {\n\t\t// return a new object every time\n\t\t// this ensures future state changes will not affect outside callers\n\t\tconst snapshot = this._quorum.snapshot();\n\n\t\tif (scrubUserData) {\n\t\t\t// In place, remove any identifying client information\n\t\t\tsnapshot.members = snapshot.members.map(([id, sequencedClient]) => [\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\t...sequencedClient,\n\t\t\t\t\tclient: {\n\t\t\t\t\t\t...sequencedClient.client,\n\t\t\t\t\t\tuser: { id: \"\" },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\n\t\treturn {\n\t\t\tsequenceNumber: this.sequenceNumber,\n\t\t\tminimumSequenceNumber: this.minimumSequenceNumber,\n\t\t\t...snapshot,\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,0EAWqD;AAErD,2CAA2D;AA4B3D;;;GAGG;AACH,MAAa,iBAAiB;IAOrB;IACA;IAPS,OAAO,CAAS;IACjC,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,YACQ,qBAA6B,EAC7B,cAAsB,EAC7B,OAAqC,EACrC,SAAmD,EACnD,MAAsC,EACtC,YAAqD;QAL9C,0BAAqB,GAArB,qBAAqB,CAAQ;QAC7B,mBAAc,GAAd,cAAc,CAAQ;QAM7B,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAM,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IACrE,CAAC;IAED,IAAW,UAAU;QACpB,OAAO;YACN,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC;IACH,CAAC;IAED,kBAAkB,CAAC,SAAkB,EAAE,QAA4B;QAClE,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAEM,cAAc,CACpB,OAAkC,EAClC,KAAc;QAEd,kCAAkC;QAClC,IAAI,OAAO,CAAC,cAAc,KAAK,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CACd,6CAA6C;gBAC5C,cAAc,IAAI,CAAC,cAAc,aAAa,OAAO,CAAC,cAAc,EAAE,C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AAO,CAAC,WAAW,CACvB,QAAQ,CAAC,GAAG,EACZ,QAAQ,CAAC,KAAK,EACd,OAAO,CAAC,cAAc,EACtB,KAAK,EACL,OAAO,CAAC,oBAAoB,CAC5B,CAAC;gBAEF,8EAA8E;gBAC9E,aAAa,GAAG,IAAI,CAAC;gBACrB,MAAM;YACP,CAAC;YAED,QAAQ;QACT,CAAC;QAED,kGAAkG;QAClG,yCAAyC;QACzC,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAElD,OAAO,EAAE,aAAa,EAAE,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAC,aAAa,GAAG,KAAK;QAC5C,iCAAiC;QACjC,oEAAoE;QACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAEzC,IAAI,aAAa,EAAE,CAAC;YACnB,sDAAsD;YACtD,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,eAAe,CAAC,EAAE,EAAE,CAAC;gBAClE,EAAE;gBACF;oBACC,GAAG,eAAe;oBAClB,MAAM,EAAE;wBACP,GAAG,eAAe,CAAC,MAAM;wBACzB,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;qBAChB;iBACD;aACD,CAAC,CAAC;QACJ,CAAC;QAED,OAAO;YACN,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,GAAG,QAAQ;SACX,CAAC;IACH,CAAC;CACD;AArID,8CAqIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\ttype ISequencedDocumentMessage,\n\ttype IDocumentAttributes,\n\ttype IClientJoin,\n\ttype ICommittedProposal,\n\ttype IProcessMessageResult,\n\ttype IProposal,\n\ttype IQuorum,\n\ttype ISequencedDocumentSystemMessage,\n\ttype ISequencedProposal,\n\tMessageType,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport { type IQuorumSnapshot, Quorum } from \"./quorum.js\";\n\n/**\n * @legacy @beta\n */\nexport interface IScribeProtocolState {\n\tsequenceNumber: number;\n\tminimumSequenceNumber: number;\n\tmembers: [string, ISequencedClient][];\n\tproposals: [number, ISequencedProposal, string[]][];\n\tvalues: [string, ICommittedProposal][];\n}\n\n/**\n * @legacy @beta\n */\nexport interface IProtocolHandler {\n\treadonly quorum: IQuorum;\n\treadonly attributes: IDocumentAttributes;\n\n\tsetConnectionState(connected: boolean, clientId: string | undefined);\n\tsnapshot(): IQuorumSnapshot;\n\n\tclose(): void;\n\tprocessMessage(message: ISequencedDocumentMessage, local: boolean): IProcessMessageResult;\n\tgetProtocolState(): IScribeProtocolState;\n}\n\n/**\n * Handles protocol specific ops.\n * @internal\n */\nexport class ProtocolOpHandler implements IProtocolHandler {\n\tprivate readonly _quorum: Quorum;\n\tpublic get quorum(): Quorum {\n\t\treturn this._quorum;\n\t}\n\n\tconstructor(\n\t\tpublic minimumSequenceNumber: number,\n\t\tpublic sequenceNumber: number,\n\t\tmembers: [string, ISequencedClient][],\n\t\tproposals: [number, ISequencedProposal, string[]][],\n\t\tvalues: [string, ICommittedProposal][],\n\t\tsendProposal: (key: string, value: unknown) => number,\n\t) {\n\t\tthis._quorum = new Quorum(members, proposals, values, sendProposal);\n\t}\n\n\tpublic get attributes(): IDocumentAttributes {\n\t\treturn {\n\t\t\tminimumSequenceNumber: this.minimumSequenceNumber,\n\t\t\tsequenceNumber: this.sequenceNumber,\n\t\t};\n\t}\n\n\tsetConnectionState(connected: boolean, clientId: string | undefined): void {\n\t\tthis._quorum.setConnectionState(connected, clientId);\n\t}\n\n\tsnapshot(): IQuorumSnapshot {\n\t\treturn this._quorum.snapshot();\n\t}\n\n\tpublic close(): void {\n\t\tthis._quorum.close();\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// verify it's moving sequentially\n\t\tif (message.sequenceNumber !== this.sequenceNumber + 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Protocol state is not moving sequentially. ` +\n\t\t\t\t\t`Current is ${this.sequenceNumber}. Next is ${message.sequenceNumber}`,\n\t\t\t);\n\t\t}\n\n\t\t// Update tracked sequence numbers\n\t\tthis.sequenceNumber = message.sequenceNumber;\n\t\tthis.minimumSequenceNumber = message.minimumSequenceNumber;\n\n\t\tlet immediateNoOp = false;\n\n\t\tswitch (message.type) {\n\t\t\tcase MessageType.ClientJoin: {\n\t\t\t\tconst systemJoinMessage = message as ISequencedDocumentSystemMessage;\n\t\t\t\tconst join = JSON.parse(systemJoinMessage.data) as IClientJoin;\n\t\t\t\tconst member: ISequencedClient = {\n\t\t\t\t\tclient: join.detail,\n\t\t\t\t\tsequenceNumber: systemJoinMessage.sequenceNumber,\n\t\t\t\t};\n\t\t\t\tthis._quorum.addMember(join.clientId, member);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MessageType.ClientLeave: {\n\t\t\t\tconst systemLeaveMessage = message as ISequencedDocumentSystemMessage;\n\t\t\t\tconst clientId = JSON.parse(systemLeaveMessage.data) as string;\n\t\t\t\tthis._quorum.removeMember(clientId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MessageType.Propose: {\n\t\t\t\t// DeltaManager is no longer parsing the contents, so we expect this to be a string here\n\t\t\t\t// (However, switching this to an assert caused some tests to fail, apparently due to the same\n\t\t\t\t// message object being processed multiple times - So we will retain the typeof check for now)\n\t\t\t\tif (typeof message.contents === \"string\") {\n\t\t\t\t\tmessage.contents = JSON.parse(message.contents);\n\t\t\t\t}\n\t\t\t\tconst proposal = message.contents as IProposal;\n\t\t\t\tthis._quorum.addProposal(\n\t\t\t\t\tproposal.key,\n\t\t\t\t\tproposal.value,\n\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\tlocal,\n\t\t\t\t\tmessage.clientSequenceNumber,\n\t\t\t\t);\n\n\t\t\t\t// On a quorum proposal, immediately send a response to expedite the approval.\n\t\t\t\timmediateNoOp = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t}\n\n\t\t// Notify the quorum of the MSN from the message. We rely on it to handle duplicate values but may\n\t\t// want to move that logic to this class.\n\t\tthis._quorum.updateMinimumSequenceNumber(message);\n\n\t\treturn { immediateNoOp };\n\t}\n\n\t/**\n\t * Gets the scribe protocol state\n\t * @param scrubUserData - whether to remove all user data from the quorum members. CAUTION: this will corrupt the quorum if used in a summary.\n\t */\n\tpublic getProtocolState(scrubUserData = false): IScribeProtocolState {\n\t\t// return a new object every time\n\t\t// this ensures future state changes will not affect outside callers\n\t\tconst snapshot = this._quorum.snapshot();\n\n\t\tif (scrubUserData) {\n\t\t\t// In place, remove any identifying client information\n\t\t\tsnapshot.members = snapshot.members.map(([id, sequencedClient]) => [\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\t...sequencedClient,\n\t\t\t\t\tclient: {\n\t\t\t\t\t\t...sequencedClient.client,\n\t\t\t\t\t\tuser: { id: \"\" },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\n\t\treturn {\n\t\t\tsequenceNumber: this.sequenceNumber,\n\t\t\tminimumSequenceNumber: this.minimumSequenceNumber,\n\t\t\t...snapshot,\n\t\t};\n\t}\n}\n"]}
@@ -16,6 +16,10 @@ const { EventEmitter } = events_pkg_1.default;
16
16
  * Structure for tracking proposals that have been sequenced but not approved yet.
17
17
  */
18
18
  class PendingProposal {
19
+ sequenceNumber;
20
+ key;
21
+ value;
22
+ local;
19
23
  constructor(sequenceNumber, key, value, local) {
20
24
  this.sequenceNumber = sequenceNumber;
21
25
  this.key = key;
@@ -28,12 +32,18 @@ class PendingProposal {
28
32
  * @internal
29
33
  */
30
34
  class QuorumClients extends client_utils_1.TypedEventEmitter {
35
+ members;
36
+ isDisposed = false;
31
37
  get disposed() {
32
38
  return this.isDisposed;
33
39
  }
40
+ /**
41
+ * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.
42
+ * Cleared immediately (set to undefined) when the cache becomes invalid.
43
+ */
44
+ snapshotCache;
34
45
  constructor(snapshot) {
35
46
  super();
36
- this.isDisposed = false;
37
47
  this.members = new Map(snapshot);
38
48
  this.snapshotCache = snapshot;
39
49
  }
@@ -90,15 +100,24 @@ exports.QuorumClients = QuorumClients;
90
100
  * @internal
91
101
  */
92
102
  class QuorumProposals extends client_utils_1.TypedEventEmitter {
103
+ sendProposal;
104
+ proposals;
105
+ values;
106
+ isDisposed = false;
93
107
  get disposed() {
94
108
  return this.isDisposed;
95
109
  }
110
+ // Event emitter for changes to the environment that affect pending proposal promises.
111
+ stateEvents = new EventEmitter();
112
+ /**
113
+ * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.
114
+ * Cleared immediately (set to undefined) when the cache becomes invalid.
115
+ */
116
+ proposalsSnapshotCache;
117
+ valuesSnapshotCache;
96
118
  constructor(snapshot, sendProposal) {
97
119
  super();
98
120
  this.sendProposal = sendProposal;
99
- this.isDisposed = false;
100
- // Event emitter for changes to the environment that affect pending proposal promises.
101
- this.stateEvents = new EventEmitter();
102
121
  this.proposals = new Map(snapshot.proposals.map(([, proposal]) => {
103
122
  return [
104
123
  proposal.sequenceNumber,
@@ -301,12 +320,14 @@ exports.QuorumProposals = QuorumProposals;
301
320
  * @internal
302
321
  */
303
322
  class Quorum extends client_utils_1.TypedEventEmitter {
323
+ quorumClients;
324
+ quorumProposals;
325
+ isDisposed = false;
304
326
  get disposed() {
305
327
  return this.isDisposed;
306
328
  }
307
329
  constructor(members, proposals, values, sendProposal) {
308
330
  super();
309
- this.isDisposed = false;
310
331
  this.quorumClients = new QuorumClients(members);
311
332
  this.quorumClients.on("addMember", (clientId, details) => {
312
333
  this.emit("addMember", clientId, details);
@@ -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,CAAC,aAAa,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACI,UAAU;QAChB,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAc;QAC/C,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,WAAW,CACjB,GAAW,EACX,KAAc,EACd,cAAsB,EACtB,KAAc,EACd,oBAA4B;QAE5B,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CACtC,GAAG,EACH,KAAK,EACL,cAAc,EACd,KAAK,EACL,oBAAoB,CACpB,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,2BAA2B,CAAC,OAAkC;QACpE,IAAI,CAAC,eAAe,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAEM,kBAAkB,CAAC,SAAkB,EAAE,QAAiB;QAC9D,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IAEM,OAAO;QACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;CACD;AA/ID,wBA+IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport type {\n\tISequencedDocumentMessage,\n\tICommittedProposal,\n\tIQuorum,\n\tIQuorumProposals,\n\tISequencedProposal,\n} from \"@fluidframework/driver-definitions/internal\";\nimport events_pkg from \"events_pkg\";\nconst { EventEmitter } = events_pkg;\n\n/**\n * Structure for tracking proposals that have been sequenced but not approved yet.\n */\nclass PendingProposal implements ISequencedProposal {\n\tconstructor(\n\t\tpublic readonly sequenceNumber: number,\n\t\tpublic readonly key: string,\n\t\tpublic readonly value: unknown,\n\t\tpublic readonly local: boolean,\n\t) {}\n}\n\n/**\n * Snapshot format for a QuorumClients\n * @legacy @beta\n */\nexport type QuorumClientsSnapshot = [string, ISequencedClient][];\n\n/**\n * Snapshot format for a QuorumProposals\n * @legacy @beta\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type QuorumProposalsSnapshot = {\n\tproposals: [number, ISequencedProposal, string[]][];\n\tvalues: [string, ICommittedProposal][];\n};\n\n/**\n * Snapshot format for a Quorum\n * @legacy @beta\n */\nexport interface IQuorumSnapshot {\n\tmembers: QuorumClientsSnapshot;\n\tproposals: QuorumProposalsSnapshot[\"proposals\"];\n\tvalues: QuorumProposalsSnapshot[\"values\"];\n}\n\n/**\n * The QuorumClients is used to track members joining and leaving the collaboration session.\n * @internal\n */\nexport class QuorumClients\n\textends TypedEventEmitter<IQuorumClients[\"on\"]>\n\timplements IQuorumClients\n{\n\tprivate readonly members: Map<string, ISequencedClient>;\n\tprivate isDisposed: boolean = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\n\t/**\n\t * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.\n\t * Cleared immediately (set to undefined) when the cache becomes invalid.\n\t */\n\tprivate snapshotCache: QuorumClientsSnapshot | undefined;\n\n\tconstructor(snapshot: QuorumClientsSnapshot) {\n\t\tsuper();\n\n\t\tthis.members = new Map(snapshot);\n\t\tthis.snapshotCache = snapshot;\n\t}\n\n\t/**\n\t * Snapshots the current state of the QuorumClients\n\t * @returns a snapshot of the clients in the quorum\n\t */\n\tpublic snapshot(): QuorumClientsSnapshot {\n\t\tthis.snapshotCache ??= [...this.members];\n\n\t\treturn this.snapshotCache;\n\t}\n\n\t/**\n\t * Adds a new client to the quorum\n\t */\n\tpublic addMember(clientId: string, details: ISequencedClient): void {\n\t\tassert(!!clientId, 0x9a0 /* clientId has to be non-empty string */);\n\t\tassert(!this.members.has(clientId), 0x9a1 /* clientId not found */);\n\t\tthis.members.set(clientId, details);\n\t\tthis.emit(\"addMember\", clientId, details);\n\n\t\t// clear the cache\n\t\tthis.snapshotCache = undefined;\n\t}\n\n\t/**\n\t * Removes a client from the quorum\n\t */\n\tpublic removeMember(clientId: string): void {\n\t\tassert(!!clientId, 0x9a2 /* clientId has to be non-empty string */);\n\t\tassert(this.members.has(clientId), 0x9a3 /* clientId not found */);\n\t\tthis.members.delete(clientId);\n\t\tthis.emit(\"removeMember\", clientId);\n\n\t\t// clear the cache\n\t\tthis.snapshotCache = undefined;\n\t}\n\n\t/**\n\t * Retrieves all the members in the quorum\n\t */\n\tpublic getMembers(): Map<string, ISequencedClient> {\n\t\treturn new Map(this.members);\n\t}\n\n\t/**\n\t * Retrieves a specific member of the quorum\n\t */\n\tpublic getMember(clientId: string): ISequencedClient | undefined {\n\t\treturn this.members.get(clientId);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t}\n}\n\n/**\n * The QuorumProposals holds a key/value store. Proposed values become finalized in the store once all connected\n * clients have seen the proposal.\n * @internal\n */\nexport class QuorumProposals\n\textends TypedEventEmitter<IQuorumProposals[\"on\"]>\n\timplements IQuorumProposals\n{\n\tprivate readonly proposals: Map<number, PendingProposal>;\n\tprivate readonly values: Map<string, ICommittedProposal>;\n\tprivate isDisposed: boolean = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\n\t// Event emitter for changes to the environment that affect pending proposal promises.\n\tprivate readonly stateEvents = new EventEmitter();\n\n\t/**\n\t * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.\n\t * Cleared immediately (set to undefined) when the cache becomes invalid.\n\t */\n\tprivate proposalsSnapshotCache: QuorumProposalsSnapshot[\"proposals\"] | undefined;\n\tprivate valuesSnapshotCache: QuorumProposalsSnapshot[\"values\"] | undefined;\n\n\tconstructor(\n\t\tsnapshot: QuorumProposalsSnapshot,\n\t\tprivate readonly sendProposal: (key: string, value: unknown) => number,\n\t) {\n\t\tsuper();\n\n\t\tthis.proposals = new Map(\n\t\t\tsnapshot.proposals.map(([, proposal]) => {\n\t\t\t\treturn [\n\t\t\t\t\tproposal.sequenceNumber,\n\t\t\t\t\tnew PendingProposal(\n\t\t\t\t\t\tproposal.sequenceNumber,\n\t\t\t\t\t\tproposal.key,\n\t\t\t\t\t\tproposal.value,\n\t\t\t\t\t\tfalse, // local\n\t\t\t\t\t),\n\t\t\t\t] as [number, PendingProposal];\n\t\t\t}),\n\t\t);\n\t\tthis.values = new Map(snapshot.values);\n\t\tthis.proposalsSnapshotCache = snapshot.proposals;\n\t\tthis.valuesSnapshotCache = snapshot.values;\n\t}\n\n\t/**\n\t * Snapshots the current state of the QuorumProposals\n\t * @returns arrays of proposals and values\n\t */\n\tpublic snapshot(): QuorumProposalsSnapshot {\n\t\tthis.proposalsSnapshotCache ??= [...this.proposals].map(([sequenceNumber, proposal]) => [\n\t\t\tsequenceNumber,\n\t\t\t{ sequenceNumber, key: proposal.key, value: proposal.value },\n\t\t\t[], // rejections, which has been removed\n\t\t]);\n\t\tthis.valuesSnapshotCache ??= [...this.values];\n\n\t\treturn {\n\t\t\tproposals: this.proposalsSnapshotCache,\n\t\t\tvalues: this.valuesSnapshotCache,\n\t\t};\n\t}\n\n\t/**\n\t * Returns whether the quorum has achieved a consensus for the given key.\n\t */\n\tpublic has(key: string): boolean {\n\t\treturn this.values.has(key);\n\t}\n\n\t/**\n\t * Returns the consensus value for the given key\n\t */\n\tpublic get(key: string): unknown {\n\t\treturn this.values.get(key)?.value;\n\t}\n\n\t/**\n\t * Proposes a new value. Returns a promise that will either:\n\t * - Resolve when the proposal is accepted\n\t * - Reject if the proposal fails to send or if the QuorumProposals is disposed\n\t */\n\tpublic async propose(key: string, value: unknown): Promise<void> {\n\t\tconst clientSequenceNumber = this.sendProposal(key, value);\n\t\tif (clientSequenceNumber < 0) {\n\t\t\tthis.emit(\"error\", { eventName: \"ProposalInDisconnectedState\", key });\n\t\t\tthrow new Error(\"Can't propose in disconnected state\");\n\t\t}\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\t// The sequence number that our proposal was assigned and went pending.\n\t\t\t// If undefined, then it's not sequenced yet.\n\t\t\tlet thisProposalSequenceNumber: number | undefined;\n\n\t\t\t// A proposal goes through two phases before this promise resolves:\n\t\t\t// 1. Sequencing - waiting for the proposal to be ack'd by the server.\n\t\t\t// 2. Approval - waiting for the proposal to be approved by connected clients.\n\t\t\tconst localProposalSequencedHandler = (\n\t\t\t\tsequencedCSN: number,\n\t\t\t\tsequenceNumber: number,\n\t\t\t): void => {\n\t\t\t\tif (sequencedCSN === clientSequenceNumber) {\n\t\t\t\t\tthisProposalSequenceNumber = sequenceNumber;\n\t\t\t\t\tthis.stateEvents.off(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\t\t\tthis.stateEvents.off(\"disconnected\", disconnectedHandler);\n\t\t\t\t\tthis.stateEvents.on(\"localProposalApproved\", localProposalApprovedHandler);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst localProposalApprovedHandler = (sequenceNumber: number): void => {\n\t\t\t\t// Proposals can be uniquely identified by the sequenceNumber they were assigned.\n\t\t\t\tif (sequenceNumber === thisProposalSequenceNumber) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tremoveListeners();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// There are two error flows we consider: disconnect and disposal.\n\t\t\t// If we get disconnected before the proposal is sequenced, it has one of two possible futures:\n\t\t\t// 1. We reconnect and see the proposal was sequenced in the meantime.\n\t\t\t// -> The promise can still resolve, once it is approved.\n\t\t\t// 2. We reconnect and see the proposal was not sequenced in the meantime, so it will never sequence.\n\t\t\t// -> The promise rejects.\n\t\t\tconst disconnectedHandler = (): void => {\n\t\t\t\t// If we haven't seen the ack by the time we disconnect, we hope to see it by the time we reconnect.\n\t\t\t\tif (thisProposalSequenceNumber === undefined) {\n\t\t\t\t\tthis.stateEvents.once(\"connected\", () => {\n\t\t\t\t\t\t// If we don't see the ack by the time reconnection finishes, it failed to send.\n\t\t\t\t\t\tif (thisProposalSequenceNumber === undefined) {\n\t\t\t\t\t\t\treject(new Error(\"Client disconnected without successfully sending proposal\"));\n\t\t\t\t\t\t\tremoveListeners();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t\t// If the QuorumProposals is disposed of, we assume something catastrophic has happened\n\t\t\t// All outstanding proposals are considered rejected.\n\t\t\tconst disposedHandler = (): void => {\n\t\t\t\treject(new Error(\"QuorumProposals was disposed\"));\n\t\t\t\tremoveListeners();\n\t\t\t};\n\t\t\t// Convenience function to clean up our listeners.\n\t\t\tconst removeListeners = (): void => {\n\t\t\t\tthis.stateEvents.off(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\t\tthis.stateEvents.off(\"localProposalApproved\", localProposalApprovedHandler);\n\t\t\t\tthis.stateEvents.off(\"disconnected\", disconnectedHandler);\n\t\t\t\tthis.stateEvents.off(\"disposed\", disposedHandler);\n\t\t\t};\n\t\t\tthis.stateEvents.on(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\tthis.stateEvents.on(\"disconnected\", disconnectedHandler);\n\t\t\tthis.stateEvents.on(\"disposed\", disposedHandler);\n\t\t});\n\t}\n\n\t/**\n\t * Begins tracking a new proposal\n\t */\n\tpublic addProposal(\n\t\tkey: string,\n\t\tvalue: unknown,\n\t\tsequenceNumber: number,\n\t\tlocal: boolean,\n\t\tclientSequenceNumber: number,\n\t): void {\n\t\tassert(!this.proposals.has(sequenceNumber), 0x9a4 /* sequenceNumber not found */);\n\n\t\tconst proposal = new PendingProposal(sequenceNumber, key, value, local);\n\t\tthis.proposals.set(sequenceNumber, proposal);\n\n\t\t// Legacy event, from rejection support. May still have some use for clients to learn that a proposal is\n\t\t// likely to be approved soon.\n\t\tthis.emit(\"addProposal\", proposal);\n\n\t\tif (local) {\n\t\t\tthis.stateEvents.emit(\"localProposalSequenced\", clientSequenceNumber, sequenceNumber);\n\t\t}\n\n\t\t// clear the proposal cache\n\t\tthis.proposalsSnapshotCache = undefined;\n\t}\n\n\t/**\n\t * Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it\n\t * becomes an approved value.\n\t */\n\tpublic updateMinimumSequenceNumber(message: ISequencedDocumentMessage): void {\n\t\tconst msn = message.minimumSequenceNumber;\n\n\t\t// Accept proposals proposals whose sequenceNumber is <= the minimumSequenceNumber\n\n\t\t// Return a sorted list of approved proposals. We sort so that we apply them in their sequence number order\n\t\t// TODO this can be optimized if necessary to avoid the linear search+sort\n\t\tconst completed: PendingProposal[] = [];\n\t\tfor (const [sequenceNumber, proposal] of this.proposals) {\n\t\t\tif (sequenceNumber <= msn) {\n\t\t\t\tcompleted.push(proposal);\n\t\t\t}\n\t\t}\n\t\tcompleted.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n\n\t\tfor (const proposal of completed) {\n\t\t\tconst committedProposal: ICommittedProposal = {\n\t\t\t\tapprovalSequenceNumber: message.sequenceNumber,\n\t\t\t\t// No longer used. We still stamp a -1 for compat with older versions of the quorum.\n\t\t\t\t// Can be removed after 0.1035 and higher is ubiquitous.\n\t\t\t\tcommitSequenceNumber: -1,\n\t\t\t\tkey: proposal.key,\n\t\t\t\tsequenceNumber: proposal.sequenceNumber,\n\t\t\t\tvalue: proposal.value,\n\t\t\t};\n\n\t\t\tthis.values.set(committedProposal.key, committedProposal);\n\n\t\t\t// clear the values cache\n\t\t\tthis.valuesSnapshotCache = undefined;\n\n\t\t\t// check if there are multiple proposals with matching keys\n\t\t\tlet proposalSettled = false;\n\t\t\tlet proposalKeySeen = false;\n\t\t\tfor (const [, p] of this.proposals) {\n\t\t\t\tif (p.key === committedProposal.key) {\n\t\t\t\t\tif (proposalKeySeen) {\n\t\t\t\t\t\t// set proposalSettled to false if matching proposal key is not unique\n\t\t\t\t\t\tproposalSettled = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// set proposalSettled to true if the proposal key match is unique thus far\n\t\t\t\t\t\tproposalSettled = true;\n\t\t\t\t\t}\n\t\t\t\t\tproposalKeySeen = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.emit(\n\t\t\t\t\"approveProposal\",\n\t\t\t\tcommittedProposal.sequenceNumber,\n\t\t\t\tcommittedProposal.key,\n\t\t\t\tcommittedProposal.value,\n\t\t\t\tcommittedProposal.approvalSequenceNumber,\n\t\t\t);\n\n\t\t\t// emit approveProposalComplete when all pending proposals are processed\n\t\t\tif (proposalSettled) {\n\t\t\t\tthis.emit(\n\t\t\t\t\t\"approveProposalComplete\",\n\t\t\t\t\tcommittedProposal.sequenceNumber,\n\t\t\t\t\tcommittedProposal.key,\n\t\t\t\t\tcommittedProposal.value,\n\t\t\t\t\tcommittedProposal.approvalSequenceNumber,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.proposals.delete(proposal.sequenceNumber);\n\n\t\t\t// clear the proposals cache\n\t\t\tthis.proposalsSnapshotCache = undefined;\n\t\t\tif (proposal.local) {\n\t\t\t\tthis.stateEvents.emit(\"localProposalApproved\", proposal.sequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic setConnectionState(connected: boolean): void {\n\t\tif (connected) {\n\t\t\tthis.stateEvents.emit(\"connected\");\n\t\t} else {\n\t\t\tthis.stateEvents.emit(\"disconnected\");\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t\tthis.stateEvents.emit(\"disposed\");\n\t}\n}\n\n/**\n * A quorum represents all clients currently within the collaboration window. As well as the values\n * they have agreed upon and any pending proposals.\n * @internal\n */\nexport class Quorum extends TypedEventEmitter<IQuorum[\"on\"]> implements IQuorum {\n\tprivate readonly quorumClients: QuorumClients;\n\tprivate readonly quorumProposals: QuorumProposals;\n\tprivate readonly isDisposed: boolean = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\n\tconstructor(\n\t\tmembers: QuorumClientsSnapshot,\n\t\tproposals: QuorumProposalsSnapshot[\"proposals\"],\n\t\tvalues: QuorumProposalsSnapshot[\"values\"],\n\t\tsendProposal: (key: string, value: unknown) => number,\n\t) {\n\t\tsuper();\n\n\t\tthis.quorumClients = new QuorumClients(members);\n\t\tthis.quorumClients.on(\"addMember\", (clientId: string, details: ISequencedClient) => {\n\t\t\tthis.emit(\"addMember\", clientId, details);\n\t\t});\n\t\tthis.quorumClients.on(\"removeMember\", (clientId: string) => {\n\t\t\tthis.emit(\"removeMember\", clientId);\n\t\t});\n\n\t\tthis.quorumProposals = new QuorumProposals({ proposals, values }, sendProposal);\n\t\tthis.quorumProposals.on(\"addProposal\", (proposal: ISequencedProposal) => {\n\t\t\tthis.emit(\"addProposal\", proposal);\n\t\t});\n\t\tthis.quorumProposals.on(\n\t\t\t\"approveProposal\",\n\t\t\t(\n\t\t\t\tsequenceNumber: number,\n\t\t\t\tkey: string,\n\t\t\t\tvalue: unknown,\n\t\t\t\tapprovalSequenceNumber: number,\n\t\t\t) => {\n\t\t\t\tthis.emit(\"approveProposal\", sequenceNumber, key, value, approvalSequenceNumber);\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic close(): void {\n\t\tthis.removeAllListeners();\n\t}\n\n\t/**\n\t * Snapshots the entire quorum\n\t * @returns a quorum snapshot\n\t */\n\tpublic snapshot(): IQuorumSnapshot {\n\t\tconst members = this.quorumClients.snapshot();\n\t\tconst { proposals, values } = this.quorumProposals.snapshot();\n\t\treturn {\n\t\t\tmembers,\n\t\t\tproposals,\n\t\t\tvalues,\n\t\t};\n\t}\n\n\t/**\n\t * Returns whether the quorum has achieved a consensus for the given key.\n\t */\n\tpublic has(key: string): boolean {\n\t\treturn this.quorumProposals.has(key);\n\t}\n\n\t/**\n\t * Returns the consensus value for the given key\n\t */\n\tpublic get(key: string): unknown {\n\t\treturn this.quorumProposals.get(key);\n\t}\n\n\t/**\n\t * Adds a new client to the quorum\n\t */\n\tpublic addMember(clientId: string, details: ISequencedClient): void {\n\t\tthis.quorumClients.addMember(clientId, details);\n\t}\n\n\t/**\n\t * Removes a client from the quorum\n\t */\n\tpublic removeMember(clientId: string): void {\n\t\tthis.quorumClients.removeMember(clientId);\n\t}\n\n\t/**\n\t * Retrieves all the members in the quorum\n\t */\n\tpublic getMembers(): Map<string, ISequencedClient> {\n\t\treturn this.quorumClients.getMembers();\n\t}\n\n\t/**\n\t * Retrieves a specific member of the quorum\n\t */\n\tpublic getMember(clientId: string): ISequencedClient | undefined {\n\t\treturn this.quorumClients.getMember(clientId);\n\t}\n\n\t/**\n\t * Proposes a new value. Returns a promise that will resolve when the proposal is either accepted, or reject if\n\t * the proposal fails to send.\n\t */\n\tpublic async propose(key: string, value: unknown): Promise<void> {\n\t\treturn this.quorumProposals.propose(key, value);\n\t}\n\n\t/**\n\t * Begins tracking a new proposal\n\t */\n\tpublic addProposal(\n\t\tkey: string,\n\t\tvalue: unknown,\n\t\tsequenceNumber: number,\n\t\tlocal: boolean,\n\t\tclientSequenceNumber: number,\n\t): void {\n\t\treturn this.quorumProposals.addProposal(\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tsequenceNumber,\n\t\t\tlocal,\n\t\t\tclientSequenceNumber,\n\t\t);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it\n\t * becomes an approved value.\n\t */\n\tpublic updateMinimumSequenceNumber(message: ISequencedDocumentMessage): void {\n\t\tthis.quorumProposals.updateMinimumSequenceNumber(message);\n\t}\n\n\tpublic setConnectionState(connected: boolean, clientId?: string): void {\n\t\tthis.quorumProposals.setConnectionState(connected);\n\t}\n\n\tpublic dispose(): void {\n\t\tthrow new Error(\"Not implemented.\");\n\t}\n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CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB,EAAE,OAAyB;QAC3D,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,QAAgB;QACnC,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACI,UAAU;QAChB,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAc;QAC/C,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,WAAW,CACjB,GAAW,EACX,KAAc,EACd,cAAsB,EACtB,KAAc,EACd,oBAA4B;QAE5B,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CACtC,GAAG,EACH,KAAK,EACL,cAAc,EACd,KAAK,EACL,oBAAoB,CACpB,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,2BAA2B,CAAC,OAAkC;QACpE,IAAI,CAAC,eAAe,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAEM,kBAAkB,CAAC,SAAkB,EAAE,QAAiB;QAC9D,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IAEM,OAAO;QACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;CACD;AA/ID,wBA+IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport type {\n\tISequencedDocumentMessage,\n\tICommittedProposal,\n\tIQuorum,\n\tIQuorumProposals,\n\tISequencedProposal,\n} from \"@fluidframework/driver-definitions/internal\";\nimport events_pkg from \"events_pkg\";\nconst { EventEmitter } = events_pkg;\n\n/**\n * Structure for tracking proposals that have been sequenced but not approved yet.\n */\nclass PendingProposal implements ISequencedProposal {\n\tconstructor(\n\t\tpublic readonly sequenceNumber: number,\n\t\tpublic readonly key: string,\n\t\tpublic readonly value: unknown,\n\t\tpublic readonly local: boolean,\n\t) {}\n}\n\n/**\n * Snapshot format for a QuorumClients\n * @legacy @beta\n */\nexport type QuorumClientsSnapshot = [string, ISequencedClient][];\n\n/**\n * Snapshot format for a QuorumProposals\n * @legacy @beta\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type QuorumProposalsSnapshot = {\n\tproposals: [number, ISequencedProposal, string[]][];\n\tvalues: [string, ICommittedProposal][];\n};\n\n/**\n * Snapshot format for a Quorum\n * @legacy @beta\n */\nexport interface IQuorumSnapshot {\n\tmembers: QuorumClientsSnapshot;\n\tproposals: QuorumProposalsSnapshot[\"proposals\"];\n\tvalues: QuorumProposalsSnapshot[\"values\"];\n}\n\n/**\n * The QuorumClients is used to track members joining and leaving the collaboration session.\n * @internal\n */\nexport class QuorumClients\n\textends TypedEventEmitter<IQuorumClients[\"on\"]>\n\timplements IQuorumClients\n{\n\tprivate readonly members: Map<string, ISequencedClient>;\n\tprivate isDisposed: boolean = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\n\t/**\n\t * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.\n\t * Cleared immediately (set to undefined) when the cache becomes invalid.\n\t */\n\tprivate snapshotCache: QuorumClientsSnapshot | undefined;\n\n\tconstructor(snapshot: QuorumClientsSnapshot) {\n\t\tsuper();\n\n\t\tthis.members = new Map(snapshot);\n\t\tthis.snapshotCache = snapshot;\n\t}\n\n\t/**\n\t * Snapshots the current state of the QuorumClients\n\t * @returns a snapshot of the clients in the quorum\n\t */\n\tpublic snapshot(): QuorumClientsSnapshot {\n\t\tthis.snapshotCache ??= [...this.members];\n\n\t\treturn this.snapshotCache;\n\t}\n\n\t/**\n\t * Adds a new client to the quorum\n\t */\n\tpublic addMember(clientId: string, details: ISequencedClient): void {\n\t\tassert(!!clientId, 0x9a0 /* clientId has to be non-empty string */);\n\t\tassert(!this.members.has(clientId), 0x9a1 /* clientId not found */);\n\t\tthis.members.set(clientId, details);\n\t\tthis.emit(\"addMember\", clientId, details);\n\n\t\t// clear the cache\n\t\tthis.snapshotCache = undefined;\n\t}\n\n\t/**\n\t * Removes a client from the quorum\n\t */\n\tpublic removeMember(clientId: string): void {\n\t\tassert(!!clientId, 0x9a2 /* clientId has to be non-empty string */);\n\t\tassert(this.members.has(clientId), 0x9a3 /* clientId not found */);\n\t\tthis.members.delete(clientId);\n\t\tthis.emit(\"removeMember\", clientId);\n\n\t\t// clear the cache\n\t\tthis.snapshotCache = undefined;\n\t}\n\n\t/**\n\t * Retrieves all the members in the quorum\n\t */\n\tpublic getMembers(): Map<string, ISequencedClient> {\n\t\treturn new Map(this.members);\n\t}\n\n\t/**\n\t * Retrieves a specific member of the quorum\n\t */\n\tpublic getMember(clientId: string): ISequencedClient | undefined {\n\t\treturn this.members.get(clientId);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t}\n}\n\n/**\n * The QuorumProposals holds a key/value store. Proposed values become finalized in the store once all connected\n * clients have seen the proposal.\n * @internal\n */\nexport class QuorumProposals\n\textends TypedEventEmitter<IQuorumProposals[\"on\"]>\n\timplements IQuorumProposals\n{\n\tprivate readonly proposals: Map<number, PendingProposal>;\n\tprivate readonly values: Map<string, ICommittedProposal>;\n\tprivate isDisposed: boolean = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\n\t// Event emitter for changes to the environment that affect pending proposal promises.\n\tprivate readonly stateEvents = new EventEmitter();\n\n\t/**\n\t * Cached snapshot state, to avoid unnecessary deep clones on repeated snapshot calls.\n\t * Cleared immediately (set to undefined) when the cache becomes invalid.\n\t */\n\tprivate proposalsSnapshotCache: QuorumProposalsSnapshot[\"proposals\"] | undefined;\n\tprivate valuesSnapshotCache: QuorumProposalsSnapshot[\"values\"] | undefined;\n\n\tconstructor(\n\t\tsnapshot: QuorumProposalsSnapshot,\n\t\tprivate readonly sendProposal: (key: string, value: unknown) => number,\n\t) {\n\t\tsuper();\n\n\t\tthis.proposals = new Map(\n\t\t\tsnapshot.proposals.map(([, proposal]) => {\n\t\t\t\treturn [\n\t\t\t\t\tproposal.sequenceNumber,\n\t\t\t\t\tnew PendingProposal(\n\t\t\t\t\t\tproposal.sequenceNumber,\n\t\t\t\t\t\tproposal.key,\n\t\t\t\t\t\tproposal.value,\n\t\t\t\t\t\tfalse, // local\n\t\t\t\t\t),\n\t\t\t\t] as [number, PendingProposal];\n\t\t\t}),\n\t\t);\n\t\tthis.values = new Map(snapshot.values);\n\t\tthis.proposalsSnapshotCache = snapshot.proposals;\n\t\tthis.valuesSnapshotCache = snapshot.values;\n\t}\n\n\t/**\n\t * Snapshots the current state of the QuorumProposals\n\t * @returns arrays of proposals and values\n\t */\n\tpublic snapshot(): QuorumProposalsSnapshot {\n\t\tthis.proposalsSnapshotCache ??= [...this.proposals].map(([sequenceNumber, proposal]) => [\n\t\t\tsequenceNumber,\n\t\t\t{ sequenceNumber, key: proposal.key, value: proposal.value },\n\t\t\t[], // rejections, which has been removed\n\t\t]);\n\t\tthis.valuesSnapshotCache ??= [...this.values];\n\n\t\treturn {\n\t\t\tproposals: this.proposalsSnapshotCache,\n\t\t\tvalues: this.valuesSnapshotCache,\n\t\t};\n\t}\n\n\t/**\n\t * Returns whether the quorum has achieved a consensus for the given key.\n\t */\n\tpublic has(key: string): boolean {\n\t\treturn this.values.has(key);\n\t}\n\n\t/**\n\t * Returns the consensus value for the given key\n\t */\n\tpublic get(key: string): unknown {\n\t\treturn this.values.get(key)?.value;\n\t}\n\n\t/**\n\t * Proposes a new value. Returns a promise that will either:\n\t * - Resolve when the proposal is accepted\n\t * - Reject if the proposal fails to send or if the QuorumProposals is disposed\n\t */\n\tpublic async propose(key: string, value: unknown): Promise<void> {\n\t\tconst clientSequenceNumber = this.sendProposal(key, value);\n\t\tif (clientSequenceNumber < 0) {\n\t\t\tthis.emit(\"error\", { eventName: \"ProposalInDisconnectedState\", key });\n\t\t\tthrow new Error(\"Can't propose in disconnected state\");\n\t\t}\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\t// The sequence number that our proposal was assigned and went pending.\n\t\t\t// If undefined, then it's not sequenced yet.\n\t\t\tlet thisProposalSequenceNumber: number | undefined;\n\n\t\t\t// A proposal goes through two phases before this promise resolves:\n\t\t\t// 1. Sequencing - waiting for the proposal to be ack'd by the server.\n\t\t\t// 2. Approval - waiting for the proposal to be approved by connected clients.\n\t\t\tconst localProposalSequencedHandler = (\n\t\t\t\tsequencedCSN: number,\n\t\t\t\tsequenceNumber: number,\n\t\t\t): void => {\n\t\t\t\tif (sequencedCSN === clientSequenceNumber) {\n\t\t\t\t\tthisProposalSequenceNumber = sequenceNumber;\n\t\t\t\t\tthis.stateEvents.off(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\t\t\tthis.stateEvents.off(\"disconnected\", disconnectedHandler);\n\t\t\t\t\tthis.stateEvents.on(\"localProposalApproved\", localProposalApprovedHandler);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst localProposalApprovedHandler = (sequenceNumber: number): void => {\n\t\t\t\t// Proposals can be uniquely identified by the sequenceNumber they were assigned.\n\t\t\t\tif (sequenceNumber === thisProposalSequenceNumber) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tremoveListeners();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// There are two error flows we consider: disconnect and disposal.\n\t\t\t// If we get disconnected before the proposal is sequenced, it has one of two possible futures:\n\t\t\t// 1. We reconnect and see the proposal was sequenced in the meantime.\n\t\t\t// -> The promise can still resolve, once it is approved.\n\t\t\t// 2. We reconnect and see the proposal was not sequenced in the meantime, so it will never sequence.\n\t\t\t// -> The promise rejects.\n\t\t\tconst disconnectedHandler = (): void => {\n\t\t\t\t// If we haven't seen the ack by the time we disconnect, we hope to see it by the time we reconnect.\n\t\t\t\tif (thisProposalSequenceNumber === undefined) {\n\t\t\t\t\tthis.stateEvents.once(\"connected\", () => {\n\t\t\t\t\t\t// If we don't see the ack by the time reconnection finishes, it failed to send.\n\t\t\t\t\t\tif (thisProposalSequenceNumber === undefined) {\n\t\t\t\t\t\t\treject(new Error(\"Client disconnected without successfully sending proposal\"));\n\t\t\t\t\t\t\tremoveListeners();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t\t// If the QuorumProposals is disposed of, we assume something catastrophic has happened\n\t\t\t// All outstanding proposals are considered rejected.\n\t\t\tconst disposedHandler = (): void => {\n\t\t\t\treject(new Error(\"QuorumProposals was disposed\"));\n\t\t\t\tremoveListeners();\n\t\t\t};\n\t\t\t// Convenience function to clean up our listeners.\n\t\t\tconst removeListeners = (): void => {\n\t\t\t\tthis.stateEvents.off(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\t\tthis.stateEvents.off(\"localProposalApproved\", localProposalApprovedHandler);\n\t\t\t\tthis.stateEvents.off(\"disconnected\", disconnectedHandler);\n\t\t\t\tthis.stateEvents.off(\"disposed\", disposedHandler);\n\t\t\t};\n\t\t\tthis.stateEvents.on(\"localProposalSequenced\", localProposalSequencedHandler);\n\t\t\tthis.stateEvents.on(\"disconnected\", disconnectedHandler);\n\t\t\tthis.stateEvents.on(\"disposed\", disposedHandler);\n\t\t});\n\t}\n\n\t/**\n\t * Begins tracking a new proposal\n\t */\n\tpublic addProposal(\n\t\tkey: string,\n\t\tvalue: unknown,\n\t\tsequenceNumber: number,\n\t\tlocal: boolean,\n\t\tclientSequenceNumber: number,\n\t): void {\n\t\tassert(!this.proposals.has(sequenceNumber), 0x9a4 /* sequenceNumber not found */);\n\n\t\tconst proposal = new PendingProposal(sequenceNumber, key, value, local);\n\t\tthis.proposals.set(sequenceNumber, proposal);\n\n\t\t// Legacy event, from rejection support. May still have some use for clients to learn that a proposal is\n\t\t// likely to be approved soon.\n\t\tthis.emit(\"addProposal\", proposal);\n\n\t\tif (local) {\n\t\t\tthis.stateEvents.emit(\"localProposalSequenced\", clientSequenceNumber, sequenceNumber);\n\t\t}\n\n\t\t// clear the proposal cache\n\t\tthis.proposalsSnapshotCache = undefined;\n\t}\n\n\t/**\n\t * Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it\n\t * becomes an approved value.\n\t */\n\tpublic updateMinimumSequenceNumber(message: ISequencedDocumentMessage): void {\n\t\tconst msn = message.minimumSequenceNumber;\n\n\t\t// Accept proposals proposals whose sequenceNumber is <= the minimumSequenceNumber\n\n\t\t// Return a sorted list of approved proposals. We sort so that we apply them in their sequence number order\n\t\t// TODO this can be optimized if necessary to avoid the linear search+sort\n\t\tconst completed: PendingProposal[] = [];\n\t\tfor (const [sequenceNumber, proposal] of this.proposals) {\n\t\t\tif (sequenceNumber <= msn) {\n\t\t\t\tcompleted.push(proposal);\n\t\t\t}\n\t\t}\n\t\tcompleted.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n\n\t\tfor (const proposal of completed) {\n\t\t\tconst committedProposal: ICommittedProposal = {\n\t\t\t\tapprovalSequenceNumber: message.sequenceNumber,\n\t\t\t\t// No longer used. We still stamp a -1 for compat with older versions of the quorum.\n\t\t\t\t// Can be removed after 0.1035 and higher is ubiquitous.\n\t\t\t\tcommitSequenceNumber: -1,\n\t\t\t\tkey: proposal.key,\n\t\t\t\tsequenceNumber: proposal.sequenceNumber,\n\t\t\t\tvalue: proposal.value,\n\t\t\t};\n\n\t\t\tthis.values.set(committedProposal.key, committedProposal);\n\n\t\t\t// clear the values cache\n\t\t\tthis.valuesSnapshotCache = undefined;\n\n\t\t\t// check if there are multiple proposals with matching keys\n\t\t\tlet proposalSettled = false;\n\t\t\tlet proposalKeySeen = false;\n\t\t\tfor (const [, p] of this.proposals) {\n\t\t\t\tif (p.key === committedProposal.key) {\n\t\t\t\t\tif (proposalKeySeen) {\n\t\t\t\t\t\t// set proposalSettled to false if matching proposal key is not unique\n\t\t\t\t\t\tproposalSettled = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// set proposalSettled to true if the proposal key match is unique thus far\n\t\t\t\t\t\tproposalSettled = true;\n\t\t\t\t\t}\n\t\t\t\t\tproposalKeySeen = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.emit(\n\t\t\t\t\"approveProposal\",\n\t\t\t\tcommittedProposal.sequenceNumber,\n\t\t\t\tcommittedProposal.key,\n\t\t\t\tcommittedProposal.value,\n\t\t\t\tcommittedProposal.approvalSequenceNumber,\n\t\t\t);\n\n\t\t\t// emit approveProposalComplete when all pending proposals are processed\n\t\t\tif (proposalSettled) {\n\t\t\t\tthis.emit(\n\t\t\t\t\t\"approveProposalComplete\",\n\t\t\t\t\tcommittedProposal.sequenceNumber,\n\t\t\t\t\tcommittedProposal.key,\n\t\t\t\t\tcommittedProposal.value,\n\t\t\t\t\tcommittedProposal.approvalSequenceNumber,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.proposals.delete(proposal.sequenceNumber);\n\n\t\t\t// clear the proposals cache\n\t\t\tthis.proposalsSnapshotCache = undefined;\n\t\t\tif (proposal.local) {\n\t\t\t\tthis.stateEvents.emit(\"localProposalApproved\", proposal.sequenceNumber);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic setConnectionState(connected: boolean): void {\n\t\tif (connected) {\n\t\t\tthis.stateEvents.emit(\"connected\");\n\t\t} else {\n\t\t\tthis.stateEvents.emit(\"disconnected\");\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t\tthis.stateEvents.emit(\"disposed\");\n\t}\n}\n\n/**\n * A quorum represents all clients currently within the collaboration window. As well as the values\n * they have agreed upon and any pending proposals.\n * @internal\n */\nexport class Quorum extends TypedEventEmitter<IQuorum[\"on\"]> implements IQuorum {\n\tprivate readonly quorumClients: QuorumClients;\n\tprivate readonly quorumProposals: QuorumProposals;\n\tprivate readonly isDisposed: boolean = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\n\tconstructor(\n\t\tmembers: QuorumClientsSnapshot,\n\t\tproposals: QuorumProposalsSnapshot[\"proposals\"],\n\t\tvalues: QuorumProposalsSnapshot[\"values\"],\n\t\tsendProposal: (key: string, value: unknown) => number,\n\t) {\n\t\tsuper();\n\n\t\tthis.quorumClients = new QuorumClients(members);\n\t\tthis.quorumClients.on(\"addMember\", (clientId: string, details: ISequencedClient) => {\n\t\t\tthis.emit(\"addMember\", clientId, details);\n\t\t});\n\t\tthis.quorumClients.on(\"removeMember\", (clientId: string) => {\n\t\t\tthis.emit(\"removeMember\", clientId);\n\t\t});\n\n\t\tthis.quorumProposals = new QuorumProposals({ proposals, values }, sendProposal);\n\t\tthis.quorumProposals.on(\"addProposal\", (proposal: ISequencedProposal) => {\n\t\t\tthis.emit(\"addProposal\", proposal);\n\t\t});\n\t\tthis.quorumProposals.on(\n\t\t\t\"approveProposal\",\n\t\t\t(\n\t\t\t\tsequenceNumber: number,\n\t\t\t\tkey: string,\n\t\t\t\tvalue: unknown,\n\t\t\t\tapprovalSequenceNumber: number,\n\t\t\t) => {\n\t\t\t\tthis.emit(\"approveProposal\", sequenceNumber, key, value, approvalSequenceNumber);\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic close(): void {\n\t\tthis.removeAllListeners();\n\t}\n\n\t/**\n\t * Snapshots the entire quorum\n\t * @returns a quorum snapshot\n\t */\n\tpublic snapshot(): IQuorumSnapshot {\n\t\tconst members = this.quorumClients.snapshot();\n\t\tconst { proposals, values } = this.quorumProposals.snapshot();\n\t\treturn {\n\t\t\tmembers,\n\t\t\tproposals,\n\t\t\tvalues,\n\t\t};\n\t}\n\n\t/**\n\t * Returns whether the quorum has achieved a consensus for the given key.\n\t */\n\tpublic has(key: string): boolean {\n\t\treturn this.quorumProposals.has(key);\n\t}\n\n\t/**\n\t * Returns the consensus value for the given key\n\t */\n\tpublic get(key: string): unknown {\n\t\treturn this.quorumProposals.get(key);\n\t}\n\n\t/**\n\t * Adds a new client to the quorum\n\t */\n\tpublic addMember(clientId: string, details: ISequencedClient): void {\n\t\tthis.quorumClients.addMember(clientId, details);\n\t}\n\n\t/**\n\t * Removes a client from the quorum\n\t */\n\tpublic removeMember(clientId: string): void {\n\t\tthis.quorumClients.removeMember(clientId);\n\t}\n\n\t/**\n\t * Retrieves all the members in the quorum\n\t */\n\tpublic getMembers(): Map<string, ISequencedClient> {\n\t\treturn this.quorumClients.getMembers();\n\t}\n\n\t/**\n\t * Retrieves a specific member of the quorum\n\t */\n\tpublic getMember(clientId: string): ISequencedClient | undefined {\n\t\treturn this.quorumClients.getMember(clientId);\n\t}\n\n\t/**\n\t * Proposes a new value. Returns a promise that will resolve when the proposal is either accepted, or reject if\n\t * the proposal fails to send.\n\t */\n\tpublic async propose(key: string, value: unknown): Promise<void> {\n\t\treturn this.quorumProposals.propose(key, value);\n\t}\n\n\t/**\n\t * Begins tracking a new proposal\n\t */\n\tpublic addProposal(\n\t\tkey: string,\n\t\tvalue: unknown,\n\t\tsequenceNumber: number,\n\t\tlocal: boolean,\n\t\tclientSequenceNumber: number,\n\t): void {\n\t\treturn this.quorumProposals.addProposal(\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tsequenceNumber,\n\t\t\tlocal,\n\t\t\tclientSequenceNumber,\n\t\t);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number. If the MSN advances past the sequence number for any proposal then it\n\t * becomes an approved value.\n\t */\n\tpublic updateMinimumSequenceNumber(message: ISequencedDocumentMessage): void {\n\t\tthis.quorumProposals.updateMinimumSequenceNumber(message);\n\t}\n\n\tpublic setConnectionState(connected: boolean, clientId?: string): void {\n\t\tthis.quorumProposals.setConnectionState(connected);\n\t}\n\n\tpublic dispose(): void {\n\t\tthrow new Error(\"Not implemented.\");\n\t}\n}\n"]}
package/dist/protocol.js CHANGED
@@ -4,7 +4,9 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.wrapProtocolHandlerBuilder = exports.protocolHandlerShouldProcessSignal = exports.ProtocolHandler = exports.SignalType = void 0;
7
+ exports.ProtocolHandler = exports.SignalType = void 0;
8
+ exports.protocolHandlerShouldProcessSignal = protocolHandlerShouldProcessSignal;
9
+ exports.wrapProtocolHandlerBuilder = wrapProtocolHandlerBuilder;
8
10
  const internal_1 = require("@fluidframework/driver-definitions/internal");
9
11
  const internal_2 = require("@fluidframework/driver-utils/internal");
10
12
  const index_js_1 = require("./protocol/index.js");
@@ -15,6 +17,8 @@ exports.SignalType = {
15
17
  Clear: "clear", // used only by client for synthetic signals
16
18
  };
17
19
  class ProtocolHandler extends index_js_1.ProtocolOpHandler {
20
+ audience;
21
+ shouldClientHaveLeft;
18
22
  constructor(attributes, quorumSnapshot,
19
23
  // TODO: use a real type (breaking change)
20
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -99,7 +103,6 @@ function protocolHandlerShouldProcessSignal(message) {
99
103
  }
100
104
  return false;
101
105
  }
102
- exports.protocolHandlerShouldProcessSignal = protocolHandlerShouldProcessSignal;
103
106
  function wrapProtocolHandlerBuilder(builder, signalAudience) {
104
107
  return (attributes, snapshot, sendProposal) => {
105
108
  const baseHandler = builder(attributes, snapshot, sendProposal);
@@ -141,5 +144,4 @@ function wrapProtocolHandlerBuilder(builder, signalAudience) {
141
144
  });
142
145
  };
143
146
  }
144
- exports.wrapProtocolHandlerBuilder = wrapProtocolHandlerBuilder;
145
147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AAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC5C,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AA/CD,gEA+CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudienceOwner } from \"@fluidframework/container-definitions/internal\";\nimport {\n\ttype IDocumentAttributes,\n\ttype IProcessMessageResult,\n\ttype ISignalClient,\n\tMessageType,\n\ttype ISequencedDocumentMessage,\n\ttype ISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canBeCoalescedByService } from \"@fluidframework/driver-utils/internal\";\n\nimport {\n\ttype IBaseProtocolHandler,\n\ttype IQuorumSnapshot,\n\tProtocolOpHandler,\n} from \"./protocol/index.js\";\n\n// ADO: #1986: Start using enum from protocol-base.\nexport const SignalType = {\n\tClientJoin: \"join\", // same value as MessageType.ClientJoin,\n\tClientLeave: \"leave\", // same value as MessageType.ClientLeave,\n\tClear: \"clear\", // used only by client for synthetic signals\n} as const;\n\ninterface SystemSignalContent {\n\ttype: (typeof SignalType)[keyof typeof SignalType];\n\tcontent?: unknown;\n}\n\ninterface InboundSystemSignal<TSignalContent extends SystemSignalContent>\n\textends ISignalMessage<{ type: never; content: TSignalContent }> {\n\t// eslint-disable-next-line @rushstack/no-new-null -- `null` is used in JSON protocol to indicate system message\n\treadonly clientId: null;\n}\n\ntype ClientJoinSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.ClientJoin;\n\tcontent: ISignalClient;\n}>;\n\ntype ClientLeaveSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.ClientLeave;\n\tcontent: string; // clientId of leaving client\n}>;\n\ntype ClearClientsSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.Clear;\n}>;\n\ntype AudienceSignal = ClientJoinSignal | ClientLeaveSignal | ClearClientsSignal;\n\n/**\n * Function to be used for creating a protocol handler.\n * @legacy @beta\n */\nexport type ProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => IProtocolHandler;\n\n/**\n * @legacy @beta\n */\nexport interface IProtocolHandler extends IBaseProtocolHandler {\n\treadonly audience: IAudienceOwner;\n\tprocessSignal(message: ISignalMessage);\n}\n\n/**\n * More specific version of {@link IProtocolHandler} with narrower call\n * constraints for {@link IProtocolHandler.processSignal}.\n */\nexport interface ProtocolHandlerInternal extends IProtocolHandler {\n\t/**\n\t * Process the audience related signal.\n\t * @privateRemarks\n\t * Internally, only {@link AudienceSignal} messages need handling.\n\t */\n\tprocessSignal(message: AudienceSignal): void;\n}\n\n/**\n * Function to be used for creating a protocol handler.\n *\n * @remarks This is the same are {@link ProtocolHandlerBuilder} but\n * returns the {@link ProtocolHandlerInternal} which has narrower\n * expectations for `processSignal`.\n */\nexport type InternalProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => ProtocolHandlerInternal;\n\nexport class ProtocolHandler extends ProtocolOpHandler implements ProtocolHandlerInternal {\n\tconstructor(\n\t\tattributes: IDocumentAttributes,\n\t\tquorumSnapshot: IQuorumSnapshot,\n\t\t// TODO: use a real type (breaking change)\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tsendProposal: (key: string, value: any) => number,\n\t\tpublic readonly audience: IAudienceOwner,\n\t\tprivate readonly shouldClientHaveLeft: (clientId: string) => boolean,\n\t) {\n\t\tsuper(\n\t\t\tattributes.minimumSequenceNumber,\n\t\t\tattributes.sequenceNumber,\n\t\t\tquorumSnapshot.members,\n\t\t\tquorumSnapshot.proposals,\n\t\t\tquorumSnapshot.values,\n\t\t\tsendProposal,\n\t\t);\n\n\t\tfor (const [clientId, member] of this.quorum.getMembers()) {\n\t\t\taudience.addMember(clientId, member.client);\n\t\t}\n\n\t\t// Join / leave signals are ignored for \"write\" clients in favor of join / leave ops\n\t\tthis.quorum.on(\"addMember\", (clientId, details) =>\n\t\t\taudience.addMember(clientId, details.client),\n\t\t);\n\t\tthis.quorum.on(\"removeMember\", (clientId) => audience.removeMember(clientId));\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// Check and report if we're getting messages from a clientId that we previously\n\t\t// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tif (message.clientId != null) {\n\t\t\tconst client = this.quorum.getMember(message.clientId);\n\n\t\t\tif (client === undefined && message.type !== MessageType.ClientJoin) {\n\t\t\t\t// pre-0.58 error message: messageClientIdMissingFromQuorum\n\t\t\t\tthrow new Error(\"Remote message's clientId is missing from the quorum\");\n\t\t\t}\n\n\t\t\t// Here checking canBeCoalescedByService is used as an approximation of \"is benign to process despite being unexpected\".\n\t\t\t// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the\n\t\t\t// document we don't need to blow up aggressively.\n\t\t\tif (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {\n\t\t\t\t// pre-0.58 error message: messageClientIdShouldHaveLeft\n\t\t\t\tthrow new Error(\"Remote message's clientId already should have left\");\n\t\t\t}\n\t\t}\n\n\t\treturn super.processMessage(message, local);\n\t}\n\n\tpublic processSignal(message: AudienceSignal): void {\n\t\tconst innerContent = message.content;\n\t\tswitch (innerContent.type) {\n\t\t\tcase SignalType.Clear: {\n\t\t\t\tconst members = this.audience.getMembers();\n\t\t\t\tfor (const [clientId, client] of members) {\n\t\t\t\t\tif (client.mode === \"read\") {\n\t\t\t\t\t\tthis.audience.removeMember(clientId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\tconst newClient = innerContent.content;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (newClient.client.mode === \"read\") {\n\t\t\t\t\tthis.audience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\tconst leftClientId = innerContent.content;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (this.audience.getMember(leftClientId)?.mode === \"read\") {\n\t\t\t\t\tthis.audience.removeMember(leftClientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Function to check whether the protocol handler should process the Signal.\n * The protocol handler should strictly handle only ClientJoin, ClientLeave\n * and Clear signal types.\n */\nexport function protocolHandlerShouldProcessSignal(\n\tmessage: ISignalMessage,\n): message is AudienceSignal {\n\t// Signal originates from server\n\tif (message.clientId === null) {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\treturn (\n\t\t\tinnerContent.type === SignalType.Clear ||\n\t\t\tinnerContent.type === SignalType.ClientJoin ||\n\t\t\tinnerContent.type === SignalType.ClientLeave\n\t\t);\n\t}\n\treturn false;\n}\n\nexport function wrapProtocolHandlerBuilder(\n\tbuilder: ProtocolHandlerBuilder,\n\tsignalAudience: IAudienceOwner,\n): InternalProtocolHandlerBuilder {\n\treturn (\n\t\tattributes: IDocumentAttributes,\n\t\tsnapshot: IQuorumSnapshot,\n\t\tsendProposal: (key: string, value: unknown) => number,\n\t): ProtocolHandlerInternal => {\n\t\tconst baseHandler = builder(attributes, snapshot, sendProposal);\n\t\t// Create proxy handler with an overridden processSignal method.\n\t\t// Use a Proxy since base may use [dynamic] property getters.\n\t\treturn new Proxy(baseHandler, {\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop === \"processSignal\") {\n\t\t\t\t\treturn (message: AudienceSignal) => {\n\t\t\t\t\t\tconst innerContent = message.content;\n\t\t\t\t\t\tswitch (innerContent.type) {\n\t\t\t\t\t\t\tcase SignalType.Clear: {\n\t\t\t\t\t\t\t\tconst members = signalAudience.getMembers();\n\t\t\t\t\t\t\t\tfor (const clientId of members.keys()) {\n\t\t\t\t\t\t\t\t\tsignalAudience.removeMember(clientId);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\t\t\t\t\tconst newClient = innerContent.content;\n\t\t\t\t\t\t\t\tsignalAudience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\t\t\t\t\tconst leftClientId = innerContent.content;\n\t\t\t\t\t\t\t\tsignalAudience.removeMember(leftClientId);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttarget.processSignal(message);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAsMH,gFAaC;AAED,gEA+CC;AAjQD,0EAOqD;AACrD,oEAAgF;AAEhF,kDAI6B;AAE7B,mDAAmD;AACtC,QAAA,UAAU,GAAG;IACzB,UAAU,EAAE,MAAM,EAAE,wCAAwC;IAC5D,WAAW,EAAE,OAAO,EAAE,yCAAyC;IAC/D,KAAK,EAAE,OAAO,EAA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,OAAO,CAAC,OAAO,CAAC;wBACrC,QAAQ,YAAY,CAAC,IAAI,EAAE,CAAC;4BAC3B,KAAK,kBAAU,CAAC,KAAK,CAAC,CAAC,CAAC;gCACvB,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,EAAE,CAAC;gCAC5C,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;oCACvC,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;gCACvC,CAAC;gCACD,MAAM;4BACP,CAAC;4BACD,KAAK,kBAAU,CAAC,UAAU,CAAC,CAAC,CAAC;gCAC5B,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;gCACvC,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;gCAC/D,MAAM;4BACP,CAAC;4BACD,KAAK,kBAAU,CAAC,WAAW,CAAC,CAAC,CAAC;gCAC7B,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC;gCAC1C,cAAc,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;gCAC1C,MAAM;4BACP,CAAC;4BACD,OAAO,CAAC,CAAC,CAAC;gCACT,MAAM;4BACP,CAAC;wBACF,CAAC;wBACD,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBAC/B,CAAC,CAAC;gBACH,CAAC;gBACD,+DAA+D;gBAC/D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC5C,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudienceOwner } from \"@fluidframework/container-definitions/internal\";\nimport {\n\ttype IDocumentAttributes,\n\ttype IProcessMessageResult,\n\ttype ISignalClient,\n\tMessageType,\n\ttype ISequencedDocumentMessage,\n\ttype ISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canBeCoalescedByService } from \"@fluidframework/driver-utils/internal\";\n\nimport {\n\ttype IBaseProtocolHandler,\n\ttype IQuorumSnapshot,\n\tProtocolOpHandler,\n} from \"./protocol/index.js\";\n\n// ADO: #1986: Start using enum from protocol-base.\nexport const SignalType = {\n\tClientJoin: \"join\", // same value as MessageType.ClientJoin,\n\tClientLeave: \"leave\", // same value as MessageType.ClientLeave,\n\tClear: \"clear\", // used only by client for synthetic signals\n} as const;\n\ninterface SystemSignalContent {\n\ttype: (typeof SignalType)[keyof typeof SignalType];\n\tcontent?: unknown;\n}\n\ninterface InboundSystemSignal<TSignalContent extends SystemSignalContent>\n\textends ISignalMessage<{ type: never; content: TSignalContent }> {\n\t// eslint-disable-next-line @rushstack/no-new-null -- `null` is used in JSON protocol to indicate system message\n\treadonly clientId: null;\n}\n\ntype ClientJoinSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.ClientJoin;\n\tcontent: ISignalClient;\n}>;\n\ntype ClientLeaveSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.ClientLeave;\n\tcontent: string; // clientId of leaving client\n}>;\n\ntype ClearClientsSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.Clear;\n}>;\n\ntype AudienceSignal = ClientJoinSignal | ClientLeaveSignal | ClearClientsSignal;\n\n/**\n * Function to be used for creating a protocol handler.\n * @legacy @beta\n */\nexport type ProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => IProtocolHandler;\n\n/**\n * @legacy @beta\n */\nexport interface IProtocolHandler extends IBaseProtocolHandler {\n\treadonly audience: IAudienceOwner;\n\tprocessSignal(message: ISignalMessage);\n}\n\n/**\n * More specific version of {@link IProtocolHandler} with narrower call\n * constraints for {@link IProtocolHandler.processSignal}.\n */\nexport interface ProtocolHandlerInternal extends IProtocolHandler {\n\t/**\n\t * Process the audience related signal.\n\t * @privateRemarks\n\t * Internally, only {@link AudienceSignal} messages need handling.\n\t */\n\tprocessSignal(message: AudienceSignal): void;\n}\n\n/**\n * Function to be used for creating a protocol handler.\n *\n * @remarks This is the same are {@link ProtocolHandlerBuilder} but\n * returns the {@link ProtocolHandlerInternal} which has narrower\n * expectations for `processSignal`.\n */\nexport type InternalProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => ProtocolHandlerInternal;\n\nexport class ProtocolHandler extends ProtocolOpHandler implements ProtocolHandlerInternal {\n\tconstructor(\n\t\tattributes: IDocumentAttributes,\n\t\tquorumSnapshot: IQuorumSnapshot,\n\t\t// TODO: use a real type (breaking change)\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tsendProposal: (key: string, value: any) => number,\n\t\tpublic readonly audience: IAudienceOwner,\n\t\tprivate readonly shouldClientHaveLeft: (clientId: string) => boolean,\n\t) {\n\t\tsuper(\n\t\t\tattributes.minimumSequenceNumber,\n\t\t\tattributes.sequenceNumber,\n\t\t\tquorumSnapshot.members,\n\t\t\tquorumSnapshot.proposals,\n\t\t\tquorumSnapshot.values,\n\t\t\tsendProposal,\n\t\t);\n\n\t\tfor (const [clientId, member] of this.quorum.getMembers()) {\n\t\t\taudience.addMember(clientId, member.client);\n\t\t}\n\n\t\t// Join / leave signals are ignored for \"write\" clients in favor of join / leave ops\n\t\tthis.quorum.on(\"addMember\", (clientId, details) =>\n\t\t\taudience.addMember(clientId, details.client),\n\t\t);\n\t\tthis.quorum.on(\"removeMember\", (clientId) => audience.removeMember(clientId));\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// Check and report if we're getting messages from a clientId that we previously\n\t\t// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tif (message.clientId != null) {\n\t\t\tconst client = this.quorum.getMember(message.clientId);\n\n\t\t\tif (client === undefined && message.type !== MessageType.ClientJoin) {\n\t\t\t\t// pre-0.58 error message: messageClientIdMissingFromQuorum\n\t\t\t\tthrow new Error(\"Remote message's clientId is missing from the quorum\");\n\t\t\t}\n\n\t\t\t// Here checking canBeCoalescedByService is used as an approximation of \"is benign to process despite being unexpected\".\n\t\t\t// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the\n\t\t\t// document we don't need to blow up aggressively.\n\t\t\tif (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {\n\t\t\t\t// pre-0.58 error message: messageClientIdShouldHaveLeft\n\t\t\t\tthrow new Error(\"Remote message's clientId already should have left\");\n\t\t\t}\n\t\t}\n\n\t\treturn super.processMessage(message, local);\n\t}\n\n\tpublic processSignal(message: AudienceSignal): void {\n\t\tconst innerContent = message.content;\n\t\tswitch (innerContent.type) {\n\t\t\tcase SignalType.Clear: {\n\t\t\t\tconst members = this.audience.getMembers();\n\t\t\t\tfor (const [clientId, client] of members) {\n\t\t\t\t\tif (client.mode === \"read\") {\n\t\t\t\t\t\tthis.audience.removeMember(clientId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\tconst newClient = innerContent.content;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (newClient.client.mode === \"read\") {\n\t\t\t\t\tthis.audience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\tconst leftClientId = innerContent.content;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (this.audience.getMember(leftClientId)?.mode === \"read\") {\n\t\t\t\t\tthis.audience.removeMember(leftClientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Function to check whether the protocol handler should process the Signal.\n * The protocol handler should strictly handle only ClientJoin, ClientLeave\n * and Clear signal types.\n */\nexport function protocolHandlerShouldProcessSignal(\n\tmessage: ISignalMessage,\n): message is AudienceSignal {\n\t// Signal originates from server\n\tif (message.clientId === null) {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\treturn (\n\t\t\tinnerContent.type === SignalType.Clear ||\n\t\t\tinnerContent.type === SignalType.ClientJoin ||\n\t\t\tinnerContent.type === SignalType.ClientLeave\n\t\t);\n\t}\n\treturn false;\n}\n\nexport function wrapProtocolHandlerBuilder(\n\tbuilder: ProtocolHandlerBuilder,\n\tsignalAudience: IAudienceOwner,\n): InternalProtocolHandlerBuilder {\n\treturn (\n\t\tattributes: IDocumentAttributes,\n\t\tsnapshot: IQuorumSnapshot,\n\t\tsendProposal: (key: string, value: unknown) => number,\n\t): ProtocolHandlerInternal => {\n\t\tconst baseHandler = builder(attributes, snapshot, sendProposal);\n\t\t// Create proxy handler with an overridden processSignal method.\n\t\t// Use a Proxy since base may use [dynamic] property getters.\n\t\treturn new Proxy(baseHandler, {\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop === \"processSignal\") {\n\t\t\t\t\treturn (message: AudienceSignal) => {\n\t\t\t\t\t\tconst innerContent = message.content;\n\t\t\t\t\t\tswitch (innerContent.type) {\n\t\t\t\t\t\t\tcase SignalType.Clear: {\n\t\t\t\t\t\t\t\tconst members = signalAudience.getMembers();\n\t\t\t\t\t\t\t\tfor (const clientId of members.keys()) {\n\t\t\t\t\t\t\t\t\tsignalAudience.removeMember(clientId);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\t\t\t\t\tconst newClient = innerContent.content;\n\t\t\t\t\t\t\t\tsignalAudience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\t\t\t\t\tconst leftClientId = innerContent.content;\n\t\t\t\t\t\t\t\tsignalAudience.removeMember(leftClientId);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttarget.processSignal(message);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
@@ -10,6 +10,9 @@ exports.ProtocolTreeStorageService = void 0;
10
10
  * the protocol summary, using the provided callback to add it if necessary.
11
11
  */
12
12
  class ProtocolTreeStorageService {
13
+ internalStorageService;
14
+ addProtocolSummaryIfMissing;
15
+ shouldSummarizeProtocolTree;
13
16
  /**
14
17
  *
15
18
  * @param internalStorageService - Document storage service responsible to make api calls to the storage.
@@ -34,6 +37,13 @@ class ProtocolTreeStorageService {
34
37
  get disposed() {
35
38
  return this.internalStorageService.disposed;
36
39
  }
40
+ getSnapshotTree;
41
+ getSnapshot;
42
+ getVersions;
43
+ createBlob;
44
+ readBlob;
45
+ downloadSummary;
46
+ dispose;
37
47
  async uploadSummaryWithContext(summary, context) {
38
48
  return this.shouldSummarizeProtocolTree()
39
49
  ? this.internalStorageService.uploadSummaryWithContext(this.addProtocolSummaryIfMissing(summary), context)
@@ -1 +1 @@
1
- {"version":3,"file":"protocolTreeDocumentStorageService.js","sourceRoot":"","sources":["../src/protocolTreeDocumentStorageService.ts"],"names":[],"mapp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,EACzC,OAAO,CACP;YACF,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC;CACD;AA9CD,gEA8CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IDisposable } from \"@fluidframework/core-interfaces\";\nimport type { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions/internal\";\n\n/**\n * A storage service wrapper whose sole job is to intercept calls to uploadSummaryWithContext and ensure they include\n * the protocol summary, using the provided callback to add it if necessary.\n */\nexport class ProtocolTreeStorageService implements IDocumentStorageService, IDisposable {\n\t/**\n\t *\n\t * @param internalStorageService - Document storage service responsible to make api calls to the storage.\n\t * @param addProtocolSummaryIfMissing - Function to add protocol summary tree to the summary. Used in scenarios where single-commit summaries are used.\n\t * @param shouldSummarizeProtocolTree - Callback function to learn about the service preference on whether single-commit summaries are enabled.\n\t */\n\tconstructor(\n\t\tprivate readonly internalStorageService: IDocumentStorageService & IDisposable,\n\t\tprivate readonly addProtocolSummaryIfMissing: (summaryTree: ISummaryTree) => ISummaryTree,\n\t\tprivate readonly shouldSummarizeProtocolTree: () => boolean,\n\t) {\n\t\tthis.getSnapshotTree = internalStorageService.getSnapshotTree.bind(internalStorageService);\n\t\tthis.getSnapshot = internalStorageService.getSnapshot?.bind(internalStorageService);\n\t\tthis.getVersions = internalStorageService.getVersions.bind(internalStorageService);\n\t\tthis.createBlob = internalStorageService.createBlob.bind(internalStorageService);\n\t\tthis.readBlob = internalStorageService.readBlob.bind(internalStorageService);\n\t\tthis.downloadSummary = internalStorageService.downloadSummary.bind(internalStorageService);\n\t\tthis.dispose = internalStorageService.dispose.bind(internalStorageService);\n\t}\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\treturn this.internalStorageService.policies;\n\t}\n\tpublic get disposed(): boolean {\n\t\treturn this.internalStorageService.disposed;\n\t}\n\n\tgetSnapshotTree: IDocumentStorageService[\"getSnapshotTree\"];\n\tgetSnapshot: IDocumentStorageService[\"getSnapshot\"];\n\tgetVersions: IDocumentStorageService[\"getVersions\"];\n\tcreateBlob: IDocumentStorageService[\"createBlob\"];\n\treadBlob: IDocumentStorageService[\"readBlob\"];\n\tdownloadSummary: IDocumentStorageService[\"downloadSummary\"];\n\tdispose: IDisposable[\"dispose\"];\n\n\tasync uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\treturn this.shouldSummarizeProtocolTree()\n\t\t\t? this.internalStorageService.uploadSummaryWithContext(\n\t\t\t\t\tthis.addProtocolSummaryIfMissing(summary),\n\t\t\t\t\tcontext,\n\t\t\t\t)\n\t\t\t: this.internalStorageService.uploadSummaryWithContext(summary, context);\n\t}\n}\n"]}
1
+ {"version":3,"file":"protocolTreeDocumentStorageService.js","sourceRoot":"","sources":["../src/protocolTreeDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH;;;GAGG;AACH,MAAa,0BAA0B;IAQpB;IACA;IACA;IATlB;;;;;OAKG;IACH,YACkB,sBAA6D,EAC7D,2BAAwE,EACxE,2BAA0C;QAF1C,2BAAsB,GAAtB,sBAAsB,CAAuC;QAC7D,gCAA2B,GAA3B,2BAA2B,CAA6C;QACxE,gCAA2B,GAA3B,2BAA2B,CAAe;QAE3D,IAAI,CAAC,eAAe,GAAG,sBAAsB,CAAC,eAAe,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC3F,IAAI,CAAC,WAAW,GAAG,sBAAsB,CAAC,WAAW,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACpF,IAAI,CAAC,WAAW,GAAG,sBAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACnF,IAAI,CAAC,UAAU,GAAG,sBAAsB,CAAC,UAAU,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACjF,IAAI,CAAC,QAAQ,GAAG,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC7E,IAAI,CAAC,eAAe,GAAG,sBAAsB,CAAC,eAAe,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC3F,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC5E,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;IAC7C,CAAC;IAED,eAAe,CAA6C;IAC5D,WAAW,CAAyC;IACpD,WAAW,CAAyC;IACpD,UAAU,CAAwC;IAClD,QAAQ,CAAsC;IAC9C,eAAe,CAA6C;IAC5D,OAAO,CAAyB;IAEhC,KAAK,CAAC,wBAAwB,CAC7B,OAAqB,EACrB,OAAwB;QAExB,OAAO,IAAI,CAAC,2BAA2B,EAAE;YACxC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,wBAAwB,CACpD,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,EACzC,OAAO,CACP;YACF,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC;CACD;AA9CD,gEA8CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IDisposable } from \"@fluidframework/core-interfaces\";\nimport type { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions/internal\";\n\n/**\n * A storage service wrapper whose sole job is to intercept calls to uploadSummaryWithContext and ensure they include\n * the protocol summary, using the provided callback to add it if necessary.\n */\nexport class ProtocolTreeStorageService implements IDocumentStorageService, IDisposable {\n\t/**\n\t *\n\t * @param internalStorageService - Document storage service responsible to make api calls to the storage.\n\t * @param addProtocolSummaryIfMissing - Function to add protocol summary tree to the summary. Used in scenarios where single-commit summaries are used.\n\t * @param shouldSummarizeProtocolTree - Callback function to learn about the service preference on whether single-commit summaries are enabled.\n\t */\n\tconstructor(\n\t\tprivate readonly internalStorageService: IDocumentStorageService & IDisposable,\n\t\tprivate readonly addProtocolSummaryIfMissing: (summaryTree: ISummaryTree) => ISummaryTree,\n\t\tprivate readonly shouldSummarizeProtocolTree: () => boolean,\n\t) {\n\t\tthis.getSnapshotTree = internalStorageService.getSnapshotTree.bind(internalStorageService);\n\t\tthis.getSnapshot = internalStorageService.getSnapshot?.bind(internalStorageService);\n\t\tthis.getVersions = internalStorageService.getVersions.bind(internalStorageService);\n\t\tthis.createBlob = internalStorageService.createBlob.bind(internalStorageService);\n\t\tthis.readBlob = internalStorageService.readBlob.bind(internalStorageService);\n\t\tthis.downloadSummary = internalStorageService.downloadSummary.bind(internalStorageService);\n\t\tthis.dispose = internalStorageService.dispose.bind(internalStorageService);\n\t}\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\treturn this.internalStorageService.policies;\n\t}\n\tpublic get disposed(): boolean {\n\t\treturn this.internalStorageService.disposed;\n\t}\n\n\tgetSnapshotTree: IDocumentStorageService[\"getSnapshotTree\"];\n\tgetSnapshot: IDocumentStorageService[\"getSnapshot\"];\n\tgetVersions: IDocumentStorageService[\"getVersions\"];\n\tcreateBlob: IDocumentStorageService[\"createBlob\"];\n\treadBlob: IDocumentStorageService[\"readBlob\"];\n\tdownloadSummary: IDocumentStorageService[\"downloadSummary\"];\n\tdispose: IDisposable[\"dispose\"];\n\n\tasync uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\treturn this.shouldSummarizeProtocolTree()\n\t\t\t? this.internalStorageService.uploadSummaryWithContext(\n\t\t\t\t\tthis.addProtocolSummaryIfMissing(summary),\n\t\t\t\t\tcontext,\n\t\t\t\t)\n\t\t\t: this.internalStorageService.uploadSummaryWithContext(summary, context);\n\t}\n}\n"]}
package/dist/quorum.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.initQuorumValuesFromCodeDetails = void 0;
7
+ exports.initQuorumValuesFromCodeDetails = initQuorumValuesFromCodeDetails;
8
8
  function initQuorumValuesFromCodeDetails(source) {
9
9
  // Seed the base quorum to be an empty list with a code quorum set
10
10
  const committedCodeProposal = {
@@ -16,5 +16,4 @@ function initQuorumValuesFromCodeDetails(source) {
16
16
  };
17
17
  return [["code", committedCodeProposal]];
18
18
  }
19
- exports.initQuorumValuesFromCodeDetails = initQuorumValuesFromCodeDetails;
20
19
  //# sourceMappingURL=quorum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"quorum.js","sourceRoot":"","sources":["../src/quorum.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,SAAgB,+BAA+B,CAC9C,MAAyB;IAEzB,kEAAkE;IAClE,MAAM,qBAAqB,GAAuB;QACjD,GAAG,EAAE,MAAM;QACX,KAAK,EAAE,MAAM;QACb,sBAAsB,EAAE,CAAC;QACzB,oBAAoB,EAAE,CAAC;QACvB,cAAc,EAAE,CAAC;KACjB,CAAC;IACF,OAAO,CAAC,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAC1C,CAAC;AAZD,0EAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidCodeDetails } from \"@fluidframework/container-definitions/internal\";\nimport type { ICommittedProposal } from \"@fluidframework/driver-definitions/internal\";\n\nexport function initQuorumValuesFromCodeDetails(\n\tsource: IFluidCodeDetails,\n): [string, ICommittedProposal][] {\n\t// Seed the base quorum to be an empty list with a code quorum set\n\tconst committedCodeProposal: ICommittedProposal = {\n\t\tkey: \"code\",\n\t\tvalue: source,\n\t\tapprovalSequenceNumber: 0,\n\t\tcommitSequenceNumber: 0,\n\t\tsequenceNumber: 0,\n\t};\n\treturn [[\"code\", committedCodeProposal]];\n}\n"]}
1
+ {"version":3,"file":"quorum.js","sourceRoot":"","sources":["../src/quorum.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAKH,0EAYC;AAZD,SAAgB,+BAA+B,CAC9C,MAAyB;IAEzB,kEAAkE;IAClE,MAAM,qBAAqB,GAAuB;QACjD,GAAG,EAAE,MAAM;QACX,KAAK,EAAE,MAAM;QACb,sBAAsB,EAAE,CAAC;QACzB,oBAAoB,EAAE,CAAC;QACvB,cAAc,EAAE,CAAC;KACjB,CAAC;IACF,OAAO,CAAC,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidCodeDetails } from \"@fluidframework/container-definitions/internal\";\nimport type { ICommittedProposal } from \"@fluidframework/driver-definitions/internal\";\n\nexport function initQuorumValuesFromCodeDetails(\n\tsource: IFluidCodeDetails,\n): [string, ICommittedProposal][] {\n\t// Seed the base quorum to be an empty list with a code quorum set\n\tconst committedCodeProposal: ICommittedProposal = {\n\t\tkey: \"code\",\n\t\tvalue: source,\n\t\tapprovalSequenceNumber: 0,\n\t\tcommitSequenceNumber: 0,\n\t\tsequenceNumber: 0,\n\t};\n\treturn [[\"code\", committedCodeProposal]];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"retriableDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/retriableDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,W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,MAAM,GAEnB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAUnB,WAAW,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC;IAe7E,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAO9C,WAAW,CAGvB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUT,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IA8BL,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAO9D,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO5E,OAAO,CAAC,oBAAoB;YAiBd,YAAY;CAY1B"}
@@ -9,11 +9,15 @@ const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const internal_2 = require("@fluidframework/driver-utils/internal");
10
10
  const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
11
  class RetriableDocumentStorageService {
12
+ internalStorageServiceP;
13
+ logger;
14
+ maxRetries;
15
+ _disposed = false;
16
+ internalStorageService;
12
17
  constructor(internalStorageServiceP, logger, maxRetries) {
13
18
  this.internalStorageServiceP = internalStorageServiceP;
14
19
  this.logger = logger;
15
20
  this.maxRetries = maxRetries;
16
- this._disposed = false;
17
21
  this.internalStorageServiceP
18
22
  .then((s) => (this.internalStorageService = s))
19
23
  .catch(() => { });