Skip to content

Commit 0c00af1

Browse files
committed
donotmerge: dummy inspector api
1 parent 95dd3b3 commit 0c00af1

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

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

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,89 @@ export function buildNativeFactory(
36383638
);
36393639
return jsonResponse({ rows: jsonSafe(rows) });
36403640
}
3641+
if (
3642+
url.pathname === "/inspector/eval" &&
3643+
jsRequest.method === "POST"
3644+
) {
3645+
const body = (await jsRequest.json()) as {
3646+
code?: unknown;
3647+
};
3648+
if (
3649+
typeof body.code !== "string" ||
3650+
body.code.trim() === ""
3651+
) {
3652+
return jsonResponse(
3653+
{ error: "code is required and must be non-empty" },
3654+
{ status: 400 },
3655+
);
3656+
}
3657+
3658+
let db: unknown;
3659+
try {
3660+
db = actorCtx.db;
3661+
} catch {
3662+
db = undefined;
3663+
}
3664+
3665+
const logs: string[] = [];
3666+
const log = (...args: unknown[]) => {
3667+
logs.push(
3668+
args
3669+
.map((a) =>
3670+
typeof a === "string"
3671+
? a
3672+
: JSON.stringify(a),
3673+
)
3674+
.join(" "),
3675+
);
3676+
};
3677+
3678+
try {
3679+
// biome-ignore lint/security/noGlobalEval: intentional admin eval endpoint
3680+
const AsyncFunction = Object.getPrototypeOf(
3681+
async function () {},
3682+
).constructor;
3683+
const fn = new AsyncFunction(
3684+
"ctx",
3685+
"kv",
3686+
"sql",
3687+
"db",
3688+
"state",
3689+
"queue",
3690+
"schedule",
3691+
"conns",
3692+
"log",
3693+
body.code,
3694+
);
3695+
const result = await fn(
3696+
actorCtx,
3697+
actorCtx.kv,
3698+
actorCtx.sql,
3699+
db,
3700+
stateEnabled ? actorCtx.state : undefined,
3701+
actorCtx.queue,
3702+
actorCtx.schedule,
3703+
actorCtx.conns,
3704+
log,
3705+
);
3706+
return jsonResponse({
3707+
result: jsonSafe(result ?? null),
3708+
logs,
3709+
});
3710+
} catch (error) {
3711+
if (error instanceof Error) {
3712+
return jsonResponse(
3713+
{
3714+
error: error.message,
3715+
stack: error.stack,
3716+
logs,
3717+
},
3718+
{ status: 500 },
3719+
);
3720+
}
3721+
return errorResponse(error);
3722+
}
3723+
}
36413724
if (
36423725
url.pathname === "/inspector/summary" &&
36433726
jsRequest.method === "GET"

0 commit comments

Comments
 (0)