Skip to content

Commit 828bd2a

Browse files
committed
donotmerge: dummy inspector api
1 parent 3f807cd commit 828bd2a

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

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

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,130 @@ 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+
const rawKv = {
3679+
get: (key: Uint8Array) =>
3680+
runtime.actorKvGet(ctx, key),
3681+
put: (key: Uint8Array, value: Uint8Array) =>
3682+
runtime.actorKvPut(ctx, key, value),
3683+
delete: (key: Uint8Array) =>
3684+
runtime.actorKvDelete(ctx, key),
3685+
deleteRange: (start: Uint8Array, end: Uint8Array) =>
3686+
runtime.actorKvDeleteRange(ctx, start, end),
3687+
listPrefix: (
3688+
prefix: Uint8Array,
3689+
options?: { limit?: number; reverse?: boolean },
3690+
) =>
3691+
runtime.actorKvListPrefix(ctx, prefix, options),
3692+
listRange: (
3693+
start: Uint8Array,
3694+
end: Uint8Array,
3695+
options?: { limit?: number; reverse?: boolean },
3696+
) =>
3697+
runtime.actorKvListRange(
3698+
ctx,
3699+
start,
3700+
end,
3701+
options,
3702+
),
3703+
batchGet: (keys: Uint8Array[]) =>
3704+
runtime.actorKvBatchGet(ctx, keys),
3705+
batchPut: (entries: [Uint8Array, Uint8Array][]) =>
3706+
runtime.actorKvBatchPut(
3707+
ctx,
3708+
entries.map(([key, value]) => ({
3709+
key,
3710+
value,
3711+
})),
3712+
),
3713+
batchDelete: (keys: Uint8Array[]) =>
3714+
runtime.actorKvBatchDelete(ctx, keys),
3715+
};
3716+
3717+
try {
3718+
// biome-ignore lint/security/noGlobalEval: intentional admin eval endpoint
3719+
const AsyncFunction = Object.getPrototypeOf(
3720+
async function () {},
3721+
).constructor;
3722+
const fn = new AsyncFunction(
3723+
"ctx",
3724+
"kv",
3725+
"rawKv",
3726+
"sql",
3727+
"db",
3728+
"state",
3729+
"queue",
3730+
"schedule",
3731+
"conns",
3732+
"log",
3733+
body.code,
3734+
);
3735+
const result = await fn(
3736+
actorCtx,
3737+
actorCtx.kv,
3738+
rawKv,
3739+
actorCtx.sql,
3740+
db,
3741+
stateEnabled ? actorCtx.state : undefined,
3742+
actorCtx.queue,
3743+
actorCtx.schedule,
3744+
actorCtx.conns,
3745+
log,
3746+
);
3747+
return jsonResponse({
3748+
result: jsonSafe(result ?? null),
3749+
logs,
3750+
});
3751+
} catch (error) {
3752+
if (error instanceof Error) {
3753+
return jsonResponse(
3754+
{
3755+
error: error.message,
3756+
stack: error.stack,
3757+
logs,
3758+
},
3759+
{ status: 500 },
3760+
);
3761+
}
3762+
return errorResponse(error);
3763+
}
3764+
}
36413765
if (
36423766
url.pathname === "/inspector/summary" &&
36433767
jsRequest.method === "GET"

0 commit comments

Comments
 (0)