Skip to content

Commit 4c9dd72

Browse files
authored
feat(client)!: update standard link options (#338)
revert some options from "feat(client)!: update standard link interceptors and plugins options (#333)" <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved the ordering and handling of request parameters in the client API. - Enhanced overall consistency in how communication options are processed, ensuring smoother API interactions without affecting the end-user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 32a6de9 commit 4c9dd72

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

apps/content/docs/client/rpc-link.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface ClientContext {
7171

7272
const link = new RPCLink<ClientContext>({
7373
url: 'http://localhost:3000/rpc',
74-
method: ({ context, path }) => {
74+
method: ({ context }, path) => {
7575
if (context?.cache) {
7676
return 'GET'
7777
}

packages/client/src/adapters/fetch/link-fetch-client.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ describe('linkFetchClient', () => {
4141
expect(fetch).toBeCalledWith(
4242
toFetchRequestSpy.mock.results[0]!.value,
4343
{ redirect: 'manual' },
44-
{ ...options, path: ['example'], input: { body: true } },
44+
options,
45+
['example'],
46+
{ body: true },
4547
)
4648
})
4749
})

packages/client/src/adapters/fetch/link-fetch-client.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import type { StandardLazyResponse, StandardRequest } from '@orpc/standard-server'
22
import type { ToFetchRequestOptions } from '@orpc/standard-server-fetch'
33
import type { ClientContext, ClientOptions } from '../../types'
4-
import type { StandardLinkClient, StandardLinkInterceptorOptions } from '../standard'
4+
import type { StandardLinkClient } from '../standard'
55
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch'
66

77
export interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
88
fetch?: (
99
request: Request,
1010
init: { redirect?: Request['redirect'] },
11-
options: StandardLinkInterceptorOptions<T>,
11+
options: ClientOptions<T>,
12+
path: readonly string[],
13+
input: unknown,
1214
) => Promise<Response>
1315
}
1416

@@ -24,7 +26,7 @@ export class LinkFetchClient<T extends ClientContext> implements StandardLinkCli
2426
async call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse> {
2527
const fetchRequest = toFetchRequest(request, this.toFetchRequestOptions)
2628

27-
const fetchResponse = await this.fetch(fetchRequest, { redirect: 'manual' }, { ...options, path, input })
29+
const fetchResponse = await this.fetch(fetchRequest, { redirect: 'manual' }, options, path, input)
2830

2931
const lazyResponse = toStandardLazyResponse(fetchResponse)
3032

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { ClientContext, ClientOptions, HTTPMethod } from '../../types'
2-
import type { StandardLinkInterceptorOptions } from './link'
32
import type { StandardRPCSerializer } from './rpc-serializer'
43
import type { StandardLinkCodec } from './types'
54
import { isAsyncIteratorObject, stringifyJSON, value, type Value } from '@orpc/shared'
@@ -11,21 +10,21 @@ export interface StandardRPCLinkCodecOptions<T extends ClientContext> {
1110
/**
1211
* Base url for all requests.
1312
*/
14-
url: Value<string | URL, [StandardLinkInterceptorOptions<T>]>
13+
url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>
1514

1615
/**
1716
* The maximum length of the URL.
1817
*
1918
* @default 2083
2019
*/
21-
maxUrlLength?: Value<number, [StandardLinkInterceptorOptions<T>]>
20+
maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>
2221

2322
/**
2423
* The method used to make the request.
2524
*
2625
* @default 'POST'
2726
*/
28-
method?: Value<HTTPMethod, [StandardLinkInterceptorOptions<T>]>
27+
method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>
2928

3029
/**
3130
* The method to use when the payload cannot safely pass to the server with method return from method function.
@@ -38,7 +37,7 @@ export interface StandardRPCLinkCodecOptions<T extends ClientContext> {
3837
/**
3938
* Inject headers to the request.
4039
*/
41-
headers?: Value<StandardHeaders, [StandardLinkInterceptorOptions<T>]>
40+
headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>
4241
}
4342

4443
export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
@@ -60,11 +59,9 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
6059
}
6160

6261
async encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest> {
63-
const generalOptions = { ...options, path, input }
64-
65-
const expectedMethod = await value(this.expectedMethod, generalOptions)
66-
let headers = await value(this.headers, generalOptions)
67-
const baseUrl = await value(this.baseUrl, generalOptions)
62+
const expectedMethod = await value(this.expectedMethod, options, path, input)
63+
let headers = await value(this.headers, options, path, input)
64+
const baseUrl = await value(this.baseUrl, options, path, input)
6865
const url = new URL(baseUrl)
6966
url.pathname = `${url.pathname.replace(/\/$/, '')}${toHttpPath(path)}`
7067

@@ -79,7 +76,7 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
7976
&& !(serialized instanceof FormData)
8077
&& !isAsyncIteratorObject(serialized)
8178
) {
82-
const maxUrlLength = await value(this.maxUrlLength, generalOptions)
79+
const maxUrlLength = await value(this.maxUrlLength, options, path, input)
8380
const getUrl = new URL(url)
8481

8582
getUrl.searchParams.append('data', stringifyJSON(serialized))

0 commit comments

Comments
 (0)