Skip to content

Commit b2b375a

Browse files
committed
fix(rivetkit): fix actor-handle type error
1 parent ec71001 commit b2b375a

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

rivetkit-typescript/packages/rivetkit/src/client/actor-handle.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ export class ActorHandleRaw {
249249
async resolve(): Promise<string> {
250250
if ("getForKey" in this.#actorQuery) {
251251
const name = this.#actorQuery.getForKey.name;
252-
const key = this.#actorQuery.getForKey.key;
253252

254253
// Query the actor to get the id
255254
const { actorId } = await queryActor(
@@ -260,9 +259,22 @@ export class ActorHandleRaw {
260259

261260
this.#actorQuery = { getForId: { actorId, name } };
262261

262+
return actorId;
263+
} else if ("getOrCreateForKey" in this.#actorQuery) {
264+
const name = this.#actorQuery.getOrCreateForKey.name;
265+
266+
// Query the actor to get or create and get the id
267+
const { actorId } = await queryActor(
268+
undefined,
269+
this.#actorQuery,
270+
this.#driver,
271+
);
272+
273+
this.#actorQuery = { getForId: { actorId, name } };
274+
263275
return actorId;
264276
} else if ("getForId" in this.#actorQuery) {
265-
// SKip since it's already resolved
277+
// Skip since it's already resolved
266278
return this.#actorQuery.getForId.actorId;
267279
} else if ("create" in this.#actorQuery) {
268280
// Cannot create a handle with this query

rivetkit-typescript/packages/rivetkit/src/client/queue.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface QueueSenderOptions {
5252
customFetch: (request: Request) => Promise<Response>;
5353
}
5454

55-
export function createQueueSender(options: QueueSenderOptions): QueueSender {
55+
export function createQueueSender(senderOptions: QueueSenderOptions): QueueSender {
5656
return {
5757
async send(
5858
name: string,
@@ -75,18 +75,18 @@ export function createQueueSender(options: QueueSenderOptions): QueueSender {
7575
url: `http://actor/queue/${encodeURIComponent(name)}`,
7676
method: "POST",
7777
headers: {
78-
[HEADER_ENCODING]: options.encoding,
79-
...(options.params !== undefined
78+
[HEADER_ENCODING]: senderOptions.encoding,
79+
...(senderOptions.params !== undefined
8080
? {
8181
[HEADER_CONN_PARAMS]: JSON.stringify(
82-
options.params,
82+
senderOptions.params,
8383
),
8484
}
8585
: {}),
8686
},
8787
body: { body, wait, timeout },
88-
encoding: options.encoding,
89-
customFetch: options.customFetch,
88+
encoding: senderOptions.encoding,
89+
customFetch: senderOptions.customFetch,
9090
signal: normalizedOptions?.signal,
9191
requestVersion: CLIENT_PROTOCOL_CURRENT_VERSION,
9292
requestVersionedDataHandler: HTTP_QUEUE_SEND_REQUEST_VERSIONED,
@@ -103,23 +103,23 @@ export function createQueueSender(options: QueueSenderOptions): QueueSender {
103103
name: value.name ?? name,
104104
body: bufferToArrayBuffer(cbor.encode(value.body)),
105105
wait: value.wait ?? false,
106-
timeout: value.timeout ?? null,
106+
timeout: value.timeout !== undefined ? BigInt(value.timeout) : null,
107107
}),
108108
responseFromJson: (json): QueueSendResult => {
109109
if (json.response === undefined) {
110-
return { status: json.status };
110+
return { status: json.status as "completed" | "timedOut" };
111111
}
112112
return {
113-
status: json.status,
113+
status: json.status as "completed" | "timedOut",
114114
response: json.response,
115115
};
116116
},
117117
responseFromBare: (bare): QueueSendResult => {
118118
if (bare.response === null || bare.response === undefined) {
119-
return { status: bare.status };
119+
return { status: bare.status as "completed" | "timedOut" };
120120
}
121121
return {
122-
status: bare.status,
122+
status: bare.status as "completed" | "timedOut",
123123
response: cbor.decode(new Uint8Array(bare.response)),
124124
};
125125
},

0 commit comments

Comments
 (0)