A collection of useful code to complement the official packages.
In the packages directory there's the convex-helpers
directory, so you can npm install convex-helpers@latest
.
It doesn't have all of the below features, but the ones it has can be used directly, rather than copying the code from this repo.
See the README for more details on:
- Customizing Functions (customQuery, customMutation, customAction).
- Relationship utilities to navigate database references.
- Row-Level Security (to be used with Custom Functions).
- Zod validation for function arguments and schemas.
See the guide on Stack for tips on how to set up and use Sessions.
To use sessions, you'll need the files:
- withSession.ts on the server-side to give you function wrappers like
mutation(withSession(...))
. - sessions.ts on the server-side as a place to write your custom session creation logic.
- useServerSession.ts on the client-side to give you hooks like
useSessionMutation(...)
. - You'll need to define a table in your
convex/schema.ts
for whatever your session data looks like. Here we just uses.any()
.
See the Stack post on withUser
Use the withUser wrappers in your functions to easily look up a user. You'll need to add an entry in your schema similar to convex/schema.ts.
See the Stack post on migrations and the migration primer Stack post.
Use the migration wrapper to define a function to run over a given table. It generates an internalMutation to migrate a batch of documents.
Run the mutation to test it out, then run it over the whole table with the runMigration action.
See the guide on Stack for tips on using Hono for HTTP endpoints.
To use Hono, you'll need the file honoWithConvex.ts.
See the Stack post on single-flighting for info on a technique to limit client requests.
You'll need the useSingleFlight.ts file, or useLatestValue.ts utilities.
If you're fine getting stale results from queries when parameters change, check out the Stack post on useStableQuery.
You'll need the useStableQuery.ts file.
See the Stack post on implementing presence for details on how to implement presence in your app.
Related files:
- presence.ts for server-side presence functions. Intended to be modified for your application.
- usePresence.ts for client-side React hooks. Modify to match your server API.
- (optional)useTypingIndicator.ts for specifically doing typing indicator presence.
- (optional)Facepile.tsx for showing a facepile based on presence data. Intended to be used as an example to extend.