@@ -23,7 +23,6 @@ import {
23
23
ServiceDiscoveryResponse ,
24
24
} from "../generated/proto/discovery" ;
25
25
import { Event } from "../types/types" ;
26
- import { StringKeyedEvent } from "../generated/dev/restate/events" ;
27
26
import {
28
27
FileDescriptorProto ,
29
28
UninterpretedOption ,
@@ -43,6 +42,7 @@ import {
43
42
RpcResponse ,
44
43
ProtoMetadata as RpcServiceProtoMetadata ,
45
44
protoMetadata as rpcServiceProtoMetadata ,
45
+ KeyedEvent ,
46
46
} from "../generated/proto/dynrpc" ;
47
47
import { RestateContext , useContext } from "../restate_context" ;
48
48
import { RpcContextImpl } from "../restate_context_impl" ;
@@ -202,15 +202,15 @@ export abstract class BaseRestateServer {
202
202
throw new TerminalError ( "Unkeyed Event handlers are not yet supported." ) ;
203
203
}
204
204
const descriptor = createStringKeyedMethodDescriptor ( route ) ;
205
- const localMethod = ( instance : unknown , input : StringKeyedEvent ) => {
205
+ const localMethod = ( instance : unknown , input : KeyedEvent ) => {
206
206
const ctx = useContext ( instance ) ;
207
207
return dispatchKeyedEventHandler ( ctx , input , handler ) ;
208
208
} ;
209
209
210
- const decoder = StringKeyedEvent . decode ;
210
+ const decoder = KeyedEvent . decode ;
211
211
const encoder = ( message : Empty ) => Empty . encode ( message ) . finish ( ) ;
212
212
213
- const method = new GrpcServiceMethod < StringKeyedEvent , Empty > (
213
+ const method = new GrpcServiceMethod < KeyedEvent , Empty > (
214
214
route ,
215
215
route ,
216
216
localMethod ,
@@ -447,19 +447,19 @@ async function dispatchUnkeyedRpcHandler(
447
447
448
448
async function dispatchKeyedEventHandler (
449
449
origCtx : RestateContext ,
450
- req : StringKeyedEvent ,
450
+ req : KeyedEvent ,
451
451
handler : Function
452
452
) : Promise < Empty > {
453
453
const ctx = new RpcContextImpl ( origCtx ) ;
454
454
const key = req . key ;
455
- if ( typeof key !== "string" || key . length === 0 ) {
455
+ if ( key === null || key === undefined || key . length === 0 ) {
456
456
// we throw a terminal error here, because this cannot be patched by updating code:
457
457
// if the request is wrong (missing a key), the request can never make it
458
458
throw new TerminalError (
459
- "Keyed handlers must recieve a non null or empty string key"
459
+ "Keyed handlers must receive a non null or empty string key"
460
460
) ;
461
461
}
462
- const jsEvent = new Event ( key , req . payload , req . source , req . attributes ) ;
462
+ const jsEvent = new Event ( key , req . payload , req . attributes ) ;
463
463
await handler ( ctx , jsEvent ) ;
464
464
return Empty . create ( { } ) ;
465
465
}
0 commit comments