Skip to content

Commit c5debae

Browse files
refactor: clean up types and imports (#409)
1 parent d79e7e8 commit c5debae

11 files changed

Lines changed: 152 additions & 155 deletions

File tree

handwritten/logging/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ system-test/*key.json
99
*.lock
1010
.DS_Store
1111
package-lock.json
12+
__pycache__
13+
.vscode

handwritten/logging/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"@types/pify": "^3.0.2",
8989
"@types/proxyquire": "^1.3.28",
9090
"@types/pumpify": "^1.4.1",
91+
"@types/sinon": "^7.0.8",
9192
"@types/through2": "^2.0.34",
9293
"@types/uuid": "^3.4.4",
9394
"assert-rejects": "^1.0.0",
@@ -99,17 +100,18 @@
99100
"eslint-plugin-prettier": "^3.0.0",
100101
"google-proto-files": "^0.18.0",
101102
"gts": "^0.9.0",
102-
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",
103103
"intelli-espower-loader": "^1.0.1",
104104
"jsdoc": "^3.5.5",
105+
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",
106+
"linkinator": "^1.1.2",
105107
"mocha": "^6.0.0",
106108
"nock": "^10.0.1",
107109
"nyc": "^13.0.1",
108110
"power-assert": "^1.6.0",
109111
"prettier": "^1.15.1",
110112
"proxyquire": "^2.1.0",
113+
"sinon": "^7.2.5",
111114
"typescript": "~3.3.0",
112-
"uuid": "^3.3.2",
113-
"linkinator": "^1.1.2"
115+
"uuid": "^3.3.2"
114116
}
115117
}

handwritten/logging/src/entry.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const eventId = new EventId();
2525

2626
export type LogEntry = google.logging.v2.ILogEntry;
2727
export type Timestamp = google.protobuf.IDuration;
28+
// tslint:disable-next-line no-any
29+
export type Data = any;
2830

2931
export interface EntryJson {
3032
timestamp: Timestamp|Date;
@@ -97,10 +99,8 @@ export interface ToJsonOptions {
9799
*/
98100
class Entry {
99101
metadata: LogEntry;
100-
// tslint:disable-next-line no-any
101-
data: any;
102-
// tslint:disable-next-line no-any
103-
constructor(metadata?: LogEntry, data?: any) {
102+
data: Data;
103+
constructor(metadata?: LogEntry, data?: Data) {
104104
/**
105105
* @name Entry#metadata
106106
* @type {object}
@@ -136,8 +136,7 @@ class Entry {
136136
* @param {boolean} [options.removeCircular] Replace circular references in an
137137
* object with a string value, `[Circular]`.
138138
*/
139-
toJSON(options: ToJsonOptions) {
140-
options = options || {};
139+
toJSON(options: ToJsonOptions = {}) {
141140
const entry = extend(true, {}, this.metadata) as {} as EntryJson;
142141
if (is.object(this.data)) {
143142
// tslint:disable-next-line no-any
@@ -178,8 +177,7 @@ class Entry {
178177
if (serializedEntry.metadata.timestamp) {
179178
let ms = Number(serializedEntry.metadata.timestamp.seconds) * 1000;
180179
ms += Number(serializedEntry.metadata.timestamp.nanos) / 1e6;
181-
// tslint:disable-next-line no-any
182-
(serializedEntry as any).metadata.timestamp = new Date(ms);
180+
serializedEntry.metadata.timestamp = new Date(ms) as Timestamp;
183181
}
184182
return serializedEntry;
185183
}

handwritten/logging/src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,7 @@ class Logging {
587587
* this.end();
588588
* });
589589
*/
590-
getEntriesStream(options: GetEntriesRequest) {
591-
const self = this;
592-
options = options || {};
590+
getEntriesStream(options: GetEntriesRequest = {}) {
593591
let requestStream: Duplex;
594592
const userStream = streamEvents<Duplex>(pumpify.obj());
595593
(userStream as AbortableDuplex).abort = () => {
@@ -607,15 +605,15 @@ class Logging {
607605
},
608606
options);
609607
reqOpts.resourceNames = arrify(reqOpts.resourceNames);
610-
reqOpts.resourceNames.push('projects/' + self.projectId);
608+
reqOpts.resourceNames.push(`projects/${this.projectId}`);
611609
delete reqOpts.autoPaginate;
612610
delete reqOpts.gaxOptions;
613611
const gaxOptions = extend(
614612
{
615613
autoPaginate: options.autoPaginate,
616614
},
617615
options.gaxOptions);
618-
requestStream = self.request({
616+
requestStream = this.request({
619617
client: 'LoggingServiceV2Client',
620618
method: 'listLogEntriesStream',
621619
reqOpts,
@@ -921,7 +919,6 @@ class Logging {
921919
*/
922920
setAclForBucket_(
923921
name: string, config: CreateSinkRequest, callback: CreateSinkCallback) {
924-
const self = this;
925922
const bucket = config.destination as Bucket;
926923
// tslint:disable-next-line no-any
927924
(bucket.acl.owners as any)
@@ -933,7 +930,7 @@ class Logging {
933930
return;
934931
}
935932
config.destination = 'storage.googleapis.com/' + bucket.name;
936-
self.createSink(name, config, callback);
933+
this.createSink(name, config, callback);
937934
});
938935
}
939936

handwritten/logging/src/log.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {DeleteCallback} from '@google-cloud/common';
1818
import {promisifyAll} from '@google-cloud/promisify';
1919
import * as arrify from 'arrify';
2020
import * as extend from 'extend';
21-
import {CallOptions} from 'google-gax/build/src/gax';
21+
import {CallOptions} from 'google-gax';
2222
import * as is from 'is';
2323
import {Response} from 'request';
2424

@@ -531,8 +531,9 @@ class Log implements LogSeverityFunctions {
531531
}
532532

533533
/**
534-
* This method is a wrapper around {module:logging#getEntriesStream}, but with a
535-
* filter specified to only return {module:logging/entry} objects from this log.
534+
* This method is a wrapper around {module:logging#getEntriesStream}, but with
535+
* a filter specified to only return {module:logging/entry} objects from this
536+
* log.
536537
*
537538
* @method Log#getEntriesStream
538539
* @param {GetEntriesRequest} [query] Query object for listing entries.
@@ -601,9 +602,14 @@ class Log implements LogSeverityFunctions {
601602
* });
602603
*/
603604
info(entry: Entry|Entry[], options?: WriteOptions): Promise<ApiResponse>;
604-
info(entry: Entry|Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
605+
info(
606+
entry: Entry|Entry[], options: WriteOptions,
607+
callback: ApiResponseCallback): void;
605608
info(entry: Entry|Entry[], callback: ApiResponseCallback): void;
606-
info(entry: Entry|Entry[], optionsOrCallback?: WriteOptions|ApiResponseCallback, cb?: ApiResponseCallback):void|Promise<ApiResponse> {
609+
info(
610+
entry: Entry|Entry[],
611+
optionsOrCallback?: WriteOptions|ApiResponseCallback,
612+
cb?: ApiResponseCallback): void|Promise<ApiResponse> {
607613
const options =
608614
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
609615
const callback =
@@ -641,9 +647,14 @@ class Log implements LogSeverityFunctions {
641647
* });
642648
*/
643649
notice(entry: Entry|Entry[], options?: WriteOptions): Promise<ApiResponse>;
644-
notice(entry: Entry|Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
650+
notice(
651+
entry: Entry|Entry[], options: WriteOptions,
652+
callback: ApiResponseCallback): void;
645653
notice(entry: Entry|Entry[], callback: ApiResponseCallback): void;
646-
notice(entry: Entry|Entry[], optionsOrCallback?: WriteOptions|ApiResponseCallback, cb?: ApiResponseCallback):void|Promise<ApiResponse> {
654+
notice(
655+
entry: Entry|Entry[],
656+
optionsOrCallback?: WriteOptions|ApiResponseCallback,
657+
cb?: ApiResponseCallback): void|Promise<ApiResponse> {
647658
const options =
648659
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
649660
const callback =
@@ -681,9 +692,14 @@ class Log implements LogSeverityFunctions {
681692
* });
682693
*/
683694
warning(entry: Entry|Entry[], options?: WriteOptions): Promise<ApiResponse>;
684-
warning(entry: Entry|Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
695+
warning(
696+
entry: Entry|Entry[], options: WriteOptions,
697+
callback: ApiResponseCallback): void;
685698
warning(entry: Entry|Entry[], callback: ApiResponseCallback): void;
686-
warning(entry: Entry|Entry[], optionsOrCallback?: WriteOptions|ApiResponseCallback, cb?: ApiResponseCallback):void|Promise<ApiResponse> {
699+
warning(
700+
entry: Entry|Entry[],
701+
optionsOrCallback?: WriteOptions|ApiResponseCallback,
702+
cb?: ApiResponseCallback): void|Promise<ApiResponse> {
687703
const options =
688704
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
689705
const callback =
@@ -750,8 +766,8 @@ class Log implements LogSeverityFunctions {
750766
*
751767
* //-
752768
* // To save some steps, you can also pass in plain values as your entries.
753-
* // Note, however, that you must provide a configuration object to specify the
754-
* // resource.
769+
* // Note, however, that you must provide a configuration object to specify
770+
* // the resource.
755771
* //-
756772
* const entries = [
757773
* {
@@ -784,9 +800,14 @@ class Log implements LogSeverityFunctions {
784800
* Another example:
785801
*/
786802
write(entry: Entry|Entry[], options?: WriteOptions): Promise<ApiResponse>;
787-
write(entry: Entry|Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
803+
write(
804+
entry: Entry|Entry[], options: WriteOptions,
805+
callback: ApiResponseCallback): void;
788806
write(entry: Entry|Entry[], callback: ApiResponseCallback): void;
789-
write(entry: Entry|Entry[], optionsOrCallback?: WriteOptions|ApiResponseCallback, cb?: ApiResponseCallback): void|Promise<ApiResponse> {
807+
write(
808+
entry: Entry|Entry[],
809+
optionsOrCallback?: WriteOptions|ApiResponseCallback,
810+
cb?: ApiResponseCallback): void|Promise<ApiResponse> {
790811
const options =
791812
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
792813
const callback =
@@ -866,7 +887,8 @@ class Log implements LogSeverityFunctions {
866887
* @param {object|object[]} entries - Log entries.
867888
* @param {string} severity - The desired severity level.
868889
*/
869-
static assignSeverityToEntries_(entries: Entry|Entry[], severity: string): Entry[] {
890+
static assignSeverityToEntries_(entries: Entry|Entry[], severity: string):
891+
Entry[] {
870892
return arrify(entries).map(entry => {
871893
const metadata = extend(true, {}, entry.metadata, {
872894
severity,

handwritten/logging/src/sink.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import * as common from '@google-cloud/common-grpc';
1818
import {promisifyAll} from '@google-cloud/promisify';
1919
import * as extend from 'extend';
20-
import {CallOptions} from 'google-gax/build/src/gax';
21-
import * as is from 'is';
22-
20+
import {CallOptions} from 'google-gax';
2321
import {CreateSinkCallback, CreateSinkRequest, DeleteCallback, DeleteResponse, Logging, LogSink} from '.';
2422

2523
export interface SinkMetadataCallback {

0 commit comments

Comments
 (0)