Changelog
for @ghostry/fabricator-census
Every release of @ghostry/fabricator-census, newest first.
v0.0.3
New
- Every bounded suggestion now has
admits, andreportwrites it as an.admits(...)call. A suggestion'swherebyrange is only what the sample held. An adapter turnswherebybounds into validation limits, so without.admits(...)the schema would reject real values outside the sample. By default it states no limit.// $.age T.number.integer.whereby({ min: 18, max: 79, distribution: { … } }).admits({ min: -Infinity, max: Infinity }) limitssay what a column accepts. Pass them ascensus.from(rows, { limits })(orcensus.begin({ limits })):{ column, limits }entries withmin,max, andlength.max..admits(...)then states those ends. A declared limit that would reject whatwherebydraws is dropped, with a note.limits(columns)in@ghostry/fabricator-census/postgresreads declared limits from column types:varchar(n)andchar(n)lengths,int2/int4/int8ranges, andnumeric(p, s).collectreturns them aslimits.const { rows, facts, limits } = await collect(run, { table: "users" }); console.log(report(census.from(rows, { facts, limits })));- A column where every value is distinct now gets a note pointing to
T.unique.numberorT.unique.string. A detected format's note shows the.admits({ format })call that states it.
Behavior change
- An error's
.namenow starts with the package name, as in"@ghostry/fabricator-census:FinishedError".instanceofchecks are unaffected.
Compatibility
- Peer dependency raised to
@ghostry/fabricator >=0.0.14 <0.1.0. Suggestions use.admits(...)andT.unique, which arrive in that version. - The
number,string,bigint,date,array, andrecordsuggestion types gainadmits, and aCensusgainslimits.SuggestedEnds,Limits, andColumnLimitsare exported as types.
Docs: Census guide, Limits
v0.0.2
New
@ghostry/fabricator-census/postgresbuilds the PostgreSQL queries a census is fed from. It never opens a connection: you run each query with your own driver.sampledraws a sample (Bernoulli, system, or hash).count,estimate,columns,statistics, andestimatedFactsread catalog estimates and statistics.aggregatescomputes exact whole-table facts.collectruns all of it through arun(text, values)function you supply, and returns{ rows, facts }.coerceandparseTextgive each value one type regardless of what your driver returned (int8,numeric, and so on).
census.from(rows, { facts })merges whole-table facts over the sample: exact counts and extremes win over estimates, and estimates win over the sample. A suggestion that relied on an estimate says so in its notes.sampleSizetells you how many rows a census needs.
import { collect } from "@ghostry/fabricator-census/postgres";
const { rows, facts } = await collect(
async (text, values) => (await client.query(text, values)).rows,
{ table: "users" },
);
console.log(report(census.from(rows, { facts })));
v0.0.1
Initial release.
Take a census of real data and get @ghostry/fabricator schema suggestions: how values are distributed, how often fields are missing or null, how long strings run and which characters they hold, and which strings are really enums. Suggestions come back in fabricator's own terms: Distribution variants, whereby ranges, .weighted(...) weights, and string composition.
import { census, report } from "@ghostry/fabricator-census";
console.log(report(census.from(rows)));
// $.age T.number.integer.whereby({ min: 18, max: 79, distribution: { kind: "normal", mean: 38.31, spread: 11.95 } })
// $.plan T.enum.weighted([[3528, "free"], [1237, "pro"], [235, "team"]])
Fits are scored against the exact curves fabricator draws from. A census keeps the values it observed, so treat it like the data it came from.
npm install @ghostry/fabricator-census @ghostry/fabricator
