@fluidframework/container-loader 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.1

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 (246) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/api-report/container-loader.api.md +13 -13
  3. package/dist/attachment.d.ts +6 -9
  4. package/dist/attachment.d.ts.map +1 -1
  5. package/dist/attachment.js +5 -5
  6. package/dist/attachment.js.map +1 -1
  7. package/dist/audience.d.ts +1 -1
  8. package/dist/audience.d.ts.map +1 -1
  9. package/dist/audience.js +4 -4
  10. package/dist/audience.js.map +1 -1
  11. package/dist/catchUpMonitor.d.ts +1 -1
  12. package/dist/catchUpMonitor.d.ts.map +1 -1
  13. package/dist/catchUpMonitor.js +2 -2
  14. package/dist/catchUpMonitor.js.map +1 -1
  15. package/dist/connectionManager.d.ts +4 -4
  16. package/dist/connectionManager.d.ts.map +1 -1
  17. package/dist/connectionManager.js +48 -43
  18. package/dist/connectionManager.js.map +1 -1
  19. package/dist/connectionStateHandler.d.ts +3 -3
  20. package/dist/connectionStateHandler.d.ts.map +1 -1
  21. package/dist/connectionStateHandler.js +27 -27
  22. package/dist/connectionStateHandler.js.map +1 -1
  23. package/dist/container.d.ts +9 -46
  24. package/dist/container.d.ts.map +1 -1
  25. package/dist/container.js +105 -116
  26. package/dist/container.js.map +1 -1
  27. package/dist/containerContext.d.ts +19 -7
  28. package/dist/containerContext.d.ts.map +1 -1
  29. package/dist/containerContext.js +7 -2
  30. package/dist/containerContext.js.map +1 -1
  31. package/dist/containerStorageAdapter.d.ts +3 -3
  32. package/dist/containerStorageAdapter.d.ts.map +1 -1
  33. package/dist/containerStorageAdapter.js +6 -6
  34. package/dist/containerStorageAdapter.js.map +1 -1
  35. package/dist/contracts.d.ts +4 -3
  36. package/dist/contracts.d.ts.map +1 -1
  37. package/dist/contracts.js +2 -2
  38. package/dist/contracts.js.map +1 -1
  39. package/dist/debugLogger.d.ts +2 -1
  40. package/dist/debugLogger.d.ts.map +1 -1
  41. package/dist/debugLogger.js +4 -4
  42. package/dist/debugLogger.js.map +1 -1
  43. package/dist/deltaManager.d.ts +11 -7
  44. package/dist/deltaManager.d.ts.map +1 -1
  45. package/dist/deltaManager.js +53 -50
  46. package/dist/deltaManager.js.map +1 -1
  47. package/dist/deltaQueue.d.ts +1 -1
  48. package/dist/deltaQueue.d.ts.map +1 -1
  49. package/dist/deltaQueue.js +5 -5
  50. package/dist/deltaQueue.js.map +1 -1
  51. package/dist/error.d.ts +3 -2
  52. package/dist/error.d.ts.map +1 -1
  53. package/dist/error.js +5 -5
  54. package/dist/error.js.map +1 -1
  55. package/dist/legacy.d.ts +29 -0
  56. package/dist/loader.d.ts +4 -4
  57. package/dist/loader.d.ts.map +1 -1
  58. package/dist/loader.js +23 -23
  59. package/dist/loader.js.map +1 -1
  60. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
  61. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
  62. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
  63. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  64. package/dist/noopHeuristic.d.ts +1 -1
  65. package/dist/noopHeuristic.d.ts.map +1 -1
  66. package/dist/noopHeuristic.js +6 -6
  67. package/dist/noopHeuristic.js.map +1 -1
  68. package/dist/packageVersion.d.ts +1 -1
  69. package/dist/packageVersion.js +1 -1
  70. package/dist/packageVersion.js.map +1 -1
  71. package/dist/protocol.d.ts +1 -1
  72. package/dist/protocol.d.ts.map +1 -1
  73. package/dist/protocol.js +2 -2
  74. package/dist/protocol.js.map +1 -1
  75. package/dist/protocolTreeDocumentStorageService.d.ts +4 -4
  76. package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
  77. package/dist/protocolTreeDocumentStorageService.js.map +1 -1
  78. package/dist/public.d.ts +14 -0
  79. package/dist/quorum.d.ts +1 -1
  80. package/dist/quorum.d.ts.map +1 -1
  81. package/dist/quorum.js +4 -0
  82. package/dist/quorum.js.map +1 -1
  83. package/dist/retriableDocumentStorageService.d.ts +2 -2
  84. package/dist/retriableDocumentStorageService.d.ts.map +1 -1
  85. package/dist/retriableDocumentStorageService.js +7 -7
  86. package/dist/retriableDocumentStorageService.js.map +1 -1
  87. package/dist/serializedStateManager.d.ts +86 -16
  88. package/dist/serializedStateManager.d.ts.map +1 -1
  89. package/dist/serializedStateManager.js +182 -82
  90. package/dist/serializedStateManager.js.map +1 -1
  91. package/dist/utils.d.ts +24 -9
  92. package/dist/utils.d.ts.map +1 -1
  93. package/dist/utils.js +82 -25
  94. package/dist/utils.js.map +1 -1
  95. package/internal.d.ts +11 -0
  96. package/legacy.d.ts +11 -0
  97. package/lib/attachment.d.ts +6 -9
  98. package/lib/attachment.d.ts.map +1 -1
  99. package/lib/attachment.js +1 -1
  100. package/lib/attachment.js.map +1 -1
  101. package/lib/audience.d.ts +1 -1
  102. package/lib/audience.d.ts.map +1 -1
  103. package/lib/audience.js +1 -1
  104. package/lib/audience.js.map +1 -1
  105. package/lib/catchUpMonitor.d.ts +1 -1
  106. package/lib/catchUpMonitor.d.ts.map +1 -1
  107. package/lib/catchUpMonitor.js +1 -1
  108. package/lib/catchUpMonitor.js.map +1 -1
  109. package/lib/connectionManager.d.ts +4 -4
  110. package/lib/connectionManager.d.ts.map +1 -1
  111. package/lib/connectionManager.js +11 -6
  112. package/lib/connectionManager.js.map +1 -1
  113. package/lib/connectionStateHandler.d.ts +3 -3
  114. package/lib/connectionStateHandler.d.ts.map +1 -1
  115. package/lib/connectionStateHandler.js +2 -2
  116. package/lib/connectionStateHandler.js.map +1 -1
  117. package/lib/container.d.ts +9 -46
  118. package/lib/container.d.ts.map +1 -1
  119. package/lib/container.js +37 -48
  120. package/lib/container.js.map +1 -1
  121. package/lib/containerContext.d.ts +19 -7
  122. package/lib/containerContext.d.ts.map +1 -1
  123. package/lib/containerContext.js +7 -2
  124. package/lib/containerContext.js.map +1 -1
  125. package/lib/containerStorageAdapter.d.ts +3 -3
  126. package/lib/containerStorageAdapter.d.ts.map +1 -1
  127. package/lib/containerStorageAdapter.js +2 -2
  128. package/lib/containerStorageAdapter.js.map +1 -1
  129. package/lib/contracts.d.ts +4 -3
  130. package/lib/contracts.d.ts.map +1 -1
  131. package/lib/contracts.js +1 -1
  132. package/lib/contracts.js.map +1 -1
  133. package/lib/debugLogger.d.ts +2 -1
  134. package/lib/debugLogger.d.ts.map +1 -1
  135. package/lib/debugLogger.js +1 -1
  136. package/lib/debugLogger.js.map +1 -1
  137. package/lib/deltaManager.d.ts +11 -7
  138. package/lib/deltaManager.d.ts.map +1 -1
  139. package/lib/deltaManager.js +13 -10
  140. package/lib/deltaManager.js.map +1 -1
  141. package/lib/deltaQueue.d.ts +1 -1
  142. package/lib/deltaQueue.d.ts.map +1 -1
  143. package/lib/deltaQueue.js +2 -2
  144. package/lib/deltaQueue.js.map +1 -1
  145. package/lib/error.d.ts +3 -2
  146. package/lib/error.d.ts.map +1 -1
  147. package/lib/error.js +2 -2
  148. package/lib/error.js.map +1 -1
  149. package/lib/legacy.d.ts +29 -0
  150. package/lib/loader.d.ts +4 -4
  151. package/lib/loader.d.ts.map +1 -1
  152. package/lib/loader.js +4 -4
  153. package/lib/loader.js.map +1 -1
  154. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
  155. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
  156. package/lib/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
  157. package/lib/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  158. package/lib/noopHeuristic.d.ts +1 -1
  159. package/lib/noopHeuristic.d.ts.map +1 -1
  160. package/lib/noopHeuristic.js +2 -2
  161. package/lib/noopHeuristic.js.map +1 -1
  162. package/lib/packageVersion.d.ts +1 -1
  163. package/lib/packageVersion.js +1 -1
  164. package/lib/packageVersion.js.map +1 -1
  165. package/lib/protocol.d.ts +1 -1
  166. package/lib/protocol.d.ts.map +1 -1
  167. package/lib/protocol.js +1 -1
  168. package/lib/protocol.js.map +1 -1
  169. package/lib/protocolTreeDocumentStorageService.d.ts +4 -4
  170. package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
  171. package/lib/protocolTreeDocumentStorageService.js.map +1 -1
  172. package/lib/public.d.ts +14 -0
  173. package/lib/quorum.d.ts +1 -1
  174. package/lib/quorum.d.ts.map +1 -1
  175. package/lib/quorum.js +4 -0
  176. package/lib/quorum.js.map +1 -1
  177. package/lib/retriableDocumentStorageService.d.ts +2 -2
  178. package/lib/retriableDocumentStorageService.d.ts.map +1 -1
  179. package/lib/retriableDocumentStorageService.js +3 -3
  180. package/lib/retriableDocumentStorageService.js.map +1 -1
  181. package/lib/serializedStateManager.d.ts +86 -16
  182. package/lib/serializedStateManager.d.ts.map +1 -1
  183. package/lib/serializedStateManager.js +174 -77
  184. package/lib/serializedStateManager.js.map +1 -1
  185. package/lib/utils.d.ts +24 -9
  186. package/lib/utils.d.ts.map +1 -1
  187. package/lib/utils.js +69 -15
  188. package/lib/utils.js.map +1 -1
  189. package/package.json +37 -58
  190. package/src/attachment.ts +10 -8
  191. package/src/audience.ts +3 -2
  192. package/src/catchUpMonitor.ts +2 -2
  193. package/src/connectionManager.ts +27 -20
  194. package/src/connectionStateHandler.ts +7 -7
  195. package/src/container.ts +90 -143
  196. package/src/containerContext.ts +22 -12
  197. package/src/containerStorageAdapter.ts +7 -6
  198. package/src/contracts.ts +4 -5
  199. package/src/debugLogger.ts +3 -4
  200. package/src/deltaManager.ts +40 -30
  201. package/src/deltaQueue.ts +2 -2
  202. package/src/error.ts +5 -4
  203. package/src/loader.ts +25 -23
  204. package/src/location-redirection-utilities/resolveWithLocationRedirection.ts +4 -4
  205. package/src/noopHeuristic.ts +3 -3
  206. package/src/packageVersion.ts +1 -1
  207. package/src/protocol.ts +2 -2
  208. package/src/protocolTreeDocumentStorageService.ts +4 -1
  209. package/src/quorum.ts +2 -1
  210. package/src/retriableDocumentStorageService.ts +6 -5
  211. package/src/serializedStateManager.ts +299 -111
  212. package/src/utils.ts +103 -24
  213. package/api-extractor-cjs.json +0 -8
  214. package/dist/container-loader-alpha.d.ts +0 -275
  215. package/dist/container-loader-beta.d.ts +0 -101
  216. package/dist/container-loader-public.d.ts +0 -101
  217. package/dist/container-loader-untrimmed.d.ts +0 -331
  218. package/lib/container-loader-alpha.d.ts +0 -275
  219. package/lib/container-loader-beta.d.ts +0 -101
  220. package/lib/container-loader-public.d.ts +0 -101
  221. package/lib/container-loader-untrimmed.d.ts +0 -331
  222. package/lib/test/attachment.spec.js +0 -380
  223. package/lib/test/attachment.spec.js.map +0 -1
  224. package/lib/test/catchUpMonitor.spec.js +0 -88
  225. package/lib/test/catchUpMonitor.spec.js.map +0 -1
  226. package/lib/test/connectionManager.spec.js +0 -201
  227. package/lib/test/connectionManager.spec.js.map +0 -1
  228. package/lib/test/connectionStateHandler.spec.js +0 -555
  229. package/lib/test/connectionStateHandler.spec.js.map +0 -1
  230. package/lib/test/container.spec.js +0 -64
  231. package/lib/test/container.spec.js.map +0 -1
  232. package/lib/test/deltaManager.spec.js +0 -405
  233. package/lib/test/deltaManager.spec.js.map +0 -1
  234. package/lib/test/loader.spec.js +0 -212
  235. package/lib/test/loader.spec.js.map +0 -1
  236. package/lib/test/locationRedirectionTests.spec.js +0 -44
  237. package/lib/test/locationRedirectionTests.spec.js.map +0 -1
  238. package/lib/test/serializedStateManager.spec.js +0 -148
  239. package/lib/test/serializedStateManager.spec.js.map +0 -1
  240. package/lib/test/snapshotConversionTest.spec.js +0 -79
  241. package/lib/test/snapshotConversionTest.spec.js.map +0 -1
  242. package/lib/test/types/validateContainerLoaderPrevious.generated.js +0 -38
  243. package/lib/test/types/validateContainerLoaderPrevious.generated.js.map +0 -1
  244. package/lib/test/utils.spec.js +0 -31
  245. package/lib/test/utils.spec.js.map +0 -1
  246. /package/{dist → lib}/tsdoc-metadata.json +0 -0
