Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
Merged
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
7 changes: 2 additions & 5 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,9 +145,7 @@ export function generateServiceStub(
};
}

const cancelController = hasAbortController()
? new AbortController()
: new NodeAbortController();
const cancelController = new AbortController();
const cancelSignal = cancelController.signal as AbortSignal;
let cancelRequested = false;
const url = fetchParameters.url;
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;
}
8 changes: 2 additions & 6 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 {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
50 changes: 17 additions & 33 deletions gax/test/unit/grpc-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import assert from '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 @@ -171,11 +167,8 @@ describe('grpc-fallback', () => {
protos: protobuf.NamespaceBase,
echoService: protobuf.Service,
stubOptions: ClientStubOptions;
const createdAbortControllers: string[] = [];
// @ts-ignore
const savedAbortController = hasAbortController
? AbortController
: abortController.AbortController;
const createdAbortControllers: AbortController[] = [];
const savedAbortController = AbortController;

beforeEach(() => {
stubOptions = {
Expand All @@ -191,24 +184,21 @@ describe('grpc-fallback', () => {
port: 443,
};

const FakeAbortController = function () {
// @ts-ignore
this.abort = function () {
// @ts-ignore
this.abortCalled = true;
};
// @ts-ignore
createdAbortControllers.push(this);
};
class FakeAbortController extends savedAbortController {
abortCalled = false;

if (hasAbortController) {
// @ts-ignore
// eslint-disable-next-line no-global-assign
AbortController = FakeAbortController;
} else {
// @ts-ignore
abortController.AbortController = FakeAbortController;
constructor() {
super();
createdAbortControllers.push(this);
}
abort(reason?: unknown) {
super.abort(reason);
this.abortCalled = true;
}
}

// eslint-disable-next-line no-global-assign
AbortController = FakeAbortController;
});

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

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

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