@rivetkit/core
Version:
165 lines (148 loc) • 2.95 kB
text/typescript
import type { ActorKey } from "@/actor/mod";
import type { Client } from "@/client/client";
import type { Logger } from "@/common/log";
import type { Registry } from "@/registry/mod";
import type { Conn, ConnId } from "./connection";
import type { ActorContext } from "./context";
import type { AnyDatabaseProvider, InferDatabaseClient } from "./database";
import type { SaveStateOptions } from "./instance";
import type { Schedule } from "./schedule";
/**
* Context for a remote procedure call.
*
* @typeParam A Actor this action belongs to
*/
export class ActionContext<
TState,
TConnParams,
TConnState,
TVars,
TInput,
TAuthData,
TDatabase extends AnyDatabaseProvider,
> {
TState,
TConnParams,
TConnState,
TVars,
TInput,
TAuthData,
TDatabase
>;
/**
* Should not be called directly.
*
* @param actorContext - The actor context
* @param conn - The connection associated with the action
*/
constructor(
actorContext: ActorContext<
TState,
TConnParams,
TConnState,
TVars,
TInput,
TAuthData,
TDatabase
>,
public readonly conn: Conn<
TState,
TConnParams,
TConnState,
TVars,
TInput,
TAuthData,
TDatabase
>,
) {
this.
}
/**
* Get the actor state
*/
get state(): TState {
return this.
}
/**
* Get the actor variables
*/
get vars(): TVars {
return this.
}
/**
* Broadcasts an event to all connected clients.
*/
broadcast(name: string, ...args: any[]): void {
this.
}
/**
* Gets the logger instance.
*/
get log(): Logger {
return this.
}
/**
* Gets actor ID.
*/
get actorId(): string {
return this.
}
/**
* Gets the actor name.
*/
get name(): string {
return this.
}
/**
* Gets the actor key.
*/
get key(): ActorKey {
return this.
}
/**
* Gets the region.
*/
get region(): string {
return this.
}
/**
* Gets the scheduler.
*/
get schedule(): Schedule {
return this.
}
/**
* Gets the map of connections.
*/
get conns(): Map<
ConnId,
Conn<TState, TConnParams, TConnState, TVars, TInput, TAuthData, TDatabase>
> {
return this.
}
/**
* Returns the client for the given registry.
*/
client<R extends Registry<any>>(): Client<R> {
return this.
}
/**
* @experimental
*/
get db(): InferDatabaseClient<TDatabase> {
return this.
}
/**
* Forces the state to get saved.
*/
async saveState(opts: SaveStateOptions): Promise<void> {
return this.
}
/**
* Runs a promise in the background.
*/
runInBackground(promise: Promise<void>): void {
this.
}
}