Skip to content

Commit

Permalink
Remove null
Browse files Browse the repository at this point in the history
  • Loading branch information
srikrsna-buf committed Oct 2, 2023
1 parent 842a57f commit 6b2eb59
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/connect-web-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ it like a web server would usually do.

| code generator | bundle size | minified | compressed |
|----------------|-------------------:|-----------------------:|---------------------:|
| connect | 113,714 b | 49,970 b | 13,462 b |
| connect | 113,658 b | 49,964 b | 13,487 b |
| grpc-web | 414,071 b | 300,352 b | 53,255 b |
12 changes: 8 additions & 4 deletions packages/connect-web/src/connect-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function createConnectTransport(
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
message: PartialMessage<I>,
): Promise<UnaryResponse<I, O>> {
Expand All @@ -152,7 +152,9 @@ export function createConnectTransport(
timeoutMs =
timeoutMs === undefined
? options.defaultTimeoutMs
: timeoutMs ?? undefined;
: timeoutMs <= 0
? undefined
: timeoutMs;
return await runUnaryCall<I, O>({
interceptors: options.interceptors,
signal,
Expand Down Expand Up @@ -237,7 +239,7 @@ export function createConnectTransport(
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: AsyncIterable<PartialMessage<I>>,
): Promise<StreamResponse<I, O>> {
Expand Down Expand Up @@ -294,7 +296,9 @@ export function createConnectTransport(
timeoutMs =
timeoutMs === undefined
? options.defaultTimeoutMs
: timeoutMs ?? undefined;
: timeoutMs <= 0
? undefined
: timeoutMs;
return await runStreamingCall<I, O>({
interceptors: options.interceptors,
timeoutMs,
Expand Down
12 changes: 8 additions & 4 deletions packages/connect-web/src/grpc-web-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function createGrpcWebTransport(
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: Headers,
message: PartialMessage<I>,
): Promise<UnaryResponse<I, O>> {
Expand All @@ -147,7 +147,9 @@ export function createGrpcWebTransport(
timeoutMs =
timeoutMs === undefined
? options.defaultTimeoutMs
: timeoutMs ?? undefined;
: timeoutMs <= 0
? undefined
: timeoutMs;
return await runUnaryCall<I, O>({
interceptors: options.interceptors,
signal,
Expand Down Expand Up @@ -228,7 +230,7 @@ export function createGrpcWebTransport(
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: AsyncIterable<PartialMessage<I>>,
): Promise<StreamResponse<I, O>> {
Expand Down Expand Up @@ -302,7 +304,9 @@ export function createGrpcWebTransport(
timeoutMs =
timeoutMs === undefined
? options.defaultTimeoutMs
: timeoutMs ?? undefined;
: timeoutMs <= 0
? undefined
: timeoutMs;
return runStreamingCall<I, O>({
interceptors: options.interceptors,
signal,
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/call-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export interface CallOptions {
/**
* Timeout in milliseconds.
*
* Set to `null` to disable the default timeout.
* Set to <= 0 to disable the default timeout.
*/
timeoutMs?: number | null;
timeoutMs?: number;

/**
* Custom headers to send with the request.
Expand Down
16 changes: 12 additions & 4 deletions packages/connect/src/protocol-connect/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
message: PartialMessage<I>,
): Promise<UnaryResponse<I, O>> {
Expand All @@ -77,7 +77,11 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt,
);
timeoutMs =
timeoutMs === undefined ? opt.defaultTimeoutMs : timeoutMs ?? undefined;
timeoutMs === undefined
? opt.defaultTimeoutMs
: timeoutMs <= 0
? undefined
: timeoutMs;
return await runUnaryCall<I, O>({
interceptors: opt.interceptors,
signal,
Expand Down Expand Up @@ -181,7 +185,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: AsyncIterable<PartialMessage<I>>,
): Promise<StreamResponse<I, O>> {
Expand All @@ -195,7 +199,11 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt.jsonOptions,
);
timeoutMs =
timeoutMs === undefined ? opt.defaultTimeoutMs : timeoutMs ?? undefined;
timeoutMs === undefined
? opt.defaultTimeoutMs
: timeoutMs <= 0
? undefined
: timeoutMs;
return runStreamingCall<I, O>({
interceptors: opt.interceptors,
signal,
Expand Down
16 changes: 12 additions & 4 deletions packages/connect/src/protocol-grpc-web/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
message: PartialMessage<I>,
): Promise<UnaryResponse<I, O>> {
Expand All @@ -71,7 +71,11 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt,
);
timeoutMs =
timeoutMs === undefined ? opt.defaultTimeoutMs : timeoutMs ?? undefined;
timeoutMs === undefined
? opt.defaultTimeoutMs
: timeoutMs <= 0
? undefined
: timeoutMs;
return await runUnaryCall<I, O>({
interceptors: opt.interceptors,
signal,
Expand Down Expand Up @@ -185,7 +189,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: AsyncIterable<PartialMessage<I>>,
): Promise<StreamResponse<I, O>> {
Expand All @@ -196,7 +200,11 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt,
);
timeoutMs =
timeoutMs === undefined ? opt.defaultTimeoutMs : timeoutMs ?? undefined;
timeoutMs === undefined
? opt.defaultTimeoutMs
: timeoutMs <= 0
? undefined
: timeoutMs;
return runStreamingCall<I, O>({
interceptors: opt.interceptors,
signal,
Expand Down
16 changes: 12 additions & 4 deletions packages/connect/src/protocol-grpc/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
message: PartialMessage<I>,
): Promise<UnaryResponse<I, O>> {
Expand All @@ -70,7 +70,11 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt,
);
timeoutMs =
timeoutMs === undefined ? opt.defaultTimeoutMs : timeoutMs ?? undefined;
timeoutMs === undefined
? opt.defaultTimeoutMs
: timeoutMs <= 0
? undefined
: timeoutMs;
return await runUnaryCall<I, O>({
interceptors: opt.interceptors,
signal,
Expand Down Expand Up @@ -161,7 +165,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: AsyncIterable<PartialMessage<I>>,
): Promise<StreamResponse<I, O>> {
Expand All @@ -172,7 +176,11 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt,
);
timeoutMs =
timeoutMs === undefined ? opt.defaultTimeoutMs : timeoutMs ?? undefined;
timeoutMs === undefined
? opt.defaultTimeoutMs
: timeoutMs <= 0
? undefined
: timeoutMs;
return runStreamingCall<I, O>({
interceptors: opt.interceptors,
signal,
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: PartialMessage<I>,
): Promise<UnaryResponse<I, O>>;
Expand All @@ -48,7 +48,7 @@ export interface Transport {
service: ServiceType,
method: MethodInfo<I, O>,
signal: AbortSignal | undefined,
timeoutMs: number | undefined | null,
timeoutMs: number | undefined,
header: HeadersInit | undefined,
input: AsyncIterable<PartialMessage<I>>,
): Promise<StreamResponse<I, O>>;
Expand Down

0 comments on commit 6b2eb59

Please sign in to comment.