@fluidframework/container-loader 2.0.0-dev-rc.2.0.0.246488 → 2.0.0-dev-rc.3.0.0.253463

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 (236) hide show
  1. package/api-report/container-loader.api.md +11 -11
  2. package/dist/attachment.d.ts +6 -9
  3. package/dist/attachment.d.ts.map +1 -1
  4. package/dist/attachment.js +3 -3
  5. package/dist/attachment.js.map +1 -1
  6. package/dist/audience.d.ts +1 -1
  7. package/dist/audience.d.ts.map +1 -1
  8. package/dist/audience.js +2 -2
  9. package/dist/audience.js.map +1 -1
  10. package/dist/catchUpMonitor.d.ts +1 -1
  11. package/dist/catchUpMonitor.d.ts.map +1 -1
  12. package/dist/catchUpMonitor.js +2 -2
  13. package/dist/catchUpMonitor.js.map +1 -1
  14. package/dist/connectionManager.d.ts +4 -4
  15. package/dist/connectionManager.d.ts.map +1 -1
  16. package/dist/connectionManager.js +42 -42
  17. package/dist/connectionManager.js.map +1 -1
  18. package/dist/connectionStateHandler.d.ts +3 -3
  19. package/dist/connectionStateHandler.d.ts.map +1 -1
  20. package/dist/connectionStateHandler.js +27 -27
  21. package/dist/connectionStateHandler.js.map +1 -1
  22. package/dist/container-loader-alpha.d.ts +11 -11
  23. package/dist/container-loader-beta.d.ts +11 -11
  24. package/dist/container-loader-public.d.ts +11 -11
  25. package/dist/container-loader-untrimmed.d.ts +11 -11
  26. package/dist/container.d.ts +9 -46
  27. package/dist/container.d.ts.map +1 -1
  28. package/dist/container.js +96 -108
  29. package/dist/container.js.map +1 -1
  30. package/dist/containerContext.d.ts +19 -7
  31. package/dist/containerContext.d.ts.map +1 -1
  32. package/dist/containerContext.js +7 -2
  33. package/dist/containerContext.js.map +1 -1
  34. package/dist/containerStorageAdapter.d.ts +3 -3
  35. package/dist/containerStorageAdapter.d.ts.map +1 -1
  36. package/dist/containerStorageAdapter.js +6 -6
  37. package/dist/containerStorageAdapter.js.map +1 -1
  38. package/dist/contracts.d.ts +4 -3
  39. package/dist/contracts.d.ts.map +1 -1
  40. package/dist/contracts.js +2 -2
  41. package/dist/contracts.js.map +1 -1
  42. package/dist/debugLogger.d.ts +2 -1
  43. package/dist/debugLogger.d.ts.map +1 -1
  44. package/dist/debugLogger.js +4 -4
  45. package/dist/debugLogger.js.map +1 -1
  46. package/dist/deltaManager.d.ts +7 -6
  47. package/dist/deltaManager.d.ts.map +1 -1
  48. package/dist/deltaManager.js +45 -45
  49. package/dist/deltaManager.js.map +1 -1
  50. package/dist/deltaQueue.d.ts +1 -1
  51. package/dist/deltaQueue.d.ts.map +1 -1
  52. package/dist/deltaQueue.js +5 -5
  53. package/dist/deltaQueue.js.map +1 -1
  54. package/dist/error.d.ts +3 -2
  55. package/dist/error.d.ts.map +1 -1
  56. package/dist/error.js +5 -5
  57. package/dist/error.js.map +1 -1
  58. package/dist/loader.d.ts +4 -4
  59. package/dist/loader.d.ts.map +1 -1
  60. package/dist/loader.js +23 -23
  61. package/dist/loader.js.map +1 -1
  62. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
  63. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
  64. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
  65. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  66. package/dist/noopHeuristic.d.ts +1 -1
  67. package/dist/noopHeuristic.d.ts.map +1 -1
  68. package/dist/noopHeuristic.js +6 -6
  69. package/dist/noopHeuristic.js.map +1 -1
  70. package/dist/packageVersion.d.ts +1 -1
  71. package/dist/packageVersion.js +1 -1
  72. package/dist/packageVersion.js.map +1 -1
  73. package/dist/protocol.d.ts +1 -1
  74. package/dist/protocol.d.ts.map +1 -1
  75. package/dist/protocol.js +2 -2
  76. package/dist/protocol.js.map +1 -1
  77. package/dist/protocolTreeDocumentStorageService.d.ts +4 -4
  78. package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
  79. package/dist/protocolTreeDocumentStorageService.js.map +1 -1
  80. package/dist/quorum.d.ts +1 -1
  81. package/dist/quorum.d.ts.map +1 -1
  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 +87 -16
  88. package/dist/serializedStateManager.d.ts.map +1 -1
  89. package/dist/serializedStateManager.js +164 -80
  90. package/dist/serializedStateManager.js.map +1 -1
  91. package/dist/utils.d.ts +6 -7
  92. package/dist/utils.d.ts.map +1 -1
  93. package/dist/utils.js +39 -23
  94. package/dist/utils.js.map +1 -1
  95. package/lib/attachment.d.ts +6 -9
  96. package/lib/attachment.d.ts.map +1 -1
  97. package/lib/attachment.js +1 -1
  98. package/lib/attachment.js.map +1 -1
  99. package/lib/audience.d.ts +1 -1
  100. package/lib/audience.d.ts.map +1 -1
  101. package/lib/audience.js +1 -1
  102. package/lib/audience.js.map +1 -1
  103. package/lib/catchUpMonitor.d.ts +1 -1
  104. package/lib/catchUpMonitor.d.ts.map +1 -1
  105. package/lib/catchUpMonitor.js +1 -1
  106. package/lib/catchUpMonitor.js.map +1 -1
  107. package/lib/connectionManager.d.ts +4 -4
  108. package/lib/connectionManager.d.ts.map +1 -1
  109. package/lib/connectionManager.js +5 -5
  110. package/lib/connectionManager.js.map +1 -1
  111. package/lib/connectionStateHandler.d.ts +3 -3
  112. package/lib/connectionStateHandler.d.ts.map +1 -1
  113. package/lib/connectionStateHandler.js +2 -2
  114. package/lib/connectionStateHandler.js.map +1 -1
  115. package/lib/container-loader-alpha.d.ts +11 -11
  116. package/lib/container-loader-beta.d.ts +11 -11
  117. package/lib/container-loader-public.d.ts +11 -11
  118. package/lib/container-loader-untrimmed.d.ts +11 -11
  119. package/lib/container.d.ts +9 -46
  120. package/lib/container.d.ts.map +1 -1
  121. package/lib/container.js +28 -40
  122. package/lib/container.js.map +1 -1
  123. package/lib/containerContext.d.ts +19 -7
  124. package/lib/containerContext.d.ts.map +1 -1
  125. package/lib/containerContext.js +7 -2
  126. package/lib/containerContext.js.map +1 -1
  127. package/lib/containerStorageAdapter.d.ts +3 -3
  128. package/lib/containerStorageAdapter.d.ts.map +1 -1
  129. package/lib/containerStorageAdapter.js +2 -2
  130. package/lib/containerStorageAdapter.js.map +1 -1
  131. package/lib/contracts.d.ts +4 -3
  132. package/lib/contracts.d.ts.map +1 -1
  133. package/lib/contracts.js +1 -1
  134. package/lib/contracts.js.map +1 -1
  135. package/lib/debugLogger.d.ts +2 -1
  136. package/lib/debugLogger.d.ts.map +1 -1
  137. package/lib/debugLogger.js +1 -1
  138. package/lib/debugLogger.js.map +1 -1
  139. package/lib/deltaManager.d.ts +7 -6
  140. package/lib/deltaManager.d.ts.map +1 -1
  141. package/lib/deltaManager.js +5 -5
  142. package/lib/deltaManager.js.map +1 -1
  143. package/lib/deltaQueue.d.ts +1 -1
  144. package/lib/deltaQueue.d.ts.map +1 -1
  145. package/lib/deltaQueue.js +2 -2
  146. package/lib/deltaQueue.js.map +1 -1
  147. package/lib/error.d.ts +3 -2
  148. package/lib/error.d.ts.map +1 -1
  149. package/lib/error.js +2 -2
  150. package/lib/error.js.map +1 -1
  151. package/lib/loader.d.ts +4 -4
  152. package/lib/loader.d.ts.map +1 -1
  153. package/lib/loader.js +4 -4
  154. package/lib/loader.js.map +1 -1
  155. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
  156. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
  157. package/lib/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
  158. package/lib/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  159. package/lib/noopHeuristic.d.ts +1 -1
  160. package/lib/noopHeuristic.d.ts.map +1 -1
  161. package/lib/noopHeuristic.js +2 -2
  162. package/lib/noopHeuristic.js.map +1 -1
  163. package/lib/packageVersion.d.ts +1 -1
  164. package/lib/packageVersion.js +1 -1
  165. package/lib/packageVersion.js.map +1 -1
  166. package/lib/protocol.d.ts +1 -1
  167. package/lib/protocol.d.ts.map +1 -1
  168. package/lib/protocol.js +1 -1
  169. package/lib/protocol.js.map +1 -1
  170. package/lib/protocolTreeDocumentStorageService.d.ts +4 -4
  171. package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
  172. package/lib/protocolTreeDocumentStorageService.js.map +1 -1
  173. package/lib/quorum.d.ts +1 -1
  174. package/lib/quorum.d.ts.map +1 -1
  175. package/lib/quorum.js.map +1 -1
  176. package/lib/retriableDocumentStorageService.d.ts +2 -2
  177. package/lib/retriableDocumentStorageService.d.ts.map +1 -1
  178. package/lib/retriableDocumentStorageService.js +3 -3
  179. package/lib/retriableDocumentStorageService.js.map +1 -1
  180. package/lib/serializedStateManager.d.ts +87 -16
  181. package/lib/serializedStateManager.d.ts.map +1 -1
  182. package/lib/serializedStateManager.js +156 -75
  183. package/lib/serializedStateManager.js.map +1 -1
  184. package/lib/tsdoc-metadata.json +11 -0
  185. package/lib/utils.d.ts +6 -7
  186. package/lib/utils.d.ts.map +1 -1
  187. package/lib/utils.js +27 -12
  188. package/lib/utils.js.map +1 -1
  189. package/package.json +19 -28
  190. package/src/attachment.ts +9 -8
  191. package/src/audience.ts +2 -2
  192. package/src/catchUpMonitor.ts +2 -2
  193. package/src/connectionManager.ts +19 -19
  194. package/src/connectionStateHandler.ts +7 -7
  195. package/src/container.ts +78 -133
  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 +31 -25
  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 +1 -1
  210. package/src/retriableDocumentStorageService.ts +6 -5
  211. package/src/serializedStateManager.ts +276 -110
  212. package/src/utils.ts +51 -20
  213. package/lib/test/attachment.spec.js +0 -380
  214. package/lib/test/attachment.spec.js.map +0 -1
  215. package/lib/test/catchUpMonitor.spec.js +0 -88
  216. package/lib/test/catchUpMonitor.spec.js.map +0 -1
  217. package/lib/test/connectionManager.spec.js +0 -201
  218. package/lib/test/connectionManager.spec.js.map +0 -1
  219. package/lib/test/connectionStateHandler.spec.js +0 -555
  220. package/lib/test/connectionStateHandler.spec.js.map +0 -1
  221. package/lib/test/container.spec.js +0 -64
  222. package/lib/test/container.spec.js.map +0 -1
  223. package/lib/test/deltaManager.spec.js +0 -405
  224. package/lib/test/deltaManager.spec.js.map +0 -1
  225. package/lib/test/loader.spec.js +0 -212
  226. package/lib/test/loader.spec.js.map +0 -1
  227. package/lib/test/locationRedirectionTests.spec.js +0 -44
  228. package/lib/test/locationRedirectionTests.spec.js.map +0 -1
  229. package/lib/test/serializedStateManager.spec.js +0 -148
  230. package/lib/test/serializedStateManager.spec.js.map +0 -1
  231. package/lib/test/snapshotConversionTest.spec.js +0 -79
  232. package/lib/test/snapshotConversionTest.spec.js.map +0 -1
  233. package/lib/test/types/validateContainerLoaderPrevious.generated.js +0 -38
  234. package/lib/test/types/validateContainerLoaderPrevious.generated.js.map +0 -1
  235. package/lib/test/utils.spec.js +0 -31
  236. package/lib/test/utils.spec.js.map +0 -1
