Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http)!: enhance blob handling in HttpClient #2181

Merged
merged 3 commits into from
May 27, 2024

Conversation

odinr
Copy link
Collaborator

@odinr odinr commented May 23, 2024

Why

This pull request introduces a major update to the blob and blob$ methods in the HttpClient class of the @equinor/fusion-framework-module-http package.

Current Behavior

The existing blob and blob$ methods in the HttpClient class return a Blob or a StreamResponse<Blob> respectively, without providing any information about the filename of the fetched blob.

New Behavior

The updated blob and blob$ methods now accept an optional args parameter of type FetchRequestInit<T, TRequest, TResponse>, where T is the type of the expected blob result. This allows consumers to customize the fetch request and response handling.

Additionally, the blob and blob$ methods now return a Promise<T> and StreamResponse<T> respectively, where T is the type of the expected blob result. This allows consumers to handle the blob data in a more type-safe manner.

The blobSelector function has also been updated to extract the filename (if available) from the content-disposition header and return it along with the blob data in a BlobResult object.

Breaking Change

This update alters the return type of the blob and blob$ methods, which is a breaking change. If you were previously using these methods and expecting a Blob result, you must now use the new BlobResult type, which includes the filename (if available) and the blob data.

Example Usage

const blobResult = await httpClient.blob('/path/to/blob');
console.log(blobResult.filename); // 'example.pdf'
console.log(blobResult.blob); // Blob instance

const blobStream = httpClient.blob$('/path/to/blob');
blobStream.subscribe((blobResult) => {
    console.log(blobResult.filename); // 'example.pdf'
    console.log(blobResult.blob); // Blob instance
});

Check off the following:

  • Confirm that I checked changes to branch which I am merging into.
    • I have validated included files
    • My code does not generate new linting warnings
    • My PR is not a duplicate, check existing pr`s
  • Confirm that the I have completed the self-review checklist.
  • Confirm that my changes meet our code of conduct.

Copy link

changeset-bot bot commented May 23, 2024

🦋 Changeset detected

Latest commit: e3af32b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@equinor/fusion-framework-react-components-people-provider Minor
@equinor/fusion-framework-module-services Minor
@equinor/fusion-framework-app Minor
@equinor/fusion-framework Minor
@equinor/fusion-framework-react-app Minor
@equinor/fusion-framework-react Minor
@equinor/fusion-framework-module-http Major
@equinor/fusion-framework-cli Patch
@equinor/fusion-framework-legacy-interopt Major
@equinor/fusion-framework-react-widget Patch
@equinor/fusion-framework-widget Patch
@equinor/fusion-framework-cookbook-app-react-context-custom-error Patch
@equinor/fusion-framework-cookbook-app-react-context Patch
@equinor/fusion-framework-cookbook-app-react-feature-flag Patch
@equinor/fusion-framework-react-components-bookmark Patch
@equinor/fusion-framework-react-module-bookmark Patch
@equinor/fusion-framework-module-service-discovery Patch
@equinor/fusion-framework-module-widget Major
@equinor/fusion-framework-react-module-http Major
@equinor/fusion-framework-react-module-context Patch
@equinor/fusion-framework-module-signalr Patch
@equinor/fusion-framework-react-module-signalr Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added 🚀 feature New feature or request 🧨 breaking changes 🧬 Modules 📚 documentation Improvements or additions to documentation labels May 23, 2024
@odinr odinr force-pushed the feat/http/improve-blob-requests branch from 5fad73b to 65704c5 Compare May 24, 2024 09:33
@odinr odinr marked this pull request as ready for review May 24, 2024 09:33
@odinr odinr requested a review from a team as a code owner May 24, 2024 09:33
Copy link
Contributor

github-actions bot commented May 24, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 13.07% 3795 / 29024
🔵 Statements 13.07% 3795 / 29024
🔵 Functions 13.04% 95 / 728
🔵 Branches 28.4% 238 / 838
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/modules/http/src/lib/client/client.ts 48.24% 100% 11.76% 48.24% 52-53, 70-74, 77-81, 85-89, 92-106, 109-113, 123-137, 147-151, 155-159, 162-167, 170-171, 174-214, 217-218, 221-222, 225-227
packages/modules/http/src/lib/client/types.ts 100% 100% 100% 100%
packages/modules/http/src/lib/selectors/blob-selector.ts 29.26% 100% 0% 29.26% 11-39
packages/modules/services/src/people/client.ts 0% 0% 0% 0% 1-109
packages/modules/services/src/people/person-photo/client.ts 0% 0% 0% 0% 1-37
packages/react/components/people-resolver/src/PersonController.ts 0% 0% 0% 0% 1-254
Generated in workflow #6503

@odinr odinr self-assigned this May 24, 2024
@odinr odinr force-pushed the feat/http/improve-blob-requests branch from 276da48 to fc51e93 Compare May 27, 2024 10:07
odinr added 3 commits May 27, 2024 12:39
- Update `blob` and `blob$` methods to accept `FetchRequestInit<T>` args
- Return `Promise<BlobResult>` and `StreamResponse<BlobResult>` from `blob` and `blob$` methods
- `BlobResult` includes filename (if available) and blob data
- Update `blobSelector` to extract filename from 'content-disposition' header
- Add JSDoc comments for improved documentation

The `blob` and `blob$` methods now provide a more robust and flexible API for fetching blob resources. This change introduces a breaking change in the return types of these methods.

BREAKING CHANGE: The `blob` and `blob$` methods now return `Promise<BlobResult>` and `StreamResponse<BlobResult>` instead of `Promise<Blob>` and `StreamResponse<Blob>`. The `BlobResult` type includes the filename (if available) and the blob data.
Update PeopleApiClient.photo method to return PersonPhotoApiResponse instead of Blob since the IHttpClient interface has changed

Adjust related types and methods to handle the updated return type
Modify PersonController to map the API response to Blob and handle errors appropriately
@odinr odinr force-pushed the feat/http/improve-blob-requests branch from fc51e93 to e3af32b Compare May 27, 2024 10:39
@odinr odinr merged commit ba2379b into main May 27, 2024
7 of 8 checks passed
@odinr odinr deleted the feat/http/improve-blob-requests branch May 27, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧨 breaking changes 📚 documentation Improvements or additions to documentation 🚀 feature New feature or request 🧬 Modules 👾 React
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants