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

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 (42) hide show
  1. package/dist/container.d.ts.map +1 -1
  2. package/dist/container.js +9 -8
  3. package/dist/container.js.map +1 -1
  4. package/dist/deltaManager.d.ts +4 -1
  5. package/dist/deltaManager.d.ts.map +1 -1
  6. package/dist/deltaManager.js +8 -5
  7. package/dist/deltaManager.js.map +1 -1
  8. package/dist/packageVersion.d.ts +1 -1
  9. package/dist/packageVersion.js +1 -1
  10. package/dist/packageVersion.js.map +1 -1
  11. package/dist/serializedStateManager.d.ts +3 -4
  12. package/dist/serializedStateManager.d.ts.map +1 -1
  13. package/dist/serializedStateManager.js +28 -12
  14. package/dist/serializedStateManager.js.map +1 -1
  15. package/dist/utils.d.ts +18 -2
  16. package/dist/utils.d.ts.map +1 -1
  17. package/dist/utils.js +43 -1
  18. package/dist/utils.js.map +1 -1
  19. package/lib/container.d.ts.map +1 -1
  20. package/lib/container.js +9 -8
  21. package/lib/container.js.map +1 -1
  22. package/lib/deltaManager.d.ts +4 -1
  23. package/lib/deltaManager.d.ts.map +1 -1
  24. package/lib/deltaManager.js +8 -5
  25. package/lib/deltaManager.js.map +1 -1
  26. package/lib/packageVersion.d.ts +1 -1
  27. package/lib/packageVersion.js +1 -1
  28. package/lib/packageVersion.js.map +1 -1
  29. package/lib/serializedStateManager.d.ts +3 -4
  30. package/lib/serializedStateManager.d.ts.map +1 -1
  31. package/lib/serializedStateManager.js +28 -12
  32. package/lib/serializedStateManager.js.map +1 -1
  33. package/lib/utils.d.ts +18 -2
  34. package/lib/utils.d.ts.map +1 -1
  35. package/lib/utils.js +41 -1
  36. package/lib/utils.js.map +1 -1
  37. package/package.json +16 -16
  38. package/src/container.ts +12 -10
  39. package/src/deltaManager.ts +9 -5
  40. package/src/packageVersion.ts +1 -1
  41. package/src/serializedStateManager.ts +33 -17
  42. package/src/utils.ts +51 -2
package/src/utils.ts CHANGED
@@ -3,10 +3,13 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { Uint8ArrayToString, stringToBuffer } from "@fluid-internal/client-utils";
6
+ import { Uint8ArrayToString, bufferToString, stringToBuffer } from "@fluid-internal/client-utils";
7
7
  import { assert, compareArrays, unreachableCase } from "@fluidframework/core-utils/internal";
8
8
  import { DriverErrorTypes } from "@fluidframework/driver-definitions";
9
- import { IDocumentStorageService } from "@fluidframework/driver-definitions/internal";
9
+ import {
10
+ IDocumentStorageService,
11
+ type ISnapshot,
12
+ } from "@fluidframework/driver-definitions/internal";
10
13
  import {
11
14
  CombinedAppAndProtocolSummary,
12
15
  DeltaStreamConnectionForbiddenError,
@@ -25,6 +28,7 @@ import { v4 as uuid } from "uuid";
25
28
  import { ISerializableBlobContents } from "./containerStorageAdapter.js";
26
29
  import type {
27
30
  IPendingDetachedContainerState,
31
+ ISnapshotInfo,
28
32
  SnapshotWithBlobs,
29
33
  } from "./serializedStateManager.js";
30
34
 
@@ -169,6 +173,51 @@ function convertSummaryToSnapshotAndBlobs(summary: ISummaryTree): SnapshotWithBl
169
173
  return pendingSnapshot;
170
174
  }
171
175
 
176
+ /**
177
+ * Converts a snapshot to snapshotInfo with its blob contents
178
+ * to align detached container format with IPendingContainerState
179
+ *
180
+ * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown
181
+ * @param snapshot - ISnapshot
182
+ */
183
+ export function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): ISnapshotInfo {
184
+ assert(snapshot.sequenceNumber !== undefined, "Snapshot sequence number is missing");
185
+ const snapshotBlobs: ISerializableBlobContents = {};
186
+ for (const [blobId, arrayBufferLike] of snapshot.blobContents.entries()) {
187
+ snapshotBlobs[blobId] = bufferToString(arrayBufferLike, "utf8");
188
+ }
189
+ return {
190
+ baseSnapshot: snapshot.snapshotTree,
191
+ snapshotBlobs,
192
+ snapshotSequenceNumber: snapshot.sequenceNumber,
193
+ };
194
+ }
195
+
196
+ /**
197
+ * Converts a snapshot to snapshotInfo with its blob contents
198
+ * to align detached container format with IPendingContainerState
199
+ *
200
+ * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown
201
+ * @param snapshot - ISnapshot
202
+ */
203
+ export function convertSnapshotInfoToSnapshot(
204
+ snapshotInfo: ISnapshotInfo,
205
+ snapshotSequenceNumber: number,
206
+ ): ISnapshot {
207
+ const blobContents = new Map<string, ArrayBufferLike>();
208
+ for (const [blobId, serializedContent] of Object.entries(snapshotInfo.snapshotBlobs)) {
209
+ blobContents.set(blobId, stringToBuffer(serializedContent, "utf8"));
210
+ }
211
+ return {
212
+ snapshotTree: snapshotInfo.baseSnapshot,
213
+ blobContents,
214
+ ops: [],
215
+ sequenceNumber: snapshotSequenceNumber,
216
+ latestSequenceNumber: undefined,
217
+ snapshotFormatV: 1,
218
+ };
219
+ }
220
+
172
221
  /**
173
222
  * Converts summary parts into a SnapshotTree and its blob contents.
174
223
  * @param protocolSummaryTree - Protocol Summary Tree