Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit d63b256

Browse files
chore: clean up types related to common (#482)
1 parent 8009e7b commit d63b256

10 files changed

Lines changed: 608 additions & 717 deletions

File tree

package-lock.json

Lines changed: 565 additions & 565 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@types/p-limit": "^2.0.0",
3838
"@types/pify": "^3.0.0",
3939
"@types/proxyquire": "^1.3.28",
40-
"@types/request": "^2.0.0",
40+
"@types/request": "^2.47.1",
4141
"@types/rimraf": "^2.0.2",
4242
"@types/semver": "^5.3.32",
4343
"@types/tmp": "0.0.33",

src/agent/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as common from '../types/common';
17+
import {GoogleAuthOptions} from '@google-cloud/common';
1818

19-
export type DebugAgentConfig = {
19+
export type DebugAgentConfig = GoogleAuthOptions&{
2020
[K in keyof ResolvedDebugAgentConfig]?: Partial<ResolvedDebugAgentConfig[K]>
2121
};
2222

@@ -66,7 +66,7 @@ export interface GitSourceContext {
6666
revisionId: string;
6767
}
6868

69-
export interface ResolvedDebugAgentConfig extends common.AuthenticationConfig {
69+
export interface ResolvedDebugAgentConfig extends GoogleAuthOptions {
7070
/**
7171
* Specifies the working directory of the application being
7272
* debugged. That is, the directory containing the application's
@@ -249,7 +249,7 @@ export interface ResolvedDebugAgentConfig extends common.AuthenticationConfig {
249249
testMode_: boolean;
250250
}
251251

252-
export interface StackdriverConfig extends common.AuthenticationConfig {
252+
export interface StackdriverConfig extends GoogleAuthOptions {
253253
debug?: DebugAgentConfig;
254254
}
255255

src/agent/controller.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
* @module debug/controller
1919
*/
2020

21-
import {Common} from '../types/common';
22-
export const common: Common = require('@google-cloud/common');
23-
21+
import {ServiceObject} from '@google-cloud/common';
2422
import * as assert from 'assert';
2523
import * as http from 'http';
2624
import * as qs from 'querystring';
25+
import {Response} from 'request';
2726

2827
import {Debug} from '../client/stackdriver/debug';
2928
import {Debuggee} from '../debuggee';
@@ -32,7 +31,7 @@ import * as stackdriver from '../types/stackdriver';
3231
/** @const {string} Cloud Debug API endpoint */
3332
const API = 'https://clouddebugger.googleapis.com/v2/controller';
3433

35-
export class Controller extends common.ServiceObject {
34+
export class Controller extends ServiceObject {
3635
private nextWaitToken: string|null;
3736

3837
/**
@@ -60,22 +59,19 @@ export class Controller extends common.ServiceObject {
6059
json: true,
6160
body: {debuggee}
6261
};
63-
this.request(
64-
options,
65-
(err: Error, body: {debuggee: Debuggee},
66-
response: http.ServerResponse) => {
67-
if (err) {
68-
callback(err);
69-
} else if (response.statusCode !== 200) {
70-
callback(new Error(
71-
'unable to register, statusCode ' + response.statusCode));
72-
} else if (!body.debuggee) {
73-
callback(new Error('invalid response body from server'));
74-
} else {
75-
debuggee.id = body.debuggee.id;
76-
callback(null, body);
77-
}
78-
});
62+
this.request(options, (err, body: {debuggee: Debuggee}, response) => {
63+
if (err) {
64+
callback(err);
65+
} else if (response!.statusCode !== 200) {
66+
callback(new Error(
67+
'unable to register, statusCode ' + response!.statusCode));
68+
} else if (!body.debuggee) {
69+
callback(new Error('invalid response body from server'));
70+
} else {
71+
debuggee.id = body.debuggee.id;
72+
callback(null, body);
73+
}
74+
});
7975
}
8076

8177

@@ -87,7 +83,7 @@ export class Controller extends common.ServiceObject {
8783
listBreakpoints(
8884
debuggee: Debuggee,
8985
callback:
90-
(err: Error|null, response?: http.ServerResponse,
86+
(err: Error|null, response?: Response,
9187
body?: stackdriver.ListBreakpointsResponse) => void): void {
9288
const that = this;
9389
assert(debuggee.id, 'should have a registered debuggee');
@@ -100,8 +96,7 @@ export class Controller extends common.ServiceObject {
10096
'/breakpoints?' + qs.stringify(query);
10197
that.request(
10298
{uri, json: true},
103-
(err: Error, body: stackdriver.ListBreakpointsResponse,
104-
response: http.ServerResponse) => {
99+
(err, body: stackdriver.ListBreakpointsResponse, response) => {
105100
if (!response) {
106101
callback(
107102
err || new Error('unknown error - request response missing'));
@@ -151,8 +146,8 @@ export class Controller extends common.ServiceObject {
151146
// stringify them. The try-catch keeps it resilient and avoids crashing the
152147
// user's app.
153148
try {
154-
this.request(options, (err: Error, body: {} /*, response */) => {
155-
callback(err, body);
149+
this.request(options, (err, body /*, response */) => {
150+
callback(err!, body);
156151
});
157152
} catch (error) {
158153
callback(error);

src/agent/debuglet.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ import {EventEmitter} from 'events';
2020
import * as extend from 'extend';
2121
import * as fs from 'fs';
2222
import * as metadata from 'gcp-metadata';
23-
import * as http from 'http';
2423
import * as _ from 'lodash';
2524
import * as path from 'path';
2625
import * as util from 'util';
2726

2827
import {Debug, PackageInfo} from '../client/stackdriver/debug';
2928
import {StatusMessage} from '../client/stackdriver/status-message';
3029
import {Debuggee, DebuggeeProperties} from '../debuggee';
31-
import {AuthenticationConfig} from '../types/common';
3230
import * as stackdriver from '../types/stackdriver';
3331

3432
import {defaultConfig} from './config';
@@ -40,6 +38,7 @@ import * as utils from './util/utils';
4038
import * as debugapi from './v8/debugapi';
4139
import {DebugApi} from './v8/debugapi';
4240
import consoleLogLevel = require('console-log-level');
41+
import {GoogleAuthOptions} from '@google-cloud/common';
4342

4443
const promisify = require('util.promisify');
4544

@@ -250,9 +249,8 @@ export class Debuglet extends EventEmitter {
250249
this.debuggeeRegistered = new CachedPromise();
251250
}
252251

253-
static LEVELNAMES: consoleLogLevel.LogLevelNames[] = [
254-
'fatal', 'error', 'warn', 'info', 'debug', 'trace'
255-
];
252+
static LEVELNAMES: consoleLogLevel.LogLevelNames[] =
253+
['fatal', 'error', 'warn', 'info', 'debug', 'trace'];
256254
static logLevelToName(level: number): consoleLogLevel.LogLevelNames {
257255
if (typeof level === 'string') {
258256
level = Number(level);
@@ -525,7 +523,7 @@ export class Debuglet extends EventEmitter {
525523
return new Debuggee(properties);
526524
}
527525

528-
static async getProjectId(options: AuthenticationConfig): Promise<string> {
526+
static async getProjectId(options: GoogleAuthOptions): Promise<string> {
529527
const project = options.projectId || process.env.GCLOUD_PROJECT ||
530528
await this.getProjectIdFromMetadata();
531529
if (!project) {
@@ -654,7 +652,7 @@ export class Debuglet extends EventEmitter {
654652
return;
655653
}
656654
// TODO: Address the case where `response` is `undefined`.
657-
switch ((response as http.ServerResponse).statusCode) {
655+
switch (response!.statusCode) {
658656
case 404:
659657
// Registration expired. Deactivate the fetcher and queue
660658
// re-registration, which will re-active breakpoint fetching.
@@ -666,9 +664,7 @@ export class Debuglet extends EventEmitter {
666664

667665
default:
668666
// TODO: Address the case where `response` is `undefined`.
669-
that.logger.info(
670-
'\t' + (response as http.ServerResponse).statusCode +
671-
' completed.');
667+
that.logger.info('\t' + response!.statusCode + ' completed.');
672668
if (!body) {
673669
that.logger.error('\tinvalid list response: empty body');
674670
that.scheduleBreakpointFetch_(

src/agent/v8/debugapi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export interface DebugApi {
3636
}
3737

3838
interface DebugApiConstructor {
39-
new(logger: consoleLogLevel.Logger, config: DebugAgentConfig, jsFiles: ScanStats,
40-
sourcemapper: SourceMapper): DebugApi;
39+
new(logger: consoleLogLevel.Logger, config: DebugAgentConfig,
40+
jsFiles: ScanStats, sourcemapper: SourceMapper): DebugApi;
4141
}
4242

4343
let debugApiConstructor: DebugApiConstructor;
@@ -61,8 +61,8 @@ export const MODULE_WRAP_PREFIX_LENGTH =
6161
let singleton: DebugApi;
6262

6363
export function create(
64-
logger: consoleLogLevel.Logger, config: DebugAgentConfig, jsFiles: ScanStats,
65-
sourcemapper: SourceMapper): DebugApi {
64+
logger: consoleLogLevel.Logger, config: DebugAgentConfig,
65+
jsFiles: ScanStats, sourcemapper: SourceMapper): DebugApi {
6666
if (singleton && !config.forceNewAgent_) {
6767
return singleton;
6868
} else if (singleton) {

src/client/stackdriver/debug.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {AuthenticationConfig, Common} from '../../types/common';
18-
export const common: Common = require('@google-cloud/common');
17+
import {GoogleAuthOptions, Service} from '@google-cloud/common';
1918

2019
export interface PackageInfo {
2120
name: string;
2221
version: string;
2322
}
2423

25-
export class Debug extends common.Service {
26-
options!: AuthenticationConfig;
24+
export class Debug extends Service {
25+
options!: GoogleAuthOptions;
2726
packageInfo!: PackageInfo;
2827

2928
/**
@@ -49,11 +48,10 @@ export class Debug extends common.Service {
4948
*
5049
* @param options - [Authentication options](#/docs)
5150
*/
52-
constructor(options: AuthenticationConfig, packageJson: {
51+
constructor(options: GoogleAuthOptions, packageJson: {
5352
name: string; version: string;
5453
}) {
5554
if (new.target !== Debug) {
56-
options = common.util.normalizeArguments(null, options);
5755
return new Debug(options, packageJson);
5856
}
5957

src/types/common.d.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

test/debugger.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
* @module debug/debugger
1919
*/
2020

21+
import {ServiceObject} from '@google-cloud/common';
2122
import {Debug} from '../src/client/stackdriver/debug';
2223
import {Debuggee} from '../src/debuggee';
23-
import * as commonTypes from '../src/types/common';
2424
import * as stackdriver from '../src/types/stackdriver';
2525

26-
export const common: commonTypes.Common = require('@google-cloud/common');
2726
// TODO: Verify these types are correct.
2827
const qs: {
2928
parse: (
@@ -36,7 +35,7 @@ const qs: {
3635
/** @const {string} Cloud Debug API endpoint */
3736
const API = 'https://clouddebugger.googleapis.com/v2/debugger';
3837

39-
export class Debugger extends common.ServiceObject {
38+
export class Debugger extends ServiceObject {
4039
private nextWaitToken: string|null;
4140
private clientVersion: string;
4241

test/test-controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ describe('Controller API', () => {
120120
// TODO: Determine if the response parameter should be used.
121121
controller.listBreakpoints(
122122
debuggee as Debuggee,
123-
(err: Error|null, response?: http.ServerResponse,
124-
result?: stackdriver.ListBreakpointsResponse) => {
123+
(err, response, result?: stackdriver.ListBreakpointsResponse) => {
125124
assert(!err, 'not expecting an error');
126125
// TODO: Handle the case where result is undefined
127126
assert(
@@ -148,8 +147,7 @@ describe('Controller API', () => {
148147
// TODO: Determine if the response parameter should be used.
149148
controller.listBreakpoints(
150149
debuggee as Debuggee,
151-
(err: Error|null, response?: http.ServerResponse,
152-
result?: stackdriver.ListBreakpointsResponse) => {
150+
(err, response, result?: stackdriver.ListBreakpointsResponse) => {
153151
assert(!err, 'not expecting an error');
154152
// TODO: Handle the case where result is undefined
155153
assert(

0 commit comments

Comments
 (0)