Chaca is a TypeScript library for generating realistic, relational mock data — schemas that reference each other, exported to JSON, CSV, SQL, Java, Python and more. Until now, it only ran in Node. Version 2.2 changes that.
🌐 Chaca is now isomorphic
You can install and use Chaca in any browser app — React, Vue, Svelte, vanilla JS. No configuration needed: your bundler automatically resolves the browser-safe build through the package exports map. The package now ships both ESM and CommonJS builds, each with its own type definitions.
The key piece is transform, which serializes your data to any supported format fully in memory — no filesystem involved. That makes it the natural way to get file contents in the browser, for example to trigger a download:
import { chaca, modules } from "chaca";
const schema = chaca.schema({
id: chaca.key(() => modules.id.uuid()),
name: () => modules.person.firstName(),
});
const [file] = await schema.transform(50, {
filename: "users",
format: "json",
});
// file.filename -> "users.json"
// file.content -> serialized string, ready to download or display
transform supports every format: json, csv, yaml, postgresql, sqlite, mysql, java, python, typescript and javascript.
Note:
export(which writes files to disk) is not available in the browser build and throws a descriptive error pointing you totransform. In Node,exportkeeps working exactly as before.
🗄️ New export formats: SQLite and MySQL
Two new SQL targets join postgresql, sharing all of its options (keys, uniques, nulls, refs, generateIds, declarationOnly, ...):
await dataset.export({
filename: "data",
location: "./data",
format: "sqlite", // or "mysql"
});
Both are also available from the CLI (chaca sqlite, chaca mysql) and generate scripts with native types for each engine:
-
SQLite:
PRAGMA foreign_keys = ON,INTEGER PRIMARY KEYfor generated ids,TEXTfor strings and ISO dates,REALfor floats. -
MySQL:
INT AUTO_INCREMENT PRIMARY KEY,VARCHAR(255)/TEXT,DATETIME(3)for dates, table-levelFOREIGN KEYconstraints, and reserved words safely quoted with backticks.
🧯 A single Errors namespace
Every Chaca exception is now grouped under one namespace, so error handling is easier to discover:
import { Errors } from "chaca";
try {
await schema.export(/* ... */);
} catch (e) {
if (e instanceof Errors.TryRefANoKeyFieldError) {
/* handle the specific error */
}
if (e instanceof Errors.ChacaError) {
/* catch-all for any chaca error */
}
}
The existing flat exports keep working, and three error classes announced in 2.0.0 but never actually exported are finally reachable.
🪛 40+ fixes
This release closes a long list of bugs. Some highlights:
-
chaca.pickandisArraywith{ min, max }could never reachmax— the upper bound is now inclusive, as documented. - The Java exporter generated code that didn't compile (missing semicolons, wrong float literals, invalid
biginttypes, reserved-word identifiers). It compiles now. - PostgreSQL export: single quotes in strings are properly escaped, all-null columns get a
TEXTtype, dates keep their time asTIMESTAMP, and reserved-word identifiers are double quoted. - An array
reffield that runs out of values no longer pads the array withnull— it stops at the references it could actually resolve. Check your code if you relied on the padding; as a bonus, largeisArrayrefs are noticeably faster. -
modules.date.past/soon/betweenno longer mutate theDateyou pass in. -
modules.internet.emailno longer producespedro@yahoo.com.com, andmodules.datatype.hexadecimalno longer outputs the letterG. - CSV missing values are empty cells instead of the literal string
undefined, and YAML no longer silently dropsbigintvalues.
The full list — including a few small behavior changes worth checking (ethereumAddress now includes the 0x prefix, color.rgb CSS output no longer carries the hex prefix, and the continent typos Oseania/Antartica were corrected) — is in the changelog.
Try it
npm install chaca
Docs and guides at chaca.app. If you build something with it — or hit a bug — issues and PRs are welcome on GitHub.
Top comments (0)