Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Commit eaacf7a

Browse files
refactor: remove configurable request (#394)
1 parent 04b5610 commit eaacf7a

6 files changed

Lines changed: 54 additions & 128 deletions

File tree

src/service-object.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export type RequestResponse = [Metadata, r.Response];
3232
export interface ServiceObjectParent {
3333
// tslint:disable-next-line:variable-name
3434
Promise?: PromiseConstructor;
35-
requestModule?: typeof r;
3635
requestStream(reqOpts: DecorateRequestOptions): r.Request;
3736
request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback):
3837
void;
@@ -82,11 +81,6 @@ export interface ServiceObjectConfig {
8281
* object is Bucket.
8382
*/
8483
parent: ServiceObjectParent;
85-
86-
/**
87-
* Dependency for HTTP calls.
88-
*/
89-
requestModule?: typeof r;
9084
}
9185

9286
export interface Methods {
@@ -148,7 +142,6 @@ class ServiceObject<T = any> extends EventEmitter {
148142
protected interceptors: Interceptor[];
149143
// tslint:disable-next-line:variable-name
150144
Promise?: PromiseConstructor;
151-
requestModule: typeof r;
152145

153146
/*
154147
* @constructor
@@ -178,8 +171,6 @@ class ServiceObject<T = any> extends EventEmitter {
178171
this.methods = config.methods || {};
179172
this.interceptors = [];
180173
this.Promise = this.parent ? this.parent.Promise : undefined;
181-
this.requestModule =
182-
(config.requestModule || (this.parent && this.parent.requestModule))!;
183174

184175
if (config.methods) {
185176
Object.getOwnPropertyNames(ServiceObject.prototype)

src/service.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export interface ServiceConfig {
4545

4646
projectIdRequired?: boolean;
4747
packageJson: PackageJson;
48-
requestModule: typeof r;
4948

5049
/**
5150
* Reuse an existing GoogleAuth client instead of creating a new one.
@@ -72,7 +71,6 @@ export class Service {
7271
makeAuthenticatedRequest: MakeAuthenticatedRequest;
7372
authClient: GoogleAuth;
7473
private getCredentials: {};
75-
requestModule: typeof r;
7674

7775
/**
7876
* Service is a base class, meant to be inherited from by a "service," like
@@ -99,16 +97,14 @@ export class Service {
9997
this.projectId = options.projectId || PROJECT_ID_TOKEN;
10098
this.projectIdRequired = config.projectIdRequired !== false;
10199
this.Promise = options.promise || Promise;
102-
this.requestModule = config.requestModule;
103100

104101
const reqCfg = extend({}, config, {
105102
projectIdRequired: this.projectIdRequired,
106103
projectId: this.projectId,
107104
credentials: options.credentials,
108105
keyFile: options.keyFilename,
109106
email: options.email,
110-
token: options.token,
111-
request: this.requestModule,
107+
token: options.token
112108
});
113109

114110
this.makeAuthenticatedRequest =

src/util.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {CredentialBody} from 'google-auth-library/build/src/auth/credentials';
2626
import * as r from 'request'; // types only
2727
import * as retryRequest from 'retry-request';
2828
import {Duplex, DuplexOptions, PassThrough, Readable, Writable} from 'stream';
29+
import {teenyRequest} from 'teeny-request';
2930

3031
import {Interceptor} from './service-object';
3132

@@ -121,8 +122,6 @@ export interface MakeAuthenticatedRequestFactoryConfig extends
121122

122123
stream?: Duplexify;
123124

124-
request: typeof r;
125-
126125
/**
127126
* A pre-instantiated GoogleAuth client that should be used.
128127
* A new will be created if this is not set.
@@ -167,11 +166,6 @@ export interface MakeWritableStreamOptions {
167166
*/
168167
request?: r.Options;
169168

170-
/**
171-
* Dependency for HTTP calls.
172-
*/
173-
requestModule: typeof r;
174-
175169
makeAuthenticatedRequest(reqOpts: r.OptionsWithUri, fnobj: {
176170
onAuthenticated(err: Error|null, authenticatedReqOpts?: r.Options): void
177171
}): void;
@@ -304,8 +298,6 @@ export interface MakeRequestConfig {
304298

305299
stream?: Duplexify;
306300

307-
request?: typeof r;
308-
309301
shouldRetryFn?: (response?: r.Response) => boolean;
310302
}
311303

@@ -460,7 +452,7 @@ export class Util {
460452
return;
461453
}
462454

463-
const request = options.requestModule.defaults(requestDefaults);
455+
const request = teenyRequest.defaults(requestDefaults);
464456
request(authenticatedReqOpts!, (err, resp, body) => {
465457
util.handleResp(err, resp, body, (err, data) => {
466458
if (err) {
@@ -672,7 +664,7 @@ export class Util {
672664
reqOpts: DecorateRequestOptions, config: MakeRequestConfig,
673665
callback: BodyResponseCallback): void|Abortable {
674666
const options = {
675-
request: (config.request as typeof r).defaults(requestDefaults),
667+
request: teenyRequest.defaults(requestDefaults),
676668
retries: config.autoRetry !== false ? config.maxRetries || 3 : 0,
677669
shouldRetryFn(httpRespMessage: r.Response) {
678670
const err = util.parseHttpRespMessage(httpRespMessage).err;

test/operation.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ describe('Operation', () => {
3232
const sandbox = sinon.createSandbox();
3333
let operation: Operation;
3434
beforeEach(() => {
35-
operation = new Operation({
36-
parent: FAKE_SERVICE,
37-
id: OPERATION_ID,
38-
requestModule: {} as typeof r,
39-
});
35+
operation = new Operation({parent: FAKE_SERVICE, id: OPERATION_ID});
4036
operation.Promise = Promise;
4137
});
4238

@@ -45,7 +41,7 @@ describe('Operation', () => {
4541
});
4642

4743
describe('instantiation', () => {
48-
const parent = {requestModule: {}};
44+
const parent = {};
4945

5046
it('should extend ServiceObject and EventEmitter', () => {
5147
const svcObj = ServiceObject;

test/service-object.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ describe('ServiceObject', () => {
4444

4545
const CONFIG = {
4646
baseUrl: 'base-url',
47-
parent: {
48-
requestModule: {},
49-
} as Service,
47+
parent: {} as Service,
5048
id: 'id',
5149
createMethod: util.noop
5250
};
@@ -115,17 +113,11 @@ describe('ServiceObject', () => {
115113
// tslint:disable-next-line:variable-name
116114
const FakePromise = () => {};
117115
const config = extend({}, CONFIG, {
118-
parent: {Promise: FakePromise, requestModule: {}},
116+
parent: {Promise: FakePromise},
119117
});
120118
const serviceObject = new ServiceObject(config) as FakeServiceObject;
121119
assert.strictEqual(serviceObject.Promise, FakePromise);
122120
});
123-
124-
it('should inherit the parents requestModule', () => {
125-
const serviceObject = new ServiceObject(CONFIG);
126-
assert.strictEqual(
127-
serviceObject.requestModule, CONFIG.parent.requestModule);
128-
});
129121
});
130122

131123
describe('create', () => {

0 commit comments

Comments
 (0)