Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 5 deletions packages/client/src/adapters/standard/rpc-link-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ describe('standardRPCLinkCodec', () => {

const output = await codec.decode({
status: 200,
raw: { adapter: 'unknown' },
headers: {},
body: () => Promise.resolve(serialized),
})
Expand All @@ -157,7 +156,6 @@ describe('standardRPCLinkCodec', () => {

await expect(codec.decode({
status: 499,
raw: { adapter: 'unknown' },
headers: {},
body: () => Promise.resolve(serialized),
})).rejects.toSatisfy((e) => {
Expand All @@ -173,7 +171,6 @@ describe('standardRPCLinkCodec', () => {
it('error: Cannot parse response body', async () => {
await expect(codec.decode({
status: 200,
raw: { adapter: 'unknown' },
headers: {},
body: () => {
throw new Error('test')
Expand All @@ -186,7 +183,6 @@ describe('standardRPCLinkCodec', () => {
it('error: Invalid RPC response format.', async () => {
await expect(codec.decode({
status: 200,
raw: { adapter: 'unknown' },
headers: {},
body: () => Promise.resolve({ meta: 123 }),
})).rejects.toThrow('Invalid RPC response format.')
Expand All @@ -209,7 +205,6 @@ describe('standardRPCLinkCodec', () => {

await expect(codec.decode({
status: 403,
raw: { adapter: 'unknown' },
headers: {},
body: () => Promise.resolve(serialized),
})).rejects.toThrow('Invalid RPC error response format.')
Expand Down
4 changes: 0 additions & 4 deletions packages/openapi/src/adapters/standard/openapi-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('standardOpenAPICodec', () => {
url.searchParams.append('data', JSON.stringify('__data__'))

const input = await codec.decode({
raw: { adapter: 'unknown' },
method: 'GET',
url,
body: vi.fn(),
Expand All @@ -44,7 +43,6 @@ describe('standardOpenAPICodec', () => {
serializer.deserialize.mockReturnValueOnce('__deserialized__')

const input = await codec.decode({
raw: { adapter: 'unknown' },
method: 'POST',
url: new URL('http://localhost/api/v1?data=data'),
body: vi.fn(async () => serialized),
Expand Down Expand Up @@ -74,7 +72,6 @@ describe('standardOpenAPICodec', () => {
url.searchParams.append('data', JSON.stringify('__data__'))

const input = await codec.decode({
raw: { adapter: 'unknown' },
method: 'GET',
url,
body: vi.fn(),
Expand Down Expand Up @@ -105,7 +102,6 @@ describe('standardOpenAPICodec', () => {
const url = new URL('http://localhost/api/v1?data=data')

const input = await codec.decode({
raw: { adapter: 'unknown' },
method: 'POST',
url,
body: vi.fn(async () => serialized),
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/adapters/node/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('nodeHttpHandlerOptions', async () => {
}).get('/api/v1')

const standardRequest = {
raw: { adapter: 'unknown' },
method: 'POST',
url: new URL('https://example.com/api/v1/users/1'),
headers: {
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/adapters/standard/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('standardHandler', () => {
const signal = controller.signal

const request = {
raw: { adapter: '' },
method: 'GET',
headers: {
Accept: 'application/json',
Expand Down Expand Up @@ -343,7 +342,6 @@ describe('standardHandler', () => {

it('should check prefix first', async () => {
const result = await handler.handle({
raw: { adapter: '' },
method: 'GET',
headers: {
Accept: 'application/json',
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/adapters/standard/rpc-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('standardRPCCodec', () => {
url.searchParams.append('data', JSON.stringify({ json: '__json__', meta: '__meta__' }))

const input = await codec.decode({
raw: { adapter: '' },
method: 'GET',
url,
body: vi.fn(),
Expand All @@ -45,7 +44,6 @@ describe('standardRPCCodec', () => {
serializer.deserialize.mockReturnValueOnce('__deserialized__')

const input = await codec.decode({
raw: { adapter: '' },
method: 'POST',
url: new URL('http://localhost/api/v1?data=data'),
body: vi.fn(async () => serialized),
Expand Down
1 change: 0 additions & 1 deletion packages/standard-server-fetch/src/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('toStandardLazyRequest', () => {
expect(standardRequest.url).toEqual(new URL('https://example.com'))
expect(standardRequest.method).toBe('POST')
expect(standardRequest.signal).toBe(request.signal)
expect(standardRequest.raw).toEqual({ adapter: 'fetch', request })
expect(standardRequest.headers).toEqual(toStandardHeadersSpy.mock.results[0]!.value)
expect(standardRequest.body()).toBe(toStandardBodySpy.mock.results[0]!.value)

Expand Down
7 changes: 2 additions & 5 deletions packages/standard-server-fetch/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import { toFetchBody, toStandardBody } from './body'
import { toFetchHeaders, toStandardHeaders } from './headers'

export function toStandardLazyRequest(request: Request): StandardLazyRequest {
const raw = { adapter: 'fetch', request }

return {
raw,
url: new URL(request.url),
signal: request.signal,
method: request.method,
body: once(() => toStandardBody(raw.request)),
body: once(() => toStandardBody(request)),
get headers() {
const headers = toStandardHeaders(raw.request.headers)
const headers = toStandardHeaders(request.headers)
Object.defineProperty(this, 'headers', { value: headers, writable: true })
return headers
},
Expand Down
1 change: 0 additions & 1 deletion packages/standard-server-fetch/src/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe('toStandardLazyResponse', () => {

expect(lazyResponse.status).toBe(206)

expect(lazyResponse.raw).toEqual({ adapter: 'fetch', response })
expect(lazyResponse.headers).toBe(toStandardHeadersSpy.mock.results[0]!.value)
expect(toStandardHeadersSpy).toBeCalledTimes(1)
expect(toStandardHeadersSpy).toBeCalledWith(response.headers)
Expand Down
7 changes: 2 additions & 5 deletions packages/standard-server-fetch/src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ export function toFetchResponse(
}

export function toStandardLazyResponse(response: Response): StandardLazyResponse {
const raw = { adapter: 'fetch', response }

return {
raw,
body: once(() => toStandardBody(raw.response)),
body: once(() => toStandardBody(response)),
status: response.status,
get headers() {
const headers = toStandardHeaders(raw.response.headers)
const headers = toStandardHeaders(response.headers)
Object.defineProperty(this, 'headers', { value: headers, writable: true })
return headers
},
Expand Down
1 change: 0 additions & 1 deletion packages/standard-server-node/src/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('toStandardLazyRequest', () => {

await request(async (req: IncomingMessage, res: ServerResponse) => {
standardRequest = toStandardLazyRequest(req, res)
expect(standardRequest.raw).toEqual({ adapter: 'node', request: req, response: res })
expect(toStandardBodySpy).not.toBeCalled()
await standardRequest.body() // ensure body is load before sending response
expect(standardRequest.headers).toBe(req.headers)
Expand Down
4 changes: 1 addition & 3 deletions packages/standard-server-node/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ export function toStandardLazyRequest(
req: NodeHttpRequest,
res: NodeHttpResponse,
): StandardLazyRequest {
const raw = { adapter: 'node', request: req, response: res }
const method = req.method ?? 'GET'

const protocol = ('encrypted' in req.socket && req.socket.encrypted ? 'https:' : 'http:')
const host = req.headers.host ?? 'localhost'
const url = new URL(req.originalUrl ?? req.url ?? '/', `${protocol}//${host}`)

return {
raw,
method,
url,
headers: req.headers,
body: once(() => toStandardBody(raw.request)),
body: once(() => toStandardBody(req)),
signal: toAbortSignal(res),
}
}
10 changes: 0 additions & 10 deletions packages/standard-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ export interface StandardRequest {
}

export interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
/**
* Can be { adapter: 'fetch', request: Request } | { adapter: 'node', request: IncomingMessage, response: ServerResponse }
*/
raw: Record<string, unknown> & { adapter: string }

/**
* The body has been parsed based on the content-type header.
* This method can safely call multiple times (cached).
Expand All @@ -46,11 +41,6 @@ export interface StandardResponse {
}

export interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
/**
* Can be { adapter: 'fetch', response: Response }
*/
raw: Record<string, unknown> & { adapter: string }

/**
* The body has been parsed based on the content-type header.
* This method can safely call multiple times (cached).
Expand Down
3 changes: 0 additions & 3 deletions packages/zod/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"rootDir": "src"
},
"references": [
{ "path": "../openapi" },
{ "path": "../contract" },
Expand Down