@@ -2,43 +2,113 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { IGetPendingLocalStateProps, IRuntime } from "@fluidframework/container-definitions/internal";
6
+ import { IDocumentStorageService, IResolvedUrl, ISnapshot } from "@fluidframework/driver-definitions/internal";
5
7
  import { ISequencedDocumentMessage, ISnapshotTree, IVersion } from "@fluidframework/protocol-definitions";
6
- import { IGetPendingLocalStateProps, IRuntime } from "@fluidframework/container-definitions";
7
8
  import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
8
- import { IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
9
+ import { MonitoringContext } from "@fluidframework/telemetry-utils/internal";
9
10
  import { ISerializableBlobContents } from "./containerStorageAdapter.js";
10
- import { IPendingContainerState } from "./container.js";
11
+ export interface SnapshotWithBlobs {
12
+ /**
13
+ * Snapshot from which container initially loaded.
14
+ */
15
+ baseSnapshot: ISnapshotTree;
16
+ /**
17
+ * Serializable blobs from the base snapshot. Used to load offline since
18
+ * storage is not available.
19
+ */
20
+ snapshotBlobs: ISerializableBlobContents;
21
+ }
22
+ /**
23
+ * State saved by a container at close time, to be used to load a new instance
24
+ * of the container to the same state
25
+ * @internal
26
+ */
27
+ export interface IPendingContainerState extends SnapshotWithBlobs {
28
+ attached: true;
29
+ pendingRuntimeState: unknown;
30
+ /**
31
+ * All ops since base snapshot sequence number up to the latest op
32
+ * seen when the container was closed. Used to apply stashed (saved pending)
33
+ * ops at the same sequence number at which they were made.
34
+ */
35
+ savedOps: ISequencedDocumentMessage[];
36
+ url: string;
37
+ clientId?: string;
38
+ }
39
+ /**
40
+ * State saved by a container in detached state, to be used to load a new instance
41
+ * of the container to the same state (rehydrate)
42
+ * @internal
43
+ */
44
+ export interface IPendingDetachedContainerState extends SnapshotWithBlobs {
45
+ attached: false;
46
+ hasAttachmentBlobs: boolean;
47
+ pendingRuntimeState?: unknown;
48
+ }
49
+ export interface ISnapshotInfo extends SnapshotWithBlobs {
50
+ snapshotSequenceNumber: number;
51
+ }
11
52
  export declare class SerializedStateManager {
12
53
  private readonly pendingLocalState;
13
54
  private readonly storageAdapter;
14
55
  private readonly _offlineLoadEnabled;
56
+ private readonly newSnapshotFetched?;
15
57
  private readonly processedOps;
16
58
  private snapshot;
17
59
  private readonly mc;
18
- constructor(pendingLocalState: IPendingContainerState | undefined, subLogger: ITelemetryLoggerExt, storageAdapter: Pick<IDocumentStorageService, "readBlob" | "getSnapshotTree" | "getSnapshot" | "getVersions">, _offlineLoadEnabled: boolean);
60
+ private latestSnapshot;
61
+ private refreshSnapshot;
62
+ constructor(pendingLocalState: IPendingContainerState | undefined, subLogger: ITelemetryLoggerExt, storageAdapter: Pick<IDocumentStorageService, "readBlob" | "getSnapshotTree" | "getSnapshot" | "getVersions">, _offlineLoadEnabled: boolean, newSnapshotFetched?: (() => void) | undefined);
19
63
  get offlineLoadEnabled(): boolean;
20
64
  addProcessedOp(message: ISequencedDocumentMessage): void;
21
- private getVersion;
22
- fetchSnapshot(specifiedVersion: string | undefined, supportGetSnapshotApi: boolean | undefined): Promise<{
23
- snapshotTree: ISnapshotTree | undefined;
65
+ fetchSnapshot(specifiedVersion: string | undefined, supportGetSnapshotApi: boolean): Promise<{
66
+ baseSnapshot: ISnapshotTree;
24
67
  version: IVersion | undefined;
25
68
  }>;
26
- private fetchSnapshotCore;
27
69
  /**
28
- * Get the most recent snapshot, or a specific version.
29
- * @param specifiedVersion - The specific version of the snapshot to retrieve
30
- * @returns The snapshot requested, or the latest snapshot if no version was specified, plus version ID
70
+ * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.
31
71
  */
32
- private fetchSnapshotTree;
72
+ private updateSnapshotAndProcessedOpsMaybe;
33
73
  /**
34
74
  * This method is only meant to be used by Container.attach() to set the initial
35
75
  * base snapshot when attaching.
36
76
  * @param snapshot - snapshot and blobs collected while attaching
37
77
  */
38
- setSnapshot(snapshot: {
39
- tree: ISnapshotTree;
40
- blobs: ISerializableBlobContents;
41
- } | undefined): void;
78
+ setInitialSnapshot(snapshot: SnapshotWithBlobs | undefined): void;
42
79
  getPendingLocalStateCore(props: IGetPendingLocalStateProps, clientId: string | undefined, runtime: Pick<IRuntime, "getPendingLocalState">, resolvedUrl: IResolvedUrl): Promise<string>;
43
80
  }
81
+ /**
82
+ * Retrieves the most recent snapshot and returns its info.
83
+ *
84
+ * @param mc - The monitoring context.
85
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
86
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
87
+ * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.
88
+ */
89
+ export declare function getLatestSnapshotInfo(mc: MonitoringContext, storageAdapter: Pick<IDocumentStorageService, "getSnapshot" | "getSnapshotTree" | "getVersions" | "readBlob">, supportGetSnapshotApi: boolean): Promise<ISnapshotInfo | undefined>;
90
+ /**
91
+ * Fetches an ISnapshot from a storage adapter based on the specified version.
92
+ *
93
+ * @param mc - The monitoring context.
94
+ * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.
95
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
96
+ * @returns - The fetched snapshot tree and its version.
97
+ */
98
+ export declare function fetchISnapshot(mc: MonitoringContext, storageAdapter: Pick<IDocumentStorageService, "getSnapshot">, specifiedVersion: string | undefined): Promise<{
99
+ snapshot?: ISnapshot;
100
+ version?: IVersion;
101
+ }>;
102
+ /**
103
+ * Fetches an ISnapshotTree from a storage adapter based on the specified version.
104
+ *
105
+ * @param mc - The monitoring context.
106
+ * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.
107
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
108
+ * @returns - The fetched snapshot tree and its version.
109
+ */
110
+ export declare function fetchISnapshotTree(mc: MonitoringContext, storageAdapter: Pick<IDocumentStorageService, "getSnapshotTree" | "getVersions">, specifiedVersion: string | undefined): Promise<{
111
+ snapshot?: ISnapshotTree;
112
+ version?: IVersion | undefined;
113
+ }>;
44
114
  //# sourceMappingURL=serializedStateManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializedStateManager.d.ts","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,yBAAyB,EACzB,aAAa,EACb,QAAQ,EACR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EACN,mBAAmB,EAKnB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACN,uBAAuB,EACvB,YAAY,EAEZ,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,yBAAyB,EAA2B,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,qBAAa,sBAAsB;IAWjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAElC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAI/B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAhBrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;IAChE,OAAO,CAAC,QAAQ,CAKH;IACb,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAoB;gBAGrB,iBAAiB,EAAE,sBAAsB,GAAG,SAAS,EACtE,SAAS,EAAE,mBAAmB,EACb,cAAc,EAAE,IAAI,CACpC,uBAAuB,EACvB,UAAU,GAAG,iBAAiB,GAAG,aAAa,GAAG,aAAa,CAC9D,EACgB,mBAAmB,EAAE,OAAO;IAQ9C,IAAW,kBAAkB,IAAI,OAAO,CAEvC;IAEM,cAAc,CAAC,OAAO,EAAE,yBAAyB;YAM1C,UAAU;IAKX,aAAa,CACzB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,qBAAqB,EAAE,OAAO,GAAG,SAAS;;;;YAyB7B,iBAAiB;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AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAC1C,EAAE,EAAE,iBAAiB,EACrB,cAAc,EAAE,IAAI,CACnB,uBAAuB,EACvB,aAAa,GAAG,iBAAiB,GAAG,aAAa,GAAG,UAAU,CAC9D,EACD,qBAAqB,EAAE,OAAO,GAC5B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAoBpC;AA8BD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CACnC,EAAE,EAAE,iBAAiB,EACrB,cAAc,EAAE,IAAI,CAAC,uBAAuB,EAAE,aAAa,CAAC,EAC5D,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAAC;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,QAAQ,CAAA;CAAE,CAAC,CAsBvD;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,iBAAiB,EACrB,cAAc,EAAE,IAAI,CAAC,uBAAuB,EAAE,iBAAiB,GAAG,aAAa,CAAC,EAChF,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAAC;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAC;IAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,CAAC,CAsBvE"}
@@ -2,15 +2,17 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { PerformanceEvent, UsageError, createChildMonitoringContext, } from "@fluidframework/telemetry-utils";
6
- import { assert } from "@fluidframework/core-utils";
7
- import { isInstanceOfISnapshot } from "@fluidframework/driver-utils";
5
+ import { assert } from "@fluidframework/core-utils/internal";
6
+ import { isInstanceOfISnapshot } from "@fluidframework/driver-utils/internal";
7
+ import { PerformanceEvent, UsageError, createChildMonitoringContext, } from "@fluidframework/telemetry-utils/internal";
8
8
  import { getBlobContentsFromTree } from "./containerStorageAdapter.js";
9
+ import { getDocumentAttributes } from "./utils.js";
9
10
  export class SerializedStateManager {
10
- constructor(pendingLocalState, subLogger, storageAdapter, _offlineLoadEnabled) {
11
+ constructor(pendingLocalState, subLogger, storageAdapter, _offlineLoadEnabled, newSnapshotFetched) {
11
12
  this.pendingLocalState = pendingLocalState;
12
13
  this.storageAdapter = storageAdapter;
13
14
  this._offlineLoadEnabled = _offlineLoadEnabled;
15
+ this.newSnapshotFetched = newSnapshotFetched;
14
16
  this.processedOps = [];
15
17
  this.mc = createChildMonitoringContext({
16
18
  logger: subLogger,
@@ -23,98 +25,97 @@ export class SerializedStateManager {
23
25
  addProcessedOp(message) {
24
26
  if (this.offlineLoadEnabled) {
25
27
  this.processedOps.push(message);
28
+ this.updateSnapshotAndProcessedOpsMaybe();
26
29
  }
27
30
  }
28
- async getVersion(version) {
29
- const versions = await this.storageAdapter.getVersions(version, 1);
30
- return versions[0];
31
- }
32
31
  async fetchSnapshot(specifiedVersion, supportGetSnapshotApi) {
33
- const { snapshot, version } = this.pendingLocalState === undefined
34
- ? await this.fetchSnapshotCore(specifiedVersion, supportGetSnapshotApi)
35
- : { snapshot: this.pendingLocalState.baseSnapshot, version: undefined };
36
- const snapshotTree = isInstanceOfISnapshot(snapshot)
37
- ? snapshot.snapshotTree
38
- : snapshot;
39
- if (this.pendingLocalState) {
40
- this.snapshot = {
41
- tree: this.pendingLocalState.baseSnapshot,
42
- blobs: this.pendingLocalState.snapshotBlobs,
43
- };
44
- }
45
- else {
46
- assert(snapshotTree !== undefined, 0x8e4 /* Snapshot should exist */);
32
+ if (this.pendingLocalState === undefined) {
33
+ const { baseSnapshot, version } = await getSnapshotTree(this.mc, this.storageAdapter, supportGetSnapshotApi, specifiedVersion);
47
34
  // non-interactive clients will not have any pending state we want to save
48
35
  if (this.offlineLoadEnabled) {
49
- const blobs = await getBlobContentsFromTree(snapshotTree, this.storageAdapter);
50
- this.snapshot = { tree: snapshotTree, blobs };
51
- }
52
- }
53
- return { snapshotTree, version };
54
- }
55
- async fetchSnapshotCore(specifiedVersion, supportGetSnapshotApi) {
56
- if (this.mc.config.getBoolean("Fluid.Container.UseLoadingGroupIdForSnapshotFetch") ===
57
- true &&
58
- supportGetSnapshotApi === true) {
59
- const snapshot = (await this.storageAdapter.getSnapshot?.({
60
- versionId: specifiedVersion,
61
- })) ?? undefined;
62
- const version = snapshot?.snapshotTree.id === undefined
63
- ? undefined
64
- : {
65
- id: snapshot.snapshotTree.id,
66
- treeId: snapshot.snapshotTree.id,
36
+ const snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, this.storageAdapter);
37
+ const attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshot);
38
+ this.snapshot = {
39
+ baseSnapshot,
40
+ snapshotBlobs,
41
+ snapshotSequenceNumber: attributes.sequenceNumber,
67
42
  };
68
- if (snapshot === undefined && specifiedVersion !== undefined) {
69
- this.mc.logger.sendErrorEvent({
70
- eventName: "getSnapshotTreeFailed",
71
- id: specifiedVersion,
72
- });
73
- // Not sure if this should be here actually
74
- }
75
- else if (snapshot !== undefined && version?.id === undefined) {
76
- this.mc.logger.sendErrorEvent({
77
- eventName: "getSnapshotFetchedTreeWithoutVersionId",
78
- hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
79
- });
80
43
  }
81
- return { snapshot, version };
44
+ return { baseSnapshot, version };
45
+ }
46
+ else {
47
+ const { baseSnapshot, snapshotBlobs } = this.pendingLocalState;
48
+ const attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshot);
49
+ this.snapshot = {
50
+ baseSnapshot,
51
+ snapshotBlobs,
52
+ snapshotSequenceNumber: attributes.sequenceNumber,
53
+ };
54
+ this.refreshSnapshot ?? (this.refreshSnapshot = (async () => {
55
+ this.latestSnapshot = await getLatestSnapshotInfo(this.mc, this.storageAdapter, supportGetSnapshotApi);
56
+ this.newSnapshotFetched?.();
57
+ this.updateSnapshotAndProcessedOpsMaybe();
58
+ })());
59
+ return { baseSnapshot, version: undefined };
82
60
  }
83
- return this.fetchSnapshotTree(specifiedVersion);
84
61
  }
85
62
  /**
86
- * Get the most recent snapshot, or a specific version.
87
- * @param specifiedVersion - The specific version of the snapshot to retrieve
88
- * @returns The snapshot requested, or the latest snapshot if no version was specified, plus version ID
63
+ * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.
89
64
  */
90
- async fetchSnapshotTree(specifiedVersion) {
91
- const version = await this.getVersion(specifiedVersion ?? null);
92
- if (version === undefined && specifiedVersion !== undefined) {
93
- // We should have a defined version to load from if specified version requested
94
- this.mc.logger.sendErrorEvent({
95
- eventName: "NoVersionFoundWhenSpecified",
96
- id: specifiedVersion,
97
- });
65
+ updateSnapshotAndProcessedOpsMaybe() {
66
+ if (this.latestSnapshot === undefined || this.processedOps.length === 0) {
67
+ // can't refresh latest snapshot until we have processed the ops up to it.
68
+ // Pending state would be behind the latest snapshot.
69
+ return;
98
70
  }
99
- const snapshot = (await this.storageAdapter.getSnapshotTree(version)) ?? undefined;
100
- if (snapshot === undefined && version !== undefined) {
101
- this.mc.logger.sendErrorEvent({ eventName: "getSnapshotTreeFailed", id: version.id });
71
+ const snapshotSequenceNumber = this.latestSnapshot.snapshotSequenceNumber;
72
+ const firstProcessedOpSequenceNumber = this.processedOps[0].sequenceNumber;
73
+ const lastProcessedOpSequenceNumber = this.processedOps[this.processedOps.length - 1].sequenceNumber;
74
+ if (snapshotSequenceNumber < firstProcessedOpSequenceNumber) {
75
+ // Snapshot seq number is older than our first processed op, which could mean we're fetching
76
+ // the same snapshot that we already have or snapshot is too old, implicating an unexpected behavior.
77
+ this.mc.logger.sendTelemetryEvent({
78
+ eventName: "OldSnapshotFetchWhileRefreshing",
79
+ snapshotSequenceNumber,
80
+ firstProcessedOpSequenceNumber,
81
+ lastProcessedOpSequenceNumber,
82
+ stashedSnapshotSequenceNumber: this.snapshot?.snapshotSequenceNumber,
83
+ });
84
+ this.latestSnapshot = undefined;
102
85
  }
103
- else if (snapshot !== undefined && version?.id === undefined) {
104
- this.mc.logger.sendErrorEvent({
105
- eventName: "getSnapshotFetchedTreeWithoutVersionId",
106
- hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
86
+ else if (snapshotSequenceNumber <= lastProcessedOpSequenceNumber) {
87
+ // Snapshot seq num is between the first and last processed op.
88
+ // Remove the ops that are already part of the snapshot
89
+ this.processedOps.splice(0, snapshotSequenceNumber - firstProcessedOpSequenceNumber + 1);
90
+ this.snapshot = this.latestSnapshot;
91
+ this.latestSnapshot = undefined;
92
+ this.mc.logger.sendTelemetryEvent({
93
+ eventName: "SnapshotRefreshed",
94
+ snapshotSequenceNumber,
95
+ firstProcessedOpSequenceNumber,
96
+ newFirstProcessedOpSequenceNumber: this.processedOps.length === 0
97
+ ? undefined
98
+ : this.processedOps[0].sequenceNumber,
107
99
  });
108
100
  }
109
- return { snapshot, version };
110
101
  }
111
102
  /**
112
103
  * This method is only meant to be used by Container.attach() to set the initial
113
104
  * base snapshot when attaching.
114
105
  * @param snapshot - snapshot and blobs collected while attaching
115
106
  */
116
- setSnapshot(snapshot) {
117
- this.snapshot = snapshot;
107
+ setInitialSnapshot(snapshot) {
108
+ if (this.offlineLoadEnabled) {
109
+ assert(this.snapshot === undefined, 0x937 /* inital snapshot should only be defined once */);
110
+ assert(snapshot !== undefined, 0x938 /* attachment snapshot should be defined */);
111
+ const { baseSnapshot, snapshotBlobs } = snapshot;
112
+ const attributesHash = ".protocol" in baseSnapshot.trees
113
+ ? baseSnapshot.trees[".protocol"].blobs.attributes
114
+ : baseSnapshot.blobs[".attributes"];
115
+ const attributes = JSON.parse(snapshotBlobs[attributesHash]);
116
+ assert(attributes.sequenceNumber === 0, 0x939 /* trying to set a non attachment snapshot */);
117
+ this.snapshot = { ...snapshot, snapshotSequenceNumber: attributes.sequenceNumber };
118
+ }
118
119
  }
119
120
  async getPendingLocalStateCore(props, clientId, runtime, resolvedUrl) {
120
121
  return PerformanceEvent.timedExecAsync(this.mc.logger, {
@@ -131,8 +132,8 @@ export class SerializedStateManager {
131
132
  const pendingState = {
132
133
  attached: true,
133
134
  pendingRuntimeState,
134
- baseSnapshot: this.snapshot.tree,
135
- snapshotBlobs: this.snapshot.blobs,
135
+ baseSnapshot: this.snapshot.baseSnapshot,
136
+ snapshotBlobs: this.snapshot.snapshotBlobs,
136
137
  savedOps: this.processedOps,
137
138
  url: resolvedUrl.url,
138
139
  // no need to save this if there is no pending runtime state
@@ -142,4 +143,100 @@ export class SerializedStateManager {
142
143
  });
143
144
  }
144
145
  }
146
+ /**
147
+ * Retrieves the most recent snapshot and returns its info.
148
+ *
149
+ * @param mc - The monitoring context.
150
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
151
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
152
+ * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.
153
+ */
154
+ export async function getLatestSnapshotInfo(mc, storageAdapter, supportGetSnapshotApi) {
155
+ return PerformanceEvent.timedExecAsync(mc.logger, { eventName: "GetLatestSnapshotInfo" }, async () => {
156
+ const { baseSnapshot } = await getSnapshotTree(mc, storageAdapter, supportGetSnapshotApi, undefined);
157
+ const snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, storageAdapter);
158
+ const attributes = await getDocumentAttributes(storageAdapter, baseSnapshot);
159
+ const snapshotSequenceNumber = attributes.sequenceNumber;
160
+ return { baseSnapshot, snapshotBlobs, snapshotSequenceNumber };
161
+ }).catch(() => undefined);
162
+ }
163
+ /**
164
+ * Retrieves a snapshot from the storage adapter and transforms it into an ISnapshotTree object.
165
+ *
166
+ * @param mc - The monitoring context.
167
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
168
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
169
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
170
+ * @returns - An ISnapshotTree and its version.
171
+ */
172
+ async function getSnapshotTree(mc, storageAdapter, supportGetSnapshotApi, specifiedVersion) {
173
+ const { snapshot, version } = supportGetSnapshotApi
174
+ ? await fetchISnapshot(mc, storageAdapter, specifiedVersion)
175
+ : await fetchISnapshotTree(mc, storageAdapter, specifiedVersion);
176
+ const baseSnapshot = isInstanceOfISnapshot(snapshot)
177
+ ? snapshot.snapshotTree
178
+ : snapshot;
179
+ assert(baseSnapshot !== undefined, 0x8e4 /* Snapshot should exist */);
180
+ return { baseSnapshot, version };
181
+ }
182
+ /**
183
+ * Fetches an ISnapshot from a storage adapter based on the specified version.
184
+ *
185
+ * @param mc - The monitoring context.
186
+ * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.
187
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
188
+ * @returns - The fetched snapshot tree and its version.
189
+ */
190
+ export async function fetchISnapshot(mc, storageAdapter, specifiedVersion) {
191
+ const snapshot = await storageAdapter.getSnapshot?.({ versionId: specifiedVersion });
192
+ const version = snapshot?.snapshotTree.id === undefined
193
+ ? undefined
194
+ : {
195
+ id: snapshot.snapshotTree.id,
196
+ treeId: snapshot.snapshotTree.id,
197
+ };
198
+ if (snapshot === undefined && specifiedVersion !== undefined) {
199
+ mc.logger.sendErrorEvent({
200
+ eventName: "getSnapshotTreeFailed",
201
+ id: specifiedVersion,
202
+ });
203
+ }
204
+ else if (snapshot !== undefined && version?.id === undefined) {
205
+ mc.logger.sendErrorEvent({
206
+ eventName: "getSnapshotFetchedTreeWithoutVersionId",
207
+ hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
208
+ });
209
+ }
210
+ return { snapshot, version };
211
+ }
212
+ /**
213
+ * Fetches an ISnapshotTree from a storage adapter based on the specified version.
214
+ *
215
+ * @param mc - The monitoring context.
216
+ * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.
217
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
218
+ * @returns - The fetched snapshot tree and its version.
219
+ */
220
+ export async function fetchISnapshotTree(mc, storageAdapter, specifiedVersion) {
221
+ const versions = await storageAdapter.getVersions(specifiedVersion ?? null, 1);
222
+ const version = versions[0];
223
+ if (version === undefined && specifiedVersion !== undefined) {
224
+ // We should have a defined version to load from if specified version requested
225
+ mc.logger.sendErrorEvent({
226
+ eventName: "NoVersionFoundWhenSpecified",
227
+ id: specifiedVersion,
228
+ });
229
+ }
230
+ const snapshot = (await storageAdapter.getSnapshotTree(version)) ?? undefined;
231
+ if (snapshot === undefined && version !== undefined) {
232
+ mc.logger.sendErrorEvent({ eventName: "getSnapshotTreeFailed", id: version.id });
233
+ }
234
+ else if (snapshot !== undefined && version?.id === undefined) {
235
+ mc.logger.sendErrorEvent({
236
+ eventName: "getSnapshotFetchedTreeWithoutVersionId",
237
+ hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
238
+ });
239
+ }
240
+ return { snapshot, version };
241
+ }
145
242
  //# sourceMappingURL=serializedStateManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializedStateManager.js","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAGN,gBAAgB,EAChB,UAAU,EACV,4BAA4B,GAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAMpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAA6B,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAGlG,MAAM,OAAO,sBAAsB;IAUlC,YACkB,iBAAqD,EACtE,SAA8B,EACb,cAGhB,EACgB,mBAA4B;QAN5B,sBAAiB,GAAjB,iBAAiB,CAAoC;QAErD,mBAAc,GAAd,cAAc,CAG9B;QACgB,wBAAmB,GAAnB,mBAAmB,CAAS;QAhB7B,iBAAY,GAAgC,EAAE,CAAC;QAkB/D,IAAI,CAAC,EAAE,GAAG,4BAA4B,CAAC;YACtC,MAAM,EAAE,SAAS;Y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ACjC,QAA4B,EAC5B,OAA+C,EAC/C,WAAyB;QAEzB,OAAO,gBAAgB,CAAC,cAAc,CACrC,IAAI,CAAC,EAAE,CAAC,MAAM,EACd;YACC,SAAS,EAAE,sBAAsB;YACjC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;YAClD,gBAAgB,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM;YAC1C,QAAQ;SACR,EACD,KAAK,IAAI,EAAE;YACV,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;gBAC7B,MAAM,IAAI,UAAU,CACnB,8DAA8D,CAC9D,CAAC;aACF;YACD,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAC9D,MAAM,mBAAmB,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;YACtE,MAAM,YAAY,GAA2B;gBAC5C,QAAQ,EAAE,IAAI;gBACd,mBAAmB;gBACnB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;gBAChC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK;gBAClC,QAAQ,EAAE,IAAI,CAAC,YAAY;gBAC3B,GAAG,EAAE,WAAW,CAAC,GAAG;gBACpB,4DAA4D;gBAC5D,QAAQ,EAAE,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;aAClE,CAAC;YAEF,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC,CACD,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISequencedDocumentMessage,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { IGetPendingLocalStateProps, IRuntime } from \"@fluidframework/container-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tIDocumentStorageService,\n\tIResolvedUrl,\n\tISnapshot,\n} from \"@fluidframework/driver-definitions\";\nimport { isInstanceOfISnapshot } from \"@fluidframework/driver-utils\";\nimport { ISerializableBlobContents, getBlobContentsFromTree } from \"./containerStorageAdapter.js\";\nimport { IPendingContainerState } from \"./container.js\";\n\nexport class SerializedStateManager {\n\tprivate readonly processedOps: ISequencedDocumentMessage[] = [];\n\tprivate snapshot:\n\t\t| {\n\t\t\t\ttree: ISnapshotTree;\n\t\t\t\tblobs: ISerializableBlobContents;\n\t\t }\n\t\t| undefined;\n\tprivate readonly mc: MonitoringContext;\n\n\tconstructor(\n\t\tprivate readonly pendingLocalState: IPendingContainerState | undefined,\n\t\tsubLogger: ITelemetryLoggerExt,\n\t\tprivate readonly storageAdapter: Pick<\n\t\t\tIDocumentStorageService,\n\t\t\t\"readBlob\" | \"getSnapshotTree\" | \"getSnapshot\" | \"getVersions\"\n\t\t>,\n\t\tprivate readonly _offlineLoadEnabled: boolean,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: subLogger,\n\t\t\tnamespace: \"serializedStateManager\",\n\t\t});\n\t}\n\n\tpublic get offlineLoadEnabled(): boolean {\n\t\treturn this._offlineLoadEnabled;\n\t}\n\n\tpublic addProcessedOp(message: ISequencedDocumentMessage) {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tthis.processedOps.push(message);\n\t\t}\n\t}\n\n\tprivate async getVersion(version: string | null): Promise<IVersion | undefined> {\n\t\tconst versions = await this.storageAdapter.getVersions(version, 1);\n\t\treturn versions[0];\n\t}\n\n\tpublic async fetchSnapshot(\n\t\tspecifiedVersion: string | undefined,\n\t\tsupportGetSnapshotApi: boolean | undefined,\n\t) {\n\t\tconst { snapshot, version } =\n\t\t\tthis.pendingLocalState === undefined\n\t\t\t\t? await this.fetchSnapshotCore(specifiedVersion, supportGetSnapshotApi)\n\t\t\t\t: { snapshot: this.pendingLocalState.baseSnapshot, version: undefined };\n\t\tconst snapshotTree: ISnapshotTree | undefined = isInstanceOfISnapshot(snapshot)\n\t\t\t? snapshot.snapshotTree\n\t\t\t: snapshot;\n\t\tif (this.pendingLocalState) {\n\t\t\tthis.snapshot = {\n\t\t\t\ttree: this.pendingLocalState.baseSnapshot,\n\t\t\t\tblobs: this.pendingLocalState.snapshotBlobs,\n\t\t\t};\n\t\t} else {\n\t\t\tassert(snapshotTree !== undefined, 0x8e4 /* Snapshot should exist */);\n\t\t\t// non-interactive clients will not have any pending state we want to save\n\t\t\tif (this.offlineLoadEnabled) {\n\t\t\t\tconst blobs = await getBlobContentsFromTree(snapshotTree, this.storageAdapter);\n\t\t\t\tthis.snapshot = { tree: snapshotTree, blobs };\n\t\t\t}\n\t\t}\n\t\treturn { snapshotTree, version };\n\t}\n\n\tprivate async fetchSnapshotCore(\n\t\tspecifiedVersion: string | undefined,\n\t\tsupportGetSnapshotApi: boolean | undefined,\n\t): Promise<{ snapshot?: ISnapshot | ISnapshotTree; version?: IVersion }> {\n\t\tif (\n\t\t\tthis.mc.config.getBoolean(\"Fluid.Container.UseLoadingGroupIdForSnapshotFetch\") ===\n\t\t\t\ttrue &&\n\t\t\tsupportGetSnapshotApi === true\n\t\t) {\n\t\t\tconst snapshot =\n\t\t\t\t(await this.storageAdapter.getSnapshot?.({\n\t\t\t\t\tversionId: specifiedVersion,\n\t\t\t\t})) ?? undefined;\n\t\t\tconst version: IVersion | undefined =\n\t\t\t\tsnapshot?.snapshotTree.id === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tid: snapshot.snapshotTree.id,\n\t\t\t\t\t\t\ttreeId: snapshot.snapshotTree.id,\n\t\t\t\t\t };\n\n\t\t\tif (snapshot === undefined && specifiedVersion !== undefined) {\n\t\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"getSnapshotTreeFailed\",\n\t\t\t\t\tid: specifiedVersion,\n\t\t\t\t});\n\t\t\t\t// Not sure if this should be here actually\n\t\t\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn { snapshot, version };\n\t\t}\n\t\treturn this.fetchSnapshotTree(specifiedVersion);\n\t}\n\n\t/**\n\t * Get the most recent snapshot, or a specific version.\n\t * @param specifiedVersion - The specific version of the snapshot to retrieve\n\t * @returns The snapshot requested, or the latest snapshot if no version was specified, plus version ID\n\t */\n\tprivate async fetchSnapshotTree(\n\t\tspecifiedVersion: string | undefined,\n\t): Promise<{ snapshot?: ISnapshotTree; version?: IVersion | undefined }> {\n\t\tconst version = await this.getVersion(specifiedVersion ?? null);\n\n\t\tif (version === undefined && specifiedVersion !== undefined) {\n\t\t\t// We should have a defined version to load from if specified version requested\n\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\teventName: \"NoVersionFoundWhenSpecified\",\n\t\t\t\tid: specifiedVersion,\n\t\t\t});\n\t\t}\n\t\tconst snapshot = (await this.storageAdapter.getSnapshotTree(version)) ?? undefined;\n\n\t\tif (snapshot === undefined && version !== undefined) {\n\t\t\tthis.mc.logger.sendErrorEvent({ eventName: \"getSnapshotTreeFailed\", id: version.id });\n\t\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t\t});\n\t\t}\n\t\treturn { snapshot, version };\n\t}\n\n\t/**\n\t * This method is only meant to be used by Container.attach() to set the initial\n\t * base snapshot when attaching.\n\t * @param snapshot - snapshot and blobs collected while attaching\n\t */\n\tpublic setSnapshot(\n\t\tsnapshot:\n\t\t\t| {\n\t\t\t\t\ttree: ISnapshotTree;\n\t\t\t\t\tblobs: ISerializableBlobContents;\n\t\t\t }\n\t\t\t| undefined,\n\t) {\n\t\tthis.snapshot = snapshot;\n\t}\n\n\tpublic async getPendingLocalStateCore(\n\t\tprops: IGetPendingLocalStateProps,\n\t\tclientId: string | undefined,\n\t\truntime: Pick<IRuntime, \"getPendingLocalState\">,\n\t\tresolvedUrl: IResolvedUrl,\n\t) {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"getPendingLocalState\",\n\t\t\t\tnotifyImminentClosure: props.notifyImminentClosure,\n\t\t\t\tprocessedOpsSize: this.processedOps.length,\n\t\t\t\tclientId,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tif (!this.offlineLoadEnabled) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"Can't get pending local state unless offline load is enabled\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tassert(this.snapshot !== undefined, 0x8e5 /* no base data */);\n\t\t\t\tconst pendingRuntimeState = await runtime.getPendingLocalState(props);\n\t\t\t\tconst pendingState: IPendingContainerState = {\n\t\t\t\t\tattached: true,\n\t\t\t\t\tpendingRuntimeState,\n\t\t\t\t\tbaseSnapshot: this.snapshot.tree,\n\t\t\t\t\tsnapshotBlobs: this.snapshot.blobs,\n\t\t\t\t\tsavedOps: this.processedOps,\n\t\t\t\t\turl: resolvedUrl.url,\n\t\t\t\t\t// no need to save this if there is no pending runtime state\n\t\t\t\t\tclientId: pendingRuntimeState !== undefined ? clientId : undefined,\n\t\t\t\t};\n\n\t\t\t\treturn JSON.stringify(pendingState);\n\t\t\t},\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"serializedStateManager.js","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"mappings":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ation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIGetPendingLocalStateProps,\n\tIRuntime,\n} from \"@fluidframework/container-definitions/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tIResolvedUrl,\n\tISnapshot,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { isInstanceOfISnapshot } from \"@fluidframework/driver-utils/internal\";\nimport {\n\ttype IDocumentAttributes,\n\tISequencedDocumentMessage,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils\";\nimport {\n\tMonitoringContext,\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { ISerializableBlobContents, getBlobContentsFromTree } from \"./containerStorageAdapter.js\";\nimport { getDocumentAttributes } from \"./utils.js\";\n\nexport interface SnapshotWithBlobs {\n\t/**\n\t * Snapshot from which container initially loaded.\n\t */\n\tbaseSnapshot: ISnapshotTree;\n\t/**\n\t * Serializable blobs from the base snapshot. Used to load offline since\n\t * storage is not available.\n\t */\n\tsnapshotBlobs: ISerializableBlobContents;\n}\n/**\n * State saved by a container at close time, to be used to load a new instance\n * of the container to the same state\n * @internal\n */\nexport interface IPendingContainerState extends SnapshotWithBlobs {\n\tattached: true;\n\tpendingRuntimeState: unknown;\n\t/**\n\t * All ops since base snapshot sequence number up to the latest op\n\t * seen when the container was closed. Used to apply stashed (saved pending)\n\t * ops at the same sequence number at which they were made.\n\t */\n\tsavedOps: ISequencedDocumentMessage[];\n\turl: string;\n\tclientId?: string;\n}\n\n/**\n * State saved by a container in detached state, to be used to load a new instance\n * of the container to the same state (rehydrate)\n * @internal\n */\nexport interface IPendingDetachedContainerState extends SnapshotWithBlobs {\n\tattached: false;\n\thasAttachmentBlobs: boolean;\n\tpendingRuntimeState?: unknown;\n}\n\nexport interface ISnapshotInfo extends SnapshotWithBlobs {\n\tsnapshotSequenceNumber: number;\n}\n\nexport class SerializedStateManager {\n\tprivate readonly processedOps: ISequencedDocumentMessage[] = [];\n\tprivate snapshot: ISnapshotInfo | undefined;\n\tprivate readonly mc: MonitoringContext;\n\tprivate latestSnapshot: ISnapshotInfo | undefined;\n\tprivate refreshSnapshot: Promise<void> | undefined;\n\n\tconstructor(\n\t\tprivate readonly pendingLocalState: IPendingContainerState | undefined,\n\t\tsubLogger: ITelemetryLoggerExt,\n\t\tprivate readonly storageAdapter: Pick<\n\t\t\tIDocumentStorageService,\n\t\t\t\"readBlob\" | \"getSnapshotTree\" | \"getSnapshot\" | \"getVersions\"\n\t\t>,\n\t\tprivate readonly _offlineLoadEnabled: boolean,\n\t\tprivate readonly newSnapshotFetched?: () => void,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: subLogger,\n\t\t\tnamespace: \"serializedStateManager\",\n\t\t});\n\t}\n\n\tpublic get offlineLoadEnabled(): boolean {\n\t\treturn this._offlineLoadEnabled;\n\t}\n\n\tpublic addProcessedOp(message: ISequencedDocumentMessage) {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tthis.processedOps.push(message);\n\t\t\tthis.updateSnapshotAndProcessedOpsMaybe();\n\t\t}\n\t}\n\n\tpublic async fetchSnapshot(\n\t\tspecifiedVersion: string | undefined,\n\t\tsupportGetSnapshotApi: boolean,\n\t) {\n\t\tif (this.pendingLocalState === undefined) {\n\t\t\tconst { baseSnapshot, version } = await getSnapshotTree(\n\t\t\t\tthis.mc,\n\t\t\t\tthis.storageAdapter,\n\t\t\t\tsupportGetSnapshotApi,\n\t\t\t\tspecifiedVersion,\n\t\t\t);\n\t\t\t// non-interactive clients will not have any pending state we want to save\n\t\t\tif (this.offlineLoadEnabled) {\n\t\t\t\tconst snapshotBlobs = await getBlobContentsFromTree(\n\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\tthis.storageAdapter,\n\t\t\t\t);\n\t\t\t\tconst attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshot);\n\t\t\t\tthis.snapshot = {\n\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\tsnapshotBlobs,\n\t\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { baseSnapshot, version };\n\t\t} else {\n\t\t\tconst { baseSnapshot, snapshotBlobs } = this.pendingLocalState;\n\t\t\tconst attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshot);\n\t\t\tthis.snapshot = {\n\t\t\t\tbaseSnapshot,\n\t\t\t\tsnapshotBlobs,\n\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber,\n\t\t\t};\n\t\t\tthis.refreshSnapshot ??= (async () => {\n\t\t\t\tthis.latestSnapshot = await getLatestSnapshotInfo(\n\t\t\t\t\tthis.mc,\n\t\t\t\t\tthis.storageAdapter,\n\t\t\t\t\tsupportGetSnapshotApi,\n\t\t\t\t);\n\t\t\t\tthis.newSnapshotFetched?.();\n\t\t\t\tthis.updateSnapshotAndProcessedOpsMaybe();\n\t\t\t})();\n\n\t\t\treturn { baseSnapshot, version: undefined };\n\t\t}\n\t}\n\n\t/**\n\t * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.\n\t */\n\tprivate updateSnapshotAndProcessedOpsMaybe() {\n\t\tif (this.latestSnapshot === undefined || this.processedOps.length === 0) {\n\t\t\t// can't refresh latest snapshot until we have processed the ops up to it.\n\t\t\t// Pending state would be behind the latest snapshot.\n\t\t\treturn;\n\t\t}\n\t\tconst snapshotSequenceNumber = this.latestSnapshot.snapshotSequenceNumber;\n\t\tconst firstProcessedOpSequenceNumber = this.processedOps[0].sequenceNumber;\n\t\tconst lastProcessedOpSequenceNumber =\n\t\t\tthis.processedOps[this.processedOps.length - 1].sequenceNumber;\n\n\t\tif (snapshotSequenceNumber < firstProcessedOpSequenceNumber) {\n\t\t\t// Snapshot seq number is older than our first processed op, which could mean we're fetching\n\t\t\t// the same snapshot that we already have or snapshot is too old, implicating an unexpected behavior.\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"OldSnapshotFetchWhileRefreshing\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\n\t\t\t\tlastProcessedOpSequenceNumber,\n\t\t\t\tstashedSnapshotSequenceNumber: this.snapshot?.snapshotSequenceNumber,\n\t\t\t});\n\t\t\tthis.latestSnapshot = undefined;\n\t\t} else if (snapshotSequenceNumber <= lastProcessedOpSequenceNumber) {\n\t\t\t// Snapshot seq num is between the first and last processed op.\n\t\t\t// Remove the ops that are already part of the snapshot\n\t\t\tthis.processedOps.splice(\n\t\t\t\t0,\n\t\t\t\tsnapshotSequenceNumber - firstProcessedOpSequenceNumber + 1,\n\t\t\t);\n\t\t\tthis.snapshot = this.latestSnapshot;\n\t\t\tthis.latestSnapshot = undefined;\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"SnapshotRefreshed\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\n\t\t\t\tnewFirstProcessedOpSequenceNumber:\n\t\t\t\t\tthis.processedOps.length === 0\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: this.processedOps[0].sequenceNumber,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * This method is only meant to be used by Container.attach() to set the initial\n\t * base snapshot when attaching.\n\t * @param snapshot - snapshot and blobs collected while attaching\n\t */\n\tpublic setInitialSnapshot(snapshot: SnapshotWithBlobs | undefined) {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tassert(\n\t\t\t\tthis.snapshot === undefined,\n\t\t\t\t0x937 /* inital snapshot should only be defined once */,\n\t\t\t);\n\t\t\tassert(snapshot !== undefined, 0x938 /* attachment snapshot should be defined */);\n\t\t\tconst { baseSnapshot, snapshotBlobs } = snapshot;\n\t\t\tconst attributesHash =\n\t\t\t\t\".protocol\" in baseSnapshot.trees\n\t\t\t\t\t? baseSnapshot.trees[\".protocol\"].blobs.attributes\n\t\t\t\t\t: baseSnapshot.blobs[\".attributes\"];\n\t\t\tconst attributes = JSON.parse(snapshotBlobs[attributesHash]);\n\t\t\tassert(\n\t\t\t\tattributes.sequenceNumber === 0,\n\t\t\t\t0x939 /* trying to set a non attachment snapshot */,\n\t\t\t);\n\t\t\tthis.snapshot = { ...snapshot, snapshotSequenceNumber: attributes.sequenceNumber };\n\t\t}\n\t}\n\n\tpublic async getPendingLocalStateCore(\n\t\tprops: IGetPendingLocalStateProps,\n\t\tclientId: string | undefined,\n\t\truntime: Pick<IRuntime, \"getPendingLocalState\">,\n\t\tresolvedUrl: IResolvedUrl,\n\t) {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"getPendingLocalState\",\n\t\t\t\tnotifyImminentClosure: props.notifyImminentClosure,\n\t\t\t\tprocessedOpsSize: this.processedOps.length,\n\t\t\t\tclientId,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tif (!this.offlineLoadEnabled) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"Can't get pending local state unless offline load is enabled\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tassert(this.snapshot !== undefined, 0x8e5 /* no base data */);\n\t\t\t\tconst pendingRuntimeState = await runtime.getPendingLocalState(props);\n\t\t\t\tconst pendingState: IPendingContainerState = {\n\t\t\t\t\tattached: true,\n\t\t\t\t\tpendingRuntimeState,\n\t\t\t\t\tbaseSnapshot: this.snapshot.baseSnapshot,\n\t\t\t\t\tsnapshotBlobs: this.snapshot.snapshotBlobs,\n\t\t\t\t\tsavedOps: this.processedOps,\n\t\t\t\t\turl: resolvedUrl.url,\n\t\t\t\t\t// no need to save this if there is no pending runtime state\n\t\t\t\t\tclientId: pendingRuntimeState !== undefined ? clientId : undefined,\n\t\t\t\t};\n\n\t\t\t\treturn JSON.stringify(pendingState);\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * Retrieves the most recent snapshot and returns its info.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.\n * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.\n */\nexport async function getLatestSnapshotInfo(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<\n\t\tIDocumentStorageService,\n\t\t\"getSnapshot\" | \"getSnapshotTree\" | \"getVersions\" | \"readBlob\"\n\t>,\n\tsupportGetSnapshotApi: boolean,\n): Promise<ISnapshotInfo | undefined> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tmc.logger,\n\t\t{ eventName: \"GetLatestSnapshotInfo\" },\n\t\tasync () => {\n\t\t\tconst { baseSnapshot } = await getSnapshotTree(\n\t\t\t\tmc,\n\t\t\t\tstorageAdapter,\n\t\t\t\tsupportGetSnapshotApi,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t\tconst snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, storageAdapter);\n\t\t\tconst attributes: IDocumentAttributes = await getDocumentAttributes(\n\t\t\t\tstorageAdapter,\n\t\t\t\tbaseSnapshot,\n\t\t\t);\n\t\t\tconst snapshotSequenceNumber = attributes.sequenceNumber;\n\t\t\treturn { baseSnapshot, snapshotBlobs, snapshotSequenceNumber };\n\t\t},\n\t).catch(() => undefined);\n}\n\n/**\n * Retrieves a snapshot from the storage adapter and transforms it into an ISnapshotTree object.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.\n * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - An ISnapshotTree and its version.\n */\nasync function getSnapshotTree(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<\n\t\tIDocumentStorageService,\n\t\t\"getSnapshot\" | \"getSnapshotTree\" | \"getVersions\"\n\t>,\n\tsupportGetSnapshotApi: boolean,\n\tspecifiedVersion: string | undefined,\n): Promise<{ baseSnapshot: ISnapshotTree; version?: IVersion }> {\n\tconst { snapshot, version } = supportGetSnapshotApi\n\t\t? await fetchISnapshot(mc, storageAdapter, specifiedVersion)\n\t\t: await fetchISnapshotTree(mc, storageAdapter, specifiedVersion);\n\tconst baseSnapshot: ISnapshotTree | undefined = isInstanceOfISnapshot(snapshot)\n\t\t? snapshot.snapshotTree\n\t\t: snapshot;\n\tassert(baseSnapshot !== undefined, 0x8e4 /* Snapshot should exist */);\n\treturn { baseSnapshot, version };\n}\n\n/**\n * Fetches an ISnapshot from a storage adapter based on the specified version.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - The fetched snapshot tree and its version.\n */\nexport async function fetchISnapshot(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<IDocumentStorageService, \"getSnapshot\">,\n\tspecifiedVersion: string | undefined,\n): Promise<{ snapshot?: ISnapshot; version?: IVersion }> {\n\tconst snapshot = await storageAdapter.getSnapshot?.({ versionId: specifiedVersion });\n\tconst version: IVersion | undefined =\n\t\tsnapshot?.snapshotTree.id === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: snapshot.snapshotTree.id,\n\t\t\t\t\ttreeId: snapshot.snapshotTree.id,\n\t\t\t };\n\n\tif (snapshot === undefined && specifiedVersion !== undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotTreeFailed\",\n\t\t\tid: specifiedVersion,\n\t\t});\n\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t});\n\t}\n\treturn { snapshot, version };\n}\n\n/**\n * Fetches an ISnapshotTree from a storage adapter based on the specified version.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - The fetched snapshot tree and its version.\n */\nexport async function fetchISnapshotTree(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<IDocumentStorageService, \"getSnapshotTree\" | \"getVersions\">,\n\tspecifiedVersion: string | undefined,\n): Promise<{ snapshot?: ISnapshotTree; version?: IVersion | undefined }> {\n\tconst versions = await storageAdapter.getVersions(specifiedVersion ?? null, 1);\n\tconst version = versions[0];\n\n\tif (version === undefined && specifiedVersion !== undefined) {\n\t\t// We should have a defined version to load from if specified version requested\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"NoVersionFoundWhenSpecified\",\n\t\t\tid: specifiedVersion,\n\t\t});\n\t}\n\tconst snapshot = (await storageAdapter.getSnapshotTree(version)) ?? undefined;\n\n\tif (snapshot === undefined && version !== undefined) {\n\t\tmc.logger.sendErrorEvent({ eventName: \"getSnapshotTreeFailed\", id: version.id });\n\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t});\n\t}\n\treturn { snapshot, version };\n}\n"]}
package/lib/utils.d.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ISummaryTree, ISnapshotTree } from "@fluidframework/protocol-definitions";
6
- import { CombinedAppAndProtocolSummary, DeltaStreamConnectionForbiddenError } from "@fluidframework/driver-utils";
5
+ import { IDocumentStorageService, type ISnapshot } from "@fluidframework/driver-definitions/internal";
6
+ import { CombinedAppAndProtocolSummary, DeltaStreamConnectionForbiddenError } from "@fluidframework/driver-utils/internal";
7
+ import { IDocumentAttributes, ISnapshotTree, ISummaryTree } from "@fluidframework/protocol-definitions";
7
8
  import { ISerializableBlobContents } from "./containerStorageAdapter.js";
8
- import { IPendingDetachedContainerState } from "./container.js";
9
+ import type { IPendingDetachedContainerState, ISnapshotInfo, SnapshotWithBlobs } from "./serializedStateManager.js";
9
10
  export interface ISnapshotTreeWithBlobContents extends ISnapshotTree {
10
11
  blobsContents: {
11
12
  [path: string]: ArrayBufferLike;
@@ -18,7 +19,7 @@ export interface ISnapshotTreeWithBlobContents extends ISnapshotTree {
18
19
  * Interface to represent the parsed parts of IResolvedUrl.url to help
19
20
  * in getting info about different parts of the url.
20
21
  * May not be compatible or relevant for any Url Resolver
21
- * @internal
22
+ * @alpha
22
23
  */
23
24
  export interface IParsedUrl {
24
25
  /**
@@ -46,7 +47,7 @@ export interface IParsedUrl {
46
47
  * with urls of type: protocol://<string>/.../..?<querystring>
47
48
  * @param url - This is the IResolvedUrl.url part of the resolved url.
48
49
  * @returns The IParsedUrl representing the input URL, or undefined if the format was not supported
49
- * @internal
50
+ * @alpha
50
51
  */
51
52
  export declare function tryParseCompatibleResolvedUrl(url: string): IParsedUrl | undefined;
52
53
  /**
@@ -56,10 +57,23 @@ export declare function tryParseCompatibleResolvedUrl(url: string): IParsedUrl |
56
57
  * @internal
57
58
  */
58
59
  export declare function combineAppAndProtocolSummary(appSummary: ISummaryTree, protocolSummary: ISummaryTree): CombinedAppAndProtocolSummary;
59
- export declare const getSnapshotTreeAndBlobsFromSerializedContainer: (detachedContainerSnapshot: ISummaryTree) => {
60
- tree: ISnapshotTree;
61
- blobs: ISerializableBlobContents;
62
- };
60
+ /**
61
+ * Converts a snapshot to snapshotInfo with its blob contents
62
+ * to align detached container format with IPendingContainerState
63
+ *
64
+ * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown
65
+ * @param snapshot - ISnapshot
66
+ */
67
+ export declare function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): ISnapshotInfo;
68
+ /**
69
+ * Converts a snapshot to snapshotInfo with its blob contents
70
+ * to align detached container format with IPendingContainerState
71
+ *
72
+ * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown
73
+ * @param snapshot - ISnapshot
74
+ */
75
+ export declare function convertSnapshotInfoToSnapshot(snapshotInfo: ISnapshotInfo, snapshotSequenceNumber: number): ISnapshot;
76
+ export declare const getSnapshotTreeAndBlobsFromSerializedContainer: (detachedContainerSnapshot: ISummaryTree) => SnapshotWithBlobs;
63
77
  export declare function getProtocolSnapshotTree(snapshot: ISnapshotTree): ISnapshotTree;
64
78
  export declare const combineSnapshotTreeAndSnapshotBlobs: (baseSnapshot: ISnapshotTree, snapshotBlobs: ISerializableBlobContents) => ISnapshotTreeWithBlobContents;
65
79
  export declare function isDeltaStreamConnectionForbiddenError(error: any): error is DeltaStreamConnectionForbiddenError;
@@ -69,4 +83,5 @@ export declare function getDetachedContainerStateFromSerializedContainer(seriali
69
83
  * If there are multiple calls they will all get the same promise to wait on.
70
84
  */
71
85
  export declare const runSingle: <A extends any[], R>(func: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
86
+ export declare function getDocumentAttributes(storage: Pick<IDocumentStorageService, "readBlob">, tree: ISnapshotTree | undefined): Promise<IDocumentAttributes>;
72
87
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAe,MAAM,sCAAsC,CAAC;AAEhG,OAAO,EACN,6BAA6B,EAC7B,mCAAmC,EAEnC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAIhE,MAAM,W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