forked from googleapis/google-cloud-node
-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add gaxios and node 18 migration guide #15
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
Open
thiyaguk09
wants to merge
31
commits into
storage-node-18
Choose a base branch
from
docs/gaxios-migration-guide
base: storage-node-18
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a2cd00b
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 72c17d7
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 3b2a681
docs: add gaxios and node 18 migration guide
thiyaguk09 ea376ce
docs: add examples for passing options headers and URL resolution
thiyaguk09 8eb2d72
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 eacb087
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 49a2b5a
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 b1a228c
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 683b3f4
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 0c58a9a
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 51c3e81
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 b5c81a1
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 fe44861
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 197b249
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 7c3ee50
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 0a4f5ac
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 86f0fb7
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 ef7c4d4
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 e3288e3
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 dafce2e
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 3dd33a5
test: add bytes method to mock responses in acl and headers tests
thiyaguk09 eb547c4
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 1fba172
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 5ad4fef
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 fafab27
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 d4b912f
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 4f6f722
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 c5be999
fix(storage): standardize URL formatting and enhance transport retry
thiyaguk09 c0a6220
refactor(storage): remove Service.ts and migrate logic to StorageTran…
thiyaguk09 0a2ebe9
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 64b606d
Merge remote-tracking branch 'upstream/storage-node-18' into docs/gax…
thiyaguk09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Storage v7 to v8 Migration Guide - Node.js 18 & Gaxios Update | ||
|
|
||
| This guide helps you migrate your application from `@google-cloud/storage` v7 to v8, focusing on the transition to Node.js 18+ as the minimum supported environment and changes introduced by updating the underlying HTTP client, `gaxios`, to version 7. | ||
|
|
||
| ## Minimum Requirements: Node.js 18 | ||
|
|
||
| `@google-cloud/storage` v8 now officially requires Node.js 18 or higher. This update aligns the library with modern JavaScript environments. | ||
|
|
||
| Specifically, Node.js 18 introduced native global Web APIs (such as `fetch` and `Headers`). Conforming to this standard, the underlying HTTP client, `gaxios` (updated to v7), leverages native `Headers` rather than custom user-land header representations. As a result, `@google-cloud/storage` v8 has transitioned response and request headers to standard native global `Headers` objects. | ||
|
|
||
|
|
||
| ## Key Breaking Changes for Storage Users | ||
|
|
||
| ### 1. Response Headers are now `Headers` objects | ||
|
|
||
| When you receive a full API response from Storage methods (e.g., via callbacks or promise resolutions that include the response object), the `headers` property of the response is now a standard native `Headers` object (aligned with the Fetch API standard in Node.js 18) rather than a plain JavaScript object. | ||
|
|
||
| **Before (Storage v7):** | ||
|
|
||
| ```js | ||
| const [retrievedFile, apiResponse] = await file.get(); | ||
| const contentType = apiResponse.headers['content-type']; | ||
| ``` | ||
|
|
||
| **After (Storage v8):** | ||
|
|
||
| ```js | ||
| const [retrievedFile, apiResponse] = await file.get(); | ||
| // Accessing headers requires the .get() method | ||
| const contentType = apiResponse.headers.get('content-type'); | ||
| ``` | ||
|
|
||
| ### 2. Passing Headers in Options | ||
|
|
||
| If you pass custom headers in options to Storage methods (which extend `GaxiosOptions`), you can still pass plain objects, as the Storage library will convert them to standard `Headers` internally for the request. However, if you read them back from the prepared options or response, they will be `Headers` objects. | ||
|
|
||
| **Before (Storage v7):** | ||
|
|
||
| ```js | ||
| // Reading request headers back from response metadata returned a plain object | ||
| const customHeader = apiResponse.config.headers['x-custom-header']; | ||
| ``` | ||
|
|
||
| **After (Storage v8):** | ||
|
|
||
| ```js | ||
| // Reading request headers back from response metadata requires .get() | ||
| const customHeader = apiResponse.config.headers.get('x-custom-header'); | ||
| ``` | ||
|
|
||
| > [!WARNING] | ||
| > **Header Value Stringification:** Plain JavaScript objects allow passing non-string values (such as arrays or numbers) which are implicitly processed. However, the native `Headers` constructor strictly converts all values to standard string representations. For example, passing an array of values (e.g., `['val1', 'val2']`) will result in a single comma-separated string (e.g., `'val1, val2'`). Ensure you pre-format or verify your header values before passing them to custom options. | ||
|
|
||
|
|
||
| ### 3. URL Resolution (`baseURL`) | ||
|
|
||
| If you are using custom `baseURL` options or passing relative URLs to methods that accept them, be aware that resolution now strictly follows the standard native `URL` constructor spec (`new URL(url, baseURL)`). This can affect how leading slashes in paths resolve. | ||
|
|
||
| **Before (Storage v7):** | ||
|
|
||
| Using standard path-joining custom resolution: | ||
| - `baseURL`: `https://storage.googleapis.com/storage/v1` | ||
| - `url`: `/b/my-bucket` | ||
| - Resolved URL: `https://storage.googleapis.com/storage/v1/b/my-bucket` | ||
|
|
||
| **After (Storage v8):** | ||
|
|
||
| Strictly resolved via the standard native `URL` constructor rules (where a leading slash resolves relative to the root of the host): | ||
| - `baseURL`: `https://storage.googleapis.com/storage/v1` | ||
| - `url`: `/b/my-bucket` | ||
| - Resolved URL: `https://storage.googleapis.com/b/my-bucket` (resolves relative to host root, stripping `storage/v1`) | ||
|
|
||
|
|
||
| ## Upgrade Instructions | ||
|
|
||
| Update your `@google-cloud/storage` dependency to version 8: | ||
|
|
||
| ```sh | ||
| npm install @google-cloud/storage@latest | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - If you encounter `undefined` when accessing headers on the response object, ensure you are using `apiResponse.headers.get('header-name')`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gaxios is indirect dependency?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it's direct dependency. |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add examples for 2 and 3 as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added