-
Notifications
You must be signed in to change notification settings - Fork 147
feat: kv api #3976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: kv api #3976
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
More templates
@rivetkit/cloudflare-workers
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/virtual-websocket
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
PR Review - KV API ImplementationThis PR introduces a user-facing KV (key-value) storage API for Rivet Actors. The implementation is generally well-structured with good TypeScript typing and proper separation of concerns. Below are my findings: ✅ Strengths
🐛 Issues Found1. Formatting Issue in Test File (rivetkit-typescript/packages/rivetkit/src/driver-test-suite/tests/actor-kv.ts:26-42)The second test has incorrect indentation - the opening brace is on the wrong line: test(
"supports arrayBuffer encoding and decoding",
async (c: TestContext) => {
// ^^ This should be on the previous lineShould be: test("supports arrayBuffer encoding and decoding", async (c: TestContext) => {2. Missing Error Handling in encodeKey (rivetkit-typescript/packages/rivetkit/src/actor/instance/kv.ts:36-48)When function encodeKey<K extends KvKeyType = KvKeyType>(
key: KvKeyTypeMap[K],
keyType?: K,
): Uint8Array {
if (key instanceof Uint8Array) {
return key;
}
const resolvedKeyType = keyType ?? "text";
if (resolvedKeyType === "binary") {
throw new TypeError("Expected a Uint8Array when keyType is binary");
}
return textEncoder.encode(key);
}The logic assumes that if the key is not a Uint8Array and keyType is "binary", it should throw. However, if someone passes a string key with no keyType specified, it defaults to "text" and works fine. But if they explicitly pass Consider adding validation when keyType is explicitly provided to ensure it matches the actual key type. 3. Potential Type Safety Gap in encodeValue (rivetkit-typescript/packages/rivetkit/src/actor/instance/kv.ts:80-106)The const type =
options?.type ??
resolveValueType(value as string | Uint8Array | ArrayBuffer);The cast to
|
| import type { AnyDatabaseProvider, InferDatabaseClient } from "../../database"; | ||
| import type { ActorDefinition, AnyActorDefinition } from "../../definition"; | ||
| import type { ActorInstance, SaveStateOptions } from "../../instance/mod"; | ||
| import { ActorKv } from "../../instance/kv"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import for ActorKv is inserted in the middle of other imports, which violates import sorting rules. It should be moved to maintain alphabetical order with the other imports.
Spotted by Graphite Agent (based on CI logs)
Is this helpful? React 👍 or 👎 to let us know.
ed37d98 to
825c812
Compare
ab3e7db to
4b0cbc8
Compare
| import type { DriverTestConfig } from "../mod"; | ||
| import { setupDriverTest } from "../utils"; | ||
| import { describe, expect, test, type TestContext } from "vitest"; | ||
|
|
||
| export function runActorKvTests(driverTestConfig: DriverTestConfig) { | ||
| describe("Actor KV Tests", () => { | ||
| test("supports text encoding and decoding", async (c: TestContext) => { | ||
| const { client } = await setupDriverTest(c, driverTestConfig); | ||
| const kvHandle = client.kvActor.getOrCreate(["kv-text"]); | ||
|
|
||
| await kvHandle.putText("greeting", "hello"); | ||
| const value = await kvHandle.getText("greeting"); | ||
| expect(value).toBe("hello"); | ||
|
|
||
| await kvHandle.putText("prefix-a", "alpha"); | ||
| await kvHandle.putText("prefix-b", "beta"); | ||
|
|
||
| const results = await kvHandle.listText("prefix-"); | ||
| const sorted = results.sort((a, b) => a.key.localeCompare(b.key)); | ||
| expect(sorted).toEqual([ | ||
| { key: "prefix-a", value: "alpha" }, | ||
| { key: "prefix-b", value: "beta" }, | ||
| ]); | ||
| }); | ||
|
|
||
| test( | ||
| "supports arrayBuffer encoding and decoding", | ||
| async (c: TestContext) => { | ||
| const { client } = await setupDriverTest(c, driverTestConfig); | ||
| const kvHandle = client.kvActor.getOrCreate(["kv-array-buffer"]); | ||
|
|
||
| const values = await kvHandle.roundtripArrayBuffer("bytes", [ | ||
| 4, | ||
| 8, | ||
| 15, | ||
| 16, | ||
| 23, | ||
| 42, | ||
| ]); | ||
| expect(values).toEqual([4, 8, 15, 16, 23, 42]); | ||
| }, | ||
| ); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs to be formatted with Biome. Run biome format --write . to fix formatting issues and biome lint --apply . to fix any linting issues
Spotted by Graphite Agent (based on CI logs)
Is this helpful? React 👍 or 👎 to let us know.
4b0cbc8 to
bab56c9
Compare
Merge activity
|

No description provided.