Skip to content

Commit

Permalink
feat: [#4503] azure-storage deprecation (#4510)
Browse files Browse the repository at this point in the history
* Migrate botbuilder-azure to azure/storage-blob

* Fix paged results in blobsTranscriptStore

* Update unit tests

* Fix lint issue
  • Loading branch information
ceciliaavila committed Jul 28, 2023
1 parent faf57c5 commit 51016a6
Show file tree
Hide file tree
Showing 18 changed files with 2,641 additions and 3,210 deletions.
52 changes: 33 additions & 19 deletions libraries/botbuilder-azure-blobs/src/blobsTranscriptStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ export class BlobsTranscriptStore implements TranscriptStore {
.byPage({ continuationToken, maxPageSize: MAX_PAGE_SIZE });

let page = await iter.next();
const result: Activity[] = [];
let response: ContainerListBlobHierarchySegmentResponse | undefined;
while (!page.done) {
// Note: azure library does not properly type iterator result, hence the need to cast
const response = maybeCast<ContainerListBlobHierarchySegmentResponse>(page?.value ?? {});
response = maybeCast<ContainerListBlobHierarchySegmentResponse>(page?.value ?? {});
const blobItems = response?.segment?.blobItems ?? [];

// Locate first index of results to slice from. If we have a start date, we want to return
Expand Down Expand Up @@ -174,19 +176,18 @@ export class BlobsTranscriptStore implements TranscriptStore {
{ concurrency: this._concurrency }
);

return {
continuationToken: response?.continuationToken ?? '',
items: activities.reduce<Activity[]>(
(acc, activity) => (activity ? acc.concat(activity) : acc),
[]
),
};
activities.forEach((activity) => {
if (activity) result.push(activity);
});
}

page = await iter.next();
}

return { continuationToken: '', items: [] };
return {
continuationToken: response?.continuationToken ?? '',
items: result.reduce<Activity[]>((acc, activity) => (activity ? acc.concat(activity) : acc), []),
};
}

/**
Expand All @@ -202,26 +203,39 @@ export class BlobsTranscriptStore implements TranscriptStore {

await this._initialize();

const page = await this._containerClient
const iter = this._containerClient
.listBlobsByHierarchy('/', {
prefix: getChannelPrefix(channelId),
})
.byPage({ continuationToken, maxPageSize: MAX_PAGE_SIZE })
.next();
.byPage({ continuationToken, maxPageSize: MAX_PAGE_SIZE });

// Note: azure library does not properly type iterator result, hence the need to cast
const response = maybeCast<ContainerListBlobHierarchySegmentResponse>(page?.value ?? {});
const blobItems = response?.segment?.blobItems ?? [];
let page = await iter.next();
const result: any[] = [];
let response: ContainerListBlobHierarchySegmentResponse | undefined;

return {
continuationToken: response?.continuationToken ?? '',
items: blobItems.map((blobItem) => {
while (!page.done) {
// Note: azure library does not properly type iterator result, hence the need to cast
const response = maybeCast<ContainerListBlobHierarchySegmentResponse>(page?.value ?? {});
const blobItems = response?.segment?.blobItems ?? [];

const items = blobItems.map((blobItem) => {
const [, id] = decodeURIComponent(blobItem.name).split('/');

const created = blobItem.metadata?.timestamp ? new Date(blobItem.metadata.timestamp) : new Date();

return { channelId, created, id };
}),
});

items.forEach((transcript) => {
if (transcript) result.push(transcript);
});

page = await iter.next();
}

return {
continuationToken: response?.continuationToken ?? '',
items: result ?? [],
};
}

Expand Down
9 changes: 6 additions & 3 deletions libraries/botbuilder-azure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
},
"dependencies": {
"@azure/cosmos": "3.10.0",
"@azure/core-auth": "^1.1.3",
"azure-storage": "2.10.7",
"@azure/core-auth": "^1.4.0",
"@azure/storage-blob": "^12.15.0",
"botbuilder": "4.1.6",
"lodash": "^4.17.20",
"botbuilder-stdlib": "4.1.6",
"get-stream": "^6.0.0",
"bcrypt": "^5.0.1",
"lodash": "^4.17.20",
"p-map": "^4.0.0",
"@types/bcrypt": "^5.0.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 51016a6

Please sign in to comment.