Skip to content

Commit abb6ff1

Browse files
committed
[slop]fix(rivetkit): remove async drizzle db proxy
1 parent 0499832 commit abb6ff1

1 file changed

Lines changed: 18 additions & 24 deletions

File tree

  • rivetkit-typescript/packages/rivetkit/src/registry

rivetkit-typescript/packages/rivetkit/src/registry/native.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ function databaseNotConfiguredError(): RivetError {
355355
);
356356
}
357357

358+
function databaseClientNotReadyError(): RivetError {
359+
return new RivetError(
360+
"actor",
361+
"database_client_not_ready",
362+
"actor database client was not initialized before user code ran. this is an internal lifecycle error; the migration callback should have pre-warmed the client. file an issue if you can reproduce.",
363+
{ public: true },
364+
);
365+
}
366+
358367
function stateNotEnabledError(): RivetError {
359368
return new RivetError(
360369
"actor",
@@ -2378,7 +2387,6 @@ export class ActorContextHandleAdapter {
23782387
#clientFactory?: () => AnyClient;
23792388
#databaseProvider?: Exclude<AnyDatabaseProvider, undefined>;
23802389
#db?: unknown;
2381-
#dbProxy?: unknown;
23822390
#dispatchCancelToken?: CancellationTokenHandle;
23832391
#kv?: NativeKvAdapter;
23842392
#queue?: NativeQueueAdapter;
@@ -2441,32 +2449,18 @@ export class ActorContextHandleAdapter {
24412449
throw databaseNotConfiguredError();
24422450
}
24432451

2444-
if (!this.#dbProxy) {
2445-
this.#dbProxy = new Proxy(
2446-
{},
2447-
{
2448-
get: (_target, property) => {
2449-
if (property === "then") {
2450-
return undefined;
2451-
}
2452+
if (this.#db) {
2453+
return this.#db;
2454+
}
24522455

2453-
return async (...args: Array<unknown>) => {
2454-
const client = await this.ensureDatabaseClient();
2455-
const value = Reflect.get(
2456-
client as object,
2457-
property,
2458-
);
2459-
if (typeof value !== "function") {
2460-
return value;
2461-
}
2462-
return await value.apply(client, args);
2463-
};
2464-
},
2465-
},
2466-
);
2456+
const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
2457+
const cachedClient = runtimeState.databaseClient;
2458+
if (cachedClient) {
2459+
this.#db = cachedClient.client;
2460+
return this.#db;
24672461
}
24682462

2469-
return this.#dbProxy;
2463+
throw databaseClientNotReadyError();
24702464
}
24712465

24722466
get state(): unknown {

0 commit comments

Comments
 (0)