Skip to content

Commit 2b648d0

Browse files
authored
add node runtime for convex (#40)
* add node runtime for convex * update convex package
1 parent a38ef99 commit 2b648d0

11 files changed

+63
-26
lines changed

convex.json

-7
This file was deleted.

convex/_generated/api.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* THIS CODE IS AUTOMATICALLY GENERATED.
66
*
7-
* Generated by convex@1.7.1.
7+
* Generated by convex@1.11.2.
88
* To regenerate, run `npx convex dev`.
99
* @module
1010
*/

convex/_generated/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* THIS CODE IS AUTOMATICALLY GENERATED.
66
*
7-
* Generated by convex@1.7.1.
7+
* Generated by convex@1.11.2.
88
* To regenerate, run `npx convex dev`.
99
* @module
1010
*/

convex/_generated/dataModel.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* THIS CODE IS AUTOMATICALLY GENERATED.
66
*
7-
* Generated by convex@1.7.1.
7+
* Generated by convex@1.11.2.
88
* To regenerate, run `npx convex dev`.
99
* @module
1010
*/

convex/_generated/server.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* THIS CODE IS AUTOMATICALLY GENERATED.
66
*
7-
* Generated by convex@1.7.1.
7+
* Generated by convex@1.11.2.
88
* To regenerate, run `npx convex dev`.
99
* @module
1010
*/

convex/_generated/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* THIS CODE IS AUTOMATICALLY GENERATED.
66
*
7-
* Generated by convex@1.7.1.
7+
* Generated by convex@1.11.2.
88
* To regenerate, run `npx convex dev`.
99
* @module
1010
*/

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"lint": "next lint",
88
"gen:planetscale": "prisma generate --schema ./prisma-planetscale/schema.prisma",
99
"gen:supabase": "prisma generate --schema ./prisma-supabase/schema.prisma"
10-
1110
},
1211
"dependencies": {
1312
"@headlessui/react": "^1.7.18",
@@ -29,7 +28,7 @@
2928
"@vercel/postgres": "^0.7.2",
3029
"@xata.io/client": "^0.29.3",
3130
"autoprefixer": "^10.4.18",
32-
"convex": "1.10.0",
31+
"convex": "1.11.2",
3332
"drizzle-orm": "^0.30.9",
3433
"eslint": "8.57.0",
3534
"eslint-config-next": "14.1.3",

pages/api/convex-node.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ConvexHttpClient } from "convex/browser";
2+
import type { NextApiRequest, NextApiResponse } from "next";
3+
import { api as convexApi } from "../../convex/_generated/api";
4+
5+
// Make sure we use the Edge endpoints.
6+
let url = process.env.NEXT_PUBLIC_CONVEX_URL;
7+
if (!url.endsWith("edge.convex.cloud")) {
8+
url = url.replace(/convex.cloud$/g, "edge.convex.cloud");
9+
}
10+
11+
const convex = new ConvexHttpClient(url);
12+
13+
const start = Date.now();
14+
15+
export default async function api(req: NextApiRequest, res: NextApiResponse) {
16+
const count = toNumber(req.query.count);
17+
const time = Date.now();
18+
19+
let data = null;
20+
for (let i = 0; i < count; i++) {
21+
const limit = 10;
22+
data = await convex.query(convexApi.employees.default, { limit });
23+
}
24+
25+
return res.json({
26+
data,
27+
queryDuration: Date.now() - time,
28+
invocationIsCold: start === time,
29+
});
30+
}
31+
32+
// convert a query parameter to a number
33+
// also apply a min and a max
34+
function toNumber(queryParam: string | string[] | null, min = 1, max = 5) {
35+
const num = Number(queryParam);
36+
return Number.isNaN(num) ? 1 : Math.min(Math.max(num, min), max);
37+
}

pages/api/convex-regional.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { default as api } from "./convex-global";
2+
13
export const config = {
2-
runtime: "edge",
3-
regions: ["iad1"],
4-
};
5-
6-
export { default } from "./convex-global";
7-
4+
runtime: "edge",
5+
regions: ["iad1"],
6+
};
7+
8+
export default api;

pages/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Head from "next/head";
66
import GithubCorner from "@/components/github-corner";
77

88
const ATTEMPTS = 10;
9-
const NODE_AVAILABLE = ["planetscale-drizzle", "planetscale-prisma"];
9+
const NODE_AVAILABLE = ["planetscale-drizzle", "planetscale-prisma", "convex"];
1010
const NODE_ONLY = ["supabase-drizzle", "supabase-prisma"];
1111

1212
type Region = "regional" | "global" | "node";

pnpm-lock.yaml

+12-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)