@fluidframework/driver-utils 0.59.2000-63294 → 0.59.3000-66610

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 (70) hide show
  1. package/dist/blobAggregationStorage.d.ts.map +1 -1
  2. package/dist/blobAggregationStorage.js +20 -20
  3. package/dist/blobAggregationStorage.js.map +1 -1
  4. package/dist/buildSnapshotTree.js +4 -4
  5. package/dist/buildSnapshotTree.js.map +1 -1
  6. package/dist/documentStorageServiceProxy.js.map +1 -1
  7. package/dist/fluidResolvedUrl.js +1 -1
  8. package/dist/fluidResolvedUrl.js.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/insecureUrlResolver.js +2 -2
  14. package/dist/insecureUrlResolver.js.map +1 -1
  15. package/dist/multiDocumentServiceFactory.js +4 -4
  16. package/dist/multiDocumentServiceFactory.js.map +1 -1
  17. package/dist/network.d.ts.map +1 -1
  18. package/dist/network.js.map +1 -1
  19. package/dist/networkUtils.js +3 -3
  20. package/dist/networkUtils.js.map +1 -1
  21. package/dist/packageVersion.d.ts +1 -1
  22. package/dist/packageVersion.js +1 -1
  23. package/dist/packageVersion.js.map +1 -1
  24. package/dist/parallelRequests.d.ts.map +1 -1
  25. package/dist/parallelRequests.js +28 -28
  26. package/dist/parallelRequests.js.map +1 -1
  27. package/dist/prefetchDocumentStorageService.js +1 -1
  28. package/dist/prefetchDocumentStorageService.js.map +1 -1
  29. package/dist/rateLimiter.js +1 -1
  30. package/dist/rateLimiter.js.map +1 -1
  31. package/dist/readAndParse.js +1 -1
  32. package/dist/readAndParse.js.map +1 -1
  33. package/dist/runWithRetry.js +3 -3
  34. package/dist/runWithRetry.js.map +1 -1
  35. package/dist/summaryForCreateNew.js.map +1 -1
  36. package/dist/treeConversions.js +2 -2
  37. package/dist/treeConversions.js.map +1 -1
  38. package/dist/treeUtils.d.ts +51 -0
  39. package/dist/treeUtils.d.ts.map +1 -0
  40. package/dist/treeUtils.js +85 -0
  41. package/dist/treeUtils.js.map +1 -0
  42. package/lib/blobAggregationStorage.d.ts.map +1 -1
  43. package/lib/blobAggregationStorage.js.map +1 -1
  44. package/lib/documentStorageServiceProxy.js.map +1 -1
  45. package/lib/index.d.ts +1 -0
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js +1 -0
  48. package/lib/index.js.map +1 -1
  49. package/lib/insecureUrlResolver.js.map +1 -1
  50. package/lib/network.d.ts.map +1 -1
  51. package/lib/network.js.map +1 -1
  52. package/lib/networkUtils.js.map +1 -1
  53. package/lib/packageVersion.d.ts +1 -1
  54. package/lib/packageVersion.js +1 -1
  55. package/lib/packageVersion.js.map +1 -1
  56. package/lib/parallelRequests.d.ts.map +1 -1
  57. package/lib/parallelRequests.js.map +1 -1
  58. package/lib/runWithRetry.js.map +1 -1
  59. package/lib/summaryForCreateNew.js.map +1 -1
  60. package/lib/treeUtils.d.ts +51 -0
  61. package/lib/treeUtils.d.ts.map +1 -0
  62. package/lib/treeUtils.js +80 -0
  63. package/lib/treeUtils.js.map +1 -0
  64. package/package.json +11 -10
  65. package/src/blobAggregationStorage.ts +5 -7
  66. package/src/index.ts +1 -0
  67. package/src/network.ts +2 -2
  68. package/src/packageVersion.ts +1 -1
  69. package/src/parallelRequests.ts +9 -12
  70. package/src/treeUtils.ts +111 -0
@@ -0,0 +1,111 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ assert,
8
+ IsoBuffer,
9
+ } from "@fluidframework/common-utils";
10
+ import {
11
+ SummaryType,
12
+ ISnapshotTree,
13
+ ISummaryTree,
14
+ SummaryObject,
15
+ } from "@fluidframework/protocol-definitions";
16
+
17
+ /**
18
+ * Summary tree assembler props
19
+ */
20
+ export interface ISummaryTreeAssemblerProps {
21
+ /**
22
+ * Indicates that this tree is unreferenced. If this is not present, the tree is considered referenced.
23
+ */
24
+ unreferenced?: true;
25
+ }
26
+
27
+ /**
28
+ * Summary tree assembler (without stats collection).
29
+ */
30
+ export class SummaryTreeAssembler {
31
+ private attachmentCounter: number = 0;
32
+ private readonly summaryTree: { [path: string]: SummaryObject; } = {};
33
+
34
+ constructor(
35
+ private readonly props?: ISummaryTreeAssemblerProps,
36
+ ) { }
37
+
38
+ /**
39
+ * Get final summary
40
+ */
41
+ public get summary(): ISummaryTree {
42
+ return {
43
+ type: SummaryType.Tree,
44
+ tree: { ...this.summaryTree },
45
+ unreferenced: this.props?.unreferenced,
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Add blob to summary
51
+ */
52
+ public addBlob(key: string, content: string | Uint8Array): void {
53
+ this.summaryTree[key] = {
54
+ type: SummaryType.Blob,
55
+ content,
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Add handle to summary
61
+ */
62
+ public addHandle(
63
+ key: string,
64
+ handleType: SummaryType.Tree | SummaryType.Blob | SummaryType.Attachment,
65
+ handle: string): void {
66
+ this.summaryTree[key] = {
67
+ type: SummaryType.Handle,
68
+ handleType,
69
+ handle,
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Add tree to summary
75
+ */
76
+ public addTree(key: string, summary: ISummaryTree): void {
77
+ this.summaryTree[key] = summary;
78
+ }
79
+
80
+ /**
81
+ * Add attachment to summary
82
+ */
83
+ public addAttachment(id: string) {
84
+ this.summaryTree[this.attachmentCounter++] = { id, type: SummaryType.Attachment };
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Helper function that converts ISnapshotTree and blobs to ISummaryTree
90
+ * @param snapshot - Source snapshot tree
91
+ * @param blobs - Blobs cache
92
+ * @returns Converted snapshot in ISummaryTree format
93
+ */
94
+ export function convertSnapshotAndBlobsToSummaryTree(
95
+ snapshot: ISnapshotTree,
96
+ blobs: Map<string, ArrayBuffer>,
97
+ ): ISummaryTree {
98
+ const assembler = new SummaryTreeAssembler({
99
+ unreferenced: snapshot.unreferenced,
100
+ });
101
+ for (const [path, id] of Object.entries(snapshot.blobs)) {
102
+ const blob = blobs.get(id);
103
+ assert(blob !== undefined, 0x2dd /* "Cannot find blob for a given id" */);
104
+ assembler.addBlob(path, IsoBuffer.from(blob).toString("utf-8"));
105
+ }
106
+ for (const [key, tree] of Object.entries(snapshot.trees)) {
107
+ const subtree = convertSnapshotAndBlobsToSummaryTree(tree, blobs);
108
+ assembler.addTree(key, subtree);
109
+ }
110
+ return assembler.summary;
111
+ }