Skip to content

Commit

Permalink
fix!: remove support for custom promises (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Mar 5, 2020
1 parent f04be12 commit ecf1c16
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 46 deletions.
14 changes: 6 additions & 8 deletions src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ export class Operation<T = any> extends ServiceObject<T> {
/**
* Wraps the `complete` and `error` events in a Promise.
*
* @return {promise}
* @return {Promise}
*/
promise() {
return new this.Promise!(
(resolve: Function, reject: (err: Error) => void) => {
this.on('error', reject).on('complete', (metadata: {}) => {
resolve([metadata]);
});
}
);
return new Promise((resolve, reject) => {
this.on('error', reject).on('complete', (metadata: {}) => {
resolve([metadata]);
});
});
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import {
export type RequestResponse = [Metadata, r.Response];

export interface ServiceObjectParent {
// tslint:disable-next-line:variable-name
Promise?: PromiseConstructor;
requestStream(reqOpts: DecorateRequestOptions): r.Request;
request(
reqOpts: DecorateRequestOptions,
Expand Down Expand Up @@ -158,8 +156,6 @@ class ServiceObject<T = any> extends EventEmitter {
private createMethod?: Function;
protected methods: Methods;
protected interceptors: Interceptor[];
// tslint:disable-next-line:variable-name
Promise?: PromiseConstructor;

/*
* @constructor
Expand Down Expand Up @@ -189,7 +185,6 @@ class ServiceObject<T = any> extends EventEmitter {
this.methods = config.methods || {};
this.interceptors = [];
this.pollIntervalMs = config.pollIntervalMs;
this.Promise = this.parent ? this.parent.Promise : undefined;

if (config.methods) {
Object.getOwnPropertyNames(ServiceObject.prototype)
Expand Down
4 changes: 0 additions & 4 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface ServiceConfig {

export interface ServiceOptions extends GoogleAuthOptions {
interceptors_?: Interceptor[];
promise?: PromiseConstructor;
email?: string;
token?: string;
timeout?: number; // http.request.options.timeout
Expand All @@ -79,8 +78,6 @@ export class Service {
private packageJson: PackageJson;
projectId: string;
private projectIdRequired: boolean;
// tslint:disable-next-line:variable-name
Promise: PromiseConstructor;
makeAuthenticatedRequest: MakeAuthenticatedRequest;
authClient: GoogleAuth;
private getCredentials: {};
Expand Down Expand Up @@ -111,7 +108,6 @@ export class Service {
this.packageJson = config.packageJson;
this.projectId = options.projectId || PROJECT_ID_TOKEN;
this.projectIdRequired = config.projectIdRequired !== false;
this.Promise = options.promise || Promise;

const reqCfg = extend({}, config, {
projectIdRequired: this.projectIdRequired,
Expand Down
8 changes: 0 additions & 8 deletions test/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('Operation', () => {
let operation: Operation;
beforeEach(() => {
operation = new Operation({parent: FAKE_SERVICE, id: OPERATION_ID});
operation.Promise = Promise;
});

afterEach(() => {
Expand Down Expand Up @@ -93,13 +92,6 @@ describe('Operation', () => {
asAny(operation).startPolling_ = () => Promise.resolve();
});

it('should return an instance of the localized Promise', () => {
class FakePromise<T> extends Promise<T> {}
operation.Promise = FakePromise;
const promise = operation.promise();
assert(promise instanceof FakePromise);
});

it('should reject the promise if an error occurs', () => {
const error = new Error('err');
setImmediate(() => {
Expand Down
10 changes: 0 additions & 10 deletions test/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ describe('ServiceObject', () => {
assert.strictEqual(typeof serviceObject.create, 'function');
assert.strictEqual(serviceObject.delete, undefined);
});

it('should localize the Promise object', () => {
// tslint:disable-next-line:variable-name
const FakePromise = () => {};
const config = extend({}, CONFIG, {
parent: {Promise: FakePromise},
});
const serviceObject = new ServiceObject(config) as FakeServiceObject;
assert.strictEqual(serviceObject.Promise, FakePromise);
});
});

describe('create', () => {
Expand Down
11 changes: 0 additions & 11 deletions test/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ describe('Service', () => {
assert.strictEqual(service.projectIdRequired, true);
});

it('should localize the Promise object', () => {
// tslint:disable-next-line:variable-name
const FakePromise = () => {};
const service = new Service(fakeCfg, {promise: FakePromise});
assert.strictEqual(service.Promise, FakePromise);
});

it('should localize the native Promise object by default', () => {
assert.strictEqual(service.Promise, global.Promise);
});

it('should disable forever agent for Cloud Function envs', () => {
process.env.FUNCTION_NAME = 'cloud-function-name';
const service = new Service(CONFIG, OPTIONS);
Expand Down

0 comments on commit ecf1c16

Please sign in to comment.