Skip to content
Logo

Changelog

for @ghostry/fabricator-census

Every release of @ghostry/fabricator-census, newest first.

v0.0.3

· Release on GitHub

New

  • Every bounded suggestion now has admits, and report writes it as an .admits(...) call. A suggestion's whereby range is only what the sample held. An adapter turns whereby bounds 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 })
    
  • limits say what a column accepts. Pass them as census.from(rows, { limits }) (or census.begin({ limits })): { column, limits } entries with min, max, and length.max. .admits(...) then states those ends. A declared limit that would reject what whereby draws is dropped, with a note.
  • limits(columns) in @ghostry/fabricator-census/postgres reads declared limits from column types: varchar(n) and char(n) lengths, int2/int4/int8 ranges, and numeric(p, s). collect returns them as limits.
    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.number or T.unique.string. A detected format's note shows the .admits({ format }) call that states it.

Behavior change

  • An error's .name now starts with the package name, as in "@ghostry/fabricator-census:FinishedError". instanceof checks are unaffected.

Compatibility

  • Peer dependency raised to @ghostry/fabricator >=0.0.14 <0.1.0. Suggestions use .admits(...) and T.unique, which arrive in that version.
  • The number, string, bigint, date, array, and record suggestion types gain admits, and a Census gains limits. SuggestedEnds, Limits, and ColumnLimits are exported as types.

Docs: Census guide, Limits

v0.0.2

· Release on GitHub

New

  • @ghostry/fabricator-census/postgres builds the PostgreSQL queries a census is fed from. It never opens a connection: you run each query with your own driver.
    • sample draws a sample (Bernoulli, system, or hash).
    • count, estimate, columns, statistics, and estimatedFacts read catalog estimates and statistics.
    • aggregates computes exact whole-table facts.
    • collect runs all of it through a run(text, values) function you supply, and returns { rows, facts }.
    • coerce and parseText give 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.
  • sampleSize tells 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 })));

Docs: https://docs.ghostry.dev/fabricator/guides/census

v0.0.1

· Release on GitHub

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

Docs: https://docs.ghostry.dev/fabricator/guides/census