@@ -2,43 +2,114 @@
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
+ interface SnapshotInfo 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
+ setSnapshot(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<SnapshotInfo | 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
+ }>;
114
+ export {};
44
115
  //# 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,EAC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A8BD;;;;;;;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,90 +25,73 @@ 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 };
36
+ const snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, this.storageAdapter);
37
+ this.snapshot = { baseSnapshot, snapshotBlobs };
51
38
  }
39
+ return { baseSnapshot, version };
52
40
  }
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,
67
- };
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
- }
81
- return { snapshot, version };
41
+ else {
42
+ const { baseSnapshot, snapshotBlobs } = this.pendingLocalState;
43
+ this.snapshot = { baseSnapshot, snapshotBlobs };
44
+ this.refreshSnapshot ?? (this.refreshSnapshot = (async () => {
45
+ this.latestSnapshot = await getLatestSnapshotInfo(this.mc, this.storageAdapter, supportGetSnapshotApi);
46
+ this.newSnapshotFetched?.();
47
+ this.updateSnapshotAndProcessedOpsMaybe();
48
+ })());
49
+ return { baseSnapshot, version: undefined };
82
50
  }
83
- return this.fetchSnapshotTree(specifiedVersion);
84
51
  }
85
52
  /**
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
53
+ * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.
89
54
  */
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
- });
55
+ updateSnapshotAndProcessedOpsMaybe() {
56
+ if (this.latestSnapshot === undefined) {
57
+ return;
98
58
  }
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 });
59
+ const snapshotSequenceNumber = this.latestSnapshot?.snapshotSequenceNumber;
60
+ if (this.processedOps.length === 0) {
61
+ // can't refresh latest snapshot until we have processed the ops up to it.
62
+ // Pending state would be behind the latest snapshot.
63
+ return;
64
+ }
65
+ const firstProcessedOpSequenceNumber = this.processedOps[0].sequenceNumber;
66
+ const lastProcessedOpSequenceNumber = this.processedOps[this.processedOps.length - 1].sequenceNumber;
67
+ if (snapshotSequenceNumber < firstProcessedOpSequenceNumber) {
68
+ // Snapshot seq number is older than our first processed op, which could mean we're fetching
69
+ // the same snapshot that we already have or snapshot is too old, implicating an unexpected behavior.
70
+ this.mc.logger.sendTelemetryEvent({
71
+ category: snapshotSequenceNumber < firstProcessedOpSequenceNumber - 1
72
+ ? "error"
73
+ : "generic",
74
+ eventName: "OldSnapshotFetchWhileRefreshing",
75
+ snapshotSequenceNumber,
76
+ firstProcessedOpSequenceNumber,
77
+ });
78
+ this.latestSnapshot = undefined;
102
79
  }
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.
80
+ else if (snapshotSequenceNumber <= lastProcessedOpSequenceNumber) {
81
+ // Snapshot seq num is between the first and last processed op.
82
+ // Remove the ops that are already part of the snapshot
83
+ this.processedOps.splice(0, snapshotSequenceNumber - firstProcessedOpSequenceNumber + 1);
84
+ this.snapshot = this.latestSnapshot;
85
+ this.latestSnapshot = undefined;
86
+ this.mc.logger.sendTelemetryEvent({
87
+ eventName: "SnapshotRefreshed",
88
+ snapshotSequenceNumber,
89
+ firstProcessedOpSequenceNumber,
90
+ newFirstProcessedOpSequenceNumber: this.processedOps.length === 0
91
+ ? undefined
92
+ : this.processedOps[0].sequenceNumber,
107
93
  });
108
94
  }
