@@ -458,7 +458,7 @@ export class ActorInstance<S, CP, CS, V> {
458
458
}
459
459
}
460
460
461
- // State will be flushed at the end of the RPC
461
+ // State will be flushed at the end of the action
462
462
} ,
463
463
{ ignoreDetached : true } ,
464
464
) ;
@@ -734,8 +734,8 @@ export class ActorInstance<S, CP, CS, V> {
734
734
// MARK: Messages
735
735
async processMessage ( message : wsToServer . ToServer , conn : Conn < S , CP , CS , V > ) {
736
736
await processMessage ( message , this , conn , {
737
- onExecuteRpc : async ( ctx , name , args ) => {
738
- return await this . executeRpc ( ctx , name , args ) ;
737
+ onExecuteAction : async ( ctx , name , args ) => {
738
+ return await this . executeAction ( ctx , name , args ) ;
739
739
} ,
740
740
onSubscribe : async ( eventName , conn ) => {
741
741
this . #addSubscription( eventName , conn , false ) ;
@@ -820,98 +820,98 @@ export class ActorInstance<S, CP, CS, V> {
820
820
}
821
821
822
822
/**
823
- * Execute an RPC call from a client.
823
+ * Execute an action call from a client.
824
824
*
825
825
* This method handles:
826
- * 1. Validating the RPC name
827
- * 2. Executing the RPC function
828
- * 3. Processing the result through onBeforeRpcResponse (if configured)
826
+ * 1. Validating the action name
827
+ * 2. Executing the action function
828
+ * 3. Processing the result through onBeforeActionResponse (if configured)
829
829
* 4. Handling timeouts and errors
830
830
* 5. Saving state changes
831
831
*
832
- * @param ctx The RPC context
833
- * @param rpcName The name of the RPC being called
834
- * @param args The arguments passed to the RPC
835
- * @returns The result of the RPC call
836
- * @throws {RpcNotFound } If the RPC doesn't exist
837
- * @throws {RpcTimedOut } If the RPC times out
832
+ * @param ctx The action context
833
+ * @param actionName The name of the action being called
834
+ * @param args The arguments passed to the action
835
+ * @returns The result of the action call
836
+ * @throws {ActionNotFound } If the action doesn't exist
837
+ * @throws {ActionTimedOut } If the action times out
838
838
* @internal
839
839
*/
840
- async executeRpc (
840
+ async executeAction (
841
841
ctx : ActionContext < S , CP , CS , V > ,
842
- rpcName : string ,
842
+ actionName : string ,
843
843
args : unknown [ ] ,
844
844
) : Promise < unknown > {
845
- invariant ( this . #ready, "exucuting rpc before ready" ) ;
845
+ invariant ( this . #ready, "exucuting action before ready" ) ;
846
846
847
847
// Prevent calling private or reserved methods
848
- if ( ! ( rpcName in this . #config. actions ) ) {
849
- logger ( ) . warn ( "rpc does not exist" , { rpcName } ) ;
848
+ if ( ! ( actionName in this . #config. actions ) ) {
849
+ logger ( ) . warn ( "action does not exist" , { actionName } ) ;
850
850
throw new errors . ActionNotFound ( ) ;
851
851
}
852
852
853
853
// Check if the method exists on this object
854
- // biome-ignore lint/suspicious/noExplicitAny: RPC name is dynamic from client
855
- const rpcFunction = this . #config. actions [ rpcName ] ;
856
- if ( typeof rpcFunction !== "function" ) {
857
- logger ( ) . warn ( "action not found" , { actionName : rpcName } ) ;
854
+ // biome-ignore lint/suspicious/noExplicitAny: action name is dynamic from client
855
+ const actionFunction = this . #config. actions [ actionName ] ;
856
+ if ( typeof actionFunction !== "function" ) {
857
+ logger ( ) . warn ( "action not found" , { actionName : actionName } ) ;
858
858
throw new errors . ActionNotFound ( ) ;
859
859
}
860
860
861
- // TODO: pass abortable to the rpc to decide when to abort
861
+ // TODO: pass abortable to the action to decide when to abort
862
862
// TODO: Manually call abortable for better error handling
863
863
// Call the function on this object with those arguments
864
864
try {
865
865
// Log when we start executing the action
866
- logger ( ) . debug ( "executing action" , { actionName : rpcName , args } ) ;
866
+ logger ( ) . debug ( "executing action" , { actionName : actionName , args } ) ;
867
867
868
- const outputOrPromise = rpcFunction . call ( undefined , ctx , ...args ) ;
868
+ const outputOrPromise = actionFunction . call ( undefined , ctx , ...args ) ;
869
869
let output : unknown ;
870
870
if ( outputOrPromise instanceof Promise ) {
871
871
// Log that we're waiting for an async action
872
- logger ( ) . debug ( "awaiting async action" , { actionName : rpcName } ) ;
872
+ logger ( ) . debug ( "awaiting async action" , { actionName : actionName } ) ;
873
873
874
874
output = await deadline (
875
875
outputOrPromise ,
876
876
this . #config. options . action . timeout ,
877
877
) ;
878
878
879
879
// Log that async action completed
880
- logger ( ) . debug ( "async action completed" , { actionName : rpcName } ) ;
880
+ logger ( ) . debug ( "async action completed" , { actionName : actionName } ) ;
881
881
} else {
882
882
output = outputOrPromise ;
883
883
}
884
884
885
- // Process the output through onBeforeRpcResponse if configured
885
+ // Process the output through onBeforeActionResponse if configured
886
886
if ( this . #config. onBeforeActionResponse ) {
887
887
try {
888
888
const processedOutput = this . #config. onBeforeActionResponse (
889
889
this . actorContext ,
890
- rpcName ,
890
+ actionName ,
891
891
args ,
892
892
output ,
893
893
) ;
894
894
if ( processedOutput instanceof Promise ) {
895
895
logger ( ) . debug ( "awaiting onBeforeActionResponse" , {
896
- actionName : rpcName ,
896
+ actionName : actionName ,
897
897
} ) ;
898
898
output = await processedOutput ;
899
899
logger ( ) . debug ( "onBeforeActionResponse completed" , {
900
- actionName : rpcName ,
900
+ actionName : actionName ,
901
901
} ) ;
902
902
} else {
903
903
output = processedOutput ;
904
904
}
905
905
} catch ( error ) {
906
- logger ( ) . error ( "error in `onBeforeRpcResponse `" , {
906
+ logger ( ) . error ( "error in `onBeforeActionResponse `" , {
907
907
error : stringifyError ( error ) ,
908
908
} ) ;
909
909
}
910
910
}
911
911
912
912
// Log the output before returning
913
913
logger ( ) . debug ( "action completed" , {
914
- actionName : rpcName ,
914
+ actionName : actionName ,
915
915
outputType : typeof output ,
916
916
isPromise : output instanceof Promise ,
917
917
} ) ;
@@ -922,7 +922,7 @@ export class ActorInstance<S, CP, CS, V> {
922
922
throw new errors . ActionTimedOut ( ) ;
923
923
}
924
924
logger ( ) . error ( "action error" , {
925
- actionName : rpcName ,
925
+ actionName : actionName ,
926
926
error : stringifyError ( error ) ,
927
927
} ) ;
928
928
throw error ;
@@ -932,9 +932,9 @@ export class ActorInstance<S, CP, CS, V> {
932
932
}
933
933
934
934
/**
935
- * Returns a list of RPC methods available on this actor.
935
+ * Returns a list of action methods available on this actor.
936
936
*/
937
- get rpcs ( ) : string [ ] {
937
+ get actions ( ) : string [ ] {
938
938
return Object . keys ( this . #config. actions ) ;
939
939
}
940
940
@@ -1040,7 +1040,7 @@ export class ActorInstance<S, CP, CS, V> {
1040
1040
* Runs a promise in the background.
1041
1041
*
1042
1042
* This allows the actor runtime to ensure that a promise completes while
1043
- * returning from an RPC request early.
1043
+ * returning from an action request early.
1044
1044
*
1045
1045
* @param promise - The promise to run in the background.
1046
1046
*/
0 commit comments