@fluidframework/container-loader 2.63.0-359286 → 2.63.0-359734

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/attachment.d.ts +2 -7
  2. package/dist/attachment.d.ts.map +1 -1
  3. package/dist/attachment.js +2 -4
  4. package/dist/attachment.js.map +1 -1
  5. package/dist/container.d.ts.map +1 -1
  6. package/dist/container.js +10 -9
  7. package/dist/container.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 +11 -8
  12. package/dist/serializedStateManager.d.ts.map +1 -1
  13. package/dist/serializedStateManager.js +51 -34
  14. package/dist/serializedStateManager.js.map +1 -1
  15. package/dist/utils.d.ts +7 -1
  16. package/dist/utils.d.ts.map +1 -1
  17. package/dist/utils.js +41 -23
  18. package/dist/utils.js.map +1 -1
  19. package/lib/attachment.d.ts +2 -7
  20. package/lib/attachment.d.ts.map +1 -1
  21. package/lib/attachment.js +3 -5
  22. package/lib/attachment.js.map +1 -1
  23. package/lib/container.d.ts.map +1 -1
  24. package/lib/container.js +11 -10
  25. package/lib/container.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 +11 -8
  30. package/lib/serializedStateManager.d.ts.map +1 -1
  31. package/lib/serializedStateManager.js +52 -35
  32. package/lib/serializedStateManager.js.map +1 -1
  33. package/lib/utils.d.ts +7 -1
  34. package/lib/utils.d.ts.map +1 -1
  35. package/lib/utils.js +39 -22
  36. package/lib/utils.js.map +1 -1
  37. package/package.json +11 -11
  38. package/src/attachment.ts +7 -13
  39. package/src/container.ts +11 -11
  40. package/src/packageVersion.ts +1 -1
  41. package/src/serializedStateManager.ts +68 -39
  42. package/src/utils.ts +49 -26
package/src/utils.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import {
7
- Uint8ArrayToString,
7
+ Uint8ArrayToArrayBuffer,
8
8
  bufferToString,
9
9
  stringToBuffer,
10
10
  } from "@fluid-internal/client-utils";
