Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-sachs committed Oct 25, 2023
1 parent 047212a commit fa03a64
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
18 changes: 9 additions & 9 deletions packages/connect/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -169,7 +169,7 @@ export function createHandlerContext(
const abortController = createLinkedAbortController(
deadline.signal,
init.requestSignal,
init.shutdownSignal
init.shutdownSignal,
);
return {
...init,
Expand All @@ -191,7 +191,7 @@ export function createHandlerContext(
*/
export type UnaryImpl<I extends Message<I>, O extends Message<O>> = (
request: I,
context: HandlerContext
context: HandlerContext,
) => Promise<O | PartialMessage<O>> | O | PartialMessage<O>;

/**
Expand All @@ -200,7 +200,7 @@ export type UnaryImpl<I extends Message<I>, O extends Message<O>> = (
*/
export type ClientStreamingImpl<I extends Message<I>, O extends Message<O>> = (
requests: AsyncIterable<I>,
context: HandlerContext
context: HandlerContext,
) => Promise<O | PartialMessage<O>>;

/**
Expand All @@ -209,7 +209,7 @@ export type ClientStreamingImpl<I extends Message<I>, O extends Message<O>> = (
*/
export type ServerStreamingImpl<I extends Message<I>, O extends Message<O>> = (
request: I,
context: HandlerContext
context: HandlerContext,
) => AsyncIterable<O | PartialMessage<O>>;

/**
Expand All @@ -218,7 +218,7 @@ export type ServerStreamingImpl<I extends Message<I>, O extends Message<O>> = (
*/
export type BiDiStreamingImpl<I extends Message<I>, O extends Message<O>> = (
requests: AsyncIterable<I>,
context: HandlerContext
context: HandlerContext,
) => AsyncIterable<O | PartialMessage<O>>;

// prettier-ignore
Expand Down Expand Up @@ -254,12 +254,12 @@ export type ServiceImplSpec = {
*/
export function createMethodImplSpec<M extends MethodType>(
method: M,
impl: MethodImpl<M>
impl: MethodImpl<M>,
): MethodImplSpec;
export function createMethodImplSpec<M extends MethodInfo>(
service: ServiceType,
method: M,
impl: MethodImpl<M>
impl: MethodImpl<M>,
): MethodImplSpec;
export function createMethodImplSpec<
M extends MethodInfo,
Expand Down Expand Up @@ -293,7 +293,7 @@ export function createMethodImplSpec<
*/
export function createServiceImplSpec<T extends ServiceType>(
service: T,
impl: Partial<ServiceImpl<T>>
impl: Partial<ServiceImpl<T>>,
): ServiceImplSpec {
const s: ServiceImplSpec = { service, methods: {} };
for (const [localName, methodInfo] of Object.entries(service.methods)) {
Expand Down
14 changes: 14 additions & 0 deletions packages/connect/src/method-type.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 6 additions & 6 deletions packages/connect/src/router-transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand All @@ -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",
);
}
});
Expand All @@ -139,7 +139,7 @@ describe("createRoutesTransport", function () {
kind: "scalar",
T: 9 /* ScalarType.STRING */,
},
]
],
);
interface SayResponse extends Message<SayResponse> {
sentence: string;
Expand All @@ -153,7 +153,7 @@ describe("createRoutesTransport", function () {
kind: "scalar",
T: 9 /* ScalarType.STRING */,
},
]
],
);
const ElizaService = {
typeName: "connectrpc.eliza.v1.ElizaService",
Expand Down Expand Up @@ -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({
Expand All @@ -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/,
);
});
});
Expand Down
32 changes: 16 additions & 16 deletions packages/connect/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ export interface ConnectRouter {
service<T extends ServiceType>(
service: T,
implementation: Partial<ServiceImpl<T>>,
options?: Partial<UniversalHandlerOptions>
options?: Partial<UniversalHandlerOptions>,
): this;
rpc<M extends MethodInfo>(
service: ServiceType,
method: M,
impl: MethodImpl<M>,
options?: Partial<UniversalHandlerOptions>
options?: Partial<UniversalHandlerOptions>,
): this;
rpc<M extends MethodType>(
method: M,
impl: MethodImpl<M>,
options?: Partial<UniversalHandlerOptions>
options?: Partial<UniversalHandlerOptions>,
): this;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ export interface ConnectRouterOptions extends Partial<UniversalHandlerOptions> {
* Create a new ConnectRouter.
*/
export function createConnectRouter(
routerOptions?: ConnectRouterOptions
routerOptions?: ConnectRouterOptions,
): ConnectRouter {
const base = whichProtocols(routerOptions);
const handlers: UniversalHandler[] = [];
Expand All @@ -133,8 +133,8 @@ export function createConnectRouter(
handlers.push(
...createUniversalServiceHandlers(
createServiceImplSpec(service, implementation),
protocols
)
protocols,
),
);
return this;
},
Expand All @@ -144,7 +144,7 @@ export function createConnectRouter(
implementationOrOptions?:
| MethodImpl<MethodInfo<AnyMessage>>
| Partial<UniversalHandlerOptions>,
options?: Partial<UniversalHandlerOptions>
options?: Partial<UniversalHandlerOptions>,
) {
if ("typeName" in serviceOrMethod) {
const { protocols } = whichProtocols(options, base);
Expand All @@ -154,24 +154,24 @@ export function createConnectRouter(
createMethodImplSpec(
serviceOrMethod,
methodOrImpl as MethodInfo<AnyMessage>,
implementationOrOptions as MethodImpl<MethodInfo<AnyMessage>>
implementationOrOptions as MethodImpl<MethodInfo<AnyMessage>>,
),
protocols
)
protocols,
),
);
}
const { protocols } = whichProtocols(
implementationOrOptions as Partial<UniversalHandlerOptions>,
base
base,
);
handlers.push(
createUniversalMethodHandler(
createMethodImplSpec(
serviceOrMethod as MethodType,
methodOrImpl as MethodImpl<MethodType<AnyMessage>>
methodOrImpl as MethodImpl<MethodType<AnyMessage>>,
),
protocols
)
protocols,
),
);
return this;
},
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fa03a64

Please sign in to comment.