From fc159fd93d0ee14be78df674211929f4b9e33863 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Sun, 9 Nov 2025 14:12:44 -0800 Subject: [PATCH] chore(rivetkit): rename `onFetch` to `onRequest` --- .../raw-http-request-properties.ts | 5 ++++- .../fixtures/driver-test-suite/raw-http.ts | 12 +++++++++--- .../fixtures/driver-test-suite/request-access.ts | 14 +++++++------- .../rivetkit/fixtures/driver-test-suite/sleep.ts | 2 +- .../packages/rivetkit/src/actor/config.ts | 8 ++++---- .../packages/rivetkit/src/actor/errors.ts | 12 ++++++------ .../packages/rivetkit/src/actor/instance/mod.ts | 14 +++++++------- .../rivetkit/src/actor/router-endpoints.ts | 2 +- .../packages/rivetkit/src/actor/router.ts | 4 ++-- .../driver-test-suite/test-inline-client-driver.ts | 8 ++++---- .../tests/raw-http-direct-registry.ts | 2 +- .../tests/raw-http-request-properties.ts | 2 +- .../src/driver-test-suite/tests/raw-http.ts | 10 +++++----- .../src/driver-test-suite/tests/request-access.ts | 4 ++-- 14 files changed, 54 insertions(+), 45 deletions(-) diff --git a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http-request-properties.ts b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http-request-properties.ts index 5a6c8f35c8..5c89bca0a8 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http-request-properties.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http-request-properties.ts @@ -2,7 +2,10 @@ import { type ActorContext, actor } from "rivetkit"; export const rawHttpRequestPropertiesActor = actor({ actions: {}, - onFetch(ctx: ActorContext, request: Request) { + onRequest( + ctx: ActorContext, + request: Request, + ) { // Extract all relevant Request properties const url = new URL(request.url); const method = request.method; diff --git a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http.ts b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http.ts index 0d7c31a97a..5723337c2b 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http.ts @@ -5,7 +5,10 @@ export const rawHttpActor = actor({ state: { requestCount: 0, }, - onFetch(ctx: ActorContext, request: Request) { + onRequest( + ctx: ActorContext, + request: Request, + ) { const url = new URL(request.url); const method = request.method; @@ -57,7 +60,7 @@ export const rawHttpNoHandlerActor = actor({ }); export const rawHttpVoidReturnActor = actor({ - onFetch(ctx, request) { + onRequest(ctx, request) { // Intentionally return void to test error handling return undefined as any; }, @@ -107,7 +110,10 @@ export const rawHttpHonoActor = actor({ // Return the router as a var return { router }; }, - onFetch(ctx: ActorContext, request: Request) { + onRequest( + ctx: ActorContext, + request: Request, + ) { // Use the Hono router from vars return ctx.vars.router.fetch(request); }, diff --git a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/request-access.ts b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/request-access.ts index 481526ef6f..5caf7dd150 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/request-access.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/request-access.ts @@ -18,7 +18,7 @@ export const requestAccessActor = actor({ requestMethod: null as string | null, requestHeaders: {} as Record, }, - onFetchRequest: { + onRequestRequest: { hasRequest: false, requestUrl: null as string | null, requestMethod: null as string | null, @@ -74,18 +74,18 @@ export const requestAccessActor = actor({ } } }, - onFetch: (c, request) => { + onRequest: (c, request) => { // Store request info - c.state.onFetchRequest.hasRequest = true; - c.state.onFetchRequest.requestUrl = request.url; - c.state.onFetchRequest.requestMethod = request.method; + c.state.onRequestRequest.hasRequest = true; + c.state.onRequestRequest.requestUrl = request.url; + c.state.onRequestRequest.requestMethod = request.method; // Store select headers const headers: Record = {}; request.headers.forEach((value, key) => { headers[key] = value; }); - c.state.onFetchRequest.requestHeaders = headers; + c.state.onRequestRequest.requestHeaders = headers; // Return response with request info return new Response( @@ -134,7 +134,7 @@ export const requestAccessActor = actor({ return { onBeforeConnect: c.state.onBeforeConnectRequest, createConnState: c.state.createConnStateRequest, - onFetch: c.state.onFetchRequest, + onRequest: c.state.onRequestRequest, onWebSocket: c.state.onWebSocketRequest, }; }, diff --git a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts index 8c77c5c1ba..1856c3fe87 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts @@ -72,7 +72,7 @@ export const sleepWithRawHttp = actor({ onSleep: (c) => { c.state.sleepCount += 1; }, - onFetch: async (c, request) => { + onRequest: async (c, request) => { c.state.requestCount += 1; const url = new URL(request.url); diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/config.ts b/rivetkit-typescript/packages/rivetkit/src/actor/config.ts index 9281bce706..704693d05f 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/config.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/config.ts @@ -45,7 +45,7 @@ export const ActorConfigSchema = z onConnect: z.function().optional(), onDisconnect: z.function().optional(), onBeforeActionResponse: z.function().optional(), - onFetch: z.function().optional(), + onRequest: z.function().optional(), onWebSocket: z.function().optional(), actions: z.record(z.function()).default({}), state: z.any().optional(), @@ -410,7 +410,7 @@ interface BaseActorConfig< * @param request The raw HTTP request object * @returns A Response object to send back, or void to continue with default routing */ - onFetch?: ( + onRequest?: ( c: ActorContext< TState, TConnParams, @@ -477,7 +477,7 @@ export type ActorConfig< | "onConnect" | "onDisconnect" | "onBeforeActionResponse" - | "onFetch" + | "onRequest" | "onWebSocket" | "state" | "createState" @@ -537,7 +537,7 @@ export type ActorConfigInput< | "onConnect" | "onDisconnect" | "onBeforeActionResponse" - | "onFetch" + | "onRequest" | "onWebSocket" | "state" | "createState" diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/errors.ts b/rivetkit-typescript/packages/rivetkit/src/actor/errors.ts index 07a517dbd0..8b7b9bfd05 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/errors.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/errors.ts @@ -317,12 +317,12 @@ export class DatabaseNotEnabled extends ActorError { } } -export class FetchHandlerNotDefined extends ActorError { +export class RequestHandlerNotDfeined extends ActorError { constructor() { super( "handler", - "fetch_not_defined", - "Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", + "request_not_defined", + "Raw request handler not defined. Actor must implement `onRequest` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", { public: true }, ); this.statusCode = 404; @@ -341,12 +341,12 @@ export class WebSocketHandlerNotDefined extends ActorError { } } -export class InvalidFetchResponse extends ActorError { +export class InvalidRequestHandlerResponse extends ActorError { constructor() { super( "handler", - "invalid_fetch_response", - "Actor's onFetch handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", + "invalid_request_handler_response", + "Actor's onRequest handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", { public: true }, ); this.statusCode = 500; diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts b/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts index e4e45a1c19..bfddac74fa 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts @@ -643,29 +643,29 @@ export class ActorInstance { } // MARK: - HTTP/WebSocket Handlers - async handleFetch( + async handleRawRequest( request: Request, opts: Record, ): Promise { this.#assertReady(); - if (!this.#config.onFetch) { - throw new errors.FetchHandlerNotDefined(); + if (!this.#config.onRequest) { + throw new errors.RequestHandlerNotDfeined(); } try { - const response = await this.#config.onFetch( + const response = await this.#config.onRequest( this.actorContext, request, opts, ); if (!response) { - throw new errors.InvalidFetchResponse(); + throw new errors.InvalidRequestHandlerResponse(); } return response; } catch (error) { this.#rLog.error({ - msg: "onFetch error", + msg: "onRequest error", error: stringifyError(error), }); throw error; @@ -674,7 +674,7 @@ export class ActorInstance { } } - async handleWebSocket( + async handleRawWebSocket( websocket: UniversalWebSocket, opts: { request: Request }, ): Promise { diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts b/rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts index afa49911e1..123421cd8e 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts @@ -452,7 +452,7 @@ export async function handleRawWebSocketHandler( createdConn = conn; // Call the actor's onWebSocket handler with the adapted WebSocket - actor.handleWebSocket(adapter, { + actor.handleRawWebSocket(adapter, { request: newRequest, }); } catch (error) { diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/router.ts b/rivetkit-typescript/packages/rivetkit/src/actor/router.ts index 305ce03a38..e64943e4a3 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/router.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/router.ts @@ -195,8 +195,8 @@ export function createActorRouter( to: correctedRequest.url, }); - // Call the actor's onFetch handler - it will throw appropriate errors - const response = await actor.handleFetch(correctedRequest, {}); + // Call the actor's onRequest handler - it will throw appropriate errors + const response = await actor.handleRawRequest(correctedRequest, {}); // This should never happen now since handleFetch throws errors if (!response) { diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/test-inline-client-driver.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/test-inline-client-driver.ts index 4f672a414f..076b47b3eb 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/test-inline-client-driver.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/test-inline-client-driver.ts @@ -129,7 +129,7 @@ export function createTestInlineClientDriver( if (errorData.error) { // Handle both error formats: // 1. { error: { code, message, metadata } } - structured format - // 2. { error: "message" } - simple string format (from custom onFetch handlers) + // 2. { error: "message" } - simple string format (from custom onRequest handlers) if (typeof errorData.error === "object") { throw new ClientActorError( errorData.error.code, @@ -138,7 +138,7 @@ export function createTestInlineClientDriver( ); } // For simple string errors, just return the response as-is - // This allows custom onFetch handlers to return their own error formats + // This allows custom onRequest handlers to return their own error formats } } catch (e) { // If it's not our error format, just return the response as-is @@ -452,7 +452,7 @@ export function createTestInlineClientDriver( // if (errorData.error) { // // Handle both error formats: // // 1. { error: { code, message, metadata } } - structured format - // // 2. { error: "message" } - simple string format (from custom onFetch handlers) + // // 2. { error: "message" } - simple string format (from custom onRequest handlers) // if (typeof errorData.error === "object") { // throw new ClientActorError( // errorData.error.code, @@ -461,7 +461,7 @@ export function createTestInlineClientDriver( // ); // } // // For simple string errors, just return the response as-is - // // This allows custom onFetch handlers to return their own error formats + // // This allows custom onRequest handlers to return their own error formats // } // } catch (e) { // // If it's not our error format, just return the response as-is diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-direct-registry.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-direct-registry.ts index 359db4d54e..206b8f0e52 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-direct-registry.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-direct-registry.ts @@ -129,7 +129,7 @@ // expect(data).toEqual({ message: "Hello from actor!" }); // }); // -// test("should return 404 for actors without onFetch handler", async (c) => { +// test("should return 404 for actors without onRequest handler", async (c) => { // const { endpoint } = await setupDriverTest(c, driverTestConfig); // // const actorQuery: ActorQuery = { diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-request-properties.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-request-properties.ts index 34f587fc06..201da0f1fd 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-request-properties.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http-request-properties.ts @@ -8,7 +8,7 @@ export function runRawHttpRequestPropertiesTests( driverTestConfig: DriverTestConfig, ) { describe("raw http request properties", () => { - test("should pass all Request properties correctly to onFetch", async (c) => { + test("should pass all Request properties correctly to onRequest", async (c) => { const { client } = await setupDriverTest(c, driverTestConfig); const actor = client.rawHttpRequestPropertiesActor.getOrCreate([ "test", diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http.ts index ac20cfb39e..62ec39e661 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/raw-http.ts @@ -79,7 +79,7 @@ export function runRawHttpTests(driverTestConfig: DriverTestConfig) { expect(response.status).toBe(404); }); - test("should return 404 when no onFetch handler defined", async (c) => { + test("should return 404 when no onRequest handler defined", async (c) => { const { client } = await setupDriverTest(c, driverTestConfig); const actor = client.rawHttpNoHandlerActor.getOrCreate([ "no-handler", @@ -89,10 +89,10 @@ export function runRawHttpTests(driverTestConfig: DriverTestConfig) { expect(response.ok).toBe(false); expect(response.status).toBe(404); - // No actions available without onFetch handler + // No actions available without onRequest handler }); - test("should return 500 error when onFetch returns void", async (c) => { + test("should return 500 error when onRequest returns void", async (c) => { const { client } = await setupDriverTest(c, driverTestConfig); const actor = client.rawHttpVoidReturnActor.getOrCreate([ "void-return", @@ -108,14 +108,14 @@ export function runRawHttpTests(driverTestConfig: DriverTestConfig) { message: string; }; expect(errorData.message).toContain( - "onFetch handler must return a Response", + "onRequest handler must return a Response", ); } catch { // If JSON parsing fails, just check that we got a 500 error // The error details are already validated by the status code } - // No actions available when onFetch returns void + // No actions available when onRequest returns void }); test("should handle different HTTP methods", async (c) => { diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/request-access.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/request-access.ts index a5ac02f671..e11e6643d8 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/request-access.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/request-access.ts @@ -125,7 +125,7 @@ export function runRequestAccessTests(driverTestConfig: DriverTestConfig) { }); // TODO: re-expose this once we can have actor queries on the gateway - // test("should have access to request object in onFetch", async (c) => { + // test("should have access to request object in onRequest", async (c) => { // const { client, endpoint } = await setupDriverTest(c, driverTestConfig); // // // Create actor @@ -163,7 +163,7 @@ export function runRequestAccessTests(driverTestConfig: DriverTestConfig) { // expect(response.ok).toBe(true); // const data = await response.json(); // - // // Verify request info from onFetch + // // Verify request info from onRequest // expect((data as any).hasRequest).toBe(true); // expect((data as any).requestUrl).toContain("/test-path"); // expect((data as any).requestMethod).toBe("POST");