@fluidframework/container-loader 2.63.0-359461 → 2.63.0-359962

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 (77) hide show
  1. package/api-report/container-loader.legacy.alpha.api.md +3 -0
  2. package/dist/attachment.d.ts +2 -7
  3. package/dist/attachment.d.ts.map +1 -1
  4. package/dist/attachment.js +2 -4
  5. package/dist/attachment.js.map +1 -1
  6. package/dist/container.d.ts.map +1 -1
  7. package/dist/container.js +7 -7
  8. package/dist/container.js.map +1 -1
  9. package/dist/containerStorageAdapter.d.ts +2 -2
  10. package/dist/containerStorageAdapter.d.ts.map +1 -1
  11. package/dist/containerStorageAdapter.js +1 -1
  12. package/dist/containerStorageAdapter.js.map +1 -1
  13. package/dist/createAndLoadContainerUtils.js +1 -1
  14. package/dist/createAndLoadContainerUtils.js.map +1 -1
  15. package/dist/frozenServices.d.ts +10 -1
  16. package/dist/frozenServices.d.ts.map +1 -1
  17. package/dist/frozenServices.js +24 -4
  18. package/dist/frozenServices.js.map +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/legacyAlpha.d.ts +1 -0
  24. package/dist/packageVersion.d.ts +1 -1
  25. package/dist/packageVersion.js +1 -1
  26. package/dist/packageVersion.js.map +1 -1
  27. package/dist/serializedStateManager.d.ts +19 -12
  28. package/dist/serializedStateManager.d.ts.map +1 -1
  29. package/dist/serializedStateManager.js +112 -98
  30. package/dist/serializedStateManager.js.map +1 -1
  31. package/dist/utils.d.ts +10 -4
  32. package/dist/utils.d.ts.map +1 -1
  33. package/dist/utils.js +43 -25
  34. package/dist/utils.js.map +1 -1
  35. package/lib/attachment.d.ts +2 -7
  36. package/lib/attachment.d.ts.map +1 -1
  37. package/lib/attachment.js +3 -5
  38. package/lib/attachment.js.map +1 -1
  39. package/lib/container.d.ts.map +1 -1
  40. package/lib/container.js +8 -8
  41. package/lib/container.js.map +1 -1
  42. package/lib/containerStorageAdapter.d.ts +2 -2
  43. package/lib/containerStorageAdapter.d.ts.map +1 -1
  44. package/lib/containerStorageAdapter.js +1 -1
  45. package/lib/containerStorageAdapter.js.map +1 -1
  46. package/lib/createAndLoadContainerUtils.js +2 -2
  47. package/lib/createAndLoadContainerUtils.js.map +1 -1
  48. package/lib/frozenServices.d.ts +10 -1
  49. package/lib/frozenServices.d.ts.map +1 -1
  50. package/lib/frozenServices.js +20 -1
  51. package/lib/frozenServices.js.map +1 -1
  52. package/lib/index.d.ts +1 -0
  53. package/lib/index.d.ts.map +1 -1
  54. package/lib/index.js +1 -0
  55. package/lib/index.js.map +1 -1
  56. package/lib/legacyAlpha.d.ts +1 -0
  57. package/lib/packageVersion.d.ts +1 -1
  58. package/lib/packageVersion.js +1 -1
  59. package/lib/packageVersion.js.map +1 -1
  60. package/lib/serializedStateManager.d.ts +19 -12
  61. package/lib/serializedStateManager.d.ts.map +1 -1
  62. package/lib/serializedStateManager.js +114 -100
  63. package/lib/serializedStateManager.js.map +1 -1
  64. package/lib/utils.d.ts +10 -4
  65. package/lib/utils.d.ts.map +1 -1
  66. package/lib/utils.js +41 -24
  67. package/lib/utils.js.map +1 -1
  68. package/package.json +11 -11
  69. package/src/attachment.ts +7 -13
  70. package/src/container.ts +12 -10
  71. package/src/containerStorageAdapter.ts +5 -6
  72. package/src/createAndLoadContainerUtils.ts +2 -2
  73. package/src/frozenServices.ts +28 -2
  74. package/src/index.ts +1 -0
  75. package/src/packageVersion.ts +1 -1
  76. package/src/serializedStateManager.ts +166 -132
  77. package/src/utils.ts +53 -31
package/src/utils.ts CHANGED
@@ -4,9 +4,9 @@
4
4
  */
5
5
 
6
6
  import {
7
- Uint8ArrayToString,
8
7
  bufferToString,
9
8
  stringToBuffer,
9
+ Uint8ArrayToArrayBuffer,
10
10
  } from "@fluid-internal/client-utils";
11
11
  import { assert, compareArrays, unreachableCase } from "@fluidframework/core-utils/internal";
12
12
  import { type ISummaryTree, SummaryType } from "@fluidframework/driver-definitions";
@@ -34,7 +34,7 @@ import type { ISerializableBlobContents } from "./containerStorageAdapter.js";
34
34
  import type {
35
35
  IPendingContainerState,
36
36
  IPendingDetachedContainerState,
37
- ISnapshotInfo,
37
+ SerializedSnapshotInfo,
38
38
  SnapshotWithBlobs,
39
39
  } from "./serializedStateManager.js";
40
40
 
@@ -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
  /**
@@ -185,7 +195,7 @@ function convertSummaryToSnapshotAndBlobs(summary: ISummaryTree): SnapshotWithBl
185
195
  * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown
186
196
  * @param snapshot - ISnapshot
187
197
  */