@@ -132,35 +132,39 @@ export function combineAppAndProtocolSummary(
132
132
  * to align detached container format with IPendingContainerState
133
133
  * @param summary - ISummaryTree
134
134
  */
135
- function convertSummaryToSnapshotAndBlobs(summary: ISummaryTree): SnapshotWithBlobs {
136
- let blobContents: ISerializableBlobContents = {};
137
- const treeNode: ISnapshotTree = {
135
+ function convertSummaryToISnapshot(
136
+ summary: ISummaryTree,
137
+ blobContents = new Map<string, ArrayBuffer>(),
138
+ ): ISnapshot {
139
+ const snapshotTree: ISnapshotTree = {
138
140
  blobs: {},
139
141
  trees: {},
140
142
  id: uuid(),
141
143
  unreferenced: summary.unreferenced,
142
144
  groupId: summary.groupId,
143
145
  };
146
+
144
147
  for (const [key, summaryObject] of Object.entries(summary.tree)) {
145
148
  switch (summaryObject.type) {
146
149
  case SummaryType.Tree: {
147
- const innerSnapshot = convertSummaryToSnapshotAndBlobs(summaryObject);
148
- treeNode.trees[key] = innerSnapshot.baseSnapshot;
149
- blobContents = { ...blobContents, ...innerSnapshot.snapshotBlobs };
150
+ const innerSnapshot = convertSummaryToISnapshot(summaryObject, blobContents);
151
+ snapshotTree.trees[key] = innerSnapshot.snapshotTree;
150
152
  break;
151
153
  }
152
154
  case SummaryType.Attachment: {
153
- treeNode.blobs[key] = summaryObject.id;
155
+ snapshotTree.blobs[key] = summaryObject.id;
154
156
  break;
155
157
  }
156
158
  case SummaryType.Blob: {
157
159
  const blobId = uuid();
158
- treeNode.blobs[key] = blobId;
159
- const contentString: string =
160
+ snapshotTree.blobs[key] = blobId;
161
+ blobContents.set(
162
+ blobId,
160
163
  summaryObject.content instanceof Uint8Array
161
- ? Uint8ArrayToString(summaryObject.content)
162
- : summaryObject.content;
163
- blobContents[blobId] = contentString;
164
+ ? Uint8ArrayToArrayBuffer(summaryObject.content)
165
+ : stringToBuffer(summaryObject.content, "utf8"),
166
+ );
167
+
164
168
  break;
165
169
  }
166
170
  case SummaryType.Handle: {
@@ -174,8 +178,14 @@ function convertSummaryToSnapshotAndBlobs(summary: ISummaryTree): SnapshotWithBl
174
178
  }
175
179
  }
176
180
  }
177
- const pendingSnapshot = { baseSnapshot: treeNode, snapshotBlobs: blobContents };
178
- return pendingSnapshot;
181
+ return {
182
+ blobContents,
183
+ latestSequenceNumber: undefined,
184
+ ops: [],
185
+ sequenceNumber: 0,
186
+ snapshotFormatV: 1,
187
+ snapshotTree,
188
+ };
179
189
  }
180
190
 
181
191
  /**
@@ -212,7 +222,7 @@ export function convertSnapshotInfoToSnapshot(
212
222
  snapshotInfo: ISnapshotInfo,
213
223
  snapshotSequenceNumber: number,
214
224
  ): ISnapshot {
215
- const blobContents = new Map<string, ArrayBufferLike>();
225
+ const blobContents = new Map<string, ArrayBuffer>();
216
226
  for (const [blobId, serializedContent] of Object.entries(snapshotInfo.snapshotBlobs)) {
217
227
  blobContents.set(blobId, stringToBuffer(serializedContent, "utf8"));
218
228
  }
@@ -231,30 +241,30 @@ export function convertSnapshotInfoToSnapshot(
231
241
  * @param protocolSummaryTree - Protocol Summary Tree
232
242
  * @param appSummaryTree - App Summary Tree
233
243
  */
234
- function convertProtocolAndAppSummaryToSnapshotAndBlobs(
244
+ function convertProtocolAndAppSummaryToISnapshot(
235
245
  protocolSummaryTree: ISummaryTree,
236
246
  appSummaryTree: ISummaryTree,
237
- ): SnapshotWithBlobs {
247
+ ): ISnapshot {
238
248
  const combinedSummary: ISummaryTree = {
239
249
  type: SummaryType.Tree,
240
250
  tree: { ...appSummaryTree.tree },
241
251
  };
242
252
 
243
253
  combinedSummary.tree[".protocol"] = protocolSummaryTree;
244
- const snapshotTreeWithBlobContents = convertSummaryToSnapshotAndBlobs(combinedSummary);
254
+ const snapshotTreeWithBlobContents = convertSummaryToISnapshot(combinedSummary);
245
255
  return snapshotTreeWithBlobContents;
246
256
  }
247
257
 
248
- export const getSnapshotTreeAndBlobsFromSerializedContainer = (
258
+ export const getISnapshotFromSerializedContainer = (
249
259
  detachedContainerSnapshot: ISummaryTree,
250
- ): SnapshotWithBlobs => {
260
+ ): ISnapshot => {
251
261
  assert(
252
262
  isCombinedAppAndProtocolSummary(detachedContainerSnapshot),
253
263
  0x8e6 /* Protocol and App summary trees should be present */,
254
264
  );
255
265
  const protocolSummaryTree = detachedContainerSnapshot.tree[".protocol"];
256
266
  const appSummaryTree = detachedContainerSnapshot.tree[".app"];
257
- const snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToSnapshotAndBlobs(
267
+ const snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToISnapshot(
258
268
  protocolSummaryTree,
259
269
  appSummaryTree,
260
270
  );
@@ -322,6 +332,21 @@ function isPendingDetachedContainerState(
322
332
  }
323
333
  return true;
324
334
  }
335
+ /**
336
+ * Converts an ISnapshot to a SnapshotWithBlobs, extracting and serializing its blob contents.
337
+ * @param snapshot - The ISnapshot to convert.
338
+ * @returns A SnapshotWithBlobs containing the base snapshot and serialized blob contents.
339
+ */
340
+ export function convertISnapshotToSnapshotWithBlobs(snapshot: ISnapshot): SnapshotWithBlobs {
341
+ const snapshotBlobs: ISerializableBlobContents = {};
342
+ for (const [id, blob] of snapshot.blobContents.entries()) {
343
+ snapshotBlobs[id] = bufferToString(blob, "utf8");
344
+ }
345
+ return {
346
+ baseSnapshot: snapshot.snapshotTree,
347
+ snapshotBlobs,
348
+ };
349
+ }
325
350
 
326
351
  /**
327
352
  * Parses the given string into {@link IPendingDetachedContainerState} format,
@@ -339,12 +364,10 @@ export function getDetachedContainerStateFromSerializedContainer(
339
364
  return parsedContainerState;
340
365
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
341
366
  } else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {
342
- const { baseSnapshot, snapshotBlobs } =
343
- getSnapshotTreeAndBlobsFromSerializedContainer(parsedContainerState);
367
+ const snapshot = getISnapshotFromSerializedContainer(parsedContainerState);
344
368
  const detachedContainerState: IPendingDetachedContainerState = {
345
369
  attached: false,
346
- baseSnapshot,
347
- snapshotBlobs,
370
+ ...convertISnapshotToSnapshotWithBlobs(snapshot),
348
371
  hasAttachmentBlobs: parsedContainerState.tree[hasBlobsSummaryTree] !== undefined,
349
372
  };
350
373
  return detachedContainerState;