Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: some exports #4106

Merged
merged 4 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/server/src/adapters/aws-lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import type {
} from 'aws-lambda';
import { TRPCError } from '../..';
import { AnyRouter, inferRouterContext } from '../../core';
import { resolveHTTPResponse } from '../../http';
import { HTTPRequest } from '../../http/internals/types';
import type { HTTPResponse } from '../../http/internals/types';
import { HTTPRequest, resolveHTTPResponse } from '../../http';
import { HTTPResponse } from '../../http/internals/types';
import {
APIGatewayEvent,
APIGatewayResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { FastifyReply, FastifyRequest } from 'fastify';
import { AnyRouter, inferRouterContext } from '../../core';
import {
HTTPBaseHandlerOptions,
HTTPRequest,
} from '../../http/internals/types';
import { HTTPBaseHandlerOptions, HTTPRequest } from '../../http';
import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
import { NodeHTTPCreateContextOption } from '../node-http';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnyRouter } from '../../core';
import { HTTPRequest } from '../../http/internals/types';
import { HTTPRequest } from '../../http';
import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
import { FetchHandlerOptions } from './types';

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/fetch/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnyRouter, inferRouterContext } from '../../core';
import { HTTPBaseHandlerOptions } from '../../http/internals/types';
import { HTTPBaseHandlerOptions } from '../../http';

export type FetchCreateContextFnOptions = {
req: Request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { AnyRouter } from '../../core';
import { inferRouterContext } from '../../core/types';
import { HTTPRequest } from '../../http/internals/types';
import { HTTPRequest } from '../../http';
import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
import { getPostBody } from './internals/getPostBody';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/node-http/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IncomingMessage, ServerResponse } from 'http';
import { AnyRouter, inferRouterContext } from '../../core';
import { HTTPBaseHandlerOptions } from '../../http/internals/types';
import { HTTPBaseHandlerOptions } from '../../http';
import { MaybePromise } from '../../types';

interface ParsedQs {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/adapters/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '../core';
import { TRPCError, getTRPCErrorFromUnknown } from '../error/TRPCError';
import { getCauseFromUnknown } from '../error/utils';
import { transformTRPCResponse } from '../internals/transformTRPCResponse';
import { BaseHandlerOptions } from '../internals/types';
import { Unsubscribable, isObservable } from '../observable';
import {
Expand All @@ -17,6 +16,7 @@ import {
TRPCReconnectNotification,
TRPCResponseMessage,
} from '../rpc';
import { transformTRPCResponse } from '../shared/transformTRPCResponse';
import { CombinedDataTransformer } from '../transformer';
import {
NodeHTTPCreateContextFnOptions,
Expand Down Expand Up @@ -62,7 +62,7 @@ function assertIsJSONRPC2OrUndefined(
throw new Error('Must be JSONRPC 2.0');
}
}
function parseMessage(
export function parseMessage(
obj: unknown,
transformer: CombinedDataTransformer,
): TRPCClientOutgoingMessage {
Expand Down
21 changes: 0 additions & 21 deletions packages/server/src/http/internals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
inferRouterError,
} from '../../core';
import { TRPCError } from '../../error/TRPCError';
import { BaseHandlerOptions } from '../../internals/types';
import { TRPCResponse } from '../../rpc';
import { Dict } from '../../types';
import { ResponseMeta } from '../types';
Expand All @@ -18,13 +17,6 @@ export interface HTTPResponse {
body?: string;
}

export interface HTTPRequest {
method: string;
query: URLSearchParams;
headers: HTTPHeaders;
body: unknown;
}

/**
* @internal
*/
Expand All @@ -38,16 +30,3 @@ export type ResponseMetaFn<TRouter extends AnyRouter> = (opts: {
type: ProcedureType | 'unknown';
errors: TRPCError[];
}) => ResponseMeta;

/**
* Base interface for anything using HTTP
*/
export interface HTTPBaseHandlerOptions<TRouter extends AnyRouter, TRequest>
extends BaseHandlerOptions<TRouter, TRequest> {
/**
* Add handler to be called before response is sent to the user
* Useful for setting cache headers
* @link https://trpc.io/docs/caching
*/
responseMeta?: ResponseMetaFn<TRouter>;
}
10 changes: 3 additions & 7 deletions packages/server/src/http/resolveHTTPResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ import {
} from '../core';
import { TRPCError, getTRPCErrorFromUnknown } from '../error/TRPCError';
import { getCauseFromUnknown } from '../error/utils';
import { transformTRPCResponse } from '../internals/transformTRPCResponse';
import { TRPCResponse } from '../rpc';
import { transformTRPCResponse } from '../shared/transformTRPCResponse';
import { Maybe } from '../types';
import { getHTTPStatusCode } from './getHTTPStatusCode';
import {
HTTPBaseHandlerOptions,
HTTPHeaders,
HTTPRequest,
HTTPResponse,
} from './internals/types';
import { HTTPHeaders, HTTPResponse } from './internals/types';
import { HTTPBaseHandlerOptions, HTTPRequest } from './types';

const HTTP_METHOD_PROCEDURE_TYPE_MAP: Record<
string,
Expand Down
24 changes: 24 additions & 0 deletions packages/server/src/http/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
import { AnyRouter } from '../core';
import { BaseHandlerOptions } from '../internals/types';
import { HTTPHeaders, ResponseMetaFn } from './internals/types';

export interface HTTPRequest {
method: string;
query: URLSearchParams;
headers: HTTPHeaders;
body: unknown;
}

/**
* Base interface for anything using HTTP
*/
export interface HTTPBaseHandlerOptions<TRouter extends AnyRouter, TRequest>
extends BaseHandlerOptions<TRouter, TRequest> {
/**
* Add handler to be called before response is sent to the user
* Useful for setting cache headers
* @link https://trpc.io/docs/caching
*/
responseMeta?: ResponseMetaFn<TRouter>;
}

export interface ResponseMeta {
status?: number;
headers?: Record<string, string>;
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './createProxy';
export * from './jsonify';
export * from './transformTRPCResponse';

// For `.d.ts` files https://github.com/trpc/trpc/issues/3943
export type { SerializeObject } from './internal/serialize';