From c298cf6401479dc39c51a56dfe89fb342660e6ae Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Sat, 8 Nov 2025 21:06:39 -0800 Subject: [PATCH] chore(rivetkit): rename onstart/onstop to onwake/onsleep --- examples/crdt/src/backend/registry.ts | 2 +- examples/game/src/backend/registry.ts | 4 ++-- examples/kitchen-sink/SPEC.md | 8 +++---- .../kitchen-sink/src/backend/actors/demo.ts | 4 ++-- .../fixtures/driver-test-suite/lifecycle.ts | 4 ++-- .../fixtures/driver-test-suite/metadata.ts | 4 ++-- .../fixtures/driver-test-suite/sleep.ts | 20 ++++++++--------- .../packages/rivetkit/src/actor/config.ts | 14 ++++++------ .../rivetkit/src/actor/instance/mod.ts | 8 +++---- .../src/driver-test-suite/tests/actor-conn.ts | 8 +++---- .../driver-test-suite/tests/actor-handle.ts | 22 +++++++++---------- .../driver-test-suite/tests/actor-metadata.ts | 2 +- 12 files changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/crdt/src/backend/registry.ts b/examples/crdt/src/backend/registry.ts index 32d7753cd7..b4f1e5214b 100644 --- a/examples/crdt/src/backend/registry.ts +++ b/examples/crdt/src/backend/registry.ts @@ -13,7 +13,7 @@ export const yjsDocument = actor({ doc: new Y.Doc(), }), - onStart: (c) => { + onWake: (c) => { if (c.state.docData.length > 0) { applyUpdate(c.vars.doc, c.state.docData); } diff --git a/examples/game/src/backend/registry.ts b/examples/game/src/backend/registry.ts index 3b5b5d43e2..53350170f7 100644 --- a/examples/game/src/backend/registry.ts +++ b/examples/game/src/backend/registry.ts @@ -12,7 +12,7 @@ const gameRoom = actor({ createVars: (): GameVars => ({}), - onStart: (c) => { + onWake: (c) => { // Set up game update loop c.vars.gameLoopInterval = setInterval(() => { const playerList: Player[] = []; @@ -49,7 +49,7 @@ const gameRoom = actor({ }, 50); }, - onStop: (c) => { + onSleep: (c) => { if (c.vars.gameLoopInterval) { clearInterval(c.vars.gameLoopInterval); } diff --git a/examples/kitchen-sink/SPEC.md b/examples/kitchen-sink/SPEC.md index ebbc7f3b1c..dc6875a5c8 100644 --- a/examples/kitchen-sink/SPEC.md +++ b/examples/kitchen-sink/SPEC.md @@ -45,7 +45,7 @@ Comprehensive example demonstrating all RivetKit features with a simple React fr #### 4. Sleep - `sleep()` button - Sleep timeout configuration -- Lifecycle event display (`onStart`, `onStop`) +- Lifecycle event display (`onWake`, `onSleep`) #### 5. Connections (Only visible in Connection Mode) - Connection state display @@ -83,7 +83,7 @@ Comprehensive example demonstrating all RivetKit features with a simple React fr - Scheduling capabilities (`schedule.at()`, `schedule.after()`) - Sleep functionality with configurable timeout - Connection state support -- Lifecycle hooks (`onStart`, `onStop`, `onConnect`, `onDisconnect`) +- Lifecycle hooks (`onWake`, `onSleep`, `onConnect`, `onDisconnect`) - Metadata access ### 2. `http` - Raw HTTP handling @@ -104,7 +104,7 @@ Comprehensive example demonstrating all RivetKit features with a simple React fr - **State Management**: actor state + per-connection state - **Scheduling**: `schedule.at()`, `schedule.after()` with alarm handlers - **Force Sleep**: `sleep()` method with configurable sleep timeout -- **Lifecycle Hooks**: `onStart`, `onStop`, `onConnect`, `onDisconnect` +- **Lifecycle Hooks**: `onWake`, `onSleep`, `onConnect`, `onDisconnect` ### Configuration Options - **Transport**: WebSocket vs Server-Sent Events @@ -123,4 +123,4 @@ Comprehensive example demonstrating all RivetKit features with a simple React fr - **Get**: `client.actor.get(key, opts)` - **Get or Create**: `client.actor.getOrCreate(key, opts)` - **Get by ID**: `client.actor.getForId(actorId, opts)` -- **Dispose**: `client.dispose()` - disconnect all connections \ No newline at end of file +- **Dispose**: `client.dispose()` - disconnect all connections diff --git a/examples/kitchen-sink/src/backend/actors/demo.ts b/examples/kitchen-sink/src/backend/actors/demo.ts index 8dc4f6d24e..deb5360bd3 100644 --- a/examples/kitchen-sink/src/backend/actors/demo.ts +++ b/examples/kitchen-sink/src/backend/actors/demo.ts @@ -14,14 +14,14 @@ export const demo = actor({ connState: { connectionTime: 0, }, - onStart: (c) => { + onWake: (c) => { c.state.startCount += 1; c.log.info({ msg: "demo actor started", startCount: c.state.startCount, }); }, - onStop: (c) => { + onSleep: (c) => { c.state.stopCount += 1; c.log.info({ msg: "demo actor stopped", stopCount: c.state.stopCount }); }, diff --git a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/lifecycle.ts b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/lifecycle.ts index 0cdcf059c9..292ca8da91 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/lifecycle.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/lifecycle.ts @@ -10,8 +10,8 @@ export const counterWithLifecycle = actor({ createConnState: (c, opts, params: ConnParams) => ({ joinTime: Date.now(), }), - onStart: (c) => { - c.state.events.push("onStart"); + onWake: (c) => { + c.state.events.push("onWake"); }, onBeforeConnect: (c, opts, params: ConnParams) => { if (params?.trackLifecycle) c.state.events.push("onBeforeConnect"); diff --git a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/metadata.ts b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/metadata.ts index 0330f43f83..7d8641d817 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/metadata.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/metadata.ts @@ -11,7 +11,7 @@ export const metadataActor = actor({ storedTags: {} as Record, storedRegion: null as string | null, }, - onStart: (c) => { + onWake: (c) => { // Store the actor name during initialization c.state.actorName = c.name; }, @@ -62,7 +62,7 @@ export const metadataActor = actor({ return c.state.storedRegion; }, - // Get the stored actor name (from onStart) + // Get the stored actor name (from onWake) getStoredActorName: (c) => { return c.state.actorName; }, 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 731177b4f2..8c77c5c1ba 100644 --- a/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts +++ b/rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/sleep.ts @@ -5,10 +5,10 @@ export const SLEEP_TIMEOUT = 1000; export const sleep = actor({ state: { startCount: 0, sleepCount: 0 }, - onStart: (c) => { + onWake: (c) => { c.state.startCount += 1; }, - onStop: (c) => { + onSleep: (c) => { c.state.sleepCount += 1; }, actions: { @@ -37,10 +37,10 @@ export const sleepWithLongRpc = actor({ state: { startCount: 0, sleepCount: 0 }, createVars: () => ({}) as { longRunningResolve: PromiseWithResolvers }, - onStart: (c) => { + onWake: (c) => { c.state.startCount += 1; }, - onStop: (c) => { + onSleep: (c) => { c.state.sleepCount += 1; }, actions: { @@ -66,10 +66,10 @@ export const sleepWithLongRpc = actor({ export const sleepWithRawHttp = actor({ state: { startCount: 0, sleepCount: 0, requestCount: 0 }, - onStart: (c) => { + onWake: (c) => { c.state.startCount += 1; }, - onStop: (c) => { + onSleep: (c) => { c.state.sleepCount += 1; }, onFetch: async (c, request) => { @@ -106,10 +106,10 @@ export const sleepWithRawHttp = actor({ export const sleepWithRawWebSocket = actor({ state: { startCount: 0, sleepCount: 0, connectionCount: 0 }, - onStart: (c) => { + onWake: (c) => { c.state.startCount += 1; }, - onStop: (c) => { + onSleep: (c) => { c.state.sleepCount += 1; }, onWebSocket: (c, websocket: UniversalWebSocket, opts) => { @@ -175,10 +175,10 @@ export const sleepWithRawWebSocket = actor({ export const sleepWithNoSleepOption = actor({ state: { startCount: 0, sleepCount: 0 }, - onStart: (c) => { + onWake: (c) => { c.state.startCount += 1; }, - onStop: (c) => { + onSleep: (c) => { c.state.sleepCount += 1; }, actions: { diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/config.ts b/rivetkit-typescript/packages/rivetkit/src/actor/config.ts index b7fa486025..9281bce706 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/config.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/config.ts @@ -38,8 +38,8 @@ export interface ActorTypes< export const ActorConfigSchema = z .object({ onCreate: z.function().optional(), - onStart: z.function().optional(), - onStop: z.function().optional(), + onWake: z.function().optional(), + onSleep: z.function().optional(), onStateChange: z.function().optional(), onBeforeConnect: z.function().optional(), onConnect: z.function().optional(), @@ -255,7 +255,7 @@ interface BaseActorConfig< * * @returns Void or a Promise that resolves when startup is complete */ - onStart?: ( + onWake?: ( c: ActorContext< TState, TConnParams, @@ -276,7 +276,7 @@ interface BaseActorConfig< * * @returns Void or a Promise that resolves when shutdown is complete */ - onStop?: ( + onSleep?: ( c: ActorContext< TState, TConnParams, @@ -471,7 +471,7 @@ export type ActorConfig< z.infer, | "actions" | "onCreate" - | "onStart" + | "onWake" | "onStateChange" | "onBeforeConnect" | "onConnect" @@ -530,8 +530,8 @@ export type ActorConfigInput< z.input, | "actions" | "onCreate" - | "onStart" - | "onStop" + | "onWake" + | "onSleep" | "onStateChange" | "onBeforeConnect" | "onConnect" diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts b/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts index f7ea90be49..40ebe6d00c 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/instance/mod.ts @@ -864,8 +864,8 @@ export class ActorInstance { async #callOnStart() { this.#rLog.info({ msg: "actor starting" }); - if (this.#config.onStart) { - const result = this.#config.onStart(this.actorContext); + if (this.#config.onWake) { + const result = this.#config.onWake(this.actorContext); if (result instanceof Promise) { await result; } @@ -873,10 +873,10 @@ export class ActorInstance { } async #callOnStop() { - if (this.#config.onStop) { + if (this.#config.onSleep) { try { this.#rLog.debug({ msg: "calling onStop" }); - const result = this.#config.onStop(this.actorContext); + const result = this.#config.onSleep(this.actorContext); if (result instanceof Promise) { await deadline(result, this.#config.options.onStopTimeout); } diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-conn.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-conn.ts index 9378d1f8a9..86c312ea0f 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-conn.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-conn.ts @@ -261,7 +261,7 @@ export function runActorConnTests(driverTestConfig: DriverTestConfig) { // Verify lifecycle events were triggered const events = await connection.getEvents(); expect(events).toEqual([ - "onStart", + "onWake", "onBeforeConnect", "onConnect", ]); @@ -279,18 +279,18 @@ export function runActorConnTests(driverTestConfig: DriverTestConfig) { expect(finalEvents).toBeOneOf([ // Still active [ - "onStart", + "onWake", "onBeforeConnect", "onConnect", "onDisconnect", ], // Went to sleep and woke back up [ - "onStart", + "onWake", "onBeforeConnect", "onConnect", "onDisconnect", - "onStart", + "onWake", ], ]); }, diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-handle.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-handle.ts index b6bbc43710..5ffb4692ba 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-handle.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-handle.ts @@ -183,25 +183,25 @@ export function runActorHandleTests(driverTestConfig: DriverTestConfig) { test("should trigger lifecycle hooks on actor creation", async (c) => { const { client } = await setupDriverTest(c, driverTestConfig); - // Get or create a new actor - this should trigger onStart + // Get or create a new actor - this should trigger onWake const handle = client.counterWithLifecycle.getOrCreate([ "test-lifecycle-handle", ]); - // Verify onStart was triggered + // Verify onWake was triggered const initialEvents = await handle.getEvents(); - expect(initialEvents).toContain("onStart"); + expect(initialEvents).toContain("onWake"); // Create a separate handle to the same actor const sameHandle = client.counterWithLifecycle.getOrCreate([ "test-lifecycle-handle", ]); - // Verify events still include onStart but don't duplicate it - // (onStart should only be called once when the actor is first created) + // Verify events still include onWake but don't duplicate it + // (onWake should only be called once when the actor is first created) const events = await sameHandle.getEvents(); - expect(events).toContain("onStart"); - expect(events.filter((e) => e === "onStart").length).toBe(1); + expect(events).toContain("onWake"); + expect(events.filter((e) => e === "onWake").length).toBe(1); }); test("should trigger lifecycle hooks for each Action call", async (c) => { @@ -212,9 +212,9 @@ export function runActorHandleTests(driverTestConfig: DriverTestConfig) { "test-lifecycle-action", ]); - // Initial state should only have onStart + // Initial state should only have onWake const initialEvents = await viewHandle.getEvents(); - expect(initialEvents).toContain("onStart"); + expect(initialEvents).toContain("onWake"); expect(initialEvents).not.toContain("onBeforeConnect"); expect(initialEvents).not.toContain("onConnect"); expect(initialEvents).not.toContain("onDisconnect"); @@ -297,8 +297,8 @@ export function runActorHandleTests(driverTestConfig: DriverTestConfig) { // Check lifecycle hooks const events = await viewHandle.getEvents(); - // Should have 1 onStart, 2 each of onBeforeConnect, onConnect, and onDisconnect - expect(events.filter((e) => e === "onStart").length).toBe(1); + // Should have 1 onWake, 2 each of onBeforeConnect, onConnect, and onDisconnect + expect(events.filter((e) => e === "onWake").length).toBe(1); expect( events.filter((e) => e === "onBeforeConnect").length, ).toBe(2); diff --git a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-metadata.ts b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-metadata.ts index 1e24145fb3..2f1297156a 100644 --- a/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-metadata.ts +++ b/rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-metadata.ts @@ -16,7 +16,7 @@ export function runActorMetadataTests(driverTestConfig: DriverTestConfig) { expect(actorName).toBe("metadataActor"); }); - test("should preserve actor name in state during onStart", async (c) => { + test("should preserve actor name in state during onWake", async (c) => { const { client } = await setupDriverTest(c, driverTestConfig); // Get the stored actor name