Skip to content

Commit

Permalink
chore: use gts v2 (#757)
Browse files Browse the repository at this point in the history
* chore: use gts v2

* chore: ahhhhh thaaaats why

* chore: do not run on node8

* fix: new gts rules
  • Loading branch information
alexander-fenster authored Mar 26, 2020
1 parent 70e0a15 commit 247aeb7
Show file tree
Hide file tree
Showing 57 changed files with 295 additions and 342 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/node_modules
**/.coverage
src/**/doc/*
build/
docs/
Expand Down
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts"
}
15 changes: 0 additions & 15 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [8, 10, 12, 13]
node: [10, 12, 13]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

17 changes: 17 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module.exports = {
...require('gts/.prettierrc.json')
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@compodoc/compodoc": "^1.1.7",
"@types/chai": "^4.1.3",
"@types/download": "^6.2.4",
"@types/lodash.at": "^4.6.4",
"@types/lodash.has": "^4.5.4",
"@types/mocha": "^7.0.0",
Expand All @@ -57,7 +58,7 @@
"file-loader": "^6.0.0",
"fs-extra": "^9.0.0",
"google-proto-files": "^1.0.0",
"gts": "^1.0.0",
"gts": "next",
"is-docker": "^2.0.0",
"json-loader": "^0.5.7",
"karma": "^4.1.0",
Expand Down
3 changes: 0 additions & 3 deletions samples/.eslintrc.yml

This file was deleted.

1 change: 1 addition & 0 deletions src/bundlingCalls/bundleExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class BundleExecutor {
const bundledField = request[this._descriptor.bundledField] as Array<{}>;
const elementCount = bundledField.length;
let requestBytes = 0;
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
bundledField.forEach(obj => {
requestBytes += this._descriptor.byteLengthFunction(obj);
Expand Down
3 changes: 1 addition & 2 deletions src/bundlingCalls/bundlingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import at = require('lodash.at');
import {RequestType} from '../apitypes';
import {Dictionary} from 'lodash';

/**
* Compute the identifier of the `obj`. The objects of the same ID
Expand All @@ -40,7 +39,7 @@ export function computeBundleId(
const ids: unknown[] = [];
let hasIds = false;
for (let i = 0; i < discriminatorFields.length; ++i) {
const id = at(obj as Dictionary<unknown>, discriminatorFields[i])[0];
const id = at(obj, discriminatorFields[i])[0];
if (id === undefined) {
ids.push(null);
} else {
Expand Down
17 changes: 8 additions & 9 deletions src/bundlingCalls/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ export interface SubResponseInfo {
end?: number;
}

export interface TaskElement {}

export interface TaskData {
elements: TaskElement[];
elements: {}[];
bytes: number;
callback: TaskCallback;
cancelled?: boolean;
Expand All @@ -54,11 +52,11 @@ export interface TaskCallback extends APICallback {
* @private
*/
export function deepCopyForResponse(
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
obj: any,
subresponseInfo: SubResponseInfo | null
) {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let result: any;
if (obj === null) {
return null;
Expand Down Expand Up @@ -106,7 +104,7 @@ export function deepCopyForResponse(

export class Task {
_apiCall: SimpleCallbackFunction;
_request: {[index: string]: TaskElement[]};
_request: {[index: string]: {}[]};
_bundledField: string;
_subresponseField?: string | null;
_data: TaskData[];
Expand Down Expand Up @@ -167,13 +165,14 @@ export class Task {
return [];
}
const request = this._request;
const elements: TaskElement[] = [];
const elements: {}[] = [];
const ids: string[] = [];
for (let i = 0; i < this._data.length; ++i) {
elements.push.apply(elements, this._data[i].elements);
elements.push(...this._data[i].elements);
ids.push(this._data[i].callback.id!);
}
request[this._bundledField] = elements;
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.callCanceller = this._apiCall(
request,
Expand Down Expand Up @@ -221,7 +220,7 @@ export class Task {
* @param {number} bytes - the byte size required to encode elements in the API.
* @param {APICallback} callback - the callback of the method call.
*/
extend(elements: TaskElement[], bytes: number, callback: TaskCallback) {
extend(elements: {}[], bytes: number, callback: TaskCallback) {
this._data.push({
elements,
bytes,
Expand Down
3 changes: 1 addition & 2 deletions src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class OngoingCall {
if (this.completed) {
return;
}
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const canceller = func(argument, (...args: any[]) => {
this.completed = true;
setImmediate(this.callback!, ...args);
Expand All @@ -99,7 +99,6 @@ export class OngoingCallPromise extends OngoingCall {
* @constructor
* @private
*/
// tslint:disable-next-line variable-name
constructor() {
let resolveCallback: (
result: [ResponseType, NextPageRequestType, RawResponseType]
Expand Down
19 changes: 8 additions & 11 deletions src/fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ export class GrpcClient {
// Since gRPC expects each header to be an array,
// we are doing the same for fallback here.
for (const key in headers) {
if (headers.hasOwnProperty(key)) {
metadata[key] = Array.isArray(headers[key])
? (headers[key] as string[])
: ([headers[key]] as string[]);
}
metadata[key] = Array.isArray(headers[key])
? (headers[key] as string[])
: ([headers[key]] as string[]);
}

// gRPC-fallback request must have 'grpc-web/' in 'x-goog-api-client'
Expand All @@ -167,10 +165,7 @@ export class GrpcClient {
return metadata;
}
for (const key in moreHeaders) {
if (
key.toLowerCase() !== CLIENT_VERSION_HEADER &&
moreHeaders.hasOwnProperty(key)
) {
if (key.toLowerCase() !== CLIENT_VERSION_HEADER) {
const value = moreHeaders[key];
if (Array.isArray(value)) {
if (metadata[key] === undefined) {
Expand Down Expand Up @@ -264,9 +259,10 @@ export class GrpcClient {
const [method, requestData, serviceCallback] = serviceStub[
methodName
].apply(serviceStub, [req, callback]);
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let cancelController: AbortController, cancelSignal: any;
if (isBrowser && typeof AbortController !== 'undefined') {
// eslint-disable-next-line no-undef
cancelController = new AbortController();
} else {
cancelController = new NodeAbortController();
Expand Down Expand Up @@ -320,7 +316,8 @@ export class GrpcClient {
const url = `${grpcFallbackProtocol}://${servicePath}:${servicePort}/$rpc/${protoServiceName}/${rpcName}`;

const fetch = isBrowser()
? window.fetch
? // eslint-disable-next-line no-undef
window.fetch
: ((nodeFetch as unknown) as NodeFetchType);
fetch(url, {
headers,
Expand Down
1 change: 1 addition & 0 deletions src/fallbackError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class FallbackErrorDecoder {
statusType: protobuf.Type;

constructor() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const errorProtoJson = require('../../protos/status.json');
this.root = protobuf.Root.fromJSON(errorProtoJson);
this.anyType = this.root.lookupType('google.protobuf.Any');
Expand Down
9 changes: 3 additions & 6 deletions src/gax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export interface CallOptions {
pageSize?: number;
maxResults?: number;
maxRetries?: number;
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
otherArgs?: {[index: string]: any};
bundleOptions?: BundleOptions | null;
isBundling?: boolean;
Expand All @@ -133,7 +133,7 @@ export class CallSettings {
pageToken?: string;
pageSize?: number;
maxResults?: number;
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
otherArgs: {[index: string]: any};
bundleOptions?: BundleOptions | null;
isBundling: boolean;
Expand Down Expand Up @@ -219,11 +219,9 @@ export class CallSettings {

if ('otherArgs' in options) {
otherArgs = {};
// tslint:disable-next-line forin
for (const key in this.otherArgs) {
otherArgs[key] = this.otherArgs[key];
}
// tslint:disable-next-line forin
for (const optionsKey in options.otherArgs!) {
otherArgs[optionsKey] = options.otherArgs![optionsKey];
}
Expand Down Expand Up @@ -609,7 +607,7 @@ export function constructSettings(
otherArgs?: {}
) {
otherArgs = otherArgs || {};
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const defaults: any = {};

const serviceConfig = (clientConfig.interfaces || {})[serviceName];
Expand All @@ -620,7 +618,6 @@ export function constructSettings(
const overrides = (configOverrides.interfaces || {})[serviceName] || {};
const methods = serviceConfig.methods;
const overridingMethods = overrides.methods || {};
// tslint:disable-next-line forin
for (const methodName in methods) {
const methodConfig = methods[methodName];
const jsName = methodName[0].toLowerCase() + methodName.slice(1);
Expand Down
10 changes: 3 additions & 7 deletions src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface MetadataValue {
}

export interface Metadata {
// eslint-disable-next-line @typescript-eslint/no-misused-new
new (): Metadata;
set: (key: {}, value?: {} | null) => void;
clone: () => Metadata;
Expand All @@ -64,7 +65,7 @@ export interface ClientStubOptions {
servicePath?: string;
port?: number;
// TODO: use sslCreds?: grpc.ChannelCredentials;
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sslCreds?: any;
[index: string]: string | number | undefined | {};
}
Expand Down Expand Up @@ -192,7 +193,6 @@ export class GrpcClient {
metadataBuilder(headers: OutgoingHttpHeaders) {
const Metadata = this.grpc.Metadata;
const baseMetadata = new Metadata();
// tslint:disable-next-line forin
for (const key in headers) {
const value = headers[key];
if (Array.isArray(value)) {
Expand All @@ -210,10 +210,7 @@ export class GrpcClient {
let metadata = baseMetadata;
if (moreHeaders) {
for (const key in moreHeaders) {
if (
key.toLowerCase() !== 'x-goog-api-client' &&
moreHeaders!.hasOwnProperty(key)
) {
if (key.toLowerCase() !== 'x-goog-api-client') {
if (!copied) {
copied = true;
metadata = metadata.clone();
Expand Down Expand Up @@ -269,7 +266,6 @@ export class GrpcClient {
* to set up gRPC connection.
* @return {Promise} A promise which resolves to a gRPC stub instance.
*/
// tslint:disable-next-line variable-name
async createStub(CreateStub: typeof ClientStub, options: ClientStubOptions) {
const serviceAddress = options.servicePath + ':' + options.port;
const creds = await this._getCredentials(options);
Expand Down
2 changes: 0 additions & 2 deletions src/longRunningCalls/longRunningApiCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {OngoingCall, OngoingCallPromise} from '../call';
import {
BackoffSettings,
CallOptions,
CallSettings,
createBackoffSettings,
createDefaultBackoffSettings,
} from '../gax';
import {GoogleError} from '../googleError';
Expand Down
4 changes: 1 addition & 3 deletions src/longRunningCalls/longRunningDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import * as protobuf from 'protobufjs';
import {Descriptor} from '../descriptor';
import {CallSettings} from '../gax';
import {Metadata} from '../grpc';
import {OperationsClient} from '../operationsClient';
import {LongrunningApiCaller} from './longRunningApiCaller';

Expand Down Expand Up @@ -46,7 +44,7 @@ export class LongRunningDescriptor implements Descriptor {
this.metadataDecoder = metadataDecoder;
}

getApiCaller(settings: CallSettings) {
getApiCaller() {
return new LongrunningApiCaller(this);
}
}
Loading

0 comments on commit 247aeb7

Please sign in to comment.