From fa03a64060090f55d6531bd5e95da424fc453632 Mon Sep 17 00:00:00 2001 From: Paul Sachs Date: Wed, 25 Oct 2023 11:01:42 -0400 Subject: [PATCH] Format code --- packages/connect/src/implementation.ts | 18 +++++------ packages/connect/src/method-type.ts | 14 ++++++++ packages/connect/src/router-transport.spec.ts | 12 +++---- packages/connect/src/router.ts | 32 +++++++++---------- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/packages/connect/src/implementation.ts b/packages/connect/src/implementation.ts index 7bed45f2b..6ac262d74 100644 --- a/packages/connect/src/implementation.ts +++ b/packages/connect/src/implementation.ts @@ -156,7 +156,7 @@ interface HandlerContextController extends HandlerContext { * a context. */ export function createHandlerContext( - init: HandlerContextInit + init: HandlerContextInit, ): HandlerContextController { let timeoutMs: () => undefined | number; if (init.timeoutMs !== undefined) { @@ -169,7 +169,7 @@ export function createHandlerContext( const abortController = createLinkedAbortController( deadline.signal, init.requestSignal, - init.shutdownSignal + init.shutdownSignal, ); return { ...init, @@ -191,7 +191,7 @@ export function createHandlerContext( */ export type UnaryImpl, O extends Message> = ( request: I, - context: HandlerContext + context: HandlerContext, ) => Promise> | O | PartialMessage; /** @@ -200,7 +200,7 @@ export type UnaryImpl, O extends Message> = ( */ export type ClientStreamingImpl, O extends Message> = ( requests: AsyncIterable, - context: HandlerContext + context: HandlerContext, ) => Promise>; /** @@ -209,7 +209,7 @@ export type ClientStreamingImpl, O extends Message> = ( */ export type ServerStreamingImpl, O extends Message> = ( request: I, - context: HandlerContext + context: HandlerContext, ) => AsyncIterable>; /** @@ -218,7 +218,7 @@ export type ServerStreamingImpl, O extends Message> = ( */ export type BiDiStreamingImpl, O extends Message> = ( requests: AsyncIterable, - context: HandlerContext + context: HandlerContext, ) => AsyncIterable>; // prettier-ignore @@ -254,12 +254,12 @@ export type ServiceImplSpec = { */ export function createMethodImplSpec( method: M, - impl: MethodImpl + impl: MethodImpl, ): MethodImplSpec; export function createMethodImplSpec( service: ServiceType, method: M, - impl: MethodImpl + impl: MethodImpl, ): MethodImplSpec; export function createMethodImplSpec< M extends MethodInfo, @@ -293,7 +293,7 @@ export function createMethodImplSpec< */ export function createServiceImplSpec( service: T, - impl: Partial> + impl: Partial>, ): ServiceImplSpec { const s: ServiceImplSpec = { service, methods: {} }; for (const [localName, methodInfo] of Object.entries(service.methods)) { diff --git a/packages/connect/src/method-type.ts b/packages/connect/src/method-type.ts index 777dd05a1..8d111ff9b 100644 --- a/packages/connect/src/method-type.ts +++ b/packages/connect/src/method-type.ts @@ -1,3 +1,17 @@ +// Copyright 2021-2023 The Connect Authors +// +// 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. + import type { AnyMessage, Message, diff --git a/packages/connect/src/router-transport.spec.ts b/packages/connect/src/router-transport.spec.ts index 1af579c0d..5e0e6f9fd 100644 --- a/packages/connect/src/router-transport.spec.ts +++ b/packages/connect/src/router-transport.spec.ts @@ -97,7 +97,7 @@ describe("createRoutesTransport", function () { }); it("should work for client steam", async function () { const res = await client.client( - createAsyncIterable([{ value: 12 }, { value: 13 }]) + createAsyncIterable([{ value: 12 }, { value: 13 }]), ); expect(res.value).toBe("13"); }); @@ -122,7 +122,7 @@ describe("createRoutesTransport", function () { } catch (e) { expect(e).toBeInstanceOf(ConnectError); expect(ConnectError.from(e).message).toBe( - "[unimplemented] RouterHttpClient: no handler registered for /TestService/Unary" + "[unimplemented] RouterHttpClient: no handler registered for /TestService/Unary", ); } }); @@ -139,7 +139,7 @@ describe("createRoutesTransport", function () { kind: "scalar", T: 9 /* ScalarType.STRING */, }, - ] + ], ); interface SayResponse extends Message { sentence: string; @@ -153,7 +153,7 @@ describe("createRoutesTransport", function () { kind: "scalar", T: 9 /* ScalarType.STRING */, }, - ] + ], ); const ElizaService = { typeName: "connectrpc.eliza.v1.ElizaService", @@ -205,7 +205,7 @@ describe("createRoutesTransport", function () { if (sentences.length > 3) { throw new ConnectError( "I have no words anymore.", - Code.ResourceExhausted + Code.ResourceExhausted, ); } return new SayResponse({ @@ -220,7 +220,7 @@ describe("createRoutesTransport", function () { await client.say({ sentence: "2" }); await client.say({ sentence: "3" }); await expectAsync(client.say({ sentence: "4" })).toBeRejectedWithError( - /I have no words anymore/ + /I have no words anymore/, ); }); }); diff --git a/packages/connect/src/router.ts b/packages/connect/src/router.ts index 8d9ba684e..e5f835e3f 100644 --- a/packages/connect/src/router.ts +++ b/packages/connect/src/router.ts @@ -56,18 +56,18 @@ export interface ConnectRouter { service( service: T, implementation: Partial>, - options?: Partial + options?: Partial, ): this; rpc( service: ServiceType, method: M, impl: MethodImpl, - options?: Partial + options?: Partial, ): this; rpc( method: M, impl: MethodImpl, - options?: Partial + options?: Partial, ): this; } @@ -121,7 +121,7 @@ export interface ConnectRouterOptions extends Partial { * Create a new ConnectRouter. */ export function createConnectRouter( - routerOptions?: ConnectRouterOptions + routerOptions?: ConnectRouterOptions, ): ConnectRouter { const base = whichProtocols(routerOptions); const handlers: UniversalHandler[] = []; @@ -133,8 +133,8 @@ export function createConnectRouter( handlers.push( ...createUniversalServiceHandlers( createServiceImplSpec(service, implementation), - protocols - ) + protocols, + ), ); return this; }, @@ -144,7 +144,7 @@ export function createConnectRouter( implementationOrOptions?: | MethodImpl> | Partial, - options?: Partial + options?: Partial, ) { if ("typeName" in serviceOrMethod) { const { protocols } = whichProtocols(options, base); @@ -154,24 +154,24 @@ export function createConnectRouter( createMethodImplSpec( serviceOrMethod, methodOrImpl as MethodInfo, - implementationOrOptions as MethodImpl> + implementationOrOptions as MethodImpl>, ), - protocols - ) + protocols, + ), ); } const { protocols } = whichProtocols( implementationOrOptions as Partial, - base + base, ); handlers.push( createUniversalMethodHandler( createMethodImplSpec( serviceOrMethod as MethodType, - methodOrImpl as MethodImpl> + methodOrImpl as MethodImpl>, ), - protocols - ) + protocols, + ), ); return this; }, @@ -180,7 +180,7 @@ export function createConnectRouter( function whichProtocols( options: ConnectRouterOptions | undefined, - base?: { options: ConnectRouterOptions; protocols: ProtocolHandlerFactory[] } + base?: { options: ConnectRouterOptions; protocols: ProtocolHandlerFactory[] }, ): { options: ConnectRouterOptions; protocols: ProtocolHandlerFactory[] } { if (base && !options) { return base; @@ -208,7 +208,7 @@ function whichProtocols( if (protocols.length === 0) { throw new ConnectError( "cannot create handler, all protocols are disabled", - Code.InvalidArgument + Code.InvalidArgument, ); } return {