11import type { StandardHeaders , StandardLazyResponse , StandardRequest } from '@orpc/standard-server'
22import type { ClientContext , ClientOptionsOut } from '../../types'
3+ import type { RPCSerializer } from './rpc-serializer'
34import type { StandardLinkCodec } from './types'
45import { isAsyncIteratorObject , stringifyJSON , trim , value , type Value } from '@orpc/shared'
56import { ORPCError } from '../../error'
6- import { RPCSerializer } from './rpc-serializer'
77
88type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
99
@@ -55,8 +55,6 @@ export interface StandardRPCLinkCodecOptions<T extends ClientContext> {
5555 path : readonly string [ ] ,
5656 input : unknown ,
5757 ] >
58-
59- rpcSerializer ?: RPCSerializer
6058}
6159
6260export class StandardRPCLinkCodec < T extends ClientContext > implements StandardLinkCodec < T > {
@@ -65,15 +63,16 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
6563 private readonly fallbackMethod : Exclude < StandardRPCLinkCodecOptions < T > [ 'fallbackMethod' ] , undefined >
6664 private readonly expectedMethod : Exclude < StandardRPCLinkCodecOptions < T > [ 'method' ] , undefined >
6765 private readonly headers : Exclude < StandardRPCLinkCodecOptions < T > [ 'headers' ] , undefined >
68- private readonly rpcSerializer : Exclude < StandardRPCLinkCodecOptions < T > [ 'rpcSerializer' ] , undefined >
6966
70- constructor ( options : StandardRPCLinkCodecOptions < T > ) {
67+ constructor (
68+ private readonly serializer : RPCSerializer ,
69+ options : StandardRPCLinkCodecOptions < T > ,
70+ ) {
7171 this . baseUrl = options . url
7272 this . maxUrlLength = options . maxUrlLength ?? 2083
7373 this . fallbackMethod = options . fallbackMethod ?? 'POST'
7474 this . expectedMethod = options . method ?? this . fallbackMethod
7575 this . headers = options . headers ?? { }
76- this . rpcSerializer = options . rpcSerializer ?? new RPCSerializer ( )
7776 }
7877
7978 async encode ( path : readonly string [ ] , input : unknown , options : ClientOptionsOut < any > ) : Promise < StandardRequest > {
@@ -82,7 +81,7 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
8281 const baseUrl = await value ( this . baseUrl , options , path , input )
8382 const url = new URL ( `${ trim ( baseUrl . toString ( ) , '/' ) } /${ path . map ( encodeURIComponent ) . join ( '/' ) } ` )
8483
85- const serialized = this . rpcSerializer . serialize ( input )
84+ const serialized = this . serializer . serialize ( input )
8685
8786 if (
8887 expectedMethod === 'GET'
@@ -126,7 +125,7 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
126125
127126 isBodyOk = true
128127
129- return this . rpcSerializer . deserialize ( body )
128+ return this . serializer . deserialize ( body )
130129 }
131130 catch ( error ) {
132131 if ( ! isBodyOk ) {
0 commit comments