Skip to content

Commit 427bff4

Browse files
authored
feat(standard-server)!: remove unused raw (#298)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Streamlined the handling of request and response data by removing redundant properties. - **Tests** - Updated tests to align with the simplified data structures, ensuring consistent behavior. - **Chores** - Refined configuration settings for improved compilation and project maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 173b319 commit 427bff4

File tree

13 files changed

+5
-43
lines changed

13 files changed

+5
-43
lines changed

packages/client/src/adapters/standard/rpc-link-codec.test.ts

-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ describe('standardRPCLinkCodec', () => {
135135

136136
const output = await codec.decode({
137137
status: 200,
138-
raw: { adapter: 'unknown' },
139138
headers: {},
140139
body: () => Promise.resolve(serialized),
141140
})
@@ -157,7 +156,6 @@ describe('standardRPCLinkCodec', () => {
157156

158157
await expect(codec.decode({
159158
status: 499,
160-
raw: { adapter: 'unknown' },
161159
headers: {},
162160
body: () => Promise.resolve(serialized),
163161
})).rejects.toSatisfy((e) => {
@@ -173,7 +171,6 @@ describe('standardRPCLinkCodec', () => {
173171
it('error: Cannot parse response body', async () => {
174172
await expect(codec.decode({
175173
status: 200,
176-
raw: { adapter: 'unknown' },
177174
headers: {},
178175
body: () => {
179176
throw new Error('test')
@@ -186,7 +183,6 @@ describe('standardRPCLinkCodec', () => {
186183
it('error: Invalid RPC response format.', async () => {
187184
await expect(codec.decode({
188185
status: 200,
189-
raw: { adapter: 'unknown' },
190186
headers: {},
191187
body: () => Promise.resolve({ meta: 123 }),
192188
})).rejects.toThrow('Invalid RPC response format.')
@@ -209,7 +205,6 @@ describe('standardRPCLinkCodec', () => {
209205

210206
await expect(codec.decode({
211207
status: 403,
212-
raw: { adapter: 'unknown' },
213208
headers: {},
214209
body: () => Promise.resolve(serialized),
215210
})).rejects.toThrow('Invalid RPC error response format.')

packages/openapi/src/adapters/standard/openapi-codec.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ describe('standardOpenAPICodec', () => {
2424
url.searchParams.append('data', JSON.stringify('__data__'))
2525

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

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

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

107104
const input = await codec.decode({
108-
raw: { adapter: 'unknown' },
109105
method: 'POST',
110106
url,
111107
body: vi.fn(async () => serialized),

packages/server/src/adapters/node/handler.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe('nodeHttpHandlerOptions', async () => {
3737
}).get('/api/v1')
3838

3939
const standardRequest = {
40-
raw: { adapter: 'unknown' },
4140
method: 'POST',
4241
url: new URL('https://example.com/api/v1/users/1'),
4342
headers: {

packages/server/src/adapters/standard/handler.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe('standardHandler', () => {
3535
const signal = controller.signal
3636

3737
const request = {
38-
raw: { adapter: '' },
3938
method: 'GET',
4039
headers: {
4140
Accept: 'application/json',
@@ -343,7 +342,6 @@ describe('standardHandler', () => {
343342

344343
it('should check prefix first', async () => {
345344
const result = await handler.handle({
346-
raw: { adapter: '' },
347345
method: 'GET',
348346
headers: {
349347
Accept: 'application/json',

packages/server/src/adapters/standard/rpc-codec.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe('standardRPCCodec', () => {
2222
url.searchParams.append('data', JSON.stringify({ json: '__json__', meta: '__meta__' }))
2323

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

4746
const input = await codec.decode({
48-
raw: { adapter: '' },
4947
method: 'POST',
5048
url: new URL('http://localhost/api/v1?data=data'),
5149
body: vi.fn(async () => serialized),

packages/standard-server-fetch/src/request.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ describe('toStandardLazyRequest', () => {
2828
expect(standardRequest.url).toEqual(new URL('https://example.com'))
2929
expect(standardRequest.method).toBe('POST')
3030
expect(standardRequest.signal).toBe(request.signal)
31-
expect(standardRequest.raw).toEqual({ adapter: 'fetch', request })
3231
expect(standardRequest.headers).toEqual(toStandardHeadersSpy.mock.results[0]!.value)
3332
expect(standardRequest.body()).toBe(toStandardBodySpy.mock.results[0]!.value)
3433

packages/standard-server-fetch/src/request.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ import { toFetchBody, toStandardBody } from './body'
55
import { toFetchHeaders, toStandardHeaders } from './headers'
66

77
export function toStandardLazyRequest(request: Request): StandardLazyRequest {
8-
const raw = { adapter: 'fetch', request }
9-
108
return {
11-
raw,
129
url: new URL(request.url),
1310
signal: request.signal,
1411
method: request.method,
15-
body: once(() => toStandardBody(raw.request)),
12+
body: once(() => toStandardBody(request)),
1613
get headers() {
17-
const headers = toStandardHeaders(raw.request.headers)
14+
const headers = toStandardHeaders(request.headers)
1815
Object.defineProperty(this, 'headers', { value: headers, writable: true })
1916
return headers
2017
},

packages/standard-server-fetch/src/response.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ describe('toStandardLazyResponse', () => {
8787

8888
expect(lazyResponse.status).toBe(206)
8989

90-
expect(lazyResponse.raw).toEqual({ adapter: 'fetch', response })
9190
expect(lazyResponse.headers).toBe(toStandardHeadersSpy.mock.results[0]!.value)
9291
expect(toStandardHeadersSpy).toBeCalledTimes(1)
9392
expect(toStandardHeadersSpy).toBeCalledWith(response.headers)

packages/standard-server-fetch/src/response.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ export function toFetchResponse(
1616
}
1717

1818
export function toStandardLazyResponse(response: Response): StandardLazyResponse {
19-
const raw = { adapter: 'fetch', response }
20-
2119
return {
22-
raw,
23-
body: once(() => toStandardBody(raw.response)),
20+
body: once(() => toStandardBody(response)),
2421
status: response.status,
2522
get headers() {
26-
const headers = toStandardHeaders(raw.response.headers)
23+
const headers = toStandardHeaders(response.headers)
2724
Object.defineProperty(this, 'headers', { value: headers, writable: true })
2825
return headers
2926
},

packages/standard-server-node/src/request.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('toStandardLazyRequest', () => {
1717

1818
await request(async (req: IncomingMessage, res: ServerResponse) => {
1919
standardRequest = toStandardLazyRequest(req, res)
20-
expect(standardRequest.raw).toEqual({ adapter: 'node', request: req, response: res })
2120
expect(toStandardBodySpy).not.toBeCalled()
2221
await standardRequest.body() // ensure body is load before sending response
2322
expect(standardRequest.headers).toBe(req.headers)

packages/standard-server-node/src/request.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ export function toStandardLazyRequest(
88
req: NodeHttpRequest,
99
res: NodeHttpResponse,
1010
): StandardLazyRequest {
11-
const raw = { adapter: 'node', request: req, response: res }
1211
const method = req.method ?? 'GET'
1312

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

1817
return {
19-
raw,
2018
method,
2119
url,
2220
headers: req.headers,
23-
body: once(() => toStandardBody(raw.request)),
21+
body: once(() => toStandardBody(req)),
2422
signal: toAbortSignal(res),
2523
}
2624
}

packages/standard-server/src/types.ts

-10
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ export interface StandardRequest {
2424
}
2525

2626
export interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
27-
/**
28-
* Can be { adapter: 'fetch', request: Request } | { adapter: 'node', request: IncomingMessage, response: ServerResponse }
29-
*/
30-
raw: Record<string, unknown> & { adapter: string }
31-
3227
/**
3328
* The body has been parsed based on the content-type header.
3429
* This method can safely call multiple times (cached).
@@ -46,11 +41,6 @@ export interface StandardResponse {
4641
}
4742

4843
export interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
49-
/**
50-
* Can be { adapter: 'fetch', response: Response }
51-
*/
52-
raw: Record<string, unknown> & { adapter: string }
53-
5444
/**
5545
* The body has been parsed based on the content-type header.
5646
* This method can safely call multiple times (cached).

packages/zod/tsconfig.json

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"extends": "../../tsconfig.lib.json",
3-
"compilerOptions": {
4-
"rootDir": "src"
5-
},
63
"references": [
74
{ "path": "../openapi" },
85
{ "path": "../contract" },

0 commit comments

Comments
 (0)