Skip to content

Instantly share code, notes, and snippets.

View jacobsamo's full-sized avatar

Jacob Samorowski jacobsamo

View GitHub Profile
@jacobsamo
jacobsamo / convex-helpers.ts
Created December 24, 2025 08:57
I created this neat little helper function for defining tables for convex using zod, it utilises the convex-helpers (https://github.com/get-convex/convex-helpers) package for transforming zod into convex schemas, this apporach reduces code duplicated as well as reducing the change of missing a type or field in queries or mutations.
// convex/helpers.ts
import { NoOp } from "convex-helpers/server/customFunctions";
import {
zCustomAction,
zCustomMutation,
zCustomQuery,
} from "convex-helpers/server/zod4";
import { components } from "./_generated/api";
import type { Id } from "./_generated/dataModel";
import {
// Simple and compatible ID generator
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
function generateRandomString(length: number): string {
let result = "";
const len = ALPHABET.length;
const arr = new Uint8Array(length);
// In modern environments (including Cloudflare Workers and Next.js),
// crypto is always available on globalThis