@@ -5,6 +5,8 @@ import type { AnyActorDefinition } from "@/actor/definition";
5
5
import type { ActorQuery } from "@/manager/protocol/query" ;
6
6
import type { ActorDefinitionRpcs } from "./actor_common" ;
7
7
import type { RpcRequest , RpcResponse } from "@/actor/protocol/http/rpc" ;
8
+ import { type ActorConn , ActorConnRaw } from "./actor_conn" ;
9
+ import { CREATE_ACTOR_CONN_PROXY , type ClientRaw } from "./client" ;
8
10
9
11
/**
10
12
* Provides underlying functions for stateless {@link ActorHandle} for RPC calls.
@@ -13,6 +15,7 @@ import type { RpcRequest, RpcResponse } from "@/actor/protocol/http/rpc";
13
15
* @see {@link ActorHandle }
14
16
*/
15
17
export class ActorHandleRaw {
18
+ #client: ClientRaw ;
16
19
#endpoint: string ;
17
20
#encodingKind: Encoding ;
18
21
#actorQuery: ActorQuery ;
@@ -27,11 +30,13 @@ export class ActorHandleRaw {
27
30
* @protected
28
31
*/
29
32
public constructor (
33
+ client : any ,
30
34
endpoint : string ,
31
35
private readonly params : unknown ,
32
36
encodingKind : Encoding ,
33
37
actorQuery : ActorQuery ,
34
38
) {
39
+ this . #client = client ;
35
40
this . #endpoint = endpoint ;
36
41
this . #encodingKind = encodingKind ;
37
42
this . #actorQuery = actorQuery ;
@@ -82,6 +87,30 @@ export class ActorHandleRaw {
82
87
83
88
return responseData . o as Response ;
84
89
}
90
+
91
+ /**
92
+ * Establishes a persistent connection to the actor.
93
+ *
94
+ * @template AD The actor class that this connection is for.
95
+ * @returns {ActorConn<AD> } A connection to the actor.
96
+ */
97
+ connect ( ) : ActorConn < AnyActorDefinition > {
98
+ logger ( ) . debug ( "establishing connection from handle" , {
99
+ query : this . #actorQuery,
100
+ } ) ;
101
+
102
+ const conn = new ActorConnRaw (
103
+ this . #client,
104
+ this . #endpoint,
105
+ this . params ,
106
+ this . #encodingKind,
107
+ this . #actorQuery,
108
+ ) ;
109
+
110
+ return this . #client[ CREATE_ACTOR_CONN_PROXY ] (
111
+ conn ,
112
+ ) as ActorConn < AnyActorDefinition > ;
113
+ }
85
114
}
86
115
87
116
/**
@@ -100,5 +129,10 @@ export class ActorHandleRaw {
100
129
* @template AD The actor class that this handle is for.
101
130
* @see {@link ActorHandleRaw }
102
131
*/
103
- export type ActorHandle < AD extends AnyActorDefinition > = ActorHandleRaw &
104
- ActorDefinitionRpcs < AD > ;
132
+ export type ActorHandle < AD extends AnyActorDefinition > = Omit <
133
+ ActorHandleRaw ,
134
+ "connect"
135
+ > & {
136
+ // Add typed version of ActorConn (instead of using AnyActorDefinition)
137
+ connect ( ) : ActorConn < AD > ;
138
+ } & ActorDefinitionRpcs < AD > ;
0 commit comments