From 34d298259bd52f4d7912858246399b8f5175d873 Mon Sep 17 00:00:00 2001 From: Rishhi Balakrishnan <107130183+RishhiB@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:20:46 -0500 Subject: [PATCH] eslint(container-loader): Prefix container-loader before enabling no-unchecked-record-access (#23423) Prefix container-loader before enabling no-unchecked-record-access [AB#26471](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/26471) --- .../src/containerStorageAdapter.ts | 6 +++--- .../src/test/serializedStateManager.spec.ts | 5 +++-- .../src/test/snapshotConversionTest.spec.ts | 20 ++++++++++--------- packages/loader/container-loader/src/utils.ts | 5 +---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/loader/container-loader/src/containerStorageAdapter.ts b/packages/loader/container-loader/src/containerStorageAdapter.ts index 5ba5788368c8..1033395d7f93 100644 --- a/packages/loader/container-loader/src/containerStorageAdapter.ts +++ b/packages/loader/container-loader/src/containerStorageAdapter.ts @@ -214,7 +214,7 @@ export class ContainerStorageAdapter } public async readBlob(id: string): Promise { - const maybeBlob = this.blobContents[id]; + const maybeBlob: string | ArrayBufferLike | undefined = this.blobContents[id]; if (maybeBlob !== undefined) { if (typeof maybeBlob === "string") { const blob = stringToBuffer(maybeBlob, "utf8"); @@ -361,7 +361,7 @@ async function getBlobManagerTreeFromTree( blobs: ISerializableBlobContents, storage: Pick, ): Promise { - const id = tree.blobs[redirectTableBlobName]; + const id: string | undefined = tree.blobs[redirectTableBlobName]; assert(id !== undefined, 0x9ce /* id is undefined in getBlobManagerTreeFromTree */); const blob = await storage.readBlob(id); // ArrayBufferLike will not survive JSON.stringify() @@ -404,7 +404,7 @@ function getBlobManagerTreeFromTreeWithBlobContents( tree: ISnapshotTreeWithBlobContents, blobs: ISerializableBlobContents, ): void { - const id = tree.blobs[redirectTableBlobName]; + const id: string | undefined = tree.blobs[redirectTableBlobName]; assert( id !== undefined, 0x9cf /* id is undefined in getBlobManagerTreeFromTreeWithBlobContents */, diff --git a/packages/loader/container-loader/src/test/serializedStateManager.spec.ts b/packages/loader/container-loader/src/test/serializedStateManager.spec.ts index 9eaa273f2c24..3df5c02aac10 100644 --- a/packages/loader/container-loader/src/test/serializedStateManager.spec.ts +++ b/packages/loader/container-loader/src/test/serializedStateManager.spec.ts @@ -154,8 +154,9 @@ const getAttributesFromPendingState = ( if (pendingState.baseSnapshot === undefined) { throw new Error("base snapshot should be valid"); } - const attributesId = pendingState.baseSnapshot.trees[".protocol"].blobs.attributes; - const attributes = pendingState.snapshotBlobs[attributesId]; + const attributesId: string | undefined = + pendingState.baseSnapshot.trees[".protocol"]?.blobs.attributes; + const attributes: string | undefined = pendingState.snapshotBlobs[attributesId]; return JSON.parse(attributes) as IDocumentAttributes; }; diff --git a/packages/loader/container-loader/src/test/snapshotConversionTest.spec.ts b/packages/loader/container-loader/src/test/snapshotConversionTest.spec.ts index 858d4b0e2359..b3ca7e4ab395 100644 --- a/packages/loader/container-loader/src/test/snapshotConversionTest.spec.ts +++ b/packages/loader/container-loader/src/test/snapshotConversionTest.spec.ts @@ -67,14 +67,15 @@ describe("Dehydrate Container", () => { assert.strictEqual(Object.keys(baseSnapshot.trees).length, 2, "2 trees should be there"); assert.strictEqual( - Object.keys(baseSnapshot.trees[".protocol"].blobs).length, + Object.keys(baseSnapshot.trees[".protocol"]?.blobs).length, 2, "2 protocol blobs should be there.", ); // Validate the ".component" blob. - const defaultDataStoreBlobId = baseSnapshot.trees.default.blobs[".component"]; - const defaultDataStoreBlob = snapshotBlobs[defaultDataStoreBlobId]; + const defaultDataStoreBlobId: string | undefined = + baseSnapshot.trees.default?.blobs[".component"]; + const defaultDataStoreBlob: string | undefined = snapshotBlobs[defaultDataStoreBlobId]; assert.strict(defaultDataStoreBlob, "defaultDataStoreBlob undefined"); assert.strictEqual( JSON.parse(defaultDataStoreBlob), @@ -83,8 +84,9 @@ describe("Dehydrate Container", () => { ); // Validate "root" sub-tree. - const rootAttributesBlobId = baseSnapshot.trees.default.trees.root.blobs.attributes; - const rootAttributesBlob = snapshotBlobs[rootAttributesBlobId]; + const rootAttributesBlobId: string | undefined = + baseSnapshot.trees.default.trees.root?.blobs.attributes; + const rootAttributesBlob: string | undefined = snapshotBlobs[rootAttributesBlobId]; assert.strict(rootAttributesBlob, "rootAttributesBlob undefined"); assert.strictEqual( JSON.parse(rootAttributesBlob), @@ -92,28 +94,28 @@ describe("Dehydrate Container", () => { "The root sub-tree's content is incorrect", ); assert.strictEqual( - baseSnapshot.trees.default.trees.root.unreferenced, + baseSnapshot.trees.default?.trees.root?.unreferenced, undefined, "The root sub-tree should not be marked as unreferenced", ); // Validate "unref" sub-tree. assert.strictEqual( - baseSnapshot.trees.default.trees.unref.unreferenced, + baseSnapshot.trees.default?.trees.unref?.unreferenced, true, "The unref sub-tree should be marked as unreferenced", ); // Validate "groupId" sub-tree. assert.strictEqual( - baseSnapshot.trees.default.trees.groupId.groupId, + baseSnapshot.trees.default?.trees.groupId?.groupId, "group", "The groupId sub-tree should have a groupId", ); // Validate "groupId" sub-tree. assert.strictEqual( - baseSnapshot.trees.default.trees.groupId.groupId, + baseSnapshot.trees.default?.trees.groupId?.groupId, "group", "The groupId sub-tree should have a groupId", ); diff --git a/packages/loader/container-loader/src/utils.ts b/packages/loader/container-loader/src/utils.ts index 761673b56e0d..d2718706dad8 100644 --- a/packages/loader/container-loader/src/utils.ts +++ b/packages/loader/container-loader/src/utils.ts @@ -145,10 +145,7 @@ function convertSummaryToSnapshotAndBlobs(summary: ISummaryTree): SnapshotWithBl unreferenced: summary.unreferenced, groupId: summary.groupId, }; - const keys = Object.keys(summary.tree); - for (const key of keys) { - const summaryObject = summary.tree[key]; - + for (const [key, summaryObject] of Object.entries(summary.tree)) { switch (summaryObject.type) { case SummaryType.Tree: { const innerSnapshot = convertSummaryToSnapshotAndBlobs(summaryObject);