109
- return { snapshot, version };
110
95
  }
111
96
  /**
112
97
  * This method is only meant to be used by Container.attach() to set the initial
@@ -131,8 +116,8 @@ export class SerializedStateManager {
131
116
  const pendingState = {
132
117
  attached: true,
133
118
  pendingRuntimeState,
134
- baseSnapshot: this.snapshot.tree,
135
- snapshotBlobs: this.snapshot.blobs,
119
+ baseSnapshot: this.snapshot.baseSnapshot,
120
+ snapshotBlobs: this.snapshot.snapshotBlobs,
136
121
  savedOps: this.processedOps,
137
122
  url: resolvedUrl.url,
138
123
  // no need to save this if there is no pending runtime state
@@ -142,4 +127,100 @@ export class SerializedStateManager {
142
127
  });
143
128
  }
144
129
  }
130
+ /**
131
+ * Retrieves the most recent snapshot and returns its info.
132
+ *
133
+ * @param mc - The monitoring context.
134
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
135
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
136
+ * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.
137
+ */
138
+ export async function getLatestSnapshotInfo(mc, storageAdapter, supportGetSnapshotApi) {
139
+ return PerformanceEvent.timedExecAsync(mc.logger, { eventName: "GetLatestSnapshotInfo" }, async () => {
140
+ const { baseSnapshot } = await getSnapshotTree(mc, storageAdapter, supportGetSnapshotApi, undefined);
141
+ const snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, storageAdapter);
142
+ const attributes = await getDocumentAttributes(storageAdapter, baseSnapshot);
143
+ const snapshotSequenceNumber = attributes.sequenceNumber;
144
+ return { baseSnapshot, snapshotBlobs, snapshotSequenceNumber };
145
+ }).catch(() => undefined);
146
+ }
147
+ /**
148
+ * Retrieves a snapshot from the storage adapter and transforms it into an ISnapshotTree object.
149
+ *
150
+ * @param mc - The monitoring context.
151
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
152
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
153
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
154
+ * @returns - An ISnapshotTree and its version.
155
+ */
156
+ async function getSnapshotTree(mc, storageAdapter, supportGetSnapshotApi, specifiedVersion) {
157
+ const { snapshot, version } = supportGetSnapshotApi
158
+ ? await fetchISnapshot(mc, storageAdapter, specifiedVersion)
159
+ : await fetchISnapshotTree(mc, storageAdapter, specifiedVersion);
160
+ const baseSnapshot = isInstanceOfISnapshot(snapshot)
161
+ ? snapshot.snapshotTree
162
+ : snapshot;
163
+ assert(baseSnapshot !== undefined, 0x8e4 /* Snapshot should exist */);
164
+ return { baseSnapshot, version };
165
+ }
166
+ /**
167
+ * Fetches an ISnapshot from a storage adapter based on the specified version.
168
+ *
169
+ * @param mc - The monitoring context.
170
+ * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.
171
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
172
+ * @returns - The fetched snapshot tree and its version.
173
+ */
174
+ export async function fetchISnapshot(mc, storageAdapter, specifiedVersion) {
175
+ const snapshot = await storageAdapter.getSnapshot?.({ versionId: specifiedVersion });
176
+ const version = snapshot?.snapshotTree.id === undefined
177
+ ? undefined
178
+ : {
179
+ id: snapshot.snapshotTree.id,
180
+ treeId: snapshot.snapshotTree.id,
181
+ };
182
+ if (snapshot === undefined && specifiedVersion !== undefined) {
183
+ mc.logger.sendErrorEvent({
184
+ eventName: "getSnapshotTreeFailed",
185
+ id: specifiedVersion,
186
+ });
187
+ }
188
+ else if (snapshot !== undefined && version?.id === undefined) {
189
+ mc.logger.sendErrorEvent({
190
+ eventName: "getSnapshotFetchedTreeWithoutVersionId",
191
+ hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
192
+ });
193
+ }
194
+ return { snapshot, version };
195
+ }
196
+ /**
197
+ * Fetches an ISnapshotTree from a storage adapter based on the specified version.
198
+ *
199
+ * @param mc - The monitoring context.
200
+ * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.
201
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
202
+ * @returns - The fetched snapshot tree and its version.
203
+ */
204
+ export async function fetchISnapshotTree(mc, storageAdapter, specifiedVersion) {
205
+ const versions = await storageAdapter.getVersions(specifiedVersion ?? null, 1);
206
+ const version = versions[0];
207
+ if (version === undefined && specifiedVersion !== undefined) {
208
+ // We should have a defined version to load from if specified version requested
209
+ mc.logger.sendErrorEvent({
210
+ eventName: "NoVersionFoundWhenSpecified",
211
+ id: specifiedVersion,
212
+ });
213
+ }
214
+ const snapshot = (await storageAdapter.getSnapshotTree(version)) ?? undefined;
215
+ if (snapshot === undefined && version !== undefined) {
216
+ mc.logger.sendErrorEvent({ eventName: "getSnapshotTreeFailed", id: version.id });
217
+ }
218
+ else if (snapshot !== undefined && version?.id === undefined) {
219
+ mc.logger.sendErrorEvent({
220
+ eventName: "getSnapshotFetchedTreeWithoutVersionId",
221
+ hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
222
+ });
223
+ }
224
+ return { snapshot, version };
225
+ }
145
226
  //# 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,CAA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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":"AAAA;;;GAGG;AAMH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAQ9E,OAAO,EAEN,gBAAgB,EAChB,UAAU,EACV,4BAA4B,GAC5B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAA6B,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA8CnD,MAAM,OAAO,sBAAsB;IAOlC,YACkB,iBAAqD,EACtE,SAA8B,EACb,cAGhB,EACgB,mBAA4B,EAC5B,kBAA+B;QAP/B,sBAAiB,GAAjB,iBAAiB,CAAoC;QAErD,mBAAc,GAAd,cAAc,CAG9B;QACgB,wBAAmB,GAAnB,mBAAmB,CAAS;QAC5B,uBAAkB,GAAlB,kBAAkB,CAAa;QAdhC,iBAAY,GAAgC,EAAE,CAAC;QAgB/D,IAAI,CAAC,EAAE,GAAG,4BAA4B,CAAC;YACtC,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,wBAAwB;SACnC,CAAC,CAAC;IACJ,CAAC;IAED,IAAW,kBAAkB;QAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IACjC,CAAC;IAEM,cAAc,CAAC,OAAkC;QACvD,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC5B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAChC,IAAI,CAAC,kCAAkC,EAAE,CAAC;SAC1C;IACF,CAAC;IAEM,KAAK,CAAC,aAAa,CACzB,gBAAoC,EACpC,qBAA8B;QAE9B,IAAI,IAAI,CAAC,iBA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AC,IAAI,SAAS,CAAC;IAE9E,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE;QACpD,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;KACjF;SAAM,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,EAAE,EAAE,KAAK,SAAS,EAAE;QAC/D,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC;YACxB,SAAS,EAAE,wCAAwC;YACnD,UAAU,EAAE,OAAO,KAAK,SAAS,EAAE,mFAAmF;SACtH,CAAC,CAAC;KACH;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation 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\ninterface SnapshotInfo extends SnapshotWithBlobs {\n\tsnapshotSequenceNumber: number;\n}\n\nexport class SerializedStateManager {\n\tprivate readonly processedOps: ISequencedDocumentMessage[] = [];\n\tprivate snapshot: SnapshotWithBlobs | undefined;\n\tprivate readonly mc: MonitoringContext;\n\tprivate latestSnapshot: SnapshotInfo | 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\tthis.snapshot = { baseSnapshot, snapshotBlobs };\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\tthis.snapshot = { baseSnapshot, snapshotBlobs };\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) {\n\t\t\treturn;\n\t\t}\n\t\tconst snapshotSequenceNumber = this.latestSnapshot?.snapshotSequenceNumber;\n\t\tif (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 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\tcategory:\n\t\t\t\t\tsnapshotSequenceNumber < firstProcessedOpSequenceNumber - 1\n\t\t\t\t\t\t? \"error\"\n\t\t\t\t\t\t: \"generic\",\n\t\t\t\teventName: \"OldSnapshotFetchWhileRefreshing\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\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 setSnapshot(snapshot: SnapshotWithBlobs | undefined) {\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.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<SnapshotInfo | 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"]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.42.3"
