Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions examples/sandbox-vercel/src/fdb-tuple-shim.mjs

This file was deleted.

5 changes: 0 additions & 5 deletions examples/sandbox/src/fdb-tuple-shim.mjs

This file was deleted.

6 changes: 0 additions & 6 deletions examples/sandbox/vite.config.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 3 additions & 41 deletions rivetkit-typescript/packages/rivetkit/src/actor/definition.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { RegistryConfig } from "@/registry/config";
import { getRequireFn } from "@/utils/node";
import type { Actions, ActorConfig } from "./config";
import type { AnyDatabaseProvider } from "./database";
import type { ActorInstance } from "./instance/mod";
import { ActorInstance } from "./instance/mod";

export type AnyActorDefinition = ActorDefinition<
any,
Expand Down Expand Up @@ -33,48 +32,11 @@ export class ActorDefinition<
return this.#config;
}

async instantiate(): Promise<ActorInstance<S, CP, CS, V, I, DB>> {
// Lazy import to avoid pulling server-only dependencies (traces, fdb-tuple, etc.)
// into browser bundles. This method is only called on the server.
// const requireFn = getRequireFn();
// if (!requireFn) {
// throw new Error(
// "ActorDefinition.instantiate requires a Node.js environment",
// );
// }

try {
const { ActorInstance: ActorInstanceClass } = await import(
"./instance/mod"
);
return new ActorInstanceClass(this.#config);
} catch (error) {
if (!isInstanceModuleNotFound(error)) {
throw error;
}

try {
// In tests, register tsx so require() can resolve .ts files.
await getRequireFn()("tsx/cjs");
} catch {
throw error;
}

const { ActorInstance: ActorInstanceClass } = await import(
"./instance/mod"
);
return new ActorInstanceClass(this.#config);
}
instantiate(): ActorInstance<S, CP, CS, V, I, DB> {
return new ActorInstance(this.#config);
}
}

function isInstanceModuleNotFound(error: unknown): boolean {
if (!error || typeof error !== "object") return false;
const err = error as { code?: string; message?: string };
if (err.code !== "MODULE_NOT_FOUND") return false;
return (err.message ?? "").includes("./instance/mod");
}

export function lookupInRegistry(
config: RegistryConfig,
name: string,
Expand Down
Loading