Skip to content

Commit 97d39a8

Browse files
NicolappsConvex, Inc.
authored andcommitted
load-generator: Add missing arg validators in scenario-runner (#43696)
GitOrigin-RevId: 4c3b04b2133a48fef9393160d13a5bb8ecd8f793
1 parent ccd1008 commit 97d39a8

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

npm-packages/scenario-runner/convex/actions/externalNodeDeps.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { load } from "langchain/load";
33
import { Tiktoken } from "tiktoken/lite";
44
import { action } from "../_generated/server";
5+
import { v } from "convex/values";
6+
57
// eslint-disable-next-line @typescript-eslint/no-require-imports
68
const gpt2_base = require("tiktoken/encoders/gpt2.json");
79

@@ -10,7 +12,10 @@ const gpt2_base = require("tiktoken/encoders/gpt2.json");
1012
load;
1113

1214
export const encode = action({
13-
handler: (_, { str }: { str: string }): number[] => {
15+
args: {
16+
str: v.string(),
17+
},
18+
handler: (_, { str }): number[] => {
1419
const enc = new Tiktoken(
1520
gpt2_base.bpe_ranks,
1621
gpt2_base.special_tokens,

npm-packages/scenario-runner/convex/query_index.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DatabaseReader, query } from "./_generated/server";
22
import { Id } from "./_generated/dataModel";
33
import { CACHE_BREAKER_ARGS, MessagesTable } from "./common";
4+
import { v } from "convex/values";
45

56
export const queryMessages = query({
67
args: CACHE_BREAKER_ARGS,
@@ -33,20 +34,13 @@ export const queryMessagesWithSearch = query({
3334
});
3435

3536
export const queryMessagesWithArgs = query({
36-
handler: async (
37-
{ db },
38-
{
39-
channel,
40-
rand,
41-
limit,
42-
table,
43-
}: {
44-
channel: string;
45-
rand: number;
46-
limit: number;
47-
table: MessagesTable;
48-
},
49-
) => {
37+
args: {
38+
channel: v.string(),
39+
rand: v.number(),
40+
limit: v.number(),
41+
table: v.union(v.literal("messages"), v.literal("messages_with_search")),
42+
},
43+
handler: async ({ db }, { channel, rand, limit, table }) => {
5044
return await queryMessagesHelper(db, channel, rand, limit, table);
5145
},
5246
});
@@ -67,7 +61,10 @@ function queryMessagesHelper(
6761
}
6862

6963
export const queryMessagesById = query({
70-
handler: async ({ db }, { id }: { id: Id<MessagesTable> }) => {
71-
return await db.get(id);
64+
args: {
65+
id: v.union(v.id("messages"), v.id("messages_with_search")),
66+
},
67+
handler: async ({ db }, { id }) => {
68+
return await db.get(id satisfies Id<MessagesTable>);
7269
},
7370
});

npm-packages/scenario-runner/convex/setup.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { v } from "convex/values";
55
import { rand } from "./common";
66

77
export const setupMessages = mutation({
8-
handler: async (
9-
{ db },
10-
{ rows, channel }: { rows: number; channel: string },
11-
): Promise<void> => {
8+
args: {
9+
rows: v.number(),
10+
channel: v.string(),
11+
},
12+
handler: async ({ db }, { rows, channel }): Promise<void> => {
1213
console.log(`Fill the messages table with ${rows} rows`);
1314
for (let i = 0; i < rows; i++) {
1415
// The first record always has rand=0. This is used in update_first

0 commit comments

Comments
 (0)