Skip to content

Commit 21961be

Browse files
authored
feat(client)!: remove Content-Disposition requirement from RPC serializer (#269)
Closes: #263 Related: https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Enhanced the encoding logic for data requests so that GET requests now construct URLs more precisely. - Streamlined serialization routines to consistently return structured data, ensuring reliable handling of transmitted data. - **Documentation** - Removed redundant notes regarding the potential for empty (`undefined`) payloads across multiple sections of the RPC protocol documentation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e563486 commit 21961be

File tree

4 files changed

+3
-45
lines changed

4 files changed

+3
-45
lines changed

apps/content/docs/advanced/rpc-protocol.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ url.searchParams.append('data', JSON.stringify({
4545
const response = await fetch(url)
4646
```
4747

48-
::: info
49-
The payload can be empty (`undefined`).
50-
:::
51-
5248
### Input in Request Body
5349

5450
```bash
@@ -63,10 +59,6 @@ curl -X POST https://example.com/rpc/planet/create \
6359
}'
6460
```
6561

66-
::: info
67-
The payload can be empty (`undefined`).
68-
:::
69-
7062
### Input with File
7163

7264
```ts
@@ -91,10 +83,6 @@ const response = await fetch('https://example.com/rpc/planet/create', {
9183
})
9284
```
9385

94-
::: info
95-
The input can be empty (`undefined`) or binary data (`blob/file`).
96-
:::
97-
9886
## Success Response
9987

10088
```http
@@ -113,10 +101,6 @@ Content-Type: application/json
113101

114102
A success response has an HTTP status code between `200-299` and returns the procedure's output.
115103

116-
::: info
117-
The payload can be empty (`undefined`) or binary data (`blob/file`).
118-
:::
119-
120104
## Error Response
121105

122106
```http

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,6 @@ describe('standardRPCLinkCodec', () => {
3838
}))
3939
})
4040

41-
it('with method=GET & input=undefined', async () => {
42-
method.mockResolvedValueOnce('GET')
43-
44-
const signal = AbortSignal.timeout(100)
45-
const output = await codec.encode(['test'], undefined, { context: {}, signal })
46-
47-
expect(output).toEqual(expect.objectContaining({
48-
url: new URL(`http://localhost:3000/test?data=`),
49-
method: 'GET',
50-
headers: {
51-
'x-custom-header': 'custom-value',
52-
},
53-
body: undefined,
54-
signal,
55-
}))
56-
})
57-
5841
it('with method=POST', async () => {
5942
method.mockResolvedValueOnce('POST')
6043

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
9898
if (
9999
expectedMethod === 'GET'
100100
&& !(serialized instanceof FormData)
101-
&& !(serialized instanceof Blob)
102101
&& !isAsyncIteratorObject(serialized)
103102
) {
104103
const maxUrlLength = await value(this.maxUrlLength, options, path, input)
105104
const getUrl = new URL(url)
106105

107-
getUrl.searchParams.append('data', stringifyJSON(serialized) ?? '')
106+
getUrl.searchParams.append('data', stringifyJSON(serialized))
108107

109108
if (getUrl.toString().length <= maxUrlLength) {
110109
return {

packages/client/src/adapters/standard/rpc-serializer.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class StandardRPCSerializer {
99
private readonly jsonSerializer: StandardRPCJsonSerializer,
1010
) {}
1111

12-
serialize(data: unknown): unknown {
12+
serialize(data: unknown): object {
1313
if (isAsyncIteratorObject(data)) {
1414
return mapEventIterator(data, {
1515
value: async (value: unknown) => this.#serialize(value, false),
@@ -28,11 +28,7 @@ export class StandardRPCSerializer {
2828
#serialize(
2929
data: unknown,
3030
enableFormData: boolean,
31-
): unknown {
32-
if (data === undefined || data instanceof Blob) {
33-
return data
34-
}
35-
31+
): object {
3632
const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data)
3733

3834
const meta = meta_.length === 0 ? undefined : meta_
@@ -82,10 +78,6 @@ export class StandardRPCSerializer {
8278
}
8379

8480
#deserialize(data: unknown): unknown {
85-
if (data === undefined || data instanceof Blob) {
86-
return data
87-
}
88-
8981
if (!(data instanceof FormData)) {
9082
return this.jsonSerializer.deserialize((data as any).json, (data as any).meta ?? [])
9183
}

0 commit comments

Comments
 (0)