9
+ }
10
+ ]
11
+ }
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 } 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, SnapshotWithBlobs } from "./serializedStateManager.js";
9
10
  export interface ISnapshotTreeWithBlobContents extends ISnapshotTree {
10
11
  blobsContents: {
11
12
  [path: string]: ArrayBufferLike;
@@ -56,10 +57,7 @@ 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
+ export declare const getSnapshotTreeAndBlobsFromSerializedContainer: (detachedContainerSnapshot: ISummaryTree) => SnapshotWithBlobs;
63
61
  export declare function getProtocolSnapshotTree(snapshot: ISnapshotTree): ISnapshotTree;
64
62
  export declare const combineSnapshotTreeAndSnapshotBlobs: (baseSnapshot: ISnapshotTree, snapshotBlobs: ISerializableBlobContents) => ISnapshotTreeWithBlobContents;
65
63
  export declare function isDeltaStreamConnectionForbiddenError(error: any): error is DeltaStreamConnectionForbiddenError;
@@ -69,4 +67,5 @@ export declare function getDetachedContainerStateFromSerializedContainer(seriali
69
67
  * If there are multiple calls they will all get the same promise to wait on.
70
68
  */
71
69
  export declare const runSingle: <A extends any[], R>(func: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
70
+ export declare function getDocumentAttributes(storage: Pick<IDocumentStorageService, "readBlob">, tree: ISnapshotTree | undefined): Promise<IDocumentAttributes>;
72
71
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":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AiB/B;AAyED,eAAO,MAAM,8CAA8C,8BAC/B,YAAY,KACrC,iBAYF,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,CAE9E;AAED,eAAO,MAAM,mCAAmC,iBACjC,aAAa,iBACZ,yBAAyB,KACtC,6BAwBF,CAAC;AAEF,wBAAgB,qCAAqC,CACpD,KAAK,EAAE,GAAG,GACR,KAAK,IAAI,mCAAmC,CAM9C;AAoBD,wBAAgB,gDAAgD,CAC/D,mBAAmB,EAAE,MAAM,GACzB,8BAA8B,CAkBhC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,sFAsBrB,CAAC;AAEF,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,EAClD,IAAI,EAAE,aAAa,GAAG,SAAS,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAiB9B"}
package/lib/utils.js CHANGED
@@ -2,13 +2,13 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { v4 as uuid } from "uuid";
6
5
  import { Uint8ArrayToString, stringToBuffer } from "@fluid-internal/client-utils";
7
- import { assert, compareArrays, unreachableCase } from "@fluidframework/core-utils";
8
- import { SummaryType } from "@fluidframework/protocol-definitions";
9
- import { LoggingError, UsageError } from "@fluidframework/telemetry-utils";
10
- import { isCombinedAppAndProtocolSummary, } from "@fluidframework/driver-utils";
6
+ import { assert, compareArrays, unreachableCase } from "@fluidframework/core-utils/internal";
11
7
  import { DriverErrorTypes } from "@fluidframework/driver-definitions";
8
+ import { isCombinedAppAndProtocolSummary, readAndParse, } from "@fluidframework/driver-utils/internal";
9
+ import { SummaryType, } from "@fluidframework/protocol-definitions";
10
+ import { LoggingError, UsageError } from "@fluidframework/telemetry-utils/internal";
11
+ import { v4 as uuid } from "uuid";
12
12
  /**
13
13
  * Utility api to parse the IResolvedUrl.url into specific parts like querystring, path to get
14
14
  * deep link info etc.
@@ -73,9 +73,9 @@ function convertSummaryToSnapshotAndBlobs(summary) {
73
73
  const summaryObject = summary.tree[key];
74
74
  switch (summaryObject.type) {
75
75
  case SummaryType.Tree: {
76
- const { tree, blobs } = convertSummaryToSnapshotAndBlobs(summaryObject);
77
- treeNode.trees[key] = tree;
78
- blobContents = { ...blobContents, ...blobs };
76
+ const innerSnapshot = convertSummaryToSnapshotAndBlobs(summaryObject);
77
+ treeNode.trees[key] = innerSnapshot.baseSnapshot;
78
+ blobContents = { ...blobContents, ...innerSnapshot.snapshotBlobs };
79
79
  break;
80
80
  }
81
81
  case SummaryType.Attachment:
@@ -98,7 +98,8 @@ function convertSummaryToSnapshotAndBlobs(summary) {
98
98
  }
99
99
  }
100
100
  }
101
- return { tree: treeNode, blobs: blobContents };
101
+ const pendingSnapshot = { baseSnapshot: treeNode, snapshotBlobs: blobContents };
102
+ return pendingSnapshot;
102
103
  }
103
104
  /**
104
105
  * Converts summary parts into a SnapshotTree and its blob contents.
@@ -170,11 +171,11 @@ export function getDetachedContainerStateFromSerializedContainer(serializedConta
170
171
  return parsedContainerState;
171
172
  }
172
173
  else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {
173
- const { tree, blobs } = getSnapshotTreeAndBlobsFromSerializedContainer(parsedContainerState);
174
+ const { baseSnapshot, snapshotBlobs } = getSnapshotTreeAndBlobsFromSerializedContainer(parsedContainerState);
174
175
  const detachedContainerState = {
175
176
  attached: false,
176
- baseSnapshot: tree,
177
- snapshotBlobs: blobs,
177
+ baseSnapshot,
178
+ snapshotBlobs,
178
179
  hasAttachmentBlobs: parsedContainerState.tree[hasBlobsSummaryTree] !== undefined,
179
180
  };
180
181
  return detachedContainerState;
@@ -203,4 +204,18 @@ export const runSingle = (func) => {
203
204
  return running.result;
204
205
  };
205
206
  };
207
+ export async function getDocumentAttributes(storage, tree) {
208
+ if (tree === undefined) {
209
+ return {
210
+ minimumSequenceNumber: 0,
211
+ sequenceNumber: 0,
212
+ };
213
+ }
214
+ // Backward compatibility: old docs would have ".attributes" instead of "attributes"
215
+ const attributesHash = ".protocol" in tree.trees
216
+ ? tree.trees[".protocol"].blobs.attributes
217
+ : tree.blobs[".attributes"];
218
+ const attributes = await readAndParse(storage, attributesHash);
219
+ return attributes;
220
+ }
206
221
  //# sourceMappingURL=utils.js.map