Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"dependencies": {
"@grpc/grpc-js": "^1.12.6",
"@grpc/proto-loader": "^0.8.0",
"abort-controller": "^3.0.0",
"duplexify": "^4.1.3",
"google-auth-library": "^10.1.0",
"google-logging-utils": "^1.1.1",
Expand Down
10 changes: 3 additions & 7 deletions gax/src/fallbackServiceStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/

import type {Response as NodeFetchResponse} from 'node-fetch' with {'resolution-mode': 'import'};
import {AbortController as NodeAbortController} from 'abort-controller';

import {AuthClient, GoogleAuth, gaxios} from 'google-auth-library';
import * as serializer from 'proto3-json-serializer';

import {hasAbortController, isNodeJS} from './featureDetection';
import {isNodeJS} from './featureDetection';
import {StreamArrayParser} from './streamArrayParser';
import {defaultToObjectOptions} from './fallback';
import {pipeline, PipelineSource} from 'stream';
Expand Down Expand Up @@ -146,10 +145,7 @@ export function generateServiceStub(
};
}

const cancelController = hasAbortController()
? new AbortController()
: new NodeAbortController();
const cancelSignal = cancelController.signal as AbortSignal;
const cancelController = new AbortController();
let cancelRequested = false;
const url = fetchParameters.url;
const headers = new Headers(fetchParameters.headers);
Expand All @@ -162,7 +158,7 @@ export function generateServiceStub(
headers: headers,
body: fetchParameters.body,
method: fetchParameters.method,
signal: cancelSignal,
signal: cancelController.signal,
responseType: 'stream', // ensure gaxios returns the data directly so that it handle data/streams itself
agent: agentOption || undefined,
};
Expand Down
5 changes: 0 additions & 5 deletions gax/src/featureDetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const features = {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
textDecoder: typeof TextDecoder !== 'undefined',
nodeJS: typeof process !== 'undefined' && process?.versions?.node,
abortController: typeof AbortController !== 'undefined',
};

export function hasWindowFetch() {
Expand All @@ -36,7 +35,3 @@ export function hasWindowFetch() {
export function isNodeJS() {
return features.nodeJS;
}

export function hasAbortController() {
return features.abortController;
}
10 changes: 3 additions & 7 deletions gax/src/streamArrayParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
* limitations under the License.
*/

import {AbortController as NodeAbortController} from 'abort-controller';
import {Transform} from 'stream';
import {Transform} from 'node:stream';

import {decodeResponse} from './fallbackRest';
import {hasAbortController} from './featureDetection';

export class StreamArrayParser extends Transform {
private _done: boolean;
Expand All @@ -27,7 +25,7 @@ export class StreamArrayParser extends Transform {
private _isSkipped: boolean;
private _level: number;
rpc: protobuf.Method;
cancelController: AbortController | NodeAbortController;
cancelController: AbortController;
cancelSignal: AbortSignal;
cancelRequested: boolean;
/**
Expand Down Expand Up @@ -59,9 +57,7 @@ export class StreamArrayParser extends Transform {
this._isSkipped = false;
this._level = 0;
this.rpc = rpc;
this.cancelController = hasAbortController()
? new AbortController()
: new NodeAbortController();
this.cancelController = new AbortController();
this.cancelSignal = this.cancelController.signal as AbortSignal;
this.cancelRequested = false;
}
Expand Down
32 changes: 8 additions & 24 deletions gax/test/unit/grpc-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable no-undef */

import assert from 'assert';
import assert from 'node:assert';
import {describe, it, beforeEach, afterEach, after} from 'mocha';
import * as abortController from 'abort-controller';
import * as protobuf from 'protobufjs';
import * as sinon from 'sinon';
import echoProtoJson = require('../fixtures/echo.json');
Expand All @@ -28,9 +27,6 @@ import {ClientStubOptions, GoogleAuth, GoogleError} from '../../src';
import {PassThroughClient} from 'google-auth-library';
import {setMockFallbackResponse} from './utils';

// @ts-ignore
const hasAbortController = typeof AbortController !== 'undefined';

let authClient = new PassThroughClient();
let opts = {
auth: new GoogleAuth({authClient}),
Expand Down Expand Up @@ -173,9 +169,7 @@ describe('grpc-fallback', () => {
stubOptions: ClientStubOptions;
const createdAbortControllers: string[] = [];
// @ts-ignore
const savedAbortController = hasAbortController
? AbortController
: abortController.AbortController;
const savedAbortController = AbortController;

beforeEach(() => {
stubOptions = {
Expand All @@ -201,14 +195,9 @@ describe('grpc-fallback', () => {
createdAbortControllers.push(this);
};

if (hasAbortController) {
// @ts-ignore
// eslint-disable-next-line no-global-assign
AbortController = FakeAbortController;
} else {
// @ts-ignore
abortController.AbortController = FakeAbortController;
}
// @ts-ignore
// eslint-disable-next-line no-global-assign
AbortController = FakeAbortController;
});

beforeEach(() => {
Expand All @@ -220,14 +209,9 @@ describe('grpc-fallback', () => {
});

after(() => {
if (hasAbortController) {
// @ts-ignore
// eslint-disable-next-line no-global-assign
AbortController = savedAbortController;
} else {
// @ts-ignore
abortController.AbortController = savedAbortController;
}
// @ts-ignore
// eslint-disable-next-line no-global-assign
AbortController = savedAbortController;
});

it('should send grpc-web version in the header', () => {
Expand Down
Loading