188
- export function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): ISnapshotInfo {
198
+ export function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): SerializedSnapshotInfo {
189
199
  assert(
190
200
  snapshot.sequenceNumber !== undefined,
191
201
  0x93a /* Snapshot sequence number is missing */,
@@ -209,10 +219,9 @@ export function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): ISnapshotInf
209
219
  * @param snapshot - ISnapshot
210
220
  */
211
221
  export function convertSnapshotInfoToSnapshot(
212
- snapshotInfo: ISnapshotInfo,
213
- snapshotSequenceNumber: number,
222
+ snapshotInfo: SerializedSnapshotInfo,
214
223
  ): ISnapshot {
215
- const blobContents = new Map<string, ArrayBufferLike>();
224
+ const blobContents = new Map<string, ArrayBuffer>();
216
225
  for (const [blobId, serializedContent] of Object.entries(snapshotInfo.snapshotBlobs)) {
217
226
  blobContents.set(blobId, stringToBuffer(serializedContent, "utf8"));
218
227
  }
@@ -220,7 +229,7 @@ export function convertSnapshotInfoToSnapshot(
220
229
  snapshotTree: snapshotInfo.baseSnapshot,
221
230
  blobContents,
222
231
  ops: [],
223
- sequenceNumber: snapshotSequenceNumber,
232
+ sequenceNumber: snapshotInfo.snapshotSequenceNumber,
224
233
  latestSequenceNumber: undefined,
225
234
  snapshotFormatV: 1,
226
235
  };
@@ -231,30 +240,30 @@ export function convertSnapshotInfoToSnapshot(
231
240
  * @param protocolSummaryTree - Protocol Summary Tree
232
241
  * @param appSummaryTree - App Summary Tree
233
242
  */
234
- function convertProtocolAndAppSummaryToSnapshotAndBlobs(
243
+ function convertProtocolAndAppSummaryToISnapshot(
235
244
  protocolSummaryTree: ISummaryTree,
236
245
  appSummaryTree: ISummaryTree,
237
- ): SnapshotWithBlobs {
246
+ ): ISnapshot {
238
247
  const combinedSummary: ISummaryTree = {
239
248
  type: SummaryType.Tree,
240
249
  tree: { ...appSummaryTree.tree },
241
250
  };
242
251
 
243
252
  combinedSummary.tree[".protocol"] = protocolSummaryTree;
244
- const snapshotTreeWithBlobContents = convertSummaryToSnapshotAndBlobs(combinedSummary);
253
+ const snapshotTreeWithBlobContents = convertSummaryToISnapshot(combinedSummary);
245
254
  return snapshotTreeWithBlobContents;
246
255
  }
247
256
 
248
- export const getSnapshotTreeAndBlobsFromSerializedContainer = (
257
+ export const getISnapshotFromSerializedContainer = (
249
258
  detachedContainerSnapshot: ISummaryTree,
250
- ): SnapshotWithBlobs => {
259
+ ): ISnapshot => {
251
260
  assert(
252
261
  isCombinedAppAndProtocolSummary(detachedContainerSnapshot),
253
262
  0x8e6 /* Protocol and App summary trees should be present */,
254
263
  );
255
264
  const protocolSummaryTree = detachedContainerSnapshot.tree[".protocol"];
256
265
  const appSummaryTree = detachedContainerSnapshot.tree[".app"];
257
- const snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToSnapshotAndBlobs(
266
+ const snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToISnapshot(
258
267
  protocolSummaryTree,
259
268
  appSummaryTree,
260
269
  );
@@ -322,6 +331,21 @@ function isPendingDetachedContainerState(
322
331
  }
323
332
  return true;
324
333
  }
334
+ /**
335
+ * Converts an ISnapshot to a SnapshotWithBlobs, extracting and serializing its blob contents.
336
+ * @param snapshot - The ISnapshot to convert.
337
+ * @returns A SnapshotWithBlobs containing the base snapshot and serialized blob contents.
338
+ */
339
+ export function convertISnapshotToSnapshotWithBlobs(snapshot: ISnapshot): SnapshotWithBlobs {
340
+ const snapshotBlobs: ISerializableBlobContents = {};
341
+ for (const [id, blob] of snapshot.blobContents.entries()) {
342
+ snapshotBlobs[id] = bufferToString(blob, "utf8");
343
+ }
344
+ return {
345
+ baseSnapshot: snapshot.snapshotTree,
346
+ snapshotBlobs,
347
+ };
348
+ }
325
349
 
326
350
  /**
327
351
  * Parses the given string into {@link IPendingDetachedContainerState} format,
@@ -339,12 +363,10 @@ export function getDetachedContainerStateFromSerializedContainer(
339
363
  return parsedContainerState;
340
364
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
341
365
  } else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {
342
- const { baseSnapshot, snapshotBlobs } =
343
- getSnapshotTreeAndBlobsFromSerializedContainer(parsedContainerState);
366
+ const snapshot = getISnapshotFromSerializedContainer(parsedContainerState);
344
367
  const detachedContainerState: IPendingDetachedContainerState = {
345
368
  attached: false,
346
- baseSnapshot,
347
- snapshotBlobs,
369
+ ...convertISnapshotToSnapshotWithBlobs(snapshot),
348
370
  hasAttachmentBlobs: parsedContainerState.tree[hasBlobsSummaryTree] !== undefined,
349
371
  };
350
372
  return detachedContainerState;