Skip to content

Commit 916b548

Browse files
committed
chore(rivetkit): rename onFetch to onRequest
1 parent eb167b2 commit 916b548

File tree

14 files changed

+54
-45
lines changed

14 files changed

+54
-45
lines changed

rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http-request-properties.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { type ActorContext, actor } from "rivetkit";
22

33
export const rawHttpRequestPropertiesActor = actor({
44
actions: {},
5-
onFetch(ctx: ActorContext<any, any, any, any, any, any>, request: Request) {
5+
onRequest(
6+
ctx: ActorContext<any, any, any, any, any, any>,
7+
request: Request,
8+
) {
69
// Extract all relevant Request properties
710
const url = new URL(request.url);
811
const method = request.method;

rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-http.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export const rawHttpActor = actor({
55
state: {
66
requestCount: 0,
77
},
8-
onFetch(ctx: ActorContext<any, any, any, any, any, any>, request: Request) {
8+
onRequest(
9+
ctx: ActorContext<any, any, any, any, any, any>,
10+
request: Request,
11+
) {
912
const url = new URL(request.url);
1013
const method = request.method;
1114

@@ -57,7 +60,7 @@ export const rawHttpNoHandlerActor = actor({
5760
});
5861

5962
export const rawHttpVoidReturnActor = actor({
60-
onFetch(ctx, request) {
63+
onRequest(ctx, request) {
6164
// Intentionally return void to test error handling
6265
return undefined as any;
6366
},
@@ -107,7 +110,10 @@ export const rawHttpHonoActor = actor({
107110
// Return the router as a var
108111
return { router };
109112
},
110-
onFetch(ctx: ActorContext<any, any, any, any, any, any>, request: Request) {
113+
onRequest(
114+
ctx: ActorContext<any, any, any, any, any, any>,
115+
request: Request,
116+
) {
111117
// Use the Hono router from vars
112118
return ctx.vars.router.fetch(request);
113119
},

rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/request-access.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const requestAccessActor = actor({
1818
requestMethod: null as string | null,
1919
requestHeaders: {} as Record<string, string>,
2020
},
21-
onFetchRequest: {
21+
onRequestRequest: {
2222
hasRequest: false,
2323
requestUrl: null as string | null,
2424
requestMethod: null as string | null,
@@ -74,18 +74,18 @@ export const requestAccessActor = actor({
7474
}
7575
}
7676
},
77-
onFetch: (c, request) => {
77+
onRequest: (c, request) => {
7878
// Store request info
79-
c.state.onFetchRequest.hasRequest = true;
80-
c.state.onFetchRequest.requestUrl = request.url;
81-
c.state.onFetchRequest.requestMethod = request.method;
79+
c.state.onRequestRequest.hasRequest = true;
80+
c.state.onRequestRequest.requestUrl = request.url;
81+
c.state.onRequestRequest.requestMethod = request.method;
8282

8383
// Store select headers
8484
const headers: Record<string, string> = {};
8585
request.headers.forEach((value, key) => {
8686
headers[key] = value;
8787
});
88-
c.state.onFetchRequest.requestHeaders = headers;
88+
c.state.onRequestRequest.requestHeaders = headers;
8989

9090
// Return response with request info
9191
return new Response(
@@ -134,7 +134,7 @@ export const requestAccessActor = actor({
134134
return {
135135
onBeforeConnect: c.state.onBeforeConnectRequest,
136136
createConnState: c.state.createConnStateRequest,
137-
onFetch: c.state.onFetchRequest,
137+
onRequest: c.state.onRequestRequest,
138138
onWebSocket: c.state.onWebSocketRequest,
139139
};
140140
},

rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const sleepWithRawHttp = actor({
7272
onSleep: (c) => {
7373
c.state.sleepCount += 1;
7474
},
75-
onFetch: async (c, request) => {
75+
onRequest: async (c, request) => {
7676
c.state.requestCount += 1;
7777
const url = new URL(request.url);
7878

rivetkit-typescript/packages/rivetkit/src/actor/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const ActorConfigSchema = z
4545
onConnect: z.function().optional(),
4646
onDisconnect: z.function().optional(),
4747
onBeforeActionResponse: z.function().optional(),
48-
onFetch: z.function().optional(),
48+
onRequest: z.function().optional(),
4949
onWebSocket: z.function().optional(),
5050
actions: z.record(z.function()).default({}),
5151
state: z.any().optional(),
@@ -410,7 +410,7 @@ interface BaseActorConfig<
410410
* @param request The raw HTTP request object
411411
* @returns A Response object to send back, or void to continue with default routing
412412
*/
413-
onFetch?: (
413+
onRequest?: (
414414
c: ActorContext<
415415
TState,
416416
TConnParams,
@@ -477,7 +477,7 @@ export type ActorConfig<
477477
| "onConnect"
478478
| "onDisconnect"
479479
| "onBeforeActionResponse"
480-
| "onFetch"
480+
| "onRequest"
481481
| "onWebSocket"
482482
| "state"
483483
| "createState"
@@ -537,7 +537,7 @@ export type ActorConfigInput<
537537
| "onConnect"
538538
| "onDisconnect"
539539
| "onBeforeActionResponse"
540-
| "onFetch"
540+
| "onRequest"
541541
| "onWebSocket"
542542
| "state"
543543
| "createState"

rivetkit-typescript/packages/rivetkit/src/actor/errors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ export class DatabaseNotEnabled extends ActorError {
317317
}
318318
}
319319

320-
export class FetchHandlerNotDefined extends ActorError {
320+
export class RequestHandlerNotDfeined extends ActorError {
321321
constructor() {
322322
super(
323323
"handler",
324-
"fetch_not_defined",
325-
"Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)",
324+
"request_not_defined",
325+
"Raw request handler not defined. Actor must implement `onRequest` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)",
326326
{ public: true },
327327
);
328328
this.statusCode = 404;
@@ -341,12 +341,12 @@ export class WebSocketHandlerNotDefined extends ActorError {
341341
}
342342
}
343343

344-
export class InvalidFetchResponse extends ActorError {
344+
export class InvalidRequestHandlerResponse extends ActorError {
345345
constructor() {
346346
super(
347347
"handler",
348-
"invalid_fetch_response",
349-
"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/)",
348+
"invalid_request_handler_response",
349+
"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/)",
350350
{ public: true },
351351
);
352352
this.statusCode = 500;

rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,29 +643,29 @@ export class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
643643
}
644644

645645
// MARK: - HTTP/WebSocket Handlers
646-
async handleFetch(
646+
async handleRawRequest(
647647
request: Request,
648648
opts: Record<never, never>,
649649
): Promise<Response> {
650650
this.#assertReady();
651651

652-
if (!this.#config.onFetch) {
653-
throw new errors.FetchHandlerNotDefined();
652+
if (!this.#config.onRequest) {
653+
throw new errors.RequestHandlerNotDfeined();
654654
}
655655

656656
try {
657-
const response = await this.#config.onFetch(
657+
const response = await this.#config.onRequest(
658658
this.actorContext,
659659
request,
660660
opts,
661661
);
662662
if (!response) {
663-
throw new errors.InvalidFetchResponse();
663+
throw new errors.InvalidRequestHandlerResponse();
664664
}
665665
return response;
666666
} catch (error) {
667667
this.#rLog.error({
668-
msg: "onFetch error",
668+
msg: "onRequest error",
669669
error: stringifyError(error),
670670
});
671671
throw error;
@@ -674,7 +674,7 @@ export class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
674674
}
675675
}
676676

677-
async handleWebSocket(
677+
async handleRawWebSocket(
678678
websocket: UniversalWebSocket,
679679
opts: { request: Request },
680680
): Promise<void> {

rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export async function handleRawWebSocketHandler(
452452
createdConn = conn;
453453

454454
// Call the actor's onWebSocket handler with the adapted WebSocket
455-
actor.handleWebSocket(adapter, {
455+
actor.handleRawWebSocket(adapter, {
456456
request: newRequest,
457457
});
458458
} catch (error) {

rivetkit-typescript/packages/rivetkit/src/actor/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export function createActorRouter(
195195
to: correctedRequest.url,
196196
});
197197

198-
// Call the actor's onFetch handler - it will throw appropriate errors
199-
const response = await actor.handleFetch(correctedRequest, {});
198+
// Call the actor's onRequest handler - it will throw appropriate errors
199+
const response = await actor.handleRawRequest(correctedRequest, {});
200200

201201
// This should never happen now since handleFetch throws errors
202202
if (!response) {

rivetkit-typescript/packages/rivetkit/src/driver-test-suite/test-inline-client-driver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function createTestInlineClientDriver(
129129
if (errorData.error) {
130130
// Handle both error formats:
131131
// 1. { error: { code, message, metadata } } - structured format
132-
// 2. { error: "message" } - simple string format (from custom onFetch handlers)
132+
// 2. { error: "message" } - simple string format (from custom onRequest handlers)
133133
if (typeof errorData.error === "object") {
134134
throw new ClientActorError(
135135
errorData.error.code,
@@ -138,7 +138,7 @@ export function createTestInlineClientDriver(
138138
);
139139
}
140140
// For simple string errors, just return the response as-is
141-
// This allows custom onFetch handlers to return their own error formats
141+
// This allows custom onRequest handlers to return their own error formats
142142
}
143143
} catch (e) {
144144
// If it's not our error format, just return the response as-is
@@ -452,7 +452,7 @@ export function createTestInlineClientDriver(
452452
// if (errorData.error) {
453453
// // Handle both error formats:
454454
// // 1. { error: { code, message, metadata } } - structured format
455-
// // 2. { error: "message" } - simple string format (from custom onFetch handlers)
455+
// // 2. { error: "message" } - simple string format (from custom onRequest handlers)
456456
// if (typeof errorData.error === "object") {
457457
// throw new ClientActorError(
458458
// errorData.error.code,
@@ -461,7 +461,7 @@ export function createTestInlineClientDriver(
461461
// );
462462
// }
463463
// // For simple string errors, just return the response as-is
464-
// // This allows custom onFetch handlers to return their own error formats
464+
// // This allows custom onRequest handlers to return their own error formats
465465
// }
466466
// } catch (e) {
467467
// // If it's not our error format, just return the response as-is

0 commit comments

Comments
 (0)