You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rpc: RPC over HTTP, any and enum arguments lose their type #767
Over HTTP, an action whose arguments are all primitives is called with GET and its arguments in the query string, where they lose their type: an any parameter gets the string '5', and a numeric enum argument is rejected. Over WebSocket both arrive as sent.
import{App}from'@deepkit/app';import{ApplicationServer,FrameworkModule}from'@deepkit/framework';import{rpc,RpcClient,RpcHttpClientAdapter}from'@deepkit/rpc';enumPriority{low=1,high=2,}
@rpc.controller('settings')classSettingsController{
@rpc.action()set(key: string,value: any): string{return`${key} = ${typeofvalue}${value}`;}
@rpc.action()priority(priority: Priority): string{return`${typeofpriority}${priority}`;}}constapp=newApp({controllers: [SettingsController],imports: [newFrameworkModule({port: 8080,httpRpcBasePath: '/api'})],});awaitapp.get(ApplicationServer).start();constsettings=newRpcClient(newRpcHttpClientAdapter('http://127.0.0.1:8080/api')).controller<SettingsController>('settings');console.log(awaitsettings.set('retries',5));// actual: retries = string 5, should be: retries = number 5 (as over WebSocket)console.log(awaitsettings.priority(Priority.high).catch((error: Error)=>error.message));// actual: 'Validation error:\npriority(type): Cannot convert 2 to enum. No valid value of 1, 2', should be: number 2 (as over WebSocket)
Related: #766 (a string | number argument loses its type over HTTP).
Activity