surreal-codegen
v0.1.1
Published
Generate Zod schemas and a typed TypeScript client from a SurrealDB schema or live database
Downloads
15
Maintainers
Readme
surreal-codegen
surreal-codegen is the maintained generator fork used by Hey Murph. It started from @sebastianwessel/surql-gen, then was adapted for SurrealDB v3 and a schemaful, generated-client-first workflow.
The package publishes as surreal-codegen. The GitHub repository is still patgpt/surreal-client until the repo rename lands.
Docs
What It Does
- reads a single SurrealQL schema file or a schema directory
- spins up a temporary SurrealDB instance for schema-file introspection
- connects to a running SurrealDB instance for live introspection
- generates Zod schemas
- generates a typed TypeScript client and repository helpers
Install
Run directly:
bunx surreal-codegenInstall as a dev dependency:
bun add -D surreal-codegenThe package also keeps the upstream-compatible surql-gen bin alias:
bunx surql-genUsage
Generate from a running database:
bunx surreal-codegen \
--surreal http://localhost:8000 \
--username root \
--password root \
--ns test \
--db testGenerate from a schema file:
bunx surreal-codegen -f ./schema.surqlGenerate from a schema directory:
bunx surreal-codegen -f ./db/schemaGenerate without the TypeScript client:
bunx surreal-codegen -f ./schema.surql --no-clientConfiguration
You can configure the generator with CLI flags, a config file, or both. CLI values win.
The default JSON config filename is surreal-codegen.config.json for compatibility with the upstream tool.
Example:
{
"schemaFile": "./schema",
"surreal": "http://localhost:8000",
"username": "root",
"password": "root",
"ns": "test",
"db": "test",
"outputFolder": "./client_generated",
"generateClient": true,
"surrealImage": "surrealdb/surrealdb:latest"
}How It Works
Schema-file mode
When you pass -f with a file or directory, the generator:
- starts a temporary SurrealDB container with Testcontainers
- loads your schema into that database
- introspects the resulting definitions
- writes generated Zod schemas and optional client files
Docker is required for this path.
Live-database mode
When you omit -f, the generator connects to the database specified by --surreal, --ns, --db, and auth flags, then introspects that database directly.
Output Structure
_generated/: regenerated output and record helpersschema/: schema wrappers and customization pointsclient/: CRUD and repository helpers for generated tables
Development
Install dependencies:
bun installRun the full validation pass:
bun run ciUseful individual commands:
bun run lint
bun run lint:fix
bun run typecheck
bun run test
bun run build
bun run pack:dry-runRelease Notes
- npm and JSR publishing steps live in
PUBLISHING.md - the manual GitHub Actions release flow lives in
.github/workflows/release-manual.yml package.jsonandjsr.jsonversions must stay in sync- the current GitHub repository is
patgpt/surreal-clienteven though the package name issurreal-codegen
