Skip to content

Commit 63871ca

Browse files
authored
chore!: migrate to Node 18 (#2592)
* chore: Migrate to node 18 * fix: lint errors * fix: unit tests * fix: interceptor error * fix: ESM compatible issue Resolve the ES module compatibility issue for the mime and p-limit modules. * fix: json parse issue * Downgrade some dependencies * fix: failed unit test cases * lint fix * bug fix * lint fix * addressing review comments * addressing comments * fix request url issue and typo corrections * downgrade sinon & bug fix * fix: spell check * bug fix * fix: 429 error * Revert "fix: 429 error" This reverts commit 96b64e554efd830a1c991e4dda97b199dc950875. * fix: delete object cb issue * bug fix * Downgrade some dependencies * bug fix * update dependency jsdoc-fresh to v4
1 parent 2a1d14a commit 63871ca

33 files changed

Lines changed: 878 additions & 581 deletions

handwritten/storage/.github/.OwlBot.lock.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Google LLC
1+
# Copyright 2025 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,5 +13,4 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest
16-
digest: sha256:609822e3c09b7a1bd90b99655904609f162cc15acb4704f1edf778284c36f429
17-
# created: 2024-10-01T19:34:30.797530443Z
16+
digest: sha256:ebf1487fdb5be0d02d49a20b01547be3cd15cbd03f4ded7b47c65eae7920a080

handwritten/storage/conformance-test/conformanceCommon.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
Bucket,
2020
File,
2121
GaxiosOptions,
22+
GaxiosOptionsPrepared,
2223
HmacKey,
2324
Notification,
2425
Storage,
@@ -159,12 +160,15 @@ export function executeScenario(testCase: RetryTestCase) {
159160
);
160161

161162
storage.interceptors.push({
162-
resolved: requestConfig => {
163-
requestConfig.headers = requestConfig.headers || {};
164-
Object.assign(requestConfig.headers, {
163+
resolved: (
164+
requestConfig: GaxiosOptionsPrepared,
165+
): Promise<GaxiosOptionsPrepared> => {
166+
const config = requestConfig as GaxiosOptions;
167+
config.headers = config.headers || {};
168+
Object.assign(config.headers, {
165169
'x-retry-test-id': creationResult.id,
166170
});
167-
return Promise.resolve(requestConfig as GaxiosOptions);
171+
return Promise.resolve(config as GaxiosOptionsPrepared);
168172
},
169173
rejected: error => {
170174
return Promise.reject(error);

handwritten/storage/package.json

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,54 +72,54 @@
7272
"test": "c8 mocha build/cjs/test"
7373
},
7474
"dependencies": {
75-
"@google-cloud/paginator": "^5.0.0",
76-
"@google-cloud/promisify": "^4.0.0",
75+
"@google-cloud/paginator": "^6.0.0",
76+
"@google-cloud/promisify": "^5.0.0",
7777
"abort-controller": "^3.0.0",
7878
"async-retry": "^1.3.3",
7979
"duplexify": "^4.1.3",
80-
"fast-xml-parser": "^4.4.1",
81-
"gaxios": "^6.0.2",
82-
"google-auth-library": "^9.14.2",
83-
"html-entities": "^2.5.2",
84-
"mime": "^3.0.0",
85-
"p-limit": "^3.0.1",
86-
"uuid": "^8.0.0"
80+
"fast-xml-parser": "^5.2.0",
81+
"gaxios": "^7.0.0-rc.4",
82+
"google-auth-library": "^10.0.0-rc.2",
83+
"html-entities": "^2.6.0",
84+
"mime": "3.0.0",
85+
"p-limit": "3.1.0",
86+
"uuid": "^11.1.0"
8787
},
8888
"devDependencies": {
89-
"@babel/cli": "^7.22.10",
90-
"@babel/core": "^7.22.11",
91-
"@google-cloud/pubsub": "^4.0.0",
92-
"@grpc/grpc-js": "^1.0.3",
93-
"@grpc/proto-loader": "^0.7.0",
94-
"@types/async-retry": "^1.4.3",
89+
"@babel/cli": "^7.27.0",
90+
"@babel/core": "^7.26.10",
91+
"@google-cloud/pubsub": "^4.11.0",
92+
"@grpc/grpc-js": "^1.13.2",
93+
"@grpc/proto-loader": "^0.7.13",
94+
"@types/async-retry": "^1.4.9",
9595
"@types/duplexify": "^3.6.4",
96-
"@types/mime": "^3.0.0",
97-
"@types/mocha": "^9.1.1",
98-
"@types/mockery": "^1.4.29",
99-
"@types/node": "^22.0.0",
100-
"@types/node-fetch": "^2.1.3",
101-
"@types/proxyquire": "^1.3.28",
102-
"@types/sinon": "^17.0.3",
103-
"@types/tmp": "0.2.6",
104-
"@types/uuid": "^8.0.0",
105-
"@types/yargs": "^17.0.10",
106-
"c8": "^9.0.0",
107-
"form-data": "^4.0.0",
108-
"gapic-tools": "^0.4.6",
96+
"@types/mime": "3.0.0",
97+
"@types/mocha": "^10.0.10",
98+
"@types/mockery": "^1.4.33",
99+
"@types/node": "^22.14.0",
100+
"@types/node-fetch": "^2.6.12",
101+
"@types/proxyquire": "^1.3.31",
102+
"@types/sinon": "^17.0.4",
103+
"@types/tmp": "^0.2.6",
104+
"@types/uuid": "^10.0.0",
105+
"@types/yargs": "^17.0.33",
106+
"c8": "^10.1.3",
107+
"form-data": "^4.0.2",
108+
"gapic-tools": "^1.0.1",
109109
"gts": "^6.0.2",
110-
"jsdoc": "^4.0.0",
111-
"jsdoc-fresh": "^3.0.0",
110+
"jsdoc": "^4.0.4",
111+
"jsdoc-fresh": "^4.0.0",
112112
"jsdoc-region-tag": "^3.0.0",
113113
"linkinator": "^6.1.2",
114-
"mocha": "^9.2.2",
114+
"mocha": "^11.1.0",
115115
"mockery": "^2.1.0",
116-
"nock": "~13.5.0",
117-
"node-fetch": "^2.6.7",
118-
"pack-n-play": "^2.0.0",
116+
"nock": "^14.0.3",
117+
"node-fetch": "^3.3.2",
118+
"pack-n-play": "^3.0.1",
119119
"proxyquire": "^2.1.3",
120120
"sinon": "^18.0.0",
121-
"tmp": "^0.2.0",
122-
"typescript": "^5.7.2",
123-
"yargs": "^17.3.1"
121+
"tmp": "^0.2.3",
122+
"typescript": "^5.8.3",
123+
"yargs": "^17.7.2"
124124
}
125-
}
125+
}

handwritten/storage/samples/moveFileAtomic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function main(
2424
bucketName = 'my-bucket',
2525
srcFileName = 'test.txt',
2626
destFileName = 'test2.txt',
27-
destinationGenerationMatchPrecondition = 0
27+
destinationGenerationMatchPrecondition = 0,
2828
) {
2929
// [START storage_move_object]
3030
/**
@@ -66,7 +66,7 @@ function main(
6666
.moveFileAtomic(destFileName, moveOptions);
6767

6868
console.log(
69-
`gs://${bucketName}/${srcFileName} moved to gs://${bucketName}/${destFileName}`
69+
`gs://${bucketName}/${srcFileName} moved to gs://${bucketName}/${destFileName}`,
7070
);
7171
}
7272

handwritten/storage/samples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "Apache-2.0",
55
"author": "Google Inc.",
66
"engines": {
7-
"node": ">=12"
7+
"node": ">=18"
88
},
99
"repository": "googleapis/nodejs-storage",
1010
"private": true,
@@ -27,4 +27,4 @@
2727
"mocha": "^8.0.0",
2828
"p-limit": "^3.1.0"
2929
}
30-
}
30+
}

handwritten/storage/samples/system-test/files.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,11 @@ describe('file', () => {
618618
const file = hnsBucket.file(fileName);
619619
await file.save(fileName);
620620
const output = execSync(
621-
`node moveFileAtomic.js ${hnsBucketName} ${fileName} ${movedFileName} ${doesNotExistPrecondition}`
621+
`node moveFileAtomic.js ${hnsBucketName} ${fileName} ${movedFileName} ${doesNotExistPrecondition}`,
622622
);
623623
assert.include(
624624
output,
625-
`gs://${hnsBucketName}/${fileName} moved to gs://${hnsBucketName}/${movedFileName}`
625+
`gs://${hnsBucketName}/${fileName} moved to gs://${hnsBucketName}/${movedFileName}`,
626626
);
627627
const [exists] = await hnsBucket.file(movedFileName).exists();
628628
assert.strictEqual(exists, true);

handwritten/storage/src/acl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ class Acl extends AclRoleAccessorMethods {
541541
url,
542542
queryParameters: query as unknown as StorageQueryParameters,
543543
retry: false,
544-
body: {
544+
body: JSON.stringify({
545545
entity: options.entity,
546546
role: options.role.toUpperCase(),
547-
},
547+
}),
548548
},
549549
(err, data, resp) => {
550550
if (err) {
@@ -904,9 +904,9 @@ class Acl extends AclRoleAccessorMethods {
904904
method: 'PUT',
905905
url,
906906
queryParameters: query as unknown as StorageQueryParameters,
907-
body: {
907+
body: JSON.stringify({
908908
role: options.role.toUpperCase(),
909-
},
909+
}),
910910
},
911911
(err, data, resp) => {
912912
if (err) {

handwritten/storage/src/bucket.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ import {paginator} from '@google-cloud/paginator';
2525
import {promisifyAll} from '@google-cloud/promisify';
2626
import * as fs from 'fs';
2727
import * as http from 'http';
28-
import mime from 'mime';
2928
import * as path from 'path';
30-
import pLimit from 'p-limit';
3129
import {promisify} from 'util';
3230
import AsyncRetry from 'async-retry';
3331
import {convertObjKeysToSnakeCase} from './util.js';
@@ -67,6 +65,8 @@ import {
6765
} from './nodejs-common/service-object.js';
6866
import {GaxiosError} from 'gaxios';
6967
import {StorageQueryParameters} from './storage-transport.js';
68+
import mime from 'mime';
69+
import pLimit from 'p-limit';
7070

7171
interface SourceObject {
7272
name: string;
@@ -540,7 +540,7 @@ export enum BucketExceptionMessages {
540540
SPECIFY_FILE_NAME = 'A file name must be specified.',
541541
METAGENERATION_NOT_PROVIDED = 'A metageneration must be provided.',
542542
SUPPLY_NOTIFICATION_ID = 'You must supply a notification ID.',
543-
INVAILD_CHANNEL_RESPONSE = 'Response data was null',
543+
INVALID_CHANNEL_RESPONSE = 'Response data was null',
544544
}
545545

546546
/**
@@ -1342,7 +1342,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
13421342
* **Note**: For configuring a raw-formatted rule object to be passed as `action`
13431343
* please refer to the [examples]{@link https://cloud.google.com/storage/docs/managing-lifecycles#configexamples}.
13441344
* @param {object} rule.condition Condition a bucket must meet before the
1345-
* action occurson the bucket. Refer to followitn supported [conditions]{@link https://cloud.google.com/storage/docs/lifecycle#conditions}.
1345+
* action occurs on the bucket. Refer to following supported [conditions]{@link https://cloud.google.com/storage/docs/lifecycle#conditions}.
13461346
* @param {string} [rule.storageClass] When using the `setStorageClass`
13471347
* action, provide this option to dictate which storage class the object
13481348
* should update to.
@@ -1690,7 +1690,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
16901690
method: 'POST',
16911691
url: '/compose',
16921692
maxRetries,
1693-
body: {
1693+
body: JSON.stringify({
16941694
destination: {
16951695
contentType: destinationFile.metadata.contentType,
16961696
contentEncoding: destinationFile.metadata.contentEncoding,
@@ -1708,7 +1708,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
17081708

17091709
return sourceObject;
17101710
}),
1711-
},
1711+
}),
17121712
queryParameters: options as unknown as StorageQueryParameters,
17131713
},
17141714
(err, resp) => {
@@ -1851,13 +1851,15 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
18511851
.makeRequest<CreateChannel>(
18521852
{
18531853
method: 'POST',
1854-
url: `${this.baseUrl}/o/watch`,
1855-
body: Object.assign(
1856-
{
1857-
id,
1858-
type: 'web_hook',
1859-
},
1860-
config,
1854+
url: `${this.baseUrl}/${this.name}/o/watch`,
1855+
body: JSON.stringify(
1856+
Object.assign(
1857+
{
1858+
id,
1859+
type: 'web_hook',
1860+
},
1861+
config,
1862+
),
18611863
),
18621864
queryParameters: options as unknown as StorageQueryParameters,
18631865
},
@@ -1876,7 +1878,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
18761878
return;
18771879
}
18781880
callback!(
1879-
new Error(BucketExceptionMessages.INVAILD_CHANNEL_RESPONSE),
1881+
new Error(BucketExceptionMessages.INVALID_CHANNEL_RESPONSE),
18801882
null,
18811883
resp,
18821884
);
@@ -1978,7 +1980,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
19781980
* myBucket.createNotification('my-topic', callback);
19791981
*
19801982
* //-
1981-
* // Configure the nofiication by providing Notification metadata.
1983+
* // Configure the notification by providing Notification metadata.
19821984
* //-
19831985
* const metadata = {
19841986
* objectNamePrefix: 'prefix-'
@@ -2044,8 +2046,8 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
20442046
.makeRequest(
20452047
{
20462048
method: 'POST',
2047-
url: `${this.baseUrl}/notificationConfigs`,
2048-
body: convertObjKeysToSnakeCase(body),
2049+
url: `${this.baseUrl}/${this.name}/notificationConfigs`,
2050+
body: JSON.stringify(convertObjKeysToSnakeCase(body)),
20492051
queryParameters: query as unknown as StorageQueryParameters,
20502052
retry: false,
20512053
},
@@ -2859,7 +2861,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
28592861
this.storageTransport
28602862
.makeRequest<GetFilesResponseData>(
28612863
{
2862-
url: `${this.baseUrl}/${this.id}/o`,
2864+
url: `${this.baseUrl}/${this.name}/o`,
28632865
queryParameters: query as unknown as StorageQueryParameters,
28642866
},
28652867
(err, data, resp) => {
@@ -3058,7 +3060,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
30583060
this.storageTransport
30593061
.makeRequest<GetNotificationsResponseData>(
30603062
{
3061-
url: `${this.baseUrl}/notificationConfigs`,
3063+
url: `${this.baseUrl}/${this.name}/notificationConfigs`,
30623064
queryParameters: options as unknown as StorageQueryParameters,
30633065
},
30643066
(err, data, resp) => {
@@ -3104,7 +3106,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
31043106
* @property {boolean} [virtualHostedStyle=false] Use virtual hosted-style
31053107
* URLs ('https://mybucket.storage.googleapis.com/...') instead of path-style
31063108
* ('https://storage.googleapis.com/mybucket/...'). Virtual hosted-style URLs
3107-
* should generally be preferred instaed of path-style URL.
3109+
* should generally be preferred instead of path-style URL.
31083110
* Currently defaults to `false` for path-style, although this may change in a
31093111
* future major-version release.
31103112
* @property {string} [cname] The cname for this bucket, i.e.,
@@ -3151,7 +3153,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
31513153
* @param {boolean} [config.virtualHostedStyle=false] Use virtual hosted-style
31523154
* URLs ('https://mybucket.storage.googleapis.com/...') instead of path-style
31533155
* ('https://storage.googleapis.com/mybucket/...'). Virtual hosted-style URLs
3154-
* should generally be preferred instaed of path-style URL.
3156+
* should generally be preferred instead of path-style URL.
31553157
* Currently defaults to `false` for path-style, although this may change in a
31563158
* future major-version release.
31573159
* @param {string} [config.cname] The cname for this bucket, i.e.,
@@ -3255,7 +3257,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
32553257
* @throws {Error} if a metageneration is not provided.
32563258
*
32573259
* @param {number|string} metageneration The bucket's metageneration. This is
3258-
* accesssible from calling {@link File#getMetadata}.
3260+
* accessible from calling {@link File#getMetadata}.
32593261
* @param {BucketLockCallback} [callback] Callback function.
32603262
* @returns {Promise<BucketLockResponse>}
32613263
*
@@ -3289,7 +3291,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
32893291
.makeRequest(
32903292
{
32913293
method: 'POST',
3292-
url: `${this.baseUrl}/lockRetentionPolicy`,
3294+
url: `${this.baseUrl}/${this.name}/lockRetentionPolicy`,
32933295
queryParameters: {
32943296
ifMetagenerationMatch: metageneration,
32953297
},
@@ -3313,7 +3315,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
33133315
async restore(options: RestoreOptions): Promise<Bucket> {
33143316
const bucket = await this.storageTransport.makeRequest<Bucket>({
33153317
method: 'POST',
3316-
url: `${this.baseUrl}/restore`,
3318+
url: `${this.baseUrl}/${this.name}/restore`,
33173319
queryParameters: options as unknown as StorageQueryParameters,
33183320
});
33193321

handwritten/storage/src/channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Channel extends ServiceObject<Channel, BaseMetadata> {
8888
{
8989
method: 'POST',
9090
url: `${this.baseUrl}/stop`,
91-
body: this.metadata,
91+
body: JSON.stringify(this.metadata),
9292
responseType: 'json',
9393
},
9494
(err, data, resp) => {

0 commit comments

Comments
 (0)