Skip to content

Commit

Permalink
style: run eslint fix on codebase
Browse files Browse the repository at this point in the history
Fixes grpc#2464
  • Loading branch information
dancrumb committed Jun 15, 2023
1 parent 3bf2af1 commit cd24d69
Show file tree
Hide file tree
Showing 63 changed files with 4,096 additions and 2,195 deletions.
20 changes: 13 additions & 7 deletions packages/grpc-js/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

import { ServiceDefinition } from "./make-client";
import { Server, UntypedServiceImplementation } from "./server";
import { ServiceDefinition } from './make-client';
import { Server, UntypedServiceImplementation } from './server';

interface GetServiceDefinition {
(): ServiceDefinition;
Expand All @@ -26,14 +26,20 @@ interface GetHandlers {
(): UntypedServiceImplementation;
}

const registeredAdminServices: {getServiceDefinition: GetServiceDefinition, getHandlers: GetHandlers}[] = [];
const registeredAdminServices: {
getServiceDefinition: GetServiceDefinition;
getHandlers: GetHandlers;
}[] = [];

export function registerAdminService(getServiceDefinition: GetServiceDefinition, getHandlers: GetHandlers) {
registeredAdminServices.push({getServiceDefinition, getHandlers});
export function registerAdminService(
getServiceDefinition: GetServiceDefinition,
getHandlers: GetHandlers
) {
registeredAdminServices.push({ getServiceDefinition, getHandlers });
}

export function addAdminServicesToServer(server: Server): void {
for (const {getServiceDefinition, getHandlers} of registeredAdminServices) {
for (const { getServiceDefinition, getHandlers } of registeredAdminServices) {
server.addService(getServiceDefinition(), getHandlers());
}
}
}
6 changes: 3 additions & 3 deletions packages/grpc-js/src/call-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export abstract class CallCredentials {
});
}
getHeaders.then(
(headers) => {
headers => {
const metadata = new Metadata();
for (const key of Object.keys(headers)) {
metadata.add(key, headers[key]);
}
callback(null, metadata);
},
(err) => {
err => {
callback(err);
}
);
Expand All @@ -152,7 +152,7 @@ class ComposedCallCredentials extends CallCredentials {
async generateMetadata(options: CallMetadataOptions): Promise<Metadata> {
const base: Metadata = new Metadata();
const generated: Metadata[] = await Promise.all(
this.creds.map((cred) => cred.generateMetadata(options))
this.creds.map(cred => cred.generateMetadata(options))
);
for (const gen of generated) {
base.merge(gen);
Expand Down
22 changes: 11 additions & 11 deletions packages/grpc-js/src/call-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*
*/

import { CallCredentials } from "./call-credentials";
import { Status } from "./constants";
import { Deadline } from "./deadline";
import { Metadata } from "./metadata";
import { ServerSurfaceCall } from "./server-call";
import { CallCredentials } from './call-credentials';
import { Status } from './constants';
import { Deadline } from './deadline';
import { Metadata } from './metadata';
import { ServerSurfaceCall } from './server-call';

export interface CallStreamOptions {
deadline: Deadline;
Expand All @@ -38,7 +38,7 @@ export interface StatusObject {

export type PartialStatusObject = Pick<StatusObject, 'code' | 'details'> & {
metadata: Metadata | null;
}
};

export const enum WriteFlags {
BufferHint = 1,
Expand Down Expand Up @@ -118,7 +118,7 @@ export class InterceptingListenerImpl implements InterceptingListener {

onReceiveMetadata(metadata: Metadata): void {
this.processingMetadata = true;
this.listener.onReceiveMetadata(metadata, (metadata) => {
this.listener.onReceiveMetadata(metadata, metadata => {
this.processingMetadata = false;
this.nextListener.onReceiveMetadata(metadata);
this.processPendingMessage();
Expand All @@ -128,9 +128,9 @@ export class InterceptingListenerImpl implements InterceptingListener {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onReceiveMessage(message: any): void {
/* If this listener processes messages asynchronously, the last message may
* be reordered with respect to the status */
* be reordered with respect to the status */
this.processingMessage = true;
this.listener.onReceiveMessage(message, (msg) => {
this.listener.onReceiveMessage(message, msg => {
this.processingMessage = false;
if (this.processingMetadata) {
this.pendingMessage = msg;
Expand All @@ -142,7 +142,7 @@ export class InterceptingListenerImpl implements InterceptingListener {
});
}
onReceiveStatus(status: StatusObject): void {
this.listener.onReceiveStatus(status, (processedStatus) => {
this.listener.onReceiveStatus(status, processedStatus => {
if (this.processingMetadata || this.processingMessage) {
this.pendingStatus = processedStatus;
} else {
Expand Down Expand Up @@ -170,4 +170,4 @@ export interface Call {
halfClose(): void;
getCallNumber(): number;
setCredentials(credentials: CallCredentials): void;
}
}
4 changes: 2 additions & 2 deletions packages/grpc-js/src/call-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
let nextCallNumber = 0;

export function getNextCallNumber() {
return nextCallNumber++;
}
return nextCallNumber++;
}
25 changes: 15 additions & 10 deletions packages/grpc-js/src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,29 @@ export type ClientWritableStream<RequestType> = {
/**
* A type representing the return value of a bidirectional stream method call.
*/
export type ClientDuplexStream<
RequestType,
ResponseType
> = ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;
export type ClientDuplexStream<RequestType, ResponseType> =
ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;

/**
* Construct a ServiceError from a StatusObject. This function exists primarily
* as an attempt to make the error stack trace clearly communicate that the
* error is not necessarily a problem in gRPC itself.
* @param status
*/
export function callErrorFromStatus(status: StatusObject, callerStack: string): ServiceError {
export function callErrorFromStatus(
status: StatusObject,
callerStack: string
): ServiceError {
const message = `${status.code} ${Status[status.code]}: ${status.details}`;
const error = new Error(message);
const stack = `${error.stack}\nfor call at\n${callerStack}`;
return Object.assign(new Error(message), status, {stack});
return Object.assign(new Error(message), status, { stack });
}

export class ClientUnaryCallImpl
extends EventEmitter
implements ClientUnaryCall {
implements ClientUnaryCall
{
public call?: InterceptingCallInterface;
constructor() {
super();
Expand All @@ -102,7 +104,8 @@ export class ClientUnaryCallImpl

export class ClientReadableStreamImpl<ResponseType>
extends Readable
implements ClientReadableStream<ResponseType> {
implements ClientReadableStream<ResponseType>
{
public call?: InterceptingCallInterface;
constructor(readonly deserialize: (chunk: Buffer) => ResponseType) {
super({ objectMode: true });
Expand All @@ -123,7 +126,8 @@ export class ClientReadableStreamImpl<ResponseType>

export class ClientWritableStreamImpl<RequestType>
extends Writable
implements ClientWritableStream<RequestType> {
implements ClientWritableStream<RequestType>
{
public call?: InterceptingCallInterface;
constructor(readonly serialize: (value: RequestType) => Buffer) {
super({ objectMode: true });
Expand Down Expand Up @@ -156,7 +160,8 @@ export class ClientWritableStreamImpl<RequestType>

export class ClientDuplexStreamImpl<RequestType, ResponseType>
extends Duplex
implements ClientDuplexStream<RequestType, ResponseType> {
implements ClientDuplexStream<RequestType, ResponseType>
{
public call?: InterceptingCallInterface;
constructor(
readonly serialize: (value: RequestType) => Buffer,
Expand Down
46 changes: 24 additions & 22 deletions packages/grpc-js/src/channel-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
*
*/

import { ConnectionOptions, createSecureContext, PeerCertificate, SecureContext } from 'tls';
import {
ConnectionOptions,
createSecureContext,
PeerCertificate,
SecureContext,
} from 'tls';

import { CallCredentials } from './call-credentials';
import { CIPHER_SUITES, getDefaultRootsData } from './tls-helpers';
Expand Down Expand Up @@ -137,10 +142,7 @@ export abstract class ChannelCredentials {
cert: certChain ?? undefined,
ciphers: CIPHER_SUITES,
});
return new SecureChannelCredentialsImpl(
secureContext,
verifyOptions ?? {}
);
return new SecureChannelCredentialsImpl(secureContext, verifyOptions ?? {});
}

/**
Expand All @@ -153,11 +155,11 @@ export abstract class ChannelCredentials {
* @param secureContext The return value of tls.createSecureContext()
* @param verifyOptions Additional options to modify certificate verification
*/
static createFromSecureContext(secureContext: SecureContext, verifyOptions?: VerifyOptions): ChannelCredentials {
return new SecureChannelCredentialsImpl(
secureContext,
verifyOptions ?? {}
)
static createFromSecureContext(
secureContext: SecureContext,
verifyOptions?: VerifyOptions
): ChannelCredentials {
return new SecureChannelCredentialsImpl(secureContext, verifyOptions ?? {});
}

/**
Expand Down Expand Up @@ -196,19 +198,19 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
private verifyOptions: VerifyOptions
) {
super();
this.connectionOptions = {
secureContext
this.connectionOptions = {
secureContext,
};
// Node asserts that this option is a function, so we cannot pass undefined
if (verifyOptions?.checkServerIdentity) {
this.connectionOptions.checkServerIdentity = verifyOptions.checkServerIdentity;
this.connectionOptions.checkServerIdentity =
verifyOptions.checkServerIdentity;
}
}

compose(callCredentials: CallCredentials): ChannelCredentials {
const combinedCallCredentials = this.callCredentials.compose(
callCredentials
);
const combinedCallCredentials =
this.callCredentials.compose(callCredentials);
return new ComposedChannelCredentialsImpl(this, combinedCallCredentials);
}

Expand All @@ -225,9 +227,10 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
}
if (other instanceof SecureChannelCredentialsImpl) {
return (
this.secureContext === other.secureContext &&
this.verifyOptions.checkServerIdentity === other.verifyOptions.checkServerIdentity
);
this.secureContext === other.secureContext &&
this.verifyOptions.checkServerIdentity ===
other.verifyOptions.checkServerIdentity
);
} else {
return false;
}
Expand All @@ -242,9 +245,8 @@ class ComposedChannelCredentialsImpl extends ChannelCredentials {
super(callCreds);
}
compose(callCredentials: CallCredentials) {
const combinedCallCredentials = this.callCredentials.compose(
callCredentials
);
const combinedCallCredentials =
this.callCredentials.compose(callCredentials);
return new ComposedChannelCredentialsImpl(
this.channelCredentials,
combinedCallCredentials
Expand Down
17 changes: 13 additions & 4 deletions packages/grpc-js/src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export interface Channel {
}

export class ChannelImplementation implements Channel {

private internalChannel: InternalChannel;

constructor(
Expand Down Expand Up @@ -133,13 +132,17 @@ export class ChannelImplementation implements Channel {
deadline: Date | number,
callback: (error?: Error) => void
): void {
this.internalChannel.watchConnectivityState(currentState, deadline, callback);
this.internalChannel.watchConnectivityState(
currentState,
deadline,
callback
);
}

/**
* Get the channelz reference object for this channel. The returned value is
* garbage if channelz is disabled for this channel.
* @returns
* @returns
*/
getChannelzRef() {
return this.internalChannel.getChannelzRef();
Expand All @@ -160,6 +163,12 @@ export class ChannelImplementation implements Channel {
'Channel#createCall: deadline must be a number or Date'
);
}
return this.internalChannel.createCall(method, deadline, host, parentCall, propagateFlags);
return this.internalChannel.createCall(
method,
deadline,
host,
parentCall,
propagateFlags
);
}
}
Loading

0 comments on commit cd24d69

Please sign in to comment.