diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 24943e11..4456edb0 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,4 +1,4 @@ -# Copyright 2024 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. docker: - image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest - digest: sha256:609822e3c09b7a1bd90b99655904609f162cc15acb4704f1edf778284c36f429 -# created: 2024-10-01T19:34:30.797530443Z + image: 'gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest' + digest: 'sha256:0d39e59663287ae929c1d4ccf8ebf7cef9946826c9b86eda7e85d8d752dbb584' diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml index d4ca9418..a37ea931 100644 --- a/.github/release-trigger.yml +++ b/.github/release-trigger.yml @@ -1 +1,2 @@ enabled: true +multiScmName: nodejs-common \ No newline at end of file diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index b46e4c4d..a013376d 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -8,9 +8,9 @@ branchProtectionRules: - "ci/kokoro: Samples test" - "ci/kokoro: System test" - lint - - test (14) - - test (16) - test (18) + - test (20) + - test (22) - cla/google - windows - OwlBot Post Processor diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4892eb2c..791891a0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,10 +9,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [14, 16, 18, 20] + node: [18, 20, 22] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - run: node --version @@ -29,10 +29,10 @@ jobs: windows: runs-on: windows-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - run: npm install --engine-strict - run: npm test env: @@ -40,19 +40,19 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - run: npm install - run: npm run lint docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - run: npm install - run: npm run docs - uses: JustinBeckwith/linkinator-action@v1 diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg index c73cda8c..f1892dfe 100644 --- a/.kokoro/common.cfg +++ b/.kokoro/common.cfg @@ -16,7 +16,7 @@ build_file: "nodejs-common/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:18-user" } env_vars: { key: "TRAMPOLINE_BUILD_FILE" diff --git a/.kokoro/continuous/node14/common.cfg b/.kokoro/continuous/node18/common.cfg similarity index 89% rename from .kokoro/continuous/node14/common.cfg rename to .kokoro/continuous/node18/common.cfg index c73cda8c..f1892dfe 100644 --- a/.kokoro/continuous/node14/common.cfg +++ b/.kokoro/continuous/node18/common.cfg @@ -16,7 +16,7 @@ build_file: "nodejs-common/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:18-user" } env_vars: { key: "TRAMPOLINE_BUILD_FILE" diff --git a/.kokoro/continuous/node14/lint.cfg b/.kokoro/continuous/node18/lint.cfg similarity index 100% rename from .kokoro/continuous/node14/lint.cfg rename to .kokoro/continuous/node18/lint.cfg diff --git a/.kokoro/continuous/node14/samples-test.cfg b/.kokoro/continuous/node18/samples-test.cfg similarity index 100% rename from .kokoro/continuous/node14/samples-test.cfg rename to .kokoro/continuous/node18/samples-test.cfg diff --git a/.kokoro/continuous/node14/system-test.cfg b/.kokoro/continuous/node18/system-test.cfg similarity index 100% rename from .kokoro/continuous/node14/system-test.cfg rename to .kokoro/continuous/node18/system-test.cfg diff --git a/.kokoro/continuous/node14/test.cfg b/.kokoro/continuous/node18/test.cfg similarity index 100% rename from .kokoro/continuous/node14/test.cfg rename to .kokoro/continuous/node18/test.cfg diff --git a/.kokoro/presubmit/node14/common.cfg b/.kokoro/presubmit/node18/common.cfg similarity index 89% rename from .kokoro/presubmit/node14/common.cfg rename to .kokoro/presubmit/node18/common.cfg index c73cda8c..f1892dfe 100644 --- a/.kokoro/presubmit/node14/common.cfg +++ b/.kokoro/presubmit/node18/common.cfg @@ -16,7 +16,7 @@ build_file: "nodejs-common/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:18-user" } env_vars: { key: "TRAMPOLINE_BUILD_FILE" diff --git a/.kokoro/presubmit/node14/samples-test.cfg b/.kokoro/presubmit/node18/samples-test.cfg similarity index 100% rename from .kokoro/presubmit/node14/samples-test.cfg rename to .kokoro/presubmit/node18/samples-test.cfg diff --git a/.kokoro/presubmit/node14/system-test.cfg b/.kokoro/presubmit/node18/system-test.cfg similarity index 100% rename from .kokoro/presubmit/node14/system-test.cfg rename to .kokoro/presubmit/node18/system-test.cfg diff --git a/.kokoro/presubmit/node14/test.cfg b/.kokoro/presubmit/node18/test.cfg similarity index 100% rename from .kokoro/presubmit/node14/test.cfg rename to .kokoro/presubmit/node18/test.cfg diff --git a/.kokoro/release/docs-devsite.cfg b/.kokoro/release/docs-devsite.cfg index d42505bd..fa25d85a 100644 --- a/.kokoro/release/docs-devsite.cfg +++ b/.kokoro/release/docs-devsite.cfg @@ -11,7 +11,7 @@ before_action { # doc publications use a Python image. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:18-user" } # Download trampoline resources. diff --git a/.kokoro/release/docs.cfg b/.kokoro/release/docs.cfg index 7a1725d1..151b037a 100644 --- a/.kokoro/release/docs.cfg +++ b/.kokoro/release/docs.cfg @@ -11,7 +11,7 @@ before_action { # doc publications use a Python image. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:18-user" } # Download trampoline resources. diff --git a/.kokoro/release/docs.sh b/.kokoro/release/docs.sh index 1d8f3f49..e9079a60 100755 --- a/.kokoro/release/docs.sh +++ b/.kokoro/release/docs.sh @@ -16,7 +16,7 @@ set -eo pipefail -# build jsdocs (Python is installed on the Node 10 docker image). +# build jsdocs (Python is installed on the Node 18 docker image). if [[ -z "$CREDENTIALS" ]]; then # if CREDENTIALS are explicitly set, assume we're testing locally # and don't set NPM_CONFIG_PREFIX. diff --git a/.kokoro/release/publish.cfg b/.kokoro/release/publish.cfg index 067d861a..7e27b970 100644 --- a/.kokoro/release/publish.cfg +++ b/.kokoro/release/publish.cfg @@ -30,7 +30,7 @@ build_file: "nodejs-common/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:18-user" } env_vars: { diff --git a/.kokoro/samples-test.sh b/.kokoro/samples-test.sh index 8c5d108c..52877539 100755 --- a/.kokoro/samples-test.sh +++ b/.kokoro/samples-test.sh @@ -16,7 +16,9 @@ set -eo pipefail -export NPM_CONFIG_PREFIX=${HOME}/.npm-global +# Ensure the npm global directory is writable, otherwise rebuild `npm` +mkdir -p $NPM_CONFIG_PREFIX +npm config -g ls || npm i -g npm@`npm --version` # Setup service account credentials. export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secret_manager/long-door-651-kokoro-system-test-service-account @@ -56,7 +58,7 @@ fi # codecov combines coverage across integration and unit tests. Include # the logic below for any environment you wish to collect coverage for: -COVERAGE_NODE=14 +COVERAGE_NODE=18 if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then NYC_BIN=./node_modules/nyc/bin/nyc.js if [ -f "$NYC_BIN" ]; then diff --git a/.kokoro/system-test.sh b/.kokoro/system-test.sh index 0b3043d2..a90d5cfe 100755 --- a/.kokoro/system-test.sh +++ b/.kokoro/system-test.sh @@ -49,7 +49,7 @@ npm run system-test # codecov combines coverage across integration and unit tests. Include # the logic below for any environment you wish to collect coverage for: -COVERAGE_NODE=14 +COVERAGE_NODE=18 if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then NYC_BIN=./node_modules/nyc/bin/nyc.js if [ -f "$NYC_BIN" ]; then diff --git a/.kokoro/test.bat b/.kokoro/test.bat index 0bb12405..caf82565 100644 --- a/.kokoro/test.bat +++ b/.kokoro/test.bat @@ -21,7 +21,7 @@ cd .. @rem we upgrade Node.js in the image: SET PATH=%PATH%;/cygdrive/c/Program Files/nodejs/npm -call nvm use v14.17.3 +call nvm use 18 call which node call npm install || goto :error diff --git a/.kokoro/test.sh b/.kokoro/test.sh index 862d478d..0d9f6392 100755 --- a/.kokoro/test.sh +++ b/.kokoro/test.sh @@ -39,7 +39,7 @@ npm test # codecov combines coverage across integration and unit tests. Include # the logic below for any environment you wish to collect coverage for: -COVERAGE_NODE=14 +COVERAGE_NODE=18 if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then NYC_BIN=./node_modules/nyc/bin/nyc.js if [ -f "$NYC_BIN" ]; then diff --git a/.kokoro/trampoline_v2.sh b/.kokoro/trampoline_v2.sh index 4d031121..5d6cfcca 100755 --- a/.kokoro/trampoline_v2.sh +++ b/.kokoro/trampoline_v2.sh @@ -44,7 +44,7 @@ # the project root. # # Here is an example for running this script. -# TRAMPOLINE_IMAGE=gcr.io/cloud-devrel-kokoro-resources/node:10-user \ +# TRAMPOLINE_IMAGE=gcr.io/cloud-devrel-kokoro-resources/node:18-user \ # TRAMPOLINE_BUILD_FILE=.kokoro/system-test.sh \ # .kokoro/trampoline_v2.sh diff --git a/package.json b/package.json index 4eed75c6..dfb5314b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "author": "Google Inc.", "engines": { - "node": ">=14.0.0" + "node": ">=18" }, "repository": "googleapis/nodejs-common", "main": "./build/src/index.js", @@ -34,39 +34,39 @@ "dependencies": { "@google-cloud/projectify": "^4.0.0", "@google-cloud/promisify": "^4.0.0", - "arrify": "^2.0.1", - "duplexify": "^4.1.1", + "arrify": "^2.0.0", + "duplexify": "^4.1.3", "extend": "^3.0.2", - "google-auth-library": "^9.0.0", + "google-auth-library": "^10.0.0-rc.1", "html-entities": "^2.5.2", - "retry-request": "^7.0.0", - "teeny-request": "^9.0.0" + "retry-request": "^8.0.0", + "teeny-request": "^10.0.0" }, "devDependencies": { - "@types/ent": "^2.2.1", - "@types/extend": "^3.0.1", - "@types/mocha": "^9.0.0", - "@types/mv": "^2.1.0", - "@types/ncp": "^2.0.3", - "@types/node": "^20.4.9", - "@types/proxyquire": "^1.3.28", - "@types/request": "^2.48.4", - "@types/sinon": "^17.0.0", - "@types/tmp": "0.2.6", - "c8": "^8.0.1", - "codecov": "^3.6.5", - "gts": "^5.0.0", - "jsdoc": "^4.0.0", + "@types/ent": "^2.2.8", + "@types/extend": "^3.0.4", + "@types/mocha": "^10.0.10", + "@types/mv": "^2.1.4", + "@types/ncp": "^2.0.8", + "@types/node": "^22.13.5", + "@types/proxyquire": "^1.3.31", + "@types/request": "^2.48.12", + "@types/sinon": "^17.0.4", + "@types/tmp": "^0.2.6", + "c8": "^10.1.3", + "codecov": "^3.8.3", + "gts": "^6.0.2", + "jsdoc": "^4.0.4", "jsdoc-fresh": "^3.0.0", "jsdoc-region-tag": "^3.0.0", - "linkinator": "^3.0.0", - "mocha": "^9.2.2", + "linkinator": "^6.1.2", + "mocha": "^11.1.0", "mv": "^2.1.1", "ncp": "^2.0.0", - "nock": "^13.0.0", + "nock": "^14.0.1", "proxyquire": "^2.1.3", - "sinon": "^17.0.0", - "tmp": "0.2.3", - "typescript": "^5.1.6" + "sinon": "^19.0.2", + "tmp": "^0.2.3", + "typescript": "^5.8.2" } } diff --git a/samples/package.json b/samples/package.json index ab040e36..070046d7 100644 --- a/samples/package.json +++ b/samples/package.json @@ -3,7 +3,7 @@ "license": "Apache-2.0", "author": "Google LLC", "engines": { - "node": ">=14.0.0" + "node": ">=18" }, "repository": "googleapis/nodejs-common", "private": true, diff --git a/src/operation.ts b/src/operation.ts index 65a1e8f5..7de87b7f 100644 --- a/src/operation.ts +++ b/src/operation.ts @@ -66,7 +66,7 @@ export class Operation extends ServiceObject { { baseUrl: '', }, - config + config, ); // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -106,7 +106,7 @@ export class Operation extends ServiceObject { this.completeListeners++; if (!this.hasActiveListeners) { this.hasActiveListeners = true; - this.startPolling_(); + void this.startPolling_(); } } }); @@ -125,7 +125,7 @@ export class Operation extends ServiceObject { * @private */ protected poll_(callback: MetadataCallback): void { - this.getMetadata((err: ApiError, body: Metadata) => { + void this.getMetadata((err: ApiError, body: Metadata) => { if (err || body!.error) { callback(err || (body!.error as Error)); return; diff --git a/src/service-object.ts b/src/service-object.ts index 797c44ce..79819381 100644 --- a/src/service-object.ts +++ b/src/service-object.ts @@ -17,7 +17,7 @@ */ import {promisifyAll} from '@google-cloud/promisify'; -import arrify = require('arrify'); +const arrify = require('arrify'); import {EventEmitter} from 'events'; import * as extend from 'extend'; import * as r from 'teeny-request'; @@ -39,7 +39,7 @@ export interface ServiceObjectParent { requestStream(reqOpts: DecorateRequestOptions): r.Request; request( reqOpts: DecorateRequestOptions, - callback: BodyResponseCallback + callback: BodyResponseCallback, ): void; } @@ -55,7 +55,7 @@ export type MetadataResponse = [Metadata, r.Response]; export type MetadataCallback = ( err: Error | null, metadata?: Metadata, - apiResponse?: r.Response + apiResponse?: r.Response, ) => void; export type ExistsOptions = object; @@ -238,7 +238,7 @@ class ServiceObject extends EventEmitter { create(callback: CreateCallback): void; create( optionsOrCallback?: CreateOptions | CreateCallback, - callback?: CreateCallback + callback?: CreateCallback, ): void | Promise> { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; @@ -280,7 +280,7 @@ class ServiceObject extends EventEmitter { delete(callback: DeleteCallback): void; delete( optionsOrCallback?: DeleteOptions | DeleteCallback, - cb?: DeleteCallback + cb?: DeleteCallback, ): Promise<[r.Response]> | void { const [options, callback] = util.maybeOptionsOrCallback< DeleteOptions, @@ -302,7 +302,7 @@ class ServiceObject extends EventEmitter { methodConfig.reqOpts, { qs: options, - } + }, ); // The `request` method may have been overridden to hold any special @@ -317,7 +317,7 @@ class ServiceObject extends EventEmitter { } } callback(err, ...(args as any)); - } + }, ); } @@ -333,7 +333,7 @@ class ServiceObject extends EventEmitter { exists(callback: ExistsCallback): void; exists( optionsOrCallback?: ExistsOptions | ExistsCallback, - cb?: ExistsCallback + cb?: ExistsCallback, ): void | Promise<[boolean]> { const [options, callback] = util.maybeOptionsOrCallback< ExistsOptions, @@ -370,7 +370,7 @@ class ServiceObject extends EventEmitter { get(options: GetOrCreateOptions, callback: InstanceResponseCallback): void; get( optionsOrCallback?: GetOrCreateOptions | InstanceResponseCallback, - cb?: InstanceResponseCallback + cb?: InstanceResponseCallback, ): Promise> | void { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; @@ -387,7 +387,7 @@ class ServiceObject extends EventEmitter { function onCreate( err: ApiError | null, instance: T, - apiResponse: r.Response + apiResponse: r.Response, ) { if (err) { if (err.code === 409) { @@ -408,7 +408,7 @@ class ServiceObject extends EventEmitter { args.push(options); } args.push(onCreate); - self.create(...args); + void self.create(...args); return; } callback!(err, null, metadata as r.Response); @@ -431,7 +431,7 @@ class ServiceObject extends EventEmitter { getMetadata(callback: MetadataCallback): void; getMetadata( optionsOrCallback: GetMetadataOptions | MetadataCallback, - cb?: MetadataCallback + cb?: MetadataCallback, ): Promise | void { const [options, callback] = util.maybeOptionsOrCallback< GetMetadataOptions, @@ -450,7 +450,7 @@ class ServiceObject extends EventEmitter { methodConfig.reqOpts, { qs: options, - } + }, ); // The `request` method may have been overridden to hold any special @@ -461,7 +461,7 @@ class ServiceObject extends EventEmitter { (err: Error | null, body?: ResponseBody, res?: r.Response) => { this.metadata = body; callback!(err, this.metadata, res); - } + }, ); } @@ -487,18 +487,18 @@ class ServiceObject extends EventEmitter { */ setMetadata( metadata: Metadata, - options?: SetMetadataOptions + options?: SetMetadataOptions, ): Promise; setMetadata(metadata: Metadata, callback: MetadataCallback): void; setMetadata( metadata: Metadata, options: SetMetadataOptions, - callback: MetadataCallback + callback: MetadataCallback, ): void; setMetadata( metadata: Metadata, optionsOrCallback: SetMetadataOptions | MetadataCallback, - cb?: MetadataCallback + cb?: MetadataCallback, ): Promise | void { const [options, callback] = util.maybeOptionsOrCallback< SetMetadataOptions, @@ -520,7 +520,7 @@ class ServiceObject extends EventEmitter { { json: metadata, qs: options, - } + }, ); // The `request` method may have been overridden to hold any special @@ -531,7 +531,7 @@ class ServiceObject extends EventEmitter { (err: Error | null, body?: ResponseBody, res?: r.Response) => { this.metadata = body; callback!(err, this.metadata, res); - } + }, ); } @@ -547,11 +547,11 @@ class ServiceObject extends EventEmitter { private request_(reqOpts: StreamRequestOptions): r.Request; private request_( reqOpts: DecorateRequestOptions, - callback: BodyResponseCallback + callback: BodyResponseCallback, ): void; private request_( reqOpts: DecorateRequestOptions | StreamRequestOptions, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ): void | r.Request { reqOpts = extend(true, {}, reqOpts); @@ -574,7 +574,9 @@ class ServiceObject extends EventEmitter { }) .join('/'); - const childInterceptors = arrify(reqOpts.interceptors_!); + const childInterceptors = (arrify as unknown as (arg1: any) => [])( + reqOpts.interceptors_!, + ); const localInterceptors = [].slice.call(this.interceptors); reqOpts.interceptors_ = childInterceptors.concat(localInterceptors); @@ -596,11 +598,11 @@ class ServiceObject extends EventEmitter { request(reqOpts: DecorateRequestOptions): Promise; request( reqOpts: DecorateRequestOptions, - callback: BodyResponseCallback + callback: BodyResponseCallback, ): void; request( reqOpts: DecorateRequestOptions, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ): void | Promise { this.request_(reqOpts, callback!); } diff --git a/src/service.ts b/src/service.ts index 022403a4..d0a17924 100644 --- a/src/service.ts +++ b/src/service.ts @@ -16,7 +16,7 @@ * @module common/service */ -import arrify = require('arrify'); +const arrify = require('arrify'); import * as extend from 'extend'; import {AuthClient, GoogleAuth, GoogleAuthOptions} from 'google-auth-library'; import * as r from 'teeny-request'; @@ -105,7 +105,9 @@ export class Service { this.baseUrl = config.baseUrl; this.apiEndpoint = config.apiEndpoint; this.timeout = options.timeout; - this.globalInterceptors = arrify(options.interceptors_!); + this.globalInterceptors = (arrify as unknown as (arg1: any) => [])( + options.interceptors_!, + ); this.interceptors = []; this.packageJson = config.packageJson; this.projectId = options.projectId || DEFAULT_PROJECT_ID_TOKEN; @@ -159,7 +161,7 @@ export class Service { getProjectId(): Promise; getProjectId(callback: (err: Error | null, projectId?: string) => void): void; getProjectId( - callback?: (err: Error | null, projectId?: string) => void + callback?: (err: Error | null, projectId?: string) => void, ): Promise | void { if (!callback) { return this.getProjectIdAsync(); @@ -187,11 +189,11 @@ export class Service { private request_(reqOpts: StreamRequestOptions): r.Request; private request_( reqOpts: DecorateRequestOptions, - callback: BodyResponseCallback + callback: BodyResponseCallback, ): void; private request_( reqOpts: DecorateRequestOptions | StreamRequestOptions, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ): void | r.Request { reqOpts = extend(true, {}, reqOpts, {timeout: this.timeout}); const isAbsoluteUrl = reqOpts.uri.indexOf('http') === 0; @@ -226,11 +228,13 @@ export class Service { const requestInterceptors = this.getRequestInterceptors(); - arrify(reqOpts.interceptors_!).forEach(interceptor => { - if (typeof interceptor.request === 'function') { - requestInterceptors.push(interceptor.request); - } - }); + (arrify as unknown as (arg1: any) => any[])(reqOpts.interceptors_!).forEach( + interceptor => { + if (typeof interceptor.request === 'function') { + requestInterceptors.push(interceptor.request); + } + }, + ); requestInterceptors.forEach(requestInterceptor => { reqOpts = requestInterceptor(reqOpts); @@ -264,7 +268,7 @@ export class Service { */ request( reqOpts: DecorateRequestOptions, - callback: BodyResponseCallback + callback: BodyResponseCallback, ): void { Service.prototype.request_.call(this, reqOpts, callback); } diff --git a/src/util.ts b/src/util.ts index 88ce1508..322e6cfe 100644 --- a/src/util.ts +++ b/src/util.ts @@ -79,17 +79,17 @@ export interface DuplexifyConstructor { obj( writable?: Writable | false | null, readable?: Readable | false | null, - options?: DuplexifyOptions + options?: DuplexifyOptions, ): Duplexify; new ( writable?: Writable | false | null, readable?: Readable | false | null, - options?: DuplexifyOptions + options?: DuplexifyOptions, ): Duplexify; ( writable?: Writable | false | null, readable?: Readable | false | null, - options?: DuplexifyOptions + options?: DuplexifyOptions, ): Duplexify; } @@ -102,18 +102,18 @@ export interface MakeAuthenticatedRequest { (reqOpts: DecorateRequestOptions): Duplexify; ( reqOpts: DecorateRequestOptions, - options?: MakeAuthenticatedRequestOptions + options?: MakeAuthenticatedRequestOptions, ): void | Abortable; ( reqOpts: DecorateRequestOptions, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ): void | Abortable; ( reqOpts: DecorateRequestOptions, - optionsOrCallback?: MakeAuthenticatedRequestOptions | BodyResponseCallback + optionsOrCallback?: MakeAuthenticatedRequestOptions | BodyResponseCallback, ): void | Abortable | Duplexify; getCredentials: ( - callback: (err?: Error | null, credentials?: CredentialBody) => void + callback: (err?: Error | null, credentials?: CredentialBody) => void, ) => void; authClient: GoogleAuth; } @@ -214,9 +214,9 @@ export interface MakeWritableStreamOptions { fnobj: { onAuthenticated( err: Error | null, - authenticatedReqOpts?: r.Options + authenticatedReqOpts?: r.Options, ): void; - } + }, ): void; } @@ -280,7 +280,7 @@ export class ApiError extends Error { */ static createMultiErrorMessage( err: GoogleErrorBody, - errors?: GoogleInnerError[] + errors?: GoogleInnerError[], ): string { const messages: Set = new Set(); @@ -301,7 +301,7 @@ export class ApiError extends Error { if (messageArr.length > 1) { messageArr = messageArr.map((message, i) => ` ${i + 1}. ${message}`); messageArr.unshift( - 'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n' + 'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n', ); messageArr.push('\n'); } @@ -392,7 +392,7 @@ export class Util { err: Error | null, resp?: r.Response | null, body?: ResponseBody, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ) { callback = callback || util.noop; @@ -400,7 +400,7 @@ export class Util { true, {err: err || null}, resp && util.parseHttpRespMessage(resp), - body && util.parseHttpRespBody(body) + body && util.parseHttpRespBody(body), ); // Assign the parsed body to resp.body, even if { json: false } was passed // as a request option. @@ -490,7 +490,7 @@ export class Util { makeWritableStream( dup: Duplexify, options: MakeWritableStreamOptions, - onComplete?: Function + onComplete?: Function, ) { onComplete = onComplete || util.noop; @@ -594,7 +594,7 @@ export class Util { * @param {array} config.scopes - Array of scopes required for the API. */ makeAuthenticatedRequestFactory( - config: MakeAuthenticatedRequestFactoryConfig + config: MakeAuthenticatedRequestFactoryConfig, ) { const googleAutoAuthConfig = extend({}, config); if (googleAutoAuthConfig.projectId === DEFAULT_PROJECT_ID_TOKEN) { @@ -626,19 +626,21 @@ export class Util { * authenticated request options. */ function makeAuthenticatedRequest( - reqOpts: DecorateRequestOptions + reqOpts: DecorateRequestOptions, ): Duplexify; function makeAuthenticatedRequest( reqOpts: DecorateRequestOptions, - options?: MakeAuthenticatedRequestOptions + options?: MakeAuthenticatedRequestOptions, ): void | Abortable; function makeAuthenticatedRequest( reqOpts: DecorateRequestOptions, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ): void | Abortable; function makeAuthenticatedRequest( reqOpts: DecorateRequestOptions, - optionsOrCallback?: MakeAuthenticatedRequestOptions | BodyResponseCallback + optionsOrCallback?: + | MakeAuthenticatedRequestOptions + | BodyResponseCallback, ): void | Abortable | Duplexify { let stream: Duplexify; let projectId: string; @@ -661,7 +663,7 @@ export class Util { const onAuthenticated = async ( err: Error | null, - authenticatedReqOpts?: DecorateRequestOptions + authenticatedReqOpts?: DecorateRequestOptions, ) => { const authLibraryError = err; const autoAuthFailed = @@ -679,7 +681,7 @@ export class Util { // Try with existing `projectId` value authenticatedReqOpts = util.decorateRequest( authenticatedReqOpts!, - projectId + projectId, ); err = null; @@ -692,7 +694,7 @@ export class Util { authenticatedReqOpts = util.decorateRequest( authenticatedReqOpts!, - projectId + projectId, ); err = null; @@ -738,7 +740,7 @@ export class Util { apiResponseError = authLibraryError; } callback!(apiResponseError, ...params); - } + }, ); } }; @@ -787,14 +789,14 @@ export class Util { return onAuthenticated( null, - authorizedReqOpts as DecorateRequestOptions + authorizedReqOpts as DecorateRequestOptions, ); } catch (e) { return onAuthenticated(e as Error); } }; - prepareRequest(); + void prepareRequest(); if (stream!) { return stream!; @@ -835,7 +837,7 @@ export class Util { makeRequest( reqOpts: DecorateRequestOptions, config: MakeRequestConfig, - callback: BodyResponseCallback + callback: BodyResponseCallback, ): void | Abortable { let autoRetryValue = AUTO_RETRY_DEFAULT; if ( @@ -843,7 +845,7 @@ export class Util { config.retryOptions?.autoRetry !== undefined ) { throw new ApiError( - 'autoRetry is deprecated. Use retryOptions.autoRetry instead.' + 'autoRetry is deprecated. Use retryOptions.autoRetry instead.', ); } else if (config.autoRetry !== undefined) { autoRetryValue = config.autoRetry; @@ -854,7 +856,7 @@ export class Util { let maxRetryValue = MAX_RETRY_DEFAULT; if (config.maxRetries && config.retryOptions?.maxRetries) { throw new ApiError( - 'maxRetries is deprecated. Use retryOptions.maxRetries instead.' + 'maxRetries is deprecated. Use retryOptions.maxRetries instead.', ); } else if (config.maxRetries) { maxRetryValue = config.maxRetries; @@ -999,7 +1001,7 @@ export class Util { */ maybeOptionsOrCallback void>( optionsOrCallback?: T | C, - cb?: C + cb?: C, ): [T, C] { return typeof optionsOrCallback === 'function' ? [{} as T, optionsOrCallback as C] diff --git a/system-test/common.ts b/system-test/common.ts index d861baed..9f12f928 100644 --- a/system-test/common.ts +++ b/system-test/common.ts @@ -50,7 +50,7 @@ describe('Common', () => { assert.ifError(err); assert.strictEqual(resp, mockResponse); mockServer.close(done); - } + }, ); }); @@ -75,7 +75,7 @@ describe('Common', () => { assert.strictEqual((err! as common.ApiError).code, 408); assert.strictEqual(numRequestAttempts, 4); mockServer.close(done); - } + }, ); }); @@ -104,7 +104,7 @@ describe('Common', () => { const timeResponse = Date.now(); assert(timeResponse - timeRequest > minExpectedResponseTime); done(); - } + }, ); }); }); diff --git a/system-test/install.ts b/system-test/install.ts index 87cfe748..487c01cf 100644 --- a/system-test/install.ts +++ b/system-test/install.ts @@ -33,7 +33,7 @@ const npm = os.platform() === 'win32' ? 'npm.cmd' : 'npm'; const spawnp = ( command: string, args: string[], - options: cp.SpawnOptions = {} + options: cp.SpawnOptions = {}, ) => { return new Promise((resolve, reject) => { cp.spawn(command, args, Object.assign(options, {stdio: 'inherit'})) diff --git a/test/operation.ts b/test/operation.ts index b656bbb7..e8f598b7 100644 --- a/test/operation.ts +++ b/test/operation.ts @@ -101,7 +101,7 @@ describe('Operation', () => { }, (err: Error) => { assert.strictEqual(err, error); - } + }, ); }); diff --git a/test/service-object.ts b/test/service-object.ts index 1e30b2e2..1d3ed35a 100644 --- a/test/service-object.ts +++ b/test/service-object.ts @@ -55,7 +55,7 @@ type FakeServiceObject = any; interface InternalServiceObject { request_: ( reqOpts: DecorateRequestOptions, - callback?: BodyResponseCallback + callback?: BodyResponseCallback, ) => void | r.Request; createMethod?: Function; methods: SO.Methods; @@ -110,7 +110,7 @@ describe('ServiceObject', () => { it('should localize the createMethod', () => { assert.strictEqual( asInternal(serviceObject).createMethod, - CONFIG.createMethod + CONFIG.createMethod, ); }); @@ -149,7 +149,7 @@ describe('ServiceObject', () => { const serviceObject = new ServiceObject(config); assert.strictEqual( typeof serviceObject.getRequestInterceptors, - 'function' + 'function', ); }); }); @@ -164,7 +164,7 @@ describe('ServiceObject', () => { function createMethod( id: string, options_: {}, - callback: (err: Error | null, a: {}, b: {}) => void + callback: (err: Error | null, a: {}, b: {}) => void, ) { assert.strictEqual(id, config.id); assert.strictEqual(options_, options); @@ -184,7 +184,7 @@ describe('ServiceObject', () => { function createMethod( id: string, options_: {}, - callback: (err: Error | null, a: {}, b: {}) => void + callback: (err: Error | null, a: {}, b: {}) => void, ) { assert.strictEqual(id, config.id); assert.strictEqual(options_, options); @@ -230,7 +230,7 @@ describe('ServiceObject', () => { assert.strictEqual(instance, null); assert.strictEqual(apiResponse_, apiResponse); done(); - } + }, ); }); @@ -294,7 +294,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts, callback) => { assert.strictEqual( (reqOpts as DecorateRequestOptions).method, - 'DELETE' + 'DELETE', ); assert.strictEqual((reqOpts as DecorateRequestOptions).uri, ''); done(); @@ -310,7 +310,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts, callback) => { assert.deepStrictEqual( (reqOpts as DecorateRequestOptions).qs, - options + options, ); done(); (callback as any)(null, null, {} as r.Response); @@ -333,15 +333,15 @@ describe('ServiceObject', () => { .callsFake((reqOpts_, callback) => { assert.deepStrictEqual( serviceObject.methods.delete, - cachedMethodConfig + cachedMethodConfig, ); assert.deepStrictEqual( (reqOpts_ as DecorateRequestOptions).uri, - 'v2' + 'v2', ); assert.deepStrictEqual( (reqOpts_ as DecorateRequestOptions).method, - 'PATCH' + 'PATCH', ); done(); (callback as any)(null, null, null!); @@ -381,7 +381,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts, callback) => { assert.strictEqual( (reqOpts as DecorateRequestOptions).qs.ignoreNotFound, - undefined + undefined, ); done(); (callback as any)(null, null, {} as r.Response); @@ -406,7 +406,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts_, callback) => { assert.deepStrictEqual( serviceObject.methods.delete, - cachedMethodConfig + cachedMethodConfig, ); assert.deepStrictEqual((reqOpts_ as DecorateRequestOptions).qs, { defaultProperty: true, @@ -430,7 +430,7 @@ describe('ServiceObject', () => { .stub(ServiceObject.prototype, 'request') .callsArgWith(1, null, null, {}); assert.doesNotThrow(() => { - serviceObject.delete(); + void serviceObject.delete(); }); }); @@ -449,7 +449,7 @@ describe('ServiceObject', () => { describe('exists', () => { it('should call get', done => { sandbox.stub(serviceObject, 'get').callsFake(() => done()); - serviceObject.exists(() => {}); + void serviceObject.exists(() => {}); }); it('should accept options', done => { @@ -468,7 +468,7 @@ describe('ServiceObject', () => { const error = new ApiError(''); error.code = 404; sandbox.stub(serviceObject, 'get').callsArgWith(1, error); - serviceObject.exists((err: Error, exists: boolean) => { + void serviceObject.exists((err: Error, exists: boolean) => { assert.ifError(err); assert.strictEqual(exists, false); done(); @@ -479,7 +479,7 @@ describe('ServiceObject', () => { const error = new ApiError(''); error.code = 500; sandbox.stub(serviceObject, 'get').callsArgWith(1, error); - serviceObject.exists((err: Error, exists: boolean) => { + void serviceObject.exists((err: Error, exists: boolean) => { assert.strictEqual(err, error); assert.strictEqual(exists, undefined); done(); @@ -488,7 +488,7 @@ describe('ServiceObject', () => { it('should execute callback with true if no error', done => { sandbox.stub(serviceObject, 'get').callsArgWith(1, null); - serviceObject.exists((err: Error, exists: boolean) => { + void serviceObject.exists((err: Error, exists: boolean) => { assert.ifError(err); assert.strictEqual(exists, true); done(); @@ -511,7 +511,7 @@ describe('ServiceObject', () => { (options_: SO.GetMetadataOptions): void => { assert.deepStrictEqual(options, options_); done(); - } + }, ); serviceObject.exists(options, assert.ifError); }); @@ -530,7 +530,7 @@ describe('ServiceObject', () => { serviceObject.getMetadata = promisify( (options: SO.GetMetadataOptions, callback: SO.MetadataCallback) => { callback(error, metadata); - } + }, ); serviceObject.get((err, instance, metadata_) => { @@ -548,7 +548,7 @@ describe('ServiceObject', () => { serviceObject.getMetadata = promisify( (options: SO.GetMetadataOptions, callback: SO.MetadataCallback) => { callback(null, metadata); - } + }, ); serviceObject.get((err, instance, metadata_) => { @@ -576,7 +576,7 @@ describe('ServiceObject', () => { serviceObject.getMetadata = promisify( (options: SO.GetMetadataOptions, callback: SO.MetadataCallback) => { callback(ERROR, METADATA); - } + }, ); }); @@ -625,7 +625,7 @@ describe('ServiceObject', () => { callback!(null); // done() }); callback!(error, null, apiResponse); - } + }, ); serviceObject.get(AUTO_CREATE_CONFIG, (err, instance, resp) => { @@ -659,14 +659,14 @@ describe('ServiceObject', () => { sandbox.stub(ServiceObject.prototype, 'request').callsFake(function ( this: SO.ServiceObject, reqOpts, - callback + callback, ) { assert.strictEqual(this, serviceObject); assert.strictEqual((reqOpts as DecorateRequestOptions).uri, ''); done(); (callback as any)(null, null, {} as r.Response); }); - serviceObject.getMetadata(() => {}); + void serviceObject.getMetadata(() => {}); }); it('should accept options', done => { @@ -676,7 +676,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts, callback) => { assert.deepStrictEqual( (reqOpts as DecorateRequestOptions).qs, - options + options, ); done(); (callback as any)(null, null, {} as r.Response); @@ -698,11 +698,11 @@ describe('ServiceObject', () => { .callsFake((reqOpts_, callback) => { assert.deepStrictEqual( serviceObject.methods.getMetadata, - cachedMethodConfig + cachedMethodConfig, ); assert.deepStrictEqual( (reqOpts_ as DecorateRequestOptions).uri, - 'v2' + 'v2', ); done(); (callback as any)(null, null, null!); @@ -730,7 +730,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts_, callback) => { assert.deepStrictEqual( serviceObject.methods.getMetadata, - cachedMethodConfig + cachedMethodConfig, ); assert.deepStrictEqual((reqOpts_ as DecorateRequestOptions).qs, { defaultProperty: true, @@ -752,7 +752,7 @@ describe('ServiceObject', () => { it('should execute callback with error & apiResponse', done => { const error = new Error('ಠ_ಠ'); sandbox.stub(ServiceObject.prototype, 'request').callsArgWith(1, error); - serviceObject.getMetadata((err: Error, metadata: {}) => { + void serviceObject.getMetadata((err: Error, metadata: {}) => { assert.strictEqual(err, error); assert.strictEqual(metadata, undefined); done(); @@ -764,7 +764,7 @@ describe('ServiceObject', () => { sandbox .stub(ServiceObject.prototype, 'request') .callsArgWith(1, null, {}, apiResponse); - serviceObject.getMetadata((err: Error) => { + void serviceObject.getMetadata((err: Error) => { assert.ifError(err); assert.deepStrictEqual(serviceObject.metadata, apiResponse); done(); @@ -777,7 +777,7 @@ describe('ServiceObject', () => { sandbox .stub(ServiceObject.prototype, 'request') .callsArgWith(1, null, apiResponse, requestResponse); - serviceObject.getMetadata((err: Error, metadata: {}) => { + void serviceObject.getMetadata((err: Error, metadata: {}) => { assert.ifError(err); assert.strictEqual(metadata, apiResponse); done(); @@ -821,7 +821,7 @@ describe('ServiceObject', () => { serviceObject.parent.getRequestInterceptors = () => { return serviceObject.parent.interceptors.map( - interceptor => interceptor.request + interceptor => interceptor.request, ); }; @@ -842,21 +842,21 @@ describe('ServiceObject', () => { serviceObject.interceptors = [{request}]; const originalParentInterceptors = [].slice.call( - serviceObject.parent.interceptors + serviceObject.parent.interceptors, ); const originalLocalInterceptors = [].slice.call( - serviceObject.interceptors + serviceObject.interceptors, ); serviceObject.getRequestInterceptors(); assert.deepStrictEqual( serviceObject.parent.interceptors, - originalParentInterceptors + originalParentInterceptors, ); assert.deepStrictEqual( serviceObject.interceptors, - originalLocalInterceptors + originalLocalInterceptors, ); }); @@ -883,19 +883,19 @@ describe('ServiceObject', () => { sandbox.stub(ServiceObject.prototype, 'request').callsFake(function ( this: SO.ServiceObject, reqOpts, - callback + callback, ) { assert.strictEqual(this, serviceObject); assert.strictEqual((reqOpts as DecorateRequestOptions).method, 'PATCH'); assert.strictEqual((reqOpts as DecorateRequestOptions).uri, ''); assert.deepStrictEqual( (reqOpts as DecorateRequestOptions).json, - metadata + metadata, ); done(); (callback as any)(null, null, {} as r.Response); }); - serviceObject.setMetadata(metadata, () => {}); + void serviceObject.setMetadata(metadata, () => {}); }); it('should accept options', done => { @@ -906,7 +906,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts, callback) => { assert.deepStrictEqual( (reqOpts as DecorateRequestOptions).qs, - options + options, ); done(); (callback as any)(null, null, {} as r.Response); @@ -928,15 +928,15 @@ describe('ServiceObject', () => { .callsFake((reqOpts_, callback) => { assert.deepStrictEqual( serviceObject.methods.setMetadata, - cachedMethodConfig + cachedMethodConfig, ); assert.deepStrictEqual( (reqOpts_ as DecorateRequestOptions).uri, - 'v2' + 'v2', ); assert.deepStrictEqual( (reqOpts_ as DecorateRequestOptions).method, - 'PUT' + 'PUT', ); done(); (callback as any)(null, null, null!); @@ -963,7 +963,7 @@ describe('ServiceObject', () => { .callsFake((reqOpts_, callback) => { assert.deepStrictEqual( serviceObject.methods.setMetadata, - cachedMethodConfig + cachedMethodConfig, ); assert.deepStrictEqual((reqOpts_ as DecorateRequestOptions).qs, { defaultProperty: true, @@ -981,14 +981,14 @@ describe('ServiceObject', () => { { optionalProperty: true, thisPropertyWasOverridden: true, - } + }, ); }); it('should execute callback with error & apiResponse', done => { const error = new Error('Error.'); sandbox.stub(ServiceObject.prototype, 'request').callsArgWith(1, error); - serviceObject.setMetadata({}, (err: Error, apiResponse_: {}) => { + void serviceObject.setMetadata({}, (err: Error, apiResponse_: {}) => { assert.strictEqual(err, error); assert.strictEqual(apiResponse_, undefined); done(); @@ -1000,7 +1000,7 @@ describe('ServiceObject', () => { sandbox .stub(ServiceObject.prototype, 'request') .callsArgWith(1, undefined, apiResponse); - serviceObject.setMetadata({}, (err: Error) => { + void serviceObject.setMetadata({}, (err: Error) => { assert.ifError(err); assert.strictEqual(serviceObject.metadata, apiResponse); done(); @@ -1013,7 +1013,7 @@ describe('ServiceObject', () => { sandbox .stub(ServiceObject.prototype, 'request') .callsArgWith(1, null, body, apiResponse); - serviceObject.setMetadata({}, (err: Error, metadata: {}) => { + void serviceObject.setMetadata({}, (err: Error, metadata: {}) => { assert.ifError(err); assert.strictEqual(metadata, body); done(); @@ -1085,7 +1085,7 @@ describe('ServiceObject', () => { uri: '//1/2//', }; const expectedUri = [serviceObject.baseUrl, serviceObject.id, '1/2'].join( - '/' + '/', ); serviceObject.parent.request = (reqOpts_, callback) => { assert.strictEqual(reqOpts_.uri, expectedUri); @@ -1107,7 +1107,7 @@ describe('ServiceObject', () => { }); const child = new ServiceObject( - extend({}, CONFIG, {parent}) + extend({}, CONFIG, {parent}), ) as FakeServiceObject; child.interceptors.push({ request(reqOpts: DecorateRequestOptions) { @@ -1124,13 +1124,13 @@ describe('ServiceObject', () => { reqOpts.interceptors_![0].request({} as DecorateRequestOptions), { child: true, - } + }, ); assert.deepStrictEqual( reqOpts.interceptors_![1].request({} as DecorateRequestOptions), { parent: true, - } + }, ); callback(null, null, {} as r.Response); }); @@ -1152,7 +1152,7 @@ describe('ServiceObject', () => { asInternal(serviceObject).interceptors; assert.deepStrictEqual( reqOpts.interceptors_, - serviceObjectInterceptors + serviceObjectInterceptors, ); assert.notStrictEqual(reqOpts.interceptors_, serviceObjectInterceptors); callback(null, null, {} as r.Response); diff --git a/test/service.ts b/test/service.ts index d5b1ca35..768e7db4 100644 --- a/test/service.ts +++ b/test/service.ts @@ -42,12 +42,12 @@ const makeAuthRequestFactoryCache = util.makeAuthenticatedRequestFactory; let makeAuthenticatedRequestFactoryOverride: | null | (( - config: MakeAuthenticatedRequestFactoryConfig + config: MakeAuthenticatedRequestFactoryConfig, ) => MakeAuthenticatedRequest); util.makeAuthenticatedRequestFactory = function ( this: Util, - config: MakeAuthenticatedRequestFactoryConfig + config: MakeAuthenticatedRequestFactoryConfig, ) { if (makeAuthenticatedRequestFactoryOverride) { return makeAuthenticatedRequestFactoryOverride.call(this, config); @@ -98,7 +98,7 @@ describe('Service', () => { const authenticatedRequest = {} as MakeAuthenticatedRequest; makeAuthenticatedRequestFactoryOverride = ( - config: MakeAuthenticatedRequestFactoryConfig + config: MakeAuthenticatedRequestFactoryConfig, ) => { const expectedConfig = extend({}, CONFIG, { authClient: OPTIONS.authClient, @@ -143,7 +143,7 @@ describe('Service', () => { } async getRequestHeaders() { - return {}; + return {} as Headers; } request = OAuth2Client.prototype.request.bind(this); @@ -305,7 +305,7 @@ describe('Service', () => { service.interceptors = [{request}]; const originalGlobalInterceptors = [].slice.call( - service.globalInterceptors + service.globalInterceptors, ); const originalLocalInterceptors = [].slice.call(service.interceptors); @@ -313,7 +313,7 @@ describe('Service', () => { assert.deepStrictEqual( service.globalInterceptors, - originalGlobalInterceptors + originalGlobalInterceptors, ); assert.deepStrictEqual(service.interceptors, originalLocalInterceptors); }); @@ -399,7 +399,7 @@ describe('Service', () => { const expectedUri = [service.baseUrl, reqOpts.uri].join('/'); service.makeAuthenticatedRequest = ( reqOpts_: DecorateRequestOptions, - callback: BodyResponseCallback + callback: BodyResponseCallback, ) => { assert.notStrictEqual(reqOpts_, reqOpts); assert.strictEqual(reqOpts_.uri, expectedUri); @@ -503,7 +503,7 @@ describe('Service', () => { service.makeAuthenticatedRequest = (reqOpts: DecorateRequestOptions) => { assert.strictEqual( reqOpts.headers!['User-Agent'], - `${providedUserAgent} ${userAgent}` + `${providedUserAgent} ${userAgent}`, ); done(); }; @@ -516,7 +516,7 @@ describe('Service', () => { const pkg = service.packageJson; assert.strictEqual( reqOpts.headers!['x-goog-api-client'], - `gl-node/${process.versions.node} gccl/${pkg.version}` + `gl-node/${process.versions.node} gccl/${pkg.version}`, ); done(); }; @@ -533,7 +533,7 @@ describe('Service', () => { const expectedUri = [service.baseUrl, reqOpts.uri].join('/'); service.makeAuthenticatedRequest = ( - reqOpts_: DecorateRequestOptions + reqOpts_: DecorateRequestOptions, ) => { assert.strictEqual(reqOpts_.uri, expectedUri); @@ -557,7 +557,7 @@ describe('Service', () => { ].join('/'); service.makeAuthenticatedRequest = ( - reqOpts_: DecorateRequestOptions + reqOpts_: DecorateRequestOptions, ) => { assert.strictEqual(reqOpts_.uri, expectedUri); @@ -582,7 +582,7 @@ describe('Service', () => { ].join('/'); service.makeAuthenticatedRequest = ( - reqOpts_: DecorateRequestOptions + reqOpts_: DecorateRequestOptions, ) => { assert.strictEqual(reqOpts_.uri, expectedUri); @@ -694,7 +694,7 @@ describe('Service', () => { const response = {body: {abc: '123'}, statusCode: 200}; Service.prototype.request_ = ( reqOpts: DecorateRequestOptions, - callback: Function + callback: Function, ) => { assert.strictEqual(reqOpts, fakeOpts); callback(null, response.body, response); diff --git a/test/util.ts b/test/util.ts index e23207bf..6c018afd 100644 --- a/test/util.ts +++ b/test/util.ts @@ -44,6 +44,7 @@ import { MakeAuthenticatedRequestFactoryConfig, MakeRequestConfig, ParsedHttpRespMessage, + ParsedHttpResponseBody, Util, } from '../src/util'; import {DEFAULT_PROJECT_ID_TOKEN} from '../src/service'; @@ -95,7 +96,7 @@ function fakeReplaceProjectIdToken() { return (replaceProjectIdTokenOverride || replaceProjectIdToken).apply( null, // eslint-disable-next-line prefer-spread, prefer-rest-params - arguments + arguments, ); } @@ -103,7 +104,7 @@ describe('common/util', () => { let util: Util & {[index: string]: Function}; // eslint-disable-next-line @typescript-eslint/no-explicit-any - function stub(method: keyof Util, meth: (...args: any[]) => void) { + function stub(method: keyof Util, meth: (...args: any[]) => any) { return sandbox.stub(util, method).callsFake(meth); } @@ -114,7 +115,7 @@ describe('common/util', () => { errors = errors.map((error, i) => ` ${i + 1}. ${error}`); errors.unshift( - 'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n' + 'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n', ); errors.push('\n'); @@ -129,7 +130,7 @@ describe('common/util', () => { } async getRequestHeaders() { - return {}; + return {} as Headers; } request = OAuth2Client.prototype.request.bind(this); @@ -369,7 +370,7 @@ describe('common/util', () => { assert.deepStrictEqual(body, fakeResponse.body); assert.deepStrictEqual(resp, fakeResponse); done(); - } + }, ); }); @@ -439,7 +440,7 @@ describe('common/util', () => { } done(); - } + }, ); }); }); @@ -513,20 +514,20 @@ describe('common/util', () => { assert.strictEqual( // eslint-disable-next-line @typescript-eslint/no-explicit-any (mp[0] as any)['Content-Type'], - 'application/json' + 'application/json', ); assert.strictEqual(mp[0].body, JSON.stringify(metadata)); assert.strictEqual( // eslint-disable-next-line @typescript-eslint/no-explicit-any (mp[1] as any)['Content-Type'], - 'application/octet-stream' + 'application/octet-stream', ); // (is a writable stream:) assert.strictEqual( // eslint-disable-next-line @typescript-eslint/no-explicit-any typeof (mp[1].body as any)._writableState, - 'object' + 'object', ); done(); @@ -619,7 +620,7 @@ describe('common/util', () => { requestOverride = ( reqOpts: DecorateRequestOptions, - callback: (err: Error) => void + callback: (err: Error) => void, ) => { callback(error); }; @@ -654,7 +655,7 @@ describe('common/util', () => { requestOverride = ( reqOpts: DecorateRequestOptions, - callback: (err: Error | null, res: r.Response) => void + callback: (err: Error | null, res: r.Response) => void, ) => { callback(null, fakeResponse); }; @@ -689,7 +690,7 @@ describe('common/util', () => { requestOverride = ( reqOpts: DecorateRequestOptions, - callback: () => void + callback: () => void, ) => { callback(); }; @@ -782,7 +783,7 @@ describe('common/util', () => { it('should return a function', () => { assert.strictEqual( typeof util.makeAuthenticatedRequestFactory({}), - 'function' + 'function', ); }); @@ -826,7 +827,7 @@ describe('common/util', () => { makeAuthenticatedRequest(fakeReqOpts, { onAuthenticated( err: Error, - authenticatedReqOpts: DecorateRequestOptions + authenticatedReqOpts: DecorateRequestOptions, ) { assert.ifError(err); assert.strictEqual(authenticatedReqOpts, decoratedRequest); @@ -853,7 +854,7 @@ describe('common/util', () => { makeAuthenticatedRequest(reqOpts, { onAuthenticated( err: Error, - authenticatedReqOpts: DecorateRequestOptions + authenticatedReqOpts: DecorateRequestOptions, ) { assert.ifError(err); assert.deepStrictEqual(reqOpts, authenticatedReqOpts); @@ -945,7 +946,7 @@ describe('common/util', () => { }); const makeAuthenticatedRequest = util.makeAuthenticatedRequestFactory( - {customEndpoint: true} + {customEndpoint: true}, ); makeAuthenticatedRequest(reqOpts, { @@ -1046,7 +1047,7 @@ describe('common/util', () => { it('should attempt request anyway', done => { sandbox.stub(fakeGoogleAuth, 'GoogleAuth').returns(authClient); const makeAuthenticatedRequest = util.makeAuthenticatedRequestFactory( - {} + {}, ); const correctReqOpts = {} as DecorateRequestOptions; @@ -1068,7 +1069,7 @@ describe('common/util', () => { it('should block 401 API errors', done => { const authClientError = new Error( - 'Could not load the default credentials' + 'Could not load the default credentials', ); authClient.authorizeRequest = async () => { throw authClientError; @@ -1084,7 +1085,7 @@ describe('common/util', () => { }); const makeAuthenticatedRequest = util.makeAuthenticatedRequestFactory( - {} + {}, ); makeAuthenticatedRequest( {} as DecorateRequestOptions, @@ -1093,7 +1094,7 @@ describe('common/util', () => { assert.strictEqual(arg2, makeRequestArg2); assert.strictEqual(arg3, makeRequestArg3); done(); - } + }, ); }); @@ -1112,7 +1113,7 @@ describe('common/util', () => { }); const makeAuthenticatedRequest = util.makeAuthenticatedRequestFactory( - {} + {}, ); makeAuthenticatedRequest( {} as DecorateRequestOptions, @@ -1121,7 +1122,7 @@ describe('common/util', () => { assert.strictEqual(arg2, makeRequestArg2); assert.strictEqual(arg3, makeRequestArg3); done(); - } + }, ); }); @@ -1133,7 +1134,7 @@ describe('common/util', () => { }); const makeAuthenticatedRequest = util.makeAuthenticatedRequestFactory( - {} + {}, ); makeAuthenticatedRequest(fakeReqOpts, { onAuthenticated(err) { @@ -1240,7 +1241,7 @@ describe('common/util', () => { const mar = util.makeAuthenticatedRequestFactory({}); const authenticatedRequest = mar( reqOpts, - assert.ifError + assert.ifError, ) as Abortable; authenticatedRequest.abort(); // done() @@ -1383,7 +1384,7 @@ describe('common/util', () => { function testNoRetryRequestConfig(done: () => void) { return ( reqOpts: DecorateRequestOptions, - config: retryRequest.Options + config: retryRequest.Options, ) => { assert.strictEqual(config.retries, 0); done(); @@ -1416,27 +1417,27 @@ describe('common/util', () => { function testRetryOptions(done: () => void) { return ( reqOpts: DecorateRequestOptions, - config: retryRequest.Options + config: retryRequest.Options, ) => { assert.strictEqual( config.retries, - 0 //autoRetry was set to false, so shouldn't retry + 0, //autoRetry was set to false, so shouldn't retry ); assert.strictEqual( config.noResponseRetries, - 0 //autoRetry was set to false, so shouldn't retry + 0, //autoRetry was set to false, so shouldn't retry ); assert.strictEqual( config.retryDelayMultiplier, - retryOptionsConfig.retryOptions.retryDelayMultiplier + retryOptionsConfig.retryOptions.retryDelayMultiplier, ); assert.strictEqual( config.totalTimeout, - retryOptionsConfig.retryOptions.totalTimeout + retryOptionsConfig.retryOptions.totalTimeout, ); assert.strictEqual( config.maxRetryDelay, - retryOptionsConfig.retryOptions.maxRetryDelay + retryOptionsConfig.retryOptions.maxRetryDelay, ); done(); }; @@ -1552,7 +1553,7 @@ describe('common/util', () => { util.makeRequest( {method: 'POST'} as DecorateRequestOptions, {stream: userStream}, - util.noop + util.noop, ); }); @@ -1565,7 +1566,7 @@ describe('common/util', () => { requestStream.abort = done; return requestStream; }, - {defaults: () => requestOverride} + {defaults: () => requestOverride}, ); util.makeRequest(reqOpts, {stream: userStream}, util.noop); @@ -1581,7 +1582,7 @@ describe('common/util', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any reqOpts, {}, - assert.ifError + assert.ifError, ); }); @@ -1590,7 +1591,7 @@ describe('common/util', () => { util.makeRequest( reqOpts, customRetryRequestFunctionConfig, - assert.ifError + assert.ifError, ); }); @@ -1628,12 +1629,12 @@ describe('common/util', () => { const reqOptsWithRetrySettings = extend( {}, reqOpts, - customRetryRequestConfig + customRetryRequestConfig, ); util.makeRequest( reqOptsWithRetrySettings, noRetryRequestConfig, - assert.ifError + assert.ifError, ); }); @@ -1653,7 +1654,7 @@ describe('common/util', () => { retryRequestOverride = ( rOpts: DecorateRequestOptions, opts: MakeRequestConfig, - callback: r.RequestCallback + callback: r.RequestCallback, ) => { callback(error, fakeResponse, body); }; @@ -1677,7 +1678,7 @@ describe('common/util', () => { { autoPaginate: true, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.autoPaginate, undefined); @@ -1688,7 +1689,7 @@ describe('common/util', () => { { autoPaginateVal: true, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.autoPaginateVal, undefined); @@ -1699,7 +1700,7 @@ describe('common/util', () => { { objectMode: true, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.objectMode, undefined); @@ -1712,7 +1713,7 @@ describe('common/util', () => { autoPaginate: true, }, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.qs.autoPaginate, undefined); @@ -1725,7 +1726,7 @@ describe('common/util', () => { autoPaginateVal: true, }, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.qs.autoPaginateVal, undefined); @@ -1738,7 +1739,7 @@ describe('common/util', () => { autoPaginate: true, }, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.json.autoPaginate, undefined); @@ -1751,7 +1752,7 @@ describe('common/util', () => { autoPaginateVal: true, }, } as DecorateRequestOptions, - projectId + projectId, ); assert.strictEqual(decoratedReqOpts.json.autoPaginateVal, undefined); @@ -1915,7 +1916,7 @@ describe('common/util', () => { const callback = () => {}; const [opts, cb] = util.maybeOptionsOrCallback( optionsOrCallback, - callback + callback, ); assert.strictEqual(opts, optionsOrCallback); assert.strictEqual(cb, callback);