Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove support for custom promises #541

Merged
merged 1 commit into from Mar 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/operation.ts
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
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
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
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
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
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