@fluidframework/local-driver 2.0.0-rc.3.0.3 → 2.0.0-rc.4.0.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/local-driver
2
2
 
3
+ ## 2.0.0-rc.4.0.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.0.0-rc.3.0.0
4
8
 
5
9
  ### Major Changes
package/dist/legacy.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  export {
12
- // alpha APIs
12
+ // @alpha APIs
13
13
  LocalDocumentServiceFactory,
14
14
  LocalResolver,
15
15
  createLocalResolverCreateNewRequest
@@ -22,12 +22,13 @@ export declare class LocalDocumentStorageService implements IDocumentStorageServ
22
22
  getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null>;
23
23
  getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot>;
24
24
  /**
25
- * Strips the tree or any subtree of data if it has a groupId.
25
+ * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus
26
+ * any other loading groupId along with it.
26
27
  *
27
- * @param tree - The tree to strip of loading groupIds
28
+ * @param tree - The tree to evaluate for loading groupIds
28
29
  * @returns a tree that has trees with groupIds that are empty
29
30
  */
30
- private stripTreeOfMissingLoadingGroupIds;
31
+ private collectBlobContentsForUngroupedSnapshot;
31
32
  /**
32
33
  * Named differently as the algorithm is a little more involved.
33
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EACN,uBAAuB,EACvB,+BAA+B,EAC/B,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,eAAe,EACf,MAAM,6CAA6C,CAAC;AAErD,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,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AiBpE,WAAW,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC;IAiD1F;;;;;;OAMG;YACW,uCAAuC;IAsBrD;;;;;;;;;;;;OAYG;YACW,2BAA2B;YA0D3B,oBAAoB;YAoBpB,eAAe;IAS7B,OAAO,CAAC,SAAS;YAMH,WAAW;IAaZ,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAOlD,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IAkBL,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO/D,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;YAI7D,uBAAuB;CAWrC"}
@@ -61,21 +61,23 @@ class LocalDocumentStorageService {
61
61
  const rawTree = await this.manager.getTree(versionId);
62
62
  const snapshotTree = (0, protocol_base_1.buildGitTreeHierarchy)(rawTree, this.blobsShaCache, true);
63
63
  const groupIds = new Set(snapshotFetchOptions?.loadingGroupIds ?? []);
64
+ const attributesBlobId = snapshotTree.trees[".protocol"].blobs.attributes;
65
+ // Only populate contents for the blobs which are supposed to be returned.
66
+ const blobContents = new Map();
67
+ const attributesBlobData = await this.readBlob(attributesBlobId);
64
68
  if (groupIds.has("") || groupIds.size === 0) {
65
69
  // If the root is in the groupIds, we don't need to filter the tree.
66
- // We can just strip the tree of all groupIds.
67
- // If we want to include the root groupId,
68
- await this.stripTreeOfMissingLoadingGroupIds(snapshotTree, groupIds);
70
+ // We can just strip the of all groupIds as in collect the blobIds so that we can
71
+ // return blob contents only for those ids.
72
+ await this.collectBlobContentsForUngroupedSnapshot(snapshotTree, groupIds, blobContents);
69
73
  }
70
74
  else {
71
- const hasFoundTree = await this.filterTreeByLoadingGroupIds(snapshotTree, groupIds, false);
75
+ const hasFoundTree = await this.filterTreeByLoadingGroupIds(snapshotTree, groupIds, false, blobContents);
72
76
  (0, internal_1.assert)(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);
73
77
  }
74
- const blobContents = new Map();
75
- await this.populateBlobContents(snapshotTree, blobContents);
76
- const metadataString = client_utils_1.IsoBuffer.from(blobContents.get(".metadata")).toString("utf-8");
77
- const metadata = JSON.parse(metadataString);
78
- const sequenceNumber = metadata.message?.sequenceNumber ?? 0;
78
+ const attributesString = client_utils_1.IsoBuffer.from(attributesBlobData).toString("utf-8");
79
+ const attributes = JSON.parse(attributesString);
80
+ const sequenceNumber = attributes.sequenceNumber ?? 0;
79
81
  return {
80
82
  snapshotTree,
81
83
  blobContents,
@@ -86,21 +88,22 @@ class LocalDocumentStorageService {
86
88
  };
87
89
  }
88
90
  /**
89
- * Strips the tree or any subtree of data if it has a groupId.
91
+ * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus
92
+ * any other loading groupId along with it.
90
93
  *
91
- * @param tree - The tree to strip of loading groupIds
94
+ * @param tree - The tree to evaluate for loading groupIds
92
95
  * @returns a tree that has trees with groupIds that are empty
93
96
  */
94
- async stripTreeOfMissingLoadingGroupIds(tree, loadingGroupIds) {
97
+ async collectBlobContentsForUngroupedSnapshot(tree, loadingGroupIds, blobContents) {
95
98
  const groupId = await this.readGroupId(tree);
96
- if (groupId !== undefined && !loadingGroupIds.has(groupId)) {
97
- // strip
98
- this.stripTree(tree, groupId);
99
- return;
99
+ if (groupId === undefined || loadingGroupIds.has(groupId)) {
100
+ for (const id of Object.values(tree.blobs)) {
101
+ blobContents.set(id, await this.readBlob(id));
102
+ }
103
+ await Promise.all(Object.values(tree.trees).map(async (childTree) => {
104
+ await this.collectBlobContentsForUngroupedSnapshot(childTree, loadingGroupIds, blobContents);
105
+ }));
100
106
  }
101
- await Promise.all(Object.values(tree.trees).map(async (childTree) => {
102
- await this.stripTreeOfMissingLoadingGroupIds(childTree, loadingGroupIds);
103
- }));
104
107
  }
105
108
  /**
106
109
  * Named differently as the algorithm is a little more involved.
@@ -115,7 +118,7 @@ class LocalDocumentStorageService {
115
118
  * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds
116
119
  * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds
117
120
  */
118
- async filterTreeByLoadingGroupIds(tree, loadingGroupIds, ancestorGroupIdInLoadingGroup) {
121
+ async filterTreeByLoadingGroupIds(tree, loadingGroupIds, ancestorGroupIdInLoadingGroup, blobContents) {
119
122
  (0, internal_1.assert)(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);
120
123
  const groupId = await this.readGroupId(tree);
121
124
  // Strip the tree if it has a groupId and it is not in the loadingGroupIds
@@ -129,9 +132,15 @@ class LocalDocumentStorageService {
129
132
  const groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);
130
133
  // Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId
131
134
  const isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;
135
+ // Collect blobsIds so that we can return blob contents only for these blobs.
136
+ if (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {
137
+ for (const id of Object.values(tree.blobs)) {
138
+ blobContents.set(id, await this.readBlob(id));
139
+ }
140
+ }
132
141
  // Keep tree if it has a child that has a groupId that is in loadingGroupIds
133
142
  const descendants = await Promise.all(Object.values(tree.trees).map(async (childTree) => {
134
- return this.filterTreeByLoadingGroupIds(childTree, loadingGroupIds, ancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds);
143
+ return this.filterTreeByLoadingGroupIds(childTree, loadingGroupIds, ancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds, blobContents);
135
144
  }));
136
145
  const isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);
137
146
  // We don't want to return prematurely as we still may have children that we want to keep.
@@ -146,13 +155,15 @@ class LocalDocumentStorageService {
146
155
  return false;
147
156
  }
148
157
  // Takes all the blobs of a tree and puts it into the blobContents
149
- async populateBlobContents(tree, blobContents) {
158
+ async populateBlobContents(tree, blobContents, blobIdsToKeep) {
150
159
  await Promise.all(Object.entries(tree.blobs).map(async ([path, blobId]) => {
151
- const content = await this.readBlob(blobId);
152
- blobContents.set(path, content);
160
+ if (blobIdsToKeep.has(blobId)) {
161
+ const content = await this.readBlob(blobId);
162
+ blobContents.set(blobId, content);
163
+ }
153
164
  }));
154
165
  await Promise.all(Object.values(tree.trees).map(async (childTree) => {
155
- await this.populateBlobContents(childTree, blobContents);
166
+ await this.populateBlobContents(childTree, blobContents, blobIdsToKeep);
156
167
  }));
157
168
  }
158
169
  async populateGroupId(tree) {
@@ -165,7 +176,6 @@ class LocalDocumentStorageService {
165
176
  tree.blobs = {};
166
177
  tree.groupId = groupId;
167
178
  tree.trees = {};
168
- tree.omitted = true;
169
179
  }
170
180
  async readGroupId(tree) {
171
181
  const groupIdBlobId = tree.blobs[".groupId"];
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAKsC;AACtC,kEAA6D;AAS7D,iEAAsE;AAStE,mFAIgD;AAEhD,qEAA0D;AAE1D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,mBAAmB;AACzD;;GAEG;AACH,MAAa,2BAA2B;IAMvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC,EACxC,0BAAwD,EACxD,WAA0B;QAJ1B,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAiC;QACxC,+BAA0B,GAA1B,0BAA0B,CAA8B;QACxD,gBAAW,GAAX,WAAW,CAAe;QAV5C,uFAAuF;QACvF,2BAA2B;QACR,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QAU5D,IAAI,CAAC,wBAAwB,GAAG,IAAI,iDA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AAI,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO;aACjB,UAAU,CAAC,IAAA,iCAAkB,EAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;aAClE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD;AAhRD,kEAgRC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\tversionId = versions[0].treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the tree of all groupIds.\n\t\t\t// If we want to include the root groupId,\n\t\t\tawait this.stripTreeOfMissingLoadingGroupIds(snapshotTree, groupIds);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst blobContents = new Map<string, ArrayBufferLike>();\n\t\tawait this.populateBlobContents(snapshotTree, blobContents);\n\n\t\tconst metadataString = IsoBuffer.from(blobContents.get(\".metadata\")).toString(\"utf-8\");\n\t\tconst metadata = JSON.parse(metadataString);\n\t\tconst sequenceNumber: number = metadata.message?.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Strips the tree or any subtree of data if it has a groupId.\n\t *\n\t * @param tree - The tree to strip of loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async stripTreeOfMissingLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t) {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId !== undefined && !loadingGroupIds.has(groupId)) {\n\t\t\t// strip\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn;\n\t\t}\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.stripTreeOfMissingLoadingGroupIds(childTree, loadingGroupIds);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\tblobContents.set(path, content);\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined) {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t\ttree.omitted = true;\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\treturn version[0].id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n}\n"]}
1
+ {"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAKsC;AACtC,kEAA6D;AAS7D,iEAAsE;AAStE,mFAIgD;AAEhD,qEAA0D;AAE1D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,mBAAmB;AACzD;;GAEG;AACH,MAAa,2BAA2B;IAMvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC,EACxC,0BAAwD,EACxD,WAA0B;QAJ1B,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAiC;QACxC,+BAA0B,GAA1B,0BAA0B,CAA8B;QACxD,gBAAW,GAAX,WAAW,CAAe;QAV5C,uFAAuF;QACvF,2BAA2B;QACR,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QAU5D,IAAI,CAAC,wBAAwB,GAAG,IAAI,iDAAwB,CA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,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD;AAtSD,kEAsSC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\tversionId = versions[0].treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\tconst attributesBlobId = snapshotTree.trees[\".protocol\"].blobs.attributes;\n\t\t// Only populate contents for the blobs which are supposed to be returned.\n\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\tconst attributesBlobData = await this.readBlob(attributesBlobId);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the of all groupIds as in collect the blobIds so that we can\n\t\t\t// return blob contents only for those ids.\n\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst attributesString = IsoBuffer.from(attributesBlobData).toString(\"utf-8\");\n\t\tconst attributes = JSON.parse(attributesString);\n\t\tconst sequenceNumber: number = attributes.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus\n\t * any other loading groupId along with it.\n\t *\n\t * @param tree - The tree to evaluate for loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async collectBlobContentsForUngroupedSnapshot(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t) {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId === undefined || loadingGroupIds.has(groupId)) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t\tawait Promise.all(\n\t\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\t\t\tchildTree,\n\t\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\t\tblobContents,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Collect blobsIds so that we can return blob contents only for these blobs.\n\t\tif (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t}\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t\tblobContents,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t\tblobIdsToKeep: Set<string>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tif (blobIdsToKeep.has(blobId)) {\n\t\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\t\tblobContents.set(blobId, content);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents, blobIdsToKeep);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined) {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\treturn version[0].id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n}\n"]}
package/lib/legacy.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  export {
12
- // alpha APIs
12
+ // @alpha APIs
13
13
  LocalDocumentServiceFactory,
14
14
  LocalResolver,
15
15
  createLocalResolverCreateNewRequest
@@ -22,12 +22,13 @@ export declare class LocalDocumentStorageService implements IDocumentStorageServ
22
22
  getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null>;
23
23
  getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot>;
24
24
  /**
25
- * Strips the tree or any subtree of data if it has a groupId.
25
+ * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus
26
+ * any other loading groupId along with it.
26
27
  *
27
- * @param tree - The tree to strip of loading groupIds
28
+ * @param tree - The tree to evaluate for loading groupIds
28
29
  * @returns a tree that has trees with groupIds that are empty
29
30
  */
30
- private stripTreeOfMissingLoadingGroupIds;
31
+ private collectBlobContentsForUngroupedSnapshot;
31
32
  /**
32
33
  * Named differently as the algorithm is a little more involved.
33
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentStorageService.d.ts","sourceRoot":"","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ACxD,WAAW,CAAC,0BAAc;IAS/B,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUzE,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAiBpE,WAAW,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC;IAiD1F;;;;;;OAMG;YACW,uCAAuC;IAsBrD;;;;;;;;;;;;OAYG;YACW,2BAA2B;YA0D3B,oBAAoB;YAoBpB,eAAe;IAS7B,OAAO,CAAC,SAAS;YAMH,WAAW;IAaZ,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAOlD,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IAkBL,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO/D,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;YAI7D,uBAAuB;CAWrC"}
@@ -58,21 +58,23 @@ export class LocalDocumentStorageService {
58
58
  const rawTree = await this.manager.getTree(versionId);
59
59
  const snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);
60
60
  const groupIds = new Set(snapshotFetchOptions?.loadingGroupIds ?? []);
61
+ const attributesBlobId = snapshotTree.trees[".protocol"].blobs.attributes;
62
+ // Only populate contents for the blobs which are supposed to be returned.
63
+ const blobContents = new Map();
64
+ const attributesBlobData = await this.readBlob(attributesBlobId);
61
65
  if (groupIds.has("") || groupIds.size === 0) {
62
66
  // If the root is in the groupIds, we don't need to filter the tree.
63
- // We can just strip the tree of all groupIds.
64
- // If we want to include the root groupId,
65
- await this.stripTreeOfMissingLoadingGroupIds(snapshotTree, groupIds);
67
+ // We can just strip the of all groupIds as in collect the blobIds so that we can
68
+ // return blob contents only for those ids.
69
+ await this.collectBlobContentsForUngroupedSnapshot(snapshotTree, groupIds, blobContents);
66
70
  }
67
71
  else {
68
- const hasFoundTree = await this.filterTreeByLoadingGroupIds(snapshotTree, groupIds, false);
72
+ const hasFoundTree = await this.filterTreeByLoadingGroupIds(snapshotTree, groupIds, false, blobContents);
69
73
  assert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);
70
74
  }
71
- const blobContents = new Map();
72
- await this.populateBlobContents(snapshotTree, blobContents);
73
- const metadataString = IsoBuffer.from(blobContents.get(".metadata")).toString("utf-8");
74
- const metadata = JSON.parse(metadataString);
75
- const sequenceNumber = metadata.message?.sequenceNumber ?? 0;
75
+ const attributesString = IsoBuffer.from(attributesBlobData).toString("utf-8");
76
+ const attributes = JSON.parse(attributesString);
77
+ const sequenceNumber = attributes.sequenceNumber ?? 0;
76
78
  return {
77
79
  snapshotTree,
78
80
  blobContents,
@@ -83,21 +85,22 @@ export class LocalDocumentStorageService {
83
85
  };
84
86
  }
85
87
  /**
86
- * Strips the tree or any subtree of data if it has a groupId.
88
+ * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus
89
+ * any other loading groupId along with it.
87
90
  *
88
- * @param tree - The tree to strip of loading groupIds
91
+ * @param tree - The tree to evaluate for loading groupIds
89
92
  * @returns a tree that has trees with groupIds that are empty
90
93
  */
91
- async stripTreeOfMissingLoadingGroupIds(tree, loadingGroupIds) {
94
+ async collectBlobContentsForUngroupedSnapshot(tree, loadingGroupIds, blobContents) {
92
95
  const groupId = await this.readGroupId(tree);
93
- if (groupId !== undefined && !loadingGroupIds.has(groupId)) {
94
- // strip
95
- this.stripTree(tree, groupId);
96
- return;
96
+ if (groupId === undefined || loadingGroupIds.has(groupId)) {
97
+ for (const id of Object.values(tree.blobs)) {
98
+ blobContents.set(id, await this.readBlob(id));
99
+ }
100
+ await Promise.all(Object.values(tree.trees).map(async (childTree) => {
101
+ await this.collectBlobContentsForUngroupedSnapshot(childTree, loadingGroupIds, blobContents);
102
+ }));
97
103
  }
98
- await Promise.all(Object.values(tree.trees).map(async (childTree) => {
99
- await this.stripTreeOfMissingLoadingGroupIds(childTree, loadingGroupIds);
100
- }));
101
104
  }
102
105
  /**
103
106
  * Named differently as the algorithm is a little more involved.
@@ -112,7 +115,7 @@ export class LocalDocumentStorageService {
112
115
  * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds
113
116
  * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds
114
117
  */
115
- async filterTreeByLoadingGroupIds(tree, loadingGroupIds, ancestorGroupIdInLoadingGroup) {
118
+ async filterTreeByLoadingGroupIds(tree, loadingGroupIds, ancestorGroupIdInLoadingGroup, blobContents) {
116
119
  assert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);
117
120
  const groupId = await this.readGroupId(tree);
118
121
  // Strip the tree if it has a groupId and it is not in the loadingGroupIds
@@ -126,9 +129,15 @@ export class LocalDocumentStorageService {
126
129
  const groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);
127
130
  // Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId
128
131
  const isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;
132
+ // Collect blobsIds so that we can return blob contents only for these blobs.
133
+ if (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {
134
+ for (const id of Object.values(tree.blobs)) {
135
+ blobContents.set(id, await this.readBlob(id));
136
+ }
137
+ }
129
138
  // Keep tree if it has a child that has a groupId that is in loadingGroupIds
130
139
  const descendants = await Promise.all(Object.values(tree.trees).map(async (childTree) => {
131
- return this.filterTreeByLoadingGroupIds(childTree, loadingGroupIds, ancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds);
140
+ return this.filterTreeByLoadingGroupIds(childTree, loadingGroupIds, ancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds, blobContents);
132
141
  }));
133
142
  const isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);
134
143
  // We don't want to return prematurely as we still may have children that we want to keep.
@@ -143,13 +152,15 @@ export class LocalDocumentStorageService {
143
152
  return false;
144
153
  }
145
154
  // Takes all the blobs of a tree and puts it into the blobContents
146
- async populateBlobContents(tree, blobContents) {
155
+ async populateBlobContents(tree, blobContents, blobIdsToKeep) {
147
156
  await Promise.all(Object.entries(tree.blobs).map(async ([path, blobId]) => {
148
- const content = await this.readBlob(blobId);
149
- blobContents.set(path, content);
157
+ if (blobIdsToKeep.has(blobId)) {
158
+ const content = await this.readBlob(blobId);
159
+ blobContents.set(blobId, content);
160
+ }
150
161
  }));
151
162
  await Promise.all(Object.values(tree.trees).map(async (childTree) => {
152
- await this.populateBlobContents(childTree, blobContents);
163
+ await this.populateBlobContents(childTree, blobContents, blobIdsToKeep);
153
164
  }));
154
165
  }
155
166
  async populateGroupId(tree) {
@@ -162,7 +173,6 @@ export class LocalDocumentStorageService {
162
173
  tree.blobs = {};
163
174
  tree.groupId = groupId;
164
175
  tree.trees = {};
165
- tree.omitted = true;
166
176
  }
167
177
  async readGroupId(tree) {
168
178
  const groupIdBlobId = tree.blobs[".groupId"];
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAS7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAStE,OAAO,EAGN,wBAAwB,GACxB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,m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AO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACnD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,CACpD,OAAO,EACP,OAAO,CAAC,SAAS,IAAI,EAAE,EACvB,SAAS,CACT,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO;aACjB,UAAU,CAAC,kBAAkB,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;aAClE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\tversionId = versions[0].treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the tree of all groupIds.\n\t\t\t// If we want to include the root groupId,\n\t\t\tawait this.stripTreeOfMissingLoadingGroupIds(snapshotTree, groupIds);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst blobContents = new Map<string, ArrayBufferLike>();\n\t\tawait this.populateBlobContents(snapshotTree, blobContents);\n\n\t\tconst metadataString = IsoBuffer.from(blobContents.get(\".metadata\")).toString(\"utf-8\");\n\t\tconst metadata = JSON.parse(metadataString);\n\t\tconst sequenceNumber: number = metadata.message?.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Strips the tree or any subtree of data if it has a groupId.\n\t *\n\t * @param tree - The tree to strip of loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async stripTreeOfMissingLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t) {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId !== undefined && !loadingGroupIds.has(groupId)) {\n\t\t\t// strip\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn;\n\t\t}\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.stripTreeOfMissingLoadingGroupIds(childTree, loadingGroupIds);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\tblobContents.set(path, content);\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined) {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t\ttree.omitted = true;\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\treturn version[0].id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n}\n"]}
1
+ {"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAS7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAStE,OAAO,EAGN,wBAAwB,GAC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E,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\tversionId = versions[0].treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\tconst attributesBlobId = snapshotTree.trees[\".protocol\"].blobs.attributes;\n\t\t// Only populate contents for the blobs which are supposed to be returned.\n\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\tconst attributesBlobData = await this.readBlob(attributesBlobId);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the of all groupIds as in collect the blobIds so that we can\n\t\t\t// return blob contents only for those ids.\n\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst attributesString = IsoBuffer.from(attributesBlobData).toString(\"utf-8\");\n\t\tconst attributes = JSON.parse(attributesString);\n\t\tconst sequenceNumber: number = attributes.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus\n\t * any other loading groupId along with it.\n\t *\n\t * @param tree - The tree to evaluate for loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async collectBlobContentsForUngroupedSnapshot(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t) {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId === undefined || loadingGroupIds.has(groupId)) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t\tawait Promise.all(\n\t\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\t\t\tchildTree,\n\t\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\t\tblobContents,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Collect blobsIds so that we can return blob contents only for these blobs.\n\t\tif (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t}\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t\tblobContents,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t\tblobIdsToKeep: Set<string>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tif (blobIdsToKeep.has(blobId)) {\n\t\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\t\tblobContents.set(blobId, content);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents, blobIdsToKeep);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined) {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\treturn version[0].id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.42.3"
8
+ "packageVersion": "7.43.1"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/local-driver",
3
- "version": "2.0.0-rc.3.0.3",
3
+ "version": "2.0.0-rc.4.0.0",
4
4
  "description": "Fluid local driver",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -69,33 +69,33 @@
69
69
  "temp-directory": "nyc/.nyc_output"
70
70
  },
71
71
  "dependencies": {
72
- "@fluid-internal/client-utils": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
73
- "@fluidframework/core-interfaces": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
74
- "@fluidframework/core-utils": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
75
- "@fluidframework/driver-base": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
76
- "@fluidframework/driver-definitions": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
77
- "@fluidframework/driver-utils": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
72
+ "@fluid-internal/client-utils": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
73
+ "@fluidframework/core-interfaces": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
74
+ "@fluidframework/core-utils": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
75
+ "@fluidframework/driver-base": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
76
+ "@fluidframework/driver-definitions": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
77
+ "@fluidframework/driver-utils": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
78
78
  "@fluidframework/protocol-base": "^4.0.0",
79
79
  "@fluidframework/protocol-definitions": "^3.2.0",
80
- "@fluidframework/routerlicious-driver": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
80
+ "@fluidframework/routerlicious-driver": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
81
81
  "@fluidframework/server-local-server": "^4.0.0",
82
82
  "@fluidframework/server-services-client": "^4.0.0",
83
83
  "@fluidframework/server-services-core": "^4.0.0",
84
84
  "@fluidframework/server-test-utils": "^4.0.0",
85
- "@fluidframework/telemetry-utils": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
85
+ "@fluidframework/telemetry-utils": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
86
86
  "jsrsasign": "^11.0.0",
87
87
  "uuid": "^9.0.0"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@arethetypeswrong/cli": "^0.15.2",
91
91
  "@biomejs/biome": "^1.6.2",
92
- "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.3.0.3 <2.0.0-rc.3.1.0",
93
- "@fluid-tools/build-cli": "^0.37.0",
92
+ "@fluid-internal/mocha-test-setup": ">=2.0.0-rc.4.0.0 <2.0.0-rc.4.1.0",
93
+ "@fluid-tools/build-cli": "^0.38.0",
94
94
  "@fluidframework/build-common": "^2.0.3",
95
- "@fluidframework/build-tools": "^0.37.0",
95
+ "@fluidframework/build-tools": "^0.38.0",
96
96
  "@fluidframework/eslint-config-fluid": "^5.1.0",
97
- "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.0.0-internal.8.0.0",
98
- "@microsoft/api-extractor": "^7.42.3",
97
+ "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.0.0-rc.3.0.0",
98
+ "@microsoft/api-extractor": "^7.43.1",
99
99
  "@types/jsrsasign": "^10.5.12",
100
100
  "@types/mocha": "^9.1.1",
101
101
  "@types/node": "^18.19.0",
@@ -114,15 +114,7 @@
114
114
  "typescript": "~5.1.6"
115
115
  },
116
116
  "typeValidation": {
117
- "broken": {
118
- "ClassDeclaration_LocalDocumentService": {
119
- "forwardCompat": false
120
- },
121
- "ClassDeclaration_LocalDocumentStorageService": {
122
- "backCompat": false,
123
- "forwardCompat": false
124
- }
125
- }
117
+ "broken": {}
126
118
  },
127
119
  "scripts": {
128
120
  "api": "fluid-build . --task api",
@@ -154,7 +146,7 @@
154
146
  "test:mocha:esm": "mocha --recursive \"lib/test/**/*.spec.*js\" --exit",
155
147
  "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
156
148
  "tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
157
- "typetests:gen": "fluid-type-test-generator",
149
+ "typetests:gen": "flub generate typetests --dir . -v --publicFallback",
158
150
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
159
151
  }
160
152
  }
@@ -99,26 +99,32 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
99
99
  const rawTree = await this.manager.getTree(versionId);
100
100
  const snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);
101
101
  const groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);
102
+ const attributesBlobId = snapshotTree.trees[".protocol"].blobs.attributes;
103
+ // Only populate contents for the blobs which are supposed to be returned.
104
+ const blobContents = new Map<string, ArrayBuffer>();
105
+ const attributesBlobData = await this.readBlob(attributesBlobId);
102
106
  if (groupIds.has("") || groupIds.size === 0) {
103
107
  // If the root is in the groupIds, we don't need to filter the tree.
104
- // We can just strip the tree of all groupIds.
105
- // If we want to include the root groupId,
106
- await this.stripTreeOfMissingLoadingGroupIds(snapshotTree, groupIds);
108
+ // We can just strip the of all groupIds as in collect the blobIds so that we can
109
+ // return blob contents only for those ids.
110
+ await this.collectBlobContentsForUngroupedSnapshot(
111
+ snapshotTree,
112
+ groupIds,
113
+ blobContents,
114
+ );
107
115
  } else {
108
116
  const hasFoundTree = await this.filterTreeByLoadingGroupIds(
109
117
  snapshotTree,
110
118
  groupIds,
111
119
  false,
120
+ blobContents,
112
121
  );
113
122
  assert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);
114
123
  }
115
124
 
116
- const blobContents = new Map<string, ArrayBufferLike>();
117
- await this.populateBlobContents(snapshotTree, blobContents);
118
-
119
- const metadataString = IsoBuffer.from(blobContents.get(".metadata")).toString("utf-8");
120
- const metadata = JSON.parse(metadataString);
121
- const sequenceNumber: number = metadata.message?.sequenceNumber ?? 0;
125
+ const attributesString = IsoBuffer.from(attributesBlobData).toString("utf-8");
126
+ const attributes = JSON.parse(attributesString);
127
+ const sequenceNumber: number = attributes.sequenceNumber ?? 0;
122
128
  return {
123
129
  snapshotTree,
124
130
  blobContents,
@@ -130,26 +136,32 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
130
136
  }
131
137
 
132
138
  /**
133
- * Strips the tree or any subtree of data if it has a groupId.
139
+ * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus
140
+ * any other loading groupId along with it.
134
141
  *
135
- * @param tree - The tree to strip of loading groupIds
142
+ * @param tree - The tree to evaluate for loading groupIds
136
143
  * @returns a tree that has trees with groupIds that are empty
137
144
  */
138
- private async stripTreeOfMissingLoadingGroupIds(
145
+ private async collectBlobContentsForUngroupedSnapshot(
139
146
  tree: ISnapshotTreeEx,
140
147
  loadingGroupIds: Set<string>,
148
+ blobContents: Map<string, ArrayBuffer>,
141
149
  ) {
142
150
  const groupId = await this.readGroupId(tree);
143
- if (groupId !== undefined && !loadingGroupIds.has(groupId)) {
144
- // strip
145
- this.stripTree(tree, groupId);
146
- return;
151
+ if (groupId === undefined || loadingGroupIds.has(groupId)) {
152
+ for (const id of Object.values(tree.blobs)) {
153
+ blobContents.set(id, await this.readBlob(id));
154
+ }
155
+ await Promise.all(
156
+ Object.values(tree.trees).map(async (childTree) => {
157
+ await this.collectBlobContentsForUngroupedSnapshot(
158
+ childTree,
159
+ loadingGroupIds,
160
+ blobContents,
161
+ );
162
+ }),
163
+ );
147
164
  }
148
- await Promise.all(
149
- Object.values(tree.trees).map(async (childTree) => {
150
- await this.stripTreeOfMissingLoadingGroupIds(childTree, loadingGroupIds);
151
- }),
152
- );
153
165
  }
154
166
 
155
167
  /**
@@ -169,6 +181,7 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
169
181
  tree: ISnapshotTreeEx,
170
182
  loadingGroupIds: Set<string>,
171
183
  ancestorGroupIdInLoadingGroup: boolean,
184
+ blobContents: Map<string, ArrayBuffer>,
172
185
  ): Promise<boolean> {
173
186
  assert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);
174
187
  const groupId = await this.readGroupId(tree);
@@ -187,6 +200,12 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
187
200
  // Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId
188
201
  const isChildOfAncestorWithGroupId = ancestorGroupIdInLoadingGroup && groupId === undefined;
189
202
 
203
+ // Collect blobsIds so that we can return blob contents only for these blobs.
204
+ if (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {
205
+ for (const id of Object.values(tree.blobs)) {
206
+ blobContents.set(id, await this.readBlob(id));
207
+ }
208
+ }
190
209
  // Keep tree if it has a child that has a groupId that is in loadingGroupIds
191
210
  const descendants = await Promise.all<boolean>(
192
211
  Object.values(tree.trees).map(async (childTree) => {
@@ -194,6 +213,7 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
194
213
  childTree,
195
214
  loadingGroupIds,
196
215
  ancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,
216
+ blobContents,
197
217
  );
198
218
  }),
199
219
  );
@@ -218,16 +238,19 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
218
238
  private async populateBlobContents(
219
239
  tree: ISnapshotTreeEx,
220
240
  blobContents: Map<string, ArrayBufferLike>,
241
+ blobIdsToKeep: Set<string>,
221
242
  ): Promise<void> {
222
243
  await Promise.all(
223
244
  Object.entries(tree.blobs).map(async ([path, blobId]) => {
224
- const content = await this.readBlob(blobId);
225
- blobContents.set(path, content);
245
+ if (blobIdsToKeep.has(blobId)) {
246
+ const content = await this.readBlob(blobId);
247
+ blobContents.set(blobId, content);
248
+ }
226
249
  }),
227
250
  );
228
251
  await Promise.all(
229
252
  Object.values(tree.trees).map(async (childTree) => {
230
- await this.populateBlobContents(childTree, blobContents);
253
+ await this.populateBlobContents(childTree, blobContents, blobIdsToKeep);
231
254
  }),
232
255
  );
233
256
  }
@@ -245,7 +268,6 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
245
268
  tree.blobs = {};
246
269
  tree.groupId = groupId;
247
270
  tree.trees = {};
248
- tree.omitted = true;
249
271
  }
250
272
 
251
273
  private async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {